changeset 1792:b0bdec1b820c

Similar fixes to the Mac one on OS/2 and Windows.... Plus a performance optimization on all three platforms. Don't redraw the window if the calculated control size did not change.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 05 Aug 2012 13:47:57 +0000
parents ed8851658015
children 2cfbfccbbafe
files mac/dw.m os2/dw.c win/dw.c
diffstat 3 files changed, 70 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Sun Aug 05 13:02:39 2012 +0000
+++ b/mac/dw.m	Sun Aug 05 13:47:57 2012 +0000
@@ -8918,9 +8918,21 @@
     /* 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);
+      int newwidth, newheight;
+      
+      _control_size(handle, &newwidth, &newheight); 
+      
+      /* Only update the item and redraw the window if it changed */
+      if((item->origwidth == -1 && item->width != newwidth) ||
+         (item->origheight == -1 && item->height != newheight))
+      {
+         if(item->origwidth == -1)
+            item->width = newwidth;
+         if(item->origheight == -1)
+            item->height = newheight;
+         /* Queue a redraw on the top-level window */
+         _dw_redraw([object window], TRUE);
+      }
     }
 }
 
--- a/os2/dw.c	Sun Aug 05 13:02:39 2012 +0000
+++ b/os2/dw.c	Sun Aug 05 13:47:57 2012 +0000
@@ -5204,10 +5204,15 @@
                thisheight = bmp.cy;
             }
        }
-       else if(dw_window_get_data(handle, "_dw_status"))
+       else
        {
-           extrawidth = 4;
-           extraheight = 4;
+            if(thiswidth == 1 && thisheight == 1)
+               dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight);
+            if(dw_window_get_data(handle, "_dw_status"))
+            {
+               extrawidth = 4;
+               extraheight = 4;
+            }
        }
    }
    /* Ranged: Slider/Percent */
@@ -7523,9 +7528,21 @@
       /* 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(_toplevel_window(handle), TRUE);
+         int newwidth, newheight;
+         
+         _control_size(handle, &newwidth, &newheight); 
+         
+         /* Only update the item and redraw the window if it changed */
+         if((item->origwidth == -1 && item->width != newwidth) ||
+            (item->origheight == -1 && item->height != newheight))
+         {
+            if(item->origwidth == -1)
+               item->width = newwidth;
+            if(item->origheight == -1)
+               item->height = newheight;
+            /* Queue a redraw on the top-level window */
+            _dw_redraw(_toplevel_window(handle), TRUE);
+         }
       }
    }
 }
--- a/win/dw.c	Sun Aug 05 13:02:39 2012 +0000
+++ b/win/dw.c	Sun Aug 05 13:47:57 2012 +0000
@@ -4572,7 +4572,6 @@
 void _control_size(HWND handle, int *width, int *height)
 {
    int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0;
-   char *buf = dw_window_get_text(handle);
    TCHAR tmpbuf[100] = {0};
    static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    HBITMAP hbm = 0;
@@ -4581,16 +4580,6 @@
 
    GetClassName(handle, tmpbuf, 99);
 
-   /* If we have a string... 
-    * calculate the size with the current font.
-    */
-   if(buf)
-   {
-      if(*buf)
-         dw_font_text_extents_get(handle, NULL, buf, &thiswidth, &thisheight);
-      dw_free(buf);
-   }
-   
    /* Attempt to get icon from classes that can have them */
    if(_tcsnicmp(tmpbuf, STATICCLASSNAME, _tcslen(STATICCLASSNAME)+1) == 0)
       hic = (HICON)SendMessage(handle, STM_GETIMAGE, IMAGE_ICON, 0);
@@ -4623,6 +4612,23 @@
       thiswidth = bmi.bmWidth;
       thisheight = bmi.bmHeight;
    }
+   else
+   {
+      char *buf = dw_window_get_text(handle);
+      
+      /* If we have a string... 
+       * calculate the size with the current font.
+       */
+      if(buf)
+      {
+         if(*buf)
+            dw_font_text_extents_get(handle, NULL, buf, &thiswidth, &thisheight);
+         else if(_tcsnicmp(tmpbuf, STATICCLASSNAME, _tcslen(STATICCLASSNAME)+1) == 0 ||
+                 _tcsnicmp(tmpbuf, StatusbarClassName, _tcslen(StatusbarClassName)+1) == 0)
+            dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight);
+         dw_free(buf);
+      }
+   }
    
    /* Combobox */
    if(_tcsnicmp(tmpbuf, COMBOBOXCLASSNAME, _tcslen(COMBOBOXCLASSNAME)+1) == 0)
@@ -6917,9 +6923,21 @@
       /* 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(_toplevel_window(handle), TRUE);
+         int newwidth, newheight;
+         
+         _control_size(handle, &newwidth, &newheight); 
+         
+         /* Only update the item and redraw the window if it changed */
+         if((item->origwidth == -1 && item->width != newwidth) ||
+            (item->origheight == -1 && item->height != newheight))
+         {
+            if(item->origwidth == -1)
+               item->width = newwidth;
+            if(item->origheight == -1)
+               item->height = newheight;
+            /* Queue a redraw on the top-level window */
+            _dw_redraw(_toplevel_window(handle), TRUE);
+         }
       }
    }
 }