Mercurial > dwindows
comparison win/dw.c @ 1766:47e503ecc812
Ported clang/Xcode fixes to Windows and OS/2 just in case.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 01 Jul 2012 07:51:25 +0000 |
parents | 15414cbe857f |
children | d81bebc5c8cc |
comparison
equal
deleted
inserted
replaced
1765:15414cbe857f | 1766:47e503ecc812 |
---|---|
7084 { | 7084 { |
7085 int z, x = 0; | 7085 int z, x = 0; |
7086 Item *tmpitem, *thisitem = thisbox->items; | 7086 Item *tmpitem, *thisitem = thisbox->items; |
7087 | 7087 |
7088 /* Do some sanity bounds checking */ | 7088 /* Do some sanity bounds checking */ |
7089 if(!thisitem) | |
7090 thisbox->count = 0; | |
7089 if(index < 0) | 7091 if(index < 0) |
7090 index = 0; | 7092 index = 0; |
7091 if(index > thisbox->count) | 7093 if(index > thisbox->count) |
7092 index = thisbox->count; | 7094 index = thisbox->count; |
7093 | 7095 |
7094 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | 7096 tmpitem = calloc(sizeof(Item), (thisbox->count+1)); |
7095 | 7097 |
7096 for(z=0;z<thisbox->count;z++) | 7098 for(z=0;z<thisbox->count;z++) |
7097 { | 7099 { |
7098 if(z == index) | 7100 if(z == index) |
7099 x++; | 7101 x++; |
7142 if(width == -1 || height == -1) | 7144 if(width == -1 || height == -1) |
7143 _control_size(item, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL); | 7145 _control_size(item, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL); |
7144 | 7146 |
7145 thisbox->items = tmpitem; | 7147 thisbox->items = tmpitem; |
7146 | 7148 |
7147 if(thisbox->count) | 7149 if(thisitem) |
7148 free(thisitem); | 7150 free(thisitem); |
7149 | 7151 |
7150 thisbox->count++; | 7152 thisbox->count++; |
7151 | 7153 |
7152 SetParent(item, box); | 7154 SetParent(item, box); |
7197 * try to remove it from the layout | 7199 * try to remove it from the layout |
7198 */ | 7200 */ |
7199 if(thisbox && thisbox->count) | 7201 if(thisbox && thisbox->count) |
7200 { | 7202 { |
7201 int z, index = -1; | 7203 int z, index = -1; |
7202 Item *tmpitem, *thisitem = thisbox->items; | 7204 Item *tmpitem = NULL, *thisitem = thisbox->items; |
7205 | |
7206 if(!thisitem) | |
7207 thisbox->count = 0; | |
7203 | 7208 |
7204 for(z=0;z<thisbox->count;z++) | 7209 for(z=0;z<thisbox->count;z++) |
7205 { | 7210 { |
7206 if(thisitem[z].hwnd == handle) | 7211 if(thisitem[z].hwnd == handle) |
7207 index = z; | 7212 index = z; |
7208 } | 7213 } |
7209 | 7214 |
7210 if(index == -1) | 7215 if(index == -1) |
7211 return DW_ERROR_GENERAL; | 7216 return DW_ERROR_GENERAL; |
7212 | 7217 |
7213 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); | 7218 if(thisbox->count > 1) |
7219 { | |
7220 tmpitem = calloc(sizeof(Item), (thisbox->count-1)); | |
7221 | |
7222 /* Copy all but the current entry to the new list */ | |
7223 for(z=0;z<index;z++) | |
7224 { | |
7225 tmpitem[z] = thisitem[z]; | |
7226 } | |
7227 for(z=index+1;z<thisbox->count;z++) | |
7228 { | |
7229 tmpitem[z-1] = thisitem[z]; | |
7230 } | |
7231 } | |
7232 | |
7233 thisbox->items = tmpitem; | |
7234 if(thisitem) | |
7235 free(thisitem); | |
7236 if(tmpitem) | |
7237 thisbox->count--; | |
7238 else | |
7239 thisbox->count = 0; | |
7240 | |
7241 SetParent(handle, DW_HWND_OBJECT); | |
7242 /* Queue a redraw on the top-level window */ | |
7243 _dw_redraw(_toplevel_window(parent), TRUE); | |
7244 return DW_ERROR_NONE; | |
7245 } | |
7246 } | |
7247 return DW_ERROR_GENERAL; | |
7248 } | |
7249 | |
7250 /* | |
7251 * Remove windows (widgets) from a box at an arbitrary location. | |
7252 * Parameters: | |
7253 * box: Window handle of the box to be removed from. | |
7254 * index: 0 based index of packed items. | |
7255 * Returns: | |
7256 * Handle to the removed item on success, 0 on failure or padding. | |
7257 */ | |
7258 HWND API dw_box_remove_at_index(HWND box, int index) | |
7259 { | |
7260 Box *thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA); | |
7261 | |
7262 /* Try to remove it from the layout */ | |
7263 if(thisbox && index > -1 && index < thisbox->count) | |
7264 { | |
7265 int z; | |
7266 Item *tmpitem = NULL, *thisitem = thisbox->items; | |
7267 HWND handle = thisitem[index].hwnd; | |
7268 | |
7269 if(thisbox->count > 1) | |
7270 { | |
7271 tmpitem = calloc(sizeof(Item), (thisbox->count-1)); | |
7214 | 7272 |
7215 /* Copy all but the current entry to the new list */ | 7273 /* Copy all but the current entry to the new list */ |
7216 for(z=0;z<index;z++) | 7274 for(z=0;z<index;z++) |
7217 { | 7275 { |
7218 tmpitem[z] = thisitem[z]; | 7276 tmpitem[z] = thisitem[z]; |
7219 } | 7277 } |
7220 for(z=index+1;z<thisbox->count;z++) | 7278 for(z=index+1;z<thisbox->count;z++) |
7221 { | 7279 { |
7222 tmpitem[z-1] = thisitem[z]; | 7280 tmpitem[z-1] = thisitem[z]; |
7223 } | 7281 } |
7224 | 7282 } |
7225 thisbox->items = tmpitem; | 7283 |
7284 thisbox->items = tmpitem; | |
7285 if(thisitem) | |
7226 free(thisitem); | 7286 free(thisitem); |
7287 if(tmpitem) | |
7227 thisbox->count--; | 7288 thisbox->count--; |
7228 SetParent(handle, DW_HWND_OBJECT); | 7289 else |
7229 /* Queue a redraw on the top-level window */ | 7290 thisbox->count = 0; |
7230 _dw_redraw(_toplevel_window(parent), TRUE); | 7291 |
7231 return DW_ERROR_NONE; | |
7232 } | |
7233 } | |
7234 return DW_ERROR_GENERAL; | |
7235 } | |
7236 | |
7237 /* | |
7238 * Remove windows (widgets) from a box at an arbitrary location. | |
7239 * Parameters: | |
7240 * box: Window handle of the box to be removed from. | |
7241 * index: 0 based index of packed items. | |
7242 * Returns: | |
7243 * Handle to the removed item on success, 0 on failure or padding. | |
7244 */ | |
7245 HWND API dw_box_remove_at_index(HWND box, int index) | |
7246 { | |
7247 Box *thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA); | |
7248 | |
7249 /* Try to remove it from the layout */ | |
7250 if(thisbox && index > -1 && index < thisbox->count) | |
7251 { | |
7252 int z; | |
7253 Item *tmpitem, *thisitem = thisbox->items; | |
7254 HWND handle = thisitem[index].hwnd; | |
7255 | |
7256 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); | |
7257 | |
7258 /* Copy all but the current entry to the new list */ | |
7259 for(z=0;z<index;z++) | |
7260 { | |
7261 tmpitem[z] = thisitem[z]; | |
7262 } | |
7263 for(z=index+1;z<thisbox->count;z++) | |
7264 { | |
7265 tmpitem[z-1] = thisitem[z]; | |
7266 } | |
7267 | |
7268 thisbox->items = tmpitem; | |
7269 free(thisitem); | |
7270 thisbox->count--; | |
7271 /* If it isn't padding, reset the parent */ | 7292 /* If it isn't padding, reset the parent */ |
7272 if(handle) | 7293 if(handle) |
7273 SetParent(handle, DW_HWND_OBJECT); | 7294 SetParent(handle, DW_HWND_OBJECT); |
7274 /* Queue a redraw on the top-level window */ | 7295 /* Queue a redraw on the top-level window */ |
7275 _dw_redraw(_toplevel_window(box), TRUE); | 7296 _dw_redraw(_toplevel_window(box), TRUE); |