Dialog as independent window with ComboBox as 2D matrix

The macro IndependentDialog shows Dialog Window as new LibreOffice window (opened document is only for example to write the clicked text from Dialog to document).

After mousemove to lightgreen square (that is ComboBox) is shown the HoverWindow with colored notes. The click on color note put one to new document. Mousewheel in ComboBox (and also in HoverWindow if ComboBox is still focused) changes the notes. So the ComboBox is something like 2D matrix now.

HoverWindow is hidden where the mouse is moved to the empty place in Dialog Window or to the current rest of RichTextBox (text Click colored note).

	Type tColors
		Default& Lightgreen& Color1& Color2& Color3
	End Type

global oDOC as object 'new document
global oHOVER as object 'HoverWindow (shown after onmouseover on Combobox)
global oCOMBO as object 'ComboBox (lightgreen square)

Sub IndependentDialog 'create dialog in independent window (like MRI)
	dim oColors as tColors
	with oColors 'init colors
		.Default=RGB(251, 252, 227) 'background of dialog
		.Lightgreen=RGB(220, 254, 240) 'combobox
		.Color1=RGB(225, 150, 20) 'orange
		.Color2=RGB(25, 150, 220) 'blue
		.Color3=RGB(252, 22, 32) 'red
	end with

	oDOC=StarDesktop.loadComponentFromUrl("private:factory/swriter", "_blank", 0, array()) 'new document

	rem (the code of independent window is according to MRI)
	dim oCtx as object, oSmgr as object, oDesktop as object, oFrame as object, oWindow as object, oToolkit as object
	oCtx=GetDefaultContext()
	oSmgr=oCtx.getServiceManager()
	oDesktop=oSmgr.createInstanceWithContext("com.sun.star.frame.Desktop", oCtx)

    dim oPosSize as new com.sun.star.awt.Rectangle, oRect as new com.sun.star.awt.Rectangle, arr(1) as new com.sun.star.beans.PropertyValue
    const cWidth=300, cHeight=100 'size of Dialog Window
    oPosSize=oDOC.CurrentController.Frame.ContainerWindow.getPosSize()
	with oRect 'position and size of Independent Dialog window
		.X= (oPosSize.Width - cWidth) / 2
		.Y= (oPosSize.Height - cHeight) / 2
		.Width=cWidth
		.Height=cHeight
	end with
	arr(0).Name="FrameName" : arr(0).Value="IndependentDialog"
	arr(1).Name="PosSize" : arr(1).Value=oRect

	oFrame=oSmgr.createInstanceWithContext("com.sun.star.frame.TaskCreator", oCtx).createInstanceWithArguments(arr)
	oFrame.setTitle("Independent Dialog") 'title for Dialog Window
	oWindow=oFrame.getContainerWindow() 'Independent Dialog Window
	oFrame.setCreator(oDesktop)
	oDesktop.getFrames().append(oFrame)
	oToolkit=oWindow.getToolkit()

