1 const char w32log_rcs[] = "$Id: w32log.c,v 1.6 2001/05/26 00:31:30 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.6 2001/05/26 00:31:30 jongfoster
36 * Fixing compiler warning about comparing signed/unsigned.
38 * Revision 1.5 2001/05/26 00:28:36 jongfoster
39 * Automatic reloading of config file.
40 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
41 * Most of the global variables have been moved to a new
42 * struct configuration_spec, accessed through csp->config->globalname
43 * Most of the globals remaining are used by the Win32 GUI.
45 * Revision 1.4 2001/05/22 18:56:28 oes
48 * Revision 1.3 2001/05/20 15:07:54 jongfoster
49 * File is now ignored if _WIN_CONSOLE is defined.
51 * Revision 1.2 2001/05/20 01:21:20 jongfoster
52 * Version 2.9.4 checkin.
53 * - Merged popupfile and cookiefile, and added control over PCRS
54 * filtering, in new "permissionsfile".
55 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
56 * file error you now get a message box (in the Win32 GUI) rather
57 * than the program exiting with no explanation.
58 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
60 * - Removed tabs from "config"
61 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
62 * - Bumped up version number.
64 * Revision 1.1.1.1 2001/05/15 13:59:07 oes
65 * Initial import of version 2.9.3 source tree
68 *********************************************************************/
81 #include "w32taskbar.h"
82 #include "w32rulesdlg.h"
89 const char w32res_h_rcs[] = W32RES_H_VERSION;
93 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
96 const char w32log_h_rcs[] = W32LOG_H_VERSION;
98 #ifndef _WIN_CONSOLE /* entire file */
101 * Timers and the various durations
103 #define TIMER_ANIM_ID 1
104 #define TIMER_ANIM_TIME 100
105 #define TIMER_ANIMSTOP_ID 2
106 #define TIMER_ANIMSTOP_TIME 1000
107 #define TIMER_CLIPBUFFER_ID 3
108 #define TIMER_CLIPBUFFER_TIME 1000
109 #define TIMER_CLIPBUFFER_FORCE_ID 4
110 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
113 * Styles of text that can be output
116 #define STYLE_HIGHLIGHT 1
118 #define STYLE_HEADER 3
121 * Number of frames of animation in tray activity sequence
123 #define ANIM_FRAMES 8
125 #define DEFAULT_MAX_BUFFER_LINES 200
126 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
127 #define DEFAULT_LOG_FONT_SIZE 8
130 * These values affect the way the log window behaves, they should be read
131 * from a file but for the moment, they are hardcoded here. Some options are
132 * configurable through the UI.
135 /* Indicates whether task bar shows activity animation */
136 BOOL g_bShowActivityAnimation = 1;
138 /* Indicates if the log window appears on the task bar */
139 BOOL g_bShowOnTaskBar = 0;
141 /* Indicates whether closing the log window really just hides it */
142 BOOL g_bCloseHidesWindow = 1;
144 /* Indicates if messages are logged at all */
145 BOOL g_bLogMessages = 1;
147 /* Indicates whether log messages are highlighted */
148 BOOL g_bHighlightMessages = 1;
150 /* Indicates if buffer is limited in size */
151 BOOL g_bLimitBufferSize = 1;
153 /* Maximum number of lines allowed in buffer when limited */
154 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
157 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
159 /* Size of font to use */
160 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
163 /* FIXME: this is a kludge */
165 const char * g_blockfile = NULL;
166 const char * g_permissions_file = NULL;
167 const char * g_forwardfile = NULL;
169 const char * g_aclfile = NULL;
170 #endif /* def ACL_FILES */
171 #ifdef USE_IMAGE_LIST
172 const char * g_imagefile = NULL;
173 #endif /* def USE_IMAGE_LIST */
175 const char * g_re_filterfile = NULL;
178 const char * g_trustfile = NULL;
179 #endif /* def TRUST_FILES */
181 /* FIXME: end kludge */
185 /* Regular expression for detected URLs */
186 #define RE_URL "http:[^ \n\r]*"
189 * Regular expressions that are used to perform highlight in the log window
191 static struct _Pattern
196 } patterns_to_highlight[] =
199 { RE_URL, STYLE_LINK },
200 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
201 /* interesting text to highlight */
202 { "crunch!", STYLE_HIGHLIGHT },
204 { "referer:", STYLE_HEADER },
205 { "proxy-connection:", STYLE_HEADER },
206 { "proxy-agent:", STYLE_HEADER },
207 { "user-agent:", STYLE_HEADER },
208 { "host:", STYLE_HEADER },
209 { "accept:", STYLE_HEADER },
210 { "accept-encoding:", STYLE_HEADER },
211 { "accept-language:", STYLE_HEADER },
212 { "accept-charset:", STYLE_HEADER },
213 { "accept-ranges:", STYLE_HEADER },
214 { "date:", STYLE_HEADER },
215 { "cache-control:", STYLE_HEADER },
216 { "cache-last-checked:", STYLE_HEADER },
217 { "connection:", STYLE_HEADER },
218 { "content-type", STYLE_HEADER },
219 { "content-length", STYLE_HEADER },
220 { "cookie", STYLE_HEADER },
221 { "last-modified:", STYLE_HEADER },
222 { "pragma:", STYLE_HEADER },
223 { "server:", STYLE_HEADER },
224 { "etag:", STYLE_HEADER },
225 { "expires:", STYLE_HEADER },
226 { "warning:", STYLE_HEADER },
227 /* this is the terminator statement - do not delete! */
230 #endif /* def REGEX */
241 static CRITICAL_SECTION g_criticalsection;
242 static HWND g_hwndTray;
243 static HWND g_hwndLogBox;
244 static WNDPROC g_fnLogBox;
245 static HICON g_hiconAnim[ANIM_FRAMES];
246 static HICON g_hiconIdle;
247 static HICON g_hiconApp;
248 static int g_nAnimFrame;
249 static BOOL g_bClipPending = FALSE;
250 static int g_nRichEditVersion = 0;
255 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
256 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
257 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
258 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
259 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
260 static BOOL InitRichEdit(void);
261 static void LogClipBuffer(void);
262 static void LogCreatePatternMatchingBuffers(void);
263 static void LogDestroyPatternMatchingBuffers(void);
264 static int LogPutStringNoMatch(const char *pszText, int style);
267 /*********************************************************************
269 * Function : InitLogWindow
271 * Description : Initialise the log window.
275 * Returns : Always TRUE (there should be error checking on the resources).
277 *********************************************************************/
278 BOOL InitLogWindow(void)
283 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
284 for (i = 0; i < ANIM_FRAMES; i++)
286 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER1 + i));
288 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER));
290 /* Create the user interface */
291 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
292 g_hwndTray = CreateTrayWindow(g_hInstance);
293 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Junkbuster");
295 /* Create pattern matching buffers (for highlighting */
296 LogCreatePatternMatchingBuffers();
298 /* Create a critical section to protect multi-threaded access to certain things */
299 InitializeCriticalSection(&g_criticalsection);
306 /*********************************************************************
308 * Function : TermLogWindow
310 * Description : Cleanup the logwindow.
316 *********************************************************************/
317 void TermLogWindow(void)
321 LogDestroyPatternMatchingBuffers();
323 TrayDeleteIcon(g_hwndTray, 1);
324 DeleteObject(g_hiconApp);
325 DeleteObject(g_hiconIdle);
326 for (i = 0; i < ANIM_FRAMES; i++)
328 DeleteObject(g_hiconAnim[i]);
334 /*********************************************************************
336 * Function : LogCreatePatternMatchingBuffers
338 * Description : Compile the pattern matching buffers.
344 *********************************************************************/
345 void LogCreatePatternMatchingBuffers(void)
349 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
351 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
358 /*********************************************************************
360 * Function : LogDestroyPatternMatchingBuffers
362 * Description : Free up the pattern matching buffers.
368 *********************************************************************/
369 void LogDestroyPatternMatchingBuffers(void)
373 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
375 regfree(&patterns_to_highlight[i].buffer);
382 /*********************************************************************
384 * Function : LogGetURLUnderCursor
386 * Description : Returns the URL from under the cursor (remember to free it!).
390 * Returns : NULL or a pointer to an URL string.
392 *********************************************************************/
393 char *LogGetURLUnderCursor(void)
395 char *szResult = NULL;
401 DWORD nWordStart = 0;
404 regcomp(&re, RE_URL, REG_ICASE);
406 /* Get the position of the cursor over the text window */
407 GetCursorPos(&ptCursor);
408 ScreenToClient(g_hwndLogBox, &ptCursor);
412 /* Search backwards and fowards to obtain the word that is highlighted */
413 nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
414 nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
415 nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
417 /* Compare the string to the pattern */
418 if (nWordEnd > nWordStart)
423 range.chrg.cpMin = nWordStart;
424 range.chrg.cpMax = nWordEnd;
425 range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
426 SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
428 if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
430 szResult = range.lpstrText;
434 free(range.lpstrText);
445 /*********************************************************************
447 * Function : LogPutString
449 * Description : Inserts text into the logging window. This is really
450 * a REGEXP aware wrapper function to `LogPutStringNoMatch'.
453 * 1 : pszText = pointer to string going to the log window
455 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
456 * FIXME: this is backwards to the rest of IJB and to common
457 * programming practice. Please use 0 => success instead.
459 *********************************************************************/
460 int LogPutString(const char *pszText)
467 if (pszText == NULL || strlen(pszText) == 0)
477 /* Critical section stops multiple threads doing nasty interactions that
478 * foul up the highlighting and output.
480 EnterCriticalSection(&g_criticalsection);
483 if (g_bHighlightMessages)
487 /* First things first, regexp scan for various things that we would like highlighted */
488 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
490 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
492 char *pszBefore = NULL;
493 char *pszMatch = NULL;
494 char *pszAfter = NULL;
497 /* Split the string up into pieces representing the strings, before
498 at and after the matching pattern
502 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
503 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
504 strncpy(pszBefore, pszText, match.rm_so);
506 if (match.rm_eo < (regoff_t)strlen(pszText))
508 pszAfter = strdup(&pszText[match.rm_eo]);
510 nMatchSize = match.rm_eo - match.rm_so;
511 pszMatch = (char *)malloc(nMatchSize + 1);
512 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
513 pszMatch[nMatchSize] = '\0';
515 /* Recursively call LogPutString */
518 LogPutString(pszBefore);
523 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
528 LogPutString(pszAfter);
539 result = LogPutStringNoMatch(pszText, STYLE_NONE);
544 LeaveCriticalSection(&g_criticalsection);
551 /*********************************************************************
553 * Function : LogPutStringNoMatch
555 * Description : Puts a string into the logging window.
558 * 1 : pszText = pointer to string going to the log window
559 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
561 * Returns : Always 1 => success.
562 * FIXME: this is backwards to the rest of IJB and to common
563 * programming practice. Please use 0 => success instead.
565 *********************************************************************/
566 int LogPutStringNoMatch(const char *pszText, int style)
572 assert(g_hwndLogBox);
573 if (g_hwndLogBox == NULL)
578 /* TODO preserve existing selection */
580 /* Go to the end of the text */
581 nTextLength = GetWindowTextLength(g_hwndLogBox);
582 range.cpMin = nTextLength;
583 range.cpMax = nTextLength;
584 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
586 /* Apply a formatting style */
587 memset(&format, 0, sizeof(format));
588 format.cbSize = sizeof(format);
589 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
590 format.yHeight = (g_nFontSize * 1440) / 72;
591 strcpy(format.szFaceName, g_szFontFaceName);
592 if (style == STYLE_NONE)
595 format.dwEffects |= CFE_AUTOCOLOR;
597 else if (style == STYLE_HEADER)
599 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
601 else if (style == STYLE_HIGHLIGHT)
603 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
605 else if (style == STYLE_LINK)
607 format.dwEffects |= CFE_UNDERLINE;
608 format.crTextColor = RGB(0, 0, 255);
610 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
612 /* Append text to the end */
613 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
615 /* TODO Restore the old selection */
618 if (strchr(pszText, '\n') != NULL)
620 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
623 /* Set the force clip timer going. This timer ensures clipping is done
624 intermittently even when there is a sustained burst of logging
626 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
628 g_bClipPending = TRUE;
636 /*********************************************************************
638 * Function : LogShowActivity
640 * Description : Start the spinner.
646 *********************************************************************/
647 void LogShowActivity(void)
649 /* Start some activity timers */
650 if (g_bShowActivityAnimation)
652 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
653 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
659 /*********************************************************************
661 * Function : LogClipBuffer
663 * Description : Prunes old lines from the log.
669 *********************************************************************/
670 void LogClipBuffer(void)
672 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
673 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
675 /* Compute the range representing the lines to be deleted */
676 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
677 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
680 range.cpMax = nLastChar;
682 /* TODO get current selection */
684 /* TODO adjust and clip old selection against range to be deleted */
686 /* Select range and erase it (turning off autoscroll to prevent
688 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
689 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
690 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
691 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
693 /* Restore old selection */
699 /*********************************************************************
701 * Function : CreateHiddenLogOwnerWindow
703 * Description : Creates a hidden owner window that stops the log
704 * window appearing in the task bar.
707 * 1 : hInstance = application's instance handle
709 * Returns : Handle to newly created window.
711 *********************************************************************/
712 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
714 static const char *szWndName = "JunkbusterLogLogOwner";
719 wc.lpfnWndProc = LogOwnerWindowProc;
722 wc.hInstance = hInstance;
725 wc.hbrBackground = 0;
727 wc.lpszClassName = szWndName;
731 hwnd = CreateWindow(szWndName, szWndName,
732 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
733 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
740 /*********************************************************************
742 * Function : LogOwnerWindowProc
744 * Description : Dummy procedure that does nothing special.
747 * 1 : hwnd = window handle
748 * 2 : uMsg = message number
749 * 3 : wParam = first param for this message
750 * 4 : lParam = next param for this message
752 * Returns : Same as `DefWindowProc'.
754 *********************************************************************/
755 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
757 return DefWindowProc(hwnd, uMsg, wParam, lParam);
762 /*********************************************************************
764 * Function : CreateLogWindow
766 * Description : Create the logging window.
769 * 1 : hInstance = application's instance handle
770 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
772 * Returns : Handle to newly created window.
774 *********************************************************************/
775 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
777 static const char *szWndName = "JunkbusterLogWindow";
778 static const char *szWndTitle = "Junkbuster";
781 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
782 HWND hwndChild = NULL;
786 memset(&wc, 0, sizeof(wc));
787 wc.cbSize = sizeof(wc);
788 wc.style = CS_DBLCLKS;
789 wc.lpfnWndProc = LogWindowProc;
792 wc.hInstance = hInstance;
793 wc.hIcon = g_hiconApp;
795 wc.hbrBackground = 0;
796 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
797 wc.lpszClassName = szWndName;
798 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
799 RegisterClassEx(&wc);
801 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
802 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
803 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
805 /* Now create a child list box */
806 GetClientRect(hwnd, &rcClient);
808 /* Create a rich edit control */
810 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
811 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
812 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
813 hwnd, NULL, hInstance, NULL);
814 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
816 /* Subclass the control to catch certain messages */
817 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
818 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
820 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
821 if (!g_bShowOnTaskBar &&
822 (nCmdShow == SW_SHOWMINIMIZED ||
823 nCmdShow == SW_MINIMIZE ||
824 nCmdShow == SW_SHOWMINNOACTIVE))
829 ShowWindow(hwnd, nCmdShow);
832 GetClientRect(g_hwndLogFrame, &rcClient);
833 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
840 /*********************************************************************
842 * Function : InitRichEdit
844 * Description : Initialise the rich edit control library.
848 * Returns : TRUE => success, FALSE => failure.
849 * FIXME: this is backwards to the rest of IJB and to common
850 * programming practice. Please use 0 => success instead.
852 *********************************************************************/
853 BOOL InitRichEdit(void)
855 static HINSTANCE hInstRichEdit;
856 if (hInstRichEdit == NULL)
858 g_nRichEditVersion = 0;
859 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
862 g_nRichEditVersion = _RICHEDIT_VER;
866 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
869 g_nRichEditVersion = 0x0100;
873 return (hInstRichEdit != NULL) ? TRUE : FALSE;
878 /*********************************************************************
880 * Function : ShowLogWindow
882 * Description : Shows or hides the log window. We will also raise the
883 * window on a show command in case it is buried.
886 * 1 : bShow = TRUE to show, FALSE to mimize/hide
890 *********************************************************************/
891 void ShowLogWindow(BOOL bShow)
895 SetForegroundWindow(g_hwndLogFrame);
896 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
898 else if (g_bShowOnTaskBar)
900 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
904 ShowWindow(g_hwndLogFrame, SW_HIDE);
910 /*********************************************************************
912 * Function : EditFile
914 * Description : Opens the specified setting file for editing.
917 * 1 : filename = filename from the config (aka junkbstr.txt) file.
921 *********************************************************************/
922 void EditFile(const char *filename)
926 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
932 /*--------------------------------------------------------------------------*/
933 /* Windows message handlers */
934 /*--------------------------------------------------------------------------*/
937 /*********************************************************************
939 * Function : OnLogRButtonUp
941 * Description : Handler for WM_RBUTTONUP messages.
944 * 1 : nModifier = wParam from mouse message (unused)
945 * 2 : x = x coordinate of the mouse event
946 * 3 : y = y coordinate of the mouse event
950 *********************************************************************/
951 void OnLogRButtonUp(int nModifier, int x, int y)
953 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
956 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
957 #ifdef WIN_GUI_EDIT
\r
959 #endif /* def WIN_GUI_EDIT */
\r
961 /* Check if there is a selection */
963 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
964 if (range.cpMin == range.cpMax)
966 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
970 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
973 #ifdef WIN_GUI_EDIT
\r
974 /* Check if cursor is over a link */
975 szURL = LogGetURLUnderCursor();
979 TCHAR szMenuItemTemplate[1000];
982 memset(&item, 0, sizeof(item));
983 item.cbSize = sizeof(item);
984 item.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
985 item.fType = MFT_STRING;
986 item.fState = MFS_ENABLED;
987 item.wID = ID_NEW_BLOCKER;
989 /* Put the item into the menu */
990 memset(szMenuItemTemplate, 0, sizeof(szMenuItemTemplate));
991 LoadString(g_hInstance, IDS_NEW_BLOCKER, szMenuItemTemplate, sizeof(szMenuItemTemplate) / sizeof(szMenuItemTemplate[0]));
993 szMenuItem = (char *)malloc(strlen(szMenuItemTemplate) + strlen(szURL) + 1);
994 sprintf(szMenuItem, szMenuItemTemplate, szURL);
996 item.dwTypeData = szMenuItem;
997 item.cch = strlen(szMenuItem);
999 InsertMenuItem(hMenuPopup, 1, TRUE, &item);
1001 SetDefaultRule(szURL);
1005 #endif /* def WIN_GUI_EDIT */
\r
1007 /* Display the popup */
1008 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
1015 /*********************************************************************
1017 * Function : OnLogCommand
1019 * Description : Handler for WM_COMMAND messages.
1022 * 1 : nCommand = the command portion of the menu selection event
1026 *********************************************************************/
1027 void OnLogCommand(int nCommand)
1032 ShowLogWindow(TRUE);
1036 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1040 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1043 case ID_VIEW_CLEARLOG:
1044 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1047 case ID_VIEW_LOGMESSAGES:
1048 g_bLogMessages = !g_bLogMessages;
1049 /* SaveLogSettings(); */
1052 case ID_VIEW_MESSAGEHIGHLIGHTING:
1053 g_bHighlightMessages = !g_bHighlightMessages;
1054 /* SaveLogSettings(); */
1057 case ID_VIEW_LIMITBUFFERSIZE:
1058 g_bLimitBufferSize = !g_bLimitBufferSize;
1059 /* SaveLogSettings(); */
1062 case ID_VIEW_ACTIVITYANIMATION:
1063 g_bShowActivityAnimation = !g_bShowActivityAnimation;
1064 /* SaveLogSettings(); */
1068 /* by haroon - change toggle to its opposite value */
1070 g_bToggleIJB = !g_bToggleIJB;
1073 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1077 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1082 case ID_TOOLS_EDITJUNKBUSTER:
1083 EditFile(configfile);
1086 case ID_TOOLS_EDITBLOCKERS:
1087 EditFile(g_blockfile);
1090 case ID_TOOLS_EDITPERMISSIONS:
1091 EditFile(g_permissions_file);
1094 case ID_TOOLS_EDITFORWARD:
1095 EditFile(g_forwardfile);
1099 case ID_TOOLS_EDITACLS:
1100 EditFile(g_aclfile);
1102 #endif /* def ACL_FILES */
1104 #ifdef USE_IMAGE_LIST
1105 case ID_TOOLS_EDITIMAGE:
1106 EditFile(g_imagefile);
1108 #endif /* def USE_IMAGE_LIST */
1111 case ID_TOOLS_EDITPERLRE:
1112 EditFile(g_re_filterfile);
1117 case ID_TOOLS_EDITTRUST:
1118 EditFile(g_trustfile);
1120 #endif /* def TRUST_FILES */
1122 #ifdef WIN_GUI_EDIT
\r
1123 case ID_NEW_BLOCKER:
1124 ShowRulesDialog(g_hwndLogFrame);
1126 #endif /* def WIN_GUI_EDIT */
\r
1129 ShellExecute(g_hwndLogFrame, "open", "gpl.html", NULL, NULL, SW_SHOWNORMAL);
1133 ShellExecute(g_hwndLogFrame, "open", "ijbfaq.html", NULL, NULL, SW_SHOWNORMAL);
1136 case ID_HELP_MANUAL:
1137 ShellExecute(g_hwndLogFrame, "open", "ijbman.html", NULL, NULL, SW_SHOWNORMAL);
1140 case ID_HELP_STATUS:
1141 ShellExecute(g_hwndLogFrame, "open", "Junkbuster Status.URL", NULL, NULL, SW_SHOWNORMAL);
1144 case ID_HELP_ABOUTJUNKBUSTER:
1145 MessageBox(g_hwndLogFrame, win32_blurb, "Junkbuster Information", MB_OK);
1156 /*********************************************************************
1158 * Function : OnLogInitMenu
1160 * Description : Handler for WM_INITMENU messages. Enable, disable,
1161 * check, and/or uncheck menu options as apropos.
1164 * 1 : hmenu = handle to menu to "make current"
1168 *********************************************************************/
1169 void OnLogInitMenu(HMENU hmenu)
1171 /* Only enable editors if there is a file to edit */
1172 EnableMenuItem(hmenu, ID_TOOLS_EDITPERMISSIONS, MF_BYCOMMAND | (g_permissions_file ? MF_ENABLED : MF_GRAYED));
1173 EnableMenuItem(hmenu, ID_TOOLS_EDITBLOCKERS, MF_BYCOMMAND | (g_blockfile ? MF_ENABLED : MF_GRAYED));
1174 EnableMenuItem(hmenu, ID_TOOLS_EDITFORWARD, MF_BYCOMMAND | (g_forwardfile ? MF_ENABLED : MF_GRAYED));
1176 EnableMenuItem(hmenu, ID_TOOLS_EDITACLS, MF_BYCOMMAND | (g_aclfile ? MF_ENABLED : MF_GRAYED));
1177 #endif /* def ACL_FILES */
1178 #ifdef USE_IMAGE_LIST
1179 EnableMenuItem(hmenu, ID_TOOLS_EDITIMAGE, MF_BYCOMMAND | (g_imagefile ? MF_ENABLED : MF_GRAYED));
1180 #endif /* def USE_IMAGE_LIST */
1182 EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1185 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1186 #endif /* def TRUST_FILES */
1188 /* Check/uncheck options */
1189 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1190 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1191 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1192 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1194 /* by haroon - menu item for Enable toggle on/off */
1195 CheckMenuItem(hmenu, ID_TOGGLE_IJB, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1201 /*********************************************************************
1203 * Function : OnLogTimer
1205 * Description : Handler for WM_TIMER messages.
1208 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1212 *********************************************************************/
1213 void OnLogTimer(int nTimer)
1218 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1221 case TIMER_ANIMSTOP_ID:
1223 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1224 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1225 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1228 case TIMER_CLIPBUFFER_ID:
1229 case TIMER_CLIPBUFFER_FORCE_ID:
1231 g_bClipPending = FALSE;
1232 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1233 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1244 /*********************************************************************
1246 * Function : LogRichEditProc
1248 * Description : Window subclass routine handles some events for the rich edit control.
1251 * 1 : hwnd = window handle of the rich edit control
1252 * 2 : uMsg = message number
1253 * 3 : wParam = first param for this message
1254 * 4 : lParam = next param for this message
1256 * Returns : Appropriate M$ window message handler codes.
1258 *********************************************************************/
1259 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1266 pt.x = LOWORD(lParam);
1267 pt.y = HIWORD(lParam);
1268 ClientToScreen(hwnd, &pt);
1269 OnLogRButtonUp(wParam, pt.x, pt.y);
1273 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1278 /*********************************************************************
1280 * Function : LogWindowProc
1282 * Description : Windows call back routine handles events on the log window.
1285 * 1 : hwnd = handle of the logging window
1286 * 2 : uMsg = message number
1287 * 3 : wParam = first param for this message
1288 * 4 : lParam = next param for this message
1290 * Returns : Appropriate M$ window message handler codes.
1292 *********************************************************************/
1293 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1301 /* This is the end - beautiful friend - the end */
1302 DestroyWindow(g_hwndLogBox);
1303 DestroyWindow(g_hwndLogFrame);
1312 /* Resize the logging window to fit the new frame */
1316 GetClientRect(g_hwndLogFrame, &rc);
1317 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1322 OnLogInitMenu((HMENU) wParam);
1330 OnLogCommand(LOWORD(wParam));
1337 if (g_bCloseHidesWindow)
1339 ShowLogWindow(FALSE);
1344 ShowLogWindow(FALSE);
1350 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1354 #endif /* ndef _WIN_CONSOLE - entire file */