diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-12 20:44:28 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-12 20:44:28 +0000 |
commit | cdb4266b62202b44eb1fb36877398c2cb5504917 (patch) | |
tree | 60f5de9c0460d67cd7150ba5f2e33499892c38b2 /views/controls | |
parent | f148ed7a47e14416efd1cc2666ea331fbcf5aa42 (diff) | |
download | chromium_src-cdb4266b62202b44eb1fb36877398c2cb5504917.zip chromium_src-cdb4266b62202b44eb1fb36877398c2cb5504917.tar.gz chromium_src-cdb4266b62202b44eb1fb36877398c2cb5504917.tar.bz2 |
Remove the Menu object, converting all the remaining callers to use Menu2. I'll rename Menu2->Menu afterwards.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/122027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r-- | views/controls/menu/menu_2.cc | 4 | ||||
-rw-r--r-- | views/controls/menu/menu_2.h | 4 | ||||
-rw-r--r-- | views/controls/menu/native_menu_win.cc | 7 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_win.cc | 67 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_win.h | 22 |
5 files changed, 72 insertions, 32 deletions
diff --git a/views/controls/menu/menu_2.cc b/views/controls/menu/menu_2.cc index 8ce63b6..2a0ed56 100644 --- a/views/controls/menu/menu_2.cc +++ b/views/controls/menu/menu_2.cc @@ -50,6 +50,10 @@ void Menu2::RunMenuAt(const gfx::Point& point, Alignment alignment) { wrapper_->RunMenuAt(point, alignment); } +void Menu2::RunContextMenuAt(const gfx::Point& point) { + wrapper_->RunMenuAt(point, ALIGN_TOPLEFT); +} + void Menu2::CancelMenu() { wrapper_->CancelMenu(); } diff --git a/views/controls/menu/menu_2.h b/views/controls/menu/menu_2.h index a131ee5..68c4833 100644 --- a/views/controls/menu/menu_2.h +++ b/views/controls/menu/menu_2.h @@ -114,8 +114,10 @@ class Menu2 { }; // Runs the menu at the specified point. This may or may not block, depending - // on the platform and type of menu in use. + // on the platform and type of menu in use. RunContextMenuAt is the same, but + // the alignment is the default for a context menu. void RunMenuAt(const gfx::Point& point, Alignment alignment); + void RunContextMenuAt(const gfx::Point& point); // Cancels the active menu. void CancelMenu(); diff --git a/views/controls/menu/native_menu_win.cc b/views/controls/menu/native_menu_win.cc index c82844e..c5f8331 100644 --- a/views/controls/menu/native_menu_win.cc +++ b/views/controls/menu/native_menu_win.cc @@ -63,7 +63,7 @@ class NativeMenuWin::MenuHostWindow { NativeMenuWin* GetNativeMenuWinFromHMENU(HMENU hmenu) const { MENUINFO mi = {0}; mi.cbSize = sizeof(mi); - mi.fMask = MIM_MENUDATA; + mi.fMask = MIM_MENUDATA | MIM_STYLE; GetMenuInfo(hmenu, &mi); return reinterpret_cast<NativeMenuWin*>(mi.dwMenuData); } @@ -92,7 +92,9 @@ class NativeMenuWin::MenuHostWindow { // Called when the user selects a specific item. void OnMenuCommand(int position, HMENU menu) { - GetNativeMenuWinFromHMENU(menu)->model_->ActivatedAt(position); + NativeMenuWin* intergoat = GetNativeMenuWinFromHMENU(menu); + Menu2Model* model = intergoat->model_; + model->ActivatedAt(position); } // Called as the user moves their mouse or arrows through the contents of the @@ -165,6 +167,7 @@ NativeMenuWin::NativeMenuWin(Menu2Model* model, HWND system_menu_for) NativeMenuWin::~NativeMenuWin() { STLDeleteContainerPointers(items_.begin(), items_.end()); + DestroyMenu(menu_); } //////////////////////////////////////////////////////////////////////////////// diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc index d2044a5..65c6b53 100644 --- a/views/controls/textfield/native_textfield_win.cc +++ b/views/controls/textfield/native_textfield_win.cc @@ -97,21 +97,6 @@ NativeTextfieldWin::NativeTextfieldWin(Textfield* textfield) ole_interface.Attach(GetOleInterface()); text_object_model_ = ole_interface; - context_menu_.reset(new MenuWin(this, Menu::TOPLEFT, m_hWnd)); - context_menu_->AppendMenuItemWithLabel(IDS_APP_UNDO, - l10n_util::GetString(IDS_APP_UNDO)); - context_menu_->AppendSeparator(); - context_menu_->AppendMenuItemWithLabel(IDS_APP_CUT, - l10n_util::GetString(IDS_APP_CUT)); - context_menu_->AppendMenuItemWithLabel(IDS_APP_COPY, - l10n_util::GetString(IDS_APP_COPY)); - context_menu_->AppendMenuItemWithLabel(IDS_APP_PASTE, - l10n_util::GetString(IDS_APP_PASTE)); - context_menu_->AppendSeparator(); - context_menu_->AppendMenuItemWithLabel( - IDS_APP_SELECT_ALL, - l10n_util::GetString(IDS_APP_SELECT_ALL)); - container_view_ = new NativeViewHost; textfield_->AddChildView(container_view_); container_view_->set_focus_view(textfield_); @@ -227,13 +212,17 @@ gfx::NativeView NativeTextfieldWin::GetTestingHandle() const { } //////////////////////////////////////////////////////////////////////////////// -// NativeTextfieldWin, Menu::Delegate implementation: +// NativeTextfieldWin, SimpleMenuModel::Delegate implementation: + +bool NativeTextfieldWin::IsCommandIdChecked(int command_id) const { + return false; +} -bool NativeTextfieldWin::IsCommandEnabled(int id) const { - switch (id) { +bool NativeTextfieldWin::IsCommandIdEnabled(int command_id) const { + switch (command_id) { case IDS_APP_UNDO: return !textfield_->read_only() && !!CanUndo(); case IDS_APP_CUT: return !textfield_->read_only() && - !textfield_->IsPassword() && !!CanCut(); + !textfield_->IsPassword() && !!CanCut(); case IDS_APP_COPY: return !!CanCopy() && !textfield_->IsPassword(); case IDS_APP_PASTE: return !textfield_->read_only() && !!CanPaste(); case IDS_APP_SELECT_ALL: return !!CanSelectAll(); @@ -242,10 +231,28 @@ bool NativeTextfieldWin::IsCommandEnabled(int id) const { } } -void NativeTextfieldWin::ExecuteCommand(int id) { +bool NativeTextfieldWin::GetAcceleratorForCommandId(int command_id, + Accelerator* accelerator) { + // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators + // anywhere so we need to check for them explicitly here. + switch (command_id) { + case IDS_APP_CUT: + *accelerator = views::Accelerator(L'X', false, true, false); + return true; + case IDS_APP_COPY: + *accelerator = views::Accelerator(L'C', false, true, false); + return true; + case IDS_APP_PASTE: + *accelerator = views::Accelerator(L'V', false, true, false); + return true; + } + return container_view_->GetWidget()->GetAccelerator(command_id, accelerator); +} + +void NativeTextfieldWin::ExecuteCommand(int command_id) { ScopedFreeze freeze(this, GetTextObjectModel()); OnBeforePossibleChange(); - switch (id) { + switch (command_id) { case IDS_APP_UNDO: Undo(); break; case IDS_APP_CUT: Cut(); break; case IDS_APP_COPY: Copy(); break; @@ -269,7 +276,8 @@ void NativeTextfieldWin::OnContextMenu(HWND window, const CPoint& point) { GetCaretPos(&p); MapWindowPoints(HWND_DESKTOP, &p, 1); } - context_menu_->RunMenuAt(p.x, p.y); + BuildContextMenu(); + context_menu_->RunContextMenuAt(gfx::Point(p)); } void NativeTextfieldWin::OnCopy() { @@ -837,6 +845,21 @@ ITextDocument* NativeTextfieldWin::GetTextObjectModel() const { return text_object_model_; } +void NativeTextfieldWin::BuildContextMenu() { + if (context_menu_contents_.get()) + return; + context_menu_contents_.reset(new SimpleMenuModel(this)); + context_menu_contents_->AddItemWithStringId(IDS_APP_UNDO, IDS_APP_UNDO); + context_menu_contents_->AddSeparator(); + context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); + context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); + context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); + context_menu_contents_->AddSeparator(); + context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, + IDS_APP_SELECT_ALL); + context_menu_.reset(new Menu2(context_menu_contents_.get())); +} + //////////////////////////////////////////////////////////////////////////////// // NativeTextfieldWrapper, public: diff --git a/views/controls/textfield/native_textfield_win.h b/views/controls/textfield/native_textfield_win.h index 58034c0..514c27f 100644 --- a/views/controls/textfield/native_textfield_win.h +++ b/views/controls/textfield/native_textfield_win.h @@ -13,6 +13,7 @@ #include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl #include <vsstyle.h> +#include "views/controls/menu/simple_menu_model.h" #include "views/controls/textfield/native_textfield_wrapper.h" namespace views { @@ -28,7 +29,7 @@ class NativeTextfieldWin CWinTraits<kDefaultEditStyle> >, public CRichEditCommands<NativeTextfieldWin>, public NativeTextfieldWrapper, - public Menu::Delegate { + public SimpleMenuModel::Delegate { public: DECLARE_WND_CLASS(L"ViewsTextfieldEdit"); @@ -52,6 +53,13 @@ class NativeTextfieldWin virtual View* GetView(); virtual gfx::NativeView GetTestingHandle() const; + // Overridden from SimpleMenuModel::Delegate: + virtual bool IsCommandIdChecked(int command_id) const; + virtual bool IsCommandIdEnabled(int command_id) const; + virtual bool GetAcceleratorForCommandId(int command_id, + Accelerator* accelerator); + virtual void ExecuteCommand(int command_id); + // CWindowImpl BEGIN_MSG_MAP(Edit) MSG_WM_CHAR(OnChar) @@ -79,10 +87,6 @@ class NativeTextfieldWin MSG_WM_SYSKEYDOWN(OnKeyDown) END_MSG_MAP() - // Menu::Delegate - virtual bool IsCommandEnabled(int id) const; - virtual void ExecuteCommand(int id); - private: // This object freezes repainting of the edit until the object is destroyed. // Some methods of the CRichEditCtrl draw synchronously to the screen. If we @@ -156,6 +160,9 @@ class NativeTextfieldWin // alive. ITextDocument* GetTextObjectModel() const; + // Generates the contents of the context menu. + void BuildContextMenu(); + // The Textfield this object is bound to. Textfield* textfield_; @@ -177,8 +184,9 @@ class NativeTextfieldWin static bool did_load_library_; - // The context menu for the edit. - scoped_ptr<Menu> context_menu_; + // The contents of the context menu for the edit. + scoped_ptr<SimpleMenuModel> context_menu_contents_; + scoped_ptr<Menu2> context_menu_; // Border insets. gfx::Insets content_insets_; |