LibreOffice Module sd (master) 1
SdUnoDrawView.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
20#include <SdUnoDrawView.hxx>
21
22#include <DrawController.hxx>
23#include <DrawDocShell.hxx>
24#include <DrawViewShell.hxx>
25#include <drawdoc.hxx>
26#include "unolayer.hxx"
27#include <unomodel.hxx>
28#include <Window.hxx>
29#include <pres.hxx>
30
33#include <sfx2/dispatch.hxx>
34#include <sfx2/viewfrm.hxx>
35#include <svx/svdpagv.hxx>
36#include <svx/unopage.hxx>
37#include <sfx2/zoomitem.hxx>
38#include <com/sun/star/drawing/DrawViewMode.hpp>
39#include <com/sun/star/drawing/ShapeCollection.hpp>
40#include <com/sun/star/drawing/XLayerManager.hpp>
41#include <com/sun/star/view/DocumentZoomType.hpp>
42
43#include <vector>
44
45using namespace ::com::sun::star;
46using namespace ::com::sun::star::uno;
47using namespace ::com::sun::star::drawing;
48
49namespace sd {
50
52 DrawViewShell& rViewShell,
53 View& rView) noexcept
54 : mrDrawViewShell(rViewShell),
55 mrView(rView)
56{
57}
58
60{
61}
62
64{
66}
67
68void SdUnoDrawView::setMasterPageMode (bool bMasterPageMode) noexcept
69{
70 if ((mrDrawViewShell.GetEditMode() == EditMode::MasterPage) != bMasterPageMode)
71 {
72 mrDrawViewShell.ChangeEditMode (
73 bMasterPageMode ? EditMode::MasterPage : EditMode::Page,
74 mrDrawViewShell.IsLayerModeActive());
75 }
76}
77
78bool SdUnoDrawView::getLayerMode() const noexcept
79{
81}
82
83void SdUnoDrawView::setLayerMode (bool bLayerMode) noexcept
84{
85 if (mrDrawViewShell.IsLayerModeActive() != bLayerMode)
86 {
87 mrDrawViewShell.ChangeEditMode (
88 mrDrawViewShell.GetEditMode(),
89 bLayerMode);
90 }
91}
92
93Reference<drawing::XLayer> SdUnoDrawView::getActiveLayer() const
94{
95 Reference<drawing::XLayer> xCurrentLayer;
96
97 do
98 {
99 // Retrieve the layer manager from the model.
100 SdXImpressDocument* pModel = GetModel();
101 if (pModel == nullptr)
102 break;
103
104 SdDrawDocument* pSdModel = pModel->GetDoc();
105 if (pSdModel == nullptr)
106 break;
107
108 // From the model get the current SdrLayer object via the layer admin.
109 SdrLayerAdmin& rLayerAdmin = pSdModel->GetLayerAdmin ();
110 SdrLayer* pLayer = rLayerAdmin.GetLayer (mrView.GetActiveLayer());
111 if (pLayer == nullptr)
112 break;
113
114 // Get the corresponding XLayer object from the implementation
115 // object of the layer manager.
116 Reference<drawing::XLayerManager> xManager (pModel->getLayerManager(), uno::UNO_QUERY);
117 SdLayerManager* pManager = dynamic_cast<SdLayerManager*> (xManager.get());
118 if (pManager != nullptr)
119 xCurrentLayer = pManager->GetLayer (pLayer);
120 }
121 while (false);
122
123 return xCurrentLayer;
124}
125
126void SdUnoDrawView::setActiveLayer (const Reference<drawing::XLayer>& rxLayer)
127{
128 // Get the SdrLayer object corresponding to the given reference.
129 if ( ! rxLayer.is())
130 return;
131
132 SdLayer* pLayer = dynamic_cast<SdLayer*> (rxLayer.get());
133 if (pLayer == nullptr)
134 return;
135
136 SdrLayer* pSdrLayer = pLayer->GetSdrLayer();
137 if (pSdrLayer == nullptr)
138 return;
139
140 // Set the new active layer and make the change visible.
141 mrView.SetActiveLayer (pSdrLayer->GetName());
143}
144
145// XSelectionSupplier
146
147sal_Bool SAL_CALL SdUnoDrawView::select( const Any& aSelection )
148{
149 bool bOk = true;
150
151 ::std::vector<SdrObject*> aObjects;
152
153 SdrPage* pSdrPage = nullptr;
154
155 Reference< drawing::XShape > xShape;
156 aSelection >>= xShape;
157
158 if(xShape.is())
159 {
161 if( pObj )
162 {
163 pSdrPage = pObj->getSdrPageFromSdrObject();
164 aObjects.push_back( pObj );
165 }
166 else
167 {
168 bOk = false;
169 }
170 }
171 else
172 {
173 Reference< drawing::XShapes > xShapes;
174 aSelection >>= xShapes;
175 if( xShapes.is() )
176 {
177 const sal_uInt32 nCount = xShapes->getCount();
178 for( sal_uInt32 i = 0; i < nCount; i++ )
179 {
180 xShapes->getByIndex(i) >>= xShape;
181 if( xShape.is() )
182 {
184 if( !pObj )
185 {
186 bOk = false;
187 break;
188 }
189
190 if( pSdrPage == nullptr )
191 {
192 pSdrPage = pObj->getSdrPageFromSdrObject();
193 }
194 else if( pSdrPage != pObj->getSdrPageFromSdrObject() )
195 {
196 bOk = false;
197 break;
198 }
199
200 aObjects.push_back( pObj );
201 }
202 }
203 }
204 }
205
206 if( bOk )
207 {
208 if( pSdrPage )
209 {
210 setMasterPageMode( pSdrPage->IsMasterPage() );
211 mrDrawViewShell.SwitchPage( (pSdrPage->GetPageNum() - 1) >> 1 );
213 }
214
216
217 if(pPV)
218 {
219 // first deselect all
220 mrView.UnmarkAllObj( pPV );
221
222 for( SdrObject* pObj : aObjects )
223 {
224 mrView.MarkObj( pObj, pPV );
225 }
226 }
227 else
228 {
229 bOk = false;
230 }
231 }
232
233 return bOk;
234}
235
237{
238 Any aAny;
239
240 if( mrView.IsTextEdit() )
241 mrView.getTextSelection( aAny );
242
243 if( !aAny.hasValue() )
244 {
245 const SdrMarkList& rMarkList = mrView.GetMarkedObjectList();
246 const size_t nCount = rMarkList.GetMarkCount();
247 if( nCount )
248 {
249 Reference< drawing::XShapes > xShapes = drawing::ShapeCollection::create(
251 for( size_t nNum = 0; nNum < nCount; ++nNum)
252 {
253 SdrMark *pMark = rMarkList.GetMark(nNum);
254 if(pMark==nullptr)
255 continue;
256
257 SdrObject *pObj = pMark->GetMarkedSdrObj();
258 if(pObj==nullptr || pObj->getSdrPageFromSdrObject() == nullptr)
259 continue;
260
261 Reference< drawing::XDrawPage > xPage( pObj->getSdrPageFromSdrObject()->getUnoPage(), UNO_QUERY);
262
263 if(!xPage.is())
264 continue;
265
266 SvxDrawPage* pDrawPage = comphelper::getFromUnoTunnel<SvxDrawPage>( xPage );
267
268 if(pDrawPage==nullptr)
269 continue;
270
271 Reference< drawing::XShape > xShape( pObj->getUnoShape(), UNO_QUERY );
272
273 if(xShape.is())
274 xShapes->add(xShape);
275 }
276 aAny <<= xShapes;
277 }
278 }
279
280 return aAny;
281}
282
284 const css::uno::Reference<css::view::XSelectionChangeListener>&)
285{}
286
288 const css::uno::Reference<css::view::XSelectionChangeListener>&)
289{}
290
292 sal_Int32 nHandle,
293 const Any& rValue)
294{
295 switch( nHandle )
296 {
298 {
299 Reference< drawing::XDrawPage > xPage;
300 rValue >>= xPage;
301 setCurrentPage( xPage );
302 }
303 break;
304
306 {
307 bool bValue = false;
308 rValue >>= bValue;
309 setMasterPageMode( bValue );
310 }
311 break;
312
314 {
315 bool bValue = false;
316 rValue >>= bValue;
317 setLayerMode( bValue );
318 }
319 break;
321 {
322 Reference<drawing::XLayer> xLayer;
323 rValue >>= xLayer;
324 setActiveLayer (xLayer);
325 }
326 break;
328 {
329 sal_Int16 nZoom = 0;
330 rValue >>= nZoom;
331 SetZoom( nZoom );
332 }
333 break;
335 {
336 sal_Int16 nType = 0;
337 rValue >>= nType;
339 }
340 break;
342 {
343 awt::Point aOffset;
344 rValue >>= aOffset;
345 SetViewOffset( aOffset );
346 }
347 break;
348 default:
349 throw beans::UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
350 }
351}
352
354 sal_Int32 nHandle)
355{
356 Any aValue;
357 switch( nHandle )
358 {
360 aValue <<= getCurrentPage();
361 break;
362
364 aValue <<= getMasterPageMode();
365 break;
366
368 aValue <<= getLayerMode();
369 break;
370
372 aValue <<= getActiveLayer();
373 break;
374
376 aValue <<= GetZoom();
377 break;
379 aValue <<= sal_Int16(css::view::DocumentZoomType::BY_VALUE);
380 break;
382 aValue <<= GetViewOffset();
383 break;
384
386 aValue = getDrawViewMode();
387 break;
388
389 default:
390 throw beans::UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
391 }
392
393 return aValue;
394}
395
396// XDrawView
397
399 const Reference< drawing::XDrawPage >& xPage )
400{
401 SvxDrawPage* pDrawPage = comphelper::getFromUnoTunnel<SvxDrawPage>( xPage );
402 SdrPage *pSdrPage = pDrawPage ? pDrawPage->GetSdrPage() : nullptr;
403
404 if(pSdrPage)
405 {
406 // End editing of text. Otherwise the edited text object would
407 // still be visible on the new page.
409
410 setMasterPageMode( pSdrPage->IsMasterPage() );
411 mrDrawViewShell.SwitchPage( (pSdrPage->GetPageNum() - 1) >> 1 );
413 }
414}
415
416Reference< drawing::XDrawPage > SAL_CALL SdUnoDrawView::getCurrentPage()
417{
418 Reference< drawing::XDrawPage > xPage;
419
421 SdrPage* pPage = pPV ? pPV->GetPage() : nullptr;
422
423 if(pPage)
424 xPage.set( pPage->getUnoPage(), UNO_QUERY );
425
426 return xPage;
427}
428
429sal_Int16 SdUnoDrawView::GetZoom() const
430{
432 {
433 return static_cast<sal_Int16>(mrDrawViewShell.GetActiveWindow()->GetZoom());
434 }
435 else
436 {
437 return 0;
438 }
439}
440
441void SdUnoDrawView::SetZoom( sal_Int16 nZoom )
442{
443 SvxZoomItem aZoomItem( SvxZoomType::PERCENT, nZoom );
444
446 if( pViewFrame )
447 {
448 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
449 if( pDispatcher )
450 {
451 pDispatcher->ExecuteList(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON,
452 { &aZoomItem });
453 }
454 }
455}
456
457void SdUnoDrawView::SetViewOffset(const awt::Point& rWinPos )
458{
459 Point aWinPos( rWinPos.X, rWinPos.Y );
460 aWinPos += mrDrawViewShell.GetViewOrigin();
462}
463
465{
468
469 return awt::Point( aRet.X(), aRet.Y() );
470}
471
472void SdUnoDrawView::SetZoomType ( sal_Int16 nType )
473{
475 if( !pViewFrame )
476 return;
477
478 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
479 if( !pDispatcher )
480 return;
481
482 SvxZoomType eZoomType;
483 switch( nType )
484 {
485 case css::view::DocumentZoomType::OPTIMAL:
486 eZoomType = SvxZoomType::OPTIMAL;
487 break;
488
489 case css::view::DocumentZoomType::PAGE_WIDTH:
490 case css::view::DocumentZoomType::PAGE_WIDTH_EXACT:
491 eZoomType = SvxZoomType::PAGEWIDTH;
492 break;
493
494 case css::view::DocumentZoomType::ENTIRE_PAGE:
495 eZoomType = SvxZoomType::WHOLEPAGE;
496 break;
497
498 default:
499 return;
500 }
501 SvxZoomItem aZoomItem( eZoomType );
502 pDispatcher->ExecuteList(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON,
503 { &aZoomItem });
504}
505
507{
508 if (mrView.GetDocSh()!=nullptr)
509 {
510 Reference<frame::XModel> xModel (mrView.GetDocSh()->GetModel());
511 return comphelper::getFromUnoTunnel<SdXImpressDocument>(xModel);
512 }
513 else
514 return nullptr;
515}
516
518{
519 Any aRet;
520 switch( mrDrawViewShell.GetPageKind() )
521 {
522 case PageKind::Notes: aRet <<= DrawViewMode_NOTES; break;
523 case PageKind::Handout: aRet <<= DrawViewMode_HANDOUT; break;
524 case PageKind::Standard: aRet <<= DrawViewMode_DRAW; break;
525 }
526 return aRet;
527}
528
529// XServiceInfo
531{
532 return "com.sun.star.comp.sd.SdUnoDrawView" ;
533}
534
535sal_Bool SAL_CALL SdUnoDrawView::supportsService( const OUString& ServiceName )
536{
537 return cppu::supportsService( this, ServiceName );
538}
539
540Sequence< OUString > SAL_CALL SdUnoDrawView::getSupportedServiceNames( )
541{
542 return { "com.sun.star.drawing.DrawingDocumentDrawView" };
543}
544
545} // end of namespace sd
546
547/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SlideSorterView & mrView
constexpr tools::Long Y() const
constexpr tools::Long X() const
css::uno::Reference< css::drawing::XLayer > GetLayer(SdrLayer *pLayer)
Return the <type>XLayer</type> object that is associated with the given <type>SdrLayer</type> object.
Definition: unolayer.cxx:680
SdrLayer * GetSdrLayer() const noexcept
Definition: unolayer.hxx:52
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getLayerManager() override
Definition: unomodel.cxx:765
SdDrawDocument * GetDoc() const
Definition: unomodel.hxx:141
SdrLayer * GetLayer(sal_uInt16 i)
const OUString & GetName() const
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
void UnmarkAllObj(SdrPageView const *pPV=nullptr)
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
SdrObject * GetMarkedSdrObj() const
const SdrLayerAdmin & GetLayerAdmin() const
void getTextSelection(css::uno::Any &rSelection)
virtual bool IsTextEdit() const final override
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
virtual css::uno::Reference< css::drawing::XShape > getUnoShape()
SdrPage * getSdrPageFromSdrObject() const
SdrPage * GetPage() const
css::uno::Reference< css::uno::XInterface > const & getUnoPage()
sal_uInt16 GetPageNum() const
bool IsMasterPage() const
void SetActiveLayer(const OUString &rName)
SdrPageView * GetSdrPageView() const
const OUString & GetActiveLayer() const
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
css::uno::Reference< css::frame::XModel3 > GetModel() const
SfxDispatcher * GetDispatcher()
SdrPage * GetSdrPage() const
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
EditMode GetEditMode() const
bool IsLayerModeActive() const
virtual void WriteFrameViewData() override
Apply data of the current view on the FrameView.
Definition: drviews5.cxx:311
bool SwitchPage(sal_uInt16 nPage, bool bAllowChangeFocus=true)
Switch to desired page.
Definition: drviews1.cxx:831
PageKind GetPageKind() const
void ResetActualLayer()
Select new refreshed page, in case of a page order change (eg.
Definition: drviews1.cxx:1211
DrawViewShell & mrDrawViewShell
css::uno::Any getDrawViewMode() const
virtual sal_Bool SAL_CALL select(const css::uno::Any &aSelection) override
virtual void SAL_CALL removeSelectionChangeListener(const css::uno::Reference< css::view::XSelectionChangeListener > &rxListener) override
SdXImpressDocument * GetModel() const noexcept
virtual ~SdUnoDrawView() noexcept override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void SetZoom(sal_Int16 nZoom)
sal_Int16 GetZoom() const
virtual css::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) override
bool getLayerMode() const noexcept
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::drawing::XDrawPage > SAL_CALL getCurrentPage() override
void setLayerMode(bool LayerMode_) noexcept
virtual void SAL_CALL setFastPropertyValue(sal_Int32 nHandle, const css::uno::Any &rValue) override
void SetViewOffset(const css::awt::Point &rWinPos)
void setMasterPageMode(bool MasterPageMode_) noexcept
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Any SAL_CALL getSelection() override
void SetZoomType(sal_Int16 nType)
SdUnoDrawView(DrawViewShell &rViewShell, View &rView) noexcept
css::awt::Point GetViewOffset() const
virtual void SAL_CALL addSelectionChangeListener(const css::uno::Reference< css::view::XSelectionChangeListener > &rxListener) override
virtual void SAL_CALL setCurrentPage(const css::uno::Reference< css::drawing::XDrawPage > &xPage) override
css::uno::Reference< css::drawing::XLayer > getActiveLayer() const
Return a reference to the active layer object.
void setActiveLayer(const css::uno::Reference< css::drawing::XLayer > &rxLayer)
Make the specified object the active layer.
bool getMasterPageMode() const noexcept
Point const & GetViewOrigin() const
Definition: viewshe2.cxx:942
void SetWinViewPos(const Point &rWinPos)
Definition: viewshe2.cxx:908
::sd::Window * GetActiveWindow() const
The active window is usually the mpContentWindow.
Definition: ViewShell.hxx:155
::sd::View * GetView() const
Definition: ViewShell.hxx:144
Point const & GetWinViewPos() const
Definition: viewshe2.cxx:937
SD_DLLPUBLIC SfxViewFrame * GetViewFrame() const
Definition: viewshel.cxx:118
DrawDocShell * GetDocSh() const
Definition: View.hxx:142
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false) override
ends current text editing
Definition: sdview.cxx:772
::tools::Long GetZoom() const
Definition: sdwindow.cxx:183
int nCount
Reference< XComponentContext > getProcessComponentContext()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
QPRO_FUNC_TYPE nType
sal_Int32 nHandle
Reference< XModel > xModel
unsigned char sal_Bool
SvxZoomType