Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / unoobj / viewuno.cxx
blobea7bb416bdb41e045036793b426853693aaf2944
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 <com/sun/star/awt/MouseButton.hpp>
22 #include <com/sun/star/script/vba/VBAEventId.hpp>
23 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
24 #include <com/sun/star/view/DocumentZoomType.hpp>
26 #include <editeng/outliner.hxx>
27 #include <svx/fmdpage.hxx>
28 #include <svx/svditer.hxx>
29 #include <svx/svdmark.hxx>
30 #include <svx/svdouno.hxx>
31 #include <svx/svdpage.hxx>
32 #include <svx/svdpagv.hxx>
33 #include <svx/svdview.hxx>
34 #include <svx/unoshape.hxx>
35 #include <svx/unoshcol.hxx>
36 #include <svx/fmshell.hxx>
37 #include <sfx2/bindings.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/printer.hxx>
40 #include <sfx2/request.hxx>
41 #include <sfx2/viewfrm.hxx>
42 #include <comphelper/servicehelper.hxx>
43 #include <toolkit/helper/convert.hxx>
44 #include <vcl/svapp.hxx>
46 #include "drawsh.hxx"
47 #include "drtxtob.hxx"
48 #include "transobj.hxx"
49 #include "editsh.hxx"
50 #include "viewuno.hxx"
51 #include "cellsuno.hxx"
52 #include "miscuno.hxx"
53 #include "tabvwsh.hxx"
54 #include "prevwsh.hxx"
55 #include "docsh.hxx"
56 #include "drwlayer.hxx"
57 #include "drawview.hxx"
58 #include "fupoor.hxx"
59 #include "sc.hrc"
60 #include "unonames.hxx"
61 #include "scmod.hxx"
62 #include "appoptio.hxx"
63 #include "gridwin.hxx"
64 #include "sheetevents.hxx"
65 #include "markdata.hxx"
66 #include "AccessibilityHints.hxx"
67 #include "scextopt.hxx"
68 #include "preview.hxx"
69 #include <svx/sdrhittesthelper.hxx>
70 #include <boost/foreach.hpp>
71 #include "formatsh.hxx"
72 #include "sfx2/app.hxx"
74 using namespace com::sun::star;
76 //------------------------------------------------------------------------
78 //! Clipping-Markierungen
80 // alles ohne Which-ID, Map nur fuer PropertySetInfo
82 static const SfxItemPropertyMapEntry* lcl_GetViewOptPropertyMap()
84 static const SfxItemPropertyMapEntry aViewOptPropertyMap_Impl[] =
86 {MAP_CHAR_LEN(OLD_UNO_COLROWHDR), 0, &getBooleanCppuType(), 0, 0},
87 {MAP_CHAR_LEN(SC_UNO_GRIDCOLOR), 0, &getCppuType((sal_Int32*)0), 0, 0},
88 {MAP_CHAR_LEN(SC_UNO_COLROWHDR), 0, &getBooleanCppuType(), 0, 0},
89 {MAP_CHAR_LEN(SC_UNO_HORSCROLL), 0, &getBooleanCppuType(), 0, 0},
90 {MAP_CHAR_LEN(SC_UNO_SHEETTABS), 0, &getBooleanCppuType(), 0, 0},
91 {MAP_CHAR_LEN(SC_UNO_VERTSCROLL), 0, &getBooleanCppuType(), 0, 0},
92 {MAP_CHAR_LEN(SC_UNO_HIDESPELL), 0, &getBooleanCppuType(), 0, 0}, /* deprecated #i91949 */
93 {MAP_CHAR_LEN(OLD_UNO_HORSCROLL), 0, &getBooleanCppuType(), 0, 0},
94 {MAP_CHAR_LEN(SC_UNO_OUTLSYMB), 0, &getBooleanCppuType(), 0, 0},
95 {MAP_CHAR_LEN(SC_UNO_VALUEHIGH), 0, &getBooleanCppuType(), 0, 0},
96 {MAP_CHAR_LEN(OLD_UNO_OUTLSYMB), 0, &getBooleanCppuType(), 0, 0},
97 {MAP_CHAR_LEN(OLD_UNO_SHEETTABS), 0, &getBooleanCppuType(), 0, 0},
98 {MAP_CHAR_LEN(SC_UNO_SHOWANCHOR), 0, &getBooleanCppuType(), 0, 0},
99 {MAP_CHAR_LEN(SC_UNO_SHOWCHARTS), 0, &getCppuType((sal_Int16*)0), 0, 0},
100 {MAP_CHAR_LEN(SC_UNO_SHOWDRAW), 0, &getCppuType((sal_Int16*)0), 0, 0},
101 {MAP_CHAR_LEN(SC_UNO_SHOWFORM), 0, &getBooleanCppuType(), 0, 0},
102 {MAP_CHAR_LEN(SC_UNO_SHOWGRID), 0, &getBooleanCppuType(), 0, 0},
103 {MAP_CHAR_LEN(SC_UNO_SHOWHELP), 0, &getBooleanCppuType(), 0, 0},
104 {MAP_CHAR_LEN(SC_UNO_SHOWNOTES), 0, &getBooleanCppuType(), 0, 0},
105 {MAP_CHAR_LEN(SC_UNO_SHOWOBJ), 0, &getCppuType((sal_Int16*)0), 0, 0},
106 {MAP_CHAR_LEN(SC_UNO_SHOWPAGEBR), 0, &getBooleanCppuType(), 0, 0},
107 {MAP_CHAR_LEN(SC_UNO_SHOWZERO), 0, &getBooleanCppuType(), 0, 0},
108 {MAP_CHAR_LEN(OLD_UNO_VALUEHIGH), 0, &getBooleanCppuType(), 0, 0},
109 {MAP_CHAR_LEN(OLD_UNO_VERTSCROLL), 0, &getBooleanCppuType(), 0, 0},
110 {MAP_CHAR_LEN(SC_UNO_VISAREA), 0, &getCppuType((awt::Rectangle*)0), 0, 0},
111 {MAP_CHAR_LEN(SC_UNO_ZOOMTYPE), 0, &getCppuType((sal_Int16*)0), 0, 0},
112 {MAP_CHAR_LEN(SC_UNO_ZOOMVALUE), 0, &getCppuType((sal_Int16*)0), 0, 0},
113 {MAP_CHAR_LEN(SC_UNO_VISAREASCREEN),0, &getCppuType((awt::Rectangle*)0), 0, 0},
114 {0,0,0,0,0,0}
116 return aViewOptPropertyMap_Impl;
119 //------------------------------------------------------------------------
121 #define SCTABVIEWOBJ_SERVICE "com.sun.star.sheet.SpreadsheetView"
122 #define SCVIEWSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetViewSettings"
124 SC_SIMPLE_SERVICE_INFO( ScViewPaneBase, "ScViewPaneObj", "com.sun.star.sheet.SpreadsheetViewPane" )
126 //------------------------------------------------------------------------
128 ScViewPaneBase::ScViewPaneBase(ScTabViewShell* pViewSh, sal_uInt16 nP) :
129 pViewShell( pViewSh ),
130 nPane( nP )
132 if (pViewShell)
133 StartListening(*pViewShell);
136 ScViewPaneBase::~ScViewPaneBase()
138 if (pViewShell)
139 EndListening(*pViewShell);
142 void ScViewPaneBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
144 if ( rHint.ISA( SfxSimpleHint ) &&
145 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
146 pViewShell = NULL;
149 uno::Any SAL_CALL ScViewPaneBase::queryInterface( const uno::Type& rType )
150 throw(uno::RuntimeException)
152 SC_QUERYINTERFACE( sheet::XViewPane )
153 SC_QUERYINTERFACE( sheet::XCellRangeReferrer )
154 SC_QUERYINTERFACE( view::XFormLayerAccess )
155 SC_QUERYINTERFACE( view::XControlAccess )
156 SC_QUERYINTERFACE( lang::XServiceInfo )
157 SC_QUERYINTERFACE( lang::XTypeProvider )
159 return uno::Any(); // OWeakObject is in derived objects
162 uno::Sequence<uno::Type> SAL_CALL ScViewPaneBase::getTypes() throw(uno::RuntimeException)
164 static uno::Sequence<uno::Type> aTypes;
165 if ( aTypes.getLength() == 0 )
167 aTypes.realloc(5);
168 uno::Type* pPtr = aTypes.getArray();
169 pPtr[0] = getCppuType((const uno::Reference<sheet::XViewPane>*)0);
170 pPtr[1] = getCppuType((const uno::Reference<sheet::XCellRangeReferrer>*)0);
171 pPtr[2] = getCppuType((const uno::Reference<view::XFormLayerAccess>*)0);
172 pPtr[3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
173 pPtr[4] = getCppuType((const uno::Reference<lang::XTypeProvider>*)0);
175 return aTypes;
178 namespace
180 class theScViewPaneBaseImplementationId : public rtl::Static< UnoTunnelIdInit, theScViewPaneBaseImplementationId > {};
183 uno::Sequence<sal_Int8> SAL_CALL ScViewPaneBase::getImplementationId()
184 throw(uno::RuntimeException)
186 return theScViewPaneBaseImplementationId::get().getSeq();
189 // XViewPane
191 sal_Int32 SAL_CALL ScViewPaneBase::getFirstVisibleColumn() throw(uno::RuntimeException)
193 SolarMutexGuard aGuard;
194 if (pViewShell)
196 ScViewData* pViewData = pViewShell->GetViewData();
197 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
198 pViewData->GetActivePart() :
199 (ScSplitPos) nPane;
200 ScHSplitPos eWhichH = WhichH( eWhich );
202 return pViewData->GetPosX( eWhichH );
204 OSL_FAIL("keine View ?!?"); //! Exception?
205 return 0;
208 void SAL_CALL ScViewPaneBase::setFirstVisibleColumn( sal_Int32 nFirstVisibleColumn )
209 throw(uno::RuntimeException)
211 SolarMutexGuard aGuard;
212 if (pViewShell)
214 ScViewData* pViewData = pViewShell->GetViewData();
215 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
216 pViewData->GetActivePart() :
217 (ScSplitPos) nPane;
218 ScHSplitPos eWhichH = WhichH( eWhich );
220 long nDeltaX = ((long)nFirstVisibleColumn) - pViewData->GetPosX( eWhichH );
221 pViewShell->ScrollX( nDeltaX, eWhichH );
225 sal_Int32 SAL_CALL ScViewPaneBase::getFirstVisibleRow() throw(uno::RuntimeException)
227 SolarMutexGuard aGuard;
228 if (pViewShell)
230 ScViewData* pViewData = pViewShell->GetViewData();
231 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
232 pViewData->GetActivePart() :
233 (ScSplitPos) nPane;
234 ScVSplitPos eWhichV = WhichV( eWhich );
236 return pViewData->GetPosY( eWhichV );
238 OSL_FAIL("keine View ?!?"); //! Exception?
239 return 0;
242 void SAL_CALL ScViewPaneBase::setFirstVisibleRow( sal_Int32 nFirstVisibleRow )
243 throw(uno::RuntimeException)
245 SolarMutexGuard aGuard;
246 if (pViewShell)
248 ScViewData* pViewData = pViewShell->GetViewData();
249 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
250 pViewData->GetActivePart() :
251 (ScSplitPos) nPane;
252 ScVSplitPos eWhichV = WhichV( eWhich );
254 long nDeltaY = ((long)nFirstVisibleRow) - pViewData->GetPosY( eWhichV );
255 pViewShell->ScrollY( nDeltaY, eWhichV );
259 table::CellRangeAddress SAL_CALL ScViewPaneBase::getVisibleRange() throw(uno::RuntimeException)
261 SolarMutexGuard aGuard;
262 table::CellRangeAddress aAdr;
263 if (pViewShell)
265 ScViewData* pViewData = pViewShell->GetViewData();
266 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
267 pViewData->GetActivePart() :
268 (ScSplitPos) nPane;
269 ScHSplitPos eWhichH = WhichH( eWhich );
270 ScVSplitPos eWhichV = WhichV( eWhich );
272 // VisibleCellsX gibt nur komplett sichtbare Zellen,
273 // VisibleRange in Excel auch teilweise sichtbare.
274 //! anpassen ???
276 SCCOL nVisX = pViewData->VisibleCellsX( eWhichH );
277 SCROW nVisY = pViewData->VisibleCellsY( eWhichV );
278 if (!nVisX) nVisX = 1; // irgendwas muss ja im Range sein
279 if (!nVisY) nVisY = 1;
280 aAdr.Sheet = pViewData->GetTabNo();
281 aAdr.StartColumn = pViewData->GetPosX( eWhichH );
282 aAdr.StartRow = pViewData->GetPosY( eWhichV );
283 aAdr.EndColumn = aAdr.StartColumn + nVisX - 1;
284 aAdr.EndRow = aAdr.StartRow + nVisY - 1;
286 return aAdr;
289 // XCellRangeSource
291 uno::Reference<table::XCellRange> SAL_CALL ScViewPaneBase::getReferredCells()
292 throw(uno::RuntimeException)
294 SolarMutexGuard aGuard;
295 if (pViewShell)
297 ScDocShell* pDocSh = pViewShell->GetViewData()->GetDocShell();
299 table::CellRangeAddress aAdr(getVisibleRange()); //! Hilfsfunktion mit ScRange?
300 ScRange aRange( (SCCOL)aAdr.StartColumn, (SCROW)aAdr.StartRow, aAdr.Sheet,
301 (SCCOL)aAdr.EndColumn, (SCROW)aAdr.EndRow, aAdr.Sheet );
302 if ( aRange.aStart == aRange.aEnd )
303 return new ScCellObj( pDocSh, aRange.aStart );
304 else
305 return new ScCellRangeObj( pDocSh, aRange );
308 return NULL;
311 namespace
313 bool lcl_prepareFormShellCall( ScTabViewShell* _pViewShell, sal_uInt16 _nPane, FmFormShell*& _rpFormShell, Window*& _rpWindow, SdrView*& _rpSdrView )
315 if ( !_pViewShell )
316 return false;
318 ScViewData* pViewData = _pViewShell->GetViewData();
319 ScSplitPos eWhich = ( _nPane == SC_VIEWPANE_ACTIVE ) ?
320 pViewData->GetActivePart() :
321 (ScSplitPos) _nPane;
322 _rpWindow = _pViewShell->GetWindowByPos( eWhich );
323 _rpSdrView = _pViewShell->GetSdrView();
324 _rpFormShell = _pViewShell->GetFormShell();
325 return ( _rpFormShell != NULL ) && ( _rpSdrView != NULL )&& ( _rpWindow != NULL );
329 // XFormLayerAccess
330 uno::Reference< form::runtime::XFormController > SAL_CALL ScViewPaneBase::getFormController( const uno::Reference< form::XForm >& _Form ) throw (uno::RuntimeException)
332 SolarMutexGuard aGuard;
334 uno::Reference< form::runtime::XFormController > xController;
336 Window* pWindow( NULL );
337 SdrView* pSdrView( NULL );
338 FmFormShell* pFormShell( NULL );
339 if ( lcl_prepareFormShellCall( pViewShell, nPane, pFormShell, pWindow, pSdrView ) )
340 xController = pFormShell->GetFormController( _Form, *pSdrView, *pWindow );
342 return xController;
345 ::sal_Bool SAL_CALL ScViewPaneBase::isFormDesignMode( ) throw (uno::RuntimeException)
347 SolarMutexGuard aGuard;
349 sal_Bool bIsFormDesignMode( sal_True );
351 FmFormShell* pFormShell( pViewShell ? pViewShell->GetFormShell() : NULL );
352 if ( pFormShell )
353 bIsFormDesignMode = pFormShell->IsDesignMode();
355 return bIsFormDesignMode;
358 void SAL_CALL ScViewPaneBase::setFormDesignMode( ::sal_Bool _DesignMode ) throw (uno::RuntimeException)
360 SolarMutexGuard aGuard;
362 Window* pWindow( NULL );
363 SdrView* pSdrView( NULL );
364 FmFormShell* pFormShell( NULL );
365 if ( lcl_prepareFormShellCall( pViewShell, nPane, pFormShell, pWindow, pSdrView ) )
366 pFormShell->SetDesignMode( _DesignMode );
369 // XControlAccess
371 uno::Reference<awt::XControl> SAL_CALL ScViewPaneBase::getControl(
372 const uno::Reference<awt::XControlModel>& xModel )
373 throw(container::NoSuchElementException, uno::RuntimeException)
375 SolarMutexGuard aGuard;
377 uno::Reference<awt::XControl> xRet;
379 Window* pWindow( NULL );
380 SdrView* pSdrView( NULL );
381 FmFormShell* pFormShell( NULL );
382 if ( lcl_prepareFormShellCall( pViewShell, nPane, pFormShell, pWindow, pSdrView ) )
383 pFormShell->GetFormControl( xModel, *pSdrView, *pWindow, xRet );
385 if ( !xRet.is() )
386 throw container::NoSuchElementException(); // no control found
388 return xRet;
391 awt::Rectangle ScViewPaneBase::GetVisArea() const
393 awt::Rectangle aVisArea;
394 if (pViewShell)
396 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
397 pViewShell->GetViewData()->GetActivePart() :
398 (ScSplitPos) nPane;
399 ScGridWindow* pWindow = (ScGridWindow*)pViewShell->GetWindowByPos(eWhich);
400 ScDocument* pDoc = pViewShell->GetViewData()->GetDocument();
401 if (pWindow && pDoc)
403 ScHSplitPos eWhichH = ((eWhich == SC_SPLIT_TOPLEFT) || (eWhich == SC_SPLIT_BOTTOMLEFT)) ?
404 SC_SPLIT_LEFT : SC_SPLIT_RIGHT;
405 ScVSplitPos eWhichV = ((eWhich == SC_SPLIT_TOPLEFT) || (eWhich == SC_SPLIT_TOPRIGHT)) ?
406 SC_SPLIT_TOP : SC_SPLIT_BOTTOM;
407 ScAddress aCell(pViewShell->GetViewData()->GetPosX(eWhichH),
408 pViewShell->GetViewData()->GetPosY(eWhichV),
409 pViewShell->GetViewData()->GetTabNo());
410 Rectangle aCellRect( pDoc->GetMMRect( aCell.Col(), aCell.Row(), aCell.Col(), aCell.Row(), aCell.Tab() ) );
411 Size aVisSize( pWindow->PixelToLogic( pWindow->GetSizePixel(), pWindow->GetDrawMapMode( sal_True ) ) );
412 Point aVisPos( aCellRect.TopLeft() );
413 if ( pDoc->IsLayoutRTL( aCell.Tab() ) )
415 aVisPos = aCellRect.TopRight();
416 aVisPos.X() -= aVisSize.Width();
418 Rectangle aVisRect( aVisPos, aVisSize );
419 aVisArea = AWTRectangle(aVisRect);
422 return aVisArea;
425 //------------------------------------------------------------------------
427 ScViewPaneObj::ScViewPaneObj(ScTabViewShell* pViewSh, sal_uInt16 nP) :
428 ScViewPaneBase( pViewSh, nP )
432 ScViewPaneObj::~ScViewPaneObj()
436 uno::Any SAL_CALL ScViewPaneObj::queryInterface( const uno::Type& rType )
437 throw(uno::RuntimeException)
439 // ScViewPaneBase has everything except OWeakObject
441 uno::Any aRet(ScViewPaneBase::queryInterface( rType ));
442 if (!aRet.hasValue())
443 aRet = OWeakObject::queryInterface( rType );
444 return aRet;
447 void SAL_CALL ScViewPaneObj::acquire() throw()
449 OWeakObject::acquire();
452 void SAL_CALL ScViewPaneObj::release() throw()
454 OWeakObject::release();
457 //------------------------------------------------------------------------
459 // Default-ctor wird fuer SMART_REFLECTION_IMPLEMENTATION gebraucht
461 ScTabViewObj::ScTabViewObj( ScTabViewShell* pViewSh ) :
462 ScViewPaneBase( pViewSh, SC_VIEWPANE_ACTIVE ),
463 SfxBaseController( pViewSh ),
464 aPropSet( lcl_GetViewOptPropertyMap() ),
465 aMouseClickHandlers( 0 ),
466 aActivationListeners( 0 ),
467 nPreviousTab( 0 ),
468 bDrawSelModeSet(false),
469 mbLeftMousePressed(false ),
470 mbPendingSelectionChanged(false)
472 if (pViewSh)
473 nPreviousTab = pViewSh->GetViewData()->GetTabNo();
476 ScTabViewObj::~ScTabViewObj()
478 //! Listening oder so
479 if (!aMouseClickHandlers.empty())
481 acquire();
482 EndMouseListening();
484 if (!aActivationListeners.empty())
486 acquire();
487 EndActivationListening();
491 uno::Any SAL_CALL ScTabViewObj::queryInterface( const uno::Type& rType )
492 throw(uno::RuntimeException)
494 SC_QUERYINTERFACE( sheet::XSpreadsheetView )
495 SC_QUERYINTERFACE( sheet::XEnhancedMouseClickBroadcaster )
496 SC_QUERYINTERFACE( sheet::XActivationBroadcaster )
497 SC_QUERYINTERFACE( container::XEnumerationAccess )
498 SC_QUERYINTERFACE( container::XIndexAccess )
499 SC_QUERY_MULTIPLE( container::XElementAccess, container::XIndexAccess )
500 SC_QUERYINTERFACE( view::XSelectionSupplier )
501 SC_QUERYINTERFACE( beans::XPropertySet )
502 SC_QUERYINTERFACE( sheet::XViewSplitable )
503 SC_QUERYINTERFACE( sheet::XViewFreezable )
504 SC_QUERYINTERFACE( sheet::XRangeSelection )
505 SC_QUERYINTERFACE( lang::XUnoTunnel )
506 SC_QUERYINTERFACE( datatransfer::XTransferableSupplier )
507 SC_QUERYINTERFACE( sheet::XSelectedSheetsSupplier )
509 uno::Any aRet(ScViewPaneBase::queryInterface( rType ));
510 if (!aRet.hasValue())
511 aRet = SfxBaseController::queryInterface( rType );
512 return aRet;
515 void SAL_CALL ScTabViewObj::acquire() throw()
517 SfxBaseController::acquire();
520 void SAL_CALL ScTabViewObj::release() throw()
522 SfxBaseController::release();
525 static void lcl_CallActivate( ScDocShell* pDocSh, SCTAB nTab, sal_Int32 nEvent )
527 ScDocument* pDoc = pDocSh->GetDocument();
528 // when deleting a sheet, nPreviousTab can be invalid
529 // (could be handled with reference updates)
530 if (!pDoc->HasTable(nTab))
531 return;
533 const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
534 if (pEvents)
536 const OUString* pScript = pEvents->GetScript(nEvent);
537 if (pScript)
539 uno::Any aRet;
540 uno::Sequence<uno::Any> aParams;
541 uno::Sequence<sal_Int16> aOutArgsIndex;
542 uno::Sequence<uno::Any> aOutArgs;
543 /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
547 // execute VBA event handlers
550 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
551 // the parameter is the clicked object, as in the mousePressed call above
552 uno::Sequence< uno::Any > aArgs( 1 );
553 aArgs[ 0 ] <<= nTab;
554 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( nEvent ), aArgs );
556 catch( uno::Exception& )
561 void ScTabViewObj::SheetChanged( bool bSameTabButMoved )
563 if ( !GetViewShell() )
564 return;
566 ScViewData* pViewData = GetViewShell()->GetViewData();
567 ScDocShell* pDocSh = pViewData->GetDocShell();
568 if (!aActivationListeners.empty())
570 sheet::ActivationEvent aEvent;
571 uno::Reference< sheet::XSpreadsheetView > xView(this);
572 uno::Reference< uno::XInterface > xSource(xView, uno::UNO_QUERY);
573 aEvent.Source = xSource;
574 aEvent.ActiveSheet = new ScTableSheetObj(pDocSh, pViewData->GetTabNo());
575 for (XActivationEventListenerVector::iterator it = aActivationListeners.begin(); it != aActivationListeners.end(); )
579 (*it)->activeSpreadsheetChanged( aEvent );
580 ++it;
582 catch( uno::Exception& )
584 it = aActivationListeners.erase( it);
589 /* Handle sheet events, but do not trigger event handlers, if the old
590 active sheet gets re-activated after inserting/deleting/moving a sheet. */
591 SCTAB nNewTab = pViewData->GetTabNo();
592 if ( !bSameTabButMoved && (nNewTab != nPreviousTab) )
594 lcl_CallActivate( pDocSh, nPreviousTab, SC_SHEETEVENT_UNFOCUS );
595 lcl_CallActivate( pDocSh, nNewTab, SC_SHEETEVENT_FOCUS );
597 nPreviousTab = nNewTab;
600 uno::Sequence<uno::Type> SAL_CALL ScTabViewObj::getTypes() throw(uno::RuntimeException)
602 static uno::Sequence<uno::Type> aTypes;
603 if ( aTypes.getLength() == 0 )
605 uno::Sequence<uno::Type> aViewPaneTypes(ScViewPaneBase::getTypes());
606 long nViewPaneLen = aViewPaneTypes.getLength();
607 const uno::Type* pViewPanePtr = aViewPaneTypes.getConstArray();
609 uno::Sequence<uno::Type> aControllerTypes(SfxBaseController::getTypes());
610 long nControllerLen = aControllerTypes.getLength();
611 const uno::Type* pControllerPtr = aControllerTypes.getConstArray();
613 long nParentLen = nViewPaneLen + nControllerLen;
615 aTypes.realloc( nParentLen + 12 );
616 uno::Type* pPtr = aTypes.getArray();
617 pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSpreadsheetView>*)0);
618 pPtr[nParentLen + 1] = getCppuType((const uno::Reference<container::XEnumerationAccess>*)0);
619 pPtr[nParentLen + 2] = getCppuType((const uno::Reference<container::XIndexAccess>*)0);
620 pPtr[nParentLen + 3] = getCppuType((const uno::Reference<view::XSelectionSupplier>*)0);
621 pPtr[nParentLen + 4] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
622 pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XViewSplitable>*)0);
623 pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XViewFreezable>*)0);
624 pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XRangeSelection>*)0);
625 pPtr[nParentLen + 8] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0);
626 pPtr[nParentLen + 9] = getCppuType((const uno::Reference<sheet::XEnhancedMouseClickBroadcaster>*)0);
627 pPtr[nParentLen + 10] = getCppuType((const uno::Reference<sheet::XActivationBroadcaster>*)0);
628 pPtr[nParentLen + 11] = getCppuType((const uno::Reference<datatransfer::XTransferableSupplier>*)0);
630 long i;
631 for (i=0; i<nViewPaneLen; i++)
632 pPtr[i] = pViewPanePtr[i]; // parent types first
633 for (i=0; i<nControllerLen; i++)
634 pPtr[nViewPaneLen+i] = pControllerPtr[i];
636 return aTypes;
639 namespace
641 class theScTabViewObjImplementationId : public rtl::Static< UnoTunnelIdInit, theScTabViewObjImplementationId > {};
644 uno::Sequence<sal_Int8> SAL_CALL ScTabViewObj::getImplementationId()
645 throw(uno::RuntimeException)
647 return theScTabViewObjImplementationId::get().getSeq();
650 // XDocumentView
652 static sal_Bool lcl_TabInRanges( SCTAB nTab, const ScRangeList& rRanges )
654 for (size_t i = 0, nCount = rRanges.size(); i < nCount; ++i)
656 const ScRange* pRange = rRanges[ i ];
657 if ( nTab >= pRange->aStart.Tab() && nTab <= pRange->aEnd.Tab() )
658 return sal_True;
660 return false;
663 static void lcl_ShowObject( ScTabViewShell& rViewSh, ScDrawView& rDrawView, SdrObject* pSelObj )
665 sal_Bool bFound = false;
666 SCTAB nObjectTab = 0;
668 SdrModel* pModel = rDrawView.GetModel();
669 sal_uInt16 nPageCount = pModel->GetPageCount();
670 for (sal_uInt16 i=0; i<nPageCount && !bFound; i++)
672 SdrPage* pPage = pModel->GetPage(i);
673 if (pPage)
675 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
676 SdrObject* pObject = aIter.Next();
677 while (pObject && !bFound)
679 if ( pObject == pSelObj )
681 bFound = sal_True;
682 nObjectTab = static_cast<SCTAB>(i);
684 pObject = aIter.Next();
689 if (bFound)
691 rViewSh.SetTabNo( nObjectTab );
692 rViewSh.ScrollToObject( pSelObj );
696 sal_Bool SAL_CALL ScTabViewObj::select( const uno::Any& aSelection )
697 throw(lang::IllegalArgumentException, uno::RuntimeException)
699 SolarMutexGuard aGuard;
700 ScTabViewShell* pViewSh = GetViewShell();
702 if ( !pViewSh )
703 return false;
705 //! Type of aSelection can be some specific interface instead of XInterface
707 sal_Bool bRet = false;
708 uno::Reference<uno::XInterface> xInterface(aSelection, uno::UNO_QUERY);
709 if ( !xInterface.is() ) //clear all selections
711 ScDrawView* pDrawView = pViewSh->GetScDrawView();
712 if (pDrawView)
714 pDrawView->ScEndTextEdit();
715 pDrawView->UnmarkAll();
717 else //#102232#; if there is no DrawView remove range selection
718 pViewSh->Unmark();
719 bRet = sal_True;
722 if (bDrawSelModeSet) // remove DrawSelMode if set by API; if necessary it will be set again later
724 pViewSh->SetDrawSelMode(false);
725 pViewSh->UpdateLayerLocks();
726 bDrawSelModeSet = false;
729 if (bRet)
730 return bRet;
733 ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( xInterface );
734 uno::Reference<drawing::XShapes> xShapeColl( xInterface, uno::UNO_QUERY );
735 uno::Reference<drawing::XShape> xShapeSel( xInterface, uno::UNO_QUERY );
736 SvxShape* pShapeImp = SvxShape::getImplementation( xShapeSel );
738 if (pRangesImp) // Zell-Ranges
740 ScViewData* pViewData = pViewSh->GetViewData();
741 if ( pViewData->GetDocShell() == pRangesImp->GetDocShell() )
743 // Zuerst evtl. Drawing-Selektion aufheben
744 // (MarkListHasChanged hebt Tabellen-Selektion auf)
746 ScDrawView* pDrawView = pViewSh->GetScDrawView();
747 if (pDrawView)
749 pDrawView->ScEndTextEdit();
750 pDrawView->UnmarkAll();
752 FuPoor* pFunc = pViewSh->GetDrawFuncPtr();
753 if ( pFunc && pFunc->GetSlotID() != SID_OBJECT_SELECT )
755 // Slot der Zeichenfunktion nochmal ausfuehren -> abschalten
756 SfxDispatcher* pDisp = pViewSh->GetDispatcher();
757 if (pDisp)
758 pDisp->Execute( pFunc->GetSlotID(), SFX_CALLMODE_SYNCHRON );
760 pViewSh->SetDrawShell(false);
761 pViewSh->SetDrawSelMode(false); // nach dem Dispatcher-Execute
763 // Ranges selektieren
765 const ScRangeList& rRanges = pRangesImp->GetRangeList();
766 size_t nRangeCount = rRanges.size();
767 // for empty range list, remove selection (cursor remains where it was)
768 if ( nRangeCount == 0 )
769 pViewSh->Unmark();
770 else if ( nRangeCount == 1 )
771 pViewSh->MarkRange( *rRanges[ 0 ] );
772 else
774 // Mehrfachselektion
776 const ScRange* pFirst = rRanges[ 0 ];
777 if ( pFirst && !lcl_TabInRanges( pViewData->GetTabNo(), rRanges ) )
778 pViewSh->SetTabNo( pFirst->aStart.Tab() );
779 pViewSh->DoneBlockMode();
780 pViewSh->InitOwnBlockMode();
781 pViewData->GetMarkData().MarkFromRangeList( rRanges, sal_True );
782 pViewSh->MarkDataChanged();
783 pViewData->GetDocShell()->PostPaintGridAll(); // Markierung (alt&neu)
784 if ( pFirst )
786 pViewSh->AlignToCursor( pFirst->aStart.Col(), pFirst->aStart.Row(),
787 SC_FOLLOW_JUMP );
788 pViewSh->SetCursor( pFirst->aStart.Col(), pFirst->aStart.Row() );
791 //! Methode an der View, um RangeList zu selektieren
793 bRet = sal_True;
796 else if ( pShapeImp || xShapeColl.is() ) // Drawing-Layer
798 ScDrawView* pDrawView = pViewSh->GetScDrawView();
799 if (pDrawView)
801 pDrawView->ScEndTextEdit();
802 pDrawView->UnmarkAll();
804 if (pShapeImp) // einzelnes Shape
806 SdrObject *pObj = pShapeImp->GetSdrObject();
807 if (pObj)
809 lcl_ShowObject( *pViewSh, *pDrawView, pObj );
810 SdrPageView* pPV = pDrawView->GetSdrPageView();
811 if ( pPV && pObj->GetPage() == pPV->GetPage() )
813 pDrawView->MarkObj( pObj, pPV );
814 bRet = sal_True;
818 else // Shape-Collection (xShapeColl ist nicht 0)
820 // Es wird auf die Tabelle des ersten Objekts umgeschaltet,
821 // und alle Objekte selektiert, die auf dieser Tabelle liegen
822 //! Exception, wenn Objekte auf verschiedenen Tabellen?
824 long nCount = xShapeColl->getCount();
825 if (nCount)
827 SdrPageView* pPV = NULL;
828 sal_Bool bAllMarked(sal_True);
829 for ( long i = 0; i < nCount; i++ )
831 uno::Reference<drawing::XShape> xShapeInt(xShapeColl->getByIndex(i), uno::UNO_QUERY);
832 if (xShapeInt.is())
834 SvxShape* pShape = SvxShape::getImplementation( xShapeInt );
835 if (pShape)
837 SdrObject *pObj = pShape->GetSdrObject();
838 if (pObj)
840 if (!bDrawSelModeSet && (pObj->GetLayer() == SC_LAYER_BACK))
842 pViewSh->SetDrawSelMode(sal_True);
843 pViewSh->UpdateLayerLocks();
844 bDrawSelModeSet = sal_True;
846 if (!pPV) // erstes Objekt
848 lcl_ShowObject( *pViewSh, *pDrawView, pObj );
849 pPV = pDrawView->GetSdrPageView();
851 if ( pPV && pObj->GetPage() == pPV->GetPage() )
853 if (pDrawView->IsObjMarkable( pObj, pPV ))
854 pDrawView->MarkObj( pObj, pPV );
855 else
856 bAllMarked = false;
862 if (bAllMarked)
863 bRet = sal_True;
865 else
866 bRet = sal_True; // empty XShapes (all shapes are deselected)
869 if (bRet)
870 pViewSh->SetDrawShell(sal_True);
874 if (!bRet)
875 throw lang::IllegalArgumentException();
877 return bRet;
880 uno::Any SAL_CALL ScTabViewObj::getSelection() throw(uno::RuntimeException)
882 SolarMutexGuard aGuard;
883 ScTabViewShell* pViewSh = GetViewShell();
884 ScCellRangesBase* pObj = NULL;
885 if (pViewSh)
887 // Ist auf dem Drawing-Layer etwas selektiert?
889 SdrView* pDrawView = pViewSh->GetSdrView();
890 if (pDrawView)
892 const SdrMarkList& rMarkList = pDrawView->GetMarkedObjectList();
893 sal_uLong nMarkCount = rMarkList.GetMarkCount();
894 if (nMarkCount)
896 // ShapeCollection erzeugen (wie in SdXImpressView::getSelection im Draw)
897 // Zurueckgegeben wird XInterfaceRef, das muss das UsrObject-XInterface sein
899 SvxShapeCollection* pShapes = new SvxShapeCollection();
900 uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pShapes));
902 for (sal_uLong i=0; i<nMarkCount; i++)
904 SdrObject* pDrawObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
905 if (pDrawObj)
907 uno::Reference<drawing::XShape> xShape( pDrawObj->getUnoShape(), uno::UNO_QUERY );
908 if (xShape.is())
909 pShapes->add(xShape);
912 return uno::makeAny(xRet);
916 // sonst Tabellen-(Zellen-)Selektion
918 ScViewData* pViewData = pViewSh->GetViewData();
919 ScDocShell* pDocSh = pViewData->GetDocShell();
921 const ScMarkData& rMark = pViewData->GetMarkData();
922 SCTAB nTabs = rMark.GetSelectCount();
924 ScRange aRange;
925 ScMarkType eMarkType = pViewData->GetSimpleArea(aRange);
926 if ( nTabs == 1 && (eMarkType == SC_MARK_SIMPLE) )
928 if (aRange.aStart == aRange.aEnd)
929 pObj = new ScCellObj( pDocSh, aRange.aStart );
930 else
931 pObj = new ScCellRangeObj( pDocSh, aRange );
933 else if ( nTabs == 1 && (eMarkType == SC_MARK_SIMPLE_FILTERED) )
935 ScMarkData aFilteredMark( rMark );
936 ScViewUtil::UnmarkFiltered( aFilteredMark, pDocSh->GetDocument());
937 ScRangeList aRangeList;
938 aFilteredMark.FillRangeListWithMarks( &aRangeList, false);
939 // Theoretically a selection may start and end on a filtered row.
940 switch ( aRangeList.size() )
942 case 0:
943 // No unfiltered row, we have to return some object, so
944 // here is one with no ranges.
945 pObj = new ScCellRangesObj( pDocSh, aRangeList );
946 break;
947 case 1:
949 const ScRange& rRange = *(aRangeList[ 0 ]);
950 if (rRange.aStart == rRange.aEnd)
951 pObj = new ScCellObj( pDocSh, rRange.aStart );
952 else
953 pObj = new ScCellRangeObj( pDocSh, rRange );
955 break;
956 default:
957 pObj = new ScCellRangesObj( pDocSh, aRangeList );
960 else // Mehrfachselektion
962 ScRangeListRef xRanges;
963 pViewData->GetMultiArea( xRanges );
965 // bei mehreren Tabellen Ranges kopieren
966 //! sollte eigentlich schon in ScMarkData::FillRangeListWithMarks passieren?
967 if ( nTabs > 1 )
968 rMark.ExtendRangeListTables( xRanges );
970 pObj = new ScCellRangesObj( pDocSh, *xRanges );
973 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
975 // remember if the selection was from the cursor position without anything selected
976 // (used when rendering the selection)
978 pObj->SetCursorOnly( sal_True );
982 return uno::makeAny(uno::Reference<uno::XInterface>(static_cast<cppu::OWeakObject*>(pObj)));
985 // XEnumerationAccess
987 uno::Reference<container::XEnumeration> SAL_CALL ScTabViewObj::createEnumeration()
988 throw(uno::RuntimeException)
990 SolarMutexGuard aGuard;
991 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.SpreadsheetViewPanesEnumeration"));
994 // XIndexAccess
996 sal_Int32 SAL_CALL ScTabViewObj::getCount() throw(uno::RuntimeException)
998 SolarMutexGuard aGuard;
999 ScTabViewShell* pViewSh = GetViewShell();
1000 sal_uInt16 nPanes = 0;
1001 if (pViewSh)
1003 nPanes = 1;
1004 ScViewData* pViewData = pViewSh->GetViewData();
1005 if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
1006 nPanes *= 2;
1007 if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1008 nPanes *= 2;
1010 return nPanes;
1013 uno::Any SAL_CALL ScTabViewObj::getByIndex( sal_Int32 nIndex )
1014 throw(lang::IndexOutOfBoundsException,
1015 lang::WrappedTargetException, uno::RuntimeException)
1017 SolarMutexGuard aGuard;
1018 uno::Reference<sheet::XViewPane> xPane(GetObjectByIndex_Impl((sal_uInt16)nIndex));
1019 if (xPane.is())
1020 return uno::makeAny(xPane);
1021 else
1022 throw lang::IndexOutOfBoundsException();
1023 // return uno::Any();
1026 uno::Type SAL_CALL ScTabViewObj::getElementType() throw(uno::RuntimeException)
1028 SolarMutexGuard aGuard;
1029 return getCppuType((uno::Reference<sheet::XViewPane>*)0);
1032 sal_Bool SAL_CALL ScTabViewObj::hasElements() throw(uno::RuntimeException)
1034 SolarMutexGuard aGuard;
1035 return ( getCount() != 0 );
1038 // XSpreadsheetView
1040 ScViewPaneObj* ScTabViewObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) const
1042 static const ScSplitPos ePosHV[4] =
1043 { SC_SPLIT_TOPLEFT, SC_SPLIT_BOTTOMLEFT, SC_SPLIT_TOPRIGHT, SC_SPLIT_BOTTOMRIGHT };
1045 ScTabViewShell* pViewSh = GetViewShell();
1046 if (pViewSh)
1048 ScSplitPos eWhich = SC_SPLIT_BOTTOMLEFT; // default Position
1049 sal_Bool bError = false;
1050 ScViewData* pViewData = pViewSh->GetViewData();
1051 sal_Bool bHor = ( pViewData->GetHSplitMode() != SC_SPLIT_NONE );
1052 sal_Bool bVer = ( pViewData->GetVSplitMode() != SC_SPLIT_NONE );
1053 if ( bHor && bVer )
1055 // links oben, links unten, rechts oben, rechts unten - wie in Excel
1056 if ( nIndex < 4 )
1057 eWhich = ePosHV[nIndex];
1058 else
1059 bError = sal_True;
1061 else if ( bHor )
1063 if ( nIndex > 1 )
1064 bError = sal_True;
1065 else if ( nIndex == 1 )
1066 eWhich = SC_SPLIT_BOTTOMRIGHT;
1067 // sonst SC_SPLIT_BOTTOMLEFT
1069 else if ( bVer )
1071 if ( nIndex > 1 )
1072 bError = sal_True;
1073 else if ( nIndex == 0 )
1074 eWhich = SC_SPLIT_TOPLEFT;
1075 // sonst SC_SPLIT_BOTTOMLEFT
1077 else if ( nIndex > 0 )
1078 bError = sal_True; // nicht geteilt: nur 0 gueltig
1080 if (!bError)
1081 return new ScViewPaneObj( pViewSh, sal::static_int_cast<sal_uInt16>(eWhich) );
1084 return NULL;
1087 uno::Reference<sheet::XSpreadsheet> SAL_CALL ScTabViewObj::getActiveSheet()
1088 throw(uno::RuntimeException)
1090 SolarMutexGuard aGuard;
1091 ScTabViewShell* pViewSh = GetViewShell();
1092 if (pViewSh)
1094 ScViewData* pData = pViewSh->GetViewData();
1095 SCTAB nTab = pData->GetTabNo();
1096 return new ScTableSheetObj( pData->GetDocShell(), nTab );
1098 return NULL;
1101 // support expand (but not replace) the active sheet
1102 void SAL_CALL ScTabViewObj::setActiveSheet( const uno::Reference<sheet::XSpreadsheet>& xActiveSheet )
1103 throw(uno::RuntimeException)
1105 SolarMutexGuard aGuard;
1107 ScTabViewShell* pViewSh = GetViewShell();
1108 if ( pViewSh && xActiveSheet.is() )
1110 // XSpreadsheet und ScCellRangesBase -> muss ein Sheet sein
1112 ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( xActiveSheet );
1113 if ( pRangesImp && pViewSh->GetViewData()->GetDocShell() == pRangesImp->GetDocShell() )
1115 const ScRangeList& rRanges = pRangesImp->GetRangeList();
1116 if ( rRanges.size() == 1 )
1118 SCTAB nNewTab = rRanges[ 0 ]->aStart.Tab();
1119 if ( pViewSh->GetViewData()->GetDocument()->HasTable(nNewTab) )
1120 pViewSh->SetTabNo( nNewTab );
1126 uno::Reference< uno::XInterface > ScTabViewObj::GetClickedObject(const Point& rPoint) const
1128 uno::Reference< uno::XInterface > xTarget;
1129 if (GetViewShell())
1131 SCsCOL nX;
1132 SCsROW nY;
1133 ScViewData* pData = GetViewShell()->GetViewData();
1134 ScSplitPos eSplitMode = pData->GetActivePart();
1135 SCTAB nTab(pData->GetTabNo());
1136 pData->GetPosFromPixel( rPoint.X(), rPoint.Y(), eSplitMode, nX, nY);
1138 ScAddress aCellPos (nX, nY, nTab);
1139 ScCellObj* pCellObj = new ScCellObj(pData->GetDocShell(), aCellPos);
1141 xTarget.set(uno::Reference<table::XCell>(pCellObj), uno::UNO_QUERY);
1143 ScDocument* pDoc = pData->GetDocument();
1144 if (pDoc && pDoc->GetDrawLayer())
1146 SdrPage* pDrawPage = NULL;
1147 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1148 if (pDrawLayer->HasObjects() && (pDrawLayer->GetPageCount() > nTab))
1149 pDrawPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
1151 SdrView* pDrawView = GetViewShell()->GetSdrView();
1153 if (pDrawPage && pDrawView && pDrawView->GetSdrPageView())
1155 Window* pActiveWin = pData->GetActiveWin();
1156 Point aPos = pActiveWin->PixelToLogic(rPoint);
1158 sal_uInt16 nHitLog = (sal_uInt16) pActiveWin->PixelToLogic(
1159 Size(pDrawView->GetHitTolerancePixel(),0)).Width();
1161 sal_uInt32 nCount(pDrawPage->GetObjCount());
1162 sal_Bool bFound(false);
1163 sal_uInt32 i(0);
1164 while (i < nCount && !bFound)
1166 SdrObject* pObj = pDrawPage->GetObj(i);
1167 if (pObj && SdrObjectPrimitiveHit(*pObj, aPos, nHitLog, *pDrawView->GetSdrPageView(), 0, false))
1169 xTarget.set(pObj->getUnoShape(), uno::UNO_QUERY);
1170 bFound = sal_True;
1172 ++i;
1177 return xTarget;
1180 bool ScTabViewObj::IsMouseListening() const
1182 if ( !aMouseClickHandlers.empty() )
1183 return true;
1185 // also include sheet events, because MousePressed must be called for them
1186 ScViewData* pViewData = GetViewShell()->GetViewData();
1187 ScDocument* pDoc = pViewData->GetDocument();
1188 SCTAB nTab = pViewData->GetTabNo();
1189 return
1190 pDoc->HasSheetEventScript( nTab, SC_SHEETEVENT_RIGHTCLICK, true ) ||
1191 pDoc->HasSheetEventScript( nTab, SC_SHEETEVENT_DOUBLECLICK, true ) ||
1192 pDoc->HasSheetEventScript( nTab, SC_SHEETEVENT_SELECT, true );
1196 sal_Bool ScTabViewObj::MousePressed( const awt::MouseEvent& e )
1197 throw (::uno::RuntimeException)
1199 sal_Bool bReturn(false);
1200 if ( e.Buttons == ::com::sun::star::awt::MouseButton::LEFT )
1201 mbLeftMousePressed = true;
1203 uno::Reference< uno::XInterface > xTarget = GetClickedObject(Point(e.X, e.Y));
1204 if (!aMouseClickHandlers.empty() && xTarget.is())
1206 awt::EnhancedMouseEvent aMouseEvent;
1208 aMouseEvent.Buttons = e.Buttons;
1209 aMouseEvent.X = e.X;
1210 aMouseEvent.Y = e.Y;
1211 aMouseEvent.ClickCount = e.ClickCount;
1212 aMouseEvent.PopupTrigger = e.PopupTrigger;
1213 aMouseEvent.Target = xTarget;
1215 for (XMouseClickHandlerVector::iterator it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); )
1219 if (!(*it)->mousePressed( aMouseEvent ))
1220 bReturn = sal_True;
1221 ++it;
1223 catch ( uno::Exception& )
1225 it = aMouseClickHandlers.erase(it);
1230 // handle sheet events
1231 bool bDoubleClick = ( e.Buttons == awt::MouseButton::LEFT && e.ClickCount == 2 );
1232 bool bRightClick = ( e.Buttons == awt::MouseButton::RIGHT && e.ClickCount == 1 );
1233 if ( ( bDoubleClick || bRightClick ) && !bReturn && xTarget.is())
1235 sal_Int32 nEvent = bDoubleClick ? SC_SHEETEVENT_DOUBLECLICK : SC_SHEETEVENT_RIGHTCLICK;
1237 ScTabViewShell* pViewSh = GetViewShell();
1238 ScViewData* pViewData = pViewSh->GetViewData();
1239 ScDocShell* pDocSh = pViewData->GetDocShell();
1240 ScDocument* pDoc = pDocSh->GetDocument();
1241 SCTAB nTab = pViewData->GetTabNo();
1242 const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
1243 if (pEvents)
1245 const OUString* pScript = pEvents->GetScript(nEvent);
1246 if (pScript)
1248 // the macro parameter is the clicked object, as in the mousePressed call above
1249 uno::Sequence<uno::Any> aParams(1);
1250 aParams[0] <<= xTarget;
1252 uno::Any aRet;
1253 uno::Sequence<sal_Int16> aOutArgsIndex;
1254 uno::Sequence<uno::Any> aOutArgs;
1256 /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
1258 // look for a boolean return value of true
1259 sal_Bool bRetValue = false;
1260 if (aRet >>= bRetValue)
1262 if (bRetValue)
1263 bReturn = sal_True;
1268 // execute VBA event handler
1269 if (!bReturn && xTarget.is()) try
1271 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
1272 // the parameter is the clicked object, as in the mousePressed call above
1273 uno::Sequence< uno::Any > aArgs( 1 );
1274 aArgs[ 0 ] <<= xTarget;
1275 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( nEvent ), aArgs );
1277 catch( util::VetoException& )
1279 bReturn = sal_True;
1281 catch( uno::Exception& )
1286 return bReturn;
1289 sal_Bool ScTabViewObj::MouseReleased( const awt::MouseEvent& e )
1290 throw (uno::RuntimeException)
1292 if ( e.Buttons == ::com::sun::star::awt::MouseButton::LEFT )
1296 mbPendingSelectionChanged = false;
1297 ScTabViewShell* pViewSh = GetViewShell();
1298 ScViewData* pViewData = pViewSh->GetViewData();
1299 ScDocShell* pDocSh = pViewData->GetDocShell();
1300 ScDocument* pDoc = pDocSh->GetDocument();
1301 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
1302 uno::Sequence< uno::Any > aArgs( 1 );
1303 aArgs[ 0 ] <<= getSelection();
1304 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_SELECT ), aArgs );
1306 catch( uno::Exception& )
1309 mbLeftMousePressed = false;
1312 sal_Bool bReturn(false);
1314 if (!aMouseClickHandlers.empty())
1316 uno::Reference< uno::XInterface > xTarget = GetClickedObject(Point(e.X, e.Y));
1318 if (xTarget.is())
1320 awt::EnhancedMouseEvent aMouseEvent;
1322 aMouseEvent.Buttons = e.Buttons;
1323 aMouseEvent.X = e.X;
1324 aMouseEvent.Y = e.Y;
1325 aMouseEvent.ClickCount = e.ClickCount;
1326 aMouseEvent.PopupTrigger = e.PopupTrigger;
1327 aMouseEvent.Target = xTarget;
1329 for (XMouseClickHandlerVector::iterator it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); )
1333 if (!(*it)->mouseReleased( aMouseEvent ))
1334 bReturn = sal_True;
1335 ++it;
1337 catch ( uno::Exception& )
1339 it = aMouseClickHandlers.erase(it);
1344 return bReturn;
1347 // XEnhancedMouseClickBroadcaster
1349 void ScTabViewObj::StartMouseListening()
1353 void ScTabViewObj::EndMouseListening()
1355 lang::EventObject aEvent;
1356 aEvent.Source = (cppu::OWeakObject*)this;
1357 BOOST_FOREACH(const XMouseClickHandlerUnoRef rListener, aMouseClickHandlers)
1361 rListener->disposing(aEvent);
1363 catch ( uno::Exception& )
1367 aMouseClickHandlers.clear();
1370 void ScTabViewObj::StartActivationListening()
1374 void ScTabViewObj::EndActivationListening()
1376 lang::EventObject aEvent;
1377 aEvent.Source = (cppu::OWeakObject*)this;
1378 BOOST_FOREACH(const XActivationEventListenerUnoRef rListener, aActivationListeners)
1382 rListener->disposing(aEvent);
1384 catch ( uno::Exception& )
1388 aActivationListeners.clear();
1391 void SAL_CALL ScTabViewObj::addEnhancedMouseClickHandler( const uno::Reference< awt::XEnhancedMouseClickHandler >& aListener )
1392 throw (uno::RuntimeException)
1394 SolarMutexGuard aGuard;
1396 if (aListener.is())
1398 sal_uInt16 nCount = aMouseClickHandlers.size();
1399 uno::Reference<awt::XEnhancedMouseClickHandler> *pObj =
1400 new uno::Reference<awt::XEnhancedMouseClickHandler>( aListener );
1401 aMouseClickHandlers.push_back( pObj );
1403 if (aMouseClickHandlers.size() == 1 && nCount == 0) // only if a listener added
1404 StartMouseListening();
1408 void SAL_CALL ScTabViewObj::removeEnhancedMouseClickHandler( const uno::Reference< awt::XEnhancedMouseClickHandler >& aListener )
1409 throw (uno::RuntimeException)
1411 SolarMutexGuard aGuard;
1412 sal_uInt16 nCount = aMouseClickHandlers.size();
1413 for (XMouseClickHandlerVector::iterator it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); )
1415 if ( *it == aListener )
1416 it = aMouseClickHandlers.erase(it);
1417 else
1418 ++it;
1420 if ((aMouseClickHandlers.size() == 0) && (nCount > 0)) // only if last listener removed
1421 EndMouseListening();
1424 // XActivationBroadcaster
1426 void SAL_CALL ScTabViewObj::addActivationEventListener( const uno::Reference< sheet::XActivationEventListener >& aListener )
1427 throw (uno::RuntimeException)
1429 SolarMutexGuard aGuard;
1431 if (aListener.is())
1433 sal_uInt16 nCount = aActivationListeners.size();
1434 uno::Reference<sheet::XActivationEventListener> *pObj =
1435 new uno::Reference<sheet::XActivationEventListener>( aListener );
1436 aActivationListeners.push_back( pObj );
1438 if (aActivationListeners.size() == 1 && nCount == 0) // only if a listener added
1439 StartActivationListening();
1443 void SAL_CALL ScTabViewObj::removeActivationEventListener( const uno::Reference< sheet::XActivationEventListener >& aListener )
1444 throw (uno::RuntimeException)
1446 SolarMutexGuard aGuard;
1447 sal_uInt16 nCount = aActivationListeners.size();
1448 for (XActivationEventListenerVector::iterator it = aActivationListeners.begin(); it != aActivationListeners.end(); )
1450 if ( *it == aListener )
1451 it = aActivationListeners.erase(it);
1452 else
1453 ++it;
1455 if ((aActivationListeners.size() == 0) && (nCount > 0)) // only if last listener removed
1456 EndActivationListening();
1459 sal_Int16 ScTabViewObj::GetZoom(void) const
1461 ScTabViewShell* pViewSh = GetViewShell();
1462 if (pViewSh)
1464 const Fraction& rZoomY = pViewSh->GetViewData()->GetZoomY(); // Y wird angezeigt
1465 return (sal_Int16)(( rZoomY.GetNumerator() * 100 ) / rZoomY.GetDenominator());
1467 return 0;
1470 void ScTabViewObj::SetZoom(sal_Int16 nZoom)
1472 ScTabViewShell* pViewSh = GetViewShell();
1473 if (pViewSh)
1475 if ( nZoom != GetZoom() && nZoom != 0 )
1477 if (!pViewSh->GetViewData()->IsPagebreakMode())
1479 ScModule* pScMod = SC_MOD();
1480 ScAppOptions aNewOpt(pScMod->GetAppOptions());
1481 aNewOpt.SetZoom( nZoom );
1482 aNewOpt.SetZoomType( pViewSh->GetViewData()->GetView()->GetZoomType() );
1483 pScMod->SetAppOptions( aNewOpt );
1486 Fraction aFract( nZoom, 100 );
1487 pViewSh->SetZoom( aFract, aFract, sal_True );
1488 pViewSh->PaintGrid();
1489 pViewSh->PaintTop();
1490 pViewSh->PaintLeft();
1491 pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM );
1492 pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER );
1496 sal_Int16 ScTabViewObj::GetZoomType(void) const
1498 sal_Int16 aZoomType = view::DocumentZoomType::OPTIMAL;
1499 ScTabViewShell* pViewSh = GetViewShell();
1500 if (pViewSh)
1502 SvxZoomType eZoomType = pViewSh->GetViewData()->GetView()->GetZoomType();
1503 switch (eZoomType)
1505 case SVX_ZOOM_PERCENT:
1506 aZoomType = view::DocumentZoomType::BY_VALUE;
1507 break;
1508 case SVX_ZOOM_OPTIMAL:
1509 aZoomType = view::DocumentZoomType::OPTIMAL;
1510 break;
1511 case SVX_ZOOM_WHOLEPAGE:
1512 aZoomType = view::DocumentZoomType::ENTIRE_PAGE;
1513 break;
1514 case SVX_ZOOM_PAGEWIDTH:
1515 aZoomType = view::DocumentZoomType::PAGE_WIDTH;
1516 break;
1517 case SVX_ZOOM_PAGEWIDTH_NOBORDER:
1518 aZoomType = view::DocumentZoomType::PAGE_WIDTH_EXACT;
1519 break;
1522 return aZoomType;
1525 void ScTabViewObj::SetZoomType(sal_Int16 aZoomType)
1527 ScTabViewShell* pViewSh = GetViewShell();
1528 if (pViewSh)
1530 ScDBFunc* pView = pViewSh->GetViewData()->GetView();
1531 if (pView)
1533 SvxZoomType eZoomType;
1534 switch (aZoomType)
1536 case view::DocumentZoomType::BY_VALUE:
1537 eZoomType = SVX_ZOOM_PERCENT;
1538 break;
1539 case view::DocumentZoomType::OPTIMAL:
1540 eZoomType = SVX_ZOOM_OPTIMAL;
1541 break;
1542 case view::DocumentZoomType::ENTIRE_PAGE:
1543 eZoomType = SVX_ZOOM_WHOLEPAGE;
1544 break;
1545 case view::DocumentZoomType::PAGE_WIDTH:
1546 eZoomType = SVX_ZOOM_PAGEWIDTH;
1547 break;
1548 case view::DocumentZoomType::PAGE_WIDTH_EXACT:
1549 eZoomType = SVX_ZOOM_PAGEWIDTH_NOBORDER;
1550 break;
1551 default:
1552 eZoomType = SVX_ZOOM_OPTIMAL;
1554 sal_Int16 nZoom(GetZoom());
1555 sal_Int16 nOldZoom(nZoom);
1556 if ( eZoomType == SVX_ZOOM_PERCENT )
1558 if ( nZoom < MINZOOM ) nZoom = MINZOOM;
1559 if ( nZoom > MAXZOOM ) nZoom = MAXZOOM;
1561 else
1562 nZoom = pView->CalcZoom( eZoomType, nOldZoom );
1564 switch ( eZoomType )
1566 case SVX_ZOOM_WHOLEPAGE:
1567 case SVX_ZOOM_PAGEWIDTH:
1568 pView->SetZoomType( eZoomType, sal_True );
1569 break;
1571 default:
1572 pView->SetZoomType( SVX_ZOOM_PERCENT, sal_True );
1574 SetZoom( nZoom );
1579 sal_Bool SAL_CALL ScTabViewObj::getIsWindowSplit() throw(uno::RuntimeException)
1581 SolarMutexGuard aGuard;
1582 // wie Menue-Slot SID_WINDOW_SPLIT
1584 ScTabViewShell* pViewSh = GetViewShell();
1585 if (pViewSh)
1587 ScViewData* pViewData = pViewSh->GetViewData();
1588 return ( pViewData->GetHSplitMode() == SC_SPLIT_NORMAL ||
1589 pViewData->GetVSplitMode() == SC_SPLIT_NORMAL );
1592 return false;
1595 sal_Bool SAL_CALL ScTabViewObj::hasFrozenPanes() throw(uno::RuntimeException)
1597 SolarMutexGuard aGuard;
1598 // wie Menue-Slot SID_WINDOW_FIX
1600 ScTabViewShell* pViewSh = GetViewShell();
1601 if (pViewSh)
1603 ScViewData* pViewData = pViewSh->GetViewData();
1604 return ( pViewData->GetHSplitMode() == SC_SPLIT_FIX ||
1605 pViewData->GetVSplitMode() == SC_SPLIT_FIX );
1608 return false;
1611 sal_Int32 SAL_CALL ScTabViewObj::getSplitHorizontal() throw(uno::RuntimeException)
1613 SolarMutexGuard aGuard;
1614 ScTabViewShell* pViewSh = GetViewShell();
1615 if (pViewSh)
1617 ScViewData* pViewData = pViewSh->GetViewData();
1618 if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
1619 return pViewData->GetHSplitPos();
1621 return 0;
1624 sal_Int32 SAL_CALL ScTabViewObj::getSplitVertical() throw(uno::RuntimeException)
1626 SolarMutexGuard aGuard;
1627 ScTabViewShell* pViewSh = GetViewShell();
1628 if (pViewSh)
1630 ScViewData* pViewData = pViewSh->GetViewData();
1631 if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1632 return pViewData->GetVSplitPos();
1634 return 0;
1637 sal_Int32 SAL_CALL ScTabViewObj::getSplitColumn() throw(uno::RuntimeException)
1639 SolarMutexGuard aGuard;
1640 ScTabViewShell* pViewSh = GetViewShell();
1641 if (pViewSh)
1643 ScViewData* pViewData = pViewSh->GetViewData();
1644 if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
1646 long nSplit = pViewData->GetHSplitPos();
1648 ScSplitPos ePos = SC_SPLIT_BOTTOMLEFT;
1649 if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1650 ePos = SC_SPLIT_TOPLEFT;
1652 SCsCOL nCol;
1653 SCsROW nRow;
1654 pViewData->GetPosFromPixel( nSplit, 0, ePos, nCol, nRow, false );
1655 if ( nCol > 0 )
1656 return nCol;
1659 return 0;
1662 sal_Int32 SAL_CALL ScTabViewObj::getSplitRow() throw(uno::RuntimeException)
1664 SolarMutexGuard aGuard;
1665 ScTabViewShell* pViewSh = GetViewShell();
1666 if (pViewSh)
1668 ScViewData* pViewData = pViewSh->GetViewData();
1669 if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1671 long nSplit = pViewData->GetVSplitPos();
1673 ScSplitPos ePos = SC_SPLIT_TOPLEFT; // es ist vertikal geteilt
1674 SCsCOL nCol;
1675 SCsROW nRow;
1676 pViewData->GetPosFromPixel( 0, nSplit, ePos, nCol, nRow, false );
1677 if ( nRow > 0 )
1678 return nRow;
1681 return 0;
1684 void SAL_CALL ScTabViewObj::splitAtPosition( sal_Int32 nPixelX, sal_Int32 nPixelY )
1685 throw(uno::RuntimeException)
1687 SolarMutexGuard aGuard;
1688 ScTabViewShell* pViewSh = GetViewShell();
1689 if (pViewSh)
1691 pViewSh->SplitAtPixel( Point( nPixelX, nPixelY ), sal_True, sal_True );
1692 pViewSh->FreezeSplitters( false );
1693 pViewSh->InvalidateSplit();
1697 void SAL_CALL ScTabViewObj::freezeAtPosition( sal_Int32 nColumns, sal_Int32 nRows )
1698 throw(uno::RuntimeException)
1700 SolarMutexGuard aGuard;
1701 ScTabViewShell* pViewSh = GetViewShell();
1702 if (pViewSh)
1704 // erst alles aufheben -> kein Stress mit Scrolling zwischendurch o.ae.
1706 pViewSh->RemoveSplit();
1708 Point aWinStart;
1709 Window* pWin = pViewSh->GetWindowByPos( SC_SPLIT_BOTTOMLEFT );
1710 if (pWin)
1711 aWinStart = pWin->GetPosPixel();
1713 ScViewData* pViewData = pViewSh->GetViewData();
1714 Point aSplit(pViewData->GetScrPos( (SCCOL)nColumns, (SCROW)nRows, SC_SPLIT_BOTTOMLEFT, sal_True ));
1715 aSplit += aWinStart;
1717 pViewSh->SplitAtPixel( aSplit, sal_True, sal_True );
1718 pViewSh->FreezeSplitters( sal_True );
1719 pViewSh->InvalidateSplit();
1723 void SAL_CALL ScTabViewObj::addSelectionChangeListener(
1724 const uno::Reference<view::XSelectionChangeListener>& xListener )
1725 throw(uno::RuntimeException)
1727 SolarMutexGuard aGuard;
1728 uno::Reference<view::XSelectionChangeListener>* pObj =
1729 new uno::Reference<view::XSelectionChangeListener>( xListener );
1730 aSelectionChgListeners.push_back( pObj );
1733 void SAL_CALL ScTabViewObj::removeSelectionChangeListener(
1734 const uno::Reference< view::XSelectionChangeListener >& xListener )
1735 throw(uno::RuntimeException)
1737 SolarMutexGuard aGuard;
1738 for (XSelectionChangeListenerVector::iterator it = aSelectionChgListeners.begin();
1739 it != aSelectionChgListeners.end(); ++it )
1741 if ( *it == xListener ) //! wozu der Mumpitz mit queryInterface?
1743 aSelectionChgListeners.erase(it);
1744 break;
1749 void ScTabViewObj::SelectionChanged()
1751 // Selection changed so end any style preview
1752 // Note: executing this slot through the dispatcher
1753 // will cause the style dialog to be raised so we go
1754 // direct here
1755 ScFormatShell aShell( GetViewShell()->GetViewData() );
1756 SfxAllItemSet reqList( SFX_APP()->GetPool() );
1757 SfxRequest aReq( SID_STYLE_END_PREVIEW, 0, reqList );
1758 aShell.ExecuteStyle( aReq );
1759 lang::EventObject aEvent;
1760 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
1761 BOOST_FOREACH(const XSelectionChangeListenerUnoRef rListener, aSelectionChgListeners)
1762 rListener->selectionChanged( aEvent );
1764 // handle sheet events
1765 ScTabViewShell* pViewSh = GetViewShell();
1766 ScViewData* pViewData = pViewSh->GetViewData();
1767 ScDocShell* pDocSh = pViewData->GetDocShell();
1768 ScDocument* pDoc = pDocSh->GetDocument();
1769 SCTAB nTab = pViewData->GetTabNo();
1770 const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
1771 if (pEvents)
1773 const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_SELECT);
1774 if (pScript)
1776 // the macro parameter is the selection as returned by getSelection
1777 uno::Sequence<uno::Any> aParams(1);
1778 aParams[0] = getSelection();
1779 uno::Any aRet;
1780 uno::Sequence<sal_Int16> aOutArgsIndex;
1781 uno::Sequence<uno::Any> aOutArgs;
1782 /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
1785 if ( !mbLeftMousePressed ) // selection still in progress
1787 mbPendingSelectionChanged = false;
1790 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
1791 uno::Sequence< uno::Any > aArgs( 1 );
1792 aArgs[ 0 ] <<= getSelection();
1793 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_SELECT ), aArgs );
1795 catch( uno::Exception& )
1799 else
1801 mbPendingSelectionChanged = true;
1806 // XPropertySet (View-Optionen)
1807 //! auch an der Applikation anbieten?
1809 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTabViewObj::getPropertySetInfo()
1810 throw(uno::RuntimeException)
1812 SolarMutexGuard aGuard;
1813 static uno::Reference<beans::XPropertySetInfo> aRef(
1814 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1815 return aRef;
1818 void SAL_CALL ScTabViewObj::setPropertyValue(
1819 const OUString& aPropertyName, const uno::Any& aValue )
1820 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1821 lang::IllegalArgumentException, lang::WrappedTargetException,
1822 uno::RuntimeException)
1824 SolarMutexGuard aGuard;
1825 OUString aString(aPropertyName);
1827 if ( aString.equalsAscii(SC_UNO_FILTERED_RANGE_SELECTION) )
1829 bFilteredRangeSelection = ScUnoHelpFunctions::GetBoolFromAny(aValue);
1830 return;
1833 ScTabViewShell* pViewSh = GetViewShell();
1834 if (pViewSh)
1836 ScViewData* pViewData = pViewSh->GetViewData();
1837 const ScViewOptions& rOldOpt = pViewSh->GetViewData()->GetOptions();
1838 ScViewOptions aNewOpt(rOldOpt);
1840 if ( aString.equalsAscii( SC_UNO_COLROWHDR ) || aString.equalsAscii( OLD_UNO_COLROWHDR ) )
1841 aNewOpt.SetOption( VOPT_HEADER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1842 else if ( aString.equalsAscii( SC_UNO_HORSCROLL ) || aString.equalsAscii( OLD_UNO_HORSCROLL ) )
1843 aNewOpt.SetOption( VOPT_HSCROLL, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1844 else if ( aString.equalsAscii( SC_UNO_OUTLSYMB ) || aString.equalsAscii( OLD_UNO_OUTLSYMB ) )
1845 aNewOpt.SetOption( VOPT_OUTLINER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1846 else if ( aString.equalsAscii( SC_UNO_SHEETTABS ) || aString.equalsAscii( OLD_UNO_SHEETTABS ) )
1847 aNewOpt.SetOption( VOPT_TABCONTROLS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1848 else if ( aString.equalsAscii( SC_UNO_SHOWANCHOR ) )
1849 aNewOpt.SetOption( VOPT_ANCHOR, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1850 else if ( aString.equalsAscii( SC_UNO_SHOWFORM ) )
1851 aNewOpt.SetOption( VOPT_FORMULAS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1852 else if ( aString.equalsAscii( SC_UNO_SHOWGRID ) )
1853 aNewOpt.SetOption( VOPT_GRID, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1854 else if ( aString.equalsAscii( SC_UNO_SHOWHELP ) )
1855 aNewOpt.SetOption( VOPT_HELPLINES, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1856 else if ( aString.equalsAscii( SC_UNO_SHOWNOTES ) )
1857 aNewOpt.SetOption( VOPT_NOTES, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1858 else if ( aString.equalsAscii( SC_UNO_SHOWPAGEBR ) )
1859 aNewOpt.SetOption( VOPT_PAGEBREAKS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1860 else if ( aString.equalsAscii( SC_UNO_SHOWZERO ) )
1861 aNewOpt.SetOption( VOPT_NULLVALS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1862 else if ( aString.equalsAscii( SC_UNO_VALUEHIGH ) || aString.equalsAscii( OLD_UNO_VALUEHIGH ) )
1863 aNewOpt.SetOption( VOPT_SYNTAX, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1864 else if ( aString.equalsAscii( SC_UNO_VERTSCROLL ) || aString.equalsAscii( OLD_UNO_VERTSCROLL ) )
1865 aNewOpt.SetOption( VOPT_VSCROLL, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1866 else if ( aString.equalsAscii( SC_UNO_SHOWOBJ ) )
1868 sal_Int16 nIntVal = 0;
1869 if ( aValue >>= nIntVal )
1871 //#i80528# adapt to new range eventually
1872 if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1874 aNewOpt.SetObjMode( VOBJ_TYPE_OLE, (ScVObjMode)nIntVal);
1877 else if ( aString.equalsAscii( SC_UNO_SHOWCHARTS ) )
1879 sal_Int16 nIntVal = 0;
1880 if ( aValue >>= nIntVal )
1882 //#i80528# adapt to new range eventually
1883 if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1885 aNewOpt.SetObjMode( VOBJ_TYPE_CHART, (ScVObjMode)nIntVal);
1888 else if ( aString.equalsAscii( SC_UNO_SHOWDRAW ) )
1890 sal_Int16 nIntVal = 0;
1891 if ( aValue >>= nIntVal )
1893 //#i80528# adapt to new range eventually
1894 if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1896 aNewOpt.SetObjMode( VOBJ_TYPE_DRAW, (ScVObjMode)nIntVal);
1899 else if ( aString.equalsAscii( SC_UNO_GRIDCOLOR ) )
1901 sal_Int32 nIntVal = 0;
1902 if ( aValue >>= nIntVal )
1903 aNewOpt.SetGridColor( nIntVal, OUString() );
1905 else if ( aString.equalsAscii( SC_UNO_ZOOMTYPE ) )
1907 sal_Int16 nIntVal = 0;
1908 if ( aValue >>= nIntVal )
1909 SetZoomType(nIntVal);
1911 else if ( aString.equalsAscii( SC_UNO_ZOOMVALUE ) )
1913 sal_Int16 nIntVal = 0;
1914 if ( aValue >>= nIntVal )
1915 SetZoom(nIntVal);
1918 // Optionen werden an der View und am Dokument (fuer neue Views) gesetzt,
1919 // damit sie beim Speichern erhalten bleiben.
1920 //! An der App (Module) braeuchte man noch eine Extra-Moeglichkeit,
1921 //! das einzustellen (fuer neue Dokumente)
1923 if ( aNewOpt != rOldOpt )
1925 pViewData->SetOptions( aNewOpt );
1926 pViewData->GetDocument()->SetViewOptions( aNewOpt );
1927 pViewData->GetDocShell()->SetDocumentModified(); //! wirklich?
1929 pViewSh->UpdateFixPos();
1930 pViewSh->PaintGrid();
1931 pViewSh->PaintTop();
1932 pViewSh->PaintLeft();
1933 pViewSh->PaintExtras();
1934 pViewSh->InvalidateBorder();
1936 SfxBindings& rBindings = pViewSh->GetViewFrame()->GetBindings();
1937 rBindings.Invalidate( FID_TOGGLEHEADERS ); // -> Checks im Menue
1938 rBindings.Invalidate( FID_TOGGLESYNTAX );
1943 uno::Any SAL_CALL ScTabViewObj::getPropertyValue( const OUString& aPropertyName )
1944 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1945 uno::RuntimeException)
1947 SolarMutexGuard aGuard;
1948 OUString aString(aPropertyName);
1949 uno::Any aRet;
1951 if ( aString.equalsAscii(SC_UNO_FILTERED_RANGE_SELECTION) )
1953 ScUnoHelpFunctions::SetBoolInAny(aRet, bFilteredRangeSelection);
1954 return aRet;
1957 ScTabViewShell* pViewSh = GetViewShell();
1958 if (pViewSh)
1960 const ScViewOptions& rOpt = pViewSh->GetViewData()->GetOptions();
1962 if ( aString.equalsAscii( SC_UNO_COLROWHDR ) || aString.equalsAscii( OLD_UNO_COLROWHDR ) )
1963 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HEADER ) );
1964 else if ( aString.equalsAscii( SC_UNO_HORSCROLL ) || aString.equalsAscii( OLD_UNO_HORSCROLL ) )
1965 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HSCROLL ) );
1966 else if ( aString.equalsAscii( SC_UNO_OUTLSYMB ) || aString.equalsAscii( OLD_UNO_OUTLSYMB ) )
1967 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_OUTLINER ) );
1968 else if ( aString.equalsAscii( SC_UNO_SHEETTABS ) || aString.equalsAscii( OLD_UNO_SHEETTABS ) )
1969 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_TABCONTROLS ) );
1970 else if ( aString.equalsAscii( SC_UNO_SHOWANCHOR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_ANCHOR ) );
1971 else if ( aString.equalsAscii( SC_UNO_SHOWFORM ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_FORMULAS ) );
1972 else if ( aString.equalsAscii( SC_UNO_SHOWGRID ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_GRID ) );
1973 else if ( aString.equalsAscii( SC_UNO_SHOWHELP ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HELPLINES ) );
1974 else if ( aString.equalsAscii( SC_UNO_SHOWNOTES ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_NOTES ) );
1975 else if ( aString.equalsAscii( SC_UNO_SHOWPAGEBR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_PAGEBREAKS ) );
1976 else if ( aString.equalsAscii( SC_UNO_SHOWZERO ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_NULLVALS ) );
1977 else if ( aString.equalsAscii( SC_UNO_VALUEHIGH ) || aString.equalsAscii( OLD_UNO_VALUEHIGH ) )
1978 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_SYNTAX ) );
1979 else if ( aString.equalsAscii( SC_UNO_VERTSCROLL ) || aString.equalsAscii( OLD_UNO_VERTSCROLL ) )
1980 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_VSCROLL ) );
1981 else if ( aString.equalsAscii( SC_UNO_SHOWOBJ ) ) aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_OLE ) );
1982 else if ( aString.equalsAscii( SC_UNO_SHOWCHARTS ) ) aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_CHART ) );
1983 else if ( aString.equalsAscii( SC_UNO_SHOWDRAW ) ) aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_DRAW ) );
1984 else if ( aString.equalsAscii( SC_UNO_GRIDCOLOR ) ) aRet <<= (sal_Int32)( rOpt.GetGridColor().GetColor() );
1985 else if ( aString.equalsAscii( SC_UNO_VISAREA ) ) aRet <<= GetVisArea();
1986 else if ( aString.equalsAscii( SC_UNO_ZOOMTYPE ) ) aRet <<= GetZoomType();
1987 else if ( aString.equalsAscii( SC_UNO_ZOOMVALUE ) ) aRet <<= GetZoom();
1988 else if ( aString.equalsAscii( SC_UNO_VISAREASCREEN ) )
1990 ScViewData* pViewData = pViewSh->GetViewData();
1991 Window* pActiveWin = ( pViewData ? pViewData->GetActiveWin() : NULL );
1992 if ( pActiveWin )
1994 Rectangle aRect = pActiveWin->GetWindowExtentsRelative( NULL );
1995 aRet <<= AWTRectangle( aRect );
2000 return aRet;
2003 void SAL_CALL ScTabViewObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
2004 const uno::Reference<beans::XPropertyChangeListener >& xListener )
2005 throw(beans::UnknownPropertyException,
2006 lang::WrappedTargetException,
2007 uno::RuntimeException)
2009 SolarMutexGuard aGuard;
2010 uno::Reference<beans::XPropertyChangeListener>* pObj =
2011 new uno::Reference<beans::XPropertyChangeListener>( xListener );
2012 aPropertyChgListeners.push_back( pObj );
2015 void SAL_CALL ScTabViewObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
2016 const uno::Reference<beans::XPropertyChangeListener >& xListener )
2017 throw(beans::UnknownPropertyException,
2018 lang::WrappedTargetException,
2019 uno::RuntimeException)
2021 SolarMutexGuard aGuard;
2022 for (XViewPropertyChangeListenerVector::iterator it = aPropertyChgListeners.begin();
2023 it != aPropertyChgListeners.end(); ++it )
2025 if ( *it == xListener ) //! wozu der Mumpitz mit queryInterface?
2027 aPropertyChgListeners.erase(it);
2028 break;
2033 void SAL_CALL ScTabViewObj::addVetoableChangeListener( const OUString& /* PropertyName */,
2034 const uno::Reference<beans::XVetoableChangeListener >& /* aListener */ )
2035 throw(beans::UnknownPropertyException,
2036 lang::WrappedTargetException,
2037 uno::RuntimeException)
2041 void SAL_CALL ScTabViewObj::removeVetoableChangeListener( const OUString& /* PropertyName */,
2042 const uno::Reference<beans::XVetoableChangeListener >& /* aListener */ )
2043 throw(beans::UnknownPropertyException,
2044 lang::WrappedTargetException,
2045 uno::RuntimeException)
2049 void ScTabViewObj::VisAreaChanged()
2051 beans::PropertyChangeEvent aEvent;
2052 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2053 BOOST_FOREACH(const XViewPropertyChangeListenerUnoRef rListener, aPropertyChgListeners)
2054 rListener->propertyChange( aEvent );
2057 // XRangeSelection
2059 void SAL_CALL ScTabViewObj::startRangeSelection(
2060 const uno::Sequence<beans::PropertyValue>& aArguments )
2061 throw(uno::RuntimeException)
2063 SolarMutexGuard aGuard;
2064 ScTabViewShell* pViewSh = GetViewShell();
2065 if (pViewSh)
2067 OUString aInitVal, aTitle;
2068 sal_Bool bCloseOnButtonUp = false;
2069 sal_Bool bSingleCell = false;
2070 sal_Bool bMultiSelection = false;
2072 OUString aStrVal;
2073 const beans::PropertyValue* pPropArray = aArguments.getConstArray();
2074 long nPropCount = aArguments.getLength();
2075 for (long i = 0; i < nPropCount; i++)
2077 const beans::PropertyValue& rProp = pPropArray[i];
2078 OUString aPropName(rProp.Name);
2080 if (aPropName.equalsAscii( SC_UNONAME_CLOSEONUP ))
2081 bCloseOnButtonUp = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2082 else if (aPropName.equalsAscii( SC_UNONAME_TITLE ))
2084 if ( rProp.Value >>= aStrVal )
2085 aTitle = aStrVal;
2087 else if (aPropName.equalsAscii( SC_UNONAME_INITVAL ))
2089 if ( rProp.Value >>= aStrVal )
2090 aInitVal = aStrVal;
2092 else if (aPropName.equalsAscii( SC_UNONAME_SINGLECELL ))
2093 bSingleCell = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2094 else if (aPropName.equalsAscii( SC_UNONAME_MULTISEL ))
2095 bMultiSelection = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2098 pViewSh->StartSimpleRefDialog( aTitle, aInitVal, bCloseOnButtonUp, bSingleCell, bMultiSelection );
2102 void SAL_CALL ScTabViewObj::abortRangeSelection() throw(uno::RuntimeException)
2104 SolarMutexGuard aGuard;
2105 ScTabViewShell* pViewSh = GetViewShell();
2106 if (pViewSh)
2107 pViewSh->StopSimpleRefDialog();
2110 void SAL_CALL ScTabViewObj::addRangeSelectionListener(
2111 const uno::Reference<sheet::XRangeSelectionListener>& xListener )
2112 throw(uno::RuntimeException)
2114 SolarMutexGuard aGuard;
2115 uno::Reference<sheet::XRangeSelectionListener>* pObj =
2116 new uno::Reference<sheet::XRangeSelectionListener>( xListener );
2117 aRangeSelListeners.push_back( pObj );
2120 void SAL_CALL ScTabViewObj::removeRangeSelectionListener(
2121 const uno::Reference<sheet::XRangeSelectionListener>& xListener )
2122 throw(uno::RuntimeException)
2124 SolarMutexGuard aGuard;
2125 for (XRangeSelectionListenerVector::iterator it = aRangeSelListeners.begin();
2126 it != aRangeSelListeners.end(); ++it )
2128 if ( *it == xListener )
2130 aRangeSelListeners.erase(it);
2131 break;
2136 void SAL_CALL ScTabViewObj::addRangeSelectionChangeListener(
2137 const uno::Reference<sheet::XRangeSelectionChangeListener>& xListener )
2138 throw(uno::RuntimeException)
2140 SolarMutexGuard aGuard;
2141 uno::Reference<sheet::XRangeSelectionChangeListener>* pObj =
2142 new uno::Reference<sheet::XRangeSelectionChangeListener>( xListener );
2143 aRangeChgListeners.push_back( pObj );
2146 void SAL_CALL ScTabViewObj::removeRangeSelectionChangeListener(
2147 const uno::Reference<sheet::XRangeSelectionChangeListener>& xListener )
2148 throw(uno::RuntimeException)
2150 SolarMutexGuard aGuard;
2151 for (XRangeSelectionChangeListenerVector::iterator it = aRangeChgListeners.begin();
2152 it != aRangeChgListeners.end(); ++it )
2154 if ( *it == xListener )
2156 aRangeChgListeners.erase(it);
2157 break;
2162 void ScTabViewObj::RangeSelDone( const OUString& rText )
2164 sheet::RangeSelectionEvent aEvent;
2165 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2166 aEvent.RangeDescriptor = OUString( rText );
2168 // copy on the stack because listener could remove itself
2169 XRangeSelectionListenerVector const listeners(aRangeSelListeners);
2171 BOOST_FOREACH(const XRangeSelectionListenerUnoRef rListener, listeners)
2172 rListener->done( aEvent );
2175 void ScTabViewObj::RangeSelAborted( const OUString& rText )
2177 sheet::RangeSelectionEvent aEvent;
2178 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2179 aEvent.RangeDescriptor = OUString( rText );
2181 // copy on the stack because listener could remove itself
2182 XRangeSelectionListenerVector const listeners(aRangeSelListeners);
2184 BOOST_FOREACH(const XRangeSelectionListenerUnoRef rListener, listeners)
2185 rListener->aborted( aEvent );
2188 void ScTabViewObj::RangeSelChanged( const OUString& rText )
2190 sheet::RangeSelectionEvent aEvent;
2191 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2192 aEvent.RangeDescriptor = OUString( rText );
2194 // copy on the stack because listener could remove itself
2195 XRangeSelectionChangeListenerVector const listener(aRangeChgListeners);
2197 BOOST_FOREACH(const XRangeSelectionChangeListenerUnoRef rListener, listener)
2198 rListener->descriptorChanged( aEvent );
2201 // XServiceInfo
2203 OUString SAL_CALL ScTabViewObj::getImplementationName() throw(uno::RuntimeException)
2205 return OUString( "ScTabViewObj" );
2208 sal_Bool SAL_CALL ScTabViewObj::supportsService( const OUString& rServiceName )
2209 throw(uno::RuntimeException)
2211 return rServiceName.equalsAscii( SCTABVIEWOBJ_SERVICE ) ||
2212 rServiceName.equalsAscii( SCVIEWSETTINGS_SERVICE );
2215 uno::Sequence<OUString> SAL_CALL ScTabViewObj::getSupportedServiceNames()
2216 throw(uno::RuntimeException)
2218 uno::Sequence<OUString> aRet(2);
2219 OUString* pArray = aRet.getArray();
2220 pArray[0] = OUString( SCTABVIEWOBJ_SERVICE );
2221 pArray[1] = OUString( SCVIEWSETTINGS_SERVICE );
2222 return aRet;
2225 // XUnoTunnel
2227 sal_Int64 SAL_CALL ScTabViewObj::getSomething(
2228 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
2230 if ( rId.getLength() == 16 &&
2231 0 == memcmp( getUnoTunnelId().getConstArray(),
2232 rId.getConstArray(), 16 ) )
2234 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
2236 return 0;
2239 namespace
2241 class theScTabViewObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScTabViewObjUnoTunnelId> {};
2244 const uno::Sequence<sal_Int8>& ScTabViewObj::getUnoTunnelId()
2246 return theScTabViewObjUnoTunnelId::get().getSeq();
2249 ScTabViewObj* ScTabViewObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
2251 ScTabViewObj* pRet = NULL;
2252 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
2253 if (xUT.is())
2254 pRet = reinterpret_cast<ScTabViewObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
2255 return pRet;
2258 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL ScTabViewObj::getTransferable( ) throw (::com::sun::star::uno::RuntimeException)
2260 SolarMutexGuard aGuard;
2261 ScEditShell* pShell = PTR_CAST( ScEditShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2262 if (pShell)
2263 return pShell->GetEditView()->GetTransferable();
2265 ScDrawTextObjectBar* pTextShell = PTR_CAST( ScDrawTextObjectBar, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2266 if (pTextShell)
2268 ScViewData* pViewData = GetViewShell()->GetViewData();
2269 ScDrawView* pView = pViewData->GetScDrawView();
2270 OutlinerView* pOutView = pView->GetTextEditOutlinerView();
2271 if (pOutView)
2272 return pOutView->GetEditView().GetTransferable();
2275 ScDrawShell* pDrawShell = PTR_CAST( ScDrawShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2276 if (pDrawShell)
2277 return pDrawShell->GetDrawView()->CopyToTransferable();
2279 ScTransferObj* pObj = GetViewShell()->CopyToTransferable();
2280 uno::Reference<datatransfer::XTransferable> xTransferable( pObj );
2281 return xTransferable;
2284 void SAL_CALL ScTabViewObj::insertTransferable( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans ) throw (::com::sun::star::datatransfer::UnsupportedFlavorException, ::com::sun::star::uno::RuntimeException)
2286 SolarMutexGuard aGuard;
2287 ScEditShell* pShell = PTR_CAST( ScEditShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2288 if (pShell)
2289 pShell->GetEditView()->InsertText( xTrans, OUString(), false );
2290 else
2292 ScDrawTextObjectBar* pTextShell = PTR_CAST( ScDrawTextObjectBar, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2293 if (pTextShell)
2295 ScViewData* pViewData = GetViewShell()->GetViewData();
2296 ScDrawView* pView = pViewData->GetScDrawView();
2297 OutlinerView* pOutView = pView->GetTextEditOutlinerView();
2298 if ( pOutView )
2300 pOutView->GetEditView().InsertText( xTrans, OUString(), false );
2301 return;
2305 GetViewShell()->PasteFromTransferable( xTrans );
2309 namespace {
2311 uno::Sequence<sal_Int32> toSequence(const ScMarkData::MarkedTabsType& rSelected)
2313 uno::Sequence<sal_Int32> aRet(rSelected.size());
2314 ScMarkData::MarkedTabsType::const_iterator itr = rSelected.begin(), itrEnd = rSelected.end();
2315 for (size_t i = 0; itr != itrEnd; ++itr, ++i)
2316 aRet[i] = static_cast<sal_Int32>(*itr);
2318 return aRet;
2323 uno::Sequence<sal_Int32> ScTabViewObj::getSelectedSheets()
2324 throw (uno::RuntimeException)
2326 ScTabViewShell* pViewSh = GetViewShell();
2327 if (!pViewSh)
2328 return uno::Sequence<sal_Int32>();
2330 ScViewData* pViewData = pViewSh->GetViewData();
2331 if (!pViewData)
2332 return uno::Sequence<sal_Int32>();
2334 // #i95280# when printing from the shell, the view is never activated,
2335 // so Excel view settings must also be evaluated here.
2336 ScExtDocOptions* pExtOpt = pViewData->GetDocument()->GetExtDocOptions();
2337 if (pExtOpt && pExtOpt->IsChanged())
2339 pViewSh->GetViewData()->ReadExtOptions(*pExtOpt); // Excel view settings
2340 pViewSh->SetTabNo(pViewSh->GetViewData()->GetTabNo(), true);
2341 pExtOpt->SetChanged(false);
2344 return toSequence(pViewData->GetMarkData().GetSelectedTabs());
2347 ScPreviewObj::ScPreviewObj(ScPreviewShell* pViewSh) :
2348 SfxBaseController(pViewSh),
2349 mpViewShell(pViewSh)
2351 if (mpViewShell)
2352 StartListening(*mpViewShell);
2355 ScPreviewObj::~ScPreviewObj()
2357 if (mpViewShell)
2358 EndListening(*mpViewShell);
2361 uno::Any ScPreviewObj::queryInterface(const uno::Type& rType)
2362 throw(uno::RuntimeException)
2364 SC_QUERYINTERFACE(sheet::XSelectedSheetsSupplier)
2365 return SfxBaseController::queryInterface(rType);
2368 void ScPreviewObj::acquire() throw()
2370 SfxBaseController::acquire();
2373 void ScPreviewObj::release() throw()
2375 SfxBaseController::release();
2378 void ScPreviewObj::Notify(SfxBroadcaster&, const SfxHint& rHint)
2380 const SfxSimpleHint* p = dynamic_cast<const SfxSimpleHint*>(&rHint);
2381 if (p && p->GetId() == SFX_HINT_DYING)
2382 mpViewShell = NULL;
2385 uno::Sequence<sal_Int32> ScPreviewObj::getSelectedSheets()
2386 throw (uno::RuntimeException)
2388 ScPreview* p = mpViewShell->GetPreview();
2389 if (!p)
2390 return uno::Sequence<sal_Int32>();
2392 return toSequence(p->GetSelectedTabs());
2395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */