Dodgy add complex control to toolbar in Basic

Creating Extension - Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This forum is not for asking questions about writing your own macros.
Post Reply
Posts: 2056
Joined: Wed Mar 09, 2016 2:40 pm

Dodgy add complex control to toolbar in Basic

Post by JeJe »

This recent submission ... p?t=108410

reminded me of this old code. My understanding is OOBasic doesn't allow access to XToolbarController.

What you can do in Basic is add a normal button as a position holder and then add an awt control on top.

For the below example for OO the findbar(Find toolbar) (Edit: in Writer in the active frame) needs to be visible and docked.
It adds a combobox at the end which could be used for entering replace text.
A message box is shown if you press enter from the new combobox.

******CAUTION - MAY CAUSE CRASH. eg if you undock toolbar and click close button********

Code: Select all

Sub AddComboToFindBar()
	le = thiscomponent.currentcontroller.frame.layoutmanager
	for i = 0 to ubound(le.elements)
		'find the findbar
		if instr(1,le.elements(i).resourceurl,"FindBar") then

		'add a normal button as a place holder
			le.elements(i).getrealinterface.enabledocking TRUE
			aRect = CreateUnoStruct("")
			sets =le.elements(i).getsettings(true)
			ee= sets.getbyindex(3)
			ub =ubound(ee)+1
			redim preserve ee(ub)

			ee(ub)=  New
			ee(ub).name= "IsEnabled"
			ee(ub).value = false
			ee(0).value = "ReplacePerhaps"
			ee(2).value = "                                  "
			le.elements(i).setsettings (sets)
			bounds=  le.elements(i).GETREALINTERFACE.accessiblecontext.getaccessiblechild(4).bounds
		'create an awt combobox and position over placeholder button
			ARECT.WIDTH =bounds.width
			ARECT.HEIGHT = bounds.height
			WA =
			aRect = CreateUnoStruct("")
			WindowServiceName ="combobox"
			oParent = ThisComponent.getCurrentController().getFrame().ComponentWindow()
			oToolkit =  le.elements(i).realinterface.getToolkit()
			windowAttributes =16 or 1 or
			win= createWindowJe(oToolkit, le.elements(i).realinterface,WindowServiceName,bounds,windowAttributes ,windowtype)

		'add a listener to show message box when enter key pressed
			oListener = CreateUnoListener( "FBKeyListen2_", "" )
			exit sub
		end if
End Sub

function createWindowJe(oToolkit,parent,WindowServiceName,arect,windowAttributes ,windowtype) 'helper to create awt winod
	Dim  WA , oDesc
	WA =
	oDesc = CreateUnoStruct("")
	With oDesc
		.Type = windowtype
		.WindowServiceName =WindowServiceName
		.Parent =  parent
		.ParentIndex =0 
		.Bounds = aRect
		.windowAttributes = windowAttributes
	End With
	button = oToolkit.createWindow(oDesc)
	createWindowJe = button
end function

Sub FBKeyListen2_keyPressed(ev) 'listener for combo key events
	select case ev.keycode
	case 1280
		msgbox "return pressed"
	end select
end sub
Sub FBKeyListen2_keyReleased(ev)
end sub
Sub FBKeyListen2_disposing(oEvent)
End Sub

Openoffice 4.1.6
Windows 8
Post Reply