wa_dlg.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /*
  2. ** Copyright (C) 2003-2008 Nullsoft, Inc.
  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: alternate item background
  62. x=94: alternate item foreground
  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,
  91. WADLG_ITEMFG2,
  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. void WADlg_close();
  128. int WADlg_getColor(int idx);
  129. int WADlg_initted();
  130. LRESULT WADlg_handleDialogMsgs(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); //
  131. void WADlg_DrawChildWindowBorders(HWND hwndDlg, int *tab, int tabsize); // each entry in tab would be the id | DCW_*
  132. HBITMAP WADlg_getBitmap();
  133. /// define WA_DLG_IMPLEMENT in one of your source files before including this .h
  134. // if you are making a media library plugin, you dont need to do this, look at view_ex for
  135. // an example of how to get the function *'s via an IPC message.
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #ifdef WA_DLG_IMPLEMENT
  140. static HBRUSH wadlg_lastbrush=0;
  141. static HBITMAP wadlg_bitmap=0; // load this manually
  142. static int wadlg_colors[WADLG_NUM_COLORS];
  143. static int wadlg_defcolors[WADLG_NUM_COLORS]=
  144. {
  145. RGB(0,0,0),
  146. RGB(0,255,0),
  147. RGB(36,36,60),
  148. RGB(57,56,66),
  149. RGB(255,255,255),
  150. RGB(132,148,165),
  151. RGB(0,0,198),
  152. RGB(36*2,36*2,60*2),
  153. RGB(255,255,255),
  154. RGB(36*3,36*3,60*3),
  155. RGB(36,36,60),
  156. RGB(36*0.5,36*0.5,60*0.5),
  157. RGB(36,36,60),
  158. RGB(36*1,36*1,60*1),
  159. RGB(36*1,36*1,60*1),
  160. RGB(121,130,150),
  161. RGB(78,88,110),
  162. RGB(36*1,36*1,60*1),
  163. RGB(255,255,255),
  164. RGB(0,0,180),
  165. RGB(0,255,0),
  166. RGB(0,0,128),
  167. RGB(0,0,0),
  168. RGB(0,255,0),
  169. };
  170. int WADlg_initted()
  171. {
  172. return !!wadlg_bitmap;
  173. }
  174. int WADlg_getColor(int idx)
  175. {
  176. if (idx < 0 || idx >= WADLG_NUM_COLORS) return 0;
  177. return wadlg_colors[idx];
  178. }
  179. HBITMAP WADlg_getBitmap()
  180. {
  181. return wadlg_bitmap;
  182. }
  183. void WADlg_init(HWND hwndWinamp) // call this on init, or on WM_DISPLAYCHANGE
  184. {
  185. if (wadlg_bitmap) DeleteObject(wadlg_bitmap);
  186. wadlg_bitmap = (HBITMAP) SendMessage(hwndWinamp,WM_WA_IPC,0,IPC_GET_GENSKINBITMAP);
  187. if (wadlg_bitmap)
  188. {
  189. HDC tmpDC=CreateCompatibleDC(NULL);
  190. HGDIOBJ o=SelectObject(tmpDC,(HGDIOBJ)wadlg_bitmap);
  191. int defbgcol=GetPixel(tmpDC,111,0);
  192. for (int x = 0; x < WADLG_NUM_COLORS; x ++)
  193. {
  194. int a=GetPixel(tmpDC,48+x*2,0);
  195. if (a == CLR_INVALID || a == RGB(0,198,255) || a == defbgcol)
  196. {
  197. //defaults for old skins
  198. if (x == WADLG_SELBAR_FGCOLOR || x == WADLG_INACT_SELBAR_FGCOLOR) a=wadlg_colors[WADLG_WNDFG];
  199. else if (x == WADLG_SELBAR_BGCOLOR || x == WADLG_INACT_SELBAR_BGCOLOR)
  200. {
  201. a=wadlg_colors[WADLG_SELCOLOR];
  202. if (x == WADLG_INACT_SELBAR_BGCOLOR)
  203. a=((a/2)&0x7F7F7F)+(((wadlg_colors[WADLG_WNDBG])/2)&0x7F7F7F);
  204. }
  205. else if (x == WADLG_ITEMBG2)
  206. {
  207. a=wadlg_colors[WADLG_ITEMBG];
  208. }
  209. else if (x == WADLG_ITEMFG2)
  210. {
  211. a=wadlg_colors[WADLG_ITEMFG];
  212. }
  213. else a=wadlg_defcolors[x];
  214. }
  215. wadlg_colors[x]=a;
  216. }
  217. SelectObject(tmpDC,o);
  218. DeleteDC(tmpDC);
  219. }
  220. }
  221. void WADlg_close()
  222. {
  223. if (wadlg_bitmap) DeleteObject(wadlg_bitmap);
  224. wadlg_bitmap=0;
  225. if (wadlg_lastbrush) DeleteObject(wadlg_lastbrush);
  226. wadlg_lastbrush=0;
  227. }
  228. void WADlg_dotLine(HDC hdc, int left, int top, int len, int vert)
  229. {
  230. for(int i=(top&1);i<len-1;i+=2)
  231. {
  232. if(vert)
  233. {
  234. MoveToEx(hdc,left,top+i,NULL);
  235. LineTo(hdc,left,top+i+1);
  236. }
  237. else
  238. {
  239. MoveToEx(hdc,left+i,top,NULL);
  240. LineTo(hdc,left+i+1,top);
  241. }
  242. }
  243. }
  244. LRESULT WADlg_handleDialogMsgs(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  245. {
  246. if (uMsg == WM_DRAWITEM)
  247. {
  248. DRAWITEMSTRUCT *di = (DRAWITEMSTRUCT *)lParam;
  249. if (di->CtlType == ODT_BUTTON) {
  250. wchar_t wt[256];
  251. RECT r;
  252. GetDlgItemTextW(hwndDlg,(INT)wParam,wt,sizeof(wt)/sizeof(*wt));
  253. HDC hdc = CreateCompatibleDC(di->hDC);
  254. HBITMAP hbmpOld = (HBITMAP)SelectObject(hdc, wadlg_bitmap);
  255. r=di->rcItem;
  256. SetStretchBltMode(di->hDC,COLORONCOLOR);
  257. int yoffs = (di->itemState & ODS_SELECTED) ? 15 : 0;
  258. BitBlt(di->hDC,r.left,r.top,4,4,hdc,0,yoffs,SRCCOPY); // top left
  259. 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
  260. BitBlt(di->hDC,r.right-4,r.top,4,4,hdc,47-4,yoffs,SRCCOPY); // top right
  261. 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
  262. 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
  263. // center
  264. 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);
  265. BitBlt(di->hDC,r.left,r.bottom-4,4,4,hdc,0,15-4+yoffs,SRCCOPY); // bottom left
  266. 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
  267. BitBlt(di->hDC,r.right-4,r.bottom-4,4,4,hdc,47-4,15-4+yoffs,SRCCOPY); // bottom right
  268. // draw text
  269. SetBkMode(di->hDC,TRANSPARENT);
  270. // this will do a different style for the button text depending on enabled state of the button
  271. COLORREF colour = wadlg_colors[WADLG_BUTTONFG];
  272. if(!IsWindowEnabled(di->hwndItem)){
  273. COLORREF fg = wadlg_colors[WADLG_WNDFG],
  274. bg = wadlg_colors[WADLG_WNDBG];
  275. colour = RGB((GetRValue(fg)+GetRValue(bg))/2,
  276. (GetGValue(fg)+GetGValue(bg))/2,
  277. (GetBValue(fg)+GetBValue(bg))/2);
  278. }
  279. SetTextColor(di->hDC,colour);
  280. if (di->itemState & ODS_SELECTED) {r.left+=2; r.top+=2;}
  281. DrawTextW(di->hDC,wt,-1,&r,DT_VCENTER|DT_SINGLELINE|DT_CENTER);
  282. SelectObject(hdc, hbmpOld);
  283. DeleteDC(hdc);
  284. if(GetFocus()==di->hwndItem) {
  285. HPEN hpen, hpenOld;
  286. hpen =CreatePen(PS_SOLID,0,RGB(0,0,0));
  287. hpenOld = (HPEN)SelectObject(di->hDC, hpen);
  288. WADlg_dotLine(di->hDC,r.left+2,r.top+2,r.right-r.left-3,0);
  289. WADlg_dotLine(di->hDC,r.right-3,r.top+2,r.bottom-r.top-3,1);
  290. WADlg_dotLine(di->hDC,r.left+2,r.top+2,r.bottom-r.top-3,1);
  291. WADlg_dotLine(di->hDC,r.left+2,r.bottom-3,r.right-r.left-3,0);
  292. SelectObject(di->hDC, hpenOld);
  293. DeleteObject(hpen);
  294. }
  295. }
  296. }
  297. switch(uMsg)
  298. {
  299. case WM_CTLCOLORLISTBOX:
  300. case WM_CTLCOLORDLG:
  301. case WM_CTLCOLORBTN:
  302. case WM_CTLCOLORSTATIC:
  303. case WM_CTLCOLOREDIT:
  304. {
  305. int bgcolor=(uMsg == WM_CTLCOLOREDIT || uMsg == WM_CTLCOLORLISTBOX) ? wadlg_colors[WADLG_ITEMBG] : (uMsg == WM_CTLCOLORBTN ? wadlg_colors[WADLG_ITEMBG] : wadlg_colors[WADLG_WNDBG]);
  306. LOGBRUSH lb={BS_SOLID,GetNearestColor((HDC)wParam,bgcolor)};
  307. if (wadlg_lastbrush) DeleteObject(wadlg_lastbrush);
  308. wadlg_lastbrush=CreateBrushIndirect(&lb);
  309. SetTextColor((HDC)wParam,uMsg == WM_CTLCOLORSTATIC ? wadlg_colors[WADLG_WNDFG] : wadlg_colors[WADLG_ITEMFG]);
  310. SetBkColor((HDC)wParam,lb.lbColor);
  311. return (LRESULT)wadlg_lastbrush;
  312. }
  313. }
  314. return 0;
  315. }
  316. static int RectInRect(RECT *rect1, RECT *rect2)
  317. {
  318. // this has a bias towards true
  319. // this could probably be optimized a lot
  320. return ((rect1->top >= rect2->top && rect1->top <= rect2->bottom) ||
  321. (rect1->bottom >= rect2->top && rect1->bottom <= rect2->bottom) ||
  322. (rect2->top >= rect1->top && rect2->top <= rect1->bottom) ||
  323. (rect2->bottom >= rect1->top && rect2->bottom <= rect1->bottom)) // vertical intersect
  324. &&
  325. ((rect1->left >= rect2->left && rect1->left <= rect2->right) ||
  326. (rect1->right >= rect2->left && rect1->right <= rect2->right) ||
  327. (rect2->left >= rect1->left && rect2->left <= rect1->right) ||
  328. (rect2->right >= rect1->left && rect2->right <= rect1->right)) // horiz intersect
  329. ;
  330. }
  331. static void WADlg_removeFromRgn(HRGN hrgn, int left, int top, int right, int bottom)
  332. {
  333. HRGN rgn2=CreateRectRgn(left,top,right,bottom);
  334. CombineRgn(hrgn,hrgn,rgn2,RGN_DIFF);
  335. DeleteObject(rgn2);
  336. }
  337. void WADlg_DrawChildWindowBorders(HWND hwndDlg, int *tab, int tabsize)
  338. {
  339. PAINTSTRUCT ps;
  340. BeginPaint(hwndDlg,&ps);
  341. HRGN hrgn = (ps.fErase) ? CreateRectRgnIndirect(&ps.rcPaint) : NULL;
  342. HPEN pen = CreatePen(PS_SOLID, 0, wadlg_colors[WADLG_HILITE]);
  343. HGDIOBJ o = SelectObject(ps.hdc, pen);
  344. while (tabsize--)
  345. {
  346. RECT r;
  347. int a = *tab++;
  348. GetWindowRect(GetDlgItem(hwndDlg, a & 0xffff),&r);
  349. MapWindowPoints(HWND_DESKTOP, hwndDlg, (LPPOINT)&r, 2);
  350. if (RectInRect(&ps.rcPaint,&r))
  351. {
  352. if ((a & 0xffff0000) == DCW_SUNKENBORDER)
  353. {
  354. MoveToEx(ps.hdc,r.left,r.bottom,NULL);
  355. LineTo(ps.hdc,r.right,r.bottom);
  356. LineTo(ps.hdc,r.right,r.top-1);
  357. if(hrgn)
  358. {
  359. WADlg_removeFromRgn(hrgn,r.left,r.bottom,r.right,r.bottom+1);
  360. WADlg_removeFromRgn(hrgn,r.right,r.top,r.right+1,r.bottom);
  361. }
  362. }
  363. else if ((a & 0xffff0000) == DCW_DIVIDER)
  364. {
  365. if (r.right - r.left < r.bottom - r.top) // vertical
  366. {
  367. int left=(r.left+r.right)/2;
  368. MoveToEx(ps.hdc,left,r.top,NULL);
  369. LineTo(ps.hdc,left,r.bottom+1);
  370. if(hrgn) WADlg_removeFromRgn(hrgn,left,r.top,left+1,r.bottom);
  371. }
  372. else // horiz
  373. {
  374. int top=(r.top+r.bottom)/2;
  375. MoveToEx(ps.hdc,r.left,top,NULL);
  376. LineTo(ps.hdc,r.right+1,top);
  377. if(hrgn) WADlg_removeFromRgn(hrgn,r.left,top,r.right,top+1);
  378. }
  379. }
  380. }
  381. }
  382. SelectObject(ps.hdc, o);
  383. DeleteObject(pen);
  384. if(hrgn)
  385. {
  386. //erase bkgnd while clipping out our own drawn stuff (for flickerless display)
  387. HBRUSH b = CreateSolidBrush(wadlg_colors[WADLG_WNDBG]);
  388. FillRgn(ps.hdc,hrgn,b);
  389. DeleteObject(b);
  390. DeleteObject(hrgn);
  391. }
  392. EndPaint(hwndDlg,&ps);
  393. }
  394. #endif
  395. #endif//_WA_DLG_H_