1/*
2 * Copyright 2006-2011, Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5#ifndef LAUNCH_BUTTON_H
6#define LAUNCH_BUTTON_H
7
8
9#include <IconButton.h>
10#include <List.h>
11#include <String.h>
12
13
14enum {
15	MSG_ADD_SLOT				= 'adsl',
16	MSG_CLEAR_SLOT				= 'clsl',
17	MSG_REMOVE_SLOT				= 'rmsl',
18	MSG_LAUNCH					= 'lnch',
19};
20
21
22class LaunchButton : public BIconButton {
23public:
24								LaunchButton(const char* name,
25									const char* label = NULL,
26									BMessage* message = NULL,
27									BHandler* target = NULL);
28	virtual						~LaunchButton();
29
30	// BIconButton interface
31	virtual	void				AttachedToWindow();
32	virtual	void				Draw(BRect updateRect);
33	virtual	void				MessageReceived(BMessage* message);
34	virtual	void				MouseDown(BPoint where);
35	virtual	void				MouseUp(BPoint where);
36	virtual	void				MouseMoved(BPoint where, uint32 transit,
37									const BMessage* dragMessage);
38
39	virtual	BSize				MinSize();
40	virtual	BSize				PreferredSize();
41	virtual	BSize				MaxSize();
42
43	// LaunchButton
44			void				SetTo(const entry_ref* ref);
45			entry_ref*			Ref() const;
46
47			void				SetTo(const char* appSig, bool updateIcon);
48			const char*			AppSignature() const
49									{ return fAppSig; }
50
51			void				SetDescription(const char* text);
52			const char*			Description() const
53									{ return fDescription.String(); }
54
55			void				SetIconSize(uint32 size);
56			uint32				IconSize() const
57									{ return fIconSize; }
58
59	static	void				SetIgnoreDoubleClick(bool refuse);
60	static	bool				IgnoreDoubleClick()
61									{ return sIgnoreDoubleClick; }
62
63private:
64			void				_UpdateToolTip();
65			void				_UpdateIcon(const entry_ref* ref);
66
67			void				_DrawFrame(BRect frame,
68									rgb_color left, rgb_color top,
69									rgb_color right, rgb_color bottom);
70
71private:
72			entry_ref*			fRef;
73			char*				fAppSig;
74			BString				fDescription;
75
76			bool				fAnticipatingDrop;
77			bigtime_t			fLastClickTime;
78			BPoint				fDragStart;
79
80			uint32				fIconSize;
81
82	static	bigtime_t			sClickSpeed;
83	static	bool				sIgnoreDoubleClick;
84};
85
86#endif // LAUNCH_BUTTON_H
87