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

Legend:
Removed from v.23  
changed lines
  Added in v.214

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26