Page 1 of 1

uno.Any() problem with c#

Posted: Thu Jul 01, 2010 2:43 pm
by sid_openoffice_1
hi,

I am using c# to develop an addon but the problem comes when I use insertByIndex(int,uno.Any) on XnamContainer it is giving me error "[map_to_uno():any] could not convert type!"
I am using this code

Code: Select all

 private String menuBarURL = "private:resource/menubar/menubar";
        private String topLevelMenuCmd = ".uno:dct_test";
        private String topLevelMenuLabel = "Sun Developer Connection";
        private String itemCmd = "macro:///Standard.Module1.myMacro()";
        private String itemLabel = "myMacro";

        public static string res = "1";
        public static XComponent xcomponent;
        XComponentLoader componentLoader;
        XMultiServiceFactory multiServiceFactory;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            unoidl.com.sun.star.uno.XComponentContext localContext = uno.util.Bootstrap.bootstrap();
            multiServiceFactory = (XMultiServiceFactory)localContext.getServiceManager();

            get_menu(localContext);

            componentLoader = (XComponentLoader)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
           
            XDesktop desktop = (XDesktop)componentLoader;
            xcomponent = desktop.getCurrentComponent();
            XFrame xf = desktop.getCurrentFrame();

        }
public void get_menu(XComponentContext xContext)
        {
            XModuleManager modulemanager = (XModuleManager)multiServiceFactory.createInstance("com.sun.star.frame.ModuleManager");
            unoidl.com.sun.star.ui.XModuleUIConfigurationManagerSupplier xmucm = (unoidl.com.sun.star.ui.XModuleUIConfigurationManagerSupplier)multiServiceFactory.createInstance("com.sun.star.ui.ModuleUIConfigurationManagerSupplier");
            unoidl.com.sun.star.ui.XUIConfigurationManager xui_conf_manager = xmucm.getUIConfigurationManager("com.sun.star.text.TextDocument");
            unoidl.com.sun.star.container.XIndexAccess _xindexaccess = xui_conf_manager.getSettings("private:resource/menubar/menubar", true);
            XSingleComponentFactory xCfgMgrFactory = (XSingleComponentFactory)_xindexaccess;
            PropertyValue[] topLevelMenuProperty = SetTopLevelMenuProperties(topLevelMenuCmd, topLevelMenuLabel, xCfgMgrFactory, xContext);
            PropertyValue[] menuItemProperty = SetItemProperty(itemCmd, itemLabel);


uno.Any a=new uno.Any(topLevelMenuProperty.getType());
            XIndexContainer _xindexcontainer = (XIndexContainer)xCfgMgrFactory;
            _xindexcontainer.insertByIndex(0,a );

            xui_conf_manager.replaceSettings(menuBarURL, _xindexaccess);

        }

        protected PropertyValue[] SetTopLevelMenuProperties(String CommandId, String _label, XSingleComponentFactory xCfgMgrFactory, XComponentContext xContext)
        {

            PropertyValue[] MenuProperty = new PropertyValue[4];
            uno.Any a = new uno.Any(CommandId);
            try
            {
                MenuProperty[0] = new PropertyValue();
                MenuProperty[0].Name = "CommandURL";
                MenuProperty[0].Value = a;
                MenuProperty[1] = new PropertyValue();
                MenuProperty[1].Name = "Label";
                a = new uno.Any(_label);
                MenuProperty[1].Value = a;
                MenuProperty[2] = new PropertyValue();
                MenuProperty[2].Name = "Type";
                a = new uno.Any(0);
                MenuProperty[2].Value = a;
                MenuProperty[3] = new PropertyValue();
                MenuProperty[3].Name = "ItemDescriptorContainer";
                a = new uno.Any(xCfgMgrFactory.createInstanceWithContext(xContext).GetType());
                MenuProperty[3].Value = a;
            }
            catch (unoidl.com.sun.star.uno.Exception ex)
            { }
            return MenuProperty;

        }
        protected PropertyValue[] SetItemProperty(String CommandId, String _label)
        {

            PropertyValue[] itemProperty = new PropertyValue[3];
            uno.Any a = new uno.Any(CommandId);
            itemProperty[0] = new PropertyValue();
            itemProperty[0].Name = "CommandURL";
            itemProperty[0].Value = a;
            itemProperty[1] = new PropertyValue();
            itemProperty[1].Name = "Label";
            a = new uno.Any(_label);
            itemProperty[1].Value = a;
            itemProperty[2] = new PropertyValue();
            itemProperty[2].Name = "Type";
            a = new uno.Any(0);
            itemProperty[2].Value = a;

            return itemProperty;
        }

    }

Re: uno.Any() problem with c#

Posted: Sun Oct 17, 2010 12:30 pm
by Hagar Delest
Moved from Beginners to External Programs.

Re: uno.Any() problem with c#

Posted: Sun Oct 17, 2010 1:35 pm
by hanya
This might be fixed but your variable "a" initialized with Type as its value, pass correct value as its second argument.

Re: uno.Any() problem with c#

Posted: Tue Mar 20, 2012 12:06 pm
by baraujo
I had this problem too and searched everywhere with no success.

The solution was to install same openoffice version as SDK version.

Re: uno.Any() problem with c#

Posted: Fri Nov 09, 2012 6:56 pm
by YumBiscuits
Hi - a bit late in the day, but this worked for me:

uno.Any a = new uno.Any(topLevelMenuProperty.GetType(), topLevelMenuProperty);

Re: uno.Any() problem with c#

Posted: Mon Sep 25, 2017 11:56 am
by gurujuly
I followed this example and created a top level menu using Java. Could someone please tell me how to handle the events? Thanks.