+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);
+}