1 /* $Id: macctrls.c,v 1.9 2003/03/23 14:11:39 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>
33 #include <Resources.h>
35 #include <TextUtils.h>
47 /* Range of menu IDs for popup menus */
53 struct macctrl_generic
{
61 /* Template from which this was generated */
63 /* Next control in this panel */
67 struct macctrl_generic generic
;
71 struct macctrl_generic generic
;
75 struct macctrl_generic generic
;
79 struct macctrl_generic generic
;
83 struct macctrl_generic generic
;
92 struct mac_layoutstate
{
95 unsigned int panelnum
;
98 #define ctrlevent(mcs, mc, event) do { \
99 if ((mc)->generic.ctrl->generic.handler != NULL) \
100 (*(mc)->generic.ctrl->generic.handler)((mc)->generic.ctrl, (mcs),\
101 (mcs)->data, (event)); \
104 #define findbyctrl(mcs, ctrl) \
105 find234((mcs)->byctrl, (ctrl), macctrl_cmp_byctrl_find)
107 static void macctrl_layoutset(struct mac_layoutstate
*, struct controlset
*,
108 WindowPtr
, struct macctrls
*);
109 static void macctrl_switchtopanel(struct macctrls
*, unsigned int);
110 static void macctrl_text(struct macctrls
*, WindowPtr
,
111 struct mac_layoutstate
*, union control
*);
112 static void macctrl_radio(struct macctrls
*, WindowPtr
,
113 struct mac_layoutstate
*, union control
*);
114 static void macctrl_checkbox(struct macctrls
*, WindowPtr
,
115 struct mac_layoutstate
*, union control
*);
116 static void macctrl_button(struct macctrls
*, WindowPtr
,
117 struct mac_layoutstate
*, union control
*);
118 static void macctrl_popup(struct macctrls
*, WindowPtr
,
119 struct mac_layoutstate
*, union control
*);
120 #if !TARGET_API_MAC_CARBON
121 static pascal SInt32
macctrl_sys7_text_cdef(SInt16
, ControlRef
,
122 ControlDefProcMessage
, SInt32
);
123 static pascal SInt32
macctrl_sys7_default_cdef(SInt16
, ControlRef
,
124 ControlDefProcMessage
, SInt32
);
127 #if !TARGET_API_MAC_CARBON
129 * This trick enables us to keep all the CDEF code in the main
130 * application, which makes life easier. For details, see
131 * <http://developer.apple.com/technotes/tn/tn2003.html#custom_code_base>.
134 #pragma options align=mac68k
136 short jmpabs
; /* 4EF9 */
137 ControlDefUPP theUPP
;
139 #pragma options align=reset
142 static void macctrl_init()
144 #if !TARGET_API_MAC_CARBON
145 static int inited
= 0;
149 cdef
= (PatchCDEF
)GetResource(kControlDefProcResourceType
, CDEF_Text
);
150 (*cdef
)->theUPP
= NewControlDefProc(macctrl_sys7_text_cdef
);
151 cdef
= (PatchCDEF
)GetResource(kControlDefProcResourceType
, CDEF_Default
);
152 (*cdef
)->theUPP
= NewControlDefProc(macctrl_sys7_default_cdef
);
158 static int macctrl_cmp_byctrl(void *av
, void *bv
)
160 union macctrl
*a
= (union macctrl
*)av
;
161 union macctrl
*b
= (union macctrl
*)bv
;
163 if (a
->generic
.ctrl
< b
->generic
.ctrl
)
165 else if (a
->generic
.ctrl
> b
->generic
.ctrl
)
171 static int macctrl_cmp_byctrl_find(void *av
, void *bv
)
173 union control
*a
= (union control
*)av
;
174 union macctrl
*b
= (union macctrl
*)bv
;
176 if (a
< b
->generic
.ctrl
)
178 else if (a
> b
->generic
.ctrl
)
184 void macctrl_layoutbox(struct controlbox
*cb
, WindowPtr window
,
185 struct macctrls
*mcs
)
188 struct mac_layoutstate curstate
;
193 #if TARGET_API_MAC_CARBON
194 GetPortBounds(GetWindowPort(window
), &rect
);
196 rect
= window
->portRect
;
198 curstate
.pos
.h
= rect
.left
+ 13;
199 curstate
.pos
.v
= rect
.bottom
- 59;
200 curstate
.width
= rect
.right
- rect
.left
- (13 * 2);
201 if (mac_gestalts
.apprvers
>= 0x100)
202 CreateRootControl(window
, &root
);
203 mcs
->byctrl
= newtree234(macctrl_cmp_byctrl
);
204 /* Count the number of panels */
206 for (i
= 1; i
< cb
->nctrlsets
; i
++)
207 if (strcmp(cb
->ctrlsets
[i
]->pathname
, cb
->ctrlsets
[i
-1]->pathname
))
209 mcs
->panels
= smalloc(sizeof(*mcs
->panels
) * mcs
->npanels
);
210 memset(mcs
->panels
, 0, sizeof(*mcs
->panels
) * mcs
->npanels
);
211 curstate
.panelnum
= 0;
212 for (i
= 0; i
< cb
->nctrlsets
; i
++) {
213 if (i
> 0 && strcmp(cb
->ctrlsets
[i
]->pathname
,
214 cb
->ctrlsets
[i
-1]->pathname
)) {
215 curstate
.pos
.v
= rect
.top
+ 13;
217 assert(curstate
.panelnum
< mcs
->npanels
);
219 macctrl_layoutset(&curstate
, cb
->ctrlsets
[i
], window
, mcs
);
221 macctrl_switchtopanel(mcs
, 20);
224 static void macctrl_layoutset(struct mac_layoutstate
*curstate
,
225 struct controlset
*s
,
226 WindowPtr window
, struct macctrls
*mcs
)
230 fprintf(stderr
, "--- begin set ---\n");
231 fprintf(stderr
, "pathname = %s\n", s
->pathname
);
232 if (s
->boxname
&& *s
->boxname
)
233 fprintf(stderr
, "boxname = %s\n", s
->boxname
);
235 fprintf(stderr
, "boxtitle = %s\n", s
->boxtitle
);
238 for (i
= 0; i
< s
->ncontrols
; i
++) {
239 union control
*ctrl
= s
->ctrls
[i
];
242 switch (ctrl
->generic
.type
) {
243 case CTRL_TEXT
: s
= "text"; break;
244 case CTRL_EDITBOX
: s
= "editbox"; break;
245 case CTRL_RADIO
: s
= "radio"; break;
246 case CTRL_CHECKBOX
: s
= "checkbox"; break;
247 case CTRL_BUTTON
: s
= "button"; break;
248 case CTRL_LISTBOX
: s
= "listbox"; break;
249 case CTRL_COLUMNS
: s
= "columns"; break;
250 case CTRL_FILESELECT
: s
= "fileselect"; break;
251 case CTRL_FONTSELECT
: s
= "fontselect"; break;
252 case CTRL_TABDELAY
: s
= "tabdelay"; break;
253 default: s
= "unknown"; break;
255 fprintf(stderr
, " control: %s\n", s
);
256 switch (ctrl
->generic
.type
) {
258 macctrl_text(mcs
, window
, curstate
, ctrl
);
261 macctrl_radio(mcs
, window
, curstate
, ctrl
);
264 macctrl_checkbox(mcs
, window
, curstate
, ctrl
);
267 macctrl_button(mcs
, window
, curstate
, ctrl
);
270 if (ctrl
->listbox
.height
== 0)
271 macctrl_popup(mcs
, window
, curstate
, ctrl
);
277 static void macctrl_switchtopanel(struct macctrls
*mcs
, unsigned int which
)
282 /* Panel 0 is special and always visible. */
283 for (i
= 1; i
< mcs
->npanels
; i
++)
284 for (mc
= mcs
->panels
[i
]; mc
!= NULL
; mc
= mc
->generic
.next
)
285 switch (mc
->generic
.type
) {
288 ShowControl(mc
->text
.tbctrl
);
290 HideControl(mc
->text
.tbctrl
);
293 for (j
= 0; j
< mc
->generic
.ctrl
->radio
.nbuttons
; j
++)
295 ShowControl(mc
->radio
.tbctrls
[j
]);
297 HideControl(mc
->radio
.tbctrls
[j
]);
299 case MACCTRL_CHECKBOX
:
301 ShowControl(mc
->checkbox
.tbctrl
);
303 HideControl(mc
->checkbox
.tbctrl
);
307 ShowControl(mc
->button
.tbctrl
);
309 HideControl(mc
->button
.tbctrl
);
315 static void macctrl_text(struct macctrls
*mcs
, WindowPtr window
,
316 struct mac_layoutstate
*curstate
,
319 union macctrl
*mc
= smalloc(sizeof *mc
);
322 fprintf(stderr
, " label = %s\n", ctrl
->text
.label
);
323 mc
->generic
.type
= MACCTRL_TEXT
;
324 mc
->generic
.ctrl
= ctrl
;
325 bounds
.left
= curstate
->pos
.h
;
326 bounds
.right
= bounds
.left
+ curstate
->width
;
327 bounds
.top
= curstate
->pos
.v
;
328 bounds
.bottom
= bounds
.top
+ 16;
329 if (mac_gestalts
.apprvers
>= 0x100) {
333 mc
->text
.tbctrl
= NewControl(window
, &bounds
, NULL
, TRUE
, 0, 0, 0,
334 kControlStaticTextProc
, (long)mc
);
335 SetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
336 kControlStaticTextTextTag
,
337 strlen(ctrl
->text
.label
), ctrl
->text
.label
);
338 GetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
339 kControlStaticTextTextHeightTag
,
340 sizeof(height
), &height
, &olen
);
341 fprintf(stderr
, " height = %d\n", height
);
342 SizeControl(mc
->text
.tbctrl
, curstate
->width
, height
);
343 curstate
->pos
.v
+= height
+ 6;
347 c2pstrcpy(title
, ctrl
->text
.label
);
348 mc
->text
.tbctrl
= NewControl(window
, &bounds
, title
, TRUE
, 0, 0, 0,
349 SYS7_TEXT_PROC
, (long)mc
);
351 add234(mcs
->byctrl
, mc
);
352 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
353 mcs
->panels
[curstate
->panelnum
] = mc
;
356 #if !TARGET_API_MAC_CARBON
357 static pascal SInt32
macctrl_sys7_text_cdef(SInt16 variant
, ControlRef control
,
358 ControlDefProcMessage msg
, SInt32 param
)
364 if ((*control
)->contrlVis
)
365 TETextBox((*control
)->contrlTitle
+ 1, (*control
)->contrlTitle
[0],
366 &(*control
)->contrlRect
, teFlushDefault
);
369 if (param
& (1 << 31)) {
375 rgn
= (RgnHandle
)param
;
376 RectRgn(rgn
, &(*control
)->contrlRect
);
380 rgn
= (RgnHandle
)param
;
389 static void macctrl_radio(struct macctrls
*mcs
, WindowPtr window
,
390 struct mac_layoutstate
*curstate
,
393 union macctrl
*mc
= smalloc(sizeof *mc
);
396 unsigned int i
, colwidth
;
398 fprintf(stderr
, " label = %s\n", ctrl
->radio
.label
);
399 mc
->generic
.type
= MACCTRL_RADIO
;
400 mc
->generic
.ctrl
= ctrl
;
402 smalloc(sizeof(*mc
->radio
.tbctrls
) * ctrl
->radio
.nbuttons
);
403 colwidth
= (curstate
->width
+ 13) / ctrl
->radio
.ncolumns
;
404 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
405 fprintf(stderr
, " button = %s\n", ctrl
->radio
.buttons
[i
]);
406 bounds
.top
= curstate
->pos
.v
;
407 bounds
.bottom
= bounds
.top
+ 16;
408 bounds
.left
= curstate
->pos
.h
+ colwidth
* (i
% ctrl
->radio
.ncolumns
);
409 if (i
== ctrl
->radio
.nbuttons
- 1 ||
410 i
% ctrl
->radio
.ncolumns
== ctrl
->radio
.ncolumns
- 1) {
411 bounds
.right
= curstate
->pos
.h
+ curstate
->width
;
412 curstate
->pos
.v
+= 22;
414 bounds
.right
= bounds
.left
+ colwidth
- 13;
415 c2pstrcpy(title
, ctrl
->radio
.buttons
[i
]);
416 mc
->radio
.tbctrls
[i
] = NewControl(window
, &bounds
, title
, TRUE
,
417 0, 0, 1, radioButProc
, (long)mc
);
419 add234(mcs
->byctrl
, mc
);
420 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
421 mcs
->panels
[curstate
->panelnum
] = mc
;
422 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
425 static void macctrl_checkbox(struct macctrls
*mcs
, WindowPtr window
,
426 struct mac_layoutstate
*curstate
,
429 union macctrl
*mc
= smalloc(sizeof *mc
);
433 fprintf(stderr
, " label = %s\n", ctrl
->checkbox
.label
);
434 mc
->generic
.type
= MACCTRL_CHECKBOX
;
435 mc
->generic
.ctrl
= ctrl
;
436 bounds
.left
= curstate
->pos
.h
;
437 bounds
.right
= bounds
.left
+ curstate
->width
;
438 bounds
.top
= curstate
->pos
.v
;
439 bounds
.bottom
= bounds
.top
+ 16;
440 c2pstrcpy(title
, ctrl
->checkbox
.label
);
441 mc
->checkbox
.tbctrl
= NewControl(window
, &bounds
, title
, TRUE
, 0, 0, 1,
442 checkBoxProc
, (long)mc
);
443 add234(mcs
->byctrl
, mc
);
444 curstate
->pos
.v
+= 22;
445 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
446 mcs
->panels
[curstate
->panelnum
] = mc
;
447 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
450 static void macctrl_button(struct macctrls
*mcs
, WindowPtr window
,
451 struct mac_layoutstate
*curstate
,
454 union macctrl
*mc
= smalloc(sizeof *mc
);
458 fprintf(stderr
, " label = %s\n", ctrl
->button
.label
);
459 if (ctrl
->button
.isdefault
)
460 fprintf(stderr
, " is default\n");
461 mc
->generic
.type
= MACCTRL_BUTTON
;
462 mc
->generic
.ctrl
= ctrl
;
463 bounds
.left
= curstate
->pos
.h
;
464 bounds
.right
= bounds
.left
+ 100; /* XXX measure string */
465 bounds
.top
= curstate
->pos
.v
;
466 bounds
.bottom
= bounds
.top
+ 20;
467 c2pstrcpy(title
, ctrl
->button
.label
);
468 mc
->button
.tbctrl
= NewControl(window
, &bounds
, title
, TRUE
, 0, 0, 1,
469 pushButProc
, (long)mc
);
470 if (mac_gestalts
.apprvers
>= 0x100) {
471 Boolean isdefault
= ctrl
->button
.isdefault
;
473 SetControlData(mc
->button
.tbctrl
, kControlEntireControl
,
474 kControlPushButtonDefaultTag
,
475 sizeof(isdefault
), &isdefault
);
476 } else if (ctrl
->button
.isdefault
) {
477 InsetRect(&bounds
, -4, -4);
478 NewControl(window
, &bounds
, title
, TRUE
, 0, 0, 1,
479 SYS7_DEFAULT_PROC
, (long)mc
);
481 if (mac_gestalts
.apprvers
>= 0x110) {
482 Boolean iscancel
= ctrl
->button
.iscancel
;
484 SetControlData(mc
->button
.tbctrl
, kControlEntireControl
,
485 kControlPushButtonCancelTag
,
486 sizeof(iscancel
), &iscancel
);
488 add234(mcs
->byctrl
, mc
);
489 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
490 mcs
->panels
[curstate
->panelnum
] = mc
;
491 curstate
->pos
.v
+= 26;
494 #if !TARGET_API_MAC_CARBON
495 static pascal SInt32
macctrl_sys7_default_cdef(SInt16 variant
,
497 ControlDefProcMessage msg
,
506 if ((*control
)->contrlVis
) {
507 rect
= (*control
)->contrlRect
;
510 oval
= (rect
.bottom
- rect
.top
) / 2 + 2;
511 FrameRoundRect(&rect
, oval
, oval
);
515 if (param
& (1 << 31)) {
521 rgn
= (RgnHandle
)param
;
522 RectRgn(rgn
, &(*control
)->contrlRect
);
526 rgn
= (RgnHandle
)param
;
535 static void macctrl_popup(struct macctrls
*mcs
, WindowPtr window
,
536 struct mac_layoutstate
*curstate
,
539 union macctrl
*mc
= smalloc(sizeof *mc
);
542 unsigned int labelwidth
;
543 static int nextmenuid
;
548 * <http://developer.apple.com/qa/tb/tb42.html> explains how to
549 * create a popup menu with dynamic content.
551 assert(ctrl
->listbox
.height
== 0);
552 assert(!ctrl
->listbox
.draglist
);
553 assert(!ctrl
->listbox
.multisel
);
555 fprintf(stderr
, " label = %s\n", ctrl
->listbox
.label
);
556 fprintf(stderr
, " percentwidth = %d\n", ctrl
->listbox
.percentwidth
);
558 mc
->generic
.type
= MACCTRL_POPUP
;
559 mc
->generic
.ctrl
= ctrl
;
560 c2pstrcpy(title
, ctrl
->button
.label
);
562 /* Find a spare menu ID and create the menu */
563 while (GetMenuHandle(nextmenuid
) != NULL
)
564 if (++nextmenuid
>= MENU_MAX
) nextmenuid
= MENU_MIN
;
565 menuid
= nextmenuid
++;
566 menu
= NewMenu(menuid
, "\pdummy");
567 if (menu
== NULL
) return;
568 mc
->popup
.menu
= menu
;
569 mc
->popup
.menuid
= menuid
;
570 InsertMenu(menu
, kInsertHierarchicalMenu
);
572 /* The menu starts off empty */
574 mc
->popup
.ids
= NULL
;
576 bounds
.left
= curstate
->pos
.h
;
577 bounds
.right
= bounds
.left
+ curstate
->width
;
578 bounds
.top
= curstate
->pos
.v
;
579 bounds
.bottom
= bounds
.top
+ 20;
580 /* XXX handle percentwidth == 100 */
581 labelwidth
= curstate
->width
* (100 - ctrl
->listbox
.percentwidth
) / 100;
582 mc
->popup
.tbctrl
= NewControl(window
, &bounds
, title
, TRUE
,
583 popupTitleLeftJust
, menuid
, labelwidth
,
584 popupMenuProc
+ popupFixedWidth
, (long)mc
);
585 add234(mcs
->byctrl
, mc
);
586 curstate
->pos
.v
+= 26;
587 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
588 mcs
->panels
[curstate
->panelnum
] = mc
;
589 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
593 void macctrl_activate(WindowPtr window
, EventRecord
*event
)
595 Boolean active
= (event
->modifiers
& activeFlag
) != 0;
600 SetPort((GrafPtr
)GetWindowPort(window
));
601 if (mac_gestalts
.apprvers
>= 0x100) {
602 SetThemeWindowBackground(window
, active ?
603 kThemeBrushModelessDialogBackgroundActive
:
604 kThemeBrushModelessDialogBackgroundInactive
,
606 GetRootControl(window
, &root
);
608 ActivateControl(root
);
610 DeactivateControl(root
);
612 /* (De)activate controls one at a time */
617 void macctrl_click(WindowPtr window
, EventRecord
*event
)
620 ControlHandle control
;
624 struct macctrls
*mcs
= mac_winctrls(window
);
628 SetPort((GrafPtr
)GetWindowPort(window
));
629 mouse
= event
->where
;
630 GlobalToLocal(&mouse
);
631 part
= FindControl(mouse
, window
, &control
);
632 if (control
!= NULL
) {
633 mc
= (union macctrl
*)GetControlReference(control
);
634 switch (mc
->generic
.type
) {
636 TrackControl(control
, mouse
, (ControlActionUPP
)-1);
637 ctrlevent(mcs
, mc
, EVENT_SELCHANGE
);
639 if (TrackControl(control
, mouse
, NULL
) != 0) {
640 for (i
= 0; i
< mc
->generic
.ctrl
->radio
.nbuttons
; i
++)
641 if (mc
->radio
.tbctrls
[i
] == control
)
642 SetControlValue(mc
->radio
.tbctrls
[i
],
643 kControlRadioButtonCheckedValue
);
645 SetControlValue(mc
->radio
.tbctrls
[i
],
646 kControlRadioButtonUncheckedValue
);
647 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
650 case MACCTRL_CHECKBOX
:
651 if (TrackControl(control
, mouse
, NULL
) != 0) {
652 SetControlValue(control
, !GetControlValue(control
));
653 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
657 if (TrackControl(control
, mouse
, NULL
) != 0)
658 ctrlevent(mcs
, mc
, EVENT_ACTION
);
665 void macctrl_update(WindowPtr window
)
667 #if TARGET_API_MAC_CARBON
675 SetPort((GrafPtr
)GetWindowPort(window
));
676 if (mac_gestalts
.apprvers
>= 0x101) {
677 #if TARGET_API_MAC_CARBON
678 GetPortBounds(GetWindowPort(window
), &rect
);
680 rect
= window
->portRect
;
682 InsetRect(&rect
, -1, -1);
683 DrawThemeModelessDialogFrame(&rect
, mac_frontwindow() == window ?
684 kThemeStateActive
: kThemeStateInactive
);
686 #if TARGET_API_MAC_CARBON
688 GetPortVisibleRegion(GetWindowPort(window
), visrgn
);
689 UpdateControls(window
, visrgn
);
692 UpdateControls(window
, window
->visRgn
);
698 #if TARGET_API_MAC_CARBON
699 #define EnableItem EnableMenuItem
700 #define DisableItem DisableMenuItem
702 void macctrl_adjustmenus(WindowPtr window
)
706 menu
= GetMenuHandle(mFile
);
707 DisableItem(menu
, iSave
); /* XXX enable if modified */
708 EnableItem(menu
, iSaveAs
);
709 EnableItem(menu
, iDuplicate
);
711 menu
= GetMenuHandle(mEdit
);
712 DisableItem(menu
, 0);
715 void macctrl_close(WindowPtr window
)
717 struct macctrls
*mcs
= mac_winctrls(window
);
721 * Mostly, we don't bother disposing of the Toolbox controls,
722 * since that will happen automatically when the window is
723 * disposed of. Popup menus are an exception, because we have to
724 * dispose of the menu ourselves, and doing that while the control
725 * still holds a reference to it seems rude.
727 while ((mc
= index234(mcs
->byctrl
, 0)) != NULL
) {
728 switch (mc
->generic
.type
) {
730 DisposeControl(mc
->popup
.tbctrl
);
731 DeleteMenu(mc
->popup
.menuid
);
732 DisposeMenu(mc
->popup
.menu
);
735 del234(mcs
->byctrl
, mc
);
739 freetree234(mcs
->byctrl
);
745 void dlg_update_start(union control
*ctrl
, void *dlg
)
751 void dlg_update_done(union control
*ctrl
, void *dlg
)
757 void dlg_set_focus(union control
*ctrl
, void *dlg
)
760 if (mac_gestalts
.apprvers
>= 0x100) {
761 /* Use SetKeyboardFocus() */
763 /* Do our own mucking around */
767 union control
*dlg_last_focused(union control
*ctrl
, void *dlg
)
773 void dlg_beep(void *dlg
)
779 void dlg_error_msg(void *dlg
, char *msg
)
783 c2pstrcpy(pmsg
, msg
);
784 ParamText(pmsg
, NULL
, NULL
, NULL
);
785 StopAlert(128, NULL
);
788 void dlg_end(void *dlg
, int value
)
793 void dlg_refresh(union control
*ctrl
, void *dlg
)
798 void *dlg_get_privdata(union control
*ctrl
, void *dlg
)
804 void dlg_set_privdata(union control
*ctrl
, void *dlg
, void *ptr
)
807 fatalbox("dlg_set_privdata");
810 void *dlg_alloc_privdata(union control
*ctrl
, void *dlg
, size_t size
)
813 fatalbox("dlg_alloc_privdata");
818 * Radio Button control
821 void dlg_radiobutton_set(union control
*ctrl
, void *dlg
, int whichbutton
)
823 struct macctrls
*mcs
= dlg
;
824 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
828 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
829 if (i
== whichbutton
)
830 SetControlValue(mc
->radio
.tbctrls
[i
],
831 kControlRadioButtonCheckedValue
);
833 SetControlValue(mc
->radio
.tbctrls
[i
],
834 kControlRadioButtonUncheckedValue
);
839 int dlg_radiobutton_get(union control
*ctrl
, void *dlg
)
841 struct macctrls
*mcs
= dlg
;
842 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
846 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
847 if (GetControlValue(mc
->radio
.tbctrls
[i
]) ==
848 kControlRadioButtonCheckedValue
)
859 void dlg_checkbox_set(union control
*ctrl
, void *dlg
, int checked
)
861 struct macctrls
*mcs
= dlg
;
862 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
865 SetControlValue(mc
->checkbox
.tbctrl
,
866 checked ? kControlCheckBoxCheckedValue
:
867 kControlCheckBoxUncheckedValue
);
870 int dlg_checkbox_get(union control
*ctrl
, void *dlg
)
872 struct macctrls
*mcs
= dlg
;
873 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
876 return GetControlValue(mc
->checkbox
.tbctrl
);
884 void dlg_editbox_set(union control
*ctrl
, void *dlg
, char const *text
)
889 void dlg_editbox_get(union control
*ctrl
, void *dlg
, char *buffer
, int length
)
899 static void dlg_macpopup_clear(union control
*ctrl
, void *dlg
)
901 struct macctrls
*mcs
= dlg
;
902 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
903 MenuRef menu
= mc
->popup
.menu
;
906 fprintf(stderr
, " popup_clear\n");
907 n
= CountMItems(menu
);
908 for (i
= 0; i
< n
; i
++)
909 DeleteMenuItem(menu
, n
- i
);
911 sfree(mc
->popup
.ids
);
912 mc
->popup
.ids
= NULL
;
913 SetControlMaximum(mc
->popup
.tbctrl
, CountMItems(menu
));
916 void dlg_listbox_clear(union control
*ctrl
, void *dlg
)
919 if (ctrl
->listbox
.height
== 0)
920 dlg_macpopup_clear(ctrl
, dlg
);
923 static void dlg_macpopup_del(union control
*ctrl
, void *dlg
, int index
)
925 struct macctrls
*mcs
= dlg
;
926 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
927 MenuRef menu
= mc
->popup
.menu
;
929 fprintf(stderr
, " popup_del %d\n", index
);
930 DeleteMenuItem(menu
, index
+ 1);
931 if (mc
->popup
.ids
!= NULL
)
932 memcpy(mc
->popup
.ids
+ index
, mc
->popup
.ids
+ index
+ 1,
933 (mc
->popup
.nids
- index
- 1) * sizeof(*mc
->popup
.ids
));
934 SetControlMaximum(mc
->popup
.tbctrl
, CountMItems(menu
));
937 void dlg_listbox_del(union control
*ctrl
, void *dlg
, int index
)
940 if (ctrl
->listbox
.height
== 0)
941 dlg_macpopup_del(ctrl
, dlg
, index
);
944 static void dlg_macpopup_add(union control
*ctrl
, void *dlg
, char const *text
)
946 struct macctrls
*mcs
= dlg
;
947 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
948 MenuRef menu
= mc
->popup
.menu
;
951 fprintf(stderr
, " popup_add %s\n", text
);
952 assert(text
[0] != '\0');
953 c2pstrcpy(itemstring
, text
);
954 AppendMenu(menu
, "\pdummy");
955 SetMenuItemText(menu
, CountMItems(menu
), itemstring
);
956 SetControlMaximum(mc
->popup
.tbctrl
, CountMItems(menu
));
959 void dlg_listbox_add(union control
*ctrl
, void *dlg
, char const *text
)
962 if (ctrl
->listbox
.height
== 0)
963 dlg_macpopup_add(ctrl
, dlg
, text
);
966 static void dlg_macpopup_addwithindex(union control
*ctrl
, void *dlg
,
967 char const *text
, int id
)
969 struct macctrls
*mcs
= dlg
;
970 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
971 MenuRef menu
= mc
->popup
.menu
;
974 fprintf(stderr
, " popup_addwthindex %s, %d\n", text
, id
);
975 dlg_macpopup_add(ctrl
, dlg
, text
);
976 index
= CountMItems(menu
) - 1;
977 if (mc
->popup
.nids
<= index
) {
978 mc
->popup
.nids
= index
+ 1;
979 mc
->popup
.ids
= srealloc(mc
->popup
.ids
,
980 mc
->popup
.nids
* sizeof(*mc
->popup
.ids
));
982 mc
->popup
.ids
[index
] = id
;
985 void dlg_listbox_addwithindex(union control
*ctrl
, void *dlg
,
986 char const *text
, int id
)
989 if (ctrl
->listbox
.height
== 0)
990 dlg_macpopup_addwithindex(ctrl
, dlg
, text
, id
);
993 int dlg_listbox_getid(union control
*ctrl
, void *dlg
, int index
)
995 struct macctrls
*mcs
= dlg
;
996 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
998 if (ctrl
->listbox
.height
== 0) {
999 assert(mc
->popup
.ids
!= NULL
&& mc
->popup
.nids
> index
);
1000 return mc
->popup
.ids
[index
];
1005 int dlg_listbox_index(union control
*ctrl
, void *dlg
)
1007 struct macctrls
*mcs
= dlg
;
1008 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1010 if (ctrl
->listbox
.height
== 0)
1011 return GetControlValue(mc
->popup
.tbctrl
) - 1;
1015 int dlg_listbox_issel(union control
*ctrl
, void *dlg
, int index
)
1017 struct macctrls
*mcs
= dlg
;
1018 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1020 if (ctrl
->listbox
.height
== 0)
1021 return GetControlValue(mc
->popup
.tbctrl
) - 1 == index
;
1025 void dlg_listbox_select(union control
*ctrl
, void *dlg
, int index
)
1027 struct macctrls
*mcs
= dlg
;
1028 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1030 if (ctrl
->listbox
.height
== 0)
1031 SetControlValue(mc
->popup
.tbctrl
, index
+ 1);
1039 void dlg_text_set(union control
*ctrl
, void *dlg
, char const *text
)
1041 struct macctrls
*mcs
= dlg
;
1042 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1046 if (mac_gestalts
.apprvers
>= 0x100)
1047 SetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
1048 kControlStaticTextTextTag
,
1049 strlen(ctrl
->text
.label
), ctrl
->text
.label
);
1051 c2pstrcpy(title
, text
);
1052 SetControlTitle(mc
->text
.tbctrl
, title
);
1058 * File Selector control
1061 void dlg_filesel_set(union control
*ctrl
, void *dlg
, Filename fn
)
1066 void dlg_filesel_get(union control
*ctrl
, void *dlg
, Filename
*fn
)
1073 * Font Selector control
1076 void dlg_fontsel_set(union control
*ctrl
, void *dlg
, FontSpec fn
)
1081 void dlg_fontsel_get(union control
*ctrl
, void *dlg
, FontSpec
*fn
)
1088 * Printer enumeration
1091 printer_enum
*printer_start_enum(int *nprinters
)
1098 char *printer_get_name(printer_enum
*pe
, int thing
)
1104 void printer_finish_enum(printer_enum
*pe
)
1111 * Colour selection stuff
1114 void dlg_coloursel_start(union control
*ctrl
, void *dlg
,
1115 int r
, int g
, int b
)
1120 int dlg_coloursel_results(union control
*ctrl
, void *dlg
,
1121 int *r
, int *g
, int *b
)
1129 * c-file-style: "simon"