On 8/10/05, Andreas Schlüns <[EMAIL PROTECTED]> wrote:
Hello Andrzej !

> Hi Andreas !
> I think I'm in a dead point right now, I can't figure this out :-(
> I've been trying to get the menubar retrieving done for the
> whole afternoon, yet without effect.
>
> First, I implemented your basic example in my component,
> more less like this :
>
>  Reference< css::beans::XPropertySet > xFrameProp(xFrame, UNO_QUERY_THROW);
>  Reference< XLayoutManager > xLayout;
>  Any aProp =
> xFrameProp->getPropertyValue(::rtl::OUString::createFromAscii("LayoutManager"));
> aProp >>= xLayout;
> Reference< css::ui::XUIElement > xMenu
> (xLayout->getElement(::rtl::OUString::createFromAscii("private:resource/menubar/menubar")));
>         if( xMenu.is()) printf("*** properly retrieved xMenu ***\n");
>                 else {
> xLayout->createElement(::rtl::OUString::createFromAscii("private:resource/menubar/menubar"));
>                         xMenu = Reference<css::ui::XUIElement
>  >(xLayout->getElement(::rtl::OUString::createFromAscii("private:resource/menubar/menubar")

This looks good ... but .-)
The UIElement returned by xLayout->getElement() isnt the menu bar
object. It's a wrapper around it. You have to query this xMenu object
for it's XPropertySet interface and ask for it's property "XMenuBar".
This property can then be used as XMenuBar reference to be set on a
XTopWindow->setMenubar() call.

Yes, I know, I used the wrong term in my post. I meant the UIElement -
I can't get it from the layout manager, nor can I create it :-(
I don't know why this happens. If I run this code

       xFrame = StarDesktop.findFrame("_blank", 0)
       xFrame.getContainerWindow().setVisible(TRUE)
       xFrame.loadComponentFromURL("private:factory/scalc", "", 0, DimArray())


       xFrameProps   = xFrame
       xLM           = xFrameProps.getPropertyValue("LayoutManager")
       xMenuUIElem   = xLM.getElement("private:resource/menubar
/menubar")
       if isNull(xMenuUIElem) then
               xLM.createElement("private:resource/menubar/menubar")
               xMenuUIElem = xLM.getElement("private:resource/menubar/menubar")
       endif

       if isNull(xMenuUIElem) then
               msgbox "Error: no menu"
               exit sub
       endif

it works fine.

On the other side you may be dont checked the "else" switch.
If the document was loaded, there is may be nor menu bar available.
But it's possible to create one.

Yes, it should be possible, but for some reason it's not :-(
I'll put the full code here :

http://iapart.net/dav/soc/menu_problem/

in a minute.

That's why you have to make the following:

// try to retrieve the menu bar wrapper
xMenuWrapper = xLayout->getElement("")
// if it does not exists ...
if ! xMenuWrapper.is()
        // ... create it ...
        xLayout->createElement("")
        // ... and try to retrieve it again.
        xMenuWrapper = xLayout->getElement("")
// if no menu bar wrapper exists and could not be created successfully
// throw a RuntimeException to show this unexpected situation !
if ! xMenuWrapper.is ()
        throw RuntimeException();
// Otherwise get the real XMenuBar interface from this wrapper.
xMenuBar = xMenuWrapper->getPropertyValue("XMenuBar");

> but I couldn't retrieve the menubar.
> I also tried to retrieve the "_blank" frame from the desktop and get the
> layout manager for that frame, that didn't work either. I made a couple
> of other tryes, I even tried retrieving an XTopWindow using the
> XExtendedToolkit, but nothing worked.
>
> Then I tried doing a similar thing from basic (using the child frame
> returned by
> my component's createInstance) - still no joy.
>
> Then I  figured I'll check the interfaces supported by the tabcontrol's
> parent :
>
>  oTabWinFactory = createUnoService( "com.sun.star.frame.TabWindowFactory" )
>  oTabWindow     = oTabWinFactory.createInstanceWithContext(
> GetDefaultContext() )
>  oParentWindow  = oTabWindow.getPropertyValue("ParentWindow")
> msgbox oParentWindow.dbg_supportedInterfaces
>
> the XTopWindow isn't on that list :/
> is that why I can't get the menu? You said that only the windows that
> implement this interface have a menubar. But why can't I create one?
>

The menu bar must be retrieved from the layout manager ... not from the
parent window !
Yes, but doesn't it make a difference which frame you are using for retrieving the
XLayoutManager ? I mean is the layout manager a singleton or is it something that
each frame has ? I think the latter, and then if I get a LayoutManager for a frame that
isn't contained in a TopWindow I won't find the menubar UIElement there. But I still
should be able to create one, right ?
 

On the other side you are right ... the returned parent window of the
TabControl does not provide the right interface .-(
The returned window isnt the most upper window ... it's another child
window of it.

Hierarchy:
        TabControl
        [
                TopWindow (1)
                        -> ChildWindow (2) with TabButtons
                        -> ChildWindow (3) to layout Frames there
        ]

You will get the ChildWindow (3); which isnt the window you need.
I thing we have to adopt the TabControl a little bit.
May be there will be another property: "TopWindow", which returns the
real top window of this control and can be used.

Sorry for that .-)

No problem, could you put the TabController's source code somewhere where I could see it?
I'm interested in how it's done.

Regards,
Andrzej

Reply via email to