bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / unoidl / SdUnoDrawView.cxx
blobec0a54c17b7c47cfef6418995fdc3b9a63d8d00c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
30 #include "Window.hxx"
31 #include "pres.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>
45 #include <vector>
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::drawing;
53 namespace sd {
55 SdUnoDrawView::SdUnoDrawView(
56 DrawViewShell& rViewShell,
57 View& rView) throw()
58 : DrawSubControllerInterfaceBase(m_aMutex),
59 mrDrawViewShell(rViewShell),
60 mrView(rView)
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(),
109 bLayerMode);
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();
124 if (pModel == NULL)
125 break;
127 SdDrawDocument* pSdModel = pModel->GetDoc();
128 if (pSdModel == NULL)
129 break;
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);
134 if (pLayer == NULL)
135 break;
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);
144 while (false);
146 return xCurrentLayer;
152 void SdUnoDrawView::setActiveLayer (const Reference<drawing::XLayer>& rxLayer) throw ()
154 // Get the SdrLayer object corresponding to the given reference.
155 if ( ! rxLayer.is())
156 return;
158 SdLayer* pLayer = SdLayer::getImplementation (rxLayer);
159 if (pLayer == NULL)
160 return;
162 SdrLayer* pSdrLayer = pLayer->GetSdrLayer();
163 if (pSdrLayer == NULL)
164 return;
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)
180 bool bOk = true;
182 ::std::vector<SdrObject*> aObjects;
184 SdrPage* pSdrPage = NULL;
186 Reference< drawing::XShape > xShape;
187 aSelection >>= xShape;
189 if(xShape.is())
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 );
198 else
200 bOk = false;
203 else
205 Reference< drawing::XShapes > xShapes;
206 aSelection >>= xShapes;
207 if( xShapes.is() )
209 const sal_uInt32 nCount = xShapes->getCount();
210 for( sal_uInt32 i = 0; i < nCount; i++ )
212 xShapes->getByIndex(i) >>= xShape;
213 if( xShape.is() )
215 SvxShape* pShape = SvxShape::getImplementation(xShape);
216 if( (pShape == NULL) || (pShape->GetSdrObject() == NULL) )
218 bOk = false;
219 break;
222 SdrObject* pObj = pShape->GetSdrObject();
224 if( pSdrPage == NULL )
226 pSdrPage = pObj->GetPage();
228 else if( pSdrPage != pObj->GetPage() )
230 bOk = false;
231 break;
234 aObjects.push_back( pObj );
240 if( bOk )
242 if( pSdrPage )
244 setMasterPageMode( pSdrPage->IsMasterPage() );
245 mrDrawViewShell.SwitchPage( (pSdrPage->GetPageNum() - 1) >> 1 );
246 mrDrawViewShell.WriteFrameViewData();
249 SdrPageView *pPV = mrView.GetSdrPageView();
251 if(pPV)
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 );
264 else
266 bOk = false;
270 return bOk;
273 //----------------------------------------------------------------------
275 Any SAL_CALL SdUnoDrawView::getSelection()
276 throw(RuntimeException)
278 Any aAny;
280 if( mrView.IsTextEdit() )
281 mrView.getTextSelection( aAny );
284 if( !aAny.hasValue() )
286 const SdrMarkList& rMarkList = mrView.GetMarkedObjectList();
287 sal_uInt32 nCount = rMarkList.GetMarkCount();
288 if( nCount )
290 Reference< drawing::XShapes > xShapes( SvxShapeCollection_NewInstance(), UNO_QUERY );
291 for( sal_uInt32 nNum = 0; nNum < nCount; nNum++)
293 SdrMark *pMark = rMarkList.GetMark(nNum);
294 if(pMark==NULL)
295 continue;
297 SdrObject *pObj = pMark->GetMarkedSdrObj();
298 if(pObj==NULL || pObj->GetPage() == NULL)
299 continue;
301 Reference< drawing::XDrawPage > xPage( pObj->GetPage()->getUnoPage(), UNO_QUERY);
303 if(!xPage.is())
304 continue;
306 SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xPage );
308 if(pDrawPage==NULL)
309 continue;
311 Reference< drawing::XShape > xShape( pObj->getUnoShape(), UNO_QUERY );
313 if(xShape.is())
314 xShapes->add(xShape);
316 aAny <<= xShapes;
320 return aAny;
326 void SAL_CALL SdUnoDrawView::addSelectionChangeListener (
327 const css::uno::Reference<css::view::XSelectionChangeListener>& rxListener)
328 throw(css::uno::RuntimeException)
330 (void)rxListener;
336 void SAL_CALL SdUnoDrawView::removeSelectionChangeListener (
337 const css::uno::Reference<css::view::XSelectionChangeListener>& rxListener)
338 throw(css::uno::RuntimeException)
340 (void)rxListener;
346 void SdUnoDrawView::setFastPropertyValue (
347 sal_Int32 nHandle,
348 const Any& rValue)
349 throw(css::beans::UnknownPropertyException,
350 css::beans::PropertyVetoException,
351 css::lang::IllegalArgumentException,
352 css::lang::WrappedTargetException,
353 css::uno::RuntimeException)
355 switch( nHandle )
357 case DrawController::PROPERTY_CURRENTPAGE:
359 Reference< drawing::XDrawPage > xPage;
360 rValue >>= xPage;
361 setCurrentPage( xPage );
363 break;
365 case DrawController::PROPERTY_MASTERPAGEMODE:
367 sal_Bool bValue = sal_False;
368 rValue >>= bValue;
369 setMasterPageMode( bValue );
371 break;
373 case DrawController::PROPERTY_LAYERMODE:
375 sal_Bool bValue = sal_False;
376 rValue >>= bValue;
377 setLayerMode( bValue );
380 case DrawController::PROPERTY_ACTIVE_LAYER:
382 Reference<drawing::XLayer> xLayer;
383 rValue >>= xLayer;
384 setActiveLayer (xLayer);
386 break;
387 case DrawController::PROPERTY_ZOOMVALUE:
389 sal_Int16 nZoom = 0;
390 rValue >>= nZoom;
391 SetZoom( nZoom );
393 break;
394 case DrawController::PROPERTY_ZOOMTYPE:
396 sal_Int16 nType = 0;
397 rValue >>= nType;
398 SetZoomType( nType );
400 break;
401 case DrawController::PROPERTY_VIEWOFFSET:
403 awt::Point aOffset;
404 rValue >>= aOffset;
405 SetViewOffset( aOffset );
407 break;
408 default:
409 throw beans::UnknownPropertyException();
416 Any SAL_CALL SdUnoDrawView::getFastPropertyValue (
417 sal_Int32 nHandle)
418 throw(css::beans::UnknownPropertyException,
419 css::lang::WrappedTargetException,
420 css::uno::RuntimeException)
422 Any aValue;
423 switch( nHandle )
425 case DrawController::PROPERTY_CURRENTPAGE:
426 aValue <<= (const_cast<SdUnoDrawView*>(this))->getCurrentPage();
427 break;
429 case DrawController::PROPERTY_MASTERPAGEMODE:
430 aValue <<= getMasterPageMode();
431 break;
433 case DrawController::PROPERTY_LAYERMODE:
434 aValue <<= getLayerMode();
435 break;
437 case DrawController::PROPERTY_ACTIVE_LAYER:
438 aValue <<= (const_cast<SdUnoDrawView*>(this))->getActiveLayer();
439 break;
441 case DrawController::PROPERTY_ZOOMVALUE:
442 aValue <<= GetZoom();
443 break;
444 case DrawController::PROPERTY_ZOOMTYPE:
445 aValue <<= (sal_Int16)com::sun::star::view::DocumentZoomType::BY_VALUE;
446 break;
447 case DrawController::PROPERTY_VIEWOFFSET:
448 aValue <<= GetViewOffset();
449 break;
451 case DrawController::PROPERTY_DRAWVIEWMODE:
452 aValue = getDrawViewMode();
453 break;
455 default:
456 throw beans::UnknownPropertyException();
459 return aValue;
465 // XDrawView
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;
475 if(pSdrPage)
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;
497 if(pPage)
498 xPage = Reference< drawing::XDrawPage >::query( pPage->getUnoPage() );
500 return xPage;
504 sal_Int16 SdUnoDrawView::GetZoom(void) const
506 if (mrDrawViewShell.GetActiveWindow() )
508 return (sal_Int16)mrDrawViewShell.GetActiveWindow()->GetZoom();
510 else
512 return 0;
516 void SdUnoDrawView::SetZoom( sal_Int16 nZoom )
518 SvxZoomItem aZoomItem( SVX_ZOOM_PERCENT, nZoom );
520 SfxViewFrame* pViewFrame = mrDrawViewShell.GetViewFrame();
521 if( pViewFrame )
523 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
524 if( pDispatcher )
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
541 Point aRet;
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();
552 if( pViewFrame )
554 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
555 if( pDispatcher )
557 SvxZoomType eZoomType;
558 switch( nType )
560 case com::sun::star::view::DocumentZoomType::OPTIMAL:
561 eZoomType = SVX_ZOOM_OPTIMAL;
562 break;
564 case com::sun::star::view::DocumentZoomType::PAGE_WIDTH:
565 case com::sun::star::view::DocumentZoomType::PAGE_WIDTH_EXACT:
566 eZoomType = SVX_ZOOM_PAGEWIDTH;
567 break;
569 case com::sun::star::view::DocumentZoomType::ENTIRE_PAGE:
570 eZoomType = SVX_ZOOM_WHOLEPAGE;
571 break;
573 default:
574 return;
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);
592 else
593 return NULL;
596 Any SdUnoDrawView::getDrawViewMode() const
598 Any aRet;
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;
605 return aRet;
608 // XServiceInfo
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 );
623 return aSeq;
626 } // end of namespace sd
628 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */