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