Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / views / examples / message_box_example.cc
blobcb9e924fbf624c374666e2cf03603d57da555d3e
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.
5 #include "ui/views/examples/message_box_example.h"
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"
13 using base::ASCIIToUTF16;
15 namespace views {
16 namespace examples {
18 MessageBoxExample::MessageBoxExample() : ExampleBase("Message Box View") {
21 MessageBoxExample::~MessageBoxExample() {
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"));
30 GridLayout* layout = new GridLayout(container);
31 container->SetLayoutManager(layout);
33 message_box_view_->SetCheckBoxLabel(ASCIIToUTF16("Check Box"));
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_);
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);
49 layout->StartRow(0 /* no expand */, button_column);
51 layout->AddView(status_);
52 layout->AddView(toggle_);
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());
67 } // namespace examples
68 } // namespace views