summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2022-11-04 16:54:41 +0100
committerJean-Pierre Ledure <jp@ledure.be>2022-11-05 17:10:41 +0100
commit18638efa3973bf919a2502866773c02b7c24f7d7 (patch)
tree79159bfed99824cbc0928c666ad329aae8f7bebc /wizards
parente0a5a201d4170f4dac23a0e1aa8df18918549991 (diff)
ScriptForge - (SF_Datasheet) new menu methods
Next 2 methods are added: CreateMenu() RemoveMenu() They allow the addition of a menu entry in the menubar of datasheets in the same way as in documents. The implementation required to make the SFWidgets.SF_Menu SFWidgets.SF_MenuListener SFWidgets.SF_Register classes and modules more generic to be applicable in several contexts. In addition, 2 properties are added: DatabaseFileName ParentDatabase to better identify the database from which the datasheet is derived. New properties and methods are applicable both for Basic and Python user scripts. Change-Id: Iac6318287e89b18810a53ec5928a68e921ea96db Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142285 Tested-by: Jean-Pierre Ledure <jp@ledure.be> Reviewed-by: Jean-Pierre Ledure <jp@ledure.be> Tested-by: Jenkins
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/scriptforge/SF_UI.xba2
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py11
-rw-r--r--wizards/source/sfdatabases/SF_Database.xba4
-rw-r--r--wizards/source/sfdatabases/SF_Datasheet.xba167
-rw-r--r--wizards/source/sfdatabases/SF_Register.xba59
-rw-r--r--wizards/source/sfdocuments/SF_Base.xba6
-rw-r--r--wizards/source/sfdocuments/SF_Document.xba2
-rw-r--r--wizards/source/sfdocuments/SF_Form.xba6
-rw-r--r--wizards/source/sfwidgets/SF_Menu.xba10
-rw-r--r--wizards/source/sfwidgets/SF_MenuListener.xba5
-rw-r--r--wizards/source/sfwidgets/SF_Register.xba16
11 files changed, 234 insertions, 54 deletions
diff --git a/wizards/source/scriptforge/SF_UI.xba b/wizards/source/scriptforge/SF_UI.xba
index 8d2b78e3714b..186d88244d75 100644
--- a/wizards/source/scriptforge/SF_UI.xba
+++ b/wizards/source/scriptforge/SF_UI.xba
@@ -1364,4 +1364,4 @@ Private Function _Repr() As String
End Function &apos; ScriptForge.SF_UI._Repr
REM ============================================ END OF SCRIPTFORGE.SF_UI
-</script:module>
+</script:module> \ No newline at end of file
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index 940c355f1e44..24a4aac8d70f 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -1777,8 +1777,9 @@ class SFDatabases:
serviceimplementation = 'basic'
servicename = 'SFDatabases.Datasheet'
servicesynonyms = ('datasheet', 'sfdatabases.datasheet')
- serviceproperties = dict(ColumnHeaders = False, CurrentColumn = False, CurrentRow = False, LastRow = False,
- SOurce = False, SourceType = False, XComponent = False, XControlModel = False,
+ serviceproperties = dict(ColumnHeaders = False, CurrentColumn = False, CurrentRow = False,
+ DatabaseFileName = False, LastRow = False, ParentDatabase = False, Source = False,
+ SourceType = False, XComponent = False, XControlModel = False,
XTabControllerModel = False)
def Activate(self):
@@ -1790,6 +1791,9 @@ class SFDatabases:
def CloseDatasheet(self):
return self.ExecMethod(self.vbMethod, 'CloseDatasheet')
+ def CreateMenu(self, menuheader, before = '', submenuchar = '>'):
+ return self.ExecMethod(self.vbMethod, 'CreateMenu', menuheader, before, submenuchar)
+
def GetText(self, column = 0):
return self.ExecMethod(self.vbMethod, 'GetText', column)
@@ -1802,6 +1806,9 @@ class SFDatabases:
def OrderBy(self, order = ''):
return self.ExecMethod(self.vbMethod, 'OrderBy', order)
+ def RemoveMenu(self, menuheader):
+ return self.ExecMethod(self.vbMethod, 'RemoveMenu', menuheader)
+
# #####################################################################################################################
# SFDialogs CLASS (alias of SFDialogs Basic library) ###
diff --git a/wizards/source/sfdatabases/SF_Database.xba b/wizards/source/sfdatabases/SF_Database.xba
index 6994f791a433..f0dec87c294e 100644
--- a/wizards/source/sfdatabases/SF_Database.xba
+++ b/wizards/source/sfdatabases/SF_Database.xba
@@ -897,7 +897,7 @@ Try:
&apos; Setup the dispatcher
Set oURL = New com.sun.star.util.URL
oURL.Complete = &quot;.component:DB/DataSourceBrowser&quot;
- Set oDispatch = StarDesktop.queryDispatch(oURL, &quot;_Blank&quot;, 8)
+ Set oDispatch = StarDesktop.queryDispatch(oURL, &quot;_blank&quot;, com.sun.star.frame.FrameSearchFlag.CREATE)
&apos; Setup the arguments of the component to create
With ScriptForge.SF_Utils
@@ -916,7 +916,7 @@ Try:
&apos; Open the targeted datasheet
Set oNewDatasheet = oDispatch.dispatchWithReturnValue(oURL, vArgs)
- If Not IsNull(oNewDatasheet) Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, [Me], oNewDatasheet)
+ If Not IsNull(oNewDatasheet) Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, oNewDatasheet, [Me])
Finally:
Set _OpenDatasheet = oOpen
diff --git a/wizards/source/sfdatabases/SF_Datasheet.xba b/wizards/source/sfdatabases/SF_Datasheet.xba
index 743e2ca3ea86..f085ac510a60 100644
--- a/wizards/source/sfdatabases/SF_Datasheet.xba
+++ b/wizards/source/sfdatabases/SF_Datasheet.xba
@@ -123,6 +123,12 @@ Property Get CurrentRow() As Long
End Property &apos; SFDatabases.SF_Datasheet.CurrentRow
REM -----------------------------------------------------------------------------
+Property Get DatabaseFileName() As String
+&apos;&apos;&apos; Returns the file name of the Base file in FSO.FileNaming format
+ DatabaseFileName = _PropertyGet(&quot;DatabaseFileName&quot;)
+End Property &apos; SFDatabases.SF_Datasheet.DatabaseFileName
+
+REM -----------------------------------------------------------------------------
Property Get LastRow() As Long
&apos;&apos;&apos; Returns the total number of rows
&apos;&apos;&apos; The process may imply to move the cursor to the last available row.
@@ -131,6 +137,12 @@ Property Get LastRow() As Long
End Property &apos; SFDatabases.SF_Datasheet.LastRow
REM -----------------------------------------------------------------------------
+Property Get ParentDatabase() As Object
+&apos;&apos;&apos; Returns the database instance to which the datasheet belongs
+ Set ParentDatabase = _PropertyGet(&quot;ParentDatabase&quot;)
+End Property &apos; SFDatabases.SF_Datasheet.ParentDatabase
+
+REM -----------------------------------------------------------------------------
Property Get Source() As String
&apos;&apos;&apos; Returns the source of the data: table name, query name or sql statement
Source = _PropertyGet(&quot;Source&quot;)
@@ -283,6 +295,60 @@ Catch:
End Function &apos; SFDatabases.SF_Datasheet.CloseDatasheet
REM -----------------------------------------------------------------------------
+Public Function CreateMenu(Optional ByVal MenuHeader As Variant _
+ , Optional ByVal Before As Variant _
+ , Optional ByVal SubmenuChar As Variant _
+ ) As Object
+&apos;&apos;&apos; Create a new menu entry in the datasheet&apos;s menubar
+&apos;&apos;&apos; The menu is not intended to be saved neither in the LibreOffice global environment, nor elsewhere
+&apos;&apos;&apos; The method returns a SFWidgets.Menu instance. Its methods let define the menu further.
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; MenuHeader: the name/header of the menu
+&apos;&apos;&apos; Before: the place where to put the new menu on the menubar (string or number &gt;= 1)
+&apos;&apos;&apos; When not found =&gt; last position
+&apos;&apos;&apos; SubmenuChar: the delimiter used in menu trees. Default = &quot;&gt;&quot;
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; A SFWidgets.Menu instance or Nothing
+&apos;&apos;&apos; Examples:
+&apos;&apos;&apos; Dim oMenu As Object
+&apos;&apos;&apos; Set oMenu = oDoc.CreateMenu(&quot;My menu&quot;, Before := &quot;Styles&quot;)
+&apos;&apos;&apos; With oMenu
+&apos;&apos;&apos; .AddItem(&quot;Item 1&quot;, Command := &quot;.uno:About&quot;)
+&apos;&apos;&apos; &apos;...
+&apos;&apos;&apos; .Dispose() &apos; When definition is complete, the menu instance may be disposed
+&apos;&apos;&apos; End With
+&apos;&apos;&apos; &apos; ...
+
+Dim oMenu As Object &apos; return value
+Const cstThisSub = &quot;SFDatabases.Datasheet.CreateMenu&quot;
+Const cstSubArgs = &quot;MenuHeader, [Before=&quot;&quot;&quot;&quot;], [SubmenuChar=&quot;&quot;&gt;&quot;&quot;]&quot;
+
+ If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+ Set oMenu = Nothing
+
+Check:
+ If IsMissing(Before) Or IsEmpty(Before) Then Before = &quot;&quot;
+ If IsMissing(SubmenuChar) Or IsEmpty(SubmenuChar) Then SubmenuChar = &quot;&quot;
+
+ If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
+ If Not _IsStillAlive() Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(MenuHeader, &quot;MenuHeader&quot;, V_STRING) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(Before, &quot;Before&quot;, V_STRING) Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(SubmenuChar, &quot;SubmenuChar&quot;, V_STRING) Then GoTo Finally
+ End If
+
+Try:
+ Set oMenu = ScriptForge.SF_Services.CreateScriptService(&quot;SFWidgets.Menu&quot;, _Component, MenuHeader, Before, SubmenuChar)
+
+Finally:
+ Set CreateMenu = oMenu
+ ScriptForge.SF_Utils._ExitFunction(cstThisSub)
+ Exit Function
+Catch:
+ GoTo Finally
+End Function &apos; SFDatabases.SF_Document.CreateMenu
+
+REM -----------------------------------------------------------------------------
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
&apos;&apos;&apos; Return the actual value of the given property
&apos;&apos;&apos; Args:
@@ -442,7 +508,7 @@ Public Function GoToCell(Optional ByVal Row As Variant _
&apos;&apos;&apos; oSheet.GoToCell(1000000, &quot;ShipCity&quot;)) &apos; Set the cursor on he last row, column &quot;ShipCity&quot;
Dim bGoTo As Boolean &apos; Return value
-Dim lCol As Long &apos; Numeric index of Column in lists of columns
+Dim lCol As Long &apos; Numeric index of Column in list of columns
Dim lMaxCol As Long &apos; Index of last column
Const cstThisSub = &quot;SFDatabases.Datasheet.GoToCell&quot;
Const cstSubArgs = &quot;[Row=0], [Column=0]&quot;
@@ -503,10 +569,12 @@ Public Function Methods() As Variant
&quot;Activate&quot; _
, &quot;ApplyFilter&quot; _
, &quot;CloseDatasheet&quot; _
+ , &quot;CreateMenu&quot; _
, &quot;GetText&quot; _
, &quot;GetValue&quot; _
, &quot;GoToCell&quot; _
, &quot;OrderBy&quot; _
+ , &quot;RemoveMenu&quot; _
)
End Function &apos; SFDatabases.SF_Datasheet.Methods
@@ -569,7 +637,9 @@ Public Function Properties() As Variant
&quot;ColumnHeaders&quot; _
, &quot;CurrentColumn&quot; _
, &quot;CurrentRow&quot; _
+ , &quot;DatabaseFileName&quot; _
, &quot;LastRow&quot; _
+ , &quot;ParentDatabase&quot; _
, &quot;Source&quot; _
, &quot;SourceType&quot; _
, &quot;XComponent&quot; _
@@ -579,6 +649,69 @@ Public Function Properties() As Variant
End Function &apos; SFDatabases.SF_Datasheet.Properties
+REM -----------------------------------------------------------------------------
+Public Function RemoveMenu(Optional ByVal MenuHeader As Variant) As Boolean
+&apos;&apos;&apos; Remove a menu entry in the document&apos;s menubar
+&apos;&apos;&apos; The removal is not intended to be saved neither in the LibreOffice global environment, nor in the document
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; MenuHeader: the name/header of the menu, without tilde &quot;~&quot;, as a case-sensitive string
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; True when successful
+&apos;&apos;&apos; Examples:
+&apos;&apos;&apos; oDoc.RemoveMenu(&quot;File&quot;)
+&apos;&apos;&apos; &apos; ...
+
+Dim bRemove As Boolean &apos; Return value
+Dim oLayout As Object &apos; com.sun.star.comp.framework.LayoutManager
+Dim oMenuBar As Object &apos; com.sun.star.awt.XMenuBar or stardiv.Toolkit.VCLXMenuBar
+Dim sName As String &apos; Menu name
+Dim iMenuId As Integer &apos; Menu identifier
+Dim iMenuPosition As Integer &apos; Menu position &gt;= 0
+Dim i As Integer
+Const cstTilde = &quot;~&quot;
+
+Const cstThisSub = &quot;SFDatabases.Datasheet.RemoveMenu&quot;
+Const cstSubArgs = &quot;MenuHeader&quot;
+
+ If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+ bRemove = False
+
+Check:
+ If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
+ If Not _IsStillAlive() Then GoTo Finally
+ If Not ScriptForge.SF_Utils._Validate(MenuHeader, &quot;MenuHeader&quot;, V_STRING) Then GoTo Finally
+ End If
+
+Try:
+ Set oLayout = _Component.Frame.LayoutManager
+ Set oMenuBar = oLayout.getElement(&quot;private:resource/menubar/menubar&quot;).XMenuBar
+
+ &apos; Search the menu identifier to remove by its name, Mark its position
+ With oMenuBar
+ iMenuPosition = -1
+ For i = 0 To .ItemCount - 1
+ iMenuId = .getItemId(i)
+ sName = Replace(.getItemText(iMenuId), cstTilde, &quot;&quot;)
+ If MenuHeader= sName Then
+ iMenuPosition = i
+ Exit For
+ End If
+ Next i
+ &apos; Remove the found menu item
+ If iMenuPosition &gt;= 0 Then
+ .removeItem(iMenuPosition, 1)
+ bRemove = True
+ End If
+ End With
+
+Finally:
+ RemoveMenu = bRemove
+ ScriptForge.SF_Utils._ExitFunction(cstThisSub)
+ Exit Function
+Catch:
+ GoTo Finally
+End Function &apos; SFDatabases.SF_Datasheet.RemoveMenu
+
REM =========================================================== PRIVATE FUNCTIONS
REM -----------------------------------------------------------------------------
@@ -589,10 +722,11 @@ Public Sub _Initialize()
Dim iType As Integer &apos; One of the com.sun.star.sdb.CommandType constants
Dim oColumn As Object &apos; A single column
Dim oColumnDescriptor As Object &apos; A single column descriptor
+Dim FSO As Object : Set FSO = ScriptForge.SF_FileSystem
Dim i As Long
Try:
- _ParentType = [_Parent].ObjectType
+ If IsNull([_Parent]) Then _ParentType = &quot;&quot; Else _ParentType = [_Parent].ObjectType
With _Component
&apos; The existence of _Component.Selection must be checked upfront
@@ -611,31 +745,33 @@ Try:
&apos; Useful UNO objects
Set _Frame = .Frame
Set _ControlView = .CurrentControl
- Set _TabControllerModel = .com_sun_star_awt_XTabController_getModel
+ Set _TabControllerModel = .com_sun_star_awt_XTabController_getModel()
Set _ControlModel = _ControlView.getModel()
+ End With
&apos; Retrieve the parent database instance
- Select Case [_Parent].ObjectType
+ With _TabControllerModel
+ Select Case _ParentType
Case &quot;BASE&quot;
- With _TabControllerModel
- Set _ParentDatabase = [_Parent].GetDatabase(.User, .Password)
- End With
+ Set _ParentDatabase = [_Parent].GetDatabase(.User, .Password)
Set _ParentBase = [_Parent]
Case &quot;DATABASE&quot;
Set _ParentDatabase = [_Parent]
Set _ParentBase = Nothing
+ Case &quot;&quot; &apos; Derive the DATABASE instance from what can be found in the Component
+ Set _ParentDatabase = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Database&quot; _
+ , FSO._ConvertFromUrl(_BaseFileName), , , .User, .Password)
+ _ParentType = &quot;DATABASE&quot;
+ Set _ParentBase = Nothing
End Select
-
&apos; Load column headers
- _ColumnHeaders = _TabControllerModel.getColumns().getElementNames()
-
+ _ColumnHeaders = .getColumns().getElementNames()
End With
Finally:
Exit Sub
End Sub &apos; SFDatabases.SF_Datasheet._Initialize
- &apos; or Nothing when opened manually from the user interface
REM -----------------------------------------------------------------------------
Private Function _IsStillAlive(Optional ByVal pbError As Boolean) As Boolean
&apos;&apos;&apos; Returns True if the datasheet has not been closed manually or incidentally since the last use
@@ -685,14 +821,13 @@ Const cstSubArgs = &quot;&quot;
Select Case psProperty
Case &quot;ColumnHeaders&quot;
- &apos; or Nothing when opened manually from the user interface
-
- &apos; or Nothing when opened manually from the user interface
_PropertyGet = _ColumnHeaders
Case &quot;CurrentColumn&quot;
_PropertyGet = _ColumnHeaders(_ControlView.getCurrentColumnPosition())
Case &quot;CurrentRow&quot;
_PropertyGet = _TabControllerModel.Row
+ Case &quot;DatabaseFileName&quot;
+ _PropertyGet = ScriptForge.SF_FileSystem._ConvertFromUrl(_BaseFileName)
Case &quot;LastRow&quot;
With _TabControllerModel
If .IsRowCountFinal Then
@@ -708,6 +843,8 @@ Const cstSubArgs = &quot;&quot;
End If
End If
End With
+ Case &quot;ParentDatabase&quot;
+ Set _PropertyGet = _ParentDatabase
Case &quot;Source&quot;
_PropertyGet = _Command
Case &quot;SourceType&quot;
@@ -741,4 +878,4 @@ Private Function _Repr() As String
End Function &apos; SFDatabases.SF_Datasheet._Repr
REM ============================================ END OF SFDATABASES.SF_DATASHEET
-</script:module>
+</script:module> \ No newline at end of file
diff --git a/wizards/source/sfdatabases/SF_Register.xba b/wizards/source/sfdatabases/SF_Register.xba
index 25d41e99718a..04c76ff59e94 100644
--- a/wizards/source/sfdatabases/SF_Register.xba
+++ b/wizards/source/sfdatabases/SF_Register.xba
@@ -152,8 +152,8 @@ Public Function _NewDatabaseFromSource(Optional ByVal pvArgs As Variant) As Obje
Dim oDatabase As Object &apos; Return value
Dim oConnection As Object &apos; com.sun.star.sdbc.XConnection
Dim oDataSource As Object &apos; Alias of pvArgs(0)
-Dim sUser As String &apos; Alias of pvARgs(1)
-Dim sPassword As String &apos; Alias of pvARgs(2)
+Dim sUser As String &apos; Alias of pvArgs(1)
+Dim sPassword As String &apos; Alias of pvArgs(2)
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
Set oDatabase = Nothing
@@ -194,11 +194,11 @@ End Function &apos; SFDatabases.SF_Register._NewDatabaseFromSource
REM -----------------------------------------------------------------------------
Public Function _NewDatasheet(Optional ByVal pvArgs As Variant) As Object
-&apos; Optional ByRef poParent As Object _
-&apos; , Optional ByRef poComponent As Object _
+&apos; Optional ByRef poComponent As Object _
+&apos; , Optional ByRef poParent As Object _
&apos; ) As Object
&apos;&apos;&apos; Create a new instance of the SF_Datasheet class
-&apos;&apos;&apos; Called from (internal calls only)
+&apos;&apos;&apos; Called from
&apos;&apos;&apos; base.Datasheets()
&apos;&apos;&apos; base.OpenTable()
&apos;&apos;&apos; base.OpenQuery()
@@ -206,36 +206,57 @@ Public Function _NewDatasheet(Optional ByVal pvArgs As Variant) As Object
&apos;&apos;&apos; database.OpenQuery()
&apos;&apos;&apos; database.OpenSql()
&apos;&apos;&apos; Args:
-&apos;&apos;&apos; Parent: the parent SF_Database or SF_Base instance having produced the new datasheet
&apos;&apos;&apos; Component: the component of the new datasheet
&apos;&apos;&apos; com.sun.star.lang.XComponent - org.openoffice.comp.dbu.ODatasourceBrowser
+&apos;&apos;&apos; Parent: the parent SF_Database or SF_Base instance having produced the new datasheet
+&apos;&apos;&apos; When absent, the SF_Database instance will be derived from the component
&apos;&apos;&apos; Returns:
&apos;&apos;&apos; The instance or Nothing
Dim oDatasheet As Object &apos; Return value
Dim oParent As Object &apos; The parent SF_Database or SF_Base instance having produced the new datasheet
Dim oComponent As Object &apos; The component of the new datasheet
+Dim oWindow As Object &apos; ui.Window user-defined type
+Dim oUi As Object : Set oUi = ScriptForge.SF_Services.CreateScriptService(&quot;ScriptForge.UI&quot;)
+
+Const TABLEDATA = &quot;TableData&quot;
+Const QUERYDATA = &quot;QueryData&quot;
+Const SQLDATA = &quot;SqlData&quot;
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
Set oDatasheet = Nothing
Check:
- &apos; Get arguments
- If UBound(pvArgs) &lt;&gt; 1 Then GoTo Catch
- Set oParent = pvArgs(0)
- Set oComponent = pvArgs(1)
- If IsNull(oParent) Or IsNull(oComponent) Then GoTo Catch
+ &apos; Get, check and assign arguments
+ If Not IsArray(pvArgs) Then GoTo Catch
+ If UBound(pvArgs) &gt;= 0 Then
+ Set oComponent = pvArgs(0)
+ End If
+ If UBound(pvArgs) = 0 Then
+ Set oParent = Nothing
+ ElseIf UBound(pvArgs) = 1 Then
+ Set oParent = pvArgs(1)
+ Else
+ GoTo Catch
+ End If
+
+ &apos; Check the validity of the proposed window: is it really a datasheet ? Otherwise, do nothing
+ If IsNull(oComponent) Then GoTo Catch
+ Set oWindow = oUi._IdentifyWindow(oComponent)
+ With oWindow
+ If .DocumentType &lt;&gt; TABLEDATA And .DocumentType &lt;&gt; QUERYDATA And .DocumentType &lt;&gt; SQLDATA Then GoTo Catch
+ End With
If IsEmpty(oComponent.Selection) Then GoTo Catch
Try:
- Set oDatasheet = New SF_Datasheet
- With oDatasheet
- Set .[Me] = oDatasheet
- Set .[_Parent] = oParent
- Set ._Component = oComponent
- &apos; Achieve the initialization
- ._Initialize()
- End With
+ Set oDatasheet = New SF_Datasheet
+ With oDatasheet
+ Set .[Me] = oDatasheet
+ Set .[_Parent] = oParent
+ Set ._Component = oComponent
+ &apos; Achieve the initialization
+ ._Initialize()
+ End With
Finally:
Set _NewDatasheet = oDatasheet
diff --git a/wizards/source/sfdocuments/SF_Base.xba b/wizards/source/sfdocuments/SF_Base.xba
index 6b70d9fc4228..eb39c86e851f 100644
--- a/wizards/source/sfdocuments/SF_Base.xba
+++ b/wizards/source/sfdocuments/SF_Base.xba
@@ -551,7 +551,7 @@ Try:
Set oNewQuery = .loadComponent(com.sun.star.sdb.application.DatabaseObject.QUERY, QueryName, DesignMode)
End With
&apos; When design mode, the method returns Nothing
- If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, [Me], oNewQuery)
+ If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, oNewQuery, [Me])
Finally:
Set OpenQuery = oOpen
@@ -604,7 +604,7 @@ Try:
Set oNewTable = .loadComponent(com.sun.star.sdb.application.DatabaseObject.TABLE, TableName, DesignMode)
End With
&apos; When design mode, the method returns Nothing
- If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, [Me], oNewTable)
+ If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, oNewTable, [Me])
Finally:
Set OpenTable = oOpen
@@ -1095,4 +1095,4 @@ Private Function _Repr() As String
End Function &apos; SFDocuments.SF_Base._Repr
REM ============================================ END OF SFDOCUMENTS.SF_BASE
-</script:module>
+</script:module> \ No newline at end of file
diff --git a/wizards/source/sfdocuments/SF_Document.xba b/wizards/source/sfdocuments/SF_Document.xba
index e537b90e5da1..bba8b3c21bd5 100644
--- a/wizards/source/sfdocuments/SF_Document.xba
+++ b/wizards/source/sfdocuments/SF_Document.xba
@@ -766,7 +766,7 @@ End Function &apos; SFDocuments.SF_Document.Properties
REM -----------------------------------------------------------------------------
Public Function RemoveMenu(Optional ByVal MenuHeader As Variant _
, Optional ByRef _Document As Variant _
-) As Boolean
+ ) As Boolean
&apos;&apos;&apos; Remove a menu entry in the document&apos;s menubar
&apos;&apos;&apos; The removal is not intended to be saved neither in the LibreOffice global environment, nor in the document
&apos;&apos;&apos; Args:
diff --git a/wizards/source/sfdocuments/SF_Form.xba b/wizards/source/sfdocuments/SF_Form.xba
index 404c24bd3b20..2879536efb6f 100644
--- a/wizards/source/sfdocuments/SF_Form.xba
+++ b/wizards/source/sfdocuments/SF_Form.xba
@@ -660,6 +660,7 @@ Public Function GetDatabase(Optional ByVal User As Variant _
&apos;&apos;&apos; Set myDb = oForm.GetDatabase()
Dim FSO As Object &apos; Alias for SF_FileSystem
+Dim sDataSource As String &apos; Database file name in FileNaming format
Dim sUser As String &apos; Alias for User
Dim sPassword As String &apos; Alias for Password
Const cstThisSub = &quot;SFDocuments.Form.GetDatabase&quot;
@@ -700,9 +701,10 @@ Try:
Else
&apos; Check if DataSourceName is a file or a registered name and create database instance accordingly
Set FSO = ScriptForge.SF_FileSystem
- If FSO.FileExists(FSO._ConvertFromUrl(_Form.DataSourceName)) Then
+ sDataSource = FSO._ConvertFromUrl(_Form.DataSourceName)
+ If FSO.FileExists(sDataSource) Then
Set _Database = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Database&quot; _
- , _Form.DataSourceName, , , sUser, sPassword)
+ , sDataSource, , , sUser, sPassword)
Else
Set _Database = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Database&quot; _
, , _Form.DataSourceName, , sUser, sPassword)
diff --git a/wizards/source/sfwidgets/SF_Menu.xba b/wizards/source/sfwidgets/SF_Menu.xba
index e211685361bf..85d505904df5 100644
--- a/wizards/source/sfwidgets/SF_Menu.xba
+++ b/wizards/source/sfwidgets/SF_Menu.xba
@@ -503,12 +503,20 @@ Public Sub _Initialize(ByRef poComponent As Object _
Dim oLayout As Object &apos; com.sun.star.comp.framework.LayoutManager
Dim sName As String &apos; Menu name
Dim iMenuId As Integer &apos; Menu identifier
+Dim oWindow As Object &apos; ui.Window type
+Dim oUi As Object : Set oUi = ScriptForge.SF_Services.CreateScriptService(&quot;ScriptForge.UI&quot;)
Dim i As Integer
Const cstTilde = &quot;~&quot;
+Check:
+ &apos; How does the window look on top of which a menu is requested ?
+ Set oWindow = oUi._IdentifyWindow(poComponent)
+ With oWindow
+ If Not IsNull(.Frame) Then Set oLayout = .Frame.LayoutManager Else GoTo Finally
+ End With
+
Try:
&apos; Initialize the menubar
- Set oLayout = poComponent.CurrentController.Frame.LayoutManager
Set MenuBar = oLayout.getElement(&quot;private:resource/menubar/menubar&quot;).XMenuBar
&apos; Determine the new menu identifier and its position
diff --git a/wizards/source/sfwidgets/SF_MenuListener.xba b/wizards/source/sfwidgets/SF_MenuListener.xba
index 6045f2dd8d96..9ab018f77b8b 100644
--- a/wizards/source/sfwidgets/SF_MenuListener.xba
+++ b/wizards/source/sfwidgets/SF_MenuListener.xba
@@ -71,8 +71,8 @@ Dim bType As Boolean &apos; True when status is meaningful: item is radio but
Dim bStatus As Boolean &apos; Status of the menu item, always False for normal items
Dim oFrame As Object &apos; com.sun.star.comp.framework.Frame
Dim oDispatcher As Object &apos; com.sun.star.frame.DispatchHelper
-Dim oSession As Object &apos; SF_Session service
Dim vScript As Variant &apos; Split command in script/argument
+Dim oSession As Object : Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;ScriptForge.Session&quot;)
Dim oArgs() As new com.sun.star.beans.PropertyValue
On Local Error GoTo Catch &apos; Avoid stopping event scripts
@@ -88,15 +88,14 @@ Try:
End With
If Len(sCommand) &gt; 0 Then
+ Set oFrame = StarDesktop.ActiveFrame &apos; A menu has been clicked necessarily in the current window
If Left(sCommand, Len(cstUnoPrefix)) = cstUnoPrefix Then
&apos; Execute uno command
- Set oFrame = StarDesktop.CurrentComponent.CurrentController.Frame &apos; A menu has been clicked necessarily in the current window
Set oDispatcher = ScriptForge.SF_Utils._GetUNOService(&quot;DispatchHelper&quot;)
oDispatcher.executeDispatch(oFrame, sCommand, &quot;&quot;, 0, oArgs())
oFrame.activate()
Else
&apos; Execute script
- Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
vScript = Split(sCommand, cstScriptArg)
oSession._ExecuteScript(vScript(0), vScript(1) &amp; &quot;,&quot; &amp; Iif(bStatus, &quot;1&quot;, &quot;0&quot;)) &apos; Return value is ignored
End If
diff --git a/wizards/source/sfwidgets/SF_Register.xba b/wizards/source/sfwidgets/SF_Register.xba
index 2c58b858d1e9..7dc27083be65 100644
--- a/wizards/source/sfwidgets/SF_Register.xba
+++ b/wizards/source/sfwidgets/SF_Register.xba
@@ -113,7 +113,7 @@ Public Function _NewPopupMenu(Optional ByVal pvArgs As Variant) As Object
&apos;&apos;&apos; Create a new instance of the SF_PopupMenu class
&apos;&apos;&apos; Args:
&apos;&apos;&apos; Event: a mouse event
-&apos;&apos;&apos; If the event has no source or is not a mouse event, the menu is displayed above ThisComponent
+&apos;&apos;&apos; If the event has no source or is not a mouse event, the menu is displayed above the actual window
&apos;&apos;&apos; X, Y: forced coordinates
&apos;&apos;&apos; SubmenuChar: Delimiter used in menu trees
&apos;&apos;&apos; Returns: the instance or Nothing
@@ -123,14 +123,17 @@ Dim Event As Variant &apos; Mouse event
Dim X As Long &apos; Mouse click coordinates
Dim Y As Long
Dim SubmenuChar As String &apos; Delimiter in menu trees
-Dim oSession As Object &apos; ScriptForge.SF_Session
Dim vUno As Variant &apos; UNO type split into an array
Dim sEventType As String &apos; Event type, must be &quot;MouseEvent&quot;
Dim oControl As Object &apos; The dialog or form control view which triggered the event
+Dim oWindow As Object &apos; ui.Window type
+Dim oSession As Object : Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;ScriptForge.Session&quot;)
+Dim oUi As Object : Set oUi = ScriptForge.SF_Services.CreateScriptService(&quot;ScriptForge.UI&quot;)
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
Check:
+ &apos; Check and get arguments, their number may vary
If IsMissing(pvArgs) Or IsEmpty(pvArgs) Then pvArgs = Array()
If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
If UBound(pvArgs) &gt;= 0 Then Event = pvArgs(0) Else Event = Nothing
@@ -145,7 +148,7 @@ Check:
Set oMenu = Nothing
Try:
- Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
+ &apos; Find and identify the control that triggered the popup menu
Set oControl = Nothing
If Not IsNull(Event) Then
&apos; Determine the X, Y coordinates
@@ -158,9 +161,12 @@ Try:
If oSession.HasUnoProperty(Event, &quot;Source&quot;) Then Set oControl = Event.Source.Peer
End If
End If
- &apos; If not a mouse event, if no control, ...
+ &apos; If not a mouse event, if no control, find what can be decent alternatives: (a menu header in) the actual window
If IsNull(oControl) Then
- If Not IsNull(ThisComponent) Then Set oControl = ThisComponent.CurrentController.Frame.getContainerWindow()
+ Set oWindow = oUi._IdentifyWindow(StarDesktop.getCurrentComponent()) &apos; A menu has been clicked necessarily in the current window
+ With oWindow
+ If Not IsNull(.Frame) Then Set oControl = .Frame.getContainerWindow()
+ End With
End If
If Not IsNull(oControl) Then