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