Mercurial > dwindows
comparison os2/dw.c @ 1085:5a951cfd67ad
Merge all 3 box packing functions into one internal function on OS/2.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 28 Jun 2011 18:27:12 +0000 |
parents | 6eadfe0007b4 |
children | e24e5a13ff2c |
comparison
equal
deleted
inserted
replaced
1084:fa219e997fb8 | 1085:5a951cfd67ad |
---|---|
5970 } | 5970 } |
5971 WinEndEnumWindows(henum); | 5971 WinEndEnumWindows(henum); |
5972 return NULLHANDLE; | 5972 return NULLHANDLE; |
5973 } | 5973 } |
5974 | 5974 |
5975 /* Internal box packing function called by the other 3 functions */ | |
5976 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname) | |
5977 { | |
5978 Box *thisbox; | |
5979 | |
5980 /* | |
5981 * If you try and pack an item into itself VERY bad things can happen; like at least an | |
5982 * infinite loop on GTK! Lets be safe! | |
5983 */ | |
5984 if(box == item) | |
5985 { | |
5986 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); | |
5987 return; | |
5988 } | |
5989 | |
5990 if(WinWindowFromID(box, FID_CLIENT)) | |
5991 { | |
5992 HWND intbox = (HWND)dw_window_get_data(box, "_dw_box"); | |
5993 if(intbox) | |
5994 { | |
5995 box = intbox; | |
5996 } | |
5997 else | |
5998 { | |
5999 box = WinWindowFromID(box, FID_CLIENT); | |
6000 hsize = vsize = TRUE; | |
6001 } | |
6002 } | |
6003 | |
6004 thisbox = WinQueryWindowPtr(box, QWP_USER); | |
6005 | |
6006 if(thisbox) | |
6007 { | |
6008 int z, x = 0; | |
6009 Item *tmpitem, *thisitem = thisbox->items; | |
6010 char tmpbuf[100]; | |
6011 HWND frame = (HWND)dw_window_get_data(item, "_dw_combo_box"); | |
6012 | |
6013 /* Do some sanity bounds checking */ | |
6014 if(index < 0) | |
6015 index = 0; | |
6016 if(index > thisbox->count) | |
6017 index = thisbox->count; | |
6018 | |
6019 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | |
6020 | |
6021 for(z=0;z<thisbox->count;z++) | |
6022 { | |
6023 if(z == index) | |
6024 x++; | |
6025 tmpitem[x] = thisitem[z]; | |
6026 x++; | |
6027 } | |
6028 | |
6029 | |
6030 WinQueryClassName(item, 99, tmpbuf); | |
6031 | |
6032 if(vsize && !height) | |
6033 height = 1; | |
6034 if(hsize && !width) | |
6035 width = 1; | |
6036 | |
6037 if(strncmp(tmpbuf, "#1", 3)==0) | |
6038 tmpitem[index].type = TYPEBOX; | |
6039 else | |
6040 { | |
6041 if ( width == 0 && hsize == FALSE ) | |
6042 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | |
6043 if ( height == 0 && vsize == FALSE ) | |
6044 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); | |
6045 | |
6046 tmpitem[index].type = TYPEITEM; | |
6047 } | |
6048 | |
6049 tmpitem[index].hwnd = item; | |
6050 tmpitem[index].origwidth = tmpitem[index].width = width; | |
6051 tmpitem[index].origheight = tmpitem[index].height = height; | |
6052 tmpitem[index].pad = pad; | |
6053 if(hsize) | |
6054 tmpitem[index].hsize = SIZEEXPAND; | |
6055 else | |
6056 tmpitem[index].hsize = SIZESTATIC; | |
6057 | |
6058 if(vsize) | |
6059 tmpitem[index].vsize = SIZEEXPAND; | |
6060 else | |
6061 tmpitem[index].vsize = SIZESTATIC; | |
6062 | |
6063 thisbox->items = tmpitem; | |
6064 | |
6065 if(thisbox->count) | |
6066 free(thisitem); | |
6067 | |
6068 thisbox->count++; | |
6069 | |
6070 WinQueryClassName(item, 99, tmpbuf); | |
6071 /* Don't set the ownership if it's an entryfield or spinbutton */ | |
6072 if(strncmp(tmpbuf, "#6", 3)!=0 && strncmp(tmpbuf, "#32", 4)!=0 && strncmp(tmpbuf, "#2", 3)!=0) | |
6073 WinSetOwner(item, box); | |
6074 WinSetParent(frame ? frame : item, box, FALSE); | |
6075 } | |
6076 } | |
6077 | |
5975 /* | 6078 /* |
5976 * Pack windows (widgets) into a box at an arbitrary location. | 6079 * Pack windows (widgets) into a box at an arbitrary location. |
5977 * Parameters: | 6080 * Parameters: |
5978 * box: Window handle of the box to be packed into. | 6081 * box: Window handle of the box to be packed into. |
5979 * item: Window handle of the item to be back. | 6082 * item: Window handle of the item to be back. |
5984 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | 6087 * vsize: TRUE if the window (widget) should expand vertically to fill space given. |
5985 * pad: Number of pixels of padding around the item. | 6088 * pad: Number of pixels of padding around the item. |
5986 */ | 6089 */ |
5987 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad) | 6090 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad) |
5988 { | 6091 { |
5989 char *funcname = "dw_box_pack_at_index()"; | 6092 _dw_box_pack(box, item, index, width, height, hsize, vsize, pad, "dw_box_pack_at_index()"); |
5990 Box *thisbox; | 6093 } |
5991 | 6094 |
5992 /* | 6095 /* |
5993 * If you try and pack an item into itself VERY bad things can happen; like at least an | 6096 * Pack windows (widgets) into a box from the start (or top). |
5994 * infinite loop on GTK! Lets be safe! | |
5995 */ | |
5996 if(box == item) | |
5997 { | |
5998 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); | |
5999 return; | |
6000 } | |
6001 | |
6002 if(WinWindowFromID(box, FID_CLIENT)) | |
6003 { | |
6004 HWND intbox = (HWND)dw_window_get_data(box, "_dw_box"); | |
6005 if(intbox) | |
6006 { | |
6007 box = intbox; | |
6008 } | |
6009 else | |
6010 { | |
6011 box = WinWindowFromID(box, FID_CLIENT); | |
6012 hsize = vsize = TRUE; | |
6013 } | |
6014 } | |
6015 | |
6016 thisbox = WinQueryWindowPtr(box, QWP_USER); | |
6017 | |
6018 if(thisbox) | |
6019 { | |
6020 int z, x = 0; | |
6021 Item *tmpitem, *thisitem = thisbox->items; | |
6022 char tmpbuf[100]; | |
6023 HWND frame = (HWND)dw_window_get_data(item, "_dw_combo_box"); | |
6024 | |
6025 /* Do some sanity bounds checking */ | |
6026 if(index < 0) | |
6027 index = 0; | |
6028 if(index > thisbox->count) | |
6029 index = thisbox->count; | |
6030 | |
6031 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | |
6032 | |
6033 for(z=0;z<thisbox->count;z++) | |
6034 { | |
6035 if(z == index) | |
6036 x++; | |
6037 tmpitem[x] = thisitem[z]; | |
6038 x++; | |
6039 } | |
6040 | |
6041 | |
6042 WinQueryClassName(item, 99, tmpbuf); | |
6043 | |
6044 if(vsize && !height) | |
6045 height = 1; | |
6046 if(hsize && !width) | |
6047 width = 1; | |
6048 | |
6049 if(strncmp(tmpbuf, "#1", 3)==0) | |
6050 tmpitem[index].type = TYPEBOX; | |
6051 else | |
6052 { | |
6053 if ( width == 0 && hsize == FALSE ) | |
6054 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | |
6055 if ( height == 0 && vsize == FALSE ) | |
6056 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); | |
6057 | |
6058 tmpitem[index].type = TYPEITEM; | |
6059 } | |
6060 | |
6061 tmpitem[index].hwnd = item; | |
6062 tmpitem[index].origwidth = tmpitem[index].width = width; | |
6063 tmpitem[index].origheight = tmpitem[index].height = height; | |
6064 tmpitem[index].pad = pad; | |
6065 if(hsize) | |
6066 tmpitem[index].hsize = SIZEEXPAND; | |
6067 else | |
6068 tmpitem[index].hsize = SIZESTATIC; | |
6069 | |
6070 if(vsize) | |
6071 tmpitem[index].vsize = SIZEEXPAND; | |
6072 else | |
6073 tmpitem[index].vsize = SIZESTATIC; | |
6074 | |
6075 thisbox->items = tmpitem; | |
6076 | |
6077 if(thisbox->count) | |
6078 free(thisitem); | |
6079 | |
6080 thisbox->count++; | |
6081 | |
6082 WinQueryClassName(item, 99, tmpbuf); | |
6083 /* Don't set the ownership if it's an entryfield or spinbutton */ | |
6084 if(strncmp(tmpbuf, "#6", 3)!=0 && strncmp(tmpbuf, "#32", 4)!=0 && strncmp(tmpbuf, "#2", 3)!=0) | |
6085 WinSetOwner(item, box); | |
6086 WinSetParent(frame ? frame : item, box, FALSE); | |
6087 } | |
6088 } | |
6089 | |
6090 /* | |
6091 * Pack windows (widgets) into a box from the end (or bottom). | |
6092 * Parameters: | 6097 * Parameters: |
6093 * box: Window handle of the box to be packed into. | 6098 * box: Window handle of the box to be packed into. |
6094 * item: Window handle of the item to be back. | 6099 * item: Window handle of the item to be back. |
6095 * width: Width in pixels of the item or -1 to be self determined. | 6100 * width: Width in pixels of the item or -1 to be self determined. |
6096 * height: Height in pixels of the item or -1 to be self determined. | 6101 * height: Height in pixels of the item or -1 to be self determined. |
6097 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | 6102 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. |
6098 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | 6103 * vsize: TRUE if the window (widget) should expand vertically to fill space given. |
6099 * pad: Number of pixels of padding around the item. | 6104 * pad: Number of pixels of padding around the item. |
6100 */ | 6105 */ |
6106 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | |
6107 { | |
6108 /* 65536 is the table limit on GTK... | |
6109 * seems like a high enough value we will never hit it here either. | |
6110 */ | |
6111 _dw_box_pack(box, item, 65536, width, height, hsize, vsize, pad, "dw_box_pack_start()"); | |
6112 } | |
6113 | |
6114 /* | |
6115 * Pack windows (widgets) into a box from the end (or bottom). | |
6116 * Parameters: | |
6117 * box: Window handle of the box to be packed into. | |
6118 * item: Window handle of the item to be back. | |
6119 * width: Width in pixels of the item or -1 to be self determined. | |
6120 * height: Height in pixels of the item or -1 to be self determined. | |
6121 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | |
6122 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | |
6123 * pad: Number of pixels of padding around the item. | |
6124 */ | |
6101 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 6125 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
6102 { | 6126 { |
6103 char *funcname = "dw_box_pack_end()"; | 6127 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()"); |
6104 | |
6105 /* | |
6106 * If you try and pack an item into itself VERY bad things can happen; like at least an | |
6107 * infinite loop on GTK! Lets be safe! | |
6108 */ | |
6109 if(box == item) | |
6110 { | |
6111 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); | |
6112 return; | |
6113 } | |
6114 | |
6115 if(WinWindowFromID(box, FID_CLIENT)) | |
6116 { | |
6117 HWND intbox = (HWND)dw_window_get_data(box, "_dw_box"); | |
6118 if(intbox) | |
6119 { | |
6120 box = intbox; | |
6121 } | |
6122 else | |
6123 { | |
6124 box = WinWindowFromID(box, FID_CLIENT); | |
6125 hsize = vsize = TRUE; | |
6126 } | |
6127 } | |
6128 _dw_box_pack_end(box, item, width, height, hsize, vsize, pad, funcname); | |
6129 } | |
6130 | |
6131 void _dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname) | |
6132 { | |
6133 Box *thisbox = WinQueryWindowPtr(box, QWP_USER); | |
6134 | |
6135 if(thisbox) | |
6136 { | |
6137 int z; | |
6138 Item *tmpitem, *thisitem = thisbox->items; | |
6139 char tmpbuf[100]; | |
6140 HWND frame = (HWND)dw_window_get_data(item, "_dw_combo_box"); | |
6141 | |
6142 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | |
6143 | |
6144 for(z=0;z<thisbox->count;z++) | |
6145 { | |
6146 tmpitem[z+1] = thisitem[z]; | |
6147 } | |
6148 | |
6149 WinQueryClassName(item, 99, tmpbuf); | |
6150 | |
6151 if(vsize && !height) | |
6152 height = 1; | |
6153 if(hsize && !width) | |
6154 width = 1; | |
6155 | |
6156 if(strncmp(tmpbuf, "#1", 3)==0) | |
6157 tmpitem[0].type = TYPEBOX; | |
6158 else | |
6159 { | |
6160 if ( width == 0 && hsize == FALSE ) | |
6161 dw_messagebox(functionname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | |
6162 if ( height == 0 && vsize == FALSE ) | |
6163 dw_messagebox(functionname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); | |
6164 | |
6165 tmpitem[0].type = TYPEITEM; | |
6166 } | |
6167 | |
6168 tmpitem[0].hwnd = item; | |
6169 tmpitem[0].origwidth = tmpitem[0].width = width; | |
6170 tmpitem[0].origheight = tmpitem[0].height = height; | |
6171 tmpitem[0].pad = pad; | |
6172 if(hsize) | |
6173 tmpitem[0].hsize = SIZEEXPAND; | |
6174 else | |
6175 tmpitem[0].hsize = SIZESTATIC; | |
6176 | |
6177 if(vsize) | |
6178 tmpitem[0].vsize = SIZEEXPAND; | |
6179 else | |
6180 tmpitem[0].vsize = SIZESTATIC; | |
6181 | |
6182 thisbox->items = tmpitem; | |
6183 | |
6184 if(thisbox->count) | |
6185 free(thisitem); | |
6186 | |
6187 thisbox->count++; | |
6188 | |
6189 WinQueryClassName(item, 99, tmpbuf); | |
6190 /* Don't set the ownership if it's an entryfield or spinbutton */ | |
6191 if(strncmp(tmpbuf, "#6", 3)!=0 && strncmp(tmpbuf, "#32", 4)!=0 && strncmp(tmpbuf, "#2", 3)!=0) | |
6192 WinSetOwner(item, box); | |
6193 WinSetParent(frame ? frame : item, box, FALSE); | |
6194 } | |
6195 } | 6128 } |
6196 | 6129 |
6197 /* | 6130 /* |
6198 * Sets the size of a given window (widget). | 6131 * Sets the size of a given window (widget). |
6199 * Parameters: | 6132 * Parameters: |
9463 float *percent = (float *)dw_window_get_data(handle, "_dw_percent"); | 9396 float *percent = (float *)dw_window_get_data(handle, "_dw_percent"); |
9464 | 9397 |
9465 if(percent) | 9398 if(percent) |
9466 return *percent; | 9399 return *percent; |
9467 return 0.0; | 9400 return 0.0; |
9468 } | |
9469 | |
9470 /* | |
9471 * Pack windows (widgets) into a box from the start (or top). | |
9472 * Parameters: | |
9473 * box: Window handle of the box to be packed into. | |
9474 * item: Window handle of the item to be back. | |
9475 * width: Width in pixels of the item or -1 to be self determined. | |
9476 * height: Height in pixels of the item or -1 to be self determined. | |
9477 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | |
9478 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | |
9479 * pad: Number of pixels of padding around the item. | |
9480 */ | |
9481 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | |
9482 { | |
9483 char *funcname = "dw_box_pack_start()"; | |
9484 | |
9485 /* | |
9486 * If you try and pack an item into itself VERY bad things can happen; like at least an | |
9487 * infinite loop on GTK! Lets be safe! | |
9488 */ | |
9489 if(box == item) | |
9490 { | |
9491 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); | |
9492 return; | |
9493 } | |
9494 | |
9495 if(WinWindowFromID(box, FID_CLIENT)) | |
9496 { | |
9497 HWND intbox = (HWND)dw_window_get_data(box, "_dw_box"); | |
9498 if(intbox) | |
9499 { | |
9500 box = intbox; | |
9501 } | |
9502 else | |
9503 { | |
9504 box = WinWindowFromID(box, FID_CLIENT); | |
9505 hsize = vsize = TRUE; | |
9506 } | |
9507 } | |
9508 _dw_box_pack_start(box, item, width, height, hsize, vsize, pad, funcname); | |
9509 } | |
9510 | |
9511 void _dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad, char *functionname) | |
9512 { | |
9513 Box *thisbox = WinQueryWindowPtr(box, QWP_USER); | |
9514 | |
9515 if(thisbox) | |
9516 { | |
9517 int z; | |
9518 Item *tmpitem, *thisitem = thisbox->items; | |
9519 char tmpbuf[100]; | |
9520 HWND frame = (HWND)dw_window_get_data(item, "_dw_combo_box"); | |
9521 | |
9522 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | |
9523 | |
9524 for(z=0;z<thisbox->count;z++) | |
9525 { | |
9526 tmpitem[z] = thisitem[z]; | |
9527 } | |
9528 | |
9529 WinQueryClassName(item, 99, tmpbuf); | |
9530 | |
9531 if(vsize && !height) | |
9532 height = 1; | |
9533 if(hsize && !width) | |
9534 width = 1; | |
9535 | |
9536 if(strncmp(tmpbuf, "#1", 3)==0) | |
9537 tmpitem[thisbox->count].type = TYPEBOX; | |
9538 else | |
9539 { | |
9540 if ( width == 0 && hsize == FALSE ) | |
9541 dw_messagebox(functionname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | |
9542 if ( height == 0 && vsize == FALSE ) | |
9543 dw_messagebox(functionname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); | |
9544 | |
9545 tmpitem[thisbox->count].type = TYPEITEM; | |
9546 } | |
9547 | |
9548 tmpitem[thisbox->count].hwnd = item; | |
9549 tmpitem[thisbox->count].origwidth = tmpitem[thisbox->count].width = width; | |
9550 tmpitem[thisbox->count].origheight = tmpitem[thisbox->count].height = height; | |
9551 tmpitem[thisbox->count].pad = pad; | |
9552 if(hsize) | |
9553 tmpitem[thisbox->count].hsize = SIZEEXPAND; | |
9554 else | |
9555 tmpitem[thisbox->count].hsize = SIZESTATIC; | |
9556 | |
9557 if(vsize) | |
9558 tmpitem[thisbox->count].vsize = SIZEEXPAND; | |
9559 else | |
9560 tmpitem[thisbox->count].vsize = SIZESTATIC; | |
9561 | |
9562 thisbox->items = tmpitem; | |
9563 | |
9564 if(thisbox->count) | |
9565 free(thisitem); | |
9566 | |
9567 thisbox->count++; | |
9568 | |
9569 /* Don't set the ownership if it's an entryfield or spinbutton */ | |
9570 WinQueryClassName(item, 99, tmpbuf); | |
9571 if(strncmp(tmpbuf, "#6", 3)!=0 && strncmp(tmpbuf, "#32", 4)!=0 && strncmp(tmpbuf, "#2", 3)!=0) | |
9572 WinSetOwner(item, box); | |
9573 WinSetParent(frame ? frame : item, box, FALSE); | |
9574 } | |
9575 } | 9401 } |
9576 | 9402 |
9577 /* The following two functions graciously contributed by Peter Nielsen. */ | 9403 /* The following two functions graciously contributed by Peter Nielsen. */ |
9578 static ULONG _ParseBuildLevel (char* pchBuffer, ULONG ulSize) { | 9404 static ULONG _ParseBuildLevel (char* pchBuffer, ULONG ulSize) { |
9579 char* pchStart = pchBuffer; | 9405 char* pchStart = pchBuffer; |