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

Side by Side Diff: views/window/dialog_client_view.cc

Issue 115957: Make DialogClientView compile on Linux. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « views/views.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if defined(OS_WIN)
7 #include <windows.h> 8 #include <windows.h>
8 #include <uxtheme.h> 9 #include <uxtheme.h>
9 #include <vsstyle.h> 10 #include <vsstyle.h>
11 #endif
10 12
11 #include "app/gfx/canvas.h" 13 #include "app/gfx/canvas.h"
12 #include "app/gfx/font.h" 14 #include "app/gfx/font.h"
13 #include "app/l10n_util.h" 15 #include "app/l10n_util.h"
14 #include "app/resource_bundle.h" 16 #include "app/resource_bundle.h"
17 #if defined(OS_WIN)
15 #include "base/gfx/native_theme.h" 18 #include "base/gfx/native_theme.h"
19 #endif
16 #include "grit/app_strings.h" 20 #include "grit/app_strings.h"
17 #include "views/controls/button/native_button.h" 21 #include "views/controls/button/native_button.h"
18 #include "views/standard_layout.h" 22 #include "views/standard_layout.h"
19 #include "views/window/dialog_delegate.h" 23 #include "views/window/dialog_delegate.h"
24 #if !defined(OS_WIN)
25 #include "views/window/hit_test.h"
26 #endif
20 #include "views/window/window.h" 27 #include "views/window/window.h"
21 28
22 namespace views { 29 namespace views {
23 30
24 namespace { 31 namespace {
25 32
26 // Updates any of the standard buttons according to the delegate. 33 // Updates any of the standard buttons according to the delegate.
27 void UpdateButtonHelper(NativeButton* button_view, 34 void UpdateButtonHelper(NativeButton* button_view,
28 DialogDelegate* delegate, 35 DialogDelegate* delegate,
29 MessageBoxFlags::DialogButton button) { 36 MessageBoxFlags::DialogButton button) {
30 std::wstring label = delegate->GetDialogButtonLabel(button); 37 std::wstring label = delegate->GetDialogButtonLabel(button);
31 if (!label.empty()) 38 if (!label.empty())
32 button_view->SetLabel(label); 39 button_view->SetLabel(label);
33 button_view->SetEnabled(delegate->IsDialogButtonEnabled(button)); 40 button_view->SetEnabled(delegate->IsDialogButtonEnabled(button));
34 button_view->SetVisible(delegate->IsDialogButtonVisible(button)); 41 button_view->SetVisible(delegate->IsDialogButtonVisible(button));
35 } 42 }
36 43
44 #if defined(OS_WIN)
37 void FillViewWithSysColor(gfx::Canvas* canvas, View* view, COLORREF color) { 45 void FillViewWithSysColor(gfx::Canvas* canvas, View* view, COLORREF color) {
38 SkColor sk_color = 46 SkColor sk_color =
39 SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color)); 47 SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color));
40 canvas->FillRectInt(sk_color, 0, 0, view->width(), view->height()); 48 canvas->FillRectInt(sk_color, 0, 0, view->width(), view->height());
41 } 49 }
50 #endif
42 51
43 // DialogButton ---------------------------------------------------------------- 52 // DialogButton ----------------------------------------------------------------
44 53
45 // DialogButtons is used for the ok/cancel buttons of the window. DialogButton 54 // DialogButtons is used for the ok/cancel buttons of the window. DialogButton
46 // forwards AcceleratorPressed to the delegate. 55 // forwards AcceleratorPressed to the delegate.
47 56
48 class DialogButton : public NativeButton { 57 class DialogButton : public NativeButton {
49 public: 58 public:
50 DialogButton(ButtonListener* listener, 59 DialogButton(ButtonListener* listener,
51 Window* owner, 60 Window* owner,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // conflict with other groups that could be in the dialog content. 95 // conflict with other groups that could be in the dialog content.
87 static const int kButtonGroup = 6666; 96 static const int kButtonGroup = 6666;
88 97
89 /////////////////////////////////////////////////////////////////////////////// 98 ///////////////////////////////////////////////////////////////////////////////
90 // DialogClientView, public: 99 // DialogClientView, public:
91 100
92 DialogClientView::DialogClientView(Window* owner, View* contents_view) 101 DialogClientView::DialogClientView(Window* owner, View* contents_view)
93 : ClientView(owner, contents_view), 102 : ClientView(owner, contents_view),
94 ok_button_(NULL), 103 ok_button_(NULL),
95 cancel_button_(NULL), 104 cancel_button_(NULL),
105 default_button_(NULL),
96 extra_view_(NULL), 106 extra_view_(NULL),
97 accepted_(false), 107 accepted_(false) {
98 default_button_(NULL) {
99 InitClass(); 108 InitClass();
100 } 109 }
101 110
102 DialogClientView::~DialogClientView() { 111 DialogClientView::~DialogClientView() {
103 } 112 }
104 113
105 void DialogClientView::ShowDialogButtons() { 114 void DialogClientView::ShowDialogButtons() {
106 DialogDelegate* dd = GetDialogDelegate(); 115 DialogDelegate* dd = GetDialogDelegate();
107 int buttons = dd->GetDialogButtons(); 116 int buttons = dd->GetDialogButtons();
108 if (buttons & MessageBoxFlags::DIALOGBUTTON_OK && !ok_button_) { 117 if (buttons & MessageBoxFlags::DIALOGBUTTON_OK && !ok_button_) {
109 std::wstring label = 118 std::wstring label =
110 dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_OK); 119 dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_OK);
111 if (label.empty()) 120 if (label.empty())
112 label = l10n_util::GetString(IDS_APP_OK); 121 label = l10n_util::GetString(IDS_APP_OK);
113 bool is_default_button = 122 bool is_default_button =
114 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_OK) != 0; 123 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_OK) != 0;
115 ok_button_ = new DialogButton(this, window(), 124 ok_button_ = new DialogButton(this, window(),
116 MessageBoxFlags::DIALOGBUTTON_OK, label, 125 MessageBoxFlags::DIALOGBUTTON_OK, label,
117 is_default_button); 126 is_default_button);
118 ok_button_->SetGroup(kButtonGroup); 127 ok_button_->SetGroup(kButtonGroup);
119 if (is_default_button) 128 if (is_default_button)
120 default_button_ = ok_button_; 129 default_button_ = ok_button_;
130 #if defined(OS_WIN)
121 if (!(buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL)) 131 if (!(buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL))
122 ok_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); 132 ok_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false));
133 #else
134 NOTIMPLEMENTED();
135 // TODO(port): add accelerators
136 #endif
123 AddChildView(ok_button_); 137 AddChildView(ok_button_);
124 } 138 }
125 if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL && !cancel_button_) { 139 if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL && !cancel_button_) {
126 std::wstring label = 140 std::wstring label =
127 dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_CANCEL); 141 dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_CANCEL);
128 if (label.empty()) { 142 if (label.empty()) {
129 if (buttons & MessageBoxFlags::DIALOGBUTTON_OK) { 143 if (buttons & MessageBoxFlags::DIALOGBUTTON_OK) {
130 label = l10n_util::GetString(IDS_APP_CANCEL); 144 label = l10n_util::GetString(IDS_APP_CANCEL);
131 } else { 145 } else {
132 label = l10n_util::GetString(IDS_APP_CLOSE); 146 label = l10n_util::GetString(IDS_APP_CLOSE);
133 } 147 }
134 } 148 }
135 bool is_default_button = 149 bool is_default_button =
136 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_CANCEL) 150 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_CANCEL)
137 != 0; 151 != 0;
138 cancel_button_ = new DialogButton(this, window(), 152 cancel_button_ = new DialogButton(this, window(),
139 MessageBoxFlags::DIALOGBUTTON_CANCEL, 153 MessageBoxFlags::DIALOGBUTTON_CANCEL,
140 label, is_default_button); 154 label, is_default_button);
141 cancel_button_->SetGroup(kButtonGroup); 155 cancel_button_->SetGroup(kButtonGroup);
156 #if defined(OS_WIN)
142 cancel_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); 157 cancel_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false));
158 #else
159 NOTIMPLEMENTED();
160 // TODO(port): add accelerators
161 #endif
143 if (is_default_button) 162 if (is_default_button)
144 default_button_ = ok_button_; 163 default_button_ = ok_button_;
145 AddChildView(cancel_button_); 164 AddChildView(cancel_button_);
146 } 165 }
147 if (!buttons) { 166 if (!buttons) {
148 // Register the escape key as an accelerator which will close the window 167 // Register the escape key as an accelerator which will close the window
149 // if there are no dialog buttons. 168 // if there are no dialog buttons.
169 #if defined(OS_WIN)
150 AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); 170 AddAccelerator(Accelerator(VK_ESCAPE, false, false, false));
171 #else
172 NOTIMPLEMENTED();
173 // TODO(port): add accelerators
174 #endif
151 } 175 }
152 } 176 }
153 177
154 void DialogClientView::SetDefaultButton(NativeButton* new_default_button) { 178 void DialogClientView::SetDefaultButton(NativeButton* new_default_button) {
155 if (default_button_ && default_button_ != new_default_button) { 179 if (default_button_ && default_button_ != new_default_button) {
156 default_button_->SetIsDefault(false); 180 default_button_->SetIsDefault(false);
157 default_button_ = NULL; 181 default_button_ = NULL;
158 } 182 }
159 183
160 if (new_default_button) { 184 if (new_default_button) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 int DialogClientView::NonClientHitTest(const gfx::Point& point) { 268 int DialogClientView::NonClientHitTest(const gfx::Point& point) {
245 if (size_box_bounds_.Contains(point.x() - x(), point.y() - y())) 269 if (size_box_bounds_.Contains(point.x() - x(), point.y() - y()))
246 return HTBOTTOMRIGHT; 270 return HTBOTTOMRIGHT;
247 return ClientView::NonClientHitTest(point); 271 return ClientView::NonClientHitTest(point);
248 } 272 }
249 273
250 //////////////////////////////////////////////////////////////////////////////// 274 ////////////////////////////////////////////////////////////////////////////////
251 // DialogClientView, View overrides: 275 // DialogClientView, View overrides:
252 276
253 void DialogClientView::Paint(gfx::Canvas* canvas) { 277 void DialogClientView::Paint(gfx::Canvas* canvas) {
278 #if defined(OS_WIN)
254 FillViewWithSysColor(canvas, this, GetSysColor(COLOR_3DFACE)); 279 FillViewWithSysColor(canvas, this, GetSysColor(COLOR_3DFACE));
280 #else
281 NOTIMPLEMENTED();
282 // TODO(port): paint dialog background color
283 #endif
255 } 284 }
256 285
257 void DialogClientView::PaintChildren(gfx::Canvas* canvas) { 286 void DialogClientView::PaintChildren(gfx::Canvas* canvas) {
258 View::PaintChildren(canvas); 287 View::PaintChildren(canvas);
259 if (!window()->IsMaximized() && !window()->IsMinimized()) 288 if (!window()->IsMaximized() && !window()->IsMinimized())
260 PaintSizeBox(canvas); 289 PaintSizeBox(canvas);
261 } 290 }
262 291
263 void DialogClientView::Layout() { 292 void DialogClientView::Layout() {
264 if (has_dialog_buttons()) 293 if (has_dialog_buttons())
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 if (width > 0) { 348 if (width > 0) {
320 width += 2 * kButtonHEdgeMargin; 349 width += 2 * kButtonHEdgeMargin;
321 prefsize.set_width(std::max(prefsize.width(), width)); 350 prefsize.set_width(std::max(prefsize.width(), width));
322 } 351 }
323 } 352 }
324 prefsize.Enlarge(0, button_height); 353 prefsize.Enlarge(0, button_height);
325 return prefsize; 354 return prefsize;
326 } 355 }
327 356
328 bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) { 357 bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) {
358 #if defined(OS_WIN)
329 DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); // We only expect Escape key. 359 DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); // We only expect Escape key.
360 #else
361 NOTIMPLEMENTED();
362 // TODO(port): add accelerators
363 #endif
330 Close(); 364 Close();
331 return true; 365 return true;
332 } 366 }
333 367
334 //////////////////////////////////////////////////////////////////////////////// 368 ////////////////////////////////////////////////////////////////////////////////
335 // DialogClientView, ButtonListener implementation: 369 // DialogClientView, ButtonListener implementation:
336 370
337 void DialogClientView::ButtonPressed(Button* sender) { 371 void DialogClientView::ButtonPressed(Button* sender) {
338 if (sender == ok_button_) { 372 if (sender == ok_button_) {
339 AcceptWindow(); 373 AcceptWindow();
340 } else if (sender == cancel_button_) { 374 } else if (sender == cancel_button_) {
341 CancelWindow(); 375 CancelWindow();
342 } else { 376 } else {
343 NOTREACHED(); 377 NOTREACHED();
344 } 378 }
345 } 379 }
346 380
347 //////////////////////////////////////////////////////////////////////////////// 381 ////////////////////////////////////////////////////////////////////////////////
348 // DialogClientView, private: 382 // DialogClientView, private:
349 383
350 void DialogClientView::PaintSizeBox(gfx::Canvas* canvas) { 384 void DialogClientView::PaintSizeBox(gfx::Canvas* canvas) {
351 if (window()->GetDelegate()->CanResize() || 385 if (window()->GetDelegate()->CanResize() ||
352 window()->GetDelegate()->CanMaximize()) { 386 window()->GetDelegate()->CanMaximize()) {
387 #if defined(OS_WIN)
353 HDC dc = canvas->beginPlatformPaint(); 388 HDC dc = canvas->beginPlatformPaint();
354 SIZE gripper_size = { 0, 0 }; 389 SIZE gripper_size = { 0, 0 };
355 gfx::NativeTheme::instance()->GetThemePartSize( 390 gfx::NativeTheme::instance()->GetThemePartSize(
356 gfx::NativeTheme::STATUS, dc, SP_GRIPPER, 1, NULL, TS_TRUE, 391 gfx::NativeTheme::STATUS, dc, SP_GRIPPER, 1, NULL, TS_TRUE,
357 &gripper_size); 392 &gripper_size);
358 393
359 // TODO(beng): (http://b/1085509) In "classic" rendering mode, there isn't 394 // TODO(beng): (http://b/1085509) In "classic" rendering mode, there isn't
360 // a theme-supplied gripper. We should probably improvise 395 // a theme-supplied gripper. We should probably improvise
361 // something, which would also require changing |gripper_size| 396 // something, which would also require changing |gripper_size|
362 // to have different default values, too... 397 // to have different default values, too...
363 size_box_bounds_ = GetLocalBounds(false); 398 size_box_bounds_ = GetLocalBounds(false);
364 size_box_bounds_.set_x(size_box_bounds_.right() - gripper_size.cx); 399 size_box_bounds_.set_x(size_box_bounds_.right() - gripper_size.cx);
365 size_box_bounds_.set_y(size_box_bounds_.bottom() - gripper_size.cy); 400 size_box_bounds_.set_y(size_box_bounds_.bottom() - gripper_size.cy);
366 RECT native_bounds = size_box_bounds_.ToRECT(); 401 RECT native_bounds = size_box_bounds_.ToRECT();
367 gfx::NativeTheme::instance()->PaintStatusGripper( 402 gfx::NativeTheme::instance()->PaintStatusGripper(
368 dc, SP_PANE, 1, 0, &native_bounds); 403 dc, SP_PANE, 1, 0, &native_bounds);
369 canvas->endPlatformPaint(); 404 canvas->endPlatformPaint();
405 #else
406 NOTIMPLEMENTED();
407 // TODO(port): paint size box
408 #endif
370 } 409 }
371 } 410 }
372 411
373 int DialogClientView::GetButtonWidth(int button) const { 412 int DialogClientView::GetButtonWidth(int button) const {
374 DialogDelegate* dd = GetDialogDelegate(); 413 DialogDelegate* dd = GetDialogDelegate();
375 std::wstring button_label = dd->GetDialogButtonLabel( 414 std::wstring button_label = dd->GetDialogButtonLabel(
376 static_cast<MessageBoxFlags::DialogButton>(button)); 415 static_cast<MessageBoxFlags::DialogButton>(button));
377 int string_width = dialog_button_font_->GetStringWidth(button_label); 416 int string_width = dialog_button_font_->GetStringWidth(button_label);
378 return std::max(string_width + kDialogButtonLabelSpacing, 417 return std::max(string_width + kDialogButtonLabelSpacing,
379 kDialogMinButtonWidth); 418 kDialogMinButtonWidth);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 initialized = true; 497 initialized = true;
459 } 498 }
460 } 499 }
461 500
462 void DialogClientView::Close() { 501 void DialogClientView::Close() {
463 window()->Close(); 502 window()->Close();
464 GetDialogDelegate()->OnClose(); 503 GetDialogDelegate()->OnClose();
465 } 504 }
466 505
467 } // namespace views 506 } // namespace views
OLDNEW
« no previous file with comments | « views/views.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698