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
|
#include "main.h"
#include <windowsx.h>
#include "./resource.h"
#include "./commandbar.h"
#include <shlwapi.h>
#include <strsafe.h>
static HMLIMGLST hmlilButton = NULL;
static LPCTSTR GetImageTagStr(INT resId)
{
switch(resId)
{
case IDB_PLAY_NORMAL: return TEXT("button.play");
case IDB_PLAY_HIGHLIGHTED: return TEXT("button.play.highlighted");
case IDB_PLAY_PRESSED: return TEXT("button.play.pressed");
case IDB_PLAY_DISABLED: return TEXT("button.play.disabled");
case IDB_ENQUEUE_NORMAL: return TEXT("button.enqueue");
case IDB_ENQUEUE_HIGHLIGHTED: return TEXT("button.enqueue.highlighted");
case IDB_ENQUEUE_PRESSED: return TEXT("button.enqueue.pressed");
case IDB_ENQUEUE_DISABLED: return TEXT("button.enqueue.disabled");
case IDB_EJECT2_NORMAL: return TEXT("button.eject");
case IDB_EJECT2_HIGHLIGHTED: return TEXT("button.eject.highlighted");
case IDB_EJECT2_PRESSED: return TEXT("button.eject.pressed");
case IDB_EJECT2_DISABLED: return TEXT("button.eject.disabled");
}
return NULL;
}
static HMLIMGLST DataCmdBar_CreateImageList()
{
HMLIMGLST hmlil;
MLIMAGELISTCREATE mlilCreate;
MLIMAGESOURCE mlis;
MLIMAGELISTITEM mlilItem;
mlilCreate.cx = g_view_metaconf->ReadIntEx(TEXT("artwork"), TEXT("button.icon.cx"), 12);
mlilCreate.cy = g_view_metaconf->ReadIntEx(TEXT("artwork"), TEXT("button.icon.cy"), 12);
mlilCreate.cInitial = 12;
mlilCreate.cGrow = 3;
mlilCreate.cCacheSize = 4;
mlilCreate.flags = MLILC_COLOR32;
hmlil = MLImageList_Create(plugin.hwndLibraryParent, &mlilCreate);
if (NULL == hmlil) return NULL;
ZeroMemory(&mlilItem, sizeof(MLIMAGELISTITEM));
mlilItem.cbSize = sizeof(MLIMAGELISTITEM);
mlilItem.hmlil = hmlil;
mlilItem.filterUID = MLIF_BUTTONBLENDPLUSCOLOR_UID;
mlilItem.pmlImgSource = &mlis;
ZeroMemory(&mlis, sizeof(MLIMAGESOURCE));
mlis.cbSize = sizeof(MLIMAGESOURCE);
mlis.type = SRC_TYPE_PNG;
mlis.hInst = plugin.hDllInstance;
INT imageList[] =
{ IDB_PLAY_NORMAL, IDB_PLAY_PRESSED, IDB_PLAY_HIGHLIGHTED, IDB_PLAY_DISABLED,
IDB_ENQUEUE_NORMAL, IDB_ENQUEUE_PRESSED, IDB_ENQUEUE_HIGHLIGHTED, IDB_ENQUEUE_DISABLED,
IDB_EJECT2_NORMAL, IDB_EJECT2_PRESSED, IDB_EJECT2_HIGHLIGHTED, IDB_EJECT2_DISABLED,
};
TCHAR szResource[MAX_PATH] = {0}, szPath[MAX_PATH] = {0}, szFullPath[MAX_PATH] = {0};
g_view_metaconf->ReadCchStringEx(szPath, ARRAYSIZE(szPath), TEXT("artwork"), TEXT("path"), NULL);
for(int i = 0; i < sizeof(imageList)/sizeof(imageList[0]); i++)
{
mlilItem.nTag = imageList[i];
g_view_metaconf->ReadCchStringEx(szResource, ARRAYSIZE(szResource), TEXT("artwork"), GetImageTagStr(imageList[i]), NULL);
if (TEXT('\0') != szResource[0])
{
PathCombine(szFullPath, szPath, szResource);
mlis.lpszName = szFullPath;
mlis.flags |= ISF_LOADFROMFILE;
}
else
{
mlis.lpszName = MAKEINTRESOURCE(imageList[i]);
mlis.flags &= ~ISF_LOADFROMFILE;
}
MLImageList_Add(plugin.hwndLibraryParent, &mlilItem);
}
return hmlil;
}
static HMLIMGLST DataCmdBar_CreateDropDownImageList(HMENU hMenu)
{
HMLIMGLST hmlil;
MLIMAGELISTCREATE mlilCreate;
MLIMAGESOURCE mlis;
if (!hMenu) return NULL;
mlilCreate.cx = 16;
mlilCreate.cy = 16;
mlilCreate.cInitial = 2;
mlilCreate.cGrow = 1;
mlilCreate.cCacheSize = 3;
mlilCreate.flags = MLILC_COLOR32;
hmlil = MLImageList_Create(plugin.hwndLibraryParent, &mlilCreate);
if (NULL == hmlil) return NULL;
ZeroMemory(&mlis, sizeof(MLIMAGESOURCE));
mlis.cbSize = sizeof(MLIMAGESOURCE);
mlis.type = SRC_TYPE_PNG;
mlis.hInst = plugin.hDllInstance;
INT imageList[] = { IDB_PLAY_MENU, IDB_ENQUEUE_MENU, };
MENUITEMINFOW mii = { sizeof(MENUITEMINFOW), };
mii.fMask = MIIM_ID;
for(int i = 0; i < sizeof(imageList)/sizeof(imageList[0]); i++)
{
if (GetMenuItemInfoW(hMenu, i, TRUE, &mii))
{
mlis.lpszName = MAKEINTRESOURCEW(imageList[i]);
MLImageList_Add2(plugin.hwndLibraryParent, hmlil, MLIF_FILTER1_UID, &mlis, mii.wID);
}
}
return hmlil;
}
static void DataCmdBar_SetButtonImages(HWND hButton, HMLIMGLST hmlil, INT normal, INT hover, INT pressed, INT disabled)
{
MLBUTTONIMAGELIST bil;
MLIMAGELISTTAG t;
bil.hmlil = hmlil;
t.hmlil = bil.hmlil;
t.nTag = normal;
bil.normalIndex = (MLImageList_GetIndexFromTag(plugin.hwndLibraryParent, &t)) ? t.mlilIndex : -1;
if (disabled == normal) bil.disabledIndex = bil.normalIndex;
else
{
t.nTag = disabled;
bil.disabledIndex = (MLImageList_GetIndexFromTag(plugin.hwndLibraryParent, &t)) ? t.mlilIndex : bil.normalIndex;
}
if (hover == normal) bil.hoverIndex = bil.normalIndex;
else if (hover == disabled) bil.hoverIndex = bil.disabledIndex;
else
{
t.nTag = hover;
bil.hoverIndex = (MLImageList_GetIndexFromTag(plugin.hwndLibraryParent, &t)) ? t.mlilIndex : bil.normalIndex;
}
if (pressed == normal) bil.pressedIndex = bil.normalIndex;
else if (pressed == disabled) bil.pressedIndex = bil.disabledIndex;
else if (pressed == hover) bil.pressedIndex = bil.hoverIndex;
else
{
t.nTag = pressed;
bil.pressedIndex = (MLImageList_GetIndexFromTag(plugin.hwndLibraryParent, &t)) ? t.mlilIndex : bil.normalIndex;
}
SENDMLIPC(hButton, ML_IPC_SKINNEDBUTTON_SETIMAGELIST, (LPARAM)&bil);
}
static void PlayEx_Initialize(HWND hdlg)
{
HWND hButton = GetDlgItem(hdlg, IDC_BTN_PLAYEX);
if (!hButton) return;
HWND hFileView = (HWND)CommandBar_GetData(hdlg);
if (NULL == hFileView) return;
HMENU hMenu = FileView_GetMenu(hFileView, FVMENU_PLAY);
if (!hMenu) return;
BOOL bPlay = (!hFileView || 0 == (FVS_ENQUEUE & FileView_GetStyle(hFileView)));
WCHAR szBuffer[256] = {0};
MENUITEMINFOW mii = { sizeof(MENUITEMINFOW), };
mii.fMask = MIIM_STRING;
mii.dwTypeData = szBuffer;
mii.cch = sizeof(szBuffer)/sizeof(szBuffer[0]);
if (GetMenuItemInfoW(hMenu, (bPlay) ? 0 : 1, TRUE, &mii))
{
while(mii.cch && L'\t' != szBuffer[mii.cch]) mii.cch--;
if (mii.cch > 0) szBuffer[mii.cch] = L'\0';
SetWindowTextW(hButton, szBuffer);
}
if (bPlay)
{
DataCmdBar_SetButtonImages(hButton, hmlilButton, IDB_PLAY_NORMAL,
IDB_PLAY_PRESSED, IDB_PLAY_HIGHLIGHTED, IDB_PLAY_DISABLED);
}
else
{
DataCmdBar_SetButtonImages(hButton, hmlilButton, IDB_ENQUEUE_NORMAL,
IDB_ENQUEUE_PRESSED, IDB_ENQUEUE_HIGHLIGHTED, IDB_ENQUEUE_DISABLED);
}
}
static void DataCmdBar_UpdateControls(HWND hdlg, BOOL bRedraw)
{
INT buttonList[] = { IDC_BTN_PLAYEX, IDC_BTN_COPY, };
HDWP hdwp;
DWORD flags, size;
INT w;
flags = SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | ((bRedraw) ? 0 : SWP_NOREDRAW);
hdwp = BeginDeferWindowPos(sizeof(buttonList)/sizeof(buttonList[0]));
if (!hdwp) return;
for(int i =0; i < sizeof(buttonList)/sizeof(buttonList[0]); i++)
{
HWND hctrl = GetDlgItem(hdlg, buttonList[i]);
if (NULL != hctrl)
{
size = 0;
switch(buttonList[i])
{
case IDC_BTN_PLAYEX:
{
HWND hFileView = (HWND)CommandBar_GetData(hdlg);
if (NULL == hFileView) return;
HMENU hMenu = FileView_GetMenu(hFileView, FVMENU_PLAY);
if (hMenu)
{
WCHAR szText[256] = {0};
INT count = GetMenuItemCount(hMenu);
MENUITEMINFO mii = {0};
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING;
mii.dwTypeData = szText;
w = 0;
for (int i = 0; i < count; i++)
{
mii.cch = sizeof(szText)/sizeof(szText[0]);
if (GetMenuItemInfo(hMenu, i, TRUE, &mii))
{
while(mii.cch && L'\t' != szText[mii.cch]) mii.cch--;
if (mii.cch > 0) szText[mii.cch] = L'\0';
size = MLSkinnedButton_GetIdealSize(hctrl, szText);
if (w < LOWORD(size)) w = LOWORD(size);
}
}
size = MAKELONG(w + 8, HIWORD(size));
}
}
break;
default:
size = MLSkinnedButton_GetIdealSize(hctrl, NULL);
break;
}
INT width = LOWORD(size), height = HIWORD(size);
if (width < 82) width = 82;
if (height < 14) height = 14;
hdwp = DeferWindowPos(hdwp, hctrl, NULL, 0, 0, width, height, flags);
}
}
EndDeferWindowPos(hdwp);
SetWindowPos(hdlg, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE |
SWP_NOZORDER | SWP_FRAMECHANGED | ((bRedraw) ? 0 : SWP_NOREDRAW));
}
static BOOL DataCmdBar_OnInitDialog(HWND hdlg, HWND hwndFocus, LPARAM lParam)
{
MLSKINWINDOW sw;
sw.skinType = SKINNEDWND_TYPE_AUTO;
sw.style = SWS_USESKINCOLORS | SWS_USESKINCURSORS | SWS_USESKINFONT;
sw.hwndToSkin = hdlg;
MLSkinWindow(plugin.hwndLibraryParent, &sw);
sw.hwndToSkin = GetDlgItem(hdlg, IDC_BTN_EJECT);
MLSkinWindow(plugin.hwndLibraryParent, &sw);
sw.style |= SWBS_SPLITBUTTON;
sw.hwndToSkin = GetDlgItem(hdlg, IDC_BTN_PLAYEX);
MLSkinWindow(plugin.hwndLibraryParent, &sw);
sw.style = SWS_USESKINCOLORS | SWS_USESKINCURSORS | SWS_USESKINFONT;
sw.hwndToSkin = GetDlgItem(hdlg, IDC_BTN_COPY);
MLSkinWindow(plugin.hwndLibraryParent, &sw);
sw.skinType = SKINNEDWND_TYPE_STATIC;
sw.style = SWS_USESKINCOLORS | SWS_USESKINCURSORS | SWS_USESKINFONT;
sw.hwndToSkin = GetDlgItem(hdlg, IDC_LBL_STATUS);
MLSkinWindow(plugin.hwndLibraryParent, &sw);
hmlilButton = DataCmdBar_CreateImageList();
PlayEx_Initialize(hdlg);
DataCmdBar_SetButtonImages(GetDlgItem(hdlg, IDC_BTN_EJECT), hmlilButton, IDB_EJECT2_NORMAL,
IDB_EJECT2_PRESSED, IDB_EJECT2_HIGHLIGHTED, IDB_EJECT2_DISABLED);
DataCmdBar_UpdateControls(hdlg, FALSE);
return FALSE;
}
static void DataCmdBar_OnDestroy(HWND hdlg)
{
if (hmlilButton)
{
MLImageList_Destroy(plugin.hwndLibraryParent, hmlilButton);
hmlilButton = NULL;
}
}
static void DataCmdBar_OnWindowPosChanged(HWND hdlg, WINDOWPOS *pwp)
{
if (0 == (SWP_NOSIZE & pwp->flags) || 0 != (SWP_FRAMECHANGED & pwp->flags))
{
HWND hctrl;
HDWP hdwp;
RECT rc, rw;
DWORD flags;
if (!GetClientRect(hdlg, &rc)) return;
InflateRect(&rc, -2, 0);
LONG left = rc.left-2;
LONG right = rc.right;
hdwp = BeginDeferWindowPos(4);
if (!hdwp) return;
flags = SWP_NOACTIVATE | SWP_NOZORDER | ((SWP_NOREDRAW | SWP_NOCOPYBITS) & pwp->flags);
if (NULL != (hctrl = GetDlgItem(hdlg, IDC_BTN_PLAYEX)) && GetWindowRect(hctrl, &rw))
{
hdwp = DeferWindowPos(hdwp, hctrl, NULL, left, rc.top, rw.right - rw.left, rc.bottom - rc.top, flags);
left += ((rw.right - rw.left) + 8);
}
if (NULL != (hctrl = GetDlgItem(hdlg, IDC_BTN_COPY)) && GetWindowRect(hctrl, &rw))
{
hdwp = DeferWindowPos(hdwp, hctrl, NULL, left, rc.top, rw.right - rw.left, rc.bottom - rc.top, flags);
left += ((rw.right - rw.left) + 8);
}
if (NULL != (hctrl = GetDlgItem(hdlg, IDC_BTN_EJECT)) && GetWindowRect(hctrl, &rw))
{
right -= (rw.right - rw.left);
if (right < (left + 16)) right = left + 16;
hdwp = DeferWindowPos(hdwp, hctrl, NULL, right, rc.top, rw.right - rw.left, rc.bottom - rc.top, flags);
right -= 4;
}
if (NULL != (hctrl = GetDlgItem(hdlg, IDC_LBL_STATUS)) && GetWindowRect(hctrl, &rw))
{
hdwp = DeferWindowPos(hdwp, hctrl, NULL, left, rc.top, right - left, rc.bottom - rc.top, flags);
}
EndDeferWindowPos(hdwp);
}
if (0 == (SWP_NOREDRAW & pwp->flags)) InvalidateRect(GetDlgItem(hdlg, IDC_LBL_STATUS), NULL, TRUE);
}
static void DataCmdBar_OnPlayDropDown(HWND hdlg, HWND hctrl)
{
RECT r;
if (!GetWindowRect(hctrl, &r)) return;
HWND hFileView = (HWND)CommandBar_GetData(hdlg);
if (NULL == hFileView) return;
HMENU hMenu = FileView_GetMenu(hFileView, FVMENU_PLAY);
if (!hMenu) return;
MLSkinnedButton_SetDropDownState(hctrl, TRUE);
HMLIMGLST hmlilDropDown = DataCmdBar_CreateDropDownImageList(hMenu);
MLTrackSkinnedPopupMenuEx(plugin.hwndLibraryParent, hMenu,
TPM_RIGHTBUTTON | TPM_LEFTBUTTON | TPM_BOTTOMALIGN | TPM_LEFTALIGN | TPM_NONOTIFY,
r.left, r.top - 2, hFileView, NULL, hmlilDropDown, r.right - r.left,
SMS_USESKINFONT, NULL, 0L);
MLSkinnedButton_SetDropDownState(hctrl, FALSE);
MLImageList_Destroy(plugin.hwndLibraryParent, hmlilDropDown);
}
static void DataCmdBar_OnPlayClick(HWND hdlg, HWND hButton)
{
EnableWindow(hButton, FALSE);
HWND hFileView = (HWND)CommandBar_GetData(hdlg);
if (NULL != hFileView)
{
HMENU hMenu = FileView_GetMenu(hFileView, FVMENU_PLAY);
if (NULL != hMenu)
{
UINT uCmd = (FVS_ENQUEUE & FileView_GetStyle(hFileView)) ? FVA_ENQUEUE : FVA_PLAY;
SendMessageW(hFileView, WM_COMMAND, MAKEWPARAM(FileView_GetActionCommand(hFileView, uCmd), 0), 0L);
}
}
EnableWindow(hButton, TRUE);
}
static void DataCmdBar_OnCommand(HWND hdlg, INT eventId, INT ctrlId, HWND hwndCtrl)
{
switch (ctrlId)
{
case IDC_BTN_PLAYEX:
switch(eventId)
{
case MLBN_DROPDOWN: DataCmdBar_OnPlayDropDown(hdlg, hwndCtrl); break;
case BN_CLICKED: DataCmdBar_OnPlayClick(hdlg, hwndCtrl); break;
}
break;
case IDC_BTN_EJECT:
switch(eventId)
{
case BN_CLICKED: SendMessageW(GetParent(hdlg), WM_COMMAND, MAKEWPARAM(ID_EJECT_DISC, 0), 0L); break; // straight to container...
}
break;
case IDC_BTN_COPY:
switch(eventId)
{
case BN_CLICKED: SendMessageW(hdlg, WM_COMMAND, MAKEWPARAM(ID_COPY_SELECTION, 0), 0L); break;
}
break;
}
}
static INT DataCmdBar_OnGetBestHeight(HWND hdlg)
{
INT h, height = 0;
INT buttonList[] = { IDC_BTN_PLAYEX, };
for(int i =0; i < sizeof(buttonList)/sizeof(buttonList[0]); i++)
{
HWND hctrl = GetDlgItem(hdlg, buttonList[i]);
if (NULL != hctrl)
{
DWORD sz = MLSkinnedButton_GetIdealSize(hctrl, NULL);
h = HIWORD(sz);
if (height < h) height = h;
}
}
return height;
}
INT_PTR WINAPI DataCmdBar_DialogProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG: return DataCmdBar_OnInitDialog(hdlg, (HWND)wParam, lParam);
case WM_DESTROY: DataCmdBar_OnDestroy(hdlg); break;
case WM_WINDOWPOSCHANGED: DataCmdBar_OnWindowPosChanged(hdlg, (WINDOWPOS*)lParam); return TRUE;
case WM_COMMAND: DataCmdBar_OnCommand(hdlg, HIWORD(wParam), LOWORD(wParam), (HWND)lParam); break;
case CBM_GETBESTHEIGHT: SetWindowLongPtrW(hdlg, DWLP_MSGRESULT, DataCmdBar_OnGetBestHeight(hdlg)); return TRUE;
case WM_DISPLAYCHANGE:
PlayEx_Initialize(hdlg);
break;
case WM_SETFONT:
DataCmdBar_UpdateControls(hdlg, LOWORD(lParam));
return 0;
case WM_SETTEXT:
case WM_GETTEXT:
case WM_GETTEXTLENGTH:
SetWindowLongPtrW(hdlg, DWLP_MSGRESULT, (LONGX86)(LONG_PTR)SendDlgItemMessageW(hdlg, IDC_LBL_STATUS, uMsg, wParam, lParam));
return TRUE;
}
return 0;
}
|