Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "framework/ViewShellWrapper.hxx"
22 : #include "framework/Pane.hxx"
23 : #include "sdpage.hxx"
24 : #include "ViewShell.hxx"
25 : #include "Window.hxx"
26 :
27 : #include "SlideSorter.hxx"
28 : #include "SlideSorterViewShell.hxx"
29 : #include "controller/SlsPageSelector.hxx"
30 : #include "controller/SlsCurrentSlideManager.hxx"
31 : #include "controller/SlideSorterController.hxx"
32 : #include "model/SlsPageEnumerationProvider.hxx"
33 : #include "model/SlideSorterModel.hxx"
34 : #include "model/SlsPageDescriptor.hxx"
35 :
36 : #include <com/sun/star/drawing/framework/XPane.hpp>
37 : #include <com/sun/star/lang/DisposedException.hpp>
38 : #include <com/sun/star/beans/XPropertySet.hpp>
39 :
40 : #include <toolkit/helper/vclunohelper.hxx>
41 : #include <comphelper/sequence.hxx>
42 : #include <comphelper/servicehelper.hxx>
43 : #include <cppuhelper/typeprovider.hxx>
44 : #include <vcl/svapp.hxx>
45 : #include <osl/mutex.hxx>
46 : #include <tools/diagnose_ex.h>
47 :
48 :
49 : using namespace ::com::sun::star;
50 : using namespace ::com::sun::star::uno;
51 : using namespace ::com::sun::star::drawing::framework;
52 :
53 : using ::com::sun::star::awt::XWindow;
54 : using ::com::sun::star::rendering::XCanvas;
55 : using ::com::sun::star::lang::DisposedException;
56 :
57 :
58 : namespace sd { namespace framework {
59 :
60 143 : ViewShellWrapper::ViewShellWrapper (
61 : ::boost::shared_ptr<ViewShell> pViewShell,
62 : const Reference<XResourceId>& rxViewId,
63 : const Reference<awt::XWindow>& rxWindow)
64 : : ViewShellWrapperInterfaceBase(MutexOwner::maMutex),
65 : mpViewShell(pViewShell),
66 : mpSlideSorterViewShell(
67 : ::boost::dynamic_pointer_cast< ::sd::slidesorter::SlideSorterViewShell >( pViewShell )),
68 : mxViewId(rxViewId),
69 143 : mxWindow(rxWindow)
70 : {
71 143 : }
72 :
73 :
74 :
75 :
76 286 : ViewShellWrapper::~ViewShellWrapper (void)
77 : {
78 286 : }
79 :
80 :
81 :
82 :
83 143 : void SAL_CALL ViewShellWrapper::disposing (void)
84 : {
85 143 : ::osl::MutexGuard aGuard( maMutex );
86 :
87 : OSL_TRACE("disposing ViewShellWrapper %x", this);
88 286 : Reference<awt::XWindow> xWindow (mxWindow);
89 143 : if (xWindow.is())
90 : {
91 : OSL_TRACE("removing ViewShellWrapper %x from window listener at %x", this, mxWindow.get());
92 65 : xWindow->removeWindowListener(this);
93 : }
94 :
95 143 : mpSlideSorterViewShell.reset();
96 286 : mpViewShell.reset();
97 143 : }
98 :
99 4685 : uno::Any SAL_CALL ViewShellWrapper::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException)
100 : {
101 5465 : if( mpSlideSorterViewShell &&
102 5465 : rType == ::getCppuType( static_cast< uno::Reference< view::XSelectionSupplier > * >( 0 ) ) )
103 : {
104 0 : uno::Any aAny;
105 0 : uno::Reference<view::XSelectionSupplier> xSupplier( this );
106 0 : aAny <<= xSupplier;
107 :
108 0 : return aAny;
109 : }
110 : else
111 4685 : return ViewShellWrapperInterfaceBase::queryInterface( rType );
112 : }
113 :
114 :
115 :
116 3172 : ::boost::shared_ptr<ViewShell> ViewShellWrapper::GetViewShell (void)
117 : {
118 3172 : return mpViewShell;
119 : }
120 :
121 :
122 :
123 :
124 : //----- XResource -------------------------------------------------------------
125 :
126 304 : Reference<XResourceId> SAL_CALL ViewShellWrapper::getResourceId (void)
127 : throw (RuntimeException)
128 : {
129 304 : return mxViewId;
130 : }
131 :
132 :
133 :
134 :
135 466 : sal_Bool SAL_CALL ViewShellWrapper::isAnchorOnly (void)
136 : throw (RuntimeException)
137 : {
138 466 : return false;
139 : }
140 :
141 :
142 : //----- XSelectionSupplier --------------------------------------------------
143 :
144 0 : sal_Bool SAL_CALL ViewShellWrapper::select( const ::com::sun::star::uno::Any& aSelection ) throw(lang::IllegalArgumentException, uno::RuntimeException)
145 : {
146 0 : if (!mpSlideSorterViewShell)
147 0 : return false;
148 :
149 0 : bool bOk = true;
150 :
151 : ::sd::slidesorter::controller::SlideSorterController& rSlideSorterController
152 0 : = mpSlideSorterViewShell->GetSlideSorter().GetController();
153 0 : ::sd::slidesorter::controller::PageSelector& rSelector (rSlideSorterController.GetPageSelector());
154 0 : rSelector.DeselectAllPages();
155 0 : Sequence<Reference<drawing::XDrawPage> > xPages;
156 0 : aSelection >>= xPages;
157 0 : const sal_uInt32 nCount = xPages.getLength();
158 0 : for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
159 : {
160 0 : Reference<beans::XPropertySet> xSet (xPages[nIndex], UNO_QUERY);
161 0 : if (xSet.is())
162 : {
163 : try
164 : {
165 0 : Any aNumber = xSet->getPropertyValue("Number");
166 0 : sal_Int32 nPageNumber = 0;
167 0 : aNumber >>= nPageNumber;
168 0 : nPageNumber -=1; // Transform 1-based page numbers to 0-based ones.
169 0 : rSelector.SelectPage(nPageNumber);
170 : }
171 0 : catch (const RuntimeException&)
172 : {
173 : }
174 : }
175 0 : }
176 :
177 0 : return bOk;
178 : }
179 :
180 0 : uno::Any SAL_CALL ViewShellWrapper::getSelection() throw(uno::RuntimeException)
181 : {
182 0 : Any aResult;
183 :
184 0 : if (!mpSlideSorterViewShell)
185 0 : return aResult;
186 :
187 : slidesorter::model::PageEnumeration aSelectedPages (
188 : slidesorter::model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
189 0 : mpSlideSorterViewShell->GetSlideSorter().GetModel()));
190 : int nSelectedPageCount (
191 0 : mpSlideSorterViewShell->GetSlideSorter().GetController().GetPageSelector().GetSelectedPageCount());
192 :
193 0 : Sequence<Reference<XInterface> > aPages(nSelectedPageCount);
194 0 : int nIndex = 0;
195 0 : while (aSelectedPages.HasMoreElements() && nIndex<nSelectedPageCount)
196 : {
197 0 : slidesorter::model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
198 0 : aPages[nIndex++] = pDescriptor->GetPage()->getUnoPage();
199 0 : }
200 0 : aResult <<= aPages;
201 :
202 0 : return aResult;
203 : }
204 :
205 0 : void SAL_CALL ViewShellWrapper::addSelectionChangeListener( const uno::Reference< view::XSelectionChangeListener >& ) throw(uno::RuntimeException)
206 : {
207 0 : }
208 :
209 0 : void SAL_CALL ViewShellWrapper::removeSelectionChangeListener( const uno::Reference< view::XSelectionChangeListener >& ) throw(uno::RuntimeException)
210 : {
211 0 : }
212 :
213 :
214 : //----- XRelocatableResource --------------------------------------------------
215 :
216 78 : sal_Bool SAL_CALL ViewShellWrapper::relocateToAnchor (
217 : const Reference<XResource>& xResource)
218 : throw (RuntimeException)
219 : {
220 78 : sal_Bool bResult (false);
221 :
222 78 : Reference<XPane> xPane (xResource, UNO_QUERY);
223 78 : if (xPane.is())
224 : {
225 : // Detach from the window of the old pane.
226 78 : Reference<awt::XWindow> xWindow (mxWindow);
227 78 : if (xWindow.is())
228 78 : xWindow->removeWindowListener(this);
229 78 : mxWindow = NULL;
230 :
231 78 : if (mpViewShell.get() != NULL)
232 : {
233 78 : ::Window* pWindow = VCLUnoHelper::GetWindow(xPane->getWindow());
234 78 : if (pWindow != NULL && mpViewShell->RelocateToParentWindow(pWindow))
235 : {
236 78 : bResult = sal_True;
237 :
238 : // Attach to the window of the new pane.
239 78 : xWindow = Reference<awt::XWindow>(xPane->getWindow(), UNO_QUERY);
240 78 : if (xWindow.is())
241 : {
242 78 : xWindow->addWindowListener(this);
243 78 : mpViewShell->Resize();
244 : }
245 : }
246 78 : }
247 : }
248 :
249 78 : return bResult;
250 : }
251 :
252 :
253 :
254 :
255 : //----- XUnoTunnel ------------------------------------------------------------
256 :
257 : namespace
258 : {
259 : class theViewShellWrapperUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theViewShellWrapperUnoTunnelId> {};
260 : }
261 :
262 6344 : const Sequence<sal_Int8>& ViewShellWrapper::getUnoTunnelId (void)
263 : {
264 6344 : return theViewShellWrapperUnoTunnelId::get().getSeq();
265 : }
266 :
267 :
268 :
269 :
270 3172 : sal_Int64 SAL_CALL ViewShellWrapper::getSomething (const Sequence<sal_Int8>& rId)
271 : throw (RuntimeException)
272 : {
273 3172 : sal_Int64 nResult = 0;
274 :
275 6344 : if (rId.getLength() == 16
276 3172 : && memcmp(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
277 : {
278 3172 : nResult = reinterpret_cast<sal_Int64>(this);
279 : }
280 :
281 3172 : return nResult;
282 : }
283 :
284 :
285 :
286 :
287 : //===== awt::XWindowListener ==================================================
288 :
289 231 : void SAL_CALL ViewShellWrapper::windowResized (const awt::WindowEvent& rEvent)
290 : throw (RuntimeException)
291 : {
292 : (void)rEvent;
293 231 : ViewShell* pViewShell (mpViewShell.get());
294 231 : if (pViewShell != NULL)
295 231 : pViewShell->Resize();
296 231 : }
297 :
298 :
299 :
300 :
301 242 : void SAL_CALL ViewShellWrapper::windowMoved (const awt::WindowEvent& rEvent)
302 : throw (RuntimeException)
303 : {
304 : (void)rEvent;
305 242 : }
306 :
307 :
308 :
309 :
310 125 : void SAL_CALL ViewShellWrapper::windowShown (const lang::EventObject& rEvent)
311 : throw (RuntimeException)
312 : {
313 : (void)rEvent;
314 125 : ViewShell* pViewShell (mpViewShell.get());
315 125 : if (pViewShell != NULL)
316 125 : pViewShell->Resize();
317 125 : }
318 :
319 :
320 :
321 :
322 0 : void SAL_CALL ViewShellWrapper::windowHidden (const lang::EventObject& rEvent)
323 : throw (RuntimeException)
324 : {
325 : (void)rEvent;
326 0 : }
327 :
328 :
329 :
330 :
331 : //===== XEventListener ========================================================
332 :
333 78 : void SAL_CALL ViewShellWrapper::disposing (const lang::EventObject& rEvent)
334 : throw (RuntimeException)
335 : {
336 78 : if (rEvent.Source == mxWindow)
337 0 : mxWindow = NULL;
338 78 : }
339 :
340 :
341 33 : } } // end of namespace sd::framework
342 :
343 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|