summaryrefslogtreecommitdiffstats
path: root/views/examples/examples_main_base.cc
blob: 9a1644b67f94784ff19dd975450cda18c03ed0d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// 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.

#include "views/examples/examples_main_base.h"

#include "app/app_paths.h"
#include "app/resource_bundle.h"
#include "base/at_exit.h"
#include "base/process_util.h"
#include "views/controls/label.h"
#include "views/focus/accelerator_handler.h"
#include "views/grid_layout.h"
#include "views/widget/widget.h"

// Examples
#include "views/examples/button_example.h"
#include "views/examples/combobox_example.h"
#include "views/examples/message_box_example.h"
#include "views/examples/radio_button_example.h"
#include "views/examples/scroll_view_example.h"
#include "views/examples/tabbed_pane_example.h"
#include "views/examples/textfield_example.h"

namespace examples {

using views::Background;
using views::ColumnSet;
using views::GridLayout;
using views::Label;
using views::TabbedPane;
using views::View;
using views::Widget;

void ExamplesMainBase::Run() {
  base::EnableTerminationOnHeapCorruption();

  // The exit manager is in charge of calling the dtors of singleton objects.
  base::AtExitManager exit_manager;

  app::RegisterPathProvider();

  // This requires chrome to be built first right now.
  // TODO(oshima): fix build to include resource file.
  ResourceBundle::InitSharedInstance(L"en-US");
  ResourceBundle::GetSharedInstance().LoadThemeResources();

  MessageLoop main_message_loop(MessageLoop::TYPE_UI);

  Widget* widget = CreateTopLevelWidget();
  widget->Init(NULL, gfx::Rect(0, 0, 500, 300));

  // Creates a window with the tabbed pane for each examples, and
  // a label to print messages from each examples.
  View* container = new View();
  container->set_background(Background::CreateStandardPanelBackground());
  GridLayout* layout = new GridLayout(container);
  container->SetLayoutManager(layout);

  widget->SetContentsView(container);

  ColumnSet* column_set = layout->AddColumnSet(0);
  column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
                        GridLayout::USE_PREF, 0, 0);

  TabbedPane* tabbed_pane = new TabbedPane();
  Label* message = new Label();

  layout->StartRow(1, 0);
  layout->AddView(tabbed_pane);
  layout->StartRow(0 /* no expand */, 0);
  layout->AddView(message);

  TextfieldExample textfield_example(tabbed_pane, message);
  ButtonExample button_example(tabbed_pane, message);
  ComboboxExample combobox_example(tabbed_pane, message);
  TabbedPaneExample tabbed_pane_example(tabbed_pane, message);
  MessageBoxExample message_box_example(tabbed_pane, message);
  RadioButtonExample radio_button_example(tabbed_pane, message);
  ScrollViewExample scroll_view_example(tabbed_pane, message);

  widget->Show();

  views::AcceleratorHandler accelerator_handler;
  MessageLoopForUI::current()->Run(&accelerator_handler);
}

}  // namespace examples