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 <SdUnoDrawView.hxx>
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 <unopage.hxx>
32 #include <comphelper/processfactory.hxx>
33 #include <cppuhelper/supportsservice.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <svx/unoshape.hxx>
38 #include <sfx2/zoomitem.hxx>
39 #include <com/sun/star/drawing/DrawViewMode.hpp>
40 #include <com/sun/star/drawing/ShapeCollection.hpp>
41 #include <com/sun/star/drawing/XLayerManager.hpp>
42 #include <com/sun/star/view/DocumentZoomType.hpp>
46 using namespace ::com::sun::star
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::drawing
;
52 SdUnoDrawView::SdUnoDrawView(
53 DrawViewShell
& rViewShell
,
55 : DrawSubControllerInterfaceBase(m_aMutex
),
56 mrDrawViewShell(rViewShell
),
61 SdUnoDrawView::~SdUnoDrawView() throw()
65 bool SdUnoDrawView::getMasterPageMode() const throw()
67 return (mrDrawViewShell
.GetEditMode() == EditMode::MasterPage
);
70 void SdUnoDrawView::setMasterPageMode (bool bMasterPageMode
) throw()
72 if ((mrDrawViewShell
.GetEditMode() == EditMode::MasterPage
) != bMasterPageMode
)
74 mrDrawViewShell
.ChangeEditMode (
75 bMasterPageMode
? EditMode::MasterPage
: EditMode::Page
,
76 mrDrawViewShell
.IsLayerModeActive());
80 bool SdUnoDrawView::getLayerMode() const throw()
82 return mrDrawViewShell
.IsLayerModeActive();
85 void SdUnoDrawView::setLayerMode (bool bLayerMode
) throw()
87 if (mrDrawViewShell
.IsLayerModeActive() != bLayerMode
)
89 mrDrawViewShell
.ChangeEditMode (
90 mrDrawViewShell
.GetEditMode(),
95 Reference
<drawing::XLayer
> SdUnoDrawView::getActiveLayer()
97 Reference
<drawing::XLayer
> xCurrentLayer
;
101 // Retrieve the layer manager from the model.
102 SdXImpressDocument
* pModel
= GetModel();
103 if (pModel
== nullptr)
106 SdDrawDocument
* pSdModel
= pModel
->GetDoc();
107 if (pSdModel
== nullptr)
110 // From the model get the current SdrLayer object via the layer admin.
111 SdrLayerAdmin
& rLayerAdmin
= pSdModel
->GetLayerAdmin ();
112 SdrLayer
* pLayer
= rLayerAdmin
.GetLayer (mrView
.GetActiveLayer());
113 if (pLayer
== nullptr)
116 // Get the corresponding XLayer object from the implementation
117 // object of the layer manager.
118 Reference
<drawing::XLayerManager
> xManager (pModel
->getLayerManager(), uno::UNO_QUERY
);
119 SdLayerManager
* pManager
= SdLayerManager::getImplementation (xManager
);
120 if (pManager
!= nullptr)
121 xCurrentLayer
= pManager
->GetLayer (pLayer
);
125 return xCurrentLayer
;
128 void SdUnoDrawView::setActiveLayer (const Reference
<drawing::XLayer
>& rxLayer
)
130 // Get the SdrLayer object corresponding to the given reference.
134 SdLayer
* pLayer
= SdLayer::getImplementation (rxLayer
);
135 if (pLayer
== nullptr)
138 SdrLayer
* pSdrLayer
= pLayer
->GetSdrLayer();
139 if (pSdrLayer
== nullptr)
142 // Set the new active layer and make the change visible.
143 mrView
.SetActiveLayer (pSdrLayer
->GetName());
144 mrDrawViewShell
.ResetActualLayer ();
147 // XSelectionSupplier
149 sal_Bool SAL_CALL
SdUnoDrawView::select( const Any
& aSelection
)
153 ::std::vector
<SdrObject
*> aObjects
;
155 SdrPage
* pSdrPage
= nullptr;
157 Reference
< drawing::XShape
> xShape
;
158 aSelection
>>= xShape
;
162 SvxShape
* pShape
= SvxShape::getImplementation( xShape
);
163 if( pShape
&& (pShape
->GetSdrObject() != nullptr) )
165 SdrObject
* pObj
= pShape
->GetSdrObject();
166 pSdrPage
= pObj
->getSdrPageFromSdrObject();
167 aObjects
.push_back( pObj
);
176 Reference
< drawing::XShapes
> xShapes
;
177 aSelection
>>= xShapes
;
180 const sal_uInt32 nCount
= xShapes
->getCount();
181 for( sal_uInt32 i
= 0; i
< nCount
; i
++ )
183 xShapes
->getByIndex(i
) >>= xShape
;
186 SvxShape
* pShape
= SvxShape::getImplementation(xShape
);
187 if( (pShape
== nullptr) || (pShape
->GetSdrObject() == nullptr) )
193 SdrObject
* pObj
= pShape
->GetSdrObject();
195 if( pSdrPage
== nullptr )
197 pSdrPage
= pObj
->getSdrPageFromSdrObject();
199 else if( pSdrPage
!= pObj
->getSdrPageFromSdrObject() )
205 aObjects
.push_back( pObj
);
215 setMasterPageMode( pSdrPage
->IsMasterPage() );
216 mrDrawViewShell
.SwitchPage( (pSdrPage
->GetPageNum() - 1) >> 1 );
217 mrDrawViewShell
.WriteFrameViewData();
220 SdrPageView
*pPV
= mrView
.GetSdrPageView();
224 // first deselect all
225 mrView
.UnmarkAllObj( pPV
);
227 for( SdrObject
* pObj
: aObjects
)
229 mrView
.MarkObj( pObj
, pPV
);
241 Any SAL_CALL
SdUnoDrawView::getSelection()
245 if( mrView
.IsTextEdit() )
246 mrView
.getTextSelection( aAny
);
248 if( !aAny
.hasValue() )
250 const SdrMarkList
& rMarkList
= mrView
.GetMarkedObjectList();
251 const size_t nCount
= rMarkList
.GetMarkCount();
254 Reference
< drawing::XShapes
> xShapes( drawing::ShapeCollection::create(
255 comphelper::getProcessComponentContext()), UNO_QUERY
);
256 for( size_t nNum
= 0; nNum
< nCount
; ++nNum
)
258 SdrMark
*pMark
= rMarkList
.GetMark(nNum
);
262 SdrObject
*pObj
= pMark
->GetMarkedSdrObj();
263 if(pObj
==nullptr || pObj
->getSdrPageFromSdrObject() == nullptr)
266 Reference
< drawing::XDrawPage
> xPage( pObj
->getSdrPageFromSdrObject()->getUnoPage(), UNO_QUERY
);
271 SvxDrawPage
* pDrawPage
= SvxDrawPage::getImplementation( xPage
);
273 if(pDrawPage
==nullptr)
276 Reference
< drawing::XShape
> xShape( pObj
->getUnoShape(), UNO_QUERY
);
279 xShapes
->add(xShape
);
288 void SAL_CALL
SdUnoDrawView::addSelectionChangeListener (
289 const css::uno::Reference
<css::view::XSelectionChangeListener
>&)
292 void SAL_CALL
SdUnoDrawView::removeSelectionChangeListener (
293 const css::uno::Reference
<css::view::XSelectionChangeListener
>&)
296 void SdUnoDrawView::setFastPropertyValue (
302 case DrawController::PROPERTY_CURRENTPAGE
:
304 Reference
< drawing::XDrawPage
> xPage
;
306 setCurrentPage( xPage
);
310 case DrawController::PROPERTY_MASTERPAGEMODE
:
314 setMasterPageMode( bValue
);
318 case DrawController::PROPERTY_LAYERMODE
:
322 setLayerMode( bValue
);
325 case DrawController::PROPERTY_ACTIVE_LAYER
:
327 Reference
<drawing::XLayer
> xLayer
;
329 setActiveLayer (xLayer
);
332 case DrawController::PROPERTY_ZOOMVALUE
:
339 case DrawController::PROPERTY_ZOOMTYPE
:
343 SetZoomType( nType
);
346 case DrawController::PROPERTY_VIEWOFFSET
:
350 SetViewOffset( aOffset
);
354 throw beans::UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
358 Any SAL_CALL
SdUnoDrawView::getFastPropertyValue (
364 case DrawController::PROPERTY_CURRENTPAGE
:
365 aValue
<<= getCurrentPage();
368 case DrawController::PROPERTY_MASTERPAGEMODE
:
369 aValue
<<= getMasterPageMode();
372 case DrawController::PROPERTY_LAYERMODE
:
373 aValue
<<= getLayerMode();
376 case DrawController::PROPERTY_ACTIVE_LAYER
:
377 aValue
<<= getActiveLayer();
380 case DrawController::PROPERTY_ZOOMVALUE
:
381 aValue
<<= GetZoom();
383 case DrawController::PROPERTY_ZOOMTYPE
:
384 aValue
<<= sal_Int16(css::view::DocumentZoomType::BY_VALUE
);
386 case DrawController::PROPERTY_VIEWOFFSET
:
387 aValue
<<= GetViewOffset();
390 case DrawController::PROPERTY_DRAWVIEWMODE
:
391 aValue
= getDrawViewMode();
395 throw beans::UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
403 void SAL_CALL
SdUnoDrawView::setCurrentPage (
404 const Reference
< drawing::XDrawPage
>& xPage
)
406 SvxDrawPage
* pDrawPage
= SvxDrawPage::getImplementation( xPage
);
407 SdrPage
*pSdrPage
= pDrawPage
? pDrawPage
->GetSdrPage() : nullptr;
411 // End editing of text. Otherwise the edited text object would
412 // still be visible on the new page.
413 mrDrawViewShell
.GetView()->SdrEndTextEdit();
415 setMasterPageMode( pSdrPage
->IsMasterPage() );
416 mrDrawViewShell
.SwitchPage( (pSdrPage
->GetPageNum() - 1) >> 1 );
417 mrDrawViewShell
.WriteFrameViewData();
421 Reference
< drawing::XDrawPage
> SAL_CALL
SdUnoDrawView::getCurrentPage()
423 Reference
< drawing::XDrawPage
> xPage
;
425 SdrPageView
*pPV
= mrView
.GetSdrPageView();
426 SdrPage
* pPage
= pPV
? pPV
->GetPage() : nullptr;
429 xPage
.set( pPage
->getUnoPage(), UNO_QUERY
);
434 sal_Int16
SdUnoDrawView::GetZoom() const
436 if (mrDrawViewShell
.GetActiveWindow() )
438 return static_cast<sal_Int16
>(mrDrawViewShell
.GetActiveWindow()->GetZoom());
446 void SdUnoDrawView::SetZoom( sal_Int16 nZoom
)
448 SvxZoomItem
aZoomItem( SvxZoomType::PERCENT
, nZoom
);
450 SfxViewFrame
* pViewFrame
= mrDrawViewShell
.GetViewFrame();
453 SfxDispatcher
* pDispatcher
= pViewFrame
->GetDispatcher();
456 pDispatcher
->ExecuteList(SID_ATTR_ZOOM
, SfxCallMode::SYNCHRON
,
462 void SdUnoDrawView::SetViewOffset(const awt::Point
& rWinPos
)
464 Point
aWinPos( rWinPos
.X
, rWinPos
.Y
);
465 aWinPos
+= mrDrawViewShell
.GetViewOrigin();
466 mrDrawViewShell
.SetWinViewPos( aWinPos
);
469 awt::Point
SdUnoDrawView::GetViewOffset() const
471 Point aRet
= mrDrawViewShell
.GetWinViewPos();
472 aRet
-= mrDrawViewShell
.GetViewOrigin();
474 return awt::Point( aRet
.X(), aRet
.Y() );
477 void SdUnoDrawView::SetZoomType ( sal_Int16 nType
)
479 SfxViewFrame
* pViewFrame
= mrDrawViewShell
.GetViewFrame();
483 SfxDispatcher
* pDispatcher
= pViewFrame
->GetDispatcher();
487 SvxZoomType eZoomType
;
490 case css::view::DocumentZoomType::OPTIMAL
:
491 eZoomType
= SvxZoomType::OPTIMAL
;
494 case css::view::DocumentZoomType::PAGE_WIDTH
:
495 case css::view::DocumentZoomType::PAGE_WIDTH_EXACT
:
496 eZoomType
= SvxZoomType::PAGEWIDTH
;
499 case css::view::DocumentZoomType::ENTIRE_PAGE
:
500 eZoomType
= SvxZoomType::WHOLEPAGE
;
506 SvxZoomItem
aZoomItem( eZoomType
);
507 pDispatcher
->ExecuteList(SID_ATTR_ZOOM
, SfxCallMode::SYNCHRON
,
511 SdXImpressDocument
* SdUnoDrawView::GetModel() const throw()
513 if (mrView
.GetDocSh()!=nullptr)
515 Reference
<frame::XModel
> xModel (mrView
.GetDocSh()->GetModel());
516 return SdXImpressDocument::getImplementation(xModel
);
522 Any
SdUnoDrawView::getDrawViewMode() const
525 switch( mrDrawViewShell
.GetPageKind() )
527 case PageKind::Notes
: aRet
<<= DrawViewMode_NOTES
; break;
528 case PageKind::Handout
: aRet
<<= DrawViewMode_HANDOUT
; break;
529 case PageKind::Standard
: aRet
<<= DrawViewMode_DRAW
; break;
535 OUString SAL_CALL
SdUnoDrawView::getImplementationName( )
537 return OUString( "com.sun.star.comp.sd.SdUnoDrawView") ;
540 sal_Bool SAL_CALL
SdUnoDrawView::supportsService( const OUString
& ServiceName
)
542 return cppu::supportsService( this, ServiceName
);
545 Sequence
< OUString
> SAL_CALL
SdUnoDrawView::getSupportedServiceNames( )
547 OUString
aSN("com.sun.star.drawing.DrawingDocumentDrawView");
548 uno::Sequence
< OUString
> aSeq( &aSN
, 1 );
552 } // end of namespace sd
554 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */