comparison win/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 fa219e997fb8
comparison
equal deleted inserted replaced
1076:dbaf1b11c301 1077:34f1d6f5f1c3
5928 EnumChildWindows(handle, _wfid, (LPARAM)id); 5928 EnumChildWindows(handle, _wfid, (LPARAM)id);
5929 return _dw_wfid_hwnd; 5929 return _dw_wfid_hwnd;
5930 } 5930 }
5931 5931
5932 /* 5932 /*
5933 * Pack windows (widgets) into a box at an arbitrary location.
5934 * Parameters:
5935 * box: Window handle of the box to be packed into.
5936 * item: Window handle of the item to be back.
5937 * index: 0 based index of packed items.
5938 * width: Width in pixels of the item or -1 to be self determined.
5939 * height: Height in pixels of the item or -1 to be self determined.
5940 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
5941 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
5942 * pad: Number of pixels of padding around the item.
5943 */
5944 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad)
5945 {
5946 Box *thisbox = NULL;
5947 char tmpbuf[100];
5948
5949 /*
5950 * If you try and pack an item into itself VERY bad things can happen; like at least an
5951 * infinite loop on GTK! Lets be safe!
5952 */
5953 if(box == item)
5954 {
5955 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
5956 return;
5957 }
5958
5959 GetClassName(box, tmpbuf, 99);
5960
5961 /* If we are in a scrolled box... extract the interal box */
5962 if(strnicmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0)
5963 {
5964 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(box, GWLP_USERDATA);
5965 if(cinfo)
5966 {
5967 box = cinfo->buddy;
5968 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA);
5969 }
5970 }
5971 else //if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0)
5972 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA);
5973 if(thisbox)
5974 {
5975 int z, x = 0;
5976 Item *tmpitem, *thisitem = thisbox->items;
5977
5978 /* Do some sanity bounds checking */
5979 if(index < 0)
5980 index = 0;
5981 if(index > thisbox->count)
5982 index = thisbox->count;
5983
5984 tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
5985
5986 for(z=0;z<thisbox->count;z++)
5987 {
5988 if(z == index)
5989 x++;
5990 tmpitem[x] = thisitem[z];
5991 x++;
5992 }
5993
5994 GetClassName(item, tmpbuf, 99);
5995
5996 if(vsize && !height)
5997 height = 1;
5998 if(hsize && !width)
5999 width = 1;
6000
6001 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0)
6002 tmpitem[index].type = TYPEBOX;
6003 else if(strnicmp(tmpbuf, "SysMonthCal32", 13)==0)
6004 {
6005 RECT rc;
6006 MonthCal_GetMinReqRect(item, &rc);
6007 width = 1 + rc.right - rc.left;
6008 height = 1 + rc.bottom - rc.top;
6009 tmpitem[index].type = TYPEITEM;
6010 }
6011 else
6012 {
6013 if ( width == 0 && hsize == FALSE )
6014 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
6015 if ( height == 0 && vsize == FALSE )
6016 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
6017
6018 tmpitem[index].type = TYPEITEM;
6019 }
6020
6021 tmpitem[index].hwnd = item;
6022 tmpitem[index].origwidth = tmpitem[index].width = width;
6023 tmpitem[index].origheight = tmpitem[index].height = height;
6024 tmpitem[index].pad = pad;
6025 if(hsize)
6026 tmpitem[index].hsize = SIZEEXPAND;
6027 else
6028 tmpitem[index].hsize = SIZESTATIC;
6029
6030 if(vsize)
6031 tmpitem[index].vsize = SIZEEXPAND;
6032 else
6033 tmpitem[index].vsize = SIZESTATIC;
6034
6035 thisbox->items = tmpitem;
6036
6037 if(thisbox->count)
6038 free(thisitem);
6039
6040 thisbox->count++;
6041
6042 SetParent(item, box);
6043 if(strncmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0)
6044 {
6045 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(item, GWLP_USERDATA);
6046
6047 if(cinfo)
6048 {
6049 SetParent(cinfo->buddy, box);
6050 ShowWindow(cinfo->buddy, SW_SHOW);
6051 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0);
6052 }
6053 }
6054 }
6055 }
6056
6057 /*
5933 * Pack windows (widgets) into a box from the start (or top). 6058 * Pack windows (widgets) into a box from the start (or top).
5934 * Parameters: 6059 * Parameters:
5935 * box: Window handle of the box to be packed into. 6060 * box: Window handle of the box to be packed into.
5936 * item: Window handle of the item to be back. 6061 * item: Window handle of the item to be back.
5937 * width: Width in pixels of the item or -1 to be self determined. 6062 * width: Width in pixels of the item or -1 to be self determined.