| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ | 5 #ifndef VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ |
| 6 #define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ | 6 #define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ |
| 7 | 7 |
| 8 #include <atlbase.h> | 8 #include <atlbase.h> |
| 9 #include <atlapp.h> | 9 #include <atlapp.h> |
| 10 #include <atlcrack.h> | 10 #include <atlcrack.h> |
| 11 #include <atlctrls.h> | 11 #include <atlctrls.h> |
| 12 #include <atlmisc.h> | 12 #include <atlmisc.h> |
| 13 #include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl | 13 #include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl |
| 14 #include <vsstyle.h> | 14 #include <vsstyle.h> |
| 15 | 15 |
| 16 #include "views/controls/menu/simple_menu_model.h" |
| 16 #include "views/controls/textfield/native_textfield_wrapper.h" | 17 #include "views/controls/textfield/native_textfield_wrapper.h" |
| 17 | 18 |
| 18 namespace views { | 19 namespace views { |
| 19 | 20 |
| 20 class NativeViewHost; | 21 class NativeViewHost; |
| 21 class Textfield; | 22 class Textfield; |
| 22 | 23 |
| 23 static const int kDefaultEditStyle = WS_CHILD | WS_VISIBLE; | 24 static const int kDefaultEditStyle = WS_CHILD | WS_VISIBLE; |
| 24 | 25 |
| 25 // TODO(beng): make a subclass of NativeControlWin instead. | 26 // TODO(beng): make a subclass of NativeControlWin instead. |
| 26 class NativeTextfieldWin | 27 class NativeTextfieldWin |
| 27 : public CWindowImpl<NativeTextfieldWin, CRichEditCtrl, | 28 : public CWindowImpl<NativeTextfieldWin, CRichEditCtrl, |
| 28 CWinTraits<kDefaultEditStyle> >, | 29 CWinTraits<kDefaultEditStyle> >, |
| 29 public CRichEditCommands<NativeTextfieldWin>, | 30 public CRichEditCommands<NativeTextfieldWin>, |
| 30 public NativeTextfieldWrapper, | 31 public NativeTextfieldWrapper, |
| 31 public Menu::Delegate { | 32 public SimpleMenuModel::Delegate { |
| 32 public: | 33 public: |
| 33 DECLARE_WND_CLASS(L"ViewsTextfieldEdit"); | 34 DECLARE_WND_CLASS(L"ViewsTextfieldEdit"); |
| 34 | 35 |
| 35 explicit NativeTextfieldWin(Textfield* parent); | 36 explicit NativeTextfieldWin(Textfield* parent); |
| 36 ~NativeTextfieldWin(); | 37 ~NativeTextfieldWin(); |
| 37 | 38 |
| 38 // Overridden from NativeTextfieldWrapper: | 39 // Overridden from NativeTextfieldWrapper: |
| 39 virtual std::wstring GetText() const; | 40 virtual std::wstring GetText() const; |
| 40 virtual void UpdateText(); | 41 virtual void UpdateText(); |
| 41 virtual void AppendText(const std::wstring& text); | 42 virtual void AppendText(const std::wstring& text); |
| 42 virtual std::wstring GetSelectedText() const; | 43 virtual std::wstring GetSelectedText() const; |
| 43 virtual void SelectAll(); | 44 virtual void SelectAll(); |
| 44 virtual void ClearSelection(); | 45 virtual void ClearSelection(); |
| 45 virtual void UpdateBorder(); | 46 virtual void UpdateBorder(); |
| 46 virtual void UpdateBackgroundColor(); | 47 virtual void UpdateBackgroundColor(); |
| 47 virtual void UpdateReadOnly(); | 48 virtual void UpdateReadOnly(); |
| 48 virtual void UpdateFont(); | 49 virtual void UpdateFont(); |
| 49 virtual void UpdateEnabled(); | 50 virtual void UpdateEnabled(); |
| 50 virtual void SetHorizontalMargins(int left, int right); | 51 virtual void SetHorizontalMargins(int left, int right); |
| 51 virtual void SetFocus(); | 52 virtual void SetFocus(); |
| 52 virtual View* GetView(); | 53 virtual View* GetView(); |
| 53 virtual gfx::NativeView GetTestingHandle() const; | 54 virtual gfx::NativeView GetTestingHandle() const; |
| 54 | 55 |
| 56 // Overridden from SimpleMenuModel::Delegate: |
| 57 virtual bool IsCommandIdChecked(int command_id) const; |
| 58 virtual bool IsCommandIdEnabled(int command_id) const; |
| 59 virtual bool GetAcceleratorForCommandId(int command_id, |
| 60 Accelerator* accelerator); |
| 61 virtual void ExecuteCommand(int command_id); |
| 62 |
| 55 // CWindowImpl | 63 // CWindowImpl |
| 56 BEGIN_MSG_MAP(Edit) | 64 BEGIN_MSG_MAP(Edit) |
| 57 MSG_WM_CHAR(OnChar) | 65 MSG_WM_CHAR(OnChar) |
| 58 MSG_WM_CONTEXTMENU(OnContextMenu) | 66 MSG_WM_CONTEXTMENU(OnContextMenu) |
| 59 MSG_WM_COPY(OnCopy) | 67 MSG_WM_COPY(OnCopy) |
| 60 MSG_WM_CUT(OnCut) | 68 MSG_WM_CUT(OnCut) |
| 61 MESSAGE_HANDLER_EX(WM_IME_CHAR, OnImeChar) | 69 MESSAGE_HANDLER_EX(WM_IME_CHAR, OnImeChar) |
| 62 MESSAGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, OnImeStartComposition) | 70 MESSAGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, OnImeStartComposition) |
| 63 MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeComposition) | 71 MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeComposition) |
| 64 MESSAGE_HANDLER_EX(WM_IME_ENDCOMPOSITION, OnImeEndComposition) | 72 MESSAGE_HANDLER_EX(WM_IME_ENDCOMPOSITION, OnImeEndComposition) |
| 65 MSG_WM_KEYDOWN(OnKeyDown) | 73 MSG_WM_KEYDOWN(OnKeyDown) |
| 66 MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) | 74 MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) |
| 67 MSG_WM_LBUTTONDOWN(OnLButtonDown) | 75 MSG_WM_LBUTTONDOWN(OnLButtonDown) |
| 68 MSG_WM_LBUTTONUP(OnLButtonUp) | 76 MSG_WM_LBUTTONUP(OnLButtonUp) |
| 69 MSG_WM_MBUTTONDOWN(OnNonLButtonDown) | 77 MSG_WM_MBUTTONDOWN(OnNonLButtonDown) |
| 70 MSG_WM_MOUSEMOVE(OnMouseMove) | 78 MSG_WM_MOUSEMOVE(OnMouseMove) |
| 71 MSG_WM_MOUSELEAVE(OnMouseLeave) | 79 MSG_WM_MOUSELEAVE(OnMouseLeave) |
| 72 MESSAGE_HANDLER_EX(WM_MOUSEWHEEL, OnMouseWheel) | 80 MESSAGE_HANDLER_EX(WM_MOUSEWHEEL, OnMouseWheel) |
| 73 MSG_WM_NCCALCSIZE(OnNCCalcSize) | 81 MSG_WM_NCCALCSIZE(OnNCCalcSize) |
| 74 MSG_WM_NCPAINT(OnNCPaint) | 82 MSG_WM_NCPAINT(OnNCPaint) |
| 75 MSG_WM_RBUTTONDOWN(OnNonLButtonDown) | 83 MSG_WM_RBUTTONDOWN(OnNonLButtonDown) |
| 76 MSG_WM_PASTE(OnPaste) | 84 MSG_WM_PASTE(OnPaste) |
| 77 MSG_WM_SETFOCUS(OnSetFocus) | 85 MSG_WM_SETFOCUS(OnSetFocus) |
| 78 MSG_WM_SYSCHAR(OnSysChar) // WM_SYSxxx == WM_xxx with ALT down | 86 MSG_WM_SYSCHAR(OnSysChar) // WM_SYSxxx == WM_xxx with ALT down |
| 79 MSG_WM_SYSKEYDOWN(OnKeyDown) | 87 MSG_WM_SYSKEYDOWN(OnKeyDown) |
| 80 END_MSG_MAP() | 88 END_MSG_MAP() |
| 81 | 89 |
| 82 // Menu::Delegate | |
| 83 virtual bool IsCommandEnabled(int id) const; | |
| 84 virtual void ExecuteCommand(int id); | |
| 85 | |
| 86 private: | 90 private: |
| 87 // This object freezes repainting of the edit until the object is destroyed. | 91 // This object freezes repainting of the edit until the object is destroyed. |
| 88 // Some methods of the CRichEditCtrl draw synchronously to the screen. If we | 92 // Some methods of the CRichEditCtrl draw synchronously to the screen. If we |
| 89 // don't freeze, the user will see a rapid series of calls to these as | 93 // don't freeze, the user will see a rapid series of calls to these as |
| 90 // flickers. | 94 // flickers. |
| 91 // | 95 // |
| 92 // Freezing the control while it is already frozen is permitted; the control | 96 // Freezing the control while it is already frozen is permitted; the control |
| 93 // will unfreeze once both freezes are released (the freezes stack). | 97 // will unfreeze once both freezes are released (the freezes stack). |
| 94 class ScopedFreeze { | 98 class ScopedFreeze { |
| 95 public: | 99 public: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 153 |
| 150 // Sets whether the mouse is in the edit. As necessary this redraws the | 154 // Sets whether the mouse is in the edit. As necessary this redraws the |
| 151 // edit. | 155 // edit. |
| 152 void SetContainsMouse(bool contains_mouse); | 156 void SetContainsMouse(bool contains_mouse); |
| 153 | 157 |
| 154 // Getter for the text_object_model_, used by the ScopedFreeze class. Note | 158 // Getter for the text_object_model_, used by the ScopedFreeze class. Note |
| 155 // that the pointer returned here is only valid as long as the Edit is still | 159 // that the pointer returned here is only valid as long as the Edit is still |
| 156 // alive. | 160 // alive. |
| 157 ITextDocument* GetTextObjectModel() const; | 161 ITextDocument* GetTextObjectModel() const; |
| 158 | 162 |
| 163 // Generates the contents of the context menu. |
| 164 void BuildContextMenu(); |
| 165 |
| 159 // The Textfield this object is bound to. | 166 // The Textfield this object is bound to. |
| 160 Textfield* textfield_; | 167 Textfield* textfield_; |
| 161 | 168 |
| 162 // We need to know if the user triple-clicks, so track double click points | 169 // We need to know if the user triple-clicks, so track double click points |
| 163 // and times so we can see if subsequent clicks are actually triple clicks. | 170 // and times so we can see if subsequent clicks are actually triple clicks. |
| 164 bool tracking_double_click_; | 171 bool tracking_double_click_; |
| 165 CPoint double_click_point_; | 172 CPoint double_click_point_; |
| 166 DWORD double_click_time_; | 173 DWORD double_click_time_; |
| 167 | 174 |
| 168 // Used to discard unnecessary WM_MOUSEMOVE events after the first such | 175 // Used to discard unnecessary WM_MOUSEMOVE events after the first such |
| 169 // unnecessary event. See detailed comments in OnMouseMove(). | 176 // unnecessary event. See detailed comments in OnMouseMove(). |
| 170 bool can_discard_mousemove_; | 177 bool can_discard_mousemove_; |
| 171 | 178 |
| 172 // The text of this control before a possible change. | 179 // The text of this control before a possible change. |
| 173 std::wstring text_before_change_; | 180 std::wstring text_before_change_; |
| 174 | 181 |
| 175 // If true, the mouse is over the edit. | 182 // If true, the mouse is over the edit. |
| 176 bool contains_mouse_; | 183 bool contains_mouse_; |
| 177 | 184 |
| 178 static bool did_load_library_; | 185 static bool did_load_library_; |
| 179 | 186 |
| 180 // The context menu for the edit. | 187 // The contents of the context menu for the edit. |
| 181 scoped_ptr<Menu> context_menu_; | 188 scoped_ptr<SimpleMenuModel> context_menu_contents_; |
| 189 scoped_ptr<Menu2> context_menu_; |
| 182 | 190 |
| 183 // Border insets. | 191 // Border insets. |
| 184 gfx::Insets content_insets_; | 192 gfx::Insets content_insets_; |
| 185 | 193 |
| 186 // This interface is useful for accessing the CRichEditCtrl at a low level. | 194 // This interface is useful for accessing the CRichEditCtrl at a low level. |
| 187 mutable CComQIPtr<ITextDocument> text_object_model_; | 195 mutable CComQIPtr<ITextDocument> text_object_model_; |
| 188 | 196 |
| 189 // The position and the length of the ongoing composition string. | 197 // The position and the length of the ongoing composition string. |
| 190 // These values are used for removing a composition string from a search | 198 // These values are used for removing a composition string from a search |
| 191 // text to emulate Firefox. | 199 // text to emulate Firefox. |
| 192 bool ime_discard_composition_; | 200 bool ime_discard_composition_; |
| 193 int ime_composition_start_; | 201 int ime_composition_start_; |
| 194 int ime_composition_length_; | 202 int ime_composition_length_; |
| 195 | 203 |
| 196 // TODO(beng): remove this when we are a subclass of NativeControlWin. | 204 // TODO(beng): remove this when we are a subclass of NativeControlWin. |
| 197 NativeViewHost* container_view_; | 205 NativeViewHost* container_view_; |
| 198 | 206 |
| 199 COLORREF bg_color_; | 207 COLORREF bg_color_; |
| 200 | 208 |
| 201 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldWin); | 209 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldWin); |
| 202 }; | 210 }; |
| 203 | 211 |
| 204 } // namespace views | 212 } // namespace views |
| 205 | 213 |
| 206 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ | 214 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ |
| OLD | NEW |