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