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

troubles with menu

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Ondra
General User
General User


Joined: 12 Mar 2004
Posts: 10

PostPosted: Fri Apr 16, 2004 1:06 am    Post subject: troubles with menu Reply with quote

Hello!
Here is code, which add my menu into Writer menu
Code:

Sub AddVismoMenu()
   oConfigAccess = GetConfigAccess( "/org.openoffice.Office.Addons/AddonUI", True )

   oElement = oConfigAccess.getByName( "OfficeMenuBar" )
   
  If oElement.hasByName( "VismoMenu" ) Then
      MsgBox( "Vismo Menu je už instalováno." )
      Exit Sub
   EndIf
   
   ' Create a menu.
   oMenu = oElement.createInstance()
   oMenu.Title = "Vismo"
   oMenu.Context = "com.sun.star.text.TextDocument"

   oMenuItem = MakeMenuItem( oMenu.Submenu, "Prvni", "Polozka1","macro:///standad.VismoUprDok.SpustVismo()")
       
   oElement.insertByName( "VismoMenu", oMenu )
   
   oConfigAccess.commitChanges()
End Sub


So I have a silly question: (But I hope that it isn't so silly)
Is any similary way how can I add my function (macro), respectively my menu, into function toolbar?
Thank you for your answers

Ondra
Back to top
View user's profile Send private message Send e-mail
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Fri Apr 16, 2004 7:36 am    Post subject: Reply with quote

Yes it is possible to install toolbar items.

I do not know if the following is helpful.

Here is how I do it.


Code:
'----------
' Configuration Node Names.
' Note that these name must be unique in the configuration manager.
'----------

Const cMyToolbarItemName = "com.Example123.DrawDupShapes"


'----------
' The URL's for the commands that activate our macros...
' The "macro:///...." URL will cause a Basic macro to execute.
' Conveniently, we've already installed  this Basic code so that this
'  URL can execute it when the user picks the menu command.
'----------
Const cUrlDupShapeUp = "macro:///Example123.DupShapes.DupSelectedShapeUp()"
Const cUrlDupShapeDn = "macro:///Example123.DupShapes.DupSelectedShapeDown()"
Const cUrlDupShapeLf = "macro:///Example123.DupShapes.DupSelectedShapeLeft()"
Const cUrlDupShapeRt = "macro:///Example123.DupShapes.DupSelectedShapeRight()"


Sub InstallToolBarCommands()
   ' Get the configuration node, with write access.
   ' Note for the adventurous...
   '  What we are editing is the XML file named...
   '   OOo\user\registry\data\org\openoffice\Office\Addons.xcu
   '  then within that XML file, the node AddonUI.
   oConfigAccess = GetConfigAccess( "/org.openoffice.Office.Addons/AddonUI", True )
   ' Get the OfficeToolBar element.
   oElement = oConfigAccess.getByName( "OfficeToolBar" )
   
   If oElement.hasByName( cMyTopLevelMenuName ) Then
      'MsgBox( " Top Level menu already installed." )
      Exit Sub
   EndIf
   
   ' Create a toolbar.
   oToolbar = oElement.createInstance()
      

   ' Create toolbar items and add them to the toolbar.
   ' "Dup Shape Up" is the menu item title that the user sees.
   ' "DupShapeUp" is the internal name of the menu node in the configuration.
   oToolbarItem = MakeToolbarItem( oToolbar, "Dup Shape Up", cMyToolbarItemName+".DupShapeUp", cUrlDupShapeUp )
   ' The context can be a comma seperated list of services.
   ' Put in the name of the drawing document service so that
   '  the toolbar item ONLY appears on Drawing documents.
   oToolbarItem.Context = "com.sun.star.drawing.DrawingDocument"


   oToolbarItem = MakeToolbarItem( oToolbar, "Dup Shape Down",  cMyToolbarItemName+".DupShapeDn", cUrlDupShapeDn )
   oToolbarItem.Context = "com.sun.star.drawing.DrawingDocument"


   oToolbarItem = MakeToolbarItem( oToolbar, "Dup Shape Left",  cMyToolbarItemName+".DupShapeLf", cUrlDupShapeLf )
   oToolbarItem.Context = "com.sun.star.drawing.DrawingDocument"


   oToolbarItem = MakeToolbarItem( oToolbar, "Dup Shape Right", cMyToolbarItemName+".DupShapeRt", cUrlDupShapeRt )
   oToolbarItem.Context = "com.sun.star.drawing.DrawingDocument"
   
   
   ' Add the toolbar to the configuration.
   ' This inserts the node oToolbar, and all of its sub nodes.
   oElement.insertByName( cMyToolbarItemName, oToolbar )

   
   ' Commit the changes to the configuration.
   ' You can't actuall see these changes until the office has been restarted.
   '  (This includes making sure that the quickstarter is not running!)
   oConfigAccess.commitChanges()
End Sub


Sub RemoveToolBarCommands()
   ' Get the configuration node, with write access.
   ' Note for the adventurous...
   '  What we are editing is the XML file named...
   '   OOo\user\registry\data\org\openoffice\Office\Addons.xcu
   '  then within that XML file, the node AddonUI.
   oConfigAccess = GetConfigAccess( "/org.openoffice.Office.Addons/AddonUI", True )
   ' Get the OfficeToolBar element.
   oElement = oConfigAccess.getByName( "OfficeToolBar" )
   
   If Not oElement.hasByName( cMyToolbarItemName ) Then
      'MsgBox( "Toolbar is not installed." )
      Exit Sub
   EndIf
   
   ' Remove the toolbar from the configuration.
   ' This removes the toolbar, and all of its sub nodes.
   oElement.removeByName( cMyToolbarItemName )
   
   ' Commit the changes to the configuration.
   ' You can't actuall see these changes until the office has been restarted.
   '  (This includes making sure that the quickstarter is not running!)
   oConfigAccess.commitChanges()
End Sub



Function MakeToolbarItem( oParentContainer, cTitle, cConfigName, Optional cURL )
   oToolbarItem = oParentContainer.createInstance
   oToolbarItem.Title = cTitle
   If Not IsMissing( cURL ) Then
      oToolbarItem.URL = cURL
   EndIf
   oParentContainer.insertByName( cConfigName, oToolbarItem )
   MakeToolbarItem() = oToolbarItem
End Function



For toolbar items, it really is important to also install icons. I have a complete working example.

In fact, the above code is from a much more elaborate working example that you can find at OOoMacros.org. The example is here.

http://www.ooomacros.org/user.php#115800


To encode the icons that appear in this example, see this article....

EncodeFile and EncodeIcon
http://www.oooforum.org/forum/viewtopic.php?t=6910
_________________
Want to make OOo Drawings like the colored flower design to the left?


Last edited by DannyB on Tue Apr 20, 2004 9:07 am; edited 1 time in total
Back to top
View user's profile Send private message
Ondra
General User
General User


Joined: 12 Mar 2004
Posts: 10

PostPosted: Mon Apr 19, 2004 5:00 am    Post subject: troubles with menu Reply with quote

Hi!

I can't understand this:
Code:

Const cMyTopLevelMenuName = "nom.DannyBrewer.Example.DrawDupShapes.TopMenu"
Const cMyAddOnMenuName    = "nom.DannyBrewer.Example.DrawDupShapes.AddOnMenu"
Const cMyIconName         = "nom.DannyBrewer.Example.DrawDupShapes.Icon"


Exactly, if "nom" has any mean or if it deduce from something?
If it's realy necessary to call it "nom.DannyBrewer.Example.DrawDupShapes.TopMenu"
It's possible to call it, for example "MyTopMenuNameSet"?

Thanks

Ondra
Back to top
View user's profile Send private message Send e-mail
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Mon Apr 19, 2004 9:42 am    Post subject: Re: troubles with menu Reply with quote

Ondra wrote:
Exactly, if "nom" has any mean or if it deduce from something?
If it's realy necessary to call it "nom.DannyBrewer.Example.DrawDupShapes.TopMenu"
It's possible to call it, for example "MyTopMenuNameSet"?


You can give it a name that is hierarchically qualified. The name must be unique under the configuration node. For example, under the "OfficeToolbar" node, no two toolbar names can have the same name.

Examples you see in the developer's guide would be like....


org.openoffice.something....


I would NOT use a name prefixed with "org.openoffice....." unless I were developing something that were officially part of OOo.

You could use a name like.....

com.MyCompanyInc.OOo.MyProductName.something

In general it is good to adopt a naming scheme like this in general. I name all my Java packages this way, and all my Python packages this way. I name all my OOo components this way.

I choose "nom.DannyBrewer" because it is fairly unique. There are not likely to be too many Danny Brewer's on the planet developing OOo components. Even if so, I further differentiate my names with longer portions of the name even to avoid conflict with 500 other possible developers named "Danny Brewer". I use "nom" because some new domain naming scheme proposes to allow you to register domain names for individuals using the dot-nom convention.

The key point here is to use a name unique enough that you globally, and for all time, won't break (1) your own product and (2) somebody else's product.

Using a name like "MyTopMenuNameSet" is just asking to break both your and someone else's product.

Personally, If I bought a third-party plug in at the computer store, took it home, installed it into my OpenOffice.org and it broke another third party plug in.....

.....once I investigated and found out what the conflict was, careless developers who didn't care about stepping on someone else's stuff, I would probably disconue using the products of both developers and would wonder just how bad of code they must write if their unique naming is so poorly chosen.

Be a good citizen of the system. The developer does not own the system. The end user does. The end user might want to install other third party packages into the office in addition to your package. Imagine if you install a new commercial Photoshop plug in, only to break either Photoshop, or some other third party plug in that you already use. Imagine if you install a new game onto Windows, only to break some existing game......ooops....that last one is not too difficult to imagine.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Ondra
General User
General User


Joined: 12 Mar 2004
Posts: 10

PostPosted: Mon Apr 19, 2004 3:39 pm    Post subject: troubles with menu Reply with quote

Ok, I think that it's exactly all I want to know Idea

Thank you very much

Ondra
Back to top
View user's profile Send private message Send e-mail
xxhimanshu
General User
General User


Joined: 28 Dec 2004
Posts: 11

PostPosted: Tue Jan 18, 2005 10:07 pm    Post subject: how to create a new toolbar item on openoffice writer??? Reply with quote

Hi All,

Can anybody show me some links or help code in C or C++ or VC++ that can add the new toolbar or a button to existing toolbar in openoffice writer..i have done that in MS word but i cannot find any help for openoffice....

Any help or pointers are thoroughly appreciated.

Looking forward to any help from you guys...

thanks a lot in advance.

Regards,
Himanshu
Back to top
View user's profile Send private message Yahoo Messenger
harrybo
Power User
Power User


Joined: 27 Apr 2004
Posts: 75
Location: Germany

PostPosted: Sun May 21, 2006 4:57 am    Post subject: Reply with quote

Hello,

I could manage to implement a new top level menu and a toolbar with DannyB's example. Some additional notes:

1. I noticed, that menuitems and toolbar items were not shown in the order of their construction. They are sorted by Name. Ok, using a special naming convention, the elements can individually be arranged.

2. At the beginning it was not clear for me, how the icons, that are stored in an "Images" array are matched to the menu and toolbar elements. Of course the answer is easy: by their url, usually a macro.

Some remaining questions:

1. Toolbar-Tile: The Top Level Menu can be given a title but I couldn't find a way to name the custom toolbar. It is called "Add-On 1" How can I change this?

2. The toolbar does not appear in the customization dialog, so the user can not rearrange or hide toolbar items . How can I make the new toolbar available?

Regards
Harry
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Mon May 22, 2006 8:40 am    Post subject: Reply with quote

See
Is there a way to add (temporary) toolbar buttons? http://www.oooforum.org/forum/viewtopic.phtml?t=20152&highlight=
With OOobasic code :
To know if a toolbar is visible (C++, XDispatchHelper)http://www.oooforum.org/forum/viewtopic.phtml?t=25834&highlight=
How to change the toolbar name in the View->Toolbars menu http://www.oooforum.org/forum/viewtopic.phtml?t=29596&highlight=
handle the menu with java http://www.oooforum.org/forum/viewtopic.phtml?t=31222&highlight=
Programmatically adding to existing Menus http://www.oooforum.org/forum/viewtopic.phtml?t=18491&highlight=
OO 2.0: where are menu files and macro library files saved? http://www.oooforum.org/forum/viewtopic.phtml?t=21709&highlight=
Context Menu Intercepting http://www.oooforum.org/forum/viewtopic.phtml?t=26669
Assign a macro to the context menu http://www.oooforum.org/forum/viewtopic.phtml?t=34157&highlight=
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API 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