1 const char w32log_rcs[] = "$Id: w32log.c,v 1.16 2001/08/01 19:58:12 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.16 2001/08/01 19:58:12 jongfoster
36 * Fixing documentation filenames in help menu, and making status
37 * option work without needing the "Junkbuster Status.URL" file.
39 * Revision 1.15 2001/07/30 22:08:36 jongfoster
40 * Tidying up #defines:
41 * - All feature #defines are now of the form FEATURE_xxx
42 * - Permanently turned off WIN_GUI_EDIT
43 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
45 * Revision 1.14 2001/07/29 18:47:05 jongfoster
46 * Adding missing #include "loadcfg.h"
48 * Revision 1.13 2001/07/19 19:15:14 haroon
49 * - Added a FIXME for EditFile but didn't fix :-)
51 * Revision 1.12 2001/07/13 14:04:59 oes
52 * Removed all #ifdef PCRS
54 * Revision 1.11 2001/06/07 23:08:12 jongfoster
55 * Forward and ACL edit options removed.
57 * Revision 1.10 2001/05/31 21:37:11 jongfoster
58 * GUI changes to rename "permissions file" to "actions file".
60 * Revision 1.9 2001/05/31 17:33:13 oes
64 * Revision 1.8 2001/05/29 09:50:24 jongfoster
65 * Unified blocklist/imagelist/permissionslist.
66 * File format is still under discussion, but the internal changes
69 * Also modified interceptor behaviour:
70 * - We now intercept all URLs beginning with one of the following
71 * prefixes (and *only* these prefixes):
73 * * http://ijbswa.sf.net/config/
74 * * http://ijbswa.sourceforge.net/config/
75 * - New interceptors "home page" - go to http://i.j.b/ to see it.
76 * - Internal changes so that intercepted and fast redirect pages
77 * are not replaced with an image.
78 * - Interceptors now have the option to send a binary page direct
79 * to the client. (i.e. ijb-send-banner uses this)
80 * - Implemented show-url-info interceptor. (Which is why I needed
81 * the above interceptors changes - a typical URL is
82 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
83 * The previous mechanism would not have intercepted that, and
84 * if it had been intercepted then it then it would have replaced
87 * Revision 1.7 2001/05/26 01:26:34 jongfoster
88 * New #define, WIN_GUI_EDIT, enables the (embryonic) Win32 GUI editor.
89 * This #define cannot be set from ./configure - there's no point, it
90 * doesn't work yet. See feature request # 425722
92 * Revision 1.6 2001/05/26 00:31:30 jongfoster
93 * Fixing compiler warning about comparing signed/unsigned.
95 * Revision 1.5 2001/05/26 00:28:36 jongfoster
96 * Automatic reloading of config file.
97 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
98 * Most of the global variables have been moved to a new
99 * struct configuration_spec, accessed through csp->config->globalname
100 * Most of the globals remaining are used by the Win32 GUI.
102 * Revision 1.4 2001/05/22 18:56:28 oes
105 * Revision 1.3 2001/05/20 15:07:54 jongfoster
106 * File is now ignored if _WIN_CONSOLE is defined.
108 * Revision 1.2 2001/05/20 01:21:20 jongfoster
109 * Version 2.9.4 checkin.
110 * - Merged popupfile and cookiefile, and added control over PCRS
111 * filtering, in new "permissionsfile".
112 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
113 * file error you now get a message box (in the Win32 GUI) rather
114 * than the program exiting with no explanation.
115 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
117 * - Removed tabs from "config"
118 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
119 * - Bumped up version number.
121 * Revision 1.1.1.1 2001/05/15 13:59:07 oes
122 * Initial import of version 2.9.3 source tree
125 *********************************************************************/
134 #include <richedit.h>
138 #include "w32taskbar.h"
142 #include "miscutil.h"
146 const char w32res_h_rcs[] = W32RES_H_VERSION;
150 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
153 const char w32log_h_rcs[] = W32LOG_H_VERSION;
155 #ifndef _WIN_CONSOLE /* entire file */
158 * Timers and the various durations
160 #define TIMER_ANIM_ID 1
161 #define TIMER_ANIM_TIME 100
162 #define TIMER_ANIMSTOP_ID 2
163 #define TIMER_ANIMSTOP_TIME 1000
164 #define TIMER_CLIPBUFFER_ID 3
165 #define TIMER_CLIPBUFFER_TIME 1000
166 #define TIMER_CLIPBUFFER_FORCE_ID 4
167 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
170 * Styles of text that can be output
173 #define STYLE_HIGHLIGHT 1
175 #define STYLE_HEADER 3
178 * Number of frames of animation in tray activity sequence
180 #define ANIM_FRAMES 8
182 #define DEFAULT_MAX_BUFFER_LINES 200
183 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
184 #define DEFAULT_LOG_FONT_SIZE 8
187 * These values affect the way the log window behaves, they should be read
188 * from a file but for the moment, they are hardcoded here. Some options are
189 * configurable through the UI.
192 /* Indicates whether task bar shows activity animation */
193 BOOL g_bShowActivityAnimation = 1;
195 /* Indicates if the log window appears on the task bar */
196 BOOL g_bShowOnTaskBar = 0;
198 /* Indicates whether closing the log window really just hides it */
199 BOOL g_bCloseHidesWindow = 1;
201 /* Indicates if messages are logged at all */
202 BOOL g_bLogMessages = 1;
204 /* Indicates whether log messages are highlighted */
205 BOOL g_bHighlightMessages = 1;
207 /* Indicates if buffer is limited in size */
208 BOOL g_bLimitBufferSize = 1;
210 /* Maximum number of lines allowed in buffer when limited */
211 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
214 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
216 /* Size of font to use */
217 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
220 /* FIXME: this is a kludge */
222 const char * g_actions_file = NULL;
223 const char * g_re_filterfile = NULL;
225 const char * g_trustfile = NULL;
226 #endif /* def FEATURE_TRUST */
228 /* FIXME: end kludge */
232 /* Regular expression for detected URLs */
233 #define RE_URL "http:[^ \n\r]*"
236 * Regular expressions that are used to perform highlight in the log window
238 static struct _Pattern
243 } patterns_to_highlight[] =
246 { RE_URL, STYLE_LINK },
247 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
248 /* interesting text to highlight */
249 { "crunch!", STYLE_HIGHLIGHT },
251 { "referer:", STYLE_HEADER },
252 { "proxy-connection:", STYLE_HEADER },
253 { "proxy-agent:", STYLE_HEADER },
254 { "user-agent:", STYLE_HEADER },
255 { "host:", STYLE_HEADER },
256 { "accept:", STYLE_HEADER },
257 { "accept-encoding:", STYLE_HEADER },
258 { "accept-language:", STYLE_HEADER },
259 { "accept-charset:", STYLE_HEADER },
260 { "accept-ranges:", STYLE_HEADER },
261 { "date:", STYLE_HEADER },
262 { "cache-control:", STYLE_HEADER },
263 { "cache-last-checked:", STYLE_HEADER },
264 { "connection:", STYLE_HEADER },
265 { "content-type", STYLE_HEADER },
266 { "content-length", STYLE_HEADER },
267 { "cookie", STYLE_HEADER },
268 { "last-modified:", STYLE_HEADER },
269 { "pragma:", STYLE_HEADER },
270 { "server:", STYLE_HEADER },
271 { "etag:", STYLE_HEADER },
272 { "expires:", STYLE_HEADER },
273 { "warning:", STYLE_HEADER },
274 /* this is the terminator statement - do not delete! */
277 #endif /* def REGEX */
288 static CRITICAL_SECTION g_criticalsection;
289 static HWND g_hwndTray;
290 static HWND g_hwndLogBox;
291 static WNDPROC g_fnLogBox;
292 static HICON g_hiconAnim[ANIM_FRAMES];
293 static HICON g_hiconIdle;
294 static HICON g_hiconApp;
295 static int g_nAnimFrame;
296 static BOOL g_bClipPending = FALSE;
297 static int g_nRichEditVersion = 0;
302 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
303 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
304 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
305 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
306 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
307 static BOOL InitRichEdit(void);
308 static void LogClipBuffer(void);
309 static void LogCreatePatternMatchingBuffers(void);
310 static void LogDestroyPatternMatchingBuffers(void);
311 static int LogPutStringNoMatch(const char *pszText, int style);
314 /*********************************************************************
316 * Function : InitLogWindow
318 * Description : Initialise the log window.
322 * Returns : Always TRUE (there should be error checking on the resources).
324 *********************************************************************/
325 BOOL InitLogWindow(void)
330 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
331 for (i = 0; i < ANIM_FRAMES; i++)
333 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER1 + i));
335 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER));
337 /* Create the user interface */
338 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
339 g_hwndTray = CreateTrayWindow(g_hInstance);
340 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Junkbuster");
342 /* Create pattern matching buffers (for highlighting */
343 LogCreatePatternMatchingBuffers();
345 /* Create a critical section to protect multi-threaded access to certain things */
346 InitializeCriticalSection(&g_criticalsection);
353 /*********************************************************************
355 * Function : TermLogWindow
357 * Description : Cleanup the logwindow.
363 *********************************************************************/
364 void TermLogWindow(void)
368 LogDestroyPatternMatchingBuffers();
370 TrayDeleteIcon(g_hwndTray, 1);
371 DeleteObject(g_hiconApp);
372 DeleteObject(g_hiconIdle);
373 for (i = 0; i < ANIM_FRAMES; i++)
375 DeleteObject(g_hiconAnim[i]);
381 /*********************************************************************
383 * Function : LogCreatePatternMatchingBuffers
385 * Description : Compile the pattern matching buffers.
391 *********************************************************************/
392 void LogCreatePatternMatchingBuffers(void)
396 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
398 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
405 /*********************************************************************
407 * Function : LogDestroyPatternMatchingBuffers
409 * Description : Free up the pattern matching buffers.
415 *********************************************************************/
416 void LogDestroyPatternMatchingBuffers(void)
420 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
422 regfree(&patterns_to_highlight[i].buffer);
429 /*********************************************************************
431 * Function : LogGetURLUnderCursor
433 * Description : Returns the URL from under the cursor (remember to free it!).
437 * Returns : NULL or a pointer to an URL string.
439 *********************************************************************/
440 char *LogGetURLUnderCursor(void)
442 char *szResult = NULL;
448 DWORD nWordStart = 0;
451 regcomp(&re, RE_URL, REG_ICASE);
453 /* Get the position of the cursor over the text window */
454 GetCursorPos(&ptCursor);
455 ScreenToClient(g_hwndLogBox, &ptCursor);
459 /* Search backwards and fowards to obtain the word that is highlighted */
460 nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
461 nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
462 nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
464 /* Compare the string to the pattern */
465 if (nWordEnd > nWordStart)
470 range.chrg.cpMin = nWordStart;
471 range.chrg.cpMax = nWordEnd;
472 range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
473 SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
475 if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
477 szResult = range.lpstrText;
481 free(range.lpstrText);
492 /*********************************************************************
494 * Function : LogPutString
496 * Description : Inserts text into the logging window. This is really
497 * a REGEXP aware wrapper function to `LogPutStringNoMatch'.
500 * 1 : pszText = pointer to string going to the log window
502 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
503 * FIXME: this is backwards to the rest of IJB and to common
504 * programming practice. Please use 0 => success instead.
506 *********************************************************************/
507 int LogPutString(const char *pszText)
514 if (pszText == NULL || strlen(pszText) == 0)
524 /* Critical section stops multiple threads doing nasty interactions that
525 * foul up the highlighting and output.
527 EnterCriticalSection(&g_criticalsection);
530 if (g_bHighlightMessages)
534 /* First things first, regexp scan for various things that we would like highlighted */
535 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
537 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
539 char *pszBefore = NULL;
540 char *pszMatch = NULL;
541 char *pszAfter = NULL;
544 /* Split the string up into pieces representing the strings, before
545 at and after the matching pattern
549 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
550 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
551 strncpy(pszBefore, pszText, match.rm_so);
553 if (match.rm_eo < (regoff_t)strlen(pszText))
555 pszAfter = strdup(&pszText[match.rm_eo]);
557 nMatchSize = match.rm_eo - match.rm_so;
558 pszMatch = (char *)malloc(nMatchSize + 1);
559 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
560 pszMatch[nMatchSize] = '\0';
562 /* Recursively call LogPutString */
565 LogPutString(pszBefore);
570 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
575 LogPutString(pszAfter);
586 result = LogPutStringNoMatch(pszText, STYLE_NONE);
591 LeaveCriticalSection(&g_criticalsection);
598 /*********************************************************************
600 * Function : LogPutStringNoMatch
602 * Description : Puts a string into the logging window.
605 * 1 : pszText = pointer to string going to the log window
606 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
608 * Returns : Always 1 => success.
609 * FIXME: this is backwards to the rest of IJB and to common
610 * programming practice. Please use 0 => success instead.
612 *********************************************************************/
613 int LogPutStringNoMatch(const char *pszText, int style)
619 assert(g_hwndLogBox);
620 if (g_hwndLogBox == NULL)
625 /* TODO preserve existing selection */
627 /* Go to the end of the text */
628 nTextLength = GetWindowTextLength(g_hwndLogBox);
629 range.cpMin = nTextLength;
630 range.cpMax = nTextLength;
631 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
633 /* Apply a formatting style */
634 memset(&format, 0, sizeof(format));
635 format.cbSize = sizeof(format);
636 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
637 format.yHeight = (g_nFontSize * 1440) / 72;
638 strcpy(format.szFaceName, g_szFontFaceName);
639 if (style == STYLE_NONE)
642 format.dwEffects |= CFE_AUTOCOLOR;
644 else if (style == STYLE_HEADER)
646 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
648 else if (style == STYLE_HIGHLIGHT)
650 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
652 else if (style == STYLE_LINK)
654 format.dwEffects |= CFE_UNDERLINE;
655 format.crTextColor = RGB(0, 0, 255);
657 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
659 /* Append text to the end */
660 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
662 /* TODO Restore the old selection */
665 if (strchr(pszText, '\n') != NULL)
667 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
670 /* Set the force clip timer going. This timer ensures clipping is done
671 intermittently even when there is a sustained burst of logging
673 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
675 g_bClipPending = TRUE;
683 /*********************************************************************
685 * Function : LogShowActivity
687 * Description : Start the spinner.
693 *********************************************************************/
694 void LogShowActivity(void)
696 /* Start some activity timers */
697 if (g_bShowActivityAnimation)
699 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
700 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
706 /*********************************************************************
708 * Function : LogClipBuffer
710 * Description : Prunes old lines from the log.
716 *********************************************************************/
717 void LogClipBuffer(void)
719 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
720 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
722 /* Compute the range representing the lines to be deleted */
723 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
724 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
727 range.cpMax = nLastChar;
729 /* TODO get current selection */
731 /* TODO adjust and clip old selection against range to be deleted */
733 /* Select range and erase it (turning off autoscroll to prevent
735 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
736 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
737 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
738 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
740 /* Restore old selection */
746 /*********************************************************************
748 * Function : CreateHiddenLogOwnerWindow
750 * Description : Creates a hidden owner window that stops the log
751 * window appearing in the task bar.
754 * 1 : hInstance = application's instance handle
756 * Returns : Handle to newly created window.
758 *********************************************************************/
759 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
761 static const char *szWndName = "JunkbusterLogLogOwner";
766 wc.lpfnWndProc = LogOwnerWindowProc;
769 wc.hInstance = hInstance;
772 wc.hbrBackground = 0;
774 wc.lpszClassName = szWndName;
778 hwnd = CreateWindow(szWndName, szWndName,
779 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
780 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
787 /*********************************************************************
789 * Function : LogOwnerWindowProc
791 * Description : Dummy procedure that does nothing special.
794 * 1 : hwnd = window handle
795 * 2 : uMsg = message number
796 * 3 : wParam = first param for this message
797 * 4 : lParam = next param for this message
799 * Returns : Same as `DefWindowProc'.
801 *********************************************************************/
802 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
804 return DefWindowProc(hwnd, uMsg, wParam, lParam);
809 /*********************************************************************
811 * Function : CreateLogWindow
813 * Description : Create the logging window.
816 * 1 : hInstance = application's instance handle
817 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
819 * Returns : Handle to newly created window.
821 *********************************************************************/
822 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
824 static const char *szWndName = "JunkbusterLogWindow";
825 static const char *szWndTitle = "Junkbuster";
828 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
832 memset(&wc, 0, sizeof(wc));
833 wc.cbSize = sizeof(wc);
834 wc.style = CS_DBLCLKS;
835 wc.lpfnWndProc = LogWindowProc;
838 wc.hInstance = hInstance;
839 wc.hIcon = g_hiconApp;
841 wc.hbrBackground = 0;
842 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
843 wc.lpszClassName = szWndName;
844 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
845 RegisterClassEx(&wc);
847 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
848 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
849 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
851 /* Now create a child list box */
852 GetClientRect(hwnd, &rcClient);
854 /* Create a rich edit control */
856 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
857 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
858 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
859 hwnd, NULL, hInstance, NULL);
860 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
862 /* Subclass the control to catch certain messages */
863 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
864 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
866 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
867 if (!g_bShowOnTaskBar &&
868 (nCmdShow == SW_SHOWMINIMIZED ||
869 nCmdShow == SW_MINIMIZE ||
870 nCmdShow == SW_SHOWMINNOACTIVE))
875 ShowWindow(hwnd, nCmdShow);
878 GetClientRect(g_hwndLogFrame, &rcClient);
879 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
886 /*********************************************************************
888 * Function : InitRichEdit
890 * Description : Initialise the rich edit control library.
894 * Returns : TRUE => success, FALSE => failure.
895 * FIXME: this is backwards to the rest of IJB and to common
896 * programming practice. Please use 0 => success instead.
898 *********************************************************************/
899 BOOL InitRichEdit(void)
901 static HINSTANCE hInstRichEdit;
902 if (hInstRichEdit == NULL)
904 g_nRichEditVersion = 0;
905 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
908 g_nRichEditVersion = _RICHEDIT_VER;
912 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
915 g_nRichEditVersion = 0x0100;
919 return (hInstRichEdit != NULL) ? TRUE : FALSE;
924 /*********************************************************************
926 * Function : ShowLogWindow
928 * Description : Shows or hides the log window. We will also raise the
929 * window on a show command in case it is buried.
932 * 1 : bShow = TRUE to show, FALSE to mimize/hide
936 *********************************************************************/
937 void ShowLogWindow(BOOL bShow)
941 SetForegroundWindow(g_hwndLogFrame);
942 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
944 else if (g_bShowOnTaskBar)
946 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
950 ShowWindow(g_hwndLogFrame, SW_HIDE);
956 /*********************************************************************
958 * Function : EditFile
960 * Description : Opens the specified setting file for editing.
961 * FIXME: What if the file has no associated application. Check for return values
962 * from ShellExecute??
965 * 1 : filename = filename from the config (aka junkbstr.txt) file.
969 *********************************************************************/
970 void EditFile(const char *filename)
974 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
980 /*--------------------------------------------------------------------------*/
981 /* Windows message handlers */
982 /*--------------------------------------------------------------------------*/
985 /*********************************************************************
987 * Function : OnLogRButtonUp
989 * Description : Handler for WM_RBUTTONUP messages.
992 * 1 : nModifier = wParam from mouse message (unused)
993 * 2 : x = x coordinate of the mouse event
994 * 3 : y = y coordinate of the mouse event
998 *********************************************************************/
999 void OnLogRButtonUp(int nModifier, int x, int y)
1001 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
1004 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
1006 /* Check if there is a selection */
1008 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
1009 if (range.cpMin == range.cpMax)
1011 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
1015 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
1018 /* Display the popup */
1019 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
1026 /*********************************************************************
1028 * Function : OnLogCommand
1030 * Description : Handler for WM_COMMAND messages.
1033 * 1 : nCommand = the command portion of the menu selection event
1037 *********************************************************************/
1038 void OnLogCommand(int nCommand)
1043 ShowLogWindow(TRUE);
1047 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1051 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1054 case ID_VIEW_CLEARLOG:
1055 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1058 case ID_VIEW_LOGMESSAGES:
1059 g_bLogMessages = !g_bLogMessages;
1060 /* SaveLogSettings(); */
1063 case ID_VIEW_MESSAGEHIGHLIGHTING:
1064 g_bHighlightMessages = !g_bHighlightMessages;
1065 /* SaveLogSettings(); */
1068 case ID_VIEW_LIMITBUFFERSIZE:
1069 g_bLimitBufferSize = !g_bLimitBufferSize;
1070 /* SaveLogSettings(); */
1073 case ID_VIEW_ACTIVITYANIMATION:
1074 g_bShowActivityAnimation = !g_bShowActivityAnimation;
1075 /* SaveLogSettings(); */
1078 #ifdef FEATURE_TOGGLE
1079 /* by haroon - change toggle to its opposite value */
1081 g_bToggleIJB = !g_bToggleIJB;
1084 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1088 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1091 #endif /* def FEATURE_TOGGLE */
1093 case ID_TOOLS_EDITJUNKBUSTER:
1094 EditFile(configfile);
1097 case ID_TOOLS_EDITACTIONS:
1098 EditFile(g_actions_file);
1101 case ID_TOOLS_EDITPERLRE:
1102 EditFile(g_re_filterfile);
1105 #ifdef FEATURE_TRUST
1106 case ID_TOOLS_EDITTRUST:
1107 EditFile(g_trustfile);
1109 #endif /* def FEATURE_TRUST */
1112 ShellExecute(g_hwndLogFrame, "open", "doc/gpl.html", NULL, NULL, SW_SHOWNORMAL);
1116 ShellExecute(g_hwndLogFrame, "open", "doc/ijbfaq.html", NULL, NULL, SW_SHOWNORMAL);
1119 case ID_HELP_MANUAL:
1120 ShellExecute(g_hwndLogFrame, "open", "doc/ijbman.html", NULL, NULL, SW_SHOWNORMAL);
1123 case ID_HELP_STATUS:
1124 ShellExecute(g_hwndLogFrame, "open", HOME_PAGE_URL "/config/show-status", NULL, NULL, SW_SHOWNORMAL);
1127 case ID_HELP_ABOUTJUNKBUSTER:
1128 MessageBox(g_hwndLogFrame, win32_blurb, "Junkbuster Information", MB_OK);
1139 /*********************************************************************
1141 * Function : OnLogInitMenu
1143 * Description : Handler for WM_INITMENU messages. Enable, disable,
1144 * check, and/or uncheck menu options as apropos.
1147 * 1 : hmenu = handle to menu to "make current"
1151 *********************************************************************/
1152 void OnLogInitMenu(HMENU hmenu)
1154 /* Only enable editors if there is a file to edit */
1155 EnableMenuItem(hmenu, ID_TOOLS_EDITACTIONS, MF_BYCOMMAND | (g_actions_file ? MF_ENABLED : MF_GRAYED));
1156 EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1157 #ifdef FEATURE_TRUST
1158 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1159 #endif /* def FEATURE_TRUST */
1161 /* Check/uncheck options */
1162 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1163 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1164 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1165 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1166 #ifdef FEATURE_TOGGLE
1167 /* by haroon - menu item for Enable toggle on/off */
1168 CheckMenuItem(hmenu, ID_TOGGLE_IJB, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1169 #endif /* def FEATURE_TOGGLE */
1174 /*********************************************************************
1176 * Function : OnLogTimer
1178 * Description : Handler for WM_TIMER messages.
1181 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1185 *********************************************************************/
1186 void OnLogTimer(int nTimer)
1191 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1194 case TIMER_ANIMSTOP_ID:
1196 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1197 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1198 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1201 case TIMER_CLIPBUFFER_ID:
1202 case TIMER_CLIPBUFFER_FORCE_ID:
1204 g_bClipPending = FALSE;
1205 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1206 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1217 /*********************************************************************
1219 * Function : LogRichEditProc
1221 * Description : Window subclass routine handles some events for the rich edit control.
1224 * 1 : hwnd = window handle of the rich edit control
1225 * 2 : uMsg = message number
1226 * 3 : wParam = first param for this message
1227 * 4 : lParam = next param for this message
1229 * Returns : Appropriate M$ window message handler codes.
1231 *********************************************************************/
1232 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1239 pt.x = LOWORD(lParam);
1240 pt.y = HIWORD(lParam);
1241 ClientToScreen(hwnd, &pt);
1242 OnLogRButtonUp(wParam, pt.x, pt.y);
1246 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1251 /*********************************************************************
1253 * Function : LogWindowProc
1255 * Description : Windows call back routine handles events on the log window.
1258 * 1 : hwnd = handle of the logging window
1259 * 2 : uMsg = message number
1260 * 3 : wParam = first param for this message
1261 * 4 : lParam = next param for this message
1263 * Returns : Appropriate M$ window message handler codes.
1265 *********************************************************************/
1266 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1274 /* This is the end - beautiful friend - the end */
1275 DestroyWindow(g_hwndLogBox);
1276 DestroyWindow(g_hwndLogFrame);
1285 /* Resize the logging window to fit the new frame */
1289 GetClientRect(g_hwndLogFrame, &rc);
1290 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1295 OnLogInitMenu((HMENU) wParam);
1303 OnLogCommand(LOWORD(wParam));
1310 if (g_bCloseHidesWindow)
1312 ShowLogWindow(FALSE);
1317 ShowLogWindow(FALSE);
1323 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1327 #endif /* ndef _WIN_CONSOLE - entire file */