https://forum.openoffice.org/en/forum/v ... 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("com.sun.star.awt.Rectangle")
sets =le.elements(i).getsettings(true)
ee= sets.getbyindex(3)
ub =ubound(ee)+1
redim preserve ee(ub)
ee(ub)= New com.sun.star.beans.PropertyValue
ee(ub).name= "IsEnabled"
ee(ub).value = false
ee(0).value = "ReplacePerhaps"
ee(2).value = " "
sets.insertbyindex(4,ee)
le.elements(i).setsettings (sets)
le.elements(i).updatesettings
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 = com.sun.star.awt.WindowAttribute
WC= com.sun.star.awt.WindowClass
aRect = CreateUnoStruct("com.sun.star.awt.Rectangle")
WindowServiceName ="combobox"
oParent = ThisComponent.getCurrentController().getFrame().ComponentWindow()
oToolkit = le.elements(i).realinterface.getToolkit()
windowAttributes =16 or 1 or com.sun.star.awt.VclWindowPeerAttribute.DROPDOWN
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_", "com.sun.star.awt.XKeyListener" )
win.addKeyListener(oListener)
exit sub
end if
next
End Sub
function createWindowJe(oToolkit,parent,WindowServiceName,arect,windowAttributes ,windowtype) 'helper to create awt winod
Dim WA , oDesc
WA = com.sun.star.awt.WindowAttribute
oDesc = CreateUnoStruct("com.sun.star.awt.WindowDescriptor")
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