Be careful not to try to get information from windows we don't own, or that
[u/mdw/putty] / mac / macpgkey.c
CommitLineData
217b88d1 1/* $Id: macpgkey.c,v 1.2 2003/02/16 14:27:37 ben Exp $ */
ef394767 2/*
3 * Copyright (c) 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/* Stuff to handle the key window in PuTTYgen */
29
30#include <MacTypes.h>
31#include <Dialogs.h>
32#include <MacWindows.h>
33
34#include "putty.h"
35#include "mac.h"
36#include "macpgrid.h"
37
217b88d1 38static void mac_clickkey(WindowPtr window, EventRecord *event)
39{
40 short item;
41 DialogRef dialog;
42
43 dialog = GetDialogFromWindow(window);
44 if (DialogSelect(event, &dialog, &item))
45 switch (item) {
46 case wiKeyGenerate:
47 /* Do something */
48 break;
49 }
50}
51
52static void mac_activatekey(WindowPtr window, EventRecord *event)
53{
54 DialogRef dialog;
55 DialogItemType itemtype;
56 Handle itemhandle;
57 short item;
58 Rect itemrect;
59 int active;
60
61 dialog = GetDialogFromWindow(window);
62 active = (event->modifiers & activeFlag) != 0;
63 GetDialogItem(dialog, wiKeyGenerate, &itemtype, &itemhandle, &itemrect);
64 HiliteControl((ControlHandle)itemhandle, active ? 0 : 255);
65 DialogSelect(event, &dialog, &item);
66}
67
68static void mac_updatekey(WindowPtr window)
69{
70#if TARGET_API_MAC_CARBON
71 RgnHandle rgn;
72#endif
73
74 BeginUpdate(window);
75#if TARGET_API_MAC_CARBON
76 rgn = NewRgn();
77 GetPortVisibleRegion(GetWindowPort(window), rgn);
78 UpdateDialog(GetDialogFromWindow(window), rgn);
79 DisposeRgn(rgn);
80#else
81 UpdateDialog(window, window->visRgn);
82#endif
83 EndUpdate(window);
84}
85
ef394767 86void mac_newkey(void)
87{
88 KeyState *ks;
89 WinInfo *wi;
90
91 ks = smalloc(sizeof(*ks));
92 ks->box = GetNewDialog(wKey, NULL, (WindowPtr)-1);
93 wi = smalloc(sizeof(*wi));
94 memset(wi, 0, sizeof(*wi));
95 wi->ks = ks;
96 wi->wtype = wKey;
217b88d1 97 wi->update = &mac_updatekey;
98 wi->click = &mac_clickkey;
99 wi->activate = &mac_activatekey;
100 SetWRefCon(GetDialogWindow(ks->box), (long)wi);
101 ShowWindow(GetDialogWindow(ks->box));
ef394767 102}
103
104/*
105 * Local Variables:
106 * c-file-style: "simon"
107 * End:
108 */