[Solved] Non-modal Dialog

Discuss the spreadsheet application
Post Reply
mikephillips
Posts: 30
Joined: Wed Jan 27, 2016 6:43 pm

[Solved] Non-modal Dialog

Post by mikephillips »

Most links here do not appear to work to threads about this - PHP script broken.

I wish to have a Dialog which is non-modal to allow scrolling of a spreadsheet behind.
Last edited by mikephillips on Sat Jan 30, 2016 4:59 pm, edited 1 time in total.
Open Office 4.0.1 on Windows 7
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Non-modal Dialog

Post by FJCC »

I had the attached file lying around with a very simple example.
Attachments
Non-modal dialog.ods
(14.92 KiB) Downloaded 493 times
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
mikephillips
Posts: 30
Joined: Wed Jan 27, 2016 6:43 pm

Re: Non-modal Dialog

Post by mikephillips »

Hmm! Thanks for digging that out, FJCC, but I am out of my depth here. I see a Command button on the sheet which initially opens Xray and when that is closed a non-modal Dialog1 (good - just what I want!). Could you please explain (very patiently) to me where is the code to open Dialog1 and what makes it non-modal? The sheet is opening 'Read Only' for me so I cannot examine it.
Open Office 4.0.1 on Windows 7
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Non-modal Dialog

Post by FJCC »

I changed the code so there is a variable called Modal. If it is true, The dialog will come up but you can't interact with the spreadsheet and the dialog as it exists is useless. If you set Modal to False, you can click on the sheet and change the content of the text box in the dialog. Note that in the Modal version, the dialog is closed with the OK button and in the non-modal version you have to click on the radio button. The Do loop in the code is watching the state of the radio button. Of course, you normally make a dialog for only one of these situations.
Attachments
Non-modal dialog.ods
(20.27 KiB) Downloaded 535 times
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
mikephillips
Posts: 30
Joined: Wed Jan 27, 2016 6:43 pm

Re: Non-modal Dialog

Post by mikephillips »

Thanks for that - I'm almost there!
Open Office 4.0.1 on Windows 7
mikephillips
Posts: 30
Joined: Wed Jan 27, 2016 6:43 pm

Re: Non-modal Dialog

Post by mikephillips »

For those, like me - beginners - who do not want the 'Mickey Mouse' soultions sometimes offered (and with thanks to FJCC) this is the simple code I am using to produce a non-Modal dialogue (d1) over my Calc sheet. '

Code: Select all

d1.visible = true
	do        
           wait (100)
	loop
Incredibly simple but VERY difficult to track down, and it should not be! A non-modal option should be a 'bread and butter' requirement for any GUI with dialogues. I am amazed it does not exist in OO. NB I have not bothered with an 'exit' from the non-modal loop since I have a 'Close Programme 'option on d1 anyway for when I no longer need the other functions on it.
Open Office 4.0.1 on Windows 7
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Non-modal Dialog

Post by JeJe »

Resurrecting this old thread in case anyone new looks for this.

This is how to do this without a Wait timer:

Code: Select all

'your library with this code has to be in MyMacros not in the document or the URI will give an error.

Sub Test
	oParent = ThisComponent.getCurrentController().getFrame().getContainerWindow()
	dlg = CreateNonModalDialog(oparent,"JeTest.Dialog1",true) 'example library called JeTest and Dialog called Dialog1
	dlg.setpossize 100,100,500,500,15
	dlg.setvisible true
End Sub

Function CreateNonModalDialog(oParent,DialogParam, Closeable as boolean) As Variant
	dim dlg,CWP,sURL As String
	sURL = "vnd.sun.star.script:" & DialogParam & "?location=" & "application"
	CWP = CreateUnoService("com.sun.star.awt.ContainerWindowProvider")
	dlg = CWP.createContainerWindow(sURL, "", oParent, nothing)
	if Closeable then 'if want closeable need this
	dlg.addTopWindowListener(CreateUnoListener("NonModalWindowListener_", "com.sun.star.awt.XTopWindowListener"))
	end if
	CreateNonModalDialog = dlg
End Function

'XTopWindowListener subs
Sub NonModalWindowListener_disposing(ev) 
End Sub
Sub NonModalWindowListener_windowOpened(ev)
End Sub
Sub NonModalWindowListener_windowClosing(ev) 
ev.source.dispose 'if want closeable need this
End Sub
Sub NonModalWindowListener_windowClosed(ev)
End Sub
Sub NonModalWindowListener_windowMinimized(ev)
End Sub
Sub NonModalWindowListener_windowNormalized(ev)
End Sub
Sub NonModalWindowListener_windowActivated(ev)
End Sub
Sub NonModalWindowListener_windowDeactivated(ev)
End Sub
'/XTopWindowListener subs

sub commandclose(ev) 'if window is not closeable you might want a button perhaps to close it
ev.source.context.dispose
end sub

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
mikephillips
Posts: 30
Joined: Wed Jan 27, 2016 6:43 pm

Re: [Solved] Non-modal Dialog

Post by mikephillips »

Jeje - many thanks for resurrecting my query. I will look with interest at your solution.
Open Office 4.0.1 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Non-modal Dialog

Post by Villeroy »

Very interesting, indeed. In order to make this work with non-document windows such as the IDE or the welcome screen:

Code: Select all

   oParent = StarDesktop.getCurrentFrame().getContainerWindow()
This is a good example how the total lack of documentation inhibits thousands of interested coders.
Documentation on createContainerWindow wrote:Methods' Summary
createContainerWindow creates a window for the given URL
Methods' Details
createContainerWindow( [in] string URL,
[in] string WindowType,
[in] XWindowPeer xParent,
[in] ::com::sun::star::uno::XInterface xHandler )
raises( ::com::sun::star::lang::IllegalArgumentException );

Description
creates a window for the given URL
Parameter URL
is the URL.
Today I've learned that "the URL" is meant to be a dialog's script-URL, finally after 20 years.

The xHandler argument is the next interesting argument.
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
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Non-modal Dialog

Post by JeJe »

My code above is based on part of the code (the 'inner' dialog) from the resizable dialog thread which was originally work by hanya.

viewtopic.php?f=21&t=92867

You can create a resizable dialog with that code - which is fine with a modal dialog, but I found there's a crash if the document window is closed before the dialog is if its non-modal.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2780
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Non-modal Dialog

Post by JeJe »

You can use another dialog (modal or non-modal) as the oParent with oParent = Dialog.getPeer (but the new dialog must have with title bar set to yes, which is the default value, or there will be a crash)

Edit: indeed generally using this method to try to create a dialog with title bar changed to no causes a crash. Not a problem, just a note that that can't be done.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply