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