summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/button/checkbox.h
blob: 08d2c338d98db735a0e2882303011ad161f2f01d (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
89
// Copyright (c) 2012 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 UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_
#define UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_

#include <string>

#include "base/compiler_specific.h"
#include "base/string16.h"
#include "ui/views/controls/button/text_button.h"

namespace views {

// A border with zero left inset.
class VIEWS_EXPORT CheckboxNativeThemeBorder
    : public TextButtonNativeThemeBorder {
 public:
  explicit CheckboxNativeThemeBorder(views::NativeThemeDelegate* delegate)
      : TextButtonNativeThemeBorder(delegate) {}
  virtual ~CheckboxNativeThemeBorder() {}

  // The insets apply to the whole view (checkbox + text), not just the square
  // with the checkmark in it. The insets do not visibly affect the checkbox,
  // except to ensure that there is enough padding between this and other
  // elements.
  virtual gfx::Insets GetInsets() const OVERRIDE;

  // Use the |custom_insets_| provided instead of those from the theme.
  void SetCustomInsets(const gfx::Insets& custom_insets);

  // Use the default insets and ignore any |custom_insets_| that may be set.
  void UseDefaultInsets();

 private:
  // Only used if |use_custom_insets_| is true.
  gfx::Insets custom_insets_;

  // Whether |custom_insets_| should be used in |GetInsets()|.
  bool use_custom_insets_;

  DISALLOW_COPY_AND_ASSIGN(CheckboxNativeThemeBorder);
};

// A native themed class representing a checkbox.  This class does not use
// platform specific objects to replicate the native platforms looks and feel.
class VIEWS_EXPORT Checkbox : public TextButtonBase {
 public:
  static const char kViewClassName[];

  explicit Checkbox(const string16& label);
  virtual ~Checkbox();

  // Sets a listener for this checkbox. Checkboxes aren't required to have them
  // since their state can be read independently of them being toggled.
  void set_listener(ButtonListener* listener) { listener_ = listener; }

  // Sets/Gets whether or not the checkbox is checked.
  virtual void SetChecked(bool checked);
  bool checked() const { return checked_; }

 protected:
  // Overridden from View:
  virtual gfx::Size GetPreferredSize() OVERRIDE;
  virtual std::string GetClassName() const OVERRIDE;
  virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
  virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;

 private:
  // Overridden from Button:
  virtual void NotifyClick(const ui::Event& event) OVERRIDE;

  // Overridden from TextButtonBase:
  virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE;
  virtual gfx::Rect GetThemePaintRect() const OVERRIDE;
  virtual void GetExtraParams(
      ui::NativeTheme::ExtraParams* params) const OVERRIDE;
  virtual gfx::Rect GetTextBounds() const OVERRIDE;

  // True if the checkbox is checked.
  bool checked_;

  DISALLOW_COPY_AND_ASSIGN(Checkbox);
};

}  // namespace views

#endif  // UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_