Java 类org.eclipse.swt.internal.Callback 实例源码

项目:TuxGuitar-1.3.1-fork    文件:OpenDocListener.java   
public void init() {
    Callback openDocCallback = new Callback(this, "openDocProc", 3);
    int openDocProc = openDocCallback.getAddress();
    if (openDocProc == 0) {
        openDocCallback.dispose();
        return;
    }
    if (OS.AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,openDocProc, 0, false) != OS.noErr) {
        return;
    }
    if (OS.AEInstallEventHandler(kURLEventClass, kURLEventClass,openDocProc, 0, false) != OS.noErr) {
        return;
    }
    int appTarget = OS.GetApplicationEventTarget();
    Callback appleEventCallback = new Callback(this, "appleEventProc", 3);
    int appleEventProc = appleEventCallback.getAddress();
    int[] mask3 = new int[] { OS.kEventClassAppleEvent, OS.kEventAppleEvent, kURLEventClass, };
    OS.InstallEventHandler(appTarget, appleEventProc,mask3.length / 2, mask3, 0, null);
}
项目:eclipsensis    文件:ControlSubclasser.java   
private static ILongPtr getCallbackAddress(Callback callback)
{
    ILongPtr address = WinAPI.ZERO_LONGPTR;
    if (callback != null)
    {
        try
        {
            Class<? extends Callback> clasz = callback.getClass();
            Method m = clasz.getMethod("getAddress");
            address = WinAPI.INSTANCE.createLongPtr(((Number) m.invoke(callback)));
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    return address;
}
项目:totallicks-tuxguitar    文件:OpenDocListener.java   
public void init() {
    Callback openDocCallback = new Callback(this, "openDocProc", 3);
    int openDocProc = openDocCallback.getAddress();
    if (openDocProc == 0) {
        openDocCallback.dispose();
        return;
    }
    if (OS.AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,openDocProc, 0, false) != OS.noErr) {
        return;
    }
    if (OS.AEInstallEventHandler(kURLEventClass, kURLEventClass,openDocProc, 0, false) != OS.noErr) {
        return;
    }
    int appTarget = OS.GetApplicationEventTarget();
    Callback appleEventCallback = new Callback(this, "appleEventProc", 3);
    int appleEventProc = appleEventCallback.getAddress();
    int[] mask3 = new int[] { OS.kEventClassAppleEvent, OS.kEventAppleEvent, kURLEventClass, };
    OS.InstallEventHandler(appTarget, appleEventProc,mask3.length / 2, mask3, 0, null);
}
项目:TuxGuitar-1.3.1-fork    文件:OpenDocListener.java   
public void init() throws Throwable{
    long cls = TGCocoa.objc_lookUpClass ("SWTApplicationDelegate");
    if( cls != 0 ){
        Callback callback = TGCocoa.newCallback( this , "callbackProc64" , "callbackProc32", 4 );

        long callbackProc = TGCocoa.getCallbackAddress( callback );
        if( callbackProc != 0 ){
            TGCocoa.class_addMethod(cls, sel_application_openFile_, callbackProc , "B:@@");
        }
    }
}
项目:TuxGuitar-1.3.1-fork    文件:MacToolbar.java   
public void init( Shell shell ) throws Throwable{
    Callback callback = TGCocoa.newCallback( this , "callbackProc64", "callbackProc32", 3 );
    long callbackProc = TGCocoa.getCallbackAddress( callback );

    if( callbackProc != 0 ){
        String classname = ("MacToolbarDelegate");
        if( TGCocoa.objc_lookUpClass ( classname ) == 0 ) {
            long cls = TGCocoa.objc_allocateClassPair( classname , 0 ) ;
            TGCocoa.class_addIvar(cls, SWT_OBJECT, C.PTR_SIZEOF , (byte)(C.PTR_SIZEOF == 4 ? 2 : 3), new byte[]{'*','\0'} );
            TGCocoa.class_addMethod(cls, sel_toolbarButtonClicked_, callbackProc , "@:@");
            TGCocoa.objc_registerClassPair(cls);
        }

        this.delegate = TGCocoa.newMacToolbarDelegate();
        this.delegate.alloc().init();
        this.delegateRef = TGCocoa.NewGlobalRef( MacToolbar.this );

        TGCocoa.object_setInstanceVariable( MacToolbarDelegate.class.getField("id").get( delegate ) , SWT_OBJECT , this.delegateRef );

        NSToolbar dummyBar = new NSToolbar();
        dummyBar.alloc();
        dummyBar.initWithIdentifier(NSString.stringWith("SWTToolbar")); //$NON-NLS-1$
        dummyBar.setVisible(false);

        NSWindow nsWindow = shell.view.window();
        nsWindow.setToolbar(dummyBar);
        dummyBar.release();
        nsWindow.setShowsToolbarButton(true);

        NSButton toolbarButton = TGCocoa.getStandardWindowButton(nsWindow, NSWindowToolbarButton);
        if (toolbarButton != null) {
            toolbarButton.setTarget( delegate );
            TGCocoa.setControlAction( toolbarButton , sel_toolbarButtonClicked_ );
        }
    }
}
项目:gef-gwt    文件:ClipboardProxy.java   
ClipboardProxy(Display display) {
    this.display = display;
    getFunc = new Callback(this, "getFunc", 4); //$NON-NLS-1$
    if (getFunc.getAddress() == 0)
        SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
    clearFunc = new Callback(this, "clearFunc", 2); //$NON-NLS-1$
    if (clearFunc.getAddress() == 0)
        SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
}
项目:gef-gwt    文件:AccessibleFactory.java   
static private Callback newCallback(Object object, String method,
        int argCount) {
    Callback callback = new Callback(object, method, argCount);
    if (callback.getAddress() == 0)
        SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
    return callback;
}
项目:totallicks-tuxguitar    文件:OpenDocListener.java   
public void init() throws Throwable{
    long cls = TGCocoa.objc_lookUpClass ("SWTApplicationDelegate");
    if( cls != 0 ){
        Callback callback = TGCocoa.newCallback( this , "callbackProc64" , "callbackProc32", 4 );

        long callbackProc = TGCocoa.getCallbackAddress( callback );
        if( callbackProc != 0 ){
            TGCocoa.class_addMethod(cls, sel_application_openFile_, callbackProc , "B:@@");
        }
    }
}
项目:totallicks-tuxguitar    文件:MacToolbar.java   
public void init( Shell shell ) throws Throwable{
    Callback callback = TGCocoa.newCallback( this , "callbackProc64", "callbackProc32", 3 );
    long callbackProc = TGCocoa.getCallbackAddress( callback );

    if( callbackProc != 0 ){
        String classname = ("MacToolbarDelegate");
        if( TGCocoa.objc_lookUpClass ( classname ) == 0 ) {
            long cls = TGCocoa.objc_allocateClassPair( classname , 0 ) ;
            TGCocoa.class_addIvar(cls, SWT_OBJECT, C.PTR_SIZEOF , (byte)(C.PTR_SIZEOF == 4 ? 2 : 3), new byte[]{'*','\0'} );
            TGCocoa.class_addMethod(cls, sel_toolbarButtonClicked_, callbackProc , "@:@");
            TGCocoa.objc_registerClassPair(cls);
        }

        this.delegate = TGCocoa.newMacToolbarDelegate();
        this.delegate.alloc().init();
        this.delegateRef = TGCocoa.NewGlobalRef( MacToolbar.this );

        TGCocoa.object_setInstanceVariable( MacToolbarDelegate.class.getField("id").get( delegate ) , SWT_OBJECT , this.delegateRef );

        NSToolbar dummyBar = new NSToolbar();
        dummyBar.alloc();
        dummyBar.initWithIdentifier(NSString.stringWith("SWTToolbar")); //$NON-NLS-1$
        dummyBar.setVisible(false);

        NSWindow nsWindow = shell.view.window();
        nsWindow.setToolbar(dummyBar);
        dummyBar.release();
        nsWindow.setShowsToolbarButton(true);

        NSButton toolbarButton = TGCocoa.getStandardWindowButton(nsWindow, NSWindowToolbarButton);
        if (toolbarButton != null) {
            toolbarButton.setTarget( delegate );
            TGCocoa.setControlAction( toolbarButton , sel_toolbarButtonClicked_ );
        }
    }
}
项目:TuxGuitar-1.3.1-fork    文件:TGCocoa.java   
public static final Callback newCallback(Object object, String method64, String method32, int argCount) throws Throwable {
    return new Callback( object, ( C.PTR_SIZEOF == 8 ? method64 : method32 ) , argCount );
}
项目:TuxGuitar-1.3.1-fork    文件:TGCocoa.java   
public static final long getCallbackAddress( Callback callback ) throws Throwable {
    return longValue(invokeMethod(Callback.class, callback , "getAddress", new Object[] {}));
}
项目:JFaceUtils    文件:CocoaUIEnhancer.java   
private void initialize(final CallbackObject callbackObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {
    final Class<?> osCls = Class.forName("org.eclipse.swt.internal.cocoa.OS");

    // Register names in Objective-C.
    if (sel_toolbarButtonClicked_ == 0) {
        sel_preferencesMenuItemSelected_ = registerName(osCls, "preferencesMenuItemSelected:");
        sel_aboutMenuItemSelected_ = registerName(osCls, "aboutMenuItemSelected:");
    }

    // Create an SWT Callback object that will invoke the actionProc method of our internal callbackObject.
    proc3Args = new Callback(callbackObject, "actionProc", 3);
    final long proc3 = proc3Args.getAddress();
    if (proc3 == 0) {
        SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
    }

    final Object object = invoke(osCls, "objc_lookUpClass", new Object[] { "SWTApplicationDelegate" });
    final long cls = convertToLong(object);

    // Add the action callbacks for Preferences and About menu items.
    invoke(osCls, "class_addMethod", new Object[] { wrapPointer(cls), wrapPointer(sel_preferencesMenuItemSelected_), wrapPointer(proc3), "@:@" });
    invoke(osCls, "class_addMethod", new Object[] { wrapPointer(cls), wrapPointer(sel_aboutMenuItemSelected_), wrapPointer(proc3), "@:@" });

    final Class<?> nsapplicationCls = Class.forName("org.eclipse.swt.internal.cocoa.NSApplication");
    final Class<?> nsmenuCls = Class.forName("org.eclipse.swt.internal.cocoa.NSMenu");

    // Get the Mac OS X Application menu.
    final Object sharedApplication = invoke(nsapplicationCls, "sharedApplication");
    final Object mainMenu = invoke(sharedApplication, "mainMenu");
    final Object mainMenuItem = invoke(nsmenuCls, mainMenu, ITEM_AT_INDEX, new Number[] { wrapPointer(0) });
    final Object appMenu = invoke(mainMenuItem, "submenu");

    final Object aboutMenuItem = invoke(nsmenuCls, appMenu, ITEM_AT_INDEX, new Number[] { wrapPointer(kAboutMenuItem) });
    final Object prefMenuItem = invoke(nsmenuCls, appMenu, ITEM_AT_INDEX, new Number[] { wrapPointer(kPreferencesMenuItem) });

    final Class<?> nsmenuitemCls = Class.forName("org.eclipse.swt.internal.cocoa.NSMenuItem");

    if (callbackObject.aboutEnabled) {
        invoke(nsmenuitemCls, aboutMenuItem, "setAction", new Number[] { wrapPointer(sel_aboutMenuItemSelected_) });
    }
    invoke(nsmenuitemCls, aboutMenuItem, "setEnabled", new Boolean[] { callbackObject.aboutEnabled });

    if (callbackObject.preferencesEnabled) {
        invoke(nsmenuitemCls, prefMenuItem, "setAction", new Number[] { wrapPointer(sel_preferencesMenuItemSelected_) });
    }
    invoke(nsmenuitemCls, prefMenuItem, "setEnabled", new Boolean[] { callbackObject.preferencesEnabled });
}
项目:totallicks-tuxguitar    文件:TGCocoa.java   
public static final Callback newCallback(Object object, String method64, String method32, int argCount) throws Throwable {
    return new Callback( object, ( C.PTR_SIZEOF == 8 ? method64 : method32 ) , argCount );
}
项目:totallicks-tuxguitar    文件:TGCocoa.java   
public static final long getCallbackAddress( Callback callback ) throws Throwable {
    return longValue(invokeMethod(Callback.class, callback , "getAddress", new Object[] {}));
}