rem elements in dialog window
	dim oFontDesc as new com.sun.star.awt.FontDescriptor
	with oFontDesc 'font for some elements
		.Name="Liberation Sans"
		.Height=20
		.Weight=com.sun.star.awt.FontWeight.BOLD
	end With

	rem ComboBox (lightgreen square)
	dim oComboModel as object
	oCOMBO=oSmgr.createInstanceWithContext("com.sun.star.awt.UnoControlComboBox", oCtx)
	oComboModel=oSmgr.createInstanceWithContext("com.sun.star.awt.UnoControlComboBoxModel", oCtx)
	with oComboModel
		.Align=1
		.Autocomplete=false
		.BackgroundColor=oColors.Lightgreen
		.Border=0
		.BorderColor=RGB(212, 82, 156)
		.FontDescriptor=oFontDesc
		.MouseWheelBehavior=2 'automatic focus for mouse-hover
		.StringItemList=array(chr(&H266C&), chr(&H266B), chr(&H266A), chr(&H2669&)) 'musical notes
		.Text=.StringItemList(ubound(.StringItemList)) 'last character from .StringItemList
	end with
	with oCOMBO
		.setModel(oComboModel)
		.DropDownLineCount=0
		.setPosSize(10, 20, 35, 35, 15)
		.createPeer(oToolkit, oWindow)
		.addMouseListener(CreateUnoListener("ListenerCombo_", "com.sun.star.awt.XMouseListener"))
		.addTextListener(CreateUnoListener("ListenerComboText_", "com.sun.star.awt.XTextListener"))
	end with

	rem RichTextBox (color text: Click colored note)
	dim oRich as object, oRichModel as object
	dim aColor1(1) as new com.sun.star.beans.PropertyValue, aColor2(1) as new com.sun.star.beans.PropertyValue, aColor3(1) as new com.sun.star.beans.PropertyValue
	oRichModel=createUNOservice("com.sun.star.form.component.RichTextControl")
    oFontDesc.Height=12 'decrease the font height for RichTextBox
	aColor1(0).Name="CharColor" : aColor1(0).Value=oCOLORS.Color1
	aColor1(1).Name="FontDescriptor" : aColor1(1).Value=oFontDesc
	aColor2(0).Name="CharColor" : aColor2(0).Value=oCOLORS.Color2
	aColor2(1).Name="FontDescriptor" : aColor2(1).Value=oFontDesc
	aColor3(0).Name="CharColor" : aColor3(0).Value=oCOLORS.Color3
	aColor3(1).Name="FontDescriptor" : aColor3(1).Value=oFontDesc
	with oRichModel
		.BackgroundColor=oColors.Default
		.Border=0
		.Multiline=false
		.ReadOnly=true
	    .RichText=true
		.appendTextPortion("Click", aColor1())
		.appendTextPortion(" colored", aColor2())
		.appendTextPortion(" note", aColor3())
	end with
	oRich=createUNOservice("com.sun.star.form.control.RichTextControl")
	with oRich
		.setModel(oRichModel)
		.addMouseListener(CreateUnoListener("ListenerRich_", "com.sun.star.awt.XMouseListener"))
		.createPeer(oToolKit, oWindow)
		.setPosSize(46, 28, 200, 27, 15)
	end with

	rem HoverWindow (shown after mousemove on Combobox)
	dim oHoverDesc as new com.sun.star.awt.WindowDescriptor, oParent as object
	with oHoverDesc
		.Type=com.sun.star.awt.WindowClass.SIMPLE
		.WindowServiceName="floatingwindow"
		.ParentIndex=-1
		.Parent=oWindow
		.Bounds=CreateUnoStruct("com.sun.star.awt.Rectangle")
		with .Bounds
			.X=44
			.Y=20
			.Width=100
			.Height=35
		end with
		.WindowAttributes=com.sun.star.awt.WindowAttribute.BORDER
	end with
	oHOVER=oToolkit.createWindow(oHoverDesc)
	oHOVER.Background=oColors.Lightgreen

	rem TextBoxes (colored notes) in HoverWindow
	with oFontDesc
		.Height=22
		.Weight=com.sun.star.awt.FontWeight.BOLD
	end with
	insertFixedText(0, 0, oColors.Color1, oFontDesc, oToolkit, oHOVER)
	insertFixedText(33, 0, oColors.Color2, oFontDesc, oToolkit, oHOVER)
	insertFixedText(66, 0, oColors.Color3, oFontDesc, oToolkit, oHOVER)

	with oWindow
		.Background=oColors.Default
		.addMouseListener(CreateUnoListener("ListenerWindow_", "com.sun.star.awt.XMouseListener"))
		.setVisible(true) 'show Dialog Window
		.toFront()
	end with
End Sub


Sub insertFixedText(X&, Y&, iColor&, oFontDesc as object, oToolkit as object, oWindow as object) 'create element with one colored note in HoverWindow
	dim oFixed as object, oFixedDesc as new com.sun.star.awt.WindowDescriptor
	with oFixedDesc
		.Type=com.sun.star.awt.WindowClass.SIMPLE
		.WindowServiceName="fixedtext"
		.ParentIndex=-1
		.Parent=oWindow
		.Bounds=CreateUnoStruct("com.sun.star.awt.Rectangle")
		with .Bounds
			.X=X
			.Y=Y
			.Width=33
			.Height=33
		end with
		.WindowAttributes=com.sun.star.awt.WindowAttribute.SHOW
	end with
	oFixed=oToolkit.createWindow(oFixedDesc)
	with oFixed
		.setProperty("FontDescriptor", oFontDesc)
		.setProperty("TextColor", iColor)
		.setProperty("Align", 1)
		.addMouseListener(CreateUnoListener("ListenerFixed_", "com.sun.star.awt.XMouseListener"))
	end with
