/* GTK only has abssolute positioning using a GtkFixed container, so all elements returned by iupChildTreeGetNativeParentHandle should be a GtkFixed. If not looks in the native parent. */ static GtkFixed* gtkGetFixedParent(Ihandle* ih) { GtkWidget* widget = iupChildTreeGetNativeParentHandle(ih); while (widget && !GTK_IS_FIXED(widget)) widget = gtk_widget_get_parent(widget); return (GtkFixed*)widget; }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setNativeBounds (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) { GtkWidget *widget; void *ptr; gdk_threads_enter (); ptr = gtkpeer_get_widget (env, obj); widget = GTK_WIDGET (ptr); /* We assume that -1 is a width or height and not a request for the widget's natural size. */ width = width < 0 ? 0 : width; height = height < 0 ? 0 : height; if (!(width == 0 && height == 0)) { gtk_widget_set_size_request (widget, width, height); /* The GTK_IS_FIXED check here prevents gtk_fixed_move being called when our parent is a GtkScrolledWindow. In that case though, moving the child widget is invalid since a ScrollPane only has one child and that child is always located at (0, 0) in viewport coordinates. */ if (widget->parent != NULL && GTK_IS_FIXED (widget->parent)) gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y); } gdk_threads_leave (); }
static gboolean _GuiWindow_resizeCallback (GuiObject widget, GtkAllocation *allocation, gpointer void_me) { (void) widget; iam (GuiWindow); trace ("fixed received size allocation: (%ld, %ld), %ld x %ld.", (long) allocation -> x, (long) allocation -> y, (long) allocation -> width, (long) allocation -> height); if (allocation -> width != my d_width || allocation -> height != my d_height) { trace ("user changed the size of the window?"); /* * Apparently, GTK sends the size allocation message both to the shell and to its fixed-container child. * we could capture the message either from the shell or from the fixed; we choose to do it from the fixed. */ Melder_assert (GTK_IS_FIXED (widget)); /* * We move and resize all the children of the fixed. */ GList *children = GTK_FIXED (widget) -> children; for (GList *l = g_list_first (children); l != NULL; l = g_list_next (l)) { GtkFixedChild *listElement = (GtkFixedChild *) l -> data; GtkWidget *childWidget = listElement -> widget; Melder_assert (childWidget); Thing_cast (GuiThing, child, _GuiObject_getUserData (childWidget)); if (child) { GuiControl control = NULL; if (Thing_member (child, classGuiControl)) { control = static_cast <GuiControl> (child); } else if (Thing_member (child, classGuiMenu)) { Thing_cast (GuiMenu, menu, child); control = menu -> d_cascadeButton; } if (control) { /* * Move and resize. */ trace ("moving child of class %ls", Thing_className (control)); int left = control -> d_left, right = control -> d_right, top = control -> d_top, bottom = control -> d_bottom; if (left < 0) left += allocation -> width; // this replicates structGuiControl :: v_positionInForm () if (right <= 0) right += allocation -> width; if (top < 0) top += allocation -> height; if (bottom <= 0) bottom += allocation -> height; trace ("moving child to (%d,%d)", left, top); gtk_fixed_move (GTK_FIXED (widget), GTK_WIDGET (childWidget), left, top); gtk_widget_set_size_request (GTK_WIDGET (childWidget), right - left, bottom - top); trace ("moved child of class %ls", Thing_className (control)); } } } my d_width = allocation -> width; my d_height = allocation -> height; gtk_widget_set_size_request (GTK_WIDGET (widget), allocation -> width, allocation -> height); } trace ("end"); return FALSE; }
static gboolean _GuiWindow_resizeCallback (GuiObject widget, GtkAllocation *allocation, gpointer void_me) { (void) widget; iam (GuiWindow); trace (U"fixed received size allocation: (", allocation -> x, U", ", allocation -> y, U"), ", allocation -> width, U" x ", allocation -> height, U"."); if (allocation -> width != my d_width || allocation -> height != my d_height) { trace (U"user changed the size of the window?"); /* * Apparently, GTK sends the size allocation message both to the shell and to its fixed-container child. * we could capture the message either from the shell or from the fixed; we choose to do it from the fixed. */ Melder_assert (GTK_IS_FIXED (widget)); /* * We move and resize all the children of the fixed. */ gtk_container_foreach (GTK_CONTAINER (widget), _GuiWindow_child_resizeCallback, allocation); my d_width = allocation -> width; my d_height = allocation -> height; gtk_widget_set_size_request (GTK_WIDGET (widget), allocation -> width, allocation -> height); } trace (U"end"); return false; }