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