1 const char w32log_rcs[] = "$Id: w32log.c,v 1.3 2001/05/20 15:07:54 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.3 2001/05/20 15:07:54 jongfoster
36 * File is now ignored if _WIN_CONSOLE is defined.
38 * Revision 1.2 2001/05/20 01:21:20 jongfoster
39 * Version 2.9.4 checkin.
40 * - Merged popupfile and cookiefile, and added control over PCRS
41 * filtering, in new "permissionsfile".
42 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
43 * file error you now get a message box (in the Win32 GUI) rather
44 * than the program exiting with no explanation.
45 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
47 * - Removed tabs from "config"
48 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
49 * - Bumped up version number.
51 * Revision 1.1.1.1 2001/05/15 13:59:07 oes
52 * Initial import of version 2.9.3 source tree
55 *********************************************************************/
68 #include "w32taskbar.h"
69 #include "w32rulesdlg.h"
76 const char w32res_h_rcs[] = W32RES_H_VERSION;
80 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
83 const char w32log_h_rcs[] = W32LOG_H_VERSION;
85 #ifndef _WIN_CONSOLE /* entire file */
88 * Timers and the various durations
90 #define TIMER_ANIM_ID 1
91 #define TIMER_ANIM_TIME 100
92 #define TIMER_ANIMSTOP_ID 2
93 #define TIMER_ANIMSTOP_TIME 1000
94 #define TIMER_CLIPBUFFER_ID 3
95 #define TIMER_CLIPBUFFER_TIME 1000
96 #define TIMER_CLIPBUFFER_FORCE_ID 4
97 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
100 * Styles of text that can be output
103 #define STYLE_HIGHLIGHT 1
105 #define STYLE_HEADER 3
108 * Number of frames of animation in tray activity sequence
110 #define ANIM_FRAMES 8
112 #define DEFAULT_MAX_BUFFER_LINES 200
113 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
114 #define DEFAULT_LOG_FONT_SIZE 8
117 * These values affect the way the log window behaves, they should be read
118 * from a file but for the moment, they are hardcoded here. Some options are
119 * configurable through the UI.
122 /* Indicates whether task bar shows activity animation */
123 BOOL g_bShowActivityAnimation = 1;
125 /* Indicates if the log window appears on the task bar */
126 BOOL g_bShowOnTaskBar = 0;
128 /* Indicates whether closing the log window really just hides it */
129 BOOL g_bCloseHidesWindow = 1;
131 /* Indicates if messages are logged at all */
132 BOOL g_bLogMessages = 1;
134 /* Indicates whether log messages are highlighted */
135 BOOL g_bHighlightMessages = 1;
137 /* Indicates if buffer is limited in size */
138 BOOL g_bLimitBufferSize = 1;
140 /* Maximum number of lines allowed in buffer when limited */
141 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
144 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
146 /* Size of font to use */
147 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
151 /* Regular expression for detected URLs */
152 #define RE_URL "http:[^ \n\r]*"
155 * Regular expressions that are used to perform highlight in the log window
157 static struct _Pattern
162 } patterns_to_highlight[] =
165 { RE_URL, STYLE_LINK },
166 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
167 /* interesting text to highlight */
168 { "crunch!", STYLE_HIGHLIGHT },
170 { "referer:", STYLE_HEADER },
171 { "proxy-connection:", STYLE_HEADER },
172 { "proxy-agent:", STYLE_HEADER },
173 { "user-agent:", STYLE_HEADER },
174 { "host:", STYLE_HEADER },
175 { "accept:", STYLE_HEADER },
176 { "accept-encoding:", STYLE_HEADER },
177 { "accept-language:", STYLE_HEADER },
178 { "accept-charset:", STYLE_HEADER },
179 { "accept-ranges:", STYLE_HEADER },
180 { "date:", STYLE_HEADER },
181 { "cache-control:", STYLE_HEADER },
182 { "cache-last-checked:", STYLE_HEADER },
183 { "connection:", STYLE_HEADER },
184 { "content-type", STYLE_HEADER },
185 { "content-length", STYLE_HEADER },
186 { "cookie", STYLE_HEADER },
187 { "last-modified:", STYLE_HEADER },
188 { "pragma:", STYLE_HEADER },
189 { "server:", STYLE_HEADER },
190 { "etag:", STYLE_HEADER },
191 { "expires:", STYLE_HEADER },
192 { "warning:", STYLE_HEADER },
193 /* this is the terminator statement - do not delete! */
196 #endif /* def REGEX */
207 static CRITICAL_SECTION g_criticalsection;
208 static HWND g_hwndTray;
209 static HWND g_hwndLogBox;
210 static WNDPROC g_fnLogBox;
211 static HICON g_hiconAnim[ANIM_FRAMES];
212 static HICON g_hiconIdle;
213 static HICON g_hiconApp;
214 static int g_nAnimFrame;
215 static BOOL g_bClipPending = FALSE;
216 static int g_nRichEditVersion = 0;
221 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
222 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
223 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
224 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
225 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
226 static BOOL InitRichEdit(void);
227 static void LogClipBuffer(void);
228 static void LogCreatePatternMatchingBuffers(void);
229 static void LogDestroyPatternMatchingBuffers(void);
230 static int LogPutStringNoMatch(const char *pszText, int style);
233 /*********************************************************************
235 * Function : InitLogWindow
237 * Description : Initialise the log window.
241 * Returns : Always TRUE (there should be error checking on the resources).
243 *********************************************************************/
244 BOOL InitLogWindow(void)
249 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
250 for (i = 0; i < ANIM_FRAMES; i++)
252 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER1 + i));
254 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER));
256 /* Create the user interface */
257 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
258 g_hwndTray = CreateTrayWindow(g_hInstance);
259 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Junkbuster");
261 /* Create pattern matching buffers (for highlighting */
262 LogCreatePatternMatchingBuffers();
264 /* Create a critical section to protect multi-threaded access to certain things */
265 InitializeCriticalSection(&g_criticalsection);
272 /*********************************************************************
274 * Function : TermLogWindow
276 * Description : Cleanup the logwindow.
282 *********************************************************************/
283 void TermLogWindow(void)
287 LogDestroyPatternMatchingBuffers();
289 TrayDeleteIcon(g_hwndTray, 1);
290 DeleteObject(g_hiconApp);
291 DeleteObject(g_hiconIdle);
292 for (i = 0; i < ANIM_FRAMES; i++)
294 DeleteObject(g_hiconAnim[i]);
300 /*********************************************************************
302 * Function : LogCreatePatternMatchingBuffers
304 * Description : Compile the pattern matching buffers.
310 *********************************************************************/
311 void LogCreatePatternMatchingBuffers(void)
315 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
317 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
324 /*********************************************************************
326 * Function : LogDestroyPatternMatchingBuffers
328 * Description : Free up the pattern matching buffers.
334 *********************************************************************/
335 void LogDestroyPatternMatchingBuffers(void)
339 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
341 regfree(&patterns_to_highlight[i].buffer);
348 /*********************************************************************
350 * Function : LogGetURLUnderCursor
352 * Description : Returns the URL from under the cursor (remember to free it!).
356 * Returns : NULL or a pointer to an URL string.
358 *********************************************************************/
359 char *LogGetURLUnderCursor(void)
361 char *szResult = NULL;
367 DWORD nWordStart = 0;
370 regcomp(&re, RE_URL, REG_ICASE);
372 /* Get the position of the cursor over the text window */
373 GetCursorPos(&ptCursor);
374 ScreenToClient(g_hwndLogBox, &ptCursor);
378 /* Search backwards and fowards to obtain the word that is highlighted */
379 nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
380 nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
381 nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
383 /* Compare the string to the pattern */
384 if (nWordEnd > nWordStart)
389 range.chrg.cpMin = nWordStart;
390 range.chrg.cpMax = nWordEnd;
391 range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
392 SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
394 if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
396 szResult = range.lpstrText;
400 free(range.lpstrText);
411 /*********************************************************************
413 * Function : LogPutString
415 * Description : Inserts text into the logging window. This is really
416 * a REGEXP aware wrapper function to `LogPutStringNoMatch'.
419 * 1 : pszText = pointer to string going to the log window
421 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
422 * FIXME: this is backwards to the rest of IJB and to common
423 * programming practice. Please use 0 => success instead.
425 *********************************************************************/
426 int LogPutString(const char *pszText)
433 if (pszText == NULL || strlen(pszText) == 0)
443 /* Critical section stops multiple threads doing nasty interactions that
444 * foul up the highlighting and output.
446 EnterCriticalSection(&g_criticalsection);
449 if (g_bHighlightMessages)
453 /* First things first, regexp scan for various things that we would like highlighted */
454 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
456 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
458 char *pszBefore = NULL;
459 char *pszMatch = NULL;
460 char *pszAfter = NULL;
463 /* Split the string up into pieces representing the strings, before
464 at and after the matching pattern
468 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
469 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
470 strncpy(pszBefore, pszText, match.rm_so);
472 if (match.rm_eo < strlen(pszText))
474 pszAfter = strdup(&pszText[match.rm_eo]);
476 nMatchSize = match.rm_eo - match.rm_so;
477 pszMatch = (char *)malloc(nMatchSize + 1);
478 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
479 pszMatch[nMatchSize] = '\0';
481 /* Recursively call LogPutString */
484 LogPutString(pszBefore);
489 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
494 LogPutString(pszAfter);
505 result = LogPutStringNoMatch(pszText, STYLE_NONE);
510 LeaveCriticalSection(&g_criticalsection);
517 /*********************************************************************
519 * Function : LogPutStringNoMatch
521 * Description : Puts a string into the logging window.
524 * 1 : pszText = pointer to string going to the log window
525 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
527 * Returns : Always 1 => success.
528 * FIXME: this is backwards to the rest of IJB and to common
529 * programming practice. Please use 0 => success instead.
531 *********************************************************************/
532 int LogPutStringNoMatch(const char *pszText, int style)
538 assert(g_hwndLogBox);
539 if (g_hwndLogBox == NULL)
544 /* TODO preserve existing selection */
546 /* Go to the end of the text */
547 nTextLength = GetWindowTextLength(g_hwndLogBox);
548 range.cpMin = nTextLength;
549 range.cpMax = nTextLength;
550 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
552 /* Apply a formatting style */
553 memset(&format, 0, sizeof(format));
554 format.cbSize = sizeof(format);
555 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
556 format.yHeight = (g_nFontSize * 1440) / 72;
557 strcpy(format.szFaceName, g_szFontFaceName);
558 if (style == STYLE_NONE)
561 format.dwEffects |= CFE_AUTOCOLOR;
563 else if (style == STYLE_HEADER)
565 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
567 else if (style == STYLE_HIGHLIGHT)
569 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
571 else if (style == STYLE_LINK)
573 format.dwEffects |= CFE_UNDERLINE;
574 format.crTextColor = RGB(0, 0, 255);
576 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
578 /* Append text to the end */
579 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
581 /* TODO Restore the old selection */
584 if (strchr(pszText, '\n') != NULL)
586 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
589 /* Set the force clip timer going. This timer ensures clipping is done
590 intermittently even when there is a sustained burst of logging
592 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
594 g_bClipPending = TRUE;
602 /*********************************************************************
604 * Function : LogShowActivity
606 * Description : Start the spinner.
612 *********************************************************************/
613 void LogShowActivity(void)
615 /* Start some activity timers */
616 if (g_bShowActivityAnimation)
618 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
619 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
625 /*********************************************************************
627 * Function : LogClipBuffer
629 * Description : Prunes old lines from the log.
635 *********************************************************************/
636 void LogClipBuffer(void)
638 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
639 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
641 /* Compute the range representing the lines to be deleted */
642 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
643 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
646 range.cpMax = nLastChar;
648 /* TODO get current selection */
650 /* TODO adjust and clip old selection against range to be deleted */
652 /* Select range and erase it (turning off autoscroll to prevent
654 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
655 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
656 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
657 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
659 /* Restore old selection */
665 /*********************************************************************
667 * Function : CreateHiddenLogOwnerWindow
669 * Description : Creates a hidden owner window that stops the log
670 * window appearing in the task bar.
673 * 1 : hInstance = application's instance handle
675 * Returns : Handle to newly created window.
677 *********************************************************************/
678 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
680 static const char *szWndName = "JunkbusterLogLogOwner";
685 wc.lpfnWndProc = LogOwnerWindowProc;
688 wc.hInstance = hInstance;
691 wc.hbrBackground = 0;
693 wc.lpszClassName = szWndName;
697 hwnd = CreateWindow(szWndName, szWndName,
698 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
699 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
706 /*********************************************************************
708 * Function : LogOwnerWindowProc
710 * Description : Dummy procedure that does nothing special.
713 * 1 : hwnd = window handle
714 * 2 : uMsg = message number
715 * 3 : wParam = first param for this message
716 * 4 : lParam = next param for this message
718 * Returns : Same as `DefWindowProc'.
720 *********************************************************************/
721 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
723 return DefWindowProc(hwnd, uMsg, wParam, lParam);
728 /*********************************************************************
730 * Function : CreateLogWindow
732 * Description : Create the logging window.
735 * 1 : hInstance = application's instance handle
736 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
738 * Returns : Handle to newly created window.
740 *********************************************************************/
741 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
743 static const char *szWndName = "JunkbusterLogWindow";
744 static const char *szWndTitle = "Junkbuster";
747 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
748 HWND hwndChild = NULL;
752 memset(&wc, 0, sizeof(wc));
753 wc.cbSize = sizeof(wc);
754 wc.style = CS_DBLCLKS;
755 wc.lpfnWndProc = LogWindowProc;
758 wc.hInstance = hInstance;
759 wc.hIcon = g_hiconApp;
761 wc.hbrBackground = 0;
762 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
763 wc.lpszClassName = szWndName;
764 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
765 RegisterClassEx(&wc);
767 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
768 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
769 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
771 /* Now create a child list box */
772 GetClientRect(hwnd, &rcClient);
774 /* Create a rich edit control */
776 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
777 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
778 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
779 hwnd, NULL, hInstance, NULL);
780 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
782 /* Subclass the control to catch certain messages */
783 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
784 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
786 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
787 if (!g_bShowOnTaskBar &&
788 (nCmdShow == SW_SHOWMINIMIZED ||
789 nCmdShow == SW_MINIMIZE ||
790 nCmdShow == SW_SHOWMINNOACTIVE))
795 ShowWindow(hwnd, nCmdShow);
798 GetClientRect(g_hwndLogFrame, &rcClient);
799 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
806 /*********************************************************************
808 * Function : InitRichEdit
810 * Description : Initialise the rich edit control library.
814 * Returns : TRUE => success, FALSE => failure.
815 * FIXME: this is backwards to the rest of IJB and to common
816 * programming practice. Please use 0 => success instead.
818 *********************************************************************/
819 BOOL InitRichEdit(void)
821 static HINSTANCE hInstRichEdit;
822 if (hInstRichEdit == NULL)
824 g_nRichEditVersion = 0;
825 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
828 g_nRichEditVersion = _RICHEDIT_VER;
832 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
835 g_nRichEditVersion = 0x0100;
839 return (hInstRichEdit != NULL) ? TRUE : FALSE;
844 /*********************************************************************
846 * Function : ShowLogWindow
848 * Description : Shows or hides the log window. We will also raise the
849 * window on a show command in case it is buried.
852 * 1 : bShow = TRUE to show, FALSE to mimize/hide
856 *********************************************************************/
857 void ShowLogWindow(BOOL bShow)
861 SetForegroundWindow(g_hwndLogFrame);
862 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
864 else if (g_bShowOnTaskBar)
866 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
870 ShowWindow(g_hwndLogFrame, SW_HIDE);
876 /*********************************************************************
878 * Function : EditFile
880 * Description : Opens the specified setting file for editing.
883 * 1 : filename = filename from the config (aka junkbstr.txt) file.
887 *********************************************************************/
888 void EditFile(const char *filename)
892 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
898 /*--------------------------------------------------------------------------*/
899 /* Windows message handlers */
900 /*--------------------------------------------------------------------------*/
903 /*********************************************************************
905 * Function : OnLogRButtonUp
907 * Description : Handler for WM_RBUTTONUP messages.
910 * 1 : nModifier = wParam from mouse message (unused)
911 * 2 : x = x coordinate of the mouse event
912 * 3 : y = y coordinate of the mouse event
916 *********************************************************************/
917 void OnLogRButtonUp(int nModifier, int x, int y)
919 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
922 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
925 /* Check if there is a selection */
927 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
928 if (range.cpMin == range.cpMax)
930 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
934 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
937 /* Check if cursor is over a link */
938 szURL = LogGetURLUnderCursor();
942 TCHAR szMenuItemTemplate[1000];
945 memset(&item, 0, sizeof(item));
946 item.cbSize = sizeof(item);
947 item.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
948 item.fType = MFT_STRING;
949 item.fState = MFS_ENABLED;
950 item.wID = ID_NEW_BLOCKER;
952 /* Put the item into the menu */
953 memset(szMenuItemTemplate, 0, sizeof(szMenuItemTemplate));
954 LoadString(g_hInstance, IDS_NEW_BLOCKER, szMenuItemTemplate, sizeof(szMenuItemTemplate) / sizeof(szMenuItemTemplate[0]));
956 szMenuItem = (char *)malloc(strlen(szMenuItemTemplate) + strlen(szURL) + 1);
957 sprintf(szMenuItem, szMenuItemTemplate, szURL);
959 item.dwTypeData = szMenuItem;
960 item.cch = strlen(szMenuItem);
962 InsertMenuItem(hMenuPopup, 1, TRUE, &item);
964 SetDefaultRule(szURL);
969 /* Display the popup */
970 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
977 /*********************************************************************
979 * Function : OnLogCommand
981 * Description : Handler for WM_COMMAND messages.
984 * 1 : nCommand = the command portion of the menu selection event
988 *********************************************************************/
989 void OnLogCommand(int nCommand)
998 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1002 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1005 case ID_VIEW_CLEARLOG:
1006 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1009 case ID_VIEW_LOGMESSAGES:
1010 g_bLogMessages = !g_bLogMessages;
1011 /* SaveLogSettings(); */
1014 case ID_VIEW_MESSAGEHIGHLIGHTING:
1015 g_bHighlightMessages = !g_bHighlightMessages;
1016 /* SaveLogSettings(); */
1019 case ID_VIEW_LIMITBUFFERSIZE:
1020 g_bLimitBufferSize = !g_bLimitBufferSize;
1021 /* SaveLogSettings(); */
1024 case ID_VIEW_ACTIVITYANIMATION:
1025 g_bShowActivityAnimation = !g_bShowActivityAnimation;
1026 /* SaveLogSettings(); */
1030 /* by haroon - change toggle to its opposite value */
1032 g_bToggleIJB = !g_bToggleIJB;
1035 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1039 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1044 case ID_RELOAD_CONFIG:
1050 log_error(LOG_LEVEL_ERROR, "load_config encountered a problem! You should probably restart IJB.");
1054 log_error(LOG_LEVEL_INFO, "Configuration has been reloaded.");
1058 case ID_TOOLS_EDITJUNKBUSTER:
1059 EditFile(configfile);
1062 case ID_TOOLS_EDITBLOCKERS:
1063 EditFile(blockfile);
1066 case ID_TOOLS_EDITPERMISSIONS:
1067 EditFile(permissions_file);
1070 case ID_TOOLS_EDITFORWARD:
1071 EditFile(forwardfile);
1075 case ID_TOOLS_EDITACLS:
1078 #endif /* def ACL_FILES */
1080 #ifdef USE_IMAGE_LIST
1081 case ID_TOOLS_EDITIMAGE:
1082 EditFile(imagefile);
1084 #endif /* def USE_IMAGE_LIST */
1087 case ID_TOOLS_EDITPERLRE:
1088 EditFile(re_filterfile);
1093 case ID_TOOLS_EDITTRUST:
1094 EditFile(trustfile);
1096 #endif /* def TRUST_FILES */
1098 case ID_NEW_BLOCKER:
1099 ShowRulesDialog(g_hwndLogFrame);
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_EDITPERMISSIONS, MF_BYCOMMAND | (permissions_file ? MF_ENABLED : MF_GRAYED));
1147 EnableMenuItem(hmenu, ID_TOOLS_EDITBLOCKERS, MF_BYCOMMAND | (blockfile ? MF_ENABLED : MF_GRAYED));
1148 EnableMenuItem(hmenu, ID_TOOLS_EDITFORWARD, MF_BYCOMMAND | (forwardfile ? MF_ENABLED : MF_GRAYED));
1150 EnableMenuItem(hmenu, ID_TOOLS_EDITACLS, MF_BYCOMMAND | (aclfile ? MF_ENABLED : MF_GRAYED));
1151 #endif /* def ACL_FILES */
1152 #ifdef USE_IMAGE_LIST
1153 EnableMenuItem(hmenu, ID_TOOLS_EDITIMAGE, MF_BYCOMMAND | (imagefile ? MF_ENABLED : MF_GRAYED));
1154 #endif /* def USE_IMAGE_LIST */
1156 EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (re_filterfile ? MF_ENABLED : MF_GRAYED));
1159 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (trustfile ? MF_ENABLED : MF_GRAYED));
1160 #endif /* def TRUST_FILES */
1162 /* Check/uncheck options */
1163 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1164 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1165 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1166 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1168 /* by haroon - menu item for Enable toggle on/off */
1169 CheckMenuItem(hmenu, ID_TOGGLE_IJB, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1175 /*********************************************************************
1177 * Function : OnLogTimer
1179 * Description : Handler for WM_TIMER messages.
1182 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1186 *********************************************************************/
1187 void OnLogTimer(int nTimer)
1192 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1195 case TIMER_ANIMSTOP_ID:
1197 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1198 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1199 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1202 case TIMER_CLIPBUFFER_ID:
1203 case TIMER_CLIPBUFFER_FORCE_ID:
1205 g_bClipPending = FALSE;
1206 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1207 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1218 /*********************************************************************
1220 * Function : LogRichEditProc
1222 * Description : Window subclass routine handles some events for the rich edit control.
1225 * 1 : hwnd = window handle of the rich edit control
1226 * 2 : uMsg = message number
1227 * 3 : wParam = first param for this message
1228 * 4 : lParam = next param for this message
1230 * Returns : Appropriate M$ window message handler codes.
1232 *********************************************************************/
1233 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1240 pt.x = LOWORD(lParam);
1241 pt.y = HIWORD(lParam);
1242 ClientToScreen(hwnd, &pt);
1243 OnLogRButtonUp(wParam, pt.x, pt.y);
1247 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1252 /*********************************************************************
1254 * Function : LogWindowProc
1256 * Description : Windows call back routine handles events on the log window.
1259 * 1 : hwnd = handle of the logging window
1260 * 2 : uMsg = message number
1261 * 3 : wParam = first param for this message
1262 * 4 : lParam = next param for this message
1264 * Returns : Appropriate M$ window message handler codes.
1266 *********************************************************************/
1267 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1275 /* This is the end - beautiful friend - the end */
1276 DestroyWindow(g_hwndLogBox);
1277 DestroyWindow(g_hwndLogFrame);
1286 /* Resize the logging window to fit the new frame */
1290 GetClientRect(g_hwndLogFrame, &rc);
1291 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1296 OnLogInitMenu((HMENU) wParam);
1304 OnLogCommand(LOWORD(wParam));
1311 if (g_bCloseHidesWindow)
1313 ShowLogWindow(FALSE);
1318 ShowLogWindow(FALSE);
1324 return DefWindowProc(hwnd, uMsg, wParam, lParam);
1328 #endif /* ndef _WIN_CONSOLE - entire file */