/[winpt]/trunk/Src/wptSigTreeDlg.cpp
ViewVC logotype

Annotation of /trunk/Src/wptSigTreeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 222 - (hide annotations)
Thu Jun 1 08:30:46 2006 UTC (18 years, 9 months ago) by twoaday
File size: 5031 byte(s)
Applied some more patches.


1 twoaday 176 /* wptSigTreeDlg.cpp - List signatures in a tree view
2 twoaday 175 * Copyright (C) 2006 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20    
21     #include <windows.h>
22     #include <commctrl.h>
23    
24     #include "resource.h"
25     #include "wptGPG.h"
26     #include "wptNLS.h"
27 twoaday 176 #include "wptVersion.h"
28     #include "wptTypes.h"
29     #include "wptCommonCtl.h"
30     #include "wptContext.h"
31 twoaday 188 #include "wptUTF8.h"
32 twoaday 193 #include "wptW32API.h"
33 twoaday 175
34 twoaday 180
35     /* ID to display signature properties. */
36     #define _ID_SIGCTX_PROPS 65000
37    
38    
39 twoaday 176 BOOL CALLBACK sigprops_dlg_proc (HWND dlg, UINT msg,
40     WPARAM wparam, LPARAM lparam);
41 twoaday 188 BOOL CALLBACK keysig_dlg_proc (HWND dlg, UINT msg,
42     WPARAM wparam, LPARAM lparam);
43 twoaday 176
44 twoaday 175 /* Initialize the signature tree based on the given key @key. */
45     static void
46 twoaday 208 sigtree_load (HWND dlg, winpt_key_t key)
47 twoaday 175 {
48     TVITEM tvi;
49     TVINSERTSTRUCT ctx;
50 twoaday 208 HTREEITEM uid;
51 twoaday 175 gpgme_key_sig_t s;
52 twoaday 208 winpt_key_s signer;
53     struct native_uid_s *u;
54 twoaday 175
55     memset (&tvi, 0, sizeof (tvi));
56     memset (&ctx, 0, sizeof (ctx));
57 twoaday 208 for (u=key->ext->uids; u; u = u->next) {
58 twoaday 176 if (u->revoked)
59     continue;
60 twoaday 208 tvi.pszText = u->uid;
61 twoaday 175 tvi.state = TVIS_BOLD;
62 twoaday 176 tvi.mask = TVIF_TEXT;
63     tvi.iImage = 0;
64     tvi.iSelectedImage = 0;
65 twoaday 175 ctx.hParent = TVI_ROOT;
66     ctx.item = tvi;
67     uid = TreeView_InsertItem (dlg, &ctx);
68     for (s = u->signatures; s; s=s->next) {
69 twoaday 208 memset (&signer, 0, sizeof (signer));
70     if (winpt_get_pubkey (s->keyid+8, &signer))
71 twoaday 175 continue;
72 twoaday 208 tvi.pszText = signer.ext->uids->uid;
73 twoaday 176 tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
74     tvi.iImage = 1;
75     tvi.iSelectedImage = 1;
76     tvi.lParam = (LPARAM)s;
77 twoaday 175 ctx.hParent = uid;
78     ctx.item = tvi;
79 twoaday 222 /* XXX: mark non exportable sigs */
80 twoaday 175 TreeView_InsertItem (dlg, &ctx);
81     }
82     }
83     }
84    
85    
86 twoaday 176 /* Associate a signature list based on the icons @ico with
87     the treeview control @tree. */
88     HIMAGELIST
89     treeview_set_image_list (HWND tree, HICON *ico, DWORD nicons)
90     {
91     HIMAGELIST hil;
92     DWORD i;
93    
94     hil = ImageList_Create (16, 16, ILC_COLOR8|ILC_MASK, nicons, 1);
95     ImageList_SetBkColor (hil, CLR_NONE);
96     for (i=0; i < nicons; i++)
97     ImageList_AddIcon (hil, ico[i]);
98     TreeView_SetImageList (tree, hil, TVSIL_NORMAL);
99     return hil;
100     }
101    
102    
103 twoaday 180 static void
104     create_popup (HWND dlg)
105     {
106     HMENU hm;
107     POINT p;
108    
109     hm = CreatePopupMenu ();
110     if (!hm)
111 twoaday 193 BUG (0);
112     insert_menu_item (hm, 0, _ID_SIGCTX_PROPS, _("Signature &Properties"));
113 twoaday 180 GetCursorPos (&p);
114     TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL);
115     DestroyMenu (hm);
116     }
117    
118    
119     static void
120     show_sigprops (HWND dlg)
121     {
122     HWND tree;
123     HTREEITEM hti;
124     TVITEM tvi;
125    
126     memset (&tvi, 0, sizeof (tvi));
127     tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE);
128     hti = TreeView_GetSelection (tree);
129     tvi.mask = TVIF_PARAM;
130     tvi.hItem = hti;
131     TreeView_GetItem (tree, &tvi);
132     if (tvi.lParam != 0)
133     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
134     sigprops_dlg_proc, tvi.lParam);
135     }
136    
137    
138 twoaday 175 /* Dialog box procedure for the tree based signature listing. */
139     BOOL CALLBACK
140     sigtree_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
141     {
142 twoaday 208 static winpt_key_t key;
143 twoaday 176 static HIMAGELIST hil;
144 twoaday 208 HWND tree;
145 twoaday 176 HICON ico[2];
146     NMHDR *nft;
147 twoaday 208 char inf[300];
148 twoaday 175
149     switch (msg) {
150     case WM_INITDIALOG:
151 twoaday 176 key = (winpt_key_t)lparam;
152 twoaday 175 if (!key)
153 twoaday 176 BUG (0);
154     ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_USERID);
155     ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEY_SIG);
156 twoaday 175 tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE);
157 twoaday 176 hil = treeview_set_image_list (tree, ico, 2);
158 twoaday 208 sigtree_load (tree, key);
159 twoaday 193 _snprintf (inf, sizeof (inf)-1,
160     _("Signature Tree for \"%s\" (0x%s)"),
161 twoaday 208 key->ext->uids->uid, key->ctx->subkeys->keyid+8);
162 twoaday 179 SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit..."));
163 twoaday 205 SetWindowText (dlg, inf);
164 twoaday 175 SetForegroundWindow (dlg);
165     break;
166    
167 twoaday 176 case WM_DESTROY:
168     ImageList_Destroy (hil);
169     break;
170    
171     case WM_NOTIFY:
172     nft = (NMHDR*)lparam;
173 twoaday 180 if (nft->code == NM_DBLCLK)
174     show_sigprops (dlg);
175     else if (nft->code == NM_RCLICK)
176     create_popup (dlg);
177 twoaday 176 break;
178    
179 twoaday 175 case WM_COMMAND:
180     switch (LOWORD (wparam)) {
181 twoaday 180 case _ID_SIGCTX_PROPS:
182     show_sigprops (dlg);
183     break;
184    
185 twoaday 175 case IDOK:
186     EndDialog (dlg, 1);
187     break;
188    
189     case IDCANCEL:
190     EndDialog (dlg, 0);
191     break;
192 twoaday 176
193     case IDC_VKEYSIG_EDIT:
194     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSIG, dlg,
195     keysig_dlg_proc, (LPARAM)key);
196 twoaday 175 }
197     break;
198     }
199    
200     return FALSE;
201     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26