1 const char w32log_rcs[] = "$Id: w32log.c,v 1.1.1.1 2001/05/15 13:59:07 oes 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.1.1.1 2001/05/15 13:59:07 oes
36 * Initial import of version 2.9.3 source tree
39 *********************************************************************/
52 #include "w32taskbar.h"
53 #include "w32rulesdlg.h"
60 const char w32res_h_rcs[] = W32RES_H_VERSION;
64 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
67 const char w32log_h_rcs[] = W32LOG_H_VERSION;
70 * Timers and the various durations
72 #define TIMER_ANIM_ID 1
73 #define TIMER_ANIM_TIME 100
74 #define TIMER_ANIMSTOP_ID 2
75 #define TIMER_ANIMSTOP_TIME 1000
76 #define TIMER_CLIPBUFFER_ID 3
77 #define TIMER_CLIPBUFFER_TIME 1000
78 #define TIMER_CLIPBUFFER_FORCE_ID 4
79 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
82 * Styles of text that can be output
85 #define STYLE_HIGHLIGHT 1
87 #define STYLE_HEADER 3
90 * Number of frames of animation in tray activity sequence
94 #define DEFAULT_MAX_BUFFER_LINES 200
95 #define DEFAULT_LOG_FONT_NAME "MS Sans Serif"
96 #define DEFAULT_LOG_FONT_SIZE 8
99 * These values affect the way the log window behaves, they should be read
100 * from a file but for the moment, they are hardcoded here. Some options are
101 * configurable through the UI.
104 /* Indicates whether task bar shows activity animation */
105 BOOL g_bShowActivityAnimation = 1;
107 /* Indicates if the log window appears on the task bar */
108 BOOL g_bShowOnTaskBar = 0;
110 /* Indicates whether closing the log window really just hides it */
111 BOOL g_bCloseHidesWindow = 1;
113 /* Indicates if messages are logged at all */
114 BOOL g_bLogMessages = 1;
116 /* Indicates whether log messages are highlighted */
117 BOOL g_bHighlightMessages = 1;
119 /* Indicates if buffer is limited in size */
120 BOOL g_bLimitBufferSize = 1;
122 /* Maximum number of lines allowed in buffer when limited */
123 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
126 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
128 /* Size of font to use */
129 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
133 /* Regular expression for detected URLs */
134 #define RE_URL "http:[^ \n\r]*"
137 * Regular expressions that are used to perform highlight in the log window
139 static struct _Pattern
144 } patterns_to_highlight[] =
147 { RE_URL, STYLE_LINK },
148 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
149 /* interesting text to highlight */
150 { "crunch!", STYLE_HIGHLIGHT },
152 { "referer:", STYLE_HEADER },
153 { "proxy-connection:", STYLE_HEADER },
154 { "proxy-agent:", STYLE_HEADER },
155 { "user-agent:", STYLE_HEADER },
156 { "host:", STYLE_HEADER },
157 { "accept:", STYLE_HEADER },
158 { "accept-encoding:", STYLE_HEADER },
159 { "accept-language:", STYLE_HEADER },
160 { "accept-charset:", STYLE_HEADER },
161 { "accept-ranges:", STYLE_HEADER },
162 { "date:", STYLE_HEADER },
163 { "cache-control:", STYLE_HEADER },
164 { "cache-last-checked:", STYLE_HEADER },
165 { "connection:", STYLE_HEADER },
166 { "content-type", STYLE_HEADER },
167 { "content-length", STYLE_HEADER },
168 { "cookie", STYLE_HEADER },
169 { "last-modified:", STYLE_HEADER },
170 { "pragma:", STYLE_HEADER },
171 { "server:", STYLE_HEADER },
172 { "etag:", STYLE_HEADER },
173 { "expires:", STYLE_HEADER },
174 { "warning:", STYLE_HEADER },
175 /* this is the terminator statement - do not delete! */
178 #endif /* def REGEX */
189 static CRITICAL_SECTION g_criticalsection;
190 static HWND g_hwndTray;
191 static HWND g_hwndLogBox;
192 static WNDPROC g_fnLogBox;
193 static HICON g_hiconAnim[ANIM_FRAMES];
194 static HICON g_hiconIdle;
195 static HICON g_hiconApp;
196 static int g_nAnimFrame;
197 static BOOL g_bClipPending = FALSE;
198 static int g_nRichEditVersion = 0;
203 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
204 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
205 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
206 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
207 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
208 static BOOL InitRichEdit(void);
209 static void LogClipBuffer(void);
210 static void LogCreatePatternMatchingBuffers(void);
211 static void LogDestroyPatternMatchingBuffers(void);
212 static int LogPutStringNoMatch(const char *pszText, int style);
215 /*********************************************************************
217 * Function : InitLogWindow
219 * Description : Initialise the log window.
223 * Returns : Always TRUE (there should be error checking on the resources).
225 *********************************************************************/
226 BOOL InitLogWindow(void)
231 g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
232 for (i = 0; i < ANIM_FRAMES; i++)
234 g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER1 + i));
236 g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER));
238 /* Create the user interface */
239 g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
240 g_hwndTray = CreateTrayWindow(g_hInstance);
241 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Junkbuster");
243 /* Create pattern matching buffers (for highlighting */
244 LogCreatePatternMatchingBuffers();
246 /* Create a critical section to protect multi-threaded access to certain things */
247 InitializeCriticalSection(&g_criticalsection);
254 /*********************************************************************
256 * Function : TermLogWindow
258 * Description : Cleanup the logwindow.
264 *********************************************************************/
265 void TermLogWindow(void)
269 LogDestroyPatternMatchingBuffers();
271 TrayDeleteIcon(g_hwndTray, 1);
272 DeleteObject(g_hiconApp);
273 DeleteObject(g_hiconIdle);
274 for (i = 0; i < ANIM_FRAMES; i++)
276 DeleteObject(g_hiconAnim[i]);
282 /*********************************************************************
284 * Function : LogCreatePatternMatchingBuffers
286 * Description : Compile the pattern matching buffers.
292 *********************************************************************/
293 void LogCreatePatternMatchingBuffers(void)
297 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
299 regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
306 /*********************************************************************
308 * Function : LogDestroyPatternMatchingBuffers
310 * Description : Free up the pattern matching buffers.
316 *********************************************************************/
317 void LogDestroyPatternMatchingBuffers(void)
321 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
323 regfree(&patterns_to_highlight[i].buffer);
330 /*********************************************************************
332 * Function : LogGetURLUnderCursor
334 * Description : Returns the URL from under the cursor (remember to free it!).
338 * Returns : NULL or a pointer to an URL string.
340 *********************************************************************/
341 char *LogGetURLUnderCursor(void)
343 char *szResult = NULL;
349 DWORD nWordStart = 0;
352 regcomp(&re, RE_URL, REG_ICASE);
354 /* Get the position of the cursor over the text window */
355 GetCursorPos(&ptCursor);
356 ScreenToClient(g_hwndLogBox, &ptCursor);
360 /* Search backwards and fowards to obtain the word that is highlighted */
361 nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
362 nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
363 nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
365 /* Compare the string to the pattern */
366 if (nWordEnd > nWordStart)
371 range.chrg.cpMin = nWordStart;
372 range.chrg.cpMax = nWordEnd;
373 range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
374 SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
376 if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
378 szResult = range.lpstrText;
382 free(range.lpstrText);
393 /*********************************************************************
395 * Function : LogPutString
397 * Description : Inserts text into the logging window. This is really
398 * a REGEXP aware wrapper function to `LogPutStringNoMatch'.
401 * 1 : pszText = pointer to string going to the log window
403 * Returns : 1 => success, else the return code from `LogPutStringNoMatch'.
404 * FIXME: this is backwards to the rest of IJB and to common
405 * programming practice. Please use 0 => success instead.
407 *********************************************************************/
408 int LogPutString(const char *pszText)
415 if (pszText == NULL || strlen(pszText) == 0)
425 /* Critical section stops multiple threads doing nasty interactions that
426 * foul up the highlighting and output.
428 EnterCriticalSection(&g_criticalsection);
431 if (g_bHighlightMessages)
435 /* First things first, regexp scan for various things that we would like highlighted */
436 for (i = 0; patterns_to_highlight[i].str != NULL; i++)
438 if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
440 char *pszBefore = NULL;
441 char *pszMatch = NULL;
442 char *pszAfter = NULL;
445 /* Split the string up into pieces representing the strings, before
446 at and after the matching pattern
450 pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
451 memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
452 strncpy(pszBefore, pszText, match.rm_so);
454 if (match.rm_eo < strlen(pszText))
456 pszAfter = strdup(&pszText[match.rm_eo]);
458 nMatchSize = match.rm_eo - match.rm_so;
459 pszMatch = (char *)malloc(nMatchSize + 1);
460 strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
461 pszMatch[nMatchSize] = '\0';
463 /* Recursively call LogPutString */
466 LogPutString(pszBefore);
471 LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
476 LogPutString(pszAfter);
487 result = LogPutStringNoMatch(pszText, STYLE_NONE);
492 LeaveCriticalSection(&g_criticalsection);
499 /*********************************************************************
501 * Function : LogPutStringNoMatch
503 * Description : Puts a string into the logging window.
506 * 1 : pszText = pointer to string going to the log window
507 * 2 : style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
509 * Returns : Always 1 => success.
510 * FIXME: this is backwards to the rest of IJB and to common
511 * programming practice. Please use 0 => success instead.
513 *********************************************************************/
514 int LogPutStringNoMatch(const char *pszText, int style)
520 assert(g_hwndLogBox);
521 if (g_hwndLogBox == NULL)
526 /* TODO preserve existing selection */
528 /* Go to the end of the text */
529 nTextLength = GetWindowTextLength(g_hwndLogBox);
530 range.cpMin = nTextLength;
531 range.cpMax = nTextLength;
532 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
534 /* Apply a formatting style */
535 memset(&format, 0, sizeof(format));
536 format.cbSize = sizeof(format);
537 format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
538 format.yHeight = (g_nFontSize * 1440) / 72;
539 strcpy(format.szFaceName, g_szFontFaceName);
540 if (style == STYLE_NONE)
543 format.dwEffects |= CFE_AUTOCOLOR;
545 else if (style == STYLE_HEADER)
547 format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
549 else if (style == STYLE_HIGHLIGHT)
551 format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
553 else if (style == STYLE_LINK)
555 format.dwEffects |= CFE_UNDERLINE;
556 format.crTextColor = RGB(0, 0, 255);
558 SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
560 /* Append text to the end */
561 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
563 /* TODO Restore the old selection */
566 if (strchr(pszText, '\n') != NULL)
568 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
571 /* Set the force clip timer going. This timer ensures clipping is done
572 intermittently even when there is a sustained burst of logging
574 SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
576 g_bClipPending = TRUE;
584 /*********************************************************************
586 * Function : LogShowActivity
588 * Description : Start the spinner.
594 *********************************************************************/
595 void LogShowActivity(void)
597 /* Start some activity timers */
598 if (g_bShowActivityAnimation)
600 SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
601 SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
607 /*********************************************************************
609 * Function : LogClipBuffer
611 * Description : Prunes old lines from the log.
617 *********************************************************************/
618 void LogClipBuffer(void)
620 int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
621 if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
623 /* Compute the range representing the lines to be deleted */
624 LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
625 LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
628 range.cpMax = nLastChar;
630 /* TODO get current selection */
632 /* TODO adjust and clip old selection against range to be deleted */
634 /* Select range and erase it (turning off autoscroll to prevent
636 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
637 SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
638 SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
639 SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
641 /* Restore old selection */
647 /*********************************************************************
649 * Function : CreateHiddenLogOwnerWindow
651 * Description : Creates a hidden owner window that stops the log
652 * window appearing in the task bar.
655 * 1 : hInstance = application's instance handle
657 * Returns : Handle to newly created window.
659 *********************************************************************/
660 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
662 static const char *szWndName = "JunkbusterLogLogOwner";
667 wc.lpfnWndProc = LogOwnerWindowProc;
670 wc.hInstance = hInstance;
673 wc.hbrBackground = 0;
675 wc.lpszClassName = szWndName;
679 hwnd = CreateWindow(szWndName, szWndName,
680 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
681 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
688 /*********************************************************************
690 * Function : LogOwnerWindowProc
692 * Description : Dummy procedure that does nothing special.
695 * 1 : hwnd = window handle
696 * 2 : uMsg = message number
697 * 3 : wParam = first param for this message
698 * 4 : lParam = next param for this message
700 * Returns : Same as `DefWindowProc'.
702 *********************************************************************/
703 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
705 return DefWindowProc(hwnd, uMsg, wParam, lParam);
710 /*********************************************************************
712 * Function : CreateLogWindow
714 * Description : Create the logging window.
717 * 1 : hInstance = application's instance handle
718 * 2 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
720 * Returns : Handle to newly created window.
722 *********************************************************************/
723 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
725 static const char *szWndName = "JunkbusterLogWindow";
726 static const char *szWndTitle = "Junkbuster";
729 HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
730 HWND hwndChild = NULL;
734 memset(&wc, 0, sizeof(wc));
735 wc.cbSize = sizeof(wc);
736 wc.style = CS_DBLCLKS;
737 wc.lpfnWndProc = LogWindowProc;
740 wc.hInstance = hInstance;
741 wc.hIcon = g_hiconApp;
743 wc.hbrBackground = 0;
744 wc.lpszMenuName = MAKEINTRESOURCE(IDR_LOGVIEW);
745 wc.lpszClassName = szWndName;
746 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
747 RegisterClassEx(&wc);
749 hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
750 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
751 CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
753 /* Now create a child list box */
754 GetClientRect(hwnd, &rcClient);
756 /* Create a rich edit control */
758 g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
759 ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
760 rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
761 hwnd, NULL, hInstance, NULL);
762 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
764 /* Subclass the control to catch certain messages */
765 g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
766 SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
768 /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
769 if (!g_bShowOnTaskBar &&
770 (nCmdShow == SW_SHOWMINIMIZED ||
771 nCmdShow == SW_MINIMIZE ||
772 nCmdShow == SW_SHOWMINNOACTIVE))
777 ShowWindow(hwnd, nCmdShow);
780 GetClientRect(g_hwndLogFrame, &rcClient);
781 SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
788 /*********************************************************************
790 * Function : InitRichEdit
792 * Description : Initialise the rich edit control library.
796 * Returns : TRUE => success, FALSE => failure.
797 * FIXME: this is backwards to the rest of IJB and to common
798 * programming practice. Please use 0 => success instead.
800 *********************************************************************/
801 BOOL InitRichEdit(void)
803 static HINSTANCE hInstRichEdit;
804 if (hInstRichEdit == NULL)
806 g_nRichEditVersion = 0;
807 hInstRichEdit = LoadLibraryA("RICHED20.DLL");
810 g_nRichEditVersion = _RICHEDIT_VER;
814 hInstRichEdit = LoadLibraryA("RICHED32.DLL");
817 g_nRichEditVersion = 0x0100;
821 return (hInstRichEdit != NULL) ? TRUE : FALSE;
826 /*********************************************************************
828 * Function : ShowLogWindow
830 * Description : Shows or hides the log window. We will also raise the
831 * window on a show command in case it is buried.
834 * 1 : bShow = TRUE to show, FALSE to mimize/hide
838 *********************************************************************/
839 void ShowLogWindow(BOOL bShow)
843 SetForegroundWindow(g_hwndLogFrame);
844 SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
846 else if (g_bShowOnTaskBar)
848 ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
852 ShowWindow(g_hwndLogFrame, SW_HIDE);
858 /*********************************************************************
860 * Function : EditFile
862 * Description : Opens the specified setting file for editing.
865 * 1 : filename = filename from the config (aka junkbstr.txt) file.
869 *********************************************************************/
870 void EditFile(const char *filename)
874 ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
880 /*--------------------------------------------------------------------------*/
881 /* Windows message handlers */
882 /*--------------------------------------------------------------------------*/
885 /*********************************************************************
887 * Function : OnLogRButtonUp
889 * Description : Handler for WM_RBUTTONUP messages.
892 * 1 : nModifier = wParam from mouse message (unused)
893 * 2 : x = x coordinate of the mouse event
894 * 3 : y = y coordinate of the mouse event
898 *********************************************************************/
899 void OnLogRButtonUp(int nModifier, int x, int y)
901 HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
904 HMENU hMenuPopup = GetSubMenu(hMenu, 0);
907 /* Check if there is a selection */
909 SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
910 if (range.cpMin == range.cpMax)
912 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
916 EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
919 /* Check if cursor is over a link */
920 szURL = LogGetURLUnderCursor();
924 TCHAR szMenuItemTemplate[1000];
927 memset(&item, 0, sizeof(item));
928 item.cbSize = sizeof(item);
929 item.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
930 item.fType = MFT_STRING;
931 item.fState = MFS_ENABLED;
932 item.wID = ID_NEW_BLOCKER;
934 /* Put the item into the menu */
935 memset(szMenuItemTemplate, 0, sizeof(szMenuItemTemplate));
936 LoadString(g_hInstance, IDS_NEW_BLOCKER, szMenuItemTemplate, sizeof(szMenuItemTemplate) / sizeof(szMenuItemTemplate[0]));
938 szMenuItem = (char *)malloc(strlen(szMenuItemTemplate) + strlen(szURL) + 1);
939 sprintf(szMenuItem, szMenuItemTemplate, szURL);
941 item.dwTypeData = szMenuItem;
942 item.cch = strlen(szMenuItem);
944 InsertMenuItem(hMenuPopup, 1, TRUE, &item);
946 SetDefaultRule(szURL);
951 /* Display the popup */
952 TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
959 /*********************************************************************
961 * Function : OnLogCommand
963 * Description : Handler for WM_COMMAND messages.
966 * 1 : nCommand = the command portion of the menu selection event
970 *********************************************************************/
971 void OnLogCommand(int nCommand)
980 PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
984 SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
987 case ID_VIEW_CLEARLOG:
988 SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
991 case ID_VIEW_LOGMESSAGES:
992 g_bLogMessages = !g_bLogMessages;
993 /* SaveLogSettings(); */
996 case ID_VIEW_MESSAGEHIGHLIGHTING:
997 g_bHighlightMessages = !g_bHighlightMessages;
998 /* SaveLogSettings(); */
1001 case ID_VIEW_LIMITBUFFERSIZE:
1002 g_bLimitBufferSize = !g_bLimitBufferSize;
1003 /* SaveLogSettings(); */
1006 case ID_VIEW_ACTIVITYANIMATION:
1007 g_bShowActivityAnimation = !g_bShowActivityAnimation;
1008 /* SaveLogSettings(); */
1012 /* by haroon - change toggle to its opposite value */
1014 g_bToggleIJB = !g_bToggleIJB;
1017 log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1021 log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1026 case ID_RELOAD_CONFIG:
1032 log_error(LOG_LEVEL_ERROR, "load_config encountered a problem! You should probably restart IJB.");
1036 log_error(LOG_LEVEL_INFO, "Configuration has been reloaded.");
1040 case ID_TOOLS_EDITJUNKBUSTER:
1041 EditFile(configfile);
1044 case ID_TOOLS_EDITBLOCKERS:
1045 EditFile(blockfile);
1048 case ID_TOOLS_EDITPERMISSIONS:
1049 EditFile(permissions_file);
1052 case ID_TOOLS_EDITFORWARD:
1053 EditFile(forwardfile);
1057 case ID_TOOLS_EDITACLS:
1060 #endif /* def ACL_FILES */
1062 #ifdef USE_IMAGE_LIST
1063 case ID_TOOLS_EDITIMAGE:
1064 EditFile(imagefile);
1066 #endif /* def USE_IMAGE_LIST */
1069 case ID_TOOLS_EDITPERLRE:
1070 EditFile(re_filterfile);
1075 case ID_TOOLS_EDITTRUST:
1076 EditFile(trustfile);
1078 #endif /* def TRUST_FILES */
1080 case ID_NEW_BLOCKER:
1081 ShowRulesDialog(g_hwndLogFrame);
1085 ShellExecute(g_hwndLogFrame, "open", "gpl.html", NULL, NULL, SW_SHOWNORMAL);
1089 ShellExecute(g_hwndLogFrame, "open", "ijbfaq.html", NULL, NULL, SW_SHOWNORMAL);
1092 case ID_HELP_MANUAL:
1093 ShellExecute(g_hwndLogFrame, "open", "ijbman.html", NULL, NULL, SW_SHOWNORMAL);
1096 case ID_HELP_STATUS:
1097 ShellExecute(g_hwndLogFrame, "open", "Junkbuster Status.URL", NULL, NULL, SW_SHOWNORMAL);
1100 case ID_HELP_ABOUTJUNKBUSTER:
1101 MessageBox(g_hwndLogFrame, win32_blurb, "Junkbuster Information", MB_OK);
1112 /*********************************************************************
1114 * Function : OnLogInitMenu
1116 * Description : Handler for WM_INITMENU messages. Enable, disable,
1117 * check, and/or uncheck menu options as apropos.
1120 * 1 : hmenu = handle to menu to "make current"
1124 *********************************************************************/
1125 void OnLogInitMenu(HMENU hmenu)
1127 /* Only enable editors if there is a file to edit */
1128 EnableMenuItem(hmenu, ID_TOOLS_EDITPERMISSIONS, MF_BYCOMMAND | (permissions_file ? MF_ENABLED : MF_GRAYED));
1129 EnableMenuItem(hmenu, ID_TOOLS_EDITBLOCKERS, MF_BYCOMMAND | (blockfile ? MF_ENABLED : MF_GRAYED));
1130 EnableMenuItem(hmenu, ID_TOOLS_EDITFORWARD, MF_BYCOMMAND | (forwardfile ? MF_ENABLED : MF_GRAYED));
1132 EnableMenuItem(hmenu, ID_TOOLS_EDITACLS, MF_BYCOMMAND | (aclfile ? MF_ENABLED : MF_GRAYED));
1133 #endif /* def ACL_FILES */
1134 #ifdef USE_IMAGE_LIST
1135 EnableMenuItem(hmenu, ID_TOOLS_EDITIMAGE, MF_BYCOMMAND | (imagefile ? MF_ENABLED : MF_GRAYED));
1136 #endif /* def USE_IMAGE_LIST */
1138 EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (re_filterfile ? MF_ENABLED : MF_GRAYED));
1141 EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (trustfile ? MF_ENABLED : MF_GRAYED));
1142 #endif /* def TRUST_FILES */
1144 /* Check/uncheck options */
1145 CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1146 CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1147 CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1148 CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1150 /* by haroon - menu item for Enable toggle on/off */
1151 CheckMenuItem(hmenu, ID_TOGGLE_IJB, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1157 /*********************************************************************
1159 * Function : OnLogTimer
1161 * Description : Handler for WM_TIMER messages.
1164 * 1 : nTimer = timer id (animation start/stop or clip buffer)
1168 *********************************************************************/
1169 void OnLogTimer(int nTimer)
1174 TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1177 case TIMER_ANIMSTOP_ID:
1179 TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1180 KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1181 KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1184 case TIMER_CLIPBUFFER_ID:
1185 case TIMER_CLIPBUFFER_FORCE_ID:
1187 g_bClipPending = FALSE;
1188 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1189 KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1200 /*********************************************************************
1202 * Function : LogRichEditProc
1204 * Description : Window subclass routine handles some events for the rich edit control.
1207 * 1 : hwnd = window handle of the rich edit control
1208 * 2 : uMsg = message number
1209 * 3 : wParam = first param for this message
1210 * 4 : lParam = next param for this message
1212 * Returns : Appropriate M$ window message handler codes.
1214 *********************************************************************/
1215 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1222 pt.x = LOWORD(lParam);
1223 pt.y = HIWORD(lParam);
1224 ClientToScreen(hwnd, &pt);
1225 OnLogRButtonUp(wParam, pt.x, pt.y);
1229 return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1234 /*********************************************************************
1236 * Function : LogWindowProc
1238 * Description : Windows call back routine handles events on the log window.
1241 * 1 : hwnd = handle of the logging window
1242 * 2 : uMsg = message number
1243 * 3 : wParam = first param for this message
1244 * 4 : lParam = next param for this message
1246 * Returns : Appropriate M$ window message handler codes.
1248 *********************************************************************/
1249 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1257 /* This is the end - beautiful friend - the end */
1258 DestroyWindow(g_hwndLogBox);
1259 DestroyWindow(g_hwndLogFrame);
1268 /* Resize the logging window to fit the new frame */
1272 GetClientRect(g_hwndLogFrame, &rc);
1273 SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1278 OnLogInitMenu((HMENU) wParam);
1286 OnLogCommand(LOWORD(wParam));
1293 if (g_bCloseHidesWindow)
1295 ShowLogWindow(FALSE);
1300 ShowLogWindow(FALSE);
1306 return DefWindowProc(hwnd, uMsg, wParam, lParam);