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