• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 "ui/views/examples/example_base.h"
6 
7 #include <stdarg.h>
8 
9 #include "base/strings/stringprintf.h"
10 #include "ui/views/view.h"
11 
12 namespace views {
13 namespace examples {
14 
15 // Logs the specified string to the status area of the examples window.
16 // This function can only be called if there is a visible examples window.
17 void LogStatus(const std::string& status);
18 
19 namespace {
20 
21 // TODO(oshima): Check if this special container is still necessary.
22 class ContainerView : public View {
23  public:
ContainerView(ExampleBase * base)24   explicit ContainerView(ExampleBase* base)
25       : example_view_created_(false),
26         example_base_(base) {
27   }
28 
29  private:
30   // View:
ViewHierarchyChanged(const ViewHierarchyChangedDetails & details)31   virtual void ViewHierarchyChanged(
32       const ViewHierarchyChangedDetails& details) OVERRIDE {
33     View::ViewHierarchyChanged(details);
34     // We're not using child == this because a Widget may not be
35     // available when this is added to the hierarchy.
36     if (details.is_add && GetWidget() && !example_view_created_) {
37       example_view_created_ = true;
38       example_base_->CreateExampleView(this);
39     }
40   }
41 
42   // True if the example view has already been created, or false otherwise.
43   bool example_view_created_;
44 
45   ExampleBase* example_base_;
46 
47   DISALLOW_COPY_AND_ASSIGN(ContainerView);
48 };
49 
50 }  // namespace
51 
~ExampleBase()52 ExampleBase::~ExampleBase() {}
53 
ExampleBase(const char * title)54 ExampleBase::ExampleBase(const char* title) : example_title_(title) {
55   container_ = new ContainerView(this);
56 }
57 
58 // Prints a message in the status area, at the bottom of the window.
PrintStatus(const char * format,...)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   LogStatus(msg);
65 }
66 
67 }  // namespace examples
68 }  // namespace views
69