xref: /aoo41x/main/sc/source/ui/unoobj/viewuno.cxx (revision d0db51ec)
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 												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 
getTypes()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 
getImplementationId()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 
getFirstVisibleColumn()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 
setFirstVisibleColumn(sal_Int32 nFirstVisibleColumn)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 
getFirstVisibleRow()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 
setFirstVisibleRow(sal_Int32 nFirstVisibleRow)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 
getVisibleRange()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 
getReferredCells()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 {
lcl_prepareFormShellCall(ScTabViewShell * _pViewShell,sal_uInt16 _nPane,FmFormShell * & _rpFormShell,Window * & _rpWindow,SdrView * & _rpSdrView)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
getFormController(const uno::Reference<form::XForm> & _Form)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 
isFormDesignMode()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 
setFormDesignMode(::sal_Bool _DesignMode)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 
getControl(const uno::Reference<awt::XControlModel> & xModel)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 
GetVisArea() const400 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 
ScViewPaneObj(ScTabViewShell * pViewSh,sal_uInt16 nP)436 ScViewPaneObj::ScViewPaneObj(ScTabViewShell* pViewSh, sal_uInt16 nP) :
437 	ScViewPaneBase( pViewSh, nP )
438 {
439 }
440 
~ScViewPaneObj()441 ScViewPaneObj::~ScViewPaneObj()
442 {
443 }
444 
queryInterface(const uno::Type & rType)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 
acquire()456 void SAL_CALL ScViewPaneObj::acquire() throw()
457 {
458 	OWeakObject::acquire();
459 }
460 
release()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 
ScTabViewObj(ScTabViewShell * pViewSh)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 
~ScTabViewObj()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 
queryInterface(const uno::Type & rType)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 
acquire()532 void SAL_CALL ScTabViewObj::acquire() throw()
533 {
534 	SfxBaseController::acquire();
535 }
536 
release()537 void SAL_CALL ScTabViewObj::release() throw()
538 {
539 	SfxBaseController::release();
540 }
541 
lcl_CallActivate(ScDocShell * pDocSh,SCTAB nTab,sal_Int32 nEvent)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 
SheetChanged(bool bSameTabButMoved)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 
getTypes()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 
getImplementationId()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 
lcl_TabInRanges(SCTAB nTab,const ScRangeList & rRanges)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 
lcl_ShowObject(ScTabViewShell & rViewSh,ScDrawView & rDrawView,SdrObject * pSelObj)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 
select(const uno::Any & aSelection)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 
getSelection()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 
createEnumeration()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 
getCount()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 
getByIndex(sal_Int32 nIndex)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 
getElementType()1105 uno::Type SAL_CALL ScTabViewObj::getElementType() throw(uno::RuntimeException)
1106 {
1107 	ScUnoGuard aGuard;
1108 	return getCppuType((uno::Reference<sheet::XViewPane>*)0);
1109 }
1110 
hasElements()1111 sal_Bool SAL_CALL ScTabViewObj::hasElements() throw(uno::RuntimeException)
1112 {
1113 	ScUnoGuard aGuard;
1114 	return ( getCount() != 0 );
1115 }
1116 
1117 // XSpreadsheetView
1118 
GetObjectByIndex_Impl(sal_uInt16 nIndex) const1119 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 
getActiveSheet()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 
setActiveSheet(const uno::Reference<sheet::XSpreadsheet> & xActiveSheet)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 
GetClickedObject(const Point & rPoint) const1204 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 
IsMouseListening() const1258 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 
MousePressed(const awt::MouseEvent & e)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         aMouseEvent.Modifiers = e.Modifiers;
1289 
1290         for ( sal_uInt16 n=0; n<aMouseClickHandlers.Count(); n++ )
1291         {
1292             try
1293             {
1294                 if (!(*aMouseClickHandlers[n])->mousePressed( aMouseEvent ))
1295                     bReturn = sal_True;
1296             }
1297             catch ( uno::Exception& )
1298             {
1299                 aMouseClickHandlers.DeleteAndDestroy(n);
1300                 --n; // because it will be increased again in the loop
1301             }
1302         }
1303     }
1304 
1305     // handle sheet events
1306     bool bDoubleClick = ( e.Buttons == awt::MouseButton::LEFT && e.ClickCount == 2 );
1307     bool bRightClick = ( e.Buttons == awt::MouseButton::RIGHT && e.ClickCount == 1 );
1308     if ( ( bDoubleClick || bRightClick ) && !bReturn && xTarget.is())
1309     {
1310         sal_Int32 nEvent = bDoubleClick ? SC_SHEETEVENT_DOUBLECLICK : SC_SHEETEVENT_RIGHTCLICK;
1311 
1312         ScTabViewShell* pViewSh = GetViewShell();
1313         ScViewData* pViewData = pViewSh->GetViewData();
1314         ScDocShell* pDocSh = pViewData->GetDocShell();
1315         ScDocument* pDoc = pDocSh->GetDocument();
1316         SCTAB nTab = pViewData->GetTabNo();
1317         const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
1318         if (pEvents)
1319         {
1320             const rtl::OUString* pScript = pEvents->GetScript(nEvent);
1321             if (pScript)
1322             {
1323                 // the macro parameter is the clicked object, as in the mousePressed call above
1324                 uno::Sequence<uno::Any> aParams(1);
1325                 aParams[0] <<= xTarget;
1326 
1327                 uno::Any aRet;
1328                 uno::Sequence<sal_Int16> aOutArgsIndex;
1329                 uno::Sequence<uno::Any> aOutArgs;
1330 
1331                 /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
1332 
1333                 // look for a boolean return value of true
1334                 sal_Bool bRetValue = sal_False;
1335                 if (aRet >>= bRetValue)
1336                 {
1337                     if (bRetValue)
1338                         bReturn = sal_True;
1339                 }
1340             }
1341         }
1342 
1343         // execute VBA event handler
1344         if (!bReturn && xTarget.is()) try
1345         {
1346             uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
1347             // the parameter is the clicked object, as in the mousePressed call above
1348             uno::Sequence< uno::Any > aArgs( 1 );
1349             aArgs[ 0 ] <<= xTarget;
1350             xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( nEvent ), aArgs );
1351         }
1352         catch( util::VetoException& )
1353         {
1354             bReturn = sal_True;
1355         }
1356         catch( uno::Exception& )
1357         {
1358         }
1359     }
1360 
1361     return bReturn;
1362 }
1363 
MouseReleased(const awt::MouseEvent & e)1364 sal_Bool ScTabViewObj::MouseReleased( const awt::MouseEvent& e )
1365                                     throw (uno::RuntimeException)
1366 {
1367     sal_Bool bReturn(sal_False);
1368 
1369     if (aMouseClickHandlers.Count())
1370     {
1371         uno::Reference< uno::XInterface > xTarget = GetClickedObject(Point(e.X, e.Y));
1372 
1373         if (xTarget.is())
1374         {
1375             awt::EnhancedMouseEvent aMouseEvent;
1376 
1377             aMouseEvent.Buttons = e.Buttons;
1378             aMouseEvent.X = e.X;
1379             aMouseEvent.Y = e.Y;
1380             aMouseEvent.ClickCount = e.ClickCount;
1381             aMouseEvent.PopupTrigger = e.PopupTrigger;
1382             aMouseEvent.Target = xTarget;
1383             aMouseEvent.Modifiers = e.Modifiers;
1384 
1385 	        for ( sal_uInt16 n=0; n<aMouseClickHandlers.Count(); n++ )
1386             {
1387                 try
1388                 {
1389                     if (!(*aMouseClickHandlers[n])->mouseReleased( aMouseEvent ))
1390                         bReturn = sal_True;
1391                 }
1392                 catch ( uno::Exception& )
1393                 {
1394                     aMouseClickHandlers.DeleteAndDestroy(n);
1395                     --n; // because it will be increased again in the loop
1396                 }
1397             }
1398         }
1399     }
1400     return bReturn;
1401 }
1402 
1403 // XEnhancedMouseClickBroadcaster
1404 
StartMouseListening()1405 void ScTabViewObj::StartMouseListening()
1406 {
1407 }
1408 
EndMouseListening()1409 void ScTabViewObj::EndMouseListening()
1410 {
1411     sal_uInt16 nCount(aMouseClickHandlers.Count());
1412     lang::EventObject aEvent;
1413     aEvent.Source = (cppu::OWeakObject*)this;
1414 	for ( sal_uInt16 n=0; n<nCount; n++ )
1415     {
1416         try
1417         {
1418             (*aMouseClickHandlers[n])->disposing(aEvent);
1419         }
1420         catch ( uno::Exception& )
1421         {
1422         }
1423     }
1424     aMouseClickHandlers.DeleteAndDestroy(0, nCount);
1425 }
1426 
StartActivationListening()1427 void ScTabViewObj::StartActivationListening()
1428 {
1429 }
1430 
EndActivationListening()1431 void ScTabViewObj::EndActivationListening()
1432 {
1433     sal_uInt16 nCount = aActivationListeners.Count();
1434     lang::EventObject aEvent;
1435     aEvent.Source = (cppu::OWeakObject*)this;
1436 	for ( sal_uInt16 n=0; n<nCount; n++ )
1437     {
1438         try
1439         {
1440             (*aActivationListeners[n])->disposing(aEvent);
1441         }
1442         catch ( uno::Exception& )
1443         {
1444         }
1445     }
1446     aActivationListeners.DeleteAndDestroy(0, nCount);
1447 }
1448 
addEnhancedMouseClickHandler(const uno::Reference<awt::XEnhancedMouseClickHandler> & aListener)1449 void SAL_CALL ScTabViewObj::addEnhancedMouseClickHandler( const uno::Reference< awt::XEnhancedMouseClickHandler >& aListener )
1450                                     throw (uno::RuntimeException)
1451 {
1452 	ScUnoGuard aGuard;
1453 
1454     if (aListener.is())
1455     {
1456 	    sal_uInt16 nCount = aMouseClickHandlers.Count();
1457 	    uno::Reference<awt::XEnhancedMouseClickHandler> *pObj =
1458 			    new uno::Reference<awt::XEnhancedMouseClickHandler>( aListener );
1459 	    aMouseClickHandlers.Insert( pObj, nCount );
1460 
1461         if (aMouseClickHandlers.Count() == 1 && nCount == 0) // only if a listener added
1462             StartMouseListening();
1463     }
1464 }
1465 
removeEnhancedMouseClickHandler(const uno::Reference<awt::XEnhancedMouseClickHandler> & aListener)1466 void SAL_CALL ScTabViewObj::removeEnhancedMouseClickHandler( const uno::Reference< awt::XEnhancedMouseClickHandler >& aListener )
1467                                     throw (uno::RuntimeException)
1468 {
1469 	ScUnoGuard aGuard;
1470 	sal_uInt16 nCount = aMouseClickHandlers.Count();
1471 	for ( sal_uInt16 n=nCount; n--; )
1472 	{
1473 		uno::Reference<awt::XEnhancedMouseClickHandler> *pObj = aMouseClickHandlers[n];
1474 		if ( *pObj == aListener )
1475 			aMouseClickHandlers.DeleteAndDestroy( n );
1476 	}
1477     if ((aMouseClickHandlers.Count() == 0) && (nCount > 0)) // only if last listener removed
1478         EndMouseListening();
1479 }
1480 
1481 // XActivationBroadcaster
1482 
addActivationEventListener(const uno::Reference<sheet::XActivationEventListener> & aListener)1483 void SAL_CALL ScTabViewObj::addActivationEventListener( const uno::Reference< sheet::XActivationEventListener >& aListener )
1484                                     throw (uno::RuntimeException)
1485 {
1486 	ScUnoGuard aGuard;
1487 
1488     if (aListener.is())
1489     {
1490 	    sal_uInt16 nCount = aActivationListeners.Count();
1491 	    uno::Reference<sheet::XActivationEventListener> *pObj =
1492 			    new uno::Reference<sheet::XActivationEventListener>( aListener );
1493 	    aActivationListeners.Insert( pObj, nCount );
1494 
1495         if (aActivationListeners.Count() == 1 && nCount == 0) // only if a listener added
1496             StartActivationListening();
1497     }
1498 }
1499 
removeActivationEventListener(const uno::Reference<sheet::XActivationEventListener> & aListener)1500 void SAL_CALL ScTabViewObj::removeActivationEventListener( const uno::Reference< sheet::XActivationEventListener >& aListener )
1501                                     throw (uno::RuntimeException)
1502 {
1503 	ScUnoGuard aGuard;
1504 	sal_uInt16 nCount = aActivationListeners.Count();
1505 	for ( sal_uInt16 n=nCount; n--; )
1506 	{
1507 		uno::Reference<sheet::XActivationEventListener> *pObj = aActivationListeners[n];
1508 		if ( *pObj == aListener )
1509 			aActivationListeners.DeleteAndDestroy( n );
1510 	}
1511     if ((aActivationListeners.Count() == 0) && (nCount > 0)) // only if last listener removed
1512         EndActivationListening();
1513 }
1514 
1515 //	PageBreakMode / Zoom sind Properties
1516 
1517 #if 0
1518 
1519 sal_Bool ScTabViewObj::getPagebreakMode(void) const
1520 {
1521 	ScUnoGuard aGuard;
1522 	ScTabViewShell* pViewSh = GetViewShell();
1523 	if (pViewSh)
1524 		return pViewSh->GetViewData()->IsPagebreakMode();
1525 	return sal_False;
1526 }
1527 
1528 void ScTabViewObj::setPagebreakMode(sal_Bool PagebreakMode)
1529 {
1530 	ScUnoGuard aGuard;
1531 	ScTabViewShell* pViewSh = GetViewShell();
1532 	if (pViewSh)
1533 		pViewSh->SetPagebreakMode(PagebreakMode);
1534 }
1535 
1536 #endif
1537 
GetZoom(void) const1538 sal_Int16 ScTabViewObj::GetZoom(void) const
1539 {
1540 	ScTabViewShell* pViewSh = GetViewShell();
1541 	if (pViewSh)
1542 	{
1543 		const Fraction& rZoomY = pViewSh->GetViewData()->GetZoomY();	// Y wird angezeigt
1544 		return (sal_Int16)(( rZoomY.GetNumerator() * 100 ) / rZoomY.GetDenominator());
1545 	}
1546 	return 0;
1547 }
1548 
SetZoom(sal_Int16 nZoom)1549 void ScTabViewObj::SetZoom(sal_Int16 nZoom)
1550 {
1551 	ScTabViewShell* pViewSh = GetViewShell();
1552 	if (pViewSh)
1553 	{
1554 		if ( nZoom != GetZoom() && nZoom != 0 )
1555 		{
1556 			if (!pViewSh->GetViewData()->IsPagebreakMode())
1557 			{
1558 				ScModule* pScMod = SC_MOD();
1559 				ScAppOptions aNewOpt(pScMod->GetAppOptions());
1560 				aNewOpt.SetZoom( nZoom );
1561 				aNewOpt.SetZoomType( pViewSh->GetViewData()->GetView()->GetZoomType() );
1562 				pScMod->SetAppOptions( aNewOpt );
1563 			}
1564 		}
1565 		Fraction aFract( nZoom, 100 );
1566         pViewSh->SetZoom( aFract, aFract, sal_True );
1567 		pViewSh->PaintGrid();
1568 		pViewSh->PaintTop();
1569 		pViewSh->PaintLeft();
1570 		pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM );
1571         pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER );
1572 	}
1573 }
1574 
GetZoomType(void) const1575 sal_Int16 ScTabViewObj::GetZoomType(void) const
1576 {
1577     sal_Int16 aZoomType = view::DocumentZoomType::OPTIMAL;
1578 	ScTabViewShell* pViewSh = GetViewShell();
1579 	if (pViewSh)
1580 	{
1581         SvxZoomType eZoomType = pViewSh->GetViewData()->GetView()->GetZoomType();
1582         switch (eZoomType)
1583         {
1584         case SVX_ZOOM_PERCENT:
1585             aZoomType = view::DocumentZoomType::BY_VALUE;
1586             break;
1587         case SVX_ZOOM_OPTIMAL:
1588             aZoomType = view::DocumentZoomType::OPTIMAL;
1589             break;
1590         case SVX_ZOOM_WHOLEPAGE:
1591             aZoomType = view::DocumentZoomType::ENTIRE_PAGE;
1592             break;
1593         case SVX_ZOOM_PAGEWIDTH:
1594             aZoomType = view::DocumentZoomType::PAGE_WIDTH;
1595             break;
1596         case SVX_ZOOM_PAGEWIDTH_NOBORDER:
1597             aZoomType = view::DocumentZoomType::PAGE_WIDTH_EXACT;
1598             break;
1599         }
1600     }
1601     return aZoomType;
1602 }
1603 
SetZoomType(sal_Int16 aZoomType)1604 void ScTabViewObj::SetZoomType(sal_Int16 aZoomType)
1605 {
1606 	ScTabViewShell* pViewSh = GetViewShell();
1607 	if (pViewSh)
1608 	{
1609         ScDBFunc* pView = pViewSh->GetViewData()->GetView();
1610         if (pView)
1611         {
1612             SvxZoomType eZoomType;
1613             switch (aZoomType)
1614             {
1615             case view::DocumentZoomType::BY_VALUE:
1616                 eZoomType = SVX_ZOOM_PERCENT;
1617                 break;
1618             case view::DocumentZoomType::OPTIMAL:
1619                 eZoomType = SVX_ZOOM_OPTIMAL;
1620                 break;
1621             case view::DocumentZoomType::ENTIRE_PAGE:
1622                 eZoomType = SVX_ZOOM_WHOLEPAGE;
1623                 break;
1624             case view::DocumentZoomType::PAGE_WIDTH:
1625                 eZoomType = SVX_ZOOM_PAGEWIDTH;
1626                 break;
1627             case view::DocumentZoomType::PAGE_WIDTH_EXACT:
1628                 eZoomType = SVX_ZOOM_PAGEWIDTH_NOBORDER;
1629                 break;
1630             default:
1631                 eZoomType = SVX_ZOOM_OPTIMAL;
1632             }
1633             sal_Int16 nZoom(GetZoom());
1634             sal_Int16 nOldZoom(nZoom);
1635 		    if ( eZoomType == SVX_ZOOM_PERCENT )
1636 		    {
1637 			    if ( nZoom < MINZOOM )	nZoom = MINZOOM;
1638 			    if ( nZoom > MAXZOOM )	nZoom = MAXZOOM;
1639 		    }
1640 		    else
1641 			    nZoom = pView->CalcZoom( eZoomType, nOldZoom );
1642 
1643 		    switch ( eZoomType )
1644 		    {
1645 			    case SVX_ZOOM_WHOLEPAGE:
1646 			    case SVX_ZOOM_PAGEWIDTH:
1647                     pView->SetZoomType( eZoomType, sal_True );
1648 				    break;
1649 
1650 			    default:
1651                     pView->SetZoomType( SVX_ZOOM_PERCENT, sal_True );
1652 		    }
1653 			SetZoom( nZoom );
1654         }
1655     }
1656 }
1657 
getIsWindowSplit()1658 sal_Bool SAL_CALL ScTabViewObj::getIsWindowSplit() throw(uno::RuntimeException)
1659 {
1660 	ScUnoGuard aGuard;
1661 	//	wie Menue-Slot SID_WINDOW_SPLIT
1662 
1663 	ScTabViewShell* pViewSh = GetViewShell();
1664 	if (pViewSh)
1665 	{
1666 		ScViewData* pViewData = pViewSh->GetViewData();
1667 		return ( pViewData->GetHSplitMode() == SC_SPLIT_NORMAL ||
1668 				 pViewData->GetVSplitMode() == SC_SPLIT_NORMAL );
1669 	}
1670 
1671 	return sal_False;
1672 }
1673 
hasFrozenPanes()1674 sal_Bool SAL_CALL ScTabViewObj::hasFrozenPanes() throw(uno::RuntimeException)
1675 {
1676 	ScUnoGuard aGuard;
1677 	//	wie Menue-Slot SID_WINDOW_FIX
1678 
1679 	ScTabViewShell* pViewSh = GetViewShell();
1680 	if (pViewSh)
1681 	{
1682 		ScViewData* pViewData = pViewSh->GetViewData();
1683 		return ( pViewData->GetHSplitMode() == SC_SPLIT_FIX ||
1684 				 pViewData->GetVSplitMode() == SC_SPLIT_FIX );
1685 	}
1686 
1687 	return sal_False;
1688 }
1689 
getSplitHorizontal()1690 sal_Int32 SAL_CALL ScTabViewObj::getSplitHorizontal() throw(uno::RuntimeException)
1691 {
1692 	ScUnoGuard aGuard;
1693 	ScTabViewShell* pViewSh = GetViewShell();
1694 	if (pViewSh)
1695 	{
1696 		ScViewData* pViewData = pViewSh->GetViewData();
1697 		if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
1698 			return pViewData->GetHSplitPos();
1699 	}
1700 	return 0;
1701 }
1702 
getSplitVertical()1703 sal_Int32 SAL_CALL ScTabViewObj::getSplitVertical() throw(uno::RuntimeException)
1704 {
1705 	ScUnoGuard aGuard;
1706 	ScTabViewShell* pViewSh = GetViewShell();
1707 	if (pViewSh)
1708 	{
1709 		ScViewData* pViewData = pViewSh->GetViewData();
1710 		if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1711 			return pViewData->GetVSplitPos();
1712 	}
1713 	return 0;
1714 }
1715 
getSplitColumn()1716 sal_Int32 SAL_CALL ScTabViewObj::getSplitColumn() throw(uno::RuntimeException)
1717 {
1718 	ScUnoGuard aGuard;
1719 	ScTabViewShell* pViewSh = GetViewShell();
1720 	if (pViewSh)
1721 	{
1722 		ScViewData* pViewData = pViewSh->GetViewData();
1723 		if ( pViewData->GetHSplitMode() != SC_SPLIT_NONE )
1724 		{
1725 			long nSplit = pViewData->GetHSplitPos();
1726 
1727 			ScSplitPos ePos = SC_SPLIT_BOTTOMLEFT;
1728 			if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1729 				ePos = SC_SPLIT_TOPLEFT;
1730 
1731             SCsCOL nCol;
1732             SCsROW nRow;
1733             pViewData->GetPosFromPixel( nSplit, 0, ePos, nCol, nRow, sal_False );
1734 			if ( nCol > 0 )
1735 				return nCol;
1736 		}
1737 	}
1738 	return 0;
1739 }
1740 
getSplitRow()1741 sal_Int32 SAL_CALL ScTabViewObj::getSplitRow() throw(uno::RuntimeException)
1742 {
1743 	ScUnoGuard aGuard;
1744 	ScTabViewShell* pViewSh = GetViewShell();
1745 	if (pViewSh)
1746 	{
1747 		ScViewData* pViewData = pViewSh->GetViewData();
1748 		if ( pViewData->GetVSplitMode() != SC_SPLIT_NONE )
1749 		{
1750 			long nSplit = pViewData->GetVSplitPos();
1751 
1752 			ScSplitPos ePos = SC_SPLIT_TOPLEFT;		// es ist vertikal geteilt
1753             SCsCOL nCol;
1754             SCsROW nRow;
1755             pViewData->GetPosFromPixel( 0, nSplit, ePos, nCol, nRow, sal_False );
1756 			if ( nRow > 0 )
1757 				return nRow;
1758 		}
1759 	}
1760 	return 0;
1761 }
1762 
splitAtPosition(sal_Int32 nPixelX,sal_Int32 nPixelY)1763 void SAL_CALL ScTabViewObj::splitAtPosition( sal_Int32 nPixelX, sal_Int32 nPixelY )
1764 												throw(uno::RuntimeException)
1765 {
1766 	ScUnoGuard aGuard;
1767 	ScTabViewShell* pViewSh = GetViewShell();
1768 	if (pViewSh)
1769 	{
1770 		pViewSh->SplitAtPixel( Point( nPixelX, nPixelY ), sal_True, sal_True );
1771 		pViewSh->FreezeSplitters( sal_False );
1772 		pViewSh->InvalidateSplit();
1773 	}
1774 }
1775 
freezeAtPosition(sal_Int32 nColumns,sal_Int32 nRows)1776 void SAL_CALL ScTabViewObj::freezeAtPosition( sal_Int32 nColumns, sal_Int32 nRows )
1777 												throw(uno::RuntimeException)
1778 {
1779 	ScUnoGuard aGuard;
1780 	ScTabViewShell* pViewSh = GetViewShell();
1781 	if (pViewSh)
1782 	{
1783 		//	erst alles aufheben -> kein Stress mit Scrolling zwischendurch o.ae.
1784 
1785 		pViewSh->RemoveSplit();
1786 
1787 		Point aWinStart;
1788 		Window* pWin = pViewSh->GetWindowByPos( SC_SPLIT_BOTTOMLEFT );
1789 		if (pWin)
1790 			aWinStart = pWin->GetPosPixel();
1791 
1792 		ScViewData* pViewData = pViewSh->GetViewData();
1793 		Point aSplit(pViewData->GetScrPos( (SCCOL)nColumns, (SCROW)nRows, SC_SPLIT_BOTTOMLEFT, sal_True ));
1794 		aSplit += aWinStart;
1795 
1796 		pViewSh->SplitAtPixel( aSplit, sal_True, sal_True );
1797 		pViewSh->FreezeSplitters( sal_True );
1798 		pViewSh->InvalidateSplit();
1799 	}
1800 }
1801 
addSelectionChangeListener(const uno::Reference<view::XSelectionChangeListener> & xListener)1802 void SAL_CALL ScTabViewObj::addSelectionChangeListener(
1803 				const uno::Reference<view::XSelectionChangeListener>& xListener )
1804 													throw(uno::RuntimeException)
1805 {
1806 	ScUnoGuard aGuard;
1807 	uno::Reference<view::XSelectionChangeListener>* pObj =
1808 			new uno::Reference<view::XSelectionChangeListener>( xListener );
1809 	aSelectionListeners.Insert( pObj, aSelectionListeners.Count() );
1810 }
1811 
removeSelectionChangeListener(const uno::Reference<view::XSelectionChangeListener> & xListener)1812 void SAL_CALL ScTabViewObj::removeSelectionChangeListener(
1813 				const uno::Reference< view::XSelectionChangeListener >& xListener )
1814 													throw(uno::RuntimeException)
1815 {
1816 	ScUnoGuard aGuard;
1817 	sal_uInt16 nCount = aSelectionListeners.Count();
1818 	for ( sal_uInt16 n=nCount; n--; )
1819 	{
1820 		uno::Reference<view::XSelectionChangeListener> *pObj = aSelectionListeners[n];
1821 		if ( *pObj == xListener )		//! wozu der Mumpitz mit queryInterface?
1822 		{
1823 			aSelectionListeners.DeleteAndDestroy( n );
1824 			break;
1825 		}
1826 	}
1827 }
1828 
SelectionChanged()1829 void ScTabViewObj::SelectionChanged()
1830 {
1831 	lang::EventObject aEvent;
1832 	aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
1833 	for ( sal_uInt16 n=0; n<aSelectionListeners.Count(); n++ )
1834 		(*aSelectionListeners[n])->selectionChanged( aEvent );
1835 
1836     // handle sheet events
1837     ScTabViewShell* pViewSh = GetViewShell();
1838     ScViewData* pViewData = pViewSh->GetViewData();
1839     ScDocShell* pDocSh = pViewData->GetDocShell();
1840     ScDocument* pDoc = pDocSh->GetDocument();
1841     SCTAB nTab = pViewData->GetTabNo();
1842     const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
1843     if (pEvents)
1844     {
1845         const rtl::OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_SELECT);
1846         if (pScript)
1847         {
1848             // the macro parameter is the selection as returned by getSelection
1849             uno::Sequence<uno::Any> aParams(1);
1850             aParams[0] = getSelection();
1851             uno::Any aRet;
1852             uno::Sequence<sal_Int16> aOutArgsIndex;
1853             uno::Sequence<uno::Any> aOutArgs;
1854             /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
1855         }
1856     }
1857 
1858     // execute VBA event handler
1859     try
1860     {
1861         uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
1862         // the parameter is the clicked object, as in the mousePressed call above
1863         uno::Sequence< uno::Any > aArgs( 1 );
1864         aArgs[ 0 ] <<= getSelection();
1865         xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_SELECT ), aArgs );
1866     }
1867     catch( uno::Exception& )
1868     {
1869     }
1870 }
1871 
1872 
1873 //	XPropertySet (View-Optionen)
1874 //!	auch an der Applikation anbieten?
1875 
getPropertySetInfo()1876 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTabViewObj::getPropertySetInfo()
1877 														throw(uno::RuntimeException)
1878 {
1879 	ScUnoGuard aGuard;
1880 	static uno::Reference<beans::XPropertySetInfo> aRef(
1881 		new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1882 	return aRef;
1883 }
1884 
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)1885 void SAL_CALL ScTabViewObj::setPropertyValue(
1886 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
1887 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1888 						lang::IllegalArgumentException, lang::WrappedTargetException,
1889 						uno::RuntimeException)
1890 {
1891 	ScUnoGuard aGuard;
1892 	String aString(aPropertyName);
1893 
1894 	ScTabViewShell* pViewSh = GetViewShell();
1895 	if (pViewSh)
1896 	{
1897 		ScViewData* pViewData = pViewSh->GetViewData();
1898 		const ScViewOptions& rOldOpt = pViewSh->GetViewData()->GetOptions();
1899 		ScViewOptions aNewOpt(rOldOpt);
1900 
1901 		if ( aString.EqualsAscii( SC_UNO_COLROWHDR ) || aString.EqualsAscii( OLD_UNO_COLROWHDR ) )
1902 			aNewOpt.SetOption( VOPT_HEADER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1903 		else if ( aString.EqualsAscii( SC_UNO_HORSCROLL ) || aString.EqualsAscii( OLD_UNO_HORSCROLL ) )
1904 			aNewOpt.SetOption( VOPT_HSCROLL, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1905 		else if ( aString.EqualsAscii( SC_UNO_OUTLSYMB ) || aString.EqualsAscii( OLD_UNO_OUTLSYMB ) )
1906 			aNewOpt.SetOption( VOPT_OUTLINER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1907 		else if ( aString.EqualsAscii( SC_UNO_SHEETTABS ) || aString.EqualsAscii( OLD_UNO_SHEETTABS ) )
1908 			aNewOpt.SetOption( VOPT_TABCONTROLS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1909 		else if ( aString.EqualsAscii( SC_UNO_SHOWANCHOR ) )
1910 			aNewOpt.SetOption( VOPT_ANCHOR, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1911 		else if ( aString.EqualsAscii( SC_UNO_SHOWFORM ) )
1912 			aNewOpt.SetOption( VOPT_FORMULAS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1913 		else if ( aString.EqualsAscii( SC_UNO_SHOWGRID ) )
1914 			aNewOpt.SetOption( VOPT_GRID, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1915 		else if ( aString.EqualsAscii( SC_UNO_SHOWHELP ) )
1916 			aNewOpt.SetOption( VOPT_HELPLINES, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1917 		else if ( aString.EqualsAscii( SC_UNO_SHOWNOTES ) )
1918 			aNewOpt.SetOption( VOPT_NOTES, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1919 		else if ( aString.EqualsAscii( SC_UNO_SHOWPAGEBR ) )
1920 			aNewOpt.SetOption( VOPT_PAGEBREAKS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1921 		else if ( aString.EqualsAscii( SC_UNO_SHOWZERO ) )
1922 			aNewOpt.SetOption( VOPT_NULLVALS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1923 		else if ( aString.EqualsAscii( SC_UNO_SHOWSOLID ) )
1924 			aNewOpt.SetOption( VOPT_SOLIDHANDLES, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1925 		else if ( aString.EqualsAscii( SC_UNO_VALUEHIGH ) || aString.EqualsAscii( OLD_UNO_VALUEHIGH ) )
1926 			aNewOpt.SetOption( VOPT_SYNTAX, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1927 		else if ( aString.EqualsAscii( SC_UNO_VERTSCROLL ) || aString.EqualsAscii( OLD_UNO_VERTSCROLL ) )
1928 			aNewOpt.SetOption( VOPT_VSCROLL, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1929 		else if ( aString.EqualsAscii( SC_UNO_SHOWOBJ ) )
1930 		{
1931 			sal_Int16 nIntVal = 0;
1932 			if ( aValue >>= nIntVal )
1933 			{
1934 				//#i80528# adapt to new range eventually
1935 				if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1936 
1937 				aNewOpt.SetObjMode( VOBJ_TYPE_OLE, (ScVObjMode)nIntVal);
1938 			}
1939 		}
1940 		else if ( aString.EqualsAscii( SC_UNO_SHOWCHARTS ) )
1941 		{
1942 			sal_Int16 nIntVal = 0;
1943 			if ( aValue >>= nIntVal )
1944 			{
1945 				//#i80528# adapt to new range eventually
1946 				if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1947 
1948 				aNewOpt.SetObjMode( VOBJ_TYPE_CHART, (ScVObjMode)nIntVal);
1949 			}
1950 		}
1951 		else if ( aString.EqualsAscii( SC_UNO_SHOWDRAW ) )
1952 		{
1953 			sal_Int16 nIntVal = 0;
1954 			if ( aValue >>= nIntVal )
1955 			{
1956 				//#i80528# adapt to new range eventually
1957 				if((sal_Int16)VOBJ_MODE_HIDE < nIntVal) nIntVal = (sal_Int16)VOBJ_MODE_SHOW;
1958 
1959 				aNewOpt.SetObjMode( VOBJ_TYPE_DRAW, (ScVObjMode)nIntVal);
1960 			}
1961 		}
1962 		else if ( aString.EqualsAscii( SC_UNO_GRIDCOLOR ) )
1963 		{
1964 			sal_Int32 nIntVal = 0;
1965 			if ( aValue >>= nIntVal )
1966 				aNewOpt.SetGridColor( nIntVal, String() );
1967 		}
1968         else if ( aString.EqualsAscii( SC_UNO_ZOOMTYPE ) )
1969         {
1970             sal_Int16 nIntVal = 0;
1971             if ( aValue >>= nIntVal )
1972                 SetZoomType(nIntVal);
1973         }
1974         else if ( aString.EqualsAscii( SC_UNO_ZOOMVALUE ) )
1975         {
1976             sal_Int16 nIntVal = 0;
1977             if ( aValue >>= nIntVal )
1978                 SetZoom(nIntVal);
1979         }
1980 
1981 		//	Optionen werden an der View und am Dokument (fuer neue Views) gesetzt,
1982 		//	damit sie beim Speichern erhalten bleiben.
1983 		//!	An der App (Module) braeuchte man noch eine Extra-Moeglichkeit,
1984 		//!	das einzustellen (fuer neue Dokumente)
1985 
1986 		if ( aNewOpt != rOldOpt )
1987 		{
1988 			pViewData->SetOptions( aNewOpt );
1989 			pViewData->GetDocument()->SetViewOptions( aNewOpt );
1990 			pViewData->GetDocShell()->SetDocumentModified();	//! wirklich?
1991 
1992 			pViewSh->UpdateFixPos();
1993 			pViewSh->PaintGrid();
1994 			pViewSh->PaintTop();
1995 			pViewSh->PaintLeft();
1996 			pViewSh->PaintExtras();
1997 			pViewSh->InvalidateBorder();
1998 
1999 			SfxBindings& rBindings = pViewSh->GetViewFrame()->GetBindings();
2000 			rBindings.Invalidate( FID_TOGGLEHEADERS ); // -> Checks im Menue
2001 			rBindings.Invalidate( FID_TOGGLESYNTAX );
2002 		}
2003 	}
2004 }
2005 
getPropertyValue(const rtl::OUString & aPropertyName)2006 uno::Any SAL_CALL ScTabViewObj::getPropertyValue( const rtl::OUString& aPropertyName )
2007 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2008 						uno::RuntimeException)
2009 {
2010 	ScUnoGuard aGuard;
2011 	String aString(aPropertyName);
2012 	uno::Any aRet;
2013 
2014 	ScTabViewShell* pViewSh = GetViewShell();
2015 	if (pViewSh)
2016 	{
2017 		const ScViewOptions& rOpt = pViewSh->GetViewData()->GetOptions();
2018 
2019 		if ( aString.EqualsAscii( SC_UNO_COLROWHDR ) || aString.EqualsAscii( OLD_UNO_COLROWHDR ) )
2020 			ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HEADER ) );
2021 		else if ( aString.EqualsAscii( SC_UNO_HORSCROLL ) || aString.EqualsAscii( OLD_UNO_HORSCROLL ) )
2022 			ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HSCROLL ) );
2023 		else if ( aString.EqualsAscii( SC_UNO_OUTLSYMB ) || aString.EqualsAscii( OLD_UNO_OUTLSYMB ) )
2024 			ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_OUTLINER ) );
2025 		else if ( aString.EqualsAscii( SC_UNO_SHEETTABS ) || aString.EqualsAscii( OLD_UNO_SHEETTABS ) )
2026 			ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_TABCONTROLS ) );
2027 		else if ( aString.EqualsAscii( SC_UNO_SHOWANCHOR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_ANCHOR ) );
2028 		else if ( aString.EqualsAscii( SC_UNO_SHOWFORM ) )	 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_FORMULAS ) );
2029 		else if ( aString.EqualsAscii( SC_UNO_SHOWGRID ) )	 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_GRID ) );
2030 		else if ( aString.EqualsAscii( SC_UNO_SHOWHELP ) )	 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_HELPLINES ) );
2031 		else if ( aString.EqualsAscii( SC_UNO_SHOWNOTES ) )	 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_NOTES ) );
2032 		else if ( aString.EqualsAscii( SC_UNO_SHOWPAGEBR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_PAGEBREAKS ) );
2033 		else if ( aString.EqualsAscii( SC_UNO_SHOWZERO ) )	 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_NULLVALS ) );
2034 		else if ( aString.EqualsAscii( SC_UNO_SHOWSOLID ) )	 ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_SOLIDHANDLES ) );
2035 		else if ( aString.EqualsAscii( SC_UNO_VALUEHIGH ) || aString.EqualsAscii( OLD_UNO_VALUEHIGH ) )
2036 			ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_SYNTAX ) );
2037 		else if ( aString.EqualsAscii( SC_UNO_VERTSCROLL ) || aString.EqualsAscii( OLD_UNO_VERTSCROLL ) )
2038 			ScUnoHelpFunctions::SetBoolInAny( aRet, rOpt.GetOption( VOPT_VSCROLL ) );
2039 		else if ( aString.EqualsAscii( SC_UNO_SHOWOBJ ) )	 aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_OLE ) );
2040 		else if ( aString.EqualsAscii( SC_UNO_SHOWCHARTS ) ) aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_CHART ) );
2041 		else if ( aString.EqualsAscii( SC_UNO_SHOWDRAW ) )	 aRet <<= (sal_Int16)( rOpt.GetObjMode( VOBJ_TYPE_DRAW ) );
2042 		else if ( aString.EqualsAscii( SC_UNO_GRIDCOLOR ) )	 aRet <<= (sal_Int32)( rOpt.GetGridColor().GetColor() );
2043 		else if ( aString.EqualsAscii( SC_UNO_VISAREA ) ) aRet <<= GetVisArea();
2044         else if ( aString.EqualsAscii( SC_UNO_ZOOMTYPE ) ) aRet <<= GetZoomType();
2045         else if ( aString.EqualsAscii( SC_UNO_ZOOMVALUE ) ) aRet <<= GetZoom();
2046         else if ( aString.EqualsAscii( SC_UNO_VISAREASCREEN ) )
2047         {
2048             ScViewData* pViewData = pViewSh->GetViewData();
2049             Window* pActiveWin = ( pViewData ? pViewData->GetActiveWin() : NULL );
2050             if ( pActiveWin )
2051             {
2052                 Rectangle aRect = pActiveWin->GetWindowExtentsRelative( NULL );
2053                 aRet <<= AWTRectangle( aRect );
2054             }
2055         }
2056 	}
2057 
2058 	return aRet;
2059 }
2060 
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> & xListener)2061 void SAL_CALL ScTabViewObj::addPropertyChangeListener( const ::rtl::OUString& /* aPropertyName */,
2062 									const uno::Reference<beans::XPropertyChangeListener >& xListener )
2063 								throw(beans::UnknownPropertyException,
2064 									lang::WrappedTargetException,
2065 									uno::RuntimeException)
2066 {
2067 	ScUnoGuard aGuard;
2068 	uno::Reference<beans::XPropertyChangeListener>* pObj =
2069 			new uno::Reference<beans::XPropertyChangeListener>( xListener );
2070 	aPropertyChgListeners.Insert( pObj, aPropertyChgListeners.Count() );
2071 }
2072 
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> & xListener)2073 void SAL_CALL ScTabViewObj::removePropertyChangeListener( const ::rtl::OUString& /* aPropertyName */,
2074 									const uno::Reference<beans::XPropertyChangeListener >& xListener )
2075 								throw(beans::UnknownPropertyException,
2076 									lang::WrappedTargetException,
2077 									uno::RuntimeException)
2078 {
2079 	ScUnoGuard aGuard;
2080 	sal_uInt16 nCount = aPropertyChgListeners.Count();
2081 	for ( sal_uInt16 n=nCount; n--; )
2082 	{
2083 		uno::Reference<beans::XPropertyChangeListener> *pObj = aPropertyChgListeners[n];
2084 		if ( *pObj == xListener )		//! wozu der Mumpitz mit queryInterface?
2085 		{
2086 			aPropertyChgListeners.DeleteAndDestroy( n );
2087 			break;
2088 		}
2089 	}
2090 }
2091 
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)2092 void SAL_CALL ScTabViewObj::addVetoableChangeListener( const ::rtl::OUString& /* PropertyName */,
2093                                     const uno::Reference<beans::XVetoableChangeListener >& /* aListener */ )
2094 								throw(beans::UnknownPropertyException,
2095 									lang::WrappedTargetException,
2096 									uno::RuntimeException)
2097 {
2098 }
2099 
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)2100 void SAL_CALL ScTabViewObj::removeVetoableChangeListener( const ::rtl::OUString& /* PropertyName */,
2101                                     const uno::Reference<beans::XVetoableChangeListener >& /* aListener */ )
2102 								throw(beans::UnknownPropertyException,
2103 									lang::WrappedTargetException,
2104 									uno::RuntimeException)
2105 {
2106 }
2107 
VisAreaChanged()2108 void ScTabViewObj::VisAreaChanged()
2109 {
2110 	beans::PropertyChangeEvent aEvent;
2111 	aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2112 	for ( sal_uInt16 n=0; n<aPropertyChgListeners.Count(); n++ )
2113 		(*aPropertyChgListeners[n])->propertyChange( aEvent );
2114 }
2115 
2116 // XRangeSelection
2117 
startRangeSelection(const uno::Sequence<beans::PropertyValue> & aArguments)2118 void SAL_CALL ScTabViewObj::startRangeSelection(
2119 								const uno::Sequence<beans::PropertyValue>& aArguments )
2120 									throw(uno::RuntimeException)
2121 {
2122 	ScUnoGuard aGuard;
2123 	ScTabViewShell* pViewSh = GetViewShell();
2124 	if (pViewSh)
2125 	{
2126 		String aInitVal, aTitle;
2127 		sal_Bool bCloseOnButtonUp = sal_False;
2128 		sal_Bool bSingleCell = sal_False;
2129         sal_Bool bMultiSelection = sal_False;
2130 
2131 		rtl::OUString aStrVal;
2132 		const beans::PropertyValue* pPropArray = aArguments.getConstArray();
2133 		long nPropCount = aArguments.getLength();
2134 		for (long i = 0; i < nPropCount; i++)
2135 		{
2136 			const beans::PropertyValue& rProp = pPropArray[i];
2137 			String aPropName(rProp.Name);
2138 
2139 			if (aPropName.EqualsAscii( SC_UNONAME_CLOSEONUP ))
2140 				bCloseOnButtonUp = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2141 			else if (aPropName.EqualsAscii( SC_UNONAME_TITLE ))
2142 			{
2143 				if ( rProp.Value >>= aStrVal )
2144 					aTitle = String( aStrVal );
2145 			}
2146 			else if (aPropName.EqualsAscii( SC_UNONAME_INITVAL ))
2147 			{
2148 				if ( rProp.Value >>= aStrVal )
2149 					aInitVal = String( aStrVal );
2150 			}
2151 			else if (aPropName.EqualsAscii( SC_UNONAME_SINGLECELL ))
2152 				bSingleCell = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2153             else if (aPropName.EqualsAscii( SC_UNONAME_MULTISEL ))
2154                 bMultiSelection = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
2155 		}
2156 
2157 		pViewSh->StartSimpleRefDialog( aTitle, aInitVal, bCloseOnButtonUp, bSingleCell, bMultiSelection );
2158 	}
2159 }
2160 
abortRangeSelection()2161 void SAL_CALL ScTabViewObj::abortRangeSelection() throw(uno::RuntimeException)
2162 {
2163 	ScUnoGuard aGuard;
2164 	ScTabViewShell* pViewSh = GetViewShell();
2165 	if (pViewSh)
2166 		pViewSh->StopSimpleRefDialog();
2167 }
2168 
addRangeSelectionListener(const uno::Reference<sheet::XRangeSelectionListener> & xListener)2169 void SAL_CALL ScTabViewObj::addRangeSelectionListener(
2170 								const uno::Reference<sheet::XRangeSelectionListener>& xListener )
2171 									throw(uno::RuntimeException)
2172 {
2173 	ScUnoGuard aGuard;
2174 	uno::Reference<sheet::XRangeSelectionListener>* pObj =
2175 			new uno::Reference<sheet::XRangeSelectionListener>( xListener );
2176 	aRangeSelListeners.Insert( pObj, aRangeSelListeners.Count() );
2177 }
2178 
removeRangeSelectionListener(const uno::Reference<sheet::XRangeSelectionListener> & xListener)2179 void SAL_CALL ScTabViewObj::removeRangeSelectionListener(
2180 								const uno::Reference<sheet::XRangeSelectionListener>& xListener )
2181 									throw(uno::RuntimeException)
2182 {
2183 	ScUnoGuard aGuard;
2184 	sal_uInt16 nCount = aRangeSelListeners.Count();
2185 	for ( sal_uInt16 n=nCount; n--; )
2186 	{
2187 		uno::Reference<sheet::XRangeSelectionListener> *pObj = aRangeSelListeners[n];
2188 		if ( *pObj == xListener )
2189 		{
2190 			aRangeSelListeners.DeleteAndDestroy( n );
2191 			break;
2192 		}
2193 	}
2194 }
2195 
addRangeSelectionChangeListener(const uno::Reference<sheet::XRangeSelectionChangeListener> & xListener)2196 void SAL_CALL ScTabViewObj::addRangeSelectionChangeListener(
2197 								const uno::Reference<sheet::XRangeSelectionChangeListener>& xListener )
2198 									throw(uno::RuntimeException)
2199 {
2200 	ScUnoGuard aGuard;
2201 	uno::Reference<sheet::XRangeSelectionChangeListener>* pObj =
2202 			new uno::Reference<sheet::XRangeSelectionChangeListener>( xListener );
2203 	aRangeChgListeners.Insert( pObj, aRangeChgListeners.Count() );
2204 }
2205 
removeRangeSelectionChangeListener(const uno::Reference<sheet::XRangeSelectionChangeListener> & xListener)2206 void SAL_CALL ScTabViewObj::removeRangeSelectionChangeListener(
2207 								const uno::Reference<sheet::XRangeSelectionChangeListener>& xListener )
2208 									throw(uno::RuntimeException)
2209 {
2210 	ScUnoGuard aGuard;
2211 	sal_uInt16 nCount = aRangeChgListeners.Count();
2212 	for ( sal_uInt16 n=nCount; n--; )
2213 	{
2214 		uno::Reference<sheet::XRangeSelectionChangeListener> *pObj = aRangeChgListeners[n];
2215 		if ( *pObj == xListener )
2216 		{
2217 			aRangeChgListeners.DeleteAndDestroy( n );
2218 			break;
2219 		}
2220 	}
2221 }
2222 
RangeSelDone(const String & rText)2223 void ScTabViewObj::RangeSelDone( const String& rText )
2224 {
2225 	sheet::RangeSelectionEvent aEvent;
2226 	aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2227 	aEvent.RangeDescriptor = rtl::OUString( rText );
2228 
2229 	for ( sal_uInt16 n=0; n<aRangeSelListeners.Count(); n++ )
2230 		(*aRangeSelListeners[n])->done( aEvent );
2231 }
2232 
RangeSelAborted(const String & rText)2233 void ScTabViewObj::RangeSelAborted( const String& rText )
2234 {
2235 	sheet::RangeSelectionEvent aEvent;
2236 	aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2237 	aEvent.RangeDescriptor = rtl::OUString( rText );
2238 
2239 	for ( sal_uInt16 n=0; n<aRangeSelListeners.Count(); n++ )
2240 		(*aRangeSelListeners[n])->aborted( aEvent );
2241 }
2242 
RangeSelChanged(const String & rText)2243 void ScTabViewObj::RangeSelChanged( const String& rText )
2244 {
2245 	sheet::RangeSelectionEvent aEvent;
2246 	aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
2247 	aEvent.RangeDescriptor = rtl::OUString( rText );
2248 
2249 	for ( sal_uInt16 n=0; n<aRangeChgListeners.Count(); n++ )
2250 		(*aRangeChgListeners[n])->descriptorChanged( aEvent );
2251 }
2252 
2253 // XServiceInfo
2254 
getImplementationName()2255 rtl::OUString SAL_CALL ScTabViewObj::getImplementationName() throw(uno::RuntimeException)
2256 {
2257 	return rtl::OUString::createFromAscii( "ScTabViewObj" );
2258 }
2259 
supportsService(const rtl::OUString & rServiceName)2260 sal_Bool SAL_CALL ScTabViewObj::supportsService( const rtl::OUString& rServiceName )
2261 													throw(uno::RuntimeException)
2262 {
2263 	String aServiceStr( rServiceName );
2264 	return aServiceStr.EqualsAscii( SCTABVIEWOBJ_SERVICE ) ||
2265 		   aServiceStr.EqualsAscii( SCVIEWSETTINGS_SERVICE );
2266 }
2267 
getSupportedServiceNames()2268 uno::Sequence<rtl::OUString> SAL_CALL ScTabViewObj::getSupportedServiceNames()
2269 													throw(uno::RuntimeException)
2270 {
2271 	uno::Sequence<rtl::OUString> aRet(2);
2272 	rtl::OUString* pArray = aRet.getArray();
2273 	pArray[0] = rtl::OUString::createFromAscii( SCTABVIEWOBJ_SERVICE );
2274 	pArray[1] = rtl::OUString::createFromAscii( SCVIEWSETTINGS_SERVICE );
2275 	return aRet;
2276 }
2277 
2278 // XUnoTunnel
2279 
getSomething(const uno::Sequence<sal_Int8> & rId)2280 sal_Int64 SAL_CALL ScTabViewObj::getSomething(
2281 				const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
2282 {
2283 	if ( rId.getLength() == 16 &&
2284           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
2285 									rId.getConstArray(), 16 ) )
2286 	{
2287         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
2288 	}
2289 	return 0;
2290 }
2291 
2292 // static
getUnoTunnelId()2293 const uno::Sequence<sal_Int8>& ScTabViewObj::getUnoTunnelId()
2294 {
2295 	static uno::Sequence<sal_Int8> * pSeq = 0;
2296 	if( !pSeq )
2297 	{
2298 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
2299 		if( !pSeq )
2300 		{
2301 			static uno::Sequence< sal_Int8 > aSeq( 16 );
2302 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
2303 			pSeq = &aSeq;
2304 		}
2305 	}
2306 	return *pSeq;
2307 }
2308 
2309 // static
getImplementation(const uno::Reference<uno::XInterface> xObj)2310 ScTabViewObj* ScTabViewObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
2311 {
2312 	ScTabViewObj* pRet = NULL;
2313 	uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
2314 	if (xUT.is())
2315         pRet = reinterpret_cast<ScTabViewObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
2316 	return pRet;
2317 }
2318 
getTransferable()2319 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL ScTabViewObj::getTransferable(  ) throw (::com::sun::star::uno::RuntimeException)
2320 {
2321 	ScUnoGuard aGuard;
2322 	ScEditShell* pShell = PTR_CAST( ScEditShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2323 	if (pShell)
2324 		return pShell->GetEditView()->GetTransferable();
2325 
2326     ScDrawTextObjectBar* pTextShell = PTR_CAST( ScDrawTextObjectBar, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2327     if (pTextShell)
2328     {
2329         ScViewData* pViewData = GetViewShell()->GetViewData();
2330         ScDrawView* pView = pViewData->GetScDrawView();
2331         OutlinerView* pOutView = pView->GetTextEditOutlinerView();
2332         if (pOutView)
2333 			return pOutView->GetEditView().GetTransferable();
2334     }
2335 
2336     ScDrawShell* pDrawShell = PTR_CAST( ScDrawShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2337     if (pDrawShell)
2338         return pDrawShell->GetDrawView()->CopyToTransferable();
2339 
2340     ScTransferObj* pObj = GetViewShell()->CopyToTransferable();
2341 	uno::Reference<datatransfer::XTransferable> xTransferable( pObj );
2342 	return xTransferable;
2343 }
2344 
insertTransferable(const::com::sun::star::uno::Reference<::com::sun::star::datatransfer::XTransferable> & xTrans)2345 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)
2346 {
2347 	ScUnoGuard aGuard;
2348 	ScEditShell* pShell = PTR_CAST( ScEditShell, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2349 	if (pShell)
2350         pShell->GetEditView()->InsertText( xTrans, ::rtl::OUString(), sal_False );
2351     else
2352     {
2353         ScDrawTextObjectBar* pTextShell = PTR_CAST( ScDrawTextObjectBar, GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) );
2354         if (pTextShell)
2355         {
2356             ScViewData* pViewData = GetViewShell()->GetViewData();
2357             ScDrawView* pView = pViewData->GetScDrawView();
2358             OutlinerView* pOutView = pView->GetTextEditOutlinerView();
2359             if ( pOutView )
2360             {
2361                 pOutView->GetEditView().InsertText( xTrans, ::rtl::OUString(), sal_False );
2362                 return;
2363             }
2364         }
2365 
2366         GetViewShell()->PasteFromTransferable( xTrans );
2367     }
2368 }
2369 
2370 //------------------------------------------------------------------------
2371 
2372 
2373 
2374 
2375