view dwt/internal/cocoa/NSTrackingArea.d @ 13:f565d3a95c0a

Ported dwt.internal
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Fri, 22 Aug 2008 16:46:34 +0200
parents 8b48be5454ce
children
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 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
 *     
 * Port to the D programming language:
 *     Jacob Carlborg <jacob.carlborg@gmail.com>
 *******************************************************************************/
module dwt.internal.cocoa.NSTrackingArea;

import dwt.internal.cocoa.id;
import dwt.internal.cocoa.NSDictionary;
import dwt.internal.cocoa.NSInteger;
import dwt.internal.cocoa.NSObject;
import dwt.internal.cocoa.NSRect;
import dwt.internal.cocoa.OS;
import objc = dwt.internal.objc.runtime;

/* Type of tracking area.  You must specify one or more type from this list in the NSTrackingAreaOptions argument of -initWithRect:options:owner:userInfo: */
enum : NSUInteger
{
    NSTrackingMouseEnteredAndExited = 0x01, // owner receives mouseEntered when mouse enters area, and mouseExited when mouse leaves area
    NSTrackingMouseMoved = 0x02, // owner receives mouseMoved while mouse is within area.  Note that mouseMoved events do not contain userInfo 
    NSTrackingCursorUpdate = 0x04, // owner receives cursorUpdate when mouse enters area.  Cursor is set appropriately when mouse exits area
}

/* When tracking area is active.  You must specify one of the following in the NSTrackingAreaOptions argument of -initWithRect:options:owner:userInfo: */
enum : NSUInteger
{
    NSTrackingActiveWhenFirstResponder = 0x10, // owner receives mouseEntered/Exited, mouseMoved, or cursorUpdate when view is first responder
    NSTrackingActiveInKeyWindow = 0x20, // owner receives mouseEntered/Exited, mouseMoved, or cursorUpdate when view is in key window
    NSTrackingActiveInActiveApp = 0x40, // owner receives mouseEntered/Exited, mouseMoved, or cursorUpdate when app is active
    NSTrackingActiveAlways = 0x80, // owner receives mouseEntered/Exited or mouseMoved regardless of activation.  Not supported for NSTrackingCursorUpdate.
}

/* Behavior of tracking area.  These values are used in NSTrackingAreaOptions.  You may specify any number of the following in the NSTrackingAreaOptions argument of -initWithRect:options:owner:userInfo: */
enum : NSUInteger
{
    NSTrackingAssumeInside = 0x100, // If set, generate mouseExited event when mouse leaves area (same as assumeInside argument in deprecated addtrackingArea:owner:userData:assumeInside:)
    NSTrackingInVisibleRect = 0x200, // If set, tracking occurs in visibleRect of view and rect is ignored
    NSTrackingEnabledDuringMouseDrag = 0x400 // If set, mouseEntered events will be generated as mouse is dragged.  If not set, mouseEntered events will be generated as mouse is moved, and on mouseUp after a drag.  mouseExited events are paired with mouseEntered events so their delivery is affected indirectly.  That is, if a mouseEntered event is generated and the mouse subsequently moves out of the trackingArea, a mouseExited event will be generated whether the mouse is being moved or dragged, independent of this flag.
}

alias NSUInteger NSTrackingAreaOptions;

public class NSTrackingArea : NSObject
{

    public this ()
    {
        super();
    }

    public this (objc.id id)
    {
        super(id);
    }

    public NSTrackingArea initWithRect (NSRect rect, NSTrackingAreaOptions options, id owner, NSDictionary userInfo)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithRect_1options_1owner_1userInfo_1, rect, options, owner !is null ? owner.id_ : null,
                userInfo !is null ? userInfo.id_ : null);
        return result is this.id_ ? this : (result !is null ? new NSTrackingArea(result) : null);
    }

    public NSTrackingAreaOptions options ()
    {
        return cast(NSTrackingAreaOptions) OS.objc_msgSend(this.id_, OS.sel_options);
    }

    public id owner ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_owner);
        return result !is null ? new id(result) : null;
    }

    public NSRect rect ()
    {
        NSRect result;
        OS.objc_msgSend_stret(&result, this.id_, OS.sel_rect);
        return result;
    }

    public NSDictionary userInfo ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_userInfo);
        return result !is null ? new NSDictionary(result) : null;
    }

}