bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / unoidl / SdUnoDrawView.cxx
blobdb9f7a46586480f3fc536f405414a3e7f5fd918d
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 .
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>
29 #include <Window.hxx>
30 #include <pres.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>
44 #include <vector>
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::drawing;
50 namespace sd {
52 SdUnoDrawView::SdUnoDrawView(
53 DrawViewShell& rViewShell,
54 View& rView) throw()
55 : DrawSubControllerInterfaceBase(m_aMutex),
56 mrDrawViewShell(rViewShell),
57 mrView(rView)
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(),
91 bLayerMode);
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)
104 break;
106 SdDrawDocument* pSdModel = pModel->GetDoc();
107 if (pSdModel == nullptr)
108 break;
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)
114 break;
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);
123 while (false);
125 return xCurrentLayer;
128 void SdUnoDrawView::setActiveLayer (const Reference<drawing::XLayer>& rxLayer)
130 // Get the SdrLayer object corresponding to the given reference.
131 if ( ! rxLayer.is())
132 return;
134 SdLayer* pLayer = SdLayer::getImplementation (rxLayer);
135 if (pLayer == nullptr)
136 return;
138 SdrLayer* pSdrLayer = pLayer->GetSdrLayer();
139 if (pSdrLayer == nullptr)
140 return;
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 )
151 bool bOk = true;
153 ::std::vector<SdrObject*> aObjects;
155 SdrPage* pSdrPage = nullptr;
157 Reference< drawing::XShape > xShape;
158 aSelection >>= xShape;
160 if(xShape.is())
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 );
169 else
171 bOk = false;
174 else
176 Reference< drawing::XShapes > xShapes;
177 aSelection >>= xShapes;
178 if( xShapes.is() )
180 const sal_uInt32 nCount = xShapes->getCount();
181 for( sal_uInt32 i = 0; i < nCount; i++ )
183 xShapes->getByIndex(i) >>= xShape;
184 if( xShape.is() )
186 SvxShape* pShape = SvxShape::getImplementation(xShape);
187 if( (pShape == nullptr) || (pShape->GetSdrObject() == nullptr) )
189 bOk = false;
190 break;
193 SdrObject* pObj = pShape->GetSdrObject();
195 if( pSdrPage == nullptr )
197 pSdrPage = pObj->getSdrPageFromSdrObject();
199 else if( pSdrPage != pObj->getSdrPageFromSdrObject() )
201 bOk = false;
202 break;
205 aObjects.push_back( pObj );
211 if( bOk )
213 if( pSdrPage )
215 setMasterPageMode( pSdrPage->IsMasterPage() );
216 mrDrawViewShell.SwitchPage( (pSdrPage->GetPageNum() - 1) >> 1 );
217 mrDrawViewShell.WriteFrameViewData();
220 SdrPageView *pPV = mrView.GetSdrPageView();
222 if(pPV)
224 // first deselect all
225 mrView.UnmarkAllObj( pPV );
227 for( SdrObject* pObj : aObjects )
229 mrView.MarkObj( pObj, pPV );
232 else
234 bOk = false;
238 return bOk;
241 Any SAL_CALL SdUnoDrawView::getSelection()
243 Any aAny;
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();
252 if( nCount )
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);
259 if(pMark==nullptr)
260 continue;
262 SdrObject *pObj = pMark->GetMarkedSdrObj();
263 if(pObj==nullptr || pObj->getSdrPageFromSdrObject() == nullptr)
264 continue;
266 Reference< drawing::XDrawPage > xPage( pObj->getSdrPageFromSdrObject()->getUnoPage(), UNO_QUERY);
268 if(!xPage.is())
269 continue;
271 SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xPage );
273 if(pDrawPage==nullptr)
274 continue;
276 Reference< drawing::XShape > xShape( pObj->getUnoShape(), UNO_QUERY );
278 if(xShape.is())
279 xShapes->add(xShape);
281 aAny <<= xShapes;
285 return aAny;
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 (
297 sal_Int32 nHandle,
298 const Any& rValue)
300 switch( nHandle )
302 case DrawController::PROPERTY_CURRENTPAGE:
304 Reference< drawing::XDrawPage > xPage;
305 rValue >>= xPage;
306 setCurrentPage( xPage );
308 break;
310 case DrawController::PROPERTY_MASTERPAGEMODE:
312 bool bValue = false;
313 rValue >>= bValue;
314 setMasterPageMode( bValue );
316 break;
318 case DrawController::PROPERTY_LAYERMODE:
320 bool bValue = false;
321 rValue >>= bValue;
322 setLayerMode( bValue );
324 break;
325 case DrawController::PROPERTY_ACTIVE_LAYER:
327 Reference<drawing::XLayer> xLayer;
328 rValue >>= xLayer;
329 setActiveLayer (xLayer);
331 break;
332 case DrawController::PROPERTY_ZOOMVALUE:
334 sal_Int16 nZoom = 0;
335 rValue >>= nZoom;
336 SetZoom( nZoom );
338 break;
339 case DrawController::PROPERTY_ZOOMTYPE:
341 sal_Int16 nType = 0;
342 rValue >>= nType;
343 SetZoomType( nType );
345 break;
346 case DrawController::PROPERTY_VIEWOFFSET:
348 awt::Point aOffset;
349 rValue >>= aOffset;
350 SetViewOffset( aOffset );
352 break;
353 default:
354 throw beans::UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
358 Any SAL_CALL SdUnoDrawView::getFastPropertyValue (
359 sal_Int32 nHandle)
361 Any aValue;
362 switch( nHandle )
364 case DrawController::PROPERTY_CURRENTPAGE:
365 aValue <<= getCurrentPage();
366 break;
368 case DrawController::PROPERTY_MASTERPAGEMODE:
369 aValue <<= getMasterPageMode();
370 break;
372 case DrawController::PROPERTY_LAYERMODE:
373 aValue <<= getLayerMode();
374 break;
376 case DrawController::PROPERTY_ACTIVE_LAYER:
377 aValue <<= getActiveLayer();
378 break;
380 case DrawController::PROPERTY_ZOOMVALUE:
381 aValue <<= GetZoom();
382 break;
383 case DrawController::PROPERTY_ZOOMTYPE:
384 aValue <<= sal_Int16(css::view::DocumentZoomType::BY_VALUE);
385 break;
386 case DrawController::PROPERTY_VIEWOFFSET:
387 aValue <<= GetViewOffset();
388 break;
390 case DrawController::PROPERTY_DRAWVIEWMODE:
391 aValue = getDrawViewMode();
392 break;
394 default:
395 throw beans::UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
398 return aValue;
401 // XDrawView
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;
409 if(pSdrPage)
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;
428 if(pPage)
429 xPage.set( pPage->getUnoPage(), UNO_QUERY );
431 return xPage;
434 sal_Int16 SdUnoDrawView::GetZoom() const
436 if (mrDrawViewShell.GetActiveWindow() )
438 return static_cast<sal_Int16>(mrDrawViewShell.GetActiveWindow()->GetZoom());
440 else
442 return 0;
446 void SdUnoDrawView::SetZoom( sal_Int16 nZoom )
448 SvxZoomItem aZoomItem( SvxZoomType::PERCENT, nZoom );
450 SfxViewFrame* pViewFrame = mrDrawViewShell.GetViewFrame();
451 if( pViewFrame )
453 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
454 if( pDispatcher )
456 pDispatcher->ExecuteList(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON,
457 { &aZoomItem });
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();
480 if( !pViewFrame )
481 return;
483 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
484 if( !pDispatcher )
485 return;
487 SvxZoomType eZoomType;
488 switch( nType )
490 case css::view::DocumentZoomType::OPTIMAL:
491 eZoomType = SvxZoomType::OPTIMAL;
492 break;
494 case css::view::DocumentZoomType::PAGE_WIDTH:
495 case css::view::DocumentZoomType::PAGE_WIDTH_EXACT:
496 eZoomType = SvxZoomType::PAGEWIDTH;
497 break;
499 case css::view::DocumentZoomType::ENTIRE_PAGE:
500 eZoomType = SvxZoomType::WHOLEPAGE;
501 break;
503 default:
504 return;
506 SvxZoomItem aZoomItem( eZoomType );
507 pDispatcher->ExecuteList(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON,
508 { &aZoomItem });
511 SdXImpressDocument* SdUnoDrawView::GetModel() const throw()
513 if (mrView.GetDocSh()!=nullptr)
515 Reference<frame::XModel> xModel (mrView.GetDocSh()->GetModel());
516 return SdXImpressDocument::getImplementation(xModel);
518 else
519 return nullptr;
522 Any SdUnoDrawView::getDrawViewMode() const
524 Any aRet;
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;
531 return aRet;
534 // XServiceInfo
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 );
549 return aSeq;
552 } // end of namespace sd
554 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */