1/*
2 * Copyright 2006-2011, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stephan Aßmus <superstippi@gmx.de>
7 */
8#ifndef ICON_BUTTON_H
9#define ICON_BUTTON_H
10
11
12//! GUI class that loads an image from disk and shows it as clickable button.
13
14
15#include <Control.h>
16#include <String.h>
17
18
19class BBitmap;
20class BMimeType;
21
22
23namespace BPrivate {
24
25
26class BIconButton : public BControl {
27public:
28								BIconButton(const char* name,
29									const char* label = NULL,
30									BMessage* message = NULL,
31									BHandler* target = NULL);
32	virtual						~BIconButton();
33
34	// BView interface
35	virtual	void				MessageReceived(BMessage* message);
36	virtual	void				AttachedToWindow();
37
38	virtual	void				Draw(BRect updateRect);
39	virtual	bool				ShouldDrawBorder() const;
40	virtual	void				DrawBorder(BRect& frame,
41									const BRect& updateRect,
42									const rgb_color& backgroundColor,
43									uint32 controlLookFlags);
44	virtual	void				DrawBackground(BRect& frame,
45									const BRect& updateRect,
46									const rgb_color& backgroundColor,
47									uint32 controlLookFlags);
48
49	virtual	void				MouseDown(BPoint where);
50	virtual	void				MouseUp(BPoint where);
51	virtual	void				MouseMoved(BPoint where, uint32 transit,
52										   const BMessage* message);
53	virtual	void				GetPreferredSize(float* width,
54												 float* height);
55	virtual	BSize				MinSize();
56	virtual	BSize				MaxSize();
57
58
59	// BInvoker interface
60	virtual	status_t			Invoke(BMessage* message = NULL);
61
62	// BControl interface
63	virtual	void				SetValue(int32 value);
64	virtual	void				SetEnabled(bool enable);
65
66	// BIconButton
67			bool				IsValid() const;
68
69			void				SetPressed(bool pressed);
70			bool				IsPressed() const;
71
72			status_t			SetIcon(int32 resourceID);
73			status_t			SetIcon(const char* pathToBitmap);
74			status_t			SetIcon(const BBitmap* bitmap);
75			status_t			SetIcon(const BMimeType* fileType,
76									bool small = true);
77			status_t			SetIcon(const unsigned char* bitsFromQuickRes,
78									uint32 width, uint32 height,
79									color_space format,
80									bool convertToBW = false);
81			void				ClearIcon();
82			void				TrimIcon(bool keepAspect = true);
83
84			BBitmap*			Bitmap() const;
85									// caller has to delete the returned bitmap
86
87protected:
88			bool				IsInside() const;
89			void				SetInside(bool inside);
90
91private:
92			BBitmap*			_ConvertToRGB32(const BBitmap* bitmap) const;
93			status_t			_MakeBitmaps(const BBitmap* bitmap);
94			void				_DeleteBitmaps();
95			void				_SendMessage() const;
96			void				_Update();
97			void				_SetTracking(bool state);
98			void				_SetFlags(uint32 flags, bool set);
99			bool				_HasFlags(uint32 flags) const;
100
101private:
102			uint32				fButtonState;
103			BBitmap*			fNormalBitmap;
104			BBitmap*			fDisabledBitmap;
105			BBitmap*			fClickedBitmap;
106			BBitmap*			fDisabledClickedBitmap;
107
108			BHandler*			fTargetCache;
109};
110
111
112} // namespac BPrivate
113
114
115using BPrivate::BIconButton;
116
117
118#endif // ICON_BUTTON_H
119