Bug 454376 add -lCrun -lCstd for Solaris OS_LIBS, r=bsmedberg
[wine-gecko.git] / modules / plugin / tools / spy / windows / loggerw.cpp
blob21cef673b3c123149638fc4957e3e931b6b3298d
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
13 * License.
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.
22 * Contributor(s):
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 ***** */
38 #include "xp.h"
39 #include "windowsx.h"
41 #include "resource.h"
42 #include "loggerw.h"
43 #include "profilew.h"
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(),
53 hWnd(NULL),
54 width(0),
55 height(0),
56 x(0),
57 y(0),
58 bSaveSettings(FALSE)
62 LoggerWin::~LoggerWin()
66 BOOL LoggerWin::platformInit()
68 WNDCLASS wc;
69 wc.style = 0;
70 wc.lpfnWndProc = DefDlgProc;
71 wc.cbClsExtra = 0;
72 wc.cbWndExtra = DLGWINDOWEXTRA;
73 wc.hInstance = hInst;
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))
81 return FALSE;
83 // restore prefs
84 ProfileWin profile;
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++)
95 BOOL selected = TRUE;
96 if(profile.getBool(ActionName[i], &selected))
97 bMutedCalls[i] = !selected;
100 if(!profile.getSizeAndPosition(&width, &height, &x, &y))
102 width = 0;
103 height = 0;
104 x = 0;
105 y = 0;
108 hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DIALOG_MAIN), GetDesktopWindow(), (DLGPROC)MainDlgProc, (LPARAM)this);
109 if(hWnd == NULL)
111 UnregisterClass(szClassName, hInst);
112 return FALSE;
115 if(bOnTop)
116 SetWindowPos(hWnd, bOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
118 return TRUE;
121 void LoggerWin::platformShut()
123 if(hWnd != NULL)
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);
135 ProfileWin profile;
137 RECT rc;
138 if(GetWindowRect(hWnd, &rc))
139 profile.setSizeAndPosition(rc.right - rc.left, rc.bottom - rc.top, rc.left, rc.top);
141 DestroyWindow(hWnd);
142 hWnd = NULL;
145 UnregisterClass(szClassName, hInst);
148 void LoggerWin::onDestroyWindow()
150 hWnd = NULL;
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');
157 if(p)
158 *p = '\0';
160 p = strrchr(string, '\r');
161 if(p)
162 *p = '\0';
164 HWND hWndOutput = GetDlgItem(hWnd, IDC_MAIN_OUTPUT);
165 ListBox_AddString(hWndOutput, string);
166 int count = ListBox_GetCount(hWndOutput);
167 if(count == 32767)
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);
180 Logger * NewLogger()
182 LoggerWin * res = new LoggerWin();
183 return res;
186 void DeleteLogger(Logger * logger)
188 if(logger)
189 delete logger;