1 const char w32log_rcs[] = "$Id: w32log.c,v 1.5 2001/05/26 00:28:36 jongfoster 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 the SourceForge
10 * IJBSWA team. http://ijbswa.sourceforge.net
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.
35 * Revision 1.5 2001/05/26 00:28:36 jongfoster
36 * Automatic reloading of config file.
37 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
38 * Most of the global variables have been moved to a new
39 * struct configuration_spec, accessed through csp->config->globalname
40 * Most of the globals remaining are used by the Win32 GUI.
42 * Revision 1.4 2001/05/22 18:56:28 oes
45 * Revision 1.3 2001/05/20 15:07:54 jongfoster
46 * File is now ignored if _WIN_CONSOLE is defined.
48 * Revision 1.2 2001/05/20 01:21:20 jongfoster
49 * Version 2.9.4 checkin.
50 * - Merged popupfile and cookiefile, and added control over PCRS
51 * filtering, in new "permissionsfile".
52 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
53 * file error you now get a message box (in the Win32 GUI) rather
54 * than the program exiting with no explanation.
55 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
57 * - Removed tabs from "config"
58 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
59 * - Bumped up version number.
61 * Revision 1.1.1.1 2001/05/15 13:59:07 oes
62 * Initial import of version 2.9.3 source tree
65 *********************************************************************/
78 #include "w32taskbar.h"
79 #include "w32rulesdlg.h"
86 const char w32res_h_rcs[] = W32RES_H_VERSION;
90 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
93 const char w32log_h_rcs[] = W32LOG_H_VERSION;
95 #ifndef _WIN_CONSOLE /* entire file */
98 * Timers and the various durations
100 #define TIMER_ANIM_ID 1
101 #define TIMER_ANIM_TIME 100
102 #define TIMER_ANIMSTOP_ID 2
103 #define TIMER_ANIMSTOP_TIME 1000
104 #define TIMER_CLIPBUFFER_ID 3
105 #define TIMER_CLIPBUFFER_TIME 1000
106 #define TIMER_CLIPBUFFER_FORCE_ID 4
107 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
110 * Styles of text that can be output
113 #define STYLE_HIGHLIGHT 1
115 #define STYLE_HEADER 3
118 * Number of frames of animation in tray activity sequence
120 #define ANIM_FRAMES 8
122 #define DEFAULT_MAX_BUFFER_LINES 200
123 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
124 #define DEFAULT_LOG_FONT_SIZE 8
127 * These values affect the way the log window behaves, they should be read
128 * from a file but for the moment, they are hardcoded here. Some options are
129 * configurable through the UI.
132 /* Indicates whether task bar shows activity animation */
133 BOOL g_bShowActivityAnimation = 1;
135 /* Indicates if the log window appears on the task bar */
136 BOOL g_bShowOnTaskBar = 0;
138 /* Indicates whether closing the log window really just hides it */
139 BOOL g_bCloseHidesWindow = 1;
141 /* Indicates if messages are logged at all */
142 BOOL g_bLogMessages = 1;
144 /* Indicates whether log messages are highlighted */
145 BOOL g_bHighlightMessages = 1;
147 /* Indicates if buffer is limited in size */
148 BOOL g_bLimitBufferSize = 1;
150 /* Maximum number of lines allowed in buffer when limited */
151 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
154 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
156 /* Size of font to use */
157 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
160 /* FIXME: this is a kludge */
162 const char * g_blockfile = NULL;
163 const char * g_permissions_file = NULL;
164 const char * g_forwardfile = NULL;
166 const char * g_aclfile = NULL;
167 #endif /* def ACL_FILES */
168 #ifdef USE_IMAGE_LIST
169 const char * g_imagefile = NULL;
170 #endif /* def USE_IMAGE_LIST */
172 const char * g_re_filterfile = NULL;
175 const char * g_trustfile = NULL;
176 #endif /* def TRUST_FILES */
178 /* FIXME: end kludge */
182 /* Regular expression for detected URLs */
183 #define RE_URL "http:[^ \n\r]*"
186 * Regular expressions that are used to perform highlight in the log window
188 static struct _Pattern
193 } patterns_to_highlight[] =
196 { RE_URL, STYLE_LINK },
197 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
198 /* interesting text to highlight */
199 { "crunch!", STYLE_HIGHLIGHT },
201 { "referer:", STYLE_HEADER },
202 { "proxy-connection:", STYLE_HEADER },
203 { "proxy-agent:", STYLE_HEADER },
204 { "user-agent:", STYLE_HEADER },
205 { "host:", STYLE_HEADER },
206 { "accept:", STYLE_HEADER },
207 { "accept-encoding:", STYLE_HEADER },
208 { "accept-language:", STYLE_HEADER },
209 { "accept-charset:", STYLE_HEADER },
210 { "accept-ranges:", STYLE_HEADER },
211 { "date:", STYLE_HEADER },
212 { "cache-control:", STYLE_HEADER },
213 { "cache-last-checked:", STYLE_HEADER },
214 { "connection:", STYLE_HEADER },
215 { "content-type", STYLE_HEADER },
216 { "content-length", STYLE_HEADER },
217 { "cookie", STYLE_HEADER },
218 { "last-modified:", STYLE_HEADER },
219 { "pragma:", STYLE_HEADER },
220 { "server:", STYLE_HEADER },
221 { "etag:", STYLE_HEADER },
222 { "expires:", STYLE_HEADER },
223 { "warning:", STYLE_HEADER },
224 /* this is the terminator statement - do not delete! */
227 #endif /* def REGEX */
238 static CRITICAL_SECTION g_criticalsection;
239 static HWND g_hwndTray;
240 static HWND g_hwndLogBox;
241 static WNDPROC g_fnLogBox;
242 static HICON g_hiconAnim[ANIM_FRAMES];
243 static HICON g_hiconIdle;
244 static HICON g_hiconApp;
245 static int g_nAnimFrame;
246 static BOOL g_bClipPending = FALSE;
247 static int g_nRichEditVersion = 0;
252 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
253 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
254 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
255 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
256 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
257 static BOOL InitRichEdit(void);
258 static void LogClipBuffer(void);
259 static void LogCreatePatternMatchingBuffers(void);
260 static void LogDestroyPatternMatchingBuffers(void);
261 static int LogPutStringNoMatch(const char *pszText, int style);
264 /*********************************************************************
266 * Function : InitLogWindow
268 * Description : Initialise the log window.
272 * Returns : Always TRUE (there should be error checking on the resources).
274 *********************************************************************/
275 BOOL InitLogWindow(void)
280 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
281 for (i = 0; i < ANIM_FRAMES; i++)
283 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER1 + i));
285 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER));
287 /* Create the user interface */
288 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
289 g_hwndTray = CreateTrayWindow(g_hInstance);
290 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Junkbuster");
292 /* Create pattern matching buffers (for highlighting */
293 LogCreatePatternMatchingBuffers();
295 /* Create a critical section to protect multi-threaded access to certain things */
296 InitializeCriticalSection(&g_criticalsection);
303 /*********************************************************************
305 * Function : TermLogWindow
307 * Description : Cleanup the logwindow.
313 *********************************************************************/
314 void TermLogWindow(void)
318 LogDestroyPatternMatchingBuffers();
320 TrayDeleteIcon(g_hwndTray, 1);
321 DeleteObject(g_hiconApp);
322 DeleteObject(g_hiconIdle);
323 for (i = 0; i < ANIM_FRAMES; i++)
325 DeleteObject(g_hiconAnim[i]);
331 /*********************************************************************
333 * Function : LogCreatePatternMatchingBuffers
335 * Description : Compile the pattern matching buffers.
341 *********************************************************************/
342 void LogCreatePatternMatchingBuffers(void)
346 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
348 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
355 /*********************************************************************
357 * Function : LogDestroyPatternMatchingBuffers
359 * Description : Free up the pattern matching buffers.
365 *********************************************************************/
366 void LogDestroyPatternMatchingBuffers(void)
370 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
372 regfree(&patterns_to_highlight[i].buffer);
379 /*********************************************************************
381 * Function : LogGetURLUnderCursor
383 * Description : Returns the URL from under the cursor (remember to free it!).
387 * Returns : NULL or a pointer to an URL string.
389 *********************************************************************/
390 char *LogGetURLUnderCursor(void)
392 char *szResult = NULL;
398 DWORD nWordStart = 0;
401 regcomp(&re, RE_URL, REG_ICASE);
403 /* Get the position of the cursor over the text window */
404 GetCursorPos(&ptCursor);
405 ScreenToClient(g_hwndLogBox, &ptCursor);
409 /* Search backwards and fowards to obtain the word that is highlighted */
410 nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
411 nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
412 nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
414 /* Compare the string to the pattern */
415 if (nWordEnd > nWordStart)
420 range.chrg.cpMin = nWordStart;
421 range.chrg.cpMax = nWordEnd;
422 range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
423 SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
425 if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
427 szResult = range.lpstrText;
431 free(range.lpstrText);
442 /*********************************************************************
444 * Function : LogPutString
446 * Description : Inserts text into the logging window. This is really
447 * a REGEXP aware wrapper function to `LogPutStringNoMatch'.
450 * 1 : pszText = pointer to string going to the log window
452 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
453 * FIXME: this is backwards to the rest of IJB and to common
454 * programming practice. Please use 0 => success instead.
456 *********************************************************************/
457 int LogPutString(const char *pszText)
464 if (pszText == NULL || strlen(pszText) == 0)
474 /* Critical section stops multiple threads doing nasty interactions that
475 * foul up the highlighting and output.
477 EnterCriticalSection(&g_criticalsection);
480 if (g_bHighlightMessages)
484 /* First things first, regexp scan for various things that we would like highlighted */
485 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
487 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
489 char *pszBefore = NULL;
490 char *pszMatch = NULL;
491 char *pszAfter = NULL;
494 /* Split the string up into pieces representing the strings, before
495 at and after the matching pattern
499 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
500 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
501 strncpy(pszBefore, pszText, match.rm_so);
503 if (match.rm_eo < (regoff_t)strlen(pszText))
505 pszAfter = strdup(&pszText[match.rm_eo]);
507 nMatchSize = match.rm_eo - match.rm_so;
508 pszMatch = (char *)malloc(nMatchSize + 1);
509 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
510 pszMatch[nMatchSize] = '\0';
512 /* Recursively call LogPutString */
515 LogPutString(pszBefore);
520 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
525 LogPutString(pszAfter);
536 result = LogPutStringNoMatch(pszText, STYLE_NONE);
541 LeaveCriticalSection(&g_criticalsection);
548 /*********************************************************************
550 * Function : LogPutStringNoMatch
552 * Description : Puts a string into the logging window.
555 * 1 : pszText = pointer to string going to the log window
556 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
558 * Returns : Always 1 => success.
559 * FIXME: this is backwards to the rest of IJB and to common
560 * programming practice. Please use 0 => success instead.
562 *********************************************************************/
563 int LogPutStringNoMatch(const char *pszText, int style)
569 assert(g_hwndLogBox);
570 if (g_hwndLogBox == NULL)
575 /* TODO preserve existing selection */
577 /* Go to the end of the text */
578 nTextLength = GetWindowTextLength(g_hwndLogBox);
579 range.cpMin = nTextLength;
580 range.cpMax = nTextLength;
581 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
583 /* Apply a formatting style */
584 memset(&format, 0, sizeof(format));
585 format.cbSize = sizeof(format);
586 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
587 format.yHeight = (g_nFontSize * 1440) / 72;
588 strcpy(format.szFaceName, g_szFontFaceName);
589 if (style == STYLE_NONE)
592 format.dwEffects |= CFE_AUTOCOLOR;
594 else if (style == STYLE_HEADER)
596 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
598 else if (style == STYLE_HIGHLIGHT)
600 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
602 else if (style == STYLE_LINK)
604 format.dwEffects |= CFE_UNDERLINE;
605 format.crTextColor = RGB(0, 0, 255);
607 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
609 /* Append text to the end */
610 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
612 /* TODO Restore the old selection */
615 if (strchr(pszText, '\n') != NULL)
617 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
620 /* Set the force clip timer going. This timer ensures clipping is done
621 intermittently even when there is a sustained burst of logging
623 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
625 g_bClipPending = TRUE;
633 /*********************************************************************
635 * Function : LogShowActivity
637 * Description : Start the spinner.
643 *********************************************************************/
644 void LogShowActivity(void)
646 /* Start some activity timers */
647 if (g_bShowActivityAnimation)
649 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
650 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
656 /*********************************************************************
658 * Function : LogClipBuffer
660 * Description : Prunes old lines from the log.
666 *********************************************************************/
667 void LogClipBuffer(void)
669 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
670 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
672 /* Compute the range representing the lines to be deleted */
673 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
674 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
677 range.cpMax = nLastChar;
679 /* TODO get current selection */
681 /* TODO adjust and clip old selection against range to be deleted */
683 /* Select range and erase it (turning off autoscroll to prevent
685 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
686 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
687 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
688 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
690 /* Restore old selection */
696 /*********************************************************************
698 * Function : CreateHiddenLogOwnerWindow
700 * Description : Creates a hidden owner window that stops the log
701 * window appearing in the task bar.
704 * 1 : hInstance = application's instance handle
706 * Returns : Handle to newly created window.
708 *********************************************************************/
709 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
711 static const char *szWndName = "JunkbusterLogLogOwner";
716 wc.lpfnWndProc = LogOwnerWindowProc;
719 wc.hInstance = hInstance;
722 wc.hbrBackground = 0;
724 wc.lpszClassName = szWndName;
728 hwnd = CreateWindow(szWndName, szWndName,
729 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
730 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
737 /*********************************************************************
739 * Function : LogOwnerWindowProc
741 * Description : Dummy procedure that does nothing special.
744 * 1 : hwnd = window handle
745 * 2 : uMsg = message number
746 * 3 : wParam = first param for this message
747 * 4 : lParam = next param for this message
749 * Returns : Same as `DefWindowProc'.
751 *********************************************************************/
752 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
754 return DefWindowProc(hwnd, uMsg, wParam, lParam);
759 /*********************************************************************
761 * Function : CreateLogWindow
763 * Description : Create the logging window.
766 * 1 : hInstance = application's instance handle
767 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
769 * Returns : Handle to newly created window.
771 *********************************************************************/
772 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
774 static const char *szWndName = "JunkbusterLogWindow";
775 static const char *szWndTitle = "Junkbuster";
778 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
779 HWND hwndChild = NULL;
783 memset(&wc, 0, sizeof(wc));
784 wc.cbSize = sizeof(wc);
785 wc.style = CS_DBLCLKS;
786 wc.lpfnWndProc = LogWindowProc;
789 wc.hInstance = hInstance;
790 wc.hIcon = g_hiconApp;
792 wc.hbrBackground = 0;
793 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
794 wc.lpszClassName = szWndName;
795 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
796 RegisterClassEx(&wc);
798 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
799 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
800 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
802 /* Now create a child list box */
803 GetClientRect(hwnd, &rcClient);
805 /* Create a rich edit control */
807 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
808 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
809 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
810 hwnd, NULL, hInstance, NULL);
811 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
813 /* Subclass the control to catch certain messages */
814 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
815 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
817 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
818 if (!g_bShowOnTaskBar &&
819 (nCmdShow == SW_SHOWMINIMIZED ||
820 nCmdShow == SW_MINIMIZE ||
821 nCmdShow == SW_SHOWMINNOACTIVE))
826 ShowWindow(hwnd, nCmdShow);
829 GetClientRect(g_hwndLogFrame, &rcClient);
830 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
837 /*********************************************************************
839 * Function : InitRichEdit
841 * Description : Initialise the rich edit control library.
845 * Returns : TRUE => success, FALSE => failure.
846 * FIXME: this is backwards to the rest of IJB and to common
847 * programming practice. Please use 0 => success instead.
849 *********************************************************************/
850 BOOL InitRichEdit(void)
852 static HINSTANCE hInstRichEdit;
853 if (hInstRichEdit == NULL)
855 g_nRichEditVersion = 0;
856 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
859 g_nRichEditVersion = _RICHEDIT_VER;
863 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
866 g_nRichEditVersion = 0x0100;
870 return (hInstRichEdit != NULL) ? TRUE : FALSE;
875 /*********************************************************************
877 * Function : ShowLogWindow
879 * Description : Shows or hides the log window. We will also raise the
880 * window on a show command in case it is buried.
883 * 1 : bShow = TRUE to show, FALSE to mimize/hide
887 *********************************************************************/
888 void ShowLogWindow(BOOL bShow)
892 SetForegroundWindow(g_hwndLogFrame);
893 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
895 else if (g_bShowOnTaskBar)
897 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
901 ShowWindow(g_hwndLogFrame, SW_HIDE);
907 /*********************************************************************
909 * Function : EditFile
911 * Description : Opens the specified setting file for editing.
914 * 1 : filename = filename from the config (aka junkbstr.txt) file.
918 *********************************************************************/
919 void EditFile(const char *filename)
923 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
929 /*--------------------------------------------------------------------------*/
930 /* Windows message handlers */
931 /*--------------------------------------------------------------------------*/
934 /*********************************************************************
936 * Function : OnLogRButtonUp
938 * Description : Handler for WM_RBUTTONUP messages.
941 * 1 : nModifier = wParam from mouse message (unused)
942 * 2 : x = x coordinate of the mouse event
943 * 3 : y = y coordinate of the mouse event
947 *********************************************************************/
948 void OnLogRButtonUp(int nModifier, int x, int y)
950 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
953 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
956 /* Check if there is a selection */
958 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
959 if (range.cpMin == range.cpMax)
961 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
965 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
968 /* Check if cursor is over a link */
969 szURL = LogGetURLUnderCursor();
973 TCHAR szMenuItemTemplate[1000];
976 memset(&item, 0, sizeof(item));
977 item.cbSize = sizeof(item);
978 item.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
979 item.fType = MFT_STRING;
980 item.fState = MFS_ENABLED;
981 item.wID = ID_NEW_BLOCKER;
983 /* Put the item into the menu */
984 memset(szMenuItemTemplate, 0, sizeof(szMenuItemTemplate));
985 LoadString(g_hInstance, IDS_NEW_BLOCKER, szMenuItemTemplate, sizeof(szMenuItemTemplate) / sizeof(szMenuItemTemplate[0]));
987 szMenuItem = (char *)malloc(strlen(szMenuItemTemplate) + strlen(szURL) + 1);
988 sprintf(szMenuItem, szMenuItemTemplate, szURL);
990 item.dwTypeData = szMenuItem;
991 item.cch = strlen(szMenuItem);
993 InsertMenuItem(hMenuPopup, 1, TRUE, &item);
995 SetDefaultRule(szURL);
1000 /* Display the popup */
1001 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
1008 /*********************************************************************
1010 * Function : OnLogCommand
1012 * Description : Handler for WM_COMMAND messages.
1015 * 1 : nCommand = the command portion of the menu selection event
1019 *********************************************************************/
1020 void OnLogCommand(int nCommand)
1025 ShowLogWindow(TRUE);
1029 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1033 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1036 case ID_VIEW_CLEARLOG:
1037 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1040 case ID_VIEW_LOGMESSAGES:
1041 g_bLogMessages = !g_bLogMessages;
1042 /* SaveLogSettings(); */
1045 case ID_VIEW_MESSAGEHIGHLIGHTING:
1046 g_bHighlightMessages = !g_bHighlightMessages;
1047 /* SaveLogSettings(); */
1050 case ID_VIEW_LIMITBUFFERSIZE:
1051 g_bLimitBufferSize = !g_bLimitBufferSize;
1052 /* SaveLogSettings(); */
1055 case ID_VIEW_ACTIVITYANIMATION:
1056 g_bShowActivityAnimation = !g_bShowActivityAnimation;
1057 /* SaveLogSettings(); */
1061 /* by haroon - change toggle to its opposite value */
1063 g_bToggleIJB = !g_bToggleIJB;
1066 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1070 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1075 case ID_TOOLS_EDITJUNKBUSTER:
1076 EditFile(configfile);
1079 case ID_TOOLS_EDITBLOCKERS:
1080 EditFile(g_blockfile);
1083 case ID_TOOLS_EDITPERMISSIONS:
1084 EditFile(g_permissions_file);
1087 case ID_TOOLS_EDITFORWARD:
1088 EditFile(g_forwardfile);
1092 case ID_TOOLS_EDITACLS:
1093 EditFile(g_aclfile);
1095 #endif /* def ACL_FILES */
1097 #ifdef USE_IMAGE_LIST
1098 case ID_TOOLS_EDITIMAGE:
1099 EditFile(g_imagefile);
1101 #endif /* def USE_IMAGE_LIST */
1104 case ID_TOOLS_EDITPERLRE:
1105 EditFile(g_re_filterfile);
1110 case ID_TOOLS_EDITTRUST:
1111 EditFile(g_trustfile);
1113 #endif /* def TRUST_FILES */
1115 case ID_NEW_BLOCKER:
1116 ShowRulesDialog(g_hwndLogFrame);
1120 ShellExecute(g_hwndLogFrame, "open", "gpl.html", NULL, NULL, SW_SHOWNORMAL);
1124 ShellExecute(g_hwndLogFrame, "open", "ijbfaq.html", NULL, NULL, SW_SHOWNORMAL);
1127 case ID_HELP_MANUAL:
1128 ShellExecute(g_hwndLogFrame, "open", "ijbman.html", NULL, NULL, SW_SHOWNORMAL);
1131 case ID_HELP_STATUS:
1132 ShellExecute(g_hwndLogFrame, "open", "Junkbuster Status.URL", NULL, NULL, SW_SHOWNORMAL);
1135 case ID_HELP_ABOUTJUNKBUSTER:
1136 MessageBox(g_hwndLogFrame, win32_blurb, "Junkbuster Information", MB_OK);
1147 /*********************************************************************
1149 * Function : OnLogInitMenu
1151 * Description : Handler for WM_INITMENU messages. Enable, disable,
1152 * check, and/or uncheck menu options as apropos.
1155 * 1 : hmenu = handle to menu to "make current"
1159 *********************************************************************/
1160 void OnLogInitMenu(HMENU hmenu)
1162 /* Only enable editors if there is a file to edit */
1163 EnableMenuItem(hmenu, ID_TOOLS_EDITPERMISSIONS, MF_BYCOMMAND | (g_permissions_file ? MF_ENABLED : MF_GRAYED));
1164 EnableMenuItem(hmenu, ID_TOOLS_EDITBLOCKERS, MF_BYCOMMAND | (g_blockfile ? MF_ENABLED : MF_GRAYED));
1165 EnableMenuItem(hmenu, ID_TOOLS_EDITFORWARD, MF_BYCOMMAND | (g_forwardfile ? MF_ENABLED : MF_GRAYED));
1167 EnableMenuItem(hmenu, ID_TOOLS_EDITACLS, MF_BYCOMMAND | (g_aclfile ? MF_ENABLED : MF_GRAYED));
1168 #endif /* def ACL_FILES */
1169 #ifdef USE_IMAGE_LIST
1170 EnableMenuItem(hmenu, ID_TOOLS_EDITIMAGE, MF_BYCOMMAND | (g_imagefile ? MF_ENABLED : MF_GRAYED));
1171 #endif /* def USE_IMAGE_LIST */
1173 EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1176 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1177 #endif /* def TRUST_FILES */
1179 /* Check/uncheck options */
1180 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1181 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1182 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1183 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1185 /* by haroon - menu item for Enable toggle on/off */
1186 CheckMenuItem(hmenu, ID_TOGGLE_IJB, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1192 /*********************************************************************
1194 * Function : OnLogTimer
1196 * Description : Handler for WM_TIMER messages.
1199 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1203 *********************************************************************/
1204 void OnLogTimer(int nTimer)
1209 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1212 case TIMER_ANIMSTOP_ID:
1214 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1215 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1216 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1219 case TIMER_CLIPBUFFER_ID:
1220 case TIMER_CLIPBUFFER_FORCE_ID:
1222 g_bClipPending = FALSE;
1223 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1224 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1235 /*********************************************************************
1237 * Function : LogRichEditProc
1239 * Description : Window subclass routine handles some events for the rich edit control.
1242 * 1 : hwnd = window handle of the rich edit control
1243 * 2 : uMsg = message number
1244 * 3 : wParam = first param for this message
1245 * 4 : lParam = next param for this message
1247 * Returns : Appropriate M$ window message handler codes.
1249 *********************************************************************/
1250 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1257 pt.x = LOWORD(lParam);
1258 pt.y = HIWORD(lParam);
1259 ClientToScreen(hwnd, &pt);
1260 OnLogRButtonUp(wParam, pt.x, pt.y);
1264 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1269 /*********************************************************************
1271 * Function : LogWindowProc
1273 * Description : Windows call back routine handles events on the log window.
1276 * 1 : hwnd = handle of the logging window
1277 * 2 : uMsg = message number
1278 * 3 : wParam = first param for this message
1279 * 4 : lParam = next param for this message
1281 * Returns : Appropriate M$ window message handler codes.
1283 *********************************************************************/
1284 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1292 /* This is the end - beautiful friend - the end */
1293 DestroyWindow(g_hwndLogBox);
1294 DestroyWindow(g_hwndLogFrame);
1303 /* Resize the logging window to fit the new frame */
1307 GetClientRect(g_hwndLogFrame, &rc);
1308 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1313 OnLogInitMenu((HMENU) wParam);
1321 OnLogCommand(LOWORD(wParam));
1328 if (g_bCloseHidesWindow)
1330 ShowLogWindow(FALSE);
1335 ShowLogWindow(FALSE);
1341 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1345 #endif /* ndef _WIN_CONSOLE - entire file */