[Libreoffice-commits] core.git: wizards/source

Jean-Pierre Ledure (via logerrit) logerrit at kemper.freedesktop.org
Sat Feb 6 14:32:25 UTC 2021


 wizards/source/sfdocuments/SF_FormControl.xba |   37 +++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 6 deletions(-)

New commits:
commit 1ea8e56ec3c15fb23bb8c0512c4e6afa8bc9d66e
Author:     Jean-Pierre Ledure <jp at ledure.be>
AuthorDate: Fri Feb 5 17:34:02 2021 +0100
Commit:     Jean-Pierre Ledure <jp at ledure.be>
CommitDate: Sat Feb 6 15:31:41 2021 +0100

    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 at ledure.be>
    Reviewed-by: Jean-Pierre Ledure <jp at ledure.be>

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


More information about the Libreoffice-commits mailing list