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