From 02fea78109594b0cbeff2e8bfd5291c9ebf54c4f Mon Sep 17 00:00:00 2001 From: Jean-Pierre Ledure Date: Sat, 21 Feb 2015 15:41:43 +0100 Subject: Access2Base - Sharper recognition of document type in _SelectWindow() Recognizes new ("untitled ...") writer, calc, ... documents. Necessary for correct toolbars management Change-Id: Ic1db29b8aebe377e08e6a5101162ca107f2f7154 --- wizards/source/access2base/DoCmd.xba | 28 ++++++++++++++++++++-------- wizards/source/access2base/acConstants.xba | 6 ++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/wizards/source/access2base/DoCmd.xba b/wizards/source/access2base/DoCmd.xba index a93973d476ea..89684050b5ee 100644 --- a/wizards/source/access2base/DoCmd.xba +++ b/wizards/source/access2base/DoCmd.xba @@ -31,6 +31,7 @@ Type _Window Frame As Object ' com.sun.star.comp.framework.Frame _Name As String ' Object Name WindowType As Integer ' One of the object types + DocumentType As String ' Writer, Calc, ... - Only if WindowType = acDocument End Type REM VBA allows call to actions with missing arguments e.g. OpenForm("aaa",,"[field]=2") @@ -2160,7 +2161,7 @@ Public Function _SelectWindow(Optional ByVal piWindowType As Integer, Optional B ' Return a _Window object type describing the found window Dim oEnum As Object, oDesk As Object, oComp As Object, oFrame As Object, i As Integer -Dim bFound As Boolean, bActive As Boolean, bName As Boolean, sName As String, iType As Integer +Dim bFound As Boolean, bActive As Boolean, sName As String, iType As Integer, sDocumentType As String Dim sImplementation As String, vLocation() As Variant Dim oWindow As _Window @@ -2169,8 +2170,9 @@ Dim oWindow As _Window bActive = IsMissing(piWindowType) If IsMissing(psWindow) Then psWindow = "" Set oWindow.Frame = Nothing + oWindow.DocumentType = "" If bActive Then - oWindow.WindowType = -1 + oWindow.WindowType = acDefault oWindow._Name = "" Else oWindow.WindowType = piWindowType @@ -2179,7 +2181,8 @@ Dim oWindow As _Window Case Else : oWindow._Name = psWindow End Select End If - + iType = acDefault + sDocumentType = "" Set oDesk = CreateUnoService("com.sun.star.frame.Desktop") Set oEnum = oDesk.Components().createEnumeration @@ -2196,7 +2199,6 @@ Dim oWindow As _Window iType = acDatabaseWindow sName = "" Case "SwXTextDocument" - bName = False If HasUnoInterfaces(oComp, "com.sun.star.frame.XModule") Then Select Case oComp.Identifier Case "com.sun.star.sdb.FormDesign" ' Form @@ -2205,11 +2207,11 @@ Dim oWindow As _Window iType = acReport Case "com.sun.star.text.TextDocument" ' Writer vLocation = Split(oComp.getLocation(), "/") - sName = Join(Split(vLocation(UBound(vLocation)), "%20"), " ") - bName = True + If UBound(vLocation) >= 0 Then sName = Join(Split(vLocation(UBound(vLocation)), "%20"), " ") Else sName = "" iType = acDocument + sDocumentType = docWriter End Select - If Not bName Then ' Identify Form or Report name + If iType = acForm Or iType = acReport Then ' Identify Form or Report name For i = 0 To UBound(oComp.Args()) If oComp.Args(i).Name = "DocumentTitle" Then sName = oComp.Args(i).Value @@ -2258,8 +2260,17 @@ Dim oWindow As _Window Case Else ' Other Calc, ..., whatever documents If Utils._hasUNOProperty(oComp, "Location") Then vLocation = Split(oComp.getLocation(), "/") - sName = Join(Split(vLocation(UBound(vLocation)), "%20"), " ") + If UBound(vLocation) >= 0 Then sName = Join(Split(vLocation(UBound(vLocation)), "%20"), " ") Else sName = "" iType = acDocument + If Utils._hasUNOProperty(oComp, "Identifier") Then + Select Case oComp.Identifier + Case "com.sun.star.sheet.SpreadsheetDocument" : sDocumentType = docCalc + Case "com.sun.star.presentation.PresentationDocument" : sDocumentType = docImpress + Case "com.sun.star.drawing.DrawingDocument" : sDocumentType = docDraw + Case "com.sun.star.formula.FormulaProperties" : sDocumentType = docMath + Case Else : sDocumentType = "" + End Select + End If Set oFrame = oComp.CurrentController.Frame End If End Select @@ -2278,6 +2289,7 @@ Dim oWindow As _Window Set oWindow.Frame = oFrame oWindow._Name = sName oWindow.WindowType = iType + oWindow.DocumentType = sDocumentType Else Set oWindow.Frame = Nothing End If diff --git a/wizards/source/access2base/acConstants.xba b/wizards/source/access2base/acConstants.xba index 7c456ca58b60..21deeaa422aa 100644 --- a/wizards/source/access2base/acConstants.xba +++ b/wizards/source/access2base/acConstants.xba @@ -53,6 +53,12 @@ Global Const acTable = 0 Global Const acBasicIDE = 101 Global Const acDatabaseWindow = 102 Global Const acDocument = 111 +' Subtype if acDocument +Global Const docWriter = "Writer" +Global Const docCalc = "Calc" +Global Const docImpress = "Impress" +Global Const docDraw = "Draw" +Global Const docMath = "Math" REM AcWindowMode REM ----------------------------------------------------------------- -- cgit