1 /*********************************************************************
3 * File : $Source: /cvsroot/ijbswa/current/w32log.c,v $
5 * Purpose : Functions for creating and destroying the log window,
6 * outputting strings, processing messages and so on.
8 * Copyright : Written by and Copyright (C) 2001-2009 members of
9 * the Privoxy team. https://www.privoxy.org/
11 * Written by and Copyright (C) 1999 Adam Lock
14 * This program is free software; you can redistribute it
15 * and/or modify it under the terms of the GNU General
16 * Public License as published by the Free Software
17 * Foundation; either version 2 of the License, or (at
18 * your option) any later version.
20 * This program is distributed in the hope that it will
21 * be useful, but WITHOUT ANY WARRANTY; without even the
22 * implied warranty of MERCHANTABILITY or FITNESS FOR A
23 * PARTICULAR PURPOSE. See the GNU General Public
24 * License for more details.
26 * The GNU General Public License should be included with
27 * this file. If not, you can view it at
28 * http://www.gnu.org/copyleft/gpl.html
29 * or write to the Free Software Foundation, Inc., 59
30 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 *********************************************************************/
49 #include "w32taskbar.h"
57 #ifndef _WIN_CONSOLE /* entire file */
60 * Timers and the various durations
62 #define TIMER_ANIM_ID 1
63 #define TIMER_ANIM_TIME 100
64 #define TIMER_ANIMSTOP_ID 2
65 #define TIMER_ANIMSTOP_TIME 1000
66 #define TIMER_CLIPBUFFER_ID 3
67 #define TIMER_CLIPBUFFER_TIME 1000
68 #define TIMER_CLIPBUFFER_FORCE_ID 4
69 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
72 * Styles of text that can be output
75 #define STYLE_HIGHLIGHT 1
77 #define STYLE_HEADER 3
80 * Number of frames of animation in tray activity sequence
84 #define DEFAULT_MAX_BUFFER_LINES 200
85 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
86 #define DEFAULT_LOG_FONT_SIZE 8
89 * These values affect the way the log window behaves, they should be read
90 * from a file but for the moment, they are hardcoded here. Some options are
91 * configurable through the UI.
94 /* Indicates whether task bar shows activity animation */
95 BOOL g_bShowActivityAnimation = 1;
97 /* Indicates whether the log window is shown */
98 BOOL g_bShowLogWindow = 1;
100 /* Indicates if the log window appears on the task bar */
101 BOOL g_bShowOnTaskBar = 0;
103 /* Indicates whether closing the log window really just hides it */
104 BOOL g_bCloseHidesWindow = 1;
106 /* Indicates if messages are logged at all */
107 BOOL g_bLogMessages = 1;
109 /* Indicates whether log messages are highlighted */
110 BOOL g_bHighlightMessages = 1;
112 /* Indicates if buffer is limited in size */
113 BOOL g_bLimitBufferSize = 1;
115 /* Maximum number of lines allowed in buffer when limited */
116 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
119 char g_szFontFaceName[32] = DEFAULT_LOG_FONT_NAME;
121 /* Size of font to use */
122 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
125 /* FIXME: this is a kludge */
127 const char * g_default_actions_file = NULL;
128 const char * g_user_actions_file = NULL;
129 const char * g_default_filterfile = NULL;
130 const char * g_user_filterfile = NULL;
132 const char * g_trustfile = NULL;
133 #endif /* def FEATURE_TRUST */
135 /* FIXME: end kludge */
137 /* Regular expression for detected URLs */
138 #define RE_URL "http:[^ \n\r]*"
141 * Regular expressions that are used to perform highlight in the log window
143 static struct _Pattern
148 } patterns_to_highlight[] =
151 { RE_URL, STYLE_LINK },
152 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
153 /* interesting text to highlight */
154 /* see jcc.c crunch_reason for the full list */
155 { "Crunch: Blocked:", STYLE_HIGHLIGHT },
156 { "Crunch: Untrusted", STYLE_HIGHLIGHT },
157 { "Crunch: Redirected:", STYLE_HIGHLIGHT },
158 { "Crunch: DNS failure", STYLE_HIGHLIGHT },
159 { "Crunch: Forwarding failed", STYLE_HIGHLIGHT },
160 { "Crunch: Connection failure", STYLE_HIGHLIGHT },
161 { "Crunch: Out of memory", STYLE_HIGHLIGHT },
162 { "Connect: Found reusable socket", STYLE_HIGHLIGHT },
163 { "Connect: Reusing server socket", STYLE_HIGHLIGHT },
164 { "Connect: Created new connection to", STYLE_HIGHLIGHT },
165 { "hung up on us", STYLE_HIGHLIGHT },
166 { "Info: Loading actions file:", STYLE_HIGHLIGHT },
167 { "Info: Loading filter file:", STYLE_HIGHLIGHT },
168 { "Info: Now toggled ", STYLE_HIGHLIGHT },
169 { "Crunching Referer:", STYLE_HIGHLIGHT },
170 /* what are all the possible error strings?? */
171 { "Error:", STYLE_HIGHLIGHT },
173 { "referer:", STYLE_HEADER },
174 { "proxy-connection:", STYLE_HEADER },
175 { "proxy-agent:", STYLE_HEADER },
176 { "user-agent:", STYLE_HEADER },
177 { "host:", STYLE_HEADER },
178 { "accept:", STYLE_HEADER },
179 { "accept-encoding:", STYLE_HEADER },
180 { "accept-language:", STYLE_HEADER },
181 { "accept-charset:", STYLE_HEADER },
182 { "accept-ranges:", STYLE_HEADER },
183 { "date:", STYLE_HEADER },
184 { "cache-control:", STYLE_HEADER },
185 { "cache-last-checked:", STYLE_HEADER },
186 { "connection:", STYLE_HEADER },
187 { "content-type", STYLE_HEADER },
188 { "content-length", STYLE_HEADER },
189 { "cookie", STYLE_HEADER },
190 { "last-modified:", STYLE_HEADER },
191 { "pragma:", STYLE_HEADER },
192 { "server:", STYLE_HEADER },
193 { "etag:", STYLE_HEADER },
194 { "expires:", STYLE_HEADER },
195 { "warning:", STYLE_HEADER },
196 /* this is the terminator statement - do not delete! */
209 static CRITICAL_SECTION g_criticalsection;
210 static HWND g_hwndTray;
211 static HWND g_hwndLogBox;
212 static WNDPROC g_fnLogBox;
213 static HICON g_hiconAnim[ANIM_FRAMES];
214 static HICON g_hiconIdle;
215 static HICON g_hiconOff;
216 static int g_nAnimFrame;
217 static BOOL g_bClipPending = FALSE;
218 static int g_nRichEditVersion = 0;
223 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
224 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
225 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
226 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
227 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
228 static BOOL InitRichEdit(void);
229 static void LogClipBuffer(void);
230 static void LogCreatePatternMatchingBuffers(void);
231 static void LogDestroyPatternMatchingBuffers(void);
232 static int LogPutStringNoMatch(const char *pszText, int style);
233 static void SetIdleIcon(void);
236 /*********************************************************************
238 * Function : InitLogWindow
240 * Description : Initialise the log window.
244 * Returns : Always TRUE (there should be error checking on the resources).
246 *********************************************************************/
247 BOOL InitLogWindow(void)
252 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
253 g_hiconOff = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_OFF));
254 for (i = 0; i < ANIM_FRAMES; i++)
256 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ANIMATED1 + i));
258 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_MAINICON));
260 /* Create the user interface */
261 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
262 g_hwndTray = CreateTrayWindow(g_hInstance);
263 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Privoxy");
265 /* Create pattern matching buffers (for highlighting */
266 LogCreatePatternMatchingBuffers();
268 /* Create a critical section to protect multi-threaded access to certain things */
269 InitializeCriticalSection(&g_criticalsection);
276 /*********************************************************************
278 * Function : TermLogWindow
280 * Description : Cleanup the logwindow.
286 *********************************************************************/
287 void TermLogWindow(void)
291 LogDestroyPatternMatchingBuffers();
293 TrayDeleteIcon(g_hwndTray, 1);
294 DeleteObject(g_hiconApp);
295 DeleteObject(g_hiconIdle);
296 DeleteObject(g_hiconOff);
297 for (i = 0; i < ANIM_FRAMES; i++)
299 DeleteObject(g_hiconAnim[i]);
305 /*********************************************************************
307 * Function : LogCreatePatternMatchingBuffers
309 * Description : Compile the pattern matching buffers.
315 *********************************************************************/
316 void LogCreatePatternMatchingBuffers(void)
320 #warning The win32 build of Privoxy is expected to crash when compiled with pcre2 support.
322 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
324 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
329 /*********************************************************************
331 * Function : LogDestroyPatternMatchingBuffers
333 * Description : Free up the pattern matching buffers.
339 *********************************************************************/
340 void LogDestroyPatternMatchingBuffers(void)
343 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
345 regfree(&patterns_to_highlight[i].buffer);
350 /*********************************************************************
352 * Function : LogPutString
354 * Description : Inserts text into the logging window. This is really
355 * a regexp aware wrapper function to `LogPutStringNoMatch'.
358 * 1 : pszText = pointer to string going to the log window
360 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
361 * FIXME: this is backwards to the rest of IJB and to common
362 * programming practice. Please use 0 => success instead.
364 *********************************************************************/
365 int LogPutString(const char *pszText)
375 if (pszText == NULL || strlen(pszText) == 0)
380 /* Critical section stops multiple threads doing nasty interactions that
381 * foul up the highlighting and output.
383 EnterCriticalSection(&g_criticalsection);
385 if (g_bHighlightMessages)
389 /* First things first, regexp scan for various things that we would like highlighted */
390 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
392 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
394 char *pszBefore = NULL;
395 char *pszMatch = NULL;
396 char *pszAfter = NULL;
399 /* Split the string up into pieces representing the strings, before
400 at and after the matching pattern
404 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
405 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
406 strncpy(pszBefore, pszText, match.rm_so);
408 if (match.rm_eo < (regoff_t)strlen(pszText))
410 pszAfter = strdup(&pszText[match.rm_eo]);
412 nMatchSize = match.rm_eo - match.rm_so;
413 pszMatch = (char *)malloc(nMatchSize + 1);
414 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
415 pszMatch[nMatchSize] = '\0';
417 /* Recursively call LogPutString */
420 LogPutString(pszBefore);
425 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
430 LogPutString(pszAfter);
440 result = LogPutStringNoMatch(pszText, STYLE_NONE);
443 LeaveCriticalSection(&g_criticalsection);
450 /*********************************************************************
452 * Function : LogPutStringNoMatch
454 * Description : Puts a string into the logging window.
457 * 1 : pszText = pointer to string going to the log window
458 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
460 * Returns : Always 1 => success.
461 * FIXME: this is backwards to the rest of IJB and to common
462 * programming practice. Please use 0 => success instead.
464 *********************************************************************/
465 int LogPutStringNoMatch(const char *pszText, int style)
471 assert(g_hwndLogBox);
472 if (g_hwndLogBox == NULL)
477 /* TODO preserve existing selection */
479 /* Go to the end of the text */
480 nTextLength = GetWindowTextLength(g_hwndLogBox);
481 range.cpMin = nTextLength;
482 range.cpMax = nTextLength;
483 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
485 /* Apply a formatting style */
486 memset(&format, 0, sizeof(format));
487 format.cbSize = sizeof(format);
488 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT |
489 CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET;
490 format.bCharSet = DEFAULT_CHARSET;
491 format.yHeight = (g_nFontSize * 1440) / 72;
492 strlcpy(format.szFaceName, g_szFontFaceName, sizeof(format.szFaceName));
493 if (style == STYLE_NONE)
496 format.dwEffects |= CFE_AUTOCOLOR;
498 else if (style == STYLE_HEADER)
500 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
502 else if (style == STYLE_HIGHLIGHT)
504 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
506 else if (style == STYLE_LINK)
508 format.dwEffects |= CFE_UNDERLINE;
509 format.crTextColor = RGB(0, 0, 255);
511 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
513 /* Append text to the end */
514 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
516 /* TODO Restore the old selection */
519 if (strchr(pszText, '\n') != NULL)
521 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
524 /* Set the force clip timer going. This timer ensures clipping is done
525 intermittently even when there is a sustained burst of logging
527 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
529 g_bClipPending = TRUE;
537 /*********************************************************************
539 * Function : LogShowActivity
541 * Description : Start the spinner.
547 *********************************************************************/
548 void LogShowActivity(void)
550 /* Start some activity timers */
551 if (g_bShowActivityAnimation)
553 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
554 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
560 /*********************************************************************
562 * Function : LogClipBuffer
564 * Description : Prunes old lines from the log.
570 *********************************************************************/
571 void LogClipBuffer(void)
573 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
574 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
576 /* Compute the range representing the lines to be deleted */
577 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
578 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
581 range.cpMax = nLastChar;
583 /* TODO get current selection */
585 /* TODO adjust and clip old selection against range to be deleted */
587 /* Select range and erase it (turning off autoscroll to prevent
589 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
590 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
591 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
592 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
594 /* reposition (back to) the end of the log content */
595 range.cpMin = SendMessage (g_hwndLogBox, WM_GETTEXTLENGTH, 0, 0);
597 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
599 /* restore vertical ScrollBar stuff (messed up by AUTOVSCROLL) */
600 SendMessage (g_hwndLogBox, EM_SCROLL, SB_LINEDOWN, 0);
607 /*********************************************************************
609 * Function : CreateHiddenLogOwnerWindow
611 * Description : Creates a hidden owner window that stops the log
612 * window appearing in the task bar.
615 * 1 : hInstance = application's instance handle
617 * Returns : Handle to newly created window.
619 *********************************************************************/
620 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
622 static const char *szWndName = "PrivoxyLogOwner";
627 wc.lpfnWndProc = LogOwnerWindowProc;
630 wc.hInstance = hInstance;
631 wc.hIcon = g_hiconApp;
633 wc.hbrBackground = 0;
635 wc.lpszClassName = szWndName;
639 hwnd = CreateWindow(szWndName, szWndName,
640 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
641 CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
648 /*********************************************************************
650 * Function : LogOwnerWindowProc
652 * Description : Dummy procedure that does nothing special.
655 * 1 : hwnd = window handle
656 * 2 : uMsg = message number
657 * 3 : wParam = first param for this message
658 * 4 : lParam = next param for this message
660 * Returns : Same as `DefWindowProc'.
662 *********************************************************************/
663 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
665 return DefWindowProc(hwnd, uMsg, wParam, lParam);
670 /*********************************************************************
672 * Function : CreateLogWindow
674 * Description : Create the logging window.
677 * 1 : hInstance = application's instance handle
678 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
680 * Returns : Handle to newly created window.
682 *********************************************************************/
683 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
685 static const char *szWndName = "PrivoxyLogWindow";
686 static const char *szWndTitle = "Privoxy";
689 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
693 memset(&wc, 0, sizeof(wc));
694 wc.cbSize = sizeof(wc);
695 wc.style = CS_DBLCLKS;
696 wc.lpfnWndProc = LogWindowProc;
699 wc.hInstance = hInstance;
700 wc.hIcon = g_hiconApp;
702 wc.hbrBackground = 0;
703 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
704 wc.lpszClassName = szWndName;
705 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
706 RegisterClassEx(&wc);
708 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
709 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
710 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
712 /* Now create a child list box */
713 GetClientRect(hwnd, &rcClient);
715 /* Create a rich edit control */
717 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
718 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
719 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
720 hwnd, NULL, hInstance, NULL);
721 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
723 /* Subclass the control to catch certain messages */
724 g_fnLogBox = (WNDPROC) GetWindowLongPtr(g_hwndLogBox, GWLP_WNDPROC);
725 SetWindowLongPtr(g_hwndLogBox, GWLP_WNDPROC, (LONG_PTR) LogRichEditProc);
727 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
728 if (!g_bShowOnTaskBar &&
729 (nCmdShow == SW_SHOWMINIMIZED ||
730 nCmdShow == SW_MINIMIZE ||
731 nCmdShow == SW_SHOWMINNOACTIVE))
733 g_bShowLogWindow = FALSE;
737 ShowWindow(hwnd, nCmdShow);
741 GetClientRect(g_hwndLogFrame, &rcClient);
742 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
749 /*********************************************************************
751 * Function : InitRichEdit
753 * Description : Initialise the rich edit control library.
757 * Returns : TRUE => success, FALSE => failure.
758 * FIXME: this is backwards to the rest of IJB and to common
759 * programming practice. Please use 0 => success instead.
761 *********************************************************************/
762 BOOL InitRichEdit(void)
764 static HINSTANCE hInstRichEdit;
765 if (hInstRichEdit == NULL)
767 g_nRichEditVersion = 0;
768 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
771 g_nRichEditVersion = _RICHEDIT_VER;
775 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
778 g_nRichEditVersion = 0x0100;
782 return (hInstRichEdit != NULL) ? TRUE : FALSE;
787 /*********************************************************************
789 * Function : ShowLogWindow
791 * Description : Shows or hides the log window. We will also raise the
792 * window on a show command in case it is buried.
795 * 1 : bShow = TRUE to show, FALSE to mimize/hide
799 *********************************************************************/
800 void ShowLogWindow(BOOL bShow)
804 SetForegroundWindow(g_hwndLogFrame);
805 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
808 else if (g_bShowOnTaskBar)
810 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
814 ShowWindow(g_hwndLogFrame, SW_HIDE);
819 /*********************************************************************
821 * Function : EditFile
823 * Description : Opens the specified setting file for editing.
824 * FIXME: What if the file has no associated application. Check for return values
825 * from ShellExecute??
828 * 1 : filename = filename from the config (aka config.txt) file.
832 *********************************************************************/
833 void EditFile(const char *filename)
837 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
843 /*--------------------------------------------------------------------------*/
844 /* Windows message handlers */
845 /*--------------------------------------------------------------------------*/
848 /*********************************************************************
850 * Function : OnLogRButtonUp
852 * Description : Handler for WM_RBUTTONUP messages.
855 * 1 : nModifier = wParam from mouse message (unused)
856 * 2 : x = x coordinate of the mouse event
857 * 3 : y = y coordinate of the mouse event
861 *********************************************************************/
862 void OnLogRButtonUp(int nModifier, int x, int y)
864 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
867 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
869 /* Check if there is a selection */
871 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
872 if (range.cpMin == range.cpMax)
874 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
878 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
881 /* Display the popup */
882 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
889 /*********************************************************************
891 * Function : OnLogCommand
893 * Description : Handler for WM_COMMAND messages.
896 * 1 : nCommand = the command portion of the menu selection event
900 *********************************************************************/
901 void OnLogCommand(int nCommand)
905 case ID_TOGGLE_SHOWWINDOW:
906 g_bShowLogWindow = !g_bShowLogWindow;
908 ShowLogWindow(g_bShowLogWindow);
912 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
916 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
919 case ID_VIEW_CLEARLOG:
920 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
923 case ID_VIEW_LOGMESSAGES:
924 g_bLogMessages = !g_bLogMessages;
925 /* SaveLogSettings(); */
928 case ID_VIEW_MESSAGEHIGHLIGHTING:
929 g_bHighlightMessages = !g_bHighlightMessages;
930 /* SaveLogSettings(); */
933 case ID_VIEW_LIMITBUFFERSIZE:
934 g_bLimitBufferSize = !g_bLimitBufferSize;
935 /* SaveLogSettings(); */
938 case ID_VIEW_ACTIVITYANIMATION:
939 g_bShowActivityAnimation = !g_bShowActivityAnimation;
940 /* SaveLogSettings(); */
943 #ifdef FEATURE_TOGGLE
944 case ID_TOGGLE_ENABLED:
945 global_toggle_state = !global_toggle_state;
946 log_error(LOG_LEVEL_INFO,
947 "Now toggled %s", global_toggle_state ? "ON" : "OFF");
949 * Leverage TIMER_ANIMSTOP_ID to set the idle icon through the
950 * "application queue". According to MSDN, 10 milliseconds are
951 * the lowest value possible and seem to be close enough to
954 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, 10, NULL);
956 #endif /* def FEATURE_TOGGLE */
958 case ID_TOOLS_EDITCONFIG:
959 EditFile(configfile);
962 case ID_TOOLS_EDITDEFAULTACTIONS:
963 EditFile(g_default_actions_file);
966 case ID_TOOLS_EDITUSERACTIONS:
967 EditFile(g_user_actions_file);
970 case ID_TOOLS_EDITDEFAULTFILTERS:
971 EditFile(g_default_filterfile);
974 case ID_TOOLS_EDITUSERFILTERS:
975 EditFile(g_user_filterfile);
979 case ID_TOOLS_EDITTRUST:
980 EditFile(g_trustfile);
982 #endif /* def FEATURE_TRUST */
985 ShellExecute(g_hwndLogFrame, "open", "LICENSE.txt", NULL, NULL, SW_SHOWNORMAL);
989 ShellExecute(g_hwndLogFrame, "open", "doc\\faq\\index.html", NULL, NULL, SW_SHOWNORMAL);
993 ShellExecute(g_hwndLogFrame, "open", "doc\\user-manual\\index.html", NULL, NULL, SW_SHOWNORMAL);
997 ShellExecute(g_hwndLogFrame, "open", CGI_PREFIX "show-status", NULL, NULL, SW_SHOWNORMAL);
1001 MessageBox(g_hwndLogFrame, win32_blurb, "About Privoxy", MB_OK);
1012 /*********************************************************************
1014 * Function : OnLogInitMenu
1016 * Description : Handler for WM_INITMENU messages. Enable, disable,
1017 * check, and/or uncheck menu options as apropos.
1020 * 1 : hmenu = handle to menu to "make current"
1024 *********************************************************************/
1025 void OnLogInitMenu(HMENU hmenu)
1027 /* Only enable editors if there is a file to edit */
1028 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTACTIONS, MF_BYCOMMAND | (g_default_actions_file ? MF_ENABLED : MF_GRAYED));
1029 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERACTIONS, MF_BYCOMMAND | (g_user_actions_file ? MF_ENABLED : MF_GRAYED));
1030 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTFILTERS, MF_BYCOMMAND | (g_default_filterfile ? MF_ENABLED : MF_GRAYED));
1031 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERFILTERS, MF_BYCOMMAND | (g_user_filterfile ? MF_ENABLED : MF_GRAYED));
1032 #ifdef FEATURE_TRUST
1033 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1034 #endif /* def FEATURE_TRUST */
1036 /* Check/uncheck options */
1037 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1038 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1039 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1040 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1041 #ifdef FEATURE_TOGGLE
1042 /* by haroon - menu item for Enable toggle on/off */
1043 CheckMenuItem(hmenu, ID_TOGGLE_ENABLED, MF_BYCOMMAND | (global_toggle_state ? MF_CHECKED : MF_UNCHECKED));
1044 #endif /* def FEATURE_TOGGLE */
1045 CheckMenuItem(hmenu, ID_TOGGLE_SHOWWINDOW, MF_BYCOMMAND | (g_bShowLogWindow ? MF_CHECKED : MF_UNCHECKED));
1050 /*********************************************************************
1052 * Function : OnLogTimer
1054 * Description : Handler for WM_TIMER messages.
1057 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1061 *********************************************************************/
1062 void OnLogTimer(int nTimer)
1067 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1070 case TIMER_ANIMSTOP_ID:
1073 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1074 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1077 case TIMER_CLIPBUFFER_ID:
1078 case TIMER_CLIPBUFFER_FORCE_ID:
1080 g_bClipPending = FALSE;
1081 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1082 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1093 /*********************************************************************
1095 * Function : SetIdleIcon
1097 * Description : Sets the tray icon to either idle or off
1103 *********************************************************************/
1106 #ifdef FEATURE_TOGGLE
1107 if (!global_toggle_state)
1109 TraySetIcon(g_hwndTray, 1, g_hiconOff);
1112 #endif /* def FEATURE_TOGGLE */
1113 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1117 /*********************************************************************
1119 * Function : LogRichEditProc
1121 * Description : Window subclass routine handles some events for the rich edit control.
1124 * 1 : hwnd = window handle of the rich edit control
1125 * 2 : uMsg = message number
1126 * 3 : wParam = first param for this message
1127 * 4 : lParam = next param for this message
1129 * Returns : Appropriate M$ window message handler codes.
1131 *********************************************************************/
1132 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1139 pt.x = LOWORD(lParam);
1140 pt.y = HIWORD(lParam);
1141 ClientToScreen(hwnd, &pt);
1142 OnLogRButtonUp(wParam, pt.x, pt.y);
1147 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1149 OnLogCommand(ID_VIEW_CLEARLOG);
1154 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1159 /*********************************************************************
1161 * Function : LogWindowProc
1163 * Description : Windows call back routine handles events on the log window.
1166 * 1 : hwnd = handle of the logging window
1167 * 2 : uMsg = message number
1168 * 3 : wParam = first param for this message
1169 * 4 : lParam = next param for this message
1171 * Returns : Appropriate M$ window message handler codes.
1173 *********************************************************************/
1174 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1182 /* This is the end - my only friend - the end */
1183 DestroyWindow(g_hwndLogBox);
1184 DestroyWindow(g_hwndLogFrame);
1192 g_bShowLogWindow = wParam;
1193 case WM_SIZE: /* note: implicit-fallthrough */
1194 /* Resize the logging window to fit the new frame */
1198 GetClientRect(g_hwndLogFrame, &rc);
1199 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1204 OnLogInitMenu((HMENU) wParam);
1212 OnLogCommand(LOWORD(wParam));
1219 if (g_bCloseHidesWindow)
1221 ShowLogWindow(FALSE);
1226 ShowLogWindow(FALSE);
1232 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1234 OnLogCommand(ID_VIEW_CLEARLOG);
1240 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1244 #endif /* ndef _WIN_CONSOLE - entire file */