[BASIC] Resizable dialog

Creating Extension - Shared Libraries
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 forum is not for asking questions about writing your own macros.
Post Reply
roland65
Posts: 21
Joined: Tue Oct 18, 2011 6:41 pm

[BASIC] Resizable dialog

Post 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
Attachments
ResizableDialog-0.6.zip
(4.76 KiB) Downloaded 655 times
Last edited by roland65 on Wed Mar 21, 2018 5:38 pm, edited 4 times in total.
LibreOffice 5.x on Ubuntu
JeJe
Volunteer
Posts: 2066
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC]Resizable dialog

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

Re: [BASIC]Resizable dialog

Post 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

Openoffice 4.1.6
Windows 8
roland65
Posts: 21
Joined: Tue Oct 18, 2011 6:41 pm

Re: [BASIC]Resizable dialog

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

Re: [BASIC]Resizable dialog

Post 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...
LibreOffice 5.x on Ubuntu
JeJe
Volunteer
Posts: 2066
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC]Resizable dialog

Post by JeJe »

Try declaring oBaseDialog using global

Code: Select all

global oBaseDialog
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
Posts: 2066
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC]Resizable dialog

Post 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.
Last edited by JeJe on Mon Mar 19, 2018 7:17 pm, edited 1 time in total.
Openoffice 4.1.6
Windows 8
roland65
Posts: 21
Joined: Tue Oct 18, 2011 6:41 pm

Re: [BASIC]Resizable dialog

Post 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...
LibreOffice 5.x on Ubuntu
JeJe
Volunteer
Posts: 2066
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC]Resizable dialog

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

Re: [BASIC]Resizable dialog

Post by JeJe »

Investigating - in LibreOffice's windows(0) and windows(1) are scrollbars - you can see them by using setvisible to true.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
Posts: 2066
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC]Resizable dialog

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

Re: [BASIC]Resizable dialog

Post 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.
Openoffice 4.1.6
Windows 8
roland65
Posts: 21
Joined: Tue Oct 18, 2011 6:41 pm

Re: [BASIC] Resizable dialog

Post 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!
LibreOffice 5.x on Ubuntu
JeJe
Volunteer
Posts: 2066
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC] Resizable dialog

Post 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
Openoffice 4.1.6
Windows 8
roland65
Posts: 21
Joined: Tue Oct 18, 2011 6:41 pm

Re: [BASIC] Resizable dialog

Post 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!
LibreOffice 5.x on Ubuntu
JeJe
Volunteer
Posts: 2066
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC] Resizable dialog

Post 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.
Openoffice 4.1.6
Windows 8
roland65
Posts: 21
Joined: Tue Oct 18, 2011 6:41 pm

Re: [BASIC] Resizable dialog

Post 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)...
LibreOffice 5.x on Ubuntu
JeJe
Volunteer
Posts: 2066
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC] Resizable dialog

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

Re: [BASIC] Resizable dialog

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

Re: [BASIC] Resizable dialog

Post by JeJe »

I've posted a slightly different approach here:

viewtopic.php?f=21&t=104768&p=508044#p508044
Openoffice 4.1.6
Windows 8
Post Reply