changeset 88:58d8139fe0a2

Added vertical center logic for static text controls on windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 16 Apr 2002 19:10:16 +0000
parents 1eb72c0e8c79
children ec311fe773da
files dw.h win/dw.c
diffstat 2 files changed, 54 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Wed Apr 03 05:48:15 2002 +0000
+++ b/dw.h	Tue Apr 16 19:10:16 2002 +0000
@@ -168,7 +168,7 @@
 #define DW_DT_CENTER             SS_CENTER
 #define DW_DT_RIGHT              SS_RIGHT
 #define DW_DT_TOP                0
-#define DW_DT_VCENTER            0
+#define DW_DT_VCENTER            SS_NOPREFIX
 #define DW_DT_BOTTOM             0
 #define DW_DT_HALFTONE           0
 #define DW_DT_MNEMONIC           0
@@ -267,6 +267,7 @@
 	int back;
 	HWND combo, buddy;
 	int user;
+	int vcenter;
 	HWND clickdefault;
 	HBRUSH hbrush;
 	char fontname[128];
--- a/win/dw.c	Wed Apr 03 05:48:15 2002 +0000
+++ b/win/dw.c	Tue Apr 16 19:10:16 2002 +0000
@@ -1102,13 +1102,13 @@
 
 				GetClassName(handle, tmpbuf, 99);
 
-				if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0)
+				if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
 				{
 					/* Handle special case Combobox */
 					MoveWindow(handle, currentx + pad, currenty + pad,
 							   width + vectorx, (height + vectory) + 400, TRUE);
 				}
-				else if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS))==0)
+				else if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0)
 				{
 					/* Handle special case Spinbutton */
 					ColorInfo *cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA);
@@ -1122,6 +1122,33 @@
 								   (width + vectorx) - 20, height + vectory, TRUE);
 					}
 				}
+				else if(strnicmp(tmpbuf, STATICCLASSNAME, strlen(STATICCLASSNAME)+1)==0)
+				{
+					/* Handle special case Vertically Center static text */
+					ColorInfo *cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA);
+
+					if(cinfo && cinfo->vcenter)
+					{
+						/* We are centered so calculate a new position */
+						char tmpbuf[1024];
+						int textheight, diff, total = height + vectory;
+
+						GetWindowText(handle, tmpbuf, 1023);
+
+						/* Figure out how big the text is */
+						dw_font_text_extents(handle, 0, tmpbuf, 0, &textheight);
+
+						diff = (total - textheight) / 2;
+
+						MoveWindow(handle, currentx + pad, currenty + pad + diff,
+								   width + vectorx, height + vectory - diff, TRUE);
+					}
+					else
+					{
+						MoveWindow(handle, currentx + pad, currenty + pad,
+								   width + vectorx, height + vectory, TRUE);
+					}
+				}
 				else
 				{
 					/* Everything else */
@@ -3088,7 +3115,7 @@
 	int z, size = 9;
 	LOGFONT lf;
 
-	if(fontname == DefaultFont)
+	if(fontname == DefaultFont || !fontname[0])
 		hfont = GetStockObject(DEFAULT_GUI_FONT);
 	else
 	{
@@ -4398,11 +4425,32 @@
 void dw_window_set_style(HWND handle, ULONG style, ULONG mask)
 {
 	ULONG tmp, currentstyle = GetWindowLong(handle, GWL_STYLE);
+	ColorInfo *cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA);
 
 	tmp = currentstyle | mask;
 	tmp ^= mask;
 	tmp |= style;
 
+
+	/* We are using SS_NOPREFIX as a VCENTER flag */
+	if(tmp & SS_NOPREFIX)
+	{
+
+		if(cinfo)
+			cinfo->vcenter = 1;
+		else
+		{
+			cinfo = calloc(1, sizeof(ColorInfo));
+			cinfo->fore = cinfo->back = -1;
+			cinfo->vcenter = 1;
+
+			cinfo->pOldProc = SubclassWindow(handle, _colorwndproc);
+			SetWindowLong(handle, GWL_USERDATA, (ULONG)cinfo);
+		}
+	}
+	else if(cinfo)
+		cinfo->vcenter = 0;
+
 	SetWindowLong(handle, GWL_STYLE, tmp);
 }
 
@@ -6197,7 +6245,7 @@
 {
 	HDC hdc;
 	int mustdelete = 0;
-	HFONT hFont, oldFont;
+	HFONT hFont = NULL, oldFont;
 	SIZE sz;
 
 	if(handle)