struct macctrl_generic generic;
ControlRef tbctrl;
ControlRef tblabel;
+ ControlRef tbbutton;
+ MenuRef menu;
+ int menuid;
+ unsigned int nids;
+ int *ids;
} editbox;
struct {
struct macctrl_generic generic;
struct {
struct macctrl_generic generic;
ControlRef tbctrl;
+ ControlRef tbup;
+ ControlRef tbdown;
ListHandle list;
unsigned int nids;
int *ids;
struct mac_layoutstate *, union control *);
static void macctrl_groupbox(struct macctrls *, WindowPtr,
struct mac_layoutstate *, union control *);
+static void draglist_up(union macctrl *, struct macctrls *);
+static void draglist_down(union macctrl *, struct macctrls *);
+
#if !TARGET_API_MAC_CARBON
static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16, ControlRef,
ControlDefProcMessage, SInt32);
hideshow(mc->editbox.tbctrl);
if (mc->editbox.tblabel != NULL)
hideshow(mc->editbox.tblabel);
+ if (mc->editbox.tbbutton != NULL)
+ hideshow(mc->editbox.tbbutton);
break;
case MACCTRL_RADIO:
for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
break;
case MACCTRL_LISTBOX:
hideshow(mc->listbox.tbctrl);
+ if (mc->listbox.tbup != NULL)
+ hideshow(mc->listbox.tbup);
+ if (mc->listbox.tbdown != NULL)
+ hideshow(mc->listbox.tbdown);
/*
* At least under Mac OS 8.1, hiding a list box
* doesn't hide its scroll bars.
union control *ctrl)
{
union macctrl *mc = snew(union macctrl);
- Rect lbounds, bounds;
+ Rect lbounds, bounds, butbounds;
+ static int nextmenuid = MENU_MIN;
+ int menuid;
+ MenuRef menu;
mc->generic.type = MACCTRL_EDITBOX;
mc->generic.ctrl = ctrl;
}
bounds.top = curstate->pos.v;
bounds.bottom = bounds.top + 22;
+
+ if (ctrl->editbox.has_list) {
+ butbounds = bounds;
+ butbounds.left = butbounds.right - 20;
+ bounds.right -= 26; /* enough for 6 px gap and a button */
+ }
+
if (mac_gestalts.apprvers >= 0x100) {
if (ctrl->editbox.label == NULL)
mc->editbox.tblabel = NULL;
SYS7_EDITBOX_PROC, (long)mc);
}
#endif
+
+ if (ctrl->editbox.has_list) {
+ while (GetMenuHandle(nextmenuid) != NULL)
+ if (++nextmenuid >= MENU_MAX) nextmenuid = MENU_MIN;
+ menuid = nextmenuid++;
+ menu = NewMenu(menuid, "\pdummy");
+ if (menu == NULL) goto nomenu;
+ mc->editbox.menu = menu;
+ mc->editbox.menuid = menuid;
+ InsertMenu(menu, kInsertHierarchicalMenu);
+ mc->editbox.nids = 0;
+ mc->editbox.ids = NULL;
+
+ mc->editbox.tbbutton = NewControl(window, &butbounds, NULL, FALSE,
+ popupTitleLeftJust, menuid, 0,
+ popupMenuProc + popupFixedWidth,
+ (long)mc);
+ }
+
+ nomenu:
+
curstate->pos.v += 28;
add234(mcs->byctrl, mc);
mc->generic.next = mcs->panels[curstate->panelnum];
return 0;
}
#endif
-
+
static void macctrl_radio(struct macctrls *mcs, WindowPtr window,
struct mac_layoutstate *curstate,
union control *ctrl)
union control *ctrl)
{
union macctrl *mc = snew(union macctrl);
- Rect bounds;
+ Rect bounds, upbounds, downbounds;
Size olen;
/* XXX Use label */
bounds.top = curstate->pos.v;
bounds.bottom = bounds.top + 16 * ctrl->listbox.height + 2;
+ if (ctrl->listbox.draglist) {
+ upbounds = downbounds = bounds;
+ upbounds.left = upbounds.right - 58;
+ upbounds.bottom = upbounds.top + 20;
+ downbounds.left = downbounds.right - 58;
+ downbounds.top = upbounds.bottom + 6;
+ downbounds.bottom = downbounds.top + 20;
+ bounds.right -= 64; /* enough for 6 px gap and a button */
+ }
+
if (mac_gestalts.apprvers >= 0x100) {
InsetRect(&bounds, 3, 3);
mc->listbox.tbctrl = NewControl(window, &bounds, NULL, FALSE,
(*mc->listbox.list)->selFlags = lOnlyOne;
#endif
}
+
+ if (ctrl->listbox.draglist) {
+ mc->listbox.tbup = NewControl(window, &upbounds, "\pUp", FALSE, 0, 0, 1,
+ pushButProc, (long)mc);
+ mc->listbox.tbdown = NewControl(window, &downbounds, "\pDown", FALSE, 0, 0, 1,
+ pushButProc, (long)mc);
+ }
+
add234(mcs->byctrl, mc);
curstate->pos.v += 6 + 16 * ctrl->listbox.height + 2;
mc->generic.next = mcs->panels[curstate->panelnum];
HiliteControl(mc->editbox.tbctrl, state);
if (mc->editbox.tblabel != NULL)
HiliteControl(mc->editbox.tblabel, state);
+ if (mc->editbox.tbbutton != NULL)
+ HiliteControl(mc->editbox.tbbutton, state);
break;
case MACCTRL_RADIO:
for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
break;
case MACCTRL_LISTBOX:
HiliteControl(mc->listbox.tbctrl, state);
+ if (mc->listbox.tbup != NULL)
+ HiliteControl(mc->listbox.tbup, state);
+ if (mc->listbox.tbdown != NULL)
+ HiliteControl(mc->listbox.tbdown, state);
break;
case MACCTRL_POPUP:
HiliteControl(mc->popup.tbctrl, state);
TEClick(mouse, !!(event->modifiers & shiftKey), te);
goto done;
}
+ if (mc->generic.type == MACCTRL_EDITBOX &&
+ control == mc->editbox.tbbutton) {
+ dlg_editbox_set(mc->generic.ctrl, mcs,
+ cp_enumerate(dlg_listbox_index(mc->generic.ctrl, mcs)));
+ ctrlevent(mcs, mc, EVENT_VALCHANGE);
+ }
if (mc->generic.type == MACCTRL_LISTBOX &&
(control == mc->listbox.tbctrl ||
control == (*mc->listbox.list)->vScroll)) {
ctrlevent(mcs, mc, EVENT_SELCHANGE);
goto done;
}
+ if (mc->generic.type == MACCTRL_LISTBOX &&
+ control == mc->listbox.tbup)
+ draglist_up(mc, mcs);
+ if (mc->generic.type == MACCTRL_LISTBOX &&
+ control == mc->listbox.tbdown)
+ draglist_down(mc, mcs);
#endif
trackresult = TrackControl(control, mouse, (ControlActionUPP)-1);
}
if (trackresult != 0)
ctrlevent(mcs, mc, EVENT_ACTION);
break;
+ case MACCTRL_EDITBOX:
+ if (control == mc->editbox.tbbutton) {
+ dlg_editbox_set(mc->generic.ctrl, mcs,
+ cp_enumerate(dlg_listbox_index(mc->generic.ctrl, mcs)));
+ ctrlevent(mcs, mc, EVENT_VALCHANGE);
+ }
+ break;
case MACCTRL_LISTBOX:
+ if (control == mc->listbox.tbup)
+ draglist_up(mc, mcs);
+ if (control == mc->listbox.tbdown)
+ draglist_down(mc, mcs);
+
/* FIXME spot double-click */
ctrlevent(mcs, mc, EVENT_SELCHANGE);
break;
SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
}
+static void dlg_macedit_clear(union control *ctrl, void *dlg)
+{
+ struct macctrls *mcs = dlg;
+ union macctrl *mc = findbyctrl(mcs, ctrl);
+ MenuRef menu = mc->editbox.menu;
+ unsigned int i, n;
+
+ if (mc == NULL) return;
+ n = CountMenuItems(menu);
+ for (i = 0; i < n; i++)
+ DeleteMenuItem(menu, n - i);
+ mc->editbox.nids = 0;
+ sfree(mc->editbox.ids);
+ mc->editbox.ids = NULL;
+ SetControlMaximum(mc->editbox.tbbutton, CountMenuItems(menu));
+}
+
static void dlg_maclist_clear(union control *ctrl, void *dlg)
{
struct macctrls *mcs = dlg;
else
dlg_maclist_clear(ctrl, dlg);
break;
+ case CTRL_EDITBOX:
+ dlg_macedit_clear(ctrl, dlg);
}
}
SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
}
+static void dlg_macedit_del(union control *ctrl, void *dlg, int index)
+{
+ struct macctrls *mcs = dlg;
+ union macctrl *mc = findbyctrl(mcs, ctrl);
+ MenuRef menu = mc->editbox.menu;
+
+ if (mc == NULL) return;
+ DeleteMenuItem(menu, index + 1);
+ if (mc->editbox.ids != NULL)
+ memcpy(mc->editbox.ids + index, mc->editbox.ids + index + 1,
+ (mc->editbox.nids - index - 1) * sizeof(*mc->editbox.ids));
+ SetControlMaximum(mc->editbox.tbbutton, CountMenuItems(menu));
+}
+
static void dlg_maclist_del(union control *ctrl, void *dlg, int index)
{
struct macctrls *mcs = dlg;
else
dlg_maclist_del(ctrl, dlg, index);
break;
+ case CTRL_EDITBOX:
+ dlg_macedit_del(ctrl, dlg, index);
}
}
SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
}
+static void dlg_macedit_add(union control *ctrl, void *dlg, char const *text)
+{
+ struct macctrls *mcs = dlg;
+ union macctrl *mc = findbyctrl(mcs, ctrl);
+ MenuRef menu = mc->editbox.menu;
+ Str255 itemstring;
+
+ if (mc == NULL) return;
+ assert(text[0] != '\0');
+ c2pstrcpy(itemstring, text);
+ AppendMenu(menu, "\pdummy");
+ SetMenuItemText(menu, CountMenuItems(menu), itemstring);
+ SetControlMaximum(mc->editbox.tbbutton, CountMenuItems(menu));
+}
static void dlg_maclist_add(union control *ctrl, void *dlg, char const *text)
{
else
dlg_maclist_add(ctrl, dlg, text);
break;
+ case CTRL_EDITBOX:
+ dlg_macedit_add(ctrl, dlg, text);
+ break;
}
}
mc->popup.ids[index] = id;
}
+static void dlg_macedit_addwithid(union control *ctrl, void *dlg,
+ char const *text, int id)
+{
+ struct macctrls *mcs = dlg;
+ union macctrl *mc = findbyctrl(mcs, ctrl);
+ MenuRef menu = mc->editbox.menu;
+ unsigned int index;
+
+ if (mc == NULL) return;
+ dlg_macedit_add(ctrl, dlg, text);
+ index = CountMenuItems(menu) - 1;
+ if (mc->editbox.nids <= index) {
+ mc->editbox.nids = index + 1;
+ mc->editbox.ids = sresize(mc->editbox.ids, mc->editbox.nids, int);
+ }
+ mc->editbox.ids[index] = id;
+}
+
static void dlg_maclist_addwithid(union control *ctrl, void *dlg,
char const *text, int id)
{
else
dlg_maclist_addwithid(ctrl, dlg, text, id);
break;
+ case CTRL_EDITBOX:
+ dlg_macedit_addwithid(ctrl, dlg, text, id);
+ break;
}
}
assert(mc->listbox.ids != NULL && mc->listbox.nids > index);
return mc->listbox.ids[index];
}
+ case CTRL_EDITBOX:
+ assert(mc->editbox.ids != NULL && mc->editbox.nids > index);
+ return mc->editbox.ids[index];
}
return -1;
}
else
return -1;
}
+ case CTRL_EDITBOX:
+ return GetControlValue(mc->editbox.tbbutton) - 1;
}
return -1;
}
cell.v = index;
return LGetSelect(FALSE, &cell, mc->listbox.list);
}
+ case CTRL_EDITBOX:
+ return GetControlValue(mc->editbox.tbbutton) - 1 == index;
}
return FALSE;
}
if (ctrl->listbox.height == 0)
SetControlValue(mc->popup.tbctrl, index + 1);
break;
+ case CTRL_EDITBOX:
+ SetControlValue(mc->editbox.tbbutton, index + 1);
+ }
+}
+
+static void draglist_move(union macctrl *mc, struct macctrls *mcs,
+ int direction)
+{
+ ListBounds bounds;
+ Cell cell = {0, 0};
+ char current[255];
+ char new[255];
+ short curlength = 255;
+ short newlength = 255;
+ int curid, newid;
+
+ int index = dlg_listbox_index(mc->generic.ctrl, mcs);
+
+#if TARGET_API_MAC_CARBON
+ GetListDataBounds(mc->listbox.list, &bounds);
+#else
+ bounds = (*mc->listbox.list)->dataBounds;
+#endif
+
+ if ((index < 0) ||
+ (index == 0 && direction < 0) ||
+ (index == bounds.bottom-1 && direction > 0)) {
+ SysBeep(30);
+ return;
}
+
+ /* Swap the contents of the selected and target list cells */
+
+ cell.v = index;
+ LGetCell(current, &curlength, cell, mc->listbox.list);
+ current[curlength] = '\0';
+ cell.v += direction;
+ LGetCell(new, &newlength, cell, mc->listbox.list);
+ new[newlength] = '\0';
+
+ cell.v = index;
+ LSetCell(new, newlength, cell, mc->listbox.list);
+ cell.v += direction;
+ LSetCell(current, curlength, cell, mc->listbox.list);
+
+ /* Move the selection to the target list cell */
+
+ cell.v = index;
+ LSetSelect(FALSE, cell, mc->listbox.list);
+ cell.v += direction;
+ LSetSelect(TRUE, cell, mc->listbox.list);
+ DrawOneControl(mc->listbox.tbctrl);
+
+ /* Swap the ids of the list cells */
+
+ curid = mc->listbox.ids[index];
+ newid = mc->listbox.ids[index + direction];
+ mc->listbox.ids[index] = newid;
+ mc->listbox.ids[index + direction] = curid;
+
+ ctrlevent(mcs, mc, EVENT_VALCHANGE);
}
+static void draglist_up(union macctrl *mc, struct macctrls *mcs)
+{
+ draglist_move(mc, mcs, -1);
+}
+
+static void draglist_down(union macctrl *mc, struct macctrls *mcs)
+{
+ draglist_move(mc, mcs, +1);
+}
/*
* Text control
return 0;
}
+void dlg_label_change(union control *ctrl, void *dlg, char const *text)
+{
+ /*
+ * This function is currently only used by the config box to
+ * switch the labels on the host and port boxes between serial
+ * and network modes. Since the Mac port does not have a serial
+ * back end, this function can safely do nothing.
+ */
+}
+
+
/*
* Local Variables:
* c-file-style: "simon"