1
0

optionsUi.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. #include "main.h"
  2. #include "./options.h"
  3. #include "./resource.h"
  4. #include "./obj_ombrowser.h"
  5. #include "./ifc_omconfig.h"
  6. #include "./ifc_omtoolbarconfig.h"
  7. #include "./ifc_omstatusbarconfig.h"
  8. #include <windows.h>
  9. #include <commctrl.h>
  10. #include <shlwapi.h>
  11. #include <strsafe.h>
  12. #define TOOLBAR_TOPDOCK 0
  13. #define TOOLBAR_BOTTOMDOCK 1
  14. #define BOOL2HRESULT(__result) ((FALSE != (__result)) ? S_OK : S_FALSE)
  15. static INT_PTR CALLBACK OptionsUI_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  16. HWND CALLBACK OptionsUI_CreatePage(HWND hParent, UINT style)
  17. {
  18. return Plugin_CreateDialogParam(MAKEINTRESOURCE(IDD_OPTIONS_UI), hParent, OptionsUI_DialogProc, 0L);
  19. }
  20. static INT OptionsUI_GetLocationIndex(HWND hwnd, UINT locationId)
  21. {
  22. HWND hControl = GetDlgItem(hwnd, IDC_TOOLBAR_LOCATION);
  23. if (NULL == hControl) return CB_ERR;
  24. INT count = (INT)SendMessage(hControl, CB_GETCOUNT, 0, 0L);
  25. for (INT i = 0; i < count; i++)
  26. {
  27. if (locationId == (UINT)SendMessage(hControl, CB_GETITEMDATA, i, 0L))
  28. return i;
  29. }
  30. return CB_ERR;
  31. }
  32. static void OptionsUI_UpdateToolbarLocation(HWND hwnd, HRESULT bottomLocation)
  33. {
  34. HWND hControl = GetDlgItem(hwnd, IDC_TOOLBAR_LOCATION);
  35. if (NULL == hControl) return;
  36. if (FAILED(bottomLocation))
  37. {
  38. EnableWindow(hControl, FALSE);
  39. }
  40. else
  41. {
  42. INT iIndex = OptionsUI_GetLocationIndex(hwnd, (S_OK == bottomLocation) ? TOOLBAR_BOTTOMDOCK : TOOLBAR_TOPDOCK);
  43. if (CB_ERR != iIndex)
  44. SendMessage(hControl, CB_SETCURSEL, iIndex, 0L);
  45. EnableWindow(hControl, TRUE);
  46. }
  47. }
  48. static void OptionsUI_UpdateToolbarAutoHide(HWND hwnd, HRESULT autoHide)
  49. {
  50. Options_SetCheckbox(hwnd, IDC_TOOLBAR_AUTOHIDE, autoHide);
  51. }
  52. static void OptionsUI_UpdateToolbarTabStop(HWND hwnd, HRESULT tabStop)
  53. {
  54. Options_SetCheckbox(hwnd, IDC_TOOLBAR_TABSTOP, tabStop);
  55. }
  56. static void OptionsUI_UpdateToolbarForceAddress(HWND hwnd, HRESULT enabled)
  57. {
  58. Options_SetCheckbox(hwnd, IDC_TOOLBAR_FORCEADDRESS, enabled);
  59. }
  60. static void OptionsUI_UpdateToolbarFancyAddress(HWND hwnd, HRESULT enabled)
  61. {
  62. Options_SetCheckbox(hwnd, IDC_TOOLBAR_FANCYADDRESS, enabled);
  63. }
  64. static void OptionsUI_UpdateStatusbarEnabled(HWND hwnd, HRESULT enabled)
  65. {
  66. Options_SetCheckbox(hwnd, IDC_STATUSBAR_ENABLED, enabled);
  67. }
  68. static INT_PTR OptionsUI_OnInitDialog(HWND hwnd, HWND hFocus, LPARAM param)
  69. {
  70. WCHAR szBuffer[512] = {0};
  71. Plugin_LoadString(IDS_OPTIONS_UI, szBuffer, ARRAYSIZE(szBuffer));
  72. SetWindowText(hwnd, szBuffer);
  73. HWND hControl = GetDlgItem(hwnd, IDC_TOOLBAR_LOCATION);
  74. if (NULL != hControl)
  75. {
  76. INT iItem;
  77. Plugin_LoadString(IDS_TOOLBAR_TOPDOCK, szBuffer, ARRAYSIZE(szBuffer));
  78. iItem = (INT)(INT_PTR)SendMessage(hControl, CB_ADDSTRING, 0, (LPARAM)szBuffer);
  79. if (CB_ERR != iItem)
  80. SendMessage(hControl, CB_SETITEMDATA, (WPARAM)iItem, (LPARAM)TOOLBAR_TOPDOCK);
  81. Plugin_LoadString(IDS_TOOLBAR_BOTTOMDOCK, szBuffer, ARRAYSIZE(szBuffer));
  82. iItem = (INT)(INT_PTR)SendMessage(hControl, CB_ADDSTRING, 0, (LPARAM)szBuffer);
  83. if (CB_ERR != iItem)
  84. SendMessage(hControl, CB_SETITEMDATA, (WPARAM)iItem, (LPARAM)TOOLBAR_BOTTOMDOCK);
  85. }
  86. HWND hParent = GetParent(hwnd);
  87. obj_ombrowser *browserManager;
  88. if (FALSE == SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  89. browserManager = NULL;
  90. ifc_omtoolbarconfig *toolbarConfig;
  91. if (NULL != browserManager &&
  92. SUCCEEDED(browserManager->GetConfig(&IFC_OmToolbarConfig, (void**)&toolbarConfig)))
  93. {
  94. OptionsUI_UpdateToolbarLocation(hwnd, toolbarConfig->GetBottomDockEnabled());
  95. OptionsUI_UpdateToolbarAutoHide(hwnd, toolbarConfig->GetAutoHideEnabled());
  96. OptionsUI_UpdateToolbarTabStop(hwnd, toolbarConfig->GetTabStopEnabled());
  97. OptionsUI_UpdateToolbarForceAddress(hwnd, toolbarConfig->GetForceAddressbarEnabled());
  98. OptionsUI_UpdateToolbarFancyAddress(hwnd, toolbarConfig->GetFancyAddressbarEnabled());
  99. toolbarConfig->Release();
  100. }
  101. else
  102. {
  103. OptionsUI_UpdateToolbarLocation(hwnd, E_FAIL);
  104. OptionsUI_UpdateToolbarAutoHide(hwnd, E_FAIL);
  105. OptionsUI_UpdateToolbarTabStop(hwnd, E_FAIL);
  106. }
  107. ifc_omstatusbarconfig *statusbarConfig;
  108. if (NULL != browserManager &&
  109. SUCCEEDED(browserManager->GetConfig(&IFC_OmStatusbarConfig, (void**)&statusbarConfig)))
  110. {
  111. OptionsUI_UpdateStatusbarEnabled(hwnd, statusbarConfig->GetEnabled());
  112. statusbarConfig->Release();
  113. }
  114. else
  115. {
  116. OptionsUI_UpdateStatusbarEnabled(hwnd, E_FAIL);
  117. }
  118. if (NULL != browserManager)
  119. browserManager->Release();
  120. return 0;
  121. }
  122. static void OptionsUI_OnDestroy(HWND hwnd)
  123. {
  124. }
  125. static void OptionsUI_OnWindowPosChanged(HWND hwnd, WINDOWPOS *pwp)
  126. {
  127. }
  128. static void OptionsUI_OnToolbarLocation(HWND hwnd)
  129. {
  130. HWND hControl = GetDlgItem(hwnd, IDC_TOOLBAR_LOCATION);
  131. if (NULL == hControl) return;
  132. HWND hParent = GetParent(hwnd);
  133. if (NULL == hParent) return;
  134. INT iIndex = (INT)SendMessage(hControl, CB_GETCURSEL, 0, 0L);
  135. if (CB_ERR == iIndex) return;
  136. INT dockType = (INT)SendMessage(hControl, CB_GETITEMDATA, iIndex, 0L);
  137. if (TOOLBAR_TOPDOCK != dockType && TOOLBAR_BOTTOMDOCK != dockType)
  138. return;
  139. obj_ombrowser *browserManager;
  140. if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  141. {
  142. ifc_omtoolbarconfig *toolbarConfig;
  143. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmToolbarConfig, (void**)&toolbarConfig)))
  144. {
  145. toolbarConfig->EnableBottomDock(TOOLBAR_BOTTOMDOCK == dockType);
  146. toolbarConfig->Release();
  147. }
  148. browserManager->Release();
  149. }
  150. }
  151. static void OptionsUI_OnToolbarAutoHide(HWND hwnd)
  152. {
  153. HWND hControl = GetDlgItem(hwnd, IDC_TOOLBAR_AUTOHIDE);
  154. if (NULL == hControl) return;
  155. HWND hParent = GetParent(hwnd);
  156. if (NULL == hParent) return;
  157. BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));
  158. obj_ombrowser *browserManager;
  159. if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  160. {
  161. ifc_omtoolbarconfig *toolbarConfig;
  162. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmToolbarConfig, (void**)&toolbarConfig)))
  163. {
  164. toolbarConfig->EnableAutoHide(checked);
  165. toolbarConfig->Release();
  166. }
  167. browserManager->Release();
  168. }
  169. }
  170. static void OptionsUI_OnToolbarTabstop(HWND hwnd)
  171. {
  172. HWND hControl = GetDlgItem(hwnd, IDC_TOOLBAR_TABSTOP);
  173. if (NULL == hControl) return;
  174. HWND hParent = GetParent(hwnd);
  175. if (NULL == hParent) return;
  176. BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));
  177. obj_ombrowser *browserManager;
  178. if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  179. {
  180. ifc_omtoolbarconfig *toolbarConfig;
  181. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmToolbarConfig, (void**)&toolbarConfig)))
  182. {
  183. toolbarConfig->EnableTabStop(checked);
  184. toolbarConfig->Release();
  185. }
  186. browserManager->Release();
  187. }
  188. }
  189. static void OptionsUI_OnToolbarForceAddress(HWND hwnd)
  190. {
  191. HWND hControl = GetDlgItem(hwnd, IDC_TOOLBAR_FORCEADDRESS);
  192. if (NULL == hControl) return;
  193. HWND hParent = GetParent(hwnd);
  194. if (NULL == hParent) return;
  195. BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));
  196. obj_ombrowser *browserManager;
  197. if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  198. {
  199. ifc_omtoolbarconfig *toolbarConfig;
  200. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmToolbarConfig, (void**)&toolbarConfig)))
  201. {
  202. toolbarConfig->EnableForceAddressbar(checked);
  203. toolbarConfig->Release();
  204. }
  205. browserManager->Release();
  206. }
  207. }
  208. static void OptionsUI_OnToolbarFancyAddress(HWND hwnd)
  209. {
  210. HWND hControl = GetDlgItem(hwnd, IDC_TOOLBAR_FANCYADDRESS);
  211. if (NULL == hControl) return;
  212. HWND hParent = GetParent(hwnd);
  213. if (NULL == hParent) return;
  214. BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));
  215. obj_ombrowser *browserManager;
  216. if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  217. {
  218. ifc_omtoolbarconfig *toolbarConfig;
  219. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmToolbarConfig, (void**)&toolbarConfig)))
  220. {
  221. toolbarConfig->EnableFancyAddressbar(checked);
  222. toolbarConfig->Release();
  223. }
  224. browserManager->Release();
  225. }
  226. }
  227. static void OptionsUI_OnStatusbarEnabled(HWND hwnd)
  228. {
  229. HWND hControl = GetDlgItem(hwnd, IDC_STATUSBAR_ENABLED);
  230. if (NULL == hControl) return;
  231. HWND hParent = GetParent(hwnd);
  232. if (NULL == hParent) return;
  233. BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));
  234. obj_ombrowser *browserManager;
  235. if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  236. {
  237. ifc_omstatusbarconfig *statusbarConfig;
  238. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmStatusbarConfig, (void**)&statusbarConfig)))
  239. {
  240. statusbarConfig->EnableStatusbar(checked);
  241. statusbarConfig->Release();
  242. }
  243. browserManager->Release();
  244. }
  245. }
  246. static void OptionsUI_OnCommand(HWND hwnd, INT commandId, INT eventId, HWND hControl)
  247. {
  248. switch(commandId)
  249. {
  250. case IDC_TOOLBAR_LOCATION:
  251. if (CBN_SELCHANGE == eventId)
  252. OptionsUI_OnToolbarLocation(hwnd);
  253. break;
  254. case IDC_TOOLBAR_AUTOHIDE:
  255. if (BN_CLICKED == eventId)
  256. OptionsUI_OnToolbarAutoHide(hwnd);
  257. break;
  258. case IDC_TOOLBAR_TABSTOP:
  259. if (BN_CLICKED == eventId)
  260. OptionsUI_OnToolbarTabstop(hwnd);
  261. break;
  262. case IDC_TOOLBAR_FORCEADDRESS:
  263. if (BN_CLICKED == eventId)
  264. OptionsUI_OnToolbarForceAddress(hwnd);
  265. break;
  266. case IDC_TOOLBAR_FANCYADDRESS:
  267. if (BN_CLICKED == eventId)
  268. OptionsUI_OnToolbarFancyAddress(hwnd);
  269. break;
  270. case IDC_STATUSBAR_ENABLED:
  271. if (BN_CLICKED == eventId)
  272. OptionsUI_OnStatusbarEnabled(hwnd);
  273. break;
  274. }
  275. }
  276. static void OptionsUI_OnConfigChanged(HWND hwnd, BOMCONFIGCHANGED *configData)
  277. {
  278. if (NULL == configData || NULL == configData->configUid)
  279. return;
  280. if (IsEqualIID(IFC_OmToolbarConfig, *configData->configUid))
  281. {
  282. switch(configData->valueId)
  283. {
  284. case CFGID_TOOLBAR_BOTTOMDOCK: OptionsUI_UpdateToolbarLocation(hwnd, BOOL2HRESULT(configData->value)); break;
  285. case CFGID_TOOLBAR_AUTOHIDE: OptionsUI_UpdateToolbarAutoHide(hwnd, BOOL2HRESULT(configData->value)); break;
  286. case CFGID_TOOLBAR_TABSTOP: OptionsUI_UpdateToolbarTabStop(hwnd, BOOL2HRESULT(configData->value)); break;
  287. case CFGID_TOOLBAR_FORCEADDRESS: OptionsUI_UpdateToolbarForceAddress(hwnd, BOOL2HRESULT(configData->value)); break;
  288. case CFGID_TOOLBAR_FANCYADDRESS: OptionsUI_UpdateToolbarFancyAddress(hwnd, BOOL2HRESULT(configData->value)); break;
  289. }
  290. }
  291. else if (IsEqualIID(IFC_OmStatusbarConfig, *configData->configUid))
  292. {
  293. switch(configData->valueId)
  294. {
  295. case CFGID_STATUSBAR_ENABLED: OptionsUI_UpdateStatusbarEnabled(hwnd, BOOL2HRESULT(configData->value)); break;
  296. }
  297. }
  298. }
  299. static INT_PTR CALLBACK OptionsUI_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  300. {
  301. switch(uMsg)
  302. {
  303. case WM_INITDIALOG: return OptionsUI_OnInitDialog(hwnd, (HWND)wParam, lParam);
  304. case WM_DESTROY: OptionsUI_OnDestroy(hwnd); return 0;
  305. case WM_WINDOWPOSCHANGED: OptionsUI_OnWindowPosChanged(hwnd, (WINDOWPOS*)lParam); return TRUE;
  306. case WM_COMMAND: OptionsUI_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); return TRUE;
  307. case BOM_CONFIGCHANGED: OptionsUI_OnConfigChanged(hwnd, (BOMCONFIGCHANGED*)lParam); return TRUE;
  308. }
  309. return 0;
  310. }