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>
22 #include <ViewShell.hxx>
24 #include <SlideSorter.hxx>
25 #include <SlideSorterViewShell.hxx>
26 #include <controller/SlsPageSelector.hxx>
27 #include <controller/SlideSorterController.hxx>
28 #include <model/SlsPageEnumerationProvider.hxx>
29 #include <model/SlsPageDescriptor.hxx>
31 #include <com/sun/star/drawing/framework/XPane.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <toolkit/helper/vclunohelper.hxx>
35 #include <comphelper/servicehelper.hxx>
36 #include <sal/log.hxx>
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::drawing::framework
;
42 using ::com::sun::star::awt::XWindow
;
44 namespace sd::framework
{
46 ViewShellWrapper::ViewShellWrapper (
47 const std::shared_ptr
<ViewShell
>& pViewShell
,
48 const Reference
<XResourceId
>& rxViewId
,
49 const Reference
<awt::XWindow
>& rxWindow
)
50 : mpViewShell(pViewShell
),
51 mpSlideSorterViewShell(
52 std::dynamic_pointer_cast
< ::sd::slidesorter::SlideSorterViewShell
>( pViewShell
)),
58 ViewShellWrapper::~ViewShellWrapper()
62 void ViewShellWrapper::disposing(std::unique_lock
<std::mutex
>&)
64 SAL_INFO("sd.ui", "disposing ViewShellWrapper " << this);
65 Reference
<awt::XWindow
> xWindow (mxWindow
);
70 "removing ViewShellWrapper " << this << " from window listener at "
72 xWindow
->removeWindowListener(this);
75 mpSlideSorterViewShell
.reset();
79 uno::Any SAL_CALL
ViewShellWrapper::queryInterface( const uno::Type
& rType
)
81 if( mpSlideSorterViewShell
&&
82 rType
== cppu::UnoType
<view::XSelectionSupplier
>::get() )
84 uno::Reference
<view::XSelectionSupplier
> xSupplier( this );
85 return Any(xSupplier
);
88 return ViewShellWrapperInterfaceBase::queryInterface( rType
);
91 //----- XResource -------------------------------------------------------------
93 Reference
<XResourceId
> SAL_CALL
ViewShellWrapper::getResourceId()
98 sal_Bool SAL_CALL
ViewShellWrapper::isAnchorOnly()
103 //----- XSelectionSupplier --------------------------------------------------
105 sal_Bool SAL_CALL
ViewShellWrapper::select( const css::uno::Any
& aSelection
)
107 if (!mpSlideSorterViewShell
)
110 ::sd::slidesorter::controller::SlideSorterController
& rSlideSorterController
111 = mpSlideSorterViewShell
->GetSlideSorter().GetController();
112 ::sd::slidesorter::controller::PageSelector
& rSelector (rSlideSorterController
.GetPageSelector());
113 rSelector
.DeselectAllPages();
114 Sequence
<Reference
<drawing::XDrawPage
> > xPages
;
115 aSelection
>>= xPages
;
116 for (const auto& rPage
: xPages
)
118 Reference
<beans::XPropertySet
> xSet (rPage
, UNO_QUERY
);
123 Any aNumber
= xSet
->getPropertyValue(u
"Number"_ustr
);
124 sal_Int32 nPageNumber
= 0;
125 aNumber
>>= nPageNumber
;
126 nPageNumber
-=1; // Transform 1-based page numbers to 0-based ones.
127 rSelector
.SelectPage(nPageNumber
);
129 catch (const RuntimeException
&)
138 uno::Any SAL_CALL
ViewShellWrapper::getSelection()
142 if (!mpSlideSorterViewShell
)
145 slidesorter::model::PageEnumeration
aSelectedPages (
146 slidesorter::model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
147 mpSlideSorterViewShell
->GetSlideSorter().GetModel()));
148 int nSelectedPageCount (
149 mpSlideSorterViewShell
->GetSlideSorter().GetController().GetPageSelector().GetSelectedPageCount());
151 Sequence
<Reference
<XInterface
> > aPages(nSelectedPageCount
);
152 auto aPagesRange
= asNonConstRange(aPages
);
154 while (aSelectedPages
.HasMoreElements() && nIndex
<nSelectedPageCount
)
156 slidesorter::model::SharedPageDescriptor
pDescriptor (aSelectedPages
.GetNextElement());
157 aPagesRange
[nIndex
++] = pDescriptor
->GetPage()->getUnoPage();
164 void SAL_CALL
ViewShellWrapper::addSelectionChangeListener( const uno::Reference
< view::XSelectionChangeListener
>& )
168 void SAL_CALL
ViewShellWrapper::removeSelectionChangeListener( const uno::Reference
< view::XSelectionChangeListener
>& )
172 //----- XRelocatableResource --------------------------------------------------
174 sal_Bool SAL_CALL
ViewShellWrapper::relocateToAnchor (
175 const Reference
<XResource
>& xResource
)
177 bool bResult (false);
179 Reference
<XPane
> xPane (xResource
, UNO_QUERY
);
182 // Detach from the window of the old pane.
183 Reference
<awt::XWindow
> xWindow (mxWindow
);
185 xWindow
->removeWindowListener(this);
188 if (mpViewShell
!= nullptr)
190 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow(xPane
->getWindow());
191 if (pWindow
&& mpViewShell
->RelocateToParentWindow(pWindow
))
195 // Attach to the window of the new pane.
196 xWindow
= xPane
->getWindow();
199 xWindow
->addWindowListener(this);
200 mpViewShell
->Resize();
209 //===== awt::XWindowListener ==================================================
211 void SAL_CALL
ViewShellWrapper::windowResized (const awt::WindowEvent
&)
213 ViewShell
* pViewShell (mpViewShell
.get());
214 if (pViewShell
!= nullptr)
215 pViewShell
->Resize();
218 void SAL_CALL
ViewShellWrapper::windowMoved (const awt::WindowEvent
&) {}
220 void SAL_CALL
ViewShellWrapper::windowShown (const lang::EventObject
&)
222 ViewShell
* pViewShell (mpViewShell
.get());
223 if (pViewShell
!= nullptr)
224 pViewShell
->Resize();
227 void SAL_CALL
ViewShellWrapper::windowHidden (const lang::EventObject
&) {}
229 //===== XEventListener ========================================================
231 void SAL_CALL
ViewShellWrapper::disposing (const lang::EventObject
& rEvent
)
233 if (rEvent
.Source
== mxWindow
)
237 } // end of namespace sd::framework
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */