LibreOffice Module sd (master) 1
ViewShellWrapper.cxx
Go to the documentation of this file.
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
21#include <sdpage.hxx>
22#include <ViewShell.hxx>
23
24#include <SlideSorter.hxx>
30
31#include <com/sun/star/drawing/framework/XPane.hpp>
32#include <com/sun/star/beans/XPropertySet.hpp>
33
36#include <sal/log.hxx>
37
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::uno;
41
42using ::com::sun::star::awt::XWindow;
43
44namespace sd::framework {
45
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 )),
53 mxViewId(rxViewId),
54 mxWindow(rxWindow)
55{
56}
57
59{
60}
61
62void ViewShellWrapper::disposing(std::unique_lock<std::mutex>&)
63{
64 SAL_INFO("sd.ui", "disposing ViewShellWrapper " << this);
65 Reference<awt::XWindow> xWindow (mxWindow);
66 if (xWindow.is())
67 {
69 "sd.ui",
70 "removing ViewShellWrapper " << this << " from window listener at "
71 << mxWindow.get());
72 xWindow->removeWindowListener(this);
73 }
74
76 mpViewShell.reset();
77}
78
80{
83 {
84 uno::Reference<view::XSelectionSupplier> xSupplier( this );
85 return Any(xSupplier);
86 }
87 else
89}
90
91//----- XResource -------------------------------------------------------------
92
93Reference<XResourceId> SAL_CALL ViewShellWrapper::getResourceId()
94{
95 return mxViewId;
96}
97
99{
100 return false;
101}
102
103//----- XSelectionSupplier --------------------------------------------------
104
105sal_Bool SAL_CALL ViewShellWrapper::select( const css::uno::Any& aSelection )
106{
108 return false;
109
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 : std::as_const(xPages))
117 {
118 Reference<beans::XPropertySet> xSet (rPage, UNO_QUERY);
119 if (xSet.is())
120 {
121 try
122 {
123 Any aNumber = xSet->getPropertyValue("Number");
124 sal_Int32 nPageNumber = 0;
125 aNumber >>= nPageNumber;
126 nPageNumber -=1; // Transform 1-based page numbers to 0-based ones.
127 rSelector.SelectPage(nPageNumber);
128 }
129 catch (const RuntimeException&)
130 {
131 }
132 }
133 }
134
135 return true;
136}
137
139{
140 Any aResult;
141
143 return aResult;
144
147 mpSlideSorterViewShell->GetSlideSorter().GetModel()));
148 int nSelectedPageCount (
149 mpSlideSorterViewShell->GetSlideSorter().GetController().GetPageSelector().GetSelectedPageCount());
150
151 Sequence<Reference<XInterface> > aPages(nSelectedPageCount);
152 auto aPagesRange = asNonConstRange(aPages);
153 int nIndex = 0;
154 while (aSelectedPages.HasMoreElements() && nIndex<nSelectedPageCount)
155 {
156 slidesorter::model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
157 aPagesRange[nIndex++] = pDescriptor->GetPage()->getUnoPage();
158 }
159 aResult <<= aPages;
160
161 return aResult;
162}
163
164void SAL_CALL ViewShellWrapper::addSelectionChangeListener( const uno::Reference< view::XSelectionChangeListener >& )
165{
166}
167
168void SAL_CALL ViewShellWrapper::removeSelectionChangeListener( const uno::Reference< view::XSelectionChangeListener >& )
169{
170}
171
172//----- XRelocatableResource --------------------------------------------------
173
175 const Reference<XResource>& xResource)
176{
177 bool bResult (false);
178
179 Reference<XPane> xPane (xResource, UNO_QUERY);
180 if (xPane.is())
181 {
182 // Detach from the window of the old pane.
183 Reference<awt::XWindow> xWindow (mxWindow);
184 if (xWindow.is())
185 xWindow->removeWindowListener(this);
186 mxWindow = nullptr;
187
188 if (mpViewShell != nullptr)
189 {
190 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xPane->getWindow());
191 if (pWindow && mpViewShell->RelocateToParentWindow(pWindow))
192 {
193 bResult = true;
194
195 // Attach to the window of the new pane.
196 xWindow = xPane->getWindow();
197 if (xWindow.is())
198 {
199 xWindow->addWindowListener(this);
200 mpViewShell->Resize();
201 }
202 }
203 }
204 }
205
206 return bResult;
207}
208
209//===== awt::XWindowListener ==================================================
210
211void SAL_CALL ViewShellWrapper::windowResized (const awt::WindowEvent&)
212{
213 ViewShell* pViewShell (mpViewShell.get());
214 if (pViewShell != nullptr)
215 pViewShell->Resize();
216}
217
218void SAL_CALL ViewShellWrapper::windowMoved (const awt::WindowEvent&) {}
219
220void SAL_CALL ViewShellWrapper::windowShown (const lang::EventObject&)
221{
222 ViewShell* pViewShell (mpViewShell.get());
223 if (pViewShell != nullptr)
224 pViewShell->Resize();
225}
226
227void SAL_CALL ViewShellWrapper::windowHidden (const lang::EventObject&) {}
228
229//===== XEventListener ========================================================
230
231void SAL_CALL ViewShellWrapper::disposing (const lang::EventObject& rEvent)
232{
233 if (rEvent.Source == mxWindow)
234 mxWindow = nullptr;
235}
236
237} // end of namespace sd::framework
238
239/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
virtual void Resize()
Notify the view shell that its parent window has been resized.
Definition: viewshel.cxx:908
virtual void SAL_CALL windowHidden(const css::lang::EventObject &rEvent) override
virtual void SAL_CALL removeSelectionChangeListener(const css::uno::Reference< css::view::XSelectionChangeListener > &xListener) override
::std::shared_ptr< ::sd::slidesorter::SlideSorterViewShell > mpSlideSorterViewShell
virtual void SAL_CALL windowShown(const css::lang::EventObject &rEvent) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL addSelectionChangeListener(const css::uno::Reference< css::view::XSelectionChangeListener > &xListener) override
virtual sal_Bool SAL_CALL isAnchorOnly() override
ViewShellWrapper(const ::std::shared_ptr< ViewShell > &pViewShell, const css::uno::Reference< css::drawing::framework::XResourceId > &rxViewId, const css::uno::Reference< css::awt::XWindow > &rxWindow)
Create a new ViewShellWrapper object that wraps the given ViewShell object.
virtual css::uno::Any SAL_CALL getSelection() override
virtual void disposing(std::unique_lock< std::mutex > &) override
css::uno::Reference< css::awt::XWindow > mxWindow
::std::shared_ptr< ViewShell > mpViewShell
const css::uno::Reference< css::drawing::framework::XResourceId > mxViewId
virtual sal_Bool SAL_CALL relocateToAnchor(const css::uno::Reference< css::drawing::framework::XResource > &xResource) override
virtual void SAL_CALL windowResized(const css::awt::WindowEvent &rEvent) override
virtual void SAL_CALL windowMoved(const css::awt::WindowEvent &rEvent) override
virtual sal_Bool SAL_CALL select(const css::uno::Any &aSelection) override
virtual css::uno::Reference< css::drawing::framework::XResourceId > SAL_CALL getResourceId() override
A sub-controller that handles page selection of the slide browser.
void SelectPage(int nPageIndex)
Select the specified descriptor.
static PageEnumeration CreateSelectedPagesEnumeration(const SlideSorterModel &rModel)
The returned enumeration of slides iterates over the currently selected slides of the given model.
Public class of page enumerations that delegates its calls to an implementation object that can filte...
virtual SharedPageDescriptor GetNextElement() override
Return the next element of the enumeration.
virtual bool HasMoreElements() const override
Return <TRUE> when the enumeration has more elements, i.e.
sal_Int32 nIndex
#define SAL_INFO(area, stream)
std::shared_ptr< PageDescriptor > SharedPageDescriptor
unsigned char sal_Bool