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