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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/*
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.
*/
#include "Common.h"
extern HINSTANCE hInst;
void StartBlinkAction(char *, WORD);
int getCustomNro(DWORD actionID, HWND hwndDlg, int nItems)
{
int i;
DBVARIANT dbv;
char theme[MAX_PATH+1];
if (DBGetTriggerSetting(actionID, NULL, KEYBDMODULE, "custom", &dbv))
return DEF_SETTING_CUSTOMTHEME;
for (i=0; i < nItems; i++) {
SendDlgItemMessage(hwndDlg, IDC_CUSTOMTHEME, CB_GETLBTEXT, (WPARAM)i, (LPARAM)theme);
if (!strcmp(dbv.pszVal, theme)) {
db_free(&dbv);
return i;
}
}
db_free(&dbv);
return DEF_SETTING_CUSTOMTHEME;
}
static INT_PTR CALLBACK DlgProcOptsActionKbdNotify(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
DBVARIANT dbv;
DWORD actionID;
int i, nItems;
char theme[MAX_PATH+1];
switch (msg) {
case WM_INITDIALOG:
actionID = (DWORD)lParam;
TranslateDialogDefault(hwndDlg);
for (i=0; !db_get(NULL, KEYBDMODULE, fmtDBSettingName("theme%d", i), &dbv); i++) {
int index = SendDlgItemMessage(hwndDlg, IDC_CUSTOMTHEME, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)dbv.pszVal);
db_free(&dbv);
if (index != CB_ERR && index != CB_ERRSPACE)
SendDlgItemMessage(hwndDlg, IDC_CUSTOMTHEME, CB_SETITEMDATA, (WPARAM)index, (LPARAM)i);
}
nItems = SendDlgItemMessage(hwndDlg, IDC_CUSTOMTHEME, CB_GETCOUNT, 0, 0);
CheckDlgButton(hwndDlg, IDC_USECUSTOM, nItems && DBGetTriggerSettingByte(actionID, NULL, KEYBDMODULE, "usecustom", 0) ? BST_CHECKED:BST_UNCHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_USECUSTOM), nItems);
SendDlgItemMessage(hwndDlg, IDC_CUSTOMTHEME, CB_SETCURSEL, (WPARAM)getCustomNro(actionID, hwndDlg, nItems), 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMTHEME), IsDlgButtonChecked(hwndDlg, IDC_USECUSTOM) == BST_CHECKED);
SendDlgItemMessage(hwndDlg, IDC_FORCEOPEN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_SFORCEOPEN), 0);
SendDlgItemMessage(hwndDlg, IDC_FORCEOPEN, UDM_SETRANGE32, 1, MAKELONG(UD_MAXVAL, 0));
SendDlgItemMessage(hwndDlg, IDC_FORCEOPEN, UDM_SETPOS, 0, MAKELONG(DBGetTriggerSettingWord(actionID, NULL, KEYBDMODULE, "forceopen", DEF_SETTING_NBLINKS), 0));
break;
case TM_ADDACTION: // save the settings
actionID = (DWORD)wParam;
DBWriteTriggerSettingByte(actionID, NULL, KEYBDMODULE, "usecustom", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_USECUSTOM) == BST_CHECKED ? 1:0));
SendDlgItemMessage(hwndDlg, IDC_CUSTOMTHEME, CB_GETLBTEXT, (WPARAM)SendDlgItemMessage(hwndDlg, IDC_CUSTOMTHEME, CB_GETCURSEL, 0, 0), (LPARAM)theme);
DBWriteTriggerSettingString(actionID, NULL, KEYBDMODULE, "custom", theme);
DBWriteTriggerSettingWord(actionID, NULL, KEYBDMODULE, "forceopen", (WORD)SendDlgItemMessage(hwndDlg, IDC_FORCEOPEN, UDM_GETPOS, 0, 0));
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_USECUSTOM)
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMTHEME), IsDlgButtonChecked(hwndDlg, IDC_USECUSTOM) == BST_CHECKED);
break;
case WM_DESTROY:
break;
}
return FALSE;
}
char *getCustomString(DWORD actionID)
{
int i;
DBVARIANT dbv, dbv2;
static char customString[MAX_PATH+1];
if (DBGetTriggerSetting(actionID, NULL, KEYBDMODULE, "custom", &dbv))
return NULL;
for (i=0; !db_get(NULL, KEYBDMODULE, fmtDBSettingName("theme%d", i), &dbv2); i++) {
if (!strcmp(dbv.pszVal, dbv2.pszVal)) {
db_free(&dbv);
db_free(&dbv2);
if(db_get(NULL, KEYBDMODULE, fmtDBSettingName("custom%d", i), &dbv2))
return NULL;
strcpy(customString, dbv2.pszVal);
db_free(&dbv2);
return customString;
}
db_free(&dbv2);
}
db_free(&dbv);
return NULL;
}
static int TriggerStartBlinkFunction(DWORD actionID, REPORTINFO *ri)
{
if (ri->flags&ACT_PERFORM) {
char *customStr;
if (!DBGetTriggerSettingByte(actionID, NULL, KEYBDMODULE, "usecustom", 0))
customStr = NULL;
else
customStr = getCustomString(actionID);
StartBlinkAction(customStr, DBGetTriggerSettingWord(actionID, NULL, KEYBDMODULE, "forceopen", DEF_SETTING_NBLINKS));
}
if (ri->flags&ACT_CLEANUP) { // request to delete all associated settings
RemoveAllActionSettings(actionID, KEYBDMODULE);
}
return 0; // all ok
}
int RegisterAction()
{
ACTIONREGISTER ar;
if (!ServiceExists(MS_TRIGGER_REGISTERACTION))
return -1;
ZeroMemory(&ar, sizeof(ar));
ar.cbSize = sizeof(ar);
ar.pszName = "Keyboard Flash: Start Blinking";
ar.actionFunction = TriggerStartBlinkFunction;
ar.hInstance = hInst;
ar.pfnDlgProc = DlgProcOptsActionKbdNotify;
ar.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_KN_ACTION);
ar.flags = ARF_FUNCTION;
return CallService(MS_TRIGGER_REGISTERACTION, 0, (LPARAM)&ar);
}
int DeInitAction()
{
return 0;
}
|