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>
30 #include <ColorPicker.h>
32 #include <ControlDefinitions.h>
36 #include <Resources.h>
40 #include <TextUtils.h>
41 #include <ToolUtils.h>
53 /* Range of menu IDs for popup menus */
59 struct macctrl_generic
{
70 /* Template from which this was generated */
72 /* Next control in this panel */
78 struct macctrl_generic generic
;
82 struct macctrl_generic generic
;
92 struct macctrl_generic generic
;
97 struct macctrl_generic generic
;
101 struct macctrl_generic generic
;
106 struct macctrl_generic generic
;
113 struct macctrl_generic generic
;
121 struct macctrl_generic generic
;
126 struct mac_layoutstate
{
131 unsigned int panelnum
;
134 #define ctrlevent(mcs, mc, event) do { \
135 if ((mc)->generic.ctrl->generic.handler != NULL) \
136 (*(mc)->generic.ctrl->generic.handler)((mc)->generic.ctrl, (mcs),\
137 (mcs)->data, (event)); \
140 #define findbyctrl(mcs, ctrl) \
141 find234((mcs)->byctrl, (ctrl), macctrl_cmp_byctrl_find)
143 static void macctrl_layoutset(struct mac_layoutstate
*, struct controlset
*,
144 WindowPtr
, struct macctrls
*);
145 static void macctrl_hideshowpanel(struct macctrls
*, unsigned int, int);
146 static void macctrl_switchtopanel(struct macctrls
*, unsigned int);
147 static void macctrl_setfocus(struct macctrls
*, union macctrl
*);
148 static void macctrl_text(struct macctrls
*, WindowPtr
,
149 struct mac_layoutstate
*, union control
*);
150 static void macctrl_editbox(struct macctrls
*, WindowPtr
,
151 struct mac_layoutstate
*, union control
*);
152 static void macctrl_radio(struct macctrls
*, WindowPtr
,
153 struct mac_layoutstate
*, union control
*);
154 static void macctrl_checkbox(struct macctrls
*, WindowPtr
,
155 struct mac_layoutstate
*, union control
*);
156 static void macctrl_button(struct macctrls
*, WindowPtr
,
157 struct mac_layoutstate
*, union control
*);
158 static void macctrl_listbox(struct macctrls
*, WindowPtr
,
159 struct mac_layoutstate
*, union control
*);
160 static void macctrl_popup(struct macctrls
*, WindowPtr
,
161 struct mac_layoutstate
*, union control
*);
162 static void macctrl_groupbox(struct macctrls
*, WindowPtr
,
163 struct mac_layoutstate
*, union control
*);
164 #if !TARGET_API_MAC_CARBON
165 static pascal SInt32
macctrl_sys7_editbox_cdef(SInt16
, ControlRef
,
166 ControlDefProcMessage
, SInt32
);
167 static pascal SInt32
macctrl_sys7_default_cdef(SInt16
, ControlRef
,
168 ControlDefProcMessage
, SInt32
);
169 static pascal SInt32
macctrl_sys7_listbox_cdef(SInt16
, ControlRef
,
170 ControlDefProcMessage
, SInt32
);
171 static pascal SInt32
macctrl_sys7_groupbox_cdef(SInt16
, ControlRef
,
172 ControlDefProcMessage
, SInt32
);
175 #if !TARGET_API_MAC_CARBON
177 * This trick enables us to keep all the CDEF code in the main
178 * application, which makes life easier. For details, see
179 * <http://developer.apple.com/technotes/tn/tn2003.html#custom_code_base>.
182 #pragma options align=mac68k
184 short jmpabs
; /* 4EF9 */
185 ControlDefUPP theUPP
;
187 #pragma options align=reset
190 static void macctrl_init()
192 #if !TARGET_API_MAC_CARBON
193 static int inited
= 0;
197 cdef
= (PatchCDEF
)GetResource(kControlDefProcResourceType
, CDEF_EditBox
);
198 (*cdef
)->theUPP
= NewControlDefProc(macctrl_sys7_editbox_cdef
);
199 cdef
= (PatchCDEF
)GetResource(kControlDefProcResourceType
, CDEF_Default
);
200 (*cdef
)->theUPP
= NewControlDefProc(macctrl_sys7_default_cdef
);
201 cdef
= (PatchCDEF
)GetResource(kControlDefProcResourceType
, CDEF_ListBox
);
202 (*cdef
)->theUPP
= NewControlDefProc(macctrl_sys7_listbox_cdef
);
203 cdef
= (PatchCDEF
)GetResource(kControlDefProcResourceType
, CDEF_GroupBox
);
204 (*cdef
)->theUPP
= NewControlDefProc(macctrl_sys7_groupbox_cdef
);
210 static int macctrl_cmp_byctrl(void *av
, void *bv
)
212 union macctrl
*a
= (union macctrl
*)av
;
213 union macctrl
*b
= (union macctrl
*)bv
;
215 if (a
->generic
.ctrl
< b
->generic
.ctrl
)
217 else if (a
->generic
.ctrl
> b
->generic
.ctrl
)
223 static int macctrl_cmp_byctrl_find(void *av
, void *bv
)
225 union control
*a
= (union control
*)av
;
226 union macctrl
*b
= (union macctrl
*)bv
;
228 if (a
< b
->generic
.ctrl
)
230 else if (a
> b
->generic
.ctrl
)
236 static union control panellist
;
238 static void panellist_handler(union control
*ctrl
, void *dlg
, void *data
,
241 struct macctrls
*mcs
= dlg
;
243 /* XXX what if there's no selection? */
244 if (event
== EVENT_SELCHANGE
)
245 macctrl_switchtopanel(mcs
, dlg_listbox_index(ctrl
, dlg
) + 1);
248 void macctrl_layoutbox(struct controlbox
*cb
, WindowPtr window
,
249 struct macctrls
*mcs
)
252 struct mac_layoutstate curstate
;
257 if (mac_gestalts
.apprvers
>= 0x100)
258 CreateRootControl(window
, &root
);
259 #if TARGET_API_MAC_CARBON
260 GetPortBounds(GetWindowPort(window
), &rect
);
262 rect
= window
->portRect
;
264 mcs
->window
= window
;
265 mcs
->byctrl
= newtree234(macctrl_cmp_byctrl
);
267 mcs
->defbutton
= NULL
;
268 mcs
->canbutton
= NULL
;
270 /* Count the number of panels */
272 for (i
= 1; i
< cb
->nctrlsets
; i
++)
273 if (strcmp(cb
->ctrlsets
[i
]->pathname
, cb
->ctrlsets
[i
-1]->pathname
))
275 mcs
->panels
= snewn(mcs
->npanels
, union macctrl
*);
276 memset(mcs
->panels
, 0, sizeof(*mcs
->panels
) * mcs
->npanels
);
277 curstate
.panelnum
= 0;
279 curstate
.pos
.h
= rect
.left
+ 13;
280 curstate
.pos
.v
= rect
.top
+ 13;
281 curstate
.width
= 160;
282 panellist
.listbox
.type
= CTRL_LISTBOX
;
283 panellist
.listbox
.handler
= &panellist_handler
;
284 panellist
.listbox
.height
= 20;
285 panellist
.listbox
.percentwidth
= 100;
286 macctrl_listbox(mcs
, window
, &curstate
, &panellist
);
287 /* XXX Start with panel 1 active */
289 curstate
.pos
.h
= rect
.left
+ 13 + 160 + 13;
290 curstate
.pos
.v
= rect
.bottom
- 33;
291 curstate
.width
= rect
.right
- (rect
.left
+ 13 + 160) - (13 * 2);
292 for (i
= 0; i
< cb
->nctrlsets
; i
++) {
293 if (i
> 0 && strcmp(cb
->ctrlsets
[i
]->pathname
,
294 cb
->ctrlsets
[i
-1]->pathname
)) {
295 curstate
.pos
.v
= rect
.top
+ 13;
297 assert(curstate
.panelnum
< mcs
->npanels
);
298 dlg_listbox_add(&panellist
, mcs
, cb
->ctrlsets
[i
]->pathname
);
300 macctrl_layoutset(&curstate
, cb
->ctrlsets
[i
], window
, mcs
);
302 macctrl_switchtopanel(mcs
, 1);
303 macctrl_hideshowpanel(mcs
, 0, TRUE
);
304 /* 14 = proxies, 19 = portfwd, 20 = SSH bugs */
311 static void macctrl_layoutset(struct mac_layoutstate
*curstate
,
312 struct controlset
*s
,
313 WindowPtr window
, struct macctrls
*mcs
)
315 unsigned int i
, j
, ncols
, colstart
, colspan
;
316 struct mac_layoutstate cols
[MAXCOLS
], pos
;
318 /* Start a containing box, if we have a boxname. */
319 if (s
->boxname
&& *s
->boxname
) {
320 curstate
->boxpos
= curstate
->pos
;
322 curstate
->boxname
= s
->boxtitle
;
323 curstate
->pos
.v
+= 10; /* XXX determine font height */
325 curstate
->boxname
= NULL
;
327 curstate
->pos
.v
+= 6;
328 curstate
->pos
.h
+= 12;
329 curstate
->width
-= 24;
332 /* Draw a title, if we have one. */
333 if (!s
->boxname
&& s
->boxtitle
) {
334 union control
*ctrl
= snew(union control
);
335 ctrl
->generic
.handler
= NULL
;
336 ctrl
->text
.label
= dupstr(s
->boxtitle
);
337 macctrl_text(mcs
, window
, curstate
, ctrl
);
338 /* FIXME: should be highlighted, centred or boxed */
344 for (i
= 0; i
< s
->ncontrols
; i
++) {
345 union control
*ctrl
= s
->ctrls
[i
];
347 colstart
= COLUMN_START(ctrl
->generic
.column
);
348 colspan
= COLUMN_SPAN(ctrl
->generic
.column
);
349 if (ctrl
->generic
.type
== CTRL_COLUMNS
) {
350 if (ctrl
->columns
.ncols
!= 1) {
351 ncols
= ctrl
->columns
.ncols
;
352 assert(ncols
<= MAXCOLS
);
353 for (j
= 0; j
< ncols
; j
++) {
356 cols
[j
].pos
.h
= cols
[j
-1].pos
.h
+ cols
[j
-1].width
+ 6;
358 cols
[j
].width
= curstate
->width
-
359 (cols
[j
].pos
.h
- curstate
->pos
.h
);
361 cols
[j
].width
= (curstate
->width
+ 6) *
362 ctrl
->columns
.percentages
[j
] / 100 - 6;
365 for (j
= 0; j
< ncols
; j
++)
366 if (cols
[j
].pos
.v
> cols
[0].pos
.v
)
367 cols
[0].pos
.v
= cols
[j
].pos
.v
;
368 cols
[0].width
= curstate
->width
;
372 pos
= cols
[colstart
];
373 pos
.width
= cols
[colstart
+ colspan
- 1].width
+
374 (cols
[colstart
+ colspan
- 1].pos
.h
- cols
[colstart
].pos
.h
);
376 for (j
= colstart
; j
< colstart
+ colspan
; j
++)
377 if (pos
.pos
.v
< cols
[j
].pos
.v
)
378 pos
.pos
.v
= cols
[j
].pos
.v
;
380 switch (ctrl
->generic
.type
) {
382 macctrl_text(mcs
, window
, &pos
, ctrl
);
385 macctrl_editbox(mcs
, window
, &pos
, ctrl
);
388 macctrl_radio(mcs
, window
, &pos
, ctrl
);
391 macctrl_checkbox(mcs
, window
, &pos
, ctrl
);
394 macctrl_button(mcs
, window
, &pos
, ctrl
);
397 if (ctrl
->listbox
.height
== 0)
398 macctrl_popup(mcs
, window
, &pos
, ctrl
);
400 macctrl_listbox(mcs
, window
, &pos
, ctrl
);
403 for (j
= colstart
; j
< colstart
+ colspan
; j
++)
404 cols
[j
].pos
.v
= pos
.pos
.v
;
407 for (j
= 0; j
< ncols
; j
++)
408 if (cols
[j
].pos
.v
> curstate
->pos
.v
)
409 curstate
->pos
.v
= cols
[j
].pos
.v
;
411 if (s
->boxname
&& *s
->boxname
) {
412 union control
*ctrl
= snew(union control
);
413 /* We're coming out of a box, so set the width back */
414 curstate
->pos
.h
-= 12;
415 curstate
->width
+= 24;
416 /* And draw the box to the original width */
417 macctrl_groupbox(mcs
, window
, curstate
, ctrl
);
421 static void macctrl_hideshowpanel(struct macctrls
*mcs
, unsigned int panel
,
427 #define hideshow(c) do { \
428 if (showit) ShowControl(c); else HideControl(c); \
431 for (mc
= mcs
->panels
[panel
]; mc
!= NULL
; mc
= mc
->generic
.next
) {
432 #if !TARGET_API_MAC_CARBON
433 if (mcs
->focus
== mc
)
434 macctrl_setfocus(mcs
, NULL
);
436 switch (mc
->generic
.type
) {
438 hideshow(mc
->text
.tbctrl
);
440 case MACCTRL_EDITBOX
:
441 hideshow(mc
->editbox
.tbctrl
);
442 if (mc
->editbox
.tblabel
!= NULL
)
443 hideshow(mc
->editbox
.tblabel
);
444 if (mc
->editbox
.tbbutton
!= NULL
)
445 hideshow(mc
->editbox
.tbbutton
);
448 for (j
= 0; j
< mc
->generic
.ctrl
->radio
.nbuttons
; j
++)
449 hideshow(mc
->radio
.tbctrls
[j
]);
450 if (mc
->radio
.tblabel
!= NULL
)
451 hideshow(mc
->radio
.tblabel
);
453 case MACCTRL_CHECKBOX
:
454 hideshow(mc
->checkbox
.tbctrl
);
457 hideshow(mc
->button
.tbctrl
);
458 if (mc
->button
.tbring
!= NULL
)
459 hideshow(mc
->button
.tbring
);
461 case MACCTRL_LISTBOX
:
462 hideshow(mc
->listbox
.tbctrl
);
464 * At least under Mac OS 8.1, hiding a list box
465 * doesn't hide its scroll bars.
467 #if TARGET_API_MAC_CARBON
468 hideshow(GetListVerticalScrollBar(mc
->listbox
.list
));
470 hideshow((*mc
->listbox
.list
)->vScroll
);
474 hideshow(mc
->popup
.tbctrl
);
476 case MACCTRL_GROUPBOX
:
477 hideshow(mc
->groupbox
.tbctrl
);
483 static void macctrl_switchtopanel(struct macctrls
*mcs
, unsigned int which
)
486 macctrl_hideshowpanel(mcs
, mcs
->curpanel
, FALSE
);
487 macctrl_hideshowpanel(mcs
, which
, TRUE
);
488 mcs
->curpanel
= which
;
491 #if !TARGET_API_MAC_CARBON
493 * System 7 focus manipulation
495 static void macctrl_defocus(union macctrl
*mc
)
498 assert(mac_gestalts
.apprvers
< 0x100);
499 switch (mc
->generic
.type
) {
500 case MACCTRL_EDITBOX
:
501 TEDeactivate((TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
);
506 static void macctrl_enfocus(union macctrl
*mc
)
509 assert(mac_gestalts
.apprvers
< 0x100);
510 switch (mc
->generic
.type
) {
511 case MACCTRL_EDITBOX
:
512 TEActivate((TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
);
517 static void macctrl_setfocus(struct macctrls
*mcs
, union macctrl
*mc
)
520 if (mcs
->focus
== mc
)
522 if (mcs
->focus
!= NULL
)
523 macctrl_defocus(mcs
->focus
);
530 static void macctrl_text(struct macctrls
*mcs
, WindowPtr window
,
531 struct mac_layoutstate
*curstate
,
534 union macctrl
*mc
= snew(union macctrl
);
538 assert(ctrl
->text
.label
!= NULL
);
539 mc
->generic
.type
= MACCTRL_TEXT
;
540 mc
->generic
.ctrl
= ctrl
;
541 mc
->generic
.privdata
= NULL
;
542 bounds
.left
= curstate
->pos
.h
;
543 bounds
.right
= bounds
.left
+ curstate
->width
;
544 bounds
.top
= curstate
->pos
.v
;
545 bounds
.bottom
= bounds
.top
+ 16;
546 if (mac_gestalts
.apprvers
>= 0x100) {
549 mc
->text
.tbctrl
= NewControl(window
, &bounds
, NULL
, FALSE
, 0, 0, 0,
550 kControlStaticTextProc
, (long)mc
);
551 SetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
552 kControlStaticTextTextTag
,
553 strlen(ctrl
->text
.label
), ctrl
->text
.label
);
554 GetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
555 kControlStaticTextTextHeightTag
,
556 sizeof(height
), &height
, &olen
);
558 #if !TARGET_API_MAC_CARBON
562 mc
->text
.tbctrl
= NewControl(window
, &bounds
, NULL
, FALSE
, 0, 0, 0,
563 SYS7_TEXT_PROC
, (long)mc
);
564 te
= (TEHandle
)(*mc
->text
.tbctrl
)->contrlData
;
565 TESetText(ctrl
->text
.label
, strlen(ctrl
->text
.label
), te
);
566 height
= TEGetHeight(1, (*te
)->nLines
, te
);
569 SizeControl(mc
->text
.tbctrl
, curstate
->width
, height
);
570 curstate
->pos
.v
+= height
+ 6;
571 add234(mcs
->byctrl
, mc
);
572 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
573 mcs
->panels
[curstate
->panelnum
] = mc
;
576 static void macctrl_editbox(struct macctrls
*mcs
, WindowPtr window
,
577 struct mac_layoutstate
*curstate
,
580 union macctrl
*mc
= snew(union macctrl
);
581 Rect lbounds
, bounds
, butbounds
;
582 static int nextmenuid
= MENU_MIN
;
586 mc
->generic
.type
= MACCTRL_EDITBOX
;
587 mc
->generic
.ctrl
= ctrl
;
588 mc
->generic
.privdata
= NULL
;
589 lbounds
.left
= curstate
->pos
.h
;
590 lbounds
.top
= curstate
->pos
.v
;
591 if (ctrl
->editbox
.percentwidth
== 100) {
592 if (ctrl
->editbox
.label
!= NULL
) {
593 lbounds
.right
= lbounds
.left
+ curstate
->width
;
594 lbounds
.bottom
= lbounds
.top
+ 16;
595 curstate
->pos
.v
+= 18;
597 bounds
.left
= curstate
->pos
.h
;
598 bounds
.right
= bounds
.left
+ curstate
->width
;
600 lbounds
.right
= lbounds
.left
+
601 curstate
->width
* (100 - ctrl
->editbox
.percentwidth
) / 100;
602 lbounds
.bottom
= lbounds
.top
+ 22;
603 bounds
.left
= lbounds
.right
;
604 bounds
.right
= lbounds
.left
+ curstate
->width
;
606 bounds
.top
= curstate
->pos
.v
;
607 bounds
.bottom
= bounds
.top
+ 22;
609 if (ctrl
->editbox
.has_list
) {
611 butbounds
.left
= butbounds
.right
- 20;
612 bounds
.right
-= 26; /* enough for 6 px gap and a button */
615 if (mac_gestalts
.apprvers
>= 0x100) {
616 if (ctrl
->editbox
.label
== NULL
)
617 mc
->editbox
.tblabel
= NULL
;
619 mc
->editbox
.tblabel
= NewControl(window
, &lbounds
, NULL
, FALSE
,
620 0, 0, 0, kControlStaticTextProc
,
622 SetControlData(mc
->editbox
.tblabel
, kControlEntireControl
,
623 kControlStaticTextTextTag
,
624 strlen(ctrl
->editbox
.label
), ctrl
->editbox
.label
);
626 InsetRect(&bounds
, 3, 3);
627 mc
->editbox
.tbctrl
= NewControl(window
, &bounds
, NULL
, FALSE
, 0, 0, 0,
628 ctrl
->editbox
.password ?
629 kControlEditTextPasswordProc
:
630 kControlEditTextProc
, (long)mc
);
632 #if !TARGET_API_MAC_CARBON
634 if (ctrl
->editbox
.label
== NULL
)
635 mc
->editbox
.tblabel
= NULL
;
637 mc
->editbox
.tblabel
= NewControl(window
, &lbounds
, NULL
, FALSE
,
638 0, 0, 0, SYS7_TEXT_PROC
,
640 TESetText(ctrl
->editbox
.label
, strlen(ctrl
->editbox
.label
),
641 (TEHandle
)(*mc
->editbox
.tblabel
)->contrlData
);
643 mc
->editbox
.tbctrl
= NewControl(window
, &bounds
, NULL
, FALSE
, 0, 0, 0,
644 SYS7_EDITBOX_PROC
, (long)mc
);
648 if (ctrl
->editbox
.has_list
) {
649 while (GetMenuHandle(nextmenuid
) != NULL
)
650 if (++nextmenuid
>= MENU_MAX
) nextmenuid
= MENU_MIN
;
651 menuid
= nextmenuid
++;
652 menu
= NewMenu(menuid
, "\pdummy");
653 if (menu
== NULL
) goto nomenu
;
654 mc
->editbox
.menu
= menu
;
655 mc
->editbox
.menuid
= menuid
;
656 InsertMenu(menu
, kInsertHierarchicalMenu
);
657 mc
->editbox
.nids
= 0;
658 mc
->editbox
.ids
= NULL
;
660 mc
->editbox
.tbbutton
= NewControl(window
, &butbounds
, NULL
, FALSE
,
661 popupTitleLeftJust
, menuid
, 0,
662 popupMenuProc
+ popupFixedWidth
,
668 curstate
->pos
.v
+= 28;
669 add234(mcs
->byctrl
, mc
);
670 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
671 mcs
->panels
[curstate
->panelnum
] = mc
;
672 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
675 #if !TARGET_API_MAC_CARBON
676 static pascal SInt32
macctrl_sys7_editbox_cdef(SInt16 variant
,
678 ControlDefProcMessage msg
,
689 rect
= (*control
)->contrlRect
;
690 if (variant
== SYS7_EDITBOX_VARIANT
)
691 InsetRect(&rect
, 3, 3); /* 2 if it's 20 pixels high */
692 te
= TENew(&rect
, &rect
);
693 ssfs
= GetScriptVariable(smSystemScript
, smScriptSysFondSize
);
694 (*te
)->txSize
= LoWord(ssfs
);
695 (*te
)->txFont
= HiWord(ssfs
);
696 (*control
)->contrlData
= (Handle
)te
;
699 TEDispose((TEHandle
)(*control
)->contrlData
);
702 if ((*control
)->contrlVis
) {
703 rect
= (*control
)->contrlRect
;
704 if (variant
== SYS7_EDITBOX_VARIANT
) {
707 InsetRect(&rect
, 3, 3);
710 (*(TEHandle
)(*control
)->contrlData
)->viewRect
= rect
;
711 TEUpdate(&rect
, (TEHandle
)(*control
)->contrlData
);
715 if (variant
== SYS7_TEXT_VARIANT
)
716 return kControlNoPart
;
717 mouse
.h
= LoWord(param
);
718 mouse
.v
= HiWord(param
);
719 rect
= (*control
)->contrlRect
;
720 InsetRect(&rect
, 3, 3);
721 return PtInRect(mouse
, &rect
) ? kControlEditTextPart
: kControlNoPart
;
723 if (param
& (1 << 31)) {
729 rgn
= (RgnHandle
)param
;
730 RectRgn(rgn
, &(*control
)->contrlRect
);
734 rgn
= (RgnHandle
)param
;
743 static void macctrl_radio(struct macctrls
*mcs
, WindowPtr window
,
744 struct mac_layoutstate
*curstate
,
747 union macctrl
*mc
= snew(union macctrl
);
750 unsigned int i
, colwidth
;
752 mc
->generic
.type
= MACCTRL_RADIO
;
753 mc
->generic
.ctrl
= ctrl
;
754 mc
->generic
.privdata
= NULL
;
755 mc
->radio
.tbctrls
= snewn(ctrl
->radio
.nbuttons
, ControlRef
);
756 colwidth
= (curstate
->width
+ 13) / ctrl
->radio
.ncolumns
;
757 bounds
.top
= curstate
->pos
.v
;
758 bounds
.bottom
= bounds
.top
+ 16;
759 bounds
.left
= curstate
->pos
.h
;
760 bounds
.right
= bounds
.left
+ curstate
->width
;
761 if (ctrl
->radio
.label
== NULL
)
762 mc
->radio
.tblabel
= NULL
;
764 if (mac_gestalts
.apprvers
>= 0x100) {
765 mc
->radio
.tblabel
= NewControl(window
, &bounds
, NULL
, FALSE
,
766 0, 0, 0, kControlStaticTextProc
,
768 SetControlData(mc
->radio
.tblabel
, kControlEntireControl
,
769 kControlStaticTextTextTag
,
770 strlen(ctrl
->radio
.label
), ctrl
->radio
.label
);
772 #if !TARGET_API_MAC_CARBON
774 mc
->radio
.tblabel
= NewControl(window
, &bounds
, NULL
, FALSE
,
775 0, 0, 0, SYS7_TEXT_PROC
, (long)mc
);
776 TESetText(ctrl
->radio
.label
, strlen(ctrl
->radio
.label
),
777 (TEHandle
)(*mc
->radio
.tblabel
)->contrlData
);
780 curstate
->pos
.v
+= 18;
782 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
783 bounds
.top
= curstate
->pos
.v
- 2;
784 bounds
.bottom
= bounds
.top
+ 18;
785 bounds
.left
= curstate
->pos
.h
+ colwidth
* (i
% ctrl
->radio
.ncolumns
);
786 if (i
== ctrl
->radio
.nbuttons
- 1 ||
787 i
% ctrl
->radio
.ncolumns
== ctrl
->radio
.ncolumns
- 1) {
788 bounds
.right
= curstate
->pos
.h
+ curstate
->width
;
789 curstate
->pos
.v
+= 18;
791 bounds
.right
= bounds
.left
+ colwidth
- 13;
792 c2pstrcpy(title
, ctrl
->radio
.buttons
[i
]);
793 mc
->radio
.tbctrls
[i
] = NewControl(window
, &bounds
, title
, FALSE
,
794 0, 0, 1, radioButProc
, (long)mc
);
796 curstate
->pos
.v
+= 4;
797 add234(mcs
->byctrl
, mc
);
798 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
799 mcs
->panels
[curstate
->panelnum
] = mc
;
800 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
803 static void macctrl_checkbox(struct macctrls
*mcs
, WindowPtr window
,
804 struct mac_layoutstate
*curstate
,
807 union macctrl
*mc
= snew(union macctrl
);
811 assert(ctrl
->checkbox
.label
!= NULL
);
812 mc
->generic
.type
= MACCTRL_CHECKBOX
;
813 mc
->generic
.ctrl
= ctrl
;
814 mc
->generic
.privdata
= NULL
;
815 bounds
.left
= curstate
->pos
.h
;
816 bounds
.right
= bounds
.left
+ curstate
->width
;
817 bounds
.top
= curstate
->pos
.v
;
818 bounds
.bottom
= bounds
.top
+ 16;
819 c2pstrcpy(title
, ctrl
->checkbox
.label
);
820 mc
->checkbox
.tbctrl
= NewControl(window
, &bounds
, title
, FALSE
, 0, 0, 1,
821 checkBoxProc
, (long)mc
);
822 add234(mcs
->byctrl
, mc
);
823 curstate
->pos
.v
+= 22;
824 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
825 mcs
->panels
[curstate
->panelnum
] = mc
;
826 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
829 static void macctrl_button(struct macctrls
*mcs
, WindowPtr window
,
830 struct mac_layoutstate
*curstate
,
833 union macctrl
*mc
= snew(union macctrl
);
837 assert(ctrl
->button
.label
!= NULL
);
838 mc
->generic
.type
= MACCTRL_BUTTON
;
839 mc
->generic
.ctrl
= ctrl
;
840 mc
->generic
.privdata
= NULL
;
841 bounds
.left
= curstate
->pos
.h
;
842 bounds
.right
= bounds
.left
+ curstate
->width
;
843 bounds
.top
= curstate
->pos
.v
;
844 bounds
.bottom
= bounds
.top
+ 20;
845 c2pstrcpy(title
, ctrl
->button
.label
);
846 mc
->button
.tbctrl
= NewControl(window
, &bounds
, title
, FALSE
, 0, 0, 1,
847 pushButProc
, (long)mc
);
848 mc
->button
.tbring
= NULL
;
849 if (mac_gestalts
.apprvers
>= 0x100) {
850 Boolean isdefault
= ctrl
->button
.isdefault
;
852 SetControlData(mc
->button
.tbctrl
, kControlEntireControl
,
853 kControlPushButtonDefaultTag
,
854 sizeof(isdefault
), &isdefault
);
855 } else if (ctrl
->button
.isdefault
) {
856 InsetRect(&bounds
, -4, -4);
857 mc
->button
.tbring
= NewControl(window
, &bounds
, title
, FALSE
, 0, 0, 1,
858 SYS7_DEFAULT_PROC
, (long)mc
);
860 if (mac_gestalts
.apprvers
>= 0x110) {
861 Boolean iscancel
= ctrl
->button
.iscancel
;
863 SetControlData(mc
->button
.tbctrl
, kControlEntireControl
,
864 kControlPushButtonCancelTag
,
865 sizeof(iscancel
), &iscancel
);
867 if (ctrl
->button
.isdefault
)
869 if (ctrl
->button
.iscancel
)
871 add234(mcs
->byctrl
, mc
);
872 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
873 mcs
->panels
[curstate
->panelnum
] = mc
;
874 curstate
->pos
.v
+= 26;
877 #if !TARGET_API_MAC_CARBON
878 static pascal SInt32
macctrl_sys7_default_cdef(SInt16 variant
,
880 ControlDefProcMessage msg
,
890 if ((*control
)->contrlVis
) {
891 rect
= (*control
)->contrlRect
;
892 GetPenState(&savestate
);
895 if ((*control
)->contrlHilite
== kControlInactivePart
)
897 oval
= (rect
.bottom
- rect
.top
) / 2 + 2;
898 FrameRoundRect(&rect
, oval
, oval
);
899 SetPenState(&savestate
);
903 if (param
& (1 << 31)) {
909 rgn
= (RgnHandle
)param
;
910 RectRgn(rgn
, &(*control
)->contrlRect
);
914 rgn
= (RgnHandle
)param
;
923 static void macctrl_listbox(struct macctrls
*mcs
, WindowPtr window
,
924 struct mac_layoutstate
*curstate
,
927 union macctrl
*mc
= snew(union macctrl
);
932 assert(ctrl
->listbox
.percentwidth
== 100);
933 mc
->generic
.type
= MACCTRL_LISTBOX
;
934 mc
->generic
.ctrl
= ctrl
;
935 mc
->generic
.privdata
= NULL
;
936 /* The list starts off empty */
937 mc
->listbox
.nids
= 0;
938 mc
->listbox
.ids
= NULL
;
939 bounds
.left
= curstate
->pos
.h
;
940 bounds
.right
= bounds
.left
+ curstate
->width
;
941 bounds
.top
= curstate
->pos
.v
;
942 bounds
.bottom
= bounds
.top
+ 16 * ctrl
->listbox
.height
+ 2;
944 if (mac_gestalts
.apprvers
>= 0x100) {
945 InsetRect(&bounds
, 3, 3);
946 mc
->listbox
.tbctrl
= NewControl(window
, &bounds
, NULL
, FALSE
,
948 kControlListBoxProc
, (long)mc
);
949 if (GetControlData(mc
->listbox
.tbctrl
, kControlEntireControl
,
950 kControlListBoxListHandleTag
,
951 sizeof(mc
->listbox
.list
), &mc
->listbox
.list
,
953 DisposeControl(mc
->listbox
.tbctrl
);
958 #if !TARGET_API_MAC_CARBON
960 InsetRect(&bounds
, -3, -3);
961 mc
->listbox
.tbctrl
= NewControl(window
, &bounds
, NULL
, FALSE
,
963 SYS7_LISTBOX_PROC
, (long)mc
);
964 mc
->listbox
.list
= (ListHandle
)(*mc
->listbox
.tbctrl
)->contrlData
;
965 (*mc
->listbox
.list
)->refCon
= (long)mc
;
968 if (!ctrl
->listbox
.multisel
) {
969 #if TARGET_API_MAC_CARBON
970 SetListSelectionFlags(mc
->listbox
.list
, lOnlyOne
);
972 (*mc
->listbox
.list
)->selFlags
= lOnlyOne
;
975 add234(mcs
->byctrl
, mc
);
976 curstate
->pos
.v
+= 6 + 16 * ctrl
->listbox
.height
+ 2;
977 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
978 mcs
->panels
[curstate
->panelnum
] = mc
;
979 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
980 #if TARGET_API_MAC_CARBON
981 HideControl(GetListVerticalScrollBar(mc
->listbox
.list
));
983 HideControl((*mc
->listbox
.list
)->vScroll
);
987 #if !TARGET_API_MAC_CARBON
988 static pascal SInt32
macctrl_sys7_listbox_cdef(SInt16 variant
,
990 ControlDefProcMessage msg
,
1006 rect
= (*control
)->contrlRect
;
1007 InsetRect(&rect
, 4, 4);
1008 rect
.right
-= 15; /* scroll bar */
1009 bounds
.top
= bounds
.bottom
= bounds
.left
= 0;
1011 csize
.h
= csize
.v
= 0;
1013 savefont
= curport
->txFont
;
1014 savesize
= curport
->txSize
;
1015 ssfs
= GetScriptVariable(smSystemScript
, smScriptSysFondSize
);
1016 TextFont(HiWord(ssfs
));
1017 TextSize(LoWord(ssfs
));
1018 list
= LNew(&rect
, &bounds
, csize
, 0, (*control
)->contrlOwner
,
1019 TRUE
, FALSE
, FALSE
, TRUE
);
1020 SetControlReference((*list
)->vScroll
, (long)list
);
1021 (*control
)->contrlData
= (Handle
)list
;
1027 * If the dialogue box is being destroyed, the scroll bar
1028 * might have gone already. In our situation, this is the
1029 * only time we destroy a control, so NULL out the scroll bar
1030 * handle to prevent LDispose trying to free it.
1032 list
= (ListHandle
)(*control
)->contrlData
;
1033 (*list
)->vScroll
= NULL
;
1037 if ((*control
)->contrlVis
) {
1038 rect
= (*control
)->contrlRect
;
1039 /* XXX input focus highlighting? */
1040 InsetRect(&rect
, 3, 3);
1043 list
= (ListHandle
)(*control
)->contrlData
;
1044 LActivate((*control
)->contrlHilite
!= kControlInactivePart
, list
);
1046 LUpdate(curport
->visRgn
, list
);
1050 mouse
.h
= LoWord(param
);
1051 mouse
.v
= HiWord(param
);
1052 rect
= (*control
)->contrlRect
;
1053 InsetRect(&rect
, 4, 4);
1055 * We deliberately exclude the scrollbar so that LClick() can see it.
1058 return PtInRect(mouse
, &rect
) ? kControlListBoxPart
: kControlNoPart
;
1060 if (param
& (1 << 31)) {
1061 param
&= ~(1 << 31);
1066 rgn
= (RgnHandle
)param
;
1067 RectRgn(rgn
, &(*control
)->contrlRect
);
1071 rgn
= (RgnHandle
)param
;
1080 #if !TARGET_API_MAC_CARBON
1081 static pascal SInt32
macctrl_sys7_groupbox_cdef(SInt16 variant
,
1083 ControlDefProcMessage msg
,
1092 if ((*control
)->contrlVis
) {
1093 rect
= (*control
)->contrlRect
;
1094 GetPenState(&savestate
);
1099 SetPenState(&savestate
);
1103 if (param
& (1 << 31)) {
1104 param
&= ~(1 << 31);
1109 rgn
= (RgnHandle
)param
;
1110 RectRgn(rgn
, &(*control
)->contrlRect
);
1114 rgn
= (RgnHandle
)param
;
1122 static void macctrl_popup(struct macctrls
*mcs
, WindowPtr window
,
1123 struct mac_layoutstate
*curstate
,
1124 union control
*ctrl
)
1126 union macctrl
*mc
= snew(union macctrl
);
1129 unsigned int labelwidth
;
1130 static int nextmenuid
= MENU_MIN
;
1135 * <http://developer.apple.com/qa/tb/tb42.html> explains how to
1136 * create a popup menu with dynamic content.
1138 assert(ctrl
->listbox
.height
== 0);
1139 assert(!ctrl
->listbox
.draglist
);
1140 assert(!ctrl
->listbox
.multisel
);
1142 mc
->generic
.type
= MACCTRL_POPUP
;
1143 mc
->generic
.ctrl
= ctrl
;
1144 mc
->generic
.privdata
= NULL
;
1145 c2pstrcpy(title
, ctrl
->button
.label
== NULL ?
"" : ctrl
->button
.label
);
1147 /* Find a spare menu ID and create the menu */
1148 while (GetMenuHandle(nextmenuid
) != NULL
)
1149 if (++nextmenuid
>= MENU_MAX
) nextmenuid
= MENU_MIN
;
1150 menuid
= nextmenuid
++;
1151 menu
= NewMenu(menuid
, "\pdummy");
1152 if (menu
== NULL
) return;
1153 mc
->popup
.menu
= menu
;
1154 mc
->popup
.menuid
= menuid
;
1155 InsertMenu(menu
, kInsertHierarchicalMenu
);
1157 /* The menu starts off empty */
1159 mc
->popup
.ids
= NULL
;
1161 bounds
.left
= curstate
->pos
.h
;
1162 bounds
.right
= bounds
.left
+ curstate
->width
;
1163 bounds
.top
= curstate
->pos
.v
;
1164 bounds
.bottom
= bounds
.top
+ 20;
1165 /* XXX handle percentwidth == 100 */
1166 labelwidth
= curstate
->width
* (100 - ctrl
->listbox
.percentwidth
) / 100;
1167 mc
->popup
.tbctrl
= NewControl(window
, &bounds
, title
, FALSE
,
1168 popupTitleLeftJust
, menuid
, labelwidth
,
1169 popupMenuProc
+ popupFixedWidth
, (long)mc
);
1170 add234(mcs
->byctrl
, mc
);
1171 curstate
->pos
.v
+= 26;
1172 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
1173 mcs
->panels
[curstate
->panelnum
] = mc
;
1174 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
1177 static void macctrl_groupbox(struct macctrls
*mcs
, WindowPtr window
,
1178 struct mac_layoutstate
*curstate
,
1179 union control
*ctrl
)
1181 union macctrl
*mc
= snew (union macctrl
);
1185 r
.top
= curstate
->boxpos
.v
;
1186 r
.left
= curstate
->boxpos
.h
;
1187 r
.bottom
= curstate
->pos
.v
;
1188 r
.right
= curstate
->boxpos
.h
+ curstate
->width
;
1190 mc
->generic
.type
= MACCTRL_GROUPBOX
;
1191 mc
->generic
.privdata
= NULL
;
1192 mc
->generic
.ctrl
= ctrl
;
1193 mc
->generic
.ctrl
->generic
.handler
= NULL
;
1195 if (curstate
->boxname
)
1196 c2pstrcpy(ptitle
, curstate
->boxname
);
1198 c2pstrcpy(ptitle
, "");
1199 if (mac_gestalts
.apprvers
>= 0x100) { /* Appearance Manager */
1200 mc
->groupbox
.tbctrl
= NewControl(window
, &r
, ptitle
, FALSE
, 0, 0, 1,
1201 kControlGroupBoxTextTitleProc
, (long)mc
);
1203 mc
->groupbox
.tbctrl
= NewControl(window
, &r
, ptitle
, FALSE
, 0, 0, 1,
1204 SYS7_GROUPBOX_PROC
, (long)mc
);
1206 add234(mcs
->byctrl
, mc
);
1207 mc
->generic
.next
= mcs
->panels
[curstate
->panelnum
];
1208 mcs
->panels
[curstate
->panelnum
] = mc
;
1211 void macctrl_activate(WindowPtr window
, EventRecord
*event
)
1213 struct macctrls
*mcs
= mac_winctrls(window
);
1214 Boolean active
= (event
->modifiers
& activeFlag
) != 0;
1217 ControlPartCode state
;
1221 SetPort((GrafPtr
)GetWindowPort(window
));
1222 if (mac_gestalts
.apprvers
>= 0x100)
1223 SetThemeWindowBackground(window
, active ?
1224 kThemeBrushModelessDialogBackgroundActive
:
1225 kThemeBrushModelessDialogBackgroundInactive
,
1227 state
= active ? kControlNoPart
: kControlInactivePart
;
1228 for (i
= 0; i
<= mcs
->curpanel
; i
+= mcs
->curpanel
)
1229 for (mc
= mcs
->panels
[i
]; mc
!= NULL
; mc
= mc
->generic
.next
) {
1230 switch (mc
->generic
.type
) {
1232 HiliteControl(mc
->text
.tbctrl
, state
);
1234 case MACCTRL_EDITBOX
:
1235 HiliteControl(mc
->editbox
.tbctrl
, state
);
1236 if (mc
->editbox
.tblabel
!= NULL
)
1237 HiliteControl(mc
->editbox
.tblabel
, state
);
1238 if (mc
->editbox
.tbbutton
!= NULL
)
1239 HiliteControl(mc
->editbox
.tbbutton
, state
);
1242 for (j
= 0; j
< mc
->generic
.ctrl
->radio
.nbuttons
; j
++)
1243 HiliteControl(mc
->radio
.tbctrls
[j
], state
);
1244 if (mc
->radio
.tblabel
!= NULL
)
1245 HiliteControl(mc
->radio
.tblabel
, state
);
1247 case MACCTRL_CHECKBOX
:
1248 HiliteControl(mc
->checkbox
.tbctrl
, state
);
1250 case MACCTRL_BUTTON
:
1251 HiliteControl(mc
->button
.tbctrl
, state
);
1252 if (mc
->button
.tbring
!= NULL
)
1253 HiliteControl(mc
->button
.tbring
, state
);
1255 case MACCTRL_LISTBOX
:
1256 HiliteControl(mc
->listbox
.tbctrl
, state
);
1259 HiliteControl(mc
->popup
.tbctrl
, state
);
1261 case MACCTRL_GROUPBOX
:
1262 HiliteControl(mc
->popup
.tbctrl
, state
);
1264 #if !TARGET_API_MAC_CARBON
1265 if (mcs
->focus
== mc
) {
1267 macctrl_enfocus(mc
);
1269 macctrl_defocus(mc
);
1276 void macctrl_click(WindowPtr window
, EventRecord
*event
)
1279 ControlHandle control
, oldfocus
;
1280 int part
, trackresult
;
1283 struct macctrls
*mcs
= mac_winctrls(window
);
1288 SetPort((GrafPtr
)GetWindowPort(window
));
1289 mouse
= event
->where
;
1290 GlobalToLocal(&mouse
);
1291 part
= FindControl(mouse
, window
, &control
);
1292 if (control
!= NULL
) {
1293 #if !TARGET_API_MAC_CARBON
1295 * Special magic for scroll bars in list boxes, whose refcon
1298 if (part
== kControlUpButtonPart
|| part
== kControlDownButtonPart
||
1299 part
== kControlPageUpPart
|| part
== kControlPageDownPart
||
1300 part
== kControlIndicatorPart
)
1301 mc
= (union macctrl
*)
1302 (*(ListHandle
)GetControlReference(control
))->refCon
;
1305 mc
= (union macctrl
*)GetControlReference(control
);
1306 if (mac_gestalts
.apprvers
>= 0x100) {
1307 if (GetControlFeatures(control
, &features
) == noErr
&&
1308 (features
& kControlSupportsFocus
) &&
1309 (features
& kControlGetsFocusOnClick
) &&
1310 GetKeyboardFocus(window
, &oldfocus
) == noErr
&&
1311 control
!= oldfocus
)
1312 SetKeyboardFocus(window
, control
, part
);
1313 trackresult
= HandleControlClick(control
, mouse
, event
->modifiers
,
1314 (ControlActionUPP
)-1);
1316 #if !TARGET_API_MAC_CARBON
1317 if (mc
->generic
.type
== MACCTRL_EDITBOX
&&
1318 control
== mc
->editbox
.tbctrl
) {
1319 TEHandle te
= (TEHandle
)(*control
)->contrlData
;
1321 macctrl_setfocus(mcs
, mc
);
1322 TEClick(mouse
, !!(event
->modifiers
& shiftKey
), te
);
1325 if (mc
->generic
.type
== MACCTRL_EDITBOX
&&
1326 control
== mc
->editbox
.tbbutton
) {
1327 dlg_editbox_set(mc
->generic
.ctrl
, mcs
,
1328 cp_enumerate(dlg_listbox_index(mc
->generic
.ctrl
, mcs
)));
1329 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
1331 if (mc
->generic
.type
== MACCTRL_LISTBOX
&&
1332 (control
== mc
->listbox
.tbctrl
||
1333 control
== (*mc
->listbox
.list
)->vScroll
)) {
1335 macctrl_setfocus(mcs
, mc
);
1336 if (LClick(mouse
, event
->modifiers
, mc
->listbox
.list
))
1338 ctrlevent(mcs
, mc
, EVENT_ACTION
);
1340 ctrlevent(mcs
, mc
, EVENT_SELCHANGE
);
1344 trackresult
= TrackControl(control
, mouse
, (ControlActionUPP
)-1);
1346 switch (mc
->generic
.type
) {
1348 if (trackresult
!= 0) {
1349 for (i
= 0; i
< mc
->generic
.ctrl
->radio
.nbuttons
; i
++)
1350 if (mc
->radio
.tbctrls
[i
] == control
)
1351 SetControlValue(mc
->radio
.tbctrls
[i
],
1352 kControlRadioButtonCheckedValue
);
1354 SetControlValue(mc
->radio
.tbctrls
[i
],
1355 kControlRadioButtonUncheckedValue
);
1356 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
1359 case MACCTRL_CHECKBOX
:
1360 if (trackresult
!= 0) {
1361 SetControlValue(control
, !GetControlValue(control
));
1362 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
1365 case MACCTRL_BUTTON
:
1366 if (trackresult
!= 0)
1367 ctrlevent(mcs
, mc
, EVENT_ACTION
);
1369 case MACCTRL_EDITBOX
:
1370 if (control
== mc
->editbox
.tbbutton
) {
1371 dlg_editbox_set(mc
->generic
.ctrl
, mcs
,
1372 cp_enumerate(dlg_listbox_index(mc
->generic
.ctrl
, mcs
)));
1373 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
1376 case MACCTRL_LISTBOX
:
1377 /* FIXME spot double-click */
1378 ctrlevent(mcs
, mc
, EVENT_SELCHANGE
);
1381 ctrlevent(mcs
, mc
, EVENT_SELCHANGE
);
1389 void macctrl_key(WindowPtr window
, EventRecord
*event
)
1392 struct macctrls
*mcs
= mac_winctrls(window
);
1394 unsigned long dummy
;
1396 switch (event
->message
& charCodeMask
) {
1397 case kEnterCharCode
:
1398 case kReturnCharCode
:
1399 if (mcs
->defbutton
!= NULL
) {
1400 assert(mcs
->defbutton
->generic
.type
== MACCTRL_BUTTON
);
1401 HiliteControl(mcs
->defbutton
->button
.tbctrl
, kControlButtonPart
);
1403 * I'd like to delay unhilighting the button until after
1404 * the event has been processed, but by them the entire
1405 * dialgue box might have been destroyed.
1408 HiliteControl(mcs
->defbutton
->button
.tbctrl
, kControlNoPart
);
1409 ctrlevent(mcs
, mcs
->defbutton
, EVENT_ACTION
);
1412 case kEscapeCharCode
:
1413 if (mcs
->canbutton
!= NULL
) {
1414 assert(mcs
->canbutton
->generic
.type
== MACCTRL_BUTTON
);
1415 HiliteControl(mcs
->canbutton
->button
.tbctrl
, kControlButtonPart
);
1417 HiliteControl(mcs
->defbutton
->button
.tbctrl
, kControlNoPart
);
1418 ctrlevent(mcs
, mcs
->canbutton
, EVENT_ACTION
);
1422 if (mac_gestalts
.apprvers
>= 0x100) {
1423 if (GetKeyboardFocus(window
, &control
) == noErr
&& control
!= NULL
) {
1424 HandleControlKey(control
, (event
->message
& keyCodeMask
) >> 8,
1425 event
->message
& charCodeMask
, event
->modifiers
);
1426 mc
= (union macctrl
*)GetControlReference(control
);
1427 switch (mc
->generic
.type
) {
1428 case MACCTRL_LISTBOX
:
1429 ctrlevent(mcs
, mc
, EVENT_SELCHANGE
);
1432 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
1437 #if !TARGET_API_MAC_CARBON
1441 if (mcs
->focus
!= NULL
) {
1443 switch (mc
->generic
.type
) {
1444 case MACCTRL_EDITBOX
:
1445 te
= (TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
;
1446 TEKey(event
->message
& charCodeMask
, te
);
1447 ctrlevent(mcs
, mc
, EVENT_VALCHANGE
);
1455 void macctrl_update(WindowPtr window
)
1457 #if TARGET_API_MAC_CARBON
1463 BeginUpdate(window
);
1465 SetPort((GrafPtr
)GetWindowPort(window
));
1466 if (mac_gestalts
.apprvers
>= 0x101) {
1467 #if TARGET_API_MAC_CARBON
1468 GetPortBounds(GetWindowPort(window
), &rect
);
1470 rect
= window
->portRect
;
1472 InsetRect(&rect
, -1, -1);
1473 DrawThemeModelessDialogFrame(&rect
, mac_frontwindow() == window ?
1474 kThemeStateActive
: kThemeStateInactive
);
1476 #if TARGET_API_MAC_CARBON
1478 GetPortVisibleRegion(GetWindowPort(window
), visrgn
);
1479 UpdateControls(window
, visrgn
);
1482 UpdateControls(window
, window
->visRgn
);
1488 #if TARGET_API_MAC_CARBON
1489 #define EnableItem EnableMenuItem
1490 #define DisableItem DisableMenuItem
1492 void macctrl_adjustmenus(WindowPtr window
)
1496 menu
= GetMenuHandle(mFile
);
1497 DisableItem(menu
, iSave
); /* XXX enable if modified */
1498 EnableItem(menu
, iSaveAs
);
1499 EnableItem(menu
, iDuplicate
);
1501 menu
= GetMenuHandle(mEdit
);
1502 DisableItem(menu
, 0);
1505 void macctrl_close(WindowPtr window
)
1507 struct macctrls
*mcs
= mac_winctrls(window
);
1511 * Mostly, we don't bother disposing of the Toolbox controls,
1512 * since that will happen automatically when the window is
1513 * disposed of. Popup menus are an exception, because we have to
1514 * dispose of the menu ourselves, and doing that while the control
1515 * still holds a reference to it seems rude.
1517 while ((mc
= index234(mcs
->byctrl
, 0)) != NULL
) {
1518 if (mc
->generic
.privdata
!= NULL
&& mc
->generic
.freeprivdata
)
1519 sfree(mc
->generic
.privdata
);
1520 switch (mc
->generic
.type
) {
1522 DisposeControl(mc
->popup
.tbctrl
);
1523 DeleteMenu(mc
->popup
.menuid
);
1524 DisposeMenu(mc
->popup
.menu
);
1527 del234(mcs
->byctrl
, mc
);
1531 freetree234(mcs
->byctrl
);
1537 void dlg_update_start(union control
*ctrl
, void *dlg
)
1543 void dlg_update_done(union control
*ctrl
, void *dlg
)
1549 void dlg_set_focus(union control
*ctrl
, void *dlg
)
1552 if (mac_gestalts
.apprvers
>= 0x100) {
1553 /* Use SetKeyboardFocus() */
1555 /* Do our own mucking around */
1559 union control
*dlg_last_focused(union control
*ctrl
, void *dlg
)
1565 void dlg_beep(void *dlg
)
1571 void dlg_error_msg(void *dlg
, char *msg
)
1575 c2pstrcpy(pmsg
, msg
);
1576 ParamText(pmsg
, NULL
, NULL
, NULL
);
1577 StopAlert(128, NULL
);
1580 void dlg_end(void *dlg
, int value
)
1582 struct macctrls
*mcs
= dlg
;
1584 if (mcs
->end
!= NULL
)
1585 (*mcs
->end
)(mcs
->window
, value
);
1588 void dlg_refresh(union control
*ctrl
, void *dlg
)
1590 struct macctrls
*mcs
= dlg
;
1595 /* NULL means refresh every control */
1596 for (i
= 0 ; i
< mcs
->npanels
; i
++) {
1597 for (mc
= mcs
->panels
[i
]; mc
!= NULL
; mc
= mc
->generic
.next
) {
1598 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
1603 /* Just refresh a specific control */
1604 mc
= findbyctrl(mcs
, ctrl
);
1606 ctrlevent(mcs
, mc
, EVENT_REFRESH
);
1609 void *dlg_get_privdata(union control
*ctrl
, void *dlg
)
1611 struct macctrls
*mcs
= dlg
;
1612 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1615 return mc
->generic
.privdata
;
1618 void dlg_set_privdata(union control
*ctrl
, void *dlg
, void *ptr
)
1620 struct macctrls
*mcs
= dlg
;
1621 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1624 mc
->generic
.privdata
= ptr
;
1625 mc
->generic
.freeprivdata
= FALSE
;
1628 void *dlg_alloc_privdata(union control
*ctrl
, void *dlg
, size_t size
)
1630 struct macctrls
*mcs
= dlg
;
1631 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1634 mc
->generic
.privdata
= smalloc(size
);
1635 mc
->generic
.freeprivdata
= TRUE
;
1636 return mc
->generic
.privdata
;
1641 * Radio Button control
1644 void dlg_radiobutton_set(union control
*ctrl
, void *dlg
, int whichbutton
)
1646 struct macctrls
*mcs
= dlg
;
1647 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1650 if (mc
== NULL
) return;
1651 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
1652 if (i
== whichbutton
)
1653 SetControlValue(mc
->radio
.tbctrls
[i
],
1654 kControlRadioButtonCheckedValue
);
1656 SetControlValue(mc
->radio
.tbctrls
[i
],
1657 kControlRadioButtonUncheckedValue
);
1662 int dlg_radiobutton_get(union control
*ctrl
, void *dlg
)
1664 struct macctrls
*mcs
= dlg
;
1665 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1669 for (i
= 0; i
< ctrl
->radio
.nbuttons
; i
++) {
1670 if (GetControlValue(mc
->radio
.tbctrls
[i
]) ==
1671 kControlRadioButtonCheckedValue
)
1682 void dlg_checkbox_set(union control
*ctrl
, void *dlg
, int checked
)
1684 struct macctrls
*mcs
= dlg
;
1685 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1687 if (mc
== NULL
) return;
1688 SetControlValue(mc
->checkbox
.tbctrl
,
1689 checked ? kControlCheckBoxCheckedValue
:
1690 kControlCheckBoxUncheckedValue
);
1693 int dlg_checkbox_get(union control
*ctrl
, void *dlg
)
1695 struct macctrls
*mcs
= dlg
;
1696 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1699 return GetControlValue(mc
->checkbox
.tbctrl
);
1707 void dlg_editbox_set(union control
*ctrl
, void *dlg
, char const *text
)
1709 struct macctrls
*mcs
= dlg
;
1710 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1713 if (mc
== NULL
) return;
1714 assert(mc
->generic
.type
== MACCTRL_EDITBOX
);
1716 SetPort((GrafPtr
)(GetWindowPort(mcs
->window
)));
1717 if (mac_gestalts
.apprvers
>= 0x100)
1718 SetControlData(mc
->editbox
.tbctrl
, kControlEntireControl
,
1719 ctrl
->editbox
.password ?
1720 kControlEditTextPasswordTag
:
1721 kControlEditTextTextTag
,
1722 strlen(text
), text
);
1723 #if !TARGET_API_MAC_CARBON
1725 TESetText(text
, strlen(text
),
1726 (TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
);
1728 DrawOneControl(mc
->editbox
.tbctrl
);
1732 void dlg_editbox_get(union control
*ctrl
, void *dlg
, char *buffer
, int length
)
1734 struct macctrls
*mcs
= dlg
;
1735 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1739 assert(mc
->generic
.type
== MACCTRL_EDITBOX
);
1740 if (mac_gestalts
.apprvers
>= 0x100) {
1741 if (GetControlData(mc
->editbox
.tbctrl
, kControlEntireControl
,
1742 ctrl
->editbox
.password ?
1743 kControlEditTextPasswordTag
:
1744 kControlEditTextTextTag
,
1745 length
- 1, buffer
, &olen
) != noErr
)
1747 if (olen
> length
- 1)
1750 #if !TARGET_API_MAC_CARBON
1752 TEHandle te
= (TEHandle
)(*mc
->editbox
.tbctrl
)->contrlData
;
1754 olen
= (*te
)->teLength
;
1755 if (olen
> length
- 1)
1757 memcpy(buffer
, *(*te
)->hText
, olen
);
1760 buffer
[olen
] = '\0';
1768 static void dlg_macpopup_clear(union control
*ctrl
, void *dlg
)
1770 struct macctrls
*mcs
= dlg
;
1771 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1772 MenuRef menu
= mc
->popup
.menu
;
1775 if (mc
== NULL
) return;
1776 n
= CountMenuItems(menu
);
1777 for (i
= 0; i
< n
; i
++)
1778 DeleteMenuItem(menu
, n
- i
);
1780 sfree(mc
->popup
.ids
);
1781 mc
->popup
.ids
= NULL
;
1782 SetControlMaximum(mc
->popup
.tbctrl
, CountMenuItems(menu
));
1785 static void dlg_macedit_clear(union control
*ctrl
, void *dlg
)
1787 struct macctrls
*mcs
= dlg
;
1788 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1789 MenuRef menu
= mc
->editbox
.menu
;
1792 if (mc
== NULL
) return;
1793 n
= CountMenuItems(menu
);
1794 for (i
= 0; i
< n
; i
++)
1795 DeleteMenuItem(menu
, n
- i
);
1796 mc
->editbox
.nids
= 0;
1797 sfree(mc
->editbox
.ids
);
1798 mc
->editbox
.ids
= NULL
;
1799 SetControlMaximum(mc
->editbox
.tbbutton
, CountMenuItems(menu
));
1802 static void dlg_maclist_clear(union control
*ctrl
, void *dlg
)
1804 struct macctrls
*mcs
= dlg
;
1805 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1807 if (mc
== NULL
) return;
1808 LDelRow(0, 0, mc
->listbox
.list
);
1809 mc
->listbox
.nids
= 0;
1810 sfree(mc
->listbox
.ids
);
1811 mc
->listbox
.ids
= NULL
;
1812 DrawOneControl(mc
->listbox
.tbctrl
);
1815 void dlg_listbox_clear(union control
*ctrl
, void *dlg
)
1818 switch (ctrl
->generic
.type
) {
1820 if (ctrl
->listbox
.height
== 0)
1821 dlg_macpopup_clear(ctrl
, dlg
);
1823 dlg_maclist_clear(ctrl
, dlg
);
1826 dlg_macedit_clear(ctrl
, dlg
);
1830 static void dlg_macpopup_del(union control
*ctrl
, void *dlg
, int index
)
1832 struct macctrls
*mcs
= dlg
;
1833 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1834 MenuRef menu
= mc
->popup
.menu
;
1836 if (mc
== NULL
) return;
1837 DeleteMenuItem(menu
, index
+ 1);
1838 if (mc
->popup
.ids
!= NULL
)
1839 memcpy(mc
->popup
.ids
+ index
, mc
->popup
.ids
+ index
+ 1,
1840 (mc
->popup
.nids
- index
- 1) * sizeof(*mc
->popup
.ids
));
1841 SetControlMaximum(mc
->popup
.tbctrl
, CountMenuItems(menu
));
1844 static void dlg_macedit_del(union control
*ctrl
, void *dlg
, int index
)
1846 struct macctrls
*mcs
= dlg
;
1847 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1848 MenuRef menu
= mc
->editbox
.menu
;
1850 if (mc
== NULL
) return;
1851 DeleteMenuItem(menu
, index
+ 1);
1852 if (mc
->editbox
.ids
!= NULL
)
1853 memcpy(mc
->editbox
.ids
+ index
, mc
->editbox
.ids
+ index
+ 1,
1854 (mc
->editbox
.nids
- index
- 1) * sizeof(*mc
->editbox
.ids
));
1855 SetControlMaximum(mc
->editbox
.tbbutton
, CountMenuItems(menu
));
1858 static void dlg_maclist_del(union control
*ctrl
, void *dlg
, int index
)
1860 struct macctrls
*mcs
= dlg
;
1861 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1863 if (mc
== NULL
) return;
1864 LDelRow(1, index
, mc
->listbox
.list
);
1865 if (mc
->listbox
.ids
!= NULL
)
1866 memcpy(mc
->listbox
.ids
+ index
, mc
->listbox
.ids
+ index
+ 1,
1867 (mc
->listbox
.nids
- index
- 1) * sizeof(*mc
->listbox
.ids
));
1868 DrawOneControl(mc
->listbox
.tbctrl
);
1871 void dlg_listbox_del(union control
*ctrl
, void *dlg
, int index
)
1874 switch (ctrl
->generic
.type
) {
1876 if (ctrl
->listbox
.height
== 0)
1877 dlg_macpopup_del(ctrl
, dlg
, index
);
1879 dlg_maclist_del(ctrl
, dlg
, index
);
1882 dlg_macedit_del(ctrl
, dlg
, index
);
1886 static void dlg_macpopup_add(union control
*ctrl
, void *dlg
, char const *text
)
1888 struct macctrls
*mcs
= dlg
;
1889 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1890 MenuRef menu
= mc
->popup
.menu
;
1893 if (mc
== NULL
) return;
1894 assert(text
[0] != '\0');
1895 c2pstrcpy(itemstring
, text
);
1896 AppendMenu(menu
, "\pdummy");
1897 SetMenuItemText(menu
, CountMenuItems(menu
), itemstring
);
1898 SetControlMaximum(mc
->popup
.tbctrl
, CountMenuItems(menu
));
1901 static void dlg_macedit_add(union control
*ctrl
, void *dlg
, char const *text
)
1903 struct macctrls
*mcs
= dlg
;
1904 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1905 MenuRef menu
= mc
->editbox
.menu
;
1908 if (mc
== NULL
) return;
1909 assert(text
[0] != '\0');
1910 c2pstrcpy(itemstring
, text
);
1911 AppendMenu(menu
, "\pdummy");
1912 SetMenuItemText(menu
, CountMenuItems(menu
), itemstring
);
1913 SetControlMaximum(mc
->editbox
.tbbutton
, CountMenuItems(menu
));
1916 static void dlg_maclist_add(union control
*ctrl
, void *dlg
, char const *text
)
1918 struct macctrls
*mcs
= dlg
;
1919 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1921 Cell cell
= { 0, 0 };
1923 if (mc
== NULL
) return;
1924 #if TARGET_API_MAC_CARBON
1925 GetListDataBounds(mc
->listbox
.list
, &bounds
);
1927 bounds
= (*mc
->listbox
.list
)->dataBounds
;
1929 cell
.v
= bounds
.bottom
;
1930 LAddRow(1, cell
.v
, mc
->listbox
.list
);
1931 LSetCell(text
, strlen(text
), cell
, mc
->listbox
.list
);
1932 DrawOneControl(mc
->listbox
.tbctrl
);
1935 void dlg_listbox_add(union control
*ctrl
, void *dlg
, char const *text
)
1938 switch (ctrl
->generic
.type
) {
1940 if (ctrl
->listbox
.height
== 0)
1941 dlg_macpopup_add(ctrl
, dlg
, text
);
1943 dlg_maclist_add(ctrl
, dlg
, text
);
1946 dlg_macedit_add(ctrl
, dlg
, text
);
1951 static void dlg_macpopup_addwithid(union control
*ctrl
, void *dlg
,
1952 char const *text
, int id
)
1954 struct macctrls
*mcs
= dlg
;
1955 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1956 MenuRef menu
= mc
->popup
.menu
;
1959 if (mc
== NULL
) return;
1960 dlg_macpopup_add(ctrl
, dlg
, text
);
1961 index
= CountMenuItems(menu
) - 1;
1962 if (mc
->popup
.nids
<= index
) {
1963 mc
->popup
.nids
= index
+ 1;
1964 mc
->popup
.ids
= sresize(mc
->popup
.ids
, mc
->popup
.nids
, int);
1966 mc
->popup
.ids
[index
] = id
;
1969 static void dlg_macedit_addwithid(union control
*ctrl
, void *dlg
,
1970 char const *text
, int id
)
1972 struct macctrls
*mcs
= dlg
;
1973 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1974 MenuRef menu
= mc
->editbox
.menu
;
1977 if (mc
== NULL
) return;
1978 dlg_macedit_add(ctrl
, dlg
, text
);
1979 index
= CountMenuItems(menu
) - 1;
1980 if (mc
->editbox
.nids
<= index
) {
1981 mc
->editbox
.nids
= index
+ 1;
1982 mc
->editbox
.ids
= sresize(mc
->editbox
.ids
, mc
->editbox
.nids
, int);
1984 mc
->editbox
.ids
[index
] = id
;
1987 static void dlg_maclist_addwithid(union control
*ctrl
, void *dlg
,
1988 char const *text
, int id
)
1990 struct macctrls
*mcs
= dlg
;
1991 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
1995 if (mc
== NULL
) return;
1996 dlg_maclist_add(ctrl
, dlg
, text
);
1997 #if TARGET_API_MAC_CARBON
1998 GetListDataBounds(mc
->listbox
.list
, &bounds
);
2000 bounds
= (*mc
->listbox
.list
)->dataBounds
;
2002 index
= bounds
.bottom
;
2003 if (mc
->listbox
.nids
<= index
) {
2004 mc
->listbox
.nids
= index
+ 1;
2005 mc
->listbox
.ids
= sresize(mc
->listbox
.ids
, mc
->listbox
.nids
, int);
2007 mc
->listbox
.ids
[index
] = id
;
2010 void dlg_listbox_addwithid(union control
*ctrl
, void *dlg
,
2011 char const *text
, int id
)
2014 switch (ctrl
->generic
.type
) {
2016 if (ctrl
->listbox
.height
== 0)
2017 dlg_macpopup_addwithid(ctrl
, dlg
, text
, id
);
2019 dlg_maclist_addwithid(ctrl
, dlg
, text
, id
);
2022 dlg_macedit_addwithid(ctrl
, dlg
, text
, id
);
2027 int dlg_listbox_getid(union control
*ctrl
, void *dlg
, int index
)
2029 struct macctrls
*mcs
= dlg
;
2030 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
2033 switch (ctrl
->generic
.type
) {
2035 if (ctrl
->listbox
.height
== 0) {
2036 assert(mc
->popup
.ids
!= NULL
&& mc
->popup
.nids
> index
);
2037 return mc
->popup
.ids
[index
];
2039 assert(mc
->listbox
.ids
!= NULL
&& mc
->listbox
.nids
> index
);
2040 return mc
->listbox
.ids
[index
];
2043 assert(mc
->editbox
.ids
!= NULL
&& mc
->editbox
.nids
> index
);
2044 return mc
->editbox
.ids
[index
];
2049 int dlg_listbox_index(union control
*ctrl
, void *dlg
)
2051 struct macctrls
*mcs
= dlg
;
2052 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
2053 Cell cell
= { 0, 0 };
2056 switch (ctrl
->generic
.type
) {
2058 if (ctrl
->listbox
.height
== 0)
2059 return GetControlValue(mc
->popup
.tbctrl
) - 1;
2061 if (LGetSelect(TRUE
, &cell
, mc
->listbox
.list
))
2067 return GetControlValue(mc
->editbox
.tbbutton
) - 1;
2072 int dlg_listbox_issel(union control
*ctrl
, void *dlg
, int index
)
2074 struct macctrls
*mcs
= dlg
;
2075 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
2076 Cell cell
= { 0, 0 };
2079 switch (ctrl
->generic
.type
) {
2081 if (ctrl
->listbox
.height
== 0)
2082 return GetControlValue(mc
->popup
.tbctrl
) - 1 == index
;
2085 return LGetSelect(FALSE
, &cell
, mc
->listbox
.list
);
2088 return GetControlValue(mc
->editbox
.tbbutton
) - 1 == index
;
2093 void dlg_listbox_select(union control
*ctrl
, void *dlg
, int index
)
2095 struct macctrls
*mcs
= dlg
;
2096 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
2098 if (mc
== NULL
) return;
2099 switch (ctrl
->generic
.type
) {
2101 if (ctrl
->listbox
.height
== 0)
2102 SetControlValue(mc
->popup
.tbctrl
, index
+ 1);
2105 SetControlValue(mc
->editbox
.tbbutton
, index
+ 1);
2114 void dlg_text_set(union control
*ctrl
, void *dlg
, char const *text
)
2116 struct macctrls
*mcs
= dlg
;
2117 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
2119 if (mc
== NULL
) return;
2120 if (mac_gestalts
.apprvers
>= 0x100)
2121 SetControlData(mc
->text
.tbctrl
, kControlEntireControl
,
2122 kControlStaticTextTextTag
, strlen(text
), text
);
2123 #if !TARGET_API_MAC_CARBON
2125 TESetText(text
, strlen(text
),
2126 (TEHandle
)(*mc
->text
.tbctrl
)->contrlData
);
2132 * File Selector control
2135 void dlg_filesel_set(union control
*ctrl
, void *dlg
, Filename fn
)
2140 void dlg_filesel_get(union control
*ctrl
, void *dlg
, Filename
*fn
)
2147 * Font Selector control
2150 void dlg_fontsel_set(union control
*ctrl
, void *dlg
, FontSpec fn
)
2155 void dlg_fontsel_get(union control
*ctrl
, void *dlg
, FontSpec
*fn
)
2162 * Printer enumeration
2165 printer_enum
*printer_start_enum(int *nprinters
)
2172 char *printer_get_name(printer_enum
*pe
, int thing
)
2178 void printer_finish_enum(printer_enum
*pe
)
2185 * Colour selection stuff
2188 void dlg_coloursel_start(union control
*ctrl
, void *dlg
,
2189 int r
, int g
, int b
)
2191 struct macctrls
*mcs
= dlg
;
2192 union macctrl
*mc
= findbyctrl(mcs
, ctrl
);
2193 Point where
= {-1, -1}; /* Screen with greatest colour depth */
2196 if (HAVE_COLOR_QD()) {
2197 incolour
.red
= r
* 0x0101;
2198 incolour
.green
= g
* 0x0101;
2199 incolour
.blue
= b
* 0x0101;
2200 mcs
->gotcolour
= GetColor(where
, "\pModify Colour:", &incolour
,
2202 ctrlevent(mcs
, mc
, EVENT_CALLBACK
);
2207 int dlg_coloursel_results(union control
*ctrl
, void *dlg
,
2208 int *r
, int *g
, int *b
)
2210 struct macctrls
*mcs
= dlg
;
2212 if (mcs
->gotcolour
) {
2213 *r
= mcs
->thecolour
.red
>> 8;
2214 *g
= mcs
->thecolour
.green
>> 8;
2215 *b
= mcs
->thecolour
.blue
>> 8;
2223 * c-file-style: "simon"