aboutsummaryrefslogtreecommitdiff
path: root/libjava/gnu/java
diff options
context:
space:
mode:
authorThomas Fitzsimmons <fitzsim@redhat.com>2004-01-13 20:58:33 +0000
committerThomas Fitzsimmons <fitzsim@redhat.com>2004-01-13 20:58:33 +0000
commitd02f31d46f01bd70fd9e2c38611e532ad5415a0c (patch)
treeb7d513f8624f5a1b1705ce57bce0883838a7052c /libjava/gnu/java
parent4064f5efd21694bc703f31435340d34389d80674 (diff)
2004-01-13 Thomas Fitzsimmons <fitzsim@redhat.com>
* gnu/java/awt/peer/gtk/GtkTextAreaPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c (native create): Add width and height parameters. Set text view's size request according to new parameters. (create): Calculate text view size based on current font's metrics and number of rows and columns. Set TextArea's font if not already set. Call native create. (getMinimumSize): Call minimumSize. (getPreferredSize): Call preferredSize. (getHScrollbarHeight): New method. (getVScrollbarWidth): New method. (minimumSize): Calculate minimum size based on scrollbar visibility, scrollbar sizes, font metrics and number of rows and columns. (preferredSize): Likewise for preferred size. (gtkTextGetSize): Remove method. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@75817 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/gnu/java')
-rw-r--r--libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java110
1 files changed, 91 insertions, 19 deletions
diff --git a/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
index c38207c90cb..e31a481537f 100644
--- a/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
+++ b/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
@@ -40,23 +40,46 @@ package gnu.java.awt.peer.gtk;
import java.awt.Dimension;
import java.awt.Font;
+import java.awt.FontMetrics;
import java.awt.TextArea;
import java.awt.peer.TextAreaPeer;
public class GtkTextAreaPeer extends GtkTextComponentPeer
implements TextAreaPeer
{
- native void create (int scrollbarVisibility);
+ native void create (int width, int height, int scrollbarVisibility);
- native void gtkSetFont(String name, int style, int size);
+ native void gtkSetFont (String name, int style, int size);
void create ()
{
- create (((TextArea)awtComponent).getScrollbarVisibility ());
+ Font f = awtComponent.getFont ();
+
+ // By default, Sun sets a TextArea's font when its peer is
+ // created. If f != null then the peer's font is set by
+ // GtkComponent.create.
+ if (f == null)
+ {
+ f = new Font ("Fixed", Font.PLAIN, 12);
+ awtComponent.setFont (f);
+ }
+
+ FontMetrics fm;
+ if (GtkToolkit.useGraphics2D ())
+ fm = new GdkClasspathFontPeerMetrics (f);
+ else
+ fm = new GdkFontMetrics (f);
+
+ TextArea ta = ((TextArea) awtComponent);
+ int rows = ta.getRows ();
+ int cols = ta.getColumns ();
+
+ int width = cols * fm.getMaxAdvance ();
+ int height = rows * (fm.getMaxDescent () + fm.getMaxAscent ());
+
+ create (width, height, ta.getScrollbarVisibility ());
}
- native void gtkTextGetSize (int dims[]);
-
public GtkTextAreaPeer (TextArea ta)
{
super (ta);
@@ -67,31 +90,80 @@ public class GtkTextAreaPeer extends GtkTextComponentPeer
public Dimension getMinimumSize (int rows, int cols)
{
- int dims[] = new int[2];
-
- gtkTextGetSize (dims);
-
- return (new Dimension (dims[0], dims[1]));
+ return minimumSize (rows, cols);
}
public Dimension getPreferredSize (int rows, int cols)
{
- int dims[] = new int[2];
-
- gtkTextGetSize (dims);
-
- return (new Dimension (dims[0], dims[1]));
+ return preferredSize (rows, cols);
}
- /* Deprecated */
+ native int getHScrollbarHeight ();
+ native int getVScrollbarWidth ();
+
+ // Deprecated
public Dimension minimumSize (int rows, int cols)
{
- return getMinimumSize (rows, cols);
+ TextArea ta = ((TextArea) awtComponent);
+ int hScrollbarHeight = 0;
+ int vScrollbarWidth = 0;
+ int height = 0;
+ int width = 0;
+
+ if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
+ || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY)
+ height = getHScrollbarHeight ();
+
+ if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
+ || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY)
+ width = getVScrollbarWidth ();
+
+ Font f = awtComponent.getFont ();
+ if (f == null)
+ return new Dimension (width, height);
+
+ FontMetrics fm;
+ if (GtkToolkit.useGraphics2D ())
+ fm = new GdkClasspathFontPeerMetrics (f);
+ else
+ fm = new GdkFontMetrics (f);
+
+ width += cols * fm.getMaxAdvance ();
+ height += rows * (fm.getMaxDescent () + fm.getMaxAscent ());
+
+ return new Dimension (width, height);
}
public Dimension preferredSize (int rows, int cols)
{
- return getPreferredSize (rows, cols);
+ TextArea ta = ((TextArea) awtComponent);
+ int hScrollbarHeight = 0;
+ int vScrollbarWidth = 0;
+ int height = 0;
+ int width = 0;
+
+ if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
+ || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_HORIZONTAL_ONLY)
+ height = getHScrollbarHeight ();
+
+ if (ta.getScrollbarVisibility () == TextArea.SCROLLBARS_BOTH
+ || ta.getScrollbarVisibility () == TextArea.SCROLLBARS_VERTICAL_ONLY)
+ width = getVScrollbarWidth ();
+
+ Font f = awtComponent.getFont ();
+ if (f == null)
+ return new Dimension (width, height);
+
+ FontMetrics fm;
+ if (GtkToolkit.useGraphics2D ())
+ fm = new GdkClasspathFontPeerMetrics (f);
+ else
+ fm = new GdkFontMetrics (f);
+
+ width += cols * fm.getMaxAdvance ();
+ height += rows * (fm.getMaxDescent () + fm.getMaxAscent ());
+
+ return new Dimension (width, height);
}
public void replaceText (String str, int start, int end)
@@ -106,6 +178,6 @@ public class GtkTextAreaPeer extends GtkTextComponentPeer
public void setFont (Font f)
{
- gtkSetFont(f.getName(), f.getStyle(), f.getSize());
+ gtkSetFont (f.getName (), f.getStyle (), f.getSize ());
}
}