GtkTextAreaPeer.java, [...] (native create): Add width and height parameters.
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. From-SVN: r75817
This commit is contained in:
parent
db19e39b82
commit
9e2c04c59a
3 changed files with 162 additions and 49 deletions
|
@ -1,3 +1,22 @@
|
|||
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.
|
||||
|
||||
2004-01-13 Thomas Fitzsimmons <fitzsim@redhat.com>
|
||||
|
||||
* gnu/java/awt/peer/gtk/GtkComponentPeer.java
|
||||
|
|
|
@ -40,22 +40,45 @@ 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 ();
|
||||
|
||||
native void gtkTextGetSize (int dims[]);
|
||||
// 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 ());
|
||||
}
|
||||
|
||||
public GtkTextAreaPeer (TextArea 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 ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ exception statement from your version. */
|
|||
#define TEXT_FROM_SW(obj) (GTK_TEXT_VIEW(GTK_SCROLLED_WINDOW (obj)->container.child))
|
||||
JNIEXPORT void JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_create
|
||||
(JNIEnv *env, jobject obj, jint scroll)
|
||||
(JNIEnv *env, jobject obj,
|
||||
jint textview_width, jint textview_height, jint scroll)
|
||||
{
|
||||
GtkWidget *text, *sw;
|
||||
|
||||
|
@ -50,8 +51,9 @@ Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_create
|
|||
NSA_SET_GLOBAL_REF (env, obj);
|
||||
|
||||
gdk_threads_enter ();
|
||||
|
||||
|
||||
text = gtk_text_view_new ();
|
||||
gtk_widget_set_size_request (text, textview_width, textview_height);
|
||||
gtk_widget_show (text);
|
||||
|
||||
sw = gtk_scrolled_window_new (NULL, NULL);
|
||||
|
@ -77,34 +79,6 @@ Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_create
|
|||
NSA_SET_PTR (env, obj, sw);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkTextGetSize
|
||||
(JNIEnv *env, jobject obj, jintArray jdims)
|
||||
{
|
||||
void *ptr;
|
||||
jint *dims;
|
||||
GtkWidget *text;
|
||||
GtkRequisition requisition;
|
||||
|
||||
ptr = NSA_GET_PTR (env, obj);
|
||||
|
||||
dims = (*env)->GetIntArrayElements (env, jdims, 0);
|
||||
dims[0] = dims[1] = 0;
|
||||
|
||||
gdk_threads_enter ();
|
||||
|
||||
text = GTK_WIDGET (TEXT_FROM_SW (ptr));
|
||||
|
||||
gtk_widget_size_request(GTK_WIDGET (text), &requisition);
|
||||
dims[0] = requisition.width;
|
||||
dims[1] = requisition.height;
|
||||
|
||||
gdk_threads_leave ();
|
||||
|
||||
(*env)->ReleaseIntArrayElements (env, jdims, dims, 0);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_insert
|
||||
(JNIEnv *env, jobject obj, jstring contents, jint position)
|
||||
|
@ -198,3 +172,51 @@ Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkSetFont
|
|||
|
||||
(*env)->ReleaseStringUTFChars (env, name, font_name);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getHScrollbarHeight
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
void *ptr;
|
||||
GtkScrolledWindow *sw;
|
||||
GtkRequisition requisition;
|
||||
jint height = 0;
|
||||
jint spacing = 0;
|
||||
|
||||
ptr = NSA_GET_PTR (env, obj);
|
||||
|
||||
gdk_threads_enter ();
|
||||
sw = GTK_SCROLLED_WINDOW (ptr);
|
||||
|
||||
gtk_widget_size_request (sw->hscrollbar, &requisition);
|
||||
gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL);
|
||||
height = requisition.height + spacing;
|
||||
|
||||
gdk_threads_leave ();
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getVScrollbarWidth
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
void *ptr;
|
||||
GtkScrolledWindow *sw;
|
||||
GtkRequisition requisition;
|
||||
jint width = 0;
|
||||
jint spacing = 0;
|
||||
|
||||
ptr = NSA_GET_PTR (env, obj);
|
||||
|
||||
gdk_threads_enter ();
|
||||
sw = GTK_SCROLLED_WINDOW (ptr);
|
||||
|
||||
gtk_widget_size_request (sw->vscrollbar, &requisition);
|
||||
gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL);
|
||||
width = requisition.width + spacing;
|
||||
|
||||
gdk_threads_leave ();
|
||||
|
||||
return width;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue