| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // text is displayed correctly in right-to-left UIs. | 58 // text is displayed correctly in right-to-left UIs. |
| 59 base::i18n::AdjustStringForLocaleDirection(&text); | 59 base::i18n::AdjustStringForLocaleDirection(&text); |
| 60 | 60 |
| 61 SendMessage(native_view(), CB_ADDSTRING, 0, | 61 SendMessage(native_view(), CB_ADDSTRING, 0, |
| 62 reinterpret_cast<LPARAM>(UTF16ToWide(text).c_str())); | 62 reinterpret_cast<LPARAM>(UTF16ToWide(text).c_str())); |
| 63 max_width = std::max(max_width, font.GetStringWidth(text)); | 63 max_width = std::max(max_width, font.GetStringWidth(text)); |
| 64 } | 64 } |
| 65 content_width_ = max_width; | 65 content_width_ = max_width; |
| 66 | 66 |
| 67 if (num_items > 0) { | 67 if (num_items > 0) { |
| 68 SendMessage(native_view(), CB_SETCURSEL, combobox_->selected_item(), 0); | 68 SendMessage(native_view(), CB_SETCURSEL, combobox_->selected_index(), 0); |
| 69 | 69 |
| 70 // Set the width for the drop down while accounting for the scrollbar and | 70 // Set the width for the drop down while accounting for the scrollbar and |
| 71 // borders. | 71 // borders. |
| 72 if (num_items > ComboBox_GetMinVisible(native_view())) | 72 if (num_items > ComboBox_GetMinVisible(native_view())) |
| 73 max_width += GetSystemMetrics(SM_CXVSCROLL); | 73 max_width += GetSystemMetrics(SM_CXVSCROLL); |
| 74 // SM_CXEDGE would not be correct here, since the dropdown is flat, not 3D. | 74 // SM_CXEDGE would not be correct here, since the dropdown is flat, not 3D. |
| 75 int kComboboxDropdownBorderSize = 1; | 75 int kComboboxDropdownBorderSize = 1; |
| 76 max_width += 2 * kComboboxDropdownBorderSize + kComboboxExtraPaddingX; | 76 max_width += 2 * kComboboxDropdownBorderSize + kComboboxExtraPaddingX; |
| 77 SendMessage(native_view(), CB_SETDROPPEDWIDTH, max_width, 0); | 77 SendMessage(native_view(), CB_SETDROPPEDWIDTH, max_width, 0); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 void NativeComboboxWin::UpdateSelectedItem() { | 81 void NativeComboboxWin::UpdateSelectedIndex() { |
| 82 // Note that we use CB_SETCURSEL and not CB_SELECTSTRING because on RTL | 82 // Note that we use CB_SETCURSEL and not CB_SELECTSTRING because on RTL |
| 83 // locales the strings we get from our ComboBox::Model might be augmented | 83 // locales the strings we get from our ComboBox::Model might be augmented |
| 84 // with Unicode directionality marks before we insert them into the combo box | 84 // with Unicode directionality marks before we insert them into the combo box |
| 85 // and therefore we can not assume that the string we get from | 85 // and therefore we can not assume that the string we get from |
| 86 // ComboBox::Model can be safely searched for and selected (which is what | 86 // ComboBox::Model can be safely searched for and selected (which is what |
| 87 // CB_SELECTSTRING does). | 87 // CB_SELECTSTRING does). |
| 88 SendMessage(native_view(), CB_SETCURSEL, combobox_->selected_item(), 0); | 88 SendMessage(native_view(), CB_SETCURSEL, combobox_->selected_index(), 0); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void NativeComboboxWin::UpdateEnabled() { | 91 void NativeComboboxWin::UpdateEnabled() { |
| 92 SetEnabled(combobox_->enabled()); | 92 SetEnabled(combobox_->enabled()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 int NativeComboboxWin::GetSelectedItem() const { | 95 int NativeComboboxWin::GetSelectedIndex() const { |
| 96 LRESULT selected_item = SendMessage(native_view(), CB_GETCURSEL, 0, 0); | 96 LRESULT selected_index = SendMessage(native_view(), CB_GETCURSEL, 0, 0); |
| 97 return selected_item != CB_ERR ? selected_item : -1; | 97 return selected_index != CB_ERR ? selected_index : -1; |
| 98 } | 98 } |
| 99 | 99 |
| 100 bool NativeComboboxWin::IsDropdownOpen() const { | 100 bool NativeComboboxWin::IsDropdownOpen() const { |
| 101 return SendMessage(native_view(), CB_GETDROPPEDSTATE, 0, 0) != 0; | 101 return SendMessage(native_view(), CB_GETDROPPEDSTATE, 0, 0) != 0; |
| 102 } | 102 } |
| 103 | 103 |
| 104 gfx::Size NativeComboboxWin::GetPreferredSize() { | 104 gfx::Size NativeComboboxWin::GetPreferredSize() { |
| 105 COMBOBOXINFO cbi = { 0 }; | 105 COMBOBOXINFO cbi = { 0 }; |
| 106 cbi.cbSize = sizeof(cbi); | 106 cbi.cbSize = sizeof(cbi); |
| 107 // Note: Don't use CB_GETCOMBOBOXINFO since that crashes on WOW64 systems | 107 // Note: Don't use CB_GETCOMBOBOXINFO since that crashes on WOW64 systems |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 206 |
| 207 // static | 207 // static |
| 208 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( | 208 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( |
| 209 Combobox* combobox) { | 209 Combobox* combobox) { |
| 210 if (Widget::IsPureViews()) | 210 if (Widget::IsPureViews()) |
| 211 return new NativeComboboxViews(combobox); | 211 return new NativeComboboxViews(combobox); |
| 212 return new NativeComboboxWin(combobox); | 212 return new NativeComboboxWin(combobox); |
| 213 } | 213 } |
| 214 | 214 |
| 215 } // namespace views | 215 } // namespace views |
| OLD | NEW |