d9158b5e |
1 | /* $Id: macctrls.c,v 1.17 2003/03/28 00:50:04 ben Exp $ */ |
8a7e67ec |
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> |
56c01970 |
32 | #include <Menus.h> |
fa4942e7 |
33 | #include <Resources.h> |
0e9ce565 |
34 | #include <Script.h> |
8a7e67ec |
35 | #include <Sound.h> |
0e9ce565 |
36 | #include <TextEdit.h> |
8a7e67ec |
37 | #include <TextUtils.h> |
0e9ce565 |
38 | #include <ToolUtils.h> |
8a7e67ec |
39 | #include <Windows.h> |
40 | |
93ba25f8 |
41 | #include <assert.h> |
ee10bc56 |
42 | #include <string.h> |
93ba25f8 |
43 | |
8a7e67ec |
44 | #include "putty.h" |
45 | #include "mac.h" |
46 | #include "macresid.h" |
47 | #include "dialog.h" |
48 | #include "tree234.h" |
49 | |
56c01970 |
50 | /* Range of menu IDs for popup menus */ |
51 | #define MENU_MIN 1024 |
52 | #define MENU_MAX 2048 |
53 | |
54 | |
8a7e67ec |
55 | union macctrl { |
56 | struct macctrl_generic { |
57 | enum { |
58 | MACCTRL_TEXT, |
1f1ec0e5 |
59 | MACCTRL_EDITBOX, |
8a7e67ec |
60 | MACCTRL_RADIO, |
61 | MACCTRL_CHECKBOX, |
56c01970 |
62 | MACCTRL_BUTTON, |
63 | MACCTRL_POPUP |
8a7e67ec |
64 | } type; |
65 | /* Template from which this was generated */ |
66 | union control *ctrl; |
ee10bc56 |
67 | /* Next control in this panel */ |
68 | union macctrl *next; |
1f1ec0e5 |
69 | void *privdata; |
70 | int freeprivdata; |
8a7e67ec |
71 | } generic; |
72 | struct { |
73 | struct macctrl_generic generic; |
74 | ControlRef tbctrl; |
75 | } text; |
76 | struct { |
77 | struct macctrl_generic generic; |
1f1ec0e5 |
78 | ControlRef tbctrl; |
79 | } editbox; |
80 | struct { |
81 | struct macctrl_generic generic; |
8a7e67ec |
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; |
56c01970 |
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; |
8a7e67ec |
100 | }; |
101 | |
102 | struct mac_layoutstate { |
103 | Point pos; |
104 | unsigned int width; |
ee10bc56 |
105 | unsigned int panelnum; |
8a7e67ec |
106 | }; |
107 | |
108 | #define ctrlevent(mcs, mc, event) do { \ |
109 | if ((mc)->generic.ctrl->generic.handler != NULL) \ |
93ba25f8 |
110 | (*(mc)->generic.ctrl->generic.handler)((mc)->generic.ctrl, (mcs),\ |
8a7e67ec |
111 | (mcs)->data, (event)); \ |
112 | } while (0) |
113 | |
93ba25f8 |
114 | #define findbyctrl(mcs, ctrl) \ |
115 | find234((mcs)->byctrl, (ctrl), macctrl_cmp_byctrl_find) |
116 | |
8a7e67ec |
117 | static void macctrl_layoutset(struct mac_layoutstate *, struct controlset *, |
118 | WindowPtr, struct macctrls *); |
ee10bc56 |
119 | static void macctrl_switchtopanel(struct macctrls *, unsigned int); |
8a7e67ec |
120 | static void macctrl_text(struct macctrls *, WindowPtr, |
121 | struct mac_layoutstate *, union control *); |
1f1ec0e5 |
122 | static void macctrl_editbox(struct macctrls *, WindowPtr, |
123 | struct mac_layoutstate *, union control *); |
8a7e67ec |
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 *); |
56c01970 |
130 | static void macctrl_popup(struct macctrls *, WindowPtr, |
131 | struct mac_layoutstate *, union control *); |
fa4942e7 |
132 | #if !TARGET_API_MAC_CARBON |
133 | static pascal SInt32 macctrl_sys7_text_cdef(SInt16, ControlRef, |
134 | ControlDefProcMessage, SInt32); |
0e9ce565 |
135 | static pascal SInt32 macctrl_sys7_editbox_cdef(SInt16, ControlRef, |
136 | ControlDefProcMessage, SInt32); |
5537f572 |
137 | static pascal SInt32 macctrl_sys7_default_cdef(SInt16, ControlRef, |
138 | ControlDefProcMessage, SInt32); |
fa4942e7 |
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); |
0e9ce565 |
165 | cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_EditBox); |
166 | (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_editbox_cdef); |
5537f572 |
167 | cdef = (PatchCDEF)GetResource(kControlDefProcResourceType, CDEF_Default); |
168 | (*cdef)->theUPP = NewControlDefProc(macctrl_sys7_default_cdef); |
fa4942e7 |
169 | inited = 1; |
170 | #endif |
171 | } |
172 | |
8a7e67ec |
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 | |
93ba25f8 |
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 | |
8a7e67ec |
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; |
fa4942e7 |
207 | |
208 | macctrl_init(); |
8a7e67ec |
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; |
ee10bc56 |
215 | curstate.pos.v = rect.bottom - 59; |
8a7e67ec |
216 | curstate.width = rect.right - rect.left - (13 * 2); |
217 | if (mac_gestalts.apprvers >= 0x100) |
218 | CreateRootControl(window, &root); |
1f1ec0e5 |
219 | mcs->window = window; |
8a7e67ec |
220 | mcs->byctrl = newtree234(macctrl_cmp_byctrl); |
ee10bc56 |
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 | } |
8a7e67ec |
236 | macctrl_layoutset(&curstate, cb->ctrlsets[i], window, mcs); |
ee10bc56 |
237 | } |
1f1ec0e5 |
238 | macctrl_switchtopanel(mcs, 1); |
8a7e67ec |
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"); |
93ba25f8 |
248 | fprintf(stderr, "pathname = %s\n", s->pathname); |
8a7e67ec |
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; |
1f1ec0e5 |
277 | case CTRL_EDITBOX: |
278 | macctrl_editbox(mcs, window, curstate, ctrl); |
279 | break; |
8a7e67ec |
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; |
56c01970 |
289 | case CTRL_LISTBOX: |
290 | if (ctrl->listbox.height == 0) |
291 | macctrl_popup(mcs, window, curstate, ctrl); |
292 | break; |
8a7e67ec |
293 | } |
294 | } |
295 | } |
296 | |
ee10bc56 |
297 | static void macctrl_switchtopanel(struct macctrls *mcs, unsigned int which) |
298 | { |
299 | unsigned int i, j; |
300 | union macctrl *mc; |
301 | |
0a33efe1 |
302 | #define hideshow(c) do { \ |
303 | if (i == which) ShowControl(c); else HideControl(c); \ |
304 | } while (0) |
305 | |
306 | mcs->curpanel = which; |
ee10bc56 |
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: |
0a33efe1 |
312 | hideshow(mc->text.tbctrl); |
ee10bc56 |
313 | break; |
1f1ec0e5 |
314 | case MACCTRL_EDITBOX: |
315 | hideshow(mc->editbox.tbctrl); |
316 | break; |
ee10bc56 |
317 | case MACCTRL_RADIO: |
318 | for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++) |
0a33efe1 |
319 | hideshow(mc->radio.tbctrls[j]); |
ee10bc56 |
320 | break; |
321 | case MACCTRL_CHECKBOX: |
0a33efe1 |
322 | hideshow(mc->checkbox.tbctrl); |
ee10bc56 |
323 | break; |
324 | case MACCTRL_BUTTON: |
0a33efe1 |
325 | hideshow(mc->button.tbctrl); |
326 | break; |
327 | case MACCTRL_POPUP: |
328 | hideshow(mc->popup.tbctrl); |
ee10bc56 |
329 | break; |
ee10bc56 |
330 | } |
331 | } |
332 | |
8a7e67ec |
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; |
1f1ec0e5 |
343 | mc->generic.privdata = NULL; |
8a7e67ec |
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 { |
fa4942e7 |
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); |
8a7e67ec |
369 | } |
370 | add234(mcs->byctrl, mc); |
ee10bc56 |
371 | mc->generic.next = mcs->panels[curstate->panelnum]; |
372 | mcs->panels[curstate->panelnum] = mc; |
8a7e67ec |
373 | } |
374 | |
fa4942e7 |
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 | |
1f1ec0e5 |
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; |
0e9ce565 |
424 | bounds.top = curstate->pos.v; |
425 | bounds.bottom = bounds.top + 22; |
1f1ec0e5 |
426 | if (mac_gestalts.apprvers >= 0x100) { |
0e9ce565 |
427 | InsetRect(&bounds, 2, 2); |
1f1ec0e5 |
428 | mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0, |
429 | ctrl->editbox.password ? |
430 | kControlEditTextPasswordProc : |
431 | kControlEditTextProc, (long)mc); |
1f1ec0e5 |
432 | } else { |
0e9ce565 |
433 | mc->text.tbctrl = NewControl(window, &bounds, NULL, TRUE, 0, 0, 0, |
434 | SYS7_EDITBOX_PROC, (long)mc); |
1f1ec0e5 |
435 | } |
0e9ce565 |
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); |
1f1ec0e5 |
441 | } |
442 | |
0e9ce565 |
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 | |
8a7e67ec |
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; |
1f1ec0e5 |
509 | mc->generic.privdata = NULL; |
8a7e67ec |
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]); |
35790008 |
515 | bounds.top = curstate->pos.v - 2; |
516 | bounds.bottom = bounds.top + 18; |
8a7e67ec |
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; |
35790008 |
521 | curstate->pos.v += 18; |
8a7e67ec |
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 | } |
35790008 |
528 | curstate->pos.v += 4; |
8a7e67ec |
529 | add234(mcs->byctrl, mc); |
ee10bc56 |
530 | mc->generic.next = mcs->panels[curstate->panelnum]; |
531 | mcs->panels[curstate->panelnum] = mc; |
8a7e67ec |
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; |
1f1ec0e5 |
546 | mc->generic.privdata = NULL; |
8a7e67ec |
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; |
ee10bc56 |
556 | mc->generic.next = mcs->panels[curstate->panelnum]; |
557 | mcs->panels[curstate->panelnum] = mc; |
8a7e67ec |
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; |
1f1ec0e5 |
574 | mc->generic.privdata = NULL; |
8a7e67ec |
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); |
5537f572 |
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); |
8a7e67ec |
592 | } |
855d05c4 |
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 | } |
8a7e67ec |
600 | add234(mcs->byctrl, mc); |
ee10bc56 |
601 | mc->generic.next = mcs->panels[curstate->panelnum]; |
602 | mcs->panels[curstate->panelnum] = mc; |
8a7e67ec |
603 | curstate->pos.v += 26; |
604 | } |
605 | |
5537f572 |
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 | |
56c01970 |
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; |
0a33efe1 |
655 | static int nextmenuid = MENU_MIN; |
56c01970 |
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; |
1f1ec0e5 |
672 | mc->generic.privdata = NULL; |
56c01970 |
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 | |
8a7e67ec |
705 | |
706 | void macctrl_activate(WindowPtr window, EventRecord *event) |
707 | { |
0a33efe1 |
708 | struct macctrls *mcs = mac_winctrls(window); |
8a7e67ec |
709 | Boolean active = (event->modifiers & activeFlag) != 0; |
710 | GrafPtr saveport; |
0a33efe1 |
711 | int i, j; |
712 | ControlPartCode state; |
713 | union macctrl *mc; |
8a7e67ec |
714 | |
715 | GetPort(&saveport); |
716 | SetPort((GrafPtr)GetWindowPort(window)); |
78f015b8 |
717 | if (mac_gestalts.apprvers >= 0x100) |
8a7e67ec |
718 | SetThemeWindowBackground(window, active ? |
719 | kThemeBrushModelessDialogBackgroundActive : |
720 | kThemeBrushModelessDialogBackgroundInactive, |
721 | TRUE); |
0a33efe1 |
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; |
1f1ec0e5 |
729 | case MACCTRL_EDITBOX: |
730 | HiliteControl(mc->editbox.tbctrl, state); |
731 | break; |
0a33efe1 |
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 | } |
8a7e67ec |
746 | SetPort(saveport); |
747 | } |
748 | |
749 | void macctrl_click(WindowPtr window, EventRecord *event) |
750 | { |
751 | Point mouse; |
752 | ControlHandle control; |
1f1ec0e5 |
753 | int part, trackresult; |
8a7e67ec |
754 | GrafPtr saveport; |
755 | union macctrl *mc; |
756 | struct macctrls *mcs = mac_winctrls(window); |
757 | int i; |
1f1ec0e5 |
758 | UInt32 features; |
8a7e67ec |
759 | |
760 | GetPort(&saveport); |
761 | SetPort((GrafPtr)GetWindowPort(window)); |
762 | mouse = event->where; |
763 | GlobalToLocal(&mouse); |
764 | part = FindControl(mouse, window, &control); |
56c01970 |
765 | if (control != NULL) { |
1f1ec0e5 |
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); |
56c01970 |
775 | mc = (union macctrl *)GetControlReference(control); |
776 | switch (mc->generic.type) { |
56c01970 |
777 | case MACCTRL_RADIO: |
1f1ec0e5 |
778 | if (trackresult != 0) { |
56c01970 |
779 | for (i = 0; i < mc->generic.ctrl->radio.nbuttons; i++) |
8a7e67ec |
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); |
8a7e67ec |
786 | ctrlevent(mcs, mc, EVENT_VALCHANGE); |
56c01970 |
787 | } |
788 | break; |
789 | case MACCTRL_CHECKBOX: |
1f1ec0e5 |
790 | if (trackresult != 0) { |
8a7e67ec |
791 | SetControlValue(control, !GetControlValue(control)); |
792 | ctrlevent(mcs, mc, EVENT_VALCHANGE); |
8a7e67ec |
793 | } |
56c01970 |
794 | break; |
795 | case MACCTRL_BUTTON: |
1f1ec0e5 |
796 | if (trackresult != 0) |
56c01970 |
797 | ctrlevent(mcs, mc, EVENT_ACTION); |
798 | break; |
1f1ec0e5 |
799 | case MACCTRL_POPUP: |
800 | ctrlevent(mcs, mc, EVENT_SELCHANGE); |
801 | break; |
8a7e67ec |
802 | } |
56c01970 |
803 | } |
8a7e67ec |
804 | SetPort(saveport); |
805 | } |
806 | |
1f1ec0e5 |
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 | |
8a7e67ec |
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 | |
56c01970 |
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 | */ |
8a7e67ec |
884 | while ((mc = index234(mcs->byctrl, 0)) != NULL) { |
1f1ec0e5 |
885 | if (mc->generic.privdata != NULL && mc->generic.freeprivdata) |
886 | sfree(mc->generic.privdata); |
56c01970 |
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 | } |
8a7e67ec |
894 | del234(mcs->byctrl, mc); |
895 | sfree(mc); |
896 | } |
897 | |
898 | freetree234(mcs->byctrl); |
899 | mcs->byctrl = NULL; |
ee10bc56 |
900 | sfree(mcs->panels); |
901 | mcs->panels = NULL; |
8a7e67ec |
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 | |
0bd8d76d |
926 | union control *dlg_last_focused(union control *ctrl, void *dlg) |
8a7e67ec |
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 | { |
1f1ec0e5 |
954 | struct macctrls *mcs = dlg; |
955 | union macctrl *mc; |
8a7e67ec |
956 | |
1f1ec0e5 |
957 | if (ctrl == NULL) |
958 | return; /* FIXME */ |
959 | mc = findbyctrl(mcs, ctrl); |
960 | assert(mc != NULL); |
961 | ctrlevent(mcs, mc, EVENT_REFRESH); |
8a7e67ec |
962 | }; |
963 | |
964 | void *dlg_get_privdata(union control *ctrl, void *dlg) |
965 | { |
1f1ec0e5 |
966 | struct macctrls *mcs = dlg; |
967 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
968 | |
1f1ec0e5 |
969 | assert(mc != NULL); |
970 | return mc->generic.privdata; |
8a7e67ec |
971 | } |
972 | |
973 | void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr) |
974 | { |
1f1ec0e5 |
975 | struct macctrls *mcs = dlg; |
976 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
977 | |
1f1ec0e5 |
978 | assert(mc != NULL); |
979 | mc->generic.privdata = ptr; |
980 | mc->generic.freeprivdata = FALSE; |
8a7e67ec |
981 | } |
982 | |
983 | void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size) |
984 | { |
1f1ec0e5 |
985 | struct macctrls *mcs = dlg; |
986 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
987 | |
1f1ec0e5 |
988 | assert(mc != NULL); |
989 | mc->generic.privdata = smalloc(size); |
990 | mc->generic.freeprivdata = TRUE; |
991 | return mc->generic.privdata; |
8a7e67ec |
992 | } |
993 | |
994 | |
995 | /* |
996 | * Radio Button control |
997 | */ |
998 | |
999 | void dlg_radiobutton_set(union control *ctrl, void *dlg, int whichbutton) |
1000 | { |
93ba25f8 |
1001 | struct macctrls *mcs = dlg; |
1002 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
1003 | int i; |
1004 | |
93ba25f8 |
1005 | assert(mc != NULL); |
8a7e67ec |
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 | { |
93ba25f8 |
1019 | struct macctrls *mcs = dlg; |
1020 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
1021 | int i; |
1022 | |
93ba25f8 |
1023 | assert(mc != NULL); |
8a7e67ec |
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 | { |
93ba25f8 |
1039 | struct macctrls *mcs = dlg; |
1040 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
1041 | |
93ba25f8 |
1042 | assert(mc != NULL); |
8a7e67ec |
1043 | SetControlValue(mc->checkbox.tbctrl, |
1044 | checked ? kControlCheckBoxCheckedValue : |
1045 | kControlCheckBoxUncheckedValue); |
1046 | } |
1047 | |
1048 | int dlg_checkbox_get(union control *ctrl, void *dlg) |
1049 | { |
93ba25f8 |
1050 | struct macctrls *mcs = dlg; |
1051 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
1052 | |
93ba25f8 |
1053 | assert(mc != NULL); |
8a7e67ec |
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 | { |
1f1ec0e5 |
1064 | struct macctrls *mcs = dlg; |
1065 | union macctrl *mc = findbyctrl(mcs, ctrl); |
1066 | GrafPtr saveport; |
8a7e67ec |
1067 | |
1f1ec0e5 |
1068 | assert(mc != NULL); |
1069 | assert(mc->generic.type == MACCTRL_EDITBOX); |
0e9ce565 |
1070 | GetPort(&saveport); |
1071 | SetPort((GrafPtr)(GetWindowPort(mcs->window))); |
d9158b5e |
1072 | if (mac_gestalts.apprvers >= 0x100) |
1f1ec0e5 |
1073 | SetControlData(mc->editbox.tbctrl, kControlEntireControl, |
1074 | ctrl->editbox.password ? |
1075 | kControlEditTextPasswordTag : |
1076 | kControlEditTextTextTag, |
1077 | strlen(text), text); |
d9158b5e |
1078 | else |
0e9ce565 |
1079 | TESetText(text, strlen(text), |
1080 | (TEHandle)(*mc->editbox.tbctrl)->contrlData); |
d9158b5e |
1081 | DrawOneControl(mc->editbox.tbctrl); |
0e9ce565 |
1082 | SetPort(saveport); |
1083 | } |
8a7e67ec |
1084 | |
1085 | void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length) |
1086 | { |
1f1ec0e5 |
1087 | struct macctrls *mcs = dlg; |
1088 | union macctrl *mc = findbyctrl(mcs, ctrl); |
d9158b5e |
1089 | TEHandle te; |
1f1ec0e5 |
1090 | Size olen; |
8a7e67ec |
1091 | |
1f1ec0e5 |
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) |
d9158b5e |
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'; |
1f1ec0e5 |
1111 | fprintf(stderr, "dlg_editbox_get: %s\n", buffer); |
d9158b5e |
1112 | } |
8a7e67ec |
1113 | |
1114 | |
1115 | /* |
1116 | * List Box control |
1117 | */ |
1118 | |
56c01970 |
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"); |
fd703c0a |
1127 | n = CountMenuItems(menu); |
56c01970 |
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; |
fd703c0a |
1133 | SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); |
56c01970 |
1134 | } |
1135 | |
8a7e67ec |
1136 | void dlg_listbox_clear(union control *ctrl, void *dlg) |
1137 | { |
1138 | |
56c01970 |
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)); |
fd703c0a |
1154 | SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); |
56c01970 |
1155 | } |
8a7e67ec |
1156 | |
1157 | void dlg_listbox_del(union control *ctrl, void *dlg, int index) |
1158 | { |
1159 | |
56c01970 |
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"); |
fd703c0a |
1175 | SetMenuItemText(menu, CountMenuItems(menu), itemstring); |
1176 | SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu)); |
56c01970 |
1177 | } |
8a7e67ec |
1178 | |
1179 | void dlg_listbox_add(union control *ctrl, void *dlg, char const *text) |
1180 | { |
1181 | |
56c01970 |
1182 | if (ctrl->listbox.height == 0) |
1183 | dlg_macpopup_add(ctrl, dlg, text); |
1184 | } |
1185 | |
4eaff8d4 |
1186 | static void dlg_macpopup_addwithid(union control *ctrl, void *dlg, |
1187 | char const *text, int id) |
56c01970 |
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); |
fd703c0a |
1196 | index = CountMenuItems(menu) - 1; |
56c01970 |
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 | } |
8a7e67ec |
1204 | |
4eaff8d4 |
1205 | void dlg_listbox_addwithid(union control *ctrl, void *dlg, |
1206 | char const *text, int id) |
8a7e67ec |
1207 | { |
1208 | |
56c01970 |
1209 | if (ctrl->listbox.height == 0) |
4eaff8d4 |
1210 | dlg_macpopup_addwithid(ctrl, dlg, text, id); |
56c01970 |
1211 | } |
8a7e67ec |
1212 | |
1213 | int dlg_listbox_getid(union control *ctrl, void *dlg, int index) |
1214 | { |
56c01970 |
1215 | struct macctrls *mcs = dlg; |
1216 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
1217 | |
56c01970 |
1218 | if (ctrl->listbox.height == 0) { |
1219 | assert(mc->popup.ids != NULL && mc->popup.nids > index); |
1220 | return mc->popup.ids[index]; |
1221 | } |
8a7e67ec |
1222 | return 0; |
56c01970 |
1223 | } |
8a7e67ec |
1224 | |
1225 | int dlg_listbox_index(union control *ctrl, void *dlg) |
1226 | { |
56c01970 |
1227 | struct macctrls *mcs = dlg; |
1228 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
1229 | |
56c01970 |
1230 | if (ctrl->listbox.height == 0) |
1231 | return GetControlValue(mc->popup.tbctrl) - 1; |
8a7e67ec |
1232 | return 0; |
1233 | }; |
1234 | |
1235 | int dlg_listbox_issel(union control *ctrl, void *dlg, int index) |
1236 | { |
56c01970 |
1237 | struct macctrls *mcs = dlg; |
1238 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
1239 | |
56c01970 |
1240 | if (ctrl->listbox.height == 0) |
1241 | return GetControlValue(mc->popup.tbctrl) - 1 == index; |
8a7e67ec |
1242 | return 0; |
1243 | }; |
1244 | |
1245 | void dlg_listbox_select(union control *ctrl, void *dlg, int index) |
1246 | { |
56c01970 |
1247 | struct macctrls *mcs = dlg; |
1248 | union macctrl *mc = findbyctrl(mcs, ctrl); |
8a7e67ec |
1249 | |
56c01970 |
1250 | if (ctrl->listbox.height == 0) |
1251 | SetControlValue(mc->popup.tbctrl, index + 1); |
8a7e67ec |
1252 | }; |
1253 | |
1254 | |
1255 | /* |
1256 | * Text control |
1257 | */ |
1258 | |
1259 | void dlg_text_set(union control *ctrl, void *dlg, char const *text) |
1260 | { |
93ba25f8 |
1261 | struct macctrls *mcs = dlg; |
1262 | union macctrl *mc = findbyctrl(mcs, ctrl); |
f32ce408 |
1263 | Str255 title; |
8a7e67ec |
1264 | |
93ba25f8 |
1265 | assert(mc != NULL); |
8a7e67ec |
1266 | if (mac_gestalts.apprvers >= 0x100) |
1267 | SetControlData(mc->text.tbctrl, kControlEntireControl, |
1f1ec0e5 |
1268 | kControlStaticTextTextTag, strlen(text), text); |
f32ce408 |
1269 | else { |
1270 | c2pstrcpy(title, text); |
1271 | SetControlTitle(mc->text.tbctrl, title); |
1272 | } |
8a7e67ec |
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 | */ |