update dev300-m58
[ooovba.git] / sd / source / ui / unoidl / SdUnoDrawView.cxx
blobb5ef58741067269a86e46c1fa5a594aeb17b985e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SdUnoDrawView.cxx,v $
10 * $Revision: 1.35 $
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"
43 #include "Window.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>
55 #include <vector>
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
61 namespace sd {
63 SdUnoDrawView::SdUnoDrawView(
64 DrawController& rController,
65 DrawViewShell& rViewShell,
66 View& rView) throw()
67 : DrawSubControllerInterfaceBase(m_aMutex),
68 mrController(rController),
69 mrDrawViewShell(rViewShell),
70 mrView(rView)
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(),
119 bLayerMode);
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();
134 if (pModel == NULL)
135 break;
137 SdDrawDocument* pSdModel = pModel->GetDoc();
138 if (pSdModel == NULL)
139 break;
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);
144 if (pLayer == NULL)
145 break;
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);
154 while (false);
156 return xCurrentLayer;
162 void SdUnoDrawView::setActiveLayer (const Reference<drawing::XLayer>& rxLayer) throw ()
166 // Get the SdrLayer object corresponding to the given reference.
167 if ( ! rxLayer.is())
168 break;
170 SdLayer* pLayer = SdLayer::getImplementation (rxLayer);
171 if (pLayer == NULL)
172 break;
174 SdrLayer* pSdrLayer = pLayer->GetSdrLayer();
175 if (pSdrLayer == NULL)
176 break;
178 // Set the new active layer and make the change visible.
179 mrView.SetActiveLayer (pSdrLayer->GetName());
180 mrDrawViewShell.ResetActualLayer ();
182 while (false);
188 // XSelectionSupplier
191 sal_Bool SAL_CALL SdUnoDrawView::select( const Any& aSelection )
192 throw(lang::IllegalArgumentException, RuntimeException)
194 bool bOk = true;
196 ::std::vector<SdrObject*> aObjects;
198 SdrPage* pSdrPage = NULL;
200 Reference< drawing::XShape > xShape;
201 aSelection >>= xShape;
203 if(xShape.is())
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 );
212 else
214 bOk = false;
217 else
219 Reference< drawing::XShapes > xShapes;
220 aSelection >>= xShapes;
221 if( xShapes.is() )
223 const sal_uInt32 nCount = xShapes->getCount();
224 for( sal_uInt32 i = 0; i < nCount; i++ )
226 xShapes->getByIndex(i) >>= xShape;
227 if( xShape.is() )
229 SvxShape* pShape = SvxShape::getImplementation(xShape);
230 if( (pShape == NULL) || (pShape->GetSdrObject() == NULL) )
232 bOk = false;
233 break;
236 SdrObject* pObj = pShape->GetSdrObject();
238 if( pSdrPage == NULL )
240 pSdrPage = pObj->GetPage();
242 else if( pSdrPage != pObj->GetPage() )
244 bOk = false;
245 break;
248 aObjects.push_back( pObj );
254 if( bOk )
256 if( pSdrPage )
258 setMasterPageMode( pSdrPage->IsMasterPage() );
259 mrDrawViewShell.SwitchPage( (pSdrPage->GetPageNum() - 1) >> 1 );
260 mrDrawViewShell.WriteFrameViewData();
263 SdrPageView *pPV = mrView.GetSdrPageView();
265 if(pPV)
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 );
278 else
280 bOk = false;
284 return bOk;
287 //----------------------------------------------------------------------
289 Any SAL_CALL SdUnoDrawView::getSelection()
290 throw(RuntimeException)
292 Any aAny;
294 if( mrView.IsTextEdit() )
295 mrView.getTextSelection( aAny );
298 if( !aAny.hasValue() )
300 const SdrMarkList& rMarkList = mrView.GetMarkedObjectList();
301 sal_uInt32 nCount = rMarkList.GetMarkCount();
302 if( nCount )
304 Reference< drawing::XShapes > xShapes( SvxShapeCollection_NewInstance(), UNO_QUERY );
305 for( sal_uInt32 nNum = 0; nNum < nCount; nNum++)
307 SdrMark *pMark = rMarkList.GetMark(nNum);
308 if(pMark==NULL)
309 continue;
311 SdrObject *pObj = pMark->GetMarkedSdrObj();
312 if(pObj==NULL || pObj->GetPage() == NULL)
313 continue;
315 Reference< drawing::XDrawPage > xPage( pObj->GetPage()->getUnoPage(), UNO_QUERY);
317 if(!xPage.is())
318 continue;
320 SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xPage );
322 if(pDrawPage==NULL)
323 continue;
325 Reference< drawing::XShape > xShape( pObj->getUnoShape(), UNO_QUERY );
327 if(xShape.is())
328 xShapes->add(xShape);
330 aAny <<= xShapes;
334 return aAny;
340 void SAL_CALL SdUnoDrawView::addSelectionChangeListener (
341 const css::uno::Reference<css::view::XSelectionChangeListener>& rxListener)
342 throw(css::uno::RuntimeException)
344 (void)rxListener;
350 void SAL_CALL SdUnoDrawView::removeSelectionChangeListener (
351 const css::uno::Reference<css::view::XSelectionChangeListener>& rxListener)
352 throw(css::uno::RuntimeException)
354 (void)rxListener;
360 void SdUnoDrawView::setFastPropertyValue (
361 sal_Int32 nHandle,
362 const Any& rValue)
363 throw(css::beans::UnknownPropertyException,
364 css::beans::PropertyVetoException,
365 css::lang::IllegalArgumentException,
366 css::lang::WrappedTargetException,
367 css::uno::RuntimeException)
369 switch( nHandle )
371 case DrawController::PROPERTY_CURRENTPAGE:
373 Reference< drawing::XDrawPage > xPage;
374 rValue >>= xPage;
375 setCurrentPage( xPage );
377 break;
379 case DrawController::PROPERTY_MASTERPAGEMODE:
381 sal_Bool bValue = sal_False;
382 rValue >>= bValue;
383 setMasterPageMode( bValue );
385 break;
387 case DrawController::PROPERTY_LAYERMODE:
389 sal_Bool bValue = sal_False;
390 rValue >>= bValue;
391 setLayerMode( bValue );
394 case DrawController::PROPERTY_ACTIVE_LAYER:
396 Reference<drawing::XLayer> xLayer;
397 rValue >>= xLayer;
398 setActiveLayer (xLayer);
400 break;
401 case DrawController::PROPERTY_ZOOMVALUE:
403 sal_Int16 nZoom = 0;
404 rValue >>= nZoom;
405 SetZoom( nZoom );
407 break;
408 case DrawController::PROPERTY_ZOOMTYPE:
410 sal_Int16 nType = 0;
411 rValue >>= nType;
412 SetZoomType( nType );
414 break;
415 case DrawController::PROPERTY_VIEWOFFSET:
417 awt::Point aOffset;
418 rValue >>= aOffset;
419 SetViewOffset( aOffset );
421 break;
423 default:
424 throw beans::UnknownPropertyException();
431 Any SAL_CALL SdUnoDrawView::getFastPropertyValue (
432 sal_Int32 nHandle)
433 throw(css::beans::UnknownPropertyException,
434 css::lang::WrappedTargetException,
435 css::uno::RuntimeException)
437 Any aValue;
438 switch( nHandle )
440 case DrawController::PROPERTY_CURRENTPAGE:
441 aValue <<= (const_cast<SdUnoDrawView*>(this))->getCurrentPage();
442 break;
444 case DrawController::PROPERTY_MASTERPAGEMODE:
445 aValue <<= getMasterPageMode();
446 break;
448 case DrawController::PROPERTY_LAYERMODE:
449 aValue <<= getLayerMode();
450 break;
452 case DrawController::PROPERTY_ACTIVE_LAYER:
453 aValue <<= (const_cast<SdUnoDrawView*>(this))->getActiveLayer();
454 break;
456 case DrawController::PROPERTY_ZOOMVALUE:
457 aValue <<= GetZoom();
458 break;
459 case DrawController::PROPERTY_ZOOMTYPE:
460 aValue <<= (sal_Int16)com::sun::star::view::DocumentZoomType::BY_VALUE;
461 break;
462 case DrawController::PROPERTY_VIEWOFFSET:
463 aValue <<= GetViewOffset();
464 break;
466 default:
467 throw beans::UnknownPropertyException();
470 return aValue;
476 // XDrawView
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;
486 if(pSdrPage)
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;
508 if(pPage)
509 xPage = Reference< drawing::XDrawPage >::query( pPage->getUnoPage() );
511 return xPage;
515 sal_Int16 SdUnoDrawView::GetZoom(void) const
517 if (mrDrawViewShell.GetActiveWindow() )
519 return (sal_Int16)mrDrawViewShell.GetActiveWindow()->GetZoom();
521 else
523 return 0;
527 void SdUnoDrawView::SetZoom( sal_Int16 nZoom )
529 SvxZoomItem aZoomItem( SVX_ZOOM_PERCENT, nZoom );
531 SfxViewFrame* pViewFrame = mrDrawViewShell.GetViewFrame();
532 if( pViewFrame )
534 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
535 if( pDispatcher )
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
552 Point aRet;
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();
563 if( pViewFrame )
565 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
566 if( pDispatcher )
568 SvxZoomType eZoomType;
569 switch( nType )
571 case com::sun::star::view::DocumentZoomType::OPTIMAL:
572 eZoomType = SVX_ZOOM_OPTIMAL;
573 break;
575 case com::sun::star::view::DocumentZoomType::PAGE_WIDTH:
576 case com::sun::star::view::DocumentZoomType::PAGE_WIDTH_EXACT:
577 eZoomType = SVX_ZOOM_PAGEWIDTH;
578 break;
580 case com::sun::star::view::DocumentZoomType::ENTIRE_PAGE:
581 eZoomType = SVX_ZOOM_WHOLEPAGE;
582 break;
584 default:
585 return;
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);
603 else
604 return NULL;
608 } // end of namespace sd