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 <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>
40 namespace com::sun::star::awt
{
41 class XControlContainer
;
43 namespace sdr::overlay
{ class OverlayManager
; }
52 enum class GraphicManagerDrawFlags
;
54 namespace sdr::contact
{
55 class ViewObjectContactRedirector
;
58 // Defines for AnimationMode
59 enum class SdrAnimationMode
66 namespace sdr::contact
{ class ViewObjectContactRedirector
; }
73 class SvxViewChangedHint final
: public SfxHint
76 explicit SvxViewChangedHint();
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 ////////////////////////////////////////////////////////////////////////////////////////////////////
109 // sd::View (may have more?)
114 class SVXCORE_DLLPUBLIC SdrPaintView
: public SfxListener
, public SfxRepeatTarget
, public SfxBroadcaster
, public ::utl::ConfigurationListener
117 friend class SdrPageView
;
118 friend class SdrGrafObj
;
120 // the SdrModel this view was created with, unchanged during lifetime
123 std::unique_ptr
<SdrPageView
> mpPageView
;
125 VclPtr
<OutputDevice
> mpActualOutDev
; // Only for comparison
126 VclPtr
<OutputDevice
> mpDragWin
;
127 SfxStyleSheet
* mpDefaultStyleSheet
;
129 OUString maActualLayer
; // Current drawing layer
130 OUString maMeasureLayer
; // Current layer for measurements
132 // Container aPagV; // List of SdrPageViews
134 // All windows this view is displayed on
135 std::vector
<std::unique_ptr
<SdrPaintWindow
>> maPaintWindows
;
137 Size maGridBig
; // FIXME: We need to get rid of this eventually
138 Size maGridFin
; // FIXME: We need to get rid of this eventually
139 SdrDragStat maDragStat
;
140 tools::Rectangle maMaxWorkArea
;
141 SfxItemSet maDefaultAttr
;
144 SdrAnimationMode meAnimationMode
;
146 sal_uInt16 mnHitTolPix
;
147 sal_uInt16 mnMinMovPix
;
148 sal_uInt16 mnHitTolLog
;
149 sal_uInt16 mnMinMovLog
;
151 bool mbPageVisible
: 1;
152 bool mbPageShadowVisible
: 1;
153 bool mbPageBorderVisible
: 1;
154 bool mbBordVisible
: 1;
155 bool mbGridVisible
: 1;
156 bool mbGridFront
: 1;
157 bool mbHlplVisible
: 1;
158 bool mbHlplFront
: 1;
159 bool mbGlueVisible
: 1; // Persistent; show gluepoints
160 bool mbGlueVisible2
: 1; // Also show gluepoints for GluePointEdit
161 bool mbGlueVisible3
: 1; // Also show gluepoints for EdgeTool
162 bool mbGlueVisible4
: 1; // Show gluepoints, if one edge is selected
163 bool mbSomeObjChgdFlag
: 1;
164 bool mbSwapAsynchron
: 1;
165 bool mbPrintPreview
: 1;
167 // These bools manage, the status that is displayed
169 bool mbAnimationPause
: 1;
171 // Flag which decides if buffered output for this view is allowed. When
172 // set, PreRendering for PageView rendering will be used. Default is sal_False
173 bool mbBufferedOutputAllowed
: 1;
175 // Flag which decides if buffered overlay for this view is allowed. When
176 // set, the output will be buffered in an overlay vdev. When not, overlay is
177 // directly painted to OutDev. Default is sal_False.
178 bool mbBufferedOverlayAllowed
: 1;
180 // Allow page painting at all?
181 bool mbPagePaintingAllowed
: 1;
183 // Is this a preview renderer?
184 bool mbPreviewRenderer
: 1;
186 // Flags for calc and sw for suppressing OLE, CHART or DRAW objects
188 bool mbHideChart
: 1;
189 bool mbHideDraw
: 1; // hide draw objects other than form controls
190 bool mbHideFormControl
: 1; // hide form controls only
191 bool mbPaintTextEdit
: 1; // if should paint currently edited text
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;
209 svtools::ColorConfig maColorConfig
;
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
);
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;
225 DECL_DLLPRIVATE_LINK(ImpComeBackHdl
, Timer
*, void);
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(); } }
239 bool ImpIsGlueVisible() const { return mbGlueVisible
|| mbGlueVisible2
|| mbGlueVisible3
|| mbGlueVisible4
; }
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
;
256 // SdrModel access on SdrView level
257 SdrModel
& getSdrModelFromSdrView() const { return mrModel
; }
259 SdrModel
& GetModel() const { return mrModel
; }
261 virtual void ClearPageView();
263 virtual bool IsAction() const;
264 virtual void MovAction(const Point
& rPnt
);
265 virtual void EndAction();
266 virtual void BckAction();
267 virtual void BrkAction(); // Cancel all Actions (e.g. cancel dragging)
268 virtual void TakeActionRect(tools::Rectangle
& rRect
) const;
270 // Info about TextEdit. Default is sal_False.
271 virtual bool IsTextEdit() const;
273 // Must be called for every Window change as well as MapMode (Scaling) change:
274 // If the SdrView is shown in multiple windows at the same time (e.g.
275 // using the split pane), so that I can convert my pixel values to logical
277 void SetActualWin(const OutputDevice
* pWin
);
278 void SetMinMoveDistancePixel(sal_uInt16 nVal
) { mnMinMovPix
=nVal
; TheresNewMapMode(); }
279 void SetHitTolerancePixel(sal_uInt16 nVal
) { mnHitTolPix
=nVal
; TheresNewMapMode(); }
280 sal_uInt16
GetHitTolerancePixel() const { return mnHitTolPix
; }
282 // Data read access on logic HitTolerance and MinMoveTolerance
283 sal_uInt16
getHitTolLog() const { return mnHitTolLog
; }
285 // Using the DragState we can tell e.g. which distance was
287 const SdrDragStat
& GetDragStat() const { return maDragStat
; }
289 // Registering/de-registering a PageView at a View
291 // The same Page cannot be registered multiple times.
293 // Methods ending in PgNum expect being passed a Page number.
294 // Methods ending in PvNum, instead, expect the number of the
295 // PageView at the SdrView (iterating over all registered Pages).
296 virtual SdrPageView
* ShowSdrPage(SdrPage
* pPage
);
297 virtual void HideSdrPage();
299 // Iterate over all registered PageViews
300 SdrPageView
* GetSdrPageView() const { return mpPageView
.get(); }
302 // A SdrView can be output to multiple devices at the same time
303 virtual void AddDeviceToPaintView(OutputDevice
& rNewDev
, vcl::Window
* pWindow
);
304 virtual void DeleteDeviceFromPaintView(OutputDevice
& rOldDev
);
306 void SetLayerVisible(const OUString
& rName
, bool bShow
);
307 bool IsLayerVisible(const OUString
& rName
) const;
309 void SetLayerLocked(const OUString
& rName
, bool bLock
=true);
310 bool IsLayerLocked(const OUString
& rName
) const;
312 void SetLayerPrintable(const OUString
& rName
, bool bPrn
);
313 bool IsLayerPrintable(const OUString
& rName
) const;
315 // PrePaint call forwarded from app windows
319 // Used internally for Draw/Impress/sch/chart2
320 virtual void CompleteRedraw(OutputDevice
* pOut
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
= nullptr);
322 // #i72889# used from CompleteRedraw() implementation internally, added to be able to do a complete redraw in single steps
324 // BeginCompleteRedraw returns (or even creates) a SdrPaintWindow which will then be used as the
325 // target for paints. Since paints may be buffered, use its GetTargetOutputDevice() method which will
326 // return the buffer in case it's buffered.
328 // DoCompleteRedraw then draws the DrawingLayer hierarchy
329 // EndCompleteRedraw does the necessary refreshes, paints text edit and overlay as well as destroys the
330 // SdrPaintWindow again, if needed.
331 // This means: the SdrPaintWindow is no longer safe after this closing call.
332 virtual SdrPaintWindow
* BeginCompleteRedraw(OutputDevice
* pOut
);
333 void DoCompleteRedraw(SdrPaintWindow
& rPaintWindow
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
= nullptr);
334 virtual void EndCompleteRedraw(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
);
337 // Used for the other applications basctl/sc/sw which call DrawLayer at PageViews
338 // #i74769# Interface change to use common BeginCompleteRedraw/EndCompleteRedraw
339 // #i76114# bDisableIntersect disables intersecting rReg with the Window's paint region
340 SdrPaintWindow
* BeginDrawLayers(OutputDevice
* pOut
, const vcl::Region
& rReg
, bool bDisableIntersect
= false);
342 // Used when the region passed to BeginDrawLayers needs to be changed
343 void UpdateDrawLayersRegion(const OutputDevice
* pOut
, const vcl::Region
& rReg
);
344 void EndDrawLayers(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
);
348 // Used to paint the form layer after the PreRender device is flushed (painted) to the window.
349 void ImpFormLayerDrawing( SdrPaintWindow
& rPaintWindow
);
351 static vcl::Region
OptimizeDrawLayersRegion(const OutputDevice
* pOut
, const vcl::Region
& rReg
, bool bDisableIntersect
);
354 /// Draw Page as a white area or not
355 bool IsPageVisible() const { return mbPageVisible
; }
357 /// Draw Page shadow or not
358 bool IsPageShadowVisible() const { return mbPageShadowVisible
; }
360 /// Draw Page as a white area or not
361 bool IsPageBorderVisible() const { return mbPageBorderVisible
; }
363 /// Draw Border line or not
364 bool IsBordVisible() const { return mbBordVisible
; }
367 bool IsGridVisible() const { return mbGridVisible
; }
369 /// Draw Grid in front of objects or behind them
370 bool IsGridFront() const { return mbGridFront
; }
372 /// Draw Help line of the Page or not
373 bool IsHlplVisible() const { return mbHlplVisible
; }
375 /// Draw Help line in front of the objects or behind them
376 bool IsHlplFront() const { return mbHlplFront
; }
378 const Color
& GetGridColor() const { return maGridColor
;}
379 void SetPageVisible(bool bOn
= true) { mbPageVisible
=bOn
; InvalidateAllWin(); }
380 void SetPageShadowVisible(bool bOn
) { mbPageShadowVisible
=bOn
; InvalidateAllWin(); }
381 void SetPageBorderVisible(bool bOn
= true) { mbPageBorderVisible
=bOn
; InvalidateAllWin(); }
382 void SetBordVisible(bool bOn
= true) { mbBordVisible
=bOn
; InvalidateAllWin(); }
383 void SetGridVisible(bool bOn
) { mbGridVisible
=bOn
; InvalidateAllWin(); }
384 void SetGridFront(bool bOn
) { mbGridFront
=bOn
; InvalidateAllWin(); }
385 void SetHlplVisible(bool bOn
= true) { mbHlplVisible
=bOn
; InvalidateAllWin(); }
386 void SetHlplFront(bool bOn
) { mbHlplFront
=bOn
; InvalidateAllWin(); }
387 void SetGlueVisible(bool bOn
= true) { if (mbGlueVisible
!=bOn
) { mbGlueVisible
=bOn
; if (!mbGlueVisible2
&& !mbGlueVisible3
&& !mbGlueVisible4
) GlueInvalidate(); } }
389 bool IsPreviewRenderer() const { return mbPreviewRenderer
; }
390 void SetPreviewRenderer(bool bOn
) { mbPreviewRenderer
=bOn
; }
392 // Access methods for calc and sw hide object modes
393 bool getHideOle() const { return mbHideOle
; }
394 bool getHideChart() const { return mbHideChart
; }
395 bool getHideDraw() const { return mbHideDraw
; }
396 bool getHideFormControl() const { return mbHideFormControl
; }
397 void setHideOle(bool bNew
) { if(bNew
!= mbHideOle
) mbHideOle
= bNew
; }
398 void setHideChart(bool bNew
) { if(bNew
!= mbHideChart
) mbHideChart
= bNew
; }
399 void setHideDraw(bool bNew
) { if(bNew
!= mbHideDraw
) mbHideDraw
= bNew
; }
400 void setHideFormControl(bool bNew
) { if(bNew
!= mbHideFormControl
) mbHideFormControl
= bNew
; }
402 void SetGridCoarse(const Size
& rSiz
) { maGridBig
=rSiz
; }
403 void SetGridFine(const Size
& rSiz
) {
405 if (maGridFin
.Height()==0) maGridFin
.setHeight(maGridFin
.Width());
406 if (mbGridVisible
) InvalidateAllWin();
408 const Size
& GetGridCoarse() const { return maGridBig
; }
409 const Size
& GetGridFine() const { return maGridFin
; }
411 void InvalidateAllWin();
412 void InvalidateAllWin(const tools::Rectangle
& rRect
);
414 /// If the View should not call Invalidate() on the windows, override
415 /// the following 2 methods and do something else.
416 virtual void InvalidateOneWin(OutputDevice
& rWin
);
417 virtual void InvalidateOneWin(OutputDevice
& rWin
, const tools::Rectangle
& rRect
);
419 void SetActiveLayer(const OUString
& rName
) { maActualLayer
=rName
; }
420 const OUString
& GetActiveLayer() const { return maActualLayer
; }
422 /// Leave an object group of all visible Pages (like `chdir ..` in MS-DOS)
423 void LeaveOneGroup();
425 /// Leave all entered object groups of all visible Pages (like `chdir \` in MS-DOS)
426 void LeaveAllGroup();
428 /// Determine, whether Leave is useful or not
429 bool IsGroupEntered() const;
431 /// Default attributes at the View
432 /// Newly created objects are assigned these attributes by default when they are created.
433 void SetDefaultAttr(const SfxItemSet
& rAttr
, bool bReplaceAll
);
434 const SfxItemSet
& GetDefaultAttr() const { return maDefaultAttr
; }
435 void SetDefaultStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
);
437 void SetNotPersistDefaultAttr(const SfxItemSet
& rAttr
);
438 void MergeNotPersistDefaultAttr(SfxItemSet
& rAttr
) const;
440 /// Execute a swap-in of e.g. graphics asynchronously.
441 /// This does not reload all graphics like Paint does, but kicks off
442 /// the loading there. When such an object is done loading, it is displayed.
443 /// TODO: Only works at the moment, if SwapGraphics is enabled in the model.
444 /// The default = false flag is non-persistent
445 bool IsSwapAsynchron() const { return mbSwapAsynchron
; }
446 void SetSwapAsynchron(bool bJa
=true) { mbSwapAsynchron
=bJa
; }
447 virtual bool KeyInput(const KeyEvent
& rKEvt
, vcl::Window
* pWin
);
449 virtual bool MouseButtonDown(const MouseEvent
& /*rMEvt*/, OutputDevice
* /*pWin*/) { return false; }
450 virtual bool MouseButtonUp(const MouseEvent
& /*rMEvt*/, OutputDevice
* /*pWin*/) { return false; }
451 virtual bool MouseMove(const MouseEvent
& /*rMEvt*/, OutputDevice
* /*pWin*/) { return false; }
452 virtual bool RequestHelp(const HelpEvent
& /*rHEvt*/) { return false; }
453 virtual bool Command(const CommandEvent
& /*rCEvt*/, vcl::Window
* /*pWin*/) { return false; }
455 void GetAttributes(SfxItemSet
& rTargetSet
, bool bOnlyHardAttr
) const;
457 void SetAttributes(const SfxItemSet
& rSet
, bool bReplaceAll
);
458 SfxStyleSheet
* GetStyleSheet() const; // SfxStyleSheet* GetStyleSheet(bool& rOk) const;
459 void SetStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
);
461 virtual void MakeVisible(const tools::Rectangle
& rRect
, vcl::Window
& rWin
);
464 /// Is called by the Paint of the OLE object
465 virtual void DoConnect(SdrOle2Obj
* pOleObj
);
467 /// Enable/disable animations for ::Paint
468 /// Is used by e.g. SdrGrafObj, if it contains an animation
469 /// Preventing automatic animation is needed for e.g. the presentation view
470 bool IsAnimationEnabled() const { return ( SdrAnimationMode::Animate
== meAnimationMode
); }
471 void SetAnimationEnabled( bool bEnable
=true );
473 /// Set/unset pause state for animations
474 void SetAnimationPause( bool bSet
);
476 /// Mode when starting an animation in the Paint Handler:
477 /// 1. SdrAnimationMode::Animate (default): start animation normally
478 /// 2. SDR_ANIMATION_DONT_ANIMATE: only show the replacement picture
479 /// 3. SdrAnimationMode::Disable: don't start and don't show any replacement
480 void SetAnimationMode( const SdrAnimationMode eMode
);
482 /// Must be called by the App when scrolling etc. in order for
483 /// an active FormControl to be moved too
484 void VisAreaChanged(const OutputDevice
* pOut
);
485 void VisAreaChanged();
487 bool IsPrintPreview() const { return mbPrintPreview
; }
488 void SetPrintPreview(bool bOn
= true) { mbPrintPreview
=bOn
; }
490 const svtools::ColorConfig
& getColorConfig() const { return maColorConfig
;}
492 void onChangeColorConfig();
494 // #103834# Set background color for svx at SdrPageViews
495 void SetApplicationBackgroundColor(Color aBackgroundColor
);
497 // #103911# Set document color for svx at SdrPageViews
498 void SetApplicationDocumentColor(Color aDocumentColor
);
501 // Sets the timer for Object animations and restarts.
502 void SetAnimationTimer(sal_uInt32 nTime
);
504 /// @see vcl::ITiledRenderable::setPaintTextEdit().
505 void SetPaintTextEdit(bool bPaint
) { mbPaintTextEdit
= bPaint
; }
508 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */