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

Legend:
Removed from v.24  
changed lines
  Added in v.208

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26