1 const char w32log_rcs[] = "$Id: w32log.c,v 1.14 2001/07/29 18:47:05 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.14 2001/07/29 18:47:05 jongfoster
36 * Adding missing #include "loadcfg.h"
38 * Revision 1.13 2001/07/19 19:15:14 haroon
39 * - Added a FIXME for EditFile but didn't fix :-)
41 * Revision 1.12 2001/07/13 14:04:59 oes
42 * Removed all #ifdef PCRS
44 * Revision 1.11 2001/06/07 23:08:12 jongfoster
45 * Forward and ACL edit options removed.
47 * Revision 1.10 2001/05/31 21:37:11 jongfoster
48 * GUI changes to rename "permissions file" to "actions file".
50 * Revision 1.9 2001/05/31 17:33:13 oes
54 * Revision 1.8 2001/05/29 09:50:24 jongfoster
55 * Unified blocklist/imagelist/permissionslist.
56 * File format is still under discussion, but the internal changes
59 * Also modified interceptor behaviour:
60 * - We now intercept all URLs beginning with one of the following
61 * prefixes (and *only* these prefixes):
63 * * http://ijbswa.sf.net/config/
64 * * http://ijbswa.sourceforge.net/config/
65 * - New interceptors "home page" - go to http://i.j.b/ to see it.
66 * - Internal changes so that intercepted and fast redirect pages
67 * are not replaced with an image.
68 * - Interceptors now have the option to send a binary page direct
69 * to the client. (i.e. ijb-send-banner uses this)
70 * - Implemented show-url-info interceptor. (Which is why I needed
71 * the above interceptors changes - a typical URL is
72 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
73 * The previous mechanism would not have intercepted that, and
74 * if it had been intercepted then it then it would have replaced
77 * Revision 1.7 2001/05/26 01:26:34 jongfoster
78 * New #define, WIN_GUI_EDIT, enables the (embryonic) Win32 GUI editor.
79 * This #define cannot be set from ./configure - there's no point, it
80 * doesn't work yet. See feature request # 425722
82 * Revision 1.6 2001/05/26 00:31:30 jongfoster
83 * Fixing compiler warning about comparing signed/unsigned.
85 * Revision 1.5 2001/05/26 00:28:36 jongfoster
86 * Automatic reloading of config file.
87 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
88 * Most of the global variables have been moved to a new
89 * struct configuration_spec, accessed through csp->config->globalname
90 * Most of the globals remaining are used by the Win32 GUI.
92 * Revision 1.4 2001/05/22 18:56:28 oes
95 * Revision 1.3 2001/05/20 15:07:54 jongfoster
96 * File is now ignored if _WIN_CONSOLE is defined.
98 * Revision 1.2 2001/05/20 01:21:20 jongfoster
99 * Version 2.9.4 checkin.
100 * - Merged popupfile and cookiefile, and added control over PCRS
101 * filtering, in new "permissionsfile".
102 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
103 * file error you now get a message box (in the Win32 GUI) rather
104 * than the program exiting with no explanation.
105 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
107 * - Removed tabs from "config"
108 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
109 * - Bumped up version number.
111 * Revision 1.1.1.1 2001/05/15 13:59:07 oes
112 * Initial import of version 2.9.3 source tree
115 *********************************************************************/
124 #include <richedit.h>
128 #include "w32taskbar.h"
132 #include "miscutil.h"
136 const char w32res_h_rcs[] = W32RES_H_VERSION;
140 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
143 const char w32log_h_rcs[] = W32LOG_H_VERSION;
145 #ifndef _WIN_CONSOLE /* entire file */
148 * Timers and the various durations
150 #define TIMER_ANIM_ID 1
151 #define TIMER_ANIM_TIME 100
152 #define TIMER_ANIMSTOP_ID 2
153 #define TIMER_ANIMSTOP_TIME 1000
154 #define TIMER_CLIPBUFFER_ID 3
155 #define TIMER_CLIPBUFFER_TIME 1000
156 #define TIMER_CLIPBUFFER_FORCE_ID 4
157 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
160 * Styles of text that can be output
163 #define STYLE_HIGHLIGHT 1
165 #define STYLE_HEADER 3
168 * Number of frames of animation in tray activity sequence
170 #define ANIM_FRAMES 8
172 #define DEFAULT_MAX_BUFFER_LINES 200
173 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
174 #define DEFAULT_LOG_FONT_SIZE 8
177 * These values affect the way the log window behaves, they should be read
178 * from a file but for the moment, they are hardcoded here. Some options are
179 * configurable through the UI.
182 /* Indicates whether task bar shows activity animation */
183 BOOL g_bShowActivityAnimation = 1;
185 /* Indicates if the log window appears on the task bar */
186 BOOL g_bShowOnTaskBar = 0;
188 /* Indicates whether closing the log window really just hides it */
189 BOOL g_bCloseHidesWindow = 1;
191 /* Indicates if messages are logged at all */
192 BOOL g_bLogMessages = 1;
194 /* Indicates whether log messages are highlighted */
195 BOOL g_bHighlightMessages = 1;
197 /* Indicates if buffer is limited in size */
198 BOOL g_bLimitBufferSize = 1;
200 /* Maximum number of lines allowed in buffer when limited */
201 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
204 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
206 /* Size of font to use */
207 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
210 /* FIXME: this is a kludge */
212 const char * g_actions_file = NULL;
213 const char * g_re_filterfile = NULL;
215 const char * g_trustfile = NULL;
216 #endif /* def FEATURE_TRUST */
218 /* FIXME: end kludge */
222 /* Regular expression for detected URLs */
223 #define RE_URL "http:[^ \n\r]*"
226 * Regular expressions that are used to perform highlight in the log window
228 static struct _Pattern
233 } patterns_to_highlight[] =
236 { RE_URL, STYLE_LINK },
237 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
238 /* interesting text to highlight */
239 { "crunch!", STYLE_HIGHLIGHT },
241 { "referer:", STYLE_HEADER },
242 { "proxy-connection:", STYLE_HEADER },
243 { "proxy-agent:", STYLE_HEADER },
244 { "user-agent:", STYLE_HEADER },
245 { "host:", STYLE_HEADER },
246 { "accept:", STYLE_HEADER },
247 { "accept-encoding:", STYLE_HEADER },
248 { "accept-language:", STYLE_HEADER },
249 { "accept-charset:", STYLE_HEADER },
250 { "accept-ranges:", STYLE_HEADER },
251 { "date:", STYLE_HEADER },
252 { "cache-control:", STYLE_HEADER },
253 { "cache-last-checked:", STYLE_HEADER },
254 { "connection:", STYLE_HEADER },
255 { "content-type", STYLE_HEADER },
256 { "content-length", STYLE_HEADER },
257 { "cookie", STYLE_HEADER },
258 { "last-modified:", STYLE_HEADER },
259 { "pragma:", STYLE_HEADER },
260 { "server:", STYLE_HEADER },
261 { "etag:", STYLE_HEADER },
262 { "expires:", STYLE_HEADER },
263 { "warning:", STYLE_HEADER },
264 /* this is the terminator statement - do not delete! */
267 #endif /* def REGEX */
278 static CRITICAL_SECTION g_criticalsection;
279 static HWND g_hwndTray;
280 static HWND g_hwndLogBox;
281 static WNDPROC g_fnLogBox;
282 static HICON g_hiconAnim[ANIM_FRAMES];
283 static HICON g_hiconIdle;
284 static HICON g_hiconApp;
285 static int g_nAnimFrame;
286 static BOOL g_bClipPending = FALSE;
287 static int g_nRichEditVersion = 0;
292 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
293 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
294 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
295 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
296 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
297 static BOOL InitRichEdit(void);
298 static void LogClipBuffer(void);
299 static void LogCreatePatternMatchingBuffers(void);
300 static void LogDestroyPatternMatchingBuffers(void);
301 static int LogPutStringNoMatch(const char *pszText, int style);
304 /*********************************************************************
306 * Function : InitLogWindow
308 * Description : Initialise the log window.
312 * Returns : Always TRUE (there should be error checking on the resources).
314 *********************************************************************/
315 BOOL InitLogWindow(void)
320 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
321 for (i = 0; i < ANIM_FRAMES; i++)
323 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER1 + i));
325 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER));
327 /* Create the user interface */
328 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
329 g_hwndTray = CreateTrayWindow(g_hInstance);
330 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Junkbuster");
332 /* Create pattern matching buffers (for highlighting */
333 LogCreatePatternMatchingBuffers();
335 /* Create a critical section to protect multi-threaded access to certain things */
336 InitializeCriticalSection(&g_criticalsection);
343 /*********************************************************************
345 * Function : TermLogWindow
347 * Description : Cleanup the logwindow.
353 *********************************************************************/
354 void TermLogWindow(void)
358 LogDestroyPatternMatchingBuffers();
360 TrayDeleteIcon(g_hwndTray, 1);
361 DeleteObject(g_hiconApp);
362 DeleteObject(g_hiconIdle);
363 for (i = 0; i < ANIM_FRAMES; i++)
365 DeleteObject(g_hiconAnim[i]);
371 /*********************************************************************
373 * Function : LogCreatePatternMatchingBuffers
375 * Description : Compile the pattern matching buffers.
381 *********************************************************************/
382 void LogCreatePatternMatchingBuffers(void)
386 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
388 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
395 /*********************************************************************
397 * Function : LogDestroyPatternMatchingBuffers
399 * Description : Free up the pattern matching buffers.
405 *********************************************************************/
406 void LogDestroyPatternMatchingBuffers(void)
410 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
412 regfree(&patterns_to_highlight[i].buffer);
419 /*********************************************************************
421 * Function : LogGetURLUnderCursor
423 * Description : Returns the URL from under the cursor (remember to free it!).
427 * Returns : NULL or a pointer to an URL string.
429 *********************************************************************/
430 char *LogGetURLUnderCursor(void)
432 char *szResult = NULL;
438 DWORD nWordStart = 0;
441 regcomp(&re, RE_URL, REG_ICASE);
443 /* Get the position of the cursor over the text window */
444 GetCursorPos(&ptCursor);
445 ScreenToClient(g_hwndLogBox, &ptCursor);
449 /* Search backwards and fowards to obtain the word that is highlighted */
450 nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
451 nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
452 nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
454 /* Compare the string to the pattern */
455 if (nWordEnd > nWordStart)
460 range.chrg.cpMin = nWordStart;
461 range.chrg.cpMax = nWordEnd;
462 range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
463 SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
465 if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
467 szResult = range.lpstrText;
471 free(range.lpstrText);
482 /*********************************************************************
484 * Function : LogPutString
486 * Description : Inserts text into the logging window. This is really
487 * a REGEXP aware wrapper function to `LogPutStringNoMatch'.
490 * 1 : pszText = pointer to string going to the log window
492 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
493 * FIXME: this is backwards to the rest of IJB and to common
494 * programming practice. Please use 0 => success instead.
496 *********************************************************************/
497 int LogPutString(const char *pszText)
504 if (pszText == NULL || strlen(pszText) == 0)
514 /* Critical section stops multiple threads doing nasty interactions that
515 * foul up the highlighting and output.
517 EnterCriticalSection(&g_criticalsection);
520 if (g_bHighlightMessages)
524 /* First things first, regexp scan for various things that we would like highlighted */
525 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
527 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
529 char *pszBefore = NULL;
530 char *pszMatch = NULL;
531 char *pszAfter = NULL;
534 /* Split the string up into pieces representing the strings, before
535 at and after the matching pattern
539 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
540 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
541 strncpy(pszBefore, pszText, match.rm_so);
543 if (match.rm_eo < (regoff_t)strlen(pszText))
545 pszAfter = strdup(&pszText[match.rm_eo]);
547 nMatchSize = match.rm_eo - match.rm_so;
548 pszMatch = (char *)malloc(nMatchSize + 1);
549 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
550 pszMatch[nMatchSize] = '\0';
552 /* Recursively call LogPutString */
555 LogPutString(pszBefore);
560 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
565 LogPutString(pszAfter);
576 result = LogPutStringNoMatch(pszText, STYLE_NONE);
581 LeaveCriticalSection(&g_criticalsection);
588 /*********************************************************************
590 * Function : LogPutStringNoMatch
592 * Description : Puts a string into the logging window.
595 * 1 : pszText = pointer to string going to the log window
596 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
598 * Returns : Always 1 => success.
599 * FIXME: this is backwards to the rest of IJB and to common
600 * programming practice. Please use 0 => success instead.
602 *********************************************************************/
603 int LogPutStringNoMatch(const char *pszText, int style)
609 assert(g_hwndLogBox);
610 if (g_hwndLogBox == NULL)
615 /* TODO preserve existing selection */
617 /* Go to the end of the text */
618 nTextLength = GetWindowTextLength(g_hwndLogBox);
619 range.cpMin = nTextLength;
620 range.cpMax = nTextLength;
621 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
623 /* Apply a formatting style */
624 memset(&format, 0, sizeof(format));
625 format.cbSize = sizeof(format);
626 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
627 format.yHeight = (g_nFontSize * 1440) / 72;
628 strcpy(format.szFaceName, g_szFontFaceName);
629 if (style == STYLE_NONE)
632 format.dwEffects |= CFE_AUTOCOLOR;
634 else if (style == STYLE_HEADER)
636 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
638 else if (style == STYLE_HIGHLIGHT)
640 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
642 else if (style == STYLE_LINK)
644 format.dwEffects |= CFE_UNDERLINE;
645 format.crTextColor = RGB(0, 0, 255);
647 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
649 /* Append text to the end */
650 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
652 /* TODO Restore the old selection */
655 if (strchr(pszText, '\n') != NULL)
657 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
660 /* Set the force clip timer going. This timer ensures clipping is done
661 intermittently even when there is a sustained burst of logging
663 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
665 g_bClipPending = TRUE;
673 /*********************************************************************
675 * Function : LogShowActivity
677 * Description : Start the spinner.
683 *********************************************************************/
684 void LogShowActivity(void)
686 /* Start some activity timers */
687 if (g_bShowActivityAnimation)
689 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
690 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
696 /*********************************************************************
698 * Function : LogClipBuffer
700 * Description : Prunes old lines from the log.
706 *********************************************************************/
707 void LogClipBuffer(void)
709 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
710 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
712 /* Compute the range representing the lines to be deleted */
713 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
714 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
717 range.cpMax = nLastChar;
719 /* TODO get current selection */
721 /* TODO adjust and clip old selection against range to be deleted */
723 /* Select range and erase it (turning off autoscroll to prevent
725 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
726 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
727 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
728 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
730 /* Restore old selection */
736 /*********************************************************************
738 * Function : CreateHiddenLogOwnerWindow
740 * Description : Creates a hidden owner window that stops the log
741 * window appearing in the task bar.
744 * 1 : hInstance = application's instance handle
746 * Returns : Handle to newly created window.
748 *********************************************************************/
749 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
751 static const char *szWndName = "JunkbusterLogLogOwner";
756 wc.lpfnWndProc = LogOwnerWindowProc;
759 wc.hInstance = hInstance;
762 wc.hbrBackground = 0;
764 wc.lpszClassName = szWndName;
768 hwnd = CreateWindow(szWndName, szWndName,
769 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
770 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
777 /*********************************************************************
779 * Function : LogOwnerWindowProc
781 * Description : Dummy procedure that does nothing special.
784 * 1 : hwnd = window handle
785 * 2 : uMsg = message number
786 * 3 : wParam = first param for this message
787 * 4 : lParam = next param for this message
789 * Returns : Same as `DefWindowProc'.
791 *********************************************************************/
792 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
794 return DefWindowProc(hwnd, uMsg, wParam, lParam);
799 /*********************************************************************
801 * Function : CreateLogWindow
803 * Description : Create the logging window.
806 * 1 : hInstance = application's instance handle
807 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
809 * Returns : Handle to newly created window.
811 *********************************************************************/
812 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
814 static const char *szWndName = "JunkbusterLogWindow";
815 static const char *szWndTitle = "Junkbuster";
818 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
819 HWND hwndChild = NULL;
823 memset(&wc, 0, sizeof(wc));
824 wc.cbSize = sizeof(wc);
825 wc.style = CS_DBLCLKS;
826 wc.lpfnWndProc = LogWindowProc;
829 wc.hInstance = hInstance;
830 wc.hIcon = g_hiconApp;
832 wc.hbrBackground = 0;
833 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
834 wc.lpszClassName = szWndName;
835 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
836 RegisterClassEx(&wc);
838 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
839 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
840 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
842 /* Now create a child list box */
843 GetClientRect(hwnd, &rcClient);
845 /* Create a rich edit control */
847 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
848 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
849 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
850 hwnd, NULL, hInstance, NULL);
851 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
853 /* Subclass the control to catch certain messages */
854 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
855 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
857 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
858 if (!g_bShowOnTaskBar &&
859 (nCmdShow == SW_SHOWMINIMIZED ||
860 nCmdShow == SW_MINIMIZE ||
861 nCmdShow == SW_SHOWMINNOACTIVE))
866 ShowWindow(hwnd, nCmdShow);
869 GetClientRect(g_hwndLogFrame, &rcClient);
870 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
877 /*********************************************************************
879 * Function : InitRichEdit
881 * Description : Initialise the rich edit control library.
885 * Returns : TRUE => success, FALSE => failure.
886 * FIXME: this is backwards to the rest of IJB and to common
887 * programming practice. Please use 0 => success instead.
889 *********************************************************************/
890 BOOL InitRichEdit(void)
892 static HINSTANCE hInstRichEdit;
893 if (hInstRichEdit == NULL)
895 g_nRichEditVersion = 0;
896 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
899 g_nRichEditVersion = _RICHEDIT_VER;
903 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
906 g_nRichEditVersion = 0x0100;
910 return (hInstRichEdit != NULL) ? TRUE : FALSE;
915 /*********************************************************************
917 * Function : ShowLogWindow
919 * Description : Shows or hides the log window. We will also raise the
920 * window on a show command in case it is buried.
923 * 1 : bShow = TRUE to show, FALSE to mimize/hide
927 *********************************************************************/
928 void ShowLogWindow(BOOL bShow)
932 SetForegroundWindow(g_hwndLogFrame);
933 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
935 else if (g_bShowOnTaskBar)
937 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
941 ShowWindow(g_hwndLogFrame, SW_HIDE);
947 /*********************************************************************
949 * Function : EditFile
951 * Description : Opens the specified setting file for editing.
952 * FIXME: What if the file has no associated application. Check for return values
953 * from ShellExecute??
956 * 1 : filename = filename from the config (aka junkbstr.txt) file.
960 *********************************************************************/
961 void EditFile(const char *filename)
965 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
971 /*--------------------------------------------------------------------------*/
972 /* Windows message handlers */
973 /*--------------------------------------------------------------------------*/
976 /*********************************************************************
978 * Function : OnLogRButtonUp
980 * Description : Handler for WM_RBUTTONUP messages.
983 * 1 : nModifier = wParam from mouse message (unused)
984 * 2 : x = x coordinate of the mouse event
985 * 3 : y = y coordinate of the mouse event
989 *********************************************************************/
990 void OnLogRButtonUp(int nModifier, int x, int y)
992 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
995 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
997 /* Check if there is a selection */
999 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
1000 if (range.cpMin == range.cpMax)
1002 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
1006 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
1009 /* Display the popup */
1010 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
1017 /*********************************************************************
1019 * Function : OnLogCommand
1021 * Description : Handler for WM_COMMAND messages.
1024 * 1 : nCommand = the command portion of the menu selection event
1028 *********************************************************************/
1029 void OnLogCommand(int nCommand)
1034 ShowLogWindow(TRUE);
1038 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1042 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1045 case ID_VIEW_CLEARLOG:
1046 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1049 case ID_VIEW_LOGMESSAGES:
1050 g_bLogMessages = !g_bLogMessages;
1051 /* SaveLogSettings(); */
1054 case ID_VIEW_MESSAGEHIGHLIGHTING:
1055 g_bHighlightMessages = !g_bHighlightMessages;
1056 /* SaveLogSettings(); */
1059 case ID_VIEW_LIMITBUFFERSIZE:
1060 g_bLimitBufferSize = !g_bLimitBufferSize;
1061 /* SaveLogSettings(); */
1064 case ID_VIEW_ACTIVITYANIMATION:
1065 g_bShowActivityAnimation = !g_bShowActivityAnimation;
1066 /* SaveLogSettings(); */
1069 #ifdef FEATURE_TOGGLE
1070 /* by haroon - change toggle to its opposite value */
1072 g_bToggleIJB = !g_bToggleIJB;
1075 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1079 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1082 #endif /* def FEATURE_TOGGLE */
1084 case ID_TOOLS_EDITJUNKBUSTER:
1085 EditFile(configfile);
1088 case ID_TOOLS_EDITACTIONS:
1089 EditFile(g_actions_file);
1092 case ID_TOOLS_EDITPERLRE:
1093 EditFile(g_re_filterfile);
1096 #ifdef FEATURE_TRUST
1097 case ID_TOOLS_EDITTRUST:
1098 EditFile(g_trustfile);
1100 #endif /* def FEATURE_TRUST */
1103 ShellExecute(g_hwndLogFrame, "open", "gpl.html", NULL, NULL, SW_SHOWNORMAL);
1107 ShellExecute(g_hwndLogFrame, "open", "ijbfaq.html", NULL, NULL, SW_SHOWNORMAL);
1110 case ID_HELP_MANUAL:
1111 ShellExecute(g_hwndLogFrame, "open", "ijbman.html", NULL, NULL, SW_SHOWNORMAL);
1114 case ID_HELP_STATUS:
1115 ShellExecute(g_hwndLogFrame, "open", "Junkbuster Status.URL", NULL, NULL, SW_SHOWNORMAL);
1118 case ID_HELP_ABOUTJUNKBUSTER:
1119 MessageBox(g_hwndLogFrame, win32_blurb, "Junkbuster Information", MB_OK);
1130 /*********************************************************************
1132 * Function : OnLogInitMenu
1134 * Description : Handler for WM_INITMENU messages. Enable, disable,
1135 * check, and/or uncheck menu options as apropos.
1138 * 1 : hmenu = handle to menu to "make current"
1142 *********************************************************************/
1143 void OnLogInitMenu(HMENU hmenu)
1145 /* Only enable editors if there is a file to edit */
1146 EnableMenuItem(hmenu, ID_TOOLS_EDITACTIONS, MF_BYCOMMAND | (g_actions_file ? MF_ENABLED : MF_GRAYED));
1147 EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1148 #ifdef FEATURE_TRUST
1149 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1150 #endif /* def FEATURE_TRUST */
1152 /* Check/uncheck options */
1153 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1154 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1155 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1156 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1157 #ifdef FEATURE_TOGGLE
1158 /* by haroon - menu item for Enable toggle on/off */
1159 CheckMenuItem(hmenu, ID_TOGGLE_IJB, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1160 #endif /* def FEATURE_TOGGLE */
1165 /*********************************************************************
1167 * Function : OnLogTimer
1169 * Description : Handler for WM_TIMER messages.
1172 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1176 *********************************************************************/
1177 void OnLogTimer(int nTimer)
1182 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1185 case TIMER_ANIMSTOP_ID:
1187 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1188 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1189 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1192 case TIMER_CLIPBUFFER_ID:
1193 case TIMER_CLIPBUFFER_FORCE_ID:
1195 g_bClipPending = FALSE;
1196 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1197 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1208 /*********************************************************************
1210 * Function : LogRichEditProc
1212 * Description : Window subclass routine handles some events for the rich edit control.
1215 * 1 : hwnd = window handle of the rich edit control
1216 * 2 : uMsg = message number
1217 * 3 : wParam = first param for this message
1218 * 4 : lParam = next param for this message
1220 * Returns : Appropriate M$ window message handler codes.
1222 *********************************************************************/
1223 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1230 pt.x = LOWORD(lParam);
1231 pt.y = HIWORD(lParam);
1232 ClientToScreen(hwnd, &pt);
1233 OnLogRButtonUp(wParam, pt.x, pt.y);
1237 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1242 /*********************************************************************
1244 * Function : LogWindowProc
1246 * Description : Windows call back routine handles events on the log window.
1249 * 1 : hwnd = handle of the logging window
1250 * 2 : uMsg = message number
1251 * 3 : wParam = first param for this message
1252 * 4 : lParam = next param for this message
1254 * Returns : Appropriate M$ window message handler codes.
1256 *********************************************************************/
1257 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1265 /* This is the end - beautiful friend - the end */
1266 DestroyWindow(g_hwndLogBox);
1267 DestroyWindow(g_hwndLogFrame);
1276 /* Resize the logging window to fit the new frame */
1280 GetClientRect(g_hwndLogFrame, &rc);
1281 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1286 OnLogInitMenu((HMENU) wParam);
1294 OnLogCommand(LOWORD(wParam));
1301 if (g_bCloseHidesWindow)
1303 ShowLogWindow(FALSE);
1308 ShowLogWindow(FALSE);
1314 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1318 #endif /* ndef _WIN_CONSOLE - entire file */