# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1335472419 0 # Node ID 9dbd2984c1e5f0225fee11cbaa7e7c8a212005fc # Parent df25fee81502005ef821bc6dcdc67fd2b0a5e826 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. diff -r df25fee81502 -r 9dbd2984c1e5 dw.h --- a/dw.h Tue Apr 24 16:30:11 2012 +0000 +++ b/dw.h Thu Apr 26 20:33:39 2012 +0000 @@ -1463,6 +1463,8 @@ void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad); void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad); void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad); +HWND API dw_box_remove_at_index(HWND box, int index); +int API dw_box_remove(HWND handle); #if !defined(__OS2__) && !defined(__WIN32__) && !defined(__EMX__) && !defined(__MAC__) int API dw_int_init(DWResources *res, int newthread, int *argc, char **argv[]); #define dw_init(a, b, c) dw_int_init(&_resources, a, &b, &c) diff -r df25fee81502 -r 9dbd2984c1e5 dwtest.c --- a/dwtest.c Tue Apr 24 16:30:11 2012 +0000 +++ b/dwtest.c Thu Apr 26 20:33:39 2012 +0000 @@ -882,13 +882,16 @@ dw_box_pack_start(lbbox, buttonbox, 0, 0, TRUE, TRUE, 0); + cancelbutton = dw_button_new("Exit", 1002L); + dw_box_pack_start(buttonbox, cancelbutton, 130, 30, TRUE, TRUE, 2); + cursortogglebutton = dw_button_new("Set Cursor pointer - CLOCK", 1003L); dw_box_pack_start(buttonbox, cursortogglebutton, 130, 30, TRUE, TRUE, 2); okbutton = dw_button_new("Turn Off Annoying Beep!", 1001L); dw_box_pack_start(buttonbox, okbutton, 130, 30, TRUE, TRUE, 2); - cancelbutton = dw_button_new("Exit", 1002L); + dw_box_remove(cancelbutton); dw_box_pack_start(buttonbox, cancelbutton, 130, 30, TRUE, TRUE, 2); dw_window_click_default( mainwindow, cancelbutton ); diff -r df25fee81502 -r 9dbd2984c1e5 os2/dw.c --- a/os2/dw.c Tue Apr 24 16:30:11 2012 +0000 +++ b/os2/dw.c Thu Apr 26 20:33:39 2012 +0000 @@ -4493,7 +4493,6 @@ int API dw_window_destroy(HWND handle) { HWND frame, menu, parent; - Box *thisbox; if(!handle) return DW_ERROR_UNKNOWN; @@ -4512,7 +4511,6 @@ } parent = WinQueryWindow(handle, QW_PARENT); - thisbox = WinQueryWindowPtr(parent, QWP_USER); frame = (HWND)dw_window_get_data(handle, "_dw_combo_box"); if((menu = WinWindowFromID(handle, FID_MENU)) != NULLHANDLE) @@ -4521,41 +4519,7 @@ /* If it is a desktop window let WM_DESTROY handle it */ if(parent != desktop) { - /* If the parent box has items... - * try to remove it from the layout - */ - if(thisbox && thisbox->count) - { - int z, index = -1; - Item *tmpitem, *thisitem = thisbox->items; - - for(z=0;zcount;z++) - { - if(thisitem[z].hwnd == handle) - index = z; - } - - if(index == -1) - return 0; - - tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); - - /* Copy all but the current entry to the new list */ - for(z=0;zcount;z++) - { - tmpitem[z-1] = thisitem[z]; - } - - thisbox->items = tmpitem; - free(thisitem); - thisbox->count--; - /* Queue a redraw on the top-level window */ - _dw_redraw(_toplevel_window(handle), TRUE); - } + dw_box_remove(handle); _free_window_memory(frame ? frame : handle); } return WinDestroyWindow(frame ? frame : handle); @@ -7231,6 +7195,108 @@ } /* + * Remove windows (widgets) from the box they are packed into. + * Parameters: + * handle: Window handle of the item to be back. + * Returns: + * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. + */ +int API dw_box_remove(HWND handle) +{ + HWND parent = WinQueryWindow(handle, QW_PARENT); + + if(parent != desktop) + { + Box *thisbox = WinQueryWindowPtr(parent, QWP_USER); + + /* If the parent box has items... + * try to remove it from the layout + */ + if(thisbox && thisbox->count) + { + int z, index = -1; + Item *tmpitem, *thisitem = thisbox->items; + + for(z=0;zcount;z++) + { + if(thisitem[z].hwnd == handle) + index = z; + } + + if(index == -1) + return DW_ERROR_GENERAL; + + tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); + + /* Copy all but the current entry to the new list */ + for(z=0;zcount;z++) + { + tmpitem[z-1] = thisitem[z]; + } + + thisbox->items = tmpitem; + free(thisitem); + thisbox->count--; + /* If it isn't padding, reset the parent */ + if(handle) + WinSetParent(handle, HWND_OBJECT); + /* Queue a redraw on the top-level window */ + _dw_redraw(_toplevel_window(handle), TRUE); + return DW_ERROR_NONE; + } + } + return DW_ERROR_GENERAL; +} + +/* + * Remove windows (widgets) from a box at an arbitrary location. + * Parameters: + * box: Window handle of the box to be removed from. + * index: 0 based index of packed items. + * Returns: + * Handle to the removed item on success, 0 on failure. + */ +HWND API dw_box_remove_at_index(HWND box, int index) +{ + Box *thisbox = WinQueryWindowPtr(box, QWP_USER); + + /* Try to remove it from the layout */ + if(thisbox && index > -1 && index < thisbox->count) + { + int z; + Item *tmpitem, *thisitem = thisbox->items; + HWND handle = thisitem[index].hwnd; + + tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); + + /* Copy all but the current entry to the new list */ + for(z=0;zcount;z++) + { + tmpitem[z-1] = thisitem[z]; + } + + thisbox->items = tmpitem; + free(thisitem); + thisbox->count--; + /* If it isn't padding, reset the parent */ + if(handle) + WinSetParent(handle, HWND_OBJECT); + /* Queue a redraw on the top-level window */ + _dw_redraw(_toplevel_window(handle), TRUE); + return DW_ERROR_NONE; + } + return DW_ERROR_GENERAL; +} + +/* * Pack windows (widgets) into a box at an arbitrary location. * Parameters: * box: Window handle of the box to be packed into. diff -r df25fee81502 -r 9dbd2984c1e5 os2/dw.def --- a/os2/dw.def Tue Apr 24 16:30:11 2012 +0000 +++ b/os2/dw.def Thu Apr 26 20:33:39 2012 +0000 @@ -35,6 +35,9 @@ dw_mdi_new @46 + dw_box_remove @47 + dw_box_remove_at_index @48 + dw_window_new @50 dw_window_show @51 dw_window_hide @52 diff -r df25fee81502 -r 9dbd2984c1e5 template/dw.c --- a/template/dw.c Tue Apr 24 16:30:11 2012 +0000 +++ b/template/dw.c Thu Apr 26 20:33:39 2012 +0000 @@ -596,6 +596,31 @@ } /* + * Remove windows (widgets) from the box they are packed into. + * Parameters: + * handle: Window handle of the item to be back. + * Returns: + * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. + */ +int API dw_box_remove(HWND handle) +{ + return DW_ERROR_GENERAL; +} + +/* + * Remove windows (widgets) from a box at an arbitrary location. + * Parameters: + * box: Window handle of the box to be removed from. + * index: 0 based index of packed items. + * Returns: + * Handle to the removed item on success, 0 on failure. + */ +HWND API dw_box_remove_at_index(HWND box, int index) +{ + return DW_ERROR_GENERAL; +} + +/* * Pack windows (widgets) into a box at an arbitrary location. * Parameters: * box: Window handle of the box to be packed into. diff -r df25fee81502 -r 9dbd2984c1e5 win/dw.c --- a/win/dw.c Tue Apr 24 16:30:11 2012 +0000 +++ b/win/dw.c Thu Apr 26 20:33:39 2012 +0000 @@ -4323,7 +4323,6 @@ int API dw_window_destroy(HWND handle) { HWND parent; - Box *thisbox; HMENU menu; /* Handle special case for menu handle */ @@ -4341,7 +4340,6 @@ } parent = GetParent(handle); - thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA); menu = GetMenu(handle); if(menu) @@ -4350,41 +4348,7 @@ /* If it is a desktop window let WM_DESTROY handle it */ if(parent != HWND_DESKTOP) { - /* If the parent box has items... - * try to remove it from the layout - */ - if(thisbox && thisbox->count) - { - int z, index = -1; - Item *tmpitem, *thisitem = thisbox->items; - - for(z=0;zcount;z++) - { - if(thisitem[z].hwnd == handle) - index = z; - } - - if(index == -1) - return 0; - - tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); - - /* Copy all but the current entry to the new list */ - for(z=0;zcount;z++) - { - tmpitem[z-1] = thisitem[z]; - } - - thisbox->items = tmpitem; - free(thisitem); - thisbox->count--; - /* Queue a redraw on the top-level window */ - _dw_redraw(_toplevel_window(handle), TRUE); - } + dw_box_remove(handle); _free_window_memory(handle, 0); EnumChildWindows(handle, _free_window_memory, 0); } @@ -7009,10 +6973,110 @@ } /* + * Remove windows (widgets) from the box they are packed into. + * Parameters: + * handle: Window handle of the item to be back. + * Returns: + * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. + */ +int API dw_box_remove(HWND handle) +{ + HWND parent = GetParent(handle); + + if(handle && parent != HWND_DESKTOP) + { + Box *thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA); + + /* If the parent box has items... + * try to remove it from the layout + */ + if(thisbox && thisbox->count) + { + int z, index = -1; + Item *tmpitem, *thisitem = thisbox->items; + + for(z=0;zcount;z++) + { + if(thisitem[z].hwnd == handle) + index = z; + } + + if(index == -1) + return DW_ERROR_GENERAL; + + tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); + + /* Copy all but the current entry to the new list */ + for(z=0;zcount;z++) + { + tmpitem[z-1] = thisitem[z]; + } + + thisbox->items = tmpitem; + free(thisitem); + thisbox->count--; + SetParent(handle, DW_HWND_OBJECT); + /* Queue a redraw on the top-level window */ + _dw_redraw(_toplevel_window(handle), TRUE); + return DW_ERROR_NONE; + } + } + return DW_ERROR_GENERAL; +} + +/* + * Remove windows (widgets) from a box at an arbitrary location. + * Parameters: + * box: Window handle of the box to be removed from. + * index: 0 based index of packed items. + * Returns: + * Handle to the removed item on success, 0 on failure. + */ +HWND API dw_box_remove_at_index(HWND box, int index) +{ + Box *thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA); + + /* Try to remove it from the layout */ + if(thisbox && index > -1 && index < thisbox->count) + { + int z; + Item *tmpitem, *thisitem = thisbox->items; + HWND handle = thisitem[index].hwnd; + + tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); + + /* Copy all but the current entry to the new list */ + for(z=0;zcount;z++) + { + tmpitem[z-1] = thisitem[z]; + } + + thisbox->items = tmpitem; + free(thisitem); + thisbox->count--; + /* If it isn't padding, reset the parent */ + if(handle) + SetParent(handle, DW_HWND_OBJECT); + /* Queue a redraw on the top-level window */ + _dw_redraw(_toplevel_window(handle), TRUE); + return DW_ERROR_NONE; + } + return DW_ERROR_GENERAL; +} + +/* * Pack windows (widgets) into a box at an arbitrary location. * Parameters: * box: Window handle of the box to be packed into. - * item: Window handle of the item to be back. + * item: Window handle of the item to pack. * index: 0 based index of packed items. * width: Width in pixels of the item or -1 to be self determined. * height: Height in pixels of the item or -1 to be self determined. @@ -7029,7 +7093,7 @@ * Pack windows (widgets) into a box from the start (or top). * Parameters: * box: Window handle of the box to be packed into. - * item: Window handle of the item to be back. + * item: Window handle of the item to pack. * width: Width in pixels of the item or -1 to be self determined. * height: Height in pixels of the item or -1 to be self determined. * hsize: TRUE if the window (widget) should expand horizontally to fill space given. @@ -7048,7 +7112,7 @@ * Pack windows (widgets) into a box from the end (or bottom). * Parameters: * box: Window handle of the box to be packed into. - * item: Window handle of the item to be back. + * item: Window handle of the item to pack. * width: Width in pixels of the item or -1 to be self determined. * height: Height in pixels of the item or -1 to be self determined. * hsize: TRUE if the window (widget) should expand horizontally to fill space given. diff -r df25fee81502 -r 9dbd2984c1e5 win/dw.def --- a/win/dw.def Tue Apr 24 16:30:11 2012 +0000 +++ b/win/dw.def Thu Apr 26 20:33:39 2012 +0000 @@ -31,6 +31,9 @@ dw_box_pack_at_index @44 dw_mdi_new @46 + + dw_box_remove @47 + dw_box_remove_at_index @48 dw_window_new @50 dw_window_show @51