All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bugvm.apple.uikit.UIMenuController Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2013-2015 RoboVM AB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bugvm.apple.uikit;

/**/
import java.io.*;
import java.nio.*;
import java.util.*;
import com.bugvm.objc.*;
import com.bugvm.objc.annotation.*;
import com.bugvm.objc.block.*;
import com.bugvm.rt.*;
import com.bugvm.rt.annotation.*;
import com.bugvm.rt.bro.*;
import com.bugvm.rt.bro.annotation.*;
import com.bugvm.rt.bro.ptr.*;
import com.bugvm.apple.foundation.*;
import com.bugvm.apple.coreanimation.*;
import com.bugvm.apple.coregraphics.*;
import com.bugvm.apple.coredata.*;
import com.bugvm.apple.coreimage.*;
import com.bugvm.apple.coretext.*;
import com.bugvm.apple.corelocation.*;
/**/

/**/
/**
 * @since Available in iOS 3.0 and later.
 */
/**/
/**/@Library("UIKit") @NativeClass/**/
/**/public/**/ class /**/UIMenuController/**/ 
    extends /**/NSObject/**/ 
    /**//**/ {

    public static class Notifications {
        public static NSObject observeWillShowMenu(final Runnable block) {
            return NSNotificationCenter.getDefaultCenter().addObserver(WillShowMenuNotification(), null, NSOperationQueue.getMainQueue(), new VoidBlock1() {
                @Override
                public void invoke(NSNotification a) {
                    block.run();
                }
            });
        }
        public static NSObject observeDidShowMenu(final Runnable block) {
            return NSNotificationCenter.getDefaultCenter().addObserver(DidShowMenuNotification(), null, NSOperationQueue.getMainQueue(), new VoidBlock1() {
                @Override
                public void invoke(NSNotification a) {
                    block.run();
                }
            });
        }
        public static NSObject observeWillHideMenu(final Runnable block) {
            return NSNotificationCenter.getDefaultCenter().addObserver(WillHideMenuNotification(), null, NSOperationQueue.getMainQueue(), new VoidBlock1() {
                @Override
                public void invoke(NSNotification a) {
                    block.run();
                }
            });
        }
        public static NSObject observeDidHideMenu(final Runnable block) {
            return NSNotificationCenter.getDefaultCenter().addObserver(DidHideMenuNotification(), null, NSOperationQueue.getMainQueue(), new VoidBlock1() {
                @Override
                public void invoke(NSNotification a) {
                    block.run();
                }
            });
        }
        public static NSObject observeMenuFrameDidChange(final Runnable block) {
            return NSNotificationCenter.getDefaultCenter().addObserver(MenuFrameDidChangeNotification(), null, NSOperationQueue.getMainQueue(), new VoidBlock1() {
                @Override
                public void invoke(NSNotification a) {
                    block.run();
                }
            });
        }
    }
    
    private static final long UI_MENU_CONTROLLER = ObjCRuntime.objc_getClass(VM.getStringUTFChars("NSObject"));
    private static final java.lang.reflect.Method cbForwarder;
    
    static {
        try {
            cbForwarder = UIMenuController.class.getDeclaredMethod("cbForwarder", long.class, long.class, UIMenuController.class);
        } catch (Exception e) {
            throw new Error(e);
        }
    }
    
    @Callback
    private static void cbForwarder(@Pointer long self, @Pointer long sel, UIMenuController menuController) {
        UIMenuItem item = UIMenuItem.items.get(sel);
        if (item != null && item.getActionListener() != null) {
            item.getActionListener().onAction(menuController, item);
        }
    }
    
    /**/public static class UIMenuControllerPtr extends Ptr {}/**/
    /**/static { ObjCRuntime.bind(UIMenuController.class); }/**/
    /**//**/
    /**/
    public UIMenuController() {}
    protected UIMenuController(SkipInit skipInit) { super(skipInit); }
    /**/
    /**/
    @Property(selector = "isMenuVisible")
    public native boolean isMenuVisible();
    @Property(selector = "setMenuVisible:")
    public native void setMenuVisible(boolean v);
    /**
     * @since Available in iOS 3.2 and later.
     */
    @Property(selector = "arrowDirection")
    public native UIMenuControllerArrowDirection getArrowDirection();
    /**
     * @since Available in iOS 3.2 and later.
     */
    @Property(selector = "setArrowDirection:")
    public native void setArrowDirection(UIMenuControllerArrowDirection v);
    /**
     * @since Available in iOS 3.2 and later.
     */
    @Property(selector = "menuItems")
    private native NSArray getMenuItems0();
    /**
     * @since Available in iOS 3.2 and later.
     */
    @Property(selector = "setMenuItems:")
    private native void setMenuItems0(NSArray v);
    @Property(selector = "menuFrame")
    public native @ByVal CGRect getMenuFrame();
    /**/
    /**//**/
    public NSArray getMenuItems() {
        return getMenuItems0();
    }
    public void setMenuItems(NSArray items) {
        updateMenu(items);
        setMenuItems0(items);
    }
    
    private void updateMenu(NSArray items) {
        long imp = VM.getCallbackMethodImpl(cbForwarder);
        long typeEncodings = VM.getStringUTFChars("v@:@");
        
        for (UIMenuItem item : items) {
            Selector sel = item.getAction();
            ObjCRuntime.class_addMethod(UI_MENU_CONTROLLER, sel.getHandle(), imp, typeEncodings);
        }
    }
    /**/
    @GlobalValue(symbol="UIMenuControllerWillShowMenuNotification", optional=true)
    public static native NSString WillShowMenuNotification();
    @GlobalValue(symbol="UIMenuControllerDidShowMenuNotification", optional=true)
    public static native NSString DidShowMenuNotification();
    @GlobalValue(symbol="UIMenuControllerWillHideMenuNotification", optional=true)
    public static native NSString WillHideMenuNotification();
    @GlobalValue(symbol="UIMenuControllerDidHideMenuNotification", optional=true)
    public static native NSString DidHideMenuNotification();
    @GlobalValue(symbol="UIMenuControllerMenuFrameDidChangeNotification", optional=true)
    public static native NSString MenuFrameDidChangeNotification();
    
    @Method(selector = "setMenuVisible:animated:")
    public native void setMenuVisible(boolean menuVisible, boolean animated);
    @Method(selector = "setTargetRect:inView:")
    public native void setTargetRect(@ByVal CGRect targetRect, UIView targetView);
    @Method(selector = "update")
    public native void update();
    @Method(selector = "sharedMenuController")
    public static native UIMenuController getSharedMenuController();
    /**/
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy