1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <rtl/ref.hxx>
24 #include <sfx2/viewsh.hxx>
25 #include <svl/typedwhich.hxx>
26 #include <svtools/scrolladaptor.hxx>
27 #include <vcl/prntypes.hxx>
28 #include <o3tl/deleter.hxx>
38 class SdrOle2Obj
; // for the ones, who have undefined parts of SVDRAW
40 class SvxNumBulletItem
;
47 namespace com::sun::star::drawing
{ class XDrawSubController
; }
59 #undef OUTPUT_DRAWMODE_COLOR
60 #undef OUTPUT_DRAWMODE_CONTRAST
62 const DrawModeFlags OUTPUT_DRAWMODE_COLOR
= DrawModeFlags::Default
;
63 const DrawModeFlags OUTPUT_DRAWMODE_GRAYSCALE
64 = DrawModeFlags::GrayLine
| DrawModeFlags::GrayFill
65 | DrawModeFlags::BlackText
| DrawModeFlags::GrayBitmap
66 | DrawModeFlags::GrayGradient
;
67 const DrawModeFlags OUTPUT_DRAWMODE_BLACKWHITE
68 = DrawModeFlags::BlackLine
| DrawModeFlags::BlackText
69 | DrawModeFlags::WhiteFill
| DrawModeFlags::GrayBitmap
70 | DrawModeFlags::WhiteGradient
;
71 const DrawModeFlags OUTPUT_DRAWMODE_CONTRAST
72 = DrawModeFlags::SettingsLine
| DrawModeFlags::SettingsFill
73 | DrawModeFlags::SettingsText
| DrawModeFlags::SettingsGradient
;
75 /** Base class of the stacked shell hierarchy.
77 <p>Despite its name this class is not a descendant of SfxViewShell
78 but of SfxShell. Its name expresses the fact that it acts like a
79 view shell. Being a stacked shell rather than being an actual view shell
80 there can be several instances of this class that
82 <li>all are based on the same view shell and thus show the same
83 document and share common view functionality and</li>
84 <li>are all visible at the same time and live in the same
88 <p>This class replaces the former ViewShell class.</p>
90 class SAL_DLLPUBLIC_RTTI ViewShell
96 ST_DRAW
, // The Draw application.
97 ST_IMPRESS
, // Main view of the Impress application.
105 static const int MAX_HSPLIT_CNT
= 1;
106 static const int MAX_VSPLIT_CNT
= 1;
107 static const int MIN_SCROLLBAR_SIZE
= 50;
111 vcl::Window
* pParentWindow
,
112 ViewShellBase
& rViewShellBase
);
113 virtual ~ViewShell() override
;
115 /** The Init method has to be called from the outside directly
116 after a new object of this class has been created. It can be
117 used for that part of the initialisation that can be run only
118 after the creation of the new object is finished. This
119 includes registration as listener at event broadcasters.
121 Derived classes should call this method at the head of their
123 @param bIsMainViewShell
124 This flag tells the Init() method whether the new ViewShell will
125 be the main view shell.
127 virtual void Init (bool bIsMainViewShell
);
129 /** The Exit() method has to be called before the destructor so that the
130 view shell is still a valid object and can safely call methods that
137 /** Return the window that is the parent of all controls of this view
138 shell. This may or may not be the window of the frame.
140 vcl::Window
* GetParentWindow() const { return mpParentWindow
; }
142 sd::Window
* GetContentWindow() const;
144 ::sd::View
* GetView() const { return mpView
; }
145 inline SdrView
* GetDrawView() const;
146 SD_DLLPUBLIC DrawDocShell
* GetDocSh() const;
148 SdDrawDocument
* GetDoc() const;
150 SD_DLLPUBLIC SfxViewFrame
* GetViewFrame() const;
152 /** The active window is usually the mpContentWindow. When there is a
153 show running then the active window is a ShowWindow.
155 ::sd::Window
* GetActiveWindow() const { return mpActiveWindow
;}
156 SD_DLLPUBLIC
weld::Window
* GetFrameWeld() const;
158 /** Set the active window. When the shell is displayed in the center
159 pane then the window of the ViewShellBase is also set to the given
162 void SetActiveWindow (::sd::Window
* pWindow
);
164 /** Return the rectangle that encloses all windows of the view. That
165 excludes the controls in the frame like rulers, scroll bars, tab
168 The rectangle is returned in screen coordinates, i.e. pixel
169 values relative to the upper left corner of the screen?.
171 const ::tools::Rectangle
& GetAllWindowRect();
173 // Mouse- & Key-Events
174 virtual void PrePaint();
175 virtual void Paint (const ::tools::Rectangle
& rRect
, ::sd::Window
* pWin
);
176 virtual bool KeyInput(const KeyEvent
& rKEvt
, ::sd::Window
* pWin
);
177 virtual void MouseMove(const MouseEvent
& rMEvt
, ::sd::Window
* pWin
);
178 virtual void MouseButtonUp(const MouseEvent
& rMEvt
, ::sd::Window
* pWin
);
179 virtual void MouseButtonDown(const MouseEvent
& rMEvt
, ::sd::Window
* pWin
);
180 virtual void Command(const CommandEvent
& rCEvt
, ::sd::Window
* pWin
);
181 bool RequestHelp( const HelpEvent
& rEvt
);
182 bool Notify( NotifyEvent
const & rNEvt
, ::sd::Window
* pWin
);
184 bool HandleScrollCommand(const CommandEvent
& rCEvt
, ::sd::Window
* pWin
);
186 void SetUIUnit(FieldUnit eUnit
);
187 void SetDefTabHRuler( sal_uInt16 nDefTab
);
189 const SvxNumBulletItem
* GetNumBulletItem(SfxItemSet
& aNewAttr
, TypedWhichId
<SvxNumBulletItem
>& nNumItemId
);
191 bool HasRuler() const { return mbHasRulers
;}
192 void SetRuler(bool bRuler
);
193 // Hides horizontal, vertical scrollbar as well as scrollbox
194 void SetScrollBarsVisible(bool bVisible
);
196 /** Set internal values of all scroll bars that determine thumb size and
197 position. The external values like size and position of the scroll
198 bar controls are not modified.
200 virtual void UpdateScrollBars();
201 void Scroll(::tools::Long nX
, ::tools::Long nY
);
202 void ScrollLines(::tools::Long nX
, ::tools::Long nY
);
203 virtual void SetZoom(::tools::Long nZoom
);
204 ::tools::Long
GetZoom() const;
205 virtual void SetZoomRect(const ::tools::Rectangle
& rZoomRect
);
206 void InitWindows(const Point
& rViewOrigin
, const Size
& rViewSize
,
207 const Point
& rWinPos
, bool bUpdate
= false);
208 void InvalidateWindows();
209 /** This method is still used by the OutlineViewShell to update the
210 model according to the content of the outline view. This in turn
211 updates the previews in the slide sorter.
213 virtual void UpdatePreview (SdPage
* pPage
);
215 void DrawMarkRect(const ::tools::Rectangle
& rRect
) const;
217 void ExecReq( SfxRequest
&rReq
);
219 ZoomList
* GetZoomList() { return mpZoomList
.get();}
221 FrameView
* GetFrameView() { return mpFrameView
; }
222 /** Setting a frame view triggers ReadFrameViewData() for the new
225 The new frame view that replaces the old one.
227 void SetFrameView (FrameView
* pFrameView
);
228 virtual void ReadFrameViewData(FrameView
* pView
);
229 virtual void WriteFrameViewData();
230 void WriteUserData();
233 virtual bool ActivateObject(SdrOle2Obj
* pObj
, sal_Int32 nVerb
);
236 current or selected page or 0. This method
237 will fail in master page mode.
239 @deprecated, please use getCurrentPage();
241 virtual SdPage
* GetActualPage() = 0;
244 current or selected page or 0.
246 virtual SdPage
* getCurrentPage() const = 0;
248 const rtl::Reference
<FuPoor
>& GetOldFunction() const { return mxOldFunction
; }
249 bool HasOldFunction() const { return mxOldFunction
.is(); }
250 const rtl::Reference
<FuPoor
>& GetCurrentFunction() const { return mxCurrentFunction
; }
251 bool HasCurrentFunction( sal_uInt16 nSID
) { return mxCurrentFunction
.is() && (mxCurrentFunction
->GetSlotID() == nSID
); }
252 bool HasCurrentFunction() const { return mxCurrentFunction
.is(); }
254 void SetCurrentFunction(const rtl::Reference
<FuPoor
>& xFunction
);
255 void SetOldFunction(const rtl::Reference
<FuPoor
>& xFunction
);
256 void DeactivateCurrentFunction( bool bPermanent
= false );
258 void SetPageSizeAndBorder(PageKind ePageKind
, const Size
& rNewSize
,
259 ::tools::Long nLeft
, ::tools::Long nRight
, ::tools::Long nUpper
, ::tools::Long nLower
,
260 bool bScaleAll
, Orientation eOrient
, sal_uInt16 nPaperBin
,
261 bool bBackgroundFullSize
);
263 void SetStartShowWithDialog( bool bIn
) { mbStartShowWithDialog
= bIn
; }
264 bool IsStartShowWithDialog() const { return mbStartShowWithDialog
; }
266 sal_uInt16
GetPrintedHandoutPageNum() const { return mnPrintedHandoutPageNum
; }
267 void SetPrintedHandoutPageNum (sal_uInt16 nPageNumber
) {mnPrintedHandoutPageNum
=nPageNumber
; }
269 sal_uInt16
GetPrintedHandoutPageCount() const { return mnPrintedHandoutPageCount
; }
270 void SetPrintedHandoutPageCount (sal_uInt16 nPageCount
) {mnPrintedHandoutPageCount
=nPageCount
; }
272 virtual bool PrepareClose( bool bUI
= true );
274 void GetMenuState(SfxItemSet
& rSet
);
276 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
, DropTargetHelper
& rTargetHelper
,
277 ::sd::Window
* pTargetWindow
, sal_uInt16 nPage
, SdrLayerID nLayer
);
278 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
, DropTargetHelper
& rTargetHelper
,
279 ::sd::Window
* pTargetWindow
, sal_uInt16 nPage
, SdrLayerID nLayer
);
281 virtual void WriteUserDataSequence ( css::uno::Sequence
< css::beans::PropertyValue
>& );
282 virtual void ReadUserDataSequence ( const css::uno::Sequence
< css::beans::PropertyValue
>& );
284 /** this method is called when the visible area of the view from this viewshell is changed */
285 virtual void VisAreaChanged(const ::tools::Rectangle
& rRect
);
287 /** Create an accessible object representing the specified window.
288 Override this method to provide view mode specific objects. The
289 default implementation returns an empty reference.
291 Make the document displayed in this window accessible.
293 This default implementation returns an empty reference.
295 virtual css::uno::Reference
<css::accessibility::XAccessible
>
296 CreateAccessibleDocumentView (::sd::Window
* pWindow
);
298 virtual void SwitchViewFireFocus( const css::uno::Reference
< css::accessibility::XAccessible
>& xAcc
);
299 void SwitchActiveViewFireFocus( );
300 // Move these two methods from DrawViewShell to enable slide show view
301 void NotifyAccUpdate();
302 void fireSwitchCurrentPage(sal_Int32 pageIndex
);
303 void SetWinViewPos(const Point
& rWinPos
);
304 Point
const & GetWinViewPos() const;
305 Point
const & GetViewOrigin() const;
307 /** Return the window updater of this view shell.
309 In rare circumstances the returned pointer may be <null/>,
310 i.e. when no memory is available anymore.
312 ::sd::WindowUpdater
* GetWindowUpdater() const;
314 /** Return the border that is drawn around the actual document view.
315 The border contains typically rulers and scroll bars.
317 SvBorder
GetBorder();
319 /** Notify the view shell that its parent window has been resized.
320 The ViewShell places and resizes its UI elements accordingly.
321 The new size can be obtained from the parent window.
323 virtual void Resize();
325 /** Set position and size of the GUI elements that are controlled by
326 the view shell like rulers and scroll bars as well as the actual
327 document view according to the position and size that were given
328 with the last Resize() call.
330 virtual void ArrangeGUIElements();
332 // virtual void OuterResizePixel(const Point &rPos, const Size &rSize);
333 // virtual void InnerResizePixel(const Point &rPos, const Size &rSize);
335 // Exported for unit test
336 SD_DLLPUBLIC ViewShellBase
& GetViewShellBase() const;
338 /** Return <TRUE/> when the called view shell is the main sub shell of
339 its ViewShellBase object, i.e. is display in the center pane. This
340 convenience function is equivalent to comparing the this pointer to
341 the result of ViewShellBase::GetViewShell(PT_CENTER).
343 bool IsMainViewShell() const;
345 /** Set or reset the flag that indicates whether the called shell is the
346 one displayed in the center pane. By default this flag is set to
347 <FALSE/>. For the main view shell it thus has to be set to <TRUE/>.
349 void SetIsMainViewShell (bool bIsMainViewShell
);
351 /** Return a sub controller that implements the view shell specific
352 part of the DrawController.
354 virtual css::uno::Reference
<css::drawing::XDrawSubController
> CreateSubController() = 0;
356 /** Return the type of the shell.
358 SD_DLLPUBLIC ShellType
GetShellType() const; //Export for unit test
360 /** This method is more or less an alias to Deactivate(). It is called
361 before an object of this class is taken from the stack of view
364 <p>When this method is not called before a view shell is taken from
365 a stack then the Deactivate() call from the SFX as a response to
366 RemoveSubShell() comes too late when the view shell is not on the
369 virtual void Shutdown();
371 /** This function is called from the underlying ViewShellBase
372 object to handle a verb execution request.
374 virtual ErrCode
DoVerb(sal_Int32 nVerb
);
376 virtual void UIActivating( SfxInPlaceClient
* );
377 virtual void UIDeactivated( SfxInPlaceClient
* );
379 /** Show controls of the UI or hide them, depending on the given flag.
380 As a result the border is adapted.
382 virtual void ShowUIControls (bool bVisible
);
383 bool IsPageFlipMode() const;
385 /** Set the given window as new parent window. This is not possible for
386 all views, so the return value tells the caller if the relocation
389 virtual bool RelocateToParentWindow (vcl::Window
* pParentWindow
);
391 /** Depending on the given request create a new page or duplicate an
392 existing one. A new page is created behind the given slide.
394 The request as passed to an Execute() method. Its arguments are
395 evaluated. Its slot id determines whether to create or
398 This page is either duplicated or becomes the predecessor of the
399 new slide. If NULL a duplication request is ignored. A new
400 slide is inserted as first slide.
401 @param nInsertPosition
402 When -1 (the default) then insert after pPage. Otherwise insert
403 before the given index (of a standard page).
405 The new slide is returned. If for some reason a new page can
406 not be created then NULL is returned.
408 virtual SdPage
* CreateOrDuplicatePage (
409 SfxRequest
& rRequest
,
412 const sal_Int32 nInsertPosition
= -1);
414 /// Allows adjusting the point or mark of the selection to a document coordinate.
415 void SetCursorMm100Position(const Point
& rPosition
, bool bPoint
, bool bClearMark
);
416 /// Gets the current selection
417 css::uno::Reference
<css::datatransfer::XTransferable
> GetSelectionTransferable() const;
418 /// Allows starting or ending a graphic move or resize action.
419 void SetGraphicMm100Position(bool bStart
, const Point
& rPosition
);
421 class Implementation
;
424 /** must be called in the beginning of each subclass d'tor.
425 disposes and clears both current and old function. */
426 void DisposeFunctions();
428 friend class ViewShellBase
;
430 /** Window inside the rulers and scroll bars that shows a view of the
434 VclPtr
<sd::Window
> mpContentWindow
;
436 /// Horizontal scroll bar for the current slide is displayed when needed.
437 VclPtr
<ScrollAdaptor
> mpHorizontalScrollBar
;
438 /// Vertical scroll bar for whole document is always visible.
439 VclPtr
<ScrollAdaptor
> mpVerticalScrollBar
;
440 /// Horizontal ruler is not shown by default.
441 VclPtr
<SvxRuler
> mpHorizontalRuler
;
442 /// Vertical ruler is not shown by default.
443 VclPtr
<SvxRuler
> mpVerticalRuler
;
445 VclPtr
<LayerTabBar
> mpLayerTabBar
;
447 /// This flag controls whether the rulers are visible.
450 /// The active window.
451 VclPtr
< ::sd::Window
> mpActiveWindow
;
453 FrameView
* mpFrameView
;
455 rtl::Reference
<FuPoor
> mxCurrentFunction
;
456 rtl::Reference
<FuPoor
> mxOldFunction
;
457 std::unique_ptr
<ZoomList
> mpZoomList
;
458 double mfLastZoomScale
;
459 double mfAccumulatedZoom
= 0;
465 bool mbStartShowWithDialog
; // presentation is started by dialog
466 sal_uInt16 mnPrintedHandoutPageNum
; // Page number of the handout page that is to be printed.
467 sal_uInt16 mnPrintedHandoutPageCount
; // Page count of the handout pages that are to be printed.
469 //af bool bPrintDirectSelected; // Print only selected objects in direct print
470 //afString sPageRange; // pagerange if selected objects in direct print
472 /** Area covered by all windows, i.e. the area of the parent window
473 without the controls at the borders like rulers, scroll bars, tab
475 This rectangle may be set in window coordinates (i.e. pixel values
476 relative to the parent window). It is transformed by every call to
477 GetAllWindowRectangle() into screen coordinates (relative to the
478 upper left corner of the screen.
480 ::tools::Rectangle maAllWindowRectangle
;
482 /// The type of the shell. Returned by GetShellType().
483 ShellType meShellType
;
485 std::unique_ptr
<Implementation
, o3tl::default_delete
<Implementation
>> mpImpl
;
487 // Support methods for centralized UNDO/REDO
488 virtual SfxUndoManager
* ImpGetUndoManager() const;
489 void ImpGetUndoStrings(SfxItemSet
&rSet
) const;
490 void ImpGetRedoStrings(SfxItemSet
&rSet
) const;
491 void ImpSidUndo(SfxRequest
& rReq
);
492 void ImpSidRedo(SfxRequest
& rReq
);
494 DECL_DLLPRIVATE_LINK( HScrollHdl
, weld::Scrollbar
&, void );
495 DECL_DLLPRIVATE_LINK( VScrollHdl
, weld::Scrollbar
&, void );
497 // virtual scroll handler, here, derivative classes can add themselves here
498 virtual void VirtHScrollHdl(ScrollAdaptor
* pHScroll
);
499 virtual void VirtVScrollHdl(ScrollAdaptor
* pVScroll
);
501 // virtual functions ruler handling
502 virtual VclPtr
<SvxRuler
> CreateHRuler(::sd::Window
* pWin
);
503 virtual VclPtr
<SvxRuler
> CreateVRuler(::sd::Window
* pWin
);
504 virtual void UpdateHRuler();
505 virtual void UpdateVRuler();
507 virtual void Activate(bool IsMDIActivate
) override
;
508 virtual void Deactivate(bool IsMDIActivate
) override
;
510 virtual void SetZoomFactor( const Fraction
&rZoomX
,
511 const Fraction
&rZoomY
);
514 This must be called after the ctor, but before anything else.
515 It's the part of construction that is dependent
516 on showing the top-level window.
518 Showing a window with a11y enabled causes various callbacks
521 Due to the "virtual methods are not virtual during constructors"
522 problem, this is a disaster to call from the ctor
524 i.e. construct calls Show, and if a11y is enabled this
525 reenters the not-fully constructed object and calls
526 CreateAccessibleDocumentView, so if construct is called
527 from the ctor then if a derived class is constructed the base-case
528 CreateAccessibleDocumentView is used, not the derived
529 CreateAccessibleDocumentView. i.e. run smoketest under a11y with
530 debugging assertions enabled
535 VclPtr
<vcl::Window
> mpParentWindow
;
536 /** This window updater is used to keep all relevant windows up to date
537 with reference to the digit language used to display digits in text
540 ::std::unique_ptr
< ::sd::WindowUpdater
> mpWindowUpdater
;
542 /** Code common to all constructors. It generally is a bad idea
543 to call this function from outside a constructor.
547 /** Create the rulers.
552 SdrView
* ViewShell::GetDrawView() const
554 return static_cast<SdrView
*>(mpView
);
557 } // end of namespace sd
559 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */