-
Notifications
You must be signed in to change notification settings - Fork 0
/
HotkeyConfig.h
104 lines (85 loc) · 2.88 KB
/
HotkeyConfig.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Virtual Dimension - a free, fast, and feature-full virtual desktop manager
* for the Microsoft Windows platform.
* Copyright (C) 2003-2008 Francois Ferrand
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __HOTKEYCONFIG_H__
#define __HOTKEYCONFIG_H__
#include <list>
#include "PlatformHelper.h"
#include "HotkeyManager.h"
#include "Config.h"
#include "Settings.h"
using namespace std;
class ConfigurableHotkey: public HotKeyManager::EventHandler
{
friend class ShortcutsConfigurationDlg;
public:
ConfigurableHotkey();
virtual ~ConfigurableHotkey();
int GetHotkey() const;
bool SetHotkey(int hotkey);
virtual void SaveHotkey() {}
virtual LPCSTR GetName() const = 0;
protected:
int m_hotkey;
private:
int m_tempHotkey;
void Commit() { if (SetHotkey(m_tempHotkey)) SaveHotkey(); }
};
template <const Config::Setting<int>& setting> class PersistentHotkey: ConfigurableHotkey
{
public:
PersistentHotkey()
{
Settings s;
SetHotkey(s.LoadSetting(setting));
}
virtual void SaveHotkey()
{
Settings s;
s.SaveSetting(setting, GetHotkey());
}
};
class ShortcutsConfigurationDlg
{
public:
static DLGPROC GetWindowProc() { return (DLGPROC)DlgProc; }
static void RegisterHotkey(ConfigurableHotkey * hotkey) { m_hotkeys.push_back(hotkey); }
static void UnRegisterHotkey(ConfigurableHotkey * hotkey) { m_hotkeys.remove(hotkey); }
ShortcutsConfigurationDlg(HWND hwnd);
~ShortcutsConfigurationDlg();
protected:
void InsertItem(ConfigurableHotkey* hotkey);
ConfigurableHotkey* GetItemHotkey(int index);
void SetItemShortcut(int index, int shortcut);
int GetItemShortcut(int index);
void BeginEdit(int item);
void EndEdit();
LRESULT OnApply();
void OnClick(LPNMITEMACTIVATE lpnmitem);
void OnRightClick(LPNMITEMACTIVATE lpnmitem);
void OnSetFocus();
bool IsEditing() const { return IsWindowVisible(m_editCtrl) ? true : false; }
HWND m_hDlg;
HWND m_editCtrl;
HWND m_listViewWnd;
int m_editedItemIndex;
static list<ConfigurableHotkey*> m_hotkeys;
static LRESULT CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM /*wParam*/, LPARAM lParam);
};
#endif /*__HOTKEYCONFIG_H__*/