-/* $Id: macctrls.c,v 1.1 2003/03/17 21:40:37 ben Exp $ */
+/* $Id: macctrls.c,v 1.6 2003/03/19 00:40:15 ben Exp $ */
/*
* Copyright (c) 2003 Ben Harris
* All rights reserved.
#include <Appearance.h>
#include <Controls.h>
#include <ControlDefinitions.h>
+#include <Resources.h>
#include <Sound.h>
#include <TextUtils.h>
#include <Windows.h>
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);
+static pascal SInt32 macctrl_sys7_default_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
+ * <http://developer.apple.com/technotes/tn/tn2003.html#custom_code_base>.
+ */
+
+#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);
+ cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Default);
+ (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_default_cdef);
+ inited = 1;
+#endif
+}
+
static int macctrl_cmp_byctrl(void *av, void *bv)
{
struct mac_layoutstate curstate;
ControlRef root;
Rect rect;
-
+
+ macctrl_init();
#if TARGET_API_MAC_CARBON
GetPortBounds(GetWindowPort(window), &rect);
#else
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)
SetControlData(mc->button.tbctrl, kControlEntireControl,
kControlPushButtonDefaultTag,
sizeof(isdefault), &isdefault);
+ } else if (ctrl->button.isdefault) {
+ InsetRect(&bounds, -4, -4);
+ NewControl(window, &bounds, title, TRUE, 0, 0, 1,
+ SYS7_DEFAULT_PROC, (long)mc);
+ }
+ if (mac_gestalts.apprvers >= 0x110) {
+ Boolean iscancel = ctrl->button.iscancel;
+
+ SetControlData(mc->button.tbctrl, kControlEntireControl,
+ kControlPushButtonCancelTag,
+ sizeof(iscancel), &iscancel);
}
add234(mcs->byctrl, mc);
curstate->pos.v += 26;
}
+#if !TARGET_API_MAC_CARBON
+static pascal SInt32 macctrl_sys7_default_cdef(SInt16 variant,
+ ControlRef control,
+ ControlDefProcMessage msg,
+ SInt32 param)
+{
+ RgnHandle rgn;
+ Rect rect;
+ int oval;
+
+ switch (msg) {
+ case drawCntl:
+ if ((*control)->contrlVis) {
+ rect = (*control)->contrlRect;
+ PenNormal();
+ PenSize(3, 3);
+ oval = (rect.bottom - rect.top) / 2 + 2;
+ FrameRoundRect(&rect, oval, oval);
+ }
+ 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
+
void macctrl_activate(WindowPtr window, EventRecord *event)
{
}
}
-union control *dlg_last_focused(void *dlg)
+union control *dlg_last_focused(union control *ctrl, void *dlg)
{
return NULL;
void dlg_text_set(union control *ctrl, void *dlg, char const *text)
{
union macctrl *mc = dlg;
+ Str255 title;
if (mac_gestalts.apprvers >= 0x100)
SetControlData(mc->text.tbctrl, kControlEntireControl,
kControlStaticTextTextTag,
strlen(ctrl->text.label), ctrl->text.label);
+ else {
+ c2pstrcpy(title, text);
+ SetControlTitle(mc->text.tbctrl, title);
+ }
}