summaryrefslogtreecommitdiffstats
path: root/views/controls/button/native_button_win.h
blob: 95b8a5acbc701c477d9506b9e4f5c51c49adf397 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (c) 2010 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_CONTROLS_BUTTON_NATIVE_BUTTON_WIN_H_
#define VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_WIN_H_

#include "views/controls/native_control_win.h"
#include "views/controls/button/native_button_wrapper.h"

namespace views {

// A View that hosts a native Windows button.
class NativeButtonWin : public NativeControlWin,
                        public NativeButtonWrapper {
 public:
  explicit NativeButtonWin(NativeButton* native_button);
  virtual ~NativeButtonWin();

  // Overridden from NativeButtonWrapper:
  virtual void UpdateLabel();
  virtual void UpdateFont();
  virtual void UpdateEnabled();
  virtual void UpdateDefault();
  virtual View* GetView();
  virtual void SetFocus();
  virtual bool UsesNativeLabel() const;
  virtual bool UsesNativeRadioButtonGroup() const;
  virtual gfx::NativeView GetTestingHandle() const;

  // Overridden from View:
  virtual gfx::Size GetPreferredSize();

  // Overridden from NativeControlWin:
  virtual bool ProcessMessage(UINT message,
                              WPARAM w_param,
                              LPARAM l_param,
                              LRESULT* result);
  virtual bool OnKeyDown(int vkey);

 protected:
  virtual void CreateNativeControl();
  virtual void NativeControlCreated(HWND control_hwnd);

  // Returns true if this button is actually a checkbox or radio button.
  virtual bool IsCheckbox() const { return false; }

 private:
  // The NativeButton we are bound to.
  NativeButton* native_button_;

  // It's expensive to find the size of a button on windows, so we cache it.
  mutable gfx::Size button_size_;
  mutable bool button_size_valid_;

  DISALLOW_COPY_AND_ASSIGN(NativeButtonWin);
};

// A View that hosts a native Windows checkbox.
class NativeCheckboxWin : public NativeButtonWin {
 public:
  explicit NativeCheckboxWin(Checkbox* native_button);
  virtual ~NativeCheckboxWin();

  // Overridden from View:
  virtual gfx::Size GetPreferredSize();

  // Overridden from NativeButtonWrapper:
  virtual void UpdateChecked();
  virtual void SetPushed(bool pushed);
  virtual bool OnKeyDown(int vkey);
  virtual bool UsesNativeLabel() const;

  // Overridden from NativeControlWin:
  virtual bool ProcessMessage(UINT message,
                              WPARAM w_param,
                              LPARAM l_param,
                              LRESULT* result);

 protected:
  virtual void CreateNativeControl();
  virtual void NativeControlCreated(HWND control_hwnd);
  virtual bool IsCheckbox() const { return true; }

  // Returns true if this button is actually a radio button.
  virtual bool IsRadioButton() const { return false; }

 private:
  // The Checkbox we are bound to.
  Checkbox* checkbox_;

  DISALLOW_COPY_AND_ASSIGN(NativeCheckboxWin);
};

// A View that hosts a native Windows radio button.
class NativeRadioButtonWin : public NativeCheckboxWin {
 public:
  explicit NativeRadioButtonWin(RadioButton* radio_button);
  virtual ~NativeRadioButtonWin();

 protected:
  // Overridden from NativeCheckboxWin:
  virtual void CreateNativeControl();
  virtual bool IsRadioButton() const { return true; }

 private:
  DISALLOW_COPY_AND_ASSIGN(NativeRadioButtonWin);
};

}  // namespace views

#endif  // #ifndef VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_WIN_H_