setup.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. #define APSTUDIO_READONLY_SYMBOLS
  2. #include "main.h"
  3. #include "./setup.h"
  4. #include "./setup_resource.h"
  5. #include "./loadimage.h"
  6. #include "./langutil.h"
  7. #include "../nu/AutoWide.h"
  8. #include "api.h"
  9. #define HEADER_FONT_NAME "Arial"//"Lucida Sans Unicode"//"Verdana"//"Trebuchet MS"//"Arial Unicode MS"
  10. #define HEADER_FONT_SIZE 13 //11
  11. #define HEADER_FONT_ITALIC FALSE
  12. #define HEADER_FONT_WEIGHT FW_MEDIUM
  13. #define HEADER_TEXT_COLOR RGB(255,255,255)//RGB(16, 72, 148)//RGB(7, 30, 140)
  14. #define HEADER_BORDER_COLOR RGB(236, 233, 216)
  15. #define HEADER_PAGENUM_FONT_NAME "Lucida Sans Unicode"//"Lucida Sans Unicode"//"Verdana"//"Trebuchet MS"//"Arial Unicode MS"
  16. #define HEADER_PAGENUM_FONT_SIZE 10
  17. #define HEADER_PAGENUM_FONT_ITALIC FALSE
  18. #define HEADER_PAGENUM_FONT_WEIGHT FW_SEMIBOLD//FW_MEDIUM
  19. #define HEADER_PAGENUM_TEXT_COLOR RGB(210,120,42)
  20. #define NAVIGATION_FONT_NAME "Arial"
  21. #define NAVIGATION_FONT_SIZE 9
  22. #define NAVIGATION_FONT_ITALIC FALSE
  23. #define NAVIGATION_FONT_WEIGHT FW_MEDIUM
  24. #define NAVIGATION_SEL_FONT_NAME "Arial"
  25. #define NAVIGATION_SEL_FONT_SIZE 10
  26. #define NAVIGATION_SEL_FONT_ITALIC FALSE
  27. #define NAVIGATION_SEL_FONT_WEIGHT FW_MEDIUM//FW_SEMIBOLD
  28. #define NAVIGATION_SEL_TEXT_COLOR RGB(252, 252, 255)
  29. #define NAVIGATION_TEXT_COLOR RGB(222, 225, 234)
  30. #define NAVIGATION_BACK_COLOR RGB(137,145,156)//RGB(150,156,163)
  31. #define NAVIGATION_PADDING_LEFT 0
  32. #define NAVIGATION_PADDING_RIGHT 0
  33. #define PAGE_BACK_COLOR RGB(236, 234, 232)
  34. typedef struct _UI
  35. {
  36. ULONG ref;
  37. HBRUSH hbPage;
  38. HBRUSH hbHeader;
  39. HBRUSH hbNavItemSel;
  40. HBRUSH hbNavBack;
  41. HFONT hfHeader;
  42. HFONT hfNavItem;
  43. HFONT hfNavItemSel;
  44. HFONT hfHeaderPageNum;
  45. INT nHdrTxtHeight;
  46. INT nHdrPageTxtHeight;
  47. INT nNavTxtHeight;
  48. INT nNavTxtSelHeight;
  49. INT nHdrHeight;
  50. INT nNavItemHeight;
  51. COLORREF rgbPageBk;
  52. } UI;
  53. typedef struct _SPTHEME
  54. {
  55. WNDPROC fnOldProc;
  56. UI *pui;
  57. BOOL bUnicode;
  58. } SPTHEME;
  59. static WASetup *g_pAttachInstance = NULL;
  60. static BOOL bUseMarquee = -1;
  61. static INT_PTR WINAPI AboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  62. static INT_PTR WINAPI JobStatusDialog(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  63. static INT_PTR WINAPI ErrorPageDialog(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  64. static LRESULT WINAPI PageWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  65. static INT ConvertFontHeight(HWND hwnd, INT ptHeight);
  66. static DWORD GetHighestFontQuality(void);
  67. static BOOL InitializeUI(UI *pui, HWND hwndCtrl);
  68. static BOOL ReleaseUI(UI *pui);
  69. static const wchar_t *GetUnknownStr(void);
  70. static LRESULT WINAPI FrameWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  71. static BOOL JobStatus_Advance(HWND hwndStatus);
  72. WASetup::WASetup(void)
  73. : ref((size_t)1), hwnd(NULL), hwndActive(NULL), nPageActive((size_t)-1), pui(NULL), hWinamp(NULL)
  74. {
  75. }
  76. WASetup::~WASetup(void)
  77. {
  78. if (hwnd && IsWindow(hwnd)) DestroyWindow(hwnd);
  79. size_t index;
  80. index = pageList.size();
  81. while(index--)
  82. {
  83. pageList[index]->Release();
  84. }
  85. index = jobList.size();
  86. while(index--)
  87. {
  88. jobList[index]->Release();
  89. }
  90. }
  91. svc_setup *WASetup::CreateInstance()
  92. {
  93. WASetup *instance = new WASetup();
  94. return (svc_setup*)instance;
  95. }
  96. int WASetup::AddRef(void)
  97. {
  98. return ++ref;
  99. }
  100. int WASetup::Release(void)
  101. {
  102. if (1 == ref)
  103. {
  104. delete(this);
  105. return 0;
  106. }
  107. return --ref;
  108. }
  109. HRESULT WASetup::InsertPage(ifc_setuppage *pPage, int* pIndex)
  110. {
  111. size_t index;
  112. if (!pIndex || !pPage) return E_INVALIDARG;
  113. index = *pIndex;
  114. if (index >= pageList.size())
  115. {
  116. index = pageList.size();
  117. pageList.push_back(pPage);
  118. }
  119. else
  120. {
  121. //pageList.insertBefore(*pIndex, pPage);
  122. pageList.insert(pageList.begin() + index, pPage);
  123. }
  124. *pIndex = (int)index;
  125. pPage->AddRef();
  126. return S_OK;
  127. }
  128. HRESULT WASetup::RemovePage(size_t index)
  129. {
  130. if (index >= pageList.size())
  131. return HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
  132. pageList[index]->Release();
  133. pageList.erase(pageList.begin() + index);
  134. return S_OK;
  135. }
  136. HRESULT WASetup::GetPageCount(int *pCount)
  137. {
  138. if (!pCount) return E_INVALIDARG;
  139. *pCount = (int)pageList.size();
  140. return S_OK;
  141. }
  142. HRESULT WASetup::GetPage(size_t index, ifc_setuppage **pPage)
  143. {
  144. if (index >= pageList.size()) return HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
  145. *pPage = pageList[index];
  146. return S_OK;
  147. }
  148. HRESULT WASetup::AddJob(ifc_setupjob *pJob)
  149. {
  150. for (size_t i = 0; i < jobList.size(); i++)
  151. {
  152. if (jobList[i] == pJob) return S_OK;
  153. }
  154. jobList.push_back(pJob);
  155. pJob->AddRef();
  156. return S_OK;
  157. }
  158. HRESULT WASetup::RemoveJob(ifc_setupjob *pJob)
  159. {
  160. for (size_t i = 0; i < jobList.size(); i++)
  161. {
  162. if (jobList[i] == pJob)
  163. {
  164. jobList[i]->Release();
  165. jobList.erase(jobList.begin() + i);
  166. return S_OK;
  167. }
  168. }
  169. return E_INVALIDARG;
  170. }
  171. HRESULT WASetup::GetActiveIndex(int* pIndex)
  172. {
  173. if (!pIndex) return E_INVALIDARG;
  174. *pIndex = (int)nPageActive;
  175. return S_OK;
  176. }
  177. HRESULT WASetup::CreateStatusWnd(HWND *phwndStatus)
  178. {
  179. HWND hwndStatus;
  180. if (!phwndStatus) return S_FALSE;
  181. *phwndStatus = NULL;
  182. if (-1 == bUseMarquee)
  183. {
  184. OSVERSIONINFO vi;
  185. vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  186. bUseMarquee = (GetVersionEx(&vi) && (vi.dwMajorVersion > 5 || (vi.dwMajorVersion == 5 && vi.dwMinorVersion > 0)));
  187. }
  188. hwndStatus = WACreateDialog(MAKEINTRESOURCEW(IDD_SETUPSTATUS), NULL, JobStatusDialog);
  189. if (!hwndStatus) return S_FALSE;
  190. if (rcUI.right != rcUI.left)
  191. {
  192. RECT rw;
  193. GetWindowRect(hwndStatus, &rw);
  194. SetWindowPos(hwndStatus, NULL, rcUI.left + ((rcUI.right - rcUI.left) - (rw.right - rw.left))/2,
  195. rcUI.top + ((rcUI.bottom - rcUI.top) - (rw.bottom - rw.top))/2, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
  196. }
  197. HWND hwndCtrl = GetDlgItem(hwndStatus, IDC_PROGRESS);
  198. if (hwndCtrl)
  199. {
  200. if (bUseMarquee)
  201. {
  202. SetWindowLongPtrW(hwndCtrl, GWL_STYLE, GetWindowLongPtrW(hwndCtrl, GWL_STYLE) | 0x08/*PBS_MARQUEE*/);
  203. SendMessageW(hwndCtrl, (WM_USER + 10)/*PBM_SETMARQUEE*/, TRUE, (LPARAM)200);
  204. }
  205. else
  206. {
  207. SendMessageW(hwndCtrl, PBM_SETRANGE, 0, MAKELPARAM(0, 1 + (INT)(pageList.size() + jobList.size())));
  208. SendMessageW(hwndCtrl, PBM_SETPOS, 0, 0L);
  209. SendMessageW(hwndCtrl, PBM_SETSTEP, 1, 0L);
  210. }
  211. }
  212. *phwndStatus = hwndStatus;
  213. return S_OK;
  214. }
  215. static BOOL WaSetup_MessageLoop(HWND hMainWnd, HACCEL hAccel)
  216. {
  217. MSG msg;
  218. for (;;)
  219. {
  220. DWORD status = MsgWaitForMultipleObjectsEx(0, NULL, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE | MWMO_INPUTAVAILABLE);
  221. if (WAIT_OBJECT_0 == status)
  222. {
  223. while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
  224. {
  225. //if (!CallMsgFilter(&msg, MSGF_DIALOGBOX))
  226. {
  227. if (msg.message == WM_QUIT)
  228. return (BOOL)msg.wParam;
  229. if (!TranslateAcceleratorW(hMainWnd, hAccel, &msg) &&
  230. !IsDialogMessageW(hMainWnd, &msg))
  231. {
  232. TranslateMessage(&msg);
  233. DispatchMessageW(&msg);
  234. }
  235. }
  236. }
  237. }
  238. }
  239. }
  240. HRESULT WASetup::Start(HWND hwndWinamp)
  241. {
  242. INT_PTR r(IDOK);
  243. SetRectEmpty(&rcUI);
  244. hWinamp = hwndWinamp;
  245. if (pageList.size())
  246. {
  247. HACCEL hAccel;
  248. static UI ui = {0, };
  249. for (size_t i = 0; i < pageList.size(); i++) pageList[i]->Revert();
  250. g_pAttachInstance = this;
  251. InitializeUI(&ui, hwnd);
  252. pui = &ui;
  253. hwnd = WACreateDialog(MAKEINTRESOURCEW(IDD_SETUP), NULL, ::DialogProc);
  254. if (!hwnd) return E_UNEXPECTED;
  255. HINSTANCE hInst = (language_pack_instance) ? language_pack_instance : hMainInstance;
  256. hAccel = LoadAcceleratorsW(hInst, MAKEINTRESOURCEW(IDR_ACCEL_SETUP));
  257. r = WaSetup_MessageLoop(hwnd, hAccel);
  258. g_pAttachInstance = NULL;
  259. ReleaseUI(&ui);
  260. }
  261. return (IDOK == r) ? S_OK : S_FALSE;
  262. }
  263. HRESULT WASetup::Save(HWND hwndStatus)
  264. {
  265. HRESULT hr(S_OK);
  266. HWND hwndText = GetDlgItem(hwndStatus, IDC_LBL_STATUS);
  267. for (size_t i = 0; i < pageList.size(); i++)
  268. {
  269. if (hwndText) SetWindowTextW(hwndText, getStringW(IDS_STATUS_SAVING, NULL, 0));
  270. if (S_OK != pageList[i]->Save(hwndText)) hr = S_FALSE;
  271. JobStatus_Advance(hwndStatus);
  272. }
  273. WritePrivateProfileStringW(L"WinampReg", L"WAVer", AutoWide(APP_VERSION), INI_FILE);
  274. return hr;
  275. }
  276. HRESULT WASetup::ExecJobs(HWND hwndStatus)
  277. {
  278. HRESULT hr(S_OK);
  279. HWND hwndText = GetDlgItem(hwndStatus, IDC_LBL_STATUS);
  280. HWND hwndBtn = GetDlgItem(hwndStatus, IDC_BTN_SKIP);
  281. for (size_t i = 0; i < jobList.size(); i++)
  282. {
  283. if (hwndText) SetWindowTextW(hwndText, getStringW(IDS_STATUS_JOBS, NULL, 0));
  284. if (hwndBtn && S_OK == jobList[i]->IsCancelSupported() &&
  285. SetPropW(hwndStatus, L"JOB", (HANDLE)jobList[i]))
  286. {
  287. EnableWindow(hwndBtn, TRUE);
  288. }
  289. if (S_OK != jobList[i]->Execute(hwndText)) hr = S_FALSE;
  290. if (hwndBtn) EnableWindow(hwndBtn, FALSE);
  291. JobStatus_Advance(hwndStatus);
  292. }
  293. return hr;
  294. }
  295. HRESULT WASetup::GetWinampWnd(HWND *phwndWinamp)
  296. {
  297. if (NULL == phwndWinamp)
  298. return E_INVALIDARG;
  299. *phwndWinamp = hWinamp;
  300. return (NULL == hWinamp) ? E_UNEXPECTED : S_OK;
  301. }
  302. static INT_PTR CALLBACK tmpProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  303. {
  304. return 0;
  305. }
  306. INT_PTR WASetup::OnInitDialog(HWND hwndFocused, LPARAM lParam)
  307. {
  308. HWND hwndLB, hwndFrame, hwndHeader;
  309. RECT rw, rc;
  310. HICON hIcon = LoadIconW(hMainInstance, MAKEINTRESOURCE(ICON_XP));
  311. // make other people's dialogs show the winamp icon
  312. HWND h = CreateDialogW(hMainInstance, MAKEINTRESOURCE(IDD_OPENLOC), NULL, tmpProc);
  313. SetClassLongPtrW(h, GCLP_HICON, (LONG_PTR)hIcon);
  314. DestroyWindow(h);
  315. SendMessageW(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDC_BTN_NEXT), TRUE);
  316. wchar_t buf[256] = {0};
  317. StringCchPrintfW(buf,256, getStringW(IDS_SETUP_WND_TITLE,NULL,0), AutoWideDup(app_version_string));
  318. SetWindowTextW(hwnd, buf);
  319. // adjust dialog
  320. rw.left = GetPrivateProfileIntW(L"SETUP", L"left", 0, INI_FILE);
  321. rw.top = GetPrivateProfileIntW(L"SETUP", L"top", 0, INI_FILE);
  322. rw.right = GetPrivateProfileIntW(L"SETUP", L"right", 0, INI_FILE);
  323. rw.bottom = GetPrivateProfileIntW(L"SETUP", L"bottom", 0, INI_FILE);
  324. if (rw.left != rw.right && rw.top != rw.bottom)
  325. {
  326. INT x, y;
  327. GetWindowRect(hwnd, &rc);
  328. x = (rw.right) ? (rw.left + ((rw.right - rw.left) - (rc.right - rc.left))/2) : rw.left;
  329. y = (rw.bottom) ? (rw.top + ((rw.bottom - rw.top) - (rc.bottom - rc.top))/2) : rw.top;
  330. SetWindowPos(hwnd, NULL, x, y, rc.right - rc.left, rc.bottom - rc.top, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
  331. }
  332. hwndFrame = GetDlgItem(hwnd, IDC_FRAME);
  333. // TODO if this is needed again then remove
  334. // deletes the 'Tools' menu as it's not used
  335. DeleteMenu(GetMenu(hwnd), 2, MF_BYPOSITION);
  336. DrawMenuBar(hwnd);
  337. WNDPROC fnOldProc = (WNDPROC)(LONG_PTR)SetWindowLongPtrW(hwndFrame, GWLP_WNDPROC, (LONG_PTR)FrameWndProc);
  338. if (fnOldProc) SetPropW(hwndFrame, L"SKINFRAME", fnOldProc);
  339. SetWindowLongPtrW(hwndFrame, GWL_STYLE, GetWindowLongPtrW(hwndFrame, GWL_STYLE) | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  340. if (!IsWinXPTheme()) SetWindowLongPtrW(hwndFrame, GWL_EXSTYLE, (GetWindowLongPtrW(hwndFrame, GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE) | WS_EX_STATICEDGE);
  341. SetWindowPos(hwndFrame, HWND_BOTTOM, 0,0,0,0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
  342. GetClientRect(hwndFrame, &rc);
  343. MapWindowPoints(hwndFrame, hwnd, (POINT*)&rc, 2);
  344. hwndLB = GetDlgItem(hwnd, IDC_LB_NAVIGATION);
  345. if (hwndLB)
  346. {
  347. GetWindowRect(hwndLB, &rw);
  348. SetWindowPos(hwndLB, GetDlgItem(hwnd, IDC_BTN_BACK), rc.left, rc.top, rw.right - rw.left, rc.bottom - rc.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  349. SendMessageW(hwndLB, WM_SETFONT, (WPARAM)pui->hfNavItem, FALSE);
  350. }
  351. hwndHeader = GetDlgItem(hwnd, IDC_HEADER);
  352. if (hwndHeader)
  353. {
  354. SendMessageW(hwndHeader, WM_SETFONT, (WPARAM)pui->hfHeader, FALSE);
  355. GetWindowRect(hwndLB, &rw);
  356. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rw, 2);
  357. SetWindowPos(hwndHeader, NULL, rw.right, rc.top, rc.right - rw.right, pui->nHdrHeight, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  358. }
  359. if (hwndLB)
  360. {
  361. for (size_t i = 0; i < pageList.size(); i++) SendMessageW(hwndLB, LB_ADDSTRING, 0, (LPARAM)i);
  362. SendMessageW(hwndLB, LB_SETCURSEL, 0, 0L);
  363. PostMessageW(hwnd, WM_COMMAND, MAKEWPARAM(IDC_LB_NAVIGATION, LBN_SELCHANGE), (LPARAM)hwndLB);
  364. }
  365. ShowWindow(hwnd, SW_SHOWNORMAL);
  366. DWORD ourThreadID, foregroundThreadID;
  367. foregroundThreadID = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
  368. ourThreadID = GetCurrentThreadId();
  369. if (foregroundThreadID != ourThreadID) AttachThreadInput(foregroundThreadID, ourThreadID, TRUE);
  370. SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  371. SetForegroundWindow(hwnd);
  372. SetFocus(hwnd);
  373. if (foregroundThreadID != ourThreadID) AttachThreadInput(foregroundThreadID, ourThreadID, FALSE);
  374. return 0;
  375. }
  376. void WASetup::OnDestroy(void)
  377. {
  378. GetWindowRect(hwnd, &rcUI);
  379. }
  380. void WASetup::OnCancel(void)
  381. {
  382. BOOL bNeedSave = FALSE;
  383. WCHAR szTitle[128] = {0};
  384. for (size_t i = 0; i < pageList.size() && !bNeedSave; i++)
  385. {
  386. bNeedSave = (S_FALSE != pageList[i]->IsDirty());
  387. }
  388. GetWindowTextW(hwnd, szTitle, sizeof(szTitle)/sizeof(WCHAR));
  389. if (bNeedSave)
  390. {
  391. INT nr = MessageBoxW(hwnd, getStringW(IDS_SAVE_CHANGES_BEFORE_EXIT, NULL, 0), szTitle, MB_YESNOCANCEL | MB_ICONWARNING);
  392. switch(nr)
  393. {
  394. case IDYES: SendMessageW(hwnd, WM_COMMAND, MAKEWPARAM(IDM_FILE_SAVECHANGES, 0), 0L); break;
  395. case IDCANCEL: return;
  396. }
  397. }
  398. else if (IDNO == MessageBoxW(hwnd, getStringW(IDS_QUIT_OK, NULL, 0), szTitle, MB_YESNO | MB_ICONWARNING)) return;
  399. DestroyWindow(hwnd);
  400. PostQuitMessage(IDCANCEL);
  401. }
  402. void WASetup::OnNext_Clicked(HWND hwndCtrl)
  403. {
  404. HWND hwndLB = GetDlgItem(hwnd, IDC_LB_NAVIGATION);
  405. INT index = (INT)SendMessageW(hwndLB, LB_GETCURSEL, 0, 0L) + 1;
  406. if (index > -1) SendMessageW(hwndLB, LB_SETCURSEL, (WPARAM)index, 0L);
  407. PostMessageW(hwnd, WM_COMMAND, MAKEWPARAM(IDC_LB_NAVIGATION, LBN_SELCHANGE), (LPARAM)hwndLB);
  408. }
  409. void WASetup::OnBack_Clicked(HWND hwndCtrl)
  410. {
  411. HWND hwndLB = GetDlgItem(hwnd, IDC_LB_NAVIGATION);
  412. INT index = (INT)SendMessageW(hwndLB, LB_GETCURSEL, 0, 0L) -1;
  413. if (index > -1) SendMessageW(hwndLB, LB_SETCURSEL, (WPARAM)index, 0L);
  414. PostMessageW(hwnd, WM_COMMAND, MAKEWPARAM(IDC_LB_NAVIGATION, LBN_SELCHANGE), (LPARAM)hwndLB);
  415. }
  416. void WASetup::OnNavigation_SelChange(HWND hwndCtrl)
  417. {
  418. HWND hwndFrame;
  419. HMENU hMenu;
  420. MENUITEMINFO mii;
  421. INT idList[] = { IDC_BTN_BACK, IDC_BTN_NEXT};
  422. INT count = (INT)SendMessageW(hwndCtrl, LB_GETCOUNT, 0, 0L);
  423. INT index = (INT)SendMessageW(hwndCtrl, LB_GETCURSEL, 0, 0L);
  424. if (nPageActive == (size_t)index) return;
  425. if (-1 != nPageActive && S_FALSE == pageList[nPageActive]->Validate())
  426. {
  427. SendMessageW(hwndCtrl, LB_SETCURSEL, nPageActive, 0L);
  428. return;
  429. }
  430. hwndFrame = GetDlgItem(hwnd, IDC_FRAME);
  431. hMenu = GetMenu(hwnd);
  432. mii.cbSize = sizeof(MENUITEMINFO);
  433. mii.fMask = MIIM_STATE;
  434. for(int i = sizeof(idList)/sizeof(int) - 1; i >= 0 ; i--)
  435. {
  436. HWND hwndBtn = GetDlgItem(hwnd, idList[i]);
  437. BOOL bEnable = (IDC_BTN_NEXT == idList[i]) ? ((count - index) > 1) : (0 != index);
  438. if (hwndBtn)
  439. {
  440. if (bEnable != IsWindowEnabled(hwndBtn))
  441. {
  442. if (IDC_BTN_NEXT == idList[i]) SendMessageW(hwnd, DM_SETDEFID, (WPARAM)((bEnable) ? IDC_BTN_NEXT : IDOK), 0L);
  443. EnableWindow(hwndBtn, bEnable);
  444. }
  445. if (hMenu)
  446. {
  447. mii.fState = (bEnable) ? MFS_ENABLED : MFS_DISABLED;
  448. SetMenuItemInfoW(hMenu, (IDC_BTN_NEXT == idList[i]) ? IDM_NAVIGATE_NEXT : IDM_NAVIGATE_BACK, FALSE, &mii);
  449. }
  450. }
  451. }
  452. if (hwndActive)
  453. {
  454. DestroyWindow(hwndActive);
  455. hwndActive = NULL;
  456. nPageActive = (size_t)-1;
  457. }
  458. if (S_OK != pageList[index]->CreateView(hwnd, &hwndActive))
  459. hwndActive = WACreateDialog(MAKEINTRESOURCEW(IDD_SETUP_PAGE_ERROR), hwnd, ErrorPageDialog);
  460. HWND hwndHeader;
  461. RECT rc;
  462. GetClientRect(hwndFrame, &rc);
  463. MapWindowPoints(hwndFrame, hwnd, (POINT*)&rc, 2);
  464. hwndHeader = GetDlgItem(hwnd, IDC_HEADER);
  465. if (hwndHeader && (WS_VISIBLE & GetWindowLongPtrW(hwndHeader, GWL_STYLE)))
  466. {
  467. RECT rw;
  468. GetWindowRect(hwndHeader, &rw);
  469. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rw, 2);
  470. rc.top = rw.bottom;
  471. rc.left = rw.left;
  472. }
  473. SetWindowPos(hwndActive, GetDlgItem(hwnd, IDC_LB_NAVIGATION), rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOACTIVATE);
  474. if(IsWinXPTheme()) WAEnableThemeDialogTexture(hwndActive, ETDT_ENABLETAB);
  475. else
  476. {
  477. SPTHEME *pTheme = (SPTHEME*)malloc(sizeof(SPTHEME));
  478. pTheme->bUnicode = IsWindowUnicode(hwndActive);
  479. pTheme->pui = pui;
  480. pTheme->fnOldProc = (WNDPROC)SetWindowLongPtrW(hwndActive, GWLP_WNDPROC, (LONG_PTR)PageWndProc);
  481. if (!pTheme->fnOldProc || !SetPropW(hwndActive, L"SPTHEME", pTheme))
  482. {
  483. if (pTheme->fnOldProc) SetWindowLongPtrW(hwndActive, GWLP_WNDPROC, (LONG_PTR)pTheme->fnOldProc);
  484. free(pTheme);
  485. }
  486. }
  487. ShowWindow(hwndActive, SW_SHOW);
  488. nPageActive = index;
  489. if (hwndHeader) InvalidateRect(hwndHeader, NULL, FALSE);
  490. HWND hwndTest = GetNextDlgTabItem(hwnd, GetWindow(hwndActive, GW_HWNDPREV), FALSE);
  491. if (hwndTest) SendMessageW(hwnd, WM_NEXTDLGCTL, (WPARAM)hwndTest, TRUE);
  492. }
  493. void WASetup::OnCommand(INT nCtrlID, INT nEvntID, HWND hwndCtrl)
  494. {
  495. switch(nCtrlID)
  496. {
  497. case IDOK:
  498. if (BN_CLICKED == nEvntID)
  499. {
  500. if (-1 != nPageActive && S_FALSE != pageList[nPageActive]->Validate())
  501. {
  502. DestroyWindow(hwnd);
  503. PostQuitMessage(IDOK);
  504. }
  505. }
  506. break;
  507. case IDCANCEL: if (BN_CLICKED == nEvntID) OnCancel(); break;
  508. case IDC_BTN_NEXT: if (BN_CLICKED == nEvntID) OnNext_Clicked(hwndCtrl); break;
  509. case IDC_BTN_BACK: if (BN_CLICKED == nEvntID) OnBack_Clicked(hwndCtrl); break;
  510. case IDC_LB_NAVIGATION:
  511. switch(nEvntID)
  512. {
  513. case LBN_SELCHANGE: OnNavigation_SelChange(hwndCtrl); break;
  514. }
  515. break;
  516. case IDM_HELP_ABOUT: WADialogBox(MAKEINTRESOURCEW(IDD_ABOUT), hwnd, AboutDialogProc); break;
  517. case IDM_NAVIGATE_BACK: SendMessageW(GetDlgItem(hwnd, IDC_BTN_BACK), BM_CLICK, 0, 0L); break;
  518. case IDM_NAVIGATE_NEXT: SendMessageW(GetDlgItem(hwnd, IDC_BTN_NEXT), BM_CLICK, 0, 0L); break;
  519. case IDM_FILE_EXIT: OnCancel(); break;
  520. case IDM_FILE_SAVECHANGES:
  521. if (S_OK != Save(NULL))
  522. {
  523. WCHAR szTitle[128] = {0}, szText[256] = {0};
  524. GetWindowTextW(hwnd, szTitle, sizeof(szTitle)/sizeof(WCHAR));
  525. MessageBoxW(hwnd, getStringW(IDS_CHANGES_NOT_SAVED, szText, sizeof(szText)/sizeof(wchar_t)), szTitle, MB_OK | MB_ICONERROR);
  526. }
  527. break;
  528. }
  529. }
  530. void WASetup::OnDrawHeader(DRAWITEMSTRUCT *pdis)
  531. {
  532. const wchar_t *pszName;
  533. RECT ri, re;
  534. INT top;
  535. CopyRect(&ri, &pdis->rcItem);
  536. CopyRect(&re, &ri);
  537. re.right = ri.left + 1;
  538. FillRect(pdis->hDC, &re, (HBRUSH)GetStockObject(WHITE_BRUSH));
  539. ri.left = re.right;
  540. SetBrushOrgEx(pdis->hDC, ri.left, ri.top, NULL);
  541. FillRect(pdis->hDC, &ri, pui->hbHeader);
  542. if (nPageActive >= pageList.size() || S_OK != pageList[nPageActive]->GetName(FALSE, &pszName) || !*pszName) pszName = GetUnknownStr();
  543. SetBkMode(pdis->hDC, TRANSPARENT);
  544. InflateRect(&ri, -4, -2);
  545. top = ri.top + (ri.bottom - ri.top - pui->nHdrTxtHeight)/2 - 1;
  546. if (top > ri.top) ri.top = top;
  547. if (ri.left < ri.right)
  548. {
  549. RECT rn;
  550. wchar_t szPageInfo[64] = {0};
  551. CopyRect(&rn, &ri);
  552. SetTextColor(pdis->hDC, HEADER_PAGENUM_TEXT_COLOR);
  553. UINT oldMode = SetTextAlign(pdis->hDC, TA_RIGHT);
  554. HFONT hfOld = (pui->hfHeaderPageNum) ? (HFONT)SelectObject(pdis->hDC, pui->hfHeaderPageNum) : NULL;
  555. top = ri.top + pui->nHdrTxtHeight - pui->nHdrPageTxtHeight;
  556. if (top > rn.top) rn.top = top;
  557. rn.right -= 8;
  558. rn.left = rn.right - 42;
  559. StringCchPrintfW(szPageInfo, sizeof(szPageInfo)/sizeof(wchar_t), L"%d/%d", nPageActive + 1, pageList.size());
  560. ExtTextOutW(pdis->hDC, rn.right, rn.top, ETO_CLIPPED, &rn, szPageInfo, lstrlenW(szPageInfo), NULL);
  561. SetTextAlign(pdis->hDC, oldMode);
  562. if (hfOld) SelectObject(pdis->hDC, hfOld);
  563. ri.right = rn.left -= 4;
  564. }
  565. if (ri.left < ri.right)
  566. {
  567. SetTextColor(pdis->hDC, HEADER_TEXT_COLOR);
  568. SetTextAlign(pdis->hDC, TA_LEFT);
  569. ExtTextOutW(pdis->hDC, ri.left, ri.top, ETO_CLIPPED, &ri, pszName, lstrlenW(pszName), NULL);
  570. }
  571. }
  572. void WASetup::OnDrawNavigationItem(DRAWITEMSTRUCT *pdis)
  573. {
  574. const wchar_t *pszName;
  575. RECT ri;
  576. HFONT hfOld;
  577. wchar_t szTitle[128] = {0};
  578. COLORREF rgbText;
  579. if (pdis->itemID == -1) return;
  580. CopyRect(&ri, &pdis->rcItem);
  581. ri.left += NAVIGATION_PADDING_LEFT;
  582. ri.right -= NAVIGATION_PADDING_RIGHT;
  583. if (ODA_FOCUS == pdis->itemAction)
  584. {
  585. if (0 == (0x0200/*ODS_NOFOCUSRECT*/ & pdis->itemState))
  586. {
  587. InflateRect(&ri, -1, -1);
  588. DrawFocusRect(pdis->hDC, &ri);
  589. }
  590. return;
  591. }
  592. if (ODS_SELECTED & pdis->itemState)
  593. {
  594. HBRUSH hbActive;
  595. if (pui->hbNavItemSel)
  596. {
  597. SetBrushOrgEx(pdis->hDC, ri.left, ri.top, NULL);
  598. hbActive = pui->hbNavItemSel;
  599. }
  600. else
  601. {
  602. SetBrushOrgEx(pdis->hDC, 0, 0, NULL);
  603. hbActive = pui->hbNavBack;
  604. }
  605. FillRect(pdis->hDC, &ri, hbActive);
  606. rgbText = SetTextColor(pdis->hDC, NAVIGATION_SEL_TEXT_COLOR);
  607. hfOld = (HFONT)SelectObject(pdis->hDC, pui->hfNavItemSel);
  608. }
  609. else
  610. {
  611. if (ODA_SELECT == pdis->itemAction)
  612. {
  613. SetBrushOrgEx(pdis->hDC, 0, 0, NULL);
  614. FillRect(pdis->hDC, &ri, pui->hbNavBack);
  615. }
  616. rgbText = 0;
  617. hfOld = NULL;
  618. }
  619. if (pdis->itemData >= pageList.size() || S_OK != pageList[pdis->itemData]->GetName(TRUE, &pszName) || !*pszName)
  620. pszName = GetUnknownStr();
  621. SetBkMode(pdis->hDC, TRANSPARENT);
  622. InflateRect(&ri, -4, -2);
  623. INT top = ri.top + (ri.bottom - ri.top - pui->nNavTxtHeight)/2 - 1;
  624. if (top > ri.top) ri.top = top;
  625. StringCchPrintfW(szTitle, sizeof(szTitle)/sizeof(wchar_t), L"%d. %s", pdis->itemData + 1, pszName);
  626. ExtTextOutW(pdis->hDC, ri.left, ri.top, ETO_CLIPPED, &ri, szTitle, lstrlenW(szTitle), NULL);
  627. if (ODS_SELECTED & pdis->itemState)
  628. {
  629. SetTextColor(pdis->hDC, rgbText);
  630. if (hfOld) SelectObject(pdis->hDC, hfOld);
  631. }
  632. }
  633. INT_PTR WASetup::OnDrawItem(INT nCtrlID, DRAWITEMSTRUCT *pdis)
  634. {
  635. switch(nCtrlID)
  636. {
  637. case IDC_HEADER: OnDrawHeader(pdis); return TRUE;
  638. case IDC_LB_NAVIGATION: OnDrawNavigationItem(pdis); return TRUE;
  639. }
  640. return 0;
  641. }
  642. INT_PTR WASetup::OnMeasureItem(INT nCtrlID, MEASUREITEMSTRUCT *pmis)
  643. {
  644. switch(nCtrlID)
  645. {
  646. case IDC_LB_NAVIGATION:
  647. pmis->itemHeight = (pui) ? pui->nNavItemHeight : 0;
  648. return TRUE;
  649. }
  650. return FALSE;
  651. }
  652. INT_PTR WASetup::OnColorListBox(HDC hdc, HWND hwndCtrl)
  653. {
  654. if (hwndCtrl == GetDlgItem(hwnd, IDC_LB_NAVIGATION))
  655. {
  656. SetTextColor(hdc, NAVIGATION_TEXT_COLOR);
  657. SetBkColor(hdc, NAVIGATION_BACK_COLOR);
  658. return (INT_PTR)pui->hbNavBack;
  659. }
  660. return NULL;
  661. }
  662. INT_PTR WASetup::DialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  663. {
  664. INT_PTR result = 0;
  665. switch(uMsg)
  666. {
  667. case WM_INITDIALOG: return OnInitDialog((HWND)wParam, lParam);
  668. case WM_DESTROY: OnDestroy(); break;
  669. case WM_COMMAND: OnCommand(LOWORD(wParam), HIWORD(wParam), (HWND)lParam); break;
  670. case WM_DRAWITEM: result = OnDrawItem((INT)wParam, (DRAWITEMSTRUCT*)lParam); break;
  671. case WM_MEASUREITEM: result = OnMeasureItem((INT)wParam, (MEASUREITEMSTRUCT*)lParam); break;
  672. case WM_CTLCOLORLISTBOX: return OnColorListBox((HDC)wParam, (HWND)lParam);
  673. case WM_CHAR:
  674. if (0x30 == wParam)
  675. {
  676. OutputDebugStringA("test\n");
  677. return 0;
  678. }
  679. }
  680. if (result)
  681. {
  682. SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (LONG_PTR)result);
  683. return TRUE;
  684. }
  685. return 0;
  686. }
  687. static INT_PTR WINAPI DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  688. {
  689. WASetup *pInst = (WASetup*)GetPropW(hwndDlg, L"SETUPDLG");
  690. if (!pInst && g_pAttachInstance)
  691. {
  692. pInst = g_pAttachInstance;
  693. pInst->hwnd = hwndDlg;
  694. SetPropW(hwndDlg, L"SETUPDLG", pInst);
  695. g_pAttachInstance = NULL;
  696. }
  697. switch(uMsg)
  698. {
  699. case WM_DESTROY:
  700. if (pInst)
  701. {
  702. pInst->DialogProc(uMsg, wParam, lParam);
  703. RemovePropW(hwndDlg, L"SETUPDLG");
  704. pInst = NULL;
  705. }
  706. break;
  707. }
  708. return (pInst) ? pInst->DialogProc(uMsg, wParam, lParam) : 0;
  709. }
  710. static INT_PTR WINAPI AboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  711. {
  712. switch(uMsg)
  713. {
  714. case WM_INITDIALOG:
  715. {
  716. SendDlgItemMessageW(hwndDlg, IDC_PIC_ABOUT, STM_SETIMAGE, IMAGE_BITMAP,
  717. (LPARAM)WALoadImage2(L"PNG", MAKEINTRESOURCEW(IDB_ABOUT), FALSE));
  718. wchar_t buf[2048] = {0}, buf2[2048] = {0};
  719. GetWindowTextW(GetDlgItem(hwndDlg,IDC_VER_TEXT),buf,ARRAYSIZE(buf));
  720. StringCchPrintfW(buf2,2048,(buf[0] ? buf : L"v%s %s - %s"),AutoWideDup(app_version_string),AutoWideDup(APP_VERSION_PLATFORM),AutoWideDup(app_date));
  721. SetWindowTextW(GetDlgItem(hwndDlg,IDC_VER_TEXT),buf2);
  722. }
  723. break;
  724. case WM_DESTROY:
  725. {
  726. DeleteObject((HBITMAP)SendDlgItemMessageW(hwndDlg, IDC_PIC_ABOUT, STM_GETIMAGE, IMAGE_BITMAP, 0L));
  727. }
  728. break;
  729. case WM_COMMAND:
  730. switch(LOWORD(wParam))
  731. {
  732. case IDOK:
  733. case IDCANCEL:
  734. EndDialog(hwndDlg, 0);
  735. break;
  736. }
  737. }
  738. return 0;
  739. }
  740. static INT_PTR WINAPI JobStatusDialog(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  741. {
  742. switch(uMsg)
  743. {
  744. case WM_COMMAND:
  745. switch(LOWORD(wParam))
  746. {
  747. case IDC_BTN_SKIP:
  748. if (BN_CLICKED == HIWORD(wParam))
  749. {
  750. ifc_setupjob *pj = (ifc_setupjob*)GetPropW(hwndDlg, L"JOB");
  751. if (pj)
  752. {
  753. HWND hwndStatus = GetDlgItem(hwndDlg, IDC_LBL_STATUS);
  754. EnableWindow((HWND)lParam, FALSE);
  755. if (hwndStatus) SetWindowTextW(hwndStatus, getStringW(IDS_HTTP_ABORT, NULL, 0));
  756. pj->Cancel(hwndStatus);
  757. }
  758. }
  759. break;
  760. }
  761. case WM_DESTROY:
  762. RemovePropW(hwndDlg, L"JOB");
  763. }
  764. return 0;
  765. }
  766. static INT_PTR WINAPI ErrorPageDialog(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  767. {
  768. switch(uMsg)
  769. {
  770. case WM_WINDOWPOSCHANGED:
  771. if (SWP_NOSIZE != ((SWP_NOSIZE | SWP_FRAMECHANGED) & ((WINDOWPOS*)lParam)->flags))
  772. {
  773. HWND messageWindow;
  774. messageWindow = GetDlgItem(hwndDlg, IDC_LBL_MESSAGE);
  775. if (NULL != messageWindow)
  776. {
  777. RECT rect;
  778. long top;
  779. GetWindowRect(messageWindow, &rect);
  780. MapWindowPoints(HWND_DESKTOP, hwndDlg, (POINT*)&rect, 1);
  781. top = rect.top;
  782. GetClientRect(hwndDlg, &rect);
  783. rect.top = top;
  784. SetWindowPos(messageWindow, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
  785. SWP_NOACTIVATE | SWP_NOZORDER);
  786. }
  787. }
  788. break;
  789. }
  790. return 0;
  791. }
  792. static LRESULT WINAPI PageWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  793. {
  794. SPTHEME *pTheme = (SPTHEME*)GetPropW(hwnd, L"SPTHEME");
  795. if (!pTheme || !pTheme->fnOldProc) return DefWindowProcW(hwnd, uMsg, wParam, lParam);
  796. switch(uMsg)
  797. {
  798. case WM_CTLCOLORDLG:
  799. case WM_CTLCOLORSTATIC:
  800. SetBkColor((HDC)wParam, PAGE_BACK_COLOR);
  801. SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
  802. return (LRESULT)pTheme->pui->hbPage;
  803. case WM_DESTROY:
  804. {
  805. WNDPROC fnOldProc = pTheme->fnOldProc;
  806. RemovePropA(hwnd, "SPTHEME");
  807. free(pTheme);
  808. SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)fnOldProc);
  809. return CallWindowProcW(fnOldProc, hwnd, uMsg, wParam, lParam);
  810. }
  811. }
  812. return (pTheme->bUnicode) ? CallWindowProcW(pTheme->fnOldProc, hwnd, uMsg, wParam, lParam) :
  813. CallWindowProcA(pTheme->fnOldProc, hwnd, uMsg, wParam, lParam);
  814. }
  815. static DWORD GetHighestFontQuality(void)
  816. {
  817. DWORD fdwQuality;
  818. BOOL bSmoothing;
  819. if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &bSmoothing, 0) && bSmoothing)
  820. {
  821. OSVERSIONINFO vi = { sizeof(OSVERSIONINFO), };
  822. fdwQuality = (GetVersionEx(&vi) && (vi.dwMajorVersion > 5 || (vi.dwMajorVersion == 5 && vi.dwMinorVersion > 0))) ?
  823. 5/*CLEARTYPE_QUALITY*/ : ANTIALIASED_QUALITY;
  824. }
  825. else fdwQuality = DEFAULT_QUALITY;
  826. return fdwQuality;
  827. }
  828. static BOOL InitializeUI(UI *pui, HWND hwndCtrl)
  829. {
  830. if (!pui) return FALSE;
  831. if (!pui->ref)
  832. {
  833. HBITMAP hbmp;
  834. BITMAP bi;
  835. HDC hdc;
  836. INT logPx;
  837. TEXTMETRIC tm;
  838. hdc = GetWindowDC(hwndCtrl);
  839. logPx = GetDeviceCaps(hdc, LOGPIXELSY);
  840. pui->hbPage = CreateSolidBrush(PAGE_BACK_COLOR);
  841. hbmp = (HBITMAP)LoadImageW(hMainInstance, MAKEINTRESOURCEW(IDB_NAVIGATION_STRIP), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
  842. if (hbmp)
  843. {
  844. pui->hbNavBack = CreatePatternBrush(hbmp);
  845. DeleteObject(hbmp);
  846. }
  847. else pui->hbNavBack = CreateSolidBrush(NAVIGATION_BACK_COLOR);
  848. pui->hfNavItem = CreateFontA(-MulDiv(NAVIGATION_FONT_SIZE, logPx, 72), 0, 0, 0, NAVIGATION_FONT_WEIGHT,
  849. NAVIGATION_FONT_ITALIC, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  850. GetHighestFontQuality(), FF_DONTCARE, NAVIGATION_FONT_NAME);
  851. pui->hfNavItemSel = CreateFontA(-MulDiv(NAVIGATION_SEL_FONT_SIZE, logPx, 72), 0, 0, 0, NAVIGATION_SEL_FONT_WEIGHT,
  852. NAVIGATION_SEL_FONT_ITALIC, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  853. GetHighestFontQuality(), FF_DONTCARE, NAVIGATION_SEL_FONT_NAME);
  854. pui->hfHeader = CreateFontA(-MulDiv(HEADER_FONT_SIZE, logPx, 72), 0, 0, 0, HEADER_FONT_WEIGHT,
  855. HEADER_FONT_ITALIC, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  856. GetHighestFontQuality(), FF_DONTCARE, HEADER_FONT_NAME);
  857. pui->hfHeaderPageNum = CreateFontA(-MulDiv(HEADER_PAGENUM_FONT_SIZE, logPx, 72), 0, 0, 0, HEADER_PAGENUM_FONT_WEIGHT,
  858. HEADER_PAGENUM_FONT_ITALIC, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  859. GetHighestFontQuality(), FF_DONTCARE, HEADER_PAGENUM_FONT_NAME);
  860. pui->nHdrHeight = 36;
  861. hbmp = (HBITMAP)LoadImageW(hMainInstance, MAKEINTRESOURCEW(IDB_HEADER_STRIP), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
  862. if (hbmp)
  863. {
  864. if (GetObject(hbmp, sizeof(BITMAP), &bi)) pui->nHdrHeight = bi.bmHeight;
  865. pui->hbHeader = CreatePatternBrush(hbmp);
  866. DeleteObject(hbmp);
  867. }
  868. pui->nNavItemHeight = 32;
  869. // hbmp = (HBITMAP)LoadImageW(hMainInstance, MAKEINTRESOURCEW(IDB_NAVITEM_STRIP), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
  870. // if (hbmp)
  871. // {
  872. // if (GetObject(hbmp, sizeof(BITMAP), &bi)) pui->nNavItemHeight = bi.bmHeight;
  873. // pui->hbNavItemSel = CreatePatternBrush(hbmp);
  874. // DeleteObject(hbmp);
  875. // }
  876. HFONT hfOld = (HFONT)SelectObject(hdc, pui->hfHeader);
  877. GetTextMetrics(hdc, &tm);
  878. pui->nHdrTxtHeight = tm.tmAscent;
  879. SelectObject(hdc, pui->hfHeaderPageNum);
  880. GetTextMetrics(hdc, &tm);
  881. pui->nHdrPageTxtHeight = tm.tmAscent;
  882. SelectObject(hdc, pui->hfNavItem);
  883. GetTextMetrics(hdc, &tm);
  884. pui->nNavTxtHeight = tm.tmAscent;
  885. SelectObject(hdc, pui->hfNavItemSel);
  886. GetTextMetrics(hdc, &tm);
  887. pui->nNavTxtSelHeight = tm.tmAscent;
  888. SelectObject(hdc, hfOld);
  889. ReleaseDC(hwndCtrl, hdc);
  890. }
  891. pui->ref++;
  892. return TRUE;
  893. }
  894. static BOOL ReleaseUI(UI *pui)
  895. {
  896. if (!pui) return FALSE;
  897. if (0 == pui->ref)
  898. {
  899. return TRUE;
  900. }
  901. if (1 == pui->ref)
  902. {
  903. if (pui->hbPage) DeleteObject(pui->hbPage);
  904. if (pui->hbNavBack) DeleteObject(pui->hbNavBack);
  905. if (pui->hbHeader) DeleteObject(pui->hbHeader);
  906. if (pui->hbNavItemSel) DeleteObject(pui->hbNavItemSel);
  907. if (pui->hfNavItem) DeleteObject(pui->hfNavItem);
  908. if (pui->hfNavItemSel) DeleteObject(pui->hfNavItemSel);
  909. if (pui->hfHeader) DeleteObject(pui->hfHeader);
  910. if (pui->hfHeaderPageNum) DeleteObject(pui->hfHeaderPageNum);
  911. ZeroMemory(pui, sizeof(UI));
  912. return TRUE;
  913. }
  914. pui->ref--;
  915. return TRUE;
  916. }
  917. static const wchar_t *GetUnknownStr(void)
  918. {
  919. static wchar_t unknown[64] = {0,};
  920. return (unknown) ? unknown : getStringW(IDS_UNKNOWN, unknown, sizeof(unknown)/sizeof(wchar_t));
  921. }
  922. static LRESULT WINAPI FrameWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  923. {
  924. WNDPROC fnOldProc = (WNDPROC)GetPropW(hwnd, L"SKINFRAME");
  925. if (!fnOldProc) return DefWindowProcW(hwnd, uMsg, wParam, lParam);
  926. switch(uMsg)
  927. {
  928. case WM_DESTROY:
  929. RemovePropW(hwnd, L"SKINFRAME");
  930. SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)fnOldProc);
  931. break;
  932. case WM_PAINT:
  933. ValidateRect(hwnd, NULL);
  934. return 0;
  935. case WM_ERASEBKGND: return 1;
  936. }
  937. return CallWindowProcW(fnOldProc, hwnd, uMsg, wParam, lParam);
  938. }
  939. static BOOL JobStatus_Advance(HWND hwndStatus)
  940. {
  941. if (bUseMarquee > 0 ) return TRUE;
  942. if (!hwndStatus) return FALSE;
  943. HWND hwndCtrl = GetDlgItem(hwndStatus, IDC_PROGRESS);
  944. if (!hwndCtrl) return FALSE;
  945. SendMessageW(hwndCtrl, PBM_STEPIT, 0, 0L);
  946. return TRUE;
  947. }
  948. #ifdef CBCLASS
  949. #undef CBCLASS
  950. #endif
  951. #define CBCLASS WASetup
  952. START_DISPATCH
  953. CB(ADDREF, AddRef)
  954. CB(RELEASE, Release)
  955. CB(API_SETUP_INSERT_PAGE, InsertPage)
  956. CB(API_SETUP_REMOVE_PAGE, RemovePage)
  957. CB(API_SETUP_GET_PAGE_COUNT, GetPageCount)
  958. CB(API_SETUP_GET_PAGE, GetPage)
  959. CB(API_SETUP_GET_ACTIVE_INDEX, GetActiveIndex)
  960. CB(API_SETUP_START, Start)
  961. CB(API_SETUP_ADD_JOB, AddJob)
  962. CB(API_SETUP_REMOVE_JOB, RemoveJob)
  963. CB(API_SETUP_CREATE_STATUSWND, CreateStatusWnd)
  964. CB(API_SETUP_SAVE, Save)
  965. CB(API_SETUP_EXECJOBS, ExecJobs)
  966. CB(API_SETUP_GETWINAMPWND, GetWinampWnd)
  967. END_DISPATCH
  968. #undef CBCLASS