[3002] in Kerberos-V5-bugs

home help back first fref pref prev next nref lref last post

krb5-clients/660: windows vardlg (new creds "prompter") doesn't size well.

daemon@ATHENA.MIT.EDU (fcusack@iconnet.net)
Wed Nov 11 19:17:18 1998

Resent-From: gnats@rt-11.MIT.EDU (GNATS Management)
Resent-To: krb5-unassigned@RT-11.MIT.EDU
Resent-Reply-To: krb5-bugs@MIT.EDU, fcusack@iconnet.net
Date: Wed, 11 Nov 1998 19:11:26 -0500 (EST)
From: fcusack@iconnet.net
Reply-To: fcusack@iconnet.net
To: krb5-bugs@MIT.EDU


>Number:         660
>Category:       krb5-clients
>Synopsis:       windows vardlg (new creds "prompter") doesn't size well.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    krb5-unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   unknown
>Arrival-Date:   Wed Nov 11 19:11:00 EST 1998
>Last-Modified:
>Originator:     Frank Cusack
>Organization:
Icon CMT Corp.
>Release:        krb5-current-19981012
>Environment:
All Win32
System: SunOS ratbert 5.6 Generic_105181-09 sun4u sparc SUNW,Ultra-5_10
Architecture: sun4

>Description:
	vardlg.c uses GetTextExtentPoint32() but doesn't set the font
	first. This causes the extents returned to be wrong.

	This also contains another patch to windows/lib/gic.c that
	corrects a previous patch I submitted about the sam-type-name
	being passed to the prompter. This patch should be applied
	in addition to the previous one. The id was krb5-libs/658
	and krb5-libs/659.
>How-To-Repeat:
	Use SAM preauth, the dialog will come up poorly sized.
>Fix:
Index: vardlg.c
===================================================================
RCS file: /icon/d04/cvsroot/3rd-party/krb5/src/windows/lib/vardlg.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- vardlg.c	1998/11/11 21:44:33	1.3
+++ vardlg.c	1998/11/11 22:55:29	1.4
@@ -227,8 +227,12 @@
 #define SPACE_X     4  /* logical units */
 #define ENTRY_PX  120  /* pixels */
 #define BUTTON_PX  70  /* pixels */
-#define BUTTON_PY  30  /* pixels */
+#define BUTTON_PY  25  /* pixels */
 
+/* width is not used. also, any previous attempts to limit
+   window size to MIN_WIDTH/MAX_WIDTH are ignored. sigh. */
+/* should not return void? or some things should be done elsewhere */
+/* Does not handle multi-line banners correctly */
 void
 vardlg_config(HWND hwnd, WORD width, const char *banner, WORD num_prompts,
 	      krb5_prompt *prompts, WORD id)
@@ -237,15 +241,15 @@
 	WORD        cid;
 	HDC         hdc;
 	SIZE        csize;
+	SIZE		bsize; /* banner text size */
+	SIZE		psize; /* (max) prompt + space + entry field */
 	SIZE        maxsize;
 	LONG        cx, cy;
 	LONG        ccx, ccy;
 	LONG        space_x, space_y;
-	LONG        max_x, max_y;
-	LONG        banner_y;
+	LONG        max_x, max_y, ban_x, ban_y;
 	RECT        rect;
-	int         done;
-	const char *p;
+	HFONT		hFont;
 
 	/*
 	 * First, set the banner's text.
@@ -270,10 +274,34 @@
 	/*
 	 * Now run through the entry fields and find the longest string.
 	 */
-	maxsize.cx = maxsize.cy = 0;
-	cid = (id + 1);
+    maxsize.cx = maxsize.cy = 0;
+	cid = (id + 3);
 	hdc = GetDC(GetDlgItem(hwnd, cid)); /* assume one label is the same as all the others */
 
+	/*
+	 * First set the font. Do it the long way; I'm not so sure
+	 * CreateFontIndirect() will correctly setup with minimal input.
+	 */
+
+	hFont = CreateFont(-MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72), /* nHeight */
+		               0,                              /* nWidth */
+				       0,                              /* nEscapement */
+					   0,                              /* nOrientation */
+					   FW_NORMAL,                      /* fnWeight */
+					   0,                              /* fdwItalic */
+					   0,                              /* fdwUnderline */
+					   0,                              /* fdwStrikeOut */
+					   DEFAULT_CHARSET,                /* fdwCharSet */
+					   OUT_DEFAULT_PRECIS,             /* fdwOutputPrecision */
+					   CLIP_DEFAULT_PRECIS,            /* fdwClipPrecision */
+					   DEFAULT_QUALITY,                /* fdwQuality */
+					   DEFAULT_PITCH | FF_DONTCARE,    /* fdwPitchAndFamily */
+					   "MS Sans Serif");               /* lpszFace */
+	
+	if (!hFont) /* Something is seriously screwed. */
+		return;
+
+	hFont = SelectObject(hdc, hFont); /* Setup for GetTextExtentPoint32() */
 	for (n = 0 ; n < num_prompts ; n++) {
 		GetTextExtentPoint32(hdc, prompts[n].prompt, strlen(prompts[n].prompt), &csize);
 		if (csize.cx > maxsize.cx)
@@ -282,22 +310,8 @@
 			maxsize.cy = csize.cy;
 	}
 
