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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26