[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.

[BASIC] Resizable dialog

Postby roland65 » Mon Mar 19, 2018 10:48 am

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 137 times
Last edited by roland65 on Wed Mar 21, 2018 5:38 pm, edited 4 times in total.
LibreOffice 5.x on Ubuntu
roland65
 
Posts: 21
Joined: Tue Oct 18, 2011 6:41 pm

Re: [BASIC]Resizable dialog

Postby JeJe » Mon Mar 19, 2018 3:06 pm

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   Expand viewCollapse view
   ev.Source.Windows(0).setPosSize(0, 0, aSize.Width, aSize.Height, com.sun.star.awt.PosSize.SIZE)
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 607
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC]Resizable dialog

Postby JeJe » Mon Mar 19, 2018 3:17 pm

For a non-modal dialog I found that putting dispose in the windowClosing worked - no need for the wait loop.

Code: Select all   Expand viewCollapse view

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

Re: [BASIC]Resizable dialog

Postby roland65 » Mon Mar 19, 2018 4:14 pm

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

Postby roland65 » Mon Mar 19, 2018 4:18 pm

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

Re: [BASIC]Resizable dialog

Postby JeJe » Mon Mar 19, 2018 6:59 pm

Try declaring oBaseDialog using global

Code: Select all   Expand viewCollapse view
global oBaseDialog
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 607
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC]Resizable dialog

Postby JeJe » Mon Mar 19, 2018 7:15 pm

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

Re: [BASIC]Resizable dialog

Postby roland65 » Mon Mar 19, 2018 7:16 pm

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

Re: [BASIC]Resizable dialog

Postby JeJe » Mon Mar 19, 2018 7:25 pm

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

Re: [BASIC]Resizable dialog

Postby JeJe » Mon Mar 19, 2018 8:18 pm

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

Re: [BASIC]Resizable dialog

Postby JeJe » Mon Mar 19, 2018 8:49 pm

The windows bit is easy to work round (while both have a GetProductName function in the same place anyway)

Code: Select all   Expand viewCollapse view
dim windowIndex

Sub ResizableModalDialog
if instr(1, tools.Misc.GetProductName(),"Open") <> 1 then windowIndex = 2   
...etc


and

Code: Select all   Expand viewCollapse view

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

Re: [BASIC]Resizable dialog

Postby JeJe » Mon Mar 19, 2018 9:38 pm

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

Re: [BASIC] Resizable dialog

Postby roland65 » Tue Mar 20, 2018 10:55 am

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

Re: [BASIC] Resizable dialog

Postby JeJe » Tue Mar 20, 2018 8:27 pm

A better way to get the windows count is, before the inner dialog is added use:

Code: Select all   Expand viewCollapse view
   windowIndex= oBaseDialog.AccessibleContext.getAccessibleChildCount
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 607
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC] Resizable dialog

Postby roland65 » Wed Mar 21, 2018 9:41 am

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

Re: [BASIC] Resizable dialog

Postby JeJe » Wed Mar 21, 2018 12:26 pm

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   Expand viewCollapse view
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.2
Windows 8
JeJe
Volunteer
 
Posts: 607
Joined: Wed Mar 09, 2016 2:40 pm

Re: [BASIC] Resizable dialog

Postby roland65 » Wed Mar 21, 2018 5:42 pm

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


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 2 guests