Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <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>
26 :
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>
46 :
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"
74 :
75 : using namespace com::sun::star;
76 :
77 : //! Clipping-Markierungen
78 :
79 : // alles ohne Which-ID, Map nur fuer PropertySetInfo
80 :
81 0 : static const SfxItemPropertyMapEntry* lcl_GetViewOptPropertyMap()
82 : {
83 : static const SfxItemPropertyMapEntry aViewOptPropertyMap_Impl[] =
84 : {
85 0 : {OUString(OLD_UNO_COLROWHDR), 0, getBooleanCppuType(), 0, 0},
86 0 : {OUString(SC_UNO_GRIDCOLOR), 0, getCppuType((sal_Int32*)0), 0, 0},
87 0 : {OUString(SC_UNO_COLROWHDR), 0, getBooleanCppuType(), 0, 0},
88 0 : {OUString(SC_UNO_HORSCROLL), 0, getBooleanCppuType(), 0, 0},
89 0 : {OUString(SC_UNO_SHEETTABS), 0, getBooleanCppuType(), 0, 0},
90 0 : {OUString(SC_UNO_VERTSCROLL), 0, getBooleanCppuType(), 0, 0},
91 0 : {OUString(SC_UNO_HIDESPELL), 0, getBooleanCppuType(), 0, 0}, /* deprecated #i91949 */
92 0 : {OUString(OLD_UNO_HORSCROLL), 0, getBooleanCppuType(), 0, 0},
93 0 : {OUString(SC_UNO_OUTLSYMB), 0, getBooleanCppuType(), 0, 0},
94 0 : {OUString(SC_UNO_VALUEHIGH), 0, getBooleanCppuType(), 0, 0},
95 0 : {OUString(OLD_UNO_OUTLSYMB), 0, getBooleanCppuType(), 0, 0},
96 0 : {OUString(OLD_UNO_SHEETTABS), 0, getBooleanCppuType(), 0, 0},
97 0 : {OUString(SC_UNO_SHOWANCHOR), 0, getBooleanCppuType(), 0, 0},
98 0 : {OUString(SC_UNO_SHOWCHARTS), 0, getCppuType((sal_Int16*)0), 0, 0},
99 0 : {OUString(SC_UNO_SHOWDRAW), 0, getCppuType((sal_Int16*)0), 0, 0},
100 0 : {OUString(SC_UNO_SHOWFORM), 0, getBooleanCppuType(), 0, 0},
101 0 : {OUString(SC_UNO_SHOWGRID), 0, getBooleanCppuType(), 0, 0},
102 0 : {OUString(SC_UNO_SHOWHELP), 0, getBooleanCppuType(), 0, 0},
103 0 : {OUString(SC_UNO_SHOWNOTES), 0, getBooleanCppuType(), 0, 0},
104 0 : {OUString(SC_UNO_SHOWOBJ), 0, getCppuType((sal_Int16*)0), 0, 0},
105 0 : {OUString(SC_UNO_SHOWPAGEBR), 0, getBooleanCppuType(), 0, 0},
106 0 : {OUString(SC_UNO_SHOWZERO), 0, getBooleanCppuType(), 0, 0},
107 0 : {OUString(OLD_UNO_VALUEHIGH), 0, getBooleanCppuType(), 0, 0},
108 0 : {OUString(OLD_UNO_VERTSCROLL), 0, getBooleanCppuType(), 0, 0},
109 0 : {OUString(SC_UNO_VISAREA), 0, getCppuType((awt::Rectangle*)0), 0, 0},
110 0 : {OUString(SC_UNO_ZOOMTYPE), 0, getCppuType((sal_Int16*)0), 0, 0},
111 0 : {OUString(SC_UNO_ZOOMVALUE), 0, getCppuType((sal_Int16*)0), 0, 0},
112 0 : {OUString(SC_UNO_VISAREASCREEN),0, getCppuType((awt::Rectangle*)0), 0, 0},
113 : { OUString(), 0, css::uno::Type(), 0, 0 }
114 0 : };
115 0 : return aViewOptPropertyMap_Impl;
116 : }
117 :
118 : #define SCTABVIEWOBJ_SERVICE "com.sun.star.sheet.SpreadsheetView"
119 : #define SCVIEWSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetViewSettings"
120 :
121 0 : SC_SIMPLE_SERVICE_INFO( ScViewPaneBase, "ScViewPaneObj", "com.sun.star.sheet.SpreadsheetViewPane" )
122 :
123 0 : ScViewPaneBase::ScViewPaneBase(ScTabViewShell* pViewSh, sal_uInt16 nP) :
124 : pViewShell( pViewSh ),
125 0 : nPane( nP )
126 : {
127 0 : if (pViewShell)
128 0 : StartListening(*pViewShell);
129 0 : }
130 :
131 0 : ScViewPaneBase::~ScViewPaneBase()
132 : {
133 0 : if (pViewShell)
134 0 : EndListening(*pViewShell);
135 0 : }
136 :
137 0 : void ScViewPaneBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
138 : {
139 0 : if ( rHint.ISA( SfxSimpleHint ) &&
140 0 : ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
141 0 : pViewShell = NULL;
142 0 : }
143 :
144 0 : uno::Any SAL_CALL ScViewPaneBase::queryInterface( const uno::Type& rType )
145 : throw(uno::RuntimeException, std::exception)
146 : {
147 0 : SC_QUERYINTERFACE( sheet::XViewPane )
148 0 : SC_QUERYINTERFACE( sheet::XCellRangeReferrer )
149 0 : SC_QUERYINTERFACE( view::XFormLayerAccess )
150 0 : SC_QUERYINTERFACE( view::XControlAccess )
151 0 : SC_QUERYINTERFACE( lang::XServiceInfo )
152 0 : SC_QUERYINTERFACE( lang::XTypeProvider )
153 :
154 0 : return uno::Any(); // OWeakObject is in derived objects
155 : }
156 :
157 0 : uno::Sequence<uno::Type> SAL_CALL ScViewPaneBase::getTypes() throw(uno::RuntimeException, std::exception)
158 : {
159 0 : static uno::Sequence<uno::Type> aTypes;
160 0 : if ( aTypes.getLength() == 0 )
161 : {
162 0 : aTypes.realloc(5);
163 0 : uno::Type* pPtr = aTypes.getArray();
164 0 : pPtr[0] = getCppuType((const uno::Reference<sheet::XViewPane>*)0);
165 0 : pPtr[1] = getCppuType((const uno::Reference<sheet::XCellRangeReferrer>*)0);
166 0 : pPtr[2] = getCppuType((const uno::Reference<view::XFormLayerAccess>*)0);
167 0 : pPtr[3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
168 0 : pPtr[4] = getCppuType((const uno::Reference<lang::XTypeProvider>*)0);
169 : }
170 0 : return aTypes;
171 : }
172 :
173 0 : uno::Sequence<sal_Int8> SAL_CALL ScViewPaneBase::getImplementationId()
174 : throw(uno::RuntimeException, std::exception)
175 : {
176 0 : return css::uno::Sequence<sal_Int8>();
177 : }
178 :
179 : // XViewPane
180 :
181 0 : sal_Int32 SAL_CALL ScViewPaneBase::getFirstVisibleColumn() throw(uno::RuntimeException, std::exception)
182 : {
183 0 : SolarMutexGuard aGuard;
184 0 : if (pViewShell)
185 : {
186 0 : ScViewData* pViewData = pViewShell->GetViewData();
187 0 : ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
188 : pViewData->GetActivePart() :
189 0 : (ScSplitPos) nPane;
190 0 : ScHSplitPos eWhichH = WhichH( eWhich );
191 :
192 0 : return pViewData->GetPosX( eWhichH );
193 : }
194 : OSL_FAIL("keine View ?!?"); //! Exception?
195 0 : return 0;
196 : }
197 :
198 0 : void SAL_CALL ScViewPaneBase::setFirstVisibleColumn(sal_Int32 nFirstVisibleColumn)
199 : throw(uno::RuntimeException, std::exception)
200 : {
201 0 : SolarMutexGuard aGuard;
202 0 : if (pViewShell)
203 : {
204 0 : ScViewData* pViewData = pViewShell->GetViewData();
205 0 : ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
206 : pViewData->GetActivePart() :
207 0 : (ScSplitPos) nPane;
208 0 : ScHSplitPos eWhichH = WhichH( eWhich );
209 :
210 0 : long nDeltaX = ((long)nFirstVisibleColumn) - pViewData->GetPosX( eWhichH );
211 0 : pViewShell->ScrollX( nDeltaX, eWhichH );
212 0 : }
213 0 : }
214 :
215 0 : sal_Int32 SAL_CALL ScViewPaneBase::getFirstVisibleRow() throw(uno::RuntimeException, std::exception)
216 : {
217 0 : SolarMutexGuard aGuard;
218 0 : if (pViewShell)
219 : {
220 0 : ScViewData* pViewData = pViewShell->GetViewData();
221 0 : ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
222 : pViewData->GetActivePart() :
223 0 : (ScSplitPos) nPane;
224 0 : ScVSplitPos eWhichV = WhichV( eWhich );
225 :
226 0 : return pViewData->GetPosY( eWhichV );
227 : }
228 : OSL_FAIL("keine View ?!?"); //! Exception?
229 0 : return 0;
230 : }
231 :
232 0 : void SAL_CALL ScViewPaneBase::setFirstVisibleRow( sal_Int32 nFirstVisibleRow )
233 : throw(uno::RuntimeException, std::exception)
234 : {
235 0 : SolarMutexGuard aGuard;
236 0 : if (pViewShell)
237 : {
238 0 : ScViewData* pViewData = pViewShell->GetViewData();
239 0 : ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
240 : pViewData->GetActivePart() :
241 0 : (ScSplitPos) nPane;
242 0 : ScVSplitPos eWhichV = WhichV( eWhich );
243 :
244 0 : long nDeltaY = ((long)nFirstVisibleRow) - pViewData->GetPosY( eWhichV );
245 0 : pViewShell->ScrollY( nDeltaY, eWhichV );
246 0 : }
247 0 : }
248 :
249 0 : table::CellRangeAddress SAL_CALL ScViewPaneBase::getVisibleRange()
250 : throw(uno::RuntimeException, std::exception)
251 : {
252 0 : SolarMutexGuard aGuard;
253 0 : table::CellRangeAddress aAdr;
254 0 : if (pViewShell)
255 : {
256 0 : ScViewData* pViewData = pViewShell->GetViewData();
257 0 : ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
258 : pViewData->GetActivePart() :
259 0 : (ScSplitPos) nPane;
260 0 : ScHSplitPos eWhichH = WhichH( eWhich );
261 0 : ScVSplitPos eWhichV = WhichV( eWhich );
262 :
263 : // VisibleCellsX gibt nur komplett sichtbare Zellen,
264 : // VisibleRange in Excel auch teilweise sichtbare.
265 : //! anpassen ???
266 :
267 0 : SCCOL nVisX = pViewData->VisibleCellsX( eWhichH );
268 0 : SCROW nVisY = pViewData->VisibleCellsY( eWhichV );
269 0 : if (!nVisX) nVisX = 1; // irgendwas muss ja im Range sein
270 0 : if (!nVisY) nVisY = 1;
271 0 : aAdr.Sheet = pViewData->GetTabNo();
272 0 : aAdr.StartColumn = pViewData->GetPosX( eWhichH );
273 0 : aAdr.StartRow = pViewData->GetPosY( eWhichV );
274 0 : aAdr.EndColumn = aAdr.StartColumn + nVisX - 1;
275 0 : aAdr.EndRow = aAdr.StartRow + nVisY - 1;
276 : }
277 0 : return aAdr;
278 : }
279 :
280 : // XCellRangeSource
281 :
282 0 : uno::Reference<table::XCellRange> SAL_CALL ScViewPaneBase::getReferredCells()
283 : throw(uno::RuntimeException, std::exception)
284 : {
285 0 : SolarMutexGuard aGuard;
286 0 : if (pViewShell)
287 : {
288 0 : ScDocShell* pDocSh = pViewShell->GetViewData()->GetDocShell();
289 :
290 0 : table::CellRangeAddress aAdr(getVisibleRange()); //! Hilfsfunktion mit ScRange?
291 : ScRange aRange( (SCCOL)aAdr.StartColumn, (SCROW)aAdr.StartRow, aAdr.Sheet,
292 0 : (SCCOL)aAdr.EndColumn, (SCROW)aAdr.EndRow, aAdr.Sheet );
293 0 : if ( aRange.aStart == aRange.aEnd )
294 0 : return new ScCellObj( pDocSh, aRange.aStart );
295 : else
296 0 : return new ScCellRangeObj( pDocSh, aRange );
297 : }
298 :
299 0 : return NULL;
300 : }
301 :
302 : namespace
303 : {
304 0 : bool lcl_prepareFormShellCall( ScTabViewShell* _pViewShell, sal_uInt16 _nPane, FmFormShell*& _rpFormShell, Window*& _rpWindow, SdrView*& _rpSdrView )
305 : {
306 0 : if ( !_pViewShell )
307 0 : return false;
308 :
309 0 : ScViewData* pViewData = _pViewShell->GetViewData();
310 : ScSplitPos eWhich = ( _nPane == SC_VIEWPANE_ACTIVE ) ?
311 : pViewData->GetActivePart() :
312 0 : (ScSplitPos) _nPane;
313 0 : _rpWindow = _pViewShell->GetWindowByPos( eWhich );
314 0 : _rpSdrView = _pViewShell->GetSdrView();
315 0 : _rpFormShell = _pViewShell->GetFormShell();
316 0 : return ( _rpFormShell != NULL ) && ( _rpSdrView != NULL )&& ( _rpWindow != NULL );
317 : }
318 : }
319 :
320 : // XFormLayerAccess
321 0 : uno::Reference< form::runtime::XFormController > SAL_CALL ScViewPaneBase::getFormController( const uno::Reference< form::XForm >& _Form ) throw (uno::RuntimeException, std::exception)
322 : {
323 0 : SolarMutexGuard aGuard;
324 :
325 0 : uno::Reference< form::runtime::XFormController > xController;
326 :
327 0 : Window* pWindow( NULL );
328 0 : SdrView* pSdrView( NULL );
329 0 : FmFormShell* pFormShell( NULL );
330 0 : if ( lcl_prepareFormShellCall( pViewShell, nPane, pFormShell, pWindow, pSdrView ) )
331 0 : xController = pFormShell->GetFormController( _Form, *pSdrView, *pWindow );
332 :
333 0 : return xController;
334 : }
335 :
336 0 : sal_Bool SAL_CALL ScViewPaneBase::isFormDesignMode( ) throw (uno::RuntimeException, std::exception)
337 : {
338 0 : SolarMutexGuard aGuard;
339 :
340 0 : sal_Bool bIsFormDesignMode( sal_True );
341 :
342 0 : FmFormShell* pFormShell( pViewShell ? pViewShell->GetFormShell() : NULL );
343 0 : if ( pFormShell )
344 0 : bIsFormDesignMode = pFormShell->IsDesignMode();
345 :
346 0 : return bIsFormDesignMode;
347 : }
348 :
349 0 : void SAL_CALL ScViewPaneBase::setFormDesignMode( sal_Bool _DesignMode ) throw (uno::RuntimeException, std::exception)
350 : {
351 0 : SolarMutexGuard aGuard;
352 :
353 0 : Window* pWindow( NULL );
354 0 : SdrView* pSdrView( NULL );
355 0 : FmFormShell* pFormShell( NULL );
356 0 : if ( lcl_prepareFormShellCall( pViewShell, nPane, pFormShell, pWindow, pSdrView ) )
357 0 : pFormShell->SetDesignMode( _DesignMode );
358 0 : }
359 :
360 : // XControlAccess
361 :
362 0 : uno::Reference<awt::XControl> SAL_CALL ScViewPaneBase::getControl(
363 : const uno::Reference<awt::XControlModel>& xModel )
364 : throw(container::NoSuchElementException, uno::RuntimeException, std::exception)
365 : {
366 0 : SolarMutexGuard aGuard;
367 :
368 0 : uno::Reference<awt::XControl> xRet;
369 :
370 0 : Window* pWindow( NULL );
371 0 : SdrView* pSdrView( NULL );
372 0 : FmFormShell* pFormShell( NULL );
373 0 : if ( lcl_prepareFormShellCall( pViewShell, nPane, pFormShell, pWindow, pSdrView ) )
374 0 : pFormShell->GetFormControl( xModel, *pSdrView, *pWindow, xRet );
375 :
376 0 : if ( !xRet.is() )
377 0 : throw container::NoSuchElementException(); // no control found
378 :
379 0 : return xRet;
380 : }
381 :
382 0 : awt::Rectangle ScViewPaneBase::GetVisArea() const
383 : {
384 0 : awt::Rectangle aVisArea;
385 0 : if (pViewShell)
386 : {
387 0 : ScSplitPos eWhich = ( nPane == SC_VIEWPANE_ACTIVE ) ?
388 0 : pViewShell->GetViewData()->GetActivePart() :
389 0 : (ScSplitPos) nPane;
390 0 : ScGridWindow* pWindow = (ScGridWindow*)pViewShell->GetWindowByPos(eWhich);
391 0 : ScDocument* pDoc = pViewShell->GetViewData()->GetDocument();
392 0 : if (pWindow && pDoc)
393 : {
394 : ScHSplitPos eWhichH = ((eWhich == SC_SPLIT_TOPLEFT) || (eWhich == SC_SPLIT_BOTTOMLEFT)) ?
395 0 : SC_SPLIT_LEFT : SC_SPLIT_RIGHT;
396 : ScVSplitPos eWhichV = ((eWhich == SC_SPLIT_TOPLEFT) || (eWhich == SC_SPLIT_TOPRIGHT)) ?
397 0 : SC_SPLIT_TOP : SC_SPLIT_BOTTOM;
398 0 : ScAddress aCell(pViewShell->GetViewData()->GetPosX(eWhichH),
399 : pViewShell->GetViewData()->GetPosY(eWhichV),
400 0 : pViewShell->GetViewData()->GetTabNo());
401 0 : Rectangle aCellRect( pDoc->GetMMRect( aCell.Col(), aCell.Row(), aCell.Col(), aCell.Row(), aCell.Tab() ) );
402 0 : Size aVisSize( pWindow->PixelToLogic( pWindow->GetSizePixel(), pWindow->GetDrawMapMode( true ) ) );
403 0 : Point aVisPos( aCellRect.TopLeft() );
404 0 : if ( pDoc->IsLayoutRTL( aCell.Tab() ) )
405 : {
406 0 : aVisPos = aCellRect.TopRight();
407 0 : aVisPos.X() -= aVisSize.Width();
408 : }
409 0 : Rectangle aVisRect( aVisPos, aVisSize );
410 0 : aVisArea = AWTRectangle(aVisRect);
411 : }
412 : }
413 0 : return aVisArea;
414 : }
415 :
416 0 : ScViewPaneObj::ScViewPaneObj(ScTabViewShell* pViewSh, sal_uInt16 nP) :
417 0 : ScViewPaneBase( pViewSh, nP )
418 : {
419 0 : }
420 :
421 0 : ScViewPaneObj::~ScViewPaneObj()
422 : {
423 0 : }
424 :
425 0 : uno::Any SAL_CALL ScViewPaneObj::queryInterface( const uno::Type& rType )
426 : throw(uno::RuntimeException, std::exception)
427 : {
428 : // ScViewPaneBase has everything except OWeakObject
429 :
430 0 : uno::Any aRet(ScViewPaneBase::queryInterface( rType ));
431 0 : if (!aRet.hasValue())
432 0 : aRet = OWeakObject::queryInterface( rType );
433 0 : return aRet;
434 : }
435 :
436 0 : void SAL_CALL ScViewPaneObj::acquire() throw()
437 : {
438 0 : OWeakObject::acquire();
439 0 : }
440 :
441 0 : void SAL_CALL ScViewPaneObj::release() throw()
442 : {
443 0 : OWeakObject::release();
444 0 : }
445 :
446 : // Default-ctor wird fuer SMART_REFLECTION_IMPLEMENTATION gebraucht
447 :
448 0 : 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 0 : mbPendingSelectionChanged(false)
459 : {
460 0 : if (pViewSh)
461 0 : nPreviousTab = pViewSh->GetViewData()->GetTabNo();
462 0 : }
463 :
464 0 : ScTabViewObj::~ScTabViewObj()
465 : {
466 : //! Listening oder so
467 0 : if (!aMouseClickHandlers.empty())
468 : {
469 0 : acquire();
470 0 : EndMouseListening();
471 : }
472 0 : if (!aActivationListeners.empty())
473 : {
474 0 : acquire();
475 0 : EndActivationListening();
476 : }
477 0 : }
478 :
479 0 : uno::Any SAL_CALL ScTabViewObj::queryInterface( const uno::Type& rType )
480 : throw(uno::RuntimeException, std::exception)
481 : {
482 0 : SC_QUERYINTERFACE( sheet::XSpreadsheetView )
483 0 : SC_QUERYINTERFACE( sheet::XEnhancedMouseClickBroadcaster )
484 0 : SC_QUERYINTERFACE( sheet::XActivationBroadcaster )
485 0 : SC_QUERYINTERFACE( container::XEnumerationAccess )
486 0 : SC_QUERYINTERFACE( container::XIndexAccess )
487 0 : SC_QUERY_MULTIPLE( container::XElementAccess, container::XIndexAccess )
488 0 : SC_QUERYINTERFACE( view::XSelectionSupplier )
489 0 : SC_QUERYINTERFACE( beans::XPropertySet )
490 0 : SC_QUERYINTERFACE( sheet::XViewSplitable )
491 0 : SC_QUERYINTERFACE( sheet::XViewFreezable )
492 0 : SC_QUERYINTERFACE( sheet::XRangeSelection )
493 0 : SC_QUERYINTERFACE( lang::XUnoTunnel )
494 0 : SC_QUERYINTERFACE( datatransfer::XTransferableSupplier )
495 0 : SC_QUERYINTERFACE( sheet::XSelectedSheetsSupplier )
496 :
497 0 : uno::Any aRet(ScViewPaneBase::queryInterface( rType ));
498 0 : if (!aRet.hasValue())
499 0 : aRet = SfxBaseController::queryInterface( rType );
500 0 : return aRet;
501 : }
502 :
503 0 : void SAL_CALL ScTabViewObj::acquire() throw()
504 : {
505 0 : SfxBaseController::acquire();
506 0 : }
507 :
508 0 : void SAL_CALL ScTabViewObj::release() throw()
509 : {
510 0 : SfxBaseController::release();
511 0 : }
512 :
513 0 : static void lcl_CallActivate( ScDocShell* pDocSh, SCTAB nTab, sal_Int32 nEvent )
514 : {
515 0 : ScDocument* pDoc = pDocSh->GetDocument();
516 : // when deleting a sheet, nPreviousTab can be invalid
517 : // (could be handled with reference updates)
518 0 : if (!pDoc->HasTable(nTab))
519 0 : return;
520 :
521 0 : const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
522 0 : if (pEvents)
523 : {
524 0 : const OUString* pScript = pEvents->GetScript(nEvent);
525 0 : if (pScript)
526 : {
527 0 : uno::Any aRet;
528 0 : uno::Sequence<uno::Any> aParams;
529 0 : uno::Sequence<sal_Int16> aOutArgsIndex;
530 0 : uno::Sequence<uno::Any> aOutArgs;
531 0 : /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
532 : }
533 : }
534 :
535 : // execute VBA event handlers
536 : try
537 : {
538 0 : 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 0 : uno::Sequence< uno::Any > aArgs( 1 );
541 0 : aArgs[ 0 ] <<= nTab;
542 0 : xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( nEvent ), aArgs );
543 : }
544 0 : catch( uno::Exception& )
545 : {
546 : }
547 : }
548 :
549 0 : void ScTabViewObj::SheetChanged( bool bSameTabButMoved )
550 : {
551 0 : if ( !GetViewShell() )
552 0 : return;
553 :
554 0 : ScViewData* pViewData = GetViewShell()->GetViewData();
555 0 : ScDocShell* pDocSh = pViewData->GetDocShell();
556 0 : if (!aActivationListeners.empty())
557 : {
558 0 : sheet::ActivationEvent aEvent;
559 0 : uno::Reference< sheet::XSpreadsheetView > xView(this);
560 0 : uno::Reference< uno::XInterface > xSource(xView, uno::UNO_QUERY);
561 0 : aEvent.Source = xSource;
562 0 : aEvent.ActiveSheet = new ScTableSheetObj(pDocSh, pViewData->GetTabNo());
563 0 : for (XActivationEventListenerVector::iterator it = aActivationListeners.begin(); it != aActivationListeners.end(); )
564 : {
565 : try
566 : {
567 0 : (*it)->activeSpreadsheetChanged( aEvent );
568 0 : ++it;
569 : }
570 0 : catch( uno::Exception& )
571 : {
572 0 : it = aActivationListeners.erase( it);
573 : }
574 0 : }
575 : }
576 :
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 0 : SCTAB nNewTab = pViewData->GetTabNo();
580 0 : if ( !bSameTabButMoved && (nNewTab != nPreviousTab) )
581 : {
582 0 : lcl_CallActivate( pDocSh, nPreviousTab, SC_SHEETEVENT_UNFOCUS );
583 0 : lcl_CallActivate( pDocSh, nNewTab, SC_SHEETEVENT_FOCUS );
584 : }
585 0 : nPreviousTab = nNewTab;
586 : }
587 :
588 0 : uno::Sequence<uno::Type> SAL_CALL ScTabViewObj::getTypes() throw(uno::RuntimeException, std::exception)
589 : {
590 0 : static uno::Sequence<uno::Type> aTypes;
591 0 : if ( aTypes.getLength() == 0 )
592 : {
593 0 : uno::Sequence<uno::Type> aViewPaneTypes(ScViewPaneBase::getTypes());
594 0 : long nViewPaneLen = aViewPaneTypes.getLength();
595 0 : const uno::Type* pViewPanePtr = aViewPaneTypes.getConstArray();
596 :
597 0 : uno::Sequence<uno::Type> aControllerTypes(SfxBaseController::getTypes());
598 0 : long nControllerLen = aControllerTypes.getLength();
599 0 : const uno::Type* pControllerPtr = aControllerTypes.getConstArray();
600 :
601 0 : long nParentLen = nViewPaneLen + nControllerLen;
602 :
603 0 : aTypes.realloc( nParentLen + 12 );
604 0 : uno::Type* pPtr = aTypes.getArray();
605 0 : pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSpreadsheetView>*)0);
606 0 : pPtr[nParentLen + 1] = getCppuType((const uno::Reference<container::XEnumerationAccess>*)0);
607 0 : pPtr[nParentLen + 2] = getCppuType((const uno::Reference<container::XIndexAccess>*)0);
608 0 : pPtr[nParentLen + 3] = getCppuType((const uno::Reference<view::XSelectionSupplier>*)0);
609 0 : pPtr[nParentLen + 4] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
610 0 : pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XViewSplitable>*)0);
611 0 : pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XViewFreezable>*)0);
612 0 : pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XRangeSelection>*)0);
613 0 : pPtr[nParentLen + 8] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0);
614 0 : pPtr[nParentLen + 9] = getCppuType((const uno::Reference<sheet::XEnhancedMouseClickBroadcaster>*)0);
615 0 : pPtr[nParentLen + 10] = getCppuType((const uno::Reference<sheet::XActivationBroadcaster>*)0);
616 0 : pPtr[nParentLen + 11] = getCppuType((const uno::Reference<datatransfer::XTransferableSupplier>*)0);
617 :
618 : long i;
619 0 : for (i=0; i<nViewPaneLen; i++)
620 0 : pPtr[i] = pViewPanePtr[i]; // parent types first
621 0 : for (i=0; i<nControllerLen; i++)
622 0 : pPtr[nViewPaneLen+i] = pControllerPtr[i];
623 : }
624 0 : return aTypes;
625 : }
626 :
627 0 : uno::Sequence<sal_Int8> SAL_CALL ScTabViewObj::getImplementationId()
628 : throw(uno::RuntimeException, std::exception)
629 : {
630 0 : return css::uno::Sequence<sal_Int8>();
631 : }
632 :
633 : // XDocumentView
634 :
635 0 : static sal_Bool lcl_TabInRanges( SCTAB nTab, const ScRangeList& rRanges )
636 : {
637 0 : for (size_t i = 0, nCount = rRanges.size(); i < nCount; ++i)
638 : {
639 0 : const ScRange* pRange = rRanges[ i ];
640 0 : if ( nTab >= pRange->aStart.Tab() && nTab <= pRange->aEnd.Tab() )
641 0 : return sal_True;
642 : }
643 0 : return false;
644 : }
645 :
646 0 : static void lcl_ShowObject( ScTabViewShell& rViewSh, ScDrawView& rDrawView, SdrObject* pSelObj )
647 : {
648 0 : sal_Bool bFound = false;
649 0 : SCTAB nObjectTab = 0;
650 :
651 0 : SdrModel* pModel = rDrawView.GetModel();
652 0 : sal_uInt16 nPageCount = pModel->GetPageCount();
653 0 : for (sal_uInt16 i=0; i<nPageCount && !bFound; i++)
654 : {
655 0 : SdrPage* pPage = pModel->GetPage(i);
656 0 : if (pPage)
657 : {
658 0 : SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
659 0 : SdrObject* pObject = aIter.Next();
660 0 : while (pObject && !bFound)
661 : {
662 0 : if ( pObject == pSelObj )
663 : {
664 0 : bFound = sal_True;
665 0 : nObjectTab = static_cast<SCTAB>(i);
666 : }
667 0 : pObject = aIter.Next();
668 0 : }
669 : }
670 : }
671 :
672 0 : if (bFound)
673 : {
674 0 : rViewSh.SetTabNo( nObjectTab );
675 0 : rViewSh.ScrollToObject( pSelObj );
676 : }
677 0 : }
678 :
679 0 : sal_Bool SAL_CALL ScTabViewObj::select( const uno::Any& aSelection )
680 : throw(lang::IllegalArgumentException, uno::RuntimeException,
681 : std::exception)
682 : {
683 0 : SolarMutexGuard aGuard;
684 0 : ScTabViewShell* pViewSh = GetViewShell();
685 :
686 0 : if ( !pViewSh )
687 0 : return false;
688 :
689 : //! Type of aSelection can be some specific interface instead of XInterface
690 :
691 0 : sal_Bool bRet = false;
692 0 : uno::Reference<uno::XInterface> xInterface(aSelection, uno::UNO_QUERY);
693 0 : if ( !xInterface.is() ) //clear all selections
694 : {
695 0 : ScDrawView* pDrawView = pViewSh->GetScDrawView();
696 0 : if (pDrawView)
697 : {
698 0 : pDrawView->ScEndTextEdit();
699 0 : pDrawView->UnmarkAll();
700 : }
701 : else //#102232#; if there is no DrawView remove range selection
702 0 : pViewSh->Unmark();
703 0 : bRet = sal_True;
704 : }
705 :
706 0 : if (bDrawSelModeSet) // remove DrawSelMode if set by API; if necessary it will be set again later
707 : {
708 0 : pViewSh->SetDrawSelMode(false);
709 0 : pViewSh->UpdateLayerLocks();
710 0 : bDrawSelModeSet = false;
711 : }
712 :
713 0 : if (bRet)
714 0 : return bRet;
715 :
716 :
717 0 : ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( xInterface );
718 0 : uno::Reference<drawing::XShapes> xShapeColl( xInterface, uno::UNO_QUERY );
719 0 : uno::Reference<drawing::XShape> xShapeSel( xInterface, uno::UNO_QUERY );
720 0 : SvxShape* pShapeImp = SvxShape::getImplementation( xShapeSel );
721 :
722 0 : if (pRangesImp) // Zell-Ranges
723 : {
724 0 : ScViewData* pViewData = pViewSh->GetViewData();
725 0 : if ( pViewData->GetDocShell() == pRangesImp->GetDocShell() )
726 : {
727 : // Zuerst evtl. Drawing-Selektion aufheben
728 : // (MarkListHasChanged hebt Tabellen-Selektion auf)
729 :
730 0 : ScDrawView* pDrawView = pViewSh->GetScDrawView();
731 0 : if (pDrawView)
732 : {
733 0 : pDrawView->ScEndTextEdit();
734 0 : pDrawView->UnmarkAll();
735 : }
736 0 : FuPoor* pFunc = pViewSh->GetDrawFuncPtr();
737 0 : if ( pFunc && pFunc->GetSlotID() != SID_OBJECT_SELECT )
738 : {
739 : // Slot der Zeichenfunktion nochmal ausfuehren -> abschalten
740 0 : SfxDispatcher* pDisp = pViewSh->GetDispatcher();
741 0 : if (pDisp)
742 0 : pDisp->Execute( pFunc->GetSlotID(), SFX_CALLMODE_SYNCHRON );
743 : }
744 0 : pViewSh->SetDrawShell(false);
745 0 : pViewSh->SetDrawSelMode(false); // nach dem Dispatcher-Execute
746 :
747 : // Ranges selektieren
748 :
749 0 : const ScRangeList& rRanges = pRangesImp->GetRangeList();
750 0 : size_t nRangeCount = rRanges.size();
751 : // for empty range list, remove selection (cursor remains where it was)
752 0 : if ( nRangeCount == 0 )
753 0 : pViewSh->Unmark();
754 0 : else if ( nRangeCount == 1 )
755 0 : pViewSh->MarkRange( *rRanges[ 0 ] );
756 : else
757 : {
758 : // Mehrfachselektion
759 :
760 0 : const ScRange* pFirst = rRanges[ 0 ];
761 0 : if ( pFirst && !lcl_TabInRanges( pViewData->GetTabNo(), rRanges ) )
762 0 : pViewSh->SetTabNo( pFirst->aStart.Tab() );
763 0 : pViewSh->DoneBlockMode();
764 0 : pViewSh->InitOwnBlockMode();
765 0 : pViewData->GetMarkData().MarkFromRangeList( rRanges, true );
766 0 : pViewSh->MarkDataChanged();
767 0 : pViewData->GetDocShell()->PostPaintGridAll(); // Markierung (alt&neu)
768 0 : if ( pFirst )
769 : {
770 0 : pViewSh->AlignToCursor( pFirst->aStart.Col(), pFirst->aStart.Row(),
771 0 : SC_FOLLOW_JUMP );
772 0 : pViewSh->SetCursor( pFirst->aStart.Col(), pFirst->aStart.Row() );
773 : }
774 :
775 : //! Methode an der View, um RangeList zu selektieren
776 : }
777 0 : bRet = sal_True;
778 : }
779 : }
780 0 : else if ( pShapeImp || xShapeColl.is() ) // Drawing-Layer
781 : {
782 0 : ScDrawView* pDrawView = pViewSh->GetScDrawView();
783 0 : if (pDrawView)
784 : {
785 0 : pDrawView->ScEndTextEdit();
786 0 : pDrawView->UnmarkAll();
787 :
788 0 : if (pShapeImp) // einzelnes Shape
789 : {
790 0 : SdrObject *pObj = pShapeImp->GetSdrObject();
791 0 : if (pObj)
792 : {
793 0 : lcl_ShowObject( *pViewSh, *pDrawView, pObj );
794 0 : SdrPageView* pPV = pDrawView->GetSdrPageView();
795 0 : if ( pPV && pObj->GetPage() == pPV->GetPage() )
796 : {
797 0 : pDrawView->MarkObj( pObj, pPV );
798 0 : bRet = sal_True;
799 : }
800 : }
801 : }
802 : else // Shape-Collection (xShapeColl ist nicht 0)
803 : {
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?
807 :
808 0 : long nCount = xShapeColl->getCount();
809 0 : if (nCount)
810 : {
811 0 : SdrPageView* pPV = NULL;
812 0 : sal_Bool bAllMarked(sal_True);
813 0 : for ( long i = 0; i < nCount; i++ )
814 : {
815 0 : uno::Reference<drawing::XShape> xShapeInt(xShapeColl->getByIndex(i), uno::UNO_QUERY);
816 0 : if (xShapeInt.is())
817 : {
818 0 : SvxShape* pShape = SvxShape::getImplementation( xShapeInt );
819 0 : if (pShape)
820 : {
821 0 : SdrObject *pObj = pShape->GetSdrObject();
822 0 : if (pObj)
823 : {
824 0 : if (!bDrawSelModeSet && (pObj->GetLayer() == SC_LAYER_BACK))
825 : {
826 0 : pViewSh->SetDrawSelMode(true);
827 0 : pViewSh->UpdateLayerLocks();
828 0 : bDrawSelModeSet = true;
829 : }
830 0 : if (!pPV) // erstes Objekt
831 : {
832 0 : lcl_ShowObject( *pViewSh, *pDrawView, pObj );
833 0 : pPV = pDrawView->GetSdrPageView();
834 : }
835 0 : if ( pPV && pObj->GetPage() == pPV->GetPage() )
836 : {
837 0 : if (pDrawView->IsObjMarkable( pObj, pPV ))
838 0 : pDrawView->MarkObj( pObj, pPV );
839 : else
840 0 : bAllMarked = false;
841 : }
842 : }
843 : }
844 : }
845 0 : }
846 0 : if (bAllMarked)
847 0 : bRet = sal_True;
848 : }
849 : else
850 0 : bRet = sal_True; // empty XShapes (all shapes are deselected)
851 : }
852 :
853 0 : if (bRet)
854 0 : pViewSh->SetDrawShell(true);
855 : }
856 : }
857 :
858 0 : if (!bRet)
859 0 : throw lang::IllegalArgumentException();
860 :
861 0 : return bRet;
862 : }
863 :
864 0 : uno::Any SAL_CALL ScTabViewObj::getSelection()
865 : throw(uno::RuntimeException, std::exception)
866 : {
867 0 : SolarMutexGuard aGuard;
868 0 : ScTabViewShell* pViewSh = GetViewShell();
869 0 : ScCellRangesBase* pObj = NULL;
870 0 : if (pViewSh)
871 : {
872 : // Ist auf dem Drawing-Layer etwas selektiert?
873 :
874 0 : SdrView* pDrawView = pViewSh->GetSdrView();
875 0 : if (pDrawView)
876 : {
877 0 : const SdrMarkList& rMarkList = pDrawView->GetMarkedObjectList();
878 0 : sal_uLong nMarkCount = rMarkList.GetMarkCount();
879 0 : if (nMarkCount)
880 : {
881 : // ShapeCollection erzeugen (wie in SdXImpressView::getSelection im Draw)
882 : // Zurueckgegeben wird XInterfaceRef, das muss das UsrObject-XInterface sein
883 :
884 : uno::Reference< drawing::XShapes > xShapes = drawing::ShapeCollection::create(
885 0 : comphelper::getProcessComponentContext());
886 :
887 0 : uno::Reference<uno::XInterface> xRet(xShapes);
888 :
889 0 : for (sal_uLong i=0; i<nMarkCount; i++)
890 : {
891 0 : SdrObject* pDrawObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
892 0 : if (pDrawObj)
893 : {
894 0 : uno::Reference<drawing::XShape> xShape( pDrawObj->getUnoShape(), uno::UNO_QUERY );
895 0 : if (xShape.is())
896 0 : xShapes->add(xShape);
897 : }
898 : }
899 0 : return uno::makeAny(xRet);
900 : }
901 : }
902 :
903 : // sonst Tabellen-(Zellen-)Selektion
904 :
905 0 : ScViewData* pViewData = pViewSh->GetViewData();
906 0 : ScDocShell* pDocSh = pViewData->GetDocShell();
907 :
908 0 : const ScMarkData& rMark = pViewData->GetMarkData();
909 0 : SCTAB nTabs = rMark.GetSelectCount();
910 :
911 0 : ScRange aRange;
912 0 : ScMarkType eMarkType = pViewData->GetSimpleArea(aRange);
913 0 : if ( nTabs == 1 && (eMarkType == SC_MARK_SIMPLE) )
914 : {
915 0 : if (aRange.aStart == aRange.aEnd)
916 0 : pObj = new ScCellObj( pDocSh, aRange.aStart );
917 : else
918 0 : pObj = new ScCellRangeObj( pDocSh, aRange );
919 : }
920 0 : else if ( nTabs == 1 && (eMarkType == SC_MARK_SIMPLE_FILTERED) )
921 : {
922 0 : ScMarkData aFilteredMark( rMark );
923 0 : ScViewUtil::UnmarkFiltered( aFilteredMark, pDocSh->GetDocument());
924 0 : ScRangeList aRangeList;
925 0 : aFilteredMark.FillRangeListWithMarks( &aRangeList, false);
926 : // Theoretically a selection may start and end on a filtered row.
927 0 : switch ( aRangeList.size() )
928 : {
929 : case 0:
930 : // No unfiltered row, we have to return some object, so
931 : // here is one with no ranges.
932 0 : pObj = new ScCellRangesObj( pDocSh, aRangeList );
933 0 : break;
934 : case 1:
935 : {
936 0 : const ScRange& rRange = *(aRangeList[ 0 ]);
937 0 : if (rRange.aStart == rRange.aEnd)
938 0 : pObj = new ScCellObj( pDocSh, rRange.aStart );
939 : else
940 0 : pObj = new ScCellRangeObj( pDocSh, rRange );
941 : }
942 0 : break;
943 : default:
944 0 : pObj = new ScCellRangesObj( pDocSh, aRangeList );
945 0 : }
946 : }
947 : else // Mehrfachselektion
948 : {
949 0 : ScRangeListRef xRanges;
950 0 : pViewData->GetMultiArea( xRanges );
951 :
952 : // bei mehreren Tabellen Ranges kopieren
953 : //! sollte eigentlich schon in ScMarkData::FillRangeListWithMarks passieren?
954 0 : if ( nTabs > 1 )
955 0 : rMark.ExtendRangeListTables( xRanges );
956 :
957 0 : pObj = new ScCellRangesObj( pDocSh, *xRanges );
958 : }
959 :
960 0 : if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
961 : {
962 : // remember if the selection was from the cursor position without anything selected
963 : // (used when rendering the selection)
964 :
965 0 : pObj->SetCursorOnly( true );
966 : }
967 : }
968 :
969 0 : return uno::makeAny(uno::Reference<uno::XInterface>(static_cast<cppu::OWeakObject*>(pObj)));
970 : }
971 :
972 : // XEnumerationAccess
973 :
974 0 : uno::Reference<container::XEnumeration> SAL_CALL ScTabViewObj::createEnumeration()
975 : throw(uno::RuntimeException, std::exception)
976 : {
977 0 : SolarMutexGuard aGuard;
978 0 : return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.SpreadsheetViewPanesEnumeration"));
979 : }
980 :
981 : // XIndexAccess
982 :
983 0 : sal_Int32 SAL_CALL ScTabViewObj::getCount() throw(uno::RuntimeException, std::exception)
984 : {
985 0 : SolarMutexGuard aGuard;
986 0 : ScTabViewShell* pViewSh = GetViewShell();
987 0 : sal_uInt16 nPanes = 0;
988 0 : if (pViewSh)
989 : {
990 0 : nPanes = 1;
991 0 : ScViewData* pViewData = pViewSh->GetViewData();
992 0 : if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
993 0 : nPanes *= 2;
994 0 : if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
995 0 : nPanes *= 2;
996 : }
997 0 : return nPanes;
998 : }
999 :
1000 0 : uno::Any SAL_CALL ScTabViewObj::getByIndex( sal_Int32 nIndex )
1001 : throw(lang::IndexOutOfBoundsException,
1002 : lang::WrappedTargetException, uno::RuntimeException, std::exception)
1003 : {
1004 0 : SolarMutexGuard aGuard;
1005 0 : uno::Reference<sheet::XViewPane> xPane(GetObjectByIndex_Impl((sal_uInt16)nIndex));
1006 0 : if (xPane.is())
1007 0 : return uno::makeAny(xPane);
1008 : else
1009 0 : throw lang::IndexOutOfBoundsException();
1010 : // return uno::Any();
1011 : }
1012 :
1013 0 : uno::Type SAL_CALL ScTabViewObj::getElementType() throw(uno::RuntimeException, std::exception)
1014 : {
1015 0 : SolarMutexGuard aGuard;
1016 0 : return getCppuType((uno::Reference<sheet::XViewPane>*)0);
1017 : }
1018 :
1019 0 : sal_Bool SAL_CALL ScTabViewObj::hasElements() throw(uno::RuntimeException, std::exception)
1020 : {
1021 0 : SolarMutexGuard aGuard;
1022 0 : return ( getCount() != 0 );
1023 : }
1024 :
1025 : // XSpreadsheetView
1026 :
1027 0 : ScViewPaneObj* ScTabViewObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) const
1028 : {
1029 : static const ScSplitPos ePosHV[4] =
1030 : { SC_SPLIT_TOPLEFT, SC_SPLIT_BOTTOMLEFT, SC_SPLIT_TOPRIGHT, SC_SPLIT_BOTTOMRIGHT };
1031 :
1032 0 : ScTabViewShell* pViewSh = GetViewShell();
1033 0 : if (pViewSh)
1034 : {
1035 0 : ScSplitPos eWhich = SC_SPLIT_BOTTOMLEFT; // default Position
1036 0 : sal_Bool bError = false;
1037 0 : ScViewData* pViewData = pViewSh->GetViewData();
1038 0 : sal_Bool bHor = ( pViewData->GetHSplitMode() != SC_SPLIT_NONE );
1039 0 : sal_Bool bVer = ( pViewData->GetVSplitMode() != SC_SPLIT_NONE );
1040 0 : if ( bHor && bVer )
1041 : {
1042 : // links oben, links unten, rechts oben, rechts unten - wie in Excel
1043 0 : if ( nIndex < 4 )
1044 0 : eWhich = ePosHV[nIndex];
1045 : else
1046 0 : bError = sal_True;
1047 : }
1048 0 : else if ( bHor )
1049 : {
1050 0 : if ( nIndex > 1 )
1051 0 : bError = sal_True;
1052 0 : else if ( nIndex == 1 )
1053 0 : eWhich = SC_SPLIT_BOTTOMRIGHT;
1054 : // sonst SC_SPLIT_BOTTOMLEFT
1055 : }
1056 0 : else if ( bVer )
1057 : {
1058 0 : if ( nIndex > 1 )
1059 0 : bError = sal_True;
1060 0 : else if ( nIndex == 0 )
1061 0 : eWhich = SC_SPLIT_TOPLEFT;
1062 : // sonst SC_SPLIT_BOTTOMLEFT
1063 : }
1064 0 : else if ( nIndex > 0 )
1065 0 : bError = sal_True; // nicht geteilt: nur 0 gueltig
1066 :
1067 0 : if (!bError)
1068 0 : return new ScViewPaneObj( pViewSh, sal::static_int_cast<sal_uInt16>(eWhich) );
1069 : }
1070 :
1071 0 : return NULL;
1072 : }
1073 :
1074 0 : uno::Reference<sheet::XSpreadsheet> SAL_CALL ScTabViewObj::getActiveSheet()
1075 : throw(uno::RuntimeException, std::exception)
1076 : {
1077 0 : SolarMutexGuard aGuard;
1078 0 : ScTabViewShell* pViewSh = GetViewShell();
1079 0 : if (pViewSh)
1080 : {
1081 0 : ScViewData* pData = pViewSh->GetViewData();
1082 0 : SCTAB nTab = pData->GetTabNo();
1083 0 : return new ScTableSheetObj( pData->GetDocShell(), nTab );
1084 : }
1085 0 : return NULL;
1086 : }
1087 :
1088 : // support expand (but not replace) the active sheet
1089 0 : void SAL_CALL ScTabViewObj::setActiveSheet( const uno::Reference<sheet::XSpreadsheet>& xActiveSheet )
1090 : throw(uno::RuntimeException, std::exception)
1091 : {
1092 0 : SolarMutexGuard aGuard;
1093 :
1094 0 : ScTabViewShell* pViewSh = GetViewShell();
1095 0 : if ( pViewSh && xActiveSheet.is() )
1096 : {
1097 : // XSpreadsheet und ScCellRangesBase -> muss ein Sheet sein
1098 :
1099 0 : ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( xActiveSheet );
1100 0 : if ( pRangesImp && pViewSh->GetViewData()->GetDocShell() == pRangesImp->GetDocShell() )
1101 : {
1102 0 : const ScRangeList& rRanges = pRangesImp->GetRangeList();
1103 0 : if ( rRanges.size() == 1 )
1104 : {
1105 0 : SCTAB nNewTab = rRanges[ 0 ]->aStart.Tab();
1106 0 : if ( pViewSh->GetViewData()->GetDocument()->HasTable(nNewTab) )
1107 0 : pViewSh->SetTabNo( nNewTab );
1108 : }
1109 : }
1110 0 : }
1111 0 : }
1112 :
1113 0 : uno::Reference< uno::XInterface > ScTabViewObj::GetClickedObject(const Point& rPoint) const
1114 : {
1115 0 : uno::Reference< uno::XInterface > xTarget;
1116 0 : if (GetViewShell())
1117 : {
1118 : SCsCOL nX;
1119 : SCsROW nY;
1120 0 : ScViewData* pData = GetViewShell()->GetViewData();
1121 0 : ScSplitPos eSplitMode = pData->GetActivePart();
1122 0 : SCTAB nTab(pData->GetTabNo());
1123 0 : pData->GetPosFromPixel( rPoint.X(), rPoint.Y(), eSplitMode, nX, nY);
1124 :
1125 0 : ScAddress aCellPos (nX, nY, nTab);
1126 0 : ScCellObj* pCellObj = new ScCellObj(pData->GetDocShell(), aCellPos);
1127 :
1128 0 : xTarget.set(uno::Reference<table::XCell>(pCellObj), uno::UNO_QUERY);
1129 :
1130 0 : ScDocument* pDoc = pData->GetDocument();
1131 0 : if (pDoc && pDoc->GetDrawLayer())
1132 : {
1133 0 : SdrPage* pDrawPage = NULL;
1134 0 : ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1135 0 : if (pDrawLayer->HasObjects() && (pDrawLayer->GetPageCount() > nTab))
1136 0 : pDrawPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
1137 :
1138 0 : SdrView* pDrawView = GetViewShell()->GetSdrView();
1139 :
1140 0 : if (pDrawPage && pDrawView && pDrawView->GetSdrPageView())
1141 : {
1142 0 : Window* pActiveWin = pData->GetActiveWin();
1143 0 : Point aPos = pActiveWin->PixelToLogic(rPoint);
1144 :
1145 : sal_uInt16 nHitLog = (sal_uInt16) pActiveWin->PixelToLogic(
1146 0 : Size(pDrawView->GetHitTolerancePixel(),0)).Width();
1147 :
1148 0 : sal_uInt32 nCount(pDrawPage->GetObjCount());
1149 0 : sal_Bool bFound(false);
1150 0 : sal_uInt32 i(0);
1151 0 : while (i < nCount && !bFound)
1152 : {
1153 0 : SdrObject* pObj = pDrawPage->GetObj(i);
1154 0 : if (pObj && SdrObjectPrimitiveHit(*pObj, aPos, nHitLog, *pDrawView->GetSdrPageView(), 0, false))
1155 : {
1156 0 : xTarget.set(pObj->getUnoShape(), uno::UNO_QUERY);
1157 0 : bFound = sal_True;
1158 : }
1159 0 : ++i;
1160 : }
1161 : }
1162 : }
1163 : }
1164 0 : return xTarget;
1165 : }
1166 :
1167 0 : bool ScTabViewObj::IsMouseListening() const
1168 : {
1169 0 : if ( !aMouseClickHandlers.empty() )
1170 0 : return true;
1171 :
1172 : // also include sheet events, because MousePressed must be called for them
1173 0 : ScViewData* pViewData = GetViewShell()->GetViewData();
1174 0 : ScDocument* pDoc = pViewData->GetDocument();
1175 0 : SCTAB nTab = pViewData->GetTabNo();
1176 : return
1177 0 : pDoc->HasSheetEventScript( nTab, SC_SHEETEVENT_RIGHTCLICK, true ) ||
1178 0 : pDoc->HasSheetEventScript( nTab, SC_SHEETEVENT_DOUBLECLICK, true ) ||
1179 0 : pDoc->HasSheetEventScript( nTab, SC_SHEETEVENT_SELECT, true );
1180 :
1181 : }
1182 :
1183 0 : bool ScTabViewObj::MousePressed( const awt::MouseEvent& e )
1184 : throw (::uno::RuntimeException)
1185 : {
1186 0 : bool bReturn(false);
1187 0 : if ( e.Buttons == ::com::sun::star::awt::MouseButton::LEFT )
1188 0 : mbLeftMousePressed = true;
1189 :
1190 0 : uno::Reference< uno::XInterface > xTarget = GetClickedObject(Point(e.X, e.Y));
1191 0 : if (!aMouseClickHandlers.empty() && xTarget.is())
1192 : {
1193 0 : awt::EnhancedMouseEvent aMouseEvent;
1194 :
1195 0 : aMouseEvent.Buttons = e.Buttons;
1196 0 : aMouseEvent.X = e.X;
1197 0 : aMouseEvent.Y = e.Y;
1198 0 : aMouseEvent.ClickCount = e.ClickCount;
1199 0 : aMouseEvent.PopupTrigger = e.PopupTrigger;
1200 0 : aMouseEvent.Target = xTarget;
1201 0 : aMouseEvent.Modifiers = e.Modifiers;
1202 :
1203 0 : for (XMouseClickHandlerVector::iterator it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); )
1204 : {
1205 : try
1206 : {
1207 0 : if (!(*it)->mousePressed( aMouseEvent ))
1208 0 : bReturn = true;
1209 0 : ++it;
1210 : }
1211 0 : catch ( uno::Exception& )
1212 : {
1213 0 : it = aMouseClickHandlers.erase(it);
1214 : }
1215 0 : }
1216 : }
1217 :
1218 : // handle sheet events
1219 0 : bool bDoubleClick = ( e.Buttons == awt::MouseButton::LEFT && e.ClickCount == 2 );
1220 0 : bool bRightClick = ( e.Buttons == awt::MouseButton::RIGHT && e.ClickCount == 1 );
1221 0 : if ( ( bDoubleClick || bRightClick ) && !bReturn && xTarget.is())
1222 : {
1223 0 : sal_Int32 nEvent = bDoubleClick ? SC_SHEETEVENT_DOUBLECLICK : SC_SHEETEVENT_RIGHTCLICK;
1224 :
1225 0 : ScTabViewShell* pViewSh = GetViewShell();
1226 0 : ScViewData* pViewData = pViewSh->GetViewData();
1227 0 : ScDocShell* pDocSh = pViewData->GetDocShell();
1228 0 : ScDocument* pDoc = pDocSh->GetDocument();
1229 0 : SCTAB nTab = pViewData->GetTabNo();
1230 0 : const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
1231 0 : if (pEvents)
1232 : {
1233 0 : const OUString* pScript = pEvents->GetScript(nEvent);
1234 0 : if (pScript)
1235 : {
1236 : // the macro parameter is the clicked object, as in the mousePressed call above
1237 0 : uno::Sequence<uno::Any> aParams(1);
1238 0 : aParams[0] <<= xTarget;
1239 :
1240 0 : uno::Any aRet;
1241 0 : uno::Sequence<sal_Int16> aOutArgsIndex;
1242 0 : uno::Sequence<uno::Any> aOutArgs;
1243 :
1244 0 : /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
1245 :
1246 : // look for a boolean return value of true
1247 0 : sal_Bool bRetValue = false;
1248 0 : if (aRet >>= bRetValue)
1249 : {
1250 0 : if (bRetValue)
1251 0 : bReturn = true;
1252 0 : }
1253 : }
1254 : }
1255 :
1256 : // execute VBA event handler
1257 0 : if (!bReturn && xTarget.is()) try
1258 : {
1259 0 : 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 0 : uno::Sequence< uno::Any > aArgs( 1 );
1262 0 : aArgs[ 0 ] <<= xTarget;
1263 0 : xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( nEvent ), aArgs );
1264 : }
1265 0 : catch( util::VetoException& )
1266 : {
1267 0 : bReturn = true;
1268 : }
1269 0 : catch( uno::Exception& )
1270 : {
1271 : }
1272 : }
1273 :
1274 0 : return bReturn;
1275 : }
1276 :
1277 0 : bool ScTabViewObj::MouseReleased( const awt::MouseEvent& e )
1278 : throw (uno::RuntimeException)
1279 : {
1280 0 : if ( e.Buttons == ::com::sun::star::awt::MouseButton::LEFT )
1281 : {
1282 : try
1283 : {
1284 0 : mbPendingSelectionChanged = false;
1285 0 : ScTabViewShell* pViewSh = GetViewShell();
1286 0 : ScViewData* pViewData = pViewSh->GetViewData();
1287 0 : ScDocShell* pDocSh = pViewData->GetDocShell();
1288 0 : ScDocument* pDoc = pDocSh->GetDocument();
1289 0 : uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
1290 0 : uno::Sequence< uno::Any > aArgs( 1 );
1291 0 : aArgs[ 0 ] <<= getSelection();
1292 0 : xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_SELECT ), aArgs );
1293 : }
1294 0 : catch( uno::Exception& )
1295 : {
1296 : }
1297 0 : mbLeftMousePressed = false;
1298 : }
1299 :
1300 0 : bool bReturn(false);
1301 :
1302 0 : if (!aMouseClickHandlers.empty())
1303 : {
1304 0 : uno::Reference< uno::XInterface > xTarget = GetClickedObject(Point(e.X, e.Y));
1305 :
1306 0 : if (xTarget.is())
1307 : {
1308 0 : awt::EnhancedMouseEvent aMouseEvent;
1309 :
1310 0 : aMouseEvent.Buttons = e.Buttons;
1311 0 : aMouseEvent.X = e.X;
1312 0 : aMouseEvent.Y = e.Y;
1313 0 : aMouseEvent.ClickCount = e.ClickCount;
1314 0 : aMouseEvent.PopupTrigger = e.PopupTrigger;
1315 0 : aMouseEvent.Target = xTarget;
1316 0 : aMouseEvent.Modifiers = e.Modifiers;
1317 :
1318 0 : for (XMouseClickHandlerVector::iterator it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); )
1319 : {
1320 : try
1321 : {
1322 0 : if (!(*it)->mouseReleased( aMouseEvent ))
1323 0 : bReturn = true;
1324 0 : ++it;
1325 : }
1326 0 : catch ( uno::Exception& )
1327 : {
1328 0 : it = aMouseClickHandlers.erase(it);
1329 : }
1330 0 : }
1331 0 : }
1332 : }
1333 0 : return bReturn;
1334 : }
1335 :
1336 : // XEnhancedMouseClickBroadcaster
1337 :
1338 0 : void ScTabViewObj::StartMouseListening()
1339 : {
1340 0 : }
1341 :
1342 0 : void ScTabViewObj::EndMouseListening()
1343 : {
1344 0 : lang::EventObject aEvent;
1345 0 : aEvent.Source = (cppu::OWeakObject*)this;
1346 0 : BOOST_FOREACH(const XMouseClickHandlerUnoRef rListener, aMouseClickHandlers)
1347 : {
1348 : try
1349 : {
1350 0 : rListener->disposing(aEvent);
1351 : }
1352 0 : catch ( uno::Exception& )
1353 : {
1354 : }
1355 0 : }
1356 0 : aMouseClickHandlers.clear();
1357 0 : }
1358 :
1359 0 : void ScTabViewObj::StartActivationListening()
1360 : {
1361 0 : }
1362 :
1363 0 : void ScTabViewObj::EndActivationListening()
1364 : {
1365 0 : lang::EventObject aEvent;
1366 0 : aEvent.Source = (cppu::OWeakObject*)this;
1367 0 : BOOST_FOREACH(const XActivationEventListenerUnoRef rListener, aActivationListeners)
1368 : {
1369 : try
1370 : {
1371 0 : rListener->disposing(aEvent);
1372 : }
1373 0 : catch ( uno::Exception& )
1374 : {
1375 : }
1376 0 : }
1377 0 : aActivationListeners.clear();
1378 0 : }
1379 :
1380 0 : void SAL_CALL ScTabViewObj::addEnhancedMouseClickHandler( const uno::Reference< awt::XEnhancedMouseClickHandler >& aListener )
1381 : throw (uno::RuntimeException, std::exception)
1382 : {
1383 0 : SolarMutexGuard aGuard;
1384 :
1385 0 : if (aListener.is())
1386 : {
1387 0 : sal_uInt16 nCount = aMouseClickHandlers.size();
1388 : uno::Reference<awt::XEnhancedMouseClickHandler> *pObj =
1389 0 : new uno::Reference<awt::XEnhancedMouseClickHandler>( aListener );
1390 0 : aMouseClickHandlers.push_back( pObj );
1391 :
1392 0 : if (aMouseClickHandlers.size() == 1 && nCount == 0) // only if a listener added
1393 0 : StartMouseListening();
1394 0 : }
1395 0 : }
1396 :
1397 0 : void SAL_CALL ScTabViewObj::removeEnhancedMouseClickHandler( const uno::Reference< awt::XEnhancedMouseClickHandler >& aListener )
1398 : throw (uno::RuntimeException, std::exception)
1399 : {
1400 0 : SolarMutexGuard aGuard;
1401 0 : sal_uInt16 nCount = aMouseClickHandlers.size();
1402 0 : for (XMouseClickHandlerVector::iterator it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); )
1403 : {
1404 0 : if ( *it == aListener )
1405 0 : it = aMouseClickHandlers.erase(it);
1406 : else
1407 0 : ++it;
1408 : }
1409 0 : if ((aMouseClickHandlers.size() == 0) && (nCount > 0)) // only if last listener removed
1410 0 : EndMouseListening();
1411 0 : }
1412 :
1413 : // XActivationBroadcaster
1414 :
1415 0 : void SAL_CALL ScTabViewObj::addActivationEventListener( const uno::Reference< sheet::XActivationEventListener >& aListener )
1416 : throw (uno::RuntimeException, std::exception)
1417 : {
1418 0 : SolarMutexGuard aGuard;
1419 :
1420 0 : if (aListener.is())
1421 : {
1422 0 : sal_uInt16 nCount = aActivationListeners.size();
1423 : uno::Reference<sheet::XActivationEventListener> *pObj =
1424 0 : new uno::Reference<sheet::XActivationEventListener>( aListener );
1425 0 : aActivationListeners.push_back( pObj );
1426 :
1427 0 : if (aActivationListeners.size() == 1 && nCount == 0) // only if a listener added
1428 0 : StartActivationListening();
1429 0 : }
1430 0 : }
1431 :
1432 0 : void SAL_CALL ScTabViewObj::removeActivationEventListener( const uno::Reference< sheet::XActivationEventListener >& aListener )
1433 : throw (uno::RuntimeException, std::exception)
1434 : {
1435 0 : SolarMutexGuard aGuard;
1436 0 : sal_uInt16 nCount = aActivationListeners.size();
1437 0 : for (XActivationEventListenerVector::iterator it = aActivationListeners.begin(); it != aActivationListeners.end(); )
1438 : {
1439 0 : if ( *it == aListener )
1440 0 : it = aActivationListeners.erase(it);
1441 : else
1442 0 : ++it;
1443 : }
1444 0 : if ((aActivationListeners.size() == 0) && (nCount > 0)) // only if last listener removed
1445 0 : EndActivationListening();
1446 0 : }
1447 :
1448 0 : sal_Int16 ScTabViewObj::GetZoom(void) const
1449 : {
1450 0 : ScTabViewShell* pViewSh = GetViewShell();
1451 0 : if (pViewSh)
1452 : {
1453 0 : const Fraction& rZoomY = pViewSh->GetViewData()->GetZoomY(); // Y wird angezeigt
1454 0 : return (sal_Int16)(( rZoomY.GetNumerator() * 100 ) / rZoomY.GetDenominator());
1455 : }
1456 0 : return 0;
1457 : }
1458 :
1459 0 : void ScTabViewObj::SetZoom(sal_Int16 nZoom)
1460 : {
1461 0 : ScTabViewShell* pViewSh = GetViewShell();
1462 0 : if (pViewSh)
1463 : {
1464 0 : if ( nZoom != GetZoom() && nZoom != 0 )
1465 : {
1466 0 : if (!pViewSh->GetViewData()->IsPagebreakMode())
1467 : {
1468 0 : ScModule* pScMod = SC_MOD();
1469 0 : ScAppOptions aNewOpt(pScMod->GetAppOptions());
1470 0 : aNewOpt.SetZoom( nZoom );
1471 0 : aNewOpt.SetZoomType( pViewSh->GetViewData()->GetView()->GetZoomType() );
1472 0 : pScMod->SetAppOptions( aNewOpt );
1473 : }
1474 : }
1475 0 : Fraction aFract( nZoom, 100 );
1476 0 : pViewSh->SetZoom( aFract, aFract, true );
1477 0 : pViewSh->PaintGrid();
1478 0 : pViewSh->PaintTop();
1479 0 : pViewSh->PaintLeft();
1480 0 : pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM );
1481 0 : pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER );
1482 : }
1483 0 : }
1484 :
1485 0 : sal_Int16 ScTabViewObj::GetZoomType(void) const
1486 : {
1487 0 : sal_Int16 aZoomType = view::DocumentZoomType::OPTIMAL;
1488 0 : ScTabViewShell* pViewSh = GetViewShell();
1489 0 : if (pViewSh)
1490 : {
1491 0 : SvxZoomType eZoomType = pViewSh->GetViewData()->GetView()->GetZoomType();
1492 0 : switch (eZoomType)
1493 : {
1494 : case SVX_ZOOM_PERCENT:
1495 0 : aZoomType = view::DocumentZoomType::BY_VALUE;
1496 0 : break;
1497 : case SVX_ZOOM_OPTIMAL:
1498 0 : aZoomType = view::DocumentZoomType::OPTIMAL;
1499 0 : break;
1500 : case SVX_ZOOM_WHOLEPAGE:
1501 0 : aZoomType = view::DocumentZoomType::ENTIRE_PAGE;
1502 0 : break;
1503 : case SVX_ZOOM_PAGEWIDTH:
1504 0 : aZoomType = view::DocumentZoomType::PAGE_WIDTH;
1505 0 : break;
1506 : case SVX_ZOOM_PAGEWIDTH_NOBORDER:
1507 0 : aZoomType = view::DocumentZoomType::PAGE_WIDTH_EXACT;
1508 0 : break;
1509 : }
1510 : }
1511 0 : return aZoomType;
1512 : }
1513 :
1514 0 : void ScTabViewObj::SetZoomType(sal_Int16 aZoomType)
1515 : {
1516 0 : ScTabViewShell* pViewSh = GetViewShell();
1517 0 : if (pViewSh)
1518 : {
1519 0 : ScDBFunc* pView = pViewSh->GetViewData()->GetView();
1520 0 : if (pView)
1521 : {
1522 : SvxZoomType eZoomType;
1523 0 : switch (aZoomType)
1524 : {
1525 : case view::DocumentZoomType::BY_VALUE:
1526 0 : eZoomType = SVX_ZOOM_PERCENT;
1527 0 : break;
1528 : case view::DocumentZoomType::OPTIMAL:
1529 0 : eZoomType = SVX_ZOOM_OPTIMAL;
1530 0 : break;
1531 : case view::DocumentZoomType::ENTIRE_PAGE:
1532 0 : eZoomType = SVX_ZOOM_WHOLEPAGE;
1533 0 : break;
1534 : case view::DocumentZoomType::PAGE_WIDTH:
1535 0 : eZoomType = SVX_ZOOM_PAGEWIDTH;
1536 0 : break;
1537 : case view::DocumentZoomType::PAGE_WIDTH_EXACT:
1538 0 : eZoomType = SVX_ZOOM_PAGEWIDTH_NOBORDER;
1539 0 : break;
1540 : default:
1541 0 : eZoomType = SVX_ZOOM_OPTIMAL;
1542 : }
1543 0 : sal_Int16 nZoom(GetZoom());
1544 0 : sal_Int16 nOldZoom(nZoom);
1545 0 : if ( eZoomType == SVX_ZOOM_PERCENT )
1546 : {
1547 0 : if ( nZoom < MINZOOM ) nZoom = MINZOOM;
1548 0 : if ( nZoom > MAXZOOM ) nZoom = MAXZOOM;
1549 : }
1550 : else
1551 0 : nZoom = pView->CalcZoom( eZoomType, nOldZoom );
1552 :
1553 0 : switch ( eZoomType )
1554 : {
1555 : case SVX_ZOOM_WHOLEPAGE:
1556 : case SVX_ZOOM_PAGEWIDTH:
1557 0 : pView->SetZoomType( eZoomType, true );
1558 0 : break;
1559 :
1560 : default:
1561 0 : pView->SetZoomType( SVX_ZOOM_PERCENT, true );
1562 : }
1563 0 : SetZoom( nZoom );
1564 : }
1565 : }
1566 0 : }
1567 :
1568 0 : sal_Bool SAL_CALL ScTabViewObj::getIsWindowSplit() throw(uno::RuntimeException, std::exception)
1569 : {
1570 0 : SolarMutexGuard aGuard;
1571 : // wie Menue-Slot SID_WINDOW_SPLIT
1572 :
1573 0 : ScTabViewShell* pViewSh = GetViewShell();
1574 0 : if (pViewSh)
1575 : {
1576 0 : ScViewData* pViewData = pViewSh->GetViewData();
1577 0 : return ( pViewData->GetHSplitMode() == SC_SPLIT_NORMAL ||
1578 0 : pViewData->GetVSplitMode() == SC_SPLIT_NORMAL );
1579 : }
1580 :
1581 0 : return false;
1582 : }
1583 :
1584 0 : sal_Bool SAL_CALL ScTabViewObj::hasFrozenPanes() throw(uno::RuntimeException, std::exception)
1585 : {
1586 0 : SolarMutexGuard aGuard;
1587 : // wie Menue-Slot SID_WINDOW_FIX
1588 :
1589 0 : ScTabViewShell* pViewSh = GetViewShell();
1590 0 : if (pViewSh)
1591 : {
1592 0 : ScViewData* pViewData = pViewSh->GetViewData();
1593 0 : return ( pViewData->GetHSplitMode() == SC_SPLIT_FIX ||
1594 0 : pViewData->GetVSplitMode() == SC_SPLIT_FIX );
1595 : }
1596 :
1597 0 : return false;
1598 : }
1599 :
1600 0 : sal_Int32 SAL_CALL ScTabViewObj::getSplitHorizontal() throw(uno::RuntimeException, std::exception)
1601 : {
1602 0 : SolarMutexGuard aGuard;
1603 0 : ScTabViewShell* pViewSh = GetViewShell();
1604 0 : if (pViewSh)
1605 : {
1606 0 : ScViewData* pViewData = pViewSh->GetViewData();
1607 0 : if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
1608 0 : return pViewData->GetHSplitPos();
1609 : }
1610 0 : return 0;
1611 : }
1612 :
1613 0 : sal_Int32 SAL_CALL ScTabViewObj::getSplitVertical() throw(uno::RuntimeException, std::exception)
1614 : {
1615 0 : SolarMutexGuard aGuard;
1616 0 : ScTabViewShell* pViewSh = GetViewShell();
1617 0 : if (pViewSh)
1618 : {
1619 0 : ScViewData* pViewData = pViewSh->GetViewData();
1620 0 : if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1621 0 : return pViewData->GetVSplitPos();
1622 : }
1623 0 : return 0;
1624 : }
1625 :
1626 0 : sal_Int32 SAL_CALL ScTabViewObj::getSplitColumn()
1627 : throw(uno::RuntimeException, std::exception)
1628 : {
1629 0 : SolarMutexGuard aGuard;
1630 0 : ScTabViewShell* pViewSh = GetViewShell();
1631 0 : if (pViewSh)
1632 : {
1633 0 : ScViewData* pViewData = pViewSh->GetViewData();
1634 0 : if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
1635 : {
1636 0 : long nSplit = pViewData->GetHSplitPos();
1637 :
1638 0 : ScSplitPos ePos = SC_SPLIT_BOTTOMLEFT;
1639 0 : if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1640 0 : ePos = SC_SPLIT_TOPLEFT;
1641 :
1642 : SCsCOL nCol;
1643 : SCsROW nRow;
1644 0 : pViewData->GetPosFromPixel( nSplit, 0, ePos, nCol, nRow, false );
1645 0 : if ( nCol > 0 )
1646 0 : return nCol;
1647 : }
1648 : }
1649 0 : return 0;
1650 : }
1651 :
1652 0 : sal_Int32 SAL_CALL ScTabViewObj::getSplitRow() throw(uno::RuntimeException, std::exception)
1653 : {
1654 0 : SolarMutexGuard aGuard;
1655 0 : ScTabViewShell* pViewSh = GetViewShell();
1656 0 : if (pViewSh)
1657 : {
1658 0 : ScViewData* pViewData = pViewSh->GetViewData();
1659 0 : if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1660 : {
1661 0 : long nSplit = pViewData->GetVSplitPos();
1662 :
1663 0 : ScSplitPos ePos = SC_SPLIT_TOPLEFT; // es ist vertikal geteilt
1664 : SCsCOL nCol;
1665 : SCsROW nRow;
1666 0 : pViewData->GetPosFromPixel( 0, nSplit, ePos, nCol, nRow, false );
1667 0 : if ( nRow > 0 )
1668 0 : return nRow;
1669 : }
1670 : }
1671 0 : return 0;
1672 : }
1673 :
1674 0 : void SAL_CALL ScTabViewObj::splitAtPosition( sal_Int32 nPixelX, sal_Int32 nPixelY )
1675 : throw(uno::RuntimeException, std::exception)
1676 : {
1677 0 : SolarMutexGuard aGuard;
1678 0 : ScTabViewShell* pViewSh = GetViewShell();
1679 0 : if (pViewSh)
1680 : {
1681 0 : pViewSh->SplitAtPixel( Point( nPixelX, nPixelY ), true, true );
1682 0 : pViewSh->FreezeSplitters( false );
1683 0 : pViewSh->InvalidateSplit();
1684 0 : }
1685 0 : }
1686 :
1687 0 : void SAL_CALL ScTabViewObj::freezeAtPosition( sal_Int32 nColumns, sal_Int32 nRows )
1688 : throw(uno::RuntimeException, std::exception)
1689 : {
1690 0 : SolarMutexGuard aGuard;
1691 0 : ScTabViewShell* pViewSh = GetViewShell();
1692 0 : if (pViewSh)
1693 : {
1694 : // erst alles aufheben -> kein Stress mit Scrolling zwischendurch o.ae.
1695 :
1696 0 : pViewSh->RemoveSplit();
1697 :
1698 0 : Point aWinStart;
1699 0 : Window* pWin = pViewSh->GetWindowByPos( SC_SPLIT_BOTTOMLEFT );
1700 0 : if (pWin)
1701 0 : aWinStart = pWin->GetPosPixel();
1702 :
1703 0 : ScViewData* pViewData = pViewSh->GetViewData();
1704 0 : Point aSplit(pViewData->GetScrPos( (SCCOL)nColumns, (SCROW)nRows, SC_SPLIT_BOTTOMLEFT, true ));
1705 0 : aSplit += aWinStart;
1706 :
1707 0 : pViewSh->SplitAtPixel( aSplit, true, true );
1708 0 : pViewSh->FreezeSplitters( true );
1709 0 : pViewSh->InvalidateSplit();
1710 0 : }
1711 0 : }
1712 :
1713 0 : void SAL_CALL ScTabViewObj::addSelectionChangeListener(
1714 : const uno::Reference<view::XSelectionChangeListener>& xListener )
1715 : throw (uno::RuntimeException, std::exception)
1716 : {
1717 0 : SolarMutexGuard aGuard;
1718 : uno::Reference<view::XSelectionChangeListener>* pObj =
1719 0 : new uno::Reference<view::XSelectionChangeListener>( xListener );
1720 0 : aSelectionChgListeners.push_back( pObj );
1721 0 : }
1722 :
1723 0 : void SAL_CALL ScTabViewObj::removeSelectionChangeListener(
1724 : const uno::Reference< view::XSelectionChangeListener >& xListener )
1725 : throw(uno::RuntimeException, std::exception)
1726 : {
1727 0 : SolarMutexGuard aGuard;
1728 0 : for (XSelectionChangeListenerVector::iterator it = aSelectionChgListeners.begin();
1729 0 : it != aSelectionChgListeners.end(); ++it )
1730 : {
1731 0 : if ( *it == xListener ) //! wozu der Mumpitz mit queryInterface?
1732 : {
1733 0 : aSelectionChgListeners.erase(it);
1734 0 : break;
1735 : }
1736 0 : }
1737 0 : }
1738 :
1739 0 : void ScTabViewObj::SelectionChanged()
1740 : {
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 0 : ScFormatShell aShell( GetViewShell()->GetViewData() );
1746 0 : SfxAllItemSet reqList( SFX_APP()->GetPool() );
1747 0 : SfxRequest aReq( SID_STYLE_END_PREVIEW, 0, reqList );
1748 0 : aShell.ExecuteStyle( aReq );
1749 0 : lang::EventObject aEvent;
1750 0 : aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
1751 0 : BOOST_FOREACH(const XSelectionChangeListenerUnoRef rListener, aSelectionChgListeners)
1752 0 : rListener->selectionChanged( aEvent );
1753 :
1754 : // handle sheet events
1755 0 : ScTabViewShell* pViewSh = GetViewShell();
1756 0 : ScViewData* pViewData = pViewSh->GetViewData();
1757 0 : ScDocShell* pDocSh = pViewData->GetDocShell();
1758 0 : ScDocument* pDoc = pDocSh->GetDocument();
1759 0 : SCTAB nTab = pViewData->GetTabNo();
1760 0 : const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
1761 0 : if (pEvents)
1762 : {
1763 0 : const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_SELECT);
1764 0 : if (pScript)
1765 : {
1766 : // the macro parameter is the selection as returned by getSelection
1767 0 : uno::Sequence<uno::Any> aParams(1);
1768 0 : aParams[0] = getSelection();
1769 0 : uno::Any aRet;
1770 0 : uno::Sequence<sal_Int16> aOutArgsIndex;
1771 0 : uno::Sequence<uno::Any> aOutArgs;
1772 0 : /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
1773 : }
1774 : }
1775 0 : if ( !mbLeftMousePressed ) // selection still in progress
1776 : {
1777 0 : mbPendingSelectionChanged = false;
1778 : try
1779 : {
1780 0 : uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
1781 0 : uno::Sequence< uno::Any > aArgs( 1 );
1782 0 : aArgs[ 0 ] <<= getSelection();
1783 0 : xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_SELECT ), aArgs );
1784 : }
1785 0 : catch( uno::Exception& )
1786 : {
1787 : }
1788 : }
1789 : else
1790 : {
1791 0 : mbPendingSelectionChanged = true;
1792 0 : }
1793 0 : }
1794 :
1795 :
1796 : // XPropertySet (View-Optionen)
1797 : //! auch an der Applikation anbieten?
1798 :
1799 0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTabViewObj::getPropertySetInfo()
1800 : throw(uno::RuntimeException, std::exception)
1801 : {
1802 0 : SolarMutexGuard aGuard;
1803 : static uno::Reference<beans::XPropertySetInfo> aRef(
1804 0 : new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1805 0 : return aRef;
1806 : }
1807 :
1808 0 : 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)
1813 : {
1814 0 : SolarMutexGuard aGuard;
1815 0 : OUString aString(aPropertyName);
1816 :
1817 0 : if ( aString.equalsAscii(SC_UNO_FILTERED_RANGE_SELECTION) )
1818 : {
1819 0 : bFilteredRangeSelection = ScUnoHelpFunctions::GetBoolFromAny(aValue);
1820 0 : return;
1821 : }
1822 :
1823 0 : ScTabViewShell* pViewSh = GetViewShell();
1824 0 : if (pViewSh)
1825 : {
1826 0 : ScViewData* pViewData = pViewSh->GetViewData();
1827 0 : const ScViewOptions& rOldOpt = pViewSh->GetViewData()->GetOptions();
1828 0 : ScViewOptions aNewOpt(rOldOpt);
1829 :
1830 0 : if ( aString.equalsAscii( SC_UNO_COLROWHDR ) || aString.equalsAscii( OLD_UNO_COLROWHDR ) )
1831 0 : aNewOpt.SetOption( VOPT_HEADER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1832 0 : else if ( aString.equalsAscii( SC_UNO_HORSCROLL ) || aString.equalsAscii( OLD_UNO_HORSCROLL ) )
1833 0 : aNewOpt.SetOption( VOPT_HSCROLL, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1834 0 : else if ( aString.equalsAscii( SC_UNO_OUTLSYMB ) || aString.equalsAscii( OLD_UNO_OUTLSYMB ) )
1835 0 : aNewOpt.SetOption( VOPT_OUTLINER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1836 0 : else if ( aString.equalsAscii( SC_UNO_SHEETTABS ) || aString.equalsAscii( OLD_UNO_SHEETTABS ) )
1837 0 : aNewOpt.SetOption( VOPT_TABCONTROLS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1838 0 : else if ( aString.equalsAscii( SC_UNO_SHOWANCHOR ) )
1839 0 : aNewOpt.SetOption( VOPT_ANCHOR, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1840 0 : else if ( aString.equalsAscii( SC_UNO_SHOWFORM ) )
1841 0 : aNewOpt.SetOption( VOPT_FORMULAS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1842 0 : else if ( aString.equalsAscii( SC_UNO_SHOWGRID ) )
1843 0 : aNewOpt.SetOption( VOPT_GRID, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1844 0 : else if ( aString.equalsAscii( SC_UNO_SHOWHELP ) )
1845 0 : aNewOpt.SetOption( VOPT_HELPLINES, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1846 0 : else if ( aString.equalsAscii( SC_UNO_SHOWNOTES ) )
1847 0 : aNewOpt.SetOption( VOPT_NOTES, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1848 0 : else if ( aString.equalsAscii( SC_UNO_SHOWPAGEBR ) )
1849 0 : aNewOpt.SetOption( VOPT_PAGEBREAKS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1850 0 : else if ( aString.equalsAscii( SC_UNO_SHOWZERO ) )
1851 0 : aNewOpt.SetOption( VOPT_NULLVALS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1852 0 : else if ( aString.equalsAscii( SC_UNO_VALUEHIGH ) || aString.equalsAscii( OLD_UNO_VALUEHIGH ) )
1853 0 : aNewOpt.SetOption( VOPT_SYNTAX, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1854 0 : else if ( aString.equalsAscii( SC_UNO_VERTSCROLL ) || aString.equalsAscii( OLD_UNO_VERTSCROLL ) )
1855 0 : aNewOpt.SetOption( VOPT_VSCROLL, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1856 0 : else if ( aString.equalsAscii( SC_UNO_SHOWOBJ ) )
1857 : {
1858 0 : sal_Int16 nIntVal = 0;
1859 0 : if ( aValue >>= nIntVal )
1860 : {
1861 : //#i80528# adapt to new range eventually
1862 0 : if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1863 :
1864 0 : aNewOpt.SetObjMode( VOBJ_TYPE_OLE, (ScVObjMode)nIntVal);
1865 : }
1866 : }
1867 0 : else if ( aString.equalsAscii( SC_UNO_SHOWCHARTS ) )
1868 : {
1869 0 : sal_Int16 nIntVal = 0;
1870 0 : if ( aValue >>= nIntVal )
1871 : {
1872 : //#i80528# adapt to new range eventually
1873 0 : if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1874 :
1875 0 : aNewOpt.SetObjMode( VOBJ_TYPE_CHART, (ScVObjMode)nIntVal);
1876 : }
1877 : }
1878 0 : else if ( aString.equalsAscii( SC_UNO_SHOWDRAW ) )
1879 : {
1880 0 : sal_Int16 nIntVal = 0;
1881 0 : if ( aValue >>= nIntVal )
1882 : {
1883 : //#i80528# adapt to new range eventually
1884 0 : if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1885 :
1886 0 : aNewOpt.SetObjMode( VOBJ_TYPE_DRAW, (ScVObjMode)nIntVal);
1887 : }
1888 : }
1889 0 : else if ( aString.equalsAscii( SC_UNO_GRIDCOLOR ) )
1890 : {
1891 0 : sal_Int32 nIntVal = 0;
1892 0 : if ( aValue >>= nIntVal )
1893 0 : aNewOpt.SetGridColor( nIntVal, OUString() );
1894 : }
1895 0 : else if ( aString.equalsAscii( SC_UNO_ZOOMTYPE ) )
1896 : {
1897 0 : sal_Int16 nIntVal = 0;
1898 0 : if ( aValue >>= nIntVal )
1899 0 : SetZoomType(nIntVal);
1900 : }
1901 0 : else if ( aString.equalsAscii( SC_UNO_ZOOMVALUE ) )
1902 : {
1903 0 : sal_Int16 nIntVal = 0;
1904 0 : if ( aValue >>= nIntVal )
1905 0 : SetZoom(nIntVal);
1906 : }
1907 :
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)
1912 :
1913 0 : if ( aNewOpt != rOldOpt )
1914 : {
1915 0 : pViewData->SetOptions( aNewOpt );
1916 0 : pViewData->GetDocument()->SetViewOptions( aNewOpt );
1917 0 : pViewData->GetDocShell()->SetDocumentModified(); //! wirklich?
1918 :
1919 0 : pViewSh->UpdateFixPos();
1920 0 : pViewSh->PaintGrid();
1921 0 : pViewSh->PaintTop();
1922 0 : pViewSh->PaintLeft();
1923 0 : pViewSh->PaintExtras();
1924 0 : pViewSh->InvalidateBorder();
1925 :
1926 0 : SfxBindings& rBindings = pViewSh->GetViewFrame()->GetBindings();
1927 0 : rBindings.Invalidate( FID_TOGGLEHEADERS ); // -> Checks im Menue
1928 0 : rBindings.Invalidate( FID_TOGGLESYNTAX );
1929 0 : }
1930 0 : }
1931 : }
1932 :
1933 0 : uno::Any SAL_CALL ScTabViewObj::getPropertyValue( const OUString& aPropertyName )
1934 : throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1935 : uno::RuntimeException, std::exception)
1936 : {
1937 0 : SolarMutexGuard aGuard;
1938 0 : OUString aString(aPropertyName);
1939 0 : uno::Any aRet;
1940 :
1941 0 : if ( aString.equalsAscii(SC_UNO_FILTERED_RANGE_SELECTION) )
1942 : {
1943 0 : ScUnoHelpFunctions::SetBoolInAny(aRet, bFilteredRangeSelection);
1944 0 : return aRet;
1945 : }
1946 :
1947 0 : ScTabViewShell* pViewSh = GetViewShell();
1948 0 : if (pViewSh)
1949 : {
1950 0 : const ScViewOptions& rOpt = pViewSh->GetViewData()->GetOptions();
1951 :
1952 0 : if ( aString.equalsAscii( SC_UNO_COLROWHDR ) || aString.equalsAscii( OLD_UNO_COLROWHDR ) )
1953 0 : ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HEADER ) );
1954 0 : else if ( aString.equalsAscii( SC_UNO_HORSCROLL ) || aString.equalsAscii( OLD_UNO_HORSCROLL ) )
1955 0 : ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HSCROLL ) );
1956 0 : else if ( aString.equalsAscii( SC_UNO_OUTLSYMB ) || aString.equalsAscii( OLD_UNO_OUTLSYMB ) )
1957 0 : ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_OUTLINER ) );
1958 0 : else if ( aString.equalsAscii( SC_UNO_SHEETTABS ) || aString.equalsAscii( OLD_UNO_SHEETTABS ) )
1959 0 : ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_TABCONTROLS ) );
1960 0 : else if ( aString.equalsAscii( SC_UNO_SHOWANCHOR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_ANCHOR ) );
1961 0 : else if ( aString.equalsAscii( SC_UNO_SHOWFORM ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_FORMULAS ) );
1962 0 : else if ( aString.equalsAscii( SC_UNO_SHOWGRID ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_GRID ) );
1963 0 : else if ( aString.equalsAscii( SC_UNO_SHOWHELP ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HELPLINES ) );
1964 0 : else if ( aString.equalsAscii( SC_UNO_SHOWNOTES ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_NOTES ) );
1965 0 : else if ( aString.equalsAscii( SC_UNO_SHOWPAGEBR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_PAGEBREAKS ) );
1966 0 : else if ( aString.equalsAscii( SC_UNO_SHOWZERO ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_NULLVALS ) );
1967 0 : else if ( aString.equalsAscii( SC_UNO_VALUEHIGH ) || aString.equalsAscii( OLD_UNO_VALUEHIGH ) )
1968 0 : ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_SYNTAX ) );
1969 0 : else if ( aString.equalsAscii( SC_UNO_VERTSCROLL ) || aString.equalsAscii( OLD_UNO_VERTSCROLL ) )
1970 0 : ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_VSCROLL ) );
1971 0 : else if ( aString.equalsAscii( SC_UNO_SHOWOBJ ) ) aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_OLE ) );
1972 0 : else if ( aString.equalsAscii( SC_UNO_SHOWCHARTS ) ) aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_CHART ) );
1973 0 : else if ( aString.equalsAscii( SC_UNO_SHOWDRAW ) ) aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_DRAW ) );
1974 0 : else if ( aString.equalsAscii( SC_UNO_GRIDCOLOR ) ) aRet <<= (sal_Int32)( rOpt.GetGridColor().GetColor() );
1975 0 : else if ( aString.equalsAscii( SC_UNO_VISAREA ) ) aRet <<= GetVisArea();
1976 0 : else if ( aString.equalsAscii( SC_UNO_ZOOMTYPE ) ) aRet <<= GetZoomType();
1977 0 : else if ( aString.equalsAscii( SC_UNO_ZOOMVALUE ) ) aRet <<= GetZoom();
1978 0 : else if ( aString.equalsAscii( SC_UNO_VISAREASCREEN ) )
1979 : {
1980 0 : ScViewData* pViewData = pViewSh->GetViewData();
1981 0 : Window* pActiveWin = ( pViewData ? pViewData->GetActiveWin() : NULL );
1982 0 : if ( pActiveWin )
1983 : {
1984 0 : Rectangle aRect = pActiveWin->GetWindowExtentsRelative( NULL );
1985 0 : aRet <<= AWTRectangle( aRect );
1986 : }
1987 : }
1988 : }
1989 :
1990 0 : return aRet;
1991 : }
1992 :
1993 0 : 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)
1999 : {
2000 0 : SolarMutexGuard aGuard;
2001 : uno::Reference<beans::XPropertyChangeListener>* pObj =
2002 0 : new uno::Reference<beans::XPropertyChangeListener>( xListener );
2003 0 : aPropertyChgListeners.push_back( pObj );
2004 0 : }
2005 :
2006 0 : 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)
2011 : {
2012 0 : SolarMutexGuard aGuard;
2013 0 : for (XViewPropertyChangeListenerVector::iterator it = aPropertyChgListeners.begin();
2014 0 : it != aPropertyChgListeners.end(); ++it )
2015 : {
2016 0 : if ( *it == xListener ) //! wozu der Mumpitz mit queryInterface?
2017 : {
2018 0 : aPropertyChgListeners.erase(it);
2019 0 : break;
2020 : }
2021 0 : }
2022 0 : }
2023 :
2024 0 : 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)
2029 : {
2030 0 : }
2031 :
2032 0 : 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)
2037 : {
2038 0 : }
2039 :
2040 0 : void ScTabViewObj::VisAreaChanged()
2041 : {
2042 0 : beans::PropertyChangeEvent aEvent;
2043 0 : aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2044 0 : BOOST_FOREACH(const XViewPropertyChangeListenerUnoRef rListener, aPropertyChgListeners)
2045 0 : rListener->propertyChange( aEvent );
2046 0 : }
2047 :
2048 : // XRangeSelection
2049 :
2050 0 : void SAL_CALL ScTabViewObj::startRangeSelection(
2051 : const uno::Sequence<beans::PropertyValue>& aArguments )
2052 : throw(uno::RuntimeException, std::exception)
2053 : {
2054 0 : SolarMutexGuard aGuard;
2055 0 : ScTabViewShell* pViewSh = GetViewShell();
2056 0 : if (pViewSh)
2057 : {
2058 0 : OUString aInitVal, aTitle;
2059 0 : sal_Bool bCloseOnButtonUp = false;
2060 0 : sal_Bool bSingleCell = false;
2061 0 : sal_Bool bMultiSelection = false;
2062 :
2063 0 : OUString aStrVal;
2064 0 : const beans::PropertyValue* pPropArray = aArguments.getConstArray();
2065 0 : long nPropCount = aArguments.getLength();
2066 0 : for (long i = 0; i < nPropCount; i++)
2067 : {
2068 0 : const beans::PropertyValue& rProp = pPropArray[i];
2069 0 : OUString aPropName(rProp.Name);
2070 :
2071 0 : if (aPropName.equalsAscii( SC_UNONAME_CLOSEONUP ))
2072 0 : bCloseOnButtonUp = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2073 0 : else if (aPropName.equalsAscii( SC_UNONAME_TITLE ))
2074 : {
2075 0 : if ( rProp.Value >>= aStrVal )
2076 0 : aTitle = aStrVal;
2077 : }
2078 0 : else if (aPropName.equalsAscii( SC_UNONAME_INITVAL ))
2079 : {
2080 0 : if ( rProp.Value >>= aStrVal )
2081 0 : aInitVal = aStrVal;
2082 : }
2083 0 : else if (aPropName.equalsAscii( SC_UNONAME_SINGLECELL ))
2084 0 : bSingleCell = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2085 0 : else if (aPropName.equalsAscii( SC_UNONAME_MULTISEL ))
2086 0 : bMultiSelection = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2087 0 : }
2088 :
2089 0 : pViewSh->StartSimpleRefDialog( aTitle, aInitVal, bCloseOnButtonUp, bSingleCell, bMultiSelection );
2090 0 : }
2091 0 : }
2092 :
2093 0 : void SAL_CALL ScTabViewObj::abortRangeSelection() throw(uno::RuntimeException, std::exception)
2094 : {
2095 0 : SolarMutexGuard aGuard;
2096 0 : ScTabViewShell* pViewSh = GetViewShell();
2097 0 : if (pViewSh)
2098 0 : pViewSh->StopSimpleRefDialog();
2099 0 : }
2100 :
2101 0 : void SAL_CALL ScTabViewObj::addRangeSelectionListener(
2102 : const uno::Reference<sheet::XRangeSelectionListener>& xListener )
2103 : throw (uno::RuntimeException, std::exception)
2104 : {
2105 0 : SolarMutexGuard aGuard;
2106 : uno::Reference<sheet::XRangeSelectionListener>* pObj =
2107 0 : new uno::Reference<sheet::XRangeSelectionListener>( xListener );
2108 0 : aRangeSelListeners.push_back( pObj );
2109 0 : }
2110 :
2111 0 : void SAL_CALL ScTabViewObj::removeRangeSelectionListener(
2112 : const uno::Reference<sheet::XRangeSelectionListener>& xListener )
2113 : throw(uno::RuntimeException, std::exception)
2114 : {
2115 0 : SolarMutexGuard aGuard;
2116 0 : for (XRangeSelectionListenerVector::iterator it = aRangeSelListeners.begin();
2117 0 : it != aRangeSelListeners.end(); ++it )
2118 : {
2119 0 : if ( *it == xListener )
2120 : {
2121 0 : aRangeSelListeners.erase(it);
2122 0 : break;
2123 : }
2124 0 : }
2125 0 : }
2126 :
2127 0 : void SAL_CALL ScTabViewObj::addRangeSelectionChangeListener(
2128 : const uno::Reference<sheet::XRangeSelectionChangeListener>& xListener )
2129 : throw (uno::RuntimeException, std::exception)
2130 : {
2131 0 : SolarMutexGuard aGuard;
2132 : uno::Reference<sheet::XRangeSelectionChangeListener>* pObj =
2133 0 : new uno::Reference<sheet::XRangeSelectionChangeListener>( xListener );
2134 0 : aRangeChgListeners.push_back( pObj );
2135 0 : }
2136 :
2137 0 : void SAL_CALL ScTabViewObj::removeRangeSelectionChangeListener(
2138 : const uno::Reference<sheet::XRangeSelectionChangeListener>& xListener )
2139 : throw(uno::RuntimeException, std::exception)
2140 : {
2141 0 : SolarMutexGuard aGuard;
2142 0 : for (XRangeSelectionChangeListenerVector::iterator it = aRangeChgListeners.begin();
2143 0 : it != aRangeChgListeners.end(); ++it )
2144 : {
2145 0 : if ( *it == xListener )
2146 : {
2147 0 : aRangeChgListeners.erase(it);
2148 0 : break;
2149 : }
2150 0 : }
2151 0 : }
2152 :
2153 0 : void ScTabViewObj::RangeSelDone( const OUString& rText )
2154 : {
2155 0 : sheet::RangeSelectionEvent aEvent;
2156 0 : aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2157 0 : aEvent.RangeDescriptor = OUString( rText );
2158 :
2159 : // copy on the stack because listener could remove itself
2160 0 : XRangeSelectionListenerVector const listeners(aRangeSelListeners);
2161 :
2162 0 : BOOST_FOREACH(const XRangeSelectionListenerUnoRef rListener, listeners)
2163 0 : rListener->done( aEvent );
2164 0 : }
2165 :
2166 0 : void ScTabViewObj::RangeSelAborted( const OUString& rText )
2167 : {
2168 0 : sheet::RangeSelectionEvent aEvent;
2169 0 : aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2170 0 : aEvent.RangeDescriptor = OUString( rText );
2171 :
2172 : // copy on the stack because listener could remove itself
2173 0 : XRangeSelectionListenerVector const listeners(aRangeSelListeners);
2174 :
2175 0 : BOOST_FOREACH(const XRangeSelectionListenerUnoRef rListener, listeners)
2176 0 : rListener->aborted( aEvent );
2177 0 : }
2178 :
2179 0 : void ScTabViewObj::RangeSelChanged( const OUString& rText )
2180 : {
2181 0 : sheet::RangeSelectionEvent aEvent;
2182 0 : aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2183 0 : aEvent.RangeDescriptor = OUString( rText );
2184 :
2185 : // copy on the stack because listener could remove itself
2186 0 : XRangeSelectionChangeListenerVector const listener(aRangeChgListeners);
2187 :
2188 0 : BOOST_FOREACH(const XRangeSelectionChangeListenerUnoRef rListener, listener)
2189 0 : rListener->descriptorChanged( aEvent );
2190 0 : }
2191 :
2192 : // XServiceInfo
2193 0 : OUString SAL_CALL ScTabViewObj::getImplementationName() throw(uno::RuntimeException, std::exception)
2194 : {
2195 0 : return OUString( "ScTabViewObj" );
2196 : }
2197 :
2198 0 : sal_Bool SAL_CALL ScTabViewObj::supportsService( const OUString& rServiceName )
2199 : throw(uno::RuntimeException, std::exception)
2200 : {
2201 0 : return cppu::supportsService(this, rServiceName);
2202 : }
2203 :
2204 0 : uno::Sequence<OUString> SAL_CALL ScTabViewObj::getSupportedServiceNames()
2205 : throw(uno::RuntimeException, std::exception)
2206 : {
2207 0 : uno::Sequence<OUString> aRet(2);
2208 0 : OUString* pArray = aRet.getArray();
2209 0 : pArray[0] = OUString( SCTABVIEWOBJ_SERVICE );
2210 0 : pArray[1] = OUString( SCVIEWSETTINGS_SERVICE );
2211 0 : return aRet;
2212 : }
2213 :
2214 : // XUnoTunnel
2215 :
2216 0 : sal_Int64 SAL_CALL ScTabViewObj::getSomething(
2217 : const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception)
2218 : {
2219 0 : if ( rId.getLength() == 16 &&
2220 0 : 0 == memcmp( getUnoTunnelId().getConstArray(),
2221 0 : rId.getConstArray(), 16 ) )
2222 : {
2223 0 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
2224 : }
2225 0 : return 0;
2226 : }
2227 :
2228 : namespace
2229 : {
2230 : class theScTabViewObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScTabViewObjUnoTunnelId> {};
2231 : }
2232 :
2233 0 : const uno::Sequence<sal_Int8>& ScTabViewObj::getUnoTunnelId()
2234 : {
2235 0 : return theScTabViewObjUnoTunnelId::get().getSeq();
2236 : }
2237 :
2238 0 : ScTabViewObj* ScTabViewObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
2239 : {
2240 0 : ScTabViewObj* pRet = NULL;
2241 0 : uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
2242 0 : if (xUT.is())
2243 0 : pRet = reinterpret_cast<ScTabViewObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
2244 0 : return pRet;
2245 : }
2246 :
2247 0 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL ScTabViewObj::getTransferable()
2248 : throw (::com::sun::star::uno::RuntimeException,
2249 : std::exception)
2250 : {
2251 0 : SolarMutexGuard aGuard;
2252 0 : ScEditShell* pShell = PTR_CAST( ScEditShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2253 0 : if (pShell)
2254 0 : return pShell->GetEditView()->GetTransferable();
2255 :
2256 0 : ScDrawTextObjectBar* pTextShell = PTR_CAST( ScDrawTextObjectBar, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2257 0 : if (pTextShell)
2258 : {
2259 0 : ScViewData* pViewData = GetViewShell()->GetViewData();
2260 0 : ScDrawView* pView = pViewData->GetScDrawView();
2261 0 : OutlinerView* pOutView = pView->GetTextEditOutlinerView();
2262 0 : if (pOutView)
2263 0 : return pOutView->GetEditView().GetTransferable();
2264 : }
2265 :
2266 0 : ScDrawShell* pDrawShell = PTR_CAST( ScDrawShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2267 0 : if (pDrawShell)
2268 0 : return pDrawShell->GetDrawView()->CopyToTransferable();
2269 :
2270 0 : ScTransferObj* pObj = GetViewShell()->CopyToTransferable();
2271 0 : uno::Reference<datatransfer::XTransferable> xTransferable( pObj );
2272 0 : return xTransferable;
2273 : }
2274 :
2275 0 : 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)
2279 : {
2280 0 : SolarMutexGuard aGuard;
2281 0 : ScEditShell* pShell = PTR_CAST( ScEditShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2282 0 : if (pShell)
2283 0 : pShell->GetEditView()->InsertText( xTrans, OUString(), false );
2284 : else
2285 : {
2286 0 : ScDrawTextObjectBar* pTextShell = PTR_CAST( ScDrawTextObjectBar, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2287 0 : if (pTextShell)
2288 : {
2289 0 : ScViewData* pViewData = GetViewShell()->GetViewData();
2290 0 : ScDrawView* pView = pViewData->GetScDrawView();
2291 0 : OutlinerView* pOutView = pView->GetTextEditOutlinerView();
2292 0 : if ( pOutView )
2293 : {
2294 0 : pOutView->GetEditView().InsertText( xTrans, OUString(), false );
2295 0 : return;
2296 : }
2297 : }
2298 :
2299 0 : GetViewShell()->PasteFromTransferable( xTrans );
2300 0 : }
2301 : }
2302 :
2303 : namespace {
2304 :
2305 0 : uno::Sequence<sal_Int32> toSequence(const ScMarkData::MarkedTabsType& rSelected)
2306 : {
2307 0 : uno::Sequence<sal_Int32> aRet(rSelected.size());
2308 0 : ScMarkData::MarkedTabsType::const_iterator itr = rSelected.begin(), itrEnd = rSelected.end();
2309 0 : for (size_t i = 0; itr != itrEnd; ++itr, ++i)
2310 0 : aRet[i] = static_cast<sal_Int32>(*itr);
2311 :
2312 0 : return aRet;
2313 : }
2314 :
2315 : }
2316 :
2317 0 : uno::Sequence<sal_Int32> ScTabViewObj::getSelectedSheets()
2318 : throw (uno::RuntimeException, std::exception)
2319 : {
2320 0 : ScTabViewShell* pViewSh = GetViewShell();
2321 0 : if (!pViewSh)
2322 0 : return uno::Sequence<sal_Int32>();
2323 :
2324 0 : ScViewData* pViewData = pViewSh->GetViewData();
2325 0 : if (!pViewData)
2326 0 : return uno::Sequence<sal_Int32>();
2327 :
2328 : // #i95280# when printing from the shell, the view is never activated,
2329 : // so Excel view settings must also be evaluated here.
2330 0 : ScExtDocOptions* pExtOpt = pViewData->GetDocument()->GetExtDocOptions();
2331 0 : if (pExtOpt && pExtOpt->IsChanged())
2332 : {
2333 0 : pViewSh->GetViewData()->ReadExtOptions(*pExtOpt); // Excel view settings
2334 0 : pViewSh->SetTabNo(pViewSh->GetViewData()->GetTabNo(), true);
2335 0 : pExtOpt->SetChanged(false);
2336 : }
2337 :
2338 0 : return toSequence(pViewData->GetMarkData().GetSelectedTabs());
2339 : }
2340 :
2341 0 : ScPreviewObj::ScPreviewObj(ScPreviewShell* pViewSh) :
2342 : SfxBaseController(pViewSh),
2343 0 : mpViewShell(pViewSh)
2344 : {
2345 0 : if (mpViewShell)
2346 0 : StartListening(*mpViewShell);
2347 0 : }
2348 :
2349 0 : ScPreviewObj::~ScPreviewObj()
2350 : {
2351 0 : if (mpViewShell)
2352 0 : EndListening(*mpViewShell);
2353 0 : }
2354 :
2355 0 : uno::Any ScPreviewObj::queryInterface(const uno::Type& rType)
2356 : throw(uno::RuntimeException, std::exception)
2357 : {
2358 0 : SC_QUERYINTERFACE(sheet::XSelectedSheetsSupplier)
2359 0 : return SfxBaseController::queryInterface(rType);
2360 : }
2361 :
2362 0 : void ScPreviewObj::acquire() throw()
2363 : {
2364 0 : SfxBaseController::acquire();
2365 0 : }
2366 :
2367 0 : void ScPreviewObj::release() throw()
2368 : {
2369 0 : SfxBaseController::release();
2370 0 : }
2371 :
2372 0 : void ScPreviewObj::Notify(SfxBroadcaster&, const SfxHint& rHint)
2373 : {
2374 0 : const SfxSimpleHint* p = dynamic_cast<const SfxSimpleHint*>(&rHint);
2375 0 : if (p && p->GetId() == SFX_HINT_DYING)
2376 0 : mpViewShell = NULL;
2377 0 : }
2378 :
2379 0 : uno::Sequence<sal_Int32> ScPreviewObj::getSelectedSheets()
2380 : throw (uno::RuntimeException, std::exception)
2381 : {
2382 0 : ScPreview* p = mpViewShell->GetPreview();
2383 0 : if (!p)
2384 0 : return uno::Sequence<sal_Int32>();
2385 :
2386 0 : return toSequence(p->GetSelectedTabs());
2387 0 : }
2388 :
2389 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|