view dwt/internal/cocoa/NSEvent.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 d8635bb48c7c
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.NSEvent;

import dwt.internal.cocoa.CGEventTypes;
import dwt.internal.cocoa.CGFloat;
import dwt.internal.cocoa.id;
import dwt.internal.cocoa.IOLLEvent;
import dwt.internal.cocoa.NSDate : NSTimeInterval;
import dwt.internal.cocoa.NSGraphicsContext;
import dwt.internal.cocoa.NSInteger;
import dwt.internal.cocoa.NSObject;
import dwt.internal.cocoa.NSPoint;
import dwt.internal.cocoa.NSString;
import dwt.internal.cocoa.NSTrackingArea;
import dwt.internal.cocoa.NSWindow;
import dwt.internal.cocoa.OS;
import objc = dwt.internal.objc.runtime;

enum NSEventType
{
    NSLeftMouseDown = 1,
    NSLeftMouseUp = 2,
    NSRightMouseDown = 3,
    NSRightMouseUp = 4,
    NSMouseMoved = 5,
    NSLeftMouseDragged = 6,
    NSRightMouseDragged = 7,
    NSMouseEntered = 8,
    NSMouseExited = 9,
    NSKeyDown = 10,
    NSKeyUp = 11,
    NSFlagsChanged = 12,
    NSAppKitDefined = 13,
    NSSystemDefined = 14,
    NSApplicationDefined = 15,
    NSPeriodic = 16,
    NSCursorUpdate = 17,
    NSScrollWheel = 22,
    NSTabletPoint = 23,
    NSTabletProximity = 24,
    NSOtherMouseDown = 25,
    NSOtherMouseUp = 26,
    NSOtherMouseDragged = 27
}

alias NSEventType.NSLeftMouseDown NSLeftMouseDown;
alias NSEventType.NSLeftMouseUp NSLeftMouseUp;
alias NSEventType.NSRightMouseDown NSRightMouseDown;
alias NSEventType.NSRightMouseUp NSRightMouseUp;
alias NSEventType.NSMouseMoved NSMouseMoved;
alias NSEventType.NSLeftMouseDragged NSLeftMouseDragged;
alias NSEventType.NSRightMouseDragged NSRightMouseDragged;
alias NSEventType.NSMouseEntered NSMouseEntered;
alias NSEventType.NSMouseExited NSMouseExited;
alias NSEventType.NSKeyDown NSKeyDown;
alias NSEventType.NSKeyUp NSKeyUp;
alias NSEventType.NSFlagsChanged NSFlagsChanged;
alias NSEventType.NSAppKitDefined NSAppKitDefined;
alias NSEventType.NSSystemDefined NSSystemDefined;
alias NSEventType.NSApplicationDefined NSApplicationDefined;
alias NSEventType.NSPeriodic NSPeriodic;
alias NSEventType.NSCursorUpdate NSCursorUpdate;
alias NSEventType.NSScrollWheel NSScrollWheel;
alias NSEventType.NSTabletPoint NSTabletPoint;
alias NSEventType.NSTabletProximity NSTabletProximity;
alias NSEventType.NSOtherMouseDown NSOtherMouseDown;
alias NSEventType.NSOtherMouseUp NSOtherMouseUp;
alias NSEventType.NSOtherMouseDragged NSOtherMouseDragged;

enum NSPointingDeviceType
{
    NSUnknownPointingDevice = NX_TABLET_POINTER_UNKNOWN,
    NSPenPointingDevice = NX_TABLET_POINTER_PEN,
    NSCursorPointingDevice = NX_TABLET_POINTER_CURSOR,
    NSEraserPointingDevice = NX_TABLET_POINTER_ERASER
}

alias NSPointingDeviceType.NSUnknownPointingDevice NSUnknownPointingDevice;
alias NSPointingDeviceType.NSPenPointingDevice NSPenPointingDevice;
alias NSPointingDeviceType.NSCursorPointingDevice NSCursorPointingDevice;
alias NSPointingDeviceType.NSEraserPointingDevice NSEraserPointingDevice;

public class NSEvent : NSObject
{
    public this ()
    {
        super();
    }

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

