From e43dc5ecd425ecc35398898d79c8578b50704932 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 16 Mar 1999 20:27:31 +0000 Subject: [PATCH] The edit menu is now mostly functional. I'm not sure about paste, since I haven't got a working backend at the moment, but it all looks OK. [originally from svn r118] --- Makefile.mpw | 4 +++- mac.c | 37 +++++++++++++++++++++++------- mac.h | 1 + mac_res.r | 21 ++++++++++++++--- maccfg.c | 5 +++- macterm.c | 64 ++++++++++++++++++++++++++++++++++++++++++++-------- putty.h | 4 +++- terminal.c | 11 ++++++++- 8 files changed, 123 insertions(+), 24 deletions(-) diff --git a/Makefile.mpw b/Makefile.mpw index ccebe9a5..7d7c98af 100644 --- a/Makefile.mpw +++ b/Makefile.mpw @@ -1,4 +1,4 @@ -# $Id: Makefile.mpw,v 1.1.2.2 1999/03/14 20:07:04 ben Exp $ +# $Id: Makefile.mpw,v 1.1.2.3 1999/03/16 20:27:30 ben Exp $ # This is the Makefile for building PuTTY for the Mac OS. # Users of non-Mac systems will see some pretty strange characters around. @@ -34,12 +34,14 @@ Libs PuTTY ÄÄ {Objects¥68K} {Libs¥68K} IF (`exists {Targ}.NJ`) ILink ¶ + -compact ¶ -o {Targ} {Sym¥68K} ¶ -t 'APPL' ¶ -c 'pTTY' ¶ -newerdeps {NewerDeps} ELSE ILink ¶ + -compact ¶ -o {Targ} {Sym¥68K} ¶ -t 'APPL' ¶ -c 'pTTY' ¶ diff --git a/mac.c b/mac.c index 72a95b8b..ea266400 100644 --- a/mac.c +++ b/mac.c @@ -1,4 +1,4 @@ -/* $Id: mac.c,v 1.1.2.15 1999/03/14 13:08:43 ben Exp $ */ +/* $Id: mac.c,v 1.1.2.16 1999/03/16 20:27:30 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -304,35 +304,48 @@ static void mac_keypress(EventRecord *event) { static void mac_menucommand(long result) { short menu, item; Str255 da; + WindowPtr window; menu = HiWord(result); item = LoWord(result); + window = FrontWindow(); + /* Things which do the same whatever window we're in. */ switch (menu) { case mApple: switch (item) { case iAbout: - GetNewDialog(wAbout, NULL, (GrafPort *)-1); - break; + if (windows.about) + SelectWindow(windows.about); + else + windows.about = GetNewDialog(wAbout, NULL, (WindowPtr)-1); + goto done; default: GetMenuItemText(GetMenuHandle(mApple), item, da); OpenDeskAcc(da); - break; + goto done; } break; case mFile: switch (item) { case iNew: mac_newsession(); - break; + goto done; case iClose: - mac_closewindow(FrontWindow()); - break; + mac_closewindow(window); + goto done; case iQuit: mac_shutdown(); - break; + goto done; } break; } + /* If we get here, handling is up to window-specific code. */ + switch (mac_windowtype(window)) { + case wTerminal: + mac_menuterm(window, menu, item); + break; + } + done: HiliteMenu(0); } @@ -345,6 +358,10 @@ static void mac_closewindow(WindowPtr window) { case wTerminal: /* FIXME: end session and stuff */ break; + case wAbout: + windows.about = NULL; + CloseWindow(window); + break; default: CloseWindow(window); break; @@ -371,6 +388,10 @@ static void mac_adjustmenus(void) { menu = GetMenuHandle(mFile); EnableItem(menu, 0); EnableItem(menu, iNew); + if (window != NULL) + EnableItem(menu, iClose); + else + DisableItem(menu, iClose); EnableItem(menu, iQuit); switch (mac_windowtype(window)) { diff --git a/mac.h b/mac.h index 407614a3..cfc11a70 100644 --- a/mac.h +++ b/mac.h @@ -27,6 +27,7 @@ extern void mac_updateterm(WindowPtr); extern void mac_clickterm(WindowPtr, EventRecord *); extern void mac_growterm(WindowPtr, EventRecord *); extern void mac_keyterm(WindowPtr, EventRecord *); +extern void mac_menuterm(WindowPtr, short, short); /* from maccfg.c */ extern void mac_loadconfig(Config *); diff --git a/mac_res.r b/mac_res.r index be599684..2cedc468 100644 --- a/mac_res.r +++ b/mac_res.r @@ -1,4 +1,4 @@ -/* $Id: mac_res.r,v 1.1.2.12 1999/03/15 00:40:55 ben Exp $ */ +/* $Id: mac_res.r,v 1.1.2.13 1999/03/16 20:27:30 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -459,8 +459,10 @@ type 'TEXT' { resource 'TEXT' (wLicence, "licence", purgeable) { "Copyright © 1997-9 Simon Tatham\n" - "Portions copyright Gary S. Brown, Eric Young and Ben Harris\n\n" - + "Portions copyright © 1999 Ben Harris\n" + "Portions copyright © 1993 Eric Young\n" + "Portions copyright © 1986 Gary S. Brown\n" + "\n" "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 " @@ -525,6 +527,9 @@ type 'pSET' { /* Colour options */ boolean bold_font, bold_colour; align long; + /* Selection options */ + boolean no_implicit_copy, implicit_copy; + align long; /* Non-boolean options */ integer; integer; /* host */ longint; /* port */ @@ -556,6 +561,7 @@ resource 'pSET' (PREF_settings, "settings", purgeable) { no_auto_cr, use_icon_name, bold_colour, + no_implicit_copy, #define PREF_strings 1024 PREF_strings, 1, /* host 'STR#' */ 23, prot_telnet, /* port, protocol */ @@ -653,6 +659,15 @@ resource 'TMPL' (128, "pSET") { "", 'BBIT', "", 'BBIT', "", 'ALNG', + "Implicit copy", 'BBIT', + "", 'BBIT', + "", 'BBIT', + "", 'BBIT', + "", 'BBIT', + "", 'BBIT', + "", 'BBIT', + "", 'BBIT', + "", 'ALNG', "Host STR# ID", 'DWRD', "Host STR# index", 'DWRD', "Port", 'DLNG', diff --git a/maccfg.c b/maccfg.c index 704b1722..5b11cae4 100644 --- a/maccfg.c +++ b/maccfg.c @@ -1,4 +1,4 @@ -/* $Id: maccfg.c,v 1.1.2.2 1999/03/14 15:48:35 ben Exp $ */ +/* $Id: maccfg.c,v 1.1.2.3 1999/03/16 20:27:30 ben Exp $ */ /* * maccfg.c -- Mac port configuration */ @@ -60,6 +60,8 @@ struct pSET { #define WIN_NAME_ALWAYS 0x10000000 unsigned long colour_flags; #define BOLD_COLOUR 0x80000000 + unsigned long selection_flags; +#define IMPLICIT_COPY 0x80000000 struct strloc host; long port; long protocol; @@ -127,6 +129,7 @@ void mac_loadconfig(Config *cfg) { if (cfg->colours == NULL) fatalbox("Failed to get default palette"); /* Selection */ + cfg->implicit_copy = (s->selection_flags & IMPLICIT_COPY) != 0; get_wordness(s->wordness_id, cfg->wordness); SetResAttrs(h, GetResAttrs(h) & ~resLocked); ReleaseResource(h); diff --git a/macterm.c b/macterm.c index 695031fa..a78e2307 100644 --- a/macterm.c +++ b/macterm.c @@ -1,4 +1,4 @@ -/* $Id: macterm.c,v 1.1.2.24 1999/03/15 14:22:45 ben Exp $ */ +/* $Id: macterm.c,v 1.1.2.25 1999/03/16 20:27:31 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,7 @@ static void mac_initfont(struct mac_session *); static void mac_initpalette(struct mac_session *); static void mac_adjustwinbg(struct mac_session *); static void mac_adjustsize(struct mac_session *, int, int); +static void mac_drawgrowicon(struct mac_session *s); static pascal void mac_scrolltracker(ControlHandle, short); static pascal void do_text_for_device(short, short, GDHandle, long); static pascal void mac_set_attr_mask(short, short, GDHandle, long); @@ -233,7 +235,10 @@ void mac_adjusttermmenus(WindowPtr window) { EnableItem(menu, 0); DisableItem(menu, iUndo); DisableItem(menu, iCut); - DisableItem(menu, iCopy); + if (term_hasselection()) + EnableItem(menu, iCopy); + else + DisableItem(menu, iCopy); if (GetScrap(NULL, 'TEXT', &offset) == noTypeErr) DisableItem(menu, iPaste); else @@ -242,6 +247,23 @@ void mac_adjusttermmenus(WindowPtr window) { EnableItem(menu, iSelectAll); } +void mac_menuterm(WindowPtr window, short menu, short item) { + struct mac_session *s; + + s = (struct mac_session *)GetWRefCon(window); + switch (menu) { + case mEdit: + switch (item) { + case iCopy: + term_copy(); + break; + case iPaste: + term_paste(); + break; + } + } +} + void mac_clickterm(WindowPtr window, EventRecord *event) { struct mac_session *s; Point mouse; @@ -321,8 +343,24 @@ void write_clip(void *data, int len) { } void get_clip(void **p, int *lenp) { + static Handle h = NULL; + long offset; - /* XXX: do something */ + if (p == NULL) { + /* release memory */ + if (h != NULL) + DisposeHandle(h); + h = NULL; + } else + if (GetScrap(NULL, 'TEXT', &offset) > 0) { + h = NewEmptyHandle(); + *lenp = GetScrap(h, 'TEXT', &offset); + HLock(h); + *p = *h; + } else { + *p = NULL; + *lenp = 0; + } } static pascal void mac_scrolltracker(ControlHandle control, short part) { @@ -565,11 +603,11 @@ void mac_activateterm(WindowPtr window, Boolean active) { PmBackColor(DEFAULT_BG); /* HideControl clears behind the control */ HideControl(s->scrollbar); } + mac_drawgrowicon(s); } void mac_updateterm(WindowPtr window) { struct mac_session *s; - Rect clip; s = (struct mac_session *)GetWRefCon(window); BeginUpdate(window); @@ -585,15 +623,23 @@ void mac_updateterm(WindowPtr window) { if (FrontWindow() != window) EraseRect(&(*s->scrollbar)->contrlRect); UpdateControls(window, window->visRgn); + mac_drawgrowicon(s); + free_ctx(NULL); + EndUpdate(window); +} + +static void mac_drawgrowicon(struct mac_session *s) { + Rect clip; + + SetPort(s->window); /* Stop DrawGrowIcon giving us space for a horizontal scrollbar */ - SetRect(&clip, window->portRect.right - 15, SHRT_MIN, SHRT_MAX, SHRT_MAX); + SetRect(&clip, s->window->portRect.right - 15, SHRT_MIN, + SHRT_MAX, SHRT_MAX); ClipRect(&clip); - DrawGrowIcon(window); + DrawGrowIcon(s->window); clip.left = SHRT_MIN; ClipRect(&clip); - free_ctx(NULL); - EndUpdate(window); -} +} struct do_text_args { struct mac_session *s; diff --git a/putty.h b/putty.h index 81935f76..34b57cb0 100644 --- a/putty.h +++ b/putty.h @@ -164,7 +164,8 @@ typedef struct { unsigned char colours[22][3]; #endif /* not macintosh */ /* Selection options */ -#ifndef macintosh + int implicit_copy; +#ifdef macintosh int mouse_is_xterm; #endif short wordness[256]; @@ -246,6 +247,7 @@ void term_clrsb (void); void term_mouse (Mouse_Button, Mouse_Action, int, int); void term_copy(void); void term_paste(void); +int term_hasselection(void); void term_deselect (void); void term_update (void); void term_invalidate(void); diff --git a/terminal.c b/terminal.c index da5fe9da..aa5a9a63 100644 --- a/terminal.c +++ b/terminal.c @@ -1427,7 +1427,8 @@ void term_mouse (Mouse_Button b, Mouse_Action a, int x, int y) { sel_spread(); } else if ((b == MB_SELECT || b == MB_EXTEND) && a == MA_RELEASE) if (selstate == DRAGGING) { - term_copy(); + if (cfg.implicit_copy) + term_copy(); selstate = SELECTED; } else selstate = NO_SELECTION; @@ -1492,6 +1493,14 @@ void term_paste() { get_clip(NULL, NULL); } +/* + * Find out if there's a selection. + */ +int term_hasselection(void) { + + return selstate == SELECTED; +} + static void deselect (void) { selstate = NO_SELECTION; selstart = selend = scrtop; -- 2.45.2