06c24bc0 |
1 | /* $Id: mac.c,v 1.48 2003/02/12 23:53:15 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> |
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" |
d082ac49 |
64 | #include "mac.h" |
65 | |
0c4b7799 |
66 | Session *sesslist; |
67 | |
d082ac49 |
68 | static int cold = 1; |
97cfddb2 |
69 | static int borednow = FALSE; |
d082ac49 |
70 | struct mac_gestalts mac_gestalts; |
71 | |
72 | static void mac_startup(void); |
73 | static void mac_eventloop(void); |
74 | #pragma noreturn (mac_eventloop) |
75 | static void mac_event(EventRecord *); |
76 | static void mac_contentclick(WindowPtr, EventRecord *); |
77 | static void mac_growwindow(WindowPtr, EventRecord *); |
78 | static void mac_activatewindow(WindowPtr, EventRecord *); |
79 | static void mac_activateabout(WindowPtr, EventRecord *); |
80 | static void mac_updatewindow(WindowPtr); |
ebd78b62 |
81 | static void mac_updatelicence(WindowPtr); |
d082ac49 |
82 | static void mac_keypress(EventRecord *); |
83 | static int mac_windowtype(WindowPtr); |
84 | static void mac_menucommand(long); |
85 | static void mac_openabout(void); |
ebd78b62 |
86 | static void mac_openlicence(void); |
d082ac49 |
87 | static void mac_adjustcursor(RgnHandle); |
88 | static void mac_adjustmenus(void); |
89 | static void mac_closewindow(WindowPtr); |
90 | static void mac_zoomwindow(WindowPtr, short); |
0c4b7799 |
91 | #pragma noreturn (cleanup_exit) |
d082ac49 |
92 | |
93 | struct mac_windows { |
94 | WindowPtr about; |
95 | WindowPtr licence; |
96 | }; |
97 | |
98 | struct mac_windows windows; |
99 | |
100 | int main (int argc, char **argv) { |
101 | |
102 | mac_startup(); |
103 | mac_eventloop(); |
104 | } |
105 | |
106 | #pragma noreturn (main) |
107 | |
108 | static void mac_startup(void) { |
109 | Handle menuBar; |
8768ce31 |
110 | TECInfoHandle ti; |
d082ac49 |
111 | |
fc34fbaf |
112 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
113 | /* Init Memory Manager */ |
114 | MaxApplZone(); |
115 | /* Init QuickDraw */ |
116 | InitGraf(&qd.thePort); |
117 | /* Init Font Manager */ |
118 | InitFonts(); |
119 | /* Init Window Manager */ |
120 | InitWindows(); |
121 | /* Init Menu Manager */ |
122 | InitMenus(); |
123 | /* Init TextEdit */ |
124 | TEInit(); |
125 | /* Init Dialog Manager */ |
f3ab148c |
126 | InitDialogs(NULL); |
fc34fbaf |
127 | #endif |
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 | } |
9ef3c1ca |
175 | /* Navigation Services? */ |
176 | if (NavServicesAvailable()) |
177 | mac_gestalts.navsvers = NavLibraryVersion(); |
178 | else |
179 | mac_gestalts.navsvers = 0; |
97cfddb2 |
180 | |
f6fc0010 |
181 | sk_init(); |
2beb0fb0 |
182 | |
d082ac49 |
183 | /* We've been tested with the Appearance Manager */ |
184 | if (mac_gestalts.apprvers != 0) |
185 | RegisterAppearanceClient(); |
186 | |
187 | menuBar = GetNewMBar(128); |
188 | if (menuBar == NULL) |
189 | fatalbox("Unable to create menu bar."); |
190 | SetMenuBar(menuBar); |
191 | AppendResMenu(GetMenuHandle(mApple), 'DRVR'); |
192 | mac_adjustmenus(); |
193 | DrawMenuBar(); |
194 | InitCursor(); |
195 | windows.about = NULL; |
196 | windows.licence = NULL; |
197 | |
ffa79828 |
198 | default_protocol = be_default_protocol; |
199 | /* Find the appropriate default port. */ |
200 | { |
ffa79828 |
201 | int i; |
1adaeb2e |
202 | default_port = 0; /* illegal */ |
ffa79828 |
203 | for (i = 0; backends[i].backend != NULL; i++) |
204 | if (backends[i].protocol == default_protocol) { |
205 | default_port = backends[i].backend->default_port; |
206 | break; |
207 | } |
208 | } |
0c4b7799 |
209 | flags = FLAG_INTERACTIVE; |
210 | |
fc34fbaf |
211 | #if !TARGET_API_MAC_CARBON |
bf873e8e |
212 | { |
213 | short vol; |
214 | long dirid; |
215 | |
216 | /* Set the default directory for loading and saving settings. */ |
217 | /* XXX Should we create it? */ |
218 | if (get_session_dir(FALSE, &vol, &dirid) == noErr) { |
219 | LMSetSFSaveDisk(-vol); |
220 | LMSetCurDirStore(dirid); |
221 | } |
222 | } |
fc34fbaf |
223 | #endif |
97cfddb2 |
224 | |
225 | /* Install Apple Event handlers. */ |
d70e3b83 |
226 | AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, |
227 | NewAEEventHandlerUPP(&mac_aevt_oapp), 0, FALSE); |
228 | AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, |
229 | NewAEEventHandlerUPP(&mac_aevt_odoc), 0, FALSE); |
230 | AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, |
231 | NewAEEventHandlerUPP(&mac_aevt_pdoc), 0, FALSE); |
97cfddb2 |
232 | AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, |
233 | NewAEEventHandlerUPP(&mac_aevt_quit), 0, FALSE); |
d082ac49 |
234 | } |
235 | |
236 | static void mac_eventloop(void) { |
237 | Boolean gotevent; |
238 | EventRecord event; |
239 | RgnHandle cursrgn; |
240 | |
241 | cursrgn = NewRgn(); |
242 | for (;;) { |
243 | mac_adjustcursor(cursrgn); |
244 | gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, cursrgn); |
245 | mac_adjustcursor(cursrgn); |
246 | if (gotevent) |
247 | mac_event(&event); |
97cfddb2 |
248 | if (borednow) |
249 | cleanup_exit(0); |
f6fc0010 |
250 | sk_poll(); |
0c4b7799 |
251 | mac_pollterm(); |
d082ac49 |
252 | } |
253 | DisposeRgn(cursrgn); |
254 | } |
255 | |
256 | static void mac_event(EventRecord *event) { |
257 | short part; |
258 | WindowPtr window; |
d082ac49 |
259 | |
260 | switch (event->what) { |
261 | case mouseDown: |
262 | part = FindWindow(event->where, &window); |
263 | switch (part) { |
264 | case inMenuBar: |
265 | mac_adjustmenus(); |
266 | mac_menucommand(MenuSelect(event->where)); |
267 | break; |
fc34fbaf |
268 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
269 | case inSysWindow: |
270 | SystemClick(event, window); |
271 | break; |
fc34fbaf |
272 | #endif |
d082ac49 |
273 | case inContent: |
274 | if (window != FrontWindow()) |
275 | /* XXX: check for movable modal dboxes? */ |
276 | SelectWindow(window); |
277 | else |
278 | mac_contentclick(window, event); |
279 | break; |
280 | case inGoAway: |
281 | if (TrackGoAway(window, event->where)) |
282 | mac_closewindow(window); |
283 | break; |
284 | case inDrag: |
285 | /* XXX: moveable modal check? */ |
fc34fbaf |
286 | #if TARGET_API_MAC_CARBON |
287 | { |
288 | BitMap screenBits; |
289 | |
290 | GetQDGlobalsScreenBits(&screenBits); |
291 | DragWindow(window, event->where, &screenBits.bounds); |
292 | } |
293 | #else |
d082ac49 |
294 | DragWindow(window, event->where, &qd.screenBits.bounds); |
fc34fbaf |
295 | #endif |
d082ac49 |
296 | break; |
297 | case inGrow: |
298 | mac_growwindow(window, event); |
299 | break; |
300 | case inZoomIn: |
301 | case inZoomOut: |
302 | if (TrackBox(window, event->where, part)) |
303 | mac_zoomwindow(window, part); |
304 | break; |
305 | } |
306 | break; |
307 | case keyDown: |
308 | case autoKey: |
309 | mac_keypress(event); |
310 | break; |
311 | case activateEvt: |
312 | mac_activatewindow((WindowPtr)event->message, event); |
313 | break; |
314 | case updateEvt: |
315 | mac_updatewindow((WindowPtr)event->message); |
316 | break; |
fc34fbaf |
317 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
318 | case diskEvt: |
319 | if (HiWord(event->message) != noErr) { |
fc34fbaf |
320 | Point pt; |
321 | |
d082ac49 |
322 | SetPt(&pt, 120, 120); |
323 | DIBadMount(pt, event->message); |
324 | } |
325 | break; |
fc34fbaf |
326 | #endif |
97cfddb2 |
327 | case kHighLevelEvent: |
328 | AEProcessAppleEvent(event); /* errors? */ |
329 | break; |
d082ac49 |
330 | } |
331 | } |
332 | |
333 | static void mac_contentclick(WindowPtr window, EventRecord *event) { |
334 | short item; |
fc34fbaf |
335 | DialogRef dialog; |
d082ac49 |
336 | |
337 | switch (mac_windowtype(window)) { |
338 | case wTerminal: |
339 | mac_clickterm(window, event); |
340 | break; |
341 | case wAbout: |
fc34fbaf |
342 | dialog = GetDialogFromWindow(window); |
343 | if (DialogSelect(event, &dialog, &item)) |
d082ac49 |
344 | switch (item) { |
345 | case wiAboutLicence: |
ebd78b62 |
346 | mac_openlicence(); |
d082ac49 |
347 | break; |
348 | } |
349 | break; |
6cb61a05 |
350 | case wSettings: |
351 | mac_clickdlg(window, event); |
352 | break; |
7dcd1f87 |
353 | case wEventLog: |
354 | mac_clickeventlog(window, event); |
355 | break; |
d082ac49 |
356 | } |
357 | } |
358 | |
359 | static void mac_growwindow(WindowPtr window, EventRecord *event) { |
360 | |
361 | switch (mac_windowtype(window)) { |
362 | case wTerminal: |
363 | mac_growterm(window, event); |
7dcd1f87 |
364 | break; |
365 | case wEventLog: |
366 | mac_groweventlog(window, event); |
367 | break; |
d082ac49 |
368 | } |
369 | } |
370 | |
371 | static void mac_activatewindow(WindowPtr window, EventRecord *event) { |
372 | int active; |
373 | |
374 | active = (event->modifiers & activeFlag) != 0; |
375 | mac_adjustmenus(); |
376 | switch (mac_windowtype(window)) { |
377 | case wTerminal: |
378 | mac_activateterm(window, active); |
379 | break; |
6cb61a05 |
380 | case wSettings: |
381 | mac_activatedlg(window, event); |
382 | break; |
d082ac49 |
383 | case wAbout: |
384 | mac_activateabout(window, event); |
385 | break; |
7dcd1f87 |
386 | case wEventLog: |
387 | mac_activateeventlog(window, event); |
388 | break; |
d082ac49 |
389 | } |
390 | } |
391 | |
392 | static void mac_activateabout(WindowPtr window, EventRecord *event) { |
fc34fbaf |
393 | DialogRef dialog; |
d082ac49 |
394 | DialogItemType itemtype; |
395 | Handle itemhandle; |
396 | short item; |
397 | Rect itemrect; |
398 | int active; |
399 | |
fc34fbaf |
400 | dialog = GetDialogFromWindow(window); |
d082ac49 |
401 | active = (event->modifiers & activeFlag) != 0; |
fc34fbaf |
402 | GetDialogItem(dialog, wiAboutLicence, &itemtype, &itemhandle, &itemrect); |
d082ac49 |
403 | HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); |
fc34fbaf |
404 | DialogSelect(event, &dialog, &item); |
d082ac49 |
405 | } |
406 | |
fc34fbaf |
407 | static void mac_updatewindow(WindowPtr window) |
408 | { |
409 | #if TARGET_API_MAC_CARBON |
410 | RgnHandle rgn; |
411 | #endif |
d082ac49 |
412 | |
413 | switch (mac_windowtype(window)) { |
414 | case wTerminal: |
415 | mac_updateterm(window); |
416 | break; |
417 | case wAbout: |
6cb61a05 |
418 | case wSettings: |
d082ac49 |
419 | BeginUpdate(window); |
fc34fbaf |
420 | #if TARGET_API_MAC_CARBON |
421 | rgn = NewRgn(); |
422 | GetPortVisibleRegion(GetWindowPort(window), rgn); |
423 | UpdateDialog(GetDialogFromWindow(window), rgn); |
424 | DisposeRgn(rgn); |
425 | #else |
d082ac49 |
426 | UpdateDialog(window, window->visRgn); |
fc34fbaf |
427 | #endif |
d082ac49 |
428 | EndUpdate(window); |
429 | break; |
430 | case wLicence: |
ebd78b62 |
431 | mac_updatelicence(window); |
432 | break; |
7dcd1f87 |
433 | case wEventLog: |
434 | mac_updateeventlog(window); |
435 | break; |
ebd78b62 |
436 | } |
437 | } |
438 | |
439 | static void mac_updatelicence(WindowPtr window) |
440 | { |
441 | Handle h; |
442 | int len; |
36577dc9 |
443 | long fondsize; |
fc34fbaf |
444 | Rect textrect; |
ebd78b62 |
445 | |
fc34fbaf |
446 | SetPort((GrafPtr)GetWindowPort(window)); |
ebd78b62 |
447 | BeginUpdate(window); |
36577dc9 |
448 | fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize); |
449 | TextFont(HiWord(fondsize)); |
450 | TextSize(LoWord(fondsize)); |
ebd78b62 |
451 | h = Get1Resource('TEXT', wLicence); |
452 | len = GetResourceSizeOnDisk(h); |
fc34fbaf |
453 | #if TARGET_API_MAC_CARBON |
454 | GetPortBounds(GetWindowPort(window), &textrect); |
455 | #else |
456 | textrect = window->portRect; |
457 | #endif |
ebd78b62 |
458 | if (h != NULL) { |
459 | HLock(h); |
fc34fbaf |
460 | TETextBox(*h, len, &textrect, teFlushDefault); |
ebd78b62 |
461 | HUnlock(h); |
d082ac49 |
462 | } |
ebd78b62 |
463 | EndUpdate(window); |
d082ac49 |
464 | } |
465 | |
466 | /* |
467 | * Work out what kind of window we're dealing with. |
d082ac49 |
468 | */ |
347bfcd7 |
469 | static int mac_windowtype(WindowPtr window) |
470 | { |
471 | |
472 | #if !TARGET_API_MAC_CARBON |
473 | if (GetWindowKind(window) < 0) |
d082ac49 |
474 | return wDA; |
347bfcd7 |
475 | #endif |
476 | return ((WinInfo *)GetWRefCon(window))->wtype; |
d082ac49 |
477 | } |
478 | |
479 | /* |
480 | * Handle a key press |
481 | */ |
482 | static void mac_keypress(EventRecord *event) { |
483 | WindowPtr window; |
484 | |
485 | window = FrontWindow(); |
486 | /* |
487 | * Check for a command-key combination, but ignore it if it counts |
488 | * as a meta-key combination and we're in a terminal window. |
489 | */ |
490 | if (event->what == keyDown && (event->modifiers & cmdKey) /*&& |
491 | !((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers && |
492 | mac_windowtype(window) == wTerminal)*/) { |
493 | mac_adjustmenus(); |
494 | mac_menucommand(MenuKey(event->message & charCodeMask)); |
495 | } else { |
496 | switch (mac_windowtype(window)) { |
497 | case wTerminal: |
498 | mac_keyterm(window, event); |
499 | break; |
500 | } |
501 | } |
502 | } |
503 | |
504 | static void mac_menucommand(long result) { |
505 | short menu, item; |
d082ac49 |
506 | WindowPtr window; |
fc34fbaf |
507 | #if !TARGET_API_MAC_CARBON |
508 | Str255 da; |
509 | #endif |
d082ac49 |
510 | |
511 | menu = HiWord(result); |
512 | item = LoWord(result); |
513 | window = FrontWindow(); |
514 | /* Things which do the same whatever window we're in. */ |
515 | switch (menu) { |
516 | case mApple: |
517 | switch (item) { |
518 | case iAbout: |
519 | mac_openabout(); |
520 | goto done; |
cc2be455 |
521 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
522 | default: |
523 | GetMenuItemText(GetMenuHandle(mApple), item, da); |
524 | OpenDeskAcc(da); |
525 | goto done; |
cc2be455 |
526 | #endif |
d082ac49 |
527 | } |
528 | break; |
529 | case mFile: |
530 | switch (item) { |
531 | case iNew: |
532 | mac_newsession(); |
533 | goto done; |
ce283213 |
534 | case iOpen: |
535 | mac_opensession(); |
536 | goto done; |
d082ac49 |
537 | case iClose: |
538 | mac_closewindow(window); |
539 | goto done; |
b537dd42 |
540 | case iSave: |
541 | mac_savesession(); |
542 | goto done; |
543 | case iSaveAs: |
544 | mac_savesessionas(); |
545 | goto done; |
5211281f |
546 | case iDuplicate: |
547 | mac_dupsession(); |
548 | goto done; |
d082ac49 |
549 | case iQuit: |
0c4b7799 |
550 | cleanup_exit(0); |
d082ac49 |
551 | goto done; |
552 | } |
553 | break; |
554 | } |
555 | /* If we get here, handling is up to window-specific code. */ |
556 | switch (mac_windowtype(window)) { |
557 | case wTerminal: |
558 | mac_menuterm(window, menu, item); |
559 | break; |
560 | } |
561 | done: |
562 | HiliteMenu(0); |
563 | } |
564 | |
565 | static void mac_openabout(void) { |
566 | DialogItemType itemtype; |
567 | Handle item; |
568 | VersRecHndl vers; |
569 | Rect box; |
570 | StringPtr longvers; |
347bfcd7 |
571 | WinInfo *wi; |
d082ac49 |
572 | |
573 | if (windows.about) |
574 | SelectWindow(windows.about); |
575 | else { |
fc34fbaf |
576 | windows.about = |
577 | GetDialogWindow(GetNewDialog(wAbout, NULL, (WindowPtr)-1)); |
347bfcd7 |
578 | wi = smalloc(sizeof(*wi)); |
579 | wi->s = NULL; |
580 | wi->wtype = wAbout; |
581 | SetWRefCon(windows.about, (long)wi); |
5dbc118e |
582 | vers = (VersRecHndl)Get1Resource('vers', 1); |
583 | if (vers != NULL && *vers != NULL) { |
584 | longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1; |
fc34fbaf |
585 | GetDialogItem(GetDialogFromWindow(windows.about), wiAboutVersion, |
5dbc118e |
586 | &itemtype, &item, &box); |
587 | assert(itemtype & kStaticTextDialogItem); |
588 | SetDialogItemText(item, longvers); |
589 | } |
d082ac49 |
590 | ShowWindow(windows.about); |
591 | } |
592 | } |
593 | |
ebd78b62 |
594 | static void mac_openlicence(void) { |
347bfcd7 |
595 | WinInfo *wi; |
ebd78b62 |
596 | |
597 | if (windows.licence) |
598 | SelectWindow(windows.licence); |
599 | else { |
600 | windows.licence = GetNewWindow(wLicence, NULL, (WindowPtr)-1); |
347bfcd7 |
601 | wi = smalloc(sizeof(*wi)); |
602 | wi->s = NULL; |
603 | wi->wtype = wLicence; |
604 | SetWRefCon(windows.licence, (long)wi); |
ebd78b62 |
605 | ShowWindow(windows.licence); |
606 | } |
607 | } |
608 | |
d082ac49 |
609 | static void mac_closewindow(WindowPtr window) { |
610 | |
611 | switch (mac_windowtype(window)) { |
fc34fbaf |
612 | #if !TARGET_API_MAC_CARBON |
d082ac49 |
613 | case wDA: |
347bfcd7 |
614 | CloseDeskAcc(GetWindowKind(window)); |
d082ac49 |
615 | break; |
fc34fbaf |
616 | #endif |
d082ac49 |
617 | case wTerminal: |
fabd1805 |
618 | mac_closeterm(window); |
d082ac49 |
619 | break; |
620 | case wAbout: |
621 | windows.about = NULL; |
fc34fbaf |
622 | DisposeDialog(GetDialogFromWindow(window)); |
d082ac49 |
623 | break; |
ebd78b62 |
624 | case wLicence: |
625 | windows.licence = NULL; |
fabd1805 |
626 | DisposeWindow(window); |
d082ac49 |
627 | break; |
628 | } |
629 | } |
630 | |
631 | static void mac_zoomwindow(WindowPtr window, short part) { |
632 | |
633 | /* FIXME: do something */ |
634 | } |
635 | |
636 | /* |
637 | * Make the menus look right before the user gets to see them. |
638 | */ |
fc34fbaf |
639 | #if TARGET_API_MAC_CARBON |
fc34fbaf |
640 | #define EnableItem EnableMenuItem |
641 | #define DisableItem DisableMenuItem |
642 | #endif |
d082ac49 |
643 | static void mac_adjustmenus(void) { |
644 | WindowPtr window; |
645 | MenuHandle menu; |
646 | |
647 | window = FrontWindow(); |
648 | menu = GetMenuHandle(mApple); |
649 | EnableItem(menu, 0); |
650 | EnableItem(menu, iAbout); |
651 | |
652 | menu = GetMenuHandle(mFile); |
653 | EnableItem(menu, 0); |
654 | EnableItem(menu, iNew); |
655 | if (window != NULL) |
656 | EnableItem(menu, iClose); |
657 | else |
658 | DisableItem(menu, iClose); |
659 | EnableItem(menu, iQuit); |
660 | |
661 | switch (mac_windowtype(window)) { |
b537dd42 |
662 | case wSettings: |
663 | DisableItem(menu, iSave); /* XXX enable if modified */ |
664 | EnableItem(menu, iSaveAs); |
5211281f |
665 | EnableItem(menu, iDuplicate); |
b537dd42 |
666 | menu = GetMenuHandle(mEdit); |
667 | DisableItem(menu, 0); |
668 | break; |
d082ac49 |
669 | case wTerminal: |
670 | mac_adjusttermmenus(window); |
671 | break; |
672 | default: |
b537dd42 |
673 | DisableItem(menu, iSave); |
674 | DisableItem(menu, iSaveAs); |
5211281f |
675 | DisableItem(menu, iDuplicate); |
d082ac49 |
676 | menu = GetMenuHandle(mEdit); |
677 | DisableItem(menu, 0); |
7dcd1f87 |
678 | menu = GetMenuHandle(mWindow); |
679 | DisableItem(menu, 0); /* Until we get more than 1 item on it. */ |
d082ac49 |
680 | break; |
681 | } |
682 | DrawMenuBar(); |
683 | } |
684 | |
685 | /* |
686 | * Make sure the right cursor's being displayed. |
687 | */ |
688 | static void mac_adjustcursor(RgnHandle cursrgn) { |
689 | Point mouse; |
690 | WindowPtr window, front; |
691 | short part; |
fc34fbaf |
692 | #if TARGET_API_MAC_CARBON |
693 | Cursor arrow; |
694 | RgnHandle visrgn; |
695 | #endif |
d082ac49 |
696 | |
697 | GetMouse(&mouse); |
698 | LocalToGlobal(&mouse); |
699 | part = FindWindow(mouse, &window); |
700 | front = FrontWindow(); |
701 | if (part != inContent || window == NULL || window != front) { |
702 | /* Cursor isn't in the front window, so switch to arrow */ |
fc34fbaf |
703 | #if TARGET_API_MAC_CARBON |
704 | GetQDGlobalsArrow(&arrow); |
705 | SetCursor(&arrow); |
706 | #else |
d082ac49 |
707 | SetCursor(&qd.arrow); |
fc34fbaf |
708 | #endif |
d082ac49 |
709 | SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); |
fc34fbaf |
710 | if (front != NULL) { |
711 | #if TARGET_API_MAC_CARBON |
712 | visrgn = NewRgn(); |
713 | GetPortVisibleRegion(GetWindowPort(front), visrgn); |
714 | DiffRgn(cursrgn, visrgn, cursrgn); |
715 | DisposeRgn(visrgn); |
716 | #else |
d082ac49 |
717 | DiffRgn(cursrgn, front->visRgn, cursrgn); |
fc34fbaf |
718 | #endif |
719 | } |
d082ac49 |
720 | } else { |
721 | switch (mac_windowtype(window)) { |
722 | case wTerminal: |
723 | mac_adjusttermcursor(window, mouse, cursrgn); |
724 | break; |
725 | default: |
fc34fbaf |
726 | #if TARGET_API_MAC_CARBON |
727 | GetQDGlobalsArrow(&arrow); |
728 | SetCursor(&arrow); |
729 | GetPortVisibleRegion(GetWindowPort(window), cursrgn); |
730 | #else |
d082ac49 |
731 | SetCursor(&qd.arrow); |
732 | CopyRgn(window->visRgn, cursrgn); |
fc34fbaf |
733 | #endif |
d082ac49 |
734 | break; |
735 | } |
736 | } |
737 | } |
738 | |
d70e3b83 |
739 | pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply, |
97cfddb2 |
740 | long refcon) |
741 | { |
d70e3b83 |
742 | DescType type; |
743 | Size size; |
744 | |
745 | if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard, |
746 | &type, NULL, 0, &size) == noErr) |
747 | return errAEParamMissed; |
97cfddb2 |
748 | |
749 | borednow = 1; |
750 | return noErr; |
751 | } |
752 | |
0c4b7799 |
753 | void cleanup_exit(int status) |
754 | { |
d082ac49 |
755 | |
713b8b7a |
756 | #if !TARGET_RT_MAC_CFM |
8768ce31 |
757 | if (mac_gestalts.encvvers != 0) |
758 | TerminateUnicodeConverter(); |
713b8b7a |
759 | #endif |
27a3458f |
760 | sk_cleanup(); |
0c4b7799 |
761 | exit(status); |
d082ac49 |
762 | } |
763 | |
2beb0fb0 |
764 | /* This should only kill the current session, not the whole application. */ |
765 | void connection_fatal(void *fontend, char *fmt, ...) { |
766 | va_list ap; |
767 | Str255 stuff; |
768 | |
769 | va_start(ap, fmt); |
770 | /* We'd like stuff to be a Pascal string */ |
771 | stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap); |
772 | va_end(ap); |
773 | ParamText(stuff, NULL, NULL, NULL); |
774 | StopAlert(128, NULL); |
04b0fa02 |
775 | cleanup_exit(1); |
2beb0fb0 |
776 | } |
777 | |
0c4b7799 |
778 | /* Null SSH agent client -- never finds an agent. */ |
779 | |
780 | int agent_exists(void) |
781 | { |
782 | |
783 | return FALSE; |
784 | } |
785 | |
786 | void agent_query(void *in, int inlen, void **out, int *outlen) |
787 | { |
788 | |
789 | *out = NULL; |
790 | *outlen = 0; |
791 | } |
792 | |
793 | /* Temporary null routines for testing. */ |
794 | |
795 | void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, |
796 | char *keystr, char *fingerprint) |
797 | { |
798 | |
799 | } |
800 | |
801 | void askcipher(void *frontend, char *ciphername, int cs) |
802 | { |
803 | |
804 | } |
805 | |
806 | void old_keyfile_warning(void) |
807 | { |
808 | |
809 | } |
810 | |
e3c5b245 |
811 | FontSpec platform_default_fontspec(char const *name) |
5a9eb105 |
812 | { |
9a30e26b |
813 | FontSpec ret; |
a499fbf9 |
814 | long smfs; |
a499fbf9 |
815 | |
816 | if (!strcmp(name, "Font")) { |
817 | smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize); |
818 | if (smfs == 0) |
819 | smfs = GetScriptVariable(smRoman, smScriptMonoFondSize); |
820 | if (smfs != 0) { |
e3c5b245 |
821 | GetFontName(HiWord(smfs), ret.name); |
822 | if (ret.name[0] == 0) |
823 | memcpy(ret.name, "\pMonaco", 7); |
824 | ret.size = LoWord(smfs); |
9a30e26b |
825 | } else { |
e3c5b245 |
826 | memcpy(ret.name, "\pMonaco", 7); |
827 | ret.size = 9; |
9a30e26b |
828 | } |
e3c5b245 |
829 | ret.face = 0; |
9a30e26b |
830 | } else { |
e3c5b245 |
831 | ret.name[0] = 0; |
a499fbf9 |
832 | } |
9a30e26b |
833 | |
834 | return ret; |
835 | } |
836 | |
837 | Filename platform_default_filename(const char *name) |
838 | { |
839 | Filename ret; |
840 | if (!strcmp(name, "LogFileName")) |
02cf4001 |
841 | FSMakeFSSpec(0, 0, "\pputty.log", &ret.fss); |
9a30e26b |
842 | else |
02cf4001 |
843 | memset(&ret, 0, sizeof(ret)); |
9a30e26b |
844 | return ret; |
845 | } |
846 | |
847 | char *platform_default_s(char const *name) |
848 | { |
5a9eb105 |
849 | return NULL; |
850 | } |
851 | |
f5d2d791 |
852 | int platform_default_i(char const *name, int def) |
5a9eb105 |
853 | { |
a499fbf9 |
854 | |
5a9eb105 |
855 | /* Non-raw cut and paste of line-drawing chars works badly on the |
856 | * current Unix stub implementation of the Unicode functions. |
857 | * So I'm going to temporarily set the default to raw mode so |
858 | * that the failure mode isn't quite so drastically horrid. |
859 | * When Unicode comes in, this can all be put right. */ |
860 | if (!strcmp(name, "RawCNP")) |
861 | return 1; |
862 | return def; |
863 | } |
864 | |
e0e7dff8 |
865 | void platform_get_x11_auth(char *display, int *proto, |
866 | unsigned char *data, int *datalen) |
867 | { |
868 | /* SGT: I have no idea whether Mac X servers need anything here. */ |
869 | } |
870 | |
d082ac49 |
871 | /* |
872 | * Local Variables: |
873 | * c-file-style: "simon" |
874 | * End: |
875 | */ |