1
0

wa_dlg.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /*
  2. ** Copyright © 2003-2014 Winamp SA
  3. **
  4. ** This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held
  5. ** liable for any damages arising from the use of this software.
  6. **
  7. ** Permission is granted to anyone to use this software for any purpose, including commercial applications, and to
  8. ** alter it and redistribute it freely, subject to the following restrictions:
  9. **
  10. ** 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
  11. ** If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  12. **
  13. ** 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  14. **
  15. ** 3. This notice may not be removed or altered from any source distribution.
  16. **
  17. */
  18. #ifndef _WA_DLG_H_
  19. #define _WA_DLG_H_
  20. #include "wa_ipc.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /*
  25. 1) gen.bmp has a generic window frame for plugins to use.
  26. its format is similar to the minibrowser's.
  27. In addition gen.bmp includes a font for the titlebar, in both
  28. highlight and no-highlight modes. The font is variable width,
  29. and it uses the first color before the letter A as the delimiter.
  30. The no-highlight form of letter must be the same width as the
  31. highlight form.
  32. 2) genex.bmp has button and scrollbar images, as well as some individual
  33. pixels that describe the colors for the dialog. The button and
  34. scrollbar images should be self explanatory (note that the buttons
  35. have 4 pixel sized edges that are not stretched, and the center is
  36. stretched), and the scrollbars do something similar.
  37. The colors start at (48,0) and run every other pixel. The meaning
  38. of each pixel is:
  39. x=48: item background (background to edits, listviews etc)
  40. x=50: item foreground (text color of edit/listview, etc)
  41. x=52: window background (used to set the bg color for the dialog)
  42. x=54: button text color
  43. x=56: window text color
  44. x=58: color of dividers and sunken borders
  45. x=60: selection color for playlists
  46. x=62: listview header background color
  47. x=64: listview header text color
  48. x=66: listview header frame top color
  49. x=68: listview header frame middle color
  50. x=70: listview header frame bottom color
  51. x=72: listview header empty color
  52. x=74: scrollbar foreground color
  53. x=76: scrollbar background color
  54. x=78: inverse scrollbar foreground color
  55. x=80: inverse scrollbar background color
  56. x=82: scrollbar dead area color
  57. x=84: listview/treeview selection bar text color (active)
  58. x=86: listview/treeview selection bar back color (active)
  59. x=88: listview/treeview selection bar text color (inactive)
  60. x=90: listview/treeview selection bar back color (inactive)
  61. x=92: listview header alternating background color (added with 5.55+ or will revert to x=48)
  62. x=94: listview header alternating text color (added with 5.55+ or will revert to x=50)
  63. */
  64. #define DCW_SUNKENBORDER 0x00010000
  65. #define DCW_DIVIDER 0x00020000
  66. enum
  67. {
  68. WADLG_ITEMBG,
  69. WADLG_ITEMFG,
  70. WADLG_WNDBG,
  71. WADLG_BUTTONFG,
  72. WADLG_WNDFG,
  73. WADLG_HILITE,
  74. WADLG_SELCOLOR,
  75. WADLG_LISTHEADER_BGCOLOR,
  76. WADLG_LISTHEADER_FONTCOLOR,
  77. WADLG_LISTHEADER_FRAME_TOPCOLOR,
  78. WADLG_LISTHEADER_FRAME_MIDDLECOLOR,
  79. WADLG_LISTHEADER_FRAME_BOTTOMCOLOR,
  80. WADLG_LISTHEADER_EMPTY_BGCOLOR,
  81. WADLG_SCROLLBAR_FGCOLOR,
  82. WADLG_SCROLLBAR_BGCOLOR,
  83. WADLG_SCROLLBAR_INV_FGCOLOR,
  84. WADLG_SCROLLBAR_INV_BGCOLOR,
  85. WADLG_SCROLLBAR_DEADAREA_COLOR,
  86. WADLG_SELBAR_FGCOLOR,
  87. WADLG_SELBAR_BGCOLOR,
  88. WADLG_INACT_SELBAR_FGCOLOR,
  89. WADLG_INACT_SELBAR_BGCOLOR,
  90. WADLG_ITEMBG2, // added with 5.55+ (otherwise will revert to WADLG_ITEMBG)
  91. WADLG_ITEMFG2, // added with 5.55+ (otherwise will revert to WADLG_ITEMBG)
  92. WADLG_NUM_COLORS
  93. };
  94. typedef enum _WACURSOR // used in IPC_GETSKINCURSORS
  95. {
  96. WACURSOR_VOLUME = 0, // volume & balane
  97. WACURSOR_POSITION = 1, // position
  98. WACURSOR_BTN_WINSHADE = 2, // winshade
  99. WACURSOR_BTN_MINIMIZE = 3, // minimize
  100. WACURSOR_BTN_CLOSE = 4, // close
  101. WACURSOR_MENU = 5, // main menu
  102. WACURSOR_TITLEBAR = 6, // title bar
  103. WACURSOR_SONGNAME = 7,
  104. WACURSOR_NORMAL = 8,
  105. WACURSOR_WINSHADE_BTN_WINSHADE = 9,
  106. WACURSOR_WINSHADE_BTN_MINIMIZE = 10,
  107. WACURSOR_WINSHADE_POSITION = 11,
  108. WACURSOR_WINSHADE_BTN_CLOSE = 12,
  109. WACURSOR_WINSHADE_MENU = 13,
  110. WACURSOR_WINSHADE_NORMAL = 14,
  111. WACURSOR_PL_BTN_WINSHADE = 15,
  112. WACURSOR_PL_BTN_CLOSE = 16,
  113. WACURSOR_PL_TITLEBAR = 17,
  114. WACURSOR_PL_VSCROLL = 18,
  115. WACURSOR_PL_RESIZE = 19,
  116. WACURSOR_PL_NORMAL = 20,
  117. WACURSOR_PL_WINSHADE_BTN_WINSHADE = 21,
  118. WACURSOR_PL_WINSHADE_BTN_CLOSE = 22,
  119. WACURSOR_PL_WINSHADE_HSIZE = 23,
  120. WACURSOR_PL_WINSHADE_NORMAL = 24,
  121. WACURSOR_EQ_SLIDER = 25,
  122. WACURSOR_EQ_BTN_CLOSE = 26,
  123. WACURSOR_EQ_TITLEBAR = 27,
  124. WACURSOR_EQ_NORMAL = 28,
  125. } WACURSOR;
  126. void WADlg_init(HWND hwndWinamp); // call this on init, or on WM_DISPLAYCHANGE
  127. int WADlg_initted();
  128. void WADlg_close();
  129. int WADlg_getColor(int idx);
  130. HBITMAP WADlg_getBitmap();
  131. void WADlg_setSolidBorder(int solidborder);
  132. LRESULT WADlg_handleDialogMsgs(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); //
  133. void WADlg_DrawChildWindowBorders(HWND hwndDlg, int *tab, int tabsize); // each entry in tab would be the id | DCW_*
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137. #endif//_WA_DLG_H_
  138. // define WA_DLG_IMPLEMENT in one of your source files before including this .h
  139. // if you are making a media library plugin, you dont need to do this, look at view_ex for
  140. // an example of how to get the function *'s via an IPC message.
  141. #if (defined WA_DLG_IMPLEMENT && !defined WA_DLG_IMPLEMENT_DONE)
  142. #define WA_DLG_IMPLEMENT_DONE
  143. #ifdef __cplusplus
  144. extern "C" {
  145. #endif
  146. static int wadlg_solidborder=0;
  147. static HBRUSH wadlg_lastbrush=0;
  148. static HBITMAP wadlg_bitmap=0; // load this manually
  149. static int wadlg_colors[WADLG_NUM_COLORS];
  150. static int wadlg_defcolors[WADLG_NUM_COLORS]=
  151. {
  152. RGB(0,0,0),
  153. RGB(0,255,0),
  154. RGB(36,36,60),
  155. RGB(57,56,66),
  156. RGB(255,255,255),
  157. RGB(132,148,165),
  158. RGB(0,0,198),
  159. RGB(72,72,120),
  160. RGB(255,255,255),
  161. RGB(108,108,180),
  162. RGB(36,36,60),
  163. RGB(18,18,30),
  164. RGB(36,36,60),
  165. RGB(36,36,60),
  166. RGB(36,36,60),
  167. RGB(121,130,150),
  168. RGB(78,88,110),
  169. RGB(36,36,60),
  170. RGB(255,255,255),
  171. RGB(0,0,180),
  172. RGB(0,255,0),
  173. RGB(0,0,128),
  174. RGB(0,0,0),
  175. RGB(0,255,0),
  176. };
  177. int WADlg_initted()
  178. {
  179. return !!wadlg_bitmap;
  180. }
  181. int WADlg_getColor(int idx)
  182. {
  183. if (idx < 0 || idx >= WADLG_NUM_COLORS) return 0;
  184. return wadlg_colors[idx];
  185. }
  186. HBITMAP WADlg_getBitmap()
  187. {
  188. return wadlg_bitmap;
  189. }
  190. // set this to draw the border all the way around the control
  191. void WADlg_setSolidBorder(int solidborder)
  192. {
  193. wadlg_solidborder = solidborder;
  194. }
  195. void WADlg_init(HWND hwndWinamp) // call this on init, or on WM_DISPLAYCHANGE
  196. {
  197. if (wadlg_bitmap) DeleteObject(wadlg_bitmap);
  198. wadlg_bitmap = (HBITMAP) SendMessage(hwndWinamp,WM_WA_IPC,0,IPC_GET_GENSKINBITMAP);
  199. if (wadlg_bitmap)
  200. {
  201. HDC tmpDC=CreateCompatibleDC(NULL);
  202. HGDIOBJ o=SelectObject(tmpDC,(HGDIOBJ)wadlg_bitmap);
  203. int defbgcol=GetPixel(tmpDC,111,0);
  204. for (int x = 0; x < WADLG_NUM_COLORS; x ++)
  205. {
  206. int a=GetPixel(tmpDC,48+x*2,0);
  207. if (a == CLR_INVALID || a == RGB(0,198,255) || a == defbgcol)
  208. {
  209. //defaults for old skins
  210. if (x == WADLG_SELBAR_FGCOLOR || x == WADLG_INACT_SELBAR_FGCOLOR) a=wadlg_colors[WADLG_WNDFG];
  211. else if (x == WADLG_SELBAR_BGCOLOR || x == WADLG_INACT_SELBAR_BGCOLOR)
  212. {
  213. a=wadlg_colors[WADLG_SELCOLOR];
  214. if (x == WADLG_INACT_SELBAR_BGCOLOR)
  215. a=((a/2)&0x7F7F7F)+(((wadlg_colors[WADLG_WNDBG])/2)&0x7F7F7F);
  216. }
  217. else if (x == WADLG_ITEMBG2)
  218. {
  219. a=wadlg_colors[WADLG_ITEMBG];
  220. }
  221. else if (x == WADLG_ITEMFG2)
  222. {
  223. a=wadlg_colors[WADLG_ITEMFG];
  224. }
  225. else a=wadlg_defcolors[x];
  226. }
  227. wadlg_colors[x]=a;
  228. }
  229. SelectObject(tmpDC,o);
  230. DeleteDC(tmpDC);
  231. }
  232. }
  233. void WADlg_close()
  234. {
  235. if (wadlg_bitmap) DeleteObject(wadlg_bitmap);
  236. wadlg_bitmap=0;
  237. if (wadlg_lastbrush) DeleteObject(wadlg_lastbrush);
  238. wadlg_lastbrush=0;
  239. }
  240. void WADlg_dotLine(HDC hdc, int left, int top, int len, int vert)
  241. {
  242. for (int i=(top&1);i<len-1;i+=2)
  243. {
  244. if (vert)
  245. {
  246. MoveToEx(hdc,left,top+i,NULL);
  247. LineTo(hdc,left,top+i+1);
  248. }
  249. else
  250. {
  251. MoveToEx(hdc,left+i,top,NULL);
  252. LineTo(hdc,left+i+1,top);
  253. }
  254. }
  255. }
  256. LRESULT WADlg_handleDialogMsgs(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  257. {
  258. if (uMsg == WM_DRAWITEM)
  259. {
  260. DRAWITEMSTRUCT *di = (DRAWITEMSTRUCT *)lParam;
  261. if (di->CtlType == ODT_BUTTON)
  262. {
  263. wchar_t wt[256] = {0};
  264. GetDlgItemTextW(hwndDlg,(INT)wParam,wt,ARRAYSIZE(wt));
  265. HDC hdc = CreateCompatibleDC(di->hDC);
  266. HBITMAP hbmpOld = (HBITMAP)SelectObject(hdc, wadlg_bitmap);
  267. RECT r=di->rcItem;
  268. SetStretchBltMode(di->hDC,COLORONCOLOR);
  269. int yoffs = (di->itemState & ODS_SELECTED) ? 15 : 0;
  270. BitBlt(di->hDC,r.left,r.top,4,4,hdc,0,yoffs,SRCCOPY); // top left
  271. StretchBlt(di->hDC,r.left+4,r.top,r.right-r.left-4-4,4,hdc,4,yoffs,47-4-4,4,SRCCOPY); // top center
  272. BitBlt(di->hDC,r.right-4,r.top,4,4,hdc,47-4,yoffs,SRCCOPY); // top right
  273. StretchBlt(di->hDC,r.left,r.top+4,4,r.bottom-r.top-4-4,hdc,0,4+yoffs,4,15-4-4,SRCCOPY); // left edge
  274. StretchBlt(di->hDC,r.right-4,r.top+4,4,r.bottom-r.top-4-4,hdc,47-4,4+yoffs,4,15-4-4,SRCCOPY); // right edge
  275. // center
  276. StretchBlt(di->hDC,r.left+4,r.top+4,r.right-r.left-4-4,r.bottom-r.top-4-4,hdc,4,4+yoffs,47-4-4,15-4-4,SRCCOPY);
  277. BitBlt(di->hDC,r.left,r.bottom-4,4,4,hdc,0,15-4+yoffs,SRCCOPY); // bottom left
  278. StretchBlt(di->hDC,r.left+4,r.bottom-4,r.right-r.left-4-4,4,hdc,4,15-4+yoffs,47-4-4,4,SRCCOPY); // bottom center
  279. BitBlt(di->hDC,r.right-4,r.bottom-4,4,4,hdc,47-4,15-4+yoffs,SRCCOPY); // bottom right
  280. // draw text
  281. SetBkMode(di->hDC,TRANSPARENT);
  282. // this will do a different style for the button text depending on enabled state of the button
  283. COLORREF colour = wadlg_colors[WADLG_BUTTONFG];
  284. if (!IsWindowEnabled(di->hwndItem))
  285. {
  286. COLORREF fg = wadlg_colors[WADLG_WNDFG],
  287. bg = wadlg_colors[WADLG_WNDBG];
  288. colour = RGB((GetRValue(fg)+GetRValue(bg))/2,
  289. (GetGValue(fg)+GetGValue(bg))/2,
  290. (GetBValue(fg)+GetBValue(bg))/2);
  291. }
  292. SetTextColor(di->hDC,colour);
  293. if (di->itemState & ODS_SELECTED) {r.left+=2; r.top+=2;}
  294. r.right -= 4; r.left += 5;
  295. DrawTextW(di->hDC,wt,-1,&r,DT_VCENTER|DT_SINGLELINE|DT_CENTER|DT_END_ELLIPSIS);
  296. r.right += 4; r.left -= 5;
  297. SelectObject(hdc, hbmpOld);
  298. DeleteDC(hdc);
  299. if (GetFocus()==di->hwndItem)
  300. {
  301. HPEN hpen = CreatePen(PS_SOLID,0,RGB(0,0,0));
  302. HPEN hpenOld = (HPEN)SelectObject(di->hDC, hpen);
  303. WADlg_dotLine(di->hDC,r.left+2,r.top+2,r.right-r.left-3,0);
  304. WADlg_dotLine(di->hDC,r.right-3,r.top+2,r.bottom-r.top-3,1);
  305. WADlg_dotLine(di->hDC,r.left+2,r.top+2,r.bottom-r.top-3,1);
  306. WADlg_dotLine(di->hDC,r.left+2,r.bottom-3,r.right-r.left-3,0);
  307. SelectObject(di->hDC, hpenOld);
  308. DeleteObject(hpen);
  309. }
  310. }
  311. }
  312. switch (uMsg)
  313. {
  314. case WM_CTLCOLORLISTBOX:
  315. case WM_CTLCOLORDLG:
  316. case WM_CTLCOLORBTN:
  317. case WM_CTLCOLORSTATIC:
  318. case WM_CTLCOLOREDIT:
  319. {
  320. int bgcolor=(uMsg == WM_CTLCOLOREDIT || uMsg == WM_CTLCOLORLISTBOX) ? wadlg_colors[WADLG_ITEMBG] : (uMsg == WM_CTLCOLORBTN ? wadlg_colors[WADLG_ITEMBG] : wadlg_colors[WADLG_WNDBG]);
  321. LOGBRUSH lb={BS_SOLID,GetNearestColor((HDC)wParam,bgcolor)};
  322. if (wadlg_lastbrush) DeleteObject(wadlg_lastbrush);
  323. wadlg_lastbrush=CreateBrushIndirect(&lb);
  324. SetTextColor((HDC)wParam,uMsg == WM_CTLCOLORSTATIC ? wadlg_colors[WADLG_WNDFG] : wadlg_colors[WADLG_ITEMFG]);
  325. SetBkColor((HDC)wParam,lb.lbColor);
  326. return (LRESULT)wadlg_lastbrush;
  327. }
  328. }
  329. return 0;
  330. }
  331. static int RectInRect(RECT *rect1, RECT *rect2)
  332. {
  333. // this has a bias towards true
  334. // this could probably be optimized a lot
  335. return ((rect1->top >= rect2->top && rect1->top <= rect2->bottom) ||
  336. (rect1->bottom >= rect2->top && rect1->bottom <= rect2->bottom) ||
  337. (rect2->top >= rect1->top && rect2->top <= rect1->bottom) ||
  338. (rect2->bottom >= rect1->top && rect2->bottom <= rect1->bottom)) // vertical intersect
  339. &&
  340. ((rect1->left >= rect2->left && rect1->left <= rect2->right) ||
  341. (rect1->right >= rect2->left && rect1->right <= rect2->right) ||
  342. (rect2->left >= rect1->left && rect2->left <= rect1->right) ||
  343. (rect2->right >= rect1->left && rect2->right <= rect1->right)) // horiz intersect
  344. ;
  345. }
  346. static void WADlg_removeFromRgn(HRGN hrgn, int left, int top, int right, int bottom)
  347. {
  348. HRGN rgn2=CreateRectRgn(left,top,right,bottom);
  349. CombineRgn(hrgn,hrgn,rgn2,RGN_DIFF);
  350. DeleteObject(rgn2);
  351. }
  352. void WADlg_DrawChildWindowBorders(HWND hwndDlg, int *tab, int tabsize)
  353. {
  354. PAINTSTRUCT ps={0};
  355. BeginPaint(hwndDlg,&ps);
  356. HRGN hrgn = (ps.fErase) ? CreateRectRgnIndirect(&ps.rcPaint) : NULL;
  357. HPEN pen = CreatePen(PS_SOLID, 0, wadlg_colors[WADLG_HILITE]);
  358. HGDIOBJ o = SelectObject(ps.hdc, pen);
  359. while (tabsize--)
  360. {
  361. RECT r = {0};
  362. int a = *tab++;
  363. GetWindowRect(GetDlgItem(hwndDlg, a & 0xffff),&r);
  364. MapWindowPoints(HWND_DESKTOP, hwndDlg, (LPPOINT)&r, 2);
  365. if (RectInRect(&ps.rcPaint,&r))
  366. {
  367. if ((a & 0xffff0000) == DCW_SUNKENBORDER)
  368. {
  369. MoveToEx(ps.hdc,r.left,r.bottom,NULL);
  370. LineTo(ps.hdc,r.right,r.bottom);
  371. LineTo(ps.hdc,r.right,r.top-1);
  372. if (hrgn)
  373. {
  374. WADlg_removeFromRgn(hrgn,r.left,r.bottom,r.right,r.bottom+1);
  375. WADlg_removeFromRgn(hrgn,r.right,r.top,r.right+1,r.bottom);
  376. }
  377. }
  378. else if ((a & 0xffff0000) == DCW_DIVIDER)
  379. {
  380. if (r.right - r.left < r.bottom - r.top) // vertical
  381. {
  382. int left=(r.left+r.right)/2;
  383. MoveToEx(ps.hdc,left,r.top,NULL);
  384. LineTo(ps.hdc,left,r.bottom+1);
  385. if (hrgn) WADlg_removeFromRgn(hrgn,left,r.top,left+1,r.bottom);
  386. }
  387. else // horiz
  388. {
  389. int top=(r.top+r.bottom)/2;
  390. MoveToEx(ps.hdc,r.left,top,NULL);
  391. LineTo(ps.hdc,r.right+1,top);
  392. if (hrgn) WADlg_removeFromRgn(hrgn,r.left,top,r.right,top+1);
  393. }
  394. }
  395. }
  396. }
  397. SelectObject(ps.hdc, o);
  398. DeleteObject(pen);
  399. if(hrgn)
  400. {
  401. //erase bkgnd while clipping out our own drawn stuff (for flickerless display)
  402. HBRUSH b = CreateSolidBrush(wadlg_colors[WADLG_WNDBG]);
  403. FillRgn(ps.hdc,hrgn,b);
  404. DeleteObject(b);
  405. DeleteObject(hrgn);
  406. }
  407. EndPaint(hwndDlg,&ps);
  408. }
  409. #ifdef __cplusplus
  410. }
  411. #endif
  412. #endif // WA_DLG_IMPLEMENT