b24ecb46 |
1 | /* $Id: mac.c,v 1.55 2003/03/17 19:00:36 ben Exp $ */ |
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> |
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> |
9ef3c1ca |
46 | #include <Navigation.h> |
d082ac49 |
47 | #include <Resources.h> |
36577dc9 |
48 | #include <Script.h> |
8768ce31 |
49 | #include <TextCommon.h> |
d082ac49 |
50 | #include <ToolUtils.h> |
8768ce31 |
51 | #include <UnicodeConverter.h> |
d082ac49 |
52 | |
53 | #include <assert.h> |
54 | #include <limits.h> |
55 | #include <stdarg.h> |
56 | #include <stdlib.h> /* putty.h needs size_t */ |
57 | #include <stdio.h> /* for vsprintf */ |
58 | |
59 | #define PUTTY_DO_GLOBALS |
60 | |
61 | #include "macresid.h" |
62 | #include "putty.h" |
0c4b7799 |
63 | #include "ssh.h" |
538bfd1d |
64 | #include "terminal.h" |
d082ac49 |
65 | #include "mac.h" |
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; |
0ec4b50f |
72 | UInt32 sleeptime; |
d082ac49 |
73 | |
74 | static void mac_startup(void); |
75 | static void mac_eventloop(void); |
76 | #pragma noreturn (mac_eventloop) |
77 | static void mac_event(EventRecord *); |
78 | static void mac_contentclick(WindowPtr, EventRecord *); |
79 | static void mac_growwindow(WindowPtr, EventRecord *); |
80 | static void mac_activatewindow(WindowPtr, EventRecord *); |
0c5c7f5c |
81 | static void mac_suspendresume(EventRecord *); |
d082ac49 |
82 | static void mac_activateabout(WindowPtr, EventRecord *); |
83 | static void mac_updatewindow(WindowPtr); |
ebd78b62 |
84 | static void mac_updatelicence(WindowPtr); |
d082ac49 |
85 | static void mac_keypress(EventRecord *); |
86 | static int mac_windowtype(WindowPtr); |
87 | static void mac_menucommand(long); |
ebd78b62 |
88 | static void mac_openlicence(void); |
d082ac49 |
89 | static void mac_adjustcursor(RgnHandle); |
90 | static void mac_adjustmenus(void); |
91 | static void mac_closewindow(WindowPtr); |
92 | static void mac_zoomwindow(WindowPtr, short); |
0c4b7799 |
93 | #pragma noreturn (cleanup_exit) |
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 | |
fc34fbaf |
114 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
115 | /* Init Memory Manager */ |
116 | MaxApplZone(); |
117 | /* Init QuickDraw */ |
118 | InitGraf(&qd.thePort); |
119 | /* Init Font Manager */ |
120 | InitFonts(); |
121 | /* Init Window Manager */ |
122 | InitWindows(); |
123 | /* Init Menu Manager */ |
124 | InitMenus(); |
125 | /* Init TextEdit */ |
126 | TEInit(); |
127 | /* Init Dialog Manager */ |
f3ab148c |
128 | InitDialogs(NULL); |
fc34fbaf |
129 | #endif |
d082ac49 |
130 | cold = 0; |
131 | |
56ed4cf7 |
132 | /* Get base system version (only used if there's no better selector) */ |
133 | if (Gestalt(gestaltSystemVersion, &mac_gestalts.sysvers) != noErr || |
6e1063b1 |
134 | (mac_gestalts.sysvers &= 0xffff) < 0x700) |
56ed4cf7 |
135 | fatalbox("PuTTY requires System 7 or newer"); |
d082ac49 |
136 | /* Find out if we've got Color Quickdraw */ |
137 | if (Gestalt(gestaltQuickdrawVersion, &mac_gestalts.qdvers) != noErr) |
138 | mac_gestalts.qdvers = gestaltOriginalQD; |
139 | /* ... and the Appearance Manager? */ |
140 | if (Gestalt(gestaltAppearanceVersion, &mac_gestalts.apprvers) != noErr) |
141 | if (Gestalt(gestaltAppearanceAttr, NULL) == noErr) |
142 | mac_gestalts.apprvers = 0x0100; |
143 | else |
144 | mac_gestalts.apprvers = 0; |
145 | #if TARGET_RT_MAC_CFM |
146 | /* Paranoia: Did we manage to pull in AppearanceLib? */ |
147 | if (&RegisterAppearanceClient == kUnresolvedCFragSymbolAddress) |
148 | mac_gestalts.apprvers = 0; |
149 | #endif |
1fc898ea |
150 | #if TARGET_CPU_68K |
151 | mac_gestalts.cntlattr = 0; |
152 | mac_gestalts.windattr = 0; |
153 | #else |
d082ac49 |
154 | /* Mac OS 8.5 Control Manager (proportional scrollbars)? */ |
1fc898ea |
155 | if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr || |
156 | &SetControlViewSize == kUnresolvedCFragSymbolAddress) |
d082ac49 |
157 | mac_gestalts.cntlattr = 0; |
158 | /* Mac OS 8.5 Window Manager? */ |
1fc898ea |
159 | if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr || |
160 | &SetWindowContentColor == kUnresolvedCFragSymbolAddress) |
d082ac49 |
161 | mac_gestalts.windattr = 0; |
d49b7117 |
162 | /* Mac OS 8.5 Menu Manager? */ |
163 | if (Gestalt(gestaltMenuMgrAttr, &mac_gestalts.menuattr) != noErr) |
164 | mac_gestalts.menuattr = 0; |
1fc898ea |
165 | #endif |
8768ce31 |
166 | /* Text Encoding Conversion Manager? */ |
167 | if ( |
168 | #if TARGET_RT_MAC_CFM |
169 | &TECGetInfo == kUnresolvedCFragSymbolAddress || |
170 | #else |
171 | InitializeUnicodeConverter(NULL) != noErr || |
172 | #endif |
173 | TECGetInfo(&ti) != noErr) |
174 | mac_gestalts.encvvers = 0; |
175 | else { |
176 | mac_gestalts.encvvers = (*ti)->tecVersion; |
379836ca |
177 | mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures; |
8768ce31 |
178 | DisposeHandle((Handle)ti); |
179 | } |
9ef3c1ca |
180 | /* Navigation Services? */ |
181 | if (NavServicesAvailable()) |
182 | mac_gestalts.navsvers = NavLibraryVersion(); |
183 | else |
184 | mac_gestalts.navsvers = 0; |
97cfddb2 |
185 | |
f6fc0010 |
186 | sk_init(); |
2beb0fb0 |
187 | |
d082ac49 |
188 | /* We've been tested with the Appearance Manager */ |
189 | if (mac_gestalts.apprvers != 0) |
190 | RegisterAppearanceClient(); |
191 | |
192 | menuBar = GetNewMBar(128); |
193 | if (menuBar == NULL) |
194 | fatalbox("Unable to create menu bar."); |
195 | SetMenuBar(menuBar); |
196 | AppendResMenu(GetMenuHandle(mApple), 'DRVR'); |
b24ecb46 |
197 | if (mac_gestalts.menuattr & gestaltMenuMgrAquaLayoutMask) { |
d49b7117 |
198 | DeleteMenuItem(GetMenuHandle(mFile), iQuit); |
b24ecb46 |
199 | /* Also delete the separator above the Quit item. */ |
200 | DeleteMenuItem(GetMenuHandle(mFile), iQuit - 1); |
201 | } |
d082ac49 |
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 | |
fc34fbaf |
221 | #if !TARGET_API_MAC_CARBON |
bf873e8e |
222 | { |
223 | short vol; |
224 | long dirid; |
225 | |
226 | /* Set the default directory for loading and saving settings. */ |
227 | /* XXX Should we create it? */ |
228 | if (get_session_dir(FALSE, &vol, &dirid) == noErr) { |
229 | LMSetSFSaveDisk(-vol); |
230 | LMSetCurDirStore(dirid); |
231 | } |
232 | } |
fc34fbaf |
233 | #endif |
97cfddb2 |
234 | |
235 | /* Install Apple Event handlers. */ |
d70e3b83 |
236 | AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, |
237 | NewAEEventHandlerUPP(&mac_aevt_oapp), 0, FALSE); |
238 | AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, |
239 | NewAEEventHandlerUPP(&mac_aevt_odoc), 0, FALSE); |
240 | AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, |
241 | NewAEEventHandlerUPP(&mac_aevt_pdoc), 0, FALSE); |
97cfddb2 |
242 | AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, |
243 | NewAEEventHandlerUPP(&mac_aevt_quit), 0, FALSE); |
d082ac49 |
244 | } |
245 | |
246 | static void mac_eventloop(void) { |
247 | Boolean gotevent; |
248 | EventRecord event; |
249 | RgnHandle cursrgn; |
250 | |
251 | cursrgn = NewRgn(); |
0ec4b50f |
252 | sleeptime = 0; |
d082ac49 |
253 | for (;;) { |
254 | mac_adjustcursor(cursrgn); |
0ec4b50f |
255 | gotevent = WaitNextEvent(everyEvent, &event, sleeptime, cursrgn); |
256 | /* |
257 | * XXX For now, limit sleep time to 1/10 s to work around |
258 | * wake-before-sleep race in MacTCP code. |
259 | */ |
260 | sleeptime = 6; |
d082ac49 |
261 | mac_adjustcursor(cursrgn); |
0ec4b50f |
262 | if (gotevent) { |
263 | /* Ensure we get a null event when the real ones run out. */ |
264 | sleeptime = 0; |
d082ac49 |
265 | mac_event(&event); |
0ec4b50f |
266 | if (borednow) |
267 | cleanup_exit(0); |
268 | } |
f6fc0010 |
269 | sk_poll(); |
0ec4b50f |
270 | if (!gotevent) |
271 | mac_pollterm(); |
d082ac49 |
272 | } |
273 | DisposeRgn(cursrgn); |
274 | } |
275 | |
276 | static void mac_event(EventRecord *event) { |
277 | short part; |
278 | WindowPtr window; |
d082ac49 |
279 | |
280 | switch (event->what) { |
281 | case mouseDown: |
282 | part = FindWindow(event->where, &window); |
283 | switch (part) { |
284 | case inMenuBar: |
285 | mac_adjustmenus(); |
286 | mac_menucommand(MenuSelect(event->where)); |
287 | break; |
fc34fbaf |
288 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
289 | case inSysWindow: |
290 | SystemClick(event, window); |
291 | break; |
fc34fbaf |
292 | #endif |
d082ac49 |
293 | case inContent: |
294 | if (window != FrontWindow()) |
295 | /* XXX: check for movable modal dboxes? */ |
296 | SelectWindow(window); |
297 | else |
298 | mac_contentclick(window, event); |
299 | break; |
300 | case inGoAway: |
301 | if (TrackGoAway(window, event->where)) |
302 | mac_closewindow(window); |
303 | break; |
304 | case inDrag: |
305 | /* XXX: moveable modal check? */ |
fc34fbaf |
306 | #if TARGET_API_MAC_CARBON |
307 | { |
308 | BitMap screenBits; |
309 | |
310 | GetQDGlobalsScreenBits(&screenBits); |
311 | DragWindow(window, event->where, &screenBits.bounds); |
312 | } |
313 | #else |
d082ac49 |
314 | DragWindow(window, event->where, &qd.screenBits.bounds); |
fc34fbaf |
315 | #endif |
d082ac49 |
316 | break; |
317 | case inGrow: |
318 | mac_growwindow(window, event); |
319 | break; |
320 | case inZoomIn: |
321 | case inZoomOut: |
322 | if (TrackBox(window, event->where, part)) |
323 | mac_zoomwindow(window, part); |
324 | break; |
325 | } |
326 | break; |
327 | case keyDown: |
328 | case autoKey: |
329 | mac_keypress(event); |
330 | break; |
331 | case activateEvt: |
332 | mac_activatewindow((WindowPtr)event->message, event); |
333 | break; |
334 | case updateEvt: |
335 | mac_updatewindow((WindowPtr)event->message); |
336 | break; |
fc34fbaf |
337 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
338 | case diskEvt: |
339 | if (HiWord(event->message) != noErr) { |
fc34fbaf |
340 | Point pt; |
341 | |
d082ac49 |
342 | SetPt(&pt, 120, 120); |
343 | DIBadMount(pt, event->message); |
344 | } |
345 | break; |
fc34fbaf |
346 | #endif |
0c5c7f5c |
347 | case osEvt: |
348 | switch ((event->message & osEvtMessageMask) >> 24) { |
349 | case suspendResumeMessage: |
350 | mac_suspendresume(event); |
351 | break; |
352 | } |
353 | break; |
97cfddb2 |
354 | case kHighLevelEvent: |
355 | AEProcessAppleEvent(event); /* errors? */ |
356 | break; |
d082ac49 |
357 | } |
358 | } |
359 | |
f854b482 |
360 | static void mac_contentclick(WindowPtr window, EventRecord *event) |
361 | { |
d082ac49 |
362 | |
f854b482 |
363 | if (mac_wininfo(window)->click != NULL) |
364 | (*mac_wininfo(window)->click)(window, event); |
d082ac49 |
365 | } |
366 | |
f854b482 |
367 | static void mac_growwindow(WindowPtr window, EventRecord *event) |
368 | { |
d082ac49 |
369 | |
f854b482 |
370 | if (mac_wininfo(window)->grow != NULL) |
371 | (*mac_wininfo(window)->grow)(window, event); |
d082ac49 |
372 | } |
373 | |
f854b482 |
374 | static void mac_activatewindow(WindowPtr window, EventRecord *event) |
375 | { |
d082ac49 |
376 | |
d082ac49 |
377 | mac_adjustmenus(); |
f854b482 |
378 | if (mac_wininfo(window)->activate != NULL) |
379 | (*mac_wininfo(window)->activate)(window, event); |
d082ac49 |
380 | } |
381 | |
fc34fbaf |
382 | static void mac_updatewindow(WindowPtr window) |
383 | { |
d082ac49 |
384 | |
f854b482 |
385 | if (mac_wininfo(window)->update != NULL) |
386 | (*mac_wininfo(window)->update)(window); |
d082ac49 |
387 | } |
388 | |
389 | /* |
390 | * Work out what kind of window we're dealing with. |
d082ac49 |
391 | */ |
347bfcd7 |
392 | static int mac_windowtype(WindowPtr window) |
393 | { |
394 | |
395 | #if !TARGET_API_MAC_CARBON |
396 | if (GetWindowKind(window) < 0) |
d082ac49 |
397 | return wDA; |
347bfcd7 |
398 | #endif |
399 | return ((WinInfo *)GetWRefCon(window))->wtype; |
d082ac49 |
400 | } |
401 | |
402 | /* |
403 | * Handle a key press |
404 | */ |
405 | static void mac_keypress(EventRecord *event) { |
406 | WindowPtr window; |
407 | |
3fa61577 |
408 | window = mac_frontwindow(); |
d082ac49 |
409 | /* |
410 | * Check for a command-key combination, but ignore it if it counts |
411 | * as a meta-key combination and we're in a terminal window. |
412 | */ |
413 | if (event->what == keyDown && (event->modifiers & cmdKey) /*&& |
414 | !((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers && |
415 | mac_windowtype(window) == wTerminal)*/) { |
416 | mac_adjustmenus(); |
417 | mac_menucommand(MenuKey(event->message & charCodeMask)); |
418 | } else { |
3fa61577 |
419 | if (window != NULL && mac_wininfo(window)->key != NULL) |
f854b482 |
420 | (*mac_wininfo(window)->key)(window, event); |
d082ac49 |
421 | } |
422 | } |
423 | |
424 | static void mac_menucommand(long result) { |
425 | short menu, item; |
d082ac49 |
426 | WindowPtr window; |
fc34fbaf |
427 | #if !TARGET_API_MAC_CARBON |
428 | Str255 da; |
429 | #endif |
d082ac49 |
430 | |
431 | menu = HiWord(result); |
432 | item = LoWord(result); |
3fa61577 |
433 | window = mac_frontwindow(); |
d082ac49 |
434 | /* Things which do the same whatever window we're in. */ |
435 | switch (menu) { |
436 | case mApple: |
437 | switch (item) { |
438 | case iAbout: |
439 | mac_openabout(); |
440 | goto done; |
cc2be455 |
441 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
442 | default: |
443 | GetMenuItemText(GetMenuHandle(mApple), item, da); |
444 | OpenDeskAcc(da); |
445 | goto done; |
cc2be455 |
446 | #endif |
d082ac49 |
447 | } |
448 | break; |
449 | case mFile: |
450 | switch (item) { |
451 | case iNew: |
452 | mac_newsession(); |
453 | goto done; |
ce283213 |
454 | case iOpen: |
455 | mac_opensession(); |
456 | goto done; |
d082ac49 |
457 | case iClose: |
458 | mac_closewindow(window); |
459 | goto done; |
b537dd42 |
460 | case iSave: |
461 | mac_savesession(); |
462 | goto done; |
463 | case iSaveAs: |
464 | mac_savesessionas(); |
465 | goto done; |
5211281f |
466 | case iDuplicate: |
467 | mac_dupsession(); |
468 | goto done; |
d082ac49 |
469 | case iQuit: |
0c4b7799 |
470 | cleanup_exit(0); |
d082ac49 |
471 | goto done; |
472 | } |
473 | break; |
474 | } |
475 | /* If we get here, handling is up to window-specific code. */ |
3fa61577 |
476 | if (window != NULL && mac_wininfo(window)->menu != NULL) |
f854b482 |
477 | (*mac_wininfo(window)->menu)(window, menu, item); |
478 | |
d082ac49 |
479 | done: |
480 | HiliteMenu(0); |
481 | } |
482 | |
d082ac49 |
483 | static void mac_closewindow(WindowPtr window) { |
484 | |
485 | switch (mac_windowtype(window)) { |
fc34fbaf |
486 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
487 | case wDA: |
347bfcd7 |
488 | CloseDeskAcc(GetWindowKind(window)); |
d082ac49 |
489 | break; |
fc34fbaf |
490 | #endif |
f854b482 |
491 | default: |
492 | if (mac_wininfo(window)->close != NULL) |
493 | (*mac_wininfo(window)->close)(window); |
d082ac49 |
494 | break; |
495 | } |
496 | } |
497 | |
0c5c7f5c |
498 | static void mac_suspendresume(EventRecord *event) |
499 | { |
500 | WindowPtr front; |
501 | EventRecord fakeevent; |
502 | |
503 | /* |
504 | * We're called either before we're suspended or after we're |
505 | * resumed, so we're the front application at this point. |
506 | */ |
507 | front = FrontWindow(); |
508 | if (front != NULL) { |
509 | fakeevent.what = activateEvt; |
510 | fakeevent.message = (UInt32)front; |
511 | fakeevent.when = event->when; |
512 | fakeevent.where = event->where; |
513 | fakeevent.modifiers = |
514 | (event->message & resumeFlag) ? activeFlag : 0; |
515 | mac_activatewindow(front, &fakeevent); |
516 | } |
517 | } |
518 | |
d082ac49 |
519 | static void mac_zoomwindow(WindowPtr window, short part) { |
520 | |
521 | /* FIXME: do something */ |
522 | } |
523 | |
524 | /* |
525 | * Make the menus look right before the user gets to see them. |
526 | */ |
fc34fbaf |
527 | #if TARGET_API_MAC_CARBON |
fc34fbaf |
528 | #define EnableItem EnableMenuItem |
529 | #define DisableItem DisableMenuItem |
530 | #endif |
d082ac49 |
531 | static void mac_adjustmenus(void) { |
532 | WindowPtr window; |
533 | MenuHandle menu; |
534 | |
3fa61577 |
535 | window = mac_frontwindow(); |
d082ac49 |
536 | menu = GetMenuHandle(mApple); |
537 | EnableItem(menu, 0); |
538 | EnableItem(menu, iAbout); |
539 | |
540 | menu = GetMenuHandle(mFile); |
541 | EnableItem(menu, 0); |
542 | EnableItem(menu, iNew); |
543 | if (window != NULL) |
544 | EnableItem(menu, iClose); |
545 | else |
546 | DisableItem(menu, iClose); |
547 | EnableItem(menu, iQuit); |
548 | |
3fa61577 |
549 | if (window != NULL && mac_wininfo(window)->adjustmenus != NULL) |
f854b482 |
550 | (*mac_wininfo(window)->adjustmenus)(window); |
551 | else { |
b537dd42 |
552 | DisableItem(menu, iSave); |
553 | DisableItem(menu, iSaveAs); |
5211281f |
554 | DisableItem(menu, iDuplicate); |
d082ac49 |
555 | menu = GetMenuHandle(mEdit); |
556 | DisableItem(menu, 0); |
7dcd1f87 |
557 | menu = GetMenuHandle(mWindow); |
558 | DisableItem(menu, 0); /* Until we get more than 1 item on it. */ |
d082ac49 |
559 | } |
560 | DrawMenuBar(); |
561 | } |
562 | |
563 | /* |
564 | * Make sure the right cursor's being displayed. |
565 | */ |
566 | static void mac_adjustcursor(RgnHandle cursrgn) { |
567 | Point mouse; |
568 | WindowPtr window, front; |
569 | short part; |
fc34fbaf |
570 | #if TARGET_API_MAC_CARBON |
571 | Cursor arrow; |
572 | RgnHandle visrgn; |
573 | #endif |
d082ac49 |
574 | |
575 | GetMouse(&mouse); |
576 | LocalToGlobal(&mouse); |
577 | part = FindWindow(mouse, &window); |
578 | front = FrontWindow(); |
579 | if (part != inContent || window == NULL || window != front) { |
580 | /* Cursor isn't in the front window, so switch to arrow */ |
fc34fbaf |
581 | #if TARGET_API_MAC_CARBON |
582 | GetQDGlobalsArrow(&arrow); |
583 | SetCursor(&arrow); |
584 | #else |
d082ac49 |
585 | SetCursor(&qd.arrow); |
fc34fbaf |
586 | #endif |
d082ac49 |
587 | SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); |
fc34fbaf |
588 | if (front != NULL) { |
589 | #if TARGET_API_MAC_CARBON |
590 | visrgn = NewRgn(); |
591 | GetPortVisibleRegion(GetWindowPort(front), visrgn); |
592 | DiffRgn(cursrgn, visrgn, cursrgn); |
593 | DisposeRgn(visrgn); |
594 | #else |
d082ac49 |
595 | DiffRgn(cursrgn, front->visRgn, cursrgn); |
fc34fbaf |
596 | #endif |
597 | } |
d082ac49 |
598 | } else { |
f854b482 |
599 | if (mac_wininfo(window)->adjustcursor != NULL) |
600 | (*mac_wininfo(window)->adjustcursor)(window, mouse, cursrgn); |
601 | else { |
fc34fbaf |
602 | #if TARGET_API_MAC_CARBON |
603 | GetQDGlobalsArrow(&arrow); |
604 | SetCursor(&arrow); |
605 | GetPortVisibleRegion(GetWindowPort(window), cursrgn); |
606 | #else |
d082ac49 |
607 | SetCursor(&qd.arrow); |
608 | CopyRgn(window->visRgn, cursrgn); |
fc34fbaf |
609 | #endif |
d082ac49 |
610 | } |
611 | } |
612 | } |
613 | |
d70e3b83 |
614 | pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply, |
97cfddb2 |
615 | long refcon) |
616 | { |
d70e3b83 |
617 | DescType type; |
618 | Size size; |
619 | |
620 | if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, |
621 | &type, NULL, 0, &size) == noErr) |
622 | return errAEParamMissed; |
97cfddb2 |
623 | |
624 | borednow = 1; |
625 | return noErr; |
626 | } |
627 | |
0c4b7799 |
628 | void cleanup_exit(int status) |
629 | { |
d082ac49 |
630 | |
713b8b7a |
631 | #if !TARGET_RT_MAC_CFM |
8768ce31 |
632 | if (mac_gestalts.encvvers != 0) |
633 | TerminateUnicodeConverter(); |
713b8b7a |
634 | #endif |
27a3458f |
635 | sk_cleanup(); |
0c4b7799 |
636 | exit(status); |
d082ac49 |
637 | } |
638 | |
2beb0fb0 |
639 | /* This should only kill the current session, not the whole application. */ |
640 | void connection_fatal(void *fontend, char *fmt, ...) { |
641 | va_list ap; |
642 | Str255 stuff; |
643 | |
644 | va_start(ap, fmt); |
645 | /* We'd like stuff to be a Pascal string */ |
646 | stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); |
647 | va_end(ap); |
648 | ParamText(stuff, NULL, NULL, NULL); |
649 | StopAlert(128, NULL); |
04b0fa02 |
650 | cleanup_exit(1); |
2beb0fb0 |
651 | } |
652 | |
0c4b7799 |
653 | /* Null SSH agent client -- never finds an agent. */ |
654 | |
655 | int agent_exists(void) |
656 | { |
657 | |
658 | return FALSE; |
659 | } |
660 | |
661 | void agent_query(void *in, int inlen, void **out, int *outlen) |
662 | { |
663 | |
664 | *out = NULL; |
665 | *outlen = 0; |
666 | } |
667 | |
668 | /* Temporary null routines for testing. */ |
669 | |
538bfd1d |
670 | /* |
671 | * FIXME: verify_ssh_host_key() should be passed a frontend handle, |
672 | * but backends have to have a terminal handle instead, because they |
673 | * pass it to from_backend(), so we accept a terminal handle here as |
674 | * well, and hope no-one tries to call us with sensible arguments. |
675 | */ |
0c4b7799 |
676 | void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, |
677 | char *keystr, char *fingerprint) |
678 | { |
538bfd1d |
679 | Str255 stuff; |
680 | Terminal *term = frontend; |
681 | Session *s = term->frontend; |
682 | |
683 | /* |
684 | * This function is horribly wrong. For one thing, the alert |
685 | * shouldn't be modal, it should be movable modal, or a sheet in |
686 | * Aqua. Also, PuTTY might be in the background, in which case we |
687 | * should use the Notification Manager to wake up the user. In |
688 | * any case, we shouldn't hold up processing of other connections' |
689 | * data just because this one's waiting for the user. It should |
690 | * also handle a host key cache, of course, and see the note above |
691 | * about the "frontend" argument and the one below about closing |
692 | * the connection. All in all, a bit of a mess really. |
693 | */ |
0c4b7799 |
694 | |
538bfd1d |
695 | stuff[0] = sprintf((char *)(&stuff[1]), |
696 | "The server's key fingerprint is: %s\n" |
697 | "Continue connecting?", fingerprint); |
698 | ParamText(stuff, NULL, NULL, NULL); |
699 | if (CautionAlert(wQuestion, NULL) == 2) { |
700 | /* |
701 | * User chose "Cancel". Unfortunately, if I tear the |
702 | * connection down here, Bad Things happen when I return. I |
703 | * think this function should actually return something |
704 | * telling the SSH code to abandon the connection. |
705 | */ |
706 | } |
0c4b7799 |
707 | } |
708 | |
709 | void askcipher(void *frontend, char *ciphername, int cs) |
710 | { |
711 | |
712 | } |
713 | |
714 | void old_keyfile_warning(void) |
715 | { |
716 | |
717 | } |
718 | |
e3c5b245 |
719 | FontSpec platform_default_fontspec(char const *name) |
5a9eb105 |
720 | { |
9a30e26b |
721 | FontSpec ret; |
a499fbf9 |
722 | long smfs; |
a499fbf9 |
723 | |
724 | if (!strcmp(name, "Font")) { |
725 | smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize); |
726 | if (smfs == 0) |
727 | smfs = GetScriptVariable(smRoman, smScriptMonoFondSize); |
728 | if (smfs != 0) { |
e3c5b245 |
729 | GetFontName(HiWord(smfs), ret.name); |
730 | if (ret.name[0] == 0) |
731 | memcpy(ret.name, "\pMonaco", 7); |
732 | ret.size = LoWord(smfs); |
9a30e26b |
733 | } else { |
e3c5b245 |
734 | memcpy(ret.name, "\pMonaco", 7); |
735 | ret.size = 9; |
9a30e26b |
736 | } |
e3c5b245 |
737 | ret.face = 0; |
9a30e26b |
738 | } else { |
e3c5b245 |
739 | ret.name[0] = 0; |
a499fbf9 |
740 | } |
9a30e26b |
741 | |
742 | return ret; |
743 | } |
744 | |
745 | Filename platform_default_filename(const char *name) |
746 | { |
747 | Filename ret; |
748 | if (!strcmp(name, "LogFileName")) |
02cf4001 |
749 | FSMakeFSSpec(0, 0, "\pputty.log", &ret.fss); |
9a30e26b |
750 | else |
02cf4001 |
751 | memset(&ret, 0, sizeof(ret)); |
9a30e26b |
752 | return ret; |
753 | } |
754 | |
755 | char *platform_default_s(char const *name) |
756 | { |
5a9eb105 |
757 | return NULL; |
758 | } |
759 | |
f5d2d791 |
760 | int platform_default_i(char const *name, int def) |
5a9eb105 |
761 | { |
a499fbf9 |
762 | |
5a9eb105 |
763 | /* Non-raw cut and paste of line-drawing chars works badly on the |
764 | * current Unix stub implementation of the Unicode functions. |
765 | * So I'm going to temporarily set the default to raw mode so |
766 | * that the failure mode isn't quite so drastically horrid. |
767 | * When Unicode comes in, this can all be put right. */ |
768 | if (!strcmp(name, "RawCNP")) |
769 | return 1; |
770 | return def; |
771 | } |
772 | |
e0e7dff8 |
773 | void platform_get_x11_auth(char *display, int *proto, |
774 | unsigned char *data, int *datalen) |
775 | { |
776 | /* SGT: I have no idea whether Mac X servers need anything here. */ |
777 | } |
778 | |
d082ac49 |
779 | /* |
780 | * Local Variables: |
781 | * c-file-style: "simon" |
782 | * End: |
783 | */ |