-/* $Id: macctrls.c,v 1.29 2003/04/05 18:00:46 ben Exp $ */
+/* $Id: macctrls.c,v 1.30 2003/04/05 22:00:57 ben Exp $ */
/*
* Copyright (c) 2003 Ben Harris
* All rights reserved.
MACCTRL_RADIO,
MACCTRL_CHECKBOX,
MACCTRL_BUTTON,
+ MACCTRL_LISTBOX,
MACCTRL_POPUP
} type;
/* Template from which this was generated */
struct {
struct macctrl_generic generic;
ControlRef tbctrl;
+ unsigned int nids;
+ int *ids;
+ } listbox;
+ struct {
+ struct macctrl_generic generic;
+ ControlRef tbctrl;
MenuRef menu;
int menuid;
unsigned int nids;
struct mac_layoutstate *, union control *);
static void macctrl_button(struct macctrls *, WindowPtr,
struct mac_layoutstate *, union control *);
+static void macctrl_listbox(struct macctrls *, WindowPtr,
+ struct mac_layoutstate *, union control *);
static void macctrl_popup(struct macctrls *, WindowPtr,
struct mac_layoutstate *, union control *);
#if !TARGET_API_MAC_CARBON
}
macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs);
}
- macctrl_switchtopanel(mcs, 1);
+ macctrl_switchtopanel(mcs, 19);
/* 14 = proxies, 20 = SSH bugs */
}
case CTRL_LISTBOX:
if (ctrl->listbox.height == 0)
macctrl_popup(mcs, window, &cols[colstart], ctrl);
+ else
+ macctrl_listbox(mcs, window, &cols[colstart], ctrl);
break;
}
}
{
unsigned int i, j;
union macctrl *mc;
+ ListHandle list;
+ Size olen;
+
#define hideshow(c) do { \
if (i == which) ShowControl(c); else HideControl(c); \
case MACCTRL_BUTTON:
hideshow(mc->button.tbctrl);
break;
+ case MACCTRL_LISTBOX:
+ hideshow(mc->listbox.tbctrl);
+ /*
+ * At least under Mac OS 8.1, hiding a list box
+ * doesn't hide its scroll bars.
+ */
+ if (mac_gestalts.apprvers >= 0x100) {
+ if (GetControlData(mc->listbox.tbctrl,
+ kControlEntireControl,
+ kControlListBoxListHandleTag,
+ sizeof(list), &list, &olen) == noErr)
+#if TARGET_API_MAC_CARBON
+ hideshow(GetListVerticalScrollBar(list));
+#else
+ hideshow((*list)->vScroll);
+#endif
+ }
+ break;
case MACCTRL_POPUP:
hideshow(mc->popup.tbctrl);
break;
}
#endif
+static void macctrl_listbox(struct macctrls *mcs, WindowPtr window,
+ struct mac_layoutstate *curstate,
+ union control *ctrl)
+{
+ union macctrl *mc = snew(union macctrl);
+ Rect bounds;
+ ListHandle list;
+ Size olen;
+
+ if (mac_gestalts.apprvers < 0x100)
+ return;
+ if (ctrl->listbox.label != NULL)
+ fprintf(stderr, " label = %s\n", ctrl->listbox.label);
+ fprintf(stderr, " height = %d\n", ctrl->listbox.height);
+ if (ctrl->listbox.draglist)
+ fprintf(stderr, " draglist\n");
+ if (ctrl->listbox.multisel)
+ fprintf(stderr, " multisel\n");
+ fprintf(stderr, " ncols = %d\n", ctrl->listbox.ncols);
+ assert(ctrl->listbox.percentwidth == 100);
+ mc->generic.type = MACCTRL_LISTBOX;
+ mc->generic.ctrl = ctrl;
+ mc->generic.privdata = NULL;
+ /* The list starts off empty */
+ mc->listbox.nids = 0;
+ mc->listbox.ids = NULL;
+ bounds.left = curstate->pos.h;
+ bounds.right = bounds.left + curstate->width;
+ bounds.top = curstate->pos.v;
+ bounds.bottom = bounds.top + 20 * ctrl->listbox.height;
+
+ mc->button.tbctrl = NewControl(window, &bounds, NULL, TRUE,
+ ldes_Default, 0, 0,
+ kControlListBoxProc, (long)mc);
+ if (!ctrl->listbox.multisel) {
+ if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
+ kControlListBoxListHandleTag, sizeof(list), &list,
+ &olen) != noErr)
+ return;
+#if TARGET_API_MAC_CARBON
+ SetListSelectionFlags(list, lOnlyOne);
+#else
+ (*list)->selFlags = lOnlyOne;
+#endif
+ }
+ add234(mcs->byctrl, mc);
+ curstate->pos.v += 6 + 20 * ctrl->listbox.height;
+ mc->generic.next = mcs->panels[curstate->panelnum];
+ mcs->panels[curstate->panelnum] = mc;
+ ctrlevent(mcs, mc, EVENT_REFRESH);
+}
+
+
static void macctrl_popup(struct macctrls *mcs, WindowPtr window,
struct mac_layoutstate *curstate,
union control *ctrl)
if (mc->button.tbring != NULL)
HiliteControl(mc->button.tbring, state);
break;
+ case MACCTRL_LISTBOX:
+ HiliteControl(mc->listbox.tbctrl, state);
+ break;
case MACCTRL_POPUP:
HiliteControl(mc->popup.tbctrl, state);
break;
if (trackresult != 0)
ctrlevent(mcs, mc, EVENT_ACTION);
break;
+ case MACCTRL_LISTBOX:
+ /* FIXME spot double-click */
+ ctrlevent(mcs, mc, EVENT_SELCHANGE);
+ break;
case MACCTRL_POPUP:
ctrlevent(mcs, mc, EVENT_SELCHANGE);
break;
union macctrl *mc = findbyctrl(mcs, ctrl);
int i;
- assert(mc != NULL);
+ if (mc == NULL) return;
for (i = 0; i < ctrl->radio.nbuttons; i++) {
if (i == whichbutton)
SetControlValue(mc->radio.tbctrls[i],
struct macctrls *mcs = dlg;
union macctrl *mc = findbyctrl(mcs, ctrl);
- assert(mc != NULL);
+ if (mc == NULL) return;
SetControlValue(mc->checkbox.tbctrl,
checked ? kControlCheckBoxCheckedValue :
kControlCheckBoxUncheckedValue);
union macctrl *mc = findbyctrl(mcs, ctrl);
GrafPtr saveport;
- assert(mc != NULL);
+ if (mc == NULL) return;
assert(mc->generic.type == MACCTRL_EDITBOX);
GetPort(&saveport);
SetPort((GrafPtr)(GetWindowPort(mcs->window)));
MenuRef menu = mc->popup.menu;
unsigned int i, n;
+ if (mc == NULL) return;
fprintf(stderr, " popup_clear\n");
n = CountMenuItems(menu);
for (i = 0; i < n; i++)
SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
}
+static void dlg_maclist_clear(union control *ctrl, void *dlg)
+{
+ struct macctrls *mcs = dlg;
+ union macctrl *mc = findbyctrl(mcs, ctrl);
+ ListHandle list;
+ Size olen;
+
+ if (mc == NULL) return;
+ fprintf(stderr, " maclist_clear\n");
+ if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
+ kControlListBoxListHandleTag, sizeof(list), &list,
+ &olen) != noErr)
+ return;
+ LDelRow(0, 0, list);
+ mc->listbox.nids = 0;
+ sfree(mc->listbox.ids);
+ mc->listbox.ids = NULL;
+ DrawOneControl(mc->listbox.tbctrl);
+}
+
void dlg_listbox_clear(union control *ctrl, void *dlg)
{
if (ctrl->listbox.height == 0)
dlg_macpopup_clear(ctrl, dlg);
+ else
+ dlg_maclist_clear(ctrl, dlg);
}
static void dlg_macpopup_del(union control *ctrl, void *dlg, int index)
union macctrl *mc = findbyctrl(mcs, ctrl);
MenuRef menu = mc->popup.menu;
+ if (mc == NULL) return;
fprintf(stderr, " popup_del %d\n", index);
DeleteMenuItem(menu, index + 1);
if (mc->popup.ids != NULL)
SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
}
+static void dlg_maclist_del(union control *ctrl, void *dlg, int index)
+{
+ struct macctrls *mcs = dlg;
+ union macctrl *mc = findbyctrl(mcs, ctrl);
+ ListHandle list;
+ Size olen;
+
+ if (mc == NULL) return;
+ fprintf(stderr, " maclist_del %d\n", index);
+ if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
+ kControlListBoxListHandleTag, sizeof(list), &list,
+ &olen) != noErr)
+ return;
+ LDelRow(1, index, list);
+ if (mc->listbox.ids != NULL)
+ memcpy(mc->listbox.ids + index, mc->listbox.ids + index + 1,
+ (mc->listbox.nids - index - 1) * sizeof(*mc->listbox.ids));
+ DrawOneControl(mc->listbox.tbctrl);
+}
+
void dlg_listbox_del(union control *ctrl, void *dlg, int index)
{
if (ctrl->listbox.height == 0)
dlg_macpopup_del(ctrl, dlg, index);
+ else
+ dlg_maclist_del(ctrl, dlg, index);
}
static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text)
MenuRef menu = mc->popup.menu;
Str255 itemstring;
+ if (mc == NULL) return;
fprintf(stderr, " popup_add %s\n", text);
assert(text[0] != '\0');
c2pstrcpy(itemstring, text);
SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
}
+
+static void dlg_maclist_add(union control *ctrl, void *dlg, char const *text)
+{
+ struct macctrls *mcs = dlg;
+ union macctrl *mc = findbyctrl(mcs, ctrl);
+ ListHandle list;
+ Size olen;
+ ListBounds bounds;
+ Cell cell = { 0, 0 };
+
+ if (mc == NULL) return;
+ fprintf(stderr, " maclist_add %s\n", text);
+ if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
+ kControlListBoxListHandleTag, sizeof(list), &list,
+ &olen) != noErr)
+ return;
+#if TARGET_API_MAC_CARBON
+ GetListDataBounds(list, &bounds);
+#else
+ bounds = (*list)->dataBounds;
+#endif
+ cell.v = bounds.bottom;
+ LAddRow(1, cell.v, list);
+ LSetCell(text, strlen(text), cell, list);
+ DrawOneControl(mc->listbox.tbctrl);
+}
+
void dlg_listbox_add(union control *ctrl, void *dlg, char const *text)
{
if (ctrl->listbox.height == 0)
dlg_macpopup_add(ctrl, dlg, text);
+ else
+ dlg_maclist_add(ctrl, dlg, text);
}
static void dlg_macpopup_addwithid(union control *ctrl, void *dlg,
MenuRef menu = mc->popup.menu;
unsigned int index;
- fprintf(stderr, " popup_addwthindex %s, %d\n", text, id);
+ if (mc == NULL) return;
+ fprintf(stderr, " popup_addwthid %s, %d\n", text, id);
dlg_macpopup_add(ctrl, dlg, text);
index = CountMenuItems(menu) - 1;
if (mc->popup.nids <= index) {
mc->popup.ids[index] = id;
}
+static void dlg_maclist_addwithid(union control *ctrl, void *dlg,
+ char const *text, int id)
+{
+ struct macctrls *mcs = dlg;
+ union macctrl *mc = findbyctrl(mcs, ctrl);
+ ListHandle list;
+ Size olen;
+ ListBounds bounds;
+ int index;
+
+ if (mc == NULL) return;
+ fprintf(stderr, " maclist_addwithid %s %d\n", text, id);
+ dlg_maclist_add(ctrl, dlg, text);
+ if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
+ kControlListBoxListHandleTag, sizeof(list), &list,
+ &olen) != noErr)
+ return;
+#if TARGET_API_MAC_CARBON
+ GetListDataBounds(list, &bounds);
+#else
+ bounds = (*list)->dataBounds;
+#endif
+ index = bounds.bottom;
+ if (mc->listbox.nids <= index) {
+ mc->listbox.nids = index + 1;
+ mc->listbox.ids = sresize(mc->listbox.ids, mc->listbox.nids, int);
+ }
+ mc->listbox.ids[index] = id;
+}
+
void dlg_listbox_addwithid(union control *ctrl, void *dlg,
char const *text, int id)
{
if (ctrl->listbox.height == 0)
dlg_macpopup_addwithid(ctrl, dlg, text, id);
+ else
+ dlg_maclist_addwithid(ctrl, dlg, text, id);
}
int dlg_listbox_getid(union control *ctrl, void *dlg, int index)
struct macctrls *mcs = dlg;
union macctrl *mc = findbyctrl(mcs, ctrl);
+ assert(mc != NULL);
if (ctrl->listbox.height == 0) {
assert(mc->popup.ids != NULL && mc->popup.nids > index);
return mc->popup.ids[index];
return 0;
}
-int dlg_listbox_index(union control *ctrl, void *dlg)
+static int dlg_maclist_index(union control *ctrl, void *dlg)
{
struct macctrls *mcs = dlg;
union macctrl *mc = findbyctrl(mcs, ctrl);
+ ListHandle list;
+ Size olen;
+ Cell cell = { 0, 0 };
- if (ctrl->listbox.height == 0)
+ if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
+ kControlListBoxListHandleTag, sizeof(list), &list,
+ &olen) != noErr)
+ return -1;
+ if (LGetSelect(TRUE, &cell, list))
+ return cell.v;
+ else
+ return -1;
+}
+
+int dlg_listbox_index(union control *ctrl, void *dlg)
+{
+ struct macctrls *mcs = dlg;
+ union macctrl *mc;
+
+ if (ctrl->listbox.height == 0) {
+ mc = findbyctrl(mcs, ctrl);
+ assert(mc != NULL);
return GetControlValue(mc->popup.tbctrl) - 1;
- return 0;
-};
+ } else
+ return dlg_maclist_index(ctrl, dlg);
+}
+
+static int dlg_maclist_issel(union control *ctrl, void *dlg, int index)
+{
+ struct macctrls *mcs = dlg;
+ union macctrl *mc = findbyctrl(mcs, ctrl);
+ ListHandle list;
+ Size olen;
+ Cell cell = { 0, 0 };
+
+ if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
+ kControlListBoxListHandleTag, sizeof(list), &list,
+ &olen) != noErr)
+ return FALSE;
+ cell.v = index;
+ return LGetSelect(FALSE, &cell, list);
+}
int dlg_listbox_issel(union control *ctrl, void *dlg, int index)
{
if (ctrl->listbox.height == 0)
return GetControlValue(mc->popup.tbctrl) - 1 == index;
- return 0;
-};
+ else
+ return dlg_maclist_issel(ctrl, dlg, index);
+}
void dlg_listbox_select(union control *ctrl, void *dlg, int index)
{
struct macctrls *mcs = dlg;
union macctrl *mc = findbyctrl(mcs, ctrl);
+ if (mc == NULL) return;
if (ctrl->listbox.height == 0)
SetControlValue(mc->popup.tbctrl, index + 1);
};
struct macctrls *mcs = dlg;
union macctrl *mc = findbyctrl(mcs, ctrl);
- assert(mc != NULL);
+ if (mc == NULL) return;
if (mac_gestalts.apprvers >= 0x100)
SetControlData(mc->text.tbctrl, kControlEntireControl,
kControlStaticTextTextTag, strlen(text), text);