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