    public CGEventRef CGEvent ()
    {
        return cast(CGEventRef) OS.objc_msgSend(this.id_, OS.sel_CGEvent);
    }

    public NSInteger absoluteX ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_absoluteX);
    }

    public NSInteger absoluteY ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_absoluteY);
    }

    public NSInteger absoluteZ ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_absoluteZ);
    }

    public NSUInteger buttonMask ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_buttonMask);
    }

    public NSInteger buttonNumber ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_buttonNumber);
    }

    public NSUInteger capabilityMask ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_capabilityMask);
    }

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

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

    public NSInteger clickCount ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_clickCount);
    }

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

    public NSInteger data1 ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_data1);
    }

    public NSInteger data2 ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_data2);
    }

    public CGFloat deltaX ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_deltaX);
    }

    public CGFloat deltaY ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_deltaY);
    }

    public CGFloat deltaZ ()
    {
        return cast(CGFloat) OS.objc_msgSend_fpret(this.id_, OS.sel_deltaZ);
    }

    public NSUInteger deviceID ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_deviceID);
    }

    public static NSEvent enterExitEventWithType (objc.id type, NSPoint location, NSUInteger flags, NSTimeInterval time, NSInteger wNum,
            NSGraphicsContext context, NSInteger eNum, NSInteger tNum, void* data)
    {
        objc.id result = OS.objc_msgSend(OS.class_NSEvent,
                OS.sel_enterExitEventWithType_1location_1modifierFlags_1timestamp_1windowNumber_1context_1eventNumber_1trackingNumber_1userData_1,
                type, location, flags, time, wNum, context !is null ? context.id_ : null, eNum, tNum, data);
        return result !is null ? new NSEvent(result) : null;
    }

    public NSInteger eventNumber ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_eventNumber);
    }

    public /*const*/void* eventRef ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_eventRef);
    }

    public static NSEvent eventWithCGEvent (CGEventRef cgEvent)
    {
        objc.id result = OS.objc_msgSend(OS.class_NSEvent, OS.sel_eventWithCGEvent_1, cgEvent);
        return result !is null ? new NSEvent(result) : null;
    }

    public static NSEvent eventWithEventRef (/*const*/void* eventRef)
    {
        objc.id result = OS.objc_msgSend(OS.class_NSEvent, OS.sel_eventWithEventRef_1, eventRef);
        return result !is null ? new NSEvent(result) : null;
    }

    public bool isARepeat ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_isARepeat) !is null;
    }

    public bool isEnteringProximity ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_isEnteringProximity) !is null;
    }

    public static bool isMouseCoalescingEnabled ()
    {
        return OS.objc_msgSend(OS.class_NSEvent, OS.sel_isMouseCoalescingEnabled) !is null;
    }

    public short keyCode ()
    {
        return cast(short) OS.objc_msgSend(this.id_, OS.sel_keyCode);
    }

    public static NSEvent keyEventWithType (NSEventType type, NSPoint location, NSUInteger flags, NSTimeInterval time, NSInteger wNum,
            NSGraphicsContext context, NSString keys, NSString ukeys, bool flag, short code)
    {
        objc.id
                result = OS.objc_msgSend(
                        OS.class_NSEvent,
                        OS.sel_keyEventWithType_1location_1modifierFlags_1timestamp_1windowNumber_1context_1characters_1charactersIgnoringModifiers_1isARepeat_1keyCode_1,
                        type, location, flags, time, wNum, context !is null ? context.id_ : null, keys !is null ? keys.id_ : null,
                        ukeys !is null ? ukeys.id_ : null, flag, code);
        return result !is null ? new NSEvent(result) : null;
    }

    public NSPoint locationInWindow ()
    {
        NSPoint result;
        OS.objc_msgSend_struct(&result, this.id_, OS.sel_locationInWindow);
        return result;
    }

    public NSUInteger modifierFlags ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_modifierFlags);
    }

    public static NSEvent mouseEventWithType (NSEventType type, NSPoint location, NSUInteger flags, NSTimeInterval time, NSInteger wNum,
            NSGraphicsContext context, NSInteger eNum, NSInteger cNum, float pressure)
    {
        objc.id result = OS.objc_msgSend(OS.class_NSEvent,
                OS.sel_mouseEventWithType_1location_1modifierFlags_1timestamp_1windowNumber_1context_1eventNumber_1clickCount_1pressure_1, type,
                location, flags, time, wNum, context !is null ? context.id_ : null, eNum, cNum, pressure);
        return result !is null ? new NSEvent(result) : null;
    }

    public static NSPoint mouseLocation ()
    {
        NSPoint result;
        OS.objc_msgSend_struct(&result, OS.class_NSEvent, OS.sel_mouseLocation);
        return result;
    }

    public static NSEvent otherEventWithType (NSEventType type, NSPoint location, NSUInteger flags, NSTimeInterval time, NSInteger wNum, NSGraphicsContext context,
            short subtype, NSInteger d1, NSInteger d2)
    {
        objc.id result = OS.objc_msgSend(OS.class_NSEvent,
                OS.sel_otherEventWithType_1location_1modifierFlags_1timestamp_1windowNumber_1context_1subtype_1data1_1data2_1, type, location, flags,
                time, wNum, context !is null ? context.id_ : null, subtype, d1, d2);
        return result !is null ? new NSEvent(result) : null;
    }

    public NSUInteger pointingDeviceID ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_pointingDeviceID);
    }

    public NSUInteger pointingDeviceSerialNumber ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_pointingDeviceSerialNumber);
    }

    public NSPointingDeviceType pointingDeviceType ()
    {
        return cast(NSPointingDeviceType) OS.objc_msgSend(this.id_, OS.sel_pointingDeviceType);
    }

    public float pressure ()
    {
        return cast(float) OS.objc_msgSend_fpret(this.id_, OS.sel_pressure);
    }

    public float rotation ()
    {
        return cast(float) OS.objc_msgSend_fpret(this.id_, OS.sel_rotation);
    }

    public static void setMouseCoalescingEnabled (bool flag)
    {
        OS.objc_msgSend(OS.class_NSEvent, OS.sel_setMouseCoalescingEnabled_1, flag);
    }

    public static void startPeriodicEventsAfterDelay (double delay, double period)
    {
        OS.objc_msgSend(OS.class_NSEvent, OS.sel_startPeriodicEventsAfterDelay_1withPeriod_1, delay, period);
    }

    public static void stopPeriodicEvents ()
    {
        OS.objc_msgSend(OS.class_NSEvent, OS.sel_stopPeriodicEvents);
    }

    public short subtype ()
    {
        return cast(short) OS.objc_msgSend(this.id_, OS.sel_subtype);
    }

    public NSUInteger systemTabletID ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_systemTabletID);
    }

    public NSUInteger tabletID ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_tabletID);
    }

    public float tangentialPressure ()
    {
        return cast(float) OS.objc_msgSend_fpret(this.id_, OS.sel_tangentialPressure);
    }

    public NSPoint tilt ()
    {
        NSPoint result;
        OS.objc_msgSend_stret(&result, this.id_, OS.sel_tilt);
        return result;
    }

    public NSTimeInterval timestamp ()
    {
        return OS.objc_msgSend_fpret(this.id_, OS.sel_timestamp);
    }

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

    public NSInteger trackingNumber ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_trackingNumber);
    }

    public NSEventType type ()
    {
        return cast(NSEventType) OS.objc_msgSend(this.id_, OS.sel_type);
    }

    public long uniqueID ()
    {
        return cast(long) OS.objc_msgSend(this.id_, OS.sel_uniqueID);
    }

    public void* userData ()
    {
        return OS.objc_msgSend(this.id_, OS.sel_userData);
    }

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

    public NSUInteger vendorID ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_vendorID);
    }

    public NSUInteger vendorPointingDeviceType ()
    {
        return cast(NSUInteger) OS.objc_msgSend(this.id_, OS.sel_vendorPointingDeviceType);
    }

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

    public NSInteger windowNumber ()
    {
        return cast(NSInteger) OS.objc_msgSend(this.id_, OS.sel_windowNumber);
    }

}