changeset 859:80a88c91ccf6

Implemented vertical centering on text fields.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 01 Apr 2011 01:22:00 +0000
parents 80f3e108fa43
children 93ac372941c4
files dw.h mac/dw.m
diffstat 2 files changed, 42 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Thu Mar 31 23:34:12 2011 +0000
+++ b/dw.h	Fri Apr 01 01:22:00 2011 +0000
@@ -323,7 +323,7 @@
 #define DW_DT_CENTER             2 /* NSCenterTextAlignment */
 #define DW_DT_RIGHT              1 /* NSRightTextAlignment */
 #define DW_DT_TOP                0
-#define DW_DT_VCENTER            0
+#define DW_DT_VCENTER            (1 << 10)
 #define DW_DT_BOTTOM             0
 #define DW_DT_HALFTONE           0
 #define DW_DT_MNEMONIC           0
--- a/mac/dw.m	Thu Mar 31 23:34:12 2011 +0000
+++ b/mac/dw.m	Fri Apr 01 01:22:00 2011 +0000
@@ -715,6 +715,41 @@
 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
 @end
 
+/* Subclass for a textfield that supports vertical centering */
+@interface DWTextFieldCell : NSTextFieldCell
+{
+	BOOL vcenter;
+}
+-(NSRect)drawingRectForBounds:(NSRect)theRect;
+-(void)setVCenter:(BOOL)input;
+@end
+
+@implementation DWTextFieldCell
+-(NSRect)drawingRectForBounds:(NSRect)theRect
+{
+	/* Get the parent's idea of where we should draw */
+	NSRect newRect = [super drawingRectForBounds:theRect];
+    
+    /* If we are being vertically centered */
+    if(vcenter)
+    {
+        /* Get our ideal size for current text */
+        NSSize textSize = [self cellSizeForBounds:theRect];
+        
+		/* Center that in the proposed rect */
+		float heightDelta = newRect.size.height - textSize.height;	
+		if (heightDelta > 0)
+		{
+			newRect.size.height -= heightDelta;
+			newRect.origin.y += (heightDelta / 2);
+		}
+	}
+	
+	return newRect;
+}
+-(void)setVCenter:(BOOL)input { vcenter = input; }
+@end
+
 /* Subclass for a entryfield type */
 @interface DWEntryField : NSTextField
 {
@@ -6482,8 +6517,11 @@
     {
         NSTextField *tf = object;
 
-        /* TODO: See if we need to switch to a bitmask */
-        [[tf cell] setAlignment:style];
+        [[tf cell] setAlignment:(style & 0xF)];
+        if(style & DW_DT_VCENTER)
+        {
+            [[tf cell] setVCenter:YES];
+        }
     }
     else if([object isMemberOfClass:[NSTextView class]])
     {
@@ -8219,6 +8257,7 @@
     NSThread *thread = [[ NSThread alloc] initWithTarget:DWObj selector:@selector(uselessThread:) object:nil];
     [thread start];
     [thread release];
+    [NSTextField setCellClass:[DWTextFieldCell class]];
     return 0;
 }