| 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 #include "views/controls/text_field.h" | 5 #include "views/controls/text_field.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlapp.h> | 8 #include <atlapp.h> |
| 9 #include <atlcrack.h> | 9 #include <atlcrack.h> |
| 10 #include <atlctrls.h> | 10 #include <atlctrls.h> |
| 11 #include <atlmisc.h> | 11 #include <atlmisc.h> |
| 12 #include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl | 12 #include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl |
| 13 #include <vsstyle.h> | 13 #include <vsstyle.h> |
| 14 | 14 |
| 15 #include "app/gfx/insets.h" | 15 #include "app/gfx/insets.h" |
| 16 #include "app/l10n_util.h" | 16 #include "app/l10n_util.h" |
| 17 #include "app/l10n_util_win.h" | 17 #include "app/l10n_util_win.h" |
| 18 #include "app/win_util.h" | 18 #include "app/win_util.h" |
| 19 #include "base/clipboard.h" | 19 #include "base/clipboard.h" |
| 20 #include "base/gfx/native_theme.h" | 20 #include "base/gfx/native_theme.h" |
| 21 #include "base/scoped_clipboard_writer.h" | 21 #include "base/scoped_clipboard_writer.h" |
| 22 #include "base/string_util.h" | 22 #include "base/string_util.h" |
| 23 #include "base/win_util.h" | 23 #include "base/win_util.h" |
| 24 #include "grit/generated_resources.h" | 24 #include "grit/app_strings.h" |
| 25 #include "skia/ext/skia_utils_win.h" | 25 #include "skia/ext/skia_utils_win.h" |
| 26 #include "views/controls/hwnd_view.h" | 26 #include "views/controls/hwnd_view.h" |
| 27 #include "views/controls/menu/menu_win.h" | 27 #include "views/controls/menu/menu_win.h" |
| 28 #include "views/focus/focus_util_win.h" | 28 #include "views/focus/focus_util_win.h" |
| 29 #include "views/views_delegate.h" | 29 #include "views/views_delegate.h" |
| 30 #include "views/widget/widget.h" | 30 #include "views/widget/widget.h" |
| 31 | 31 |
| 32 using gfx::NativeTheme; | 32 using gfx::NativeTheme; |
| 33 | 33 |
| 34 namespace views { | 34 namespace views { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 DCHECK((parent->GetStyle() & TextField::STYLE_PASSWORD) == 0); | 279 DCHECK((parent->GetStyle() & TextField::STYLE_PASSWORD) == 0); |
| 280 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE); | 280 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE); |
| 281 } | 281 } |
| 282 | 282 |
| 283 // Set up the text_object_model_. | 283 // Set up the text_object_model_. |
| 284 CComPtr<IRichEditOle> ole_interface; | 284 CComPtr<IRichEditOle> ole_interface; |
| 285 ole_interface.Attach(GetOleInterface()); | 285 ole_interface.Attach(GetOleInterface()); |
| 286 text_object_model_ = ole_interface; | 286 text_object_model_ = ole_interface; |
| 287 | 287 |
| 288 context_menu_.reset(new MenuWin(this, Menu::TOPLEFT, m_hWnd)); | 288 context_menu_.reset(new MenuWin(this, Menu::TOPLEFT, m_hWnd)); |
| 289 context_menu_->AppendMenuItemWithLabel(IDS_UNDO, | 289 context_menu_->AppendMenuItemWithLabel(IDS_APP_UNDO, |
| 290 l10n_util::GetString(IDS_UNDO)); | 290 l10n_util::GetString(IDS_APP_UNDO)); |
| 291 context_menu_->AppendSeparator(); | 291 context_menu_->AppendSeparator(); |
| 292 context_menu_->AppendMenuItemWithLabel(IDS_CUT, | 292 context_menu_->AppendMenuItemWithLabel(IDS_APP_CUT, |
| 293 l10n_util::GetString(IDS_CUT)); | 293 l10n_util::GetString(IDS_APP_CUT)); |
| 294 context_menu_->AppendMenuItemWithLabel(IDS_COPY, | 294 context_menu_->AppendMenuItemWithLabel(IDS_APP_COPY, |
| 295 l10n_util::GetString(IDS_COPY)); | 295 l10n_util::GetString(IDS_APP_COPY)); |
| 296 context_menu_->AppendMenuItemWithLabel(IDS_PASTE, | 296 context_menu_->AppendMenuItemWithLabel(IDS_APP_PASTE, |
| 297 l10n_util::GetString(IDS_PASTE)); | 297 l10n_util::GetString(IDS_APP_PASTE)); |
| 298 context_menu_->AppendSeparator(); | 298 context_menu_->AppendSeparator(); |
| 299 context_menu_->AppendMenuItemWithLabel(IDS_SELECT_ALL, | 299 context_menu_->AppendMenuItemWithLabel(IDS_APP_SELECT_ALL, |
| 300 l10n_util::GetString(IDS_SELECT_ALL)); | 300 l10n_util::GetString(IDS_APP_SELECT_ALL
)); |
| 301 } | 301 } |
| 302 | 302 |
| 303 TextField::Edit::~Edit() { | 303 TextField::Edit::~Edit() { |
| 304 } | 304 } |
| 305 | 305 |
| 306 std::wstring TextField::Edit::GetText() const { | 306 std::wstring TextField::Edit::GetText() const { |
| 307 int len = GetTextLength() + 1; | 307 int len = GetTextLength() + 1; |
| 308 std::wstring str; | 308 std::wstring str; |
| 309 GetWindowText(WriteInto(&str, len), len); | 309 GetWindowText(WriteInto(&str, len), len); |
| 310 return str; | 310 return str; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 static_cast<WPARAM>(enabled), 0); | 366 static_cast<WPARAM>(enabled), 0); |
| 367 } | 367 } |
| 368 | 368 |
| 369 void TextField::Edit::SetBackgroundColor(COLORREF bg_color) { | 369 void TextField::Edit::SetBackgroundColor(COLORREF bg_color) { |
| 370 CRichEditCtrl::SetBackgroundColor(bg_color); | 370 CRichEditCtrl::SetBackgroundColor(bg_color); |
| 371 bg_color_ = bg_color; | 371 bg_color_ = bg_color; |
| 372 } | 372 } |
| 373 | 373 |
| 374 bool TextField::Edit::IsCommandEnabled(int id) const { | 374 bool TextField::Edit::IsCommandEnabled(int id) const { |
| 375 switch (id) { | 375 switch (id) { |
| 376 case IDS_UNDO: return !parent_->IsReadOnly() && !!CanUndo(); | 376 case IDS_APP_UNDO: return !parent_->IsReadOnly() && !!CanUndo(); |
| 377 case IDS_CUT: return !parent_->IsReadOnly() && | 377 case IDS_APP_CUT: return !parent_->IsReadOnly() && |
| 378 !parent_->IsPassword() && !!CanCut(); | 378 !parent_->IsPassword() && !!CanCut(); |
| 379 case IDS_COPY: return !!CanCopy() && !parent_->IsPassword(); | 379 case IDS_APP_COPY: return !!CanCopy() && !parent_->IsPassword(); |
| 380 case IDS_PASTE: return !parent_->IsReadOnly() && !!CanPaste(); | 380 case IDS_APP_PASTE: return !parent_->IsReadOnly() && !!CanPaste(); |
| 381 case IDS_SELECT_ALL: return !!CanSelectAll(); | 381 case IDS_APP_SELECT_ALL: return !!CanSelectAll(); |
| 382 default: NOTREACHED(); | 382 default: NOTREACHED(); |
| 383 return false; | 383 return false; |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 | 386 |
| 387 void TextField::Edit::ExecuteCommand(int id) { | 387 void TextField::Edit::ExecuteCommand(int id) { |
| 388 ScopedFreeze freeze(this, GetTextObjectModel()); | 388 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 389 OnBeforePossibleChange(); | 389 OnBeforePossibleChange(); |
| 390 switch (id) { | 390 switch (id) { |
| 391 case IDS_UNDO: Undo(); break; | 391 case IDS_APP_UNDO: Undo(); break; |
| 392 case IDS_CUT: Cut(); break; | 392 case IDS_APP_CUT: Cut(); break; |
| 393 case IDS_COPY: Copy(); break; | 393 case IDS_APP_COPY: Copy(); break; |
| 394 case IDS_PASTE: Paste(); break; | 394 case IDS_APP_PASTE: Paste(); break; |
| 395 case IDS_SELECT_ALL: SelectAll(); break; | 395 case IDS_APP_SELECT_ALL: SelectAll(); break; |
| 396 default: NOTREACHED(); break; | 396 default: NOTREACHED(); break; |
| 397 } | 397 } |
| 398 OnAfterPossibleChange(); | 398 OnAfterPossibleChange(); |
| 399 } | 399 } |
| 400 | 400 |
| 401 void TextField::Edit::OnChar(TCHAR ch, UINT repeat_count, UINT flags) { | 401 void TextField::Edit::OnChar(TCHAR ch, UINT repeat_count, UINT flags) { |
| 402 HandleKeystroke(GetCurrentMessage()->message, ch, repeat_count, flags); | 402 HandleKeystroke(GetCurrentMessage()->message, ch, repeat_count, flags); |
| 403 } | 403 } |
| 404 | 404 |
| 405 void TextField::Edit::OnContextMenu(HWND window, const CPoint& point) { | 405 void TextField::Edit::OnContextMenu(HWND window, const CPoint& point) { |
| 406 CPoint p(point); | 406 CPoint p(point); |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 | 1171 |
| 1172 COLORREF bg_color; | 1172 COLORREF bg_color; |
| 1173 if (!use_default_background_color_) | 1173 if (!use_default_background_color_) |
| 1174 bg_color = skia::SkColorToCOLORREF(background_color_); | 1174 bg_color = skia::SkColorToCOLORREF(background_color_); |
| 1175 else | 1175 else |
| 1176 bg_color = GetSysColor(read_only_ ? COLOR_3DFACE : COLOR_WINDOW); | 1176 bg_color = GetSysColor(read_only_ ? COLOR_3DFACE : COLOR_WINDOW); |
| 1177 edit_->SetBackgroundColor(bg_color); | 1177 edit_->SetBackgroundColor(bg_color); |
| 1178 } | 1178 } |
| 1179 | 1179 |
| 1180 } // namespace views | 1180 } // namespace views |
| OLD | NEW |