comparison gtk/dw.c @ 1677:60f8ae42a0be

Implement dw_box_remove_at_index() for GTK2.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 27 Apr 2012 15:33:05 +0000
parents ca5123dc5819
children 896f377a47c7
comparison
equal deleted inserted replaced
1676:007bced14910 1677:60f8ae42a0be
9219 GdkPixbuf *pborig = gdk_pixbuf_scale_simple(srcp->pixbuf, width, height, GDK_INTERP_BILINEAR); 9219 GdkPixbuf *pborig = gdk_pixbuf_scale_simple(srcp->pixbuf, width, height, GDK_INTERP_BILINEAR);
9220 gdk_pixbuf_render_threshold_alpha(pborig, bitmap, 0, 0, 0, 0, width, height, 1); 9220 gdk_pixbuf_render_threshold_alpha(pborig, bitmap, 0, 0, 0, 0, width, height, 1);
9221 gdk_gc_set_clip_mask( gc, bitmap ); 9221 gdk_gc_set_clip_mask( gc, bitmap );
9222 gdk_gc_set_clip_origin( gc, xdest, ydest ); 9222 gdk_gc_set_clip_origin( gc, xdest, ydest );
9223 gdk_bitmap_unref(bitmap); 9223 gdk_bitmap_unref(bitmap);
9224 gdk_pixbuf_unref(pborig); 9224 g_object_unref(G_OBJECT(pborig));
9225 } 9225 }
9226 /* Draw the final pixbuf onto the destination drawable */ 9226 /* Draw the final pixbuf onto the destination drawable */
9227 gdk_draw_pixbuf(dest ? dest->window : destp->pixmap, gc, pbdst, 0, 0, xdest, ydest, width, height, GDK_RGB_DITHER_NONE, 0, 0); 9227 gdk_draw_pixbuf(dest ? dest->window : destp->pixmap, gc, pbdst, 0, 0, xdest, ydest, width, height, GDK_RGB_DITHER_NONE, 0, 0);
9228 /* Cleanup so we don't leak */ 9228 /* Cleanup so we don't leak */
9229 gdk_pixbuf_unref(pbsrc); 9229 g_object_unref(G_OBJECT(pbsrc));
9230 gdk_pixbuf_unref(pbdst); 9230 g_object_unref(G_OBJECT(pbdst));
9231 } 9231 }
9232 else 9232 else
9233 #endif 9233 #endif
9234 { 9234 {
9235 /* 9235 /*
10419 * Handle to the removed item on success, 0 on failure. 10419 * Handle to the removed item on success, 0 on failure.
10420 */ 10420 */
10421 HWND API dw_box_remove_at_index(HWND box, int index) 10421 HWND API dw_box_remove_at_index(HWND box, int index)
10422 { 10422 {
10423 HWND retval = 0; 10423 HWND retval = 0;
10424 #if 0
10425 int _locked_by_me = FALSE; 10424 int _locked_by_me = FALSE;
10426 10425
10427 DW_MUTEX_LOCK; 10426 DW_MUTEX_LOCK;
10428 /* Check if we are removing a widget from a box */ 10427 /* Check if we are removing a widget from a box */
10429 if(GTK_IS_TABLE(box)) 10428 if(GTK_IS_TABLE(box))
10430 { 10429 {
10431 /* Get the number of items in the box... */ 10430 /* Get the number of items in the box... */
10432 int boxcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount")); 10431 int boxcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxcount"));
10433 int boxtype = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype")); 10432 int boxtype = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(box), "_dw_boxtype"));
10433 GList *children, *child;
10434 GtkWidget *item = NULL;
10434 gint pos; 10435 gint pos;
10435 10436
10436 gtk_container_child_get(GTK_CONTAINER(box), handle2, boxtype == DW_VERT ? "top-attach" : "left-attach", &pos, NULL); 10437 children = child = gtk_container_get_children(GTK_CONTAINER(box));
10437 gtk_widget_destroy(handle2); 10438
10438 10439 /* Locate the child with the correct attachment point in the table */
10439 /* If we haven't incremented the reference count... raise it before removal */ 10440 while(child)
10440 if(gtk_object_get_data(GTK_OBJECT(item), "_dw_padding")) 10441 {
10441 gtk_widget_destroy(item); 10442 gtk_container_child_get(GTK_CONTAINER(box), (GtkWidget *)child->data, boxtype == DW_VERT ? "top-attach" : "left-attach", &pos, NULL);
10442 else 10443 if(pos == index)
10443 {
10444 if(!gtk_object_get_data(GTK_OBJECT(item), "_dw_refed"))
10445 { 10444 {
10446 g_object_ref(G_OBJECT(item)); 10445 item = (GtkWidget *)child->data;
10447 gtk_object_set_data(GTK_OBJECT(item), "_dw_refed", GINT_TO_POINTER(1)); 10446 child = NULL;
10448 } 10447 }
10449 /* Remove the widget from the box */ 10448 else
10450 gtk_container_remove(GTK_CONTAINER(box), item); 10449 child = child->next;
10451 retval = item; 10450 }
10452 } 10451
10452 /* Free the returned list */
10453 if(children)
10454 g_list_free(children);
10453 10455
10454 /* If we are destroying the last item in the box this isn't necessary */ 10456 if(item)
10455 if((pos+1) < boxcount) 10457 {
10456 { 10458 /* If we haven't incremented the reference count... raise it before removal */
10457 /* If we need to contract the table, reposition all the children */ 10459 if(gtk_object_get_data(GTK_OBJECT(item), "_dw_padding"))
10458 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table_destroy, GINT_TO_POINTER(boxtype == DW_VERT ? pos : -(pos+1))); 10460 gtk_widget_destroy(item);
10459 } 10461 else
10460 10462 {
10461 if(boxcount > 0) 10463 if(!gtk_object_get_data(GTK_OBJECT(item), "_dw_refed"))
10462 { 10464 {
10463 /* Decrease the count by 1 */ 10465 g_object_ref(G_OBJECT(item));
10464 boxcount--; 10466 gtk_object_set_data(GTK_OBJECT(item), "_dw_refed", GINT_TO_POINTER(1));
10465 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount)); 10467 }
10466 } 10468 /* Remove the widget from the box */
10467 10469 gtk_container_remove(GTK_CONTAINER(box), item);
10468 /* If we aren't trying to resize the table to 0... */ 10470 retval = item;
10469 if(boxcount > 0) 10471 }
10470 { 10472
10471 /* Contract the table to the size we need */ 10473 /* If we are destroying the last item in the box this isn't necessary */
10472 gtk_table_resize(GTK_TABLE(box), boxtype == DW_VERT ? boxcount : 1, boxtype == DW_VERT ? 1 : boxcount); 10474 if((pos+1) < boxcount)
10473 } 10475 {
10474 } 10476 /* If we need to contract the table, reposition all the children */
10475 else 10477 gtk_container_forall(GTK_CONTAINER(box),_rearrange_table_destroy, GINT_TO_POINTER(boxtype == DW_VERT ? pos : -(pos+1)));
10476 { 10478 }
10477 /* Finally destroy the widget */ 10479
10478 gtk_widget_destroy(handle2); 10480 if(boxcount > 0)
10479 } 10481 {
10480 DW_MUTEX_UNLOCK; 10482 /* Decrease the count by 1 */
10481 #endif 10483 boxcount--;
10484 gtk_object_set_data(GTK_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount));
10485 }
10486
10487 /* If we aren't trying to resize the table to 0... */
10488 if(boxcount > 0)
10489 {
10490 /* Contract the table to the size we need */
10491 gtk_table_resize(GTK_TABLE(box), boxtype == DW_VERT ? boxcount : 1, boxtype == DW_VERT ? 1 : boxcount);
10492 }
10493 }
10494 }
10495 DW_MUTEX_UNLOCK;
10482 return retval; 10496 return retval;
10483 } 10497 }
10484 10498
10485 /* 10499 /*
10486 * Pack windows (widgets) into a box at an arbitrary location. 10500 * Pack windows (widgets) into a box at an arbitrary location.