comparison os2/dw.c @ 1077:34f1d6f5f1c3

Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest. Only tested on Windows... will be testing on OS/2 and Mac shortly... then implementing the GTK versions of the function after that.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 28 Jun 2011 04:41:43 +0000
parents 3d117071a50b
children 6eadfe0007b4
comparison
equal deleted inserted replaced
1076:dbaf1b11c301 1077:34f1d6f5f1c3
5971 WinEndEnumWindows(henum); 5971 WinEndEnumWindows(henum);
5972 return NULLHANDLE; 5972 return NULLHANDLE;
5973 } 5973 }
5974 5974
5975 /* 5975 /*
5976 * Pack windows (widgets) into a box at an arbitrary location.
5977 * Parameters:
5978 * box: Window handle of the box to be packed into.
5979 * item: Window handle of the item to be back.
5980 * index: 0 based index of packed items.
5981 * width: Width in pixels of the item or -1 to be self determined.
5982 * height: Height in pixels of the item or -1 to be self determined.
5983 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
5984 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
5985 * pad: Number of pixels of padding around the item.
5986 */
5987 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad)
5988 {
5989 char *funcname = "dw_box_pack_at_index()";
5990 Box *thisbox;
5991
5992 /*
5993 * If you try and pack an item into itself VERY bad things can happen; like at least an
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(functionname, 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(functionname, 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 /*
5976 * Pack windows (widgets) into a box from the end (or bottom). 6091 * Pack windows (widgets) into a box from the end (or bottom).
5977 * Parameters: 6092 * Parameters:
5978 * box: Window handle of the box to be packed into. 6093 * box: Window handle of the box to be packed into.
5979 * item: Window handle of the item to be back. 6094 * item: Window handle of the item to be back.
5980 * width: Width in pixels of the item or -1 to be self determined. 6095 * width: Width in pixels of the item or -1 to be self determined.