Alle 12:27, mercoledì 10 ottobre 2007, Zbigniew Banach ha scritto:
> Hi everyone,
>
> I posted a similar question a few months back, but now I'm more or less
> running around the same problem. I've done some extra research, so I
> hope someone will be able to help.
>
> I want to create and show a non-modal dialog from one macro (I'm using
> Python) and once it's open I want to access and modify its controls from
> another macro. I haven't found a way to store a global reference to the
> dialog window, so I'm trying to access it through the frame hierarchy.
> It's almost there, but I'm finally stuck.
>
> First I create and display the dialog in one macro -- pretty standard
> stuff except that I pass the current frame's container window as the peer:
>
> smgr = XSCRIPTCONTEXT.getComponentContext().ServiceManager
> ctx = XSCRIPTCONTEXT.getComponentContext()
> dialogModel = smgr.createInstanceWithContext(
>               "com.sun.star.awt.UnoControlDialogModel", ctx)
> dialogModel.Title = "FooBar"
> controlContainer = smgr.createInstanceWithContext(
>                    "com.sun.star.awt.UnoControlDialog", ctx)
> controlContainer.setModel(dialogModel)
> toolkit = smgr.createInstanceWithContext(
>           "com.sun.star.awt.Toolkit", ctx)
> containerWin = XSCRIPTCONTEXT.getDocument().getCurrentController()
>                .getFrame().getContainerWindow()
> controlContainer.createPeer(toolkit, containerWin)
> controlContainer.setVisible(True)

This is the old way, when men were men and created their own AWT-Windows :-)
Apart from jokes, is there any reasons for not using the (relatively) new 
css.awt.DialogProvider ?
In this way you could design the dialog in the Starbasic IDE and then recall 
it from anywhere.


>
> Now the dialog is displayed (non-modally, because I used setVisible()
> instead of execute()), I want to access it via the frame hierarchy from
> another macro. Using through the same frame's toolkit and going through
> its TopWindows, in a separate macro I've managed to get hold of what
> seems to be the dialog's container window (it's the only one with a
> Title, and it's the same Title as for my dialog):
>
> tk = XSCRIPTCONTEXT.getDocument().getCurrentController().getFrame()
>      .getContainerWindow().getToolkit()
> for i in range(0, tk.getTopWindowCount()):
>     currWin = tk.getTopWindow(i)
>     if "Title" in dir(currWin) and currWin.Title == "FooBar":
>         dialogRef = currWin
>         break
>
> (For non-Python speakers, dir() returns a sequence of available
> attributes). Now dialogRef is an XTopWindow and XDialog, and a call to
> its getWindows() shows an XWindow and XButton (presumably the dialog
> window and default close button). However, I can't find a way of getting
> the dialog model from dialogRef nor its inner XWindow, which is what I
> really need.
>
> So my question: is it at all possible to achieve what I'm doing, i.e.
> access the controls of an open dialog window through the frame
> hierarchy? If so, am I going the right way? 

Perhaps I can propose an idea for a workaround, see below:

(Basic example - adapt to your context)
----------------------------------------------------
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
oFrame = CreateUnoService("com.sun.star.frame.Frame")

'initialize the frame with a parent window
oFrame.initialize(StarDesktop.ActiveFrame.ContainerWindow)

'set the dialog as component (with no controller)
oFrame.setComponent(oDlg, Null)

'insert the new frame in desktop hierarchy
oFrame.Name = "MyOwnFrame" 'use an unique name
StarDesktop.Frames.append(oFrame)

'restore the pos&size of the dialog
With oDlg.Model
        .PositionX = 130
        .PositionY = 60
        .Width = 130
        .Height = 130
End With

'show the dialog
oDlg.execute
----------------------------------------------------


As you can see, the dialog is now attached to a frame that belongs to the 
frames hierarchy.
In this way you can access to your dialog from anywhere in (more or less) this 
way:

(Basic example - adapt to your context)
----------------------------------------------------
oMyFrame = StarDesktop.findFrame("MyOwnFrame", _
 com.sun.star.frame.FrameSearchFlag.GLOBAL)
oDialog = oMyFrame.ComponentWindow
----------------------------------------------------

Obviously, in the real world you should check if the result of the findFrame 
method is not null before to access to its members


> And if not, what could I do 
> to get a similar effect (maybe abandon dialogs and create a window some
> other way)? 

Of course you can use a TopWindow instead of an UnoDialog this would give you 
more flexibility but at the cost of some more code lines, especially for the 
UnoControls management


> For my original question, Mathias Bauer suggested 
> implementing a singleton UNO service for the dialog,
> but I was hoping 
> for some simpler way. I'm basically trying to create a glossary window
> for my app, acting something like the OOo Stylist (non-modal,
> always-on-top) and fully accessible to macros from the API.
>
> Bit long for a question, but it seems to me a useful problem to resolve.
> Hope someone can help me out here.

regards
Paolo Mantovani

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to