1 const char w32log_rcs[] = "$Id: w32log.c,v 1.51 2016/07/23 23:25:18 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_default_filterfile = NULL;
139 const char * g_user_filterfile = NULL;
141 const char * g_trustfile = NULL;
142 #endif /* def FEATURE_TRUST */
144 /* FIXME: end kludge */
146 /* Regular expression for detected URLs */
147 #define RE_URL "http:[^ \n\r]*"
150 * Regular expressions that are used to perform highlight in the log window
152 static struct _Pattern
157 } patterns_to_highlight[] =
160 { RE_URL, STYLE_LINK },
161 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
162 /* interesting text to highlight */
163 /* see jcc.c crunch_reason for the full list */
164 { "Crunch: Blocked:", STYLE_HIGHLIGHT },
165 { "Crunch: Untrusted", STYLE_HIGHLIGHT },
166 { "Crunch: Redirected:", STYLE_HIGHLIGHT },
167 { "Crunch: DNS failure", STYLE_HIGHLIGHT },
168 { "Crunch: Forwarding failed", STYLE_HIGHLIGHT },
169 { "Crunch: Connection failure", STYLE_HIGHLIGHT },
170 { "Crunch: Out of memory", STYLE_HIGHLIGHT },
171 { "Connect: Found reusable socket", STYLE_HIGHLIGHT },
172 { "Connect: Reusing server socket", STYLE_HIGHLIGHT },
173 { "Connect: Created new connection to", STYLE_HIGHLIGHT },
174 { "hung up on us", STYLE_HIGHLIGHT },
175 { "Info: Loading actions file:", STYLE_HIGHLIGHT },
176 { "Info: Loading filter file:", STYLE_HIGHLIGHT },
177 { "Info: Now toggled ", STYLE_HIGHLIGHT },
178 { "Crunching Referer:", STYLE_HIGHLIGHT },
179 /* what are all the possible error strings?? */
180 { "Error:", STYLE_HIGHLIGHT },
182 { "referer:", STYLE_HEADER },
183 { "proxy-connection:", STYLE_HEADER },
184 { "proxy-agent:", STYLE_HEADER },
185 { "user-agent:", STYLE_HEADER },
186 { "host:", STYLE_HEADER },
187 { "accept:", STYLE_HEADER },
188 { "accept-encoding:", STYLE_HEADER },
189 { "accept-language:", STYLE_HEADER },
190 { "accept-charset:", STYLE_HEADER },
191 { "accept-ranges:", STYLE_HEADER },
192 { "date:", STYLE_HEADER },
193 { "cache-control:", STYLE_HEADER },
194 { "cache-last-checked:", STYLE_HEADER },
195 { "connection:", STYLE_HEADER },
196 { "content-type", STYLE_HEADER },
197 { "content-length", STYLE_HEADER },
198 { "cookie", STYLE_HEADER },
199 { "last-modified:", STYLE_HEADER },
200 { "pragma:", STYLE_HEADER },
201 { "server:", STYLE_HEADER },
202 { "etag:", STYLE_HEADER },
203 { "expires:", STYLE_HEADER },
204 { "warning:", STYLE_HEADER },
205 /* this is the terminator statement - do not delete! */
218 static CRITICAL_SECTION g_criticalsection;
219 static HWND g_hwndTray;
220 static HWND g_hwndLogBox;
221 static WNDPROC g_fnLogBox;
222 static HICON g_hiconAnim[ANIM_FRAMES];
223 static HICON g_hiconIdle;
224 static HICON g_hiconOff;
225 static int g_nAnimFrame;
226 static BOOL g_bClipPending = FALSE;
227 static int g_nRichEditVersion = 0;
232 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
233 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
234 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
235 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
236 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
237 static BOOL InitRichEdit(void);
238 static void LogClipBuffer(void);
239 static void LogCreatePatternMatchingBuffers(void);
240 static void LogDestroyPatternMatchingBuffers(void);
241 static int LogPutStringNoMatch(const char *pszText, int style);
242 static void SetIdleIcon(void);
245 /*********************************************************************
247 * Function : InitLogWindow
249 * Description : Initialise the log window.
253 * Returns : Always TRUE (there should be error checking on the resources).
255 *********************************************************************/
256 BOOL InitLogWindow(void)
261 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
262 g_hiconOff = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_OFF));
263 for (i = 0; i < ANIM_FRAMES; i++)
265 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ANIMATED1 + i));
267 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_MAINICON));
269 /* Create the user interface */
270 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
271 g_hwndTray = CreateTrayWindow(g_hInstance);
272 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Privoxy");
274 /* Create pattern matching buffers (for highlighting */
275 LogCreatePatternMatchingBuffers();
277 /* Create a critical section to protect multi-threaded access to certain things */
278 InitializeCriticalSection(&g_criticalsection);
285 /*********************************************************************
287 * Function : TermLogWindow
289 * Description : Cleanup the logwindow.
295 *********************************************************************/
296 void TermLogWindow(void)
300 LogDestroyPatternMatchingBuffers();
302 TrayDeleteIcon(g_hwndTray, 1);
303 DeleteObject(g_hiconApp);
304 DeleteObject(g_hiconIdle);
305 DeleteObject(g_hiconOff);
306 for (i = 0; i < ANIM_FRAMES; i++)
308 DeleteObject(g_hiconAnim[i]);
314 /*********************************************************************
316 * Function : LogCreatePatternMatchingBuffers
318 * Description : Compile the pattern matching buffers.
324 *********************************************************************/
325 void LogCreatePatternMatchingBuffers(void)
328 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
330 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
335 /*********************************************************************
337 * Function : LogDestroyPatternMatchingBuffers
339 * Description : Free up the pattern matching buffers.
345 *********************************************************************/
346 void LogDestroyPatternMatchingBuffers(void)
349 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
351 regfree(&patterns_to_highlight[i].buffer);
356 /*********************************************************************
358 * Function : LogPutString
360 * Description : Inserts text into the logging window. This is really
361 * a regexp aware wrapper function to `LogPutStringNoMatch'.
364 * 1 : pszText = pointer to string going to the log window
366 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
367 * FIXME: this is backwards to the rest of IJB and to common
368 * programming practice. Please use 0 => success instead.
370 *********************************************************************/
371 int LogPutString(const char *pszText)
381 if (pszText == NULL || strlen(pszText) == 0)
386 /* Critical section stops multiple threads doing nasty interactions that
387 * foul up the highlighting and output.
389 EnterCriticalSection(&g_criticalsection);
391 if (g_bHighlightMessages)
395 /* First things first, regexp scan for various things that we would like highlighted */
396 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
398 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
400 char *pszBefore = NULL;
401 char *pszMatch = NULL;
402 char *pszAfter = NULL;
405 /* Split the string up into pieces representing the strings, before
406 at and after the matching pattern
410 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
411 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
412 strncpy(pszBefore, pszText, match.rm_so);
414 if (match.rm_eo < (regoff_t)strlen(pszText))
416 pszAfter = strdup(&pszText[match.rm_eo]);
418 nMatchSize = match.rm_eo - match.rm_so;
419 pszMatch = (char *)malloc(nMatchSize + 1);
420 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
421 pszMatch[nMatchSize] = '\0';
423 /* Recursively call LogPutString */
426 LogPutString(pszBefore);
431 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
436 LogPutString(pszAfter);
446 result = LogPutStringNoMatch(pszText, STYLE_NONE);
449 LeaveCriticalSection(&g_criticalsection);
456 /*********************************************************************
458 * Function : LogPutStringNoMatch
460 * Description : Puts a string into the logging window.
463 * 1 : pszText = pointer to string going to the log window
464 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
466 * Returns : Always 1 => success.
467 * FIXME: this is backwards to the rest of IJB and to common
468 * programming practice. Please use 0 => success instead.
470 *********************************************************************/
471 int LogPutStringNoMatch(const char *pszText, int style)
477 assert(g_hwndLogBox);
478 if (g_hwndLogBox == NULL)
483 /* TODO preserve existing selection */
485 /* Go to the end of the text */
486 nTextLength = GetWindowTextLength(g_hwndLogBox);
487 range.cpMin = nTextLength;
488 range.cpMax = nTextLength;
489 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
491 /* Apply a formatting style */
492 memset(&format, 0, sizeof(format));
493 format.cbSize = sizeof(format);
494 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT |
495 CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET;
496 format.bCharSet = DEFAULT_CHARSET;
497 format.yHeight = (g_nFontSize * 1440) / 72;
498 strlcpy(format.szFaceName, g_szFontFaceName, sizeof(format.szFaceName));
499 if (style == STYLE_NONE)
502 format.dwEffects |= CFE_AUTOCOLOR;
504 else if (style == STYLE_HEADER)
506 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
508 else if (style == STYLE_HIGHLIGHT)
510 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
512 else if (style == STYLE_LINK)
514 format.dwEffects |= CFE_UNDERLINE;
515 format.crTextColor = RGB(0, 0, 255);
517 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
519 /* Append text to the end */
520 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
522 /* TODO Restore the old selection */
525 if (strchr(pszText, '\n') != NULL)
527 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
530 /* Set the force clip timer going. This timer ensures clipping is done
531 intermittently even when there is a sustained burst of logging
533 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
535 g_bClipPending = TRUE;
543 /*********************************************************************
545 * Function : LogShowActivity
547 * Description : Start the spinner.
553 *********************************************************************/
554 void LogShowActivity(void)
556 /* Start some activity timers */
557 if (g_bShowActivityAnimation)
559 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
560 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
566 /*********************************************************************
568 * Function : LogClipBuffer
570 * Description : Prunes old lines from the log.
576 *********************************************************************/
577 void LogClipBuffer(void)
579 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
580 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
582 /* Compute the range representing the lines to be deleted */
583 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
584 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
587 range.cpMax = nLastChar;
589 /* TODO get current selection */
591 /* TODO adjust and clip old selection against range to be deleted */
593 /* Select range and erase it (turning off autoscroll to prevent
595 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
596 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
597 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
598 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
600 /* reposition (back to) the end of the log content */
601 range.cpMin = SendMessage (g_hwndLogBox, WM_GETTEXTLENGTH, 0, 0);
603 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
605 /* restore vertical ScrollBar stuff (messed up by AUTOVSCROLL) */
606 SendMessage (g_hwndLogBox, EM_SCROLL, SB_LINEDOWN, 0);
613 /*********************************************************************
615 * Function : CreateHiddenLogOwnerWindow
617 * Description : Creates a hidden owner window that stops the log
618 * window appearing in the task bar.
621 * 1 : hInstance = application's instance handle
623 * Returns : Handle to newly created window.
625 *********************************************************************/
626 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
628 static const char *szWndName = "PrivoxyLogOwner";
633 wc.lpfnWndProc = LogOwnerWindowProc;
636 wc.hInstance = hInstance;
637 wc.hIcon = g_hiconApp;
639 wc.hbrBackground = 0;
641 wc.lpszClassName = szWndName;
645 hwnd = CreateWindow(szWndName, szWndName,
646 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
647 CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
654 /*********************************************************************
656 * Function : LogOwnerWindowProc
658 * Description : Dummy procedure that does nothing special.
661 * 1 : hwnd = window handle
662 * 2 : uMsg = message number
663 * 3 : wParam = first param for this message
664 * 4 : lParam = next param for this message
666 * Returns : Same as `DefWindowProc'.
668 *********************************************************************/
669 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
671 return DefWindowProc(hwnd, uMsg, wParam, lParam);
676 /*********************************************************************
678 * Function : CreateLogWindow
680 * Description : Create the logging window.
683 * 1 : hInstance = application's instance handle
684 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
686 * Returns : Handle to newly created window.
688 *********************************************************************/
689 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
691 static const char *szWndName = "PrivoxyLogWindow";
692 static const char *szWndTitle = "Privoxy";
695 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
699 memset(&wc, 0, sizeof(wc));
700 wc.cbSize = sizeof(wc);
701 wc.style = CS_DBLCLKS;
702 wc.lpfnWndProc = LogWindowProc;
705 wc.hInstance = hInstance;
706 wc.hIcon = g_hiconApp;
708 wc.hbrBackground = 0;
709 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
710 wc.lpszClassName = szWndName;
711 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
712 RegisterClassEx(&wc);
714 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
715 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
716 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
718 /* Now create a child list box */
719 GetClientRect(hwnd, &rcClient);
721 /* Create a rich edit control */
723 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
724 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
725 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
726 hwnd, NULL, hInstance, NULL);
727 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
729 /* Subclass the control to catch certain messages */
730 g_fnLogBox = (WNDPROC) GetWindowLongPtr(g_hwndLogBox, GWLP_WNDPROC);
731 SetWindowLongPtr(g_hwndLogBox, GWLP_WNDPROC, (LONG_PTR) LogRichEditProc);
733 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
734 if (!g_bShowOnTaskBar &&
735 (nCmdShow == SW_SHOWMINIMIZED ||
736 nCmdShow == SW_MINIMIZE ||
737 nCmdShow == SW_SHOWMINNOACTIVE))
739 g_bShowLogWindow = FALSE;
743 ShowWindow(hwnd, nCmdShow);
747 GetClientRect(g_hwndLogFrame, &rcClient);
748 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
755 /*********************************************************************
757 * Function : InitRichEdit
759 * Description : Initialise the rich edit control library.
763 * Returns : TRUE => success, FALSE => failure.
764 * FIXME: this is backwards to the rest of IJB and to common
765 * programming practice. Please use 0 => success instead.
767 *********************************************************************/
768 BOOL InitRichEdit(void)
770 static HINSTANCE hInstRichEdit;
771 if (hInstRichEdit == NULL)
773 g_nRichEditVersion = 0;
774 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
777 g_nRichEditVersion = _RICHEDIT_VER;
781 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
784 g_nRichEditVersion = 0x0100;
788 return (hInstRichEdit != NULL) ? TRUE : FALSE;
793 /*********************************************************************
795 * Function : ShowLogWindow
797 * Description : Shows or hides the log window. We will also raise the
798 * window on a show command in case it is buried.
801 * 1 : bShow = TRUE to show, FALSE to mimize/hide
805 *********************************************************************/
806 void ShowLogWindow(BOOL bShow)
810 SetForegroundWindow(g_hwndLogFrame);
811 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
814 else if (g_bShowOnTaskBar)
816 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
820 ShowWindow(g_hwndLogFrame, SW_HIDE);
825 /*********************************************************************
827 * Function : EditFile
829 * Description : Opens the specified setting file for editing.
830 * FIXME: What if the file has no associated application. Check for return values
831 * from ShellExecute??
834 * 1 : filename = filename from the config (aka config.txt) file.
838 *********************************************************************/
839 void EditFile(const char *filename)
843 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
849 /*--------------------------------------------------------------------------*/
850 /* Windows message handlers */
851 /*--------------------------------------------------------------------------*/
854 /*********************************************************************
856 * Function : OnLogRButtonUp
858 * Description : Handler for WM_RBUTTONUP messages.
861 * 1 : nModifier = wParam from mouse message (unused)
862 * 2 : x = x coordinate of the mouse event
863 * 3 : y = y coordinate of the mouse event
867 *********************************************************************/
868 void OnLogRButtonUp(int nModifier, int x, int y)
870 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
873 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
875 /* Check if there is a selection */
877 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
878 if (range.cpMin == range.cpMax)
880 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
884 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
887 /* Display the popup */
888 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
895 /*********************************************************************
897 * Function : OnLogCommand
899 * Description : Handler for WM_COMMAND messages.
902 * 1 : nCommand = the command portion of the menu selection event
906 *********************************************************************/
907 void OnLogCommand(int nCommand)
911 case ID_TOGGLE_SHOWWINDOW:
912 g_bShowLogWindow = !g_bShowLogWindow;
914 ShowLogWindow(g_bShowLogWindow);
918 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
922 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
925 case ID_VIEW_CLEARLOG:
926 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
929 case ID_VIEW_LOGMESSAGES:
930 g_bLogMessages = !g_bLogMessages;
931 /* SaveLogSettings(); */
934 case ID_VIEW_MESSAGEHIGHLIGHTING:
935 g_bHighlightMessages = !g_bHighlightMessages;
936 /* SaveLogSettings(); */
939 case ID_VIEW_LIMITBUFFERSIZE:
940 g_bLimitBufferSize = !g_bLimitBufferSize;
941 /* SaveLogSettings(); */
944 case ID_VIEW_ACTIVITYANIMATION:
945 g_bShowActivityAnimation = !g_bShowActivityAnimation;
946 /* SaveLogSettings(); */
949 #ifdef FEATURE_TOGGLE
950 case ID_TOGGLE_ENABLED:
951 global_toggle_state = !global_toggle_state;
952 log_error(LOG_LEVEL_INFO,
953 "Now toggled %s", global_toggle_state ? "ON" : "OFF");
955 * Leverage TIMER_ANIMSTOP_ID to set the idle icon through the
956 * "application queue". According to MSDN, 10 milliseconds are
957 * the lowest value possible and seem to be close enough to
960 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, 10, NULL);
962 #endif /* def FEATURE_TOGGLE */
964 case ID_TOOLS_EDITCONFIG:
965 EditFile(configfile);
968 case ID_TOOLS_EDITDEFAULTACTIONS:
969 EditFile(g_default_actions_file);
972 case ID_TOOLS_EDITUSERACTIONS:
973 EditFile(g_user_actions_file);
976 case ID_TOOLS_EDITDEFAULTFILTERS:
977 EditFile(g_default_filterfile);
980 case ID_TOOLS_EDITUSERFILTERS:
981 EditFile(g_user_filterfile);
985 case ID_TOOLS_EDITTRUST:
986 EditFile(g_trustfile);
988 #endif /* def FEATURE_TRUST */
991 ShellExecute(g_hwndLogFrame, "open", "LICENSE.txt", NULL, NULL, SW_SHOWNORMAL);
995 ShellExecute(g_hwndLogFrame, "open", "doc\\faq\\index.html", NULL, NULL, SW_SHOWNORMAL);
999 ShellExecute(g_hwndLogFrame, "open", "doc\\user-manual\\index.html", NULL, NULL, SW_SHOWNORMAL);
1002 case ID_HELP_STATUS:
1003 ShellExecute(g_hwndLogFrame, "open", CGI_PREFIX "show-status", NULL, NULL, SW_SHOWNORMAL);
1007 MessageBox(g_hwndLogFrame, win32_blurb, "About Privoxy", MB_OK);
1018 /*********************************************************************
1020 * Function : OnLogInitMenu
1022 * Description : Handler for WM_INITMENU messages. Enable, disable,
1023 * check, and/or uncheck menu options as apropos.
1026 * 1 : hmenu = handle to menu to "make current"
1030 *********************************************************************/
1031 void OnLogInitMenu(HMENU hmenu)
1033 /* Only enable editors if there is a file to edit */
1034 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTACTIONS, MF_BYCOMMAND | (g_default_actions_file ? MF_ENABLED : MF_GRAYED));
1035 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERACTIONS, MF_BYCOMMAND | (g_user_actions_file ? MF_ENABLED : MF_GRAYED));
1036 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTFILTERS, MF_BYCOMMAND | (g_default_filterfile ? MF_ENABLED : MF_GRAYED));
1037 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERFILTERS, MF_BYCOMMAND | (g_user_filterfile ? MF_ENABLED : MF_GRAYED));
1038 #ifdef FEATURE_TRUST
1039 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1040 #endif /* def FEATURE_TRUST */
1042 /* Check/uncheck options */
1043 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1044 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1045 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1046 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1047 #ifdef FEATURE_TOGGLE
1048 /* by haroon - menu item for Enable toggle on/off */
1049 CheckMenuItem(hmenu, ID_TOGGLE_ENABLED, MF_BYCOMMAND | (global_toggle_state ? MF_CHECKED : MF_UNCHECKED));
1050 #endif /* def FEATURE_TOGGLE */
1051 CheckMenuItem(hmenu, ID_TOGGLE_SHOWWINDOW, MF_BYCOMMAND | (g_bShowLogWindow ? MF_CHECKED : MF_UNCHECKED));
1056 /*********************************************************************
1058 * Function : OnLogTimer
1060 * Description : Handler for WM_TIMER messages.
1063 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1067 *********************************************************************/
1068 void OnLogTimer(int nTimer)
1073 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1076 case TIMER_ANIMSTOP_ID:
1079 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1080 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1083 case TIMER_CLIPBUFFER_ID:
1084 case TIMER_CLIPBUFFER_FORCE_ID:
1086 g_bClipPending = FALSE;
1087 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1088 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1099 /*********************************************************************
1101 * Function : SetIdleIcon
1103 * Description : Sets the tray icon to either idle or off
1109 *********************************************************************/
1112 #ifdef FEATURE_TOGGLE
1113 if (!global_toggle_state)
1115 TraySetIcon(g_hwndTray, 1, g_hiconOff);
1118 #endif /* def FEATURE_TOGGLE */
1119 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1123 /*********************************************************************
1125 * Function : LogRichEditProc
1127 * Description : Window subclass routine handles some events for the rich edit control.
1130 * 1 : hwnd = window handle of the rich edit control
1131 * 2 : uMsg = message number
1132 * 3 : wParam = first param for this message
1133 * 4 : lParam = next param for this message
1135 * Returns : Appropriate M$ window message handler codes.
1137 *********************************************************************/
1138 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1145 pt.x = LOWORD(lParam);
1146 pt.y = HIWORD(lParam);
1147 ClientToScreen(hwnd, &pt);
1148 OnLogRButtonUp(wParam, pt.x, pt.y);
1153 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1155 OnLogCommand(ID_VIEW_CLEARLOG);
1160 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1165 /*********************************************************************
1167 * Function : LogWindowProc
1169 * Description : Windows call back routine handles events on the log window.
1172 * 1 : hwnd = handle of the logging window
1173 * 2 : uMsg = message number
1174 * 3 : wParam = first param for this message
1175 * 4 : lParam = next param for this message
1177 * Returns : Appropriate M$ window message handler codes.
1179 *********************************************************************/
1180 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1188 /* This is the end - my only friend - the end */
1189 DestroyWindow(g_hwndLogBox);
1190 DestroyWindow(g_hwndLogFrame);
1198 g_bShowLogWindow = wParam;
1200 /* Resize the logging window to fit the new frame */
1204 GetClientRect(g_hwndLogFrame, &rc);
1205 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1210 OnLogInitMenu((HMENU) wParam);
1218 OnLogCommand(LOWORD(wParam));
1225 if (g_bCloseHidesWindow)
1227 ShowLogWindow(FALSE);
1232 ShowLogWindow(FALSE);
1238 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1240 OnLogCommand(ID_VIEW_CLEARLOG);
1246 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1250 #endif /* ndef _WIN_CONSOLE - entire file */