# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1325944798 0 # Node ID 783a464afab257b4db5567ac7fdcd969255fe857 # Parent eecfceaf581f9d787928a7bd5375b9c8498ea537 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. diff -r eecfceaf581f -r 783a464afab2 mac/dw.m --- a/mac/dw.m Sat Jan 07 03:46:10 2012 +0000 +++ b/mac/dw.m Sat Jan 07 13:59:58 2012 +0000 @@ -8524,7 +8524,7 @@ /* Calculate space requirements */ _resize_box(thisbox, &depth, (int)width, (int)height, 1); - /* Might need to take into account the window border here */ + /* Update components that need auto-sizing */ if(width < 1) content.size.width = thisbox->minwidth; if(height < 1) content.size.height = thisbox->minheight; } @@ -8558,9 +8558,10 @@ /* Calculate space requirements */ _resize_box(thisbox, &depth, 0, 0, 1); + /* Figure out the border size */ frame = [NSWindow frameRectForContentRect:NSMakeRect(0, 0, thisbox->minwidth, thisbox->minheight) styleMask:[object styleMask]]; - /* Might need to take into account the window border here */ + /* Return what was requested */ if(width) *width = frame.size.width; if(height) *height = frame.size.height; } @@ -8576,7 +8577,7 @@ /* Calculate space requirements */ _resize_box(thisbox, &depth, 0, 0, 1); - /* Might need to take into account the window border here */ + /* Return what was requested */ if(width) *width = thisbox->minwidth; if(height) *height = thisbox->minheight; } diff -r eecfceaf581f -r 783a464afab2 os2/dw.c --- 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); diff -r eecfceaf581f -r 783a464afab2 readme --- a/readme Sat Jan 07 03:46:10 2012 +0000 +++ b/readme Sat Jan 07 13:59:58 2012 +0000 @@ -40,10 +40,10 @@ Added automatic window redraw support for OS/2, Windows and Mac. Added dw_window_set_gravity() for enhanced window placement. Added DW_GRAV_OBSTACLES support for using system obstacles as gravity - anchor points on OS/2, Mac and Windows. + anchor points on OS/2, Mac, Windows and GTK3 (3.4 and later). Added automatic window border detection on GTK. This eliminates the need for the DW_BORDER_* environment variables. -Added Open Watcom compiler support for OS/2. +Added Open Watcom compiler support for OS/2 (Thanks Andy Willis). Added pseudo transparent background widget support on Windows and OS/2. If you set the background color of a widget to DW_RGB_TRANSPARENT... it will attempt to use the background color of the parent. @@ -55,7 +55,7 @@ Added dw_main_quit() to cause the dw_main() message loop to return. Fixed auto-sizing top-level windows on Windows; added on OS/2 and Mac. Fixed bubble help not being displayed on Windows. -Fixed menu bar items remaining highlighted on Mac. +Fixed menu bar items remaining highlighted on Mac 10.6 and later. Fixed OS/2 and Windows showing windows during dw_window_set_pos/size(). Deprecated DW_FCF_NOBYTEALIGN and DW_FCF_SHELLPOSITION flags. diff -r eecfceaf581f -r 783a464afab2 win/dw.c --- a/win/dw.c Sat Jan 07 03:46:10 2012 +0000 +++ b/win/dw.c Sat Jan 07 13:59:58 2012 +0000 @@ -582,7 +582,7 @@ ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); HICON oldicon = (HICON)SendMessage(handle, WM_GETICON, 0, 0); - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -729,7 +729,7 @@ */ int _validate_focus(HWND handle) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; if(!handle) return 0; @@ -756,7 +756,7 @@ HWND _normalize_handle(HWND handle) { - char tmpbuf[100] = ""; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS))==0) /* Spinner */ @@ -851,7 +851,7 @@ } else { - char tmpbuf[100] = ""; + char tmpbuf[100] = {0}; GetClassName(box->items[z].hwnd, tmpbuf, 99); @@ -986,7 +986,7 @@ } else { - char tmpbuf[100] = ""; + char tmpbuf[100] = {0}; GetClassName(box->items[z].hwnd, tmpbuf, 99); @@ -1052,7 +1052,7 @@ void _initial_focus(HWND handle) { Box *thisbox; - char tmpbuf[100]; + char tmpbuf[100] = {0}; if(!handle) return; @@ -1086,7 +1086,7 @@ } if(lastbox) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(lastbox, tmpbuf, 99); @@ -1334,7 +1334,7 @@ { int pad = thisbox->items[z].pad; HWND handle = thisbox->items[z].hwnd; - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -1442,7 +1442,7 @@ if(cinfo && cinfo->vcenter) { /* We are centered so calculate a new position */ - char tmpbuf[1024]; + char tmpbuf[1024] = {0}; int textheight, diff, total = height; GetWindowText(handle, tmpbuf, 1023); @@ -1857,7 +1857,7 @@ { NMTREEVIEW FAR *tem=(NMTREEVIEW FAR *)mp2; NMLISTVIEW FAR *lem=(NMLISTVIEW FAR *)mp2; - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(tem->hdr.hwndFrom, tmpbuf, 99); @@ -2029,7 +2029,7 @@ case WM_HSCROLL: case WM_VSCROLL: { - char tmpbuf[100] = ""; + char tmpbuf[100] = {0}; HWND handle = (HWND)mp2; int (*valuechangefunc)(HWND, int, void *) = tmp->signalfunction; @@ -2172,7 +2172,6 @@ case WM_VSCROLL: { HWND handle = (HWND)mp2; - char tmpbuf[100]; int bar = (origmsg == WM_HSCROLL) ? SB_HORZ : SB_VERT; if(dw_window_get_data(handle, "_dw_scrollbar")) @@ -2184,6 +2183,8 @@ } else { + char tmpbuf[100] = {0}; + GetClassName( hWnd, tmpbuf, 99 ); if ( strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1 ) == 0 ) { @@ -2494,7 +2495,7 @@ void _click_default(HWND handle) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -2531,7 +2532,7 @@ BOOL CALLBACK _colorwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) { ColorInfo *cinfo; - char tmpbuf[100]; + char tmpbuf[100] = {0}; WNDPROC pOldProc = 0; int ret = -1; @@ -4231,7 +4232,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"; HBITMAP hbm = 0; @@ -4352,7 +4353,7 @@ { HFONT hfont, oldfont; ColorInfo *cinfo; - char tmpbuf[100]; + char tmpbuf[100] = {0}; cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); @@ -4467,7 +4468,7 @@ char *italic = ""; LOGFONT lf = { 0 }; Box *thisbox; - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); if ( strnicmp( tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1) == 0 ) @@ -4513,7 +4514,7 @@ { ColorInfo *cinfo; Box *thisbox; - char tmpbuf[100]; + char tmpbuf[100] = {0}; cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); @@ -6265,7 +6266,7 @@ void API dw_window_set_text(HWND handle, char *text) { Box *thisbox; - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -6325,7 +6326,7 @@ */ char * API dw_window_get_text(HWND handle) { - char tmpbuf[100], *tempbuf; + char tmpbuf[100] = {0}, *tempbuf; int len; GetClassName(handle, tmpbuf, 99); @@ -6423,7 +6424,7 @@ void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname) { Box *thisbox = NULL; - char tmpbuf[100]; + char tmpbuf[100] = {0}; /* * If you try and pack an item into itself VERY bad things can happen; like at least an @@ -6643,7 +6644,39 @@ */ void API dw_window_get_preferred_size(HWND handle, int *width, int *height) { - _control_size(handle, width, height); + char tmpbuf[100] = {0}; + + GetClassName(handle, tmpbuf, 99); + + if(strnicmp(tmpbuf, ClassName, strlen(ClassName)+1) == 0) + { + 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 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1) == 0) + { + Box *thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA); + + 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); } /* @@ -7118,7 +7151,7 @@ */ void API dw_listbox_append(HWND handle, char *text) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -7141,7 +7174,7 @@ */ void API dw_listbox_list_append(HWND handle, char **text, int count) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; int listbox_type; int i; @@ -7165,7 +7198,7 @@ */ void API dw_listbox_insert(HWND handle, char *text, int pos) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -7186,7 +7219,7 @@ */ void API dw_listbox_clear(HWND handle) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -7217,7 +7250,7 @@ */ void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -7246,7 +7279,7 @@ */ void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; int len; if(!buffer || !length) @@ -7281,7 +7314,7 @@ */ int API dw_listbox_selected(HWND handle) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -7304,7 +7337,7 @@ int API dw_listbox_selected_multi(HWND handle, int where) { int *array, count, z; - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -7347,7 +7380,7 @@ */ void API dw_listbox_select(HWND handle, int index, int state) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -7369,7 +7402,7 @@ */ void API dw_listbox_delete(HWND handle, int index) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -7386,7 +7419,7 @@ */ int API dw_listbox_count(HWND handle) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -7406,7 +7439,7 @@ */ void API dw_listbox_set_top(HWND handle, int top) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99); @@ -7832,7 +7865,7 @@ /* This function unchecks all radiobuttons on a box */ BOOL CALLBACK _uncheck_radios(HWND handle, LPARAM lParam) { - char tmpbuf[100]; + char tmpbuf[100] = {0}; GetClassName(handle, tmpbuf, 99);