Mercurial > dwindows
comparison os2/dw.c @ 1667:9dbd2984c1e5
Initial implementation of dw_box_remove() and dw_box_remove_at_index()
for OS/2, Windows and template. Mac and GTK2/3 versions coming soon.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 26 Apr 2012 20:33:39 +0000 |
parents | fc135161f2b1 |
children | 724a7361cb42 |
comparison
equal
deleted
inserted
replaced
1666:df25fee81502 | 1667:9dbd2984c1e5 |
---|---|
4491 * handle: The window handle to destroy. | 4491 * handle: The window handle to destroy. |
4492 */ | 4492 */ |
4493 int API dw_window_destroy(HWND handle) | 4493 int API dw_window_destroy(HWND handle) |
4494 { | 4494 { |
4495 HWND frame, menu, parent; | 4495 HWND frame, menu, parent; |
4496 Box *thisbox; | |
4497 | 4496 |
4498 if(!handle) | 4497 if(!handle) |
4499 return DW_ERROR_UNKNOWN; | 4498 return DW_ERROR_UNKNOWN; |
4500 | 4499 |
4501 /* Handle special case for menu handle */ | 4500 /* Handle special case for menu handle */ |
4510 return dw_menu_delete_item((HMENUI)menu, handle); | 4509 return dw_menu_delete_item((HMENUI)menu, handle); |
4511 return DW_ERROR_UNKNOWN; | 4510 return DW_ERROR_UNKNOWN; |
4512 } | 4511 } |
4513 | 4512 |
4514 parent = WinQueryWindow(handle, QW_PARENT); | 4513 parent = WinQueryWindow(handle, QW_PARENT); |
4515 thisbox = WinQueryWindowPtr(parent, QWP_USER); | |
4516 frame = (HWND)dw_window_get_data(handle, "_dw_combo_box"); | 4514 frame = (HWND)dw_window_get_data(handle, "_dw_combo_box"); |
4517 | 4515 |
4518 if((menu = WinWindowFromID(handle, FID_MENU)) != NULLHANDLE) | 4516 if((menu = WinWindowFromID(handle, FID_MENU)) != NULLHANDLE) |
4519 _free_menu_data(menu); | 4517 _free_menu_data(menu); |
4520 | 4518 |
4521 /* If it is a desktop window let WM_DESTROY handle it */ | 4519 /* If it is a desktop window let WM_DESTROY handle it */ |
4522 if(parent != desktop) | 4520 if(parent != desktop) |
4523 { | 4521 { |
4524 /* If the parent box has items... | 4522 dw_box_remove(handle); |
4525 * try to remove it from the layout | |
4526 */ | |
4527 if(thisbox && thisbox->count) | |
4528 { | |
4529 int z, index = -1; | |
4530 Item *tmpitem, *thisitem = thisbox->items; | |
4531 | |
4532 for(z=0;z<thisbox->count;z++) | |
4533 { | |
4534 if(thisitem[z].hwnd == handle) | |
4535 index = z; | |
4536 } | |
4537 | |
4538 if(index == -1) | |
4539 return 0; | |
4540 | |
4541 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); | |
4542 | |
4543 /* Copy all but the current entry to the new list */ | |
4544 for(z=0;z<index;z++) | |
4545 { | |
4546 tmpitem[z] = thisitem[z]; | |
4547 } | |
4548 for(z=index+1;z<thisbox->count;z++) | |
4549 { | |
4550 tmpitem[z-1] = thisitem[z]; | |
4551 } | |
4552 | |
4553 thisbox->items = tmpitem; | |
4554 free(thisitem); | |
4555 thisbox->count--; | |
4556 /* Queue a redraw on the top-level window */ | |
4557 _dw_redraw(_toplevel_window(handle), TRUE); | |
4558 } | |
4559 _free_window_memory(frame ? frame : handle); | 4523 _free_window_memory(frame ? frame : handle); |
4560 } | 4524 } |
4561 return WinDestroyWindow(frame ? frame : handle); | 4525 return WinDestroyWindow(frame ? frame : handle); |
4562 } | 4526 } |
4563 | 4527 |
7229 _dw_redraw(_toplevel_window(item), TRUE); | 7193 _dw_redraw(_toplevel_window(item), TRUE); |
7230 } | 7194 } |
7231 } | 7195 } |
7232 | 7196 |
7233 /* | 7197 /* |
7198 * Remove windows (widgets) from the box they are packed into. | |
7199 * Parameters: | |
7200 * handle: Window handle of the item to be back. | |
7201 * Returns: | |
7202 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. | |
7203 */ | |
7204 int API dw_box_remove(HWND handle) | |
7205 { | |
7206 HWND parent = WinQueryWindow(handle, QW_PARENT); | |
7207 | |
7208 if(parent != desktop) | |
7209 { | |
7210 Box *thisbox = WinQueryWindowPtr(parent, QWP_USER); | |
7211 | |
7212 /* If the parent box has items... | |
7213 * try to remove it from the layout | |
7214 */ | |
7215 if(thisbox && thisbox->count) | |
7216 { | |
7217 int z, index = -1; | |
7218 Item *tmpitem, *thisitem = thisbox->items; | |
7219 | |
7220 for(z=0;z<thisbox->count;z++) | |
7221 { | |
7222 if(thisitem[z].hwnd == handle) | |
7223 index = z; | |
7224 } | |
7225 | |
7226 if(index == -1) | |
7227 return DW_ERROR_GENERAL; | |
7228 | |
7229 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); | |
7230 | |
7231 /* Copy all but the current entry to the new list */ | |
7232 for(z=0;z<index;z++) | |
7233 { | |
7234 tmpitem[z] = thisitem[z]; | |
7235 } | |
7236 for(z=index+1;z<thisbox->count;z++) | |
7237 { | |
7238 tmpitem[z-1] = thisitem[z]; | |
7239 } | |
7240 | |
7241 thisbox->items = tmpitem; | |
7242 free(thisitem); | |
7243 thisbox->count--; | |
7244 /* If it isn't padding, reset the parent */ | |
7245 if(handle) | |
7246 WinSetParent(handle, HWND_OBJECT); | |
7247 /* Queue a redraw on the top-level window */ | |
7248 _dw_redraw(_toplevel_window(handle), TRUE); | |
7249 return DW_ERROR_NONE; | |
7250 } | |
7251 } | |
7252 return DW_ERROR_GENERAL; | |
7253 } | |
7254 | |
7255 /* | |
7256 * Remove windows (widgets) from a box at an arbitrary location. | |
7257 * Parameters: | |
7258 * box: Window handle of the box to be removed from. | |
7259 * index: 0 based index of packed items. | |
7260 * Returns: | |
7261 * Handle to the removed item on success, 0 on failure. | |
7262 */ | |
7263 HWND API dw_box_remove_at_index(HWND box, int index) | |
7264 { | |
7265 Box *thisbox = WinQueryWindowPtr(box, QWP_USER); | |
7266 | |
7267 /* Try to remove it from the layout */ | |
7268 if(thisbox && index > -1 && index < thisbox->count) | |
7269 { | |
7270 int z; | |
7271 Item *tmpitem, *thisitem = thisbox->items; | |
7272 HWND handle = thisitem[index].hwnd; | |
7273 | |
7274 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); | |
7275 | |
7276 /* Copy all but the current entry to the new list */ | |
7277 for(z=0;z<index;z++) | |
7278 { | |
7279 tmpitem[z] = thisitem[z]; | |
7280 } | |
7281 for(z=index+1;z<thisbox->count;z++) | |
7282 { | |
7283 tmpitem[z-1] = thisitem[z]; | |
7284 } | |
7285 | |
7286 thisbox->items = tmpitem; | |
7287 free(thisitem); | |
7288 thisbox->count--; | |
7289 /* If it isn't padding, reset the parent */ | |
7290 if(handle) | |
7291 WinSetParent(handle, HWND_OBJECT); | |
7292 /* Queue a redraw on the top-level window */ | |
7293 _dw_redraw(_toplevel_window(handle), TRUE); | |
7294 return DW_ERROR_NONE; | |
7295 } | |
7296 return DW_ERROR_GENERAL; | |
7297 } | |
7298 | |
7299 /* | |
7234 * Pack windows (widgets) into a box at an arbitrary location. | 7300 * Pack windows (widgets) into a box at an arbitrary location. |
7235 * Parameters: | 7301 * Parameters: |
7236 * box: Window handle of the box to be packed into. | 7302 * box: Window handle of the box to be packed into. |
7237 * item: Window handle of the item to be back. | 7303 * item: Window handle of the item to be back. |
7238 * index: 0 based index of packed items. | 7304 * index: 0 based index of packed items. |