Button.h revision 1f424632
1/*
2 * Copyright 2001-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _BUTTON_H
6#define _BUTTON_H
7
8
9#include <Control.h>
10
11
12class BButton : public BControl {
13public:
14			enum BBehavior {
15				B_BUTTON_BEHAVIOR,
16				B_TOGGLE_BEHAVIOR,
17				B_POP_UP_BEHAVIOR,
18			};
19
20public:
21								BButton(BRect frame, const char* name,
22									const char* label, BMessage* message,
23									uint32 resizingMode
24										= B_FOLLOW_LEFT | B_FOLLOW_TOP,
25									uint32 flags = B_WILL_DRAW | B_NAVIGABLE
26										| B_FULL_UPDATE_ON_RESIZE);
27								BButton(const char* name, const char* label,
28									BMessage* message,
29										uint32 flags = B_WILL_DRAW | B_NAVIGABLE
30											| B_FULL_UPDATE_ON_RESIZE);
31								BButton(const char* label,
32									BMessage* message = NULL);
33								BButton(BMessage* data);
34
35	virtual						~BButton();
36
37	static	BArchivable*		Instantiate(BMessage* data);
38	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
39
40	virtual	void				Draw(BRect updateRect);
41	virtual	void				MouseDown(BPoint where);
42	virtual	void				AttachedToWindow();
43	virtual	void				KeyDown(const char* bytes, int32 numBytes);
44	virtual	void				MakeDefault(bool flag);
45	virtual	void				SetLabel(const char* string);
46			bool				IsDefault() const;
47
48			bool				IsFlat() const;
49			void				SetFlat(bool flat);
50
51			BBehavior			Behavior() const;
52			void				SetBehavior(BBehavior behavior);
53
54			BMessage*			PopUpMessage() const;
55			void				SetPopUpMessage(BMessage* message);
56
57	virtual	void				MessageReceived(BMessage* message);
58	virtual	void				WindowActivated(bool active);
59	virtual	void				MouseMoved(BPoint where, uint32 code,
60									const BMessage* dragMessage);
61	virtual	void				MouseUp(BPoint where);
62	virtual	void				DetachedFromWindow();
63	virtual	void				SetValue(int32 value);
64	virtual	void				GetPreferredSize (float* _width,
65									float* _height);
66	virtual	void				ResizeToPreferred();
67	virtual	status_t			Invoke(BMessage* message = NULL);
68	virtual	void				FrameMoved(BPoint newPosition);
69	virtual	void				FrameResized(float newWidth, float newHeight);
70
71	virtual	void				MakeFocus(bool focus = true);
72	virtual	void				AllAttached();
73	virtual	void				AllDetached();
74
75	virtual	BHandler*			ResolveSpecifier(BMessage* message,
76									int32 index, BMessage* specifier,
77									int32 what, const char* property);
78	virtual	status_t			GetSupportedSuites(BMessage* message);
79	virtual	status_t			Perform(perform_code d, void* arg);
80
81	virtual	BSize				MinSize();
82	virtual	BSize				MaxSize();
83	virtual	BSize				PreferredSize();
84
85	virtual	status_t			SetIcon(const BBitmap* icon, uint32 flags = 0);
86
87protected:
88	virtual	void				LayoutInvalidated(bool descendants = false);
89
90private:
91	virtual	void				_ReservedButton1();
92	virtual	void				_ReservedButton2();
93	virtual	void				_ReservedButton3();
94
95			BButton&			operator=(const BButton &);
96
97			BSize				_ValidatePreferredSize();
98
99			BRect				_PopUpRect() const;
100
101	inline	bool				_Flag(uint32 flag) const;
102	inline	bool				_SetFlag(uint32 flag, bool set);
103
104private:
105			BSize				fPreferredSize;
106			uint32				fFlags;
107			BBehavior			fBehavior;
108			BMessage*			fPopUpMessage;
109};
110
111
112#endif	// _BUTTON_H
113