1 const char w32log_rcs[] = "$Id: w32log.c,v 1.7 2001/05/26 01:26:34 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.7 2001/05/26 01:26:34 jongfoster
36 * New #define, WIN_GUI_EDIT, enables the (embryonic) Win32 GUI editor.
37 * This #define cannot be set from ./configure - there's no point, it
38 * doesn't work yet. See feature request # 425722
40 * Revision 1.6 2001/05/26 00:31:30 jongfoster
41 * Fixing compiler warning about comparing signed/unsigned.
43 * Revision 1.5 2001/05/26 00:28:36 jongfoster
44 * Automatic reloading of config file.
45 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
46 * Most of the global variables have been moved to a new
47 * struct configuration_spec, accessed through csp->config->globalname
48 * Most of the globals remaining are used by the Win32 GUI.
50 * Revision 1.4 2001/05/22 18:56:28 oes
53 * Revision 1.3 2001/05/20 15:07:54 jongfoster
54 * File is now ignored if _WIN_CONSOLE is defined.
56 * Revision 1.2 2001/05/20 01:21:20 jongfoster
57 * Version 2.9.4 checkin.
58 * - Merged popupfile and cookiefile, and added control over PCRS
59 * filtering, in new "permissionsfile".
60 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
61 * file error you now get a message box (in the Win32 GUI) rather
62 * than the program exiting with no explanation.
63 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
65 * - Removed tabs from "config"
66 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
67 * - Bumped up version number.
69 * Revision 1.1.1.1 2001/05/15 13:59:07 oes
70 * Initial import of version 2.9.3 source tree
73 *********************************************************************/
86 #include "w32taskbar.h"
87 #include "w32rulesdlg.h"
94 const char w32res_h_rcs[] = W32RES_H_VERSION;
98 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
101 const char w32log_h_rcs[] = W32LOG_H_VERSION;
103 #ifndef _WIN_CONSOLE /* entire file */
106 * Timers and the various durations
108 #define TIMER_ANIM_ID 1
109 #define TIMER_ANIM_TIME 100
110 #define TIMER_ANIMSTOP_ID 2
111 #define TIMER_ANIMSTOP_TIME 1000
112 #define TIMER_CLIPBUFFER_ID 3
113 #define TIMER_CLIPBUFFER_TIME 1000
114 #define TIMER_CLIPBUFFER_FORCE_ID 4
115 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
118 * Styles of text that can be output
121 #define STYLE_HIGHLIGHT 1
123 #define STYLE_HEADER 3
126 * Number of frames of animation in tray activity sequence
128 #define ANIM_FRAMES 8
130 #define DEFAULT_MAX_BUFFER_LINES 200
131 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
132 #define DEFAULT_LOG_FONT_SIZE 8
135 * These values affect the way the log window behaves, they should be read
136 * from a file but for the moment, they are hardcoded here. Some options are
137 * configurable through the UI.
140 /* Indicates whether task bar shows activity animation */
141 BOOL g_bShowActivityAnimation = 1;
143 /* Indicates if the log window appears on the task bar */
144 BOOL g_bShowOnTaskBar = 0;
146 /* Indicates whether closing the log window really just hides it */
147 BOOL g_bCloseHidesWindow = 1;
149 /* Indicates if messages are logged at all */
150 BOOL g_bLogMessages = 1;
152 /* Indicates whether log messages are highlighted */
153 BOOL g_bHighlightMessages = 1;
155 /* Indicates if buffer is limited in size */
156 BOOL g_bLimitBufferSize = 1;
158 /* Maximum number of lines allowed in buffer when limited */
159 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
162 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
164 /* Size of font to use */
165 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
168 /* FIXME: this is a kludge */
170 const char * g_permissions_file = NULL;
171 const char * g_forwardfile = NULL;
173 const char * g_aclfile = NULL;
174 #endif /* def ACL_FILES */
176 const char * g_re_filterfile = NULL;
179 const char * g_trustfile = NULL;
180 #endif /* def TRUST_FILES */
182 /* FIXME: end kludge */
186 /* Regular expression for detected URLs */
187 #define RE_URL "http:[^ \n\r]*"
190 * Regular expressions that are used to perform highlight in the log window
192 static struct _Pattern
197 } patterns_to_highlight[] =
200 { RE_URL, STYLE_LINK },
201 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
202 /* interesting text to highlight */
203 { "crunch!", STYLE_HIGHLIGHT },
205 { "referer:", STYLE_HEADER },
206 { "proxy-connection:", STYLE_HEADER },
207 { "proxy-agent:", STYLE_HEADER },
208 { "user-agent:", STYLE_HEADER },
209 { "host:", STYLE_HEADER },
210 { "accept:", STYLE_HEADER },
211 { "accept-encoding:", STYLE_HEADER },
212 { "accept-language:", STYLE_HEADER },
213 { "accept-charset:", STYLE_HEADER },
214 { "accept-ranges:", STYLE_HEADER },
215 { "date:", STYLE_HEADER },
216 { "cache-control:", STYLE_HEADER },
217 { "cache-last-checked:", STYLE_HEADER },
218 { "connection:", STYLE_HEADER },
219 { "content-type", STYLE_HEADER },
220 { "content-length", STYLE_HEADER },
221 { "cookie", STYLE_HEADER },
222 { "last-modified:", STYLE_HEADER },
223 { "pragma:", STYLE_HEADER },
224 { "server:", STYLE_HEADER },
225 { "etag:", STYLE_HEADER },
226 { "expires:", STYLE_HEADER },
227 { "warning:", STYLE_HEADER },
228 /* this is the terminator statement - do not delete! */
231 #endif /* def REGEX */
242 static CRITICAL_SECTION g_criticalsection;
243 static HWND g_hwndTray;
244 static HWND g_hwndLogBox;
245 static WNDPROC g_fnLogBox;
246 static HICON g_hiconAnim[ANIM_FRAMES];
247 static HICON g_hiconIdle;
248 static HICON g_hiconApp;
249 static int g_nAnimFrame;
250 static BOOL g_bClipPending = FALSE;
251 static int g_nRichEditVersion = 0;
256 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
257 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
258 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
259 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
260 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
261 static BOOL InitRichEdit(void);
262 static void LogClipBuffer(void);
263 static void LogCreatePatternMatchingBuffers(void);
264 static void LogDestroyPatternMatchingBuffers(void);
265 static int LogPutStringNoMatch(const char *pszText, int style);
268 /*********************************************************************
270 * Function : InitLogWindow
272 * Description : Initialise the log window.
276 * Returns : Always TRUE (there should be error checking on the resources).
278 *********************************************************************/
279 BOOL InitLogWindow(void)
284 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
285 for (i = 0; i < ANIM_FRAMES; i++)
287 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER1 + i));
289 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER));
291 /* Create the user interface */
292 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
293 g_hwndTray = CreateTrayWindow(g_hInstance);
294 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Junkbuster");
296 /* Create pattern matching buffers (for highlighting */
297 LogCreatePatternMatchingBuffers();
299 /* Create a critical section to protect multi-threaded access to certain things */
300 InitializeCriticalSection(&g_criticalsection);
307 /*********************************************************************
309 * Function : TermLogWindow
311 * Description : Cleanup the logwindow.
317 *********************************************************************/
318 void TermLogWindow(void)
322 LogDestroyPatternMatchingBuffers();
324 TrayDeleteIcon(g_hwndTray, 1);
325 DeleteObject(g_hiconApp);
326 DeleteObject(g_hiconIdle);
327 for (i = 0; i < ANIM_FRAMES; i++)
329 DeleteObject(g_hiconAnim[i]);
335 /*********************************************************************
337 * Function : LogCreatePatternMatchingBuffers
339 * Description : Compile the pattern matching buffers.
345 *********************************************************************/
346 void LogCreatePatternMatchingBuffers(void)
350 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
352 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
359 /*********************************************************************
361 * Function : LogDestroyPatternMatchingBuffers
363 * Description : Free up the pattern matching buffers.
369 *********************************************************************/
370 void LogDestroyPatternMatchingBuffers(void)
374 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
376 regfree(&patterns_to_highlight[i].buffer);
383 /*********************************************************************
385 * Function : LogGetURLUnderCursor
387 * Description : Returns the URL from under the cursor (remember to free it!).
391 * Returns : NULL or a pointer to an URL string.
393 *********************************************************************/
394 char *LogGetURLUnderCursor(void)
396 char *szResult = NULL;
402 DWORD nWordStart = 0;
405 regcomp(&re, RE_URL, REG_ICASE);
407 /* Get the position of the cursor over the text window */
408 GetCursorPos(&ptCursor);
409 ScreenToClient(g_hwndLogBox, &ptCursor);
413 /* Search backwards and fowards to obtain the word that is highlighted */
414 nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
415 nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
416 nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
418 /* Compare the string to the pattern */
419 if (nWordEnd > nWordStart)
424 range.chrg.cpMin = nWordStart;
425 range.chrg.cpMax = nWordEnd;
426 range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
427 SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
429 if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
431 szResult = range.lpstrText;
435 free(range.lpstrText);
446 /*********************************************************************
448 * Function : LogPutString
450 * Description : Inserts text into the logging window. This is really
451 * a REGEXP aware wrapper function to `LogPutStringNoMatch'.
454 * 1 : pszText = pointer to string going to the log window
456 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
457 * FIXME: this is backwards to the rest of IJB and to common
458 * programming practice. Please use 0 => success instead.
460 *********************************************************************/
461 int LogPutString(const char *pszText)
468 if (pszText == NULL || strlen(pszText) == 0)
478 /* Critical section stops multiple threads doing nasty interactions that
479 * foul up the highlighting and output.
481 EnterCriticalSection(&g_criticalsection);
484 if (g_bHighlightMessages)
488 /* First things first, regexp scan for various things that we would like highlighted */
489 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
491 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
493 char *pszBefore = NULL;
494 char *pszMatch = NULL;
495 char *pszAfter = NULL;
498 /* Split the string up into pieces representing the strings, before
499 at and after the matching pattern
503 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
504 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
505 strncpy(pszBefore, pszText, match.rm_so);
507 if (match.rm_eo < (regoff_t)strlen(pszText))
509 pszAfter = strdup(&pszText[match.rm_eo]);
511 nMatchSize = match.rm_eo - match.rm_so;
512 pszMatch = (char *)malloc(nMatchSize + 1);
513 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
514 pszMatch[nMatchSize] = '\0';
516 /* Recursively call LogPutString */
519 LogPutString(pszBefore);
524 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
529 LogPutString(pszAfter);
540 result = LogPutStringNoMatch(pszText, STYLE_NONE);
545 LeaveCriticalSection(&g_criticalsection);
552 /*********************************************************************
554 * Function : LogPutStringNoMatch
556 * Description : Puts a string into the logging window.
559 * 1 : pszText = pointer to string going to the log window
560 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
562 * Returns : Always 1 => success.
563 * FIXME: this is backwards to the rest of IJB and to common
564 * programming practice. Please use 0 => success instead.
566 *********************************************************************/
567 int LogPutStringNoMatch(const char *pszText, int style)
573 assert(g_hwndLogBox);
574 if (g_hwndLogBox == NULL)
579 /* TODO preserve existing selection */
581 /* Go to the end of the text */
582 nTextLength = GetWindowTextLength(g_hwndLogBox);
583 range.cpMin = nTextLength;
584 range.cpMax = nTextLength;
585 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
587 /* Apply a formatting style */
588 memset(&format, 0, sizeof(format));
589 format.cbSize = sizeof(format);
590 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
591 format.yHeight = (g_nFontSize * 1440) / 72;
592 strcpy(format.szFaceName, g_szFontFaceName);
593 if (style == STYLE_NONE)
596 format.dwEffects |= CFE_AUTOCOLOR;
598 else if (style == STYLE_HEADER)
600 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
602 else if (style == STYLE_HIGHLIGHT)
604 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
606 else if (style == STYLE_LINK)
608 format.dwEffects |= CFE_UNDERLINE;
609 format.crTextColor = RGB(0, 0, 255);
611 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
613 /* Append text to the end */
614 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
616 /* TODO Restore the old selection */
619 if (strchr(pszText, '\n') != NULL)
621 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
624 /* Set the force clip timer going. This timer ensures clipping is done
625 intermittently even when there is a sustained burst of logging
627 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
629 g_bClipPending = TRUE;
637 /*********************************************************************
639 * Function : LogShowActivity
641 * Description : Start the spinner.
647 *********************************************************************/
648 void LogShowActivity(void)
650 /* Start some activity timers */
651 if (g_bShowActivityAnimation)
653 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
654 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
660 /*********************************************************************
662 * Function : LogClipBuffer
664 * Description : Prunes old lines from the log.
670 *********************************************************************/
671 void LogClipBuffer(void)
673 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
674 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
676 /* Compute the range representing the lines to be deleted */
677 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
678 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
681 range.cpMax = nLastChar;
683 /* TODO get current selection */
685 /* TODO adjust and clip old selection against range to be deleted */
687 /* Select range and erase it (turning off autoscroll to prevent
689 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
690 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
691 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
692 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
694 /* Restore old selection */
700 /*********************************************************************
702 * Function : CreateHiddenLogOwnerWindow
704 * Description : Creates a hidden owner window that stops the log
705 * window appearing in the task bar.
708 * 1 : hInstance = application's instance handle
710 * Returns : Handle to newly created window.
712 *********************************************************************/
713 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
715 static const char *szWndName = "JunkbusterLogLogOwner";
720 wc.lpfnWndProc = LogOwnerWindowProc;
723 wc.hInstance = hInstance;
726 wc.hbrBackground = 0;
728 wc.lpszClassName = szWndName;
732 hwnd = CreateWindow(szWndName, szWndName,
733 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
734 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
741 /*********************************************************************
743 * Function : LogOwnerWindowProc
745 * Description : Dummy procedure that does nothing special.
748 * 1 : hwnd = window handle
749 * 2 : uMsg = message number
750 * 3 : wParam = first param for this message
751 * 4 : lParam = next param for this message
753 * Returns : Same as `DefWindowProc'.
755 *********************************************************************/
756 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
758 return DefWindowProc(hwnd, uMsg, wParam, lParam);
763 /*********************************************************************
765 * Function : CreateLogWindow
767 * Description : Create the logging window.
770 * 1 : hInstance = application's instance handle
771 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
773 * Returns : Handle to newly created window.
775 *********************************************************************/
776 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
778 static const char *szWndName = "JunkbusterLogWindow";
779 static const char *szWndTitle = "Junkbuster";
782 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
783 HWND hwndChild = NULL;
787 memset(&wc, 0, sizeof(wc));
788 wc.cbSize = sizeof(wc);
789 wc.style = CS_DBLCLKS;
790 wc.lpfnWndProc = LogWindowProc;
793 wc.hInstance = hInstance;
794 wc.hIcon = g_hiconApp;
796 wc.hbrBackground = 0;
797 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
798 wc.lpszClassName = szWndName;
799 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
800 RegisterClassEx(&wc);
802 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
803 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
804 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
806 /* Now create a child list box */
807 GetClientRect(hwnd, &rcClient);
809 /* Create a rich edit control */
811 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
812 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
813 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
814 hwnd, NULL, hInstance, NULL);
815 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
817 /* Subclass the control to catch certain messages */
818 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
819 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
821 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
822 if (!g_bShowOnTaskBar &&
823 (nCmdShow == SW_SHOWMINIMIZED ||
824 nCmdShow == SW_MINIMIZE ||
825 nCmdShow == SW_SHOWMINNOACTIVE))
830 ShowWindow(hwnd, nCmdShow);
833 GetClientRect(g_hwndLogFrame, &rcClient);
834 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
841 /*********************************************************************
843 * Function : InitRichEdit
845 * Description : Initialise the rich edit control library.
849 * Returns : TRUE => success, FALSE => failure.
850 * FIXME: this is backwards to the rest of IJB and to common
851 * programming practice. Please use 0 => success instead.
853 *********************************************************************/
854 BOOL InitRichEdit(void)
856 static HINSTANCE hInstRichEdit;
857 if (hInstRichEdit == NULL)
859 g_nRichEditVersion = 0;
860 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
863 g_nRichEditVersion = _RICHEDIT_VER;
867 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
870 g_nRichEditVersion = 0x0100;
874 return (hInstRichEdit != NULL) ? TRUE : FALSE;
879 /*********************************************************************
881 * Function : ShowLogWindow
883 * Description : Shows or hides the log window. We will also raise the
884 * window on a show command in case it is buried.
887 * 1 : bShow = TRUE to show, FALSE to mimize/hide
891 *********************************************************************/
892 void ShowLogWindow(BOOL bShow)
896 SetForegroundWindow(g_hwndLogFrame);
897 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
899 else if (g_bShowOnTaskBar)
901 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
905 ShowWindow(g_hwndLogFrame, SW_HIDE);
911 /*********************************************************************
913 * Function : EditFile
915 * Description : Opens the specified setting file for editing.
918 * 1 : filename = filename from the config (aka junkbstr.txt) file.
922 *********************************************************************/
923 void EditFile(const char *filename)
927 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
933 /*--------------------------------------------------------------------------*/
934 /* Windows message handlers */
935 /*--------------------------------------------------------------------------*/
938 /*********************************************************************
940 * Function : OnLogRButtonUp
942 * Description : Handler for WM_RBUTTONUP messages.
945 * 1 : nModifier = wParam from mouse message (unused)
946 * 2 : x = x coordinate of the mouse event
947 * 3 : y = y coordinate of the mouse event
951 *********************************************************************/
952 void OnLogRButtonUp(int nModifier, int x, int y)
954 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
957 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
958 #ifdef WIN_GUI_EDIT
\r
960 #endif /* def WIN_GUI_EDIT */
\r
962 /* Check if there is a selection */
964 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
965 if (range.cpMin == range.cpMax)
967 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
971 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
974 #ifdef WIN_GUI_EDIT
\r
975 /* Check if cursor is over a link */
976 szURL = LogGetURLUnderCursor();
980 TCHAR szMenuItemTemplate[1000];
983 memset(&item, 0, sizeof(item));
984 item.cbSize = sizeof(item);
985 item.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
986 item.fType = MFT_STRING;
987 item.fState = MFS_ENABLED;
988 item.wID = ID_NEW_BLOCKER;
990 /* Put the item into the menu */
991 memset(szMenuItemTemplate, 0, sizeof(szMenuItemTemplate));
992 LoadString(g_hInstance, IDS_NEW_BLOCKER, szMenuItemTemplate, sizeof(szMenuItemTemplate) / sizeof(szMenuItemTemplate[0]));
994 szMenuItem = (char *)malloc(strlen(szMenuItemTemplate) + strlen(szURL) + 1);
995 sprintf(szMenuItem, szMenuItemTemplate, szURL);
997 item.dwTypeData = szMenuItem;
998 item.cch = strlen(szMenuItem);
1000 InsertMenuItem(hMenuPopup, 1, TRUE, &item);
1002 SetDefaultRule(szURL);
1006 #endif /* def WIN_GUI_EDIT */
\r
1008 /* Display the popup */
1009 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
1016 /*********************************************************************
1018 * Function : OnLogCommand
1020 * Description : Handler for WM_COMMAND messages.
1023 * 1 : nCommand = the command portion of the menu selection event
1027 *********************************************************************/
1028 void OnLogCommand(int nCommand)
1033 ShowLogWindow(TRUE);
1037 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1041 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1044 case ID_VIEW_CLEARLOG:
1045 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1048 case ID_VIEW_LOGMESSAGES:
1049 g_bLogMessages = !g_bLogMessages;
1050 /* SaveLogSettings(); */
1053 case ID_VIEW_MESSAGEHIGHLIGHTING:
1054 g_bHighlightMessages = !g_bHighlightMessages;
1055 /* SaveLogSettings(); */
1058 case ID_VIEW_LIMITBUFFERSIZE:
1059 g_bLimitBufferSize = !g_bLimitBufferSize;
1060 /* SaveLogSettings(); */
1063 case ID_VIEW_ACTIVITYANIMATION:
1064 g_bShowActivityAnimation = !g_bShowActivityAnimation;
1065 /* SaveLogSettings(); */
1069 /* by haroon - change toggle to its opposite value */
1071 g_bToggleIJB = !g_bToggleIJB;
1074 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1078 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1083 case ID_TOOLS_EDITJUNKBUSTER:
1084 EditFile(configfile);
1087 case ID_TOOLS_EDITPERMISSIONS:
1088 EditFile(g_permissions_file);
1091 case ID_TOOLS_EDITFORWARD:
1092 EditFile(g_forwardfile);
1096 case ID_TOOLS_EDITACLS:
1097 EditFile(g_aclfile);
1099 #endif /* def ACL_FILES */
1102 case ID_TOOLS_EDITPERLRE:
1103 EditFile(g_re_filterfile);
1108 case ID_TOOLS_EDITTRUST:
1109 EditFile(g_trustfile);
1111 #endif /* def TRUST_FILES */
1113 #ifdef WIN_GUI_EDIT
\r
1114 case ID_NEW_BLOCKER:
1115 ShowRulesDialog(g_hwndLogFrame);
1117 #endif /* def WIN_GUI_EDIT */
\r
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_EDITFORWARD, MF_BYCOMMAND | (g_forwardfile ? MF_ENABLED : MF_GRAYED));
1166 EnableMenuItem(hmenu, ID_TOOLS_EDITACLS, MF_BYCOMMAND | (g_aclfile ? MF_ENABLED : MF_GRAYED));
1167 #endif /* def ACL_FILES */
1169 EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1172 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1173 #endif /* def TRUST_FILES */
1175 /* Check/uncheck options */
1176 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1177 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1178 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1179 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1181 /* by haroon - menu item for Enable toggle on/off */
1182 CheckMenuItem(hmenu, ID_TOGGLE_IJB, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1188 /*********************************************************************
1190 * Function : OnLogTimer
1192 * Description : Handler for WM_TIMER messages.
1195 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1199 *********************************************************************/
1200 void OnLogTimer(int nTimer)
1205 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1208 case TIMER_ANIMSTOP_ID:
1210 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1211 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1212 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1215 case TIMER_CLIPBUFFER_ID:
1216 case TIMER_CLIPBUFFER_FORCE_ID:
1218 g_bClipPending = FALSE;
1219 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1220 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1231 /*********************************************************************
1233 * Function : LogRichEditProc
1235 * Description : Window subclass routine handles some events for the rich edit control.
1238 * 1 : hwnd = window handle of the rich edit control
1239 * 2 : uMsg = message number
1240 * 3 : wParam = first param for this message
1241 * 4 : lParam = next param for this message
1243 * Returns : Appropriate M$ window message handler codes.
1245 *********************************************************************/
1246 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1253 pt.x = LOWORD(lParam);
1254 pt.y = HIWORD(lParam);
1255 ClientToScreen(hwnd, &pt);
1256 OnLogRButtonUp(wParam, pt.x, pt.y);
1260 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1265 /*********************************************************************
1267 * Function : LogWindowProc
1269 * Description : Windows call back routine handles events on the log window.
1272 * 1 : hwnd = handle of the logging window
1273 * 2 : uMsg = message number
1274 * 3 : wParam = first param for this message
1275 * 4 : lParam = next param for this message
1277 * Returns : Appropriate M$ window message handler codes.
1279 *********************************************************************/
1280 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1288 /* This is the end - beautiful friend - the end */
1289 DestroyWindow(g_hwndLogBox);
1290 DestroyWindow(g_hwndLogFrame);
1299 /* Resize the logging window to fit the new frame */
1303 GetClientRect(g_hwndLogFrame, &rc);
1304 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1309 OnLogInitMenu((HMENU) wParam);
1317 OnLogCommand(LOWORD(wParam));
1324 if (g_bCloseHidesWindow)
1326 ShowLogWindow(FALSE);
1331 ShowLogWindow(FALSE);
1337 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1341 #endif /* ndef _WIN_CONSOLE - entire file */