Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / view / tabvwsh4.cxx
blob799f95322a1c017c6764fe0a63945d3d789539e0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "scitems.hxx"
21 #include <editeng/eeitem.hxx>
23 #include <sfx2/app.hxx>
24 #include <svx/extrusionbar.hxx>
25 #include <svx/fontworkbar.hxx>
26 #include <editeng/boxitem.hxx>
27 #include <svx/fmshell.hxx>
28 #include <editeng/sizeitem.hxx>
29 #include <svx/prtqry.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/printer.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <svl/whiter.hxx>
34 #include <unotools/moduleoptions.hxx>
35 #include <rtl/logfile.hxx>
36 #include <tools/urlobj.hxx>
37 #include <sfx2/docfile.hxx>
39 #include "tabvwsh.hxx"
40 #include "sc.hrc"
41 #include "globstr.hrc"
42 #include "stlpool.hxx"
43 #include "stlsheet.hxx"
44 #include "docsh.hxx"
45 #include "scmod.hxx"
46 #include "appoptio.hxx"
47 #include "rangeutl.hxx"
48 #include "printfun.hxx"
49 #include "drawsh.hxx"
50 #include "drformsh.hxx"
51 #include "editsh.hxx"
52 #include "pivotsh.hxx"
53 #include "auditsh.hxx"
54 #include "drtxtob.hxx"
55 #include "inputhdl.hxx"
56 #include "editutil.hxx"
57 #include "inputopt.hxx"
58 #include "inputwin.hxx"
59 #include "scresid.hxx"
60 #include "dbdata.hxx" // fuer ReImport
61 #include "reffact.hxx"
62 #include "viewuno.hxx"
63 #include "dispuno.hxx"
64 #include "anyrefdg.hxx"
65 #include "chgtrack.hxx"
66 #include "cellsh.hxx"
67 #include "oleobjsh.hxx"
68 #include "chartsh.hxx"
69 #include "graphsh.hxx"
70 #include "mediash.hxx"
71 #include "pgbrksh.hxx"
72 #include "dpobject.hxx"
73 #include "prevwsh.hxx"
74 #include "tpprint.hxx"
75 #include "scextopt.hxx"
76 #include "printopt.hxx"
77 #include "drawview.hxx"
78 #include "fupoor.hxx"
79 #include "navsett.hxx"
80 #include "scabstdlg.hxx"
81 #include "externalrefmgr.hxx"
82 #include "defaultsoptions.hxx"
83 #include "markdata.hxx"
84 #include "preview.hxx"
86 #include <com/sun/star/document/XDocumentProperties.hpp>
88 void ActivateOlk( ScViewData* pViewData );
89 void DeActivateOlk( ScViewData* pViewData );
91 extern SfxViewShell* pScActiveViewShell; // global.cxx
93 using namespace com::sun::star;
95 // STATIC DATA -----------------------------------------------------------
97 sal_uInt16 ScTabViewShell::nInsertCtrlState = SID_INSERT_GRAPHIC;
98 sal_uInt16 ScTabViewShell::nInsCellsCtrlState = 0;
99 sal_uInt16 ScTabViewShell::nInsObjCtrlState = SID_INSERT_DIAGRAM;
101 // -----------------------------------------------------------------------
103 void ScTabViewShell::Activate(sal_Bool bMDI)
105 SfxViewShell::Activate(bMDI);
107 // hier kein GrabFocus, sonst gibt's Probleme wenn etwas inplace editiert wird!
109 if ( bMDI )
111 // fuer Eingabezeile (ClearCache)
112 ScModule* pScMod = SC_MOD();
113 pScMod->ViewShellChanged();
115 ActivateView( sal_True, bFirstActivate );
116 ActivateOlk( GetViewData() );
118 // AutoCorrect umsetzen, falls der Writer seins neu angelegt hat
119 UpdateDrawTextOutliner();
121 // RegisterNewTargetNames gibts nicht mehr
123 SfxViewFrame* pThisFrame = GetViewFrame();
124 if ( pInputHandler && pThisFrame->HasChildWindow(FID_INPUTLINE_STATUS) )
126 // eigentlich nur beim Reload (letzte Version) noetig:
127 // Das InputWindow bleibt stehen, aber die View mitsamt InputHandler wird
128 // neu angelegt, darum muss der InputHandler am InputWindow gesetzt werden.
129 SfxChildWindow* pChild = pThisFrame->GetChildWindow(FID_INPUTLINE_STATUS);
130 if (pChild)
132 ScInputWindow* pWin = (ScInputWindow*)pChild->GetWindow();
133 if (pWin && pWin->IsVisible())
136 ScInputHandler* pOldHdl=pWin->GetInputHandler();
138 TypeId aScType = TYPE(ScTabViewShell);
140 SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
141 while ( pSh!=NULL && pOldHdl!=NULL)
143 if (((ScTabViewShell*)pSh)->GetInputHandler() == pOldHdl)
145 pOldHdl->ResetDelayTimer();
146 break;
148 pSh = SfxViewShell::GetNext( *pSh, &aScType );
151 pWin->SetInputHandler( pInputHandler );
156 UpdateInputHandler( sal_True );
158 if ( bFirstActivate )
160 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_NAVIGATOR_UPDATEALL ) );
161 bFirstActivate = false;
163 // ReadExtOptions (view settings from Excel import) must also be done
164 // after the ctor, because of the potential calls to Window::Show.
165 // Even after a bugfix (Window::Show no longer notifies the access
166 // bridge, it's done in ImplSetReallyVisible), there are problems if Window::Show
167 // is called during the ViewShell ctor and reschedules asynchronous calls
168 // (for example from the FmFormShell ctor).
169 ScExtDocOptions* pExtOpt = GetViewData()->GetDocument()->GetExtDocOptions();
170 if ( pExtOpt && pExtOpt->IsChanged() )
172 GetViewData()->ReadExtOptions(*pExtOpt); // Excel view settings
173 SetTabNo( GetViewData()->GetTabNo(), sal_True );
174 pExtOpt->SetChanged( false );
178 pScActiveViewShell = this;
180 ScInputHandler* pHdl = pScMod->GetInputHdl(this);
181 if (pHdl)
183 pHdl->SetRefScale( GetViewData()->GetZoomX(), GetViewData()->GetZoomY() );
186 // Aenderungs-Dialog aktualisieren
188 if ( pThisFrame->HasChildWindow(FID_CHG_ACCEPT) )
190 SfxChildWindow* pChild = pThisFrame->GetChildWindow(FID_CHG_ACCEPT);
191 if (pChild)
193 ((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg();
197 if(pScMod->IsRefDialogOpen())
199 sal_uInt16 nModRefDlgId=pScMod->GetCurRefDlgId();
200 SfxChildWindow* pChildWnd = pThisFrame->GetChildWindow( nModRefDlgId );
201 if ( pChildWnd )
203 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
204 pRefDlg->ViewShellChanged();
209 // don't call CheckSelectionTransfer here - activating a view should not change the
210 // primary selection (may be happening just because the mouse was moved over the window)
212 // Wenn Referenzeingabe-Tip-Hilfe hier wieder angezeigt werden soll (ShowRefTip),
213 // muss sie beim Verschieben der View angepasst werden (gibt sonst Probleme unter OS/2
214 // beim Umschalten zwischen Dokumenten)
217 void ScTabViewShell::Deactivate(sal_Bool bMDI)
219 HideTip();
221 ScDocument* pDoc=GetViewData()->GetDocument();
223 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
225 if(pChanges!=NULL)
227 Link aLink;
228 pChanges->SetModifiedLink(aLink);
231 SfxViewShell::Deactivate(bMDI);
233 ScInputHandler* pHdl = SC_MOD()->GetInputHdl(this);
235 if( bMDI )
237 // during shell deactivation, shells must not be switched, or the loop
238 // through the shell stack (in SfxDispatcher::DoDeactivate_Impl) will not work
239 sal_Bool bOldDontSwitch = bDontSwitch;
240 bDontSwitch = sal_True;
242 DeActivateOlk( GetViewData() );
243 ActivateView( false, false );
245 if ( GetViewFrame()->GetFrame().IsInPlace() ) // inplace
246 GetViewData()->GetDocShell()->UpdateOle(GetViewData(),sal_True);
248 if ( pHdl )
249 pHdl->NotifyChange( NULL, sal_True ); // Timer-verzoegert wg. Dokumentwechsel
251 if (pScActiveViewShell == this)
252 pScActiveViewShell = NULL;
254 bDontSwitch = bOldDontSwitch;
256 else
258 HideNoteMarker(); // Notiz-Anzeige
260 if ( pHdl )
261 pHdl->HideTip(); // Formel-AutoEingabe-Tip abschalten
265 void ScTabViewShell::SetActive()
267 // Die Sfx-View moechte sich gerne selbst aktivieren, weil dabei noch
268 // magische Dinge geschehen (z.B. stuerzt sonst evtl. der Gestalter ab)
269 ActiveGrabFocus();
272 sal_uInt16 ScTabViewShell::PrepareClose(sal_Bool bUI, sal_Bool bForBrowsing)
274 // Call EnterHandler even in formula mode here,
275 // so a formula change in an embedded object isn't lost
276 // (ScDocShell::PrepareClose isn't called then).
277 ScInputHandler* pHdl = SC_MOD()->GetInputHdl( this );
278 if ( pHdl && pHdl->IsInputMode() )
279 pHdl->EnterHandler();
281 // draw text edit mode must be closed
282 FuPoor* pPoor = GetDrawFuncPtr();
283 if ( pPoor && ( IsDrawTextShell() || pPoor->GetSlotID() == SID_DRAW_NOTEEDIT ) )
285 // "clean" end of text edit, including note handling, subshells and draw func switching,
286 // as in FuDraw and ScTabView::DrawDeselectAll
287 GetViewData()->GetDispatcher().Execute( pPoor->GetSlotID(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
289 ScDrawView* pDrView = GetScDrawView();
290 if ( pDrView )
292 // force end of text edit, to be safe
293 // ScEndTextEdit must always be used, to ensure correct UndoManager
294 pDrView->ScEndTextEdit();
297 if ( pFormShell )
299 sal_uInt16 nRet = pFormShell->PrepareClose(bUI, bForBrowsing);
300 if (nRet!=sal_True)
301 return nRet;
303 return SfxViewShell::PrepareClose(bUI,bForBrowsing);
306 //------------------------------------------------------------------
308 Size ScTabViewShell::GetOptimalSizePixel() const
310 Size aOptSize;
312 SCTAB nCurTab = GetViewData()->GetTabNo();
313 ScDocument* pDoc = GetViewData()->GetDocument();
314 ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
315 SfxStyleSheetBase* pStyleSheet = pStylePool->Find(
316 pDoc->GetPageStyle( nCurTab ),
317 SFX_STYLE_FAMILY_PAGE );
319 OSL_ENSURE( pStyleSheet, "PageStyle not found :-/" );
321 if ( pStyleSheet )
323 const SfxItemSet& rSet = pStyleSheet->GetItemSet();
324 const SvxSizeItem& rItem = (const SvxSizeItem&)rSet.Get( ATTR_PAGE_SIZE );
325 const Size& rPageSize = rItem.GetSize();
327 aOptSize.Width() = (long) (rPageSize.Width() * GetViewData()->GetPPTX());
328 aOptSize.Height() = (long) (rPageSize.Height() * GetViewData()->GetPPTY());
331 return aOptSize;
334 //------------------------------------------------------------------
336 // Zoom fuer In-Place berechnen
337 // aus Verhaeltnis von VisArea und Fenstergroesse des GridWin
339 void ScTabViewShell::UpdateOleZoom()
341 ScDocShell* pDocSh = GetViewData()->GetDocShell();
342 if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
344 //TODO/LATER: is there a difference between the two GetVisArea methods?
345 Size aObjSize = ((const SfxObjectShell*)pDocSh)->GetVisArea().GetSize();
346 if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
348 Window* pWin = GetActiveWin();
349 Size aWinHMM = pWin->PixelToLogic( pWin->GetOutputSizePixel(), MAP_100TH_MM );
350 SetZoomFactor( Fraction( aWinHMM.Width(),aObjSize.Width() ),
351 Fraction( aWinHMM.Height(),aObjSize.Height() ) );
356 void ScTabViewShell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
358 OuterResizePixel( rPos, rSize );
361 void ScTabViewShell::InnerResizePixel( const Point &rOfs, const Size &rSize )
363 Size aNewSize( rSize );
364 if ( GetViewFrame()->GetFrame().IsInPlace() )
366 SvBorder aBorder;
367 GetBorderSize( aBorder, rSize );
368 SetBorderPixel( aBorder );
370 Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
372 Size aSize( rSize );
373 aSize.Width() -= (aBorder.Left() + aBorder.Right());
374 aSize.Height() -= (aBorder.Top() + aBorder.Bottom());
376 if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
378 Size aLogicSize = GetWindow()->PixelToLogic( aSize, MAP_100TH_MM );
379 SfxViewShell::SetZoomFactor( Fraction( aLogicSize.Width(),aObjSize.Width() ),
380 Fraction( aLogicSize.Height(),aObjSize.Height() ) );
383 Point aPos( rOfs );
384 aPos.X() += aBorder.Left();
385 aPos.Y() += aBorder.Top();
386 GetWindow()->SetPosSizePixel( aPos, aSize );
388 else
390 SvBorder aBorder;
391 GetBorderSize( aBorder, rSize );
392 SetBorderPixel( aBorder );
393 aNewSize.Width() += aBorder.Left() + aBorder.Right();
394 aNewSize.Height() += aBorder.Top() + aBorder.Bottom();
397 DoResize( rOfs, aNewSize, sal_True ); // rSize = Groesse von gridwin
399 UpdateOleZoom(); // Zoom fuer In-Place berechnen
401 GetViewData()->GetDocShell()->SetDocumentModified();
404 void ScTabViewShell::OuterResizePixel( const Point &rOfs, const Size &rSize )
406 SvBorder aBorder;
407 GetBorderSize( aBorder, rSize );
408 SetBorderPixel( aBorder );
410 DoResize( rOfs, rSize ); // Position und Groesse von tabview wie uebergeben
412 // ForceMove als Ersatz fuer den Sfx-Move-Mechanismus
413 // (aWinPos muss aktuell gehalten werden, damit ForceMove beim Ole-Deaktivieren klappt)
415 ForceMove();
418 void ScTabViewShell::SetZoomFactor( const Fraction &rZoomX, const Fraction &rZoomY )
420 // fuer OLE...
422 Fraction aFrac20( 1,5 );
423 Fraction aFrac400( 4,1 );
425 Fraction aNewX( rZoomX );
426 if ( aNewX < aFrac20 )
427 aNewX = aFrac20;
428 if ( aNewX > aFrac400 )
429 aNewX = aFrac400;
430 Fraction aNewY( rZoomY );
431 if ( aNewY < aFrac20 )
432 aNewY = aFrac20;
433 if ( aNewY > aFrac400 )
434 aNewY = aFrac400;
436 GetViewData()->UpdateScreenZoom( aNewX, aNewY );
437 SetZoom( aNewX, aNewY, sal_True );
439 PaintGrid();
440 PaintTop();
441 PaintLeft();
443 SfxViewShell::SetZoomFactor( rZoomX, rZoomY );
446 void ScTabViewShell::QueryObjAreaPixel( Rectangle& rRect ) const
448 // auf ganze Zellen anpassen (in 1/100 mm)
450 Size aPixelSize = rRect.GetSize();
451 Window* pWin = ((ScTabViewShell*)this)->GetActiveWin();
452 Size aLogicSize = pWin->PixelToLogic( aPixelSize );
454 const ScViewData* pViewData = GetViewData();
455 ScDocument* pDoc = pViewData->GetDocument();
456 ScSplitPos ePos = pViewData->GetActivePart();
457 SCCOL nCol = pViewData->GetPosX(WhichH(ePos));
458 SCROW nRow = pViewData->GetPosY(WhichV(ePos));
459 SCTAB nTab = pViewData->GetTabNo();
460 sal_Bool bNegativePage = pDoc->IsNegativePage( nTab );
462 Rectangle aLogicRect = pDoc->GetMMRect( nCol, nRow, nCol, nRow, nTab );
463 if ( bNegativePage )
465 // use right edge of aLogicRect, and aLogicSize
466 aLogicRect.Left() = aLogicRect.Right() - aLogicSize.Width() + 1; // Right() is set below
468 aLogicRect.SetSize( aLogicSize );
470 pDoc->SnapVisArea( aLogicRect );
472 rRect.SetSize( pWin->LogicToPixel( aLogicRect.GetSize() ) );
475 //------------------------------------------------------------------
477 void ScTabViewShell::Move()
479 Point aNewPos = GetViewFrame()->GetWindow().OutputToScreenPixel(Point());
481 if (aNewPos != aWinPos)
483 StopMarking();
484 aWinPos = aNewPos;
488 //------------------------------------------------------------------
490 void ScTabViewShell::ShowCursor(bool /* bOn */)
492 /*!!! ShowCursor wird nicht paarweise wie im gridwin gerufen.
493 Der CursorLockCount am Gridwin muss hier direkt auf 0 gesetzt werden
495 if (bOn)
496 ShowAllCursors();
497 else
498 HideAllCursors();
502 //------------------------------------------------------------------
504 void ScTabViewShell::WriteUserData(String& rData, sal_Bool /* bBrowse */)
506 GetViewData()->WriteUserData(rData);
509 void ScTabViewShell::WriteUserDataSequence (uno::Sequence < beans::PropertyValue >& rSettings, sal_Bool /* bBrowse */ )
511 GetViewData()->WriteUserDataSequence (rSettings);
514 void ScTabViewShell::ReadUserData(const String& rData, sal_Bool /* bBrowse */)
516 if ( !GetViewData()->GetDocShell()->IsPreview() )
517 DoReadUserData( rData );
520 void ScTabViewShell::ReadUserDataSequence (const uno::Sequence < beans::PropertyValue >& rSettings, sal_Bool /* bBrowse */ )
522 if ( !GetViewData()->GetDocShell()->IsPreview() )
523 DoReadUserDataSequence( rSettings );
526 void ScTabViewShell::DoReadUserDataSequence( const uno::Sequence < beans::PropertyValue >& rSettings )
528 Window* pOldWin = GetActiveWin();
529 sal_Bool bFocus = pOldWin && pOldWin->HasFocus();
531 GetViewData()->ReadUserDataSequence(rSettings);
532 SetTabNo( GetViewData()->GetTabNo(), sal_True );
534 if ( GetViewData()->IsPagebreakMode() )
535 SetCurSubShell( GetCurObjectSelectionType(), sal_True );
537 Window* pNewWin = GetActiveWin();
538 if (pNewWin && pNewWin != pOldWin)
540 SetWindow( pNewWin ); //! ist diese ViewShell immer aktiv???
541 if (bFocus)
542 pNewWin->GrabFocus();
543 WindowChanged(); // Drawing-Layer (z.B. #56771#)
546 if (GetViewData()->GetHSplitMode() == SC_SPLIT_FIX ||
547 GetViewData()->GetVSplitMode() == SC_SPLIT_FIX)
549 InvalidateSplit();
552 ZoomChanged();
554 TestHintWindow();
556 //! if ViewData has more tables than document, remove tables in ViewData
559 // DoReadUserData is also called from ctor when switching from print preview
561 void ScTabViewShell::DoReadUserData( const String& rData )
563 Window* pOldWin = GetActiveWin();
564 sal_Bool bFocus = pOldWin && pOldWin->HasFocus();
566 GetViewData()->ReadUserData(rData);
567 SetTabNo( GetViewData()->GetTabNo(), sal_True );
569 if ( GetViewData()->IsPagebreakMode() )
570 SetCurSubShell( GetCurObjectSelectionType(), sal_True );
572 Window* pNewWin = GetActiveWin();
573 if (pNewWin && pNewWin != pOldWin)
575 SetWindow( pNewWin ); //! ist diese ViewShell immer aktiv???
576 if (bFocus)
577 pNewWin->GrabFocus();
578 WindowChanged(); // Drawing-Layer (z.B. #56771#)
581 if (GetViewData()->GetHSplitMode() == SC_SPLIT_FIX ||
582 GetViewData()->GetVSplitMode() == SC_SPLIT_FIX)
584 InvalidateSplit();
587 ZoomChanged();
589 TestHintWindow();
591 //! if ViewData has more tables than document, remove tables in ViewData
594 //------------------------------------------------------------------
596 void ScTabViewShell::UpdateDrawShell()
598 // Called after user interaction that may delete the selected drawing object.
599 // Remove DrawShell if nothing is selected.
601 SdrView* pDrView = GetSdrView();
602 if ( pDrView && !pDrView->AreObjectsMarked() && !IsDrawSelMode() )
603 SetDrawShell( false );
606 void ScTabViewShell::SetDrawShellOrSub()
608 bActiveDrawSh = sal_True;
610 if(bActiveDrawFormSh)
612 SetCurSubShell(OST_DrawForm);
614 else if(bActiveGraphicSh)
616 SetCurSubShell(OST_Graphic);
618 else if(bActiveMediaSh)
620 SetCurSubShell(OST_Media);
622 else if(bActiveChartSh)
624 SetCurSubShell(OST_Chart);
626 else if(bActiveOleObjectSh)
628 SetCurSubShell(OST_OleObject);
630 else
632 SetCurSubShell(OST_Drawing, true /* force: different toolbars are
633 visible concerning shape type
634 and shape state */);
638 void ScTabViewShell::SetDrawShell( sal_Bool bActive )
640 if(bActive)
642 SetCurSubShell(OST_Drawing, true /* force: different toolbars are
643 visible concerning shape type
644 and shape state */);
646 else
648 if(bActiveDrawFormSh || bActiveDrawSh ||
649 bActiveGraphicSh || bActiveMediaSh || bActiveOleObjectSh||
650 bActiveChartSh || bActiveDrawTextSh)
652 SetCurSubShell(OST_Cell);
654 bActiveDrawFormSh=false;
655 bActiveGraphicSh=false;
656 bActiveMediaSh=false;
657 bActiveOleObjectSh=false;
658 bActiveChartSh=false;
661 sal_Bool bWasDraw = bActiveDrawSh || bActiveDrawTextSh;
663 bActiveDrawSh = bActive;
664 bActiveDrawTextSh = false;
666 if ( !bActive )
668 ResetDrawDragMode(); // Mirror / Rotate aus
670 if (bWasDraw && (GetViewData()->GetHSplitMode() == SC_SPLIT_FIX ||
671 GetViewData()->GetVSplitMode() == SC_SPLIT_FIX))
673 // Aktiven Teil an Cursor anpassen, etc.
674 MoveCursorAbs( GetViewData()->GetCurX(), GetViewData()->GetCurY(),
675 SC_FOLLOW_NONE, false, false, sal_True );
680 void ScTabViewShell::SetDrawTextShell( sal_Bool bActive )
682 bActiveDrawTextSh = bActive;
683 if ( bActive )
685 bActiveDrawFormSh=false;
686 bActiveGraphicSh=false;
687 bActiveMediaSh=false;
688 bActiveOleObjectSh=false;
689 bActiveChartSh=false;
690 bActiveDrawSh = false;
691 SetCurSubShell(OST_DrawText);
693 else
694 SetCurSubShell(OST_Cell);
698 void ScTabViewShell::SetPivotShell( sal_Bool bActive )
700 bActivePivotSh = bActive;
702 // SetPivotShell is called from CursorPosChanged every time
703 // -> don't change anything except switching between cell and pivot shell
705 if ( eCurOST == OST_Pivot || eCurOST == OST_Cell )
707 if ( bActive )
709 bActiveDrawTextSh = bActiveDrawSh = false;
710 bActiveDrawFormSh=false;
711 bActiveGraphicSh=false;
712 bActiveMediaSh=false;
713 bActiveOleObjectSh=false;
714 bActiveChartSh=false;
715 SetCurSubShell(OST_Pivot);
717 else
718 SetCurSubShell(OST_Cell);
722 void ScTabViewShell::SetAuditShell( sal_Bool bActive )
724 bActiveAuditingSh = bActive;
725 if ( bActive )
727 bActiveDrawTextSh = bActiveDrawSh = false;
728 bActiveDrawFormSh=false;
729 bActiveGraphicSh=false;
730 bActiveMediaSh=false;
731 bActiveOleObjectSh=false;
732 bActiveChartSh=false;
733 SetCurSubShell(OST_Auditing);
735 else
736 SetCurSubShell(OST_Cell);
739 void ScTabViewShell::SetDrawFormShell( sal_Bool bActive )
741 bActiveDrawFormSh = bActive;
743 if(bActiveDrawFormSh)
744 SetCurSubShell(OST_DrawForm);
746 void ScTabViewShell::SetChartShell( sal_Bool bActive )
748 bActiveChartSh = bActive;
750 if(bActiveChartSh)
751 SetCurSubShell(OST_Chart);
754 void ScTabViewShell::SetGraphicShell( sal_Bool bActive )
756 bActiveGraphicSh = bActive;
758 if(bActiveGraphicSh)
759 SetCurSubShell(OST_Graphic);
762 void ScTabViewShell::SetMediaShell( sal_Bool bActive )
764 bActiveMediaSh = bActive;
766 if(bActiveMediaSh)
767 SetCurSubShell(OST_Media);
770 void ScTabViewShell::SetOleObjectShell( sal_Bool bActive )
772 bActiveOleObjectSh = bActive;
774 if(bActiveOleObjectSh)
775 SetCurSubShell(OST_OleObject);
776 else
777 SetCurSubShell(OST_Cell);
780 void ScTabViewShell::SetEditShell(EditView* pView, sal_Bool bActive )
782 if(bActive)
784 if (pEditShell)
785 pEditShell->SetEditView( pView );
786 else
787 pEditShell = new ScEditShell( pView, GetViewData() );
789 SetCurSubShell(OST_Editing);
791 else if(bActiveEditSh)
793 SetCurSubShell(OST_Cell);
795 bActiveEditSh = bActive;
798 void ScTabViewShell::SetCurSubShell(ObjectSelectionType eOST, sal_Bool bForce)
800 ScViewData* pViewData = GetViewData();
801 ScDocShell* pDocSh = pViewData->GetDocShell();
803 if(bDontSwitch) return;
805 if(!pCellShell) //Wird eh immer gebraucht.
807 pCellShell = new ScCellShell( GetViewData() );
808 pCellShell->SetRepeatTarget( &aTarget );
811 sal_Bool bPgBrk=pViewData->IsPagebreakMode();
813 if(bPgBrk && !pPageBreakShell)
815 pPageBreakShell = new ScPageBreakShell( this );
816 pPageBreakShell->SetRepeatTarget( &aTarget );
820 if ( eOST!=eCurOST || bForce )
822 sal_Bool bCellBrush = false; // "format paint brush" allowed for cells
823 sal_Bool bDrawBrush = false; // "format paint brush" allowed for drawing objects
825 if(eCurOST!=OST_NONE) RemoveSubShell();
827 if (pFormShell && !bFormShellAtTop)
828 AddSubShell(*pFormShell); // add below own subshells
830 switch(eOST)
832 case OST_Cell:
834 AddSubShell(*pCellShell);
835 if(bPgBrk) AddSubShell(*pPageBreakShell);
836 bCellBrush = sal_True;
838 break;
839 case OST_Editing:
841 AddSubShell(*pCellShell);
842 if(bPgBrk) AddSubShell(*pPageBreakShell);
844 if(pEditShell)
846 AddSubShell(*pEditShell);
849 break;
850 case OST_DrawText:
852 if ( !pDrawTextShell )
854 pDocSh->MakeDrawLayer();
855 pDrawTextShell = new ScDrawTextObjectBar( GetViewData() );
857 AddSubShell(*pDrawTextShell);
859 break;
860 case OST_Drawing:
862 if (svx::checkForSelectedCustomShapes(
863 GetScDrawView(), true /* bOnlyExtruded */ )) {
864 if (pExtrusionBarShell == 0)
865 pExtrusionBarShell = new svx::ExtrusionBar(this);
866 AddSubShell( *pExtrusionBarShell );
868 sal_uInt32 nCheckStatus = 0;
869 if (svx::checkForSelectedFontWork(
870 GetScDrawView(), nCheckStatus )) {
871 if (pFontworkBarShell == 0)
872 pFontworkBarShell = new svx::FontworkBar(this);
873 AddSubShell( *pFontworkBarShell );
876 if ( !pDrawShell )
878 pDocSh->MakeDrawLayer();
879 pDrawShell = new ScDrawShell( GetViewData() );
880 pDrawShell->SetRepeatTarget( &aTarget );
882 AddSubShell(*pDrawShell);
883 bDrawBrush = sal_True;
885 break;
887 case OST_DrawForm:
889 if ( !pDrawFormShell )
891 pDocSh->MakeDrawLayer();
892 pDrawFormShell = new ScDrawFormShell( GetViewData() );
893 pDrawFormShell->SetRepeatTarget( &aTarget );
895 AddSubShell(*pDrawFormShell);
896 bDrawBrush = sal_True;
898 break;
900 case OST_Chart:
902 if ( !pChartShell )
904 pDocSh->MakeDrawLayer();
905 pChartShell = new ScChartShell( GetViewData() );
906 pChartShell->SetRepeatTarget( &aTarget );
908 AddSubShell(*pChartShell);
909 bDrawBrush = sal_True;
911 break;
913 case OST_OleObject:
915 if ( !pOleObjectShell )
917 pDocSh->MakeDrawLayer();
918 pOleObjectShell = new ScOleObjectShell( GetViewData() );
919 pOleObjectShell->SetRepeatTarget( &aTarget );
921 AddSubShell(*pOleObjectShell);
922 bDrawBrush = sal_True;
924 break;
926 case OST_Graphic:
928 if ( !pGraphicShell)
930 pDocSh->MakeDrawLayer();
931 pGraphicShell = new ScGraphicShell( GetViewData() );
932 pGraphicShell->SetRepeatTarget( &aTarget );
934 AddSubShell(*pGraphicShell);
935 bDrawBrush = sal_True;
937 break;
939 case OST_Media:
941 if ( !pMediaShell)
943 pDocSh->MakeDrawLayer();
944 pMediaShell = new ScMediaShell( GetViewData() );
945 pMediaShell->SetRepeatTarget( &aTarget );
947 AddSubShell(*pMediaShell);
949 break;
951 case OST_Pivot:
953 AddSubShell(*pCellShell);
954 if(bPgBrk) AddSubShell(*pPageBreakShell);
956 if ( !pPivotShell )
958 pPivotShell = new ScPivotShell( this );
959 pPivotShell->SetRepeatTarget( &aTarget );
961 AddSubShell(*pPivotShell);
962 bCellBrush = sal_True;
964 break;
965 case OST_Auditing:
967 AddSubShell(*pCellShell);
968 if(bPgBrk) AddSubShell(*pPageBreakShell);
970 if ( !pAuditingShell )
972 pDocSh->MakeDrawLayer(); // die Wartezeit lieber jetzt als beim Klick
974 pAuditingShell = new ScAuditingShell( GetViewData() );
975 pAuditingShell->SetRepeatTarget( &aTarget );
977 AddSubShell(*pAuditingShell);
978 bCellBrush = sal_True;
980 break;
981 default:
982 OSL_FAIL("Falsche Shell angefordert");
983 break;
986 if (pFormShell && bFormShellAtTop)
987 AddSubShell(*pFormShell); // add on top of own subshells
989 eCurOST=eOST;
991 // abort "format paint brush" when switching to an incompatible shell
992 if ( ( GetBrushDocument() && !bCellBrush ) || ( GetDrawBrushSet() && !bDrawBrush ) )
993 ResetBrushDocument();
997 void ScTabViewShell::SetFormShellAtTop( sal_Bool bSet )
999 if ( pFormShell && !bSet )
1000 pFormShell->ForgetActiveControl(); // let the FormShell know it no longer has the focus
1002 if ( bFormShellAtTop != bSet )
1004 bFormShellAtTop = bSet;
1005 SetCurSubShell( GetCurObjectSelectionType(), sal_True );
1009 IMPL_LINK_NOARG(ScTabViewShell, FormControlActivated)
1011 // a form control got the focus, so the form shell has to be on top
1012 SetFormShellAtTop( sal_True );
1013 return 0;
1016 ObjectSelectionType ScTabViewShell::GetCurObjectSelectionType()
1018 return eCurOST;
1021 // GetMySubShell / SetMySubShell: altes Verhalten simulieren,
1022 // dass es nur eine SubShell gibt (nur innerhalb der 5 eignenen SubShells)
1024 SfxShell* ScTabViewShell::GetMySubShell() const
1026 // GetSubShell() war frueher const, und GetSubShell(sal_uInt16) sollte es auch sein...
1028 sal_uInt16 nPos = 0;
1029 SfxShell* pSub = ((ScTabViewShell*)this)->GetSubShell(nPos);
1030 while (pSub)
1032 if ( pSub == pDrawShell || pSub == pDrawTextShell || pSub == pEditShell ||
1033 pSub == pPivotShell || pSub == pAuditingShell || pSub == pDrawFormShell ||
1034 pSub == pCellShell || pSub == pOleObjectShell|| pSub == pChartShell ||
1035 pSub == pGraphicShell || pSub == pMediaShell || pSub == pPageBreakShell)
1036 return pSub; // gefunden
1038 pSub = ((ScTabViewShell*)this)->GetSubShell(++nPos);
1040 return NULL; // keine von meinen dabei
1044 sal_Bool ScTabViewShell::IsDrawTextShell() const
1046 return ( pDrawTextShell && ( GetMySubShell() == pDrawTextShell ) );
1049 sal_Bool ScTabViewShell::IsAuditShell() const
1051 return ( pAuditingShell && ( GetMySubShell() == pAuditingShell ) );
1054 void ScTabViewShell::SetDrawTextUndo( ::svl::IUndoManager* pNewUndoMgr )
1056 // Default: Undo-Manager der DocShell
1057 if (!pNewUndoMgr)
1058 pNewUndoMgr = GetViewData()->GetDocShell()->GetUndoManager();
1060 if (pDrawTextShell)
1062 pDrawTextShell->SetUndoManager(pNewUndoMgr);
1063 ScDocShell* pDocSh = GetViewData()->GetDocShell();
1064 if ( pNewUndoMgr == pDocSh->GetUndoManager() &&
1065 !pDocSh->GetDocument()->IsUndoEnabled() )
1067 pNewUndoMgr->SetMaxUndoActionCount( 0 );
1070 else
1072 OSL_FAIL("SetDrawTextUndo ohne DrawTextShell");
1076 //------------------------------------------------------------------
1078 ScTabViewShell* ScTabViewShell::GetActiveViewShell()
1080 return PTR_CAST(ScTabViewShell,Current());
1083 //------------------------------------------------------------------
1085 SfxPrinter* ScTabViewShell::GetPrinter( sal_Bool bCreate )
1087 // Drucker ist immer da (wird fuer die FontListe schon beim Starten angelegt)
1088 return GetViewData()->GetDocShell()->GetPrinter(bCreate);
1091 sal_uInt16 ScTabViewShell::SetPrinter( SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool )
1093 return GetViewData()->GetDocShell()->SetPrinter( pNewPrinter, nDiffFlags );
1096 SfxTabPage* ScTabViewShell::CreatePrintOptionsPage( Window *pParent, const SfxItemSet &rOptions )
1098 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1099 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1100 ::CreateTabPage ScTpPrintOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_PRINT );
1101 if ( ScTpPrintOptionsCreate )
1102 return (*ScTpPrintOptionsCreate)( pParent, rOptions);
1103 return 0;
1106 void ScTabViewShell::StopEditShell()
1108 if ( pEditShell != NULL && !bDontSwitch )
1109 SetEditShell(NULL, false );
1112 //------------------------------------------------------------------
1114 // close handler to ensure function of dialog:
1116 IMPL_LINK_NOARG(ScTabViewShell, SimpleRefClose)
1118 SfxInPlaceClient* pClient = GetIPClient();
1119 if ( pClient && pClient->IsObjectInPlaceActive() )
1121 // If range selection was started with an active embedded object,
1122 // switch back to original sheet (while the dialog is still open).
1124 SetTabNo( GetViewData()->GetRefTabNo() );
1127 ScSimpleRefDlgWrapper::SetAutoReOpen( sal_True );
1128 return 0;
1131 // handlers to call UNO listeners:
1133 static ScTabViewObj* lcl_GetViewObj( ScTabViewShell& rShell )
1135 ScTabViewObj* pRet = NULL;
1136 SfxViewFrame* pViewFrame = rShell.GetViewFrame();
1137 if (pViewFrame)
1139 SfxFrame& rFrame = pViewFrame->GetFrame();
1140 uno::Reference<frame::XController> xController = rFrame.GetController();
1141 if (xController.is())
1142 pRet = ScTabViewObj::getImplementation( xController );
1144 return pRet;
1147 IMPL_LINK( ScTabViewShell, SimpleRefDone, String*, pResult )
1149 ScTabViewObj* pImpObj = lcl_GetViewObj( *this );
1150 if ( pImpObj && pResult )
1151 pImpObj->RangeSelDone( *pResult );
1152 return 0;
1155 IMPL_LINK( ScTabViewShell, SimpleRefAborted, String*, pResult )
1157 ScTabViewObj* pImpObj = lcl_GetViewObj( *this );
1158 if ( pImpObj && pResult )
1159 pImpObj->RangeSelAborted( *pResult );
1160 return 0;
1163 IMPL_LINK( ScTabViewShell, SimpleRefChange, String*, pResult )
1165 ScTabViewObj* pImpObj = lcl_GetViewObj( *this );
1166 if ( pImpObj && pResult )
1167 pImpObj->RangeSelChanged( *pResult );
1168 return 0;
1171 void ScTabViewShell::StartSimpleRefDialog(
1172 const String& rTitle, const String& rInitVal,
1173 sal_Bool bCloseOnButtonUp, sal_Bool bSingleCell, sal_Bool bMultiSelection )
1175 SfxViewFrame* pViewFrm = GetViewFrame();
1177 if ( GetActiveViewShell() != this )
1179 // #i18833# / #i34499# The API method can be called for a view that's not active.
1180 // Then the view has to be activated first, the same way as in Execute for SID_CURRENTDOC.
1181 // Can't use GrabFocus here, because it needs to take effect immediately.
1183 pViewFrm->GetFrame().Appear();
1186 sal_uInt16 nId = ScSimpleRefDlgWrapper::GetChildWindowId();
1188 SC_MOD()->SetRefDialog( nId, sal_True, pViewFrm );
1190 ScSimpleRefDlgWrapper* pWnd = (ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
1191 if (pWnd)
1193 pWnd->SetCloseHdl( LINK( this, ScTabViewShell, SimpleRefClose ) );
1194 pWnd->SetUnoLinks( LINK( this, ScTabViewShell, SimpleRefDone ),
1195 LINK( this, ScTabViewShell, SimpleRefAborted ),
1196 LINK( this, ScTabViewShell, SimpleRefChange ) );
1197 pWnd->SetRefString( rInitVal );
1198 pWnd->SetFlags( bCloseOnButtonUp, bSingleCell, bMultiSelection );
1199 pWnd->SetAutoReOpen( false );
1200 Window* pWin = pWnd->GetWindow();
1201 pWin->SetText( rTitle );
1202 pWnd->StartRefInput();
1206 void ScTabViewShell::StopSimpleRefDialog()
1208 SfxViewFrame* pViewFrm = GetViewFrame();
1209 sal_uInt16 nId = ScSimpleRefDlgWrapper::GetChildWindowId();
1211 ScSimpleRefDlgWrapper* pWnd = (ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
1212 if (pWnd)
1214 Window* pWin = pWnd->GetWindow();
1215 if (pWin && pWin->IsSystemWindow())
1216 ((SystemWindow*)pWin)->Close(); // calls abort handler
1220 //------------------------------------------------------------------
1222 sal_Bool ScTabViewShell::TabKeyInput(const KeyEvent& rKEvt)
1224 ScModule* pScMod = SC_MOD();
1226 SfxViewFrame* pThisFrame = GetViewFrame();
1227 if ( pThisFrame->GetChildWindow( SID_OPENDLG_FUNCTION ) )
1228 return false;
1230 KeyCode aCode = rKEvt.GetKeyCode();
1231 sal_Bool bShift = aCode.IsShift();
1232 sal_Bool bControl = aCode.IsMod1();
1233 sal_Bool bAlt = aCode.IsMod2();
1234 sal_uInt16 nCode = aCode.GetCode();
1235 sal_Bool bUsed = false;
1236 sal_Bool bInPlace = pScMod->IsEditMode(); // Editengine bekommt alles
1237 sal_Bool bAnyEdit = pScMod->IsInputMode(); // nur Zeichen & Backspace
1238 sal_Bool bDraw = IsDrawTextEdit();
1240 HideNoteMarker(); // Notiz-Anzeige
1242 // don't do extra HideCursor/ShowCursor calls if EnterHandler will switch to a different sheet
1243 sal_Bool bOnRefSheet = ( GetViewData()->GetRefTabNo() == GetViewData()->GetTabNo() );
1244 sal_Bool bHideCursor = ( ( nCode == KEY_RETURN && bInPlace ) || nCode == KEY_TAB ) && bOnRefSheet;
1246 if (bHideCursor)
1247 HideAllCursors();
1249 ScDocument* pDoc = GetViewData()->GetDocument();
1250 if ( pDoc )
1251 pDoc->KeyInput( rKEvt ); // TimerDelays etc.
1253 if( bInPlace )
1255 bUsed = pScMod->InputKeyEvent( rKEvt ); // Eingabe
1256 if( !bUsed )
1257 bUsed = sal::static_int_cast<sal_Bool>(SfxViewShell::KeyInput( rKEvt )); // accelerators
1259 else if( bAnyEdit )
1261 sal_Bool bIsType = false;
1262 sal_uInt16 nModi = aCode.GetModifier();
1263 sal_uInt16 nGroup = aCode.GetGroup();
1265 if ( nGroup == KEYGROUP_NUM || nGroup == KEYGROUP_ALPHA || nGroup == 0 )
1266 if ( !bControl && !bAlt )
1267 bIsType = sal_True;
1269 if ( nGroup == KEYGROUP_MISC )
1270 switch ( nCode )
1272 case KEY_RETURN:
1273 bIsType = bControl && !bAlt; // Control, Shift-Control-Return
1274 if ( !bIsType && nModi == 0 )
1276 // Will der InputHandler auch ein einfaches Return?
1278 ScInputHandler* pHdl = pScMod->GetInputHdl(this);
1279 bIsType = pHdl && pHdl->TakesReturn();
1281 break;
1282 case KEY_SPACE:
1283 bIsType = !bControl && !bAlt; // ohne Modifier oder Shift-Space
1284 break;
1285 case KEY_ESCAPE:
1286 bIsType = (nModi == 0); // nur ohne Modifier
1287 break;
1288 default:
1289 bIsType = sal_True;
1292 if( bIsType )
1293 bUsed = pScMod->InputKeyEvent( rKEvt ); // Eingabe
1295 if( !bUsed )
1296 bUsed = sal::static_int_cast<sal_Bool>(SfxViewShell::KeyInput( rKEvt )); // accelerators
1298 if ( !bUsed && !bIsType && nCode != KEY_RETURN ) // Eingabe nochmal hinterher
1299 bUsed = pScMod->InputKeyEvent( rKEvt );
1301 else
1303 // Spezialfall: Copy/Cut bei Mehrfachselektion -> Fehlermeldung
1304 // (Slot ist disabled, SfxViewShell::KeyInput wuerde also kommentarlos verschluckt)
1305 KeyFuncType eFunc = aCode.GetFunction();
1306 if ( eFunc == KEYFUNC_CUT )
1308 ScRange aDummy;
1309 ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy );
1310 if ( eMarkType != SC_MARK_SIMPLE &&
1311 !(eFunc == KEYFUNC_COPY && eMarkType == SC_MARK_SIMPLE_FILTERED) )
1313 ErrorMessage(STR_NOMULTISELECT);
1314 bUsed = sal_True;
1317 if (!bUsed)
1318 bUsed = sal::static_int_cast<sal_Bool>(SfxViewShell::KeyInput( rKEvt )); // accelerators
1320 // during inplace editing, some slots are handled by the
1321 // container app and are executed during Window::KeyInput.
1322 // -> don't pass keys to input handler that would be used there
1323 // but should call slots instead.
1324 sal_Bool bParent = ( GetViewFrame()->GetFrame().IsInPlace() && eFunc != KEYFUNC_DONTKNOW );
1326 if( !bUsed && !bDraw && nCode != KEY_RETURN && !bParent )
1327 bUsed = pScMod->InputKeyEvent( rKEvt, sal_True ); // Eingabe
1330 if (!bInPlace && !bUsed && !bDraw)
1332 switch (nCode)
1334 case KEY_RETURN:
1336 sal_Bool bNormal = !bControl && !bAlt;
1337 if ( !bAnyEdit && bNormal )
1339 // je nach Optionen mit Enter in den Edit-Modus schalten
1341 const ScInputOptions& rOpt = pScMod->GetInputOptions();
1342 if ( rOpt.GetEnterEdit() )
1344 pScMod->SetInputMode( SC_INPUT_TABLE );
1345 bUsed = sal_True;
1349 sal_Bool bEditReturn = bControl && !bShift; // An Edit-Engine weiter
1350 if ( !bUsed && !bEditReturn )
1352 if ( bOnRefSheet )
1353 HideAllCursors();
1355 sal_uInt8 nMode = SC_ENTER_NORMAL;
1356 if ( bShift && bControl )
1357 nMode = SC_ENTER_MATRIX;
1358 else if ( bAlt )
1359 nMode = SC_ENTER_BLOCK;
1360 pScMod->InputEnterHandler(nMode);
1362 if (nMode == SC_ENTER_NORMAL)
1364 if( bShift )
1365 GetViewData()->GetDispatcher().Execute( SID_CURSORENTERUP,
1366 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1367 else
1368 GetViewData()->GetDispatcher().Execute( SID_CURSORENTERDOWN,
1369 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1371 else
1372 UpdateInputHandler(sal_True);
1374 if ( bOnRefSheet )
1375 ShowAllCursors();
1377 // hier kein UpdateInputHandler, weil bei Referenzeingabe auf ein
1378 // anderes Dokument diese ViewShell nicht die ist, auf der eingegeben
1379 // wird!
1381 bUsed = sal_True;
1384 break;
1388 // Alt-Cursortasten hart codiert, weil Alt nicht konfigurierbar ist
1390 if ( !bUsed && bAlt && !bControl )
1392 sal_uInt16 nSlotId = 0;
1393 switch (nCode)
1395 case KEY_UP:
1396 ModifyCellSize( DIR_TOP, bShift );
1397 bUsed = sal_True;
1398 break;
1399 case KEY_DOWN:
1400 ModifyCellSize( DIR_BOTTOM, bShift );
1401 bUsed = sal_True;
1402 break;
1403 case KEY_LEFT:
1404 ModifyCellSize( DIR_LEFT, bShift );
1405 bUsed = sal_True;
1406 break;
1407 case KEY_RIGHT:
1408 ModifyCellSize( DIR_RIGHT, bShift );
1409 bUsed = sal_True;
1410 break;
1411 case KEY_PAGEUP:
1412 nSlotId = bShift ? SID_CURSORPAGELEFT_SEL : SID_CURSORPAGELEFT_;
1413 break;
1414 case KEY_PAGEDOWN:
1415 nSlotId = bShift ? SID_CURSORPAGERIGHT_SEL : SID_CURSORPAGERIGHT_;
1416 break;
1418 if ( nSlotId )
1420 GetViewData()->GetDispatcher().Execute( nSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1421 bUsed = sal_True;
1425 if (bHideCursor)
1426 ShowAllCursors();
1428 return bUsed;
1431 sal_Bool ScTabViewShell::SfxKeyInput(const KeyEvent& rKeyEvent)
1433 return sal::static_int_cast<sal_Bool>(SfxViewShell::KeyInput( rKeyEvent ));
1436 bool ScTabViewShell::KeyInput( const KeyEvent &rKeyEvent )
1438 return TabKeyInput( rKeyEvent );
1441 //------------------------------------------------------------------
1443 #define __INIT_ScTabViewShell \
1444 eCurOST(OST_NONE), \
1445 nDrawSfxId(0), \
1446 nCtrlSfxId(USHRT_MAX), \
1447 nFormSfxId(USHRT_MAX), \
1448 pDrawShell(NULL), \
1449 pDrawTextShell(NULL), \
1450 pEditShell(NULL), \
1451 pPivotShell(NULL), \
1452 pAuditingShell(NULL), \
1453 pDrawFormShell(NULL), \
1454 pCellShell(NULL), \
1455 pOleObjectShell(NULL), \
1456 pChartShell(NULL), \
1457 pGraphicShell(NULL), \
1458 pMediaShell(NULL), \
1459 pPageBreakShell(NULL), \
1460 pExtrusionBarShell(NULL), \
1461 pFontworkBarShell(NULL), \
1462 pFormShell(NULL), \
1463 pInputHandler(NULL), \
1464 pCurFrameLine(NULL), \
1465 aTarget( this ), \
1466 pDialogDPObject(NULL), \
1467 pNavSettings(NULL), \
1468 bActiveDrawSh(false), \
1469 bActiveDrawTextSh(false), \
1470 bActivePivotSh(false), \
1471 bActiveAuditingSh(false), \
1472 bActiveDrawFormSh(false), \
1473 bActiveOleObjectSh(false), \
1474 bActiveChartSh(false), \
1475 bActiveGraphicSh(false), \
1476 bActiveMediaSh(false), \
1477 bActiveEditSh(false), \
1478 bFormShellAtTop(false), \
1479 bDontSwitch(false), \
1480 bInFormatDialog(false), \
1481 bPrintSelected(false), \
1482 bReadOnly(false), \
1483 pScSbxObject(NULL), \
1484 bChartAreaValid(false), \
1485 nCurRefDlgId(0), \
1486 pAccessibilityBroadcaster(NULL), \
1487 mbInSwitch(false)
1490 //------------------------------------------------------------------
1492 void ScTabViewShell::Construct( sal_uInt8 nForceDesignMode )
1494 SfxApplication* pSfxApp = SFX_APP();
1495 ScDocShell* pDocSh = GetViewData()->GetDocShell();
1496 ScDocument* pDoc = pDocSh->GetDocument();
1498 bReadOnly = pDocSh->IsReadOnly();
1500 SetName(rtl::OUString("View")); // fuer SBX
1501 Color aColBlack( COL_BLACK );
1502 SetPool( &SC_MOD()->GetPool() );
1503 SetWindow( GetActiveWin() );
1505 pCurFrameLine = new ::editeng::SvxBorderLine(&aColBlack, 20,
1506 table::BorderLineStyle::SOLID);
1507 pPivotSource = new ScArea;
1508 StartListening(*GetViewData()->GetDocShell(),sal_True);
1509 StartListening(*GetViewFrame(),sal_True);
1510 StartListening(*pSfxApp,sal_True); // #i62045# #i62046# application is needed for Calc's own hints
1512 SfxViewFrame* pFirst = SfxViewFrame::GetFirst(pDocSh);
1513 sal_Bool bFirstView = !pFirst
1514 || (pFirst == GetViewFrame() && !SfxViewFrame::GetNext(*pFirst,pDocSh));
1516 if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1518 //TODO/LATER: is there a difference between the two GetVisArea methods?
1519 Rectangle aVisArea = ((const SfxObjectShell*)pDocSh)->GetVisArea();
1521 SCTAB nVisTab = pDoc->GetVisibleTab();
1522 if (!pDoc->HasTable(nVisTab))
1524 nVisTab = 0;
1525 pDoc->SetVisibleTab(nVisTab);
1527 SetTabNo( nVisTab );
1528 sal_Bool bNegativePage = pDoc->IsNegativePage( nVisTab );
1529 // show the right cells
1530 GetViewData()->SetScreenPos( bNegativePage ? aVisArea.TopRight() : aVisArea.TopLeft() );
1532 if ( GetViewFrame()->GetFrame().IsInPlace() ) // inplace
1534 pDocSh->SetInplace( sal_True ); // schon so initialisiert
1535 if (pDoc->IsEmbedded())
1536 pDoc->ResetEmbedded(); // keine blaue Markierung
1538 else if ( bFirstView )
1540 pDocSh->SetInplace( false );
1541 GetViewData()->RefreshZoom(); // recalculate PPT
1542 if (!pDoc->IsEmbedded())
1543 pDoc->SetEmbedded( aVisArea ); // VisArea markieren
1547 // ViewInputHandler
1548 // jeder Task hat neuerdings sein eigenes InputWindow,
1549 // darum muesste eigentlich entweder jeder Task seinen InputHandler bekommen,
1550 // oder das InputWindow muesste sich beim App-InputHandler anmelden, wenn der
1551 // Task aktiv wird, oder das InputWindow muesste sich den InputHandler selbst
1552 // anlegen (dann immer ueber das InputWindow suchen, und nur wenn das nicht da
1553 // ist, den InputHandler von der App nehmen).
1554 // Als Sofortloesung bekommt erstmal jede View ihren Inputhandler, das gibt
1555 // nur noch Probleme, wenn zwei Views in einem Task-Fenster sind.
1557 pInputHandler = new ScInputHandler;
1559 // Alte Version:
1560 // if ( !GetViewFrame()->ISA(SfxTopViewFrame) ) // OLE oder Plug-In
1561 // pInputHandler = new ScInputHandler;
1563 // FormShell vor MakeDrawView anlegen, damit die DrawView auf jeden Fall
1564 // an der FormShell angemeldet werden kann
1565 // Gepusht wird die FormShell im ersten Activate
1566 pFormShell = new FmFormShell(this);
1567 pFormShell->SetControlActivationHandler( LINK( this, ScTabViewShell, FormControlActivated ) );
1569 // DrawView darf nicht im TabView - ctor angelegt werden,
1570 // wenn die ViewShell noch nicht kostruiert ist...
1571 if (pDoc->GetDrawLayer())
1572 MakeDrawView( nForceDesignMode );
1573 ViewOptionsHasChanged(false); // legt auch evtl. DrawView an
1575 ::svl::IUndoManager* pMgr = pDocSh->GetUndoManager();
1576 SetUndoManager( pMgr );
1577 pFormShell->SetUndoManager( pMgr );
1578 if ( !pDoc->IsUndoEnabled() )
1580 pMgr->SetMaxUndoActionCount( 0 );
1582 SetRepeatTarget( &aTarget );
1583 pFormShell->SetRepeatTarget( &aTarget );
1584 SetHelpId( HID_SCSHELL_TABVWSH );
1586 if ( bFirstView ) // first view?
1588 pDoc->SetDocVisible( sal_True ); // used when creating new sheets
1589 if ( pDocSh->IsEmpty() )
1591 // set first sheet's RTL flag (following will already be initialized because of SetDocVisible)
1592 pDoc->SetLayoutRTL( 0, ScGlobal::IsSystemRTL() );
1594 // append additional sheets (not for OLE object)
1595 if ( pDocSh->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
1597 // Get the customized initial tab count
1598 const ScDefaultsOptions& rOpt = SC_MOD()->GetDefaultsOptions();
1599 SCTAB nInitTabCount = rOpt.GetInitTabCount();
1601 for (SCTAB i=1; i<nInitTabCount; i++)
1602 pDoc->MakeTable(i,false);
1605 pDocSh->SetEmpty( false ); // #i6232# make sure this is done only once
1608 // ReadExtOptions is now in Activate
1610 // Link-Update nicht verschachteln
1611 if ( pDocSh->GetCreateMode() != SFX_CREATE_MODE_INTERNAL &&
1612 pDocSh->IsUpdateEnabled() ) // #105575#; update only in the first creation of the ViewShell
1614 // Check if there are any external data.
1615 bool bLink = pDoc->GetExternalRefManager()->hasExternalData();
1616 if (!bLink)
1618 // #i100042# sheet links can still exist independently from external formula references
1619 SCTAB nTabCount = pDoc->GetTableCount();
1620 for (SCTAB i=0; i<nTabCount && !bLink; i++)
1621 if (pDoc->IsLinked(i))
1622 bLink = true;
1624 if (!bLink)
1625 if (pDoc->HasDdeLinks() || pDoc->HasAreaLinks())
1626 bLink = sal_True;
1627 if (bLink)
1629 if ( !pFirst )
1630 pFirst = GetViewFrame();
1632 if(SC_MOD()->GetCurRefDlgId()==0)
1634 pFirst->GetDispatcher()->Execute( SID_UPDATETABLINKS,
1635 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
1639 bool bReImport = false; // importierte Daten aktualisieren
1640 ScDBCollection* pDBColl = pDoc->GetDBCollection();
1641 if ( pDBColl )
1643 const ScDBCollection::NamedDBs& rDBs = pDBColl->getNamedDBs();
1644 ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin(), itrEnd = rDBs.end();
1645 for (; itr != itrEnd; ++itr)
1647 if (itr->IsStripData() && itr->HasImportParam() && !itr->HasImportSelection())
1649 bReImport = true;
1650 break;
1654 if (bReImport)
1656 if ( !pFirst )
1657 pFirst = GetViewFrame();
1658 if(SC_MOD()->GetCurRefDlgId()==0)
1660 pFirst->GetDispatcher()->Execute( SID_REIMPORT_AFTER_LOAD,
1661 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
1667 UpdateAutoFillMark();
1669 // ScDispatchProviderInterceptor registers itself in ctor
1670 xDisProvInterceptor = new ScDispatchProviderInterceptor( this );
1672 bFirstActivate = sal_True; // NavigatorUpdate aufschieben bis Activate()
1674 // #105575#; update only in the first creation of the ViewShell
1675 pDocSh->SetUpdateEnabled(false);
1677 if ( GetViewFrame()->GetFrame().IsInPlace() )
1678 UpdateHeaderWidth(); // The implace activation requires headers to be calculated
1680 SvBorder aBorder;
1681 GetBorderSize( aBorder, Size() );
1682 SetBorderPixel( aBorder );
1685 //------------------------------------------------------------------
1688 //------------------------------------------------------------------
1690 ScTabViewShell::ScTabViewShell( SfxViewFrame* pViewFrame,
1691 SfxViewShell* pOldSh ) :
1692 SfxViewShell( pViewFrame, SFX_VIEW_CAN_PRINT | SFX_VIEW_HAS_PRINTOPTIONS ),
1693 ScDBFunc( &pViewFrame->GetWindow(), (ScDocShell&)*pViewFrame->GetObjectShell(), this ),
1694 __INIT_ScTabViewShell
1696 RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScTabViewShell::ScTabViewShell" );
1698 const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
1700 // if switching back from print preview,
1701 // restore the view settings that were active when creating the preview
1702 // ReadUserData must not happen from ctor, because the view's edit window
1703 // has to be shown by the sfx. ReadUserData is deferred until the first Activate call.
1704 // old DesignMode state from form layer must be restored, too
1706 sal_uInt8 nForceDesignMode = SC_FORCEMODE_NONE;
1707 if ( pOldSh && pOldSh->ISA( ScPreviewShell ) )
1709 ScPreviewShell* pPreviewShell = ((ScPreviewShell*)pOldSh);
1710 nForceDesignMode = pPreviewShell->GetSourceDesignMode();
1711 ScPreview* p = pPreviewShell->GetPreview();
1712 if (p)
1713 GetViewData()->GetMarkData().SetSelectedTabs(p->GetSelectedTabs());
1716 Construct( nForceDesignMode );
1718 if ( GetViewData()->GetDocShell()->IsPreview() )
1720 // preview for template dialog: always show whole page
1721 SetZoomType( SVX_ZOOM_WHOLEPAGE, sal_True ); // zoom value is recalculated at next Resize
1723 else
1725 Fraction aFract( rAppOpt.GetZoom(), 100 );
1726 SetZoom( aFract, aFract, sal_True );
1727 SetZoomType( rAppOpt.GetZoomType(), sal_True );
1730 // make Controller known to SFX
1731 new ScTabViewObj( this );
1733 SetCurSubShell(OST_Cell);
1734 SvBorder aBorder;
1735 GetBorderSize( aBorder, Size() );
1736 SetBorderPixel( aBorder );
1738 // #114409#
1739 MakeDrawLayer();
1742 #undef __INIT_ScTabViewShell
1744 //------------------------------------------------------------------
1746 ScTabViewShell::~ScTabViewShell()
1748 ScDocShell* pDocSh = GetViewData()->GetDocShell();
1749 EndListening(*pDocSh);
1750 EndListening(*GetViewFrame());
1751 EndListening(*SFX_APP()); // #i62045# #i62046# needed now - SfxViewShell no longer does it
1753 SC_MOD()->ViewShellGone(this);
1755 RemoveSubShell(); // alle
1756 SetWindow(0);
1758 // alles auf NULL, falls aus dem TabView-dtor noch darauf zugegriffen wird
1759 //! (soll eigentlich nicht !??!?!)
1761 DELETEZ(pFontworkBarShell);
1762 DELETEZ(pExtrusionBarShell);
1763 DELETEZ(pCellShell);
1764 DELETEZ(pPageBreakShell);
1765 DELETEZ(pDrawShell);
1766 DELETEZ(pDrawFormShell);
1767 DELETEZ(pOleObjectShell);
1768 DELETEZ(pChartShell);
1769 DELETEZ(pGraphicShell);
1770 DELETEZ(pMediaShell);
1771 DELETEZ(pDrawTextShell);
1772 DELETEZ(pEditShell);
1773 DELETEZ(pPivotShell);
1774 DELETEZ(pAuditingShell);
1775 DELETEZ(pCurFrameLine);
1776 DELETEZ(pInputHandler);
1777 DELETEZ(pPivotSource);
1778 DELETEZ(pDialogDPObject);
1779 DELETEZ(pNavSettings);
1781 DELETEZ(pFormShell);
1782 DELETEZ(pAccessibilityBroadcaster);
1785 //------------------------------------------------------------------
1787 void ScTabViewShell::SetDialogDPObject( const ScDPObject* pObj )
1789 delete pDialogDPObject;
1790 if (pObj)
1791 pDialogDPObject = new ScDPObject( *pObj );
1792 else
1793 pDialogDPObject = NULL;
1796 //------------------------------------------------------------------
1798 void ScTabViewShell::FillFieldData( ScHeaderFieldData& rData )
1800 ScDocShell* pDocShell = GetViewData()->GetDocShell();
1801 ScDocument* pDoc = pDocShell->GetDocument();
1802 SCTAB nTab = GetViewData()->GetTabNo();
1803 rtl::OUString aTmp;
1804 pDoc->GetName(nTab, aTmp);
1805 rData.aTabName = aTmp;
1807 if( pDocShell->getDocProperties()->getTitle().getLength() != 0 )
1808 rData.aTitle = pDocShell->getDocProperties()->getTitle();
1809 else
1810 rData.aTitle = pDocShell->GetTitle();
1812 const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject();
1813 rData.aLongDocName = rURLObj.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
1814 if ( rData.aLongDocName.Len() )
1815 rData.aShortDocName = rURLObj.GetName( INetURLObject::DECODE_UNAMBIGUOUS );
1816 else
1817 rData.aShortDocName = rData.aLongDocName = rData.aTitle;
1818 rData.nPageNo = 1;
1819 rData.nTotalPages = 99;
1821 // eNumType kennt der Dialog selber
1824 //------------------------------------------------------------------
1826 void ScTabViewShell::SetChartArea( const ScRangeListRef& rSource, const Rectangle& rDest )
1828 bChartAreaValid = sal_True;
1829 aChartSource = rSource;
1830 aChartPos = rDest;
1831 nChartDestTab = GetViewData()->GetTabNo();
1834 sal_Bool ScTabViewShell::GetChartArea( ScRangeListRef& rSource, Rectangle& rDest, SCTAB& rTab ) const
1836 rSource = aChartSource;
1837 rDest = aChartPos;
1838 rTab = nChartDestTab;
1839 return bChartAreaValid;
1842 ScNavigatorSettings* ScTabViewShell::GetNavigatorSettings()
1844 if( !pNavSettings )
1845 pNavSettings = new ScNavigatorSettings;
1846 return pNavSettings;
1850 //------------------------------------------------------------------
1852 void ScTabViewShell::ExecTbx( SfxRequest& rReq )
1854 const SfxItemSet* pReqArgs = rReq.GetArgs();
1855 sal_uInt16 nSlot = rReq.GetSlot();
1856 const SfxPoolItem* pItem = NULL;
1857 if ( pReqArgs )
1858 pReqArgs->GetItemState( nSlot, sal_True, &pItem );
1860 switch ( nSlot )
1862 case SID_TBXCTL_INSERT:
1863 if ( pItem )
1864 nInsertCtrlState = ((const SfxUInt16Item*)pItem)->GetValue();
1865 break;
1866 case SID_TBXCTL_INSCELLS:
1867 if ( pItem )
1868 nInsCellsCtrlState = ((const SfxUInt16Item*)pItem)->GetValue();
1869 break;
1870 case SID_TBXCTL_INSOBJ:
1871 if ( pItem )
1872 nInsObjCtrlState = ((const SfxUInt16Item*)pItem)->GetValue();
1873 break;
1874 default:
1875 OSL_FAIL("Slot im Wald");
1877 GetViewFrame()->GetBindings().Invalidate( nSlot );
1880 void ScTabViewShell::GetTbxState( SfxItemSet& rSet )
1882 rSet.Put( SfxUInt16Item( SID_TBXCTL_INSERT, nInsertCtrlState ) );
1883 rSet.Put( SfxUInt16Item( SID_TBXCTL_INSCELLS, nInsCellsCtrlState ) );
1885 // ohne installiertes Chart darf Chart nicht Default sein...
1886 if ( nInsObjCtrlState == SID_DRAW_CHART && !SvtModuleOptions().IsChart() )
1887 nInsObjCtrlState = SID_INSERT_OBJECT;
1889 rSet.Put( SfxUInt16Item( SID_TBXCTL_INSOBJ, nInsObjCtrlState ) );
1896 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */