From 893ca6173a32912071dce0e4e865767e20f1f921 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 18 Mar 2003 00:35:40 +0000 Subject: [PATCH] My First CDEF: A terribly trivial static text control for System 7. Needs work. [originally from svn r2955] --- mac/mac_res.r | 8 +++++- mac/macctrls.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++-- mac/macresid.h | 6 +++- 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/mac/mac_res.r b/mac/mac_res.r index 17e1bce7..e9cb121f 100644 --- a/mac/mac_res.r +++ b/mac/mac_res.r @@ -1,4 +1,4 @@ -/* $Id: mac_res.r,v 1.32 2003/03/17 21:40:37 ben Exp $ */ +/* $Id: mac_res.r,v 1.33 2003/03/18 00:35:40 ben Exp $ */ /* * Copyright (c) 1999, 2002, 2003 Ben Harris * All rights reserved. @@ -1119,3 +1119,9 @@ resource 'TEXT' (wLicence, "licence", purgeable) { "CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE " "SOFTWARE." }; + +/* Custom xDEFs */ + +data 'CDEF' (CDEF_Text) { + $"4EF9 00000000" +}; diff --git a/mac/macctrls.c b/mac/macctrls.c index 354f9dec..5903b553 100644 --- a/mac/macctrls.c +++ b/mac/macctrls.c @@ -1,4 +1,4 @@ -/* $Id: macctrls.c,v 1.1 2003/03/17 21:40:37 ben Exp $ */ +/* $Id: macctrls.c,v 1.2 2003/03/18 00:35:40 ben Exp $ */ /* * Copyright (c) 2003 Ben Harris * All rights reserved. @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -89,6 +90,39 @@ static void macctrl_checkbox(struct macctrls *, WindowPtr, struct mac_layoutstate *, union control *); static void macctrl_button(struct macctrls *, WindowPtr, struct mac_layoutstate *, union control *); +#if !TARGET_API_MAC_CARBON +static pascal SInt32 macctrl_sys7_text_cdef(SInt16, ControlRef, + ControlDefProcMessage, SInt32); +#endif + +#if !TARGET_API_MAC_CARBON +/* + * This trick enables us to keep all the CDEF code in the main + * application, which makes life easier. For details, see + * . + */ + +#pragma options align=mac68k +typedef struct { + short jmpabs; /* 4EF9 */ + ControlDefUPP theUPP; +} **PatchCDEF; +#pragma options align=reset +#endif + +static void macctrl_init() +{ +#if !TARGET_API_MAC_CARBON + static int inited = 0; + PatchCDEF cdef; + + if (inited) return; + cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Text); + (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_text_cdef); + inited = 1; +#endif +} + static int macctrl_cmp_byctrl(void *av, void *bv) { @@ -110,7 +144,8 @@ void macctrl_layoutbox(struct controlbox *cb, WindowPtr window, struct mac_layoutstate curstate; ControlRef root; Rect rect; - + + macctrl_init(); #if TARGET_API_MAC_CARBON GetPortBounds(GetWindowPort(window), &rect); #else @@ -205,11 +240,48 @@ static void macctrl_text(struct macctrls *mcs, WindowPtr window, SizeControl(mc->text.tbctrl, curstate->width, height); curstate->pos.v += height + 6; } else { - /* Do something useful */ + Str255 title; + + c2pstrcpy(title, ctrl->text.label); + mc->text.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 0, + SYS7_TEXT_PROC, (long)mc); } add234(mcs->byctrl, mc); } +#if !TARGET_API_MAC_CARBON +static pascal SInt32 macctrl_sys7_text_cdef(SInt16 variant, ControlRef control, + ControlDefProcMessage msg, SInt32 param) +{ + RgnHandle rgn; + + switch (msg) { + case drawCntl: + if ((*control)->contrlVis) + TETextBox((*control)->contrlTitle + 1, (*control)->contrlTitle[0], + &(*control)->contrlRect, teFlushDefault); + return 0; + case calcCRgns: + if (param & (1 << 31)) { + param &= ~(1 << 31); + goto calcthumbrgn; + } + /* FALLTHROUGH */ + case calcCntlRgn: + rgn = (RgnHandle)param; + RectRgn(rgn, &(*control)->contrlRect); + return 0; + case calcThumbRgn: + calcthumbrgn: + rgn = (RgnHandle)param; + SetEmptyRgn(rgn); + return 0; + } + + return 0; +} +#endif + static void macctrl_radio(struct macctrls *mcs, WindowPtr window, struct mac_layoutstate *curstate, union control *ctrl) diff --git a/mac/macresid.h b/mac/macresid.h index 108f47f5..d3489ff7 100644 --- a/mac/macresid.h +++ b/mac/macresid.h @@ -1,4 +1,4 @@ -/* $Id: macresid.h,v 1.10 2003/03/06 23:46:06 ben Exp $ */ +/* $Id: macresid.h,v 1.11 2003/03/18 00:35:40 ben Exp $ */ /* * macresid.h -- Mac resource IDs @@ -58,3 +58,7 @@ /* Controls */ #define cVScroll 128 + +/* xDEFs */ +#define CDEF_Text 128 +#define SYS7_TEXT_PROC (CDEF_Text << 4)