Mercurial > projects > dwt-mac
diff dwt/widgets/Canvas.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/Canvas.d Tue Oct 21 15:20:04 2008 +0200 +++ b/dwt/widgets/Canvas.d Mon Dec 01 17:07:00 2008 +0100 @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 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.Canvas; @@ -22,8 +22,11 @@ import dwt.graphics.Rectangle; import dwt.internal.cocoa.NSBezierPath; import dwt.internal.cocoa.NSColor; +import dwt.internal.cocoa.NSCursor; +import dwt.internal.cocoa.NSEvent; import dwt.internal.cocoa.NSGraphicsContext; import dwt.internal.cocoa.NSPoint; +import dwt.internal.cocoa.NSRange; import dwt.internal.cocoa.NSRect; import dwt.internal.cocoa.NSSize; import dwt.internal.cocoa.OS; @@ -53,6 +56,9 @@ * </p> * * @see Composite + * @see <a href="http://www.eclipse.org/swt/snippets/#canvas">Canvas snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class Canvas : Composite { Caret caret; @@ -62,14 +68,19 @@ /* Do nothing */ } -bool becomeFirstResponder () { - if (caret !is null) caret.setFocus (); - return super.becomeFirstResponder(); +int /*long*/ attributedSubstringFromRange (int /*long*/ id, int /*long*/ sel, int /*long*/ range) { + if (ime !is null) return ime.attributedSubstringFromRange (id, sel, range); + return super.attributedSubstringFromRange(id, sel, range); } -bool resignFirstResponder () { +bool becomeFirstResponder (int /*long*/ id, int /*long*/ sel) { + if (caret !is null) caret.setFocus (); + return super.becomeFirstResponder(id, sel); +} + +bool resignFirstResponder (int /*long*/ id, int /*long*/ sel) { if (caret !is null) caret.killFocus (); - return super.resignFirstResponder(); + return super.resignFirstResponder(id, sel); } @@ -104,6 +115,11 @@ super (parent, style); } +int /*long*/ characterIndexForPoint (int /*long*/ id, int /*long*/ sel, int /*long*/ point) { + if (ime !is null) return ime.characterIndexForPoint (id, sel, point); + return super.characterIndexForPoint (id, sel, point); +} + /** * Fills the interior of the rectangle specified by the arguments, * with the receiver's background. @@ -131,14 +147,19 @@ if (gc.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); Control control = findBackgroundControl (); if (control !is null) { -// control.fillBackground (handle, gc.handle, new Rectangle (x, y, width, height)); + NSRect rect = new NSRect(); + rect.x = x; + rect.y = y; + rect.width = width; + rect.height = height; + control.fillBackground (view, gc.handle, rect); } else { gc.fillRectangle (x, y, width, height); } } -void drawRect(objc.id id, NSRect rect) { - super.drawRect(id, rect); +void drawWidget (objc.id id_, NSRect rect) { + super.drawWidget (id, rect); if (caret is null) return; if (caret.isShowing) { NSGraphicsContext context = NSGraphicsContext.currentContext(); @@ -170,6 +191,11 @@ } } +NSRect firstRectForCharacterRange (int /*long*/ id, int /*long*/ sel, int /*long*/ range) { + if (ime !is null) return ime.firstRectForCharacterRange (id, sel, range); + return super.firstRectForCharacterRange (id, sel, range); +} + /** * Returns the caret. * <p> @@ -181,7 +207,7 @@ * drawing in the window any other time. * </p> * - * @return the caret + * @return the caret for the receiver, may be null * * @exception DWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> @@ -193,11 +219,40 @@ return caret; } +/** + * Returns the IME. + * + * @return the IME + * + * @exception DWTException <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.4 + */ public IME getIME () { checkWidget(); return ime; } +bool hasMarkedText (int /*long*/ id, int /*long*/ sel) { + if (ime !is null) return ime.hasMarkedText (id, sel); + return super.hasMarkedText (id, sel); +} + +bool insertText (int /*long*/ id, int /*long*/ sel, int /*long*/ string) { + if (ime !is null) { + if (!ime.insertText (id, sel, string)) return false; + } + return super.insertText (id, sel, string); +} + +NSRange markedRange (int /*long*/ id, int /*long*/ sel) { + if (ime !is null) return ime.markedRange (id, sel); + return super.markedRange (id, sel); +} + //void redrawWidget (int control, bool children) { // bool isFocus = OS.VERSION < 0x1040 && caret !is null && caret.isFocusCaret (); // if (isFocus) caret.killFocus (); @@ -291,6 +346,16 @@ if (isFocus) caret.setFocus (); } +NSRange selectedRange (int /*long*/ id, int /*long*/ sel) { + if (ime !is null) return ime.selectedRange (id, sel); + return super.selectedRange (id, sel); +} + +bool sendKeyEvent (NSEvent nsEvent, int type) { + if (caret !is null) NSCursor.setHiddenUntilMouseMoves (true); + return super.sendKeyEvent (nsEvent, type); +} + /** * Sets the receiver's caret. * <p> @@ -331,10 +396,37 @@ super.setFont (font); } +/** + * Sets the receiver's IME. + * + * @param ime the new IME for the receiver, may be null + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the IME has been disposed</li> + * </ul> + * @exception DWTException <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.4 + */ public void setIME (IME ime) { checkWidget (); if (ime !is null && ime.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT); this.ime = ime; } +bool setMarkedText_selectedRange (int /*long*/ id, int /*long*/ sel, int /*long*/ string, int /*long*/ range) { + if (ime !is null) { + if (!ime.setMarkedText_selectedRange (id, sel, string, range)) return false; + } + return super.setMarkedText_selectedRange (id, sel, string, range); } + +int /*long*/ validAttributesForMarkedText (int /*long*/ id, int /*long*/ sel) { + if (ime !is null) return ime.validAttributesForMarkedText (id, sel); + return super.validAttributesForMarkedText(id, sel); +} + +}