config2.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005-2013 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #include "api__vis_milk2.h"
  25. #include "pluginshell.h"
  26. #include "resource.h"
  27. #include "utility.h"
  28. #include <strsafe.h>
  29. int g_nFontSize[] = { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 30, 32,
  30. 36, 40, 44, 48, 52, 56, 60, 64, 72, 80, 88, 96, 104, 112, 120, 128 };
  31. int CALLBACK EnumFontsProc(
  32. CONST LOGFONT *lplf, // logical-font data
  33. CONST TEXTMETRIC *lptm, // physical-font data
  34. DWORD dwType, // font type
  35. LPARAM lpData // application-defined data
  36. )
  37. {
  38. SendMessage( GetDlgItem( (HWND)lpData, IDC_FONT1), CB_ADDSTRING, 0, (LPARAM)(lplf->lfFaceName));
  39. SendMessage( GetDlgItem( (HWND)lpData, IDC_FONT2), CB_ADDSTRING, 0, (LPARAM)(lplf->lfFaceName));
  40. SendMessage( GetDlgItem( (HWND)lpData, IDC_FONT3), CB_ADDSTRING, 0, (LPARAM)(lplf->lfFaceName));
  41. SendMessage( GetDlgItem( (HWND)lpData, IDC_FONT4), CB_ADDSTRING, 0, (LPARAM)(lplf->lfFaceName));
  42. SendMessage( GetDlgItem( (HWND)lpData, IDC_FONT5), CB_ADDSTRING, 0, (LPARAM)(lplf->lfFaceName));
  43. SendMessage( GetDlgItem( (HWND)lpData, IDC_FONT6), CB_ADDSTRING, 0, (LPARAM)(lplf->lfFaceName));
  44. SendMessage( GetDlgItem( (HWND)lpData, IDC_FONT7), CB_ADDSTRING, 0, (LPARAM)(lplf->lfFaceName));
  45. SendMessage( GetDlgItem( (HWND)lpData, IDC_FONT8), CB_ADDSTRING, 0, (LPARAM)(lplf->lfFaceName));
  46. SendMessage( GetDlgItem( (HWND)lpData, IDC_FONT9), CB_ADDSTRING, 0, (LPARAM)(lplf->lfFaceName));
  47. return 1;
  48. }
  49. void SaveFont2(td_fontinfo *fi, DWORD ctrl1, DWORD ctrl2, DWORD bold_id, DWORD ital_id, DWORD aa_id, HWND hwnd)
  50. {
  51. HWND fontbox = GetDlgItem( hwnd, ctrl1 );
  52. HWND sizebox = GetDlgItem( hwnd, ctrl2 );
  53. // font face
  54. int t = SendMessage( fontbox, CB_GETCURSEL, 0, 0);
  55. SendMessageW( fontbox, CB_GETLBTEXT, t, (LPARAM)fi->szFace);
  56. // font size
  57. t = SendMessage( sizebox, CB_GETCURSEL, 0, 0);
  58. if (t != CB_ERR)
  59. {
  60. int nMax = sizeof(g_nFontSize)/sizeof(int);
  61. fi->nSize =g_nFontSize[nMax-1 - t];
  62. }
  63. // font options
  64. fi->bBold = DlgItemIsChecked(hwnd, bold_id);
  65. fi->bItalic = DlgItemIsChecked(hwnd, ital_id);
  66. fi->bAntiAliased = DlgItemIsChecked(hwnd, aa_id);
  67. }
  68. void InitFont2(td_fontinfo *fi, DWORD ctrl1, DWORD ctrl2, DWORD bold_id, DWORD ital_id, DWORD aa_id, HWND hwnd, DWORD ctrl4, wchar_t* szFontName)
  69. {
  70. HWND namebox = ctrl4 ? GetDlgItem( hwnd, ctrl4 ) : 0;
  71. HWND fontbox = GetDlgItem( hwnd, ctrl1 );
  72. HWND sizebox = GetDlgItem( hwnd, ctrl2 );
  73. ShowWindow(fontbox, SW_NORMAL);
  74. ShowWindow(sizebox, SW_NORMAL);
  75. ShowWindow(GetDlgItem(hwnd,bold_id), SW_NORMAL);
  76. ShowWindow(GetDlgItem(hwnd,ital_id), SW_NORMAL);
  77. ShowWindow(GetDlgItem(hwnd,aa_id), SW_NORMAL);
  78. if (namebox && szFontName && szFontName[0])
  79. {
  80. ShowWindow(namebox, SW_NORMAL);
  81. wchar_t buf[256];
  82. StringCbPrintfW(buf, sizeof(buf), L"%s:", szFontName);
  83. SetWindowTextW(GetDlgItem(hwnd,ctrl4), buf);
  84. }
  85. // set selection
  86. int nPos = SendMessageW( fontbox, CB_FINDSTRINGEXACT, -1, (LPARAM)fi->szFace);
  87. if (nPos == CB_ERR)
  88. nPos = 0;
  89. SendMessage( fontbox, CB_SETCURSEL, nPos, 0);
  90. //---------font size box-------------------
  91. int nSel = 0;
  92. int nMax = sizeof(g_nFontSize)/sizeof(int);
  93. for (int i=0; i<nMax; i++)
  94. {
  95. wchar_t buf[256];
  96. int s = g_nFontSize[nMax-1 - i];
  97. StringCbPrintfW(buf, sizeof(buf), L" %2d ", s);
  98. SendMessageW(sizebox, CB_ADDSTRING, i, (LPARAM)buf);
  99. if (s == fi->nSize)
  100. nSel = i;
  101. }
  102. SendMessage(sizebox, CB_SETCURSEL, nSel, 0);
  103. //---------font options box-------------------
  104. CheckDlgButton(hwnd, bold_id, fi->bBold);
  105. CheckDlgButton(hwnd, ital_id, fi->bItalic);
  106. CheckDlgButton(hwnd, aa_id, fi->bAntiAliased);
  107. }
  108. void SCOOT_CONTROL(HWND hwnd, int ctrl_id, int dx, int dy)
  109. {
  110. RECT r;
  111. GetWindowRect(GetDlgItem(hwnd,ctrl_id), &r);
  112. ScreenToClient(hwnd, (LPPOINT)&r);
  113. SetWindowPos (GetDlgItem(hwnd,ctrl_id), NULL, r.left + dx, r.top + dy, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
  114. }
  115. BOOL CALLBACK CPluginShell::FontDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  116. {
  117. if (msg==WM_INITDIALOG && lParam > 0 && GetWindowLongPtr(hwnd,GWLP_USERDATA)==0)
  118. SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
  119. CPluginShell* p = (CPluginShell*)GetWindowLongPtr(hwnd,GWLP_USERDATA);
  120. if (p)
  121. return p->PluginShellFontDialogProc(hwnd, msg, wParam, lParam);
  122. else
  123. return FALSE;
  124. }
  125. BOOL CPluginShell::PluginShellFontDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  126. {
  127. #ifdef _DEBUG
  128. OutputDebugMessage("FontDlgProc: ", hwnd, msg, wParam, lParam);
  129. #endif
  130. switch (msg)
  131. {
  132. case WM_DESTROY:
  133. return 0;
  134. case WM_INITDIALOG:
  135. {
  136. // Initialize all font dialog global variables here:
  137. // ...
  138. HDC hdc = GetDC(hwnd);
  139. if (hdc)
  140. {
  141. EnumFonts(hdc, NULL, &EnumFontsProc, (LPARAM)hwnd);
  142. ReleaseDC(hwnd, hdc);
  143. }
  144. #define InitFont(n, m) InitFont2(&m_fontinfo[n-1], IDC_FONT##n, IDC_FONTSIZE##n, IDC_FONTBOLD##n, IDC_FONTITAL##n, IDC_FONTAA##n, hwnd, IDC_FONT_NAME_##n, m)
  145. InitFont(1, 0);
  146. InitFont(2, 0);
  147. InitFont(3, 0);
  148. InitFont(4, 0);
  149. #if (NUM_EXTRA_FONTS >= 1)
  150. InitFont(5, WASABI_API_LNGSTRINGW(IDS_EXTRA_FONT_1_NAME));
  151. #endif
  152. #if (NUM_EXTRA_FONTS >= 2)
  153. InitFont(6, WASABI_API_LNGSTRINGW(IDS_EXTRA_FONT_2_NAME));
  154. #endif
  155. #if (NUM_EXTRA_FONTS >= 3)
  156. InitFont(7, EXTRA_FONT_3_NAME);
  157. #endif
  158. #if (NUM_EXTRA_FONTS >= 4)
  159. InitFont(5, EXTRA_FONT_4_NAME);
  160. #endif
  161. #if (NUM_EXTRA_FONTS >= 5)
  162. InitFont(9, EXTRA_FONT_5_NAME);
  163. #endif
  164. // Finally, if not all extra fonts are in use, shrink the window size, and
  165. // move up any controls that were at the bottom:
  166. RECT r;
  167. GetWindowRect(hwnd, &r);
  168. int scoot_factor = 128*(MAX_EXTRA_FONTS-NUM_EXTRA_FONTS)/MAX_EXTRA_FONTS;
  169. if (scoot_factor>0)
  170. {
  171. SetWindowPos(hwnd, NULL, 0, 0, r.right-r.left, r.bottom-r.top - scoot_factor, SWP_NOMOVE|SWP_NOZORDER);
  172. SCOOT_CONTROL(hwnd, IDC_FONT_TEXT, 0, -scoot_factor);
  173. SCOOT_CONTROL(hwnd, IDOK, 0, -scoot_factor);
  174. SCOOT_CONTROL(hwnd, IDCANCEL, 0, -scoot_factor);
  175. }
  176. }
  177. break;
  178. case WM_COMMAND:
  179. {
  180. int id = LOWORD(wParam);
  181. switch(id)
  182. {
  183. case IDOK:
  184. #define SaveFont(n) SaveFont2(&m_fontinfo[n-1], IDC_FONT##n, IDC_FONTSIZE##n, IDC_FONTBOLD##n, IDC_FONTITAL##n, IDC_FONTAA##n, hwnd)
  185. SaveFont(1);
  186. SaveFont(2);
  187. SaveFont(3);
  188. SaveFont(4);
  189. #if (NUM_EXTRA_FONTS >= 1)
  190. SaveFont(5);
  191. #endif
  192. #if (NUM_EXTRA_FONTS >= 2)
  193. SaveFont(6);
  194. #endif
  195. #if (NUM_EXTRA_FONTS >= 3)
  196. SaveFont(7);
  197. #endif
  198. #if (NUM_EXTRA_FONTS >= 4)
  199. SaveFont(5);
  200. #endif
  201. #if (NUM_EXTRA_FONTS >= 5)
  202. SaveFont(9);
  203. #endif
  204. EndDialog(hwnd,id);
  205. break;
  206. case IDCANCEL:
  207. EndDialog(hwnd,id);
  208. break;
  209. }
  210. }
  211. break;
  212. }
  213. return 0;
  214. }
  215. void EnableStuff(HWND hwnd, int bEnable)
  216. {
  217. EnableWindow(GetDlgItem(hwnd, IDC_CB_BOX), bEnable);
  218. EnableWindow(GetDlgItem(hwnd, IDC_CB_MANUAL_SCOOT), bEnable);
  219. EnableWindow(GetDlgItem(hwnd, IDC_DM_ALPHA_FIX_CAPTION), bEnable);
  220. EnableWindow(GetDlgItem(hwnd, IDC_DM_ALPHA_FIX), bEnable);
  221. }
  222. BOOL CALLBACK CPluginShell::DesktopOptionsDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  223. {
  224. if (msg==WM_INITDIALOG && lParam > 0 && GetWindowLongPtr(hwnd,GWLP_USERDATA)==0)
  225. SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
  226. CPluginShell* p = (CPluginShell*)GetWindowLongPtr(hwnd,GWLP_USERDATA);
  227. if (p)
  228. return p->PluginShellDesktopOptionsDialogProc(hwnd, msg, wParam, lParam);
  229. else
  230. return FALSE;
  231. }
  232. BOOL CPluginShell::PluginShellDesktopOptionsDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  233. {
  234. #ifdef _DEBUG
  235. OutputDebugMessage("DmDlgProc: ", hwnd, msg, wParam, lParam);
  236. #endif
  237. switch (msg)
  238. {
  239. case WM_DESTROY:
  240. return 0;
  241. case WM_INITDIALOG:
  242. {
  243. CheckDlgButton(hwnd, IDC_CB_SHOW_ICONS, m_desktop_show_icons );
  244. CheckDlgButton(hwnd, IDC_CB_BOX, m_desktop_textlabel_boxes );
  245. CheckDlgButton(hwnd, IDC_CB_MANUAL_SCOOT, m_desktop_manual_icon_scoot);
  246. HWND ctrl = GetDlgItem(hwnd, IDC_DM_ALPHA_FIX);
  247. SendMessageW( ctrl, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_5_6_5_TEXTURE));
  248. SendMessageW( ctrl, CB_ADDSTRING, 1, (LPARAM)WASABI_API_LNGSTRINGW(IDS_5_5_5_TEXTURE));
  249. SendMessageW( ctrl, CB_ADDSTRING, 2, (LPARAM)WASABI_API_LNGSTRINGW(IDS_8_8_8_TEXTURE));
  250. SendMessageW( ctrl, CB_SETCURSEL, m_desktop_555_fix, 0 );
  251. EnableStuff(hwnd, m_desktop_show_icons);
  252. }
  253. break;
  254. case WM_COMMAND:
  255. {
  256. int id = LOWORD(wParam);
  257. switch(id)
  258. {
  259. case IDC_CB_SHOW_ICONS:
  260. m_desktop_show_icons = DlgItemIsChecked(hwnd, IDC_CB_SHOW_ICONS);
  261. EnableStuff(hwnd, m_desktop_show_icons);
  262. break;
  263. case IDOK:
  264. m_desktop_show_icons = DlgItemIsChecked(hwnd, IDC_CB_SHOW_ICONS);
  265. m_desktop_textlabel_boxes = DlgItemIsChecked(hwnd, IDC_CB_BOX);
  266. m_desktop_manual_icon_scoot = DlgItemIsChecked(hwnd, IDC_CB_MANUAL_SCOOT);
  267. m_desktop_555_fix = SendMessage( GetDlgItem(hwnd, IDC_DM_ALPHA_FIX), CB_GETCURSEL, 0, 0 );
  268. EndDialog(hwnd,id);
  269. break;
  270. case IDCANCEL:
  271. EndDialog(hwnd,id);
  272. break;
  273. }
  274. }
  275. break;
  276. case WM_HELP:
  277. if (lParam)
  278. {
  279. HELPINFO *ph = (HELPINFO*)lParam;
  280. wchar_t title[1024];
  281. wchar_t buf[2048];
  282. wchar_t ctrl_name[1024];
  283. GetWindowTextW(GetDlgItem(hwnd, ph->iCtrlId), ctrl_name, sizeof(ctrl_name)/sizeof(*ctrl_name));
  284. RemoveSingleAmpersands(ctrl_name);
  285. buf[0] = 0;
  286. switch(ph->iCtrlId)
  287. {
  288. case IDC_DM_ALPHA_FIX:
  289. case IDC_DM_ALPHA_FIX_CAPTION:
  290. WASABI_API_LNGSTRINGW_BUF(IDS_NO_ALPHA_FALLBACK, title, 1024);
  291. WASABI_API_LNGSTRINGW_BUF(IDS_NO_ALPHA_FALLBACK_HELP, buf, 2048);
  292. break;
  293. case IDC_CB_SHOW_ICONS:
  294. StringCbPrintfW(title, sizeof(title), WASABI_API_LNGSTRINGW(IDS_HELP_ON_X_CHECKBOX), ctrl_name);
  295. WASABI_API_LNGSTRINGW_BUF(IDS_CB_SHOW_ICONS_HELP, buf, 2048);
  296. break;
  297. case IDC_CB_BOX:
  298. WASABI_API_LNGSTRINGW_BUF(IDS_CB_BOX, title, 1024);
  299. WASABI_API_LNGSTRINGW_BUF(IDS_CB_BOX_HELP, buf, 2048);
  300. break;
  301. case IDC_CB_MANUAL_SCOOT:
  302. WASABI_API_LNGSTRINGW_BUF(IDS_CB_MANUAL_SCOOT, title, 1024);
  303. WASABI_API_LNGSTRINGW_BUF(IDS_CB_MANUAL_SCOOT_HELP, buf, 2048);
  304. break;
  305. }
  306. if (buf[0])
  307. MessageBoxW(hwnd, buf, title, MB_OK|MB_SETFOREGROUND|MB_TOPMOST|MB_TASKMODAL);
  308. }
  309. break;
  310. }
  311. return 0;
  312. }
  313. BOOL CALLBACK CPluginShell::DualheadDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  314. {
  315. if (msg==WM_INITDIALOG && lParam > 0 && GetWindowLongPtr(hwnd,GWLP_USERDATA)==0)
  316. SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
  317. CPluginShell* p = (CPluginShell*)GetWindowLongPtr(hwnd,GWLP_USERDATA);
  318. if (p)
  319. return p->PluginShellDualheadDialogProc(hwnd, msg, wParam, lParam);
  320. else
  321. return FALSE;
  322. }
  323. BOOL CPluginShell::PluginShellDualheadDialogProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  324. {
  325. #ifdef _DEBUG
  326. OutputDebugMessage("DHDlgProc: ", hwnd, msg, wParam, lParam);
  327. #endif
  328. switch (msg)
  329. {
  330. case WM_DESTROY:
  331. return 0;
  332. case WM_INITDIALOG:
  333. {
  334. HWND ctrl = GetDlgItem(hwnd, IDC_H_PICK);
  335. SendMessageW( ctrl, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_SPAN_BOTH_SCREENS));
  336. SendMessageW( ctrl, CB_ADDSTRING, 1, (LPARAM)WASABI_API_LNGSTRINGW(IDS_USE_LEFT_SCREEN_ONLY));
  337. SendMessageW( ctrl, CB_ADDSTRING, 2, (LPARAM)WASABI_API_LNGSTRINGW(IDS_USE_RIGHT_SCREEN_ONLY));
  338. SendMessage( ctrl, CB_SETCURSEL, m_dualhead_horz, 0 );
  339. ctrl = GetDlgItem(hwnd, IDC_V_PICK);
  340. SendMessageW( ctrl, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_SPAN_BOTH_SCREENS));
  341. SendMessageW( ctrl, CB_ADDSTRING, 1, (LPARAM)WASABI_API_LNGSTRINGW(IDS_USE_TOP_SCREEN_ONLY));
  342. SendMessageW( ctrl, CB_ADDSTRING, 2, (LPARAM)WASABI_API_LNGSTRINGW(IDS_USE_BOTTOM_SCREEN_ONLY));
  343. SendMessage( ctrl, CB_SETCURSEL, m_dualhead_vert, 0 );
  344. }
  345. break;
  346. case WM_COMMAND:
  347. {
  348. int id = LOWORD(wParam);
  349. switch(id)
  350. {
  351. case IDOK:
  352. m_dualhead_horz = SendMessage( GetDlgItem(hwnd, IDC_H_PICK), CB_GETCURSEL, 0, 0 );
  353. m_dualhead_vert = SendMessage( GetDlgItem(hwnd, IDC_V_PICK), CB_GETCURSEL, 0, 0 );
  354. EndDialog(hwnd,id);
  355. break;
  356. case IDCANCEL:
  357. EndDialog(hwnd,id);
  358. break;
  359. }
  360. }
  361. break;
  362. }
  363. return 0;
  364. }