# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1335475117 0 # Node ID 36a090da4cb19171233c71814daf5dd63329d005 # Parent 724a7361cb42485be7dc3cb16e868f36e20d1d2c Initial implementation of dw_box_remove() for GTK2/3 and stub for dw_box_remove_at_index(). Fixed errors in the OS/2 and Windows dw_box_remove_at_index() implementations. diff -r 724a7361cb42 -r 36a090da4cb1 gtk/dw.c --- a/gtk/dw.c Thu Apr 26 20:47:50 2012 +0000 +++ b/gtk/dw.c Thu Apr 26 21:18:37 2012 +0000 @@ -10229,6 +10229,7 @@ if(!item) { item = gtk_label_new(""); + gtk_object_set_data(GTK_OBJECT(item), "_dw_padding", GINT_TO_POINTER(1)); gtk_widget_show_all(item); } @@ -10326,6 +10327,12 @@ else gtk_object_set_data(GTK_OBJECT(box), "_dw_group", (gpointer)item); } + /* If we previously incremented the reference count... drop it now that it is packed */ + if(gtk_object_get_data(GTK_OBJECT(item), "_dw_refed")) + { + g_object_unref(G_OBJECT(item)); + gtk_object_set_data(GTK_OBJECT(item), "_dw_refed", NULL); + } } DW_MUTEX_UNLOCK; @@ -10339,6 +10346,84 @@ } /* + * 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) +{ + int _locked_by_me = FALSE, retcode = DW_ERROR_GENERAL; + + DW_MUTEX_LOCK; + if(GTK_IS_WIDGET(handle)) + { + GtkWidget *box, *handle2 = handle; + GtkWidget *eventbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_eventbox"); + + /* Handle the invisible event box if it exists */ + if(eventbox && GTK_IS_WIDGET(eventbox)) + handle2 = eventbox; + + /* Check if we are removing a widget from a box */ + if((box = gtk_widget_get_parent(handle2)) && GTK_IS_TABLE(box)) + { + /* Get the number of items in the box... */ + int boxcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount")); + int boxtype = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype")); + gint pos; + + gtk_container_child_get(GTK_CONTAINER(box), handle2, boxtype == DW_VERT ? "top-attach" : "left-attach", &pos, NULL); + /* If we haven't incremented the reference count... raised it before removal */ + if(!gtk_object_get_data(GTK_OBJECT(handle2), "_dw_refed")) + { + g_object_ref(G_OBJECT(handle2)); + gtk_object_set_data(GTK_OBJECT(handle2), "_dw_refed", GINT_TO_POINTER(1)); + } + gtk_container_remove(GTK_CONTAINER(box), handle2); + retcode = DW_ERROR_NONE; + + /* If we are destroying the last item in the box this isn't necessary */ + if((pos+1) < boxcount) + { + /* If we need to contract the table, reposition all the children */ + gtk_container_forall(GTK_CONTAINER(box),_rearrange_table_destroy, GINT_TO_POINTER(boxtype == DW_VERT ? pos : -(pos+1))); + } + + if(boxcount > 0) + { + /* Decrease the count by 1 */ + boxcount--; + gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount)); + } + + /* If we aren't trying to resize the table to 0... */ + if(boxcount > 0) + { + /* Contract the table to the size we need */ + gtk_table_resize(GTK_TABLE(box), boxtype == DW_VERT ? boxcount : 1, boxtype == DW_VERT ? 1 : boxcount); + } + } + } + DW_MUTEX_UNLOCK; + return retcode; +} + +/* + * 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 0; +} + +/* * Pack windows (widgets) into a box at an arbitrary location. * Parameters: * box: Window handle of the box to be packed into. diff -r 724a7361cb42 -r 36a090da4cb1 gtk3/dw.c --- a/gtk3/dw.c Thu Apr 26 20:47:50 2012 +0000 +++ b/gtk3/dw.c Thu Apr 26 21:18:37 2012 +0000 @@ -8473,6 +8473,7 @@ if(!item) { item = gtk_label_new(""); + g_object_set_data(G_OBJECT(item), "_dw_padding", GINT_TO_POINTER(1)); gtk_widget_show_all(item); } /* Due to GTK3 minimum size limitations, if we are packing a widget @@ -8626,6 +8627,12 @@ else g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item); } + /* If we previously incremented the reference count... drop it now that it is packed */ + if(g_object_get_data(G_OBJECT(item), "_dw_refed")) + { + g_object_unref(G_OBJECT(item)); + g_object_set_data(G_OBJECT(item), "_dw_refed", NULL); + } } DW_MUTEX_UNLOCK; @@ -8639,6 +8646,67 @@ } /* + * 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) +{ + int _locked_by_me = FALSE, retcode = DW_ERROR_GENERAL; + + DW_MUTEX_LOCK; + if(GTK_IS_WIDGET(handle)) + { + GtkWidget *box, *handle2 = handle; + GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_eventbox"); + + /* Handle the invisible event box if it exists */ + if(eventbox && GTK_IS_WIDGET(eventbox)) + handle2 = eventbox; + + /* Check if we are removing a widget from a box */ + if((box = gtk_widget_get_parent(handle2)) && GTK_IS_GRID(box)) + { + /* Get the number of items in the box... */ + int boxcount = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(box), "_dw_boxcount")); + + if(boxcount > 0) + { + /* Decrease the count by 1 */ + boxcount--; + g_object_set_data(G_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount)); + } + /* If we haven't incremented the reference count... raise it before removal */ + if(!g_object_get_data(G_OBJECT(handle2), "_dw_refed")) + { + g_object_ref(G_OBJECT(handle2)); + g_object_set_data(G_OBJECT(handle2), "_dw_refed", GINT_TO_POINTER(1)); + } + /* Remove the widget from the box */ + gtk_container_remove(GTK_CONTAINER(box), handle2); + retcode = DW_ERROR_NONE; + } + } + DW_MUTEX_UNLOCK; + return retcode; +} + +/* + * 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 0; +} + +/* * Pack windows (widgets) into a box at an arbitrary location. * Parameters: * box: Window handle of the box to be packed into. diff -r 724a7361cb42 -r 36a090da4cb1 os2/dw.c --- a/os2/dw.c Thu Apr 26 20:47:50 2012 +0000 +++ b/os2/dw.c Thu Apr 26 21:18:37 2012 +0000 @@ -7290,10 +7290,10 @@ if(handle) WinSetParent(handle, HWND_OBJECT, FALSE); /* Queue a redraw on the top-level window */ - _dw_redraw(_toplevel_window(handle), TRUE); - return DW_ERROR_NONE; - } - return DW_ERROR_GENERAL; + _dw_redraw(_toplevel_window(box), TRUE); + return handle; + } + return 0; } /* diff -r 724a7361cb42 -r 36a090da4cb1 template/dw.c --- a/template/dw.c Thu Apr 26 20:47:50 2012 +0000 +++ b/template/dw.c Thu Apr 26 21:18:37 2012 +0000 @@ -617,7 +617,7 @@ */ HWND API dw_box_remove_at_index(HWND box, int index) { - return DW_ERROR_GENERAL; + return 0; } /* diff -r 724a7361cb42 -r 36a090da4cb1 win/dw.c --- a/win/dw.c Thu Apr 26 20:47:50 2012 +0000 +++ b/win/dw.c Thu Apr 26 21:18:37 2012 +0000 @@ -7066,10 +7066,10 @@ 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; + _dw_redraw(_toplevel_window(box), TRUE); + return handle; + } + return 0; } /*