Easy status bar item in Basic

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

Easy status bar item in Basic

Post by JeJe »

Status bar items need a statusbar controller to function. What we can do in Basic is add a blank area which calls an uno or macro command on a double click.

Code: Select all

Sub testAddStatusArea 'customises the current controller's status bar

'uno command example for Writer
AddStatusBarArea ".uno:Bold" 

'macro
'macropath = libraryname.modulename.subname
'AddStatusButton "vnd.sun.star.script:" & macropath & "?language=Basic&location=application"

end sub

sub AddStatusBarArea(CommandURL)
dim lm,el,sett, props(2) as new com.sun.star.beans.PropertyValue

lm= thiscomponent.currentcontroller.frame.layoutmanager '.getelements 
el= lm.getElement("private:resource/statusbar/statusbar")
props(0).name = "CommandURL"
props(0).value =CommandURL
props(1).name = "Width"
props(1).value =20
sett = el.getsettings(true)
sett.insertbyindex(0,props)
el.setsettings(sett)
el.updatesettings    
end sub
Edit: you can add a listener to capture a single mouse press or ones with modifiers. Things get awkward though, if for example, in Writer there's a switch to full screen and back - in which case a new status bar looks to be created - with the inserted item and double click function still - but that listener is lost. I lost interest about there and didn't look further to see if a paint listener could be employed for drawing on the blank item as well.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Easy status bar item in Basic

Post by JeJe »

More complicated offshoot

The attached Writer document tested on OO is what I ended up with

A blank area should be added to the far left of the status bar on opening. Clicking with the mouse will show a message box of the modifier keys pressed. It will continue to work after a switch to full screen and back.

Could perhaps be used if someone wanted a minimal interface with just the status bar showing but wanted to add some more click options to it.

Just experimenting... usual use at own risk caveat...

(Paint listener was unsuccessful)

Code:

Code: Select all

	REM  *****  BASIC  *****

Sub StartLayoutManagerEventListener 'RUNS ON DOCUMENT VIEW CREATED EVENT
	dim lm,el

	'LAYOUT MANAGER LISTENER NEEDED SEE BELOW FOR WHY
	lm= thiscomponent.currentcontroller.frame.layoutmanager
	LML = createUnoListener("StatusLM_", "com.sun.star.frame.XLayoutManagerListener")
	lm.addLayoutManagerEventListener(LML)

	el= lm.getElement("private:resource/statusbar/statusbar")
	
	'ADD STATUS BAR AREA IF NOT ALREADY THERE
	if el.realinterface.accessiblecontext.getaccessiblechild(0).getTitledBorderText <>"" then
		dim props(1) as new com.sun.star.beans.PropertyValue
		props(0).name = "CommandURL"
		props(0).value ="vnd.sun.star.script:Standard.Module1.Test?language=Basic&location=document"
		props(1).name = "Width"
		props(1).value =20
		sett = el.getsettings(true)
		sett.insertbyindex(0,props)
		el.setsettings(sett)
		el.updatesettings
	end if
	if lm.isElementVisible("private:resource/statusbar/statusbar") =true then setElMouseHandler(el)
end sub



sub StatusLM_disposing(ev)
end sub


'WE NEED LAYOUT MANAGER LISTENER IN CASE STATUS BAR DISPOSED AND RESHOWN - WE NEED TO 
'ADD THE MOUSE LISTENER AGAIN IF THAT HAPPENS
'THERE'S NO WAY TO KNOW IF THE LISTENER IS STILL RUNNING SO I'VE USED MODIFYING THE
'FOREGROUND COLOR TO JUST OFF BLACK AS A WAY OF MARKING THE STATUS BAR AS RUNNING THE LISTENER
sub StatusLM_layoutEvent(ev)
	dim lm,el,oMouseClickHandler,sett
	lm = ev.source
	if lm.isElementVisible("private:resource/statusbar/statusbar") =true then
		el= lm.getElement("private:resource/statusbar/statusbar")
		if el.realinterface.AccessibleContext.foreground <> rgb(1,1,1) then setElMouseHandler(el)
	end if
end sub

sub setElMouseHandler(el)
			el.realinterface.setforeground rgb(1,1,1)
			oMouseClickHandler = createUnoListener("StatusM_", "com.sun.star.awt.XMouseListener")
			el.realinterface.addMouseListener (oMouseClickHandler)
end sub


'CAPTURE MOUSE EVENTS FOR AREA
Sub StatusM_mouseEntered(ev) 'mouse listener
end sub
Sub StatusM_mouseExited(Ev)
end sub
Sub StatusM_disposing(Ev)
End Sub
Function StatusM_mousePressed(Ev) As Boolean
	if ev.x<20 then
		msgbox ev.modifiers
		StatusM_mousePressed = true
	end if

End Function
Function StatusM_mouseReleased(Ev) As Boolean
end function

sub Test()
msgbox "Double Click works without any listeners"
end sub
Attachments
addtostatusbar.odt
(12.67 KiB) Downloaded 189 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply