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 bOnTop = false; // XXXMB
88 profile.getBool(NPSPY_REG_KEY_LOGTOWINDOW, &bToWindow);
89 profile.getBool(NPSPY_REG_KEY_LOGTOCONSOLE, &bToConsole);
90 profile.getBool(NPSPY_REG_KEY_LOGTOFILE, &bToFile);
91 profile.getBool(NPSPY_REG_KEY_SPALID, &bSPALID);
92 profile.getString(NPSPY_REG_KEY_LOGFILENAME, szFile, strlen(szFile));
94 for(int i = 1; i < TOTAL_NUMBER_OF_API_CALLS; i++)
97 if(profile.getBool(ActionName[i], &selected))
98 bMutedCalls[i] = !selected;
101 if(!profile.getSizeAndPosition(&width, &height, &x, &y))
109 hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DIALOG_MAIN), GetDesktopWindow(), (DLGPROC)MainDlgProc, (LPARAM)this);
112 UnregisterClass(szClassName, hInst);
117 SetWindowPos(hWnd, bOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
122 void LoggerWin::platformShut()
126 char szLog[] = "--- GOING AWAY... PRESS SPACE BAR TO CONTINUE ---";
127 HWND hWndOutput = GetDlgItem(hWnd, IDC_MAIN_OUTPUT);
128 ListBox_AddString(hWndOutput, "");
129 ListBox_AddString(hWndOutput, szLog);
130 int count = ListBox_GetCount(hWndOutput);
131 ListBox_SetCaretIndex(hWndOutput, count - 1);
132 UpdateWindow(hWndOutput);
134 DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_PAUSE), hWnd, (DLGPROC)PauseDlgProc);
139 if(GetWindowRect(hWnd, &rc))
140 profile.setSizeAndPosition(rc.right - rc.left, rc.bottom - rc.top, rc.left, rc.top);
146 UnregisterClass(szClassName, hInst);
149 void LoggerWin::onDestroyWindow()
154 void LoggerWin::dumpStringToMainWindow(const std::string& string)
156 const char* output = string.c_str();
157 std::string temp_string;
158 // listboxes don't want <CR> and <LF> so cut them off if any. The order is important.
159 size_t newline = string.find('\n');
160 if(newline != std::string::npos) {
161 // make copy of string since it might be a constant
162 temp_string = string;
164 char* p = strrchr(const_cast<char*>(temp_string.c_str()), '\n');
167 p = strrchr(const_cast<char*>(temp_string.c_str()), '\r');
170 output = temp_string.c_str();
173 HWND hWndOutput = GetDlgItem(hWnd, IDC_MAIN_OUTPUT);
174 ListBox_AddString(hWndOutput, output);
175 int count = ListBox_GetCount(hWndOutput);
177 ListBox_ResetContent(hWndOutput);
178 ListBox_SetCaretIndex(hWndOutput, count - 1);
179 UpdateWindow(hWndOutput);
182 void LoggerWin::onClear()
184 HWND hWndOutput = GetDlgItem(hWnd, IDC_MAIN_OUTPUT);
185 ListBox_ResetContent(hWndOutput);
186 UpdateWindow(hWndOutput);
191 LoggerWin * res = new LoggerWin();
195 void DeleteLogger(Logger * logger)