| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/combobox/native_combobox_win.h" | 5 #include "ui/views/controls/combobox/native_combobox_win.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "ui/base/models/combobox_model.h" | 9 #include "ui/base/models/combobox_model.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/base/win/hwnd_util.h" | 11 #include "ui/base/win/hwnd_util.h" |
| 12 #include "ui/gfx/font.h" | 12 #include "ui/gfx/font.h" |
| 13 #include "ui/gfx/native_theme_win.h" | 13 #include "ui/gfx/native_theme_win.h" |
| 14 #include "ui/views/controls/combobox/combobox.h" | 14 #include "ui/views/controls/combobox/combobox.h" |
| 15 #include "ui/views/controls/combobox/native_combobox_views.h" | 15 #include "ui/views/controls/combobox/native_combobox_views.h" |
| 16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 17 | 17 |
| 18 namespace views { | 18 namespace { |
| 19 | 19 |
| 20 // Limit how small a combobox can be. | 20 // Limit how small a combobox can be. |
| 21 static const int kMinComboboxWidth = 148; | 21 const int kMinComboboxWidth = 148; |
| 22 | 22 |
| 23 // Add a couple extra pixels to the widths of comboboxes and combobox | 23 // Add a couple extra pixels to the widths of comboboxes and combobox |
| 24 // dropdowns so that text isn't too crowded. | 24 // dropdowns so that text isn't too crowded. |
| 25 static const int kComboboxExtraPaddingX = 6; | 25 const int kComboboxExtraPaddingX = 6; |
| 26 |
| 27 const gfx::Font& GetFont() { |
| 28 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 29 return rb.GetFont(ui::ResourceBundle::BaseFont); |
| 30 } |
| 31 |
| 32 } // namespace |
| 33 |
| 34 namespace views { |
| 26 | 35 |
| 27 //////////////////////////////////////////////////////////////////////////////// | 36 //////////////////////////////////////////////////////////////////////////////// |
| 28 // NativeComboboxWin, public: | 37 // NativeComboboxWin, public: |
| 29 | 38 |
| 30 NativeComboboxWin::NativeComboboxWin(Combobox* combobox) | 39 NativeComboboxWin::NativeComboboxWin(Combobox* combobox) |
| 31 : combobox_(combobox), | 40 : combobox_(combobox), |
| 32 content_width_(0) { | 41 content_width_(0) { |
| 33 // Associates the actual HWND with the combobox so it is the one considered as | 42 // Associates the actual HWND with the combobox so it is the one considered as |
| 34 // having the focus (not the wrapper) when the HWND is focused directly (with | 43 // having the focus (not the wrapper) when the HWND is focused directly (with |
| 35 // a click for example). | 44 // a click for example). |
| 36 set_focus_view(combobox); | 45 set_focus_view(combobox); |
| 37 } | 46 } |
| 38 | 47 |
| 39 NativeComboboxWin::~NativeComboboxWin() { | 48 NativeComboboxWin::~NativeComboboxWin() { |
| 40 } | 49 } |
| 41 | 50 |
| 42 //////////////////////////////////////////////////////////////////////////////// | 51 //////////////////////////////////////////////////////////////////////////////// |
| 43 // NativeComboboxWin, NativeComboboxWrapper implementation: | 52 // NativeComboboxWin, NativeComboboxWrapper implementation: |
| 44 | 53 |
| 45 void NativeComboboxWin::UpdateFromModel() { | 54 void NativeComboboxWin::UpdateFromModel() { |
| 46 SendMessage(native_view(), CB_RESETCONTENT, 0, 0); | 55 SendMessage(native_view(), CB_RESETCONTENT, 0, 0); |
| 47 gfx::Font font = ResourceBundle::GetSharedInstance().GetFont( | 56 const gfx::Font& font = GetFont(); |
| 48 ResourceBundle::BaseFont); | |
| 49 int max_width = 0; | 57 int max_width = 0; |
| 50 int num_items = combobox_->model()->GetItemCount(); | 58 int num_items = combobox_->model()->GetItemCount(); |
| 51 for (int i = 0; i < num_items; ++i) { | 59 for (int i = 0; i < num_items; ++i) { |
| 52 string16 text = combobox_->model()->GetItemAt(i); | 60 string16 text = combobox_->model()->GetItemAt(i); |
| 53 | 61 |
| 54 // Inserting the Unicode formatting characters if necessary so that the | 62 // Inserting the Unicode formatting characters if necessary so that the |
| 55 // text is displayed correctly in right-to-left UIs. | 63 // text is displayed correctly in right-to-left UIs. |
| 56 base::i18n::AdjustStringForLocaleDirection(&text); | 64 base::i18n::AdjustStringForLocaleDirection(&text); |
| 57 | 65 |
| 58 SendMessage(native_view(), CB_ADDSTRING, 0, | 66 SendMessage(native_view(), CB_ADDSTRING, 0, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 void NativeComboboxWin::NativeControlCreated(HWND native_control) { | 195 void NativeComboboxWin::NativeControlCreated(HWND native_control) { |
| 188 NativeControlWin::NativeControlCreated(native_control); | 196 NativeControlWin::NativeControlCreated(native_control); |
| 189 | 197 |
| 190 UpdateFont(); | 198 UpdateFont(); |
| 191 } | 199 } |
| 192 | 200 |
| 193 //////////////////////////////////////////////////////////////////////////////// | 201 //////////////////////////////////////////////////////////////////////////////// |
| 194 // NativeComboboxWin, private: | 202 // NativeComboboxWin, private: |
| 195 | 203 |
| 196 void NativeComboboxWin::UpdateFont() { | 204 void NativeComboboxWin::UpdateFont() { |
| 197 HFONT font = ResourceBundle::GetSharedInstance(). | 205 HFONT font = GetFont().GetNativeFont(); |
| 198 GetFont(ResourceBundle::BaseFont).GetNativeFont(); | |
| 199 SendMessage(native_view(), WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE); | 206 SendMessage(native_view(), WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE); |
| 200 } | 207 } |
| 201 | 208 |
| 202 //////////////////////////////////////////////////////////////////////////////// | 209 //////////////////////////////////////////////////////////////////////////////// |
| 203 // NativeComboboxWrapper, public: | 210 // NativeComboboxWrapper, public: |
| 204 | 211 |
| 205 // static | 212 // static |
| 206 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( | 213 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( |
| 207 Combobox* combobox) { | 214 Combobox* combobox) { |
| 208 if (Widget::IsPureViews()) | 215 if (Widget::IsPureViews()) |
| 209 return new NativeComboboxViews(combobox); | 216 return new NativeComboboxViews(combobox); |
| 210 return new NativeComboboxWin(combobox); | 217 return new NativeComboboxWin(combobox); |
| 211 } | 218 } |
| 212 | 219 |
| 213 } // namespace views | 220 } // namespace views |
| OLD | NEW |