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 .
21 #include "SdUnoDrawView.hxx"
23 #include "DrawController.hxx"
24 #include "DrawDocShell.hxx"
25 #include "DrawViewShell.hxx"
26 #include "drawdoc.hxx"
27 #include "unolayer.hxx"
28 #include "unomodel.hxx"
29 #include "unopage.hxx"
33 #include <cppuhelper/proptypehlp.hxx>
34 #include <comphelper/serviceinfohelper.hxx>
35 #include <sfx2/dispatch.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <svx/svdpagv.hxx>
38 #include <svx/unoshape.hxx>
39 #include <svx/unoshcol.hxx>
40 #include <sfx2/zoomitem.hxx>
41 #include <com/sun/star/drawing/DrawViewMode.hpp>
42 #include <com/sun/star/drawing/XLayerManager.hpp>
43 #include <com/sun/star/view/DocumentZoomType.hpp>
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::drawing
;
55 SdUnoDrawView::SdUnoDrawView(
56 DrawViewShell
& rViewShell
,
58 : DrawSubControllerInterfaceBase(m_aMutex
),
59 mrDrawViewShell(rViewShell
),
67 SdUnoDrawView::~SdUnoDrawView() throw()
74 sal_Bool
SdUnoDrawView::getMasterPageMode(void) const throw()
76 return (mrDrawViewShell
.GetEditMode() == EM_MASTERPAGE
);
82 void SdUnoDrawView::setMasterPageMode (sal_Bool bMasterPageMode
) throw()
84 if ((mrDrawViewShell
.GetEditMode() == EM_MASTERPAGE
) != bMasterPageMode
)
86 mrDrawViewShell
.ChangeEditMode (
87 bMasterPageMode
? EM_MASTERPAGE
: EM_PAGE
,
88 mrDrawViewShell
.IsLayerModeActive());
95 sal_Bool
SdUnoDrawView::getLayerMode(void) const throw()
97 return mrDrawViewShell
.IsLayerModeActive();
103 void SdUnoDrawView::setLayerMode (sal_Bool bLayerMode
) throw()
105 if (mrDrawViewShell
.IsLayerModeActive() != (bLayerMode
==sal_True
))
107 mrDrawViewShell
.ChangeEditMode (
108 mrDrawViewShell
.GetEditMode(),
116 Reference
<drawing::XLayer
> SdUnoDrawView::getActiveLayer (void) throw ()
118 Reference
<drawing::XLayer
> xCurrentLayer
;
122 // Retrieve the layer manager from the model.
123 SdXImpressDocument
* pModel
= GetModel();
127 SdDrawDocument
* pSdModel
= pModel
->GetDoc();
128 if (pSdModel
== NULL
)
131 // From the model get the current SdrLayer object via the layer admin.
132 SdrLayerAdmin
& rLayerAdmin
= pSdModel
->GetLayerAdmin ();
133 SdrLayer
* pLayer
= rLayerAdmin
.GetLayer (mrView
.GetActiveLayer(), sal_True
);
137 // Get the corresponding XLayer object from the implementation
138 // object of the layer manager.
139 Reference
<drawing::XLayerManager
> xManager (pModel
->getLayerManager(), uno::UNO_QUERY
);
140 SdLayerManager
* pManager
= SdLayerManager::getImplementation (xManager
);
141 if (pManager
!= NULL
)
142 xCurrentLayer
= pManager
->GetLayer (pLayer
);
146 return xCurrentLayer
;
152 void SdUnoDrawView::setActiveLayer (const Reference
<drawing::XLayer
>& rxLayer
) throw ()
154 // Get the SdrLayer object corresponding to the given reference.
158 SdLayer
* pLayer
= SdLayer::getImplementation (rxLayer
);
162 SdrLayer
* pSdrLayer
= pLayer
->GetSdrLayer();
163 if (pSdrLayer
== NULL
)
166 // Set the new active layer and make the change visible.
167 mrView
.SetActiveLayer (pSdrLayer
->GetName());
168 mrDrawViewShell
.ResetActualLayer ();
174 // XSelectionSupplier
177 sal_Bool SAL_CALL
SdUnoDrawView::select( const Any
& aSelection
)
178 throw(lang::IllegalArgumentException
, RuntimeException
)
182 ::std::vector
<SdrObject
*> aObjects
;
184 SdrPage
* pSdrPage
= NULL
;
186 Reference
< drawing::XShape
> xShape
;
187 aSelection
>>= xShape
;
191 SvxShape
* pShape
= SvxShape::getImplementation( xShape
);
192 if( pShape
&& (pShape
->GetSdrObject() != NULL
) )
194 SdrObject
* pObj
= pShape
->GetSdrObject();
195 pSdrPage
= pObj
->GetPage();
196 aObjects
.push_back( pObj
);
205 Reference
< drawing::XShapes
> xShapes
;
206 aSelection
>>= xShapes
;
209 const sal_uInt32 nCount
= xShapes
->getCount();
210 for( sal_uInt32 i
= 0; i
< nCount
; i
++ )
212 xShapes
->getByIndex(i
) >>= xShape
;
215 SvxShape
* pShape
= SvxShape::getImplementation(xShape
);
216 if( (pShape
== NULL
) || (pShape
->GetSdrObject() == NULL
) )
222 SdrObject
* pObj
= pShape
->GetSdrObject();
224 if( pSdrPage
== NULL
)
226 pSdrPage
= pObj
->GetPage();
228 else if( pSdrPage
!= pObj
->GetPage() )
234 aObjects
.push_back( pObj
);
244 setMasterPageMode( pSdrPage
->IsMasterPage() );
245 mrDrawViewShell
.SwitchPage( (pSdrPage
->GetPageNum() - 1) >> 1 );
246 mrDrawViewShell
.WriteFrameViewData();
249 SdrPageView
*pPV
= mrView
.GetSdrPageView();
253 // first deselect all
254 mrView
.UnmarkAllObj( pPV
);
256 ::std::vector
<SdrObject
*>::iterator
aIter( aObjects
.begin() );
257 const ::std::vector
<SdrObject
*>::iterator
aEnd( aObjects
.end() );
258 while( aIter
!= aEnd
)
260 SdrObject
* pObj
= (*aIter
++);
261 mrView
.MarkObj( pObj
, pPV
);
273 //----------------------------------------------------------------------
275 Any SAL_CALL
SdUnoDrawView::getSelection()
276 throw(RuntimeException
)
280 if( mrView
.IsTextEdit() )
281 mrView
.getTextSelection( aAny
);
284 if( !aAny
.hasValue() )
286 const SdrMarkList
& rMarkList
= mrView
.GetMarkedObjectList();
287 sal_uInt32 nCount
= rMarkList
.GetMarkCount();
290 Reference
< drawing::XShapes
> xShapes( SvxShapeCollection_NewInstance(), UNO_QUERY
);
291 for( sal_uInt32 nNum
= 0; nNum
< nCount
; nNum
++)
293 SdrMark
*pMark
= rMarkList
.GetMark(nNum
);
297 SdrObject
*pObj
= pMark
->GetMarkedSdrObj();
298 if(pObj
==NULL
|| pObj
->GetPage() == NULL
)
301 Reference
< drawing::XDrawPage
> xPage( pObj
->GetPage()->getUnoPage(), UNO_QUERY
);
306 SvxDrawPage
* pDrawPage
= SvxDrawPage::getImplementation( xPage
);
311 Reference
< drawing::XShape
> xShape( pObj
->getUnoShape(), UNO_QUERY
);
314 xShapes
->add(xShape
);
326 void SAL_CALL
SdUnoDrawView::addSelectionChangeListener (
327 const css::uno::Reference
<css::view::XSelectionChangeListener
>& rxListener
)
328 throw(css::uno::RuntimeException
)
336 void SAL_CALL
SdUnoDrawView::removeSelectionChangeListener (
337 const css::uno::Reference
<css::view::XSelectionChangeListener
>& rxListener
)
338 throw(css::uno::RuntimeException
)
346 void SdUnoDrawView::setFastPropertyValue (
349 throw(css::beans::UnknownPropertyException
,
350 css::beans::PropertyVetoException
,
351 css::lang::IllegalArgumentException
,
352 css::lang::WrappedTargetException
,
353 css::uno::RuntimeException
)
357 case DrawController::PROPERTY_CURRENTPAGE
:
359 Reference
< drawing::XDrawPage
> xPage
;
361 setCurrentPage( xPage
);
365 case DrawController::PROPERTY_MASTERPAGEMODE
:
367 sal_Bool bValue
= sal_False
;
369 setMasterPageMode( bValue
);
373 case DrawController::PROPERTY_LAYERMODE
:
375 sal_Bool bValue
= sal_False
;
377 setLayerMode( bValue
);
380 case DrawController::PROPERTY_ACTIVE_LAYER
:
382 Reference
<drawing::XLayer
> xLayer
;
384 setActiveLayer (xLayer
);
387 case DrawController::PROPERTY_ZOOMVALUE
:
394 case DrawController::PROPERTY_ZOOMTYPE
:
398 SetZoomType( nType
);
401 case DrawController::PROPERTY_VIEWOFFSET
:
405 SetViewOffset( aOffset
);
409 throw beans::UnknownPropertyException();
416 Any SAL_CALL
SdUnoDrawView::getFastPropertyValue (
418 throw(css::beans::UnknownPropertyException
,
419 css::lang::WrappedTargetException
,
420 css::uno::RuntimeException
)
425 case DrawController::PROPERTY_CURRENTPAGE
:
426 aValue
<<= (const_cast<SdUnoDrawView
*>(this))->getCurrentPage();
429 case DrawController::PROPERTY_MASTERPAGEMODE
:
430 aValue
<<= getMasterPageMode();
433 case DrawController::PROPERTY_LAYERMODE
:
434 aValue
<<= getLayerMode();
437 case DrawController::PROPERTY_ACTIVE_LAYER
:
438 aValue
<<= (const_cast<SdUnoDrawView
*>(this))->getActiveLayer();
441 case DrawController::PROPERTY_ZOOMVALUE
:
442 aValue
<<= GetZoom();
444 case DrawController::PROPERTY_ZOOMTYPE
:
445 aValue
<<= (sal_Int16
)com::sun::star::view::DocumentZoomType::BY_VALUE
;
447 case DrawController::PROPERTY_VIEWOFFSET
:
448 aValue
<<= GetViewOffset();
451 case DrawController::PROPERTY_DRAWVIEWMODE
:
452 aValue
= getDrawViewMode();
456 throw beans::UnknownPropertyException();
468 void SAL_CALL
SdUnoDrawView::setCurrentPage (
469 const Reference
< drawing::XDrawPage
>& xPage
)
470 throw(RuntimeException
)
472 SvxDrawPage
* pDrawPage
= SvxDrawPage::getImplementation( xPage
);
473 SdrPage
*pSdrPage
= pDrawPage
? pDrawPage
->GetSdrPage() : NULL
;
477 // End editing of text. Otherwise the edited text object would
478 // still be visible on the new page.
479 mrDrawViewShell
.GetView()->SdrEndTextEdit();
481 setMasterPageMode( pSdrPage
->IsMasterPage() );
482 mrDrawViewShell
.SwitchPage( (pSdrPage
->GetPageNum() - 1) >> 1 );
483 mrDrawViewShell
.WriteFrameViewData();
487 //----------------------------------------------------------------------
489 Reference
< drawing::XDrawPage
> SAL_CALL
SdUnoDrawView::getCurrentPage()
490 throw(RuntimeException
)
492 Reference
< drawing::XDrawPage
> xPage
;
494 SdrPageView
*pPV
= mrView
.GetSdrPageView();
495 SdrPage
* pPage
= pPV
? pPV
->GetPage() : NULL
;
498 xPage
= Reference
< drawing::XDrawPage
>::query( pPage
->getUnoPage() );
504 sal_Int16
SdUnoDrawView::GetZoom(void) const
506 if (mrDrawViewShell
.GetActiveWindow() )
508 return (sal_Int16
)mrDrawViewShell
.GetActiveWindow()->GetZoom();
516 void SdUnoDrawView::SetZoom( sal_Int16 nZoom
)
518 SvxZoomItem
aZoomItem( SVX_ZOOM_PERCENT
, nZoom
);
520 SfxViewFrame
* pViewFrame
= mrDrawViewShell
.GetViewFrame();
523 SfxDispatcher
* pDispatcher
= pViewFrame
->GetDispatcher();
526 pDispatcher
->Execute(SID_ATTR_ZOOM
,SFX_CALLMODE_SYNCHRON
,&aZoomItem
, 0L);
532 void SdUnoDrawView::SetViewOffset(const awt::Point
& rWinPos
)
534 Point
aWinPos( rWinPos
.X
, rWinPos
.Y
);
535 aWinPos
+= mrDrawViewShell
.GetViewOrigin();
536 mrDrawViewShell
.SetWinViewPos( aWinPos
, true );
539 awt::Point
SdUnoDrawView::GetViewOffset() const
543 aRet
= mrDrawViewShell
.GetWinViewPos();
544 aRet
-= mrDrawViewShell
.GetViewOrigin();
546 return awt::Point( aRet
.X(), aRet
.Y() );
549 void SdUnoDrawView::SetZoomType ( sal_Int16 nType
)
551 SfxViewFrame
* pViewFrame
= mrDrawViewShell
.GetViewFrame();
554 SfxDispatcher
* pDispatcher
= pViewFrame
->GetDispatcher();
557 SvxZoomType eZoomType
;
560 case com::sun::star::view::DocumentZoomType::OPTIMAL
:
561 eZoomType
= SVX_ZOOM_OPTIMAL
;
564 case com::sun::star::view::DocumentZoomType::PAGE_WIDTH
:
565 case com::sun::star::view::DocumentZoomType::PAGE_WIDTH_EXACT
:
566 eZoomType
= SVX_ZOOM_PAGEWIDTH
;
569 case com::sun::star::view::DocumentZoomType::ENTIRE_PAGE
:
570 eZoomType
= SVX_ZOOM_WHOLEPAGE
;
576 SvxZoomItem
aZoomItem( eZoomType
);
577 pDispatcher
->Execute(SID_ATTR_ZOOM
,SFX_CALLMODE_SYNCHRON
,&aZoomItem
, 0L);
585 SdXImpressDocument
* SdUnoDrawView::GetModel (void) const throw()
587 if (mrView
.GetDocSh()!=NULL
)
589 Reference
<frame::XModel
> xModel (mrView
.GetDocSh()->GetModel());
590 return SdXImpressDocument::getImplementation(xModel
);
596 Any
SdUnoDrawView::getDrawViewMode() const
599 switch( mrDrawViewShell
.GetPageKind() )
601 case PK_NOTES
: aRet
<<= DrawViewMode_NOTES
; break;
602 case PK_HANDOUT
: aRet
<<= DrawViewMode_HANDOUT
; break;
603 case PK_STANDARD
: aRet
<<= DrawViewMode_DRAW
; break;
609 OUString SAL_CALL
SdUnoDrawView::getImplementationName( ) throw (RuntimeException
)
611 return OUString( "com.sun.star.comp.sd.SdUnoDrawView") ;
614 sal_Bool SAL_CALL
SdUnoDrawView::supportsService( const OUString
& ServiceName
) throw (RuntimeException
)
616 return comphelper::ServiceInfoHelper::supportsService( ServiceName
, getSupportedServiceNames() );
619 Sequence
< OUString
> SAL_CALL
SdUnoDrawView::getSupportedServiceNames( ) throw (RuntimeException
)
621 OUString
aSN("com.sun.star.drawing.DrawingDocumentDrawView");
622 uno::Sequence
< OUString
> aSeq( &aSN
, 1 );
626 } // end of namespace sd
628 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */