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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/*
Copyright (C) 2010 Unsane
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this file; see the file license.txt. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg) {
case WM_CHAR:
if (wParam == 1 && GetKeyState(VK_CONTROL) & 0x8000)
{ // ctrl-a
SendMessage(hwnd, EM_SETSEL, 0, -1);
return 0;
}
if (wParam == 26 && GetKeyState(VK_CONTROL) & 0x8000)
{ // ctrl-z
SendMessage(hwnd, EM_UNDO, 0, 0);
return 0;
}
if (wParam == 127 && GetKeyState(VK_CONTROL) & 0x8000)
{ // ctrl-backspace
DWORD start, end;
WCHAR text[1024];
SendMessage(hwnd, EM_GETSEL, (WPARAM) & end, (LPARAM) (PDWORD) NULL);
SendMessage(hwnd, WM_KEYDOWN, VK_LEFT, 0);
SendMessage(hwnd, EM_GETSEL, (WPARAM) & start, (LPARAM) (PDWORD) NULL);
GetWindowText(hwnd, text, _countof(text));
memmove(text + start, text + end, sizeof(WCHAR) * (mir_wstrlen(text) + 1 - end));
SetWindowText(hwnd, text);
SendMessage(hwnd, EM_SETSEL, start, start);
SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hwnd), EN_CHANGE), (LPARAM) hwnd);
return 0;
}
break;
}
return mir_callNextSubclass(hwnd, MessageEditSubclassProc, msg, wParam, lParam);
}
INT_PTR CALLBACK DlgProcOptionsPage(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
{
char key[64];
int count = 0;
CMStringW replies;
TranslateDialogDefault(hwndDlg);
variables_skin_helpbutton(hwndDlg, IDC_VARIABLES);
ShowWindow(GetDlgItem(hwndDlg, IDC_VARIABLES_HINT), ServiceExists(MS_VARS_FORMATSTRING));
mir_subclassWindow(GetDlgItem(hwndDlg, IDC_REPLIES), MessageEditSubclassProc);
mir_snprintf(key, "ImmediatelySend_%x", iNumber);
CheckDlgButton(hwndDlg, IDC_IMMEDIATELY, db_get_w(NULL, MODULE, key, 1) ? BST_CHECKED : BST_UNCHECKED);
mir_snprintf(key, "RepliesCount_%x", iNumber);
count = db_get_w(NULL, MODULE, key, 0);
for (int i = 0; i < count; i++)
{
mir_snprintf(key, "Reply_%x_%x", iNumber, i);
wchar_t *value = db_get_wsa(NULL, MODULE, key);
if (value)
{
replies.Append(value);
replies.Append(L"\r\n");
}
mir_free(value);
}
SetDlgItemText(hwndDlg, IDC_REPLIES, replies.GetBuffer());
}
return TRUE;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED) {
switch(LOWORD(wParam)) {
case IDC_VARIABLES:
variables_showhelp(hwndDlg, IDC_REPLIES, VHF_SIMPLEDLG, NULL, NULL);
break;
case IDC_IMMEDIATELY:
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
}
}
break;
case WM_NOTIFY:
{
NMHDR *p = ((LPNMHDR)lParam);
switch (p->code) {
case PSN_APPLY:
{
char key[64];
int count = 0;
wchar_t *tszReplies;
mir_snprintf(key, "RepliesCount_%x", iNumber);
count = db_get_b(NULL, MODULE, key, 0);
for (int i = 0; i < count; i++)
{
mir_snprintf(key, "Reply_%x_%x", iNumber, i);
db_unset(NULL, MODULE, key);
}
int length = SendDlgItemMessage(hwndDlg, IDC_REPLIES, WM_GETTEXTLENGTH, 0, 0);
tszReplies = (wchar_t*)mir_alloc(sizeof(wchar_t)* (length + 1));
GetDlgItemText(hwndDlg, IDC_REPLIES, tszReplies, length + 1);
tszReplies[length] = '\0';
{
CMStringW replies = tszReplies;
if (replies.Right(2) != L"\r\n")
replies.Append(L"\r\n");
count = 0;
int pos = -1, prev = 0;
while ((pos = replies.Find(L"\r\n", prev)) != -1)
{
mir_snprintf(key, "Reply_%x_%x", iNumber, count++);
db_set_ws(NULL, MODULE, key, replies.Mid(prev, pos - prev).GetBuffer());
prev = pos + 2;
}
}
mir_free(tszReplies);
mir_snprintf(key, "RepliesCount_%x", iNumber);
db_set_w(NULL, MODULE, key, count);
mir_snprintf(key, "ImmediatelySend_%x", iNumber);
db_set_b(NULL, MODULE, key, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_IMMEDIATELY));
return TRUE;
}
break;
}
}
break;
}
if (HIWORD(wParam) == EN_CHANGE && GetFocus() == (HWND)lParam)
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return FALSE;
}
int OnOptInitialized(WPARAM wParam, LPARAM)
{
char tabName[32];
mir_snprintf(tabName, "%s %x", Translate("Button"), iNumber + 1);
OPTIONSDIALOGPAGE odp = { 0 };
odp.pszGroup = LPGEN("Message sessions");
odp.pszTitle = LPGEN("Quick Replies");
odp.pszTab = tabName;
odp.position = iNumber;
odp.hInstance = hInstance;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_PAGE);
odp.pfnDlgProc = DlgProcOptionsPage;
Options_AddPage(wParam, &odp);
return 0;
}
|