crashtesting: fix crash seen on loading forum-mso-de-98993.xlsx
[LibreOffice.git] / include / svx / svdpntv.hxx
blob557846fe01d84d30173d26f88be5ec2c7151d4e0
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 <svl/SfxBroadcaster.hxx>
23 #include <svl/lstner.hxx>
24 #include <svl/undo.hxx>
25 #include <svx/svddrag.hxx>
26 #include <svx/svdlayer.hxx>
27 #include <svtools/colorcfg.hxx>
28 #include <svl/itemset.hxx>
29 #include <svx/svxdllapi.h>
30 #include <unotools/options.hxx>
31 #include <vcl/event.hxx>
32 #include <vcl/idle.hxx>
33 #include <vcl/timer.hxx>
34 #include <memory>
37 // Pre defines
38 class SdrPageWindow;
40 namespace com::sun::star::awt {
41 class XControlContainer;
43 namespace sdr::overlay { class OverlayManager; }
45 class SdrPage;
46 class SdrView;
47 class SfxItemSet;
48 class SfxStyleSheet;
49 class SdrOle2Obj;
50 class SdrModel;
51 class SdrObject;
52 enum class GraphicManagerDrawFlags;
54 namespace sdr::contact {
55 class ViewObjectContactRedirector;
58 // Defines for AnimationMode
59 enum class SdrAnimationMode
61 Animate,
62 Disable
65 class SdrPaintView;
66 namespace sdr::contact { class ViewObjectContactRedirector; }
68 namespace vcl {
69 class Window;
73 class SvxViewChangedHint final : public SfxHint
75 public:
76 explicit SvxViewChangedHint();
79 class SdrPaintWindow;
81 /**
82 * Helper to convert any GDIMetaFile to a good quality BitmapEx,
83 * using default parameters and graphic::XPrimitive2DRenderer
85 BitmapEx convertMetafileToBitmapEx(
86 const GDIMetaFile& rMtf,
87 const basegfx::B2DRange& rTargetRange,
88 const sal_uInt32 nMaximumQuadraticPixels);
90 ////////////////////////////////////////////////////////////////////////////////////////////////////
92 // SdrPaintView
93 // SdrSnapView
94 // SdrMarkView
95 // SdrEditView
96 // SdrPolyEditView
97 // SdrGlueEditView
98 // SdrObjEditView
99 // SdrExchangeView
100 // SdrDragView
101 // SdrCreateView
102 // SdrView
103 // DlgEdView
104 // GraphCtrlView
105 // E3dView
106 // DrawViewWrapper
107 // FmFormView
108 // ScDrawView
109 // sd::View (may have more?)
110 // sd::DrawView
111 // SwDrawView
112 // OSectionView
114 class SVXCORE_DLLPUBLIC SdrPaintView : public SfxListener, public SfxRepeatTarget, public SfxBroadcaster, public ::utl::ConfigurationListener
116 private:
117 friend class SdrPageView;
118 friend class SdrGrafObj;
120 // the SdrModel this view was created with, unchanged during lifetime
121 SdrModel& mrSdrModelFromSdrView;
123 std::unique_ptr<SdrPageView> mpPageView;
124 protected:
125 SdrModel* mpModel;
126 VclPtr<OutputDevice> mpActualOutDev; // Only for comparison
127 VclPtr<OutputDevice> mpDragWin;
128 SfxStyleSheet* mpDefaultStyleSheet;
130 OUString maActualLayer; // Current drawing layer
131 OUString maMeasureLayer; // Current layer for measurements
133 // Container aPagV; // List of SdrPageViews
135 // All windows this view is displayed on
136 std::vector< std::unique_ptr<SdrPaintWindow> > maPaintWindows;
138 Size maGridBig; // FIXME: We need to get rid of this eventually
139 Size maGridFin; // FIXME: We need to get rid of this eventually
140 SdrDragStat maDragStat;
141 tools::Rectangle maMaxWorkArea;
142 SfxItemSet maDefaultAttr;
143 Idle maComeBackIdle;
145 SdrAnimationMode meAnimationMode;
147 sal_uInt16 mnHitTolPix;
148 sal_uInt16 mnMinMovPix;
149 sal_uInt16 mnHitTolLog;
150 sal_uInt16 mnMinMovLog;
152 bool mbPageVisible : 1;
153 bool mbPageShadowVisible : 1;
154 bool mbPageBorderVisible : 1;
155 bool mbBordVisible : 1;
156 bool mbGridVisible : 1;
157 bool mbGridFront : 1;
158 bool mbHlplVisible : 1;
159 bool mbHlplFront : 1;
160 bool mbGlueVisible : 1; // Persistent; show gluepoints
161 bool mbGlueVisible2 : 1; // Also show gluepoints for GluePointEdit
162 bool mbGlueVisible3 : 1; // Also show gluepoints for EdgeTool
163 bool mbGlueVisible4 : 1; // Show gluepoints, if one edge is selected
164 bool mbSomeObjChgdFlag : 1;
165 bool mbSwapAsynchron : 1;
166 bool mbPrintPreview : 1;
168 // These bools manage, the status that is displayed
170 bool mbAnimationPause : 1;
172 // Flag which decides if buffered output for this view is allowed. When
173 // set, PreRendering for PageView rendering will be used. Default is sal_False
174 bool mbBufferedOutputAllowed : 1;
176 // Flag which decides if buffered overlay for this view is allowed. When
177 // set, the output will be buffered in an overlay vdev. When not, overlay is
178 // directly painted to OutDev. Default is sal_False.
179 bool mbBufferedOverlayAllowed : 1;
181 // Allow page painting at all?
182 bool mbPagePaintingAllowed : 1;
184 // Is this a preview renderer?
185 bool mbPreviewRenderer : 1;
187 // Flags for calc and sw for suppressing OLE, CHART or DRAW objects
188 bool mbHideOle : 1;
189 bool mbHideChart : 1;
190 bool mbHideDraw : 1; // hide draw objects other than form controls
191 bool mbHideFormControl : 1; // hide form controls only
193 public:
194 // Interface for PagePaintingAllowed flag
195 bool IsBufferedOutputAllowed() const;
196 void SetBufferedOutputAllowed(bool bNew);
198 // Interface for BufferedOverlayAllowed flag
199 bool IsBufferedOverlayAllowed() const;
200 void SetBufferedOverlayAllowed(bool bNew);
202 // Allow page painting at all?
203 bool IsPagePaintingAllowed() const { return mbPagePaintingAllowed;}
204 void SetPagePaintingAllowed(bool bNew);
206 virtual rtl::Reference<sdr::overlay::OverlayManager> CreateOverlayManager(OutputDevice& rDevice) const;
208 protected:
209 svtools::ColorConfig maColorConfig;
210 Color maGridColor;
212 // Interface to SdrPaintWindow
213 void DeletePaintWindow(const SdrPaintWindow& rOld);
214 void ConfigurationChanged( ::utl::ConfigurationBroadcaster*, ConfigurationHints ) override;
215 static void InitOverlayManager(rtl::Reference<sdr::overlay::OverlayManager> xOverlayManager);
217 public:
218 sal_uInt32 PaintWindowCount() const { return maPaintWindows.size(); }
219 SdrPaintWindow* FindPaintWindow(const OutputDevice& rOut) const;
220 SdrPaintWindow* GetPaintWindow(sal_uInt32 nIndex) const;
221 // Replacement for GetWin(0), may return 0L (!)
222 OutputDevice* GetFirstOutputDevice() const;
224 private:
225 DECL_DLLPRIVATE_LINK(ImpComeBackHdl, Timer*, void);
227 protected:
228 sal_uInt16 ImpGetMinMovLogic(short nMinMov, const OutputDevice* pOut) const;
229 sal_uInt16 ImpGetHitTolLogic(short nHitTol, const OutputDevice* pOut) const;
231 // If one does not want to wait for the IdleState of the system (cheated as const)
232 void FlushComeBackTimer() const;
233 void TheresNewMapMode();
234 void ImpSetGlueVisible2(bool bOn) { if (mbGlueVisible2!=bOn) { mbGlueVisible2=bOn; if (!mbGlueVisible && !mbGlueVisible3 && !mbGlueVisible4) GlueInvalidate(); } }
235 void ImpSetGlueVisible3(bool bOn) { if (mbGlueVisible3!=bOn) { mbGlueVisible3=bOn; if (!mbGlueVisible && !mbGlueVisible2 && !mbGlueVisible4) GlueInvalidate(); } }
236 void ImpSetGlueVisible4(bool bOn) { if (mbGlueVisible4!=bOn) { mbGlueVisible4=bOn; if (!mbGlueVisible && !mbGlueVisible2 && !mbGlueVisible3) GlueInvalidate(); } }
238 public:
239 bool ImpIsGlueVisible() const { return mbGlueVisible || mbGlueVisible2 || mbGlueVisible3 || mbGlueVisible4; }
241 protected:
242 virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
243 void GlueInvalidate() const;
245 // ModelHasChanged is called, as soon as the system is idle again after many SdrHintKind::ObjectChange.
247 // Any sub-class override this method, MUST call the base class' ModelHasChanged() method
248 virtual void ModelHasChanged();
250 // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
251 // A SdrView always needs a SdrModel for lifetime (Pool, ...)
252 SdrPaintView(SdrModel& rSdrModel, OutputDevice* pOut);
253 virtual ~SdrPaintView() override;
255 public:
256 // SdrModel access on SdrView level
257 SdrModel& getSdrModelFromSdrView() const { return mrSdrModelFromSdrView; }
259 virtual void ClearPageView();
260 SdrModel* GetModel() const { return mpModel; }
262 virtual bool IsAction() const;
263 virtual void MovAction(const Point& rPnt);
264 virtual void EndAction();
265 virtual void BckAction();
266 virtual void BrkAction(); // Cancel all Actions (e.g. cancel dragging)
267 virtual void TakeActionRect(tools::Rectangle& rRect) const;
269 // Info about TextEdit. Default is sal_False.
270 virtual bool IsTextEdit() const;
272 // Must be called for every Window change as well as MapMode (Scaling) change:
273 // If the SdrView is shown in multiple windows at the same time (e.g.
274 // using the split pane), so that I can convert my pixel values to logical
275 // values.
276 void SetActualWin(const OutputDevice* pWin);
277 void SetMinMoveDistancePixel(sal_uInt16 nVal) { mnMinMovPix=nVal; TheresNewMapMode(); }
278 void SetHitTolerancePixel(sal_uInt16 nVal) { mnHitTolPix=nVal; TheresNewMapMode(); }
279 sal_uInt16 GetHitTolerancePixel() const { return mnHitTolPix; }
281 // Data read access on logic HitTolerance and MinMoveTolerance
282 sal_uInt16 getHitTolLog() const { return mnHitTolLog; }
284 // Using the DragState we can tell e.g. which distance was
285 // already dragged
286 const SdrDragStat& GetDragStat() const { return maDragStat; }
288 // Registering/de-registering a PageView at a View
290 // The same Page cannot be registered multiple times.
292 // Methods ending in PgNum expect being passed a Page number.
293 // Methods ending in PvNum, instead, expect the number of the
294 // PageView at the SdrView (iterating over all registered Pages).
295 virtual SdrPageView* ShowSdrPage(SdrPage* pPage);
296 virtual void HideSdrPage();
298 // Iterate over all registered PageViews
299 SdrPageView* GetSdrPageView() const { return mpPageView.get(); }
301 // A SdrView can be displayed on multiple Windows at the same time
302 virtual void AddWindowToPaintView(OutputDevice* pNewWin, vcl::Window* pWindow);
303 virtual void DeleteWindowFromPaintView(OutputDevice* pOldWin);
305 void SetLayerVisible(const OUString& rName, bool bShow);
306 bool IsLayerVisible(const OUString& rName) const;
308 void SetLayerLocked(const OUString& rName, bool bLock=true);
309 bool IsLayerLocked(const OUString& rName) const;
311 void SetLayerPrintable(const OUString& rName, bool bPrn);
312 bool IsLayerPrintable(const OUString& rName) const;
314 // PrePaint call forwarded from app windows
315 void PrePaint();
318 // Used internally for Draw/Impress/sch/chart2
319 virtual void CompleteRedraw(OutputDevice* pOut, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector = nullptr);
321 // #i72889# used from CompleteRedraw() implementation internally, added to be able to do a complete redraw in single steps
323 // BeginCompleteRedraw returns (or even creates) a SdrPaintWindow which will then be used as the
324 // target for paints. Since paints may be buffered, use its GetTargetOutputDevice() method which will
325 // return the buffer in case it's buffered.
327 // DoCompleteRedraw then draws the DrawingLayer hierarchy
328 // EndCompleteRedraw does the necessary refreshes, paints text edit and overlay as well as destroys the
329 // SdrPaintWindow again, if needed.
330 // This means: the SdrPaintWindow is no longer safe after this closing call.
331 virtual SdrPaintWindow* BeginCompleteRedraw(OutputDevice* pOut);
332 void DoCompleteRedraw(SdrPaintWindow& rPaintWindow, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector = nullptr);
333 virtual void EndCompleteRedraw(SdrPaintWindow& rPaintWindow, bool bPaintFormLayer);
336 // Used for the other applications basctl/sc/sw which call DrawLayer at PageViews
337 // #i74769# Interface change to use common BeginCompleteRedraw/EndCompleteRedraw
338 // #i76114# bDisableIntersect disables intersecting rReg with the Window's paint region
339 SdrPaintWindow* BeginDrawLayers(OutputDevice* pOut, const vcl::Region& rReg, bool bDisableIntersect = false);
341 // Used when the region passed to BeginDrawLayers needs to be changed
342 void UpdateDrawLayersRegion(const OutputDevice* pOut, const vcl::Region& rReg);
343 void EndDrawLayers(SdrPaintWindow& rPaintWindow, bool bPaintFormLayer);
345 protected:
347 // Used to paint the form layer after the PreRender device is flushed (painted) to the window.
348 void ImpFormLayerDrawing( SdrPaintWindow& rPaintWindow );
350 static vcl::Region OptimizeDrawLayersRegion(const OutputDevice* pOut, const vcl::Region& rReg, bool bDisableIntersect);
352 public:
353 /// Draw Page as a white area or not
354 bool IsPageVisible() const { return mbPageVisible; }
356 /// Draw Page shadow or not
357 bool IsPageShadowVisible() const { return mbPageShadowVisible; }
359 /// Draw Page as a white area or not
360 bool IsPageBorderVisible() const { return mbPageBorderVisible; }
362 /// Draw Border line or not
363 bool IsBordVisible() const { return mbBordVisible; }
365 /// Draw Grid or not
366 bool IsGridVisible() const { return mbGridVisible; }
368 /// Draw Grid in front of objects or behind them
369 bool IsGridFront() const { return mbGridFront ; }
371 /// Draw Help line of the Page or not
372 bool IsHlplVisible() const { return mbHlplVisible; }
374 /// Draw Help line in front of the objects or behind them
375 bool IsHlplFront() const { return mbHlplFront ; }
377 const Color& GetGridColor() const { return maGridColor;}
378 void SetPageVisible(bool bOn = true) { mbPageVisible=bOn; InvalidateAllWin(); }
379 void SetPageShadowVisible(bool bOn) { mbPageShadowVisible=bOn; InvalidateAllWin(); }
380 void SetPageBorderVisible(bool bOn = true) { mbPageBorderVisible=bOn; InvalidateAllWin(); }
381 void SetBordVisible(bool bOn = true) { mbBordVisible=bOn; InvalidateAllWin(); }
382 void SetGridVisible(bool bOn) { mbGridVisible=bOn; InvalidateAllWin(); }
383 void SetGridFront(bool bOn) { mbGridFront =bOn; InvalidateAllWin(); }
384 void SetHlplVisible(bool bOn = true) { mbHlplVisible=bOn; InvalidateAllWin(); }
385 void SetHlplFront(bool bOn) { mbHlplFront =bOn; InvalidateAllWin(); }
386 void SetGlueVisible(bool bOn = true) { if (mbGlueVisible!=bOn) { mbGlueVisible=bOn; if (!mbGlueVisible2 && !mbGlueVisible3 && !mbGlueVisible4) GlueInvalidate(); } }
388 bool IsPreviewRenderer() const { return mbPreviewRenderer; }
389 void SetPreviewRenderer(bool bOn) { mbPreviewRenderer=bOn; }
391 // Access methods for calc and sw hide object modes
392 bool getHideOle() const { return mbHideOle; }
393 bool getHideChart() const { return mbHideChart; }
394 bool getHideDraw() const { return mbHideDraw; }
395 bool getHideFormControl() const { return mbHideFormControl; }
396 void setHideOle(bool bNew) { if(bNew != mbHideOle) mbHideOle = bNew; }
397 void setHideChart(bool bNew) { if(bNew != mbHideChart) mbHideChart = bNew; }
398 void setHideDraw(bool bNew) { if(bNew != mbHideDraw) mbHideDraw = bNew; }
399 void setHideFormControl(bool bNew) { if(bNew != mbHideFormControl) mbHideFormControl = bNew; }
401 void SetGridCoarse(const Size& rSiz) { maGridBig=rSiz; }
402 void SetGridFine(const Size& rSiz) {
403 maGridFin=rSiz;
404 if (maGridFin.Height()==0) maGridFin.setHeight(maGridFin.Width());
405 if (mbGridVisible) InvalidateAllWin();
407 const Size& GetGridCoarse() const { return maGridBig; }
408 const Size& GetGridFine() const { return maGridFin; }
410 void InvalidateAllWin();
411 void InvalidateAllWin(const tools::Rectangle& rRect);
413 /// If the View should not call Invalidate() on the windows, override
414 /// the following 2 methods and do something else.
415 virtual void InvalidateOneWin(OutputDevice& rWin);
416 virtual void InvalidateOneWin(OutputDevice& rWin, const tools::Rectangle& rRect);
418 void SetActiveLayer(const OUString& rName) { maActualLayer=rName; }
419 const OUString& GetActiveLayer() const { return maActualLayer; }
421 /// Leave an object group of all visible Pages (like `chdir ..` in MS-DOS)
422 void LeaveOneGroup();
424 /// Leave all entered object groups of all visible Pages (like `chdir \` in MS-DOS)
425 void LeaveAllGroup();
427 /// Determine, whether Leave is useful or not
428 bool IsGroupEntered() const;
430 /// Default attributes at the View
431 /// Newly created objects are assigned these attributes by default when they are created.
432 void SetDefaultAttr(const SfxItemSet& rAttr, bool bReplaceAll);
433 const SfxItemSet& GetDefaultAttr() const { return maDefaultAttr; }
434 void SetDefaultStyleSheet(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr);
436 void SetNotPersistDefaultAttr(const SfxItemSet& rAttr);
437 void MergeNotPersistDefaultAttr(SfxItemSet& rAttr) const;
439 /// Execute a swap-in of e.g. graphics asynchronously.
440 /// This does not reload all graphics like Paint does, but kicks off
441 /// the loading there. When such an object is done loading, it is displayed.
442 /// TODO: Only works at the moment, if SwapGraphics is enabled in the model.
443 /// The default = false flag is non-persistent
444 bool IsSwapAsynchron() const { return mbSwapAsynchron; }
445 void SetSwapAsynchron(bool bJa=true) { mbSwapAsynchron=bJa; }
446 virtual bool KeyInput(const KeyEvent& rKEvt, vcl::Window* pWin);
448 virtual bool MouseButtonDown(const MouseEvent& /*rMEvt*/, OutputDevice* /*pWin*/) { return false; }
449 virtual bool MouseButtonUp(const MouseEvent& /*rMEvt*/, OutputDevice* /*pWin*/) { return false; }
450 virtual bool MouseMove(const MouseEvent& /*rMEvt*/, OutputDevice* /*pWin*/) { return false; }
451 virtual bool RequestHelp(const HelpEvent& /*rHEvt*/) { return false; }
452 virtual bool Command(const CommandEvent& /*rCEvt*/, vcl::Window* /*pWin*/) { return false; }
454 void GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAttr) const;
456 void SetAttributes(const SfxItemSet& rSet, bool bReplaceAll);
457 SfxStyleSheet* GetStyleSheet() const; // SfxStyleSheet* GetStyleSheet(bool& rOk) const;
458 void SetStyleSheet(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr);
460 virtual void MakeVisible(const tools::Rectangle& rRect, vcl::Window& rWin);
462 /// For Plugins
463 /// Is called by the Paint of the OLE object
464 virtual void DoConnect(SdrOle2Obj* pOleObj);
466 /// Enable/disable animations for ::Paint
467 /// Is used by e.g. SdrGrafObj, if it contains an animation
468 /// Preventing automatic animation is needed for e.g. the presentation view
469 bool IsAnimationEnabled() const { return ( SdrAnimationMode::Animate == meAnimationMode ); }
470 void SetAnimationEnabled( bool bEnable=true );
472 /// Set/unset pause state for animations
473 void SetAnimationPause( bool bSet );
475 /// Mode when starting an animation in the Paint Handler:
476 /// 1. SdrAnimationMode::Animate (default): start animation normally
477 /// 2. SDR_ANIMATION_DONT_ANIMATE: only show the replacement picture
478 /// 3. SdrAnimationMode::Disable: don't start and don't show any replacement
479 void SetAnimationMode( const SdrAnimationMode eMode );
481 /// Must be called by the App when scrolling etc. in order for
482 /// an active FormControl to be moved too
483 void VisAreaChanged(const OutputDevice* pOut);
484 void VisAreaChanged();
486 bool IsPrintPreview() const { return mbPrintPreview; }
487 void SetPrintPreview(bool bOn = true) { mbPrintPreview=bOn; }
489 const svtools::ColorConfig& getColorConfig() const { return maColorConfig;}
491 void onChangeColorConfig();
493 // #103834# Set background color for svx at SdrPageViews
494 void SetApplicationBackgroundColor(Color aBackgroundColor);
496 // #103911# Set document color for svx at SdrPageViews
497 void SetApplicationDocumentColor(Color aDocumentColor);
499 // #i38135#
500 // Sets the timer for Object animations and restarts.
501 void SetAnimationTimer(sal_uInt32 nTime);
504 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */