1 /* $Id: macpgkey.c,v 1.5 2003/03/29 23:57:55 ben Exp $ */
3 * Copyright (c) 2003 Ben Harris
4 * Copyright (c) 1997-2003 Simon Tatham
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 /* Stuff to handle the key window in PuTTYgen */
34 #include <MacWindows.h>
41 /* ----------------------------------------------------------------------
42 * Progress report code. This is really horrible :-)
44 #define PROGRESSRANGE 65535
50 unsigned startpoint, total;
51 unsigned param, current, n; /* if exponential */
52 unsigned mult; /* if linear */
54 unsigned total, divisor, range;
55 ControlHandle progbar;
58 static void progress_update(void *param, int action, int phase, int iprogress)
60 struct progress *p = (struct progress *) param;
61 unsigned progress = iprogress;
64 if (action < PROGFN_READY && p->nphases < phase)
67 case PROGFN_INITIALISE:
70 case PROGFN_LIN_PHASE:
71 p->phases[phase-1].exponential = 0;
72 p->phases[phase-1].mult = p->phases[phase].total / progress;
74 case PROGFN_EXP_PHASE:
75 p->phases[phase-1].exponential = 1;
76 p->phases[phase-1].param = 0x10000 + progress;
77 p->phases[phase-1].current = p->phases[phase-1].total;
78 p->phases[phase-1].n = 0;
80 case PROGFN_PHASE_EXTENT:
81 p->phases[phase-1].total = progress;
87 for (i = 0; i < p->nphases; i++) {
88 p->phases[i].startpoint = total;
89 total += p->phases[i].total;
92 p->divisor = ((p->total + PROGRESSRANGE - 1) / PROGRESSRANGE);
93 p->range = p->total / p->divisor;
94 SetControlMaximum(p->progbar, p->range);
98 if (p->phases[phase-1].exponential) {
99 while (p->phases[phase-1].n < progress) {
100 p->phases[phase-1].n++;
101 p->phases[phase-1].current *= p->phases[phase-1].param;
102 p->phases[phase-1].current /= 0x10000;
104 position = (p->phases[phase-1].startpoint +
105 p->phases[phase-1].total - p->phases[phase-1].current);
107 position = (p->phases[phase-1].startpoint +
108 progress * p->phases[phase-1].mult);
110 SetControlValue(p->progbar, position / p->divisor);
115 static void mac_clickkey(WindowPtr window, EventRecord *event)
119 KeyState *ks = mac_windowkey(window);
121 dialog = GetDialogFromWindow(window);
122 if (DialogSelect(event, &dialog, &item))
125 SetControlMaximum(ks->progress, 1024);
126 ks->entropy = snewn(1024, unsigned int);
127 ks->entropy_required = 1024;
129 ks->collecting_entropy = TRUE;
135 static void mac_activatekey(WindowPtr window, EventRecord *event)
138 DialogItemType itemtype;
144 dialog = GetDialogFromWindow(window);
145 active = (event->modifiers & activeFlag) != 0;
146 GetDialogItem(dialog, wiKeyGenerate, &itemtype, &itemhandle, &itemrect);
147 HiliteControl((ControlHandle)itemhandle, active ? 0 : 255);
148 DialogSelect(event, &dialog, &item);
151 static void mac_updatekey(WindowPtr window)
153 #if TARGET_API_MAC_CARBON
158 #if TARGET_API_MAC_CARBON
160 GetPortVisibleRegion(GetWindowPort(window), rgn);
161 UpdateDialog(GetDialogFromWindow(window), rgn);
164 UpdateDialog(window, window->visRgn);
169 void mac_newkey(void)
178 ks->box = GetNewDialog(wKey, NULL, (WindowPtr)-1);
179 GetDialogItem(ks->box, wiKeyProgress, &type, &h, &rect);
180 ks->progress = (ControlHandle)h;
182 memset(wi, 0, sizeof(*wi));
185 wi->update = &mac_updatekey;
186 wi->click = &mac_clickkey;
187 wi->activate = &mac_activatekey;
188 SetWRefCon(GetDialogWindow(ks->box), (long)wi);
189 ShowWindow(GetDialogWindow(ks->box));
194 * c-file-style: "simon"