I’ve noticed that if I start a dialog from a macro located in “My Macros & Dialogs”, running the macro from the Basic IDE (for example using ctrl-shift-F8), then the dialog started is modal with the basic IDE and not with the active document.
This can then be a problem trying to debug the macros called from events triggered by controls in the dialog.
I can work around this problem by first setting the document active, I’m using the following to set the current document active.
StarDesktop.loadComponentFromURL(ThisComponent.URL,"_default",0,array()) ' sets focus to the document'
Is there a better method than this to set the active focus to ThisComponent?
Edit. Slightly better method to change focus from the Basic IDE to the document when starting a modal dialog. Either the DoEvents or a Wait seems to be needed to avoid the dialog still being attached to the Basic IDE.
ThisComponent.CurrentController.Frame.ContainerWindow.setFocus
DoEvents
Also is there some similar method that could create a dialog that is non-modal with documents but without it being modal with the basic IDE?
I saw this prior question how-to-make-non-modal-dialog answered by @pierre-yves-samyn, but wondered if the above behaviour could lead to some other method.
Attached contains sample dialog and macro.
Untitled 29.ods
Note the macro module and dialog needs to be copied to “My Macros & Dialogs” to show the problem.
I’m using LibreOffice 5.2.1.2 x64 on Windows 8.1.
Edit to add code for fake non-modal dialog created using IDE and setting the dummy document invisible. Note the dialog is not shown in the windows task bar and can become hidden behind other windows. Also reference to ThisComponent will refer to the hidden dummy document.
Sub ShowHiddenDocDialog
Dim oDummyDoc As Object
Dim oController As Variant
oDummyDoc = StarDesktop.loadComponentFromURL("private:factory/scalc", "_default", 0, array())
oController = oDummyDoc.CurrentController
DoEvents ' Wait for the new document to be activated'
DialogLibraries.LoadLibrary("Standard")
MySampleDialog = CreateUnoDialog(DialogLibraries.Standard.DocIdentify)
oController.Frame.ContainerWindow.Visible = False
MySampleDialog.execute()
oDummyDoc.close(true)
End Sub