summaryrefslogtreecommitdiffstats
path: root/views/controls/textfield
diff options
context:
space:
mode:
Diffstat (limited to 'views/controls/textfield')
-rw-r--r--views/controls/textfield/native_textfield_win.cc67
-rw-r--r--views/controls/textfield/native_textfield_win.h22
2 files changed, 60 insertions, 29 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:
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_;