Home | History | Annotate | Download | only in examples
      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 namespace views {
     14 namespace examples {
     15 
     16 MessageBoxExample::MessageBoxExample() : ExampleBase("Message Box View") {
     17 }
     18 
     19 MessageBoxExample::~MessageBoxExample() {
     20 }
     21 
     22 void MessageBoxExample::CreateExampleView(View* container) {
     23   message_box_view_ = new MessageBoxView(
     24       MessageBoxView::InitParams(ASCIIToUTF16("Hello, world!")));
     25   status_ = new LabelButton(this, ASCIIToUTF16("Show Status"));
     26   toggle_ = new LabelButton(this, ASCIIToUTF16("Toggle Checkbox"));
     27 
     28   GridLayout* layout = new GridLayout(container);
     29   container->SetLayoutManager(layout);
     30 
     31   message_box_view_->SetCheckBoxLabel(ASCIIToUTF16("Check Box"));
     32 
     33   const int message_box_column = 0;
     34   ColumnSet* column_set = layout->AddColumnSet(message_box_column);
     35   column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
     36                         GridLayout::USE_PREF, 0, 0);
     37   layout->StartRow(1 /* expand */, message_box_column);
     38   layout->AddView(message_box_view_);
     39 
     40   const int button_column = 1;
     41   column_set = layout->AddColumnSet(button_column);
     42   column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
     43                         0.5f, GridLayout::USE_PREF, 0, 0);
     44   column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
     45                         0.5f, GridLayout::USE_PREF, 0, 0);
     46 
     47   layout->StartRow(0 /* no expand */, button_column);
     48 
     49   layout->AddView(status_);
     50   layout->AddView(toggle_);
     51 }
     52 
     53 void MessageBoxExample::ButtonPressed(Button* sender, const ui::Event& event) {
     54   if (sender == status_) {
     55     message_box_view_->SetCheckBoxLabel(
     56         ASCIIToUTF16(BoolToOnOff(message_box_view_->IsCheckBoxSelected())));
     57     PrintStatus(message_box_view_->IsCheckBoxSelected() ?
     58        "Check Box Selected" : "Check Box Not Selected");
     59   } else if (sender == toggle_) {
     60     message_box_view_->SetCheckBoxSelected(
     61         !message_box_view_->IsCheckBoxSelected());
     62   }
     63 }
     64 
     65 }  // namespace examples
     66 }  // namespace views
     67