Update ooo320-m1
[ooovba.git] / sd / source / ui / view / viewshel.cxx
blob9974f5829aa3ae50c7ab35c795514aef8a43d69a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewshel.cxx,v $
10 * $Revision: 1.71.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "ViewShell.hxx"
35 #include "ViewShellImplementation.hxx"
37 #ifndef _COM_SUN_STAR_EMBED_EMBEDSTATE_HPP_
38 #include <com/sun/star/embed/EmbedStates.hpp>
39 #endif
40 #include "ViewShellBase.hxx"
41 #include "ShellFactory.hxx"
42 #include "DrawController.hxx"
43 #include "LayerTabBar.hxx"
45 #include <sfx2/viewfrm.hxx>
46 #include <sfx2/bindings.hxx>
47 #include <sfx2/dispatch.hxx>
48 #ifndef _SCRBAR_HXX //autogen
49 #include <vcl/scrbar.hxx>
50 #endif
51 #include <svtools/eitem.hxx>
52 #include <svx/ruler.hxx>
53 #ifndef _SVXIDS_HXX
54 #include <svx/svxids.hrc>
55 #endif
56 #include <svx/fmshell.hxx>
57 #ifndef SD_WINDOW_UPDATER_HXX
58 #include "WindowUpdater.hxx"
59 #endif
60 #include "GraphicViewShell.hxx"
61 #include <sfx2/childwin.hxx>
62 #include <sdxfer.hxx>
63 #include "GraphicViewShell.hxx"
64 #include <sfx2/childwin.hxx>
66 #include "app.hrc"
67 #include "helpids.h"
68 #include "strings.hrc"
69 #include "res_bmp.hrc"
70 #include "OutlineView.hxx"
71 #include "Client.hxx"
72 #include "sdresid.hxx"
73 #include "DrawDocShell.hxx"
74 #include "slideshow.hxx"
75 #include "drawdoc.hxx"
76 #include "sdpage.hxx"
77 #include "zoomlist.hxx"
78 #include "FrameView.hxx"
79 #include "optsitem.hxx"
80 #include "BezierObjectBar.hxx"
81 #include "TextObjectBar.hxx"
82 #include "GraphicObjectBar.hxx"
83 #include "MediaObjectBar.hxx"
84 #include "ViewShellManager.hxx"
85 #include "FormShellManager.hxx"
86 #include <svx/fmshell.hxx>
87 #include <svx/dialogs.hrc>
88 #include <svx/extrusionbar.hxx>
89 #include <svx/fontworkbar.hxx>
90 #include <svx/svdoutl.hxx>
92 // #96090#
93 #include <svtools/slstitm.hxx>
94 #include <sfx2/request.hxx>
95 #include "SpellDialogChildWindow.hxx"
97 #include "Window.hxx"
98 #include "fupoor.hxx"
100 #ifndef SO2_DECL_SVINPLACEOBJECT_DEFINED
101 #define SO2_DECL_SVINPLACEOBJECT_DEFINED
102 SO2_DECL_REF(SvInPlaceObject)
103 #endif
105 namespace sd { namespace ui { namespace table {
106 extern SfxShell* CreateTableObjectBar( ViewShell& rShell, ::sd::View* pView );
107 } } }
109 using namespace ::com::sun::star;
110 using namespace ::com::sun::star::uno;
111 using namespace ::com::sun::star::presentation;
113 namespace {
115 class ViewShellObjectBarFactory
116 : public ::sd::ShellFactory<SfxShell>
118 public:
119 ViewShellObjectBarFactory (::sd::ViewShell& rViewShell);
120 virtual ~ViewShellObjectBarFactory (void);
121 virtual SfxShell* CreateShell (
122 ::sd::ShellId nId,
123 ::Window* pParentWindow,
124 ::sd::FrameView* pFrameView);
125 virtual void ReleaseShell (SfxShell* pShell);
126 private:
127 ::sd::ViewShell& mrViewShell;
128 /** This cache holds the already created object bars.
130 typedef ::std::map< ::sd::ShellId,SfxShell*> ShellCache;
131 ShellCache maShellCache;
135 } // end of anonymous namespace
138 namespace sd {
140 static const int DELTA_ZOOM = 10;
142 BOOL ViewShell::IsPageFlipMode(void) const
144 return this->ISA(DrawViewShell) && mpContentWindow.get() != NULL &&
145 mpContentWindow->GetVisibleHeight() >= 1.0;
148 SfxViewFrame* ViewShell::GetViewFrame (void) const
150 const SfxViewShell* pViewShell = GetViewShell();
151 if (pViewShell != NULL)
153 return pViewShell->GetViewFrame();
155 else
157 OSL_ASSERT (GetViewShell()!=NULL);
158 return NULL;
163 /*************************************************************************
165 |* SFX-Slotmap und Standardinterface deklarieren
167 \************************************************************************/
168 TYPEINIT1(ViewShell, SfxShell);
171 ViewShell::ViewShell( SfxViewFrame*, ::Window* pParentWindow, ViewShellBase& rViewShellBase, bool bAllowCenter)
172 : SfxShell(&rViewShellBase)
173 , mbCenterAllowed(bAllowCenter)
174 , mpParentWindow(pParentWindow)
176 construct();
179 ViewShell::ViewShell( SfxViewFrame*, ::Window* pParentWindow, const ViewShell& rShell)
180 : SfxShell(rShell.GetViewShell())
181 , mbCenterAllowed(rShell.mbCenterAllowed)
182 , mpParentWindow(pParentWindow)
184 construct();
187 ViewShell::~ViewShell()
189 // Keep the content window from accessing in its destructor the
190 // WindowUpdater.
191 mpContentWindow->SetViewShell(NULL);
193 delete mpZoomList;
195 mpLayerTabBar.reset();
197 if (mpImpl->mpSubShellFactory.get() != NULL)
198 GetViewShellBase().GetViewShellManager()->RemoveSubShellFactory(
199 this,mpImpl->mpSubShellFactory);
203 /*************************************************************************
205 |* gemeinsamer Initialiserungsanteil der beiden Konstruktoren
207 \************************************************************************/
209 void ViewShell::construct(void)
211 mbHasRulers = false;
212 mpActiveWindow = 0;
213 mpView = 0;
214 mpFrameView = 0;
215 mpZoomList = 0;
216 mbStartShowWithDialog = FALSE;
217 mnPrintedHandoutPageNum = 1;
218 mnPrintedHandoutPageCount = 0;
219 mpWindowUpdater.reset( new ::sd::WindowUpdater() );
220 mpImpl.reset(new Implementation(*this));
221 meShellType = ST_NONE;
223 OSL_ASSERT (GetViewShell()!=NULL);
225 if (IsMainViewShell())
226 GetDocSh()->Connect (this);
228 mpZoomList = new ZoomList( this );
230 mpContentWindow.reset(new ::sd::Window(GetParentWindow()));
231 SetActiveWindow (mpContentWindow.get());
233 GetParentWindow()->SetBackground (Wallpaper());
234 mpContentWindow->SetBackground (Wallpaper());
235 mpContentWindow->SetCenterAllowed(mbCenterAllowed);
236 mpContentWindow->SetViewShell(this);
237 mpContentWindow->SetPosSizePixel(
238 GetParentWindow()->GetPosPixel(),GetParentWindow()->GetSizePixel());
239 mpContentWindow->Show();
240 static_cast< ::Window*>(mpContentWindow.get())->Resize();
241 OSL_TRACE("content window has size %d %d",
242 mpContentWindow->GetSizePixel().Width(),
243 mpContentWindow->GetSizePixel().Height());
245 if ( ! GetDocSh()->IsPreview())
247 // Create scroll bars and the filler between the scroll bars.
248 mpHorizontalScrollBar.reset (new ScrollBar(GetParentWindow(), WinBits(WB_HSCROLL | WB_DRAG)));
249 mpHorizontalScrollBar->EnableRTL (FALSE);
250 mpHorizontalScrollBar->SetRange(Range(0, 32000));
251 mpHorizontalScrollBar->SetScrollHdl(LINK(this, ViewShell, HScrollHdl));
252 mpHorizontalScrollBar->Show();
254 mpVerticalScrollBar.reset (new ScrollBar(GetParentWindow(), WinBits(WB_VSCROLL | WB_DRAG)));
255 mpVerticalScrollBar->SetRange(Range(0, 32000));
256 mpVerticalScrollBar->SetScrollHdl(LINK(this, ViewShell, VScrollHdl));
257 mpVerticalScrollBar->Show();
258 maScrBarWH = Size(
259 mpVerticalScrollBar->GetSizePixel().Width(),
260 mpHorizontalScrollBar->GetSizePixel().Height());
262 mpScrollBarBox.reset(new ScrollBarBox(GetParentWindow(), WB_SIZEABLE));
263 mpScrollBarBox->Show();
266 String aName( RTL_CONSTASCII_USTRINGPARAM( "ViewShell" ));
267 SetName (aName);
269 GetDoc()->StartOnlineSpelling(FALSE);
271 mpWindowUpdater->SetViewShell (*this);
272 mpWindowUpdater->SetDocument (GetDoc());
274 // Re-initialize the spell dialog.
275 ::sd::SpellDialogChildWindow* pSpellDialog =
276 static_cast< ::sd::SpellDialogChildWindow*> (
277 GetViewFrame()->GetChildWindow (
278 ::sd::SpellDialogChildWindow::GetChildWindowId()));
279 if (pSpellDialog != NULL)
280 pSpellDialog->InvalidateSpellDialog();
282 // Register the sub shell factory.
283 mpImpl->mpSubShellFactory.reset(new ViewShellObjectBarFactory(*this));
284 GetViewShellBase().GetViewShellManager()->AddSubShellFactory(this,mpImpl->mpSubShellFactory);
286 GetParentWindow()->Show();
292 void ViewShell::Init (bool bIsMainViewShell)
294 mpImpl->mbIsInitialized = true;
295 SetIsMainViewShell(bIsMainViewShell);
296 if (bIsMainViewShell)
297 SetActiveWindow (mpContentWindow.get());
303 void ViewShell::Exit (void)
305 sd::View* pView = GetView();
306 if (pView!=NULL && pView->IsTextEdit())
308 pView->SdrEndTextEdit();
309 pView->UnmarkAll();
312 Deactivate (TRUE);
314 if (IsMainViewShell())
316 GetDocSh()->Disconnect(this);
319 SetIsMainViewShell(false);
325 /*************************************************************************
327 |* Aktivierung: Arbeitsfenster den Fokus zuweisen
329 \************************************************************************/
331 void ViewShell::Activate(BOOL bIsMDIActivate)
333 SfxShell::Activate(bIsMDIActivate);
335 // Laut MI darf keiner GrabFocus rufen, der nicht genau weiss von
336 // welchem Window der Focus gegrabt wird. Da Activate() vom SFX teilweise
337 // asynchron verschickt wird, kann es sein, dass ein falsches Window
338 // den Focus hat (#29682#):
339 //GetViewFrame()->GetWindow().GrabFocus();
341 if (mpHorizontalRuler.get() != NULL)
342 mpHorizontalRuler->SetActive(TRUE);
343 if (mpVerticalRuler.get() != NULL)
344 mpVerticalRuler->SetActive(TRUE);
346 if (bIsMDIActivate)
348 // Damit der Navigator auch einen aktuellen Status bekommt
349 SfxBoolItem aItem( SID_NAVIGATOR_INIT, TRUE );
350 if (GetDispatcher() != NULL)
351 GetDispatcher()->Execute(
352 SID_NAVIGATOR_INIT,
353 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
354 &aItem,
355 0L);
357 SfxViewShell* pViewShell = GetViewShell();
358 OSL_ASSERT (pViewShell!=NULL);
359 SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
360 rBindings.Invalidate( SID_3D_STATE, TRUE, FALSE );
362 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
363 if(xSlideShow.is() && xSlideShow->isRunning() )
365 xSlideShow->activate(GetViewShellBase());
367 if(HasCurrentFunction())
369 GetCurrentFunction()->Activate();
372 if(!GetDocSh()->IsUIActive())
373 UpdatePreview( GetActualPage(), TRUE );
375 //HMH::sd::View* pView = GetView();
377 //HMHif (pView)
378 //HMH{
379 //HMH pView->ShowMarkHdl();
380 //HMH}
383 ReadFrameViewData( mpFrameView );
385 if (IsMainViewShell())
386 GetDocSh()->Connect(this);
389 void ViewShell::UIActivating( SfxInPlaceClient* )
391 OSL_ASSERT (GetViewShell()!=NULL);
392 GetViewShellBase().GetToolBarManager()->ToolBarsDestroyed();
397 void ViewShell::UIDeactivated( SfxInPlaceClient* )
399 OSL_ASSERT (GetViewShell()!=NULL);
400 GetViewShellBase().GetToolBarManager()->ToolBarsDestroyed();
401 if ( GetDrawView() )
402 GetViewShellBase().GetToolBarManager()->SelectionHasChanged(*this, *GetDrawView());
405 /*************************************************************************
407 |* Deaktivierung
409 \************************************************************************/
411 void ViewShell::Deactivate(BOOL bIsMDIActivate)
413 // remove view from a still active drag'n'drop session
414 SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
416 if (IsMainViewShell())
417 GetDocSh()->Disconnect(this);
419 if( pDragTransferable )
420 pDragTransferable->SetView( NULL );
422 OSL_ASSERT (GetViewShell()!=NULL);
424 // View-Attribute an der FrameView merken
425 WriteFrameViewData();
427 if (bIsMDIActivate)
429 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
430 if(xSlideShow.is() && xSlideShow->isRunning() )
432 xSlideShow->deactivate(GetViewShellBase());
434 if(HasCurrentFunction())
436 GetCurrentFunction()->Deactivate();
440 if (mpHorizontalRuler.get() != NULL)
441 mpHorizontalRuler->SetActive(FALSE);
442 if (mpVerticalRuler.get() != NULL)
443 mpVerticalRuler->SetActive(FALSE);
445 SfxShell::Deactivate(bIsMDIActivate);
451 void ViewShell::Shutdown (void)
453 Exit ();
459 /*************************************************************************
461 |* Keyboard event
463 \************************************************************************/
465 BOOL ViewShell::KeyInput(const KeyEvent& rKEvt, ::sd::Window* pWin)
467 BOOL bReturn(FALSE);
469 if(pWin)
471 SetActiveWindow(pWin);
474 if(!bReturn)
476 // #76008#
477 // give key input first to SfxViewShell to give CTRL+Key
478 // (e.g. CTRL+SHIFT+'+', to front) priority.
479 OSL_ASSERT (GetViewShell()!=NULL);
480 bReturn = (BOOL)GetViewShell()->KeyInput(rKEvt);
483 if(!bReturn)
485 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
486 if(xSlideShow.is() && xSlideShow->isRunning())
488 bReturn = xSlideShow->keyInput(rKEvt);
490 else
492 bool bConsumed = false;
493 if( GetView() )
494 bConsumed = GetView()->getSmartTags().KeyInput(rKEvt);
497 if( !bConsumed )
499 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
500 if( !xSelectionController.is() || !xSelectionController->onKeyInput( rKEvt, pWin ) )
502 if(HasCurrentFunction())
503 bReturn = GetCurrentFunction()->KeyInput(rKEvt);
505 else
507 bReturn = TRUE;
513 if(!bReturn && GetActiveWindow())
515 KeyCode aKeyCode = rKEvt.GetKeyCode();
517 if (aKeyCode.IsMod1() && aKeyCode.IsShift()
518 && aKeyCode.GetCode() == KEY_R)
520 InvalidateWindows();
521 bReturn = TRUE;
525 return(bReturn);
528 /*************************************************************************
530 |* MouseButtonDown event
532 \************************************************************************/
534 void ViewShell::MouseButtonDown(const MouseEvent& rMEvt, ::sd::Window* pWin)
536 // We have to lock tool bar updates while the mouse button is pressed in
537 // order to prevent the shape under the mouse to be moved (this happens
538 // when the number of docked tool bars changes as result of a changed
539 // selection; this changes the window size and thus the mouse position
540 // in model coordinates: with respect to model coordinates the mouse
541 // moves.)
542 OSL_ASSERT(mpImpl->mpUpdateLockForMouse.expired());
543 mpImpl->mpUpdateLockForMouse = ViewShell::Implementation::ToolBarManagerLock::Create(
544 GetViewShellBase().GetToolBarManager());
546 if ( pWin && !pWin->HasFocus() )
548 pWin->GrabFocus();
549 SetActiveWindow(pWin);
550 // GetViewFrame()->GetWindow().GrabFocus();
553 // MouseEvent in E3dView eintragen
554 if (GetView() != NULL)
555 GetView()->SetMouseEvent(rMEvt);
557 bool bConsumed = false;
558 if( GetView() )
559 bConsumed = GetView()->getSmartTags().MouseButtonDown( rMEvt );
561 if( !bConsumed )
563 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
564 if( !xSelectionController.is() || !xSelectionController->onMouseButtonDown( rMEvt, pWin ) )
566 if(HasCurrentFunction())
568 GetCurrentFunction()->MouseButtonDown(rMEvt);
574 /*************************************************************************
576 |* MouseMove event
578 \************************************************************************/
580 void ViewShell::MouseMove(const MouseEvent& rMEvt, ::sd::Window* pWin)
582 if (rMEvt.IsLeaveWindow())
584 if ( ! mpImpl->mpUpdateLockForMouse.expired())
586 ::boost::shared_ptr<ViewShell::Implementation::ToolBarManagerLock> pLock(
587 mpImpl->mpUpdateLockForMouse);
588 if (pLock.get() != NULL)
589 pLock->Release();
593 if ( pWin )
595 SetActiveWindow(pWin);
598 // MouseEvent in E3dView eintragen
599 if (GetView() != NULL)
600 GetView()->SetMouseEvent(rMEvt);
602 if(HasCurrentFunction())
604 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
605 if( !xSelectionController.is() || !xSelectionController->onMouseMove( rMEvt, pWin ) )
607 if(HasCurrentFunction())
608 GetCurrentFunction()->MouseMove(rMEvt);
613 /*************************************************************************
615 |* MouseButtonUp event
617 \************************************************************************/
619 void ViewShell::MouseButtonUp(const MouseEvent& rMEvt, ::sd::Window* pWin)
621 if ( pWin )
623 SetActiveWindow(pWin);
626 // MouseEvent in E3dView eintragen
627 if (GetView() != NULL)
628 GetView()->SetMouseEvent(rMEvt);
630 if( HasCurrentFunction())
632 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
633 if( !xSelectionController.is() || !xSelectionController->onMouseButtonUp( rMEvt, pWin ) )
635 if(HasCurrentFunction())
636 GetCurrentFunction()->MouseButtonUp(rMEvt);
640 if ( ! mpImpl->mpUpdateLockForMouse.expired())
642 ::boost::shared_ptr<ViewShell::Implementation::ToolBarManagerLock> pLock(
643 mpImpl->mpUpdateLockForMouse);
644 if (pLock.get() != NULL)
645 pLock->Release();
650 /*************************************************************************
652 |* Command event
654 \************************************************************************/
656 void ViewShell::Command(const CommandEvent& rCEvt, ::sd::Window* pWin)
658 BOOL bDone = HandleScrollCommand (rCEvt, pWin);
660 if( !bDone )
662 if( rCEvt.GetCommand() == COMMAND_INPUTLANGUAGECHANGE )
664 //#i42732# update state of fontname if input language changes
665 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_CHAR_FONT );
666 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
668 else
670 bool bConsumed = false;
671 if( GetView() )
673 bConsumed = GetView()->getSmartTags().Command(rCEvt);
676 if( !bConsumed && HasCurrentFunction())
678 GetCurrentFunction()->Command(rCEvt);
684 long ViewShell::Notify(NotifyEvent& rNEvt, ::sd::Window* pWin)
686 // handle scroll commands when they arrived at child windows
687 long nRet = FALSE;
688 if( rNEvt.GetType() == EVENT_COMMAND )
690 // note: dynamic_cast is not possible as GetData() returns a void*
691 CommandEvent* pCmdEvent = reinterpret_cast< CommandEvent* >(rNEvt.GetData());
692 nRet = HandleScrollCommand(*pCmdEvent, pWin);
694 return nRet;
698 BOOL ViewShell::HandleScrollCommand(const CommandEvent& rCEvt, ::sd::Window* pWin)
700 BOOL bDone = FALSE;
702 switch( rCEvt.GetCommand() )
704 case COMMAND_WHEEL:
706 Reference< XSlideShowController > xSlideShowController( SlideShow::GetSlideShowController(GetViewShellBase() ) );
707 if( xSlideShowController.is() )
709 // We ignore zooming with control+mouse wheel.
710 const CommandWheelData* pData = rCEvt.GetWheelData();
711 if( pData && !pData->GetModifier() && ( pData->GetMode() == COMMAND_WHEEL_SCROLL ) && !pData->IsHorz() )
713 long nDelta = pData->GetDelta();
714 if( nDelta > 0 )
716 xSlideShowController->gotoPreviousSlide();
718 else if( nDelta < 0 )
720 xSlideShowController->gotoNextEffect();
723 break;
726 // fall through when not running slideshow
727 case COMMAND_STARTAUTOSCROLL:
728 case COMMAND_AUTOSCROLL:
730 const CommandWheelData* pData = rCEvt.GetWheelData();
732 if (pData != NULL)
734 if (pData->IsMod1())
736 if( !GetDocSh()->IsUIActive() )
738 const long nOldZoom = GetActiveWindow()->GetZoom();
739 long nNewZoom;
741 if( pData->GetDelta() < 0L )
742 nNewZoom = Max( (long) pWin->GetMinZoom(), (long)(nOldZoom - DELTA_ZOOM) );
743 else
744 nNewZoom = Min( (long) pWin->GetMaxZoom(), (long)(nOldZoom + DELTA_ZOOM) );
746 SetZoom( nNewZoom );
747 Invalidate( SID_ATTR_ZOOM );
748 Invalidate( SID_ATTR_ZOOMSLIDER );
750 bDone = TRUE;
753 else
755 if( mpContentWindow.get() == pWin )
757 ULONG nScrollLines = pData->GetScrollLines();
758 if(IsPageFlipMode())
759 nScrollLines = COMMAND_WHEEL_PAGESCROLL;
760 CommandWheelData aWheelData( pData->GetDelta(),pData->GetNotchDelta(),
761 nScrollLines,pData->GetMode(),pData->GetModifier(),pData->IsHorz() );
762 CommandEvent aReWrite( rCEvt.GetMousePosPixel(),rCEvt.GetCommand(),
763 rCEvt.IsMouseEvent(),(const void *) &aWheelData );
764 bDone = pWin->HandleScrollCommand( aReWrite,
765 mpHorizontalScrollBar.get(),
766 mpVerticalScrollBar.get());
771 break;
773 default:
774 break;
777 return bDone;
782 void ViewShell::SetupRulers (void)
784 if(mbHasRulers && (mpContentWindow.get() != NULL) && !SlideShow::IsRunning(GetViewShellBase()))
786 long nHRulerOfs = 0;
788 if ( mpVerticalRuler.get() == NULL )
790 mpVerticalRuler.reset(CreateVRuler(GetActiveWindow()));
791 if ( mpVerticalRuler.get() != NULL )
793 nHRulerOfs = mpVerticalRuler->GetSizePixel().Width();
794 mpVerticalRuler->SetActive(TRUE);
795 mpVerticalRuler->Show();
798 if ( mpHorizontalRuler.get() == NULL )
800 mpHorizontalRuler.reset(CreateHRuler(GetActiveWindow(), TRUE));
801 if ( mpHorizontalRuler.get() != NULL )
803 mpHorizontalRuler->SetWinPos(nHRulerOfs);
804 mpHorizontalRuler->SetActive(TRUE);
805 mpHorizontalRuler->Show();
814 BOOL ViewShell::HasRuler (void)
816 return mbHasRulers;
822 void ViewShell::Resize (void)
824 SetupRulers ();
826 if (mpParentWindow == NULL)
827 return;
829 // Make sure that the new size is not degenerate.
830 const Size aSize (mpParentWindow->GetSizePixel());
831 if (aSize.Width()==0 || aSize.Height()==0)
832 return;
834 // Remember the new position and size.
835 maViewPos = Point(0,0); //mpParentWindow->GetPosPixel();
836 maViewSize = aSize;
838 // Rearrange the UI elements to take care of the new position and size.
839 ArrangeGUIElements ();
840 // end of included AdjustPosSizePixel.
842 Size aS (GetParentWindow()->GetOutputSizePixel());
843 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
844 Rectangle aVisArea = GetParentWindow()->PixelToLogic(
845 Rectangle( Point(0,0), aVisSizePixel));
846 Rectangle aCurrentVisArea (GetDocSh()->GetVisArea(ASPECT_CONTENT));
847 Rectangle aWindowRect = GetActiveWindow()->LogicToPixel(aCurrentVisArea);
848 if (GetDocSh()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED
849 && IsMainViewShell())
851 // GetDocSh()->SetVisArea(aVisArea);
854 // VisAreaChanged(aVisArea);
856 ::sd::View* pView = GetView();
858 if (pView)
860 pView->VisAreaChanged(GetActiveWindow());
864 SvBorder ViewShell::GetBorder (bool )
866 SvBorder aBorder;
868 // Horizontal scrollbar.
869 if (mpHorizontalScrollBar.get()!=NULL
870 && mpHorizontalScrollBar->IsVisible())
872 aBorder.Bottom() = maScrBarWH.Height();
875 // Vertical scrollbar.
876 if (mpVerticalScrollBar.get()!=NULL
877 && mpVerticalScrollBar->IsVisible())
879 aBorder.Right() = maScrBarWH.Width();
882 // Place horizontal ruler below tab bar.
883 if (mbHasRulers && mpContentWindow.get() != NULL)
885 SetupRulers();
886 if (mpHorizontalRuler.get() != NULL)
887 aBorder.Top() = mpHorizontalRuler->GetSizePixel().Height();
888 if (mpVerticalRuler.get() != NULL)
889 aBorder.Left() = mpVerticalRuler->GetSizePixel().Width();
892 return aBorder;
898 void ViewShell::ArrangeGUIElements (void)
900 if (mpImpl->mbArrangeActive)
901 return;
902 mpImpl->mbArrangeActive = true;
904 // Calculate border for in-place editing.
905 long nLeft = maViewPos.X();
906 long nTop = maViewPos.Y();
907 long nRight = maViewPos.X() + maViewSize.Width();
908 long nBottom = maViewPos.Y() + maViewSize.Height();
910 // Horizontal scrollbar.
911 if (mpHorizontalScrollBar.get()!=NULL
912 && mpHorizontalScrollBar->IsVisible())
914 int nLocalLeft = nLeft;
915 if (mpLayerTabBar.get()!=NULL && mpLayerTabBar->IsVisible())
916 nLocalLeft += mpLayerTabBar->GetSizePixel().Width();
917 nBottom -= maScrBarWH.Height();
918 mpHorizontalScrollBar->SetPosSizePixel (
919 Point(nLocalLeft,nBottom),
920 Size(nRight-nLocalLeft-maScrBarWH.Width(),maScrBarWH.Height()));
923 // Vertical scrollbar.
924 if (mpVerticalScrollBar.get()!=NULL
925 && mpVerticalScrollBar->IsVisible())
927 nRight -= maScrBarWH.Width();
928 mpVerticalScrollBar->SetPosSizePixel (
929 Point(nRight,nTop),
930 Size (maScrBarWH.Width(),nBottom-nTop));
933 // Filler in the lower right corner.
934 if (mpScrollBarBox.get() != NULL)
936 if (mpHorizontalScrollBar.get()!=NULL
937 && mpHorizontalScrollBar->IsVisible()
938 && mpVerticalScrollBar.get()!=NULL
939 && mpVerticalScrollBar->IsVisible())
941 mpScrollBarBox->Show();
942 mpScrollBarBox->SetPosSizePixel(Point(nRight, nBottom), maScrBarWH);
944 else
945 mpScrollBarBox->Hide();
948 // Place horizontal ruler below tab bar.
949 if (mbHasRulers && mpContentWindow.get() != NULL)
951 if (mpHorizontalRuler.get() != NULL)
953 Size aRulerSize = mpHorizontalRuler->GetSizePixel();
954 aRulerSize.Width() = nRight - nLeft;
955 mpHorizontalRuler->SetPosSizePixel (
956 Point(nLeft,nTop), aRulerSize);
957 if (mpVerticalRuler.get() != NULL)
958 mpHorizontalRuler->SetBorderPos(
959 mpVerticalRuler->GetSizePixel().Width()-1);
960 nTop += aRulerSize.Height();
962 if (mpVerticalRuler.get() != NULL)
964 Size aRulerSize = mpVerticalRuler->GetSizePixel();
965 aRulerSize.Height() = nBottom - nTop;
966 mpVerticalRuler->SetPosSizePixel (
967 Point (nLeft,nTop), aRulerSize);
968 nLeft += aRulerSize.Width();
972 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
974 // The size of the window of the center pane is set differently from
975 // that of the windows in the docking windows.
976 bool bSlideShowActive = (xSlideShow.is() && xSlideShow->isRunning()) && !xSlideShow->isFullScreen() && xSlideShow->getAnimationMode() == ANIMATIONMODE_SHOW;
977 if ( !bSlideShowActive)
979 OSL_ASSERT (GetViewShell()!=NULL);
981 mpContentWindow->SetPosSizePixel(
982 Point(nLeft,nTop),
983 Size(nRight-nLeft,nBottom-nTop));
986 // Windows in the center and rulers at the left and top side.
987 maAllWindowRectangle = Rectangle(
988 maViewPos,
989 Size(maViewSize.Width()-maScrBarWH.Width(),
990 maViewSize.Height()-maScrBarWH.Height()));
992 if (mpContentWindow.get() != NULL)
994 mpContentWindow->UpdateMapOrigin();
997 UpdateScrollBars();
999 mpImpl->mbArrangeActive = false;
1005 void ViewShell::SetUIUnit(FieldUnit eUnit)
1007 // Set unit at horizontal and vertical rulers.
1008 if (mpHorizontalRuler.get() != NULL)
1009 mpHorizontalRuler->SetUnit(eUnit);
1012 if (mpVerticalRuler.get() != NULL)
1013 mpVerticalRuler->SetUnit(eUnit);
1016 /*************************************************************************
1018 |* DefTab an den horizontalen Linealen setzen
1020 \************************************************************************/
1021 void ViewShell::SetDefTabHRuler( UINT16 nDefTab )
1023 if (mpHorizontalRuler.get() != NULL)
1024 mpHorizontalRuler->SetDefTabDist( nDefTab );
1030 /** Tell the FmFormShell that the view shell is closing. Give it the
1031 oportunity to prevent that.
1033 USHORT ViewShell::PrepareClose (BOOL bUI, BOOL bForBrowsing)
1035 USHORT nResult = TRUE;
1037 FmFormShell* pFormShell = GetViewShellBase().GetFormShellManager()->GetFormShell();
1038 if (pFormShell != NULL)
1039 nResult = pFormShell->PrepareClose (bUI, bForBrowsing);
1041 return nResult;
1047 void ViewShell::UpdatePreview (SdPage*, BOOL )
1049 // Do nothing. After the actual preview has been removed,
1050 // OutlineViewShell::UpdatePreview() is the place where something
1051 // usefull is still done.
1054 SfxUndoManager* ViewShell::ImpGetUndoManager (void) const
1056 const ViewShell* pMainViewShell = GetViewShellBase().GetMainViewShell().get();
1058 if( pMainViewShell == 0 )
1059 pMainViewShell = this;
1061 ::sd::View* pView = pMainViewShell->GetView();
1063 // check for text edit our outline view
1064 if( pView )
1066 if( pMainViewShell->GetShellType() == ViewShell::ST_OUTLINE )
1068 OutlineView* pOlView = dynamic_cast< OutlineView* >( pView );
1069 if( pOlView )
1071 ::Outliner* pOutl = pOlView->GetOutliner();
1072 if( pOutl )
1073 return &pOutl->GetUndoManager();
1076 else if( pView->IsTextEdit() )
1078 SdrOutliner* pOL = pView->GetTextEditOutliner();
1079 if( pOL )
1080 return &pOL->GetUndoManager();
1084 if( GetDocSh() )
1085 return GetDocSh()->GetUndoManager();
1087 return NULL;
1093 void ViewShell::ImpGetUndoStrings(SfxItemSet &rSet) const
1095 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1096 if(pUndoManager)
1098 sal_uInt16 nCount(pUndoManager->GetUndoActionCount());
1099 if(nCount)
1101 // prepare list
1102 List aStringList;
1103 sal_uInt16 a;
1105 for( a = 0; a < nCount; a++)
1107 // generate one String in list per undo step
1108 String* pInsertString = new String(pUndoManager->GetUndoActionComment(a));
1109 aStringList.Insert(pInsertString, LIST_APPEND);
1112 // set item
1113 rSet.Put(SfxStringListItem(SID_GETUNDOSTRINGS, &aStringList));
1115 // delete Strings again
1116 for(a = 0; a < nCount; a++)
1117 delete (String*)aStringList.GetObject(a);
1119 else
1121 rSet.DisableItem(SID_GETUNDOSTRINGS);
1126 // -----------------------------------------------------------------------------
1128 void ViewShell::ImpGetRedoStrings(SfxItemSet &rSet) const
1130 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1131 if(pUndoManager)
1133 sal_uInt16 nCount(pUndoManager->GetRedoActionCount());
1134 if(nCount)
1136 // prepare list
1137 List aStringList;
1138 sal_uInt16 a;
1140 for( a = 0; a < nCount; a++)
1142 // generate one String in list per undo step
1143 String* pInsertString = new String(pUndoManager->GetRedoActionComment(a));
1144 aStringList.Insert(pInsertString, LIST_APPEND);
1147 // set item
1148 rSet.Put(SfxStringListItem(SID_GETREDOSTRINGS, &aStringList));
1150 // delete Strings again
1151 for(a = 0; a < nCount; a++)
1152 delete (String*)aStringList.GetObject(a);
1154 else
1156 rSet.DisableItem(SID_GETREDOSTRINGS);
1161 // -----------------------------------------------------------------------------
1163 void ViewShell::ImpSidUndo(BOOL, SfxRequest& rReq)
1165 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1166 sal_uInt16 nNumber(1);
1167 const SfxItemSet* pReqArgs = rReq.GetArgs();
1169 if(pReqArgs)
1171 SfxUInt16Item* pUIntItem = (SfxUInt16Item*)&pReqArgs->Get(SID_UNDO);
1172 nNumber = pUIntItem->GetValue();
1175 if(nNumber && pUndoManager)
1177 sal_uInt16 nCount(pUndoManager->GetUndoActionCount());
1178 if(nCount >= nNumber)
1180 // #94637# when UndoStack is cleared by ModifyPageUndoAction
1181 // the nCount may have changed, so test GetUndoActionCount()
1182 while(nNumber-- && pUndoManager->GetUndoActionCount())
1184 pUndoManager->Undo();
1188 // #91081# refresh rulers, maybe UNDO was move of TAB marker in ruler
1189 if (mbHasRulers)
1191 Invalidate(SID_ATTR_TABSTOP);
1195 // This one is corresponding to the default handling
1196 // of SID_UNDO in sfx2
1197 GetViewFrame()->GetBindings().InvalidateAll(sal_False);
1199 rReq.Done();
1202 // -----------------------------------------------------------------------------
1204 void ViewShell::ImpSidRedo(BOOL, SfxRequest& rReq)
1206 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1207 sal_uInt16 nNumber(1);
1208 const SfxItemSet* pReqArgs = rReq.GetArgs();
1210 if(pReqArgs)
1212 SfxUInt16Item* pUIntItem = (SfxUInt16Item*)&pReqArgs->Get(SID_REDO);
1213 nNumber = pUIntItem->GetValue();
1216 if(nNumber && pUndoManager)
1218 sal_uInt16 nCount(pUndoManager->GetRedoActionCount());
1219 if(nCount >= nNumber)
1221 // #94637# when UndoStack is cleared by ModifyPageRedoAction
1222 // the nCount may have changed, so test GetRedoActionCount()
1223 while(nNumber-- && pUndoManager->GetRedoActionCount())
1225 pUndoManager->Redo();
1229 // #91081# refresh rulers, maybe REDO was move of TAB marker in ruler
1230 if (mbHasRulers)
1232 Invalidate(SID_ATTR_TABSTOP);
1236 // This one is corresponding to the default handling
1237 // of SID_UNDO in sfx2
1238 GetViewFrame()->GetBindings().InvalidateAll(sal_False);
1240 rReq.Done();
1243 // -----------------------------------------------------------------------------
1245 void ViewShell::ExecReq( SfxRequest& rReq )
1247 USHORT nSlot = rReq.GetSlot();
1248 switch( nSlot )
1250 case SID_MAIL_SCROLLBODY_PAGEDOWN:
1252 FunctionReference xFunc( GetCurrentFunction() );
1253 if( xFunc.is() )
1255 xFunc->ScrollStart();
1256 ScrollLines( 0, -1 );
1257 xFunc->ScrollEnd();
1260 rReq.Done();
1262 break;
1264 case SID_OUTPUT_QUALITY_COLOR:
1265 case SID_OUTPUT_QUALITY_GRAYSCALE:
1266 case SID_OUTPUT_QUALITY_BLACKWHITE:
1267 case SID_OUTPUT_QUALITY_CONTRAST:
1269 ULONG nMode = OUTPUT_DRAWMODE_COLOR;
1271 switch( nSlot )
1273 case SID_OUTPUT_QUALITY_COLOR: nMode = OUTPUT_DRAWMODE_COLOR; break;
1274 case SID_OUTPUT_QUALITY_GRAYSCALE: nMode = OUTPUT_DRAWMODE_GRAYSCALE; break;
1275 case SID_OUTPUT_QUALITY_BLACKWHITE: nMode = OUTPUT_DRAWMODE_BLACKWHITE; break;
1276 case SID_OUTPUT_QUALITY_CONTRAST: nMode = OUTPUT_DRAWMODE_CONTRAST; break;
1279 GetActiveWindow()->SetDrawMode( nMode );
1280 mpFrameView->SetDrawMode( nMode );
1281 // #110094#-7
1282 // GetView()->ReleaseMasterPagePaintCache();
1283 GetActiveWindow()->Invalidate();
1285 Invalidate();
1286 rReq.Done();
1287 break;
1295 /** This default implemenation returns only an empty reference. See derived
1296 classes for more interesting examples.
1298 ::com::sun::star::uno::Reference<
1299 ::com::sun::star::accessibility::XAccessible>
1300 ViewShell::CreateAccessibleDocumentView (::sd::Window* )
1302 return ::com::sun::star::uno::Reference<
1303 ::com::sun::star::accessibility::XAccessible> ();
1308 ::sd::WindowUpdater* ViewShell::GetWindowUpdater (void) const
1310 return mpWindowUpdater.get();
1316 ViewShellBase& ViewShell::GetViewShellBase (void) const
1318 return *static_cast<ViewShellBase*>(GetViewShell());
1324 ViewShell::ShellType ViewShell::GetShellType (void) const
1326 return meShellType;
1332 DrawDocShell* ViewShell::GetDocSh (void) const
1334 return GetViewShellBase().GetDocShell();
1340 SdDrawDocument* ViewShell::GetDoc (void) const
1342 return GetViewShellBase().GetDocument();
1345 ErrCode ViewShell::DoVerb (long )
1347 return ERRCODE_NONE;
1350 void ViewShell::SetCurrentFunction( const FunctionReference& xFunction)
1352 if( mxCurrentFunction.is() && (mxOldFunction != mxCurrentFunction) )
1353 mxCurrentFunction->Dispose();
1354 FunctionReference xTemp( mxCurrentFunction );
1355 mxCurrentFunction = xFunction;
1358 void ViewShell::SetOldFunction(const FunctionReference& xFunction)
1360 if( mxOldFunction.is() && (xFunction != mxOldFunction) && (mxCurrentFunction != mxOldFunction) )
1361 mxOldFunction->Dispose();
1363 FunctionReference xTemp( mxOldFunction );
1364 mxOldFunction = xFunction;
1367 /** this method deactivates the current function. If an old function is
1368 saved, this will become activated and current function.
1370 void ViewShell::Cancel()
1372 if(mxCurrentFunction.is() && (mxCurrentFunction != mxOldFunction ))
1374 FunctionReference xTemp( mxCurrentFunction );
1375 mxCurrentFunction.clear();
1376 xTemp->Deactivate();
1377 xTemp->Dispose();
1380 if(mxOldFunction.is())
1382 mxCurrentFunction = mxOldFunction;
1383 mxCurrentFunction->Activate();
1387 void ViewShell::DeactivateCurrentFunction( bool bPermanent /* == false */ )
1389 if( mxCurrentFunction.is() )
1391 if(bPermanent && (mxOldFunction == mxCurrentFunction))
1392 mxOldFunction.clear();
1394 mxCurrentFunction->Deactivate();
1395 if( mxCurrentFunction != mxOldFunction )
1396 mxCurrentFunction->Dispose();
1398 FunctionReference xTemp( mxCurrentFunction );
1399 mxCurrentFunction.clear();
1403 void ViewShell::DisposeFunctions()
1405 if(mxCurrentFunction.is())
1407 FunctionReference xTemp( mxCurrentFunction );
1408 mxCurrentFunction.clear();
1409 xTemp->Deactivate();
1410 xTemp->Dispose();
1413 if(mxOldFunction.is())
1415 FunctionReference xTemp( mxOldFunction );
1416 mxOldFunction->Dispose();
1417 mxOldFunction.clear();
1421 bool ViewShell::IsMainViewShell (void) const
1423 return mpImpl->mbIsMainViewShell;
1424 // return GetViewShellBase().GetMainViewShell() == this;
1427 void ViewShell::SetIsMainViewShell (bool bIsMainViewShell)
1429 if (bIsMainViewShell != mpImpl->mbIsMainViewShell)
1431 mpImpl->mbIsMainViewShell = bIsMainViewShell;
1432 if (bIsMainViewShell)
1434 GetDocSh()->Connect (this);
1436 else
1438 GetDocSh()->Disconnect (this);
1446 ::sd::Window* ViewShell::GetActiveWindow (void) const
1448 return mpActiveWindow;
1454 void ViewShell::PrePaint()
1461 void ViewShell::Paint (const Rectangle&, ::sd::Window* )
1468 void ViewShell::Draw(OutputDevice &, const Region &)
1475 ZoomList* ViewShell::GetZoomList (void)
1477 return mpZoomList;
1483 void ViewShell::ShowUIControls (bool bVisible)
1485 mpImpl->mbIsShowingUIControls = bVisible;
1487 if (mbHasRulers)
1489 if (mpHorizontalRuler.get() != NULL)
1490 mpHorizontalRuler->Show( bVisible );
1492 if (mpVerticalRuler.get() != NULL)
1493 mpVerticalRuler->Show( bVisible );
1496 if (mpVerticalScrollBar.get() != NULL)
1497 mpVerticalScrollBar->Show( bVisible );
1499 if (mpHorizontalScrollBar.get() != NULL)
1500 mpHorizontalScrollBar->Show( bVisible );
1502 if (mpScrollBarBox.get() != NULL)
1503 mpScrollBarBox->Show(bVisible);
1505 if (mpContentWindow.get() != NULL)
1506 mpContentWindow->Show( bVisible );
1513 bool ViewShell::RelocateToParentWindow (::Window* pParentWindow)
1515 mpParentWindow = pParentWindow;
1517 mpParentWindow->SetBackground (Wallpaper());
1519 if (mpContentWindow.get() != NULL)
1520 mpContentWindow->SetParent(pParentWindow);
1522 if (mpHorizontalScrollBar.get() != NULL)
1523 mpHorizontalScrollBar->SetParent(mpParentWindow);
1524 if (mpVerticalScrollBar.get() != NULL)
1525 mpVerticalScrollBar->SetParent(mpParentWindow);
1526 if (mpScrollBarBox.get() != NULL)
1527 mpScrollBarBox->SetParent(mpParentWindow);
1529 return true;
1534 } // end of namespace sd
1540 //===== ViewShellObjectBarFactory =============================================
1542 namespace {
1544 ViewShellObjectBarFactory::ViewShellObjectBarFactory (
1545 ::sd::ViewShell& rViewShell)
1546 : mrViewShell (rViewShell)
1553 ViewShellObjectBarFactory::~ViewShellObjectBarFactory (void)
1555 for (ShellCache::iterator aI(maShellCache.begin());
1556 aI!=maShellCache.end();
1557 aI++)
1559 delete aI->second;
1566 SfxShell* ViewShellObjectBarFactory::CreateShell (
1567 ::sd::ShellId nId,
1568 ::Window*,
1569 ::sd::FrameView* )
1571 SfxShell* pShell = NULL;
1573 ShellCache::iterator aI (maShellCache.find(nId));
1574 if (aI == maShellCache.end() || aI->second==NULL)
1576 ::sd::View* pView = mrViewShell.GetView();
1577 switch (nId)
1579 case RID_BEZIER_TOOLBOX:
1580 pShell = new ::sd::BezierObjectBar(&mrViewShell, pView);
1581 break;
1583 case RID_DRAW_TEXT_TOOLBOX:
1584 pShell = new ::sd::TextObjectBar(
1585 &mrViewShell, mrViewShell.GetDoc()->GetPool(), pView);
1586 break;
1588 case RID_DRAW_GRAF_TOOLBOX:
1589 pShell = new ::sd::GraphicObjectBar(&mrViewShell, pView);
1590 break;
1592 case RID_DRAW_MEDIA_TOOLBOX:
1593 pShell = new ::sd::MediaObjectBar(&mrViewShell, pView);
1594 break;
1596 case RID_DRAW_TABLE_TOOLBOX:
1597 pShell = ::sd::ui::table::CreateTableObjectBar( mrViewShell, pView );
1598 break;
1600 case RID_SVX_EXTRUSION_BAR:
1601 pShell = new ::svx::ExtrusionBar(
1602 &mrViewShell.GetViewShellBase());
1603 break;
1605 case RID_SVX_FONTWORK_BAR:
1606 pShell = new ::svx::FontworkBar(
1607 &mrViewShell.GetViewShellBase());
1608 break;
1610 default:
1611 pShell = NULL;
1612 break;
1615 else
1616 pShell = aI->second;
1618 return pShell;
1624 void ViewShellObjectBarFactory::ReleaseShell (SfxShell* pShell)
1626 if (pShell != NULL)
1627 delete pShell;
1630 } // end of anonymous namespace