Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / view / tabvwsh4.cxx
blob54bde9ff7425deb7ba5e1c41ca067a699afd1f71
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 <sal/config.h>
22 #include "olkact.hxx"
23 #include "scitems.hxx"
24 #include <editeng/eeitem.hxx>
26 #include <sfx2/app.hxx>
27 #include <svx/extrusionbar.hxx>
28 #include <svx/fontworkbar.hxx>
29 #include <editeng/boxitem.hxx>
30 #include <svx/fmpage.hxx>
31 #include <svx/fmshell.hxx>
32 #include <editeng/sizeitem.hxx>
33 #include <svx/prtqry.hxx>
34 #include <svx/sidebar/ContextChangeEventMultiplexer.hxx>
35 #include <sfx2/request.hxx>
36 #include <sfx2/printer.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <svl/whiter.hxx>
39 #include <unotools/moduleoptions.hxx>
40 #include <tools/urlobj.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <vcl/openglwin.hxx>
44 #include "tabvwsh.hxx"
45 #include "sc.hrc"
46 #include "globstr.hrc"
47 #include "stlpool.hxx"
48 #include "stlsheet.hxx"
49 #include "docsh.hxx"
50 #include "scmod.hxx"
51 #include "appoptio.hxx"
52 #include "rangeutl.hxx"
53 #include "printfun.hxx"
54 #include "drawsh.hxx"
55 #include "drformsh.hxx"
56 #include "editsh.hxx"
57 #include "pivotsh.hxx"
58 #include "auditsh.hxx"
59 #include "drtxtob.hxx"
60 #include "inputhdl.hxx"
61 #include "editutil.hxx"
62 #include "inputopt.hxx"
63 #include "inputwin.hxx"
64 #include "scresid.hxx"
65 #include "dbdata.hxx"
66 #include "reffact.hxx"
67 #include "viewuno.hxx"
68 #include "dispuno.hxx"
69 #include "anyrefdg.hxx"
70 #include "chgtrack.hxx"
71 #include "cellsh.hxx"
72 #include "oleobjsh.hxx"
73 #include "chartsh.hxx"
74 #include "graphsh.hxx"
75 #include "mediash.hxx"
76 #include "pgbrksh.hxx"
77 #include "dpobject.hxx"
78 #include "prevwsh.hxx"
79 #include "tpprint.hxx"
80 #include "scextopt.hxx"
81 #include "printopt.hxx"
82 #include "drawview.hxx"
83 #include "fupoor.hxx"
84 #include "navsett.hxx"
85 #include "scabstdlg.hxx"
86 #include "externalrefmgr.hxx"
87 #include "defaultsoptions.hxx"
88 #include "markdata.hxx"
89 #include "preview.hxx"
90 #include "docoptio.hxx"
91 #include <documentlinkmgr.hxx>
92 #include <gridwin.hxx>
94 #include <com/sun/star/document/XDocumentProperties.hpp>
95 #include <com/sun/star/chart2/X3DChartWindowProvider.hpp>
97 extern SfxViewShell* pScActiveViewShell; // global.cxx
99 using namespace com::sun::star;
101 // STATIC DATA -----------------------------------------------------------
103 sal_uInt16 ScTabViewShell::nInsertCtrlState = SID_INSERT_GRAPHIC;
104 sal_uInt16 ScTabViewShell::nInsCellsCtrlState = 0;
105 sal_uInt16 ScTabViewShell::nInsObjCtrlState = SID_INSERT_DIAGRAM;
107 void ScTabViewShell::Activate(bool bMDI)
109 SfxViewShell::Activate(bMDI);
110 bIsActive = true;
111 // hier kein GrabFocus, sonst gibt's Probleme wenn etwas inplace editiert wird!
113 if ( bMDI )
115 // fuer Eingabezeile (ClearCache)
116 ScModule* pScMod = SC_MOD();
117 pScMod->ViewShellChanged();
119 ActivateView( true, bFirstActivate );
120 ActivateOlk( GetViewData() );
122 // AutoCorrect umsetzen, falls der Writer seins neu angelegt hat
123 UpdateDrawTextOutliner();
125 // RegisterNewTargetNames gibts nicht mehr
127 SfxViewFrame* pThisFrame = GetViewFrame();
128 if ( pInputHandler && pThisFrame->HasChildWindow(FID_INPUTLINE_STATUS) )
130 // eigentlich nur beim Reload (letzte Version) noetig:
131 // Das InputWindow bleibt stehen, aber die View mitsamt InputHandler wird
132 // neu angelegt, darum muss der InputHandler am InputWindow gesetzt werden.
133 SfxChildWindow* pChild = pThisFrame->GetChildWindow(FID_INPUTLINE_STATUS);
134 if (pChild)
136 ScInputWindow* pWin = (ScInputWindow*)pChild->GetWindow();
137 if (pWin && pWin->IsVisible())
140 ScInputHandler* pOldHdl=pWin->GetInputHandler();
142 TypeId aScType = TYPE(ScTabViewShell);
144 SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
145 while ( pSh!=NULL && pOldHdl!=NULL)
147 if (((ScTabViewShell*)pSh)->GetInputHandler() == pOldHdl)
149 pOldHdl->ResetDelayTimer();
150 break;
152 pSh = SfxViewShell::GetNext( *pSh, &aScType );
155 pWin->SetInputHandler( pInputHandler );
160 UpdateInputHandler( true );
162 if ( bFirstActivate )
164 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_NAVIGATOR_UPDATEALL ) );
165 bFirstActivate = false;
167 // ReadExtOptions (view settings from Excel import) must also be done
168 // after the ctor, because of the potential calls to Window::Show.
169 // Even after a bugfix (Window::Show no longer notifies the access
170 // bridge, it's done in ImplSetReallyVisible), there are problems if Window::Show
171 // is called during the ViewShell ctor and reschedules asynchronous calls
172 // (for example from the FmFormShell ctor).
173 ScExtDocOptions* pExtOpt = GetViewData()->GetDocument()->GetExtDocOptions();
174 if ( pExtOpt && pExtOpt->IsChanged() )
176 GetViewData()->ReadExtOptions(*pExtOpt); // Excel view settings
177 SetTabNo( GetViewData()->GetTabNo(), true );
178 pExtOpt->SetChanged( false );
182 pScActiveViewShell = this;
184 ScInputHandler* pHdl = pScMod->GetInputHdl(this);
185 if (pHdl)
187 pHdl->SetRefScale( GetViewData()->GetZoomX(), GetViewData()->GetZoomY() );
190 // Aenderungs-Dialog aktualisieren
192 if ( pThisFrame->HasChildWindow(FID_CHG_ACCEPT) )
194 SfxChildWindow* pChild = pThisFrame->GetChildWindow(FID_CHG_ACCEPT);
195 if (pChild)
197 ((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg();
201 if(pScMod->IsRefDialogOpen())
203 sal_uInt16 nModRefDlgId=pScMod->GetCurRefDlgId();
204 SfxChildWindow* pChildWnd = pThisFrame->GetChildWindow( nModRefDlgId );
205 if ( pChildWnd )
207 IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetWindow());
208 assert(pRefDlg);
209 if(pRefDlg)
211 pRefDlg->ViewShellChanged();
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)
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)
224 ContextChangeEventMultiplexer::NotifyContextChange(
225 GetController(),
226 ::sfx2::sidebar::EnumContext::Context_Default);
229 void ScTabViewShell::Deactivate(bool bMDI)
231 HideTip();
233 ScDocument* pDoc=GetViewData()->GetDocument();
235 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
237 if(pChanges!=NULL)
239 Link aLink;
240 pChanges->SetModifiedLink(aLink);
243 SfxViewShell::Deactivate(bMDI);
244 bIsActive = false;
245 ScInputHandler* pHdl = SC_MOD()->GetInputHdl(this);
247 if( bMDI )
249 // during shell deactivation, shells must not be switched, or the loop
250 // through the shell stack (in SfxDispatcher::DoDeactivate_Impl) will not work
251 bool bOldDontSwitch = bDontSwitch;
252 bDontSwitch = true;
254 DeActivateOlk( GetViewData() );
255 ActivateView( false, false );
257 if ( GetViewFrame()->GetFrame().IsInPlace() ) // inplace
258 GetViewData()->GetDocShell()->UpdateOle(GetViewData(), true);
260 if ( pHdl )
261 pHdl->NotifyChange( NULL, true ); // Timer-verzoegert wg. Dokumentwechsel
263 if (pScActiveViewShell == this)
264 pScActiveViewShell = NULL;
266 bDontSwitch = bOldDontSwitch;
268 else
270 HideNoteMarker(); // Notiz-Anzeige
272 if ( pHdl )
273 pHdl->HideTip(); // Formel-AutoEingabe-Tip abschalten
277 void ScTabViewShell::SetActive()
279 // Die Sfx-View moechte sich gerne selbst aktivieren, weil dabei noch
280 // magische Dinge geschehen (z.B. stuerzt sonst evtl. der Gestalter ab)
281 ActiveGrabFocus();
284 bool ScTabViewShell::PrepareClose(bool bUI)
286 // Call EnterHandler even in formula mode here,
287 // so a formula change in an embedded object isn't lost
288 // (ScDocShell::PrepareClose isn't called then).
289 ScInputHandler* pHdl = SC_MOD()->GetInputHdl( this );
290 if ( pHdl && pHdl->IsInputMode() )
291 pHdl->EnterHandler();
293 // draw text edit mode must be closed
294 FuPoor* pPoor = GetDrawFuncPtr();
295 if ( pPoor && ( IsDrawTextShell() || pPoor->GetSlotID() == SID_DRAW_NOTEEDIT ) )
297 // "clean" end of text edit, including note handling, subshells and draw func switching,
298 // as in FuDraw and ScTabView::DrawDeselectAll
299 GetViewData()->GetDispatcher().Execute( pPoor->GetSlotID(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
301 ScDrawView* pDrView = GetScDrawView();
302 if ( pDrView )
304 // force end of text edit, to be safe
305 // ScEndTextEdit must always be used, to ensure correct UndoManager
306 pDrView->ScEndTextEdit();
309 if ( pFormShell )
311 bool nRet = pFormShell->PrepareClose(bUI);
312 if (!nRet)
313 return nRet;
315 return SfxViewShell::PrepareClose(bUI);
318 // Zoom fuer In-Place berechnen
319 // aus Verhaeltnis von VisArea und Fenstergroesse des GridWin
321 void ScTabViewShell::UpdateOleZoom()
323 ScDocShell* pDocSh = GetViewData()->GetDocShell();
324 if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
326 //TODO/LATER: is there a difference between the two GetVisArea methods?
327 Size aObjSize = ((const SfxObjectShell*)pDocSh)->GetVisArea().GetSize();
328 if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
330 Window* pWin = GetActiveWin();
331 Size aWinHMM = pWin->PixelToLogic( pWin->GetOutputSizePixel(), MAP_100TH_MM );
332 SetZoomFactor( Fraction( aWinHMM.Width(),aObjSize.Width() ),
333 Fraction( aWinHMM.Height(),aObjSize.Height() ) );
338 void ScTabViewShell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
340 OuterResizePixel( rPos, rSize );
343 void ScTabViewShell::InnerResizePixel( const Point &rOfs, const Size &rSize )
345 Size aNewSize( rSize );
346 if ( GetViewFrame()->GetFrame().IsInPlace() )
348 SvBorder aBorder;
349 GetBorderSize( aBorder, rSize );
350 SetBorderPixel( aBorder );
352 Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
354 Size aSize( rSize );
355 aSize.Width() -= (aBorder.Left() + aBorder.Right());
356 aSize.Height() -= (aBorder.Top() + aBorder.Bottom());
358 if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
360 Size aLogicSize = GetWindow()->PixelToLogic( aSize, MAP_100TH_MM );
361 SfxViewShell::SetZoomFactor( Fraction( aLogicSize.Width(),aObjSize.Width() ),
362 Fraction( aLogicSize.Height(),aObjSize.Height() ) );
365 Point aPos( rOfs );
366 aPos.X() += aBorder.Left();
367 aPos.Y() += aBorder.Top();
368 GetWindow()->SetPosSizePixel( aPos, aSize );
370 else
372 SvBorder aBorder;
373 GetBorderSize( aBorder, rSize );
374 SetBorderPixel( aBorder );
375 aNewSize.Width() += aBorder.Left() + aBorder.Right();
376 aNewSize.Height() += aBorder.Top() + aBorder.Bottom();
379 DoResize( rOfs, aNewSize, true ); // rSize = Groesse von gridwin
381 UpdateOleZoom(); // Zoom fuer In-Place berechnen
383 GetViewData()->GetDocShell()->SetDocumentModified();
386 void ScTabViewShell::OuterResizePixel( const Point &rOfs, const Size &rSize )
388 SvBorder aBorder;
389 GetBorderSize( aBorder, rSize );
390 SetBorderPixel( aBorder );
392 DoResize( rOfs, rSize ); // Position und Groesse von tabview wie uebergeben
394 // ForceMove als Ersatz fuer den Sfx-Move-Mechanismus
395 // (aWinPos muss aktuell gehalten werden, damit ForceMove beim Ole-Deaktivieren klappt)
397 ForceMove();
400 void ScTabViewShell::SetZoomFactor( const Fraction &rZoomX, const Fraction &rZoomY )
402 // fuer OLE...
404 Fraction aFrac20( 1,5 );
405 Fraction aFrac400( 4,1 );
407 Fraction aNewX( rZoomX );
408 if ( aNewX < aFrac20 )
409 aNewX = aFrac20;
410 if ( aNewX > aFrac400 )
411 aNewX = aFrac400;
412 Fraction aNewY( rZoomY );
413 if ( aNewY < aFrac20 )
414 aNewY = aFrac20;
415 if ( aNewY > aFrac400 )
416 aNewY = aFrac400;
418 GetViewData()->UpdateScreenZoom( aNewX, aNewY );
419 SetZoom( aNewX, aNewY, true );
421 PaintGrid();
422 PaintTop();
423 PaintLeft();
425 SfxViewShell::SetZoomFactor( rZoomX, rZoomY );
428 void ScTabViewShell::QueryObjAreaPixel( Rectangle& rRect ) const
430 // auf ganze Zellen anpassen (in 1/100 mm)
432 Size aPixelSize = rRect.GetSize();
433 Window* pWin = ((ScTabViewShell*)this)->GetActiveWin();
434 Size aLogicSize = pWin->PixelToLogic( aPixelSize );
436 const ScViewData* pViewData = GetViewData();
437 ScDocument* pDoc = pViewData->GetDocument();
438 ScSplitPos ePos = pViewData->GetActivePart();
439 SCCOL nCol = pViewData->GetPosX(WhichH(ePos));
440 SCROW nRow = pViewData->GetPosY(WhichV(ePos));
441 SCTAB nTab = pViewData->GetTabNo();
442 bool bNegativePage = pDoc->IsNegativePage( nTab );
444 Rectangle aLogicRect = pDoc->GetMMRect( nCol, nRow, nCol, nRow, nTab );
445 if ( bNegativePage )
447 // use right edge of aLogicRect, and aLogicSize
448 aLogicRect.Left() = aLogicRect.Right() - aLogicSize.Width() + 1; // Right() is set below
450 aLogicRect.SetSize( aLogicSize );
452 pViewData->GetDocShell()->SnapVisArea( aLogicRect );
454 rRect.SetSize( pWin->LogicToPixel( aLogicRect.GetSize() ) );
457 void ScTabViewShell::Move()
459 Point aNewPos = GetViewFrame()->GetWindow().OutputToScreenPixel(Point());
461 if (aNewPos != aWinPos)
463 StopMarking();
464 aWinPos = aNewPos;
468 void ScTabViewShell::ShowCursor(bool /* bOn */)
470 /*!!! ShowCursor wird nicht paarweise wie im gridwin gerufen.
471 Der CursorLockCount am Gridwin muss hier direkt auf 0 gesetzt werden
473 if (bOn)
474 ShowAllCursors();
475 else
476 HideAllCursors();
480 void ScTabViewShell::WriteUserData(OUString& rData, bool /* bBrowse */)
482 GetViewData()->WriteUserData(rData);
485 void ScTabViewShell::WriteUserDataSequence (uno::Sequence < beans::PropertyValue >& rSettings, bool /* bBrowse */ )
487 GetViewData()->WriteUserDataSequence (rSettings);
490 void ScTabViewShell::ReadUserData(const OUString& rData, bool /* bBrowse */)
492 if ( !GetViewData()->GetDocShell()->IsPreview() )
493 DoReadUserData( rData );
496 void ScTabViewShell::ReadUserDataSequence (const uno::Sequence < beans::PropertyValue >& rSettings, bool /* bBrowse */ )
498 if ( !GetViewData()->GetDocShell()->IsPreview() )
499 DoReadUserDataSequence( rSettings );
502 void ScTabViewShell::DoReadUserDataSequence( const uno::Sequence < beans::PropertyValue >& rSettings )
504 Window* pOldWin = GetActiveWin();
505 bool bFocus = pOldWin && pOldWin->HasFocus();
507 GetViewData()->ReadUserDataSequence(rSettings);
508 SetTabNo( GetViewData()->GetTabNo(), true );
510 if ( GetViewData()->IsPagebreakMode() )
511 SetCurSubShell( GetCurObjectSelectionType(), true );
513 Window* pNewWin = GetActiveWin();
514 if (pNewWin && pNewWin != pOldWin)
516 SetWindow( pNewWin ); //! ist diese ViewShell immer aktiv???
517 if (bFocus)
518 pNewWin->GrabFocus();
519 WindowChanged(); // Drawing-Layer (z.B. #56771#)
522 if (GetViewData()->GetHSplitMode() == SC_SPLIT_FIX ||
523 GetViewData()->GetVSplitMode() == SC_SPLIT_FIX)
525 InvalidateSplit();
528 ZoomChanged();
530 TestHintWindow();
532 //! if ViewData has more tables than document, remove tables in ViewData
535 void ScTabViewShell::AddOpenGLChartWindows()
537 #if 0
538 ScDocument* pDoc = GetViewData()->GetDocument();
539 ScGridWindow* pParentWindow = GetActiveWin();
541 std::vector<std::pair<uno::Reference<chart2::XChartDocument>, Rectangle> > aCharts = pDoc->GetAllCharts();
543 for(std::vector<std::pair<uno::Reference<chart2::XChartDocument>, Rectangle> >::iterator itr = aCharts.begin(),
544 itrEnd = aCharts.end(); itr != itrEnd; ++itr)
546 OpenGLWindow* pOpenGLWindow = new OpenGLWindow(pParentWindow);
547 pOpenGLWindow->Show(false);
548 Size aSize = itr->second.GetSize();
550 pOpenGLWindow->SetSizePixel(aSize);
551 Point aPos = itr->second.TopLeft();
552 pOpenGLWindow->SetPosPixel(aPos);
553 pParentWindow->AddChildWindow(pOpenGLWindow);
554 uno::Reference< chart2::X3DChartWindowProvider > x3DWindowProvider( itr->first, uno::UNO_QUERY_THROW );
555 sal_uInt64 nWindowPtr = reinterpret_cast<sal_uInt64>(pOpenGLWindow);
556 x3DWindowProvider->setWindow(nWindowPtr);
558 #endif
561 // DoReadUserData is also called from ctor when switching from print preview
563 void ScTabViewShell::DoReadUserData( const OUString& rData )
565 Window* pOldWin = GetActiveWin();
566 bool bFocus = pOldWin && pOldWin->HasFocus();
568 GetViewData()->ReadUserData(rData);
569 SetTabNo( GetViewData()->GetTabNo(), true );
571 if ( GetViewData()->IsPagebreakMode() )
572 SetCurSubShell( GetCurObjectSelectionType(), true );
574 Window* pNewWin = GetActiveWin();
575 if (pNewWin && pNewWin != pOldWin)
577 SetWindow( pNewWin ); //! ist diese ViewShell immer aktiv???
578 if (bFocus)
579 pNewWin->GrabFocus();
580 WindowChanged(); // Drawing-Layer (z.B. #56771#)
583 if (GetViewData()->GetHSplitMode() == SC_SPLIT_FIX ||
584 GetViewData()->GetVSplitMode() == SC_SPLIT_FIX)
586 InvalidateSplit();
589 ZoomChanged();
591 TestHintWindow();
593 //! if ViewData has more tables than document, remove tables in ViewData
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 = 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( 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 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, true );
680 void ScTabViewShell::SetDrawTextShell( 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( 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( 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( bool bActive )
741 bActiveDrawFormSh = bActive;
743 if(bActiveDrawFormSh)
744 SetCurSubShell(OST_DrawForm);
746 void ScTabViewShell::SetChartShell( bool bActive )
748 bActiveChartSh = bActive;
750 if(bActiveChartSh)
751 SetCurSubShell(OST_Chart);
754 void ScTabViewShell::SetGraphicShell( bool bActive )
756 bActiveGraphicSh = bActive;
758 if(bActiveGraphicSh)
759 SetCurSubShell(OST_Graphic);
762 void ScTabViewShell::SetMediaShell( bool bActive )
764 bActiveMediaSh = bActive;
766 if(bActiveMediaSh)
767 SetCurSubShell(OST_Media);
770 void ScTabViewShell::SetOleObjectShell( bool bActive )
772 bActiveOleObjectSh = bActive;
774 if(bActiveOleObjectSh)
775 SetCurSubShell(OST_OleObject);
776 else
777 SetCurSubShell(OST_Cell);
780 void ScTabViewShell::SetEditShell(EditView* pView, 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, 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 bool bPgBrk=pViewData->IsPagebreakMode();
813 if(bPgBrk && !pPageBreakShell)
815 pPageBreakShell = new ScPageBreakShell( this );
816 pPageBreakShell->SetRepeatTarget( &aTarget );
820 if ( eOST!=eCurOST || bForce )
822 bool bCellBrush = false; // "format paint brush" allowed for cells
823 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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( 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(), 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( 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 bool ScTabViewShell::IsDrawTextShell() const
1046 return ( pDrawTextShell && ( GetMySubShell() == pDrawTextShell ) );
1049 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 ScTabViewShell* ScTabViewShell::GetActiveViewShell()
1078 return PTR_CAST(ScTabViewShell,Current());
1081 SfxPrinter* ScTabViewShell::GetPrinter( bool bCreate )
1083 // Drucker ist immer da (wird fuer die FontListe schon beim Starten angelegt)
1084 return GetViewData()->GetDocShell()->GetPrinter(bCreate);
1087 sal_uInt16 ScTabViewShell::SetPrinter( SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool )
1089 return GetViewData()->GetDocShell()->SetPrinter( pNewPrinter, nDiffFlags );
1092 bool ScTabViewShell::HasPrintOptionsPage() const
1094 return true;
1097 SfxTabPage* ScTabViewShell::CreatePrintOptionsPage( Window *pParent, const SfxItemSet &rOptions )
1099 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1100 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1101 ::CreateTabPage ScTpPrintOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_PRINT );
1102 if ( ScTpPrintOptionsCreate )
1103 return (*ScTpPrintOptionsCreate)( pParent, rOptions);
1104 return 0;
1107 void ScTabViewShell::StopEditShell()
1109 if ( pEditShell != NULL && !bDontSwitch )
1110 SetEditShell(NULL, false );
1113 // close handler to ensure function of dialog:
1115 IMPL_LINK_NOARG(ScTabViewShell, SimpleRefClose)
1117 SfxInPlaceClient* pClient = GetIPClient();
1118 if ( pClient && pClient->IsObjectInPlaceActive() )
1120 // If range selection was started with an active embedded object,
1121 // switch back to original sheet (while the dialog is still open).
1123 SetTabNo( GetViewData()->GetRefTabNo() );
1126 ScSimpleRefDlgWrapper::SetAutoReOpen( true );
1127 return 0;
1130 // handlers to call UNO listeners:
1132 static ScTabViewObj* lcl_GetViewObj( ScTabViewShell& rShell )
1134 ScTabViewObj* pRet = NULL;
1135 SfxViewFrame* pViewFrame = rShell.GetViewFrame();
1136 if (pViewFrame)
1138 SfxFrame& rFrame = pViewFrame->GetFrame();
1139 uno::Reference<frame::XController> xController = rFrame.GetController();
1140 if (xController.is())
1141 pRet = ScTabViewObj::getImplementation( xController );
1143 return pRet;
1146 IMPL_LINK( ScTabViewShell, SimpleRefDone, OUString*, pResult )
1148 ScTabViewObj* pImpObj = lcl_GetViewObj( *this );
1149 if ( pImpObj && pResult )
1150 pImpObj->RangeSelDone( *pResult );
1151 return 0;
1154 IMPL_LINK( ScTabViewShell, SimpleRefAborted, OUString*, pResult )
1156 ScTabViewObj* pImpObj = lcl_GetViewObj( *this );
1157 if ( pImpObj && pResult )
1158 pImpObj->RangeSelAborted( *pResult );
1159 return 0;
1162 IMPL_LINK( ScTabViewShell, SimpleRefChange, OUString*, pResult )
1164 ScTabViewObj* pImpObj = lcl_GetViewObj( *this );
1165 if ( pImpObj && pResult )
1166 pImpObj->RangeSelChanged( *pResult );
1167 return 0;
1170 void ScTabViewShell::StartSimpleRefDialog(
1171 const OUString& rTitle, const OUString& rInitVal,
1172 bool bCloseOnButtonUp, bool bSingleCell, bool bMultiSelection )
1174 SfxViewFrame* pViewFrm = GetViewFrame();
1176 if ( GetActiveViewShell() != this )
1178 // #i18833# / #i34499# The API method can be called for a view that's not active.
1179 // Then the view has to be activated first, the same way as in Execute for SID_CURRENTDOC.
1180 // Can't use GrabFocus here, because it needs to take effect immediately.
1182 pViewFrm->GetFrame().Appear();
1185 sal_uInt16 nId = ScSimpleRefDlgWrapper::GetChildWindowId();
1187 SC_MOD()->SetRefDialog( nId, true, pViewFrm );
1189 ScSimpleRefDlgWrapper* pWnd = (ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
1190 if (pWnd)
1192 pWnd->SetCloseHdl( LINK( this, ScTabViewShell, SimpleRefClose ) );
1193 pWnd->SetUnoLinks( LINK( this, ScTabViewShell, SimpleRefDone ),
1194 LINK( this, ScTabViewShell, SimpleRefAborted ),
1195 LINK( this, ScTabViewShell, SimpleRefChange ) );
1196 pWnd->SetRefString( rInitVal );
1197 pWnd->SetFlags( bCloseOnButtonUp, bSingleCell, bMultiSelection );
1198 pWnd->SetAutoReOpen( false );
1199 Window* pWin = pWnd->GetWindow();
1200 pWin->SetText( rTitle );
1201 pWnd->StartRefInput();
1205 void ScTabViewShell::StopSimpleRefDialog()
1207 SfxViewFrame* pViewFrm = GetViewFrame();
1208 sal_uInt16 nId = ScSimpleRefDlgWrapper::GetChildWindowId();
1210 ScSimpleRefDlgWrapper* pWnd = (ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
1211 if (pWnd)
1213 Window* pWin = pWnd->GetWindow();
1214 if (pWin && pWin->IsSystemWindow())
1215 ((SystemWindow*)pWin)->Close(); // calls abort handler
1219 bool ScTabViewShell::TabKeyInput(const KeyEvent& rKEvt)
1221 ScModule* pScMod = SC_MOD();
1223 SfxViewFrame* pThisFrame = GetViewFrame();
1224 if ( pThisFrame->GetChildWindow( SID_OPENDLG_FUNCTION ) )
1225 return false;
1227 KeyCode aCode = rKEvt.GetKeyCode();
1228 bool bShift = aCode.IsShift();
1229 bool bControl = aCode.IsMod1();
1230 bool bAlt = aCode.IsMod2();
1231 sal_uInt16 nCode = aCode.GetCode();
1232 bool bUsed = false;
1233 bool bInPlace = pScMod->IsEditMode(); // Editengine bekommt alles
1234 bool bAnyEdit = pScMod->IsInputMode(); // nur Zeichen & Backspace
1235 bool bDraw = IsDrawTextEdit();
1237 HideNoteMarker(); // Notiz-Anzeige
1239 // don't do extra HideCursor/ShowCursor calls if EnterHandler will switch to a different sheet
1240 bool bOnRefSheet = ( GetViewData()->GetRefTabNo() == GetViewData()->GetTabNo() );
1241 bool bHideCursor = ( ( nCode == KEY_RETURN && bInPlace ) || nCode == KEY_TAB ) && bOnRefSheet;
1243 if (bHideCursor)
1244 HideAllCursors();
1246 ScDocument* pDoc = GetViewData()->GetDocument();
1247 if ( pDoc )
1248 pDoc->KeyInput( rKEvt ); // TimerDelays etc.
1250 if( bInPlace )
1252 bUsed = pScMod->InputKeyEvent( rKEvt ); // Eingabe
1253 if( !bUsed )
1254 bUsed = SfxViewShell::KeyInput( rKEvt ); // accelerators
1256 else if( bAnyEdit )
1258 bool bIsType = false;
1259 sal_uInt16 nModi = aCode.GetModifier();
1260 sal_uInt16 nGroup = aCode.GetGroup();
1262 if ( nGroup == KEYGROUP_NUM || nGroup == KEYGROUP_ALPHA || nGroup == 0 )
1263 if ( !bControl && !bAlt )
1264 bIsType = true;
1266 if ( nGroup == KEYGROUP_MISC )
1267 switch ( nCode )
1269 case KEY_RETURN:
1270 bIsType = bControl && !bAlt; // Control, Shift-Control-Return
1271 if ( !bIsType && nModi == 0 )
1273 // Will der InputHandler auch ein einfaches Return?
1275 ScInputHandler* pHdl = pScMod->GetInputHdl(this);
1276 bIsType = pHdl && pHdl->TakesReturn();
1278 break;
1279 case KEY_SPACE:
1280 bIsType = !bControl && !bAlt; // ohne Modifier oder Shift-Space
1281 break;
1282 case KEY_ESCAPE:
1283 bIsType = (nModi == 0); // nur ohne Modifier
1284 break;
1285 default:
1286 bIsType = true;
1289 if( bIsType )
1290 bUsed = pScMod->InputKeyEvent( rKEvt ); // Eingabe
1292 if( !bUsed )
1293 bUsed = SfxViewShell::KeyInput( rKEvt ); // accelerators
1295 if ( !bUsed && !bIsType && nCode != KEY_RETURN ) // Eingabe nochmal hinterher
1296 bUsed = pScMod->InputKeyEvent( rKEvt );
1298 else
1300 // Spezialfall: Copy/Cut bei Mehrfachselektion -> Fehlermeldung
1301 // (Slot ist disabled, SfxViewShell::KeyInput wuerde also kommentarlos verschluckt)
1302 KeyFuncType eFunc = aCode.GetFunction();
1303 if ( eFunc == KEYFUNC_CUT )
1305 ScRange aDummy;
1306 ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy );
1307 if (eMarkType != SC_MARK_SIMPLE)
1309 ErrorMessage(STR_NOMULTISELECT);
1310 bUsed = true;
1313 if (!bUsed)
1314 bUsed = SfxViewShell::KeyInput( rKEvt ); // accelerators
1316 // during inplace editing, some slots are handled by the
1317 // container app and are executed during Window::KeyInput.
1318 // -> don't pass keys to input handler that would be used there
1319 // but should call slots instead.
1320 bool bParent = ( GetViewFrame()->GetFrame().IsInPlace() && eFunc != KEYFUNC_DONTKNOW );
1322 if( !bUsed && !bDraw && nCode != KEY_RETURN && !bParent )
1323 bUsed = pScMod->InputKeyEvent( rKEvt, true ); // Eingabe
1326 if (!bInPlace && !bUsed && !bDraw)
1328 switch (nCode)
1330 case KEY_RETURN:
1332 bool bNormal = !bControl && !bAlt;
1333 if ( !bAnyEdit && bNormal )
1335 // je nach Optionen mit Enter in den Edit-Modus schalten
1337 const ScInputOptions& rOpt = pScMod->GetInputOptions();
1338 if ( rOpt.GetEnterEdit() )
1340 pScMod->SetInputMode( SC_INPUT_TABLE );
1341 bUsed = true;
1345 bool bEditReturn = bControl && !bShift; // An Edit-Engine weiter
1346 if ( !bUsed && !bEditReturn )
1348 if ( bOnRefSheet )
1349 HideAllCursors();
1351 sal_uInt8 nMode = SC_ENTER_NORMAL;
1352 if ( bShift && bControl )
1353 nMode = SC_ENTER_MATRIX;
1354 else if ( bAlt )
1355 nMode = SC_ENTER_BLOCK;
1356 pScMod->InputEnterHandler(nMode);
1358 if (nMode == SC_ENTER_NORMAL)
1360 if( bShift )
1361 GetViewData()->GetDispatcher().Execute( SID_CURSORENTERUP,
1362 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1363 else
1364 GetViewData()->GetDispatcher().Execute( SID_CURSORENTERDOWN,
1365 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1367 else
1368 UpdateInputHandler(true);
1370 if ( bOnRefSheet )
1371 ShowAllCursors();
1373 // hier kein UpdateInputHandler, weil bei Referenzeingabe auf ein
1374 // anderes Dokument diese ViewShell nicht die ist, auf der eingegeben
1375 // wird!
1377 bUsed = true;
1380 break;
1384 // Alt-Cursortasten hart codiert, weil Alt nicht konfigurierbar ist
1386 if ( !bUsed && bAlt && !bControl )
1388 sal_uInt16 nSlotId = 0;
1389 switch (nCode)
1391 case KEY_UP:
1392 ModifyCellSize( DIR_TOP, bShift );
1393 bUsed = true;
1394 break;
1395 case KEY_DOWN:
1396 ModifyCellSize( DIR_BOTTOM, bShift );
1397 bUsed = true;
1398 break;
1399 case KEY_LEFT:
1400 ModifyCellSize( DIR_LEFT, bShift );
1401 bUsed = true;
1402 break;
1403 case KEY_RIGHT:
1404 ModifyCellSize( DIR_RIGHT, bShift );
1405 bUsed = true;
1406 break;
1407 case KEY_PAGEUP:
1408 nSlotId = bShift ? SID_CURSORPAGELEFT_SEL : SID_CURSORPAGELEFT_;
1409 break;
1410 case KEY_PAGEDOWN:
1411 nSlotId = bShift ? SID_CURSORPAGERIGHT_SEL : SID_CURSORPAGERIGHT_;
1412 break;
1414 if ( nSlotId )
1416 GetViewData()->GetDispatcher().Execute( nSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1417 bUsed = true;
1421 // use Ctrl+Alt+Shift+arrow keys to move the cursor in cells
1422 // while keeping the last selection
1423 if ( !bUsed && bAlt && bControl && bShift)
1425 sal_uInt16 nSlotId = 0;
1426 switch (nCode)
1428 case KEY_UP:
1429 nSlotId = SID_CURSORUP;
1430 break;
1431 case KEY_DOWN:
1432 nSlotId = SID_CURSORDOWN;
1433 break;
1434 case KEY_LEFT:
1435 nSlotId = SID_CURSORLEFT;
1436 break;
1437 case KEY_RIGHT:
1438 nSlotId = SID_CURSORRIGHT;
1439 break;
1440 case KEY_PAGEUP:
1441 nSlotId = SID_CURSORPAGEUP;
1442 break;
1443 case KEY_PAGEDOWN:
1444 nSlotId = SID_CURSORPAGEDOWN;
1445 break;
1446 case KEY_HOME:
1447 nSlotId = SID_CURSORHOME;
1448 break;
1449 case KEY_END:
1450 nSlotId = SID_CURSOREND;
1451 break;
1452 default:
1453 nSlotId = 0;
1454 break;
1456 if ( nSlotId )
1458 sal_uInt16 nMode = GetLockedModifiers();
1459 LockModifiers(KEY_MOD1);
1460 GetViewData()->GetDispatcher().Execute( nSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1461 LockModifiers(nMode);
1462 bUsed = true;
1465 if (bHideCursor)
1466 ShowAllCursors();
1468 return bUsed;
1471 bool ScTabViewShell::SfxKeyInput(const KeyEvent& rKeyEvent)
1473 return SfxViewShell::KeyInput( rKeyEvent );
1476 bool ScTabViewShell::KeyInput( const KeyEvent &rKeyEvent )
1478 return TabKeyInput( rKeyEvent );
1481 #define __INIT_ScTabViewShell \
1482 eCurOST(OST_NONE), \
1483 nDrawSfxId(0), \
1484 nCtrlSfxId(USHRT_MAX), \
1485 nFormSfxId(USHRT_MAX), \
1486 pDrawShell(NULL), \
1487 pDrawTextShell(NULL), \
1488 pEditShell(NULL), \
1489 pPivotShell(NULL), \
1490 pAuditingShell(NULL), \
1491 pDrawFormShell(NULL), \
1492 pCellShell(NULL), \
1493 pOleObjectShell(NULL), \
1494 pChartShell(NULL), \
1495 pGraphicShell(NULL), \
1496 pMediaShell(NULL), \
1497 pPageBreakShell(NULL), \
1498 pExtrusionBarShell(NULL), \
1499 pFontworkBarShell(NULL), \
1500 pFormShell(NULL), \
1501 pInputHandler(NULL), \
1502 pCurFrameLine(NULL), \
1503 aTarget( this ), \
1504 pDialogDPObject(NULL), \
1505 pNavSettings(NULL), \
1506 bActiveDrawSh(false), \
1507 bActiveDrawTextSh(false), \
1508 bActivePivotSh(false), \
1509 bActiveAuditingSh(false), \
1510 bActiveDrawFormSh(false), \
1511 bActiveOleObjectSh(false), \
1512 bActiveChartSh(false), \
1513 bActiveGraphicSh(false), \
1514 bActiveMediaSh(false), \
1515 bActiveEditSh(false), \
1516 bFormShellAtTop(false), \
1517 bDontSwitch(false), \
1518 bInFormatDialog(false), \
1519 bPrintSelected(false), \
1520 bReadOnly(false), \
1521 pScSbxObject(NULL), \
1522 bChartAreaValid(false), \
1523 bForceFocusOnCurCell(false),\
1524 nCurRefDlgId(0), \
1525 pAccessibilityBroadcaster(NULL), \
1526 mbInSwitch(false)
1529 void ScTabViewShell::Construct( sal_uInt8 nForceDesignMode )
1531 SfxApplication* pSfxApp = SFX_APP();
1532 ScDocShell* pDocSh = GetViewData()->GetDocShell();
1533 ScDocument* pDoc = pDocSh->GetDocument();
1534 bReadOnly = pDocSh->IsReadOnly();
1535 bIsActive = false;
1537 EnableAutoSpell(pDoc->GetDocOptions().IsAutoSpell());
1539 SetName(OUString("View")); // fuer SBX
1540 Color aColBlack( COL_BLACK );
1541 SetPool( &SC_MOD()->GetPool() );
1542 SetWindow( GetActiveWin() );
1544 pCurFrameLine = new ::editeng::SvxBorderLine(&aColBlack, 20,
1545 table::BorderLineStyle::SOLID);
1546 pPivotSource = new ScArea;
1547 StartListening(*GetViewData()->GetDocShell(),true);
1548 StartListening(*GetViewFrame(),true);
1549 StartListening(*pSfxApp,true); // #i62045# #i62046# application is needed for Calc's own hints
1551 SfxViewFrame* pFirst = SfxViewFrame::GetFirst(pDocSh);
1552 bool bFirstView = !pFirst
1553 || (pFirst == GetViewFrame() && !SfxViewFrame::GetNext(*pFirst,pDocSh));
1555 if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1557 //TODO/LATER: is there a difference between the two GetVisArea methods?
1558 Rectangle aVisArea = ((const SfxObjectShell*)pDocSh)->GetVisArea();
1560 SCTAB nVisTab = pDoc->GetVisibleTab();
1561 if (!pDoc->HasTable(nVisTab))
1563 nVisTab = 0;
1564 pDoc->SetVisibleTab(nVisTab);
1566 SetTabNo( nVisTab );
1567 bool bNegativePage = pDoc->IsNegativePage( nVisTab );
1568 // show the right cells
1569 GetViewData()->SetScreenPos( bNegativePage ? aVisArea.TopRight() : aVisArea.TopLeft() );
1571 if ( GetViewFrame()->GetFrame().IsInPlace() ) // inplace
1573 pDocSh->SetInplace( true ); // schon so initialisiert
1574 if (pDoc->IsEmbedded())
1575 pDoc->ResetEmbedded(); // keine blaue Markierung
1577 else if ( bFirstView )
1579 pDocSh->SetInplace( false );
1580 GetViewData()->RefreshZoom(); // recalculate PPT
1581 if (!pDoc->IsEmbedded())
1582 pDoc->SetEmbedded( pDoc->GetVisibleTab(), aVisArea ); // VisArea markieren
1586 // ViewInputHandler
1587 // jeder Task hat neuerdings sein eigenes InputWindow,
1588 // darum muesste eigentlich entweder jeder Task seinen InputHandler bekommen,
1589 // oder das InputWindow muesste sich beim App-InputHandler anmelden, wenn der
1590 // Task aktiv wird, oder das InputWindow muesste sich den InputHandler selbst
1591 // anlegen (dann immer ueber das InputWindow suchen, und nur wenn das nicht da
1592 // ist, den InputHandler von der App nehmen).
1593 // Als Sofortloesung bekommt erstmal jede View ihren Inputhandler, das gibt
1594 // nur noch Probleme, wenn zwei Views in einem Task-Fenster sind.
1596 pInputHandler = new ScInputHandler;
1598 // Alte Version:
1599 // if ( !GetViewFrame()->ISA(SfxTopViewFrame) ) // OLE oder Plug-In
1600 // pInputHandler = new ScInputHandler;
1602 // FormShell vor MakeDrawView anlegen, damit die DrawView auf jeden Fall
1603 // an der FormShell angemeldet werden kann
1604 // Gepusht wird die FormShell im ersten Activate
1605 pFormShell = new FmFormShell(this);
1606 pFormShell->SetControlActivationHandler( LINK( this, ScTabViewShell, FormControlActivated ) );
1608 // DrawView darf nicht im TabView - ctor angelegt werden,
1609 // wenn die ViewShell noch nicht kostruiert ist...
1610 if (pDoc->GetDrawLayer())
1611 MakeDrawView( nForceDesignMode );
1612 ViewOptionsHasChanged(false); // legt auch evtl. DrawView an
1614 ::svl::IUndoManager* pMgr = pDocSh->GetUndoManager();
1615 SetUndoManager( pMgr );
1616 pFormShell->SetUndoManager( pMgr );
1617 if ( !pDoc->IsUndoEnabled() )
1619 pMgr->SetMaxUndoActionCount( 0 );
1621 SetRepeatTarget( &aTarget );
1622 pFormShell->SetRepeatTarget( &aTarget );
1623 SetHelpId( HID_SCSHELL_TABVWSH );
1625 if ( bFirstView ) // first view?
1627 pDoc->SetDocVisible( true ); // used when creating new sheets
1628 if ( pDocSh->IsEmpty() )
1630 // set first sheet's RTL flag (following will already be initialized because of SetDocVisible)
1631 pDoc->SetLayoutRTL( 0, ScGlobal::IsSystemRTL() );
1633 // append additional sheets (not for OLE object)
1634 if ( pDocSh->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
1636 // Get the customized initial tab count
1637 const ScDefaultsOptions& rOpt = SC_MOD()->GetDefaultsOptions();
1638 SCTAB nInitTabCount = rOpt.GetInitTabCount();
1640 for (SCTAB i=1; i<nInitTabCount; i++)
1641 pDoc->MakeTable(i,false);
1644 pDocSh->SetEmpty( false ); // #i6232# make sure this is done only once
1647 // ReadExtOptions is now in Activate
1649 // Link-Update nicht verschachteln
1650 if ( pDocSh->GetCreateMode() != SFX_CREATE_MODE_INTERNAL &&
1651 pDocSh->IsUpdateEnabled() ) // #105575#; update only in the first creation of the ViewShell
1653 // Check if there are any external data.
1654 bool bLink = pDoc->GetExternalRefManager()->hasExternalData();
1655 if (!bLink)
1657 // #i100042# sheet links can still exist independently from external formula references
1658 SCTAB nTabCount = pDoc->GetTableCount();
1659 for (SCTAB i=0; i<nTabCount && !bLink; i++)
1660 if (pDoc->IsLinked(i))
1661 bLink = true;
1663 if (!bLink)
1665 const sc::DocumentLinkManager& rMgr = pDoc->GetDocLinkManager();
1666 if (rMgr.hasDdeLinks() || pDoc->HasAreaLinks())
1667 bLink = true;
1669 if (bLink)
1671 if ( !pFirst )
1672 pFirst = GetViewFrame();
1674 if(SC_MOD()->GetCurRefDlgId()==0)
1676 pFirst->GetDispatcher()->Execute( SID_UPDATETABLINKS,
1677 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
1681 bool bReImport = false; // importierte Daten aktualisieren
1682 ScDBCollection* pDBColl = pDoc->GetDBCollection();
1683 if ( pDBColl )
1685 const ScDBCollection::NamedDBs& rDBs = pDBColl->getNamedDBs();
1686 ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin(), itrEnd = rDBs.end();
1687 for (; itr != itrEnd; ++itr)
1689 if (itr->IsStripData() && itr->HasImportParam() && !itr->HasImportSelection())
1691 bReImport = true;
1692 break;
1696 if (bReImport)
1698 if ( !pFirst )
1699 pFirst = GetViewFrame();
1700 if(SC_MOD()->GetCurRefDlgId()==0)
1702 pFirst->GetDispatcher()->Execute( SID_REIMPORT_AFTER_LOAD,
1703 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
1709 UpdateAutoFillMark();
1711 // ScDispatchProviderInterceptor registers itself in ctor
1712 xDisProvInterceptor = new ScDispatchProviderInterceptor( this );
1714 bFirstActivate = true; // NavigatorUpdate aufschieben bis Activate()
1716 // #105575#; update only in the first creation of the ViewShell
1717 pDocSh->SetUpdateEnabled(false);
1719 if ( GetViewFrame()->GetFrame().IsInPlace() )
1720 UpdateHeaderWidth(); // The implace activation requires headers to be calculated
1722 SvBorder aBorder;
1723 GetBorderSize( aBorder, Size() );
1724 SetBorderPixel( aBorder );
1730 ScTabViewShell::ScTabViewShell( SfxViewFrame* pViewFrame,
1731 SfxViewShell* pOldSh ) :
1732 SfxViewShell( pViewFrame, SFX_VIEW_CAN_PRINT | SFX_VIEW_HAS_PRINTOPTIONS ),
1733 ScDBFunc( &pViewFrame->GetWindow(), (ScDocShell&)*pViewFrame->GetObjectShell(), this ),
1734 __INIT_ScTabViewShell
1736 const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
1738 // if switching back from print preview,
1739 // restore the view settings that were active when creating the preview
1740 // ReadUserData must not happen from ctor, because the view's edit window
1741 // has to be shown by the sfx. ReadUserData is deferred until the first Activate call.
1742 // old DesignMode state from form layer must be restored, too
1744 sal_uInt8 nForceDesignMode = SC_FORCEMODE_NONE;
1745 if ( pOldSh && pOldSh->ISA( ScPreviewShell ) )
1747 ScPreviewShell* pPreviewShell = ((ScPreviewShell*)pOldSh);
1748 nForceDesignMode = pPreviewShell->GetSourceDesignMode();
1749 ScPreview* p = pPreviewShell->GetPreview();
1750 if (p)
1751 GetViewData()->GetMarkData().SetSelectedTabs(p->GetSelectedTabs());
1754 Construct( nForceDesignMode );
1756 if ( GetViewData()->GetDocShell()->IsPreview() )
1758 // preview for template dialog: always show whole page
1759 SetZoomType( SVX_ZOOM_WHOLEPAGE, true ); // zoom value is recalculated at next Resize
1761 else
1763 Fraction aFract( rAppOpt.GetZoom(), 100 );
1764 SetZoom( aFract, aFract, true );
1765 SetZoomType( rAppOpt.GetZoomType(), true );
1768 // make Controller known to SFX
1769 new ScTabViewObj( this );
1771 SetCurSubShell(OST_Cell);
1772 SvBorder aBorder;
1773 GetBorderSize( aBorder, Size() );
1774 SetBorderPixel( aBorder );
1776 // #114409#
1777 MakeDrawLayer();
1780 #undef __INIT_ScTabViewShell
1782 ScTabViewShell::~ScTabViewShell()
1784 ScDocShell* pDocSh = GetViewData()->GetDocShell();
1785 EndListening(*pDocSh);
1786 EndListening(*GetViewFrame());
1787 EndListening(*SFX_APP()); // #i62045# #i62046# needed now - SfxViewShell no longer does it
1789 SC_MOD()->ViewShellGone(this);
1791 RemoveSubShell(); // alle
1792 SetWindow(0);
1794 // alles auf NULL, falls aus dem TabView-dtor noch darauf zugegriffen wird
1795 //! (soll eigentlich nicht !??!?!)
1797 if (pInputHandler)
1798 pInputHandler->SetDocumentDisposing(true);
1800 DELETEZ(pFontworkBarShell);
1801 DELETEZ(pExtrusionBarShell);
1802 DELETEZ(pCellShell);
1803 DELETEZ(pPageBreakShell);
1804 DELETEZ(pDrawShell);
1805 DELETEZ(pDrawFormShell);
1806 DELETEZ(pOleObjectShell);
1807 DELETEZ(pChartShell);
1808 DELETEZ(pGraphicShell);
1809 DELETEZ(pMediaShell);
1810 DELETEZ(pDrawTextShell);
1811 DELETEZ(pEditShell);
1812 DELETEZ(pPivotShell);
1813 DELETEZ(pAuditingShell);
1814 DELETEZ(pCurFrameLine);
1815 DELETEZ(pInputHandler);
1816 DELETEZ(pPivotSource);
1817 DELETEZ(pDialogDPObject);
1818 DELETEZ(pNavSettings);
1820 DELETEZ(pFormShell);
1821 DELETEZ(pAccessibilityBroadcaster);
1824 void ScTabViewShell::SetDialogDPObject( const ScDPObject* pObj )
1826 delete pDialogDPObject;
1827 if (pObj)
1828 pDialogDPObject = new ScDPObject( *pObj );
1829 else
1830 pDialogDPObject = NULL;
1833 void ScTabViewShell::FillFieldData( ScHeaderFieldData& rData )
1835 ScDocShell* pDocShell = GetViewData()->GetDocShell();
1836 ScDocument* pDoc = pDocShell->GetDocument();
1837 SCTAB nTab = GetViewData()->GetTabNo();
1838 OUString aTmp;
1839 pDoc->GetName(nTab, aTmp);
1840 rData.aTabName = aTmp;
1842 if( pDocShell->getDocProperties()->getTitle().getLength() != 0 )
1843 rData.aTitle = pDocShell->getDocProperties()->getTitle();
1844 else
1845 rData.aTitle = pDocShell->GetTitle();
1847 const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject();
1848 rData.aLongDocName = rURLObj.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
1849 if ( !rData.aLongDocName.isEmpty() )
1850 rData.aShortDocName = rURLObj.GetName( INetURLObject::DECODE_UNAMBIGUOUS );
1851 else
1852 rData.aShortDocName = rData.aLongDocName = rData.aTitle;
1853 rData.nPageNo = 1;
1854 rData.nTotalPages = 99;
1856 // eNumType kennt der Dialog selber
1859 void ScTabViewShell::SetChartArea( const ScRangeListRef& rSource, const Rectangle& rDest )
1861 bChartAreaValid = true;
1862 aChartSource = rSource;
1863 aChartPos = rDest;
1864 nChartDestTab = GetViewData()->GetTabNo();
1867 bool ScTabViewShell::GetChartArea( ScRangeListRef& rSource, Rectangle& rDest, SCTAB& rTab ) const
1869 rSource = aChartSource;
1870 rDest = aChartPos;
1871 rTab = nChartDestTab;
1872 return bChartAreaValid;
1875 ScNavigatorSettings* ScTabViewShell::GetNavigatorSettings()
1877 if( !pNavSettings )
1878 pNavSettings = new ScNavigatorSettings;
1879 return pNavSettings;
1883 void ScTabViewShell::ExecTbx( SfxRequest& rReq )
1885 const SfxItemSet* pReqArgs = rReq.GetArgs();
1886 sal_uInt16 nSlot = rReq.GetSlot();
1887 const SfxPoolItem* pItem = NULL;
1888 if ( pReqArgs )
1889 pReqArgs->GetItemState( nSlot, true, &pItem );
1891 switch ( nSlot )
1893 case SID_TBXCTL_INSERT:
1894 if ( pItem )
1895 nInsertCtrlState = ((const SfxUInt16Item*)pItem)->GetValue();
1896 break;
1897 case SID_TBXCTL_INSCELLS:
1898 if ( pItem )
1899 nInsCellsCtrlState = ((const SfxUInt16Item*)pItem)->GetValue();
1900 break;
1901 case SID_TBXCTL_INSOBJ:
1902 if ( pItem )
1903 nInsObjCtrlState = ((const SfxUInt16Item*)pItem)->GetValue();
1904 break;
1905 default:
1906 OSL_FAIL("Slot im Wald");
1908 GetViewFrame()->GetBindings().Invalidate( nSlot );
1911 void ScTabViewShell::GetTbxState( SfxItemSet& rSet )
1913 rSet.Put( SfxUInt16Item( SID_TBXCTL_INSERT, nInsertCtrlState ) );
1914 rSet.Put( SfxUInt16Item( SID_TBXCTL_INSCELLS, nInsCellsCtrlState ) );
1916 // ohne installiertes Chart darf Chart nicht Default sein...
1917 if ( nInsObjCtrlState == SID_DRAW_CHART && !SvtModuleOptions().IsChart() )
1918 nInsObjCtrlState = SID_INSERT_OBJECT;
1920 rSet.Put( SfxUInt16Item( SID_TBXCTL_INSOBJ, nInsObjCtrlState ) );
1923 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */