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 } // namespace |
| 28 |
| 29 namespace views { |
26 | 30 |
27 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
28 // NativeComboboxWin, public: | 32 // NativeComboboxWin, public: |
29 | 33 |
30 NativeComboboxWin::NativeComboboxWin(Combobox* combobox) | 34 NativeComboboxWin::NativeComboboxWin(Combobox* combobox) |
31 : combobox_(combobox), | 35 : combobox_(combobox), |
32 content_width_(0) { | 36 content_width_(0) { |
33 // Associates the actual HWND with the combobox so it is the one considered as | 37 // 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 | 38 // having the focus (not the wrapper) when the HWND is focused directly (with |
35 // a click for example). | 39 // a click for example). |
36 set_focus_view(combobox); | 40 set_focus_view(combobox); |
37 } | 41 } |
38 | 42 |
39 NativeComboboxWin::~NativeComboboxWin() { | 43 NativeComboboxWin::~NativeComboboxWin() { |
40 } | 44 } |
41 | 45 |
42 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
43 // NativeComboboxWin, NativeComboboxWrapper implementation: | 47 // NativeComboboxWin, NativeComboboxWrapper implementation: |
44 | 48 |
45 void NativeComboboxWin::UpdateFromModel() { | 49 void NativeComboboxWin::UpdateFromModel() { |
46 SendMessage(native_view(), CB_RESETCONTENT, 0, 0); | 50 SendMessage(native_view(), CB_RESETCONTENT, 0, 0); |
47 gfx::Font font = ResourceBundle::GetSharedInstance().GetFont( | 51 const gfx::Font& font = Combobox::GetFont(); |
48 ResourceBundle::BaseFont); | |
49 int max_width = 0; | 52 int max_width = 0; |
50 int num_items = combobox_->model()->GetItemCount(); | 53 int num_items = combobox_->model()->GetItemCount(); |
51 for (int i = 0; i < num_items; ++i) { | 54 for (int i = 0; i < num_items; ++i) { |
52 string16 text = combobox_->model()->GetItemAt(i); | 55 string16 text = combobox_->model()->GetItemAt(i); |
53 | 56 |
54 // Inserting the Unicode formatting characters if necessary so that the | 57 // Inserting the Unicode formatting characters if necessary so that the |
55 // text is displayed correctly in right-to-left UIs. | 58 // text is displayed correctly in right-to-left UIs. |
56 base::i18n::AdjustStringForLocaleDirection(&text); | 59 base::i18n::AdjustStringForLocaleDirection(&text); |
57 | 60 |
58 SendMessage(native_view(), CB_ADDSTRING, 0, | 61 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) { | 190 void NativeComboboxWin::NativeControlCreated(HWND native_control) { |
188 NativeControlWin::NativeControlCreated(native_control); | 191 NativeControlWin::NativeControlCreated(native_control); |
189 | 192 |
190 UpdateFont(); | 193 UpdateFont(); |
191 } | 194 } |
192 | 195 |
193 //////////////////////////////////////////////////////////////////////////////// | 196 //////////////////////////////////////////////////////////////////////////////// |
194 // NativeComboboxWin, private: | 197 // NativeComboboxWin, private: |
195 | 198 |
196 void NativeComboboxWin::UpdateFont() { | 199 void NativeComboboxWin::UpdateFont() { |
197 HFONT font = ResourceBundle::GetSharedInstance(). | 200 HFONT font = Combobox::GetFont().GetNativeFont(); |
198 GetFont(ResourceBundle::BaseFont).GetNativeFont(); | |
199 SendMessage(native_view(), WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE); | 201 SendMessage(native_view(), WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE); |
200 } | 202 } |
201 | 203 |
202 //////////////////////////////////////////////////////////////////////////////// | 204 //////////////////////////////////////////////////////////////////////////////// |
203 // NativeComboboxWrapper, public: | 205 // NativeComboboxWrapper, public: |
204 | 206 |
205 // static | 207 // static |
206 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( | 208 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( |
207 Combobox* combobox) { | 209 Combobox* combobox) { |
208 if (Widget::IsPureViews()) | 210 if (Widget::IsPureViews()) |
209 return new NativeComboboxViews(combobox); | 211 return new NativeComboboxViews(combobox); |
210 return new NativeComboboxWin(combobox); | 212 return new NativeComboboxWin(combobox); |
211 } | 213 } |
212 | 214 |
213 } // namespace views | 215 } // namespace views |
OLD | NEW |