| OLD | NEW |
| (Empty) |
| 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 | |
| 4 * | |
| 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/ | |
| 9 * | |
| 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 | |
| 13 * License. | |
| 14 * | |
| 15 * The Original Code is mozilla.org code. | |
| 16 * | |
| 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. | |
| 21 * | |
| 22 * Contributor(s): | |
| 23 * | |
| 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. | |
| 35 * | |
| 36 * ***** END LICENSE BLOCK ***** */ | |
| 37 | |
| 38 #include "xp.h" | |
| 39 #include <windowsx.h> | |
| 40 | |
| 41 #include "resource.h" | |
| 42 #include "loggerw.h" | |
| 43 #include "profilew.h" | |
| 44 | |
| 45 extern HINSTANCE hInst; | |
| 46 extern char * ActionName[]; | |
| 47 extern char szAppName[]; | |
| 48 | |
| 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); | |
| 53 | |
| 54 static void onOptions(HWND hWnd, Logger * logger) | |
| 55 { | |
| 56 if(!logger) | |
| 57 return; | |
| 58 | |
| 59 PROPSHEETPAGE psp[4]; | |
| 60 | |
| 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); | |
| 65 psp[0].pszIcon = 0; | |
| 66 psp[0].pfnDlgProc = GeneralPageProc; | |
| 67 psp[0].pszTitle = 0; | |
| 68 psp[0].lParam = (LPARAM)logger; | |
| 69 psp[0].pfnCallback = NULL; | |
| 70 | |
| 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); | |
| 75 psp[1].pszIcon = 0; | |
| 76 psp[1].pfnDlgProc = LogPageProc; | |
| 77 psp[1].pszTitle = 0; | |
| 78 psp[1].lParam = (LPARAM)logger; | |
| 79 psp[1].pfnCallback = NULL; | |
| 80 | |
| 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); | |
| 85 psp[2].pszIcon = 0; | |
| 86 psp[2].pfnDlgProc = FilterPageProc; | |
| 87 psp[2].pszTitle = 0; | |
| 88 psp[2].lParam = (LPARAM)logger; | |
| 89 psp[2].pfnCallback = NULL; | |
| 90 | |
| 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); | |
| 95 psp[3].pszIcon = 0; | |
| 96 psp[3].pfnDlgProc = AdvancedPageProc; | |
| 97 psp[3].pszTitle = 0; | |
| 98 psp[3].lParam = (LPARAM)logger; | |
| 99 psp[3].pfnCallback = NULL; | |
| 100 | |
| 101 PROPSHEETHEADER psh; | |
| 102 psh.dwSize = sizeof(PROPSHEETHEADER); | |
| 103 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW; | |
| 104 psh.hwndParent = hWnd; | |
| 105 psh.hInstance = hInst; | |
| 106 psh.pszIcon = 0; | |
| 107 psh.pszCaption = "Settings"; | |
| 108 psh.nPages = sizeof(psp) / sizeof(psp[0]); | |
| 109 psh.nStartPage = 0; | |
| 110 psh.ppsp = psp; | |
| 111 psh.pfnCallback = NULL; | |
| 112 | |
| 113 logger->bSaveSettings = FALSE; | |
| 114 | |
| 115 int rv = PropertySheet(&psh); | |
| 116 if(rv == -1) | |
| 117 return; | |
| 118 | |
| 119 if(logger->bSaveSettings) | |
| 120 { | |
| 121 ProfileWin profile; | |
| 122 | |
| 123 if(hWnd != NULL) | |
| 124 { | |
| 125 RECT rc; | |
| 126 if(GetWindowRect(hWnd, &rc)) | |
| 127 profile.setSizeAndPosition(rc.right - rc.left, rc.bottom - rc.top, rc.le
ft, rc.top); | |
| 128 } | |
| 129 | |
| 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); | |
| 136 | |
| 137 for(int i = 1; i < TOTAL_NUMBER_OF_API_CALLS; i++) | |
| 138 profile.setBool(ActionName[i], !logger->bMutedCalls[i]); | |
| 139 | |
| 140 SetWindowPos(hWnd, logger->bOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0,0,0,0,S
WP_NOMOVE|SWP_NOSIZE); | |
| 141 } | |
| 142 | |
| 143 logger->bSaveSettings = FALSE; | |
| 144 } | |
| 145 | |
| 146 static void onCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) | |
| 147 { | |
| 148 LoggerWin * logger = (LoggerWin *)GetWindowLong(hWnd, DWL_USER); | |
| 149 switch (id) | |
| 150 { | |
| 151 case IDC_CHECK_MUTE: | |
| 152 if(logger) | |
| 153 logger->bMutedAll = (BST_CHECKED == IsDlgButtonChecked(hWnd, IDC_CHECK_M
UTE)); | |
| 154 break; | |
| 155 case IDC_BUTTON_OPTIONS: | |
| 156 onOptions(hWnd, logger); | |
| 157 break; | |
| 158 case IDC_BUTTON_CLEAR: | |
| 159 if(logger) | |
| 160 logger->onClear(); | |
| 161 break; | |
| 162 default: | |
| 163 break; | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 static BOOL onInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam) | |
| 168 { | |
| 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); | |
| 174 | |
| 175 if(logger) | |
| 176 { | |
| 177 CheckDlgButton(hWnd, IDC_CHECK_MUTE, logger->bMutedAll ? BST_CHECKED : BST_U
NCHECKED); | |
| 178 if(logger->width && logger->height) | |
| 179 SetWindowPos(hWnd, NULL, logger->x, logger->y, logger->width, logger->heig
ht, SWP_NOZORDER); | |
| 180 | |
| 181 SetWindowPos(hWnd, logger->bOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0,0,0,0,
SWP_NOMOVE | SWP_NOSIZE); | |
| 182 } | |
| 183 return TRUE; | |
| 184 } | |
| 185 | |
| 186 static void onDestroy(HWND hWnd) | |
| 187 { | |
| 188 LoggerWin * logger = (LoggerWin *)GetWindowLong(hWnd, DWL_USER); | |
| 189 if(logger) | |
| 190 logger->onDestroyWindow(); | |
| 191 } | |
| 192 | |
| 193 static void onSize(HWND hWnd, UINT state, int cx, int cy) | |
| 194 { | |
| 195 long bu = GetDialogBaseUnits(); | |
| 196 int bux = LOWORD(bu); | |
| 197 int buy = HIWORD(bu); | |
| 198 int factorx = bux/4; | |
| 199 int factory = buy/8; | |
| 200 | |
| 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; | |
| 207 | |
| 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); | |
| 213 | |
| 214 RECT rcMain; | |
| 215 GetClientRect(hWnd, &rcMain); | |
| 216 | |
| 217 int width = rcMain.right - rcMain.left; | |
| 218 int height = rcMain.bottom - rcMain.top; | |
| 219 | |
| 220 RECT rcButtonOptions; | |
| 221 GetWindowRect(hWndButtonOptions, &rcButtonOptions); | |
| 222 SetWindowPos(hWndButtonOptions, NULL, | |
| 223 width - marginLeft - rcButtonOptions.right + rcButtonOptions.left
, | |
| 224 height - rcButtonOptions.bottom + rcButtonOptions.top - marginBot
tom, | |
| 225 0, 0, SWP_NOZORDER | SWP_NOSIZE); | |
| 226 | |
| 227 RECT rcClear; | |
| 228 GetWindowRect(hWndClear, &rcClear); | |
| 229 SetWindowPos(hWndClear, NULL, | |
| 230 width - marginLeft - rcClear.right + rcClear.left - rcButtonOptio
ns.right + rcButtonOptions.left - spaceHor, | |
| 231 height - rcClear.bottom + rcClear.top - marginBottom, | |
| 232 0, 0, SWP_NOZORDER | SWP_NOSIZE); | |
| 233 | |
| 234 RECT rcCheckMute; | |
| 235 GetWindowRect(hWndCheckMute, &rcCheckMute); | |
| 236 SetWindowPos(hWndCheckMute, NULL, | |
| 237 marginLeft, | |
| 238 height - rcCheckMute.bottom + rcCheckMute.top - marginBottom, | |
| 239 0, 0, SWP_NOZORDER | SWP_NOSIZE); | |
| 240 | |
| 241 RECT rcCheckOntop; | |
| 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); | |
| 247 | |
| 248 SetWindowPos(hWndOutput, NULL, | |
| 249 0, 0, | |
| 250 width, | |
| 251 height - rcButtonOptions.bottom + rcButtonOptions.top - marginBot
tom - marginTop - spaceVer, | |
| 252 SWP_NOZORDER | SWP_NOMOVE); | |
| 253 | |
| 254 // somehow the Clear button doesn't redraw itself well, so force it | |
| 255 InvalidateRect(hWndClear, NULL, TRUE); | |
| 256 UpdateWindow(hWndClear); | |
| 257 } | |
| 258 | |
| 259 BOOL CALLBACK MainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) | |
| 260 { | |
| 261 switch(msg) | |
| 262 { | |
| 263 case WM_INITDIALOG: | |
| 264 return (BOOL)HANDLE_WM_INITDIALOG(hWnd, wParam, lParam, onInitDialog); | |
| 265 case WM_COMMAND: | |
| 266 HANDLE_WM_COMMAND(hWnd, wParam, lParam, onCommand); | |
| 267 break; | |
| 268 case WM_CLOSE: | |
| 269 DestroyWindow(hWnd); | |
| 270 break; | |
| 271 case WM_DESTROY: | |
| 272 HANDLE_WM_DESTROY(hWnd, wParam, lParam, onDestroy); | |
| 273 break; | |
| 274 case WM_SIZE: | |
| 275 HANDLE_WM_SIZE(hWnd, wParam, lParam, onSize); | |
| 276 break; | |
| 277 | |
| 278 default: | |
| 279 return FALSE; | |
| 280 } | |
| 281 return TRUE; | |
| 282 } | |
| 283 | |
| 284 // This is exported function which allows to access Settings GUI from other appl
ications | |
| 285 void WINAPI SPY_Setup() | |
| 286 { | |
| 287 LoggerWin logger; | |
| 288 ProfileWin profile; | |
| 289 | |
| 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.szFi
le)); | |
| 296 | |
| 297 for(int i = 1; i < TOTAL_NUMBER_OF_API_CALLS; i++) | |
| 298 { | |
| 299 BOOL selected = TRUE; | |
| 300 if(profile.getBool(ActionName[i], &selected)) | |
| 301 logger.bMutedCalls[i] = !selected; | |
| 302 } | |
| 303 | |
| 304 onOptions(NULL, &logger); | |
| 305 } | |
| OLD | NEW |