97cfddb2 |
1 | /* $Id: mac.c,v 1.34 2003/01/20 22:55:08 ben Exp $ */ |
d082ac49 |
2 | /* |
3 | * Copyright (c) 1999 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 | * mac.c -- miscellaneous Mac-specific routines |
29 | */ |
30 | |
31 | #include <MacTypes.h> |
97cfddb2 |
32 | #include <AEDataModel.h> |
33 | #include <AppleEvents.h> |
d082ac49 |
34 | #include <Quickdraw.h> |
35 | #include <Fonts.h> |
36 | #include <MacWindows.h> |
37 | #include <Menus.h> |
38 | #include <TextEdit.h> |
39 | #include <Appearance.h> |
40 | #include <CodeFragments.h> |
41 | #include <Dialogs.h> |
42 | #include <Devices.h> |
43 | #include <DiskInit.h> |
44 | #include <Gestalt.h> |
bf873e8e |
45 | #include <LowMem.h> |
d082ac49 |
46 | #include <Resources.h> |
36577dc9 |
47 | #include <Script.h> |
8768ce31 |
48 | #include <TextCommon.h> |
d082ac49 |
49 | #include <ToolUtils.h> |
8768ce31 |
50 | #include <UnicodeConverter.h> |
d082ac49 |
51 | |
52 | #include <assert.h> |
53 | #include <limits.h> |
54 | #include <stdarg.h> |
55 | #include <stdlib.h> /* putty.h needs size_t */ |
56 | #include <stdio.h> /* for vsprintf */ |
57 | |
58 | #define PUTTY_DO_GLOBALS |
59 | |
60 | #include "macresid.h" |
61 | #include "putty.h" |
0c4b7799 |
62 | #include "ssh.h" |
d082ac49 |
63 | #include "mac.h" |
64 | |
65 | QDGlobals qd; |
66 | |
0c4b7799 |
67 | Session *sesslist; |
68 | |
d082ac49 |
69 | static int cold = 1; |
97cfddb2 |
70 | static int borednow = FALSE; |
d082ac49 |
71 | struct mac_gestalts mac_gestalts; |
72 | |
73 | static void mac_startup(void); |
74 | static void mac_eventloop(void); |
75 | #pragma noreturn (mac_eventloop) |
76 | static void mac_event(EventRecord *); |
77 | static void mac_contentclick(WindowPtr, EventRecord *); |
78 | static void mac_growwindow(WindowPtr, EventRecord *); |
79 | static void mac_activatewindow(WindowPtr, EventRecord *); |
80 | static void mac_activateabout(WindowPtr, EventRecord *); |
81 | static void mac_updatewindow(WindowPtr); |
ebd78b62 |
82 | static void mac_updatelicence(WindowPtr); |
d082ac49 |
83 | static void mac_keypress(EventRecord *); |
84 | static int mac_windowtype(WindowPtr); |
85 | static void mac_menucommand(long); |
86 | static void mac_openabout(void); |
ebd78b62 |
87 | static void mac_openlicence(void); |
d082ac49 |
88 | static void mac_adjustcursor(RgnHandle); |
89 | static void mac_adjustmenus(void); |
90 | static void mac_closewindow(WindowPtr); |
91 | static void mac_zoomwindow(WindowPtr, short); |
0c4b7799 |
92 | #pragma noreturn (cleanup_exit) |
97cfddb2 |
93 | static pascal OSErr mac_aevt_quit(const AppleEvent *, AppleEvent *, long); |
d082ac49 |
94 | |
95 | struct mac_windows { |
96 | WindowPtr about; |
97 | WindowPtr licence; |
98 | }; |
99 | |
100 | struct mac_windows windows; |
101 | |
102 | int main (int argc, char **argv) { |
103 | |
104 | mac_startup(); |
105 | mac_eventloop(); |
106 | } |
107 | |
108 | #pragma noreturn (main) |
109 | |
110 | static void mac_startup(void) { |
111 | Handle menuBar; |
8768ce31 |
112 | TECInfoHandle ti; |
d082ac49 |
113 | |
114 | /* Init Memory Manager */ |
115 | MaxApplZone(); |
116 | /* Init QuickDraw */ |
117 | InitGraf(&qd.thePort); |
118 | /* Init Font Manager */ |
119 | InitFonts(); |
120 | /* Init Window Manager */ |
121 | InitWindows(); |
122 | /* Init Menu Manager */ |
123 | InitMenus(); |
124 | /* Init TextEdit */ |
125 | TEInit(); |
126 | /* Init Dialog Manager */ |
f3ab148c |
127 | InitDialogs(NULL); |
d082ac49 |
128 | cold = 0; |
129 | |
56ed4cf7 |
130 | /* Get base system version (only used if there's no better selector) */ |
131 | if (Gestalt(gestaltSystemVersion, &mac_gestalts.sysvers) != noErr || |
6e1063b1 |
132 | (mac_gestalts.sysvers &= 0xffff) < 0x700) |
56ed4cf7 |
133 | fatalbox("PuTTY requires System 7 or newer"); |
d082ac49 |
134 | /* Find out if we've got Color Quickdraw */ |
135 | if (Gestalt(gestaltQuickdrawVersion, &mac_gestalts.qdvers) != noErr) |
136 | mac_gestalts.qdvers = gestaltOriginalQD; |
137 | /* ... and the Appearance Manager? */ |
138 | if (Gestalt(gestaltAppearanceVersion, &mac_gestalts.apprvers) != noErr) |
139 | if (Gestalt(gestaltAppearanceAttr, NULL) == noErr) |
140 | mac_gestalts.apprvers = 0x0100; |
141 | else |
142 | mac_gestalts.apprvers = 0; |
143 | #if TARGET_RT_MAC_CFM |
144 | /* Paranoia: Did we manage to pull in AppearanceLib? */ |
145 | if (&RegisterAppearanceClient == kUnresolvedCFragSymbolAddress) |
146 | mac_gestalts.apprvers = 0; |
147 | #endif |
1fc898ea |
148 | #if TARGET_CPU_68K |
149 | mac_gestalts.cntlattr = 0; |
150 | mac_gestalts.windattr = 0; |
151 | #else |
d082ac49 |
152 | /* Mac OS 8.5 Control Manager (proportional scrollbars)? */ |
1fc898ea |
153 | if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr || |
154 | &SetControlViewSize == kUnresolvedCFragSymbolAddress) |
d082ac49 |
155 | mac_gestalts.cntlattr = 0; |
156 | /* Mac OS 8.5 Window Manager? */ |
1fc898ea |
157 | if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr || |
158 | &SetWindowContentColor == kUnresolvedCFragSymbolAddress) |
d082ac49 |
159 | mac_gestalts.windattr = 0; |
1fc898ea |
160 | #endif |
8768ce31 |
161 | /* Text Encoding Conversion Manager? */ |
162 | if ( |
163 | #if TARGET_RT_MAC_CFM |
164 | &TECGetInfo == kUnresolvedCFragSymbolAddress || |
165 | #else |
166 | InitializeUnicodeConverter(NULL) != noErr || |
167 | #endif |
168 | TECGetInfo(&ti) != noErr) |
169 | mac_gestalts.encvvers = 0; |
170 | else { |
171 | mac_gestalts.encvvers = (*ti)->tecVersion; |
379836ca |
172 | mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures; |
8768ce31 |
173 | DisposeHandle((Handle)ti); |
174 | } |
97cfddb2 |
175 | |
176 | #if 0 /* OpenTransport? */ |
27a3458f |
177 | if (Gestalt(gestaltOpenTpt, &mac_gestalts.otptattr) != noErr || |
178 | (mac_gestalts.otptattr & gestaltOpenTptTCPPresentMask) == 0 || |
179 | ot_init() != noErr) |
97cfddb2 |
180 | #endif |
27a3458f |
181 | mac_gestalts.otptattr = 0; |
182 | if (mac_gestalts.otptattr == 0) { |
183 | /* MacTCP? */ |
184 | if (Gestalt(FOUR_CHAR_CODE('mtcp'), &mac_gestalts.mtcpvers) != noErr) |
deed9e25 |
185 | mac_gestalts.mtcpvers = 0; |
27a3458f |
186 | if (mac_gestalts.mtcpvers > 0) { |
187 | if (mactcp_init() != noErr) |
188 | mac_gestalts.mtcpvers = 0; |
189 | } |
190 | } else |
191 | mac_gestalts.mtcpvers = 0; |
2beb0fb0 |
192 | |
d082ac49 |
193 | /* We've been tested with the Appearance Manager */ |
194 | if (mac_gestalts.apprvers != 0) |
195 | RegisterAppearanceClient(); |
196 | |
197 | menuBar = GetNewMBar(128); |
198 | if (menuBar == NULL) |
199 | fatalbox("Unable to create menu bar."); |
200 | SetMenuBar(menuBar); |
201 | AppendResMenu(GetMenuHandle(mApple), 'DRVR'); |
202 | mac_adjustmenus(); |
203 | DrawMenuBar(); |
204 | InitCursor(); |
205 | windows.about = NULL; |
206 | windows.licence = NULL; |
207 | |
ffa79828 |
208 | default_protocol = be_default_protocol; |
209 | /* Find the appropriate default port. */ |
210 | { |
ffa79828 |
211 | int i; |
1adaeb2e |
212 | default_port = 0; /* illegal */ |
ffa79828 |
213 | for (i = 0; backends[i].backend != NULL; i++) |
214 | if (backends[i].protocol == default_protocol) { |
215 | default_port = backends[i].backend->default_port; |
216 | break; |
217 | } |
218 | } |
0c4b7799 |
219 | flags = FLAG_INTERACTIVE; |
220 | |
bf873e8e |
221 | { |
222 | short vol; |
223 | long dirid; |
224 | |
225 | /* Set the default directory for loading and saving settings. */ |
226 | /* XXX Should we create it? */ |
227 | if (get_session_dir(FALSE, &vol, &dirid) == noErr) { |
228 | LMSetSFSaveDisk(-vol); |
229 | LMSetCurDirStore(dirid); |
230 | } |
231 | } |
97cfddb2 |
232 | |
233 | /* Install Apple Event handlers. */ |
234 | AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, |
235 | NewAEEventHandlerUPP(&mac_aevt_quit), 0, FALSE); |
d082ac49 |
236 | } |
237 | |
238 | static void mac_eventloop(void) { |
239 | Boolean gotevent; |
240 | EventRecord event; |
241 | RgnHandle cursrgn; |
242 | |
243 | cursrgn = NewRgn(); |
244 | for (;;) { |
245 | mac_adjustcursor(cursrgn); |
246 | gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, cursrgn); |
247 | mac_adjustcursor(cursrgn); |
248 | if (gotevent) |
249 | mac_event(&event); |
97cfddb2 |
250 | if (borednow) |
251 | cleanup_exit(0); |
deed9e25 |
252 | if (mac_gestalts.mtcpvers != 0) |
253 | mactcp_poll(); |
04b0fa02 |
254 | if (mac_gestalts.otptattr != 0) |
255 | ot_poll(); |
0c4b7799 |
256 | mac_pollterm(); |
d082ac49 |
257 | } |
258 | DisposeRgn(cursrgn); |
259 | } |
260 | |
261 | static void mac_event(EventRecord *event) { |
262 | short part; |
263 | WindowPtr window; |
264 | Point pt; |
265 | |
266 | switch (event->what) { |
267 | case mouseDown: |
268 | part = FindWindow(event->where, &window); |
269 | switch (part) { |
270 | case inMenuBar: |
271 | mac_adjustmenus(); |
272 | mac_menucommand(MenuSelect(event->where)); |
273 | break; |
274 | case inSysWindow: |
275 | SystemClick(event, window); |
276 | break; |
277 | case inContent: |
278 | if (window != FrontWindow()) |
279 | /* XXX: check for movable modal dboxes? */ |
280 | SelectWindow(window); |
281 | else |
282 | mac_contentclick(window, event); |
283 | break; |
284 | case inGoAway: |
285 | if (TrackGoAway(window, event->where)) |
286 | mac_closewindow(window); |
287 | break; |
288 | case inDrag: |
289 | /* XXX: moveable modal check? */ |
290 | DragWindow(window, event->where, &qd.screenBits.bounds); |
291 | break; |
292 | case inGrow: |
293 | mac_growwindow(window, event); |
294 | break; |
295 | case inZoomIn: |
296 | case inZoomOut: |
297 | if (TrackBox(window, event->where, part)) |
298 | mac_zoomwindow(window, part); |
299 | break; |
300 | } |
301 | break; |
302 | case keyDown: |
303 | case autoKey: |
304 | mac_keypress(event); |
305 | break; |
306 | case activateEvt: |
307 | mac_activatewindow((WindowPtr)event->message, event); |
308 | break; |
309 | case updateEvt: |
310 | mac_updatewindow((WindowPtr)event->message); |
311 | break; |
312 | case diskEvt: |
313 | if (HiWord(event->message) != noErr) { |
314 | SetPt(&pt, 120, 120); |
315 | DIBadMount(pt, event->message); |
316 | } |
317 | break; |
97cfddb2 |
318 | case kHighLevelEvent: |
319 | AEProcessAppleEvent(event); /* errors? */ |
320 | break; |
d082ac49 |
321 | } |
322 | } |
323 | |
324 | static void mac_contentclick(WindowPtr window, EventRecord *event) { |
325 | short item; |
326 | |
327 | switch (mac_windowtype(window)) { |
328 | case wTerminal: |
329 | mac_clickterm(window, event); |
330 | break; |
331 | case wAbout: |
34e9a202 |
332 | if (DialogSelect(event, &window, &item)) |
d082ac49 |
333 | switch (item) { |
334 | case wiAboutLicence: |
ebd78b62 |
335 | mac_openlicence(); |
d082ac49 |
336 | break; |
337 | } |
338 | break; |
6cb61a05 |
339 | case wSettings: |
340 | mac_clickdlg(window, event); |
341 | break; |
d082ac49 |
342 | } |
343 | } |
344 | |
345 | static void mac_growwindow(WindowPtr window, EventRecord *event) { |
346 | |
347 | switch (mac_windowtype(window)) { |
348 | case wTerminal: |
349 | mac_growterm(window, event); |
350 | } |
351 | } |
352 | |
353 | static void mac_activatewindow(WindowPtr window, EventRecord *event) { |
354 | int active; |
355 | |
356 | active = (event->modifiers & activeFlag) != 0; |
357 | mac_adjustmenus(); |
358 | switch (mac_windowtype(window)) { |
359 | case wTerminal: |
360 | mac_activateterm(window, active); |
361 | break; |
6cb61a05 |
362 | case wSettings: |
363 | mac_activatedlg(window, event); |
364 | break; |
d082ac49 |
365 | case wAbout: |
366 | mac_activateabout(window, event); |
367 | break; |
368 | } |
369 | } |
370 | |
371 | static void mac_activateabout(WindowPtr window, EventRecord *event) { |
372 | DialogItemType itemtype; |
373 | Handle itemhandle; |
374 | short item; |
375 | Rect itemrect; |
376 | int active; |
377 | |
378 | active = (event->modifiers & activeFlag) != 0; |
379 | GetDialogItem(window, wiAboutLicence, &itemtype, &itemhandle, &itemrect); |
380 | HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); |
381 | DialogSelect(event, &window, &item); |
382 | } |
383 | |
384 | static void mac_updatewindow(WindowPtr window) { |
385 | |
386 | switch (mac_windowtype(window)) { |
387 | case wTerminal: |
388 | mac_updateterm(window); |
389 | break; |
390 | case wAbout: |
6cb61a05 |
391 | case wSettings: |
d082ac49 |
392 | BeginUpdate(window); |
393 | UpdateDialog(window, window->visRgn); |
394 | EndUpdate(window); |
395 | break; |
396 | case wLicence: |
ebd78b62 |
397 | mac_updatelicence(window); |
398 | break; |
399 | } |
400 | } |
401 | |
402 | static void mac_updatelicence(WindowPtr window) |
403 | { |
404 | Handle h; |
405 | int len; |
36577dc9 |
406 | long fondsize; |
ebd78b62 |
407 | |
408 | SetPort(window); |
409 | BeginUpdate(window); |
36577dc9 |
410 | fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize); |
411 | TextFont(HiWord(fondsize)); |
412 | TextSize(LoWord(fondsize)); |
ebd78b62 |
413 | h = Get1Resource('TEXT', wLicence); |
414 | len = GetResourceSizeOnDisk(h); |
415 | if (h != NULL) { |
416 | HLock(h); |
417 | TETextBox(*h, len, &window->portRect, teFlushDefault); |
418 | HUnlock(h); |
d082ac49 |
419 | } |
ebd78b62 |
420 | EndUpdate(window); |
d082ac49 |
421 | } |
422 | |
423 | /* |
424 | * Work out what kind of window we're dealing with. |
425 | * Concept shamelessly nicked from SurfWriter. |
426 | */ |
427 | static int mac_windowtype(WindowPtr window) { |
428 | int kind; |
6cb61a05 |
429 | long refcon; |
d082ac49 |
430 | |
431 | if (window == NULL) |
432 | return wNone; |
433 | kind = ((WindowPeek)window)->windowKind; |
434 | if (kind < 0) |
435 | return wDA; |
436 | if (GetWVariant(window) == zoomDocProc) |
437 | return wTerminal; |
6cb61a05 |
438 | refcon = GetWRefCon(window); |
439 | if (refcon < 1024) |
440 | return refcon; |
441 | else |
442 | return wSettings; |
d082ac49 |
443 | } |
444 | |
445 | /* |
446 | * Handle a key press |
447 | */ |
448 | static void mac_keypress(EventRecord *event) { |
449 | WindowPtr window; |
450 | |
451 | window = FrontWindow(); |
452 | /* |
453 | * Check for a command-key combination, but ignore it if it counts |
454 | * as a meta-key combination and we're in a terminal window. |
455 | */ |
456 | if (event->what == keyDown && (event->modifiers & cmdKey) /*&& |
457 | !((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers && |
458 | mac_windowtype(window) == wTerminal)*/) { |
459 | mac_adjustmenus(); |
460 | mac_menucommand(MenuKey(event->message & charCodeMask)); |
461 | } else { |
462 | switch (mac_windowtype(window)) { |
463 | case wTerminal: |
464 | mac_keyterm(window, event); |
465 | break; |
466 | } |
467 | } |
468 | } |
469 | |
470 | static void mac_menucommand(long result) { |
471 | short menu, item; |
472 | Str255 da; |
473 | WindowPtr window; |
474 | |
475 | menu = HiWord(result); |
476 | item = LoWord(result); |
477 | window = FrontWindow(); |
478 | /* Things which do the same whatever window we're in. */ |
479 | switch (menu) { |
480 | case mApple: |
481 | switch (item) { |
482 | case iAbout: |
483 | mac_openabout(); |
484 | goto done; |
485 | default: |
486 | GetMenuItemText(GetMenuHandle(mApple), item, da); |
487 | OpenDeskAcc(da); |
488 | goto done; |
489 | } |
490 | break; |
491 | case mFile: |
492 | switch (item) { |
493 | case iNew: |
494 | mac_newsession(); |
495 | goto done; |
ce283213 |
496 | case iOpen: |
497 | mac_opensession(); |
498 | goto done; |
d082ac49 |
499 | case iClose: |
500 | mac_closewindow(window); |
501 | goto done; |
b537dd42 |
502 | case iSave: |
503 | mac_savesession(); |
504 | goto done; |
505 | case iSaveAs: |
506 | mac_savesessionas(); |
507 | goto done; |
d082ac49 |
508 | case iQuit: |
0c4b7799 |
509 | cleanup_exit(0); |
d082ac49 |
510 | goto done; |
511 | } |
512 | break; |
513 | } |
514 | /* If we get here, handling is up to window-specific code. */ |
515 | switch (mac_windowtype(window)) { |
516 | case wTerminal: |
517 | mac_menuterm(window, menu, item); |
518 | break; |
519 | } |
520 | done: |
521 | HiliteMenu(0); |
522 | } |
523 | |
524 | static void mac_openabout(void) { |
525 | DialogItemType itemtype; |
526 | Handle item; |
527 | VersRecHndl vers; |
528 | Rect box; |
529 | StringPtr longvers; |
530 | |
531 | if (windows.about) |
532 | SelectWindow(windows.about); |
533 | else { |
534 | windows.about = GetNewDialog(wAbout, NULL, (WindowPtr)-1); |
5dbc118e |
535 | vers = (VersRecHndl)Get1Resource('vers', 1); |
536 | if (vers != NULL && *vers != NULL) { |
537 | longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1; |
538 | GetDialogItem(windows.about, wiAboutVersion, |
539 | &itemtype, &item, &box); |
540 | assert(itemtype & kStaticTextDialogItem); |
541 | SetDialogItemText(item, longvers); |
542 | } |
d082ac49 |
543 | ShowWindow(windows.about); |
544 | } |
545 | } |
546 | |
ebd78b62 |
547 | static void mac_openlicence(void) { |
ebd78b62 |
548 | |
549 | if (windows.licence) |
550 | SelectWindow(windows.licence); |
551 | else { |
552 | windows.licence = GetNewWindow(wLicence, NULL, (WindowPtr)-1); |
553 | ShowWindow(windows.licence); |
554 | } |
555 | } |
556 | |
d082ac49 |
557 | static void mac_closewindow(WindowPtr window) { |
558 | |
559 | switch (mac_windowtype(window)) { |
560 | case wDA: |
561 | CloseDeskAcc(((WindowPeek)window)->windowKind); |
562 | break; |
563 | case wTerminal: |
fabd1805 |
564 | mac_closeterm(window); |
d082ac49 |
565 | break; |
566 | case wAbout: |
567 | windows.about = NULL; |
fabd1805 |
568 | DisposeDialog(window); |
d082ac49 |
569 | break; |
ebd78b62 |
570 | case wLicence: |
571 | windows.licence = NULL; |
fabd1805 |
572 | DisposeWindow(window); |
d082ac49 |
573 | break; |
574 | } |
575 | } |
576 | |
577 | static void mac_zoomwindow(WindowPtr window, short part) { |
578 | |
579 | /* FIXME: do something */ |
580 | } |
581 | |
582 | /* |
583 | * Make the menus look right before the user gets to see them. |
584 | */ |
585 | static void mac_adjustmenus(void) { |
586 | WindowPtr window; |
587 | MenuHandle menu; |
588 | |
589 | window = FrontWindow(); |
590 | menu = GetMenuHandle(mApple); |
591 | EnableItem(menu, 0); |
592 | EnableItem(menu, iAbout); |
593 | |
594 | menu = GetMenuHandle(mFile); |
595 | EnableItem(menu, 0); |
596 | EnableItem(menu, iNew); |
597 | if (window != NULL) |
598 | EnableItem(menu, iClose); |
599 | else |
600 | DisableItem(menu, iClose); |
601 | EnableItem(menu, iQuit); |
602 | |
603 | switch (mac_windowtype(window)) { |
b537dd42 |
604 | case wSettings: |
605 | DisableItem(menu, iSave); /* XXX enable if modified */ |
606 | EnableItem(menu, iSaveAs); |
607 | menu = GetMenuHandle(mEdit); |
608 | DisableItem(menu, 0); |
609 | break; |
d082ac49 |
610 | case wTerminal: |
611 | mac_adjusttermmenus(window); |
612 | break; |
613 | default: |
b537dd42 |
614 | DisableItem(menu, iSave); |
615 | DisableItem(menu, iSaveAs); |
d082ac49 |
616 | menu = GetMenuHandle(mEdit); |
617 | DisableItem(menu, 0); |
618 | break; |
619 | } |
620 | DrawMenuBar(); |
621 | } |
622 | |
623 | /* |
624 | * Make sure the right cursor's being displayed. |
625 | */ |
626 | static void mac_adjustcursor(RgnHandle cursrgn) { |
627 | Point mouse; |
628 | WindowPtr window, front; |
629 | short part; |
630 | |
631 | GetMouse(&mouse); |
632 | LocalToGlobal(&mouse); |
633 | part = FindWindow(mouse, &window); |
634 | front = FrontWindow(); |
635 | if (part != inContent || window == NULL || window != front) { |
636 | /* Cursor isn't in the front window, so switch to arrow */ |
637 | SetCursor(&qd.arrow); |
638 | SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); |
639 | if (front != NULL) |
640 | DiffRgn(cursrgn, front->visRgn, cursrgn); |
641 | } else { |
642 | switch (mac_windowtype(window)) { |
643 | case wTerminal: |
644 | mac_adjusttermcursor(window, mouse, cursrgn); |
645 | break; |
646 | default: |
647 | SetCursor(&qd.arrow); |
648 | CopyRgn(window->visRgn, cursrgn); |
649 | break; |
650 | } |
651 | } |
652 | } |
653 | |
97cfddb2 |
654 | static pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply, |
655 | long refcon) |
656 | { |
657 | |
658 | borednow = 1; |
659 | return noErr; |
660 | } |
661 | |
0c4b7799 |
662 | void cleanup_exit(int status) |
663 | { |
d082ac49 |
664 | |
713b8b7a |
665 | #if !TARGET_RT_MAC_CFM |
8768ce31 |
666 | if (mac_gestalts.encvvers != 0) |
667 | TerminateUnicodeConverter(); |
713b8b7a |
668 | #endif |
27a3458f |
669 | sk_cleanup(); |
0c4b7799 |
670 | exit(status); |
d082ac49 |
671 | } |
672 | |
673 | void fatalbox(char *fmt, ...) { |
674 | va_list ap; |
675 | Str255 stuff; |
676 | |
677 | va_start(ap, fmt); |
678 | /* We'd like stuff to be a Pascal string */ |
679 | stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); |
680 | va_end(ap); |
681 | ParamText(stuff, NULL, NULL, NULL); |
f3ab148c |
682 | StopAlert(128, NULL); |
04b0fa02 |
683 | cleanup_exit(1); |
d082ac49 |
684 | } |
685 | |
686 | void modalfatalbox(char *fmt, ...) { |
687 | va_list ap; |
688 | Str255 stuff; |
689 | |
690 | va_start(ap, fmt); |
691 | /* We'd like stuff to be a Pascal string */ |
692 | stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); |
693 | va_end(ap); |
694 | ParamText(stuff, NULL, NULL, NULL); |
f3ab148c |
695 | StopAlert(128, NULL); |
04b0fa02 |
696 | cleanup_exit(1); |
d082ac49 |
697 | } |
698 | |
2beb0fb0 |
699 | /* This should only kill the current session, not the whole application. */ |
700 | void connection_fatal(void *fontend, char *fmt, ...) { |
701 | va_list ap; |
702 | Str255 stuff; |
703 | |
704 | va_start(ap, fmt); |
705 | /* We'd like stuff to be a Pascal string */ |
706 | stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); |
707 | va_end(ap); |
708 | ParamText(stuff, NULL, NULL, NULL); |
709 | StopAlert(128, NULL); |
04b0fa02 |
710 | cleanup_exit(1); |
2beb0fb0 |
711 | } |
712 | |
0c4b7799 |
713 | /* Null SSH agent client -- never finds an agent. */ |
714 | |
715 | int agent_exists(void) |
716 | { |
717 | |
718 | return FALSE; |
719 | } |
720 | |
721 | void agent_query(void *in, int inlen, void **out, int *outlen) |
722 | { |
723 | |
724 | *out = NULL; |
725 | *outlen = 0; |
726 | } |
727 | |
728 | /* Temporary null routines for testing. */ |
729 | |
730 | void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, |
731 | char *keystr, char *fingerprint) |
732 | { |
733 | |
734 | } |
735 | |
736 | void askcipher(void *frontend, char *ciphername, int cs) |
737 | { |
738 | |
739 | } |
740 | |
741 | void old_keyfile_warning(void) |
742 | { |
743 | |
744 | } |
745 | |
f5d2d791 |
746 | char *platform_default_s(char const *name) |
5a9eb105 |
747 | { |
a499fbf9 |
748 | long smfs; |
749 | Str255 pname; |
750 | static char cname[256]; |
751 | |
752 | if (!strcmp(name, "Font")) { |
753 | smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize); |
754 | if (smfs == 0) |
755 | smfs = GetScriptVariable(smRoman, smScriptMonoFondSize); |
756 | if (smfs != 0) { |
757 | GetFontName(HiWord(smfs), pname); |
758 | if (pname[0] == 0) |
759 | return "Monaco"; |
760 | p2cstrcpy(cname, pname); |
761 | return cname; |
762 | } else |
763 | return "Monaco"; |
764 | } |
5a9eb105 |
765 | return NULL; |
766 | } |
767 | |
f5d2d791 |
768 | int platform_default_i(char const *name, int def) |
5a9eb105 |
769 | { |
a499fbf9 |
770 | long smfs; |
771 | |
772 | if (!strcmp(name, "FontHeight")) { |
773 | smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize); |
774 | if (smfs == 0) |
775 | smfs = GetScriptVariable(smRoman, smScriptMonoFondSize); |
776 | if (smfs != 0) |
777 | return LoWord(smfs); |
778 | else |
779 | return 9; |
780 | } |
781 | |
5a9eb105 |
782 | /* Non-raw cut and paste of line-drawing chars works badly on the |
783 | * current Unix stub implementation of the Unicode functions. |
784 | * So I'm going to temporarily set the default to raw mode so |
785 | * that the failure mode isn't quite so drastically horrid. |
786 | * When Unicode comes in, this can all be put right. */ |
787 | if (!strcmp(name, "RawCNP")) |
788 | return 1; |
789 | return def; |
790 | } |
791 | |
e0e7dff8 |
792 | void platform_get_x11_auth(char *display, int *proto, |
793 | unsigned char *data, int *datalen) |
794 | { |
795 | /* SGT: I have no idea whether Mac X servers need anything here. */ |
796 | } |
797 | |
d082ac49 |
798 | /* |
799 | * Local Variables: |
800 | * c-file-style: "simon" |
801 | * End: |
802 | */ |