Page 1 of 1

UnoControlDialogModel Resizable

Posted: Tue Oct 09, 2012 9:24 pm
by rjsteele
I see that "sizeable" is one of the properties of the UnoControlDialogModel. Is setting this property to TRUE supposed to give the user the ability to resize the dialog. I have a dialog with a calc spreadsheet embedded in it. I want to allow the user to resize the dialog. The dialog also has other controls as well.

Re: UnoControlDialogModel Resizable

Posted: Wed Oct 10, 2012 2:48 pm
by hanya
It can not be changed by the API. It looks dlg:window node support resizeable attribute in XDL file but it does not work with the dialog executed by the dialog provider.
Here is an example to make a dialog through general window creation mechanism. In the case, child controls should be created by code by it is troublesome so I embed the dialog created by the dialog editor as child window into the resizeable outer dialog. You need to resize and reposition child controls yourself.

Code: Select all

' This is an example to make resizable modal dialog. 
' A dialog created by the dialog editor can be embedded 
' to make easy to create dialog.

' This example requires Standard.Dialog in application dialog 
' with list box named ListBox1.
Sub ResizableDialogTest11
  ' parent
  oParent = ThisComponent.getCurrentController()._
      getFrame().getContainerWindow()
  ' create base window as modal dialog
  oBaseDialog = CreateBaseDialog(oParent)
  ' embed the dialog created by the dialog editor
  sURL = "vnd.sun.star.script:Standard.Dialog1?location=application"
  oDialog = CreateInnerDialog(oBaseDialog, sURL)
  
  ' to show the dialog, have to be done by the outer dialog
  If oBaseDialog.execute() > 0 Then
    msgbox "Do something..."
  End If
  oBaseDialog.dispose()
End Sub


' Create new base dialog.
' @param oParent parent window peer
' @return dialog window
Function CreateBaseDialog(oParent As Variant) As Variant
  oToolkit = oParent.getToolkit()
  WA = com.sun.star.awt.WindowAttribute
  aRect = CreateUnoStruct("com.sun.star.awt.Rectangle")
  oDesc = CreateUnoStruct("com.sun.star.awt.WindowDescriptor")
  With oDesc
    .Type = com.sun.star.awt.WindowClass.SIMPLE
    .WindowServiceName = "dialog"
    .Parent = oParent
    .ParentIndex = -1
    .Bounds = aRect
    .WindowAttributes = WA.CLOSEABLE OR WA.MOVEABLE OR WA.SIZEABLE OR WA.BORDER
  End With
  oDialog = oToolkit.createWindow(oDesc)
  oDialog.addTopWindowListener(CreateUnoListener(_
      "WindowListener_", "com.sun.star.awt.XTopWindowListener"))
  oDialog.addWindowListener(CreateUnoListener(_
      "WindowListener_", "com.sun.star.awt.XWindowListener"))
  CreateBaseDialog = oDialog
End Function


' Create child dialog embedded
' @param oParent parent window
' @param sURL dialog URL, without toolbar
Function CreateInnerDialog(oParent As Variant, sURL As String) As Variant
  PS = com.sun.star.awt.PosSize
  oDP = CreateUnoService("com.sun.star.awt.ContainerWindowProvider")
  oChildDialog = oDP.createContainerWindow(sURL, "", oParent, nothing)
  oChildDialog.setPosSize(0, 0, 0, 0, PS.POS)
  oChildDialog.setVisible(True)
  aSize = oChildDialog.getPosSize()
  oParent.setPosSize(0, 0, aSize.Width, aSize.Height, PS.SIZE)
  oChildDialog.addWindowListener(CreateUnoListener(_
      "oDialogWindow_", "com.sun.star.awt.XWindowListener"))
  CreateInnerDialog = oChildDialog
End Function

' 
' XWindowListener
Sub oDialogWindow_windowResized(ev)
  ' this called indirect by resizeing of the outer dialog
  aRect = ev.Source.getPosSize()
  
  ' dialog controls have to be repositioned and resized by hand
  oListBox = ev.Source.getControl("ListBox1")
  oListBox.setPosSize(aRect.Width - 10 - oListBox.getPosSize().Width, _
                      0, 0, 0, com.sun.star.awt.PosSize.X)
End Sub
Sub oDialogWindow_windowMoved(ev)
End Sub
Sub oDialogWindow_windowShown(ev)
End Sub
Sub oDialogWindow_windowHidden(ev)
End Sub

' Listeners for base dialog
' XTopWindowListener
Sub WindowListener_disposing(ev)
End Sub
Sub WindowListener_windowOpened(ev)
End Sub
Sub WindowListener_windowClosing(ev)
  ' helps to close the window by close button of the window
  ev.Source.endExecute()
