1 const char w32log_rcs[] = "$Id: w32log.c,v 1.2 2001/05/20 01:21:20 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.2 2001/05/20 01:21:20 jongfoster
36 * Version 2.9.4 checkin.
37 * - Merged popupfile and cookiefile, and added control over PCRS
38 * filtering, in new "permissionsfile".
39 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
40 * file error you now get a message box (in the Win32 GUI) rather
41 * than the program exiting with no explanation.
42 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
44 * - Removed tabs from "config"
45 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
46 * - Bumped up version number.
48 * Revision 1.1.1.1 2001/05/15 13:59:07 oes
49 * Initial import of version 2.9.3 source tree
52 *********************************************************************/
65 #include "w32taskbar.h"
66 #include "w32rulesdlg.h"
73 const char w32res_h_rcs[] = W32RES_H_VERSION;
77 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
80 const char w32log_h_rcs[] = W32LOG_H_VERSION;
82 #ifndef _WIN_CONSOLE /* entire file */
\r
85 * Timers and the various durations
87 #define TIMER_ANIM_ID 1
88 #define TIMER_ANIM_TIME 100
89 #define TIMER_ANIMSTOP_ID 2
90 #define TIMER_ANIMSTOP_TIME 1000
91 #define TIMER_CLIPBUFFER_ID 3
92 #define TIMER_CLIPBUFFER_TIME 1000
93 #define TIMER_CLIPBUFFER_FORCE_ID 4
94 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
97 * Styles of text that can be output
100 #define STYLE_HIGHLIGHT 1
102 #define STYLE_HEADER 3
105 * Number of frames of animation in tray activity sequence
107 #define ANIM_FRAMES 8
109 #define DEFAULT_MAX_BUFFER_LINES 200
110 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
111 #define DEFAULT_LOG_FONT_SIZE 8
114 * These values affect the way the log window behaves, they should be read
115 * from a file but for the moment, they are hardcoded here. Some options are
116 * configurable through the UI.
119 /* Indicates whether task bar shows activity animation */
120 BOOL g_bShowActivityAnimation = 1;
122 /* Indicates if the log window appears on the task bar */
123 BOOL g_bShowOnTaskBar = 0;
125 /* Indicates whether closing the log window really just hides it */
126 BOOL g_bCloseHidesWindow = 1;
128 /* Indicates if messages are logged at all */
129 BOOL g_bLogMessages = 1;
131 /* Indicates whether log messages are highlighted */
132 BOOL g_bHighlightMessages = 1;
134 /* Indicates if buffer is limited in size */
135 BOOL g_bLimitBufferSize = 1;
137 /* Maximum number of lines allowed in buffer when limited */
138 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
141 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
143 /* Size of font to use */
144 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
148 /* Regular expression for detected URLs */
149 #define RE_URL "http:[^ \n\r]*"
152 * Regular expressions that are used to perform highlight in the log window
154 static struct _Pattern
159 } patterns_to_highlight[] =
162 { RE_URL, STYLE_LINK },
163 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
164 /* interesting text to highlight */
165 { "crunch!", STYLE_HIGHLIGHT },
167 { "referer:", STYLE_HEADER },
168 { "proxy-connection:", STYLE_HEADER },
169 { "proxy-agent:", STYLE_HEADER },
170 { "user-agent:", STYLE_HEADER },
171 { "host:", STYLE_HEADER },
172 { "accept:", STYLE_HEADER },
173 { "accept-encoding:", STYLE_HEADER },
174 { "accept-language:", STYLE_HEADER },
175 { "accept-charset:", STYLE_HEADER },
176 { "accept-ranges:", STYLE_HEADER },
177 { "date:", STYLE_HEADER },
178 { "cache-control:", STYLE_HEADER },
179 { "cache-last-checked:", STYLE_HEADER },
180 { "connection:", STYLE_HEADER },
181 { "content-type", STYLE_HEADER },
182 { "content-length", STYLE_HEADER },
183 { "cookie", STYLE_HEADER },
184 { "last-modified:", STYLE_HEADER },
185 { "pragma:", STYLE_HEADER },
186 { "server:", STYLE_HEADER },
187 { "etag:", STYLE_HEADER },
188 { "expires:", STYLE_HEADER },
189 { "warning:", STYLE_HEADER },
190 /* this is the terminator statement - do not delete! */
193 #endif /* def REGEX */
204 static CRITICAL_SECTION g_criticalsection;
205 static HWND g_hwndTray;
206 static HWND g_hwndLogBox;
207 static WNDPROC g_fnLogBox;
208 static HICON g_hiconAnim[ANIM_FRAMES];
209 static HICON g_hiconIdle;
210 static HICON g_hiconApp;
211 static int g_nAnimFrame;
212 static BOOL g_bClipPending = FALSE;
213 static int g_nRichEditVersion = 0;
218 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
219 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
220 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
221 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
222 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
223 static BOOL InitRichEdit(void);
224 static void LogClipBuffer(void);
225 static void LogCreatePatternMatchingBuffers(void);
226 static void LogDestroyPatternMatchingBuffers(void);
227 static int LogPutStringNoMatch(const char *pszText, int style);
230 /*********************************************************************
232 * Function : InitLogWindow
234 * Description : Initialise the log window.
238 * Returns : Always TRUE (there should be error checking on the resources).
240 *********************************************************************/
241 BOOL InitLogWindow(void)
246 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
247 for (i = 0; i < ANIM_FRAMES; i++)
249 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER1 + i));
251 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER));
253 /* Create the user interface */
254 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
255 g_hwndTray = CreateTrayWindow(g_hInstance);
256 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Junkbuster");
258 /* Create pattern matching buffers (for highlighting */
259 LogCreatePatternMatchingBuffers();
261 /* Create a critical section to protect multi-threaded access to certain things */
262 InitializeCriticalSection(&g_criticalsection);
269 /*********************************************************************
271 * Function : TermLogWindow
273 * Description : Cleanup the logwindow.
279 *********************************************************************/
280 void TermLogWindow(void)
284 LogDestroyPatternMatchingBuffers();
286 TrayDeleteIcon(g_hwndTray, 1);
287 DeleteObject(g_hiconApp);
288 DeleteObject(g_hiconIdle);
289 for (i = 0; i < ANIM_FRAMES; i++)
291 DeleteObject(g_hiconAnim[i]);
297 /*********************************************************************
299 * Function : LogCreatePatternMatchingBuffers
301 * Description : Compile the pattern matching buffers.
307 *********************************************************************/
308 void LogCreatePatternMatchingBuffers(void)
312 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
314 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
321 /*********************************************************************
323 * Function : LogDestroyPatternMatchingBuffers
325 * Description : Free up the pattern matching buffers.
331 *********************************************************************/
332 void LogDestroyPatternMatchingBuffers(void)
336 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
338 regfree(&patterns_to_highlight[i].buffer);
345 /*********************************************************************
347 * Function : LogGetURLUnderCursor
349 * Description : Returns the URL from under the cursor (remember to free it!).
353 * Returns : NULL or a pointer to an URL string.
355 *********************************************************************/
356 char *LogGetURLUnderCursor(void)
358 char *szResult = NULL;
364 DWORD nWordStart = 0;
367 regcomp(&re, RE_URL, REG_ICASE);
369 /* Get the position of the cursor over the text window */
370 GetCursorPos(&ptCursor);
371 ScreenToClient(g_hwndLogBox, &ptCursor);
375 /* Search backwards and fowards to obtain the word that is highlighted */
376 nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
377 nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
378 nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
380 /* Compare the string to the pattern */
381 if (nWordEnd > nWordStart)
386 range.chrg.cpMin = nWordStart;
387 range.chrg.cpMax = nWordEnd;
388 range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
389 SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
391 if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
393 szResult = range.lpstrText;
397 free(range.lpstrText);
408 /*********************************************************************
410 * Function : LogPutString
412 * Description : Inserts text into the logging window. This is really
413 * a REGEXP aware wrapper function to `LogPutStringNoMatch'.
416 * 1 : pszText = pointer to string going to the log window
418 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
419 * FIXME: this is backwards to the rest of IJB and to common
420 * programming practice. Please use 0 => success instead.
422 *********************************************************************/
423 int LogPutString(const char *pszText)
430 if (pszText == NULL || strlen(pszText) == 0)
440 /* Critical section stops multiple threads doing nasty interactions that
441 * foul up the highlighting and output.
443 EnterCriticalSection(&g_criticalsection);
446 if (g_bHighlightMessages)
450 /* First things first, regexp scan for various things that we would like highlighted */
451 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
453 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
455 char *pszBefore = NULL;
456 char *pszMatch = NULL;
457 char *pszAfter = NULL;
460 /* Split the string up into pieces representing the strings, before
461 at and after the matching pattern
465 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
466 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
467 strncpy(pszBefore, pszText, match.rm_so);
469 if (match.rm_eo < strlen(pszText))
471 pszAfter = strdup(&pszText[match.rm_eo]);
473 nMatchSize = match.rm_eo - match.rm_so;
474 pszMatch = (char *)malloc(nMatchSize + 1);
475 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
476 pszMatch[nMatchSize] = '\0';
478 /* Recursively call LogPutString */
481 LogPutString(pszBefore);
486 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
491 LogPutString(pszAfter);
502 result = LogPutStringNoMatch(pszText, STYLE_NONE);
507 LeaveCriticalSection(&g_criticalsection);
514 /*********************************************************************
516 * Function : LogPutStringNoMatch
518 * Description : Puts a string into the logging window.
521 * 1 : pszText = pointer to string going to the log window
522 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
524 * Returns : Always 1 => success.
525 * FIXME: this is backwards to the rest of IJB and to common
526 * programming practice. Please use 0 => success instead.
528 *********************************************************************/
529 int LogPutStringNoMatch(const char *pszText, int style)
535 assert(g_hwndLogBox);
536 if (g_hwndLogBox == NULL)
541 /* TODO preserve existing selection */
543 /* Go to the end of the text */
544 nTextLength = GetWindowTextLength(g_hwndLogBox);
545 range.cpMin = nTextLength;
546 range.cpMax = nTextLength;
547 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
549 /* Apply a formatting style */
550 memset(&format, 0, sizeof(format));
551 format.cbSize = sizeof(format);
552 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
553 format.yHeight = (g_nFontSize * 1440) / 72;
554 strcpy(format.szFaceName, g_szFontFaceName);
555 if (style == STYLE_NONE)
558 format.dwEffects |= CFE_AUTOCOLOR;
560 else if (style == STYLE_HEADER)
562 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
564 else if (style == STYLE_HIGHLIGHT)
566 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
568 else if (style == STYLE_LINK)
570 format.dwEffects |= CFE_UNDERLINE;
571 format.crTextColor = RGB(0, 0, 255);
573 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
575 /* Append text to the end */
576 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
578 /* TODO Restore the old selection */
581 if (strchr(pszText, '\n') != NULL)
583 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
586 /* Set the force clip timer going. This timer ensures clipping is done
587 intermittently even when there is a sustained burst of logging
589 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
591 g_bClipPending = TRUE;
599 /*********************************************************************
601 * Function : LogShowActivity
603 * Description : Start the spinner.
609 *********************************************************************/
610 void LogShowActivity(void)
612 /* Start some activity timers */
613 if (g_bShowActivityAnimation)
615 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
616 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
622 /*********************************************************************
624 * Function : LogClipBuffer
626 * Description : Prunes old lines from the log.
632 *********************************************************************/
633 void LogClipBuffer(void)
635 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
636 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
638 /* Compute the range representing the lines to be deleted */
639 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
640 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
643 range.cpMax = nLastChar;
645 /* TODO get current selection */
647 /* TODO adjust and clip old selection against range to be deleted */
649 /* Select range and erase it (turning off autoscroll to prevent
651 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
652 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
653 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
654 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
656 /* Restore old selection */
662 /*********************************************************************
664 * Function : CreateHiddenLogOwnerWindow
666 * Description : Creates a hidden owner window that stops the log
667 * window appearing in the task bar.
670 * 1 : hInstance = application's instance handle
672 * Returns : Handle to newly created window.
674 *********************************************************************/
675 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
677 static const char *szWndName = "JunkbusterLogLogOwner";
682 wc.lpfnWndProc = LogOwnerWindowProc;
685 wc.hInstance = hInstance;
688 wc.hbrBackground = 0;
690 wc.lpszClassName = szWndName;
694 hwnd = CreateWindow(szWndName, szWndName,
695 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
696 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
703 /*********************************************************************
705 * Function : LogOwnerWindowProc
707 * Description : Dummy procedure that does nothing special.
710 * 1 : hwnd = window handle
711 * 2 : uMsg = message number
712 * 3 : wParam = first param for this message
713 * 4 : lParam = next param for this message
715 * Returns : Same as `DefWindowProc'.
717 *********************************************************************/
718 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
720 return DefWindowProc(hwnd, uMsg, wParam, lParam);
725 /*********************************************************************
727 * Function : CreateLogWindow
729 * Description : Create the logging window.
732 * 1 : hInstance = application's instance handle
733 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
735 * Returns : Handle to newly created window.
737 *********************************************************************/
738 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
740 static const char *szWndName = "JunkbusterLogWindow";
741 static const char *szWndTitle = "Junkbuster";
744 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
745 HWND hwndChild = NULL;
749 memset(&wc, 0, sizeof(wc));
750 wc.cbSize = sizeof(wc);
751 wc.style = CS_DBLCLKS;
752 wc.lpfnWndProc = LogWindowProc;
755 wc.hInstance = hInstance;
756 wc.hIcon = g_hiconApp;
758 wc.hbrBackground = 0;
759 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
760 wc.lpszClassName = szWndName;
761 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
762 RegisterClassEx(&wc);
764 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
765 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
766 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
768 /* Now create a child list box */
769 GetClientRect(hwnd, &rcClient);
771 /* Create a rich edit control */
773 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
774 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
775 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
776 hwnd, NULL, hInstance, NULL);
777 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
779 /* Subclass the control to catch certain messages */
780 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
781 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
783 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
784 if (!g_bShowOnTaskBar &&
785 (nCmdShow == SW_SHOWMINIMIZED ||
786 nCmdShow == SW_MINIMIZE ||
787 nCmdShow == SW_SHOWMINNOACTIVE))
792 ShowWindow(hwnd, nCmdShow);
795 GetClientRect(g_hwndLogFrame, &rcClient);
796 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
803 /*********************************************************************
805 * Function : InitRichEdit
807 * Description : Initialise the rich edit control library.
811 * Returns : TRUE => success, FALSE => failure.
812 * FIXME: this is backwards to the rest of IJB and to common
813 * programming practice. Please use 0 => success instead.
815 *********************************************************************/
816 BOOL InitRichEdit(void)
818 static HINSTANCE hInstRichEdit;
819 if (hInstRichEdit == NULL)
821 g_nRichEditVersion = 0;
822 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
825 g_nRichEditVersion = _RICHEDIT_VER;
829 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
832 g_nRichEditVersion = 0x0100;
836 return (hInstRichEdit != NULL) ? TRUE : FALSE;
841 /*********************************************************************
843 * Function : ShowLogWindow
845 * Description : Shows or hides the log window. We will also raise the
846 * window on a show command in case it is buried.
849 * 1 : bShow = TRUE to show, FALSE to mimize/hide
853 *********************************************************************/
854 void ShowLogWindow(BOOL bShow)
858 SetForegroundWindow(g_hwndLogFrame);
859 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
861 else if (g_bShowOnTaskBar)
863 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
867 ShowWindow(g_hwndLogFrame, SW_HIDE);
873 /*********************************************************************
875 * Function : EditFile
877 * Description : Opens the specified setting file for editing.
880 * 1 : filename = filename from the config (aka junkbstr.txt) file.
884 *********************************************************************/
885 void EditFile(const char *filename)
889 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
895 /*--------------------------------------------------------------------------*/
896 /* Windows message handlers */
897 /*--------------------------------------------------------------------------*/
900 /*********************************************************************
902 * Function : OnLogRButtonUp
904 * Description : Handler for WM_RBUTTONUP messages.
907 * 1 : nModifier = wParam from mouse message (unused)
908 * 2 : x = x coordinate of the mouse event
909 * 3 : y = y coordinate of the mouse event
913 *********************************************************************/
914 void OnLogRButtonUp(int nModifier, int x, int y)
916 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
919 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
922 /* Check if there is a selection */
924 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
925 if (range.cpMin == range.cpMax)
927 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
931 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
934 /* Check if cursor is over a link */
935 szURL = LogGetURLUnderCursor();
939 TCHAR szMenuItemTemplate[1000];
942 memset(&item, 0, sizeof(item));
943 item.cbSize = sizeof(item);
944 item.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
945 item.fType = MFT_STRING;
946 item.fState = MFS_ENABLED;
947 item.wID = ID_NEW_BLOCKER;
949 /* Put the item into the menu */
950 memset(szMenuItemTemplate, 0, sizeof(szMenuItemTemplate));
951 LoadString(g_hInstance, IDS_NEW_BLOCKER, szMenuItemTemplate, sizeof(szMenuItemTemplate) / sizeof(szMenuItemTemplate[0]));
953 szMenuItem = (char *)malloc(strlen(szMenuItemTemplate) + strlen(szURL) + 1);
954 sprintf(szMenuItem, szMenuItemTemplate, szURL);
956 item.dwTypeData = szMenuItem;
957 item.cch = strlen(szMenuItem);
959 InsertMenuItem(hMenuPopup, 1, TRUE, &item);
961 SetDefaultRule(szURL);
966 /* Display the popup */
967 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
974 /*********************************************************************
976 * Function : OnLogCommand
978 * Description : Handler for WM_COMMAND messages.
981 * 1 : nCommand = the command portion of the menu selection event
985 *********************************************************************/
986 void OnLogCommand(int nCommand)
995 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
999 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1002 case ID_VIEW_CLEARLOG:
1003 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1006 case ID_VIEW_LOGMESSAGES:
1007 g_bLogMessages = !g_bLogMessages;
1008 /* SaveLogSettings(); */
1011 case ID_VIEW_MESSAGEHIGHLIGHTING:
1012 g_bHighlightMessages = !g_bHighlightMessages;
1013 /* SaveLogSettings(); */
1016 case ID_VIEW_LIMITBUFFERSIZE:
1017 g_bLimitBufferSize = !g_bLimitBufferSize;
1018 /* SaveLogSettings(); */
1021 case ID_VIEW_ACTIVITYANIMATION:
1022 g_bShowActivityAnimation = !g_bShowActivityAnimation;
1023 /* SaveLogSettings(); */
1027 /* by haroon - change toggle to its opposite value */
1029 g_bToggleIJB = !g_bToggleIJB;
1032 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1036 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1041 case ID_RELOAD_CONFIG:
1047 log_error(LOG_LEVEL_ERROR, "load_config encountered a problem! You should probably restart IJB.");
1051 log_error(LOG_LEVEL_INFO, "Configuration has been reloaded.");
1055 case ID_TOOLS_EDITJUNKBUSTER:
1056 EditFile(configfile);
1059 case ID_TOOLS_EDITBLOCKERS:
1060 EditFile(blockfile);
1063 case ID_TOOLS_EDITPERMISSIONS:
1064 EditFile(permissions_file);
1067 case ID_TOOLS_EDITFORWARD:
1068 EditFile(forwardfile);
1072 case ID_TOOLS_EDITACLS:
1075 #endif /* def ACL_FILES */
1077 #ifdef USE_IMAGE_LIST
1078 case ID_TOOLS_EDITIMAGE:
1079 EditFile(imagefile);
1081 #endif /* def USE_IMAGE_LIST */
1084 case ID_TOOLS_EDITPERLRE:
1085 EditFile(re_filterfile);
1090 case ID_TOOLS_EDITTRUST:
1091 EditFile(trustfile);
1093 #endif /* def TRUST_FILES */
1095 case ID_NEW_BLOCKER:
1096 ShowRulesDialog(g_hwndLogFrame);
1100 ShellExecute(g_hwndLogFrame, "open", "gpl.html", NULL, NULL, SW_SHOWNORMAL);
1104 ShellExecute(g_hwndLogFrame, "open", "ijbfaq.html", NULL, NULL, SW_SHOWNORMAL);
1107 case ID_HELP_MANUAL:
1108 ShellExecute(g_hwndLogFrame, "open", "ijbman.html", NULL, NULL, SW_SHOWNORMAL);
1111 case ID_HELP_STATUS:
1112 ShellExecute(g_hwndLogFrame, "open", "Junkbuster Status.URL", NULL, NULL, SW_SHOWNORMAL);
1115 case ID_HELP_ABOUTJUNKBUSTER:
1116 MessageBox(g_hwndLogFrame, win32_blurb, "Junkbuster Information", MB_OK);
1127 /*********************************************************************
1129 * Function : OnLogInitMenu
1131 * Description : Handler for WM_INITMENU messages. Enable, disable,
1132 * check, and/or uncheck menu options as apropos.
1135 * 1 : hmenu = handle to menu to "make current"
1139 *********************************************************************/
1140 void OnLogInitMenu(HMENU hmenu)
1142 /* Only enable editors if there is a file to edit */
1143 EnableMenuItem(hmenu, ID_TOOLS_EDITPERMISSIONS, MF_BYCOMMAND | (permissions_file ? MF_ENABLED : MF_GRAYED));
1144 EnableMenuItem(hmenu, ID_TOOLS_EDITBLOCKERS, MF_BYCOMMAND | (blockfile ? MF_ENABLED : MF_GRAYED));
1145 EnableMenuItem(hmenu, ID_TOOLS_EDITFORWARD, MF_BYCOMMAND | (forwardfile ? MF_ENABLED : MF_GRAYED));
1147 EnableMenuItem(hmenu, ID_TOOLS_EDITACLS, MF_BYCOMMAND | (aclfile ? MF_ENABLED : MF_GRAYED));
1148 #endif /* def ACL_FILES */
1149 #ifdef USE_IMAGE_LIST
1150 EnableMenuItem(hmenu, ID_TOOLS_EDITIMAGE, MF_BYCOMMAND | (imagefile ? MF_ENABLED : MF_GRAYED));
1151 #endif /* def USE_IMAGE_LIST */
1153 EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (re_filterfile ? MF_ENABLED : MF_GRAYED));
1156 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (trustfile ? MF_ENABLED : MF_GRAYED));
1157 #endif /* def TRUST_FILES */
1159 /* Check/uncheck options */
1160 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1161 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1162 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1163 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1165 /* by haroon - menu item for Enable toggle on/off */
1166 CheckMenuItem(hmenu, ID_TOGGLE_IJB, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1172 /*********************************************************************
1174 * Function : OnLogTimer
1176 * Description : Handler for WM_TIMER messages.
1179 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1183 *********************************************************************/
1184 void OnLogTimer(int nTimer)
1189 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1192 case TIMER_ANIMSTOP_ID:
1194 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1195 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1196 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1199 case TIMER_CLIPBUFFER_ID:
1200 case TIMER_CLIPBUFFER_FORCE_ID:
1202 g_bClipPending = FALSE;
1203 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1204 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1215 /*********************************************************************
1217 * Function : LogRichEditProc
1219 * Description : Window subclass routine handles some events for the rich edit control.
1222 * 1 : hwnd = window handle of the rich edit control
1223 * 2 : uMsg = message number
1224 * 3 : wParam = first param for this message
1225 * 4 : lParam = next param for this message
1227 * Returns : Appropriate M$ window message handler codes.
1229 *********************************************************************/
1230 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1237 pt.x = LOWORD(lParam);
1238 pt.y = HIWORD(lParam);
1239 ClientToScreen(hwnd, &pt);
1240 OnLogRButtonUp(wParam, pt.x, pt.y);
1244 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1249 /*********************************************************************
1251 * Function : LogWindowProc
1253 * Description : Windows call back routine handles events on the log window.
1256 * 1 : hwnd = handle of the logging window
1257 * 2 : uMsg = message number
1258 * 3 : wParam = first param for this message
1259 * 4 : lParam = next param for this message
1261 * Returns : Appropriate M$ window message handler codes.
1263 *********************************************************************/
1264 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1272 /* This is the end - beautiful friend - the end */
1273 DestroyWindow(g_hwndLogBox);
1274 DestroyWindow(g_hwndLogFrame);
1283 /* Resize the logging window to fit the new frame */
1287 GetClientRect(g_hwndLogFrame, &rc);
1288 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1293 OnLogInitMenu((HMENU) wParam);
1301 OnLogCommand(LOWORD(wParam));
1308 if (g_bCloseHidesWindow)
1310 ShowLogWindow(FALSE);
1315 ShowLogWindow(FALSE);
1321 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1325 #endif /* ndef _WIN_CONSOLE - entire file */
\r