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