1 /* $Id: macctrls.c,v 1.29 2003/04/05 18:00:46 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
{
66 /* Template from which this was generated */
68 /* Next control in this panel */
74 struct macctrl_generic generic
;
78 struct macctrl_generic generic
;
83 struct macctrl_generic generic
;
88 struct macctrl_generic generic
;
92 struct macctrl_generic generic
;
97 struct macctrl_generic generic
;
106 struct mac_layoutstate
{
109 unsigned int panelnum
;
112 #define ctrlevent(mcs, mc, event) do { \
113 if ((mc)->generic.ctrl->generic.handler != NULL) \
114 (*(mc)->generic.ctrl->generic.handler)((mc)->generic.ctrl, (mcs),\
115 (mcs)->data, (event)); \
118 #define findbyctrl(mcs, ctrl) \
119 find234((mcs)->byctrl, (ctrl), macctrl_cmp_byctrl_find)
121 static void macctrl_layoutset(struct mac_layoutstate
*, struct controlset
*,
122 WindowPtr
, struct macctrls
*);
123 static void macctrl_switchtopanel(struct macctrls
*, unsigned int);
124 static void macctrl_setfocus(struct macctrls
*, union macctrl
*);
125 static void macctrl_text(struct macctrls
*, WindowPtr
,
126 struct mac_layoutstate
*, union control
*);
127 static void macctrl_editbox(struct macctrls
*, WindowPtr
,
128 struct mac_layoutstate
*, union control
*);
129 static void macctrl_radio(struct macctrls
*, WindowPtr
,
130 struct mac_layoutstate
*, union control
*);
131 static void macctrl_checkbox(struct macctrls
*, WindowPtr
,
132 struct mac_layoutstate
*, union control
*);
133 static void macctrl_button(struct macctrls
*, WindowPtr
,
134 struct mac_layoutstate
*, union control
*);
135 static void macctrl_popup(struct macctrls
*, WindowPtr
,
136 struct mac_layoutstate
*, union control
*);
137 #if !TARGET_API_MAC_CARBON
138 static pascal SInt32
macctrl_sys7_editbox_cdef(SInt16
, ControlRef
,
139 ControlDefProcMessage
, SInt32
);
140 static pascal SInt32
macctrl_sys7_default_cdef(SInt16
, ControlRef
,
141 ControlDefProcMessage
, SInt32
);
144 #if !TARGET_API_MAC_CARBON
146 * This trick enables us to keep all the CDEF code in the main
147 * application, which makes life easier. For details, see
148 * <http://developer.apple.com/technotes/tn/tn2003.html#custom_code_base>.
151 #pragma options align=mac68k
153 short jmpabs
; /* 4EF9 */
154 ControlDefUPP theUPP
;
156 #pragma options align=reset
159 static void macctrl_init()
161 #if !TARGET_API_MAC_CARBON
162 static int inited
= 0;
166 cdef
= (PatchCDEF
)GetResource(kControlDefProcResourceType
, CDEF_EditBox
);
167 (*cdef
)->theUPP
= NewControlDefProc(macctrl_sys7_editbox_cdef
);
168 cdef
= (PatchCDEF
)GetResource(kControlDefProcResourceType
, CDEF_Default
);
169 (*cdef
)->theUPP
= NewControlDefProc(macctrl_sys7_default_cdef
);
175 static int macctrl_cmp_byctrl(void *av
, void *bv
)
177 union macctrl
*a
= (union macctrl
*)av
;
178 union macctrl
*b
= (union macctrl
*)bv
;
180 if (a
->generic
.ctrl
< b
->generic
.ctrl
)
182 else if (a
->generic
.ctrl
> b
->generic
.ctrl
)
188 static int macctrl_cmp_byctrl_find(void *av
, void *bv
)
190 union control
*a
= (union control
*)av
;
191 union macctrl
*b
= (union macctrl
*)bv
;
193 if (a
< b
->generic
.ctrl
)
195 else if (a
> b
->generic
.ctrl
)
201 void macctrl_layoutbox(struct controlbox
*cb
, WindowPtr window
,
202 struct macctrls
*mcs
)
205 struct mac_layoutstate curstate
;
210 #if TARGET_API_MAC_CARBON
211 GetPortBounds(GetWindowPort(window
), &rect
);
213 rect
= window
->portRect
;
215 curstate
.pos
.h
= rect
.left
+ 13;
216 curstate
.pos
.v
= rect
.bottom
- 33;
217 curstate
.width
= rect
.right
- rect
.left
- (13 * 2);
218 if (mac_gestalts
.apprvers
>= 0x100)
219 CreateRootControl(window
, &root
);
220 mcs
->window
= window
;
221 mcs
->byctrl
= newtree234(macctrl_cmp_byctrl
);
223 mcs
->defbutton
= NULL
;
224 mcs
->canbutton
= NULL
;
225 /* Count the number of panels */
227 for (i
= 1; i
< cb
->nctrlsets
; i
++)
228 if (strcmp(cb
->ctrlsets
[i
]->pathname
, cb
->ctrlsets
[i
-1]->pathname
))
230 mcs
->panels
= snewn(mcs
->npanels
, union macctrl
*);
231 memset(mcs
->panels
, 0, sizeof(*mcs
->panels
) * mcs
->npanels
);
232 curstate
.panelnum
= 0;
233 for (i
= 0; i
< cb
->nctrlsets
; i
++) {
234 if (i
> 0 && strcmp(cb
->ctrlsets
[i
]->pathname
,
235 cb
->ctrlsets
[i
-1]->pathname
)) {
236 curstate
.pos
.v
= rect
.top
+ 13;
238 assert(curstate
.panelnum
< mcs
->npanels
);
240 macctrl_layoutset(&curstate
, cb
->ctrlsets
[i
], window
, mcs
);
242 macctrl_switchtopanel(mcs
, 1);
243 /* 14 = proxies, 20 = SSH bugs */
248 static void macctrl_layoutset(struct mac_layoutstate
*curstate
,
249 struct controlset
*s
,
250 WindowPtr window
, struct macctrls
*mcs
)
252 unsigned int i
, j
, ncols
, colstart
;
253 struct mac_layoutstate cols
[MAXCOLS
];
255 fprintf(stderr
, "--- begin set ---\n");
256 fprintf(stderr
, "pathname = %s\n", s
->pathname
);
257 if (s
->boxname
&& *s
->boxname
)
258 fprintf(stderr
, "boxname = %s\n", s
->boxname
);
260 fprintf(stderr
, "boxtitle = %s\n", s
->boxtitle
);
265 for (i
= 0; i
< s
->ncontrols
; i
++) {
266 union control
*ctrl
= s
->ctrls
[i
];
269 colstart
= COLUMN_START(ctrl
->generic
.column
);
270 switch (ctrl
->generic
.type
) {
271 case CTRL_TEXT
: s
= "text"; break;
272 case CTRL_EDITBOX
: s
= "editbox"; break;
273 case CTRL_RADIO
: s
= "radio"; break;
274 case CTRL_CHECKBOX
: s
= "checkbox"; break;
275 case CTRL_BUTTON
: s
= "button"; break;
276 case CTRL_LISTBOX
: s
= "listbox"; break;
277 case CTRL_COLUMNS
: s
= "columns"; break;
278 case CTRL_FILESELECT
: s
= "fileselect"; break;
279 case CTRL_FONTSELECT
: s
= "fontselect"; break;
280 case CTRL_TABDELAY
: s
= "tabdelay"; break;
281 default: s
= "unknown"; break;
283 fprintf(stderr
, " control: %s\n", s
);
284 switch (ctrl
->generic
.type
) {
286 if (ctrl
->columns
.ncols
!= 1) {
287 ncols
= ctrl
->columns
.ncols
;
288 fprintf(stderr
, " split to %d\n", ncols
);
289 assert(ncols
<= MAXCOLS
);
290 for (j
= 0; j
< ncols
; j
++) {
293 cols
[j
].pos
.h
= cols
[j
-1].pos
.h
+ cols
[j
-1].width
+ 6;
295 cols
[j
].width
= curstate
->width
-
296 (cols
[j
].pos
.h
- curstate
->pos
.h
);
298 cols
[j
].width
= (curstate
->width
+ 6) *
299 ctrl
->columns
.percentages
[j
] / 100 - 6;
302 fprintf(stderr
, " join\n");
303 for (j
= 0; j
< ncols
; j
++)
304 if (cols
[j
].pos
.v
> cols
[0].pos
.v
)
305 cols
[0].pos
.v
= cols
[j
].pos
.v
;
306 cols
[0].width
= curstate
->width
;
311 macctrl_text(mcs
, window
, &cols
[colstart
], ctrl
);
314 macctrl_editbox(mcs
, window
, &cols
[colstart
], ctrl
);
317 macctrl_radio(mcs
, window
, &cols
[colstart
], ctrl
);
320 macctrl_checkbox(mcs
, window
, &cols
[colstart
], ctrl
);
323 macctrl_button(mcs
, window
, &cols
[colstart
], ctrl
);
326 if (ctrl
->listbox
.height
== 0)
327 macctrl_popup(mcs
, window
, &cols
[colstart
], ctrl
);
331 for (j
= 0; j
< ncols
; j
++)
332 if (cols
[j
].pos
.v
> curstate
->pos
.v
)
333 curstate
->pos
.v
= cols
[j
].pos
.v
;
336 static void macctrl_switchtopanel(struct macctrls
*mcs
, unsigned int which
)
341 #define hideshow(c) do { \
342 if (i == which) ShowControl(c); else HideControl(c); \
345 mcs
->curpanel
= which
;
346 /* Panel 0 is special and always visible. */
347 for (i
= 1; i
< mcs
->npanels
; i
++)
348 for (mc
= mcs
->panels
[i
]; mc
!= NULL
; mc
= mc
->generic
.next
) {
349 #if !TARGET_API_MAC_CARBON
350 if (mcs
->focus
== mc
)
351 macctrl_setfocus(mcs
, NULL
);
353 switch (mc
->generic
.type
) {
355 hideshow(mc
->text
.tbctrl
);
357 case MACCTRL_EDITBOX
:
358 hideshow(mc
->editbox
.tbctrl
);
359 if (mc
->editbox
.tblabel
!= NULL
)
360 hideshow(mc
->editbox
.tblabel
);
363 for (j
= 0; j
< mc
->generic
.ctrl
->radio
.nbuttons
; j
++)
364 hideshow(mc
->radio
.tbctrls
[j
]);
365 if (mc
->radio
.tblabel
!= NULL
)
366 hideshow(mc
->radio
.tblabel
);
368 case MACCTRL_CHECKBOX
:
369 hideshow(mc
->checkbox
.tbctrl
);
372 hideshow(mc
->button
.tbctrl
);
375 hideshow(mc
->popup
.tbctrl
);
381 #if !TARGET_API_MAC_CARBON
383 * System 7 focus manipulation
385 static void macctrl_defocus(union macctrl
*mc
)
388 assert(mac_gestalts
.apprvers
< 0x100);
389 switch (mc
->generic
.type
) {
390 case MACCTRL_EDITBOX
:
391 TEDeactivate((TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
);
396 static void macctrl_enfocus(union macctrl
*mc
)
399 assert(mac_gestalts
.apprvers
< 0x100);
400 switch (mc
->generic
.type
) {
401 case MACCTRL_EDITBOX
:
402 TEActivate((TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
);
407 static void macctrl_setfocus(struct macctrls
*mcs
, union macctrl
*mc
)
410 if (mcs
->focus
!= NULL
)
411 macctrl_defocus(mcs
->focus
);
418 static void macctrl_text(struct macctrls
*mcs
, WindowPtr window
,
419 struct mac_layoutstate
*curstate
,
422 union macctrl
*mc
= snew(union macctrl
);
426 assert(ctrl
->text
.label
!= NULL
);
427 fprintf(stderr
, " label = %s\n", ctrl
->text
.label
);
428 mc
->generic
.type
= MACCTRL_TEXT
;
429 mc
->generic
.ctrl
= ctrl
;
430 mc
->generic
.privdata
= NULL
;
431 bounds
.left
= curstate
->pos
.h
;
432 bounds
.right
= bounds
.left
+ curstate
->width
;
433 bounds
.top
= curstate
->pos
.v
;
434 bounds
.bottom
= bounds
.top
+ 16;
435 if (mac_gestalts
.apprvers
>= 0x100) {
438 mc
->text
.tbctrl
= NewControl(window
, &bounds
, NULL
, TRUE
, 0, 0, 0,
439 kControlStaticTextProc
, (long)mc
);
440 SetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
441 kControlStaticTextTextTag
,
442 strlen(ctrl
->text
.label
), ctrl
->text
.label
);
443 GetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
444 kControlStaticTextTextHeightTag
,
445 sizeof(height
), &height
, &olen
);
447 #if !TARGET_API_MAC_CARBON
451 mc
->text
.tbctrl
= NewControl(window
, &bounds
, NULL
, TRUE
, 0, 0, 0,
452 SYS7_TEXT_PROC
, (long)mc
);
453 te
= (TEHandle
)(*mc
->text
.tbctrl
)->contrlData
;
454 TESetText(ctrl
->text
.label
, strlen(ctrl
->text
.label
), te
);
455 height
= TEGetHeight(1, (*te
)->nLines
, te
);
458 fprintf(stderr
, " height = %d\n", height
);
459 SizeControl(mc
->text
.tbctrl
, curstate
->width
, height
);
460 curstate
->pos
.v
+= height
+ 6;
461 add234(mcs
->byctrl
, mc
);
462 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
463 mcs
->panels
[curstate
->panelnum
] = mc
;
466 static void macctrl_editbox(struct macctrls
*mcs
, WindowPtr window
,
467 struct mac_layoutstate
*curstate
,
470 union macctrl
*mc
= snew(union macctrl
);
471 Rect lbounds
, bounds
;
473 if (ctrl
->editbox
.label
!= NULL
)
474 fprintf(stderr
, " label = %s\n", ctrl
->editbox
.label
);
475 fprintf(stderr
, " percentwidth = %d\n", ctrl
->editbox
.percentwidth
);
476 if (ctrl
->editbox
.password
) fprintf(stderr
, " password\n");
477 if (ctrl
->editbox
.has_list
) fprintf(stderr
, " has list\n");
478 mc
->generic
.type
= MACCTRL_EDITBOX
;
479 mc
->generic
.ctrl
= ctrl
;
480 mc
->generic
.privdata
= NULL
;
481 lbounds
.left
= curstate
->pos
.h
;
482 lbounds
.top
= curstate
->pos
.v
;
483 if (ctrl
->editbox
.percentwidth
== 100) {
484 if (ctrl
->editbox
.label
!= NULL
) {
485 lbounds
.right
= lbounds
.left
+ curstate
->width
;
486 lbounds
.bottom
= lbounds
.top
+ 16;
487 curstate
->pos
.v
+= 18;
489 bounds
.left
= curstate
->pos
.h
;
490 bounds
.right
= bounds
.left
+ curstate
->width
;
492 lbounds
.right
= lbounds
.left
+
493 curstate
->width
* (100 - ctrl
->editbox
.percentwidth
) / 100;
494 lbounds
.bottom
= lbounds
.top
+ 22;
495 bounds
.left
= lbounds
.right
;
496 bounds
.right
= lbounds
.left
+ curstate
->width
;
498 bounds
.top
= curstate
->pos
.v
;
499 bounds
.bottom
= bounds
.top
+ 22;
500 if (mac_gestalts
.apprvers
>= 0x100) {
501 if (ctrl
->editbox
.label
== NULL
)
502 mc
->editbox
.tblabel
= NULL
;
504 mc
->editbox
.tblabel
= NewControl(window
, &lbounds
, NULL
, TRUE
,
505 0, 0, 0, kControlStaticTextProc
,
507 SetControlData(mc
->editbox
.tblabel
, kControlEntireControl
,
508 kControlStaticTextTextTag
,
509 strlen(ctrl
->editbox
.label
), ctrl
->editbox
.label
);
511 InsetRect(&bounds
, 3, 3);
512 mc
->editbox
.tbctrl
= NewControl(window
, &bounds
, NULL
, TRUE
, 0, 0, 0,
513 ctrl
->editbox
.password ?
514 kControlEditTextPasswordProc
:
515 kControlEditTextProc
, (long)mc
);
517 #if !TARGET_API_MAC_CARBON
519 if (ctrl
->editbox
.label
== NULL
)
520 mc
->editbox
.tblabel
= NULL
;
522 mc
->editbox
.tblabel
= NewControl(window
, &lbounds
, NULL
, TRUE
,
523 0, 0, 0, SYS7_TEXT_PROC
,
525 TESetText(ctrl
->editbox
.label
, strlen(ctrl
->editbox
.label
),
526 (TEHandle
)(*mc
->editbox
.tblabel
)->contrlData
);
528 mc
->editbox
.tbctrl
= NewControl(window
, &bounds
, NULL
, TRUE
, 0, 0, 0,
529 SYS7_EDITBOX_PROC
, (long)mc
);
532 curstate
->pos
.v
+= 28;
533 add234(mcs
->byctrl
, mc
);
534 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
535 mcs
->panels
[curstate
->panelnum
] = mc
;
536 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
539 #if !TARGET_API_MAC_CARBON
540 static pascal SInt32
macctrl_sys7_editbox_cdef(SInt16 variant
,
542 ControlDefProcMessage msg
,
553 rect
= (*control
)->contrlRect
;
554 if (variant
== SYS7_EDITBOX_VARIANT
)
555 InsetRect(&rect
, 3, 3); /* 2 if it's 20 pixels high */
556 te
= TENew(&rect
, &rect
);
557 ssfs
= GetScriptVariable(smSystemScript
, smScriptSysFondSize
);
558 (*te
)->txSize
= LoWord(ssfs
);
559 (*te
)->txFont
= HiWord(ssfs
);
560 (*control
)->contrlData
= (Handle
)te
;
563 TEDispose((TEHandle
)(*control
)->contrlData
);
566 if ((*control
)->contrlVis
) {
567 rect
= (*control
)->contrlRect
;
568 if (variant
== SYS7_EDITBOX_VARIANT
) {
571 InsetRect(&rect
, 3, 3);
573 (*(TEHandle
)(*control
)->contrlData
)->viewRect
= rect
;
574 TEUpdate(&rect
, (TEHandle
)(*control
)->contrlData
);
578 if (variant
== SYS7_TEXT_VARIANT
)
579 return kControlNoPart
;
580 mouse
.h
= LoWord(param
);
581 mouse
.v
= HiWord(param
);
582 rect
= (*control
)->contrlRect
;
583 InsetRect(&rect
, 3, 3);
584 return PtInRect(mouse
, &rect
) ? kControlEditTextPart
: kControlNoPart
;
586 if (param
& (1 << 31)) {
592 rgn
= (RgnHandle
)param
;
593 RectRgn(rgn
, &(*control
)->contrlRect
);
597 rgn
= (RgnHandle
)param
;
606 static void macctrl_radio(struct macctrls
*mcs
, WindowPtr window
,
607 struct mac_layoutstate
*curstate
,
610 union macctrl
*mc
= snew(union macctrl
);
613 unsigned int i
, colwidth
;
615 if (ctrl
->radio
.label
!= NULL
)
616 fprintf(stderr
, " label = %s\n", ctrl
->radio
.label
);
617 mc
->generic
.type
= MACCTRL_RADIO
;
618 mc
->generic
.ctrl
= ctrl
;
619 mc
->generic
.privdata
= NULL
;
620 mc
->radio
.tbctrls
= snewn(ctrl
->radio
.nbuttons
, ControlRef
);
621 colwidth
= (curstate
->width
+ 13) / ctrl
->radio
.ncolumns
;
622 bounds
.top
= curstate
->pos
.v
;
623 bounds
.bottom
= bounds
.top
+ 16;
624 bounds
.left
= curstate
->pos
.h
;
625 bounds
.right
= bounds
.left
+ curstate
->width
;
626 if (ctrl
->radio
.label
== NULL
)
627 mc
->radio
.tblabel
= NULL
;
629 if (mac_gestalts
.apprvers
>= 0x100) {
630 mc
->radio
.tblabel
= NewControl(window
, &bounds
, NULL
, TRUE
,
631 0, 0, 0, kControlStaticTextProc
,
633 SetControlData(mc
->radio
.tblabel
, kControlEntireControl
,
634 kControlStaticTextTextTag
,
635 strlen(ctrl
->radio
.label
), ctrl
->radio
.label
);
637 #if !TARGET_API_MAC_CARBON
639 mc
->radio
.tblabel
= NewControl(window
, &bounds
, NULL
, TRUE
,
640 0, 0, 0, SYS7_TEXT_PROC
, (long)mc
);
641 TESetText(ctrl
->radio
.label
, strlen(ctrl
->radio
.label
),
642 (TEHandle
)(*mc
->radio
.tblabel
)->contrlData
);
645 curstate
->pos
.v
+= 18;
647 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
648 fprintf(stderr
, " button = %s\n", ctrl
->radio
.buttons
[i
]);
649 bounds
.top
= curstate
->pos
.v
- 2;
650 bounds
.bottom
= bounds
.top
+ 18;
651 bounds
.left
= curstate
->pos
.h
+ colwidth
* (i
% ctrl
->radio
.ncolumns
);
652 if (i
== ctrl
->radio
.nbuttons
- 1 ||
653 i
% ctrl
->radio
.ncolumns
== ctrl
->radio
.ncolumns
- 1) {
654 bounds
.right
= curstate
->pos
.h
+ curstate
->width
;
655 curstate
->pos
.v
+= 18;
657 bounds
.right
= bounds
.left
+ colwidth
- 13;
658 c2pstrcpy(title
, ctrl
->radio
.buttons
[i
]);
659 mc
->radio
.tbctrls
[i
] = NewControl(window
, &bounds
, title
, TRUE
,
660 0, 0, 1, radioButProc
, (long)mc
);
662 curstate
->pos
.v
+= 4;
663 add234(mcs
->byctrl
, mc
);
664 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
665 mcs
->panels
[curstate
->panelnum
] = mc
;
666 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
669 static void macctrl_checkbox(struct macctrls
*mcs
, WindowPtr window
,
670 struct mac_layoutstate
*curstate
,
673 union macctrl
*mc
= snew(union macctrl
);
677 assert(ctrl
->checkbox
.label
!= NULL
);
678 fprintf(stderr
, " label = %s\n", ctrl
->checkbox
.label
);
679 mc
->generic
.type
= MACCTRL_CHECKBOX
;
680 mc
->generic
.ctrl
= ctrl
;
681 mc
->generic
.privdata
= NULL
;
682 bounds
.left
= curstate
->pos
.h
;
683 bounds
.right
= bounds
.left
+ curstate
->width
;
684 bounds
.top
= curstate
->pos
.v
;
685 bounds
.bottom
= bounds
.top
+ 16;
686 c2pstrcpy(title
, ctrl
->checkbox
.label
);
687 mc
->checkbox
.tbctrl
= NewControl(window
, &bounds
, title
, TRUE
, 0, 0, 1,
688 checkBoxProc
, (long)mc
);
689 add234(mcs
->byctrl
, mc
);
690 curstate
->pos
.v
+= 22;
691 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
692 mcs
->panels
[curstate
->panelnum
] = mc
;
693 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
696 static void macctrl_button(struct macctrls
*mcs
, WindowPtr window
,
697 struct mac_layoutstate
*curstate
,
700 union macctrl
*mc
= snew(union macctrl
);
704 assert(ctrl
->button
.label
!= NULL
);
705 fprintf(stderr
, " label = %s\n", ctrl
->button
.label
);
706 if (ctrl
->button
.isdefault
)
707 fprintf(stderr
, " is default\n");
708 mc
->generic
.type
= MACCTRL_BUTTON
;
709 mc
->generic
.ctrl
= ctrl
;
710 mc
->generic
.privdata
= NULL
;
711 bounds
.left
= curstate
->pos
.h
;
712 bounds
.right
= bounds
.left
+ curstate
->width
;
713 bounds
.top
= curstate
->pos
.v
;
714 bounds
.bottom
= bounds
.top
+ 20;
715 c2pstrcpy(title
, ctrl
->button
.label
);
716 mc
->button
.tbctrl
= NewControl(window
, &bounds
, title
, TRUE
, 0, 0, 1,
717 pushButProc
, (long)mc
);
718 mc
->button
.tbring
= NULL
;
719 if (mac_gestalts
.apprvers
>= 0x100) {
720 Boolean isdefault
= ctrl
->button
.isdefault
;
722 SetControlData(mc
->button
.tbctrl
, kControlEntireControl
,
723 kControlPushButtonDefaultTag
,
724 sizeof(isdefault
), &isdefault
);
725 } else if (ctrl
->button
.isdefault
) {
726 InsetRect(&bounds
, -4, -4);
727 mc
->button
.tbring
= NewControl(window
, &bounds
, title
, TRUE
, 0, 0, 1,
728 SYS7_DEFAULT_PROC
, (long)mc
);
730 if (mac_gestalts
.apprvers
>= 0x110) {
731 Boolean iscancel
= ctrl
->button
.iscancel
;
733 SetControlData(mc
->button
.tbctrl
, kControlEntireControl
,
734 kControlPushButtonCancelTag
,
735 sizeof(iscancel
), &iscancel
);
737 if (ctrl
->button
.isdefault
)
739 if (ctrl
->button
.iscancel
)
741 add234(mcs
->byctrl
, mc
);
742 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
743 mcs
->panels
[curstate
->panelnum
] = mc
;
744 curstate
->pos
.v
+= 26;
747 #if !TARGET_API_MAC_CARBON
748 static pascal SInt32
macctrl_sys7_default_cdef(SInt16 variant
,
750 ControlDefProcMessage msg
,
760 if ((*control
)->contrlVis
) {
761 rect
= (*control
)->contrlRect
;
762 GetPenState(&savestate
);
765 if ((*control
)->contrlHilite
== kControlInactivePart
)
767 oval
= (rect
.bottom
- rect
.top
) / 2 + 2;
768 FrameRoundRect(&rect
, oval
, oval
);
769 SetPenState(&savestate
);
773 if (param
& (1 << 31)) {
779 rgn
= (RgnHandle
)param
;
780 RectRgn(rgn
, &(*control
)->contrlRect
);
784 rgn
= (RgnHandle
)param
;
793 static void macctrl_popup(struct macctrls
*mcs
, WindowPtr window
,
794 struct mac_layoutstate
*curstate
,
797 union macctrl
*mc
= snew(union macctrl
);
800 unsigned int labelwidth
;
801 static int nextmenuid
= MENU_MIN
;
806 * <http://developer.apple.com/qa/tb/tb42.html> explains how to
807 * create a popup menu with dynamic content.
809 assert(ctrl
->listbox
.height
== 0);
810 assert(!ctrl
->listbox
.draglist
);
811 assert(!ctrl
->listbox
.multisel
);
813 if (ctrl
->listbox
.label
!= NULL
)
814 fprintf(stderr
, " label = %s\n", ctrl
->listbox
.label
);
815 fprintf(stderr
, " percentwidth = %d\n", ctrl
->listbox
.percentwidth
);
817 mc
->generic
.type
= MACCTRL_POPUP
;
818 mc
->generic
.ctrl
= ctrl
;
819 mc
->generic
.privdata
= NULL
;
820 c2pstrcpy(title
, ctrl
->button
.label
== NULL ?
"" : ctrl
->button
.label
);
822 /* Find a spare menu ID and create the menu */
823 while (GetMenuHandle(nextmenuid
) != NULL
)
824 if (++nextmenuid
>= MENU_MAX
) nextmenuid
= MENU_MIN
;
825 menuid
= nextmenuid
++;
826 menu
= NewMenu(menuid
, "\pdummy");
827 if (menu
== NULL
) return;
828 mc
->popup
.menu
= menu
;
829 mc
->popup
.menuid
= menuid
;
830 InsertMenu(menu
, kInsertHierarchicalMenu
);
832 /* The menu starts off empty */
834 mc
->popup
.ids
= NULL
;
836 bounds
.left
= curstate
->pos
.h
;
837 bounds
.right
= bounds
.left
+ curstate
->width
;
838 bounds
.top
= curstate
->pos
.v
;
839 bounds
.bottom
= bounds
.top
+ 20;
840 /* XXX handle percentwidth == 100 */
841 labelwidth
= curstate
->width
* (100 - ctrl
->listbox
.percentwidth
) / 100;
842 mc
->popup
.tbctrl
= NewControl(window
, &bounds
, title
, TRUE
,
843 popupTitleLeftJust
, menuid
, labelwidth
,
844 popupMenuProc
+ popupFixedWidth
, (long)mc
);
845 add234(mcs
->byctrl
, mc
);
846 curstate
->pos
.v
+= 26;
847 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
848 mcs
->panels
[curstate
->panelnum
] = mc
;
849 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
853 void macctrl_activate(WindowPtr window
, EventRecord
*event
)
855 struct macctrls
*mcs
= mac_winctrls(window
);
856 Boolean active
= (event
->modifiers
& activeFlag
) != 0;
859 ControlPartCode state
;
863 SetPort((GrafPtr
)GetWindowPort(window
));
864 if (mac_gestalts
.apprvers
>= 0x100)
865 SetThemeWindowBackground(window
, active ?
866 kThemeBrushModelessDialogBackgroundActive
:
867 kThemeBrushModelessDialogBackgroundInactive
,
869 state
= active ? kControlNoPart
: kControlInactivePart
;
870 for (i
= 0; i
<= mcs
->curpanel
; i
+= mcs
->curpanel
)
871 for (mc
= mcs
->panels
[i
]; mc
!= NULL
; mc
= mc
->generic
.next
) {
872 switch (mc
->generic
.type
) {
874 HiliteControl(mc
->text
.tbctrl
, state
);
876 case MACCTRL_EDITBOX
:
877 HiliteControl(mc
->editbox
.tbctrl
, state
);
878 if (mc
->editbox
.tblabel
!= NULL
)
879 HiliteControl(mc
->editbox
.tblabel
, state
);
882 for (j
= 0; j
< mc
->generic
.ctrl
->radio
.nbuttons
; j
++)
883 HiliteControl(mc
->radio
.tbctrls
[j
], state
);
884 if (mc
->radio
.tblabel
!= NULL
)
885 HiliteControl(mc
->radio
.tblabel
, state
);
887 case MACCTRL_CHECKBOX
:
888 HiliteControl(mc
->checkbox
.tbctrl
, state
);
891 HiliteControl(mc
->button
.tbctrl
, state
);
892 if (mc
->button
.tbring
!= NULL
)
893 HiliteControl(mc
->button
.tbring
, state
);
896 HiliteControl(mc
->popup
.tbctrl
, state
);
899 #if !TARGET_API_MAC_CARBON
900 if (mcs
->focus
== mc
) {
911 void macctrl_click(WindowPtr window
, EventRecord
*event
)
914 ControlHandle control
;
915 int part
, trackresult
;
918 struct macctrls
*mcs
= mac_winctrls(window
);
923 SetPort((GrafPtr
)GetWindowPort(window
));
924 mouse
= event
->where
;
925 GlobalToLocal(&mouse
);
926 part
= FindControl(mouse
, window
, &control
);
927 if (control
!= NULL
) {
928 mc
= (union macctrl
*)GetControlReference(control
);
929 if (mac_gestalts
.apprvers
>= 0x100) {
930 if (GetControlFeatures(control
, &features
) == noErr
&&
931 (features
& kControlSupportsFocus
) &&
932 (features
& kControlGetsFocusOnClick
))
933 SetKeyboardFocus(window
, control
, part
);
934 trackresult
= HandleControlClick(control
, mouse
, event
->modifiers
,
935 (ControlActionUPP
)-1);
937 #if !TARGET_API_MAC_CARBON
938 if (mc
->generic
.type
== MACCTRL_EDITBOX
&&
939 control
== mc
->editbox
.tbctrl
) {
940 TEHandle te
= (TEHandle
)(*control
)->contrlData
;
942 macctrl_setfocus(mcs
, mc
);
943 TEClick(mouse
, !!(event
->modifiers
& shiftKey
), te
);
947 trackresult
= TrackControl(control
, mouse
, (ControlActionUPP
)-1);
949 switch (mc
->generic
.type
) {
951 if (trackresult
!= 0) {
952 for (i
= 0; i
< mc
->generic
.ctrl
->radio
.nbuttons
; i
++)
953 if (mc
->radio
.tbctrls
[i
] == control
)
954 SetControlValue(mc
->radio
.tbctrls
[i
],
955 kControlRadioButtonCheckedValue
);
957 SetControlValue(mc
->radio
.tbctrls
[i
],
958 kControlRadioButtonUncheckedValue
);
959 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
962 case MACCTRL_CHECKBOX
:
963 if (trackresult
!= 0) {
964 SetControlValue(control
, !GetControlValue(control
));
965 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
969 if (trackresult
!= 0)
970 ctrlevent(mcs
, mc
, EVENT_ACTION
);
973 ctrlevent(mcs
, mc
, EVENT_SELCHANGE
);
981 void macctrl_key(WindowPtr window
, EventRecord
*event
)
984 struct macctrls
*mcs
= mac_winctrls(window
);
988 switch (event
->message
& charCodeMask
) {
990 case kReturnCharCode
:
991 if (mcs
->defbutton
!= NULL
) {
992 assert(mcs
->defbutton
->generic
.type
== MACCTRL_BUTTON
);
993 HiliteControl(mcs
->defbutton
->button
.tbctrl
, kControlButtonPart
);
995 * I'd like to delay unhilighting the button until after
996 * the event has been processed, but by them the entire
997 * dialgue box might have been destroyed.
1000 HiliteControl(mcs
->defbutton
->button
.tbctrl
, kControlNoPart
);
1001 ctrlevent(mcs
, mcs
->defbutton
, EVENT_ACTION
);
1004 case kEscapeCharCode
:
1005 if (mcs
->canbutton
!= NULL
) {
1006 assert(mcs
->canbutton
->generic
.type
== MACCTRL_BUTTON
);
1007 HiliteControl(mcs
->canbutton
->button
.tbctrl
, kControlButtonPart
);
1009 HiliteControl(mcs
->defbutton
->button
.tbctrl
, kControlNoPart
);
1010 ctrlevent(mcs
, mcs
->canbutton
, EVENT_ACTION
);
1014 if (mac_gestalts
.apprvers
>= 0x100) {
1015 if (GetKeyboardFocus(window
, &control
) == noErr
&& control
!= NULL
) {
1016 HandleControlKey(control
, (event
->message
& keyCodeMask
) >> 8,
1017 event
->message
& charCodeMask
, event
->modifiers
);
1018 mc
= (union macctrl
*)GetControlReference(control
);
1019 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
1022 #if !TARGET_API_MAC_CARBON
1026 if (mcs
->focus
!= NULL
) {
1028 switch (mc
->generic
.type
) {
1029 case MACCTRL_EDITBOX
:
1030 te
= (TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
;
1031 TEKey(event
->message
& charCodeMask
, te
);
1032 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
1040 void macctrl_update(WindowPtr window
)
1042 #if TARGET_API_MAC_CARBON
1048 BeginUpdate(window
);
1050 SetPort((GrafPtr
)GetWindowPort(window
));
1051 if (mac_gestalts
.apprvers
>= 0x101) {
1052 #if TARGET_API_MAC_CARBON
1053 GetPortBounds(GetWindowPort(window
), &rect
);
1055 rect
= window
->portRect
;
1057 InsetRect(&rect
, -1, -1);
1058 DrawThemeModelessDialogFrame(&rect
, mac_frontwindow() == window ?
1059 kThemeStateActive
: kThemeStateInactive
);
1061 #if TARGET_API_MAC_CARBON
1063 GetPortVisibleRegion(GetWindowPort(window
), visrgn
);
1064 UpdateControls(window
, visrgn
);
1067 UpdateControls(window
, window
->visRgn
);
1073 #if TARGET_API_MAC_CARBON
1074 #define EnableItem EnableMenuItem
1075 #define DisableItem DisableMenuItem
1077 void macctrl_adjustmenus(WindowPtr window
)
1081 menu
= GetMenuHandle(mFile
);
1082 DisableItem(menu
, iSave
); /* XXX enable if modified */
1083 EnableItem(menu
, iSaveAs
);
1084 EnableItem(menu
, iDuplicate
);
1086 menu
= GetMenuHandle(mEdit
);
1087 DisableItem(menu
, 0);
1090 void macctrl_close(WindowPtr window
)
1092 struct macctrls
*mcs
= mac_winctrls(window
);
1096 * Mostly, we don't bother disposing of the Toolbox controls,
1097 * since that will happen automatically when the window is
1098 * disposed of. Popup menus are an exception, because we have to
1099 * dispose of the menu ourselves, and doing that while the control
1100 * still holds a reference to it seems rude.
1102 while ((mc
= index234(mcs
->byctrl
, 0)) != NULL
) {
1103 if (mc
->generic
.privdata
!= NULL
&& mc
->generic
.freeprivdata
)
1104 sfree(mc
->generic
.privdata
);
1105 switch (mc
->generic
.type
) {
1107 DisposeControl(mc
->popup
.tbctrl
);
1108 DeleteMenu(mc
->popup
.menuid
);
1109 DisposeMenu(mc
->popup
.menu
);
1112 del234(mcs
->byctrl
, mc
);
1116 freetree234(mcs
->byctrl
);
1122 void dlg_update_start(union control
*ctrl
, void *dlg
)
1128 void dlg_update_done(union control
*ctrl
, void *dlg
)
1134 void dlg_set_focus(union control
*ctrl
, void *dlg
)
1137 if (mac_gestalts
.apprvers
>= 0x100) {
1138 /* Use SetKeyboardFocus() */
1140 /* Do our own mucking around */
1144 union control
*dlg_last_focused(union control
*ctrl
, void *dlg
)
1150 void dlg_beep(void *dlg
)
1156 void dlg_error_msg(void *dlg
, char *msg
)
1160 c2pstrcpy(pmsg
, msg
);
1161 ParamText(pmsg
, NULL
, NULL
, NULL
);
1162 StopAlert(128, NULL
);
1165 void dlg_end(void *dlg
, int value
)
1167 struct macctrls
*mcs
= dlg
;
1169 if (mcs
->end
!= NULL
)
1170 (*mcs
->end
)(mcs
->window
, value
);
1173 void dlg_refresh(union control
*ctrl
, void *dlg
)
1175 struct macctrls
*mcs
= dlg
;
1180 mc
= findbyctrl(mcs
, ctrl
);
1182 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
1185 void *dlg_get_privdata(union control
*ctrl
, void *dlg
)
1187 struct macctrls
*mcs
= dlg
;
1188 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1191 return mc
->generic
.privdata
;
1194 void dlg_set_privdata(union control
*ctrl
, void *dlg
, void *ptr
)
1196 struct macctrls
*mcs
= dlg
;
1197 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1200 mc
->generic
.privdata
= ptr
;
1201 mc
->generic
.freeprivdata
= FALSE
;
1204 void *dlg_alloc_privdata(union control
*ctrl
, void *dlg
, size_t size
)
1206 struct macctrls
*mcs
= dlg
;
1207 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1210 mc
->generic
.privdata
= smalloc(size
);
1211 mc
->generic
.freeprivdata
= TRUE
;
1212 return mc
->generic
.privdata
;
1217 * Radio Button control
1220 void dlg_radiobutton_set(union control
*ctrl
, void *dlg
, int whichbutton
)
1222 struct macctrls
*mcs
= dlg
;
1223 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1227 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
1228 if (i
== whichbutton
)
1229 SetControlValue(mc
->radio
.tbctrls
[i
],
1230 kControlRadioButtonCheckedValue
);
1232 SetControlValue(mc
->radio
.tbctrls
[i
],
1233 kControlRadioButtonUncheckedValue
);
1238 int dlg_radiobutton_get(union control
*ctrl
, void *dlg
)
1240 struct macctrls
*mcs
= dlg
;
1241 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1245 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
1246 if (GetControlValue(mc
->radio
.tbctrls
[i
]) ==
1247 kControlRadioButtonCheckedValue
)
1258 void dlg_checkbox_set(union control
*ctrl
, void *dlg
, int checked
)
1260 struct macctrls
*mcs
= dlg
;
1261 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1264 SetControlValue(mc
->checkbox
.tbctrl
,
1265 checked ? kControlCheckBoxCheckedValue
:
1266 kControlCheckBoxUncheckedValue
);
1269 int dlg_checkbox_get(union control
*ctrl
, void *dlg
)
1271 struct macctrls
*mcs
= dlg
;
1272 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1275 return GetControlValue(mc
->checkbox
.tbctrl
);
1283 void dlg_editbox_set(union control
*ctrl
, void *dlg
, char const *text
)
1285 struct macctrls
*mcs
= dlg
;
1286 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1290 assert(mc
->generic
.type
== MACCTRL_EDITBOX
);
1292 SetPort((GrafPtr
)(GetWindowPort(mcs
->window
)));
1293 if (mac_gestalts
.apprvers
>= 0x100)
1294 SetControlData(mc
->editbox
.tbctrl
, kControlEntireControl
,
1295 ctrl
->editbox
.password ?
1296 kControlEditTextPasswordTag
:
1297 kControlEditTextTextTag
,
1298 strlen(text
), text
);
1299 #if !TARGET_API_MAC_CARBON
1301 TESetText(text
, strlen(text
),
1302 (TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
);
1304 DrawOneControl(mc
->editbox
.tbctrl
);
1308 void dlg_editbox_get(union control
*ctrl
, void *dlg
, char *buffer
, int length
)
1310 struct macctrls
*mcs
= dlg
;
1311 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1315 assert(mc
->generic
.type
== MACCTRL_EDITBOX
);
1316 if (mac_gestalts
.apprvers
>= 0x100) {
1317 if (GetControlData(mc
->editbox
.tbctrl
, kControlEntireControl
,
1318 ctrl
->editbox
.password ?
1319 kControlEditTextPasswordTag
:
1320 kControlEditTextTextTag
,
1321 length
- 1, buffer
, &olen
) != noErr
)
1323 if (olen
> length
- 1)
1326 #if !TARGET_API_MAC_CARBON
1328 TEHandle te
= (TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
;
1330 olen
= (*te
)->teLength
;
1331 if (olen
> length
- 1)
1333 memcpy(buffer
, *(*te
)->hText
, olen
);
1336 buffer
[olen
] = '\0';
1337 fprintf(stderr
, "dlg_editbox_get: %s\n", buffer
);
1345 static void dlg_macpopup_clear(union control
*ctrl
, void *dlg
)
1347 struct macctrls
*mcs
= dlg
;
1348 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1349 MenuRef menu
= mc
->popup
.menu
;
1352 fprintf(stderr
, " popup_clear\n");
1353 n
= CountMenuItems(menu
);
1354 for (i
= 0; i
< n
; i
++)
1355 DeleteMenuItem(menu
, n
- i
);
1357 sfree(mc
->popup
.ids
);
1358 mc
->popup
.ids
= NULL
;
1359 SetControlMaximum(mc
->popup
.tbctrl
, CountMenuItems(menu
));
1362 void dlg_listbox_clear(union control
*ctrl
, void *dlg
)
1365 if (ctrl
->listbox
.height
== 0)
1366 dlg_macpopup_clear(ctrl
, dlg
);
1369 static void dlg_macpopup_del(union control
*ctrl
, void *dlg
, int index
)
1371 struct macctrls
*mcs
= dlg
;
1372 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1373 MenuRef menu
= mc
->popup
.menu
;
1375 fprintf(stderr
, " popup_del %d\n", index
);
1376 DeleteMenuItem(menu
, index
+ 1);
1377 if (mc
->popup
.ids
!= NULL
)
1378 memcpy(mc
->popup
.ids
+ index
, mc
->popup
.ids
+ index
+ 1,
1379 (mc
->popup
.nids
- index
- 1) * sizeof(*mc
->popup
.ids
));
1380 SetControlMaximum(mc
->popup
.tbctrl
, CountMenuItems(menu
));
1383 void dlg_listbox_del(union control
*ctrl
, void *dlg
, int index
)
1386 if (ctrl
->listbox
.height
== 0)
1387 dlg_macpopup_del(ctrl
, dlg
, index
);
1390 static void dlg_macpopup_add(union control
*ctrl
, void *dlg
, char const *text
)
1392 struct macctrls
*mcs
= dlg
;
1393 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1394 MenuRef menu
= mc
->popup
.menu
;
1397 fprintf(stderr
, " popup_add %s\n", text
);
1398 assert(text
[0] != '\0');
1399 c2pstrcpy(itemstring
, text
);
1400 AppendMenu(menu
, "\pdummy");
1401 SetMenuItemText(menu
, CountMenuItems(menu
), itemstring
);
1402 SetControlMaximum(mc
->popup
.tbctrl
, CountMenuItems(menu
));
1405 void dlg_listbox_add(union control
*ctrl
, void *dlg
, char const *text
)
1408 if (ctrl
->listbox
.height
== 0)
1409 dlg_macpopup_add(ctrl
, dlg
, text
);
1412 static void dlg_macpopup_addwithid(union control
*ctrl
, void *dlg
,
1413 char const *text
, int id
)
1415 struct macctrls
*mcs
= dlg
;
1416 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1417 MenuRef menu
= mc
->popup
.menu
;
1420 fprintf(stderr
, " popup_addwthindex %s, %d\n", text
, id
);
1421 dlg_macpopup_add(ctrl
, dlg
, text
);
1422 index
= CountMenuItems(menu
) - 1;
1423 if (mc
->popup
.nids
<= index
) {
1424 mc
->popup
.nids
= index
+ 1;
1425 mc
->popup
.ids
= sresize(mc
->popup
.ids
, mc
->popup
.nids
, int);
1427 mc
->popup
.ids
[index
] = id
;
1430 void dlg_listbox_addwithid(union control
*ctrl
, void *dlg
,
1431 char const *text
, int id
)
1434 if (ctrl
->listbox
.height
== 0)
1435 dlg_macpopup_addwithid(ctrl
, dlg
, text
, id
);
1438 int dlg_listbox_getid(union control
*ctrl
, void *dlg
, int index
)
1440 struct macctrls
*mcs
= dlg
;
1441 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1443 if (ctrl
->listbox
.height
== 0) {
1444 assert(mc
->popup
.ids
!= NULL
&& mc
->popup
.nids
> index
);
1445 return mc
->popup
.ids
[index
];
1450 int dlg_listbox_index(union control
*ctrl
, void *dlg
)
1452 struct macctrls
*mcs
= dlg
;
1453 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1455 if (ctrl
->listbox
.height
== 0)
1456 return GetControlValue(mc
->popup
.tbctrl
) - 1;
1460 int dlg_listbox_issel(union control
*ctrl
, void *dlg
, int index
)
1462 struct macctrls
*mcs
= dlg
;
1463 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1465 if (ctrl
->listbox
.height
== 0)
1466 return GetControlValue(mc
->popup
.tbctrl
) - 1 == index
;
1470 void dlg_listbox_select(union control
*ctrl
, void *dlg
, int index
)
1472 struct macctrls
*mcs
= dlg
;
1473 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1475 if (ctrl
->listbox
.height
== 0)
1476 SetControlValue(mc
->popup
.tbctrl
, index
+ 1);
1484 void dlg_text_set(union control
*ctrl
, void *dlg
, char const *text
)
1486 struct macctrls
*mcs
= dlg
;
1487 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1490 if (mac_gestalts
.apprvers
>= 0x100)
1491 SetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
1492 kControlStaticTextTextTag
, strlen(text
), text
);
1493 #if !TARGET_API_MAC_CARBON
1495 TESetText(text
, strlen(text
),
1496 (TEHandle
)(*mc
->text
.tbctrl
)->contrlData
);
1502 * File Selector control
1505 void dlg_filesel_set(union control
*ctrl
, void *dlg
, Filename fn
)
1510 void dlg_filesel_get(union control
*ctrl
, void *dlg
, Filename
*fn
)
1517 * Font Selector control
1520 void dlg_fontsel_set(union control
*ctrl
, void *dlg
, FontSpec fn
)
1525 void dlg_fontsel_get(union control
*ctrl
, void *dlg
, FontSpec
*fn
)
1532 * Printer enumeration
1535 printer_enum
*printer_start_enum(int *nprinters
)
1542 char *printer_get_name(printer_enum
*pe
, int thing
)
1548 void printer_finish_enum(printer_enum
*pe
)
1555 * Colour selection stuff
1558 void dlg_coloursel_start(union control
*ctrl
, void *dlg
,
1559 int r
, int g
, int b
)
1564 int dlg_coloursel_results(union control
*ctrl
, void *dlg
,
1565 int *r
, int *g
, int *b
)
1573 * c-file-style: "simon"