diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2021-02-05 17:34:02 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2021-02-06 15:31:41 +0100 |
commit | 1ea8e56ec3c15fb23bb8c0512c4e6afa8bc9d66e (patch) | |
tree | 17ddc9547219f7b55325ab0bc5539972898e1fb9 /wizards/source | |
parent | faf0635def4ef603563f7288cb29d24e3f2ce1e3 (diff) |
ScriptForge - (SF_FormControl) add SetFocus() method
The SetFocus() method simply applies the setFocus() UNO method
for usual controls.
However controls belonging to a table control require,
to receive the focus, the columns to be scanned from left to right
up to the targeted column.
Change-Id: Idbb1ca4b4b29bff889daa83cfa895501c466bb26
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110485
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards/source')
-rw-r--r-- | wizards/source/sfdocuments/SF_FormControl.xba | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/wizards/source/sfdocuments/SF_FormControl.xba b/wizards/source/sfdocuments/SF_FormControl.xba index 3e4ad352c782..aebe9a1dd313 100644 --- a/wizards/source/sfdocuments/SF_FormControl.xba +++ b/wizards/source/sfdocuments/SF_FormControl.xba @@ -743,7 +743,7 @@ Finally: Catch: GoTo Finally CatchNotFound: - ScriptForge.SF_Utils._Validate(ControlName, "ControlName", V_STRING, _Form.getElementNames()) + ScriptForge.SF_Utils._Validate(ControlName, "ControlName", V_STRING, _ControlModel.getElementNames()) GoTo Finally End Function ' SFDocuments.SF_FormControl.Controls @@ -859,13 +859,18 @@ Public Function SetFocus() As Boolean ''' Returns: ''' True if focusing is successful ''' Example: -''' Dim oDlg As Object, oControl As Object -''' Set oDlg = CreateScriptService(,, "myControl") ' Control stored in current document's standard library +''' Dim oDoc As Object, oForm As Object, oControl As Object +''' Set oDoc = Set oDoc = CreateScriptService("SFDocuments.Document", ThisComponent) +''' Set oForm = oDoc.Forms(0) ''' Set oControl = oDlg.Controls("thisControl") ''' oControl.SetFocus() Dim bSetFocus As Boolean ' Return value -Const cstThisSub = "SFDocuments.DialogControl.SetFocus" +Dim iColPosition As Integer ' Position of control in table +Dim oTableModel As Object ' XControlModel of parent tabel +Dim oControl As Object ' com.sun.star.awt.XControlModel +Dim i As Integer, j As Integer +Const cstThisSub = "SFDocuments.FormControl.SetFocus" Const cstSubArgs = "" If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch @@ -873,14 +878,34 @@ Const cstSubArgs = "" Check: If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then - If Not [_Parent]._IsStillAlive() Then GoTo Finally + If Not _ParentForm._IsStillAlive() Then GoTo Finally End If Try: If Not IsNull(_ControlView) Then - _ControlView.setFocus() + If _ParentIsTable Then ' setFocus() method does not work on controlviews in table control ?!? + ' Find the column position of the current instance in the parent table control + iColPosition = -1 + Set oTableModel = [_Parent]._ControlModel + j = -1 + For i = 0 To oTableModel.Count - 1 + Set oControl = oTableModel.getByIndex(i) + If Not oControl.Hidden Then j = j + 1 ' Skip hidden columns + If oControl.Name = _Name Then + iColPosition = j + Exit For + End If + Next i + If iColPosition >= 0 Then + [_Parent]._ControlView.setFocus() 'Set first focus on table control itself + [_Parent]._ControlView.setCurrentColumnPosition(iColPosition) 'Deprecated but no alternative found + End If + Else + _ControlView.setFocus() + End If bSetFocus = True End If + bSetFocus = True Finally: SetFocus = bSetFocus |