Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / sc / source / ui / unoobj / viewuno.cxx
blob4c40d4a39284570a3efafbe5033662f093ec2613
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/drawing/ShapeCollection.hpp>
23 #include <com/sun/star/script/vba/VBAEventId.hpp>
24 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
25 #include <com/sun/star/view/DocumentZoomType.hpp>
27 #include <editeng/outliner.hxx>
28 #include <svx/fmdpage.hxx>
29 #include <svx/svditer.hxx>
30 #include <svx/svdmark.hxx>
31 #include <svx/svdouno.hxx>
32 #include <svx/svdpage.hxx>
33 #include <svx/svdpagv.hxx>
34 #include <svx/svdview.hxx>
35 #include <svx/unoshape.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 <cppuhelper/supportsservice.hxx>
44 #include <toolkit/helper/convert.hxx>
45 #include <vcl/svapp.hxx>
47 #include "drawsh.hxx"
48 #include "drtxtob.hxx"
49 #include "transobj.hxx"
50 #include "editsh.hxx"
51 #include "viewuno.hxx"
52 #include "cellsuno.hxx"
53 #include "miscuno.hxx"
54 #include "tabvwsh.hxx"
55 #include "prevwsh.hxx"
56 #include "docsh.hxx"
57 #include "drwlayer.hxx"
58 #include "drawview.hxx"
59 #include "fupoor.hxx"
60 #include "sc.hrc"
61 #include "unonames.hxx"
62 #include "scmod.hxx"
63 #include "appoptio.hxx"
64 #include "gridwin.hxx"
65 #include "sheetevents.hxx"
66 #include "markdata.hxx"
67 #include "AccessibilityHints.hxx"
68 #include "scextopt.hxx"
69 #include "preview.hxx"
70 #include <svx/sdrhittesthelper.hxx>
71 #include <boost/foreach.hpp>
72 #include "formatsh.hxx"
73 #include <sfx2/app.hxx>
75 using namespace com::sun::star;
77 //! Clipping-Markierungen
79 // alles ohne Which-ID, Map nur fuer PropertySetInfo
81 static const SfxItemPropertyMapEntry* lcl_GetViewOptPropertyMap()
83 static const SfxItemPropertyMapEntry aViewOptPropertyMap_Impl[] =
85 {OUString(OLD_UNO_COLROWHDR), 0, getBooleanCppuType(), 0, 0},
86 {OUString(SC_UNO_GRIDCOLOR), 0, cppu::UnoType<sal_Int32>::get(), 0, 0},
87 {OUString(SC_UNO_COLROWHDR), 0, getBooleanCppuType(), 0, 0},
88 {OUString(SC_UNO_HORSCROLL), 0, getBooleanCppuType(), 0, 0},
89 {OUString(SC_UNO_SHEETTABS), 0, getBooleanCppuType(), 0, 0},
90 {OUString(SC_UNO_VERTSCROLL), 0, getBooleanCppuType(), 0, 0},
91 {OUString(SC_UNO_HIDESPELL), 0, getBooleanCppuType(), 0, 0}, /* deprecated #i91949 */
92 {OUString(OLD_UNO_HORSCROLL), 0, getBooleanCppuType(), 0, 0},
93 {OUString(SC_UNO_OUTLSYMB), 0, getBooleanCppuType(), 0, 0},
94 {OUString(SC_UNO_VALUEHIGH), 0, getBooleanCppuType(), 0, 0},
95 {OUString(OLD_UNO_OUTLSYMB), 0, getBooleanCppuType(), 0, 0},
96 {OUString(OLD_UNO_SHEETTABS), 0, getBooleanCppuType(), 0, 0},
97 {OUString(SC_UNO_SHOWANCHOR), 0, getBooleanCppuType(), 0, 0},
98 {OUString(SC_UNO_SHOWCHARTS), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
99 {OUString(SC_UNO_SHOWDRAW), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
100 {OUString(SC_UNO_SHOWFORM), 0, getBooleanCppuType(), 0, 0},
101 {OUString(SC_UNO_SHOWGRID), 0, getBooleanCppuType(), 0, 0},
102 {OUString(SC_UNO_SHOWHELP), 0, getBooleanCppuType(), 0, 0},
103 {OUString(SC_UNO_SHOWNOTES), 0, getBooleanCppuType(), 0, 0},
104 {OUString(SC_UNO_SHOWOBJ), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
105 {OUString(SC_UNO_SHOWPAGEBR), 0, getBooleanCppuType(), 0, 0},
106 {OUString(SC_UNO_SHOWZERO), 0, getBooleanCppuType(), 0, 0},
107 {OUString(OLD_UNO_VALUEHIGH), 0, getBooleanCppuType(), 0, 0},
108 {OUString(OLD_UNO_VERTSCROLL), 0, getBooleanCppuType(), 0, 0},
109 {OUString(SC_UNO_VISAREA), 0, cppu::UnoType<awt::Rectangle>::get(), 0, 0},
110 {OUString(SC_UNO_ZOOMTYPE), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
111 {OUString(SC_UNO_ZOOMVALUE), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
112 {OUString(SC_UNO_VISAREASCREEN),0, cppu::UnoType<awt::Rectangle>::get(), 0, 0},
113 { OUString(), 0, css::uno::Type(), 0, 0 }
115 return aViewOptPropertyMap_Impl;
118 #define SCTABVIEWOBJ_SERVICE "com.sun.star.sheet.SpreadsheetView"
119 #define SCVIEWSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetViewSettings"
121 SC_SIMPLE_SERVICE_INFO( ScViewPaneBase, "ScViewPaneObj", "com.sun.star.sheet.SpreadsheetViewPane" )
123 ScViewPaneBase::ScViewPaneBase(ScTabViewShell* pViewSh, sal_uInt16 nP) :
124 pViewShell( pViewSh ),
125 nPane( nP )
127 if (pViewShell)
128 StartListening(*pViewShell);
131 ScViewPaneBase::~ScViewPaneBase()
133 if (pViewShell)
134 EndListening(*pViewShell);
137 void ScViewPaneBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
139 if ( rHint.ISA( SfxSimpleHint ) &&
140 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
141 pViewShell = NULL;
144 uno::Any SAL_CALL ScViewPaneBase::queryInterface( const uno::Type& rType )
145 throw(uno::RuntimeException, std::exception)
147 SC_QUERYINTERFACE( sheet::XViewPane )
148 SC_QUERYINTERFACE( sheet::XCellRangeReferrer )
149 SC_QUERYINTERFACE( view::XFormLayerAccess )
150 SC_QUERYINTERFACE( view::XControlAccess )
151 SC_QUERYINTERFACE( lang::XServiceInfo )
152 SC_QUERYINTERFACE( lang::XTypeProvider )
154 return uno::Any(); // OWeakObject is in derived objects
157 uno::Sequence<uno::Type> SAL_CALL ScViewPaneBase::getTypes() throw(uno::RuntimeException, std::exception)
159 static uno::Sequence<uno::Type> aTypes;
160 if ( aTypes.getLength() == 0 )
162 aTypes.realloc(5);
163 uno::Type* pPtr = aTypes.getArray();
164 pPtr[0] = cppu::UnoType<sheet::XViewPane>::get();
165 pPtr[1] = cppu::UnoType<sheet::XCellRangeReferrer>::get();
166 pPtr[2] = cppu::UnoType<view::XFormLayerAccess>::get();
167 pPtr[3] = cppu::UnoType<lang::XServiceInfo>::get();
168 pPtr[4] = cppu::UnoType<lang::XTypeProvider>::get();
170 return aTypes;
173 uno::Sequence<sal_Int8> SAL_CALL ScViewPaneBase::getImplementationId()
174 throw(uno::RuntimeException, std::exception)
176 return css::uno::Sequence<sal_Int8>();
179 // XViewPane
181 sal_Int32 SAL_CALL ScViewPaneBase::getFirstVisibleColumn() throw(uno::RuntimeException, std::exception)
183 SolarMutexGuard aGuard;
184 if (pViewShell)
186 ScViewData* pViewData = pViewShell->GetViewData();
187 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
188 pViewData->GetActivePart() :
189 (ScSplitPos) nPane;
190 ScHSplitPos eWhichH = WhichH( eWhich );
192 return pViewData->GetPosX( eWhichH );
194 OSL_FAIL("keine View ?!?"); //! Exception?
195 return 0;
198 void SAL_CALL ScViewPaneBase::setFirstVisibleColumn(sal_Int32 nFirstVisibleColumn)
199 throw(uno::RuntimeException, std::exception)
201 SolarMutexGuard aGuard;
202 if (pViewShell)
204 ScViewData* pViewData = pViewShell->GetViewData();
205 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
206 pViewData->GetActivePart() :
207 (ScSplitPos) nPane;
208 ScHSplitPos eWhichH = WhichH( eWhich );
210 long nDeltaX = ((long)nFirstVisibleColumn) - pViewData->GetPosX( eWhichH );
211 pViewShell->ScrollX( nDeltaX, eWhichH );
215 sal_Int32 SAL_CALL ScViewPaneBase::getFirstVisibleRow() throw(uno::RuntimeException, std::exception)
217 SolarMutexGuard aGuard;
218 if (pViewShell)
220 ScViewData* pViewData = pViewShell->GetViewData();
221 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
222 pViewData->GetActivePart() :
223 (ScSplitPos) nPane;
224 ScVSplitPos eWhichV = WhichV( eWhich );
226 return pViewData->GetPosY( eWhichV );
228 OSL_FAIL("keine View ?!?"); //! Exception?
229 return 0;
232 void SAL_CALL ScViewPaneBase::setFirstVisibleRow( sal_Int32 nFirstVisibleRow )
233 throw(uno::RuntimeException, std::exception)
235 SolarMutexGuard aGuard;
236 if (pViewShell)
238 ScViewData* pViewData = pViewShell->GetViewData();
239 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
240 pViewData->GetActivePart() :
241 (ScSplitPos) nPane;
242 ScVSplitPos eWhichV = WhichV( eWhich );
244 long nDeltaY = ((long)nFirstVisibleRow) - pViewData->GetPosY( eWhichV );
245 pViewShell->ScrollY( nDeltaY, eWhichV );
249 table::CellRangeAddress SAL_CALL ScViewPaneBase::getVisibleRange()
250 throw(uno::RuntimeException, std::exception)
252 SolarMutexGuard aGuard;
253 table::CellRangeAddress aAdr;
254 if (pViewShell)
256 ScViewData* pViewData = pViewShell->GetViewData();
257 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
258 pViewData->GetActivePart() :
259 (ScSplitPos) nPane;
260 ScHSplitPos eWhichH = WhichH( eWhich );
261 ScVSplitPos eWhichV = WhichV( eWhich );
263 // VisibleCellsX gibt nur komplett sichtbare Zellen,
264 // VisibleRange in Excel auch teilweise sichtbare.
265 //! anpassen ???
267 SCCOL nVisX = pViewData->VisibleCellsX( eWhichH );
268 SCROW nVisY = pViewData->VisibleCellsY( eWhichV );
269 if (!nVisX) nVisX = 1; // irgendwas muss ja im Range sein
270 if (!nVisY) nVisY = 1;
271 aAdr.Sheet = pViewData->GetTabNo();
272 aAdr.StartColumn = pViewData->GetPosX( eWhichH );
273 aAdr.StartRow = pViewData->GetPosY( eWhichV );
274 aAdr.EndColumn = aAdr.StartColumn + nVisX - 1;
275 aAdr.EndRow = aAdr.StartRow + nVisY - 1;
277 return aAdr;
280 // XCellRangeSource
282 uno::Reference<table::XCellRange> SAL_CALL ScViewPaneBase::getReferredCells()
283 throw(uno::RuntimeException, std::exception)
285 SolarMutexGuard aGuard;
286 if (pViewShell)
288 ScDocShell* pDocSh = pViewShell->GetViewData()->GetDocShell();
290 table::CellRangeAddress aAdr(getVisibleRange()); //! Hilfsfunktion mit ScRange?
291 ScRange aRange( (SCCOL)aAdr.StartColumn, (SCROW)aAdr.StartRow, aAdr.Sheet,
292 (SCCOL)aAdr.EndColumn, (SCROW)aAdr.EndRow, aAdr.Sheet );
293 if ( aRange.aStart == aRange.aEnd )
294 return new ScCellObj( pDocSh, aRange.aStart );
295 else
296 return new ScCellRangeObj( pDocSh, aRange );
299 return NULL;
302 namespace
304 bool lcl_prepareFormShellCall( ScTabViewShell* _pViewShell, sal_uInt16 _nPane, FmFormShell*& _rpFormShell, Window*& _rpWindow, SdrView*& _rpSdrView )
306 if ( !_pViewShell )
307 return false;
309 ScViewData* pViewData = _pViewShell->GetViewData();
310 ScSplitPos eWhich = ( _nPane == SC_VIEWPANE_ACTIVE ) ?
311 pViewData->GetActivePart() :
312 (ScSplitPos) _nPane;
313 _rpWindow = _pViewShell->GetWindowByPos( eWhich );
314 _rpSdrView = _pViewShell->GetSdrView();
315 _rpFormShell = _pViewShell->GetFormShell();
316 return ( _rpFormShell != NULL ) && ( _rpSdrView != NULL )&& ( _rpWindow != NULL );
320 // XFormLayerAccess
321 uno::Reference< form::runtime::XFormController > SAL_CALL ScViewPaneBase::getFormController( const uno::Reference< form::XForm >& _Form ) throw (uno::RuntimeException, std::exception)
323 SolarMutexGuard aGuard;
325 uno::Reference< form::runtime::XFormController > xController;
327 Window* pWindow( NULL );
328 SdrView* pSdrView( NULL );
329 FmFormShell* pFormShell( NULL );
330 if ( lcl_prepareFormShellCall( pViewShell, nPane, pFormShell, pWindow, pSdrView ) )
331 xController = pFormShell->GetFormController( _Form, *pSdrView, *pWindow );
333 return xController;
336 sal_Bool SAL_CALL ScViewPaneBase::isFormDesignMode( ) throw (uno::RuntimeException, std::exception)
338 SolarMutexGuard aGuard;
340 bool bIsFormDesignMode( true );
342 FmFormShell* pFormShell( pViewShell ? pViewShell->GetFormShell() : NULL );
343 if ( pFormShell )
344 bIsFormDesignMode = pFormShell->IsDesignMode();
346 return bIsFormDesignMode;
349 void SAL_CALL ScViewPaneBase::setFormDesignMode( sal_Bool _DesignMode ) throw (uno::RuntimeException, std::exception)
351 SolarMutexGuard aGuard;
353 Window* pWindow( NULL );
354 SdrView* pSdrView( NULL );
355 FmFormShell* pFormShell( NULL );
356 if ( lcl_prepareFormShellCall( pViewShell, nPane, pFormShell, pWindow, pSdrView ) )
357 pFormShell->SetDesignMode( _DesignMode );
360 // XControlAccess
362 uno::Reference<awt::XControl> SAL_CALL ScViewPaneBase::getControl(
363 const uno::Reference<awt::XControlModel>& xModel )
364 throw(container::NoSuchElementException, uno::RuntimeException, std::exception)
366 SolarMutexGuard aGuard;
368 uno::Reference<awt::XControl> xRet;
370 Window* pWindow( NULL );
371 SdrView* pSdrView( NULL );
372 FmFormShell* pFormShell( NULL );
373 if ( lcl_prepareFormShellCall( pViewShell, nPane, pFormShell, pWindow, pSdrView ) )
374 pFormShell->GetFormControl( xModel, *pSdrView, *pWindow, xRet );
376 if ( !xRet.is() )
377 throw container::NoSuchElementException(); // no control found
379 return xRet;
382 awt::Rectangle ScViewPaneBase::GetVisArea() const
384 awt::Rectangle aVisArea;
385 if (pViewShell)
387 ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
388 pViewShell->GetViewData()->GetActivePart() :
389 (ScSplitPos) nPane;
390 ScGridWindow* pWindow = (ScGridWindow*)pViewShell->GetWindowByPos(eWhich);
391 ScDocument* pDoc = pViewShell->GetViewData()->GetDocument();
392 if (pWindow && pDoc)
394 ScHSplitPos eWhichH = ((eWhich == SC_SPLIT_TOPLEFT) || (eWhich == SC_SPLIT_BOTTOMLEFT)) ?
395 SC_SPLIT_LEFT : SC_SPLIT_RIGHT;
396 ScVSplitPos eWhichV = ((eWhich == SC_SPLIT_TOPLEFT) || (eWhich == SC_SPLIT_TOPRIGHT)) ?
397 SC_SPLIT_TOP : SC_SPLIT_BOTTOM;
398 ScAddress aCell(pViewShell->GetViewData()->GetPosX(eWhichH),
399 pViewShell->GetViewData()->GetPosY(eWhichV),
400 pViewShell->GetViewData()->GetTabNo());
401 Rectangle aCellRect( pDoc->GetMMRect( aCell.Col(), aCell.Row(), aCell.Col(), aCell.Row(), aCell.Tab() ) );
402 Size aVisSize( pWindow->PixelToLogic( pWindow->GetSizePixel(), pWindow->GetDrawMapMode( true ) ) );
403 Point aVisPos( aCellRect.TopLeft() );
404 if ( pDoc->IsLayoutRTL( aCell.Tab() ) )
406 aVisPos = aCellRect.TopRight();
407 aVisPos.X() -= aVisSize.Width();
409 Rectangle aVisRect( aVisPos, aVisSize );
410 aVisArea = AWTRectangle(aVisRect);
413 return aVisArea;
416 ScViewPaneObj::ScViewPaneObj(ScTabViewShell* pViewSh, sal_uInt16 nP) :
417 ScViewPaneBase( pViewSh, nP )
421 ScViewPaneObj::~ScViewPaneObj()
425 uno::Any SAL_CALL ScViewPaneObj::queryInterface( const uno::Type& rType )
426 throw(uno::RuntimeException, std::exception)
428 // ScViewPaneBase has everything except OWeakObject
430 uno::Any aRet(ScViewPaneBase::queryInterface( rType ));
431 if (!aRet.hasValue())
432 aRet = OWeakObject::queryInterface( rType );
433 return aRet;
436 void SAL_CALL ScViewPaneObj::acquire() throw()
438 OWeakObject::acquire();
441 void SAL_CALL ScViewPaneObj::release() throw()
443 OWeakObject::release();
446 // Default-ctor wird fuer SMART_REFLECTION_IMPLEMENTATION gebraucht
448 ScTabViewObj::ScTabViewObj( ScTabViewShell* pViewSh ) :
449 ScViewPaneBase( pViewSh, SC_VIEWPANE_ACTIVE ),
450 SfxBaseController( pViewSh ),
451 aPropSet( lcl_GetViewOptPropertyMap() ),
452 aMouseClickHandlers( 0 ),
453 aActivationListeners( 0 ),
454 nPreviousTab( 0 ),
455 bDrawSelModeSet(false),
456 bFilteredRangeSelection(false),
457 mbLeftMousePressed(false),
458 mbPendingSelectionChanged(false)
460 if (pViewSh)
461 nPreviousTab = pViewSh->GetViewData()->GetTabNo();
464 ScTabViewObj::~ScTabViewObj()
466 //! Listening oder so
467 if (!aMouseClickHandlers.empty())
469 acquire();
470 EndMouseListening();
472 if (!aActivationListeners.empty())
474 acquire();
475 EndActivationListening();
479 uno::Any SAL_CALL ScTabViewObj::queryInterface( const uno::Type& rType )
480 throw(uno::RuntimeException, std::exception)
482 SC_QUERYINTERFACE( sheet::XSpreadsheetView )
483 SC_QUERYINTERFACE( sheet::XEnhancedMouseClickBroadcaster )
484 SC_QUERYINTERFACE( sheet::XActivationBroadcaster )
485 SC_QUERYINTERFACE( container::XEnumerationAccess )
486 SC_QUERYINTERFACE( container::XIndexAccess )
487 SC_QUERY_MULTIPLE( container::XElementAccess, container::XIndexAccess )
488 SC_QUERYINTERFACE( view::XSelectionSupplier )
489 SC_QUERYINTERFACE( beans::XPropertySet )
490 SC_QUERYINTERFACE( sheet::XViewSplitable )
491 SC_QUERYINTERFACE( sheet::XViewFreezable )
492 SC_QUERYINTERFACE( sheet::XRangeSelection )
493 SC_QUERYINTERFACE( lang::XUnoTunnel )
494 SC_QUERYINTERFACE( datatransfer::XTransferableSupplier )
495 SC_QUERYINTERFACE( sheet::XSelectedSheetsSupplier )
497 uno::Any aRet(ScViewPaneBase::queryInterface( rType ));
498 if (!aRet.hasValue())
499 aRet = SfxBaseController::queryInterface( rType );
500 return aRet;
503 void SAL_CALL ScTabViewObj::acquire() throw()
505 SfxBaseController::acquire();
508 void SAL_CALL ScTabViewObj::release() throw()
510 SfxBaseController::release();
513 static void lcl_CallActivate( ScDocShell* pDocSh, SCTAB nTab, sal_Int32 nEvent )
515 ScDocument* pDoc = pDocSh->GetDocument();
516 // when deleting a sheet, nPreviousTab can be invalid
517 // (could be handled with reference updates)
518 if (!pDoc->HasTable(nTab))
519 return;
521 const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
522 if (pEvents)
524 const OUString* pScript = pEvents->GetScript(nEvent);
525 if (pScript)
527 uno::Any aRet;
528 uno::Sequence<uno::Any> aParams;
529 uno::Sequence<sal_Int16> aOutArgsIndex;
530 uno::Sequence<uno::Any> aOutArgs;
531 /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
535 // execute VBA event handlers
538 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
539 // the parameter is the clicked object, as in the mousePressed call above
540 uno::Sequence< uno::Any > aArgs( 1 );
541 aArgs[ 0 ] <<= nTab;
542 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( nEvent ), aArgs );
544 catch( uno::Exception& )
549 void ScTabViewObj::SheetChanged( bool bSameTabButMoved )
551 if ( !GetViewShell() )
552 return;
554 ScViewData* pViewData = GetViewShell()->GetViewData();
555 ScDocShell* pDocSh = pViewData->GetDocShell();
556 if (!aActivationListeners.empty())
558 sheet::ActivationEvent aEvent;
559 uno::Reference< sheet::XSpreadsheetView > xView(this);
560 uno::Reference< uno::XInterface > xSource(xView, uno::UNO_QUERY);
561 aEvent.Source = xSource;
562 aEvent.ActiveSheet = new ScTableSheetObj(pDocSh, pViewData->GetTabNo());
563 for (XActivationEventListenerVector::iterator it = aActivationListeners.begin(); it != aActivationListeners.end(); )
567 (*it)->activeSpreadsheetChanged( aEvent );
568 ++it;
570 catch( uno::Exception& )
572 it = aActivationListeners.erase( it);
577 /* Handle sheet events, but do not trigger event handlers, if the old
578 active sheet gets re-activated after inserting/deleting/moving a sheet. */
579 SCTAB nNewTab = pViewData->GetTabNo();
580 if ( !bSameTabButMoved && (nNewTab != nPreviousTab) )
582 lcl_CallActivate( pDocSh, nPreviousTab, SC_SHEETEVENT_UNFOCUS );
583 lcl_CallActivate( pDocSh, nNewTab, SC_SHEETEVENT_FOCUS );
585 nPreviousTab = nNewTab;
588 uno::Sequence<uno::Type> SAL_CALL ScTabViewObj::getTypes() throw(uno::RuntimeException, std::exception)
590 static uno::Sequence<uno::Type> aTypes;
591 if ( aTypes.getLength() == 0 )
593 uno::Sequence<uno::Type> aViewPaneTypes(ScViewPaneBase::getTypes());
594 long nViewPaneLen = aViewPaneTypes.getLength();
595 const uno::Type* pViewPanePtr = aViewPaneTypes.getConstArray();
597 uno::Sequence<uno::Type> aControllerTypes(SfxBaseController::getTypes());
598 long nControllerLen = aControllerTypes.getLength();
599 const uno::Type* pControllerPtr = aControllerTypes.getConstArray();
601 long nParentLen = nViewPaneLen + nControllerLen;
603 aTypes.realloc( nParentLen + 12 );
604 uno::Type* pPtr = aTypes.getArray();
605 pPtr[nParentLen + 0] = cppu::UnoType<sheet::XSpreadsheetView>::get();
606 pPtr[nParentLen + 1] = cppu::UnoType<container::XEnumerationAccess>::get();
607 pPtr[nParentLen + 2] = cppu::UnoType<container::XIndexAccess>::get();
608 pPtr[nParentLen + 3] = cppu::UnoType<view::XSelectionSupplier>::get();
609 pPtr[nParentLen + 4] = cppu::UnoType<beans::XPropertySet>::get();
610 pPtr[nParentLen + 5] = cppu::UnoType<sheet::XViewSplitable>::get();
611 pPtr[nParentLen + 6] = cppu::UnoType<sheet::XViewFreezable>::get();
612 pPtr[nParentLen + 7] = cppu::UnoType<sheet::XRangeSelection>::get();
613 pPtr[nParentLen + 8] = cppu::UnoType<lang::XUnoTunnel>::get();
614 pPtr[nParentLen + 9] = cppu::UnoType<sheet::XEnhancedMouseClickBroadcaster>::get();
615 pPtr[nParentLen + 10] = cppu::UnoType<sheet::XActivationBroadcaster>::get();
616 pPtr[nParentLen + 11] = cppu::UnoType<datatransfer::XTransferableSupplier>::get();
618 long i;
619 for (i=0; i<nViewPaneLen; i++)
620 pPtr[i] = pViewPanePtr[i]; // parent types first
621 for (i=0; i<nControllerLen; i++)
622 pPtr[nViewPaneLen+i] = pControllerPtr[i];
624 return aTypes;
627 uno::Sequence<sal_Int8> SAL_CALL ScTabViewObj::getImplementationId()
628 throw(uno::RuntimeException, std::exception)
630 return css::uno::Sequence<sal_Int8>();
633 // XDocumentView
635 static bool lcl_TabInRanges( SCTAB nTab, const ScRangeList& rRanges )
637 for (size_t i = 0, nCount = rRanges.size(); i < nCount; ++i)
639 const ScRange* pRange = rRanges[ i ];
640 if ( nTab >= pRange->aStart.Tab() && nTab <= pRange->aEnd.Tab() )
641 return true;
643 return false;
646 static void lcl_ShowObject( ScTabViewShell& rViewSh, ScDrawView& rDrawView, SdrObject* pSelObj )
648 bool bFound = false;
649 SCTAB nObjectTab = 0;
651 SdrModel* pModel = rDrawView.GetModel();
652 sal_uInt16 nPageCount = pModel->GetPageCount();
653 for (sal_uInt16 i=0; i<nPageCount && !bFound; i++)
655 SdrPage* pPage = pModel->GetPage(i);
656 if (pPage)
658 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
659 SdrObject* pObject = aIter.Next();
660 while (pObject && !bFound)
662 if ( pObject == pSelObj )
664 bFound = true;
665 nObjectTab = static_cast<SCTAB>(i);
667 pObject = aIter.Next();
672 if (bFound)
674 rViewSh.SetTabNo( nObjectTab );
675 rViewSh.ScrollToObject( pSelObj );
679 sal_Bool SAL_CALL ScTabViewObj::select( const uno::Any& aSelection )
680 throw(lang::IllegalArgumentException, uno::RuntimeException,
681 std::exception)
683 SolarMutexGuard aGuard;
684 ScTabViewShell* pViewSh = GetViewShell();
686 if ( !pViewSh )
687 return false;
689 //! Type of aSelection can be some specific interface instead of XInterface
691 bool bRet = false;
692 uno::Reference<uno::XInterface> xInterface(aSelection, uno::UNO_QUERY);
693 if ( !xInterface.is() ) //clear all selections
695 ScDrawView* pDrawView = pViewSh->GetScDrawView();
696 if (pDrawView)
698 pDrawView->ScEndTextEdit();
699 pDrawView->UnmarkAll();
701 else //#102232#; if there is no DrawView remove range selection
702 pViewSh->Unmark();
703 bRet = true;
706 if (bDrawSelModeSet) // remove DrawSelMode if set by API; if necessary it will be set again later
708 pViewSh->SetDrawSelMode(false);
709 pViewSh->UpdateLayerLocks();
710 bDrawSelModeSet = false;
713 if (bRet)
714 return bRet;
717 ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( xInterface );
718 uno::Reference<drawing::XShapes> xShapeColl( xInterface, uno::UNO_QUERY );
719 uno::Reference<drawing::XShape> xShapeSel( xInterface, uno::UNO_QUERY );
720 SvxShape* pShapeImp = SvxShape::getImplementation( xShapeSel );
722 if (pRangesImp) // Zell-Ranges
724 ScViewData* pViewData = pViewSh->GetViewData();
725 if ( pViewData->GetDocShell() == pRangesImp->GetDocShell() )
727 // Zuerst evtl. Drawing-Selektion aufheben
728 // (MarkListHasChanged hebt Tabellen-Selektion auf)
730 ScDrawView* pDrawView = pViewSh->GetScDrawView();
731 if (pDrawView)
733 pDrawView->ScEndTextEdit();
734 pDrawView->UnmarkAll();
736 FuPoor* pFunc = pViewSh->GetDrawFuncPtr();
737 if ( pFunc && pFunc->GetSlotID() != SID_OBJECT_SELECT )
739 // Slot der Zeichenfunktion nochmal ausfuehren -> abschalten
740 SfxDispatcher* pDisp = pViewSh->GetDispatcher();
741 if (pDisp)
742 pDisp->Execute( pFunc->GetSlotID(), SFX_CALLMODE_SYNCHRON );
744 pViewSh->SetDrawShell(false);
745 pViewSh->SetDrawSelMode(false); // nach dem Dispatcher-Execute
747 // Ranges selektieren
749 const ScRangeList& rRanges = pRangesImp->GetRangeList();
750 size_t nRangeCount = rRanges.size();
751 // for empty range list, remove selection (cursor remains where it was)
752 if ( nRangeCount == 0 )
753 pViewSh->Unmark();
754 else if ( nRangeCount == 1 )
755 pViewSh->MarkRange( *rRanges[ 0 ] );
756 else
758 // Mehrfachselektion
760 const ScRange* pFirst = rRanges[ 0 ];
761 if ( pFirst && !lcl_TabInRanges( pViewData->GetTabNo(), rRanges ) )
762 pViewSh->SetTabNo( pFirst->aStart.Tab() );
763 pViewSh->DoneBlockMode();
764 pViewSh->InitOwnBlockMode();
765 pViewData->GetMarkData().MarkFromRangeList( rRanges, true );
766 pViewSh->MarkDataChanged();
767 pViewData->GetDocShell()->PostPaintGridAll(); // Markierung (alt&neu)
768 if ( pFirst )
770 pViewSh->AlignToCursor( pFirst->aStart.Col(), pFirst->aStart.Row(),
771 SC_FOLLOW_JUMP );
772 pViewSh->SetCursor( pFirst->aStart.Col(), pFirst->aStart.Row() );
775 //! Methode an der View, um RangeList zu selektieren
777 bRet = true;
780 else if ( pShapeImp || xShapeColl.is() ) // Drawing-Layer
782 ScDrawView* pDrawView = pViewSh->GetScDrawView();
783 if (pDrawView)
785 pDrawView->ScEndTextEdit();
786 pDrawView->UnmarkAll();
788 if (pShapeImp) // einzelnes Shape
790 SdrObject *pObj = pShapeImp->GetSdrObject();
791 if (pObj)
793 lcl_ShowObject( *pViewSh, *pDrawView, pObj );
794 SdrPageView* pPV = pDrawView->GetSdrPageView();
795 if ( pPV && pObj->GetPage() == pPV->GetPage() )
797 pDrawView->MarkObj( pObj, pPV );
798 bRet = true;
802 else // Shape-Collection (xShapeColl ist nicht 0)
804 // Es wird auf die Tabelle des ersten Objekts umgeschaltet,
805 // und alle Objekte selektiert, die auf dieser Tabelle liegen
806 //! Exception, wenn Objekte auf verschiedenen Tabellen?
808 long nCount = xShapeColl->getCount();
809 if (nCount)
811 SdrPageView* pPV = NULL;
812 bool bAllMarked(true);
813 for ( long i = 0; i < nCount; i++ )
815 uno::Reference<drawing::XShape> xShapeInt(xShapeColl->getByIndex(i), uno::UNO_QUERY);
816 if (xShapeInt.is())
818 SvxShape* pShape = SvxShape::getImplementation( xShapeInt );
819 if (pShape)
821 SdrObject *pObj = pShape->GetSdrObject();
822 if (pObj)
824 if (!bDrawSelModeSet && (pObj->GetLayer() == SC_LAYER_BACK))
826 pViewSh->SetDrawSelMode(true);
827 pViewSh->UpdateLayerLocks();
828 bDrawSelModeSet = true;
830 if (!pPV) // erstes Objekt
832 lcl_ShowObject( *pViewSh, *pDrawView, pObj );
833 pPV = pDrawView->GetSdrPageView();
835 if ( pPV && pObj->GetPage() == pPV->GetPage() )
837 if (pDrawView->IsObjMarkable( pObj, pPV ))
838 pDrawView->MarkObj( pObj, pPV );
839 else
840 bAllMarked = false;
846 if (bAllMarked)
847 bRet = true;
849 else
850 bRet = true; // empty XShapes (all shapes are deselected)
853 if (bRet)
854 pViewSh->SetDrawShell(true);
858 if (!bRet)
859 throw lang::IllegalArgumentException();
861 return bRet;
864 uno::Any SAL_CALL ScTabViewObj::getSelection()
865 throw(uno::RuntimeException, std::exception)
867 SolarMutexGuard aGuard;
868 ScTabViewShell* pViewSh = GetViewShell();
869 ScCellRangesBase* pObj = NULL;
870 if (pViewSh)
872 // Ist auf dem Drawing-Layer etwas selektiert?
874 SdrView* pDrawView = pViewSh->GetSdrView();
875 if (pDrawView)
877 const SdrMarkList& rMarkList = pDrawView->GetMarkedObjectList();
878 sal_uLong nMarkCount = rMarkList.GetMarkCount();
879 if (nMarkCount)
881 // ShapeCollection erzeugen (wie in SdXImpressView::getSelection im Draw)
882 // Zurueckgegeben wird XInterfaceRef, das muss das UsrObject-XInterface sein
884 uno::Reference< drawing::XShapes > xShapes = drawing::ShapeCollection::create(
885 comphelper::getProcessComponentContext());
887 uno::Reference<uno::XInterface> xRet(xShapes);
889 for (sal_uLong i=0; i<nMarkCount; i++)
891 SdrObject* pDrawObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
892 if (pDrawObj)
894 uno::Reference<drawing::XShape> xShape( pDrawObj->getUnoShape(), uno::UNO_QUERY );
895 if (xShape.is())
896 xShapes->add(xShape);
899 return uno::makeAny(xRet);
903 // sonst Tabellen-(Zellen-)Selektion
905 ScViewData* pViewData = pViewSh->GetViewData();
906 ScDocShell* pDocSh = pViewData->GetDocShell();
908 const ScMarkData& rMark = pViewData->GetMarkData();
909 SCTAB nTabs = rMark.GetSelectCount();
911 ScRange aRange;
912 ScMarkType eMarkType = pViewData->GetSimpleArea(aRange);
913 if ( nTabs == 1 && (eMarkType == SC_MARK_SIMPLE) )
915 if (aRange.aStart == aRange.aEnd)
916 pObj = new ScCellObj( pDocSh, aRange.aStart );
917 else
918 pObj = new ScCellRangeObj( pDocSh, aRange );
920 else if ( nTabs == 1 && (eMarkType == SC_MARK_SIMPLE_FILTERED) )
922 ScMarkData aFilteredMark( rMark );
923 ScViewUtil::UnmarkFiltered( aFilteredMark, pDocSh->GetDocument());
924 ScRangeList aRangeList;
925 aFilteredMark.FillRangeListWithMarks( &aRangeList, false);
926 // Theoretically a selection may start and end on a filtered row.
927 switch ( aRangeList.size() )
929 case 0:
930 // No unfiltered row, we have to return some object, so
931 // here is one with no ranges.
932 pObj = new ScCellRangesObj( pDocSh, aRangeList );
933 break;
934 case 1:
936 const ScRange& rRange = *(aRangeList[ 0 ]);
937 if (rRange.aStart == rRange.aEnd)
938 pObj = new ScCellObj( pDocSh, rRange.aStart );
939 else
940 pObj = new ScCellRangeObj( pDocSh, rRange );
942 break;
943 default:
944 pObj = new ScCellRangesObj( pDocSh, aRangeList );
947 else // Mehrfachselektion
949 ScRangeListRef xRanges;
950 pViewData->GetMultiArea( xRanges );
952 // bei mehreren Tabellen Ranges kopieren
953 //! sollte eigentlich schon in ScMarkData::FillRangeListWithMarks passieren?
954 if ( nTabs > 1 )
955 rMark.ExtendRangeListTables( xRanges );
957 pObj = new ScCellRangesObj( pDocSh, *xRanges );
960 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
962 // remember if the selection was from the cursor position without anything selected
963 // (used when rendering the selection)
965 pObj->SetCursorOnly( true );
969 return uno::makeAny(uno::Reference<uno::XInterface>(static_cast<cppu::OWeakObject*>(pObj)));
972 // XEnumerationAccess
974 uno::Reference<container::XEnumeration> SAL_CALL ScTabViewObj::createEnumeration()
975 throw(uno::RuntimeException, std::exception)
977 SolarMutexGuard aGuard;
978 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.SpreadsheetViewPanesEnumeration"));
981 // XIndexAccess
983 sal_Int32 SAL_CALL ScTabViewObj::getCount() throw(uno::RuntimeException, std::exception)
985 SolarMutexGuard aGuard;
986 ScTabViewShell* pViewSh = GetViewShell();
987 sal_uInt16 nPanes = 0;
988 if (pViewSh)
990 nPanes = 1;
991 ScViewData* pViewData = pViewSh->GetViewData();
992 if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
993 nPanes *= 2;
994 if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
995 nPanes *= 2;
997 return nPanes;
1000 uno::Any SAL_CALL ScTabViewObj::getByIndex( sal_Int32 nIndex )
1001 throw(lang::IndexOutOfBoundsException,
1002 lang::WrappedTargetException, uno::RuntimeException, std::exception)
1004 SolarMutexGuard aGuard;
1005 uno::Reference<sheet::XViewPane> xPane(GetObjectByIndex_Impl((sal_uInt16)nIndex));
1006 if (xPane.is())
1007 return uno::makeAny(xPane);
1008 else
1009 throw lang::IndexOutOfBoundsException();
1010 // return uno::Any();
1013 uno::Type SAL_CALL ScTabViewObj::getElementType() throw(uno::RuntimeException, std::exception)
1015 SolarMutexGuard aGuard;
1016 return cppu::UnoType<sheet::XViewPane>::get();
1019 sal_Bool SAL_CALL ScTabViewObj::hasElements() throw(uno::RuntimeException, std::exception)
1021 SolarMutexGuard aGuard;
1022 return ( getCount() != 0 );
1025 // XSpreadsheetView
1027 ScViewPaneObj* ScTabViewObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) const
1029 static const ScSplitPos ePosHV[4] =
1030 { SC_SPLIT_TOPLEFT, SC_SPLIT_BOTTOMLEFT, SC_SPLIT_TOPRIGHT, SC_SPLIT_BOTTOMRIGHT };
1032 ScTabViewShell* pViewSh = GetViewShell();
1033 if (pViewSh)
1035 ScSplitPos eWhich = SC_SPLIT_BOTTOMLEFT; // default Position
1036 bool bError = false;
1037 ScViewData* pViewData = pViewSh->GetViewData();
1038 bool bHor = ( pViewData->GetHSplitMode() != SC_SPLIT_NONE );
1039 bool bVer = ( pViewData->GetVSplitMode() != SC_SPLIT_NONE );
1040 if ( bHor && bVer )
1042 // links oben, links unten, rechts oben, rechts unten - wie in Excel
1043 if ( nIndex < 4 )
1044 eWhich = ePosHV[nIndex];
1045 else
1046 bError = true;
1048 else if ( bHor )
1050 if ( nIndex > 1 )
1051 bError = true;
1052 else if ( nIndex == 1 )
1053 eWhich = SC_SPLIT_BOTTOMRIGHT;
1054 // sonst SC_SPLIT_BOTTOMLEFT
1056 else if ( bVer )
1058 if ( nIndex > 1 )
1059 bError = true;
1060 else if ( nIndex == 0 )
1061 eWhich = SC_SPLIT_TOPLEFT;
1062 // sonst SC_SPLIT_BOTTOMLEFT
1064 else if ( nIndex > 0 )
1065 bError = true; // nicht geteilt: nur 0 gueltig
1067 if (!bError)
1068 return new ScViewPaneObj( pViewSh, sal::static_int_cast<sal_uInt16>(eWhich) );
1071 return NULL;
1074 uno::Reference<sheet::XSpreadsheet> SAL_CALL ScTabViewObj::getActiveSheet()
1075 throw(uno::RuntimeException, std::exception)
1077 SolarMutexGuard aGuard;
1078 ScTabViewShell* pViewSh = GetViewShell();
1079 if (pViewSh)
1081 ScViewData* pData = pViewSh->GetViewData();
1082 SCTAB nTab = pData->GetTabNo();
1083 return new ScTableSheetObj( pData->GetDocShell(), nTab );
1085 return NULL;
1088 // support expand (but not replace) the active sheet
1089 void SAL_CALL ScTabViewObj::setActiveSheet( const uno::Reference<sheet::XSpreadsheet>& xActiveSheet )
1090 throw(uno::RuntimeException, std::exception)
1092 SolarMutexGuard aGuard;
1094 ScTabViewShell* pViewSh = GetViewShell();
1095 if ( pViewSh && xActiveSheet.is() )
1097 // XSpreadsheet und ScCellRangesBase -> muss ein Sheet sein
1099 ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( xActiveSheet );
1100 if ( pRangesImp && pViewSh->GetViewData()->GetDocShell() == pRangesImp->GetDocShell() )
1102 const ScRangeList& rRanges = pRangesImp->GetRangeList();
1103 if ( rRanges.size() == 1 )
1105 SCTAB nNewTab = rRanges[ 0 ]->aStart.Tab();
1106 if ( pViewSh->GetViewData()->GetDocument()->HasTable(nNewTab) )
1107 pViewSh->SetTabNo( nNewTab );
1113 uno::Reference< uno::XInterface > ScTabViewObj::GetClickedObject(const Point& rPoint) const
1115 uno::Reference< uno::XInterface > xTarget;
1116 if (GetViewShell())
1118 SCsCOL nX;
1119 SCsROW nY;
1120 ScViewData* pData = GetViewShell()->GetViewData();
1121 ScSplitPos eSplitMode = pData->GetActivePart();
1122 SCTAB nTab(pData->GetTabNo());
1123 pData->GetPosFromPixel( rPoint.X(), rPoint.Y(), eSplitMode, nX, nY);
1125 ScAddress aCellPos (nX, nY, nTab);
1126 ScCellObj* pCellObj = new ScCellObj(pData->GetDocShell(), aCellPos);
1128 xTarget.set(uno::Reference<table::XCell>(pCellObj), uno::UNO_QUERY);
1130 ScDocument* pDoc = pData->GetDocument();
1131 if (pDoc && pDoc->GetDrawLayer())
1133 SdrPage* pDrawPage = NULL;
1134 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1135 if (pDrawLayer->HasObjects() && (pDrawLayer->GetPageCount() > nTab))
1136 pDrawPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
1138 SdrView* pDrawView = GetViewShell()->GetSdrView();
1140 if (pDrawPage && pDrawView && pDrawView->GetSdrPageView())
1142 Window* pActiveWin = pData->GetActiveWin();
1143 Point aPos = pActiveWin->PixelToLogic(rPoint);
1145 sal_uInt16 nHitLog = (sal_uInt16) pActiveWin->PixelToLogic(
1146 Size(pDrawView->GetHitTolerancePixel(),0)).Width();
1148 sal_uInt32 nCount(pDrawPage->GetObjCount());
1149 bool bFound(false);
1150 sal_uInt32 i(0);
1151 while (i < nCount && !bFound)
1153 SdrObject* pObj = pDrawPage->GetObj(i);
1154 if (pObj && SdrObjectPrimitiveHit(*pObj, aPos, nHitLog, *pDrawView->GetSdrPageView(), 0, false))
1156 xTarget.set(pObj->getUnoShape(), uno::UNO_QUERY);
1157 bFound = true;
1159 ++i;
1164 return xTarget;
1167 bool ScTabViewObj::IsMouseListening() const
1169 if ( !aMouseClickHandlers.empty() )
1170 return true;
1172 // also include sheet events, because MousePressed must be called for them
1173 ScViewData* pViewData = GetViewShell()->GetViewData();
1174 ScDocument* pDoc = pViewData->GetDocument();
1175 SCTAB nTab = pViewData->GetTabNo();
1176 return
1177 pDoc->HasSheetEventScript( nTab, SC_SHEETEVENT_RIGHTCLICK, true ) ||
1178 pDoc->HasSheetEventScript( nTab, SC_SHEETEVENT_DOUBLECLICK, true ) ||
1179 pDoc->HasSheetEventScript( nTab, SC_SHEETEVENT_SELECT, true );
1183 bool ScTabViewObj::MousePressed( const awt::MouseEvent& e )
1184 throw (::uno::RuntimeException)
1186 bool bReturn(false);
1187 if ( e.Buttons == ::com::sun::star::awt::MouseButton::LEFT )
1188 mbLeftMousePressed = true;
1190 uno::Reference< uno::XInterface > xTarget = GetClickedObject(Point(e.X, e.Y));
1191 if (!aMouseClickHandlers.empty() && xTarget.is())
1193 awt::EnhancedMouseEvent aMouseEvent;
1195 aMouseEvent.Buttons = e.Buttons;
1196 aMouseEvent.X = e.X;
1197 aMouseEvent.Y = e.Y;
1198 aMouseEvent.ClickCount = e.ClickCount;
1199 aMouseEvent.PopupTrigger = e.PopupTrigger;
1200 aMouseEvent.Target = xTarget;
1201 aMouseEvent.Modifiers = e.Modifiers;
1203 for (XMouseClickHandlerVector::iterator it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); )
1207 if (!(*it)->mousePressed( aMouseEvent ))
1208 bReturn = true;
1209 ++it;
1211 catch ( uno::Exception& )
1213 it = aMouseClickHandlers.erase(it);
1218 // handle sheet events
1219 bool bDoubleClick = ( e.Buttons == awt::MouseButton::LEFT && e.ClickCount == 2 );
1220 bool bRightClick = ( e.Buttons == awt::MouseButton::RIGHT && e.ClickCount == 1 );
1221 if ( ( bDoubleClick || bRightClick ) && !bReturn && xTarget.is())
1223 sal_Int32 nEvent = bDoubleClick ? SC_SHEETEVENT_DOUBLECLICK : SC_SHEETEVENT_RIGHTCLICK;
1225 ScTabViewShell* pViewSh = GetViewShell();
1226 ScViewData* pViewData = pViewSh->GetViewData();
1227 ScDocShell* pDocSh = pViewData->GetDocShell();
1228 ScDocument* pDoc = pDocSh->GetDocument();
1229 SCTAB nTab = pViewData->GetTabNo();
1230 const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
1231 if (pEvents)
1233 const OUString* pScript = pEvents->GetScript(nEvent);
1234 if (pScript)
1236 // the macro parameter is the clicked object, as in the mousePressed call above
1237 uno::Sequence<uno::Any> aParams(1);
1238 aParams[0] <<= xTarget;
1240 uno::Any aRet;
1241 uno::Sequence<sal_Int16> aOutArgsIndex;
1242 uno::Sequence<uno::Any> aOutArgs;
1244 /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
1246 // look for a boolean return value of true
1247 bool bRetValue = false;
1248 if (aRet >>= bRetValue)
1250 if (bRetValue)
1251 bReturn = true;
1256 // execute VBA event handler
1257 if (!bReturn && xTarget.is()) try
1259 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
1260 // the parameter is the clicked object, as in the mousePressed call above
1261 uno::Sequence< uno::Any > aArgs( 1 );
1262 aArgs[ 0 ] <<= xTarget;
1263 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( nEvent ), aArgs );
1265 catch( util::VetoException& )
1267 bReturn = true;
1269 catch( uno::Exception& )
1274 return bReturn;
1277 bool ScTabViewObj::MouseReleased( const awt::MouseEvent& e )
1278 throw (uno::RuntimeException)
1280 if ( e.Buttons == ::com::sun::star::awt::MouseButton::LEFT )
1284 mbPendingSelectionChanged = false;
1285 ScTabViewShell* pViewSh = GetViewShell();
1286 ScViewData* pViewData = pViewSh->GetViewData();
1287 ScDocShell* pDocSh = pViewData->GetDocShell();
1288 ScDocument* pDoc = pDocSh->GetDocument();
1289 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
1290 uno::Sequence< uno::Any > aArgs( 1 );
1291 aArgs[ 0 ] <<= getSelection();
1292 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_SELECT ), aArgs );
1294 catch( uno::Exception& )
1297 mbLeftMousePressed = false;
1300 bool bReturn(false);
1302 if (!aMouseClickHandlers.empty())
1304 uno::Reference< uno::XInterface > xTarget = GetClickedObject(Point(e.X, e.Y));
1306 if (xTarget.is())
1308 awt::EnhancedMouseEvent aMouseEvent;
1310 aMouseEvent.Buttons = e.Buttons;
1311 aMouseEvent.X = e.X;
1312 aMouseEvent.Y = e.Y;
1313 aMouseEvent.ClickCount = e.ClickCount;
1314 aMouseEvent.PopupTrigger = e.PopupTrigger;
1315 aMouseEvent.Target = xTarget;
1316 aMouseEvent.Modifiers = e.Modifiers;
1318 for (XMouseClickHandlerVector::iterator it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); )
1322 if (!(*it)->mouseReleased( aMouseEvent ))
1323 bReturn = true;
1324 ++it;
1326 catch ( uno::Exception& )
1328 it = aMouseClickHandlers.erase(it);
1333 return bReturn;
1336 // XEnhancedMouseClickBroadcaster
1338 void ScTabViewObj::StartMouseListening()
1342 void ScTabViewObj::EndMouseListening()
1344 lang::EventObject aEvent;
1345 aEvent.Source = (cppu::OWeakObject*)this;
1346 BOOST_FOREACH(const XMouseClickHandlerUnoRef rListener, aMouseClickHandlers)
1350 rListener->disposing(aEvent);
1352 catch ( uno::Exception& )
1356 aMouseClickHandlers.clear();
1359 void ScTabViewObj::StartActivationListening()
1363 void ScTabViewObj::EndActivationListening()
1365 lang::EventObject aEvent;
1366 aEvent.Source = (cppu::OWeakObject*)this;
1367 BOOST_FOREACH(const XActivationEventListenerUnoRef rListener, aActivationListeners)
1371 rListener->disposing(aEvent);
1373 catch ( uno::Exception& )
1377 aActivationListeners.clear();
1380 void SAL_CALL ScTabViewObj::addEnhancedMouseClickHandler( const uno::Reference< awt::XEnhancedMouseClickHandler >& aListener )
1381 throw (uno::RuntimeException, std::exception)
1383 SolarMutexGuard aGuard;
1385 if (aListener.is())
1387 sal_uInt16 nCount = aMouseClickHandlers.size();
1388 uno::Reference<awt::XEnhancedMouseClickHandler> *pObj =
1389 new uno::Reference<awt::XEnhancedMouseClickHandler>( aListener );
1390 aMouseClickHandlers.push_back( pObj );
1392 if (aMouseClickHandlers.size() == 1 && nCount == 0) // only if a listener added
1393 StartMouseListening();
1397 void SAL_CALL ScTabViewObj::removeEnhancedMouseClickHandler( const uno::Reference< awt::XEnhancedMouseClickHandler >& aListener )
1398 throw (uno::RuntimeException, std::exception)
1400 SolarMutexGuard aGuard;
1401 sal_uInt16 nCount = aMouseClickHandlers.size();
1402 for (XMouseClickHandlerVector::iterator it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); )
1404 if ( *it == aListener )
1405 it = aMouseClickHandlers.erase(it);
1406 else
1407 ++it;
1409 if ((aMouseClickHandlers.size() == 0) && (nCount > 0)) // only if last listener removed
1410 EndMouseListening();
1413 // XActivationBroadcaster
1415 void SAL_CALL ScTabViewObj::addActivationEventListener( const uno::Reference< sheet::XActivationEventListener >& aListener )
1416 throw (uno::RuntimeException, std::exception)
1418 SolarMutexGuard aGuard;
1420 if (aListener.is())
1422 sal_uInt16 nCount = aActivationListeners.size();
1423 uno::Reference<sheet::XActivationEventListener> *pObj =
1424 new uno::Reference<sheet::XActivationEventListener>( aListener );
1425 aActivationListeners.push_back( pObj );
1427 if (aActivationListeners.size() == 1 && nCount == 0) // only if a listener added
1428 StartActivationListening();
1432 void SAL_CALL ScTabViewObj::removeActivationEventListener( const uno::Reference< sheet::XActivationEventListener >& aListener )
1433 throw (uno::RuntimeException, std::exception)
1435 SolarMutexGuard aGuard;
1436 sal_uInt16 nCount = aActivationListeners.size();
1437 for (XActivationEventListenerVector::iterator it = aActivationListeners.begin(); it != aActivationListeners.end(); )
1439 if ( *it == aListener )
1440 it = aActivationListeners.erase(it);
1441 else
1442 ++it;
1444 if ((aActivationListeners.size() == 0) && (nCount > 0)) // only if last listener removed
1445 EndActivationListening();
1448 sal_Int16 ScTabViewObj::GetZoom(void) const
1450 ScTabViewShell* pViewSh = GetViewShell();
1451 if (pViewSh)
1453 const Fraction& rZoomY = pViewSh->GetViewData()->GetZoomY(); // Y wird angezeigt
1454 return (sal_Int16)(( rZoomY.GetNumerator() * 100 ) / rZoomY.GetDenominator());
1456 return 0;
1459 void ScTabViewObj::SetZoom(sal_Int16 nZoom)
1461 ScTabViewShell* pViewSh = GetViewShell();
1462 if (pViewSh)
1464 if ( nZoom != GetZoom() && nZoom != 0 )
1466 if (!pViewSh->GetViewData()->IsPagebreakMode())
1468 ScModule* pScMod = SC_MOD();
1469 ScAppOptions aNewOpt(pScMod->GetAppOptions());
1470 aNewOpt.SetZoom( nZoom );
1471 aNewOpt.SetZoomType( pViewSh->GetViewData()->GetView()->GetZoomType() );
1472 pScMod->SetAppOptions( aNewOpt );
1475 Fraction aFract( nZoom, 100 );
1476 pViewSh->SetZoom( aFract, aFract, true );
1477 pViewSh->PaintGrid();
1478 pViewSh->PaintTop();
1479 pViewSh->PaintLeft();
1480 pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM );
1481 pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER );
1485 sal_Int16 ScTabViewObj::GetZoomType(void) const
1487 sal_Int16 aZoomType = view::DocumentZoomType::OPTIMAL;
1488 ScTabViewShell* pViewSh = GetViewShell();
1489 if (pViewSh)
1491 SvxZoomType eZoomType = pViewSh->GetViewData()->GetView()->GetZoomType();
1492 switch (eZoomType)
1494 case SVX_ZOOM_PERCENT:
1495 aZoomType = view::DocumentZoomType::BY_VALUE;
1496 break;
1497 case SVX_ZOOM_OPTIMAL:
1498 aZoomType = view::DocumentZoomType::OPTIMAL;
1499 break;
1500 case SVX_ZOOM_WHOLEPAGE:
1501 aZoomType = view::DocumentZoomType::ENTIRE_PAGE;
1502 break;
1503 case SVX_ZOOM_PAGEWIDTH:
1504 aZoomType = view::DocumentZoomType::PAGE_WIDTH;
1505 break;
1506 case SVX_ZOOM_PAGEWIDTH_NOBORDER:
1507 aZoomType = view::DocumentZoomType::PAGE_WIDTH_EXACT;
1508 break;
1511 return aZoomType;
1514 void ScTabViewObj::SetZoomType(sal_Int16 aZoomType)
1516 ScTabViewShell* pViewSh = GetViewShell();
1517 if (pViewSh)
1519 ScDBFunc* pView = pViewSh->GetViewData()->GetView();
1520 if (pView)
1522 SvxZoomType eZoomType;
1523 switch (aZoomType)
1525 case view::DocumentZoomType::BY_VALUE:
1526 eZoomType = SVX_ZOOM_PERCENT;
1527 break;
1528 case view::DocumentZoomType::OPTIMAL:
1529 eZoomType = SVX_ZOOM_OPTIMAL;
1530 break;
1531 case view::DocumentZoomType::ENTIRE_PAGE:
1532 eZoomType = SVX_ZOOM_WHOLEPAGE;
1533 break;
1534 case view::DocumentZoomType::PAGE_WIDTH:
1535 eZoomType = SVX_ZOOM_PAGEWIDTH;
1536 break;
1537 case view::DocumentZoomType::PAGE_WIDTH_EXACT:
1538 eZoomType = SVX_ZOOM_PAGEWIDTH_NOBORDER;
1539 break;
1540 default:
1541 eZoomType = SVX_ZOOM_OPTIMAL;
1543 sal_Int16 nZoom(GetZoom());
1544 sal_Int16 nOldZoom(nZoom);
1545 if ( eZoomType == SVX_ZOOM_PERCENT )
1547 if ( nZoom < MINZOOM ) nZoom = MINZOOM;
1548 if ( nZoom > MAXZOOM ) nZoom = MAXZOOM;
1550 else
1551 nZoom = pView->CalcZoom( eZoomType, nOldZoom );
1553 switch ( eZoomType )
1555 case SVX_ZOOM_WHOLEPAGE:
1556 case SVX_ZOOM_PAGEWIDTH:
1557 pView->SetZoomType( eZoomType, true );
1558 break;
1560 default:
1561 pView->SetZoomType( SVX_ZOOM_PERCENT, true );
1563 SetZoom( nZoom );
1568 sal_Bool SAL_CALL ScTabViewObj::getIsWindowSplit() throw(uno::RuntimeException, std::exception)
1570 SolarMutexGuard aGuard;
1571 // wie Menue-Slot SID_WINDOW_SPLIT
1573 ScTabViewShell* pViewSh = GetViewShell();
1574 if (pViewSh)
1576 ScViewData* pViewData = pViewSh->GetViewData();
1577 return ( pViewData->GetHSplitMode() == SC_SPLIT_NORMAL ||
1578 pViewData->GetVSplitMode() == SC_SPLIT_NORMAL );
1581 return false;
1584 sal_Bool SAL_CALL ScTabViewObj::hasFrozenPanes() throw(uno::RuntimeException, std::exception)
1586 SolarMutexGuard aGuard;
1587 // wie Menue-Slot SID_WINDOW_FIX
1589 ScTabViewShell* pViewSh = GetViewShell();
1590 if (pViewSh)
1592 ScViewData* pViewData = pViewSh->GetViewData();
1593 return ( pViewData->GetHSplitMode() == SC_SPLIT_FIX ||
1594 pViewData->GetVSplitMode() == SC_SPLIT_FIX );
1597 return false;
1600 sal_Int32 SAL_CALL ScTabViewObj::getSplitHorizontal() throw(uno::RuntimeException, std::exception)
1602 SolarMutexGuard aGuard;
1603 ScTabViewShell* pViewSh = GetViewShell();
1604 if (pViewSh)
1606 ScViewData* pViewData = pViewSh->GetViewData();
1607 if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
1608 return pViewData->GetHSplitPos();
1610 return 0;
1613 sal_Int32 SAL_CALL ScTabViewObj::getSplitVertical() throw(uno::RuntimeException, std::exception)
1615 SolarMutexGuard aGuard;
1616 ScTabViewShell* pViewSh = GetViewShell();
1617 if (pViewSh)
1619 ScViewData* pViewData = pViewSh->GetViewData();
1620 if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1621 return pViewData->GetVSplitPos();
1623 return 0;
1626 sal_Int32 SAL_CALL ScTabViewObj::getSplitColumn()
1627 throw(uno::RuntimeException, std::exception)
1629 SolarMutexGuard aGuard;
1630 ScTabViewShell* pViewSh = GetViewShell();
1631 if (pViewSh)
1633 ScViewData* pViewData = pViewSh->GetViewData();
1634 if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
1636 long nSplit = pViewData->GetHSplitPos();
1638 ScSplitPos ePos = SC_SPLIT_BOTTOMLEFT;
1639 if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1640 ePos = SC_SPLIT_TOPLEFT;
1642 SCsCOL nCol;
1643 SCsROW nRow;
1644 pViewData->GetPosFromPixel( nSplit, 0, ePos, nCol, nRow, false );
1645 if ( nCol > 0 )
1646 return nCol;
1649 return 0;
1652 sal_Int32 SAL_CALL ScTabViewObj::getSplitRow() throw(uno::RuntimeException, std::exception)
1654 SolarMutexGuard aGuard;
1655 ScTabViewShell* pViewSh = GetViewShell();
1656 if (pViewSh)
1658 ScViewData* pViewData = pViewSh->GetViewData();
1659 if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1661 long nSplit = pViewData->GetVSplitPos();
1663 ScSplitPos ePos = SC_SPLIT_TOPLEFT; // es ist vertikal geteilt
1664 SCsCOL nCol;
1665 SCsROW nRow;
1666 pViewData->GetPosFromPixel( 0, nSplit, ePos, nCol, nRow, false );
1667 if ( nRow > 0 )
1668 return nRow;
1671 return 0;
1674 void SAL_CALL ScTabViewObj::splitAtPosition( sal_Int32 nPixelX, sal_Int32 nPixelY )
1675 throw(uno::RuntimeException, std::exception)
1677 SolarMutexGuard aGuard;
1678 ScTabViewShell* pViewSh = GetViewShell();
1679 if (pViewSh)
1681 pViewSh->SplitAtPixel( Point( nPixelX, nPixelY ), true, true );
1682 pViewSh->FreezeSplitters( false );
1683 pViewSh->InvalidateSplit();
1687 void SAL_CALL ScTabViewObj::freezeAtPosition( sal_Int32 nColumns, sal_Int32 nRows )
1688 throw(uno::RuntimeException, std::exception)
1690 SolarMutexGuard aGuard;
1691 ScTabViewShell* pViewSh = GetViewShell();
1692 if (pViewSh)
1694 // erst alles aufheben -> kein Stress mit Scrolling zwischendurch o.ae.
1696 pViewSh->RemoveSplit();
1698 Point aWinStart;
1699 Window* pWin = pViewSh->GetWindowByPos( SC_SPLIT_BOTTOMLEFT );
1700 if (pWin)
1701 aWinStart = pWin->GetPosPixel();
1703 ScViewData* pViewData = pViewSh->GetViewData();
1704 Point aSplit(pViewData->GetScrPos( (SCCOL)nColumns, (SCROW)nRows, SC_SPLIT_BOTTOMLEFT, true ));
1705 aSplit += aWinStart;
1707 pViewSh->SplitAtPixel( aSplit, true, true );
1708 pViewSh->FreezeSplitters( true );
1709 pViewSh->InvalidateSplit();
1713 void SAL_CALL ScTabViewObj::addSelectionChangeListener(
1714 const uno::Reference<view::XSelectionChangeListener>& xListener )
1715 throw (uno::RuntimeException, std::exception)
1717 SolarMutexGuard aGuard;
1718 uno::Reference<view::XSelectionChangeListener>* pObj =
1719 new uno::Reference<view::XSelectionChangeListener>( xListener );
1720 aSelectionChgListeners.push_back( pObj );
1723 void SAL_CALL ScTabViewObj::removeSelectionChangeListener(
1724 const uno::Reference< view::XSelectionChangeListener >& xListener )
1725 throw(uno::RuntimeException, std::exception)
1727 SolarMutexGuard aGuard;
1728 for (XSelectionChangeListenerVector::iterator it = aSelectionChgListeners.begin();
1729 it != aSelectionChgListeners.end(); ++it )
1731 if ( *it == xListener ) //! wozu der Mumpitz mit queryInterface?
1733 aSelectionChgListeners.erase(it);
1734 break;
1739 void ScTabViewObj::SelectionChanged()
1741 // Selection changed so end any style preview
1742 // Note: executing this slot through the dispatcher
1743 // will cause the style dialog to be raised so we go
1744 // direct here
1745 ScFormatShell aShell( GetViewShell()->GetViewData() );
1746 SfxAllItemSet reqList( SFX_APP()->GetPool() );
1747 SfxRequest aReq( SID_STYLE_END_PREVIEW, 0, reqList );
1748 aShell.ExecuteStyle( aReq );
1749 lang::EventObject aEvent;
1750 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
1751 BOOST_FOREACH(const XSelectionChangeListenerUnoRef rListener, aSelectionChgListeners)
1752 rListener->selectionChanged( aEvent );
1754 // handle sheet events
1755 ScTabViewShell* pViewSh = GetViewShell();
1756 ScViewData* pViewData = pViewSh->GetViewData();
1757 ScDocShell* pDocSh = pViewData->GetDocShell();
1758 ScDocument* pDoc = pDocSh->GetDocument();
1759 SCTAB nTab = pViewData->GetTabNo();
1760 const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
1761 if (pEvents)
1763 const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_SELECT);
1764 if (pScript)
1766 // the macro parameter is the selection as returned by getSelection
1767 uno::Sequence<uno::Any> aParams(1);
1768 aParams[0] = getSelection();
1769 uno::Any aRet;
1770 uno::Sequence<sal_Int16> aOutArgsIndex;
1771 uno::Sequence<uno::Any> aOutArgs;
1772 /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
1775 if ( !mbLeftMousePressed ) // selection still in progress
1777 mbPendingSelectionChanged = false;
1780 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
1781 uno::Sequence< uno::Any > aArgs( 1 );
1782 aArgs[ 0 ] <<= getSelection();
1783 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_SELECT ), aArgs );
1785 catch( uno::Exception& )
1789 else
1791 mbPendingSelectionChanged = true;
1796 // XPropertySet (View-Optionen)
1797 //! auch an der Applikation anbieten?
1799 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTabViewObj::getPropertySetInfo()
1800 throw(uno::RuntimeException, std::exception)
1802 SolarMutexGuard aGuard;
1803 static uno::Reference<beans::XPropertySetInfo> aRef(
1804 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1805 return aRef;
1808 void SAL_CALL ScTabViewObj::setPropertyValue(
1809 const OUString& aPropertyName, const uno::Any& aValue )
1810 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1811 lang::IllegalArgumentException, lang::WrappedTargetException,
1812 uno::RuntimeException, std::exception)
1814 SolarMutexGuard aGuard;
1815 OUString aString(aPropertyName);
1817 if ( aString.equalsAscii(SC_UNO_FILTERED_RANGE_SELECTION) )
1819 bFilteredRangeSelection = ScUnoHelpFunctions::GetBoolFromAny(aValue);
1820 return;
1823 ScTabViewShell* pViewSh = GetViewShell();
1824 if (pViewSh)
1826 ScViewData* pViewData = pViewSh->GetViewData();
1827 const ScViewOptions& rOldOpt = pViewSh->GetViewData()->GetOptions();
1828 ScViewOptions aNewOpt(rOldOpt);
1830 if ( aString.equalsAscii( SC_UNO_COLROWHDR ) || aString.equalsAscii( OLD_UNO_COLROWHDR ) )
1831 aNewOpt.SetOption( VOPT_HEADER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1832 else if ( aString.equalsAscii( SC_UNO_HORSCROLL ) || aString.equalsAscii( OLD_UNO_HORSCROLL ) )
1833 aNewOpt.SetOption( VOPT_HSCROLL, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1834 else if ( aString.equalsAscii( SC_UNO_OUTLSYMB ) || aString.equalsAscii( OLD_UNO_OUTLSYMB ) )
1835 aNewOpt.SetOption( VOPT_OUTLINER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1836 else if ( aString.equalsAscii( SC_UNO_SHEETTABS ) || aString.equalsAscii( OLD_UNO_SHEETTABS ) )
1837 aNewOpt.SetOption( VOPT_TABCONTROLS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1838 else if ( aString.equalsAscii( SC_UNO_SHOWANCHOR ) )
1839 aNewOpt.SetOption( VOPT_ANCHOR, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1840 else if ( aString.equalsAscii( SC_UNO_SHOWFORM ) )
1841 aNewOpt.SetOption( VOPT_FORMULAS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1842 else if ( aString.equalsAscii( SC_UNO_SHOWGRID ) )
1843 aNewOpt.SetOption( VOPT_GRID, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1844 else if ( aString.equalsAscii( SC_UNO_SHOWHELP ) )
1845 aNewOpt.SetOption( VOPT_HELPLINES, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1846 else if ( aString.equalsAscii( SC_UNO_SHOWNOTES ) )
1847 aNewOpt.SetOption( VOPT_NOTES, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1848 else if ( aString.equalsAscii( SC_UNO_SHOWPAGEBR ) )
1849 aNewOpt.SetOption( VOPT_PAGEBREAKS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1850 else if ( aString.equalsAscii( SC_UNO_SHOWZERO ) )
1851 aNewOpt.SetOption( VOPT_NULLVALS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1852 else if ( aString.equalsAscii( SC_UNO_VALUEHIGH ) || aString.equalsAscii( OLD_UNO_VALUEHIGH ) )
1853 aNewOpt.SetOption( VOPT_SYNTAX, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1854 else if ( aString.equalsAscii( SC_UNO_VERTSCROLL ) || aString.equalsAscii( OLD_UNO_VERTSCROLL ) )
1855 aNewOpt.SetOption( VOPT_VSCROLL, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1856 else if ( aString.equalsAscii( SC_UNO_SHOWOBJ ) )
1858 sal_Int16 nIntVal = 0;
1859 if ( aValue >>= nIntVal )
1861 //#i80528# adapt to new range eventually
1862 if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1864 aNewOpt.SetObjMode( VOBJ_TYPE_OLE, (ScVObjMode)nIntVal);
1867 else if ( aString.equalsAscii( SC_UNO_SHOWCHARTS ) )
1869 sal_Int16 nIntVal = 0;
1870 if ( aValue >>= nIntVal )
1872 //#i80528# adapt to new range eventually
1873 if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1875 aNewOpt.SetObjMode( VOBJ_TYPE_CHART, (ScVObjMode)nIntVal);
1878 else if ( aString.equalsAscii( SC_UNO_SHOWDRAW ) )
1880 sal_Int16 nIntVal = 0;
1881 if ( aValue >>= nIntVal )
1883 //#i80528# adapt to new range eventually
1884 if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1886 aNewOpt.SetObjMode( VOBJ_TYPE_DRAW, (ScVObjMode)nIntVal);
1889 else if ( aString.equalsAscii( SC_UNO_GRIDCOLOR ) )
1891 sal_Int32 nIntVal = 0;
1892 if ( aValue >>= nIntVal )
1893 aNewOpt.SetGridColor( nIntVal, OUString() );
1895 else if ( aString.equalsAscii( SC_UNO_ZOOMTYPE ) )
1897 sal_Int16 nIntVal = 0;
1898 if ( aValue >>= nIntVal )
1899 SetZoomType(nIntVal);
1901 else if ( aString.equalsAscii( SC_UNO_ZOOMVALUE ) )
1903 sal_Int16 nIntVal = 0;
1904 if ( aValue >>= nIntVal )
1905 SetZoom(nIntVal);
1908 // Optionen werden an der View und am Dokument (fuer neue Views) gesetzt,
1909 // damit sie beim Speichern erhalten bleiben.
1910 //! An der App (Module) braeuchte man noch eine Extra-Moeglichkeit,
1911 //! das einzustellen (fuer neue Dokumente)
1913 if ( aNewOpt != rOldOpt )
1915 pViewData->SetOptions( aNewOpt );
1916 pViewData->GetDocument()->SetViewOptions( aNewOpt );
1917 pViewData->GetDocShell()->SetDocumentModified(); //! wirklich?
1919 pViewSh->UpdateFixPos();
1920 pViewSh->PaintGrid();
1921 pViewSh->PaintTop();
1922 pViewSh->PaintLeft();
1923 pViewSh->PaintExtras();
1924 pViewSh->InvalidateBorder();
1926 SfxBindings& rBindings = pViewSh->GetViewFrame()->GetBindings();
1927 rBindings.Invalidate( FID_TOGGLEHEADERS ); // -> Checks im Menue
1928 rBindings.Invalidate( FID_TOGGLESYNTAX );
1933 uno::Any SAL_CALL ScTabViewObj::getPropertyValue( const OUString& aPropertyName )
1934 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1935 uno::RuntimeException, std::exception)
1937 SolarMutexGuard aGuard;
1938 OUString aString(aPropertyName);
1939 uno::Any aRet;
1941 if ( aString.equalsAscii(SC_UNO_FILTERED_RANGE_SELECTION) )
1943 ScUnoHelpFunctions::SetBoolInAny(aRet, bFilteredRangeSelection);
1944 return aRet;
1947 ScTabViewShell* pViewSh = GetViewShell();
1948 if (pViewSh)
1950 const ScViewOptions& rOpt = pViewSh->GetViewData()->GetOptions();
1952 if ( aString.equalsAscii( SC_UNO_COLROWHDR ) || aString.equalsAscii( OLD_UNO_COLROWHDR ) )
1953 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HEADER ) );
1954 else if ( aString.equalsAscii( SC_UNO_HORSCROLL ) || aString.equalsAscii( OLD_UNO_HORSCROLL ) )
1955 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HSCROLL ) );
1956 else if ( aString.equalsAscii( SC_UNO_OUTLSYMB ) || aString.equalsAscii( OLD_UNO_OUTLSYMB ) )
1957 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_OUTLINER ) );
1958 else if ( aString.equalsAscii( SC_UNO_SHEETTABS ) || aString.equalsAscii( OLD_UNO_SHEETTABS ) )
1959 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_TABCONTROLS ) );
1960 else if ( aString.equalsAscii( SC_UNO_SHOWANCHOR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_ANCHOR ) );
1961 else if ( aString.equalsAscii( SC_UNO_SHOWFORM ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_FORMULAS ) );
1962 else if ( aString.equalsAscii( SC_UNO_SHOWGRID ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_GRID ) );
1963 else if ( aString.equalsAscii( SC_UNO_SHOWHELP ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HELPLINES ) );
1964 else if ( aString.equalsAscii( SC_UNO_SHOWNOTES ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_NOTES ) );
1965 else if ( aString.equalsAscii( SC_UNO_SHOWPAGEBR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_PAGEBREAKS ) );
1966 else if ( aString.equalsAscii( SC_UNO_SHOWZERO ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_NULLVALS ) );
1967 else if ( aString.equalsAscii( SC_UNO_VALUEHIGH ) || aString.equalsAscii( OLD_UNO_VALUEHIGH ) )
1968 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_SYNTAX ) );
1969 else if ( aString.equalsAscii( SC_UNO_VERTSCROLL ) || aString.equalsAscii( OLD_UNO_VERTSCROLL ) )
1970 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_VSCROLL ) );
1971 else if ( aString.equalsAscii( SC_UNO_SHOWOBJ ) ) aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_OLE ) );
1972 else if ( aString.equalsAscii( SC_UNO_SHOWCHARTS ) ) aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_CHART ) );
1973 else if ( aString.equalsAscii( SC_UNO_SHOWDRAW ) ) aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_DRAW ) );
1974 else if ( aString.equalsAscii( SC_UNO_GRIDCOLOR ) ) aRet <<= (sal_Int32)( rOpt.GetGridColor().GetColor() );
1975 else if ( aString.equalsAscii( SC_UNO_VISAREA ) ) aRet <<= GetVisArea();
1976 else if ( aString.equalsAscii( SC_UNO_ZOOMTYPE ) ) aRet <<= GetZoomType();
1977 else if ( aString.equalsAscii( SC_UNO_ZOOMVALUE ) ) aRet <<= GetZoom();
1978 else if ( aString.equalsAscii( SC_UNO_VISAREASCREEN ) )
1980 ScViewData* pViewData = pViewSh->GetViewData();
1981 Window* pActiveWin = ( pViewData ? pViewData->GetActiveWin() : NULL );
1982 if ( pActiveWin )
1984 Rectangle aRect = pActiveWin->GetWindowExtentsRelative( NULL );
1985 aRet <<= AWTRectangle( aRect );
1990 return aRet;
1993 void SAL_CALL ScTabViewObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
1994 const uno::Reference<beans::XPropertyChangeListener >& xListener )
1995 throw (beans::UnknownPropertyException,
1996 lang::WrappedTargetException,
1997 uno::RuntimeException,
1998 std::exception)
2000 SolarMutexGuard aGuard;
2001 uno::Reference<beans::XPropertyChangeListener>* pObj =
2002 new uno::Reference<beans::XPropertyChangeListener>( xListener );
2003 aPropertyChgListeners.push_back( pObj );
2006 void SAL_CALL ScTabViewObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
2007 const uno::Reference<beans::XPropertyChangeListener >& xListener )
2008 throw(beans::UnknownPropertyException,
2009 lang::WrappedTargetException,
2010 uno::RuntimeException, std::exception)
2012 SolarMutexGuard aGuard;
2013 for (XViewPropertyChangeListenerVector::iterator it = aPropertyChgListeners.begin();
2014 it != aPropertyChgListeners.end(); ++it )
2016 if ( *it == xListener ) //! wozu der Mumpitz mit queryInterface?
2018 aPropertyChgListeners.erase(it);
2019 break;
2024 void SAL_CALL ScTabViewObj::addVetoableChangeListener( const OUString& /* PropertyName */,
2025 const uno::Reference<beans::XVetoableChangeListener >& /* aListener */ )
2026 throw(beans::UnknownPropertyException,
2027 lang::WrappedTargetException,
2028 uno::RuntimeException, std::exception)
2032 void SAL_CALL ScTabViewObj::removeVetoableChangeListener( const OUString& /* PropertyName */,
2033 const uno::Reference<beans::XVetoableChangeListener >& /* aListener */ )
2034 throw(beans::UnknownPropertyException,
2035 lang::WrappedTargetException,
2036 uno::RuntimeException, std::exception)
2040 void ScTabViewObj::VisAreaChanged()
2042 beans::PropertyChangeEvent aEvent;
2043 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2044 BOOST_FOREACH(const XViewPropertyChangeListenerUnoRef rListener, aPropertyChgListeners)
2045 rListener->propertyChange( aEvent );
2048 // XRangeSelection
2050 void SAL_CALL ScTabViewObj::startRangeSelection(
2051 const uno::Sequence<beans::PropertyValue>& aArguments )
2052 throw(uno::RuntimeException, std::exception)
2054 SolarMutexGuard aGuard;
2055 ScTabViewShell* pViewSh = GetViewShell();
2056 if (pViewSh)
2058 OUString aInitVal, aTitle;
2059 bool bCloseOnButtonUp = false;
2060 bool bSingleCell = false;
2061 bool bMultiSelection = false;
2063 OUString aStrVal;
2064 const beans::PropertyValue* pPropArray = aArguments.getConstArray();
2065 long nPropCount = aArguments.getLength();
2066 for (long i = 0; i < nPropCount; i++)
2068 const beans::PropertyValue& rProp = pPropArray[i];
2069 OUString aPropName(rProp.Name);
2071 if (aPropName.equalsAscii( SC_UNONAME_CLOSEONUP ))
2072 bCloseOnButtonUp = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2073 else if (aPropName.equalsAscii( SC_UNONAME_TITLE ))
2075 if ( rProp.Value >>= aStrVal )
2076 aTitle = aStrVal;
2078 else if (aPropName.equalsAscii( SC_UNONAME_INITVAL ))
2080 if ( rProp.Value >>= aStrVal )
2081 aInitVal = aStrVal;
2083 else if (aPropName.equalsAscii( SC_UNONAME_SINGLECELL ))
2084 bSingleCell = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2085 else if (aPropName.equalsAscii( SC_UNONAME_MULTISEL ))
2086 bMultiSelection = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2089 pViewSh->StartSimpleRefDialog( aTitle, aInitVal, bCloseOnButtonUp, bSingleCell, bMultiSelection );
2093 void SAL_CALL ScTabViewObj::abortRangeSelection() throw(uno::RuntimeException, std::exception)
2095 SolarMutexGuard aGuard;
2096 ScTabViewShell* pViewSh = GetViewShell();
2097 if (pViewSh)
2098 pViewSh->StopSimpleRefDialog();
2101 void SAL_CALL ScTabViewObj::addRangeSelectionListener(
2102 const uno::Reference<sheet::XRangeSelectionListener>& xListener )
2103 throw (uno::RuntimeException, std::exception)
2105 SolarMutexGuard aGuard;
2106 uno::Reference<sheet::XRangeSelectionListener>* pObj =
2107 new uno::Reference<sheet::XRangeSelectionListener>( xListener );
2108 aRangeSelListeners.push_back( pObj );
2111 void SAL_CALL ScTabViewObj::removeRangeSelectionListener(
2112 const uno::Reference<sheet::XRangeSelectionListener>& xListener )
2113 throw(uno::RuntimeException, std::exception)
2115 SolarMutexGuard aGuard;
2116 for (XRangeSelectionListenerVector::iterator it = aRangeSelListeners.begin();
2117 it != aRangeSelListeners.end(); ++it )
2119 if ( *it == xListener )
2121 aRangeSelListeners.erase(it);
2122 break;
2127 void SAL_CALL ScTabViewObj::addRangeSelectionChangeListener(
2128 const uno::Reference<sheet::XRangeSelectionChangeListener>& xListener )
2129 throw (uno::RuntimeException, std::exception)
2131 SolarMutexGuard aGuard;
2132 uno::Reference<sheet::XRangeSelectionChangeListener>* pObj =
2133 new uno::Reference<sheet::XRangeSelectionChangeListener>( xListener );
2134 aRangeChgListeners.push_back( pObj );
2137 void SAL_CALL ScTabViewObj::removeRangeSelectionChangeListener(
2138 const uno::Reference<sheet::XRangeSelectionChangeListener>& xListener )
2139 throw(uno::RuntimeException, std::exception)
2141 SolarMutexGuard aGuard;
2142 for (XRangeSelectionChangeListenerVector::iterator it = aRangeChgListeners.begin();
2143 it != aRangeChgListeners.end(); ++it )
2145 if ( *it == xListener )
2147 aRangeChgListeners.erase(it);
2148 break;
2153 void ScTabViewObj::RangeSelDone( const OUString& rText )
2155 sheet::RangeSelectionEvent aEvent;
2156 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2157 aEvent.RangeDescriptor = OUString( rText );
2159 // copy on the stack because listener could remove itself
2160 XRangeSelectionListenerVector const listeners(aRangeSelListeners);
2162 BOOST_FOREACH(const XRangeSelectionListenerUnoRef rListener, listeners)
2163 rListener->done( aEvent );
2166 void ScTabViewObj::RangeSelAborted( const OUString& rText )
2168 sheet::RangeSelectionEvent aEvent;
2169 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2170 aEvent.RangeDescriptor = OUString( rText );
2172 // copy on the stack because listener could remove itself
2173 XRangeSelectionListenerVector const listeners(aRangeSelListeners);
2175 BOOST_FOREACH(const XRangeSelectionListenerUnoRef rListener, listeners)
2176 rListener->aborted( aEvent );
2179 void ScTabViewObj::RangeSelChanged( const OUString& rText )
2181 sheet::RangeSelectionEvent aEvent;
2182 aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2183 aEvent.RangeDescriptor = OUString( rText );
2185 // copy on the stack because listener could remove itself
2186 XRangeSelectionChangeListenerVector const listener(aRangeChgListeners);
2188 BOOST_FOREACH(const XRangeSelectionChangeListenerUnoRef rListener, listener)
2189 rListener->descriptorChanged( aEvent );
2192 // XServiceInfo
2193 OUString SAL_CALL ScTabViewObj::getImplementationName() throw(uno::RuntimeException, std::exception)
2195 return OUString( "ScTabViewObj" );
2198 sal_Bool SAL_CALL ScTabViewObj::supportsService( const OUString& rServiceName )
2199 throw(uno::RuntimeException, std::exception)
2201 return cppu::supportsService(this, rServiceName);
2204 uno::Sequence<OUString> SAL_CALL ScTabViewObj::getSupportedServiceNames()
2205 throw(uno::RuntimeException, std::exception)
2207 uno::Sequence<OUString> aRet(2);
2208 OUString* pArray = aRet.getArray();
2209 pArray[0] = OUString( SCTABVIEWOBJ_SERVICE );
2210 pArray[1] = OUString( SCVIEWSETTINGS_SERVICE );
2211 return aRet;
2214 // XUnoTunnel
2216 sal_Int64 SAL_CALL ScTabViewObj::getSomething(
2217 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception)
2219 if ( rId.getLength() == 16 &&
2220 0 == memcmp( getUnoTunnelId().getConstArray(),
2221 rId.getConstArray(), 16 ) )
2223 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
2225 return 0;
2228 namespace
2230 class theScTabViewObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScTabViewObjUnoTunnelId> {};
2233 const uno::Sequence<sal_Int8>& ScTabViewObj::getUnoTunnelId()
2235 return theScTabViewObjUnoTunnelId::get().getSeq();
2238 ScTabViewObj* ScTabViewObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
2240 ScTabViewObj* pRet = NULL;
2241 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
2242 if (xUT.is())
2243 pRet = reinterpret_cast<ScTabViewObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
2244 return pRet;
2247 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL ScTabViewObj::getTransferable()
2248 throw (::com::sun::star::uno::RuntimeException,
2249 std::exception)
2251 SolarMutexGuard aGuard;
2252 ScEditShell* pShell = PTR_CAST( ScEditShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2253 if (pShell)
2254 return pShell->GetEditView()->GetTransferable();
2256 ScDrawTextObjectBar* pTextShell = PTR_CAST( ScDrawTextObjectBar, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2257 if (pTextShell)
2259 ScViewData* pViewData = GetViewShell()->GetViewData();
2260 ScDrawView* pView = pViewData->GetScDrawView();
2261 OutlinerView* pOutView = pView->GetTextEditOutlinerView();
2262 if (pOutView)
2263 return pOutView->GetEditView().GetTransferable();
2266 ScDrawShell* pDrawShell = PTR_CAST( ScDrawShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2267 if (pDrawShell)
2268 return pDrawShell->GetDrawView()->CopyToTransferable();
2270 ScTransferObj* pObj = GetViewShell()->CopyToTransferable();
2271 uno::Reference<datatransfer::XTransferable> xTransferable( pObj );
2272 return xTransferable;
2275 void SAL_CALL ScTabViewObj::insertTransferable( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans )
2276 throw (::com::sun::star::datatransfer::UnsupportedFlavorException,
2277 ::com::sun::star::uno::RuntimeException,
2278 std::exception)
2280 SolarMutexGuard aGuard;
2281 ScEditShell* pShell = PTR_CAST( ScEditShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2282 if (pShell)
2283 pShell->GetEditView()->InsertText( xTrans, OUString(), false );
2284 else
2286 ScDrawTextObjectBar* pTextShell = PTR_CAST( ScDrawTextObjectBar, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2287 if (pTextShell)
2289 ScViewData* pViewData = GetViewShell()->GetViewData();
2290 ScDrawView* pView = pViewData->GetScDrawView();
2291 OutlinerView* pOutView = pView->GetTextEditOutlinerView();
2292 if ( pOutView )
2294 pOutView->GetEditView().InsertText( xTrans, OUString(), false );
2295 return;
2299 GetViewShell()->PasteFromTransferable( xTrans );
2303 namespace {
2305 uno::Sequence<sal_Int32> toSequence(const ScMarkData::MarkedTabsType& rSelected)
2307 uno::Sequence<sal_Int32> aRet(rSelected.size());
2308 ScMarkData::MarkedTabsType::const_iterator itr = rSelected.begin(), itrEnd = rSelected.end();
2309 for (size_t i = 0; itr != itrEnd; ++itr, ++i)
2310 aRet[i] = static_cast<sal_Int32>(*itr);
2312 return aRet;
2317 uno::Sequence<sal_Int32> ScTabViewObj::getSelectedSheets()
2318 throw (uno::RuntimeException, std::exception)
2320 ScTabViewShell* pViewSh = GetViewShell();
2321 if (!pViewSh)
2322 return uno::Sequence<sal_Int32>();
2324 ScViewData* pViewData = pViewSh->GetViewData();
2325 if (!pViewData)
2326 return uno::Sequence<sal_Int32>();
2328 // #i95280# when printing from the shell, the view is never activated,
2329 // so Excel view settings must also be evaluated here.
2330 ScExtDocOptions* pExtOpt = pViewData->GetDocument()->GetExtDocOptions();
2331 if (pExtOpt && pExtOpt->IsChanged())
2333 pViewSh->GetViewData()->ReadExtOptions(*pExtOpt); // Excel view settings
2334 pViewSh->SetTabNo(pViewSh->GetViewData()->GetTabNo(), true);
2335 pExtOpt->SetChanged(false);
2338 return toSequence(pViewData->GetMarkData().GetSelectedTabs());
2341 ScPreviewObj::ScPreviewObj(ScPreviewShell* pViewSh) :
2342 SfxBaseController(pViewSh),
2343 mpViewShell(pViewSh)
2345 if (mpViewShell)
2346 StartListening(*mpViewShell);
2349 ScPreviewObj::~ScPreviewObj()
2351 if (mpViewShell)
2352 EndListening(*mpViewShell);
2355 uno::Any ScPreviewObj::queryInterface(const uno::Type& rType)
2356 throw(uno::RuntimeException, std::exception)
2358 SC_QUERYINTERFACE(sheet::XSelectedSheetsSupplier)
2359 return SfxBaseController::queryInterface(rType);
2362 void ScPreviewObj::acquire() throw()
2364 SfxBaseController::acquire();
2367 void ScPreviewObj::release() throw()
2369 SfxBaseController::release();
2372 void ScPreviewObj::Notify(SfxBroadcaster&, const SfxHint& rHint)
2374 const SfxSimpleHint* p = dynamic_cast<const SfxSimpleHint*>(&rHint);
2375 if (p && p->GetId() == SFX_HINT_DYING)
2376 mpViewShell = NULL;
2379 uno::Sequence<sal_Int32> ScPreviewObj::getSelectedSheets()
2380 throw (uno::RuntimeException, std::exception)
2382 ScPreview* p = mpViewShell->GetPreview();
2383 if (!p)
2384 return uno::Sequence<sal_Int32>();
2386 return toSequence(p->GetSelectedTabs());
2389 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */