Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: views/examples/example_base.cc

Issue 347010: Fixed view example. It was failing because some of view classes requires WidgetGTK in (Closed)
Patch Set: revert unintentional change Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « views/examples/example_base.h ('k') | views/examples/examples_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/examples/example_base.h" 5 #include "views/examples/example_base.h"
6 6
7 #include <stdarg.h> 7 #include <stdarg.h>
8 #include <string> 8 #include <string>
9 9
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "views/controls/button/text_button.h" 11 #include "views/controls/button/text_button.h"
12 #include "views/controls/tabbed_pane/tabbed_pane.h" 12 #include "views/controls/tabbed_pane/tabbed_pane.h"
13 #include "views/examples/examples_main.h"
14
15 namespace {
16
17 using views::View;
18
19 // Some of GTK based view classes require WidgetGTK in the view
20 // parent chain. This class is used to defer the creation of such
21 // views until a WidgetGTK is added to the view hierarchy.
22 class ContainerView : public View {
23 public:
24 explicit ContainerView(examples::ExampleBase* base)
25 : example_view_created_(false),
26 example_base_(base) {
27 }
28
29 protected:
30 // views::View overrides:
31 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child) {
32 View::ViewHierarchyChanged(is_add, parent, child);
33 // We're not using child == this because a Widget may not be
34 // availalbe when this is added to the hierarchy.
35 if (is_add && GetWidget() && !example_view_created_) {
36 example_view_created_ = true;
37 example_base_->CreateExampleView(this);
38 }
39 }
40
41 private:
42 // true if the example view has already been created, or false otherwise.
43 bool example_view_created_;
44
45 examples::ExampleBase* example_base_;
46
47 DISALLOW_COPY_AND_ASSIGN(ContainerView);
48 };
49
50 } // namespace
13 51
14 namespace examples { 52 namespace examples {
15 53
54 ExampleBase::ExampleBase(ExamplesMain* main)
55 : main_(main) {
56 container_ = new ContainerView(this);
57 }
58
16 // Prints a message in the status area, at the bottom of the window. 59 // Prints a message in the status area, at the bottom of the window.
17 void ExampleBase::PrintStatus(const wchar_t* format, ...) { 60 void ExampleBase::PrintStatus(const wchar_t* format, ...) {
18 va_list ap; 61 va_list ap;
19 va_start(ap, format); 62 va_start(ap, format);
20 std::wstring msg; 63 std::wstring msg;
21 StringAppendV(&msg, format, ap); 64 StringAppendV(&msg, format, ap);
22 main_->SetStatus(msg); 65 main_->SetStatus(msg);
23 } 66 }
24 67
25 } // namespace examples 68 } // namespace examples
OLDNEW
« no previous file with comments | « views/examples/example_base.h ('k') | views/examples/examples_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698