Can I change the default window size when entering hyperlink info in the dialog box? It’s too small and must be manually enlarged every time add a hyperlink to a document. Thanks in advance.
I have tried to adjust the size of the embedded dialogs launched by my macros, but - unfortunatelly - I never found any usable information about it.
(I have tried it with the Open, and Save dialogs of the office suite, but not the dialogs of the op. sys.)
Maybe it is not possible without modifying the source code of the office suite…
This is so cringe worthy.
Why can it not just remember the previously set size and name/column sorting etc of bookmarks and hyperlinks windows?..
I have to do 100s of bi-directional links, with 2 side by side windows up of the same document; and having to adjust it every time is miserable.
I saw there was a bug report - did it ever get fixed?..
https://bugs.documentfoundation.org/show_bug.cgi?id=123123#c14
I’m on Version: 6.4.1.2
You can try the following way - tested on Windows 10 (different versions of LO).
- Write the macros below into any module of any library from
My macros
. - Assign a hotkey to call the
BuiltInDialog
macro. This macro starts/stops the top-level windows listener. - For each built-in dialog, while the listener is running, when closing the dialog, the position and size of the dialog that you set will be saved. The next time you call it (in this LO session or subsequent ones), the dialog will have the same position and size.
Among the observed problems: the simultaneous operation of the top-level window listener and the MRI extension can lead to an abnormal termination of LO when the MRI window is closed.
' lang:en
' Stores information about the location and size of built-in dialogs.
Option Compatible
Option Explicit
Global BuiltInToolkit As Object ' BroadCaster
Global BuiltInListener As Object ' Listener
Global BuiltInMap As Object ' Key: AccessibleId
Global BuiltInPath As String ' Folder for saving Dialog info
' ------------------------------------------------------------------------------
' lang:en
' Start/Stop listener for top-level windows.
Sub BuiltInDialog()
If BuiltInListener Is Nothing Then
BuiltInDialogStart()
Msgbox "The dialog listener is running"
Else
BuiltInDialogStop()
Msgbox "The dialogue listener has stopped"
End If
End Sub
' ------------------------------------------------------------------------------
' lang:en
' Starts a listener for top-level windows.
Sub BuiltInDialogStart()
Dim path
BuiltInDialogStop
BuiltInToolkit = StarDesktop.CurrentFrame.ContainerWindow.Toolkit
BuiltInListener = createUnoListener("BuiltInDialog_", "com.sun.star.awt.XTopWindowListener")
BuiltInToolkit.addTopWindowListener(BuiltInListener)
BuiltInMap = com.sun.star.container.EnumerableMap.create("string", "any")
path=CreateUnoService("com.sun.star.util.PathSubstitution").getSubstituteVariableValue("$(work)") _
& "/LOparm"
With CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
If Not .isFolder(path) Then .createFolder(path)
path=path & "/Dialogs"
If Not .isFolder(path) Then .createFolder(path)
End With
BuiltInPath=path
End Sub
' ------------------------------------------------------------------------------
' lang:en
' Starts a listener for top-level windows.
Sub BuiltInDialogStop()
If Not (BuiltInListener Is Nothing) Then
If BuiltInToolkit Is Nothing Then BuiltInToolkit = StarDesktop.CurrentFrame.ContainerWindow.Toolkit
BuiltInToolkit.RemoveTopWindowListener(BuiltInListener)
End If
BuiltInToolkit=Nothing
BuiltInListener=Nothing
BuiltInMap=Nothing
End Sub
' ------------------------------------------------------------------------------
' lang:en
' Window open event handler.
Sub BuiltInDialog_windowOpened(e)
Dim oDialog, id, PosSize, value As String, arr
On Error GoTo ErrLabel
oDialog=e.source
If oDialog.AccessibleContext.AccessibleRole<>12 Then Exit Sub
id=getAccessibleId(oDialog.AccessibleContext)
If id="" Then Exit Sub
If Not BuiltInMap.containsKey(id) Then '
BuiltInMap.put id, FileToStr(BuiltInPath & "/" & id & ".txt")
End If
PosSize=oDialog.PosSize
value=BuiltInMap.get(id)
arr=Split(value, ";")
If Ubound(arr)>=4 Then
With PosSize
If Not (value Like Join(Array(.X, .Y, .Width, .Height), ";") & ";*") Then
oDialog.SetPosSize Clng(arr(0)), Clng(arr(1)), Clng(arr(2)), Clng(arr(3)), 15 ' the x- and y-coordinate, width and height.
End If
End With
End If
ErrLabel:
End Sub
' ------------------------------------------------------------------------------
' lang:en
' Window close event handler.
Sub BuiltInDialog_windowClosing(e)
Dim oDialog, id, PosSize, value As String, arr
On Error GoTo ErrLabel
If BuiltInListener Is Nothing Then Exit Sub
oDialog=e.source
If oDialog.AccessibleContext.AccessibleRole<>12 Then
Exit Sub
End If
id=getAccessibleId(oDialog.AccessibleContext)
If id="" Then Exit Sub
value=""
PosSize=oDialog.PosSize
With PosSize
If BuiltInMap.containsKey(id) Then
value=BuiltInMap.get(id)
arr=Split(value, ";")
If Ubound(arr)>=4 Then
If value Like Join(Array(.X, .Y, .Width, .Height), ";") & ";*" Then
Exit Sub ' PosSize not changed
End If
End If
End If
BuiltInMap.put id, Join(Array(.X, .Y, .Width, .Height, Format(Now(), "YYYY-MM-DD hh:mm:ss")), ";")
StrToFile BuiltInMap.get(id), BuiltInPath & "/" & id & ".txt"
End With
ErrLabel:
End Sub
Function getAccessibleId(oAC) As String
getAccessibleId=""
If HasUnoInterfaces(oAC, "com.sun.star.accessibility.XAccessibleContext2") Then
getAccessibleId=oAC.getAccessibleId()
End If
End Function
' ------------------------------------------------------------------------------
' lang:en
' Handle events that are not used.
Sub BuiltInDialog_windowActivated(e)
End Sub
Sub BuiltInDialog_windowClosed(e)
End Sub
Sub BuiltInDialog_windowMinimized(e)
End Sub
Sub BuiltInDialog_windowNormalized(e)
End Sub
Sub BuiltInDialog_windowDeactivated(e)
End Sub
Sub BuiltInDialog_disposing(e)
End Sub
' ------------------------------------------------------------------------------
' lang:en
' Returns the contents of the text file filePath.
' An empty string is returned on error.
Function FileToStr(Byval filePath As String) as String
Dim oTextStream
FileToStr=""
On Error GoTo ErrLabel
oTextStream = CreateUnoService("com.sun.star.io.TextInputStream")
With oTextStream
.setInputStream CreateUnoService("com.sun.star.ucb.SimpleFileAccess").openFileRead(ConvertToUrl(FilePath))
FileToStr=.readString(Array(), false)
.closeInput
End With
ErrLabel:
End Function
' ------------------------------------------------------------------------------
' lang:en
' Writes the string str to the text file filePath.
Sub StrToFile(Byval str As String, Byval filePath As String)
Dim oTextStream, oSFA
filePath=ConvertToUrl(FilePath)
oSFA=CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
If oSFA.exists(filePath) Then oSFA.kill filePath
oTextStream = CreateUnoService("com.sun.star.io.TextOutputStream")
With oTextStream
.setOutputStream oSFA.openFileWrite(filePath)
.writeString str
.closeOutput
End With
End Sub