summaryrefslogtreecommitdiffstats
path: root/views/controls/textfield/native_textfield_win.cc
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 20:44:28 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 20:44:28 +0000
commitcdb4266b62202b44eb1fb36877398c2cb5504917 (patch)
tree60f5de9c0460d67cd7150ba5f2e33499892c38b2 /views/controls/textfield/native_textfield_win.cc
parentf148ed7a47e14416efd1cc2666ea331fbcf5aa42 (diff)
downloadchromium_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/textfield/native_textfield_win.cc')
-rw-r--r--views/controls/textfield/native_textfield_win.cc67
1 files changed, 45 insertions, 22 deletions
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: