1 const char w32log_rcs[] = "$Id: w32log.c,v 1.40 2011/09/04 11:10:56 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)
553 /* Start some activity timers */
554 if (g_bShowActivityAnimation)
556 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
557 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
563 /*********************************************************************
565 * Function : LogClipBuffer
567 * Description : Prunes old lines from the log.
573 *********************************************************************/
574 void LogClipBuffer(void)
576 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
577 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
579 /* Compute the range representing the lines to be deleted */
580 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
581 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
584 range.cpMax = nLastChar;
586 /* TODO get current selection */
588 /* TODO adjust and clip old selection against range to be deleted */
590 /* Select range and erase it (turning off autoscroll to prevent
592 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
593 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
594 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
595 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
597 /* reposition (back to) the end of the log content */
598 range.cpMin = SendMessage (g_hwndLogBox, WM_GETTEXTLENGTH, 0, 0);
600 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
602 /* restore vertical ScrollBar stuff (messed up by AUTOVSCROLL) */
603 SendMessage (g_hwndLogBox, EM_SCROLL, SB_LINEDOWN, 0);
610 /*********************************************************************
612 * Function : CreateHiddenLogOwnerWindow
614 * Description : Creates a hidden owner window that stops the log
615 * window appearing in the task bar.
618 * 1 : hInstance = application's instance handle
620 * Returns : Handle to newly created window.
622 *********************************************************************/
623 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
625 static const char *szWndName = "PrivoxyLogOwner";
630 wc.lpfnWndProc = LogOwnerWindowProc;
633 wc.hInstance = hInstance;
634 wc.hIcon = g_hiconApp;
636 wc.hbrBackground = 0;
638 wc.lpszClassName = szWndName;
642 hwnd = CreateWindow(szWndName, szWndName,
643 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
644 CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
651 /*********************************************************************
653 * Function : LogOwnerWindowProc
655 * Description : Dummy procedure that does nothing special.
658 * 1 : hwnd = window handle
659 * 2 : uMsg = message number
660 * 3 : wParam = first param for this message
661 * 4 : lParam = next param for this message
663 * Returns : Same as `DefWindowProc'.
665 *********************************************************************/
666 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
668 return DefWindowProc(hwnd, uMsg, wParam, lParam);
673 /*********************************************************************
675 * Function : CreateLogWindow
677 * Description : Create the logging window.
680 * 1 : hInstance = application's instance handle
681 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
683 * Returns : Handle to newly created window.
685 *********************************************************************/
686 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
688 static const char *szWndName = "PrivoxyLogWindow";
689 static const char *szWndTitle = "Privoxy";
692 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
696 memset(&wc, 0, sizeof(wc));
697 wc.cbSize = sizeof(wc);
698 wc.style = CS_DBLCLKS;
699 wc.lpfnWndProc = LogWindowProc;
702 wc.hInstance = hInstance;
703 wc.hIcon = g_hiconApp;
705 wc.hbrBackground = 0;
706 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
707 wc.lpszClassName = szWndName;
708 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
709 RegisterClassEx(&wc);
711 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
712 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
713 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
715 /* Now create a child list box */
716 GetClientRect(hwnd, &rcClient);
718 /* Create a rich edit control */
720 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
721 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
722 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
723 hwnd, NULL, hInstance, NULL);
724 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
726 /* Subclass the control to catch certain messages */
727 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
728 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
730 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
731 if (!g_bShowOnTaskBar &&
732 (nCmdShow == SW_SHOWMINIMIZED ||
733 nCmdShow == SW_MINIMIZE ||
734 nCmdShow == SW_SHOWMINNOACTIVE))
736 g_bShowLogWindow = FALSE;
740 ShowWindow(hwnd, nCmdShow);
744 GetClientRect(g_hwndLogFrame, &rcClient);
745 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
752 /*********************************************************************
754 * Function : InitRichEdit
756 * Description : Initialise the rich edit control library.
760 * Returns : TRUE => success, FALSE => failure.
761 * FIXME: this is backwards to the rest of IJB and to common
762 * programming practice. Please use 0 => success instead.
764 *********************************************************************/
765 BOOL InitRichEdit(void)
767 static HINSTANCE hInstRichEdit;
768 if (hInstRichEdit == NULL)
770 g_nRichEditVersion = 0;
771 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
774 g_nRichEditVersion = _RICHEDIT_VER;
778 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
781 g_nRichEditVersion = 0x0100;
785 return (hInstRichEdit != NULL) ? TRUE : FALSE;
790 /*********************************************************************
792 * Function : ShowLogWindow
794 * Description : Shows or hides the log window. We will also raise the
795 * window on a show command in case it is buried.
798 * 1 : bShow = TRUE to show, FALSE to mimize/hide
802 *********************************************************************/
803 void ShowLogWindow(BOOL bShow)
807 SetForegroundWindow(g_hwndLogFrame);
808 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
811 else if (g_bShowOnTaskBar)
813 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
817 ShowWindow(g_hwndLogFrame, SW_HIDE);
822 /*********************************************************************
824 * Function : EditFile
826 * Description : Opens the specified setting file for editing.
827 * FIXME: What if the file has no associated application. Check for return values
828 * from ShellExecute??
831 * 1 : filename = filename from the config (aka config.txt) file.
835 *********************************************************************/
836 void EditFile(const char *filename)
840 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
846 /*--------------------------------------------------------------------------*/
847 /* Windows message handlers */
848 /*--------------------------------------------------------------------------*/
851 /*********************************************************************
853 * Function : OnLogRButtonUp
855 * Description : Handler for WM_RBUTTONUP messages.
858 * 1 : nModifier = wParam from mouse message (unused)
859 * 2 : x = x coordinate of the mouse event
860 * 3 : y = y coordinate of the mouse event
864 *********************************************************************/
865 void OnLogRButtonUp(int nModifier, int x, int y)
867 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
870 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
872 /* Check if there is a selection */
874 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
875 if (range.cpMin == range.cpMax)
877 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
881 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
884 /* Display the popup */
885 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
892 /*********************************************************************
894 * Function : OnLogCommand
896 * Description : Handler for WM_COMMAND messages.
899 * 1 : nCommand = the command portion of the menu selection event
903 *********************************************************************/
904 void OnLogCommand(int nCommand)
908 case ID_TOGGLE_SHOWWINDOW:
909 g_bShowLogWindow = !g_bShowLogWindow;
911 ShowLogWindow(g_bShowLogWindow);
915 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
919 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
922 case ID_VIEW_CLEARLOG:
923 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
926 case ID_VIEW_LOGMESSAGES:
927 g_bLogMessages = !g_bLogMessages;
928 /* SaveLogSettings(); */
931 case ID_VIEW_MESSAGEHIGHLIGHTING:
932 g_bHighlightMessages = !g_bHighlightMessages;
933 /* SaveLogSettings(); */
936 case ID_VIEW_LIMITBUFFERSIZE:
937 g_bLimitBufferSize = !g_bLimitBufferSize;
938 /* SaveLogSettings(); */
941 case ID_VIEW_ACTIVITYANIMATION:
942 g_bShowActivityAnimation = !g_bShowActivityAnimation;
943 /* SaveLogSettings(); */
946 #ifdef FEATURE_TOGGLE
947 /* by haroon - change toggle to its opposite value */
948 case ID_TOGGLE_ENABLED:
949 global_toggle_state = !global_toggle_state;
950 if (global_toggle_state)
952 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
956 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
960 #endif /* def FEATURE_TOGGLE */
962 case ID_TOOLS_EDITCONFIG:
963 EditFile(configfile);
966 case ID_TOOLS_EDITDEFAULTACTIONS:
967 EditFile(g_default_actions_file);
970 case ID_TOOLS_EDITUSERACTIONS:
971 EditFile(g_user_actions_file);
974 case ID_TOOLS_EDITDEFAULTFILTERS:
975 EditFile(g_default_filterfile);
978 case ID_TOOLS_EDITUSERFILTERS:
979 EditFile(g_user_filterfile);
983 case ID_TOOLS_EDITTRUST:
984 EditFile(g_trustfile);
986 #endif /* def FEATURE_TRUST */
989 ShellExecute(g_hwndLogFrame, "open", "LICENSE.txt", NULL, NULL, SW_SHOWNORMAL);
993 ShellExecute(g_hwndLogFrame, "open", "doc\\faq\\index.html", NULL, NULL, SW_SHOWNORMAL);
997 ShellExecute(g_hwndLogFrame, "open", "doc\\user-manual\\index.html", NULL, NULL, SW_SHOWNORMAL);
1000 case ID_HELP_STATUS:
1001 ShellExecute(g_hwndLogFrame, "open", CGI_PREFIX "show-status", NULL, NULL, SW_SHOWNORMAL);
1005 MessageBox(g_hwndLogFrame, win32_blurb, "About Privoxy", MB_OK);
1016 /*********************************************************************
1018 * Function : OnLogInitMenu
1020 * Description : Handler for WM_INITMENU messages. Enable, disable,
1021 * check, and/or uncheck menu options as apropos.
1024 * 1 : hmenu = handle to menu to "make current"
1028 *********************************************************************/
1029 void OnLogInitMenu(HMENU hmenu)
1031 /* Only enable editors if there is a file to edit */
1032 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTACTIONS, MF_BYCOMMAND | (g_default_actions_file ? MF_ENABLED : MF_GRAYED));
1033 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERACTIONS, MF_BYCOMMAND | (g_user_actions_file ? MF_ENABLED : MF_GRAYED));
1034 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTFILTERS, MF_BYCOMMAND | (g_default_filterfile ? MF_ENABLED : MF_GRAYED));
1035 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERFILTERS, MF_BYCOMMAND | (g_user_filterfile ? MF_ENABLED : MF_GRAYED));
1036 #ifdef FEATURE_TRUST
1037 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1038 #endif /* def FEATURE_TRUST */
1040 /* Check/uncheck options */
1041 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1042 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1043 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1044 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1045 #ifdef FEATURE_TOGGLE
1046 /* by haroon - menu item for Enable toggle on/off */
1047 CheckMenuItem(hmenu, ID_TOGGLE_ENABLED, MF_BYCOMMAND | (global_toggle_state ? MF_CHECKED : MF_UNCHECKED));
1048 #endif /* def FEATURE_TOGGLE */
1049 CheckMenuItem(hmenu, ID_TOGGLE_SHOWWINDOW, MF_BYCOMMAND | (g_bShowLogWindow ? MF_CHECKED : MF_UNCHECKED));
1054 /*********************************************************************
1056 * Function : OnLogTimer
1058 * Description : Handler for WM_TIMER messages.
1061 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1065 *********************************************************************/
1066 void OnLogTimer(int nTimer)
1071 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1074 case TIMER_ANIMSTOP_ID:
1077 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1078 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1081 case TIMER_CLIPBUFFER_ID:
1082 case TIMER_CLIPBUFFER_FORCE_ID:
1084 g_bClipPending = FALSE;
1085 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1086 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1097 /*********************************************************************
1099 * Function : SetIdleIcon
1101 * Description : Sets the tray icon to either idle or off
1107 *********************************************************************/
1110 #ifdef FEATURE_TOGGLE
1111 if (!global_toggle_state)
1113 TraySetIcon(g_hwndTray, 1, g_hiconOff);
1114 /* log_error(LOG_LEVEL_INFO, "Privoxy OFF icon selected."); */
1117 #endif /* def FEATURE_TOGGLE */
1118 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1122 /*********************************************************************
1124 * Function : LogRichEditProc
1126 * Description : Window subclass routine handles some events for the rich edit control.
1129 * 1 : hwnd = window handle of the rich edit control
1130 * 2 : uMsg = message number
1131 * 3 : wParam = first param for this message
1132 * 4 : lParam = next param for this message
1134 * Returns : Appropriate M$ window message handler codes.
1136 *********************************************************************/
1137 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1144 pt.x = LOWORD(lParam);
1145 pt.y = HIWORD(lParam);
1146 ClientToScreen(hwnd, &pt);
1147 OnLogRButtonUp(wParam, pt.x, pt.y);
1152 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1154 OnLogCommand(ID_VIEW_CLEARLOG);
1159 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1164 /*********************************************************************
1166 * Function : LogWindowProc
1168 * Description : Windows call back routine handles events on the log window.
1171 * 1 : hwnd = handle of the logging window
1172 * 2 : uMsg = message number
1173 * 3 : wParam = first param for this message
1174 * 4 : lParam = next param for this message
1176 * Returns : Appropriate M$ window message handler codes.
1178 *********************************************************************/
1179 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1187 /* This is the end - beautiful friend - the end */
1188 DestroyWindow(g_hwndLogBox);
1189 DestroyWindow(g_hwndLogFrame);
1197 g_bShowLogWindow = wParam;
1199 /* Resize the logging window to fit the new frame */
1203 GetClientRect(g_hwndLogFrame, &rc);
1204 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1209 OnLogInitMenu((HMENU) wParam);
1217 OnLogCommand(LOWORD(wParam));
1224 if (g_bCloseHidesWindow)
1226 ShowLogWindow(FALSE);
1231 ShowLogWindow(FALSE);
1237 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1239 OnLogCommand(ID_VIEW_CLEARLOG);
1245 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1249 #endif /* ndef _WIN_CONSOLE - entire file */