1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
27
28 #include <memory>
29 #include <set>
30
31 #include <tools/debug.hxx>
32 #include <osl/module.hxx>
33 #include <osl/mutex.hxx>
34 #include <sfx2/docfile.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/progress.hxx>
37 #include <svl/itemset.hxx>
38
39 #include "../ui/inc/DrawDocShell.hxx"
40 #include "../ui/inc/strings.hrc"
41
42 #include "sdresid.hxx"
43 #include "pres.hxx"
44 #include "drawdoc.hxx"
45 #include "sdfilter.hxx"
46
47 // --------------
48 // - Namespaces -
49 // --------------
50
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::task;
53 using namespace ::com::sun::star::frame;
54
55 // ------------
56 // - SdFilter -
57 // ------------
58
SdFilter(SfxMedium & rMedium,::sd::DrawDocShell & rDocShell,sal_Bool bShowProgress)59 SdFilter::SdFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell, sal_Bool bShowProgress )
60 : mxModel( rDocShell.GetModel() )
61 , mrMedium( rMedium )
62 , mrDocShell( rDocShell )
63 , mrDocument( *rDocShell.GetDoc() )
64 , mbIsDraw( rDocShell.GetDocumentType() == DOCUMENT_TYPE_DRAW )
65 , mbShowProgress( bShowProgress )
66 {
67 }
68
69 // -----------------------------------------------------------------------------
70
~SdFilter()71 SdFilter::~SdFilter()
72 {
73 }
74
75 // -----------------------------------------------------------------------------
76
ImplGetFullLibraryName(const::rtl::OUString & rLibraryName) const77 ::rtl::OUString SdFilter::ImplGetFullLibraryName( const ::rtl::OUString& rLibraryName ) const
78 {
79 String aTemp( ::rtl::OUString::createFromAscii( SVLIBRARY( "?" ) ) );
80 xub_StrLen nIndex = aTemp.Search( (sal_Unicode)'?' );
81 aTemp.Replace( nIndex, 1, rLibraryName );
82 ::rtl::OUString aLibraryName( aTemp );
83 return aLibraryName;
84 }
85
86 // -----------------------------------------------------------------------------
87
thisModule()88 extern "C" { static void SAL_CALL thisModule() {} }
89
OpenLibrary(const::rtl::OUString & rLibraryName) const90 ::osl::Module* SdFilter::OpenLibrary( const ::rtl::OUString& rLibraryName ) const
91 {
92 const ::rtl::OUString aFullName( ImplGetFullLibraryName( rLibraryName ) );
93 std::unique_ptr< osl::Module > mod(new osl::Module);
94 if ( !mod->loadRelative( &thisModule, aFullName ) )
95 return 0;
96
97 // Callers delete the returned Module, which unloads the library. But an
98 // import leaves objects in the document whose virtual-function tables live
99 // in the filter library or in a library it pulls in (sdfilt -> msfilter):
100 // once that is unloaded, the next virtual call on such an object jumps into
101 // unmapped memory. Opening a .ppt as the first document crashed that way
102 // in SdrObjListIter right after the import; with any document opened
103 // before, msfilter was still held by another component and survived.
104 // Take one extra reference per library and never release it, so a filter
105 // library stays loaded for the rest of the process once it has been used.
106 static std::set< ::rtl::OUString > aPinned;
107 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
108 if ( aPinned.insert( aFullName ).second )
109 osl_loadModuleRelative( &thisModule, aFullName.pData, SAL_LOADMODULE_DEFAULT );
110
111 return mod.release();
112 }
113
114 // -----------------------------------------------------------------------------
115
CreateStatusIndicator()116 void SdFilter::CreateStatusIndicator()
117 {
118 // The status indicator must be retrieved from the provided medium arguments
119 const SfxUnoAnyItem* pStatusBarItem = static_cast<const SfxUnoAnyItem*>(
120 mrMedium.GetItemSet()->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) );
121
122 if ( pStatusBarItem )
123 pStatusBarItem->GetValue() >>= mxStatusIndicator;
124
125 // try
126 // {
127 // if (mxModel.is())
128 // {
129 // Reference< XController > xController( mxModel->getCurrentController());
130 // if( xController.is())
131 // {
132 // Reference< XFrame > xFrame( xController->getFrame());
133 // if( xFrame.is())
134 // {
135 // Reference< XStatusIndicatorFactory > xFactory( xFrame, UNO_QUERY );
136 // if( xFactory.is())
137 // {
138 // mxStatusIndicator = xFactory->createStatusIndicator();
139 // }
140 // }
141 // }
142 // }
143 // }
144 // catch( Exception& )
145 // {
146 // }
147 }
148