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 .
20 #ifndef INCLUDED_SVX_SVDPNTV_HXX
21 #define INCLUDED_SVX_SVDPNTV_HXX
23 #include <svl/SfxBroadcaster.hxx>
24 #include <svl/lstner.hxx>
25 #include <svl/undo.hxx>
26 #include <svx/svddrag.hxx>
27 #include <svx/svdlayer.hxx>
28 #include <vcl/window.hxx>
29 #include <svtools/colorcfg.hxx>
30 #include <svl/itemset.hxx>
31 #include <vcl/timer.hxx>
32 #include <svx/svxdllapi.h>
33 #include <svtools/optionsdrawinglayer.hxx>
34 #include <unotools/options.hxx>
35 #include <vcl/idle.hxx>
42 namespace com::sun::star::awt
{
43 class XControlContainer
;
45 namespace sdr::overlay
{ class OverlayManager
; }
54 enum class GraphicManagerDrawFlags
;
56 namespace sdr::contact
{
57 class ViewObjectContactRedirector
;
61 // Defines for AnimationMode
62 enum class SdrAnimationMode
70 namespace sdr::contact
{ class ViewObjectContactRedirector
; }
74 class SvxViewChangedHint final
: public SfxHint
77 explicit SvxViewChangedHint();
83 * Helper to convert any GDIMetaFile to a good quality BitmapEx,
84 * using default parameters and graphic::XPrimitive2DRenderer
86 BitmapEx
convertMetafileToBitmapEx(
87 const GDIMetaFile
& rMtf
,
88 const basegfx::B2DRange
& rTargetRange
,
89 const sal_uInt32 nMaximumQuadraticPixels
);
91 ////////////////////////////////////////////////////////////////////////////////////////////////////
110 // sd::View (may have more?)
115 class SVXCORE_DLLPUBLIC SdrPaintView
: public SfxListener
, public SfxRepeatTarget
, public SfxBroadcaster
, public ::utl::ConfigurationListener
118 friend class SdrPageView
;
119 friend class SdrGrafObj
;
121 // the SdrModel this view was created with, unchanged during lifetime
122 SdrModel
& mrSdrModelFromSdrView
;
124 std::unique_ptr
<SdrPageView
> mpPageView
;
127 VclPtr
<OutputDevice
> mpActualOutDev
; // Only for comparison
128 VclPtr
<OutputDevice
> mpDragWin
;
129 SfxStyleSheet
* mpDefaultStyleSheet
;
131 OUString maActualLayer
; // Current drawing layer
132 OUString maMeasureLayer
; // Current layer for measurements
134 // Container aPagV; // List of SdrPageViews
136 // All windows this view is displayed on
137 std::vector
< std::unique_ptr
<SdrPaintWindow
> > maPaintWindows
;
139 Size maGridBig
; // FIXME: We need to get rid of this eventually
140 Size maGridFin
; // FIXME: We need to get rid of this eventually
141 SdrDragStat maDragStat
;
142 tools::Rectangle maMaxWorkArea
;
143 SfxItemSet maDefaultAttr
;
146 SdrAnimationMode meAnimationMode
;
148 sal_uInt16 mnHitTolPix
;
149 sal_uInt16 mnMinMovPix
;
150 sal_uInt16 mnHitTolLog
;
151 sal_uInt16 mnMinMovLog
;
153 // Hold an incarnation of Drawinglayer configuration options
154 SvtOptionsDrawinglayer maDrawinglayerOpt
;
156 bool mbPageVisible
: 1;
157 bool mbPageShadowVisible
: 1;
158 bool mbPageBorderVisible
: 1;
159 bool mbBordVisible
: 1;
160 bool mbGridVisible
: 1;
161 bool mbGridFront
: 1;
162 bool mbHlplVisible
: 1;
163 bool mbHlplFront
: 1;
164 bool mbGlueVisible
: 1; // Persistent; show glue points
165 bool mbGlueVisible2
: 1; // Also show glue points for GluePointEdit
166 bool mbGlueVisible3
: 1; // Also show glue points for EdgeTool
167 bool mbGlueVisible4
: 1; // Show glue points, if one edge is selected
168 bool mbSomeObjChgdFlag
: 1;
169 bool mbSwapAsynchron
: 1;
170 bool mbPrintPreview
: 1;
172 // These bools manage, the status that is displayed
174 bool mbAnimationPause
: 1;
176 // Flag which decides if buffered output for this view is allowed. When
177 // set, PreRendering for PageView rendering will be used. Default is sal_False
178 bool mbBufferedOutputAllowed
: 1;
180 // Flag which decides if buffered overlay for this view is allowed. When
181 // set, the output will be buffered in an overlay vdev. When not, overlay is
182 // directly painted to OutDev. Default is sal_False.
183 bool mbBufferedOverlayAllowed
: 1;
185 // Allow page painting at all?
186 bool mbPagePaintingAllowed
: 1;
188 // Is this a preview renderer?
189 bool mbPreviewRenderer
: 1;
191 // Flags for calc and sw for suppressing OLE, CHART or DRAW objects
193 bool mbHideChart
: 1;
194 bool mbHideDraw
: 1; // hide draw objects other than form controls
195 bool mbHideFormControl
: 1; // hide form controls only
198 // Interface for PagePaintingAllowed flag
199 bool IsBufferedOutputAllowed() const;
200 void SetBufferedOutputAllowed(bool bNew
);
202 // Interface for BufferedOverlayAllowed flag
203 bool IsBufferedOverlayAllowed() const;
204 void SetBufferedOverlayAllowed(bool bNew
);
206 // Allow page painting at all?
207 bool IsPagePaintingAllowed() const { return mbPagePaintingAllowed
;}
208 void SetPagePaintingAllowed(bool bNew
);
210 virtual rtl::Reference
<sdr::overlay::OverlayManager
> CreateOverlayManager(OutputDevice
& rDevice
) const;
213 svtools::ColorConfig maColorConfig
;
216 // Interface to SdrPaintWindow
217 void DeletePaintWindow(SdrPaintWindow
& rOld
);
218 void ConfigurationChanged( ::utl::ConfigurationBroadcaster
*, ConfigurationHints
) override
;
219 void InitOverlayManager(rtl::Reference
<sdr::overlay::OverlayManager
> xOverlayManager
) const;
222 sal_uInt32
PaintWindowCount() const { return maPaintWindows
.size(); }
223 SdrPaintWindow
* FindPaintWindow(const OutputDevice
& rOut
) const;
224 SdrPaintWindow
* GetPaintWindow(sal_uInt32 nIndex
) const;
225 // Replacement for GetWin(0), may return 0L (!)
226 OutputDevice
* GetFirstOutputDevice() const;
229 DECL_LINK(ImpComeBackHdl
, Timer
*, void);
232 sal_uInt16
ImpGetMinMovLogic(short nMinMov
, const OutputDevice
* pOut
) const;
233 sal_uInt16
ImpGetHitTolLogic(short nHitTol
, const OutputDevice
* pOut
) const;
235 // If one does not want to wait for the IdleState of the system (cheated as const)
236 void FlushComeBackTimer() const;
237 void TheresNewMapMode();
238 void ImpSetGlueVisible2(bool bOn
) { if (mbGlueVisible2
!=bOn
) { mbGlueVisible2
=bOn
; if (!mbGlueVisible
&& !mbGlueVisible3
&& !mbGlueVisible4
) GlueInvalidate(); } }
239 void ImpSetGlueVisible3(bool bOn
) { if (mbGlueVisible3
!=bOn
) { mbGlueVisible3
=bOn
; if (!mbGlueVisible
&& !mbGlueVisible2
&& !mbGlueVisible4
) GlueInvalidate(); } }
240 void ImpSetGlueVisible4(bool bOn
) { if (mbGlueVisible4
!=bOn
) { mbGlueVisible4
=bOn
; if (!mbGlueVisible
&& !mbGlueVisible2
&& !mbGlueVisible3
) GlueInvalidate(); } }
243 bool ImpIsGlueVisible() { return mbGlueVisible
|| mbGlueVisible2
|| mbGlueVisible3
|| mbGlueVisible4
; }
246 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
247 void GlueInvalidate() const;
249 // ModelHasChanged is called, as soon as the system is idle again after many SdrHintKind::ObjectChange.
251 // Any sub-class override this method, MUST call the base class' ModelHasChanged() method
252 virtual void ModelHasChanged();
254 // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
255 // A SdrView always needs a SdrModel for lifetime (Pool, ...)
256 SdrPaintView(SdrModel
& rSdrModel
, OutputDevice
* pOut
);
257 virtual ~SdrPaintView() override
;
260 // SdrModel access on SdrView level
261 SdrModel
& getSdrModelFromSdrView() const { return mrSdrModelFromSdrView
; }
263 virtual void ClearPageView();
264 SdrModel
* GetModel() const { return mpModel
; }
266 virtual bool IsAction() const;
267 virtual void MovAction(const Point
& rPnt
);
268 virtual void EndAction();
269 virtual void BckAction();
270 virtual void BrkAction(); // Cancel all Actions (e.g. cancel dragging)
271 virtual void TakeActionRect(tools::Rectangle
& rRect
) const;
273 // Info about TextEdit. Default is sal_False.
274 virtual bool IsTextEdit() const;
276 // Must be called for every Window change as well as MapMode (Scaling) change:
277 // If the SdrView is shown in multiple windows at the same time (e.g.
278 // using the split pane), so that I can convert my pixel values to logical
280 void SetActualWin(const OutputDevice
* pWin
);
281 void SetMinMoveDistancePixel(sal_uInt16 nVal
) { mnMinMovPix
=nVal
; TheresNewMapMode(); }
282 void SetHitTolerancePixel(sal_uInt16 nVal
) { mnHitTolPix
=nVal
; TheresNewMapMode(); }
283 sal_uInt16
GetHitTolerancePixel() const { return mnHitTolPix
; }
285 // Data read access on logic HitTolerance and MinMoveTolerance
286 sal_uInt16
getHitTolLog() const { return mnHitTolLog
; }
288 // Using the DragState we can tell e.g. which distance was
290 const SdrDragStat
& GetDragStat() const { return maDragStat
; }
292 // Registering/de-registering a PageView at a View
294 // The same Page cannot be registered multiple times.
296 // Methods ending in PgNum expect being passed a Page number.
297 // Methods ending in PvNum, instead, expect the number of the
298 // PageView at the SdrView (iterating over all registered Pages).
299 virtual SdrPageView
* ShowSdrPage(SdrPage
* pPage
);
300 virtual void HideSdrPage();
302 // Iterate over all registered PageViews
303 SdrPageView
* GetSdrPageView() const { return mpPageView
.get(); }
305 // A SdrView can be displayed on multiple Windows at the same time
306 virtual void AddWindowToPaintView(OutputDevice
* pNewWin
, vcl::Window
* pWindow
);
307 virtual void DeleteWindowFromPaintView(OutputDevice
* pOldWin
);
309 void SetLayerVisible(const OUString
& rName
, bool bShow
);
310 bool IsLayerVisible(const OUString
& rName
) const;
312 void SetLayerLocked(const OUString
& rName
, bool bLock
=true);
313 bool IsLayerLocked(const OUString
& rName
) const;
315 void SetLayerPrintable(const OUString
& rName
, bool bPrn
);
316 bool IsLayerPrintable(const OUString
& rName
) const;
318 // PrePaint call forwarded from app windows
322 // Used internally for Draw/Impress/sch/chart2
323 virtual void CompleteRedraw(OutputDevice
* pOut
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
= nullptr);
325 // #i72889# used from CompleteRedraw() implementation internally, added to be able to do a complete redraw in single steps
327 // BeginCompleteRedraw returns (or even creates) a SdrPaintWindow which will then be used as the
328 // target for paints. Since paints may be buffered, use its GetTargetOutputDevice() method which will
329 // return the buffer in case it's buffered.
331 // DoCompleteRedraw then draws the DrawingLayer hierarchy
332 // EndCompleteRedraw does the necessary refreshes, paints text edit and overlay as well as destroys the
333 // SdrPaintWindow again, if needed.
334 // This means: the SdrPaintWindow is no longer safe after this closing call.
335 virtual SdrPaintWindow
* BeginCompleteRedraw(OutputDevice
* pOut
);
336 void DoCompleteRedraw(SdrPaintWindow
& rPaintWindow
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
= nullptr);
337 virtual void EndCompleteRedraw(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
);
340 // Used for the other applications basctl/sc/sw which call DrawLayer at PageViews
341 // #i74769# Interface change to use common BeginCompleteRedraw/EndCompleteRedraw
342 // #i76114# bDisableIntersect disables intersecting rReg with the Window's paint region
343 SdrPaintWindow
* BeginDrawLayers(OutputDevice
* pOut
, const vcl::Region
& rReg
, bool bDisableIntersect
= false);
345 // Used when the region passed to BeginDrawLayers needs to be changed
346 void UpdateDrawLayersRegion(OutputDevice
* pOut
, const vcl::Region
& rReg
);
347 void EndDrawLayers(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
);
351 // Used to paint the form layer after the PreRender device is flushed (painted) to the window.
352 void ImpFormLayerDrawing( SdrPaintWindow
& rPaintWindow
);
354 static vcl::Region
OptimizeDrawLayersRegion(OutputDevice
* pOut
, const vcl::Region
& rReg
, bool bDisableIntersect
);
357 /// Draw Page as a white area or not
358 bool IsPageVisible() const { return mbPageVisible
; }
360 /// Draw Page shadow or not
361 bool IsPageShadowVisible() const { return mbPageShadowVisible
; }
363 /// Draw Page as a white area or not
364 bool IsPageBorderVisible() const { return mbPageBorderVisible
; }
366 /// Draw Border line or not
367 bool IsBordVisible() const { return mbBordVisible
; }
370 bool IsGridVisible() const { return mbGridVisible
; }
372 /// Draw Grid in front of objects or behind them
373 bool IsGridFront() const { return mbGridFront
; }
375 /// Draw Help line of the Page or not
376 bool IsHlplVisible() const { return mbHlplVisible
; }
378 /// Draw Help line in front of the objects or behind them
379 bool IsHlplFront() const { return mbHlplFront
; }
381 const Color
& GetGridColor() const { return maGridColor
;}
382 void SetPageVisible(bool bOn
= true) { mbPageVisible
=bOn
; InvalidateAllWin(); }
383 void SetPageShadowVisible(bool bOn
) { mbPageShadowVisible
=bOn
; InvalidateAllWin(); }
384 void SetPageBorderVisible(bool bOn
= true) { mbPageBorderVisible
=bOn
; InvalidateAllWin(); }
385 void SetBordVisible(bool bOn
= true) { mbBordVisible
=bOn
; InvalidateAllWin(); }
386 void SetGridVisible(bool bOn
) { mbGridVisible
=bOn
; InvalidateAllWin(); }
387 void SetGridFront(bool bOn
) { mbGridFront
=bOn
; InvalidateAllWin(); }
388 void SetHlplVisible(bool bOn
= true) { mbHlplVisible
=bOn
; InvalidateAllWin(); }
389 void SetHlplFront(bool bOn
) { mbHlplFront
=bOn
; InvalidateAllWin(); }
390 void SetGlueVisible(bool bOn
= true) { if (mbGlueVisible
!=bOn
) { mbGlueVisible
=bOn
; if (!mbGlueVisible2
&& !mbGlueVisible3
&& !mbGlueVisible4
) GlueInvalidate(); } }
392 bool IsPreviewRenderer() const { return mbPreviewRenderer
; }
393 void SetPreviewRenderer(bool bOn
) { mbPreviewRenderer
=bOn
; }
395 // Access methods for calc and sw hide object modes
396 bool getHideOle() const { return mbHideOle
; }
397 bool getHideChart() const { return mbHideChart
; }
398 bool getHideDraw() const { return mbHideDraw
; }
399 bool getHideFormControl() const { return mbHideFormControl
; }
400 void setHideOle(bool bNew
) { if(bNew
!= mbHideOle
) mbHideOle
= bNew
; }
401 void setHideChart(bool bNew
) { if(bNew
!= mbHideChart
) mbHideChart
= bNew
; }
402 void setHideDraw(bool bNew
) { if(bNew
!= mbHideDraw
) mbHideDraw
= bNew
; }
403 void setHideFormControl(bool bNew
) { if(bNew
!= mbHideFormControl
) mbHideFormControl
= bNew
; }
405 void SetGridCoarse(const Size
& rSiz
) { maGridBig
=rSiz
; }
406 void SetGridFine(const Size
& rSiz
) {
408 if (maGridFin
.Height()==0) maGridFin
.setHeight(maGridFin
.Width());
409 if (mbGridVisible
) InvalidateAllWin();
411 const Size
& GetGridCoarse() const { return maGridBig
; }
412 const Size
& GetGridFine() const { return maGridFin
; }
414 void InvalidateAllWin();
415 void InvalidateAllWin(const tools::Rectangle
& rRect
);
417 /// If the View should not call Invalidate() on the windows, override
418 /// the following 2 methods and do something else.
419 virtual void InvalidateOneWin(OutputDevice
& rWin
);
420 virtual void InvalidateOneWin(OutputDevice
& rWin
, const tools::Rectangle
& rRect
);
422 void SetActiveLayer(const OUString
& rName
) { maActualLayer
=rName
; }
423 const OUString
& GetActiveLayer() const { return maActualLayer
; }
425 /// Leave an object group of all visible Pages (like `chdir ..` in MS-DOS)
426 void LeaveOneGroup();
428 /// Leave all entered object groups of all visible Pages (like `chdir \` in MS-DOS)
429 void LeaveAllGroup();
431 /// Determine, whether Leave is useful or not
432 bool IsGroupEntered() const;
434 /// Default attributes at the View
435 /// Newly created objects are assigned these attributes by default when they are created.
436 void SetDefaultAttr(const SfxItemSet
& rAttr
, bool bReplaceAll
);
437 const SfxItemSet
& GetDefaultAttr() const { return maDefaultAttr
; }
438 void SetDefaultStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
);
440 void SetNotPersistDefaultAttr(const SfxItemSet
& rAttr
);
441 void MergeNotPersistDefaultAttr(SfxItemSet
& rAttr
) const;
443 /// Execute a swap-in of e.g. graphics asynchronously.
444 /// This does not reload all graphics like Paint does, but kicks off
445 /// the loading there. When such an object is done loading, it is displayed.
446 /// TODO: Only works at the moment, if SwapGraphics is enabled in the model.
447 /// The default = false flag is non-persistent
448 bool IsSwapAsynchron() const { return mbSwapAsynchron
; }
449 void SetSwapAsynchron(bool bJa
=true) { mbSwapAsynchron
=bJa
; }
450 virtual bool KeyInput(const KeyEvent
& rKEvt
, vcl::Window
* pWin
);
452 virtual bool MouseButtonDown(const MouseEvent
& /*rMEvt*/, OutputDevice
* /*pWin*/) { return false; }
453 virtual bool MouseButtonUp(const MouseEvent
& /*rMEvt*/, OutputDevice
* /*pWin*/) { return false; }
454 virtual bool MouseMove(const MouseEvent
& /*rMEvt*/, OutputDevice
* /*pWin*/) { return false; }
455 virtual bool RequestHelp(const HelpEvent
& /*rHEvt*/) { return false; }
456 virtual bool Command(const CommandEvent
& /*rCEvt*/, vcl::Window
* /*pWin*/) { return false; }
458 void GetAttributes(SfxItemSet
& rTargetSet
, bool bOnlyHardAttr
) const;
460 void SetAttributes(const SfxItemSet
& rSet
, bool bReplaceAll
);
461 SfxStyleSheet
* GetStyleSheet() const; // SfxStyleSheet* GetStyleSheet(bool& rOk) const;
462 void SetStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
);
464 virtual void MakeVisible(const tools::Rectangle
& rRect
, vcl::Window
& rWin
);
467 /// Is called by the Paint of the OLE object
468 virtual void DoConnect(SdrOle2Obj
* pOleObj
);
470 /// Enable/disable animations for ::Paint
471 /// Is used by e.g. SdrGrafObj, if it contains an animation
472 /// Preventing automatic animation is needed for e.g. the presentation view
473 bool IsAnimationEnabled() const { return ( SdrAnimationMode::Animate
== meAnimationMode
); }
474 void SetAnimationEnabled( bool bEnable
=true );
476 /// Set/unset pause state for animations
477 void SetAnimationPause( bool bSet
);
479 /// Mode when starting an animation in the Paint Handler:
480 /// 1. SdrAnimationMode::Animate (default): start animation normally
481 /// 2. SDR_ANIMATION_DONT_ANIMATE: only show the replacement picture
482 /// 3. SdrAnimationMode::Disable: don't start and don't show any replacement
483 void SetAnimationMode( const SdrAnimationMode eMode
);
485 /// Must be called by the App when scrolling etc. in order for
486 /// an active FormControl to be moved too
487 void VisAreaChanged(const OutputDevice
* pOut
);
488 void VisAreaChanged();
490 bool IsPrintPreview() const { return mbPrintPreview
; }
491 void SetPrintPreview(bool bOn
= true) { mbPrintPreview
=bOn
; }
493 const svtools::ColorConfig
& getColorConfig() const { return maColorConfig
;}
495 void onChangeColorConfig();
497 // #103834# Set background color for svx at SdrPageViews
498 void SetApplicationBackgroundColor(Color aBackgroundColor
);
500 // #103911# Set document color for svx at SdrPageViews
501 void SetApplicationDocumentColor(Color aDocumentColor
);
504 // Sets the timer for Object animations and restarts.
505 void SetAnimationTimer(sal_uInt32 nTime
);
507 // Access to Drawinglayer configuration options
508 const SvtOptionsDrawinglayer
& getOptionsDrawinglayer() const { return maDrawinglayerOpt
; }
511 #endif // INCLUDED_SVX_SVDPNTV_HXX
513 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */