| 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/combo_box.h" | 5 #include "chrome/views/combo_box.h" |
| 6 | 6 |
| 7 #include "base/gfx/native_theme.h" | 7 #include "base/gfx/native_theme.h" |
| 8 #include "base/gfx/rect.h" | 8 #include "base/gfx/rect.h" |
| 9 #include "chrome/common/gfx/chrome_canvas.h" | 9 #include "chrome/common/gfx/chrome_canvas.h" |
| 10 #include "chrome/common/gfx/chrome_font.h" | 10 #include "chrome/common/gfx/chrome_font.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 : model_(model), selected_item_(0), listener_(NULL), content_width_(0) { | 23 : model_(model), selected_item_(0), listener_(NULL), content_width_(0) { |
| 24 } | 24 } |
| 25 | 25 |
| 26 ComboBox::~ComboBox() { | 26 ComboBox::~ComboBox() { |
| 27 } | 27 } |
| 28 | 28 |
| 29 void ComboBox::SetListener(Listener* listener) { | 29 void ComboBox::SetListener(Listener* listener) { |
| 30 listener_ = listener; | 30 listener_ = listener; |
| 31 } | 31 } |
| 32 | 32 |
| 33 void ComboBox::GetPreferredSize(CSize* out) { | 33 gfx::Size ComboBox::GetPreferredSize() { |
| 34 HWND hwnd = GetNativeControlHWND(); | 34 HWND hwnd = GetNativeControlHWND(); |
| 35 if (!hwnd) | 35 if (!hwnd) |
| 36 return; | 36 return gfx::Size(); |
| 37 | 37 |
| 38 COMBOBOXINFO cbi; | 38 COMBOBOXINFO cbi; |
| 39 memset(reinterpret_cast<unsigned char*>(&cbi), 0, sizeof(cbi)); | 39 memset(reinterpret_cast<unsigned char*>(&cbi), 0, sizeof(cbi)); |
| 40 cbi.cbSize = sizeof(cbi); | 40 cbi.cbSize = sizeof(cbi); |
| 41 ::SendMessage(hwnd, CB_GETCOMBOBOXINFO, 0, reinterpret_cast<LPARAM>(&cbi)); | 41 ::SendMessage(hwnd, CB_GETCOMBOBOXINFO, 0, reinterpret_cast<LPARAM>(&cbi)); |
| 42 gfx::Rect rect_item(cbi.rcItem); | 42 gfx::Rect rect_item(cbi.rcItem); |
| 43 gfx::Rect rect_button(cbi.rcButton); | 43 gfx::Rect rect_button(cbi.rcButton); |
| 44 gfx::Size border = gfx::NativeTheme::instance()->GetThemeBorderSize( | 44 gfx::Size border = gfx::NativeTheme::instance()->GetThemeBorderSize( |
| 45 gfx::NativeTheme::MENULIST); | 45 gfx::NativeTheme::MENULIST); |
| 46 | 46 |
| 47 // The padding value of '3' is the xy offset from the corner of the control | 47 // The padding value of '3' is the xy offset from the corner of the control |
| 48 // to the corner of rcItem. It does not seem to be queryable from the theme. | 48 // to the corner of rcItem. It does not seem to be queryable from the theme. |
| 49 // It is consistent on all versions of Windows from 2K to Vista, and is | 49 // It is consistent on all versions of Windows from 2K to Vista, and is |
| 50 // invariant with respect to the combobox border size. We could conceivably | 50 // invariant with respect to the combobox border size. We could conceivably |
| 51 // get this number from rect_item.x, but it seems fragile to depend on positio
n | 51 // get this number from rect_item.x, but it seems fragile to depend on positio
n |
| 52 // here, inside of the layout code. | 52 // here, inside of the layout code. |
| 53 const int kItemOffset = 3; | 53 const int kItemOffset = 3; |
| 54 int item_to_button_distance = std::max(kItemOffset - border.width(), 0); | 54 int item_to_button_distance = std::max(kItemOffset - border.width(), 0); |
| 55 | 55 |
| 56 // The cx computation can be read as measuring from left to right. | 56 // The cx computation can be read as measuring from left to right. |
| 57 out->cx = std::max(kItemOffset + content_width_ + kComboboxExtraPaddingX + | 57 int pref_width = std::max(kItemOffset + content_width_ + |
| 58 item_to_button_distance + rect_button.width() + | 58 kComboboxExtraPaddingX + |
| 59 border.width(), kMinComboboxWidth); | 59 item_to_button_distance + rect_button.width() + |
| 60 border.width(), kMinComboboxWidth); |
| 60 // The two arguments to ::max below should be typically be equal. | 61 // The two arguments to ::max below should be typically be equal. |
| 61 out->cy = std::max(rect_item.height() + 2 * kItemOffset, | 62 int pref_height = std::max(rect_item.height() + 2 * kItemOffset, |
| 62 rect_button.height() + 2 * border.height()); | 63 rect_button.height() + 2 * border.height()); |
| 64 return gfx::Size(pref_width, pref_height); |
| 63 } | 65 } |
| 64 | 66 |
| 65 HWND ComboBox::CreateNativeControl(HWND parent_container) { | 67 HWND ComboBox::CreateNativeControl(HWND parent_container) { |
| 66 HWND r = ::CreateWindowEx(GetAdditionalExStyle(), L"COMBOBOX", L"", | 68 HWND r = ::CreateWindowEx(GetAdditionalExStyle(), L"COMBOBOX", L"", |
| 67 WS_CHILD | WS_VSCROLL | CBS_DROPDOWNLIST, | 69 WS_CHILD | WS_VSCROLL | CBS_DROPDOWNLIST, |
| 68 0, 0, width(), height(), | 70 0, 0, width(), height(), |
| 69 parent_container, NULL, NULL, NULL); | 71 parent_container, NULL, NULL, NULL); |
| 70 HFONT font = ResourceBundle::GetSharedInstance(). | 72 HFONT font = ResourceBundle::GetSharedInstance(). |
| 71 GetFont(ResourceBundle::BaseFont).hfont(); | 73 GetFont(ResourceBundle::BaseFont).hfont(); |
| 72 SendMessage(r, WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE); | 74 SendMessage(r, WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // ComboBox::Model can be safely searched for and selected (which is what | 154 // ComboBox::Model can be safely searched for and selected (which is what |
| 153 // CB_SELECTSTRING does). | 155 // CB_SELECTSTRING does). |
| 154 ::SendMessage(hwnd, CB_SETCURSEL, selected_item_, 0); | 156 ::SendMessage(hwnd, CB_SETCURSEL, selected_item_, 0); |
| 155 } | 157 } |
| 156 | 158 |
| 157 int ComboBox::GetSelectedItem() { | 159 int ComboBox::GetSelectedItem() { |
| 158 return selected_item_; | 160 return selected_item_; |
| 159 } | 161 } |
| 160 } | 162 } |
| 161 | 163 |
| OLD | NEW |