[Libreoffice-commits] core.git: sw/inc sw/source

Matteo Casalin matteo.casalin at yahoo.com
Fri Aug 16 08:51:28 PDT 2013


 sw/inc/docsh.hxx                   |   15 +++++
 sw/source/core/docnode/section.cxx |  108 -------------------------------------
 sw/source/ui/app/docsh2.cxx        |   98 +++++++++++++++++++++++++++++++++
 sw/source/ui/uiview/view2.cxx      |   11 +--
 4 files changed, 117 insertions(+), 115 deletions(-)

New commits:
commit ad3188b5faf6db2ccab07a7a8901518e80e3ad25
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date:   Thu Aug 15 13:39:11 2013 +0200

    sw_FindDocShell(): better place and name + String to OUString
    
    Change-Id: I345a2802b4428c607297cbe6972c5b7aebc5de0b
    Reviewed-on: https://gerrit.libreoffice.org/5439
    Reviewed-by: Petr Mladek <pmladek at suse.cz>
    Tested-by: Petr Mladek <pmladek at suse.cz>

diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx
index e060cb7..efa659b 100644
--- a/sw/inc/docsh.hxx
+++ b/sw/inc/docsh.hxx
@@ -305,6 +305,21 @@ class Graphic;
  /// implemented in source/ui/docvw/romenu.cxx
 String ExportGraphic( const Graphic &rGraphic, const String &rGrfName );
 
+/** Find the right DocShell and create a new one:
+    The return value specifies what should happen to the Shell
+    0 - Error, could not find the DocShell
+    1 - DocShell is an existing Document
+    2 - DocShell was created anew, thus it needs to be closed again
+        (will be assigned to xLockRef additionally)
+*/
+int SwFindDocShell( SfxObjectShellRef& xDocSh,
+                    SfxObjectShellLock& xLockRef,
+                    const OUString& rFileName,
+                    const OUString& rPasswd,
+                    const OUString& rFilter,
+                    sal_Int16 nVersion,
+                    SwDocShell* pDestSh );
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx
index d243448..6f607e7 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -1175,112 +1175,6 @@ static void lcl_UpdateLinksInSect( SwBaseLink& rUpdLnk, SwSectionNode& rSectNd )
 }
 
 
