diff os2/dw.c @ 1531:783a464afab2

Added window and box support to dw_window_get_preferred_size() on OS/2 and Windows. Fixed a number of potentially dangerous code segments on OS/2 and Windows. Updated inaccurate comments due to cut and paste and code changes and the readme.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 07 Jan 2012 13:59:58 +0000
parents 5facb5380944
children ad8181f70f31
line wrap: on
line diff
--- a/os2/dw.c	Sat Jan 07 03:46:10 2012 +0000
+++ b/os2/dw.c	Sat Jan 07 13:59:58 2012 +0000
@@ -329,7 +329,7 @@
    henum = WinBeginEnumWindows(handle);
    while((child = WinGetNextWindow(henum)) != NULLHANDLE)
    {
-      char tmpbuf[100];
+      char tmpbuf[100] = {0};
 
       WinQueryClassName(child, 99, (PCH)tmpbuf);
 
@@ -354,7 +354,7 @@
    henum = WinBeginEnumWindows(handle);
    while((child = WinGetNextWindow(henum)) != NULLHANDLE)
    {
-      char tmpbuf[100];
+      char tmpbuf[100] = {0};
 
       WinQueryClassName(child, 99, (PCH)tmpbuf);
 
@@ -433,7 +433,7 @@
    if(ptr)
    {
       WindowData *wd = (WindowData *)ptr;
-      char tmpbuf[100];
+      char tmpbuf[100] = {0};
 
       WinQueryClassName(handle, 99, (PCH)tmpbuf);
 
@@ -524,7 +524,7 @@
  */
 int _validate_focus(HWND handle)
 {
-   char tmpbuf[100];
+   char tmpbuf[100] = {0};
 
    if(!handle)
       return 0;
@@ -625,7 +625,7 @@
          }
          else
          {
-            char tmpbuf[100] = "";
+            char tmpbuf[100] = {0};
 
             WinQueryClassName(box->items[z].hwnd, 99, (PCH)tmpbuf);
             if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0)
@@ -760,7 +760,7 @@
          }
          else
          {
-            char tmpbuf[100] = "";
+            char tmpbuf[100] = {0};
 
             WinQueryClassName(box->items[z].hwnd, 99, (PCH)tmpbuf);
             if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0)
@@ -1005,7 +1005,7 @@
 
 void _check_resize_notebook(HWND hwnd)
 {
-   char tmpbuf[100];
+   char tmpbuf[100] = {0};
 
    WinQueryClassName(hwnd, 99, (PCH)tmpbuf);
 
@@ -1254,7 +1254,7 @@
          {
             int pad = thisbox->items[z].pad;
             HWND handle = thisbox->items[z].hwnd;
-            char tmpbuf[100];
+            char tmpbuf[100] = {0};
            
             WinQueryClassName(handle, 99, (PCH)tmpbuf);
 
@@ -2124,7 +2124,7 @@
 
 void _click_default(HWND handle)
 {
-   char tmpbuf[100];
+   char tmpbuf[100] = {0};
 
    WinQueryClassName(handle, 99, (PCH)tmpbuf);
 
@@ -2171,7 +2171,7 @@
 {
    WindowData *blah = (WindowData *)WinQueryWindowPtr(hWnd, QWP_USER);
    PFNWP oldproc = 0;
-   char tmpbuf[100];
+   char tmpbuf[100] = {0};
 
    if(blah)
       oldproc = blah->oldproc;
@@ -4640,7 +4640,7 @@
 void _control_size(HWND handle, int *width, int *height)
 {
    int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0;
-   char tmpbuf[100], *buf = dw_window_get_text(handle);
+   char tmpbuf[100] = {0}, *buf = dw_window_get_text(handle);
    static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
    WinQueryClassName(handle, 99, (PCH)tmpbuf);
@@ -6667,7 +6667,7 @@
  */
 void API dw_window_disable(HWND handle)
 {
-   char tmpbuf[100];
+   char tmpbuf[100] = {0};
 
    if(handle < 65536)
    {
@@ -6768,7 +6768,7 @@
 {
    HENUM henum;
    HWND child;
-   char tmpbuf[100];
+   char tmpbuf[100] = {0};
 
    henum = WinBeginEnumWindows(handle);
    while((child = WinGetNextWindow(henum)) != NULLHANDLE)
@@ -6827,7 +6827,7 @@
    {
       int z, x = 0;
       Item *tmpitem, *thisitem = thisbox->items;
-      char tmpbuf[100];
+      char tmpbuf[100] = {0};
       HWND frame = (HWND)dw_window_get_data(item, "_dw_combo_box");
 
       /* Do some sanity bounds checking */
@@ -7001,7 +7001,44 @@
  */
 void API dw_window_get_preferred_size(HWND handle, int *width, int *height)
 {
-    _control_size(handle, width, height);
+   char tmpbuf[100] = {0};
+
+   WinQueryClassName(handle, 99, (PCH)tmpbuf);
+
+   if(strncmp(tmpbuf, "#1", 3)==0)
+   {
+      HWND box = WinWindowFromID(handle, FID_CLIENT);
+      
+      if(box)
+      {
+         unsigned long thiswidth = 0, thisheight = 0;
+         
+         /* Get the size with the border */
+         _get_window_for_size(handle, &thiswidth, &thisheight);
+         
+         /* Return what was requested */
+         if(width) *width = (int)thiswidth;
+         if(height) *height = (int)thisheight;
+      }
+      else
+      {
+         Box *thisbox = WinQueryWindowPtr(handle, QWP_USER);
+         
+         if(thisbox)
+         {
+            int depth = 0;
+            
+            /* Calculate space requirements */
+            _resize_box(thisbox, &depth, 0, 0, 1);
+            
+            /* Return what was requested */
+            if(width) *width = thisbox->minwidth;
+            if(height) *height = thisbox->minheight;
+         }
+      }
+   }
+   else
+      _control_size(handle, width, height);
 }
 
 /*
@@ -7428,7 +7465,7 @@
  */
 void API dw_listbox_select(HWND handle, int index, int state)
 {
-   char tmpbuf[100];
+   char tmpbuf[100] = {0};
 
    WinSendMsg(handle, LM_SELECTITEM, MPFROMSHORT(index), (MPARAM)state);