xref: /AOO41X/main/sd/source/ui/framework/factories/BasicViewFactory.cxx (revision ca62e2c2083b5d0995f1245bad6c2edfb455fbec)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "BasicViewFactory.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "framework/ViewShellWrapper.hxx"
29cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx"
30cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
32cdf0e10cSrcweir #include "framework/Pane.hxx"
33cdf0e10cSrcweir #include "DrawController.hxx"
34cdf0e10cSrcweir #include "DrawSubController.hxx"
35cdf0e10cSrcweir #include "ViewShellBase.hxx"
36cdf0e10cSrcweir #include "ViewShellManager.hxx"
37cdf0e10cSrcweir #include "DrawDocShell.hxx"
38cdf0e10cSrcweir #include "DrawViewShell.hxx"
39cdf0e10cSrcweir #include "GraphicViewShell.hxx"
40cdf0e10cSrcweir #include "OutlineViewShell.hxx"
41cdf0e10cSrcweir #include "PresentationViewShell.hxx"
42cdf0e10cSrcweir #include "SlideSorterViewShell.hxx"
43cdf0e10cSrcweir #include "FrameView.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
46cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
47cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir #include <boost/bind.hpp>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir using namespace ::com::sun::star;
52cdf0e10cSrcweir using namespace ::com::sun::star::uno;
53cdf0e10cSrcweir using namespace ::com::sun::star::lang;
54cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir using ::rtl::OUString;
57cdf0e10cSrcweir using ::sd::framework::FrameworkHelper;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir namespace sd { namespace framework {
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
BasicViewFactory_createInstance(const Reference<XComponentContext> & rxContext)63cdf0e10cSrcweir Reference<XInterface> SAL_CALL BasicViewFactory_createInstance (
64cdf0e10cSrcweir     const Reference<XComponentContext>& rxContext)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     return Reference<XInterface>(static_cast<XWeak*>(new BasicViewFactory(rxContext)));
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
BasicViewFactory_getImplementationName(void)72cdf0e10cSrcweir ::rtl::OUString BasicViewFactory_getImplementationName (void) throw(RuntimeException)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir     return ::rtl::OUString(
75cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Draw.framework.BasicViewFactory"));
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
BasicViewFactory_getSupportedServiceNames(void)81cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL BasicViewFactory_getSupportedServiceNames (void)
82cdf0e10cSrcweir     throw (RuntimeException)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	static const ::rtl::OUString sServiceName(
85cdf0e10cSrcweir         ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.BasicViewFactory"));
86cdf0e10cSrcweir 	return Sequence<rtl::OUString>(&sServiceName, 1);
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //===== ViewDescriptor ========================================================
93cdf0e10cSrcweir 
94cdf0e10cSrcweir class BasicViewFactory::ViewDescriptor
95cdf0e10cSrcweir {
96cdf0e10cSrcweir public:
97cdf0e10cSrcweir     Reference<XResource> mxView;
98cdf0e10cSrcweir     ::boost::shared_ptr<sd::ViewShell> mpViewShell;
99cdf0e10cSrcweir     ViewShellWrapper* mpWrapper;
100cdf0e10cSrcweir     Reference<XResourceId> mxViewId;
CompareView(const::boost::shared_ptr<ViewDescriptor> & rpDescriptor,const Reference<XResource> & rxView)101cdf0e10cSrcweir     static bool CompareView (const ::boost::shared_ptr<ViewDescriptor>& rpDescriptor,
102cdf0e10cSrcweir         const Reference<XResource>& rxView)
103cdf0e10cSrcweir     { return rpDescriptor->mxView.get() == rxView.get(); }
104cdf0e10cSrcweir };
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir //===== BasicViewFactory::ViewShellContainer ==================================
111cdf0e10cSrcweir 
112cdf0e10cSrcweir class BasicViewFactory::ViewShellContainer
113cdf0e10cSrcweir     : public ::std::vector<boost::shared_ptr<ViewDescriptor> >
114cdf0e10cSrcweir {
115cdf0e10cSrcweir public:
ViewShellContainer(void)116cdf0e10cSrcweir     ViewShellContainer (void) {};
117cdf0e10cSrcweir };
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 
120cdf0e10cSrcweir class BasicViewFactory::ViewCache
121cdf0e10cSrcweir     : public ::std::vector<boost::shared_ptr<ViewDescriptor> >
122cdf0e10cSrcweir {
123cdf0e10cSrcweir public:
ViewCache(void)124cdf0e10cSrcweir     ViewCache (void) {};
125cdf0e10cSrcweir };
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
130cdf0e10cSrcweir //===== ViewFactory ===========================================================
131cdf0e10cSrcweir 
BasicViewFactory(const Reference<XComponentContext> & rxContext)132cdf0e10cSrcweir BasicViewFactory::BasicViewFactory (
133cdf0e10cSrcweir     const Reference<XComponentContext>& rxContext)
134cdf0e10cSrcweir     : BasicViewFactoryInterfaceBase(MutexOwner::maMutex),
135cdf0e10cSrcweir       mxConfigurationController(),
136cdf0e10cSrcweir       mpViewShellContainer(new ViewShellContainer()),
137cdf0e10cSrcweir       mpBase(NULL),
138cdf0e10cSrcweir       mpFrameView(NULL),
139cdf0e10cSrcweir       mpWindow(new WorkWindow(NULL,WB_STDWORK)),
140cdf0e10cSrcweir       mpViewCache(new ViewCache()),
141cdf0e10cSrcweir       mxLocalPane(new Pane(Reference<XResourceId>(), mpWindow.get()))
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     (void)rxContext;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 
~BasicViewFactory(void)149cdf0e10cSrcweir BasicViewFactory::~BasicViewFactory (void)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 
disposing(void)156cdf0e10cSrcweir void SAL_CALL BasicViewFactory::disposing (void)
157cdf0e10cSrcweir {
158cdf0e10cSrcweir     // Disconnect from the frame view.
159cdf0e10cSrcweir     if (mpFrameView != NULL)
160cdf0e10cSrcweir     {
161cdf0e10cSrcweir         mpFrameView->Disconnect();
162cdf0e10cSrcweir         mpFrameView = NULL;
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     // Relase the view cache.
166cdf0e10cSrcweir     ViewShellContainer::const_iterator iView;
167cdf0e10cSrcweir     for (iView=mpViewCache->begin(); iView!=mpViewCache->end(); ++iView)
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         ReleaseView(*iView, true);
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     // Release the view shell container.  At this point no one other than us
173cdf0e10cSrcweir     // should hold references to the view shells (at the moment this is a
174cdf0e10cSrcweir     // trivial requirement, because no one other then us holds a shared
175cdf0e10cSrcweir     // pointer).
176cdf0e10cSrcweir     //    ViewShellContainer::const_iterator iView;
177cdf0e10cSrcweir     for (iView=mpViewShellContainer->begin(); iView!=mpViewShellContainer->end(); ++iView)
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         OSL_ASSERT((*iView)->mpViewShell.unique());
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir     mpViewShellContainer.reset();
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
createResource(const Reference<XResourceId> & rxViewId)187cdf0e10cSrcweir Reference<XResource> SAL_CALL BasicViewFactory::createResource (
188cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId)
189cdf0e10cSrcweir     throw(RuntimeException, IllegalArgumentException, WrappedTargetException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     Reference<XResource> xView;
192cdf0e10cSrcweir     const bool bIsCenterPane (
193cdf0e10cSrcweir         rxViewId->isBoundToURL(FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT));
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     // Get the pane for the anchor URL.
196cdf0e10cSrcweir     Reference<XPane> xPane;
197cdf0e10cSrcweir     if (mxConfigurationController.is())
198cdf0e10cSrcweir         xPane = Reference<XPane>(mxConfigurationController->getResource(rxViewId->getAnchor()),
199cdf0e10cSrcweir             UNO_QUERY);
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     // For main views use the frame view of the last main view.
202cdf0e10cSrcweir     ::sd::FrameView* pFrameView = NULL;
203cdf0e10cSrcweir     if (xPane.is() && bIsCenterPane)
204cdf0e10cSrcweir     {
205cdf0e10cSrcweir         pFrameView = mpFrameView;
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     // Get Window pointer for XWindow of the pane.
209cdf0e10cSrcweir     ::Window* pWindow = NULL;
210cdf0e10cSrcweir     if (xPane.is())
211cdf0e10cSrcweir         pWindow = VCLUnoHelper::GetWindow(xPane->getWindow());
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     // Get the view frame.
214cdf0e10cSrcweir     SfxViewFrame* pFrame = NULL;
215cdf0e10cSrcweir     if (mpBase != NULL)
216cdf0e10cSrcweir         pFrame = mpBase->GetViewFrame();
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     if (pFrame != NULL && mpBase!=NULL && pWindow!=NULL)
219cdf0e10cSrcweir     {
220cdf0e10cSrcweir         // Try to get the view from the cache.
221cdf0e10cSrcweir         ::boost::shared_ptr<ViewDescriptor> pDescriptor (GetViewFromCache(rxViewId, xPane));
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         // When the requested view is not in the cache then create a new view.
224cdf0e10cSrcweir         if (pDescriptor.get() == NULL)
225cdf0e10cSrcweir         {
226cdf0e10cSrcweir             pDescriptor = CreateView(rxViewId, *pFrame, *pWindow, xPane, pFrameView, bIsCenterPane);
227cdf0e10cSrcweir         }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir         if (pDescriptor.get() != NULL)
230cdf0e10cSrcweir             xView = pDescriptor->mxView;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         mpViewShellContainer->push_back(pDescriptor);
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         if (bIsCenterPane)
235cdf0e10cSrcweir             ActivateCenterView(pDescriptor);
236cdf0e10cSrcweir         else
237cdf0e10cSrcweir             pWindow->Resize();
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     return xView;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 
releaseResource(const Reference<XResource> & rxView)246cdf0e10cSrcweir void SAL_CALL BasicViewFactory::releaseResource (const Reference<XResource>& rxView)
247cdf0e10cSrcweir     throw(RuntimeException)
248cdf0e10cSrcweir {
249cdf0e10cSrcweir     if ( ! rxView.is())
250cdf0e10cSrcweir         throw lang::IllegalArgumentException();
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     if (rxView.is() && mpBase!=NULL)
253cdf0e10cSrcweir     {
254cdf0e10cSrcweir         ViewShellContainer::iterator iViewShell (
255cdf0e10cSrcweir             ::std::find_if(
256cdf0e10cSrcweir                 mpViewShellContainer->begin(),
257cdf0e10cSrcweir                 mpViewShellContainer->end(),
258cdf0e10cSrcweir                 ::boost::bind(&ViewDescriptor::CompareView, _1, rxView)));
259cdf0e10cSrcweir         if (iViewShell != mpViewShellContainer->end())
260cdf0e10cSrcweir         {
261cdf0e10cSrcweir             ::boost::shared_ptr<ViewShell> pViewShell ((*iViewShell)->mpViewShell);
262cdf0e10cSrcweir 
263cdf0e10cSrcweir             if ((*iViewShell)->mxViewId->isBoundToURL(
264cdf0e10cSrcweir                 FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
265cdf0e10cSrcweir             {
266cdf0e10cSrcweir                 // Obtain a pointer to and connect to the frame view of the
267cdf0e10cSrcweir                 // view.  The next view, that is created, will be
268cdf0e10cSrcweir                 // initialized with this frame view.
269cdf0e10cSrcweir                 if (mpFrameView == NULL)
270cdf0e10cSrcweir                 {
271cdf0e10cSrcweir                     mpFrameView = pViewShell->GetFrameView();
272cdf0e10cSrcweir                     if (mpFrameView)
273cdf0e10cSrcweir                         mpFrameView->Connect();
274cdf0e10cSrcweir                 }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir                 // With the view in the center pane the sub controller is
277cdf0e10cSrcweir                 // released, too.
278cdf0e10cSrcweir                 mpBase->GetDrawController().SetSubController(
279cdf0e10cSrcweir                     Reference<drawing::XDrawSubController>());
280cdf0e10cSrcweir 
281cdf0e10cSrcweir                 SfxViewShell* pSfxViewShell = pViewShell->GetViewShell();
282cdf0e10cSrcweir                 if (pSfxViewShell != NULL)
283cdf0e10cSrcweir                     pSfxViewShell->DisconnectAllClients();
284cdf0e10cSrcweir             }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir             ReleaseView(*iViewShell);
287cdf0e10cSrcweir 
288cdf0e10cSrcweir             mpViewShellContainer->erase(iViewShell);
289cdf0e10cSrcweir         }
290cdf0e10cSrcweir         else
291cdf0e10cSrcweir         {
292cdf0e10cSrcweir             throw lang::IllegalArgumentException();
293cdf0e10cSrcweir         }
294cdf0e10cSrcweir     }
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 
initialize(const Sequence<Any> & aArguments)300cdf0e10cSrcweir void SAL_CALL BasicViewFactory::initialize (const Sequence<Any>& aArguments)
301cdf0e10cSrcweir     throw (Exception, RuntimeException)
302cdf0e10cSrcweir {
303cdf0e10cSrcweir     if (aArguments.getLength() > 0)
304cdf0e10cSrcweir     {
305cdf0e10cSrcweir         Reference<XConfigurationController> xCC;
306cdf0e10cSrcweir         try
307cdf0e10cSrcweir         {
308cdf0e10cSrcweir             // Get the XController from the first argument.
309cdf0e10cSrcweir             Reference<frame::XController> xController (aArguments[0], UNO_QUERY_THROW);
310cdf0e10cSrcweir 
311cdf0e10cSrcweir             // Tunnel through the controller to obtain a ViewShellBase.
312cdf0e10cSrcweir             Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
313cdf0e10cSrcweir             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
314cdf0e10cSrcweir                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
315cdf0e10cSrcweir             if (pController != NULL)
316cdf0e10cSrcweir                 mpBase = pController->GetViewShellBase();
317cdf0e10cSrcweir 
318cdf0e10cSrcweir             // Register the factory for its supported views.
319cdf0e10cSrcweir             Reference<XControllerManager> xCM (xController,UNO_QUERY_THROW);
320cdf0e10cSrcweir             mxConfigurationController = xCM->getConfigurationController();
321cdf0e10cSrcweir             if ( ! mxConfigurationController.is())
322cdf0e10cSrcweir                 throw RuntimeException();
323cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(FrameworkHelper::msImpressViewURL, this);
324cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(FrameworkHelper::msDrawViewURL, this);
325cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(FrameworkHelper::msOutlineViewURL, this);
326cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(FrameworkHelper::msNotesViewURL, this);
327cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(FrameworkHelper::msHandoutViewURL, this);
328cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(FrameworkHelper::msPresentationViewURL, this);
329cdf0e10cSrcweir             mxConfigurationController->addResourceFactory(FrameworkHelper::msSlideSorterURL, this);
330cdf0e10cSrcweir         }
331cdf0e10cSrcweir         catch (RuntimeException&)
332cdf0e10cSrcweir         {
333cdf0e10cSrcweir             mpBase = NULL;
334cdf0e10cSrcweir             if (mxConfigurationController.is())
335cdf0e10cSrcweir                 mxConfigurationController->removeResourceFactoryForReference(this);
336cdf0e10cSrcweir             throw;
337cdf0e10cSrcweir         }
338cdf0e10cSrcweir     }
339cdf0e10cSrcweir }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 
CreateView(const Reference<XResourceId> & rxViewId,SfxViewFrame & rFrame,::Window & rWindow,const Reference<XPane> & rxPane,FrameView * pFrameView,const bool bIsCenterPane)344cdf0e10cSrcweir ::boost::shared_ptr<BasicViewFactory::ViewDescriptor> BasicViewFactory::CreateView (
345cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId,
346cdf0e10cSrcweir     SfxViewFrame& rFrame,
347cdf0e10cSrcweir     ::Window& rWindow,
348cdf0e10cSrcweir     const Reference<XPane>& rxPane,
349cdf0e10cSrcweir     FrameView* pFrameView,
350cdf0e10cSrcweir     const bool bIsCenterPane)
351cdf0e10cSrcweir {
352cdf0e10cSrcweir     ::boost::shared_ptr<ViewDescriptor> pDescriptor (new ViewDescriptor());
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     pDescriptor->mpViewShell = CreateViewShell(
355cdf0e10cSrcweir         rxViewId,
356cdf0e10cSrcweir         rFrame,
357cdf0e10cSrcweir         rWindow,
358cdf0e10cSrcweir         pFrameView,
359cdf0e10cSrcweir         bIsCenterPane);
360cdf0e10cSrcweir     pDescriptor->mxViewId = rxViewId;
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     if (pDescriptor->mpViewShell.get() != NULL)
363cdf0e10cSrcweir     {
364cdf0e10cSrcweir         pDescriptor->mpViewShell->Init(bIsCenterPane);
365cdf0e10cSrcweir         mpBase->GetViewShellManager()->ActivateViewShell(pDescriptor->mpViewShell.get());
366cdf0e10cSrcweir 
367cdf0e10cSrcweir         pDescriptor->mpWrapper = new ViewShellWrapper(
368cdf0e10cSrcweir             pDescriptor->mpViewShell,
369cdf0e10cSrcweir             rxViewId,
370cdf0e10cSrcweir             rxPane->getWindow());
371cdf0e10cSrcweir         pDescriptor->mxView.set( pDescriptor->mpWrapper->queryInterface( XResource::static_type() ), UNO_QUERY_THROW );
372cdf0e10cSrcweir     }
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     return pDescriptor;
375cdf0e10cSrcweir }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 
CreateViewShell(const Reference<XResourceId> & rxViewId,SfxViewFrame & rFrame,::Window & rWindow,FrameView * pFrameView,const bool bIsCenterPane)380cdf0e10cSrcweir ::boost::shared_ptr<ViewShell> BasicViewFactory::CreateViewShell (
381cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId,
382cdf0e10cSrcweir     SfxViewFrame& rFrame,
383cdf0e10cSrcweir     ::Window& rWindow,
384cdf0e10cSrcweir     FrameView* pFrameView,
385cdf0e10cSrcweir     const bool bIsCenterPane)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir     ::boost::shared_ptr<ViewShell> pViewShell;
388cdf0e10cSrcweir     const OUString& rsViewURL (rxViewId->getResourceURL());
389cdf0e10cSrcweir     if (rsViewURL.equals(FrameworkHelper::msImpressViewURL))
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir         pViewShell.reset(
392cdf0e10cSrcweir             new DrawViewShell(
393cdf0e10cSrcweir                 &rFrame,
394cdf0e10cSrcweir                 *mpBase,
395cdf0e10cSrcweir                 &rWindow,
396cdf0e10cSrcweir                 PK_STANDARD,
397cdf0e10cSrcweir                 pFrameView));
398cdf0e10cSrcweir     }
399cdf0e10cSrcweir     else if (rsViewURL.equals(FrameworkHelper::msDrawViewURL))
400cdf0e10cSrcweir     {
401cdf0e10cSrcweir         pViewShell.reset(
402cdf0e10cSrcweir             new GraphicViewShell (
403cdf0e10cSrcweir                 &rFrame,
404cdf0e10cSrcweir                 *mpBase,
405cdf0e10cSrcweir                 &rWindow,
406cdf0e10cSrcweir                 pFrameView));
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir     else if (rsViewURL.equals(FrameworkHelper::msOutlineViewURL))
409cdf0e10cSrcweir     {
410cdf0e10cSrcweir         pViewShell.reset(
411cdf0e10cSrcweir             new OutlineViewShell (
412cdf0e10cSrcweir                 &rFrame,
413cdf0e10cSrcweir                 *mpBase,
414cdf0e10cSrcweir                 &rWindow,
415cdf0e10cSrcweir                 pFrameView));
416cdf0e10cSrcweir     }
417cdf0e10cSrcweir     else if (rsViewURL.equals(FrameworkHelper::msNotesViewURL))
418cdf0e10cSrcweir     {
419cdf0e10cSrcweir         pViewShell.reset(
420cdf0e10cSrcweir             new DrawViewShell(
421cdf0e10cSrcweir                 &rFrame,
422cdf0e10cSrcweir                 *mpBase,
423cdf0e10cSrcweir                 &rWindow,
424cdf0e10cSrcweir                 PK_NOTES,
425cdf0e10cSrcweir                 pFrameView));
426cdf0e10cSrcweir     }
427cdf0e10cSrcweir     else if (rsViewURL.equals(FrameworkHelper::msHandoutViewURL))
428cdf0e10cSrcweir     {
429cdf0e10cSrcweir         pViewShell.reset(
430cdf0e10cSrcweir             new DrawViewShell(
431cdf0e10cSrcweir                 &rFrame,
432cdf0e10cSrcweir                 *mpBase,
433cdf0e10cSrcweir                 &rWindow,
434cdf0e10cSrcweir                 PK_HANDOUT,
435cdf0e10cSrcweir                 pFrameView));
436cdf0e10cSrcweir     }
437cdf0e10cSrcweir     else if (rsViewURL.equals(FrameworkHelper::msPresentationViewURL))
438cdf0e10cSrcweir     {
439cdf0e10cSrcweir         pViewShell.reset(
440cdf0e10cSrcweir             new PresentationViewShell(
441cdf0e10cSrcweir                 &rFrame,
442cdf0e10cSrcweir                 *mpBase,
443cdf0e10cSrcweir                 &rWindow,
444cdf0e10cSrcweir                 pFrameView));
445cdf0e10cSrcweir     }
446cdf0e10cSrcweir     else if (rsViewURL.equals(FrameworkHelper::msSlideSorterURL))
447cdf0e10cSrcweir     {
448cdf0e10cSrcweir         pViewShell = ::sd::slidesorter::SlideSorterViewShell::Create (
449cdf0e10cSrcweir             &rFrame,
450cdf0e10cSrcweir             *mpBase,
451cdf0e10cSrcweir             &rWindow,
452cdf0e10cSrcweir             pFrameView,
453cdf0e10cSrcweir             bIsCenterPane);
454cdf0e10cSrcweir     }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir     return pViewShell;
457cdf0e10cSrcweir }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 
ReleaseView(const::boost::shared_ptr<ViewDescriptor> & rpDescriptor,bool bDoNotCache)462cdf0e10cSrcweir void BasicViewFactory::ReleaseView (
463cdf0e10cSrcweir     const ::boost::shared_ptr<ViewDescriptor>& rpDescriptor,
464cdf0e10cSrcweir     bool bDoNotCache)
465cdf0e10cSrcweir {
466cdf0e10cSrcweir     bool bIsCacheable (!bDoNotCache && IsCacheable(rpDescriptor));
467cdf0e10cSrcweir 
468cdf0e10cSrcweir     if (bIsCacheable)
469cdf0e10cSrcweir     {
470cdf0e10cSrcweir         Reference<XRelocatableResource> xResource (rpDescriptor->mxView, UNO_QUERY);
471cdf0e10cSrcweir         if (xResource.is())
472cdf0e10cSrcweir         {
473cdf0e10cSrcweir             Reference<XResource> xNewAnchor (mxLocalPane, UNO_QUERY);
474cdf0e10cSrcweir             if (xNewAnchor.is())
475cdf0e10cSrcweir                 if (xResource->relocateToAnchor(xNewAnchor))
476cdf0e10cSrcweir                     mpViewCache->push_back(rpDescriptor);
477cdf0e10cSrcweir                 else
478cdf0e10cSrcweir                     bIsCacheable = false;
479cdf0e10cSrcweir             else
480cdf0e10cSrcweir                 bIsCacheable = false;
481cdf0e10cSrcweir         }
482cdf0e10cSrcweir         else
483cdf0e10cSrcweir         {
484cdf0e10cSrcweir             bIsCacheable = false;
485cdf0e10cSrcweir         }
486cdf0e10cSrcweir     }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir     if ( ! bIsCacheable)
489cdf0e10cSrcweir     {
490cdf0e10cSrcweir         // Shut down the current view shell.
491cdf0e10cSrcweir         rpDescriptor->mpViewShell->Shutdown ();
492cdf0e10cSrcweir         mpBase->GetDocShell()->Disconnect(rpDescriptor->mpViewShell.get());
493cdf0e10cSrcweir         mpBase->GetViewShellManager()->DeactivateViewShell(rpDescriptor->mpViewShell.get());
494cdf0e10cSrcweir 
495cdf0e10cSrcweir         Reference<XComponent> xComponent (rpDescriptor->mxView, UNO_QUERY);
496cdf0e10cSrcweir         if (xComponent.is())
497cdf0e10cSrcweir             xComponent->dispose();
498cdf0e10cSrcweir     }
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 
503cdf0e10cSrcweir 
IsCacheable(const::boost::shared_ptr<ViewDescriptor> & rpDescriptor)504cdf0e10cSrcweir bool BasicViewFactory::IsCacheable (const ::boost::shared_ptr<ViewDescriptor>& rpDescriptor)
505cdf0e10cSrcweir {
506cdf0e10cSrcweir     bool bIsCacheable (false);
507cdf0e10cSrcweir 
508cdf0e10cSrcweir     Reference<XRelocatableResource> xResource (rpDescriptor->mxView, UNO_QUERY);
509cdf0e10cSrcweir     if (xResource.is())
510cdf0e10cSrcweir     {
511cdf0e10cSrcweir         static ::std::vector<Reference<XResourceId> > maCacheableResources;
512cdf0e10cSrcweir         if (maCacheableResources.empty() )
513cdf0e10cSrcweir         {
514cdf0e10cSrcweir             ::boost::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(*mpBase));
515cdf0e10cSrcweir 
516cdf0e10cSrcweir             // The slide sorter and the task panel are cacheable and relocatable.
517cdf0e10cSrcweir             maCacheableResources.push_back(pHelper->CreateResourceId(
518cdf0e10cSrcweir                 FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftDrawPaneURL));
519cdf0e10cSrcweir             maCacheableResources.push_back(pHelper->CreateResourceId(
520cdf0e10cSrcweir                 FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftImpressPaneURL));
521cdf0e10cSrcweir         }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir         ::std::vector<Reference<XResourceId> >::const_iterator iId;
524cdf0e10cSrcweir         for (iId=maCacheableResources.begin(); iId!=maCacheableResources.end(); ++iId)
525cdf0e10cSrcweir         {
526cdf0e10cSrcweir             if ((*iId)->compareTo(rpDescriptor->mxViewId) == 0)
527cdf0e10cSrcweir             {
528cdf0e10cSrcweir                 bIsCacheable = true;
529cdf0e10cSrcweir                 break;
530cdf0e10cSrcweir             }
531cdf0e10cSrcweir         }
532cdf0e10cSrcweir     }
533cdf0e10cSrcweir 
534cdf0e10cSrcweir     return bIsCacheable;
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 
GetViewFromCache(const Reference<XResourceId> & rxViewId,const Reference<XPane> & rxPane)540cdf0e10cSrcweir ::boost::shared_ptr<BasicViewFactory::ViewDescriptor> BasicViewFactory::GetViewFromCache (
541cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId,
542cdf0e10cSrcweir     const Reference<XPane>& rxPane)
543cdf0e10cSrcweir {
544cdf0e10cSrcweir     ::boost::shared_ptr<ViewDescriptor> pDescriptor;
545cdf0e10cSrcweir 
546cdf0e10cSrcweir     // Search for the requested view in the cache.
547cdf0e10cSrcweir     ViewCache::iterator iEntry;
548cdf0e10cSrcweir     for (iEntry=mpViewCache->begin(); iEntry!=mpViewCache->end(); ++iEntry)
549cdf0e10cSrcweir     {
550cdf0e10cSrcweir         if ((*iEntry)->mxViewId->compareTo(rxViewId) == 0)
551cdf0e10cSrcweir         {
552cdf0e10cSrcweir             pDescriptor = *iEntry;
553cdf0e10cSrcweir             mpViewCache->erase(iEntry);
554cdf0e10cSrcweir             break;
555cdf0e10cSrcweir         }
556cdf0e10cSrcweir     }
557cdf0e10cSrcweir 
558cdf0e10cSrcweir     // When the view has been found then relocate it to the given pane and
559cdf0e10cSrcweir     // remove it from the cache.
560cdf0e10cSrcweir     if (pDescriptor.get() != NULL)
561cdf0e10cSrcweir     {
562cdf0e10cSrcweir         bool bRelocationSuccessfull (false);
563cdf0e10cSrcweir         Reference<XRelocatableResource> xResource (pDescriptor->mxView, UNO_QUERY);
564cdf0e10cSrcweir         Reference<XResource> xNewAnchor (rxPane, UNO_QUERY);
565cdf0e10cSrcweir         if (xResource.is() && xNewAnchor.is())
566cdf0e10cSrcweir         {
567cdf0e10cSrcweir             if (xResource->relocateToAnchor(xNewAnchor))
568cdf0e10cSrcweir                 bRelocationSuccessfull = true;
569cdf0e10cSrcweir         }
570cdf0e10cSrcweir 
571cdf0e10cSrcweir         if ( ! bRelocationSuccessfull)
572cdf0e10cSrcweir         {
573cdf0e10cSrcweir             ReleaseView(pDescriptor, true);
574cdf0e10cSrcweir             pDescriptor.reset();
575cdf0e10cSrcweir         }
576cdf0e10cSrcweir     }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir     return pDescriptor;
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 
ActivateCenterView(const::boost::shared_ptr<ViewDescriptor> & rpDescriptor)584cdf0e10cSrcweir void BasicViewFactory::ActivateCenterView (
585cdf0e10cSrcweir     const ::boost::shared_ptr<ViewDescriptor>& rpDescriptor)
586cdf0e10cSrcweir {
587cdf0e10cSrcweir     mpBase->GetDocShell()->Connect(rpDescriptor->mpViewShell.get());
588cdf0e10cSrcweir 
589cdf0e10cSrcweir     // During the creation of the new sub-shell, resize requests were not
590cdf0e10cSrcweir     // forwarded to it because it was not yet registered.  Therefore, we
591cdf0e10cSrcweir     // have to request a resize now.
592cdf0e10cSrcweir     rpDescriptor->mpViewShell->UIFeatureChanged();
593cdf0e10cSrcweir     if (mpBase->GetDocShell()->IsInPlaceActive())
594cdf0e10cSrcweir         mpBase->GetViewFrame()->Resize(sal_True);
595cdf0e10cSrcweir 
596cdf0e10cSrcweir     mpBase->GetDrawController().SetSubController(
597cdf0e10cSrcweir         rpDescriptor->mpViewShell->CreateSubController());
598cdf0e10cSrcweir }
599cdf0e10cSrcweir 
600cdf0e10cSrcweir } } // end of namespace sd::framework
601