This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui][PATCH] Fix text positioning on Labels


Hi,

I committed this to java-gui-branch.  GtkLabels' size requests were not
being reset upon revalidation because they are now packed inside a
GtkEventBox.  This was causing labels to be off-centre when they were
re-added to an already-visible top-level container.  This patch fixes
the problem.

Tom

2004-10-13  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* gnu/java/awt/peer/gtk/GtkButtonPeer.java,
	jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c
	(setNativeBounds): Set GtkEventBox, GtkButton and GtkLabel size
	requests.
	* gnu/java/awt/peer/gtk/GtkComponentPeer.java,
	jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
	(setNativeBounds): Make package private.  Set size request even
	if GTK parent is NULL.
	* gnu/java/awt/peer/gtk/GtkLabelPeer.java,
	jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c
	(setNativeBounds): Set GtkEventBox and GtkLabel size requests.


Index: gnu/java/awt/peer/gtk/GtkButtonPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkButtonPeer.java,v
retrieving revision 1.8.2.9
diff -u -r1.8.2.9 GtkButtonPeer.java
--- gnu/java/awt/peer/gtk/GtkButtonPeer.java	8 Oct 2004 17:44:57 -0000	1.8.2.9
+++ gnu/java/awt/peer/gtk/GtkButtonPeer.java	13 Oct 2004 18:48:49 -0000
@@ -60,6 +60,7 @@
   native void gtkWidgetSetBackground (int red, int green, int blue);
   native void gtkActivate ();
   native void gtkWidgetRequestFocus ();
+  native void setNativeBounds (int x, int y, int width, int height);
 
   public GtkButtonPeer (Button b)
   {
Index: gnu/java/awt/peer/gtk/GtkComponentPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java,v
retrieving revision 1.16.2.21
diff -u -r1.16.2.21 GtkComponentPeer.java
--- gnu/java/awt/peer/gtk/GtkComponentPeer.java	7 Oct 2004 22:11:57 -0000	1.16.2.21
+++ gnu/java/awt/peer/gtk/GtkComponentPeer.java	13 Oct 2004 18:48:49 -0000
@@ -403,7 +403,7 @@
     gtkWidgetSetBackground (c.getRed(), c.getGreen(), c.getBlue());
   }
 
-  native public void setNativeBounds (int x, int y, int width, int height);
+  native void setNativeBounds (int x, int y, int width, int height);
 
   public void setBounds (int x, int y, int width, int height)
   {
Index: gnu/java/awt/peer/gtk/GtkLabelPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkLabelPeer.java,v
retrieving revision 1.3.10.3
diff -u -r1.3.10.3 GtkLabelPeer.java
--- gnu/java/awt/peer/gtk/GtkLabelPeer.java	2 Sep 2004 21:26:21 -0000	1.3.10.3
+++ gnu/java/awt/peer/gtk/GtkLabelPeer.java	13 Oct 2004 18:48:49 -0000
@@ -51,6 +51,7 @@
   native void nativeSetAlignment (float alignment);
 
   native public void setText (String text);
+  native void setNativeBounds (int x, int y, int width, int height);
 
   void create ()
   {
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c,v
retrieving revision 1.8.2.7
diff -u -r1.8.2.7 gnu_java_awt_peer_gtk_GtkButtonPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c	8 Oct 2004 17:44:58 -0000	1.8.2.7
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c	13 Oct 2004 18:48:50 -0000
@@ -275,6 +275,41 @@
   gdk_threads_leave ();
 }
 
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkButtonPeer_setNativeBounds
+  (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height)
+{
+  GtkWidget *widget;
+  void *ptr;
+
+  ptr = NSA_GET_PTR (env, obj);
+
+  gdk_threads_enter ();
+
+  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))
+    {
+      /* Set the event box's size request... */
+      gtk_widget_set_size_request (widget, width, height);
+      /* ...and the button's size request... */
+      gtk_widget_set_size_request (gtk_bin_get_child (GTK_BIN (widget)),
+                                   width, height);
+      /* ...and the label's size request. */
+      gtk_widget_set_size_request (gtk_bin_get_child (gtk_bin_get_child (GTK_BIN (widget))),
+                                                      width, height);
+      if (widget->parent != NULL)
+        gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y);
+    }
+
+  gdk_threads_leave ();
+}
+
 static gboolean
 focus_in_cb (GtkWidget *widget __attribute((unused)),
              GdkEventFocus *event __attribute((unused)),
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c,v
retrieving revision 1.15.2.24
diff -u -r1.15.2.24 gnu_java_awt_peer_gtk_GtkComponentPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c	7 Oct 2004 22:11:59 -0000	1.15.2.24
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c	13 Oct 2004 18:48:50 -0000
@@ -794,19 +794,18 @@
   width = width < 0 ? 0 : width;
   height = height < 0 ? 0 : height;
 
-  if (widget->parent != NULL)
+  if (GTK_IS_VIEWPORT (widget->parent))
+    gtk_widget_set_size_request (widget, width, height);
+  else
     {
-      if (GTK_IS_VIEWPORT (widget->parent))
-        gtk_widget_set_size_request (widget, width, height);
-      else
+      if (!(width == 0 && height == 0))
         {
-          if (!(width == 0 && height == 0))
-            {
-              gtk_widget_set_size_request (widget, width, height);
-              gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y);
-            }
+          gtk_widget_set_size_request (widget, width, height);
+          if (widget->parent != NULL)
+            gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y);
         }
     }
+
   gdk_threads_leave ();
 }
 
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c,v
retrieving revision 1.6.8.3
diff -u -r1.6.8.3 gnu_java_awt_peer_gtk_GtkLabelPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c	2 Sep 2004 21:26:26 -0000	1.6.8.3
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c	13 Oct 2004 18:48:50 -0000
@@ -144,3 +144,36 @@
 
   gdk_threads_leave ();
 }
+
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeBounds
+  (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height)
+{
+  GtkWidget *widget;
+  void *ptr;
+
+  ptr = NSA_GET_PTR (env, obj);
+
+  gdk_threads_enter ();
+
+  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))
+    {
+      /* Set the event box's size request... */
+      gtk_widget_set_size_request (widget, width, height);
+      /* ...and the label's size request. */
+      gtk_widget_set_size_request (gtk_bin_get_child (GTK_BIN (widget)),
+                                   width, height);
+
+      if (widget->parent != NULL)
+        gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y);
+    }
+
+  gdk_threads_leave ();
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]