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 "views/window/dialog_client_view.h" | 5 #include "views/window/dialog_client_view.h" |
6 | 6 |
7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
8 #include "app/gfx/font.h" | 8 #include "app/gfx/font.h" |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 11 #include "base/keyboard_codes.h" |
11 #include "grit/app_strings.h" | 12 #include "grit/app_strings.h" |
12 #include "views/controls/button/native_button.h" | 13 #include "views/controls/button/native_button.h" |
13 #include "views/standard_layout.h" | 14 #include "views/standard_layout.h" |
14 #include "views/window/dialog_delegate.h" | 15 #include "views/window/dialog_delegate.h" |
15 #include "views/window/window.h" | 16 #include "views/window/window.h" |
16 | 17 |
17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
18 #include <windows.h> | 19 #include <windows.h> |
19 #include <uxtheme.h> | 20 #include <uxtheme.h> |
20 #include <vsstyle.h> | 21 #include <vsstyle.h> |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 if (label.empty()) | 122 if (label.empty()) |
122 label = l10n_util::GetString(IDS_APP_OK); | 123 label = l10n_util::GetString(IDS_APP_OK); |
123 bool is_default_button = | 124 bool is_default_button = |
124 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_OK) != 0; | 125 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_OK) != 0; |
125 ok_button_ = new DialogButton(this, window(), | 126 ok_button_ = new DialogButton(this, window(), |
126 MessageBoxFlags::DIALOGBUTTON_OK, label, | 127 MessageBoxFlags::DIALOGBUTTON_OK, label, |
127 is_default_button); | 128 is_default_button); |
128 ok_button_->SetGroup(kButtonGroup); | 129 ok_button_->SetGroup(kButtonGroup); |
129 if (is_default_button) | 130 if (is_default_button) |
130 default_button_ = ok_button_; | 131 default_button_ = ok_button_; |
131 #if defined(OS_WIN) | |
132 if (!(buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL)) | 132 if (!(buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL)) |
133 ok_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); | 133 ok_button_->AddAccelerator(Accelerator(base::VKEY_ESCAPE, |
134 #else | 134 false, false, false)); |
135 NOTIMPLEMENTED(); | |
136 // TODO(port): add accelerators | |
137 #endif | |
138 AddChildView(ok_button_); | 135 AddChildView(ok_button_); |
139 } | 136 } |
140 if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL && !cancel_button_) { | 137 if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL && !cancel_button_) { |
141 std::wstring label = | 138 std::wstring label = |
142 dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_CANCEL); | 139 dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_CANCEL); |
143 if (label.empty()) { | 140 if (label.empty()) { |
144 if (buttons & MessageBoxFlags::DIALOGBUTTON_OK) { | 141 if (buttons & MessageBoxFlags::DIALOGBUTTON_OK) { |
145 label = l10n_util::GetString(IDS_APP_CANCEL); | 142 label = l10n_util::GetString(IDS_APP_CANCEL); |
146 } else { | 143 } else { |
147 label = l10n_util::GetString(IDS_APP_CLOSE); | 144 label = l10n_util::GetString(IDS_APP_CLOSE); |
148 } | 145 } |
149 } | 146 } |
150 bool is_default_button = | 147 bool is_default_button = |
151 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_CANCEL) | 148 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_CANCEL) |
152 != 0; | 149 != 0; |
153 cancel_button_ = new DialogButton(this, window(), | 150 cancel_button_ = new DialogButton(this, window(), |
154 MessageBoxFlags::DIALOGBUTTON_CANCEL, | 151 MessageBoxFlags::DIALOGBUTTON_CANCEL, |
155 label, is_default_button); | 152 label, is_default_button); |
156 cancel_button_->SetGroup(kButtonGroup); | 153 cancel_button_->SetGroup(kButtonGroup); |
157 #if defined(OS_WIN) | 154 cancel_button_->AddAccelerator(Accelerator(base::VKEY_ESCAPE, |
158 cancel_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); | 155 false, false, false)); |
159 #else | |
160 NOTIMPLEMENTED(); | |
161 // TODO(port): add accelerators | |
162 #endif | |
163 if (is_default_button) | 156 if (is_default_button) |
164 default_button_ = ok_button_; | 157 default_button_ = ok_button_; |
165 AddChildView(cancel_button_); | 158 AddChildView(cancel_button_); |
166 } | 159 } |
167 if (!buttons) { | 160 if (!buttons) { |
168 // Register the escape key as an accelerator which will close the window | 161 // Register the escape key as an accelerator which will close the window |
169 // if there are no dialog buttons. | 162 // if there are no dialog buttons. |
170 #if defined(OS_WIN) | 163 AddAccelerator(Accelerator(base::VKEY_ESCAPE, false, false, false)); |
171 AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); | |
172 #else | |
173 NOTIMPLEMENTED(); | |
174 // TODO(port): add accelerators | |
175 #endif | |
176 } | 164 } |
177 } | 165 } |
178 | 166 |
179 void DialogClientView::SetDefaultButton(NativeButton* new_default_button) { | 167 void DialogClientView::SetDefaultButton(NativeButton* new_default_button) { |
180 if (default_button_ && default_button_ != new_default_button) { | 168 if (default_button_ && default_button_ != new_default_button) { |
181 default_button_->SetIsDefault(false); | 169 default_button_->SetIsDefault(false); |
182 default_button_ = NULL; | 170 default_button_ = NULL; |
183 } | 171 } |
184 | 172 |
185 if (new_default_button) { | 173 if (new_default_button) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 if (width > 0) { | 351 if (width > 0) { |
364 width += 2 * kButtonHEdgeMargin; | 352 width += 2 * kButtonHEdgeMargin; |
365 prefsize.set_width(std::max(prefsize.width(), width)); | 353 prefsize.set_width(std::max(prefsize.width(), width)); |
366 } | 354 } |
367 } | 355 } |
368 prefsize.Enlarge(0, button_height); | 356 prefsize.Enlarge(0, button_height); |
369 return prefsize; | 357 return prefsize; |
370 } | 358 } |
371 | 359 |
372 bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) { | 360 bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) { |
373 #if defined(OS_WIN) | 361 // We only expect Escape key. |
374 DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); // We only expect Escape key. | 362 DCHECK(accelerator.GetKeyCode() == base::VKEY_ESCAPE); |
375 #else | |
376 NOTIMPLEMENTED(); | |
377 // TODO(port): add accelerators | |
378 #endif | |
379 Close(); | 363 Close(); |
380 return true; | 364 return true; |
381 } | 365 } |
382 | 366 |
383 //////////////////////////////////////////////////////////////////////////////// | 367 //////////////////////////////////////////////////////////////////////////////// |
384 // DialogClientView, ButtonListener implementation: | 368 // DialogClientView, ButtonListener implementation: |
385 | 369 |
386 void DialogClientView::ButtonPressed(Button* sender) { | 370 void DialogClientView::ButtonPressed(Button* sender) { |
387 // We NULL check the delegate here since the buttons can receive WM_COMMAND | 371 // We NULL check the delegate here since the buttons can receive WM_COMMAND |
388 // messages even after they (and the window containing us) are destroyed. | 372 // messages even after they (and the window containing us) are destroyed. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 initialized = true; | 501 initialized = true; |
518 } | 502 } |
519 } | 503 } |
520 | 504 |
521 void DialogClientView::Close() { | 505 void DialogClientView::Close() { |
522 window()->Close(); | 506 window()->Close(); |
523 GetDialogDelegate()->OnClose(); | 507 GetDialogDelegate()->OnClose(); |
524 } | 508 } |
525 | 509 |
526 } // namespace views | 510 } // namespace views |
OLD | NEW |