End Sub
Sub WindowListener_windowClosed(ev)
End Sub
Sub WindowListener_windowMinimized(ev)
End Sub
Sub WindowListener_windowNormalized(ev)
End Sub
Sub WindowListener_windowActivated(ev)
End Sub
Sub WindowListener_windowDeactivated(ev)
End Sub

' XWindowListener
Sub WindowListener_windowResized(ev)
  ' resize inner dialog as first child window
  aSize = ev.Source.getSize()
  ev.Source.Windows(0).setPosSize(0, 0, _
        aSize.Width, aSize.Height, com.sun.star.awt.PosSize.SIZE)
End Sub
Sub WindowListener_windowMoved(ev)
End Sub
Sub WindowListener_windowShown(ev)
End Sub
Sub WindowListener_windowHidden(ev)
End Sub

Re: UnoControlDialogModel Resizable

Posted: Thu Oct 11, 2012 4:51 pm
by rjsteele
Hanya,

Thanks for the response. I will try to implement this as soon as I can. I got pulled in another direction for the time being. Hopefully, when I do try, you will be available for follow-up questions.

Re: UnoControlDialogModel Resizable

Posted: Wed Apr 09, 2014 9:03 am
by roland65
Hi,

I've tried the ResizableDialogTest11 example and it doesn't work properly in LibreOffice 4.x : the inner child dialog is shown as a separate window (non resizable) and not embedded in the resizable parent.
Any idea on how to fix this?
Thanks a lot,
RB

Re: UnoControlDialogModel Resizable

Posted: Wed Apr 09, 2014 9:56 am
by hanya
Set "With title bar" of the dialog to No to make it embedded in the parent dialog.

Re: UnoControlDialogModel Resizable

Posted: Wed Apr 09, 2014 2:24 pm
by roland65
Very nice! I couldn't think the answer was so simple...
Thanks a lot,
RB

Re: UnoControlDialogModel Resizable

Posted: Tue Mar 09, 2021 5:03 pm
by eeigor
Please, help
hanya wrote:Set "With title bar" of the dialog to No to make it embedded in the parent dialog.
I cannot figure out how to do this. The properties of the dialog box are not available, I don't see them at all.
When a control is selected, a corresponding window with properties appears.

Error occured:

Function CreateInnerDialog(oParent As Variant, sURL As String) As Variant
PS = com.sun.star.awt.PosSize
oDP = CreateUnoService("com.sun.star.awt.ContainerWindowProvider")
oChildDialog = oDP.createContainerWindow(sURL, "", oParent, nothing)
<...>

I am only mastering dialog boxes...

Re: UnoControlDialogModel Resizable

Posted: Tue Mar 09, 2021 5:37 pm
by JeJe
Right click on the dialog instead of a control.
no titlebar.JPG

Re: UnoControlDialogModel Resizable

Posted: Tue Mar 09, 2021 5:52 pm
by JeJe
This is a great workaround... it works but I get crashes... which I can't figure out so I don't use it... its a shame - other people's mileage may vary.

If you're just starting to use dialogs I'd consider leaning the basics of the IDE before reaching for complicated workarounds in code.

The reason for your error is probably your URL or the parent you're passing to the function.

Re: UnoControlDialogModel Resizable

Posted: Tue Mar 09, 2021 7:50 pm
by eeigor
JeJe wrote:Right click on the dialog instead of a control.
No, something is wrong here.
Right-clicking on the dialog brings up one item: "Paste". I have never seen the properties of a dialog box before and cannot get to them.
I'm in Basic IDE, just in case. Some devilry...

UPD
OK. Found
JeJe wrote:The reason for your error is probably your URL...
But the error remained on the same line.
oChildDialog = oDP.createContainerWindow(sURL, "", oParent, nothing)

