| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/views/controls/button/native_button_win.h" | 5 #include "chrome/views/controls/button/native_button_win.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/views/controls/button/checkbox.h" | 8 #include "chrome/views/controls/button/checkbox.h" |
| 9 #include "chrome/views/controls/button/native_button.h" | 9 #include "chrome/views/controls/button/native_button.h" |
| 10 #include "chrome/views/controls/button/radio_button.h" | 10 #include "chrome/views/controls/button/radio_button.h" |
| 11 #include "chrome/views/widget/widget.h" | 11 #include "chrome/views/widget/widget.h" |
| 12 | 12 |
| 13 namespace views { | 13 namespace views { |
| 14 | 14 |
| 15 //////////////////////////////////////////////////////////////////////////////// | 15 //////////////////////////////////////////////////////////////////////////////// |
| 16 // NativeButtonWin, public: | 16 // NativeButtonWin, public: |
| 17 | 17 |
| 18 NativeButtonWin::NativeButtonWin(NativeButton* native_button) | 18 NativeButtonWin::NativeButtonWin(NativeButton* native_button) |
| 19 : NativeControlWin(), | 19 : NativeControlWin(), |
| 20 native_button_(native_button) { | 20 native_button_(native_button) { |
| 21 // Associates the actual HWND with the native_button so the native_button is |
| 22 // the one considered as having the focus (not the wrapper) when the HWND is |
| 23 // focused directly (with a click for example). |
| 24 SetAssociatedFocusView(native_button); |
| 21 } | 25 } |
| 22 | 26 |
| 23 NativeButtonWin::~NativeButtonWin() { | 27 NativeButtonWin::~NativeButtonWin() { |
| 24 } | 28 } |
| 25 | 29 |
| 26 //////////////////////////////////////////////////////////////////////////////// | 30 //////////////////////////////////////////////////////////////////////////////// |
| 27 // NativeButtonWin, NativeButtonWrapper implementation: | 31 // NativeButtonWin, NativeButtonWrapper implementation: |
| 28 | 32 |
| 29 void NativeButtonWin::UpdateLabel() { | 33 void NativeButtonWin::UpdateLabel() { |
| 30 SetWindowText(GetHWND(), native_button_->label().c_str()); | 34 SetWindowText(GetHWND(), native_button_->label().c_str()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 SendMessage(GetHWND(), BM_SETSTYLE, | 45 SendMessage(GetHWND(), BM_SETSTYLE, |
| 42 native_button_->is_default() ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON, | 46 native_button_->is_default() ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON, |
| 43 true); | 47 true); |
| 44 } | 48 } |
| 45 } | 49 } |
| 46 | 50 |
| 47 View* NativeButtonWin::GetView() { | 51 View* NativeButtonWin::GetView() { |
| 48 return this; | 52 return this; |
| 49 } | 53 } |
| 50 | 54 |
| 55 void NativeButtonWin::SetFocus() { |
| 56 // Focus the associated HWND. |
| 57 Focus(); |
| 58 } |
| 59 |
| 51 //////////////////////////////////////////////////////////////////////////////// | 60 //////////////////////////////////////////////////////////////////////////////// |
| 52 // NativeButtonWin, View overrides: | 61 // NativeButtonWin, View overrides: |
| 53 | 62 |
| 54 gfx::Size NativeButtonWin::GetPreferredSize() { | 63 gfx::Size NativeButtonWin::GetPreferredSize() { |
| 55 SIZE sz = {0}; | 64 SIZE sz = {0}; |
| 56 SendMessage(GetHWND(), BCM_GETIDEALSIZE, 0, reinterpret_cast<LPARAM>(&sz)); | 65 SendMessage(GetHWND(), BCM_GETIDEALSIZE, 0, reinterpret_cast<LPARAM>(&sz)); |
| 57 | 66 |
| 58 return gfx::Size(sz.cx, sz.cy); | 67 return gfx::Size(sz.cx, sz.cy); |
| 59 } | 68 } |
| 60 | 69 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 137 |
| 129 void NativeCheckboxWin::UpdateChecked() { | 138 void NativeCheckboxWin::UpdateChecked() { |
| 130 SendMessage(GetHWND(), BM_SETCHECK, | 139 SendMessage(GetHWND(), BM_SETCHECK, |
| 131 checkbox_->checked() ? BST_CHECKED : BST_UNCHECKED, 0); | 140 checkbox_->checked() ? BST_CHECKED : BST_UNCHECKED, 0); |
| 132 } | 141 } |
| 133 | 142 |
| 134 void NativeCheckboxWin::SetPushed(bool pushed) { | 143 void NativeCheckboxWin::SetPushed(bool pushed) { |
| 135 SendMessage(GetHWND(), BM_SETSTATE, pushed, 0); | 144 SendMessage(GetHWND(), BM_SETSTATE, pushed, 0); |
| 136 } | 145 } |
| 137 | 146 |
| 147 void NativeCheckboxWin::SetFocus() { |
| 148 // The focus should stay on the views::Checkbox (more precisely, on the |
| 149 // label, which is a view). |
| 150 } |
| 151 |
| 138 //////////////////////////////////////////////////////////////////////////////// | 152 //////////////////////////////////////////////////////////////////////////////// |
| 139 // NativeCheckboxWin, NativeButtonWin overrides: | 153 // NativeCheckboxWin, NativeButtonWin overrides: |
| 140 | 154 |
| 141 LRESULT NativeCheckboxWin::ProcessMessage(UINT message, | 155 LRESULT NativeCheckboxWin::ProcessMessage(UINT message, |
| 142 WPARAM w_param, | 156 WPARAM w_param, |
| 143 LPARAM l_param) { | 157 LPARAM l_param) { |
| 144 if (message == WM_COMMAND && HIWORD(w_param) == BN_CLICKED) { | 158 if (message == WM_COMMAND && HIWORD(w_param) == BN_CLICKED) { |
| 145 checkbox_->SetChecked(!checkbox_->checked()); | 159 checkbox_->SetChecked(!checkbox_->checked()); |
| 146 // Fall through to the NativeButtonWin's handler, which will send the | 160 // Fall through to the NativeButtonWin's handler, which will send the |
| 147 // clicked notification to the listener... | 161 // clicked notification to the listener... |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return new NativeCheckboxWin(checkbox); | 223 return new NativeCheckboxWin(checkbox); |
| 210 } | 224 } |
| 211 | 225 |
| 212 // static | 226 // static |
| 213 NativeButtonWrapper* NativeButtonWrapper::CreateRadioButtonWrapper( | 227 NativeButtonWrapper* NativeButtonWrapper::CreateRadioButtonWrapper( |
| 214 RadioButton* radio_button) { | 228 RadioButton* radio_button) { |
| 215 return new NativeRadioButtonWin(radio_button); | 229 return new NativeRadioButtonWin(radio_button); |
| 216 } | 230 } |
| 217 | 231 |
| 218 } // namespace views | 232 } // namespace views |
| 219 | |
| OLD | NEW |