optionsDebug.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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_omdebugconfig.h"
  7. #include <windows.h>
  8. #include <commctrl.h>
  9. #include <shlwapi.h>
  10. #include <strsafe.h>
  11. #define INVERTHRESULT(__result)\
  12. ((S_OK == (__result)) ? S_FALSE : ((S_FALSE == (__result)) ? S_OK : (__result)))
  13. #define BOOL2HRESULT(__result)\
  14. ((FALSE != (__result)) ? S_OK : S_FALSE)
  15. static INT_PTR CALLBACK OptionsDebug_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  16. HWND CALLBACK OptionsDebug_CreatePage(HWND hParent, UINT style)
  17. {
  18. if (0 == (BOSTYLE_SHOWDEBUG & style))
  19. return NULL;
  20. return Plugin_CreateDialogParam(MAKEINTRESOURCE(IDD_OPTIONS_DEBUG), hParent, OptionsDebug_DialogProc, 0L);
  21. }
  22. static void OptionsDebug_UpdateFilterMenu(HWND hwnd, HRESULT enable)
  23. {
  24. Options_SetCheckbox(hwnd, IDC_FILTERMENU, INVERTHRESULT(enable));
  25. }
  26. static void OptionsDebug_UpdateShowError(HWND hwnd, HRESULT enable)
  27. {
  28. Options_SetCheckbox(hwnd, IDC_SHOWERROR, enable);
  29. }
  30. static void OptionsDebug_UpdateShowDebugger(HWND hwnd, HRESULT enable)
  31. {
  32. Options_SetCheckbox(hwnd, IDC_SHOWDEBUGGER, enable);
  33. }
  34. static INT_PTR OptionsDebug_OnInitDialog(HWND hwnd, HWND hFocus, LPARAM param)
  35. {
  36. WCHAR szBuffer[512] = {0};
  37. Plugin_LoadString(IDS_OPTIONS_DEBUG, szBuffer, ARRAYSIZE(szBuffer));
  38. SetWindowText(hwnd, szBuffer);
  39. HWND hParent = GetParent(hwnd);
  40. obj_ombrowser *browserManager;
  41. if (FALSE == SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  42. browserManager = NULL;
  43. ifc_omdebugconfig *debugConfig;
  44. if (NULL != browserManager &&
  45. SUCCEEDED(browserManager->GetConfig(&IFC_OmDebugConfig, (void**)&debugConfig)))
  46. {
  47. OptionsDebug_UpdateFilterMenu(hwnd, debugConfig->GetMenuFilterEnabled());
  48. OptionsDebug_UpdateShowError(hwnd, debugConfig->GetScriptErrorEnabled());
  49. OptionsDebug_UpdateShowDebugger(hwnd, debugConfig->GetScriptDebuggerEnabled());
  50. debugConfig->Release();
  51. }
  52. else
  53. {
  54. OptionsDebug_UpdateFilterMenu(hwnd, E_FAIL);
  55. OptionsDebug_UpdateShowError(hwnd, E_FAIL);
  56. OptionsDebug_UpdateShowDebugger(hwnd, E_FAIL);
  57. }
  58. return 0;
  59. }
  60. static void OptionsDebug_OnDestroy(HWND hwnd)
  61. {
  62. }
  63. static void OptionsDebug_OnFilterMenu(HWND hwnd)
  64. {
  65. HWND hControl = GetDlgItem(hwnd, IDC_FILTERMENU);
  66. if (NULL == hControl) return;
  67. HWND hParent = GetParent(hwnd);
  68. if (NULL == hParent) return;
  69. BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));
  70. obj_ombrowser *browserManager;
  71. if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  72. {
  73. ifc_omdebugconfig *debugConfig;
  74. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmDebugConfig, (void**)&debugConfig)))
  75. {
  76. debugConfig->EnableMenuFilter(!checked);
  77. debugConfig->Release();
  78. }
  79. browserManager->Release();
  80. }
  81. }
  82. static void OptionsDebug_OnShowError(HWND hwnd)
  83. {
  84. HWND hControl = GetDlgItem(hwnd, IDC_SHOWERROR);
  85. if (NULL == hControl) return;
  86. HWND hParent = GetParent(hwnd);
  87. if (NULL == hParent) return;
  88. BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));
  89. obj_ombrowser *browserManager;
  90. if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  91. {
  92. ifc_omdebugconfig *debugConfig;
  93. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmDebugConfig, (void**)&debugConfig)))
  94. {
  95. debugConfig->EnableScriptError(checked);
  96. debugConfig->Release();
  97. }
  98. browserManager->Release();
  99. }
  100. }
  101. static void OptionsDebug_OnShowDebugger(HWND hwnd)
  102. {
  103. HWND hControl = GetDlgItem(hwnd, IDC_SHOWDEBUGGER);
  104. if (NULL == hControl) return;
  105. HWND hParent = GetParent(hwnd);
  106. if (NULL == hParent) return;
  107. BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));
  108. obj_ombrowser *browserManager;
  109. if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
  110. {
  111. ifc_omdebugconfig *debugConfig;
  112. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmDebugConfig, (void**)&debugConfig)))
  113. {
  114. debugConfig->EnableScriptDebugger(checked);
  115. debugConfig->Release();
  116. }
  117. browserManager->Release();
  118. }
  119. }
  120. static void OptionsDebug_OnConfigChanged(HWND hwnd, BOMCONFIGCHANGED *configData)
  121. {
  122. if (NULL == configData || NULL == configData->configUid ||
  123. FALSE == IsEqualIID(IFC_OmDebugConfig, *configData->configUid))
  124. {
  125. return;
  126. }
  127. switch(configData->valueId)
  128. {
  129. case CFGID_DEBUG_FILTERMENU: OptionsDebug_UpdateFilterMenu(hwnd, BOOL2HRESULT(configData->value)); break;
  130. case CFGID_DEBUG_SCRIPTERROR: OptionsDebug_UpdateShowError(hwnd, BOOL2HRESULT(configData->value)); break;
  131. case CFGID_DEBUG_SCRIPTDEBUGGER: OptionsDebug_UpdateShowDebugger(hwnd, BOOL2HRESULT(configData->value)); break;
  132. }
  133. }
  134. static void OptionsDebug_OnCommand(HWND hwnd, INT commandId, INT eventId, HWND hControl)
  135. {
  136. switch(commandId)
  137. {
  138. case IDC_FILTERMENU:
  139. if (BN_CLICKED == eventId)
  140. OptionsDebug_OnFilterMenu(hwnd);
  141. break;
  142. case IDC_SHOWERROR:
  143. if (BN_CLICKED == eventId)
  144. OptionsDebug_OnShowError(hwnd);
  145. break;
  146. case IDC_SHOWDEBUGGER:
  147. if (BN_CLICKED == eventId)
  148. OptionsDebug_OnShowDebugger(hwnd);
  149. break;
  150. }
  151. }
  152. static INT_PTR CALLBACK OptionsDebug_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  153. {
  154. switch(uMsg)
  155. {
  156. case WM_INITDIALOG: return OptionsDebug_OnInitDialog(hwnd, (HWND)wParam, lParam);
  157. case WM_DESTROY: OptionsDebug_OnDestroy(hwnd); return 0;
  158. case WM_COMMAND: OptionsDebug_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); return TRUE;
  159. case BOM_CONFIGCHANGED: OptionsDebug_OnConfigChanged(hwnd, (BOMCONFIGCHANGED*)lParam); return TRUE;
  160. }
  161. return 0;
  162. }