diff dwt/widgets/Scrollable.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 cfa563df4fdd
line wrap: on
line diff
--- a/dwt/widgets/Scrollable.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/widgets/Scrollable.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.Scrollable;
 
@@ -23,7 +23,7 @@
 import dwt.internal.cocoa.NSSize;
 import dwt.internal.cocoa.NSView;
 import dwt.internal.cocoa.OS;
-import dwt.internal.cocoa.SWTScrollView;
+import dwt.internal.cocoa.SWTScroller;
 
 import dwt.dwthelper.utils;
 import dwt.widgets.Composite;
@@ -45,9 +45,11 @@
  * IMPORTANT: This class is intended to be subclassed <em>only</em>
  * within the DWT implementation.
  * </p>
+ *
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class Scrollable : Control {
-    SWTScrollView scrollView;
+    NSScrollView scrollView;
     ScrollBar horizontalBar, verticalBar;
     
 this () {
@@ -87,6 +89,12 @@
     super (parent, style);
 }
 
+bool accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) {
+    // Always ignore scrollers.
+    if (scrollView !is null && id is scrollView.id) return true;
+    return super.accessibilityIsIgnored(id, sel);   
+}
+
 /**
  * Given a desired <em>client area</em> for the receiver
  * (as described by the arguments), returns the bounding
@@ -139,16 +147,24 @@
     bar.display = display;
     NSScroller scroller;
     String actionSelector;
+    NSRect rect = new NSRect();
     if ((style & DWT.H_SCROLL) !is 0) {
-        scroller = scrollView.horizontalScroller();
+        rect.width = 1;
+    } else {
+        rect.height = 1;
+    }
+    scroller = (NSScroller)new SWTScroller().alloc();
+    scroller.initWithFrame(rect);
+    if ((style & DWT.H_SCROLL) !is 0) {
+        scrollView.setHorizontalScroller(scroller);
         actionSelector = OS.sel_sendHorizontalSelection;
     } else {
-        scroller = scrollView.verticalScroller();
+        scrollView.setVerticalScroller(scroller);
         actionSelector = OS.sel_sendVerticalSelection;
     }
     bar.view = scroller;
     //bar.createJNIRef();
-    scroller.setTag(bar.jniRef);
+    bar.register();
     if ((state & CANVAS) is 0) {
         bar.target = scroller.target();
         bar.actionSelector = scroller.action();
@@ -164,6 +180,11 @@
     if ((style & DWT.V_SCROLL) !is 0) verticalBar = createScrollBar (DWT.V_SCROLL);
 }
 
+void deregister () {
+    super.deregister ();
+    if (scrollView !is null) display.removeWidget (scrollView);
+}
+
 /**
  * Returns a rectangle which describes the area of the
  * receiver which is capable of displaying data (that is,
@@ -225,13 +246,23 @@
     return hooks (DWT.KeyDown) || hooks (DWT.KeyUp) || hooks (DWT.Traverse);
 }
 
+bool isTrim (NSView view) {
+    if (scrollView !is null) {
+        if (scrollView.id is view.id) return true;
+        if (horizontalBar !is null && horizontalBar.view.id is view.id) return true;
+        if (verticalBar !is null && verticalBar.view.id is view.id) return true;
+    }
+    return super.isTrim (view);
+}
+
+void register () {
+    super.register ();
+    if (scrollView !is null) display.addWidget (scrollView, this);
+}
 
 void releaseHandle () {
     super.releaseHandle ();
-    if (scrollView !is null)  {
-        scrollView.setTag(-1);
-        scrollView.release();
-    }
+    if (scrollView !is null) scrollView.release();
     scrollView = null;
 }
 
@@ -247,51 +278,10 @@
     super.releaseChildren (destroy);
 }
 
-void resizeClientArea () {
-//  if (scrolledHandle is 0) return;
-//  if ((state & CANVAS) is 0) return;
-//  int vWidth = 0, hHeight = 0;
-//  int [] outMetric = new int [1];
-//  OS.GetThemeMetric (OS.kThemeMetricScrollBarWidth, outMetric);
-//  bool isVisibleHBar = horizontalBar !is null && horizontalBar.getVisible ();
-//  bool isVisibleVBar = verticalBar !is null && verticalBar.getVisible ();
-//  if (isVisibleHBar) hHeight = outMetric [0];
-//  if (isVisibleVBar) vWidth = outMetric [0];
-//  int width, height;
-//  CGRect rect = new CGRect (); 
-//  OS.HIViewGetBounds (scrolledHandle, rect);
-//  width = cast(int) rect.width;
-//  height = cast(int) rect.height;
-//  Rect inset = inset ();
-//  width = Math.max (0, width - vWidth - inset.left - inset.right);
-//  height = Math.max (0, height - hHeight - inset.top - inset.bottom);
-//  setBounds (handle, inset.left, inset.top, width, height, true, true, false);
-//  if (isVisibleHBar) {
-//      setBounds (horizontalBar.handle, inset.left, inset.top + height, width, hHeight, true, true, false);
-//  }
-//  if (isVisibleVBar) {
-//      setBounds (verticalBar.handle, inset.left + width, inset.top, vWidth, height, true, true, false);
-//  }
-}
-
 void sendHorizontalSelection () {
     horizontalBar.sendSelection ();
 }
 
-bool sendMouseWheel (short wheelAxis, int wheelDelta) {
-//  if ((state & CANVAS) !is 0) {
-//      ScrollBar bar = wheelAxis is OS.kEventMouseWheelAxisX ? horizontalBar : verticalBar;
-//      if (bar !is null && bar.getEnabled ()) {
-//          bar.setSelection (Math.max (0, bar.getSelection () - bar.getIncrement () * wheelDelta));
-//          Event event = new Event ();
-//          event.detail = wheelDelta > 0 ? DWT.PAGE_UP : DWT.PAGE_DOWN;    
-//          bar.sendEvent (DWT.Selection, event);
-//          return true;
-//      }
-//  }
-    return false;
-}
-
 void sendVerticalSelection () {
     verticalBar.sendSelection ();
 }
@@ -306,13 +296,21 @@
         if ((bar.state & HIDDEN) !is 0) return false;
         bar.state |= HIDDEN;
     }
-    resizeClientArea ();
-//  setVisible (bar.handle, visible);
+    if ((bar.style & DWT.HORIZONTAL) !is 0) {
+        scrollView.setHasHorizontalScroller (visible);
+    } else {
+        scrollView.setHasVerticalScroller (visible);
+    }
     bar.sendEvent (visible ? DWT.Show : DWT.Hide);
     sendEvent (DWT.Resize);
     return true;
 }
 
+void setZOrder () {
+    super.setZOrder ();
+    if (scrollView !is null) scrollView.setDocumentView (view);
+}
+
 NSView topView () {
     if (scrollView !is null) return scrollView;
     return super.topView ();