1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
23 #include "ViewShell.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
)),
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
);
84 "removing ViewShellWrapper " << this << " from window listener at "
86 xWindow
->removeWindowListener(this);
89 mpSlideSorterViewShell
.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() )
99 uno::Reference
<view::XSelectionSupplier
> xSupplier( this );
105 return ViewShellWrapperInterfaceBase::queryInterface( rType
);
108 //----- XResource -------------------------------------------------------------
110 Reference
<XResourceId
> SAL_CALL
ViewShellWrapper::getResourceId()
111 throw (RuntimeException
, std::exception
)
116 sal_Bool SAL_CALL
ViewShellWrapper::isAnchorOnly()
117 throw (RuntimeException
, std::exception
)
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
)
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
);
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
&)
160 uno::Any SAL_CALL
ViewShellWrapper::getSelection()
161 throw (uno::RuntimeException
, std::exception
)
165 if (!mpSlideSorterViewShell
)
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
);
176 while (aSelectedPages
.HasMoreElements() && nIndex
<nSelectedPageCount
)
178 slidesorter::model::SharedPageDescriptor
pDescriptor (aSelectedPages
.GetNextElement());
179 aPages
[nIndex
++] = pDescriptor
->GetPage()->getUnoPage();
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
);
205 // Detach from the window of the old pane.
206 Reference
<awt::XWindow
> xWindow (mxWindow
);
208 xWindow
->removeWindowListener(this);
211 if (mpViewShell
.get() != NULL
)
213 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow(xPane
->getWindow());
214 if (pWindow
!= NULL
&& mpViewShell
->RelocateToParentWindow(pWindow
))
218 // Attach to the window of the new pane.
219 xWindow
= Reference
<awt::XWindow
>(xPane
->getWindow(), UNO_QUERY
);
222 xWindow
->addWindowListener(this);
223 mpViewShell
->Resize();
232 //----- XUnoTunnel ------------------------------------------------------------
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);
258 //===== awt::XWindowListener ==================================================
260 void SAL_CALL
ViewShellWrapper::windowResized (const awt::WindowEvent
& rEvent
)
261 throw (RuntimeException
, std::exception
)
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
)
275 void SAL_CALL
ViewShellWrapper::windowShown (const lang::EventObject
& rEvent
)
276 throw (RuntimeException
, std::exception
)
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
)
290 //===== XEventListener ========================================================
292 void SAL_CALL
ViewShellWrapper::disposing (const lang::EventObject
& rEvent
)
293 throw (RuntimeException
, std::exception
)
295 if (rEvent
.Source
== mxWindow
)
299 } } // end of namespace sd::framework
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */