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