1 const char w32log_rcs[] = "$Id: w32log.c,v 1.25.2.5 2003/04/04 12:48:51 oes Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/Attic/w32log.c,v $
6 * Purpose : Functions for creating and destroying the log window,
7 * ouputting strings, processing messages and so on.
9 * Copyright : Written by and Copyright (C) 2001-2002 members of
10 * the Privoxy team. http://www.privoxy.org/
12 * Written by and Copyright (C) 1999 Adam Lock
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.
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.
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.
35 * Revision 1.25.2.5 2003/04/04 12:48:51 oes
37 * - Made tray menu correctly reflect initial window visibility state
38 * - Hopefully fixed problem where log window contents wasn't visible
39 * until vertical scroll bar was clicked. Thanks to Guy for the fix!
41 * Revision 1.25.2.4 2003/03/11 11:53:59 oes
42 * Cosmetic: Renamed cryptic variable
44 * Revision 1.25.2.3 2002/11/20 14:39:05 oes
45 * Fixed compiler warning
47 * Revision 1.25.2.2 2002/09/25 15:23:10 oes
48 * Uncheck the "Show Privoxy Window" taskbar menu item when window gets minimized. Fixes bug #606804
50 * Revision 1.25.2.1 2002/08/21 17:59:05 oes
51 * - "Show Privoxy Window" now a toggle
52 * - Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
54 * Revision 1.25 2002/04/04 00:36:36 gliptak
55 * always use pcre for matching
57 * Revision 1.24 2002/03/31 17:19:00 jongfoster
58 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
60 * Revision 1.23 2002/03/26 22:57:10 jongfoster
61 * Web server name should begin www.
63 * Revision 1.22 2002/03/24 12:48:23 jongfoster
66 * Revision 1.21 2002/03/24 12:07:35 jongfoster
67 * Consistern name for filters file
69 * Revision 1.20 2002/03/24 12:03:47 jongfoster
72 * Revision 1.19 2002/01/17 21:04:17 jongfoster
73 * Replacing hard references to the URL of the config interface
74 * with #defines from project.h
76 * Revision 1.18 2001/11/30 23:37:24 jongfoster
77 * Renaming the Win32 config file to config.txt - this is almost the
78 * same as the corresponding UNIX name "config"
80 * Revision 1.17 2001/11/16 00:46:31 jongfoster
81 * Fixing compiler warnings
83 * Revision 1.16 2001/08/01 19:58:12 jongfoster
84 * Fixing documentation filenames in help menu, and making status
85 * option work without needing the "Junkbuster Status.URL" file.
87 * Revision 1.15 2001/07/30 22:08:36 jongfoster
88 * Tidying up #defines:
89 * - All feature #defines are now of the form FEATURE_xxx
90 * - Permanently turned off WIN_GUI_EDIT
91 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
93 * Revision 1.14 2001/07/29 18:47:05 jongfoster
94 * Adding missing #include "loadcfg.h"
96 * Revision 1.13 2001/07/19 19:15:14 haroon
97 * - Added a FIXME for EditFile but didn't fix :-)
99 * Revision 1.12 2001/07/13 14:04:59 oes
100 * Removed all #ifdef PCRS
102 * Revision 1.11 2001/06/07 23:08:12 jongfoster
103 * Forward and ACL edit options removed.
105 * Revision 1.10 2001/05/31 21:37:11 jongfoster
106 * GUI changes to rename "permissions file" to "actions file".
108 * Revision 1.9 2001/05/31 17:33:13 oes
112 * Revision 1.8 2001/05/29 09:50:24 jongfoster
113 * Unified blocklist/imagelist/permissionslist.
114 * File format is still under discussion, but the internal changes
117 * Also modified interceptor behaviour:
118 * - We now intercept all URLs beginning with one of the following
119 * prefixes (and *only* these prefixes):
121 * * http://ijbswa.sf.net/config/
122 * * http://ijbswa.sourceforge.net/config/
123 * - New interceptors "home page" - go to http://i.j.b/ to see it.
124 * - Internal changes so that intercepted and fast redirect pages
125 * are not replaced with an image.
126 * - Interceptors now have the option to send a binary page direct
127 * to the client. (i.e. ijb-send-banner uses this)
128 * - Implemented show-url-info interceptor. (Which is why I needed
129 * the above interceptors changes - a typical URL is
130 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
131 * The previous mechanism would not have intercepted that, and
132 * if it had been intercepted then it then it would have replaced
135 * Revision 1.7 2001/05/26 01:26:34 jongfoster
136 * New #define, WIN_GUI_EDIT, enables the (embryonic) Win32 GUI editor.
137 * This #define cannot be set from ./configure - there's no point, it
138 * doesn't work yet. See feature request # 425722
140 * Revision 1.6 2001/05/26 00:31:30 jongfoster
141 * Fixing compiler warning about comparing signed/unsigned.
143 * Revision 1.5 2001/05/26 00:28:36 jongfoster
144 * Automatic reloading of config file.
145 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
146 * Most of the global variables have been moved to a new
147 * struct configuration_spec, accessed through csp->config->globalname
148 * Most of the globals remaining are used by the Win32 GUI.
150 * Revision 1.4 2001/05/22 18:56:28 oes
153 * Revision 1.3 2001/05/20 15:07:54 jongfoster
154 * File is now ignored if _WIN_CONSOLE is defined.
156 * Revision 1.2 2001/05/20 01:21:20 jongfoster
157 * Version 2.9.4 checkin.
158 * - Merged popupfile and cookiefile, and added control over PCRS
159 * filtering, in new "permissionsfile".
160 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
161 * file error you now get a message box (in the Win32 GUI) rather
162 * than the program exiting with no explanation.
163 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
165 * - Removed tabs from "config"
166 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
167 * - Bumped up version number.
169 * Revision 1.1.1.1 2001/05/15 13:59:07 oes
170 * Initial import of version 2.9.3 source tree
173 *********************************************************************/
185 #include <richedit.h>
189 #include "w32taskbar.h"
193 #include "miscutil.h"
197 const char w32res_h_rcs[] = W32RES_H_VERSION;
201 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
204 const char w32log_h_rcs[] = W32LOG_H_VERSION;
206 #ifndef _WIN_CONSOLE /* entire file */
209 * Timers and the various durations
211 #define TIMER_ANIM_ID 1
212 #define TIMER_ANIM_TIME 100
213 #define TIMER_ANIMSTOP_ID 2
214 #define TIMER_ANIMSTOP_TIME 1000
215 #define TIMER_CLIPBUFFER_ID 3
216 #define TIMER_CLIPBUFFER_TIME 1000
217 #define TIMER_CLIPBUFFER_FORCE_ID 4
218 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
221 * Styles of text that can be output
224 #define STYLE_HIGHLIGHT 1
226 #define STYLE_HEADER 3
229 * Number of frames of animation in tray activity sequence
231 #define ANIM_FRAMES 8
233 #define DEFAULT_MAX_BUFFER_LINES 200
234 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
235 #define DEFAULT_LOG_FONT_SIZE 8
238 * These values affect the way the log window behaves, they should be read
239 * from a file but for the moment, they are hardcoded here. Some options are
240 * configurable through the UI.
243 /* Indicates whether task bar shows activity animation */
244 BOOL g_bShowActivityAnimation = 1;
246 /* Indicates whether the log window is shown */
247 BOOL g_bShowLogWindow = 1;
249 /* Indicates if the log window appears on the task bar */
250 BOOL g_bShowOnTaskBar = 0;
252 /* Indicates whether closing the log window really just hides it */
253 BOOL g_bCloseHidesWindow = 1;
255 /* Indicates if messages are logged at all */
256 BOOL g_bLogMessages = 1;
258 /* Indicates whether log messages are highlighted */
259 BOOL g_bHighlightMessages = 1;
261 /* Indicates if buffer is limited in size */
262 BOOL g_bLimitBufferSize = 1;
264 /* Maximum number of lines allowed in buffer when limited */
265 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
268 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
270 /* Size of font to use */
271 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
274 /* FIXME: this is a kludge */
276 const char * g_default_actions_file = NULL;
277 const char * g_user_actions_file = NULL;
278 const char * g_re_filterfile = NULL;
280 const char * g_trustfile = NULL;
281 #endif /* def FEATURE_TRUST */
283 /* FIXME: end kludge */
285 /* Regular expression for detected URLs */
286 #define RE_URL "http:[^ \n\r]*"
289 * Regular expressions that are used to perform highlight in the log window
291 static struct _Pattern
296 } patterns_to_highlight[] =
299 { RE_URL, STYLE_LINK },
300 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
301 /* interesting text to highlight */
302 { "crunch!", STYLE_HIGHLIGHT },
304 { "referer:", STYLE_HEADER },
305 { "proxy-connection:", STYLE_HEADER },
306 { "proxy-agent:", STYLE_HEADER },
307 { "user-agent:", STYLE_HEADER },
308 { "host:", STYLE_HEADER },
309 { "accept:", STYLE_HEADER },
310 { "accept-encoding:", STYLE_HEADER },
311 { "accept-language:", STYLE_HEADER },
312 { "accept-charset:", STYLE_HEADER },
313 { "accept-ranges:", STYLE_HEADER },
314 { "date:", STYLE_HEADER },
315 { "cache-control:", STYLE_HEADER },
316 { "cache-last-checked:", STYLE_HEADER },
317 { "connection:", STYLE_HEADER },
318 { "content-type", STYLE_HEADER },
319 { "content-length", STYLE_HEADER },
320 { "cookie", STYLE_HEADER },
321 { "last-modified:", STYLE_HEADER },
322 { "pragma:", STYLE_HEADER },
323 { "server:", STYLE_HEADER },
324 { "etag:", STYLE_HEADER },
325 { "expires:", STYLE_HEADER },
326 { "warning:", STYLE_HEADER },
327 /* this is the terminator statement - do not delete! */
340 static CRITICAL_SECTION g_criticalsection;
341 static HWND g_hwndTray;
342 static HWND g_hwndLogBox;
343 static WNDPROC g_fnLogBox;
344 static HICON g_hiconAnim[ANIM_FRAMES];
345 static HICON g_hiconIdle;
346 static int g_nAnimFrame;
347 static BOOL g_bClipPending = FALSE;
348 static int g_nRichEditVersion = 0;
353 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
354 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
355 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
356 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
357 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
358 static BOOL InitRichEdit(void);
359 static void LogClipBuffer(void);
360 static void LogCreatePatternMatchingBuffers(void);
361 static void LogDestroyPatternMatchingBuffers(void);
362 static int LogPutStringNoMatch(const char *pszText, int style);
365 /*********************************************************************
367 * Function : InitLogWindow
369 * Description : Initialise the log window.
373 * Returns : Always TRUE (there should be error checking on the resources).
375 *********************************************************************/
376 BOOL InitLogWindow(void)
381 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
382 for (i = 0; i < ANIM_FRAMES; i++)
384 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ANIMATED1 + i));
386 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_MAINICON));
388 /* Create the user interface */
389 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
390 g_hwndTray = CreateTrayWindow(g_hInstance);
391 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Privoxy");
393 /* Create pattern matching buffers (for highlighting */
394 LogCreatePatternMatchingBuffers();
396 /* Create a critical section to protect multi-threaded access to certain things */
397 InitializeCriticalSection(&g_criticalsection);
404 /*********************************************************************
406 * Function : TermLogWindow
408 * Description : Cleanup the logwindow.
414 *********************************************************************/
415 void TermLogWindow(void)
419 LogDestroyPatternMatchingBuffers();
421 TrayDeleteIcon(g_hwndTray, 1);
422 DeleteObject(g_hiconApp);
423 DeleteObject(g_hiconIdle);
424 for (i = 0; i < ANIM_FRAMES; i++)
426 DeleteObject(g_hiconAnim[i]);
432 /*********************************************************************
434 * Function : LogCreatePatternMatchingBuffers
436 * Description : Compile the pattern matching buffers.
442 *********************************************************************/
443 void LogCreatePatternMatchingBuffers(void)
446 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
448 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
453 /*********************************************************************
455 * Function : LogDestroyPatternMatchingBuffers
457 * Description : Free up the pattern matching buffers.
463 *********************************************************************/
464 void LogDestroyPatternMatchingBuffers(void)
467 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
469 regfree(&patterns_to_highlight[i].buffer);
474 /*********************************************************************
476 * Function : LogGetURLUnderCursor
478 * Description : Returns the URL from under the cursor (remember to free it!).
482 * Returns : NULL or a pointer to an URL string.
484 *********************************************************************/
485 char *LogGetURLUnderCursor(void)
487 char *szResult = NULL;
492 DWORD nWordStart = 0;
495 regcomp(&re, RE_URL, REG_ICASE);
497 /* Get the position of the cursor over the text window */
498 GetCursorPos(&ptCursor);
499 ScreenToClient(g_hwndLogBox, &ptCursor);
503 /* Search backwards and fowards to obtain the word that is highlighted */
504 nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
505 nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
506 nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
508 /* Compare the string to the pattern */
509 if (nWordEnd > nWordStart)
514 range.chrg.cpMin = nWordStart;
515 range.chrg.cpMax = nWordEnd;
516 range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
517 SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
519 if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
521 szResult = range.lpstrText;
525 free(range.lpstrText);
535 /*********************************************************************
537 * Function : LogPutString
539 * Description : Inserts text into the logging window. This is really
540 * a regexp aware wrapper function to `LogPutStringNoMatch'.
543 * 1 : pszText = pointer to string going to the log window
545 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
546 * FIXME: this is backwards to the rest of IJB and to common
547 * programming practice. Please use 0 => success instead.
549 *********************************************************************/
550 int LogPutString(const char *pszText)
555 if (pszText == NULL || strlen(pszText) == 0)
565 /* Critical section stops multiple threads doing nasty interactions that
566 * foul up the highlighting and output.
568 EnterCriticalSection(&g_criticalsection);
570 if (g_bHighlightMessages)
574 /* First things first, regexp scan for various things that we would like highlighted */
575 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
577 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
579 char *pszBefore = NULL;
580 char *pszMatch = NULL;
581 char *pszAfter = NULL;
584 /* Split the string up into pieces representing the strings, before
585 at and after the matching pattern
589 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
590 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
591 strncpy(pszBefore, pszText, match.rm_so);
593 if (match.rm_eo < (regoff_t)strlen(pszText))
595 pszAfter = strdup(&pszText[match.rm_eo]);
597 nMatchSize = match.rm_eo - match.rm_so;
598 pszMatch = (char *)malloc(nMatchSize + 1);
599 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
600 pszMatch[nMatchSize] = '\0';
602 /* Recursively call LogPutString */
605 LogPutString(pszBefore);
610 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
615 LogPutString(pszAfter);
625 result = LogPutStringNoMatch(pszText, STYLE_NONE);
628 LeaveCriticalSection(&g_criticalsection);
635 /*********************************************************************
637 * Function : LogPutStringNoMatch
639 * Description : Puts a string into the logging window.
642 * 1 : pszText = pointer to string going to the log window
643 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
645 * Returns : Always 1 => success.
646 * FIXME: this is backwards to the rest of IJB and to common
647 * programming practice. Please use 0 => success instead.
649 *********************************************************************/
650 int LogPutStringNoMatch(const char *pszText, int style)
656 assert(g_hwndLogBox);
657 if (g_hwndLogBox == NULL)
662 /* TODO preserve existing selection */
664 /* Go to the end of the text */
665 nTextLength = GetWindowTextLength(g_hwndLogBox);
666 range.cpMin = nTextLength;
667 range.cpMax = nTextLength;
668 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
670 /* Apply a formatting style */
671 memset(&format, 0, sizeof(format));
672 format.cbSize = sizeof(format);
673 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
674 format.yHeight = (g_nFontSize * 1440) / 72;
675 strcpy(format.szFaceName, g_szFontFaceName);
676 if (style == STYLE_NONE)
679 format.dwEffects |= CFE_AUTOCOLOR;
681 else if (style == STYLE_HEADER)
683 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
685 else if (style == STYLE_HIGHLIGHT)
687 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
689 else if (style == STYLE_LINK)
691 format.dwEffects |= CFE_UNDERLINE;
692 format.crTextColor = RGB(0, 0, 255);
694 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
696 /* Append text to the end */
697 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
699 /* TODO Restore the old selection */
702 if (strchr(pszText, '\n') != NULL)
704 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
707 /* Set the force clip timer going. This timer ensures clipping is done
708 intermittently even when there is a sustained burst of logging
710 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
712 g_bClipPending = TRUE;
720 /*********************************************************************
722 * Function : LogShowActivity
724 * Description : Start the spinner.
730 *********************************************************************/
731 void LogShowActivity(void)
733 /* Start some activity timers */
734 if (g_bShowActivityAnimation)
736 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
737 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
743 /*********************************************************************
745 * Function : LogClipBuffer
747 * Description : Prunes old lines from the log.
753 *********************************************************************/
754 void LogClipBuffer(void)
756 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
757 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
759 /* Compute the range representing the lines to be deleted */
760 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
761 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
764 range.cpMax = nLastChar;
766 /* TODO get current selection */
768 /* TODO adjust and clip old selection against range to be deleted */
770 /* Select range and erase it (turning off autoscroll to prevent
772 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
773 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
774 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
775 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
777 /* reposition (back to) the end of the log content */
778 range.cpMin = SendMessage (g_hwndLogBox, WM_GETTEXTLENGTH, 0, 0);
780 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
782 /* restore vertical ScrollBar stuff (messed up by AUTOVSCROLL) */
783 SendMessage (g_hwndLogBox, EM_SCROLL, SB_LINEDOWN, 0);
790 /*********************************************************************
792 * Function : CreateHiddenLogOwnerWindow
794 * Description : Creates a hidden owner window that stops the log
795 * window appearing in the task bar.
798 * 1 : hInstance = application's instance handle
800 * Returns : Handle to newly created window.
802 *********************************************************************/
803 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
805 static const char *szWndName = "PrivoxyLogOwner";
810 wc.lpfnWndProc = LogOwnerWindowProc;
813 wc.hInstance = hInstance;
816 wc.hbrBackground = 0;
818 wc.lpszClassName = szWndName;
822 hwnd = CreateWindow(szWndName, szWndName,
823 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
824 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
831 /*********************************************************************
833 * Function : LogOwnerWindowProc
835 * Description : Dummy procedure that does nothing special.
838 * 1 : hwnd = window handle
839 * 2 : uMsg = message number
840 * 3 : wParam = first param for this message
841 * 4 : lParam = next param for this message
843 * Returns : Same as `DefWindowProc'.
845 *********************************************************************/
846 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
848 return DefWindowProc(hwnd, uMsg, wParam, lParam);
853 /*********************************************************************
855 * Function : CreateLogWindow
857 * Description : Create the logging window.
860 * 1 : hInstance = application's instance handle
861 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
863 * Returns : Handle to newly created window.
865 *********************************************************************/
866 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
868 static const char *szWndName = "PrivoxyLogWindow";
869 static const char *szWndTitle = "Privoxy";
872 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
876 memset(&wc, 0, sizeof(wc));
877 wc.cbSize = sizeof(wc);
878 wc.style = CS_DBLCLKS;
879 wc.lpfnWndProc = LogWindowProc;
882 wc.hInstance = hInstance;
883 wc.hIcon = g_hiconApp;
885 wc.hbrBackground = 0;
886 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
887 wc.lpszClassName = szWndName;
888 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
889 RegisterClassEx(&wc);
891 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
892 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
893 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
895 /* Now create a child list box */
896 GetClientRect(hwnd, &rcClient);
898 /* Create a rich edit control */
900 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
901 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
902 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
903 hwnd, NULL, hInstance, NULL);
904 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
906 /* Subclass the control to catch certain messages */
907 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
908 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
910 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
911 if (!g_bShowOnTaskBar &&
912 (nCmdShow == SW_SHOWMINIMIZED ||
913 nCmdShow == SW_MINIMIZE ||
914 nCmdShow == SW_SHOWMINNOACTIVE))
916 g_bShowLogWindow = FALSE;
920 ShowWindow(hwnd, nCmdShow);
924 GetClientRect(g_hwndLogFrame, &rcClient);
925 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
932 /*********************************************************************
934 * Function : InitRichEdit
936 * Description : Initialise the rich edit control library.
940 * Returns : TRUE => success, FALSE => failure.
941 * FIXME: this is backwards to the rest of IJB and to common
942 * programming practice. Please use 0 => success instead.
944 *********************************************************************/
945 BOOL InitRichEdit(void)
947 static HINSTANCE hInstRichEdit;
948 if (hInstRichEdit == NULL)
950 g_nRichEditVersion = 0;
951 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
954 g_nRichEditVersion = _RICHEDIT_VER;
958 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
961 g_nRichEditVersion = 0x0100;
965 return (hInstRichEdit != NULL) ? TRUE : FALSE;
970 /*********************************************************************
972 * Function : ShowLogWindow
974 * Description : Shows or hides the log window. We will also raise the
975 * window on a show command in case it is buried.
978 * 1 : bShow = TRUE to show, FALSE to mimize/hide
982 *********************************************************************/
983 void ShowLogWindow(BOOL bShow)
987 SetForegroundWindow(g_hwndLogFrame);
988 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
991 else if (g_bShowOnTaskBar)
993 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
997 ShowWindow(g_hwndLogFrame, SW_HIDE);
1002 /*********************************************************************
1004 * Function : EditFile
1006 * Description : Opens the specified setting file for editing.
1007 * FIXME: What if the file has no associated application. Check for return values
1008 * from ShellExecute??
1011 * 1 : filename = filename from the config (aka config.txt) file.
1015 *********************************************************************/
1016 void EditFile(const char *filename)
1020 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
1026 /*--------------------------------------------------------------------------*/
1027 /* Windows message handlers */
1028 /*--------------------------------------------------------------------------*/
1031 /*********************************************************************
1033 * Function : OnLogRButtonUp
1035 * Description : Handler for WM_RBUTTONUP messages.
1038 * 1 : nModifier = wParam from mouse message (unused)
1039 * 2 : x = x coordinate of the mouse event
1040 * 3 : y = y coordinate of the mouse event
1044 *********************************************************************/
1045 void OnLogRButtonUp(int nModifier, int x, int y)
1047 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
1050 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
1052 /* Check if there is a selection */
1054 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
1055 if (range.cpMin == range.cpMax)
1057 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
1061 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
1064 /* Display the popup */
1065 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
1072 /*********************************************************************
1074 * Function : OnLogCommand
1076 * Description : Handler for WM_COMMAND messages.
1079 * 1 : nCommand = the command portion of the menu selection event
1083 *********************************************************************/
1084 void OnLogCommand(int nCommand)
1088 case ID_TOGGLE_SHOWWINDOW:
1089 g_bShowLogWindow = !g_bShowLogWindow;
1091 ShowLogWindow(g_bShowLogWindow);
1095 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1099 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1102 case ID_VIEW_CLEARLOG:
1103 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1106 case ID_VIEW_LOGMESSAGES:
1107 g_bLogMessages = !g_bLogMessages;
1108 /* SaveLogSettings(); */
1111 case ID_VIEW_MESSAGEHIGHLIGHTING:
1112 g_bHighlightMessages = !g_bHighlightMessages;
1113 /* SaveLogSettings(); */
1116 case ID_VIEW_LIMITBUFFERSIZE:
1117 g_bLimitBufferSize = !g_bLimitBufferSize;
1118 /* SaveLogSettings(); */
1121 case ID_VIEW_ACTIVITYANIMATION:
1122 g_bShowActivityAnimation = !g_bShowActivityAnimation;
1123 /* SaveLogSettings(); */
1126 #ifdef FEATURE_TOGGLE
1127 /* by haroon - change toggle to its opposite value */
1128 case ID_TOGGLE_ENABLED:
1129 global_toggle_state = !global_toggle_state;
1130 if (global_toggle_state)
1132 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1136 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1139 #endif /* def FEATURE_TOGGLE */
1141 case ID_TOOLS_EDITCONFIG:
1142 EditFile(configfile);
1145 case ID_TOOLS_EDITDEFAULTACTIONS:
1146 EditFile(g_default_actions_file);
1149 case ID_TOOLS_EDITUSERACTIONS:
1150 EditFile(g_user_actions_file);
1153 case ID_TOOLS_EDITFILTERS:
1154 EditFile(g_re_filterfile);
1157 #ifdef FEATURE_TRUST
1158 case ID_TOOLS_EDITTRUST:
1159 EditFile(g_trustfile);
1161 #endif /* def FEATURE_TRUST */
1164 ShellExecute(g_hwndLogFrame, "open", "LICENSE.txt", NULL, NULL, SW_SHOWNORMAL);
1168 ShellExecute(g_hwndLogFrame, "open", "doc\\faq\\index.html", NULL, NULL, SW_SHOWNORMAL);
1171 case ID_HELP_MANUAL:
1172 ShellExecute(g_hwndLogFrame, "open", "doc\\user-manual\\index.html", NULL, NULL, SW_SHOWNORMAL);
1175 case ID_HELP_STATUS:
1176 ShellExecute(g_hwndLogFrame, "open", CGI_PREFIX "show-status", NULL, NULL, SW_SHOWNORMAL);
1180 MessageBox(g_hwndLogFrame, win32_blurb, "About Privoxy", MB_OK);
1191 /*********************************************************************
1193 * Function : OnLogInitMenu
1195 * Description : Handler for WM_INITMENU messages. Enable, disable,
1196 * check, and/or uncheck menu options as apropos.
1199 * 1 : hmenu = handle to menu to "make current"
1203 *********************************************************************/
1204 void OnLogInitMenu(HMENU hmenu)
1206 /* Only enable editors if there is a file to edit */
1207 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTACTIONS, MF_BYCOMMAND | (g_default_actions_file ? MF_ENABLED : MF_GRAYED));
1208 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERACTIONS, MF_BYCOMMAND | (g_user_actions_file ? MF_ENABLED : MF_GRAYED));
1209 EnableMenuItem(hmenu, ID_TOOLS_EDITFILTERS, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1210 #ifdef FEATURE_TRUST
1211 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1212 #endif /* def FEATURE_TRUST */
1214 /* Check/uncheck options */
1215 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1216 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1217 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1218 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1219 #ifdef FEATURE_TOGGLE
1220 /* by haroon - menu item for Enable toggle on/off */
1221 CheckMenuItem(hmenu, ID_TOGGLE_ENABLED, MF_BYCOMMAND | (global_toggle_state ? MF_CHECKED : MF_UNCHECKED));
1222 #endif /* def FEATURE_TOGGLE */
1223 CheckMenuItem(hmenu, ID_TOGGLE_SHOWWINDOW, MF_BYCOMMAND | (g_bShowLogWindow ? MF_CHECKED : MF_UNCHECKED));
1228 /*********************************************************************
1230 * Function : OnLogTimer
1232 * Description : Handler for WM_TIMER messages.
1235 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1239 *********************************************************************/
1240 void OnLogTimer(int nTimer)
1245 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1248 case TIMER_ANIMSTOP_ID:
1250 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1251 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1252 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1255 case TIMER_CLIPBUFFER_ID:
1256 case TIMER_CLIPBUFFER_FORCE_ID:
1258 g_bClipPending = FALSE;
1259 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1260 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1271 /*********************************************************************
1273 * Function : LogRichEditProc
1275 * Description : Window subclass routine handles some events for the rich edit control.
1278 * 1 : hwnd = window handle of the rich edit control
1279 * 2 : uMsg = message number
1280 * 3 : wParam = first param for this message
1281 * 4 : lParam = next param for this message
1283 * Returns : Appropriate M$ window message handler codes.
1285 *********************************************************************/
1286 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1293 pt.x = LOWORD(lParam);
1294 pt.y = HIWORD(lParam);
1295 ClientToScreen(hwnd, &pt);
1296 OnLogRButtonUp(wParam, pt.x, pt.y);
1300 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1305 /*********************************************************************
1307 * Function : LogWindowProc
1309 * Description : Windows call back routine handles events on the log window.
1312 * 1 : hwnd = handle of the logging window
1313 * 2 : uMsg = message number
1314 * 3 : wParam = first param for this message
1315 * 4 : lParam = next param for this message
1317 * Returns : Appropriate M$ window message handler codes.
1319 *********************************************************************/
1320 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1328 /* This is the end - beautiful friend - the end */
1329 DestroyWindow(g_hwndLogBox);
1330 DestroyWindow(g_hwndLogFrame);
1338 g_bShowLogWindow = wParam;
1340 /* Resize the logging window to fit the new frame */
1344 GetClientRect(g_hwndLogFrame, &rc);
1345 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1350 OnLogInitMenu((HMENU) wParam);
1358 OnLogCommand(LOWORD(wParam));
1365 if (g_bCloseHidesWindow)
1367 ShowLogWindow(FALSE);
1372 ShowLogWindow(FALSE);
1378 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1382 #endif /* ndef _WIN_CONSOLE - entire file */