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 ***** */
44 #include "actionnames.h"
46 extern HINSTANCE hInst
;
47 static char szClassName
[] = "NPSpyWindowClass";
49 BOOL CALLBACK
MainDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
50 BOOL CALLBACK
PauseDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
52 LoggerWin::LoggerWin() : Logger(),
62 LoggerWin::~LoggerWin()
66 BOOL
LoggerWin::platformInit()
70 wc
.lpfnWndProc
= DefDlgProc
;
72 wc
.cbWndExtra
= DLGWINDOWEXTRA
;
74 wc
.hIcon
= LoadIcon(hInst
, MAKEINTRESOURCE(IDI_ICON_APP
));
75 wc
.hCursor
= LoadCursor(0, IDC_ARROW
);
76 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
77 wc
.lpszMenuName
= NULL
;
78 wc
.lpszClassName
= szClassName
;
80 if(!RegisterClass(&wc
))
86 profile
.getBool(NPSPY_REG_KEY_ONTOP
, &bOnTop
);
87 profile
.getBool(NPSPY_REG_KEY_LOGTOWINDOW
, &bToWindow
);
88 profile
.getBool(NPSPY_REG_KEY_LOGTOCONSOLE
, &bToConsole
);
89 profile
.getBool(NPSPY_REG_KEY_LOGTOFILE
, &bToFile
);
90 profile
.getBool(NPSPY_REG_KEY_SPALID
, &bSPALID
);
91 profile
.getString(NPSPY_REG_KEY_LOGFILENAME
, szFile
, strlen(szFile
));
93 for(int i
= 1; i
< TOTAL_NUMBER_OF_API_CALLS
; i
++)
96 if(profile
.getBool(ActionName
[i
], &selected
))
97 bMutedCalls
[i
] = !selected
;
100 if(!profile
.getSizeAndPosition(&width
, &height
, &x
, &y
))
108 hWnd
= CreateDialogParam(hInst
, MAKEINTRESOURCE(IDD_DIALOG_MAIN
), GetDesktopWindow(), (DLGPROC
)MainDlgProc
, (LPARAM
)this);
111 UnregisterClass(szClassName
, hInst
);
116 SetWindowPos(hWnd
, bOnTop
? HWND_TOPMOST
: HWND_NOTOPMOST
, 0,0,0,0, SWP_NOMOVE
| SWP_NOSIZE
);
121 void LoggerWin::platformShut()
125 char szLog
[] = "--- GOING AWAY... PRESS SPACE BAR TO CONTINUE ---";
126 HWND hWndOutput
= GetDlgItem(hWnd
, IDC_MAIN_OUTPUT
);
127 ListBox_AddString(hWndOutput
, "");
128 ListBox_AddString(hWndOutput
, szLog
);
129 int count
= ListBox_GetCount(hWndOutput
);
130 ListBox_SetCaretIndex(hWndOutput
, count
- 1);
131 UpdateWindow(hWndOutput
);
133 DialogBox(hInst
, MAKEINTRESOURCE(IDD_DIALOG_PAUSE
), hWnd
, (DLGPROC
)PauseDlgProc
);
138 if(GetWindowRect(hWnd
, &rc
))
139 profile
.setSizeAndPosition(rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, rc
.left
, rc
.top
);
145 UnregisterClass(szClassName
, hInst
);
148 void LoggerWin::onDestroyWindow()
153 void LoggerWin::dumpStringToMainWindow(char * string
)
155 // listboxes don't want <CR> and <LF> so cut them off if any. The order is important.
156 char * p
= strrchr(string
, '\n');
160 p
= strrchr(string
, '\r');
164 HWND hWndOutput
= GetDlgItem(hWnd
, IDC_MAIN_OUTPUT
);
165 ListBox_AddString(hWndOutput
, string
);
166 int count
= ListBox_GetCount(hWndOutput
);
168 ListBox_ResetContent(hWndOutput
);
169 ListBox_SetCaretIndex(hWndOutput
, count
- 1);
170 UpdateWindow(hWndOutput
);
173 void LoggerWin::onClear()
175 HWND hWndOutput
= GetDlgItem(hWnd
, IDC_MAIN_OUTPUT
);
176 ListBox_ResetContent(hWndOutput
);
177 UpdateWindow(hWndOutput
);
182 LoggerWin
* res
= new LoggerWin();
186 void DeleteLogger(Logger
* logger
)