UnoControlDialogModel Resizable

Creating a macro - Writing a Script - Using the API

UnoControlDialogModel Resizable

Postby rjsteele » Tue Oct 09, 2012 9:24 pm

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.
Raymond
Solaris 10 x86 StarrOffice 9 - basis3.1
rjsteele
 
Posts: 23
Joined: Fri Jul 27, 2012 9:20 pm

Re: UnoControlDialogModel Resizable

Postby hanya » Wed Oct 10, 2012 2:48 pm

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   Expand viewCollapse view
' 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
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: UnoControlDialogModel Resizable

Postby rjsteele » Thu Oct 11, 2012 4:51 pm

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.
Raymond
Solaris 10 x86 StarrOffice 9 - basis3.1
rjsteele
 
Posts: 23
Joined: Fri Jul 27, 2012 9:20 pm

Re: UnoControlDialogModel Resizable

Postby roland65 » Wed Apr 09, 2014 9:03 am

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
LibreOffice 5.x on Ubuntu
roland65
 
Posts: 21
Joined: Tue Oct 18, 2011 6:41 pm

Re: UnoControlDialogModel Resizable

Postby hanya » Wed Apr 09, 2014 9:56 am

Set "With title bar" of the dialog to No to make it embedded in the parent dialog.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: UnoControlDialogModel Resizable

Postby roland65 » Wed Apr 09, 2014 2:24 pm

Very nice! I couldn't think the answer was so simple...
Thanks a lot,
RB
LibreOffice 5.x on Ubuntu
roland65
 
Posts: 21
Joined: Tue Oct 18, 2011 6:41 pm

Re: UnoControlDialogModel Resizable

Postby eeigor » Tue Mar 09, 2021 5:03 pm

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...
Ubuntu 18.04 LTS • LibreOffice 7.1.1.2 Community
eeigor
 
Posts: 128
Joined: Sun Apr 12, 2020 10:56 pm

Re: UnoControlDialogModel Resizable

Postby JeJe » Tue Mar 09, 2021 5:37 pm

Right click on the dialog instead of a control.

no titlebar.JPG
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1500
Joined: Wed Mar 09, 2016 2:40 pm

Re: UnoControlDialogModel Resizable

Postby JeJe » Tue Mar 09, 2021 5:52 pm

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.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1500
Joined: Wed Mar 09, 2016 2:40 pm

Re: UnoControlDialogModel Resizable

Postby eeigor » Tue Mar 09, 2021 7:50 pm

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).
Attachments
Снимок экрана от 2021-03-09 20-59-31.png
Ubuntu 18.04 LTS • LibreOffice 7.1.1.2 Community
eeigor
 
Posts: 128
Joined: Sun Apr 12, 2020 10:56 pm

Re: UnoControlDialogModel Resizable

Postby JeJe » Tue Mar 09, 2021 9:56 pm

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.)
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1500
Joined: Wed Mar 09, 2016 2:40 pm

Re: UnoControlDialogModel Resizable

Postby JeJe » Wed Mar 10, 2021 2:02 am

Other thread based on this one:

viewtopic.php?f=21&t=92867
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1500
Joined: Wed Mar 09, 2016 2:40 pm

Re: UnoControlDialogModel Resizable

Postby eeigor » Wed Mar 10, 2021 5:28 am

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
Attachments
Снимок экрана от 2021-03-10 06-30-50.png
Снимок экрана от 2021-03-10 06-26-16.png
Ubuntu 18.04 LTS • LibreOffice 7.1.1.2 Community
eeigor
 
Posts: 128
Joined: Sun Apr 12, 2020 10:56 pm

Re: UnoControlDialogModel Resizable

Postby JeJe » Wed Mar 10, 2021 6:02 am

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.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1500
Joined: Wed Mar 09, 2016 2:40 pm

Re: UnoControlDialogModel Resizable

Postby eeigor » Wed Mar 10, 2021 6:06 am

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.
Attachments
Снимок экрана от 2021-03-10 07-01-14.png
Снимок экрана от 2021-03-10 07-01-14.png (10.21 KiB) Viewed 1311 times
Ubuntu 18.04 LTS • LibreOffice 7.1.1.2 Community
eeigor
 
Posts: 128
Joined: Sun Apr 12, 2020 10:56 pm

Re: UnoControlDialogModel Resizable

Postby JeJe » Wed Mar 10, 2021 2:02 pm

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...
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1500
Joined: Wed Mar 09, 2016 2:40 pm

Re: UnoControlDialogModel Resizable

Postby eeigor » Wed Mar 10, 2021 7:15 pm

@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   Expand viewCollapse view
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.
Ubuntu 18.04 LTS • LibreOffice 7.1.1.2 Community
eeigor
 
Posts: 128
Joined: Sun Apr 12, 2020 10:56 pm

Re: UnoControlDialogModel Resizable

Postby JeJe » Wed Mar 10, 2021 10:28 pm

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
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1500
Joined: Wed Mar 09, 2016 2:40 pm

Re: UnoControlDialogModel Resizable

Postby eeigor » Wed Mar 10, 2021 10:36 pm

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"
Ubuntu 18.04 LTS • LibreOffice 7.1.1.2 Community
eeigor
 
Posts: 128
Joined: Sun Apr 12, 2020 10:56 pm

Re: UnoControlDialogModel Resizable

Postby JeJe » Thu Mar 11, 2021 1:41 am

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.
Attachments
clone dialog.odt
(11.88 KiB) Downloaded 38 times
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1500
Joined: Wed Mar 09, 2016 2:40 pm

Re: UnoControlDialogModel Resizable

Postby eeigor » Thu Mar 11, 2021 9:40 am

@JeJe, now everything is clear to me. Thank you for your time. Then I will continue myself...
Ubuntu 18.04 LTS • LibreOffice 7.1.1.2 Community
eeigor
 
Posts: 128
Joined: Sun Apr 12, 2020 10:56 pm

Re: UnoControlDialogModel Resizable

Postby JeJe » Sat Mar 13, 2021 5:22 pm

Update to clone dialog code in new thread of its own,

viewtopic.php?f=21&t=104768&p=508044#p508044
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1500
Joined: Wed Mar 09, 2016 2:40 pm

Re: UnoControlDialogModel Resizable

Postby Villeroy » Sat Mar 13, 2021 8:14 pm

Thank you. This one works very well.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29576
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests