1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SdUnoDrawView.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "SdUnoDrawView.hxx"
36 #include "DrawController.hxx"
37 #include "DrawDocShell.hxx"
38 #include "DrawViewShell.hxx"
39 #include "drawdoc.hxx"
40 #include "unolayer.hxx"
41 #include "unomodel.hxx"
42 #include "unopage.hxx"
45 #include <cppuhelper/proptypehlp.hxx>
46 #include <sfx2/dispatch.hxx>
47 #include <sfx2/viewfrm.hxx>
48 #include <svx/svdpagv.hxx>
49 #include <svx/unoshape.hxx>
50 #include <svx/unoshcol.hxx>
51 #include <svx/zoomitem.hxx>
52 #include <com/sun/star/drawing/XLayerManager.hpp>
53 #include <com/sun/star/view/DocumentZoomType.hpp>
57 using namespace ::com::sun::star
;
58 using namespace ::com::sun::star::uno
;
63 SdUnoDrawView::SdUnoDrawView(
64 DrawController
& rController
,
65 DrawViewShell
& rViewShell
,
67 : DrawSubControllerInterfaceBase(m_aMutex
),
68 mrController(rController
),
69 mrDrawViewShell(rViewShell
),
77 SdUnoDrawView::~SdUnoDrawView() throw()
84 sal_Bool
SdUnoDrawView::getMasterPageMode(void) const throw()
86 return (mrDrawViewShell
.GetEditMode() == EM_MASTERPAGE
);
92 void SdUnoDrawView::setMasterPageMode (sal_Bool bMasterPageMode
) throw()
94 if ((mrDrawViewShell
.GetEditMode() == EM_MASTERPAGE
) != bMasterPageMode
)
96 mrDrawViewShell
.ChangeEditMode (
97 bMasterPageMode
? EM_MASTERPAGE
: EM_PAGE
,
98 mrDrawViewShell
.IsLayerModeActive());
105 sal_Bool
SdUnoDrawView::getLayerMode(void) const throw()
107 return mrDrawViewShell
.IsLayerModeActive();
113 void SdUnoDrawView::setLayerMode (sal_Bool bLayerMode
) throw()
115 if (mrDrawViewShell
.IsLayerModeActive() != (bLayerMode
==sal_True
))
117 mrDrawViewShell
.ChangeEditMode (
118 mrDrawViewShell
.GetEditMode(),
126 Reference
<drawing::XLayer
> SdUnoDrawView::getActiveLayer (void) throw ()
128 Reference
<drawing::XLayer
> xCurrentLayer
;
132 // Retrieve the layer manager from the model.
133 SdXImpressDocument
* pModel
= GetModel();
137 SdDrawDocument
* pSdModel
= pModel
->GetDoc();
138 if (pSdModel
== NULL
)
141 // From the model get the current SdrLayer object via the layer admin.
142 SdrLayerAdmin
& rLayerAdmin
= pSdModel
->GetLayerAdmin ();
143 SdrLayer
* pLayer
= rLayerAdmin
.GetLayer (mrView
.GetActiveLayer(), TRUE
);
147 // Get the corresponding XLayer object from the implementation
148 // object of the layer manager.
149 Reference
<drawing::XLayerManager
> xManager (pModel
->getLayerManager(), uno::UNO_QUERY
);
150 SdLayerManager
* pManager
= SdLayerManager::getImplementation (xManager
);
151 if (pManager
!= NULL
)
152 xCurrentLayer
= pManager
->GetLayer (pLayer
);
156 return xCurrentLayer
;
162 void SdUnoDrawView::setActiveLayer (const Reference
<drawing::XLayer
>& rxLayer
) throw ()
166 // Get the SdrLayer object corresponding to the given reference.
170 SdLayer
* pLayer
= SdLayer::getImplementation (rxLayer
);
174 SdrLayer
* pSdrLayer
= pLayer
->GetSdrLayer();
175 if (pSdrLayer
== NULL
)
178 // Set the new active layer and make the change visible.
179 mrView
.SetActiveLayer (pSdrLayer
->GetName());
180 mrDrawViewShell
.ResetActualLayer ();
188 // XSelectionSupplier
191 sal_Bool SAL_CALL
SdUnoDrawView::select( const Any
& aSelection
)
192 throw(lang::IllegalArgumentException
, RuntimeException
)
196 ::std::vector
<SdrObject
*> aObjects
;
198 SdrPage
* pSdrPage
= NULL
;
200 Reference
< drawing::XShape
> xShape
;
201 aSelection
>>= xShape
;
205 SvxShape
* pShape
= SvxShape::getImplementation( xShape
);
206 if( pShape
&& (pShape
->GetSdrObject() != NULL
) )
208 SdrObject
* pObj
= pShape
->GetSdrObject();
209 pSdrPage
= pObj
->GetPage();
210 aObjects
.push_back( pObj
);
219 Reference
< drawing::XShapes
> xShapes
;
220 aSelection
>>= xShapes
;
223 const sal_uInt32 nCount
= xShapes
->getCount();
224 for( sal_uInt32 i
= 0; i
< nCount
; i
++ )
226 xShapes
->getByIndex(i
) >>= xShape
;
229 SvxShape
* pShape
= SvxShape::getImplementation(xShape
);
230 if( (pShape
== NULL
) || (pShape
->GetSdrObject() == NULL
) )
236 SdrObject
* pObj
= pShape
->GetSdrObject();
238 if( pSdrPage
== NULL
)
240 pSdrPage
= pObj
->GetPage();
242 else if( pSdrPage
!= pObj
->GetPage() )
248 aObjects
.push_back( pObj
);
258 setMasterPageMode( pSdrPage
->IsMasterPage() );
259 mrDrawViewShell
.SwitchPage( (pSdrPage
->GetPageNum() - 1) >> 1 );
260 mrDrawViewShell
.WriteFrameViewData();
263 SdrPageView
*pPV
= mrView
.GetSdrPageView();
267 // first deselect all
268 mrView
.UnmarkAllObj( pPV
);
270 ::std::vector
<SdrObject
*>::iterator
aIter( aObjects
.begin() );
271 const ::std::vector
<SdrObject
*>::iterator
aEnd( aObjects
.end() );
272 while( aIter
!= aEnd
)
274 SdrObject
* pObj
= (*aIter
++);
275 mrView
.MarkObj( pObj
, pPV
);
287 //----------------------------------------------------------------------
289 Any SAL_CALL
SdUnoDrawView::getSelection()
290 throw(RuntimeException
)
294 if( mrView
.IsTextEdit() )
295 mrView
.getTextSelection( aAny
);
298 if( !aAny
.hasValue() )
300 const SdrMarkList
& rMarkList
= mrView
.GetMarkedObjectList();
301 sal_uInt32 nCount
= rMarkList
.GetMarkCount();
304 Reference
< drawing::XShapes
> xShapes( SvxShapeCollection_NewInstance(), UNO_QUERY
);
305 for( sal_uInt32 nNum
= 0; nNum
< nCount
; nNum
++)
307 SdrMark
*pMark
= rMarkList
.GetMark(nNum
);
311 SdrObject
*pObj
= pMark
->GetMarkedSdrObj();
312 if(pObj
==NULL
|| pObj
->GetPage() == NULL
)
315 Reference
< drawing::XDrawPage
> xPage( pObj
->GetPage()->getUnoPage(), UNO_QUERY
);
320 SvxDrawPage
* pDrawPage
= SvxDrawPage::getImplementation( xPage
);
325 Reference
< drawing::XShape
> xShape( pObj
->getUnoShape(), UNO_QUERY
);
328 xShapes
->add(xShape
);
340 void SAL_CALL
SdUnoDrawView::addSelectionChangeListener (
341 const css::uno::Reference
<css::view::XSelectionChangeListener
>& rxListener
)
342 throw(css::uno::RuntimeException
)
350 void SAL_CALL
SdUnoDrawView::removeSelectionChangeListener (
351 const css::uno::Reference
<css::view::XSelectionChangeListener
>& rxListener
)
352 throw(css::uno::RuntimeException
)
360 void SdUnoDrawView::setFastPropertyValue (
363 throw(css::beans::UnknownPropertyException
,
364 css::beans::PropertyVetoException
,
365 css::lang::IllegalArgumentException
,
366 css::lang::WrappedTargetException
,
367 css::uno::RuntimeException
)
371 case DrawController::PROPERTY_CURRENTPAGE
:
373 Reference
< drawing::XDrawPage
> xPage
;
375 setCurrentPage( xPage
);
379 case DrawController::PROPERTY_MASTERPAGEMODE
:
381 sal_Bool bValue
= sal_False
;
383 setMasterPageMode( bValue
);
387 case DrawController::PROPERTY_LAYERMODE
:
389 sal_Bool bValue
= sal_False
;
391 setLayerMode( bValue
);
394 case DrawController::PROPERTY_ACTIVE_LAYER
:
396 Reference
<drawing::XLayer
> xLayer
;
398 setActiveLayer (xLayer
);
401 case DrawController::PROPERTY_ZOOMVALUE
:
408 case DrawController::PROPERTY_ZOOMTYPE
:
412 SetZoomType( nType
);
415 case DrawController::PROPERTY_VIEWOFFSET
:
419 SetViewOffset( aOffset
);
424 throw beans::UnknownPropertyException();
431 Any SAL_CALL
SdUnoDrawView::getFastPropertyValue (
433 throw(css::beans::UnknownPropertyException
,
434 css::lang::WrappedTargetException
,
435 css::uno::RuntimeException
)
440 case DrawController::PROPERTY_CURRENTPAGE
:
441 aValue
<<= (const_cast<SdUnoDrawView
*>(this))->getCurrentPage();
444 case DrawController::PROPERTY_MASTERPAGEMODE
:
445 aValue
<<= getMasterPageMode();
448 case DrawController::PROPERTY_LAYERMODE
:
449 aValue
<<= getLayerMode();
452 case DrawController::PROPERTY_ACTIVE_LAYER
:
453 aValue
<<= (const_cast<SdUnoDrawView
*>(this))->getActiveLayer();
456 case DrawController::PROPERTY_ZOOMVALUE
:
457 aValue
<<= GetZoom();
459 case DrawController::PROPERTY_ZOOMTYPE
:
460 aValue
<<= (sal_Int16
)com::sun::star::view::DocumentZoomType::BY_VALUE
;
462 case DrawController::PROPERTY_VIEWOFFSET
:
463 aValue
<<= GetViewOffset();
467 throw beans::UnknownPropertyException();
479 void SAL_CALL
SdUnoDrawView::setCurrentPage (
480 const Reference
< drawing::XDrawPage
>& xPage
)
481 throw(RuntimeException
)
483 SvxDrawPage
* pDrawPage
= SvxDrawPage::getImplementation( xPage
);
484 SdrPage
*pSdrPage
= pDrawPage
? pDrawPage
->GetSdrPage() : NULL
;
488 // End editing of text. Otherwise the edited text object would
489 // still be visible on the new page.
490 mrDrawViewShell
.GetView()->SdrEndTextEdit();
492 setMasterPageMode( pSdrPage
->IsMasterPage() );
493 mrDrawViewShell
.SwitchPage( (pSdrPage
->GetPageNum() - 1) >> 1 );
494 mrDrawViewShell
.WriteFrameViewData();
498 //----------------------------------------------------------------------
500 Reference
< drawing::XDrawPage
> SAL_CALL
SdUnoDrawView::getCurrentPage()
501 throw(RuntimeException
)
503 Reference
< drawing::XDrawPage
> xPage
;
505 SdrPageView
*pPV
= mrView
.GetSdrPageView();
506 SdrPage
* pPage
= pPV
? pPV
->GetPage() : NULL
;
509 xPage
= Reference
< drawing::XDrawPage
>::query( pPage
->getUnoPage() );
515 sal_Int16
SdUnoDrawView::GetZoom(void) const
517 if (mrDrawViewShell
.GetActiveWindow() )
519 return (sal_Int16
)mrDrawViewShell
.GetActiveWindow()->GetZoom();
527 void SdUnoDrawView::SetZoom( sal_Int16 nZoom
)
529 SvxZoomItem
aZoomItem( SVX_ZOOM_PERCENT
, nZoom
);
531 SfxViewFrame
* pViewFrame
= mrDrawViewShell
.GetViewFrame();
534 SfxDispatcher
* pDispatcher
= pViewFrame
->GetDispatcher();
537 pDispatcher
->Execute(SID_ATTR_ZOOM
,SFX_CALLMODE_SYNCHRON
,&aZoomItem
, 0L);
543 void SdUnoDrawView::SetViewOffset(const awt::Point
& rWinPos
)
545 Point
aWinPos( rWinPos
.X
, rWinPos
.Y
);
546 aWinPos
+= mrDrawViewShell
.GetViewOrigin();
547 mrDrawViewShell
.SetWinViewPos( aWinPos
, true );
550 awt::Point
SdUnoDrawView::GetViewOffset() const
554 aRet
= mrDrawViewShell
.GetWinViewPos();
555 aRet
-= mrDrawViewShell
.GetViewOrigin();
557 return awt::Point( aRet
.X(), aRet
.Y() );
560 void SdUnoDrawView::SetZoomType ( sal_Int16 nType
)
562 SfxViewFrame
* pViewFrame
= mrDrawViewShell
.GetViewFrame();
565 SfxDispatcher
* pDispatcher
= pViewFrame
->GetDispatcher();
568 SvxZoomType eZoomType
;
571 case com::sun::star::view::DocumentZoomType::OPTIMAL
:
572 eZoomType
= SVX_ZOOM_OPTIMAL
;
575 case com::sun::star::view::DocumentZoomType::PAGE_WIDTH
:
576 case com::sun::star::view::DocumentZoomType::PAGE_WIDTH_EXACT
:
577 eZoomType
= SVX_ZOOM_PAGEWIDTH
;
580 case com::sun::star::view::DocumentZoomType::ENTIRE_PAGE
:
581 eZoomType
= SVX_ZOOM_WHOLEPAGE
;
587 SvxZoomItem
aZoomItem( eZoomType
);
588 pDispatcher
->Execute(SID_ATTR_ZOOM
,SFX_CALLMODE_SYNCHRON
,&aZoomItem
, 0L);
596 SdXImpressDocument
* SdUnoDrawView::GetModel (void) const throw()
598 if (mrView
.GetDocSh()!=NULL
)
600 Reference
<frame::XModel
> xModel (mrView
.GetDocSh()->GetModel());
601 return SdXImpressDocument::getImplementation(xModel
);
608 } // end of namespace sd