1 /*********************************************************************
3 * File : $Source: /cvsroot/ijbswa/current/w32log.c,v $
5 * Purpose : Functions for creating and destroying the log window,
6 * ouputting 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)
319 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
321 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
326 /*********************************************************************
328 * Function : LogDestroyPatternMatchingBuffers
330 * Description : Free up the pattern matching buffers.
336 *********************************************************************/
337 void LogDestroyPatternMatchingBuffers(void)
340 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
342 regfree(&patterns_to_highlight[i].buffer);
347 /*********************************************************************
349 * Function : LogPutString
351 * Description : Inserts text into the logging window. This is really
352 * a regexp aware wrapper function to `LogPutStringNoMatch'.
355 * 1 : pszText = pointer to string going to the log window
357 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
358 * FIXME: this is backwards to the rest of IJB and to common
359 * programming practice. Please use 0 => success instead.
361 *********************************************************************/
362 int LogPutString(const char *pszText)
372 if (pszText == NULL || strlen(pszText) == 0)
377 /* Critical section stops multiple threads doing nasty interactions that
378 * foul up the highlighting and output.
380 EnterCriticalSection(&g_criticalsection);
382 if (g_bHighlightMessages)
386 /* First things first, regexp scan for various things that we would like highlighted */
387 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
389 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
391 char *pszBefore = NULL;
392 char *pszMatch = NULL;
393 char *pszAfter = NULL;
396 /* Split the string up into pieces representing the strings, before
397 at and after the matching pattern
401 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
402 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
403 strncpy(pszBefore, pszText, match.rm_so);
405 if (match.rm_eo < (regoff_t)strlen(pszText))
407 pszAfter = strdup(&pszText[match.rm_eo]);
409 nMatchSize = match.rm_eo - match.rm_so;
410 pszMatch = (char *)malloc(nMatchSize + 1);
411 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
412 pszMatch[nMatchSize] = '\0';
414 /* Recursively call LogPutString */
417 LogPutString(pszBefore);
422 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
427 LogPutString(pszAfter);
437 result = LogPutStringNoMatch(pszText, STYLE_NONE);
440 LeaveCriticalSection(&g_criticalsection);
447 /*********************************************************************
449 * Function : LogPutStringNoMatch
451 * Description : Puts a string into the logging window.
454 * 1 : pszText = pointer to string going to the log window
455 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
457 * Returns : Always 1 => success.
458 * FIXME: this is backwards to the rest of IJB and to common
459 * programming practice. Please use 0 => success instead.
461 *********************************************************************/
462 int LogPutStringNoMatch(const char *pszText, int style)
468 assert(g_hwndLogBox);
469 if (g_hwndLogBox == NULL)
474 /* TODO preserve existing selection */
476 /* Go to the end of the text */
477 nTextLength = GetWindowTextLength(g_hwndLogBox);
478 range.cpMin = nTextLength;
479 range.cpMax = nTextLength;
480 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
482 /* Apply a formatting style */
483 memset(&format, 0, sizeof(format));
484 format.cbSize = sizeof(format);
485 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT |
486 CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET;
487 format.bCharSet = DEFAULT_CHARSET;
488 format.yHeight = (g_nFontSize * 1440) / 72;
489 strlcpy(format.szFaceName, g_szFontFaceName, sizeof(format.szFaceName));
490 if (style == STYLE_NONE)
493 format.dwEffects |= CFE_AUTOCOLOR;
495 else if (style == STYLE_HEADER)
497 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
499 else if (style == STYLE_HIGHLIGHT)
501 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
503 else if (style == STYLE_LINK)
505 format.dwEffects |= CFE_UNDERLINE;
506 format.crTextColor = RGB(0, 0, 255);
508 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
510 /* Append text to the end */
511 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
513 /* TODO Restore the old selection */
516 if (strchr(pszText, '\n') != NULL)
518 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
521 /* Set the force clip timer going. This timer ensures clipping is done
522 intermittently even when there is a sustained burst of logging
524 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
526 g_bClipPending = TRUE;
534 /*********************************************************************
536 * Function : LogShowActivity
538 * Description : Start the spinner.
544 *********************************************************************/
545 void LogShowActivity(void)
547 /* Start some activity timers */
548 if (g_bShowActivityAnimation)
550 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
551 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
557 /*********************************************************************
559 * Function : LogClipBuffer
561 * Description : Prunes old lines from the log.
567 *********************************************************************/
568 void LogClipBuffer(void)
570 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
571 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
573 /* Compute the range representing the lines to be deleted */
574 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
575 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
578 range.cpMax = nLastChar;
580 /* TODO get current selection */
582 /* TODO adjust and clip old selection against range to be deleted */
584 /* Select range and erase it (turning off autoscroll to prevent
586 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
587 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
588 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
589 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
591 /* reposition (back to) the end of the log content */
592 range.cpMin = SendMessage (g_hwndLogBox, WM_GETTEXTLENGTH, 0, 0);
594 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
596 /* restore vertical ScrollBar stuff (messed up by AUTOVSCROLL) */
597 SendMessage (g_hwndLogBox, EM_SCROLL, SB_LINEDOWN, 0);
604 /*********************************************************************
606 * Function : CreateHiddenLogOwnerWindow
608 * Description : Creates a hidden owner window that stops the log
609 * window appearing in the task bar.
612 * 1 : hInstance = application's instance handle
614 * Returns : Handle to newly created window.
616 *********************************************************************/
617 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
619 static const char *szWndName = "PrivoxyLogOwner";
624 wc.lpfnWndProc = LogOwnerWindowProc;
627 wc.hInstance = hInstance;
628 wc.hIcon = g_hiconApp;
630 wc.hbrBackground = 0;
632 wc.lpszClassName = szWndName;
636 hwnd = CreateWindow(szWndName, szWndName,
637 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
638 CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
645 /*********************************************************************
647 * Function : LogOwnerWindowProc
649 * Description : Dummy procedure that does nothing special.
652 * 1 : hwnd = window handle
653 * 2 : uMsg = message number
654 * 3 : wParam = first param for this message
655 * 4 : lParam = next param for this message
657 * Returns : Same as `DefWindowProc'.
659 *********************************************************************/
660 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
662 return DefWindowProc(hwnd, uMsg, wParam, lParam);
667 /*********************************************************************
669 * Function : CreateLogWindow
671 * Description : Create the logging window.
674 * 1 : hInstance = application's instance handle
675 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
677 * Returns : Handle to newly created window.
679 *********************************************************************/
680 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
682 static const char *szWndName = "PrivoxyLogWindow";
683 static const char *szWndTitle = "Privoxy";
686 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
690 memset(&wc, 0, sizeof(wc));
691 wc.cbSize = sizeof(wc);
692 wc.style = CS_DBLCLKS;
693 wc.lpfnWndProc = LogWindowProc;
696 wc.hInstance = hInstance;
697 wc.hIcon = g_hiconApp;
699 wc.hbrBackground = 0;
700 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
701 wc.lpszClassName = szWndName;
702 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
703 RegisterClassEx(&wc);
705 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
706 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
707 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
709 /* Now create a child list box */
710 GetClientRect(hwnd, &rcClient);
712 /* Create a rich edit control */
714 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
715 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
716 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
717 hwnd, NULL, hInstance, NULL);
718 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
720 /* Subclass the control to catch certain messages */
721 g_fnLogBox = (WNDPROC) GetWindowLongPtr(g_hwndLogBox, GWLP_WNDPROC);
722 SetWindowLongPtr(g_hwndLogBox, GWLP_WNDPROC, (LONG_PTR) LogRichEditProc);
724 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
725 if (!g_bShowOnTaskBar &&
726 (nCmdShow == SW_SHOWMINIMIZED ||
727 nCmdShow == SW_MINIMIZE ||
728 nCmdShow == SW_SHOWMINNOACTIVE))
730 g_bShowLogWindow = FALSE;
734 ShowWindow(hwnd, nCmdShow);
738 GetClientRect(g_hwndLogFrame, &rcClient);
739 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
746 /*********************************************************************
748 * Function : InitRichEdit
750 * Description : Initialise the rich edit control library.
754 * Returns : TRUE => success, FALSE => failure.
755 * FIXME: this is backwards to the rest of IJB and to common
756 * programming practice. Please use 0 => success instead.
758 *********************************************************************/
759 BOOL InitRichEdit(void)
761 static HINSTANCE hInstRichEdit;
762 if (hInstRichEdit == NULL)
764 g_nRichEditVersion = 0;
765 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
768 g_nRichEditVersion = _RICHEDIT_VER;
772 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
775 g_nRichEditVersion = 0x0100;
779 return (hInstRichEdit != NULL) ? TRUE : FALSE;
784 /*********************************************************************
786 * Function : ShowLogWindow
788 * Description : Shows or hides the log window. We will also raise the
789 * window on a show command in case it is buried.
792 * 1 : bShow = TRUE to show, FALSE to mimize/hide
796 *********************************************************************/
797 void ShowLogWindow(BOOL bShow)
801 SetForegroundWindow(g_hwndLogFrame);
802 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
805 else if (g_bShowOnTaskBar)
807 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
811 ShowWindow(g_hwndLogFrame, SW_HIDE);
816 /*********************************************************************
818 * Function : EditFile
820 * Description : Opens the specified setting file for editing.
821 * FIXME: What if the file has no associated application. Check for return values
822 * from ShellExecute??
825 * 1 : filename = filename from the config (aka config.txt) file.
829 *********************************************************************/
830 void EditFile(const char *filename)
834 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
840 /*--------------------------------------------------------------------------*/
841 /* Windows message handlers */
842 /*--------------------------------------------------------------------------*/
845 /*********************************************************************
847 * Function : OnLogRButtonUp
849 * Description : Handler for WM_RBUTTONUP messages.
852 * 1 : nModifier = wParam from mouse message (unused)
853 * 2 : x = x coordinate of the mouse event
854 * 3 : y = y coordinate of the mouse event
858 *********************************************************************/
859 void OnLogRButtonUp(int nModifier, int x, int y)
861 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
864 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
866 /* Check if there is a selection */
868 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
869 if (range.cpMin == range.cpMax)
871 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
875 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
878 /* Display the popup */
879 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
886 /*********************************************************************
888 * Function : OnLogCommand
890 * Description : Handler for WM_COMMAND messages.
893 * 1 : nCommand = the command portion of the menu selection event
897 *********************************************************************/
898 void OnLogCommand(int nCommand)
902 case ID_TOGGLE_SHOWWINDOW:
903 g_bShowLogWindow = !g_bShowLogWindow;
905 ShowLogWindow(g_bShowLogWindow);
909 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
913 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
916 case ID_VIEW_CLEARLOG:
917 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
920 case ID_VIEW_LOGMESSAGES:
921 g_bLogMessages = !g_bLogMessages;
922 /* SaveLogSettings(); */
925 case ID_VIEW_MESSAGEHIGHLIGHTING:
926 g_bHighlightMessages = !g_bHighlightMessages;
927 /* SaveLogSettings(); */
930 case ID_VIEW_LIMITBUFFERSIZE:
931 g_bLimitBufferSize = !g_bLimitBufferSize;
932 /* SaveLogSettings(); */
935 case ID_VIEW_ACTIVITYANIMATION:
936 g_bShowActivityAnimation = !g_bShowActivityAnimation;
937 /* SaveLogSettings(); */
940 #ifdef FEATURE_TOGGLE
941 case ID_TOGGLE_ENABLED:
942 global_toggle_state = !global_toggle_state;
943 log_error(LOG_LEVEL_INFO,
944 "Now toggled %s", global_toggle_state ? "ON" : "OFF");
946 * Leverage TIMER_ANIMSTOP_ID to set the idle icon through the
947 * "application queue". According to MSDN, 10 milliseconds are
948 * the lowest value possible and seem to be close enough to
951 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, 10, NULL);
953 #endif /* def FEATURE_TOGGLE */
955 case ID_TOOLS_EDITCONFIG:
956 EditFile(configfile);
959 case ID_TOOLS_EDITDEFAULTACTIONS:
960 EditFile(g_default_actions_file);
963 case ID_TOOLS_EDITUSERACTIONS:
964 EditFile(g_user_actions_file);
967 case ID_TOOLS_EDITDEFAULTFILTERS:
968 EditFile(g_default_filterfile);
971 case ID_TOOLS_EDITUSERFILTERS:
972 EditFile(g_user_filterfile);
976 case ID_TOOLS_EDITTRUST:
977 EditFile(g_trustfile);
979 #endif /* def FEATURE_TRUST */
982 ShellExecute(g_hwndLogFrame, "open", "LICENSE.txt", NULL, NULL, SW_SHOWNORMAL);
986 ShellExecute(g_hwndLogFrame, "open", "doc\\faq\\index.html", NULL, NULL, SW_SHOWNORMAL);
990 ShellExecute(g_hwndLogFrame, "open", "doc\\user-manual\\index.html", NULL, NULL, SW_SHOWNORMAL);
994 ShellExecute(g_hwndLogFrame, "open", CGI_PREFIX "show-status", NULL, NULL, SW_SHOWNORMAL);
998 MessageBox(g_hwndLogFrame, win32_blurb, "About Privoxy", MB_OK);
1009 /*********************************************************************
1011 * Function : OnLogInitMenu
1013 * Description : Handler for WM_INITMENU messages. Enable, disable,
1014 * check, and/or uncheck menu options as apropos.
1017 * 1 : hmenu = handle to menu to "make current"
1021 *********************************************************************/
1022 void OnLogInitMenu(HMENU hmenu)
1024 /* Only enable editors if there is a file to edit */
1025 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTACTIONS, MF_BYCOMMAND | (g_default_actions_file ? MF_ENABLED : MF_GRAYED));
1026 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERACTIONS, MF_BYCOMMAND | (g_user_actions_file ? MF_ENABLED : MF_GRAYED));
1027 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTFILTERS, MF_BYCOMMAND | (g_default_filterfile ? MF_ENABLED : MF_GRAYED));
1028 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERFILTERS, MF_BYCOMMAND | (g_user_filterfile ? MF_ENABLED : MF_GRAYED));
1029 #ifdef FEATURE_TRUST
1030 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1031 #endif /* def FEATURE_TRUST */
1033 /* Check/uncheck options */
1034 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1035 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1036 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1037 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1038 #ifdef FEATURE_TOGGLE
1039 /* by haroon - menu item for Enable toggle on/off */
1040 CheckMenuItem(hmenu, ID_TOGGLE_ENABLED, MF_BYCOMMAND | (global_toggle_state ? MF_CHECKED : MF_UNCHECKED));
1041 #endif /* def FEATURE_TOGGLE */
1042 CheckMenuItem(hmenu, ID_TOGGLE_SHOWWINDOW, MF_BYCOMMAND | (g_bShowLogWindow ? MF_CHECKED : MF_UNCHECKED));
1047 /*********************************************************************
1049 * Function : OnLogTimer
1051 * Description : Handler for WM_TIMER messages.
1054 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1058 *********************************************************************/
1059 void OnLogTimer(int nTimer)
1064 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1067 case TIMER_ANIMSTOP_ID:
1070 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1071 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1074 case TIMER_CLIPBUFFER_ID:
1075 case TIMER_CLIPBUFFER_FORCE_ID:
1077 g_bClipPending = FALSE;
1078 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1079 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1090 /*********************************************************************
1092 * Function : SetIdleIcon
1094 * Description : Sets the tray icon to either idle or off
1100 *********************************************************************/
1103 #ifdef FEATURE_TOGGLE
1104 if (!global_toggle_state)
1106 TraySetIcon(g_hwndTray, 1, g_hiconOff);
1109 #endif /* def FEATURE_TOGGLE */
1110 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1114 /*********************************************************************
1116 * Function : LogRichEditProc
1118 * Description : Window subclass routine handles some events for the rich edit control.
1121 * 1 : hwnd = window handle of the rich edit control
1122 * 2 : uMsg = message number
1123 * 3 : wParam = first param for this message
1124 * 4 : lParam = next param for this message
1126 * Returns : Appropriate M$ window message handler codes.
1128 *********************************************************************/
1129 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1136 pt.x = LOWORD(lParam);
1137 pt.y = HIWORD(lParam);
1138 ClientToScreen(hwnd, &pt);
1139 OnLogRButtonUp(wParam, pt.x, pt.y);
1144 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1146 OnLogCommand(ID_VIEW_CLEARLOG);
1151 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1156 /*********************************************************************
1158 * Function : LogWindowProc
1160 * Description : Windows call back routine handles events on the log window.
1163 * 1 : hwnd = handle of the logging window
1164 * 2 : uMsg = message number
1165 * 3 : wParam = first param for this message
1166 * 4 : lParam = next param for this message
1168 * Returns : Appropriate M$ window message handler codes.
1170 *********************************************************************/
1171 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1179 /* This is the end - my only friend - the end */
1180 DestroyWindow(g_hwndLogBox);
1181 DestroyWindow(g_hwndLogFrame);
1189 g_bShowLogWindow = wParam;
1191 /* Resize the logging window to fit the new frame */
1195 GetClientRect(g_hwndLogFrame, &rc);
1196 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1201 OnLogInitMenu((HMENU) wParam);
1209 OnLogCommand(LOWORD(wParam));
1216 if (g_bCloseHidesWindow)
1218 ShowLogWindow(FALSE);
1223 ShowLogWindow(FALSE);
1229 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1231 OnLogCommand(ID_VIEW_CLEARLOG);
1237 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1241 #endif /* ndef _WIN_CONSOLE - entire file */