1/*
2 * Copyright 2001-2015 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 = B_FOLLOW_LEFT_TOP,
24									uint32 flags = B_WILL_DRAW | B_NAVIGABLE
25										| B_FULL_UPDATE_ON_RESIZE);
26								BButton(const char* name, const char* label,
27									BMessage* message,
28										uint32 flags = B_WILL_DRAW | B_NAVIGABLE
29											| B_FULL_UPDATE_ON_RESIZE);
30								BButton(const char* label,
31									BMessage* message = NULL);
32								BButton(BMessage* data);
33
34	virtual						~BButton();
35
36	static	BArchivable*		Instantiate(BMessage* data);
37	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
38
39	virtual	void				Draw(BRect updateRect);
40	virtual	void				MouseDown(BPoint where);
41	virtual	void				AttachedToWindow();
42	virtual	void				KeyDown(const char* bytes, int32 numBytes);
43	virtual	void				MakeDefault(bool flag);
44	virtual	void				SetLabel(const char* string);
45			bool				IsDefault() const;
46
47			bool				IsFlat() const;
48			void				SetFlat(bool flat);
49
50			BBehavior			Behavior() const;
51			void				SetBehavior(BBehavior behavior);
52
53			BMessage*			PopUpMessage() const;
54			void				SetPopUpMessage(BMessage* message);
55
56	virtual	void				MessageReceived(BMessage* message);
57	virtual	void				WindowActivated(bool active);
58	virtual	void				MouseMoved(BPoint where, uint32 code,
59									const BMessage* dragMessage);
60	virtual	void				MouseUp(BPoint where);
61	virtual	void				DetachedFromWindow();
62	virtual	void				SetValue(int32 value);
63	virtual	void				GetPreferredSize (float* _width,
64									float* _height);
65	virtual	void				ResizeToPreferred();
66	virtual	status_t			Invoke(BMessage* message = NULL);
67	virtual	void				FrameMoved(BPoint newPosition);
68	virtual	void				FrameResized(float newWidth, float newHeight);
69
70	virtual	void				MakeFocus(bool focus = true);
71	virtual	void				AllAttached();
72	virtual	void				AllDetached();
73
74	virtual	BHandler*			ResolveSpecifier(BMessage* message,
75									int32 index, BMessage* specifier,
76									int32 what, const char* property);
77	virtual	status_t			GetSupportedSuites(BMessage* message);
78	virtual	status_t			Perform(perform_code d, void* arg);
79
80	virtual	BSize				MinSize();
81	virtual	BSize				MaxSize();
82	virtual	BSize				PreferredSize();
83
84	virtual	status_t			SetIcon(const BBitmap* icon, uint32 flags = 0);
85
86protected:
87	virtual	void				LayoutInvalidated(bool descendants = false);
88
89private:
90	virtual	void				_ReservedButton1();
91	virtual	void				_ReservedButton2();
92	virtual	void				_ReservedButton3();
93
94			BButton&			operator=(const BButton &);
95
96			BSize				_ValidatePreferredSize();
97
98			BRect				_PopUpRect() const;
99
100	inline	bool				_Flag(uint32 flag) const;
101	inline	bool				_SetFlag(uint32 flag, bool set);
102
103private:
104			BSize				fPreferredSize;
105			uint32				fFlags;
106			BBehavior			fBehavior;
107			BMessage*			fPopUpMessage;
108};
109
110
111#endif	// _BUTTON_H
112