| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 "views/examples/examples_main.h" | |
| 6 | |
| 7 #include "base/at_exit.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/i18n/icu_util.h" | |
| 10 #include "base/process_util.h" | |
| 11 #include "base/stl_util.h" | |
| 12 #include "base/utf_string_conversions.h" | |
| 13 #include "ui/base/resource/resource_bundle.h" | |
| 14 #include "ui/base/ui_base_paths.h" | |
| 15 #include "views/controls/button/text_button.h" | |
| 16 #include "views/controls/label.h" | |
| 17 #include "views/controls/tabbed_pane/tabbed_pane.h" | |
| 18 #include "views/examples/bubble_example.h" | |
| 19 #include "views/examples/button_example.h" | |
| 20 #include "views/examples/combobox_example.h" | |
| 21 #include "views/examples/double_split_view_example.h" | |
| 22 #include "views/examples/link_example.h" | |
| 23 #include "views/examples/menu_example.h" | |
| 24 #include "views/examples/message_box_example.h" | |
| 25 #include "views/examples/native_theme_button_example.h" | |
| 26 #include "views/examples/native_theme_checkbox_example.h" | |
| 27 #include "views/examples/native_widget_views_example.h" | |
| 28 #include "views/examples/progress_bar_example.h" | |
| 29 #include "views/examples/radio_button_example.h" | |
| 30 #include "views/examples/scroll_view_example.h" | |
| 31 #include "views/examples/single_split_view_example.h" | |
| 32 #include "views/examples/tabbed_pane_example.h" | |
| 33 #include "views/examples/table2_example.h" | |
| 34 #include "views/examples/text_example.h" | |
| 35 #include "views/examples/textfield_example.h" | |
| 36 #include "views/examples/throbber_example.h" | |
| 37 #include "views/examples/widget_example.h" | |
| 38 #include "views/focus/accelerator_handler.h" | |
| 39 #include "views/layout/grid_layout.h" | |
| 40 #include "views/test/test_views_delegate.h" | |
| 41 #include "views/widget/widget.h" | |
| 42 | |
| 43 #if defined(OS_WIN) | |
| 44 // TableView is not yet ported to Linux. | |
| 45 #include "views/examples/table_example.h" | |
| 46 #endif | |
| 47 | |
| 48 namespace examples { | |
| 49 | |
| 50 ExamplesMain::ExamplesMain() | |
| 51 : tabbed_pane_(NULL), | |
| 52 contents_(NULL), | |
| 53 status_label_(NULL) { | |
| 54 } | |
| 55 | |
| 56 ExamplesMain::~ExamplesMain() { | |
| 57 STLDeleteElements(&examples_); | |
| 58 } | |
| 59 | |
| 60 void ExamplesMain::Init() { | |
| 61 // Creates a window with the tabbed pane for each example, | |
| 62 // and a label to print messages from each example. | |
| 63 DCHECK(contents_ == NULL) << "Run called more than once."; | |
| 64 contents_ = new views::View(); | |
| 65 contents_->set_background(views::Background::CreateStandardPanelBackground()); | |
| 66 views::GridLayout* layout = new views::GridLayout(contents_); | |
| 67 contents_->SetLayoutManager(layout); | |
| 68 | |
| 69 views::ColumnSet* column_set = layout->AddColumnSet(0); | |
| 70 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
| 71 views::GridLayout::USE_PREF, 0, 0); | |
| 72 | |
| 73 tabbed_pane_ = new views::TabbedPane(); | |
| 74 status_label_ = new views::Label(); | |
| 75 | |
| 76 layout->StartRow(1, 0); | |
| 77 layout->AddView(tabbed_pane_); | |
| 78 layout->StartRow(0 /* no expand */, 0); | |
| 79 layout->AddView(status_label_); | |
| 80 | |
| 81 // TODO(satorux): The window is getting wide. Eventually, we would have | |
| 82 // the second tabbed pane. | |
| 83 views::Widget* window = | |
| 84 views::Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 850, 300)); | |
| 85 | |
| 86 // Keep these in alphabetical order! | |
| 87 examples_.push_back(new BubbleExample(this)); | |
| 88 examples_.push_back(new ButtonExample(this)); | |
| 89 examples_.push_back(new ComboboxExample(this)); | |
| 90 examples_.push_back(new DoubleSplitViewExample(this)); | |
| 91 examples_.push_back(new LinkExample(this)); | |
| 92 examples_.push_back(new MenuExample(this)); | |
| 93 examples_.push_back(new MessageBoxExample(this)); | |
| 94 examples_.push_back(new NativeThemeButtonExample(this)); | |
| 95 examples_.push_back(new NativeThemeCheckboxExample(this)); | |
| 96 examples_.push_back(new NativeWidgetViewsExample(this)); | |
| 97 examples_.push_back(new ProgressBarExample(this)); | |
| 98 examples_.push_back(new RadioButtonExample(this)); | |
| 99 examples_.push_back(new ScrollViewExample(this)); | |
| 100 examples_.push_back(new SingleSplitViewExample(this)); | |
| 101 examples_.push_back(new TabbedPaneExample(this)); | |
| 102 #if defined(OS_WIN) | |
| 103 examples_.push_back(new TableExample(this)); | |
| 104 #endif | |
| 105 examples_.push_back(new Table2Example(this)); | |
| 106 examples_.push_back(new TextExample(this)); | |
| 107 examples_.push_back(new TextfieldExample(this)); | |
| 108 examples_.push_back(new ThrobberExample(this)); | |
| 109 examples_.push_back(new WidgetExample(this)); | |
| 110 | |
| 111 for (std::vector<ExampleBase*>::const_iterator i(examples_.begin()); | |
| 112 i != examples_.end(); ++i) | |
| 113 AddExample(*i); | |
| 114 | |
| 115 window->Show(); | |
| 116 } | |
| 117 | |
| 118 void ExamplesMain::SetStatus(const std::string& status) { | |
| 119 status_label_->SetText(UTF8ToUTF16(status)); | |
| 120 } | |
| 121 | |
| 122 void ExamplesMain::AddExample(ExampleBase* example) { | |
| 123 tabbed_pane_->AddTab(UTF8ToUTF16(example->example_title()), | |
| 124 example->example_view()); | |
| 125 } | |
| 126 | |
| 127 bool ExamplesMain::CanResize() const { | |
| 128 return true; | |
| 129 } | |
| 130 | |
| 131 bool ExamplesMain::CanMaximize() const { | |
| 132 return true; | |
| 133 } | |
| 134 | |
| 135 string16 ExamplesMain::GetWindowTitle() const { | |
| 136 return ASCIIToUTF16("Views Examples"); | |
| 137 } | |
| 138 | |
| 139 views::View* ExamplesMain::GetContentsView() { | |
| 140 return contents_; | |
| 141 } | |
| 142 | |
| 143 void ExamplesMain::WindowClosing() { | |
| 144 MessageLoopForUI::current()->Quit(); | |
| 145 } | |
| 146 | |
| 147 views::Widget* ExamplesMain::GetWidget() { | |
| 148 return contents_->GetWidget(); | |
| 149 } | |
| 150 | |
| 151 const views::Widget* ExamplesMain::GetWidget() const { | |
| 152 return contents_->GetWidget(); | |
| 153 } | |
| 154 | |
| 155 } // namespace examples | |
| 156 | |
| 157 int main(int argc, char** argv) { | |
| 158 #if defined(OS_WIN) | |
| 159 OleInitialize(NULL); | |
| 160 #elif defined(OS_LINUX) | |
| 161 // Initializes gtk stuff. | |
| 162 g_type_init(); | |
| 163 gtk_init(&argc, &argv); | |
| 164 #endif | |
| 165 CommandLine::Init(argc, argv); | |
| 166 | |
| 167 base::EnableTerminationOnHeapCorruption(); | |
| 168 | |
| 169 // The exit manager is in charge of calling the dtors of singleton objects. | |
| 170 base::AtExitManager exit_manager; | |
| 171 | |
| 172 ui::RegisterPathProvider(); | |
| 173 bool icu_result = icu_util::Initialize(); | |
| 174 CHECK(icu_result); | |
| 175 ui::ResourceBundle::InitSharedInstance("en-US"); | |
| 176 | |
| 177 MessageLoop main_message_loop(MessageLoop::TYPE_UI); | |
| 178 | |
| 179 views::TestViewsDelegate delegate; | |
| 180 | |
| 181 // We do not use this header: chrome/common/chrome_switches.h | |
| 182 // because that would create a bad dependency back on Chrome. | |
| 183 views::Widget::SetPureViews( | |
| 184 CommandLine::ForCurrentProcess()->HasSwitch("use-pure-views")); | |
| 185 | |
| 186 examples::ExamplesMain main; | |
| 187 main.Init(); | |
| 188 | |
| 189 views::AcceleratorHandler accelerator_handler; | |
| 190 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); | |
| 191 | |
| 192 #if defined(OS_WIN) | |
| 193 OleUninitialize(); | |
| 194 #endif | |
| 195 return 0; | |
| 196 } | |
| OLD | NEW |