bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / inc / ViewShell.hxx
blobbc962ca59810e4898659f8001d46cb81032c5bff
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 #ifndef INCLUDED_SD_SOURCE_UI_INC_VIEWSHELL_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_VIEWSHELL_HXX
23 #include <rtl/ref.hxx>
25 #include <vcl/field.hxx>
26 #include <sfx2/viewsh.hxx>
27 #include <vcl/prntypes.hxx>
28 #include <svtools/transfer.hxx>
29 #include "glob.hxx"
30 #include "pres.hxx"
31 #include "cfgids.hxx"
32 #include "View.hxx"
33 #include "sddllapi.h"
35 #include <com/sun/star/drawing/XDrawSubController.hpp>
36 #include <memory>
37 #include <boost/shared_ptr.hpp>
39 class SdPage;
40 class SvxRuler;
41 class SdrOle2Obj; // for the ones, who have undefined parts of SVDRAW
42 class ScrollBarBox;
43 class SdDrawDocument;
44 class ScrollBar;
46 namespace com { namespace sun { namespace star {
47 namespace embed {
48 class XEmbeddedObject;
49 }}}}
51 namespace sd {
53 extern const OUString aEmptyStr;
55 class DrawDocShell;
56 class FrameView;
57 class LayerTabBar;
58 class View;
59 class ViewShellBase;
60 class Window;
61 class WindowUpdater;
62 class ZoomList;
64 #undef OUTPUT_DRAWMODE_COLOR
65 #undef OUTPUT_DRAWMODE_CONTRAST
67 static const DrawModeFlags OUTPUT_DRAWMODE_COLOR = DrawModeFlags::Default;
68 static const DrawModeFlags OUTPUT_DRAWMODE_GRAYSCALE
69 = DrawModeFlags::GrayLine | DrawModeFlags::GrayFill
70 | DrawModeFlags::BlackText | DrawModeFlags::GrayBitmap
71 | DrawModeFlags::GrayGradient;
72 static const DrawModeFlags OUTPUT_DRAWMODE_BLACKWHITE
73 = DrawModeFlags::BlackLine | DrawModeFlags::BlackText
74 | DrawModeFlags::WhiteFill | DrawModeFlags::GrayBitmap
75 | DrawModeFlags::WhiteGradient;
76 static const DrawModeFlags OUTPUT_DRAWMODE_CONTRAST
77 = DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill
78 | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient;
80 /** Base class of the stacked shell hierarchy.
82 <p>Despite its name this class is not a descendant of SfxViewShell
83 but of SfxShell. Its name expresses the fact that it acts like a
84 view shell. Being a stacked shell rather then being an actual view shell
85 there can be several instances of this class that
86 <ul>
87 <li>all are based on the same view shell and thus show the same
88 document and share common view functionality and</li>
89 <li>are all visible at the same time and live in the same
90 frame.</li>
91 <ul></p>
93 <p>This class replaces the former ViewShell class.</p>
95 class ViewShell
96 : public SfxShell
98 public:
99 enum ShellType {
100 ST_NONE,
101 ST_DRAW, // The Draw application.
102 ST_IMPRESS, // Main view of the Impress application.
103 ST_NOTES,
104 ST_HANDOUT,
105 ST_OUTLINE,
106 ST_SLIDE_SORTER,
107 ST_PRESENTATION,
108 ST_SIDEBAR
110 static const int MAX_HSPLIT_CNT = 1;
111 static const int MAX_VSPLIT_CNT = 1;
112 static const int MIN_SCROLLBAR_SIZE = 50;
114 TYPEINFO_OVERRIDE();
116 ViewShell (
117 SfxViewFrame *pFrame,
118 vcl::Window* pParentWindow,
119 ViewShellBase& rViewShellBase,
120 bool bAllowCenter = true);
121 virtual ~ViewShell();
123 /** The Init method has to be called from the outside directly
124 after a new object of this class has been created. It can be
125 used for that part of the initialisation that can be run only
126 after the creation of the new object is finished. This
127 includes registration as listener at event broadcasters.
129 Derived classes should call this method at the head of their
130 Init() methods.
131 @param bIsMainViewShell
132 This flag tells the Init() method whether the new ViewShell will
133 be the main view shell.
135 virtual void Init (bool bIsMainViewShell);
137 /** The Exit() method has to be called before the destructor so that the
138 view shell is still a valid object and can safely call methods that
139 rely on that.
141 void Exit();
143 void Cancel();
145 /** Return the window that is the parent of all controls of this view
146 shell. This may or may not be the window of the frame.
148 inline vcl::Window* GetParentWindow() const { return mpParentWindow; }
150 inline ::sd::View* GetView() const { return mpView; }
151 inline SdrView* GetDrawView() const;
152 SD_DLLPUBLIC DrawDocShell* GetDocSh() const;
154 SdDrawDocument* GetDoc() const;
156 SD_DLLPUBLIC SfxViewFrame* GetViewFrame() const;
158 /** The active window is usually the mpContentWindow. When there is a
159 show running then the active window is a ShowWindow.
161 ::sd::Window* GetActiveWindow() const { return mpActiveWindow;}
163 /** Set the active window. When the shell is displayed in the center
164 pane then the window of the ViewShellBase is also set to the given
165 window.
167 void SetActiveWindow (::sd::Window* pWindow);
169 /** Return the rectangle that encloses all windows of the view. That
170 excludes the controls in the frame like rulers, scroll bars, tab
171 bar, and buttons.
172 @return
173 The rectangle is returned in screen coordinates, i.e. pixel
174 values relative to the upper left corner of the screen?.
176 const Rectangle& GetAllWindowRect();
178 // Mouse- & Key-Events
179 virtual void PrePaint();
180 virtual void Paint (const Rectangle& rRect, ::sd::Window* pWin);
181 virtual bool KeyInput(const KeyEvent& rKEvt, ::sd::Window* pWin);
182 virtual void MouseMove(const MouseEvent& rMEvt, ::sd::Window* pWin);
183 virtual void MouseButtonUp(const MouseEvent& rMEvt, ::sd::Window* pWin);
184 virtual void MouseButtonDown(const MouseEvent& rMEvt, ::sd::Window* pWin);
185 virtual void Command(const CommandEvent& rCEvt, ::sd::Window* pWin);
186 bool RequestHelp( const HelpEvent& rEvt, ::sd::Window* pWin );
187 bool Notify( NotifyEvent& rNEvt, ::sd::Window* pWin );
189 bool HandleScrollCommand(const CommandEvent& rCEvt, ::sd::Window* pWin);
191 virtual void SetUIUnit(FieldUnit eUnit);
192 void SetDefTabHRuler( sal_uInt16 nDefTab );
194 const SfxPoolItem* GetNumBulletItem(SfxItemSet& aNewAttr, sal_uInt16& nNumItemId);
196 bool HasRuler() { return mbHasRulers;}
197 void SetRuler(bool bRuler);
199 /** Set internal values of all scroll bars that determine thumb size and
200 position. The external values like size and position of the scroll
201 bar controls are not modified.
203 virtual void UpdateScrollBars();
204 void Scroll(long nX, long nY);
205 void ScrollLines(long nX, long nY);
206 virtual void SetZoom(long nZoom);
207 virtual void SetZoomRect(const Rectangle& rZoomRect);
208 void InitWindows(const Point& rViewOrigin, const Size& rViewSize,
209 const Point& rWinPos, bool bUpdate = false);
210 void InvalidateWindows();
211 /** This method is still used by the OutlineViewShell to update the
212 model according to the content of the outline view. This in turn
213 updates the previews in the slide sorter.
215 virtual void UpdatePreview (SdPage* pPage, bool bInit = false);
217 void DrawMarkRect(const Rectangle& rRect) const;
219 void ExecReq( SfxRequest &rReq );
221 ZoomList* GetZoomList() { return mpZoomList;}
223 FrameView* GetFrameView() { return mpFrameView; }
224 /** Setting a frame view triggers ReadFrameViewData() for the new
225 frame.
226 @param pFrameView
227 The new frame view that replaces the old one.
229 void SetFrameView (FrameView* pFrameView);
230 virtual void ReadFrameViewData(FrameView* pView);
231 virtual void WriteFrameViewData();
232 void WriteUserData(OUString& rString);
233 void ReadUserData(const OUString& rString);
235 virtual bool ActivateObject(SdrOle2Obj* pObj, long nVerb);
237 /** @returns
238 current or selected page or 0. This method
239 will fail in master page mode.
241 @deprecated, please use getCurrentPage();
243 virtual SdPage* GetActualPage() = 0;
245 /** @returns
246 current or selected page or 0.
248 virtual SdPage* getCurrentPage() const = 0;
250 rtl::Reference<FuPoor> GetOldFunction() const { return mxOldFunction; }
251 bool HasOldFunction() const { return mxOldFunction.is(); }
252 rtl::Reference<FuPoor> GetCurrentFunction() const { return mxCurrentFunction; }
253 bool HasCurrentFunction( sal_uInt16 nSID ) { return mxCurrentFunction.is() && (mxCurrentFunction->GetSlotID() == nSID ); }
254 bool HasCurrentFunction() { return mxCurrentFunction.is(); }
256 void SetCurrentFunction(const rtl::Reference<FuPoor>& xFunction);
257 void SetOldFunction(const rtl::Reference<FuPoor>& xFunction);
258 void DeactivateCurrentFunction( bool bPermanent = false );
260 void SetPageSizeAndBorder(PageKind ePageKind, const Size& rNewSize,
261 long nLeft, long nRight, long nUpper, long nLower,
262 bool bScaleAll, Orientation eOrient, sal_uInt16 nPaperBin,
263 bool bBackgroundFullSize );
265 void SetStartShowWithDialog( bool bIn = true ) { mbStartShowWithDialog = bIn; }
266 bool IsStartShowWithDialog() const { return mbStartShowWithDialog; }
268 sal_uInt16 GetPrintedHandoutPageNum() const { return mnPrintedHandoutPageNum; }
269 void SetPrintedHandoutPageNum (sal_uInt16 nPageNumber) {mnPrintedHandoutPageNum=nPageNumber; }
271 sal_uInt16 GetPrintedHandoutPageCount() const { return mnPrintedHandoutPageCount; }
272 void SetPrintedHandoutPageCount (sal_uInt16 nPageCount) {mnPrintedHandoutPageCount=nPageCount; }
274 virtual bool PrepareClose( bool bUI = true );
276 void GetMenuState(SfxItemSet& rSet);
278 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt, DropTargetHelper& rTargetHelper,
279 ::sd::Window* pTargetWindow, sal_uInt16 nPage, sal_uInt16 nLayer );
280 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt, DropTargetHelper& rTargetHelper,
281 ::sd::Window* pTargetWindow, sal_uInt16 nPage, sal_uInt16 nLayer );
283 virtual void WriteUserDataSequence ( ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, bool bBrowse = false );
284 virtual void ReadUserDataSequence ( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, bool bBrowse = false );
286 /** this method is called when the visible area of the view from this viewshell is changed */
287 virtual void VisAreaChanged(const Rectangle& rRect);
289 /** Create an accessible object representing the specified window.
290 Override this method to provide view mode specific objects. The
291 default implementation returns an empty reference.
292 @param pWindow
293 Make the document displayed in this window accessible.
294 @return
295 This default implementation returns an empty reference.
297 virtual ::com::sun::star::uno::Reference<
298 ::com::sun::star::accessibility::XAccessible>
299 CreateAccessibleDocumentView (::sd::Window* pWindow);
301 virtual void SwitchViewFireFocus( ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAcc );
302 void SwitchActiveViewFireFocus( );
303 // Move these two methods from DrawViewShell to enable slide show view
304 void NotifyAccUpdate();
305 void fireSwitchCurrentPage(sal_Int32 pageIndex);
306 void SetWinViewPos(const Point& rWinPos, bool bUpdate);
307 Point GetWinViewPos() const;
308 Point GetViewOrigin() const;
310 /** Return the window updater of this view shell.
311 @return
312 In rare circumstances the returned pointer may be <null/>,
313 i.e. when no memory is available anymore.
315 ::sd::WindowUpdater* GetWindowUpdater() const;
317 /** Return the border that is drawn around the actual document view.
318 The border contains typically rulers and scroll bars.
319 @param bOuterResize
320 When this flag is <TRUE/> then the border is used for an
321 OuterResizePixel(), i.e. there is a given window size and the
322 border elements are placed inside so that the document view has
323 the given window size minus the border.
324 When the flag is <FALSE/> then the border is used for an
325 InnerResizePixel(), i.e. the document view has a given size and
326 the border is placed outside. In this scenario the parent
327 window has the size of the document view plus the border.
329 SvBorder GetBorder (bool bOuterResize);
331 /** Notify the view shell that its parent window has been resized.
332 The ViewShell places and resizes its UI elements accordingly.
333 The new size can be obtained from the parent window.
335 virtual void Resize();
337 /** Set the position and size of the area which contains the GUI
338 elements like rulers, sliders, and buttons as well as the document
339 view. Both size and position are expected to be in pixel
340 coordinates. The positions and sizes of the mentioned GUI elements
341 are updated as well.
343 <p> This method is implemented by first setting copying the given
344 values to internal variables and then calling the
345 <type>ArrangeGUIElements</type> method which performs the actual
346 work of sizeing and arranging the UI elements accordingly.</p>
347 @param rPos
348 The position of the enclosing window relative to the document
349 window. This is only interesting if a Draw/Impress document
350 view is embedded as OLE object into another document view. For
351 normal documents this position is (0,0).
352 @param rSize
353 The new size in pixel.
355 // This is to be replaced by Resize.
356 // virtual void AdjustPosSizePixel(const Point &rPos, const Size &rSize);
358 /** Set position and size of the GUI elements that are controllerd by
359 the view shell like rulers and scroll bars as well as the actual
360 document view according to the position and size that were given
361 with the last Resize() call.
363 virtual void ArrangeGUIElements();
365 // virtual void OuterResizePixel(const Point &rPos, const Size &rSize);
366 // virtual void InnerResizePixel(const Point &rPos, const Size &rSize);
368 ViewShellBase& GetViewShellBase() const;
370 /** Return <TRUE/> when the called view shell is the main sub shell of
371 its ViewShellBase object, i.e. is display in the center pane. This
372 convenience function is equivalent to comparing the this pointer to
373 the result of ViewShellBase::GetViewShell(PT_CENTER).
375 bool IsMainViewShell() const;
377 /** Set or reset the flag that indicates whether the called shell is the
378 one displayed in the center pane. By default this flag is set to
379 <FALSE/>. For the main view shell it thus has to be set to <TRUE/>.
381 void SetIsMainViewShell (bool bIsMainViewShell);
383 /** Return a sub controller that implements the view shell specific
384 part of the DrawController.
386 virtual css::uno::Reference<css::drawing::XDrawSubController> CreateSubController() = 0;
388 /** Return the type of the shell.
390 ShellType GetShellType() const;
392 /** This method is more or less an alias to Deactivate(). It is called
393 before an object of this class is taken from the stack of view
394 shells.
396 <p>When this method is not called before a view shell is taken from
397 a stack then the Deactivate() call from the SFX as a response to
398 RemoveSubShell() comes to late when the view shell is not on the
399 stack anymore.</p>
401 virtual void Shutdown();
403 /** This function is called from the underlying ViewShellBase
404 object to handle a verb execution request.
406 virtual ErrCode DoVerb (long nVerb);
408 virtual void UIActivating( SfxInPlaceClient* );
409 virtual void UIDeactivated( SfxInPlaceClient* );
411 /** Show controls of the UI or hide them, depending on the given flag.
412 As a result the border is adapted.
414 virtual void ShowUIControls (bool bVisible = true);
415 bool IsPageFlipMode() const;
417 /** Set the given window as new parent window. This is not possible for
418 all views, so the return value tells the caller if the relocation
419 was successful.
421 virtual bool RelocateToParentWindow (vcl::Window* pParentWindow);
423 /** Depending on the given request create a new page or duplicate an
424 existing one. A new page is created behind the given slide.
425 @param rRequest
426 The request as passed to an Execute() method. Its arguments are
427 evaluated. Its slot id determines whether to create or
428 duplicate a slide.
429 @param pPage
430 This page is either duplicated or becomes the predecessor of the
431 new slide. If NULL a duplication request is ignored. A new
432 slide is inserted as first slide.
433 @param nInsertPosition
434 When -1 (the default) then insert after pPage. Otherwise insert
435 before the given index (of a standard page).
436 @return
437 The new slide is returned. If for some reason a new page can
438 not be created then NULL is returned.
440 virtual SdPage* CreateOrDuplicatePage (
441 SfxRequest& rRequest,
442 PageKind ePageKind,
443 SdPage* pPage,
444 const sal_Int32 nInsertPosition = -1);
446 /// Same as MouseButtonDown(), but coordinates are in logic unit.
447 void LogicMouseButtonDown(const MouseEvent& rMouseEvent);
448 /// Same as MouseButtonUp(), but coordinates are in logic unit.
449 void LogicMouseButtonUp(const MouseEvent& rMouseEvent);
450 /// Same as MouseMove(), but coordinates are in logic unit.
451 void LogicMouseMove(const MouseEvent& rMouseEvent);
452 /// Allows adjusting the point or mark of the selection to a document coordinate.
453 void SetCursorMm100Position(const Point& rPosition, bool bPoint, bool bClearMark);
454 /// Gets the currently selected text.
455 OString GetTextSelection(const OString& aMimeType, OString& rUsedMimeType);
456 /// Allows starting or ending a graphic move or resize action.
457 void SetGraphicMm100Position(bool bStart, const Point& rPosition);
459 class Implementation;
461 protected:
462 /** must be called in the beginning of each subclass d'tor.
463 disposes and clears both current and old function. */
464 void DisposeFunctions();
466 friend class ViewShellBase;
468 /** Window inside the rulers and scroll bars that shows a view of the
469 document.
472 VclPtr<sd::Window> mpContentWindow;
474 /// Horizontal scroll bar for the current slide is displayed when needed.
475 VclPtr<ScrollBar> mpHorizontalScrollBar;
476 /// Vertical scroll bar for whole document is always visible.
477 VclPtr<ScrollBar> mpVerticalScrollBar;
478 /// Horizontal ruler is not shown by default.
479 VclPtr<SvxRuler> mpHorizontalRuler;
480 /// Vertical ruler is not shown by default.
481 VclPtr<SvxRuler> mpVerticalRuler;
482 /// Filler of the little square enclosed by the two scroll bars.
483 VclPtr<ScrollBarBox> mpScrollBarBox;
484 /// Layer tab bar.
485 VclPtr<LayerTabBar> mpLayerTabBar;
487 /// This flag controls whether the rulers are visible.
488 bool mbHasRulers;
490 /// The active window.
491 VclPtr< ::sd::Window> mpActiveWindow;
492 ::sd::View* mpView;
493 FrameView* mpFrameView;
495 rtl::Reference<FuPoor> mxCurrentFunction;
496 rtl::Reference<FuPoor> mxOldFunction;
497 ZoomList* mpZoomList;
499 Point maViewPos;
500 Size maViewSize;
501 Size maScrBarWH;
503 bool mbCenterAllowed; // will be forwarded to window
505 bool mbStartShowWithDialog; // presentation is started by dialog
506 sal_uInt16 mnPrintedHandoutPageNum; // Page number of the handout page that is to be printed.
507 sal_uInt16 mnPrintedHandoutPageCount; // Page count of the handout pages that are to be printed.
509 //af bool bPrintDirectSelected; // Print only selected objects in direct print
510 //afString sPageRange; // pagerange if selected objects in direct print
512 /** Area covered by all windows, i.e. the area of the parent window
513 without the controls at the borders like rulers, scroll bars, tab
514 bar, buttons.
515 This rectangle may be set in window coordinates (i.e. pixel values
516 relative to the parent window). It is transformed by every call to
517 GetAllWindowRectangle() into screen coordinates (relative to the
518 upper left corner of the screen.
520 Rectangle maAllWindowRectangle;
522 /// The type of the shell. Returned by GetShellType().
523 ShellType meShellType;
525 ::std::unique_ptr<Implementation> mpImpl;
527 // Support methods for centralized UNDO/REDO
528 virtual ::svl::IUndoManager* ImpGetUndoManager() const;
529 void ImpGetUndoStrings(SfxItemSet &rSet) const;
530 void ImpGetRedoStrings(SfxItemSet &rSet) const;
531 void ImpSidUndo(bool bDrawViewShell, SfxRequest& rReq);
532 void ImpSidRedo(bool bDrawViewShell, SfxRequest& rReq);
534 DECL_LINK( HScrollHdl, ScrollBar * );
535 DECL_LINK( VScrollHdl, ScrollBar * );
537 // virtual scroll handler, here, derivative classes can add themselves here
538 virtual long VirtHScrollHdl(ScrollBar* pHScroll);
539 virtual long VirtVScrollHdl(ScrollBar* pVScroll);
541 // virtual functions ruler handling
542 virtual SvxRuler* CreateHRuler(::sd::Window* pWin, bool bIsFirst);
543 virtual SvxRuler* CreateVRuler(::sd::Window* pWin);
544 virtual void UpdateHRuler();
545 virtual void UpdateVRuler();
547 virtual void Activate(bool IsMDIActivate) SAL_OVERRIDE;
548 virtual void Deactivate(bool IsMDIActivate) SAL_OVERRIDE;
550 virtual void SetZoomFactor( const Fraction &rZoomX,
551 const Fraction &rZoomY );
554 This must be called after the ctor, but before anything else.
555 It's the part of construction that is dependent
556 on showing the top-level window.
558 Showing a window with a11y enabled causes various callbacks
559 to be triggered.
561 Due to the "virtual methods are not virtual during constructors"
562 problem, this is a disaster to call from the ctor
564 i.e. construct calls Show, and if a11y is enabled this
565 reenters the not-fully constructed object and calls
566 CreateAccessibleDocumentView, so if construct is called
567 from the ctor then if a derived class is contructed the base-cass
568 CreateAccessibleDocumentView is used, not the derived
569 CreateAccessibleDocumentView. i.e. run smoketest under a11y with
570 debugging assertions enabled
572 void doShow();
574 private:
575 VclPtr<vcl::Window> mpParentWindow;
576 /** This window updater is used to keep all relevant windows up to date
577 with reference to the digit language used to display digits in text
578 shapes.
580 ::std::unique_ptr< ::sd::WindowUpdater> mpWindowUpdater;
582 /** Code common to all constructors. It generally is a bad idea
583 to call this function from outside a constructor.
585 void construct();
587 DECL_LINK(FrameWindowEventListener, VclSimpleEvent*);
589 /** Create the rulers.
591 void SetupRulers();
594 SdrView* ViewShell::GetDrawView() const
596 return static_cast<SdrView*>(mpView);
599 } // end of namespace sd
601 #endif
603 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */