1 /* $Id: macctrls.c,v 1.27 2003/04/05 15:55:22 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>
37 #include <TextUtils.h>
38 #include <ToolUtils.h>
50 /* Range of menu IDs for popup menus */
56 struct macctrl_generic
{
65 /* Template from which this was generated */
67 /* Next control in this panel */
73 struct macctrl_generic generic
;
77 struct macctrl_generic generic
;
82 struct macctrl_generic generic
;
87 struct macctrl_generic generic
;
91 struct macctrl_generic generic
;
95 struct macctrl_generic generic
;
104 struct mac_layoutstate
{
107 unsigned int panelnum
;
110 #define ctrlevent(mcs, mc, event) do { \
111 if ((mc)->generic.ctrl->generic.handler != NULL) \
112 (*(mc)->generic.ctrl->generic.handler)((mc)->generic.ctrl, (mcs),\
113 (mcs)->data, (event)); \
116 #define findbyctrl(mcs, ctrl) \
117 find234((mcs)->byctrl, (ctrl), macctrl_cmp_byctrl_find)
119 static void macctrl_layoutset(struct mac_layoutstate
*, struct controlset
*,
120 WindowPtr
, struct macctrls
*);
121 static void macctrl_switchtopanel(struct macctrls
*, unsigned int);
122 static void macctrl_setfocus(struct macctrls
*, union macctrl
*);
123 static void macctrl_text(struct macctrls
*, WindowPtr
,
124 struct mac_layoutstate
*, union control
*);
125 static void macctrl_editbox(struct macctrls
*, WindowPtr
,
126 struct mac_layoutstate
*, union control
*);
127 static void macctrl_radio(struct macctrls
*, WindowPtr
,
128 struct mac_layoutstate
*, union control
*);
129 static void macctrl_checkbox(struct macctrls
*, WindowPtr
,
130 struct mac_layoutstate
*, union control
*);
131 static void macctrl_button(struct macctrls
*, WindowPtr
,
132 struct mac_layoutstate
*, union control
*);
133 static void macctrl_popup(struct macctrls
*, WindowPtr
,
134 struct mac_layoutstate
*, union control
*);
135 #if !TARGET_API_MAC_CARBON
136 static pascal SInt32
macctrl_sys7_editbox_cdef(SInt16
, ControlRef
,
137 ControlDefProcMessage
, SInt32
);
138 static pascal SInt32
macctrl_sys7_default_cdef(SInt16
, ControlRef
,
139 ControlDefProcMessage
, SInt32
);
142 #if !TARGET_API_MAC_CARBON
144 * This trick enables us to keep all the CDEF code in the main
145 * application, which makes life easier. For details, see
146 * <http://developer.apple.com/technotes/tn/tn2003.html#custom_code_base>.
149 #pragma options align=mac68k
151 short jmpabs
; /* 4EF9 */
152 ControlDefUPP theUPP
;
154 #pragma options align=reset
157 static void macctrl_init()
159 #if !TARGET_API_MAC_CARBON
160 static int inited
= 0;
164 cdef
= (PatchCDEF
)GetResource(kControlDefProcResourceType
, CDEF_EditBox
);
165 (*cdef
)->theUPP
= NewControlDefProc(macctrl_sys7_editbox_cdef
);
166 cdef
= (PatchCDEF
)GetResource(kControlDefProcResourceType
, CDEF_Default
);
167 (*cdef
)->theUPP
= NewControlDefProc(macctrl_sys7_default_cdef
);
173 static int macctrl_cmp_byctrl(void *av
, void *bv
)
175 union macctrl
*a
= (union macctrl
*)av
;
176 union macctrl
*b
= (union macctrl
*)bv
;
178 if (a
->generic
.ctrl
< b
->generic
.ctrl
)
180 else if (a
->generic
.ctrl
> b
->generic
.ctrl
)
186 static int macctrl_cmp_byctrl_find(void *av
, void *bv
)
188 union control
*a
= (union control
*)av
;
189 union macctrl
*b
= (union macctrl
*)bv
;
191 if (a
< b
->generic
.ctrl
)
193 else if (a
> b
->generic
.ctrl
)
199 void macctrl_layoutbox(struct controlbox
*cb
, WindowPtr window
,
200 struct macctrls
*mcs
)
203 struct mac_layoutstate curstate
;
208 #if TARGET_API_MAC_CARBON
209 GetPortBounds(GetWindowPort(window
), &rect
);
211 rect
= window
->portRect
;
213 curstate
.pos
.h
= rect
.left
+ 13;
214 curstate
.pos
.v
= rect
.bottom
- 33;
215 curstate
.width
= rect
.right
- rect
.left
- (13 * 2);
216 if (mac_gestalts
.apprvers
>= 0x100)
217 CreateRootControl(window
, &root
);
218 mcs
->window
= window
;
219 mcs
->byctrl
= newtree234(macctrl_cmp_byctrl
);
221 /* Count the number of panels */
223 for (i
= 1; i
< cb
->nctrlsets
; i
++)
224 if (strcmp(cb
->ctrlsets
[i
]->pathname
, cb
->ctrlsets
[i
-1]->pathname
))
226 mcs
->panels
= snewn(mcs
->npanels
, union macctrl
*);
227 memset(mcs
->panels
, 0, sizeof(*mcs
->panels
) * mcs
->npanels
);
228 curstate
.panelnum
= 0;
229 for (i
= 0; i
< cb
->nctrlsets
; i
++) {
230 if (i
> 0 && strcmp(cb
->ctrlsets
[i
]->pathname
,
231 cb
->ctrlsets
[i
-1]->pathname
)) {
232 curstate
.pos
.v
= rect
.top
+ 13;
234 assert(curstate
.panelnum
< mcs
->npanels
);
236 macctrl_layoutset(&curstate
, cb
->ctrlsets
[i
], window
, mcs
);
238 macctrl_switchtopanel(mcs
, 1);
239 /* 14 = proxies, 20 = SSH bugs */
244 static void macctrl_layoutset(struct mac_layoutstate
*curstate
,
245 struct controlset
*s
,
246 WindowPtr window
, struct macctrls
*mcs
)
248 unsigned int i
, j
, ncols
, colstart
;
249 struct mac_layoutstate cols
[MAXCOLS
];
251 fprintf(stderr
, "--- begin set ---\n");
252 fprintf(stderr
, "pathname = %s\n", s
->pathname
);
253 if (s
->boxname
&& *s
->boxname
)
254 fprintf(stderr
, "boxname = %s\n", s
->boxname
);
256 fprintf(stderr
, "boxtitle = %s\n", s
->boxtitle
);
261 for (i
= 0; i
< s
->ncontrols
; i
++) {
262 union control
*ctrl
= s
->ctrls
[i
];
265 colstart
= COLUMN_START(ctrl
->generic
.column
);
266 switch (ctrl
->generic
.type
) {
267 case CTRL_TEXT
: s
= "text"; break;
268 case CTRL_EDITBOX
: s
= "editbox"; break;
269 case CTRL_RADIO
: s
= "radio"; break;
270 case CTRL_CHECKBOX
: s
= "checkbox"; break;
271 case CTRL_BUTTON
: s
= "button"; break;
272 case CTRL_LISTBOX
: s
= "listbox"; break;
273 case CTRL_COLUMNS
: s
= "columns"; break;
274 case CTRL_FILESELECT
: s
= "fileselect"; break;
275 case CTRL_FONTSELECT
: s
= "fontselect"; break;
276 case CTRL_TABDELAY
: s
= "tabdelay"; break;
277 default: s
= "unknown"; break;
279 fprintf(stderr
, " control: %s\n", s
);
280 switch (ctrl
->generic
.type
) {
282 if (ctrl
->columns
.ncols
!= 1) {
283 ncols
= ctrl
->columns
.ncols
;
284 fprintf(stderr
, " split to %d\n", ncols
);
285 assert(ncols
<= MAXCOLS
);
286 for (j
= 0; j
< ncols
; j
++) {
289 cols
[j
].pos
.h
= cols
[j
-1].pos
.h
+ cols
[j
-1].width
+ 6;
291 cols
[j
].width
= curstate
->width
-
292 (cols
[j
].pos
.h
- curstate
->pos
.h
);
294 cols
[j
].width
= (curstate
->width
+ 6) *
295 ctrl
->columns
.percentages
[j
] / 100 - 6;
298 fprintf(stderr
, " join\n");
299 for (j
= 0; j
< ncols
; j
++)
300 if (cols
[j
].pos
.v
> cols
[0].pos
.v
)
301 cols
[0].pos
.v
= cols
[j
].pos
.v
;
302 cols
[0].width
= curstate
->width
;
307 macctrl_text(mcs
, window
, &cols
[colstart
], ctrl
);
310 macctrl_editbox(mcs
, window
, &cols
[colstart
], ctrl
);
313 macctrl_radio(mcs
, window
, &cols
[colstart
], ctrl
);
316 macctrl_checkbox(mcs
, window
, &cols
[colstart
], ctrl
);
319 macctrl_button(mcs
, window
, &cols
[colstart
], ctrl
);
322 if (ctrl
->listbox
.height
== 0)
323 macctrl_popup(mcs
, window
, &cols
[colstart
], ctrl
);
327 for (j
= 0; j
< ncols
; j
++)
328 if (cols
[j
].pos
.v
> curstate
->pos
.v
)
329 curstate
->pos
.v
= cols
[j
].pos
.v
;
332 static void macctrl_switchtopanel(struct macctrls
*mcs
, unsigned int which
)
337 #define hideshow(c) do { \
338 if (i == which) ShowControl(c); else HideControl(c); \
341 mcs
->curpanel
= which
;
342 /* Panel 0 is special and always visible. */
343 for (i
= 1; i
< mcs
->npanels
; i
++)
344 for (mc
= mcs
->panels
[i
]; mc
!= NULL
; mc
= mc
->generic
.next
) {
345 #if !TARGET_API_MAC_CARBON
346 if (mcs
->focus
== mc
)
347 macctrl_setfocus(mcs
, NULL
);
349 switch (mc
->generic
.type
) {
351 hideshow(mc
->text
.tbctrl
);
353 case MACCTRL_EDITBOX
:
354 hideshow(mc
->editbox
.tbctrl
);
355 if (mc
->editbox
.tblabel
!= NULL
)
356 hideshow(mc
->editbox
.tblabel
);
359 for (j
= 0; j
< mc
->generic
.ctrl
->radio
.nbuttons
; j
++)
360 hideshow(mc
->radio
.tbctrls
[j
]);
361 if (mc
->radio
.tblabel
!= NULL
)
362 hideshow(mc
->radio
.tblabel
);
364 case MACCTRL_CHECKBOX
:
365 hideshow(mc
->checkbox
.tbctrl
);
368 hideshow(mc
->button
.tbctrl
);
371 hideshow(mc
->popup
.tbctrl
);
377 #if !TARGET_API_MAC_CARBON
379 * System 7 focus manipulation
381 static void macctrl_defocus(union macctrl
*mc
)
384 assert(mac_gestalts
.apprvers
< 0x100);
385 switch (mc
->generic
.type
) {
386 case MACCTRL_EDITBOX
:
387 TEDeactivate((TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
);
392 static void macctrl_enfocus(union macctrl
*mc
)
395 assert(mac_gestalts
.apprvers
< 0x100);
396 switch (mc
->generic
.type
) {
397 case MACCTRL_EDITBOX
:
398 TEActivate((TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
);
403 static void macctrl_setfocus(struct macctrls
*mcs
, union macctrl
*mc
)
406 if (mcs
->focus
!= NULL
)
407 macctrl_defocus(mcs
->focus
);
414 static void macctrl_text(struct macctrls
*mcs
, WindowPtr window
,
415 struct mac_layoutstate
*curstate
,
418 union macctrl
*mc
= snew(union macctrl
);
422 assert(ctrl
->text
.label
!= NULL
);
423 fprintf(stderr
, " label = %s\n", ctrl
->text
.label
);
424 mc
->generic
.type
= MACCTRL_TEXT
;
425 mc
->generic
.ctrl
= ctrl
;
426 mc
->generic
.privdata
= NULL
;
427 bounds
.left
= curstate
->pos
.h
;
428 bounds
.right
= bounds
.left
+ curstate
->width
;
429 bounds
.top
= curstate
->pos
.v
;
430 bounds
.bottom
= bounds
.top
+ 16;
431 if (mac_gestalts
.apprvers
>= 0x100) {
434 mc
->text
.tbctrl
= NewControl(window
, &bounds
, NULL
, TRUE
, 0, 0, 0,
435 kControlStaticTextProc
, (long)mc
);
436 SetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
437 kControlStaticTextTextTag
,
438 strlen(ctrl
->text
.label
), ctrl
->text
.label
);
439 GetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
440 kControlStaticTextTextHeightTag
,
441 sizeof(height
), &height
, &olen
);
443 #if !TARGET_API_MAC_CARBON
447 mc
->text
.tbctrl
= NewControl(window
, &bounds
, NULL
, TRUE
, 0, 0, 0,
448 SYS7_TEXT_PROC
, (long)mc
);
449 te
= (TEHandle
)(*mc
->text
.tbctrl
)->contrlData
;
450 TESetText(ctrl
->text
.label
, strlen(ctrl
->text
.label
), te
);
451 height
= TEGetHeight(1, (*te
)->nLines
, te
);
454 fprintf(stderr
, " height = %d\n", height
);
455 SizeControl(mc
->text
.tbctrl
, curstate
->width
, height
);
456 curstate
->pos
.v
+= height
+ 6;
457 add234(mcs
->byctrl
, mc
);
458 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
459 mcs
->panels
[curstate
->panelnum
] = mc
;
462 static void macctrl_editbox(struct macctrls
*mcs
, WindowPtr window
,
463 struct mac_layoutstate
*curstate
,
466 union macctrl
*mc
= snew(union macctrl
);
467 Rect lbounds
, bounds
;
469 if (ctrl
->editbox
.label
!= NULL
)
470 fprintf(stderr
, " label = %s\n", ctrl
->editbox
.label
);
471 fprintf(stderr
, " percentwidth = %d\n", ctrl
->editbox
.percentwidth
);
472 if (ctrl
->editbox
.password
) fprintf(stderr
, " password\n");
473 if (ctrl
->editbox
.has_list
) fprintf(stderr
, " has list\n");
474 mc
->generic
.type
= MACCTRL_EDITBOX
;
475 mc
->generic
.ctrl
= ctrl
;
476 mc
->generic
.privdata
= NULL
;
477 lbounds
.left
= curstate
->pos
.h
;
478 lbounds
.top
= curstate
->pos
.v
;
479 if (ctrl
->editbox
.percentwidth
== 100) {
480 if (ctrl
->editbox
.label
!= NULL
) {
481 lbounds
.right
= lbounds
.left
+ curstate
->width
;
482 lbounds
.bottom
= lbounds
.top
+ 16;
483 curstate
->pos
.v
+= 18;
485 bounds
.left
= curstate
->pos
.h
;
486 bounds
.right
= bounds
.left
+ curstate
->width
;
488 lbounds
.right
= lbounds
.left
+
489 curstate
->width
* (100 - ctrl
->editbox
.percentwidth
) / 100;
490 lbounds
.bottom
= lbounds
.top
+ 22;
491 bounds
.left
= lbounds
.right
;
492 bounds
.right
= lbounds
.left
+ curstate
->width
;
494 bounds
.top
= curstate
->pos
.v
;
495 bounds
.bottom
= bounds
.top
+ 22;
496 if (mac_gestalts
.apprvers
>= 0x100) {
497 if (ctrl
->editbox
.label
== NULL
)
498 mc
->editbox
.tblabel
= NULL
;
500 mc
->editbox
.tblabel
= NewControl(window
, &lbounds
, NULL
, TRUE
,
501 0, 0, 0, kControlStaticTextProc
,
503 SetControlData(mc
->editbox
.tblabel
, kControlEntireControl
,
504 kControlStaticTextTextTag
,
505 strlen(ctrl
->editbox
.label
), ctrl
->editbox
.label
);
507 InsetRect(&bounds
, 3, 3);
508 mc
->editbox
.tbctrl
= NewControl(window
, &bounds
, NULL
, TRUE
, 0, 0, 0,
509 ctrl
->editbox
.password ?
510 kControlEditTextPasswordProc
:
511 kControlEditTextProc
, (long)mc
);
513 #if !TARGET_API_MAC_CARBON
515 if (ctrl
->editbox
.label
== NULL
)
516 mc
->editbox
.tblabel
= NULL
;
518 mc
->editbox
.tblabel
= NewControl(window
, &lbounds
, NULL
, TRUE
,
519 0, 0, 0, SYS7_TEXT_PROC
,
521 TESetText(ctrl
->editbox
.label
, strlen(ctrl
->editbox
.label
),
522 (TEHandle
)(*mc
->editbox
.tblabel
)->contrlData
);
524 mc
->editbox
.tbctrl
= NewControl(window
, &bounds
, NULL
, TRUE
, 0, 0, 0,
525 SYS7_EDITBOX_PROC
, (long)mc
);
528 curstate
->pos
.v
+= 28;
529 add234(mcs
->byctrl
, mc
);
530 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
531 mcs
->panels
[curstate
->panelnum
] = mc
;
532 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
535 #if !TARGET_API_MAC_CARBON
536 static pascal SInt32
macctrl_sys7_editbox_cdef(SInt16 variant
,
538 ControlDefProcMessage msg
,
549 rect
= (*control
)->contrlRect
;
550 if (variant
== SYS7_EDITBOX_VARIANT
)
551 InsetRect(&rect
, 3, 3); /* 2 if it's 20 pixels high */
552 te
= TENew(&rect
, &rect
);
553 ssfs
= GetScriptVariable(smSystemScript
, smScriptSysFondSize
);
554 (*te
)->txSize
= LoWord(ssfs
);
555 (*te
)->txFont
= HiWord(ssfs
);
556 (*control
)->contrlData
= (Handle
)te
;
559 TEDispose((TEHandle
)(*control
)->contrlData
);
562 if ((*control
)->contrlVis
) {
563 rect
= (*control
)->contrlRect
;
564 if (variant
== SYS7_EDITBOX_VARIANT
) {
567 InsetRect(&rect
, 3, 3);
569 (*(TEHandle
)(*control
)->contrlData
)->viewRect
= rect
;
570 TEUpdate(&rect
, (TEHandle
)(*control
)->contrlData
);
574 if (variant
== SYS7_TEXT_VARIANT
)
575 return kControlNoPart
;
576 mouse
.h
= LoWord(param
);
577 mouse
.v
= HiWord(param
);
578 rect
= (*control
)->contrlRect
;
579 InsetRect(&rect
, 3, 3);
580 return PtInRect(mouse
, &rect
) ? kControlEditTextPart
: kControlNoPart
;
582 if (param
& (1 << 31)) {
588 rgn
= (RgnHandle
)param
;
589 RectRgn(rgn
, &(*control
)->contrlRect
);
593 rgn
= (RgnHandle
)param
;
602 static void macctrl_radio(struct macctrls
*mcs
, WindowPtr window
,
603 struct mac_layoutstate
*curstate
,
606 union macctrl
*mc
= snew(union macctrl
);
609 unsigned int i
, colwidth
;
611 if (ctrl
->radio
.label
!= NULL
)
612 fprintf(stderr
, " label = %s\n", ctrl
->radio
.label
);
613 mc
->generic
.type
= MACCTRL_RADIO
;
614 mc
->generic
.ctrl
= ctrl
;
615 mc
->generic
.privdata
= NULL
;
616 mc
->radio
.tbctrls
= snewn(ctrl
->radio
.nbuttons
, ControlRef
);
617 colwidth
= (curstate
->width
+ 13) / ctrl
->radio
.ncolumns
;
618 bounds
.top
= curstate
->pos
.v
;
619 bounds
.bottom
= bounds
.top
+ 16;
620 bounds
.left
= curstate
->pos
.h
;
621 bounds
.right
= bounds
.left
+ curstate
->width
;
622 if (ctrl
->radio
.label
== NULL
)
623 mc
->radio
.tblabel
= NULL
;
625 if (mac_gestalts
.apprvers
>= 0x100) {
626 mc
->radio
.tblabel
= NewControl(window
, &bounds
, NULL
, TRUE
,
627 0, 0, 0, kControlStaticTextProc
,
629 SetControlData(mc
->radio
.tblabel
, kControlEntireControl
,
630 kControlStaticTextTextTag
,
631 strlen(ctrl
->radio
.label
), ctrl
->radio
.label
);
633 #if !TARGET_API_MAC_CARBON
635 mc
->radio
.tblabel
= NewControl(window
, &bounds
, NULL
, TRUE
,
636 0, 0, 0, SYS7_TEXT_PROC
, (long)mc
);
637 TESetText(ctrl
->radio
.label
, strlen(ctrl
->radio
.label
),
638 (TEHandle
)(*mc
->radio
.tblabel
)->contrlData
);
641 curstate
->pos
.v
+= 18;
643 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
644 fprintf(stderr
, " button = %s\n", ctrl
->radio
.buttons
[i
]);
645 bounds
.top
= curstate
->pos
.v
- 2;
646 bounds
.bottom
= bounds
.top
+ 18;
647 bounds
.left
= curstate
->pos
.h
+ colwidth
* (i
% ctrl
->radio
.ncolumns
);
648 if (i
== ctrl
->radio
.nbuttons
- 1 ||
649 i
% ctrl
->radio
.ncolumns
== ctrl
->radio
.ncolumns
- 1) {
650 bounds
.right
= curstate
->pos
.h
+ curstate
->width
;
651 curstate
->pos
.v
+= 18;
653 bounds
.right
= bounds
.left
+ colwidth
- 13;
654 c2pstrcpy(title
, ctrl
->radio
.buttons
[i
]);
655 mc
->radio
.tbctrls
[i
] = NewControl(window
, &bounds
, title
, TRUE
,
656 0, 0, 1, radioButProc
, (long)mc
);
658 curstate
->pos
.v
+= 4;
659 add234(mcs
->byctrl
, mc
);
660 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
661 mcs
->panels
[curstate
->panelnum
] = mc
;
662 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
665 static void macctrl_checkbox(struct macctrls
*mcs
, WindowPtr window
,
666 struct mac_layoutstate
*curstate
,
669 union macctrl
*mc
= snew(union macctrl
);
673 assert(ctrl
->checkbox
.label
!= NULL
);
674 fprintf(stderr
, " label = %s\n", ctrl
->checkbox
.label
);
675 mc
->generic
.type
= MACCTRL_CHECKBOX
;
676 mc
->generic
.ctrl
= ctrl
;
677 mc
->generic
.privdata
= NULL
;
678 bounds
.left
= curstate
->pos
.h
;
679 bounds
.right
= bounds
.left
+ curstate
->width
;
680 bounds
.top
= curstate
->pos
.v
;
681 bounds
.bottom
= bounds
.top
+ 16;
682 c2pstrcpy(title
, ctrl
->checkbox
.label
);
683 mc
->checkbox
.tbctrl
= NewControl(window
, &bounds
, title
, TRUE
, 0, 0, 1,
684 checkBoxProc
, (long)mc
);
685 add234(mcs
->byctrl
, mc
);
686 curstate
->pos
.v
+= 22;
687 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
688 mcs
->panels
[curstate
->panelnum
] = mc
;
689 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
692 static void macctrl_button(struct macctrls
*mcs
, WindowPtr window
,
693 struct mac_layoutstate
*curstate
,
696 union macctrl
*mc
= snew(union macctrl
);
700 assert(ctrl
->button
.label
!= NULL
);
701 fprintf(stderr
, " label = %s\n", ctrl
->button
.label
);
702 if (ctrl
->button
.isdefault
)
703 fprintf(stderr
, " is default\n");
704 mc
->generic
.type
= MACCTRL_BUTTON
;
705 mc
->generic
.ctrl
= ctrl
;
706 mc
->generic
.privdata
= NULL
;
707 bounds
.left
= curstate
->pos
.h
;
708 bounds
.right
= bounds
.left
+ curstate
->width
;
709 bounds
.top
= curstate
->pos
.v
;
710 bounds
.bottom
= bounds
.top
+ 20;
711 c2pstrcpy(title
, ctrl
->button
.label
);
712 mc
->button
.tbctrl
= NewControl(window
, &bounds
, title
, TRUE
, 0, 0, 1,
713 pushButProc
, (long)mc
);
714 if (mac_gestalts
.apprvers
>= 0x100) {
715 Boolean isdefault
= ctrl
->button
.isdefault
;
717 SetControlData(mc
->button
.tbctrl
, kControlEntireControl
,
718 kControlPushButtonDefaultTag
,
719 sizeof(isdefault
), &isdefault
);
720 } else if (ctrl
->button
.isdefault
) {
721 InsetRect(&bounds
, -4, -4);
722 NewControl(window
, &bounds
, title
, TRUE
, 0, 0, 1,
723 SYS7_DEFAULT_PROC
, (long)mc
);
725 if (mac_gestalts
.apprvers
>= 0x110) {
726 Boolean iscancel
= ctrl
->button
.iscancel
;
728 SetControlData(mc
->button
.tbctrl
, kControlEntireControl
,
729 kControlPushButtonCancelTag
,
730 sizeof(iscancel
), &iscancel
);
732 add234(mcs
->byctrl
, mc
);
733 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
734 mcs
->panels
[curstate
->panelnum
] = mc
;
735 curstate
->pos
.v
+= 26;
738 #if !TARGET_API_MAC_CARBON
739 static pascal SInt32
macctrl_sys7_default_cdef(SInt16 variant
,
741 ControlDefProcMessage msg
,
750 if ((*control
)->contrlVis
) {
751 rect
= (*control
)->contrlRect
;
754 oval
= (rect
.bottom
- rect
.top
) / 2 + 2;
755 FrameRoundRect(&rect
, oval
, oval
);
759 if (param
& (1 << 31)) {
765 rgn
= (RgnHandle
)param
;
766 RectRgn(rgn
, &(*control
)->contrlRect
);
770 rgn
= (RgnHandle
)param
;
779 static void macctrl_popup(struct macctrls
*mcs
, WindowPtr window
,
780 struct mac_layoutstate
*curstate
,
783 union macctrl
*mc
= snew(union macctrl
);
786 unsigned int labelwidth
;
787 static int nextmenuid
= MENU_MIN
;
792 * <http://developer.apple.com/qa/tb/tb42.html> explains how to
793 * create a popup menu with dynamic content.
795 assert(ctrl
->listbox
.height
== 0);
796 assert(!ctrl
->listbox
.draglist
);
797 assert(!ctrl
->listbox
.multisel
);
799 if (ctrl
->listbox
.label
!= NULL
)
800 fprintf(stderr
, " label = %s\n", ctrl
->listbox
.label
);
801 fprintf(stderr
, " percentwidth = %d\n", ctrl
->listbox
.percentwidth
);
803 mc
->generic
.type
= MACCTRL_POPUP
;
804 mc
->generic
.ctrl
= ctrl
;
805 mc
->generic
.privdata
= NULL
;
806 c2pstrcpy(title
, ctrl
->button
.label
== NULL ?
"" : ctrl
->button
.label
);
808 /* Find a spare menu ID and create the menu */
809 while (GetMenuHandle(nextmenuid
) != NULL
)
810 if (++nextmenuid
>= MENU_MAX
) nextmenuid
= MENU_MIN
;
811 menuid
= nextmenuid
++;
812 menu
= NewMenu(menuid
, "\pdummy");
813 if (menu
== NULL
) return;
814 mc
->popup
.menu
= menu
;
815 mc
->popup
.menuid
= menuid
;
816 InsertMenu(menu
, kInsertHierarchicalMenu
);
818 /* The menu starts off empty */
820 mc
->popup
.ids
= NULL
;
822 bounds
.left
= curstate
->pos
.h
;
823 bounds
.right
= bounds
.left
+ curstate
->width
;
824 bounds
.top
= curstate
->pos
.v
;
825 bounds
.bottom
= bounds
.top
+ 20;
826 /* XXX handle percentwidth == 100 */
827 labelwidth
= curstate
->width
* (100 - ctrl
->listbox
.percentwidth
) / 100;
828 mc
->popup
.tbctrl
= NewControl(window
, &bounds
, title
, TRUE
,
829 popupTitleLeftJust
, menuid
, labelwidth
,
830 popupMenuProc
+ popupFixedWidth
, (long)mc
);
831 add234(mcs
->byctrl
, mc
);
832 curstate
->pos
.v
+= 26;
833 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
834 mcs
->panels
[curstate
->panelnum
] = mc
;
835 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
839 void macctrl_activate(WindowPtr window
, EventRecord
*event
)
841 struct macctrls
*mcs
= mac_winctrls(window
);
842 Boolean active
= (event
->modifiers
& activeFlag
) != 0;
845 ControlPartCode state
;
849 SetPort((GrafPtr
)GetWindowPort(window
));
850 if (mac_gestalts
.apprvers
>= 0x100)
851 SetThemeWindowBackground(window
, active ?
852 kThemeBrushModelessDialogBackgroundActive
:
853 kThemeBrushModelessDialogBackgroundInactive
,
855 state
= active ? kControlNoPart
: kControlInactivePart
;
856 for (i
= 0; i
<= mcs
->curpanel
; i
+= mcs
->curpanel
)
857 for (mc
= mcs
->panels
[i
]; mc
!= NULL
; mc
= mc
->generic
.next
) {
858 switch (mc
->generic
.type
) {
860 HiliteControl(mc
->text
.tbctrl
, state
);
862 case MACCTRL_EDITBOX
:
863 HiliteControl(mc
->editbox
.tbctrl
, state
);
864 if (mc
->editbox
.tblabel
!= NULL
)
865 HiliteControl(mc
->editbox
.tblabel
, state
);
868 for (j
= 0; j
< mc
->generic
.ctrl
->radio
.nbuttons
; j
++)
869 HiliteControl(mc
->radio
.tbctrls
[j
], state
);
870 if (mc
->radio
.tblabel
!= NULL
)
871 HiliteControl(mc
->radio
.tblabel
, state
);
873 case MACCTRL_CHECKBOX
:
874 HiliteControl(mc
->checkbox
.tbctrl
, state
);
877 HiliteControl(mc
->button
.tbctrl
, state
);
880 HiliteControl(mc
->popup
.tbctrl
, state
);
883 #if !TARGET_API_MAC_CARBON
884 if (mcs
->focus
== mc
) {
895 void macctrl_click(WindowPtr window
, EventRecord
*event
)
898 ControlHandle control
;
899 int part
, trackresult
;
902 struct macctrls
*mcs
= mac_winctrls(window
);
907 SetPort((GrafPtr
)GetWindowPort(window
));
908 mouse
= event
->where
;
909 GlobalToLocal(&mouse
);
910 part
= FindControl(mouse
, window
, &control
);
911 if (control
!= NULL
) {
912 mc
= (union macctrl
*)GetControlReference(control
);
913 if (mac_gestalts
.apprvers
>= 0x100) {
914 if (GetControlFeatures(control
, &features
) == noErr
&&
915 (features
& kControlSupportsFocus
) &&
916 (features
& kControlGetsFocusOnClick
))
917 SetKeyboardFocus(window
, control
, part
);
918 trackresult
= HandleControlClick(control
, mouse
, event
->modifiers
,
919 (ControlActionUPP
)-1);
921 #if !TARGET_API_MAC_CARBON
922 if (mc
->generic
.type
== MACCTRL_EDITBOX
&&
923 control
== mc
->editbox
.tbctrl
) {
924 TEHandle te
= (TEHandle
)(*control
)->contrlData
;
926 macctrl_setfocus(mcs
, mc
);
927 TEClick(mouse
, !!(event
->modifiers
& shiftKey
), te
);
931 trackresult
= TrackControl(control
, mouse
, (ControlActionUPP
)-1);
933 switch (mc
->generic
.type
) {
935 if (trackresult
!= 0) {
936 for (i
= 0; i
< mc
->generic
.ctrl
->radio
.nbuttons
; i
++)
937 if (mc
->radio
.tbctrls
[i
] == control
)
938 SetControlValue(mc
->radio
.tbctrls
[i
],
939 kControlRadioButtonCheckedValue
);
941 SetControlValue(mc
->radio
.tbctrls
[i
],
942 kControlRadioButtonUncheckedValue
);
943 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
946 case MACCTRL_CHECKBOX
:
947 if (trackresult
!= 0) {
948 SetControlValue(control
, !GetControlValue(control
));
949 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
953 if (trackresult
!= 0)
954 ctrlevent(mcs
, mc
, EVENT_ACTION
);
957 ctrlevent(mcs
, mc
, EVENT_SELCHANGE
);
965 void macctrl_key(WindowPtr window
, EventRecord
*event
)
968 struct macctrls
*mcs
= mac_winctrls(window
);
971 if (mac_gestalts
.apprvers
>= 0x100) {
972 if (GetKeyboardFocus(window
, &control
) == noErr
&& control
!= NULL
) {
973 HandleControlKey(control
, (event
->message
& keyCodeMask
) >> 8,
974 event
->message
& charCodeMask
, event
->modifiers
);
975 mc
= (union macctrl
*)GetControlReference(control
);
976 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
979 #if !TARGET_API_MAC_CARBON
983 if (mcs
->focus
!= NULL
) {
985 switch (mc
->generic
.type
) {
986 case MACCTRL_EDITBOX
:
987 te
= (TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
;
988 TEKey(event
->message
& charCodeMask
, te
);
989 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
997 void macctrl_update(WindowPtr window
)
999 #if TARGET_API_MAC_CARBON
1005 BeginUpdate(window
);
1007 SetPort((GrafPtr
)GetWindowPort(window
));
1008 if (mac_gestalts
.apprvers
>= 0x101) {
1009 #if TARGET_API_MAC_CARBON
1010 GetPortBounds(GetWindowPort(window
), &rect
);
1012 rect
= window
->portRect
;
1014 InsetRect(&rect
, -1, -1);
1015 DrawThemeModelessDialogFrame(&rect
, mac_frontwindow() == window ?
1016 kThemeStateActive
: kThemeStateInactive
);
1018 #if TARGET_API_MAC_CARBON
1020 GetPortVisibleRegion(GetWindowPort(window
), visrgn
);
1021 UpdateControls(window
, visrgn
);
1024 UpdateControls(window
, window
->visRgn
);
1030 #if TARGET_API_MAC_CARBON
1031 #define EnableItem EnableMenuItem
1032 #define DisableItem DisableMenuItem
1034 void macctrl_adjustmenus(WindowPtr window
)
1038 menu
= GetMenuHandle(mFile
);
1039 DisableItem(menu
, iSave
); /* XXX enable if modified */
1040 EnableItem(menu
, iSaveAs
);
1041 EnableItem(menu
, iDuplicate
);
1043 menu
= GetMenuHandle(mEdit
);
1044 DisableItem(menu
, 0);
1047 void macctrl_close(WindowPtr window
)
1049 struct macctrls
*mcs
= mac_winctrls(window
);
1053 * Mostly, we don't bother disposing of the Toolbox controls,
1054 * since that will happen automatically when the window is
1055 * disposed of. Popup menus are an exception, because we have to
1056 * dispose of the menu ourselves, and doing that while the control
1057 * still holds a reference to it seems rude.
1059 while ((mc
= index234(mcs
->byctrl
, 0)) != NULL
) {
1060 if (mc
->generic
.privdata
!= NULL
&& mc
->generic
.freeprivdata
)
1061 sfree(mc
->generic
.privdata
);
1062 switch (mc
->generic
.type
) {
1064 DisposeControl(mc
->popup
.tbctrl
);
1065 DeleteMenu(mc
->popup
.menuid
);
1066 DisposeMenu(mc
->popup
.menu
);
1069 del234(mcs
->byctrl
, mc
);
1073 freetree234(mcs
->byctrl
);
1079 void dlg_update_start(union control
*ctrl
, void *dlg
)
1085 void dlg_update_done(union control
*ctrl
, void *dlg
)
1091 void dlg_set_focus(union control
*ctrl
, void *dlg
)
1094 if (mac_gestalts
.apprvers
>= 0x100) {
1095 /* Use SetKeyboardFocus() */
1097 /* Do our own mucking around */
1101 union control
*dlg_last_focused(union control
*ctrl
, void *dlg
)
1107 void dlg_beep(void *dlg
)
1113 void dlg_error_msg(void *dlg
, char *msg
)
1117 c2pstrcpy(pmsg
, msg
);
1118 ParamText(pmsg
, NULL
, NULL
, NULL
);
1119 StopAlert(128, NULL
);
1122 void dlg_end(void *dlg
, int value
)
1124 struct macctrls
*mcs
= dlg
;
1126 if (mcs
->end
!= NULL
)
1127 (*mcs
->end
)(mcs
->window
, value
);
1130 void dlg_refresh(union control
*ctrl
, void *dlg
)
1132 struct macctrls
*mcs
= dlg
;
1137 mc
= findbyctrl(mcs
, ctrl
);
1139 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
1142 void *dlg_get_privdata(union control
*ctrl
, void *dlg
)
1144 struct macctrls
*mcs
= dlg
;
1145 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1148 return mc
->generic
.privdata
;
1151 void dlg_set_privdata(union control
*ctrl
, void *dlg
, void *ptr
)
1153 struct macctrls
*mcs
= dlg
;
1154 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1157 mc
->generic
.privdata
= ptr
;
1158 mc
->generic
.freeprivdata
= FALSE
;
1161 void *dlg_alloc_privdata(union control
*ctrl
, void *dlg
, size_t size
)
1163 struct macctrls
*mcs
= dlg
;
1164 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1167 mc
->generic
.privdata
= smalloc(size
);
1168 mc
->generic
.freeprivdata
= TRUE
;
1169 return mc
->generic
.privdata
;
1174 * Radio Button control
1177 void dlg_radiobutton_set(union control
*ctrl
, void *dlg
, int whichbutton
)
1179 struct macctrls
*mcs
= dlg
;
1180 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1184 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
1185 if (i
== whichbutton
)
1186 SetControlValue(mc
->radio
.tbctrls
[i
],
1187 kControlRadioButtonCheckedValue
);
1189 SetControlValue(mc
->radio
.tbctrls
[i
],
1190 kControlRadioButtonUncheckedValue
);
1195 int dlg_radiobutton_get(union control
*ctrl
, void *dlg
)
1197 struct macctrls
*mcs
= dlg
;
1198 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1202 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
1203 if (GetControlValue(mc
->radio
.tbctrls
[i
]) ==
1204 kControlRadioButtonCheckedValue
)
1215 void dlg_checkbox_set(union control
*ctrl
, void *dlg
, int checked
)
1217 struct macctrls
*mcs
= dlg
;
1218 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1221 SetControlValue(mc
->checkbox
.tbctrl
,
1222 checked ? kControlCheckBoxCheckedValue
:
1223 kControlCheckBoxUncheckedValue
);
1226 int dlg_checkbox_get(union control
*ctrl
, void *dlg
)
1228 struct macctrls
*mcs
= dlg
;
1229 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1232 return GetControlValue(mc
->checkbox
.tbctrl
);
1240 void dlg_editbox_set(union control
*ctrl
, void *dlg
, char const *text
)
1242 struct macctrls
*mcs
= dlg
;
1243 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1247 assert(mc
->generic
.type
== MACCTRL_EDITBOX
);
1249 SetPort((GrafPtr
)(GetWindowPort(mcs
->window
)));
1250 if (mac_gestalts
.apprvers
>= 0x100)
1251 SetControlData(mc
->editbox
.tbctrl
, kControlEntireControl
,
1252 ctrl
->editbox
.password ?
1253 kControlEditTextPasswordTag
:
1254 kControlEditTextTextTag
,
1255 strlen(text
), text
);
1256 #if !TARGET_API_MAC_CARBON
1258 TESetText(text
, strlen(text
),
1259 (TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
);
1261 DrawOneControl(mc
->editbox
.tbctrl
);
1265 void dlg_editbox_get(union control
*ctrl
, void *dlg
, char *buffer
, int length
)
1267 struct macctrls
*mcs
= dlg
;
1268 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1272 assert(mc
->generic
.type
== MACCTRL_EDITBOX
);
1273 if (mac_gestalts
.apprvers
>= 0x100) {
1274 if (GetControlData(mc
->editbox
.tbctrl
, kControlEntireControl
,
1275 ctrl
->editbox
.password ?
1276 kControlEditTextPasswordTag
:
1277 kControlEditTextTextTag
,
1278 length
- 1, buffer
, &olen
) != noErr
)
1280 if (olen
> length
- 1)
1283 #if !TARGET_API_MAC_CARBON
1285 TEHandle te
= (TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
;
1287 olen
= (*te
)->teLength
;
1288 if (olen
> length
- 1)
1290 memcpy(buffer
, *(*te
)->hText
, olen
);
1293 buffer
[olen
] = '\0';
1294 fprintf(stderr
, "dlg_editbox_get: %s\n", buffer
);
1302 static void dlg_macpopup_clear(union control
*ctrl
, void *dlg
)
1304 struct macctrls
*mcs
= dlg
;
1305 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1306 MenuRef menu
= mc
->popup
.menu
;
1309 fprintf(stderr
, " popup_clear\n");
1310 n
= CountMenuItems(menu
);
1311 for (i
= 0; i
< n
; i
++)
1312 DeleteMenuItem(menu
, n
- i
);
1314 sfree(mc
->popup
.ids
);
1315 mc
->popup
.ids
= NULL
;
1316 SetControlMaximum(mc
->popup
.tbctrl
, CountMenuItems(menu
));
1319 void dlg_listbox_clear(union control
*ctrl
, void *dlg
)
1322 if (ctrl
->listbox
.height
== 0)
1323 dlg_macpopup_clear(ctrl
, dlg
);
1326 static void dlg_macpopup_del(union control
*ctrl
, void *dlg
, int index
)
1328 struct macctrls
*mcs
= dlg
;
1329 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1330 MenuRef menu
= mc
->popup
.menu
;
1332 fprintf(stderr
, " popup_del %d\n", index
);
1333 DeleteMenuItem(menu
, index
+ 1);
1334 if (mc
->popup
.ids
!= NULL
)
1335 memcpy(mc
->popup
.ids
+ index
, mc
->popup
.ids
+ index
+ 1,
1336 (mc
->popup
.nids
- index
- 1) * sizeof(*mc
->popup
.ids
));
1337 SetControlMaximum(mc
->popup
.tbctrl
, CountMenuItems(menu
));
1340 void dlg_listbox_del(union control
*ctrl
, void *dlg
, int index
)
1343 if (ctrl
->listbox
.height
== 0)
1344 dlg_macpopup_del(ctrl
, dlg
, index
);
1347 static void dlg_macpopup_add(union control
*ctrl
, void *dlg
, char const *text
)
1349 struct macctrls
*mcs
= dlg
;
1350 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1351 MenuRef menu
= mc
->popup
.menu
;
1354 fprintf(stderr
, " popup_add %s\n", text
);
1355 assert(text
[0] != '\0');
1356 c2pstrcpy(itemstring
, text
);
1357 AppendMenu(menu
, "\pdummy");
1358 SetMenuItemText(menu
, CountMenuItems(menu
), itemstring
);
1359 SetControlMaximum(mc
->popup
.tbctrl
, CountMenuItems(menu
));
1362 void dlg_listbox_add(union control
*ctrl
, void *dlg
, char const *text
)
1365 if (ctrl
->listbox
.height
== 0)
1366 dlg_macpopup_add(ctrl
, dlg
, text
);
1369 static void dlg_macpopup_addwithid(union control
*ctrl
, void *dlg
,
1370 char const *text
, int id
)
1372 struct macctrls
*mcs
= dlg
;
1373 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1374 MenuRef menu
= mc
->popup
.menu
;
1377 fprintf(stderr
, " popup_addwthindex %s, %d\n", text
, id
);
1378 dlg_macpopup_add(ctrl
, dlg
, text
);
1379 index
= CountMenuItems(menu
) - 1;
1380 if (mc
->popup
.nids
<= index
) {
1381 mc
->popup
.nids
= index
+ 1;
1382 mc
->popup
.ids
= sresize(mc
->popup
.ids
, mc
->popup
.nids
, int);
1384 mc
->popup
.ids
[index
] = id
;
1387 void dlg_listbox_addwithid(union control
*ctrl
, void *dlg
,
1388 char const *text
, int id
)
1391 if (ctrl
->listbox
.height
== 0)
1392 dlg_macpopup_addwithid(ctrl
, dlg
, text
, id
);
1395 int dlg_listbox_getid(union control
*ctrl
, void *dlg
, int index
)
1397 struct macctrls
*mcs
= dlg
;
1398 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1400 if (ctrl
->listbox
.height
== 0) {
1401 assert(mc
->popup
.ids
!= NULL
&& mc
->popup
.nids
> index
);
1402 return mc
->popup
.ids
[index
];
1407 int dlg_listbox_index(union control
*ctrl
, void *dlg
)
1409 struct macctrls
*mcs
= dlg
;
1410 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1412 if (ctrl
->listbox
.height
== 0)
1413 return GetControlValue(mc
->popup
.tbctrl
) - 1;
1417 int dlg_listbox_issel(union control
*ctrl
, void *dlg
, int index
)
1419 struct macctrls
*mcs
= dlg
;
1420 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1422 if (ctrl
->listbox
.height
== 0)
1423 return GetControlValue(mc
->popup
.tbctrl
) - 1 == index
;
1427 void dlg_listbox_select(union control
*ctrl
, void *dlg
, int index
)
1429 struct macctrls
*mcs
= dlg
;
1430 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1432 if (ctrl
->listbox
.height
== 0)
1433 SetControlValue(mc
->popup
.tbctrl
, index
+ 1);
1441 void dlg_text_set(union control
*ctrl
, void *dlg
, char const *text
)
1443 struct macctrls
*mcs
= dlg
;
1444 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1447 if (mac_gestalts
.apprvers
>= 0x100)
1448 SetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
1449 kControlStaticTextTextTag
, strlen(text
), text
);
1450 #if !TARGET_API_MAC_CARBON
1452 TESetText(text
, strlen(text
),
1453 (TEHandle
)(*mc
->text
.tbctrl
)->contrlData
);
1459 * File Selector control
1462 void dlg_filesel_set(union control
*ctrl
, void *dlg
, Filename fn
)
1467 void dlg_filesel_get(union control
*ctrl
, void *dlg
, Filename
*fn
)
1474 * Font Selector control
1477 void dlg_fontsel_set(union control
*ctrl
, void *dlg
, FontSpec fn
)
1482 void dlg_fontsel_get(union control
*ctrl
, void *dlg
, FontSpec
*fn
)
1489 * Printer enumeration
1492 printer_enum
*printer_start_enum(int *nprinters
)
1499 char *printer_get_name(printer_enum
*pe
, int thing
)
1505 void printer_finish_enum(printer_enum
*pe
)
1512 * Colour selection stuff
1515 void dlg_coloursel_start(union control
*ctrl
, void *dlg
,
1516 int r
, int g
, int b
)
1521 int dlg_coloursel_results(union control
*ctrl
, void *dlg
,
1522 int *r
, int *g
, int *b
)
1530 * c-file-style: "simon"