# HG changeset patch
# User Frank Benoit
# Date 1200036866 -3600
# Node ID f646579f309cac84e97c53d01a0c051794ca5f9d
# Parent 8015c460f713ed72be169947653b313f03c6cbc9
Tray, Tooltip, TrayItem, Item
diff -r 8015c460f713 -r f646579f309c dwt/internal/gtk/OS.d
--- a/dwt/internal/gtk/OS.d Fri Jan 11 07:11:08 2008 +0100
+++ b/dwt/internal/gtk/OS.d Fri Jan 11 08:34:26 2008 +0100
@@ -134,6 +134,7 @@
public alias dwt.internal.c.gtk.GtkBox GtkBox;
public alias dwt.internal.c.gtk.GtkMisc GtkMisc;
public alias dwt.internal.c.gtk.GtkImage GtkImage;
+public alias dwt.internal.c.gtk.GtkPlug GtkPlug;
public alias dwt.internal.c.Xlib.XErrorEvent XErrorEvent;
public alias dwt.internal.c.Xlib.XExposeEvent XExposeEvent;
@@ -143,6 +144,7 @@
public alias dwt.internal.c.Xlib.XButtonEvent XButtonEvent;
public alias dwt.internal.c.Xlib.XWindowChanges XWindowChanges;
public alias dwt.internal.c.Xlib.XFocusChangeEvent XFocusChangeEvent;
+public alias dwt.internal.c.Xlib.XClientMessageEvent XClientMessageEvent;
public alias dwt.internal.c.Xrender.XRenderPictureAttributes XRenderPictureAttributes;
public alias dwt.internal.c.Xrender.XTransform XTransform;
@@ -771,14 +773,14 @@
mixin ForwardGtkOsCFunc!(.XDefaultScreen);
mixin ForwardGtkOsCFunc!(.XDefaultRootWindow);
mixin ForwardGtkOsCFunc!(.XFlush);
-// mixin ForwardGtkOsCFunc!(.XFree);
-// mixin ForwardGtkOsCFunc!(.XGetSelectionOwner);
-// mixin ForwardGtkOsCFunc!(.XInternAtom);
-// mixin ForwardGtkOsCFunc!(.XQueryTree);
- mixin ForwardGtkOsCFunc!(.XKeysymToKeycode);
-// mixin ForwardGtkOsCFunc!(.XListProperties);
- mixin ForwardGtkOsCFunc!(.XReconfigureWMWindow);
-// mixin ForwardGtkOsCFunc!(.XSendEvent);
+ mixin ForwardGtkOsCFunc!(.XFree);
+ mixin ForwardGtkOsCFunc!(.XGetSelectionOwner);
+ mixin ForwardGtkOsCFunc!(.XInternAtom);
+ mixin ForwardGtkOsCFunc!(.XQueryTree);
+ mixin ForwardGtkOsCFunc!(.XKeysymToKeycode);
+ mixin ForwardGtkOsCFunc!(.XListProperties);
+ mixin ForwardGtkOsCFunc!(.XReconfigureWMWindow);
+ mixin ForwardGtkOsCFunc!(.XSendEvent);
mixin ForwardGtkOsCFunc!(.XSetIOErrorHandler);
mixin ForwardGtkOsCFunc!(.XSetErrorHandler);
@@ -788,17 +790,15 @@
mixin ForwardGtkOsCFunc!(.XTestFakeKeyEvent);
mixin ForwardGtkOsCFunc!(.XTestFakeMotionEvent);
mixin ForwardGtkOsCFunc!(.XWarpPointer);
- /+
mixin ForwardGtkOsCFunc!(.gdk_x11_atom_to_xatom);
mixin ForwardGtkOsCFunc!(.gdk_x11_colormap_get_xcolormap);
- +/
mixin ForwardGtkOsCFunc!(.gdk_x11_drawable_get_xdisplay);
mixin ForwardGtkOsCFunc!(.gdk_x11_drawable_get_xid);
- //mixin ForwardGtkOsCFunc!(.gdk_x11_screen_lookup_visual);
+ mixin ForwardGtkOsCFunc!(.gdk_x11_screen_lookup_visual);
mixin ForwardGtkOsCFunc!(.gdk_x11_screen_get_window_manager_name);
mixin ForwardGtkOsCFunc!(.gdk_x11_visual_get_xvisual);
-// mixin ForwardGtkOsCFunc!(.gdk_pixmap_foreign_new);
+ mixin ForwardGtkOsCFunc!(.gdk_pixmap_foreign_new);
mixin ForwardGtkOsCFunc!(.gdk_window_lookup);
mixin ForwardGtkOsCFunc!(.gdk_window_add_filter);
mixin ForwardGtkOsCFunc!(.gdk_window_remove_filter);
@@ -1669,7 +1669,6 @@
mixin ForwardGtkOsCFunc!(.gtk_widget_add_events);
mixin ForwardGtkOsCFunc!(.gtk_widget_child_focus);
mixin ForwardGtkOsCFunc!(.gtk_widget_create_pango_layout);
- mixin ForwardGtkOsCFunc!(.gtk_widget_create_pango_layout);
mixin ForwardGtkOsCFunc!(.gtk_widget_destroy);
mixin ForwardGtkOsCFunc!(.gtk_widget_event);
mixin ForwardGtkOsCFunc!(.gtk_widget_get_accessible );
diff -r 8015c460f713 -r f646579f309c dwt/widgets/Display.d
--- a/dwt/widgets/Display.d Fri Jan 11 07:11:08 2008 +0100
+++ b/dwt/widgets/Display.d Fri Jan 11 08:34:26 2008 +0100
@@ -3662,6 +3662,7 @@
}
}
+
private static extern(C) int timerProcFunc ( void * data ) {
CallbackData* cbdata = cast( CallbackData* ) data;
return cbdata.display.timerProc( cast(int) cbdata.data );
@@ -3934,12 +3935,17 @@
return widget.windowProc (handle, arg0, arg1, arg2, user_data);
}
-private static extern(C) int /*long*/ windowTimerProcFunc (int /*long*/ handle) {
- //PORTING_TODO ??
- return 0;
-// CallbackData* cbdata = cast(CallbackData*)user_data;
-// return cbdata.display.windowTimerProc( handle, cast(int)cbdata.data );
+package int doWindowTimerAdd( CallbackData* cbdata, int delay, GtkWidget* widget ){
+ timerProcCallbackData.display = this;
+ timerProcCallbackData.data = cast(void*)widget;
+ return OS.gtk_timeout_add (delay, &windowTimerProcFunc, &timerProcCallbackData);
}
+
+private static extern(C) int /*long*/ windowTimerProcFunc (void* user_data) {
+ CallbackData* cbdata = cast(CallbackData*)user_data;
+ return cbdata.display.windowTimerProc( cast(GtkWidget*)cbdata.data );
+}
+
int /*long*/ windowTimerProc (GtkWidget* handle) {
Widget widget = getWidget (handle);
if (widget is null) return 0;
diff -r 8015c460f713 -r f646579f309c dwt/widgets/Item.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/widgets/Item.d Fri Jan 11 08:34:26 2008 +0100
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+module dwt.widgets.Item;
+
+
+import dwt.widgets.Widget;
+import dwt.SWT;
+import dwt.graphics.Image;
+
+/**
+ * This class is the abstract superclass of all non-windowed
+ * user interface objects that occur within specific controls.
+ * For example, a tree will contain tree items.
+ *
+ * - Styles:
+ * - (none)
+ * - Events:
+ * - (none)
+ *
+ */
+
+public abstract class Item : Widget {
+ char[] text;
+ Image image;
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * The item is added to the end of the items maintained by its parent.
+ *
+ * The style value is either one of the style constants defined in
+ * class SWT
which is applicable to instances of this
+ * class, or must be built by bitwise OR'ing together
+ * (that is, using the int
"|" operator) two or more
+ * of those SWT
style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ *
+ *
+ * @param parent a widget which will be the parent of the new instance (cannot be null)
+ * @param style the style of item to construct
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the parent is null
+ *
+ * @exception SWTException
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
+ *
+ *
+ * @see SWT
+ * @see Widget#getStyle
+ */
+public this (Widget parent, int style) {
+ super (parent, style);
+ text = "";
+}
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance,
+ * and the index at which to place it in the items maintained
+ * by its parent.
+ *
+ * The style value is either one of the style constants defined in
+ * class SWT
which is applicable to instances of this
+ * class, or must be built by bitwise OR'ing together
+ * (that is, using the int
"|" operator) two or more
+ * of those SWT
style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ *
+ *
+ * @param parent a widget which will be the parent of the new instance (cannot be null)
+ * @param style the style of item to construct
+ * @param index the zero-relative index at which to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the parent is null
+ * - ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)
+ *
+ * @exception SWTException
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
+ *
+ *
+ * @see SWT
+ * @see Widget#getStyle
+ */
+public this (Widget parent, int style, int index) {
+ this (parent, style);
+}
+
+protected void checkSubclass () {
+ /* Do Nothing - Subclassing is allowed */
+}
+
+/**
+ * Returns the receiver's image if it has one, or null
+ * if it does not.
+ *
+ * @return the receiver's image
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public Image getImage () {
+ checkWidget ();
+ return image;
+}
+
+char[] getNameText () {
+ return getText ();
+}
+
+/**
+ * Returns the receiver's text, which will be an empty
+ * string if it has never been set.
+ *
+ * @return the receiver's text
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public char[] getText () {
+ checkWidget();
+ return text;
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ text = null;
+ image = null;
+}
+
+/**
+ * Sets the receiver's image to the argument, which may be
+ * null indicating that no image should be displayed.
+ *
+ * @param image the image to display on the receiver (may be null)
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_INVALID_ARGUMENT - if the image has been disposed
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public void setImage (Image image) {
+ checkWidget ();
+ if (image !is null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ this.image = image;
+}
+
+/**
+ * Sets the receiver's text.
+ *
+ * @param string the new text
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the text is null
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public void setText (char[] string) {
+ checkWidget ();
+ if (string is null) error (SWT.ERROR_NULL_ARGUMENT);
+ text = string;
+}
+
+}
diff -r 8015c460f713 -r f646579f309c dwt/widgets/ToolTip.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/widgets/ToolTip.d Fri Jan 11 08:34:26 2008 +0100
@@ -0,0 +1,771 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+module dwt.widgets.ToolTip;
+
+import dwt.widgets.Widget;
+import dwt.widgets.TrayItem;
+import dwt.widgets.Shell;
+import dwt.SWT;
+//import dwt.internal.*;
+import dwt.internal.gtk.OS;
+import dwt.graphics.Point;
+import dwt.graphics.Color;
+import dwt.events.SelectionListener;
+import dwt.events.SelectionEvent;
+import dwt.widgets.TypedListener;
+import dwt.widgets.Event;
+import dwt.widgets.Display;
+
+import tango.stdc.stringz;
+
+/**
+ * Instances of this class represent popup windows that are used
+ * to inform or warn the user.
+ *
+ *
+ * - Styles:
+ * - BALLOON, ICON_ERROR, ICON_INFORMATION, ICON_WARNING
+ * - Events:
+ * - Selection
+ *
+ *
+ * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION,
+ * and ICON_WARNING may be specified.
+ *
+ * IMPORTANT: This class is intended to be subclassed only
+ * within the SWT implementation.
+ *
+ *
+ * @since 3.2
+ */
+public class ToolTip : Widget {
+ Shell parent;
+ char[] text, message;
+ TrayItem item;
+ int x, y, timerId;
+ void* layoutText, layoutMessage;
+ int [] borderPolygon;
+ bool spikeAbove, autohide;
+ CallbackData timerProcCallbackData;
+
+ static final int BORDER = 5;
+ static final int PADDING = 5;
+ static final int INSET = 4;
+ static final int TIP_HEIGHT = 20;
+ static final int IMAGE_SIZE = 16;
+ static final int DELAY = 8000;
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ *
+ * The style value is either one of the style constants defined in
+ * class SWT
which is applicable to instances of this
+ * class, or must be built by bitwise OR'ing together
+ * (that is, using the int
"|" operator) two or more
+ * of those SWT
style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ *
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the parent is null
+ *
+ * @exception SWTException
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
+ * - ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
+ *
+ *
+ * @see SWT#ICON_ERROR
+ * @see SWT#ICON_INFORMATION
+ * @see SWT#ICON_WARNING
+ * @see Widget#checkSubclass
+ * @see Widget#getStyle
+ */
+public this (Shell parent, int style) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ createWidget (0);
+}
+
+static int checkStyle (int style) {
+ int mask = SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING;
+ if ((style & mask) is 0) return style;
+ return checkBits (style, SWT.ICON_INFORMATION, SWT.ICON_WARNING, SWT.ICON_ERROR, 0, 0, 0);
+}
+
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notified when the receiver is selected by the user, by sending
+ * it one of the messages defined in the SelectionListener
+ * interface.
+ *
+ * widgetSelected
is called when the receiver is selected.
+ * widgetDefaultSelected
is not called.
+ *
+ *
+ * @param listener the listener which should be notified when the receiver is selected by the user
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the listener is null
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @see SelectionListener
+ * @see #removeSelectionListener
+ * @see SelectionEvent
+ */
+public void addSelectionListener (SelectionListener listener) {
+ checkWidget ();
+ if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Selection,typedListener);
+ addListener (SWT.DefaultSelection,typedListener);
+}
+
+void configure () {
+ auto screen = OS.gdk_screen_get_default ();
+ OS.gtk_widget_realize (handle);
+ int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, OS.GTK_WIDGET_WINDOW (handle));
+ GdkRectangle* dest = new GdkRectangle ();
+ OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest);
+ Point point = getSize (dest.width / 4);
+ int w = point.x;
+ int h = point.y;
+ point = getLocation ();
+ int x = point.x;
+ int y = point.y;
+ OS.gtk_window_resize (cast(GtkWindow*)handle, w, h + TIP_HEIGHT);
+ int[] polyline;
+ spikeAbove = dest.height >= y + h + TIP_HEIGHT;
+ if (dest.width >= x + w) {
+ if (dest.height >= y + h + TIP_HEIGHT) {
+ int t = TIP_HEIGHT;
+ polyline = [
+ 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t,
+ 16, t, 16, 0, 35, t,
+ w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t,
+ w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t,
+ 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t,
+ 0, 5+t];
+ borderPolygon = [
+ 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t,
+ 16, t, 16, 1, 35, t,
+ w-6, 0+t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t,
+ w-1, h-6+t, w-2, h-5+t, w-2, h-4+t, w-4, h-2+t, w-5, h-2+t, w-6, h-1+t,
+ 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t,
+ 0, 5+t];
+ OS.gtk_window_move (cast(GtkWindow*)handle, Math.max(0, x - 17), y);
+ } else {
+ polyline = [
+ 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0,
+ w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5,
+ w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h,
+ 35, h, 16, h+TIP_HEIGHT, 16, h,
+ 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5,
+ 0, 5];
+ borderPolygon = [
+ 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0,
+ w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5,
+ w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1,
+ 35, h-1, 17, h+TIP_HEIGHT-2, 17, h-1,
+ 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6,
+ 0, 5];
+ OS.gtk_window_move (cast(GtkWindow*)handle, Math.max(0, x - 17), y - h - TIP_HEIGHT);
+ }
+ } else {
+ if (dest.height >= y + h + TIP_HEIGHT) {
+ int t = TIP_HEIGHT;
+ polyline = [
+ 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t,
+ w-35, t, w-16, 0, w-16, t,
+ w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t,
+ w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t,
+ 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t,
+ 0, 5+t];
+ borderPolygon = [
+ 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t,
+ w-35, t, w-17, 2, w-17, t,
+ w-6, t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t,
+ w-1, h-6+t, w-2, h-5+t, w-2, h-4+t, w-4, h-2+t, w-5, h-2+t, w-6, h-1+t,
+ 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t,
+ 0, 5+t];
+ OS.gtk_window_move (cast(GtkWindow*)handle, Math.min(dest.width - w, x - w + 17), y);
+ } else {
+ polyline = [
+ 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0,
+ w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5,
+ w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h,
+ w-16, h, w-16, h+TIP_HEIGHT, w-35, h,
+ 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5,
+ 0, 5];
+ borderPolygon = [
+ 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0,
+ w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5,
+ w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1,
+ w-17, h-1, w-17, h+TIP_HEIGHT-2, w-36, h-1,
+ 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6,
+ 0, 5];
+ OS.gtk_window_move (cast(GtkWindow*)handle, Math.min(dest.width - w, x - w + 17), y - h - TIP_HEIGHT);
+ }
+ }
+ auto rgn = OS.gdk_region_polygon ( cast(GdkPoint*)polyline.ptr, polyline.length / 2, OS.GDK_EVEN_ODD_RULE);
+ OS.gtk_widget_realize (handle);
+ auto window = OS.GTK_WIDGET_WINDOW (handle);
+ OS.gdk_window_shape_combine_region (window, rgn, 0, 0);
+ OS.gdk_region_destroy (rgn);
+}
+
+void createHandle (int index) {
+ state |= HANDLE;
+ if ((style & SWT.BALLOON) !is 0) {
+ handle = OS.gtk_window_new (OS.GTK_WINDOW_POPUP);
+ Color background = display.getSystemColor (SWT.COLOR_INFO_BACKGROUND);
+ OS.gtk_widget_modify_bg (handle, OS.GTK_STATE_NORMAL, background.handle);
+ OS.gtk_widget_set_app_paintable (handle, true);
+ } else {
+ handle = cast(GtkWidget*)OS.gtk_tooltips_new ();
+ if (handle is null) SWT.error (SWT.ERROR_NO_HANDLES);
+ /*
+ * Bug in Solaris-GTK. Invoking gtk_tooltips_force_window()
+ * can cause a crash in older versions of GTK. The fix is
+ * to avoid this call if the GTK version is older than 2.2.x.
+ */
+ if (OS.GTK_VERSION >= OS.buildVERSION (2, 2, 1)) {
+ OS.gtk_tooltips_force_window (cast(GtkTooltips*)handle);
+ }
+ OS.g_object_ref (handle);
+ OS.gtk_object_sink (cast(GtkObject*)handle);
+ }
+}
+
+void createWidget (int index) {
+ super.createWidget (index);
+ text = "";
+ message = "";
+ x = y = -1;
+ autohide = true;
+}
+
+void deregister () {
+ super.deregister ();
+ if ((style & SWT.BALLOON) is 0) {
+ auto tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (cast(GtkTooltips*)handle);
+ if (tipWindow !is null) display.removeWidget (tipWindow);
+ }
+}
+
+void destroyWidget () {
+ auto topHandle = topHandle ();
+ releaseHandle ();
+ if (topHandle !is null && (state & HANDLE) !is 0) {
+ if ((style & SWT.BALLOON) !is 0) {
+ OS.gtk_widget_destroy (topHandle);
+ } else {
+ OS.g_object_unref (topHandle);
+ }
+ }
+}
+
+/**
+ * Returns true
if the receiver is automatically
+ * hidden by the platform, and false
otherwise.
+ *
+ * @return the receiver's auto hide state
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ */
+public bool getAutoHide () {
+ checkWidget ();
+ return autohide;
+}
+
+Point getLocation () {
+ int x = this.x;
+ int y = this.y;
+ if (item !is null) {
+ auto itemHandle = item.handle;
+ OS.gtk_widget_realize (itemHandle);
+ auto window = OS.GTK_WIDGET_WINDOW (itemHandle);
+ int px, py;
+ OS.gdk_window_get_origin (cast(GdkWindow*)window, &px, &py);
+ x = px + OS.GTK_WIDGET_WIDTH (itemHandle) / 2;
+ y = py + OS.GTK_WIDGET_HEIGHT (itemHandle) / 2;
+ }
+ if (x is -1 || y is -1) {
+ int px, py;
+ OS.gdk_window_get_pointer (null, &px, &py, null);
+ x = px;
+ y = py;
+ }
+ return new Point(x, y);
+}
+
+/**
+ * Returns the receiver's message, which will be an empty
+ * string if it has never been set.
+ *
+ * @return the receiver's message
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public char[] getMessage () {
+ checkWidget ();
+ return message;
+}
+
+char[] getNameText () {
+ return getText ();
+}
+
+/**
+ * Returns the receiver's parent, which must be a Shell
.
+ *
+ * @return the receiver's parent
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public Shell getParent () {
+ checkWidget ();
+ return parent;
+}
+
+Point getSize (int maxWidth) {
+ int textWidth = 0, messageWidth = 0;
+ int w, h;
+ if (layoutText !is null) {
+ OS.pango_layout_set_width (layoutText, -1);
+ OS.pango_layout_get_size (layoutText, &w, &h);
+ textWidth = OS.PANGO_PIXELS (w );
+ }
+ if (layoutMessage !is null) {
+ OS.pango_layout_set_width (layoutMessage, -1);
+ OS.pango_layout_get_size (layoutMessage, &w, &h);
+ messageWidth = OS.PANGO_PIXELS (w );
+ }
+ int messageTrim = 2 * INSET + 2 * BORDER + 2 * PADDING;
+ bool hasImage = layoutText !is null && (style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING)) !is 0;
+ int textTrim = messageTrim + (hasImage ? IMAGE_SIZE : 0);
+ int width = Math.min (maxWidth, Math.max (textWidth + textTrim, messageWidth + messageTrim));
+ int textHeight = 0, messageHeight = 0;
+ if (layoutText !is null) {
+ OS.pango_layout_set_width (layoutText, (maxWidth - textTrim) * OS.PANGO_SCALE);
+ OS.pango_layout_get_size (layoutText, &w, &h);
+ textHeight = OS.PANGO_PIXELS (h );
+ }
+ if (layoutMessage !is null) {
+ OS.pango_layout_set_width (layoutMessage, (maxWidth - messageTrim) * OS.PANGO_SCALE);
+ OS.pango_layout_get_size (layoutMessage, &w, &h);
+ messageHeight = OS.PANGO_PIXELS (h);
+ }
+ int height = 2 * BORDER + 2 * PADDING + messageHeight;
+ if (layoutText !is null) height += Math.max (IMAGE_SIZE, textHeight) + 2 * PADDING;
+ return new Point(width, height);
+}
+
+/**
+ * Returns the receiver's text, which will be an empty
+ * string if it has never been set.
+ *
+ * @return the receiver's text
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public char[] getText () {
+ checkWidget ();
+ return text;
+}
+
+/**
+ * Returns true
if the receiver is visible, and
+ * false
otherwise.
+ *
+ * If one of the receiver's ancestors is not visible or some
+ * other condition makes the receiver not visible, this method
+ * may still indicate that it is considered visible even though
+ * it may not actually be showing.
+ *
+ *
+ * @return the receiver's visibility state
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public bool getVisible () {
+ checkWidget ();
+ if ((style & SWT.BALLOON) !is 0) return OS.GTK_WIDGET_VISIBLE (handle);
+ auto tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (cast(GtkTooltips*)handle);
+ return OS.GTK_WIDGET_VISIBLE (tipWindow);
+}
+
+override int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) {
+ notifyListeners (SWT.Selection, new Event ());
+ setVisible (false);
+ return 0;
+}
+
+override int /*long*/ gtk_expose_event (GtkWidget* widget, GdkEventExpose* event) {
+ auto window = OS.GTK_WIDGET_WINDOW (handle);
+ auto gdkGC = cast(GdkGC*)OS.gdk_gc_new (window);
+ OS.gdk_draw_polygon (window, gdkGC, 0, cast(GdkPoint*)borderPolygon.ptr, borderPolygon.length / 2);
+ int x = BORDER + PADDING;
+ int y = BORDER + PADDING;
+ if (spikeAbove) y += TIP_HEIGHT;
+ if (layoutText !is null) {
+ char[] buffer = null;
+ int id = style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING);
+ switch (id) {
+ case SWT.ICON_ERROR: buffer = "gtk-dialog-error"; break;
+ case SWT.ICON_INFORMATION: buffer = "gtk-dialog-info"; break;
+ case SWT.ICON_WARNING: buffer = "gtk-dialog-warning"; break;
+ }
+ if (buffer !is null) {
+ auto style = OS.gtk_widget_get_default_style ();
+ auto pixbuf = OS.gtk_icon_set_render_icon (
+ OS.gtk_icon_factory_lookup_default (buffer.ptr),
+ style,
+ OS.GTK_TEXT_DIR_NONE,
+ OS.GTK_STATE_NORMAL,
+ OS.GTK_ICON_SIZE_MENU,
+ null,
+ null);
+ OS.gdk_draw_pixbuf (window, gdkGC, pixbuf, 0, 0, x, y, IMAGE_SIZE, IMAGE_SIZE, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
+ OS.g_object_unref (pixbuf);
+ x += IMAGE_SIZE;
+ }
+ x += INSET;
+ OS.gdk_draw_layout (window, gdkGC, x, y, layoutText);
+ int w, h;
+ OS.pango_layout_get_size (layoutText, &w, &h);
+ y += 2 * PADDING + Math.max (IMAGE_SIZE, OS.PANGO_PIXELS (h ));
+ }
+ if (layoutMessage !is null) {
+ x = BORDER + PADDING + INSET;
+ OS.gdk_draw_layout (window, gdkGC, x, y, layoutMessage);
+ }
+ OS.g_object_unref (gdkGC);
+ return 0;
+}
+
+override int /*long*/ gtk_size_allocate (GtkWidget* widget, int /*long*/ allocation) {
+ Point point = getLocation ();
+ int x = point.x;
+ int y = point.y;
+ auto screen = OS.gdk_screen_get_default ();
+ OS.gtk_widget_realize (widget);
+ int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, OS.GTK_WIDGET_WINDOW (widget));
+ GdkRectangle* dest = new GdkRectangle ();
+ OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest);
+ int w = OS.GTK_WIDGET_WIDTH (widget);
+ int h = OS.GTK_WIDGET_HEIGHT (widget);
+ if (dest.height < y + h) y -= h;
+ if (dest.width < x + w) x -= w;
+ OS.gtk_window_move (cast(GtkWindow*)widget, x, y);
+ return 0;
+}
+
+void hookEvents () {
+ if ((style & SWT.BALLOON) !is 0) {
+ OS.g_signal_connect_closure (handle, OS.expose_event.ptr, display.closures [EXPOSE_EVENT], false);
+ OS.gtk_widget_add_events (handle, OS.GDK_BUTTON_PRESS_MASK);
+ OS.g_signal_connect_closure (handle, OS.button_press_event.ptr, display.closures [BUTTON_PRESS_EVENT], false);
+ } else {
+ auto tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (cast(GtkTooltips*)handle);
+ if (tipWindow !is null) {
+ OS.g_signal_connect_closure (tipWindow, OS.size_allocate.ptr, display.closures [SIZE_ALLOCATE], false);
+ OS.gtk_widget_add_events (tipWindow, OS.GDK_BUTTON_PRESS_MASK);
+ OS.g_signal_connect_closure (tipWindow, OS.button_press_event.ptr, display.closures [BUTTON_PRESS_EVENT], false);
+ }
+ }
+}
+
+/**
+ * Returns true
if the receiver is visible and all
+ * of the receiver's ancestors are visible and false
+ * otherwise.
+ *
+ * @return the receiver's visibility state
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @see #getVisible
+ */
+public bool isVisible () {
+ checkWidget ();
+ return getVisible ();
+}
+
+void register () {
+ super.register ();
+ if ((style & SWT.BALLOON) is 0) {
+ auto tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (cast(GtkTooltips*)handle);
+ if (tipWindow !is null) display.addWidget (tipWindow, this);
+ }
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ if (layoutText !is null) OS.g_object_unref (layoutText);
+ layoutText = null;
+ if (layoutMessage !is null) OS.g_object_unref (layoutMessage);
+ layoutMessage = null;
+ if (timerId !is 0) OS.gtk_timeout_remove(timerId);
+ timerId = 0;
+ text = null;
+ message = null;
+ borderPolygon = null;
+}
+
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notified when the receiver is selected by the user.
+ *
+ * @param listener the listener which should no longer be notified
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the listener is null
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @see SelectionListener
+ * @see #addSelectionListener
+ */
+public void removeSelectionListener (SelectionListener listener) {
+ checkWidget();
+ if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable is null) return;
+ eventTable.unhook (SWT.Selection, listener);
+ eventTable.unhook (SWT.DefaultSelection, listener);
+}
+
+/**
+ * Makes the receiver hide automatically when true
,
+ * and remain visible when false
.
+ *
+ * @param autoHide the auto hide state
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @see #getVisible
+ * @see #setVisible
+ */
+public void setAutoHide (bool autohide) {
+ checkWidget ();
+ this.autohide = autohide;
+ //TODO - update when visible
+}
+
+/**
+ * Sets the location of the receiver, which must be a tooltip,
+ * to the point specified by the arguments which are relative
+ * to the display.
+ *
+ * Note that this is different from most widgets where the
+ * location of the widget is relative to the parent.
+ *
+ *
+ * @param x the new x coordinate for the receiver
+ * @param y the new y coordinate for the receiver
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public void setLocation (int x, int y) {
+ checkWidget ();
+ this.x = x;
+ this.y = y;
+ if ((style & SWT.BALLOON) !is 0) {
+ if (OS.GTK_WIDGET_VISIBLE (handle)) configure ();
+ } else {
+ auto tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (cast(GtkTooltips*)handle);
+ if (OS.GTK_WIDGET_VISIBLE (tipWindow)) {
+ OS.gtk_window_move (cast(GtkWindow*)tipWindow, x, y);
+ }
+ }
+}
+
+/**
+ * Sets the location of the receiver, which must be a tooltip,
+ * to the point specified by the argument which is relative
+ * to the display.
+ *
+ * Note that this is different from most widgets where the
+ * location of the widget is relative to the parent.
+ *
+ * Note that the platform window manager ultimately has control
+ * over the location of tooltips.
+ *
+ *
+ * @param location the new location for the receiver
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the point is null
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public void setLocation (Point location) {
+ checkWidget ();
+ if (location is null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ setLocation (location.x, location.y);
+}
+
+/**
+ * Sets the receiver's message.
+ *
+ * @param string the new message
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the text is null
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public void setMessage (char[] string) {
+ checkWidget ();
+ if (string is null) error (SWT.ERROR_NULL_ARGUMENT);
+ message = string;
+ if ((style & SWT.BALLOON) is 0) return;
+ if (layoutMessage !is null) OS.g_object_unref (layoutMessage);
+ layoutMessage = null;
+ if (message.length !is 0) {
+ layoutMessage = OS.gtk_widget_create_pango_layout (handle, toStringz( message ));
+ OS.pango_layout_set_wrap (layoutMessage, OS.PANGO_WRAP_WORD_CHAR);
+ }
+ if (OS.GTK_WIDGET_VISIBLE (handle)) configure ();
+}
+
+/**
+ * Sets the receiver's text.
+ *
+ * @param string the new text
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the text is null
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public void setText (char[] string) {
+ checkWidget ();
+ if (string is null) error (SWT.ERROR_NULL_ARGUMENT);
+ text = string;
+ if ((style & SWT.BALLOON) is 0) return;
+ if (layoutText !is null) OS.g_object_unref (layoutText);
+ layoutText = null;
+ if (text.length !is 0) {
+ layoutText = OS.gtk_widget_create_pango_layout (handle, toStringz(text));
+ auto boldAttr = OS.pango_attr_weight_new (OS.PANGO_WEIGHT_BOLD);
+ boldAttr.start_index = 0;
+ boldAttr.end_index = text.length+1;
+ auto attrList = OS.pango_attr_list_new ();
+ OS.pango_attr_list_insert (attrList, boldAttr);
+ OS.pango_layout_set_attributes (layoutText, attrList);
+ OS.pango_attr_list_unref (attrList);
+ OS.pango_layout_set_wrap (layoutText, OS.PANGO_WRAP_WORD_CHAR);
+ }
+ if (OS.GTK_WIDGET_VISIBLE (handle)) configure ();
+}
+
+/**
+ * Marks the receiver as visible if the argument is true
,
+ * and marks it invisible otherwise.
+ *
+ * If one of the receiver's ancestors is not visible or some
+ * other condition makes the receiver not visible, marking
+ * it visible may not actually cause it to be displayed.
+ *
+ *
+ * @param visible the new visibility state
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public void setVisible (bool visible) {
+ if (timerId !is 0) OS.gtk_timeout_remove(timerId);
+ timerId = 0;
+ if (visible) {
+ if ((style & SWT.BALLOON) !is 0) {
+ configure ();
+ OS.gtk_widget_show (handle);
+ } else {
+ auto vboxHandle = parent.vboxHandle;
+ char[] string = text;
+ if (text.length > 0) string ~= "\n\n";
+ string ~= message;
+ char* buffer = toStringz( string );
+ OS.gtk_tooltips_set_tip (cast(GtkTooltips*)handle, vboxHandle, buffer, null);
+ auto data = OS.gtk_tooltips_data_get (vboxHandle);
+ OS.GTK_TOOLTIPS_SET_ACTIVE (cast(GtkTooltips*)handle, data);
+ OS.gtk_tooltips_set_tip (cast(GtkTooltips*)handle, vboxHandle, buffer, null);
+ }
+ if (autohide) timerId = display.doWindowTimerAdd( &timerProcCallbackData, DELAY, handle);
+ } else {
+ if ((style & SWT.BALLOON) !is 0) {
+ OS.gtk_widget_hide (handle);
+ } else {
+ auto tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (cast(GtkTooltips*)handle);
+ OS.gtk_widget_hide (tipWindow);
+ }
+ }
+}
+
+override int /*long*/ timerProc (GtkWidget* widget) {
+ if ((style & SWT.BALLOON) !is 0) {
+ OS.gtk_widget_hide (handle);
+ } else {
+ auto tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (cast(GtkTooltips*)handle);
+ OS.gtk_widget_hide (tipWindow);
+ }
+ return 0;
+}
+
+}
diff -r 8015c460f713 -r f646579f309c dwt/widgets/Tray.d
--- a/dwt/widgets/Tray.d Fri Jan 11 07:11:08 2008 +0100
+++ b/dwt/widgets/Tray.d Fri Jan 11 08:34:26 2008 +0100
@@ -9,14 +9,12 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
module dwt.widgets.Tray;
+
import dwt.widgets.Display;
-class Tray{
- public this( Display, int );
- void dispose();
-}
-
-/++
-import dwt.*;
+import dwt.widgets.Widget;
+import dwt.widgets.TrayItem;
+import dwt.SWT;
+import dwt.dwthelper.System;
/**
* Instances of this class represent the system tray that is part
@@ -36,13 +34,14 @@
*
* @since 3.0
*/
-public class Tray extends Widget {
+public class Tray : Widget {
int itemCount;
- TrayItem [] items = new TrayItem [4];
+ TrayItem [] items;
-Tray (Display display, int style) {
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
+this (Display display, int style) {
+ items = new TrayItem [4];
+ if (display is null) display = Display.getCurrent ();
+ if (display is null) display = Display.getDefault ();
if (!display.isValidThread ()) {
error (SWT.ERROR_THREAD_INVALID_ACCESS);
}
@@ -51,7 +50,7 @@
void createItem (TrayItem item, int index) {
if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
+ if (itemCount is items.length) {
TrayItem [] newItems = new TrayItem [items.length + 4];
System.arraycopy (items, 0, newItems, 0, items.length);
items = newItems;
@@ -63,10 +62,10 @@
void destroyItem (TrayItem item) {
int index = 0;
while (index < itemCount) {
- if (items [index] == item) break;
+ if (items [index] is item) break;
index++;
}
- if (index == itemCount) return;
+ if (index is itemCount) return;
System.arraycopy (items, index + 1, items, index, --itemCount - index);
items [itemCount] = null;
}
@@ -130,11 +129,11 @@
return result;
}
-void releaseChildren (boolean destroy) {
- if (items != null) {
+void releaseChildren (bool destroy) {
+ if (items !is null) {
for (int i=0; i
+ *
+ * - Styles:
+ * - (none)
+ * - Events:
+ * - DefaultSelection, MenuDetect, Selection
+ *
+ *
+ * IMPORTANT: This class is not intended to be subclassed.
+ *
+ *
+ * @since 3.0
+ */
+public class TrayItem : Item {
+ Tray parent;
+ ToolTip toolTip;
+ char[] toolTipText;
+ GtkWidget* imageHandle;
+ GtkWidget* tooltipsHandle;
+ ImageList imageList;
+
+/**
+ * Constructs a new instance of this class given its parent
+ * (which must be a Tray
) and a style value
+ * describing its behavior and appearance. The item is added
+ * to the end of the items maintained by its parent.
+ *
+ * The style value is either one of the style constants defined in
+ * class SWT
which is applicable to instances of this
+ * class, or must be built by bitwise OR'ing together
+ * (that is, using the int
"|" operator) two or more
+ * of those SWT
style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ *
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the parent is null
+ *
+ * @exception SWTException
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
+ * - ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
+ *
+ *
+ * @see SWT
+ * @see Widget#checkSubclass
+ * @see Widget#getStyle
+ */
+public this (Tray parent, int style) {
+ super (parent, style);
+ this.parent = parent;
+ createWidget (parent.getItemCount ());
+}
+
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notified when the platform-specific context menu trigger
+ * has occurred, by sending it one of the messages defined in
+ * the MenuDetectListener
interface.
+ *
+ * @param listener the listener which should be notified
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the listener is null
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @see MenuDetectListener
+ * @see #removeMenuDetectListener
+ *
+ * @since 3.3
+ */
+public void addMenuDetectListener (MenuDetectListener listener) {
+ checkWidget ();
+ if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.MenuDetect, typedListener);
+}
+
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notified when the receiver is selected by the user, by sending
+ * it one of the messages defined in the SelectionListener
+ * interface.
+ *
+ * widgetSelected
is called when the receiver is selected
+ * widgetDefaultSelected
is called when the receiver is double-clicked
+ *
+ *
+ * @param listener the listener which should be notified when the receiver is selected by the user
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the listener is null
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @see SelectionListener
+ * @see #removeSelectionListener
+ * @see SelectionEvent
+ */
+public void addSelectionListener(SelectionListener listener) {
+ checkWidget ();
+ if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Selection, typedListener);
+ addListener (SWT.DefaultSelection, typedListener);
+}
+
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+
+void createWidget (int index) {
+ super.createWidget (index);
+ parent.createItem (this, index);
+}
+
+void createHandle (int index) {
+ state |= HANDLE;
+ handle = OS.gtk_plug_new (0);
+ if (handle is null) error (SWT.ERROR_NO_HANDLES);
+ imageHandle = OS.gtk_image_new ();
+ if (imageHandle is null) error (SWT.ERROR_NO_HANDLES);
+ OS.gtk_container_add (cast(GtkContainer*)handle, imageHandle);
+ OS.gtk_widget_show (handle);
+ OS.gtk_widget_show (imageHandle);
+ auto id = OS.gtk_plug_get_id (cast(GtkPlug*)handle);
+ int monitor = 0;
+ auto screen = OS.gdk_screen_get_default ();
+ if (screen !is null) {
+ monitor = OS.gdk_screen_get_number (screen);
+ }
+ auto trayAtom = OS.gdk_atom_intern (toStringz("_NET_SYSTEM_TRAY_S" ~ to!(char[])(monitor)), true);
+ auto xTrayAtom = OS.gdk_x11_atom_to_xatom (trayAtom);
+ auto xDisplay = OS.GDK_DISPLAY ();
+ auto trayWindow = OS.XGetSelectionOwner (xDisplay, xTrayAtom);
+ auto messageAtom = OS.gdk_atom_intern (toStringz("_NET_SYSTEM_TRAY_OPCODE"), true);
+ auto xMessageAtom = OS.gdk_x11_atom_to_xatom (messageAtom);
+ XClientMessageEvent* event = cast(XClientMessageEvent*)OS.g_malloc (XClientMessageEvent.sizeof);;
+ event.type = OS.ClientMessage;
+ event.window = trayWindow;
+ event.message_type = xMessageAtom;
+ event.format = 32;
+ event.data.l [0] = OS.GDK_CURRENT_TIME;
+ event.data.l [1] = OS.SYSTEM_TRAY_REQUEST_DOCK;
+ event.data.l [2] = id;
+ OS.XSendEvent (xDisplay, trayWindow, false, OS.NoEventMask, cast(XEvent*) event);
+ OS.g_free (event);
+}
+
+void deregister () {
+ super.deregister ();
+ display.removeWidget (imageHandle);
+}
+
+void destroyWidget () {
+ parent.destroyItem (this);
+ releaseHandle ();
+}
+
+/**
+ * Returns the receiver's parent, which must be a Tray
.
+ *
+ * @return the receiver's parent
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @since 3.2
+ */
+public Tray getParent () {
+ checkWidget ();
+ return parent;
+}
+
+/**
+ * Returns the receiver's tool tip, or null if it has
+ * not been set.
+ *
+ * @return the receiver's tool tip text
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @since 3.2
+ */
+public ToolTip getToolTip () {
+ checkWidget ();
+ return toolTip;
+}
+
+/**
+ * Returns the receiver's tool tip text, or null if it has
+ * not been set.
+ *
+ * @return the receiver's tool tip text
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public char[] getToolTipText () {
+ checkWidget ();
+ return toolTipText;
+}
+
+override int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) {
+ if (event.type is OS.GDK_3BUTTON_PRESS) return 0;
+ if (event.button is 3 && event.type is OS.GDK_BUTTON_PRESS) {
+ sendEvent (SWT.MenuDetect);
+ return 0;
+ }
+ if (event.type is OS.GDK_2BUTTON_PRESS) {
+ postEvent (SWT.DefaultSelection);
+ } else {
+ postEvent (SWT.Selection);
+ }
+ return 0;
+}
+
+override int /*long*/ gtk_size_allocate (GtkWidget* widget, int /*long*/ allocation) {
+ if (image !is null && image.mask !is null) {
+ if (OS.gdk_drawable_get_depth (image.mask) is 1) {
+ int xoffset = cast(int) Math.floor (OS.GTK_WIDGET_X (widget) + ((OS.GTK_WIDGET_WIDTH (widget) - OS.GTK_WIDGET_REQUISITION_WIDTH (widget)) * 0.5) + 0.5);
+ int yoffset = cast(int) Math.floor (OS.GTK_WIDGET_Y (widget) + ((OS.GTK_WIDGET_HEIGHT (widget) - OS.GTK_WIDGET_REQUISITION_HEIGHT (widget)) * 0.5) + 0.5);
+ Rectangle b = image.getBounds();
+ auto gdkImage = OS.gdk_drawable_get_image (image.mask, 0, 0, b.width, b.height);
+ if (gdkImage is null) SWT.error(SWT.ERROR_NO_HANDLES);
+ byte[] maskData = (cast(byte*)gdkImage.mem)[ 0 .. gdkImage.bpl * gdkImage.height].dup;
+ Region region = new Region (display);
+ for (int y = 0; y < b.height; y++) {
+ for (int x = 0; x < b.width; x++) {
+ int index = (y * gdkImage.bpl) + (x >> 3);
+ int theByte = maskData [index] & 0xFF;
+ int mask = 1 << (x & 0x7);
+ if ((theByte & mask) !is 0) {
+ region.add (xoffset + x, yoffset + y, 1, 1);
+ }
+ }
+ }
+ OS.g_object_unref (gdkImage);
+ OS.gtk_widget_realize (handle);
+ auto window = OS.GTK_WIDGET_WINDOW (handle);
+ OS.gdk_window_shape_combine_region (window, region.handle, 0, 0);
+ region.dispose ();
+ }
+ }
+ return 0;
+}
+
+void hookEvents () {
+ int eventMask = OS.GDK_BUTTON_PRESS_MASK;
+ OS.gtk_widget_add_events (handle, eventMask);
+ OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false);
+ OS.g_signal_connect_closure_by_id (imageHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false);
+ }
+
+/**
+ * Returns true
if the receiver is visible and
+ * false
otherwise.
+ *
+ * @return the receiver's visibility
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public bool getVisible () {
+ checkWidget ();
+ return OS.GTK_WIDGET_VISIBLE (handle);
+}
+
+void register () {
+ super.register ();
+ display.addWidget (imageHandle, this);
+}
+
+void releaseHandle () {
+ if (handle !is null) OS.gtk_widget_destroy (handle);
+ handle = imageHandle = null;
+ super.releaseHandle ();
+ parent = null;
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ if (tooltipsHandle !is null) OS.g_object_unref (tooltipsHandle);
+ tooltipsHandle = null;
+ if (imageList !is null) imageList.dispose ();
+ imageList = null;
+ toolTipText = null;
+}
+
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notified when the platform-specific context menu trigger has
+ * occurred.
+ *
+ * @param listener the listener which should no longer be notified
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the listener is null
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @see MenuDetectListener
+ * @see #addMenuDetectListener
+ *
+ * @since 3.3
+ */
+public void removeMenuDetectListener (MenuDetectListener listener) {
+ checkWidget ();
+ if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable is null) return;
+ eventTable.unhook (SWT.MenuDetect, listener);
+}
+
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notified when the receiver is selected by the user.
+ *
+ * @param listener the listener which should no longer be notified
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_NULL_ARGUMENT - if the listener is null
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @see SelectionListener
+ * @see #addSelectionListener
+ */
+public void removeSelectionListener (SelectionListener listener) {
+ checkWidget ();
+ if (listener is null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable is null) return;
+ eventTable.unhook (SWT.Selection, listener);
+ eventTable.unhook (SWT.DefaultSelection, listener);
+}
+
+/**
+ * Sets the receiver's image.
+ *
+ * @param image the new image
+ *
+ * @exception IllegalArgumentException
+ * - ERROR_INVALID_ARGUMENT - if the image has been disposed
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public void setImage (Image image) {
+ checkWidget ();
+ if (image !is null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
+ this.image = image;
+ if (image !is null) {
+ Rectangle rect = image.getBounds ();
+ OS.gtk_widget_set_size_request (handle, rect.width, rect.height);
+ if (imageList is null) imageList = new ImageList ();
+ int imageIndex = imageList.indexOf (image);
+ if (imageIndex is -1) {
+ imageIndex = imageList.add (image);
+ } else {
+ imageList.put (imageIndex, image);
+ }
+ auto pixbuf = imageList.getPixbuf (imageIndex);
+ OS.gtk_image_set_from_pixbuf (cast(GtkImage*)imageHandle, pixbuf);
+ OS.gtk_widget_show (imageHandle);
+ } else {
+ OS.gtk_widget_set_size_request (handle, 1, 1);
+ OS.gtk_image_set_from_pixbuf (cast(GtkImage*)imageHandle, null);
+ OS.gtk_widget_hide (imageHandle);
+ }
+}
+
+/**
+ * Sets the receiver's tool tip to the argument, which
+ * may be null indicating that no tool tip should be shown.
+ *
+ * @param toolTip the new tool tip (or null)
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ *
+ * @since 3.2
+ */
+public void setToolTip (ToolTip toolTip) {
+ checkWidget ();
+ ToolTip oldTip = this.toolTip, newTip = toolTip;
+ if (oldTip !is null) oldTip.item = null;
+ this.toolTip = newTip;
+ if (newTip !is null) newTip.item = this;
+}
+
+/**
+ * Sets the receiver's tool tip text to the argument, which
+ * may be null indicating that no tool tip text should be shown.
+ *
+ * @param value the new tool tip text (or null)
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public void setToolTipText (char[] string) {
+ checkWidget ();
+ toolTipText = string;
+ char* buffer = null;
+ if (string !is null && string.length > 0) {
+ buffer = toStringz( string );
+ }
+ if (tooltipsHandle is null) {
+ tooltipsHandle = cast(GtkWidget*)OS.gtk_tooltips_new ();
+ if (tooltipsHandle is null) error (SWT.ERROR_NO_HANDLES);
+ OS.g_object_ref (cast(GObject*)tooltipsHandle);
+ OS.gtk_object_sink (cast(GtkObject*)tooltipsHandle);
+ }
+ OS.gtk_tooltips_set_tip (cast(GtkTooltips*)tooltipsHandle, handle, buffer, null);
+}
+
+/**
+ * Makes the receiver visible if the argument is true
,
+ * and makes it invisible otherwise.
+ *
+ * @param visible the new visibility state
+ *
+ * @exception SWTException
+ * - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
+ *
+ */
+public void setVisible (bool visible) {
+ checkWidget ();
+ if (OS.GTK_WIDGET_VISIBLE (handle) is visible) return;
+ if (visible) {
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the show
+ * event. If this happens, just return.
+ */
+ sendEvent (SWT.Show);
+ if (isDisposed ()) return;
+ OS.gtk_widget_show (handle);
+ } else {
+ OS.gtk_widget_hide (handle);
+ sendEvent (SWT.Hide);
+ }
+}
+}