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
|
// 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();
}
ConfirmMessageBoxDialog::ConfirmMessageBoxDialog(
ConfirmMessageBoxObserver* observer, const std::wstring& message_text,
const std::wstring& window_title)
: observer_(observer),
window_title_(window_title) {
message_label_ = new views::Label(message_text);
message_label_->SetMultiLine(true);
l10n_util::TextDirection direction =
l10n_util::GetFirstStrongCharacterDirection(message_label_->GetText());
views::Label::Alignment alignment;
if (direction == l10n_util::RIGHT_TO_LEFT)
alignment = views::Label::ALIGN_RIGHT;
else
alignment = views::Label::ALIGN_LEFT;
// In addition, we should set the RTL alignment mode as
// AUTO_DETECT_ALIGNMENT so that the alignment will not be flipped around
// in RTL locales.
message_label_->SetRTLAlignmentMode(views::Label::AUTO_DETECT_ALIGNMENT);
message_label_->SetHorizontalAlignment(alignment);
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 l10n_util::GetString(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
}
if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL)
return l10n_util::GetString(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_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 gfx::Size(views::Window::GetLocalizedContentsSize(
IDS_CONFIRM_MESSAGE_BOX_DEFAULT_WIDTH_CHARS,
IDS_CONFIRM_MESSAGE_BOX_DEFAULT_HEIGHT_LINES));
}
|