[Solved] Non-modal Dialog

Discuss the spreadsheet application

[Solved] Non-modal Dialog

Postby mikephillips » Thu Jan 28, 2016 12:09 pm

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
mikephillips
 
Posts: 25
Joined: Wed Jan 27, 2016 6:43 pm

Re: Non-modal Dialog

Postby FJCC » Thu Jan 28, 2016 3:26 pm

I had the attached file lying around with a very simple example.
Attachments
Non-modal dialog.ods
(14.92 KiB) Downloaded 205 times
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7790
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Non-modal Dialog

Postby mikephillips » Thu Jan 28, 2016 7:02 pm

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
mikephillips
 
Posts: 25
Joined: Wed Jan 27, 2016 6:43 pm

Re: Non-modal Dialog

Postby FJCC » Thu Jan 28, 2016 10:04 pm

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 247 times
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7790
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Non-modal Dialog

Postby mikephillips » Thu Jan 28, 2016 10:36 pm

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

Re: Non-modal Dialog

Postby mikephillips » Sat Jan 30, 2016 4:58 pm

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   Expand viewCollapse view
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
mikephillips
 
Posts: 25
Joined: Wed Jan 27, 2016 6:43 pm

Re: [Solved] Non-modal Dialog

Postby JeJe » Thu Jun 11, 2020 1:18 am

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

This is how to do this without a Wait timer:

Code: Select all   Expand viewCollapse view
'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

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

Re: [Solved] Non-modal Dialog

Postby mikephillips » Thu Jun 11, 2020 9:11 am

Jeje - many thanks for resurrecting my query. I will look with interest at your solution.
Open Office 4.0.1 on Windows 7
mikephillips
 
Posts: 25
Joined: Wed Jan 27, 2016 6:43 pm

Re: [Solved] Non-modal Dialog

Postby Villeroy » Thu Jun 11, 2020 10:17 am

Very interesting, indeed. In order to make this work with non-document windows such as the IDE or the welcome screen:
Code: Select all   Expand viewCollapse view
   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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28675
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Non-modal Dialog

Postby JeJe » Thu Jun 11, 2020 10:47 am

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

Re: [Solved] Non-modal Dialog

Postby JeJe » Thu Jun 11, 2020 1:10 pm

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


Return to Calc

Who is online

Users browsing this forum: No registered users and 20 guests