I cannot understand what is the matter. The dialog exists and the URL is correct.
sURL = "vnd.sun.star.script:Standard.Help?location=application"
"Help" is a name of my dialog that is placed in Standard lib of a document.
hanya wrote:Here is an example to make a dialog through general window creation mechanism.
I use that code w/o additions (the post #2).

Re: UnoControlDialogModel Resizable

Posted: Tue Mar 09, 2021 9:56 pm
by JeJe
Your sURL is wrong, its got ?location=application instead of ?location=document

(I can't remember whether that code works with a dialog in a document or whether it needs to be in MyMacros ie location=application instead.)

Re: UnoControlDialogModel Resizable

Posted: Wed Mar 10, 2021 2:02 am
by JeJe
Other thread based on this one:

viewtopic.php?f=21&t=92867

Re: UnoControlDialogModel Resizable

Posted: Wed Mar 10, 2021 5:28 am
by eeigor
JeJe wrote:Your sURL is wrong, its got ?location=application instead of ?location=document
' sURL = "vnd.sun.star.script:Standard.Help?language=Basic&location=document"
sURL = "vnd.sun.star.script:Standard.Help?location=document"
Here it is, below

Re: UnoControlDialogModel Resizable

Posted: Wed Mar 10, 2021 6:02 am
by JeJe
Try putting the dialog in mymacros somewhere and using location=application. As I said, it might not work for a dialog in a document.

The other one I linked to might do one in a document, I don't know.

Re: UnoControlDialogModel Resizable

Posted: Wed Mar 10, 2021 6:06 am
by eeigor
Moved the code and dialog to "My Macros & Dialogs". It works. Only this way and nothing else? I need to put a dialog in a document.
This is not a library dialogue, it is part of a document.

Re: UnoControlDialogModel Resizable

Posted: Wed Mar 10, 2021 2:02 pm
by JeJe
It might have to be a non-resizable dialog if no-one else can solve that problem for a document url.

There's another way of creating dialogs... that's entirely with code and not with the IDE.. create a dialog from scratch, add windows for all the buttons etc, add listeners... but that's very complicated and time consuming and people use Basic to avoid that.

There are also any number of ways to resize a dialog without using the dialog borders with dialog.setpossize. eg. you could have a textbox to set the width, another for the height... clunky but its a way...

Re: UnoControlDialogModel Resizable

Posted: Wed Mar 10, 2021 7:15 pm
by eeigor
@JeJe, could you modify this example and create a resizable dialog without a nested window, but adding one control programmatically on the fly. That very complicated and time-consuming method is right for me.

UPD
How to add a control to the base dialog?
oEdit1 = CreateCtr("Edit", 10, 10, 200, 100, Array("AutoVScroll", "MultiLine"), Array(True, True))
<?>.addControl("Edit1", oEdit1)

Code: Select all

Function CreateCtr(CtrType, nX, nY, nWidth, nHeight, sNames, vProps)
	Dim oCtr As Object, oCtrModel As Object
	oCtr = createUnoService("com.sun.star.awt.UnoControl" & CtrType )
	oCtrModel = createUnoService("com.sun.star.awt.UnoControl" & CtrType & "Model")
	oCtrModel.setPropertyValues(sNames, vProps)
	With oCtr
		.setModel(oCtrModel)
		.setPosSize(nX, nY, nWidth, nHeight, com.sun.star.awt.PosSize.POSSIZE)
	End With
	CreateCtr() = oCtr  'model can be got from returned value
End Function
UPD
This code from @Villeroy helped me but can't figure it out. Help is still needed. This is my first time working with dialogues.

Re: UnoControlDialogModel Resizable

Posted: Wed Mar 10, 2021 10:28 pm
by JeJe
There's an example here of creating a resizable dialog with a grid control.

Edit: better link to same thread:

https://dev.api.openoffice.narkive.com/ ... -ooo-3-3-0

Re: UnoControlDialogModel Resizable

Posted: Wed Mar 10, 2021 10:36 pm
by eeigor
Thank you. I understood. So far, however, it is not entirely clear why these lines are needed. I did without them.

oFrame = createUnoService("com.sun.star.frame.Frame")
oFrame.initialize(oContWin)
StarDesktop.getFrames().append(oFrame)
oFrame.Name = "TestGridFrame"
oFrame.Title = "TestGridTitle"

Re: UnoControlDialogModel Resizable

Posted: Thu Mar 11, 2021 1:41 am
by JeJe
A half-way house would be to use the IDE to create a dialog as normal - and then use generic code to clone the controls onto a resizable dialog.

It needs a heap of work... but the attached is a start... See the module, the dialog it creates isn't the one in the IDE but a clone.

Edit: apart from adding the controls, largely based on roland65's Resizable dialog code linked to above.

Re: UnoControlDialogModel Resizable

Posted: Thu Mar 11, 2021 9:40 am
by eeigor
@JeJe, now everything is clear to me. Thank you for your time. Then I will continue myself...

Re: UnoControlDialogModel Resizable

Posted: Sat Mar 13, 2021 5:22 pm
by JeJe
Update to clone dialog code in new thread of its own,

viewtopic.php?f=21&t=104768&p=508044#p508044

Re: UnoControlDialogModel Resizable

Posted: Sat Mar 13, 2021 8:14 pm
by Villeroy
Thank you. This one works very well.