OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Hiding the main menu using OO 2.o and C# resp. net

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
LarsB
OOo Advocate
OOo Advocate


Joined: 31 Aug 2005
Posts: 445
Location: Hamburg, Germany

PostPosted: Mon Nov 28, 2005 1:12 pm    Post subject: Hiding the main menu using OO 2.o and C# resp. net Reply with quote

Hi,

after there are so many postings about hiding
menus and toolbars using OO Basic here is
some code that hide the main menu using
C# resp. any other .net language. The code
based on the OO 2.0 api!

Code:

using System;
using System.Reflection;

namespace TestApp
{
   /// <summary>
   /// Start a new OpenOffice instance, load a blank writer, and hide the main menu.
   /// </summary>
   class Class1
   {
      [STAThread]
      static void Main()
      {
         //Get the service manager
         object _serviceManager = System.Activator.CreateInstance(
                        Type.GetTypeFromProgID("com.sun.star.ServiceManager", true));
         
         //Get the desktop
         object _starDesktop = ComObject.Invoke(_serviceManager,
            "createinstance",
            BindingFlags.InvokeMethod,
            "com.sun.star.frame.Desktop");
         
         //Params to create a new writer instance
         Object[] args = new Object[4];
         args[0] = "private:factory/swriter";
         args[1] = "_blank";
         args[2] = 0;
         args[3] = new Object[] { };
         
         //Create the document
         object _xDocument = ComObject.Invoke(_starDesktop,
            "loadComponentFromUrl",
            BindingFlags.InvokeMethod,
            args
            );

         // Get the current frame
         object _oframe   = ComObject.Invoke(_starDesktop,
                         "getCurrentFrame", BindingFlags.InvokeMethod, new object[] {});
         
         //Get the LayoutManager
         object _olayout   = ComObject.Invoke(_oframe,
                        "LayoutManager", BindingFlags.GetProperty, new object[] {});

         //Hide the main menu
         ComObject.Invoke(_olayout, "hideElement", BindingFlags.InvokeMethod,
                        new object[] { "private:resource/menubar/menubar" });

         Console.WriteLine("Stop");
         Console.ReadLine();
      }
   }

   public class ComObject
   {
      public ComObject()
      {
      }

      /// <summary>
      /// Create a new Com object.
      /// </summary>
      /// <param name="obj">The object to call invoke on.</param>
      /// <param name="method">The methodname to call</param>
      /// <param name="binding">One of the BiningFlags Enumertion</param>
      /// <param name="par">The params for the invoke method call</param>
      /// <returns></returns>
      public static object Invoke(object obj,string method, BindingFlags binding,params object[] par)
      {
         return obj.GetType().InvokeMember(method,binding,null,obj,par);
      }
   }
}


Cheers
Lars B
_________________
AODC - A free OpenDocument Converter
AODL - An independent OpenDocument Library C#
EmbeddedOpenOffice .net UserControl C#
EmbeddedOpenOffice Visual Studio .net Add In

http://www.OpenDocument4all.com/
Back to top
View user's profile Send private message Visit poster's website
James Miles
General User
General User


Joined: 28 Nov 2005
Posts: 22
Location: Perth - Australia

PostPosted: Tue Nov 29, 2005 12:51 am    Post subject: LayoutManager missing Reply with quote

Hi Lars,

I'm trying to do the same thing, but i have not been using reflection.

Code:
// Get the current frame.
XFrame currentFrame = OpenOfficeConnectionManager.Desktop.getCurrentFrame();


This is where i run into problems. The XFrame doesn't have a LayoutManager so i tried to use reflection.

Code:
// Get the layout manager from the current frame.
XLayoutManager layoutManager = currentFrame.GetType().InvokeMember("LayoutManager", BindingFlags.GetProperty, null, currentFrame, new object[] {}) as XLayoutManager;


When it tries to access this property i get the following exception.

"An unhandled exception of type 'System.MissingMethodException' occurred in mscorlib.dll
Additional information: Attempted to access a missing member."

Why does your XFrame have a layout manager... and mine doesn't. Is it because you created your frame object differently?

Cheers,
James Miles.
Back to top
View user's profile Send private message Send e-mail
LarsB
OOo Advocate
OOo Advocate


Joined: 31 Aug 2005
Posts: 445
Location: Hamburg, Germany

PostPosted: Tue Nov 29, 2005 2:55 am    Post subject: Not supported by the cli assmblies Reply with quote

Hi,

the XLayoutManager interface is part of the cli assemblies,
but the developer forgot to add resp. implement the LayoutManager
property on the Frame object Sad

Maybe anyone has a idea if there is another way to get a
LayoutManager instance.

I already tried to create the service with the servicemanager
and then use addFrame which result in no errors, but the
following method calls doesn't do anything.

Cheers
Lars B
_________________
AODC - A free OpenDocument Converter
AODL - An independent OpenDocument Library C#
EmbeddedOpenOffice .net UserControl C#
EmbeddedOpenOffice Visual Studio .net Add In

http://www.OpenDocument4all.com/
Back to top
View user's profile Send private message Visit poster's website
James Miles
General User
General User


Joined: 28 Nov 2005
Posts: 22
Location: Perth - Australia

PostPosted: Tue Nov 29, 2005 10:53 pm    Post subject: Work around. Reply with quote

Lars has found a tidy workaround for this problem.

See: http://www.oooforum.org/forum/viewtopic.phtml?t=27935
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group