34773273 |
1 | /* $Id: macabout.c,v 1.3 2003/03/29 23:07:55 ben Exp $ */ |
f854b482 |
2 | /* |
3 | * Copyright (c) 1999, 2002, 2003 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 | #include <MacTypes.h> |
29 | #include <Dialogs.h> |
30 | #include <MacWindows.h> |
31 | #include <Resources.h> |
32 | #include <Script.h> |
33 | #include <ToolUtils.h> |
34 | |
35 | #include <assert.h> |
36 | #include <stdlib.h> |
37 | |
38 | #include "putty.h" |
39 | #include "mac.h" |
40 | #include "macresid.h" |
41 | |
42 | static struct mac_windows { |
43 | WindowPtr about; |
44 | WindowPtr licence; |
45 | } windows; |
46 | |
47 | static void mac_openlicence(void); |
48 | |
49 | static void mac_clickabout(WindowPtr window, EventRecord *event) |
50 | { |
51 | short item; |
52 | DialogRef dialog; |
53 | |
54 | dialog = GetDialogFromWindow(window); |
55 | if (DialogSelect(event, &dialog, &item)) |
56 | switch (item) { |
57 | case wiAboutLicence: |
58 | mac_openlicence(); |
59 | break; |
60 | } |
61 | } |
62 | |
63 | static void mac_activateabout(WindowPtr window, EventRecord *event) |
64 | { |
65 | DialogRef dialog; |
66 | DialogItemType itemtype; |
67 | Handle itemhandle; |
68 | short item; |
69 | Rect itemrect; |
70 | int active; |
71 | |
72 | dialog = GetDialogFromWindow(window); |
73 | active = (event->modifiers & activeFlag) != 0; |
74 | GetDialogItem(dialog, wiAboutLicence, &itemtype, &itemhandle, &itemrect); |
75 | HiliteControl((ControlHandle)itemhandle, active ? 0 : 255); |
76 | DialogSelect(event, &dialog, &item); |
77 | } |
78 | |
79 | static void mac_updateabout(WindowPtr window) |
80 | { |
81 | #if TARGET_API_MAC_CARBON |
82 | RgnHandle rgn; |
83 | #endif |
84 | |
85 | BeginUpdate(window); |
86 | #if TARGET_API_MAC_CARBON |
87 | rgn = NewRgn(); |
88 | GetPortVisibleRegion(GetWindowPort(window), rgn); |
89 | UpdateDialog(GetDialogFromWindow(window), rgn); |
90 | DisposeRgn(rgn); |
91 | #else |
92 | UpdateDialog(window, window->visRgn); |
93 | #endif |
94 | EndUpdate(window); |
95 | } |
96 | |
7902b630 |
97 | static void mac_closeabout(WindowPtr window) |
98 | { |
99 | |
100 | windows.about = NULL; |
101 | DisposeDialog(GetDialogFromWindow(window)); |
102 | } |
103 | |
f854b482 |
104 | static void mac_updatelicence(WindowPtr window) |
105 | { |
106 | Handle h; |
107 | int len; |
108 | long fondsize; |
109 | Rect textrect; |
110 | |
111 | SetPort((GrafPtr)GetWindowPort(window)); |
112 | BeginUpdate(window); |
113 | fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize); |
114 | TextFont(HiWord(fondsize)); |
115 | TextSize(LoWord(fondsize)); |
116 | h = Get1Resource('TEXT', wLicence); |
117 | len = GetResourceSizeOnDisk(h); |
118 | #if TARGET_API_MAC_CARBON |
119 | GetPortBounds(GetWindowPort(window), &textrect); |
120 | #else |
121 | textrect = window->portRect; |
122 | #endif |
123 | if (h != NULL) { |
124 | HLock(h); |
125 | TETextBox(*h, len, &textrect, teFlushDefault); |
126 | HUnlock(h); |
127 | } |
128 | EndUpdate(window); |
129 | } |
130 | |
7902b630 |
131 | static void mac_closelicence(WindowPtr window) |
132 | { |
133 | |
134 | windows.licence = NULL; |
135 | DisposeWindow(window); |
136 | } |
137 | |
f854b482 |
138 | void mac_openabout(void) |
139 | { |
140 | DialogItemType itemtype; |
141 | Handle item; |
142 | VersRecHndl vers; |
143 | Rect box; |
144 | StringPtr longvers; |
145 | WinInfo *wi; |
146 | |
147 | if (windows.about) |
148 | SelectWindow(windows.about); |
149 | else { |
150 | windows.about = |
151 | GetDialogWindow(GetNewDialog(wAbout, NULL, (WindowPtr)-1)); |
34773273 |
152 | wi = snew(WinInfo); |
f854b482 |
153 | memset(wi, 0, sizeof(*wi)); |
154 | wi->wtype = wAbout; |
155 | wi->update = &mac_updateabout; |
156 | wi->click = &mac_clickabout; |
157 | wi->activate = &mac_activateabout; |
7902b630 |
158 | wi->close = &mac_closeabout; |
f854b482 |
159 | SetWRefCon(windows.about, (long)wi); |
160 | vers = (VersRecHndl)Get1Resource('vers', 1); |
161 | if (vers != NULL && *vers != NULL) { |
162 | longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1; |
163 | GetDialogItem(GetDialogFromWindow(windows.about), wiAboutVersion, |
164 | &itemtype, &item, &box); |
165 | assert(itemtype & kStaticTextDialogItem); |
166 | SetDialogItemText(item, longvers); |
167 | } |
168 | ShowWindow(windows.about); |
169 | } |
170 | } |
171 | |
172 | static void mac_openlicence(void) |
173 | { |
174 | WinInfo *wi; |
175 | |
176 | if (windows.licence) |
177 | SelectWindow(windows.licence); |
178 | else { |
179 | windows.licence = GetNewWindow(wLicence, NULL, (WindowPtr)-1); |
34773273 |
180 | wi = snew(WinInfo); |
f854b482 |
181 | memset(wi, 0, sizeof(*wi)); |
182 | wi->wtype = wLicence; |
183 | wi->update = &mac_updatelicence; |
7902b630 |
184 | wi->close = &mac_closelicence; |
f854b482 |
185 | SetWRefCon(windows.licence, (long)wi); |
186 | ShowWindow(windows.licence); |
187 | } |
188 | } |
189 | |