summaryrefslogtreecommitdiffstats
path: root/views/examples/example_base.h
blob: d4e41bb1bc2ee25dea9ddb36dac4fd0b5229f485 (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
// 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.

#ifndef VIEWS_EXAMPLES_EXAMPLE_BASE_H_
#define VIEWS_EXAMPLES_EXAMPLE_BASE_H_
#pragma once

#include <string>

#include "base/basictypes.h"

namespace views {
class View;
}  // namespace views

namespace examples {

class ExamplesMain;

class ExampleBase {
 public:
  // Returns the view containing this example controls.
  // This view is added as a tab to the example application.
  views::View* GetExampleView() {
    return container_;
  }

  // Sub-classes should creates and add the views to the given parent.
  virtual void CreateExampleView(views::View* parent) = 0;

 protected:
  explicit ExampleBase(ExamplesMain* main);
  virtual ~ExampleBase() {}

  // Sub-classes should return the name of this test.
  // It is used as the title of the tab displaying this test's controls.
  virtual std::wstring GetExampleTitle() = 0;

  // Prints a message in the status area, at the bottom of the window.
  void PrintStatus(const wchar_t* format, ...);

  // Converts an integer/boolean to wchat "on"/"off".
  static const wchar_t* IntToOnOff(int value) {
    return value ? L"on" : L"off";
  }

 private:
  // The runner actually running this test.
  ExamplesMain* main_;

  // The view containing example views.
  views::View* container_;

  DISALLOW_COPY_AND_ASSIGN(ExampleBase);
};

}  // namespace examples

#endif  // VIEWS_EXAMPLES_EXAMPLE_BASE_H_