Don't call GetColor() if we don't have Color Quickdraw -- no good will come
[u/mdw/putty] / mac / macctrls.c
1 /* $Id: macctrls.c,v 1.36 2003/04/14 22:55:12 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 <ColorPicker.h>
31 #include <Controls.h>
32 #include <ControlDefinitions.h>
33 #include <Events.h>
34 #include <Lists.h>
35 #include <Menus.h>
36 #include <Resources.h>
37 #include <Script.h>
38 #include <Sound.h>
39 #include <TextEdit.h>
40 #include <TextUtils.h>
41 #include <ToolUtils.h>
42 #include <Windows.h>
43
44 #include <assert.h>
45 #include <string.h>
46
47 #include "putty.h"
48 #include "mac.h"
49 #include "macresid.h"
50 #include "dialog.h"
51 #include "tree234.h"
52
53 /* Range of menu IDs for popup menus */
54 #define MENU_MIN 1024
55 #define MENU_MAX 2048
56
57
58 union macctrl {
59 struct macctrl_generic {
60 enum {
61 MACCTRL_TEXT,
62 MACCTRL_EDITBOX,
63 MACCTRL_RADIO,
64 MACCTRL_CHECKBOX,
65 MACCTRL_BUTTON,
66 MACCTRL_LISTBOX,
67 MACCTRL_POPUP
68 } type;
69 /* Template from which this was generated */
70 union control *ctrl;
71 /* Next control in this panel */
72 union macctrl *next;
73 void *privdata;
74 int freeprivdata;
75 } generic;
76 struct {
77 struct macctrl_generic generic;
78 ControlRef tbctrl;
79 } text;
80 struct {
81 struct macctrl_generic generic;
82 ControlRef tbctrl;
83 ControlRef tblabel;
84 } editbox;
85 struct {
86 struct macctrl_generic generic;
87 ControlRef *tbctrls;
88 ControlRef tblabel;
89 } radio;
90 struct {
91 struct macctrl_generic generic;
92 ControlRef tbctrl;
93 } checkbox;
94 struct {
95 struct macctrl_generic generic;
96 ControlRef tbctrl;
97 ControlRef tbring;
98 } button;
99 struct {
100 struct macctrl_generic generic;
101 ControlRef tbctrl;
102 ListHandle list;
103 unsigned int nids;
104 int *ids;
105 } listbox;
106 struct {
107 struct macctrl_generic generic;
108 ControlRef tbctrl;
109 MenuRef menu;
110 int menuid;
111 unsigned int nids;
112 int *ids;
113 } popup;
114 };
115
116 struct mac_layoutstate {
117 Point pos;
118 unsigned int width;
119 unsigned int panelnum;
120 };
121
122 #define ctrlevent(mcs, mc, event) do { \
123 if ((mc)->generic.ctrl->generic.handler != NULL) \
124 (*(mc)->generic.ctrl->generic.handler)((mc)->generic.ctrl, (mcs),\
125 (mcs)->data, (event)); \
126 } while (0)
127
128 #define findbyctrl(mcs, ctrl) \
129 find234((mcs)->byctrl, (ctrl), macctrl_cmp_byctrl_find)
130
131 static void macctrl_layoutset(struct mac_layoutstate *, struct controlset *,
132 WindowPtr, struct macctrls *);
133 static void macctrl_switchtopanel(struct macctrls *, unsigned int);
134 static void macctrl_setfocus(struct macctrls *, union macctrl *);
135 static void macctrl_text(struct macctrls *, WindowPtr,
136 struct mac_layoutstate *, union control *);
137 static void macctrl_editbox(struct macctrls *, WindowPtr,
138 struct mac_layoutstate *, union control *);
139 static void macctrl_radio(struct macctrls *, WindowPtr,
140 struct mac_layoutstate *, union control *);
141 static void macctrl_checkbox(struct macctrls *, WindowPtr,
142 struct mac_layoutstate *, union control *);
143 static void macctrl_button(struct macctrls *, WindowPtr,
144 struct mac_layoutstate *, union control *);
145 static void macctrl_listbox(struct macctrls *, WindowPtr,
146 struct mac_layoutstate *, union control *);
147 static void macctrl_popup(struct macctrls *, WindowPtr,
148 struct mac_layoutstate *, union control *);
149 #if !TARGET_API_MAC_CARBON
150 static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16, ControlRef,
151 ControlDefProcMessage, SInt32);
152 static pascal SInt32 macctrl_sys7_default_cdef(SInt16, ControlRef,
153 ControlDefProcMessage, SInt32);
154 static pascal SInt32 macctrl_sys7_listbox_cdef(SInt16, ControlRef,
155 ControlDefProcMessage, SInt32);
156 #endif
157
158 #if !TARGET_API_MAC_CARBON
159 /*
160 * This trick enables us to keep all the CDEF code in the main
161 * application, which makes life easier. For details, see
162 * <http://developer.apple.com/technotes/tn/tn2003.html#custom_code_base>.
163 */
164
165 #pragma options align=mac68k
166 typedef struct {
167 short jmpabs; /* 4EF9 */
168 ControlDefUPP theUPP;
169 } **PatchCDEF;
170 #pragma options align=reset
171 #endif
172
173 static void macctrl_init()
174 {
175 #if !TARGET_API_MAC_CARBON
176 static int inited = 0;
177 PatchCDEF cdef;
178
179 if (inited) return;
180 cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_EditBox);
181 (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_editbox_cdef);
182 cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Default);
183 (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_default_cdef);
184 cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_ListBox);
185 (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_listbox_cdef);
186 inited = 1;
187 #endif
188 }
189
190
191 static int macctrl_cmp_byctrl(void *av, void *bv)
192 {
193 union macctrl *a = (union macctrl *)av;
194 union macctrl *b = (union macctrl *)bv;
195
196 if (a->generic.ctrl < b->generic.ctrl)
197 return -1;
198 else if (a->generic.ctrl > b->generic.ctrl)
199 return +1;
200 else
201 return 0;
202 }
203
204 static int macctrl_cmp_byctrl_find(void *av, void *bv)
205 {
206 union control *a = (union control *)av;
207 union macctrl *b = (union macctrl *)bv;
208
209 if (a < b->generic.ctrl)
210 return -1;
211 else if (a > b->generic.ctrl)
212 return +1;
213 else
214 return 0;
215 }
216
217 static union control panellist;
218
219 static void panellist_handler(union control *ctrl, void *dlg, void *data,
220 int event)
221 {
222 struct macctrls *mcs = dlg;
223
224 if (event == EVENT_SELCHANGE)
225 macctrl_switchtopanel(mcs, dlg_listbox_index(ctrl, dlg) + 1);
226 }
227
228 void macctrl_layoutbox(struct controlbox *cb, WindowPtr window,
229 struct macctrls *mcs)
230 {
231 int i;
232 struct mac_layoutstate curstate;
233 ControlRef root;
234 Rect rect;
235
236 macctrl_init();
237 if (mac_gestalts.apprvers >= 0x100)
238 CreateRootControl(window, &root);
239 #if TARGET_API_MAC_CARBON
240 GetPortBounds(GetWindowPort(window), &rect);
241 #else
242 rect = window->portRect;
243 #endif
244 mcs->window = window;
245 mcs->byctrl = newtree234(macctrl_cmp_byctrl);
246 mcs->focus = NULL;
247 mcs->defbutton = NULL;
248 mcs->canbutton = NULL;
249 /* Count the number of panels */
250 mcs->npanels = 1;
251 for (i = 1; i < cb->nctrlsets; i++)
252 if (strcmp(cb->ctrlsets[i]->pathname, cb->ctrlsets[i-1]->pathname))
253 mcs->npanels++;
254 mcs->panels = snewn(mcs->npanels, union macctrl *);
255 memset(mcs->panels, 0, sizeof(*mcs->panels) * mcs->npanels);
256 curstate.panelnum = 0;
257
258 curstate.pos.h = rect.left + 13;
259 curstate.pos.v = rect.top + 13;
260 curstate.width = 160;
261 panellist.listbox.type = CTRL_LISTBOX;
262 panellist.listbox.handler = &panellist_handler;
263 panellist.listbox.height = 15;
264 panellist.listbox.percentwidth = 100;
265 macctrl_listbox(mcs, window, &curstate, &panellist);
266
267 curstate.pos.h = rect.left + 13 + 160 + 13;
268 curstate.pos.v = rect.bottom - 33;
269 curstate.width = rect.right - (rect.left + 13 + 160) - (13 * 2);
270 for (i = 0; i < cb->nctrlsets; i++) {
271 if (i > 0 && strcmp(cb->ctrlsets[i]->pathname,
272 cb->ctrlsets[i-1]->pathname)) {
273 curstate.pos.v = rect.top + 13;
274 curstate.panelnum++;
275 assert(curstate.panelnum < mcs->npanels);
276 dlg_listbox_add(&panellist, mcs, cb->ctrlsets[i]->pathname);
277 }
278 macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs);
279 }
280 macctrl_switchtopanel(mcs, 1);
281 /* 14 = proxies, 19 = portfwd, 20 = SSH bugs */
282 }
283
284 #define MAXCOLS 16
285
286 static void macctrl_layoutset(struct mac_layoutstate *curstate,
287 struct controlset *s,
288 WindowPtr window, struct macctrls *mcs)
289 {
290 unsigned int i, j, ncols, colstart;
291 struct mac_layoutstate cols[MAXCOLS];
292
293 fprintf(stderr, "--- begin set ---\n");
294 fprintf(stderr, "pathname = %s\n", s->pathname);
295 if (s->boxname && *s->boxname)
296 fprintf(stderr, "boxname = %s\n", s->boxname);
297 if (s->boxtitle)
298 fprintf(stderr, "boxtitle = %s\n", s->boxtitle);
299
300 cols[0] = *curstate;
301 ncols = 1;
302
303 for (i = 0; i < s->ncontrols; i++) {
304 union control *ctrl = s->ctrls[i];
305 char const *s;
306
307 colstart = COLUMN_START(ctrl->generic.column);
308 switch (ctrl->generic.type) {
309 case CTRL_TEXT: s = "text"; break;
310 case CTRL_EDITBOX: s = "editbox"; break;
311 case CTRL_RADIO: s = "radio"; break;
312 case CTRL_CHECKBOX: s = "checkbox"; break;
313 case CTRL_BUTTON: s = "button"; break;
314 case CTRL_LISTBOX: s = "listbox"; break;
315 case CTRL_COLUMNS: s = "columns"; break;
316 case CTRL_FILESELECT: s = "fileselect"; break;
317 case CTRL_FONTSELECT: s = "fontselect"; break;
318 case CTRL_TABDELAY: s = "tabdelay"; break;
319 default: s = "unknown"; break;
320 }
321 fprintf(stderr, " control: %s\n", s);
322 switch (ctrl->generic.type) {
323 case CTRL_COLUMNS:
324 if (ctrl->columns.ncols != 1) {
325 ncols = ctrl->columns.ncols;
326 fprintf(stderr, " split to %d\n", ncols);
327 assert(ncols <= MAXCOLS);
328 for (j = 0; j < ncols; j++) {
329 cols[j] = cols[0];
330 if (j > 0)
331 cols[j].pos.h = cols[j-1].pos.h + cols[j-1].width + 6;
332 if (j == ncols - 1)
333 cols[j].width = curstate->width -
334 (cols[j].pos.h - curstate->pos.h);
335 else
336 cols[j].width = (curstate->width + 6) *
337 ctrl->columns.percentages[j] / 100 - 6;
338 }
339 } else {
340 fprintf(stderr, " join\n");
341 for (j = 0; j < ncols; j++)
342 if (cols[j].pos.v > cols[0].pos.v)
343 cols[0].pos.v = cols[j].pos.v;
344 cols[0].width = curstate->width;
345 ncols = 1;
346 }
347 break;
348 case CTRL_TEXT:
349 macctrl_text(mcs, window, &cols[colstart], ctrl);
350 break;
351 case CTRL_EDITBOX:
352 macctrl_editbox(mcs, window, &cols[colstart], ctrl);
353 break;
354 case CTRL_RADIO:
355 macctrl_radio(mcs, window, &cols[colstart], ctrl);
356 break;
357 case CTRL_CHECKBOX:
358 macctrl_checkbox(mcs, window, &cols[colstart], ctrl);
359 break;
360 case CTRL_BUTTON:
361 macctrl_button(mcs, window, &cols[colstart], ctrl);
362 break;
363 case CTRL_LISTBOX:
364 if (ctrl->listbox.height == 0)
365 macctrl_popup(mcs, window, &cols[colstart], ctrl);
366 else
367 macctrl_listbox(mcs, window, &cols[colstart], ctrl);
368 break;
369 }
370 }
371 for (j = 0; j < ncols; j++)
372 if (cols[j].pos.v > curstate->pos.v)
373 curstate->pos.v = cols[j].pos.v;
374 }
375
376 static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which)
377 {
378 unsigned int i, j;
379 union macctrl *mc;
380
381 #define hideshow(c) do { \
382 if (i == which) ShowControl(c); else HideControl(c); \
383 } while (0)
384
385 mcs->curpanel = which;
386 /* Panel 0 is special and always visible. */
387 for (i = 1; i < mcs->npanels; i++)
388 for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) {
389 #if !TARGET_API_MAC_CARBON
390 if (mcs->focus == mc)
391 macctrl_setfocus(mcs, NULL);
392 #endif
393 switch (mc->generic.type) {
394 case MACCTRL_TEXT:
395 hideshow(mc->text.tbctrl);
396 break;
397 case MACCTRL_EDITBOX:
398 hideshow(mc->editbox.tbctrl);
399 if (mc->editbox.tblabel != NULL)
400 hideshow(mc->editbox.tblabel);
401 break;
402 case MACCTRL_RADIO:
403 for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
404 hideshow(mc->radio.tbctrls[j]);
405 if (mc->radio.tblabel != NULL)
406 hideshow(mc->radio.tblabel);
407 break;
408 case MACCTRL_CHECKBOX:
409 hideshow(mc->checkbox.tbctrl);
410 break;
411 case MACCTRL_BUTTON:
412 hideshow(mc->button.tbctrl);
413 break;
414 case MACCTRL_LISTBOX:
415 hideshow(mc->listbox.tbctrl);
416 /*
417 * At least under Mac OS 8.1, hiding a list box
418 * doesn't hide its scroll bars.
419 */
420 #if TARGET_API_MAC_CARBON
421 hideshow(GetListVerticalScrollBar(mc->listbox.list));
422 #else
423 hideshow((*mc->listbox.list)->vScroll);
424 #endif
425 break;
426 case MACCTRL_POPUP:
427 hideshow(mc->popup.tbctrl);
428 break;
429 }
430 }
431 }
432
433 #if !TARGET_API_MAC_CARBON
434 /*
435 * System 7 focus manipulation
436 */
437 static void macctrl_defocus(union macctrl *mc)
438 {
439
440 assert(mac_gestalts.apprvers < 0x100);
441 switch (mc->generic.type) {
442 case MACCTRL_EDITBOX:
443 TEDeactivate((TEHandle)(*mc->editbox.tbctrl)->contrlData);
444 break;
445 }
446 }
447
448 static void macctrl_enfocus(union macctrl *mc)
449 {
450
451 assert(mac_gestalts.apprvers < 0x100);
452 switch (mc->generic.type) {
453 case MACCTRL_EDITBOX:
454 TEActivate((TEHandle)(*mc->editbox.tbctrl)->contrlData);
455 break;
456 }
457 }
458
459 static void macctrl_setfocus(struct macctrls *mcs, union macctrl *mc)
460 {
461
462 if (mcs->focus == mc)
463 return;
464 if (mcs->focus != NULL)
465 macctrl_defocus(mcs->focus);
466 mcs->focus = mc;
467 if (mc != NULL)
468 macctrl_enfocus(mc);
469 }
470 #endif
471
472 static void macctrl_text(struct macctrls *mcs, WindowPtr window,
473 struct mac_layoutstate *curstate,
474 union control *ctrl)
475 {
476 union macctrl *mc = snew(union macctrl);
477 Rect bounds;
478 SInt16 height;
479
480 assert(ctrl->text.label != NULL);
481 fprintf(stderr, " label = %s\n", ctrl->text.label);
482 mc->generic.type = MACCTRL_TEXT;
483 mc->generic.ctrl = ctrl;
484 mc->generic.privdata = NULL;
485 bounds.left = curstate->pos.h;
486 bounds.right = bounds.left + curstate->width;
487 bounds.top = curstate->pos.v;
488 bounds.bottom = bounds.top + 16;
489 if (mac_gestalts.apprvers >= 0x100) {
490 Size olen;
491
492 mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
493 kControlStaticTextProc, (long)mc);
494 SetControlData(mc->text.tbctrl, kControlEntireControl,
495 kControlStaticTextTextTag,
496 strlen(ctrl->text.label), ctrl->text.label);
497 GetControlData(mc->text.tbctrl, kControlEntireControl,
498 kControlStaticTextTextHeightTag,
499 sizeof(height), &height, &olen);
500 }
501 #if !TARGET_API_MAC_CARBON
502 else {
503 TEHandle te;
504
505 mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
506 SYS7_TEXT_PROC, (long)mc);
507 te = (TEHandle)(*mc->text.tbctrl)->contrlData;
508 TESetText(ctrl->text.label, strlen(ctrl->text.label), te);
509 height = TEGetHeight(1, (*te)->nLines, te);
510 }
511 #endif
512 fprintf(stderr, " height = %d\n", height);
513 SizeControl(mc->text.tbctrl, curstate->width, height);
514 curstate->pos.v += height + 6;
515 add234(mcs->byctrl, mc);
516 mc->generic.next = mcs->panels[curstate->panelnum];
517 mcs->panels[curstate->panelnum] = mc;
518 }
519
520 static void macctrl_editbox(struct macctrls *mcs, WindowPtr window,
521 struct mac_layoutstate *curstate,
522 union control *ctrl)
523 {
524 union macctrl *mc = snew(union macctrl);
525 Rect lbounds, bounds;
526
527 if (ctrl->editbox.label != NULL)
528 fprintf(stderr, " label = %s\n", ctrl->editbox.label);
529 fprintf(stderr, " percentwidth = %d\n", ctrl->editbox.percentwidth);
530 if (ctrl->editbox.password) fprintf(stderr, " password\n");
531 if (ctrl->editbox.has_list) fprintf(stderr, " has list\n");
532 mc->generic.type = MACCTRL_EDITBOX;
533 mc->generic.ctrl = ctrl;
534 mc->generic.privdata = NULL;
535 lbounds.left = curstate->pos.h;
536 lbounds.top = curstate->pos.v;
537 if (ctrl->editbox.percentwidth == 100) {
538 if (ctrl->editbox.label != NULL) {
539 lbounds.right = lbounds.left + curstate->width;
540 lbounds.bottom = lbounds.top + 16;
541 curstate->pos.v += 18;
542 }
543 bounds.left = curstate->pos.h;
544 bounds.right = bounds.left + curstate->width;
545 } else {
546 lbounds.right = lbounds.left +
547 curstate->width * (100 - ctrl->editbox.percentwidth) / 100;
548 lbounds.bottom = lbounds.top + 22;
549 bounds.left = lbounds.right;
550 bounds.right = lbounds.left + curstate->width;
551 }
552 bounds.top = curstate->pos.v;
553 bounds.bottom = bounds.top + 22;
554 if (mac_gestalts.apprvers >= 0x100) {
555 if (ctrl->editbox.label == NULL)
556 mc->editbox.tblabel = NULL;
557 else {
558 mc->editbox.tblabel = NewControl(window, &lbounds, NULL, TRUE,
559 0, 0, 0, kControlStaticTextProc,
560 (long)mc);
561 SetControlData(mc->editbox.tblabel, kControlEntireControl,
562 kControlStaticTextTextTag,
563 strlen(ctrl->editbox.label), ctrl->editbox.label);
564 }
565 InsetRect(&bounds, 3, 3);
566 mc->editbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
567 ctrl->editbox.password ?
568 kControlEditTextPasswordProc :
569 kControlEditTextProc, (long)mc);
570 }
571 #if !TARGET_API_MAC_CARBON
572 else {
573 if (ctrl->editbox.label == NULL)
574 mc->editbox.tblabel = NULL;
575 else {
576 mc->editbox.tblabel = NewControl(window, &lbounds, NULL, TRUE,
577 0, 0, 0, SYS7_TEXT_PROC,
578 (long)mc);
579 TESetText(ctrl->editbox.label, strlen(ctrl->editbox.label),
580 (TEHandle)(*mc->editbox.tblabel)->contrlData);
581 }
582 mc->editbox.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
583 SYS7_EDITBOX_PROC, (long)mc);
584 }
585 #endif
586 curstate->pos.v += 28;
587 add234(mcs->byctrl, mc);
588 mc->generic.next = mcs->panels[curstate->panelnum];
589 mcs->panels[curstate->panelnum] = mc;
590 ctrlevent(mcs, mc, EVENT_REFRESH);
591 }
592
593 #if !TARGET_API_MAC_CARBON
594 static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16 variant,
595 ControlRef control,
596 ControlDefProcMessage msg,
597 SInt32 param)
598 {
599 RgnHandle rgn;
600 Rect rect;
601 TEHandle te;
602 long ssfs;
603 Point mouse;
604
605 switch (msg) {
606 case initCntl:
607 rect = (*control)->contrlRect;
608 if (variant == SYS7_EDITBOX_VARIANT)
609 InsetRect(&rect, 3, 3); /* 2 if it's 20 pixels high */
610 te = TENew(&rect, &rect);
611 ssfs = GetScriptVariable(smSystemScript, smScriptSysFondSize);
612 (*te)->txSize = LoWord(ssfs);
613 (*te)->txFont = HiWord(ssfs);
614 (*control)->contrlData = (Handle)te;
615 return noErr;
616 case dispCntl:
617 TEDispose((TEHandle)(*control)->contrlData);
618 return 0;
619 case drawCntl:
620 if ((*control)->contrlVis) {
621 rect = (*control)->contrlRect;
622 if (variant == SYS7_EDITBOX_VARIANT) {
623 PenNormal();
624 FrameRect(&rect);
625 InsetRect(&rect, 3, 3);
626 }
627 (*(TEHandle)(*control)->contrlData)->viewRect = rect;
628 TEUpdate(&rect, (TEHandle)(*control)->contrlData);
629 }
630 return 0;
631 case testCntl:
632 if (variant == SYS7_TEXT_VARIANT)
633 return kControlNoPart;
634 mouse.h = LoWord(param);
635 mouse.v = HiWord(param);
636 rect = (*control)->contrlRect;
637 InsetRect(&rect, 3, 3);
638 return PtInRect(mouse, &rect) ? kControlEditTextPart : kControlNoPart;
639 case calcCRgns:
640 if (param & (1 << 31)) {
641 param &= ~(1 << 31);
642 goto calcthumbrgn;
643 }
644 /* FALLTHROUGH */
645 case calcCntlRgn:
646 rgn = (RgnHandle)param;
647 RectRgn(rgn, &(*control)->contrlRect);
648 return 0;
649 case calcThumbRgn:
650 calcthumbrgn:
651 rgn = (RgnHandle)param;
652 SetEmptyRgn(rgn);
653 return 0;
654 }
655
656 return 0;
657 }
658 #endif
659
660 static void macctrl_radio(struct macctrls *mcs, WindowPtr window,
661 struct mac_layoutstate *curstate,
662 union control *ctrl)
663 {
664 union macctrl *mc = snew(union macctrl);
665 Rect bounds;
666 Str255 title;
667 unsigned int i, colwidth;
668
669 if (ctrl->radio.label != NULL)
670 fprintf(stderr, " label = %s\n", ctrl->radio.label);
671 mc->generic.type = MACCTRL_RADIO;
672 mc->generic.ctrl = ctrl;
673 mc->generic.privdata = NULL;
674 mc->radio.tbctrls = snewn(ctrl->radio.nbuttons, ControlRef);
675 colwidth = (curstate->width + 13) / ctrl->radio.ncolumns;
676 bounds.top = curstate->pos.v;
677 bounds.bottom = bounds.top + 16;
678 bounds.left = curstate->pos.h;
679 bounds.right = bounds.left + curstate->width;
680 if (ctrl->radio.label == NULL)
681 mc->radio.tblabel = NULL;
682 else {
683 if (mac_gestalts.apprvers >= 0x100) {
684 mc->radio.tblabel = NewControl(window, &bounds, NULL, TRUE,
685 0, 0, 0, kControlStaticTextProc,
686 (long)mc);
687 SetControlData(mc->radio.tblabel, kControlEntireControl,
688 kControlStaticTextTextTag,
689 strlen(ctrl->radio.label), ctrl->radio.label);
690 }
691 #if !TARGET_API_MAC_CARBON
692 else {
693 mc->radio.tblabel = NewControl(window, &bounds, NULL, TRUE,
694 0, 0, 0, SYS7_TEXT_PROC, (long)mc);
695 TESetText(ctrl->radio.label, strlen(ctrl->radio.label),
696 (TEHandle)(*mc->radio.tblabel)->contrlData);
697 }
698 #endif
699 curstate->pos.v += 18;
700 }
701 for (i = 0; i < ctrl->radio.nbuttons; i++) {
702 fprintf(stderr, " button = %s\n", ctrl->radio.buttons[i]);
703 bounds.top = curstate->pos.v - 2;
704 bounds.bottom = bounds.top + 18;
705 bounds.left = curstate->pos.h + colwidth * (i % ctrl->radio.ncolumns);
706 if (i == ctrl->radio.nbuttons - 1 ||
707 i % ctrl->radio.ncolumns == ctrl->radio.ncolumns - 1) {
708 bounds.right = curstate->pos.h + curstate->width;
709 curstate->pos.v += 18;
710 } else
711 bounds.right = bounds.left + colwidth - 13;
712 c2pstrcpy(title, ctrl->radio.buttons[i]);
713 mc->radio.tbctrls[i] = NewControl(window, &bounds, title, TRUE,
714 0, 0, 1, radioButProc, (long)mc);
715 }
716 curstate->pos.v += 4;
717 add234(mcs->byctrl, mc);
718 mc->generic.next = mcs->panels[curstate->panelnum];
719 mcs->panels[curstate->panelnum] = mc;
720 ctrlevent(mcs, mc, EVENT_REFRESH);
721 }
722
723 static void macctrl_checkbox(struct macctrls *mcs, WindowPtr window,
724 struct mac_layoutstate *curstate,
725 union control *ctrl)
726 {
727 union macctrl *mc = snew(union macctrl);
728 Rect bounds;
729 Str255 title;
730
731 assert(ctrl->checkbox.label != NULL);
732 fprintf(stderr, " label = %s\n", ctrl->checkbox.label);
733 mc->generic.type = MACCTRL_CHECKBOX;
734 mc->generic.ctrl = ctrl;
735 mc->generic.privdata = NULL;
736 bounds.left = curstate->pos.h;
737 bounds.right = bounds.left + curstate->width;
738 bounds.top = curstate->pos.v;
739 bounds.bottom = bounds.top + 16;
740 c2pstrcpy(title, ctrl->checkbox.label);
741 mc->checkbox.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1,
742 checkBoxProc, (long)mc);
743 add234(mcs->byctrl, mc);
744 curstate->pos.v += 22;
745 mc->generic.next = mcs->panels[curstate->panelnum];
746 mcs->panels[curstate->panelnum] = mc;
747 ctrlevent(mcs, mc, EVENT_REFRESH);
748 }
749
750 static void macctrl_button(struct macctrls *mcs, WindowPtr window,
751 struct mac_layoutstate *curstate,
752 union control *ctrl)
753 {
754 union macctrl *mc = snew(union macctrl);
755 Rect bounds;
756 Str255 title;
757
758 assert(ctrl->button.label != NULL);
759 fprintf(stderr, " label = %s\n", ctrl->button.label);
760 if (ctrl->button.isdefault)
761 fprintf(stderr, " is default\n");
762 mc->generic.type = MACCTRL_BUTTON;
763 mc->generic.ctrl = ctrl;
764 mc->generic.privdata = NULL;
765 bounds.left = curstate->pos.h;
766 bounds.right = bounds.left + curstate->width;
767 bounds.top = curstate->pos.v;
768 bounds.bottom = bounds.top + 20;
769 c2pstrcpy(title, ctrl->button.label);
770 mc->button.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1,
771 pushButProc, (long)mc);
772 mc->button.tbring = NULL;
773 if (mac_gestalts.apprvers >= 0x100) {
774 Boolean isdefault = ctrl->button.isdefault;
775
776 SetControlData(mc->button.tbctrl, kControlEntireControl,
777 kControlPushButtonDefaultTag,
778 sizeof(isdefault), &isdefault);
779 } else if (ctrl->button.isdefault) {
780 InsetRect(&bounds, -4, -4);
781 mc->button.tbring = NewControl(window, &bounds, title, TRUE, 0, 0, 1,
782 SYS7_DEFAULT_PROC, (long)mc);
783 }
784 if (mac_gestalts.apprvers >= 0x110) {
785 Boolean iscancel = ctrl->button.iscancel;
786
787 SetControlData(mc->button.tbctrl, kControlEntireControl,
788 kControlPushButtonCancelTag,
789 sizeof(iscancel), &iscancel);
790 }
791 if (ctrl->button.isdefault)
792 mcs->defbutton = mc;
793 if (ctrl->button.iscancel)
794 mcs->canbutton = mc;
795 add234(mcs->byctrl, mc);
796 mc->generic.next = mcs->panels[curstate->panelnum];
797 mcs->panels[curstate->panelnum] = mc;
798 curstate->pos.v += 26;
799 }
800
801 #if !TARGET_API_MAC_CARBON
802 static pascal SInt32 macctrl_sys7_default_cdef(SInt16 variant,
803 ControlRef control,
804 ControlDefProcMessage msg,
805 SInt32 param)
806 {
807 RgnHandle rgn;
808 Rect rect;
809 int oval;
810 PenState savestate;
811
812 switch (msg) {
813 case drawCntl:
814 if ((*control)->contrlVis) {
815 rect = (*control)->contrlRect;
816 GetPenState(&savestate);
817 PenNormal();
818 PenSize(3, 3);
819 if ((*control)->contrlHilite == kControlInactivePart)
820 PenPat(&qd.gray);
821 oval = (rect.bottom - rect.top) / 2 + 2;
822 FrameRoundRect(&rect, oval, oval);
823 SetPenState(&savestate);
824 }
825 return 0;
826 case calcCRgns:
827 if (param & (1 << 31)) {
828 param &= ~(1 << 31);
829 goto calcthumbrgn;
830 }
831 /* FALLTHROUGH */
832 case calcCntlRgn:
833 rgn = (RgnHandle)param;
834 RectRgn(rgn, &(*control)->contrlRect);
835 return 0;
836 case calcThumbRgn:
837 calcthumbrgn:
838 rgn = (RgnHandle)param;
839 SetEmptyRgn(rgn);
840 return 0;
841 }
842
843 return 0;
844 }
845 #endif
846
847 static void macctrl_listbox(struct macctrls *mcs, WindowPtr window,
848 struct mac_layoutstate *curstate,
849 union control *ctrl)
850 {
851 union macctrl *mc = snew(union macctrl);
852 Rect bounds;
853 Size olen;
854
855 if (ctrl->listbox.label != NULL)
856 fprintf(stderr, " label = %s\n", ctrl->listbox.label);
857 fprintf(stderr, " height = %d\n", ctrl->listbox.height);
858 if (ctrl->listbox.draglist)
859 fprintf(stderr, " draglist\n");
860 if (ctrl->listbox.multisel)
861 fprintf(stderr, " multisel\n");
862 fprintf(stderr, " ncols = %d\n", ctrl->listbox.ncols);
863 assert(ctrl->listbox.percentwidth == 100);
864 mc->generic.type = MACCTRL_LISTBOX;
865 mc->generic.ctrl = ctrl;
866 mc->generic.privdata = NULL;
867 /* The list starts off empty */
868 mc->listbox.nids = 0;
869 mc->listbox.ids = NULL;
870 bounds.left = curstate->pos.h;
871 bounds.right = bounds.left + curstate->width;
872 bounds.top = curstate->pos.v;
873 bounds.bottom = bounds.top + 20 * ctrl->listbox.height;
874
875 if (mac_gestalts.apprvers >= 0x100) {
876 InsetRect(&bounds, 3, 3);
877 mc->listbox.tbctrl = NewControl(window, &bounds, NULL, TRUE,
878 ldes_Default, 0, 0,
879 kControlListBoxProc, (long)mc);
880 if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
881 kControlListBoxListHandleTag,
882 sizeof(mc->listbox.list), &mc->listbox.list,
883 &olen) != noErr) {
884 DisposeControl(mc->listbox.tbctrl);
885 sfree(mc);
886 return;
887 }
888 }
889 #if !TARGET_API_MAC_CARBON
890 else {
891 InsetRect(&bounds, -3, -3);
892 mc->listbox.tbctrl = NewControl(window, &bounds, NULL, TRUE,
893 0, 0, 0,
894 SYS7_LISTBOX_PROC, (long)mc);
895 mc->listbox.list = (ListHandle)(*mc->listbox.tbctrl)->contrlData;
896 (*mc->listbox.list)->refCon = (long)mc;
897 }
898 #endif
899 if (!ctrl->listbox.multisel) {
900 #if TARGET_API_MAC_CARBON
901 SetListSelectionFlags(mc->listbox.list, lOnlyOne);
902 #else
903 (*mc->listbox.list)->selFlags = lOnlyOne;
904 #endif
905 }
906 add234(mcs->byctrl, mc);
907 curstate->pos.v += 6 + 20 * ctrl->listbox.height;
908 mc->generic.next = mcs->panels[curstate->panelnum];
909 mcs->panels[curstate->panelnum] = mc;
910 ctrlevent(mcs, mc, EVENT_REFRESH);
911 }
912
913 #if !TARGET_API_MAC_CARBON
914 static pascal SInt32 macctrl_sys7_listbox_cdef(SInt16 variant,
915 ControlRef control,
916 ControlDefProcMessage msg,
917 SInt32 param)
918 {
919 RgnHandle rgn;
920 Rect rect;
921 ListHandle list;
922 long ssfs;
923 Point mouse;
924 ListBounds bounds;
925 Point csize;
926 short savefont;
927 short savesize;
928 GrafPtr curport;
929
930 switch (msg) {
931 case initCntl:
932 rect = (*control)->contrlRect;
933 InsetRect(&rect, 4, 4);
934 rect.right -= 15; /* scroll bar */
935 bounds.top = bounds.bottom = bounds.left = 0;
936 bounds.right = 1;
937 csize.h = csize.v = 0;
938 GetPort(&curport);
939 savefont = curport->txFont;
940 savesize = curport->txSize;
941 ssfs = GetScriptVariable(smSystemScript, smScriptSysFondSize);
942 TextFont(HiWord(ssfs));
943 TextSize(LoWord(ssfs));
944 list = LNew(&rect, &bounds, csize, 0, (*control)->contrlOwner,
945 TRUE, FALSE, FALSE, TRUE);
946 SetControlReference((*list)->vScroll, (long)list);
947 (*control)->contrlData = (Handle)list;
948 TextFont(savefont);
949 TextSize(savesize);
950 return noErr;
951 case dispCntl:
952 /*
953 * If the dialogue box is being destroyed, the scroll bar
954 * might have gone already. In our situation, this is the
955 * only time we destroy a control, so NULL out the scroll bar
956 * handle to prevent LDispose trying to free it.
957 */
958 list = (ListHandle)(*control)->contrlData;
959 (*list)->vScroll = NULL;
960 LDispose(list);
961 return 0;
962 case drawCntl:
963 if ((*control)->contrlVis) {
964 rect = (*control)->contrlRect;
965 /* XXX input focus highlighting? */
966 InsetRect(&rect, 3, 3);
967 PenNormal();
968 FrameRect(&rect);
969 list = (ListHandle)(*control)->contrlData;
970 LActivate((*control)->contrlHilite != kControlInactivePart, list);
971 GetPort(&curport);
972 LUpdate(curport->visRgn, list);
973 }
974 return 0;
975 case testCntl:
976 mouse.h = LoWord(param);
977 mouse.v = HiWord(param);
978 rect = (*control)->contrlRect;
979 InsetRect(&rect, 4, 4);
980 /*
981 * We deliberately exclude the scrollbar so that LClick() can see it.
982 */
983 rect.right -= 15;
984 return PtInRect(mouse, &rect) ? kControlListBoxPart : kControlNoPart;
985 case calcCRgns:
986 if (param & (1 << 31)) {
987 param &= ~(1 << 31);
988 goto calcthumbrgn;
989 }
990 /* FALLTHROUGH */
991 case calcCntlRgn:
992 rgn = (RgnHandle)param;
993 RectRgn(rgn, &(*control)->contrlRect);
994 return 0;
995 case calcThumbRgn:
996 calcthumbrgn:
997 rgn = (RgnHandle)param;
998 SetEmptyRgn(rgn);
999 return 0;
1000 }
1001
1002 return 0;
1003 }
1004 #endif
1005
1006 static void macctrl_popup(struct macctrls *mcs, WindowPtr window,
1007 struct mac_layoutstate *curstate,
1008 union control *ctrl)
1009 {
1010 union macctrl *mc = snew(union macctrl);
1011 Rect bounds;
1012 Str255 title;
1013 unsigned int labelwidth;
1014 static int nextmenuid = MENU_MIN;
1015 int menuid;
1016 MenuRef menu;
1017
1018 /*
1019 * <http://developer.apple.com/qa/tb/tb42.html> explains how to
1020 * create a popup menu with dynamic content.
1021 */
1022 assert(ctrl->listbox.height == 0);
1023 assert(!ctrl->listbox.draglist);
1024 assert(!ctrl->listbox.multisel);
1025
1026 if (ctrl->listbox.label != NULL)
1027 fprintf(stderr, " label = %s\n", ctrl->listbox.label);
1028 fprintf(stderr, " percentwidth = %d\n", ctrl->listbox.percentwidth);
1029
1030 mc->generic.type = MACCTRL_POPUP;
1031 mc->generic.ctrl = ctrl;
1032 mc->generic.privdata = NULL;
1033 c2pstrcpy(title, ctrl->button.label == NULL ? "" : ctrl->button.label);
1034
1035 /* Find a spare menu ID and create the menu */
1036 while (GetMenuHandle(nextmenuid) != NULL)
1037 if (++nextmenuid >= MENU_MAX) nextmenuid = MENU_MIN;
1038 menuid = nextmenuid++;
1039 menu = NewMenu(menuid, "\pdummy");
1040 if (menu == NULL) return;
1041 mc->popup.menu = menu;
1042 mc->popup.menuid = menuid;
1043 InsertMenu(menu, kInsertHierarchicalMenu);
1044
1045 /* The menu starts off empty */
1046 mc->popup.nids = 0;
1047 mc->popup.ids = NULL;
1048
1049 bounds.left = curstate->pos.h;
1050 bounds.right = bounds.left + curstate->width;
1051 bounds.top = curstate->pos.v;
1052 bounds.bottom = bounds.top + 20;
1053 /* XXX handle percentwidth == 100 */
1054 labelwidth = curstate->width * (100 - ctrl->listbox.percentwidth) / 100;
1055 mc->popup.tbctrl = NewControl(window, &bounds, title, TRUE,
1056 popupTitleLeftJust, menuid, labelwidth,
1057 popupMenuProc + popupFixedWidth, (long)mc);
1058 add234(mcs->byctrl, mc);
1059 curstate->pos.v += 26;
1060 mc->generic.next = mcs->panels[curstate->panelnum];
1061 mcs->panels[curstate->panelnum] = mc;
1062 ctrlevent(mcs, mc, EVENT_REFRESH);
1063 }
1064
1065
1066 void macctrl_activate(WindowPtr window, EventRecord *event)
1067 {
1068 struct macctrls *mcs = mac_winctrls(window);
1069 Boolean active = (event->modifiers & activeFlag) != 0;
1070 GrafPtr saveport;
1071 int i, j;
1072 ControlPartCode state;
1073 union macctrl *mc;
1074
1075 GetPort(&saveport);
1076 SetPort((GrafPtr)GetWindowPort(window));
1077 if (mac_gestalts.apprvers >= 0x100)
1078 SetThemeWindowBackground(window, active ?
1079 kThemeBrushModelessDialogBackgroundActive :
1080 kThemeBrushModelessDialogBackgroundInactive,
1081 TRUE);
1082 state = active ? kControlNoPart : kControlInactivePart;
1083 for (i = 0; i <= mcs->curpanel; i += mcs->curpanel)
1084 for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) {
1085 switch (mc->generic.type) {
1086 case MACCTRL_TEXT:
1087 HiliteControl(mc->text.tbctrl, state);
1088 break;
1089 case MACCTRL_EDITBOX:
1090 HiliteControl(mc->editbox.tbctrl, state);
1091 if (mc->editbox.tblabel != NULL)
1092 HiliteControl(mc->editbox.tblabel, state);
1093 break;
1094 case MACCTRL_RADIO:
1095 for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
1096 HiliteControl(mc->radio.tbctrls[j], state);
1097 if (mc->radio.tblabel != NULL)
1098 HiliteControl(mc->radio.tblabel, state);
1099 break;
1100 case MACCTRL_CHECKBOX:
1101 HiliteControl(mc->checkbox.tbctrl, state);
1102 break;
1103 case MACCTRL_BUTTON:
1104 HiliteControl(mc->button.tbctrl, state);
1105 if (mc->button.tbring != NULL)
1106 HiliteControl(mc->button.tbring, state);
1107 break;
1108 case MACCTRL_LISTBOX:
1109 HiliteControl(mc->listbox.tbctrl, state);
1110 break;
1111 case MACCTRL_POPUP:
1112 HiliteControl(mc->popup.tbctrl, state);
1113 break;
1114 }
1115 #if !TARGET_API_MAC_CARBON
1116 if (mcs->focus == mc) {
1117 if (active)
1118 macctrl_enfocus(mc);
1119 else
1120 macctrl_defocus(mc);
1121 }
1122 #endif
1123 }
1124 SetPort(saveport);
1125 }
1126
1127 void macctrl_click(WindowPtr window, EventRecord *event)
1128 {
1129 Point mouse;
1130 ControlHandle control, oldfocus;
1131 int part, trackresult;
1132 GrafPtr saveport;
1133 union macctrl *mc;
1134 struct macctrls *mcs = mac_winctrls(window);
1135 int i;
1136 UInt32 features;
1137
1138 GetPort(&saveport);
1139 SetPort((GrafPtr)GetWindowPort(window));
1140 mouse = event->where;
1141 GlobalToLocal(&mouse);
1142 part = FindControl(mouse, window, &control);
1143 if (control != NULL) {
1144 #if !TARGET_API_MAC_CARBON
1145 /*
1146 * Special magic for scroll bars in list boxes, whose refcon
1147 * is the list.
1148 */
1149 if (part == kControlUpButtonPart || part == kControlDownButtonPart ||
1150 part == kControlPageUpPart || part == kControlPageDownPart ||
1151 part == kControlIndicatorPart)
1152 mc = (union macctrl *)
1153 (*(ListHandle)GetControlReference(control))->refCon;
1154 else
1155 #endif
1156 mc = (union macctrl *)GetControlReference(control);
1157 fprintf(stderr, "control = %p, part = %d, mc = %p\n",
1158 control, part, mc);
1159 if (mac_gestalts.apprvers >= 0x100) {
1160 if (GetControlFeatures(control, &features) == noErr &&
1161 (features & kControlSupportsFocus) &&
1162 (features & kControlGetsFocusOnClick) &&
1163 GetKeyboardFocus(window, &oldfocus) == noErr &&
1164 control != oldfocus)
1165 SetKeyboardFocus(window, control, part);
1166 trackresult = HandleControlClick(control, mouse, event->modifiers,
1167 (ControlActionUPP)-1);
1168 } else {
1169 #if !TARGET_API_MAC_CARBON
1170 if (mc->generic.type == MACCTRL_EDITBOX &&
1171 control == mc->editbox.tbctrl) {
1172 TEHandle te = (TEHandle)(*control)->contrlData;
1173
1174 macctrl_setfocus(mcs, mc);
1175 TEClick(mouse, !!(event->modifiers & shiftKey), te);
1176 goto done;
1177 }
1178 if (mc->generic.type == MACCTRL_LISTBOX &&
1179 (control == mc->listbox.tbctrl ||
1180 control == (*mc->listbox.list)->vScroll)) {
1181
1182 fprintf(stderr, "list = %p\n", mc->listbox.list);
1183 macctrl_setfocus(mcs, mc);
1184 if (LClick(mouse, event->modifiers, mc->listbox.list))
1185 /* double-click */
1186 ctrlevent(mcs, mc, EVENT_ACTION);
1187 else
1188 ctrlevent(mcs, mc, EVENT_SELCHANGE);
1189 goto done;
1190 }
1191 #endif
1192 trackresult = TrackControl(control, mouse, (ControlActionUPP)-1);
1193 }
1194 switch (mc->generic.type) {
1195 case MACCTRL_RADIO:
1196 if (trackresult != 0) {
1197 for (i = 0; i < mc->generic.ctrl->radio.nbuttons; i++)
1198 if (mc->radio.tbctrls[i] == control)
1199 SetControlValue(mc->radio.tbctrls[i],
1200 kControlRadioButtonCheckedValue);
1201 else
1202 SetControlValue(mc->radio.tbctrls[i],
1203 kControlRadioButtonUncheckedValue);
1204 ctrlevent(mcs, mc, EVENT_VALCHANGE);
1205 }
1206 break;
1207 case MACCTRL_CHECKBOX:
1208 if (trackresult != 0) {
1209 SetControlValue(control, !GetControlValue(control));
1210 ctrlevent(mcs, mc, EVENT_VALCHANGE);
1211 }
1212 break;
1213 case MACCTRL_BUTTON:
1214 if (trackresult != 0)
1215 ctrlevent(mcs, mc, EVENT_ACTION);
1216 break;
1217 case MACCTRL_LISTBOX:
1218 /* FIXME spot double-click */
1219 ctrlevent(mcs, mc, EVENT_SELCHANGE);
1220 break;
1221 case MACCTRL_POPUP:
1222 ctrlevent(mcs, mc, EVENT_SELCHANGE);
1223 break;
1224 }
1225 }
1226 done:
1227 SetPort(saveport);
1228 }
1229
1230 void macctrl_key(WindowPtr window, EventRecord *event)
1231 {
1232 ControlRef control;
1233 struct macctrls *mcs = mac_winctrls(window);
1234 union macctrl *mc;
1235 unsigned long dummy;
1236
1237 switch (event->message & charCodeMask) {
1238 case kEnterCharCode:
1239 case kReturnCharCode:
1240 if (mcs->defbutton != NULL) {
1241 assert(mcs->defbutton->generic.type == MACCTRL_BUTTON);
1242 HiliteControl(mcs->defbutton->button.tbctrl, kControlButtonPart);
1243 /*
1244 * I'd like to delay unhilighting the button until after
1245 * the event has been processed, but by them the entire
1246 * dialgue box might have been destroyed.
1247 */
1248 Delay(6, &dummy);
1249 HiliteControl(mcs->defbutton->button.tbctrl, kControlNoPart);
1250 ctrlevent(mcs, mcs->defbutton, EVENT_ACTION);
1251 }
1252 return;
1253 case kEscapeCharCode:
1254 if (mcs->canbutton != NULL) {
1255 assert(mcs->canbutton->generic.type == MACCTRL_BUTTON);
1256 HiliteControl(mcs->canbutton->button.tbctrl, kControlButtonPart);
1257 Delay(6, &dummy);
1258 HiliteControl(mcs->defbutton->button.tbctrl, kControlNoPart);
1259 ctrlevent(mcs, mcs->canbutton, EVENT_ACTION);
1260 }
1261 return;
1262 }
1263 if (mac_gestalts.apprvers >= 0x100) {
1264 if (GetKeyboardFocus(window, &control) == noErr && control != NULL) {
1265 HandleControlKey(control, (event->message & keyCodeMask) >> 8,
1266 event->message & charCodeMask, event->modifiers);
1267 mc = (union macctrl *)GetControlReference(control);
1268 switch (mc->generic.type) {
1269 case MACCTRL_LISTBOX:
1270 ctrlevent(mcs, mc, EVENT_SELCHANGE);
1271 break;
1272 default:
1273 ctrlevent(mcs, mc, EVENT_VALCHANGE);
1274 break;
1275 }
1276 }
1277 }
1278 #if !TARGET_API_MAC_CARBON
1279 else {
1280 TEHandle te;
1281
1282 if (mcs->focus != NULL) {
1283 mc = mcs->focus;
1284 switch (mc->generic.type) {
1285 case MACCTRL_EDITBOX:
1286 te = (TEHandle)(*mc->editbox.tbctrl)->contrlData;
1287 TEKey(event->message & charCodeMask, te);
1288 ctrlevent(mcs, mc, EVENT_VALCHANGE);
1289 break;
1290 }
1291 }
1292 }
1293 #endif
1294 }
1295
1296 void macctrl_update(WindowPtr window)
1297 {
1298 #if TARGET_API_MAC_CARBON
1299 RgnHandle visrgn;
1300 #endif
1301 Rect rect;
1302 GrafPtr saveport;
1303
1304 BeginUpdate(window);
1305 GetPort(&saveport);
1306 SetPort((GrafPtr)GetWindowPort(window));
1307 if (mac_gestalts.apprvers >= 0x101) {
1308 #if TARGET_API_MAC_CARBON
1309 GetPortBounds(GetWindowPort(window), &rect);
1310 #else
1311 rect = window->portRect;
1312 #endif
1313 InsetRect(&rect, -1, -1);
1314 DrawThemeModelessDialogFrame(&rect, mac_frontwindow() == window ?
1315 kThemeStateActive : kThemeStateInactive);
1316 }
1317 #if TARGET_API_MAC_CARBON
1318 visrgn = NewRgn();
1319 GetPortVisibleRegion(GetWindowPort(window), visrgn);
1320 UpdateControls(window, visrgn);
1321 DisposeRgn(visrgn);
1322 #else
1323 UpdateControls(window, window->visRgn);
1324 #endif
1325 SetPort(saveport);
1326 EndUpdate(window);
1327 }
1328
1329 #if TARGET_API_MAC_CARBON
1330 #define EnableItem EnableMenuItem
1331 #define DisableItem DisableMenuItem
1332 #endif
1333 void macctrl_adjustmenus(WindowPtr window)
1334 {
1335 MenuHandle menu;
1336
1337 menu = GetMenuHandle(mFile);
1338 DisableItem(menu, iSave); /* XXX enable if modified */
1339 EnableItem(menu, iSaveAs);
1340 EnableItem(menu, iDuplicate);
1341
1342 menu = GetMenuHandle(mEdit);
1343 DisableItem(menu, 0);
1344 }
1345
1346 void macctrl_close(WindowPtr window)
1347 {
1348 struct macctrls *mcs = mac_winctrls(window);
1349 union macctrl *mc;
1350
1351 /*
1352 * Mostly, we don't bother disposing of the Toolbox controls,
1353 * since that will happen automatically when the window is
1354 * disposed of. Popup menus are an exception, because we have to
1355 * dispose of the menu ourselves, and doing that while the control
1356 * still holds a reference to it seems rude.
1357 */
1358 while ((mc = index234(mcs->byctrl, 0)) != NULL) {
1359 if (mc->generic.privdata != NULL && mc->generic.freeprivdata)
1360 sfree(mc->generic.privdata);
1361 switch (mc->generic.type) {
1362 case MACCTRL_POPUP:
1363 DisposeControl(mc->popup.tbctrl);
1364 DeleteMenu(mc->popup.menuid);
1365 DisposeMenu(mc->popup.menu);
1366 break;
1367 }
1368 del234(mcs->byctrl, mc);
1369 sfree(mc);
1370 }
1371
1372 freetree234(mcs->byctrl);
1373 mcs->byctrl = NULL;
1374 sfree(mcs->panels);
1375 mcs->panels = NULL;
1376 }
1377
1378 void dlg_update_start(union control *ctrl, void *dlg)
1379 {
1380
1381 /* No-op for now */
1382 }
1383
1384 void dlg_update_done(union control *ctrl, void *dlg)
1385 {
1386
1387 /* No-op for now */
1388 }
1389
1390 void dlg_set_focus(union control *ctrl, void *dlg)
1391 {
1392
1393 if (mac_gestalts.apprvers >= 0x100) {
1394 /* Use SetKeyboardFocus() */
1395 } else {
1396 /* Do our own mucking around */
1397 }
1398 }
1399
1400 union control *dlg_last_focused(union control *ctrl, void *dlg)
1401 {
1402
1403 return NULL;
1404 }
1405
1406 void dlg_beep(void *dlg)
1407 {
1408
1409 SysBeep(30);
1410 }
1411
1412 void dlg_error_msg(void *dlg, char *msg)
1413 {
1414 Str255 pmsg;
1415
1416 c2pstrcpy(pmsg, msg);
1417 ParamText(pmsg, NULL, NULL, NULL);
1418 StopAlert(128, NULL);
1419 }
1420
1421 void dlg_end(void *dlg, int value)
1422 {
1423 struct macctrls *mcs = dlg;
1424
1425 if (mcs->end != NULL)
1426 (*mcs->end)(mcs->window, value);
1427 };
1428
1429 void dlg_refresh(union control *ctrl, void *dlg)
1430 {
1431 struct macctrls *mcs = dlg;
1432 union macctrl *mc;
1433
1434 if (ctrl == NULL)
1435 return; /* FIXME */
1436 mc = findbyctrl(mcs, ctrl);
1437 assert(mc != NULL);
1438 ctrlevent(mcs, mc, EVENT_REFRESH);
1439 };
1440
1441 void *dlg_get_privdata(union control *ctrl, void *dlg)
1442 {
1443 struct macctrls *mcs = dlg;
1444 union macctrl *mc = findbyctrl(mcs, ctrl);
1445
1446 assert(mc != NULL);
1447 return mc->generic.privdata;
1448 }
1449
1450 void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr)
1451 {
1452 struct macctrls *mcs = dlg;
1453 union macctrl *mc = findbyctrl(mcs, ctrl);
1454
1455 assert(mc != NULL);
1456 mc->generic.privdata = ptr;
1457 mc->generic.freeprivdata = FALSE;
1458 }
1459
1460 void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size)
1461 {
1462 struct macctrls *mcs = dlg;
1463 union macctrl *mc = findbyctrl(mcs, ctrl);
1464
1465 assert(mc != NULL);
1466 mc->generic.privdata = smalloc(size);
1467 mc->generic.freeprivdata = TRUE;
1468 return mc->generic.privdata;
1469 }
1470
1471
1472 /*
1473 * Radio Button control
1474 */
1475
1476 void dlg_radiobutton_set(union control *ctrl, void *dlg, int whichbutton)
1477 {
1478 struct macctrls *mcs = dlg;
1479 union macctrl *mc = findbyctrl(mcs, ctrl);
1480 int i;
1481
1482 if (mc == NULL) return;
1483 for (i = 0; i < ctrl->radio.nbuttons; i++) {
1484 if (i == whichbutton)
1485 SetControlValue(mc->radio.tbctrls[i],
1486 kControlRadioButtonCheckedValue);
1487 else
1488 SetControlValue(mc->radio.tbctrls[i],
1489 kControlRadioButtonUncheckedValue);
1490 }
1491
1492 };
1493
1494 int dlg_radiobutton_get(union control *ctrl, void *dlg)
1495 {
1496 struct macctrls *mcs = dlg;
1497 union macctrl *mc = findbyctrl(mcs, ctrl);
1498 int i;
1499
1500 assert(mc != NULL);
1501 for (i = 0; i < ctrl->radio.nbuttons; i++) {
1502 if (GetControlValue(mc->radio.tbctrls[i]) ==
1503 kControlRadioButtonCheckedValue)
1504 return i;
1505 }
1506 return -1;
1507 };
1508
1509
1510 /*
1511 * Check Box control
1512 */
1513
1514 void dlg_checkbox_set(union control *ctrl, void *dlg, int checked)
1515 {
1516 struct macctrls *mcs = dlg;
1517 union macctrl *mc = findbyctrl(mcs, ctrl);
1518
1519 if (mc == NULL) return;
1520 SetControlValue(mc->checkbox.tbctrl,
1521 checked ? kControlCheckBoxCheckedValue :
1522 kControlCheckBoxUncheckedValue);
1523 }
1524
1525 int dlg_checkbox_get(union control *ctrl, void *dlg)
1526 {
1527 struct macctrls *mcs = dlg;
1528 union macctrl *mc = findbyctrl(mcs, ctrl);
1529
1530 assert(mc != NULL);
1531 return GetControlValue(mc->checkbox.tbctrl);
1532 }
1533
1534
1535 /*
1536 * Edit Box control
1537 */
1538
1539 void dlg_editbox_set(union control *ctrl, void *dlg, char const *text)
1540 {
1541 struct macctrls *mcs = dlg;
1542 union macctrl *mc = findbyctrl(mcs, ctrl);
1543 GrafPtr saveport;
1544
1545 if (mc == NULL) return;
1546 assert(mc->generic.type == MACCTRL_EDITBOX);
1547 GetPort(&saveport);
1548 SetPort((GrafPtr)(GetWindowPort(mcs->window)));
1549 if (mac_gestalts.apprvers >= 0x100)
1550 SetControlData(mc->editbox.tbctrl, kControlEntireControl,
1551 ctrl->editbox.password ?
1552 kControlEditTextPasswordTag :
1553 kControlEditTextTextTag,
1554 strlen(text), text);
1555 #if !TARGET_API_MAC_CARBON
1556 else
1557 TESetText(text, strlen(text),
1558 (TEHandle)(*mc->editbox.tbctrl)->contrlData);
1559 #endif
1560 DrawOneControl(mc->editbox.tbctrl);
1561 SetPort(saveport);
1562 }
1563
1564 void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length)
1565 {
1566 struct macctrls *mcs = dlg;
1567 union macctrl *mc = findbyctrl(mcs, ctrl);
1568 Size olen;
1569
1570 assert(mc != NULL);
1571 assert(mc->generic.type == MACCTRL_EDITBOX);
1572 if (mac_gestalts.apprvers >= 0x100) {
1573 if (GetControlData(mc->editbox.tbctrl, kControlEntireControl,
1574 ctrl->editbox.password ?
1575 kControlEditTextPasswordTag :
1576 kControlEditTextTextTag,
1577 length - 1, buffer, &olen) != noErr)
1578 olen = 0;
1579 if (olen > length - 1)
1580 olen = length - 1;
1581 }
1582 #if !TARGET_API_MAC_CARBON
1583 else {
1584 TEHandle te = (TEHandle)(*mc->editbox.tbctrl)->contrlData;
1585
1586 olen = (*te)->teLength;
1587 if (olen > length - 1)
1588 olen = length - 1;
1589 memcpy(buffer, *(*te)->hText, olen);
1590 }
1591 #endif
1592 buffer[olen] = '\0';
1593 fprintf(stderr, "dlg_editbox_get: %s\n", buffer);
1594 }
1595
1596
1597 /*
1598 * List Box control
1599 */
1600
1601 static void dlg_macpopup_clear(union control *ctrl, void *dlg)
1602 {
1603 struct macctrls *mcs = dlg;
1604 union macctrl *mc = findbyctrl(mcs, ctrl);
1605 MenuRef menu = mc->popup.menu;
1606 unsigned int i, n;
1607
1608 if (mc == NULL) return;
1609 fprintf(stderr, " popup_clear\n");
1610 n = CountMenuItems(menu);
1611 for (i = 0; i < n; i++)
1612 DeleteMenuItem(menu, n - i);
1613 mc->popup.nids = 0;
1614 sfree(mc->popup.ids);
1615 mc->popup.ids = NULL;
1616 SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
1617 }
1618
1619 static void dlg_maclist_clear(union control *ctrl, void *dlg)
1620 {
1621 struct macctrls *mcs = dlg;
1622 union macctrl *mc = findbyctrl(mcs, ctrl);
1623
1624 if (mc == NULL) return;
1625 fprintf(stderr, " maclist_clear\n");
1626 LDelRow(0, 0, mc->listbox.list);
1627 mc->listbox.nids = 0;
1628 sfree(mc->listbox.ids);
1629 mc->listbox.ids = NULL;
1630 DrawOneControl(mc->listbox.tbctrl);
1631 }
1632
1633 void dlg_listbox_clear(union control *ctrl, void *dlg)
1634 {
1635
1636 switch (ctrl->generic.type) {
1637 case CTRL_LISTBOX:
1638 if (ctrl->listbox.height == 0)
1639 dlg_macpopup_clear(ctrl, dlg);
1640 else
1641 dlg_maclist_clear(ctrl, dlg);
1642 break;
1643 }
1644 }
1645
1646 static void dlg_macpopup_del(union control *ctrl, void *dlg, int index)
1647 {
1648 struct macctrls *mcs = dlg;
1649 union macctrl *mc = findbyctrl(mcs, ctrl);
1650 MenuRef menu = mc->popup.menu;
1651
1652 if (mc == NULL) return;
1653 fprintf(stderr, " popup_del %d\n", index);
1654 DeleteMenuItem(menu, index + 1);
1655 if (mc->popup.ids != NULL)
1656 memcpy(mc->popup.ids + index, mc->popup.ids + index + 1,
1657 (mc->popup.nids - index - 1) * sizeof(*mc->popup.ids));
1658 SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
1659 }
1660
1661 static void dlg_maclist_del(union control *ctrl, void *dlg, int index)
1662 {
1663 struct macctrls *mcs = dlg;
1664 union macctrl *mc = findbyctrl(mcs, ctrl);
1665
1666 if (mc == NULL) return;
1667 fprintf(stderr, " maclist_del %d\n", index);
1668 LDelRow(1, index, mc->listbox.list);
1669 if (mc->listbox.ids != NULL)
1670 memcpy(mc->listbox.ids + index, mc->listbox.ids + index + 1,
1671 (mc->listbox.nids - index - 1) * sizeof(*mc->listbox.ids));
1672 DrawOneControl(mc->listbox.tbctrl);
1673 }
1674
1675 void dlg_listbox_del(union control *ctrl, void *dlg, int index)
1676 {
1677
1678 switch (ctrl->generic.type) {
1679 case CTRL_LISTBOX:
1680 if (ctrl->listbox.height == 0)
1681 dlg_macpopup_del(ctrl, dlg, index);
1682 else
1683 dlg_maclist_del(ctrl, dlg, index);
1684 break;
1685 }
1686 }
1687
1688 static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text)
1689 {
1690 struct macctrls *mcs = dlg;
1691 union macctrl *mc = findbyctrl(mcs, ctrl);
1692 MenuRef menu = mc->popup.menu;
1693 Str255 itemstring;
1694
1695 if (mc == NULL) return;
1696 fprintf(stderr, " popup_add %s\n", text);
1697 assert(text[0] != '\0');
1698 c2pstrcpy(itemstring, text);
1699 AppendMenu(menu, "\pdummy");
1700 SetMenuItemText(menu, CountMenuItems(menu), itemstring);
1701 SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
1702 }
1703
1704
1705 static void dlg_maclist_add(union control *ctrl, void *dlg, char const *text)
1706 {
1707 struct macctrls *mcs = dlg;
1708 union macctrl *mc = findbyctrl(mcs, ctrl);
1709 ListBounds bounds;
1710 Cell cell = { 0, 0 };
1711
1712 if (mc == NULL) return;
1713 fprintf(stderr, " maclist_add %s\n", text);
1714 #if TARGET_API_MAC_CARBON
1715 GetListDataBounds(mc->listbox.list, &bounds);
1716 #else
1717 bounds = (*mc->listbox.list)->dataBounds;
1718 #endif
1719 cell.v = bounds.bottom;
1720 LAddRow(1, cell.v, mc->listbox.list);
1721 LSetCell(text, strlen(text), cell, mc->listbox.list);
1722 DrawOneControl(mc->listbox.tbctrl);
1723 }
1724
1725 void dlg_listbox_add(union control *ctrl, void *dlg, char const *text)
1726 {
1727
1728 switch (ctrl->generic.type) {
1729 case CTRL_LISTBOX:
1730 if (ctrl->listbox.height == 0)
1731 dlg_macpopup_add(ctrl, dlg, text);
1732 else
1733 dlg_maclist_add(ctrl, dlg, text);
1734 break;
1735 }
1736 }
1737
1738 static void dlg_macpopup_addwithid(union control *ctrl, void *dlg,
1739 char const *text, int id)
1740 {
1741 struct macctrls *mcs = dlg;
1742 union macctrl *mc = findbyctrl(mcs, ctrl);
1743 MenuRef menu = mc->popup.menu;
1744 unsigned int index;
1745
1746 if (mc == NULL) return;
1747 fprintf(stderr, " popup_addwthid %s, %d\n", text, id);
1748 dlg_macpopup_add(ctrl, dlg, text);
1749 index = CountMenuItems(menu) - 1;
1750 if (mc->popup.nids <= index) {
1751 mc->popup.nids = index + 1;
1752 mc->popup.ids = sresize(mc->popup.ids, mc->popup.nids, int);
1753 }
1754 mc->popup.ids[index] = id;
1755 }
1756
1757 static void dlg_maclist_addwithid(union control *ctrl, void *dlg,
1758 char const *text, int id)
1759 {
1760 struct macctrls *mcs = dlg;
1761 union macctrl *mc = findbyctrl(mcs, ctrl);
1762 ListBounds bounds;
1763 int index;
1764
1765 if (mc == NULL) return;
1766 fprintf(stderr, " maclist_addwithid %s %d\n", text, id);
1767 dlg_maclist_add(ctrl, dlg, text);
1768 #if TARGET_API_MAC_CARBON
1769 GetListDataBounds(mc->listbox.list, &bounds);
1770 #else
1771 bounds = (*mc->listbox.list)->dataBounds;
1772 #endif
1773 index = bounds.bottom;
1774 if (mc->listbox.nids <= index) {
1775 mc->listbox.nids = index + 1;
1776 mc->listbox.ids = sresize(mc->listbox.ids, mc->listbox.nids, int);
1777 }
1778 mc->listbox.ids[index] = id;
1779 }
1780
1781 void dlg_listbox_addwithid(union control *ctrl, void *dlg,
1782 char const *text, int id)
1783 {
1784
1785 switch (ctrl->generic.type) {
1786 case CTRL_LISTBOX:
1787 if (ctrl->listbox.height == 0)
1788 dlg_macpopup_addwithid(ctrl, dlg, text, id);
1789 else
1790 dlg_maclist_addwithid(ctrl, dlg, text, id);
1791 break;
1792 }
1793 }
1794
1795 int dlg_listbox_getid(union control *ctrl, void *dlg, int index)
1796 {
1797 struct macctrls *mcs = dlg;
1798 union macctrl *mc = findbyctrl(mcs, ctrl);
1799
1800 assert(mc != NULL);
1801 switch (ctrl->generic.type) {
1802 case CTRL_LISTBOX:
1803 if (ctrl->listbox.height == 0) {
1804 assert(mc->popup.ids != NULL && mc->popup.nids > index);
1805 return mc->popup.ids[index];
1806 } else {
1807 assert(mc->listbox.ids != NULL && mc->listbox.nids > index);
1808 return mc->listbox.ids[index];
1809 }
1810 }
1811 return -1;
1812 }
1813
1814 int dlg_listbox_index(union control *ctrl, void *dlg)
1815 {
1816 struct macctrls *mcs = dlg;
1817 union macctrl *mc = findbyctrl(mcs, ctrl);
1818 Cell cell = { 0, 0 };
1819
1820 assert(mc != NULL);
1821 switch (ctrl->generic.type) {
1822 case CTRL_LISTBOX:
1823 if (ctrl->listbox.height == 0)
1824 return GetControlValue(mc->popup.tbctrl) - 1;
1825 else {
1826 if (LGetSelect(TRUE, &cell, mc->listbox.list))
1827 return cell.v;
1828 else
1829 return -1;
1830 }
1831 }
1832 return -1;
1833 }
1834
1835 int dlg_listbox_issel(union control *ctrl, void *dlg, int index)
1836 {
1837 struct macctrls *mcs = dlg;
1838 union macctrl *mc = findbyctrl(mcs, ctrl);
1839 Cell cell = { 0, 0 };
1840
1841 assert(mc != NULL);
1842 switch (ctrl->generic.type) {
1843 case CTRL_LISTBOX:
1844 if (ctrl->listbox.height == 0)
1845 return GetControlValue(mc->popup.tbctrl) - 1 == index;
1846 else {
1847 cell.v = index;
1848 return LGetSelect(FALSE, &cell, mc->listbox.list);
1849 }
1850 }
1851 return FALSE;
1852 }
1853
1854 void dlg_listbox_select(union control *ctrl, void *dlg, int index)
1855 {
1856 struct macctrls *mcs = dlg;
1857 union macctrl *mc = findbyctrl(mcs, ctrl);
1858
1859 if (mc == NULL) return;
1860 switch (ctrl->generic.type) {
1861 case CTRL_LISTBOX:
1862 if (ctrl->listbox.height == 0)
1863 SetControlValue(mc->popup.tbctrl, index + 1);
1864 break;
1865 }
1866 }
1867
1868
1869 /*
1870 * Text control
1871 */
1872
1873 void dlg_text_set(union control *ctrl, void *dlg, char const *text)
1874 {
1875 struct macctrls *mcs = dlg;
1876 union macctrl *mc = findbyctrl(mcs, ctrl);
1877
1878 if (mc == NULL) return;
1879 if (mac_gestalts.apprvers >= 0x100)
1880 SetControlData(mc->text.tbctrl, kControlEntireControl,
1881 kControlStaticTextTextTag, strlen(text), text);
1882 #if !TARGET_API_MAC_CARBON
1883 else
1884 TESetText(text, strlen(text),
1885 (TEHandle)(*mc->text.tbctrl)->contrlData);
1886 #endif
1887 }
1888
1889
1890 /*
1891 * File Selector control
1892 */
1893
1894 void dlg_filesel_set(union control *ctrl, void *dlg, Filename fn)
1895 {
1896
1897 }
1898
1899 void dlg_filesel_get(union control *ctrl, void *dlg, Filename *fn)
1900 {
1901
1902 }
1903
1904
1905 /*
1906 * Font Selector control
1907 */
1908
1909 void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec fn)
1910 {
1911
1912 }
1913
1914 void dlg_fontsel_get(union control *ctrl, void *dlg, FontSpec *fn)
1915 {
1916
1917 }
1918
1919
1920 /*
1921 * Printer enumeration
1922 */
1923
1924 printer_enum *printer_start_enum(int *nprinters)
1925 {
1926
1927 *nprinters = 0;
1928 return NULL;
1929 }
1930
1931 char *printer_get_name(printer_enum *pe, int thing)
1932 {
1933
1934 return "<none>";
1935 }
1936
1937 void printer_finish_enum(printer_enum *pe)
1938 {
1939
1940 }
1941
1942
1943 /*
1944 * Colour selection stuff
1945 */
1946
1947 void dlg_coloursel_start(union control *ctrl, void *dlg,
1948 int r, int g, int b)
1949 {
1950 struct macctrls *mcs = dlg;
1951 union macctrl *mc = findbyctrl(mcs, ctrl);
1952 Point where = {-1, -1}; /* Screen with greatest colour depth */
1953 RGBColor incolour;
1954
1955 if (HAVE_COLOR_QD()) {
1956 incolour.red = r * 0x0101;
1957 incolour.green = g * 0x0101;
1958 incolour.blue = b * 0x0101;
1959 mcs->gotcolour = GetColor(where, "\pModify Colour:", &incolour,
1960 &mcs->thecolour);
1961 ctrlevent(mcs, mc, EVENT_CALLBACK);
1962 } else
1963 dlg_beep(dlg);
1964 }
1965
1966 int dlg_coloursel_results(union control *ctrl, void *dlg,
1967 int *r, int *g, int *b)
1968 {
1969 struct macctrls *mcs = dlg;
1970
1971 if (mcs->gotcolour) {
1972 *r = mcs->thecolour.red >> 8;
1973 *g = mcs->thecolour.green >> 8;
1974 *b = mcs->thecolour.blue >> 8;
1975 return 1;
1976 } else
1977 return 0;
1978 }
1979
1980 /*
1981 * Local Variables:
1982 * c-file-style: "simon"
1983 * End:
1984 */