1/*
2 * Copyright 1999-2009 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Jeremy Friesner
7 */
8#ifndef ShortcutsSpec_h
9#define ShortcutsSpec_h
10
11
12#include <Bitmap.h>
13
14#include "CLVListItem.h"
15#include "KeyInfos.h"
16
17
18class CommandActuator;
19class MetaKeyStateMap;
20
21
22MetaKeyStateMap & GetNthKeyMap(int which);
23
24/* Objects of this class represent one hotkey "entry" in the preferences
25 * ListView. Each ShortcutsSpec contains the info necessary to generate both
26 * the proper GUI display, and the proper BitFieldTester and CommandActuator
27 * object for the ShortcutsCatcher add-on to use.
28 */
29class ShortcutsSpec : public CLVListItem {
30public:
31	static	void			InitializeMetaMaps();
32
33							ShortcutsSpec(const char* command);
34							ShortcutsSpec(const ShortcutsSpec& copyMe);
35							ShortcutsSpec(BMessage* from);
36							~ShortcutsSpec();
37
38	virtual	status_t		Archive(BMessage* into, bool deep = true) const;
39	virtual void 			Pulse(BView* owner);
40	static 	BArchivable*	Instantiate(BMessage* from);
41			void			Update(BView* owner, const BFont* font);
42	const 	char* 			GetCellText(int whichColumn) const;
43			void			SetCommand(const char* commandStr);
44
45	virtual	void			DrawItemColumn(BView* owner, BRect item_column_rect,
46								int32 column_index, bool columnSelected,
47								bool complete);
48
49	static	int				MyCompare(const CLVListItem* a_Item1,
50								const CLVListItem* a_Item2, int32 KeyColumn);
51
52	// Returns the name of the Nth Column.
53	static	const char*		GetColumnName(int index);
54
55			// Update this spec's state in response to a keystroke to the given
56			// column. Returns true iff a change occurred.
57			bool 			ProcessColumnKeyStroke(int whichColumn,
58								const char* bytes, int32 key);
59
60			// Same as ProcessColumnKeyStroke, but for a mouse click instead.
61			bool			ProcessColumnMouseClick(int whichColumn);
62
63			// Same as ProcessColumnKeyStroke, but for a text string instead.
64			bool			ProcessColumnTextString(int whichColumn,
65								const char* string);
66
67			int32 			GetSelectedColumn() const {return fSelectedColumn;}
68			void 			SetSelectedColumn(int32 i) {fSelectedColumn = i;}
69
70	// default layout of columns is set in here.
71	enum {
72		SHIFT_COLUMN_INDEX		= 0,
73		CONTROL_COLUMN_INDEX	= 1,
74		COMMAND_COLUMN_INDEX	= 2,
75		OPTION_COLUMN_INDEX		= 3,
76		NUM_META_COLUMNS		= 4, // shift, control, command, option, for now
77		KEY_COLUMN_INDEX		= NUM_META_COLUMNS,
78		STRING_COLUMN_INDEX		= 5
79	};
80
81private:
82			void 			_CacheViewFont(BView* owner);
83			bool 			_AttemptTabCompletion();
84
85			// call this to ensure the icon is up-to-date
86			void 			_UpdateIconBitmap();
87
88			char*			fCommand;
89			uint32			fCommandLen; // number of bytes in fCommand buffer
90			uint32			fCommandNul; // index of the NUL byte in fCommand
91			float			fTextOffset;
92
93			// icon for associated program. Invalid if none available.
94			BBitmap			fBitmap;
95
96			char*			fLastBitmapName;
97			bool			fBitmapValid;
98			uint32			fKey;
99			int32			fMetaCellStateIndex[NUM_META_COLUMNS];
100			BPoint			fCursorPt1;
101			BPoint			fCursorPt2;
102			bool			fCursorPtsValid;
103	mutable	char			fScratch[50];
104			int32			fSelectedColumn;
105
106private:
107	static	void			_InitModifierNames();
108
109	static	const char*		sShiftName;
110	static	const char*		sControlName;
111	static	const char*		sOptionName;
112	static	const char*		sCommandName;
113};
114
115#endif
116
117