1 | /*
|
---|
2 | * synergy -- mouse and keyboard sharing utility
|
---|
3 | * Copyright (C) 2006 Chris Schoeneman
|
---|
4 | *
|
---|
5 | * This package is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU General Public License
|
---|
7 | * found in the file COPYING that should have accompanied this file.
|
---|
8 | *
|
---|
9 | * This package is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | * GNU General Public License for more details.
|
---|
13 | */
|
---|
14 |
|
---|
15 | #ifndef CHOTKEYOPTIONS_H
|
---|
16 | #define CHOTKEYOPTIONS_H
|
---|
17 |
|
---|
18 | #include "CString.h"
|
---|
19 | #include "KeyTypes.h"
|
---|
20 | #include "MouseTypes.h"
|
---|
21 | #include "CInputFilter.h"
|
---|
22 |
|
---|
23 | #define WINDOWS_LEAN_AND_MEAN
|
---|
24 | #include <windows.h>
|
---|
25 |
|
---|
26 | class CConfig;
|
---|
27 |
|
---|
28 | //! Hotkey options dialog for Microsoft Windows launcher
|
---|
29 | class CHotkeyOptions {
|
---|
30 | public:
|
---|
31 | CHotkeyOptions(HWND parent, CConfig*);
|
---|
32 | ~CHotkeyOptions();
|
---|
33 |
|
---|
34 | //! @name manipulators
|
---|
35 | //@{
|
---|
36 |
|
---|
37 | //! Run dialog
|
---|
38 | /*!
|
---|
39 | Display and handle the dialog until closed by the user.
|
---|
40 | */
|
---|
41 | void doModal();
|
---|
42 |
|
---|
43 | //@}
|
---|
44 | //! @name accessors
|
---|
45 | //@{
|
---|
46 |
|
---|
47 | //@}
|
---|
48 |
|
---|
49 | private:
|
---|
50 | void doInit(HWND hwnd);
|
---|
51 |
|
---|
52 | void fillHotkeys(HWND hwnd, UInt32 select = (UInt32)-1);
|
---|
53 | void updateHotkeysControls(HWND hwnd);
|
---|
54 |
|
---|
55 | void addHotkey(HWND hwnd);
|
---|
56 | void removeHotkey(HWND hwnd);
|
---|
57 | void editHotkey(HWND hwnd);
|
---|
58 |
|
---|
59 | void fillActions(HWND hwnd, UInt32 select = (UInt32)-1);
|
---|
60 | void updateActionsControls(HWND hwnd);
|
---|
61 |
|
---|
62 | void addAction(HWND hwnd);
|
---|
63 | void removeAction(HWND hwnd);
|
---|
64 | void editAction(HWND hwnd);
|
---|
65 |
|
---|
66 | bool editCondition(HWND hwnd, CInputFilter::CCondition*&);
|
---|
67 | bool editAction(HWND hwnd, CInputFilter::CAction*&,
|
---|
68 | bool& onActivate);
|
---|
69 |
|
---|
70 | void openRule(HWND hwnd);
|
---|
71 | void closeRule(HWND hwnd);
|
---|
72 | UInt32 findMatchingAction(
|
---|
73 | const CInputFilter::CKeystrokeAction*) const;
|
---|
74 | UInt32 findMatchingAction(
|
---|
75 | const CInputFilter::CMouseButtonAction*) const;
|
---|
76 |
|
---|
77 | // message handling
|
---|
78 | BOOL doDlgProc(HWND, UINT, WPARAM, LPARAM);
|
---|
79 | static BOOL CALLBACK dlgProc(HWND, UINT, WPARAM, LPARAM);
|
---|
80 |
|
---|
81 | // special actions we use to combine matching down/up actions into a
|
---|
82 | // single action for the convenience of the user.
|
---|
83 | class CKeystrokeDownUpAction : public CInputFilter::CKeystrokeAction {
|
---|
84 | public:
|
---|
85 | CKeystrokeDownUpAction(IPlatformScreen::CKeyInfo* adoptedInfo) :
|
---|
86 | CInputFilter::CKeystrokeAction(adoptedInfo, true) { }
|
---|
87 |
|
---|
88 | // CAction overrides
|
---|
89 | virtual CInputFilter::CAction* clone() const
|
---|
90 | {
|
---|
91 | IKeyState::CKeyInfo* info = IKeyState::CKeyInfo::alloc(*getInfo());
|
---|
92 | return new CKeystrokeDownUpAction(info);
|
---|
93 | }
|
---|
94 |
|
---|
95 | protected:
|
---|
96 | // CKeystrokeAction overrides
|
---|
97 | virtual const char* formatName() const { return "keystroke"; }
|
---|
98 | };
|
---|
99 | class CMouseButtonDownUpAction : public CInputFilter::CMouseButtonAction {
|
---|
100 | public:
|
---|
101 | CMouseButtonDownUpAction(IPrimaryScreen::CButtonInfo* adoptedInfo) :
|
---|
102 | CInputFilter::CMouseButtonAction(adoptedInfo, true) { }
|
---|
103 |
|
---|
104 | // CAction overrides
|
---|
105 | virtual CInputFilter::CAction* clone() const
|
---|
106 | {
|
---|
107 | IPlatformScreen::CButtonInfo* info =
|
---|
108 | IPrimaryScreen::CButtonInfo::alloc(*getInfo());
|
---|
109 | return new CMouseButtonDownUpAction(info);
|
---|
110 | }
|
---|
111 |
|
---|
112 | protected:
|
---|
113 | // CMouseButtonAction overrides
|
---|
114 | virtual const char* formatName() const { return "mousebutton"; }
|
---|
115 | };
|
---|
116 |
|
---|
117 | class CConditionDialog {
|
---|
118 | public:
|
---|
119 | static bool doModal(HWND parent, CInputFilter::CCondition*&);
|
---|
120 |
|
---|
121 | private:
|
---|
122 | static void doInit(HWND hwnd);
|
---|
123 | static void fillHotkey(HWND hwnd);
|
---|
124 |
|
---|
125 | static void onButton(HWND hwnd, ButtonID button);
|
---|
126 | static void onKey(HWND hwnd, WPARAM wParam, LPARAM lParam);
|
---|
127 | static KeyID getChar(WPARAM wParam, LPARAM lParam);
|
---|
128 | static KeyModifierMask
|
---|
129 | getModifiers();
|
---|
130 |
|
---|
131 | static bool isGoodCondition();
|
---|
132 |
|
---|
133 | static BOOL CALLBACK dlgProc(HWND, UINT, WPARAM, LPARAM);
|
---|
134 | static LRESULT CALLBACK editProc(HWND hwnd, UINT, WPARAM, LPARAM);
|
---|
135 |
|
---|
136 | private:
|
---|
137 | static CInputFilter::CCondition*
|
---|
138 | s_condition;
|
---|
139 | static CInputFilter::CCondition*
|
---|
140 | s_lastGoodCondition;
|
---|
141 | static WNDPROC s_editWndProc;
|
---|
142 | };
|
---|
143 |
|
---|
144 | class CActionDialog {
|
---|
145 | public:
|
---|
146 | static bool doModal(HWND parent, CConfig* config,
|
---|
147 | CInputFilter::CAction*&, bool& onActivate);
|
---|
148 |
|
---|
149 | private:
|
---|
150 | static void doInit(HWND hwnd);
|
---|
151 | static void fillHotkey(HWND hwnd);
|
---|
152 | static void updateControls(HWND hwnd);
|
---|
153 |
|
---|
154 | static void onButton(HWND hwnd, ButtonID button);
|
---|
155 | static void onKey(HWND hwnd, WPARAM wParam, LPARAM lParam);
|
---|
156 | static void onLockAction(HWND hwnd);
|
---|
157 | static void onSwitchToAction(HWND hwnd);
|
---|
158 | static void onSwitchInAction(HWND hwnd);
|
---|
159 |
|
---|
160 | static KeyID getChar(WPARAM wParam, LPARAM lParam);
|
---|
161 | static KeyModifierMask
|
---|
162 | getModifiers();
|
---|
163 |
|
---|
164 | static bool isGoodAction();
|
---|
165 | static void convertAction(HWND hwnd);
|
---|
166 |
|
---|
167 | static bool isDownUpAction();
|
---|
168 |
|
---|
169 | static BOOL CALLBACK dlgProc(HWND, UINT, WPARAM, LPARAM);
|
---|
170 | static LRESULT CALLBACK editProc(HWND hwnd, UINT, WPARAM, LPARAM);
|
---|
171 |
|
---|
172 | private:
|
---|
173 | static CConfig* s_config;
|
---|
174 | static bool s_onActivate;
|
---|
175 | static CInputFilter::CAction*
|
---|
176 | s_action;
|
---|
177 | static CInputFilter::CAction*
|
---|
178 | s_lastGoodAction;
|
---|
179 | static WNDPROC s_editWndProc;
|
---|
180 | };
|
---|
181 |
|
---|
182 | // public to allow CActionDialog to use it
|
---|
183 | public:
|
---|
184 | class CScreensDialog {
|
---|
185 | public:
|
---|
186 | static void doModal(HWND parent, CConfig* config,
|
---|
187 | CInputFilter::CKeystrokeAction*);
|
---|
188 |
|
---|
189 | // public due to compiler brokenness
|
---|
190 | typedef std::set<CString> CScreens;
|
---|
191 |
|
---|
192 | private:
|
---|
193 |
|
---|
194 | static void doInit(HWND hwnd);
|
---|
195 | static void doFini(HWND hwnd);
|
---|
196 | static void fillScreens(HWND hwnd);
|
---|
197 | static void updateControls(HWND hwnd);
|
---|
198 |
|
---|
199 | static void add(HWND hwnd);
|
---|
200 | static void remove(HWND hwnd);
|
---|
201 |
|
---|
202 | static void getSelected(HWND hwnd, UINT id,
|
---|
203 | const CScreens& inScreens, CScreens& outScreens);
|
---|
204 |
|
---|
205 | static BOOL CALLBACK dlgProc(HWND, UINT, WPARAM, LPARAM);
|
---|
206 |
|
---|
207 | private:
|
---|
208 | static CConfig* s_config;
|
---|
209 | static CInputFilter::CKeystrokeAction* s_action;
|
---|
210 | static CScreens s_nonTargets;
|
---|
211 | static CScreens s_targets;
|
---|
212 | static CString s_allScreens;
|
---|
213 | };
|
---|
214 |
|
---|
215 | private:
|
---|
216 | static CHotkeyOptions* s_singleton;
|
---|
217 |
|
---|
218 | HWND m_parent;
|
---|
219 | CConfig* m_config;
|
---|
220 | CInputFilter* m_inputFilter;
|
---|
221 | CInputFilter::CRule m_activeRule;
|
---|
222 | UInt32 m_activeRuleIndex;
|
---|
223 | };
|
---|
224 |
|
---|
225 | #endif
|
---|