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