-#if 0
-	/*
-	 * convert the maximum values into pixels.  Ugh.
-	 */
-	rect.left = 0;
-	rect.top = 0;
-	rect.right = maxsize.cx;
-	rect.bottom = maxsize.cy;
-	MapDialogRect(hwnd, &rect);
-
-	max_x = rect.right;
-	max_y = rect.bottom;
-#else
 	max_x = maxsize.cx;
-	max_y = (long)(((double)maxsize.cy) * 1.5);
-#endif
+	max_y = maxsize.cy + 10; /* fudge for edit box height */
 
 	/*
 	 * convert the spacing values, too.  Ugh.  Ugh.
@@ -318,10 +332,24 @@
 	 * spacing between the edges of the windows and the static and edit fields, and
 	 * between the static and edit fields themselves.)
 	 */
+	psize.cx = max_x + ENTRY_PX + space_x;
 	cx = max_x + ENTRY_PX + (space_x * 3);
 	cy = (max_y + space_y) * num_prompts;
 
 	/*
+	 * Extend the width to the banner size
+	 */
+	GetTextExtentPoint32(hdc, banner, strlen(banner), &bsize);
+
+	ban_x = bsize.cx;
+	ban_y = bsize.cy;
+	if (ban_x > max_x + ENTRY_PX + space_x)
+		cx = ban_x + (space_x * 2);
+
+	hFont = SelectObject(hdc, hFont); /* Restore old Font */
+	DeleteObject(hFont);
+
+	/*
 	 * resize the dialog box itself (take 1)
 	 */
 	SetWindowPos(hwnd, HWND_TOPMOST,
@@ -337,6 +365,7 @@
 		(cx - space_x * 2), max_y,
 		0);
 
+#if 0
 	/*
 	 * Now that the window for the banner is in place, convert the width into logical units
 	 * and find out how many lines we need to reserve room for.
@@ -361,13 +390,14 @@
 	} while (*p != 0);
 
 	banner_y += space_y;
+#endif
 
 	/*
 	 * position the banner (take 2)
 	 */
 	SetWindowPos(GetDlgItem(hwnd, id), HWND_BOTTOM,
 		space_x, space_y,
-		(cx - space_x * 2), banner_y,
+		(cx - space_x * 2), ban_y,
 		0);
 
 	/*
@@ -376,7 +406,7 @@
 	 * for between the top of the dialog and the banner, between the banner and the
 	 * first label, and between the buttons and the bottom of the screen.
 	 */
-	cy += banner_y + BUTTON_PY + (space_y * 3);
+	cy += ban_y + BUTTON_PY + (space_y * 3);
 
 	/*
 	 * resize the dialog box itself (Again...  ugh!)
@@ -387,12 +417,12 @@
 		SWP_NOMOVE);
 
 	cid = (id + 1);
-	ccy = banner_y + (space_y * 2);
-	ccx = max_x + (space_x * 2);  /* where the edit fields start */
+	ccy = ban_y + (space_y * 2);
+	ccx = cx - (ENTRY_PX + space_x);
 
 	for (n = 0 ; n < num_prompts ; n++) {
 		SetWindowPos(GetDlgItem(hwnd, cid), HWND_BOTTOM,
-			space_x, ccy,
+			ccx - (max_x + space_x), ccy + 3,
 			max_x, max_y, 0);
 		cid++;
 		SetWindowPos(GetDlgItem(hwnd, cid), HWND_BOTTOM,
@@ -412,10 +442,12 @@
 			BUTTON_PX, BUTTON_PY, 0);
 	} else {
 		SetWindowPos(GetDlgItem(hwnd, IDOK), HWND_BOTTOM,
-			space_x, cy - space_y - BUTTON_PY,
+			/* space_x, cy - space_y - BUTTON_PY, */
+			space_x, ccy,
 			BUTTON_PX, BUTTON_PY, 0);
 		SetWindowPos(GetDlgItem(hwnd, IDCANCEL), HWND_BOTTOM,
-			cx - space_x - BUTTON_PX, cy - space_y - BUTTON_PY,
+			/* cx - space_x - BUTTON_PX, cy - space_y - BUTTON_PY, */
+			cx - space_x - BUTTON_PX, ccy,
 			BUTTON_PX, BUTTON_PY, 0);
 	}
 
Index: gic.c
===================================================================
RCS file: /icon/d04/cvsroot/3rd-party/krb5/src/windows/lib/gic.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- gic.c	1998/11/11 22:39:18	1.2
+++ gic.c	1998/11/12 00:04:57	1.3
@@ -139,14 +139,13 @@
 
 	gd = data;
 
-	gd->name = name;
 	gd->banner = banner;
 	gd->num_prompts = num_prompts;
 	gd->prompts = prompts;
 	if (gd->width == 0)
 		gd->width = 450;
 
-	dlg = vardlg_build((WORD)(gd->width), gd->name, gd->banner,
+	dlg = vardlg_build((WORD)(gd->width), name, gd->banner,
 			   (WORD)num_prompts, prompts, (WORD)(gd->id));
 
 	rc = DialogBoxIndirect(gd->hinstance, (LPDLGTEMPLATE)dlg, gd->hwnd, gic_dialog);
>Audit-Trail:
>Unformatted:

home help back first fref pref prev next nref lref last post