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/checkbox.h" | 5 #include "chrome/views/checkbox.h" |
6 | 6 |
7 #include "chrome/common/gfx/chrome_canvas.h" | 7 #include "chrome/common/gfx/chrome_canvas.h" |
8 #include "chrome/views/checkbox.h" | 8 #include "chrome/views/checkbox.h" |
9 #include "chrome/views/hwnd_view.h" | 9 #include "chrome/views/hwnd_view.h" |
10 #include "chrome/views/label.h" | 10 #include "chrome/views/label.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 label_->SetBounds(label_x, 0, width() - label_x, height()); | 64 label_->SetBounds(label_x, 0, width() - label_x, height()); |
65 if (hwnd_view_) { | 65 if (hwnd_view_) { |
66 int first_line_height = label_->GetFont().height(); | 66 int first_line_height = label_->GetFont().height(); |
67 hwnd_view_->SetBounds(0, ((first_line_height - kCheckBoxHeight) / 2) + 1, | 67 hwnd_view_->SetBounds(0, ((first_line_height - kCheckBoxHeight) / 2) + 1, |
68 kCheckBoxWidth, kCheckBoxHeight); | 68 kCheckBoxWidth, kCheckBoxHeight); |
69 hwnd_view_->UpdateHWNDBounds(); | 69 hwnd_view_->UpdateHWNDBounds(); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 void CheckBox::ComputeTextRect(gfx::Rect* out) { | 73 void CheckBox::ComputeTextRect(gfx::Rect* out) { |
74 CSize s; | 74 gfx::Size s = label_->GetPreferredSize(); |
75 label_->GetPreferredSize(&s); | |
76 out->set_x(GetTextIndent()); | 75 out->set_x(GetTextIndent()); |
77 out->set_y(kFocusPaddingVertical); | 76 out->set_y(kFocusPaddingVertical); |
78 int new_width = std::min(width() - (kCheckBoxWidth + kCheckBoxToLabel), | 77 int new_width = std::min(width() - (kCheckBoxWidth + kCheckBoxToLabel), |
79 static_cast<int>(s.cx)); | 78 s.width()); |
80 out->set_width(std::max(0, new_width)); | 79 out->set_width(std::max(0, new_width)); |
81 out->set_height(s.cy); | 80 out->set_height(s.height()); |
82 } | 81 } |
83 | 82 |
84 void CheckBox::Paint(ChromeCanvas* canvas) { | 83 void CheckBox::Paint(ChromeCanvas* canvas) { |
85 gfx::Rect r; | 84 gfx::Rect r; |
86 ComputeTextRect(&r); | 85 ComputeTextRect(&r); |
87 // Paint the focus border if any. | 86 // Paint the focus border if any. |
88 if (HasFocus()) | 87 if (HasFocus()) |
89 canvas->DrawFocusRect(r.x() - kFocusPaddingHorizontal, | 88 canvas->DrawFocusRect(r.x() - kFocusPaddingHorizontal, |
90 r.y() - kFocusPaddingVertical, | 89 r.y() - kFocusPaddingVertical, |
91 r.width() + kFocusPaddingHorizontal * 2, | 90 r.width() + kFocusPaddingHorizontal * 2, |
(...skipping 20 matching lines...) Expand all Loading... |
112 } | 111 } |
113 | 112 |
114 void CheckBox::ConfigureNativeButton(HWND hwnd) { | 113 void CheckBox::ConfigureNativeButton(HWND hwnd) { |
115 ::SendMessage(hwnd, | 114 ::SendMessage(hwnd, |
116 static_cast<UINT>(BM_SETCHECK), | 115 static_cast<UINT>(BM_SETCHECK), |
117 static_cast<WPARAM>(is_selected_ ? BST_CHECKED : BST_UNCHECKED), | 116 static_cast<WPARAM>(is_selected_ ? BST_CHECKED : BST_UNCHECKED), |
118 0); | 117 0); |
119 label_->SetText(GetLabel()); | 118 label_->SetText(GetLabel()); |
120 } | 119 } |
121 | 120 |
122 void CheckBox::GetPreferredSize(CSize *out) { | 121 gfx::Size CheckBox::GetPreferredSize() { |
123 label_->GetPreferredSize(out); | 122 gfx::Size prefsize = label_->GetPreferredSize(); |
124 out->cy = std::max(static_cast<int>(out->cy + kFocusPaddingVertical * 2), | 123 prefsize.set_height(std::max(prefsize.height() + kFocusPaddingVertical * 2, |
125 kCheckBoxHeight); | 124 kCheckBoxHeight)); |
126 out->cx += GetTextIndent() * 2; | 125 prefsize.Enlarge(GetTextIndent() * 2, 0); |
| 126 return prefsize; |
127 } | 127 } |
128 | 128 |
129 LRESULT CheckBox::OnCommand(UINT code, int id, HWND source) { | 129 LRESULT CheckBox::OnCommand(UINT code, int id, HWND source) { |
130 if (code == BN_CLICKED) | 130 if (code == BN_CLICKED) |
131 SetIsSelected(!is_selected_); | 131 SetIsSelected(!is_selected_); |
132 | 132 |
133 return NativeButton::OnCommand(code, id, source); | 133 return NativeButton::OnCommand(code, id, source); |
134 } | 134 } |
135 | 135 |
136 void CheckBox::HighlightButton(bool f) { | 136 void CheckBox::HighlightButton(bool f) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 void CheckBox::OnMouseReleased(const MouseEvent& event, | 172 void CheckBox::OnMouseReleased(const MouseEvent& event, |
173 bool canceled) { | 173 bool canceled) { |
174 HighlightButton(false); | 174 HighlightButton(false); |
175 if (!canceled && LabelHitTest(event)) | 175 if (!canceled && LabelHitTest(event)) |
176 OnCommand(BN_CLICKED, 0, GetNativeControlHWND()); | 176 OnCommand(BN_CLICKED, 0, GetNativeControlHWND()); |
177 } | 177 } |
178 | 178 |
179 } | 179 } |
180 | 180 |
OLD | NEW |