From: ben Date: Fri, 7 Feb 2003 01:38:12 +0000 (+0000) Subject: Crude Event Log implementation for the Mac. I'm fairly convinced now that X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/commitdiff_plain/7dcd1f879d7a6d11cc7c4f67ee75a745578a46ad Crude Event Log implementation for the Mac. I'm fairly convinced now that using the List Manager was entirely the wrong decision on my part, so I'll probably rewrite this to use TextEdit at some point, but it's better than stderr even so. git-svn-id: svn://svn.tartarus.org/sgt/putty@2811 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/Recipe b/Recipe index cbf8cefa..e5589445 100644 --- a/Recipe +++ b/Recipe @@ -152,9 +152,9 @@ pterm : [X] pterm terminal wcwidth uxucs uxmisc tree234 misc ldisc ldiscucs plink : [U] uxplink uxcons NONSSH UXSSH be_all logging UXMISC signal ux_x11 -PuTTY : [M] terminal wcwidth ldiscucs logging be_all mac macdlg +PuTTY : [M] terminal wcwidth ldiscucs logging be_all mac macdlg macevlog + macterm macucs mac_res.rsrc testback NONSSH MACSSH MACMISC CHARSET + stricmp vsnprint -PuTTYtel : [M] terminal wcwidth ldiscucs logging be_nossh mac macdlg +PuTTYtel : [M] terminal wcwidth ldiscucs logging be_nossh mac macdlg macevlog + macterm macucs mac_res.rsrc testback NONSSH MACMISC CHARSET + stricmp vsnprint diff --git a/mac/mac.c b/mac/mac.c index 4c317ed4..c11566d0 100644 --- a/mac/mac.c +++ b/mac/mac.c @@ -1,4 +1,4 @@ -/* $Id: mac.c,v 1.46 2003/02/07 01:33:24 ben Exp $ */ +/* $Id: mac.c,v 1.47 2003/02/07 01:38:12 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -362,6 +362,9 @@ static void mac_contentclick(WindowPtr window, EventRecord *event) { case wSettings: mac_clickdlg(window, event); break; + case wEventLog: + mac_clickeventlog(window, event); + break; } } @@ -370,6 +373,10 @@ static void mac_growwindow(WindowPtr window, EventRecord *event) { switch (mac_windowtype(window)) { case wTerminal: mac_growterm(window, event); + break; + case wEventLog: + mac_groweventlog(window, event); + break; } } @@ -388,6 +395,9 @@ static void mac_activatewindow(WindowPtr window, EventRecord *event) { case wAbout: mac_activateabout(window, event); break; + case wEventLog: + mac_activateeventlog(window, event); + break; } } @@ -432,6 +442,9 @@ static void mac_updatewindow(WindowPtr window) case wLicence: mac_updatelicence(window); break; + case wEventLog: + mac_updateeventlog(window); + break; } } @@ -674,6 +687,8 @@ static void mac_adjustmenus(void) { DisableItem(menu, iDuplicate); menu = GetMenuHandle(mEdit); DisableItem(menu, 0); + menu = GetMenuHandle(mWindow); + DisableItem(menu, 0); /* Until we get more than 1 item on it. */ break; } DrawMenuBar(); diff --git a/mac/mac.h b/mac/mac.h index 0ab3d06b..dfe7285a 100644 --- a/mac/mac.h +++ b/mac/mac.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,8 @@ typedef struct Session { Point font_bigdenom; WindowPtr window; WindowPtr settings_window; + WindowPtr eventlog_window; + ListHandle eventlog; PaletteHandle palette; ControlHandle scrollbar; WCTabHandle wctab; @@ -100,6 +103,13 @@ extern void mac_savesession(void); extern void mac_savesessionas(void); extern void mac_clickdlg(WindowPtr, EventRecord *); extern void mac_activatedlg(WindowPtr, EventRecord *); +/* from maceventlog.c */ +void mac_freeeventlog(Session *); +extern void mac_clickeventlog(WindowPtr, EventRecord *); +extern void mac_activateeventlog(WindowPtr, EventRecord *); +extern void mac_groweventlog(WindowPtr, EventRecord *); +extern void mac_updateeventlog(WindowPtr); +extern void mac_showeventlog(Session *); /* from macterm.c */ extern void mac_opensession(void); extern void mac_startsession(Session *); diff --git a/mac/mac_res.r b/mac/mac_res.r index 6105a559..cefcfbeb 100644 --- a/mac/mac_res.r +++ b/mac/mac_res.r @@ -1,4 +1,4 @@ -/* $Id: mac_res.r,v 1.25 2003/02/02 15:59:00 ben Exp $ */ +/* $Id: mac_res.r,v 1.26 2003/02/07 01:38:12 ben Exp $ */ /* * Copyright (c) 1999, 2002 Ben Harris * All rights reserved. @@ -899,7 +899,7 @@ resource 'TMPL' (TMPL_Int, "Int ", purgeable) { /* Menu bar */ resource 'MBAR' (MBAR_Main, preload) { - { mApple, mFile, mEdit } + { mApple, mFile, mEdit, mWindow } }; resource 'MENU' (mApple, preload) { @@ -950,6 +950,17 @@ resource 'MENU' (mEdit, preload) { } }; +resource 'MENU' (mWindow, preload) { + mWindow, + textMenuProc, + 0b11111111111111111111111111111111, + enabled, + "Window", + { + "Show Event Log", noicon, nokey, nomark, plain, + } +}; + /* Fatal error box. Stolen from the Finder. */ resource 'ALRT' (wFatal, "fatalbox", purgeable) { @@ -1026,6 +1037,17 @@ resource 'DITL' (wSettings, "settings", purgeable) { } }; +/* Event log */ +resource 'WIND' (wEventLog, "event log", purgeable) { + { 0, 0, 200, 200 }, + zoomDocProc, + invisible, + goAway, + 0x0, + "PuTTY Event Log", + staggerParentWindowScreen +}; + /* "About" box */ resource 'DLOG' (wAbout, "about", purgeable) { diff --git a/mac/macevlog.c b/mac/macevlog.c new file mode 100644 index 00000000..2bc89299 --- /dev/null +++ b/mac/macevlog.c @@ -0,0 +1,253 @@ +/* $Id: macevlog.c,v 1.1 2003/02/07 01:38:12 ben Exp $ */ +/* + * Copyright (c) 2003 Ben Harris + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "putty.h" +#include "mac.h" +#include "macresid.h" +#include "terminal.h" + +static void mac_draweventloggrowicon(Session *s); +static void mac_adjusteventlogscrollbar(Session *s); + +static void mac_createeventlog(Session *s) +{ + Rect view; +#if TARGET_API_MAC_CARBON + Rect controlrect; +#endif + ListBounds bounds = { 0, 0, 0, 1 }; /* 1 column, 0 rows */ + Point csize = { 0, 0 }; + GrafPtr saveport; + long fondsize; + WinInfo *wi; + + s->eventlog_window = GetNewWindow(wEventLog, NULL, (WindowPtr)-1); + wi = smalloc(sizeof(*wi)); + wi->s = s; + wi->wtype = wEventLog; + SetWRefCon(s->eventlog_window, (long)wi); + GetPort(&saveport); + SetPort((GrafPtr)GetWindowPort(s->eventlog_window)); + fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize); + TextFont(HiWord(fondsize)); + TextSize(LoWord(fondsize)); + SetPort(saveport); +#if TARGET_API_MAC_CARBON + GetPortBounds(GetWindowPort(s->eventlog_window), &view); +#else + view = s->eventlog_window->portRect; +#endif + view.right -= 15; /* Scrollbar */ + s->eventlog = LNew(&view, &bounds, csize, 0, s->eventlog_window, + TRUE, TRUE, FALSE, TRUE); + mac_adjusteventlogscrollbar(s); +#if TARGET_API_MAC_CARBON + SetListSelectionFlags(s->eventlog, lExtendDrag | lNoDisjoint | lNoExtend); +#else + (*s->eventlog)->selFlags = lExtendDrag | lNoDisjoint | lNoExtend; +#endif + ShowWindow(s->eventlog_window); +} + +void mac_freeeventlog(Session *s) +{ + + if (s->eventlog != NULL) + LDispose(s->eventlog); + if (s->eventlog_window != NULL) { + sfree((WinInfo *)GetWRefCon(s->eventlog_window)); + DisposeWindow(s->eventlog_window); + } +} + +/* + * FIXME: logevent() should be passed a frontend handle, but backends have to + * have a terminal handle instead, because they pass it to from_backend(), + * so we accept a terminal handle here as well, and hope no-one tries to call + * us with sensible arguments. + */ +void logevent(void *frontend, char *str) +{ + Terminal *term = frontend; + Session *s = term->frontend; + ListBounds bounds; + Cell cell = { 0, 0 }; + + if (s->eventlog == NULL) + mac_createeventlog(s); + if (s->eventlog == NULL) + return; + +#if TARGET_API_MAC_CARBON + GetListDataBounds(s->eventlog, &bounds); +#else + bounds = (*s->eventlog)->dataBounds; +#endif + cell.v = bounds.bottom; + LAddRow(1, cell.v, s->eventlog); + LSetCell(str, strlen(str), cell, s->eventlog); +} + +static void mac_draweventloggrowicon(Session *s) +{ + Rect clip; + RgnHandle savergn; + + SetPort((GrafPtr)GetWindowPort(s->eventlog_window)); + /* + * Stop DrawGrowIcon giving us space for a horizontal scrollbar + * See Tech Note TB575 for details. + */ +#if TARGET_API_MAC_CARBON + GetPortBounds(GetWindowPort(s->eventlog_window), &clip); +#else + clip = s->eventlog_window->portRect; +#endif + clip.left = clip.right - 15; + savergn = NewRgn(); + GetClip(savergn); + ClipRect(&clip); + DrawGrowIcon(s->eventlog_window); + SetClip(savergn); + DisposeRgn(savergn); +} + +/* + * For some reason, LNew doesn't seem to respect the hasGrow + * parameter, so we hammer the scrollbar into shape ourselves. + */ +static void mac_adjusteventlogscrollbar(Session *s) +{ +#if TARGET_API_MAC_CARBON + Rect winrect; + + GetPortBounds(GetWindowPort(s->eventlog_window), &winrect); + SizeControl(GetListVerticalScrollBar(s->eventlog), + 16, winrect.bottom - 13); +#else + SizeControl((*s->eventlog)->vScroll, + 16, s->eventlog_window->portRect.bottom - 13); +#endif +} + +void mac_clickeventlog(WindowPtr window, EventRecord *event) +{ + Session *s = mac_windowsession(window); + Point mouse; + GrafPtr saveport; + + GetPort(&saveport); + SetPort((GrafPtr)GetWindowPort(window)); + mouse = event->where; + GlobalToLocal(&mouse); + LClick(mouse, event->modifiers, s->eventlog); + SetPort(saveport); +} + +void mac_groweventlog(WindowPtr window, EventRecord *event) +{ + Session *s = mac_windowsession(window); + Rect limits; + long grow_result; +#if TARGET_API_MAC_CARBON + Rect rect; + Point cellsize; +#else + GrafPtr saveport; +#endif + + SetRect(&limits, 15, 0, SHRT_MAX, SHRT_MAX); + grow_result = GrowWindow(window, event->where, &limits); + if (grow_result == 0) return; + SizeWindow(window, LoWord(grow_result), HiWord(grow_result), TRUE); + LSize(LoWord(grow_result) - 15, HiWord(grow_result), s->eventlog); + mac_adjusteventlogscrollbar(s); + /* We would use SetListCellSize in Carbon, but it's missing. */ + (*s->eventlog)->cellSize.h = LoWord(grow_result) - 15; +#if TARGET_API_MAC_CARBON + cellsize.h = LoWord(grow_result) - 15; + GetListViewBounds(s->eventlog, &rect); + InvalWindowRect(window, &rect); +#else + GetPort(&saveport); + SetPort(window); + InvalRect(&(*s->eventlog)->rView); + SetPort(saveport); +#endif +} + +void mac_activateeventlog(WindowPtr window, EventRecord *event) +{ + Session *s = mac_windowsession(window); + int active = (event->modifiers & activeFlag) != 0; + + LActivate(active, s->eventlog); + mac_draweventloggrowicon(s); +} + +void mac_updateeventlog(WindowPtr window) +{ + Session *s = mac_windowsession(window); +#if TARGET_API_MAC_CARBON + RgnHandle visrgn; +#endif + + SetPort((GrafPtr)GetWindowPort(window)); + BeginUpdate(window); +#if TARGET_API_MAC_CARBON + visrgn = NewRgn(); + GetPortVisibleRegion(GetWindowPort(window), visrgn); + LUpdate(visrgn, s->eventlog); + DisposeRgn(visrgn); +#else + LUpdate(window->visRgn, s->eventlog); +#endif + mac_draweventloggrowicon(s); + EndUpdate(window); +} + +void mac_showeventlog(Session *s) +{ + + ShowWindow(s->eventlog_window); +} + +/* + * Local Variables: + * c-file-style: "simon" + * End: + */ diff --git a/mac/macresid.h b/mac/macresid.h index 1cfc5ccf..ebb9f0de 100644 --- a/mac/macresid.h +++ b/mac/macresid.h @@ -1,4 +1,4 @@ -/* $Id: macresid.h,v 1.8 2003/02/02 15:59:00 ben Exp $ */ +/* $Id: macresid.h,v 1.9 2003/02/07 01:38:12 ben Exp $ */ /* * macresid.h -- Mac resource IDs @@ -19,6 +19,7 @@ #define mApple 128 #define mFile 129 #define mEdit 130 +#define mWindow 131 /* Menu Items */ /* Apple menu */ @@ -38,6 +39,8 @@ #define iPaste 5 #define iClear 6 #define iSelectAll 7 +/* Window menu */ +#define iShowEventLog 1 /* Window types (and resource IDs) */ #define wNone 0 /* Dummy value for no window */ @@ -50,6 +53,7 @@ #define wLicence 131 #define wSettings 132 #define wiSettingsOpen 1 +#define wEventLog 133 /* Controls */ #define cVScroll 128 diff --git a/mac/macterm.c b/mac/macterm.c index 52c33b86..fbf9412c 100644 --- a/mac/macterm.c +++ b/mac/macterm.c @@ -1,4 +1,4 @@ -/* $Id: macterm.c,v 1.68 2003/02/04 23:39:26 ben Exp $ */ +/* $Id: macterm.c,v 1.69 2003/02/07 01:38:12 ben Exp $ */ /* * Copyright (c) 1999 Simon Tatham * Copyright (c) 1999, 2002 Ben Harris @@ -135,7 +135,7 @@ void mac_startsession(Session *s) ActivatePalette(s->window); } - s->logctx = log_init(s, &s->cfg); + s->logctx = log_init(s->term, &s->cfg); term_provide_logctx(s->term, s->logctx); errmsg = s->back->init(s->term, &s->backhandle, &s->cfg, s->cfg.host, @@ -462,6 +462,9 @@ void mac_adjusttermmenus(WindowPtr window) { EnableItem(menu, iPaste); DisableItem(menu, iClear); EnableItem(menu, iSelectAll); + menu = GetMenuHandle(mWindow); + EnableItem(menu, 0); + EnableItem(menu, iShowEventLog); } void mac_menuterm(WindowPtr window, short menu, short item) { @@ -478,6 +481,14 @@ void mac_menuterm(WindowPtr window, short menu, short item) { term_do_paste(s->term); break; } + break; + case mWindow: + switch(item) { + case iShowEventLog: + mac_showeventlog(s); + break; + } + break; } } @@ -986,6 +997,7 @@ void mac_closeterm(WindowPtr window) if (s->uni_to_font != NULL) DisposeUnicodeToTextInfo(&s->uni_to_font); term_free(s->term); + mac_freeeventlog(s); sfree((WinInfo *)GetWRefCon(s->window)); DisposeWindow(s->window); DisposePalette(s->palette); @@ -1729,11 +1741,6 @@ void do_scroll(Context ctx, int topline, int botline, int lines) { DisposeRgn(update); } -void logevent(void *frontend, char *str) { - - fprintf(stderr, "%s\n", str); -} - /* Dummy routine, only required in plink. */ void ldisc_update(void *frontend, int echo, int edit) {