bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / viewshel.cxx
blob51a049e4d66da652000f1493cf088402de8d721e
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 "ViewShell.hxx"
21 #include "ViewShellImplementation.hxx"
22 #include "createtableobjectbar.hxx"
24 #include <com/sun/star/embed/EmbedStates.hpp>
25 #include "ViewShellBase.hxx"
26 #include "ShellFactory.hxx"
27 #include "DrawController.hxx"
28 #include "LayerTabBar.hxx"
30 #include <sfx2/viewfrm.hxx>
31 #include <sfx2/bindings.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <vcl/scrbar.hxx>
34 #include <svl/eitem.hxx>
35 #include <svx/ruler.hxx>
36 #include <svx/svxids.hrc>
37 #include <svx/fmshell.hxx>
38 #include "WindowUpdater.hxx"
39 #include "GraphicViewShell.hxx"
40 #include <sfx2/childwin.hxx>
41 #include <sdxfer.hxx>
43 #include "app.hrc"
44 #include "helpids.h"
45 #include "strings.hrc"
46 #include "res_bmp.hrc"
47 #include "OutlineView.hxx"
48 #include "Client.hxx"
49 #include "sdresid.hxx"
50 #include "DrawDocShell.hxx"
51 #include "slideshow.hxx"
52 #include "drawdoc.hxx"
53 #include "sdpage.hxx"
54 #include "zoomlist.hxx"
55 #include "FrameView.hxx"
56 #include "optsitem.hxx"
57 #include "BezierObjectBar.hxx"
58 #include "TextObjectBar.hxx"
59 #include "GraphicObjectBar.hxx"
60 #include "MediaObjectBar.hxx"
61 #include "ViewShellManager.hxx"
62 #include "FormShellManager.hxx"
63 #include <svx/dialogs.hrc>
64 #include <svx/extrusionbar.hxx>
65 #include <svx/fontworkbar.hxx>
66 #include <svx/svdoutl.hxx>
67 #include <tools/diagnose_ex.h>
69 #include <svl/slstitm.hxx>
70 #include <sfx2/request.hxx>
71 #include "SpellDialogChildWindow.hxx"
73 #include <basegfx/tools/zoomtools.hxx>
75 #include "Window.hxx"
76 #include "fupoor.hxx"
78 #include <editeng/numitem.hxx>
79 #include <editeng/eeitem.hxx>
80 #include <editeng/editview.hxx>
81 #include <editeng/editeng.hxx>
82 #include <svl/poolitem.hxx>
83 #include <glob.hrc>
84 #include "AccessibleDocumentViewBase.hxx"
86 using namespace ::com::sun::star;
87 using namespace ::com::sun::star::uno;
88 using namespace ::com::sun::star::presentation;
90 namespace {
92 class ViewShellObjectBarFactory
93 : public ::sd::ShellFactory<SfxShell>
95 public:
96 ViewShellObjectBarFactory (::sd::ViewShell& rViewShell);
97 virtual ~ViewShellObjectBarFactory();
98 virtual SfxShell* CreateShell (
99 ::sd::ShellId nId,
100 vcl::Window* pParentWindow,
101 ::sd::FrameView* pFrameView) SAL_OVERRIDE;
102 virtual void ReleaseShell (SfxShell* pShell) SAL_OVERRIDE;
103 private:
104 ::sd::ViewShell& mrViewShell;
105 /** This cache holds the already created object bars.
107 typedef ::std::map< ::sd::ShellId,SfxShell*> ShellCache;
108 ShellCache maShellCache;
111 } // end of anonymous namespace
113 namespace sd {
115 bool ViewShell::IsPageFlipMode() const
117 return this->ISA(DrawViewShell) && mpContentWindow.get() != NULL &&
118 mpContentWindow->GetVisibleHeight() >= 1.0;
121 SfxViewFrame* ViewShell::GetViewFrame() const
123 const SfxViewShell* pViewShell = GetViewShell();
124 if (pViewShell != NULL)
126 return pViewShell->GetViewFrame();
128 else
130 OSL_ASSERT (GetViewShell()!=NULL);
131 return NULL;
135 /// declare SFX-Slotmap and standard interface
136 TYPEINIT1(ViewShell, SfxShell);
138 ViewShell::ViewShell( SfxViewFrame*, vcl::Window* pParentWindow, ViewShellBase& rViewShellBase, bool bAllowCenter)
139 : SfxShell(&rViewShellBase)
140 , mbCenterAllowed(bAllowCenter)
141 , mpParentWindow(pParentWindow)
143 construct();
146 ViewShell::~ViewShell()
148 // Keep the content window from accessing in its destructor the
149 // WindowUpdater.
150 if (mpContentWindow)
151 mpContentWindow->SetViewShell(NULL);
153 delete mpZoomList;
155 mpLayerTabBar.disposeAndClear();
157 if (mpImpl->mpSubShellFactory.get() != NULL)
158 GetViewShellBase().GetViewShellManager()->RemoveSubShellFactory(
159 this,mpImpl->mpSubShellFactory);
161 if (mpContentWindow)
163 SAL_INFO(
164 "sd.ui",
165 "destroying mpContentWindow at " << mpContentWindow.get()
166 << " with parent " << mpContentWindow->GetParent());
167 mpContentWindow.disposeAndClear();
170 mpScrollBarBox.disposeAndClear();
171 mpVerticalRuler.disposeAndClear();
172 mpHorizontalRuler.disposeAndClear();
173 mpVerticalScrollBar.disposeAndClear();
174 mpHorizontalScrollBar.disposeAndClear();
178 * common initialization part of both constructors
180 void ViewShell::construct()
182 mbHasRulers = false;
183 mpActiveWindow = 0;
184 mpView = 0;
185 mpFrameView = 0;
186 mpZoomList = 0;
187 mbStartShowWithDialog = false;
188 mnPrintedHandoutPageNum = 1;
189 mnPrintedHandoutPageCount = 0;
190 mpWindowUpdater.reset( new ::sd::WindowUpdater() );
191 mpImpl.reset(new Implementation(*this));
192 meShellType = ST_NONE;
194 OSL_ASSERT (GetViewShell()!=NULL);
196 if (IsMainViewShell())
197 GetDocSh()->Connect (this);
199 mpZoomList = new ZoomList( this );
201 mpContentWindow.reset(VclPtr< ::sd::Window >::Create(GetParentWindow()));
202 SetActiveWindow (mpContentWindow.get());
204 GetParentWindow()->SetBackground (Wallpaper());
205 mpContentWindow->SetBackground (Wallpaper());
206 mpContentWindow->SetCenterAllowed(mbCenterAllowed);
207 mpContentWindow->SetViewShell(this);
208 mpContentWindow->SetPosSizePixel(
209 GetParentWindow()->GetPosPixel(),GetParentWindow()->GetSizePixel());
211 if ( ! GetDocSh()->IsPreview())
213 // Create scroll bars and the filler between the scroll bars.
214 mpHorizontalScrollBar.reset (VclPtr<ScrollBar>::Create(GetParentWindow(), WinBits(WB_HSCROLL | WB_DRAG)));
215 mpHorizontalScrollBar->EnableRTL (false);
216 mpHorizontalScrollBar->SetRange(Range(0, 32000));
217 mpHorizontalScrollBar->SetScrollHdl(LINK(this, ViewShell, HScrollHdl));
219 mpVerticalScrollBar.reset (VclPtr<ScrollBar>::Create(GetParentWindow(), WinBits(WB_VSCROLL | WB_DRAG)));
220 mpVerticalScrollBar->SetRange(Range(0, 32000));
221 mpVerticalScrollBar->SetScrollHdl(LINK(this, ViewShell, VScrollHdl));
223 mpScrollBarBox.reset(VclPtr<ScrollBarBox>::Create(GetParentWindow(), WB_SIZEABLE));
226 OUString aName( "ViewShell" );
227 SetName (aName);
229 GetDoc()->StartOnlineSpelling(false);
231 mpWindowUpdater->SetViewShell (*this);
232 mpWindowUpdater->SetDocument (GetDoc());
234 // Re-initialize the spell dialog.
235 ::sd::SpellDialogChildWindow* pSpellDialog =
236 static_cast< ::sd::SpellDialogChildWindow*> (
237 GetViewFrame()->GetChildWindow (
238 ::sd::SpellDialogChildWindow::GetChildWindowId()));
239 if (pSpellDialog != NULL)
240 pSpellDialog->InvalidateSpellDialog();
242 // Register the sub shell factory.
243 mpImpl->mpSubShellFactory.reset(new ViewShellObjectBarFactory(*this));
244 GetViewShellBase().GetViewShellManager()->AddSubShellFactory(this,mpImpl->mpSubShellFactory);
247 void ViewShell::doShow()
249 mpContentWindow->Show();
250 static_cast< vcl::Window*>(mpContentWindow.get())->Resize();
251 SAL_INFO(
252 "sd.view",
253 "content window has size " << mpContentWindow->GetSizePixel().Width()
254 << " " << mpContentWindow->GetSizePixel().Height());
256 if ( ! GetDocSh()->IsPreview())
258 // Show scroll bars
259 mpHorizontalScrollBar->Show();
261 mpVerticalScrollBar->Show();
262 maScrBarWH = Size(
263 mpVerticalScrollBar->GetSizePixel().Width(),
264 mpHorizontalScrollBar->GetSizePixel().Height());
266 mpScrollBarBox->Show();
269 GetParentWindow()->Show();
272 void ViewShell::Init (bool bIsMainViewShell)
274 mpImpl->mbIsInitialized = true;
275 SetIsMainViewShell(bIsMainViewShell);
276 if (bIsMainViewShell)
277 SetActiveWindow (mpContentWindow.get());
280 void ViewShell::Exit()
282 sd::View* pView = GetView();
283 if (pView!=NULL && pView->IsTextEdit())
285 pView->SdrEndTextEdit();
286 pView->UnmarkAll();
289 Deactivate (true);
291 if (IsMainViewShell())
293 GetDocSh()->Disconnect(this);
296 SetIsMainViewShell(false);
300 * set focus to working window
302 void ViewShell::Activate(bool bIsMDIActivate)
304 // Do not forward to SfxShell::Activate()
306 /* According to MI, nobody is allowed to call GrabFocus, who does not
307 exactly know from which window the focus is grabbed. Since Activate()
308 is sent sometimes asynchronous, it can happen, that the wrong window
309 gets the focus. */
311 if (mpHorizontalRuler.get() != NULL)
312 mpHorizontalRuler->SetActive(true);
313 if (mpVerticalRuler.get() != NULL)
314 mpVerticalRuler->SetActive(true);
316 if (bIsMDIActivate)
318 // thus, the Navigator will also get a current status
319 SfxBoolItem aItem( SID_NAVIGATOR_INIT, true );
320 if (GetDispatcher() != NULL)
321 GetDispatcher()->Execute(
322 SID_NAVIGATOR_INIT,
323 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
324 &aItem,
325 0L);
327 SfxViewShell* pViewShell = GetViewShell();
328 OSL_ASSERT (pViewShell!=NULL);
329 SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
330 rBindings.Invalidate( SID_3D_STATE, true, false );
332 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
333 if(xSlideShow.is() && xSlideShow->isRunning() )
335 xSlideShow->activate(GetViewShellBase());
337 if(HasCurrentFunction())
339 GetCurrentFunction()->Activate();
342 if(!GetDocSh()->IsUIActive())
343 UpdatePreview( GetActualPage(), true );
347 ReadFrameViewData( mpFrameView );
349 if (IsMainViewShell())
350 GetDocSh()->Connect(this);
353 void ViewShell::UIActivating( SfxInPlaceClient* )
355 OSL_ASSERT (GetViewShell()!=NULL);
356 GetViewShellBase().GetToolBarManager()->ToolBarsDestroyed();
359 void ViewShell::UIDeactivated( SfxInPlaceClient* )
361 OSL_ASSERT (GetViewShell()!=NULL);
362 GetViewShellBase().GetToolBarManager()->ToolBarsDestroyed();
363 if ( GetDrawView() )
364 GetViewShellBase().GetToolBarManager()->SelectionHasChanged(*this, *GetDrawView());
367 void ViewShell::Deactivate(bool bIsMDIActivate)
369 // remove view from a still active drag'n'drop session
370 SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
372 if (IsMainViewShell())
373 GetDocSh()->Disconnect(this);
375 if( pDragTransferable )
376 pDragTransferable->SetView( NULL );
378 OSL_ASSERT (GetViewShell()!=NULL);
380 // remember view attributes of FrameView
381 WriteFrameViewData();
383 if (bIsMDIActivate)
385 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
386 if(xSlideShow.is() && xSlideShow->isRunning() )
388 xSlideShow->deactivate(GetViewShellBase());
390 if(HasCurrentFunction())
392 GetCurrentFunction()->Deactivate();
396 if (mpHorizontalRuler.get() != NULL)
397 mpHorizontalRuler->SetActive(false);
398 if (mpVerticalRuler.get() != NULL)
399 mpVerticalRuler->SetActive(false);
401 SfxShell::Deactivate(bIsMDIActivate);
404 void ViewShell::Shutdown()
406 Exit ();
409 bool ViewShell::KeyInput(const KeyEvent& rKEvt, ::sd::Window* pWin)
411 bool bReturn(false);
413 if(pWin)
415 SetActiveWindow(pWin);
418 if(!bReturn)
420 // give key input first to SfxViewShell to give CTRL+Key
421 // (e.g. CTRL+SHIFT+'+', to front) priority.
422 OSL_ASSERT (GetViewShell()!=NULL);
423 bReturn = GetViewShell()->KeyInput(rKEvt);
426 const size_t OriCount = GetView()->GetMarkedObjectList().GetMarkCount();
427 if(!bReturn)
429 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
430 if(xSlideShow.is() && xSlideShow->isRunning())
432 bReturn = xSlideShow->keyInput(rKEvt);
434 else
436 bool bConsumed = false;
437 if( GetView() )
438 bConsumed = GetView()->getSmartTags().KeyInput(rKEvt);
440 if( !bConsumed )
442 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
443 if( !xSelectionController.is() || !xSelectionController->onKeyInput( rKEvt, pWin ) )
445 if(HasCurrentFunction())
446 bReturn = GetCurrentFunction()->KeyInput(rKEvt);
448 else
450 bReturn = true;
455 const size_t EndCount = GetView()->GetMarkedObjectList().GetMarkCount();
456 // Here, oriCount or endCount must have one value=0, another value > 0, then to switch focus between Document and shape objects
457 if(bReturn && (OriCount + EndCount > 0) && (OriCount * EndCount == 0))
459 SwitchActiveViewFireFocus();
462 if(!bReturn && GetActiveWindow())
464 vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
466 if (aKeyCode.IsMod1() && aKeyCode.IsShift()
467 && aKeyCode.GetCode() == KEY_R)
469 InvalidateWindows();
470 bReturn = true;
474 return bReturn;
477 void ViewShell::MouseButtonDown(const MouseEvent& rMEvt, ::sd::Window* pWin)
479 // We have to lock tool bar updates while the mouse button is pressed in
480 // order to prevent the shape under the mouse to be moved (this happens
481 // when the number of docked tool bars changes as result of a changed
482 // selection; this changes the window size and thus the mouse position
483 // in model coordinates: with respect to model coordinates the mouse
484 // moves.)
485 OSL_ASSERT(mpImpl->mpUpdateLockForMouse.expired());
486 mpImpl->mpUpdateLockForMouse = ViewShell::Implementation::ToolBarManagerLock::Create(
487 GetViewShellBase().GetToolBarManager());
489 if ( pWin && !pWin->HasFocus() )
491 pWin->GrabFocus();
492 SetActiveWindow(pWin);
495 // insert MouseEvent into E3dView
496 if (GetView() != NULL)
497 GetView()->SetMouseEvent(rMEvt);
499 bool bConsumed = false;
500 if( GetView() )
501 bConsumed = GetView()->getSmartTags().MouseButtonDown( rMEvt );
503 if( !bConsumed )
505 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
506 if( !xSelectionController.is() || !xSelectionController->onMouseButtonDown( rMEvt, pWin ) )
508 if(HasCurrentFunction())
510 GetCurrentFunction()->MouseButtonDown(rMEvt);
516 void ViewShell::LogicMouseButtonDown(const MouseEvent& rMouseEvent)
518 // When we're not doing tiled rendering, then positions must be passed as pixels.
519 assert(GetDoc()->isTiledRendering());
521 Point aPoint = mpActiveWindow->GetPointerPosPixel();
522 mpActiveWindow->SetLastMousePos(rMouseEvent.GetPosPixel());
524 MouseButtonDown(rMouseEvent, 0);
526 mpActiveWindow->SetPointerPosPixel(aPoint);
529 void ViewShell::LogicMouseButtonUp(const MouseEvent& rMouseEvent)
531 // When we're not doing tiled rendering, then positions must be passed as pixels.
532 assert(GetDoc()->isTiledRendering());
534 Point aPoint = mpActiveWindow->GetPointerPosPixel();
535 mpActiveWindow->SetLastMousePos(rMouseEvent.GetPosPixel());
537 MouseButtonUp(rMouseEvent, 0);
539 mpActiveWindow->SetPointerPosPixel(aPoint);
542 void ViewShell::LogicMouseMove(const MouseEvent& rMouseEvent)
544 // When we're not doing tiled rendering, then positions must be passed as pixels.
545 assert(GetDoc()->isTiledRendering());
547 Point aPoint = mpActiveWindow->GetPointerPosPixel();
548 mpActiveWindow->SetLastMousePos(rMouseEvent.GetPosPixel());
550 MouseMove(rMouseEvent, 0);
552 mpActiveWindow->SetPointerPosPixel(aPoint);
555 void ViewShell::SetCursorMm100Position(const Point& rPosition, bool bPoint, bool bClearMark)
557 if (SdrView* pSdrView = GetView())
559 rtl::Reference<sdr::SelectionController> xSelectionController(GetView()->getSelectionController());
560 if (!xSelectionController.is() || !xSelectionController->setCursorLogicPosition(rPosition, bPoint))
562 if (pSdrView->GetTextEditObject())
564 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
565 rEditView.SetCursorLogicPosition(rPosition, bPoint, bClearMark);
571 OString ViewShell::GetTextSelection(const OString& _aMimeType, OString& rUsedMimeType)
573 SdrView* pSdrView = GetView();
574 if (!pSdrView)
575 return OString();
577 if (!pSdrView->GetTextEditObject())
578 return OString();
580 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
581 uno::Reference<datatransfer::XTransferable> xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
583 // Take care of UTF-8 text here.
584 bool bConvert = false;
585 sal_Int32 nIndex = 0;
586 OString aMimeType = _aMimeType;
587 if (aMimeType.getToken(0, ';', nIndex) == "text/plain")
589 if (aMimeType.getToken(0, ';', nIndex) == "charset=utf-8")
591 aMimeType = "text/plain;charset=utf-16";
592 bConvert = true;
596 datatransfer::DataFlavor aFlavor;
597 aFlavor.MimeType = OUString::fromUtf8(aMimeType.getStr());
598 if (aMimeType == "text/plain;charset=utf-16")
599 aFlavor.DataType = cppu::UnoType<OUString>::get();
600 else
601 aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::get();
603 if (!xTransferable->isDataFlavorSupported(aFlavor))
604 return OString();
606 uno::Any aAny(xTransferable->getTransferData(aFlavor));
608 OString aRet;
609 if (aFlavor.DataType == cppu::UnoType<OUString>::get())
611 OUString aString;
612 aAny >>= aString;
613 if (bConvert)
614 aRet = OUStringToOString(aString, RTL_TEXTENCODING_UTF8);
615 else
616 aRet = OString(reinterpret_cast<const sal_Char *>(aString.getStr()), aString.getLength() * sizeof(sal_Unicode));
618 else
620 uno::Sequence<sal_Int8> aSequence;
621 aAny >>= aSequence;
622 aRet = OString(reinterpret_cast<sal_Char*>(aSequence.getArray()), aSequence.getLength());
625 rUsedMimeType = _aMimeType;
626 return aRet;
629 void ViewShell::SetGraphicMm100Position(bool bStart, const Point& rPosition)
631 if (bStart)
633 MouseEvent aClickEvent(rPosition, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
634 MouseButtonDown(aClickEvent, 0);
635 MouseEvent aMoveEvent(Point(rPosition.getX(), rPosition.getY()), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT);
636 MouseMove(aMoveEvent, 0);
638 else
640 MouseEvent aMoveEvent(Point(rPosition.getX(), rPosition.getY()), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT);
641 MouseMove(aMoveEvent, 0);
642 MouseEvent aClickEvent(rPosition, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
643 MouseButtonUp(aClickEvent, 0);
647 void ViewShell::MouseMove(const MouseEvent& rMEvt, ::sd::Window* pWin)
649 if (rMEvt.IsLeaveWindow())
651 if ( ! mpImpl->mpUpdateLockForMouse.expired())
653 ::boost::shared_ptr<ViewShell::Implementation::ToolBarManagerLock> pLock(
654 mpImpl->mpUpdateLockForMouse);
655 if (pLock.get() != NULL)
656 pLock->Release();
660 if ( pWin )
662 SetActiveWindow(pWin);
665 // insert MouseEvent into E3dView
666 if (GetView() != NULL)
667 GetView()->SetMouseEvent(rMEvt);
669 if(HasCurrentFunction())
671 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
672 if( !xSelectionController.is() || !xSelectionController->onMouseMove( rMEvt, pWin ) )
674 if(HasCurrentFunction())
675 GetCurrentFunction()->MouseMove(rMEvt);
680 void ViewShell::MouseButtonUp(const MouseEvent& rMEvt, ::sd::Window* pWin)
682 if ( pWin )
684 SetActiveWindow(pWin);
687 // insert MouseEvent into E3dView
688 if (GetView() != NULL)
689 GetView()->SetMouseEvent(rMEvt);
691 if( HasCurrentFunction())
693 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
694 if( !xSelectionController.is() || !xSelectionController->onMouseButtonUp( rMEvt, pWin ) )
696 if(HasCurrentFunction())
697 GetCurrentFunction()->MouseButtonUp(rMEvt);
701 if ( ! mpImpl->mpUpdateLockForMouse.expired())
703 ::boost::shared_ptr<ViewShell::Implementation::ToolBarManagerLock> pLock(
704 mpImpl->mpUpdateLockForMouse);
705 if (pLock.get() != NULL)
706 pLock->Release();
710 void ViewShell::Command(const CommandEvent& rCEvt, ::sd::Window* pWin)
712 bool bDone = HandleScrollCommand (rCEvt, pWin);
714 if( !bDone )
716 if( rCEvt.GetCommand() == CommandEventId::InputLanguageChange )
718 //#i42732# update state of fontname if input language changes
719 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_CHAR_FONT );
720 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
722 else
724 bool bConsumed = false;
725 if( GetView() )
727 bConsumed = GetView()->getSmartTags().Command(rCEvt);
730 if( !bConsumed && HasCurrentFunction())
732 GetCurrentFunction()->Command(rCEvt);
738 bool ViewShell::Notify(NotifyEvent& rNEvt, ::sd::Window* pWin)
740 // handle scroll commands when they arrived at child windows
741 bool nRet = false;
742 if( rNEvt.GetType() == MouseNotifyEvent::COMMAND )
744 // note: dynamic_cast is not possible as GetData() returns a void*
745 CommandEvent* pCmdEvent = static_cast< CommandEvent* >(rNEvt.GetData());
746 nRet = HandleScrollCommand(*pCmdEvent, pWin);
748 return nRet;
751 bool ViewShell::HandleScrollCommand(const CommandEvent& rCEvt, ::sd::Window* pWin)
753 bool bDone = false;
755 switch( rCEvt.GetCommand() )
757 case CommandEventId::Swipe:
759 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
760 if (xSlideShow.is())
762 const CommandSwipeData* pSwipeData = rCEvt.GetSwipeData();
763 bDone = xSlideShow->swipe(*pSwipeData);
766 break;
767 case CommandEventId::LongPress:
769 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
770 if (xSlideShow.is())
772 const CommandLongPressData* pLongPressData = rCEvt.GetLongPressData();
773 bDone = xSlideShow->longpress(*pLongPressData);
776 break;
778 case CommandEventId::Wheel:
780 Reference< XSlideShowController > xSlideShowController( SlideShow::GetSlideShowController(GetViewShellBase() ) );
781 if( xSlideShowController.is() )
783 // We ignore zooming with control+mouse wheel.
784 const CommandWheelData* pData = rCEvt.GetWheelData();
785 if( pData && !pData->GetModifier() && ( pData->GetMode() == CommandWheelMode::SCROLL ) && !pData->IsHorz() )
787 long nDelta = pData->GetDelta();
788 if( nDelta > 0 )
790 xSlideShowController->gotoPreviousSlide();
792 else if( nDelta < 0 )
794 xSlideShowController->gotoNextEffect();
797 break;
800 // fall through when not running slideshow
801 case CommandEventId::StartAutoScroll:
802 case CommandEventId::AutoScroll:
804 const CommandWheelData* pData = rCEvt.GetWheelData();
806 if (pData != NULL)
808 if (pData->IsMod1())
810 if( !GetDocSh()->IsUIActive() )
812 const long nOldZoom = GetActiveWindow()->GetZoom();
813 long nNewZoom;
814 Point aOldMousePos = GetActiveWindow()->PixelToLogic(rCEvt.GetMousePosPixel());
816 if( pData->GetDelta() < 0L )
817 nNewZoom = std::max( (long) pWin->GetMinZoom(), basegfx::zoomtools::zoomOut( nOldZoom ));
818 else
819 nNewZoom = std::min( (long) pWin->GetMaxZoom(), basegfx::zoomtools::zoomIn( nOldZoom ));
821 SetZoom( nNewZoom );
822 // Keep mouse at same doc point before zoom
823 Point aNewMousePos = GetActiveWindow()->PixelToLogic(rCEvt.GetMousePosPixel());
824 SetWinViewPos(GetWinViewPos() - (aNewMousePos - aOldMousePos), true);
826 Invalidate( SID_ATTR_ZOOM );
827 Invalidate( SID_ATTR_ZOOMSLIDER );
829 bDone = true;
832 else
834 if( mpContentWindow.get() == pWin )
836 sal_uLong nScrollLines = pData->GetScrollLines();
837 if(IsPageFlipMode())
838 nScrollLines = COMMAND_WHEEL_PAGESCROLL;
839 CommandWheelData aWheelData( pData->GetDelta(),pData->GetNotchDelta(),
840 nScrollLines,pData->GetMode(),pData->GetModifier(),pData->IsHorz() );
841 CommandEvent aReWrite( rCEvt.GetMousePosPixel(),rCEvt.GetCommand(),
842 rCEvt.IsMouseEvent(),(const void *) &aWheelData );
843 bDone = pWin->HandleScrollCommand( aReWrite,
844 mpHorizontalScrollBar.get(),
845 mpVerticalScrollBar.get());
850 break;
852 default:
853 break;
856 return bDone;
859 void ViewShell::SetupRulers()
861 if(mbHasRulers && (mpContentWindow.get() != NULL) && !SlideShow::IsRunning(GetViewShellBase()))
863 long nHRulerOfs = 0;
865 if ( mpVerticalRuler.get() == NULL )
867 mpVerticalRuler.reset(CreateVRuler(GetActiveWindow()));
868 if ( mpVerticalRuler.get() != NULL )
870 nHRulerOfs = mpVerticalRuler->GetSizePixel().Width();
871 mpVerticalRuler->SetActive(true);
872 mpVerticalRuler->Show();
875 if ( mpHorizontalRuler.get() == NULL )
877 mpHorizontalRuler.reset(CreateHRuler(GetActiveWindow(), true));
878 if ( mpHorizontalRuler.get() != NULL )
880 mpHorizontalRuler->SetWinPos(nHRulerOfs);
881 mpHorizontalRuler->SetActive(true);
882 mpHorizontalRuler->Show();
888 const SfxPoolItem* ViewShell::GetNumBulletItem(SfxItemSet& aNewAttr, sal_uInt16& nNumItemId)
890 const SfxPoolItem* pTmpItem = NULL;
892 if(aNewAttr.GetItemState(nNumItemId, false, &pTmpItem) == SfxItemState::SET)
894 return pTmpItem;
896 else
898 nNumItemId = aNewAttr.GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE);
899 SfxItemState eState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
900 if (eState == SfxItemState::SET)
901 return pTmpItem;
902 else
904 bool bOutliner = false;
905 bool bTitle = false;
907 if( mpView )
909 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
910 const size_t nCount = rMarkList.GetMarkCount();
912 for(size_t nNum = 0; nNum < nCount; ++nNum)
914 SdrObject* pObj = rMarkList.GetMark(nNum)->GetMarkedSdrObj();
915 if( pObj->GetObjInventor() == SdrInventor )
917 switch(pObj->GetObjIdentifier())
919 case OBJ_TITLETEXT:
920 bTitle = true;
921 break;
922 case OBJ_OUTLINETEXT:
923 bOutliner = true;
924 break;
930 const SvxNumBulletItem *pItem = NULL;
931 if(bOutliner)
933 SfxStyleSheetBasePool* pSSPool = mpView->GetDocSh()->GetStyleSheetPool();
934 OUString aStyleName(SD_RESSTR(STR_LAYOUT_OUTLINE) + " 1");
935 SfxStyleSheetBase* pFirstStyleSheet = pSSPool->Find( aStyleName, SD_STYLE_FAMILY_PSEUDO);
936 if( pFirstStyleSheet )
937 pFirstStyleSheet->GetItemSet().GetItemState(EE_PARA_NUMBULLET, false, reinterpret_cast<const SfxPoolItem**>(&pItem));
940 if( pItem == NULL )
941 pItem = static_cast<const SvxNumBulletItem*>( aNewAttr.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET) );
943 aNewAttr.Put(*pItem, EE_PARA_NUMBULLET);
945 if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET,true) == SfxItemState::SET )
947 const SvxNumBulletItem* pBulletItem = static_cast<const SvxNumBulletItem*>(aNewAttr.GetItem(EE_PARA_NUMBULLET,true));
948 SvxNumRule* pRule = pBulletItem->GetNumRule();
949 if(pRule)
951 SvxNumRule aNewRule( *pRule );
952 aNewRule.SetFeatureFlag( SvxNumRuleFlags::NO_NUMBERS, true );
954 SvxNumBulletItem aNewItem( aNewRule, EE_PARA_NUMBULLET );
955 aNewAttr.Put(aNewItem);
959 SfxItemState eNumState = aNewAttr.GetItemState(nNumItemId, false, &pTmpItem);
960 if (eNumState == SfxItemState::SET)
961 return pTmpItem;
965 return pTmpItem;
968 void ViewShell::Resize()
970 SetupRulers ();
972 if (mpParentWindow == nullptr)
973 return;
975 // Make sure that the new size is not degenerate.
976 const Size aSize (mpParentWindow->GetSizePixel());
977 if (aSize.Width()==0 || aSize.Height()==0)
978 return;
980 // Remember the new position and size.
981 maViewPos = Point(0,0);
982 maViewSize = aSize;
984 // Rearrange the UI elements to take care of the new position and size.
985 ArrangeGUIElements ();
986 // end of included AdjustPosSizePixel.
988 ::sd::View* pView = GetView();
990 if (pView)
992 pView->VisAreaChanged(GetActiveWindow());
996 SvBorder ViewShell::GetBorder (bool )
998 SvBorder aBorder;
1000 // Horizontal scrollbar.
1001 if (mpHorizontalScrollBar.get()!=NULL
1002 && mpHorizontalScrollBar->IsVisible())
1004 aBorder.Bottom() = maScrBarWH.Height();
1007 // Vertical scrollbar.
1008 if (mpVerticalScrollBar.get()!=NULL
1009 && mpVerticalScrollBar->IsVisible())
1011 aBorder.Right() = maScrBarWH.Width();
1014 // Place horizontal ruler below tab bar.
1015 if (mbHasRulers && mpContentWindow.get() != NULL)
1017 SetupRulers();
1018 if (mpHorizontalRuler.get() != NULL)
1019 aBorder.Top() = mpHorizontalRuler->GetSizePixel().Height();
1020 if (mpVerticalRuler.get() != NULL)
1021 aBorder.Left() = mpVerticalRuler->GetSizePixel().Width();
1024 return aBorder;
1027 void ViewShell::ArrangeGUIElements()
1029 if (mpImpl->mbArrangeActive)
1030 return;
1031 mpImpl->mbArrangeActive = true;
1033 // Calculate border for in-place editing.
1034 long nLeft = maViewPos.X();
1035 long nTop = maViewPos.Y();
1036 long nRight = maViewPos.X() + maViewSize.Width();
1037 long nBottom = maViewPos.Y() + maViewSize.Height();
1039 // Horizontal scrollbar.
1040 if (mpHorizontalScrollBar.get()!=NULL
1041 && mpHorizontalScrollBar->IsVisible())
1043 nBottom -= maScrBarWH.Height();
1044 if (mpLayerTabBar.get()!=NULL && mpLayerTabBar->IsVisible())
1045 nBottom -= mpLayerTabBar->GetSizePixel().Height();
1046 mpHorizontalScrollBar->SetPosSizePixel (
1047 Point(nLeft, nBottom),
1048 Size(nRight - nLeft - maScrBarWH.Width(), maScrBarWH.Height()));
1051 // Vertical scrollbar.
1052 if (mpVerticalScrollBar.get()!=NULL
1053 && mpVerticalScrollBar->IsVisible())
1055 nRight -= maScrBarWH.Width();
1056 mpVerticalScrollBar->SetPosSizePixel (
1057 Point(nRight,nTop),
1058 Size (maScrBarWH.Width(), nBottom-nTop));
1061 // Filler in the lower right corner.
1062 if (mpScrollBarBox.get() != NULL)
1064 if (mpHorizontalScrollBar.get()!=NULL
1065 && mpHorizontalScrollBar->IsVisible()
1066 && mpVerticalScrollBar.get()!=NULL
1067 && mpVerticalScrollBar->IsVisible())
1069 mpScrollBarBox->Show();
1070 mpScrollBarBox->SetPosSizePixel(Point(nRight, nBottom), maScrBarWH);
1072 else
1073 mpScrollBarBox->Hide();
1076 // Place horizontal ruler below tab bar.
1077 if (mbHasRulers && mpContentWindow.get() != NULL)
1079 if (mpHorizontalRuler.get() != NULL)
1081 Size aRulerSize = mpHorizontalRuler->GetSizePixel();
1082 aRulerSize.Width() = nRight - nLeft;
1083 mpHorizontalRuler->SetPosSizePixel (
1084 Point(nLeft,nTop), aRulerSize);
1085 if (mpVerticalRuler.get() != NULL)
1086 mpHorizontalRuler->SetBorderPos(
1087 mpVerticalRuler->GetSizePixel().Width()-1);
1088 nTop += aRulerSize.Height();
1090 if (mpVerticalRuler.get() != NULL)
1092 Size aRulerSize = mpVerticalRuler->GetSizePixel();
1093 aRulerSize.Height() = nBottom - nTop;
1094 mpVerticalRuler->SetPosSizePixel (
1095 Point (nLeft,nTop), aRulerSize);
1096 nLeft += aRulerSize.Width();
1100 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
1102 // The size of the window of the center pane is set differently from
1103 // that of the windows in the docking windows.
1104 bool bSlideShowActive = (xSlideShow.is() && xSlideShow->isRunning()) && !xSlideShow->isFullScreen() && xSlideShow->getAnimationMode() == ANIMATIONMODE_SHOW;
1105 if ( !bSlideShowActive)
1107 OSL_ASSERT (GetViewShell()!=NULL);
1109 if (mpContentWindow)
1110 mpContentWindow->SetPosSizePixel(
1111 Point(nLeft,nTop),
1112 Size(nRight-nLeft,nBottom-nTop));
1115 // Windows in the center and rulers at the left and top side.
1116 maAllWindowRectangle = Rectangle(
1117 maViewPos,
1118 Size(maViewSize.Width()-maScrBarWH.Width(),
1119 maViewSize.Height()-maScrBarWH.Height()));
1121 if (mpContentWindow.get() != NULL)
1123 mpContentWindow->UpdateMapOrigin();
1126 UpdateScrollBars();
1128 mpImpl->mbArrangeActive = false;
1131 void ViewShell::SetUIUnit(FieldUnit eUnit)
1133 // Set unit at horizontal and vertical rulers.
1134 if (mpHorizontalRuler.get() != NULL)
1135 mpHorizontalRuler->SetUnit(eUnit);
1137 if (mpVerticalRuler.get() != NULL)
1138 mpVerticalRuler->SetUnit(eUnit);
1142 * set DefTab at horizontal rulers
1144 void ViewShell::SetDefTabHRuler( sal_uInt16 nDefTab )
1146 if (mpHorizontalRuler.get() != NULL)
1147 mpHorizontalRuler->SetDefTabDist( nDefTab );
1150 /** Tell the FmFormShell that the view shell is closing. Give it the
1151 opportunity to prevent that.
1153 bool ViewShell::PrepareClose (bool bUI)
1155 bool nResult = true;
1157 FmFormShell* pFormShell = GetViewShellBase().GetFormShellManager()->GetFormShell();
1158 if (pFormShell != NULL)
1159 nResult = pFormShell->PrepareClose (bUI);
1161 return nResult;
1164 void ViewShell::UpdatePreview (SdPage*, bool )
1166 // Do nothing. After the actual preview has been removed,
1167 // OutlineViewShell::UpdatePreview() is the place where something
1168 // useful is still done.
1171 ::svl::IUndoManager* ViewShell::ImpGetUndoManager() const
1173 const ViewShell* pMainViewShell = GetViewShellBase().GetMainViewShell().get();
1175 if( pMainViewShell == 0 )
1176 pMainViewShell = this;
1178 ::sd::View* pView = pMainViewShell->GetView();
1180 // check for text edit our outline view
1181 if( pView )
1183 if( pMainViewShell->GetShellType() == ViewShell::ST_OUTLINE )
1185 OutlineView* pOlView = dynamic_cast< OutlineView* >( pView );
1186 if( pOlView )
1188 ::Outliner& rOutl = pOlView->GetOutliner();
1189 return &rOutl.GetUndoManager();
1192 else if( pView->IsTextEdit() )
1194 SdrOutliner* pOL = pView->GetTextEditOutliner();
1195 if( pOL )
1196 return &pOL->GetUndoManager();
1200 if( GetDocSh() )
1201 return GetDocSh()->GetUndoManager();
1203 return NULL;
1206 void ViewShell::ImpGetUndoStrings(SfxItemSet &rSet) const
1208 ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
1209 if(pUndoManager)
1211 sal_uInt16 nCount(pUndoManager->GetUndoActionCount());
1212 if(nCount)
1214 // prepare list
1215 std::vector<OUString> aStringList;
1217 for (sal_uInt16 a = 0; a < nCount; ++a)
1219 // generate one String in list per undo step
1220 aStringList.push_back( pUndoManager->GetUndoActionComment(a) );
1223 // set item
1224 rSet.Put(SfxStringListItem(SID_GETUNDOSTRINGS, &aStringList));
1226 else
1228 rSet.DisableItem(SID_GETUNDOSTRINGS);
1233 void ViewShell::ImpGetRedoStrings(SfxItemSet &rSet) const
1235 ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
1236 if(pUndoManager)
1238 sal_uInt16 nCount(pUndoManager->GetRedoActionCount());
1239 if(nCount)
1241 // prepare list
1242 ::std::vector< OUString > aStringList;
1243 sal_uInt16 a;
1245 for( a = 0; a < nCount; a++)
1247 // generate one String in list per undo step
1248 aStringList.push_back( pUndoManager->GetRedoActionComment(a) );
1251 // set item
1252 rSet.Put(SfxStringListItem(SID_GETREDOSTRINGS, &aStringList));
1254 else
1256 rSet.DisableItem(SID_GETREDOSTRINGS);
1261 void ViewShell::ImpSidUndo(bool, SfxRequest& rReq)
1263 ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
1264 sal_uInt16 nNumber(1);
1265 const SfxItemSet* pReqArgs = rReq.GetArgs();
1267 if(pReqArgs)
1269 const SfxUInt16Item* pUIntItem = static_cast<const SfxUInt16Item*>(&pReqArgs->Get(SID_UNDO));
1270 nNumber = pUIntItem->GetValue();
1273 if(nNumber && pUndoManager)
1275 sal_uInt16 nCount(pUndoManager->GetUndoActionCount());
1276 if(nCount >= nNumber)
1280 // when UndoStack is cleared by ModifyPageUndoAction
1281 // the nCount may have changed, so test GetUndoActionCount()
1282 while(nNumber-- && pUndoManager->GetUndoActionCount())
1284 pUndoManager->Undo();
1287 catch( const Exception& )
1289 // no need to handle. By definition, the UndoManager handled this by clearing the
1290 // Undo/Redo stacks
1294 // refresh rulers, maybe UNDO was move of TAB marker in ruler
1295 if (mbHasRulers)
1297 Invalidate(SID_ATTR_TABSTOP);
1301 // This one is corresponding to the default handling
1302 // of SID_UNDO in sfx2
1303 GetViewFrame()->GetBindings().InvalidateAll(false);
1305 rReq.Done();
1308 void ViewShell::ImpSidRedo(bool, SfxRequest& rReq)
1310 ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
1311 sal_uInt16 nNumber(1);
1312 const SfxItemSet* pReqArgs = rReq.GetArgs();
1314 if(pReqArgs)
1316 const SfxUInt16Item* pUIntItem = static_cast<const SfxUInt16Item*>(&pReqArgs->Get(SID_REDO));
1317 nNumber = pUIntItem->GetValue();
1320 if(nNumber && pUndoManager)
1322 sal_uInt16 nCount(pUndoManager->GetRedoActionCount());
1323 if(nCount >= nNumber)
1327 // when UndoStack is cleared by ModifyPageRedoAction
1328 // the nCount may have changed, so test GetRedoActionCount()
1329 while(nNumber-- && pUndoManager->GetRedoActionCount())
1331 pUndoManager->Redo();
1334 catch( const Exception& )
1336 // no need to handle. By definition, the UndoManager handled this by clearing the
1337 // Undo/Redo stacks
1341 // refresh rulers, maybe REDO was move of TAB marker in ruler
1342 if (mbHasRulers)
1344 Invalidate(SID_ATTR_TABSTOP);
1348 // This one is corresponding to the default handling
1349 // of SID_UNDO in sfx2
1350 GetViewFrame()->GetBindings().InvalidateAll(false);
1352 rReq.Done();
1355 void ViewShell::ExecReq( SfxRequest& rReq )
1357 sal_uInt16 nSlot = rReq.GetSlot();
1358 switch( nSlot )
1360 case SID_MAIL_SCROLLBODY_PAGEDOWN:
1362 rtl::Reference<FuPoor> xFunc( GetCurrentFunction() );
1363 if( xFunc.is() )
1364 ScrollLines( 0, -1 );
1366 rReq.Done();
1368 break;
1370 case SID_OUTPUT_QUALITY_COLOR:
1371 case SID_OUTPUT_QUALITY_GRAYSCALE:
1372 case SID_OUTPUT_QUALITY_BLACKWHITE:
1373 case SID_OUTPUT_QUALITY_CONTRAST:
1375 DrawModeFlags nMode = OUTPUT_DRAWMODE_COLOR;
1377 switch( nSlot )
1379 case SID_OUTPUT_QUALITY_COLOR: nMode = OUTPUT_DRAWMODE_COLOR; break;
1380 case SID_OUTPUT_QUALITY_GRAYSCALE: nMode = OUTPUT_DRAWMODE_GRAYSCALE; break;
1381 case SID_OUTPUT_QUALITY_BLACKWHITE: nMode = OUTPUT_DRAWMODE_BLACKWHITE; break;
1382 case SID_OUTPUT_QUALITY_CONTRAST: nMode = OUTPUT_DRAWMODE_CONTRAST; break;
1385 GetActiveWindow()->SetDrawMode( nMode );
1386 mpFrameView->SetDrawMode( nMode );
1388 GetActiveWindow()->Invalidate();
1390 Invalidate();
1391 rReq.Done();
1392 break;
1397 /** This default implementation returns only an empty reference. See derived
1398 classes for more interesting examples.
1400 ::com::sun::star::uno::Reference<
1401 ::com::sun::star::accessibility::XAccessible>
1402 ViewShell::CreateAccessibleDocumentView (::sd::Window* )
1404 OSL_FAIL("ViewShell::CreateAccessibleDocumentView should not be called!, perhaps Meyers, 3rd edition, Item 9:\n");
1406 return ::com::sun::star::uno::Reference<
1407 ::com::sun::star::accessibility::XAccessible> ();
1410 ::sd::WindowUpdater* ViewShell::GetWindowUpdater() const
1412 return mpWindowUpdater.get();
1415 ViewShellBase& ViewShell::GetViewShellBase() const
1417 return *static_cast<ViewShellBase*>(GetViewShell());
1420 ViewShell::ShellType ViewShell::GetShellType() const
1422 return meShellType;
1425 DrawDocShell* ViewShell::GetDocSh() const
1427 return GetViewShellBase().GetDocShell();
1430 SdDrawDocument* ViewShell::GetDoc() const
1432 return GetViewShellBase().GetDocument();
1435 ErrCode ViewShell::DoVerb (long )
1437 return ERRCODE_NONE;
1440 void ViewShell::SetCurrentFunction( const rtl::Reference<FuPoor>& xFunction)
1442 if( mxCurrentFunction.is() && (mxOldFunction != mxCurrentFunction) )
1443 mxCurrentFunction->Dispose();
1444 rtl::Reference<FuPoor> xTemp( mxCurrentFunction );
1445 mxCurrentFunction = xFunction;
1448 void ViewShell::SetOldFunction(const rtl::Reference<FuPoor>& xFunction)
1450 if( mxOldFunction.is() && (xFunction != mxOldFunction) && (mxCurrentFunction != mxOldFunction) )
1451 mxOldFunction->Dispose();
1453 rtl::Reference<FuPoor> xTemp( mxOldFunction );
1454 mxOldFunction = xFunction;
1457 /** this method deactivates the current function. If an old function is
1458 saved, this will become activated and current function.
1460 void ViewShell::Cancel()
1462 if(mxCurrentFunction.is() && (mxCurrentFunction != mxOldFunction ))
1464 rtl::Reference<FuPoor> xTemp( mxCurrentFunction );
1465 mxCurrentFunction.clear();
1466 xTemp->Deactivate();
1467 xTemp->Dispose();
1470 if(mxOldFunction.is())
1472 mxCurrentFunction = mxOldFunction;
1473 mxCurrentFunction->Activate();
1477 void ViewShell::DeactivateCurrentFunction( bool bPermanent /* == false */ )
1479 if( mxCurrentFunction.is() )
1481 if(bPermanent && (mxOldFunction == mxCurrentFunction))
1482 mxOldFunction.clear();
1484 mxCurrentFunction->Deactivate();
1485 if( mxCurrentFunction != mxOldFunction )
1486 mxCurrentFunction->Dispose();
1488 rtl::Reference<FuPoor> xTemp( mxCurrentFunction );
1489 mxCurrentFunction.clear();
1493 void ViewShell::DisposeFunctions()
1495 if(mxCurrentFunction.is())
1497 rtl::Reference<FuPoor> xTemp( mxCurrentFunction );
1498 mxCurrentFunction.clear();
1499 xTemp->Deactivate();
1500 xTemp->Dispose();
1503 if(mxOldFunction.is())
1505 rtl::Reference<FuPoor> xTemp( mxOldFunction );
1506 mxOldFunction->Dispose();
1507 mxOldFunction.clear();
1511 bool ViewShell::IsMainViewShell() const
1513 return mpImpl->mbIsMainViewShell;
1516 void ViewShell::SetIsMainViewShell (bool bIsMainViewShell)
1518 if (bIsMainViewShell != mpImpl->mbIsMainViewShell)
1520 mpImpl->mbIsMainViewShell = bIsMainViewShell;
1521 if (bIsMainViewShell)
1523 GetDocSh()->Connect (this);
1525 else
1527 GetDocSh()->Disconnect (this);
1532 void ViewShell::PrePaint()
1536 void ViewShell::Paint (const Rectangle&, ::sd::Window* )
1540 void ViewShell::ShowUIControls (bool bVisible)
1542 mpImpl->mbIsShowingUIControls = bVisible;
1544 if (mbHasRulers)
1546 if (mpHorizontalRuler.get() != NULL)
1547 mpHorizontalRuler->Show( bVisible );
1549 if (mpVerticalRuler.get() != NULL)
1550 mpVerticalRuler->Show( bVisible );
1553 if (mpVerticalScrollBar.get() != NULL)
1554 mpVerticalScrollBar->Show( bVisible );
1556 if (mpHorizontalScrollBar.get() != NULL)
1557 mpHorizontalScrollBar->Show( bVisible );
1559 if (mpScrollBarBox.get() != NULL)
1560 mpScrollBarBox->Show(bVisible);
1562 if (mpContentWindow.get() != NULL)
1563 mpContentWindow->Show( bVisible );
1566 bool ViewShell::RelocateToParentWindow (vcl::Window* pParentWindow)
1568 mpParentWindow = pParentWindow;
1570 if (mpParentWindow)
1571 mpParentWindow->SetBackground (Wallpaper());
1573 if (mpContentWindow.get() != NULL)
1574 mpContentWindow->SetParent(pParentWindow);
1576 if (mpHorizontalScrollBar.get() != NULL)
1577 mpHorizontalScrollBar->SetParent(mpParentWindow);
1578 if (mpVerticalScrollBar.get() != NULL)
1579 mpVerticalScrollBar->SetParent(mpParentWindow);
1580 if (mpScrollBarBox.get() != NULL)
1581 mpScrollBarBox->SetParent(mpParentWindow);
1583 return true;
1586 void ViewShell::SwitchViewFireFocus(::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAcc )
1588 if (xAcc.get())
1590 ::accessibility::AccessibleDocumentViewBase* pBase = static_cast< ::accessibility::AccessibleDocumentViewBase* >(xAcc.get());
1591 if (pBase)
1593 pBase->SwitchViewActivated();
1597 void ViewShell::SwitchActiveViewFireFocus()
1599 if (mpContentWindow)
1601 SwitchViewFireFocus(mpContentWindow->GetAccessible(false));
1604 // move these two methods from DrawViewShell.
1605 void ViewShell::fireSwitchCurrentPage(sal_Int32 pageIndex)
1607 GetViewShellBase().GetDrawController().fireSwitchCurrentPage(pageIndex);
1609 void ViewShell::NotifyAccUpdate( )
1611 GetViewShellBase().GetDrawController().NotifyAccUpdate();
1614 } // end of namespace sd
1616 //===== ViewShellObjectBarFactory =============================================
1618 namespace {
1620 ViewShellObjectBarFactory::ViewShellObjectBarFactory (
1621 ::sd::ViewShell& rViewShell)
1622 : mrViewShell (rViewShell)
1626 ViewShellObjectBarFactory::~ViewShellObjectBarFactory()
1628 for (ShellCache::iterator aI(maShellCache.begin());
1629 aI!=maShellCache.end();
1630 ++aI)
1632 delete aI->second;
1636 SfxShell* ViewShellObjectBarFactory::CreateShell (
1637 ::sd::ShellId nId,
1638 vcl::Window*,
1639 ::sd::FrameView* )
1641 SfxShell* pShell = NULL;
1643 ShellCache::iterator aI (maShellCache.find(nId));
1644 if (aI == maShellCache.end() || aI->second==NULL)
1646 ::sd::View* pView = mrViewShell.GetView();
1647 switch (nId)
1649 case RID_BEZIER_TOOLBOX:
1650 pShell = new ::sd::BezierObjectBar(&mrViewShell, pView);
1651 break;
1653 case RID_DRAW_TEXT_TOOLBOX:
1654 pShell = new ::sd::TextObjectBar(
1655 &mrViewShell, mrViewShell.GetDoc()->GetPool(), pView);
1656 break;
1658 case RID_DRAW_GRAF_TOOLBOX:
1659 pShell = new ::sd::GraphicObjectBar(&mrViewShell, pView);
1660 break;
1662 case RID_DRAW_MEDIA_TOOLBOX:
1663 pShell = new ::sd::MediaObjectBar(&mrViewShell, pView);
1664 break;
1666 case RID_DRAW_TABLE_TOOLBOX:
1667 pShell = ::sd::ui::table::CreateTableObjectBar( mrViewShell, pView );
1668 break;
1670 case RID_SVX_EXTRUSION_BAR:
1671 pShell = new svx::ExtrusionBar(
1672 &mrViewShell.GetViewShellBase());
1673 break;
1675 case RID_SVX_FONTWORK_BAR:
1676 pShell = new svx::FontworkBar(
1677 &mrViewShell.GetViewShellBase());
1678 break;
1680 default:
1681 pShell = NULL;
1682 break;
1685 else
1686 pShell = aI->second;
1688 return pShell;
1691 void ViewShellObjectBarFactory::ReleaseShell (SfxShell* pShell)
1693 if (pShell != NULL)
1694 delete pShell;
1697 } // end of anonymous namespace
1699 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */