| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/views/text_field.h" | 5 #include "chrome/views/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> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 public CRichEditCommands<TextField::Edit>, | 40 public CRichEditCommands<TextField::Edit>, |
| 41 public Menu::Delegate { | 41 public Menu::Delegate { |
| 42 public: | 42 public: |
| 43 DECLARE_WND_CLASS(L"ChromeViewsTextFieldEdit"); | 43 DECLARE_WND_CLASS(L"ChromeViewsTextFieldEdit"); |
| 44 | 44 |
| 45 Edit(TextField* parent, bool draw_border); | 45 Edit(TextField* parent, bool draw_border); |
| 46 ~Edit(); | 46 ~Edit(); |
| 47 | 47 |
| 48 std::wstring GetText() const; | 48 std::wstring GetText() const; |
| 49 void SetText(const std::wstring& text); | 49 void SetText(const std::wstring& text); |
| 50 void AppendText(const std::wstring& text); |
| 50 | 51 |
| 51 std::wstring GetSelectedText() const; | 52 std::wstring GetSelectedText() const; |
| 52 | 53 |
| 53 // Selects all the text in the edit. Use this in place of SetSelAll() to | 54 // Selects all the text in the edit. Use this in place of SetSelAll() to |
| 54 // avoid selecting the "phantom newline" at the end of the edit. | 55 // avoid selecting the "phantom newline" at the end of the edit. |
| 55 void SelectAll(); | 56 void SelectAll(); |
| 56 | 57 |
| 57 // Clears the selection within the edit field and sets the caret to the end. | 58 // Clears the selection within the edit field and sets the caret to the end. |
| 58 void ClearSelection(); | 59 void ClearSelection(); |
| 59 | 60 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // Adjusting the string direction before setting the text in order to make | 309 // Adjusting the string direction before setting the text in order to make |
| 309 // sure both RTL and LTR strings are displayed properly. | 310 // sure both RTL and LTR strings are displayed properly. |
| 310 std::wstring text_to_set; | 311 std::wstring text_to_set; |
| 311 if (!l10n_util::AdjustStringForLocaleDirection(text, &text_to_set)) | 312 if (!l10n_util::AdjustStringForLocaleDirection(text, &text_to_set)) |
| 312 text_to_set = text; | 313 text_to_set = text; |
| 313 if (parent_->GetStyle() & STYLE_LOWERCASE) | 314 if (parent_->GetStyle() & STYLE_LOWERCASE) |
| 314 text_to_set = l10n_util::ToLower(text_to_set); | 315 text_to_set = l10n_util::ToLower(text_to_set); |
| 315 SetWindowText(text_to_set.c_str()); | 316 SetWindowText(text_to_set.c_str()); |
| 316 } | 317 } |
| 317 | 318 |
| 319 void TextField::Edit::AppendText(const std::wstring& text) { |
| 320 int text_length = GetWindowTextLength(); |
| 321 ::SendMessage(m_hWnd, TBM_SETSEL, true, MAKELPARAM(text_length, text_length)); |
| 322 ::SendMessage(m_hWnd, EM_REPLACESEL, false, |
| 323 reinterpret_cast<LPARAM>(text.c_str())); |
| 324 } |
| 325 |
| 318 std::wstring TextField::Edit::GetSelectedText() const { | 326 std::wstring TextField::Edit::GetSelectedText() const { |
| 319 // Figure out the length of the selection. | 327 // Figure out the length of the selection. |
| 320 long start; | 328 long start; |
| 321 long end; | 329 long end; |
| 322 GetSel(start, end); | 330 GetSel(start, end); |
| 323 | 331 |
| 324 // Grab the selected text. | 332 // Grab the selected text. |
| 325 std::wstring str; | 333 std::wstring str; |
| 326 GetSelText(WriteInto(&str, end - start + 1)); | 334 GetSelText(WriteInto(&str, end - start + 1)); |
| 327 | 335 |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 std::wstring TextField::GetText() const { | 954 std::wstring TextField::GetText() const { |
| 947 return text_; | 955 return text_; |
| 948 } | 956 } |
| 949 | 957 |
| 950 void TextField::SetText(const std::wstring& text) { | 958 void TextField::SetText(const std::wstring& text) { |
| 951 text_ = text; | 959 text_ = text; |
| 952 if (edit_) | 960 if (edit_) |
| 953 edit_->SetText(text); | 961 edit_->SetText(text); |
| 954 } | 962 } |
| 955 | 963 |
| 964 void TextField::AppendText(const std::wstring& text) { |
| 965 text_ += text; |
| 966 if (edit_) |
| 967 edit_->AppendText(text); |
| 968 } |
| 969 |
| 956 void TextField::CalculateInsets(gfx::Insets* insets) { | 970 void TextField::CalculateInsets(gfx::Insets* insets) { |
| 957 DCHECK(insets); | 971 DCHECK(insets); |
| 958 | 972 |
| 959 if (!draw_border_) | 973 if (!draw_border_) |
| 960 return; | 974 return; |
| 961 | 975 |
| 962 // NOTE: One would think GetThemeMargins would return the insets we should | 976 // NOTE: One would think GetThemeMargins would return the insets we should |
| 963 // use, but it doesn't. The margins returned by GetThemeMargins are always | 977 // use, but it doesn't. The margins returned by GetThemeMargins are always |
| 964 // 0. | 978 // 0. |
| 965 | 979 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 | 1101 |
| 1088 COLORREF bg_color; | 1102 COLORREF bg_color; |
| 1089 if (!use_default_background_color_) | 1103 if (!use_default_background_color_) |
| 1090 bg_color = skia::SkColorToCOLORREF(background_color_); | 1104 bg_color = skia::SkColorToCOLORREF(background_color_); |
| 1091 else | 1105 else |
| 1092 bg_color = GetSysColor(read_only_ ? COLOR_3DFACE : COLOR_WINDOW); | 1106 bg_color = GetSysColor(read_only_ ? COLOR_3DFACE : COLOR_WINDOW); |
| 1093 edit_->SetBackgroundColor(bg_color); | 1107 edit_->SetBackgroundColor(bg_color); |
| 1094 } | 1108 } |
| 1095 | 1109 |
| 1096 } // namespace views | 1110 } // namespace views |
| OLD | NEW |