1 const char w32log_rcs[] = "$Id: w32log.c,v 1.25.2.4 2003/03/11 11:53:59 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.4 2003/03/11 11:53:59 oes
36 * Cosmetic: Renamed cryptic variable
38 * Revision 1.25.2.3 2002/11/20 14:39:05 oes
39 * Fixed compiler warning
41 * Revision 1.25.2.2 2002/09/25 15:23:10 oes
42 * Uncheck the "Show Privoxy Window" taskbar menu item when window gets minimized. Fixes bug #606804
44 * Revision 1.25.2.1 2002/08/21 17:59:05 oes
45 * - "Show Privoxy Window" now a toggle
46 * - Temp kludge to let user and default action file be edited through win32 GUI (FR 592080)
48 * Revision 1.25 2002/04/04 00:36:36 gliptak
49 * always use pcre for matching
51 * Revision 1.24 2002/03/31 17:19:00 jongfoster
52 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
54 * Revision 1.23 2002/03/26 22:57:10 jongfoster
55 * Web server name should begin www.
57 * Revision 1.22 2002/03/24 12:48:23 jongfoster
60 * Revision 1.21 2002/03/24 12:07:35 jongfoster
61 * Consistern name for filters file
63 * Revision 1.20 2002/03/24 12:03:47 jongfoster
66 * Revision 1.19 2002/01/17 21:04:17 jongfoster
67 * Replacing hard references to the URL of the config interface
68 * with #defines from project.h
70 * Revision 1.18 2001/11/30 23:37:24 jongfoster
71 * Renaming the Win32 config file to config.txt - this is almost the
72 * same as the corresponding UNIX name "config"
74 * Revision 1.17 2001/11/16 00:46:31 jongfoster
75 * Fixing compiler warnings
77 * Revision 1.16 2001/08/01 19:58:12 jongfoster
78 * Fixing documentation filenames in help menu, and making status
79 * option work without needing the "Junkbuster Status.URL" file.
81 * Revision 1.15 2001/07/30 22:08:36 jongfoster
82 * Tidying up #defines:
83 * - All feature #defines are now of the form FEATURE_xxx
84 * - Permanently turned off WIN_GUI_EDIT
85 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
87 * Revision 1.14 2001/07/29 18:47:05 jongfoster
88 * Adding missing #include "loadcfg.h"
90 * Revision 1.13 2001/07/19 19:15:14 haroon
91 * - Added a FIXME for EditFile but didn't fix :-)
93 * Revision 1.12 2001/07/13 14:04:59 oes
94 * Removed all #ifdef PCRS
96 * Revision 1.11 2001/06/07 23:08:12 jongfoster
97 * Forward and ACL edit options removed.
99 * Revision 1.10 2001/05/31 21:37:11 jongfoster
100 * GUI changes to rename "permissions file" to "actions file".
102 * Revision 1.9 2001/05/31 17:33:13 oes
106 * Revision 1.8 2001/05/29 09:50:24 jongfoster
107 * Unified blocklist/imagelist/permissionslist.
108 * File format is still under discussion, but the internal changes
111 * Also modified interceptor behaviour:
112 * - We now intercept all URLs beginning with one of the following
113 * prefixes (and *only* these prefixes):
115 * * http://ijbswa.sf.net/config/
116 * * http://ijbswa.sourceforge.net/config/
117 * - New interceptors "home page" - go to http://i.j.b/ to see it.
118 * - Internal changes so that intercepted and fast redirect pages
119 * are not replaced with an image.
120 * - Interceptors now have the option to send a binary page direct
121 * to the client. (i.e. ijb-send-banner uses this)
122 * - Implemented show-url-info interceptor. (Which is why I needed
123 * the above interceptors changes - a typical URL is
124 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
125 * The previous mechanism would not have intercepted that, and
126 * if it had been intercepted then it then it would have replaced
129 * Revision 1.7 2001/05/26 01:26:34 jongfoster
130 * New #define, WIN_GUI_EDIT, enables the (embryonic) Win32 GUI editor.
131 * This #define cannot be set from ./configure - there's no point, it
132 * doesn't work yet. See feature request # 425722
134 * Revision 1.6 2001/05/26 00:31:30 jongfoster
135 * Fixing compiler warning about comparing signed/unsigned.
137 * Revision 1.5 2001/05/26 00:28:36 jongfoster
138 * Automatic reloading of config file.
139 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
140 * Most of the global variables have been moved to a new
141 * struct configuration_spec, accessed through csp->config->globalname
142 * Most of the globals remaining are used by the Win32 GUI.
144 * Revision 1.4 2001/05/22 18:56:28 oes
147 * Revision 1.3 2001/05/20 15:07:54 jongfoster
148 * File is now ignored if _WIN_CONSOLE is defined.
150 * Revision 1.2 2001/05/20 01:21:20 jongfoster
151 * Version 2.9.4 checkin.
152 * - Merged popupfile and cookiefile, and added control over PCRS
153 * filtering, in new "permissionsfile".
154 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
155 * file error you now get a message box (in the Win32 GUI) rather
156 * than the program exiting with no explanation.
157 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
159 * - Removed tabs from "config"
160 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
161 * - Bumped up version number.
163 * Revision 1.1.1.1 2001/05/15 13:59:07 oes
164 * Initial import of version 2.9.3 source tree
167 *********************************************************************/
179 #include <richedit.h>
183 #include "w32taskbar.h"
187 #include "miscutil.h"
191 const char w32res_h_rcs[] = W32RES_H_VERSION;
195 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
198 const char w32log_h_rcs[] = W32LOG_H_VERSION;
200 #ifndef _WIN_CONSOLE /* entire file */
203 * Timers and the various durations
205 #define TIMER_ANIM_ID 1
206 #define TIMER_ANIM_TIME 100
207 #define TIMER_ANIMSTOP_ID 2
208 #define TIMER_ANIMSTOP_TIME 1000
209 #define TIMER_CLIPBUFFER_ID 3
210 #define TIMER_CLIPBUFFER_TIME 1000
211 #define TIMER_CLIPBUFFER_FORCE_ID 4
212 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
215 * Styles of text that can be output
218 #define STYLE_HIGHLIGHT 1
220 #define STYLE_HEADER 3
223 * Number of frames of animation in tray activity sequence
225 #define ANIM_FRAMES 8
227 #define DEFAULT_MAX_BUFFER_LINES 200
228 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
229 #define DEFAULT_LOG_FONT_SIZE 8
232 * These values affect the way the log window behaves, they should be read
233 * from a file but for the moment, they are hardcoded here. Some options are
234 * configurable through the UI.
237 /* Indicates whether task bar shows activity animation */
238 BOOL g_bShowActivityAnimation = 1;
240 /* Indicates whether the log window is shown */
241 BOOL g_bShowLogWindow = 1;
243 /* Indicates if the log window appears on the task bar */
244 BOOL g_bShowOnTaskBar = 0;
246 /* Indicates whether closing the log window really just hides it */
247 BOOL g_bCloseHidesWindow = 1;
249 /* Indicates if messages are logged at all */
250 BOOL g_bLogMessages = 1;
252 /* Indicates whether log messages are highlighted */
253 BOOL g_bHighlightMessages = 1;
255 /* Indicates if buffer is limited in size */
256 BOOL g_bLimitBufferSize = 1;
258 /* Maximum number of lines allowed in buffer when limited */
259 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
262 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
264 /* Size of font to use */
265 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
268 /* FIXME: this is a kludge */
270 const char * g_default_actions_file = NULL;
271 const char * g_user_actions_file = NULL;
272 const char * g_re_filterfile = NULL;
274 const char * g_trustfile = NULL;
275 #endif /* def FEATURE_TRUST */
277 /* FIXME: end kludge */
279 /* Regular expression for detected URLs */
280 #define RE_URL "http:[^ \n\r]*"
283 * Regular expressions that are used to perform highlight in the log window
285 static struct _Pattern
290 } patterns_to_highlight[] =
293 { RE_URL, STYLE_LINK },
294 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
295 /* interesting text to highlight */
296 { "crunch!", STYLE_HIGHLIGHT },
298 { "referer:", STYLE_HEADER },
299 { "proxy-connection:", STYLE_HEADER },
300 { "proxy-agent:", STYLE_HEADER },
301 { "user-agent:", STYLE_HEADER },
302 { "host:", STYLE_HEADER },
303 { "accept:", STYLE_HEADER },
304 { "accept-encoding:", STYLE_HEADER },
305 { "accept-language:", STYLE_HEADER },
306 { "accept-charset:", STYLE_HEADER },
307 { "accept-ranges:", STYLE_HEADER },
308 { "date:", STYLE_HEADER },
309 { "cache-control:", STYLE_HEADER },
310 { "cache-last-checked:", STYLE_HEADER },
311 { "connection:", STYLE_HEADER },
312 { "content-type", STYLE_HEADER },
313 { "content-length", STYLE_HEADER },
314 { "cookie", STYLE_HEADER },
315 { "last-modified:", STYLE_HEADER },
316 { "pragma:", STYLE_HEADER },
317 { "server:", STYLE_HEADER },
318 { "etag:", STYLE_HEADER },
319 { "expires:", STYLE_HEADER },
320 { "warning:", STYLE_HEADER },
321 /* this is the terminator statement - do not delete! */
334 static CRITICAL_SECTION g_criticalsection;
335 static HWND g_hwndTray;
336 static HWND g_hwndLogBox;
337 static WNDPROC g_fnLogBox;
338 static HICON g_hiconAnim[ANIM_FRAMES];
339 static HICON g_hiconIdle;
340 static int g_nAnimFrame;
341 static BOOL g_bClipPending = FALSE;
342 static int g_nRichEditVersion = 0;
347 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
348 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
349 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
350 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
351 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
352 static BOOL InitRichEdit(void);
353 static void LogClipBuffer(void);
354 static void LogCreatePatternMatchingBuffers(void);
355 static void LogDestroyPatternMatchingBuffers(void);
356 static int LogPutStringNoMatch(const char *pszText, int style);
359 /*********************************************************************
361 * Function : InitLogWindow
363 * Description : Initialise the log window.
367 * Returns : Always TRUE (there should be error checking on the resources).
369 *********************************************************************/
370 BOOL InitLogWindow(void)
375 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
376 for (i = 0; i < ANIM_FRAMES; i++)
378 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ANIMATED1 + i));
380 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_MAINICON));
382 /* Create the user interface */
383 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
384 g_hwndTray = CreateTrayWindow(g_hInstance);
385 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Privoxy");
387 /* Create pattern matching buffers (for highlighting */
388 LogCreatePatternMatchingBuffers();
390 /* Create a critical section to protect multi-threaded access to certain things */
391 InitializeCriticalSection(&g_criticalsection);
398 /*********************************************************************
400 * Function : TermLogWindow
402 * Description : Cleanup the logwindow.
408 *********************************************************************/
409 void TermLogWindow(void)
413 LogDestroyPatternMatchingBuffers();
415 TrayDeleteIcon(g_hwndTray, 1);
416 DeleteObject(g_hiconApp);
417 DeleteObject(g_hiconIdle);
418 for (i = 0; i < ANIM_FRAMES; i++)
420 DeleteObject(g_hiconAnim[i]);
426 /*********************************************************************
428 * Function : LogCreatePatternMatchingBuffers
430 * Description : Compile the pattern matching buffers.
436 *********************************************************************/
437 void LogCreatePatternMatchingBuffers(void)
440 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
442 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
447 /*********************************************************************
449 * Function : LogDestroyPatternMatchingBuffers
451 * Description : Free up the pattern matching buffers.
457 *********************************************************************/
458 void LogDestroyPatternMatchingBuffers(void)
461 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
463 regfree(&patterns_to_highlight[i].buffer);
468 /*********************************************************************
470 * Function : LogGetURLUnderCursor
472 * Description : Returns the URL from under the cursor (remember to free it!).
476 * Returns : NULL or a pointer to an URL string.
478 *********************************************************************/
479 char *LogGetURLUnderCursor(void)
481 char *szResult = NULL;
486 DWORD nWordStart = 0;
489 regcomp(&re, RE_URL, REG_ICASE);
491 /* Get the position of the cursor over the text window */
492 GetCursorPos(&ptCursor);
493 ScreenToClient(g_hwndLogBox, &ptCursor);
497 /* Search backwards and fowards to obtain the word that is highlighted */
498 nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
499 nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
500 nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
502 /* Compare the string to the pattern */
503 if (nWordEnd > nWordStart)
508 range.chrg.cpMin = nWordStart;
509 range.chrg.cpMax = nWordEnd;
510 range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
511 SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
513 if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
515 szResult = range.lpstrText;
519 free(range.lpstrText);
529 /*********************************************************************
531 * Function : LogPutString
533 * Description : Inserts text into the logging window. This is really
534 * a regexp aware wrapper function to `LogPutStringNoMatch'.
537 * 1 : pszText = pointer to string going to the log window
539 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
540 * FIXME: this is backwards to the rest of IJB and to common
541 * programming practice. Please use 0 => success instead.
543 *********************************************************************/
544 int LogPutString(const char *pszText)
549 if (pszText == NULL || strlen(pszText) == 0)
559 /* Critical section stops multiple threads doing nasty interactions that
560 * foul up the highlighting and output.
562 EnterCriticalSection(&g_criticalsection);
564 if (g_bHighlightMessages)
568 /* First things first, regexp scan for various things that we would like highlighted */
569 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
571 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
573 char *pszBefore = NULL;
574 char *pszMatch = NULL;
575 char *pszAfter = NULL;
578 /* Split the string up into pieces representing the strings, before
579 at and after the matching pattern
583 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
584 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
585 strncpy(pszBefore, pszText, match.rm_so);
587 if (match.rm_eo < (regoff_t)strlen(pszText))
589 pszAfter = strdup(&pszText[match.rm_eo]);
591 nMatchSize = match.rm_eo - match.rm_so;
592 pszMatch = (char *)malloc(nMatchSize + 1);
593 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
594 pszMatch[nMatchSize] = '\0';
596 /* Recursively call LogPutString */
599 LogPutString(pszBefore);
604 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
609 LogPutString(pszAfter);
619 result = LogPutStringNoMatch(pszText, STYLE_NONE);
622 LeaveCriticalSection(&g_criticalsection);
629 /*********************************************************************
631 * Function : LogPutStringNoMatch
633 * Description : Puts a string into the logging window.
636 * 1 : pszText = pointer to string going to the log window
637 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
639 * Returns : Always 1 => success.
640 * FIXME: this is backwards to the rest of IJB and to common
641 * programming practice. Please use 0 => success instead.
643 *********************************************************************/
644 int LogPutStringNoMatch(const char *pszText, int style)
650 assert(g_hwndLogBox);
651 if (g_hwndLogBox == NULL)
656 /* TODO preserve existing selection */
658 /* Go to the end of the text */
659 nTextLength = GetWindowTextLength(g_hwndLogBox);
660 range.cpMin = nTextLength;
661 range.cpMax = nTextLength;
662 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
664 /* Apply a formatting style */
665 memset(&format, 0, sizeof(format));
666 format.cbSize = sizeof(format);
667 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
668 format.yHeight = (g_nFontSize * 1440) / 72;
669 strcpy(format.szFaceName, g_szFontFaceName);
670 if (style == STYLE_NONE)
673 format.dwEffects |= CFE_AUTOCOLOR;
675 else if (style == STYLE_HEADER)
677 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
679 else if (style == STYLE_HIGHLIGHT)
681 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
683 else if (style == STYLE_LINK)
685 format.dwEffects |= CFE_UNDERLINE;
686 format.crTextColor = RGB(0, 0, 255);
688 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
690 /* Append text to the end */
691 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
693 /* TODO Restore the old selection */
696 if (strchr(pszText, '\n') != NULL)
698 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
701 /* Set the force clip timer going. This timer ensures clipping is done
702 intermittently even when there is a sustained burst of logging
704 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
706 g_bClipPending = TRUE;
714 /*********************************************************************
716 * Function : LogShowActivity
718 * Description : Start the spinner.
724 *********************************************************************/
725 void LogShowActivity(void)
727 /* Start some activity timers */
728 if (g_bShowActivityAnimation)
730 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
731 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
737 /*********************************************************************
739 * Function : LogClipBuffer
741 * Description : Prunes old lines from the log.
747 *********************************************************************/
748 void LogClipBuffer(void)
750 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
751 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
753 /* Compute the range representing the lines to be deleted */
754 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
755 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
758 range.cpMax = nLastChar;
760 /* TODO get current selection */
762 /* TODO adjust and clip old selection against range to be deleted */
764 /* Select range and erase it (turning off autoscroll to prevent
766 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
767 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
768 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
769 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
771 /* reposition (back to) the end of the log content */
772 range.cpMin = SendMessage (g_hwndLogBox, WM_GETTEXTLENGTH, 0, 0);
774 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
776 /* restore vertical ScrollBar stuff (messed up by AUTOVSCROLL) */
777 SendMessage (g_hwndLogBox, EM_SCROLL, SB_LINEDOWN, 0);
784 /*********************************************************************
786 * Function : CreateHiddenLogOwnerWindow
788 * Description : Creates a hidden owner window that stops the log
789 * window appearing in the task bar.
792 * 1 : hInstance = application's instance handle
794 * Returns : Handle to newly created window.
796 *********************************************************************/
797 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
799 static const char *szWndName = "PrivoxyLogOwner";
804 wc.lpfnWndProc = LogOwnerWindowProc;
807 wc.hInstance = hInstance;
810 wc.hbrBackground = 0;
812 wc.lpszClassName = szWndName;
816 hwnd = CreateWindow(szWndName, szWndName,
817 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
818 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
825 /*********************************************************************
827 * Function : LogOwnerWindowProc
829 * Description : Dummy procedure that does nothing special.
832 * 1 : hwnd = window handle
833 * 2 : uMsg = message number
834 * 3 : wParam = first param for this message
835 * 4 : lParam = next param for this message
837 * Returns : Same as `DefWindowProc'.
839 *********************************************************************/
840 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
842 return DefWindowProc(hwnd, uMsg, wParam, lParam);
847 /*********************************************************************
849 * Function : CreateLogWindow
851 * Description : Create the logging window.
854 * 1 : hInstance = application's instance handle
855 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
857 * Returns : Handle to newly created window.
859 *********************************************************************/
860 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
862 static const char *szWndName = "PrivoxyLogWindow";
863 static const char *szWndTitle = "Privoxy";
866 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
870 memset(&wc, 0, sizeof(wc));
871 wc.cbSize = sizeof(wc);
872 wc.style = CS_DBLCLKS;
873 wc.lpfnWndProc = LogWindowProc;
876 wc.hInstance = hInstance;
877 wc.hIcon = g_hiconApp;
879 wc.hbrBackground = 0;
880 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
881 wc.lpszClassName = szWndName;
882 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
883 RegisterClassEx(&wc);
885 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
886 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
887 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
889 /* Now create a child list box */
890 GetClientRect(hwnd, &rcClient);
892 /* Create a rich edit control */
894 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
895 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
896 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
897 hwnd, NULL, hInstance, NULL);
898 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
900 /* Subclass the control to catch certain messages */
901 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
902 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
904 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
905 if (!g_bShowOnTaskBar &&
906 (nCmdShow == SW_SHOWMINIMIZED ||
907 nCmdShow == SW_MINIMIZE ||
908 nCmdShow == SW_SHOWMINNOACTIVE))
910 g_bShowLogWindow = FALSE;
914 ShowWindow(hwnd, nCmdShow);
918 GetClientRect(g_hwndLogFrame, &rcClient);
919 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
926 /*********************************************************************
928 * Function : InitRichEdit
930 * Description : Initialise the rich edit control library.
934 * Returns : TRUE => success, FALSE => failure.
935 * FIXME: this is backwards to the rest of IJB and to common
936 * programming practice. Please use 0 => success instead.
938 *********************************************************************/
939 BOOL InitRichEdit(void)
941 static HINSTANCE hInstRichEdit;
942 if (hInstRichEdit == NULL)
944 g_nRichEditVersion = 0;
945 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
948 g_nRichEditVersion = _RICHEDIT_VER;
952 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
955 g_nRichEditVersion = 0x0100;
959 return (hInstRichEdit != NULL) ? TRUE : FALSE;
964 /*********************************************************************
966 * Function : ShowLogWindow
968 * Description : Shows or hides the log window. We will also raise the
969 * window on a show command in case it is buried.
972 * 1 : bShow = TRUE to show, FALSE to mimize/hide
976 *********************************************************************/
977 void ShowLogWindow(BOOL bShow)
981 SetForegroundWindow(g_hwndLogFrame);
982 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
985 else if (g_bShowOnTaskBar)
987 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
991 ShowWindow(g_hwndLogFrame, SW_HIDE);
996 /*********************************************************************
998 * Function : EditFile
1000 * Description : Opens the specified setting file for editing.
1001 * FIXME: What if the file has no associated application. Check for return values
1002 * from ShellExecute??
1005 * 1 : filename = filename from the config (aka config.txt) file.
1009 *********************************************************************/
1010 void EditFile(const char *filename)
1014 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
1020 /*--------------------------------------------------------------------------*/
1021 /* Windows message handlers */
1022 /*--------------------------------------------------------------------------*/
1025 /*********************************************************************
1027 * Function : OnLogRButtonUp
1029 * Description : Handler for WM_RBUTTONUP messages.
1032 * 1 : nModifier = wParam from mouse message (unused)
1033 * 2 : x = x coordinate of the mouse event
1034 * 3 : y = y coordinate of the mouse event
1038 *********************************************************************/
1039 void OnLogRButtonUp(int nModifier, int x, int y)
1041 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
1044 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
1046 /* Check if there is a selection */
1048 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
1049 if (range.cpMin == range.cpMax)
1051 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
1055 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
1058 /* Display the popup */
1059 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
1066 /*********************************************************************
1068 * Function : OnLogCommand
1070 * Description : Handler for WM_COMMAND messages.
1073 * 1 : nCommand = the command portion of the menu selection event
1077 *********************************************************************/
1078 void OnLogCommand(int nCommand)
1082 case ID_TOGGLE_SHOWWINDOW:
1083 g_bShowLogWindow = !g_bShowLogWindow;
1085 ShowLogWindow(g_bShowLogWindow);
1089 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1093 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1096 case ID_VIEW_CLEARLOG:
1097 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1100 case ID_VIEW_LOGMESSAGES:
1101 g_bLogMessages = !g_bLogMessages;
1102 /* SaveLogSettings(); */
1105 case ID_VIEW_MESSAGEHIGHLIGHTING:
1106 g_bHighlightMessages = !g_bHighlightMessages;
1107 /* SaveLogSettings(); */
1110 case ID_VIEW_LIMITBUFFERSIZE:
1111 g_bLimitBufferSize = !g_bLimitBufferSize;
1112 /* SaveLogSettings(); */
1115 case ID_VIEW_ACTIVITYANIMATION:
1116 g_bShowActivityAnimation = !g_bShowActivityAnimation;
1117 /* SaveLogSettings(); */
1120 #ifdef FEATURE_TOGGLE
1121 /* by haroon - change toggle to its opposite value */
1122 case ID_TOGGLE_ENABLED:
1123 global_toggle_state = !global_toggle_state;
1124 if (global_toggle_state)
1126 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1130 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1133 #endif /* def FEATURE_TOGGLE */
1135 case ID_TOOLS_EDITCONFIG:
1136 EditFile(configfile);
1139 case ID_TOOLS_EDITDEFAULTACTIONS:
1140 EditFile(g_default_actions_file);
1143 case ID_TOOLS_EDITUSERACTIONS:
1144 EditFile(g_user_actions_file);
1147 case ID_TOOLS_EDITFILTERS:
1148 EditFile(g_re_filterfile);
1151 #ifdef FEATURE_TRUST
1152 case ID_TOOLS_EDITTRUST:
1153 EditFile(g_trustfile);
1155 #endif /* def FEATURE_TRUST */
1158 ShellExecute(g_hwndLogFrame, "open", "LICENSE.txt", NULL, NULL, SW_SHOWNORMAL);
1162 ShellExecute(g_hwndLogFrame, "open", "doc\\faq\\index.html", NULL, NULL, SW_SHOWNORMAL);
1165 case ID_HELP_MANUAL:
1166 ShellExecute(g_hwndLogFrame, "open", "doc\\user-manual\\index.html", NULL, NULL, SW_SHOWNORMAL);
1169 case ID_HELP_STATUS:
1170 ShellExecute(g_hwndLogFrame, "open", CGI_PREFIX "show-status", NULL, NULL, SW_SHOWNORMAL);
1174 MessageBox(g_hwndLogFrame, win32_blurb, "About Privoxy", MB_OK);
1185 /*********************************************************************
1187 * Function : OnLogInitMenu
1189 * Description : Handler for WM_INITMENU messages. Enable, disable,
1190 * check, and/or uncheck menu options as apropos.
1193 * 1 : hmenu = handle to menu to "make current"
1197 *********************************************************************/
1198 void OnLogInitMenu(HMENU hmenu)
1200 /* Only enable editors if there is a file to edit */
1201 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTACTIONS, MF_BYCOMMAND | (g_default_actions_file ? MF_ENABLED : MF_GRAYED));
1202 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERACTIONS, MF_BYCOMMAND | (g_user_actions_file ? MF_ENABLED : MF_GRAYED));
1203 EnableMenuItem(hmenu, ID_TOOLS_EDITFILTERS, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1204 #ifdef FEATURE_TRUST
1205 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1206 #endif /* def FEATURE_TRUST */
1208 /* Check/uncheck options */
1209 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1210 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1211 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1212 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1213 #ifdef FEATURE_TOGGLE
1214 /* by haroon - menu item for Enable toggle on/off */
1215 CheckMenuItem(hmenu, ID_TOGGLE_ENABLED, MF_BYCOMMAND | (global_toggle_state ? MF_CHECKED : MF_UNCHECKED));
1216 #endif /* def FEATURE_TOGGLE */
1217 CheckMenuItem(hmenu, ID_TOGGLE_SHOWWINDOW, MF_BYCOMMAND | (g_bShowLogWindow ? MF_CHECKED : MF_UNCHECKED));
1222 /*********************************************************************
1224 * Function : OnLogTimer
1226 * Description : Handler for WM_TIMER messages.
1229 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1233 *********************************************************************/
1234 void OnLogTimer(int nTimer)
1239 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1242 case TIMER_ANIMSTOP_ID:
1244 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1245 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1246 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1249 case TIMER_CLIPBUFFER_ID:
1250 case TIMER_CLIPBUFFER_FORCE_ID:
1252 g_bClipPending = FALSE;
1253 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1254 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1265 /*********************************************************************
1267 * Function : LogRichEditProc
1269 * Description : Window subclass routine handles some events for the rich edit control.
1272 * 1 : hwnd = window handle of the rich edit control
1273 * 2 : uMsg = message number
1274 * 3 : wParam = first param for this message
1275 * 4 : lParam = next param for this message
1277 * Returns : Appropriate M$ window message handler codes.
1279 *********************************************************************/
1280 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1287 pt.x = LOWORD(lParam);
1288 pt.y = HIWORD(lParam);
1289 ClientToScreen(hwnd, &pt);
1290 OnLogRButtonUp(wParam, pt.x, pt.y);
1294 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1299 /*********************************************************************
1301 * Function : LogWindowProc
1303 * Description : Windows call back routine handles events on the log window.
1306 * 1 : hwnd = handle of the logging window
1307 * 2 : uMsg = message number
1308 * 3 : wParam = first param for this message
1309 * 4 : lParam = next param for this message
1311 * Returns : Appropriate M$ window message handler codes.
1313 *********************************************************************/
1314 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1322 /* This is the end - beautiful friend - the end */
1323 DestroyWindow(g_hwndLogBox);
1324 DestroyWindow(g_hwndLogFrame);
1332 g_bShowLogWindow = wParam;
1334 /* Resize the logging window to fit the new frame */
1338 GetClientRect(g_hwndLogFrame, &rc);
1339 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1344 OnLogInitMenu((HMENU) wParam);
1352 OnLogCommand(LOWORD(wParam));
1359 if (g_bCloseHidesWindow)
1361 ShowLogWindow(FALSE);
1366 ShowLogWindow(FALSE);
1372 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1376 #endif /* ndef _WIN_CONSOLE - entire file */