[svn] pinentry - r160 - in trunk: . w32

svn author wk cvs at cvs.gnupg.org
Tue Jun 26 21:02:33 CEST 2007


Author: wk
Date: 2007-06-26 21:02:02 +0200 (Tue, 26 Jun 2007)
New Revision: 160

Modified:
   trunk/ChangeLog
   trunk/w32/Makefile.am
   trunk/w32/main.c
Log:
Fixed focus issues.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-06-20 14:29:22 UTC (rev 159)
+++ trunk/ChangeLog	2007-06-26 19:02:02 UTC (rev 160)
@@ -1,5 +1,16 @@
+2007-06-26  Werner Koch  <wk at g10code.com>
+
+	* w32/Makefile.am (pinentry_w32_LDFLAGS): Add -mconsole again.
+
+	* w32/main.c (dlg_proc): Set focus.
+	(resize_button): New.  No code yet.
+	(dlg_proc): Call it for the buttons.
+	(w32_cmd_handler): Restore old foreground window.
+
 2007-06-20  Werner Koch  <wk at g10code.com>
 
+	* w32/Makefile.am (pinentry_w32_LDFLAGS): Remove -mconsole.
+
 	* w32/main.c (wchar_to_utf8): New.
 	(ok_button_clicked): Use it.
 	(utf8_to_wchar): New.

Modified: trunk/w32/Makefile.am
===================================================================
--- trunk/w32/Makefile.am	2007-06-20 14:29:22 UTC (rev 159)
+++ trunk/w32/Makefile.am	2007-06-26 19:02:02 UTC (rev 160)
@@ -29,9 +29,7 @@
 
 pinentry_w32_SOURCES = main.c pinentry-w32.rc resource.h
 
-# If you want to test pinnetry on the console, you should add
-# -mconsole to the ldflags.
-pinentry_w32_LDFLAGS = -mwindows
+pinentry_w32_LDFLAGS = -mwindows -mconsole
 pinentry_w32_LDADD = pinentry-w32.o \
 	../pinentry/libpinentry.a ../assuan/libassuan.a ../secmem/libsecmem.a
 

Modified: trunk/w32/main.c
===================================================================
--- trunk/w32/main.c	2007-06-20 14:29:22 UTC (rev 159)
+++ trunk/w32/main.c	2007-06-26 19:02:02 UTC (rev 160)
@@ -1,5 +1,5 @@
 /* main.c - Secure W32 dialog for PIN entry.
-   Copyright (C) 2004 g10 Code GmbH
+   Copyright (C) 2004, 2007 g10 Code GmbH
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -116,7 +116,7 @@
 
 /* Center the window CHILDWND with the desktop as its parent
    window.  STYLE is passed as second arg to SetWindowPos.*/
-void
+static void
 center_window (HWND childwnd, HWND style) 
 {     
   HWND parwnd;
@@ -155,8 +155,23 @@
 }
 
 
+/* Resize the button so that STRING fits into it.   */
+static void
+resize_button (HWND hwnd, const char *string)
+{
+  if (!hwnd)
+    return;
 
+  /* FIXME: Need to figure out how to convert dialog coorddnates to
+     screen coordinates and how buttons should be placed.  */
+/*   SetWindowPos (hbutton, NULL, */
+/*                 10, 180,  */
+/*                 strlen (string+2), 14, */
+/*                 (SWP_NOZORDER)); */
+}
 
+
+
 
 /* Call SetDlgItemTextW with an UTF8 string.  */
 static void
@@ -185,10 +200,12 @@
 dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
 {
   static pinentry_t pe;
+  static int item;
 
   switch (msg)
     {
     case WM_INITDIALOG:
+      dialog_handle = dlg;
       pe = (pinentry_t)lparam;
       if (!pe)
         abort ();
@@ -196,21 +213,34 @@
       set_dlg_item_text (dlg, IDC_PINENT_DESC, pe->description);
       set_dlg_item_text (dlg, IDC_PINENT_TEXT, "");
       if (pe->ok)
-        set_dlg_item_text (dlg, IDOK, pe->ok);
+        {
+          set_dlg_item_text (dlg, IDOK, pe->ok);
+          resize_button (GetDlgItem (dlg, IDOK), pe->ok);
+        }
       if (pe->cancel)
-        set_dlg_item_text (dlg, IDCANCEL, pe->cancel);
+        {
+          set_dlg_item_text (dlg, IDCANCEL, pe->cancel);
+          resize_button (GetDlgItem (dlg, IDCANCEL), pe->cancel);
+        }
       if (pe->error)
         set_dlg_item_text (dlg, IDC_PINENT_ERR, pe->error);
 
+      center_window (dlg, HWND_TOP);
+
       if (confirm_mode)
         {
           EnableWindow (GetDlgItem (dlg, IDC_PINENT_TEXT), FALSE);
           SetWindowPos (GetDlgItem (dlg, IDC_PINENT_TEXT), NULL, 0, 0, 0, 0,
                         (SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_HIDEWINDOW));
+          
+          item = IDOK;
         }
+      else
+        item = IDC_PINENT_TEXT;
 
-      dialog_handle = dlg;
-      center_window (dlg, HWND_TOP);
+      if (GetDlgCtrlID ((HWND)wparam) != item) 
+        SetFocus ( GetDlgItem (dlg, item)); 
+      
       /* Fixme: There are two problems: A race condition between the
          two calls and more important that SetForegroundWindow will
          fail if a Menu is somewhere open.  */
@@ -274,17 +304,26 @@
 static int
 w32_cmd_handler (pinentry_t pe)
 {
+  HWND lastwindow = GetForegroundWindow ();
+
   confirm_mode = !pe->pin;
 
   passphrase_ok = confirm_yes = 0;
 
+  dialog_handle = NULL;
   DialogBoxParam (NULL, (LPCTSTR) IDD_PINENT,
                   GetDesktopWindow (), dlg_proc, (LPARAM)pe);
-  ShowWindow (dialog_handle, SW_SHOWNORMAL);
-  if (lock_set_foreground_window)
-    lock_set_foreground_window (LSFW_UNLOCK);
-  DestroyWindow (dialog_handle);
-  dialog_handle = NULL;
+  if (dialog_handle)
+    {
+      ShowWindow (dialog_handle, SW_SHOWNORMAL);
+      if (lock_set_foreground_window)
+        lock_set_foreground_window (LSFW_UNLOCK);
+      if (lastwindow)
+        SetForegroundWindow (lastwindow);
+    }
+  else
+    return -1;
+
   if (confirm_mode)
     return confirm_yes;
   else if (passphrase_ok && pe->pin)




More information about the Gnupg-commits mailing list