End Sub


Sub putNotes() 'set notes in FixedText elements in HoverWindow
	dim i&, s$, o as object
	s=oCOMBO.Text 'current text from ComboBox
	for each o in oHOVER.Windows 'set text to FixedText elements
		o.Text=s
	next
End Sub


Sub writeToDoc(s$, iColor&) 'put the colored iColor& text s$ to the end of document
	dim oText as object, oCur as object, arr(1) as new com.sun.star.beans.PropertyValue
		arr(0).Name="CharColor" : arr(0).Value=iColor
		arr(1).Name="CharHeight" : arr(1).Value=20
	on local error goto bugDoc 'oDOC can be closed but Dialog Window stays
	oText=oDOC.Text
	oCur=oText.createTextCursor()
	oCur.goToEnd(false)
	oText.insertTextPortion(s, arr(), oCur.End)
	exit sub
bugDoc:
	msgbox "bug oDOC"
End Sub


rem Dialog Window listeners
Sub ListenerWindow_mouseEntered(optional oEvt as object)
	oHOVER.setVisible(false) 'hide HoverWindow
End Sub

Sub ListenerWindow_mouseExited(optional oEvt as object)
End Sub
Sub ListenerWindow_mousePressed(optional oEvt as object)
End Sub
Sub ListenerWindow_mouseReleased(optional oEvt as object)
End Sub
Sub ListenerWindow_disposing
End Sub


rem ComboBox listeners
Sub ListenerCombo_mouseEntered(optional oEvt as object)
	oEvt.Source.setFocus()
	putNotes()
	oHOVER.setVisible(true) 'show HoverWindow
End Sub

Sub ListenerCombo_mouseExited(optional oEvt as object)
End Sub
Sub ListenerCombo_mousePressed(optional oEvt as object)
End Sub
Sub ListenerCombo_mouseReleased(optional oEvt as object)
End Sub
Sub ListenerCombo_disposing
End Sub

Sub ListenerComboText_textChanged(optional oEvt as object)
	putNotes()
End Sub

Sub ListenerComboText_disposing(optional oEvt as object)
End Sub


rem RichTextBox listeners (text: Click colored note)
Sub ListenerRich_mouseEntered(optional oEvt as object)
	oHOVER.setVisible(false) 'hide HoverWindow
End Sub

Sub ListenerRich_mouseExited(optional oEvt as object)
End Sub
Sub ListenerRich_mousePressed(optional oEvt as object)
End Sub
Sub ListenerRich_mouseReleased(optional oEvt as object)
End Sub
Sub ListenerRich_disposing
End Sub


rem FixedText listeners (boxes for colored notes)
Sub ListenerFixed_mouseEntered(optional oEvt as object)
End Sub
Sub ListenerFixed_mouseExited(optional oEvt as object)
End Sub
Sub ListenerFixed_mousePressed(optional oEvt as object)
End Sub

Sub ListenerFixed_mouseReleased(optional oEvt as object)
	dim o as object, s$, iColor&
	o=oEvt.Source
	s=o.Text
	iColor=o.getProperty("TextColor")
	writeToDoc(s$, iColor&)
End Sub

Sub ListenerFixed_disposing
End Sub

There is possible to create the elements in Dialog Window with method oSmgr.createInstanceWithContext("...", oCtx) (ComboBox - but there is missing for example the property .Name that is in classical dialogs);
also with standard createUNOservice("...") (RichText);
or via com.sun.star.awt.WindowDescriptor (HoverWindow; super trick from @Pertsa).
I don’t know if there are more disadvantages or unexpected behaviours for these different ways, also don’t know if there will not be problem when HoverWindow will be drawn over more elements.

Tested Libre25.8 Ubuntu25.10 ok; Libre25.2 Win10 some text-overflow of notes in ComboBox and HoverWindow