changeset 1821:69f9aa1e1b1e

Added bitmap button support to dw_window_set_bitmap() and added missing extention handling. Plus added a simple test of the code to dwtest.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 26 Oct 2012 04:46:13 +0000
parents ece7befa9f3d
children 8d231cab845d
files dwtest.c mac/dw.m
diffstat 2 files changed, 39 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/dwtest.c	Thu Oct 25 23:15:46 2012 +0000
+++ b/dwtest.c	Fri Oct 26 04:46:13 2012 +0000
@@ -1294,6 +1294,7 @@
     abutton2 = dw_bitmapbutton_new_from_file( "Bottom", 0, FOLDER_ICON_NAME );
     dw_box_pack_start( buttonsbox, abutton2, 25, 25, FALSE, FALSE, 0 );
     dw_signal_connect( abutton2, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(button_callback), NULL );
+    dw_window_set_bitmap(abutton2, 0, FILE_ICON_NAME);
 
     create_button(0);
     /* make a combobox */
--- a/mac/dw.m	Thu Oct 25 23:15:46 2012 +0000
+++ b/mac/dw.m	Fri Oct 26 04:46:13 2012 +0000
@@ -9136,22 +9136,22 @@
  */
 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, char *data, int len)
 {
-    NSObject *object = handle;
-    if([ object isKindOfClass:[ NSImageView class ] ])
+    id object = handle;
+    
+    if([ object isKindOfClass:[ NSImageView class ] ] || [ object isKindOfClass:[ NSButton class ]])
     {
         if(data)
         {
             DW_LOCAL_POOL_IN;
-            NSImageView *iv = handle;
             NSData *thisdata = [NSData dataWithBytes:data length:len];
-            NSImage *pixmap = [[NSImage alloc] initWithData:thisdata];
+            NSImage *pixmap = [[[NSImage alloc] initWithData:thisdata] autorelease];
 
             if(pixmap)
             {
-                [iv setImage:pixmap];
-            }
-            [pixmap release];
-            /* If we changed the text... */
+                [object setImage:pixmap];
+                [pixmap release];
+            }
+            /* If we changed the bitmap... */
             Item *item = _box_item(handle);
 
             /* Check to see if any of the sizes need to be recalculated */
@@ -9159,7 +9159,7 @@
             {
                 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
                 /* Queue a redraw on the top-level window */
-                _dw_redraw([iv window], TRUE);
+                _dw_redraw([object window], TRUE);
             }
             DW_LOCAL_POOL_OUT;
         }
@@ -9180,28 +9180,46 @@
  */
 void API dw_window_set_bitmap(HWND handle, unsigned long resid, char *filename)
 {
-    NSObject *object = handle;
+    id object = handle;
     DW_LOCAL_POOL_IN;
 
-    if([ object isKindOfClass:[ NSImageView class ] ])
-    {
-        NSImageView *iv = handle;
+    if([ object isKindOfClass:[ NSImageView class ] ] || [ object isKindOfClass:[ NSButton class ]])
+    {
         NSImage *bitmap = nil;
-
+        
         if(filename)
         {
-             bitmap = [[[NSImage alloc] initWithContentsOfFile:[ NSString stringWithUTF8String:filename ]] autorelease];
-        }
-        else if(resid > 0 && resid < 65536)
+            char *ext = _dw_get_image_extension( filename );
+            NSString *nstr = [ NSString stringWithUTF8String:filename ];
+            
+            bitmap = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease];
+        
+            if(!bitmap && ext)
+            {
+                nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
+                bitmap = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease];
+            }
+        }
+        if(!bitmap && resid > 0 && resid < 65536)
         {
             bitmap = _dw_icon_load(resid);
         }
 
         if(bitmap)
         {
-            [iv setImage:bitmap];
-            /* Queue a redraw on the top-level window */
-            _dw_redraw([iv window], TRUE);
+            [object setImage:bitmap];
+            
+            /* If we changed the bitmap... */
+            Item *item = _box_item(handle);
+            
+            /* Check to see if any of the sizes need to be recalculated */
+            if(item && (item->origwidth == -1 || item->origheight == -1))
+            {
+                _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
+                /* Queue a redraw on the top-level window */
+                _dw_redraw([object window], TRUE);
+            }
+            [bitmap release];
         }
     }
     DW_LOCAL_POOL_OUT;