-// Find the right DocShell and create a new one:
-// The return value specifies what should happen to the Shell
-//  0 - Error, could not find the DocShell
-//  1 - DocShell is an existing Document
-//  2 - DocShell was created anew, thus it needs to be closed again
-//      (will be assigned to xLockRef additionally)
-int sw_FindDocShell( SfxObjectShellRef& xDocSh,
-                        SfxObjectShellLock& xLockRef,
-                        const String& rFileName,
-                        const String& rPasswd,
-                        String& rFilter,
-                        sal_Int16 nVersion,
-                        SwDocShell* pDestSh )
-{
-    if( !rFileName.Len() )
-        return 0;
-
-    // 1. Does the file already exist in the list of all Documents?
-    INetURLObject aTmpObj( rFileName );
-    aTmpObj.SetMark( aEmptyStr );
-
-    // Iterate over the DocShell and get the ones with the name
-    TypeId aType( TYPE(SwDocShell) );
-
-    SfxObjectShell* pShell = pDestSh;
-    bool bFirst = 0 != pShell;
-
-    if( !bFirst )
-        // No DocShell passed, starting with the first from the DocShell list
-        pShell = SfxObjectShell::GetFirst( &aType );
-
-    while( pShell )
-    {
-        // We want this one
-        SfxMedium* pMed = pShell->GetMedium();
-        if( pMed && pMed->GetURLObject() == aTmpObj )
-        {
-            const SfxPoolItem* pItem;
-            if( ( SFX_ITEM_SET == pMed->GetItemSet()->GetItemState(
-                                            SID_VERSION, sal_False, &pItem ) )
-                    ? (nVersion == ((SfxInt16Item*)pItem)->GetValue())
-                    : !nVersion )
-            {
-                // Found, thus return
-                xDocSh = pShell;
-                return 1;
-            }
-        }
-
-        if( bFirst )
-        {
-            bFirst = false;
-            pShell = SfxObjectShell::GetFirst( &aType );
-        }
-        else
-            pShell = SfxObjectShell::GetNext( *pShell, &aType );
-    }
-
-    // 2. Open the file ourselves
-    SfxMedium* pMed = new SfxMedium( aTmpObj.GetMainURL(
-                             INetURLObject::NO_DECODE ), STREAM_READ );
-    if( INET_PROT_FILE == aTmpObj.GetProtocol() )
-        pMed->DownLoad(); // Touch the medium (download it)
-
-    const SfxFilter* pSfxFlt = 0;
-    if( !pMed->GetError() )
-    {
-        String sFactory(OUString::createFromAscii(SwDocShell::Factory().GetShortName()));
-        SfxFilterMatcher aMatcher( sFactory );
-
-        // No Filter, so search for it. Else test if the one passed is a valid one
-        if( rFilter.Len() )
-        {
-            pSfxFlt = aMatcher.GetFilter4FilterName( rFilter );
-        }
-
-        if( nVersion )
-            pMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion ));
-
-        if( rPasswd.Len() )
-            pMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd ));
-
-        if( !pSfxFlt )
-            aMatcher.DetectFilter( *pMed, &pSfxFlt, sal_False, sal_False );
-
-        if( pSfxFlt )
-        {
-            // We cannot do anything without a Filter
-            pMed->SetFilter( pSfxFlt );
-
-            // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure
-            xLockRef = new SwDocShell( SFX_CREATE_MODE_INTERNAL );
-            xDocSh = (SfxObjectShell*)xLockRef;
-            if( xDocSh->DoLoad( pMed ) )
-                return 2;
-        }
-    }
-
-    if( !xDocSh.Is() ) // Medium still needs to be deleted
-        delete pMed;
-
-    return 0;
-}
-
-
-
 ::sfx2::SvBaseLink::UpdateResult SwIntrnlSectRefLink::DataChanged(
     const String& rMimeType, const uno::Any & rValue )
 {
@@ -1373,7 +1267,7 @@ int sw_FindDocShell( SfxObjectShellRef& xDocSh,
             }
             else
             {
-                nRet = sw_FindDocShell( xDocSh, xLockRef, sFileName,
+                nRet = SwFindDocShell( xDocSh, xLockRef, sFileName,
                                     rSection.GetLinkFilePassword(),
                                     sFilter, 0, pDoc->GetDocShell() );
                 if( nRet )
diff --git a/sw/source/ui/app/docsh2.cxx b/sw/source/ui/app/docsh2.cxx
index ab2781b..c134027 100644
--- a/sw/source/ui/app/docsh2.cxx
+++ b/sw/source/ui/app/docsh2.cxx
@@ -1494,4 +1494,102 @@ SfxInPlaceClient* SwDocShell::GetIPClient( const ::svt::EmbeddedObjectRef& xObjR
     return pResult;
 }
 
+
+int SwFindDocShell( SfxObjectShellRef& xDocSh,
+                    SfxObjectShellLock& xLockRef,
+                    const OUString& rFileName,
+                    const OUString& rPasswd,
+                    const OUString& rFilter,
+                    sal_Int16 nVersion,
+                    SwDocShell* pDestSh )
+{
+    if ( rFileName.isEmpty() )
+        return 0;
+
+    // 1. Does the file already exist in the list of all Documents?
+    INetURLObject aTmpObj( rFileName );
+    aTmpObj.SetMark( OUString() );
+
+    // Iterate over the DocShell and get the ones with the name
+    TypeId aType( TYPE(SwDocShell) );
+
+    SfxObjectShell* pShell = pDestSh;
+    bool bFirst = 0 != pShell;
+
+    if( !bFirst )
+        // No DocShell passed, starting with the first from the DocShell list
+        pShell = SfxObjectShell::GetFirst( &aType );
+
+    while( pShell )
+    {
+        // We want this one
+        SfxMedium* pMed = pShell->GetMedium();
+        if( pMed && pMed->GetURLObject() == aTmpObj )
+        {
+            const SfxPoolItem* pItem;
+            if( ( SFX_ITEM_SET == pMed->GetItemSet()->GetItemState(
+                                            SID_VERSION, sal_False, &pItem ) )
+                    ? (nVersion == ((SfxInt16Item*)pItem)->GetValue())
+                    : !nVersion )
+            {
+                // Found, thus return
+                xDocSh = pShell;
+                return 1;
+            }
+        }
+
+        if( bFirst )
+        {
+            bFirst = false;
+            pShell = SfxObjectShell::GetFirst( &aType );
+        }
+        else
+            pShell = SfxObjectShell::GetNext( *pShell, &aType );
+    }
+
+    // 2. Open the file ourselves
+    SfxMedium* pMed = new SfxMedium( aTmpObj.GetMainURL(
+                             INetURLObject::NO_DECODE ), STREAM_READ );
+    if( INET_PROT_FILE == aTmpObj.GetProtocol() )
+        pMed->DownLoad(); // Touch the medium (download it)
+
+    const SfxFilter* pSfxFlt = 0;
+    if( !pMed->GetError() )
+    {
+        SfxFilterMatcher aMatcher( OUString::createFromAscii(SwDocShell::Factory().GetShortName()) );
+
+        // No Filter, so search for it. Else test if the one passed is a valid one
+        if( !rFilter.isEmpty() )
+        {
+            pSfxFlt = aMatcher.GetFilter4FilterName( rFilter );
+        }
+
+        if( nVersion )
+            pMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion ));
+
+        if( !rPasswd.isEmpty() )
+            pMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd ));
+
+        if( !pSfxFlt )
+            aMatcher.DetectFilter( *pMed, &pSfxFlt, sal_False, sal_False );
+
+        if( pSfxFlt )
+        {
+            // We cannot do anything without a Filter
+            pMed->SetFilter( pSfxFlt );
+
+            // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure
+            xLockRef = new SwDocShell( SFX_CREATE_MODE_INTERNAL );
+            xDocSh = (SfxObjectShell*)xLockRef;
+            if( xDocSh->DoLoad( pMed ) )
+                return 2;
+        }
+    }
+
+    if( !xDocSh.Is() ) // Medium still needs to be deleted
+        delete pMed;
+
+    return 0;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/uiview/view2.cxx b/sw/source/ui/uiview/view2.cxx
index c68f616..04ae139 100644
--- a/sw/source/ui/uiview/view2.cxx
+++ b/sw/source/ui/uiview/view2.cxx
@@ -2177,13 +2177,8 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, SfxMedium* pMedium, sal_Int16 nVe
         SfxObjectShellRef xDocSh;
         SfxObjectShellLock xLockRef;
 
-        extern int sw_FindDocShell( SfxObjectShellRef& xDocSh, SfxObjectShellLock& xLockRef,
-                            const String& rFileName, const String& rPasswd,
-                            String& rFilter, sal_Int16 nVersion,
-                            SwDocShell* pDestSh );
-
         String sFltNm;
-        int nRet = sw_FindDocShell( xDocSh, xLockRef, pMedium->GetName(), aEmptyStr,
+        const int nRet = SwFindDocShell( xDocSh, xLockRef, pMedium->GetName(), OUString(),
                                     sFltNm, nVersion, pDocSh );
         if( nRet )
         {
@@ -2204,9 +2199,9 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, SfxMedium* pMedium, sal_Int16 nVe
                 Window* pWin = &GetEditWin();
                 InfoBox(pWin, SW_RES(MSG_NO_MERGE_ENTRY)).Execute();
             }
+            if( nRet==2 && xDocSh.Is() )
+                xDocSh->DoClose();
         }
-        if( 2 == nRet && xDocSh.Is() )
-            xDocSh->DoClose();
     }
 
     delete pMedium;


More information about the Libreoffice-commits mailing list