diff dwt/widgets/TrayItem.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents 642f460a0908
children 6d9ec9ccdcdd
line wrap: on
line diff
--- a/dwt/widgets/TrayItem.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/widgets/TrayItem.d	Mon Dec 01 17:07:00 2008 +0100
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 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
@@ -9,7 +9,7 @@
  *     IBM Corporation - initial API and implementation
  *     
  * Port to the D programming language:
- *     Jacob Carlborg <jacob.carlborg@gmail.com>
+ *     Jacob Carlborg <doob@me.com>
  *******************************************************************************/
 module dwt.widgets.TrayItem;
 
@@ -21,6 +21,7 @@
 import dwt.events.SelectionListener;
 import dwt.graphics.Image;
 import dwt.graphics.Point;
+import dwt.internal.cocoa.NSControl;
 import dwt.internal.cocoa.NSEvent;
 import dwt.internal.cocoa.NSImageView;
 import dwt.internal.cocoa.NSPoint;
@@ -51,6 +52,9 @@
  * </p><p>
  * IMPORTANT: This class is <em>not</em> intended to be subclassed.
  * </p>
+ *
+ * @see <a href="http://www.eclipse.org/swt/snippets/#tray">Tray, TrayItem snippets</a>
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  * 
  * @since 3.0
  */
@@ -165,7 +169,7 @@
     if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS);
 }
 
-void createWidget () {
+void createHandle () {
     NSStatusBar statusBar = NSStatusBar.systemStatusBar();
     item = statusBar.statusItemWithLength(0);
     if (item is null) error (DWT.ERROR_NO_HANDLES);
@@ -176,8 +180,12 @@
     if (view is null) error (DWT.ERROR_NO_HANDLES);
     view.initWithFrame(rect);
     item.setView(view);
-    createJNIRef();
-    view.setTag(jniRef);
+}
+
+void deregister () {
+    super.deregister ();
+    display.removeWidget (view);
+    display.removeWidget(view.cell());
 }
 
 void destroyWidget () {
@@ -263,14 +271,17 @@
     return visible;
 }
 
+void register () {
+    super.register ();
+    display.addWidget (view, this);
+    display.addWidget (((NSControl)view).cell(), this);
+}
+
 void releaseHandle () {
     super.releaseHandle ();
     parent = null;
     if (item !is null) item.release();
-    if (view !is null) {
-        view.setTag(-1);
-        view.release();
-    }
+    if (view !is null) view.release();
     item = null;
     view = null;
 }
@@ -351,7 +362,7 @@
     if (image !is null && image.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT);
     super.setImage (image);
     view.setImage(image !is null ? image.handle : null);
-    float width = image !is null && visible ? image.handle.size().width + BORDER : 0;
+    float /*double*/ width = image !is null && visible ? image.handle.size().width + BORDER : 0;
     item.setLength(width);
 }
 
@@ -418,7 +429,7 @@
         if (isDisposed ()) return;
     }
     this.visible = visible;
-    float width = image !is null && visible ? image.handle.size().width + BORDER : 0;
+    float /*double*/ width = image !is null && visible ? image.handle.size().width + BORDER : 0;
     item.setLength(width);
     if (!visible) sendEvent (DWT.Hide);
 }
@@ -432,30 +443,28 @@
     _setToolTipText (toolTipText);
 }
 
-void mouseDown(objc.id event) {
+void mouseDown(objc.id id, objc.SEL sel, objc.id event) {
     NSEvent nsEvent = new NSEvent(event);
-    int mask = nsEvent.modifierFlags() & OS.NSDeviceIndependentModifierFlagsMask;
-    if (mask is OS.NSControlKeyMask) {
+    if ((nsEvent.modifierFlags() & OS.NSDeviceIndependentModifierFlagsMask) is OS.NSControlKeyMask) {
         showMenu();
     } else {
         highlight = true;
         (cast(NSView)view).setNeedsDisplay(true);
-        int clickCount = nsEvent.clickCount();
-        postEvent(clickCount is 2 ? DWT.DefaultSelection : DWT.Selection);
+        postEvent(nsEvent.clickCount() is 2 ? DWT.DefaultSelection : DWT.Selection);
     }
 }
 
-void mouseUp(int event) {
+void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
     highlight = false;
     (cast(NSView)view).setNeedsDisplay(true);
 }
 
-void rightMouseDown(int event) {
+void rightMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
     showMenu();
 }
 
-void drawRect(objc.id id, NSRect rect) {
+void drawRect(objc.id id, objc.SEL sel, NSRect rect) {
     item.drawStatusBarBackgroundInRect(rect, highlight);
-    super.drawRect(id, rect);
+    super.drawRect(id, sel, rect);
 }
 }