Mercurial > projects > dwt-mac
diff dwt/widgets/Composite.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 | 8615c76f10e4 |
line wrap: on
line diff
--- a/dwt/widgets/Composite.d Tue Oct 21 15:20:04 2008 +0200 +++ b/dwt/widgets/Composite.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,22 +9,26 @@ * 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.Composite; import dwt.DWT; import dwt.DWTException; +import dwt.accessibility.ACC; import dwt.graphics.Point; import dwt.graphics.Rectangle; import dwt.internal.cocoa.NSArray; import dwt.internal.cocoa.NSEvent; +import dwt.internal.cocoa.NSGraphicsContext; import dwt.internal.cocoa.NSRect; +import dwt.internal.cocoa.NSScrollView; import dwt.internal.cocoa.NSView; import dwt.internal.cocoa.OS; import dwt.internal.cocoa.SWTScrollView; import dwt.internal.cocoa.SWTView; +import dwt.internal.cocoa.id; import dwt.dwthelper.utils; import dwt.internal.cocoa.NSInteger; @@ -67,11 +71,12 @@ * </p> * * @see Canvas + * @see <a href="http://www.eclipse.org/swt/snippets/#composite">Composite snippets</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class Composite : Scrollable { Layout layout_; Control[] tabList; - int scrolledVisibleRgn, siblingsVisibleRgn; int layoutCount, backgroundMode; this () { @@ -114,18 +119,14 @@ Control [] _getChildren () { NSArray views = contentView().subviews(); - NSUInteger count = views.count(); + int count = cast(int)/*64*/views.count(); Control [] children = new Control [count]; + if (count is 0) return children; int j = 0; for (int i=0; i<count; i++){ - NSInteger tag = (new NSView(views.objectAtIndex(i))).tag(); - if (tag !is 0 && tag !is -1) { - Object widget = OS.JNIGetObject(tag); - if (widget !is null && widget !is this) { - if ( null !is cast(Control)widget ) { - children [j++] = cast(Control) widget; - } - } + Widget widget = display.getWidget (views.objectAtIndex (count - i - 1).id); + if (widget !is null && widget !is this && widget instanceof Control) { + children [j++] = cast(Control) widget; } } if (j is count) return children; @@ -152,13 +153,38 @@ return tabList; } -bool acceptsFirstResponder () { +bool acceptsFirstResponder (int /*long*/ id, int /*long*/ sel) { if ((state & CANVAS) !is 0) { return ((style & DWT.NO_FOCUS) is 0); } - return super.acceptsFirstResponder (); + return super.acceptsFirstResponder (id, sel); } +int accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) { + + if (id is view.id) { + if (accessible !is null) { + // If there is an accessible, it may provide its own list of attributes if it's a lightweight control. + // If not, let Cocoa handle it for this view. + id returnObject = accessible.internal_accessibilityAttributeNames(ACC.CHILDID_SELF); + if (returnObject !is null) return returnObject.id; + } + } + + return super.accessibilityAttributeNames(id, sel); +} + +bool accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) { + // If we have an accessible and it represents a valid accessible role, this view is not ignored. + if (view !is null && id is view.id) { + if (accessible !is null) { + id role = accessible.internal_accessibilityAttributeValue(OS.NSAccessibilityRoleAttribute, ACC.CHILDID_SELF); + if (role !is null) return false; + } + } + + return super.accessibilityIsIgnored(id, sel); +} /** * Clears any data that has been cached by a Layout for all widgets that @@ -250,40 +276,33 @@ return result; } -NSView contentView () { - return view; -} - void createHandle () { - createHandle (parent.contentView()); -} - -void createHandle (NSView parent) { state |= CANVAS; NSRect rect = NSRect(); if ((style & (DWT.V_SCROLL | DWT.H_SCROLL)) !is 0 || hasBorder ()) { - SWTScrollView scrollWidget = cast(SWTScrollView)(new SWTScrollView()).alloc(); + NSScrollView scrollWidget = cast(NSScrollView)(new SWTScrollView()).alloc(); scrollWidget.initWithFrame (rect); scrollWidget.setDrawsBackground(false); if ((style & DWT.H_SCROLL) !is 0) scrollWidget.setHasHorizontalScroller(true); if ((style & DWT.V_SCROLL) !is 0) scrollWidget.setHasVerticalScroller(true); scrollWidget.setBorderType(hasBorder() ? NSBezelBorder : NSNoBorder); - scrollWidget.setTag(jniRef); scrollView = scrollWidget; rect.width = rect.height = 100000; } - SWTView widget = cast(SWTView)(new SWTView()).alloc(); + NSView widget = cast(NSView)(new SWTView()).alloc(); widget.initWithFrame (rect); // widget.setFocusRingType(OS.NSFocusRingTypeExterior); - widget.setTag(jniRef); view = widget; - if (scrollView !is null) { -// view.setAutoresizingMask (OS.NSViewWidthSizable | OS.NSViewHeightSizable); - scrollView.setDocumentView(view); - if (parent !is null) parent.addSubview_(scrollView); - } else { - if (parent !is null) parent.addSubview_(view); +} + +void drawWidget (int /*long*/ id, NSRect rect) { + if ((state & CANVAS) !is 0) { + if ((style & DWT.NO_BACKGROUND) is 0) { + NSGraphicsContext context = NSGraphicsContext.currentContext(); + fillBackground (view, context, rect); + } } + super.drawWidget (id, rect); } Composite findDeferredControl () { @@ -492,11 +511,31 @@ return findDeferredControl () !is null; } +bool isOpaque (int /*long*/ id, int /*long*/ sel) { + if ((state & CANVAS) !is 0) { + if (id is view.id) { + if (region is null && background !is null && background.handle[3] is 1) { + return true; + } + } + } + return super.isOpaque (id, sel); +} + bool isTabGroup () { if ((state & CANVAS) !is 0) return true; return super.isTabGroup (); } +void keyDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { + if ((state & CANVAS) !is 0) { + NSArray array = NSArray.arrayWithObject (new NSEvent (theEvent)); + view.interpretKeyEvents (array); + return; + } + super.keyDown (id, sel, theEvent); +} + /** * If the receiver has a layout, asks the layout to <em>lay out</em> * (that is, set the size and location of) the receiver's children. @@ -694,6 +733,21 @@ return new Point (width, height); } +void pageDown(int /*long*/ id, int /*long*/ sel, int /*long*/ sender) { + if ((state & CANVAS) !is 0) return; + super.pageDown(id, sel, sender); +} + +void pageUp(int /*long*/ id, int /*long*/ sel, int /*long*/ sender) { + if ((state & CANVAS) !is 0) return; + super.pageUp(id, sel, sender); +} + +void reflectScrolledClipView (int /*long*/ id, int /*long*/ sel, int /*long*/ aClipView) { + if ((state & CANVAS) !is 0) return; + super.reflectScrolledClipView (id, sel, aClipView); +} + void releaseChildren (bool destroy) { Control [] children = _getChildren (); for (int i=0; i<children.length; i++) { @@ -715,6 +769,56 @@ fixTabList (control); } +void resized () { + super.resized (); + if (layout !is null) { + markLayout (false, false); + updateLayout (false); + } +} + +void scrollWheel (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { + if ((state & CANVAS) !is 0) { + NSView view = scrollView !is null ? scrollView : this.view; + if (id is view.id) { + NSEvent nsEvent = new NSEvent(theEvent); + float /*double*/ delta = nsEvent.deltaY(); + if (delta !is 0) { + if (hooks (DWT.MouseWheel) || filters (DWT.MouseWheel)) { + if (!sendMouseEvent(nsEvent, DWT.MouseWheel, true)) { + return; + } + } + } + bool handled = false; + ScrollBar bar = verticalBar; + if (delta !is 0 && bar !is null && bar.getEnabled ()) { + int selection = Math.max (0, (int)(0.5f + bar.getSelection () - bar.getIncrement () * delta)); + bar.setSelection (selection); + Event event = new Event (); + event.detail = delta > 0 ? DWT.PAGE_UP : DWT.PAGE_DOWN; + bar.sendEvent (DWT.Selection, event); + handled = true; + } + bar = horizontalBar; + delta = nsEvent.deltaX (); + if (delta !is 0 && bar !is null && bar.getEnabled ()) { + int selection = Math.max (0, (int)(0.5f + bar.getSelection () - bar.getIncrement () * delta)); + bar.setSelection (selection); + Event event = new Event (); + event.detail = delta > 0 ? DWT.PAGE_UP : DWT.PAGE_DOWN; + bar.sendEvent (DWT.Selection, event); + handled = true; + } + if (!handled) view.superview().scrollWheel(nsEvent); + return; + } + callSuper(id, sel, theEvent); + return; + } + super.scrollWheel (id, sel, theEvent); +} + /** * Sets the background drawing mode to the argument which should * be one of the following constants defined in class <code>DWT</code>: @@ -741,15 +845,6 @@ } } -int setBounds (int x, int y, int width, int height, bool move, bool resize) { - int result = super.setBounds (x, y, width, height, move, resize); - if (layout_ !is null && (result & RESIZED) !is 0) { - markLayout (false, false); - updateLayout (false); - } - return result; -} - public bool setFocus () { checkWidget (); Control [] children = _getChildren ();