1 const char w32log_rcs[] = "$Id: w32log.c,v 1.36 2009/11/08 18:09:52 ler762 Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/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-2009 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.
33 *********************************************************************/
49 #include "w32taskbar.h"
57 const char w32res_h_rcs[] = W32RES_H_VERSION;
61 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
64 const char w32log_h_rcs[] = W32LOG_H_VERSION;
66 #ifndef _WIN_CONSOLE /* entire file */
69 * Timers and the various durations
71 #define TIMER_ANIM_ID 1
72 #define TIMER_ANIM_TIME 100
73 #define TIMER_ANIMSTOP_ID 2
74 #define TIMER_ANIMSTOP_TIME 1000
75 #define TIMER_CLIPBUFFER_ID 3
76 #define TIMER_CLIPBUFFER_TIME 1000
77 #define TIMER_CLIPBUFFER_FORCE_ID 4
78 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
81 * Styles of text that can be output
84 #define STYLE_HIGHLIGHT 1
86 #define STYLE_HEADER 3
89 * Number of frames of animation in tray activity sequence
93 #define DEFAULT_MAX_BUFFER_LINES 200
94 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
95 #define DEFAULT_LOG_FONT_SIZE 8
98 * These values affect the way the log window behaves, they should be read
99 * from a file but for the moment, they are hardcoded here. Some options are
100 * configurable through the UI.
103 /* Indicates whether task bar shows activity animation */
104 BOOL g_bShowActivityAnimation = 1;
106 /* Indicates whether the log window is shown */
107 BOOL g_bShowLogWindow = 1;
109 /* Indicates if the log window appears on the task bar */
110 BOOL g_bShowOnTaskBar = 0;
112 /* Indicates whether closing the log window really just hides it */
113 BOOL g_bCloseHidesWindow = 1;
115 /* Indicates if messages are logged at all */
116 BOOL g_bLogMessages = 1;
118 /* Indicates whether log messages are highlighted */
119 BOOL g_bHighlightMessages = 1;
121 /* Indicates if buffer is limited in size */
122 BOOL g_bLimitBufferSize = 1;
124 /* Maximum number of lines allowed in buffer when limited */
125 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
128 char g_szFontFaceName[32] = DEFAULT_LOG_FONT_NAME;
130 /* Size of font to use */
131 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
134 /* FIXME: this is a kludge */
136 const char * g_default_actions_file = NULL;
137 const char * g_user_actions_file = NULL;
138 const char * g_re_filterfile = NULL;
140 const char * g_trustfile = NULL;
141 #endif /* def FEATURE_TRUST */
143 /* FIXME: end kludge */
145 /* Regular expression for detected URLs */
146 #define RE_URL "http:[^ \n\r]*"
149 * Regular expressions that are used to perform highlight in the log window
151 static struct _Pattern
156 } patterns_to_highlight[] =
159 { RE_URL, STYLE_LINK },
160 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
161 /* interesting text to highlight */
162 /* see jcc.c crunch_reason for the full list */
163 { "Crunch: Blocked:", STYLE_HIGHLIGHT },
164 { "Crunch: Untrusted", STYLE_HIGHLIGHT },
165 { "Crunch: Redirected:", STYLE_HIGHLIGHT },
166 { "Crunch: DNS failure", STYLE_HIGHLIGHT },
167 { "Crunch: Forwarding failed", STYLE_HIGHLIGHT },
168 { "Crunch: Connection failure", STYLE_HIGHLIGHT },
169 { "Crunch: Out of memory", STYLE_HIGHLIGHT },
170 { "Connect: Found reusable socket", STYLE_HIGHLIGHT },
171 { "Connect: Reusing server socket", STYLE_HIGHLIGHT },
172 { "Connect: Created new connection to", STYLE_HIGHLIGHT },
173 { "hung up on us", STYLE_HIGHLIGHT },
174 { "Crunching Referer:", STYLE_HIGHLIGHT },
175 /* what are all the possible error strings?? */
176 { "Error:", STYLE_HIGHLIGHT },
178 { "referer:", STYLE_HEADER },
179 { "proxy-connection:", STYLE_HEADER },
180 { "proxy-agent:", STYLE_HEADER },
181 { "user-agent:", STYLE_HEADER },
182 { "host:", STYLE_HEADER },
183 { "accept:", STYLE_HEADER },
184 { "accept-encoding:", STYLE_HEADER },
185 { "accept-language:", STYLE_HEADER },
186 { "accept-charset:", STYLE_HEADER },
187 { "accept-ranges:", STYLE_HEADER },
188 { "date:", STYLE_HEADER },
189 { "cache-control:", STYLE_HEADER },
190 { "cache-last-checked:", STYLE_HEADER },
191 { "connection:", STYLE_HEADER },
192 { "content-type", STYLE_HEADER },
193 { "content-length", STYLE_HEADER },
194 { "cookie", STYLE_HEADER },
195 { "last-modified:", STYLE_HEADER },
196 { "pragma:", STYLE_HEADER },
197 { "server:", STYLE_HEADER },
198 { "etag:", STYLE_HEADER },
199 { "expires:", STYLE_HEADER },
200 { "warning:", STYLE_HEADER },
201 /* this is the terminator statement - do not delete! */
214 static CRITICAL_SECTION g_criticalsection;
215 static HWND g_hwndTray;
216 static HWND g_hwndLogBox;
217 static WNDPROC g_fnLogBox;
218 static HICON g_hiconAnim[ANIM_FRAMES];
219 static HICON g_hiconIdle;
220 static HICON g_hiconOff;
221 static int g_nAnimFrame;
222 static BOOL g_bClipPending = FALSE;
223 static int g_nRichEditVersion = 0;
228 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
229 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
230 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
231 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
232 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
233 static BOOL InitRichEdit(void);
234 static void LogClipBuffer(void);
235 static void LogCreatePatternMatchingBuffers(void);
236 static void LogDestroyPatternMatchingBuffers(void);
237 static int LogPutStringNoMatch(const char *pszText, int style);
238 static void SetIdleIcon(void);
241 /*********************************************************************
243 * Function : InitLogWindow
245 * Description : Initialise the log window.
249 * Returns : Always TRUE (there should be error checking on the resources).
251 *********************************************************************/
252 BOOL InitLogWindow(void)
257 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
258 g_hiconOff = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_OFF));
259 for (i = 0; i < ANIM_FRAMES; i++)
261 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ANIMATED1 + i));
263 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_MAINICON));
265 /* Create the user interface */
266 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
267 g_hwndTray = CreateTrayWindow(g_hInstance);
268 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Privoxy");
270 /* Create pattern matching buffers (for highlighting */
271 LogCreatePatternMatchingBuffers();
273 /* Create a critical section to protect multi-threaded access to certain things */
274 InitializeCriticalSection(&g_criticalsection);
281 /*********************************************************************
283 * Function : TermLogWindow
285 * Description : Cleanup the logwindow.
291 *********************************************************************/
292 void TermLogWindow(void)
296 LogDestroyPatternMatchingBuffers();
298 TrayDeleteIcon(g_hwndTray, 1);
299 DeleteObject(g_hiconApp);
300 DeleteObject(g_hiconIdle);
301 DeleteObject(g_hiconOff);
302 for (i = 0; i < ANIM_FRAMES; i++)
304 DeleteObject(g_hiconAnim[i]);
310 /*********************************************************************
312 * Function : LogCreatePatternMatchingBuffers
314 * Description : Compile the pattern matching buffers.
320 *********************************************************************/
321 void LogCreatePatternMatchingBuffers(void)
324 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
326 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
331 /*********************************************************************
333 * Function : LogDestroyPatternMatchingBuffers
335 * Description : Free up the pattern matching buffers.
341 *********************************************************************/
342 void LogDestroyPatternMatchingBuffers(void)
345 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
347 regfree(&patterns_to_highlight[i].buffer);
352 /*********************************************************************
354 * Function : LogPutString
356 * Description : Inserts text into the logging window. This is really
357 * a regexp aware wrapper function to `LogPutStringNoMatch'.
360 * 1 : pszText = pointer to string going to the log window
362 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
363 * FIXME: this is backwards to the rest of IJB and to common
364 * programming practice. Please use 0 => success instead.
366 *********************************************************************/
367 int LogPutString(const char *pszText)
372 if (pszText == NULL || strlen(pszText) == 0)
382 /* Critical section stops multiple threads doing nasty interactions that
383 * foul up the highlighting and output.
385 EnterCriticalSection(&g_criticalsection);
387 if (g_bHighlightMessages)
391 /* First things first, regexp scan for various things that we would like highlighted */
392 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
394 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
396 char *pszBefore = NULL;
397 char *pszMatch = NULL;
398 char *pszAfter = NULL;
401 /* Split the string up into pieces representing the strings, before
402 at and after the matching pattern
406 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
407 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
408 strncpy(pszBefore, pszText, match.rm_so);
410 if (match.rm_eo < (regoff_t)strlen(pszText))
412 pszAfter = strdup(&pszText[match.rm_eo]);
414 nMatchSize = match.rm_eo - match.rm_so;
415 pszMatch = (char *)malloc(nMatchSize + 1);
416 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
417 pszMatch[nMatchSize] = '\0';
419 /* Recursively call LogPutString */
422 LogPutString(pszBefore);
427 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
432 LogPutString(pszAfter);
442 result = LogPutStringNoMatch(pszText, STYLE_NONE);
445 LeaveCriticalSection(&g_criticalsection);
452 /*********************************************************************
454 * Function : LogPutStringNoMatch
456 * Description : Puts a string into the logging window.
459 * 1 : pszText = pointer to string going to the log window
460 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
462 * Returns : Always 1 => success.
463 * FIXME: this is backwards to the rest of IJB and to common
464 * programming practice. Please use 0 => success instead.
466 *********************************************************************/
467 int LogPutStringNoMatch(const char *pszText, int style)
473 assert(g_hwndLogBox);
474 if (g_hwndLogBox == NULL)
479 /* TODO preserve existing selection */
481 /* Go to the end of the text */
482 nTextLength = GetWindowTextLength(g_hwndLogBox);
483 range.cpMin = nTextLength;
484 range.cpMax = nTextLength;
485 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
487 /* Apply a formatting style */
488 memset(&format, 0, sizeof(format));
489 format.cbSize = sizeof(format);
490 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT |
491 CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET;
492 format.bCharSet = DEFAULT_CHARSET;
493 format.yHeight = (g_nFontSize * 1440) / 72;
494 strlcpy(format.szFaceName, g_szFontFaceName, sizeof(format.szFaceName));
495 if (style == STYLE_NONE)
498 format.dwEffects |= CFE_AUTOCOLOR;
500 else if (style == STYLE_HEADER)
502 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
504 else if (style == STYLE_HIGHLIGHT)
506 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
508 else if (style == STYLE_LINK)
510 format.dwEffects |= CFE_UNDERLINE;
511 format.crTextColor = RGB(0, 0, 255);
513 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
515 /* Append text to the end */
516 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
518 /* TODO Restore the old selection */
521 if (strchr(pszText, '\n') != NULL)
523 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
526 /* Set the force clip timer going. This timer ensures clipping is done
527 intermittently even when there is a sustained burst of logging
529 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
531 g_bClipPending = TRUE;
539 /*********************************************************************
541 * Function : LogShowActivity
543 * Description : Start the spinner.
549 *********************************************************************/
550 void LogShowActivity(void)
552 /* Start some activity timers */
553 if (g_bShowActivityAnimation)
555 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
556 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
562 /*********************************************************************
564 * Function : LogClipBuffer
566 * Description : Prunes old lines from the log.
572 *********************************************************************/
573 void LogClipBuffer(void)
575 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
576 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
578 /* Compute the range representing the lines to be deleted */
579 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
580 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
583 range.cpMax = nLastChar;
585 /* TODO get current selection */
587 /* TODO adjust and clip old selection against range to be deleted */
589 /* Select range and erase it (turning off autoscroll to prevent
591 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
592 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
593 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
594 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
596 /* reposition (back to) the end of the log content */
597 range.cpMin = SendMessage (g_hwndLogBox, WM_GETTEXTLENGTH, 0, 0);
599 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
601 /* restore vertical ScrollBar stuff (messed up by AUTOVSCROLL) */
602 SendMessage (g_hwndLogBox, EM_SCROLL, SB_LINEDOWN, 0);
609 /*********************************************************************
611 * Function : CreateHiddenLogOwnerWindow
613 * Description : Creates a hidden owner window that stops the log
614 * window appearing in the task bar.
617 * 1 : hInstance = application's instance handle
619 * Returns : Handle to newly created window.
621 *********************************************************************/
622 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
624 static const char *szWndName = "PrivoxyLogOwner";
629 wc.lpfnWndProc = LogOwnerWindowProc;
632 wc.hInstance = hInstance;
633 wc.hIcon = g_hiconApp;
635 wc.hbrBackground = 0;
637 wc.lpszClassName = szWndName;
641 hwnd = CreateWindow(szWndName, szWndName,
642 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
643 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
650 /*********************************************************************
652 * Function : LogOwnerWindowProc
654 * Description : Dummy procedure that does nothing special.
657 * 1 : hwnd = window handle
658 * 2 : uMsg = message number
659 * 3 : wParam = first param for this message
660 * 4 : lParam = next param for this message
662 * Returns : Same as `DefWindowProc'.
664 *********************************************************************/
665 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
667 return DefWindowProc(hwnd, uMsg, wParam, lParam);
672 /*********************************************************************
674 * Function : CreateLogWindow
676 * Description : Create the logging window.
679 * 1 : hInstance = application's instance handle
680 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
682 * Returns : Handle to newly created window.
684 *********************************************************************/
685 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
687 static const char *szWndName = "PrivoxyLogWindow";
688 static const char *szWndTitle = "Privoxy";
691 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
695 memset(&wc, 0, sizeof(wc));
696 wc.cbSize = sizeof(wc);
697 wc.style = CS_DBLCLKS;
698 wc.lpfnWndProc = LogWindowProc;
701 wc.hInstance = hInstance;
702 wc.hIcon = g_hiconApp;
704 wc.hbrBackground = 0;
705 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
706 wc.lpszClassName = szWndName;
707 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
708 RegisterClassEx(&wc);
710 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
711 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
712 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
714 /* Now create a child list box */
715 GetClientRect(hwnd, &rcClient);
717 /* Create a rich edit control */
719 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
720 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
721 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
722 hwnd, NULL, hInstance, NULL);
723 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
725 /* Subclass the control to catch certain messages */
726 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
727 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
729 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
730 if (!g_bShowOnTaskBar &&
731 (nCmdShow == SW_SHOWMINIMIZED ||
732 nCmdShow == SW_MINIMIZE ||
733 nCmdShow == SW_SHOWMINNOACTIVE))
735 g_bShowLogWindow = FALSE;
739 ShowWindow(hwnd, nCmdShow);
743 GetClientRect(g_hwndLogFrame, &rcClient);
744 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
751 /*********************************************************************
753 * Function : InitRichEdit
755 * Description : Initialise the rich edit control library.
759 * Returns : TRUE => success, FALSE => failure.
760 * FIXME: this is backwards to the rest of IJB and to common
761 * programming practice. Please use 0 => success instead.
763 *********************************************************************/
764 BOOL InitRichEdit(void)
766 static HINSTANCE hInstRichEdit;
767 if (hInstRichEdit == NULL)
769 g_nRichEditVersion = 0;
770 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
773 g_nRichEditVersion = _RICHEDIT_VER;
777 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
780 g_nRichEditVersion = 0x0100;
784 return (hInstRichEdit != NULL) ? TRUE : FALSE;
789 /*********************************************************************
791 * Function : ShowLogWindow
793 * Description : Shows or hides the log window. We will also raise the
794 * window on a show command in case it is buried.
797 * 1 : bShow = TRUE to show, FALSE to mimize/hide
801 *********************************************************************/
802 void ShowLogWindow(BOOL bShow)
806 SetForegroundWindow(g_hwndLogFrame);
807 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
810 else if (g_bShowOnTaskBar)
812 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
816 ShowWindow(g_hwndLogFrame, SW_HIDE);
821 /*********************************************************************
823 * Function : EditFile
825 * Description : Opens the specified setting file for editing.
826 * FIXME: What if the file has no associated application. Check for return values
827 * from ShellExecute??
830 * 1 : filename = filename from the config (aka config.txt) file.
834 *********************************************************************/
835 void EditFile(const char *filename)
839 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
845 /*--------------------------------------------------------------------------*/
846 /* Windows message handlers */
847 /*--------------------------------------------------------------------------*/
850 /*********************************************************************
852 * Function : OnLogRButtonUp
854 * Description : Handler for WM_RBUTTONUP messages.
857 * 1 : nModifier = wParam from mouse message (unused)
858 * 2 : x = x coordinate of the mouse event
859 * 3 : y = y coordinate of the mouse event
863 *********************************************************************/
864 void OnLogRButtonUp(int nModifier, int x, int y)
866 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
869 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
871 /* Check if there is a selection */
873 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
874 if (range.cpMin == range.cpMax)
876 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
880 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
883 /* Display the popup */
884 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
891 /*********************************************************************
893 * Function : OnLogCommand
895 * Description : Handler for WM_COMMAND messages.
898 * 1 : nCommand = the command portion of the menu selection event
902 *********************************************************************/
903 void OnLogCommand(int nCommand)
907 case ID_TOGGLE_SHOWWINDOW:
908 g_bShowLogWindow = !g_bShowLogWindow;
910 ShowLogWindow(g_bShowLogWindow);
914 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
918 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
921 case ID_VIEW_CLEARLOG:
922 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
925 case ID_VIEW_LOGMESSAGES:
926 g_bLogMessages = !g_bLogMessages;
927 /* SaveLogSettings(); */
930 case ID_VIEW_MESSAGEHIGHLIGHTING:
931 g_bHighlightMessages = !g_bHighlightMessages;
932 /* SaveLogSettings(); */
935 case ID_VIEW_LIMITBUFFERSIZE:
936 g_bLimitBufferSize = !g_bLimitBufferSize;
937 /* SaveLogSettings(); */
940 case ID_VIEW_ACTIVITYANIMATION:
941 g_bShowActivityAnimation = !g_bShowActivityAnimation;
942 /* SaveLogSettings(); */
945 #ifdef FEATURE_TOGGLE
946 /* by haroon - change toggle to its opposite value */
947 case ID_TOGGLE_ENABLED:
948 global_toggle_state = !global_toggle_state;
949 if (global_toggle_state)
951 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
955 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
959 #endif /* def FEATURE_TOGGLE */
961 case ID_TOOLS_EDITCONFIG:
962 EditFile(configfile);
965 case ID_TOOLS_EDITDEFAULTACTIONS:
966 EditFile(g_default_actions_file);
969 case ID_TOOLS_EDITUSERACTIONS:
970 EditFile(g_user_actions_file);
973 case ID_TOOLS_EDITFILTERS:
974 EditFile(g_re_filterfile);
978 case ID_TOOLS_EDITTRUST:
979 EditFile(g_trustfile);
981 #endif /* def FEATURE_TRUST */
984 ShellExecute(g_hwndLogFrame, "open", "LICENSE.txt", NULL, NULL, SW_SHOWNORMAL);
988 ShellExecute(g_hwndLogFrame, "open", "doc\\faq\\index.html", NULL, NULL, SW_SHOWNORMAL);
992 ShellExecute(g_hwndLogFrame, "open", "doc\\user-manual\\index.html", NULL, NULL, SW_SHOWNORMAL);
996 ShellExecute(g_hwndLogFrame, "open", CGI_PREFIX "show-status", NULL, NULL, SW_SHOWNORMAL);
1000 MessageBox(g_hwndLogFrame, win32_blurb, "About Privoxy", MB_OK);
1011 /*********************************************************************
1013 * Function : OnLogInitMenu
1015 * Description : Handler for WM_INITMENU messages. Enable, disable,
1016 * check, and/or uncheck menu options as apropos.
1019 * 1 : hmenu = handle to menu to "make current"
1023 *********************************************************************/
1024 void OnLogInitMenu(HMENU hmenu)
1026 /* Only enable editors if there is a file to edit */
1027 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTACTIONS, MF_BYCOMMAND | (g_default_actions_file ? MF_ENABLED : MF_GRAYED));
1028 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERACTIONS, MF_BYCOMMAND | (g_user_actions_file ? MF_ENABLED : MF_GRAYED));
1029 EnableMenuItem(hmenu, ID_TOOLS_EDITFILTERS, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1030 #ifdef FEATURE_TRUST
1031 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1032 #endif /* def FEATURE_TRUST */
1034 /* Check/uncheck options */
1035 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1036 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1037 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1038 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1039 #ifdef FEATURE_TOGGLE
1040 /* by haroon - menu item for Enable toggle on/off */
1041 CheckMenuItem(hmenu, ID_TOGGLE_ENABLED, MF_BYCOMMAND | (global_toggle_state ? MF_CHECKED : MF_UNCHECKED));
1042 #endif /* def FEATURE_TOGGLE */
1043 CheckMenuItem(hmenu, ID_TOGGLE_SHOWWINDOW, MF_BYCOMMAND | (g_bShowLogWindow ? MF_CHECKED : MF_UNCHECKED));
1048 /*********************************************************************
1050 * Function : OnLogTimer
1052 * Description : Handler for WM_TIMER messages.
1055 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1059 *********************************************************************/
1060 void OnLogTimer(int nTimer)
1065 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1068 case TIMER_ANIMSTOP_ID:
1071 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1072 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1075 case TIMER_CLIPBUFFER_ID:
1076 case TIMER_CLIPBUFFER_FORCE_ID:
1078 g_bClipPending = FALSE;
1079 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1080 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1091 /*********************************************************************
1093 * Function : SetIdleIcon
1095 * Description : Sets the tray icon to either idle or off
1101 *********************************************************************/
1104 #ifdef FEATURE_TOGGLE
1105 if (!global_toggle_state)
1107 TraySetIcon(g_hwndTray, 1, g_hiconOff);
1108 /* log_error(LOG_LEVEL_INFO, "Privoxy OFF icon selected."); */
1111 #endif /* def FEATURE_TOGGLE */
1112 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1116 /*********************************************************************
1118 * Function : LogRichEditProc
1120 * Description : Window subclass routine handles some events for the rich edit control.
1123 * 1 : hwnd = window handle of the rich edit control
1124 * 2 : uMsg = message number
1125 * 3 : wParam = first param for this message
1126 * 4 : lParam = next param for this message
1128 * Returns : Appropriate M$ window message handler codes.
1130 *********************************************************************/
1131 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1138 pt.x = LOWORD(lParam);
1139 pt.y = HIWORD(lParam);
1140 ClientToScreen(hwnd, &pt);
1141 OnLogRButtonUp(wParam, pt.x, pt.y);
1146 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1148 OnLogCommand(ID_VIEW_CLEARLOG);
1153 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1158 /*********************************************************************
1160 * Function : LogWindowProc
1162 * Description : Windows call back routine handles events on the log window.
1165 * 1 : hwnd = handle of the logging window
1166 * 2 : uMsg = message number
1167 * 3 : wParam = first param for this message
1168 * 4 : lParam = next param for this message
1170 * Returns : Appropriate M$ window message handler codes.
1172 *********************************************************************/
1173 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1181 /* This is the end - beautiful friend - the end */
1182 DestroyWindow(g_hwndLogBox);
1183 DestroyWindow(g_hwndLogFrame);
1191 g_bShowLogWindow = wParam;
1193 /* Resize the logging window to fit the new frame */
1197 GetClientRect(g_hwndLogFrame, &rc);
1198 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1203 OnLogInitMenu((HMENU) wParam);
1211 OnLogCommand(LOWORD(wParam));
1218 if (g_bCloseHidesWindow)
1220 ShowLogWindow(FALSE);
1225 ShowLogWindow(FALSE);
1231 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1233 OnLogCommand(ID_VIEW_CLEARLOG);
1239 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1243 #endif /* ndef _WIN_CONSOLE - entire file */