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

Diff of /trunk/Src/wptKeyManagerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC revision 212 by twoaday, Tue May 9 10:29:07 2006 UTC
# Line 1  Line 1 
1  /* wptKeyManagerDlg.cpp - WinPT Key Manager  /* wptKeyManagerDlg.cpp - WinPT Key Manager
2   *      Copyright (C) 2000-2005 Timo Schulz   *      Copyright (C) 2000-2006 Timo Schulz
3   *      Copyright (C) 2004 Andreas Jobs   *      Copyright (C) 2004 Andreas Jobs
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
6   *   *
7   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
8   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
9   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.   * (at your option) any later version.
11   *   *
12   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.   * GNU General Public License for more details.
16   *   *
17   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
18   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
19   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20   */   */
21    #ifdef HAVE_CONFIG_H
22  #include <windows.h>  #include <config.h>
23  #include <commctrl.h>  #endif
24    
25  #include "../resource.h"  #include <windows.h>
26  #include "wptTypes.h"  #include <commctrl.h>
27  #include "wptGPG.h"  
28  #include "wptCommonCtl.h"  #include "resource.h"
29  #include "wptContext.h" /* for passphrase_s */  #include "wptTypes.h"
30  #include "wptDlgs.h"  #include "wptGPG.h"
31  #include "wptW32API.h"  #include "wptCommonCtl.h"
32  #include "wptVersion.h"  #include "wptContext.h" /* for passphrase_s */
33  #include "wptKeylist.h"  #include "wptDlgs.h"
34  #include "wptNLS.h"  #include "wptW32API.h"
35  #include "wptErrors.h"  #include "wptVersion.h"
36  #include "wptHotkey.h"  #include "wptKeylist.h"
37  #include "wptKeyManager.h"  #include "wptNLS.h"
38  #include "wptKeyserver.h"  #include "wptErrors.h"
39  #include "wptKeyEdit.h"  #include "wptHotkey.h"
40  #include "wptRegistry.h"  #include "wptKeyManager.h"
41    #include "wptKeyserver.h"
42    #include "wptKeyEdit.h"
43  #define WINDOWCLASS_SEPARATOR_CHILD "WINPT_SEP_CHILD"  #include "wptRegistry.h"
44  #define SEPARATOR_HEIGHT            5  #include "wptUTF8.h"
45    
46  void km_dump_key (gpgme_key_t key);  /* Name and ID of the separator window. */
47    #define KM_SEPARATOR_ID                 10000
48  //int treeview_add_item (HWND tree, HTREEITEM parent, const char * text);  #define WINDOWCLASS_SEPARATOR_CHILD     "WINPT_SEP_CHILD"
49    
50  static subclass_s keylist_proc;  /* Virtual key codes. */
51  static int km_index = -1;  #ifndef VK_F
52  static int km_def_pos = 0;  #define VK_F 70
53    #endif
54  HIMAGELIST glob_imagelist;  #ifndef VK_A
55    #define VK_A 65
56  struct km_info {  #endif
57      /* Window positions */  #ifndef VK_C
58      int pos_x, pos_y;  #define VK_C 67
59      int ypos_sep;  #endif
60      int ypercent_sep;  #ifndef VK_P
61    #define VK_P 80
62      HWND hwnd_sep;  #endif
63      HWND toolbar;  
64      HWND statbar;  static subclass_s keylist_proc;
65    
66      listview_ctrl_t lv;  /* Handle to the global image list. */
67      int keylist_sortby;  HIMAGELIST glob_imagelist;
68  };  
69    struct km_info_s {
70  struct mybuttons {      /* Window positions */
71      long icon;      int pos_x, pos_y;
72      long command;      int ypos_sep;
73      char *text;      int ypercent_sep;
74  };  
75        /* Different kind of windows. */
76  struct mybuttons myb[] = {      HWND dlg;
77      {IMI_KEY_DELETE, ID_KEYMISC_DELETE, "Delete"},      HWND hwnd_sep;
78      {IMI_KEY_PROPS,  ID_KEYMISC_PROPS,  "Properties"},      HWND toolbar;
79      {IMI_KEY_SIGN,   ID_KEYMISC_SIGN,   "Sign"},      HWND statbar;
80      {IMI_KEY_IMPORT, ID_KEYMISC_IMPORT, "Import"},  
81      {IMI_KEY_EXPORT, ID_KEYMISC_EXPORT, "Export"},      listview_ctrl_t lv;
82  };      int             lv_idx;
83        int keylist_sortby;
84        int magic;
85  #ifndef VK_F  
86  #define VK_F 70      unsigned int enable_groups:1;
87  #endif  };
88  #ifndef VK_A  
89  #define VK_A 65  /* Toolbar button structure. */
90  #endif  struct mybuttons {
91  #ifndef VK_C      long icon;
92  #define VK_C 67      long command;
93  #endif      char *text;
94  #ifndef VK_P  };
95  #define VK_P 80  
96  #endif  struct mybuttons myb[] = {
97        {IMI_KEY_DELETE, ID_KEYMISC_DELETE, "Delete"},
98  static BOOL CALLBACK      {IMI_KEY_PROPS,  ID_KEYMISC_PROPS,  "Properties"},
99  keylist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)      {IMI_KEY_SIGN,   ID_KEYMISC_SIGN,   "Sign"},
100  {      {IMI_KEY_IMPORT, ID_KEYMISC_IMPORT, "Import"},
101      struct listview_ctrl_s lv;      {IMI_KEY_EXPORT, ID_KEYMISC_EXPORT, "Export"},
102    };
103      switch (msg) {  
104      case WM_LBUTTONDBLCLK:  
105          send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);  static void km_gui_import (struct km_info_s *kmi, int cmd_id, void *param);
106          break;  
107            
108      case WM_KEYUP:  /* Subclass the keylist listview control to allow extended commands. */
109          int virt_key = (int)wparam;  static BOOL CALLBACK
110          switch (virt_key) {  keylist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
111          case VK_SPACE:  {
112              send_cmd_id( keylist_proc.dlg, ID_KEYMISC_PROPS );      struct listview_ctrl_s lv;
113              break;      struct km_info_s *kmi;
114            
115          case VK_DELETE:      switch (msg) {
116              send_cmd_id( keylist_proc.dlg, ID_KEYMISC_DELETE );      case WM_DROPFILES:
117              break;          kmi = (km_info_s *)keylist_proc.opaque;
118                    km_gui_import (kmi, WM_DROPFILES, (void*)wparam);
119          case VK_INSERT:          break;
120              send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE);  
121              break;      case WM_LBUTTONDBLCLK:
122            send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);
123          case VK_A:          break;
124              if (GetAsyncKeyState (VK_CONTROL)) {          
125                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);      case WM_KEYUP:
126                  listview_select_all (&lv);          int virt_key = (int)wparam;
127              }          switch (virt_key) {
128              break;          case VK_SPACE:
129                            send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);
130          case VK_C:              break;
131              if (GetAsyncKeyState (VK_CONTROL)) {          
132                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);          case VK_DELETE:
133                  km_index = listview_get_curr_pos (&lv);              send_cmd_id (keylist_proc.dlg, ID_KEYMISC_DELETE);
134                  km_clip_export (keylist_proc.dlg, &lv);              break;
135              }          
136              break;          case VK_INSERT:
137                send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE);
138          case VK_P:              break;
139              if (GetAsyncKeyState (VK_CONTROL)) {  
140                  km_index = -1;          case VK_A:
141                  km_clip_import (keylist_proc.dlg);              if (GetAsyncKeyState (VK_CONTROL)) {
142              }                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
143              break;                  listview_select_all (&lv);
144                }
145          case VK_F:              break;
146              if (GetAsyncKeyState (VK_CONTROL)) {              
147                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);          case VK_C:
148                  km_find_key (dlg, &lv);              if (GetAsyncKeyState (VK_CONTROL)) {
149              }                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
150              break;                  km_clip_export (keylist_proc.dlg, &lv);
151          }              }
152          break;              break;
153      }  
154                case VK_P:
155      return CallWindowProc( keylist_proc.old, dlg, msg, wparam, lparam );              if (GetAsyncKeyState (VK_CONTROL))
156  } /* keylist_subclass_proc */                  send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE);
157                break;
158    
159  static HWND          case VK_F:
160  load_toolbar (HWND dlg, struct km_info * kmi)              if (GetAsyncKeyState (VK_CONTROL)) {
161  {                  lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
162      HWND tbwnd;                  km_find_key (dlg, &lv);
163      TBSAVEPARAMS tbsp;              }
164      TBBUTTON tb_buttons[] = {              break;
165          /*{imagelist_getindex(IMI_EXIT),       ID_KEYMISC_QUIT,   TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0L, 0},*/          }
166          {imagelist_getindex(IMI_KEY_DELETE), ID_KEYMISC_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},          break;
167          {imagelist_getindex(IMI_KEY_PROPS),  ID_KEYMISC_PROPS,  TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},      }
168          {imagelist_getindex(IMI_KEY_SIGN),   ID_KEYMISC_SIGN,   TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},      
169          {0,                                  0,                 0,               TBSTYLE_SEP,    {0}, 0L, 0},      return CallWindowProc (keylist_proc.old, dlg, msg, wparam, lparam);
170          {imagelist_getindex(IMI_KEY_IMPORT), ID_KEYMISC_IMPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},  }
171          {imagelist_getindex(IMI_KEY_EXPORT), ID_KEYMISC_EXPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},  
172       };  
173        #define ico2idx(ico) imagelist_getindex((ico))
174      tbwnd = CreateWindowEx (0, TOOLBARCLASSNAME, NULL,  
175                              WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|CCS_ADJUSTABLE,  static HWND
176                              0, 0, 0, 0, dlg, (HMENU)IDR_WINPT_KMTB, glob_hinst, NULL);  load_toolbar (HWND dlg, struct km_info_s *kmi)
177      if (tbwnd) {  {
178          SendMessage (tbwnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);      HWND tbwnd;
179          SendMessage (tbwnd, TB_SETIMAGELIST, 0, (LPARAM)glob_imagelist);      TBSAVEPARAMS tbsp;
180                  SendMessage (tbwnd, TB_AUTOSIZE, 0, 0);      TBBUTTON tb_buttons[] = {
181          ShowWindow (tbwnd, SW_SHOW);          {ico2idx (IMI_KEY_NEW),    ID_KEYMISC_KEYWIZARD, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L},
182            {ico2idx (IMI_KEY_DELETE), ID_KEYMISC_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
183          /* Restore toolbar */          {ico2idx (IMI_KEY_PROPS),  ID_KEYMISC_PROPS,  TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
184          tbsp.hkr = HKEY_CURRENT_USER;          {ico2idx (IMI_KEY_SIGN),   ID_KEYMISC_SIGN,   TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
185          tbsp.pszSubKey = "Software\\WinPT";          {ico2idx (IMI_KEY_SEARCH), ID_KEYMISC_SENDRECV, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
186          tbsp.pszValueName = "KM_toolbar";          {0,                                  0,                 0,               TBSTYLE_SEP,    {0}, 0L, 0},
187          if (SendMessage(tbwnd, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp ) == 0)          {ico2idx (IMI_KEY_FILE_IMPORT), ID_KEYMISC_IMPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
188              SendMessage (tbwnd, TB_ADDBUTTONS, sizeof(tb_buttons) / sizeof(tb_buttons[0]), (LONG)&tb_buttons[0]);          {ico2idx (IMI_KEY_FILE_EXPORT), ID_KEYMISC_EXPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
189       }          {ico2idx (IMI_KEY_IMPORT), ID_KEYCTX_PASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
190       return tbwnd;          {ico2idx (IMI_KEY_EXPORT), ID_KEYCTX_COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
191  } /* load_toolbar */       };
192        
193        tbwnd = CreateWindowEx (0, TOOLBARCLASSNAME, NULL,
194  static void                              WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|CCS_ADJUSTABLE,
195  do_center_window (HWND dlg, struct km_info * kmi)                              0, 0, 0, 0, dlg, (HMENU)IDR_WINPT_KMTB, glob_hinst, NULL);
196  {      if (tbwnd) {
197      RECT rect;          SendMessage (tbwnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
198      char * p;          SendMessage (tbwnd, TB_SETIMAGELIST, 0, (LPARAM)glob_imagelist);
199      int pos_x = 0, pos_y = 0;                  SendMessage (tbwnd, TB_AUTOSIZE, 0, 0);
200                    ShowWindow (tbwnd, SW_SHOW);
201      /* Find bottom of keylist */  
202      GetWindowRect (GetDlgItem(dlg, IDC_KEYMISC_KEYLIST), &rect);          /* Restore toolbar */
203      MapWindowPoints (NULL, dlg, (POINT*)&rect, 2);          tbsp.hkr = HKEY_CURRENT_USER;
204            tbsp.pszSubKey = "Software\\WinPT";
205      kmi->ypos_sep = rect.bottom;          tbsp.pszValueName = "KM_toolbar";
206            if (SendMessage(tbwnd, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp ) == 0)
207      p = get_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X" );              SendMessage (tbwnd, TB_ADDBUTTONS, sizeof(tb_buttons) / sizeof(tb_buttons[0]),
208      if( p && !strcmp( p, " " ) ) {                           (LONG)&tb_buttons[0]);
209          free_if_alloc( p );           }
210          center_window( dlg );       return tbwnd;
211          return;  }
212      }  
213      else if( p )  
214          pos_x = atol( p );  /* Restore the width of the columns from the registry.
215       If no bitstring was found, the default size is used. */
216      p = get_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y" );  int
217      if( p && !strcmp( p, " " ) ) {  restore_column_info (struct km_info_s *kmi)
218          free_if_alloc( p );  {
219          center_window( dlg );      WORD *buf;
220          return;      HKEY root;
221      }      DWORD type;
222      else if( p )      DWORD size = kmi->lv->cols*sizeof (WORD), i;
223          pos_y = atol( p );      LONG ec;
224    
225      if( !pos_y && !pos_x ) {      ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\WinPT", 0,
226          center_window( dlg );                         KEY_ALL_ACCESS, &root);
227          return;      if (ec != ERROR_SUCCESS)
228      }          return -1;
229        
230      if( pos_x > GetSystemMetrics( SM_CXSCREEN )      buf = new WORD[size/2];
231          || pos_y > GetSystemMetrics( SM_CYSCREEN ) ) {      if (!buf)
232          pos_x = pos_y = 0;          BUG (NULL);
233      }      ec = RegQueryValueEx (root, "KMColumnSize", NULL, &type,
234      GetClientRect( dlg, &rect );                            (BYTE*)buf, &size);    
235      MoveWindow( dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE );      if (ec != ERROR_SUCCESS) {
236  }          RegCloseKey (root);
237            free_if_alloc (buf);
238            return -1;
239  static void      }
240  do_resize_window( HWND dlg, struct km_info *kmi)  
241  {      /* check for garbled values. */
242      HWND h;      for (i=0; i < size/2; i++) {
243      RECT rclient, rect;          if (buf[i] == 0 || buf[i] > 512) {
244      BOOL bRepaint = FALSE;              free_if_alloc (buf);
245                return -1;
246      /* Get rect of client area and make life easier */          }
247      GetClientRect( dlg, &rclient );      }
248        for (i=0; i < size/2; i++)
249      /* Move toolbar to the top of the window */          listview_set_column_width (kmi->lv, i, buf[i]);
250      if (kmi->toolbar) {      free_if_alloc (buf);
251          GetWindowRect(kmi->toolbar, &rect);  
252          ScreenToClient(dlg, (POINT*)&rect);      size = sizeof (kmi->keylist_sortby);
253          ScreenToClient(dlg, (POINT*)&(rect.right));      ec = RegQueryValueEx (root, "KMSortBy", NULL, &type,
254                              (BYTE*)&kmi->keylist_sortby, &size);
255          rclient.top += rect.bottom - rect.top;      if (ec != ERROR_SUCCESS)
256          MoveWindow (kmi->toolbar, 0, 0, rclient.right - rclient.left,          kmi->keylist_sortby = KEY_SORT_USERID;
257                      rect.bottom - rect.top, bRepaint);      RegCloseKey (root);
258      }      return 0;
259    }
260      /* Move statusbar to the bottom of the window */  
261      if (kmi->statbar) {  
262          GetWindowRect( kmi->statbar, &rect );  /* Save the current column width to the registry. */
263          ScreenToClient(dlg, (POINT*)&rect);  int
264          ScreenToClient(dlg, (POINT*)&(rect.right));  save_column_info (struct km_info_s *kmi)
265    {    
266          rclient.bottom -= rect.bottom - rect.top;      HKEY root;
267          MoveWindow (kmi->statbar, 0, rclient.bottom, rclient.right - rclient.left,      WORD *buf;
268                      rect.bottom - rect.top, bRepaint);      LONG ec;
269      }      int i;
270    
271      // Obtain separator information and move it to the desired posistion      buf = new WORD[kmi->lv->cols];
272      if (kmi->ypercent_sep)      if (!buf)
273          kmi->ypos_sep = (rclient.bottom - rclient.top) * kmi->ypercent_sep / 100;          BUG (NULL);
274      else      for (i=0; i < kmi->lv->cols; i++) {
275          kmi->ypercent_sep = kmi->ypos_sep * 100 / (rclient.bottom - rclient.top);          LVCOLUMN lvc;
276            
277      // Don't move away          memset (&lvc, 0, sizeof (lvc));
278      if (kmi->ypos_sep+5 > rclient.bottom)          lvc.mask = LVCF_WIDTH;
279          kmi->ypos_sep = rclient.bottom - 5;          ListView_GetColumn (kmi->lv->ctrl, i, &lvc);
280      if (kmi->ypos_sep < rclient.top)          buf[i] = lvc.cx;
281          kmi->ypos_sep = rclient.top;      }
282      MoveWindow (kmi->hwnd_sep, 0, kmi->ypos_sep, (rclient.right - rclient.left), 5, bRepaint);  
283                ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\WinPT", 0,
284      // Place the keylist above the separator                         KEY_ALL_ACCESS, &root);
285      h = GetDlgItem( dlg, IDC_KEYMISC_KEYLIST );      if (ec != ERROR_SUCCESS) {
286      MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,          free_if_alloc (buf);
287                  kmi->ypos_sep - rclient.top, bRepaint);          return -1;
288      rclient.top = kmi->ypos_sep + 5 + 8;      }
289    
290      /* Place the group text and the group box below the separator */      ec = RegSetValueEx (root, "KMColumnSize", 0, REG_BINARY,
291      h = GetDlgItem( dlg, IDC_KEYMISC_GTEXT );                          (const BYTE*)buf, 2*kmi->lv->cols);
292      MoveWindow( h, rclient.left, rclient.top, 100, 14, bRepaint);      if (ec == ERROR_SUCCESS) {
293      rclient.top += 18;          ec = RegSetValueEx (root, "KMSortBy", 0, REG_DWORD_BIG_ENDIAN,
294                                (const BYTE*)&kmi->keylist_sortby,
295      h = GetDlgItem( dlg, IDC_KEYMISC_GROUP );                              sizeof (kmi->keylist_sortby));
296      MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,      }
297                  (rclient.bottom < rclient.top) ? 0 : rclient.bottom - rclient.top, bRepaint);      RegCloseKey (root);
298            free_if_alloc (buf);
299      /* Repaint the whole thing */      return ec == ERROR_SUCCESS? 0 : -1;
300      InvalidateRect (dlg, NULL, TRUE);  }
301  } /* do_resize_window */  
302    
303    /* Center window @dlg. */
304  static void  static void
305  do_create_minpopup (HWND dlg)  do_center_window (HWND dlg, struct km_info_s *kmi)
306  {  {
307      HMENU hm;      RECT rect;
308      MENUITEMINFO mi;      char *p;
309      char * s;      int pos_x = 0;
310      POINT p;      int pos_y = 0;
311                
312      if (gpg_read_only)      /* Find bottom of keylist */
313          return;      GetWindowRect (GetDlgItem(dlg, IDC_KEYMISC_KEYLIST), &rect);
314      hm = CreatePopupMenu ();      MapWindowPoints (NULL, dlg, (POINT*)&rect, 2);
315      if (!hm)  
316          BUG( NULL );      kmi->ypos_sep = rect.bottom;
317      memset (&mi, 0, sizeof mi);  
318      mi.cbSize = sizeof mi;      p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X");
319      s = (char *)_("Paste Key from Clipboard");      if (p && !strcmp (p, " ")) {
320      mi.fType = MF_STRING;          free_if_alloc (p);      
321      mi.dwTypeData = s;          center_window (dlg, NULL);
322      mi.cch = strlen (s);          return;
323      mi.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;      }
324      mi.wID = ID_KEYCTX_PASTE;      else if (p)
325      InsertMenuItem (hm, 0, FALSE, &mi);          pos_x = atol (p);
326      GetCursorPos (&p);  
327      TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL);      p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y");
328      DestroyMenu (hm);      if (p && !strcmp (p, " ")) {
329  } /* do_create_minpopup */          free_if_alloc (p);
330            center_window (dlg, NULL);
331            return;
332  static void      }
333  do_check_cache( listview_ctrl_t lv, HWND dlg, HWND sb  )      else if (p)
334  {          pos_y = atol (p);
335      gpgme_keycache_t cache;  
336        if (!pos_y && !pos_x) {
337      if( keycache_get_reload( ) ) {          center_window (dlg, NULL);
338          keycache_reload( dlg );          return;
339          keycache_set_reload( 0 );      }
340          cache = keycache_get_ctx( 1 );      
341          if( !cache )      if (pos_x < 0 || pos_y < 0)
342              BUG( dlg );          pos_x = pos_y = 0;
343          keylist_reload( lv, cache, KEYLIST_LIST, GPGME_ATTR_USERID );      if (pos_x > GetSystemMetrics (SM_CXSCREEN)
344          km_complete_status_bar (sb, lv, km_def_pos);          || pos_y > GetSystemMetrics (SM_CYSCREEN)) {
345      }          pos_x = pos_y = 0;
346  } /* do_check_cache */      }
347        GetClientRect (dlg, &rect);
348        MoveWindow (dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE);
349  long CALLBACK  }
350  separator_wnd_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )  
351  {  
352      static POINT last_mouse_pos;  /* Resize the key manager window with the information from @kmi. */
353    static void
354      if (msg == WM_CREATE)  do_resize_window (HWND dlg, struct km_info_s *kmi)
355          SetWindowLong (hwnd, GWL_USERDATA, (long)(((CREATESTRUCT*)lparam)->lpCreateParams));  {
356        HWND h;
357      switch (msg) {      RECT rclient, rect;
358      case WM_PAINT:      BOOL bRepaint = FALSE;
359          PAINTSTRUCT ps;  
360          RECT rect;      /* Get rect of client area and make life easier */
361          HPEN hpen;      GetClientRect (dlg, &rclient);
362    
363          GetClientRect (hwnd, &rect);      /* Move toolbar to the top of the window */
364          BeginPaint (hwnd, &ps);      if (kmi->toolbar) {
365            GetWindowRect (kmi->toolbar, &rect);
366          // Background          ScreenToClient (dlg, (POINT*)&rect);
367          FillRect (ps.hdc, &rect, (HBRUSH)(COLOR_3DFACE+1));          ScreenToClient (dlg, (POINT*)&(rect.right));
368    
369          // The lines from the light into the dark          rclient.top += rect.bottom - rect.top;
370          MoveToEx(ps.hdc, 0,0, NULL);          MoveWindow (kmi->toolbar, 0, 0, rclient.right - rclient.left,
371          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DHILIGHT))) != NULL) {                      rect.bottom - rect.top, bRepaint);
372              SelectObject(ps.hdc, (LPVOID)hpen);      }
373              LineTo(ps.hdc, rect.right, 0);  
374              DeleteObject(hpen);      /* Move statusbar to the bottom of the window */
375          }      if (kmi->statbar) {
376          MoveToEx(ps.hdc, 0, 1, NULL);          GetWindowRect (kmi->statbar, &rect);
377          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT))) != NULL) {          ScreenToClient (dlg, (POINT*)&rect);
378               SelectObject(ps.hdc, (LPVOID)hpen);          ScreenToClient (dlg, (POINT*)&(rect.right));
379               LineTo(ps.hdc, rect.right, rect.bottom);  
380               DeleteObject(hpen);          rclient.bottom -= rect.bottom - rect.top;
381           }          MoveWindow (kmi->statbar, 0, rclient.bottom,
382                        rclient.right - rclient.left,
383          MoveToEx(ps.hdc, 0, rect.bottom-1, NULL);                      rect.bottom - rect.top, bRepaint);
384          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW))) != NULL) {      }
385              SelectObject(ps.hdc, (LPVOID)hpen);  
386              LineTo(ps.hdc, rect.right, rect.bottom-1);      /* Obtain separator information and move it to the desired posistion */
387              DeleteObject(hpen);      if (kmi->ypercent_sep)
388          }          kmi->ypos_sep = (rclient.bottom - rclient.top) * kmi->ypercent_sep / 100;
389          MoveToEx(ps.hdc, 0, rect.bottom, NULL);      else
390          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW))) != NULL) {          kmi->ypercent_sep = kmi->ypos_sep * 100 / (rclient.bottom - rclient.top);
391              SelectObject(ps.hdc, (LPVOID)hpen);          
392              LineTo(ps.hdc, rect.right, rect.bottom);      /* Don't move away */
393              DeleteObject(hpen);      if (kmi->ypos_sep+5 > rclient.bottom)
394          }          kmi->ypos_sep = rclient.bottom - 5;
395        if (kmi->ypos_sep < rclient.top)
396          EndPaint (hwnd, &ps);          kmi->ypos_sep = rclient.top;
397          return 0;      MoveWindow (kmi->hwnd_sep, 0, kmi->ypos_sep,
398                    (rclient.right - rclient.left), 5, bRepaint);
399      case WM_LBUTTONDOWN:          
400          last_mouse_pos.x = LOWORD(lparam);      /* Place the keylist above the separator */
401          last_mouse_pos.y = HIWORD(lparam);      h = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST);
402          ClientToScreen (hwnd, &last_mouse_pos);      MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,
403          SetCapture (hwnd);                  kmi->ypos_sep - rclient.top, bRepaint);
404          return 0;      rclient.top = kmi->ypos_sep + 5 + 8;
405    
406      case WM_LBUTTONUP:      if (kmi->enable_groups != 0) {
407          ReleaseCapture ();          /* Place the group text and the group box below the separator */
408          return 0;          h = GetDlgItem (dlg, IDC_KEYMISC_GTEXT);
409            MoveWindow (h, rclient.left, rclient.top, 100, 14, bRepaint);
410      case WM_MOUSEMOVE:          rclient.top += 18;
411          if (wparam == MK_LBUTTON) {  
412              struct km_info *kmi;          h = GetDlgItem (dlg, IDC_KEYMISC_GROUP);
413              POINT p;          MoveWindow (h, rclient.left, rclient.top,
414              RECT rect;                      rclient.right - rclient.left,
415                        (rclient.bottom < rclient.top) ?
416              if ((kmi = (struct km_info *)GetWindowLong (hwnd, GWL_USERDATA)) == NULL)                      0 : rclient.bottom - rclient.top, bRepaint);
417                  break;      }
418        
419              // Calculate mouse movement      /* Repaint the whole thing */
420              p.x = LOWORD(lparam);      InvalidateRect (dlg, NULL, TRUE);
421              p.y = HIWORD(lparam);  }
422              ClientToScreen (hwnd, &p);  
423    
424              GetWindowRect (hwnd, &rect);  /* Return true if the clipboard contains an OpenPGP key. */
425              rect.top += (short)(p.y - last_mouse_pos.y);  static bool
426              rect.bottom += (short)(p.y - last_mouse_pos.y);  clip_contains_pgpkey (void)
427    {
428              last_mouse_pos.y = p.y;      char *ctxt;
429        bool val = false;
430              // Apply mouse movement to window. Beware the MoveWindow is relaive  
431              // to parent NOT screen      ctxt = get_clip_text (NULL);
432              MapWindowPoints (NULL, GetParent(hwnd), (POINT*)&rect, 2);      if (!ctxt || strlen (ctxt) < 512)
433              kmi->ypos_sep = rect.top;          val = false;
434              kmi->ypercent_sep = 0; // This forces do_resize_window to use abs. position      else if (strstr (ctxt, "BEGIN PGP") && strstr (ctxt, "KEY BLOCK") &&
435              do_resize_window (GetParent(hwnd), kmi);               strstr (ctxt, "END PGP"))
436              return 0;          val = true;
437          }      free_if_alloc (ctxt);
438      }      return val;
439    }
440      return DefWindowProc (hwnd, msg, wparam, lparam);  
441  }  
442    /* Show a mini popup menu to import keys. */
443    static void
444  static HWND  do_create_minpopup (HWND dlg)
445  regist_sep_wnd (HWND dlg, struct km_info * kmi)  {
446  {      HMENU hm;
447      WNDCLASS wndclass;      POINT p;
448      HWND h;      
449        if (gpg_read_only || !clip_contains_pgpkey ())
450      wndclass.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;          return;
451      wndclass.lpfnWndProc   = separator_wnd_proc;      hm = CreatePopupMenu ();
452      wndclass.cbClsExtra    = 0;      if (!hm)
453      wndclass.cbWndExtra    = sizeof (long);          BUG (0);
454      wndclass.hInstance     = glob_hinst;      insert_menu_item (hm, 0, ID_KEYCTX_PASTE, _("Paste Key from Clipboard"));
455      wndclass.hIcon         = NULL;      GetCursorPos (&p);
456      wndclass.hCursor       = LoadCursor (NULL, IDC_SIZENS);      TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL);
457      wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);      DestroyMenu (hm);
458      wndclass.lpszMenuName  = 0;  }
459      wndclass.lpszClassName = WINDOWCLASS_SEPARATOR_CHILD;  
460      RegisterClass (&wndclass);  
461    /* Update the default key entry in the status bar for dialog @dlg. */
462      h = CreateWindowEx (WS_EX_WINDOWEDGE, WINDOWCLASS_SEPARATOR_CHILD, NULL,  void
463                          WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,  update_default_key_str (HWND dlg)
464                          0, 400, 2000, 5, dlg, (HMENU) 0, glob_hinst, kmi);      {
465      ShowWindow (h, SW_SHOW);      const char *fmt;
466      return h;      char *keyid;
467  } /* regist_sep_wnd */      char defkeyinf[128];
468    
469        keyid = get_gnupg_default_key ();
470        if (!keyid)
471  #define enable_button(hwnd, cid) \          return;
472      SendMessage ((hwnd), TB_ENABLEBUTTON, (cid), MAKELONG (key_selected, 0))      if ((keyid[0] >= 'A' && keyid[0] <= 'Z') ||
473            (keyid[0] >= 'a' && keyid[0] <= 'z') ||
474  void          (keyid[0] == '0' && keyid[1] == 'x'))
475  update_ui_items (HWND hwnd, listview_ctrl_t lv)          fmt = _("Default Key: %s");
476  {      else
477      int key_selected = 0, key_has_sec = 0;          fmt = _("Default Key: 0x%s");
478      int i, key_inv = 0;      _snprintf (defkeyinf, sizeof (defkeyinf) - 1, fmt, keyid);
479      HWND hwnd_child;      SendMessage (dlg, SB_SETTEXT, 0, (LPARAM)defkeyinf);
480      HMENU hmenu;      gpg_keycache_set_default_key (keycache_get_ctx (0), keyid);
481            free_if_alloc (keyid);
482      /* Get some states */  }
483      key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST),  
484                                             LVM_GETSELECTEDCOUNT, 0, 0)  
485                                             ? TRUE : FALSE;  /* Count all keys and show from @lv results in the status bar @sb. */
486      key_has_sec = FALSE;  void
487      if (key_selected) {  update_status_bar (HWND sb, listview_ctrl_t lv)
488          i = listview_get_curr_pos (lv);  {
489          key_has_sec = km_check_for_seckey( lv, i, NULL ) ? TRUE : FALSE;              char txt_sec[128], txt_pub[128];
490          key_inv = km_get_key_status (lv, i) & KM_FLAG_REVOKED;      int nkeys = 0, nsec = 0;
491      }      int i;
492    
493      /* Enable / disable toolbar buttons */      nkeys = listview_count_items (lv, 0);
494      hwnd_child = GetDlgItem(hwnd, IDR_WINPT_KMTB);      for (i = 0; i < nkeys; i++) {
495      enable_button (hwnd_child, ID_KEYMISC_DELETE);          if (km_check_for_seckey (lv, i, NULL))
496      enable_button (hwnd_child, ID_KEYMISC_PROPS);              nsec++;
497      enable_button (hwnd_child, ID_KEYMISC_SIGN);      }
498      enable_button (hwnd_child, ID_KEYMISC_EXPORT);      _snprintf (txt_sec, sizeof (txt_sec)-1, _("%d secret keys"), nsec);
499        _snprintf (txt_pub, sizeof (txt_pub)-1, _("%d keys"), nkeys);
500      /* Enable / disable menu items */      SendMessage (sb, SB_SETTEXT, 1, (LPARAM)txt_sec);
501      hmenu = GetMenu (hwnd);      SendMessage (sb, SB_SETTEXT, 2, (LPARAM)txt_pub);
502      set_menu_state (hmenu, ID_KEYMISC_EXPORT, key_selected ? MF_ENABLED : MF_GRAYED);  }
503      set_menu_state (hmenu, ID_KEYMISC_EXPORT_PRIVKEY, key_has_sec ? MF_ENABLED : MF_GRAYED);  
504      set_menu_state (hmenu, ID_KEYMISC_REVCERT, key_has_sec ? MF_ENABLED : MF_GRAYED);  
505      set_menu_state (hmenu, ID_KEYMISC_DELETE, key_selected ? MF_ENABLED : MF_GRAYED);  long CALLBACK
506      set_menu_state (hmenu, ID_KEYMISC_PROPS, key_selected ? MF_ENABLED : MF_GRAYED);  separator_wnd_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
507      set_menu_state (hmenu, ID_KEYMISC_SIGN, key_selected && !key_inv ? MF_ENABLED : MF_GRAYED);      {
508  } /* update_ui_items */      static POINT last_mouse_pos;
509    
510        if (msg == WM_CREATE)
511  static void          SetWindowLong (hwnd, GWL_USERDATA,
512  popup_gpg_readonly (HWND dlg, HMENU hm)                         (long)(((CREATESTRUCT*)lparam)->lpCreateParams));
513  {  
514      int resids[] = {      switch (msg) {
515          ID_KEYCTX_PASTE,      case WM_PAINT:
516          ID_KEYCTX_EDIT,          PAINTSTRUCT ps;
517          ID_KEYCTX_SIGN,          RECT rect;
518          ID_KEYCTX_REV,          HPEN hpen;
519          ID_KEYCTX_DEL,  
520          ID_KEYCTX_ENABLE,          GetClientRect (hwnd, &rect);
521          ID_KEYCTX_DISABLE,          BeginPaint (hwnd, &ps);
522          ID_KEYCTX_RECVFROM,  
523          ID_KEYCTX_ADDKEY,          /* Background */
524          ID_KEYCTX_ADDPHOTO,          FillRect (ps.hdc, &rect, (HBRUSH)(COLOR_3DFACE+1));
525          ID_KEYCTX_ADDUID,  
526          ID_KEYCTX_ADDREV,          /* The lines from the light into the dark */
527          0          MoveToEx(ps.hdc, 0,0, NULL);
528      };          if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DHILIGHT))) != NULL) {
529      int i;              SelectObject (ps.hdc, (LPVOID)hpen);
530                LineTo (ps.hdc, rect.right, 0);
531      if (gpg_read_only == 0)              DeleteObject (hpen);
532          return;          }
533      for (i=0; resids[i] != 0; i++)          MoveToEx(ps.hdc, 0, 1, NULL);
534          set_menu_state (hm, resids[i], MF_GRAYED);          if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT))) != NULL) {
535  }               SelectObject (ps.hdc, (LPVOID)hpen);
536                 LineTo (ps.hdc, rect.right, rect.bottom);
537                 DeleteObject (hpen);
538  static void           }
539  menu_gpg_readonly (HWND dlg, HMENU hm, int id)  
540  {          MoveToEx(ps.hdc, 0, rect.bottom-1, NULL);
541      int key_resids[] = {          if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW))) != NULL) {
542          ID_KEYMISC_SIGN,              SelectObject (ps.hdc, (LPVOID)hpen);
543          ID_KEYMISC_DELETE,              LineTo (ps.hdc, rect.right, rect.bottom-1);
544          ID_KEYMISC_REVCERT,              DeleteObject (hpen);
545          ID_KEYMISC_IMPORT_HTTP,          }
546          ID_KEYMISC_IMPORT,          MoveToEx(ps.hdc, 0, rect.bottom, NULL);
547          ID_KEYMISC_REFRESH_KEYS,          if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW))) != NULL) {
548          ID_KEYMISC_REBUILD,              SelectObject (ps.hdc, (LPVOID)hpen);
549          ID_KEYMISC_KEYWIZARD,              LineTo (ps.hdc, rect.right, rect.bottom);
550          ID_KEYMISC_CARDNEW,              DeleteObject (hpen);
551          ID_KEYMISC_NEWKEY,          }
552          0,  
553      };          EndPaint (hwnd, &ps);
554      int edit_resids[] = {          return 0;
555          ID_KEYMISC_PASTE,  
556          ID_KEYMISC_OT,      case WM_LBUTTONDOWN:
557          ID_KEYMISC_EDITKEY,          last_mouse_pos.x = LOWORD (lparam);
558          0          last_mouse_pos.y = HIWORD (lparam);
559      };          ClientToScreen (hwnd, &last_mouse_pos);
560      int * resids;          SetCapture (hwnd);
561      int i;          return 0;
562    
563            case WM_LBUTTONUP:
564      if (gpg_read_only == 0)          ReleaseCapture ();
565          return;          return 0;
566      switch (id) {  
567      case 0: return;      case WM_MOUSEMOVE:
568      case 3: resids = key_resids; break;          if (wparam == MK_LBUTTON) {
569      case 1: resids = edit_resids;break;              struct km_info_s *kmi;
570      }              POINT p;
571                RECT r;
572      for (i=0; resids[i] != 0; i++)  
573          set_menu_state (hm, resids[i], MF_GRAYED);              kmi = (struct km_info_s *)GetWindowLong (hwnd, GWL_USERDATA);
574  }              if (kmi == NULL)
575                    break;
576    
577  static char*              /* Calculate mouse movement */
578  gen_export_filename (const char *keyid)              p.x = LOWORD(lparam);
579  {              p.y = HIWORD(lparam);
580      gpgme_key_t key;              ClientToScreen (hwnd, &p);
581      const char *s;  
582      char *p;              GetWindowRect (hwnd, &r);
583                r.top += (short)(p.y - last_mouse_pos.y);
584      if (get_pubkey (keyid, &key))              r.bottom += (short)(p.y - last_mouse_pos.y);
585          return m_strdup (keyid);  
586      s = gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, NULL, 0);              last_mouse_pos.y = p.y;
587      if (!s)  
588          return m_strdup (keyid);              /* Apply mouse movement to window. Beware the MoveWindow is relaive
589      p = new char[strlen (s) + 8];                 to parent NOT screen */
590      if (!p)              MapWindowPoints (NULL, GetParent(hwnd), (POINT*)&r, 2);
591          BUG (0);              kmi->ypos_sep = r.top;
592      sprintf (p, "%s.asc", s);              kmi->ypercent_sep = 0; /* This forces do_resize_window to use abs. position */
593      for (size_t i=0; i < strlen (p); i++) {              do_resize_window (GetParent(hwnd), kmi);
594          if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|')              return 0;
595              p[i] = '_';          }
596      }      }
597      return p;  
598  }      return DefWindowProc (hwnd, msg, wparam, lparam);
599    }
600    
601  static void  
602  update_key (listview_ctrl_t lv, int pos, const char *keyid, int keypair)  /* Register the separator window with @dlg as the parent window. */
603  {  static HWND
604      gpgme_key_t key;  regist_sep_wnd (HWND dlg, struct km_info_s *kmi)
605    {
606      keycache_update (0, keyid);      WNDCLASS wndclass;
607      if (keypair)      HWND h;
608          keycache_update (1, keyid);  
609        wndclass.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
610      /* because we replaced the key item, we need to update the      wndclass.lpfnWndProc   = separator_wnd_proc;
611         address of the pointer in the ListView control. */      wndclass.cbClsExtra    = 0;
612      get_pubkey (keyid, &key);      wndclass.cbWndExtra    = sizeof (long);
613      keylist_upd_key (lv, pos, key);      wndclass.hInstance     = glob_hinst;
614  }      wndclass.hIcon         = NULL;
615        wndclass.hCursor       = LoadCursor (NULL, IDC_SIZENS);
616        wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);
617        wndclass.lpszMenuName  = 0;
618  BOOL CALLBACK      wndclass.lpszClassName = WINDOWCLASS_SEPARATOR_CHILD;
619  keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)      RegisterClass (&wndclass);
620  {  
621      struct km_info *kmi;      h = CreateWindowEx (WS_EX_WINDOWEDGE, WINDOWCLASS_SEPARATOR_CHILD, NULL,
622      static km_group_s *gc = NULL;                          WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
623      static HMENU menu = NULL;                          0, 400, 2000, 5, dlg, (HMENU) 0, glob_hinst, kmi);    
624      static int refresh_keys = 0;          ShowWindow (h, SW_SHOW);
625      INITCOMMONCONTROLSEX icex;      return h;
626      HWND kl;  }
627      HMENU hm;  
628      gpgme_keycache_t c;  
629      gpgme_key_t key;  #define enable_button(hwnd, cid, item_selected) \
630      /*km_group_cb_s gcb; XXX */      SendMessage ((hwnd), TB_ENABLEBUTTON, (cid), MAKELONG ((item_selected), 0))
631      struct genkey_s genkey;  
632      struct winpt_key_s k = {0};  
633      struct URL_ctx_s *url;  /* Interactive modification of the dialog item which depend if an item
634      refresh_cache_s rcs = {0};     is selected or not and what kind of item. @lv is the list view with
635      char keyid[48], uid[128], type[32], * name;     the items. */
636      const char *t, * host;  void
637      u16 port = 0;  update_ui_items (HWND hwnd, listview_ctrl_t lv)
638      int idx = 0, i=0, rc;  {
639      size_t size = 0;      HWND tb_hwnd;
640        HMENU hmenu;
641      if ((msg != WM_INITDIALOG)      int mult_resids[] = {ID_KEYMISC_PROPS, ID_KEYMISC_SIGN, ID_KEYMISC_EDITKEY,
642          && ((kmi = (struct km_info*)GetWindowLong (dlg, GWL_USERDATA)) == NULL))                           ID_KEYMISC_CHECKSIGS, ID_KEYMISC_REVCERT, 0};
643          return FALSE;      int key_selected = 0;
644        int key_has_sec = 0;
645      switch (msg) {      int key_inv = 0;
646      case WM_INITDIALOG:      int i, state=0;
647          kmi = new struct km_info;  
648          memset (kmi, 0, sizeof (struct km_info));      /* Get some states */
649          icex.dwSize = sizeof (INITCOMMONCONTROLSEX);      key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST),
650          icex.dwICC  = ICC_BAR_CLASSES;                                             LVM_GETSELECTEDCOUNT, 0, 0)
651          InitCommonControlsEx (&icex);                                             ? TRUE : FALSE;
652          kmi->hwnd_sep = regist_sep_wnd (dlg, kmi);      key_has_sec = FALSE;
653          imagelist_load (dlg);      if (key_selected) {
654            i = listview_get_curr_pos (lv);
655  #ifndef LANG_DE          key_has_sec = km_check_for_seckey (lv, i, NULL) ? TRUE : FALSE;
656          SetWindowText( dlg, _("Key Manager") );          key_inv = km_get_key_status (lv, i) & KM_FLAG_REVOKED ||
657  #endif                            km_get_key_status (lv, i) & KM_FLAG_EXPIRED;
658          menu = LoadMenu( glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC );      }
659  #ifndef LANG_DE  
660          set_menu_text( menu, ID_KEYMISC_QUIT, _("&Quit") );      /* Enable / disable toolbar buttons */
661          set_menu_text( menu, ID_KEYMISC_UID, _("User ID") );      tb_hwnd = GetDlgItem (hwnd, IDR_WINPT_KMTB);
662          set_menu_text( menu, ID_KEYMISC_NEWKEY, _("&Expert") );      enable_button (tb_hwnd, ID_KEYMISC_DELETE, key_selected);
663          set_menu_text( menu, ID_KEYMISC_KEYWIZARD, _("&Normal") );      enable_button (tb_hwnd, ID_KEYMISC_PROPS, key_selected);
664          set_menu_text( menu, ID_KEYMISC_EDIT, _("Edit") );      enable_button (tb_hwnd, ID_KEYMISC_SIGN, key_selected && !key_inv);
665          set_menu_text( menu, ID_KEYMISC_SIGN, _("&Sign") );      enable_button (tb_hwnd, ID_KEYMISC_EXPORT, key_selected);
666          set_menu_text( menu, ID_KEYMISC_DELETE, _("&Delete") );      enable_button (tb_hwnd, ID_KEYCTX_COPY, key_selected);
667          set_menu_text( menu, ID_KEYMISC_REVCERT, _("&Revoke") );      enable_button (tb_hwnd, ID_KEYCTX_PASTE, clip_contains_pgpkey ());
668          set_menu_text( menu, ID_KEYMISC_CHECKSIGS, _("&List Signatures") );  
669          set_menu_text( menu, ID_KEYMISC_TRUSTPATH, _("List Trust Path") );      /* Enable / disable menu items */
670          set_menu_text( menu, ID_KEYMISC_PROPS, _("&Properties") );      state = key_selected? MF_ENABLED : MF_DISABLED|MF_GRAYED;
671          set_menu_text( menu, ID_KEYMISC_GPGOPT, _("Options") );      hmenu = GetMenu (hwnd);
672          set_menu_text( menu, ID_KEYMISC_GPGPREFS, _("Preferences") );      set_menu_state (hmenu, ID_KEYMISC_EXPORT, state);
673          set_menu_text( menu, ID_KEYMISC_SENDRECV, _("Keyserver") );      set_menu_state (hmenu, ID_KEYMISC_DELETE, state);
674          set_menu_text( menu, ID_KEYMISC_RECACHE, _("Re&load Key Cache") );      set_menu_state (hmenu, ID_KEYMISC_PROPS, state);
675          set_menu_text( menu, ID_KEYMISC_REBUILD, _("R&everify Signatures") );      set_menu_state (hmenu, ID_KEYMISC_EDITKEY, state);
676          set_menu_text( menu, ID_KEYMISC_INFO, _("Info") );      set_menu_state (hmenu, ID_KEYMISC_CHECKSIGS, state);
677          set_menu_text (menu, ID_KEYMISC_HELP, _("Help"));      set_menu_state (hmenu, ID_KEYMISC_SIGN,
678  #endif                      key_selected && !key_inv ? MF_ENABLED : MF_GRAYED);
679          SetMenu( dlg, menu );      set_menu_state (hmenu, ID_KEYMISC_EXPORT_PRIVKEY,
680          if( keyring_check_last_access() )                      key_selected && key_has_sec? MF_ENABLED : MF_GRAYED);
681              keycache_set_reload( 1 );      set_menu_state (hmenu, ID_KEYMISC_REVCERT,
682          if( keycache_get_reload( ) )                      key_selected && key_has_sec? MF_ENABLED : MF_GRAYED);
683              keycache_reload( dlg );  
684          c = keycache_get_ctx( KEYCACHE_PUB );      /* Disable some menu items when multiple keys are selected. */
685          if( !c )      if (listview_count_items (lv, 1) > 1) {
686              BUG( NULL );          for (i=0; mult_resids[i] != 0; i++)
687          kmi->keylist_sortby = GPGME_ATTR_USERID;              set_menu_state (hmenu, mult_resids[i], MF_GRAYED);
688          Header_SetImageList(ListView_GetHeader(GetDlgItem( dlg, IDC_KEYMISC_KEYLIST )),      }
689                              glob_imagelist);  
690          kmi->lv = keylist_load( GetDlgItem( dlg, IDC_KEYMISC_KEYLIST ), c,      /* Disable all secret-key functions when no secret key is available. */
691                                  NULL, KEYLIST_LIST, kmi->keylist_sortby );      {
692          /* init subclassing for the listview */          gpg_keycache_t sec = keycache_get_ctx (0);
693          kl = GetDlgItem( dlg, IDC_KEYMISC_KEYLIST );          if (gpg_keycache_get_size (sec) == 0) {
694          keylist_proc.dlg = dlg;              enable_button (tb_hwnd, ID_KEYMISC_SIGN, FALSE);
695          keylist_proc.current = (WNDPROC)keylist_subclass_proc;              set_menu_state (hmenu, ID_KEYMISC_SIGN, MF_GRAYED);
696          keylist_proc.old = (WNDPROC)GetWindowLong( kl, GWL_WNDPROC );          }
697          if( keylist_proc.old ) {      }
698              if( !SetWindowLong( kl, GWL_WNDPROC, (LONG)keylist_proc.current) ) {  }
699                  msg_box( dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR );  
700                  BUG( NULL );  
701              }  /* Disable some context menu items when multiple keys are selected. */
702          }  static void
703          #if 0  popup_multiple (HWND dlg, HMENU hm)
704          km_groups_new( &gc, GetDlgItem( dlg, IDC_KEYMISC_GROUP ) );  {
705          km_groups_load( gc );      int resids[] = {
706          #endif          ID_KEYCTX_EDIT,
707          SetForegroundWindow( dlg );          ID_KEYCTX_SIGN,
708                    ID_KEYCTX_REV,
709          kmi->statbar = CreateStatusWindow( WS_CHILD | WS_VISIBLE | CCS_BOTTOM, "status bar", dlg, 100000 );          ID_KEYCTX_ENABLE,
710          ShowWindow( kmi->statbar, SW_SHOW );          ID_KEYCTX_DISABLE,
711          km_update_default_key_str (kmi->statbar, &km_def_pos);          ID_KEYCTX_ADDKEY,
712          km_complete_status_bar( kmi->statbar, kmi->lv, km_def_pos );          ID_KEYCTX_ADDPHOTO,
713            ID_KEYCTX_ADDUID,
714          SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi);          ID_KEYCTX_ADDREV,
715          kmi->toolbar = load_toolbar (dlg, kmi);          ID_KEYCTX_LISTSIGS,
716            ID_KEYCTX_MAXTRUST,
717          do_center_window( dlg, kmi );          ID_KEYCTX_PROPS,
718          do_resize_window( dlg, kmi );          ID_KEYCTX_SENDMAIL,
719          update_ui_items (dlg, kmi->lv);          0};
720          return TRUE;      int i;
721                for (i=0; i < resids[i] != 0; i++)
722      case WM_DESTROY:          set_menu_state (hm, resids[i], MF_GRAYED);
723          if (kmi->lv) {  }
724              keylist_delete (kmi->lv);  
725              kmi->lv = NULL;        
726                /* The items which are shown when GPG is in read-only mode. */
727           if (gc) {  static void
728              km_groups_release (gc);  popup_gpg_readonly (HWND dlg, HMENU hm)
729              gc = NULL;  {
730          }      int resids[] = {
731         imagelist_destroy ();          ID_KEYCTX_PASTE,
732            ID_KEYCTX_EDIT,
733         char buf[32];          ID_KEYCTX_SIGN,
734         ltoa (kmi->pos_x, buf, 10);          ID_KEYCTX_REV,
735         set_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", buf );          ID_KEYCTX_DEL,
736         ltoa (kmi->pos_y, buf, 10);          ID_KEYCTX_ENABLE,
737         set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", buf);          ID_KEYCTX_DISABLE,
738         /* Remove runtime information. This should be the last action taken here. */          ID_KEYCTX_RECVFROM,
739         delete kmi; kmi = NULL;          ID_KEYCTX_ADDKEY,
740         SetWindowLong (dlg, GWL_USERDATA, NULL);              ID_KEYCTX_ADDPHOTO,
741         keycache_set_reload (refresh_keys);          ID_KEYCTX_ADDUID,
742         return FALSE;          ID_KEYCTX_ADDREV,
743            0
744      case WM_MOVE:            };
745          /* kmi->pos_x = (int)(short)LOWORD(lparam);      int i;
746             kmi->pos_y = (int)(short)HIWORD(lparam); */  
747          RECT r;      if (gpg_read_only == 0)
748          GetWindowRect (dlg, &r);          return;
749          kmi->pos_x = r.left;      for (i=0; resids[i] != 0; i++)
750          kmi->pos_y = r.top;              set_menu_state (hm, resids[i], MF_GRAYED);
751          break;  }
752            
753    
754      case WM_RBUTTONUP:  /* Change the 'Edit' menu based on the current state. */
755          do_create_minpopup (dlg);  static void
756          break;  change_edit_menu (listview_ctrl_t lv, HMENU hm, int id)
757    {
758      case WM_NOTIFY:                  enum item { EDIT_MENU = 1 };
759          NMHDR * notify;      int no_sel;
760          POINT p;  
761          HMENU popup;      if (id != EDIT_MENU)
762                    return;
763          notify = (NMHDR *)lparam;  
764          if (notify == NULL)      if (!clip_contains_pgpkey ())
765              break;          set_menu_state (hm, ID_KEYMISC_PASTE, MF_GRAYED);
766          switch (notify->code)      else
767          {          set_menu_state (hm, ID_KEYMISC_PASTE, MF_ENABLED);
768          case TBN_QUERYDELETE:      no_sel = listview_get_curr_pos (lv) == -1? 1 : 0;
769              SetWindowLong(dlg, DWL_MSGRESULT, TRUE);      set_menu_state (hm, ID_KEYMISC_DELETE2, no_sel? MF_GRAYED: MF_ENABLED);
770              return TRUE;      set_menu_state (hm, ID_KEYMISC_COPY, no_sel? MF_GRAYED : MF_ENABLED);
771            }
772          case TBN_QUERYINSERT:  
773              SetWindowLong(dlg, DWL_MSGRESULT, TRUE);  
774              return TRUE;  
775    /* Show limited key menu entries when GPG is in read-only mode. */
776          case TBN_GETBUTTONINFO:  static void
777              LPTBNOTIFY lpTbNotify;  change_key_menu (HMENU hm, int id)
778              lpTbNotify = (LPTBNOTIFY)lparam;  {
779              if (lpTbNotify->iItem < (sizeof(myb) / sizeof(mybuttons))) {      int key_resids[] = {
780                  lpTbNotify->tbButton.iBitmap = imagelist_getindex(myb[lpTbNotify->iItem].icon);          ID_KEYMISC_SIGN,
781                  lpTbNotify->tbButton.idCommand = myb[lpTbNotify->iItem].command;          ID_KEYMISC_DELETE,
782                  lpTbNotify->tbButton.fsState = TBSTATE_ENABLED;          ID_KEYMISC_REVCERT,
783                  lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON;          ID_KEYMISC_IMPORT_HTTP,
784                  lpTbNotify->tbButton.iString = 0;          ID_KEYMISC_IMPORT,
785                  strncpy (lpTbNotify->pszText, myb[lpTbNotify->iItem].text, lpTbNotify->cchText);          ID_KEYMISC_REFRESH_KEYS,
786                  SetWindowLong(dlg, DWL_MSGRESULT, TRUE);          ID_KEYMISC_REBUILD,
787              }          ID_KEYMISC_KEYWIZARD,
788              return TRUE;          ID_KEYMISC_CARDNEW,
789            ID_KEYMISC_NEWKEY,
790          case TBN_RESET: /* Restore last saved toolbar status */          0,
791              TBSAVEPARAMS tbsp;      };
792        int edit_resids[] = {
793              tbsp.hkr = HKEY_CURRENT_USER;          ID_KEYMISC_PASTE,
794              tbsp.pszSubKey = "Software\\WinPT";          ID_KEYMISC_OT,
795              tbsp.pszValueName = "KM_toolbar";          ID_KEYMISC_EDITKEY,
796              SendMessage (notify->hwndFrom, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp);          0
797              break;      };
798        int *resids;
799          case TBN_BEGINADJUST: /* User is about to change the toolbar. Save it */      int i;
800              tbsp.hkr = HKEY_CURRENT_USER;  
801              tbsp.pszSubKey = "Software\\WinPT";      
802              tbsp.pszValueName = "KM_toolbar";      if (gpg_read_only == 0)
803              SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);          return;
804              break;      switch (id) {
805        case 0: return;
806          case TBN_ENDADJUST: /* User has finished customizing the toolbar. Save it. */      case 3: resids = key_resids; break;
807              tbsp.hkr = HKEY_CURRENT_USER;      case 1: resids = edit_resids;break;
808              tbsp.pszSubKey = "Software\\WinPT";      default:resids = edit_resids; break;
809              tbsp.pszValueName = "KM_toolbar";      }
810              SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);  
811              break;      for (i=0; resids[i] != 0; i++)
812            set_menu_state (hm, resids[i], MF_GRAYED);
813          case TTN_GETDISPINFO:  }
814              LPTOOLTIPTEXT lpttt;  
815              lpttt = (LPTOOLTIPTEXT)lparam;  
816    /* Reload a single key in the cache. */
817              lpttt->hinst = NULL;  static void
818              switch (lpttt->hdr.idFrom) {  update_key (listview_ctrl_t lv, int pos, const char *keyid, int keypair)
819              case ID_KEYMISC_DELETE:  {
820                  lpttt->lpszText = (char *)_("Delete key from keyring");      struct winpt_key_s key;
821                  break;  
822        keycache_update (0, keyid);
823              case ID_KEYMISC_PROPS:      if (keypair)
824                  lpttt->lpszText = (char *)_("Show key properties");          keycache_update (1, keyid);
825                  break;  
826        /* because we replaced the key item, we need to update the
827              case ID_KEYMISC_SIGN:         address of the pointer in the ListView control. */
828                  lpttt->lpszText = (char *)_("Sign key");      memset (&key, 0, sizeof (key));
829                  break;      winpt_get_pubkey (keyid, &key);
830        keylist_upd_key (lv, pos, key.ext, key.ctx);
831              case ID_KEYMISC_IMPORT:      keyring_check_last_access ();
832                  lpttt->lpszText = (char *)_("Import key to keyring");  }
833                  break;  
834    
835              case ID_KEYMISC_EXPORT:  /* Setup status bar for the main window @dlg. */
836                  lpttt->lpszText = (char *)_("Export key to a file");  static HWND
837                  break;  setup_status_bar (HWND dlg, listview_ctrl_t lv)
838              }  {      
839              return TRUE;      HWND statbar;
840                    RECT r;
841          case LVN_ITEMCHANGED:      int partpos[3];
842              if (((LPNMLISTVIEW)lparam)->uNewState) /* item selected? */      int i;
843              {  
844                  update_ui_items (dlg, kmi->lv);      GetClientRect (dlg, &r);
845                  return TRUE;      for (i=1; i <= 3; i++)
846              }          partpos[i-1] = r.right/3*i;
847              break;      statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM,
848                                      "status bar", dlg, KM_SEPARATOR_ID);
849          case NM_RCLICK:  
850              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {      ShowWindow (statbar, SW_SHOW);
851                  if (listview_get_curr_pos (kmi->lv) == -1)      SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos);
852                      return TRUE; /* Popup only when a item was selected */  
853                  do_check_cache (kmi->lv, dlg, kmi->statbar);      update_default_key_str (statbar);
854                  GetCursorPos (&p);      update_status_bar (statbar, lv);
855                  hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX));  
856                  popup = GetSubMenu (hm, 0);      return statbar;
857              #ifndef LANG_DE  }
858                  set_menu_text( popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard") );  
859                  set_menu_text( popup, ID_KEYCTX_COPY, _("Copy Key to Clipboard") );  
860                  set_menu_text( popup, ID_KEYCTX_PASTE, _("Paste Key from Clipboard") );              /* Remove or add columns which depends on the state of @checked. */
861                  set_menu_text( popup, ID_KEYCTX_RECVFROM, _("Refresh from Keyserver") );  void
862              #endif  modify_listview_columns (km_info_s *kmi, UINT m_uid, BOOL checked)
863                  idx = listview_get_curr_pos (kmi->lv);  {
864                  if (km_check_for_seckey (kmi->lv, idx, &i))      UINT resids[] = {
865                      set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED);          0,
866                  if (i == 0)          ID_KEYMISC_VIEWKEYID,
867                      set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED);          ID_KEYMISC_VIEWTYPE,
868                  if (!km_check_for_seckey (kmi->lv, idx, NULL)) {          0,
869                      set_menu_state( popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED );          ID_KEYMISC_VIEWCIPHER,
870                      set_menu_state( popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED );          0,
871                      set_menu_state( popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED );          0,
872                      set_menu_state( popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED );          ID_KEYMISC_VIEWCREAT,
873                      set_menu_state( popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED );          ID_KEYMISC_VIEWDESC,
874                      set_menu_state (popup, ID_KEYCTX_SETPREFKS, MF_DISABLED|MF_GRAYED);          -1
875                  }      };
876                  else if( km_check_for_seckey( kmi->lv, idx, NULL )      listview_column_s cols[] = {
877                        && km_key_is_v3( kmi->lv, idx ) )      {0, 240, (char *)_("User ID")},
878                  {      {1, 78, (char *)_("Key ID")},
879                      /* PGP 2 keys, version 3 have no no support for photo-id's,      {2, 52, (char *)_("Type")},    
880                         designated revokers and secondary keys. */      {3, 66, (char *)_("Size")},
881                      set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);      {4, 60, (char *)_("Cipher")},
882                      set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED);      {5, 66, (char *)_("Validity")},
883                      set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED);      {6, 58, (char *)_("Trust")},
884                  }      {7, 72, (char *)_("Creation")},
885                  if( km_get_key_status( kmi->lv, idx ) & KM_FLAG_DISABLED )      {8, 160,(char *)_("Description")},
886                      set_menu_state( popup, ID_KEYCTX_DISABLE, MF_DISABLED|MF_GRAYED );      {0, 0, NULL}
887                  else      };
888                      set_menu_state( popup, ID_KEYCTX_ENABLE, MF_DISABLED|MF_GRAYED );      UINT pos;
889                  if (km_get_key_status (kmi->lv, idx) & KM_FLAG_REVOKED)  
890                      set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED);      for (pos=0; resids[pos] != -1; pos++) {
891                  if (mapi_init())          if (m_uid == resids[pos])
892                      set_menu_state (popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED);              break;
893                  /* Override 'Default Keyserver' with the actual name. */      }
894                  host = kserver_get_hostname (0, -1, &port);      if (!checked)
895                  set_menu_text (popup, ID_KEYCTX_KS_DEFAULT, host);          listview_del_column (kmi->lv, (int)pos);
896                  popup_gpg_readonly (dlg, popup);      else {      
897                  TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);          listview_add_column (kmi->lv, &cols[pos]);
898                  DestroyMenu (popup);          keylist_upd_col (kmi->lv, pos);
899                  DestroyMenu (hm);      }
900                  return TRUE;  }
901              }  
902              #if 0 /* XXX */  
903              if( notify->idFrom == IDC_KEYMISC_GROUP ) {  /* Helper to handle the help file. If @check is 1
904                  HWND tree = GetDlgItem( dlg, IDC_KEYMISC_GROUP );     the existence of the file is checked.
905                  if( TreeView_GetSelection( tree ) ) {     Otherwise the help file will be loaded. */
906                      GetCursorPos( &p );  static bool
907                      hm = LoadMenu( glob_hinst, MAKEINTRESOURCE(IDR_WINPT_GROUP_CTX) );  start_help (HWND dlg, int check)
908                      popup = GetSubMenu( hm, 0 );  {
909                      if( km_index == -1 )      DWORD n;
910                          set_menu_state( popup, ID_GROUP_PASTE, MF_DISABLED|MF_GRAYED );      char path[MAX_PATH+1+32];
911                      set_menu_text( popup, ID_GROUP_PASTE, _("Paste into this group") );  
912                      set_menu_text( popup, ID_GROUP_DELETE, _("Delete") );      n = GetModuleFileName (NULL, path, sizeof (path)-1-32);
913                      TrackPopupMenu( popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL );      if (!n)
914                      DestroyMenu( popup );          return false;
915                      DestroyMenu( hm );      path[n] = 0;
916                      return TRUE;      while (n-- && path[n] != '\\')
917                  }          ;
918              }      path[n+1] = 0;
919              #endif      strcat (path, "winpt.chm");
920              break;      if (!check)
921            ShellExecute (dlg, "open", path, NULL, NULL, SW_SHOW);
922          case LVN_COLUMNCLICK:      return file_exist_check (path) == 0? true : false;
923              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {  }
924                  NMLISTVIEW * p = (LPNMLISTVIEW) lparam;  
925                  int sortby = 0;  /* Translate all menu strings. */
926                  switch (p->iSubItem) {  static void
927                  case 0:  sortby = GPGME_ATTR_USERID; break;  translate_menu_strings (HWND dlg)
928                  case 1:  sortby = GPGME_ATTR_KEYID; break;  {
929                  case 2:  sortby = GPGME_ATTR_IS_SECRET; break;      HMENU menu;
930                  case 3:  sortby = GPGME_ATTR_LEN; break;  
931                  case 5:  sortby = GPGME_ATTR_VALIDITY; break;      menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC);
932                  case 6:  sortby = GPGME_ATTR_OTRUST; break;      set_menu_text_bypos (menu, 0, _("File"));
933                  case 7:  sortby = GPGME_ATTR_CREATED; break;      set_menu_text_bypos (menu, 1, _("Edit"));
934                  case 8:  sortby = GPGME_ATTR_ALGO; break;      set_menu_text_bypos (menu, 2, _("View"));
935                  default: return TRUE; //sortby = GPGME_ATTR_USERID; break;      set_menu_text_bypos (menu, 3, _("Key"));
936                  }      set_menu_text_bypos (menu, 4, _("Groups"));
937    
938                  if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby)      set_menu_text (menu, ID_KEYMISC_EDITKEY, _("Edit"));
939                      kmi->keylist_sortby ^= KEYLIST_SORT_DESC;      set_menu_text (menu, ID_KEYMISC_MAIL, _("Send Mail..."));
940                  else      set_menu_text (menu, ID_KEYMISC_OT, _("Ownertrust")); /* XXX */
941                      kmi->keylist_sortby = sortby;      set_menu_text (menu, ID_KEYMISC_COPY, _("&Copy\tCtrl+C"));
942                  keylist_sort (kmi->lv, kmi->keylist_sortby);      set_menu_text (menu, ID_KEYMISC_PASTE, _("&Paste\tCtrl+V"));
943                  return TRUE;      set_menu_text (menu, ID_KEYMISC_FIND, _("Search...\tCtrl+F"));
944              }      set_menu_text (menu, ID_KEYMISC_SELALL, _("Select All\tCtrl+A"));
945              break;      set_menu_text (menu, ID_KEYMISC_QUIT, _("&Quit"));
946          }      set_menu_text (menu, ID_KEYMISC_UID, _("User ID"));
947          break;      set_menu_text (menu, ID_KEYMISC_NEWKEY, _("&Expert"));
948          }      set_menu_text (menu, ID_KEYMISC_KEYWIZARD, _("&Normal"));
949        set_menu_text (menu, ID_KEYMISC_EDIT, _("Edit"));
950      case WM_WINDOWPOSCHANGING:      set_menu_text (menu, ID_KEYMISC_SIGN, _("&Sign"));
951          if (((WINDOWPOS*)lparam)->cx < 400)      set_menu_text (menu, ID_KEYMISC_DELETE, _("&Delete"));
952              ((WINDOWPOS*)lparam)->cx = 400;      set_menu_text (menu, ID_KEYMISC_DELETE2, _("&Delete"));
953          if (((WINDOWPOS*)lparam)->cy < 200)      set_menu_text (menu, ID_KEYMISC_REVCERT, _("&Revoke Cert"));
954              ((WINDOWPOS*)lparam)->cy = 200;      set_menu_text (menu, ID_KEYMISC_CHECKSIGS, _("&List Signatures"));
955           return TRUE;      set_menu_text (menu, ID_KEYMISC_TRUSTPATH, _("List Trust Path"));
956                set_menu_text (menu, ID_KEYMISC_EXPORT, _("&Export..."));
957      case WM_SIZE:      set_menu_text (menu, ID_KEYMISC_IMPORT, _("&Import..."));
958          do_resize_window (dlg, kmi);      set_menu_text (menu, ID_KEYMISC_PROPS, _("&Properties"));
959          return TRUE;      set_menu_text (menu, ID_KEYMISC_GPGOPT, _("Options"));
960                set_menu_text (menu, ID_KEYMISC_GPGPREFS, _("Preferences"));
961      case WM_SYSCOMMAND:      set_menu_text (menu, ID_KEYMISC_SENDRECV, _("Keyserver") );
962          if( LOWORD (wparam) == SC_CLOSE )      set_menu_text (menu, ID_KEYMISC_EXPORT_PRIVKEY, _("E&xport Secret Key"));
963              EndDialog( dlg, TRUE );      set_menu_text (menu, ID_KEYMISC_RECACHE, _("Re&load Key Cache"));
964          return FALSE;      set_menu_text (menu, ID_KEYMISC_REBUILD, _("R&everify Signatures"));
965                set_menu_text (menu, ID_KEYMISC_REFRESH_KEYS, _("Refresh &Keys (Keyserver)"));
966      case WM_MENUSELECT:      set_menu_text (menu, ID_KEYMISC_INFO, _("Info") );
967          menu_gpg_readonly (dlg, (HMENU)lparam, LOWORD (wparam));      set_menu_text (menu, ID_KEYMISC_HELP, _("&Help"));
968          break;  
969        set_menu_text (menu, ID_KEYMISC_VIEWKEYID, _("Key ID"));
970      case WM_COMMAND:      set_menu_text (menu, ID_KEYMISC_VIEWCIPHER, _("Cipher"));
971          if( gnupg_access_keyring( 1 ) ) {      set_menu_text (menu, ID_KEYMISC_VIEWTYPE, _("Type"));
972              msg_box( dlg, _("Could not access public keyring"), _("Key Manager"), MB_ERR );      set_menu_text (menu, ID_KEYMISC_VIEWCREAT, _("Creation"));
973              return FALSE;  
974          }      if (!start_help (NULL, 1))
975          do_check_cache( kmi->lv, dlg, kmi->statbar );          set_menu_state (menu, ID_KEYMISC_HELP, MF_GRAYED);
976          switch( LOWORD( wparam ) ) {  
977          case ID_KEYMISC_QUIT:      SetMenu (dlg, menu);
978              EndDialog( dlg, TRUE );  }
979              return TRUE;  
980                
981          case ID_KEYMISC_MAIL:  /* Translate popup menu strings. */
982              DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_MAIL, GetDesktopWindow (),  static void
983                              winpt_mail_proc, NULL);  translate_popupmenu_strings (HMENU popup)
984              break;  {
985                set_menu_text (popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard"));
986          case ID_KEYMISC_FIND:      set_menu_text (popup, ID_KEYCTX_KEYID_COPY, _("Copy Key ID to Clipboard"));
987              km_find_key (dlg, kmi->lv);      set_menu_text (popup, ID_KEYCTX_FPR_COPY, _("Copy Fingerprint to Clipboard"));
988              break;      set_menu_text (popup, ID_KEYCTX_KINFO_COPY, _("Copy Key Info to Clipboard"));
989        set_menu_text (popup, ID_KEYCTX_COPY, _("Copy Key to Clipboard"));
990          case ID_KEYMISC_DELETE:      set_menu_text (popup, ID_KEYCTX_PASTE, _("Paste Key from Clipboard"));
991              if (km_delete_keys (kmi->lv, dlg))      set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Refresh from Keyserver"));
992                  return FALSE;      set_menu_text (popup, ID_KEYCTX_MAXTRUST, _("Set Implicit &Trust"));
993              return TRUE;      set_menu_text (popup, ID_KEYCTX_LISTSIGS, _("&List Signatures"));
994                    set_menu_text (popup, ID_KEYCTX_PROPS, _("&Properties"));
995          case ID_KEYMISC_SIGN:              set_menu_text (popup, ID_KEYCTX_EDIT, _("Key Edit"));
996              if ( (idx = listview_get_curr_pos( kmi->lv )) == -1 ) {      set_menu_text (popup, ID_KEYCTX_DEL, _("&Delete"));
997                  msg_box( dlg, _("Please select a key."),  _("Key Manager"),      set_menu_text (popup, ID_KEYCTX_REV, _("&Revoke Cert"));
998                           MB_ERR );      set_menu_text (popup, ID_KEYCTX_SIGN, _("&Sign"));
999                  return FALSE;      set_menu_text (popup, ID_KEYCTX_ENABLE, _("&Enable"));
1000              }      set_menu_text (popup, ID_KEYCTX_DISABLE, _("&Disable"));
1001              if (km_check_key_status (kmi->lv, idx))      set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Re&fresh from Keyserver"));
1002                  return FALSE;      set_menu_text (popup, ID_KEYCTX_SETPREFKS, _("Set preferred Keyserver URL"));
1003              key = (gpgme_key_t)listview_get_item2 (kmi->lv, idx);      set_menu_text (popup, ID_KEYCTX_SENDMAIL, _("Send Key to Mail Recipient"));
1004              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);      set_menu_text (popup, ID_KEYCTX_SETDEFKEY, _("Set as Default Key"));
1005              memset (&k, 0, sizeof (k));  
1006              k.ctx = key;      set_menu_text (popup, ID_KEYCTX_ADDKEY, _("Key..."));
1007              k.keyid = keyid;      set_menu_text (popup, ID_KEYCTX_ADDUID, _("User ID..."));
1008              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg,      set_menu_text (popup, ID_KEYCTX_ADDPHOTO, _("Photo ID..."));
1009                                keysign_dlg_proc, (LPARAM)&k,      set_menu_text (popup, ID_KEYCTX_ADDREV, _("Revoker..."));
1010                                _("Key Signing"), IDS_WINPT_KEYSIGN);  
1011              if (k.update)      /* change popup texts */
1012                  update_key (kmi->lv, idx, k.keyid, 0);      set_menu_text_bypos (popup, 0, _("Key Attributes"));
1013              return TRUE;      set_menu_text_bypos (popup, 6, _("Add"));
1014                    set_menu_text_bypos (popup, 19, _("Send to Keyserver"));
1015          case ID_KEYMISC_REVCERT:  }
1016              idx = listview_get_curr_pos( kmi->lv );  
1017              if( idx == -1 ) {  
1018                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );  /* Return true if the cache contain marked keys. */
1019                  return FALSE;  static bool
1020              }  updated_keys_avail (void)
1021              listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid -1 );  {
1022              listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid-1 );      gpg_keycache_t kc = keycache_get_ctx (1);
1023              if ( !km_check_for_seckey( kmi->lv, idx, NULL ) ) {      struct keycache_s *k;
1024                  msg_box( dlg, _("There is no secret key available!"), _("Key Manager"), MB_ERR );  
1025                  return FALSE;      for (k = kc->item; k; k = k->next) {
1026              }          if (k->flags)
1027                            return true;
1028              {      }
1029                  char t[128];      return false;
1030                  listview_get_item_text( kmi->lv, idx, 5, t, sizeof t -1 );  }
1031                  if( strchr( t, 'R' ) ) {  
1032                      msg_box( dlg, _("Key already revoked!"), _("Key Manager"), MB_INFO );  
1033                      return FALSE;  /* Find the index of the key identified by @key. */
1034                  }  static int
1035              }  find_keypos (listview_ctrl_t lv, gpgme_key_t key)
1036                {
1037              name = km_quote_uid (uid);      char keyid[16+1];
1038              memset (&k, 0, sizeof (k));      int i;
1039              k.key_pair = 1;  
1040              k.keyid = keyid;      for (i=0; i < listview_count_items (lv, 0); i++) {
1041              k.uid = name;          listview_get_item_text (lv, i, KM_COL_KEYID, keyid, sizeof (keyid)-1);
1042              k.is_protected = km_check_if_protected( kmi->lv, idx );          if (!strcmp (key->subkeys->keyid+8, keyid+2))
1043              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg,              return i;
1044                               key_revoke_dlg_proc, (LPARAM)&k,      }
1045                               _("Key Revocation"), IDS_WINPT_KEYREVOKE );      return -1;
1046              free_if_alloc (name);  }
1047              return TRUE;  
1048                
1049          case ID_KEYMISC_TRUSTPATH:  /* Add all recently updated keys in the cache to the list
1050              idx = listview_get_curr_pos( kmi->lv );     and refresh all GUI elements. */
1051              if( idx == -1 ) {  static void
1052                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );  refresh_keylist (struct km_info_s *kmi)
1053                  return FALSE;  {
1054              }      struct keycache_s *ctx;
1055              listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid -1 );      gpg_keycache_t kc;
1056              listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid -1 );      int status=0, pos;
1057              if( km_check_for_seckey( kmi->lv, idx, NULL ) ) {  
1058                  msg_box( dlg, _("It does not make any sense with a key pair!"), _("Key Manager"), MB_OK );      kc = keycache_get_ctx (1);
1059                  return FALSE;      while (!gpg_keycache_next_updated_key (kc, &ctx, &status)) {
1060              }          if (status == KC_FLAG_ADD)
1061              memset (&k, 0, sizeof (k));              keylist_add_key (kmi->lv, KEYLIST_LIST, ctx, ctx->key);
1062              k.keyid = keyid;          else {
1063              k.uid = uid;              pos = find_keypos (kmi->lv, ctx->key);
1064              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg,              if (pos != -1)
1065                                keytrust_dlg_proc, (LPARAM)&k,                  keylist_upd_key (kmi->lv, pos, ctx, ctx->key);
1066                                _("List Trust Path"), IDS_WINPT_KEYTRUST );          }
1067              return TRUE;      }
1068                    keylist_sort (kmi->lv, kmi->keylist_sortby);
1069          case ID_KEYMISC_CHECKSIGS:      update_status_bar (kmi->statbar, kmi->lv);
1070              idx = listview_get_curr_pos (kmi->lv);      keyring_check_last_access ();
1071              if( idx == -1 ) {  }
1072                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );  
1073                  return FALSE;  
1074              }  static void
1075              listview_get_item_text (kmi->lv, idx, 0, uid, DIM (uid)-1);  reload_keylist (struct km_info_s *kmi)
1076              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);  {
1077              memset (&k, 0, sizeof (k));      gpg_keycache_t c;
1078              k.keyid = keyid;  
1079              k.uid = uid;      c = keycache_get_ctx (1);
1080              k.ctx = (gpgme_key_t)listview_get_item2 (kmi->lv, idx);      keycache_reload (kmi->dlg);
1081              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG, dlg,      keylist_reload (kmi->lv, c, KEYLIST_LIST, kmi->keylist_sortby);
1082                                keysig_dlg_proc, (LPARAM)&k,      update_status_bar (kmi->statbar, kmi->lv);
1083                                _("Key Signature List" ), IDS_WINPT_KEYSIG);      keyring_check_last_access ();
1084              return TRUE;  }
1085                
1086          case ID_KEYMISC_PROPS:  
1087              idx = listview_get_curr_pos( kmi->lv );  /* Reload the entire key cache and update the listview. */
1088              if( idx == -1 ) {  static void
1089                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );  reload_keycache (struct km_info_s *kmi)
1090                  return FALSE;  {
1091              }      refresh_cache_s rcs = {0};
1092              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);      gpg_keycache_t c;
1093              listview_get_item_text (kmi->lv, idx, 2, type, DIM (type)-1);  
1094              memset (&k, 0, sizeof (k));      rcs.kr_reload = rcs.kr_update = 1;
1095              k.key_pair = 0;      rcs.tr_update = 0;
1096              k.keyid = keyid;      DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, kmi->dlg,
1097              if( !strcmp( type, "pub/sec" ) || !strcmp( type, "pub/crd" ) )                      keycache_dlg_proc, (LPARAM)&rcs);
1098                  k.key_pair = 1;      c = keycache_get_ctx (1);
1099              k.callback.ctl = kmi->lv;      keylist_reload (kmi->lv, c, KEYLIST_LIST, kmi->keylist_sortby);
1100              k.callback.idx = idx;      update_status_bar (kmi->statbar, kmi->lv);
1101              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg,      SetForegroundWindow (kmi->dlg);
1102                                keyprops_dlg_proc, (LPARAM)&k,  }
1103                                _("Key Properties"), IDS_WINPT_KEYPROPS );  
1104              if (k.callback.new_val != 0) {  
1105                  t = get_key_trust_str (k.callback.new_val);  /* Handle all import request. */
1106                  listview_add_sub_item (kmi->lv, idx, 6, t);  static void
1107              }  km_gui_import (struct km_info_s *kmi, int cmd_id, void *param)
1108              return TRUE;  {
1109                    int newkeys=0, newsks=0;
1110          case ID_KEYMISC_RECACHE:      int err = 0;
1111              /* If there is already a reload request, don't bother the user with a message. */  
1112              if( keycache_get_reload() == 1 )      switch (cmd_id) {
1113                  idx = IDYES;      case ID_KEYMISC_PASTE:
1114              else {          err = km_clip_import (kmi->dlg, &newkeys, &newsks);
1115                  char t[256];          break;
1116                  _snprintf( t, sizeof t -1,  
1117                             _("This is only useful when the keyring has been "      case ID_KEYMISC_IMPORT:
1118                               "modified (sign a key...).\n"          err = km_file_import (kmi->dlg, NULL, &newkeys, &newsks);
1119                               "Do you really want to reload the keycache?") );          break;
1120                  idx = msg_box( dlg, t, _("Key Manager"), MB_YESNO );  
1121              }      case WM_DROPFILES:
1122              if( idx == IDYES ) {          err = km_dropped_file_import (kmi->dlg, (HDROP)param,
1123                  rcs.kr_reload = rcs.kr_update = 1;                                        &newkeys, &newsks);
1124                  rcs.tr_update = 0;          break;
1125                  DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,  
1126                                  keycache_dlg_proc, (LPARAM)&rcs );      default:
1127                  c = keycache_get_ctx( 1 );          err = 1;
1128                  if( !c )          break;
1129                      BUG( dlg );      }
1130                  keylist_reload( kmi->lv, c, KEYLIST_LIST, GPGME_ATTR_USERID );  
1131                  refresh_keys = 0;      if (!err && !newsks && (newkeys > 0 && newkeys < KM_PRELOAD_KEYS))
1132              }          refresh_keylist (kmi);
1133              return TRUE;      else if (!err) /* avoid to spawn too much processes. */
1134                        reload_keylist (kmi);
1135          case ID_KEYMISC_REBUILD:  
1136              rcs.kr_reload = rcs.kr_update = 0;      SetForegroundWindow (kmi->dlg);
1137              rcs.tr_update = 1;  }
1138              DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,  
1139                              keycache_dlg_proc, (LPARAM)&rcs );  
1140              c = keycache_get_ctx( 1 );  /* Dialog box procedure for the Key Manager. */
1141              if( !c )  BOOL CALLBACK
1142                  BUG( dlg );  keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1143              keylist_reload( kmi->lv, c, KEYLIST_LIST, GPGME_ATTR_USERID );  {
1144              return TRUE;      struct km_info_s *kmi = NULL;
1145                    HWND kl;
1146          case ID_KEYMISC_NEWKEY:      HMENU hm;
1147              memset (&genkey, 0, sizeof (genkey));      struct keycache_s *kci;
1148              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg,      gpg_keycache_t c;
1149                                keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"),      gpgme_key_t key;
1150                                IDS_WINPT_KEYGEN);      struct genkey_s genkey;
1151              if (genkey.newkey != NULL)      struct winpt_key_s k = {0};
1152                  keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);      struct URL_ctx_s *url;
1153              return TRUE;      char type[32], *name;
1154        const char *t, *host;
1155          case ID_KEYMISC_CARDNEW:      WORD port = 0;
1156              if( !scard_support ) {      int l_idx = 0, i=0, rc;
1157                  msg_box( dlg, _("Smart Card support is not available."), _("Key Manager"), MB_INFO );  
1158                  return FALSE;      if ((msg != WM_INITDIALOG)
1159              }          && ((kmi = (struct km_info_s*)GetWindowLong (dlg, GWL_USERDATA)) == NULL))
1160              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg,          return FALSE;
1161                                card_keygen_dlg_proc, NULL, _("Card Key Generation"),      
1162                                IDS_WINPT_CARD_KEYGEN );      /* handle dynamic popup items in the keyserver menu. */
1163              /* XXX: use new code */      if (msg == WM_COMMAND && LOWORD (wparam) >= WM_APP &&
1164              if( keycache_get_reload() )                               LOWORD (wparam) <= WM_APP+MAX_KEYSERVERS) {
1165                  send_cmd_id( dlg, ID_KEYMISC_RECACHE );          l_idx = LOWORD (wparam)-WM_APP;
1166              return TRUE;          if (l_idx < 0)
1167                return TRUE;
1168          case ID_KEYMISC_KEYWIZARD:          host = kserver_get_hostname (l_idx, 0, &port);
1169              memset (&genkey, 0, sizeof (genkey));          if (host != NULL)
1170              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, dlg,              km_send_to_keyserver (kmi->lv, dlg, host, port);
1171                                keygen_wizard_dlg_proc, (LPARAM)&genkey, _("Key Generation Wizard"),          return TRUE;
1172                                IDS_WINPT_KEYWIZARD);      }
1173              if (genkey.newkey != NULL)  
1174                  keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);      switch (msg) {
1175              return TRUE;      case WM_INITDIALOG:
1176                        kmi = new struct km_info_s;
1177          case ID_KEYMISC_SENDRECV:          memset (kmi, 0, sizeof (struct km_info_s));
1178              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg,          kmi->lv_idx = -1;
1179                                keyserver_dlg_proc, NULL, _("Keyserver Access"),          kmi->hwnd_sep = regist_sep_wnd (dlg, kmi);
1180                                IDS_WINPT_KEYSERVER );          imagelist_load (dlg);
1181              return TRUE;          translate_menu_strings (dlg);
1182                        SetWindowText (dlg, _("Key Manager"));
1183          case ID_KEYMISC_GPGPREFS:  
1184              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, dlg,          c = keycache_get_ctx (KEYCACHE_PUB);
1185                                gpgprefs_dlg_proc, NULL, _("GnuPG Preferences"),          if (!c)
1186                                IDS_WINPT_GPGPREFS );              BUG (NULL);
1187              return TRUE;          kl = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST);
1188                        kmi->keylist_sortby = KEY_SORT_USERID;
1189          case ID_KEYMISC_GPGOPT:          Header_SetImageList(ListView_GetHeader (kl), glob_imagelist);
1190              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg,          kmi->lv = keylist_load (GetDlgItem (dlg, IDC_KEYMISC_KEYLIST), c,
1191                                gpgopt_dlg_proc, NULL, _("GnuPG Options" ),                                  NULL, KEYLIST_LIST, kmi->keylist_sortby);
1192                                IDS_WINPT_GPGOPT );          if (check_ultimate_trusted_key ()) {
1193              return TRUE;              msg_box (dlg, _("No ultimately trusted key found.\n"
1194                                            "Please set at least one secret key to ultimate trust."),
1195          case ID_KEYMISC_IMPORT:                              _("Key Manager"), MB_WARN);
1196              t = get_filename_dlg (dlg, FILE_OPEN, _("Choose Name of the Key File"), NULL, NULL);          }
1197              if (t)          /* init subclassing for the listview */
1198                  km_file_import (dlg, t);          keylist_proc.opaque = kmi;
1199              return TRUE;          keylist_proc.dlg = dlg;
1200            keylist_proc.current = (WNDPROC)keylist_subclass_proc;
1201          case ID_KEYMISC_IMPORT_HTTP:          keylist_proc.old = (WNDPROC)GetWindowLong(kl, GWL_WNDPROC);
1202              url = (struct URL_ctx_s*)get_http_file_dlg (dlg);          if (keylist_proc.old) {
1203              if (url->cancel == 0)              if( !SetWindowLong (kl, GWL_WNDPROC, (LONG)keylist_proc.current)) {
1204                  km_http_import (dlg, url->url);                  msg_box (dlg, _("Could not set keylist window procedure."),
1205              delete url; url=NULL;                           _("Key Manager"), MB_ERR);
1206              break;                  BUG (NULL);
1207                            }
1208          case ID_KEYMISC_EXPORT:          }
1209              idx = listview_get_curr_pos (kmi->lv);          kmi->statbar = setup_status_bar (dlg, kmi->lv);
1210              if (idx == -1) {          SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi);
1211                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );          kmi->toolbar = load_toolbar (dlg, kmi);
1212                  return FALSE;          kmi->dlg = dlg;
1213              }  
1214              if (listview_count_items (kmi->lv, 1) > 1)          do_center_window (dlg, kmi);
1215                  name = m_strdup ("Exported_GPG_Keys.asc");          do_resize_window (dlg, kmi);
1216              else {          update_ui_items (dlg, kmi->lv);
1217                  listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);          restore_column_info (kmi);
1218                  name = gen_export_filename (keyid);          keylist_sort (kmi->lv, kmi->keylist_sortby);
1219              }  
1220              t = get_filename_dlg (dlg, FILE_SAVE, _("Choose Name for Key File"), NULL, name);          SetDlgItemText (dlg, IDC_KEYMISC_GTEXT, _("Groups"));
1221              free_if_alloc (name);          SetDlgItemText (dlg, ID_GROUP_SHOW, _("&Show"));
1222              if (!t || overwrite_file (t) == 0)          SetDlgItemText (dlg, ID_GROUP_NEW, _("&New..."));
1223                  return FALSE;          SetClassLong (dlg, GCL_HICON, (LONG)LoadIcon (glob_hinst,
1224              km_file_export (dlg, kmi->lv, t);                        (LPCTSTR)IDI_WINPT));
1225              return TRUE;          SetForegroundWindow (dlg);
1226                        kmi->magic = SetTimer (dlg, 1, 1000, NULL);
1227          case ID_KEYMISC_EXPORT_PRIVKEY:          return TRUE;
1228              idx = listview_get_curr_pos( kmi->lv );  
1229              if( idx == -1 ) {      case WM_TIMER:
1230                  msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );          KillTimer (dlg, kmi->magic);
1231                  return FALSE;          SetForegroundWindow (dlg);
1232              }          break;
1233              if( !km_check_for_seckey( kmi->lv, idx, NULL ) ) {          
1234                  msg_box( dlg, _("There is no corresponding secret key for this key."),      case WM_DESTROY:
1235                          _("Key Manager"), MB_ERR );          save_column_info (kmi);
1236                  return FALSE;          if (kmi->lv) {
1237              }              keylist_delete (kmi->lv);
1238              if( listview_count_items( kmi->lv, 1 ) > 1 ) {              kmi->lv = NULL;      
1239                  msg_box( dlg, _("You can only export one secret key."), _("Key Manager"), MB_ERR );          }
1240                  return FALSE;          imagelist_destroy ();
1241              }  
1242              idx = msg_box( dlg,          ltoa (kmi->pos_x, type, 10);
1243                            _("This operation will export your *SECRET* key!\n\n"          set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", type);
1244                              "Never send this key to ANYONE, it should be available\n"          ltoa (kmi->pos_y, type, 10);
1245                              "ONLY on your machine and you may use this function\n"          set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", type);
1246                              "to copy the key to a safe place.\n\n"          /* XXX: store window size. */
1247                              "Do you really want to export the key?"),          
1248                            _("WARNING"), MB_INFO|MB_YESNO );          /* Remove runtime information. This should be the last action taken here. */
1249              if( idx == IDYES ) {          delete kmi;
1250                  idx = listview_get_curr_pos( kmi->lv );          kmi = NULL;
1251                  listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof (keyid)-8 );          SetWindowLong (dlg, GWL_USERDATA, 0);
1252                  name = gen_export_filename (keyid);          return FALSE;
1253                  t = get_filename_dlg (dlg, 1, _("Choose Name for Key File"), NULL, name);  
1254                  if (t && !file_exist_check (t)) {      case WM_MOVE:
1255                      idx = log_box (_("Key Manager"), MB_INFO|MB_YESNO,          RECT r;
1256                                     _("File %s already exists.\nOverwrite?"), t);          GetWindowRect (dlg, &r);
1257                      if (idx == IDNO)          kmi->pos_x = r.left;
1258                          return FALSE;          kmi->pos_y = r.top;    
1259                  }          break;
1260                  if (t)          
1261                      km_privkey_export (dlg, kmi->lv, t);  
1262              }      case WM_RBUTTONUP:
1263              break;          do_create_minpopup (dlg);
1264            break;
1265          case ID_KEYMISC_INFO:  
1266              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, glob_hwnd,      case WM_NOTIFY:            
1267                                about_winpt_dlg_proc, NULL, _("About WinPT"),          NMHDR *notify;
1268                                IDS_WINPT_ABOUT );          POINT p;
1269              break;          HMENU popup;
1270            
1271          case ID_KEYMISC_HELP:          notify = (NMHDR *)lparam;
1272              ShellExecute (dlg, "open", "winpt.chm", NULL, NULL, SW_SHOW);          if (!notify)
1273              break;              break;
1274            switch (notify->code) {
1275          case ID_KEYMISC_OT:          case TBN_QUERYDELETE:
1276              dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST, glob_hwnd,              SetWindowLong (dlg, DWL_MSGRESULT, TRUE);
1277                                ownertrust_dlg_proc, NULL,              return TRUE;
1278                                _("Ownertrust"), IDS_WINPT_OWNERTRUST );          
1279              break;          case TBN_QUERYINSERT:
1280                SetWindowLong (dlg, DWL_MSGRESULT, TRUE);
1281          case ID_KEYMISC_EDITKEY:              return TRUE;
1282              idx = listview_get_curr_pos (kmi->lv);  
1283              if (idx == -1)          case TBN_GETBUTTONINFO:
1284                  break;              LPTBNOTIFY lpTbNotify;
1285              listview_get_item_text (kmi->lv, idx, 1, keyid, sizeof (keyid)-1);              lpTbNotify = (LPTBNOTIFY)lparam;
1286              /* XXX: pub/crd = secret key does not work */              if (lpTbNotify->iItem < (sizeof(myb) / sizeof(mybuttons))) {
1287              memset (&k, 0, sizeof (k));                  lpTbNotify->tbButton.iBitmap = imagelist_getindex (myb[lpTbNotify->iItem].icon);
1288              k.is_protected = km_check_if_protected (kmi->lv, idx);                  lpTbNotify->tbButton.idCommand = myb[lpTbNotify->iItem].command;
1289              k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);                  lpTbNotify->tbButton.fsState = TBSTATE_ENABLED;
1290              k.keyid = keyid;                  lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON;
1291              k.is_v3 = km_key_is_v3 (kmi->lv, idx);                  lpTbNotify->tbButton.iString = 0;
1292              k.flags = km_get_key_status (kmi->lv, idx);                  strncpy (lpTbNotify->pszText, myb[lpTbNotify->iItem].text, lpTbNotify->cchText);
1293              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg,                  SetWindowLong(dlg, DWL_MSGRESULT, TRUE);
1294                                keyedit_main_dlg_proc, (LPARAM)&k,              }
1295                                _("Key Edit"), IDS_KEYCTX_EDIT);              return TRUE;
1296              if (k.update)  
1297                  update_key (kmi->lv,  idx, keyid, 1);          case TBN_RESET: /* Restore last saved toolbar status */
1298              break;              TBSAVEPARAMS tbsp;
1299                
1300          case ID_KEYMISC_COPY:              tbsp.hkr = HKEY_CURRENT_USER;
1301              km_index = listview_get_curr_pos (kmi->lv);              tbsp.pszSubKey = "Software\\WinPT";
1302              km_clip_export (dlg, kmi->lv);              tbsp.pszValueName = "KM_toolbar";
1303              break;              SendMessage (notify->hwndFrom, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp);
1304                            break;
1305          case ID_KEYMISC_SELALL:  
1306              listview_select_all (kmi->lv);          case TBN_BEGINADJUST: /* User is about to change the toolbar. Save it */
1307              break;              tbsp.hkr = HKEY_CURRENT_USER;
1308                tbsp.pszSubKey = "Software\\WinPT";
1309          case ID_KEYMISC_PASTE:              tbsp.pszValueName = "KM_toolbar";
1310              km_index = -1;              SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);
1311              km_clip_import (dlg);              break;
1312              break;  
1313                        case TBN_ENDADJUST: /* User has finished customizing the toolbar. Save it. */
1314          case ID_KEYCTX_SETPREFKS:              tbsp.hkr = HKEY_CURRENT_USER;
1315              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM(keyid)-1);              tbsp.pszSubKey = "Software\\WinPT";
1316              memset (&k, 0, sizeof (k));              tbsp.pszValueName = "KM_toolbar";
1317              k.keyid = keyid;              SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);
1318              keyedit_set_pref_keyserver (&k, dlg);              break;
1319              break;  
1320            case TTN_GETDISPINFO:
1321          case ID_KEYMISC_REFRESH_KEYS:              LPTOOLTIPTEXT lpttt;
1322              if (listview_count_items (kmi->lv, 1) == 0) {              lpttt = (LPTOOLTIPTEXT)lparam;
1323                  msg_box (dlg, _("No key was selected, select all by default."), _("Key Manager"), MB_INFO);  
1324                  listview_select_all (kmi->lv);              lpttt->hinst = NULL;
1325              }              switch (lpttt->hdr.idFrom) {
1326              km_refresh_from_keyserver (kmi->lv, dlg);              case ID_KEYMISC_KEYWIZARD:
1327              break;                  lpttt->lpszText = (char*)_("Generate new key pair");
1328                                            break;
1329          /** Context menu **/  
1330          case ID_KEYCTX_EDIT:              case ID_KEYMISC_SENDRECV:
1331              send_cmd_id( dlg, ID_KEYMISC_EDITKEY );                  lpttt->lpszText = (char*)_("Search for a specific key");
1332              break;                  break;
1333    
1334          case ID_KEYCTX_PROPS:              case ID_KEYMISC_DELETE:
1335              send_cmd_id( dlg, ID_KEYMISC_PROPS );                  lpttt->lpszText = (char *)_("Delete key from keyring");
1336              break;                  break;
1337    
1338          case ID_KEYCTX_UIDS:              case ID_KEYMISC_PROPS:
1339              send_cmd_id( dlg, ID_KEYMISC_UID );                  lpttt->lpszText = (char *)_("Show key properties");
1340              break;                  break;
1341    
1342          case ID_KEYCTX_SIGN:              case ID_KEYMISC_SIGN:
1343              send_cmd_id( dlg, ID_KEYMISC_SIGN );                  lpttt->lpszText = (char *)_("Sign key");
1344              break;                  break;
1345    
1346          case ID_KEYCTX_DEL:              case ID_KEYCTX_COPY:
1347              send_cmd_id (dlg, ID_KEYMISC_DELETE);                  lpttt->lpszText = (char *)_("Copy key to clipboard");
1348              break;                  break;
1349    
1350          case ID_KEYCTX_REV:              case ID_KEYCTX_PASTE:
1351              send_cmd_id( dlg, ID_KEYMISC_REVCERT );                  lpttt->lpszText = (char*)_("Paste key from clipboard");
1352              break;                  break;
1353    
1354          case ID_KEYCTX_SENDMAIL:              case ID_KEYMISC_IMPORT:
1355              km_send_to_mail_recipient (kmi->lv, dlg);                  lpttt->lpszText = (char *)_("Import key to keyring");
1356              break;                  break;
1357    
1358          case ID_KEYCTX_KS_DEFAULT:              case ID_KEYMISC_EXPORT:
1359              host = kserver_get_hostname (0, -1, &port);                  lpttt->lpszText = (char *)_("Export key to a file");
1360              km_send_to_keyserver (kmi->lv, dlg, host, port);                  break;
1361              break;              }
1362                return TRUE;
1363          case ID_KEYCTX_ADDKEY:              
1364              idx = listview_get_curr_pos (kmi->lv);          case LVN_ITEMCHANGED:
1365              listview_get_item_text( kmi->lv, idx, 1, keyid, DIM (keyid)-1);              if (((LPNMLISTVIEW)lparam)->uNewState) { /* item selected? */
1366              memset (&k, 0, sizeof (k));                  kmi->lv_idx = listview_get_curr_pos (kmi->lv);
1367              k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);                  update_ui_items (dlg, kmi->lv);
1368              k.is_protected = km_check_if_protected (kmi->lv, idx);                  return TRUE;
1369              k.keyid = keyid;              }
1370              keyedit_add_subkey (&k, dlg, NULL);              break;
1371              if (k.update)  
1372                  update_key (kmi->lv, idx, keyid, 1);          case NM_RCLICK:
1373              break;              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
1374                    l_idx =listview_get_curr_pos (kmi->lv);
1375          case ID_KEYCTX_ADDUID:                  if (l_idx == -1)
1376              idx = listview_get_curr_pos (kmi->lv);                      return TRUE; /* Popup only when a item was selected */              
1377              listview_get_item_text( kmi->lv, idx, 1, keyid, DIM (keyid)-1);                  GetCursorPos (&p);
1378              memset (&k, 0, sizeof (k));                  hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX));
1379              k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);                  popup = GetSubMenu (hm, 0);
1380              k.is_protected = km_check_if_protected (kmi->lv, idx);                  translate_popupmenu_strings (popup);
1381              k.keyid = keyid;  
1382              keyedit_add_userid (&k, dlg, NULL);                  if (km_check_for_seckey (kmi->lv, l_idx, &i))
1383              if (k.update)                      set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED);
1384                  update_key (kmi->lv, idx, keyid, 1);                  if (i == 0)
1385              break;                      set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED);
1386                    if (!km_check_for_seckey (kmi->lv, l_idx, NULL) ||
1387          case ID_KEYCTX_ADDREV:                      (km_get_key_status (kmi->lv, l_idx) & KM_FLAG_REVOKED)) {
1388              idx = listview_get_curr_pos (kmi->lv);                      set_menu_state (popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED);
1389              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);                      set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);
1390              memset (&k, 0, sizeof (k));                      set_menu_state (popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED);
1391              k.keyid = keyid;                      set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED);
1392              k.is_protected = km_check_if_protected (kmi->lv, idx);                      set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED );
1393              k.key_pair = km_check_for_seckey( kmi->lv, idx, NULL );                      set_menu_state (popup, ID_KEYCTX_SETPREFKS, MF_DISABLED|MF_GRAYED);
1394              keyedit_add_revoker (&k, dlg);                  }
1395              if (k.update)                  else if (km_check_for_seckey (kmi->lv, l_idx, NULL) &&
1396                  update_key (kmi->lv, idx, keyid, 1);                           km_key_is_v3 (kmi->lv, l_idx)) {
1397              break;                      /* PGP 2 keys, version 3 have no no support for photo-id's,
1398                           designated revokers and secondary keys. */
1399          case ID_KEYCTX_ADDPHOTO:                      set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);
1400              idx = listview_get_curr_pos (kmi->lv);                      set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED);
1401              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);                      set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED);
1402              memset (&k, 0, sizeof (k));                  }
1403              k.keyid = keyid;                  if (km_get_key_status( kmi->lv, l_idx ) & KM_FLAG_DISABLED)
1404              k.is_protected = km_check_if_protected (kmi->lv, idx);                      set_menu_state (popup, ID_KEYCTX_DISABLE, MF_DISABLED|MF_GRAYED);
1405              k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);                  else
1406              keyedit_add_photo (&k, dlg);                      set_menu_state (popup, ID_KEYCTX_ENABLE, MF_DISABLED|MF_GRAYED);
1407              if (k.update)                  if (km_get_key_status (kmi->lv, l_idx) & KM_FLAG_REVOKED ||
1408                  update_key (kmi->lv, idx, keyid, 1);                      km_get_key_status (kmi->lv, l_idx) & KM_FLAG_EXPIRED)
1409              break;                      set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED);
1410                    if (!clip_contains_pgpkey ())
1411          case ID_KEYCTX_KS_NL:                      set_menu_state (popup, ID_KEYCTX_PASTE, MF_DISABLED|MF_GRAYED);
1412          case ID_KEYCTX_KS_PL:                  if (mapi_init ())
1413          case ID_KEYCTX_KS_AT:                      set_menu_state (popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED);
1414          case ID_KEYCTX_KS_DE:  
1415          case ID_KEYCTX_KS_DK:                  /* Override 'Default Keyserver' with the actual name. */
1416          case ID_KEYCTX_KS_CZ:                  host = kserver_get_hostname (0, -1, &port);
1417          case ID_KEYCTX_KS_ES:                  if (!host)
1418          case ID_KEYCTX_KS_UK:                      host = DEF_HKP_KEYSERVER;
1419              host = kserver_get_hostname (LOWORD (wparam) - 40107, 0, &port);                  set_menu_text (popup, ID_KEYCTX_KS_DEFAULT, host);
1420              km_send_to_keyserver (kmi->lv, dlg, host, port);                  {
1421              break;                      HMENU ks = GetSubMenu (popup, 19);
1422                        for (i=0; server[i].name != NULL; i++)                      
1423          case ID_KEYCTX_RECVFROM:                          insert_menu_item (ks, i+2, WM_APP+i, server[i].name);
1424              km_refresh_from_keyserver (kmi->lv, dlg);                  }
1425              break;                  popup_gpg_readonly (dlg, popup);
1426                    if (listview_count_items (kmi->lv, 1) > 1)
1427          case ID_KEYCTX_UID_COPY:                      popup_multiple (dlg, popup);
1428              /* XXX: add generic function to support multiple selection                  TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
1429                      with a callback */                  DestroyMenu (popup);
1430              idx = listview_get_curr_pos( kmi->lv );                  DestroyMenu (hm);
1431              listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid-1 );                  return TRUE;
1432              set_clip_text( NULL, uid, strlen( uid ) );              }
1433              break;              break;
1434    
1435          case ID_KEYCTX_KEYID_COPY:          case LVN_COLUMNCLICK:
1436              idx = listview_get_curr_pos( kmi->lv );              if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
1437              listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 );                  NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;
1438              set_clip_text( NULL, uid, strlen( uid ) );                  int sortby = 0;
1439              break;                  switch (nft->iSubItem) {
1440                    case 0:  sortby = KEY_SORT_USERID; break;
1441          case ID_KEYCTX_FPR_COPY:                  case 1:  sortby = KEY_SORT_KEYID; break;
1442              idx = listview_get_curr_pos( kmi->lv );                  case 2:  sortby = KEY_SORT_IS_SECRET; break;
1443              key = (gpgme_key_t) listview_get_item2 (kmi->lv, idx);                          case 3:  sortby = KEY_SORT_LEN; break;
1444              if (key) {                  case 5:  sortby = KEY_SORT_VALIDITY; break;
1445                  const char * s = get_key_fpr (key);                  case 6:  sortby = KEY_SORT_OTRUST; break;
1446                  set_clip_text (NULL, s? s : "", s? strlen (s): 0);                  case 7:  sortby = KEY_SORT_CREATED; break;
1447              }                  case 8:  sortby = KEY_SORT_ALGO; break;
1448              break;                  default: return TRUE; //sortby = KEY_SORT_USERID; break;
1449                    }
1450          case ID_KEYCTX_KINFO_COPY:  
1451              idx = listview_get_curr_pos( kmi->lv );                  if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby)
1452              listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 );                      kmi->keylist_sortby ^= KEYLIST_SORT_DESC;
1453              km_set_clip_info( uid );                          else
1454              break;                      kmi->keylist_sortby = sortby;
1455                    keylist_sort (kmi->lv, kmi->keylist_sortby);
1456          case ID_KEYCTX_COPY:                  return TRUE;
1457              km_index = listview_get_curr_pos (kmi->lv);              }
1458              km_clip_export (dlg, kmi->lv);              break;
1459              break;          }
1460            break;
1461          case ID_KEYCTX_PASTE:    
1462              km_index = -1;      case WM_WINDOWPOSCHANGING:
1463              km_clip_import (dlg);          if (((WINDOWPOS*)lparam)->cx < 400)
1464              break;              ((WINDOWPOS*)lparam)->cx = 400;
1465            if (((WINDOWPOS*)lparam)->cy < 200)
1466          case ID_KEYCTX_DISABLE:              ((WINDOWPOS*)lparam)->cy = 200;
1467              idx = listview_get_curr_pos (kmi->lv);           return TRUE;
1468              km_enable_disable_key (kmi->lv, dlg, idx, 0);          
1469              break;      case WM_SIZE:
1470            do_resize_window (dlg, kmi);
1471          case ID_KEYCTX_ENABLE:          return TRUE;
1472              idx = listview_get_curr_pos (kmi->lv);          
1473              km_enable_disable_key (kmi->lv, dlg, idx, 1);      case WM_SYSCOMMAND:
1474              break;          if (LOWORD (wparam) == SC_CLOSE)
1475                EndDialog (dlg, TRUE);
1476          case ID_KEYCTX_LISTSIGS:          return FALSE;
1477              send_cmd_id (dlg, ID_KEYMISC_CHECKSIGS);          
1478              break;      case WM_MENUSELECT:
1479            change_edit_menu (kmi->lv, (HMENU)lparam, LOWORD (wparam));
1480          case ID_KEYCTX_MAXTRUST:          change_key_menu ((HMENU)lparam, LOWORD (wparam));
1481              idx = listview_get_curr_pos (kmi->lv);          break;
1482              listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);  
1483              rc = km_set_implicit_trust (dlg, kmi->lv, idx);      case WM_INITMENUPOPUP:
1484              if (!rc)          if ((UINT)LOWORD (lparam) == 3) {
1485                  update_key (kmi->lv, idx, keyid, 0);              HMENU h = (HMENU)wparam;
1486              break;              set_menu_text_bypos (h, 0, _("New"));
1487            }
1488          case ID_KEYCTX_SETDEFKEY:          /* XXX: before we can use it, we need to find a way to
1489              idx = listview_get_curr_pos (kmi->lv);                  update the gpg access timestamp after each operation.
1490              if (!km_check_key_status (kmi->lv, idx)) {          if (keyring_check_last_access ())
1491                  listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);              reload_keylist (kmi);
1492                  rc = set_gnupg_default_key (keyid);          */
1493                  if (rc)          return FALSE;
1494                      msg_box( dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR);  
1495                  km_update_default_key_str (kmi->statbar, &km_def_pos);      case WM_COMMAND:
1496              }          /* Allow at least 'Exit' in such a case. */
1497              break;          if (gnupg_access_keyring (1) && LOWORD (wparam) != ID_KEYMISC_QUIT) {
1498                msg_box (dlg, _("Could not access public keyring"),
1499          #if 0 /* XXX */                       _("Key Manager"), MB_ERR);
1500          case ID_GROUP_NEW:              return FALSE;
1501              memset (&gcb, 0, sizeof (gcb));          }
1502              gcb.gc = gc;  
1503              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GROUP, glob_hwnd,          switch (LOWORD (wparam)) {
1504                               group_manager_dlg_proc, (LPARAM)&gcb, _("New Group"),          case ID_KEYMISC_QUIT:
1505                               IDS_WINPT_GROUP);              EndDialog (dlg, TRUE);
1506              if( gcb.use_name )              return TRUE;
1507                  treeview_add_item( GetDlgItem(dlg, IDC_KEYMISC_GROUP), NULL, gcb.name );          
1508              return TRUE;          case ID_KEYMISC_FIND:
1509                            km_find_key (dlg, kmi->lv);
1510          case ID_GROUP_PASTE:              break;
1511              km_groups_add (gc, kmi->lv, km_index);  
1512              break;          case ID_KEYMISC_DELETE:
1513                        case ID_KEYMISC_DELETE2:
1514          case ID_GROUP_DELETE:              if (!km_delete_keys (kmi->lv, dlg))
1515              km_groups_del (gc);                  update_status_bar (kmi->statbar, kmi->lv);
1516              break;              return TRUE;
1517          #endif              
1518          }          case ID_KEYMISC_SIGN:
1519                        if (kmi->lv_idx == -1) {
1520          break;                  msg_box (dlg, _("Please select a key."),  
1521      }                           _("Key Manager"), MB_ERR);
1522                        return TRUE;
1523      return FALSE;              }
1524  } /* keymanager_dlg_proc */              if (km_check_key_status (kmi->lv, kmi->lv_idx))
1525                    return TRUE;
1526                km_get_key (kmi->lv, kmi->lv_idx, &k);
1527                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg,
1528                                  keysign_dlg_proc, (LPARAM)&k,
1529                                  _("Key Signing"), IDS_WINPT_KEYSIGN);
1530                if (k.update)
1531                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1532                return TRUE;
1533                
1534            case ID_KEYMISC_REVCERT:
1535                if (kmi->lv_idx == -1) {
1536                    msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1537                    return TRUE;
1538                }
1539                    
1540                {
1541                    char state[64];
1542                    listview_get_item_text (kmi->lv, kmi->lv_idx, 5,
1543                                            state, sizeof (state) -1);
1544                    if (strchr (state, 'R' )) {
1545                        msg_box (dlg, _("Key already revoked!"),
1546                                 _("Key Manager"), MB_INFO);
1547                        return TRUE;
1548                    }
1549                }
1550    
1551                km_get_key (kmi->lv, kmi->lv_idx, &k);
1552                if (!k.key_pair) {
1553                    msg_box (dlg, _("There is no secret key available!"),
1554                            _("Key Manager"), MB_ERR);
1555                    return TRUE;
1556                }
1557                dialog_box_param(glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg,
1558                                 key_revoke_dlg_proc, (LPARAM)&k,
1559                                 _("Key Revocation Cert"), IDS_WINPT_KEYREVOKE);
1560                return TRUE;
1561                
1562            case ID_KEYMISC_TRUSTPATH:
1563                if (kmi->lv_idx == -1) {
1564                    msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1565                    return TRUE;
1566                }
1567                km_get_key (kmi->lv, kmi->lv_idx, &k);
1568                if (!k.key_pair) {
1569                    msg_box (dlg, _("It does not make any sense with a key pair!"),
1570                             _("Key Manager"), MB_ERR);
1571                    return TRUE;
1572                }
1573                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg,
1574                                  keytrust_dlg_proc, (LPARAM)&k,
1575                                  _("List Trust Path"), IDS_WINPT_KEYTRUST);
1576                return TRUE;
1577                
1578            case ID_KEYMISC_CHECKSIGS:          
1579                if (kmi->lv_idx == -1) {
1580                    msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1581                    return TRUE;
1582                }
1583                km_get_key (kmi->lv, kmi->lv_idx, &k);
1584                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG_TREE, dlg,
1585                                  sigtree_dlg_proc, (LPARAM)&k,
1586                                  _("Key Signature List"), IDS_WINPT_KEYSIG);
1587                if (k.update)
1588                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1589                if (updated_keys_avail ())
1590                    refresh_keylist (kmi);
1591                return TRUE;
1592                
1593            case ID_KEYMISC_PROPS:      
1594                if (kmi->lv_idx == -1) {
1595                    msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1596                    return TRUE;
1597                }
1598                km_get_key (kmi->lv, kmi->lv_idx, &k);
1599                k.callback.ctl = kmi->lv;
1600                k.callback.idx = kmi->lv_idx;
1601                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg,
1602                                  keyprops_dlg_proc, (LPARAM)&k,
1603                                  _("Key Properties"), IDS_WINPT_KEYPROPS);
1604                if (k.update)
1605                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, k.key_pair);
1606                return TRUE;
1607                
1608            case ID_KEYMISC_RECACHE:
1609                if (updated_keys_avail ())
1610                    l_idx = IDYES;
1611                else {
1612                    l_idx = log_box (_("Key Manager"), MB_YESNO,
1613                               _("This is only useful when the keyring has been "
1614                                 "modified (sign a key...).\n"
1615                                 "Do you really want to reload the keycache?"));
1616                }
1617                if (l_idx == IDYES)
1618                    reload_keycache (kmi);
1619                return TRUE;
1620                
1621            case ID_KEYMISC_REBUILD:
1622                name = NULL;
1623                gpg_rebuild_cache (&name);
1624                if (name != NULL) {
1625                    char *line = strchr (name, '\n');
1626                    show_msg (dlg, 2000, line? name + (line-name)+1 : name);
1627                    safe_free (name);
1628                }
1629                SetForegroundWindow (dlg);
1630                return TRUE;
1631                
1632            case ID_KEYMISC_NEWKEY:
1633                memset (&genkey, 0, sizeof (genkey));
1634                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg,
1635                                  keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"),
1636                                  IDS_WINPT_KEYGEN);
1637                if (genkey.cancel == 0)
1638                    refresh_keylist (kmi);
1639                return TRUE;
1640    
1641            case ID_KEYMISC_CARDNEW:
1642                if (!scard_support) {
1643                    msg_box (dlg, _("Smart Card support is not available."),
1644                             _("Key Manager"), MB_INFO);
1645                    return TRUE;
1646                }
1647                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg,
1648                                  card_keygen_dlg_proc, 0, _("Card Key Generation"),
1649                                  IDS_WINPT_CARD_KEYGEN);
1650                if (updated_keys_avail ())
1651                    send_cmd_id (dlg, ID_KEYMISC_RECACHE);
1652                return TRUE;
1653    
1654            case ID_KEYMISC_KEYWIZARD:
1655                memset (&genkey, 0, sizeof (genkey));
1656                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, dlg,
1657                                  keygen_wizard_dlg_proc, (LPARAM)&genkey,
1658                                  _("Key Generation Wizard"),
1659                                  IDS_WINPT_KEYWIZARD);
1660                if (genkey.cancel == 0)
1661                    refresh_keylist (kmi);
1662                return TRUE;
1663                
1664            case ID_KEYMISC_SENDRECV:
1665                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg,
1666                                  keyserver_dlg_proc, 0, _("Keyserver Access"),
1667                                  IDS_WINPT_KEYSERVER);
1668                refresh_keylist (kmi);
1669                return TRUE;
1670                
1671            case ID_KEYMISC_GPGPREFS:
1672                rc = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS,
1673                                       dlg, gpgprefs_dlg_proc, 0,
1674                                       _("GnuPG Preferences"), IDS_WINPT_GPGPREFS);
1675                if (rc == TRUE) {
1676                    reload_keycache (kmi);
1677                    update_default_key_str (kmi->statbar);
1678                }
1679                return TRUE;
1680                
1681            case ID_KEYMISC_GPGOPT:
1682                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg,
1683                                  gpgopt_dlg_proc, 0, _("GnuPG Options"),
1684                                  IDS_WINPT_GPGOPT);
1685                return TRUE;
1686                
1687            case ID_KEYMISC_IMPORT:
1688                km_gui_import (kmi, LOWORD (wparam), NULL);
1689                return TRUE;
1690    
1691            case ID_KEYMISC_IMPORT_HTTP:
1692                url = (struct URL_ctx_s*)get_http_file_dlg (dlg);
1693                if (url && url->cancel == 0) {
1694                    km_http_import (dlg, url->url);
1695                    refresh_keylist (kmi);
1696                }
1697                free_if_alloc (url);
1698                break;
1699                
1700            case ID_KEYMISC_EXPORT:
1701                if (kmi->lv_idx == -1) {
1702                    msg_box (dlg, _("Please select a key."),
1703                             _("Key Manager"), MB_ERR);
1704                    return TRUE;
1705                }
1706                if (listview_count_items (kmi->lv, 1) > 1)
1707                    name = m_strdup ("Exported_GPG_Keys.asc");
1708                else {
1709                    key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1710                    name = km_gen_export_filename (key->subkeys->keyid+8, 0);
1711                }
1712                t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);
1713                free_if_alloc (name);
1714                if (t == NULL)
1715                    return TRUE;
1716                km_file_export (dlg, kmi->lv, t);
1717                return TRUE;
1718                
1719            case ID_KEYMISC_EXPORT_PRIVKEY:
1720                if (kmi->lv_idx == -1) {
1721                    msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1722                    return TRUE;
1723                }
1724                if( !km_check_for_seckey( kmi->lv, kmi->lv_idx, NULL ) ) {
1725                    msg_box (dlg, _("There is no corresponding secret key for this key."),
1726                             _("Key Manager"), MB_ERR);
1727                    return TRUE;
1728                }
1729                if (listview_count_items (kmi->lv, 1) > 1) {
1730                    msg_box (dlg, _("You can only export one secret key."),
1731                             _("Key Manager"), MB_ERR);
1732                    return TRUE;
1733                }
1734                i = msg_box (dlg,
1735                              _("This operation will export your *SECRET* key!\n\n"
1736                                "Never send this key to ANYONE, it should be available\n"
1737                                "ONLY on your machine and you may use this function\n"
1738                                "to copy the key to a safe place.\n\n"
1739                                "Do you really want to export the key?"),
1740                              _("WARNING"), MB_INFO|MB_YESNO);
1741                if (i == IDYES) {
1742                    key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1743                    name = km_gen_export_filename (key->subkeys->keyid+8, 1);
1744                    t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);
1745                    if (t != NULL)          
1746                        km_privkey_export (dlg, kmi->lv, t);
1747                }
1748                return TRUE;
1749    
1750            case ID_KEYMISC_INFO:
1751                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, dlg,
1752                                  about_winpt_dlg_proc, 0, _("About WinPT"),
1753                                  IDS_WINPT_ABOUT);
1754                break;
1755    
1756            case ID_KEYMISC_WEBSITE:
1757                ShellExecute (dlg, "open", "http://www.winpt.org",
1758                              NULL, NULL, SW_SHOW);
1759                break;
1760    
1761            case ID_KEYMISC_HELP:
1762                start_help (dlg, 0);
1763                break;
1764    
1765            case ID_KEYMISC_OT:
1766                dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST,
1767                                  dlg, ownertrust_dlg_proc, 0,
1768                                  _("Ownertrust"), IDS_WINPT_OWNERTRUST);
1769                break;
1770    
1771            case ID_KEYMISC_EDITKEY:
1772                if (km_get_key (kmi->lv, kmi->lv_idx, &k))
1773                    break;
1774                dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg,
1775                                  keyedit_main_dlg_proc, (LPARAM)&k,
1776                                  _("Key Edit"), IDS_KEYCTX_EDIT);
1777                if (k.update)
1778                    update_key (kmi->lv,  kmi->lv_idx, k.tmp_keyid, 1);
1779                break;
1780                
1781            case ID_KEYMISC_COPY:
1782                km_clip_export (dlg, kmi->lv);
1783                break;
1784                
1785            case ID_KEYMISC_SELALL:
1786                listview_select_all (kmi->lv);
1787                break;
1788    
1789            case ID_KEYMISC_PASTE:
1790                km_gui_import (kmi, LOWORD (wparam), NULL);
1791                break;
1792                
1793            case ID_KEYCTX_SETPREFKS:
1794                if (km_get_key (kmi->lv, kmi->lv_idx, &k))
1795                    break;
1796                keyedit_set_pref_keyserver (&k, dlg);
1797                break;
1798    
1799            case ID_KEYMISC_REFRESH_KEYS:
1800                if (listview_count_items (kmi->lv, 1) == 0) {
1801                    msg_box (dlg, _("No key was selected, select all by default."),
1802                             _("Key Manager"), MB_INFO);
1803                    listview_select_all (kmi->lv);
1804                }
1805                km_refresh_from_keyserver (kmi->lv, dlg);
1806                msg_box (dlg, _("Keyserver refresh finished."),
1807                         _("Key Manager"), MB_OK);
1808                break;
1809                            
1810            /** Context menu **/
1811            case ID_KEYCTX_EDIT:
1812                send_cmd_id( dlg, ID_KEYMISC_EDITKEY );
1813                break;
1814    
1815            case ID_KEYCTX_PROPS:
1816                send_cmd_id( dlg, ID_KEYMISC_PROPS );
1817                break;
1818    
1819            case ID_KEYCTX_UIDS:
1820                send_cmd_id( dlg, ID_KEYMISC_UID );
1821                break;
1822    
1823            case ID_KEYCTX_SIGN:
1824                send_cmd_id( dlg, ID_KEYMISC_SIGN );
1825                break;
1826    
1827            case ID_KEYCTX_DEL:
1828                send_cmd_id (dlg, ID_KEYMISC_DELETE);
1829                break;
1830    
1831            case ID_KEYCTX_REV:
1832                send_cmd_id( dlg, ID_KEYMISC_REVCERT );
1833                break;
1834    
1835            case ID_KEYCTX_SENDMAIL:
1836                km_send_to_mail_recipient (kmi->lv, dlg);
1837                break;
1838    
1839            case ID_KEYCTX_KS_DEFAULT:
1840                host = kserver_get_hostname (0, -1, &port);
1841                km_send_to_keyserver (kmi->lv, dlg, host, port);
1842                break;
1843    
1844            case ID_KEYCTX_ADDKEY:
1845                km_get_key (kmi->lv, kmi->lv_idx, &k);
1846                keyedit_add_subkey (&k, dlg, NULL);
1847                if (k.update)
1848                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1849                break;
1850    
1851            case ID_KEYCTX_ADDUID:
1852                km_get_key (kmi->lv, kmi->lv_idx, &k);
1853                keyedit_add_userid (&k, dlg, NULL);
1854                if (k.update)
1855                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1856                break;
1857    
1858            case ID_KEYCTX_ADDREV:
1859                km_get_key (kmi->lv, kmi->lv_idx, &k);
1860                keyedit_add_revoker (&k, dlg);
1861                if (k.update)
1862                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1863                break;
1864    
1865            case ID_KEYCTX_ADDPHOTO:
1866                km_get_key (kmi->lv, kmi->lv_idx, &k);
1867                keyedit_add_photo (&k, dlg);
1868                if (k.update)
1869                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1870                break;
1871    
1872            case ID_KEYCTX_RECVFROM:
1873                km_refresh_from_keyserver (kmi->lv, dlg);
1874                if (updated_keys_avail ())
1875                    refresh_keylist (kmi);
1876                break;
1877    
1878            case ID_KEYCTX_UID_COPY:
1879                /* XXX: add generic function to support multiple selection
1880                        with a callback */
1881                key = km_get_key_ptr (kmi->lv, kmi->lv_idx, &kci);
1882                name = kci->uids->name;
1883                set_clip_text (NULL, name, strlen (name));
1884                break;
1885    
1886            case ID_KEYCTX_KEYID_COPY:
1887                key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1888                memset (type, 0, sizeof (type));
1889                type[0] = '0'; type[1] = 'x';
1890                memcpy (type+2, key->subkeys->keyid+8, 8);
1891                set_clip_text (NULL, type, strlen (type));
1892                break;
1893    
1894            case ID_KEYCTX_FPR_COPY:
1895                key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1896                t = key->subkeys->fpr;
1897                set_clip_text (NULL, t? t : "", t? strlen (t): 0);
1898                break;
1899    
1900            case ID_KEYCTX_KINFO_COPY:
1901                key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1902                km_set_clip_info (key->subkeys->keyid+8);
1903                break;
1904    
1905            case ID_KEYCTX_COPY:
1906                send_cmd_id (dlg, ID_KEYMISC_COPY);
1907                break;
1908    
1909            case ID_KEYCTX_PASTE:
1910                send_cmd_id (dlg, ID_KEYMISC_PASTE);
1911                break;
1912    
1913            case ID_KEYCTX_DISABLE:
1914            case ID_KEYCTX_ENABLE:
1915                i = LOWORD (wparam) == ID_KEYCTX_ENABLE? 1 : 0;
1916                if (km_get_key (kmi->lv, kmi->lv_idx, &k))
1917                    break;
1918                rc = km_enable_disable_key (kmi->lv, dlg, kmi->lv_idx, i);
1919                if (!rc)
1920                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1921                break;
1922    
1923            case ID_KEYCTX_LISTSIGS:
1924                send_cmd_id (dlg, ID_KEYMISC_CHECKSIGS);
1925                break;
1926    
1927            case ID_KEYCTX_MAXTRUST:
1928                if (km_get_key (kmi->lv, kmi->lv_idx, &k))
1929                    break;
1930                rc = km_set_implicit_trust (dlg, kmi->lv, kmi->lv_idx);
1931                if (!rc)
1932                    update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1933                break;
1934    
1935            case ID_KEYCTX_SETDEFKEY:
1936                if (!km_check_key_status (kmi->lv, kmi->lv_idx)) {
1937                    key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL);
1938                    rc = set_gnupg_default_key (key->subkeys->keyid+8);
1939                    if (rc)
1940                        msg_box (dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR);
1941                    update_default_key_str (kmi->statbar);
1942                }
1943                break;
1944    
1945            case ID_KEYMISC_VIEWKEYID:
1946            case ID_KEYMISC_VIEWCIPHER:
1947            case ID_KEYMISC_VIEWTYPE:
1948            case ID_KEYMISC_VIEWCREAT:
1949            case ID_KEYMISC_VIEWDESC:
1950                hm = GetMenu (dlg);
1951                i = get_menu_state (hm, LOWORD (wparam));
1952                set_menu_state (hm, LOWORD (wparam),
1953                                i & MFS_CHECKED? MFS_UNCHECKED : MFS_CHECKED);
1954                modify_listview_columns (kmi, LOWORD (wparam), !(i & MFS_CHECKED));
1955                break;
1956    
1957            case ID_GROUP_NEW:
1958            case ID_GROUP_PASTE:
1959            case ID_GROUP_DELETE:
1960            case ID_GROUP_SHOW:
1961                /* XXX: Implement group manager. */
1962                return TRUE;
1963    
1964            case IDCANCEL:
1965                EndDialog (dlg, TRUE);
1966                return TRUE;
1967            }
1968            
1969            break;
1970        }
1971        
1972        return FALSE;
1973    }

Legend:
Removed from v.22  
changed lines
  Added in v.212

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26