Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "SdUnoDrawView.hxx"
21 :
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"
31 :
32 : #include <comphelper/processfactory.hxx>
33 : #include <cppuhelper/proptypehlp.hxx>
34 : #include <cppuhelper/supportsservice.hxx>
35 : #include <sfx2/dispatch.hxx>
36 : #include <sfx2/viewfrm.hxx>
37 : #include <svx/svdpagv.hxx>
38 : #include <svx/unoshape.hxx>
39 : #include <sfx2/zoomitem.hxx>
40 : #include <com/sun/star/drawing/DrawViewMode.hpp>
41 : #include <com/sun/star/drawing/ShapeCollection.hpp>
42 : #include <com/sun/star/drawing/XLayerManager.hpp>
43 : #include <com/sun/star/view/DocumentZoomType.hpp>
44 :
45 : #include <vector>
46 :
47 : using namespace ::com::sun::star;
48 : using namespace ::com::sun::star::uno;
49 : using namespace ::com::sun::star::drawing;
50 :
51 : namespace sd {
52 :
53 133 : SdUnoDrawView::SdUnoDrawView(
54 : DrawViewShell& rViewShell,
55 : View& rView) throw()
56 : : DrawSubControllerInterfaceBase(m_aMutex),
57 : mrDrawViewShell(rViewShell),
58 133 : mrView(rView)
59 : {
60 133 : }
61 :
62 266 : SdUnoDrawView::~SdUnoDrawView() throw()
63 : {
64 266 : }
65 :
66 0 : bool SdUnoDrawView::getMasterPageMode() const throw()
67 : {
68 0 : return (mrDrawViewShell.GetEditMode() == EM_MASTERPAGE);
69 : }
70 :
71 5 : void SdUnoDrawView::setMasterPageMode (bool bMasterPageMode) throw()
72 : {
73 5 : if ((mrDrawViewShell.GetEditMode() == EM_MASTERPAGE) != bMasterPageMode)
74 : {
75 : mrDrawViewShell.ChangeEditMode (
76 : bMasterPageMode ? EM_MASTERPAGE : EM_PAGE,
77 0 : mrDrawViewShell.IsLayerModeActive());
78 : }
79 5 : }
80 :
81 0 : bool SdUnoDrawView::getLayerMode() const throw()
82 : {
83 0 : return mrDrawViewShell.IsLayerModeActive();
84 : }
85 :
86 0 : void SdUnoDrawView::setLayerMode (bool bLayerMode) throw()
87 : {
88 0 : if (mrDrawViewShell.IsLayerModeActive() != bLayerMode)
89 : {
90 : mrDrawViewShell.ChangeEditMode (
91 : mrDrawViewShell.GetEditMode(),
92 0 : bLayerMode);
93 : }
94 0 : }
95 :
96 0 : Reference<drawing::XLayer> SdUnoDrawView::getActiveLayer() throw ()
97 : {
98 0 : Reference<drawing::XLayer> xCurrentLayer;
99 :
100 : do
101 : {
102 : // Retrieve the layer manager from the model.
103 0 : SdXImpressDocument* pModel = GetModel();
104 0 : if (pModel == NULL)
105 0 : break;
106 :
107 0 : SdDrawDocument* pSdModel = pModel->GetDoc();
108 0 : if (pSdModel == NULL)
109 0 : break;
110 :
111 : // From the model get the current SdrLayer object via the layer admin.
112 0 : SdrLayerAdmin& rLayerAdmin = pSdModel->GetLayerAdmin ();
113 0 : SdrLayer* pLayer = rLayerAdmin.GetLayer (mrView.GetActiveLayer(), true);
114 0 : if (pLayer == NULL)
115 0 : break;
116 :
117 : // Get the corresponding XLayer object from the implementation
118 : // object of the layer manager.
119 0 : Reference<drawing::XLayerManager> xManager (pModel->getLayerManager(), uno::UNO_QUERY);
120 0 : SdLayerManager* pManager = SdLayerManager::getImplementation (xManager);
121 0 : if (pManager != NULL)
122 0 : xCurrentLayer = pManager->GetLayer (pLayer);
123 : }
124 : while (false);
125 :
126 0 : return xCurrentLayer;
127 : }
128 :
129 0 : void SdUnoDrawView::setActiveLayer (const Reference<drawing::XLayer>& rxLayer)
130 : throw (uno::RuntimeException)
131 : {
132 : // Get the SdrLayer object corresponding to the given reference.
133 0 : if ( ! rxLayer.is())
134 0 : return;
135 :
136 0 : SdLayer* pLayer = SdLayer::getImplementation (rxLayer);
137 0 : if (pLayer == NULL)
138 0 : return;
139 :
140 0 : SdrLayer* pSdrLayer = pLayer->GetSdrLayer();
141 0 : if (pSdrLayer == NULL)
142 0 : return;
143 :
144 : // Set the new active layer and make the change visible.
145 0 : mrView.SetActiveLayer (pSdrLayer->GetName());
146 0 : mrDrawViewShell.ResetActualLayer ();
147 : }
148 :
149 : // XSelectionSupplier
150 :
151 2 : sal_Bool SAL_CALL SdUnoDrawView::select( const Any& aSelection )
152 : throw (lang::IllegalArgumentException,
153 : RuntimeException,
154 : std::exception)
155 : {
156 2 : bool bOk = true;
157 :
158 2 : ::std::vector<SdrObject*> aObjects;
159 :
160 2 : SdrPage* pSdrPage = NULL;
161 :
162 4 : Reference< drawing::XShape > xShape;
163 2 : aSelection >>= xShape;
164 :
165 2 : if(xShape.is())
166 : {
167 0 : SvxShape* pShape = SvxShape::getImplementation( xShape );
168 0 : if( pShape && (pShape->GetSdrObject() != NULL) )
169 : {
170 0 : SdrObject* pObj = pShape->GetSdrObject();
171 0 : pSdrPage = pObj->GetPage();
172 0 : aObjects.push_back( pObj );
173 : }
174 : else
175 : {
176 0 : bOk = false;
177 : }
178 : }
179 : else
180 : {
181 2 : Reference< drawing::XShapes > xShapes;
182 2 : aSelection >>= xShapes;
183 2 : if( xShapes.is() )
184 : {
185 1 : const sal_uInt32 nCount = xShapes->getCount();
186 2 : for( sal_uInt32 i = 0; i < nCount; i++ )
187 : {
188 1 : xShapes->getByIndex(i) >>= xShape;
189 1 : if( xShape.is() )
190 : {
191 1 : SvxShape* pShape = SvxShape::getImplementation(xShape);
192 1 : if( (pShape == NULL) || (pShape->GetSdrObject() == NULL) )
193 : {
194 0 : bOk = false;
195 0 : break;
196 : }
197 :
198 1 : SdrObject* pObj = pShape->GetSdrObject();
199 :
200 1 : if( pSdrPage == NULL )
201 : {
202 1 : pSdrPage = pObj->GetPage();
203 : }
204 0 : else if( pSdrPage != pObj->GetPage() )
205 : {
206 0 : bOk = false;
207 0 : break;
208 : }
209 :
210 1 : aObjects.push_back( pObj );
211 : }
212 : }
213 2 : }
214 : }
215 :
216 2 : if( bOk )
217 : {
218 2 : if( pSdrPage )
219 : {
220 1 : setMasterPageMode( pSdrPage->IsMasterPage() );
221 1 : mrDrawViewShell.SwitchPage( (pSdrPage->GetPageNum() - 1) >> 1 );
222 1 : mrDrawViewShell.WriteFrameViewData();
223 : }
224 :
225 2 : SdrPageView *pPV = mrView.GetSdrPageView();
226 :
227 2 : if(pPV)
228 : {
229 : // first deselect all
230 2 : mrView.UnmarkAllObj( pPV );
231 :
232 2 : ::std::vector<SdrObject*>::iterator aIter( aObjects.begin() );
233 2 : const ::std::vector<SdrObject*>::iterator aEnd( aObjects.end() );
234 5 : while( aIter != aEnd )
235 : {
236 1 : SdrObject* pObj = (*aIter++);
237 1 : mrView.MarkObj( pObj, pPV );
238 : }
239 : }
240 : else
241 : {
242 0 : bOk = false;
243 : }
244 : }
245 :
246 4 : return bOk;
247 : }
248 :
249 9 : Any SAL_CALL SdUnoDrawView::getSelection()
250 : throw (RuntimeException, std::exception)
251 : {
252 9 : Any aAny;
253 :
254 9 : if( mrView.IsTextEdit() )
255 0 : mrView.getTextSelection( aAny );
256 :
257 9 : if( !aAny.hasValue() )
258 : {
259 9 : const SdrMarkList& rMarkList = mrView.GetMarkedObjectList();
260 9 : const size_t nCount = rMarkList.GetMarkCount();
261 9 : if( nCount )
262 : {
263 : Reference< drawing::XShapes > xShapes( drawing::ShapeCollection::create(
264 2 : comphelper::getProcessComponentContext()), UNO_QUERY );
265 4 : for( size_t nNum = 0; nNum < nCount; ++nNum)
266 : {
267 2 : SdrMark *pMark = rMarkList.GetMark(nNum);
268 2 : if(pMark==NULL)
269 0 : continue;
270 :
271 2 : SdrObject *pObj = pMark->GetMarkedSdrObj();
272 2 : if(pObj==NULL || pObj->GetPage() == NULL)
273 0 : continue;
274 :
275 2 : Reference< drawing::XDrawPage > xPage( pObj->GetPage()->getUnoPage(), UNO_QUERY);
276 :
277 2 : if(!xPage.is())
278 0 : continue;
279 :
280 2 : SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xPage );
281 :
282 2 : if(pDrawPage==NULL)
283 0 : continue;
284 :
285 4 : Reference< drawing::XShape > xShape( pObj->getUnoShape(), UNO_QUERY );
286 :
287 2 : if(xShape.is())
288 2 : xShapes->add(xShape);
289 2 : }
290 2 : aAny <<= xShapes;
291 : }
292 : }
293 :
294 9 : return aAny;
295 : }
296 :
297 0 : void SAL_CALL SdUnoDrawView::addSelectionChangeListener (
298 : const css::uno::Reference<css::view::XSelectionChangeListener>& rxListener)
299 : throw(css::uno::RuntimeException, std::exception)
300 : {
301 : (void)rxListener;
302 0 : }
303 :
304 0 : void SAL_CALL SdUnoDrawView::removeSelectionChangeListener (
305 : const css::uno::Reference<css::view::XSelectionChangeListener>& rxListener)
306 : throw(css::uno::RuntimeException, std::exception)
307 : {
308 : (void)rxListener;
309 0 : }
310 :
311 0 : void SdUnoDrawView::setFastPropertyValue (
312 : sal_Int32 nHandle,
313 : const Any& rValue)
314 : throw(css::beans::UnknownPropertyException,
315 : css::beans::PropertyVetoException,
316 : css::lang::IllegalArgumentException,
317 : css::lang::WrappedTargetException,
318 : css::uno::RuntimeException, std::exception)
319 : {
320 0 : switch( nHandle )
321 : {
322 : case DrawController::PROPERTY_CURRENTPAGE:
323 : {
324 0 : Reference< drawing::XDrawPage > xPage;
325 0 : rValue >>= xPage;
326 0 : setCurrentPage( xPage );
327 : }
328 0 : break;
329 :
330 : case DrawController::PROPERTY_MASTERPAGEMODE:
331 : {
332 0 : bool bValue = false;
333 0 : rValue >>= bValue;
334 0 : setMasterPageMode( bValue );
335 : }
336 0 : break;
337 :
338 : case DrawController::PROPERTY_LAYERMODE:
339 : {
340 0 : bool bValue = false;
341 0 : rValue >>= bValue;
342 0 : setLayerMode( bValue );
343 : }
344 0 : break;
345 : case DrawController::PROPERTY_ACTIVE_LAYER:
346 : {
347 0 : Reference<drawing::XLayer> xLayer;
348 0 : rValue >>= xLayer;
349 0 : setActiveLayer (xLayer);
350 : }
351 0 : break;
352 : case DrawController::PROPERTY_ZOOMVALUE:
353 : {
354 0 : sal_Int16 nZoom = 0;
355 0 : rValue >>= nZoom;
356 0 : SetZoom( nZoom );
357 : }
358 0 : break;
359 : case DrawController::PROPERTY_ZOOMTYPE:
360 : {
361 0 : sal_Int16 nType = 0;
362 0 : rValue >>= nType;
363 0 : SetZoomType( nType );
364 : }
365 0 : break;
366 : case DrawController::PROPERTY_VIEWOFFSET:
367 : {
368 0 : awt::Point aOffset;
369 0 : rValue >>= aOffset;
370 0 : SetViewOffset( aOffset );
371 : }
372 0 : break;
373 : default:
374 0 : throw beans::UnknownPropertyException();
375 : }
376 0 : }
377 :
378 0 : Any SAL_CALL SdUnoDrawView::getFastPropertyValue (
379 : sal_Int32 nHandle)
380 : throw(css::beans::UnknownPropertyException,
381 : css::lang::WrappedTargetException,
382 : css::uno::RuntimeException, std::exception)
383 : {
384 0 : Any aValue;
385 0 : switch( nHandle )
386 : {
387 : case DrawController::PROPERTY_CURRENTPAGE:
388 0 : aValue <<= getCurrentPage();
389 0 : break;
390 :
391 : case DrawController::PROPERTY_MASTERPAGEMODE:
392 0 : aValue <<= getMasterPageMode();
393 0 : break;
394 :
395 : case DrawController::PROPERTY_LAYERMODE:
396 0 : aValue <<= getLayerMode();
397 0 : break;
398 :
399 : case DrawController::PROPERTY_ACTIVE_LAYER:
400 0 : aValue <<= getActiveLayer();
401 0 : break;
402 :
403 : case DrawController::PROPERTY_ZOOMVALUE:
404 0 : aValue <<= GetZoom();
405 0 : break;
406 : case DrawController::PROPERTY_ZOOMTYPE:
407 0 : aValue <<= (sal_Int16)com::sun::star::view::DocumentZoomType::BY_VALUE;
408 0 : break;
409 : case DrawController::PROPERTY_VIEWOFFSET:
410 0 : aValue <<= GetViewOffset();
411 0 : break;
412 :
413 : case DrawController::PROPERTY_DRAWVIEWMODE:
414 0 : aValue = getDrawViewMode();
415 0 : break;
416 :
417 : default:
418 0 : throw beans::UnknownPropertyException();
419 : }
420 :
421 0 : return aValue;
422 : }
423 :
424 : // XDrawView
425 :
426 4 : void SAL_CALL SdUnoDrawView::setCurrentPage (
427 : const Reference< drawing::XDrawPage >& xPage )
428 : throw (RuntimeException, std::exception)
429 : {
430 4 : SvxDrawPage* pDrawPage = SvxDrawPage::getImplementation( xPage );
431 4 : SdrPage *pSdrPage = pDrawPage ? pDrawPage->GetSdrPage() : NULL;
432 :
433 4 : if(pSdrPage)
434 : {
435 : // End editing of text. Otherwise the edited text object would
436 : // still be visible on the new page.
437 4 : mrDrawViewShell.GetView()->SdrEndTextEdit();
438 :
439 4 : setMasterPageMode( pSdrPage->IsMasterPage() );
440 4 : mrDrawViewShell.SwitchPage( (pSdrPage->GetPageNum() - 1) >> 1 );
441 4 : mrDrawViewShell.WriteFrameViewData();
442 : }
443 4 : }
444 :
445 220 : Reference< drawing::XDrawPage > SAL_CALL SdUnoDrawView::getCurrentPage()
446 : throw(RuntimeException, std::exception)
447 : {
448 220 : Reference< drawing::XDrawPage > xPage;
449 :
450 220 : SdrPageView *pPV = mrView.GetSdrPageView();
451 220 : SdrPage* pPage = pPV ? pPV->GetPage() : NULL;
452 :
453 220 : if(pPage)
454 220 : xPage = Reference< drawing::XDrawPage >::query( pPage->getUnoPage() );
455 :
456 220 : return xPage;
457 : }
458 :
459 0 : sal_Int16 SdUnoDrawView::GetZoom() const
460 : {
461 0 : if (mrDrawViewShell.GetActiveWindow() )
462 : {
463 0 : return (sal_Int16)mrDrawViewShell.GetActiveWindow()->GetZoom();
464 : }
465 : else
466 : {
467 0 : return 0;
468 : }
469 : }
470 :
471 0 : void SdUnoDrawView::SetZoom( sal_Int16 nZoom )
472 : {
473 0 : SvxZoomItem aZoomItem( SvxZoomType::PERCENT, nZoom );
474 :
475 0 : SfxViewFrame* pViewFrame = mrDrawViewShell.GetViewFrame();
476 0 : if( pViewFrame )
477 : {
478 0 : SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
479 0 : if( pDispatcher )
480 : {
481 0 : pDispatcher->Execute(SID_ATTR_ZOOM,SfxCallMode::SYNCHRON,&aZoomItem, 0L);
482 : }
483 0 : }
484 0 : }
485 :
486 0 : void SdUnoDrawView::SetViewOffset(const awt::Point& rWinPos )
487 : {
488 0 : Point aWinPos( rWinPos.X, rWinPos.Y );
489 0 : aWinPos += mrDrawViewShell.GetViewOrigin();
490 0 : mrDrawViewShell.SetWinViewPos( aWinPos, true );
491 0 : }
492 :
493 0 : awt::Point SdUnoDrawView::GetViewOffset() const
494 : {
495 0 : Point aRet;
496 :
497 0 : aRet = mrDrawViewShell.GetWinViewPos();
498 0 : aRet -= mrDrawViewShell.GetViewOrigin();
499 :
500 0 : return awt::Point( aRet.X(), aRet.Y() );
501 : }
502 :
503 0 : void SdUnoDrawView::SetZoomType ( sal_Int16 nType )
504 : {
505 0 : SfxViewFrame* pViewFrame = mrDrawViewShell.GetViewFrame();
506 0 : if( pViewFrame )
507 : {
508 0 : SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
509 0 : if( pDispatcher )
510 : {
511 : SvxZoomType eZoomType;
512 0 : switch( nType )
513 : {
514 : case com::sun::star::view::DocumentZoomType::OPTIMAL:
515 0 : eZoomType = SvxZoomType::OPTIMAL;
516 0 : break;
517 :
518 : case com::sun::star::view::DocumentZoomType::PAGE_WIDTH:
519 : case com::sun::star::view::DocumentZoomType::PAGE_WIDTH_EXACT:
520 0 : eZoomType = SvxZoomType::PAGEWIDTH;
521 0 : break;
522 :
523 : case com::sun::star::view::DocumentZoomType::ENTIRE_PAGE:
524 0 : eZoomType = SvxZoomType::WHOLEPAGE;
525 0 : break;
526 :
527 : default:
528 0 : return;
529 : }
530 0 : SvxZoomItem aZoomItem( eZoomType );
531 0 : pDispatcher->Execute(SID_ATTR_ZOOM,SfxCallMode::SYNCHRON,&aZoomItem, 0L);
532 : }
533 : }
534 : }
535 :
536 0 : SdXImpressDocument* SdUnoDrawView::GetModel() const throw()
537 : {
538 0 : if (mrView.GetDocSh()!=NULL)
539 : {
540 0 : Reference<frame::XModel> xModel (mrView.GetDocSh()->GetModel());
541 0 : return SdXImpressDocument::getImplementation(xModel);
542 : }
543 : else
544 0 : return NULL;
545 : }
546 :
547 0 : Any SdUnoDrawView::getDrawViewMode() const
548 : {
549 0 : Any aRet;
550 0 : switch( mrDrawViewShell.GetPageKind() )
551 : {
552 0 : case PK_NOTES: aRet <<= DrawViewMode_NOTES; break;
553 0 : case PK_HANDOUT: aRet <<= DrawViewMode_HANDOUT; break;
554 0 : case PK_STANDARD: aRet <<= DrawViewMode_DRAW; break;
555 : }
556 0 : return aRet;
557 : }
558 :
559 : // XServiceInfo
560 0 : OUString SAL_CALL SdUnoDrawView::getImplementationName( ) throw (RuntimeException, std::exception)
561 : {
562 0 : return OUString( "com.sun.star.comp.sd.SdUnoDrawView") ;
563 : }
564 :
565 0 : sal_Bool SAL_CALL SdUnoDrawView::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
566 : {
567 0 : return cppu::supportsService( this, ServiceName );
568 : }
569 :
570 0 : Sequence< OUString > SAL_CALL SdUnoDrawView::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
571 : {
572 0 : OUString aSN("com.sun.star.drawing.DrawingDocumentDrawView");
573 0 : uno::Sequence< OUString > aSeq( &aSN, 1 );
574 0 : return aSeq;
575 : }
576 :
577 66 : } // end of namespace sd
578 :
579 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|