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