b537dd42 |
1 | /* $Id: macdlg.c,v 1.4 2003/01/18 20:09:21 ben Exp $ */ |
6cb61a05 |
2 | /* |
3 | * Copyright (c) 2002 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 | /* |
29 | * macdlg.c - settings dialogue box for Mac OS. |
30 | */ |
31 | |
32 | #include <MacTypes.h> |
33 | #include <Dialogs.h> |
b537dd42 |
34 | #include <Resources.h> |
2b8dca9e |
35 | #include <StandardFile.h> |
6cb61a05 |
36 | #include <Windows.h> |
37 | |
38 | #include <string.h> |
39 | |
40 | #include "putty.h" |
41 | #include "mac.h" |
42 | #include "macresid.h" |
2b8dca9e |
43 | #include "storage.h" |
6cb61a05 |
44 | |
45 | void mac_newsession(void) |
46 | { |
47 | Session *s; |
48 | |
49 | /* This should obviously be initialised by other means */ |
50 | s = smalloc(sizeof(*s)); |
51 | memset(s, 0, sizeof(*s)); |
52 | do_defaults(NULL, &s->cfg); |
53 | s->back = &loop_backend; |
54 | |
55 | s->settings_window = GetNewDialog(wSettings, NULL, (WindowPtr)-1); |
56 | |
57 | SetWRefCon(s->settings_window, (long)s); |
58 | ShowWindow(s->settings_window); |
59 | } |
60 | |
2b8dca9e |
61 | void mac_opensession(void) { |
62 | Session *s; |
63 | StandardFileReply sfr; |
64 | static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; |
65 | void *sesshandle; |
66 | int i; |
67 | |
68 | s = smalloc(sizeof(*s)); |
69 | memset(s, 0, sizeof(*s)); |
70 | |
71 | StandardGetFile(NULL, 1, sftypes, &sfr); |
72 | if (!sfr.sfGood) goto fail; |
73 | |
74 | sesshandle = open_settings_r_fsp(&sfr.sfFile); |
75 | if (sesshandle == NULL) goto fail; |
76 | load_open_settings(sesshandle, TRUE, &s->cfg); |
77 | close_settings_r(sesshandle); |
78 | |
79 | /* |
80 | * Select protocol. This is farmed out into a table in a |
81 | * separate file to enable an ssh-free variant. |
82 | */ |
83 | s->back = NULL; |
84 | for (i = 0; backends[i].backend != NULL; i++) |
85 | if (backends[i].protocol == s->cfg.protocol) { |
86 | s->back = backends[i].backend; |
87 | break; |
88 | } |
89 | if (s->back == NULL) { |
90 | fatalbox("Unsupported protocol number found"); |
91 | } |
92 | mac_startsession(s); |
93 | return; |
94 | |
95 | fail: |
96 | sfree(s); |
97 | return; |
98 | } |
99 | |
b537dd42 |
100 | void mac_savesession(void) |
101 | { |
102 | |
103 | /* Don't remember which file a session goes with yet, so... */ |
104 | mac_savesessionas(); |
105 | } |
106 | |
107 | void mac_savesessionas(void) |
108 | { |
109 | Session *s = (Session *)GetWRefCon(FrontWindow()); |
110 | StandardFileReply sfr; |
111 | void *sesshandle; |
112 | |
113 | StandardPutFile("\pSave session as:", "\puntitled", &sfr); |
114 | if (!sfr.sfGood) return; |
115 | |
116 | if (!sfr.sfReplacing) { |
117 | FSpCreateResFile(&sfr.sfFile, PUTTY_CREATOR, SESS_TYPE, sfr.sfScript); |
118 | if (ResError() != noErr) return; /* XXX report error */ |
119 | } |
120 | sesshandle = open_settings_w_fsp(&sfr.sfFile); |
121 | if (sesshandle == NULL) return; /* XXX report error */ |
122 | save_open_settings(sesshandle, TRUE, &s->cfg); |
123 | close_settings_w(sesshandle); |
124 | } |
125 | |
6cb61a05 |
126 | void mac_activatedlg(WindowPtr window, EventRecord *event) |
127 | { |
128 | DialogItemType itemtype; |
129 | Handle itemhandle; |
130 | short item; |
131 | Rect itemrect; |
132 | int active; |
133 | |
134 | active = (event->modifiers & activeFlag) != 0; |
135 | GetDialogItem(window, wiSettingsOpen, &itemtype, &itemhandle, &itemrect); |
136 | HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); |
137 | DialogSelect(event, &window, &item); |
138 | } |
139 | |
140 | void mac_clickdlg(WindowPtr window, EventRecord *event) |
141 | { |
142 | short item; |
143 | Session *s = (Session *)GetWRefCon(window); |
144 | |
34e9a202 |
145 | if (DialogSelect(event, &window, &item)) |
6cb61a05 |
146 | switch (item) { |
147 | case wiSettingsOpen: |
148 | CloseWindow(window); |
149 | mac_startsession(s); |
150 | break; |
151 | } |
152 | } |
153 | |
154 | /* |
155 | * Local Variables: |
156 | * c-file-style: "simon" |
157 | * End: |
158 | */ |