1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
45 extern HINSTANCE hInst
;
46 extern char * ActionName
[];
47 extern char szAppName
[];
49 BOOL CALLBACK
GeneralPageProc(HWND
, UINT
, WPARAM
, LPARAM
);
50 BOOL CALLBACK
LogPageProc(HWND
, UINT
, WPARAM
, LPARAM
);
51 BOOL CALLBACK
FilterPageProc(HWND
, UINT
, WPARAM
, LPARAM
);
52 BOOL CALLBACK
AdvancedPageProc(HWND
, UINT
, WPARAM
, LPARAM
);
54 static void onOptions(HWND hWnd
, Logger
* logger
)
61 psp
[0].dwSize
= sizeof(psp
[0]);
62 psp
[0].dwFlags
= PSP_DEFAULT
;
63 psp
[0].hInstance
= hInst
;
64 psp
[0].pszTemplate
= MAKEINTRESOURCE(IDD_PAGE_GENERAL
);
66 psp
[0].pfnDlgProc
= GeneralPageProc
;
68 psp
[0].lParam
= (LPARAM
)logger
;
69 psp
[0].pfnCallback
= NULL
;
71 psp
[1].dwSize
= sizeof(psp
[1]);
72 psp
[1].dwFlags
= PSP_DEFAULT
;
73 psp
[1].hInstance
= hInst
;
74 psp
[1].pszTemplate
= MAKEINTRESOURCE(IDD_PAGE_LOG
);
76 psp
[1].pfnDlgProc
= LogPageProc
;
78 psp
[1].lParam
= (LPARAM
)logger
;
79 psp
[1].pfnCallback
= NULL
;
81 psp
[2].dwSize
= sizeof(psp
[2]);
82 psp
[2].dwFlags
= PSP_DEFAULT
;
83 psp
[2].hInstance
= hInst
;
84 psp
[2].pszTemplate
= MAKEINTRESOURCE(IDD_PAGE_FILTER
);
86 psp
[2].pfnDlgProc
= FilterPageProc
;
88 psp
[2].lParam
= (LPARAM
)logger
;
89 psp
[2].pfnCallback
= NULL
;
91 psp
[3].dwSize
= sizeof(psp
[3]);
92 psp
[3].dwFlags
= PSP_DEFAULT
;
93 psp
[3].hInstance
= hInst
;
94 psp
[3].pszTemplate
= MAKEINTRESOURCE(IDD_PAGE_ADVANCED
);
96 psp
[3].pfnDlgProc
= AdvancedPageProc
;
98 psp
[3].lParam
= (LPARAM
)logger
;
99 psp
[3].pfnCallback
= NULL
;
102 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
103 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
104 psh
.hwndParent
= hWnd
;
105 psh
.hInstance
= hInst
;
107 psh
.pszCaption
= "Settings";
108 psh
.nPages
= sizeof(psp
) / sizeof(psp
[0]);
111 psh
.pfnCallback
= NULL
;
113 logger
->bSaveSettings
= FALSE
;
115 int rv
= PropertySheet(&psh
);
119 if(logger
->bSaveSettings
)
126 if(GetWindowRect(hWnd
, &rc
))
127 profile
.setSizeAndPosition(rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, rc
.left
, rc
.top
);
130 profile
.setBool(NPSPY_REG_KEY_ONTOP
, logger
->bOnTop
);
131 profile
.setBool(NPSPY_REG_KEY_LOGTOWINDOW
, logger
->bToWindow
);
132 profile
.setBool(NPSPY_REG_KEY_LOGTOCONSOLE
, logger
->bToConsole
);
133 profile
.setBool(NPSPY_REG_KEY_LOGTOFILE
, logger
->bToFile
);
134 profile
.setBool(NPSPY_REG_KEY_SPALID
, logger
->bSPALID
);
135 profile
.setString(NPSPY_REG_KEY_LOGFILENAME
, logger
->szFile
);
137 for(int i
= 1; i
< TOTAL_NUMBER_OF_API_CALLS
; i
++)
138 profile
.setBool(ActionName
[i
], !logger
->bMutedCalls
[i
]);
140 SetWindowPos(hWnd
, logger
->bOnTop
? HWND_TOPMOST
: HWND_NOTOPMOST
, 0,0,0,0,SWP_NOMOVE
|SWP_NOSIZE
);
143 logger
->bSaveSettings
= FALSE
;
146 static void onCommand(HWND hWnd
, int id
, HWND hWndCtl
, UINT codeNotify
)
148 LoggerWin
* logger
= (LoggerWin
*)GetWindowLong(hWnd
, DWL_USER
);
153 logger
->bMutedAll
= (BST_CHECKED
== IsDlgButtonChecked(hWnd
, IDC_CHECK_MUTE
));
155 case IDC_BUTTON_OPTIONS
:
156 onOptions(hWnd
, logger
);
158 case IDC_BUTTON_CLEAR
:
167 static BOOL
onInitDialog(HWND hWnd
, HWND hWndFocus
, LPARAM lParam
)
169 LoggerWin
* logger
= (LoggerWin
*)lParam
;
170 SetWindowLong(hWnd
, DWL_USER
, (long)logger
);
171 SetWindowText(hWnd
, szAppName
);
172 HFONT hFont
= GetStockFont(ANSI_FIXED_FONT
);
173 SetWindowFont(GetDlgItem(hWnd
, IDC_MAIN_OUTPUT
), hFont
, FALSE
);
177 CheckDlgButton(hWnd
, IDC_CHECK_MUTE
, logger
->bMutedAll
? BST_CHECKED
: BST_UNCHECKED
);
178 if(logger
->width
&& logger
->height
)
179 SetWindowPos(hWnd
, NULL
, logger
->x
, logger
->y
, logger
->width
, logger
->height
, SWP_NOZORDER
);
181 SetWindowPos(hWnd
, logger
->bOnTop
? HWND_TOPMOST
: HWND_NOTOPMOST
, 0,0,0,0, SWP_NOMOVE
| SWP_NOSIZE
);
186 static void onDestroy(HWND hWnd
)
188 LoggerWin
* logger
= (LoggerWin
*)GetWindowLong(hWnd
, DWL_USER
);
190 logger
->onDestroyWindow();
193 static void onSize(HWND hWnd
, UINT state
, int cx
, int cy
)
195 long bu
= GetDialogBaseUnits();
196 int bux
= LOWORD(bu
);
197 int buy
= HIWORD(bu
);
201 int marginLeft
= 7 * factorx
;
202 int marginRight
= 0 * factorx
;
203 int marginTop
= 0 * factory
;
204 int marginBottom
= 7 * factory
;
205 int spaceHor
= 4 * factorx
;
206 int spaceVer
= 7 * factory
;
208 HWND hWndOutput
= GetDlgItem(hWnd
, IDC_MAIN_OUTPUT
);
209 HWND hWndCheckMute
= GetDlgItem(hWnd
, IDC_CHECK_MUTE
);
210 HWND hWndCheckOntop
= GetDlgItem(hWnd
, IDC_CHECK_ONTOP
);
211 HWND hWndButtonOptions
= GetDlgItem(hWnd
, IDC_BUTTON_OPTIONS
);
212 HWND hWndClear
= GetDlgItem(hWnd
, IDC_BUTTON_CLEAR
);
215 GetClientRect(hWnd
, &rcMain
);
217 int width
= rcMain
.right
- rcMain
.left
;
218 int height
= rcMain
.bottom
- rcMain
.top
;
220 RECT rcButtonOptions
;
221 GetWindowRect(hWndButtonOptions
, &rcButtonOptions
);
222 SetWindowPos(hWndButtonOptions
, NULL
,
223 width
- marginLeft
- rcButtonOptions
.right
+ rcButtonOptions
.left
,
224 height
- rcButtonOptions
.bottom
+ rcButtonOptions
.top
- marginBottom
,
225 0, 0, SWP_NOZORDER
| SWP_NOSIZE
);
228 GetWindowRect(hWndClear
, &rcClear
);
229 SetWindowPos(hWndClear
, NULL
,
230 width
- marginLeft
- rcClear
.right
+ rcClear
.left
- rcButtonOptions
.right
+ rcButtonOptions
.left
- spaceHor
,
231 height
- rcClear
.bottom
+ rcClear
.top
- marginBottom
,
232 0, 0, SWP_NOZORDER
| SWP_NOSIZE
);
235 GetWindowRect(hWndCheckMute
, &rcCheckMute
);
236 SetWindowPos(hWndCheckMute
, NULL
,
238 height
- rcCheckMute
.bottom
+ rcCheckMute
.top
- marginBottom
,
239 0, 0, SWP_NOZORDER
| SWP_NOSIZE
);
242 GetWindowRect(hWndCheckOntop
, &rcCheckOntop
);
243 SetWindowPos(hWndCheckOntop
, NULL
,
244 marginLeft
+ rcCheckMute
.right
- rcCheckMute
.left
+ spaceHor
,
245 height
- rcCheckOntop
.bottom
+ rcCheckOntop
.top
- marginBottom
,
246 0, 0, SWP_NOZORDER
| SWP_NOSIZE
);
248 SetWindowPos(hWndOutput
, NULL
,
251 height
- rcButtonOptions
.bottom
+ rcButtonOptions
.top
- marginBottom
- marginTop
- spaceVer
,
252 SWP_NOZORDER
| SWP_NOMOVE
);
254 // somehow the Clear button doesn't redraw itself well, so force it
255 InvalidateRect(hWndClear
, NULL
, TRUE
);
256 UpdateWindow(hWndClear
);
259 BOOL CALLBACK
MainDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
264 return (BOOL
)HANDLE_WM_INITDIALOG(hWnd
, wParam
, lParam
, onInitDialog
);
266 HANDLE_WM_COMMAND(hWnd
, wParam
, lParam
, onCommand
);
272 HANDLE_WM_DESTROY(hWnd
, wParam
, lParam
, onDestroy
);
275 HANDLE_WM_SIZE(hWnd
, wParam
, lParam
, onSize
);
284 // This is exported function which allows to access Settings GUI from other applications
285 void WINAPI
SPY_Setup()
290 profile
.getBool(NPSPY_REG_KEY_ONTOP
, &logger
.bOnTop
);
291 profile
.getBool(NPSPY_REG_KEY_LOGTOWINDOW
, &logger
.bToWindow
);
292 profile
.getBool(NPSPY_REG_KEY_LOGTOCONSOLE
, &logger
.bToConsole
);
293 profile
.getBool(NPSPY_REG_KEY_LOGTOFILE
, &logger
.bToFile
);
294 profile
.getBool(NPSPY_REG_KEY_SPALID
, &logger
.bSPALID
);
295 profile
.getString(NPSPY_REG_KEY_LOGFILENAME
, logger
.szFile
, strlen(logger
.szFile
));
297 for(int i
= 1; i
< TOTAL_NUMBER_OF_API_CALLS
; i
++)
299 BOOL selected
= TRUE
;
300 if(profile
.getBool(ActionName
[i
], &selected
))
301 logger
.bMutedCalls
[i
] = !selected
;
304 onOptions(NULL
, &logger
);