Mercurial > projects > dwt-linux
changeset 39:8e76ddc90b31
merge
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 10 Jan 2008 07:34:05 +0100 |
parents | 6e625fa1612d (diff) 0b417301f404 (current diff) |
children | 7fb1ab011933 |
files | dwt/internal/gtk/OS.d |
diffstat | 13 files changed, 1698 insertions(+), 532 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/internal/gtk/OS.d Wed Jan 09 21:54:40 2008 -0800 +++ b/dwt/internal/gtk/OS.d Thu Jan 10 07:34:05 2008 +0100 @@ -66,6 +66,7 @@ public alias dwt.internal.c.gdk.GdkEventAny GdkEventAny; public alias dwt.internal.c.gdk.GdkEventFocus GdkEventFocus; public alias dwt.internal.c.gdk.GdkWindowAttr GdkWindowAttr; +public alias dwt.internal.c.gdk.GdkEventWindowState GdkEventWindowState; public alias dwt.internal.c.pango.PangoFontDescription PangoFontDescription; public alias dwt.internal.c.pango.PangoTabArray PangoTabArray; @@ -114,6 +115,8 @@ public alias dwt.internal.c.gtk.GtkCellRendererClass GtkCellRendererClass; public alias dwt.internal.c.gtk.GtkAllocation GtkAllocation; public alias dwt.internal.c.gtk.GtkSocket GtkSocket; +public alias dwt.internal.c.gtk.GtkAccelGroup GtkAccelGroup; +public alias dwt.internal.c.gtk.GtkTooltips GtkTooltips; public alias dwt.internal.c.Xlib.XErrorEvent XErrorEvent; public alias dwt.internal.c.Xlib.XExposeEvent XExposeEvent; @@ -122,6 +125,7 @@ public alias dwt.internal.c.Xlib.XRectangle XRectangle; 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.Xrender.XRenderPictureAttributes XRenderPictureAttributes; public alias dwt.internal.c.Xrender.XTransform XTransform; @@ -169,6 +173,7 @@ private GType GTK_TYPE_CELL_RENDERER_TOGGLE(); private bool GTK_IS_WINDOW(GtkWidget *); private bool GTK_IS_CONTAINER(GtkWidget*); +private int GTK_IS_PLUG(GtkWidget*); private GType GTK_TYPE_MENU(); private GType GTK_TYPE_WIDGET(); private GType GTK_WIDGET_FLAGS(GtkWidget*); @@ -1059,7 +1064,7 @@ mixin ForwardGtkOsCFunc!(.XSetIOErrorHandler); mixin ForwardGtkOsCFunc!(.XSetErrorHandler); - //mixin ForwardGtkOsCFunc!(.XSetInputFocus); + mixin ForwardGtkOsCFunc!(.XSetInputFocus); mixin ForwardGtkOsCFunc!(.XSynchronize); mixin ForwardGtkOsCFunc!(.XTestFakeButtonEvent); mixin ForwardGtkOsCFunc!(.XTestFakeKeyEvent); @@ -1078,7 +1083,7 @@ // mixin ForwardGtkOsCFunc!(.gdk_pixmap_foreign_new); mixin ForwardGtkOsCFunc!(.gdk_window_lookup); mixin ForwardGtkOsCFunc!(.gdk_window_add_filter); -// mixin ForwardGtkOsCFunc!(.gdk_window_remove_filter); + mixin ForwardGtkOsCFunc!(.gdk_window_remove_filter); /** X render natives and constants */ // mixin ForwardGtkOsCFunc!(XRenderPictureAttributes_sizeof); @@ -1104,7 +1109,7 @@ // mixin ForwardGtkOsCFunc!(.GTK_IS_CELL_RENDERER_TOGGLE); mixin ForwardGtkOsCFunc!(.GTK_IS_CONTAINER); // mixin ForwardGtkOsCFunc!(.GTK_IS_IMAGE_MENU_ITEM); -// mixin ForwardGtkOsCFunc!(.GTK_IS_PLUG); + mixin ForwardGtkOsCFunc!(.GTK_IS_PLUG); // mixin ForwardGtkOsCFunc!(.GTK_STOCK_CANCEL); // mixin ForwardGtkOsCFunc!(.GTK_STOCK_OK); mixin ForwardGtkOsCFunc!(.GTK_TYPE_CELL_RENDERER_TEXT); @@ -2173,12 +2178,10 @@ { return arg0.type; } static GdkWindow* GDK_EVENT_WINDOW( GdkEventAny* arg0 ) { return arg0.window; } -/+ - int X_EVENT_TYPE( XEvent* arg0 ) + static int X_EVENT_TYPE( XEvent* arg0 ) { return arg0.type; } - Window X_EVENT_WINDOW( XAnyEvent* arg0 ) - { return arg0.window; } - +/ + //Window X_EVENT_WINDOW( XAnyEvent* arg0 ) + // { return arg0.window; } //g_list_data(arg0) (arg0)->data static void* g_list_data( GList* arg0 ) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/widgets/Button.d Thu Jan 10 07:34:05 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.Button; + +import dwt.widgets.Control; + +class Button : Control { +} + +/+ +import dwt.internal.*; +import dwt.internal.gtk.*; +import dwt.*; +import dwt.graphics.*; +import dwt.events.*; + +/** + * Instances of this class represent a selectable user interface object that + * issues notification when pressed and released. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT</dd> + * <dd>UP, DOWN, LEFT, RIGHT, CENTER</dd> + * <dt><b>Events:</b></dt> + * <dd>Selection</dd> + * </dl> + * <p> + * Note: Only one of the styles ARROW, CHECK, PUSH, RADIO, and TOGGLE + * may be specified. + * </p><p> + * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified. + * </p><p> + * Note: Only one of the styles UP, DOWN, LEFT, and RIGHT may be specified + * when the ARROW style is specified. + * </p><p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the SWT implementation. + * </p> + */ +public class Button extends Control { + int /*long*/ boxHandle, labelHandle, imageHandle, arrowHandle, groupHandle; + boolean selected; + ImageList imageList; + Image image; + String text; + +/** + * Constructs a new instance of this class given its parent + * and a style value describing its behavior and appearance. + * <p> + * The style value is either one of the style constants defined in + * class <code>SWT</code> which is applicable to instances of this + * class, or must be built by <em>bitwise OR</em>'ing together + * (that is, using the <code>int</code> "|" operator) two or more + * of those <code>SWT</code> style constants. The class description + * lists the style constants that are applicable to the class. + * Style bits are also inherited from superclasses. + * </p> + * + * @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 <ul> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> + * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> + * </ul> + * + * @see SWT#ARROW + * @see SWT#CHECK + * @see SWT#PUSH + * @see SWT#RADIO + * @see SWT#TOGGLE + * @see SWT#FLAT + * @see SWT#LEFT + * @see SWT#RIGHT + * @see SWT#CENTER + * @see Widget#checkSubclass + * @see Widget#getStyle + */ +public Button (Composite parent, int style) { + super (parent, checkStyle (style)); +} + +static int checkStyle (int style) { + style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0); + if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) { + return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0); + } + if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { + return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0); + } + if ((style & SWT.ARROW) != 0) { + style |= SWT.NO_FOCUS; + return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0); + } + return style; +} + +/** + * Adds the listener to the collection of listeners who will + * be notified when the control is selected by the user, by sending + * it one of the messages defined in the <code>SelectionListener</code> + * interface. + * <p> + * <code>widgetSelected</code> is called when the control is selected by the user. + * <code>widgetDefaultSelected</code> is not called. + * </p> + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see SelectionListener + * @see #removeSelectionListener + * @see SelectionEvent + */ +public void addSelectionListener (SelectionListener listener) { + checkWidget (); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Selection,typedListener); + addListener (SWT.DefaultSelection,typedListener); +} + +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget (); + if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; + if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; + /* + * Feature in GTK, GtkCheckButton and GtkRadioButton allocate + * only the minimum size necessary for its child. This causes the child + * alignment to fail. The fix is to set the child size to the size + * of the button. + */ + forceResize (); + int [] reqWidth = null, reqHeight = null; + if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { + reqWidth = new int [1]; + reqHeight = new int [1]; + OS.gtk_widget_get_size_request (boxHandle, reqWidth, reqHeight); + OS.gtk_widget_set_size_request (boxHandle, -1, -1); + } + Point size = computeNativeSize (handle, wHint, hHint, changed); + if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { + OS.gtk_widget_set_size_request (boxHandle, reqWidth [0], reqHeight [0]); + } + if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) { + if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_CAN_DEFAULT) != 0) { + int /*long*/ [] buffer = new int /*long*/ [1]; + GtkBorder border = new GtkBorder (); + OS.gtk_widget_style_get (handle, OS.default_border, buffer, 0); + if (buffer[0] != 0) { + OS.memmove (border, buffer[0], GtkBorder.sizeof); + } else { + /* Use the GTK+ default value of 1 for each. */ + border.left = border.right = border.top = border.bottom = 1; + } + if (wHint != SWT.DEFAULT) size.x += border.left + border.right; + if (hHint != SWT.DEFAULT) size.y += border.top + border.bottom; + } + } + return size; +} + +void createHandle (int index) { + state |= HANDLE; + if ((style & SWT.PUSH) == 0) state |= THEME_BACKGROUND; + int bits = SWT.ARROW | SWT.TOGGLE | SWT.CHECK | SWT.RADIO | SWT.PUSH; + fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); + if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); + OS.gtk_fixed_set_has_window (fixedHandle, true); + switch (style & bits) { + case SWT.ARROW: + int arrow_type = OS.GTK_ARROW_UP; + if ((style & SWT.UP) != 0) arrow_type = OS.GTK_ARROW_UP; + if ((style & SWT.DOWN) != 0) arrow_type = OS.GTK_ARROW_DOWN; + if ((style & SWT.LEFT) != 0) arrow_type = OS.GTK_ARROW_LEFT; + if ((style & SWT.RIGHT) != 0) arrow_type = OS.GTK_ARROW_RIGHT; + handle = OS.gtk_button_new (); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + arrowHandle = OS.gtk_arrow_new (arrow_type, OS.GTK_SHADOW_OUT); + if (arrowHandle == 0) error (SWT.ERROR_NO_HANDLES); + break; + case SWT.TOGGLE: + handle = OS.gtk_toggle_button_new (); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + break; + case SWT.CHECK: + handle = OS.gtk_check_button_new (); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + break; + case SWT.RADIO: + /* + * Feature in GTK. In GTK, radio button must always be part of + * a radio button group. In a GTK radio group, one button is always + * selected. This means that it is not possible to have a single + * radio button that is unselected. This is necessary to allow + * applications to implement their own radio behavior or use radio + * buttons outside of radio groups. The fix is to create a hidden + * radio button for each radio button we create and add them + * to the same group. This allows the visible button to be + * unselected. + */ + groupHandle = OS.gtk_radio_button_new (0); + if (groupHandle == 0) error (SWT.ERROR_NO_HANDLES); + OS.g_object_ref (groupHandle); + OS.gtk_object_sink (groupHandle); + handle = OS.gtk_radio_button_new (OS.gtk_radio_button_get_group (groupHandle)); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + break; + case SWT.PUSH: + default: + handle = OS.gtk_button_new (); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_CAN_DEFAULT); + break; + } + if ((style & SWT.ARROW) != 0) { + OS.gtk_container_add (handle, arrowHandle); + } else { + boxHandle = OS.gtk_hbox_new (false, 4); + if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); + labelHandle = OS.gtk_label_new_with_mnemonic (null); + if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); + imageHandle = OS.gtk_image_new (); + if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); + OS.gtk_container_add (handle, boxHandle); + OS.gtk_container_add (boxHandle, imageHandle); + OS.gtk_container_add (boxHandle, labelHandle); + } + OS.gtk_container_add (fixedHandle, handle); + + if ((style & SWT.ARROW) != 0) return; + _setAlignment (style & (SWT.LEFT | SWT.CENTER | SWT.RIGHT)); +} + +void createWidget (int index) { + super.createWidget (index); + text = ""; +} + +void deregister () { + super.deregister (); + if (boxHandle != 0) display.removeWidget (boxHandle); + if (labelHandle != 0) display.removeWidget (labelHandle); + if (imageHandle != 0) display.removeWidget (imageHandle); + if (arrowHandle != 0) display.removeWidget (arrowHandle); +} + +int /*long*/ fontHandle () { + if (labelHandle != 0) return labelHandle; + return super.fontHandle (); +} + +/** + * Returns a value which describes the position of the + * text or image in the receiver. The value will be one of + * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> + * unless the receiver is an <code>ARROW</code> button, in + * which case, the alignment will indicate the direction of + * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>, + * <code>UP</code> or <code>DOWN</code>). + * + * @return the alignment + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public int getAlignment () { + checkWidget (); + if ((style & SWT.ARROW) != 0) { + if ((style & SWT.UP) != 0) return SWT.UP; + if ((style & SWT.DOWN) != 0) return SWT.DOWN; + if ((style & SWT.LEFT) != 0) return SWT.LEFT; + if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; + return SWT.UP; + } + if ((style & SWT.LEFT) != 0) return SWT.LEFT; + if ((style & SWT.CENTER) != 0) return SWT.CENTER; + if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; + return SWT.LEFT; +} + +/** + * Returns the receiver's image if it has one, or null + * if it does not. + * + * @return the receiver's image + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Image getImage () { + checkWidget (); + return image; +} + +String getNameText () { + return getText (); +} + +/** + * Returns <code>true</code> if the receiver is selected, + * and false otherwise. + * <p> + * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, + * it is selected when it is checked. When it is of type <code>TOGGLE</code>, + * it is selected when it is pushed in. If the receiver is of any other type, + * this method returns false. + * + * @return the selection state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public boolean getSelection () { + checkWidget (); + if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false; + return OS.gtk_toggle_button_get_active (handle); +} + +/** + * Returns the receiver's text, which will be an empty + * string if it has never been set or if the receiver is + * an <code>ARROW</code> button. + * + * @return the receiver's text + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public String getText () { + checkWidget(); + if ((style & SWT.ARROW) != 0) return ""; + return text; +} + +int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { + int /*long*/ result = super.gtk_button_press_event (widget, event); + if (result != 0) return result; + if ((style & SWT.RADIO) != 0) selected = getSelection (); + return result; +} + +int /*long*/ gtk_clicked (int /*long*/ widget) { + if ((style & SWT.RADIO) != 0) { + if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) { + setSelection (!selected); + } else { + selectRadio (); + } + } + postEvent (SWT.Selection); + return 0; +} + +int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { + int /*long*/ result = super.gtk_focus_in_event (widget, event); + // widget could be disposed at this point + if (handle == 0) return 0; + if ((style & SWT.PUSH) != 0 && OS.GTK_WIDGET_HAS_DEFAULT (handle)) { + Decorations menuShell = menuShell (); + menuShell.defaultButton = this; + } + return result; +} + +int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { + int /*long*/ result = super.gtk_focus_out_event (widget, event); + // widget could be disposed at this point + if (handle == 0) return 0; + if ((style & SWT.PUSH) != 0 && !OS.GTK_WIDGET_HAS_DEFAULT (handle)) { + Decorations menuShell = menuShell (); + if (menuShell.defaultButton == this) { + menuShell.defaultButton = null; + } + } + return result; +} + +int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { + int /*long*/ result = super.gtk_key_press_event (widget, event); + if (result != 0) return result; + if ((style & SWT.RADIO) != 0) selected = getSelection (); + return result; +} + +void hookEvents () { + super.hookEvents(); + OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false); + if (labelHandle != 0) { + OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); + } +} + +boolean isDescribedByLabel () { + return false; +} + +boolean mnemonicHit (char key) { + if (labelHandle == 0) return false; + boolean result = super.mnemonicHit (labelHandle, key); + if (result) setFocus (); + return result; +} + +boolean mnemonicMatch (char key) { + if (labelHandle == 0) return false; + return mnemonicMatch (labelHandle, key); +} + +void register () { + super.register (); + if (boxHandle != 0) display.addWidget (boxHandle, this); + if (labelHandle != 0) display.addWidget (labelHandle, this); + if (imageHandle != 0) display.addWidget (imageHandle, this); + if (arrowHandle != 0) display.addWidget (arrowHandle, this); +} + +void releaseHandle () { + super.releaseHandle (); + boxHandle = imageHandle = labelHandle = arrowHandle = 0; +} + +void releaseWidget () { + super.releaseWidget (); + if (groupHandle != 0) OS.g_object_unref (groupHandle); + groupHandle = 0; + if (imageList != null) imageList.dispose (); + imageList = null; + image = null; + text = null; +} + +/** + * Removes the listener from the collection of listeners who will + * be notified when the control is selected by the user. + * + * @param listener the listener which should no longer be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see SelectionListener + * @see #addSelectionListener + */ +public void removeSelectionListener (SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (SWT.Selection, listener); + eventTable.unhook (SWT.DefaultSelection,listener); +} + +void resizeHandle (int width, int height) { + super.resizeHandle (width, height); + /* + * Feature in GTK, GtkCheckButton and GtkRadioButton allocate + * only the minimum size necessary for its child. This causes the child + * alignment to fail. The fix is to set the child size to the size + * of the button. + */ + if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { + OS.gtk_widget_set_size_request (boxHandle, width, -1); + } +} + +void selectRadio () { + /* + * This code is intentionally commented. When two groups + * of radio buttons with the same parent are separated by + * another control, the correct behavior should be that + * the two groups act independently. This is consistent + * with radio tool and menu items. The commented code + * implements this behavior. + */ +// int index = 0; +// Control [] children = parent._getChildren (); +// while (index < children.length && children [index] != this) index++; +// int i = index - 1; +// while (i >= 0 && children [i].setRadioSelection (false)) --i; +// int j = index + 1; +// while (j < children.length && children [j].setRadioSelection (false)) j++; +// setSelection (true); + Control [] children = parent._getChildren (); + for (int i=0; i<children.length; i++) { + Control child = children [i]; + if (this != child) child.setRadioSelection (false); + } + setSelection (true); +} + +/** + * Controls how text, images and arrows will be displayed + * in the receiver. The argument should be one of + * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> + * unless the receiver is an <code>ARROW</code> button, in + * which case, the argument indicates the direction of + * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>, + * <code>UP</code> or <code>DOWN</code>). + * + * @param alignment the new alignment + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setAlignment (int alignment) { + checkWidget (); + _setAlignment (alignment); +} + +void _setAlignment (int alignment) { + if ((style & SWT.ARROW) != 0) { + if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return; + style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT); + style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT); + int arrow_type = OS.GTK_ARROW_UP; + boolean isRTL = (style & SWT.RIGHT_TO_LEFT) != 0; + switch (alignment) { + case SWT.UP: arrow_type = OS.GTK_ARROW_UP; break; + case SWT.DOWN: arrow_type = OS.GTK_ARROW_DOWN; break; + case SWT.LEFT: arrow_type = isRTL ? OS.GTK_ARROW_RIGHT : OS.GTK_ARROW_LEFT; break; + case SWT.RIGHT: arrow_type = isRTL ? OS.GTK_ARROW_LEFT : OS.GTK_ARROW_RIGHT; break; + } + OS.gtk_arrow_set (arrowHandle, arrow_type, OS.GTK_SHADOW_OUT); + return; + } + if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; + style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); + style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); + /* Alignment not honoured when image and text are visible */ + boolean bothVisible = OS.GTK_WIDGET_VISIBLE (labelHandle) && OS.GTK_WIDGET_VISIBLE (imageHandle); + if (bothVisible) { + if ((style & (SWT.RADIO | SWT.CHECK)) != 0) alignment = SWT.LEFT; + if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) alignment = SWT.CENTER; + } + if ((alignment & SWT.LEFT) != 0) { + if (bothVisible) { + OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 0, OS.GTK_PACK_START); + OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_START); + } + OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.5f); + OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_LEFT); + OS.gtk_misc_set_alignment (imageHandle, 0.0f, 0.5f); + return; + } + if ((alignment & SWT.CENTER) != 0) { + if (bothVisible) { + OS.gtk_box_set_child_packing (boxHandle, labelHandle, true, true, 0, OS.GTK_PACK_END); + OS.gtk_box_set_child_packing (boxHandle, imageHandle, true, true, 0, OS.GTK_PACK_START); + OS.gtk_misc_set_alignment (labelHandle, 0f, 0.5f); + OS.gtk_misc_set_alignment (imageHandle, 1f, 0.5f); + } else { + OS.gtk_misc_set_alignment (labelHandle, 0.5f, 0.5f); + OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_CENTER); + OS.gtk_misc_set_alignment (imageHandle, 0.5f, 0.5f); + } + return; + } + if ((alignment & SWT.RIGHT) != 0) { + if (bothVisible) { + OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 0, OS.GTK_PACK_END); + OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_END); + } + OS.gtk_misc_set_alignment (labelHandle, 1.0f, 0.5f); + OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_RIGHT); + OS.gtk_misc_set_alignment (imageHandle, 1.0f, 0.5f); + return; + } +} + +void setBackgroundColor (GdkColor color) { + super.setBackgroundColor (color); + setBackgroundColor(fixedHandle, color); + if (labelHandle != 0) setBackgroundColor(labelHandle, color); + if (imageHandle != 0) setBackgroundColor(imageHandle, color); +} + +void setFontDescription (int /*long*/ font) { + super.setFontDescription (font); + if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font); + if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font); +} + +boolean setRadioSelection (boolean value) { + if ((style & SWT.RADIO) == 0) return false; + if (getSelection () != value) { + setSelection (value); + postEvent (SWT.Selection); + } + return true; +} + +void setForegroundColor (GdkColor color) { + super.setForegroundColor (color); + setForegroundColor (fixedHandle, color); + if (labelHandle != 0) setForegroundColor (labelHandle, color); + if (imageHandle != 0) setForegroundColor (imageHandle, color); +} + +/** + * Sets the receiver's image to the argument, which may be + * <code>null</code> indicating that no image should be displayed. + * <p> + * Note that a Button can display an image and text simultaneously + * on Windows (starting with XP), GTK+ and OSX. On other platforms, + * a Button that has an image and text set into it will display the + * image or text that was set most recently. + * </p> + * @param image the image to display on the receiver (may be <code>null</code>) + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setImage (Image image) { + checkWidget (); + if ((style & SWT.ARROW) != 0) return; + if (imageList != null) imageList.dispose (); + imageList = null; + if (image != null) { + if (image.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); + imageList = new ImageList (); + int imageIndex = imageList.add (image); + int /*long*/ pixbuf = imageList.getPixbuf (imageIndex); + OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); + if (text.length () == 0) OS.gtk_widget_hide (labelHandle); + OS.gtk_widget_show (imageHandle); + } else { + OS.gtk_image_set_from_pixbuf (imageHandle, 0); + OS.gtk_widget_show (labelHandle); + OS.gtk_widget_hide (imageHandle); + } + this.image = image; + _setAlignment (style); +} + +void setOrientation () { + super.setOrientation (); + if ((style & SWT.RIGHT_TO_LEFT) != 0) { + if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL); + if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL); + if (arrowHandle != 0) { + switch (style & (SWT.LEFT | SWT.RIGHT)) { + case SWT.LEFT: OS.gtk_arrow_set (arrowHandle, OS.GTK_ARROW_RIGHT, OS.GTK_SHADOW_OUT); break; + case SWT.RIGHT: OS.gtk_arrow_set (arrowHandle, OS.GTK_ARROW_LEFT, OS.GTK_SHADOW_OUT); break; + } + } + } +} + +/** + * Sets the selection state of the receiver, if it is of type <code>CHECK</code>, + * <code>RADIO</code>, or <code>TOGGLE</code>. + * + * <p> + * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, + * it is selected when it is checked. When it is of type <code>TOGGLE</code>, + * it is selected when it is pushed in. + * + * @param selected the new selection state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setSelection (boolean selected) { + checkWidget(); + if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return; + OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); + OS.gtk_toggle_button_set_active (handle, selected); + if ((style & SWT.RADIO) != 0) OS.gtk_toggle_button_set_active (groupHandle, !selected); + OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); +} + +/** + * Sets the receiver's text. + * <p> + * This method sets the button label. The label may include + * the mnemonic character but must not contain line delimiters. + * </p> + * <p> + * Mnemonics are indicated by an '&' that causes the next + * character to be the mnemonic. When the user presses a + * key sequence that matches the mnemonic, a selection + * event occurs. On most platforms, the mnemonic appears + * underlined but may be emphasized in a platform specific + * manner. The mnemonic indicator character '&' can be + * escaped by doubling it in the string, causing a single + * '&' to be displayed. + * </p><p> + * Note that a Button can display an image and text simultaneously + * on Windows (starting with XP), GTK+ and OSX. On other platforms, + * a Button that has an image and text set into it will display the + * image or text that was set most recently. + * </p> + * @param string the new text + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the text is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setText (String string) { + checkWidget (); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + if ((style & SWT.ARROW) != 0) return; + text = string; + char [] chars = fixMnemonic (string); + byte [] buffer = Converter.wcsToMbcs (null, chars, true); + OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); + if (image == null) OS.gtk_widget_hide (imageHandle); + OS.gtk_widget_show (labelHandle); + _setAlignment (style); +} + +void showWidget () { + super.showWidget (); + if (boxHandle != 0) OS.gtk_widget_show (boxHandle); + if (labelHandle != 0) OS.gtk_widget_show (labelHandle); + if (arrowHandle != 0) OS.gtk_widget_show (arrowHandle); +} + +int traversalCode (int key, GdkEventKey event) { + int code = super.traversalCode (key, event); + if ((style & SWT.RADIO) != 0) code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS; + return code; +} + +} ++/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/widgets/Canvas.d Thu Jan 10 07:34:05 2008 +0100 @@ -0,0 +1,338 @@ +/******************************************************************************* + * 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.Canvas; + + +import dwt.graphics.Point; +import dwt.internal.gtk.OS; +import dwt.SWT; +import dwt.widgets.Composite; +import dwt.widgets.Caret; +import dwt.widgets.Control; +import dwt.graphics.GC; +import dwt.graphics.Rectangle; +import dwt.graphics.Font; + +/** + * Instances of this class provide a surface for drawing + * arbitrary graphics. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * <p> + * This class may be subclassed by custom control implementors + * who are building controls that are <em>not</em> constructed + * from aggregates of other controls. That is, they are either + * painted using SWT graphics calls or are handled by native + * methods. + * </p> + * + * @see Composite + */ +public class Canvas : Composite { + Caret caret; + +this () {} + +/** + * Constructs a new instance of this class given its parent + * and a style value describing its behavior and appearance. + * <p> + * The style value is either one of the style constants defined in + * class <code>SWT</code> which is applicable to instances of this + * class, or must be built by <em>bitwise OR</em>'ing together + * (that is, using the <code>int</code> "|" operator) two or more + * of those <code>SWT</code> style constants. The class description + * lists the style constants that are applicable to the class. + * Style bits are also inherited from superclasses. + * </p> + * + * @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 <ul> + * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> + * </ul> + * + * @see SWT + * @see Widget#checkSubclass + * @see Widget#getStyle + */ +public this (Composite parent, int style) { + super (parent, style); +} + +/** + * Fills the interior of the rectangle specified by the arguments, + * with the receiver's background. + * + * @param gc the gc where the rectangle is to be filled + * @param x the x coordinate of the rectangle to be filled + * @param y the y coordinate of the rectangle to be filled + * @param width the width of the rectangle to be filled + * @param height the height of the rectangle to be filled + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.2 + */ +public void drawBackground (GC gc, int x, int y, int width, int height) { + checkWidget (); + if (gc is null) error (SWT.ERROR_NULL_ARGUMENT); + if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); + super.drawBackground (gc, x, y, width, height); +} + +/** + * Returns the caret. + * <p> + * The caret for the control is automatically hidden + * and shown when the control is painted or resized, + * when focus is gained or lost and when an the control + * is scrolled. To avoid drawing on top of the caret, + * the programmer must hide and show the caret when + * drawing in the window any other time. + * </p> + * + * @return the caret + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Caret getCaret () { + checkWidget(); + return caret; +} + +Point getIMCaretPos () { + if (caret is null) return super.getIMCaretPos (); + return new Point (caret.x, caret.y); +} + +override int /*long*/ gtk_expose_event (GtkWidget* widget, GdkEventExpose* event) { + if ((state & OBSCURED) !is 0) return 0; + bool isFocus = caret !is null && caret.isFocusCaret (); + if (isFocus) caret.killFocus (); + auto result = super.gtk_expose_event (widget, event); + if (isFocus) caret.setFocus (); + return result; +} + +override int /*long*/ gtk_focus_in_event (GtkWidget* widget, GdkEventFocus* event) { + auto result = super.gtk_focus_in_event (widget, event); + if (caret !is null) caret.setFocus (); + return result; +} + +override int /*long*/ gtk_focus_out_event (GtkWidget* widget, GdkEventFocus* event) { + auto result = super.gtk_focus_out_event (widget, event); + if (caret !is null) caret.killFocus (); + return result; +} + +void redrawWidget (int x, int y, int width, int height, bool redrawAll, bool all, bool trim) { + bool isFocus = caret !is null && caret.isFocusCaret (); + if (isFocus) caret.killFocus (); + super.redrawWidget (x, y, width, height, redrawAll, all, trim); + if (isFocus) caret.setFocus (); +} + +void releaseChildren (bool destroy) { + if (caret !is null) { + caret.release (false); + caret = null; + } + super.releaseChildren (destroy); +} + +/** + * Scrolls a rectangular area of the receiver by first copying + * the source area to the destination and then causing the area + * of the source which is not covered by the destination to + * be repainted. Children that intersect the rectangle are + * optionally moved during the operation. In addition, outstanding + * paint events are flushed before the source area is copied to + * ensure that the contents of the canvas are drawn correctly. + * + * @param destX the x coordinate of the destination + * @param destY the y coordinate of the destination + * @param x the x coordinate of the source + * @param y the y coordinate of the source + * @param width the width of the area + * @param height the height of the area + * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void scroll (int destX, int destY, int x, int y, int width, int height, bool all) { + checkWidget(); + if (width <= 0 || height <= 0) return; + int deltaX = destX - x, deltaY = destY - y; + if (deltaX is 0 && deltaY is 0) return; + if (!isVisible ()) return; + bool isFocus = caret !is null && caret.isFocusCaret (); + if (isFocus) caret.killFocus (); + auto window = paintWindow (); + auto visibleRegion = OS.gdk_drawable_get_visible_region (window); + GdkRectangle* srcRect = new GdkRectangle (); + srcRect.x = x; + srcRect.y = y; + srcRect.width = width; + srcRect.height = height; + auto copyRegion = OS.gdk_region_rectangle (srcRect); + OS.gdk_region_intersect(copyRegion, visibleRegion); + auto invalidateRegion = OS.gdk_region_rectangle (srcRect); + OS.gdk_region_subtract (invalidateRegion, visibleRegion); + OS.gdk_region_offset (invalidateRegion, deltaX, deltaY); + GdkRectangle* copyRect = new GdkRectangle(); + OS.gdk_region_get_clipbox (copyRegion, copyRect); + if (copyRect.width !is 0 && copyRect.height !is 0) { + update (); + } + Control control = findBackgroundControl (); + if (control is null) control = this; + if (control.backgroundImage !is null) { + redrawWidget (x, y, width, height, false, false, false); + redrawWidget (destX, destY, width, height, false, false, false); + } else { +// GC gc = new GC (this); +// gc.copyArea (x, y, width, height, destX, destY); +// gc.dispose (); + auto gdkGC = OS.gdk_gc_new (window); + OS.gdk_gc_set_exposures (gdkGC, true); + OS.gdk_draw_drawable (window, gdkGC, window, copyRect.x, copyRect.y, copyRect.x + deltaX, copyRect.y + deltaY, copyRect.width, copyRect.height); + OS.g_object_unref (gdkGC); + bool disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY); + if (disjoint) { + GdkRectangle* rect = new GdkRectangle (); + rect.x = x; + rect.y = y; + rect.width = width; + rect.height = height; + OS.gdk_region_union_with_rect (invalidateRegion, rect); + } else { + GdkRectangle* rect = new GdkRectangle (); + if (deltaX !is 0) { + int newX = destX - deltaX; + if (deltaX < 0) newX = destX + width; + rect.x = newX; + rect.y = y; + rect.width = Math.abs(deltaX); + rect.height = height; + OS.gdk_region_union_with_rect (invalidateRegion, rect); + } + if (deltaY !is 0) { + int newY = destY - deltaY; + if (deltaY < 0) newY = destY + height; + rect.x = x; + rect.y = newY; + rect.width = width; + rect.height = Math.abs(deltaY); + OS.gdk_region_union_with_rect (invalidateRegion, rect); + } + } + OS.gdk_window_invalidate_region(window, invalidateRegion, all); + OS.gdk_region_destroy (visibleRegion); + OS.gdk_region_destroy (copyRegion); + OS.gdk_region_destroy (invalidateRegion); + } + if (all) { + Control [] children = _getChildren (); + for (int i=0; i<children.length; i++) { + Control child = children [i]; + Rectangle rect = child.getBounds (); + if (Math.min(x + width, rect.x + rect.width) >= Math.max (x, rect.x) && + Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) { + child.setLocation (rect.x + deltaX, rect.y + deltaY); + } + } + } + if (isFocus) caret.setFocus (); +} + +int setBounds (int x, int y, int width, int height, bool move, bool resize) { + bool isFocus = caret !is null && caret.isFocusCaret (); + if (isFocus) caret.killFocus (); + int result = super.setBounds (x, y, width, height, move, resize); + if (isFocus) caret.setFocus (); + return result; +} + +/** + * Sets the receiver's caret. + * <p> + * The caret for the control is automatically hidden + * and shown when the control is painted or resized, + * when focus is gained or lost and when an the control + * is scrolled. To avoid drawing on top of the caret, + * the programmer must hide and show the caret when + * drawing in the window any other time. + * </p> + * @param caret the new caret for the receiver, may be null + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setCaret (Caret caret) { + checkWidget(); + Caret newCaret = caret; + Caret oldCaret = this.caret; + this.caret = newCaret; + if (hasFocus ()) { + if (oldCaret !is null) oldCaret.killFocus (); + if (newCaret !is null) { + if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + newCaret.setFocus (); + } + } +} + +public void setFont (Font font) { + checkWidget(); + if (caret !is null) caret.setFont (font); + super.setFont (font); +} + +void updateCaret () { + auto imHandle = imHandle (); + if (imHandle is null) return; + GdkRectangle* rect = new GdkRectangle (); + rect.x = caret.x; + rect.y = caret.y; + rect.width = caret.width; + rect.height = caret.height; + OS.gtk_im_context_set_cursor_location (imHandle, rect); +} + +}
--- a/dwt/widgets/Caret.d Wed Jan 09 21:54:40 2008 -0800 +++ b/dwt/widgets/Caret.d Thu Jan 10 07:34:05 2008 +0100 @@ -9,10 +9,18 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ module dwt.widgets.Caret; - +import dwt.graphics.Font; class Caret{ int blinkRate; bool blinkCaret(); + int x, y, width, height; + + bool isFocusCaret () ; + void killFocus () ; + void setFocus (); + void release(bool); + bool isDisposed(); + public void setFont (Font font) ; } /+++
--- a/dwt/widgets/Composite.d Wed Jan 09 21:54:40 2008 -0800 +++ b/dwt/widgets/Composite.d Thu Jan 10 07:34:05 2008 +0100 @@ -705,17 +705,17 @@ return result; } -override int /*long*/ gtk_focus (GtkWidget* widget, int /*long*/ directionType) { +override int /*long*/ gtk_focus (GtkWidget* widget, int directionType) { if (widget is socketHandle) return 0; return super.gtk_focus (widget, directionType); } -override int /*long*/ gtk_focus_in_event (GtkWidget* widget, int /*long*/ event) { +override int /*long*/ gtk_focus_in_event (GtkWidget* widget, GdkEventFocus* event) { int /*long*/ result = super.gtk_focus_in_event (widget, event); return (state & CANVAS) !is 0 ? 1 : result; } -override int /*long*/ gtk_focus_out_event (GtkWidget* widget, int /*long*/ event) { +override int /*long*/ gtk_focus_out_event (GtkWidget* widget, GdkEventFocus* event) { auto result = super.gtk_focus_out_event (widget, event); return (state & CANVAS) !is 0 ? 1 : result; }
--- a/dwt/widgets/Control.d Wed Jan 09 21:54:40 2008 -0800 +++ b/dwt/widgets/Control.d Thu Jan 10 07:34:05 2008 +0100 @@ -2350,7 +2350,7 @@ return (state & HIDDEN) is 0; } -int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) { +override int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) { GdkEventButton* gdkEvent = new GdkEventButton (); memmove (gdkEvent, event, GdkEventButton.sizeof); if (gdkEvent.type is OS.GDK_3BUTTON_PRESS) return 0; @@ -2414,7 +2414,7 @@ return result; } -int /*long*/ gtk_button_release_event (GtkWidget* widget, GdkEventButton* event) { +override int /*long*/ gtk_button_release_event (GtkWidget* widget, GdkEventButton* event) { GdkEventButton* gdkEvent = new GdkEventButton (); memmove (gdkEvent, event, GdkEventButton.sizeof); /* @@ -2433,14 +2433,14 @@ return sendMouseEvent (SWT.MouseUp, button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; } -int /*long*/ gtk_commit (GtkIMContext* imcontext, char* text) { +override int /*long*/ gtk_commit (GtkIMContext* imcontext, char* text) { char [] chars = fromUtf8z( text ); if (chars.length is 0) return 0; sendIMKeyEvent (SWT.KeyDown, null, chars); return 0; } -int /*long*/ gtk_enter_notify_event (GtkWidget* widget, GdkEventCrossing* event) { +override int /*long*/ gtk_enter_notify_event (GtkWidget* widget, GdkEventCrossing* event) { if (display.currentControl is this) return 0; GdkEventCrossing* gdkEvent = new GdkEventCrossing (); memmove (gdkEvent, event, GdkEventCrossing.sizeof); @@ -2457,7 +2457,7 @@ return 0; } -int /*long*/ gtk_event_after (GtkWidget* widget, GdkEvent* gdkEvent) { +override int /*long*/ gtk_event_after (GtkWidget* widget, GdkEvent* gdkEvent) { GdkEvent* event = new GdkEvent (); memmove (event, gdkEvent, GdkEvent.sizeof); switch (cast(int)event.type) { @@ -2513,7 +2513,7 @@ return 0; } -int /*long*/ gtk_expose_event (GtkWidget* widget, GdkEventExpose* eventPtr) { +override int /*long*/ gtk_expose_event (GtkWidget* widget, GdkEventExpose* eventPtr) { if ((state & OBSCURED) !is 0) return 0; if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; GdkEventExpose* gdkEvent = new GdkEventExpose (); @@ -2534,12 +2534,12 @@ return 0; } -int /*long*/ gtk_focus (GtkWidget* widget, int /*long*/ directionType) { +override int /*long*/ gtk_focus (GtkWidget* widget, int directionType) { /* Stop GTK traversal for every widget */ return 1; } -int /*long*/ gtk_focus_in_event (GtkWidget* widget, int /*long*/ event) { +override int /*long*/ gtk_focus_in_event (GtkWidget* widget, GdkEventFocus* event) { // widget could be disposed at this point if (handle !is null) { Control oldControl = display.imControl; @@ -2557,7 +2557,7 @@ return 0; } -int /*long*/ gtk_focus_out_event (GtkWidget* widget, int /*long*/ event) { +override int /*long*/ gtk_focus_out_event (GtkWidget* widget, GdkEventFocus* event) { // widget could be disposed at this point if (handle !is null) { if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) { @@ -2570,7 +2570,7 @@ return 0; } -int /*long*/ gtk_key_press_event (GtkWidget* widget, GdkEventKey* event) { +override int /*long*/ gtk_key_press_event (GtkWidget* widget, GdkEventKey* event) { if (!hasFocus ()) return 0; GdkEventKey* gdkEvent = new GdkEventKey (); memmove (gdkEvent, event, GdkEventKey.sizeof); @@ -2589,7 +2589,7 @@ return super.gtk_key_press_event (widget, event); } -int /*long*/ gtk_key_release_event (GtkWidget* widget, GdkEventKey* event) { +override int /*long*/ gtk_key_release_event (GtkWidget* widget, GdkEventKey* event) { if (!hasFocus ()) return 0; auto imHandle = imHandle (); if (imHandle !is null) { @@ -2598,7 +2598,7 @@ return super.gtk_key_release_event (widget, event); } -int /*long*/ gtk_leave_notify_event (GtkWidget* widget, GdkEventCrossing* event) { +override int /*long*/ gtk_leave_notify_event (GtkWidget* widget, GdkEventCrossing* event) { if (display.currentControl !is this) return 0; display.removeMouseHoverTimeout (handle); int result = 0; @@ -2613,7 +2613,7 @@ return result; } -int /*long*/ gtk_mnemonic_activate (GtkWidget* widget, int /*long*/ arg1) { +override int /*long*/ gtk_mnemonic_activate (GtkWidget* widget, int /*long*/ arg1) { int result = 0; auto eventPtr = OS.gtk_get_current_event (); if (eventPtr !is null) { @@ -2634,7 +2634,7 @@ return result; } -int /*long*/ gtk_motion_notify_event (GtkWidget* widget, GdkEventMotion* event) { +override int /*long*/ gtk_motion_notify_event (GtkWidget* widget, GdkEventMotion* event) { GdkEventMotion* gdkEvent = new GdkEventMotion (); memmove (gdkEvent, event, GdkEventMotion.sizeof); if (this is display.currentControl && (hooks (SWT.MouseHover) || filters (SWT.MouseHover))) { @@ -2655,19 +2655,19 @@ return result; } -int /*long*/ gtk_popup_menu (GtkWidget* widget) { +override int /*long*/ gtk_popup_menu (GtkWidget* widget) { if (!hasFocus()) return 0; int x, y ; OS.gdk_window_get_pointer (null, &x, &y, null); return showMenu (x, y) ? 1 : 0; } -int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) { +override int /*long*/ gtk_preedit_changed (GtkIMContext* imcontext) { display.showIMWindow (this); return 0; } -int /*long*/ gtk_realize (GtkWidget* widget) { +override int /*long*/ gtk_realize (GtkWidget* widget) { auto imHandle = imHandle (); if (imHandle !is null) { auto window = OS.GTK_WIDGET_WINDOW (paintHandle ()); @@ -2680,7 +2680,7 @@ return 0; } -int /*long*/ gtk_scroll_event (GtkWidget* widget, GdkEventScroll* eventPtr) { +override int /*long*/ gtk_scroll_event (GtkWidget* widget, GdkEventScroll* eventPtr) { GdkEventScroll* gdkEvent = new GdkEventScroll (); memmove (gdkEvent, eventPtr, GdkEventScroll.sizeof); switch (cast(int)gdkEvent.direction) { @@ -2696,25 +2696,25 @@ return 0; } -int /*long*/ gtk_show_help (GtkWidget* widget, int /*long*/ helpType) { +override int /*long*/ gtk_show_help (GtkWidget* widget, int /*long*/ helpType) { if (!hasFocus ()) return 0; return sendHelpEvent (helpType) ? 1 : 0; } -int /*long*/ gtk_style_set (GtkWidget* widget, int /*long*/ previousStyle) { +override int /*long*/ gtk_style_set (GtkWidget* widget, int /*long*/ previousStyle) { if (backgroundImage !is null) { setBackgroundPixmap (backgroundImage.pixmap); } return 0; } -int /*long*/ gtk_unrealize (GtkWidget* widget) { +override int /*long*/ gtk_unrealize (GtkWidget* widget) { auto imHandle = imHandle (); if (imHandle !is null) OS.gtk_im_context_set_client_window (imHandle, null); return 0; } -int /*long*/ gtk_visibility_notify_event (GtkWidget* widget, GdkEventVisibility* event) { +override int /*long*/ gtk_visibility_notify_event (GtkWidget* widget, GdkEventVisibility* event) { GdkEventVisibility* gdkEvent = new GdkEventVisibility (); memmove (gdkEvent, event, GdkEventVisibility.sizeof); auto paintWindow = paintWindow(); @@ -2737,7 +2737,7 @@ return 0; } -void gtk_widget_size_request (GtkWidget* widget, GtkRequisition* requisition) { +/*no override*/ void gtk_widget_size_request (GtkWidget* widget, GtkRequisition* requisition) { OS.gtk_widget_size_request (widget, requisition); }
--- a/dwt/widgets/Decorations.d Wed Jan 09 21:54:40 2008 -0800 +++ b/dwt/widgets/Decorations.d Thu Jan 10 07:34:05 2008 +0100 @@ -14,14 +14,16 @@ import dwt.widgets.Menu; import dwt.widgets.Composite; -class Decorations : Composite { - void fixDecorations (Decorations newDecorations, Control control, Menu [] menus); - void fixAccelGroup () ; -} -/+ -import dwt.*; -import dwt.internal.gtk.*; -import dwt.graphics.*; +import dwt.SWT; +import dwt.internal.gtk.OS; +//import dwt.graphics.; +import dwt.widgets.Canvas; +import dwt.graphics.Image; +import dwt.graphics.ImageData; +import dwt.widgets.Control; +import dwt.widgets.Display; +import dwt.widgets.Widget; +import dwt.widgets.Button; /** * Instances of this class provide the appearance and @@ -100,18 +102,19 @@ * @see Shell * @see SWT */ -public class Decorations extends Canvas { - String text; +public class Decorations : Canvas { + char[] text; Image image; - Image [] images = new Image [0]; - boolean minimized, maximized; + Image [] images; + bool minimized, maximized; Menu menuBar; Menu [] menus; Control savedFocus; Button defaultButton, saveDefault; - int /*long*/ accelGroup, vboxHandle; + GtkAccelGroup* accelGroup; + GtkWidget* vboxHandle; -Decorations () { +this () { /* Do nothing */ } @@ -153,15 +156,15 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public Decorations (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, checkStyle (style)); } static int checkStyle (int style) { - if ((style & SWT.NO_TRIM) != 0) { + if ((style & SWT.NO_TRIM) !is 0) { style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER); } - if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) { + if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) !is 0) { style |= SWT.TITLE; } return style; @@ -172,35 +175,35 @@ } void _setImages (Image [] images) { - if (images != null && images.length > 1) { + if (images !is null && images.length > 1) { Image [] bestImages = new Image [images.length]; System.arraycopy (images, 0, bestImages, 0, images.length); sort (bestImages); images = bestImages; } - int /*long*/ pixbufs = 0; - if (images != null) { + GList* pixbufs; + if (images !is null) { for (int i = 0; i < images.length; i++) { Image image = images [i]; - int /*long*/ pixbuf = Display.createPixbuf (image); + auto pixbuf = Display.createPixbuf (image); pixbufs = OS.g_list_append (pixbufs, pixbuf); } } - OS.gtk_window_set_icon_list (topHandle (), pixbufs); - int /*long*/ [] data = new int /*long*/ [1]; - int /*long*/ temp = pixbufs; - while (temp != 0) { - OS.memmove (data, temp, OS.PTR_SIZEOF); - OS.g_object_unref (data [0]); - temp = OS.g_list_next (temp); + OS.gtk_window_set_icon_list (cast(GtkWindow*)topHandle (), pixbufs); + GList* data; + auto temp = pixbufs; + while (temp !is null) { + data = temp; + OS.g_object_unref (data); + temp = cast(GList*)OS.g_list_next (temp); } - if (pixbufs != 0) OS.g_list_free (pixbufs); + if (pixbufs !is null) OS.g_list_free (pixbufs); } void addMenu (Menu menu) { - if (menus == null) menus = new Menu [4]; + if (menus is null) menus = new Menu [4]; for (int i=0; i<menus.length; i++) { - if (menus [i] == null) { + if (menus [i] is null) { menus [i] = menu; return; } @@ -212,15 +215,15 @@ } int compare (ImageData data1, ImageData data2) { - if (data1.width == data2.width && data1.height == data2.height) { + if (data1.width is data2.width && data1.height is data2.height) { int transparent1 = data1.getTransparencyType (); int transparent2 = data2.getTransparencyType (); - if (transparent1 == SWT.TRANSPARENCY_ALPHA) return -1; - if (transparent2 == SWT.TRANSPARENCY_ALPHA) return 1; - if (transparent1 == SWT.TRANSPARENCY_MASK) return -1; - if (transparent2 == SWT.TRANSPARENCY_MASK) return 1; - if (transparent1 == SWT.TRANSPARENCY_PIXEL) return -1; - if (transparent2 == SWT.TRANSPARENCY_PIXEL) return 1; + if (transparent1 is SWT.TRANSPARENCY_ALPHA) return -1; + if (transparent2 is SWT.TRANSPARENCY_ALPHA) return 1; + if (transparent1 is SWT.TRANSPARENCY_MASK) return -1; + if (transparent2 is SWT.TRANSPARENCY_MASK) return 1; + if (transparent1 is SWT.TRANSPARENCY_PIXEL) return -1; + if (transparent2 is SWT.TRANSPARENCY_PIXEL) return 1; return 0; } return data1.width > data2.width || data1.height > data2.height ? -1 : 1; @@ -235,12 +238,12 @@ } void createAccelGroup () { - if (accelGroup != 0) return; + if (accelGroup !is null) return; accelGroup = OS.gtk_accel_group_new (); - if (accelGroup == 0) SWT.error (SWT.ERROR_NO_HANDLES); + if (accelGroup is null) SWT.error (SWT.ERROR_NO_HANDLES); //FIXME - what should we do for Decorations - int /*long*/ shellHandle = topHandle (); - OS.gtk_window_add_accel_group (shellHandle, accelGroup); + auto shellHandle = topHandle (); + OS.gtk_window_add_accel_group (cast(GtkWindow*)shellHandle, accelGroup); } void createWidget (int index) { @@ -249,32 +252,32 @@ } void destroyAccelGroup () { - if (accelGroup == 0) return; - int /*long*/ shellHandle = topHandle (); - OS.gtk_window_remove_accel_group (shellHandle, accelGroup); + if (accelGroup is null) return; + auto shellHandle = topHandle (); + OS.gtk_window_remove_accel_group (cast(GtkWindow*)shellHandle, accelGroup); //TEMPORARY CODE // OS.g_object_unref (accelGroup); - accelGroup = 0; + accelGroup = null; } void fixAccelGroup () { - if (menuBar == null) return; + if (menuBar is null) return; destroyAccelGroup (); createAccelGroup (); menuBar.addAccelerators (accelGroup); } void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) { - if (this == newDecorations) return; - if (control == savedFocus) savedFocus = null; - if (control == defaultButton) defaultButton = null; - if (control == saveDefault) saveDefault = null; - if (menus == null) return; + if (this is newDecorations) return; + if (control is savedFocus) savedFocus = null; + if (control is defaultButton) defaultButton = null; + if (control is saveDefault) saveDefault = null; + if (menus is null) return; Menu menu = control.menu; - if (menu != null) { + if (menu !is null) { int index = 0; while (index <menus.length) { - if (menus [index] == menu) { + if (menus [index] is menu) { control.setMenu (null); return; } @@ -299,7 +302,7 @@ */ public Button getDefaultButton () { checkWidget(); - return defaultButton != null ? defaultButton : saveDefault; + return defaultButton !is null ? defaultButton : saveDefault; } /** @@ -357,7 +360,7 @@ */ public Image [] getImages () { checkWidget (); - if (images == null) return new Image [0]; + if (images is null) return new Image [0]; Image [] result = new Image [images.length]; System.arraycopy (images, 0, result, 0, images.length); return result; @@ -377,7 +380,7 @@ * * @see #setMaximized */ -public boolean getMaximized () { +public bool getMaximized () { checkWidget(); return maximized; } @@ -412,12 +415,12 @@ * * @see #setMinimized */ -public boolean getMinimized () { +public bool getMinimized () { checkWidget(); return minimized; } -String getNameText () { +char[] getNameText () { return getText (); } @@ -434,21 +437,21 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public String getText () { +public char[] getText () { checkWidget(); return text; } -public boolean isReparentable () { +public bool isReparentable () { checkWidget (); return false; } -boolean isTabGroup () { +bool isTabGroup () { return true; } -boolean isTabItem () { +bool isTabItem () { return false; } @@ -457,25 +460,25 @@ } void removeMenu (Menu menu) { - if (menus == null) return; + if (menus is null) return; for (int i=0; i<menus.length; i++) { - if (menus [i] == menu) { + if (menus [i] is menu) { menus [i] = null; return; } } } -void releaseChildren (boolean destroy) { - if (menuBar != null) { +void releaseChildren (bool destroy) { + if (menuBar !is null) { menuBar.release (false); menuBar = null; } super.releaseChildren (destroy); - if (menus != null) { + if (menus !is null) { for (int i=0; i<menus.length; i++) { Menu menu = menus [i]; - if (menu != null && !menu.isDisposed ()) { + if (menu !is null && !menu.isDisposed ()) { menu.dispose (); } } @@ -485,7 +488,7 @@ void releaseHandle () { super.releaseHandle (); - vboxHandle = 0; + vboxHandle = null; } void releaseWidget () { @@ -496,9 +499,9 @@ defaultButton = saveDefault = null; } -boolean restoreFocus () { - if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null; - boolean restored = savedFocus != null && savedFocus.setFocus (); +bool restoreFocus () { + if (savedFocus !is null && savedFocus.isDisposed ()) savedFocus = null; + bool restored = savedFocus !is null && savedFocus.setFocus (); savedFocus = null; /* * This code is intentionally commented. When no widget @@ -506,7 +509,7 @@ * default button. Motif doesn't do this. */ // if (restored) return true; -// if (defaultButton != null && !defaultButton.isDisposed ()) { +// if (defaultButton !is null && !defaultButton.isDisposed ()) { // if (defaultButton.setFocus ()) return true; // } // return false; @@ -540,14 +543,14 @@ */ public void setDefaultButton (Button button) { checkWidget(); - int /*long*/ buttonHandle = 0; - if (button != null) { + GtkWidget* buttonHandle; + if (button !is null) { if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - if (button.menuShell () != this) error (SWT.ERROR_INVALID_PARENT); + if (button.menuShell () !is this) error (SWT.ERROR_INVALID_PARENT); buttonHandle = button.handle; } saveDefault = defaultButton = button; - OS.gtk_window_set_default (topHandle (), buttonHandle); + OS.gtk_window_set_default (cast(GtkWindow*)topHandle (), buttonHandle); } /** @@ -570,7 +573,7 @@ public void setImage (Image image) { checkWidget (); this.image = image; - _setImages (image != null ? new Image [] {image} : null); + _setImages (image !is null ? [image] : null); } /** @@ -599,9 +602,9 @@ */ public void setImages (Image [] images) { checkWidget (); - if (images == null) error (SWT.ERROR_INVALID_ARGUMENT); + if (images is null) error (SWT.ERROR_INVALID_ARGUMENT); for (int i = 0; i < images.length; i++) { - if (images [i] == null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); + if (images [i] is null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); } this.images = images; _setImages (images); @@ -630,7 +633,7 @@ * * @see #setMinimized */ -public void setMaximized (boolean maximized) { +public void setMaximized (bool maximized) { checkWidget(); this.maximized = maximized; } @@ -652,10 +655,10 @@ */ public void setMenuBar (Menu menu) { checkWidget(); - if (menuBar == menu) return; - if (menu != null) { - if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR); - if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT); + if (menuBar is menu) return; + if (menu !is null) { + if ((menu.style & SWT.BAR) is 0) error (SWT.ERROR_MENU_NOT_BAR); + if (menu.parent !is this) error (SWT.ERROR_INVALID_PARENT); } menuBar = menu; } @@ -683,13 +686,13 @@ * * @see #setMaximized */ -public void setMinimized (boolean minimized) { +public void setMinimized (bool minimized) { checkWidget(); this.minimized = minimized; } void setSavedFocus (Control control) { - if (this == control) return; + if (this is control) return; savedFocus = control; } @@ -708,9 +711,9 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setText (String string) { +public void setText (char[] string) { checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + if (string is null) error (SWT.ERROR_NULL_ARGUMENT); text = string; } @@ -738,13 +741,13 @@ } } -boolean traverseItem (boolean next) { +bool traverseItem (bool next) { return false; } -boolean traverseReturn () { - Button button = defaultButton != null ? defaultButton: saveDefault; - if (button == null || button.isDisposed ()) return false; +bool traverseReturn () { + Button button = defaultButton !is null ? defaultButton: saveDefault; + if (button is null || button.isDisposed ()) return false; /* * Bug in GTK. When a default button that is disabled is * activated using the Enter key, GTK GP's. The fix is to @@ -752,9 +755,8 @@ * key. */ if (!button.isVisible () || !button.isEnabled ()) return true; - int /*long*/ shellHandle = _getShell ().topHandle (); - return OS.gtk_window_activate_default (shellHandle); + auto shellHandle = _getShell ().topHandle (); + return cast(bool)OS.gtk_window_activate_default (cast(GtkWindow*)shellHandle); } } -+/ \ No newline at end of file
--- a/dwt/widgets/Display.d Wed Jan 09 21:54:40 2008 -0800 +++ b/dwt/widgets/Display.d Thu Jan 10 07:34:05 2008 +0100 @@ -923,6 +923,21 @@ OS.gdk_window_add_filter (null, &filterProcFunc, cast(void*)&filterProcCallbackData ); } +/* + * Used by Shell + */ +package void doWindowAddFilter( CallbackData* cbdata, GdkWindow* window, GtkWidget* widget ){ + cbdata.display = this; + cbdata.data = widget; + OS.gdk_window_add_filter (window, &filterProcFunc, cast(void*)&cbdata ); +} + +package void doWindowRemoveFilter( CallbackData* cbdata, GdkWindow* window, GtkWidget* widget ){ + cbdata.display = this; + cbdata.data = widget; + OS.gdk_window_remove_filter(window, &filterProcFunc, cast(void*)&cbdata ); +} + Image createImage (char[] name) { auto style = OS.gtk_widget_get_default_style (); char[] buffer = name; @@ -1442,7 +1457,7 @@ } Widget widget = getWidget (cast(GtkWidget*)callbackData.data); if (widget is null) return 0; - return widget.filterProc (xEvent, gdkEvent, callbackData.data); + return widget.filterProc (cast(XEvent*)xEvent, gdkEvent, callbackData.data); } /** @@ -3690,13 +3705,14 @@ return 0; } -int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { +int /*long*/ sizeAllocateProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { Widget widget = getWidget ( cast(GtkWidget*)user_data); if (widget is null) return 0; return widget.sizeAllocateProc (handle, arg0, user_data); } -int /*long*/ sizeRequestProcMeth (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { + +int /*long*/ sizeRequestProcMeth (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { Widget widget = getWidget (cast(GtkWidget*)user_data); if (widget is null) return 0; return widget.sizeRequestProc (handle, arg0, user_data); @@ -3764,10 +3780,10 @@ private static extern(C) int /*long*/ shellMapProcFunc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { auto cbdata = cast(CallbackData*)user_data; - return cbdata.display.shellMapProc( handle, arg0, cast(int)cbdata.data ); + return cbdata.display.shellMapProc( cast(GtkWidget*)handle, arg0, cast(int)cbdata.data ); } -int /*long*/ shellMapProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { +int /*long*/ shellMapProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { Widget widget = getWidget (cast(GtkWidget*)handle); if (widget is null) return 0; return widget.shellMapProc (handle, arg0, user_data);
--- a/dwt/widgets/Menu.d Wed Jan 09 21:54:40 2008 -0800 +++ b/dwt/widgets/Menu.d Thu Jan 10 07:34:05 2008 +0100 @@ -11,13 +11,16 @@ module dwt.widgets.Menu; import dwt.widgets.Control; -import dwt.internal.c.gtk; +import dwt.widgets.Decorations; +import dwt.internal.gtk.OS; class Menu : Control { -bool isDisposed(); -void dispose(); -void _setVisible (bool visible); -void createIMMenu (GtkIMContext* imHandle) ; + bool isDisposed(); + void dispose(); + void _setVisible (bool visible); + void createIMMenu (GtkIMContext* imHandle) ; + void addAccelerators(GtkAccelGroup*); + void fixMenus (Decorations newParent) ; } /+++
--- a/dwt/widgets/Shell.d Wed Jan 09 21:54:40 2008 -0800 +++ b/dwt/widgets/Shell.d Thu Jan 10 07:34:05 2008 +0100 @@ -14,28 +14,31 @@ import dwt.widgets.Control; import dwt.internal.c.gtk; -class Shell : Composite { - GtkWidget* shellHandle; - bool isDisposed(); - void dispose(); - void fixStyle (); - void redraw (bool); - void layout (bool, bool); - void setSavedFocus(Control); - GtkWidget* vboxHandle; - void fixShell (Shell newShell, Control control) ; - void bringToTop (bool force); - public void forceActive () ; - void setActiveControl (Control control) ; - void setToolTipText (GtkWidget* widget, char[] str) ; -} +import dwt.SWT; +import dwt.internal.gtk.OS; +import dwt.events.ShellListener; +import dwt.graphics.Cursor; +import dwt.graphics.Image; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +import dwt.graphics.Region; +import dwt.internal.Converter; +import dwt.internal.SWTEventListener; +import dwt.widgets.Composite; +import dwt.widgets.Control; +import dwt.widgets.Decorations; +import dwt.widgets.Display; +import dwt.widgets.Event; +import dwt.widgets.EventTable; +import dwt.widgets.Layout; +import dwt.widgets.Listener; +import dwt.widgets.Menu; +import dwt.widgets.Monitor; +import dwt.widgets.TypedListener; +import dwt.widgets.Widget; -/++ -import dwt.*; -import dwt.internal.*; -import dwt.internal.gtk.*; -import dwt.graphics.*; -import dwt.events.*; +import Unicode = tango.text.Unicode; +import tango.stdc.stringz; /** * Instances of this class represent the "windows" @@ -133,13 +136,14 @@ * @see Decorations * @see SWT */ -public class Shell extends Decorations { - int /*long*/ shellHandle, tooltipsHandle, tooltipWindow; - boolean mapped, moved, resized, opened; +public class Shell : Decorations { + GtkWidget* shellHandle, tooltipsHandle, tooltipWindow; + bool mapped, moved, resized, opened; int oldX, oldY, oldWidth, oldHeight; int minWidth, minHeight; Control lastActive; Region region; + Display.CallbackData filterProcCallbackData; static final int MAXIMUM_TRIM = 128; @@ -152,8 +156,8 @@ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> */ -public Shell () { - this ((Display) null); +public this () { + this (cast(Display) null); } /** * Constructs a new instance of this class given only the style @@ -190,8 +194,8 @@ * @see SWT#APPLICATION_MODAL * @see SWT#SYSTEM_MODAL */ -public Shell (int style) { - this ((Display) null, style); +public this (int style) { + this (cast(Display) null, style); } /** @@ -213,7 +217,7 @@ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> */ -public Shell (Display display) { +public this (Display display) { this (display, SWT.SHELL_TRIM); } /** @@ -259,25 +263,25 @@ * @see SWT#APPLICATION_MODAL * @see SWT#SYSTEM_MODAL */ -public Shell (Display display, int style) { - this (display, null, style, 0, false); +public this (Display display, int style) { + this (display, null, style, null, false); } -Shell (Display display, Shell parent, int style, int /*long*/ handle, boolean embedded) { +this (Display display, Shell parent, int style, GtkWidget* handle, bool embedded) { super (); checkSubclass (); - if (display == null) display = Display.getCurrent (); - if (display == null) display = Display.getDefault (); + if (display is null) display = Display.getCurrent (); + if (display is null) display = Display.getDefault (); if (!display.isValidThread ()) { error (SWT.ERROR_THREAD_INVALID_ACCESS); } - if (parent != null && parent.isDisposed ()) { + if (parent !is null && parent.isDisposed ()) { error (SWT.ERROR_INVALID_ARGUMENT); } this.style = checkStyle (style); this.parent = parent; this.display = display; - if (handle != 0) { + if (handle !is null) { if (embedded) { this.handle = handle; } else { @@ -310,7 +314,7 @@ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> */ -public Shell (Shell parent) { +public this (Shell parent) { this (parent, SWT.DIALOG_TRIM); } @@ -361,26 +365,26 @@ * @see SWT#APPLICATION_MODAL * @see SWT#SYSTEM_MODAL */ -public Shell (Shell parent, int style) { - this (parent != null ? parent.display : null, parent, style, 0, false); +public this (Shell parent, int style) { + this (parent !is null ? parent.display : null, parent, style, null, false); } -public static Shell gtk_new (Display display, int /*long*/ handle) { +public static Shell gtk_new (Display display, GtkWidget* handle) { return new Shell (display, null, SWT.NO_TRIM, handle, true); } -public static Shell internal_new (Display display, int /*long*/ handle) { +public static Shell internal_new (Display display, GtkWidget* handle) { return new Shell (display, null, SWT.NO_TRIM, handle, false); } static int checkStyle (int style) { style = Decorations.checkStyle (style); - if ((style & SWT.ON_TOP) != 0) style &= ~SWT.SHELL_TRIM; + if ((style & SWT.ON_TOP) !is 0) style &= ~SWT.SHELL_TRIM; int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL; int bits = style & ~mask; - if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL; - if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL; - if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL; + if ((style & SWT.SYSTEM_MODAL) !is 0) return bits | SWT.SYSTEM_MODAL; + if ((style & SWT.APPLICATION_MODAL) !is 0) return bits | SWT.APPLICATION_MODAL; + if ((style & SWT.PRIMARY_MODAL) !is 0) return bits | SWT.PRIMARY_MODAL; return bits; } @@ -405,7 +409,7 @@ */ public void addShellListener (ShellListener listener) { checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Close,typedListener); addListener (SWT.Iconify,typedListener); @@ -418,8 +422,8 @@ if (display.ignoreTrim) return; int width = OS.GTK_WIDGET_WIDTH (shellHandle); int height = OS.GTK_WIDGET_HEIGHT (shellHandle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - GdkRectangle rect = new GdkRectangle (); + auto window = OS.GTK_WIDGET_WINDOW (shellHandle); + GdkRectangle* rect = new GdkRectangle (); OS.gdk_window_get_frame_extents (window, rect); int trimWidth = Math.max (0, rect.width - width); int trimHeight = Math.max (0, rect.height - height); @@ -432,11 +436,11 @@ display.ignoreTrim = true; return; } - boolean hasTitle = false, hasResize = false, hasBorder = false; - if ((style & SWT.NO_TRIM) == 0) { - hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; - hasResize = (style & SWT.RESIZE) != 0; - hasBorder = (style & SWT.BORDER) != 0; + bool hasTitle = false, hasResize = false, hasBorder = false; + if ((style & SWT.NO_TRIM) is 0) { + hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) !is 0; + hasResize = (style & SWT.RESIZE) !is 0; + hasBorder = (style & SWT.BORDER) !is 0; } if (hasTitle) { if (hasResize) { @@ -465,16 +469,16 @@ } } -void bringToTop (boolean force) { +void bringToTop (bool force) { if (!OS.GTK_WIDGET_VISIBLE (shellHandle)) return; Display display = this.display; Shell activeShell = display.activeShell; - if (activeShell == this) return; + if (activeShell is this) return; if (!force) { - if (activeShell == null) return; + if (activeShell is null) return; if (!display.activePending) { - int /*long*/ focusHandle = OS.gtk_window_get_focus (activeShell.shellHandle); - if (focusHandle != 0 && !OS.GTK_WIDGET_HAS_FOCUS (focusHandle)) return; + auto focusHandle = OS.gtk_window_get_focus (cast(GtkWindow*)activeShell.shellHandle); + if (focusHandle !is null && !OS.GTK_WIDGET_HAS_FOCUS (focusHandle)) return; } } /* @@ -487,9 +491,9 @@ * * NOTE: This bug is fixed in GTK+ 2.6.8 and above. */ - boolean xFocus = false; - if (activeShell != null) { - if (OS.GTK_VERSION < OS.VERSION (2, 6, 8)) { + bool xFocus = false; + if (activeShell !is null) { + if (OS.GTK_VERSION < OS.buildVERSION (2, 6, 8)) { xFocus = activeShell.isUndecorated (); } display.activeShell = null; @@ -501,10 +505,10 @@ * window. The fix is to use XSetInputFocus() to force * the focus. */ - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - if ((xFocus || (style & SWT.ON_TOP) != 0) && OS.GDK_WINDOWING_X11 ()) { - int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay (window); - int /*long*/ xWindow = OS.gdk_x11_drawable_get_xid (window); + auto window = OS.GTK_WIDGET_WINDOW (shellHandle); + if ((xFocus || (style & SWT.ON_TOP) !is 0) && OS.GDK_WINDOWING_X11 ()) { + auto xDisplay = OS.gdk_x11_drawable_get_xdisplay (window); + auto xWindow = OS.gdk_x11_drawable_get_xid (window); OS.gdk_error_trap_push (); /* Use CurrentTime instead of the last event time to ensure that the shell becomes active */ OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime); @@ -516,7 +520,7 @@ * to come forward in versions > 2.10.0. The fix is to use the last * user event time. */ - if (display.windowManager.toLowerCase ().equals ("metacity")) { + if ( Unicode.toLower( display.windowManager ) ==/*eq*/ "metacity") { OS.gdk_window_focus (window, display.lastUserEventTime); } else { OS.gdk_window_focus (window, OS.GDK_CURRENT_TIME); @@ -534,8 +538,8 @@ if (!opened) resized = false; } -int /*long*/ childStyle () { - return 0; +override GtkStyle* childStyle () { + return null; } /** @@ -567,15 +571,15 @@ checkWidget(); Rectangle trim = super.computeTrim (x, y, width, height); int border = 0; - if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { - border = OS.gtk_container_get_border_width (shellHandle); + if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) is 0) { + border = OS.gtk_container_get_border_width (cast(GtkContainer*)shellHandle); } int trimWidth = trimWidth (), trimHeight = trimHeight (); trim.x -= (trimWidth / 2) + border; trim.y -= trimHeight - (trimWidth / 2) + border; trim.width += trimWidth + border * 2; trim.height += trimHeight + border * 2; - if (menuBar != null) { + if (menuBar !is null) { forceResize (); int menuBarHeight = OS.GTK_WIDGET_HEIGHT (menuBar.handle); trim.y -= menuBarHeight; @@ -584,25 +588,26 @@ return trim; } +alias Decorations.createHandle createHandle; void createHandle (int index) { state |= HANDLE | CANVAS; - if (shellHandle == 0) { - if (handle == 0) { + if (shellHandle is null) { + if (handle is null) { int type = OS.GTK_WINDOW_TOPLEVEL; - if ((style & SWT.ON_TOP) != 0) type = OS.GTK_WINDOW_POPUP; - shellHandle = OS.gtk_window_new (type); + if ((style & SWT.ON_TOP) !is 0) type = OS.GTK_WINDOW_POPUP; + shellHandle = cast(GtkWidget*)OS.gtk_window_new (type); } else { - shellHandle = OS.gtk_plug_new (handle); + shellHandle = cast(GtkWidget*) OS.gtk_plug_new (cast(uint)handle); } - if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES); - if (parent != null) { - OS.gtk_window_set_transient_for (shellHandle, parent.topHandle ()); - OS.gtk_window_set_destroy_with_parent (shellHandle, true); + if (shellHandle is null) error (SWT.ERROR_NO_HANDLES); + if (parent !is null) { + OS.gtk_window_set_transient_for (cast(GtkWindow*)shellHandle, cast(GtkWindow*)parent.topHandle ()); + OS.gtk_window_set_destroy_with_parent (cast(GtkWindow*)shellHandle, true); if (!isUndecorated ()) { - OS.gtk_window_set_type_hint (shellHandle, OS.GDK_WINDOW_TYPE_HINT_DIALOG); + OS.gtk_window_set_type_hint (cast(GtkWindow*)shellHandle, OS.GDK_WINDOW_TYPE_HINT_DIALOG); } else { - if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) { - OS.gtk_window_set_skip_taskbar_hint (shellHandle, true); + if (OS.GTK_VERSION >= OS.buildVERSION (2, 2, 0)) { + OS.gtk_window_set_skip_taskbar_hint (cast(GtkWindow*)shellHandle, true); } } } @@ -611,40 +616,41 @@ * is created or it will not be allowed to be resized smaller that the * initial size by the user. The fix is to set the size to zero. */ - if ((style & SWT.RESIZE) != 0) { + if ((style & SWT.RESIZE) !is 0) { OS.gtk_widget_set_size_request (shellHandle, 0, 0); - OS.gtk_window_set_resizable (shellHandle, true); + OS.gtk_window_set_resizable (cast(GtkWindow*)shellHandle, true); } else { - OS.gtk_window_set_resizable (shellHandle, false); + OS.gtk_window_set_resizable (cast(GtkWindow*)shellHandle, false); } vboxHandle = OS.gtk_vbox_new (false, 0); - if (vboxHandle == 0) error (SWT.ERROR_NO_HANDLES); + if (vboxHandle is null) error (SWT.ERROR_NO_HANDLES); createHandle (index, false, true); - OS.gtk_container_add (vboxHandle, scrolledHandle); - OS.gtk_box_set_child_packing (vboxHandle, scrolledHandle, true, true, 0, OS.GTK_PACK_END); - OS.gtk_window_set_title (shellHandle, new byte [1]); - if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { - OS.gtk_container_set_border_width (shellHandle, 1); - GdkColor color = new GdkColor (); + OS.gtk_container_add (cast(GtkContainer*)vboxHandle, scrolledHandle); + OS.gtk_box_set_child_packing (cast(GtkBox*)vboxHandle, scrolledHandle, true, true, 0, OS.GTK_PACK_END); + char[] dummy = "a"; + OS.gtk_window_set_title (cast(GtkWindow*)shellHandle, dummy.ptr ); + if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) is 0) { + OS.gtk_container_set_border_width (cast(GtkContainer*)shellHandle, 1); + GdkColor* color = new GdkColor (); OS.gtk_style_get_black (OS.gtk_widget_get_style (shellHandle), color); OS.gtk_widget_modify_bg (shellHandle, OS.GTK_STATE_NORMAL, color); } int bits = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL; - boolean modal = (style & bits) != 0; + bool modal = (style & bits) !is 0; //TEMPORARY CODE - if ((style & SWT.ON_TOP) == 0) modal |= (parent != null && (parent.style & bits) != 0); - OS.gtk_window_set_modal (shellHandle, modal); + if ((style & SWT.ON_TOP) is 0) modal |= (parent !is null && (parent.style & bits) !is 0); + OS.gtk_window_set_modal (cast(GtkWindow*)shellHandle, modal); } else { - vboxHandle = OS.gtk_bin_get_child (shellHandle); - if (vboxHandle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ children = OS.gtk_container_get_children (vboxHandle); + vboxHandle = OS.gtk_bin_get_child (cast(GtkBin*)shellHandle); + if (vboxHandle is null) error (SWT.ERROR_NO_HANDLES); + auto children = OS.gtk_container_get_children (cast(GtkContainer*)vboxHandle); if (OS.g_list_length (children) > 0) { - scrolledHandle = OS.g_list_data (children); + scrolledHandle = cast(GtkWidget*)OS.g_list_data (children); } OS.g_list_free (children); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_bin_get_child (scrolledHandle); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); + if (scrolledHandle is null) error (SWT.ERROR_NO_HANDLES); + handle = OS.gtk_bin_get_child (cast(GtkBin*)scrolledHandle); + if (handle is null) error (SWT.ERROR_NO_HANDLES); } /* * Feature in GTK. Realizing the shell triggers a size allocate event, @@ -655,19 +661,18 @@ OS.gtk_widget_realize (shellHandle); } -int /*long*/ filterProc (int /*long*/ xEvent, int /*long*/ gdkEvent, int /*long*/ data2) { +override int /*long*/ filterProc ( XEvent* xEvent, GdkEvent* gdkEvent, void* data2) { int eventType = OS.X_EVENT_TYPE (xEvent); - if (eventType != OS.FocusOut && eventType != OS.FocusIn) return 0; - XFocusChangeEvent xFocusEvent = new XFocusChangeEvent(); - OS.memmove (xFocusEvent, xEvent, XFocusChangeEvent.sizeof); + if (eventType !is OS.FocusOut && eventType !is OS.FocusIn) return 0; + XFocusChangeEvent* xFocusEvent = cast(XFocusChangeEvent*)xEvent; switch (eventType) { case OS.FocusIn: - if (xFocusEvent.mode == OS.NotifyNormal || xFocusEvent.mode == OS.NotifyWhileGrabbed) { + if (xFocusEvent.mode is OS.NotifyNormal || xFocusEvent.mode is OS.NotifyWhileGrabbed) { switch (xFocusEvent.detail) { case OS.NotifyNonlinear: case OS.NotifyNonlinearVirtual: case OS.NotifyAncestor: - if (tooltipsHandle != 0) OS.gtk_tooltips_enable (tooltipsHandle); + if (tooltipsHandle !is null) OS.gtk_tooltips_enable (cast(GtkTooltips*)tooltipsHandle); display.activeShell = this; display.activePending = false; sendEvent (SWT.Activate); @@ -676,16 +681,16 @@ } break; case OS.FocusOut: - if (xFocusEvent.mode == OS.NotifyNormal || xFocusEvent.mode == OS.NotifyWhileGrabbed) { + if (xFocusEvent.mode is OS.NotifyNormal || xFocusEvent.mode is OS.NotifyWhileGrabbed) { switch (xFocusEvent.detail) { case OS.NotifyNonlinear: case OS.NotifyNonlinearVirtual: case OS.NotifyVirtual: - if (tooltipsHandle != 0) OS.gtk_tooltips_disable (tooltipsHandle); + if (tooltipsHandle !is null) OS.gtk_tooltips_disable (cast(GtkTooltips*)tooltipsHandle); Display display = this.display; sendEvent (SWT.Deactivate); setActiveControl (null); - if (display.activeShell == this) { + if (display.activeShell is this) { display.activeShell = null; display.activePending = false; } @@ -698,14 +703,14 @@ } Control findBackgroundControl () { - return (state & BACKGROUND) != 0 || backgroundImage != null ? this : null; + return (state & BACKGROUND) !is 0 || backgroundImage !is null ? this : null; } Composite findDeferredControl () { return layoutCount > 0 ? this : null; } -boolean hasBorder () { +bool hasBorder () { return false; } @@ -720,23 +725,24 @@ OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [DELETE_EVENT], 0, display.closures [DELETE_EVENT], false); OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [MAP_EVENT], 0, display.shellMapProcClosure, false); OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); - OS.g_signal_connect_closure (shellHandle, OS.move_focus, display.closures [MOVE_FOCUS], false); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - OS.gdk_window_add_filter (window, display.filterProc, shellHandle); + OS.g_signal_connect_closure (shellHandle, OS.move_focus.ptr, display.closures [MOVE_FOCUS], false); + auto window = OS.GTK_WIDGET_WINDOW (shellHandle); + display.doWindowAddFilter( &filterProcCallbackData, window, shellHandle ); + //OS.gdk_window_add_filter (window, display.filterProc, shellHandle); } -public boolean isEnabled () { +public bool isEnabled () { checkWidget (); return getEnabled (); } -boolean isUndecorated () { +bool isUndecorated () { return - (style & (SWT.SHELL_TRIM | SWT.BORDER)) == SWT.NONE || - (style & (SWT.NO_TRIM | SWT.ON_TOP)) != 0; + (style & (SWT.SHELL_TRIM | SWT.BORDER)) is SWT.NONE || + (style & (SWT.NO_TRIM | SWT.ON_TOP)) !is 0; } -public boolean isVisible () { +public bool isVisible () { checkWidget(); return getVisible (); } @@ -750,37 +756,38 @@ /* Do nothing */ } -int /*long*/ topHandle () { +GtkWidget* topHandle () { return shellHandle; } void fixActiveShell () { - if (display.activeShell == this) { + if (display.activeShell is this) { Shell shell = null; - if (parent != null && parent.isVisible ()) shell = parent.getShell (); - if (shell == null && isUndecorated ()) { + if (parent !is null && parent.isVisible ()) shell = parent.getShell (); + if (shell is null && isUndecorated ()) { Shell [] shells = display.getShells (); for (int i = 0; i < shells.length; i++) { - if (shells [i] != null && shells [i].isVisible ()) { + if (shells [i] !is null && shells [i].isVisible ()) { shell = shells [i]; break; } } } - if (shell != null) shell.bringToTop (false); + if (shell !is null) shell.bringToTop (false); } } void fixShell (Shell newShell, Control control) { - if (this == newShell) return; - if (control == lastActive) setActiveControl (null); - String toolTipText = control.toolTipText; - if (toolTipText != null) { + if (this is newShell) return; + if (control is lastActive) setActiveControl (null); + char[] toolTipText = control.toolTipText; + if (toolTipText !is null) { control.setToolTipText (this, null); control.setToolTipText (newShell, toolTipText); } } +alias Decorations.fixStyle fixStyle; void fixStyle (int /*long*/ handle) { } @@ -789,22 +796,22 @@ } void forceResize (int width, int height) { - GtkRequisition requisition = new GtkRequisition (); + GtkRequisition* requisition = new GtkRequisition (); OS.gtk_widget_size_request (vboxHandle, requisition); - GtkAllocation allocation = new GtkAllocation (); - int border = OS.gtk_container_get_border_width (shellHandle); + GtkAllocation* allocation = new GtkAllocation (); + int border = OS.gtk_container_get_border_width (cast(GtkContainer*)shellHandle); allocation.x = border; allocation.y = border; allocation.width = width; allocation.height = height; - OS.gtk_widget_size_allocate (vboxHandle, allocation); + OS.gtk_widget_size_allocate (cast(GtkWidget*)vboxHandle, allocation); } public Point getLocation () { checkWidget (); - int [] x = new int [1], y = new int [1]; - OS.gtk_window_get_position (shellHandle, x,y); - return new Point (x [0], y [0]); + int x, y; + OS.gtk_window_get_position (cast(GtkWindow*)shellHandle, &x,&y); + return new Point (x, y); } /** @@ -834,13 +841,13 @@ int width = OS.GTK_WIDGET_WIDTH (vboxHandle); int height = OS.GTK_WIDGET_HEIGHT (vboxHandle); int border = 0; - if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { - border = OS.gtk_container_get_border_width (shellHandle); + if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) is 0) { + border = OS.gtk_container_get_border_width (cast(GtkContainer*)shellHandle); } return new Point (width + trimWidth () + 2*border, height + trimHeight () + 2*border); } -public boolean getVisible () { +public bool getVisible () { checkWidget(); return OS.GTK_WIDGET_VISIBLE (shellHandle); } @@ -908,8 +915,8 @@ Control shell = shells [i]; do { shell = shell.getParent (); - } while (shell != null && shell != this); - if (shell == this) count++; + } while (shell !is null && shell !is this); + if (shell is this) count++; } int index = 0; Shell [] result = new Shell [count]; @@ -917,47 +924,47 @@ Control shell = shells [i]; do { shell = shell.getParent (); - } while (shell != null && shell != this); - if (shell == this) { + } while (shell !is null && shell !is this); + if (shell is this) { result [index++] = shells [i]; } } return result; } -int /*long*/ gtk_configure_event (int /*long*/ widget, int /*long*/ event) { - int [] x = new int [1], y = new int [1]; - OS.gtk_window_get_position (shellHandle, x, y); - if (!moved || oldX != x [0] || oldY != y [0]) { +override int /*long*/ gtk_configure_event (GtkWidget* widget, int /*long*/ event) { + int x, y; + OS.gtk_window_get_position (cast(GtkWindow*)shellHandle, &x, &y); + if (!moved || oldX !is x || oldY !is y) { moved = true; - oldX = x [0]; - oldY = y [0]; + oldX = x; + oldY = y; sendEvent (SWT.Move); // widget could be disposed at this point } return 0; } -int /*long*/ gtk_delete_event (int /*long*/ widget, int /*long*/ event) { +override int /*long*/ gtk_delete_event (GtkWidget* widget, int /*long*/ event) { if (isEnabled()) closeWidget (); return 1; } -int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) { - if (widget != shellHandle) { +override int /*long*/ gtk_enter_notify_event (GtkWidget* widget, GdkEventCrossing* event) { + if (widget !is shellHandle) { return super.gtk_enter_notify_event (widget, event); } return 0; } -int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) { - switch ((int)/*64*/directionType) { +override int /*long*/ gtk_focus (GtkWidget* widget, int directionType) { + switch (cast(int)/*64*/directionType) { case OS.GTK_DIR_TAB_FORWARD: case OS.GTK_DIR_TAB_BACKWARD: Control control = display.getFocusControl (); - if (control != null) { - if ((control.state & CANVAS) != 0 && (control.style & SWT.EMBEDDED) != 0) { - int traversal = directionType == OS.GTK_DIR_TAB_FORWARD ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS; + if (control !is null) { + if ((control.state & CANVAS) !is 0 && (control.style & SWT.EMBEDDED) !is 0) { + int traversal = directionType is OS.GTK_DIR_TAB_FORWARD ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS; control.traverse (traversal); return 1; } @@ -967,34 +974,34 @@ return super.gtk_focus (widget, directionType); } -int /*long*/ gtk_move_focus (int /*long*/ widget, int /*long*/ directionType) { +override int /*long*/ gtk_move_focus (GtkWidget* widget, int directionType) { Control control = display.getFocusControl (); - if (control != null) { - int /*long*/ focusHandle = control.focusHandle (); - OS.gtk_widget_child_focus (focusHandle, (int)/*64*/directionType); + if (control !is null) { + auto focusHandle = control.focusHandle (); + OS.gtk_widget_child_focus (focusHandle, directionType); } - OS.g_signal_stop_emission_by_name (shellHandle, OS.move_focus); + OS.g_signal_stop_emission_by_name (shellHandle, OS.move_focus.ptr ); return 1; } -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { +override int /*long*/ gtk_key_press_event (GtkWidget* widget, GdkEventKey* event) { /* Stop menu mnemonics when the shell is disabled */ - if (widget == shellHandle) { - return (state & DISABLED) != 0 ? 1 : 0; + if (widget is shellHandle) { + return (state & DISABLED) !is 0 ? 1 : 0; } return super.gtk_key_press_event (widget, event); } -int /*long*/ gtk_map_event (int /*long*/ widget, int /*long*/ event) { +override int /*long*/ gtk_map_event (GtkWidget* widget, int /*long*/ event) { minimized = false; sendEvent (SWT.Deiconify); return 0; } -int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) { +override int /*long*/ gtk_size_allocate (GtkWidget* widget, int /*long*/ allocation) { int width = OS.GTK_WIDGET_WIDTH (shellHandle); int height = OS.GTK_WIDGET_HEIGHT (shellHandle); - if (!resized || oldWidth != width || oldHeight != height) { + if (!resized || oldWidth !is width || oldHeight !is height) { oldWidth = width; oldHeight = height; resizeBounds (width, height, true); @@ -1002,45 +1009,43 @@ return 0; } -int /*long*/ gtk_realize (int /*long*/ widget) { - int /*long*/ result = super.gtk_realize (widget); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - if ((style & SWT.SHELL_TRIM) != SWT.SHELL_TRIM) { +override int /*long*/ gtk_realize (GtkWidget* widget) { + auto result = super.gtk_realize (widget); + auto window = OS.GTK_WIDGET_WINDOW (shellHandle); + if ((style & SWT.SHELL_TRIM) !is SWT.SHELL_TRIM) { int decorations = 0; - if ((style & SWT.NO_TRIM) == 0) { - if ((style & SWT.MIN) != 0) decorations |= OS.GDK_DECOR_MINIMIZE; - if ((style & SWT.MAX) != 0) decorations |= OS.GDK_DECOR_MAXIMIZE; - if ((style & SWT.RESIZE) != 0) decorations |= OS.GDK_DECOR_RESIZEH; - if ((style & SWT.BORDER) != 0) decorations |= OS.GDK_DECOR_BORDER; - if ((style & SWT.MENU) != 0) decorations |= OS.GDK_DECOR_MENU; - if ((style & SWT.TITLE) != 0) decorations |= OS.GDK_DECOR_TITLE; + if ((style & SWT.NO_TRIM) is 0) { + if ((style & SWT.MIN) !is 0) decorations |= OS.GDK_DECOR_MINIMIZE; + if ((style & SWT.MAX) !is 0) decorations |= OS.GDK_DECOR_MAXIMIZE; + if ((style & SWT.RESIZE) !is 0) decorations |= OS.GDK_DECOR_RESIZEH; + if ((style & SWT.BORDER) !is 0) decorations |= OS.GDK_DECOR_BORDER; + if ((style & SWT.MENU) !is 0) decorations |= OS.GDK_DECOR_MENU; + if ((style & SWT.TITLE) !is 0) decorations |= OS.GDK_DECOR_TITLE; /* * Feature in GTK. Under some Window Managers (Sawmill), in order * to get any border at all from the window manager it is necessary to * set GDK_DECOR_BORDER. The fix is to force these bits when any * kind of border is requested. */ - if ((style & SWT.RESIZE) != 0) decorations |= OS.GDK_DECOR_BORDER; + if ((style & SWT.RESIZE) !is 0) decorations |= OS.GDK_DECOR_BORDER; } OS.gdk_window_set_decorations (window, decorations); } - if ((style & SWT.ON_TOP) != 0) { + if ((style & SWT.ON_TOP) !is 0) { OS.gdk_window_set_override_redirect (window, true); } return result; } -int /*long*/ gtk_unmap_event (int /*long*/ widget, int /*long*/ event) { +override int /*long*/ gtk_unmap_event (GtkWidget* widget, int /*long*/ event) { minimized = true; sendEvent (SWT.Iconify); return 0; } -int /*long*/ gtk_window_state_event (int /*long*/ widget, int /*long*/ event) { - GdkEventWindowState gdkEvent = new GdkEventWindowState (); - OS.memmove (gdkEvent, event, GdkEventWindowState.sizeof); - minimized = (gdkEvent.new_window_state & OS.GDK_WINDOW_STATE_ICONIFIED) != 0; - maximized = (gdkEvent.new_window_state & OS.GDK_WINDOW_STATE_MAXIMIZED) != 0; +override int /*long*/ gtk_window_state_event (GtkWidget* widget, GdkEventWindowState* event) { + minimized = (event.new_window_state & OS.GDK_WINDOW_STATE_ICONIFIED) !is 0; + maximized = (event.new_window_state & OS.GDK_WINDOW_STATE_MAXIMIZED) !is 0; return 0; } @@ -1092,8 +1097,8 @@ */ public void removeShellListener (ShellListener listener) { checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; + if (listener is null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable is null) return; eventTable.unhook (SWT.Close, listener); eventTable.unhook (SWT.Iconify,listener); eventTable.unhook (SWT.Deiconify,listener); @@ -1128,21 +1133,21 @@ } void setActiveControl (Control control) { - if (control != null && control.isDisposed ()) control = null; - if (lastActive != null && lastActive.isDisposed ()) lastActive = null; - if (lastActive == control) return; + if (control !is null && control.isDisposed ()) control = null; + if (lastActive !is null && lastActive.isDisposed ()) lastActive = null; + if (lastActive is control) return; /* * Compute the list of controls to be activated and * deactivated by finding the first common parent * control. */ - Control [] activate = (control == null) ? new Control[0] : control.getPath (); - Control [] deactivate = (lastActive == null) ? new Control[0] : lastActive.getPath (); + Control [] activate = (control is null) ? new Control[0] : control.getPath (); + Control [] deactivate = (lastActive is null) ? new Control[0] : lastActive.getPath (); lastActive = control; int index = 0, length = Math.min (activate.length, deactivate.length); while (index < length) { - if (activate [index] != deactivate [index]) break; + if (activate [index] !is deactivate [index]) break; index++; } @@ -1164,14 +1169,14 @@ } } -void resizeBounds (int width, int height, boolean notify) { - if (redrawWindow != 0) { +void resizeBounds (int width, int height, bool notify) { + if (redrawWindow !is null) { OS.gdk_window_resize (redrawWindow, width, height); } - if (enableWindow != 0) { + if (enableWindow !is null) { OS.gdk_window_resize (enableWindow, width, height); } - int border = OS.gtk_container_get_border_width (shellHandle); + int border = OS.gtk_container_get_border_width (cast(GtkContainer*)shellHandle); int boxWidth = width - 2*border; int boxHeight = height - 2*border; OS.gtk_widget_set_size_request (vboxHandle, boxWidth, boxHeight); @@ -1180,14 +1185,14 @@ resized = true; sendEvent (SWT.Resize); if (isDisposed ()) return; - if (layout != null) { + if (layout_ !is null) { markLayout (false, false); updateLayout (false); } } } -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { +int setBounds (int x, int y, int width, int height, bool move, bool resize) { /* * Bug in GTK. When either of the location or size of * a shell is changed while the shell is maximized, the @@ -1197,17 +1202,17 @@ */ if (getMaximized ()) { Rectangle rect = getBounds (); - boolean sameOrigin = !move || (rect.x == x && rect.y == y); - boolean sameExtent = !resize || (rect.width == width && rect.height == height); + bool sameOrigin = !move || (rect.x is x && rect.y is y); + bool sameExtent = !resize || (rect.width is width && rect.height is height); if (sameOrigin && sameExtent) return 0; setMaximized (false); } int result = 0; if (move) { - int [] x_pos = new int [1], y_pos = new int [1]; - OS.gtk_window_get_position (shellHandle, x_pos, y_pos); - OS.gtk_window_move (shellHandle, x, y); - if (x_pos [0] != x || y_pos [0] != y) { + int x_pos, y_pos; + OS.gtk_window_get_position (cast(GtkWindow*)shellHandle, &x_pos, &y_pos); + OS.gtk_window_move (cast(GtkWindow*)shellHandle, x, y); + if (x_pos !is x || y_pos !is y) { moved = true; oldX = x; oldY = y; @@ -1219,8 +1224,8 @@ if (resize) { width = Math.max (1, Math.max (minWidth, width - trimWidth ())); height = Math.max (1, Math.max (minHeight, height - trimHeight ())); - if ((style & SWT.RESIZE) != 0) OS.gtk_window_resize (shellHandle, width, height); - boolean changed = width != oldWidth || height != oldHeight; + if ((style & SWT.RESIZE) !is 0) OS.gtk_window_resize (cast(GtkWindow*)shellHandle, width, height); + bool changed = width !is oldWidth || height !is oldHeight; if (changed) { oldWidth = width; oldHeight = height; @@ -1231,29 +1236,29 @@ return result; } -void setCursor (int /*long*/ cursor) { - if (enableWindow != 0) { - OS.gdk_window_set_cursor (enableWindow, cursor); +void setCursor (GdkCursor* cursor) { + if (enableWindow !is null) { + OS.gdk_window_set_cursor (cast(GdkDrawable*)enableWindow, cursor); if (!OS.GDK_WINDOWING_X11 ()) { OS.gdk_flush (); } else { - int /*long*/ xDisplay = OS.GDK_DISPLAY (); + auto xDisplay = OS.GDK_DISPLAY (); OS.XFlush (xDisplay); } } super.setCursor (cursor); } -public void setEnabled (boolean enabled) { +public void setEnabled (bool enabled) { checkWidget(); - if (((state & DISABLED) == 0) == enabled) return; + if (((state & DISABLED) is 0) is enabled) return; Display display = this.display; Control control = null; - boolean fixFocus = false; + bool fixFocus_ = false; if (!enabled) { - if (display.focusEvent != SWT.FocusOut) { + if (display.focusEvent !is SWT.FocusOut) { control = display.getFocusControl (); - fixFocus = isFocusAncestor (control); + fixFocus_ = isFocusAncestor (control); } } if (enabled) { @@ -1264,30 +1269,30 @@ enableWidget (enabled); if (isDisposed ()) return; if (enabled) { - if (enableWindow != 0) { - OS.gdk_window_set_user_data (enableWindow, 0); + if (enableWindow !is null) { + OS.gdk_window_set_user_data (enableWindow, null); OS.gdk_window_destroy (enableWindow); - enableWindow = 0; + enableWindow = null; } } else { - int /*long*/ parentHandle = shellHandle; + auto parentHandle = shellHandle; OS.gtk_widget_realize (parentHandle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (parentHandle); + auto window = OS.GTK_WIDGET_WINDOW (parentHandle); Rectangle rect = getBounds (); - GdkWindowAttr attributes = new GdkWindowAttr (); + GdkWindowAttr* attributes = new GdkWindowAttr (); attributes.width = rect.width; attributes.height = rect.height; attributes.event_mask = (0xFFFFFFFF & ~OS.ExposureMask); attributes.wclass = OS.GDK_INPUT_ONLY; attributes.window_type = OS.GDK_WINDOW_CHILD; enableWindow = OS.gdk_window_new (window, attributes, 0); - if (enableWindow != 0) { - if (cursor != null) { + if (enableWindow !is null) { + if (cursor !is null) { OS.gdk_window_set_cursor (enableWindow, cursor.handle); if (!OS.GDK_WINDOWING_X11 ()) { OS.gdk_flush (); } else { - int /*long*/ xDisplay = OS.GDK_DISPLAY (); + auto xDisplay = OS.GDK_DISPLAY (); OS.XFlush (xDisplay); } } @@ -1295,8 +1300,8 @@ OS.gdk_window_show (enableWindow); } } - if (fixFocus) fixFocus (control); - if (enabled && display.activeShell == this) { + if (fixFocus_) fixFocus (control); + if (enabled && display.activeShell is this) { if (!restoreFocus ()) traverseGroup (false); } } @@ -1322,43 +1327,43 @@ } void setInitialBounds () { - if ((state & FOREIGN_HANDLE) != 0) return; - Monitor monitor = getMonitor (); + if ((state & FOREIGN_HANDLE) !is 0) return; + dwt.widgets.Monitor.Monitor monitor = getMonitor (); Rectangle rect = monitor.getClientArea (); int width = rect.width * 5 / 8; int height = rect.height * 5 / 8; - if ((style & SWT.RESIZE) != 0) { - OS.gtk_window_resize (shellHandle, width, height); + if ((style & SWT.RESIZE) !is 0) { + OS.gtk_window_resize (cast(GtkWindow*)shellHandle, width, height); } resizeBounds (width, height, false); } -public void setMaximized (boolean maximized) { +public void setMaximized (bool maximized) { checkWidget(); super.setMaximized (maximized); if (maximized) { - OS.gtk_window_maximize (shellHandle); + OS.gtk_window_maximize (cast(GtkWindow*)shellHandle); } else { - OS.gtk_window_unmaximize (shellHandle); + OS.gtk_window_unmaximize (cast(GtkWindow*)shellHandle); } } public void setMenuBar (Menu menu) { checkWidget(); - if (menuBar == menu) return; - boolean both = menu != null && menuBar != null; - if (menu != null) { - if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR); - if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT); + if (menuBar is menu) return; + bool both = menu !is null && menuBar !is null; + if (menu !is null) { + if ((menu.style & SWT.BAR) is 0) error (SWT.ERROR_MENU_NOT_BAR); + if (menu.parent !is this) error (SWT.ERROR_INVALID_PARENT); } - if (menuBar != null) { - int /*long*/ menuHandle = menuBar.handle; + if (menuBar !is null) { + auto menuHandle = menuBar.handle; OS.gtk_widget_hide (menuHandle); destroyAccelGroup (); } menuBar = menu; - if (menuBar != null) { - int /*long*/ menuHandle = menu.handle; + if (menuBar !is null) { + auto menuHandle = menu.handle; OS.gtk_widget_show (menuHandle); createAccelGroup (); menuBar.addAccelerators (accelGroup); @@ -1368,14 +1373,14 @@ resizeBounds (width, height, !both); } -public void setMinimized (boolean minimized) { +public void setMinimized (bool minimized) { checkWidget(); - if (this.minimized == minimized) return; + if (this.minimized is minimized) return; super.setMinimized (minimized); if (minimized) { - OS.gtk_window_iconify (shellHandle); + OS.gtk_window_iconify (cast(GtkWindow*)shellHandle); } else { - OS.gtk_window_deiconify (shellHandle); + OS.gtk_window_deiconify (cast(GtkWindow*)shellHandle); bringToTop (false); } } @@ -1397,10 +1402,10 @@ */ public void setMinimumSize (int width, int height) { checkWidget (); - GdkGeometry geometry = new GdkGeometry (); + GdkGeometry* geometry = new GdkGeometry (); minWidth = geometry.min_width = Math.max (width, trimWidth ()) - trimWidth (); minHeight = geometry.min_height = Math.max (height, trimHeight ()) - trimHeight (); - OS.gtk_window_set_geometry_hints (shellHandle, 0, geometry, OS.GDK_HINT_MIN_SIZE); + OS.gtk_window_set_geometry_hints (cast(GtkWindow*)shellHandle, null, geometry, OS.GDK_HINT_MIN_SIZE); } /** @@ -1422,7 +1427,7 @@ */ public void setMinimumSize (Point size) { checkWidget (); - if (size == null) error (SWT.ERROR_NULL_ARGUMENT); + if (size is null) error (SWT.ERROR_NULL_ARGUMENT); setMinimumSize (size.x, size.y); } @@ -1448,10 +1453,10 @@ */ public void setRegion (Region region) { checkWidget (); - if ((style & SWT.NO_TRIM) == 0) return; - if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - int /*long*/ shape_region = (region == null) ? 0 : region.handle; + if ((style & SWT.NO_TRIM) is 0) return; + if (region !is null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); + auto window = OS.GTK_WIDGET_WINDOW (shellHandle); + auto shape_region = (region is null) ? null : region.handle; OS.gdk_window_shape_combine_region (window, shape_region, 0, 0); this.region = region; } @@ -1462,7 +1467,7 @@ void setRelations() { } -public void setText (String string) { +public void setText (char[] string) { super.setText (string); /* @@ -1472,17 +1477,16 @@ * garbage after the last character in the title. * The fix is to pad the title. */ - int length = string.length (); - char [] chars = new char [Math.max (6, length) + 1]; - string.getChars (0, length , chars, 0); - for (int i=length; i<chars.length; i++) chars [i] = ' '; - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_window_set_title (shellHandle, buffer); + int length_ = string.length; + char [] chars = new char [Math.max (6, length_) + 1]; + chars = string[ 0 .. length_]; + for (int i=length_; i<chars.length; i++) chars [i] = ' '; + OS.gtk_window_set_title (cast(GtkWindow*)shellHandle, toStringz( chars ) ); } -public void setVisible (boolean visible) { +public void setVisible (bool visible) { checkWidget(); - if ((OS.GTK_WIDGET_MAPPED (shellHandle) == visible)) return; + if ((OS.GTK_WIDGET_MAPPED (shellHandle) is visible)) return; if (visible) { sendEvent (SWT.Show); if (isDisposed ()) return; @@ -1502,22 +1506,22 @@ if (!OS.GTK_IS_PLUG (shellHandle)) { mapped = false; if (isDisposed ()) return; - display.dispatchEvents = new int [] { + display.dispatchEvents = [ OS.GDK_EXPOSE, OS.GDK_FOCUS_CHANGE, OS.GDK_CONFIGURE, OS.GDK_MAP, OS.GDK_UNMAP, - OS.GDK_NO_EXPOSE, - }; + OS.GDK_NO_EXPOSE + ]; Display display = this.display; display.putGdkEvents(); - boolean iconic = false; - Shell shell = parent != null ? parent.getShell() : null; + bool iconic = false; + Shell shell = parent !is null ? parent.getShell() : null; do { - OS.g_main_context_iteration (0, false); + OS.g_main_context_iteration (null, false); if (isDisposed ()) break; - iconic = minimized || (shell != null && shell.minimized); + iconic = minimized || (shell !is null && shell.minimized); } while (!mapped && !iconic); display.dispatchEvents = null; if (isDisposed ()) return; @@ -1530,7 +1534,7 @@ mapped = true; int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL; - if ((style & mask) != 0) { + if ((style & mask) !is 0) { OS.gdk_pointer_ungrab (OS.GDK_CURRENT_TIME); } opened = true; @@ -1549,7 +1553,7 @@ oldHeight = size.y - trimHeight (); sendEvent (SWT.Resize); if (isDisposed ()) return; - if (layout != null) { + if (layout_ !is null) { markLayout (false, false); updateLayout (false); } @@ -1561,7 +1565,8 @@ } } -void setZOrder (Control sibling, boolean above, boolean fixRelations) { +alias Decorations.setZOrder setZOrder; +void setZOrder (Control sibling, bool above, bool fixRelations) { /* * Bug in GTK+. Changing the toplevel window Z-order causes * X to send a resize event. Before the shell is mapped, these @@ -1573,60 +1578,60 @@ if (mapped) setZOrder (sibling, above, false, false); } -int /*long*/ shellMapProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { +override int /*long*/ shellMapProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { mapped = true; display.dispatchEvents = null; return 0; } void showWidget () { - if ((state & FOREIGN_HANDLE) != 0) return; - OS.gtk_container_add (shellHandle, vboxHandle); - if (scrolledHandle != 0) OS.gtk_widget_show (scrolledHandle); - if (handle != 0) OS.gtk_widget_show (handle); - if (vboxHandle != 0) OS.gtk_widget_show (vboxHandle); + if ((state & FOREIGN_HANDLE) !is 0) return; + OS.gtk_container_add (cast(GtkContainer*)shellHandle, vboxHandle); + if (scrolledHandle !is null) OS.gtk_widget_show (scrolledHandle); + if (handle !is null) OS.gtk_widget_show (handle); + if (vboxHandle !is null) OS.gtk_widget_show (vboxHandle); } -int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { +override int /*long*/ sizeAllocateProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { int offset = 16; - int [] x = new int [1], y = new int [1]; - OS.gdk_window_get_pointer (0, x, y, null); - y [0] += offset; - int /*long*/ screen = OS.gdk_screen_get_default (); - if (screen != 0) { - int monitorNumber = OS.gdk_screen_get_monitor_at_point (screen, x[0], y[0]); - GdkRectangle dest = new GdkRectangle (); + int x, y; + OS.gdk_window_get_pointer (null, &x, &y, null); + y += offset; + auto screen = OS.gdk_screen_get_default (); + if (screen !is null) { + int monitorNumber = OS.gdk_screen_get_monitor_at_point (screen, x, y); + GdkRectangle* dest = new GdkRectangle (); OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest); int width = OS.GTK_WIDGET_WIDTH (handle); int height = OS.GTK_WIDGET_HEIGHT (handle); - if (x[0] + width > dest.x + dest.width) { - x [0] = (dest.x + dest.width) - width; + if (x + width > dest.x + dest.width) { + x = (dest.x + dest.width) - width; } - if (y[0] + height > dest.y + dest.height) { - y[0] = (dest.y + dest.height) - height; + if (y + height > dest.y + dest.height) { + y = (dest.y + dest.height) - height; } } - OS.gtk_window_move (handle, x [0], y [0]); + OS.gtk_window_move (cast(GtkWindow*)handle, x, y); return 0; } -int /*long*/ sizeRequestProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { +override int /*long*/ sizeRequestProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { OS.gtk_widget_hide (handle); return 0; } -boolean traverseEscape () { - if (parent == null) return false; +bool traverseEscape () { + if (parent is null) return false; if (!isVisible () || !isEnabled ()) return false; close (); return true; } int trimHeight () { - if ((style & SWT.NO_TRIM) != 0) return 0; - boolean hasTitle = false, hasResize = false, hasBorder = false; - hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; - hasResize = (style & SWT.RESIZE) != 0; - hasBorder = (style & SWT.BORDER) != 0; + if ((style & SWT.NO_TRIM) !is 0) return 0; + bool hasTitle = false, hasResize = false, hasBorder = false; + hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) !is 0; + hasResize = (style & SWT.RESIZE) !is 0; + hasBorder = (style & SWT.BORDER) !is 0; if (hasTitle) { if (hasResize) return display.titleResizeTrimHeight; if (hasBorder) return display.titleBorderTrimHeight; @@ -1638,11 +1643,11 @@ } int trimWidth () { - if ((style & SWT.NO_TRIM) != 0) return 0; - boolean hasTitle = false, hasResize = false, hasBorder = false; - hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; - hasResize = (style & SWT.RESIZE) != 0; - hasBorder = (style & SWT.BORDER) != 0; + if ((style & SWT.NO_TRIM) !is 0) return 0; + bool hasTitle = false, hasResize = false, hasBorder = false; + hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) !is 0; + hasResize = (style & SWT.RESIZE) !is 0; + hasBorder = (style & SWT.BORDER) !is 0; if (hasTitle) { if (hasResize) return display.titleResizeTrimWidth; if (hasBorder) return display.titleBorderTrimWidth; @@ -1697,27 +1702,27 @@ public Rectangle getBounds () { checkWidget (); - int [] x = new int [1], y = new int [1]; - OS.gtk_window_get_position (shellHandle, x, y); + int x, y ; + OS.gtk_window_get_position (cast(GtkWindow*)shellHandle, &x, &y); int width = OS.GTK_WIDGET_WIDTH (vboxHandle); int height = OS.GTK_WIDGET_HEIGHT (vboxHandle); int border = 0; - if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { - border = OS.gtk_container_get_border_width (shellHandle); + if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) is 0) { + border = OS.gtk_container_get_border_width (cast(GtkContainer*)shellHandle); } - return new Rectangle (x [0], y [0], width + trimWidth () + 2*border, height + trimHeight () + 2*border); + return new Rectangle (x, y, width + trimWidth () + 2*border, height + trimHeight () + 2*border); } void releaseHandle () { super.releaseHandle (); - shellHandle = 0; + shellHandle = null; } -void releaseChildren (boolean destroy) { +void releaseChildren (bool destroy) { Shell [] shells = getShells (); for (int i=0; i<shells.length; i++) { Shell shell = shells [i]; - if (shell != null && !shell.isDisposed ()) { + if (shell !is null && !shell.isDisposed ()) { shell.release (false); } } @@ -1727,25 +1732,24 @@ void releaseWidget () { super.releaseWidget (); destroyAccelGroup (); - if (display.activeShell == this) display.activeShell = null; - if (tooltipsHandle != 0) OS.g_object_unref (tooltipsHandle); - tooltipsHandle = 0; - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - OS.gdk_window_remove_filter(window, display.filterProc, shellHandle); + if (display.activeShell is this) display.activeShell = null; + if (tooltipsHandle !is null) OS.g_object_unref (tooltipsHandle); + tooltipsHandle = null; + auto window = OS.GTK_WIDGET_WINDOW (shellHandle); + display.doWindowRemoveFilter( &filterProcCallbackData, window, shellHandle ); region = null; lastActive = null; } -void setToolTipText (int /*long*/ widget, String string) { - byte [] buffer = null; - if (string != null && string.length () > 0) { - buffer = Converter.wcsToMbcs (null, string, true); - } - if (tooltipsHandle == 0) { - tooltipsHandle = OS.gtk_tooltips_new (); - if (tooltipsHandle == 0) error (SWT.ERROR_NO_HANDLES); +void setToolTipText (GtkWidget* widget, char[] string) { +//PORTING_LEFT +/+ + char* 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 (tooltipsHandle); - OS.gtk_object_sink (tooltipsHandle); + OS.gtk_object_sink (cast(GtkObject*)tooltipsHandle); } /* @@ -1757,11 +1761,11 @@ * 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.VERSION (2, 2, 1)) { - OS.gtk_tooltips_force_window (tooltipsHandle); + if (OS.GTK_VERSION >= OS.buildVERSION (2, 2, 1)) { + OS.gtk_tooltips_force_window (cast(GtkTooltips*)tooltipsHandle); } - int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (tooltipsHandle); - if (tipWindow != 0 && tipWindow != tooltipWindow) { + auto tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (cast(GtkTooltips*)tooltipsHandle); + if (tipWindow !is null && tipWindow !is tooltipWindow) { OS.g_signal_connect (tipWindow, OS.size_allocate, display.sizeAllocateProc, shellHandle); tooltipWindow = tipWindow; } @@ -1772,15 +1776,15 @@ * is not displayed until the mouse re-enters the window. The * fix is force the new tooltip to be active. */ - boolean set = true; - if (tipWindow != 0) { - if ((OS.GTK_WIDGET_FLAGS (widget) & (OS.GTK_REALIZED | OS.GTK_VISIBLE)) != 0) { + bool set = true; + if (tipWindow !is null) { + if ((OS.GTK_WIDGET_FLAGS (widget) & (OS.GTK_REALIZED | OS.GTK_VISIBLE)) !is 0) { int [] x = new int [1], y = new int [1]; - int /*long*/ window = OS.gdk_window_at_pointer (x, y); - if (window != 0) { - int /*long*/ [] user_data = new int /*long*/ [1]; - OS.gdk_window_get_user_data (window, user_data); - if (widget == user_data [0]) { + auto window = OS.gdk_window_at_pointer (x, y); + if (window !is null) { + GtkWidget* user_data; + OS.gdk_window_get_user_data (window, &user_data); + if (widget is user_data) { /* * Feature in GTK. Calling gtk_tooltips_set_tip() positions and * shows the tooltip. If the tooltip is already visible, moving @@ -1790,17 +1794,17 @@ */ set = false; int handler_id = OS.g_signal_connect (tipWindow, OS.size_request, display.sizeRequestProc, shellHandle); - OS.gtk_tooltips_set_tip (tooltipsHandle, widget, buffer, null); + OS.gtk_tooltips_set_tip (cast(GtkTooltips*)tooltipsHandle, widget, buffer, null); OS.gtk_widget_hide (tipWindow); - int /*long*/ data = OS.gtk_tooltips_data_get (widget); + auto data = OS.gtk_tooltips_data_get (cast(GtkTooltips*)widget); OS.GTK_TOOLTIPS_SET_ACTIVE (tooltipsHandle, data); - OS.gtk_tooltips_set_tip (tooltipsHandle, widget, buffer, null); - if (handler_id != 0) OS.g_signal_handler_disconnect (tipWindow, handler_id); + OS.gtk_tooltips_set_tip (cast(GtkTooltips*)tooltipsHandle, widget, buffer, null); + if (handler_id !is 0) OS.g_signal_handler_disconnect (tipWindow, handler_id); } } } } - if (set) OS.gtk_tooltips_set_tip (tooltipsHandle, widget, buffer, null); + if (set) OS.gtk_tooltips_set_tip (cast(GtkTooltips*)tooltipsHandle, widget, buffer, null); + +/ } } -++/ \ No newline at end of file
--- a/dwt/widgets/Widget.d Wed Jan 09 21:54:40 2008 -0800 +++ b/dwt/widgets/Widget.d Thu Jan 10 07:34:05 2008 +0100 @@ -575,11 +575,11 @@ return 0; } -int /*long*/ gtk_button_press_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) { return 0; } -int /*long*/ gtk_button_release_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_button_release_event (GtkWidget* widget, GdkEventButton* event) { return 0; } @@ -595,7 +595,7 @@ return 0; } -int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ text) { +int /*long*/ gtk_commit (GtkIMContext* imcontext, char* text) { return 0; } @@ -619,15 +619,15 @@ return 0; } -int /*long*/ gtk_enter_notify_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_enter_notify_event (GtkWidget* widget, GdkEventCrossing* event) { return 0; } -int /*long*/ gtk_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_event (GtkWidget* widget, GdkEvent* event) { return 0; } -int /*long*/ gtk_event_after (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_event_after (GtkWidget* widget, GdkEvent* event) { return 0; } @@ -635,19 +635,19 @@ return 0; } -int /*long*/ gtk_expose_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_expose_event (GtkWidget* widget, GdkEventExpose* event) { return 0; } -int /*long*/ gtk_focus (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_focus (GtkWidget* widget, int directionType) { return 0; } -int /*long*/ gtk_focus_in_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_focus_in_event (GtkWidget* widget, GdkEventFocus* event) { return 0; } -int /*long*/ gtk_focus_out_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_focus_out_event (GtkWidget* widget, GdkEventFocus* event) { return 0; } @@ -675,7 +675,7 @@ return sendKeyEvent (SWT.KeyUp, event) ? 0 : 1; } -int /*long*/ gtk_leave_notify_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_leave_notify_event (GtkWidget* widget, GdkEventCrossing* event) { return 0; } @@ -695,11 +695,11 @@ return 0; } -int /*long*/ gtk_motion_notify_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_motion_notify_event (GtkWidget* widget, GdkEventMotion* event) { return 0; } -int /*long*/ gtk_move_focus (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_move_focus (GtkWidget* widget, int directionType) { return 0; } @@ -711,7 +711,7 @@ return 0; } -int /*long*/ gtk_preedit_changed (GtkWidget* imcontext) { +int /*long*/ gtk_preedit_changed (GtkIMContext* imcontext) { return 0; } @@ -727,7 +727,7 @@ return 0; } -int /*long*/ gtk_scroll_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_scroll_event (GtkWidget* widget, GdkEventScroll* event) { return 0; } @@ -791,11 +791,11 @@ return 0; } -int /*long*/ gtk_visibility_notify_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_visibility_notify_event (GtkWidget* widget, GdkEventVisibility* event) { return 0; } -int /*long*/ gtk_window_state_event (GtkWidget* widget, int /*long*/ event) { +int /*long*/ gtk_window_state_event (GtkWidget* widget, GdkEventWindowState* event) { return 0; } @@ -809,7 +809,7 @@ return OS.PANGO_PIXELS (ascent + descent); } -int filterProc (GdkXEvent* xEvent, GdkEvent* gdkEvent, void* data) { +int filterProc (XEvent* xEvent, GdkEvent* gdkEvent, void* data) { return 0; } @@ -1402,15 +1402,15 @@ void setOrientation () { } -int /*long*/ shellMapProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { +int /*long*/ shellMapProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { return 0; } -int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { +int /*long*/ sizeAllocateProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { return 0; } -int /*long*/ sizeRequestProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { +int /*long*/ sizeRequestProc (GtkWidget* handle, int /*long*/ arg0, int /*long*/ user_data) { return 0; } @@ -1457,7 +1457,7 @@ case MONTH_CHANGED: return gtk_month_changed (handle); case OUTPUT: return gtk_output (handle); case POPUP_MENU: return gtk_popup_menu (handle); - case PREEDIT_CHANGED: return gtk_preedit_changed (handle); + case PREEDIT_CHANGED: return gtk_preedit_changed (cast(GtkIMContext*)handle); case REALIZE: return gtk_realize (handle); case SELECT: return gtk_select (cast(int)handle); case SHOW: return gtk_show (handle); @@ -1483,34 +1483,34 @@ case MOTION_NOTIFY_EVENT_INVERSE: { return 1; } - case BUTTON_PRESS_EVENT: return gtk_button_press_event (handle, arg0); - case BUTTON_RELEASE_EVENT: return gtk_button_release_event (handle, arg0); - case COMMIT: return gtk_commit (cast(int)handle, arg0); + case BUTTON_PRESS_EVENT: return gtk_button_press_event (handle, cast(GdkEventButton*)arg0); + case BUTTON_RELEASE_EVENT: return gtk_button_release_event (handle, cast(GdkEventButton*)arg0); + case COMMIT: return gtk_commit (cast(GtkIMContext*)handle, cast(char*)arg0); case CONFIGURE_EVENT: return gtk_configure_event (handle, arg0); case DELETE_EVENT: return gtk_delete_event (handle, arg0); - 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 ENTER_NOTIFY_EVENT: return gtk_enter_notify_event (handle, cast(GdkEventCrossing*)arg0); + case EVENT: return gtk_event (handle, cast(GdkEvent*)arg0); + case EVENT_AFTER: return gtk_event_after (handle, cast(GdkEvent*)arg0); + case EXPOSE_EVENT: return gtk_expose_event (handle, cast(GdkEventExpose*)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); + case FOCUS_IN_EVENT: return gtk_focus_in_event (handle, cast(GdkEventFocus*)arg0); + case FOCUS_OUT_EVENT: return gtk_focus_out_event (handle, cast(GdkEventFocus*)arg0); case KEY_PRESS_EVENT: return gtk_key_press_event (handle, cast(GdkEventKey*)arg0); case KEY_RELEASE_EVENT: return gtk_key_release_event (handle, cast(GdkEventKey*)arg0); case INPUT: return gtk_input (handle, arg0); - case LEAVE_NOTIFY_EVENT: return gtk_leave_notify_event (handle, arg0); + case LEAVE_NOTIFY_EVENT: return gtk_leave_notify_event (handle, cast(GdkEventCrossing*)arg0); case MAP_EVENT: return gtk_map_event (handle, arg0); case MNEMONIC_ACTIVATE: return gtk_mnemonic_activate (handle, arg0); - case MOTION_NOTIFY_EVENT: return gtk_motion_notify_event (handle, arg0); + case MOTION_NOTIFY_EVENT: return gtk_motion_notify_event (handle, cast(GdkEventMotion*)arg0); case MOVE_FOCUS: return gtk_move_focus (handle, arg0); - case SCROLL_EVENT: return gtk_scroll_event (handle, arg0); + case SCROLL_EVENT: return gtk_scroll_event (handle, cast(GdkEventScroll*)arg0); case SHOW_HELP: return gtk_show_help (handle, arg0); case SIZE_ALLOCATE: return gtk_size_allocate (handle, arg0); case STYLE_SET: return gtk_style_set (handle, arg0); case TOGGLED: return gtk_toggled (cast(int)handle, arg0); case UNMAP_EVENT: return gtk_unmap_event (handle, arg0); - case VISIBILITY_NOTIFY_EVENT: return gtk_visibility_notify_event (handle, arg0); - case WINDOW_STATE_EVENT: return gtk_window_state_event (handle, arg0); + case VISIBILITY_NOTIFY_EVENT: return gtk_visibility_notify_event (handle, cast(GdkEventVisibility*)arg0); + case WINDOW_STATE_EVENT: return gtk_window_state_event (handle, cast(GdkEventWindowState*)arg0); default: return 0; } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/helloworld.d Thu Jan 10 07:34:05 2008 +0100 @@ -0,0 +1,21 @@ +module helloworld; + +import dwt.SWT; +import dwt.widgets.Display; +import dwt.widgets.Shell; + +void main(){ + Display display; + Shell shell; + + display = new Display(); + shell = new Shell(display); + shell.setText("Simple SWT Sample"); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } +} +
--- a/todo.txt Wed Jan 09 21:54:40 2008 -0800 +++ b/todo.txt Thu Jan 10 07:34:05 2008 +0100 @@ -1,6 +1,6 @@ Next Steps: * accessibility package (independant) - * Composite -> Canvas -> Decorations -> Shell + * Shell Questions: Whats needed at minimum to make a test with empty window? @@ -57,16 +57,16 @@ graphics/Transform // OK widgets/Button -widgets/Canvas +widgets/Canvas // OK widgets/Caret // widgets/ColorDialog widgets/Combo -widgets/Composite +widgets/Composite // OK widgets/Control // OK widgets/CoolBar widgets/CoolItem widgets/DateTime -widgets/Decorations +widgets/Decorations // OK widgets/Dialog widgets/DirectoryDialog widgets/Display // OK