comparison win/dw.c @ 1084:fa219e997fb8

Merge all 3 box packing functions into one internal function on Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 28 Jun 2011 17:53:09 +0000
parents 34f1d6f5f1c3
children b905fd8e7fd1
comparison
equal deleted inserted replaced
1083:78d425edec46 1084:fa219e997fb8
5927 _dw_wfid_hwnd = NULL; 5927 _dw_wfid_hwnd = NULL;
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 /* Internal box packing function called by the other 3 functions */
5933 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname)
5934 {
5935 Box *thisbox = NULL;
5936 char tmpbuf[100];
5937
5938 /*
5939 * If you try and pack an item into itself VERY bad things can happen; like at least an
5940 * infinite loop on GTK! Lets be safe!
5941 */
5942 if(box == item)
5943 {
5944 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
5945 return;
5946 }
5947
5948 GetClassName(box, tmpbuf, 99);
5949
5950 /* If we are in a scrolled box... extract the interal box */
5951 if(strnicmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0)
5952 {
5953 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(box, GWLP_USERDATA);
5954 if(cinfo)
5955 {
5956 box = cinfo->buddy;
5957 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA);
5958 }
5959 }
5960 else //if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0)
5961 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA);
5962 if(thisbox)
5963 {
5964 int z, x = 0;
5965 Item *tmpitem, *thisitem = thisbox->items;
5966
5967 /* Do some sanity bounds checking */
5968 if(index < 0)
5969 index = 0;
5970 if(index > thisbox->count)
5971 index = thisbox->count;
5972
5973 tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
5974
5975 for(z=0;z<thisbox->count;z++)
5976 {
5977 if(z == index)
5978 x++;
5979 tmpitem[x] = thisitem[z];
5980 x++;
5981 }
5982
5983 GetClassName(item, tmpbuf, 99);
5984
5985 if(vsize && !height)
5986 height = 1;
5987 if(hsize && !width)
5988 width = 1;
5989
5990 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0)
5991 tmpitem[index].type = TYPEBOX;
5992 else if(strnicmp(tmpbuf, "SysMonthCal32", 13)==0)
5993 {
5994 RECT rc;
5995 MonthCal_GetMinReqRect(item, &rc);
5996 width = 1 + rc.right - rc.left;
5997 height = 1 + rc.bottom - rc.top;
5998 tmpitem[index].type = TYPEITEM;
5999 }
6000 else
6001 {
6002 if ( width == 0 && hsize == FALSE )
6003 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
6004 if ( height == 0 && vsize == FALSE )
6005 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
6006
6007 tmpitem[index].type = TYPEITEM;
6008 }
6009
6010 tmpitem[index].hwnd = item;
6011 tmpitem[index].origwidth = tmpitem[index].width = width;
6012 tmpitem[index].origheight = tmpitem[index].height = height;
6013 tmpitem[index].pad = pad;
6014 if(hsize)
6015 tmpitem[index].hsize = SIZEEXPAND;
6016 else
6017 tmpitem[index].hsize = SIZESTATIC;
6018
6019 if(vsize)
6020 tmpitem[index].vsize = SIZEEXPAND;
6021 else
6022 tmpitem[index].vsize = SIZESTATIC;
6023
6024 thisbox->items = tmpitem;
6025
6026 if(thisbox->count)
6027 free(thisitem);
6028
6029 thisbox->count++;
6030
6031 SetParent(item, box);
6032 if(strncmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0)
6033 {
6034 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(item, GWLP_USERDATA);
6035
6036 if(cinfo)
6037 {
6038 SetParent(cinfo->buddy, box);
6039 ShowWindow(cinfo->buddy, SW_SHOW);
6040 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0);
6041 }
6042 }
6043 }
6044 }
6045
5932 /* 6046 /*
5933 * Pack windows (widgets) into a box at an arbitrary location. 6047 * Pack windows (widgets) into a box at an arbitrary location.
5934 * Parameters: 6048 * Parameters:
5935 * box: Window handle of the box to be packed into. 6049 * box: Window handle of the box to be packed into.
5936 * item: Window handle of the item to be back. 6050 * item: Window handle of the item to be back.
5941 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 6055 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
5942 * pad: Number of pixels of padding around the item. 6056 * pad: Number of pixels of padding around the item.
5943 */ 6057 */
5944 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad) 6058 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad)
5945 { 6059 {
5946 Box *thisbox = NULL; 6060 _dw_box_pack(box, item, index, width, height, hsize, vsize, pad, "dw_box_pack_at_index()");
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 } 6061 }
6056 6062
6057 /* 6063 /*
6058 * Pack windows (widgets) into a box from the start (or top). 6064 * Pack windows (widgets) into a box from the start (or top).
6059 * Parameters: 6065 * Parameters:
6065 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 6071 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
6066 * pad: Number of pixels of padding around the item. 6072 * pad: Number of pixels of padding around the item.
6067 */ 6073 */
6068 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) 6074 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
6069 { 6075 {
6070 Box *thisbox = NULL; 6076 /* 65536 is the table limit on GTK...
6071 char tmpbuf[100]; 6077 * seems like a high enough value we will never hit it here either.
6072 6078 */
6073 /* 6079 _dw_box_pack(box, item, 65536, width, height, hsize, vsize, pad, "dw_box_pack_start()");
6074 * If you try and pack an item into itself VERY bad things can happen; like at least an 6080 }
6075 * infinite loop on GTK! Lets be safe! 6081
6076 */ 6082 /*
6077 if(box == item) 6083 * Pack windows (widgets) into a box from the end (or bottom).
6078 { 6084 * Parameters:
6079 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!"); 6085 * box: Window handle of the box to be packed into.
6080 return; 6086 * item: Window handle of the item to be back.
6081 } 6087 * width: Width in pixels of the item or -1 to be self determined.
6082 6088 * height: Height in pixels of the item or -1 to be self determined.
6083 GetClassName(box, tmpbuf, 99); 6089 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
6084 6090 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
6085 /* If we are in a scrolled box... extract the interal box */ 6091 * pad: Number of pixels of padding around the item.
6086 if(strnicmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0) 6092 */
6087 { 6093 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
6088 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(box, GWLP_USERDATA); 6094 {
6089 if(cinfo) 6095 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()");
6090 {
6091 box = cinfo->buddy;
6092 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA);
6093 }
6094 }
6095 else //if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0)
6096 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA);
6097 if(thisbox)
6098 {
6099 int z;
6100 Item *tmpitem, *thisitem = thisbox->items;
6101
6102 tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
6103
6104 for(z=0;z<thisbox->count;z++)
6105 {
6106 tmpitem[z] = thisitem[z];
6107 }
6108
6109 GetClassName(item, tmpbuf, 99);
6110
6111 if(vsize && !height)
6112 height = 1;
6113 if(hsize && !width)
6114 width = 1;
6115
6116 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0)
6117 tmpitem[thisbox->count].type = TYPEBOX;
6118 else if(strnicmp(tmpbuf, "SysMonthCal32", 13)==0)
6119 {
6120 RECT rc;
6121 MonthCal_GetMinReqRect(item, &rc);
6122 width = 1 + rc.right - rc.left;
6123 height = 1 + rc.bottom - rc.top;
6124 tmpitem[thisbox->count].type = TYPEITEM;
6125 }
6126 else
6127 {
6128 if ( width == 0 && hsize == FALSE )
6129 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);
6130 if ( height == 0 && vsize == FALSE )
6131 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);
6132
6133 tmpitem[thisbox->count].type = TYPEITEM;
6134 }
6135
6136 tmpitem[thisbox->count].hwnd = item;
6137 tmpitem[thisbox->count].origwidth = tmpitem[thisbox->count].width = width;
6138 tmpitem[thisbox->count].origheight = tmpitem[thisbox->count].height = height;
6139 tmpitem[thisbox->count].pad = pad;
6140 if(hsize)
6141 tmpitem[thisbox->count].hsize = SIZEEXPAND;
6142 else
6143 tmpitem[thisbox->count].hsize = SIZESTATIC;
6144
6145 if(vsize)
6146 tmpitem[thisbox->count].vsize = SIZEEXPAND;
6147 else
6148 tmpitem[thisbox->count].vsize = SIZESTATIC;
6149
6150 thisbox->items = tmpitem;
6151
6152 if(thisbox->count)
6153 free(thisitem);
6154
6155 thisbox->count++;
6156
6157 SetParent(item, box);
6158 if(strncmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0)
6159 {
6160 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(item, GWLP_USERDATA);
6161
6162 if(cinfo)
6163 {
6164 SetParent(cinfo->buddy, box);
6165 ShowWindow(cinfo->buddy, SW_SHOW);
6166 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0);
6167 }
6168 }
6169 }
6170 } 6096 }
6171 6097
6172 /* 6098 /*
6173 * Sets the size of a given window (widget). 6099 * Sets the size of a given window (widget).
6174 * Parameters: 6100 * Parameters:
6192 _resize_box(thisbox, &depth, usedx, usedy, &usedx, &usedy, 2, &usedpadx, &usedpady); 6118 _resize_box(thisbox, &depth, usedx, usedy, &usedx, &usedy, 2, &usedpadx, &usedpady);
6193 } 6119 }
6194 if ( width == 0 ) width = usedx; 6120 if ( width == 0 ) width = usedx;
6195 if ( height == 0 ) height = usedy; 6121 if ( height == 0 ) height = usedy;
6196 SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE); 6122 SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE);
6197 #if 0
6198 /* force a configure event */
6199 SendMessage( handle, WM_SIZE, 0, MAKELPARAM(usedx, usedy) );
6200 #endif
6201 } 6123 }
6202 6124
6203 /* 6125 /*
6204 * Returns the width of the screen. 6126 * Returns the width of the screen.
6205 */ 6127 */
9721 *day = date.wDay; 9643 *day = date.wDay;
9722 } 9644 }
9723 else 9645 else
9724 { 9646 {
9725 *year = *month = *day = 0; 9647 *year = *month = *day = 0;
9726 }
9727 }
9728
9729 /*
9730 * Pack windows (widgets) into a box from the end (or bottom).
9731 * Parameters:
9732 * box: Window handle of the box to be packed into.
9733 * item: Window handle of the item to be back.
9734 * width: Width in pixels of the item or -1 to be self determined.
9735 * height: Height in pixels of the item or -1 to be self determined.
9736 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
9737 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
9738 * pad: Number of pixels of padding around the item.
9739 */
9740 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
9741 {
9742 Box *thisbox = NULL;
9743 char tmpbuf[100];
9744
9745 /*
9746 * If you try and pack an item into itself VERY bad things can happen; like at least an
9747 * infinite loop on GTK! Lets be safe!
9748 */
9749 if(box == item)
9750 {
9751 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
9752 return;
9753 }
9754
9755 GetClassName(box, tmpbuf, 99);
9756
9757 /* If we are in a scrolled box... extract the interal box */
9758 if(strnicmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0)
9759 {
9760 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(box, GWLP_USERDATA);
9761 if(cinfo)
9762 {
9763 box = cinfo->buddy;
9764 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA);
9765 }
9766 }
9767 else //if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0)
9768 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA);
9769 if(thisbox)
9770 {
9771 int z;
9772 Item *tmpitem, *thisitem = thisbox->items;
9773
9774 tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
9775
9776 for(z=0;z<thisbox->count;z++)
9777 {
9778 tmpitem[z+1] = thisitem[z];
9779 }
9780
9781 GetClassName(item, tmpbuf, 99);
9782
9783 if(vsize && !height)
9784 height = 1;
9785 if(hsize && !width)
9786 width = 1;
9787
9788 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0)
9789 tmpitem[0].type = TYPEBOX;
9790 else if(strnicmp(tmpbuf, "SysMonthCal32", 13)==0)
9791 {
9792 RECT rc;
9793 MonthCal_GetMinReqRect(item, &rc);
9794 width = 1 + rc.right - rc.left;
9795 height = 1 + rc.bottom - rc.top;
9796 tmpitem[thisbox->count].type = TYPEITEM;
9797 }
9798 else
9799 {
9800 if ( width == 0 && hsize == FALSE )
9801 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
9802 if ( height == 0 && vsize == FALSE )
9803 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
9804
9805 tmpitem[0].type = TYPEITEM;
9806 }
9807
9808 tmpitem[0].hwnd = item;
9809 tmpitem[0].origwidth = tmpitem[0].width = width;
9810 tmpitem[0].origheight = tmpitem[0].height = height;
9811 tmpitem[0].pad = pad;
9812 if(hsize)
9813 tmpitem[0].hsize = SIZEEXPAND;
9814 else
9815 tmpitem[0].hsize = SIZESTATIC;
9816
9817 if(vsize)
9818 tmpitem[0].vsize = SIZEEXPAND;
9819 else
9820 tmpitem[0].vsize = SIZESTATIC;
9821
9822 thisbox->items = tmpitem;
9823
9824 if(thisbox->count)
9825 free(thisitem);
9826
9827 thisbox->count++;
9828
9829 SetParent(item, box);
9830 if(strncmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1)==0)
9831 {
9832 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(item, GWLP_USERDATA);
9833
9834 if(cinfo)
9835 {
9836 SetParent(cinfo->buddy, box);
9837 ShowWindow(cinfo->buddy, SW_SHOW);
9838 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0);
9839 }
9840 }
9841 } 9648 }
9842 } 9649 }
9843 9650
9844 /* 9651 /*
9845 * Sets the default focus item for a window/dialog. 9652 * Sets the default focus item for a window/dialog.