[Solved] [Calc] Multiple calls from a non-modal dialog box

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

[Solved] [Calc] Multiple calls from a non-modal dialog box

Post by Sébastien C »

Hello everyone,

I continue to discover with great pleasure the roland65 code snippet. Thanks again to Hubert Lambert who gave me the key to run this code as an independent file, without having to install a library. But since it's way above my level, there are things I do not understand and I'd like someone to explain to me here.

Recovering an old piece of code (not very evolved, but it's not the subject) I made a dialog box in the form of a numeric keypad to use it within Calc. Its specificity lies in that it contains a lot of controls (23) and not only two as in the example of roland65. It's a little more complicated to manage, especially because the controls do not only change places; they are also resized and their font still fits their height. The result, attached in this thread, seems to me already impressive whereas the computer that I use is an antediluvian machine, the fluidity of the resizing is more than correct.

This keypad is called by a button from Calc. Being non-modal, it is easy to fill several cells of the sheet with the numeric keypad, validating the values with the "Enter key" of the keypad, it being understood that only one cell must be selected at that time. For the moment, as long as the dialog box is open, it is impossible to click again the call button which is made unable all the time of display. This is done through the first line of the "ResizableNonModalNumericPad" macro. Comment or delete this line is interesting to note the effects: If we call a second time the macro "ResizableNonModalNumericPad" while the dialog box is displayed, it will restart just after closing.

My problem lies in the fact that I do not know the function that would allow me to know if the dialog box is open or not being displayed. In practice, I'll see a listener placed on a cell range that, when one of them is selected, call the dialog box. For the first call, there is obviously no problem; for the following, I need a function that signals NOT to redo a call...

And that's when we are a little amateur, who misses a lot to be enlightened...
;)
Attachments
nonModalNumericKeyPad.ods
(18.18 KiB) Downloaded 154 times
Last edited by Sébastien C on Sat Jun 09, 2018 7:30 pm, edited 2 times in total.
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Calc] Multiple calls from a non-modal dialog box

Post by JeJe »

You could have the function called on the button execute event and put a boolean at the top of the module to record the dialog being open

Code: Select all


public isshowing as boolean 'at top of module

Sub ResizableNonModalNumericPad
	 ' Make disable the call button.
'	 thisComponent.sheets.getByIndex(0).drawPage.forms.getByIndex(0).getByName("callNumericKeyPAd").Enabled = false
	 if isshowing =false then 
		isshowing= true
	 Dim oParent as Variant
	 oParent = ThisComponent.getCurrentController().getFrame().getContainerWindow()

	 ' Create base window as modal dialog.
	 oBaseDialog = CreateBaseDialog(oParent)
	 oBaseDialog.setTitle("Numeric KeyPad.")

	 ' Embed the dialog created by the dialog editor
	 Dim sURL as String, oDialog as Variant
	     sURL = "vnd.sun.star.script:Standard.Dialog1?location=document"
	  oDialog = CreateInnerDialog(oBaseDialog, sURL)

	 ' Compute conversion factors between map appfonts and pixels 
	 Dim aRect as Variant
	    aRect = oDialog.getPosSize()
	    convX = aRect.Width  / oDialog.Model.Width
	    convY = aRect.Height / oDialog.Model.Height
	 mySizeDb = aRect ' For memory.

	 Dim oButtons() as Variant
	 oButtons = oDialog.getControls

	 ' Show dialog
	 oBaseDialog.setVisible(True)
 
	 ' Loop for non modal dialog
	 closed = FALSE
	 While (closed = FALSE)
 	  Wait 1000
	 Wend
isshowing = false
end if
End Sub

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

Re: [Calc] Multiple calls from a non-modal dialog box

Post by Sébastien C »

That is a very good idea ; thanks a lot JeJe :)

I continue to understand this code and it process. I discover the advantages and disadvantages of the loop (here, While-Went). It is not very well known to me and it comes out of the very procedural side of my habits... For the moment, the subject is closed. I will reopen it when my code will be as I want it to be.

Many thanks in the meantime.
:super:
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

Re: [Calc] Multiple calls from a non-modal dialog box

Post by Sébastien C »

It’s done, well done and it’s work... Exactly how I wanted. I have so much learned. It make me happy. :) I think that for use on tablets, it can help a lot.

One can obviously imagine a validation of the buttons much more evolved, but that was not the question here. The fact of being able to work the drawing of the dialog box in the dedicated editor, without practically having to retouch the code, is also a wonderful thing. It will be a bit more complicated if there are several range of cells, but it remains a question of adaptation.
  • There is no more dialogue call with the button since I used the native listener of the sheet.
  • It is not possible to validate the dialog (Enter key) if a selection of several cells is made.
  • We are really in a non-modal context; as long as the selection is made in the yellow range, the dialogue follows.
  • The keyPad remains displayed at the desired dimension as long as you are in the yellow range. To exit, it is to close the dialogue.
I also made a big mistake (but can not be seen) in the previous attached files that have a call button to dialogue and that made me lose a lot of time... The event of the button's control did not call the macro by “Execute action” as it should be, but by “Approve action”. In these conditions, your Boolean flag “isShowing” did not work.

There is one more detail: closing the file with a selected yellow cell calls the dialog box three times. I do not understand why and have not really an idea for how to fix it. If it's obvious to you ...

:D
Attachments
nonModalNumericKeyPad.ods
(18.68 KiB) Downloaded 173 times
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
Post Reply