[BASIC] Resizable dialog
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
[BASIC] Resizable dialog
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
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
- Attachments
-
- ResizableDialog-0.6.zip
- (4.76 KiB) Downloaded 1001 times
Last edited by roland65 on Wed Mar 21, 2018 5:38 pm, edited 4 times in total.
LibreOffice 7.5.x on Ubuntu
Re: [BASIC]Resizable dialog
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)
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)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC]Resizable dialog
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
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC]Resizable dialog
It doesn't work for me, only windows(2) works.JeJe wrote:In Windowresized it needs to go back to windows(0) not windows(2)
LibreOffice 7.5.x on Ubuntu
Re: [BASIC]Resizable dialog
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...JeJe wrote:For a non-modal dialog I found that putting dispose in the windowClosing worked - no need for the wait loop
LibreOffice 7.5.x on Ubuntu
Re: [BASIC]Resizable dialog
Try declaring oBaseDialog using global
Code: Select all
global oBaseDialog
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC]Resizable dialog
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.
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.
Last edited by JeJe on Mon Mar 19, 2018 7:17 pm, edited 1 time in total.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC]Resizable dialog
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...
That's crappy...
LibreOffice 7.5.x on Ubuntu
Re: [BASIC]Resizable dialog
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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC]Resizable dialog
Investigating - in LibreOffice's windows(0) and windows(1) are scrollbars - you can see them by using setvisible to true.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC]Resizable dialog
The windows bit is easy to work round (while both have a GetProductName function in the same place anyway)
and
EDIT: the functions are both identical - so its easy just to include it in your own code.
Code: Select all
dim windowIndex
Sub ResizableModalDialog
if instr(1, tools.Misc.GetProductName(),"Open") <> 1 then windowIndex = 2
...etc
Code: Select all
ev.Source.Windows(windowIndex).setPosSize(0, 0, aSize.Width, aSize.Height, com.sun.star.awt.PosSize.SIZE)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC]Resizable dialog
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.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC] Resizable dialog
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!
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!
LibreOffice 7.5.x on Ubuntu
Re: [BASIC] Resizable dialog
A better way to get the windows count is, before the inner dialog is added use:
Code: Select all
windowIndex= oBaseDialog.AccessibleContext.getAccessibleChildCount
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC] Resizable dialog
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!JeJe wrote:A better way to get the windows count is, before the inner dialog is added use:
windowIndex= oBaseDialog.AccessibleContext.getAccessibleChildCount
LibreOffice 7.5.x on Ubuntu
Re: [BASIC] Resizable dialog
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...
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.
Code: Select all
oDialog = CreateInnerModalDialog(oModalBaseDialog, sURL)
msgbox oModalBaseDialog.AccessibleContext.getAccessibleChildCount
Anyway, there's the other method.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC] Resizable dialog
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)...
So, I updated the code (and also fixed a typo)...
LibreOffice 7.5.x on Ubuntu
Re: [BASIC] Resizable dialog
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
Non-resizable non-model dialog based on the inner dialog code:
viewtopic.php?f=9&t=81578&p=494238#p494222
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC] Resizable dialog
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
https://www.openoffice.org/api/docs/com ... iptor.html
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [BASIC] Resizable dialog
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)