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