Page 1 of 1
[BASIC] Resizable dialog
Posted: Mon Mar 19, 2018 10:48 am
by roland65
I finally managed to implement a fully resizable dialog in Basic. I used this
thread and the work of Hanya as a starting point.
Two versions (modal and non modal) of a simple dialog with a text field and a close button are provided. The dialog box can be fully resized with the mouse using handles, as any other window.
The code is attached as a library. To use it:
1. Unzip the ResizableDialog.zip file to a folder called 'ResizableDialog'
2. In Writer, open the Basic editor and then go to Tools / Macros / Organize Dialogs and in the opening dialog click on the Libraries tab
3. Click on the Import button and then select the dialog.xlb file of the ResizableDialog folder, then click Open and import the library
4. In the left tab of the basic editor, go to the Module1 module of the ResizableDialog library and position the cursor somewhere on the ResizableModalDialog function and press F5. You will see the resizable modal dialog and you will be able to resize it with the mouse. You can do the same with the non modal dialog, by positioning the cursor lower in the ResizableDialog function and pressing F5
I tested this stuff in LibreOffice 5.4.5.1, on Ubuntu 16.04
[EDIT1] Updated version that works in both LibreOffice and OpenOffice (thanks to Jeje, see discussion below)
[EDIT2] Fixed a typo and used a better method to deal with the different window indexes in LibreOffice and OpenOffice
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 3:06 pm
by JeJe
You wanted it too huh! After hours of failing and having posted a crybaby message about not getting it to work at the bottom of that thread I managed to get it to work in a library not attached to the document so location=application succeeded... so I thought, "What an idiot I am" and quietly deleted the message.
In Windowresized it needs to go back to windows(0) not windows(2)
Code: Select all
ev.Source.Windows(0).setPosSize(0, 0, aSize.Width, aSize.Height, com.sun.star.awt.PosSize.SIZE)
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 3:17 pm
by JeJe
For a non-modal dialog I found that putting dispose in the windowClosing worked - no need for the wait loop.
Code: Select all
Sub WindowListener_windowClosing(ev)
' Close window using the window bar close button
' ev.Source.setVisible(FALSE)
' closed = TRUE
ev.source.dispose
End Sub
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 4:14 pm
by roland65
JeJe wrote:In Windowresized it needs to go back to windows(0) not windows(2)
It doesn't work for me, only windows(2) works.
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 4:18 pm
by roland65
JeJe wrote:For a non-modal dialog I found that putting dispose in the windowClosing worked - no need for the wait loop
For me, it works for the window close (x) button but not for the Close dialog button: I get an error "Object variable not set" in the CloseDialog() function...
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 6:59 pm
by JeJe
Try declaring oBaseDialog using global
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 7:15 pm
by JeJe
The Windows() bit is interesting.
I see on LibreOffice with Windows(2) it works
with Windows(0) nothing bad happens but the inner window just doesn't resize
On OO Windows(0) works
Windows(2) gives a "inadmissible value or data type. Index out of defined range" message.
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 7:16 pm
by roland65
I did some tests in Windows 7, these differences are between LibreOffice / OpenOffice: if LibreOffice, then windows(2) and error when removing the while loop and if OpenOffice, then windows(0) and no error when removing the while loop.
That's crappy...
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 7:25 pm
by JeJe
I noticed recently OpenOffice's stand alone scrollbar didn't work in LibreOffice... I guess they're diverging to the point where code that runs on both is going to be difficult.
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 8:18 pm
by JeJe
Investigating - in LibreOffice's windows(0) and windows(1) are scrollbars - you can see them by using setvisible to true.
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 8:49 pm
by JeJe
The windows bit is easy to work round (while both have a GetProductName function in the same place anyway)
Code: Select all
dim windowIndex
Sub ResizableModalDialog
if instr(1, tools.Misc.GetProductName(),"Open") <> 1 then windowIndex = 2
...etc
and
Code: Select all
ev.Source.Windows(windowIndex).setPosSize(0, 0, aSize.Width, aSize.Height, com.sun.star.awt.PosSize.SIZE)
EDIT: the functions are both identical - so its easy just to include it in your own code.
Re: [BASIC]Resizable dialog
Posted: Mon Mar 19, 2018 9:38 pm
by JeJe
I don't get a problem in LibreOffice with a Global declaration for the oBaseDialog - so just 2 or 0 for the windows() value does it here, no need to use wait.
Re: [BASIC] Resizable dialog
Posted: Tue Mar 20, 2018 10:55 am
by roland65
Thanks for the windowIndex tip!
However, the 'global oBaseDialog' tip doesn't work for me: in this case the non modal window doesn't resize properly, in both LibreOffice and OpenOffice.
So I stick with the wait loop for now.
I've updated the code, thanks!
Re: [BASIC] Resizable dialog
Posted: Tue Mar 20, 2018 8:27 pm
by JeJe
A better way to get the windows count is, before the inner dialog is added use:
Code: Select all
windowIndex= oBaseDialog.AccessibleContext.getAccessibleChildCount
Re: [BASIC] Resizable dialog
Posted: Wed Mar 21, 2018 9:41 am
by roland65
JeJe wrote:A better way to get the windows count is, before the inner dialog is added use:
windowIndex= oBaseDialog.AccessibleContext.getAccessibleChildCount
This doesn't work for me in LibreOffice. I get windowIndex=0 before oDialog = CreateInnerDialog(oBaseDialog, sURL) and 1 after, not 2 in both cases!
Re: [BASIC] Resizable dialog
Posted: Wed Mar 21, 2018 12:26 pm
by JeJe
Sorry yeah, I didn't test thoroughly enough. For your modal one in LibreOffice I get 0 before the inner dialog is added and 3 afterwards, that's when to do it and 1 needs to be subtracted...
Code: Select all
oDialog = CreateInnerModalDialog(oModalBaseDialog, sURL)
msgbox oModalBaseDialog.AccessibleContext.getAccessibleChildCount
For your non-modal one its zero and 1. If I change the call to the CreateModalBaseDialog from CreateBaseDialog which looks identical to me, its 0 and 3 as well but scrollbars become visible. Your two sets of routines are different in some way.
Anyway, there's the other method.
Re: [BASIC] Resizable dialog
Posted: Wed Mar 21, 2018 5:42 pm
by roland65
I finally found a better trick (IMHO) for the window index issue. In WindowListener_windowResized(), I test if ev.Source.Windows(0) has the Visible property. If true, then it's OpenOffice and window index is 0, if false then it's LibreOffice and window index is 2.
So, I updated the code (and also fixed a typo)...
Re: [BASIC] Resizable dialog
Posted: Thu Jun 11, 2020 10:54 am
by JeJe
Just a warning/note that I find there's a crash if the document window is closed before the dialog is if its non-modal. And after much trying I couldn't find a way round it. That can't happen if its modal of course as the dialog must be close first.
Non-resizable non-model dialog based on the inner dialog code:
viewtopic.php?f=9&t=81578&p=494238#p494222
Re: [BASIC] Resizable dialog
Posted: Thu Mar 11, 2021 1:35 am
by JeJe
Looking at this again in connection with another thread I see there are actually modaldialog and modelessdialog options for the WindowDescriptor - no need for a do wait loop or separate code for them except to handle different showing/closing ie. execute vs setvisible.
https://www.openoffice.org/api/docs/com ... iptor.html
Re: [BASIC] Resizable dialog
Posted: Sat Mar 13, 2021 5:21 pm
by JeJe
I've posted a slightly different approach here:
viewtopic.php?f=21&t=104768&p=508044#p508044