1 const char w32log_rcs[] = "$Id: w32log.c,v 1.45 2012/05/24 15:05:17 fabiankeil 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 { "Crunching Referer:", STYLE_HIGHLIGHT },
176 /* what are all the possible error strings?? */
177 { "Error:", STYLE_HIGHLIGHT },
179 { "referer:", STYLE_HEADER },
180 { "proxy-connection:", STYLE_HEADER },
181 { "proxy-agent:", STYLE_HEADER },
182 { "user-agent:", STYLE_HEADER },
183 { "host:", STYLE_HEADER },
184 { "accept:", STYLE_HEADER },
185 { "accept-encoding:", STYLE_HEADER },
186 { "accept-language:", STYLE_HEADER },
187 { "accept-charset:", STYLE_HEADER },
188 { "accept-ranges:", STYLE_HEADER },
189 { "date:", STYLE_HEADER },
190 { "cache-control:", STYLE_HEADER },
191 { "cache-last-checked:", STYLE_HEADER },
192 { "connection:", STYLE_HEADER },
193 { "content-type", STYLE_HEADER },
194 { "content-length", STYLE_HEADER },
195 { "cookie", STYLE_HEADER },
196 { "last-modified:", STYLE_HEADER },
197 { "pragma:", STYLE_HEADER },
198 { "server:", STYLE_HEADER },
199 { "etag:", STYLE_HEADER },
200 { "expires:", STYLE_HEADER },
201 { "warning:", STYLE_HEADER },
202 /* this is the terminator statement - do not delete! */
215 static CRITICAL_SECTION g_criticalsection;
216 static HWND g_hwndTray;
217 static HWND g_hwndLogBox;
218 static WNDPROC g_fnLogBox;
219 static HICON g_hiconAnim[ANIM_FRAMES];
220 static HICON g_hiconIdle;
221 static HICON g_hiconOff;
222 static int g_nAnimFrame;
223 static BOOL g_bClipPending = FALSE;
224 static int g_nRichEditVersion = 0;
229 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
230 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
231 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
232 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
233 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
234 static BOOL InitRichEdit(void);
235 static void LogClipBuffer(void);
236 static void LogCreatePatternMatchingBuffers(void);
237 static void LogDestroyPatternMatchingBuffers(void);
238 static int LogPutStringNoMatch(const char *pszText, int style);
239 static void SetIdleIcon(void);
242 /*********************************************************************
244 * Function : InitLogWindow
246 * Description : Initialise the log window.
250 * Returns : Always TRUE (there should be error checking on the resources).
252 *********************************************************************/
253 BOOL InitLogWindow(void)
258 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
259 g_hiconOff = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_OFF));
260 for (i = 0; i < ANIM_FRAMES; i++)
262 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ANIMATED1 + i));
264 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_MAINICON));
266 /* Create the user interface */
267 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
268 g_hwndTray = CreateTrayWindow(g_hInstance);
269 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Privoxy");
271 /* Create pattern matching buffers (for highlighting */
272 LogCreatePatternMatchingBuffers();
274 /* Create a critical section to protect multi-threaded access to certain things */
275 InitializeCriticalSection(&g_criticalsection);
282 /*********************************************************************
284 * Function : TermLogWindow
286 * Description : Cleanup the logwindow.
292 *********************************************************************/
293 void TermLogWindow(void)
297 LogDestroyPatternMatchingBuffers();
299 TrayDeleteIcon(g_hwndTray, 1);
300 DeleteObject(g_hiconApp);
301 DeleteObject(g_hiconIdle);
302 DeleteObject(g_hiconOff);
303 for (i = 0; i < ANIM_FRAMES; i++)
305 DeleteObject(g_hiconAnim[i]);
311 /*********************************************************************
313 * Function : LogCreatePatternMatchingBuffers
315 * Description : Compile the pattern matching buffers.
321 *********************************************************************/
322 void LogCreatePatternMatchingBuffers(void)
325 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
327 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
332 /*********************************************************************
334 * Function : LogDestroyPatternMatchingBuffers
336 * Description : Free up the pattern matching buffers.
342 *********************************************************************/
343 void LogDestroyPatternMatchingBuffers(void)
346 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
348 regfree(&patterns_to_highlight[i].buffer);
353 /*********************************************************************
355 * Function : LogPutString
357 * Description : Inserts text into the logging window. This is really
358 * a regexp aware wrapper function to `LogPutStringNoMatch'.
361 * 1 : pszText = pointer to string going to the log window
363 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
364 * FIXME: this is backwards to the rest of IJB and to common
365 * programming practice. Please use 0 => success instead.
367 *********************************************************************/
368 int LogPutString(const char *pszText)
378 if (pszText == NULL || strlen(pszText) == 0)
383 /* Critical section stops multiple threads doing nasty interactions that
384 * foul up the highlighting and output.
386 EnterCriticalSection(&g_criticalsection);
388 if (g_bHighlightMessages)
392 /* First things first, regexp scan for various things that we would like highlighted */
393 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
395 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
397 char *pszBefore = NULL;
398 char *pszMatch = NULL;
399 char *pszAfter = NULL;
402 /* Split the string up into pieces representing the strings, before
403 at and after the matching pattern
407 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
408 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
409 strncpy(pszBefore, pszText, match.rm_so);
411 if (match.rm_eo < (regoff_t)strlen(pszText))
413 pszAfter = strdup(&pszText[match.rm_eo]);
415 nMatchSize = match.rm_eo - match.rm_so;
416 pszMatch = (char *)malloc(nMatchSize + 1);
417 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
418 pszMatch[nMatchSize] = '\0';
420 /* Recursively call LogPutString */
423 LogPutString(pszBefore);
428 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
433 LogPutString(pszAfter);
443 result = LogPutStringNoMatch(pszText, STYLE_NONE);
446 LeaveCriticalSection(&g_criticalsection);
453 /*********************************************************************
455 * Function : LogPutStringNoMatch
457 * Description : Puts a string into the logging window.
460 * 1 : pszText = pointer to string going to the log window
461 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
463 * Returns : Always 1 => success.
464 * FIXME: this is backwards to the rest of IJB and to common
465 * programming practice. Please use 0 => success instead.
467 *********************************************************************/
468 int LogPutStringNoMatch(const char *pszText, int style)
474 assert(g_hwndLogBox);
475 if (g_hwndLogBox == NULL)
480 /* TODO preserve existing selection */
482 /* Go to the end of the text */
483 nTextLength = GetWindowTextLength(g_hwndLogBox);
484 range.cpMin = nTextLength;
485 range.cpMax = nTextLength;
486 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
488 /* Apply a formatting style */
489 memset(&format, 0, sizeof(format));
490 format.cbSize = sizeof(format);
491 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT |
492 CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET;
493 format.bCharSet = DEFAULT_CHARSET;
494 format.yHeight = (g_nFontSize * 1440) / 72;
495 strlcpy(format.szFaceName, g_szFontFaceName, sizeof(format.szFaceName));
496 if (style == STYLE_NONE)
499 format.dwEffects |= CFE_AUTOCOLOR;
501 else if (style == STYLE_HEADER)
503 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
505 else if (style == STYLE_HIGHLIGHT)
507 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
509 else if (style == STYLE_LINK)
511 format.dwEffects |= CFE_UNDERLINE;
512 format.crTextColor = RGB(0, 0, 255);
514 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
516 /* Append text to the end */
517 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
519 /* TODO Restore the old selection */
522 if (strchr(pszText, '\n') != NULL)
524 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
527 /* Set the force clip timer going. This timer ensures clipping is done
528 intermittently even when there is a sustained burst of logging
530 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
532 g_bClipPending = TRUE;
540 /*********************************************************************
542 * Function : LogShowActivity
544 * Description : Start the spinner.
550 *********************************************************************/
551 void LogShowActivity(void)
555 /* Try to figure out if SetIdleIcon() is thread-safe */
556 for (i = 0; i < 1000; i++)
561 /* Start some activity timers */
562 if (g_bShowActivityAnimation)
564 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
565 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
571 /*********************************************************************
573 * Function : LogClipBuffer
575 * Description : Prunes old lines from the log.
581 *********************************************************************/
582 void LogClipBuffer(void)
584 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
585 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
587 /* Compute the range representing the lines to be deleted */
588 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
589 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
592 range.cpMax = nLastChar;
594 /* TODO get current selection */
596 /* TODO adjust and clip old selection against range to be deleted */
598 /* Select range and erase it (turning off autoscroll to prevent
600 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
601 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
602 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
603 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
605 /* reposition (back to) the end of the log content */
606 range.cpMin = SendMessage (g_hwndLogBox, WM_GETTEXTLENGTH, 0, 0);
608 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
610 /* restore vertical ScrollBar stuff (messed up by AUTOVSCROLL) */
611 SendMessage (g_hwndLogBox, EM_SCROLL, SB_LINEDOWN, 0);
618 /*********************************************************************
620 * Function : CreateHiddenLogOwnerWindow
622 * Description : Creates a hidden owner window that stops the log
623 * window appearing in the task bar.
626 * 1 : hInstance = application's instance handle
628 * Returns : Handle to newly created window.
630 *********************************************************************/
631 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
633 static const char *szWndName = "PrivoxyLogOwner";
638 wc.lpfnWndProc = LogOwnerWindowProc;
641 wc.hInstance = hInstance;
642 wc.hIcon = g_hiconApp;
644 wc.hbrBackground = 0;
646 wc.lpszClassName = szWndName;
650 hwnd = CreateWindow(szWndName, szWndName,
651 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
652 CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
659 /*********************************************************************
661 * Function : LogOwnerWindowProc
663 * Description : Dummy procedure that does nothing special.
666 * 1 : hwnd = window handle
667 * 2 : uMsg = message number
668 * 3 : wParam = first param for this message
669 * 4 : lParam = next param for this message
671 * Returns : Same as `DefWindowProc'.
673 *********************************************************************/
674 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
676 return DefWindowProc(hwnd, uMsg, wParam, lParam);
681 /*********************************************************************
683 * Function : CreateLogWindow
685 * Description : Create the logging window.
688 * 1 : hInstance = application's instance handle
689 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
691 * Returns : Handle to newly created window.
693 *********************************************************************/
694 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
696 static const char *szWndName = "PrivoxyLogWindow";
697 static const char *szWndTitle = "Privoxy";
700 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
704 memset(&wc, 0, sizeof(wc));
705 wc.cbSize = sizeof(wc);
706 wc.style = CS_DBLCLKS;
707 wc.lpfnWndProc = LogWindowProc;
710 wc.hInstance = hInstance;
711 wc.hIcon = g_hiconApp;
713 wc.hbrBackground = 0;
714 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
715 wc.lpszClassName = szWndName;
716 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
717 RegisterClassEx(&wc);
719 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
720 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
721 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
723 /* Now create a child list box */
724 GetClientRect(hwnd, &rcClient);
726 /* Create a rich edit control */
728 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
729 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
730 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
731 hwnd, NULL, hInstance, NULL);
732 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
734 /* Subclass the control to catch certain messages */
735 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
736 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
738 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
739 if (!g_bShowOnTaskBar &&
740 (nCmdShow == SW_SHOWMINIMIZED ||
741 nCmdShow == SW_MINIMIZE ||
742 nCmdShow == SW_SHOWMINNOACTIVE))
744 g_bShowLogWindow = FALSE;
748 ShowWindow(hwnd, nCmdShow);
752 GetClientRect(g_hwndLogFrame, &rcClient);
753 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
760 /*********************************************************************
762 * Function : InitRichEdit
764 * Description : Initialise the rich edit control library.
768 * Returns : TRUE => success, FALSE => failure.
769 * FIXME: this is backwards to the rest of IJB and to common
770 * programming practice. Please use 0 => success instead.
772 *********************************************************************/
773 BOOL InitRichEdit(void)
775 static HINSTANCE hInstRichEdit;
776 if (hInstRichEdit == NULL)
778 g_nRichEditVersion = 0;
779 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
782 g_nRichEditVersion = _RICHEDIT_VER;
786 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
789 g_nRichEditVersion = 0x0100;
793 return (hInstRichEdit != NULL) ? TRUE : FALSE;
798 /*********************************************************************
800 * Function : ShowLogWindow
802 * Description : Shows or hides the log window. We will also raise the
803 * window on a show command in case it is buried.
806 * 1 : bShow = TRUE to show, FALSE to mimize/hide
810 *********************************************************************/
811 void ShowLogWindow(BOOL bShow)
815 SetForegroundWindow(g_hwndLogFrame);
816 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
819 else if (g_bShowOnTaskBar)
821 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
825 ShowWindow(g_hwndLogFrame, SW_HIDE);
830 /*********************************************************************
832 * Function : EditFile
834 * Description : Opens the specified setting file for editing.
835 * FIXME: What if the file has no associated application. Check for return values
836 * from ShellExecute??
839 * 1 : filename = filename from the config (aka config.txt) file.
843 *********************************************************************/
844 void EditFile(const char *filename)
848 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
854 /*--------------------------------------------------------------------------*/
855 /* Windows message handlers */
856 /*--------------------------------------------------------------------------*/
859 /*********************************************************************
861 * Function : OnLogRButtonUp
863 * Description : Handler for WM_RBUTTONUP messages.
866 * 1 : nModifier = wParam from mouse message (unused)
867 * 2 : x = x coordinate of the mouse event
868 * 3 : y = y coordinate of the mouse event
872 *********************************************************************/
873 void OnLogRButtonUp(int nModifier, int x, int y)
875 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
878 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
880 /* Check if there is a selection */
882 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
883 if (range.cpMin == range.cpMax)
885 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
889 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
892 /* Display the popup */
893 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
900 /*********************************************************************
902 * Function : OnLogCommand
904 * Description : Handler for WM_COMMAND messages.
907 * 1 : nCommand = the command portion of the menu selection event
911 *********************************************************************/
912 void OnLogCommand(int nCommand)
916 case ID_TOGGLE_SHOWWINDOW:
917 g_bShowLogWindow = !g_bShowLogWindow;
919 ShowLogWindow(g_bShowLogWindow);
923 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
927 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
930 case ID_VIEW_CLEARLOG:
931 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
934 case ID_VIEW_LOGMESSAGES:
935 g_bLogMessages = !g_bLogMessages;
936 /* SaveLogSettings(); */
939 case ID_VIEW_MESSAGEHIGHLIGHTING:
940 g_bHighlightMessages = !g_bHighlightMessages;
941 /* SaveLogSettings(); */
944 case ID_VIEW_LIMITBUFFERSIZE:
945 g_bLimitBufferSize = !g_bLimitBufferSize;
946 /* SaveLogSettings(); */
949 case ID_VIEW_ACTIVITYANIMATION:
950 g_bShowActivityAnimation = !g_bShowActivityAnimation;
951 /* SaveLogSettings(); */
954 #ifdef FEATURE_TOGGLE
955 case ID_TOGGLE_ENABLED:
956 global_toggle_state = !global_toggle_state;
957 log_error(LOG_LEVEL_INFO,
958 "Now toggled %s", global_toggle_state ? "ON" : "OFF");
960 * Leverage TIMER_ANIMSTOP_ID to set the idle icon through the
961 * "application queue". According to MSDN, 10 milliseconds are
962 * the lowest value possible and seem to be close enough to
965 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, 10, NULL);
967 #endif /* def FEATURE_TOGGLE */
969 case ID_TOOLS_EDITCONFIG:
970 EditFile(configfile);
973 case ID_TOOLS_EDITDEFAULTACTIONS:
974 EditFile(g_default_actions_file);
977 case ID_TOOLS_EDITUSERACTIONS:
978 EditFile(g_user_actions_file);
981 case ID_TOOLS_EDITDEFAULTFILTERS:
982 EditFile(g_default_filterfile);
985 case ID_TOOLS_EDITUSERFILTERS:
986 EditFile(g_user_filterfile);
990 case ID_TOOLS_EDITTRUST:
991 EditFile(g_trustfile);
993 #endif /* def FEATURE_TRUST */
996 ShellExecute(g_hwndLogFrame, "open", "LICENSE.txt", NULL, NULL, SW_SHOWNORMAL);
1000 ShellExecute(g_hwndLogFrame, "open", "doc\\faq\\index.html", NULL, NULL, SW_SHOWNORMAL);
1003 case ID_HELP_MANUAL:
1004 ShellExecute(g_hwndLogFrame, "open", "doc\\user-manual\\index.html", NULL, NULL, SW_SHOWNORMAL);
1007 case ID_HELP_STATUS:
1008 ShellExecute(g_hwndLogFrame, "open", CGI_PREFIX "show-status", NULL, NULL, SW_SHOWNORMAL);
1012 MessageBox(g_hwndLogFrame, win32_blurb, "About Privoxy", MB_OK);
1023 /*********************************************************************
1025 * Function : OnLogInitMenu
1027 * Description : Handler for WM_INITMENU messages. Enable, disable,
1028 * check, and/or uncheck menu options as apropos.
1031 * 1 : hmenu = handle to menu to "make current"
1035 *********************************************************************/
1036 void OnLogInitMenu(HMENU hmenu)
1038 /* Only enable editors if there is a file to edit */
1039 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTACTIONS, MF_BYCOMMAND | (g_default_actions_file ? MF_ENABLED : MF_GRAYED));
1040 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERACTIONS, MF_BYCOMMAND | (g_user_actions_file ? MF_ENABLED : MF_GRAYED));
1041 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTFILTERS, MF_BYCOMMAND | (g_default_filterfile ? MF_ENABLED : MF_GRAYED));
1042 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERFILTERS, MF_BYCOMMAND | (g_user_filterfile ? MF_ENABLED : MF_GRAYED));
1043 #ifdef FEATURE_TRUST
1044 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1045 #endif /* def FEATURE_TRUST */
1047 /* Check/uncheck options */
1048 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1049 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1050 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1051 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1052 #ifdef FEATURE_TOGGLE
1053 /* by haroon - menu item for Enable toggle on/off */
1054 CheckMenuItem(hmenu, ID_TOGGLE_ENABLED, MF_BYCOMMAND | (global_toggle_state ? MF_CHECKED : MF_UNCHECKED));
1055 #endif /* def FEATURE_TOGGLE */
1056 CheckMenuItem(hmenu, ID_TOGGLE_SHOWWINDOW, MF_BYCOMMAND | (g_bShowLogWindow ? MF_CHECKED : MF_UNCHECKED));
1061 /*********************************************************************
1063 * Function : OnLogTimer
1065 * Description : Handler for WM_TIMER messages.
1068 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1072 *********************************************************************/
1073 void OnLogTimer(int nTimer)
1078 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1081 case TIMER_ANIMSTOP_ID:
1084 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1085 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1088 case TIMER_CLIPBUFFER_ID:
1089 case TIMER_CLIPBUFFER_FORCE_ID:
1091 g_bClipPending = FALSE;
1092 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1093 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1104 /*********************************************************************
1106 * Function : SetIdleIcon
1108 * Description : Sets the tray icon to either idle or off
1114 *********************************************************************/
1117 #ifdef FEATURE_TOGGLE
1118 if (!global_toggle_state)
1120 TraySetIcon(g_hwndTray, 1, g_hiconOff);
1123 #endif /* def FEATURE_TOGGLE */
1124 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1128 /*********************************************************************
1130 * Function : LogRichEditProc
1132 * Description : Window subclass routine handles some events for the rich edit control.
1135 * 1 : hwnd = window handle of the rich edit control
1136 * 2 : uMsg = message number
1137 * 3 : wParam = first param for this message
1138 * 4 : lParam = next param for this message
1140 * Returns : Appropriate M$ window message handler codes.
1142 *********************************************************************/
1143 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1150 pt.x = LOWORD(lParam);
1151 pt.y = HIWORD(lParam);
1152 ClientToScreen(hwnd, &pt);
1153 OnLogRButtonUp(wParam, pt.x, pt.y);
1158 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1160 OnLogCommand(ID_VIEW_CLEARLOG);
1165 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1170 /*********************************************************************
1172 * Function : LogWindowProc
1174 * Description : Windows call back routine handles events on the log window.
1177 * 1 : hwnd = handle of the logging window
1178 * 2 : uMsg = message number
1179 * 3 : wParam = first param for this message
1180 * 4 : lParam = next param for this message
1182 * Returns : Appropriate M$ window message handler codes.
1184 *********************************************************************/
1185 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1193 /* This is the end - my only friend - the end */
1194 DestroyWindow(g_hwndLogBox);
1195 DestroyWindow(g_hwndLogFrame);
1203 g_bShowLogWindow = wParam;
1205 /* Resize the logging window to fit the new frame */
1209 GetClientRect(g_hwndLogFrame, &rc);
1210 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1215 OnLogInitMenu((HMENU) wParam);
1223 OnLogCommand(LOWORD(wParam));
1230 if (g_bCloseHidesWindow)
1232 ShowLogWindow(FALSE);
1237 ShowLogWindow(FALSE);
1243 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1245 OnLogCommand(ID_VIEW_CLEARLOG);
1251 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1255 #endif /* ndef _WIN_CONSOLE - entire file */