Mercurial > dwindows
comparison gtk/dw.c @ 1657:f7db576f6d17
Rewrite of dw_window_destroy() on GTK2 so that the table contracts removing
empty cells when destroying child widgets. This keeps the indexes correct
for packing later. Similar in functionality to the last commit for GTK3...
but uglier although it works better because the GTK3 fix just leaves
the empty cells and skips over them... this actually removes the cells.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 10 Apr 2012 21:19:11 +0000 |
parents | c6ebff29a916 |
children | f2a3b25a9507 |
comparison
equal
deleted
inserted
replaced
1656:01f59ba51e7f | 1657:f7db576f6d17 |
---|---|
2818 gtk_widget_hide(handle); | 2818 gtk_widget_hide(handle); |
2819 DW_MUTEX_UNLOCK; | 2819 DW_MUTEX_UNLOCK; |
2820 return 0; | 2820 return 0; |
2821 } | 2821 } |
2822 | 2822 |
2823 /* Internal function that changes the attachment properties in a table for destroying. */ | |
2824 void _rearrange_table_destroy(GtkWidget *widget, gpointer data) | |
2825 { | |
2826 gint pos = GPOINTER_TO_INT(data); | |
2827 GtkContainer *cont = gtk_object_get_data(GTK_OBJECT(widget), "_dw_table"); | |
2828 guint oldpos; | |
2829 | |
2830 /* Drop out if missing table */ | |
2831 if(!cont) | |
2832 return; | |
2833 | |
2834 /* Check orientation */ | |
2835 if(pos < 0) | |
2836 { | |
2837 /* Horz */ | |
2838 pos = -(pos + 1); | |
2839 gtk_container_child_get(cont, widget, "left-attach", &oldpos, NULL); | |
2840 if(oldpos >= pos) | |
2841 { | |
2842 gtk_container_child_set(cont, widget, "left-attach", (oldpos - 1), "right-attach", oldpos, NULL); | |
2843 } | |
2844 } | |
2845 else | |
2846 { | |
2847 /* Vert */ | |
2848 gtk_container_child_get(cont, widget, "top-attach", &oldpos, NULL); | |
2849 if(oldpos >= pos) | |
2850 { | |
2851 gtk_container_child_set(cont, widget, "top-attach", (oldpos - 1), "bottom-attach", oldpos, NULL); | |
2852 } | |
2853 } | |
2854 } | |
2855 | |
2823 /* | 2856 /* |
2824 * Destroys a window and all of it's children. | 2857 * Destroys a window and all of it's children. |
2825 * Parameters: | 2858 * Parameters: |
2826 * handle: The window handle to destroy. | 2859 * handle: The window handle to destroy. |
2827 */ | 2860 */ |
2842 gtk_mdi_remove(GTK_MDI(mdi), handle); | 2875 gtk_mdi_remove(GTK_MDI(mdi), handle); |
2843 } | 2876 } |
2844 #endif | 2877 #endif |
2845 if(GTK_IS_WIDGET(handle)) | 2878 if(GTK_IS_WIDGET(handle)) |
2846 { | 2879 { |
2880 GtkWidget *box, *handle2 = handle; | |
2847 GtkWidget *eventbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_eventbox"); | 2881 GtkWidget *eventbox = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_eventbox"); |
2848 | 2882 |
2883 /* Handle the invisible event box if it exists */ | |
2849 if(eventbox && GTK_IS_WIDGET(eventbox)) | 2884 if(eventbox && GTK_IS_WIDGET(eventbox)) |
2850 gtk_widget_destroy(eventbox); | 2885 handle2 = eventbox; |
2886 | |
2887 /* Check if we are removing a widget from a box */ | |
2888 if((box = gtk_widget_get_parent(handle2)) && GTK_IS_TABLE(box)) | |
2889 { | |
2890 /* Get the number of items in the box... */ | |
2891 int boxcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount")); | |
2892 int boxtype = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype")); | |
2893 gint pos; | |
2894 | |
2895 gtk_container_child_get(GTK_CONTAINER(box), handle2, boxtype == DW_VERT ? "top-attach" : "left-attach", &pos, NULL); | |
2896 gtk_widget_destroy(handle2); | |
2897 | |
2898 /* If we are destroying the last item in the box this isn't necessary */ | |
2899 if((pos+1) < boxcount) | |
2900 { | |
2901 /* If we need to contract the table, reposition all the children */ | |
2902 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table_destroy, GINT_TO_POINTER(boxtype == DW_VERT ? pos : -(pos+1))); | |
2903 } | |
2904 | |
2905 if(boxcount > 0) | |
2906 { | |
2907 /* Decrease the count by 1 */ | |
2908 boxcount--; | |
2909 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount)); | |
2910 } | |
2911 | |
2912 /* If we aren't trying to resize the table to 0... */ | |
2913 if(boxcount > 0) | |
2914 { | |
2915 /* Contract the table to the size we need */ | |
2916 gtk_table_resize(GTK_TABLE(box), boxtype == DW_VERT ? boxcount : 1, boxtype == DW_VERT ? 1 : boxcount); | |
2917 } | |
2918 } | |
2851 else | 2919 else |
2852 gtk_widget_destroy(handle); | 2920 { |
2921 /* Finally destroy the widget */ | |
2922 gtk_widget_destroy(handle2); | |
2923 } | |
2853 } | 2924 } |
2854 DW_MUTEX_UNLOCK; | 2925 DW_MUTEX_UNLOCK; |
2855 return 0; | 2926 return 0; |
2856 } | 2927 } |
2857 | 2928 |