83e7d008 |
1 | /* $Id$ */ |
d082ac49 |
2 | /* |
f854b482 |
3 | * Copyright (c) 1999, 2003 Ben Harris |
d082ac49 |
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> |
1f1ec0e5 |
34 | #include <Controls.h> |
d082ac49 |
35 | #include <Quickdraw.h> |
36 | #include <Fonts.h> |
37 | #include <MacWindows.h> |
38 | #include <Menus.h> |
39 | #include <TextEdit.h> |
40 | #include <Appearance.h> |
41 | #include <CodeFragments.h> |
42 | #include <Dialogs.h> |
43 | #include <Devices.h> |
44 | #include <DiskInit.h> |
45 | #include <Gestalt.h> |
bf873e8e |
46 | #include <LowMem.h> |
9ef3c1ca |
47 | #include <Navigation.h> |
d082ac49 |
48 | #include <Resources.h> |
36577dc9 |
49 | #include <Script.h> |
8768ce31 |
50 | #include <TextCommon.h> |
d082ac49 |
51 | #include <ToolUtils.h> |
8768ce31 |
52 | #include <UnicodeConverter.h> |
d082ac49 |
53 | |
54 | #include <assert.h> |
55 | #include <limits.h> |
56 | #include <stdarg.h> |
57 | #include <stdlib.h> /* putty.h needs size_t */ |
58 | #include <stdio.h> /* for vsprintf */ |
59 | |
60 | #define PUTTY_DO_GLOBALS |
61 | |
62 | #include "macresid.h" |
63 | #include "putty.h" |
0c4b7799 |
64 | #include "ssh.h" |
538bfd1d |
65 | #include "terminal.h" |
d082ac49 |
66 | #include "mac.h" |
67 | |
0c4b7799 |
68 | Session *sesslist; |
69 | |
d082ac49 |
70 | static int cold = 1; |
97cfddb2 |
71 | static int borednow = FALSE; |
d082ac49 |
72 | struct mac_gestalts mac_gestalts; |
0ec4b50f |
73 | UInt32 sleeptime; |
b483d9ac |
74 | static long timing_next_time; |
d082ac49 |
75 | |
76 | static void mac_startup(void); |
77 | static void mac_eventloop(void); |
78 | #pragma noreturn (mac_eventloop) |
79 | static void mac_event(EventRecord *); |
80 | static void mac_contentclick(WindowPtr, EventRecord *); |
81 | static void mac_growwindow(WindowPtr, EventRecord *); |
82 | static void mac_activatewindow(WindowPtr, EventRecord *); |
0c5c7f5c |
83 | static void mac_suspendresume(EventRecord *); |
d082ac49 |
84 | static void mac_activateabout(WindowPtr, EventRecord *); |
85 | static void mac_updatewindow(WindowPtr); |
ebd78b62 |
86 | static void mac_updatelicence(WindowPtr); |
d082ac49 |
87 | static void mac_keypress(EventRecord *); |
88 | static int mac_windowtype(WindowPtr); |
89 | static void mac_menucommand(long); |
ebd78b62 |
90 | static void mac_openlicence(void); |
d082ac49 |
91 | static void mac_adjustcursor(RgnHandle); |
92 | static void mac_adjustmenus(void); |
93 | static void mac_closewindow(WindowPtr); |
94 | static void mac_zoomwindow(WindowPtr, short); |
0c4b7799 |
95 | #pragma noreturn (cleanup_exit) |
d082ac49 |
96 | |
97 | struct mac_windows { |
98 | WindowPtr about; |
99 | WindowPtr licence; |
100 | }; |
101 | |
102 | struct mac_windows windows; |
103 | |
104 | int main (int argc, char **argv) { |
105 | |
106 | mac_startup(); |
107 | mac_eventloop(); |
108 | } |
109 | |
110 | #pragma noreturn (main) |
111 | |
112 | static void mac_startup(void) { |
113 | Handle menuBar; |
8768ce31 |
114 | TECInfoHandle ti; |
d082ac49 |
115 | |
fc34fbaf |
116 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
117 | /* Init Memory Manager */ |
118 | MaxApplZone(); |
119 | /* Init QuickDraw */ |
120 | InitGraf(&qd.thePort); |
121 | /* Init Font Manager */ |
122 | InitFonts(); |
123 | /* Init Window Manager */ |
124 | InitWindows(); |
125 | /* Init Menu Manager */ |
126 | InitMenus(); |
127 | /* Init TextEdit */ |
128 | TEInit(); |
129 | /* Init Dialog Manager */ |
f3ab148c |
130 | InitDialogs(NULL); |
fc34fbaf |
131 | #endif |
d082ac49 |
132 | cold = 0; |
133 | |
56ed4cf7 |
134 | /* Get base system version (only used if there's no better selector) */ |
135 | if (Gestalt(gestaltSystemVersion, &mac_gestalts.sysvers) != noErr || |
6e1063b1 |
136 | (mac_gestalts.sysvers &= 0xffff) < 0x700) |
56ed4cf7 |
137 | fatalbox("PuTTY requires System 7 or newer"); |
d082ac49 |
138 | /* Find out if we've got Color Quickdraw */ |
139 | if (Gestalt(gestaltQuickdrawVersion, &mac_gestalts.qdvers) != noErr) |
140 | mac_gestalts.qdvers = gestaltOriginalQD; |
141 | /* ... and the Appearance Manager? */ |
142 | if (Gestalt(gestaltAppearanceVersion, &mac_gestalts.apprvers) != noErr) |
143 | if (Gestalt(gestaltAppearanceAttr, NULL) == noErr) |
144 | mac_gestalts.apprvers = 0x0100; |
145 | else |
146 | mac_gestalts.apprvers = 0; |
147 | #if TARGET_RT_MAC_CFM |
148 | /* Paranoia: Did we manage to pull in AppearanceLib? */ |
149 | if (&RegisterAppearanceClient == kUnresolvedCFragSymbolAddress) |
150 | mac_gestalts.apprvers = 0; |
151 | #endif |
1fc898ea |
152 | #if TARGET_CPU_68K |
153 | mac_gestalts.cntlattr = 0; |
154 | mac_gestalts.windattr = 0; |
155 | #else |
d082ac49 |
156 | /* Mac OS 8.5 Control Manager (proportional scrollbars)? */ |
1fc898ea |
157 | if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr || |
158 | &SetControlViewSize == kUnresolvedCFragSymbolAddress) |
d082ac49 |
159 | mac_gestalts.cntlattr = 0; |
160 | /* Mac OS 8.5 Window Manager? */ |
1fc898ea |
161 | if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr || |
162 | &SetWindowContentColor == kUnresolvedCFragSymbolAddress) |
d082ac49 |
163 | mac_gestalts.windattr = 0; |
d49b7117 |
164 | /* Mac OS 8.5 Menu Manager? */ |
165 | if (Gestalt(gestaltMenuMgrAttr, &mac_gestalts.menuattr) != noErr) |
166 | mac_gestalts.menuattr = 0; |
1fc898ea |
167 | #endif |
8768ce31 |
168 | /* Text Encoding Conversion Manager? */ |
169 | if ( |
170 | #if TARGET_RT_MAC_CFM |
171 | &TECGetInfo == kUnresolvedCFragSymbolAddress || |
172 | #else |
173 | InitializeUnicodeConverter(NULL) != noErr || |
174 | #endif |
175 | TECGetInfo(&ti) != noErr) |
176 | mac_gestalts.encvvers = 0; |
177 | else { |
178 | mac_gestalts.encvvers = (*ti)->tecVersion; |
379836ca |
179 | mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures; |
8768ce31 |
180 | DisposeHandle((Handle)ti); |
181 | } |
9ef3c1ca |
182 | /* Navigation Services? */ |
183 | if (NavServicesAvailable()) |
184 | mac_gestalts.navsvers = NavLibraryVersion(); |
185 | else |
186 | mac_gestalts.navsvers = 0; |
97cfddb2 |
187 | |
f6fc0010 |
188 | sk_init(); |
2beb0fb0 |
189 | |
d082ac49 |
190 | /* We've been tested with the Appearance Manager */ |
191 | if (mac_gestalts.apprvers != 0) |
192 | RegisterAppearanceClient(); |
193 | |
194 | menuBar = GetNewMBar(128); |
195 | if (menuBar == NULL) |
196 | fatalbox("Unable to create menu bar."); |
197 | SetMenuBar(menuBar); |
198 | AppendResMenu(GetMenuHandle(mApple), 'DRVR'); |
b24ecb46 |
199 | if (mac_gestalts.menuattr & gestaltMenuMgrAquaLayoutMask) { |
d49b7117 |
200 | DeleteMenuItem(GetMenuHandle(mFile), iQuit); |
b24ecb46 |
201 | /* Also delete the separator above the Quit item. */ |
202 | DeleteMenuItem(GetMenuHandle(mFile), iQuit - 1); |
203 | } |
d082ac49 |
204 | mac_adjustmenus(); |
205 | DrawMenuBar(); |
206 | InitCursor(); |
207 | windows.about = NULL; |
208 | windows.licence = NULL; |
209 | |
ffa79828 |
210 | default_protocol = be_default_protocol; |
211 | /* Find the appropriate default port. */ |
212 | { |
9e164d82 |
213 | Backend *b = backend_from_proto(default_protocol); |
1adaeb2e |
214 | default_port = 0; /* illegal */ |
9e164d82 |
215 | if (b) |
216 | default_port = b->default_port; |
ffa79828 |
217 | } |
0c4b7799 |
218 | flags = FLAG_INTERACTIVE; |
219 | |
fc34fbaf |
220 | #if !TARGET_API_MAC_CARBON |
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 | } |
fc34fbaf |
232 | #endif |
97cfddb2 |
233 | |
234 | /* Install Apple Event handlers. */ |
d70e3b83 |
235 | AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, |
236 | NewAEEventHandlerUPP(&mac_aevt_oapp), 0, FALSE); |
237 | AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, |
238 | NewAEEventHandlerUPP(&mac_aevt_odoc), 0, FALSE); |
239 | AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, |
240 | NewAEEventHandlerUPP(&mac_aevt_pdoc), 0, FALSE); |
97cfddb2 |
241 | AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, |
242 | NewAEEventHandlerUPP(&mac_aevt_quit), 0, FALSE); |
d082ac49 |
243 | } |
244 | |
b483d9ac |
245 | void timer_change_notify(long next) |
246 | { |
247 | timing_next_time = next; |
248 | } |
249 | |
d082ac49 |
250 | static void mac_eventloop(void) { |
251 | Boolean gotevent; |
252 | EventRecord event; |
253 | RgnHandle cursrgn; |
b483d9ac |
254 | long next; |
255 | long ticksleft; |
d082ac49 |
256 | |
257 | cursrgn = NewRgn(); |
0ec4b50f |
258 | sleeptime = 0; |
d082ac49 |
259 | for (;;) { |
b483d9ac |
260 | ticksleft=timing_next_time-GETTICKCOUNT(); |
261 | if (sleeptime > ticksleft && ticksleft >=0) |
262 | sleeptime=ticksleft; |
0ec4b50f |
263 | gotevent = WaitNextEvent(everyEvent, &event, sleeptime, cursrgn); |
b483d9ac |
264 | if (timing_next_time <= GETTICKCOUNT()) { |
265 | if (run_timers(timing_next_time, &next)) { |
266 | timer_change_notify(next); |
267 | } |
268 | } |
269 | |
0ec4b50f |
270 | /* |
271 | * XXX For now, limit sleep time to 1/10 s to work around |
272 | * wake-before-sleep race in MacTCP code. |
273 | */ |
274 | sleeptime = 6; |
d082ac49 |
275 | mac_adjustcursor(cursrgn); |
0ec4b50f |
276 | if (gotevent) { |
277 | /* Ensure we get a null event when the real ones run out. */ |
278 | sleeptime = 0; |
d082ac49 |
279 | mac_event(&event); |
0ec4b50f |
280 | if (borednow) |
281 | cleanup_exit(0); |
282 | } |
0ec4b50f |
283 | if (!gotevent) |
c399fc7d |
284 | sk_poll(); |
1f1ec0e5 |
285 | if (mac_gestalts.apprvers >= 0x100 && mac_frontwindow() != NULL) |
286 | IdleControls(mac_frontwindow()); |
d082ac49 |
287 | } |
288 | DisposeRgn(cursrgn); |
289 | } |
290 | |
291 | static void mac_event(EventRecord *event) { |
292 | short part; |
293 | WindowPtr window; |
d082ac49 |
294 | |
295 | switch (event->what) { |
296 | case mouseDown: |
297 | part = FindWindow(event->where, &window); |
298 | switch (part) { |
299 | case inMenuBar: |
300 | mac_adjustmenus(); |
301 | mac_menucommand(MenuSelect(event->where)); |
302 | break; |
fc34fbaf |
303 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
304 | case inSysWindow: |
305 | SystemClick(event, window); |
306 | break; |
fc34fbaf |
307 | #endif |
d082ac49 |
308 | case inContent: |
309 | if (window != FrontWindow()) |
310 | /* XXX: check for movable modal dboxes? */ |
311 | SelectWindow(window); |
312 | else |
313 | mac_contentclick(window, event); |
314 | break; |
315 | case inGoAway: |
316 | if (TrackGoAway(window, event->where)) |
317 | mac_closewindow(window); |
318 | break; |
319 | case inDrag: |
320 | /* XXX: moveable modal check? */ |
fc34fbaf |
321 | #if TARGET_API_MAC_CARBON |
322 | { |
323 | BitMap screenBits; |
324 | |
325 | GetQDGlobalsScreenBits(&screenBits); |
326 | DragWindow(window, event->where, &screenBits.bounds); |
327 | } |
328 | #else |
d082ac49 |
329 | DragWindow(window, event->where, &qd.screenBits.bounds); |
fc34fbaf |
330 | #endif |
d082ac49 |
331 | break; |
332 | case inGrow: |
333 | mac_growwindow(window, event); |
334 | break; |
335 | case inZoomIn: |
336 | case inZoomOut: |
337 | if (TrackBox(window, event->where, part)) |
338 | mac_zoomwindow(window, part); |
339 | break; |
340 | } |
341 | break; |
342 | case keyDown: |
343 | case autoKey: |
344 | mac_keypress(event); |
345 | break; |
346 | case activateEvt: |
347 | mac_activatewindow((WindowPtr)event->message, event); |
348 | break; |
349 | case updateEvt: |
350 | mac_updatewindow((WindowPtr)event->message); |
351 | break; |
fc34fbaf |
352 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
353 | case diskEvt: |
354 | if (HiWord(event->message) != noErr) { |
fc34fbaf |
355 | Point pt; |
356 | |
d082ac49 |
357 | SetPt(&pt, 120, 120); |
358 | DIBadMount(pt, event->message); |
359 | } |
360 | break; |
fc34fbaf |
361 | #endif |
0c5c7f5c |
362 | case osEvt: |
363 | switch ((event->message & osEvtMessageMask) >> 24) { |
364 | case suspendResumeMessage: |
365 | mac_suspendresume(event); |
366 | break; |
367 | } |
368 | break; |
97cfddb2 |
369 | case kHighLevelEvent: |
370 | AEProcessAppleEvent(event); /* errors? */ |
371 | break; |
d082ac49 |
372 | } |
373 | } |
374 | |
f854b482 |
375 | static void mac_contentclick(WindowPtr window, EventRecord *event) |
376 | { |
d082ac49 |
377 | |
f854b482 |
378 | if (mac_wininfo(window)->click != NULL) |
379 | (*mac_wininfo(window)->click)(window, event); |
d082ac49 |
380 | } |
381 | |
f854b482 |
382 | static void mac_growwindow(WindowPtr window, EventRecord *event) |
383 | { |
d082ac49 |
384 | |
f854b482 |
385 | if (mac_wininfo(window)->grow != NULL) |
386 | (*mac_wininfo(window)->grow)(window, event); |
d082ac49 |
387 | } |
388 | |
f854b482 |
389 | static void mac_activatewindow(WindowPtr window, EventRecord *event) |
390 | { |
d082ac49 |
391 | |
d082ac49 |
392 | mac_adjustmenus(); |
f854b482 |
393 | if (mac_wininfo(window)->activate != NULL) |
394 | (*mac_wininfo(window)->activate)(window, event); |
d082ac49 |
395 | } |
396 | |
fc34fbaf |
397 | static void mac_updatewindow(WindowPtr window) |
398 | { |
d082ac49 |
399 | |
f854b482 |
400 | if (mac_wininfo(window)->update != NULL) |
401 | (*mac_wininfo(window)->update)(window); |
d082ac49 |
402 | } |
403 | |
404 | /* |
405 | * Work out what kind of window we're dealing with. |
d082ac49 |
406 | */ |
347bfcd7 |
407 | static int mac_windowtype(WindowPtr window) |
408 | { |
409 | |
410 | #if !TARGET_API_MAC_CARBON |
411 | if (GetWindowKind(window) < 0) |
d082ac49 |
412 | return wDA; |
347bfcd7 |
413 | #endif |
414 | return ((WinInfo *)GetWRefCon(window))->wtype; |
d082ac49 |
415 | } |
416 | |
417 | /* |
418 | * Handle a key press |
419 | */ |
420 | static void mac_keypress(EventRecord *event) { |
421 | WindowPtr window; |
422 | |
3fa61577 |
423 | window = mac_frontwindow(); |
d082ac49 |
424 | /* |
425 | * Check for a command-key combination, but ignore it if it counts |
426 | * as a meta-key combination and we're in a terminal window. |
427 | */ |
428 | if (event->what == keyDown && (event->modifiers & cmdKey) /*&& |
429 | !((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers && |
430 | mac_windowtype(window) == wTerminal)*/) { |
431 | mac_adjustmenus(); |
432 | mac_menucommand(MenuKey(event->message & charCodeMask)); |
433 | } else { |
3fa61577 |
434 | if (window != NULL && mac_wininfo(window)->key != NULL) |
f854b482 |
435 | (*mac_wininfo(window)->key)(window, event); |
d082ac49 |
436 | } |
437 | } |
438 | |
439 | static void mac_menucommand(long result) { |
440 | short menu, item; |
d082ac49 |
441 | WindowPtr window; |
fc34fbaf |
442 | #if !TARGET_API_MAC_CARBON |
443 | Str255 da; |
444 | #endif |
d082ac49 |
445 | |
446 | menu = HiWord(result); |
447 | item = LoWord(result); |
3fa61577 |
448 | window = mac_frontwindow(); |
d082ac49 |
449 | /* Things which do the same whatever window we're in. */ |
450 | switch (menu) { |
451 | case mApple: |
452 | switch (item) { |
453 | case iAbout: |
454 | mac_openabout(); |
455 | goto done; |
cc2be455 |
456 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
457 | default: |
458 | GetMenuItemText(GetMenuHandle(mApple), item, da); |
459 | OpenDeskAcc(da); |
460 | goto done; |
cc2be455 |
461 | #endif |
d082ac49 |
462 | } |
463 | break; |
464 | case mFile: |
465 | switch (item) { |
466 | case iNew: |
467 | mac_newsession(); |
468 | goto done; |
ce283213 |
469 | case iOpen: |
470 | mac_opensession(); |
471 | goto done; |
71581f96 |
472 | case iChange: |
473 | mac_reconfig(); |
474 | goto done; |
d082ac49 |
475 | case iClose: |
476 | mac_closewindow(window); |
477 | goto done; |
b537dd42 |
478 | case iSave: |
479 | mac_savesession(); |
480 | goto done; |
481 | case iSaveAs: |
482 | mac_savesessionas(); |
483 | goto done; |
5211281f |
484 | case iDuplicate: |
485 | mac_dupsession(); |
486 | goto done; |
d082ac49 |
487 | case iQuit: |
0c4b7799 |
488 | cleanup_exit(0); |
d082ac49 |
489 | goto done; |
490 | } |
491 | break; |
492 | } |
493 | /* If we get here, handling is up to window-specific code. */ |
3fa61577 |
494 | if (window != NULL && mac_wininfo(window)->menu != NULL) |
f854b482 |
495 | (*mac_wininfo(window)->menu)(window, menu, item); |
496 | |
d082ac49 |
497 | done: |
498 | HiliteMenu(0); |
499 | } |
500 | |
d082ac49 |
501 | static void mac_closewindow(WindowPtr window) { |
502 | |
503 | switch (mac_windowtype(window)) { |
fc34fbaf |
504 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
505 | case wDA: |
347bfcd7 |
506 | CloseDeskAcc(GetWindowKind(window)); |
d082ac49 |
507 | break; |
fc34fbaf |
508 | #endif |
f854b482 |
509 | default: |
510 | if (mac_wininfo(window)->close != NULL) |
511 | (*mac_wininfo(window)->close)(window); |
d082ac49 |
512 | break; |
513 | } |
514 | } |
515 | |
0c5c7f5c |
516 | static void mac_suspendresume(EventRecord *event) |
517 | { |
518 | WindowPtr front; |
519 | EventRecord fakeevent; |
520 | |
521 | /* |
522 | * We're called either before we're suspended or after we're |
523 | * resumed, so we're the front application at this point. |
524 | */ |
525 | front = FrontWindow(); |
526 | if (front != NULL) { |
527 | fakeevent.what = activateEvt; |
528 | fakeevent.message = (UInt32)front; |
529 | fakeevent.when = event->when; |
530 | fakeevent.where = event->where; |
531 | fakeevent.modifiers = |
532 | (event->message & resumeFlag) ? activeFlag : 0; |
533 | mac_activatewindow(front, &fakeevent); |
534 | } |
535 | } |
536 | |
d082ac49 |
537 | static void mac_zoomwindow(WindowPtr window, short part) { |
538 | |
539 | /* FIXME: do something */ |
540 | } |
541 | |
542 | /* |
543 | * Make the menus look right before the user gets to see them. |
544 | */ |
fc34fbaf |
545 | #if TARGET_API_MAC_CARBON |
fc34fbaf |
546 | #define EnableItem EnableMenuItem |
547 | #define DisableItem DisableMenuItem |
548 | #endif |
d082ac49 |
549 | static void mac_adjustmenus(void) { |
550 | WindowPtr window; |
551 | MenuHandle menu; |
552 | |
3fa61577 |
553 | window = mac_frontwindow(); |
d082ac49 |
554 | menu = GetMenuHandle(mApple); |
555 | EnableItem(menu, 0); |
556 | EnableItem(menu, iAbout); |
557 | |
558 | menu = GetMenuHandle(mFile); |
559 | EnableItem(menu, 0); |
560 | EnableItem(menu, iNew); |
561 | if (window != NULL) |
562 | EnableItem(menu, iClose); |
563 | else |
564 | DisableItem(menu, iClose); |
565 | EnableItem(menu, iQuit); |
566 | |
3fa61577 |
567 | if (window != NULL && mac_wininfo(window)->adjustmenus != NULL) |
f854b482 |
568 | (*mac_wininfo(window)->adjustmenus)(window); |
569 | else { |
71581f96 |
570 | DisableItem(menu, iChange); |
b537dd42 |
571 | DisableItem(menu, iSave); |
572 | DisableItem(menu, iSaveAs); |
5211281f |
573 | DisableItem(menu, iDuplicate); |
d082ac49 |
574 | menu = GetMenuHandle(mEdit); |
575 | DisableItem(menu, 0); |
7dcd1f87 |
576 | menu = GetMenuHandle(mWindow); |
577 | DisableItem(menu, 0); /* Until we get more than 1 item on it. */ |
d082ac49 |
578 | } |
579 | DrawMenuBar(); |
580 | } |
581 | |
582 | /* |
583 | * Make sure the right cursor's being displayed. |
584 | */ |
585 | static void mac_adjustcursor(RgnHandle cursrgn) { |
586 | Point mouse; |
587 | WindowPtr window, front; |
588 | short part; |
fc34fbaf |
589 | #if TARGET_API_MAC_CARBON |
590 | Cursor arrow; |
591 | RgnHandle visrgn; |
592 | #endif |
d082ac49 |
593 | |
594 | GetMouse(&mouse); |
595 | LocalToGlobal(&mouse); |
596 | part = FindWindow(mouse, &window); |
597 | front = FrontWindow(); |
598 | if (part != inContent || window == NULL || window != front) { |
599 | /* Cursor isn't in the front window, so switch to arrow */ |
fc34fbaf |
600 | #if TARGET_API_MAC_CARBON |
601 | GetQDGlobalsArrow(&arrow); |
602 | SetCursor(&arrow); |
603 | #else |
d082ac49 |
604 | SetCursor(&qd.arrow); |
fc34fbaf |
605 | #endif |
d082ac49 |
606 | SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); |
fc34fbaf |
607 | if (front != NULL) { |
608 | #if TARGET_API_MAC_CARBON |
609 | visrgn = NewRgn(); |
610 | GetPortVisibleRegion(GetWindowPort(front), visrgn); |
611 | DiffRgn(cursrgn, visrgn, cursrgn); |
612 | DisposeRgn(visrgn); |
613 | #else |
d082ac49 |
614 | DiffRgn(cursrgn, front->visRgn, cursrgn); |
fc34fbaf |
615 | #endif |
616 | } |
d082ac49 |
617 | } else { |
f854b482 |
618 | if (mac_wininfo(window)->adjustcursor != NULL) |
619 | (*mac_wininfo(window)->adjustcursor)(window, mouse, cursrgn); |
620 | else { |
fc34fbaf |
621 | #if TARGET_API_MAC_CARBON |
622 | GetQDGlobalsArrow(&arrow); |
623 | SetCursor(&arrow); |
624 | GetPortVisibleRegion(GetWindowPort(window), cursrgn); |
625 | #else |
d082ac49 |
626 | SetCursor(&qd.arrow); |
627 | CopyRgn(window->visRgn, cursrgn); |
fc34fbaf |
628 | #endif |
d082ac49 |
629 | } |
630 | } |
631 | } |
632 | |
d70e3b83 |
633 | pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply, |
97cfddb2 |
634 | long refcon) |
635 | { |
d70e3b83 |
636 | DescType type; |
637 | Size size; |
638 | |
639 | if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, |
640 | &type, NULL, 0, &size) == noErr) |
641 | return errAEParamMissed; |
97cfddb2 |
642 | |
643 | borednow = 1; |
644 | return noErr; |
645 | } |
646 | |
0c4b7799 |
647 | void cleanup_exit(int status) |
648 | { |
d082ac49 |
649 | |
713b8b7a |
650 | #if !TARGET_RT_MAC_CFM |
8768ce31 |
651 | if (mac_gestalts.encvvers != 0) |
652 | TerminateUnicodeConverter(); |
713b8b7a |
653 | #endif |
27a3458f |
654 | sk_cleanup(); |
0c4b7799 |
655 | exit(status); |
d082ac49 |
656 | } |
657 | |
2beb0fb0 |
658 | /* This should only kill the current session, not the whole application. */ |
8154b602 |
659 | void connection_fatal(void *frontend, char *fmt, ...) { |
2beb0fb0 |
660 | va_list ap; |
661 | Str255 stuff; |
8154b602 |
662 | Session *s = frontend; |
2beb0fb0 |
663 | |
664 | va_start(ap, fmt); |
665 | /* We'd like stuff to be a Pascal string */ |
666 | stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); |
667 | va_end(ap); |
668 | ParamText(stuff, NULL, NULL, NULL); |
669 | StopAlert(128, NULL); |
8154b602 |
670 | |
671 | s->session_closed = TRUE; |
672 | |
673 | if (s->cfg.close_on_exit == FORCE_ON) |
674 | mac_closewindow(s->window); |
2beb0fb0 |
675 | } |
676 | |
0c4b7799 |
677 | /* Null SSH agent client -- never finds an agent. */ |
678 | |
679 | int agent_exists(void) |
680 | { |
681 | |
682 | return FALSE; |
683 | } |
684 | |
12bff6dc |
685 | int agent_query(void *in, int inlen, void **out, int *outlen, |
686 | void (*callback)(void *, void *, int), void *callback_ctx) |
0c4b7799 |
687 | { |
688 | |
689 | *out = NULL; |
690 | *outlen = 0; |
12bff6dc |
691 | return 1; |
0c4b7799 |
692 | } |
693 | |
694 | /* Temporary null routines for testing. */ |
695 | |
3d9449a1 |
696 | int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, |
697 | char *keystr, char *fingerprint, |
698 | void (*callback)(void *ctx, int result), void *ctx) |
0c4b7799 |
699 | { |
71ed591e |
700 | Str255 pappname; |
701 | Str255 pfingerprint; |
702 | Str255 pkeytype; |
c7bd96b8 |
703 | Session *s = frontend; |
71ed591e |
704 | int ret, alertret; |
705 | |
706 | c2pstrcpy(pappname, appname); |
707 | c2pstrcpy(pkeytype, keytype); |
708 | c2pstrcpy(pfingerprint, fingerprint); |
538bfd1d |
709 | |
710 | /* |
3d9449a1 |
711 | * The alert shouldn't be modal, it should be movable modal, or |
712 | * a sheet in Aqua. Also, PuTTY might be in the background, in |
713 | * which case we should use the Notification Manager to wake up |
714 | * the user. In any case, we shouldn't hold up processing of |
715 | * other connections' data just because this one's waiting for |
716 | * the user. |
538bfd1d |
717 | */ |
0c4b7799 |
718 | |
2007a49e |
719 | /* Verify the key against the cache */ |
720 | |
721 | ret = verify_host_key(host, port, keytype, keystr); |
722 | |
3d9449a1 |
723 | if (ret == 0) { /* success - key matched OK */ |
724 | return 1; |
725 | } else if (ret == 2) { /* key was different */ |
71ed591e |
726 | ParamText(pappname, pkeytype, pfingerprint, NULL); |
727 | alertret=CautionAlert(wWrong, NULL); |
95764589 |
728 | if (alertret == 8) { |
71ed591e |
729 | /* Cancel */ |
3d9449a1 |
730 | return 0; |
95764589 |
731 | } else if (alertret == 9) { |
71ed591e |
732 | /* Connect Just Once */ |
3d9449a1 |
733 | return 1; |
71ed591e |
734 | } else { |
735 | /* Update Key */ |
736 | store_host_key(host, port, keytype, keystr); |
3d9449a1 |
737 | return 1; |
71ed591e |
738 | } |
3d9449a1 |
739 | } else /* ret == 1 */ { /* key was absent */ |
71ed591e |
740 | ParamText(pkeytype, pfingerprint, pappname, NULL); |
741 | alertret=CautionAlert(wAbsent, NULL); |
95764589 |
742 | if (alertret == 7) { |
71ed591e |
743 | /* Cancel */ |
3d9449a1 |
744 | return 0; |
95764589 |
745 | } else if (alertret == 8) { |
71ed591e |
746 | /* Connect Just Once */ |
3d9449a1 |
747 | return 1; |
71ed591e |
748 | } else { |
749 | /* Update Key */ |
750 | store_host_key(host, port, keytype, keystr); |
3d9449a1 |
751 | return 1; |
71ed591e |
752 | } |
2007a49e |
753 | } |
0c4b7799 |
754 | } |
755 | |
3d9449a1 |
756 | int askalg(void *frontend, const char *algtype, const char *algname, |
757 | void (*callback)(void *ctx, int result), void *ctx) |
0c4b7799 |
758 | { |
3d9449a1 |
759 | return 0; |
0c4b7799 |
760 | } |
761 | |
762 | void old_keyfile_warning(void) |
763 | { |
764 | |
765 | } |
766 | |
e3c5b245 |
767 | FontSpec platform_default_fontspec(char const *name) |
5a9eb105 |
768 | { |
9a30e26b |
769 | FontSpec ret; |
a499fbf9 |
770 | long smfs; |
a499fbf9 |
771 | |
772 | if (!strcmp(name, "Font")) { |
773 | smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize); |
774 | if (smfs == 0) |
775 | smfs = GetScriptVariable(smRoman, smScriptMonoFondSize); |
776 | if (smfs != 0) { |
e3c5b245 |
777 | GetFontName(HiWord(smfs), ret.name); |
778 | if (ret.name[0] == 0) |
779 | memcpy(ret.name, "\pMonaco", 7); |
780 | ret.size = LoWord(smfs); |
9a30e26b |
781 | } else { |
e3c5b245 |
782 | memcpy(ret.name, "\pMonaco", 7); |
783 | ret.size = 9; |
9a30e26b |
784 | } |
e3c5b245 |
785 | ret.face = 0; |
9a30e26b |
786 | } else { |
e3c5b245 |
787 | ret.name[0] = 0; |
a499fbf9 |
788 | } |
9a30e26b |
789 | |
790 | return ret; |
791 | } |
792 | |
793 | Filename platform_default_filename(const char *name) |
794 | { |
795 | Filename ret; |
796 | if (!strcmp(name, "LogFileName")) |
02cf4001 |
797 | FSMakeFSSpec(0, 0, "\pputty.log", &ret.fss); |
9a30e26b |
798 | else |
02cf4001 |
799 | memset(&ret, 0, sizeof(ret)); |
9a30e26b |
800 | return ret; |
801 | } |
802 | |
803 | char *platform_default_s(char const *name) |
804 | { |
5a9eb105 |
805 | return NULL; |
806 | } |
807 | |
f5d2d791 |
808 | int platform_default_i(char const *name, int def) |
5a9eb105 |
809 | { |
a499fbf9 |
810 | |
5a9eb105 |
811 | /* Non-raw cut and paste of line-drawing chars works badly on the |
812 | * current Unix stub implementation of the Unicode functions. |
813 | * So I'm going to temporarily set the default to raw mode so |
814 | * that the failure mode isn't quite so drastically horrid. |
815 | * When Unicode comes in, this can all be put right. */ |
816 | if (!strcmp(name, "RawCNP")) |
817 | return 1; |
818 | return def; |
819 | } |
820 | |
e0e7dff8 |
821 | void platform_get_x11_auth(char *display, int *proto, |
822 | unsigned char *data, int *datalen) |
823 | { |
824 | /* SGT: I have no idea whether Mac X servers need anything here. */ |
825 | } |
826 | |
3ff0246a |
827 | void update_specials_menu(void *frontend) |
828 | { |
829 | Session *s = frontend; |
830 | WindowPtr front; |
831 | |
832 | front = mac_frontwindow(); |
833 | if (front != NULL && mac_windowsession(front) == s) |
834 | mac_adjustmenus(); |
835 | } |
836 | |
8154b602 |
837 | void notify_remote_exit(void *frontend) |
838 | { |
839 | Session *s = frontend; |
840 | int exitcode; |
841 | |
842 | if (!s->session_closed && |
843 | (exitcode = s->back->exitcode(s->backhandle)) >=0) { |
844 | s->session_closed = TRUE; |
845 | if (s->cfg.close_on_exit == FORCE_ON || |
846 | (s->cfg.close_on_exit == AUTO && exitcode == 0)) { |
847 | mac_closewindow(s->window); |
848 | return; |
849 | } |
850 | |
851 | /* The session's dead */ |
852 | |
853 | if (s->ldisc) { |
854 | ldisc_free(s->ldisc); |
855 | s->ldisc = NULL; |
856 | } |
857 | |
858 | if (s->back) { |
859 | s->back->free(s->backhandle); |
860 | s->backhandle = NULL; |
861 | s->back = NULL; |
862 | update_specials_menu(s); |
863 | } |
864 | |
865 | { |
866 | char title[100]; |
867 | sprintf(title, "%.70s (inactive)", appname); |
868 | set_title(s, title); |
869 | } |
870 | } |
871 | } |
e479b152 |
872 | |
d082ac49 |
873 | /* |
874 | * Local Variables: |
875 | * c-file-style: "simon" |
876 | * End: |
877 | */ |