uno.Any() problem with c#

Java, C++, C#, Delphi, ??? - Using the UNO bridges

uno.Any() problem with c#

Postby sid_openoffice_1 » Thu Jul 01, 2010 2:43 pm

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   Expand viewCollapse view
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;
        }

    }
Windows OpenOffice 3.2
sid_openoffice_1
 
Posts: 12
Joined: Tue Jun 15, 2010 1:53 pm

Re: uno.Any() problem with c#

Postby Hagar Delest » Sun Oct 17, 2010 12:30 pm

Moved from Beginners to External Programs.
AOO 4.1.5 on Xubuntu 18.04 and on Windows 7 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 28071
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: uno.Any() problem with c#

Postby hanya » Sun Oct 17, 2010 1:35 pm

This might be fixed but your variable "a" initialized with Type as its value, pass correct value as its second argument.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 881
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: uno.Any() problem with c#

Postby baraujo » Tue Mar 20, 2012 12:06 pm

I had this problem too and searched everywhere with no success.

The solution was to install same openoffice version as SDK version.
OpenOffice 3.3 on Windows 7
baraujo
 
Posts: 1
Joined: Tue Mar 20, 2012 12:04 pm

Re: uno.Any() problem with c#

Postby YumBiscuits » Fri Nov 09, 2012 6:56 pm

Hi - a bit late in the day, but this worked for me:

uno.Any a = new uno.Any(topLevelMenuProperty.GetType(), topLevelMenuProperty);
OpenOffice 3.4.0 (Rev 1327774) on Windows XP
YumBiscuits
 
Posts: 1
Joined: Fri Nov 09, 2012 6:51 pm

Re: uno.Any() problem with c#

Postby gurujuly » Mon Sep 25, 2017 11:56 am

I followed this example and created a top level menu using Java. Could someone please tell me how to handle the events? Thanks.
Open Office 4.3 and Windows 10.
gurujuly
 
Posts: 3
Joined: Thu Sep 07, 2017 1:44 pm


Return to External Programs

Who is online

Users browsing this forum: No registered users and 2 guests