Mercurial > dwindows
comparison 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 |
comparison
equal
deleted
inserted
replaced
1530:eecfceaf581f | 1531:783a464afab2 |
---|---|
327 HWND child, entry = 0; | 327 HWND child, entry = 0; |
328 | 328 |
329 henum = WinBeginEnumWindows(handle); | 329 henum = WinBeginEnumWindows(handle); |
330 while((child = WinGetNextWindow(henum)) != NULLHANDLE) | 330 while((child = WinGetNextWindow(henum)) != NULLHANDLE) |
331 { | 331 { |
332 char tmpbuf[100]; | 332 char tmpbuf[100] = {0}; |
333 | 333 |
334 WinQueryClassName(child, 99, (PCH)tmpbuf); | 334 WinQueryClassName(child, 99, (PCH)tmpbuf); |
335 | 335 |
336 if(strncmp(tmpbuf, "#6", 3)==0) /* Entryfield */ | 336 if(strncmp(tmpbuf, "#6", 3)==0) /* Entryfield */ |
337 { | 337 { |
352 HWND child; | 352 HWND child; |
353 | 353 |
354 henum = WinBeginEnumWindows(handle); | 354 henum = WinBeginEnumWindows(handle); |
355 while((child = WinGetNextWindow(henum)) != NULLHANDLE) | 355 while((child = WinGetNextWindow(henum)) != NULLHANDLE) |
356 { | 356 { |
357 char tmpbuf[100]; | 357 char tmpbuf[100] = {0}; |
358 | 358 |
359 WinQueryClassName(child, 99, (PCH)tmpbuf); | 359 WinQueryClassName(child, 99, (PCH)tmpbuf); |
360 | 360 |
361 if(strncmp(tmpbuf, "#3", 3)==0 && dw) /* Button */ | 361 if(strncmp(tmpbuf, "#3", 3)==0 && dw) /* Button */ |
362 WinSetOwner(child, dw); | 362 WinSetOwner(child, dw); |
431 } | 431 } |
432 | 432 |
433 if(ptr) | 433 if(ptr) |
434 { | 434 { |
435 WindowData *wd = (WindowData *)ptr; | 435 WindowData *wd = (WindowData *)ptr; |
436 char tmpbuf[100]; | 436 char tmpbuf[100] = {0}; |
437 | 437 |
438 WinQueryClassName(handle, 99, (PCH)tmpbuf); | 438 WinQueryClassName(handle, 99, (PCH)tmpbuf); |
439 | 439 |
440 if(strncmp(tmpbuf, "ColorSelectClass", 17)!=0) | 440 if(strncmp(tmpbuf, "ColorSelectClass", 17)!=0) |
441 { | 441 { |
522 /* This function returns 1 if the window (widget) handle | 522 /* This function returns 1 if the window (widget) handle |
523 * passed to it is a valid window that can gain input focus. | 523 * passed to it is a valid window that can gain input focus. |
524 */ | 524 */ |
525 int _validate_focus(HWND handle) | 525 int _validate_focus(HWND handle) |
526 { | 526 { |
527 char tmpbuf[100]; | 527 char tmpbuf[100] = {0}; |
528 | 528 |
529 if(!handle) | 529 if(!handle) |
530 return 0; | 530 return 0; |
531 | 531 |
532 WinQueryClassName(handle, 99, (PCH)tmpbuf); | 532 WinQueryClassName(handle, 99, (PCH)tmpbuf); |
623 | 623 |
624 lasthwnd = box->items[z].hwnd; | 624 lasthwnd = box->items[z].hwnd; |
625 } | 625 } |
626 else | 626 else |
627 { | 627 { |
628 char tmpbuf[100] = ""; | 628 char tmpbuf[100] = {0}; |
629 | 629 |
630 WinQueryClassName(box->items[z].hwnd, 99, (PCH)tmpbuf); | 630 WinQueryClassName(box->items[z].hwnd, 99, (PCH)tmpbuf); |
631 if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) | 631 if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) |
632 { | 632 { |
633 /* Then try the bottom or right box */ | 633 /* Then try the bottom or right box */ |
758 | 758 |
759 lasthwnd = box->items[z].hwnd; | 759 lasthwnd = box->items[z].hwnd; |
760 } | 760 } |
761 else | 761 else |
762 { | 762 { |
763 char tmpbuf[100] = ""; | 763 char tmpbuf[100] = {0}; |
764 | 764 |
765 WinQueryClassName(box->items[z].hwnd, 99, (PCH)tmpbuf); | 765 WinQueryClassName(box->items[z].hwnd, 99, (PCH)tmpbuf); |
766 if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) | 766 if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0) |
767 { | 767 { |
768 /* Try the top or left box */ | 768 /* Try the top or left box */ |
1003 return rc; | 1003 return rc; |
1004 } | 1004 } |
1005 | 1005 |
1006 void _check_resize_notebook(HWND hwnd) | 1006 void _check_resize_notebook(HWND hwnd) |
1007 { | 1007 { |
1008 char tmpbuf[100]; | 1008 char tmpbuf[100] = {0}; |
1009 | 1009 |
1010 WinQueryClassName(hwnd, 99, (PCH)tmpbuf); | 1010 WinQueryClassName(hwnd, 99, (PCH)tmpbuf); |
1011 | 1011 |
1012 /* If we have a notebook we resize the page again. */ | 1012 /* If we have a notebook we resize the page again. */ |
1013 if(strncmp(tmpbuf, "#40", 4)==0) | 1013 if(strncmp(tmpbuf, "#40", 4)==0) |
1252 /* If the calculated size is valid... */ | 1252 /* If the calculated size is valid... */ |
1253 if(width > 0 && height > 0) | 1253 if(width > 0 && height > 0) |
1254 { | 1254 { |
1255 int pad = thisbox->items[z].pad; | 1255 int pad = thisbox->items[z].pad; |
1256 HWND handle = thisbox->items[z].hwnd; | 1256 HWND handle = thisbox->items[z].hwnd; |
1257 char tmpbuf[100]; | 1257 char tmpbuf[100] = {0}; |
1258 | 1258 |
1259 WinQueryClassName(handle, 99, (PCH)tmpbuf); | 1259 WinQueryClassName(handle, 99, (PCH)tmpbuf); |
1260 | 1260 |
1261 if(strncmp(tmpbuf, "#2", 3)==0) | 1261 if(strncmp(tmpbuf, "#2", 3)==0) |
1262 { | 1262 { |
2122 return WinDefWindowProc(hWnd, msg, mp1, mp2); | 2122 return WinDefWindowProc(hWnd, msg, mp1, mp2); |
2123 } | 2123 } |
2124 | 2124 |
2125 void _click_default(HWND handle) | 2125 void _click_default(HWND handle) |
2126 { | 2126 { |
2127 char tmpbuf[100]; | 2127 char tmpbuf[100] = {0}; |
2128 | 2128 |
2129 WinQueryClassName(handle, 99, (PCH)tmpbuf); | 2129 WinQueryClassName(handle, 99, (PCH)tmpbuf); |
2130 | 2130 |
2131 /* These are the window classes which can | 2131 /* These are the window classes which can |
2132 * obtain input focus. | 2132 * obtain input focus. |
2169 */ | 2169 */ |
2170 MRESULT EXPENTRY _entryproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 2170 MRESULT EXPENTRY _entryproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) |
2171 { | 2171 { |
2172 WindowData *blah = (WindowData *)WinQueryWindowPtr(hWnd, QWP_USER); | 2172 WindowData *blah = (WindowData *)WinQueryWindowPtr(hWnd, QWP_USER); |
2173 PFNWP oldproc = 0; | 2173 PFNWP oldproc = 0; |
2174 char tmpbuf[100]; | 2174 char tmpbuf[100] = {0}; |
2175 | 2175 |
2176 if(blah) | 2176 if(blah) |
2177 oldproc = blah->oldproc; | 2177 oldproc = blah->oldproc; |
2178 | 2178 |
2179 WinQueryClassName(hWnd, 99, (PCH)tmpbuf); | 2179 WinQueryClassName(hWnd, 99, (PCH)tmpbuf); |
4638 * Text/Status: (textwidth)x(textheight) | 4638 * Text/Status: (textwidth)x(textheight) |
4639 */ | 4639 */ |
4640 void _control_size(HWND handle, int *width, int *height) | 4640 void _control_size(HWND handle, int *width, int *height) |
4641 { | 4641 { |
4642 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; | 4642 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; |
4643 char tmpbuf[100], *buf = dw_window_get_text(handle); | 4643 char tmpbuf[100] = {0}, *buf = dw_window_get_text(handle); |
4644 static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | 4644 static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
4645 | 4645 |
4646 WinQueryClassName(handle, 99, (PCH)tmpbuf); | 4646 WinQueryClassName(handle, 99, (PCH)tmpbuf); |
4647 | 4647 |
4648 /* If we have a string... | 4648 /* If we have a string... |
6665 * Parameters: | 6665 * Parameters: |
6666 * handle: Handle to the window. | 6666 * handle: Handle to the window. |
6667 */ | 6667 */ |
6668 void API dw_window_disable(HWND handle) | 6668 void API dw_window_disable(HWND handle) |
6669 { | 6669 { |
6670 char tmpbuf[100]; | 6670 char tmpbuf[100] = {0}; |
6671 | 6671 |
6672 if(handle < 65536) | 6672 if(handle < 65536) |
6673 { | 6673 { |
6674 char buffer[30]; | 6674 char buffer[30]; |
6675 HMENUI mymenu; | 6675 HMENUI mymenu; |
6766 */ | 6766 */ |
6767 HWND API dw_window_from_id(HWND handle, int id) | 6767 HWND API dw_window_from_id(HWND handle, int id) |
6768 { | 6768 { |
6769 HENUM henum; | 6769 HENUM henum; |
6770 HWND child; | 6770 HWND child; |
6771 char tmpbuf[100]; | 6771 char tmpbuf[100] = {0}; |
6772 | 6772 |
6773 henum = WinBeginEnumWindows(handle); | 6773 henum = WinBeginEnumWindows(handle); |
6774 while((child = WinGetNextWindow(henum)) != NULLHANDLE) | 6774 while((child = WinGetNextWindow(henum)) != NULLHANDLE) |
6775 { | 6775 { |
6776 int windowid = WinQueryWindowUShort(child, QWS_ID); | 6776 int windowid = WinQueryWindowUShort(child, QWS_ID); |
6825 | 6825 |
6826 if(thisbox) | 6826 if(thisbox) |
6827 { | 6827 { |
6828 int z, x = 0; | 6828 int z, x = 0; |
6829 Item *tmpitem, *thisitem = thisbox->items; | 6829 Item *tmpitem, *thisitem = thisbox->items; |
6830 char tmpbuf[100]; | 6830 char tmpbuf[100] = {0}; |
6831 HWND frame = (HWND)dw_window_get_data(item, "_dw_combo_box"); | 6831 HWND frame = (HWND)dw_window_get_data(item, "_dw_combo_box"); |
6832 | 6832 |
6833 /* Do some sanity bounds checking */ | 6833 /* Do some sanity bounds checking */ |
6834 if(index < 0) | 6834 if(index < 0) |
6835 index = 0; | 6835 index = 0; |
6999 * width: Width in pixels of the item or NULL if not needed. | 6999 * width: Width in pixels of the item or NULL if not needed. |
7000 * height: Height in pixels of the item or NULL if not needed. | 7000 * height: Height in pixels of the item or NULL if not needed. |
7001 */ | 7001 */ |
7002 void API dw_window_get_preferred_size(HWND handle, int *width, int *height) | 7002 void API dw_window_get_preferred_size(HWND handle, int *width, int *height) |
7003 { | 7003 { |
7004 _control_size(handle, width, height); | 7004 char tmpbuf[100] = {0}; |
7005 | |
7006 WinQueryClassName(handle, 99, (PCH)tmpbuf); | |
7007 | |
7008 if(strncmp(tmpbuf, "#1", 3)==0) | |
7009 { | |
7010 HWND box = WinWindowFromID(handle, FID_CLIENT); | |
7011 | |
7012 if(box) | |
7013 { | |
7014 unsigned long thiswidth = 0, thisheight = 0; | |
7015 | |
7016 /* Get the size with the border */ | |
7017 _get_window_for_size(handle, &thiswidth, &thisheight); | |
7018 | |
7019 /* Return what was requested */ | |
7020 if(width) *width = (int)thiswidth; | |
7021 if(height) *height = (int)thisheight; | |
7022 } | |
7023 else | |
7024 { | |
7025 Box *thisbox = WinQueryWindowPtr(handle, QWP_USER); | |
7026 | |
7027 if(thisbox) | |
7028 { | |
7029 int depth = 0; | |
7030 | |
7031 /* Calculate space requirements */ | |
7032 _resize_box(thisbox, &depth, 0, 0, 1); | |
7033 | |
7034 /* Return what was requested */ | |
7035 if(width) *width = thisbox->minwidth; | |
7036 if(height) *height = thisbox->minheight; | |
7037 } | |
7038 } | |
7039 } | |
7040 else | |
7041 _control_size(handle, width, height); | |
7005 } | 7042 } |
7006 | 7043 |
7007 /* | 7044 /* |
7008 * Returns the width of the screen. | 7045 * Returns the width of the screen. |
7009 */ | 7046 */ |
7426 * index: Item index. | 7463 * index: Item index. |
7427 * state: TRUE if selected FALSE if unselected. | 7464 * state: TRUE if selected FALSE if unselected. |
7428 */ | 7465 */ |
7429 void API dw_listbox_select(HWND handle, int index, int state) | 7466 void API dw_listbox_select(HWND handle, int index, int state) |
7430 { | 7467 { |
7431 char tmpbuf[100]; | 7468 char tmpbuf[100] = {0}; |
7432 | 7469 |
7433 WinSendMsg(handle, LM_SELECTITEM, MPFROMSHORT(index), (MPARAM)state); | 7470 WinSendMsg(handle, LM_SELECTITEM, MPFROMSHORT(index), (MPARAM)state); |
7434 | 7471 |
7435 WinQueryClassName(handle, 99, (PCH)tmpbuf); | 7472 WinQueryClassName(handle, 99, (PCH)tmpbuf); |
7436 | 7473 |