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 | { |
ffa79828 |
213 | int i; |
1adaeb2e |
214 | default_port = 0; /* illegal */ |
ffa79828 |
215 | for (i = 0; backends[i].backend != NULL; i++) |
216 | if (backends[i].protocol == default_protocol) { |
217 | default_port = backends[i].backend->default_port; |
218 | break; |
219 | } |
220 | } |
0c4b7799 |
221 | flags = FLAG_INTERACTIVE; |
222 | |
fc34fbaf |
223 | #if !TARGET_API_MAC_CARBON |
bf873e8e |
224 | { |
225 | short vol; |
226 | long dirid; |
227 | |
228 | /* Set the default directory for loading and saving settings. */ |
229 | /* XXX Should we create it? */ |
230 | if (get_session_dir(FALSE, &vol, &dirid) == noErr) { |
231 | LMSetSFSaveDisk(-vol); |
232 | LMSetCurDirStore(dirid); |
233 | } |
234 | } |
fc34fbaf |
235 | #endif |
97cfddb2 |
236 | |
237 | /* Install Apple Event handlers. */ |
d70e3b83 |
238 | AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, |
239 | NewAEEventHandlerUPP(&mac_aevt_oapp), 0, FALSE); |
240 | AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, |
241 | NewAEEventHandlerUPP(&mac_aevt_odoc), 0, FALSE); |
242 | AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, |
243 | NewAEEventHandlerUPP(&mac_aevt_pdoc), 0, FALSE); |
97cfddb2 |
244 | AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, |
245 | NewAEEventHandlerUPP(&mac_aevt_quit), 0, FALSE); |
d082ac49 |
246 | } |
247 | |
b483d9ac |
248 | void timer_change_notify(long next) |
249 | { |
250 | timing_next_time = next; |
251 | } |
252 | |
d082ac49 |
253 | static void mac_eventloop(void) { |
254 | Boolean gotevent; |
255 | EventRecord event; |
256 | RgnHandle cursrgn; |
b483d9ac |
257 | long next; |
258 | long ticksleft; |
d082ac49 |
259 | |
260 | cursrgn = NewRgn(); |
0ec4b50f |
261 | sleeptime = 0; |
d082ac49 |
262 | for (;;) { |
263 | mac_adjustcursor(cursrgn); |
b483d9ac |
264 | ticksleft=timing_next_time-GETTICKCOUNT(); |
265 | if (sleeptime > ticksleft && ticksleft >=0) |
266 | sleeptime=ticksleft; |
0ec4b50f |
267 | gotevent = WaitNextEvent(everyEvent, &event, sleeptime, cursrgn); |
b483d9ac |
268 | if (timing_next_time <= GETTICKCOUNT()) { |
269 | if (run_timers(timing_next_time, &next)) { |
270 | timer_change_notify(next); |
271 | } |
272 | } |
273 | |
0ec4b50f |
274 | /* |
275 | * XXX For now, limit sleep time to 1/10 s to work around |
276 | * wake-before-sleep race in MacTCP code. |
277 | */ |
278 | sleeptime = 6; |
d082ac49 |
279 | mac_adjustcursor(cursrgn); |
0ec4b50f |
280 | if (gotevent) { |
281 | /* Ensure we get a null event when the real ones run out. */ |
282 | sleeptime = 0; |
d082ac49 |
283 | mac_event(&event); |
0ec4b50f |
284 | if (borednow) |
285 | cleanup_exit(0); |
286 | } |
f6fc0010 |
287 | sk_poll(); |
0ec4b50f |
288 | if (!gotevent) |
289 | mac_pollterm(); |
1f1ec0e5 |
290 | if (mac_gestalts.apprvers >= 0x100 && mac_frontwindow() != NULL) |
291 | IdleControls(mac_frontwindow()); |
d082ac49 |
292 | } |
293 | DisposeRgn(cursrgn); |
294 | } |
295 | |
296 | static void mac_event(EventRecord *event) { |
297 | short part; |
298 | WindowPtr window; |
d082ac49 |
299 | |
300 | switch (event->what) { |
301 | case mouseDown: |
302 | part = FindWindow(event->where, &window); |
303 | switch (part) { |
304 | case inMenuBar: |
305 | mac_adjustmenus(); |
306 | mac_menucommand(MenuSelect(event->where)); |
307 | break; |
fc34fbaf |
308 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
309 | case inSysWindow: |
310 | SystemClick(event, window); |
311 | break; |
fc34fbaf |
312 | #endif |
d082ac49 |
313 | case inContent: |
314 | if (window != FrontWindow()) |
315 | /* XXX: check for movable modal dboxes? */ |
316 | SelectWindow(window); |
317 | else |
318 | mac_contentclick(window, event); |
319 | break; |
320 | case inGoAway: |
321 | if (TrackGoAway(window, event->where)) |
322 | mac_closewindow(window); |
323 | break; |
324 | case inDrag: |
325 | /* XXX: moveable modal check? */ |
fc34fbaf |
326 | #if TARGET_API_MAC_CARBON |
327 | { |
328 | BitMap screenBits; |
329 | |
330 | GetQDGlobalsScreenBits(&screenBits); |
331 | DragWindow(window, event->where, &screenBits.bounds); |
332 | } |
333 | #else |
d082ac49 |
334 | DragWindow(window, event->where, &qd.screenBits.bounds); |
fc34fbaf |
335 | #endif |
d082ac49 |
336 | break; |
337 | case inGrow: |
338 | mac_growwindow(window, event); |
339 | break; |
340 | case inZoomIn: |
341 | case inZoomOut: |
342 | if (TrackBox(window, event->where, part)) |
343 | mac_zoomwindow(window, part); |
344 | break; |
345 | } |
346 | break; |
347 | case keyDown: |
348 | case autoKey: |
349 | mac_keypress(event); |
350 | break; |
351 | case activateEvt: |
352 | mac_activatewindow((WindowPtr)event->message, event); |
353 | break; |
354 | case updateEvt: |
355 | mac_updatewindow((WindowPtr)event->message); |
356 | break; |
fc34fbaf |
357 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
358 | case diskEvt: |
359 | if (HiWord(event->message) != noErr) { |
fc34fbaf |
360 | Point pt; |
361 | |
d082ac49 |
362 | SetPt(&pt, 120, 120); |
363 | DIBadMount(pt, event->message); |
364 | } |
365 | break; |
fc34fbaf |
366 | #endif |
0c5c7f5c |
367 | case osEvt: |
368 | switch ((event->message & osEvtMessageMask) >> 24) { |
369 | case suspendResumeMessage: |
370 | mac_suspendresume(event); |
371 | break; |
372 | } |
373 | break; |
97cfddb2 |
374 | case kHighLevelEvent: |
375 | AEProcessAppleEvent(event); /* errors? */ |
376 | break; |
d082ac49 |
377 | } |
378 | } |
379 | |
f854b482 |
380 | static void mac_contentclick(WindowPtr window, EventRecord *event) |
381 | { |
d082ac49 |
382 | |
f854b482 |
383 | if (mac_wininfo(window)->click != NULL) |
384 | (*mac_wininfo(window)->click)(window, event); |
d082ac49 |
385 | } |
386 | |
f854b482 |
387 | static void mac_growwindow(WindowPtr window, EventRecord *event) |
388 | { |
d082ac49 |
389 | |
f854b482 |
390 | if (mac_wininfo(window)->grow != NULL) |
391 | (*mac_wininfo(window)->grow)(window, event); |
d082ac49 |
392 | } |
393 | |
f854b482 |
394 | static void mac_activatewindow(WindowPtr window, EventRecord *event) |
395 | { |
d082ac49 |
396 | |
d082ac49 |
397 | mac_adjustmenus(); |
f854b482 |
398 | if (mac_wininfo(window)->activate != NULL) |
399 | (*mac_wininfo(window)->activate)(window, event); |
d082ac49 |
400 | } |
401 | |
fc34fbaf |
402 | static void mac_updatewindow(WindowPtr window) |
403 | { |
d082ac49 |
404 | |
f854b482 |
405 | if (mac_wininfo(window)->update != NULL) |
406 | (*mac_wininfo(window)->update)(window); |
d082ac49 |
407 | } |
408 | |
409 | /* |
410 | * Work out what kind of window we're dealing with. |
d082ac49 |
411 | */ |
347bfcd7 |
412 | static int mac_windowtype(WindowPtr window) |
413 | { |
414 | |
415 | #if !TARGET_API_MAC_CARBON |
416 | if (GetWindowKind(window) < 0) |
d082ac49 |
417 | return wDA; |
347bfcd7 |
418 | #endif |
419 | return ((WinInfo *)GetWRefCon(window))->wtype; |
d082ac49 |
420 | } |
421 | |
422 | /* |
423 | * Handle a key press |
424 | */ |
425 | static void mac_keypress(EventRecord *event) { |
426 | WindowPtr window; |
427 | |
3fa61577 |
428 | window = mac_frontwindow(); |
d082ac49 |
429 | /* |
430 | * Check for a command-key combination, but ignore it if it counts |
431 | * as a meta-key combination and we're in a terminal window. |
432 | */ |
433 | if (event->what == keyDown && (event->modifiers & cmdKey) /*&& |
434 | !((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers && |
435 | mac_windowtype(window) == wTerminal)*/) { |
436 | mac_adjustmenus(); |
437 | mac_menucommand(MenuKey(event->message & charCodeMask)); |
438 | } else { |
3fa61577 |
439 | if (window != NULL && mac_wininfo(window)->key != NULL) |
f854b482 |
440 | (*mac_wininfo(window)->key)(window, event); |
d082ac49 |
441 | } |
442 | } |
443 | |
444 | static void mac_menucommand(long result) { |
445 | short menu, item; |
d082ac49 |
446 | WindowPtr window; |
fc34fbaf |
447 | #if !TARGET_API_MAC_CARBON |
448 | Str255 da; |
449 | #endif |
d082ac49 |
450 | |
451 | menu = HiWord(result); |
452 | item = LoWord(result); |
3fa61577 |
453 | window = mac_frontwindow(); |
d082ac49 |
454 | /* Things which do the same whatever window we're in. */ |
455 | switch (menu) { |
456 | case mApple: |
457 | switch (item) { |
458 | case iAbout: |
459 | mac_openabout(); |
460 | goto done; |
cc2be455 |
461 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
462 | default: |
463 | GetMenuItemText(GetMenuHandle(mApple), item, da); |
464 | OpenDeskAcc(da); |
465 | goto done; |
cc2be455 |
466 | #endif |
d082ac49 |
467 | } |
468 | break; |
469 | case mFile: |
470 | switch (item) { |
471 | case iNew: |
472 | mac_newsession(); |
473 | goto done; |
ce283213 |
474 | case iOpen: |
475 | mac_opensession(); |
476 | goto done; |
d082ac49 |
477 | case iClose: |
478 | mac_closewindow(window); |
479 | goto done; |
b537dd42 |
480 | case iSave: |
481 | mac_savesession(); |
482 | goto done; |
483 | case iSaveAs: |
484 | mac_savesessionas(); |
485 | goto done; |
5211281f |
486 | case iDuplicate: |
487 | mac_dupsession(); |
488 | goto done; |
d082ac49 |
489 | case iQuit: |
0c4b7799 |
490 | cleanup_exit(0); |
d082ac49 |
491 | goto done; |
492 | } |
493 | break; |
494 | } |
495 | /* If we get here, handling is up to window-specific code. */ |
3fa61577 |
496 | if (window != NULL && mac_wininfo(window)->menu != NULL) |
f854b482 |
497 | (*mac_wininfo(window)->menu)(window, menu, item); |
498 | |
d082ac49 |
499 | done: |
500 | HiliteMenu(0); |
501 | } |
502 | |
d082ac49 |
503 | static void mac_closewindow(WindowPtr window) { |
504 | |
505 | switch (mac_windowtype(window)) { |
fc34fbaf |
506 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
507 | case wDA: |
347bfcd7 |
508 | CloseDeskAcc(GetWindowKind(window)); |
d082ac49 |
509 | break; |
fc34fbaf |
510 | #endif |
f854b482 |
511 | default: |
512 | if (mac_wininfo(window)->close != NULL) |
513 | (*mac_wininfo(window)->close)(window); |
d082ac49 |
514 | break; |
515 | } |
516 | } |
517 | |
0c5c7f5c |
518 | static void mac_suspendresume(EventRecord *event) |
519 | { |
520 | WindowPtr front; |
521 | EventRecord fakeevent; |
522 | |
523 | /* |
524 | * We're called either before we're suspended or after we're |
525 | * resumed, so we're the front application at this point. |
526 | */ |
527 | front = FrontWindow(); |
528 | if (front != NULL) { |
529 | fakeevent.what = activateEvt; |
530 | fakeevent.message = (UInt32)front; |
531 | fakeevent.when = event->when; |
532 | fakeevent.where = event->where; |
533 | fakeevent.modifiers = |
534 | (event->message & resumeFlag) ? activeFlag : 0; |
535 | mac_activatewindow(front, &fakeevent); |
536 | } |
537 | } |
538 | |
d082ac49 |
539 | static void mac_zoomwindow(WindowPtr window, short part) { |
540 | |
541 | /* FIXME: do something */ |
542 | } |
543 | |
544 | /* |
545 | * Make the menus look right before the user gets to see them. |
546 | */ |
fc34fbaf |
547 | #if TARGET_API_MAC_CARBON |
fc34fbaf |
548 | #define EnableItem EnableMenuItem |
549 | #define DisableItem DisableMenuItem |
550 | #endif |
d082ac49 |
551 | static void mac_adjustmenus(void) { |
552 | WindowPtr window; |
553 | MenuHandle menu; |
554 | |
3fa61577 |
555 | window = mac_frontwindow(); |
d082ac49 |
556 | menu = GetMenuHandle(mApple); |
557 | EnableItem(menu, 0); |
558 | EnableItem(menu, iAbout); |
559 | |
560 | menu = GetMenuHandle(mFile); |
561 | EnableItem(menu, 0); |
562 | EnableItem(menu, iNew); |
563 | if (window != NULL) |
564 | EnableItem(menu, iClose); |
565 | else |
566 | DisableItem(menu, iClose); |
567 | EnableItem(menu, iQuit); |
568 | |
3fa61577 |
569 | if (window != NULL && mac_wininfo(window)->adjustmenus != NULL) |
f854b482 |
570 | (*mac_wininfo(window)->adjustmenus)(window); |
571 | else { |
b537dd42 |
572 | DisableItem(menu, iSave); |
573 | DisableItem(menu, iSaveAs); |
5211281f |
574 | DisableItem(menu, iDuplicate); |
d082ac49 |
575 | menu = GetMenuHandle(mEdit); |
576 | DisableItem(menu, 0); |
7dcd1f87 |
577 | menu = GetMenuHandle(mWindow); |
578 | DisableItem(menu, 0); /* Until we get more than 1 item on it. */ |
d082ac49 |
579 | } |
580 | DrawMenuBar(); |
581 | } |
582 | |
583 | /* |
584 | * Make sure the right cursor's being displayed. |
585 | */ |
586 | static void mac_adjustcursor(RgnHandle cursrgn) { |
587 | Point mouse; |
588 | WindowPtr window, front; |
589 | short part; |
fc34fbaf |
590 | #if TARGET_API_MAC_CARBON |
591 | Cursor arrow; |
592 | RgnHandle visrgn; |
593 | #endif |
d082ac49 |
594 | |
595 | GetMouse(&mouse); |
596 | LocalToGlobal(&mouse); |
597 | part = FindWindow(mouse, &window); |
598 | front = FrontWindow(); |
599 | if (part != inContent || window == NULL || window != front) { |
600 | /* Cursor isn't in the front window, so switch to arrow */ |
fc34fbaf |
601 | #if TARGET_API_MAC_CARBON |
602 | GetQDGlobalsArrow(&arrow); |
603 | SetCursor(&arrow); |
604 | #else |
d082ac49 |
605 | SetCursor(&qd.arrow); |
fc34fbaf |
606 | #endif |
d082ac49 |
607 | SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); |
fc34fbaf |
608 | if (front != NULL) { |
609 | #if TARGET_API_MAC_CARBON |
610 | visrgn = NewRgn(); |
611 | GetPortVisibleRegion(GetWindowPort(front), visrgn); |
612 | DiffRgn(cursrgn, visrgn, cursrgn); |
613 | DisposeRgn(visrgn); |
614 | #else |
d082ac49 |
615 | DiffRgn(cursrgn, front->visRgn, cursrgn); |
fc34fbaf |
616 | #endif |
617 | } |
d082ac49 |
618 | } else { |
f854b482 |
619 | if (mac_wininfo(window)->adjustcursor != NULL) |
620 | (*mac_wininfo(window)->adjustcursor)(window, mouse, cursrgn); |
621 | else { |
fc34fbaf |
622 | #if TARGET_API_MAC_CARBON |
623 | GetQDGlobalsArrow(&arrow); |
624 | SetCursor(&arrow); |
625 | GetPortVisibleRegion(GetWindowPort(window), cursrgn); |
626 | #else |
d082ac49 |
627 | SetCursor(&qd.arrow); |
628 | CopyRgn(window->visRgn, cursrgn); |
fc34fbaf |
629 | #endif |
d082ac49 |
630 | } |
631 | } |
632 | } |
633 | |
d70e3b83 |
634 | pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply, |
97cfddb2 |
635 | long refcon) |
636 | { |
d70e3b83 |
637 | DescType type; |
638 | Size size; |
639 | |
640 | if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, |
641 | &type, NULL, 0, &size) == noErr) |
642 | return errAEParamMissed; |
97cfddb2 |
643 | |
644 | borednow = 1; |
645 | return noErr; |
646 | } |
647 | |
0c4b7799 |
648 | void cleanup_exit(int status) |
649 | { |
d082ac49 |
650 | |
713b8b7a |
651 | #if !TARGET_RT_MAC_CFM |
8768ce31 |
652 | if (mac_gestalts.encvvers != 0) |
653 | TerminateUnicodeConverter(); |
713b8b7a |
654 | #endif |
27a3458f |
655 | sk_cleanup(); |
0c4b7799 |
656 | exit(status); |
d082ac49 |
657 | } |
658 | |
2beb0fb0 |
659 | /* This should only kill the current session, not the whole application. */ |
660 | void connection_fatal(void *fontend, char *fmt, ...) { |
661 | va_list ap; |
662 | Str255 stuff; |
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); |
04b0fa02 |
670 | cleanup_exit(1); |
2beb0fb0 |
671 | } |
672 | |
0c4b7799 |
673 | /* Null SSH agent client -- never finds an agent. */ |
674 | |
675 | int agent_exists(void) |
676 | { |
677 | |
678 | return FALSE; |
679 | } |
680 | |
12bff6dc |
681 | int agent_query(void *in, int inlen, void **out, int *outlen, |
682 | void (*callback)(void *, void *, int), void *callback_ctx) |
0c4b7799 |
683 | { |
684 | |
685 | *out = NULL; |
686 | *outlen = 0; |
12bff6dc |
687 | return 1; |
0c4b7799 |
688 | } |
689 | |
690 | /* Temporary null routines for testing. */ |
691 | |
692 | void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, |
693 | char *keystr, char *fingerprint) |
694 | { |
538bfd1d |
695 | Str255 stuff; |
c7bd96b8 |
696 | Session *s = frontend; |
538bfd1d |
697 | |
698 | /* |
699 | * This function is horribly wrong. For one thing, the alert |
700 | * shouldn't be modal, it should be movable modal, or a sheet in |
701 | * Aqua. Also, PuTTY might be in the background, in which case we |
702 | * should use the Notification Manager to wake up the user. In |
703 | * any case, we shouldn't hold up processing of other connections' |
704 | * data just because this one's waiting for the user. It should |
c7bd96b8 |
705 | * also handle a host key cache, of course, and see the note below |
706 | * about closing the connection. All in all, a bit of a mess |
707 | * really. |
538bfd1d |
708 | */ |
0c4b7799 |
709 | |
538bfd1d |
710 | stuff[0] = sprintf((char *)(&stuff[1]), |
711 | "The server's key fingerprint is: %s\n" |
712 | "Continue connecting?", fingerprint); |
713 | ParamText(stuff, NULL, NULL, NULL); |
714 | if (CautionAlert(wQuestion, NULL) == 2) { |
715 | /* |
716 | * User chose "Cancel". Unfortunately, if I tear the |
717 | * connection down here, Bad Things happen when I return. I |
718 | * think this function should actually return something |
719 | * telling the SSH code to abandon the connection. |
720 | */ |
721 | } |
0c4b7799 |
722 | } |
723 | |
83e7d008 |
724 | void askalg(void *frontend, const char *algtype, const char *algname) |
0c4b7799 |
725 | { |
726 | |
727 | } |
728 | |
729 | void old_keyfile_warning(void) |
730 | { |
731 | |
732 | } |
733 | |
e3c5b245 |
734 | FontSpec platform_default_fontspec(char const *name) |
5a9eb105 |
735 | { |
9a30e26b |
736 | FontSpec ret; |
a499fbf9 |
737 | long smfs; |
a499fbf9 |
738 | |
739 | if (!strcmp(name, "Font")) { |
740 | smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize); |
741 | if (smfs == 0) |
742 | smfs = GetScriptVariable(smRoman, smScriptMonoFondSize); |
743 | if (smfs != 0) { |
e3c5b245 |
744 | GetFontName(HiWord(smfs), ret.name); |
745 | if (ret.name[0] == 0) |
746 | memcpy(ret.name, "\pMonaco", 7); |
747 | ret.size = LoWord(smfs); |
9a30e26b |
748 | } else { |
e3c5b245 |
749 | memcpy(ret.name, "\pMonaco", 7); |
750 | ret.size = 9; |
9a30e26b |
751 | } |
e3c5b245 |
752 | ret.face = 0; |
9a30e26b |
753 | } else { |
e3c5b245 |
754 | ret.name[0] = 0; |
a499fbf9 |
755 | } |
9a30e26b |
756 | |
757 | return ret; |
758 | } |
759 | |
760 | Filename platform_default_filename(const char *name) |
761 | { |
762 | Filename ret; |
763 | if (!strcmp(name, "LogFileName")) |
02cf4001 |
764 | FSMakeFSSpec(0, 0, "\pputty.log", &ret.fss); |
9a30e26b |
765 | else |
02cf4001 |
766 | memset(&ret, 0, sizeof(ret)); |
9a30e26b |
767 | return ret; |
768 | } |
769 | |
770 | char *platform_default_s(char const *name) |
771 | { |
5a9eb105 |
772 | return NULL; |
773 | } |
774 | |
f5d2d791 |
775 | int platform_default_i(char const *name, int def) |
5a9eb105 |
776 | { |
a499fbf9 |
777 | |
5a9eb105 |
778 | /* Non-raw cut and paste of line-drawing chars works badly on the |
779 | * current Unix stub implementation of the Unicode functions. |
780 | * So I'm going to temporarily set the default to raw mode so |
781 | * that the failure mode isn't quite so drastically horrid. |
782 | * When Unicode comes in, this can all be put right. */ |
783 | if (!strcmp(name, "RawCNP")) |
784 | return 1; |
785 | return def; |
786 | } |
787 | |
e0e7dff8 |
788 | void platform_get_x11_auth(char *display, int *proto, |
789 | unsigned char *data, int *datalen) |
790 | { |
791 | /* SGT: I have no idea whether Mac X servers need anything here. */ |
792 | } |
793 | |
3ff0246a |
794 | void update_specials_menu(void *frontend) |
795 | { |
796 | Session *s = frontend; |
797 | WindowPtr front; |
798 | |
799 | front = mac_frontwindow(); |
800 | if (front != NULL && mac_windowsession(front) == s) |
801 | mac_adjustmenus(); |
802 | } |
803 | |
e479b152 |
804 | void notify_remote_exit(void *fe) { /* XXX anything needed here? */ } |
805 | |
d082ac49 |
806 | /* |
807 | * Local Variables: |
808 | * c-file-style: "simon" |
809 | * End: |
810 | */ |