1 /* $Id: macctrls.c,v 1.30 2003/04/05 22:00:57 ben Exp $ */
3 * Copyright (c) 2003 Ben Harris
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <Appearance.h>
31 #include <ControlDefinitions.h>
34 #include <Resources.h>
38 #include <TextUtils.h>
39 #include <ToolUtils.h>
51 /* Range of menu IDs for popup menus */
57 struct macctrl_generic {
67 /* Template from which this was generated */
69 /* Next control in this panel */
75 struct macctrl_generic generic;
79 struct macctrl_generic generic;
84 struct macctrl_generic generic;
89 struct macctrl_generic generic;
93 struct macctrl_generic generic;
98 struct macctrl_generic generic;
104 struct macctrl_generic generic;
113 struct mac_layoutstate {
116 unsigned int panelnum;
119 #define ctrlevent(mcs, mc, event) do { \
120 if ((mc)->generic.ctrl->generic.handler != NULL) \
121 (*(mc)->generic.ctrl->generic.handler)((mc)->generic.ctrl, (mcs),\
122 (mcs)->data, (event)); \
125 #define findbyctrl(mcs, ctrl) \
126 find234((mcs)->byctrl, (ctrl), macctrl_cmp_byctrl_find)
128 static void macctrl_layoutset(struct mac_layoutstate *, struct controlset *,
129 WindowPtr, struct macctrls *);
130 static void macctrl_switchtopanel(struct macctrls *, unsigned int);
131 static void macctrl_setfocus(struct macctrls *, union macctrl *);
132 static void macctrl_text(struct macctrls *, WindowPtr,
133 struct mac_layoutstate *, union control *);
134 static void macctrl_editbox(struct macctrls *, WindowPtr,
135 struct mac_layoutstate *, union control *);
136 static void macctrl_radio(struct macctrls *, WindowPtr,
137 struct mac_layoutstate *, union control *);
138 static void macctrl_checkbox(struct macctrls *, WindowPtr,
139 struct mac_layoutstate *, union control *);
140 static void macctrl_button(struct macctrls *, WindowPtr,
141 struct mac_layoutstate *, union control *);
142 static void macctrl_listbox(struct macctrls *, WindowPtr,
143 struct mac_layoutstate *, union control *);
144 static void macctrl_popup(struct macctrls *, WindowPtr,
145 struct mac_layoutstate *, union control *);
146 #if !TARGET_API_MAC_CARBON
147 static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16, ControlRef,
148 ControlDefProcMessage, SInt32);
149 static pascal SInt32 macctrl_sys7_default_cdef(SInt16, ControlRef,
150 ControlDefProcMessage, SInt32);
153 #if !TARGET_API_MAC_CARBON
155 * This trick enables us to keep all the CDEF code in the main
156 * application, which makes life easier. For details, see
157 * <http://developer.apple.com/technotes/tn/tn2003.html#custom_code_base>.
160 #pragma options align=mac68k
162 short jmpabs; /* 4EF9 */
163 ControlDefUPP theUPP;
165 #pragma options align=reset
168 static void macctrl_init()
170 #if !TARGET_API_MAC_CARBON
171 static int inited = 0;
175 cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_EditBox);
176 (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_editbox_cdef);
177 cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Default);
178 (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_default_cdef);
184 static int macctrl_cmp_byctrl(void *av, void *bv)
186 union macctrl *a = (union macctrl *)av;
187 union macctrl *b = (union macctrl *)bv;
189 if (a->generic.ctrl < b->generic.ctrl)
191 else if (a->generic.ctrl > b->generic.ctrl)
197 static int macctrl_cmp_byctrl_find(void *av, void *bv)
199 union control *a = (union control *)av;
200 union macctrl *b = (union macctrl *)bv;
202 if (a < b->generic.ctrl)
204 else if (a > b->generic.ctrl)
210 void macctrl_layoutbox(struct controlbox *cb, WindowPtr window,
211 struct macctrls *mcs)
214 struct mac_layoutstate curstate;
219 #if TARGET_API_MAC_CARBON
220 GetPortBounds(GetWindowPort(window), &rect);
222 rect = window->portRect;
224 curstate.pos.h = rect.left + 13;
225 curstate.pos.v = rect.bottom - 33;
226 curstate.width = rect.right - rect.left - (13 * 2);
227 if (mac_gestalts.apprvers >= 0x100)
228 CreateRootControl(window, &root);
229 mcs->window = window;
230 mcs->byctrl = newtree234(macctrl_cmp_byctrl);
232 mcs->defbutton = NULL;
233 mcs->canbutton = NULL;
234 /* Count the number of panels */
236 for (i = 1; i < cb->nctrlsets; i++)
237 if (strcmp(cb->ctrlsets[i]->pathname, cb->ctrlsets[i-1]->pathname))
239 mcs->panels = snewn(mcs->npanels, union macctrl *);
240 memset(mcs->panels, 0, sizeof(*mcs->panels) * mcs->npanels);
241 curstate.panelnum = 0;
242 for (i = 0; i < cb->nctrlsets; i++) {
243 if (i > 0 && strcmp(cb->ctrlsets[i]->pathname,
244 cb->ctrlsets[i-1]->pathname)) {
245 curstate.pos.v = rect.top + 13;
247 assert(curstate.panelnum < mcs->npanels);
249 macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs);
251 macctrl_switchtopanel(mcs, 19);
252 /* 14 = proxies, 20 = SSH bugs */
257 static void macctrl_layoutset(struct mac_layoutstate *curstate,
258 struct controlset *s,
259 WindowPtr window, struct macctrls *mcs)
261 unsigned int i, j, ncols, colstart;
262 struct mac_layoutstate cols[MAXCOLS];
264 fprintf(stderr, "--- begin set ---\n");
265 fprintf(stderr, "pathname = %s\n", s->pathname);
266 if (s->boxname && *s->boxname)
267 fprintf(stderr, "boxname = %s\n", s->boxname);
269 fprintf(stderr, "boxtitle = %s\n", s->boxtitle);
274 for (i = 0; i < s->ncontrols; i++) {
275 union control *ctrl = s->ctrls[i];
278 colstart = COLUMN_START(ctrl->generic.column);
279 switch (ctrl->generic.type) {
280 case CTRL_TEXT: s = "text"; break;
281 case CTRL_EDITBOX: s = "editbox"; break;
282 case CTRL_RADIO: s = "radio"; break;
283 case CTRL_CHECKBOX: s = "checkbox"; break;
284 case CTRL_BUTTON: s = "button"; break;
285 case CTRL_LISTBOX: s = "listbox"; break;
286 case CTRL_COLUMNS: s = "columns"; break;
287 case CTRL_FILESELECT: s = "fileselect"; break;
288 case CTRL_FONTSELECT: s = "fontselect"; break;
289 case CTRL_TABDELAY: s = "tabdelay"; break;
290 default: s = "unknown"; break;
292 fprintf(stderr, " control: %s\n", s);
293 switch (ctrl->generic.type) {
295 if (ctrl->columns.ncols != 1) {
296 ncols = ctrl->columns.ncols;
297 fprintf(stderr, " split to %d\n", ncols);
298 assert(ncols <= MAXCOLS);
299 for (j = 0; j < ncols; j++) {
302 cols[j].pos.h = cols[j-1].pos.h + cols[j-1].width + 6;
304 cols[j].width = curstate->width -
305 (cols[j].pos.h - curstate->pos.h);
307 cols[j].width = (curstate->width + 6) *
308 ctrl->columns.percentages[j] / 100 - 6;
311 fprintf(stderr, " join\n");
312 for (j = 0; j < ncols; j++)
313 if (cols[j].pos.v > cols[0].pos.v)
314 cols[0].pos.v = cols[j].pos.v;
315 cols[0].width = curstate->width;
320 macctrl_text(mcs, window, &cols[colstart], ctrl);
323 macctrl_editbox(mcs, window, &cols[colstart], ctrl);
326 macctrl_radio(mcs, window, &cols[colstart], ctrl);
329 macctrl_checkbox(mcs, window, &cols[colstart], ctrl);
332 macctrl_button(mcs, window, &cols[colstart], ctrl);
335 if (ctrl->listbox.height == 0)
336 macctrl_popup(mcs, window, &cols[colstart], ctrl);
338 macctrl_listbox(mcs, window, &cols[colstart], ctrl);
342 for (j = 0; j < ncols; j++)
343 if (cols[j].pos.v > curstate->pos.v)
344 curstate->pos.v = cols[j].pos.v;
347 static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which)
355 #define hideshow(c) do { \
356 if (i == which) ShowControl(c); else HideControl(c); \
359 mcs->curpanel = which;
360 /* Panel 0 is special and always visible. */
361 for (i = 1; i < mcs->npanels; i++)
362 for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) {
363 #if !TARGET_API_MAC_CARBON
364 if (mcs->focus == mc)
365 macctrl_setfocus(mcs, NULL);
367 switch (mc->generic.type) {
369 hideshow(mc->text.tbctrl);
371 case MACCTRL_EDITBOX:
372 hideshow(mc->editbox.tbctrl);
373 if (mc->editbox.tblabel != NULL)
374 hideshow(mc->editbox.tblabel);
377 for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
378 hideshow(mc->radio.tbctrls[j]);
379 if (mc->radio.tblabel != NULL)
380 hideshow(mc->radio.tblabel);
382 case MACCTRL_CHECKBOX:
383 hideshow(mc->checkbox.tbctrl);
386 hideshow(mc->button.tbctrl);
388 case MACCTRL_LISTBOX:
389 hideshow(mc->listbox.tbctrl);
391 * At least under Mac OS 8.1, hiding a list box
392 * doesn't hide its scroll bars.
394 if (mac_gestalts.apprvers >= 0x100) {
395 if (GetControlData(mc->listbox.tbctrl,
396 kControlEntireControl,
397 kControlListBoxListHandleTag,
398 sizeof(list), &list, &olen) == noErr)
399 #if TARGET_API_MAC_CARBON
400 hideshow(GetListVerticalScrollBar(list));
402 hideshow((*list)->vScroll);
407 hideshow(mc->popup.tbctrl);
413 #if !TARGET_API_MAC_CARBON
415 * System 7 focus manipulation
417 static void macctrl_defocus(union macctrl *mc)
420 assert(mac_gestalts.apprvers < 0x100);
421 switch (mc->generic.type) {
422 case MACCTRL_EDITBOX:
423 TEDeactivate((TEHandle)(*mc->editbox.tbctrl)->contrlData);
428 static void macctrl_enfocus(union macctrl *mc)
431 assert(mac_gestalts.apprvers < 0x100);
432 switch (mc->generic.type) {
433 case MACCTRL_EDITBOX:
434 TEActivate((TEHandle)(*mc->editbox.tbctrl)->contrlData);
439 static void macctrl_setfocus(struct macctrls *mcs, union macctrl *mc)
442 if (mcs->focus != NULL)
443 macctrl_defocus(mcs->focus);
450 static void macctrl_text(struct macctrls *mcs, WindowPtr window,
451 struct mac_layoutstate *curstate,
454 union macctrl *mc = snew(union macctrl);
458 assert(ctrl->text.label != NULL);
459 fprintf(stderr, " label = %s\n", ctrl->text.label);
460 mc->generic.type = MACCTRL_TEXT;
461 mc->generic.ctrl = ctrl;
462 mc->generic.privdata = NULL;
463 bounds.left = curstate->pos.h;
464 bounds.right = bounds.left + curstate->width;
465 bounds.top = curstate->pos.v;
466 bounds.bottom = bounds.top + 16;
467 if (mac_gestalts.apprvers >= 0x100) {
470 mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
471 kControlStaticTextProc, (long)mc);
472 SetControlData(mc->text.tbctrl, kControlEntireControl,
473 kControlStaticTextTextTag,
474 strlen(ctrl->text.label), ctrl->text.label);
475 GetControlData(mc->text.tbctrl, kControlEntireControl,
476 kControlStaticTextTextHeightTag,
477 sizeof(height), &height, &olen);
479 #if !TARGET_API_MAC_CARBON
483 mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
484 SYS7_TEXT_PROC, (long)mc);
485 te = (TEHandle)(*mc->text.tbctrl)->contrlData;
486 TESetText(ctrl->text.label, strlen(ctrl->text.label), te);
487 height = TEGetHeight(1, (*te)->nLines, te);
490 fprintf(stderr, " height = %d\n", height);
491 SizeControl(mc->text.tbctrl, curstate->width, height);
492 curstate->pos.v += height + 6;
493 add234(mcs->byctrl, mc);
494 mc->generic.next = mcs->panels[curstate->panelnum];
495 mcs->panels[curstate->panelnum] = mc;
498 static void macctrl_editbox(struct macctrls *mcs, WindowPtr window,
499 struct mac_layoutstate *curstate,
502 union macctrl *mc = snew(union macctrl);
503 Rect lbounds, bounds;
505 if (ctrl->editbox.label != NULL)
506 fprintf(stderr, " label = %s\n", ctrl->editbox.label);
507 fprintf(stderr, " percentwidth = %d\n", ctrl->editbox.percentwidth);
508 if (ctrl->editbox.password) fprintf(stderr, " password\n");
509 if (ctrl->editbox.has_list) fprintf(stderr, " has list\n");
510 mc->generic.type = MACCTRL_EDITBOX;
511 mc->generic.ctrl = ctrl;
512 mc->generic.privdata = NULL;
513 lbounds.left = curstate->pos.h;
514 lbounds.top = curstate->pos.v;
515 if (ctrl->editbox.percentwidth == 100) {
516 if (ctrl->editbox.label != NULL) {
517 lbounds.right = lbounds.left + curstate->width;
518 lbounds.bottom = lbounds.top + 16;
519 curstate->pos.v += 18;
521 bounds.left = curstate->pos.h;
522 bounds.right = bounds.left + curstate->width;
524 lbounds.right = lbounds.left +
525 curstate->width * (100 - ctrl->editbox.percentwidth) / 100;
526 lbounds.bottom = lbounds.top + 22;
527 bounds.left = lbounds.right;
528 bounds.right = lbounds.left + curstate->width;
530 bounds.top = curstate->pos.v;
531 bounds.bottom = bounds.top + 22;
532 if (mac_gestalts.apprvers >= 0x100) {
533 if (ctrl->editbox.label == NULL)
534 mc->editbox.tblabel = NULL;
536 mc->editbox.tblabel = NewControl(window, &lbounds, NULL, TRUE,
537 0, 0, 0, kControlStaticTextProc,
539 SetControlData(mc->editbox.tblabel, kControlEntireControl,
540 kControlStaticTextTextTag,
541 strlen(ctrl->editbox.label), ctrl->editbox.label);
543 InsetRect(&bounds, 3, 3);
544 mc->editbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
545 ctrl->editbox.password ?
546 kControlEditTextPasswordProc :
547 kControlEditTextProc, (long)mc);
549 #if !TARGET_API_MAC_CARBON
551 if (ctrl->editbox.label == NULL)
552 mc->editbox.tblabel = NULL;
554 mc->editbox.tblabel = NewControl(window, &lbounds, NULL, TRUE,
555 0, 0, 0, SYS7_TEXT_PROC,
557 TESetText(ctrl->editbox.label, strlen(ctrl->editbox.label),
558 (TEHandle)(*mc->editbox.tblabel)->contrlData);
560 mc->editbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
561 SYS7_EDITBOX_PROC, (long)mc);
564 curstate->pos.v += 28;
565 add234(mcs->byctrl, mc);
566 mc->generic.next = mcs->panels[curstate->panelnum];
567 mcs->panels[curstate->panelnum] = mc;
568 ctrlevent(mcs, mc, EVENT_REFRESH);
571 #if !TARGET_API_MAC_CARBON
572 static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16 variant,
574 ControlDefProcMessage msg,
585 rect = (*control)->contrlRect;
586 if (variant == SYS7_EDITBOX_VARIANT)
587 InsetRect(&rect, 3, 3); /* 2 if it's 20 pixels high */
588 te = TENew(&rect, &rect);
589 ssfs = GetScriptVariable(smSystemScript, smScriptSysFondSize);
590 (*te)->txSize = LoWord(ssfs);
591 (*te)->txFont = HiWord(ssfs);
592 (*control)->contrlData = (Handle)te;
595 TEDispose((TEHandle)(*control)->contrlData);
598 if ((*control)->contrlVis) {
599 rect = (*control)->contrlRect;
600 if (variant == SYS7_EDITBOX_VARIANT) {
603 InsetRect(&rect, 3, 3);
605 (*(TEHandle)(*control)->contrlData)->viewRect = rect;
606 TEUpdate(&rect, (TEHandle)(*control)->contrlData);
610 if (variant == SYS7_TEXT_VARIANT)
611 return kControlNoPart;
612 mouse.h = LoWord(param);
613 mouse.v = HiWord(param);
614 rect = (*control)->contrlRect;
615 InsetRect(&rect, 3, 3);
616 return PtInRect(mouse, &rect) ? kControlEditTextPart : kControlNoPart;
618 if (param & (1 << 31)) {
624 rgn = (RgnHandle)param;
625 RectRgn(rgn, &(*control)->contrlRect);
629 rgn = (RgnHandle)param;
638 static void macctrl_radio(struct macctrls *mcs, WindowPtr window,
639 struct mac_layoutstate *curstate,
642 union macctrl *mc = snew(union macctrl);
645 unsigned int i, colwidth;
647 if (ctrl->radio.label != NULL)
648 fprintf(stderr, " label = %s\n", ctrl->radio.label);
649 mc->generic.type = MACCTRL_RADIO;
650 mc->generic.ctrl = ctrl;
651 mc->generic.privdata = NULL;
652 mc->radio.tbctrls = snewn(ctrl->radio.nbuttons, ControlRef);
653 colwidth = (curstate->width + 13) / ctrl->radio.ncolumns;
654 bounds.top = curstate->pos.v;
655 bounds.bottom = bounds.top + 16;
656 bounds.left = curstate->pos.h;
657 bounds.right = bounds.left + curstate->width;
658 if (ctrl->radio.label == NULL)
659 mc->radio.tblabel = NULL;
661 if (mac_gestalts.apprvers >= 0x100) {
662 mc->radio.tblabel = NewControl(window, &bounds, NULL, TRUE,
663 0, 0, 0, kControlStaticTextProc,
665 SetControlData(mc->radio.tblabel, kControlEntireControl,
666 kControlStaticTextTextTag,
667 strlen(ctrl->radio.label), ctrl->radio.label);
669 #if !TARGET_API_MAC_CARBON
671 mc->radio.tblabel = NewControl(window, &bounds, NULL, TRUE,
672 0, 0, 0, SYS7_TEXT_PROC, (long)mc);
673 TESetText(ctrl->radio.label, strlen(ctrl->radio.label),
674 (TEHandle)(*mc->radio.tblabel)->contrlData);
677 curstate->pos.v += 18;
679 for (i = 0; i < ctrl->radio.nbuttons; i++) {
680 fprintf(stderr, " button = %s\n", ctrl->radio.buttons[i]);
681 bounds.top = curstate->pos.v - 2;
682 bounds.bottom = bounds.top + 18;
683 bounds.left = curstate->pos.h + colwidth * (i % ctrl->radio.ncolumns);
684 if (i == ctrl->radio.nbuttons - 1 ||
685 i % ctrl->radio.ncolumns == ctrl->radio.ncolumns - 1) {
686 bounds.right = curstate->pos.h + curstate->width;
687 curstate->pos.v += 18;
689 bounds.right = bounds.left + colwidth - 13;
690 c2pstrcpy(title, ctrl->radio.buttons[i]);
691 mc->radio.tbctrls[i] = NewControl(window, &bounds, title, TRUE,
692 0, 0, 1, radioButProc, (long)mc);
694 curstate->pos.v += 4;
695 add234(mcs->byctrl, mc);
696 mc->generic.next = mcs->panels[curstate->panelnum];
697 mcs->panels[curstate->panelnum] = mc;
698 ctrlevent(mcs, mc, EVENT_REFRESH);
701 static void macctrl_checkbox(struct macctrls *mcs, WindowPtr window,
702 struct mac_layoutstate *curstate,
705 union macctrl *mc = snew(union macctrl);
709 assert(ctrl->checkbox.label != NULL);
710 fprintf(stderr, " label = %s\n", ctrl->checkbox.label);
711 mc->generic.type = MACCTRL_CHECKBOX;
712 mc->generic.ctrl = ctrl;
713 mc->generic.privdata = NULL;
714 bounds.left = curstate->pos.h;
715 bounds.right = bounds.left + curstate->width;
716 bounds.top = curstate->pos.v;
717 bounds.bottom = bounds.top + 16;
718 c2pstrcpy(title, ctrl->checkbox.label);
719 mc->checkbox.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1,
720 checkBoxProc, (long)mc);
721 add234(mcs->byctrl, mc);
722 curstate->pos.v += 22;
723 mc->generic.next = mcs->panels[curstate->panelnum];
724 mcs->panels[curstate->panelnum] = mc;
725 ctrlevent(mcs, mc, EVENT_REFRESH);
728 static void macctrl_button(struct macctrls *mcs, WindowPtr window,
729 struct mac_layoutstate *curstate,
732 union macctrl *mc = snew(union macctrl);
736 assert(ctrl->button.label != NULL);
737 fprintf(stderr, " label = %s\n", ctrl->button.label);
738 if (ctrl->button.isdefault)
739 fprintf(stderr, " is default\n");
740 mc->generic.type = MACCTRL_BUTTON;
741 mc->generic.ctrl = ctrl;
742 mc->generic.privdata = NULL;
743 bounds.left = curstate->pos.h;
744 bounds.right = bounds.left + curstate->width;
745 bounds.top = curstate->pos.v;
746 bounds.bottom = bounds.top + 20;
747 c2pstrcpy(title, ctrl->button.label);
748 mc->button.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1,
749 pushButProc, (long)mc);
750 mc->button.tbring = NULL;
751 if (mac_gestalts.apprvers >= 0x100) {
752 Boolean isdefault = ctrl->button.isdefault;
754 SetControlData(mc->button.tbctrl, kControlEntireControl,
755 kControlPushButtonDefaultTag,
756 sizeof(isdefault), &isdefault);
757 } else if (ctrl->button.isdefault) {
758 InsetRect(&bounds, -4, -4);
759 mc->button.tbring = NewControl(window, &bounds, title, TRUE, 0, 0, 1,
760 SYS7_DEFAULT_PROC, (long)mc);
762 if (mac_gestalts.apprvers >= 0x110) {
763 Boolean iscancel = ctrl->button.iscancel;
765 SetControlData(mc->button.tbctrl, kControlEntireControl,
766 kControlPushButtonCancelTag,
767 sizeof(iscancel), &iscancel);
769 if (ctrl->button.isdefault)
771 if (ctrl->button.iscancel)
773 add234(mcs->byctrl, mc);
774 mc->generic.next = mcs->panels[curstate->panelnum];
775 mcs->panels[curstate->panelnum] = mc;
776 curstate->pos.v += 26;
779 #if !TARGET_API_MAC_CARBON
780 static pascal SInt32 macctrl_sys7_default_cdef(SInt16 variant,
782 ControlDefProcMessage msg,
792 if ((*control)->contrlVis) {
793 rect = (*control)->contrlRect;
794 GetPenState(&savestate);
797 if ((*control)->contrlHilite == kControlInactivePart)
799 oval = (rect.bottom - rect.top) / 2 + 2;
800 FrameRoundRect(&rect, oval, oval);
801 SetPenState(&savestate);
805 if (param & (1 << 31)) {
811 rgn = (RgnHandle)param;
812 RectRgn(rgn, &(*control)->contrlRect);
816 rgn = (RgnHandle)param;
825 static void macctrl_listbox(struct macctrls *mcs, WindowPtr window,
826 struct mac_layoutstate *curstate,
829 union macctrl *mc = snew(union macctrl);
834 if (mac_gestalts.apprvers < 0x100)
836 if (ctrl->listbox.label != NULL)
837 fprintf(stderr, " label = %s\n", ctrl->listbox.label);
838 fprintf(stderr, " height = %d\n", ctrl->listbox.height);
839 if (ctrl->listbox.draglist)
840 fprintf(stderr, " draglist\n");
841 if (ctrl->listbox.multisel)
842 fprintf(stderr, " multisel\n");
843 fprintf(stderr, " ncols = %d\n", ctrl->listbox.ncols);
844 assert(ctrl->listbox.percentwidth == 100);
845 mc->generic.type = MACCTRL_LISTBOX;
846 mc->generic.ctrl = ctrl;
847 mc->generic.privdata = NULL;
848 /* The list starts off empty */
849 mc->listbox.nids = 0;
850 mc->listbox.ids = NULL;
851 bounds.left = curstate->pos.h;
852 bounds.right = bounds.left + curstate->width;
853 bounds.top = curstate->pos.v;
854 bounds.bottom = bounds.top + 20 * ctrl->listbox.height;
856 mc->button.tbctrl = NewControl(window, &bounds, NULL, TRUE,
858 kControlListBoxProc, (long)mc);
859 if (!ctrl->listbox.multisel) {
860 if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
861 kControlListBoxListHandleTag, sizeof(list), &list,
864 #if TARGET_API_MAC_CARBON
865 SetListSelectionFlags(list, lOnlyOne);
867 (*list)->selFlags = lOnlyOne;
870 add234(mcs->byctrl, mc);
871 curstate->pos.v += 6 + 20 * ctrl->listbox.height;
872 mc->generic.next = mcs->panels[curstate->panelnum];
873 mcs->panels[curstate->panelnum] = mc;
874 ctrlevent(mcs, mc, EVENT_REFRESH);
878 static void macctrl_popup(struct macctrls *mcs, WindowPtr window,
879 struct mac_layoutstate *curstate,
882 union macctrl *mc = snew(union macctrl);
885 unsigned int labelwidth;
886 static int nextmenuid = MENU_MIN;
891 * <http://developer.apple.com/qa/tb/tb42.html> explains how to
892 * create a popup menu with dynamic content.
894 assert(ctrl->listbox.height == 0);
895 assert(!ctrl->listbox.draglist);
896 assert(!ctrl->listbox.multisel);
898 if (ctrl->listbox.label != NULL)
899 fprintf(stderr, " label = %s\n", ctrl->listbox.label);
900 fprintf(stderr, " percentwidth = %d\n", ctrl->listbox.percentwidth);
902 mc->generic.type = MACCTRL_POPUP;
903 mc->generic.ctrl = ctrl;
904 mc->generic.privdata = NULL;
905 c2pstrcpy(title, ctrl->button.label == NULL ? "" : ctrl->button.label);
907 /* Find a spare menu ID and create the menu */
908 while (GetMenuHandle(nextmenuid) != NULL)
909 if (++nextmenuid >= MENU_MAX) nextmenuid = MENU_MIN;
910 menuid = nextmenuid++;
911 menu = NewMenu(menuid, "\pdummy");
912 if (menu == NULL) return;
913 mc->popup.menu = menu;
914 mc->popup.menuid = menuid;
915 InsertMenu(menu, kInsertHierarchicalMenu);
917 /* The menu starts off empty */
919 mc->popup.ids = NULL;
921 bounds.left = curstate->pos.h;
922 bounds.right = bounds.left + curstate->width;
923 bounds.top = curstate->pos.v;
924 bounds.bottom = bounds.top + 20;
925 /* XXX handle percentwidth == 100 */
926 labelwidth = curstate->width * (100 - ctrl->listbox.percentwidth) / 100;
927 mc->popup.tbctrl = NewControl(window, &bounds, title, TRUE,
928 popupTitleLeftJust, menuid, labelwidth,
929 popupMenuProc + popupFixedWidth, (long)mc);
930 add234(mcs->byctrl, mc);
931 curstate->pos.v += 26;
932 mc->generic.next = mcs->panels[curstate->panelnum];
933 mcs->panels[curstate->panelnum] = mc;
934 ctrlevent(mcs, mc, EVENT_REFRESH);
938 void macctrl_activate(WindowPtr window, EventRecord *event)
940 struct macctrls *mcs = mac_winctrls(window);
941 Boolean active = (event->modifiers & activeFlag) != 0;
944 ControlPartCode state;
948 SetPort((GrafPtr)GetWindowPort(window));
949 if (mac_gestalts.apprvers >= 0x100)
950 SetThemeWindowBackground(window, active ?
951 kThemeBrushModelessDialogBackgroundActive :
952 kThemeBrushModelessDialogBackgroundInactive,
954 state = active ? kControlNoPart : kControlInactivePart;
955 for (i = 0; i <= mcs->curpanel; i += mcs->curpanel)
956 for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) {
957 switch (mc->generic.type) {
959 HiliteControl(mc->text.tbctrl, state);
961 case MACCTRL_EDITBOX:
962 HiliteControl(mc->editbox.tbctrl, state);
963 if (mc->editbox.tblabel != NULL)
964 HiliteControl(mc->editbox.tblabel, state);
967 for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
968 HiliteControl(mc->radio.tbctrls[j], state);
969 if (mc->radio.tblabel != NULL)
970 HiliteControl(mc->radio.tblabel, state);
972 case MACCTRL_CHECKBOX:
973 HiliteControl(mc->checkbox.tbctrl, state);
976 HiliteControl(mc->button.tbctrl, state);
977 if (mc->button.tbring != NULL)
978 HiliteControl(mc->button.tbring, state);
980 case MACCTRL_LISTBOX:
981 HiliteControl(mc->listbox.tbctrl, state);
984 HiliteControl(mc->popup.tbctrl, state);
987 #if !TARGET_API_MAC_CARBON
988 if (mcs->focus == mc) {
999 void macctrl_click(WindowPtr window, EventRecord *event)
1002 ControlHandle control;
1003 int part, trackresult;
1006 struct macctrls *mcs = mac_winctrls(window);
1011 SetPort((GrafPtr)GetWindowPort(window));
1012 mouse = event->where;
1013 GlobalToLocal(&mouse);
1014 part = FindControl(mouse, window, &control);
1015 if (control != NULL) {
1016 mc = (union macctrl *)GetControlReference(control);
1017 if (mac_gestalts.apprvers >= 0x100) {
1018 if (GetControlFeatures(control, &features) == noErr &&
1019 (features & kControlSupportsFocus) &&
1020 (features & kControlGetsFocusOnClick))
1021 SetKeyboardFocus(window, control, part);
1022 trackresult = HandleControlClick(control, mouse, event->modifiers,
1023 (ControlActionUPP)-1);
1025 #if !TARGET_API_MAC_CARBON
1026 if (mc->generic.type == MACCTRL_EDITBOX &&
1027 control == mc->editbox.tbctrl) {
1028 TEHandle te = (TEHandle)(*control)->contrlData;
1030 macctrl_setfocus(mcs, mc);
1031 TEClick(mouse, !!(event->modifiers & shiftKey), te);
1035 trackresult = TrackControl(control, mouse, (ControlActionUPP)-1);
1037 switch (mc->generic.type) {
1039 if (trackresult != 0) {
1040 for (i = 0; i < mc->generic.ctrl->radio.nbuttons; i++)
1041 if (mc->radio.tbctrls[i] == control)
1042 SetControlValue(mc->radio.tbctrls[i],
1043 kControlRadioButtonCheckedValue);
1045 SetControlValue(mc->radio.tbctrls[i],
1046 kControlRadioButtonUncheckedValue);
1047 ctrlevent(mcs, mc, EVENT_VALCHANGE);
1050 case MACCTRL_CHECKBOX:
1051 if (trackresult != 0) {
1052 SetControlValue(control, !GetControlValue(control));
1053 ctrlevent(mcs, mc, EVENT_VALCHANGE);
1056 case MACCTRL_BUTTON:
1057 if (trackresult != 0)
1058 ctrlevent(mcs, mc, EVENT_ACTION);
1060 case MACCTRL_LISTBOX:
1061 /* FIXME spot double-click */
1062 ctrlevent(mcs, mc, EVENT_SELCHANGE);
1065 ctrlevent(mcs, mc, EVENT_SELCHANGE);
1073 void macctrl_key(WindowPtr window, EventRecord *event)
1076 struct macctrls *mcs = mac_winctrls(window);
1078 unsigned long dummy;
1080 switch (event->message & charCodeMask) {
1081 case kEnterCharCode:
1082 case kReturnCharCode:
1083 if (mcs->defbutton != NULL) {
1084 assert(mcs->defbutton->generic.type == MACCTRL_BUTTON);
1085 HiliteControl(mcs->defbutton->button.tbctrl, kControlButtonPart);
1087 * I'd like to delay unhilighting the button until after
1088 * the event has been processed, but by them the entire
1089 * dialgue box might have been destroyed.
1092 HiliteControl(mcs->defbutton->button.tbctrl, kControlNoPart);
1093 ctrlevent(mcs, mcs->defbutton, EVENT_ACTION);
1096 case kEscapeCharCode:
1097 if (mcs->canbutton != NULL) {
1098 assert(mcs->canbutton->generic.type == MACCTRL_BUTTON);
1099 HiliteControl(mcs->canbutton->button.tbctrl, kControlButtonPart);
1101 HiliteControl(mcs->defbutton->button.tbctrl, kControlNoPart);
1102 ctrlevent(mcs, mcs->canbutton, EVENT_ACTION);
1106 if (mac_gestalts.apprvers >= 0x100) {
1107 if (GetKeyboardFocus(window, &control) == noErr && control != NULL) {
1108 HandleControlKey(control, (event->message & keyCodeMask) >> 8,
1109 event->message & charCodeMask, event->modifiers);
1110 mc = (union macctrl *)GetControlReference(control);
1111 ctrlevent(mcs, mc, EVENT_VALCHANGE);
1114 #if !TARGET_API_MAC_CARBON
1118 if (mcs->focus != NULL) {
1120 switch (mc->generic.type) {
1121 case MACCTRL_EDITBOX:
1122 te = (TEHandle)(*mc->editbox.tbctrl)->contrlData;
1123 TEKey(event->message & charCodeMask, te);
1124 ctrlevent(mcs, mc, EVENT_VALCHANGE);
1132 void macctrl_update(WindowPtr window)
1134 #if TARGET_API_MAC_CARBON
1140 BeginUpdate(window);
1142 SetPort((GrafPtr)GetWindowPort(window));
1143 if (mac_gestalts.apprvers >= 0x101) {
1144 #if TARGET_API_MAC_CARBON
1145 GetPortBounds(GetWindowPort(window), &rect);
1147 rect = window->portRect;
1149 InsetRect(&rect, -1, -1);
1150 DrawThemeModelessDialogFrame(&rect, mac_frontwindow() == window ?
1151 kThemeStateActive : kThemeStateInactive);
1153 #if TARGET_API_MAC_CARBON
1155 GetPortVisibleRegion(GetWindowPort(window), visrgn);
1156 UpdateControls(window, visrgn);
1159 UpdateControls(window, window->visRgn);
1165 #if TARGET_API_MAC_CARBON
1166 #define EnableItem EnableMenuItem
1167 #define DisableItem DisableMenuItem
1169 void macctrl_adjustmenus(WindowPtr window)
1173 menu = GetMenuHandle(mFile);
1174 DisableItem(menu, iSave); /* XXX enable if modified */
1175 EnableItem(menu, iSaveAs);
1176 EnableItem(menu, iDuplicate);
1178 menu = GetMenuHandle(mEdit);
1179 DisableItem(menu, 0);
1182 void macctrl_close(WindowPtr window)
1184 struct macctrls *mcs = mac_winctrls(window);
1188 * Mostly, we don't bother disposing of the Toolbox controls,
1189 * since that will happen automatically when the window is
1190 * disposed of. Popup menus are an exception, because we have to
1191 * dispose of the menu ourselves, and doing that while the control
1192 * still holds a reference to it seems rude.
1194 while ((mc = index234(mcs->byctrl, 0)) != NULL) {
1195 if (mc->generic.privdata != NULL && mc->generic.freeprivdata)
1196 sfree(mc->generic.privdata);
1197 switch (mc->generic.type) {
1199 DisposeControl(mc->popup.tbctrl);
1200 DeleteMenu(mc->popup.menuid);
1201 DisposeMenu(mc->popup.menu);
1204 del234(mcs->byctrl, mc);
1208 freetree234(mcs->byctrl);
1214 void dlg_update_start(union control *ctrl, void *dlg)
1220 void dlg_update_done(union control *ctrl, void *dlg)
1226 void dlg_set_focus(union control *ctrl, void *dlg)
1229 if (mac_gestalts.apprvers >= 0x100) {
1230 /* Use SetKeyboardFocus() */
1232 /* Do our own mucking around */
1236 union control *dlg_last_focused(union control *ctrl, void *dlg)
1242 void dlg_beep(void *dlg)
1248 void dlg_error_msg(void *dlg, char *msg)
1252 c2pstrcpy(pmsg, msg);
1253 ParamText(pmsg, NULL, NULL, NULL);
1254 StopAlert(128, NULL);
1257 void dlg_end(void *dlg, int value)
1259 struct macctrls *mcs = dlg;
1261 if (mcs->end != NULL)
1262 (*mcs->end)(mcs->window, value);
1265 void dlg_refresh(union control *ctrl, void *dlg)
1267 struct macctrls *mcs = dlg;
1272 mc = findbyctrl(mcs, ctrl);
1274 ctrlevent(mcs, mc, EVENT_REFRESH);
1277 void *dlg_get_privdata(union control *ctrl, void *dlg)
1279 struct macctrls *mcs = dlg;
1280 union macctrl *mc = findbyctrl(mcs, ctrl);
1283 return mc->generic.privdata;
1286 void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr)
1288 struct macctrls *mcs = dlg;
1289 union macctrl *mc = findbyctrl(mcs, ctrl);
1292 mc->generic.privdata = ptr;
1293 mc->generic.freeprivdata = FALSE;
1296 void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size)
1298 struct macctrls *mcs = dlg;
1299 union macctrl *mc = findbyctrl(mcs, ctrl);
1302 mc->generic.privdata = smalloc(size);
1303 mc->generic.freeprivdata = TRUE;
1304 return mc->generic.privdata;
1309 * Radio Button control
1312 void dlg_radiobutton_set(union control *ctrl, void *dlg, int whichbutton)
1314 struct macctrls *mcs = dlg;
1315 union macctrl *mc = findbyctrl(mcs, ctrl);
1318 if (mc == NULL) return;
1319 for (i = 0; i < ctrl->radio.nbuttons; i++) {
1320 if (i == whichbutton)
1321 SetControlValue(mc->radio.tbctrls[i],
1322 kControlRadioButtonCheckedValue);
1324 SetControlValue(mc->radio.tbctrls[i],
1325 kControlRadioButtonUncheckedValue);
1330 int dlg_radiobutton_get(union control *ctrl, void *dlg)
1332 struct macctrls *mcs = dlg;
1333 union macctrl *mc = findbyctrl(mcs, ctrl);
1337 for (i = 0; i < ctrl->radio.nbuttons; i++) {
1338 if (GetControlValue(mc->radio.tbctrls[i]) ==
1339 kControlRadioButtonCheckedValue)
1350 void dlg_checkbox_set(union control *ctrl, void *dlg, int checked)
1352 struct macctrls *mcs = dlg;
1353 union macctrl *mc = findbyctrl(mcs, ctrl);
1355 if (mc == NULL) return;
1356 SetControlValue(mc->checkbox.tbctrl,
1357 checked ? kControlCheckBoxCheckedValue :
1358 kControlCheckBoxUncheckedValue);
1361 int dlg_checkbox_get(union control *ctrl, void *dlg)
1363 struct macctrls *mcs = dlg;
1364 union macctrl *mc = findbyctrl(mcs, ctrl);
1367 return GetControlValue(mc->checkbox.tbctrl);
1375 void dlg_editbox_set(union control *ctrl, void *dlg, char const *text)
1377 struct macctrls *mcs = dlg;
1378 union macctrl *mc = findbyctrl(mcs, ctrl);
1381 if (mc == NULL) return;
1382 assert(mc->generic.type == MACCTRL_EDITBOX);
1384 SetPort((GrafPtr)(GetWindowPort(mcs->window)));
1385 if (mac_gestalts.apprvers >= 0x100)
1386 SetControlData(mc->editbox.tbctrl, kControlEntireControl,
1387 ctrl->editbox.password ?
1388 kControlEditTextPasswordTag :
1389 kControlEditTextTextTag,
1390 strlen(text), text);
1391 #if !TARGET_API_MAC_CARBON
1393 TESetText(text, strlen(text),
1394 (TEHandle)(*mc->editbox.tbctrl)->contrlData);
1396 DrawOneControl(mc->editbox.tbctrl);
1400 void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length)
1402 struct macctrls *mcs = dlg;
1403 union macctrl *mc = findbyctrl(mcs, ctrl);
1407 assert(mc->generic.type == MACCTRL_EDITBOX);
1408 if (mac_gestalts.apprvers >= 0x100) {
1409 if (GetControlData(mc->editbox.tbctrl, kControlEntireControl,
1410 ctrl->editbox.password ?
1411 kControlEditTextPasswordTag :
1412 kControlEditTextTextTag,
1413 length - 1, buffer, &olen) != noErr)
1415 if (olen > length - 1)
1418 #if !TARGET_API_MAC_CARBON
1420 TEHandle te = (TEHandle)(*mc->editbox.tbctrl)->contrlData;
1422 olen = (*te)->teLength;
1423 if (olen > length - 1)
1425 memcpy(buffer, *(*te)->hText, olen);
1428 buffer[olen] = '\0';
1429 fprintf(stderr, "dlg_editbox_get: %s\n", buffer);
1437 static void dlg_macpopup_clear(union control *ctrl, void *dlg)
1439 struct macctrls *mcs = dlg;
1440 union macctrl *mc = findbyctrl(mcs, ctrl);
1441 MenuRef menu = mc->popup.menu;
1444 if (mc == NULL) return;
1445 fprintf(stderr, " popup_clear\n");
1446 n = CountMenuItems(menu);
1447 for (i = 0; i < n; i++)
1448 DeleteMenuItem(menu, n - i);
1450 sfree(mc->popup.ids);
1451 mc->popup.ids = NULL;
1452 SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
1455 static void dlg_maclist_clear(union control *ctrl, void *dlg)
1457 struct macctrls *mcs = dlg;
1458 union macctrl *mc = findbyctrl(mcs, ctrl);
1462 if (mc == NULL) return;
1463 fprintf(stderr, " maclist_clear\n");
1464 if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
1465 kControlListBoxListHandleTag, sizeof(list), &list,
1468 LDelRow(0, 0, list);
1469 mc->listbox.nids = 0;
1470 sfree(mc->listbox.ids);
1471 mc->listbox.ids = NULL;
1472 DrawOneControl(mc->listbox.tbctrl);
1475 void dlg_listbox_clear(union control *ctrl, void *dlg)
1478 if (ctrl->listbox.height == 0)
1479 dlg_macpopup_clear(ctrl, dlg);
1481 dlg_maclist_clear(ctrl, dlg);
1484 static void dlg_macpopup_del(union control *ctrl, void *dlg, int index)
1486 struct macctrls *mcs = dlg;
1487 union macctrl *mc = findbyctrl(mcs, ctrl);
1488 MenuRef menu = mc->popup.menu;
1490 if (mc == NULL) return;
1491 fprintf(stderr, " popup_del %d\n", index);
1492 DeleteMenuItem(menu, index + 1);
1493 if (mc->popup.ids != NULL)
1494 memcpy(mc->popup.ids + index, mc->popup.ids + index + 1,
1495 (mc->popup.nids - index - 1) * sizeof(*mc->popup.ids));
1496 SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
1499 static void dlg_maclist_del(union control *ctrl, void *dlg, int index)
1501 struct macctrls *mcs = dlg;
1502 union macctrl *mc = findbyctrl(mcs, ctrl);
1506 if (mc == NULL) return;
1507 fprintf(stderr, " maclist_del %d\n", index);
1508 if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
1509 kControlListBoxListHandleTag, sizeof(list), &list,
1512 LDelRow(1, index, list);
1513 if (mc->listbox.ids != NULL)
1514 memcpy(mc->listbox.ids + index, mc->listbox.ids + index + 1,
1515 (mc->listbox.nids - index - 1) * sizeof(*mc->listbox.ids));
1516 DrawOneControl(mc->listbox.tbctrl);
1519 void dlg_listbox_del(union control *ctrl, void *dlg, int index)
1522 if (ctrl->listbox.height == 0)
1523 dlg_macpopup_del(ctrl, dlg, index);
1525 dlg_maclist_del(ctrl, dlg, index);
1528 static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text)
1530 struct macctrls *mcs = dlg;
1531 union macctrl *mc = findbyctrl(mcs, ctrl);
1532 MenuRef menu = mc->popup.menu;
1535 if (mc == NULL) return;
1536 fprintf(stderr, " popup_add %s\n", text);
1537 assert(text[0] != '\0');
1538 c2pstrcpy(itemstring, text);
1539 AppendMenu(menu, "\pdummy");
1540 SetMenuItemText(menu, CountMenuItems(menu), itemstring);
1541 SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
1545 static void dlg_maclist_add(union control *ctrl, void *dlg, char const *text)
1547 struct macctrls *mcs = dlg;
1548 union macctrl *mc = findbyctrl(mcs, ctrl);
1552 Cell cell = { 0, 0 };
1554 if (mc == NULL) return;
1555 fprintf(stderr, " maclist_add %s\n", text);
1556 if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
1557 kControlListBoxListHandleTag, sizeof(list), &list,
1560 #if TARGET_API_MAC_CARBON
1561 GetListDataBounds(list, &bounds);
1563 bounds = (*list)->dataBounds;
1565 cell.v = bounds.bottom;
1566 LAddRow(1, cell.v, list);
1567 LSetCell(text, strlen(text), cell, list);
1568 DrawOneControl(mc->listbox.tbctrl);
1571 void dlg_listbox_add(union control *ctrl, void *dlg, char const *text)
1574 if (ctrl->listbox.height == 0)
1575 dlg_macpopup_add(ctrl, dlg, text);
1577 dlg_maclist_add(ctrl, dlg, text);
1580 static void dlg_macpopup_addwithid(union control *ctrl, void *dlg,
1581 char const *text, int id)
1583 struct macctrls *mcs = dlg;
1584 union macctrl *mc = findbyctrl(mcs, ctrl);
1585 MenuRef menu = mc->popup.menu;
1588 if (mc == NULL) return;
1589 fprintf(stderr, " popup_addwthid %s, %d\n", text, id);
1590 dlg_macpopup_add(ctrl, dlg, text);
1591 index = CountMenuItems(menu) - 1;
1592 if (mc->popup.nids <= index) {
1593 mc->popup.nids = index + 1;
1594 mc->popup.ids = sresize(mc->popup.ids, mc->popup.nids, int);
1596 mc->popup.ids[index] = id;
1599 static void dlg_maclist_addwithid(union control *ctrl, void *dlg,
1600 char const *text, int id)
1602 struct macctrls *mcs = dlg;
1603 union macctrl *mc = findbyctrl(mcs, ctrl);
1609 if (mc == NULL) return;
1610 fprintf(stderr, " maclist_addwithid %s %d\n", text, id);
1611 dlg_maclist_add(ctrl, dlg, text);
1612 if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
1613 kControlListBoxListHandleTag, sizeof(list), &list,
1616 #if TARGET_API_MAC_CARBON
1617 GetListDataBounds(list, &bounds);
1619 bounds = (*list)->dataBounds;
1621 index = bounds.bottom;
1622 if (mc->listbox.nids <= index) {
1623 mc->listbox.nids = index + 1;
1624 mc->listbox.ids = sresize(mc->listbox.ids, mc->listbox.nids, int);
1626 mc->listbox.ids[index] = id;
1629 void dlg_listbox_addwithid(union control *ctrl, void *dlg,
1630 char const *text, int id)
1633 if (ctrl->listbox.height == 0)
1634 dlg_macpopup_addwithid(ctrl, dlg, text, id);
1636 dlg_maclist_addwithid(ctrl, dlg, text, id);
1639 int dlg_listbox_getid(union control *ctrl, void *dlg, int index)
1641 struct macctrls *mcs = dlg;
1642 union macctrl *mc = findbyctrl(mcs, ctrl);
1645 if (ctrl->listbox.height == 0) {
1646 assert(mc->popup.ids != NULL && mc->popup.nids > index);
1647 return mc->popup.ids[index];
1652 static int dlg_maclist_index(union control *ctrl, void *dlg)
1654 struct macctrls *mcs = dlg;
1655 union macctrl *mc = findbyctrl(mcs, ctrl);
1658 Cell cell = { 0, 0 };
1660 if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
1661 kControlListBoxListHandleTag, sizeof(list), &list,
1664 if (LGetSelect(TRUE, &cell, list))
1670 int dlg_listbox_index(union control *ctrl, void *dlg)
1672 struct macctrls *mcs = dlg;
1675 if (ctrl->listbox.height == 0) {
1676 mc = findbyctrl(mcs, ctrl);
1678 return GetControlValue(mc->popup.tbctrl) - 1;
1680 return dlg_maclist_index(ctrl, dlg);
1683 static int dlg_maclist_issel(union control *ctrl, void *dlg, int index)
1685 struct macctrls *mcs = dlg;
1686 union macctrl *mc = findbyctrl(mcs, ctrl);
1689 Cell cell = { 0, 0 };
1691 if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
1692 kControlListBoxListHandleTag, sizeof(list), &list,
1696 return LGetSelect(FALSE, &cell, list);
1699 int dlg_listbox_issel(union control *ctrl, void *dlg, int index)
1701 struct macctrls *mcs = dlg;
1702 union macctrl *mc = findbyctrl(mcs, ctrl);
1704 if (ctrl->listbox.height == 0)
1705 return GetControlValue(mc->popup.tbctrl) - 1 == index;
1707 return dlg_maclist_issel(ctrl, dlg, index);
1710 void dlg_listbox_select(union control *ctrl, void *dlg, int index)
1712 struct macctrls *mcs = dlg;
1713 union macctrl *mc = findbyctrl(mcs, ctrl);
1715 if (mc == NULL) return;
1716 if (ctrl->listbox.height == 0)
1717 SetControlValue(mc->popup.tbctrl, index + 1);
1725 void dlg_text_set(union control *ctrl, void *dlg, char const *text)
1727 struct macctrls *mcs = dlg;
1728 union macctrl *mc = findbyctrl(mcs, ctrl);
1730 if (mc == NULL) return;
1731 if (mac_gestalts.apprvers >= 0x100)
1732 SetControlData(mc->text.tbctrl, kControlEntireControl,
1733 kControlStaticTextTextTag, strlen(text), text);
1734 #if !TARGET_API_MAC_CARBON
1736 TESetText(text, strlen(text),
1737 (TEHandle)(*mc->text.tbctrl)->contrlData);
1743 * File Selector control
1746 void dlg_filesel_set(union control *ctrl, void *dlg, Filename fn)
1751 void dlg_filesel_get(union control *ctrl, void *dlg, Filename *fn)
1758 * Font Selector control
1761 void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec fn)
1766 void dlg_fontsel_get(union control *ctrl, void *dlg, FontSpec *fn)
1773 * Printer enumeration
1776 printer_enum *printer_start_enum(int *nprinters)
1783 char *printer_get_name(printer_enum *pe, int thing)
1789 void printer_finish_enum(printer_enum *pe)
1796 * Colour selection stuff
1799 void dlg_coloursel_start(union control *ctrl, void *dlg,
1800 int r, int g, int b)
1805 int dlg_coloursel_results(union control *ctrl, void *dlg,
1806 int *r, int *g, int *b)
1814 * c-file-style: "simon"