Hey,

I implemented a custom menu item using one of the examples.  However this
extra menu item disappears as soon as a printpreview screen is invoked.  The
menu item doesn't return when the printpreview is closed.

Here's the code I used



> public void doMenuExtras() {
>         try {
>             //getting the extra menu names
>             getConditionList();
>             //you need the top window of the openoffice window
>             if (xTraMenuList.size() > 0) {
> 
>                 String sMenuBar = "private:resource/menubar/menubar";
>                 XComponentContext context =
> iConnection.getComponentContext();
>                 XMultiComponentFactory serviceMgr =
> context.getServiceManager();
>                 XPropertySet xps = (XPropertySet)
> UnoRuntime.queryInterface(
>                         XPropertySet.class, aFrame);
>                 XLayoutManager xLayoutManager = (XLayoutManager)
> UnoRuntime.queryInterface(
>                         XLayoutManager.class,
>                         xps.getPropertyValue("LayoutManager"));
> 
>                 //getting the menubar of the topwindow by the
> layoutmanager
>                 XUIElement oMenuBar = xLayoutManager.getElement(sMenuBar);
>                 menuBarProps = (XPropertySet) UnoRuntime.queryInterface(
>                         XPropertySet.class, oMenuBar);
> 
>                 //the menubar we want is a property of the XUIElement
> oMenuBar
>                 XMenuBar bar = (XMenuBar)
> UnoRuntime.queryInterface(XMenuBar.class,
> menuBarProps.getPropertyValue("XMenuBar"));
> 
>                 XUIElementSettings xoMenuBarSettings =
> (XUIElementSettings) UnoRuntime
>                         .queryInterface(XUIElementSettings.class,
> oMenuBar);
>                 XIndexContainer oMenuBarSettings = (XIndexContainer)
> UnoRuntime
>                         .queryInterface(XIndexContainer.class,
> xoMenuBarSettings
>                                 .getSettings(true));
> 
>                 XSingleComponentFactory factory =
> (XSingleComponentFactory)
>                         UnoRuntime
>                                
> .queryInterface(XSingleComponentFactory.class,
>                                         oMenuBarSettings);
> 
> 
>                 PropertyValue[] propsContainer = (PropertyValue[])
> oMenuBarSettings.getByIndex(0);
>                 XIndexContainer container = null;
> 
>                 for (int i = 0; i < propsContainer.length; i++) {
>                     if
> (propsContainer[i].Name.equals("ItemDescriptorContainer")) {
>                         container = (XIndexContainer)
> UnoRuntime.queryInterface(XIndexContainer.class, propsContainer[i].Value);
> 
>                     }
>                 }
> 
>                 PropertyValue[] subPv1 = createMenuItem(".uno:Print++",
> FENIKS_PRINT, factory);
> 
>                 container.insertByIndex(26, subPv1);
>                 xoMenuBarSettings.setSettings(oMenuBarSettings);
>                 XTopWindow topWindow = (XTopWindow)
> UnoRuntime.queryInterface(XTopWindow.class,
> xFrameWindow.getUNOWindowPeer());
> 
>                 //inserting an new menu name
>                 bar.insertItem((short) 0, "~Paragraaf",
> com.sun.star.awt.MenuItemStyle.AUTOCHECK, (short) 0);
>                 //setting the menu
>                 bar.setPopupMenu((short) 0, getPopupMenu());
> 
>                 //adding an menuListener
>                 bar.addMenuListener(this);
> 
>                 //setting the new menubar
>                 topWindow.setMenuBar(bar);
>                 //not setting it persistent otherwise is will be added
> multiple times on every reload
>                 menuBarProps.setPropertyValue("Persistent", false); //true
> helpt niet voor het print prev prob
> 
> 
>             }
>         } catch (Exception e) {
>             e.printStackTrace();  //To change body of catch statement use
> File | Settings | File Templates.
>         }
>     }
> 
> public XPopupMenu getPopupMenu() {
>         XPopupMenu xPopupMenu = null;
>         try {
>             // create a popup menu
>             XComponentContext context = iConnection.getComponentContext();
>             Object oPopupMenu =
> context.getServiceManager().createInstanceWithContext("stardiv.Toolkit.VCLXPopupMenu",
> context);
>             xPopupMenu = (XPopupMenu)
> UnoRuntime.queryInterface(XPopupMenu.class, oPopupMenu);
>             XMenuExtended xMenuExtended = (XMenuExtended)
> UnoRuntime.queryInterface(XMenuExtended.class, xPopupMenu);
>             XTextSectionsSupplier oTSSupp = (XTextSectionsSupplier)
> UnoRuntime.queryInterface(
>                     XTextSectionsSupplier.class, aDocument);
> 
>             XNameAccess nameAccess = oTSSupp.getTextSections();
> 
> 
>             for (int i = 0; i < xTraMenuList.size(); i++) {
>                 XPropertySet pAccess = (XPropertySet)
> UnoRuntime.queryInterface(XPropertySet.class,
> nameAccess.getByName(xTraMenuList.get(i)));
>                 xPopupMenu.insertItem((short) i, xTraMenuList.get(i),
> (short) (MenuItemStyle.CHECKABLE + MenuItemStyle.AUTOCHECK), (short) i);
> 
>                 if((Boolean)pAccess.getPropertyValue("IsVisible")){ 
>                     xPopupMenu.checkItem((short)i,true);
>                 }
>             }
>             xPopupMenu.addMenuListener(this);
>         } catch (Exception e) {
>             e.printStackTrace();
>             throw new TechnicalException("popupmenu problem",this);
>         }
>         return xPopupMenu;
>     }
> 
-- 
View this message in context: 
http://www.nabble.com/custom-menu-item-disappearing-after-printpreview-tp22741195p22741195.html
Sent from the openoffice - dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to