1 const char w32log_rcs[] = "$Id: w32log.c,v 1.52 2016/07/28 00:38:47 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 *********************************************************************/
50 #include "w32taskbar.h"
58 const char w32res_h_rcs[] = W32RES_H_VERSION;
60 const char w32log_h_rcs[] = W32LOG_H_VERSION;
62 #ifndef _WIN_CONSOLE /* entire file */
65 * Timers and the various durations
67 #define TIMER_ANIM_ID 1
68 #define TIMER_ANIM_TIME 100
69 #define TIMER_ANIMSTOP_ID 2
70 #define TIMER_ANIMSTOP_TIME 1000
71 #define TIMER_CLIPBUFFER_ID 3
72 #define TIMER_CLIPBUFFER_TIME 1000
73 #define TIMER_CLIPBUFFER_FORCE_ID 4
74 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
77 * Styles of text that can be output
80 #define STYLE_HIGHLIGHT 1
82 #define STYLE_HEADER 3
85 * Number of frames of animation in tray activity sequence
89 #define DEFAULT_MAX_BUFFER_LINES 200
90 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
91 #define DEFAULT_LOG_FONT_SIZE 8
94 * These values affect the way the log window behaves, they should be read
95 * from a file but for the moment, they are hardcoded here. Some options are
96 * configurable through the UI.
99 /* Indicates whether task bar shows activity animation */
100 BOOL g_bShowActivityAnimation = 1;
102 /* Indicates whether the log window is shown */
103 BOOL g_bShowLogWindow = 1;
105 /* Indicates if the log window appears on the task bar */
106 BOOL g_bShowOnTaskBar = 0;
108 /* Indicates whether closing the log window really just hides it */
109 BOOL g_bCloseHidesWindow = 1;
111 /* Indicates if messages are logged at all */
112 BOOL g_bLogMessages = 1;
114 /* Indicates whether log messages are highlighted */
115 BOOL g_bHighlightMessages = 1;
117 /* Indicates if buffer is limited in size */
118 BOOL g_bLimitBufferSize = 1;
120 /* Maximum number of lines allowed in buffer when limited */
121 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
124 char g_szFontFaceName[32] = DEFAULT_LOG_FONT_NAME;
126 /* Size of font to use */
127 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
130 /* FIXME: this is a kludge */
132 const char * g_default_actions_file = NULL;
133 const char * g_user_actions_file = NULL;
134 const char * g_default_filterfile = NULL;
135 const char * g_user_filterfile = NULL;
137 const char * g_trustfile = NULL;
138 #endif /* def FEATURE_TRUST */
140 /* FIXME: end kludge */
142 /* Regular expression for detected URLs */
143 #define RE_URL "http:[^ \n\r]*"
146 * Regular expressions that are used to perform highlight in the log window
148 static struct _Pattern
153 } patterns_to_highlight[] =
156 { RE_URL, STYLE_LINK },
157 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
158 /* interesting text to highlight */
159 /* see jcc.c crunch_reason for the full list */
160 { "Crunch: Blocked:", STYLE_HIGHLIGHT },
161 { "Crunch: Untrusted", STYLE_HIGHLIGHT },
162 { "Crunch: Redirected:", STYLE_HIGHLIGHT },
163 { "Crunch: DNS failure", STYLE_HIGHLIGHT },
164 { "Crunch: Forwarding failed", STYLE_HIGHLIGHT },
165 { "Crunch: Connection failure", STYLE_HIGHLIGHT },
166 { "Crunch: Out of memory", STYLE_HIGHLIGHT },
167 { "Connect: Found reusable socket", STYLE_HIGHLIGHT },
168 { "Connect: Reusing server socket", STYLE_HIGHLIGHT },
169 { "Connect: Created new connection to", STYLE_HIGHLIGHT },
170 { "hung up on us", STYLE_HIGHLIGHT },
171 { "Info: Loading actions file:", STYLE_HIGHLIGHT },
172 { "Info: Loading filter file:", STYLE_HIGHLIGHT },
173 { "Info: Now toggled ", STYLE_HIGHLIGHT },
174 { "Crunching Referer:", STYLE_HIGHLIGHT },
175 /* what are all the possible error strings?? */
176 { "Error:", STYLE_HIGHLIGHT },
178 { "referer:", STYLE_HEADER },
179 { "proxy-connection:", STYLE_HEADER },
180 { "proxy-agent:", STYLE_HEADER },
181 { "user-agent:", STYLE_HEADER },
182 { "host:", STYLE_HEADER },
183 { "accept:", STYLE_HEADER },
184 { "accept-encoding:", STYLE_HEADER },
185 { "accept-language:", STYLE_HEADER },
186 { "accept-charset:", STYLE_HEADER },
187 { "accept-ranges:", STYLE_HEADER },
188 { "date:", STYLE_HEADER },
189 { "cache-control:", STYLE_HEADER },
190 { "cache-last-checked:", STYLE_HEADER },
191 { "connection:", STYLE_HEADER },
192 { "content-type", STYLE_HEADER },
193 { "content-length", STYLE_HEADER },
194 { "cookie", STYLE_HEADER },
195 { "last-modified:", STYLE_HEADER },
196 { "pragma:", STYLE_HEADER },
197 { "server:", STYLE_HEADER },
198 { "etag:", STYLE_HEADER },
199 { "expires:", STYLE_HEADER },
200 { "warning:", STYLE_HEADER },
201 /* this is the terminator statement - do not delete! */
214 static CRITICAL_SECTION g_criticalsection;
215 static HWND g_hwndTray;
216 static HWND g_hwndLogBox;
217 static WNDPROC g_fnLogBox;
218 static HICON g_hiconAnim[ANIM_FRAMES];
219 static HICON g_hiconIdle;
220 static HICON g_hiconOff;
221 static int g_nAnimFrame;
222 static BOOL g_bClipPending = FALSE;
223 static int g_nRichEditVersion = 0;
228 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
229 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
230 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
231 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
232 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
233 static BOOL InitRichEdit(void);
234 static void LogClipBuffer(void);
235 static void LogCreatePatternMatchingBuffers(void);
236 static void LogDestroyPatternMatchingBuffers(void);
237 static int LogPutStringNoMatch(const char *pszText, int style);
238 static void SetIdleIcon(void);
241 /*********************************************************************
243 * Function : InitLogWindow
245 * Description : Initialise the log window.
249 * Returns : Always TRUE (there should be error checking on the resources).
251 *********************************************************************/
252 BOOL InitLogWindow(void)
257 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
258 g_hiconOff = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_OFF));
259 for (i = 0; i < ANIM_FRAMES; i++)
261 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ANIMATED1 + i));
263 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_MAINICON));
265 /* Create the user interface */
266 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
267 g_hwndTray = CreateTrayWindow(g_hInstance);
268 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Privoxy");
270 /* Create pattern matching buffers (for highlighting */
271 LogCreatePatternMatchingBuffers();
273 /* Create a critical section to protect multi-threaded access to certain things */
274 InitializeCriticalSection(&g_criticalsection);
281 /*********************************************************************
283 * Function : TermLogWindow
285 * Description : Cleanup the logwindow.
291 *********************************************************************/
292 void TermLogWindow(void)
296 LogDestroyPatternMatchingBuffers();
298 TrayDeleteIcon(g_hwndTray, 1);
299 DeleteObject(g_hiconApp);
300 DeleteObject(g_hiconIdle);
301 DeleteObject(g_hiconOff);
302 for (i = 0; i < ANIM_FRAMES; i++)
304 DeleteObject(g_hiconAnim[i]);
310 /*********************************************************************
312 * Function : LogCreatePatternMatchingBuffers
314 * Description : Compile the pattern matching buffers.
320 *********************************************************************/
321 void LogCreatePatternMatchingBuffers(void)
324 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
326 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
331 /*********************************************************************
333 * Function : LogDestroyPatternMatchingBuffers
335 * Description : Free up the pattern matching buffers.
341 *********************************************************************/
342 void LogDestroyPatternMatchingBuffers(void)
345 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
347 regfree(&patterns_to_highlight[i].buffer);
352 /*********************************************************************
354 * Function : LogPutString
356 * Description : Inserts text into the logging window. This is really
357 * a regexp aware wrapper function to `LogPutStringNoMatch'.
360 * 1 : pszText = pointer to string going to the log window
362 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
363 * FIXME: this is backwards to the rest of IJB and to common
364 * programming practice. Please use 0 => success instead.
366 *********************************************************************/
367 int LogPutString(const char *pszText)
377 if (pszText == NULL || strlen(pszText) == 0)
382 /* Critical section stops multiple threads doing nasty interactions that
383 * foul up the highlighting and output.
385 EnterCriticalSection(&g_criticalsection);
387 if (g_bHighlightMessages)
391 /* First things first, regexp scan for various things that we would like highlighted */
392 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
394 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
396 char *pszBefore = NULL;
397 char *pszMatch = NULL;
398 char *pszAfter = NULL;
401 /* Split the string up into pieces representing the strings, before
402 at and after the matching pattern
406 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
407 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
408 strncpy(pszBefore, pszText, match.rm_so);
410 if (match.rm_eo < (regoff_t)strlen(pszText))
412 pszAfter = strdup(&pszText[match.rm_eo]);
414 nMatchSize = match.rm_eo - match.rm_so;
415 pszMatch = (char *)malloc(nMatchSize + 1);
416 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
417 pszMatch[nMatchSize] = '\0';
419 /* Recursively call LogPutString */
422 LogPutString(pszBefore);
427 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
432 LogPutString(pszAfter);
442 result = LogPutStringNoMatch(pszText, STYLE_NONE);
445 LeaveCriticalSection(&g_criticalsection);
452 /*********************************************************************
454 * Function : LogPutStringNoMatch
456 * Description : Puts a string into the logging window.
459 * 1 : pszText = pointer to string going to the log window
460 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
462 * Returns : Always 1 => success.
463 * FIXME: this is backwards to the rest of IJB and to common
464 * programming practice. Please use 0 => success instead.
466 *********************************************************************/
467 int LogPutStringNoMatch(const char *pszText, int style)
473 assert(g_hwndLogBox);
474 if (g_hwndLogBox == NULL)
479 /* TODO preserve existing selection */
481 /* Go to the end of the text */
482 nTextLength = GetWindowTextLength(g_hwndLogBox);
483 range.cpMin = nTextLength;
484 range.cpMax = nTextLength;
485 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
487 /* Apply a formatting style */
488 memset(&format, 0, sizeof(format));
489 format.cbSize = sizeof(format);
490 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT |
491 CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET;
492 format.bCharSet = DEFAULT_CHARSET;
493 format.yHeight = (g_nFontSize * 1440) / 72;
494 strlcpy(format.szFaceName, g_szFontFaceName, sizeof(format.szFaceName));
495 if (style == STYLE_NONE)
498 format.dwEffects |= CFE_AUTOCOLOR;
500 else if (style == STYLE_HEADER)
502 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
504 else if (style == STYLE_HIGHLIGHT)
506 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
508 else if (style == STYLE_LINK)
510 format.dwEffects |= CFE_UNDERLINE;
511 format.crTextColor = RGB(0, 0, 255);
513 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
515 /* Append text to the end */
516 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
518 /* TODO Restore the old selection */
521 if (strchr(pszText, '\n') != NULL)
523 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
526 /* Set the force clip timer going. This timer ensures clipping is done
527 intermittently even when there is a sustained burst of logging
529 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
531 g_bClipPending = TRUE;
539 /*********************************************************************
541 * Function : LogShowActivity
543 * Description : Start the spinner.
549 *********************************************************************/
550 void LogShowActivity(void)
552 /* Start some activity timers */
553 if (g_bShowActivityAnimation)
555 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
556 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
562 /*********************************************************************
564 * Function : LogClipBuffer
566 * Description : Prunes old lines from the log.
572 *********************************************************************/
573 void LogClipBuffer(void)
575 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
576 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
578 /* Compute the range representing the lines to be deleted */
579 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
580 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
583 range.cpMax = nLastChar;
585 /* TODO get current selection */
587 /* TODO adjust and clip old selection against range to be deleted */
589 /* Select range and erase it (turning off autoscroll to prevent
591 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
592 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
593 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
594 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
596 /* reposition (back to) the end of the log content */
597 range.cpMin = SendMessage (g_hwndLogBox, WM_GETTEXTLENGTH, 0, 0);
599 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
601 /* restore vertical ScrollBar stuff (messed up by AUTOVSCROLL) */
602 SendMessage (g_hwndLogBox, EM_SCROLL, SB_LINEDOWN, 0);
609 /*********************************************************************
611 * Function : CreateHiddenLogOwnerWindow
613 * Description : Creates a hidden owner window that stops the log
614 * window appearing in the task bar.
617 * 1 : hInstance = application's instance handle
619 * Returns : Handle to newly created window.
621 *********************************************************************/
622 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
624 static const char *szWndName = "PrivoxyLogOwner";
629 wc.lpfnWndProc = LogOwnerWindowProc;
632 wc.hInstance = hInstance;
633 wc.hIcon = g_hiconApp;
635 wc.hbrBackground = 0;
637 wc.lpszClassName = szWndName;
641 hwnd = CreateWindow(szWndName, szWndName,
642 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
643 CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
650 /*********************************************************************
652 * Function : LogOwnerWindowProc
654 * Description : Dummy procedure that does nothing special.
657 * 1 : hwnd = window handle
658 * 2 : uMsg = message number
659 * 3 : wParam = first param for this message
660 * 4 : lParam = next param for this message
662 * Returns : Same as `DefWindowProc'.
664 *********************************************************************/
665 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
667 return DefWindowProc(hwnd, uMsg, wParam, lParam);
672 /*********************************************************************
674 * Function : CreateLogWindow
676 * Description : Create the logging window.
679 * 1 : hInstance = application's instance handle
680 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
682 * Returns : Handle to newly created window.
684 *********************************************************************/
685 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
687 static const char *szWndName = "PrivoxyLogWindow";
688 static const char *szWndTitle = "Privoxy";
691 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
695 memset(&wc, 0, sizeof(wc));
696 wc.cbSize = sizeof(wc);
697 wc.style = CS_DBLCLKS;
698 wc.lpfnWndProc = LogWindowProc;
701 wc.hInstance = hInstance;
702 wc.hIcon = g_hiconApp;
704 wc.hbrBackground = 0;
705 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
706 wc.lpszClassName = szWndName;
707 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
708 RegisterClassEx(&wc);
710 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
711 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
712 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
714 /* Now create a child list box */
715 GetClientRect(hwnd, &rcClient);
717 /* Create a rich edit control */
719 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
720 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
721 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
722 hwnd, NULL, hInstance, NULL);
723 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
725 /* Subclass the control to catch certain messages */
726 g_fnLogBox = (WNDPROC) GetWindowLongPtr(g_hwndLogBox, GWLP_WNDPROC);
727 SetWindowLongPtr(g_hwndLogBox, GWLP_WNDPROC, (LONG_PTR) LogRichEditProc);
729 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
730 if (!g_bShowOnTaskBar &&
731 (nCmdShow == SW_SHOWMINIMIZED ||
732 nCmdShow == SW_MINIMIZE ||
733 nCmdShow == SW_SHOWMINNOACTIVE))
735 g_bShowLogWindow = FALSE;
739 ShowWindow(hwnd, nCmdShow);
743 GetClientRect(g_hwndLogFrame, &rcClient);
744 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
751 /*********************************************************************
753 * Function : InitRichEdit
755 * Description : Initialise the rich edit control library.
759 * Returns : TRUE => success, FALSE => failure.
760 * FIXME: this is backwards to the rest of IJB and to common
761 * programming practice. Please use 0 => success instead.
763 *********************************************************************/
764 BOOL InitRichEdit(void)
766 static HINSTANCE hInstRichEdit;
767 if (hInstRichEdit == NULL)
769 g_nRichEditVersion = 0;
770 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
773 g_nRichEditVersion = _RICHEDIT_VER;
777 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
780 g_nRichEditVersion = 0x0100;
784 return (hInstRichEdit != NULL) ? TRUE : FALSE;
789 /*********************************************************************
791 * Function : ShowLogWindow
793 * Description : Shows or hides the log window. We will also raise the
794 * window on a show command in case it is buried.
797 * 1 : bShow = TRUE to show, FALSE to mimize/hide
801 *********************************************************************/
802 void ShowLogWindow(BOOL bShow)
806 SetForegroundWindow(g_hwndLogFrame);
807 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
810 else if (g_bShowOnTaskBar)
812 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
816 ShowWindow(g_hwndLogFrame, SW_HIDE);
821 /*********************************************************************
823 * Function : EditFile
825 * Description : Opens the specified setting file for editing.
826 * FIXME: What if the file has no associated application. Check for return values
827 * from ShellExecute??
830 * 1 : filename = filename from the config (aka config.txt) file.
834 *********************************************************************/
835 void EditFile(const char *filename)
839 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
845 /*--------------------------------------------------------------------------*/
846 /* Windows message handlers */
847 /*--------------------------------------------------------------------------*/
850 /*********************************************************************
852 * Function : OnLogRButtonUp
854 * Description : Handler for WM_RBUTTONUP messages.
857 * 1 : nModifier = wParam from mouse message (unused)
858 * 2 : x = x coordinate of the mouse event
859 * 3 : y = y coordinate of the mouse event
863 *********************************************************************/
864 void OnLogRButtonUp(int nModifier, int x, int y)
866 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
869 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
871 /* Check if there is a selection */
873 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
874 if (range.cpMin == range.cpMax)
876 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
880 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
883 /* Display the popup */
884 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
891 /*********************************************************************
893 * Function : OnLogCommand
895 * Description : Handler for WM_COMMAND messages.
898 * 1 : nCommand = the command portion of the menu selection event
902 *********************************************************************/
903 void OnLogCommand(int nCommand)
907 case ID_TOGGLE_SHOWWINDOW:
908 g_bShowLogWindow = !g_bShowLogWindow;
910 ShowLogWindow(g_bShowLogWindow);
914 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
918 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
921 case ID_VIEW_CLEARLOG:
922 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
925 case ID_VIEW_LOGMESSAGES:
926 g_bLogMessages = !g_bLogMessages;
927 /* SaveLogSettings(); */
930 case ID_VIEW_MESSAGEHIGHLIGHTING:
931 g_bHighlightMessages = !g_bHighlightMessages;
932 /* SaveLogSettings(); */
935 case ID_VIEW_LIMITBUFFERSIZE:
936 g_bLimitBufferSize = !g_bLimitBufferSize;
937 /* SaveLogSettings(); */
940 case ID_VIEW_ACTIVITYANIMATION:
941 g_bShowActivityAnimation = !g_bShowActivityAnimation;
942 /* SaveLogSettings(); */
945 #ifdef FEATURE_TOGGLE
946 case ID_TOGGLE_ENABLED:
947 global_toggle_state = !global_toggle_state;
948 log_error(LOG_LEVEL_INFO,
949 "Now toggled %s", global_toggle_state ? "ON" : "OFF");
951 * Leverage TIMER_ANIMSTOP_ID to set the idle icon through the
952 * "application queue". According to MSDN, 10 milliseconds are
953 * the lowest value possible and seem to be close enough to
956 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, 10, NULL);
958 #endif /* def FEATURE_TOGGLE */
960 case ID_TOOLS_EDITCONFIG:
961 EditFile(configfile);
964 case ID_TOOLS_EDITDEFAULTACTIONS:
965 EditFile(g_default_actions_file);
968 case ID_TOOLS_EDITUSERACTIONS:
969 EditFile(g_user_actions_file);
972 case ID_TOOLS_EDITDEFAULTFILTERS:
973 EditFile(g_default_filterfile);
976 case ID_TOOLS_EDITUSERFILTERS:
977 EditFile(g_user_filterfile);
981 case ID_TOOLS_EDITTRUST:
982 EditFile(g_trustfile);
984 #endif /* def FEATURE_TRUST */
987 ShellExecute(g_hwndLogFrame, "open", "LICENSE.txt", NULL, NULL, SW_SHOWNORMAL);
991 ShellExecute(g_hwndLogFrame, "open", "doc\\faq\\index.html", NULL, NULL, SW_SHOWNORMAL);
995 ShellExecute(g_hwndLogFrame, "open", "doc\\user-manual\\index.html", NULL, NULL, SW_SHOWNORMAL);
999 ShellExecute(g_hwndLogFrame, "open", CGI_PREFIX "show-status", NULL, NULL, SW_SHOWNORMAL);
1003 MessageBox(g_hwndLogFrame, win32_blurb, "About Privoxy", MB_OK);
1014 /*********************************************************************
1016 * Function : OnLogInitMenu
1018 * Description : Handler for WM_INITMENU messages. Enable, disable,
1019 * check, and/or uncheck menu options as apropos.
1022 * 1 : hmenu = handle to menu to "make current"
1026 *********************************************************************/
1027 void OnLogInitMenu(HMENU hmenu)
1029 /* Only enable editors if there is a file to edit */
1030 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTACTIONS, MF_BYCOMMAND | (g_default_actions_file ? MF_ENABLED : MF_GRAYED));
1031 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERACTIONS, MF_BYCOMMAND | (g_user_actions_file ? MF_ENABLED : MF_GRAYED));
1032 EnableMenuItem(hmenu, ID_TOOLS_EDITDEFAULTFILTERS, MF_BYCOMMAND | (g_default_filterfile ? MF_ENABLED : MF_GRAYED));
1033 EnableMenuItem(hmenu, ID_TOOLS_EDITUSERFILTERS, MF_BYCOMMAND | (g_user_filterfile ? MF_ENABLED : MF_GRAYED));
1034 #ifdef FEATURE_TRUST
1035 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1036 #endif /* def FEATURE_TRUST */
1038 /* Check/uncheck options */
1039 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1040 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1041 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1042 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1043 #ifdef FEATURE_TOGGLE
1044 /* by haroon - menu item for Enable toggle on/off */
1045 CheckMenuItem(hmenu, ID_TOGGLE_ENABLED, MF_BYCOMMAND | (global_toggle_state ? MF_CHECKED : MF_UNCHECKED));
1046 #endif /* def FEATURE_TOGGLE */
1047 CheckMenuItem(hmenu, ID_TOGGLE_SHOWWINDOW, MF_BYCOMMAND | (g_bShowLogWindow ? MF_CHECKED : MF_UNCHECKED));
1052 /*********************************************************************
1054 * Function : OnLogTimer
1056 * Description : Handler for WM_TIMER messages.
1059 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1063 *********************************************************************/
1064 void OnLogTimer(int nTimer)
1069 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1072 case TIMER_ANIMSTOP_ID:
1075 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1076 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1079 case TIMER_CLIPBUFFER_ID:
1080 case TIMER_CLIPBUFFER_FORCE_ID:
1082 g_bClipPending = FALSE;
1083 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1084 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1095 /*********************************************************************
1097 * Function : SetIdleIcon
1099 * Description : Sets the tray icon to either idle or off
1105 *********************************************************************/
1108 #ifdef FEATURE_TOGGLE
1109 if (!global_toggle_state)
1111 TraySetIcon(g_hwndTray, 1, g_hiconOff);
1114 #endif /* def FEATURE_TOGGLE */
1115 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1119 /*********************************************************************
1121 * Function : LogRichEditProc
1123 * Description : Window subclass routine handles some events for the rich edit control.
1126 * 1 : hwnd = window handle of the rich edit control
1127 * 2 : uMsg = message number
1128 * 3 : wParam = first param for this message
1129 * 4 : lParam = next param for this message
1131 * Returns : Appropriate M$ window message handler codes.
1133 *********************************************************************/
1134 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1141 pt.x = LOWORD(lParam);
1142 pt.y = HIWORD(lParam);
1143 ClientToScreen(hwnd, &pt);
1144 OnLogRButtonUp(wParam, pt.x, pt.y);
1149 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1151 OnLogCommand(ID_VIEW_CLEARLOG);
1156 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1161 /*********************************************************************
1163 * Function : LogWindowProc
1165 * Description : Windows call back routine handles events on the log window.
1168 * 1 : hwnd = handle of the logging window
1169 * 2 : uMsg = message number
1170 * 3 : wParam = first param for this message
1171 * 4 : lParam = next param for this message
1173 * Returns : Appropriate M$ window message handler codes.
1175 *********************************************************************/
1176 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1184 /* This is the end - my only friend - the end */
1185 DestroyWindow(g_hwndLogBox);
1186 DestroyWindow(g_hwndLogFrame);
1194 g_bShowLogWindow = wParam;
1196 /* Resize the logging window to fit the new frame */
1200 GetClientRect(g_hwndLogFrame, &rc);
1201 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1206 OnLogInitMenu((HMENU) wParam);
1214 OnLogCommand(LOWORD(wParam));
1221 if (g_bCloseHidesWindow)
1223 ShowLogWindow(FALSE);
1228 ShowLogWindow(FALSE);
1234 if ((GetKeyState(VK_CONTROL) != 0) && (wParam == 4)) /* ctrl+d */
1236 OnLogCommand(ID_VIEW_CLEARLOG);
1242 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1246 #endif /* ndef _WIN_CONSOLE - entire file */