Mercurial > dwindows
comparison gtk4/dw.c @ 2301:69b06073a87d
GTK4: The "realize" signal is not quite the same as "size-allocate" so if
the widget allocation is too small keep requesting it be called again until
the size is valid.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 08 Feb 2021 23:07:52 +0000 |
parents | 6e47d510dbbb |
children | 785775b9002f |
comparison
equal
deleted
inserted
replaced
2300:6e47d510dbbb | 2301:69b06073a87d |
---|---|
8585 } | 8585 } |
8586 } | 8586 } |
8587 } | 8587 } |
8588 | 8588 |
8589 /* Function to do delayed positioning */ | 8589 /* Function to do delayed positioning */ |
8590 gboolean _splitbar_set_percent(gpointer data) | 8590 gboolean _dw_splitbar_set_percent(gpointer data) |
8591 { | 8591 { |
8592 GtkWidget *widget = data; | 8592 GtkWidget *widget = data; |
8593 float *percent = (float *)g_object_get_data(G_OBJECT(widget), "_dw_percent"); | 8593 float *percent = (float *)g_object_get_data(G_OBJECT(widget), "_dw_percent"); |
8594 | 8594 |
8595 if(percent) | 8595 if(percent) |
8596 { | 8596 { |
8597 GtkAllocation alloc; | 8597 GtkAllocation alloc; |
8598 | 8598 |
8599 gtk_widget_get_allocation(widget, &alloc); | 8599 gtk_widget_get_allocation(widget, &alloc); |
8600 | 8600 |
8601 if(gtk_orientable_get_orientation(GTK_ORIENTABLE(widget)) == GTK_ORIENTATION_HORIZONTAL) | 8601 if(alloc.width > 10 && alloc.height > 10) |
8602 gtk_paned_set_position(GTK_PANED(widget), (int)(alloc.width * (*percent / 100.0))); | 8602 { |
8603 if(gtk_orientable_get_orientation(GTK_ORIENTABLE(widget)) == GTK_ORIENTATION_HORIZONTAL) | |
8604 gtk_paned_set_position(GTK_PANED(widget), (int)(alloc.width * (*percent / 100.0))); | |
8605 else | |
8606 gtk_paned_set_position(GTK_PANED(widget), (int)(alloc.height * (*percent / 100.0))); | |
8607 g_object_set_data(G_OBJECT(widget), "_dw_percent", NULL); | |
8608 free(percent); | |
8609 } | |
8603 else | 8610 else |
8604 gtk_paned_set_position(GTK_PANED(widget), (int)(alloc.height * (*percent / 100.0))); | 8611 return TRUE; |
8605 g_object_set_data(G_OBJECT(widget), "_dw_percent", NULL); | |
8606 free(percent); | |
8607 } | 8612 } |
8608 return FALSE; | 8613 return FALSE; |
8609 } | 8614 } |
8610 | 8615 |
8611 /* Reposition the bar according to the percentage */ | 8616 /* Reposition the bar according to the percentage */ |
8612 static gint _splitbar_realize(GtkWidget *widget, gpointer data) | 8617 static gint _dw_splitbar_realize(GtkWidget *widget, gpointer data) |
8613 { | 8618 { |
8614 float *percent = (float *)g_object_get_data(G_OBJECT(widget), "_dw_percent"); | 8619 float *percent = (float *)g_object_get_data(G_OBJECT(widget), "_dw_percent"); |
8615 | 8620 |
8616 /* Prevent infinite recursion ;) */ | 8621 /* Prevent infinite recursion ;) */ |
8617 if(!percent) | 8622 if(!percent) |
8618 return FALSE; | 8623 return FALSE; |
8619 | 8624 |
8620 g_idle_add(_splitbar_set_percent, widget); | 8625 g_idle_add(_dw_splitbar_set_percent, widget); |
8621 return FALSE; | 8626 return FALSE; |
8622 } | 8627 } |
8623 | 8628 |
8624 /* | 8629 /* |
8625 * Creates a splitbar window (widget) with given parameters. | 8630 * Creates a splitbar window (widget) with given parameters. |
8643 gtk_paned_set_resize_end_child(GTK_PANED(tmp), TRUE); | 8648 gtk_paned_set_resize_end_child(GTK_PANED(tmp), TRUE); |
8644 gtk_paned_set_shrink_end_child(GTK_PANED(tmp), FALSE); | 8649 gtk_paned_set_shrink_end_child(GTK_PANED(tmp), FALSE); |
8645 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); | 8650 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); |
8646 *percent = 50.0; | 8651 *percent = 50.0; |
8647 g_object_set_data(G_OBJECT(tmp), "_dw_percent", (gpointer)percent); | 8652 g_object_set_data(G_OBJECT(tmp), "_dw_percent", (gpointer)percent); |
8648 g_signal_connect(G_OBJECT(tmp), "realize", G_CALLBACK(_splitbar_realize), NULL); | 8653 g_signal_connect(G_OBJECT(tmp), "realize", G_CALLBACK(_dw_splitbar_realize), NULL); |
8649 gtk_widget_show(tmp); | 8654 gtk_widget_show(tmp); |
8650 return tmp; | 8655 return tmp; |
8651 } | 8656 } |
8652 | 8657 |
8653 /* | 8658 /* |