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 <ColumnListView.h>
16#include "KeyInfos.h"
17
18
19class CommandActuator;
20class MetaKeyStateMap;
21
22
23MetaKeyStateMap& 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 */
31class ShortcutsSpec : public BRow, public BArchivable {
32public:
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	static	BArchivable*	Instantiate(BMessage* from);
42	const	char* 			GetCellText(int whichColumn) const;
43			void			SetCommand(const char* commandStr);
44
45	// Returns the name of the Nth Column.
46	static	const char*		GetColumnName(int index);
47
48			// Update this spec's state in response to a keystroke to the given
49			// column. Returns true iff a change occurred.
50			bool 			ProcessColumnKeyStroke(int whichColumn,
51								const char* bytes, int32 key);
52
53			// Same as ProcessColumnKeyStroke, but for a mouse click instead.
54			bool			ProcessColumnMouseClick(int whichColumn);
55
56			// Same as ProcessColumnKeyStroke, but for a text string instead.
57			bool			ProcessColumnTextString(int whichColumn,
58								const char* string);
59
60			int32 			GetSelectedColumn() const { return fSelectedColumn; }
61			void 			SetSelectedColumn(int32 i) { fSelectedColumn = i; }
62
63	// default layout of columns is set in here.
64	enum {
65		SHIFT_COLUMN_INDEX		= 0,
66		CONTROL_COLUMN_INDEX	= 1,
67		COMMAND_COLUMN_INDEX	= 2,
68		OPTION_COLUMN_INDEX		= 3,
69		NUM_META_COLUMNS		= 4, // shift, control, command, option, for now
70		KEY_COLUMN_INDEX		= NUM_META_COLUMNS,
71		STRING_COLUMN_INDEX		= 5
72	};
73
74private:
75			void 			_CacheViewFont(BView* owner);
76			bool 			_AttemptTabCompletion();
77
78			char*			fCommand;
79			uint32			fCommandLen;	// number of bytes in fCommand buffer
80			uint32			fCommandNul;	// index of the NUL byte in fCommand
81
82			// icon for associated program. Invalid if none available.
83			BBitmap			fBitmap;
84
85			char*			fLastBitmapName;
86			bool			fBitmapValid;
87			uint32			fKey;
88			int32			fMetaCellStateIndex[NUM_META_COLUMNS];
89			BPoint			fCursorPt1;
90			BPoint			fCursorPt2;
91			bool			fCursorPtsValid;
92	mutable	char			fScratch[50];
93			int32			fSelectedColumn;
94
95private:
96	static	void			_InitModifierNames();
97
98	static	const char*		sShiftName;
99	static	const char*		sControlName;
100	static	const char*		sOptionName;
101	static	const char*		sCommandName;
102};
103
104
105#endif	// SHORTCUTS_SPEC_H
106