xref: /aoo41x/main/sc/source/ui/view/tabvwsh4.cxx (revision 710dc5ad)
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 
28 
29 // INCLUDE ---------------------------------------------------------------
30 
31 #include "scitems.hxx"
32 #include <editeng/eeitem.hxx>
33 
34 #include <sfx2/app.hxx>
35 #include <svx/extrusionbar.hxx>
36 #include <svx/fontworkbar.hxx>
37 #include <editeng/boxitem.hxx>
38 #include <svx/fmshell.hxx>
39 #include <editeng/sizeitem.hxx>
40 #include <editeng/boxitem.hxx>
41 #include <svx/prtqry.hxx>
42 #include <svx/sidebar/ContextChangeEventMultiplexer.hxx>
43 #include <sfx2/request.hxx>
44 #include <sfx2/printer.hxx>
45 #include <sfx2/dispatch.hxx>
46 #include <svl/whiter.hxx>
47 #include <unotools/moduleoptions.hxx>
48 #include <rtl/logfile.hxx>
49 #include <tools/urlobj.hxx>
50 #include <sfx2/docfile.hxx>
51 
52 #include "tabvwsh.hxx"
53 #include "sc.hrc"
54 #include "globstr.hrc"
55 #include "stlpool.hxx"
56 #include "stlsheet.hxx"
57 #include "docsh.hxx"
58 #include "scmod.hxx"
59 #include "appoptio.hxx"
60 #include "rangeutl.hxx"
61 #include "printfun.hxx"
62 #include "drawsh.hxx"
63 #include "drformsh.hxx"
64 #include "editsh.hxx"
65 #include "pivotsh.hxx"
66 #include "auditsh.hxx"
67 #include "drtxtob.hxx"
68 #include "inputhdl.hxx"
69 #include "editutil.hxx"
70 #include "inputopt.hxx"
71 #include "inputwin.hxx"
72 #include "scresid.hxx"
73 #include "dbcolect.hxx"		// fuer ReImport
74 #include "reffact.hxx"
75 #include "viewuno.hxx"
76 #include "dispuno.hxx"
77 #include "anyrefdg.hxx"
78 #include "chgtrack.hxx"
79 #include "cellsh.hxx"
80 #include "oleobjsh.hxx"
81 #include "chartsh.hxx"
82 #include "graphsh.hxx"
83 #include "mediash.hxx"
84 #include "pgbrksh.hxx"
85 #include "dpobject.hxx"
86 #include "prevwsh.hxx"
87 #include "tpprint.hxx"
88 #include "scextopt.hxx"
89 #include "printopt.hxx"
90 #include "drawview.hxx"
91 #include "fupoor.hxx"
92 #include "navsett.hxx"
93 #include "sc.hrc" //CHINA001
94 #include "scabstdlg.hxx" //CHINA001
95 #include "externalrefmgr.hxx"
96 #include <svx/fmpage.hxx>
97 
98 void ActivateOlk( ScViewData* pViewData );
99 void DeActivateOlk( ScViewData* pViewData );
100 
101 extern SfxViewShell* pScActiveViewShell;			// global.cxx
102 
103 using namespace com::sun::star;
104 
105 // STATIC DATA -----------------------------------------------------------
106 
107 sal_uInt16 ScTabViewShell::nInsertCtrlState = SID_INSERT_GRAPHIC;
108 sal_uInt16 ScTabViewShell::nInsCellsCtrlState = 0;
109 sal_uInt16 ScTabViewShell::nInsObjCtrlState = SID_INSERT_DIAGRAM;
110 
111 // -----------------------------------------------------------------------
112 
Activate(sal_Bool bMDI)113 void __EXPORT ScTabViewShell::Activate(sal_Bool bMDI)
114 {
115 	SfxViewShell::Activate(bMDI);
116 	bIsActive = sal_True;
117 	//	hier kein GrabFocus, sonst gibt's Probleme wenn etwas inplace editiert wird!
118 
119 	if ( bMDI )
120 	{
121 		//	fuer Eingabezeile (ClearCache)
122 		ScModule* pScMod = SC_MOD();
123 		pScMod->ViewShellChanged();
124 
125 		ActivateView( sal_True, bFirstActivate );
126 		ActivateOlk( GetViewData() );
127 
128 		//	#56870# AutoCorrect umsetzen, falls der Writer seins neu angelegt hat
129 		UpdateDrawTextOutliner();
130 
131 		//	RegisterNewTargetNames gibts nicht mehr
132 
133 		SfxViewFrame* pThisFrame  = GetViewFrame();
134 		if ( pInputHandler && pThisFrame->HasChildWindow(FID_INPUTLINE_STATUS) )
135 		{
136 			//	eigentlich nur beim Reload (letzte Version) noetig:
137 			//	Das InputWindow bleibt stehen, aber die View mitsamt InputHandler wird
138 			//	neu angelegt, darum muss der InputHandler am InputWindow gesetzt werden.
139 			SfxChildWindow* pChild = pThisFrame->GetChildWindow(FID_INPUTLINE_STATUS);
140 			if (pChild)
141 			{
142 				ScInputWindow* pWin = (ScInputWindow*)pChild->GetWindow();
143 				if (pWin && pWin->IsVisible())
144 				{
145 
146 					ScInputHandler* pOldHdl=pWin->GetInputHandler();
147 
148 					TypeId aScType = TYPE(ScTabViewShell);
149 
150 					SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
151 					while ( pSh!=NULL && pOldHdl!=NULL)
152 					{
153 						if (((ScTabViewShell*)pSh)->GetInputHandler() == pOldHdl)
154 						{
155 							pOldHdl->ResetDelayTimer();
156 							break;
157 						}
158 						pSh = SfxViewShell::GetNext( *pSh, &aScType );
159 					}
160 
161 					pWin->SetInputHandler( pInputHandler );
162 				}
163 			}
164 		}
165 
166 		UpdateInputHandler( sal_True );
167 
168 		if ( bFirstActivate )
169 		{
170 			SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_NAVIGATOR_UPDATEALL ) );
171 			bFirstActivate = sal_False;
172 
173             // #116278# ReadExtOptions (view settings from Excel import) must also be done
174             // after the ctor, because of the potential calls to Window::Show.
175             // Even after the fix for #104887# (Window::Show no longer notifies the access
176             // bridge, it's done in ImplSetReallyVisible), there are problems if Window::Show
177             // is called during the ViewShell ctor and reschedules asynchronous calls
178             // (for example from the FmFormShell ctor).
179             ScExtDocOptions* pExtOpt = GetViewData()->GetDocument()->GetExtDocOptions();
180             if ( pExtOpt && pExtOpt->IsChanged() )
181             {
182                 GetViewData()->ReadExtOptions(*pExtOpt);        // Excel view settings
183                 SetTabNo( GetViewData()->GetTabNo(), sal_True );
184                 pExtOpt->SetChanged( false );
185             }
186 		}
187 
188 		pScActiveViewShell = this;
189 
190 		ScInputHandler* pHdl = pScMod->GetInputHdl(this);
191 		if (pHdl)
192 		{
193 			pHdl->SetRefScale( GetViewData()->GetZoomX(), GetViewData()->GetZoomY() );
194 		}
195 
196 		//	Aenderungs-Dialog aktualisieren
197 
198 		if ( pThisFrame->HasChildWindow(FID_CHG_ACCEPT) )
199 		{
200 			SfxChildWindow* pChild = pThisFrame->GetChildWindow(FID_CHG_ACCEPT);
201 			if (pChild)
202 			{
203 				((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg();
204 			}
205 		}
206 
207 		if(pScMod->IsRefDialogOpen())
208 		{
209 			sal_uInt16 nModRefDlgId=pScMod->GetCurRefDlgId();
210 			SfxChildWindow* pChildWnd = pThisFrame->GetChildWindow( nModRefDlgId );
211 			if ( pChildWnd )
212 			{
213 				IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
214 				pRefDlg->ViewShellChanged(this);
215 			}
216 		}
217 	}
218 
219 	//	don't call CheckSelectionTransfer here - activating a view should not change the
220 	//	primary selection (may be happening just because the mouse was moved over the window)
221 
222 	//	Wenn Referenzeingabe-Tip-Hilfe hier wieder angezeigt werden soll (ShowRefTip),
223 	//	muss sie beim Verschieben der View angepasst werden (gibt sonst Probleme unter OS/2
224 	//	beim Umschalten zwischen Dokumenten)
225 
226     ContextChangeEventMultiplexer::NotifyContextChange(
227         GetController(),
228         ::sfx2::sidebar::EnumContext::Context_Default);
229 }
230 
Deactivate(sal_Bool bMDI)231 void __EXPORT ScTabViewShell::Deactivate(sal_Bool bMDI)
232 {
233 	HideTip();
234 
235 	ScDocument*	pDoc=GetViewData()->GetDocument();
236 
237 	ScChangeTrack* pChanges=pDoc->GetChangeTrack();
238 
239 	if(pChanges!=NULL)
240 	{
241 		Link aLink;
242 		pChanges->SetModifiedLink(aLink);
243 	}
244 
245 	SfxViewShell::Deactivate(bMDI);
246 	bIsActive = sal_False;
247 	ScInputHandler* pHdl = SC_MOD()->GetInputHdl(this);
248 
249 	if( bMDI )
250 	{
251 		//	#85421# during shell deactivation, shells must not be switched, or the loop
252 		//	through the shell stack (in SfxDispatcher::DoDeactivate_Impl) will not work
253 		sal_Bool bOldDontSwitch = bDontSwitch;
254 		bDontSwitch = sal_True;
255 
256 		DeActivateOlk( GetViewData() );
257 		ActivateView( sal_False, sal_False );
258 
259         if ( GetViewFrame()->GetFrame().IsInPlace() ) // inplace
260 			GetViewData()->GetDocShell()->UpdateOle(GetViewData(),sal_True);
261 
262 		if ( pHdl )
263 			pHdl->NotifyChange( NULL, sal_True ); // Timer-verzoegert wg. Dokumentwechsel
264 
265 		if (pScActiveViewShell == this)
266 			pScActiveViewShell = NULL;
267 
268 		bDontSwitch = bOldDontSwitch;
269 	}
270 	else
271 	{
272 		HideNoteMarker();			// Notiz-Anzeige
273 
274 		if ( pHdl )
275 			pHdl->HideTip();		// Formel-AutoEingabe-Tip abschalten
276 	}
277 }
278 
SetActive()279 void ScTabViewShell::SetActive()
280 {
281 	// Die Sfx-View moechte sich gerne selbst aktivieren, weil dabei noch
282 	// magische Dinge geschehen (z.B. stuerzt sonst evtl. der Gestalter ab)
283 	ActiveGrabFocus();
284 
285 #if 0
286 	SfxViewFrame* pFrame = GetViewFrame();
287 	pFrame->GetFrame().Appear();
288 
289 	SFX_APP()->SetViewFrame( pFrame );			// immer erst Appear, dann SetViewFrame (#29290#)
290 #endif
291 }
292 
PrepareClose(sal_Bool bUI,sal_Bool bForBrowsing)293 sal_uInt16 __EXPORT ScTabViewShell::PrepareClose(sal_Bool bUI, sal_Bool bForBrowsing)
294 {
295     // Call EnterHandler even in formula mode here,
296     // so a formula change in an embedded object isn't lost
297     // (ScDocShell::PrepareClose isn't called then).
298     ScInputHandler* pHdl = SC_MOD()->GetInputHdl( this );
299     if ( pHdl && pHdl->IsInputMode() )
300         pHdl->EnterHandler();
301 
302     // #110797# draw text edit mode must be closed
303     FuPoor* pPoor = GetDrawFuncPtr();
304     if ( pPoor && ( IsDrawTextShell() || pPoor->GetSlotID() == SID_DRAW_NOTEEDIT ) )
305     {
306         // "clean" end of text edit, including note handling, subshells and draw func switching,
307         // as in FuDraw and ScTabView::DrawDeselectAll
308         GetViewData()->GetDispatcher().Execute( pPoor->GetSlotID(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
309     }
310     ScDrawView* pDrView = GetScDrawView();
311     if ( pDrView )
312     {
313         // force end of text edit, to be safe
314         // #128314# ScEndTextEdit must always be used, to ensure correct UndoManager
315         pDrView->ScEndTextEdit();
316     }
317 
318 	if ( pFormShell )
319 	{
320 		sal_uInt16 nRet = pFormShell->PrepareClose(bUI, bForBrowsing);
321 		if (nRet!=sal_True)
322 			return nRet;
323 	}
324 	return SfxViewShell::PrepareClose(bUI,bForBrowsing);
325 }
326 
327 //------------------------------------------------------------------
328 
GetOptimalSizePixel() const329 Size __EXPORT ScTabViewShell::GetOptimalSizePixel() const
330 {
331 	Size aOptSize;
332 
333 	SCTAB				nCurTab		= GetViewData()->GetTabNo();
334 	ScDocument*			pDoc		= GetViewData()->GetDocument();
335 	ScStyleSheetPool*	pStylePool  = pDoc->GetStyleSheetPool();
336 	SfxStyleSheetBase*	pStyleSheet = pStylePool->Find(
337 										pDoc->GetPageStyle( nCurTab ),
338 										SFX_STYLE_FAMILY_PAGE );
339 
340 	DBG_ASSERT( pStyleSheet, "PageStyle not found :-/" );
341 
342 	if ( pStyleSheet )
343 	{
344 		const SfxItemSet&  rSet 	 = pStyleSheet->GetItemSet();
345 		const SvxSizeItem& rItem	 = (const SvxSizeItem&)rSet.Get( ATTR_PAGE_SIZE );
346 		const Size&		   rPageSize = rItem.GetSize();
347 
348 		aOptSize.Width()  = (long) (rPageSize.Width()  * GetViewData()->GetPPTX());
349 		aOptSize.Height() = (long) (rPageSize.Height() * GetViewData()->GetPPTY());
350 	}
351 
352 	return aOptSize;
353 }
354 
355 //------------------------------------------------------------------
356 
357 //	Zoom fuer In-Place berechnen
358 //	aus Verhaeltnis von VisArea und Fenstergroesse des GridWin
359 
UpdateOleZoom()360 void ScTabViewShell::UpdateOleZoom()
361 {
362 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
363 	if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
364 	{
365         //TODO/LATER: is there a difference between the two GetVisArea methods?
366         Size aObjSize = ((const SfxObjectShell*)pDocSh)->GetVisArea().GetSize();
367 		if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
368 		{
369 			Window* pWin = GetActiveWin();
370 			Size aWinHMM = pWin->PixelToLogic( pWin->GetOutputSizePixel(), MAP_100TH_MM );
371 			SetZoomFactor( Fraction( aWinHMM.Width(),aObjSize.Width() ),
372 							Fraction( aWinHMM.Height(),aObjSize.Height() ) );
373 		}
374 	}
375 }
376 
AdjustPosSizePixel(const Point & rPos,const Size & rSize)377 void __EXPORT ScTabViewShell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
378 {
379 	OuterResizePixel( rPos, rSize );
380 }
381 
InnerResizePixel(const Point & rOfs,const Size & rSize)382 void __EXPORT ScTabViewShell::InnerResizePixel( const Point &rOfs, const Size &rSize )
383 {
384 	Size aNewSize( rSize );
385     if ( GetViewFrame()->GetFrame().IsInPlace() )
386 	{
387 		SvBorder aBorder;
388 	   	GetBorderSize( aBorder, rSize );
389 		SetBorderPixel( aBorder );
390 
391 		Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
392 
393       	Size aSize( rSize );
394         aSize.Width() -= (aBorder.Left() + aBorder.Right());
395         aSize.Height() -= (aBorder.Top() + aBorder.Bottom());
396 
397 		if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
398     	{
399         	Size aLogicSize = GetWindow()->PixelToLogic( aSize, MAP_100TH_MM );
400         	SfxViewShell::SetZoomFactor( Fraction( aLogicSize.Width(),aObjSize.Width() ),
401                         	Fraction( aLogicSize.Height(),aObjSize.Height() ) );
402     	}
403 
404         Point aPos( rOfs );
405         aPos.X() += aBorder.Left();
406         aPos.Y() += aBorder.Top();
407         GetWindow()->SetPosSizePixel( aPos, aSize );
408 	}
409 	else
410     {
411         SvBorder aBorder;
412         GetBorderSize( aBorder, rSize );
413         SetBorderPixel( aBorder );
414         aNewSize.Width()  += aBorder.Left() + aBorder.Right();
415         aNewSize.Height() += aBorder.Top() + aBorder.Bottom();
416     }
417 
418 	DoResize( rOfs, aNewSize, sal_True );					// rSize = Groesse von gridwin
419 
420 	UpdateOleZoom();									//	Zoom fuer In-Place berechnen
421 
422 //	GetViewData()->GetDocShell()->UpdateOle( GetViewData() );
423 	GetViewData()->GetDocShell()->SetDocumentModified();
424 }
425 
OuterResizePixel(const Point & rOfs,const Size & rSize)426 void __EXPORT ScTabViewShell::OuterResizePixel( const Point &rOfs, const Size &rSize )
427 {
428 	SvBorder aBorder;
429 	GetBorderSize( aBorder, rSize );
430 	SetBorderPixel( aBorder );
431 
432 	DoResize( rOfs, rSize );					// Position und Groesse von tabview wie uebergeben
433 
434 	// ForceMove als Ersatz fuer den Sfx-Move-Mechanismus
435 	// (aWinPos muss aktuell gehalten werden, damit ForceMove beim Ole-Deaktivieren klappt)
436 
437 	ForceMove();
438 }
439 
SetZoomFactor(const Fraction & rZoomX,const Fraction & rZoomY)440 void __EXPORT ScTabViewShell::SetZoomFactor( const Fraction &rZoomX, const Fraction &rZoomY )
441 {
442 	//	fuer OLE...
443 
444 	Fraction aFrac20( 1,5 );
445 	Fraction aFrac400( 4,1 );
446 
447 	Fraction aNewX( rZoomX );
448 	if ( aNewX < aFrac20 )
449 		aNewX = aFrac20;
450 	if ( aNewX > aFrac400 )
451 		aNewX = aFrac400;
452 	Fraction aNewY( rZoomY );
453 	if ( aNewY < aFrac20 )
454 		aNewY = aFrac20;
455 	if ( aNewY > aFrac400 )
456 		aNewY = aFrac400;
457 
458 	GetViewData()->UpdateScreenZoom( aNewX, aNewY );
459     SetZoom( aNewX, aNewY, sal_True );
460 
461 	PaintGrid();
462 	PaintTop();
463 	PaintLeft();
464 
465 	SfxViewShell::SetZoomFactor( rZoomX, rZoomY );
466 }
467 
QueryObjAreaPixel(Rectangle & rRect) const468 void __EXPORT ScTabViewShell::QueryObjAreaPixel( Rectangle& rRect ) const
469 {
470 	//	auf ganze Zellen anpassen (in 1/100 mm)
471 
472 	Size aPixelSize = rRect.GetSize();
473 	Window* pWin = ((ScTabViewShell*)this)->GetActiveWin();
474 	Size aLogicSize = pWin->PixelToLogic( aPixelSize );
475 
476 	const ScViewData* pViewData = GetViewData();
477 	ScDocument* pDoc = pViewData->GetDocument();
478 	ScSplitPos ePos = pViewData->GetActivePart();
479 	SCCOL nCol = pViewData->GetPosX(WhichH(ePos));
480 	SCROW nRow = pViewData->GetPosY(WhichV(ePos));
481 	SCTAB nTab = pViewData->GetTabNo();
482     sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
483 
484 	Rectangle aLogicRect = pDoc->GetMMRect( nCol, nRow, nCol, nRow, nTab );
485 	if ( bNegativePage )
486 	{
487 	    // use right edge of aLogicRect, and aLogicSize
488 	    aLogicRect.Left() = aLogicRect.Right() - aLogicSize.Width() + 1;    // Right() is set below
489 	}
490 	aLogicRect.SetSize( aLogicSize );
491 
492 	pDoc->SnapVisArea( aLogicRect );
493 
494 	rRect.SetSize( pWin->LogicToPixel( aLogicRect.GetSize() ) );
495 
496 #if 0
497 	//	auf ganze Zellen anpassen (in Pixeln)
498 
499 	ScViewData* pViewData = ((ScTabViewShell*)this)->GetViewData();
500 	Size aSize = rRect.GetSize();
501 
502 	ScSplitPos ePos = pViewData->GetActivePart();
503 	Window* pWin = ((ScTabViewShell*)this)->GetActiveWin();
504 
505 	Point aTest( aSize.Width(), aSize.Height() );
506 	SCsCOL nPosX;
507 	SCsROW nPosY;
508 	pViewData->GetPosFromPixel( aTest.X(), aTest.Y(), ePos, nPosX, nPosY );
509 	sal_Bool bLeft;
510 	sal_Bool bTop;
511 	pViewData->GetMouseQuadrant( aTest, ePos, nPosX, nPosY, bLeft, bTop );
512 	if (!bLeft)
513 		++nPosX;
514 	if (!bTop)
515 		++nPosY;
516 	aTest = pViewData->GetScrPos( (SCCOL)nPosX, (SCROW)nPosY, ePos, sal_True );
517 
518 	rRect.SetSize(Size(aTest.X(),aTest.Y()));
519 #endif
520 }
521 
522 //------------------------------------------------------------------
523 
Move()524 void __EXPORT ScTabViewShell::Move()
525 {
526 	Point aNewPos = GetViewFrame()->GetWindow().OutputToScreenPixel(Point());
527 
528 	if (aNewPos != aWinPos)
529 	{
530 		StopMarking();
531 		aWinPos = aNewPos;
532 	}
533 }
534 
535 //------------------------------------------------------------------
536 
ShowCursor(FASTBOOL)537 void __EXPORT ScTabViewShell::ShowCursor(FASTBOOL /* bOn */)
538 {
539 /*!!!	ShowCursor wird nicht paarweise wie im gridwin gerufen.
540 		Der CursorLockCount am Gridwin muss hier direkt auf 0 gesetzt werden
541 
542 	if (bOn)
543 		ShowAllCursors();
544 	else
545 		HideAllCursors();
546 */
547 }
548 
549 //------------------------------------------------------------------
550 
WriteUserData(String & rData,sal_Bool)551 void __EXPORT ScTabViewShell::WriteUserData(String& rData, sal_Bool /* bBrowse */)
552 {
553 	GetViewData()->WriteUserData(rData);
554 }
555 
WriteUserDataSequence(uno::Sequence<beans::PropertyValue> & rSettings,sal_Bool)556 void ScTabViewShell::WriteUserDataSequence (uno::Sequence < beans::PropertyValue >& rSettings, sal_Bool /* bBrowse */ )
557 {
558 	GetViewData()->WriteUserDataSequence (rSettings);
559 }
560 
ReadUserData(const String & rData,sal_Bool)561 void __EXPORT ScTabViewShell::ReadUserData(const String& rData, sal_Bool /* bBrowse */)
562 {
563 	if ( !GetViewData()->GetDocShell()->IsPreview() )
564 		DoReadUserData( rData );
565 }
566 
ReadUserDataSequence(const uno::Sequence<beans::PropertyValue> & rSettings,sal_Bool)567 void ScTabViewShell::ReadUserDataSequence (const uno::Sequence < beans::PropertyValue >& rSettings, sal_Bool /* bBrowse */ )
568 {
569     if ( !GetViewData()->GetDocShell()->IsPreview() )
570         DoReadUserDataSequence( rSettings );
571 }
572 
DoReadUserDataSequence(const uno::Sequence<beans::PropertyValue> & rSettings)573 void ScTabViewShell::DoReadUserDataSequence( const uno::Sequence < beans::PropertyValue >& rSettings )
574 {
575 	Window* pOldWin = GetActiveWin();
576 	sal_Bool bFocus = pOldWin && pOldWin->HasFocus();
577 
578 	GetViewData()->ReadUserDataSequence(rSettings);
579 	SetTabNo( GetViewData()->GetTabNo(), sal_True );
580 
581 	if ( GetViewData()->IsPagebreakMode() )
582 		SetCurSubShell( GetCurObjectSelectionType(), sal_True );
583 
584 	Window* pNewWin = GetActiveWin();
585 	if (pNewWin && pNewWin != pOldWin)
586 	{
587 		SetWindow( pNewWin );		//! ist diese ViewShell immer aktiv???
588 		if (bFocus)
589 			pNewWin->GrabFocus();
590 		WindowChanged();			// Drawing-Layer (z.B. #56771#)
591 	}
592 
593 	if (GetViewData()->GetHSplitMode() == SC_SPLIT_FIX ||
594 		GetViewData()->GetVSplitMode() == SC_SPLIT_FIX)
595 	{
596 		InvalidateSplit();
597 	}
598 
599 	ZoomChanged();
600 
601 	TestHintWindow();
602 
603 	//!	if ViewData has more tables than document, remove tables in ViewData
604 }
605 
606 // DoReadUserData is also called from ctor when switching from print preview
607 
DoReadUserData(const String & rData)608 void ScTabViewShell::DoReadUserData( const String& rData )
609 {
610 	Window* pOldWin = GetActiveWin();
611 	sal_Bool bFocus = pOldWin && pOldWin->HasFocus();
612 
613 	GetViewData()->ReadUserData(rData);
614 	SetTabNo( GetViewData()->GetTabNo(), sal_True );
615 
616 	if ( GetViewData()->IsPagebreakMode() )
617 		SetCurSubShell( GetCurObjectSelectionType(), sal_True );
618 
619 	Window* pNewWin = GetActiveWin();
620 	if (pNewWin && pNewWin != pOldWin)
621 	{
622 		SetWindow( pNewWin );		//! ist diese ViewShell immer aktiv???
623 		if (bFocus)
624 			pNewWin->GrabFocus();
625 		WindowChanged();			// Drawing-Layer (z.B. #56771#)
626 	}
627 
628 	if (GetViewData()->GetHSplitMode() == SC_SPLIT_FIX ||
629 		GetViewData()->GetVSplitMode() == SC_SPLIT_FIX)
630 	{
631 		InvalidateSplit();
632 	}
633 
634 	ZoomChanged();
635 
636 	TestHintWindow();
637 
638 	//!	if ViewData has more tables than document, remove tables in ViewData
639 }
640 
641 //------------------------------------------------------------------
642 
UpdateDrawShell()643 void ScTabViewShell::UpdateDrawShell()
644 {
645     // Called after user interaction that may delete the selected drawing object.
646     // Remove DrawShell if nothing is selected.
647 
648     SdrView* pDrView = GetSdrView();
649     if ( pDrView && !pDrView->AreObjectsMarked() && !IsDrawSelMode() )
650         SetDrawShell( sal_False );
651 }
652 
SetDrawShellOrSub()653 void ScTabViewShell::SetDrawShellOrSub()
654 {
655 	bActiveDrawSh = sal_True;
656 
657 	if(bActiveDrawFormSh)
658 	{
659 		SetCurSubShell(OST_DrawForm);
660 	}
661 	else if(bActiveGraphicSh)
662 	{
663 		SetCurSubShell(OST_Graphic);
664 	}
665 	else if(bActiveMediaSh)
666 	{
667 		SetCurSubShell(OST_Media);
668 	}
669 	else if(bActiveChartSh)
670 	{
671 		SetCurSubShell(OST_Chart);
672 	}
673 	else if(bActiveOleObjectSh)
674 	{
675 		SetCurSubShell(OST_OleObject);
676 	}
677 	else
678 	{
679 		SetCurSubShell(OST_Drawing, true /* force: different toolbars are
680                                             visible concerning shape type
681                                             and shape state */);
682 	}
683 }
684 
SetDrawShell(sal_Bool bActive)685 void ScTabViewShell::SetDrawShell( sal_Bool bActive )
686 {
687 	if(bActive)
688 	{
689 		SetCurSubShell(OST_Drawing, true /* force: different toolbars are
690                                             visible concerning shape type
691                                             and shape state */);
692 	}
693 	else
694 	{
695 		if(bActiveDrawFormSh || bActiveDrawSh ||
696             bActiveGraphicSh || bActiveMediaSh || bActiveOleObjectSh||
697 			bActiveChartSh || bActiveDrawTextSh)
698 		{
699 			SetCurSubShell(OST_Cell);
700 		}
701 		bActiveDrawFormSh=sal_False;
702 		bActiveGraphicSh=sal_False;
703         bActiveMediaSh=sal_False;
704 		bActiveOleObjectSh=sal_False;
705 		bActiveChartSh=sal_False;
706 	}
707 
708 	sal_Bool bWasDraw = bActiveDrawSh || bActiveDrawTextSh;
709 
710 	bActiveDrawSh = bActive;
711 	bActiveDrawTextSh = sal_False;
712 
713 	if ( !bActive )
714 	{
715 		ResetDrawDragMode();		//	Mirror / Rotate aus
716 
717 		if (bWasDraw && (GetViewData()->GetHSplitMode() == SC_SPLIT_FIX ||
718 						 GetViewData()->GetVSplitMode() == SC_SPLIT_FIX))
719 		{
720 			//	Aktiven Teil an Cursor anpassen, etc.
721 			MoveCursorAbs( GetViewData()->GetCurX(), GetViewData()->GetCurY(),
722 							SC_FOLLOW_NONE, sal_False, sal_False, sal_True );
723 		}
724 	}
725 }
726 
SetDrawTextShell(sal_Bool bActive)727 void ScTabViewShell::SetDrawTextShell( sal_Bool bActive )
728 {
729 	bActiveDrawTextSh = bActive;
730 	if ( bActive )
731 	{
732 		bActiveDrawFormSh=sal_False;
733 		bActiveGraphicSh=sal_False;
734         bActiveMediaSh=sal_False;
735 		bActiveOleObjectSh=sal_False;
736 		bActiveChartSh=sal_False;
737 		bActiveDrawSh = sal_False;
738 		SetCurSubShell(OST_DrawText);
739 	}
740 	else
741 		SetCurSubShell(OST_Cell);
742 
743 }
744 
SetPivotShell(sal_Bool bActive)745 void ScTabViewShell::SetPivotShell( sal_Bool bActive )
746 {
747 	bActivePivotSh = bActive;
748 
749 	//	#68771# #76198# SetPivotShell is called from CursorPosChanged every time
750 	//	-> don't change anything except switching between cell and pivot shell
751 
752 	if ( eCurOST == OST_Pivot || eCurOST == OST_Cell )
753 	{
754 		if ( bActive )
755 		{
756 			bActiveDrawTextSh = bActiveDrawSh = sal_False;
757 			bActiveDrawFormSh=sal_False;
758 			bActiveGraphicSh=sal_False;
759             bActiveMediaSh=sal_False;
760 			bActiveOleObjectSh=sal_False;
761 			bActiveChartSh=sal_False;
762 			SetCurSubShell(OST_Pivot);
763 		}
764 		else
765 			SetCurSubShell(OST_Cell);
766 	}
767 }
768 
SetAuditShell(sal_Bool bActive)769 void ScTabViewShell::SetAuditShell( sal_Bool bActive )
770 {
771 	bActiveAuditingSh = bActive;
772 	if ( bActive )
773 	{
774 		bActiveDrawTextSh = bActiveDrawSh = sal_False;
775 		bActiveDrawFormSh=sal_False;
776 		bActiveGraphicSh=sal_False;
777         bActiveMediaSh=sal_False;
778 		bActiveOleObjectSh=sal_False;
779 		bActiveChartSh=sal_False;
780 		SetCurSubShell(OST_Auditing);
781 	}
782 	else
783 		SetCurSubShell(OST_Cell);
784 }
785 
SetDrawFormShell(sal_Bool bActive)786 void ScTabViewShell::SetDrawFormShell( sal_Bool bActive )
787 {
788 	bActiveDrawFormSh = bActive;
789 
790 	if(bActiveDrawFormSh)
791 		SetCurSubShell(OST_DrawForm);
792 }
SetChartShell(sal_Bool bActive)793 void ScTabViewShell::SetChartShell( sal_Bool bActive )
794 {
795 	bActiveChartSh = bActive;
796 
797 	if(bActiveChartSh)
798 		SetCurSubShell(OST_Chart);
799 }
800 
SetGraphicShell(sal_Bool bActive)801 void ScTabViewShell::SetGraphicShell( sal_Bool bActive )
802 {
803 	bActiveGraphicSh = bActive;
804 
805 	if(bActiveGraphicSh)
806 		SetCurSubShell(OST_Graphic);
807 }
808 
SetMediaShell(sal_Bool bActive)809 void ScTabViewShell::SetMediaShell( sal_Bool bActive )
810 {
811 	bActiveMediaSh = bActive;
812 
813 	if(bActiveMediaSh)
814 		SetCurSubShell(OST_Media);
815 }
816 
SetOleObjectShell(sal_Bool bActive)817 void ScTabViewShell::SetOleObjectShell( sal_Bool bActive )
818 {
819 	bActiveOleObjectSh = bActive;
820 
821 	if(bActiveOleObjectSh)
822 		SetCurSubShell(OST_OleObject);
823 	else
824 		SetCurSubShell(OST_Cell);
825 }
826 
SetEditShell(EditView * pView,sal_Bool bActive)827 void ScTabViewShell::SetEditShell(EditView* pView, sal_Bool bActive )
828 {
829 	if(bActive)
830 	{
831 		if (pEditShell)
832 			pEditShell->SetEditView( pView );
833 		else
834 			pEditShell = new ScEditShell( pView, GetViewData() );
835 
836 		SetCurSubShell(OST_Editing);
837 	}
838 	else if(bActiveEditSh)
839 	{
840 		SetCurSubShell(OST_Cell);
841 	}
842 	bActiveEditSh = bActive;
843 }
844 
SetCurSubShell(ObjectSelectionType eOST,sal_Bool bForce)845 void ScTabViewShell::SetCurSubShell(ObjectSelectionType	eOST, sal_Bool bForce)
846 {
847 	ScViewData* pViewData	= GetViewData();
848 	ScDocShell* pDocSh		= pViewData->GetDocShell();
849 
850 	if(bDontSwitch) return;
851 
852 	if(!pCellShell) //Wird eh immer gebraucht.
853 	{
854 		pCellShell = new ScCellShell( GetViewData() );
855 		pCellShell->SetRepeatTarget( &aTarget );
856 	}
857 
858 	sal_Bool bPgBrk=pViewData->IsPagebreakMode();
859 
860 	if(bPgBrk && !pPageBreakShell)
861 	{
862 		pPageBreakShell = new ScPageBreakShell( this );
863 		pPageBreakShell->SetRepeatTarget( &aTarget );
864 	}
865 
866 
867 	if ( eOST!=eCurOST || bForce )
868 	{
869         sal_Bool bCellBrush = sal_False;    // "format paint brush" allowed for cells
870         sal_Bool bDrawBrush = sal_False;    // "format paint brush" allowed for drawing objects
871 
872 		if(eCurOST!=OST_NONE) RemoveSubShell();
873 
874 		if (pFormShell && !bFormShellAtTop)
875 		    AddSubShell(*pFormShell);               // add below own subshells
876 
877 		switch(eOST)
878 		{
879 			case	OST_Cell:
880 					{
881 						AddSubShell(*pCellShell);
882 						if(bPgBrk) AddSubShell(*pPageBreakShell);
883                         bCellBrush = sal_True;
884 					}
885 					break;
886 			case	OST_Editing:
887 					{
888 						AddSubShell(*pCellShell);
889 						if(bPgBrk) AddSubShell(*pPageBreakShell);
890 
891 						if(pEditShell)
892 						{
893 							AddSubShell(*pEditShell);
894 						}
895 					}
896 					break;
897 			case	OST_DrawText:
898 					{
899 						if ( !pDrawTextShell )
900 						{
901 							pDocSh->MakeDrawLayer();
902 							pDrawTextShell = new ScDrawTextObjectBar( GetViewData() );
903 						}
904 						AddSubShell(*pDrawTextShell);
905 					}
906 					break;
907 			case	OST_Drawing:
908 					{
909                         if (svx::checkForSelectedCustomShapes(
910                                 GetScDrawView(), true /* bOnlyExtruded */ )) {
911                             if (pExtrusionBarShell == 0)
912                                 pExtrusionBarShell = new svx::ExtrusionBar(this);
913                             AddSubShell( *pExtrusionBarShell );
914                         }
915                         sal_uInt32 nCheckStatus = 0;
916                         if (svx::checkForSelectedFontWork(
917                                 GetScDrawView(), nCheckStatus )) {
918                             if (pFontworkBarShell == 0)
919                                 pFontworkBarShell = new svx::FontworkBar(this);
920                             AddSubShell( *pFontworkBarShell );
921                         }
922 
923 						if ( !pDrawShell )
924 						{
925 							pDocSh->MakeDrawLayer();
926 							pDrawShell = new ScDrawShell( GetViewData() );
927 							pDrawShell->SetRepeatTarget( &aTarget );
928 						}
929 						AddSubShell(*pDrawShell);
930 						bDrawBrush = sal_True;
931 					}
932 					break;
933 
934 			case	OST_DrawForm:
935 					{
936 						if ( !pDrawFormShell )
937 						{
938 							pDocSh->MakeDrawLayer();
939 							pDrawFormShell = new ScDrawFormShell( GetViewData() );
940 							pDrawFormShell->SetRepeatTarget( &aTarget );
941 						}
942 						AddSubShell(*pDrawFormShell);
943 						bDrawBrush = sal_True;
944 					}
945 					break;
946 
947 			case	OST_Chart:
948 					{
949 						if ( !pChartShell )
950 						{
951 							pDocSh->MakeDrawLayer();
952 							pChartShell = new ScChartShell( GetViewData() );
953 							pChartShell->SetRepeatTarget( &aTarget );
954 						}
955 						AddSubShell(*pChartShell);
956 						bDrawBrush = sal_True;
957 					}
958 					break;
959 
960 			case	OST_OleObject:
961 					{
962 						if ( !pOleObjectShell )
963 						{
964 							pDocSh->MakeDrawLayer();
965 							pOleObjectShell = new ScOleObjectShell( GetViewData() );
966 							pOleObjectShell->SetRepeatTarget( &aTarget );
967 						}
968 						AddSubShell(*pOleObjectShell);
969 						bDrawBrush = sal_True;
970 					}
971 					break;
972 
973 			case	OST_Graphic:
974 					{
975 						if ( !pGraphicShell)
976 						{
977 							pDocSh->MakeDrawLayer();
978 							pGraphicShell = new ScGraphicShell( GetViewData() );
979 							pGraphicShell->SetRepeatTarget( &aTarget );
980 						}
981 						AddSubShell(*pGraphicShell);
982 						bDrawBrush = sal_True;
983 					}
984 					break;
985 
986 			case	OST_Media:
987 					{
988 						if ( !pMediaShell)
989 						{
990 							pDocSh->MakeDrawLayer();
991 							pMediaShell = new ScMediaShell( GetViewData() );
992 							pMediaShell->SetRepeatTarget( &aTarget );
993 						}
994 						AddSubShell(*pMediaShell);
995 					}
996 					break;
997 
998 			case	OST_Pivot:
999 					{
1000 						AddSubShell(*pCellShell);
1001 						if(bPgBrk) AddSubShell(*pPageBreakShell);
1002 
1003 						if ( !pPivotShell )
1004 						{
1005 							pPivotShell = new ScPivotShell( this );
1006 							pPivotShell->SetRepeatTarget( &aTarget );
1007 						}
1008 						AddSubShell(*pPivotShell);
1009                         bCellBrush = sal_True;
1010 					}
1011 					break;
1012 			case	OST_Auditing:
1013 					{
1014 						AddSubShell(*pCellShell);
1015 						if(bPgBrk) AddSubShell(*pPageBreakShell);
1016 
1017 						if ( !pAuditingShell )
1018 						{
1019 							pDocSh->MakeDrawLayer();	// die Wartezeit lieber jetzt als beim Klick
1020 
1021 							pAuditingShell = new ScAuditingShell( GetViewData() );
1022 							pAuditingShell->SetRepeatTarget( &aTarget );
1023 						}
1024 						AddSubShell(*pAuditingShell);
1025                         bCellBrush = sal_True;
1026 					}
1027 					break;
1028 			default:
1029 					DBG_ERROR("Falsche Shell angefordert");
1030 					break;
1031 		}
1032 
1033 		if (pFormShell && bFormShellAtTop)
1034 		    AddSubShell(*pFormShell);               // add on top of own subshells
1035 
1036 		eCurOST=eOST;
1037 
1038         // abort "format paint brush" when switching to an incompatible shell
1039         if ( ( GetBrushDocument() && !bCellBrush ) || ( GetDrawBrushSet() && !bDrawBrush ) )
1040             ResetBrushDocument();
1041 	}
1042 }
1043 
SetFormShellAtTop(sal_Bool bSet)1044 void ScTabViewShell::SetFormShellAtTop( sal_Bool bSet )
1045 {
1046     if ( pFormShell && !bSet )
1047         pFormShell->ForgetActiveControl();      // let the FormShell know it no longer has the focus
1048 
1049     if ( bFormShellAtTop != bSet )
1050     {
1051         bFormShellAtTop = bSet;
1052         SetCurSubShell( GetCurObjectSelectionType(), sal_True );
1053     }
1054 }
1055 
IMPL_LINK(ScTabViewShell,FormControlActivated,FmFormShell *,EMPTYARG)1056 IMPL_LINK( ScTabViewShell, FormControlActivated, FmFormShell*, EMPTYARG )
1057 {
1058     // a form control got the focus, so the form shell has to be on top
1059     SetFormShellAtTop( sal_True );
1060     return 0;
1061 }
1062 
GetCurObjectSelectionType()1063 ObjectSelectionType ScTabViewShell::GetCurObjectSelectionType()
1064 {
1065 	return eCurOST;
1066 }
1067 
1068 //	GetMySubShell / SetMySubShell: altes Verhalten simulieren,
1069 //	dass es nur eine SubShell gibt (nur innerhalb der 5 eignenen SubShells)
1070 
GetMySubShell() const1071 SfxShell* ScTabViewShell::GetMySubShell() const
1072 {
1073 	//	GetSubShell() war frueher const, und GetSubShell(sal_uInt16) sollte es auch sein...
1074 
1075 	sal_uInt16 nPos = 0;
1076 	SfxShell* pSub = ((ScTabViewShell*)this)->GetSubShell(nPos);
1077 	while (pSub)
1078 	{
1079 		if ( pSub == pDrawShell  || pSub == pDrawTextShell || pSub == pEditShell ||
1080 			 pSub == pPivotShell || pSub == pAuditingShell || pSub == pDrawFormShell ||
1081 			 pSub == pCellShell	 || pSub == pOleObjectShell|| pSub == pChartShell ||
1082 			 pSub == pGraphicShell || pSub == pMediaShell || pSub == pPageBreakShell)
1083 			return pSub;	// gefunden
1084 
1085 		pSub = ((ScTabViewShell*)this)->GetSubShell(++nPos);
1086 	}
1087 	return NULL;		// keine von meinen dabei
1088 }
1089 
1090 //UNUSED2008-05  void ScTabViewShell::SetMySubShell( SfxShell* pShell )
1091 //UNUSED2008-05  {
1092 //UNUSED2008-05      SfxShell* pOld = GetMySubShell();
1093 //UNUSED2008-05      if ( pOld != pShell )
1094 //UNUSED2008-05      {
1095 //UNUSED2008-05          if (pOld)
1096 //UNUSED2008-05              RemoveSubShell(pOld);   // alte SubShell entfernen
1097 //UNUSED2008-05          if (pShell)
1098 //UNUSED2008-05              AddSubShell(*pShell);   // neue setzen
1099 //UNUSED2008-05      }
1100 //UNUSED2008-05  }
1101 
IsDrawTextShell() const1102 sal_Bool ScTabViewShell::IsDrawTextShell() const
1103 {
1104 	return ( pDrawTextShell && ( GetMySubShell() == pDrawTextShell ) );
1105 }
1106 
IsAuditShell() const1107 sal_Bool ScTabViewShell::IsAuditShell() const
1108 {
1109 	return ( pAuditingShell && ( GetMySubShell() == pAuditingShell ) );
1110 }
1111 
SetDrawTextUndo(::svl::IUndoManager * pNewUndoMgr)1112 void ScTabViewShell::SetDrawTextUndo( ::svl::IUndoManager* pNewUndoMgr )
1113 {
1114 	// Default: Undo-Manager der DocShell
1115 	if (!pNewUndoMgr)
1116 		pNewUndoMgr = GetViewData()->GetDocShell()->GetUndoManager();
1117 
1118 	if (pDrawTextShell)
1119     {
1120 		pDrawTextShell->SetUndoManager(pNewUndoMgr);
1121         ScDocShell* pDocSh = GetViewData()->GetDocShell();
1122         if ( pNewUndoMgr == pDocSh->GetUndoManager() &&
1123              !pDocSh->GetDocument()->IsUndoEnabled() )
1124         {
1125             pNewUndoMgr->SetMaxUndoActionCount( 0 );
1126         }
1127     }
1128 	else
1129 	{
1130 		DBG_ERROR("SetDrawTextUndo ohne DrawTextShell");
1131 	}
1132 }
1133 
1134 //------------------------------------------------------------------
1135 
GetActiveViewShell()1136 ScTabViewShell* ScTabViewShell::GetActiveViewShell()
1137 {
1138 	return PTR_CAST(ScTabViewShell,Current());
1139 }
1140 
1141 //------------------------------------------------------------------
1142 
GetPrinter(sal_Bool bCreate)1143 SfxPrinter* __EXPORT ScTabViewShell::GetPrinter( sal_Bool bCreate )
1144 {
1145 	//	Drucker ist immer da (wird fuer die FontListe schon beim Starten angelegt)
1146 	return GetViewData()->GetDocShell()->GetPrinter(bCreate);
1147 }
1148 
SetPrinter(SfxPrinter * pNewPrinter,sal_uInt16 nDiffFlags,bool)1149 sal_uInt16 __EXPORT ScTabViewShell::SetPrinter( SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool )
1150 {
1151 	return GetViewData()->GetDocShell()->SetPrinter( pNewPrinter, nDiffFlags );
1152 }
1153 
CreatePrintOptionsPage(Window * pParent,const SfxItemSet & rOptions)1154 SfxTabPage* ScTabViewShell::CreatePrintOptionsPage( Window *pParent, const SfxItemSet &rOptions )
1155 {
1156 	ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1157 	DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1158 	//CHINA001 return ScTpPrintOptions::Create( pParent, rOptions );
1159 	::CreateTabPage ScTpPrintOptionsCreate = 	pFact->GetTabPageCreatorFunc( RID_SCPAGE_PRINT );
1160 	if ( ScTpPrintOptionsCreate )
1161 		return  (*ScTpPrintOptionsCreate)( pParent, rOptions);
1162 	return 0;
1163 }
1164 
StopEditShell()1165 void ScTabViewShell::StopEditShell()
1166 {
1167 	if ( pEditShell != NULL && !bDontSwitch )
1168 		SetEditShell(NULL, sal_False );
1169 }
1170 
1171 //------------------------------------------------------------------
1172 
1173 // close handler to ensure function of dialog:
1174 
IMPL_LINK(ScTabViewShell,SimpleRefClose,String *,EMPTYARG)1175 IMPL_LINK( ScTabViewShell, SimpleRefClose, String*, EMPTYARG )
1176 {
1177     SfxInPlaceClient* pClient = GetIPClient();
1178     if ( pClient && pClient->IsObjectInPlaceActive() )
1179     {
1180         // If range selection was started with an active embedded object,
1181         // switch back to original sheet (while the dialog is still open).
1182 
1183         SetTabNo( GetViewData()->GetRefTabNo() );
1184     }
1185 
1186 	ScSimpleRefDlgWrapper::SetAutoReOpen( sal_True );
1187 	return 0;
1188 }
1189 
1190 // handlers to call UNO listeners:
1191 
lcl_GetViewObj(ScTabViewShell & rShell)1192 ScTabViewObj* lcl_GetViewObj( ScTabViewShell& rShell )
1193 {
1194 	ScTabViewObj* pRet = NULL;
1195 	SfxViewFrame* pViewFrame = rShell.GetViewFrame();
1196 	if (pViewFrame)
1197 	{
1198 		SfxFrame& rFrame = pViewFrame->GetFrame();
1199 		uno::Reference<frame::XController> xController = rFrame.GetController();
1200 		if (xController.is())
1201 			pRet = ScTabViewObj::getImplementation( xController );
1202 	}
1203 	return pRet;
1204 }
1205 
IMPL_LINK(ScTabViewShell,SimpleRefDone,String *,pResult)1206 IMPL_LINK( ScTabViewShell, SimpleRefDone, String*, pResult )
1207 {
1208 	ScTabViewObj* pImpObj = lcl_GetViewObj( *this );
1209 	if ( pImpObj && pResult )
1210 		pImpObj->RangeSelDone( *pResult );
1211 	return 0;
1212 }
1213 
IMPL_LINK(ScTabViewShell,SimpleRefAborted,String *,pResult)1214 IMPL_LINK( ScTabViewShell, SimpleRefAborted, String*, pResult )
1215 {
1216 	ScTabViewObj* pImpObj = lcl_GetViewObj( *this );
1217 	if ( pImpObj && pResult )
1218 		pImpObj->RangeSelAborted( *pResult );
1219 	return 0;
1220 }
1221 
IMPL_LINK(ScTabViewShell,SimpleRefChange,String *,pResult)1222 IMPL_LINK( ScTabViewShell, SimpleRefChange, String*, pResult )
1223 {
1224 	ScTabViewObj* pImpObj = lcl_GetViewObj( *this );
1225 	if ( pImpObj && pResult )
1226 		pImpObj->RangeSelChanged( *pResult );
1227 	return 0;
1228 }
1229 
StartSimpleRefDialog(const String & rTitle,const String & rInitVal,sal_Bool bCloseOnButtonUp,sal_Bool bSingleCell,sal_Bool bMultiSelection)1230 void ScTabViewShell::StartSimpleRefDialog(
1231             const String& rTitle, const String& rInitVal,
1232             sal_Bool bCloseOnButtonUp, sal_Bool bSingleCell, sal_Bool bMultiSelection )
1233 {
1234 	SfxViewFrame* pViewFrm = GetViewFrame();
1235 
1236     if ( GetActiveViewShell() != this )
1237     {
1238         // #i18833# / #i34499# The API method can be called for a view that's not active.
1239         // Then the view has to be activated first, the same way as in Execute for SID_CURRENTDOC.
1240         // Can't use GrabFocus here, because it needs to take effect immediately.
1241 
1242 		pViewFrm->GetFrame().Appear();
1243     }
1244 
1245 	sal_uInt16 nId = ScSimpleRefDlgWrapper::GetChildWindowId();
1246 
1247 	SC_MOD()->SetRefDialog( nId, sal_True, pViewFrm );
1248 
1249 	ScSimpleRefDlgWrapper* pWnd = (ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
1250 	if (pWnd)
1251 	{
1252 		pWnd->SetCloseHdl( LINK( this, ScTabViewShell, SimpleRefClose ) );
1253 		pWnd->SetUnoLinks( LINK( this, ScTabViewShell, SimpleRefDone ),
1254 						   LINK( this, ScTabViewShell, SimpleRefAborted ),
1255 						   LINK( this, ScTabViewShell, SimpleRefChange ) );
1256 		pWnd->SetRefString( rInitVal );
1257         pWnd->SetFlags( bCloseOnButtonUp, bSingleCell, bMultiSelection );
1258 		pWnd->SetAutoReOpen( sal_False );
1259 		Window* pWin = pWnd->GetWindow();
1260 		pWin->SetText( rTitle );
1261 		pWnd->StartRefInput();
1262 	}
1263 }
1264 
StopSimpleRefDialog()1265 void ScTabViewShell::StopSimpleRefDialog()
1266 {
1267 	SfxViewFrame* pViewFrm = GetViewFrame();
1268 	sal_uInt16 nId = ScSimpleRefDlgWrapper::GetChildWindowId();
1269 
1270 	ScSimpleRefDlgWrapper* pWnd = (ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
1271 	if (pWnd)
1272 	{
1273 		Window* pWin = pWnd->GetWindow();
1274 		if (pWin && pWin->IsSystemWindow())
1275 			((SystemWindow*)pWin)->Close();		// calls abort handler
1276 	}
1277 }
1278 
1279 //------------------------------------------------------------------
1280 
TabKeyInput(const KeyEvent & rKEvt)1281 sal_Bool ScTabViewShell::TabKeyInput(const KeyEvent& rKEvt)
1282 {
1283 	ScModule* pScMod = SC_MOD();
1284 
1285 	SfxViewFrame* pThisFrame = GetViewFrame();
1286 	if ( pThisFrame->GetChildWindow( SID_OPENDLG_FUNCTION ) )
1287 		return sal_False;
1288 
1289 	KeyCode aCode   = rKEvt.GetKeyCode();
1290 	sal_Bool bShift     = aCode.IsShift();
1291 	sal_Bool bControl   = aCode.IsMod1();
1292 	sal_Bool bAlt	    = aCode.IsMod2();
1293 	sal_uInt16 nCode	= aCode.GetCode();
1294 	sal_Bool bUsed	    = sal_False;
1295 	sal_Bool bInPlace   = pScMod->IsEditMode(); 	// Editengine bekommt alles
1296 	sal_Bool bAnyEdit   = pScMod->IsInputMode();	// nur Zeichen & Backspace
1297 	sal_Bool bDraw		= IsDrawTextEdit();
1298 
1299 	HideNoteMarker();	// Notiz-Anzeige
1300 
1301     // don't do extra HideCursor/ShowCursor calls if EnterHandler will switch to a different sheet
1302     sal_Bool bOnRefSheet = ( GetViewData()->GetRefTabNo() == GetViewData()->GetTabNo() );
1303     sal_Bool bHideCursor = ( ( nCode == KEY_RETURN && bInPlace ) || nCode == KEY_TAB ) && bOnRefSheet;
1304 
1305 	if (bHideCursor)
1306 		HideAllCursors();
1307 
1308 	ScDocument* pDoc = GetViewData()->GetDocument();
1309 	if ( pDoc )
1310 		pDoc->KeyInput( rKEvt );	// TimerDelays etc.
1311 
1312 	if( bInPlace )
1313 	{
1314 		bUsed = pScMod->InputKeyEvent( rKEvt );			// Eingabe
1315 		if( !bUsed )
1316             bUsed = sal::static_int_cast<sal_Bool>(SfxViewShell::KeyInput( rKEvt ));    // accelerators
1317 	}
1318 	else if( bAnyEdit )
1319 	{
1320 		sal_Bool bIsType = sal_False;
1321 		sal_uInt16 nModi = aCode.GetModifier();
1322 		sal_uInt16 nGroup = aCode.GetGroup();
1323 
1324 		if ( nGroup == KEYGROUP_NUM || nGroup == KEYGROUP_ALPHA || nGroup == 0 )
1325 			if ( !bControl && !bAlt )
1326 				bIsType = sal_True;
1327 
1328 		if ( nGroup == KEYGROUP_MISC )
1329 			switch ( nCode )
1330 			{
1331 				case KEY_RETURN:
1332 					bIsType = bControl && !bAlt;		// Control, Shift-Control-Return
1333 					if ( !bIsType && nModi == 0 )
1334 					{
1335 						//	Will der InputHandler auch ein einfaches Return?
1336 
1337 						ScInputHandler* pHdl = pScMod->GetInputHdl(this);
1338 						bIsType = pHdl && pHdl->TakesReturn();
1339 					}
1340 					break;
1341 				case KEY_SPACE:
1342 					bIsType = !bControl && !bAlt;		// ohne Modifier oder Shift-Space
1343 					break;
1344 				case KEY_ESCAPE:
1345 				case KEY_BACKSPACE:
1346 					bIsType = (nModi == 0);	// nur ohne Modifier
1347 					break;
1348 				default:
1349 					bIsType = sal_True;
1350 			}
1351 
1352 		if( bIsType )
1353 			bUsed = pScMod->InputKeyEvent( rKEvt );		// Eingabe
1354 
1355 		if( !bUsed )
1356             bUsed = sal::static_int_cast<sal_Bool>(SfxViewShell::KeyInput( rKEvt ));    // accelerators
1357 
1358 		if ( !bUsed && !bIsType && nCode != KEY_RETURN )	// Eingabe nochmal hinterher
1359 			bUsed = pScMod->InputKeyEvent( rKEvt );
1360 	}
1361 	else
1362 	{
1363 		//	#51889# Spezialfall: Copy/Cut bei Mehrfachselektion -> Fehlermeldung
1364 		//	(Slot ist disabled, SfxViewShell::KeyInput wuerde also kommentarlos verschluckt)
1365 		KeyFuncType eFunc = aCode.GetFunction();
1366 		if ( eFunc == KEYFUNC_CUT )
1367 		{
1368 			ScRange aDummy;
1369 			ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy );
1370 			if ( eMarkType != SC_MARK_SIMPLE &&
1371                     !(eFunc == KEYFUNC_COPY && eMarkType == SC_MARK_SIMPLE_FILTERED) )
1372 			{
1373 				ErrorMessage(STR_NOMULTISELECT);
1374 				bUsed = sal_True;
1375 			}
1376 		}
1377 		if (!bUsed)
1378             bUsed = sal::static_int_cast<sal_Bool>(SfxViewShell::KeyInput( rKEvt ));    // accelerators
1379 
1380 		//	#74696# during inplace editing, some slots are handled by the
1381 		//	container app and are executed during Window::KeyInput.
1382 		//	-> don't pass keys to input handler that would be used there
1383 		//	but should call slots instead.
1384         sal_Bool bParent = ( GetViewFrame()->GetFrame().IsInPlace() && eFunc != KEYFUNC_DONTKNOW );
1385 
1386 		if( !bUsed && !bDraw && nCode != KEY_RETURN && !bParent )
1387 			bUsed = pScMod->InputKeyEvent( rKEvt, sal_True );		// Eingabe
1388 	}
1389 
1390 	if (!bInPlace && !bUsed && !bDraw)
1391 	{
1392 		switch (nCode)
1393 		{
1394 			case KEY_RETURN:
1395 				{
1396 					sal_Bool bNormal = !bControl && !bAlt;
1397 					if ( !bAnyEdit && bNormal )
1398 					{
1399 						//	je nach Optionen mit Enter in den Edit-Modus schalten
1400 
1401 						const ScInputOptions& rOpt = pScMod->GetInputOptions();
1402 						if ( rOpt.GetEnterEdit() )
1403 						{
1404 							pScMod->SetInputMode( SC_INPUT_TABLE );
1405 							bUsed = sal_True;
1406 						}
1407 					}
1408 
1409 					sal_Bool bEditReturn = bControl && !bShift; 		// An Edit-Engine weiter
1410 					if ( !bUsed && !bEditReturn )
1411 					{
1412 					    if ( bOnRefSheet )
1413     						HideAllCursors();
1414 
1415 						sal_uInt8 nMode = SC_ENTER_NORMAL;
1416 						if ( bShift && bControl )
1417 							nMode = SC_ENTER_MATRIX;
1418 						else if ( bAlt )
1419 							nMode = SC_ENTER_BLOCK;
1420 						pScMod->InputEnterHandler(nMode);
1421 
1422 						if (nMode == SC_ENTER_NORMAL)
1423 						{
1424 							if( bShift )
1425 								GetViewData()->GetDispatcher().Execute( SID_CURSORENTERUP,
1426 											SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1427 							else
1428 								GetViewData()->GetDispatcher().Execute( SID_CURSORENTERDOWN,
1429 											SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1430 						}
1431 						else
1432 							UpdateInputHandler(sal_True);
1433 
1434 					    if ( bOnRefSheet )
1435     						ShowAllCursors();
1436 
1437 						//	hier kein UpdateInputHandler, weil bei Referenzeingabe auf ein
1438 						//	anderes Dokument diese ViewShell nicht die ist, auf der eingegeben
1439 						//	wird!
1440 
1441 						bUsed = sal_True;
1442 					}
1443 				}
1444 				break;
1445 		}
1446 	}
1447 
1448 	//	Alt-Cursortasten hart codiert, weil Alt nicht konfigurierbar ist
1449 
1450 	if ( !bUsed && bAlt && !bControl )
1451 	{
1452 		sal_uInt16 nSlotId = 0;
1453 		switch (nCode)
1454 		{
1455 			case KEY_UP:
1456 				ModifyCellSize( DIR_TOP, bShift );
1457 				bUsed = sal_True;
1458 				break;
1459 			case KEY_DOWN:
1460 				ModifyCellSize( DIR_BOTTOM, bShift );
1461 				bUsed = sal_True;
1462 				break;
1463 			case KEY_LEFT:
1464 				ModifyCellSize( DIR_LEFT, bShift );
1465 				bUsed = sal_True;
1466 				break;
1467 			case KEY_RIGHT:
1468 				ModifyCellSize( DIR_RIGHT, bShift );
1469 				bUsed = sal_True;
1470 				break;
1471 			case KEY_PAGEUP:
1472 				nSlotId = bShift ? SID_CURSORPAGELEFT_SEL : SID_CURSORPAGELEFT_;
1473 				break;
1474 			case KEY_PAGEDOWN:
1475 				nSlotId = bShift ? SID_CURSORPAGERIGHT_SEL : SID_CURSORPAGERIGHT_;
1476 				break;
1477 		}
1478 		if ( nSlotId )
1479 		{
1480 			GetViewData()->GetDispatcher().Execute( nSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1481 			bUsed = sal_True;
1482 		}
1483 	}
1484 
1485 	// use Ctrl+Alt+Shift+arrow keys to move the cursor in cells
1486 	// while keeping the last selection
1487 	if ( !bUsed && bAlt && bControl && bShift)
1488 	{
1489 		sal_uInt16 nSlotId = 0;
1490 		switch (nCode)
1491 		{
1492 			case KEY_UP:
1493 				nSlotId = SID_CURSORUP;
1494 				break;
1495 			case KEY_DOWN:
1496 				nSlotId = SID_CURSORDOWN;
1497 				break;
1498 			case KEY_LEFT:
1499 				nSlotId = SID_CURSORLEFT;
1500 				break;
1501 			case KEY_RIGHT:
1502 				nSlotId = SID_CURSORRIGHT;
1503 				break;
1504 			case KEY_PAGEUP:
1505 				nSlotId = SID_CURSORPAGEUP;
1506 				break;
1507 			case KEY_PAGEDOWN:
1508 				nSlotId = SID_CURSORPAGEDOWN;
1509 				break;
1510 			case KEY_HOME:
1511 				nSlotId = SID_CURSORHOME;
1512 				break;
1513 			case KEY_END:
1514 				nSlotId = SID_CURSOREND;
1515 				break;
1516 			default:
1517 				nSlotId = 0;
1518 				break;
1519 		}
1520 		if ( nSlotId )
1521 		{
1522 			sal_uInt16 nMode = GetLockedModifiers();
1523 			LockModifiers(KEY_MOD1);
1524 			GetViewData()->GetDispatcher().Execute( nSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1525 			LockModifiers(nMode);
1526 			bUsed = sal_True;
1527 		}
1528 	}
1529 	if (bHideCursor)
1530 		ShowAllCursors();
1531 
1532 	return bUsed;
1533 }
1534 
SfxKeyInput(const KeyEvent & rKeyEvent)1535 sal_Bool ScTabViewShell::SfxKeyInput(const KeyEvent& rKeyEvent)
1536 {
1537     return sal::static_int_cast<sal_Bool>(SfxViewShell::KeyInput( rKeyEvent ));
1538 }
1539 
KeyInput(const KeyEvent & rKeyEvent)1540 FASTBOOL __EXPORT ScTabViewShell::KeyInput( const KeyEvent &rKeyEvent )
1541 {
1542 //	return SfxViewShell::KeyInput( rKeyEvent );
1543 	return TabKeyInput( rKeyEvent );
1544 }
1545 
1546 //------------------------------------------------------------------
1547 
1548 #define __INIT_ScTabViewShell \
1549 	eCurOST(OST_NONE),			\
1550 	nDrawSfxId(0),				\
1551 	nCtrlSfxId(USHRT_MAX),		\
1552 	nFormSfxId(USHRT_MAX),		\
1553 	pDrawShell(NULL),			\
1554 	pDrawTextShell(NULL),		\
1555 	pEditShell(NULL),			\
1556 	pPivotShell(NULL),			\
1557 	pAuditingShell(NULL),		\
1558 	pDrawFormShell(NULL),		\
1559 	pCellShell(NULL),			\
1560 	pOleObjectShell(NULL),		\
1561 	pChartShell(NULL),			\
1562 	pGraphicShell(NULL),		\
1563 	pMediaShell(NULL),			\
1564 	pPageBreakShell(NULL),		\
1565 	pExtrusionBarShell(NULL),	\
1566 	pFontworkBarShell(NULL),	\
1567 	pFormShell(NULL),			\
1568 	pInputHandler(NULL),		\
1569 	pCurFrameLine(NULL),		\
1570 	aTarget( this ),			\
1571 	pDialogDPObject(NULL),		\
1572     pNavSettings(NULL),         \
1573 	bActiveDrawSh(sal_False),		\
1574 	bActiveDrawTextSh(sal_False),	\
1575 	bActivePivotSh(sal_False),		\
1576 	bActiveAuditingSh(sal_False),	\
1577 	bActiveDrawFormSh(sal_False),	\
1578 	bActiveOleObjectSh(sal_False),	\
1579 	bActiveChartSh(sal_False),		\
1580 	bActiveGraphicSh(sal_False),	\
1581 	bActiveMediaSh(sal_False),		\
1582 	bActiveEditSh(sal_False),       \
1583 	bFormShellAtTop(sal_False),     \
1584 	bDontSwitch(sal_False),			\
1585 	bInFormatDialog(sal_False),		\
1586 	bPrintSelected(sal_False),		\
1587 	bReadOnly(sal_False),			\
1588 	pScSbxObject(NULL),			\
1589 	/*bChartDlgIsEdit(sal_False),*/		\
1590 	bChartAreaValid(sal_False),		\
1591     nCurRefDlgId(0),            \
1592 	pAccessibilityBroadcaster(NULL),	\
1593 	bForceFocusOnCurCell(sal_False)
1594 
1595 
1596 //------------------------------------------------------------------
1597 
Construct(sal_uInt8 nForceDesignMode)1598 void ScTabViewShell::Construct( sal_uInt8 nForceDesignMode )
1599 {
1600 	SfxApplication* pSfxApp  = SFX_APP();
1601 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
1602 	ScDocument* pDoc = pDocSh->GetDocument();
1603 
1604 	bReadOnly = pDocSh->IsReadOnly();
1605 	bIsActive = sal_False;
1606 
1607 	SetName( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("View")) );	// fuer SBX
1608 	Color aColBlack( COL_BLACK );
1609 //	SetPool( &pSfxApp->GetPool() );
1610 	SetPool( &SC_MOD()->GetPool() );
1611 	SetWindow( GetActiveWin() );
1612 
1613 	pCurFrameLine	= new SvxBorderLine( &aColBlack, 20, 0, 0 );
1614 	pPivotSource	= new ScArea;
1615     StartListening(*GetViewData()->GetDocShell(),sal_True);
1616     StartListening(*GetViewFrame(),sal_True);
1617     StartListening(*pSfxApp,sal_True);              // #i62045# #i62046# application is needed for Calc's own hints
1618 
1619 	SfxViewFrame* pFirst = SfxViewFrame::GetFirst(pDocSh);
1620 	sal_Bool bFirstView = !pFirst
1621 		  || (pFirst == GetViewFrame() && !SfxViewFrame::GetNext(*pFirst,pDocSh));
1622 
1623 	if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1624 	{
1625         //TODO/LATER: is there a difference between the two GetVisArea methods?
1626         Rectangle aVisArea = ((const SfxObjectShell*)pDocSh)->GetVisArea();
1627 
1628 		SCTAB nVisTab = pDoc->GetVisibleTab();
1629 		if (!pDoc->HasTable(nVisTab))
1630 		{
1631 			nVisTab = 0;
1632 			pDoc->SetVisibleTab(nVisTab);
1633 		}
1634 		SetTabNo( nVisTab );
1635         sal_Bool bNegativePage = pDoc->IsNegativePage( nVisTab );
1636         // show the right cells
1637         GetViewData()->SetScreenPos( bNegativePage ? aVisArea.TopRight() : aVisArea.TopLeft() );
1638 
1639         if ( GetViewFrame()->GetFrame().IsInPlace() )                         // inplace
1640 		{
1641 			pDocSh->SetInplace( sal_True );				// schon so initialisiert
1642 			if (pDoc->IsEmbedded())
1643 				pDoc->ResetEmbedded();				// keine blaue Markierung
1644 		}
1645 		else if ( bFirstView )
1646 		{
1647 			pDocSh->SetInplace( sal_False );
1648             GetViewData()->RefreshZoom();           // recalculate PPT
1649 			if (!pDoc->IsEmbedded())
1650 				pDoc->SetEmbedded( aVisArea );					// VisArea markieren
1651 		}
1652 	}
1653 
1654 	// ViewInputHandler
1655 	//	#48721# jeder Task hat neuerdings sein eigenes InputWindow,
1656 	//	darum muesste eigentlich entweder jeder Task seinen InputHandler bekommen,
1657 	//	oder das InputWindow muesste sich beim App-InputHandler anmelden, wenn der
1658 	//	Task aktiv wird, oder das InputWindow muesste sich den InputHandler selbst
1659 	//	anlegen (dann immer ueber das InputWindow suchen, und nur wenn das nicht da
1660 	//	ist, den InputHandler von der App nehmen).
1661 	//	Als Sofortloesung bekommt erstmal jede View ihren Inputhandler, das gibt
1662 	//	nur noch Probleme, wenn zwei Views in einem Task-Fenster sind.
1663 
1664 	pInputHandler = new ScInputHandler;
1665 
1666 	// Alte Version:
1667 	//	if ( !GetViewFrame()->ISA(SfxTopViewFrame) )		// OLE oder Plug-In
1668 	//		pInputHandler = new ScInputHandler;
1669 
1670 			//	FormShell vor MakeDrawView anlegen, damit die DrawView auf jeden Fall
1671 			//	an der FormShell angemeldet werden kann
1672 			//	Gepusht wird die FormShell im ersten Activate
1673 	pFormShell = new FmFormShell(this);
1674 	pFormShell->SetControlActivationHandler( LINK( this, ScTabViewShell, FormControlActivated ) );
1675 
1676 			//	DrawView darf nicht im TabView - ctor angelegt werden,
1677 			//	wenn die ViewShell noch nicht kostruiert ist...
1678 	if (pDoc->GetDrawLayer())
1679 		MakeDrawView( nForceDesignMode );
1680 	ViewOptionsHasChanged(sal_False);	// legt auch evtl. DrawView an
1681 
1682     ::svl::IUndoManager* pMgr = pDocSh->GetUndoManager();
1683     SetUndoManager( pMgr );
1684     pFormShell->SetUndoManager( pMgr );
1685     if ( !pDoc->IsUndoEnabled() )
1686     {
1687         pMgr->SetMaxUndoActionCount( 0 );
1688     }
1689 	SetRepeatTarget( &aTarget );
1690 	pFormShell->SetRepeatTarget( &aTarget );
1691 	SetHelpId( HID_SCSHELL_TABVWSH );
1692 
1693 	if ( bFirstView )	// first view?
1694 	{
1695 		pDoc->SetDocVisible( sal_True );		// used when creating new sheets
1696 		if ( pDocSh->IsEmpty() )
1697 		{
1698 			// set first sheet's RTL flag (following will already be initialized because of SetDocVisible)
1699 			pDoc->SetLayoutRTL( 0, ScGlobal::IsSystemRTL() );
1700 
1701 			// append additional sheets (not for OLE object)
1702 			if ( pDocSh->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
1703 			{
1704 				SCTAB nInitTabCount = 3;							//!	konfigurierbar !!!
1705 				for (SCTAB i=1; i<nInitTabCount; i++)
1706 					pDoc->MakeTable(i,false);
1707 			}
1708 
1709             pDocSh->SetEmpty( sal_False );          // #i6232# make sure this is done only once
1710 		}
1711 
1712 		// ReadExtOptions is now in Activate
1713 
1714 		//	Link-Update nicht verschachteln
1715 		if ( pDocSh->GetCreateMode() != SFX_CREATE_MODE_INTERNAL &&
1716              pDocSh->IsUpdateEnabled() )  // #105575#; update only in the first creation of the ViewShell
1717 		{
1718             // Check if there are any external data.
1719             bool bLink = pDoc->GetExternalRefManager()->hasExternalData();
1720             if (!bLink)
1721             {
1722                 // #i100042# sheet links can still exist independently from external formula references
1723                 SCTAB nTabCount = pDoc->GetTableCount();
1724                 for (SCTAB i=0; i<nTabCount && !bLink; i++)
1725                     if (pDoc->IsLinked(i))
1726                         bLink = true;
1727             }
1728 			if (!bLink)
1729 				if (pDoc->HasDdeLinks() || pDoc->HasAreaLinks())
1730 					bLink = sal_True;
1731 			if (bLink)
1732 			{
1733 				if ( !pFirst )
1734 					pFirst = GetViewFrame();
1735 
1736 				if(SC_MOD()->GetCurRefDlgId()==0)
1737 				{
1738 						pFirst->GetDispatcher()->Execute( SID_UPDATETABLINKS,
1739 											SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
1740 				}
1741 			}
1742 
1743 			sal_Bool bReImport = sal_False;								// importierte Daten aktualisieren
1744 			ScDBCollection* pDBColl = pDoc->GetDBCollection();
1745 			if ( pDBColl )
1746 			{
1747 				sal_uInt16 nCount = pDBColl->GetCount();
1748 				for (sal_uInt16 i=0; i<nCount && !bReImport; i++)
1749 				{
1750 					ScDBData* pData = (*pDBColl)[i];
1751 					if ( pData->IsStripData() &&
1752 							pData->HasImportParam() && !pData->HasImportSelection() )
1753 						bReImport = sal_True;
1754 				}
1755 			}
1756 			if (bReImport)
1757 			{
1758 				if ( !pFirst )
1759 					pFirst = GetViewFrame();
1760 				if(SC_MOD()->GetCurRefDlgId()==0)
1761 				{
1762 					pFirst->GetDispatcher()->Execute( SID_REIMPORT_AFTER_LOAD,
1763 											SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
1764 				}
1765 			}
1766 		}
1767 	}
1768 
1769 	UpdateAutoFillMark();
1770 
1771 	// ScDispatchProviderInterceptor registers itself in ctor
1772 	xDisProvInterceptor = new ScDispatchProviderInterceptor( this );
1773 
1774 	bFirstActivate = sal_True; // NavigatorUpdate aufschieben bis Activate()
1775 
1776     // #105575#; update only in the first creation of the ViewShell
1777     pDocSh->SetUpdateEnabled(sal_False);
1778 
1779 	if ( GetViewFrame()->GetFrame().IsInPlace() )
1780 		UpdateHeaderWidth(); // The implace activation requires headers to be calculated
1781 
1782 	SvBorder aBorder;
1783     GetBorderSize( aBorder, Size() );
1784 	SetBorderPixel( aBorder );
1785 }
1786 
1787 //------------------------------------------------------------------
1788 
1789 //UNUSED2008-05  ScTabViewShell::ScTabViewShell( SfxViewFrame* pViewFrame,
1790 //UNUSED2008-05                                  const ScTabViewShell& rWin ) :
1791 //UNUSED2008-05  SfxViewShell( pViewFrame, SFX_VIEW_MAXIMIZE_FIRST | SFX_VIEW_CAN_PRINT | SFX_VIEW_HAS_PRINTOPTIONS ),
1792 //UNUSED2008-05  ScDBFunc( &pViewFrame->GetWindow(), rWin, this ),
1793 //UNUSED2008-05  __INIT_ScTabViewShell
1794 //UNUSED2008-05  {
1795 //UNUSED2008-05      RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScTabViewShell::ScTabViewShell" );
1796 //UNUSED2008-05
1797 //UNUSED2008-05      Construct();
1798 //UNUSED2008-05
1799 //UNUSED2008-05      UpdatePageBreakData();
1800 //UNUSED2008-05
1801 //UNUSED2008-05      /*uno::Reference<frame::XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface();
1802 //UNUSED2008-05      if (xFrame.is())
1803 //UNUSED2008-05          xFrame->setComponent( uno::Reference<awt::XWindow>(), new ScTabViewObj( this ) );*/
1804 //UNUSED2008-05      // make Controller known to SFX
1805 //UNUSED2008-05      new ScTabViewObj( this );
1806 //UNUSED2008-05
1807 //UNUSED2008-05      SetCurSubShell(OST_Cell);
1808 //UNUSED2008-05      SvBorder aBorder;
1809 //UNUSED2008-05      GetBorderSize( aBorder, Size() );
1810 //UNUSED2008-05      SetBorderPixel( aBorder );
1811 //UNUSED2008-05  }
1812 
1813 //------------------------------------------------------------------
1814 
ScTabViewShell(SfxViewFrame * pViewFrame,SfxViewShell * pOldSh)1815 ScTabViewShell::ScTabViewShell( SfxViewFrame* pViewFrame,
1816 								SfxViewShell* pOldSh ) :
1817     SfxViewShell( pViewFrame, SFX_VIEW_CAN_PRINT | SFX_VIEW_HAS_PRINTOPTIONS ),
1818     ScDBFunc( &pViewFrame->GetWindow(), (ScDocShell&)*pViewFrame->GetObjectShell(), this ),
1819     __INIT_ScTabViewShell
1820 {
1821 	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScTabViewShell::ScTabViewShell" );
1822 
1823 	const ScAppOptions&	rAppOpt = SC_MOD()->GetAppOptions();
1824 
1825 	//	if switching back from print preview,
1826 	//	restore the view settings that were active when creating the preview
1827 	//	#89897# ReadUserData must not happen from ctor, because the view's edit window
1828 	//	has to be shown by the sfx. ReadUserData is deferred until the first Activate call.
1829 	//	#106334# old DesignMode state from form layer must be restored, too
1830 
1831 	sal_uInt8 nForceDesignMode = SC_FORCEMODE_NONE;
1832 	if ( pOldSh && pOldSh->ISA( ScPreviewShell ) )
1833 	{
1834 		ScPreviewShell* pPreviewShell = ((ScPreviewShell*)pOldSh);
1835 		nForceDesignMode = pPreviewShell->GetSourceDesignMode();
1836 	}
1837 
1838 	Construct( nForceDesignMode );
1839 
1840 	if ( GetViewData()->GetDocShell()->IsPreview() )
1841 	{
1842 		//	preview for template dialog: always show whole page
1843         SetZoomType( SVX_ZOOM_WHOLEPAGE, sal_True );    // zoom value is recalculated at next Resize
1844 	}
1845 	else
1846 	{
1847 		Fraction aFract( rAppOpt.GetZoom(), 100 );
1848         SetZoom( aFract, aFract, sal_True );
1849         SetZoomType( rAppOpt.GetZoomType(), sal_True );
1850 	}
1851 
1852     /*uno::Reference<frame::XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface();
1853 	if (xFrame.is())
1854         xFrame->setComponent( uno::Reference<awt::XWindow>(), new ScTabViewObj( this ) );*/
1855     // make Controller known to SFX
1856     new ScTabViewObj( this );
1857 
1858 	SetCurSubShell(OST_Cell);
1859 	SvBorder aBorder;
1860     GetBorderSize( aBorder, Size() );
1861 	SetBorderPixel( aBorder );
1862 
1863 	// #114409#
1864 	MakeDrawLayer();
1865 }
1866 
1867 #undef __INIT_ScTabViewShell
1868 
1869 //------------------------------------------------------------------
1870 
1871 __EXPORT ScTabViewShell::~ScTabViewShell()
1872 {
1873 	ScDocShell* pDocSh = GetViewData()->GetDocShell();
1874 	EndListening(*pDocSh);
1875 	EndListening(*GetViewFrame());
1876     EndListening(*SFX_APP());           // #i62045# #i62046# needed now - SfxViewShell no longer does it
1877 
1878 	SC_MOD()->ViewShellGone(this);
1879 
1880 	RemoveSubShell();			// alle
1881 	SetWindow(0);
1882 
1883 	//	#54104# alles auf NULL, falls aus dem TabView-dtor noch darauf zugegriffen wird
1884 	//!	(soll eigentlich nicht !??!?!)
1885 
1886 	DELETEZ(pFontworkBarShell);
1887 	DELETEZ(pExtrusionBarShell);
1888 	DELETEZ(pCellShell);
1889 	DELETEZ(pPageBreakShell);
1890 	DELETEZ(pDrawShell);
1891 	DELETEZ(pDrawFormShell);
1892 	DELETEZ(pOleObjectShell);
1893 	DELETEZ(pChartShell);
1894 	DELETEZ(pGraphicShell);
1895 	DELETEZ(pMediaShell);
1896 	DELETEZ(pDrawTextShell);
1897 	DELETEZ(pEditShell);
1898 	DELETEZ(pPivotShell);
1899 	DELETEZ(pAuditingShell);
1900 	DELETEZ(pCurFrameLine);
1901 	DELETEZ(pInputHandler);
1902 	DELETEZ(pPivotSource);
1903 	DELETEZ(pDialogDPObject);
1904     DELETEZ(pNavSettings);
1905 
1906 	DELETEZ(pFormShell);
1907 	DELETEZ(pAccessibilityBroadcaster);
1908 }
1909 
1910 //------------------------------------------------------------------
1911 
SetDialogDPObject(const ScDPObject * pObj)1912 void ScTabViewShell::SetDialogDPObject( const ScDPObject* pObj )
1913 {
1914 	delete pDialogDPObject;
1915 	if (pObj)
1916 		pDialogDPObject = new ScDPObject( *pObj );
1917 	else
1918 		pDialogDPObject = NULL;
1919 }
1920 
1921 //------------------------------------------------------------------
1922 
FillFieldData(ScHeaderFieldData & rData)1923 void ScTabViewShell::FillFieldData( ScHeaderFieldData& rData )
1924 {
1925 	ScDocShell* pDocShell = GetViewData()->GetDocShell();
1926 	ScDocument* pDoc = pDocShell->GetDocument();
1927 	SCTAB nTab = GetViewData()->GetTabNo();
1928 	pDoc->GetName( nTab, rData.aTabName );
1929 
1930 	rData.aTitle		= pDocShell->GetTitle();
1931 	const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject();
1932 	rData.aLongDocName	= rURLObj.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
1933 	if ( rData.aLongDocName.Len() )
1934 		rData.aShortDocName = rURLObj.GetName( INetURLObject::DECODE_UNAMBIGUOUS );
1935 	else
1936 		rData.aShortDocName = rData.aLongDocName = rData.aTitle;
1937 	rData.nPageNo		= 1;
1938 	rData.nTotalPages	= 99;
1939 
1940 	//	eNumType kennt der Dialog selber
1941 }
1942 
1943 //------------------------------------------------------------------
1944 
SetChartArea(const ScRangeListRef & rSource,const Rectangle & rDest)1945 void ScTabViewShell::SetChartArea( const ScRangeListRef& rSource, const Rectangle& rDest )
1946 {
1947 	bChartAreaValid	= sal_True;
1948 	aChartSource	= rSource;
1949 	aChartPos		= rDest;
1950 	nChartDestTab	= GetViewData()->GetTabNo();
1951 }
1952 
1953 //UNUSED2008-05  void ScTabViewShell::ResetChartArea()
1954 //UNUSED2008-05  {
1955 //UNUSED2008-05      bChartAreaValid = sal_False;
1956 //UNUSED2008-05  }
1957 
GetChartArea(ScRangeListRef & rSource,Rectangle & rDest,SCTAB & rTab) const1958 sal_Bool ScTabViewShell::GetChartArea( ScRangeListRef& rSource, Rectangle& rDest, SCTAB& rTab ) const
1959 {
1960 	rSource	= aChartSource;
1961 	rDest	= aChartPos;
1962 	rTab	= nChartDestTab;
1963 	return bChartAreaValid;
1964 }
1965 
1966 //UNUSED2008-05  sal_Bool ScTabViewShell::IsChartDlgEdit() const
1967 //UNUSED2008-05  {
1968 //UNUSED2008-05      return bChartDlgIsEdit;
1969 //UNUSED2008-05  }
1970 //UNUSED2008-05
1971 //UNUSED2008-05  const String& ScTabViewShell::GetEditChartName() const
1972 //UNUSED2008-05  {
1973 //UNUSED2008-05      return aEditChartName;
1974 //UNUSED2008-05  }
1975 
GetNavigatorSettings()1976 ScNavigatorSettings* ScTabViewShell::GetNavigatorSettings()
1977 {
1978     if( !pNavSettings )
1979         pNavSettings = new ScNavigatorSettings;
1980     return pNavSettings;
1981 }
1982 
1983 
1984 //------------------------------------------------------------------
1985 
ExecTbx(SfxRequest & rReq)1986 void ScTabViewShell::ExecTbx( SfxRequest& rReq )
1987 {
1988 	const SfxItemSet* pReqArgs = rReq.GetArgs();
1989 	sal_uInt16 nSlot = rReq.GetSlot();
1990 	const SfxPoolItem* pItem = NULL;
1991 	if ( pReqArgs )
1992 		pReqArgs->GetItemState( nSlot, sal_True, &pItem );
1993 
1994 	switch ( nSlot )
1995 	{
1996 		case SID_TBXCTL_INSERT:
1997 			if ( pItem )
1998 				nInsertCtrlState = ((const SfxUInt16Item*)pItem)->GetValue();
1999 			break;
2000 		case SID_TBXCTL_INSCELLS:
2001 			if ( pItem )
2002 				nInsCellsCtrlState = ((const SfxUInt16Item*)pItem)->GetValue();
2003 			break;
2004 		case SID_TBXCTL_INSOBJ:
2005 			if ( pItem )
2006 				nInsObjCtrlState = ((const SfxUInt16Item*)pItem)->GetValue();
2007 			break;
2008 		default:
2009 			DBG_ERROR("Slot im Wald");
2010 	}
2011 	GetViewFrame()->GetBindings().Invalidate( nSlot );
2012 }
2013 
GetTbxState(SfxItemSet & rSet)2014 void ScTabViewShell::GetTbxState( SfxItemSet& rSet )
2015 {
2016 	rSet.Put( SfxUInt16Item( SID_TBXCTL_INSERT,   nInsertCtrlState ) );
2017 	rSet.Put( SfxUInt16Item( SID_TBXCTL_INSCELLS, nInsCellsCtrlState ) );
2018 
2019 	//	ohne installiertes Chart darf Chart nicht Default sein...
2020 	if ( nInsObjCtrlState == SID_DRAW_CHART && !SvtModuleOptions().IsChart() )
2021 		nInsObjCtrlState = SID_INSERT_OBJECT;
2022 
2023 	rSet.Put( SfxUInt16Item( SID_TBXCTL_INSOBJ,   nInsObjCtrlState ) );
2024 }
2025 
2026 
2027 
2028 
2029 
GetForms() const2030 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & ScTabViewShell::GetForms() const
2031 {
2032 	if( !pFormShell || !pFormShell->GetCurPage() ){
2033 		static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > aRef;
2034 		return aRef;
2035 	}
2036 	return pFormShell->GetCurPage()->GetForms();
2037 }
2038