0k for 0.92. We're just replacing a stub here. Plus it works, anyway.
2006-08-03 Sven de Marothy <[EMAIL PROTECTED]>
* gnu/java/awt/peer/gtk/ComponentGraphics.java
(grab, nativeGrab): New methods.
* include/gnu_java_awt_peer_gtk_ComponentGraphics.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
(nativeGrab): New method.
* gnu/java/awt/peer/gtk/GtkComponentPeer.java
(print): Implement.
* java/awt/Component.java
(printAll): Should call peer print method.
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.19
diff -U3 -r1.19 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java 9 Jul 2006 21:56:58 -0000 1.19
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java 3 Aug 2006 07:53:19 -0000
@@ -53,6 +53,7 @@
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.image.RenderedImage;
+import gnu.classpath.Pointer;
/**
* ComponentGraphics - context for drawing directly to a component,
@@ -70,32 +71,6 @@
private static ThreadLocal hasLock = new ThreadLocal();
private static Integer ONE = Integer.valueOf(1);
- private void lock()
- {
- Integer i = (Integer) hasLock.get();
- if (i == null)
- {
- start_gdk_drawing();
- hasLock.set(ONE);
- }
- else
- hasLock.set(Integer.valueOf(i.intValue() + 1));
- }
-
- private void unlock()
- {
- Integer i = (Integer) hasLock.get();
- if (i == null)
- throw new IllegalStateException();
- if (i == ONE)
- {
- hasLock.set(null);
- end_gdk_drawing();
- }
- else
- hasLock.set(Integer.valueOf(i.intValue() - 1));
- }
-
ComponentGraphics()
{
}
@@ -127,6 +102,32 @@
*/
private native long initState(GtkComponentPeer component);
+ private void lock()
+ {
+ Integer i = (Integer) hasLock.get();
+ if (i == null)
+ {
+ start_gdk_drawing();
+ hasLock.set(ONE);
+ }
+ else
+ hasLock.set(Integer.valueOf(i.intValue() + 1));
+ }
+
+ private void unlock()
+ {
+ Integer i = (Integer) hasLock.get();
+ if (i == null)
+ throw new IllegalStateException();
+ if (i == ONE)
+ {
+ hasLock.set(null);
+ end_gdk_drawing();
+ }
+ else
+ hasLock.set(Integer.valueOf(i.intValue() - 1));
+ }
+
/**
* Destroys the component surface and calls dispose on the cairo
* graphics2d to destroy any super class resources.
@@ -162,6 +163,11 @@
*/
public static native boolean hasXRender();
+ /**
+ * This is a utility method (used by GtkComponentPeer) for grabbing the
+ * image of a component.
+ */
+ private static native Pointer nativeGrab(GtkComponentPeer component);
private native void copyAreaNative(GtkComponentPeer component, int x, int y,
int width, int height, int dx, int dy);
@@ -172,6 +178,14 @@
int cw, int ch);
/**
+ * Not really related (moveme?). Utility method used by GtkComponent.
+ */
+ public static GtkImage grab( GtkComponentPeer component )
+ {
+ return new GtkImage( nativeGrab( component ) );
+ }
+
+ /**
* Returns a Graphics2D object for a component, either an instance of this
* class (if xrender is supported), or a context which copies.
*/
Index: gnu/java/awt/peer/gtk/GtkComponentPeer.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java,v
retrieving revision 1.119
diff -U3 -r1.119 GtkComponentPeer.java
--- gnu/java/awt/peer/gtk/GtkComponentPeer.java 26 Jul 2006 19:09:50 -0000 1.119
+++ gnu/java/awt/peer/gtk/GtkComponentPeer.java 3 Aug 2006 07:59:32 -0000
@@ -371,7 +371,7 @@
public void print (Graphics g)
{
- throw new RuntimeException ();
+ g.drawImage( ComponentGraphics.grab( this ), 0, 0, null );
}
public void repaint (long tm, int x, int y, int width, int height)
Index: include/gnu_java_awt_peer_gtk_ComponentGraphics.h
===================================================================
RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_ComponentGraphics.h,v
retrieving revision 1.8
diff -U3 -r1.8 gnu_java_awt_peer_gtk_ComponentGraphics.h
--- include/gnu_java_awt_peer_gtk_ComponentGraphics.h 19 Jun 2006 11:51:43 -0000 1.8
+++ include/gnu_java_awt_peer_gtk_ComponentGraphics.h 3 Aug 2006 07:53:19 -0000
@@ -15,6 +15,7 @@
JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_initFromVolatile (JNIEnv *env, jobject, jlong, jint, jint);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_start_1gdk_1drawing (JNIEnv *env, jobject);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_end_1gdk_1drawing (JNIEnv *env, jobject);
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_nativeGrab(JNIEnv *env, jclass, jobject );
JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_hasXRender (JNIEnv *env, jclass);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_copyAreaNative (JNIEnv *env, jobject, jobject, jint, jint, jint, jint, jint, jint);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_drawVolatile (JNIEnv *env, jobject, jobject, jlong, jint, jint, jint, jint, jint, jint, jint, jint);
Index: java/awt/Component.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.141
diff -U3 -r1.141 Component.java
--- java/awt/Component.java 28 Jul 2006 15:52:06 -0000 1.141
+++ java/awt/Component.java 3 Aug 2006 07:53:20 -0000
@@ -2350,10 +2350,7 @@
}
/**
- * Prints this component, including all sub-components. This method is
- * provided so that printing can be done in a different manner from
- * painting. However, the implementation in this class simply calls the
- * <code>paintAll()</code> method.
+ * Prints this component, including all sub-components.
*
* @param g the graphics context of the print device
*
@@ -2361,7 +2358,9 @@
*/
public void printAll(Graphics g)
{
- paintAll(g);
+ if( peer != null )
+ peer.print( g );
+ paintAll( g );
}
/**
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
===================================================================
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c,v
retrieving revision 1.17
diff -U3 -r1.17 gnu_java_awt_peer_gtk_ComponentGraphics.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c 19 Jun 2006 11:51:43 -0000 1.17
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c 3 Aug 2006 07:53:21 -0000
@@ -276,6 +276,42 @@
gdk_threads_leave();
}
+JNIEXPORT jobject JNICALL
+Java_gnu_java_awt_peer_gtk_ComponentGraphics_nativeGrab
+(JNIEnv *env, jclass cls __attribute__((unused)), jobject peer )
+{
+ GdkPixbuf *pixbuf;
+ GdkDrawable *drawable;
+ GdkWindow *win;
+ gint w,h;
+ GtkWidget *widget = NULL;
+ void *ptr = NULL;
+
+ gdk_threads_enter();
+
+ ptr = NSA_GET_PTR (env, peer);
+ g_assert (ptr != NULL);
+
+ widget = GTK_WIDGET (ptr);
+ g_assert (widget != NULL);
+
+ cp_gtk_grab_current_drawable (widget, &drawable, &win);
+ g_assert (drawable != NULL);
+
+ gdk_drawable_get_size ( drawable, &w, &h );
+
+ pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, w, h );
+ gdk_pixbuf_get_from_drawable( pixbuf, drawable, NULL, 0, 0, 0, 0, w, h );
+ g_object_ref( pixbuf );
+ gdk_draw_pixbuf (drawable, NULL, pixbuf,
+ 0, 0, 0, 0,
+ w, h,
+ GDK_RGB_DITHER_NORMAL, 0, 0);
+ gdk_threads_leave();
+
+ return JCL_NewRawDataObject (env, pixbuf);
+}
+
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_ComponentGraphics_drawVolatile
(JNIEnv *env, jobject obj __attribute__ ((unused)), jobject peer,