bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / framework / factories / ViewShellWrapper.cxx
blob68ebb2a1d5361ea605e42abb9aad06044d56e487
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "framework/ViewShellWrapper.hxx"
21 #include "framework/Pane.hxx"
22 #include "sdpage.hxx"
23 #include "ViewShell.hxx"
24 #include "Window.hxx"
26 #include "SlideSorter.hxx"
27 #include "SlideSorterViewShell.hxx"
28 #include "controller/SlsPageSelector.hxx"
29 #include "controller/SlsCurrentSlideManager.hxx"
30 #include "controller/SlideSorterController.hxx"
31 #include "model/SlsPageEnumerationProvider.hxx"
32 #include "model/SlideSorterModel.hxx"
33 #include "model/SlsPageDescriptor.hxx"
35 #include <com/sun/star/drawing/framework/XPane.hpp>
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <toolkit/helper/vclunohelper.hxx>
40 #include <comphelper/sequence.hxx>
41 #include <comphelper/servicehelper.hxx>
42 #include <cppuhelper/typeprovider.hxx>
43 #include <vcl/svapp.hxx>
44 #include <osl/mutex.hxx>
45 #include <tools/diagnose_ex.h>
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::drawing::framework;
51 using ::com::sun::star::awt::XWindow;
52 using ::com::sun::star::rendering::XCanvas;
53 using ::com::sun::star::lang::DisposedException;
55 namespace sd { namespace framework {
57 ViewShellWrapper::ViewShellWrapper (
58 ::boost::shared_ptr<ViewShell> pViewShell,
59 const Reference<XResourceId>& rxViewId,
60 const Reference<awt::XWindow>& rxWindow)
61 : ViewShellWrapperInterfaceBase(MutexOwner::maMutex),
62 mpViewShell(pViewShell),
63 mpSlideSorterViewShell(
64 ::boost::dynamic_pointer_cast< ::sd::slidesorter::SlideSorterViewShell >( pViewShell )),
65 mxViewId(rxViewId),
66 mxWindow(rxWindow)
70 ViewShellWrapper::~ViewShellWrapper()
74 void SAL_CALL ViewShellWrapper::disposing()
76 ::osl::MutexGuard aGuard( maMutex );
78 SAL_INFO("sd.ui", "disposing ViewShellWrapper " << this);
79 Reference<awt::XWindow> xWindow (mxWindow);
80 if (xWindow.is())
82 SAL_INFO(
83 "sd.ui",
84 "removing ViewShellWrapper " << this << " from window listener at "
85 << mxWindow.get());
86 xWindow->removeWindowListener(this);
89 mpSlideSorterViewShell.reset();
90 mpViewShell.reset();
93 uno::Any SAL_CALL ViewShellWrapper::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException, std::exception)
95 if( mpSlideSorterViewShell &&
96 rType == cppu::UnoType<view::XSelectionSupplier>::get() )
98 uno::Any aAny;
99 uno::Reference<view::XSelectionSupplier> xSupplier( this );
100 aAny <<= xSupplier;
102 return aAny;
104 else
105 return ViewShellWrapperInterfaceBase::queryInterface( rType );
108 //----- XResource -------------------------------------------------------------
110 Reference<XResourceId> SAL_CALL ViewShellWrapper::getResourceId()
111 throw (RuntimeException, std::exception)
113 return mxViewId;
116 sal_Bool SAL_CALL ViewShellWrapper::isAnchorOnly()
117 throw (RuntimeException, std::exception)
119 return false;
122 //----- XSelectionSupplier --------------------------------------------------
124 sal_Bool SAL_CALL ViewShellWrapper::select( const ::com::sun::star::uno::Any& aSelection ) throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
126 if (!mpSlideSorterViewShell)
127 return false;
129 bool bOk = true;
131 ::sd::slidesorter::controller::SlideSorterController& rSlideSorterController
132 = mpSlideSorterViewShell->GetSlideSorter().GetController();
133 ::sd::slidesorter::controller::PageSelector& rSelector (rSlideSorterController.GetPageSelector());
134 rSelector.DeselectAllPages();
135 Sequence<Reference<drawing::XDrawPage> > xPages;
136 aSelection >>= xPages;
137 const sal_uInt32 nCount = xPages.getLength();
138 for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
140 Reference<beans::XPropertySet> xSet (xPages[nIndex], UNO_QUERY);
141 if (xSet.is())
145 Any aNumber = xSet->getPropertyValue("Number");
146 sal_Int32 nPageNumber = 0;
147 aNumber >>= nPageNumber;
148 nPageNumber -=1; // Transform 1-based page numbers to 0-based ones.
149 rSelector.SelectPage(nPageNumber);
151 catch (const RuntimeException&)
157 return bOk;
160 uno::Any SAL_CALL ViewShellWrapper::getSelection()
161 throw (uno::RuntimeException, std::exception)
163 Any aResult;
165 if (!mpSlideSorterViewShell)
166 return aResult;
168 slidesorter::model::PageEnumeration aSelectedPages (
169 slidesorter::model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
170 mpSlideSorterViewShell->GetSlideSorter().GetModel()));
171 int nSelectedPageCount (
172 mpSlideSorterViewShell->GetSlideSorter().GetController().GetPageSelector().GetSelectedPageCount());
174 Sequence<Reference<XInterface> > aPages(nSelectedPageCount);
175 int nIndex = 0;
176 while (aSelectedPages.HasMoreElements() && nIndex<nSelectedPageCount)
178 slidesorter::model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
179 aPages[nIndex++] = pDescriptor->GetPage()->getUnoPage();
181 aResult <<= aPages;
183 return aResult;
186 void SAL_CALL ViewShellWrapper::addSelectionChangeListener( const uno::Reference< view::XSelectionChangeListener >& ) throw(uno::RuntimeException, std::exception)
190 void SAL_CALL ViewShellWrapper::removeSelectionChangeListener( const uno::Reference< view::XSelectionChangeListener >& ) throw(uno::RuntimeException, std::exception)
194 //----- XRelocatableResource --------------------------------------------------
196 sal_Bool SAL_CALL ViewShellWrapper::relocateToAnchor (
197 const Reference<XResource>& xResource)
198 throw (RuntimeException, std::exception)
200 bool bResult (false);
202 Reference<XPane> xPane (xResource, UNO_QUERY);
203 if (xPane.is())
205 // Detach from the window of the old pane.
206 Reference<awt::XWindow> xWindow (mxWindow);
207 if (xWindow.is())
208 xWindow->removeWindowListener(this);
209 mxWindow = NULL;
211 if (mpViewShell.get() != NULL)
213 vcl::Window* pWindow = VCLUnoHelper::GetWindow(xPane->getWindow());
214 if (pWindow != NULL && mpViewShell->RelocateToParentWindow(pWindow))
216 bResult = true;
218 // Attach to the window of the new pane.
219 xWindow = Reference<awt::XWindow>(xPane->getWindow(), UNO_QUERY);
220 if (xWindow.is())
222 xWindow->addWindowListener(this);
223 mpViewShell->Resize();
229 return bResult;
232 //----- XUnoTunnel ------------------------------------------------------------
234 namespace
236 class theViewShellWrapperUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theViewShellWrapperUnoTunnelId> {};
239 const Sequence<sal_Int8>& ViewShellWrapper::getUnoTunnelId()
241 return theViewShellWrapperUnoTunnelId::get().getSeq();
244 sal_Int64 SAL_CALL ViewShellWrapper::getSomething (const Sequence<sal_Int8>& rId)
245 throw (RuntimeException, std::exception)
247 sal_Int64 nResult = 0;
249 if (rId.getLength() == 16
250 && memcmp(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
252 nResult = reinterpret_cast<sal_Int64>(this);
255 return nResult;
258 //===== awt::XWindowListener ==================================================
260 void SAL_CALL ViewShellWrapper::windowResized (const awt::WindowEvent& rEvent)
261 throw (RuntimeException, std::exception)
263 (void)rEvent;
264 ViewShell* pViewShell (mpViewShell.get());
265 if (pViewShell != NULL)
266 pViewShell->Resize();
269 void SAL_CALL ViewShellWrapper::windowMoved (const awt::WindowEvent& rEvent)
270 throw (RuntimeException, std::exception)
272 (void)rEvent;
275 void SAL_CALL ViewShellWrapper::windowShown (const lang::EventObject& rEvent)
276 throw (RuntimeException, std::exception)
278 (void)rEvent;
279 ViewShell* pViewShell (mpViewShell.get());
280 if (pViewShell != NULL)
281 pViewShell->Resize();
284 void SAL_CALL ViewShellWrapper::windowHidden (const lang::EventObject& rEvent)
285 throw (RuntimeException, std::exception)
287 (void)rEvent;
290 //===== XEventListener ========================================================
292 void SAL_CALL ViewShellWrapper::disposing (const lang::EventObject& rEvent)
293 throw (RuntimeException, std::exception)
295 if (rEvent.Source == mxWindow)
296 mxWindow = NULL;
299 } } // end of namespace sd::framework
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */