1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/examples/message_box_example.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/views/controls/button/label_button.h"
9 #include "ui/views/controls/message_box_view.h"
10 #include "ui/views/layout/grid_layout.h"
11 #include "ui/views/view.h"
12
13 using base::ASCIIToUTF16;
14
15 namespace views {
16 namespace examples {
17
MessageBoxExample()18 MessageBoxExample::MessageBoxExample() : ExampleBase("Message Box View") {
19 }
20
~MessageBoxExample()21 MessageBoxExample::~MessageBoxExample() {
22 }
23
CreateExampleView(View * container)24 void MessageBoxExample::CreateExampleView(View* container) {
25 message_box_view_ = new MessageBoxView(
26 MessageBoxView::InitParams(ASCIIToUTF16("Hello, world!")));
27 status_ = new LabelButton(this, ASCIIToUTF16("Show Status"));
28 toggle_ = new LabelButton(this, ASCIIToUTF16("Toggle Checkbox"));
29
30 GridLayout* layout = new GridLayout(container);
31 container->SetLayoutManager(layout);
32
33 message_box_view_->SetCheckBoxLabel(ASCIIToUTF16("Check Box"));
34
35 const int message_box_column = 0;
36 ColumnSet* column_set = layout->AddColumnSet(message_box_column);
37 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
38 GridLayout::USE_PREF, 0, 0);
39 layout->StartRow(1 /* expand */, message_box_column);
40 layout->AddView(message_box_view_);
41
42 const int button_column = 1;
43 column_set = layout->AddColumnSet(button_column);
44 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
45 0.5f, GridLayout::USE_PREF, 0, 0);
46 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
47 0.5f, GridLayout::USE_PREF, 0, 0);
48
49 layout->StartRow(0 /* no expand */, button_column);
50
51 layout->AddView(status_);
52 layout->AddView(toggle_);
53 }
54
ButtonPressed(Button * sender,const ui::Event & event)55 void MessageBoxExample::ButtonPressed(Button* sender, const ui::Event& event) {
56 if (sender == status_) {
57 message_box_view_->SetCheckBoxLabel(
58 ASCIIToUTF16(BoolToOnOff(message_box_view_->IsCheckBoxSelected())));
59 PrintStatus(message_box_view_->IsCheckBoxSelected() ?
60 "Check Box Selected" : "Check Box Not Selected");
61 } else if (sender == toggle_) {
62 message_box_view_->SetCheckBoxSelected(
63 !message_box_view_->IsCheckBoxSelected());
64 }
65 }
66
67 } // namespace examples
68 } // namespace views
69