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