1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/views/confirm_message_box_dialog.h"
#include "app/l10n_util.h"
#include "app/message_box_flags.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "views/standard_layout.h"
#include "views/widget/widget.h"
#include "views/window/window.h"
// static
void ConfirmMessageBoxDialog::Run(gfx::NativeWindow parent,
ConfirmMessageBoxObserver* observer,
const std::wstring& message_text,
const std::wstring& window_title) {
DCHECK(observer);
ConfirmMessageBoxDialog* dialog = new ConfirmMessageBoxDialog(observer,
message_text, window_title);
views::Window* window = views::Window::CreateChromeWindow(
parent, gfx::Rect(), dialog);
window->Show();
}
// static
void ConfirmMessageBoxDialog::RunWithCustomConfiguration(
gfx::NativeWindow parent,
ConfirmMessageBoxObserver* observer,
const std::wstring& message_text,
const std::wstring& window_title,
const std::wstring& confirm_label,
const std::wstring& reject_label,
const gfx::Size& preferred_size) {
DCHECK(observer);
ConfirmMessageBoxDialog* dialog = new ConfirmMessageBoxDialog(observer,
message_text, window_title);
dialog->preferred_size_ = preferred_size;
dialog->confirm_label_ = confirm_label;
dialog->reject_label_ = reject_label;
views::Window* window = views::Window::CreateChromeWindow(
parent, gfx::Rect(), dialog);
window->Show();
}
ConfirmMessageBoxDialog::ConfirmMessageBoxDialog(
ConfirmMessageBoxObserver* observer, const std::wstring& message_text,
const std::wstring& window_title)
: observer_(observer),
window_title_(window_title),
preferred_size_(gfx::Size(views::Window::GetLocalizedContentsSize(
IDS_CONFIRM_MESSAGE_BOX_DEFAULT_WIDTH_CHARS,
IDS_CONFIRM_MESSAGE_BOX_DEFAULT_HEIGHT_LINES))),
confirm_label_(l10n_util::GetString(
IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL)),
reject_label_(l10n_util::GetString(
IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)) {
message_label_ = new views::Label(message_text);
message_label_->SetMultiLine(true);
message_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
AddChildView(message_label_);
}
int ConfirmMessageBoxDialog::GetDialogButtons() const {
return MessageBoxFlags::DIALOGBUTTON_OK |
MessageBoxFlags::DIALOGBUTTON_CANCEL;
}
std::wstring ConfirmMessageBoxDialog::GetWindowTitle() const {
return window_title_;
}
std::wstring ConfirmMessageBoxDialog::GetDialogButtonLabel(
MessageBoxFlags::DialogButton button) const {
if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
return confirm_label_;
}
if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL)
return reject_label_;
return DialogDelegate::GetDialogButtonLabel(button);
}
bool ConfirmMessageBoxDialog::Accept() {
observer_->OnConfirmMessageAccept();
return true; // Dialog may now be closed.
}
bool ConfirmMessageBoxDialog::Cancel() {
observer_->OnConfirmMessageCancel();
return true; // Dialog may now be closed.
}
void ConfirmMessageBoxDialog::Layout() {
gfx::Size sz = message_label_->GetPreferredSize();
message_label_->SetBounds(kPanelHorizMargin, kPanelVertMargin,
width() - 2 * kPanelHorizMargin,
sz.height());
}
gfx::Size ConfirmMessageBoxDialog::GetPreferredSize() {
return preferred_size_;
}
|