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/example_base.h" | |
6 | |
7 #include <stdarg.h> | |
8 | |
9 #include "base/compiler_specific.h" | |
10 #include "base/stringprintf.h" | |
11 #include "views/examples/examples_main.h" | |
12 | |
13 namespace { | |
14 | |
15 // Some of GTK based view classes require NativeWidgetGtk in the view | |
16 // parent chain. This class is used to defer the creation of such | |
17 // views until a NativeWidgetGtk is added to the view hierarchy. | |
18 class ContainerView : public views::View { | |
19 public: | |
20 explicit ContainerView(examples::ExampleBase* base) | |
21 : example_view_created_(false), | |
22 example_base_(base) { | |
23 } | |
24 | |
25 private: | |
26 // Overridden from views::View: | |
27 virtual void ViewHierarchyChanged(bool is_add, | |
28 views::View* parent, | |
29 views::View* child) OVERRIDE { | |
30 views::View::ViewHierarchyChanged(is_add, parent, child); | |
31 // We're not using child == this because a Widget may not be | |
32 // availalbe when this is added to the hierarchy. | |
33 if (is_add && GetWidget() && !example_view_created_) { | |
34 example_view_created_ = true; | |
35 example_base_->CreateExampleView(this); | |
36 } | |
37 } | |
38 | |
39 // True if the example view has already been created, or false otherwise. | |
40 bool example_view_created_; | |
41 | |
42 examples::ExampleBase* example_base_; | |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(ContainerView); | |
45 }; | |
46 | |
47 } // namespace | |
48 | |
49 namespace examples { | |
50 | |
51 ExampleBase::~ExampleBase() {} | |
52 | |
53 ExampleBase::ExampleBase(ExamplesMain* main, const char* title) | |
54 : main_(main), example_title_(title) { | |
55 container_ = new ContainerView(this); | |
56 } | |
57 | |
58 // Prints a message in the status area, at the bottom of the window. | |
59 void ExampleBase::PrintStatus(const char* format, ...) { | |
60 va_list ap; | |
61 va_start(ap, format); | |
62 std::string msg; | |
63 base::StringAppendV(&msg, format, ap); | |
64 main_->SetStatus(msg); | |
65 } | |
66 | |
67 } // namespace examples | |
OLD | NEW |