fromboolean
hasFocus();
Description
returns the focus state of the window
http://www.openoffice.org/api/docs/comm ... l#hasFocus
I wrote the following test macro which when bound to a key press (Tools->Customize->Keyboard) displays the names of the form/subform where hasFocus() returns TRUE. The problem I am having is that it works as long as I select an entire row on a form/subform grid, but if I only select a single cell on a grid, which is where I need it, hasFocus() always returns FALSE.
Code: Select all
REM ***** BASIC *****
Sub CheckFocus()
Dim oDoc as object
Dim fname as string
oDoc = ThisComponent.DrawPage.Forms
fname = FocusNameListRec(oDoc)
print fname
end Sub
REM =============================================
function FocusNameListRec(oDoc as object) as string
DIM oForm as object, oController as object, oGridControlView as object, oGCMP as object
Dim fName as string
Dim i as integer, j as integer, n as integer
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
' oMRI = CreateUnoService( "mytools.Mri" )
oController = ThisComponent.CurrentController
FocusNameListRec = "Not Found"
n = oDoc.Count 'get number of elements on the form
For i=0 to n-1 'i = element counter
If oDoc.hasElements() then
oForm = oDoc.getByIndex(i)
if oForm.ServiceName = "stardiv.one.form.component.Form" then
fName = FocusNameListRec(oForm)
if fName <> "Not Found" then
FocusNameListRec = fName 'get return name
end if
else
if oForm.ServiceName = "stardiv.one.form.component.Grid" then
oGridControlView = oController.GetControl(oForm)
if oGridControlView.hasFocus() then ' isActive() then
' print "Control has Focus"
oGCMP = oGridControlView.Model.Parent
fName = ""
do
fName = oGCMP.getName() + " : " + fName
' fName = oGCMP.getName() + Chr$(10) + fName
oGCMP = oGCMP.Parent
test = oGCMP.ServiceName
loop Until test <> "stardiv.one.form.component.Form"
fName = left(fName,Len(fName)-3)
FocusNameListRec = fName
end if
if oGridControlView.Context.hasFocus() then
print "Context has Focus"
fName = oGridControlView.Model.Parent.getName()
end if
end if
end if
end if
next i
end function 'FocusNameListRec
https://wiki.openoffice.org/wiki/Framew ... Tookit_API
which I don't fully understand but it makes me wonder if perhaps hasFocus() hasn't been fully implemented.
Anyway, does anyone have any advice on how I might solve this problem?