Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: views/controls/button/native_button_win.cc

Issue 2812026: Auto-size the views version of the options dialog. (Closed)
Patch Set: Fix autosizing issue with gtk pref pages in chromeos options dialog. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "views/controls/button/native_button_win.h" 5 #include "views/controls/button/native_button_win.h"
6 6
7 #include <commctrl.h> 7 #include <commctrl.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/win_util.h" 10 #include "base/win_util.h"
11 #include "views/controls/button/checkbox.h" 11 #include "views/controls/button/checkbox.h"
12 #include "views/controls/button/native_button.h" 12 #include "views/controls/button/native_button.h"
13 #include "views/controls/button/radio_button.h" 13 #include "views/controls/button/radio_button.h"
14 #include "views/widget/widget.h" 14 #include "views/widget/widget.h"
15 15
16 namespace views { 16 namespace views {
17 17
18 //////////////////////////////////////////////////////////////////////////////// 18 ////////////////////////////////////////////////////////////////////////////////
19 // NativeButtonWin, public: 19 // NativeButtonWin, public:
20 20
21 NativeButtonWin::NativeButtonWin(NativeButton* native_button) 21 NativeButtonWin::NativeButtonWin(NativeButton* native_button)
22 : native_button_(native_button) { 22 : native_button_(native_button),
23 button_size_valid_(false) {
23 // Associates the actual HWND with the native_button so the native_button is 24 // Associates the actual HWND with the native_button so the native_button is
24 // the one considered as having the focus (not the wrapper) when the HWND is 25 // the one considered as having the focus (not the wrapper) when the HWND is
25 // focused directly (with a click for example). 26 // focused directly (with a click for example).
26 set_focus_view(native_button); 27 set_focus_view(native_button);
27 } 28 }
28 29
29 NativeButtonWin::~NativeButtonWin() { 30 NativeButtonWin::~NativeButtonWin() {
30 } 31 }
31 32
32 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
33 // NativeButtonWin, NativeButtonWrapper implementation: 34 // NativeButtonWin, NativeButtonWrapper implementation:
34 35
35 void NativeButtonWin::UpdateLabel() { 36 void NativeButtonWin::UpdateLabel() {
36 // Show or hide the shield icon of Windows onto this button every time when we 37 // Show or hide the shield icon of Windows onto this button every time when we
37 // update the button text so Windows can lay out the shield icon and the 38 // update the button text so Windows can lay out the shield icon and the
38 // button text correctly. 39 // button text correctly.
39 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA && 40 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA &&
40 win_util::UserAccountControlIsEnabled()) { 41 win_util::UserAccountControlIsEnabled()) {
41 Button_SetElevationRequiredState(native_view(), 42 Button_SetElevationRequiredState(native_view(),
42 native_button_->need_elevation()); 43 native_button_->need_elevation());
43 } 44 }
44 45
45 SetWindowText(native_view(), native_button_->label().c_str()); 46 SetWindowText(native_view(), native_button_->label().c_str());
47 button_size_valid_ = false;
46 } 48 }
47 49
48 void NativeButtonWin::UpdateFont() { 50 void NativeButtonWin::UpdateFont() {
49 SendMessage(native_view(), WM_SETFONT, 51 SendMessage(native_view(), WM_SETFONT,
50 reinterpret_cast<WPARAM>(native_button_->font().hfont()), 52 reinterpret_cast<WPARAM>(native_button_->font().hfont()),
51 FALSE); 53 FALSE);
54 button_size_valid_ = false;
52 } 55 }
53 56
54 void NativeButtonWin::UpdateEnabled() { 57 void NativeButtonWin::UpdateEnabled() {
55 SetEnabled(native_button_->IsEnabled()); 58 SetEnabled(native_button_->IsEnabled());
56 } 59 }
57 60
58 void NativeButtonWin::UpdateDefault() { 61 void NativeButtonWin::UpdateDefault() {
59 if (!IsCheckbox()) { 62 if (!IsCheckbox()) {
60 SendMessage(native_view(), BM_SETSTYLE, 63 SendMessage(native_view(), BM_SETSTYLE,
61 native_button_->is_default() ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON, 64 native_button_->is_default() ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON,
62 true); 65 true);
66 button_size_valid_ = false;
63 } 67 }
64 } 68 }
65 69
66 View* NativeButtonWin::GetView() { 70 View* NativeButtonWin::GetView() {
67 return this; 71 return this;
68 } 72 }
69 73
70 void NativeButtonWin::SetFocus() { 74 void NativeButtonWin::SetFocus() {
71 // Focus the associated HWND. 75 // Focus the associated HWND.
72 Focus(); 76 Focus();
73 } 77 }
74 78
75 bool NativeButtonWin::UsesNativeLabel() const { 79 bool NativeButtonWin::UsesNativeLabel() const {
76 return true; 80 return true;
77 } 81 }
78 82
79 bool NativeButtonWin::UsesNativeRadioButtonGroup() const { 83 bool NativeButtonWin::UsesNativeRadioButtonGroup() const {
80 return false; 84 return false;
81 } 85 }
82 86
83 gfx::NativeView NativeButtonWin::GetTestingHandle() const { 87 gfx::NativeView NativeButtonWin::GetTestingHandle() const {
84 return native_view(); 88 return native_view();
85 } 89 }
86 90
87 //////////////////////////////////////////////////////////////////////////////// 91 ////////////////////////////////////////////////////////////////////////////////
88 // NativeButtonWin, View overrides: 92 // NativeButtonWin, View overrides:
89 93
90 gfx::Size NativeButtonWin::GetPreferredSize() { 94 gfx::Size NativeButtonWin::GetPreferredSize() {
91 SIZE sz = {0}; 95 if (!button_size_valid_) {
92 SendMessage(native_view(), BCM_GETIDEALSIZE, 0, reinterpret_cast<LPARAM>(&sz)) ; 96 SIZE sz = {0};
93 97 Button_GetIdealSize(native_view(), reinterpret_cast<LPARAM>(&sz));
94 return gfx::Size(sz.cx, sz.cy); 98 button_size_.SetSize(sz.cx, sz.cy);
99 button_size_valid_ = true;
100 }
101 return button_size_;
95 } 102 }
96 103
97 //////////////////////////////////////////////////////////////////////////////// 104 ////////////////////////////////////////////////////////////////////////////////
98 // NativeButtonWin, NativeControlWin overrides: 105 // NativeButtonWin, NativeControlWin overrides:
99 106
100 bool NativeButtonWin::ProcessMessage(UINT message, WPARAM w_param, 107 bool NativeButtonWin::ProcessMessage(UINT message, WPARAM w_param,
101 LPARAM l_param, LRESULT* result) { 108 LPARAM l_param, LRESULT* result) {
102 if (message == WM_COMMAND && HIWORD(w_param) == BN_CLICKED) { 109 if (message == WM_COMMAND && HIWORD(w_param) == BN_CLICKED) {
103 native_button_->ButtonPressed(); 110 native_button_->ButtonPressed();
104 *result = 0; 111 *result = 0;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 return new NativeCheckboxWin(checkbox); 255 return new NativeCheckboxWin(checkbox);
249 } 256 }
250 257
251 // static 258 // static
252 NativeButtonWrapper* NativeButtonWrapper::CreateRadioButtonWrapper( 259 NativeButtonWrapper* NativeButtonWrapper::CreateRadioButtonWrapper(
253 RadioButton* radio_button) { 260 RadioButton* radio_button) {
254 return new NativeRadioButtonWin(radio_button); 261 return new NativeRadioButtonWin(radio_button);
255 } 262 }
256 263
257 } // namespace views 264 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/button/native_button_win.h ('k') | views/controls/menu/menu_scroll_view_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698