aboutsummaryrefslogtreecommitdiff
path: root/Src/omBrowser/optionsDebug.cpp
blob: 2f7984935e30bea3d942779ab172a072fa37d3d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "main.h"
#include "./options.h"
#include "./resource.h"

#include "./obj_ombrowser.h"
#include "./ifc_omconfig.h"
#include "./ifc_omdebugconfig.h"

#include <windows.h>
#include <commctrl.h>
#include <shlwapi.h>
#include <strsafe.h>


#define INVERTHRESULT(__result)\
	((S_OK == (__result)) ? S_FALSE : ((S_FALSE == (__result)) ? S_OK : (__result)))

#define BOOL2HRESULT(__result)\
	((FALSE != (__result)) ? S_OK : S_FALSE)

static INT_PTR CALLBACK OptionsDebug_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);


HWND CALLBACK OptionsDebug_CreatePage(HWND hParent, UINT style)
{
	if (0 == (BOSTYLE_SHOWDEBUG & style)) 
		return NULL;

	return Plugin_CreateDialogParam(MAKEINTRESOURCE(IDD_OPTIONS_DEBUG), hParent, OptionsDebug_DialogProc, 0L);
}

static void OptionsDebug_UpdateFilterMenu(HWND hwnd, HRESULT enable)
{
	Options_SetCheckbox(hwnd, IDC_FILTERMENU, INVERTHRESULT(enable));
}

static void OptionsDebug_UpdateShowError(HWND hwnd, HRESULT enable)
{
	Options_SetCheckbox(hwnd, IDC_SHOWERROR, enable);
}

static void OptionsDebug_UpdateShowDebugger(HWND hwnd, HRESULT enable)
{
	Options_SetCheckbox(hwnd, IDC_SHOWDEBUGGER, enable);
}


static INT_PTR OptionsDebug_OnInitDialog(HWND hwnd, HWND hFocus, LPARAM param)
{	
	WCHAR szBuffer[512] = {0};
	Plugin_LoadString(IDS_OPTIONS_DEBUG, szBuffer, ARRAYSIZE(szBuffer));
	SetWindowText(hwnd, szBuffer);

	HWND hParent = GetParent(hwnd);

	obj_ombrowser *browserManager;
	if (FALSE == SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
		browserManager = NULL;

	ifc_omdebugconfig *debugConfig;

	if (NULL != browserManager && 
		SUCCEEDED(browserManager->GetConfig(&IFC_OmDebugConfig, (void**)&debugConfig)))
	{
		OptionsDebug_UpdateFilterMenu(hwnd, debugConfig->GetMenuFilterEnabled());
		OptionsDebug_UpdateShowError(hwnd, debugConfig->GetScriptErrorEnabled());
		OptionsDebug_UpdateShowDebugger(hwnd, debugConfig->GetScriptDebuggerEnabled());
		debugConfig->Release();
	}
	else
	{
		OptionsDebug_UpdateFilterMenu(hwnd, E_FAIL);
		OptionsDebug_UpdateShowError(hwnd, E_FAIL);
		OptionsDebug_UpdateShowDebugger(hwnd, E_FAIL);
	}

	return 0;
}

static void OptionsDebug_OnDestroy(HWND hwnd)
{
}

static void OptionsDebug_OnFilterMenu(HWND hwnd)
{
	HWND hControl = GetDlgItem(hwnd, IDC_FILTERMENU);
	if (NULL == hControl) return;

	HWND hParent = GetParent(hwnd);
	if (NULL == hParent) return;

	BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));

	obj_ombrowser *browserManager;
	if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
	{
		ifc_omdebugconfig *debugConfig;
		if (SUCCEEDED(browserManager->GetConfig(&IFC_OmDebugConfig, (void**)&debugConfig)))
		{
			debugConfig->EnableMenuFilter(!checked);
			debugConfig->Release();
		}
		browserManager->Release();
	}
}

static void OptionsDebug_OnShowError(HWND hwnd)
{
	HWND hControl = GetDlgItem(hwnd, IDC_SHOWERROR);
	if (NULL == hControl) return;

	HWND hParent = GetParent(hwnd);
	if (NULL == hParent) return;

	BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));

	obj_ombrowser *browserManager;
	if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
	{
		ifc_omdebugconfig *debugConfig;
		if (SUCCEEDED(browserManager->GetConfig(&IFC_OmDebugConfig, (void**)&debugConfig)))
		{
			debugConfig->EnableScriptError(checked);
			debugConfig->Release();
		}
		browserManager->Release();
	}
}

static void OptionsDebug_OnShowDebugger(HWND hwnd)
{
	HWND hControl = GetDlgItem(hwnd, IDC_SHOWDEBUGGER);
	if (NULL == hControl) return;

	HWND hParent = GetParent(hwnd);
	if (NULL == hParent) return;

	BOOL checked = (BST_CHECKED == (UINT)SendMessage(hControl, BM_GETCHECK, 0, 0L));

	obj_ombrowser *browserManager;
	if (FALSE != SendMessage(hParent, BOM_GETBROWSER, 0, (LPARAM)&browserManager))
	{
		ifc_omdebugconfig *debugConfig;
		if (SUCCEEDED(browserManager->GetConfig(&IFC_OmDebugConfig, (void**)&debugConfig)))
		{
			debugConfig->EnableScriptDebugger(checked);
			debugConfig->Release();
		}
		browserManager->Release();
	}
}

static void OptionsDebug_OnConfigChanged(HWND hwnd, BOMCONFIGCHANGED *configData)
{
	if (NULL == configData || NULL == configData->configUid ||
		FALSE == IsEqualIID(IFC_OmDebugConfig, *configData->configUid))
	{
		return;
	}

	
	switch(configData->valueId)
	{
		case CFGID_DEBUG_FILTERMENU:			OptionsDebug_UpdateFilterMenu(hwnd, BOOL2HRESULT(configData->value)); break;
		case CFGID_DEBUG_SCRIPTERROR:		OptionsDebug_UpdateShowError(hwnd, BOOL2HRESULT(configData->value)); break;
		case CFGID_DEBUG_SCRIPTDEBUGGER:	OptionsDebug_UpdateShowDebugger(hwnd, BOOL2HRESULT(configData->value)); break;
	}
	
}
static void OptionsDebug_OnCommand(HWND hwnd, INT commandId, INT eventId, HWND hControl)
{
	switch(commandId)
	{		
		case IDC_FILTERMENU:	
			if (BN_CLICKED == eventId) 
				OptionsDebug_OnFilterMenu(hwnd); 
			break;
		case IDC_SHOWERROR:	
			if (BN_CLICKED == eventId) 
				OptionsDebug_OnShowError(hwnd); 
			break;
		case IDC_SHOWDEBUGGER:
			if (BN_CLICKED == eventId) 
				OptionsDebug_OnShowDebugger(hwnd); 
			break;
	}

}



static INT_PTR CALLBACK OptionsDebug_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
		case WM_INITDIALOG:			return OptionsDebug_OnInitDialog(hwnd, (HWND)wParam, lParam);
		case WM_DESTROY:				OptionsDebug_OnDestroy(hwnd); return 0;
		case WM_COMMAND:				OptionsDebug_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); return TRUE;
		
		case BOM_CONFIGCHANGED:		OptionsDebug_OnConfigChanged(hwnd, (BOMCONFIGCHANGED*)lParam); return TRUE;
	}
	return 0;
}