Pass a pointer to the entire dialog box structure to event handlers, rather
[u/mdw/putty] / mac / macctrls.c
1 /* $Id: macctrls.c,v 1.7 2003/03/20 23:15:25 ben Exp $ */
2 /*
3 * Copyright (c) 2003 Ben Harris
4 * All rights reserved.
5 *
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
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
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
25 * SOFTWARE.
26 */
27
28 #include <MacTypes.h>
29 #include <Appearance.h>
30 #include <Controls.h>
31 #include <ControlDefinitions.h>
32 #include <Resources.h>
33 #include <Sound.h>
34 #include <TextUtils.h>
35 #include <Windows.h>
36
37 #include <assert.h>
38
39 #include "putty.h"
40 #include "mac.h"
41 #include "macresid.h"
42 #include "dialog.h"
43 #include "tree234.h"
44
45 union macctrl {
46 struct macctrl_generic {
47 enum {
48 MACCTRL_TEXT,
49 MACCTRL_RADIO,
50 MACCTRL_CHECKBOX,
51 MACCTRL_BUTTON
52 } type;
53 /* Template from which this was generated */
54 union control *ctrl;
55 } generic;
56 struct {
57 struct macctrl_generic generic;
58 ControlRef tbctrl;
59 } text;
60 struct {
61 struct macctrl_generic generic;
62 ControlRef *tbctrls;
63 } radio;
64 struct {
65 struct macctrl_generic generic;
66 ControlRef tbctrl;
67 } checkbox;
68 struct {
69 struct macctrl_generic generic;
70 ControlRef tbctrl;
71 } button;
72 };
73
74 struct mac_layoutstate {
75 Point pos;
76 unsigned int width;
77 };
78
79 #define ctrlevent(mcs, mc, event) do { \
80 if ((mc)->generic.ctrl->generic.handler != NULL) \
81 (*(mc)->generic.ctrl->generic.handler)((mc)->generic.ctrl, (mcs),\
82 (mcs)->data, (event)); \
83 } while (0)
84
85 #define findbyctrl(mcs, ctrl) \
86 find234((mcs)->byctrl, (ctrl), macctrl_cmp_byctrl_find)
87
88 static void macctrl_layoutset(struct mac_layoutstate *, struct controlset *,
89 WindowPtr, struct macctrls *);
90 static void macctrl_text(struct macctrls *, WindowPtr,
91 struct mac_layoutstate *, union control *);
92 static void macctrl_radio(struct macctrls *, WindowPtr,
93 struct mac_layoutstate *, union control *);
94 static void macctrl_checkbox(struct macctrls *, WindowPtr,
95 struct mac_layoutstate *, union control *);
96 static void macctrl_button(struct macctrls *, WindowPtr,
97 struct mac_layoutstate *, union control *);
98 #if !TARGET_API_MAC_CARBON
99 static pascal SInt32 macctrl_sys7_text_cdef(SInt16, ControlRef,
100 ControlDefProcMessage, SInt32);
101 static pascal SInt32 macctrl_sys7_default_cdef(SInt16, ControlRef,
102 ControlDefProcMessage, SInt32);
103 #endif
104
105 #if !TARGET_API_MAC_CARBON
106 /*
107 * This trick enables us to keep all the CDEF code in the main
108 * application, which makes life easier. For details, see
109 * <http://developer.apple.com/technotes/tn/tn2003.html#custom_code_base>.
110 */
111
112 #pragma options align=mac68k
113 typedef struct {
114 short jmpabs; /* 4EF9 */
115 ControlDefUPP theUPP;
116 } **PatchCDEF;
117 #pragma options align=reset
118 #endif
119
120 static void macctrl_init()
121 {
122 #if !TARGET_API_MAC_CARBON
123 static int inited = 0;
124 PatchCDEF cdef;
125
126 if (inited) return;
127 cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Text);
128 (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_text_cdef);
129 cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Default);
130 (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_default_cdef);
131 inited = 1;
132 #endif
133 }
134
135
136 static int macctrl_cmp_byctrl(void *av, void *bv)
137 {
138 union macctrl *a = (union macctrl *)av;
139 union macctrl *b = (union macctrl *)bv;
140
141 if (a->generic.ctrl < b->generic.ctrl)
142 return -1;
143 else if (a->generic.ctrl > b->generic.ctrl)
144 return +1;
145 else
146 return 0;
147 }
148
149 static int macctrl_cmp_byctrl_find(void *av, void *bv)
150 {
151 union control *a = (union control *)av;
152 union macctrl *b = (union macctrl *)bv;
153
154 if (a < b->generic.ctrl)
155 return -1;
156 else if (a > b->generic.ctrl)
157 return +1;
158 else
159 return 0;
160 }
161
162 void macctrl_layoutbox(struct controlbox *cb, WindowPtr window,
163 struct macctrls *mcs)
164 {
165 int i;
166 struct mac_layoutstate curstate;
167 ControlRef root;
168 Rect rect;
169
170 macctrl_init();
171 #if TARGET_API_MAC_CARBON
172 GetPortBounds(GetWindowPort(window), &rect);
173 #else
174 rect = window->portRect;
175 #endif
176 curstate.pos.h = rect.left + 13;
177 curstate.pos.v = rect.top + 13;
178 curstate.width = rect.right - rect.left - (13 * 2);
179 if (mac_gestalts.apprvers >= 0x100)
180 CreateRootControl(window, &root);
181 mcs->byctrl = newtree234(macctrl_cmp_byctrl);
182 for (i = 0; i < cb->nctrlsets; i++)
183 macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs);
184 }
185
186 static void macctrl_layoutset(struct mac_layoutstate *curstate,
187 struct controlset *s,
188 WindowPtr window, struct macctrls *mcs)
189 {
190 unsigned int i;
191
192 fprintf(stderr, "--- begin set ---\n");
193 fprintf(stderr, "pathname = %s\n", s->pathname);
194 if (s->boxname && *s->boxname)
195 fprintf(stderr, "boxname = %s\n", s->boxname);
196 if (s->boxtitle)
197 fprintf(stderr, "boxtitle = %s\n", s->boxtitle);
198
199
200 for (i = 0; i < s->ncontrols; i++) {
201 union control *ctrl = s->ctrls[i];
202 char const *s;
203
204 switch (ctrl->generic.type) {
205 case CTRL_TEXT: s = "text"; break;
206 case CTRL_EDITBOX: s = "editbox"; break;
207 case CTRL_RADIO: s = "radio"; break;
208 case CTRL_CHECKBOX: s = "checkbox"; break;
209 case CTRL_BUTTON: s = "button"; break;
210 case CTRL_LISTBOX: s = "listbox"; break;
211 case CTRL_COLUMNS: s = "columns"; break;
212 case CTRL_FILESELECT: s = "fileselect"; break;
213 case CTRL_FONTSELECT: s = "fontselect"; break;
214 case CTRL_TABDELAY: s = "tabdelay"; break;
215 default: s = "unknown"; break;
216 }
217 fprintf(stderr, " control: %s\n", s);
218 switch (ctrl->generic.type) {
219 case CTRL_TEXT:
220 macctrl_text(mcs, window, curstate, ctrl);
221 break;
222 case CTRL_RADIO:
223 macctrl_radio(mcs, window, curstate, ctrl);
224 break;
225 case CTRL_CHECKBOX:
226 macctrl_checkbox(mcs, window, curstate, ctrl);
227 break;
228 case CTRL_BUTTON:
229 macctrl_button(mcs, window, curstate, ctrl);
230 break;
231
232 }
233 }
234 }
235
236 static void macctrl_text(struct macctrls *mcs, WindowPtr window,
237 struct mac_layoutstate *curstate,
238 union control *ctrl)
239 {
240 union macctrl *mc = smalloc(sizeof *mc);
241 Rect bounds;
242
243 fprintf(stderr, " label = %s\n", ctrl->text.label);
244 mc->generic.type = MACCTRL_TEXT;
245 mc->generic.ctrl = ctrl;
246 bounds.left = curstate->pos.h;
247 bounds.right = bounds.left + curstate->width;
248 bounds.top = curstate->pos.v;
249 bounds.bottom = bounds.top + 16;
250 if (mac_gestalts.apprvers >= 0x100) {
251 SInt16 height;
252 Size olen;
253
254 mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
255 kControlStaticTextProc, (long)mc);
256 SetControlData(mc->text.tbctrl, kControlEntireControl,
257 kControlStaticTextTextTag,
258 strlen(ctrl->text.label), ctrl->text.label);
259 GetControlData(mc->text.tbctrl, kControlEntireControl,
260 kControlStaticTextTextHeightTag,
261 sizeof(height), &height, &olen);
262 fprintf(stderr, " height = %d\n", height);
263 SizeControl(mc->text.tbctrl, curstate->width, height);
264 curstate->pos.v += height + 6;
265 } else {
266 Str255 title;
267
268 c2pstrcpy(title, ctrl->text.label);
269 mc->text.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 0,
270 SYS7_TEXT_PROC, (long)mc);
271 }
272 add234(mcs->byctrl, mc);
273 }
274
275 #if !TARGET_API_MAC_CARBON
276 static pascal SInt32 macctrl_sys7_text_cdef(SInt16 variant, ControlRef control,
277 ControlDefProcMessage msg, SInt32 param)
278 {
279 RgnHandle rgn;
280
281 switch (msg) {
282 case drawCntl:
283 if ((*control)->contrlVis)
284 TETextBox((*control)->contrlTitle + 1, (*control)->contrlTitle[0],
285 &(*control)->contrlRect, teFlushDefault);
286 return 0;
287 case calcCRgns:
288 if (param & (1 << 31)) {
289 param &= ~(1 << 31);
290 goto calcthumbrgn;
291 }
292 /* FALLTHROUGH */
293 case calcCntlRgn:
294 rgn = (RgnHandle)param;
295 RectRgn(rgn, &(*control)->contrlRect);
296 return 0;
297 case calcThumbRgn:
298 calcthumbrgn:
299 rgn = (RgnHandle)param;
300 SetEmptyRgn(rgn);
301 return 0;
302 }
303
304 return 0;
305 }
306 #endif
307
308 static void macctrl_radio(struct macctrls *mcs, WindowPtr window,
309 struct mac_layoutstate *curstate,
310 union control *ctrl)
311 {
312 union macctrl *mc = smalloc(sizeof *mc);
313 Rect bounds;
314 Str255 title;
315 unsigned int i, colwidth;
316
317 fprintf(stderr, " label = %s\n", ctrl->radio.label);
318 mc->generic.type = MACCTRL_RADIO;
319 mc->generic.ctrl = ctrl;
320 mc->radio.tbctrls =
321 smalloc(sizeof(*mc->radio.tbctrls) * ctrl->radio.nbuttons);
322 colwidth = (curstate->width + 13) / ctrl->radio.ncolumns;
323 for (i = 0; i < ctrl->radio.nbuttons; i++) {
324 fprintf(stderr, " button = %s\n", ctrl->radio.buttons[i]);
325 bounds.top = curstate->pos.v;
326 bounds.bottom = bounds.top + 16;
327 bounds.left = curstate->pos.h + colwidth * (i % ctrl->radio.ncolumns);
328 if (i == ctrl->radio.nbuttons - 1 ||
329 i % ctrl->radio.ncolumns == ctrl->radio.ncolumns - 1) {
330 bounds.right = curstate->pos.h + curstate->width;
331 curstate->pos.v += 22;
332 } else
333 bounds.right = bounds.left + colwidth - 13;
334 c2pstrcpy(title, ctrl->radio.buttons[i]);
335 mc->radio.tbctrls[i] = NewControl(window, &bounds, title, TRUE,
336 0, 0, 1, radioButProc, (long)mc);
337 }
338 add234(mcs->byctrl, mc);
339 ctrlevent(mcs, mc, EVENT_REFRESH);
340 }
341
342 static void macctrl_checkbox(struct macctrls *mcs, WindowPtr window,
343 struct mac_layoutstate *curstate,
344 union control *ctrl)
345 {
346 union macctrl *mc = smalloc(sizeof *mc);
347 Rect bounds;
348 Str255 title;
349
350 fprintf(stderr, " label = %s\n", ctrl->checkbox.label);
351 mc->generic.type = MACCTRL_CHECKBOX;
352 mc->generic.ctrl = ctrl;
353 bounds.left = curstate->pos.h;
354 bounds.right = bounds.left + curstate->width;
355 bounds.top = curstate->pos.v;
356 bounds.bottom = bounds.top + 16;
357 c2pstrcpy(title, ctrl->checkbox.label);
358 mc->checkbox.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1,
359 checkBoxProc, (long)mc);
360 add234(mcs->byctrl, mc);
361 curstate->pos.v += 22;
362 ctrlevent(mcs, mc, EVENT_REFRESH);
363 }
364
365 static void macctrl_button(struct macctrls *mcs, WindowPtr window,
366 struct mac_layoutstate *curstate,
367 union control *ctrl)
368 {
369 union macctrl *mc = smalloc(sizeof *mc);
370 Rect bounds;
371 Str255 title;
372
373 fprintf(stderr, " label = %s\n", ctrl->button.label);
374 if (ctrl->button.isdefault)
375 fprintf(stderr, " is default\n");
376 mc->generic.type = MACCTRL_BUTTON;
377 mc->generic.ctrl = ctrl;
378 bounds.left = curstate->pos.h;
379 bounds.right = bounds.left + 100; /* XXX measure string */
380 bounds.top = curstate->pos.v;
381 bounds.bottom = bounds.top + 20;
382 c2pstrcpy(title, ctrl->button.label);
383 mc->button.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1,
384 pushButProc, (long)mc);
385 if (mac_gestalts.apprvers >= 0x100) {
386 Boolean isdefault = ctrl->button.isdefault;
387
388 SetControlData(mc->button.tbctrl, kControlEntireControl,
389 kControlPushButtonDefaultTag,
390 sizeof(isdefault), &isdefault);
391 } else if (ctrl->button.isdefault) {
392 InsetRect(&bounds, -4, -4);
393 NewControl(window, &bounds, title, TRUE, 0, 0, 1,
394 SYS7_DEFAULT_PROC, (long)mc);
395 }
396 if (mac_gestalts.apprvers >= 0x110) {
397 Boolean iscancel = ctrl->button.iscancel;
398
399 SetControlData(mc->button.tbctrl, kControlEntireControl,
400 kControlPushButtonCancelTag,
401 sizeof(iscancel), &iscancel);
402 }
403 add234(mcs->byctrl, mc);
404 curstate->pos.v += 26;
405 }
406
407 #if !TARGET_API_MAC_CARBON
408 static pascal SInt32 macctrl_sys7_default_cdef(SInt16 variant,
409 ControlRef control,
410 ControlDefProcMessage msg,
411 SInt32 param)
412 {
413 RgnHandle rgn;
414 Rect rect;
415 int oval;
416
417 switch (msg) {
418 case drawCntl:
419 if ((*control)->contrlVis) {
420 rect = (*control)->contrlRect;
421 PenNormal();
422 PenSize(3, 3);
423 oval = (rect.bottom - rect.top) / 2 + 2;
424 FrameRoundRect(&rect, oval, oval);
425 }
426 return 0;
427 case calcCRgns:
428 if (param & (1 << 31)) {
429 param &= ~(1 << 31);
430 goto calcthumbrgn;
431 }
432 /* FALLTHROUGH */
433 case calcCntlRgn:
434 rgn = (RgnHandle)param;
435 RectRgn(rgn, &(*control)->contrlRect);
436 return 0;
437 case calcThumbRgn:
438 calcthumbrgn:
439 rgn = (RgnHandle)param;
440 SetEmptyRgn(rgn);
441 return 0;
442 }
443
444 return 0;
445 }
446 #endif
447
448
449 void macctrl_activate(WindowPtr window, EventRecord *event)
450 {
451 Boolean active = (event->modifiers & activeFlag) != 0;
452 GrafPtr saveport;
453 ControlRef root;
454
455 GetPort(&saveport);
456 SetPort((GrafPtr)GetWindowPort(window));
457 if (mac_gestalts.apprvers >= 0x100) {
458 SetThemeWindowBackground(window, active ?
459 kThemeBrushModelessDialogBackgroundActive :
460 kThemeBrushModelessDialogBackgroundInactive,
461 TRUE);
462 GetRootControl(window, &root);
463 if (active)
464 ActivateControl(root);
465 else
466 DeactivateControl(root);
467 } else {
468 /* (De)activate controls one at a time */
469 }
470 SetPort(saveport);
471 }
472
473 void macctrl_click(WindowPtr window, EventRecord *event)
474 {
475 Point mouse;
476 ControlHandle control;
477 int part;
478 GrafPtr saveport;
479 union macctrl *mc;
480 struct macctrls *mcs = mac_winctrls(window);
481 int i;
482
483 GetPort(&saveport);
484 SetPort((GrafPtr)GetWindowPort(window));
485 mouse = event->where;
486 GlobalToLocal(&mouse);
487 part = FindControl(mouse, window, &control);
488 if (control != NULL)
489 if (TrackControl(control, mouse, NULL) != 0) {
490 mc = (union macctrl *)GetControlReference(control);
491 switch (mc->generic.type) {
492 case MACCTRL_RADIO:
493 for (i = 0; i < mc->generic.ctrl->radio.nbuttons; i++) {
494 if (mc->radio.tbctrls[i] == control)
495 SetControlValue(mc->radio.tbctrls[i],
496 kControlRadioButtonCheckedValue);
497 else
498 SetControlValue(mc->radio.tbctrls[i],
499 kControlRadioButtonUncheckedValue);
500 }
501 ctrlevent(mcs, mc, EVENT_VALCHANGE);
502 break;
503 case MACCTRL_CHECKBOX:
504 SetControlValue(control, !GetControlValue(control));
505 ctrlevent(mcs, mc, EVENT_VALCHANGE);
506 break;
507 case MACCTRL_BUTTON:
508 ctrlevent(mcs, mc, EVENT_ACTION);
509 break;
510 }
511 }
512 SetPort(saveport);
513 }
514
515 void macctrl_update(WindowPtr window)
516 {
517 #if TARGET_API_MAC_CARBON
518 RgnHandle visrgn;
519 #endif
520 Rect rect;
521 GrafPtr saveport;
522
523 BeginUpdate(window);
524 GetPort(&saveport);
525 SetPort((GrafPtr)GetWindowPort(window));
526 if (mac_gestalts.apprvers >= 0x101) {
527 #if TARGET_API_MAC_CARBON
528 GetPortBounds(GetWindowPort(window), &rect);
529 #else
530 rect = window->portRect;
531 #endif
532 InsetRect(&rect, -1, -1);
533 DrawThemeModelessDialogFrame(&rect, mac_frontwindow() == window ?
534 kThemeStateActive : kThemeStateInactive);
535 }
536 #if TARGET_API_MAC_CARBON
537 visrgn = NewRgn();
538 GetPortVisibleRegion(GetWindowPort(window), visrgn);
539 UpdateControls(window, visrgn);
540 DisposeRgn(visrgn);
541 #else
542 UpdateControls(window, window->visRgn);
543 #endif
544 SetPort(saveport);
545 EndUpdate(window);
546 }
547
548 #if TARGET_API_MAC_CARBON
549 #define EnableItem EnableMenuItem
550 #define DisableItem DisableMenuItem
551 #endif
552 void macctrl_adjustmenus(WindowPtr window)
553 {
554 MenuHandle menu;
555
556 menu = GetMenuHandle(mFile);
557 DisableItem(menu, iSave); /* XXX enable if modified */
558 EnableItem(menu, iSaveAs);
559 EnableItem(menu, iDuplicate);
560
561 menu = GetMenuHandle(mEdit);
562 DisableItem(menu, 0);
563 }
564
565 void macctrl_close(WindowPtr window)
566 {
567 struct macctrls *mcs = mac_winctrls(window);
568 union macctrl *mc;
569
570 while ((mc = index234(mcs->byctrl, 0)) != NULL) {
571 del234(mcs->byctrl, mc);
572 sfree(mc);
573 }
574
575 freetree234(mcs->byctrl);
576 mcs->byctrl = NULL;
577
578 /* XXX
579 DisposeWindow(window);
580 if (s->window == NULL)
581 sfree(s);
582 */
583 }
584
585 void dlg_update_start(union control *ctrl, void *dlg)
586 {
587
588 /* No-op for now */
589 }
590
591 void dlg_update_done(union control *ctrl, void *dlg)
592 {
593
594 /* No-op for now */
595 }
596
597 void dlg_set_focus(union control *ctrl, void *dlg)
598 {
599
600 if (mac_gestalts.apprvers >= 0x100) {
601 /* Use SetKeyboardFocus() */
602 } else {
603 /* Do our own mucking around */
604 }
605 }
606
607 union control *dlg_last_focused(union control *ctrl, void *dlg)
608 {
609
610 return NULL;
611 }
612
613 void dlg_beep(void *dlg)
614 {
615
616 SysBeep(30);
617 }
618
619 void dlg_error_msg(void *dlg, char *msg)
620 {
621 Str255 pmsg;
622
623 c2pstrcpy(pmsg, msg);
624 ParamText(pmsg, NULL, NULL, NULL);
625 StopAlert(128, NULL);
626 }
627
628 void dlg_end(void *dlg, int value)
629 {
630
631 };
632
633 void dlg_refresh(union control *ctrl, void *dlg)
634 {
635
636 };
637
638 void *dlg_get_privdata(union control *ctrl, void *dlg)
639 {
640
641 return NULL;
642 }
643
644 void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr)
645 {
646
647 fatalbox("dlg_set_privdata");
648 }
649
650 void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size)
651 {
652
653 fatalbox("dlg_alloc_privdata");
654 }
655
656
657 /*
658 * Radio Button control
659 */
660
661 void dlg_radiobutton_set(union control *ctrl, void *dlg, int whichbutton)
662 {
663 struct macctrls *mcs = dlg;
664 union macctrl *mc = findbyctrl(mcs, ctrl);
665 int i;
666
667 assert(mc != NULL);
668 for (i = 0; i < ctrl->radio.nbuttons; i++) {
669 if (i == whichbutton)
670 SetControlValue(mc->radio.tbctrls[i],
671 kControlRadioButtonCheckedValue);
672 else
673 SetControlValue(mc->radio.tbctrls[i],
674 kControlRadioButtonUncheckedValue);
675 }
676
677 };
678
679 int dlg_radiobutton_get(union control *ctrl, void *dlg)
680 {
681 struct macctrls *mcs = dlg;
682 union macctrl *mc = findbyctrl(mcs, ctrl);
683 int i;
684
685 assert(mc != NULL);
686 for (i = 0; i < ctrl->radio.nbuttons; i++) {
687 if (GetControlValue(mc->radio.tbctrls[i]) ==
688 kControlRadioButtonCheckedValue)
689 return i;
690 }
691 return -1;
692 };
693
694
695 /*
696 * Check Box control
697 */
698
699 void dlg_checkbox_set(union control *ctrl, void *dlg, int checked)
700 {
701 struct macctrls *mcs = dlg;
702 union macctrl *mc = findbyctrl(mcs, ctrl);
703
704 assert(mc != NULL);
705 SetControlValue(mc->checkbox.tbctrl,
706 checked ? kControlCheckBoxCheckedValue :
707 kControlCheckBoxUncheckedValue);
708 }
709
710 int dlg_checkbox_get(union control *ctrl, void *dlg)
711 {
712 struct macctrls *mcs = dlg;
713 union macctrl *mc = findbyctrl(mcs, ctrl);
714
715 assert(mc != NULL);
716 return GetControlValue(mc->checkbox.tbctrl);
717 }
718
719
720 /*
721 * Edit Box control
722 */
723
724 void dlg_editbox_set(union control *ctrl, void *dlg, char const *text)
725 {
726
727 };
728
729 void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length)
730 {
731
732 };
733
734
735 /*
736 * List Box control
737 */
738
739 void dlg_listbox_clear(union control *ctrl, void *dlg)
740 {
741
742 };
743
744 void dlg_listbox_del(union control *ctrl, void *dlg, int index)
745 {
746
747 };
748
749 void dlg_listbox_add(union control *ctrl, void *dlg, char const *text)
750 {
751
752 };
753
754 void dlg_listbox_addwithindex(union control *ctrl, void *dlg,
755 char const *text, int id)
756 {
757
758 };
759
760 int dlg_listbox_getid(union control *ctrl, void *dlg, int index)
761 {
762
763 return 0;
764 };
765
766 int dlg_listbox_index(union control *ctrl, void *dlg)
767 {
768
769 return 0;
770 };
771
772 int dlg_listbox_issel(union control *ctrl, void *dlg, int index)
773 {
774
775 return 0;
776 };
777
778 void dlg_listbox_select(union control *ctrl, void *dlg, int index)
779 {
780
781 };
782
783
784 /*
785 * Text control
786 */
787
788 void dlg_text_set(union control *ctrl, void *dlg, char const *text)
789 {
790 struct macctrls *mcs = dlg;
791 union macctrl *mc = findbyctrl(mcs, ctrl);
792 Str255 title;
793
794 assert(mc != NULL);
795 if (mac_gestalts.apprvers >= 0x100)
796 SetControlData(mc->text.tbctrl, kControlEntireControl,
797 kControlStaticTextTextTag,
798 strlen(ctrl->text.label), ctrl->text.label);
799 else {
800 c2pstrcpy(title, text);
801 SetControlTitle(mc->text.tbctrl, title);
802 }
803 }
804
805
806 /*
807 * File Selector control
808 */
809
810 void dlg_filesel_set(union control *ctrl, void *dlg, Filename fn)
811 {
812
813 }
814
815 void dlg_filesel_get(union control *ctrl, void *dlg, Filename *fn)
816 {
817
818 }
819
820
821 /*
822 * Font Selector control
823 */
824
825 void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec fn)
826 {
827
828 }
829
830 void dlg_fontsel_get(union control *ctrl, void *dlg, FontSpec *fn)
831 {
832
833 }
834
835
836 /*
837 * Printer enumeration
838 */
839
840 printer_enum *printer_start_enum(int *nprinters)
841 {
842
843 *nprinters = 0;
844 return NULL;
845 }
846
847 char *printer_get_name(printer_enum *pe, int thing)
848 {
849
850 return "<none>";
851 }
852
853 void printer_finish_enum(printer_enum *pe)
854 {
855
856 }
857
858
859 /*
860 * Colour selection stuff
861 */
862
863 void dlg_coloursel_start(union control *ctrl, void *dlg,
864 int r, int g, int b)
865 {
866
867 }
868
869 int dlg_coloursel_results(union control *ctrl, void *dlg,
870 int *r, int *g, int *b)
871 {
872
873 return 0;
874 }
875
876 /*
877 * Local Variables:
878 * c-file-style: "simon"
879 * End:
880 */