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
|
/*
Miranda IM: the free IM client for Microsoft* Windows*
Copyright 2007 Artem Shpynov
Copyright 2000-2007 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 "..\..\core\commonheaders.h"
#include "m_iconheader.h"
extern HINSTANCE hMirandaInst;
static BOOL IsAeroMode()
{
BOOL result;
return dwmIsCompositionEnabled && (dwmIsCompositionEnabled(&result) == S_OK) && result;
}
static BOOL IsVSMode()
{
return isThemeActive && IsWinVerVistaPlus() && isThemeActive();
}
////////////////////////////////////////////////////////////////////////////////////
// Internals
#define ITC_BORDER_SIZE 3
static LRESULT CALLBACK MIcoTabWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
// structure is used for storing list of tab info
struct MIcoTabCtrl
{
__inline void* operator new(size_t size)
{ return mir_calloc(size);
}
__inline void operator delete(void* p)
{ mir_free(p);
}
MIcoTabCtrl(): pList(1) {}
HWND hwnd;
int nSelectedIdx, nHotIdx;
LIST<MIcoTab> pList;
// UI info
BOOL bMouseInside;
RECT rc;
int width, height;
int itemWidth, itemHeight;
//background bitmap
HBITMAP hBkgBmp;
HBITMAP hBkgOldBmp;
HDC hBkgDC;
SIZE BkgSize;
// control colors
RGBQUAD rgbBkgTop, rgbBkgBottom;
RGBQUAD rgbSelTop, rgbSelBottom;
RGBQUAD rgbHotTop, rgbHotBottom;
COLORREF clText;
COLORREF clSelText, clSelBorder;
COLORREF clHotText, clHotBorder;
// fonts
HFONT hFont;
};
typedef void (*ItemDestuctor)(void*);
static void MITListDestructor(void * adr)
{
MIcoTab * mit=(MIcoTab *)adr;
mir_free(mit->tcsName);
if (mit->hIcon && !(mit->flag&MITCF_SHAREDICON))
DestroyIcon(mit->hIcon);
mir_free(adr);
}
void li_ListDestruct(LIST<MIcoTab> &pList, ItemDestuctor pItemDestructor)
{
for (int i=0; i<pList.getCount(); i++) pItemDestructor(pList[i]);
pList.destroy();
}
int LoadIcoTabsModule()
{
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(wc));
wc.cbSize = sizeof(wc);
wc.lpszClassName = MIRANDAICOTABCLASS;
wc.lpfnWndProc = MIcoTabWndProc;
// wc.hCursor = LoadCursor(NULL, IDC_HAND);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.cbWndExtra = sizeof(MIcoTabCtrl*);
wc.hbrBackground = 0; //GetStockObject(WHITE_BRUSH);
wc.style = CS_GLOBALCLASS/*|CS_SAVEBITS*/;
RegisterClassEx(&wc);
return 0;
}
static void MIcoTab_SetupColors(MIcoTabCtrl *dat)
{
COLORREF cl;
cl = GetSysColor(COLOR_WINDOW);
dat->rgbBkgBottom.rgbRed = (dat->rgbBkgTop.rgbRed = GetRValue(cl)) * .95;
dat->rgbBkgBottom.rgbGreen = (dat->rgbBkgTop.rgbGreen = GetGValue(cl)) * .95;
dat->rgbBkgBottom.rgbBlue = (dat->rgbBkgTop.rgbBlue = GetBValue(cl)) * .95;
cl = GetSysColor(COLOR_HIGHLIGHT);
dat->rgbSelTop.rgbRed = (dat->rgbSelBottom.rgbRed = GetRValue(cl)) * .75;
dat->rgbSelTop.rgbGreen = (dat->rgbSelBottom.rgbGreen = GetGValue(cl)) * .75;
dat->rgbSelTop.rgbBlue = (dat->rgbSelBottom.rgbBlue = GetBValue(cl)) * .75;
dat->rgbHotTop.rgbRed = (dat->rgbSelTop.rgbRed + 255) / 2;
dat->rgbHotTop.rgbGreen = (dat->rgbSelTop.rgbGreen + 255) / 2;
dat->rgbHotTop.rgbBlue = (dat->rgbSelTop.rgbBlue + 255) / 2;
dat->rgbHotBottom.rgbRed = (dat->rgbSelBottom.rgbRed + 255) / 2;
dat->rgbHotBottom.rgbGreen = (dat->rgbSelBottom.rgbGreen + 255) / 2;
dat->rgbHotBottom.rgbBlue = (dat->rgbSelBottom.rgbBlue + 255) / 2;
dat->clText = GetSysColor(COLOR_WINDOWTEXT);
dat->clSelText = GetSysColor(COLOR_HIGHLIGHTTEXT);
dat->clSelBorder = RGB(dat->rgbSelTop.rgbRed, dat->rgbSelTop.rgbGreen, dat->rgbSelTop.rgbBlue);
dat->clHotBorder = RGB(dat->rgbHotTop.rgbRed, dat->rgbHotTop.rgbGreen, dat->rgbHotTop.rgbBlue);
if ( !dat->hFont) dat->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
}
static void MIcoTab_FillRect(HDC hdc, int x, int y, int width, int height, COLORREF cl)
{
int oldMode = SetBkMode(hdc, OPAQUE);
COLORREF oldColor = SetBkColor(hdc, cl);
RECT rc; SetRect(&rc, x, y, x+width, y+height);
ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, "", 0, 0);
SetBkMode(hdc, oldMode);
SetBkColor(hdc, oldColor);
}
static void MIcoTab_DrawGradient(HDC hdc, int x, int y, int width, int height, RGBQUAD *rgb0, RGBQUAD *rgb1)
{
int oldMode = SetBkMode(hdc, OPAQUE);
COLORREF oldColor = SetBkColor(hdc, 0);
RECT rc; SetRect(&rc, x, 0, x+width, 0);
for (int i=y+height; --i >= y;) {
COLORREF color = RGB(
((height-i-1)*rgb0->rgbRed + i*rgb1->rgbRed) / height,
((height-i-1)*rgb0->rgbGreen + i*rgb1->rgbGreen) / height,
((height-i-1)*rgb0->rgbBlue + i*rgb1->rgbBlue) / height);
rc.top = rc.bottom = i;
++rc.bottom;
SetBkColor(hdc, color);
ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, "", 0, 0);
}
SetBkMode(hdc, oldMode);
SetBkColor(hdc, oldColor);
}
static void MIcoTab_DrawItem(HWND hwnd, HDC hdc, MIcoTabCtrl *dat, MIcoTab *tab, int i)
{
int iTopSpace = IsAeroMode() ? 0 : ITC_BORDER_SIZE;
int itemX = ITC_BORDER_SIZE + dat->itemWidth * i;
int iconTop = iTopSpace + 5;
int textTop = iconTop + 32 + 3;
HFONT hFntSave = NULL;
if (dat->nSelectedIdx == i) {
LOGFONT lf;
GetObject(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
lf.lfWeight = FW_BOLD;
hFntSave = (HFONT)SelectObject(hdc, CreateFontIndirect(&lf));
if (IsVSMode()) {
RECT rc;
rc.left = itemX;
rc.top = iTopSpace;
rc.right = itemX + dat->itemWidth;
rc.bottom = iTopSpace + dat->itemHeight;
HANDLE hTheme = openThemeData(hwnd, L"ListView");
if (dat->nHotIdx == i || GetFocus() == hwnd)
drawThemeBackground(hTheme, hdc, LVP_LISTITEM, LISS_HOTSELECTED, &rc, NULL);
else
drawThemeBackground(hTheme, hdc, LVP_LISTITEM, LISS_SELECTED, &rc, NULL);
closeThemeData(hTheme);
}
else {
MIcoTab_FillRect(hdc, itemX, ITC_BORDER_SIZE, dat->itemWidth, dat->itemHeight, dat->clSelBorder);
MIcoTab_DrawGradient(hdc, itemX+1, ITC_BORDER_SIZE+1, dat->itemWidth-2, dat->itemHeight-2, &dat->rgbSelTop, &dat->rgbSelBottom);
}
SetTextColor(hdc, dat->clSelText);
}
else if (dat->nHotIdx == i) {
if (IsVSMode()) {
RECT rc;
rc.left = itemX;
rc.top = iTopSpace;
rc.right = itemX + dat->itemWidth;
rc.bottom = iTopSpace + dat->itemHeight;
setWindowTheme(hwnd, L"explorer", NULL);
HANDLE hTheme = openThemeData(hwnd, L"ListView");
drawThemeBackground(hTheme, hdc, LVP_LISTITEM, LISS_HOT, &rc, NULL);
closeThemeData(hTheme);
}
else {
MIcoTab_FillRect(hdc, itemX, ITC_BORDER_SIZE, dat->itemWidth, dat->itemHeight, dat->clHotBorder);
MIcoTab_DrawGradient(hdc, itemX+1, ITC_BORDER_SIZE+1, dat->itemWidth-2, dat->itemHeight-2, &dat->rgbHotTop, &dat->rgbHotBottom);
}
SetTextColor(hdc, dat->clHotText);
}
else SetTextColor(hdc, dat->clText);
RECT textRect;
textRect.left=itemX;
textRect.right=itemX+dat->itemWidth;
textRect.top=textTop;
textRect.bottom=iconTop+dat->itemHeight;
DrawIcon(hdc, itemX+dat->itemWidth/2-16, iconTop, tab->hIcon);
if (IsVSMode()) {
DTTOPTS dto = {0};
dto.dwSize = sizeof(dto);
dto.dwFlags = DTT_COMPOSITED|DTT_GLOWSIZE;
dto.iGlowSize = 10;
HANDLE hTheme = openThemeData(hwnd, L"Window");
wchar_t *tcsNameW = mir_t2u(tab->tcsName);
drawThemeTextEx(hTheme, hdc, WP_CAPTION, CS_ACTIVE, tcsNameW, -1, DT_VCENTER|DT_CENTER|DT_END_ELLIPSIS, &textRect, &dto);
mir_free(tcsNameW);
closeThemeData(hTheme);
}
else DrawText(hdc, tab->tcsName, -1, &textRect, DT_VCENTER|DT_CENTER|DT_END_ELLIPSIS);
if (hFntSave)
DeleteObject(SelectObject(hdc, hFntSave));
}
static LRESULT MIcoTab_OnPaint(HWND hwndDlg, MIcoTabCtrl *mit, UINT msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HBITMAP hBmp, hOldBmp;
RECT temprc;
int i;
HDC hdc=BeginPaint(hwndDlg, &ps);
HDC tempDC=CreateCompatibleDC(hdc);
HFONT hFont = 0;
BITMAPINFO bmi;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = mit->width;
bmi.bmiHeader.biHeight = -mit->height; // we need this for DrawThemeTextEx
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
hBmp = CreateDIBSection(tempDC, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
hOldBmp=(HBITMAP)SelectObject(tempDC, hBmp);
if (IsAeroMode()) {
temprc.left=0;
temprc.right=mit->width;
temprc.top=0;
temprc.bottom=mit->width;
FillRect(tempDC, &temprc, (HBRUSH)GetStockObject(BLACK_BRUSH));
}
else {
if (mit->hBkgBmp)
StretchBlt(tempDC, 0, 0, mit->width, mit->height, mit->hBkgDC, 0, 0, mit->BkgSize.cx, mit->BkgSize.cy, SRCCOPY);
else {
if (IsVSMode())
MIcoTab_FillRect(tempDC, 0, 0, mit->width, mit->height, GetSysColor(COLOR_WINDOW));
else
MIcoTab_DrawGradient(tempDC, 0, 0, mit->width, mit->height, &mit->rgbBkgTop, &mit->rgbBkgBottom);
MIcoTab_FillRect(tempDC, 0, mit->height-2, mit->width, 1, GetSysColor(COLOR_BTNSHADOW));
MIcoTab_FillRect(tempDC, 0, mit->height-1, mit->width, 1, GetSysColor(COLOR_BTNHIGHLIGHT));
} }
//Draw Items
hFont = mit->hFont;
SelectObject(tempDC, hFont);
SetBkMode(tempDC, TRANSPARENT);
for (i=0; i<mit->pList.getCount(); i++) {
MIcoTab *tab = (MIcoTab *)mit->pList[i];
MIcoTab_DrawItem(hwndDlg, tempDC, mit, tab, i);
}
//Copy to output
BitBlt(hdc, mit->rc.left, mit->rc.top, mit->width, mit->height, tempDC, 0, 0, SRCCOPY);
SelectObject(tempDC, hOldBmp);
DeleteObject(hBmp);
DeleteDC(tempDC);
EndPaint(hwndDlg, &ps);
return TRUE;
}
static LRESULT CALLBACK MIcoTabWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
MIcoTabCtrl* itc = (MIcoTabCtrl *)GetWindowLongPtr(hwndDlg, 0);
switch(msg) {
case WM_NCCREATE:
itc = new MIcoTabCtrl; //(MIcoTabCtrl*)mir_alloc(sizeof(MIcoTabCtrl));
if (itc == NULL) return FALSE;
itc->nSelectedIdx=-1;
itc->nHotIdx=-1;
itc->bMouseInside = FALSE;
SetWindowLongPtr(hwndDlg, 0, (LONG_PTR)itc);
MIcoTab_SetupColors(itc);
if (IsAeroMode()) {
RECT rc; GetWindowRect(hwndDlg, &rc);
MARGINS margins = {0, 0, rc.bottom-rc.top, 0};
dwmExtendFrameIntoClientArea(GetParent(hwndDlg), &margins);
}
return TRUE;
case WM_SETFONT:
itc->hFont = (HFONT)wParam;
break;
case WM_SIZE:
GetClientRect(hwndDlg, &itc->rc);
itc->width=itc->rc.right-itc->rc.left;
itc->height=itc->rc.bottom-itc->rc.top;
if (itc->pList.getCount()) {
itc->itemWidth=(itc->width-2*ITC_BORDER_SIZE)/itc->pList.getCount();
itc->itemHeight=itc->height-2*ITC_BORDER_SIZE-2;
}
else itc->itemWidth = itc->itemHeight = 0;
return TRUE;
case WM_THEMECHANGED:
case WM_STYLECHANGED:
MIcoTab_SetupColors(itc);
return TRUE;
case WM_MOUSEMOVE:
if ( !itc->bMouseInside) {
TRACKMOUSEEVENT tme = {0};
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwndDlg;
_TrackMouseEvent(&tme);
itc->bMouseInside = TRUE;
}
itc->nHotIdx = (LOWORD(lParam) - ITC_BORDER_SIZE) / itc->itemWidth;
if (itc->nHotIdx >= itc->pList.getCount())
itc->nHotIdx = -1;
RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE);
return 0;
case WM_MOUSELEAVE:
itc->bMouseInside = FALSE;
itc->nHotIdx = -1;
RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE);
return 0;
case WM_LBUTTONUP:
if ((itc->nHotIdx >= 0) && (itc->nHotIdx != itc->nSelectedIdx))
{
itc->nSelectedIdx = itc->nHotIdx;
SetWindowText(hwndDlg, itc->pList[itc->nSelectedIdx]->tcsName);
RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE);
SendMessage(GetParent(hwndDlg), WM_COMMAND,
MAKEWPARAM(GetWindowLongPtr(hwndDlg, GWL_ID), ITCN_SELCHANGED),
itc->nSelectedIdx);
}
return 0;
case WM_SETFOCUS:
case WM_KILLFOCUS:
RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE);
break;
case WM_MOUSEACTIVATE:
SetFocus(hwndDlg);
return MA_ACTIVATE;
case WM_GETDLGCODE:
{
if (lParam)
{
MSG *msg = (MSG *) lParam;
if (msg->message == WM_KEYDOWN)
{
if (msg->wParam == VK_TAB)
return 0;
if (msg->wParam == VK_ESCAPE)
return 0;
} else
if (msg->message == WM_CHAR)
{
if (msg->wParam == '\t')
return 0;
if (msg->wParam == 27)
return 0;
}
}
return DLGC_WANTMESSAGE;
}
case WM_KEYDOWN:
{
int newIdx = itc->nSelectedIdx;
switch (wParam)
{
case VK_NEXT:
case VK_RIGHT:
newIdx++;
break;
case VK_PRIOR:
case VK_LEFT:
newIdx--;
break;
}
if ((newIdx >= 0) && (newIdx < itc->pList.getCount()) && (newIdx != itc->nSelectedIdx))
{
itc->nSelectedIdx = newIdx;
SetWindowText(hwndDlg, itc->pList[itc->nSelectedIdx]->tcsName);
RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE);
SendMessage(GetParent(hwndDlg), WM_COMMAND,
MAKEWPARAM(GetWindowLongPtr(hwndDlg, GWL_ID), ITCN_SELCHANGEDKBD),
itc->nSelectedIdx);
}
return 0;
}
case WM_ERASEBKGND:
return 1;
case WM_NCPAINT:
InvalidateRect(hwndDlg, NULL, FALSE);
break;
case WM_PAINT:
MIcoTab_OnPaint(hwndDlg, itc, msg, wParam, lParam);
break;
case ITCM_SETBACKGROUND:
itc->hBkgBmp=(HBITMAP)lParam;
if ( !itc->hBkgDC)
itc->hBkgDC = CreateCompatibleDC(NULL);
itc->hBkgOldBmp = (HBITMAP)SelectObject(itc->hBkgDC, itc->hBkgBmp);
{
BITMAPINFO bmp;
GetObject(itc->hBkgBmp, sizeof(bmp), &bmp);
itc->BkgSize.cx=bmp.bmiHeader.biWidth;
itc->BkgSize.cy=bmp.bmiHeader.biHeight;
}
return TRUE;
case ITCM_ADDITEM:
{
MIcoTab* pMit=(MIcoTab *)wParam;
if ( !pMit)
return FALSE;
MIcoTab* pListMit=(MIcoTab *)mir_calloc(sizeof(MIcoTab));
pListMit->flag=pMit->flag;
pListMit->data=pMit->data;
if (pMit->flag & MITCF_UNICODE)
pListMit->tcsName=mir_u2t(pMit->lpwzName);
else
pListMit->tcsName=mir_a2t(pMit->lpzName);
if (pMit->hIcon) {
if (pListMit->flag&MITCF_SHAREDICON)
pListMit->hIcon=pMit->hIcon;
else
pListMit->hIcon=CopyIcon(pMit->hIcon);
}
itc->pList.insert(pListMit);
itc->itemWidth=(itc->width-2*ITC_BORDER_SIZE)/itc->pList.getCount();
itc->itemHeight=itc->height-2*ITC_BORDER_SIZE-2;
RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE);
return TRUE;
}
case ITCM_SETSEL:
if (wParam >= 0 && (int)wParam < itc->pList.getCount()) {
itc->nSelectedIdx = wParam;
SetWindowText(hwndDlg, itc->pList[itc->nSelectedIdx]->tcsName);
RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE);
SendMessage(GetParent(hwndDlg), WM_COMMAND,
MAKEWPARAM(GetWindowLongPtr(hwndDlg, GWL_ID), ITCN_SELCHANGED),
itc->nSelectedIdx);
}
return TRUE;
case ITCM_GETSEL:
return itc->nSelectedIdx;
case ITCM_GETITEMDATA:
if (wParam >= 0 && (int)wParam < itc->pList.getCount())
return ((MIcoTab *)itc->pList[wParam])->data;
return 0;
case WM_DESTROY:
if (itc->hBkgDC) {
SelectObject(itc->hBkgDC, itc->hBkgOldBmp);
DeleteDC(itc->hBkgDC);
}
li_ListDestruct(itc->pList, MITListDestructor);
delete itc;
return TRUE;
}
return DefWindowProc(hwndDlg, msg, wParam, lParam);
}
|