better service description. This text will be shown when the user configures the...
[privoxy.git] / w32log.c
1 const char w32log_rcs[] = "$Id: w32log.c,v 1.25.2.2 2002/09/25 15:23:10 oes Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/Attic/w32log.c,v $
5  *
6  * Purpose     :  Functions for creating and destroying the log window,
7  *                ouputting strings, processing messages and so on.
8  *
9  * Copyright   :  Written by and Copyright (C) 2001-2002 members of
10  *                the Privoxy team.  http://www.privoxy.org/
11  *
12  *                Written by and Copyright (C) 1999 Adam Lock
13  *                <locka@iol.ie>
14  *
15  *                This program is free software; you can redistribute it 
16  *                and/or modify it under the terms of the GNU General
17  *                Public License as published by the Free Software
18  *                Foundation; either version 2 of the License, or (at
19  *                your option) any later version.
20  *
21  *                This program is distributed in the hope that it will
22  *                be useful, but WITHOUT ANY WARRANTY; without even the
23  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
24  *                PARTICULAR PURPOSE.  See the GNU General Public
25  *                License for more details.
26  *
27  *                The GNU General Public License should be included with
28  *                this file.  If not, you can view it at
29  *                http://www.gnu.org/copyleft/gpl.html
30  *                or write to the Free Software Foundation, Inc., 59
31  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32  *
33  * Revisions   :
34  *    $Log: w32log.c,v $
35  *    Revision 1.25.2.2  2002/09/25 15:23:10  oes
36  *    Uncheck the "Show Privoxy Window" taskbar menu item when window gets minimized. Fixes bug #606804
37  *
38  *    Revision 1.25.2.1  2002/08/21 17:59:05  oes
39  *     - "Show Privoxy Window" now a toggle
40  *     - Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
41  *
42  *    Revision 1.25  2002/04/04 00:36:36  gliptak
43  *    always use pcre for matching
44  *
45  *    Revision 1.24  2002/03/31 17:19:00  jongfoster
46  *    Win32 only: Enabling STRICT to fix a VC++ compile warning.
47  *
48  *    Revision 1.23  2002/03/26 22:57:10  jongfoster
49  *    Web server name should begin www.
50  *
51  *    Revision 1.22  2002/03/24 12:48:23  jongfoster
52  *    Fixing doc links
53  *
54  *    Revision 1.21  2002/03/24 12:07:35  jongfoster
55  *    Consistern name for filters file
56  *
57  *    Revision 1.20  2002/03/24 12:03:47  jongfoster
58  *    Name change
59  *
60  *    Revision 1.19  2002/01/17 21:04:17  jongfoster
61  *    Replacing hard references to the URL of the config interface
62  *    with #defines from project.h
63  *
64  *    Revision 1.18  2001/11/30 23:37:24  jongfoster
65  *    Renaming the Win32 config file to config.txt - this is almost the
66  *    same as the corresponding UNIX name "config"
67  *
68  *    Revision 1.17  2001/11/16 00:46:31  jongfoster
69  *    Fixing compiler warnings
70  *
71  *    Revision 1.16  2001/08/01 19:58:12  jongfoster
72  *    Fixing documentation filenames in help menu, and making status
73  *    option work without needing the "Junkbuster Status.URL" file.
74  *
75  *    Revision 1.15  2001/07/30 22:08:36  jongfoster
76  *    Tidying up #defines:
77  *    - All feature #defines are now of the form FEATURE_xxx
78  *    - Permanently turned off WIN_GUI_EDIT
79  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
80  *
81  *    Revision 1.14  2001/07/29 18:47:05  jongfoster
82  *    Adding missing #include "loadcfg.h"
83  *
84  *    Revision 1.13  2001/07/19 19:15:14  haroon
85  *    - Added a FIXME for EditFile but didn't fix :-)
86  *
87  *    Revision 1.12  2001/07/13 14:04:59  oes
88  *    Removed all #ifdef PCRS
89  *
90  *    Revision 1.11  2001/06/07 23:08:12  jongfoster
91  *    Forward and ACL edit options removed.
92  *
93  *    Revision 1.10  2001/05/31 21:37:11  jongfoster
94  *    GUI changes to rename "permissions file" to "actions file".
95  *
96  *    Revision 1.9  2001/05/31 17:33:13  oes
97  *
98  *    CRLF -> LF
99  *
100  *    Revision 1.8  2001/05/29 09:50:24  jongfoster
101  *    Unified blocklist/imagelist/permissionslist.
102  *    File format is still under discussion, but the internal changes
103  *    are (mostly) done.
104  *
105  *    Also modified interceptor behaviour:
106  *    - We now intercept all URLs beginning with one of the following
107  *      prefixes (and *only* these prefixes):
108  *        * http://i.j.b/
109  *        * http://ijbswa.sf.net/config/
110  *        * http://ijbswa.sourceforge.net/config/
111  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
112  *    - Internal changes so that intercepted and fast redirect pages
113  *      are not replaced with an image.
114  *    - Interceptors now have the option to send a binary page direct
115  *      to the client. (i.e. ijb-send-banner uses this)
116  *    - Implemented show-url-info interceptor.  (Which is why I needed
117  *      the above interceptors changes - a typical URL is
118  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
119  *      The previous mechanism would not have intercepted that, and
120  *      if it had been intercepted then it then it would have replaced
121  *      it with an image.)
122  *
123  *    Revision 1.7  2001/05/26 01:26:34  jongfoster
124  *    New #define, WIN_GUI_EDIT, enables the (embryonic) Win32 GUI editor.
125  *    This #define cannot be set from ./configure - there's no point, it
126  *    doesn't work yet.  See feature request # 425722
127  *
128  *    Revision 1.6  2001/05/26 00:31:30  jongfoster
129  *    Fixing compiler warning about comparing signed/unsigned.
130  *
131  *    Revision 1.5  2001/05/26 00:28:36  jongfoster
132  *    Automatic reloading of config file.
133  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
134  *    Most of the global variables have been moved to a new
135  *    struct configuration_spec, accessed through csp->config->globalname
136  *    Most of the globals remaining are used by the Win32 GUI.
137  *
138  *    Revision 1.4  2001/05/22 18:56:28  oes
139  *    CRLF -> LF
140  *
141  *    Revision 1.3  2001/05/20 15:07:54  jongfoster
142  *    File is now ignored if _WIN_CONSOLE is defined.
143  *
144  *    Revision 1.2  2001/05/20 01:21:20  jongfoster
145  *    Version 2.9.4 checkin.
146  *    - Merged popupfile and cookiefile, and added control over PCRS
147  *      filtering, in new "permissionsfile".
148  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
149  *      file error you now get a message box (in the Win32 GUI) rather
150  *      than the program exiting with no explanation.
151  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
152  *      skipping.
153  *    - Removed tabs from "config"
154  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
155  *    - Bumped up version number.
156  *
157  *    Revision 1.1.1.1  2001/05/15 13:59:07  oes
158  *    Initial import of version 2.9.3 source tree
159  *
160  *
161  *********************************************************************/
162 \f
163
164 #include "config.h"
165
166 #include <assert.h>
167 #include <stdio.h>
168
169 #ifndef STRICT
170 #define STRICT
171 #endif
172 #include <windows.h>
173 #include <richedit.h>
174
175 #include "project.h"
176 #include "w32log.h"
177 #include "w32taskbar.h"
178 #include "win32.h"
179 #include "w32res.h"
180 #include "jcc.h"
181 #include "miscutil.h"
182 #include "errlog.h"
183 #include "loadcfg.h"
184
185 const char w32res_h_rcs[] = W32RES_H_VERSION;
186
187 #ifdef __MINGW32__
188 #include "cygwin.h"
189 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
190 #endif
191
192 const char w32log_h_rcs[] = W32LOG_H_VERSION;
193
194 #ifndef _WIN_CONSOLE /* entire file */
195
196 /*
197  * Timers and the various durations
198  */
199 #define TIMER_ANIM_ID               1
200 #define TIMER_ANIM_TIME             100
201 #define TIMER_ANIMSTOP_ID           2
202 #define TIMER_ANIMSTOP_TIME         1000
203 #define TIMER_CLIPBUFFER_ID         3
204 #define TIMER_CLIPBUFFER_TIME       1000
205 #define TIMER_CLIPBUFFER_FORCE_ID   4
206 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
207
208 /*
209  * Styles of text that can be output
210  */
211 #define STYLE_NONE      0
212 #define STYLE_HIGHLIGHT 1
213 #define STYLE_LINK      2
214 #define STYLE_HEADER    3
215
216 /*
217  * Number of frames of animation in tray activity sequence
218  */
219 #define ANIM_FRAMES 8
220
221 #define DEFAULT_MAX_BUFFER_LINES    200
222 #define DEFAULT_LOG_FONT_NAME       "MS Sans Serif"
223 #define DEFAULT_LOG_FONT_SIZE       8
224
225 /*
226  * These values affect the way the log window behaves, they should be read
227  * from a file but for the moment, they are hardcoded here. Some options are
228  * configurable through the UI.
229  */
230
231 /* Indicates whether task bar shows activity animation */
232 BOOL g_bShowActivityAnimation = 1;
233
234 /* Indicates whether the log window is shown */
235 BOOL g_bShowLogWindow = 1;
236
237 /* Indicates if the log window appears on the task bar */
238 BOOL g_bShowOnTaskBar = 0;
239
240 /* Indicates whether closing the log window really just hides it */
241 BOOL g_bCloseHidesWindow = 1;
242
243 /* Indicates if messages are logged at all */
244 BOOL g_bLogMessages = 1;
245
246 /* Indicates whether log messages are highlighted */
247 BOOL g_bHighlightMessages = 1;
248
249 /* Indicates if buffer is limited in size */
250 BOOL g_bLimitBufferSize = 1;
251
252 /* Maximum number of lines allowed in buffer when limited */
253 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
254
255 /* Font to use */
256 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
257
258 /* Size of font to use */
259 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
260
261
262 /* FIXME: this is a kludge */
263
264 const char * g_default_actions_file = NULL;
265 const char * g_user_actions_file = NULL;
266 const char * g_re_filterfile = NULL;
267 #ifdef FEATURE_TRUST
268 const char * g_trustfile = NULL;
269 #endif /* def FEATURE_TRUST */
270
271 /* FIXME: end kludge */
272
273 /* Regular expression for detected URLs */
274 #define RE_URL "http:[^ \n\r]*"
275
276 /*
277  * Regular expressions that are used to perform highlight in the log window
278  */
279 static struct _Pattern
280 {
281    const char *str;
282    int style;
283    regex_t buffer;
284 } patterns_to_highlight[] =
285 {
286    /* url headers */
287    { RE_URL,                STYLE_LINK },
288 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
289    /* interesting text to highlight */
290    { "crunch!",           STYLE_HIGHLIGHT },
291    /* http headers */
292    { "referer:",            STYLE_HEADER },
293    { "proxy-connection:",   STYLE_HEADER },
294    { "proxy-agent:",        STYLE_HEADER },
295    { "user-agent:",         STYLE_HEADER },
296    { "host:",               STYLE_HEADER },
297    { "accept:",             STYLE_HEADER },
298    { "accept-encoding:",    STYLE_HEADER },
299    { "accept-language:",    STYLE_HEADER },
300    { "accept-charset:",     STYLE_HEADER },
301    { "accept-ranges:",      STYLE_HEADER },
302    { "date:",               STYLE_HEADER },
303    { "cache-control:",      STYLE_HEADER },
304    { "cache-last-checked:", STYLE_HEADER },
305    { "connection:",         STYLE_HEADER },
306    { "content-type",        STYLE_HEADER },
307    { "content-length",      STYLE_HEADER },
308    { "cookie",              STYLE_HEADER },
309    { "last-modified:",      STYLE_HEADER },
310    { "pragma:",             STYLE_HEADER },
311    { "server:",             STYLE_HEADER },
312    { "etag:",               STYLE_HEADER },
313    { "expires:",            STYLE_HEADER },
314    { "warning:",            STYLE_HEADER },
315    /* this is the terminator statement - do not delete! */
316    { NULL,                  STYLE_NONE }
317 };
318
319 /*
320  * Public variables
321  */
322 HWND g_hwndLogFrame;
323 HICON g_hiconApp;
324
325 /*
326  * Private variables
327  */
328 static CRITICAL_SECTION g_criticalsection;
329 static HWND g_hwndTray;
330 static HWND g_hwndLogBox;
331 static WNDPROC g_fnLogBox;
332 static HICON g_hiconAnim[ANIM_FRAMES];
333 static HICON g_hiconIdle;
334 static int g_nAnimFrame;
335 static BOOL g_bClipPending = FALSE;
336 static int g_nRichEditVersion = 0;
337
338 /*
339  * Private functions
340  */
341 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
342 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
343 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
344 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
345 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
346 static BOOL InitRichEdit(void);
347 static void LogClipBuffer(void);
348 static void LogCreatePatternMatchingBuffers(void);
349 static void LogDestroyPatternMatchingBuffers(void);
350 static int LogPutStringNoMatch(const char *pszText, int style);
351
352
353 /*********************************************************************
354  *
355  * Function    :  InitLogWindow
356  *
357  * Description :  Initialise the log window.
358  *
359  * Parameters  :  None
360  *
361  * Returns     :  Always TRUE (there should be error checking on the resources).
362  *
363  *********************************************************************/
364 BOOL InitLogWindow(void)
365 {
366    int i;
367
368    /* Load the icons */
369    g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
370    for (i = 0; i < ANIM_FRAMES; i++)
371    {
372       g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ANIMATED1 + i));
373    }
374    g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_MAINICON));
375
376    /* Create the user interface */
377    g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
378    g_hwndTray = CreateTrayWindow(g_hInstance);
379    TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Privoxy");
380
381    /* Create pattern matching buffers (for highlighting */
382    LogCreatePatternMatchingBuffers();
383
384    /* Create a critical section to protect multi-threaded access to certain things */
385    InitializeCriticalSection(&g_criticalsection);
386
387    return TRUE;
388
389 }
390
391
392 /*********************************************************************
393  *
394  * Function    :  TermLogWindow
395  *
396  * Description :  Cleanup the logwindow.
397  *
398  * Parameters  :  None
399  *
400  * Returns     :  N/A
401  *
402  *********************************************************************/
403 void TermLogWindow(void)
404 {
405    int i;
406
407    LogDestroyPatternMatchingBuffers();
408
409    TrayDeleteIcon(g_hwndTray, 1);
410    DeleteObject(g_hiconApp);
411    DeleteObject(g_hiconIdle);
412    for (i = 0; i < ANIM_FRAMES; i++)
413    {
414       DeleteObject(g_hiconAnim[i]);
415    }
416
417 }
418
419
420 /*********************************************************************
421  *
422  * Function    :  LogCreatePatternMatchingBuffers
423  *
424  * Description :  Compile the pattern matching buffers.
425  *
426  * Parameters  :  None
427  *
428  * Returns     :  N/A
429  *
430  *********************************************************************/
431 void LogCreatePatternMatchingBuffers(void)
432 {
433    int i;
434    for (i = 0; patterns_to_highlight[i].str != NULL; i++)
435    {
436       regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
437    }
438 }
439
440
441 /*********************************************************************
442  *
443  * Function    :  LogDestroyPatternMatchingBuffers
444  *
445  * Description :  Free up the pattern matching buffers.
446  *
447  * Parameters  :  None
448  *
449  * Returns     :  N/A
450  *
451  *********************************************************************/
452 void LogDestroyPatternMatchingBuffers(void)
453 {
454    int i;
455    for (i = 0; patterns_to_highlight[i].str != NULL; i++)
456    {
457       regfree(&patterns_to_highlight[i].buffer);
458    }
459 }
460
461
462 /*********************************************************************
463  *
464  * Function    :  LogGetURLUnderCursor
465  *
466  * Description :  Returns the URL from under the cursor (remember to free it!).
467  *
468  * Parameters  :  None
469  *
470  * Returns     :  NULL or a pointer to an URL string.
471  *
472  *********************************************************************/
473 char *LogGetURLUnderCursor(void)
474 {
475    char *szResult = NULL;
476    regex_t re;
477    POINT ptCursor;
478    POINTL ptl;
479    DWORD nPos;
480    DWORD nWordStart = 0;
481    DWORD nWordEnd = 0;
482
483    regcomp(&re, RE_URL, REG_ICASE);
484
485    /* Get the position of the cursor over the text window */
486    GetCursorPos(&ptCursor);
487    ScreenToClient(g_hwndLogBox, &ptCursor);
488    ptl.x = ptCursor.x;
489    ptl.y = ptCursor.y;
490
491    /* Search backwards and fowards to obtain the word that is highlighted */
492    nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
493    nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
494    nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
495
496    /* Compare the string to the pattern */
497    if (nWordEnd > nWordStart)
498    {
499       TEXTRANGE range;
500       regmatch_t match;
501
502       range.chrg.cpMin = nWordStart;
503       range.chrg.cpMax = nWordEnd;
504       range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
505       SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
506
507       if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
508       {
509          szResult = range.lpstrText;
510       }
511       else
512       {
513          free(range.lpstrText);
514       }
515
516       regfree(&re);
517    }
518    return szResult;
519
520 }
521
522
523 /*********************************************************************
524  *
525  * Function    :  LogPutString
526  *
527  * Description :  Inserts text into the logging window.  This is really
528  *                a regexp aware wrapper function to `LogPutStringNoMatch'.
529  *
530  * Parameters  :
531  *          1  :  pszText = pointer to string going to the log window
532  *
533  * Returns     :  1 => success, else the return code from `LogPutStringNoMatch'.
534  *                FIXME: this is backwards to the rest of IJB and to common
535  *                programming practice.  Please use 0 => success instead.
536  *
537  *********************************************************************/
538 int LogPutString(const char *pszText)
539 {
540    int i;
541    int result = 0;
542
543    if (pszText == NULL || strlen(pszText) == 0)
544    {
545       return 1;
546    }
547
548    if (!g_bLogMessages)
549    {
550       return 1;
551    }
552
553    /* Critical section stops multiple threads doing nasty interactions that
554     * foul up the highlighting and output.
555     */
556    EnterCriticalSection(&g_criticalsection);
557
558    if (g_bHighlightMessages)
559    {
560       regmatch_t match;
561
562       /* First things first, regexp scan for various things that we would like highlighted */
563       for (i = 0; patterns_to_highlight[i].str != NULL; i++)
564       {
565          if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
566          {
567             char *pszBefore = NULL;
568             char *pszMatch = NULL;
569             char *pszAfter = NULL;
570             int nMatchSize;
571
572             /* Split the string up into pieces representing the strings, before
573                at and after the matching pattern
574              */
575             if (match.rm_so > 0)
576             {
577                pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
578                memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
579                strncpy(pszBefore, pszText, match.rm_so);
580             }
581             if (match.rm_eo < (regoff_t)strlen(pszText))
582             {
583                pszAfter = strdup(&pszText[match.rm_eo]);
584             }
585             nMatchSize = match.rm_eo - match.rm_so;
586             pszMatch = (char *)malloc(nMatchSize + 1);
587             strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
588             pszMatch[nMatchSize] = '\0';
589
590             /* Recursively call LogPutString */
591             if (pszBefore)
592             {
593                LogPutString(pszBefore);
594                free(pszBefore);
595             }
596             if (pszMatch)
597             {
598                LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
599                free(pszMatch);
600             }
601             if (pszAfter)
602             {
603                LogPutString(pszAfter);
604                free(pszAfter);
605             }
606
607             result = 1;
608             goto end;
609          }
610       }
611    }
612
613    result = LogPutStringNoMatch(pszText, STYLE_NONE);
614
615 end:
616    LeaveCriticalSection(&g_criticalsection);
617
618    return result;
619
620 }
621
622
623 /*********************************************************************
624  *
625  * Function    :  LogPutStringNoMatch
626  *
627  * Description :  Puts a string into the logging window.
628  *
629  * Parameters  :
630  *          1  :  pszText = pointer to string going to the log window
631  *          2  :  style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
632  *
633  * Returns     :  Always 1 => success.
634  *                FIXME: this is backwards to the rest of IJB and to common
635  *                programming practice.  Please use 0 => success instead.
636  *
637  *********************************************************************/
638 int LogPutStringNoMatch(const char *pszText, int style)
639 {
640    CHARRANGE range;
641    CHARFORMAT format;
642    int nTextLength;
643
644    assert(g_hwndLogBox);
645    if (g_hwndLogBox == NULL)
646    {
647       return 1;
648    }
649
650    /* TODO preserve existing selection */
651
652    /* Go to the end of the text */
653    nTextLength = GetWindowTextLength(g_hwndLogBox);
654    range.cpMin = nTextLength;
655    range.cpMax = nTextLength;
656    SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
657
658    /* Apply a formatting style */
659    memset(&format, 0, sizeof(format));
660    format.cbSize = sizeof(format);
661    format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
662    format.yHeight = (g_nFontSize * 1440) / 72;
663    strcpy(format.szFaceName, g_szFontFaceName);
664    if (style == STYLE_NONE)
665    {
666       /* DO NOTHING */
667       format.dwEffects |= CFE_AUTOCOLOR;
668    }
669    else if (style == STYLE_HEADER)
670    {
671       format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
672    }
673    else if (style == STYLE_HIGHLIGHT)
674    {
675       format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
676    }
677    else if (style == STYLE_LINK)
678    {
679       format.dwEffects |= CFE_UNDERLINE;
680       format.crTextColor = RGB(0, 0, 255);
681    }
682    SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
683
684    /* Append text to the end */
685    SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
686
687    /* TODO Restore the old selection */
688
689    /* Purge buffer */
690    if (strchr(pszText, '\n') != NULL)
691    {
692       SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
693       if (!g_bClipPending)
694       {
695          /* Set the force clip timer going. This timer ensures clipping is done
696             intermittently even when there is a sustained burst of logging
697          */
698          SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
699       }
700       g_bClipPending = TRUE;
701    }
702
703    return 1;
704
705 }
706
707
708 /*********************************************************************
709  *
710  * Function    :  LogShowActivity
711  *
712  * Description :  Start the spinner.
713  *
714  * Parameters  :  None
715  *
716  * Returns     :  N/A
717  *
718  *********************************************************************/
719 void LogShowActivity(void)
720 {
721    /* Start some activity timers */
722    if (g_bShowActivityAnimation)
723    {
724       SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
725       SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
726    }
727
728 }
729
730
731 /*********************************************************************
732  *
733  * Function    :  LogClipBuffer
734  *
735  * Description :  Prunes old lines from the log.
736  *
737  * Parameters  :  None
738  *
739  * Returns     :  N/A
740  *
741  *********************************************************************/
742 void LogClipBuffer(void)
743 {
744    int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
745    if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
746    {
747       /* Compute the range representing the lines to be deleted */
748       LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
749       LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
750       CHARRANGE range;
751       range.cpMin = 0;
752       range.cpMax = nLastChar;
753
754       /* TODO get current selection */
755
756       /* TODO adjust and clip old selection against range to be deleted */
757
758       /* Select range and erase it (turning off autoscroll to prevent
759          nasty scrolling) */
760       SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
761       SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
762       SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
763       SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
764
765       /* Restore old selection */
766    }
767
768 }
769
770
771 /*********************************************************************
772  *
773  * Function    :  CreateHiddenLogOwnerWindow
774  *
775  * Description :  Creates a hidden owner window that stops the log
776  *                window appearing in the task bar.
777  *
778  * Parameters  :
779  *          1  :  hInstance = application's instance handle
780  *
781  * Returns     :  Handle to newly created window.
782  *
783  *********************************************************************/
784 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
785 {
786    static const char *szWndName = "PrivoxyLogOwner";
787    WNDCLASS wc;
788    HWND hwnd;
789
790    wc.style          = 0;
791    wc.lpfnWndProc    = LogOwnerWindowProc;
792    wc.cbClsExtra     = 0;
793    wc.cbWndExtra     = 0;
794    wc.hInstance      = hInstance;
795    wc.hIcon          = 0;
796    wc.hCursor        = 0;
797    wc.hbrBackground  = 0;
798    wc.lpszMenuName   = 0;
799    wc.lpszClassName  = szWndName;
800
801    RegisterClass(&wc);
802
803    hwnd = CreateWindow(szWndName, szWndName,
804       WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
805       CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
806
807    return hwnd;
808
809 }
810
811
812 /*********************************************************************
813  *
814  * Function    :  LogOwnerWindowProc
815  *
816  * Description :  Dummy procedure that does nothing special.
817  *
818  * Parameters  :
819  *          1  :  hwnd = window handle
820  *          2  :  uMsg = message number
821  *          3  :  wParam = first param for this message
822  *          4  :  lParam = next param for this message
823  *
824  * Returns     :  Same as `DefWindowProc'.
825  *
826  *********************************************************************/
827 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
828 {
829    return DefWindowProc(hwnd, uMsg, wParam, lParam);
830
831 }
832
833
834 /*********************************************************************
835  *
836  * Function    :  CreateLogWindow
837  *
838  * Description :  Create the logging window.
839  *
840  * Parameters  :
841  *          1  :  hInstance = application's instance handle
842  *          2  :  nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
843  *
844  * Returns     :  Handle to newly created window.
845  *
846  *********************************************************************/
847 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
848 {
849    static const char *szWndName = "PrivoxyLogWindow";
850    static const char *szWndTitle = "Privoxy";
851
852    HWND hwnd = NULL;
853    HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
854    RECT rcClient;
855    WNDCLASSEX wc;
856
857    memset(&wc, 0, sizeof(wc));
858    wc.cbSize         = sizeof(wc);
859    wc.style          = CS_DBLCLKS;
860    wc.lpfnWndProc    = LogWindowProc;
861    wc.cbClsExtra     = 0;
862    wc.cbWndExtra     = 0;
863    wc.hInstance      = hInstance;
864    wc.hIcon          = g_hiconApp;
865    wc.hCursor        = 0;
866    wc.hbrBackground  = 0;
867    wc.lpszMenuName   = MAKEINTRESOURCE(IDR_LOGVIEW);
868    wc.lpszClassName  = szWndName;
869    wc.hbrBackground  = GetStockObject(WHITE_BRUSH);
870    RegisterClassEx(&wc);
871
872    hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
873       WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
874       CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
875
876    /* Now create a child list box */
877    GetClientRect(hwnd, &rcClient);
878
879    /* Create a rich edit control */
880    InitRichEdit();
881    g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
882       ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
883       rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
884       hwnd, NULL, hInstance, NULL);
885 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
886
887    /* Subclass the control to catch certain messages */
888    g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
889    SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
890
891    /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
892    if (!g_bShowOnTaskBar &&
893          (nCmdShow == SW_SHOWMINIMIZED ||
894           nCmdShow == SW_MINIMIZE ||
895           nCmdShow == SW_SHOWMINNOACTIVE))
896    {
897       nCmdShow = SW_HIDE;
898    }
899
900    ShowWindow(hwnd, nCmdShow);
901    UpdateWindow(hwnd);
902
903    GetClientRect(g_hwndLogFrame, &rcClient);
904    SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
905
906    return hwnd;
907
908 }
909
910
911 /*********************************************************************
912  *
913  * Function    :  InitRichEdit
914  *
915  * Description :  Initialise the rich edit control library.
916  *
917  * Parameters  :  None
918  *
919  * Returns     :  TRUE => success, FALSE => failure.
920  *                FIXME: this is backwards to the rest of IJB and to common
921  *                programming practice.  Please use 0 => success instead.
922  *
923  *********************************************************************/
924 BOOL InitRichEdit(void)
925 {
926    static HINSTANCE hInstRichEdit;
927    if (hInstRichEdit == NULL)
928    {
929       g_nRichEditVersion = 0;
930       hInstRichEdit = LoadLibraryA("RICHED20.DLL");
931       if (hInstRichEdit)
932       {
933          g_nRichEditVersion = _RICHEDIT_VER;
934       }
935       else
936       {
937          hInstRichEdit = LoadLibraryA("RICHED32.DLL");
938          if (hInstRichEdit)
939          {
940             g_nRichEditVersion = 0x0100;
941          }
942       }
943    }
944    return (hInstRichEdit != NULL) ? TRUE : FALSE;
945
946 }
947
948
949 /*********************************************************************
950  *
951  * Function    :  ShowLogWindow
952  *
953  * Description :  Shows or hides the log window.  We will also raise the
954  *                window on a show command in case it is buried.
955  *
956  * Parameters  :
957  *          1  :  bShow = TRUE to show, FALSE to mimize/hide
958  *
959  * Returns     :  N/A
960  *
961  *********************************************************************/
962 void ShowLogWindow(BOOL bShow)
963 {
964    if (bShow)
965    {
966       SetForegroundWindow(g_hwndLogFrame);
967       SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
968       
969    }
970    else if (g_bShowOnTaskBar)
971    {
972       ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
973    }
974    else
975    {
976       ShowWindow(g_hwndLogFrame, SW_HIDE);
977    }
978 }
979
980
981 /*********************************************************************
982  *
983  * Function    :  EditFile
984  *
985  * Description :  Opens the specified setting file for editing.
986  * FIXME: What if the file has no associated application. Check for return values
987 *        from ShellExecute??
988  *
989  * Parameters  :
990  *          1  :  filename = filename from the config (aka config.txt) file.
991  *
992  * Returns     :  N/A
993  *
994  *********************************************************************/
995 void EditFile(const char *filename)
996 {
997    if (filename)
998    {
999       ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
1000    }
1001
1002 }
1003
1004
1005 /*--------------------------------------------------------------------------*/
1006 /* Windows message handlers                                                 */
1007 /*--------------------------------------------------------------------------*/
1008
1009
1010 /*********************************************************************
1011  *
1012  * Function    :  OnLogRButtonUp
1013  *
1014  * Description :  Handler for WM_RBUTTONUP messages.
1015  *
1016  * Parameters  :
1017  *          1  :  nModifier = wParam from mouse message (unused)
1018  *          2  :  x = x coordinate of the mouse event
1019  *          3  :  y = y coordinate of the mouse event
1020  *
1021  * Returns     :  N/A
1022  *
1023  *********************************************************************/
1024 void OnLogRButtonUp(int nModifier, int x, int y)
1025 {
1026    HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
1027    if (hMenu != NULL)
1028    {
1029       HMENU hMenuPopup = GetSubMenu(hMenu, 0);
1030
1031       /* Check if there is a selection */
1032       CHARRANGE range;
1033       SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
1034       if (range.cpMin == range.cpMax)
1035       {
1036          EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
1037       }
1038       else
1039       {
1040          EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
1041       }
1042
1043       /* Display the popup */
1044       TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
1045       DestroyMenu(hMenu);
1046    }
1047
1048 }
1049
1050
1051 /*********************************************************************
1052  *
1053  * Function    :  OnLogCommand
1054  *
1055  * Description :  Handler for WM_COMMAND messages.
1056  *
1057  * Parameters  :
1058  *          1  :  nCommand = the command portion of the menu selection event
1059  *
1060  * Returns     :  N/A
1061  *
1062  *********************************************************************/
1063 void OnLogCommand(int nCommand)
1064 {
1065    switch (nCommand)
1066    {
1067       case ID_TOGGLE_SHOWWINDOW:
1068          g_bShowLogWindow = !g_bShowLogWindow;
1069
1070          ShowLogWindow(g_bShowLogWindow);
1071          break;
1072
1073       case ID_FILE_EXIT:
1074          PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1075          break;
1076
1077       case ID_EDIT_COPY:
1078          SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1079          break;
1080
1081       case ID_VIEW_CLEARLOG:
1082          SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1083          break;
1084
1085       case ID_VIEW_LOGMESSAGES:
1086          g_bLogMessages = !g_bLogMessages;
1087          /* SaveLogSettings(); */
1088          break;
1089
1090       case ID_VIEW_MESSAGEHIGHLIGHTING:
1091          g_bHighlightMessages = !g_bHighlightMessages;
1092          /* SaveLogSettings(); */
1093          break;
1094
1095       case ID_VIEW_LIMITBUFFERSIZE:
1096          g_bLimitBufferSize = !g_bLimitBufferSize;
1097          /* SaveLogSettings(); */
1098          break;
1099
1100       case ID_VIEW_ACTIVITYANIMATION:
1101          g_bShowActivityAnimation = !g_bShowActivityAnimation;
1102          /* SaveLogSettings(); */
1103          break;
1104
1105 #ifdef FEATURE_TOGGLE
1106       /* by haroon - change toggle to its opposite value */
1107       case ID_TOGGLE_ENABLED:
1108          g_bToggleIJB = !g_bToggleIJB;
1109          if (g_bToggleIJB)
1110          {
1111             log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1112          }
1113          else
1114          {
1115             log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1116          }
1117          break;
1118 #endif /* def FEATURE_TOGGLE */
1119
1120       case ID_TOOLS_EDITCONFIG:
1121          EditFile(configfile);
1122          break;
1123
1124       case ID_TOOLS_EDITDEFAULTACTIONS:
1125          EditFile(g_default_actions_file);
1126          break;
1127
1128       case ID_TOOLS_EDITUSERACTIONS:
1129          EditFile(g_user_actions_file);
1130          break;
1131
1132       case ID_TOOLS_EDITFILTERS:
1133          EditFile(g_re_filterfile);
1134          break;
1135
1136 #ifdef FEATURE_TRUST
1137       case ID_TOOLS_EDITTRUST:
1138          EditFile(g_trustfile);
1139          break;
1140 #endif /* def FEATURE_TRUST */
1141
1142       case ID_HELP_GPL:
1143          ShellExecute(g_hwndLogFrame, "open", "LICENSE.txt", NULL, NULL, SW_SHOWNORMAL);
1144          break;
1145
1146       case ID_HELP_FAQ:
1147          ShellExecute(g_hwndLogFrame, "open", "doc\\faq\\index.html", NULL, NULL, SW_SHOWNORMAL);
1148          break;
1149
1150       case ID_HELP_MANUAL:
1151          ShellExecute(g_hwndLogFrame, "open", "doc\\user-manual\\index.html", NULL, NULL, SW_SHOWNORMAL);
1152          break;
1153
1154       case ID_HELP_STATUS:
1155          ShellExecute(g_hwndLogFrame, "open", CGI_PREFIX "show-status", NULL, NULL, SW_SHOWNORMAL);
1156          break;
1157
1158       case ID_HELP_ABOUT:
1159          MessageBox(g_hwndLogFrame, win32_blurb, "About Privoxy", MB_OK);
1160          break;
1161
1162       default:
1163          /* DO NOTHING */
1164          break;
1165    }
1166
1167 }
1168
1169
1170 /*********************************************************************
1171  *
1172  * Function    :  OnLogInitMenu
1173  *
1174  * Description :  Handler for WM_INITMENU messages.  Enable, disable,
1175  *                check, and/or uncheck menu options as apropos.
1176  *
1177  * Parameters  :
1178  *          1  :  hmenu = handle to menu to "make current"
1179  *
1180  * Returns     :  N/A
1181  *
1182  *********************************************************************/
1183 void OnLogInitMenu(HMENU hmenu)
1184 {
1185    /* Only enable editors if there is a file to edit */
1186    EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTACTIONS, MF_BYCOMMAND | (g_default_actions_file ? MF_ENABLED : MF_GRAYED));
1187    EnableMenuItem(hmenu, ID_TOOLS_EDITUSERACTIONS, MF_BYCOMMAND | (g_user_actions_file ? MF_ENABLED : MF_GRAYED));
1188    EnableMenuItem(hmenu, ID_TOOLS_EDITFILTERS, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1189 #ifdef FEATURE_TRUST
1190    EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1191 #endif /* def FEATURE_TRUST */
1192
1193    /* Check/uncheck options */
1194    CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1195    CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1196    CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1197    CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1198 #ifdef FEATURE_TOGGLE
1199    /* by haroon - menu item for Enable toggle on/off */
1200    CheckMenuItem(hmenu, ID_TOGGLE_ENABLED, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1201 #endif /* def FEATURE_TOGGLE */
1202    CheckMenuItem(hmenu, ID_TOGGLE_SHOWWINDOW, MF_BYCOMMAND | (g_bShowLogWindow ? MF_CHECKED : MF_UNCHECKED));
1203
1204 }
1205
1206
1207 /*********************************************************************
1208  *
1209  * Function    :  OnLogTimer
1210  *
1211  * Description :  Handler for WM_TIMER messages.
1212  *
1213  * Parameters  :
1214  *          1  :  nTimer = timer id (animation start/stop or clip buffer)
1215  *
1216  * Returns     :  N/A
1217  *
1218  *********************************************************************/
1219 void OnLogTimer(int nTimer)
1220 {
1221    switch (nTimer)
1222    {
1223       case TIMER_ANIM_ID:
1224          TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1225          break;
1226
1227       case TIMER_ANIMSTOP_ID:
1228          g_nAnimFrame = 0;
1229          TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1230          KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1231          KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1232          break;
1233
1234       case TIMER_CLIPBUFFER_ID:
1235       case TIMER_CLIPBUFFER_FORCE_ID:
1236          LogClipBuffer();
1237          g_bClipPending = FALSE;
1238          KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1239          KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1240          break;
1241
1242       default:
1243          /* DO NOTHING */
1244          break;
1245    }
1246
1247 }
1248
1249
1250 /*********************************************************************
1251  *
1252  * Function    :  LogRichEditProc
1253  *
1254  * Description :  Window subclass routine handles some events for the rich edit control.
1255  *
1256  * Parameters  :
1257  *          1  :  hwnd = window handle of the rich edit control
1258  *          2  :  uMsg = message number
1259  *          3  :  wParam = first param for this message
1260  *          4  :  lParam = next param for this message
1261  *
1262  * Returns     :  Appropriate M$ window message handler codes.
1263  *
1264  *********************************************************************/
1265 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1266 {
1267    switch (uMsg)
1268    {
1269       case WM_RBUTTONUP:
1270       {
1271          POINT pt;
1272          pt.x = LOWORD(lParam);
1273          pt.y = HIWORD(lParam);
1274          ClientToScreen(hwnd, &pt);
1275          OnLogRButtonUp(wParam, pt.x, pt.y);
1276       }
1277       return 0;
1278    }
1279    return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1280
1281 }
1282
1283
1284 /*********************************************************************
1285  *
1286  * Function    :  LogWindowProc
1287  *
1288  * Description :  Windows call back routine handles events on the log window.
1289  *
1290  * Parameters  :
1291  *          1  :  hwnd = handle of the logging window
1292  *          2  :  uMsg = message number
1293  *          3  :  wParam = first param for this message
1294  *          4  :  lParam = next param for this message
1295  *
1296  * Returns     :  Appropriate M$ window message handler codes.
1297  *
1298  *********************************************************************/
1299 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1300 {
1301    switch (uMsg)
1302    {
1303       case WM_CREATE:
1304          return 0;
1305
1306       case WM_CLOSE:
1307          /* This is the end - beautiful friend - the end */
1308          DestroyWindow(g_hwndLogBox);
1309          DestroyWindow(g_hwndLogFrame);
1310          return 0;
1311
1312       case WM_DESTROY:
1313          PostQuitMessage(0);
1314          return 0;
1315
1316       case WM_SHOWWINDOW:
1317          g_bShowLogWindow = wParam;
1318       case WM_SIZE:
1319          /* Resize the logging window to fit the new frame */
1320          if (g_hwndLogBox)
1321          {
1322             RECT rc;
1323             GetClientRect(g_hwndLogFrame, &rc);
1324             SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1325          }
1326          return 0;
1327
1328       case WM_INITMENU:
1329          OnLogInitMenu((HMENU) wParam);
1330          return 0;
1331
1332       case WM_TIMER:
1333          OnLogTimer(wParam);
1334          return 0;
1335
1336       case WM_COMMAND:
1337          OnLogCommand(LOWORD(wParam));
1338          return 0;
1339
1340       case WM_SYSCOMMAND:
1341          switch (wParam)
1342          {
1343             case SC_CLOSE:
1344                if (g_bCloseHidesWindow)
1345                {
1346                   ShowLogWindow(FALSE);
1347                   return 0;
1348                }
1349                break;
1350             case SC_MINIMIZE:
1351                ShowLogWindow(FALSE);
1352                return 0;
1353          }
1354          break;
1355    }
1356
1357    return DefWindowProc(hwnd, uMsg, wParam, lParam);
1358
1359 }
1360
1361 #endif /* ndef _WIN_CONSOLE - entire file */
1362
1363 /*
1364   Local Variables:
1365   tab-width: 3
1366   end:
1367 */