diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-23 17:04:53 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-23 17:04:53 +0000 |
commit | e5709adccae0cfa3856d16cb3a5d908e51cbf346 (patch) | |
tree | 27c5b9495f19d2c6f9c754544834c2dfc3daa595 /views/examples/radio_button_example.h | |
parent | a6954d6f9e0a68675767df9d9939a66d6f383924 (diff) | |
download | chromium_src-e5709adccae0cfa3856d16cb3a5d908e51cbf346.zip chromium_src-e5709adccae0cfa3856d16cb3a5d908e51cbf346.tar.gz chromium_src-e5709adccae0cfa3856d16cb3a5d908e51cbf346.tar.bz2 |
More examples:
MessageBox, TabbedPane and RadioButton
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/214053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26937 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/examples/radio_button_example.h')
-rw-r--r-- | views/examples/radio_button_example.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/views/examples/radio_button_example.h b/views/examples/radio_button_example.h new file mode 100644 index 0000000..732fa3d --- /dev/null +++ b/views/examples/radio_button_example.h @@ -0,0 +1,86 @@ +// 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. + +#ifndef VIEWS_EXAMPLES_RADIO_BUTTON_EXAMPLE_H_ +#define VIEWS_EXAMPLES_RADIO_BUTTON_EXAMPLE_H_ + +#include "base/string_util.h" +#include "views/controls/button/radio_button.h" +#include "views/controls/button/text_button.h" +#include "views/controls/tabbed_pane/tabbed_pane.h" +#include "views/examples/example_base.h" + +namespace examples { + +class RadioButtonExample : protected ExampleBase, + private views::ButtonListener { + public: + RadioButtonExample(views::TabbedPane* tabbed_pane, views::Label* message) + : ExampleBase(message), + select_(new views::TextButton(this, L"Select")), + status_(new views::TextButton(this, L"Show Status")) { + int all = arraysize(radio_buttons_); + + // divide buttons into 2 groups + int group_count = all / 2; + for (int i = 0; i < all; i++) { + int group = i / group_count; + radio_buttons_[i] = new views::RadioButton( + StringPrintf(L"Radio %d in group %d", (i % group_count + 1), group), + group); + } + + views::View* container = new views::View(); + tabbed_pane->AddTab(L"Radio Button", container); + + views::GridLayout* layout = new views::GridLayout(container); + container->SetLayoutManager(layout); + + views::ColumnSet* column_set = layout->AddColumnSet(0); + column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, + 1.0f, views::GridLayout::USE_PREF, 0, 0); + for (int i = 0; i < all; i++) { + layout->StartRow(0, 0); + layout->AddView(radio_buttons_[i]); + } + layout->StartRow(0, 0); + layout->AddView(select_); + layout->StartRow(0, 0); + layout->AddView(status_); + } + + virtual ~RadioButtonExample() {} + + private: + // Override from ButtonListener + virtual void ButtonPressed(views::Button* sender, const views::Event& event) { + if (sender == select_) { + radio_buttons_[0]->SetChecked(true); + radio_buttons_[5]->SetChecked(true); + } else if (sender == status_) { + // Show the state of radio buttons. + PrintStatus(L"Group1: 1:%ls, 2:%ls, 3:%ls Group2: 1:%ls, 2:%ls, 3:%ls", + IntToOnOff(radio_buttons_[0]->checked()), + IntToOnOff(radio_buttons_[1]->checked()), + IntToOnOff(radio_buttons_[2]->checked()), + IntToOnOff(radio_buttons_[3]->checked()), + IntToOnOff(radio_buttons_[4]->checked()), + IntToOnOff(radio_buttons_[5]->checked())); + } + } + + // 6 radio buttons, 0-2 consists 1st group, and 3-5 consists + // 2nd group. + views::RadioButton* radio_buttons_[6]; + + // Control button to select radio buttons, and show the status of buttons. + views::TextButton* select_, *status_; + + DISALLOW_COPY_AND_ASSIGN(RadioButtonExample); +}; + +} // namespace examples + +#endif // VIEWS_EXAMPLES_RADIO_BUTTON_EXAMPLE_H_ + |