| 1 | /* $Id: macdlg.c,v 1.3 2003/01/18 16:54:25 ben Exp $ */ |
| 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> |
| 34 | #include <StandardFile.h> |
| 35 | #include <Windows.h> |
| 36 | |
| 37 | #include <string.h> |
| 38 | |
| 39 | #include "putty.h" |
| 40 | #include "mac.h" |
| 41 | #include "macresid.h" |
| 42 | #include "storage.h" |
| 43 | |
| 44 | void mac_newsession(void) |
| 45 | { |
| 46 | Session *s; |
| 47 | |
| 48 | /* This should obviously be initialised by other means */ |
| 49 | s = smalloc(sizeof(*s)); |
| 50 | memset(s, 0, sizeof(*s)); |
| 51 | do_defaults(NULL, &s->cfg); |
| 52 | s->back = &loop_backend; |
| 53 | |
| 54 | s->settings_window = GetNewDialog(wSettings, NULL, (WindowPtr)-1); |
| 55 | |
| 56 | SetWRefCon(s->settings_window, (long)s); |
| 57 | ShowWindow(s->settings_window); |
| 58 | } |
| 59 | |
| 60 | void mac_opensession(void) { |
| 61 | Session *s; |
| 62 | StandardFileReply sfr; |
| 63 | static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; |
| 64 | void *sesshandle; |
| 65 | int i; |
| 66 | |
| 67 | s = smalloc(sizeof(*s)); |
| 68 | memset(s, 0, sizeof(*s)); |
| 69 | |
| 70 | StandardGetFile(NULL, 1, sftypes, &sfr); |
| 71 | if (!sfr.sfGood) goto fail; |
| 72 | |
| 73 | sesshandle = open_settings_r_fsp(&sfr.sfFile); |
| 74 | if (sesshandle == NULL) goto fail; |
| 75 | load_open_settings(sesshandle, TRUE, &s->cfg); |
| 76 | close_settings_r(sesshandle); |
| 77 | |
| 78 | /* |
| 79 | * Select protocol. This is farmed out into a table in a |
| 80 | * separate file to enable an ssh-free variant. |
| 81 | */ |
| 82 | s->back = NULL; |
| 83 | for (i = 0; backends[i].backend != NULL; i++) |
| 84 | if (backends[i].protocol == s->cfg.protocol) { |
| 85 | s->back = backends[i].backend; |
| 86 | break; |
| 87 | } |
| 88 | if (s->back == NULL) { |
| 89 | fatalbox("Unsupported protocol number found"); |
| 90 | } |
| 91 | mac_startsession(s); |
| 92 | return; |
| 93 | |
| 94 | fail: |
| 95 | sfree(s); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | void mac_activatedlg(WindowPtr window, EventRecord *event) |
| 100 | { |
| 101 | DialogItemType itemtype; |
| 102 | Handle itemhandle; |
| 103 | short item; |
| 104 | Rect itemrect; |
| 105 | int active; |
| 106 | |
| 107 | active = (event->modifiers & activeFlag) != 0; |
| 108 | GetDialogItem(window, wiSettingsOpen, &itemtype, &itemhandle, &itemrect); |
| 109 | HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); |
| 110 | DialogSelect(event, &window, &item); |
| 111 | } |
| 112 | |
| 113 | void mac_clickdlg(WindowPtr window, EventRecord *event) |
| 114 | { |
| 115 | short item; |
| 116 | Session *s = (Session *)GetWRefCon(window); |
| 117 | |
| 118 | if (DialogSelect(event, &window, &item)) |
| 119 | switch (item) { |
| 120 | case wiSettingsOpen: |
| 121 | CloseWindow(window); |
| 122 | mac_startsession(s); |
| 123 | break; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Local Variables: |
| 129 | * c-file-style: "simon" |
| 130 | * End: |
| 131 | */ |