1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00

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.

[originally from svn r2811]
This commit is contained in:
Ben Harris 2003-02-07 01:38:12 +00:00
parent 60c9d7bae3
commit 2c10ece60d
7 changed files with 324 additions and 13 deletions

4
Recipe
View File

@ -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 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 + macterm macucs mac_res.rsrc testback NONSSH MACSSH MACMISC CHARSET
+ stricmp vsnprint + 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 + macterm macucs mac_res.rsrc testback NONSSH MACMISC CHARSET
+ stricmp vsnprint + stricmp vsnprint

View File

@ -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 * Copyright (c) 1999 Ben Harris
* All rights reserved. * All rights reserved.
@ -362,6 +362,9 @@ static void mac_contentclick(WindowPtr window, EventRecord *event) {
case wSettings: case wSettings:
mac_clickdlg(window, event); mac_clickdlg(window, event);
break; break;
case wEventLog:
mac_clickeventlog(window, event);
break;
} }
} }
@ -370,6 +373,10 @@ static void mac_growwindow(WindowPtr window, EventRecord *event) {
switch (mac_windowtype(window)) { switch (mac_windowtype(window)) {
case wTerminal: case wTerminal:
mac_growterm(window, event); 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: case wAbout:
mac_activateabout(window, event); mac_activateabout(window, event);
break; break;
case wEventLog:
mac_activateeventlog(window, event);
break;
} }
} }
@ -432,6 +442,9 @@ static void mac_updatewindow(WindowPtr window)
case wLicence: case wLicence:
mac_updatelicence(window); mac_updatelicence(window);
break; break;
case wEventLog:
mac_updateeventlog(window);
break;
} }
} }
@ -674,6 +687,8 @@ static void mac_adjustmenus(void) {
DisableItem(menu, iDuplicate); DisableItem(menu, iDuplicate);
menu = GetMenuHandle(mEdit); menu = GetMenuHandle(mEdit);
DisableItem(menu, 0); DisableItem(menu, 0);
menu = GetMenuHandle(mWindow);
DisableItem(menu, 0); /* Until we get more than 1 item on it. */
break; break;
} }
DrawMenuBar(); DrawMenuBar();

View File

@ -9,6 +9,7 @@
#include <Controls.h> #include <Controls.h>
#include <Events.h> #include <Events.h>
#include <Gestalt.h> #include <Gestalt.h>
#include <Lists.h>
#include <MacWindows.h> #include <MacWindows.h>
#include <Palettes.h> #include <Palettes.h>
#include <UnicodeConverter.h> #include <UnicodeConverter.h>
@ -81,6 +82,8 @@ typedef struct Session {
Point font_bigdenom; Point font_bigdenom;
WindowPtr window; WindowPtr window;
WindowPtr settings_window; WindowPtr settings_window;
WindowPtr eventlog_window;
ListHandle eventlog;
PaletteHandle palette; PaletteHandle palette;
ControlHandle scrollbar; ControlHandle scrollbar;
WCTabHandle wctab; WCTabHandle wctab;
@ -100,6 +103,13 @@ extern void mac_savesession(void);
extern void mac_savesessionas(void); extern void mac_savesessionas(void);
extern void mac_clickdlg(WindowPtr, EventRecord *); extern void mac_clickdlg(WindowPtr, EventRecord *);
extern void mac_activatedlg(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 */ /* from macterm.c */
extern void mac_opensession(void); extern void mac_opensession(void);
extern void mac_startsession(Session *); extern void mac_startsession(Session *);

View File

@ -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 * Copyright (c) 1999, 2002 Ben Harris
* All rights reserved. * All rights reserved.
@ -899,7 +899,7 @@ resource 'TMPL' (TMPL_Int, "Int ", purgeable) {
/* Menu bar */ /* Menu bar */
resource 'MBAR' (MBAR_Main, preload) { resource 'MBAR' (MBAR_Main, preload) {
{ mApple, mFile, mEdit } { mApple, mFile, mEdit, mWindow }
}; };
resource 'MENU' (mApple, preload) { 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. */ /* Fatal error box. Stolen from the Finder. */
resource 'ALRT' (wFatal, "fatalbox", purgeable) { 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 */ /* "About" box */
resource 'DLOG' (wAbout, "about", purgeable) { resource 'DLOG' (wAbout, "about", purgeable) {

253
mac/macevlog.c Normal file
View File

@ -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 <MacTypes.h>
#include <Lists.h>
#include <MacWindows.h>
#include <Quickdraw.h>
#include <Script.h>
#include <ToolUtils.h>
#include <limits.h>
#include <string.h>
#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:
*/

View File

@ -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 * macresid.h -- Mac resource IDs
@ -19,6 +19,7 @@
#define mApple 128 #define mApple 128
#define mFile 129 #define mFile 129
#define mEdit 130 #define mEdit 130
#define mWindow 131
/* Menu Items */ /* Menu Items */
/* Apple menu */ /* Apple menu */
@ -38,6 +39,8 @@
#define iPaste 5 #define iPaste 5
#define iClear 6 #define iClear 6
#define iSelectAll 7 #define iSelectAll 7
/* Window menu */
#define iShowEventLog 1
/* Window types (and resource IDs) */ /* Window types (and resource IDs) */
#define wNone 0 /* Dummy value for no window */ #define wNone 0 /* Dummy value for no window */
@ -50,6 +53,7 @@
#define wLicence 131 #define wLicence 131
#define wSettings 132 #define wSettings 132
#define wiSettingsOpen 1 #define wiSettingsOpen 1
#define wEventLog 133
/* Controls */ /* Controls */
#define cVScroll 128 #define cVScroll 128

View File

@ -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 Simon Tatham
* Copyright (c) 1999, 2002 Ben Harris * Copyright (c) 1999, 2002 Ben Harris
@ -135,7 +135,7 @@ void mac_startsession(Session *s)
ActivatePalette(s->window); 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); term_provide_logctx(s->term, s->logctx);
errmsg = s->back->init(s->term, &s->backhandle, &s->cfg, s->cfg.host, 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); EnableItem(menu, iPaste);
DisableItem(menu, iClear); DisableItem(menu, iClear);
EnableItem(menu, iSelectAll); EnableItem(menu, iSelectAll);
menu = GetMenuHandle(mWindow);
EnableItem(menu, 0);
EnableItem(menu, iShowEventLog);
} }
void mac_menuterm(WindowPtr window, short menu, short item) { 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); term_do_paste(s->term);
break; 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) if (s->uni_to_font != NULL)
DisposeUnicodeToTextInfo(&s->uni_to_font); DisposeUnicodeToTextInfo(&s->uni_to_font);
term_free(s->term); term_free(s->term);
mac_freeeventlog(s);
sfree((WinInfo *)GetWRefCon(s->window)); sfree((WinInfo *)GetWRefCon(s->window));
DisposeWindow(s->window); DisposeWindow(s->window);
DisposePalette(s->palette); DisposePalette(s->palette);
@ -1729,11 +1741,6 @@ void do_scroll(Context ctx, int topline, int botline, int lines) {
DisposeRgn(update); DisposeRgn(update);
} }
void logevent(void *frontend, char *str) {
fprintf(stderr, "%s\n", str);
}
/* Dummy routine, only required in plink. */ /* Dummy routine, only required in plink. */
void ldisc_update(void *frontend, int echo, int edit) void ldisc_update(void *frontend, int echo, int edit)
{ {