From f854b482e4de775e380033bbea7436732311d1ce Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 15 Feb 2003 16:22:15 +0000 Subject: [PATCH] Rather than increasing the size of my switch statements yet further, have a bunch of function pointers associated with each window to do things like updates and click handling. This is all looking disturbingly object-oriented. . While I'm here, separate out the about box into its own file, shared by PuTTY and PuTTYgen. git-svn-id: svn://svn.tartarus.org/sgt/putty@2850 cda61777-01e9-0310-a592-d414129be87e --- mac/mac.c | 234 ++++++++------------------------------------------------- mac/mac.h | 31 ++++---- mac/macabout.c | 173 ++++++++++++++++++++++++++++++++++++++++++ mac/macdlg.c | 57 +++++++++++++- mac/macevlog.c | 17 ++++- mac/macterm.c | 101 ++++++++++++++++++------- 6 files changed, 358 insertions(+), 255 deletions(-) create mode 100644 mac/macabout.c diff --git a/mac/mac.c b/mac/mac.c index 78e2803c..a0bc998b 100644 --- a/mac/mac.c +++ b/mac/mac.c @@ -1,6 +1,6 @@ -/* $Id: mac.c,v 1.48 2003/02/12 23:53:15 ben Exp $ */ +/* $Id: mac.c,v 1.49 2003/02/15 16:22:15 ben Exp $ */ /* - * Copyright (c) 1999 Ben Harris + * Copyright (c) 1999, 2003 Ben Harris * All rights reserved. * * Permission is hereby granted, free of charge, to any person @@ -82,7 +82,6 @@ static void mac_updatelicence(WindowPtr); static void mac_keypress(EventRecord *); static int mac_windowtype(WindowPtr); static void mac_menucommand(long); -static void mac_openabout(void); static void mac_openlicence(void); static void mac_adjustcursor(RgnHandle); static void mac_adjustmenus(void); @@ -330,137 +329,33 @@ static void mac_event(EventRecord *event) { } } -static void mac_contentclick(WindowPtr window, EventRecord *event) { - short item; - DialogRef dialog; +static void mac_contentclick(WindowPtr window, EventRecord *event) +{ - switch (mac_windowtype(window)) { - case wTerminal: - mac_clickterm(window, event); - break; - case wAbout: - dialog = GetDialogFromWindow(window); - if (DialogSelect(event, &dialog, &item)) - switch (item) { - case wiAboutLicence: - mac_openlicence(); - break; - } - break; - case wSettings: - mac_clickdlg(window, event); - break; - case wEventLog: - mac_clickeventlog(window, event); - break; - } + if (mac_wininfo(window)->click != NULL) + (*mac_wininfo(window)->click)(window, event); } -static void mac_growwindow(WindowPtr window, EventRecord *event) { +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; - } + if (mac_wininfo(window)->grow != NULL) + (*mac_wininfo(window)->grow)(window, event); } -static void mac_activatewindow(WindowPtr window, EventRecord *event) { - int active; +static void mac_activatewindow(WindowPtr window, EventRecord *event) +{ - active = (event->modifiers & activeFlag) != 0; mac_adjustmenus(); - switch (mac_windowtype(window)) { - case wTerminal: - mac_activateterm(window, active); - break; - case wSettings: - mac_activatedlg(window, event); - break; - case wAbout: - mac_activateabout(window, event); - break; - case wEventLog: - mac_activateeventlog(window, event); - break; - } -} - -static void mac_activateabout(WindowPtr window, EventRecord *event) { - DialogRef dialog; - DialogItemType itemtype; - Handle itemhandle; - short item; - Rect itemrect; - int active; - - dialog = GetDialogFromWindow(window); - active = (event->modifiers & activeFlag) != 0; - GetDialogItem(dialog, wiAboutLicence, &itemtype, &itemhandle, &itemrect); - HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); - DialogSelect(event, &dialog, &item); + if (mac_wininfo(window)->activate != NULL) + (*mac_wininfo(window)->activate)(window, event); } static void mac_updatewindow(WindowPtr window) { -#if TARGET_API_MAC_CARBON - RgnHandle rgn; -#endif - switch (mac_windowtype(window)) { - case wTerminal: - mac_updateterm(window); - break; - case wAbout: - case wSettings: - BeginUpdate(window); -#if TARGET_API_MAC_CARBON - rgn = NewRgn(); - GetPortVisibleRegion(GetWindowPort(window), rgn); - UpdateDialog(GetDialogFromWindow(window), rgn); - DisposeRgn(rgn); -#else - UpdateDialog(window, window->visRgn); -#endif - EndUpdate(window); - break; - case wLicence: - mac_updatelicence(window); - break; - case wEventLog: - mac_updateeventlog(window); - break; - } -} - -static void mac_updatelicence(WindowPtr window) -{ - Handle h; - int len; - long fondsize; - Rect textrect; - - SetPort((GrafPtr)GetWindowPort(window)); - BeginUpdate(window); - fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize); - TextFont(HiWord(fondsize)); - TextSize(LoWord(fondsize)); - h = Get1Resource('TEXT', wLicence); - len = GetResourceSizeOnDisk(h); -#if TARGET_API_MAC_CARBON - GetPortBounds(GetWindowPort(window), &textrect); -#else - textrect = window->portRect; -#endif - if (h != NULL) { - HLock(h); - TETextBox(*h, len, &textrect, teFlushDefault); - HUnlock(h); - } - EndUpdate(window); + if (mac_wininfo(window)->update != NULL) + (*mac_wininfo(window)->update)(window); } /* @@ -493,11 +388,8 @@ static void mac_keypress(EventRecord *event) { mac_adjustmenus(); mac_menucommand(MenuKey(event->message & charCodeMask)); } else { - switch (mac_windowtype(window)) { - case wTerminal: - mac_keyterm(window, event); - break; - } + if (mac_wininfo(window)->key != NULL) + (*mac_wininfo(window)->key)(window, event); } } @@ -553,59 +445,13 @@ static void mac_menucommand(long result) { break; } /* If we get here, handling is up to window-specific code. */ - switch (mac_windowtype(window)) { - case wTerminal: - mac_menuterm(window, menu, item); - break; - } + if (mac_wininfo(window)->menu != NULL) + (*mac_wininfo(window)->menu)(window, menu, item); + done: HiliteMenu(0); } -static void mac_openabout(void) { - DialogItemType itemtype; - Handle item; - VersRecHndl vers; - Rect box; - StringPtr longvers; - WinInfo *wi; - - if (windows.about) - SelectWindow(windows.about); - else { - windows.about = - GetDialogWindow(GetNewDialog(wAbout, NULL, (WindowPtr)-1)); - wi = smalloc(sizeof(*wi)); - wi->s = NULL; - wi->wtype = wAbout; - SetWRefCon(windows.about, (long)wi); - vers = (VersRecHndl)Get1Resource('vers', 1); - if (vers != NULL && *vers != NULL) { - longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1; - GetDialogItem(GetDialogFromWindow(windows.about), wiAboutVersion, - &itemtype, &item, &box); - assert(itemtype & kStaticTextDialogItem); - SetDialogItemText(item, longvers); - } - ShowWindow(windows.about); - } -} - -static void mac_openlicence(void) { - WinInfo *wi; - - if (windows.licence) - SelectWindow(windows.licence); - else { - windows.licence = GetNewWindow(wLicence, NULL, (WindowPtr)-1); - wi = smalloc(sizeof(*wi)); - wi->s = NULL; - wi->wtype = wLicence; - SetWRefCon(windows.licence, (long)wi); - ShowWindow(windows.licence); - } -} - static void mac_closewindow(WindowPtr window) { switch (mac_windowtype(window)) { @@ -614,16 +460,9 @@ static void mac_closewindow(WindowPtr window) { CloseDeskAcc(GetWindowKind(window)); break; #endif - case wTerminal: - mac_closeterm(window); - break; - case wAbout: - windows.about = NULL; - DisposeDialog(GetDialogFromWindow(window)); - break; - case wLicence: - windows.licence = NULL; - DisposeWindow(window); + default: + if (mac_wininfo(window)->close != NULL) + (*mac_wininfo(window)->close)(window); break; } } @@ -658,18 +497,9 @@ static void mac_adjustmenus(void) { DisableItem(menu, iClose); EnableItem(menu, iQuit); - switch (mac_windowtype(window)) { - case wSettings: - DisableItem(menu, iSave); /* XXX enable if modified */ - EnableItem(menu, iSaveAs); - EnableItem(menu, iDuplicate); - menu = GetMenuHandle(mEdit); - DisableItem(menu, 0); - break; - case wTerminal: - mac_adjusttermmenus(window); - break; - default: + if (mac_wininfo(window)->adjustmenus != NULL) + (*mac_wininfo(window)->adjustmenus)(window); + else { DisableItem(menu, iSave); DisableItem(menu, iSaveAs); DisableItem(menu, iDuplicate); @@ -677,7 +507,6 @@ static void mac_adjustmenus(void) { DisableItem(menu, 0); menu = GetMenuHandle(mWindow); DisableItem(menu, 0); /* Until we get more than 1 item on it. */ - break; } DrawMenuBar(); } @@ -718,11 +547,9 @@ static void mac_adjustcursor(RgnHandle cursrgn) { #endif } } else { - switch (mac_windowtype(window)) { - case wTerminal: - mac_adjusttermcursor(window, mouse, cursrgn); - break; - default: + if (mac_wininfo(window)->adjustcursor != NULL) + (*mac_wininfo(window)->adjustcursor)(window, mouse, cursrgn); + else { #if TARGET_API_MAC_CARBON GetQDGlobalsArrow(&arrow); SetCursor(&arrow); @@ -731,7 +558,6 @@ static void mac_adjustcursor(RgnHandle cursrgn) { SetCursor(&qd.arrow); CopyRgn(window->visRgn, cursrgn); #endif - break; } } } diff --git a/mac/mac.h b/mac/mac.h index e747e29b..c228d1bd 100644 --- a/mac/mac.h +++ b/mac/mac.h @@ -45,9 +45,21 @@ extern struct mac_gestalts mac_gestalts; typedef struct { struct Session *s; /* Only used in PuTTY */ struct KeyState *ks; /* Only used in PuTTYgen */ + + void (*activate) (WindowPtr, EventRecord *); + void (*adjustcursor)(WindowPtr, Point, RgnHandle); + void (*adjustmenus) (WindowPtr); + void (*update) (WindowPtr); + void (*click) (WindowPtr, EventRecord *); + void (*grow) (WindowPtr, EventRecord *); + void (*key) (WindowPtr, EventRecord *); + void (*menu) (WindowPtr, short, short); + void (*close) (WindowPtr); + int wtype; } WinInfo; +#define mac_wininfo(w) ((WinInfo *)GetWRefCon(w)) #define mac_windowsession(w) (((WinInfo *)GetWRefCon(w))->s) typedef struct Session { @@ -109,28 +121,13 @@ extern void mac_newsession(void); extern void mac_dupsession(void); 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_freeeventlog(Session *); extern void mac_showeventlog(Session *); /* from macterm.c */ extern void mac_opensession(void); extern void mac_startsession(Session *); extern void mac_pollterm(void); -extern void mac_activateterm(WindowPtr, Boolean); -extern void mac_adjusttermcursor(WindowPtr, Point, RgnHandle); -extern void mac_adjusttermmenus(WindowPtr); -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); -extern void mac_closeterm(WindowPtr); /* from macstore.c */ extern OSErr get_putty_dir(Boolean makeit, short *pVRefNum, long *pDirID); extern OSErr get_session_dir(Boolean makeit, short *pVRefNum, long *pDirID); @@ -172,6 +169,8 @@ extern Socket ot_register(void *, Plug); extern Socket ot_new(SockAddr addr, int, int, int, int, Plug); extern Socket ot_newlistener(char *, int, Plug, int); extern char *ot_addr_error(SockAddr); +/* from macabout.c */ +extern void mac_openabout(void); /* from macpgkey.c */ extern void mac_newkey(void); /* Apple Event Handlers (in various files) */ diff --git a/mac/macabout.c b/mac/macabout.c new file mode 100644 index 00000000..f1fc7ff2 --- /dev/null +++ b/mac/macabout.c @@ -0,0 +1,173 @@ +/* $Id: macabout.c,v 1.1 2003/02/15 16:22:15 ben Exp $ */ +/* + * Copyright (c) 1999, 2002, 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" + +static struct mac_windows { + WindowPtr about; + WindowPtr licence; +} windows; + +static void mac_openlicence(void); + +static void mac_clickabout(WindowPtr window, EventRecord *event) +{ + short item; + DialogRef dialog; + + dialog = GetDialogFromWindow(window); + if (DialogSelect(event, &dialog, &item)) + switch (item) { + case wiAboutLicence: + mac_openlicence(); + break; + } +} + +static void mac_activateabout(WindowPtr window, EventRecord *event) +{ + DialogRef dialog; + DialogItemType itemtype; + Handle itemhandle; + short item; + Rect itemrect; + int active; + + dialog = GetDialogFromWindow(window); + active = (event->modifiers & activeFlag) != 0; + GetDialogItem(dialog, wiAboutLicence, &itemtype, &itemhandle, &itemrect); + HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); + DialogSelect(event, &dialog, &item); +} + +static void mac_updateabout(WindowPtr window) +{ +#if TARGET_API_MAC_CARBON + RgnHandle rgn; +#endif + + BeginUpdate(window); +#if TARGET_API_MAC_CARBON + rgn = NewRgn(); + GetPortVisibleRegion(GetWindowPort(window), rgn); + UpdateDialog(GetDialogFromWindow(window), rgn); + DisposeRgn(rgn); +#else + UpdateDialog(window, window->visRgn); +#endif + EndUpdate(window); +} + +static void mac_updatelicence(WindowPtr window) +{ + Handle h; + int len; + long fondsize; + Rect textrect; + + SetPort((GrafPtr)GetWindowPort(window)); + BeginUpdate(window); + fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize); + TextFont(HiWord(fondsize)); + TextSize(LoWord(fondsize)); + h = Get1Resource('TEXT', wLicence); + len = GetResourceSizeOnDisk(h); +#if TARGET_API_MAC_CARBON + GetPortBounds(GetWindowPort(window), &textrect); +#else + textrect = window->portRect; +#endif + if (h != NULL) { + HLock(h); + TETextBox(*h, len, &textrect, teFlushDefault); + HUnlock(h); + } + EndUpdate(window); +} + +void mac_openabout(void) +{ + DialogItemType itemtype; + Handle item; + VersRecHndl vers; + Rect box; + StringPtr longvers; + WinInfo *wi; + + if (windows.about) + SelectWindow(windows.about); + else { + windows.about = + GetDialogWindow(GetNewDialog(wAbout, NULL, (WindowPtr)-1)); + wi = smalloc(sizeof(*wi)); + memset(wi, 0, sizeof(*wi)); + wi->wtype = wAbout; + wi->update = &mac_updateabout; + wi->click = &mac_clickabout; + wi->activate = &mac_activateabout; + SetWRefCon(windows.about, (long)wi); + vers = (VersRecHndl)Get1Resource('vers', 1); + if (vers != NULL && *vers != NULL) { + longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1; + GetDialogItem(GetDialogFromWindow(windows.about), wiAboutVersion, + &itemtype, &item, &box); + assert(itemtype & kStaticTextDialogItem); + SetDialogItemText(item, longvers); + } + ShowWindow(windows.about); + } +} + +static void mac_openlicence(void) +{ + WinInfo *wi; + + if (windows.licence) + SelectWindow(windows.licence); + else { + windows.licence = GetNewWindow(wLicence, NULL, (WindowPtr)-1); + wi = smalloc(sizeof(*wi)); + memset(wi, 0, sizeof(*wi)); + wi->wtype = wLicence; + wi->update = &mac_updatelicence; + SetWRefCon(windows.licence, (long)wi); + ShowWindow(windows.licence); + } +} + diff --git a/mac/macdlg.c b/mac/macdlg.c index 4f18bdd3..ad7a1ffa 100644 --- a/mac/macdlg.c +++ b/mac/macdlg.c @@ -1,4 +1,4 @@ -/* $Id: macdlg.c,v 1.11 2003/02/04 23:39:26 ben Exp $ */ +/* $Id: macdlg.c,v 1.12 2003/02/15 16:22:15 ben Exp $ */ /* * Copyright (c) 2002 Ben Harris * All rights reserved. @@ -46,9 +46,15 @@ #include "macresid.h" #include "storage.h" +static void mac_clickdlg(WindowPtr, EventRecord *); +static void mac_activatedlg(WindowPtr, EventRecord *); +static void mac_updatedlg(WindowPtr); +static void mac_adjustdlgmenus(WindowPtr); + void mac_newsession(void) { Session *s; + WinInfo *wi; /* This should obviously be initialised by other means */ s = smalloc(sizeof(*s)); @@ -59,7 +65,15 @@ void mac_newsession(void) s->settings_window = GetDialogWindow(GetNewDialog(wSettings, NULL, (WindowPtr)-1)); - SetWRefCon(s->settings_window, (long)s); + wi = smalloc(sizeof(*wi)); + memset(wi, 0, sizeof(*wi)); + wi->s = s; + wi->wtype = wSettings; + wi->update = &mac_updatedlg; + wi->click = &mac_clickdlg; + wi->activate = &mac_activatedlg; + wi->adjustmenus = &mac_adjustdlgmenus; + SetWRefCon(s->settings_window, (long)wi); ShowWindow(s->settings_window); } @@ -266,7 +280,7 @@ pascal OSErr mac_aevt_pdoc(const AppleEvent *req, AppleEvent *reply, return errAEEventNotHandled; } -void mac_activatedlg(WindowPtr window, EventRecord *event) +static void mac_activatedlg(WindowPtr window, EventRecord *event) { DialogItemType itemtype; Handle itemhandle; @@ -281,7 +295,7 @@ void mac_activatedlg(WindowPtr window, EventRecord *event) DialogSelect(event, &dialog, &item); } -void mac_clickdlg(WindowPtr window, EventRecord *event) +static void mac_clickdlg(WindowPtr window, EventRecord *event) { short item; Session *s = mac_windowsession(window); @@ -296,6 +310,41 @@ void mac_clickdlg(WindowPtr window, EventRecord *event) } } +static void mac_updatedlg(WindowPtr window) +{ +#if TARGET_API_MAC_CARBON + RgnHandle rgn; +#endif + + BeginUpdate(window); +#if TARGET_API_MAC_CARBON + rgn = NewRgn(); + GetPortVisibleRegion(GetWindowPort(window), rgn); + UpdateDialog(GetDialogFromWindow(window), rgn); + DisposeRgn(rgn); +#else + UpdateDialog(window, window->visRgn); +#endif + EndUpdate(window); +} + +#if TARGET_API_MAC_CARBON +#define EnableItem EnableMenuItem +#define DisableItem DisableMenuItem +#endif +static void mac_adjustdlgmenus(WindowPtr window) +{ + MenuHandle menu; + + menu = GetMenuHandle(mFile); + DisableItem(menu, iSave); /* XXX enable if modified */ + EnableItem(menu, iSaveAs); + EnableItem(menu, iDuplicate); + + menu = GetMenuHandle(mEdit); + DisableItem(menu, 0); +} + /* * Local Variables: * c-file-style: "simon" diff --git a/mac/macevlog.c b/mac/macevlog.c index 2bc89299..92e65bb5 100644 --- a/mac/macevlog.c +++ b/mac/macevlog.c @@ -1,4 +1,4 @@ -/* $Id: macevlog.c,v 1.1 2003/02/07 01:38:12 ben Exp $ */ +/* $Id: macevlog.c,v 1.2 2003/02/15 16:22:15 ben Exp $ */ /* * Copyright (c) 2003 Ben Harris * All rights reserved. @@ -42,6 +42,10 @@ static void mac_draweventloggrowicon(Session *s); static void mac_adjusteventlogscrollbar(Session *s); +static void mac_clickeventlog(WindowPtr, EventRecord *); +static void mac_activateeventlog(WindowPtr, EventRecord *); +static void mac_groweventlog(WindowPtr, EventRecord *); +static void mac_updateeventlog(WindowPtr); static void mac_createeventlog(Session *s) { @@ -57,8 +61,13 @@ static void mac_createeventlog(Session *s) s->eventlog_window = GetNewWindow(wEventLog, NULL, (WindowPtr)-1); wi = smalloc(sizeof(*wi)); + memset(wi, 0, sizeof(*wi)); wi->s = s; wi->wtype = wEventLog; + wi->click = &mac_clickeventlog; + wi->activate = &mac_activateeventlog; + wi->grow = &mac_groweventlog; + wi->update = &mac_updateeventlog; SetWRefCon(s->eventlog_window, (long)wi); GetPort(&saveport); SetPort((GrafPtr)GetWindowPort(s->eventlog_window)); @@ -178,7 +187,7 @@ void mac_clickeventlog(WindowPtr window, EventRecord *event) SetPort(saveport); } -void mac_groweventlog(WindowPtr window, EventRecord *event) +static void mac_groweventlog(WindowPtr window, EventRecord *event) { Session *s = mac_windowsession(window); Rect limits; @@ -210,7 +219,7 @@ void mac_groweventlog(WindowPtr window, EventRecord *event) #endif } -void mac_activateeventlog(WindowPtr window, EventRecord *event) +static void mac_activateeventlog(WindowPtr window, EventRecord *event) { Session *s = mac_windowsession(window); int active = (event->modifiers & activeFlag) != 0; @@ -219,7 +228,7 @@ void mac_activateeventlog(WindowPtr window, EventRecord *event) mac_draweventloggrowicon(s); } -void mac_updateeventlog(WindowPtr window) +static void mac_updateeventlog(WindowPtr window) { Session *s = mac_windowsession(window); #if TARGET_API_MAC_CARBON diff --git a/mac/macterm.c b/mac/macterm.c index d0abf667..d04abd33 100644 --- a/mac/macterm.c +++ b/mac/macterm.c @@ -1,4 +1,4 @@ -/* $Id: macterm.c,v 1.70 2003/02/11 23:10:34 ben Exp $ */ +/* $Id: macterm.c,v 1.71 2003/02/15 16:22:15 ben Exp $ */ /* * Copyright (c) 1999 Simon Tatham * Copyright (c) 1999, 2002 Ben Harris @@ -90,6 +90,15 @@ static pascal void mac_growtermdraghook(void); static pascal void mac_scrolltracker(ControlHandle, short); static pascal void do_text_for_device(short, short, GDHandle, long); static void text_click(Session *, EventRecord *); +static void mac_activateterm(WindowPtr, EventRecord *); +static void mac_adjusttermcursor(WindowPtr, Point, RgnHandle); +static void mac_adjusttermmenus(WindowPtr); +static void mac_updateterm(WindowPtr); +static void mac_clickterm(WindowPtr, EventRecord *); +static void mac_growterm(WindowPtr, EventRecord *); +static void mac_keyterm(WindowPtr, EventRecord *); +static void mac_menuterm(WindowPtr, short, short); +static void mac_closeterm(WindowPtr); void pre_paint(Session *s); void post_paint(Session *s); @@ -121,8 +130,18 @@ void mac_startsession(Session *s) else s->window = GetNewWindow(wTerminal, NULL, (WindowPtr)-1); wi = smalloc(sizeof(*wi)); + memset(wi, 0, sizeof(*wi)); wi->s = s; wi->wtype = wTerminal; + wi->activate = &mac_activateterm; + wi->adjustcursor = &mac_adjusttermcursor; + wi->adjustmenus = &mac_adjusttermmenus; + wi->update = &mac_updateterm; + wi->click = &mac_clickterm; + wi->grow = &mac_growterm; + wi->key = &mac_keyterm; + wi->menu = &mac_menuterm; + wi->close = &mac_closeterm; SetWRefCon(s->window, (long)wi); s->scrollbar = GetNewControl(cVScroll, s->window); s->term = term_init(&s->cfg, &s->ucsdata, s); @@ -203,7 +222,8 @@ static void mac_workoutfontscale(Session *s, int wantwidth, static UnicodeToTextFallbackUPP uni_to_font_fallback_upp; -static void mac_initfont(Session *s) { +static void mac_initfont(Session *s) +{ FontInfo fi; TextEncoding enc; OptionBits fbflags; @@ -317,7 +337,8 @@ static void mac_adjustsize(Session *s, int newrows, int newcols) { mac_drawgrowicon(s); } -static void mac_initpalette(Session *s) { +static void mac_initpalette(Session *s) +{ if (!HAVE_COLOR_QD()) return; @@ -348,7 +369,8 @@ static void mac_initpalette(Session *s) { * Set the background colour of the window correctly. Should be * called whenever the default background changes. */ -static void mac_adjustwinbg(Session *s) { +static void mac_adjustwinbg(Session *s) +{ if (!HAVE_COLOR_QD()) return; @@ -377,7 +399,9 @@ static void mac_adjustwinbg(Session *s) { /* * Set the cursor shape correctly */ -void mac_adjusttermcursor(WindowPtr window, Point mouse, RgnHandle cursrgn) { +static void mac_adjusttermcursor(WindowPtr window, Point mouse, + RgnHandle cursrgn) +{ Session *s; ControlHandle control; short part; @@ -432,7 +456,8 @@ void mac_adjusttermcursor(WindowPtr window, Point mouse, RgnHandle cursrgn) { #define DisableItem DisableMenuItem #define EnableItem EnableMenuItem #endif -void mac_adjusttermmenus(WindowPtr window) { +static void mac_adjusttermmenus(WindowPtr window) +{ Session *s; MenuHandle menu; #if !TARGET_API_MAC_CARBON @@ -467,7 +492,8 @@ void mac_adjusttermmenus(WindowPtr window) { EnableItem(menu, iShowEventLog); } -void mac_menuterm(WindowPtr window, short menu, short item) { +static void mac_menuterm(WindowPtr window, short menu, short item) +{ Session *s; s = mac_windowsession(window); @@ -492,7 +518,8 @@ void mac_menuterm(WindowPtr window, short menu, short item) { } } -void mac_clickterm(WindowPtr window, EventRecord *event) { +static void mac_clickterm(WindowPtr window, EventRecord *event) +{ Session *s; Point mouse; ControlHandle control; @@ -525,7 +552,8 @@ void mac_clickterm(WindowPtr window, EventRecord *event) { } } -static void text_click(Session *s, EventRecord *event) { +static void text_click(Session *s, EventRecord *event) +{ Point localwhere; int row, col; static UInt32 lastwhen = 0; @@ -636,7 +664,8 @@ void write_clip(void *cookie, wchar_t *data, int len, int must_deselect) #endif } -void get_clip(void *frontend, wchar_t **p, int *lenp) { +void get_clip(void *frontend, wchar_t **p, int *lenp) +{ #if TARGET_API_MAC_CARBON *lenp = 0; #else @@ -716,7 +745,8 @@ void get_clip(void *frontend, wchar_t **p, int *lenp) { #endif } -static pascal void mac_scrolltracker(ControlHandle control, short part) { +static pascal void mac_scrolltracker(ControlHandle control, short part) +{ Session *s; #if TARGET_API_MAC_CARBON @@ -740,7 +770,8 @@ static pascal void mac_scrolltracker(ControlHandle control, short part) { } } -void mac_keyterm(WindowPtr window, EventRecord *event) { +static void mac_keyterm(WindowPtr window, EventRecord *event) +{ Session *s = mac_windowsession(window); Key_Sym keysym = PK_NULL; unsigned int mods = 0, flags = PKF_NUMLOCK; @@ -900,7 +931,8 @@ static struct { char oldmsg[20]; } growterm_state; -void mac_growterm(WindowPtr window, EventRecord *event) { +static void mac_growterm(WindowPtr window, EventRecord *event) +{ Rect limits; long grow_result; int newrows, newcols; @@ -1004,8 +1036,10 @@ void mac_closeterm(WindowPtr window) sfree(s); } -void mac_activateterm(WindowPtr window, Boolean active) { +static void mac_activateterm(WindowPtr window, EventRecord *event) +{ Session *s; + Boolean active = (event->modifiers & activeFlag) != 0; s = mac_windowsession(window); s->term->has_focus = active; @@ -1022,7 +1056,8 @@ void mac_activateterm(WindowPtr window, Boolean active) { mac_drawgrowicon(s); } -void mac_updateterm(WindowPtr window) { +static void mac_updateterm(WindowPtr window) +{ Session *s; Rect bbox; #if TARGET_API_MAC_CARBON @@ -1064,7 +1099,8 @@ void mac_updateterm(WindowPtr window) { EndUpdate(window); } -static void mac_drawgrowicon(Session *s) { +static void mac_drawgrowicon(Session *s) +{ Rect clip; RgnHandle savergn; @@ -1103,7 +1139,8 @@ struct do_text_args { * x and y are text row and column (zero-based) */ void do_text(Context ctx, int x, int y, char *text, int len, - unsigned long attr, int lattr) { + unsigned long attr, int lattr) +{ Session *s = ctx; int style; struct do_text_args a; @@ -1230,7 +1267,8 @@ void do_text(Context ctx, int x, int y, char *text, int len, } static pascal void do_text_for_device(short depth, short devflags, - GDHandle device, long cookie) { + GDHandle device, long cookie) +{ struct do_text_args *a = (struct do_text_args *)cookie; int bgcolour, fgcolour, bright, reverse, tmp; #if TARGET_API_MAC_CARBON @@ -1328,7 +1366,8 @@ void do_cursor(Context ctx, int x, int y, char *text, int len, * Call from the terminal emulator to get its graphics context. * Should probably be called start_redraw or something. */ -void pre_paint(Session *s) { +void pre_paint(Session *s) +{ GDHandle gdh; Rect myrect, tmprect; #if TARGET_API_MAC_CARBON @@ -1374,21 +1413,24 @@ void pre_paint(Session *s) { (s->cfg.bold_colour ? ATTR_BOLD : 0)); } -Context get_ctx(void *frontend) { +Context get_ctx(void *frontend) +{ Session *s = frontend; pre_paint(s); return s; } -void free_ctx(Context ctx) { +void free_ctx(Context ctx) +{ } /* * Presumably this does something in Windows */ -void post_paint(Session *s) { +void post_paint(Session *s) +{ } @@ -1399,7 +1441,8 @@ void post_paint(Session *s) { * start is the line number of the top of the display * page is the length of the displayed page */ -void set_sbar(void *frontend, int total, int start, int page) { +void set_sbar(void *frontend, int total, int start, int page) +{ Session *s = frontend; /* We don't redraw until we've set everything up, to avoid glitches */ @@ -1455,7 +1498,8 @@ void set_icon(void *frontend, char *icon) { /* * Set the window title */ -void set_title(void *frontend, char *title) { +void set_title(void *frontend, char *title) +{ Session *s = frontend; Str255 mactitle; @@ -1646,7 +1690,8 @@ static void real_palette_set(Session *s, int n, int r, int g, int b) /* * Set the logical palette. Called by the terminal emulator. */ -void palette_set(void *frontend, int n, int r, int g, int b) { +void palette_set(void *frontend, int n, int r, int g, int b) +{ Session *s = frontend; static const int first[21] = { 0, 2, 4, 6, 8, 10, 12, 14, @@ -1667,7 +1712,8 @@ void palette_set(void *frontend, int n, int r, int g, int b) { /* * Reset to the default palette */ -void palette_reset(void *frontend) { +void palette_reset(void *frontend) +{ Session *s = frontend; /* This maps colour indices in cfg to those used in our palette. */ static const int ww[] = { @@ -1697,7 +1743,8 @@ void palette_reset(void *frontend) { * Scroll the screen. (`lines' is +ve for scrolling forward, -ve * for backward.) */ -void do_scroll(Context ctx, int topline, int botline, int lines) { +void do_scroll(Context ctx, int topline, int botline, int lines) +{ Session *s = ctx; Rect r; RgnHandle scrollrgn = NewRgn(); -- 2.11.0