changeset 1772:5e16351b01d2

Experimental change to use NSBox to draw border of status text widgets on Mac. Probably will take some more tweaking but it should work on 10.5 and 10.8 in addition to 10.6 and 10.7 that the old method supported.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 14 Jul 2012 04:13:59 +0000
parents bed4320cb0ce
children da7786b8573f
files mac/dw.m
diffstat 1 files changed, 47 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Thu Jul 12 21:18:01 2012 +0000
+++ b/mac/dw.m	Sat Jul 14 04:13:59 2012 +0000
@@ -3552,6 +3552,27 @@
     return range;
 }
 
+/* Return the handle to the text object */
+id _text_handle(id object)
+{
+    if([object isMemberOfClass:[ DWSpinButton class]])
+    {
+        DWSpinButton *spinbutton = object;
+        object = [spinbutton textfield];
+    }
+    if([object isMemberOfClass:[ NSBox class]])
+    {
+        NSBox *box = object;
+        id content = [box contentView];
+        
+        if([content isMemberOfClass:[ DWText class]])
+        {
+            object = content;
+        }
+    }
+    return object;
+}
+
 /* Internal function to calculate the widget's required size..
  * These are the general rules for widget sizes:
  * 
@@ -3567,10 +3588,8 @@
 {
     int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0;
     NSString *nsstr = nil;
-    id object = handle;
+    id object = _text_handle(handle);
     
-    if([object isMemberOfClass:[ DWSpinButton class]])
-        object = [object textfield];
     /* Handle all the different button types */
     if([ object isKindOfClass:[ NSButton class ] ])
     {
@@ -3750,7 +3769,7 @@
     {
         thiswidth = (int)((_DW_SCROLLED_MAX_WIDTH + _DW_SCROLLED_MIN_WIDTH)/2);
         thisheight = (int)((_DW_SCROLLED_MAX_HEIGHT + _DW_SCROLLED_MIN_HEIGHT)/2);
-    }
+    }        
     /* Any other control type */
     else if([ object isKindOfClass:[ NSControl class ] ])
         nsstr = [object stringValue];
@@ -3764,17 +3783,20 @@
     /* Handle static text fields */
     if([object isKindOfClass:[ NSTextField class ]] && ![object isEditable])
     {
+        id border = handle;
+        
         /* Handle status bar field */
-        if([object isBordered] || (DWOSMinor > 5 && [object isBezeled]))
+        if([border isMemberOfClass:[ NSBox class ] ])
         {
             extrawidth = 12;
             extraheight = 4;
         }
         else
             extrawidth = 10;
+        //dw_debug("this width %d height %d extra width %d height %d \"%s\"\n", thiswidth, thisheight, extrawidth, extraheight, (char *)[nsstr UTF8String]);
     }
     
-    /* Set the requested sizes */    
+    /* Set the requested sizes */
     if(width)
         *width = thiswidth + extrawidth;
     if(height)
@@ -5316,16 +5338,18 @@
  */
 HWND API dw_status_text_new(char *text, ULONG cid)
 {
+    NSBox *border = [[NSBox alloc] init];
     NSTextField *textfield = dw_text_new(text, cid);
-    [textfield setBordered:YES];
-    if(DWOSMinor > 5 && DWOSMinor < 8)
-    {
-        [textfield setBezeled:YES];
-        [textfield setBezelStyle:NSTextFieldSquareBezel];
-    }
+    
+    [border setBorderType:NSGrooveBorder];
+    //[border setBorderType:NSLineBorder];
+    [border setTitlePosition:NSNoTitle];
+    [border setContentView:textfield];
+    [border setContentViewMargins:NSMakeSize(1,1)];
+    [textfield autorelease];
     [textfield setBackgroundColor:[NSColor clearColor]];
     [[textfield cell] setVCenter:YES];
-    return textfield;
+    return border;
 }
 
 /*
@@ -8593,7 +8617,7 @@
 
     if(font)
     {
-        id object = handle;
+        id object = _text_handle(handle);
         if([object window])
         {
             [object lockFocus];
@@ -8639,7 +8663,7 @@
  */
 char * API dw_window_get_font(HWND handle)
 {
-    id object = handle;
+    id object = _text_handle(handle);
     NSFont *font = nil;
 
     if([object isMemberOfClass:[DWGroupBox class]])
@@ -8765,23 +8789,18 @@
  */
 char * API dw_window_get_text(HWND handle)
 {
-    NSObject *object = handle;
-
-    if([object isMemberOfClass:[ DWSpinButton class]])
-    {
-        DWSpinButton *spinbutton = handle;
-        handle = object = [spinbutton textfield];
-    }
+    id object = _text_handle(handle);
+
     if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ])
     {
-        id window = handle;
+        id window = object;
         NSString *nsstr = [ window title];
 
         return strdup([ nsstr UTF8String ]);
     }
     else if([ object isKindOfClass:[ NSControl class ] ])
     {
-        NSControl *control = handle;
+        NSControl *control = object;
         NSString *nsstr = [ control stringValue];
 
         return strdup([ nsstr UTF8String ]);
@@ -8797,23 +8816,18 @@
  */
 void API dw_window_set_text(HWND handle, char *text)
 {
-    id object = handle;
-
-    if([object isMemberOfClass:[ DWSpinButton class]])
-    {
-        DWSpinButton *spinbutton = handle;
-        object = [spinbutton textfield];
-    }
+    id object = _text_handle(handle);
+
     if([ object isKindOfClass:[ NSWindow class ] ] || [ object isKindOfClass:[ NSButton class ] ])
         [object setTitle:[ NSString stringWithUTF8String:text ]];
     else if([ object isKindOfClass:[ NSControl class ] ])
     {
-        NSControl *control = handle;
+        NSControl *control = object;
         [control setStringValue:[ NSString stringWithUTF8String:text ]];
     }
     else if([object isMemberOfClass:[DWGroupBox class]])
     {
-       DWGroupBox *groupbox = handle;
+       DWGroupBox *groupbox = object;
        [groupbox setTitle:[NSString stringWithUTF8String:text]];
     }
     else