diff options
author | Silenio Quarti <silenio_quarti@ca.ibm.com> | 2012-10-26 14:52:30 -0400 |
---|---|---|
committer | Silenio Quarti <silenio_quarti@ca.ibm.com> | 2012-10-26 14:52:30 -0400 |
commit | a886f16168f44eb14dce55165728859cc8ee3baa (patch) | |
tree | 77507a36826a1bbab089f5996d8b8b798895d212 | |
parent | d0069d7ed7376b10efa426e883f2b4851a6c7c22 (diff) | |
download | eclipse.platform.swt-a886f16168f44eb14dce55165728859cc8ee3baa.tar.gz eclipse.platform.swt-a886f16168f44eb14dce55165728859cc8ee3baa.tar.xz eclipse.platform.swt-a886f16168f44eb14dce55165728859cc8ee3baa.zip |
Bug 392841 - [GTK3] Need to replace expose-event signal with draw signal
15 files changed, 245 insertions, 125 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c index 52e3f9a024..192d301e2f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c @@ -4585,6 +4585,30 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1gdk_1cairo_1create) } #endif +#ifndef NO__1gdk_1cairo_1get_1clip_1rectangle +JNIEXPORT jboolean JNICALL OS_NATIVE(_1gdk_1cairo_1get_1clip_1rectangle) + (JNIEnv *env, jclass that, jintLong arg0, jobject arg1) +{ + GdkRectangle _arg1, *lparg1=NULL; + jboolean rc = 0; + OS_NATIVE_ENTER(env, that, _1gdk_1cairo_1get_1clip_1rectangle_FUNC); + if (arg1) if ((lparg1 = getGdkRectangleFields(env, arg1, &_arg1)) == NULL) goto fail; +/* + rc = (jboolean)gdk_cairo_get_clip_rectangle(arg0, lparg1); +*/ + { + OS_LOAD_FUNCTION(fp, gdk_cairo_get_clip_rectangle) + if (fp) { + rc = (jboolean)((jboolean (CALLING_CONVENTION*)(jintLong, GdkRectangle *))fp)(arg0, lparg1); + } + } +fail: + if (arg1 && lparg1) setGdkRectangleFields(env, arg1, lparg1); + OS_NATIVE_EXIT(env, that, _1gdk_1cairo_1get_1clip_1rectangle_FUNC); + return rc; +} +#endif + #ifndef NO__1gdk_1cairo_1region JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1cairo_1region) (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h index aed2858027..a9bd702f4b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h @@ -371,6 +371,7 @@ #define pango_cairo_font_map_get_default_LIB LIB_PANGOCAIRO #define pango_cairo_font_map_set_resolution_LIB LIB_PANGOCAIRO #define gdk_cairo_reset_clip_LIB LIB_GDK +#define gdk_cairo_get_clip_rectangle_LIB LIB_GDK #define gdk_cairo_set_source_pixbuf_LIB LIB_GDK #define gdk_cairo_set_source_color_LIB LIB_GDK #define gdk_cairo_set_source_window_LIB LIB_GDK diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c index 803892e9ea..dedcfe644c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c @@ -399,6 +399,7 @@ char * OS_nativeFunctionNames[] = { "_1gdk_1beep", "_1gdk_1bitmap_1create_1from_1data", "_1gdk_1cairo_1create", + "_1gdk_1cairo_1get_1clip_1rectangle", "_1gdk_1cairo_1region", "_1gdk_1cairo_1region_1create_1from_1surface", "_1gdk_1cairo_1reset_1clip", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h index 16f90585ed..e34fb5ef62 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h @@ -409,6 +409,7 @@ typedef enum { _1gdk_1beep_FUNC, _1gdk_1bitmap_1create_1from_1data_FUNC, _1gdk_1cairo_1create_FUNC, + _1gdk_1cairo_1get_1clip_1rectangle_FUNC, _1gdk_1cairo_1region_FUNC, _1gdk_1cairo_1region_1create_1from_1surface_FUNC, _1gdk_1cairo_1reset_1clip_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java index c3145adeda..ffa4029442 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java @@ -495,6 +495,7 @@ public class OS extends C { public static final byte[] drag_end = ascii("drag_end"); public static final byte[] drag_leave = ascii("drag_leave"); public static final byte[] drag_motion = ascii("drag_motion"); + public static final byte[] draw = ascii("draw"); public static final byte[] enter_notify_event = ascii("enter-notify-event"); public static final byte[] event = ascii("event"); public static final byte[] event_after = ascii("event-after"); @@ -3495,6 +3496,16 @@ public static final long /*int*/ gdk_cairo_create(long /*int*/ drawable) { } } /** @method flags=dynamic */ +public static final native boolean _gdk_cairo_get_clip_rectangle(long /*int*/ cr, GdkRectangle rect); +public static final boolean gdk_cairo_get_clip_rectangle(long /*int*/ cr, GdkRectangle rect) { + lock.lock(); + try { + return _gdk_cairo_get_clip_rectangle(cr, rect); + } finally { + lock.unlock(); + } +} +/** @method flags=dynamic */ public static final native void _gdk_cairo_region(long /*int*/ cairo, long /*int*/ region); public static final void gdk_cairo_region(long /*int*/ cairo, long /*int*/ region) { lock.lock(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java index e8c43471cc..d7e27f6ae8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java @@ -162,6 +162,15 @@ long /*int*/ gtk_commit (long /*int*/ imcontext, long /*int*/ text) { return super.gtk_commit (imcontext, text); } +long /*int*/ gtk_draw (long /*int*/ widget, long /*int*/ cairo) { + if ((state & OBSCURED) != 0) return 0; + boolean isFocus = caret != null && caret.isFocusCaret (); + if (isFocus) caret.killFocus (); + long /*int*/ result = super.gtk_draw (widget, cairo); + if (isFocus) caret.setFocus (); + return result; +} + long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ event) { if ((state & OBSCURED) != 0) return 0; boolean isFocus = caret != null && caret.isFocusCaret (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java index e23bf0a52d..6ffa359a07 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java @@ -725,57 +725,31 @@ long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ eventPtr) { if ((style & SWT.NO_MERGE_PAINTS) == 0) { return super.gtk_expose_event (widget, eventPtr); } - if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; + if (!hooksPaint ()) return 0; GdkEventExpose gdkEvent = new GdkEventExpose (); OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof); long /*int*/ [] rectangles = new long /*int*/ [1]; int [] n_rectangles = new int [1]; - if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) { - int num = Cairo.cairo_region_num_rectangles (gdkEvent.region); - for (int n = 0; n < num; n++) { - Cairo.cairo_region_get_rectangle (gdkEvent.region, n, rectangles[n]); - } - cairo_rectangle_int_t rect = new cairo_rectangle_int_t (); - for (int i=0; i<n_rectangles[0]; i++) { - Event event = new Event (); - Cairo.memmove (rect, rectangles [0] + i * cairo_rectangle_int_t.sizeof, cairo_rectangle_int_t.sizeof); - event.x = rect.x; - event.y = rect.y; - event.width = rect.width; - event.height = rect.height; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; - long /*int*/ damageRgn = Cairo.cairo_region_create (); - Cairo.cairo_region_union_rectangle (damageRgn, rect); - GCData data = new GCData (); - data.damageRgn = damageRgn; - GC gc = event.gc = GC.gtk_new (this, data); - sendEvent (SWT.Paint, event); - gc.dispose (); - Cairo.cairo_region_destroy (damageRgn); - event.gc = null; - } - } else { - OS.gdk_region_get_rectangles (gdkEvent.region, rectangles, n_rectangles); - GdkRectangle rect = new GdkRectangle (); - for (int i=0; i<n_rectangles[0]; i++) { - Event event = new Event (); - OS.memmove (rect, rectangles [0] + i * GdkRectangle.sizeof, GdkRectangle.sizeof); - event.x = rect.x; - event.y = rect.y; - event.width = rect.width; - event.height = rect.height; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; - long /*int*/ damageRgn = OS.gdk_region_new (); - OS.gdk_region_union_with_rect (damageRgn, rect); - GCData data = new GCData (); - data.damageRgn = damageRgn; - GC gc = event.gc = GC.gtk_new (this, data); - sendEvent (SWT.Paint, event); - gc.dispose (); - OS.gdk_region_destroy (damageRgn); - event.gc = null; - } - } + OS.gdk_region_get_rectangles (gdkEvent.region, rectangles, n_rectangles); + GdkRectangle rect = new GdkRectangle (); + for (int i=0; i<n_rectangles[0]; i++) { + Event event = new Event (); + OS.memmove (rect, rectangles [0] + i * GdkRectangle.sizeof, GdkRectangle.sizeof); + event.x = rect.x; + event.y = rect.y; + event.width = rect.width; + event.height = rect.height; + if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; + long /*int*/ damageRgn = OS.gdk_region_new (); + OS.gdk_region_union_with_rect (damageRgn, rect); + GCData data = new GCData (); + data.damageRgn = damageRgn; + GC gc = event.gc = GC.gtk_new (this, data); + sendEvent (SWT.Paint, event); + gc.dispose (); + OS.gdk_region_destroy (damageRgn); + event.gc = null; + } OS.g_free (rectangles [0]); return 0; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index aa3762cd38..18815068a5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -172,6 +172,9 @@ boolean drawGripper (int x, int y, int width, int height, boolean vertical) { return true; } +void drawWidget (GC gc) { +} + void enableWidget (boolean enabled) { OS.gtk_widget_set_sensitive (handle, enabled); } @@ -315,9 +318,11 @@ void hookEvents () { long /*int*/ paintHandle = paintHandle (); int paintMask = OS.GDK_EXPOSURE_MASK | OS.GDK_VISIBILITY_NOTIFY_MASK; OS.gtk_widget_add_events (paintHandle, paintMask); - if (OS.GTK_VERSION < OS.VERSION(3, 0, 0)) { + + if (OS.GTK_VERSION < OS.VERSION (3, 0, 0)) { OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT_INVERSE], false); } + /* * As of GTK 2.17.11, obscured controls no longer send expose * events. It is no longer necessary to track visiblity notify @@ -326,9 +331,7 @@ void hookEvents () { if (OS.GTK_VERSION < OS.VERSION (2, 17, 11)) { OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [VISIBILITY_NOTIFY_EVENT], 0, display.closures [VISIBILITY_NOTIFY_EVENT], false); } - if (OS.GTK_VERSION < OS.VERSION(3, 0, 0)) { - OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT], true); - } + OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT], true); /* Connect the Input Method signals */ OS.g_signal_connect_closure_by_id (handle, display.signalIds [REALIZE], 0, display.closures [REALIZE], true); @@ -345,6 +348,10 @@ void hookEvents () { OS.g_signal_connect_closure_by_id (topHandle, display.signalIds [MAP], 0, display.closures [MAP], true); } +boolean hooksPaint () { + return hooks (SWT.Paint) || filters (SWT.Paint); +} + long /*int*/ hoverProc (long /*int*/ widget) { int [] x = new int [1], y = new int [1], mask = new int [1]; gdk_window_get_device_position (0, x, y, mask); @@ -3017,9 +3024,32 @@ long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) { return 0; } +long /*int*/ gtk_draw (long /*int*/ widget, long /*int*/ cairo) { + if ((state & OBSCURED) != 0) return 0; + if (!hooksPaint ()) return 0; + GdkRectangle rect = new GdkRectangle (); + OS.gdk_cairo_get_clip_rectangle (cairo, rect); + Event event = new Event (); + event.count = 1; + event.x = rect.x; + event.y = rect.y; + event.width = rect.width; + event.height = rect.height; + if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; + GCData data = new GCData (); +// data.damageRgn = gdkEvent.region; + data.cairo = cairo; + GC gc = event.gc = GC.gtk_new (this, data); + drawWidget (gc); + sendEvent (SWT.Paint, event); + gc.dispose (); + event.gc = null; + return 0; +} + long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ eventPtr) { if ((state & OBSCURED) != 0) return 0; - if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; + if (!hooksPaint ()) return 0; GdkEventExpose gdkEvent = new GdkEventExpose (); OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof); Event event = new Event (); @@ -3032,6 +3062,7 @@ long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ eventPtr) { GCData data = new GCData (); data.damageRgn = gdkEvent.region; GC gc = event.gc = GC.gtk_new (this, data); + drawWidget (gc); sendEvent (SWT.Paint, event); gc.dispose (); event.gc = null; @@ -3289,11 +3320,15 @@ public long /*int*/ internal_new_GC (GCData data) { checkWidget (); long /*int*/ window = paintWindow (); if (window == 0) error (SWT.ERROR_NO_HANDLES); - long /*int*/ gc; - if (OS.USE_CAIRO) { - gc = OS.gdk_cairo_create (window); + long /*int*/ gc = data.cairo; + if (gc != 0) { + Cairo.cairo_reference (gc); } else { - gc = OS.gdk_gc_new (window); + if (OS.USE_CAIRO) { + gc = OS.gdk_cairo_create (window); + } else { + gc = OS.gdk_gc_new (window); + } } if (gc == 0) error (SWT.ERROR_NO_HANDLES); if (data != null) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 89f02622a6..b617c64042 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -2437,9 +2437,7 @@ void initializeCallbacks () { signalIds [Widget.ENTER_NOTIFY_EVENT] = OS.g_signal_lookup (OS.enter_notify_event, OS.GTK_TYPE_WIDGET ()); signalIds [Widget.EVENT] = OS.g_signal_lookup (OS.event, OS.GTK_TYPE_WIDGET ()); signalIds [Widget.EVENT_AFTER] = OS.g_signal_lookup (OS.event_after, OS.GTK_TYPE_WIDGET ()); - if (OS.GTK_VERSION < OS.VERSION(3, 0, 0)) { - signalIds [Widget.EXPOSE_EVENT] = OS.g_signal_lookup (OS.expose_event, OS.GTK_TYPE_WIDGET ()); - } + signalIds [Widget.EXPOSE_EVENT] = OS.g_signal_lookup (OS.GTK_VERSION >= OS.VERSION(3, 0, 0) ? OS.draw : OS.expose_event, OS.GTK_TYPE_WIDGET ()); signalIds [Widget.FOCUS] = OS.g_signal_lookup (OS.focus, OS.GTK_TYPE_WIDGET ()); signalIds [Widget.FOCUS_IN_EVENT] = OS.g_signal_lookup (OS.focus_in_event, OS.GTK_TYPE_WIDGET ()); signalIds [Widget.FOCUS_OUT_EVENT] = OS.g_signal_lookup (OS.focus_out_event, OS.GTK_TYPE_WIDGET ()); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java index 42945186d3..916a78fab4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java @@ -164,6 +164,26 @@ void createWidget (int index) { initAccessible (); } +void drawWidget(GC gc) { + int selStart = selection.x; + int selEnd = selection.y; + if (selStart > selEnd) { + selStart = selection.y; + selEnd = selection.x; + } + // temporary code to disable text selection + selStart = selEnd = -1; + if ((state & DISABLED) != 0) gc.setForeground (disabledColor); + layout.draw (gc, 0, 0, selStart, selEnd, null, null); + if (hasFocus () && focusIndex != -1) { + Rectangle [] rects = getRectangles (focusIndex); + for (int i = 0; i < rects.length; i++) { + Rectangle rect = rects [i]; + gc.drawFocus (rect.x, rect.y, rect.width, rect.height); + } + } +} + void enableWidget (boolean enabled) { super.enableWidget (enabled); if (isDisposed ()) return; @@ -359,46 +379,6 @@ long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) { return result; } -long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ eventPtr) { - if ((state & OBSCURED) != 0) return 0; - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, eventPtr, GdkEventExpose.sizeof); - GCData data = new GCData (); - data.damageRgn = gdkEvent.region; - GC gc = GC.gtk_new (this, data); - int selStart = selection.x; - int selEnd = selection.y; - if (selStart > selEnd) { - selStart = selection.y; - selEnd = selection.x; - } - // temporary code to disable text selection - selStart = selEnd = -1; - if ((state & DISABLED) != 0) gc.setForeground (disabledColor); - layout.draw (gc, 0, 0, selStart, selEnd, null, null); - if (hasFocus () && focusIndex != -1) { - Rectangle [] rects = getRectangles (focusIndex); - for (int i = 0; i < rects.length; i++) { - Rectangle rect = rects [i]; - gc.drawFocus (rect.x, rect.y, rect.width, rect.height); - } - } - if (hooks (SWT.Paint) || filters (SWT.Paint)) { - Event event = new Event (); - event.count = gdkEvent.count; - event.x = gdkEvent.area_x; - event.y = gdkEvent.area_y; - event.width = gdkEvent.area_width; - event.height = gdkEvent.area_height; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; - event.gc = gc; - sendEvent (SWT.Paint, event); - event.gc = null; - } - gc.dispose (); - return 0; -} - long /*int*/ gtk_key_press_event (long /*int*/ widget, long /*int*/ eventPtr) { long /*int*/ result = super.gtk_key_press_event (widget, eventPtr); if (result != 0) return result; @@ -466,6 +446,10 @@ long /*int*/ gtk_motion_notify_event (long /*int*/ widget, long /*int*/ event) { return result; } +boolean hooksPaint () { + return true; +} + boolean mnemonicHit (char key) { char uckey = Character.toUpperCase (key); String parsedText = layout.getText(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index c6b59e03fd..b71470f2b2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -845,9 +845,7 @@ void hookEvents () { if (isCustomResize ()) { int mask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_RELEASE_MASK | OS.GDK_BUTTON_PRESS_MASK | OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK; OS.gtk_widget_add_events (shellHandle, mask); - if (OS.GTK_VERSION < OS.VERSION(3, 0, 0)) { - OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures[EXPOSE_EVENT], false); - } + OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures[EXPOSE_EVENT], false); OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false); OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT], false); OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java index 9b939b045c..bc9b9beea5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java @@ -1549,14 +1549,10 @@ long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) { return super.gtk_event_after (widget, gdkEvent); } -long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ event) { - if ((state & OBSCURED) != 0) return 0; - long /*int*/ result = super.gtk_expose_event (widget, event); +void drawMessage (long /*int*/ cr) { if ((style & SWT.SINGLE) != 0 && message.length () > 0) { long /*int*/ str = OS.gtk_entry_get_text (handle); if (!gtk_widget_has_focus (handle) && OS.strlen (str) == 0) { - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, event, GdkEventExpose.sizeof); long /*int*/ window = paintWindow (); int [] w = new int [1], h = new int [1]; gdk_window_get_size (window, w, h); @@ -1600,11 +1596,11 @@ long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ event) { GdkColor baseColor = new GdkColor (); OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, baseColor); if (OS.USE_CAIRO) { - long /*int*/ cairo = OS.gdk_cairo_create(window); + long /*int*/ cairo = cr != 0 ? cr : OS.gdk_cairo_create(window); Cairo.cairo_set_source_rgba(cairo, (textColor.red & 0xFFFF) / (float)0xFFFF, (textColor.green & 0xFFFF) / (float)0xFFFF, (textColor.blue & 0xFFFF) / (float)0xFFFF, 1); Cairo.cairo_move_to(cairo, x, y); OS.pango_cairo_show_layout(cairo, layout); - Cairo.cairo_destroy(cairo); + if (cr != cairo) Cairo.cairo_destroy(cairo); } else { long /*int*/ gc = OS.gdk_gc_new (window); OS.gdk_draw_layout_with_colors (window, gc, x, y, layout, textColor, baseColor); @@ -1613,6 +1609,19 @@ long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ event) { OS.g_object_unref (layout); } } +} + +long /*int*/ gtk_draw (long /*int*/ widget, long /*int*/ cairo) { + if ((state & OBSCURED) != 0) return 0; + long /*int*/ result = super.gtk_draw (widget, cairo); + drawMessage (cairo); + return result; +} + +long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ event) { + if ((state & OBSCURED) != 0) return 0; + long /*int*/ result = super.gtk_expose_event (widget, event); + drawMessage (0); return result; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java index fab79b306a..58959e7e63 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java @@ -493,23 +493,23 @@ long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ event) { return 0; } -long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ eventPtr) { - if ((state & OBSCURED) != 0) return 0; +void drawTooltip (long /*int*/ cr) { long /*int*/ window = gtk_widget_get_window (handle); int x = BORDER + PADDING; int y = BORDER + PADDING; if (OS.USE_CAIRO) { - long /*int*/ cairo = OS.gdk_cairo_create(window); + long /*int*/ cairo = cr != 0 ? cr : OS.gdk_cairo_create(window); if (cairo == 0) error (SWT.ERROR_NO_HANDLES); int count = borderPolygon.length / 2; - if (count == 0) return 0; - Cairo.cairo_set_line_width(cairo, 1); - Cairo.cairo_move_to(cairo, borderPolygon[0], borderPolygon[1]); - for (int i=1,j=2; i<count; i++,j+=2) { - Cairo.cairo_line_to(cairo, borderPolygon[j]+0.5, borderPolygon[j+1]+0.5); + if (count != 0) { + Cairo.cairo_set_line_width(cairo, 1); + Cairo.cairo_move_to(cairo, borderPolygon[0], borderPolygon[1]); + for (int i=1,j=2; i<count; i++,j+=2) { + Cairo.cairo_line_to(cairo, borderPolygon[j]+0.5, borderPolygon[j+1]+0.5); + } + Cairo.cairo_close_path(cairo); + Cairo.cairo_stroke(cairo); } - Cairo.cairo_close_path(cairo); - Cairo.cairo_stroke(cairo); if (spikeAbove) y += TIP_HEIGHT; if (layoutText != 0) { byte[] buffer = null; @@ -550,8 +550,8 @@ long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ eventPtr) { Cairo.cairo_move_to(cairo, x, y); OS.pango_cairo_show_layout(cairo, layoutMessage); } - Cairo.cairo_destroy(cairo); - return 0; + if (cairo != cr) Cairo.cairo_destroy(cairo); + return; } long /*int*/ gdkGC = OS.gdk_gc_new (window); OS.gdk_draw_polygon (window, gdkGC, 0, borderPolygon, borderPolygon.length / 2); @@ -593,6 +593,17 @@ long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ eventPtr) { OS.gdk_draw_layout (window, gdkGC, x, y, layoutMessage); } OS.g_object_unref (gdkGC); +} + +long /*int*/ gtk_draw (long /*int*/ widget, long /*int*/ cairo) { + if ((state & OBSCURED) != 0) return 0; + drawTooltip (cairo); + return 0; +} + +long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ eventPtr) { + if ((state & OBSCURED) != 0) return 0; + drawTooltip (0); return 0; } @@ -617,9 +628,7 @@ long /*int*/ gtk_size_allocate (long /*int*/ widget, long /*int*/ allocation) { void hookEvents () { if ((style & SWT.BALLOON) != 0) { - if (OS.GTK_VERSION < OS.VERSION(3, 0, 0)) { - OS.g_signal_connect_closure (handle, OS.expose_event, display.closures [EXPOSE_EVENT], false); - } + OS.g_signal_connect_closure_by_id (handle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT], true); OS.gtk_widget_add_events (handle, OS.GDK_BUTTON_PRESS_MASK); OS.g_signal_connect_closure (handle, OS.button_press_event, display.closures [BUTTON_PRESS_EVENT], false); } else { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java index 7f990b7608..a6010807dd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java @@ -126,6 +126,7 @@ public abstract class Widget { static final int EVENT_AFTER = 16; static final int EXPAND_COLLAPSE_CURSOR_ROW = 17; static final int EXPOSE_EVENT = 18; + static final int DRAW = EXPOSE_EVENT; static final int EXPOSE_EVENT_INVERSE = 19; static final int FOCUS = 20; static final int FOCUS_IN_EVENT = 21; @@ -783,6 +784,10 @@ long /*int*/ gtk_expand_collapse_cursor_row (long /*int*/ widget, long /*int*/ l return 0; } +long /*int*/ gtk_draw (long /*int*/ widget, long /*int*/ cairo) { + return 0; +} + long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ event) { return 0; } @@ -2046,7 +2051,13 @@ long /*int*/ windowProc (long /*int*/ handle, long /*int*/ arg0, long /*int*/ us case ENTER_NOTIFY_EVENT: return gtk_enter_notify_event (handle, arg0); case EVENT: return gtk_event (handle, arg0); case EVENT_AFTER: return gtk_event_after (handle, arg0); - case EXPOSE_EVENT: return gtk_expose_event (handle, arg0); + case EXPOSE_EVENT: { + if (OS.GTK_VERSION >= OS.VERSION(3, 0, 0)) { + return gtk_draw (handle, arg0); + } else { + return gtk_expose_event (handle, arg0); + } + } case FOCUS: return gtk_focus (handle, arg0); case FOCUS_IN_EVENT: return gtk_focus_in_event (handle, arg0); case FOCUS_OUT_EVENT: return gtk_focus_out_event (handle, arg0); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java index 7ba0b1ce28..ac58a725c2 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet1.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.swt.snippets; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.layout.*; /* * example snippet: Hello World * @@ -23,6 +26,58 @@ public class Snippet1 { public static void main (String [] args) { Display display = new Display (); Shell shell = new Shell(display); + +//// Cursor cursor = display.getSystemCursor(SWT.CURSOR_APPSTARTING); +//// ImageData s = new ImageData(32, 32, 1, new PaletteData(new RGB[]{new RGB(0, 0, 0), new RGB(255, 255, 255)})); +//// ImageData m = new ImageData(32, 32, 1, new PaletteData(new RGB[]{new RGB(0, 0, 0), new RGB(255, 255, 255)})); +//// for (int i=0; i<s.data.length; i++) { +//// s.data[i] = (byte)0xFF; +//// } +//// for (int i=0; i<s.data.length; i++) { +////// m.data[i] = (byte)0xFF; +//// } +//// +//// Cursor cursor = new Cursor(display, s, m, 10, 10); +// +//// ImageData mask = new ImageData("/home/test/git/eclipse.platform.ui/bundles/org.eclipse.ui/icons/full/pointer/bottom_mask.bmp"); +//// ImageData source = new ImageData("/home/test/git/eclipse.platform.ui/bundles/org.eclipse.ui/icons/full/pointer/bottom_source.bmp"); +//// ImageData mask = new ImageData("/home/test/git/eclipse.platform.ui/bundles/org.eclipse.ui/icons/full/pointer/offscreen_mask.bmp"); +//// ImageData source = new ImageData("/home/test/git/eclipse.platform.ui/bundles/org.eclipse.ui/icons/full/pointer/offscreen_source.bmp"); +//// ImageData mask = new ImageData("/home/test/git/eclipse.platform.ui/bundles/org.eclipse.ui/icons/full/pointer/invalid_mask.bmp"); +//// ImageData source = new ImageData("/home/test/git/eclipse.platform.ui/bundles/org.eclipse.ui/icons/full/pointer/invalid_source.bmp"); +// ImageData mask = new ImageData("/home/test/git/eclipse.platform.ui/bundles/org.eclipse.ui/icons/full/pointer/left_mask.bmp"); +// ImageData source = new ImageData("/home/test/git/eclipse.platform.ui/bundles/org.eclipse.ui/icons/full/pointer/left_source.bmp"); +// Cursor cursor = new Cursor(display, mask, source, 10, 10); +// +//// Cursor cursor = new Cursor(display, new ImageData("/home/test/icons/oil-logo-v1.0.png"), 0, 0); +// +// shell.setCursor(cursor); + +// Link link = new Link(shell, SWT.BORDER); +// link.setText("a like <a>Silenio</a> now"); +// link.setSize(300, 30); + + shell.setLayout(new GridLayout(1, false)); + +// Button b = new Button(shell, SWT.PUSH); +// b.setText("Button"); +// Text text = new Text(shell, SWT.SINGLE | SWT.BORDER); +// text.setMessage("Hello wolrd"); + + shell.setBackgroundImage(new Image(display, "/home/test/icons/oil-logo-v1.0.png")); + shell.setBackgroundMode(SWT.INHERIT_FORCE); + + Table table = new Table(shell, SWT.MULTI); + for (int i=0; i<4; i++) { + + } + table.addListener(SWT.Paint, new Listener() { + public void handleEvent(Event event) { + event.gc.drawLine(0, 0, 100, 100); + } + }); + + shell.open (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); |