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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
|
/*
Miranda NG: the free IM client for Microsoft* Windows*
Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org),
Copyright (c) 2000-08 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
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 "hdr/modern_commonheaders.h"
#include "hdr/modern_clist.h"
#include "hdr/modern_commonprototypes.h"
#include "hdr/modern_row.h"
void RefreshTree(HWND hwndDlg,HTREEITEM hti);
static char* rowOptTmplStr;
static ROWCELL* rowOptTmplRoot;
static ROWCELL* rowOptTA[100];
TCHAR *types[] = {
_T("none"), _T("text1"), _T("text2"), _T("text3"), _T("status"),
_T("avatar"), _T("extra"), _T("extra1"), _T("extra2"), _T("extra3"),
_T("extra4"), _T("extra5"), _T("extra6"), _T("extra7"), _T("extra8"),
_T("extra9"), _T("time"), _T("space"), _T("fspace")
};
RECT da = {205,58,440, 130}; // Draw area
void rowOptBuildTA(pROWCELL cell, pROWCELL* TA, int* i)
{
if (!cell) return;
TA[(*i)++] = cell;
rowOptBuildTA(cell->child,TA, i);
rowOptBuildTA(cell->next, TA, i);
}
void rowOptShowSettings(HWND hwnd)
{
TVITEM tvi;
pROWCELL cell;
HTREEITEM node = TreeView_GetSelection(GetDlgItem(hwnd, IDC_ROWTREE));
int param;
tvi.hItem = node;
tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TreeView_GetItem(GetDlgItem(hwnd, IDC_ROWTREE), &tvi);
cell = (pROWCELL)tvi.lParam;
if (!tvi.hItem) {
EnableWindow(GetDlgItem(hwnd,IDC_CONTTYPE) ,0);
EnableWindow(GetDlgItem(hwnd,IDC_VALIGN),0);
EnableWindow(GetDlgItem(hwnd,IDC_HALIGN) ,0);
EnableWindow(GetDlgItem(hwnd,IDC_CONTWIDTH) ,0);
EnableWindow(GetDlgItem(hwnd,IDC_CONTHEIGHT),0);
EnableWindow(GetDlgItem(hwnd,IDC_SPINCONTWIDTH) ,0);
EnableWindow(GetDlgItem(hwnd,IDC_SPINCONTHEIGHT),0);
SendDlgItemMessage(hwnd,IDC_SPINCONTWIDTH, UDM_SETPOS, 0, 0);
SendDlgItemMessage(hwnd,IDC_SPINCONTHEIGHT,UDM_SETPOS, 0, 0);
EnableWindow(GetDlgItem(hwnd,IDC_CONTLAYER),0);
return;
}
EnableWindow(GetDlgItem(hwnd,IDC_CONTTYPE) ,1);
EnableWindow(GetDlgItem(hwnd,IDC_VALIGN),1);
EnableWindow(GetDlgItem(hwnd,IDC_HALIGN) ,1);
EnableWindow(GetDlgItem(hwnd,IDC_CONTLAYER),1);
if (cell->type != TC_SPACE && cell->type != TC_FIXED) {
EnableWindow(GetDlgItem(hwnd,IDC_CONTWIDTH) ,0);
EnableWindow(GetDlgItem(hwnd,IDC_CONTHEIGHT),0);
EnableWindow(GetDlgItem(hwnd,IDC_SPINCONTWIDTH) ,0);
EnableWindow(GetDlgItem(hwnd,IDC_SPINCONTHEIGHT),0);
SendDlgItemMessage(hwnd,IDC_SPINCONTWIDTH, UDM_SETPOS, 0, 0);
SendDlgItemMessage(hwnd,IDC_SPINCONTHEIGHT,UDM_SETPOS, 0, 0);
}
else {
EnableWindow(GetDlgItem(hwnd,IDC_CONTWIDTH) ,1);
EnableWindow(GetDlgItem(hwnd,IDC_CONTHEIGHT),1);
EnableWindow(GetDlgItem(hwnd,IDC_SPINCONTWIDTH) ,1);
EnableWindow(GetDlgItem(hwnd,IDC_SPINCONTHEIGHT),1);
SendDlgItemMessage(hwnd,IDC_SPINCONTWIDTH, UDM_SETPOS, 0, MAKELONG(cell->w,0));
SendDlgItemMessage(hwnd,IDC_SPINCONTHEIGHT,UDM_SETPOS, 0, MAKELONG(cell->h,0));
}
SendDlgItemMessage(hwnd, IDC_CONTTYPE, CB_SETCURSEL, cell->type, 0);
switch (cell->valign) {
case TC_VCENTER:
param = 1;
break;
case TC_BOTTOM:
param = 2;
break;
default:
param = 0;
}
SendDlgItemMessage(hwnd, IDC_VALIGN, CB_SETCURSEL, param, 0);
switch (cell->halign) {
case TC_HCENTER:
param = 1;
break;
case TC_RIGHT:
param = 2;
break;
default:
param = 0;
}
SendDlgItemMessage(hwnd, IDC_HALIGN, CB_SETCURSEL, param, 0);
CheckDlgButton(hwnd,IDC_CONTLAYER,cell->layer?BST_CHECKED:BST_UNCHECKED);
}
void rowOptGenerateTreeView(pROWCELL cell, HTREEITEM node, HWND hwnd)
{
if (!cell) return;
TVINSERTSTRUCT tvis;
tvis.hParent = node;
tvis.hInsertAfter = TVI_LAST;
tvis.item.mask = TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
tvis.item.stateMask = TVIS_STATEIMAGEMASK;
tvis.item.lParam = (LPARAM)cell;
switch (cell->cont) {
case TC_ROW:
tvis.item.pszText = _T("Line");
break;
case TC_COL:
tvis.item.pszText = _T("Column");
}
tvis.item.iImage = cell->child?1:2;
tvis.item.iSelectedImage = cell->child?0:2;
HTREEITEM pnode = TreeView_InsertItem(hwnd,&tvis);
rowOptGenerateTreeView(cell->child, pnode, hwnd);
rowOptGenerateTreeView(cell->next, node, hwnd);
}
int rowOptFillRowTree(HWND hwnd)
{
TreeView_DeleteAllItems(hwnd);
rowOptGenerateTreeView(rowOptTmplRoot, NULL, hwnd);
TreeView_Expand(hwnd, TreeView_GetRoot(hwnd), TVM_EXPAND);
return 0;
}
void rowOptAddContainer(HWND htree, HTREEITEM hti)
{
TVINSERTSTRUCT tvis;
TVITEM tviparent;
ROWCELL *cell = NULL;
if (!hti) {
if (TreeView_GetRoot(htree))
return;
rowAddCell(rowOptTmplRoot, TC_ROW);
tvis.hParent = NULL;
tvis.hInsertAfter = TVI_ROOT;
tvis.item.pszText = _T("Line");
tvis.item.lParam = (LPARAM)rowOptTmplRoot;
cell = rowOptTmplRoot;
}
else {
// Get parent item
tviparent.hItem = hti;
tviparent.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TreeView_GetItem(htree, &tviparent);
cell = (pROWCELL)tviparent.lParam;
if (cell->cont == TC_ROW)
tvis.item.pszText = _T("Column");
else
tvis.item.pszText = _T("Line");
if (cell->child) {
cell = cell->child;
while (cell->next)
cell = cell->next;
rowAddCell(cell->next, ((ROWCELL*)tviparent.lParam)->cont == TC_ROW?TC_COL:TC_ROW);
cell = cell->next;
}
else {
rowAddCell(cell->child, ((ROWCELL*)tviparent.lParam)->cont == TC_ROW?TC_COL:TC_ROW);
cell = cell->child;
}
tvis.hInsertAfter = TVI_LAST;
}
tvis.item.lParam = (LPARAM)cell;
tvis.hParent = hti;
tvis.item.mask = TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
tvis.item.stateMask = TVIS_STATEIMAGEMASK;
tvis.item.iImage = 2;
tvis.item.iSelectedImage = 2;
TreeView_InsertItem(htree,&tvis);
TreeView_Expand(htree, hti, TVM_EXPAND);
// Change icon at parent item
tviparent.iImage = 1;
tviparent.iSelectedImage = 0;
TreeView_SetItem(htree, &tviparent);
int i=0;
ZeroMemory( rowOptTA, sizeof( rowOptTA ));
rowOptBuildTA(rowOptTmplRoot, (pROWCELL*)&rowOptTA, &i);
}
void rowOptDelContainer(HWND htree, HTREEITEM hti)
{
HTREEITEM prev = TreeView_GetPrevSibling(htree, hti);
HTREEITEM prnt = TreeView_GetParent(htree, hti);
TVITEM tvi, tvpi;
if (!hti) return;
// Get current tree item
tvi.hItem = hti;
tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TreeView_GetItem(htree, &tvi);
tvpi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
if (prev)
{
tvpi.hItem = prev;
TreeView_GetItem(htree, &tvpi);
((pROWCELL)tvpi.lParam)->next = ((pROWCELL)tvi.lParam)->next;
}
else
{
if (prnt)
{
tvpi.hItem = prnt;
TreeView_GetItem(htree, &tvpi);
((pROWCELL)tvpi.lParam)->child = ((pROWCELL)tvi.lParam)->next;
prev = prnt;
}
else
{
tvpi.lParam = 0;
rowOptTmplRoot = (pROWCELL)tvpi.lParam;
}
}
((pROWCELL)tvi.lParam)->next = NULL;
rowDeleteTree((pROWCELL)tvi.lParam);
{
int i=0;
ZeroMemory( rowOptTA, sizeof( rowOptTA ));
rowOptBuildTA((pROWCELL)tvpi.lParam, (pROWCELL*)&rowOptTA, &i );
}
TreeView_DeleteItem(htree, hti);
// Change icon at parent item
if (!prnt || (prnt != prev)) return;
if ( TreeView_GetChild(htree, prnt))
{
tvpi.iImage = 1;
tvpi.iSelectedImage = 0;
}
else
{
tvpi.iImage = 2;
tvpi.iSelectedImage = 2;
}
TreeView_SetItem(htree, &tvpi);
}
void RefreshTree(HWND hwndDlg,HTREEITEM hti)
{
HWND htree = GetDlgItem(hwndDlg, IDC_ROWTREE);
pROWCELL cell;
TVITEM tvi = {0};
if (hti == NULL) hti = TreeView_GetRoot(htree);
while (hti)
{
tvi.hItem = hti;
tvi.mask = TVIF_HANDLE;//|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_TEXT;
TreeView_GetItem(htree, &tvi);
cell = (pROWCELL)tvi.lParam;
if (cell)
{
TCHAR buf[200] = {0};
if (!cell->child)
{
if (cell->type == 0)
mir_sntprintf(buf, SIZEOF(buf), TranslateT("Empty %s cell"), cell->cont == TC_COL?TranslateT("column"):TranslateT("line"));
else
mir_sntprintf(buf, SIZEOF(buf), TranslateT("%s"), TranslateTS(types[cell->type]));
}
else
{
if (cell->type == 0)
mir_sntprintf(buf, SIZEOF(buf), TranslateT("%s"), cell->cont != TC_COL?TranslateT("columns"):TranslateT("lines"));
else
mir_sntprintf(buf, SIZEOF(buf), TranslateT("%s, contain %s"), TranslateTS(types[cell->type]),cell->cont != TC_COL?TranslateT("columns"):TranslateT("lines"));
}
if (cell->layer) _tcsncat(buf,TranslateT(" layered"),SIZEOF(buf));
tvi.mask = TVIF_HANDLE|TVIF_TEXT;
tvi.pszText = buf;
TreeView_SetItem(htree,&tvi);
}
{
HTREEITEM child_hti = TreeView_GetChild(htree,hti);
if (child_hti) RefreshTree(hwndDlg,child_hti);
}
hti = TreeView_GetNextSibling(htree,hti);
}
RedrawWindow(hwndDlg,NULL,NULL,RDW_INVALIDATE|RDW_ERASE|RDW_UPDATENOW|RDW_ALLCHILDREN);
}
INT_PTR CALLBACK DlgTmplEditorOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
{
int hbuf = 0, seq = 0;
HWND htree = GetDlgItem(hwndDlg,IDC_ROWTREE);
TranslateDialogDefault(hwndDlg);
rowOptTmplStr = db_get_sa(NULL, "ModernData", "RowTemplate");
if (!rowOptTmplStr)
rowOptTmplStr = mir_strdup("<TR />");
SendDlgItemMessage(hwndDlg,IDC_SPINCONTWIDTH, UDM_SETRANGE, 0, MAKELONG(999,0));
SendDlgItemMessage(hwndDlg,IDC_SPINCONTHEIGHT,UDM_SETRANGE, 0, MAKELONG(999,0));
int i, item;
for (i=0; i < SIZEOF(types); i++) {
item = SendDlgItemMessage(hwndDlg,IDC_CONTTYPE,CB_ADDSTRING, 0, (LPARAM)TranslateTS(types[i]));
SendDlgItemMessage(hwndDlg,IDC_CONTTYPE,CB_SETITEMDATA,item,0);
}
SendDlgItemMessage(hwndDlg,IDC_CONTTYPE,CB_SETCURSEL, 0, 0);
TCHAR *h_alignment[] = {_T("left"), _T("hCenter"), _T("right")};
for (i=0; i < SIZEOF(h_alignment); i++) {
item = SendDlgItemMessage(hwndDlg,IDC_HALIGN,CB_ADDSTRING, 0, (LPARAM)TranslateTS(h_alignment[i]));
SendDlgItemMessage(hwndDlg,IDC_HALIGN,CB_SETITEMDATA,item,0);
}
SendDlgItemMessage(hwndDlg,IDC_HALIGN,CB_SETCURSEL, 0, 0);
TCHAR *v_alignment[] = {_T("top"), _T("vCenter"), _T("bottom")};
for (i=0; i < SIZEOF(v_alignment); i++) {
item = SendDlgItemMessage(hwndDlg,IDC_VALIGN,CB_ADDSTRING, 0, (LPARAM)TranslateTS(v_alignment[i]));
SendDlgItemMessage(hwndDlg,IDC_VALIGN,CB_SETITEMDATA,item,0);
}
SendDlgItemMessage(hwndDlg,IDC_VALIGN,CB_SETCURSEL, 0, 0);
rowDeleteTree(rowOptTmplRoot);
rowOptTmplRoot = NULL;
rowParse(rowOptTmplRoot, rowOptTmplRoot, rowOptTmplStr, hbuf, seq, rowOptTA);
seq = 0;
ZeroMemory( rowOptTA, sizeof( rowOptTA ));
rowOptBuildTA(rowOptTmplRoot, (pROWCELL*)&rowOptTA, &seq);
rowOptFillRowTree(htree);
RefreshTree(hwndDlg,NULL);
TreeView_SelectItem(GetDlgItem(hwndDlg, IDC_ROWTREE), TreeView_GetRoot(GetDlgItem(hwndDlg, IDC_ROWTREE)));
rowOptShowSettings(hwndDlg);
}
return TRUE;
case WM_COMMAND:
{
HWND htree = GetDlgItem(hwndDlg, IDC_ROWTREE);
pROWCELL cell;
TVITEM tvi = {0};
HTREEITEM hti = TreeView_GetSelection(htree);
tvi.hItem = hti;
tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TreeView_GetItem(htree, &tvi);
cell = (pROWCELL)tvi.lParam;
switch (LOWORD(wParam)) {
case IDC_CONTTYPE:
if (HIWORD(wParam) == CBN_SELENDOK) {
TVITEM tv = {0};
int index = SendMessage(GetDlgItem(hwndDlg,IDC_CONTTYPE),CB_GETCURSEL, 0, 0);
cell->type = index;
RefreshTree(hwndDlg,NULL);
}
case IDC_VALIGN:
if (HIWORD(wParam) == CBN_SELENDOK) {
switch (SendMessage(GetDlgItem(hwndDlg,IDC_VALIGN),CB_GETCURSEL, 0, 0)) {
case 0:
cell->valign = TC_TOP;
break;
case 1:
cell->valign = TC_VCENTER;
break;
case 2:
cell->valign = TC_BOTTOM;
break;
}
RefreshTree(hwndDlg,NULL);
}
case IDC_HALIGN:
if (HIWORD(wParam) == CBN_SELENDOK) {
switch (SendMessage(GetDlgItem(hwndDlg,IDC_HALIGN),CB_GETCURSEL, 0, 0)) {
case 0:
cell->halign = TC_LEFT;
break;
case 1:
cell->halign = TC_HCENTER;
break;
case 2:
cell->halign = TC_RIGHT;
break;
}
RefreshTree(hwndDlg,NULL);
}
}
if (HIWORD(wParam) == BN_CLICKED) {
if (lParam == (LPARAM)GetDlgItem(hwndDlg,IDC_ADDCONTAINER))
// Adding new container
{
rowOptAddContainer(htree, hti);
}
else if (lParam == (LPARAM)GetDlgItem(hwndDlg,IDC_DELCONTAINER))
// Deleting container
{
rowOptDelContainer(htree, hti);
}
else if (lParam == (LPARAM)GetDlgItem(hwndDlg,IDC_CONTUP))
// Moving container to up
{
RedrawWindow(htree,&da,NULL,RDW_INVALIDATE|RDW_ERASE|RDW_UPDATENOW|RDW_ALLCHILDREN);
}
RefreshTree(hwndDlg,NULL);
RedrawWindow(GetParent(hwndDlg),NULL,NULL,RDW_INVALIDATE|RDW_ERASE|RDW_UPDATENOW|RDW_ALLCHILDREN);
}
return TRUE;
}
case WM_NOTIFY:
switch(((LPNMHDR)lParam)->idFrom) {
case IDC_ROWTREE:
if (((LPNMHDR)lParam)->code == NM_SETCURSOR )
rowOptShowSettings(hwndDlg);
if (((LPNMHDR)lParam)->code == NM_CLICK )
RedrawWindow(hwndDlg,&da,NULL,RDW_INVALIDATE|RDW_ERASE|RDW_UPDATENOW);
break;
case 0: // Apply or Ok button is pressed
return FALSE; // Temporary
break;
}
return TRUE;
case WM_PAINT:
if (rowOptTmplRoot) {
int i=0;
// Drawning row template at properties page
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwndDlg, &ps);
TVITEM curItem;
curItem.hItem = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_ROWTREE));
curItem.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TreeView_GetItem(GetDlgItem(hwndDlg, IDC_ROWTREE), &curItem);
while(rowOptTA[i]) {
switch(rowOptTA[i]->type) {
case TC_AVATAR:
rowOptTA[i]->w = 25;
rowOptTA[i]->h = 30;
break;
case TC_STATUS:
case TC_EXTRA1:
case TC_EXTRA2:
case TC_EXTRA3:
case TC_EXTRA4:
case TC_EXTRA5:
case TC_EXTRA6:
case TC_EXTRA7:
case TC_EXTRA8:
case TC_EXTRA9:
rowOptTA[i]->w = 16;
rowOptTA[i]->h = 16;
break;
case TC_EXTRA:
rowOptTA[i]->w = 112;
rowOptTA[i]->h = 16;
break;
case TC_TEXT1:
case TC_TEXT2:
case TC_TEXT3:
rowOptTA[i]->w = 200;
rowOptTA[i]->h = 16;
break;
case TC_TIME:
rowOptTA[i]->w = 30;
rowOptTA[i]->h = 10;
default:
rowOptTA[i]->w = 0;
rowOptTA[i]->h = 0;
}
i++;
}
rowSizeWithReposition(rowOptTmplRoot, da.right-da.left);
i = -1;
while (rowOptTA[++i]) {
switch(rowOptTA[i]->type) {
case TC_SPACE:
case TC_FIXED:
case 0:
//if (rowOptTA[i] != (pROWCELL)curItem.lParam)
continue;
}
Rectangle(hdc,
rowOptTA[i]->r.left + da.left,
rowOptTA[i]->r.top + da.top,
rowOptTA[i]->r.right + da.left,
rowOptTA[i]->r.bottom + da.top);
}
EndPaint(hwndDlg, &ps);
return FALSE;
}
}
return FALSE;
}
|