1d2527ecb7eabc7002a12b9e0cc68f88789d3cb4
[u/mdw/putty] / mac / macctrls.c
1 /* $Id: macctrls.c,v 1.17 2003/03/28 00:50:04 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 <Menus.h>
33 #include <Resources.h>
34 #include <Script.h>
35 #include <Sound.h>
36 #include <TextEdit.h>
37 #include <TextUtils.h>
38 #include <ToolUtils.h>
39 #include <Windows.h>
40
41 #include <assert.h>
42 #include <string.h>
43
44 #include "putty.h"
45 #include "mac.h"
46 #include "macresid.h"
47 #include "dialog.h"
48 #include "tree234.h"
49
50 /* Range of menu IDs for popup menus */
51 #define MENU_MIN 1024
52 #define MENU_MAX 2048
53
54
55 union macctrl {
56 struct macctrl_generic {
57 enum {
58 MACCTRL_TEXT,
59 MACCTRL_EDITBOX,
60 MACCTRL_RADIO,
61 MACCTRL_CHECKBOX,
62 MACCTRL_BUTTON,
63 MACCTRL_POPUP
64 } type;
65 /* Template from which this was generated */
66 union control *ctrl;
67 /* Next control in this panel */
68 union macctrl *next;
69 void *privdata;
70 int freeprivdata;
71 } generic;
72 struct {
73 struct macctrl_generic generic;
74 ControlRef tbctrl;
75 } text;
76 struct {
77 struct macctrl_generic generic;
78 ControlRef tbctrl;
79 } editbox;
80 struct {
81 struct macctrl_generic generic;
82 ControlRef *tbctrls;
83 } radio;
84 struct {
85 struct macctrl_generic generic;
86 ControlRef tbctrl;
87 } checkbox;
88 struct {
89 struct macctrl_generic generic;
90 ControlRef tbctrl;
91 } button;
92 struct {
93 struct macctrl_generic generic;
94 ControlRef tbctrl;
95 MenuRef menu;
96 int menuid;
97 unsigned int nids;
98 int *ids;
99 } popup;
100 };
101
102 struct mac_layoutstate {
103 Point pos;
104 unsigned int width;
105 unsigned int panelnum;
106 };
107
108 #define ctrlevent(mcs, mc, event) do { \
109 if ((mc)->generic.ctrl->generic.handler != NULL) \
110 (*(mc)->generic.ctrl->generic.handler)((mc)->generic.ctrl, (mcs),\
111 (mcs)->data, (event)); \
112 } while (0)
113
114 #define findbyctrl(mcs, ctrl) \
115 find234((mcs)->byctrl, (ctrl), macctrl_cmp_byctrl_find)
116
117 static void macctrl_layoutset(struct mac_layoutstate *, struct controlset *,
118 WindowPtr, struct macctrls *);
119 static void macctrl_switchtopanel(struct macctrls *, unsigned int);
120 static void macctrl_text(struct macctrls *, WindowPtr,
121 struct mac_layoutstate *, union control *);
122 static void macctrl_editbox(struct macctrls *, WindowPtr,
123 struct mac_layoutstate *, union control *);
124 static void macctrl_radio(struct macctrls *, WindowPtr,
125 struct mac_layoutstate *, union control *);
126 static void macctrl_checkbox(struct macctrls *, WindowPtr,
127 struct mac_layoutstate *, union control *);
128 static void macctrl_button(struct macctrls *, WindowPtr,
129 struct mac_layoutstate *, union control *);
130 static void macctrl_popup(struct macctrls *, WindowPtr,
131 struct mac_layoutstate *, union control *);
132 #if !TARGET_API_MAC_CARBON
133 static pascal SInt32 macctrl_sys7_text_cdef(SInt16, ControlRef,
134 ControlDefProcMessage, SInt32);
135 static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16, ControlRef,
136 ControlDefProcMessage, SInt32);
137 static pascal SInt32 macctrl_sys7_default_cdef(SInt16, ControlRef,
138 ControlDefProcMessage, SInt32);
139 #endif
140
141 #if !TARGET_API_MAC_CARBON
142 /*
143 * This trick enables us to keep all the CDEF code in the main
144 * application, which makes life easier. For details, see
145 * <http://developer.apple.com/technotes/tn/tn2003.html#custom_code_base>.
146 */
147
148 #pragma options align=mac68k
149 typedef struct {
150 short jmpabs; /* 4EF9 */
151 ControlDefUPP theUPP;
152 } **PatchCDEF;
153 #pragma options align=reset
154 #endif
155
156 static void macctrl_init()
157 {
158 #if !TARGET_API_MAC_CARBON
159 static int inited = 0;
160 PatchCDEF cdef;
161
162 if (inited) return;
163 cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Text);
164 (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_text_cdef);
165 cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_EditBox);
166 (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_editbox_cdef);
167 cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Default);
168 (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_default_cdef);
169 inited = 1;
170 #endif
171 }
172
173
174 static int macctrl_cmp_byctrl(void *av, void *bv)
175 {
176 union macctrl *a = (union macctrl *)av;
177 union macctrl *b = (union macctrl *)bv;
178
179 if (a->generic.ctrl < b->generic.ctrl)
180 return -1;
181 else if (a->generic.ctrl > b->generic.ctrl)
182 return +1;
183 else
184 return 0;
185 }
186
187 static int macctrl_cmp_byctrl_find(void *av, void *bv)
188 {
189 union control *a = (union control *)av;
190 union macctrl *b = (union macctrl *)bv;
191
192 if (a < b->generic.ctrl)
193 return -1;
194 else if (a > b->generic.ctrl)
195 return +1;
196 else
197 return 0;
198 }
199
200 void macctrl_layoutbox(struct controlbox *cb, WindowPtr window,
201 struct macctrls *mcs)
202 {
203 int i;
204 struct mac_layoutstate curstate;
205 ControlRef root;
206 Rect rect;
207
208 macctrl_init();
209 #if TARGET_API_MAC_CARBON
210 GetPortBounds(GetWindowPort(window), &rect);
211 #else
212 rect = window->portRect;
213 #endif
214 curstate.pos.h = rect.left + 13;
215 curstate.pos.v = rect.bottom - 59;
216 curstate.width = rect.right - rect.left - (13 * 2);
217 if (mac_gestalts.apprvers >= 0x100)
218 CreateRootControl(window, &root);
219 mcs->window = window;
220 mcs->byctrl = newtree234(macctrl_cmp_byctrl);
221 /* Count the number of panels */
222 mcs->npanels = 1;
223 for (i = 1; i < cb->nctrlsets; i++)
224 if (strcmp(cb->ctrlsets[i]->pathname, cb->ctrlsets[i-1]->pathname))
225 mcs->npanels++;
226 mcs->panels = smalloc(sizeof(*mcs->panels) * mcs->npanels);
227 memset(mcs->panels, 0, sizeof(*mcs->panels) * mcs->npanels);
228 curstate.panelnum = 0;
229 for (i = 0; i < cb->nctrlsets; i++) {
230 if (i > 0 && strcmp(cb->ctrlsets[i]->pathname,
231 cb->ctrlsets[i-1]->pathname)) {
232 curstate.pos.v = rect.top + 13;
233 curstate.panelnum++;
234 assert(curstate.panelnum < mcs->npanels);
235 }
236 macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs);
237 }
238 macctrl_switchtopanel(mcs, 1);
239 }
240
241 static void macctrl_layoutset(struct mac_layoutstate *curstate,
242 struct controlset *s,
243 WindowPtr window, struct macctrls *mcs)
244 {
245 unsigned int i;
246
247 fprintf(stderr, "--- begin set ---\n");
248 fprintf(stderr, "pathname = %s\n", s->pathname);
249 if (s->boxname && *s->boxname)
250 fprintf(stderr, "boxname = %s\n", s->boxname);
251 if (s->boxtitle)
252 fprintf(stderr, "boxtitle = %s\n", s->boxtitle);
253
254
255 for (i = 0; i < s->ncontrols; i++) {
256 union control *ctrl = s->ctrls[i];
257 char const *s;
258
259 switch (ctrl->generic.type) {
260 case CTRL_TEXT: s = "text"; break;
261 case CTRL_EDITBOX: s = "editbox"; break;
262 case CTRL_RADIO: s = "radio"; break;
263 case CTRL_CHECKBOX: s = "checkbox"; break;
264 case CTRL_BUTTON: s = "button"; break;
265 case CTRL_LISTBOX: s = "listbox"; break;
266 case CTRL_COLUMNS: s = "columns"; break;
267 case CTRL_FILESELECT: s = "fileselect"; break;
268 case CTRL_FONTSELECT: s = "fontselect"; break;
269 case CTRL_TABDELAY: s = "tabdelay"; break;
270 default: s = "unknown"; break;
271 }
272 fprintf(stderr, " control: %s\n", s);
273 switch (ctrl->generic.type) {
274 case CTRL_TEXT:
275 macctrl_text(mcs, window, curstate, ctrl);
276 break;
277 case CTRL_EDITBOX:
278 macctrl_editbox(mcs, window, curstate, ctrl);
279 break;
280 case CTRL_RADIO:
281 macctrl_radio(mcs, window, curstate, ctrl);
282 break;
283 case CTRL_CHECKBOX:
284 macctrl_checkbox(mcs, window, curstate, ctrl);
285 break;
286 case CTRL_BUTTON:
287 macctrl_button(mcs, window, curstate, ctrl);
288 break;
289 case CTRL_LISTBOX:
290 if (ctrl->listbox.height == 0)
291 macctrl_popup(mcs, window, curstate, ctrl);
292 break;
293 }
294 }
295 }
296
297 static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which)
298 {
299 unsigned int i, j;
300 union macctrl *mc;
301
302 #define hideshow(c) do { \
303 if (i == which) ShowControl(c); else HideControl(c); \
304 } while (0)
305
306 mcs->curpanel = which;
307 /* Panel 0 is special and always visible. */
308 for (i = 1; i < mcs->npanels; i++)
309 for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next)
310 switch (mc->generic.type) {
311 case MACCTRL_TEXT:
312 hideshow(mc->text.tbctrl);
313 break;
314 case MACCTRL_EDITBOX:
315 hideshow(mc->editbox.tbctrl);
316 break;
317 case MACCTRL_RADIO:
318 for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
319 hideshow(mc->radio.tbctrls[j]);
320 break;
321 case MACCTRL_CHECKBOX:
322 hideshow(mc->checkbox.tbctrl);
323 break;
324 case MACCTRL_BUTTON:
325 hideshow(mc->button.tbctrl);
326 break;
327 case MACCTRL_POPUP:
328 hideshow(mc->popup.tbctrl);
329 break;
330 }
331 }
332
333 static void macctrl_text(struct macctrls *mcs, WindowPtr window,
334 struct mac_layoutstate *curstate,
335 union control *ctrl)
336 {
337 union macctrl *mc = smalloc(sizeof *mc);
338 Rect bounds;
339
340 fprintf(stderr, " label = %s\n", ctrl->text.label);
341 mc->generic.type = MACCTRL_TEXT;
342 mc->generic.ctrl = ctrl;
343 mc->generic.privdata = NULL;
344 bounds.left = curstate->pos.h;
345 bounds.right = bounds.left + curstate->width;
346 bounds.top = curstate->pos.v;
347 bounds.bottom = bounds.top + 16;
348 if (mac_gestalts.apprvers >= 0x100) {
349 SInt16 height;
350 Size olen;
351
352 mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
353 kControlStaticTextProc, (long)mc);
354 SetControlData(mc->text.tbctrl, kControlEntireControl,
355 kControlStaticTextTextTag,
356 strlen(ctrl->text.label), ctrl->text.label);
357 GetControlData(mc->text.tbctrl, kControlEntireControl,
358 kControlStaticTextTextHeightTag,
359 sizeof(height), &height, &olen);
360 fprintf(stderr, " height = %d\n", height);
361 SizeControl(mc->text.tbctrl, curstate->width, height);
362 curstate->pos.v += height + 6;
363 } else {
364 Str255 title;
365
366 c2pstrcpy(title, ctrl->text.label);
367 mc->text.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 0,
368 SYS7_TEXT_PROC, (long)mc);
369 }
370 add234(mcs->byctrl, mc);
371 mc->generic.next = mcs->panels[curstate->panelnum];
372 mcs->panels[curstate->panelnum] = mc;
373 }
374
375 #if !TARGET_API_MAC_CARBON
376 static pascal SInt32 macctrl_sys7_text_cdef(SInt16 variant, ControlRef control,
377 ControlDefProcMessage msg, SInt32 param)
378 {
379 RgnHandle rgn;
380
381 switch (msg) {
382 case drawCntl:
383 if ((*control)->contrlVis)
384 TETextBox((*control)->contrlTitle + 1, (*control)->contrlTitle[0],
385 &(*control)->contrlRect, teFlushDefault);
386 return 0;
387 case calcCRgns:
388 if (param & (1 << 31)) {
389 param &= ~(1 << 31);
390 goto calcthumbrgn;
391 }
392 /* FALLTHROUGH */
393 case calcCntlRgn:
394 rgn = (RgnHandle)param;
395 RectRgn(rgn, &(*control)->contrlRect);
396 return 0;
397 case calcThumbRgn:
398 calcthumbrgn:
399 rgn = (RgnHandle)param;
400 SetEmptyRgn(rgn);
401 return 0;
402 }
403
404 return 0;
405 }
406 #endif
407
408 static void macctrl_editbox(struct macctrls *mcs, WindowPtr window,
409 struct mac_layoutstate *curstate,
410 union control *ctrl)
411 {
412 union macctrl *mc = smalloc(sizeof *mc);
413 Rect bounds;
414
415 fprintf(stderr, " label = %s\n", ctrl->editbox.label);
416 fprintf(stderr, " percentwidth = %d\n", ctrl->editbox.percentwidth);
417 if (ctrl->editbox.password) fprintf(stderr, " password\n");
418 if (ctrl->editbox.has_list) fprintf(stderr, " has list\n");
419 mc->generic.type = MACCTRL_EDITBOX;
420 mc->generic.ctrl = ctrl;
421 mc->generic.privdata = NULL;
422 bounds.left = curstate->pos.h;
423 bounds.right = bounds.left + curstate->width;
424 bounds.top = curstate->pos.v;
425 bounds.bottom = bounds.top + 22;
426 if (mac_gestalts.apprvers >= 0x100) {
427 InsetRect(&bounds, 2, 2);
428 mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
429 ctrl->editbox.password ?
430 kControlEditTextPasswordProc :
431 kControlEditTextProc, (long)mc);
432 } else {
433 mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0,
434 SYS7_EDITBOX_PROC, (long)mc);
435 }
436 curstate->pos.v += 28;
437 add234(mcs->byctrl, mc);
438 mc->generic.next = mcs->panels[curstate->panelnum];
439 mcs->panels[curstate->panelnum] = mc;
440 ctrlevent(mcs, mc, EVENT_REFRESH);
441 }
442
443 #if !TARGET_API_MAC_CARBON
444 static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16 variant,
445 ControlRef control,
446 ControlDefProcMessage msg,
447 SInt32 param)
448 {
449 RgnHandle rgn;
450 Rect rect;
451 TEHandle te;
452 long ssfs;
453
454 switch (msg) {
455 case initCntl:
456 rect = (*control)->contrlRect;
457 InsetRect(&rect, 3, 3); /* 2 if it's 20 pixels high */
458 te = TENew(&rect, &rect);
459 ssfs = GetScriptVariable(smSystemScript, smScriptSysFondSize);
460 (*te)->txSize = LoWord(ssfs);
461 (*te)->txFont = HiWord(ssfs);
462 (*control)->contrlData = (Handle)te;
463 return noErr;
464 case dispCntl:
465 TEDispose((TEHandle)(*control)->contrlData);
466 return 0;
467 case drawCntl:
468 if ((*control)->contrlVis) {
469 rect = (*control)->contrlRect;
470 PenNormal();
471 FrameRect(&rect);
472 InsetRect(&rect, 3, 3);
473 TEUpdate(&rect, (TEHandle)(*control)->contrlData);
474 }
475 return 0;
476 case calcCRgns:
477 if (param & (1 << 31)) {
478 param &= ~(1 << 31);
479 goto calcthumbrgn;
480 }
481 /* FALLTHROUGH */
482 case calcCntlRgn:
483 rgn = (RgnHandle)param;
484 RectRgn(rgn, &(*control)->contrlRect);
485 return 0;
486 case calcThumbRgn:
487 calcthumbrgn:
488 rgn = (RgnHandle)param;
489 SetEmptyRgn(rgn);
490 return 0;
491 }
492
493 return 0;
494 }
495 #endif
496
497 static void macctrl_radio(struct macctrls *mcs, WindowPtr window,
498 struct mac_layoutstate *curstate,
499 union control *ctrl)
500 {
501 union macctrl *mc = smalloc(sizeof *mc);
502 Rect bounds;
503 Str255 title;
504 unsigned int i, colwidth;
505
506 fprintf(stderr, " label = %s\n", ctrl->radio.label);
507 mc->generic.type = MACCTRL_RADIO;
508 mc->generic.ctrl = ctrl;
509 mc->generic.privdata = NULL;
510 mc->radio.tbctrls =
511 smalloc(sizeof(*mc->radio.tbctrls) * ctrl->radio.nbuttons);
512 colwidth = (curstate->width + 13) / ctrl->radio.ncolumns;
513 for (i = 0; i < ctrl->radio.nbuttons; i++) {
514 fprintf(stderr, " button = %s\n", ctrl->radio.buttons[i]);
515 bounds.top = curstate->pos.v - 2;
516 bounds.bottom = bounds.top + 18;
517 bounds.left = curstate->pos.h + colwidth * (i % ctrl->radio.ncolumns);
518 if (i == ctrl->radio.nbuttons - 1 ||
519 i % ctrl->radio.ncolumns == ctrl->radio.ncolumns - 1) {
520 bounds.right = curstate->pos.h + curstate->width;
521 curstate->pos.v += 18;
522 } else
523 bounds.right = bounds.left + colwidth - 13;
524 c2pstrcpy(title, ctrl->radio.buttons[i]);
525 mc->radio.tbctrls[i] = NewControl(window, &bounds, title, TRUE,
526 0, 0, 1, radioButProc, (long)mc);
527 }
528 curstate->pos.v += 4;
529 add234(mcs->byctrl, mc);
530 mc->generic.next = mcs->panels[curstate->panelnum];
531 mcs->panels[curstate->panelnum] = mc;
532 ctrlevent(mcs, mc, EVENT_REFRESH);
533 }
534
535 static void macctrl_checkbox(struct macctrls *mcs, WindowPtr window,
536 struct mac_layoutstate *curstate,
537 union control *ctrl)
538 {
539 union macctrl *mc = smalloc(sizeof *mc);
540 Rect bounds;
541 Str255 title;
542
543 fprintf(stderr, " label = %s\n", ctrl->checkbox.label);
544 mc->generic.type = MACCTRL_CHECKBOX;
545 mc->generic.ctrl = ctrl;
546 mc->generic.privdata = NULL;
547 bounds.left = curstate->pos.h;
548 bounds.right = bounds.left + curstate->width;
549 bounds.top = curstate->pos.v;
550 bounds.bottom = bounds.top + 16;
551 c2pstrcpy(title, ctrl->checkbox.label);
552 mc->checkbox.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1,
553 checkBoxProc, (long)mc);
554 add234(mcs->byctrl, mc);
555 curstate->pos.v += 22;
556 mc->generic.next = mcs->panels[curstate->panelnum];
557 mcs->panels[curstate->panelnum] = mc;
558 ctrlevent(mcs, mc, EVENT_REFRESH);
559 }
560
561 static void macctrl_button(struct macctrls *mcs, WindowPtr window,
562 struct mac_layoutstate *curstate,
563 union control *ctrl)
564 {
565 union macctrl *mc = smalloc(sizeof *mc);
566 Rect bounds;
567 Str255 title;
568
569 fprintf(stderr, " label = %s\n", ctrl->button.label);
570 if (ctrl->button.isdefault)
571 fprintf(stderr, " is default\n");
572 mc->generic.type = MACCTRL_BUTTON;
573 mc->generic.ctrl = ctrl;
574 mc->generic.privdata = NULL;
575 bounds.left = curstate->pos.h;
576 bounds.right = bounds.left + 100; /* XXX measure string */
577 bounds.top = curstate->pos.v;
578 bounds.bottom = bounds.top + 20;
579 c2pstrcpy(title, ctrl->button.label);
580 mc->button.tbctrl = NewControl(window, &bounds, title, TRUE, 0, 0, 1,
581 pushButProc, (long)mc);
582 if (mac_gestalts.apprvers >= 0x100) {
583 Boolean isdefault = ctrl->button.isdefault;
584
585 SetControlData(mc->button.tbctrl, kControlEntireControl,
586 kControlPushButtonDefaultTag,
587 sizeof(isdefault), &isdefault);
588 } else if (ctrl->button.isdefault) {
589 InsetRect(&bounds, -4, -4);
590 NewControl(window, &bounds, title, TRUE, 0, 0, 1,
591 SYS7_DEFAULT_PROC, (long)mc);
592 }
593 if (mac_gestalts.apprvers >= 0x110) {
594 Boolean iscancel = ctrl->button.iscancel;
595
596 SetControlData(mc->button.tbctrl, kControlEntireControl,
597 kControlPushButtonCancelTag,
598 sizeof(iscancel), &iscancel);
599 }
600 add234(mcs->byctrl, mc);
601 mc->generic.next = mcs->panels[curstate->panelnum];
602 mcs->panels[curstate->panelnum] = mc;
603 curstate->pos.v += 26;
604 }
605
606 #if !TARGET_API_MAC_CARBON
607 static pascal SInt32 macctrl_sys7_default_cdef(SInt16 variant,
608 ControlRef control,
609 ControlDefProcMessage msg,
610 SInt32 param)
611 {
612 RgnHandle rgn;
613 Rect rect;
614 int oval;
615
616 switch (msg) {
617 case drawCntl:
618 if ((*control)->contrlVis) {
619 rect = (*control)->contrlRect;
620 PenNormal();
621 PenSize(3, 3);
622 oval = (rect.bottom - rect.top) / 2 + 2;
623 FrameRoundRect(&rect, oval, oval);
624 }
625 return 0;
626 case calcCRgns:
627 if (param & (1 << 31)) {
628 param &= ~(1 << 31);
629 goto calcthumbrgn;
630 }
631 /* FALLTHROUGH */
632 case calcCntlRgn:
633 rgn = (RgnHandle)param;
634 RectRgn(rgn, &(*control)->contrlRect);
635 return 0;
636 case calcThumbRgn:
637 calcthumbrgn:
638 rgn = (RgnHandle)param;
639 SetEmptyRgn(rgn);
640 return 0;
641 }
642
643 return 0;
644 }
645 #endif
646
647 static void macctrl_popup(struct macctrls *mcs, WindowPtr window,
648 struct mac_layoutstate *curstate,
649 union control *ctrl)
650 {
651 union macctrl *mc = smalloc(sizeof *mc);
652 Rect bounds;
653 Str255 title;
654 unsigned int labelwidth;
655 static int nextmenuid = MENU_MIN;
656 int menuid;
657 MenuRef menu;
658
659 /*
660 * <http://developer.apple.com/qa/tb/tb42.html> explains how to
661 * create a popup menu with dynamic content.
662 */
663 assert(ctrl->listbox.height == 0);
664 assert(!ctrl->listbox.draglist);
665 assert(!ctrl->listbox.multisel);
666
667 fprintf(stderr, " label = %s\n", ctrl->listbox.label);
668 fprintf(stderr, " percentwidth = %d\n", ctrl->listbox.percentwidth);
669
670 mc->generic.type = MACCTRL_POPUP;
671 mc->generic.ctrl = ctrl;
672 mc->generic.privdata = NULL;
673 c2pstrcpy(title, ctrl->button.label);
674
675 /* Find a spare menu ID and create the menu */
676 while (GetMenuHandle(nextmenuid) != NULL)
677 if (++nextmenuid >= MENU_MAX) nextmenuid = MENU_MIN;
678 menuid = nextmenuid++;
679 menu = NewMenu(menuid, "\pdummy");
680 if (menu == NULL) return;
681 mc->popup.menu = menu;
682 mc->popup.menuid = menuid;
683 InsertMenu(menu, kInsertHierarchicalMenu);
684
685 /* The menu starts off empty */
686 mc->popup.nids = 0;
687 mc->popup.ids = NULL;
688
689 bounds.left = curstate->pos.h;
690 bounds.right = bounds.left + curstate->width;
691 bounds.top = curstate->pos.v;
692 bounds.bottom = bounds.top + 20;
693 /* XXX handle percentwidth == 100 */
694 labelwidth = curstate->width * (100 - ctrl->listbox.percentwidth) / 100;
695 mc->popup.tbctrl = NewControl(window, &bounds, title, TRUE,
696 popupTitleLeftJust, menuid, labelwidth,
697 popupMenuProc + popupFixedWidth, (long)mc);
698 add234(mcs->byctrl, mc);
699 curstate->pos.v += 26;
700 mc->generic.next = mcs->panels[curstate->panelnum];
701 mcs->panels[curstate->panelnum] = mc;
702 ctrlevent(mcs, mc, EVENT_REFRESH);
703 }
704
705
706 void macctrl_activate(WindowPtr window, EventRecord *event)
707 {
708 struct macctrls *mcs = mac_winctrls(window);
709 Boolean active = (event->modifiers & activeFlag) != 0;
710 GrafPtr saveport;
711 int i, j;
712 ControlPartCode state;
713 union macctrl *mc;
714
715 GetPort(&saveport);
716 SetPort((GrafPtr)GetWindowPort(window));
717 if (mac_gestalts.apprvers >= 0x100)
718 SetThemeWindowBackground(window, active ?
719 kThemeBrushModelessDialogBackgroundActive :
720 kThemeBrushModelessDialogBackgroundInactive,
721 TRUE);
722 state = active ? kControlNoPart : kControlInactivePart;
723 for (i = 0; i <= mcs->curpanel; i += mcs->curpanel)
724 for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next)
725 switch (mc->generic.type) {
726 case MACCTRL_TEXT:
727 HiliteControl(mc->text.tbctrl, state);
728 break;
729 case MACCTRL_EDITBOX:
730 HiliteControl(mc->editbox.tbctrl, state);
731 break;
732 case MACCTRL_RADIO:
733 for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
734 HiliteControl(mc->radio.tbctrls[j], state);
735 break;
736 case MACCTRL_CHECKBOX:
737 HiliteControl(mc->checkbox.tbctrl, state);
738 break;
739 case MACCTRL_BUTTON:
740 HiliteControl(mc->button.tbctrl, state);
741 break;
742 case MACCTRL_POPUP:
743 HiliteControl(mc->popup.tbctrl, state);
744 break;
745 }
746 SetPort(saveport);
747 }
748
749 void macctrl_click(WindowPtr window, EventRecord *event)
750 {
751 Point mouse;
752 ControlHandle control;
753 int part, trackresult;
754 GrafPtr saveport;
755 union macctrl *mc;
756 struct macctrls *mcs = mac_winctrls(window);
757 int i;
758 UInt32 features;
759
760 GetPort(&saveport);
761 SetPort((GrafPtr)GetWindowPort(window));
762 mouse = event->where;
763 GlobalToLocal(&mouse);
764 part = FindControl(mouse, window, &control);
765 if (control != NULL) {
766 if (mac_gestalts.apprvers >= 0x100) {
767 if (GetControlFeatures(control, &features) == noErr &&
768 (features & kControlSupportsFocus) &&
769 (features & kControlGetsFocusOnClick))
770 SetKeyboardFocus(window, control, part);
771 trackresult = HandleControlClick(control, mouse, event->modifiers,
772 (ControlActionUPP)-1);
773 } else
774 trackresult = TrackControl(control, mouse, (ControlActionUPP)-1);
775 mc = (union macctrl *)GetControlReference(control);
776 switch (mc->generic.type) {
777 case MACCTRL_RADIO:
778 if (trackresult != 0) {
779 for (i = 0; i < mc->generic.ctrl->radio.nbuttons; i++)
780 if (mc->radio.tbctrls[i] == control)
781 SetControlValue(mc->radio.tbctrls[i],
782 kControlRadioButtonCheckedValue);
783 else
784 SetControlValue(mc->radio.tbctrls[i],
785 kControlRadioButtonUncheckedValue);
786 ctrlevent(mcs, mc, EVENT_VALCHANGE);
787 }
788 break;
789 case MACCTRL_CHECKBOX:
790 if (trackresult != 0) {
791 SetControlValue(control, !GetControlValue(control));
792 ctrlevent(mcs, mc, EVENT_VALCHANGE);
793 }
794 break;
795 case MACCTRL_BUTTON:
796 if (trackresult != 0)
797 ctrlevent(mcs, mc, EVENT_ACTION);
798 break;
799 case MACCTRL_POPUP:
800 ctrlevent(mcs, mc, EVENT_SELCHANGE);
801 break;
802 }
803 }
804 SetPort(saveport);
805 }
806
807 void macctrl_key(WindowPtr window, EventRecord *event)
808 {
809 ControlRef control;
810 struct macctrls *mcs = mac_winctrls(window);
811 union macctrl *mc;
812
813 if (mac_gestalts.apprvers >= 0x100 &&
814 GetKeyboardFocus(window, &control) == noErr && control != NULL) {
815 HandleControlKey(control, (event->message & keyCodeMask) >> 8,
816 event->message & charCodeMask, event->modifiers);
817 mc = (union macctrl *)GetControlReference(control);
818 ctrlevent(mcs, mc, EVENT_VALCHANGE);
819 }
820 }
821
822 void macctrl_update(WindowPtr window)
823 {
824 #if TARGET_API_MAC_CARBON
825 RgnHandle visrgn;
826 #endif
827 Rect rect;
828 GrafPtr saveport;
829
830 BeginUpdate(window);
831 GetPort(&saveport);
832 SetPort((GrafPtr)GetWindowPort(window));
833 if (mac_gestalts.apprvers >= 0x101) {
834 #if TARGET_API_MAC_CARBON
835 GetPortBounds(GetWindowPort(window), &rect);
836 #else
837 rect = window->portRect;
838 #endif
839 InsetRect(&rect, -1, -1);
840 DrawThemeModelessDialogFrame(&rect, mac_frontwindow() == window ?
841 kThemeStateActive : kThemeStateInactive);
842 }
843 #if TARGET_API_MAC_CARBON
844 visrgn = NewRgn();
845 GetPortVisibleRegion(GetWindowPort(window), visrgn);
846 UpdateControls(window, visrgn);
847 DisposeRgn(visrgn);
848 #else
849 UpdateControls(window, window->visRgn);
850 #endif
851 SetPort(saveport);
852 EndUpdate(window);
853 }
854
855 #if TARGET_API_MAC_CARBON
856 #define EnableItem EnableMenuItem
857 #define DisableItem DisableMenuItem
858 #endif
859 void macctrl_adjustmenus(WindowPtr window)
860 {
861 MenuHandle menu;
862
863 menu = GetMenuHandle(mFile);
864 DisableItem(menu, iSave); /* XXX enable if modified */
865 EnableItem(menu, iSaveAs);
866 EnableItem(menu, iDuplicate);
867
868 menu = GetMenuHandle(mEdit);
869 DisableItem(menu, 0);
870 }
871
872 void macctrl_close(WindowPtr window)
873 {
874 struct macctrls *mcs = mac_winctrls(window);
875 union macctrl *mc;
876
877 /*
878 * Mostly, we don't bother disposing of the Toolbox controls,
879 * since that will happen automatically when the window is
880 * disposed of. Popup menus are an exception, because we have to
881 * dispose of the menu ourselves, and doing that while the control
882 * still holds a reference to it seems rude.
883 */
884 while ((mc = index234(mcs->byctrl, 0)) != NULL) {
885 if (mc->generic.privdata != NULL && mc->generic.freeprivdata)
886 sfree(mc->generic.privdata);
887 switch (mc->generic.type) {
888 case MACCTRL_POPUP:
889 DisposeControl(mc->popup.tbctrl);
890 DeleteMenu(mc->popup.menuid);
891 DisposeMenu(mc->popup.menu);
892 break;
893 }
894 del234(mcs->byctrl, mc);
895 sfree(mc);
896 }
897
898 freetree234(mcs->byctrl);
899 mcs->byctrl = NULL;
900 sfree(mcs->panels);
901 mcs->panels = NULL;
902 }
903
904 void dlg_update_start(union control *ctrl, void *dlg)
905 {
906
907 /* No-op for now */
908 }
909
910 void dlg_update_done(union control *ctrl, void *dlg)
911 {
912
913 /* No-op for now */
914 }
915
916 void dlg_set_focus(union control *ctrl, void *dlg)
917 {
918
919 if (mac_gestalts.apprvers >= 0x100) {
920 /* Use SetKeyboardFocus() */
921 } else {
922 /* Do our own mucking around */
923 }
924 }
925
926 union control *dlg_last_focused(union control *ctrl, void *dlg)
927 {
928
929 return NULL;
930 }
931
932 void dlg_beep(void *dlg)
933 {
934
935 SysBeep(30);
936 }
937
938 void dlg_error_msg(void *dlg, char *msg)
939 {
940 Str255 pmsg;
941
942 c2pstrcpy(pmsg, msg);
943 ParamText(pmsg, NULL, NULL, NULL);
944 StopAlert(128, NULL);
945 }
946
947 void dlg_end(void *dlg, int value)
948 {
949
950 };
951
952 void dlg_refresh(union control *ctrl, void *dlg)
953 {
954 struct macctrls *mcs = dlg;
955 union macctrl *mc;
956
957 if (ctrl == NULL)
958 return; /* FIXME */
959 mc = findbyctrl(mcs, ctrl);
960 assert(mc != NULL);
961 ctrlevent(mcs, mc, EVENT_REFRESH);
962 };
963
964 void *dlg_get_privdata(union control *ctrl, void *dlg)
965 {
966 struct macctrls *mcs = dlg;
967 union macctrl *mc = findbyctrl(mcs, ctrl);
968
969 assert(mc != NULL);
970 return mc->generic.privdata;
971 }
972
973 void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr)
974 {
975 struct macctrls *mcs = dlg;
976 union macctrl *mc = findbyctrl(mcs, ctrl);
977
978 assert(mc != NULL);
979 mc->generic.privdata = ptr;
980 mc->generic.freeprivdata = FALSE;
981 }
982
983 void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size)
984 {
985 struct macctrls *mcs = dlg;
986 union macctrl *mc = findbyctrl(mcs, ctrl);
987
988 assert(mc != NULL);
989 mc->generic.privdata = smalloc(size);
990 mc->generic.freeprivdata = TRUE;
991 return mc->generic.privdata;
992 }
993
994
995 /*
996 * Radio Button control
997 */
998
999 void dlg_radiobutton_set(union control *ctrl, void *dlg, int whichbutton)
1000 {
1001 struct macctrls *mcs = dlg;
1002 union macctrl *mc = findbyctrl(mcs, ctrl);
1003 int i;
1004
1005 assert(mc != NULL);
1006 for (i = 0; i < ctrl->radio.nbuttons; i++) {
1007 if (i == whichbutton)
1008 SetControlValue(mc->radio.tbctrls[i],
1009 kControlRadioButtonCheckedValue);
1010 else
1011 SetControlValue(mc->radio.tbctrls[i],
1012 kControlRadioButtonUncheckedValue);
1013 }
1014
1015 };
1016
1017 int dlg_radiobutton_get(union control *ctrl, void *dlg)
1018 {
1019 struct macctrls *mcs = dlg;
1020 union macctrl *mc = findbyctrl(mcs, ctrl);
1021 int i;
1022
1023 assert(mc != NULL);
1024 for (i = 0; i < ctrl->radio.nbuttons; i++) {
1025 if (GetControlValue(mc->radio.tbctrls[i]) ==
1026 kControlRadioButtonCheckedValue)
1027 return i;
1028 }
1029 return -1;
1030 };
1031
1032
1033 /*
1034 * Check Box control
1035 */
1036
1037 void dlg_checkbox_set(union control *ctrl, void *dlg, int checked)
1038 {
1039 struct macctrls *mcs = dlg;
1040 union macctrl *mc = findbyctrl(mcs, ctrl);
1041
1042 assert(mc != NULL);
1043 SetControlValue(mc->checkbox.tbctrl,
1044 checked ? kControlCheckBoxCheckedValue :
1045 kControlCheckBoxUncheckedValue);
1046 }
1047
1048 int dlg_checkbox_get(union control *ctrl, void *dlg)
1049 {
1050 struct macctrls *mcs = dlg;
1051 union macctrl *mc = findbyctrl(mcs, ctrl);
1052
1053 assert(mc != NULL);
1054 return GetControlValue(mc->checkbox.tbctrl);
1055 }
1056
1057
1058 /*
1059 * Edit Box control
1060 */
1061
1062 void dlg_editbox_set(union control *ctrl, void *dlg, char const *text)
1063 {
1064 struct macctrls *mcs = dlg;
1065 union macctrl *mc = findbyctrl(mcs, ctrl);
1066 GrafPtr saveport;
1067
1068 assert(mc != NULL);
1069 assert(mc->generic.type == MACCTRL_EDITBOX);
1070 GetPort(&saveport);
1071 SetPort((GrafPtr)(GetWindowPort(mcs->window)));
1072 if (mac_gestalts.apprvers >= 0x100)
1073 SetControlData(mc->editbox.tbctrl, kControlEntireControl,
1074 ctrl->editbox.password ?
1075 kControlEditTextPasswordTag :
1076 kControlEditTextTextTag,
1077 strlen(text), text);
1078 else
1079 TESetText(text, strlen(text),
1080 (TEHandle)(*mc->editbox.tbctrl)->contrlData);
1081 DrawOneControl(mc->editbox.tbctrl);
1082 SetPort(saveport);
1083 }
1084
1085 void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length)
1086 {
1087 struct macctrls *mcs = dlg;
1088 union macctrl *mc = findbyctrl(mcs, ctrl);
1089 TEHandle te;
1090 Size olen;
1091
1092 assert(mc != NULL);
1093 assert(mc->generic.type == MACCTRL_EDITBOX);
1094 if (mac_gestalts.apprvers >= 0x100) {
1095 if (GetControlData(mc->editbox.tbctrl, kControlEntireControl,
1096 ctrl->editbox.password ?
1097 kControlEditTextPasswordTag :
1098 kControlEditTextTextTag,
1099 length - 1, buffer, &olen) != noErr)
1100 olen = 0;
1101 if (olen > length - 1)
1102 olen = length - 1;
1103 } else {
1104 te = (TEHandle)(*mc->editbox.tbctrl)->contrlData;
1105 olen = (*te)->teLength;
1106 if (olen > length - 1)
1107 olen = length - 1;
1108 memcpy(buffer, *(*te)->hText, olen);
1109 }
1110 buffer[olen] = '\0';
1111 fprintf(stderr, "dlg_editbox_get: %s\n", buffer);
1112 }
1113
1114
1115 /*
1116 * List Box control
1117 */
1118
1119 static void dlg_macpopup_clear(union control *ctrl, void *dlg)
1120 {
1121 struct macctrls *mcs = dlg;
1122 union macctrl *mc = findbyctrl(mcs, ctrl);
1123 MenuRef menu = mc->popup.menu;
1124 unsigned int i, n;
1125
1126 fprintf(stderr, " popup_clear\n");
1127 n = CountMenuItems(menu);
1128 for (i = 0; i < n; i++)
1129 DeleteMenuItem(menu, n - i);
1130 mc->popup.nids = 0;
1131 sfree(mc->popup.ids);
1132 mc->popup.ids = NULL;
1133 SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
1134 }
1135
1136 void dlg_listbox_clear(union control *ctrl, void *dlg)
1137 {
1138
1139 if (ctrl->listbox.height == 0)
1140 dlg_macpopup_clear(ctrl, dlg);
1141 }
1142
1143 static void dlg_macpopup_del(union control *ctrl, void *dlg, int index)
1144 {
1145 struct macctrls *mcs = dlg;
1146 union macctrl *mc = findbyctrl(mcs, ctrl);
1147 MenuRef menu = mc->popup.menu;
1148
1149 fprintf(stderr, " popup_del %d\n", index);
1150 DeleteMenuItem(menu, index + 1);
1151 if (mc->popup.ids != NULL)
1152 memcpy(mc->popup.ids + index, mc->popup.ids + index + 1,
1153 (mc->popup.nids - index - 1) * sizeof(*mc->popup.ids));
1154 SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
1155 }
1156
1157 void dlg_listbox_del(union control *ctrl, void *dlg, int index)
1158 {
1159
1160 if (ctrl->listbox.height == 0)
1161 dlg_macpopup_del(ctrl, dlg, index);
1162 }
1163
1164 static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text)
1165 {
1166 struct macctrls *mcs = dlg;
1167 union macctrl *mc = findbyctrl(mcs, ctrl);
1168 MenuRef menu = mc->popup.menu;
1169 Str255 itemstring;
1170
1171 fprintf(stderr, " popup_add %s\n", text);
1172 assert(text[0] != '\0');
1173 c2pstrcpy(itemstring, text);
1174 AppendMenu(menu, "\pdummy");
1175 SetMenuItemText(menu, CountMenuItems(menu), itemstring);
1176 SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));
1177 }
1178
1179 void dlg_listbox_add(union control *ctrl, void *dlg, char const *text)
1180 {
1181
1182 if (ctrl->listbox.height == 0)
1183 dlg_macpopup_add(ctrl, dlg, text);
1184 }
1185
1186 static void dlg_macpopup_addwithid(union control *ctrl, void *dlg,
1187 char const *text, int id)
1188 {
1189 struct macctrls *mcs = dlg;
1190 union macctrl *mc = findbyctrl(mcs, ctrl);
1191 MenuRef menu = mc->popup.menu;
1192 unsigned int index;
1193
1194 fprintf(stderr, " popup_addwthindex %s, %d\n", text, id);
1195 dlg_macpopup_add(ctrl, dlg, text);
1196 index = CountMenuItems(menu) - 1;
1197 if (mc->popup.nids <= index) {
1198 mc->popup.nids = index + 1;
1199 mc->popup.ids = srealloc(mc->popup.ids,
1200 mc->popup.nids * sizeof(*mc->popup.ids));
1201 }
1202 mc->popup.ids[index] = id;
1203 }
1204
1205 void dlg_listbox_addwithid(union control *ctrl, void *dlg,
1206 char const *text, int id)
1207 {
1208
1209 if (ctrl->listbox.height == 0)
1210 dlg_macpopup_addwithid(ctrl, dlg, text, id);
1211 }
1212
1213 int dlg_listbox_getid(union control *ctrl, void *dlg, int index)
1214 {
1215 struct macctrls *mcs = dlg;
1216 union macctrl *mc = findbyctrl(mcs, ctrl);
1217
1218 if (ctrl->listbox.height == 0) {
1219 assert(mc->popup.ids != NULL && mc->popup.nids > index);
1220 return mc->popup.ids[index];
1221 }
1222 return 0;
1223 }
1224
1225 int dlg_listbox_index(union control *ctrl, void *dlg)
1226 {
1227 struct macctrls *mcs = dlg;
1228 union macctrl *mc = findbyctrl(mcs, ctrl);
1229
1230 if (ctrl->listbox.height == 0)
1231 return GetControlValue(mc->popup.tbctrl) - 1;
1232 return 0;
1233 };
1234
1235 int dlg_listbox_issel(union control *ctrl, void *dlg, int index)
1236 {
1237 struct macctrls *mcs = dlg;
1238 union macctrl *mc = findbyctrl(mcs, ctrl);
1239
1240 if (ctrl->listbox.height == 0)
1241 return GetControlValue(mc->popup.tbctrl) - 1 == index;
1242 return 0;
1243 };
1244
1245 void dlg_listbox_select(union control *ctrl, void *dlg, int index)
1246 {
1247 struct macctrls *mcs = dlg;
1248 union macctrl *mc = findbyctrl(mcs, ctrl);
1249
1250 if (ctrl->listbox.height == 0)
1251 SetControlValue(mc->popup.tbctrl, index + 1);
1252 };
1253
1254
1255 /*
1256 * Text control
1257 */
1258
1259 void dlg_text_set(union control *ctrl, void *dlg, char const *text)
1260 {
1261 struct macctrls *mcs = dlg;
1262 union macctrl *mc = findbyctrl(mcs, ctrl);
1263 Str255 title;
1264
1265 assert(mc != NULL);
1266 if (mac_gestalts.apprvers >= 0x100)
1267 SetControlData(mc->text.tbctrl, kControlEntireControl,
1268 kControlStaticTextTextTag, strlen(text), text);
1269 else {
1270 c2pstrcpy(title, text);
1271 SetControlTitle(mc->text.tbctrl, title);
1272 }
1273 }
1274
1275
1276 /*
1277 * File Selector control
1278 */
1279
1280 void dlg_filesel_set(union control *ctrl, void *dlg, Filename fn)
1281 {
1282
1283 }
1284
1285 void dlg_filesel_get(union control *ctrl, void *dlg, Filename *fn)
1286 {
1287
1288 }
1289
1290
1291 /*
1292 * Font Selector control
1293 */
1294
1295 void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec fn)
1296 {
1297
1298 }
1299
1300 void dlg_fontsel_get(union control *ctrl, void *dlg, FontSpec *fn)
1301 {
1302
1303 }
1304
1305
1306 /*
1307 * Printer enumeration
1308 */
1309
1310 printer_enum *printer_start_enum(int *nprinters)
1311 {
1312
1313 *nprinters = 0;
1314 return NULL;
1315 }
1316
1317 char *printer_get_name(printer_enum *pe, int thing)
1318 {
1319
1320 return "<none>";
1321 }
1322
1323 void printer_finish_enum(printer_enum *pe)
1324 {
1325
1326 }
1327
1328
1329 /*
1330 * Colour selection stuff
1331 */
1332
1333 void dlg_coloursel_start(union control *ctrl, void *dlg,
1334 int r, int g, int b)
1335 {
1336
1337 }
1338
1339 int dlg_coloursel_results(union control *ctrl, void *dlg,
1340 int *r, int *g, int *b)
1341 {
1342
1343 return 0;
1344 }
1345
1346 /*
1347 * Local Variables:
1348 * c-file-style: "simon"
1349 * End:
1350 */