cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / inc / ViewShell.hxx
blob8b1292e554ad6fb19979dea3cf9c145612a77afb
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 #pragma once
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>
29 #include <pres.hxx>
30 #include "View.hxx"
31 #include "fupoor.hxx"
32 #include <sddllapi.h>
34 #include <memory>
36 class SdPage;
37 class SvxRuler;
38 class SdrOle2Obj; // for the ones, who have undefined parts of SVDRAW
39 class SdDrawDocument;
40 class SvxNumBulletItem;
42 namespace weld
44 class Window;
47 namespace com::sun::star::drawing { class XDrawSubController; }
49 namespace sd {
51 class DrawDocShell;
52 class FrameView;
53 class LayerTabBar;
54 class ViewShellBase;
55 class Window;
56 class WindowUpdater;
57 class ZoomList;
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
81 <ul>
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
85 frame.</li>
86 <ul></p>
88 <p>This class replaces the former ViewShell class.</p>
90 class SAL_DLLPUBLIC_RTTI ViewShell
91 : public SfxShell
93 public:
94 enum ShellType {
95 ST_NONE,
96 ST_DRAW, // The Draw application.
97 ST_IMPRESS, // Main view of the Impress application.
98 ST_NOTES,
99 ST_HANDOUT,
100 ST_OUTLINE,
101 ST_SLIDE_SORTER,
102 ST_PRESENTATION,
103 ST_SIDEBAR,
104 ST_NOTESPANEL
106 static const int MAX_HSPLIT_CNT = 1;
107 static const int MAX_VSPLIT_CNT = 1;
108 static const int MIN_SCROLLBAR_SIZE = 50;
111 ViewShell (
112 vcl::Window* pParentWindow,
113 ViewShellBase& rViewShellBase);
114 virtual ~ViewShell() override;
116 /** The Init method has to be called from the outside directly
117 after a new object of this class has been created. It can be
118 used for that part of the initialisation that can be run only
119 after the creation of the new object is finished. This
120 includes registration as listener at event broadcasters.
122 Derived classes should call this method at the head of their
123 Init() methods.
124 @param bIsMainViewShell
125 This flag tells the Init() method whether the new ViewShell will
126 be the main view shell.
128 virtual void Init (bool bIsMainViewShell);
130 /** The Exit() method has to be called before the destructor so that the
131 view shell is still a valid object and can safely call methods that
132 rely on that.
134 void Exit();
136 void Cancel();
138 /** Return the window that is the parent of all controls of this view
139 shell. This may or may not be the window of the frame.
141 vcl::Window* GetParentWindow() const { return mpParentWindow; }
143 sd::Window* GetContentWindow() const;
145 ::sd::View* GetView() const { return mpView; }
146 inline SdrView* GetDrawView() const;
147 SD_DLLPUBLIC DrawDocShell* GetDocSh() const;
149 SdDrawDocument* GetDoc() const;
151 SAL_RET_MAYBENULL SD_DLLPUBLIC SfxViewFrame* GetViewFrame() const;
153 /** The active window is usually the mpContentWindow. When there is a
154 show running then the active window is a ShowWindow.
156 ::sd::Window* GetActiveWindow() const { return mpActiveWindow;}
157 SD_DLLPUBLIC weld::Window* GetFrameWeld() const;
159 /** Set the active window. When the shell is displayed in the center
160 pane then the window of the ViewShellBase is also set to the given
161 window.
163 void SetActiveWindow (::sd::Window* pWindow);
165 /** Return the rectangle that encloses all windows of the view. That
166 excludes the controls in the frame like rulers, scroll bars, tab
167 bar, and buttons.
168 @return
169 The rectangle is returned in screen coordinates, i.e. pixel
170 values relative to the upper left corner of the screen?.
172 const ::tools::Rectangle& GetAllWindowRect();
174 // Mouse- & Key-Events
175 virtual void PrePaint();
176 virtual void Paint (const ::tools::Rectangle& rRect, ::sd::Window* pWin);
177 virtual bool KeyInput(const KeyEvent& rKEvt, ::sd::Window* pWin);
178 virtual void MouseMove(const MouseEvent& rMEvt, ::sd::Window* pWin);
179 virtual void MouseButtonUp(const MouseEvent& rMEvt, ::sd::Window* pWin);
180 virtual void MouseButtonDown(const MouseEvent& rMEvt, ::sd::Window* pWin);
181 virtual void Command(const CommandEvent& rCEvt, ::sd::Window* pWin);
182 bool RequestHelp( const HelpEvent& rEvt );
183 bool Notify( NotifyEvent const & rNEvt, ::sd::Window* pWin );
185 bool HandleScrollCommand(const CommandEvent& rCEvt, ::sd::Window* pWin);
187 void SetUIUnit(FieldUnit eUnit);
188 void SetDefTabHRuler( sal_uInt16 nDefTab );
190 const SvxNumBulletItem* GetNumBulletItem(SfxItemSet& aNewAttr, TypedWhichId<SvxNumBulletItem>& nNumItemId);
192 bool HasRuler() const { return mbHasRulers;}
193 void SetRuler(bool bRuler);
194 // Hides horizontal, vertical scrollbar as well as scrollbox
195 void SetScrollBarsVisible(bool bVisible);
197 /** Set internal values of all scroll bars that determine thumb size and
198 position. The external values like size and position of the scroll
199 bar controls are not modified.
201 virtual void UpdateScrollBars();
202 void Scroll(::tools::Long nX, ::tools::Long nY);
203 void ScrollLines(::tools::Long nX, ::tools::Long nY);
204 virtual void SetZoom(::tools::Long nZoom);
205 ::tools::Long GetZoom() const;
206 virtual void SetZoomRect(const ::tools::Rectangle& rZoomRect);
207 void InitWindows(const Point& rViewOrigin, const Size& rViewSize,
208 const Point& rWinPos, bool bUpdate = false);
209 void InvalidateWindows();
210 /** This method is still used by the OutlineViewShell to update the
211 model according to the content of the outline view. This in turn
212 updates the previews in the slide sorter.
214 virtual void UpdatePreview (SdPage* pPage);
216 void DrawMarkRect(const ::tools::Rectangle& rRect) const;
218 void ExecReq( SfxRequest &rReq );
220 ZoomList* GetZoomList() { return mpZoomList.get();}
222 FrameView* GetFrameView() { return mpFrameView; }
223 /** Setting a frame view triggers ReadFrameViewData() for the new
224 frame.
225 @param pFrameView
226 The new frame view that replaces the old one.
228 void SetFrameView (FrameView* pFrameView);
229 virtual void ReadFrameViewData(FrameView* pView);
230 virtual void WriteFrameViewData();
231 void WriteUserData();
232 void ReadUserData();
234 virtual bool ActivateObject(SdrOle2Obj* pObj, sal_Int32 nVerb);
236 /** @returns
237 current or selected page or 0. This method
238 will fail in master page mode.
240 @deprecated, please use getCurrentPage();
242 virtual SdPage* GetActualPage() = 0;
244 /** @returns
245 current or selected page or 0.
247 virtual SdPage* getCurrentPage() const = 0;
249 const rtl::Reference<FuPoor>& GetOldFunction() const { return mxOldFunction; }
250 bool HasOldFunction() const { return mxOldFunction.is(); }
251 const rtl::Reference<FuPoor>& GetCurrentFunction() const { return mxCurrentFunction; }
252 bool HasCurrentFunction( sal_uInt16 nSID ) { return mxCurrentFunction.is() && (mxCurrentFunction->GetSlotID() == nSID ); }
253 bool HasCurrentFunction() const { return mxCurrentFunction.is(); }
255 void SetCurrentFunction(const rtl::Reference<FuPoor>& xFunction);
256 void SetOldFunction(const rtl::Reference<FuPoor>& xFunction);
257 void DeactivateCurrentFunction( bool bPermanent = false );
259 void SetPageSizeAndBorder(PageKind ePageKind, const Size& rNewSize,
260 ::tools::Long nLeft, ::tools::Long nRight, ::tools::Long nUpper, ::tools::Long nLower,
261 bool bScaleAll, Orientation eOrient, sal_uInt16 nPaperBin,
262 bool bBackgroundFullSize );
264 void SetStartShowWithDialog( bool bIn ) { mbStartShowWithDialog = bIn; }
265 bool IsStartShowWithDialog() const { return mbStartShowWithDialog; }
267 sal_uInt16 GetPrintedHandoutPageNum() const { return mnPrintedHandoutPageNum; }
268 void SetPrintedHandoutPageNum (sal_uInt16 nPageNumber) {mnPrintedHandoutPageNum=nPageNumber; }
270 sal_uInt16 GetPrintedHandoutPageCount() const { return mnPrintedHandoutPageCount; }
271 void SetPrintedHandoutPageCount (sal_uInt16 nPageCount) {mnPrintedHandoutPageCount=nPageCount; }
273 virtual bool PrepareClose( bool bUI = true );
275 void GetMenuState(SfxItemSet& rSet);
277 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt, DropTargetHelper& rTargetHelper,
278 ::sd::Window* pTargetWindow, sal_uInt16 nPage, SdrLayerID nLayer );
279 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt, DropTargetHelper& rTargetHelper,
280 ::sd::Window* pTargetWindow, sal_uInt16 nPage, SdrLayerID nLayer );
282 virtual void WriteUserDataSequence ( css::uno::Sequence < css::beans::PropertyValue >& );
283 virtual void ReadUserDataSequence ( const css::uno::Sequence < css::beans::PropertyValue >& );
285 /** this method is called when the visible area of the view from this viewshell is changed */
286 virtual void VisAreaChanged(const ::tools::Rectangle& rRect);
288 /** Create an accessible object representing the specified window.
289 Override this method to provide view mode specific objects. The
290 default implementation returns an empty reference.
291 @param pWindow
292 Make the document displayed in this window accessible.
293 @return
294 This default implementation returns an empty reference.
296 virtual css::uno::Reference<css::accessibility::XAccessible>
297 CreateAccessibleDocumentView (::sd::Window* pWindow);
299 virtual void SwitchViewFireFocus( const css::uno::Reference< css::accessibility::XAccessible >& xAcc );
300 void SwitchActiveViewFireFocus( );
301 // Move these two methods from DrawViewShell to enable slide show view
302 void NotifyAccUpdate();
303 void fireSwitchCurrentPage(sal_Int32 pageIndex);
304 void SetWinViewPos(const Point& rWinPos);
305 Point const & GetWinViewPos() const;
306 Point const & GetViewOrigin() const;
308 /** Return the window updater of this view shell.
309 @return
310 In rare circumstances the returned pointer may be <null/>,
311 i.e. when no memory is available anymore.
313 ::sd::WindowUpdater* GetWindowUpdater() const;
315 /** Return the border that is drawn around the actual document view.
316 The border contains typically rulers and scroll bars.
318 SvBorder GetBorder();
320 /** Notify the view shell that its parent window has been resized.
321 The ViewShell places and resizes its UI elements accordingly.
322 The new size can be obtained from the parent window.
324 virtual void Resize();
326 /** Set position and size of the GUI elements that are controlled by
327 the view shell like rulers and scroll bars as well as the actual
328 document view according to the position and size that were given
329 with the last Resize() call.
331 virtual void ArrangeGUIElements();
333 // virtual void OuterResizePixel(const Point &rPos, const Size &rSize);
334 // virtual void InnerResizePixel(const Point &rPos, const Size &rSize);
336 // Exported for unit test
337 SD_DLLPUBLIC ViewShellBase& GetViewShellBase() const;
339 /** Return <TRUE/> when the called view shell is the main sub shell of
340 its ViewShellBase object, i.e. is display in the center pane. This
341 convenience function is equivalent to comparing the this pointer to
342 the result of ViewShellBase::GetViewShell(PT_CENTER).
344 bool IsMainViewShell() const;
346 /** Set or reset the flag that indicates whether the called shell is the
347 one displayed in the center pane. By default this flag is set to
348 <FALSE/>. For the main view shell it thus has to be set to <TRUE/>.
350 void SetIsMainViewShell (bool bIsMainViewShell);
352 /** Return a sub controller that implements the view shell specific
353 part of the DrawController.
355 virtual css::uno::Reference<css::drawing::XDrawSubController> CreateSubController() = 0;
357 /** Return the type of the shell.
359 SD_DLLPUBLIC ShellType GetShellType() const; //Export for unit test
361 /** This method is more or less an alias to Deactivate(). It is called
362 before an object of this class is taken from the stack of view
363 shells.
365 <p>When this method is not called before a view shell is taken from
366 a stack then the Deactivate() call from the SFX as a response to
367 RemoveSubShell() comes too late when the view shell is not on the
368 stack anymore.</p>
370 virtual void Shutdown();
372 /** This function is called from the underlying ViewShellBase
373 object to handle a verb execution request.
375 virtual ErrCode DoVerb(sal_Int32 nVerb);
377 virtual void UIActivating( SfxInPlaceClient* );
378 virtual void UIDeactivated( SfxInPlaceClient* );
380 /** Show controls of the UI or hide them, depending on the given flag.
381 As a result the border is adapted.
383 virtual void ShowUIControls (bool bVisible);
384 bool IsPageFlipMode() const;
385 bool CanPanAcrossPages() const;
387 /** Set the given window as new parent window. This is not possible for
388 all views, so the return value tells the caller if the relocation
389 was successful.
391 virtual bool RelocateToParentWindow (vcl::Window* pParentWindow);
393 /** Depending on the given request create a new page or duplicate an
394 existing one. A new page is created behind the given slide.
395 @param rRequest
396 The request as passed to an Execute() method. Its arguments are
397 evaluated. Its slot id determines whether to create or
398 duplicate a slide.
399 @param pPage
400 This page is either duplicated or becomes the predecessor of the
401 new slide. If NULL a duplication request is ignored. A new
402 slide is inserted as first slide.
403 @param nInsertPosition
404 When -1 (the default) then insert after pPage. Otherwise insert
405 before the given index (of a standard page).
406 @return
407 The new slide is returned. If for some reason a new page can
408 not be created then NULL is returned.
410 virtual SdPage* CreateOrDuplicatePage (
411 SfxRequest& rRequest,
412 PageKind ePageKind,
413 SdPage* pPage,
414 const sal_Int32 nInsertPosition = -1);
416 /** Called by sd::Window::LoseFocus to enable sd::ViewShell to take action
417 when focus is lost.
419 e.g. overriden by NotesPanelViewShell
421 virtual void onLoseFocus(){};
423 /** Called by sd::Window::GrabFocus to enable sd::ViewShell to take action
424 when focus is grabbed.
426 e.g. overriden by NotesPanelViewShell
428 virtual void onGrabFocus(){};
430 /// Allows adjusting the point or mark of the selection to a document coordinate.
431 void SetCursorMm100Position(const Point& rPosition, bool bPoint, bool bClearMark);
432 /// Gets the current selection
433 css::uno::Reference<css::datatransfer::XTransferable> GetSelectionTransferable() const;
434 /// Allows starting or ending a graphic move or resize action.
435 void SetGraphicMm100Position(bool bStart, const Point& rPosition);
437 class Implementation;
439 protected:
440 /** must be called in the beginning of each subclass d'tor.
441 disposes and clears both current and old function. */
442 void DisposeFunctions();
444 friend class ViewShellBase;
446 /** Window inside the rulers and scroll bars that shows a view of the
447 document.
450 VclPtr<sd::Window> mpContentWindow;
452 /// Horizontal scroll bar for the current slide is displayed when needed.
453 VclPtr<ScrollAdaptor> mpHorizontalScrollBar;
454 /// Vertical scroll bar for whole document is always visible.
455 VclPtr<ScrollAdaptor> mpVerticalScrollBar;
456 /// Horizontal ruler is not shown by default.
457 VclPtr<SvxRuler> mpHorizontalRuler;
458 /// Vertical ruler is not shown by default.
459 VclPtr<SvxRuler> mpVerticalRuler;
460 /// Layer tab bar.
461 VclPtr<LayerTabBar> mpLayerTabBar;
463 /// This flag controls whether the rulers are visible.
464 bool mbHasRulers;
466 /// The active window.
467 VclPtr< ::sd::Window> mpActiveWindow;
468 ::sd::View* mpView;
469 FrameView* mpFrameView;
471 rtl::Reference<FuPoor> mxCurrentFunction;
472 rtl::Reference<FuPoor> mxOldFunction;
473 std::unique_ptr<ZoomList> mpZoomList;
474 double mfLastZoomScale;
475 double mfAccumulatedZoom = 0;
477 Point maViewPos;
478 Size maViewSize;
479 Size maScrBarWH;
481 bool mbStartShowWithDialog; // presentation is started by dialog
482 sal_uInt16 mnPrintedHandoutPageNum; // Page number of the handout page that is to be printed.
483 sal_uInt16 mnPrintedHandoutPageCount; // Page count of the handout pages that are to be printed.
485 //af bool bPrintDirectSelected; // Print only selected objects in direct print
486 //afString sPageRange; // pagerange if selected objects in direct print
488 /** Area covered by all windows, i.e. the area of the parent window
489 without the controls at the borders like rulers, scroll bars, tab
490 bar, buttons.
491 This rectangle may be set in window coordinates (i.e. pixel values
492 relative to the parent window). It is transformed by every call to
493 GetAllWindowRectangle() into screen coordinates (relative to the
494 upper left corner of the screen.
496 ::tools::Rectangle maAllWindowRectangle;
498 /// The type of the shell. Returned by GetShellType().
499 ShellType meShellType;
501 std::unique_ptr<Implementation, o3tl::default_delete<Implementation>> mpImpl;
503 // Support methods for centralized UNDO/REDO
504 virtual SfxUndoManager* ImpGetUndoManager() const;
505 void ImpGetUndoStrings(SfxItemSet &rSet) const;
506 void ImpGetRedoStrings(SfxItemSet &rSet) const;
507 void ImpSidUndo(SfxRequest& rReq);
508 void ImpSidRedo(SfxRequest& rReq);
510 DECL_DLLPRIVATE_LINK( HScrollHdl, weld::Scrollbar&, void );
511 DECL_DLLPRIVATE_LINK( VScrollHdl, weld::Scrollbar&, void );
513 // virtual scroll handler, here, derivative classes can add themselves here
514 virtual void VirtHScrollHdl(ScrollAdaptor* pHScroll);
515 virtual void VirtVScrollHdl(ScrollAdaptor* pVScroll);
517 // virtual functions ruler handling
518 virtual VclPtr<SvxRuler> CreateHRuler(::sd::Window* pWin);
519 virtual VclPtr<SvxRuler> CreateVRuler(::sd::Window* pWin);
520 virtual void UpdateHRuler();
521 virtual void UpdateVRuler();
523 virtual void Activate(bool IsMDIActivate) override;
524 virtual void Deactivate(bool IsMDIActivate) override;
525 virtual void BroadcastContextForActivation (const bool bIsActivated) override;
527 virtual void SetZoomFactor( const Fraction &rZoomX,
528 const Fraction &rZoomY );
531 This must be called after the ctor, but before anything else.
532 It's the part of construction that is dependent
533 on showing the top-level window.
535 Showing a window with a11y enabled causes various callbacks
536 to be triggered.
538 Due to the "virtual methods are not virtual during constructors"
539 problem, this is a disaster to call from the ctor
541 i.e. construct calls Show, and if a11y is enabled this
542 reenters the not-fully constructed object and calls
543 CreateAccessibleDocumentView, so if construct is called
544 from the ctor then if a derived class is constructed the base-case
545 CreateAccessibleDocumentView is used, not the derived
546 CreateAccessibleDocumentView. i.e. run smoketest under a11y with
547 debugging assertions enabled
549 void doShow();
551 private:
552 VclPtr<vcl::Window> mpParentWindow;
553 /** This window updater is used to keep all relevant windows up to date
554 with reference to the digit language used to display digits in text
555 shapes.
557 ::std::unique_ptr< ::sd::WindowUpdater> mpWindowUpdater;
559 /** Code common to all constructors. It generally is a bad idea
560 to call this function from outside a constructor.
562 void construct();
564 /** Create the rulers.
566 void SetupRulers();
568 // IASS: Check if commands should be used for SlideShow
569 bool useInputForSlideShow() const;
572 SdrView* ViewShell::GetDrawView() const
574 return static_cast<SdrView*>(mpView);
577 } // end of namespace sd
579 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */