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 <com/sun/star/awt/XControlContainer.hpp>
31 #include <svl/itemset.hxx>
32 #include <vcl/timer.hxx>
33 #include <svx/svxdllapi.h>
34 #include <svtools/optionsdrawinglayer.hxx>
35 #include <unotools/options.hxx>
36 #include <vcl/idle.hxx>
42 namespace com
{ namespace sun
{ namespace star
{ namespace awt
{
43 class XControlContainer
;
53 enum class GraphicManagerDrawFlags
;
59 namespace sdr
{ namespace contact
{
60 class ViewObjectContactRedirector
;
64 // Defines for AnimationMode
65 enum class SdrAnimationMode
72 // Typedefs and defines
73 typedef unsigned char SDR_TRISTATE
;
75 #define SDR_ANYFORMAT (0xFFFFFFFF)
76 #define SDR_ANYITEM (0xFFFF)
77 #define SDRVIEWWIN_NOTFOUND (0xFFFF)
86 class ViewObjectContactRedirector
;
91 class SVX_DLLPUBLIC SvxViewChangedHint
: public SfxHint
94 explicit SvxViewChangedHint();
97 /// Typedefs for a list of SdrPaintWindows
99 typedef ::std::vector
< SdrPaintWindow
* > SdrPaintWindowVector
;
103 * Helper to convert any GDIMetaFile to a good quality BitmapEx,
104 * using default parameters and graphic::XPrimitive2DRenderer
106 BitmapEx SVX_DLLPUBLIC
convertMetafileToBitmapEx(
107 const GDIMetaFile
& rMtf
,
108 const basegfx::B2DRange
& rTargetRange
,
109 const sal_uInt32 nMaximumQuadraticPixels
);
112 class SVX_DLLPUBLIC SdrPaintView
: public SfxListener
, public SfxRepeatTarget
, public SfxBroadcaster
, public ::utl::ConfigurationListener
114 friend class SdrPageView
;
115 friend class SdrGrafObj
;
117 SdrPageView
* mpPageView
;
121 VclPtr
<SdrItemBrowser
> mpItemBrowser
;
123 VclPtr
<OutputDevice
> mpActualOutDev
; // Only for comparison
124 VclPtr
<OutputDevice
> mpDragWin
;
125 SfxStyleSheet
* mpDefaultStyleSheet
;
127 OUString maActualLayer
; // Current drawing layer
128 OUString maMeasureLayer
; // Current layer for measurements
130 // Container aPagV; // List of SdrPageViews
132 // All windows this view is displayed on
133 SdrPaintWindowVector maPaintWindows
;
135 Size maGridBig
; // FIXME: We need to get rid of this eventually
136 Size maGridFin
; // FIXME: We need to get rid of this eventually
137 SdrDragStat maDragStat
;
138 tools::Rectangle maMaxWorkArea
;
139 SfxItemSet maDefaultAttr
;
142 SdrAnimationMode meAnimationMode
;
144 sal_uInt16 mnHitTolPix
;
145 sal_uInt16 mnMinMovPix
;
146 sal_uInt16 mnHitTolLog
;
147 sal_uInt16 mnMinMovLog
;
148 GraphicManagerDrawFlags mnGraphicManagerDrawMode
;
150 // Hold an incarnation of Drawinglayer configuration options
151 SvtOptionsDrawinglayer maDrawinglayerOpt
;
153 bool mbPageVisible
: 1;
154 bool mbPageShadowVisible
: 1;
155 bool mbPageBorderVisible
: 1;
156 bool mbBordVisible
: 1;
157 bool mbGridVisible
: 1;
158 bool mbGridFront
: 1;
159 bool mbHlplVisible
: 1;
160 bool mbHlplFront
: 1;
161 bool mbGlueVisible
: 1; // Persistent; show glue points
162 bool mbGlueVisible2
: 1; // Also show glue points for GluePointEdit
163 bool mbGlueVisible3
: 1; // Also show glue points for EdgeTool
164 bool mbGlueVisible4
: 1; // Show glue points, if one edge is selected
165 bool mbSomeObjChgdFlag
: 1;
166 bool mbSwapAsynchron
: 1;
167 bool mbPrintPreview
: 1;
169 // These bools manage, the status that is displayed
171 bool mbAnimationPause
: 1;
173 // Flag which decides if buffered output for this view is allowed. When
174 // set, PreRendering for PageView rendering will be used. Default is sal_False
175 bool mbBufferedOutputAllowed
: 1;
177 // Flag which decides if buffered overlay for this view is allowed. When
178 // set, the output will be buffered in an overlay vdev. When not, overlay is
179 // directly painted to OutDev. Default is sal_False.
180 bool mbBufferedOverlayAllowed
: 1;
182 // Allow page painting at all?
183 bool mbPagePaintingAllowed
: 1;
185 // Is this a preview renderer?
186 bool mbPreviewRenderer
: 1;
188 // Flags for calc and sw for suppressing OLE, CHART or DRAW objects
190 bool mbHideChart
: 1;
191 bool mbHideDraw
: 1; // hide draw objects other than form controls
192 bool mbHideFormControl
: 1; // hide form controls only
195 // Interface for PagePaintingAllowed flag
196 bool IsBufferedOutputAllowed() const;
197 void SetBufferedOutputAllowed(bool bNew
);
199 // Interface for BufferedOverlayAllowed flag
200 bool IsBufferedOverlayAllowed() const;
201 void SetBufferedOverlayAllowed(bool bNew
);
203 // Allow page painting at all?
204 bool IsPagePaintingAllowed() const { return mbPagePaintingAllowed
;}
205 void SetPagePaintingAllowed(bool bNew
);
208 svtools::ColorConfig maColorConfig
;
211 // Interface to SdrPaintWindow
212 void RemovePaintWindow(SdrPaintWindow
& rOld
);
213 void ConfigurationChanged( ::utl::ConfigurationBroadcaster
*, ConfigurationHints
) override
;
216 sal_uInt32
PaintWindowCount() const { return maPaintWindows
.size(); }
217 SdrPaintWindow
* FindPaintWindow(const OutputDevice
& rOut
) const;
218 SdrPaintWindow
* GetPaintWindow(sal_uInt32 nIndex
) const;
219 // Replacement for GetWin(0), may return 0L (!)
220 OutputDevice
* GetFirstOutputDevice() const;
223 SVX_DLLPRIVATE
void ImpClearVars();
224 DECL_LINK(ImpComeBackHdl
, Timer
*, void);
227 sal_uInt16
ImpGetMinMovLogic(short nMinMov
, const OutputDevice
* pOut
) const;
228 sal_uInt16
ImpGetHitTolLogic(short nHitTol
, const OutputDevice
* pOut
) const;
230 // If one does not want to wait for the IdleState of the system (cheated as const)
231 void FlushComeBackTimer() const;
232 void TheresNewMapMode();
233 void ImpSetGlueVisible2(bool bOn
) { if (mbGlueVisible2
!=bOn
) { mbGlueVisible2
=bOn
; if (!mbGlueVisible
&& !mbGlueVisible3
&& !mbGlueVisible4
) GlueInvalidate(); } }
234 void ImpSetGlueVisible3(bool bOn
) { if (mbGlueVisible3
!=bOn
) { mbGlueVisible3
=bOn
; if (!mbGlueVisible
&& !mbGlueVisible2
&& !mbGlueVisible4
) GlueInvalidate(); } }
235 void ImpSetGlueVisible4(bool bOn
) { if (mbGlueVisible4
!=bOn
) { mbGlueVisible4
=bOn
; if (!mbGlueVisible
&& !mbGlueVisible2
&& !mbGlueVisible3
) GlueInvalidate(); } }
238 bool ImpIsGlueVisible() { return mbGlueVisible
|| mbGlueVisible2
|| mbGlueVisible3
|| mbGlueVisible4
; }
241 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
242 void GlueInvalidate() const;
244 // ModelHasChanged is called, as soon as the system is idle again after many SdrHintKind::ObjectChange.
246 // Any sub-class override this method, MUST call the base class' ModelHasChanged() method
247 virtual void ModelHasChanged();
249 // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
250 SdrPaintView(SdrModel
* pModel1
, OutputDevice
* pOut
);
251 virtual ~SdrPaintView() override
;
255 virtual void ClearPageView();
256 SdrModel
* GetModel() const { return mpModel
; }
258 virtual bool IsAction() const;
259 virtual void MovAction(const Point
& rPnt
);
260 virtual void EndAction();
261 virtual void BckAction();
262 virtual void BrkAction(); // Cancel all Actions (e.g. cancel dragging)
263 virtual void TakeActionRect(tools::Rectangle
& rRect
) const;
265 // Info about TextEdit. Default is sal_False.
266 virtual bool IsTextEdit() const;
268 // Info about TextEditPageView. Default is 0L.
269 virtual SdrPageView
* GetTextEditPageView() const;
271 // Must be called for every Window change as well as MapMode (Scaling) change:
272 // If the SdrView is shown in multiple windows at the same time (e.g.
273 // using the split pane), so that I can convert my pixel values to logical
275 void SetActualWin(const OutputDevice
* pWin
);
276 void SetMinMoveDistancePixel(sal_uInt16 nVal
) { mnMinMovPix
=nVal
; TheresNewMapMode(); }
277 void SetHitTolerancePixel(sal_uInt16 nVal
) { mnHitTolPix
=nVal
; TheresNewMapMode(); }
278 sal_uInt16
GetHitTolerancePixel() const { return (sal_uInt16
)mnHitTolPix
; }
280 // Data read access on logic HitTolerance and MinMoveTolerance
281 sal_uInt16
getHitTolLog() const { return mnHitTolLog
; }
283 // Using the DragState we can tell e.g. which distance was
285 const SdrDragStat
& GetDragStat() const { return maDragStat
; }
287 // Registering/de-registering a PageView at a View
289 // The same Page cannot be registered multiple times.
291 // Methods ending in PgNum expect being passed a Page number.
292 // Methods ending in PvNum, instead, expect the number of the
293 // PageView at the SdrView (iterating over all registered Pages).
294 virtual SdrPageView
* ShowSdrPage(SdrPage
* pPage
);
295 virtual void HideSdrPage();
297 // Iterate over all registered PageViews
298 SdrPageView
* GetSdrPageView() const { return mpPageView
; }
300 // A SdrView can be displayed on multiple Windows at the same time
301 virtual void AddWindowToPaintView(OutputDevice
* pNewWin
, vcl::Window
* pWindow
);
302 virtual void DeleteWindowFromPaintView(OutputDevice
* pOldWin
);
304 void SetLayerVisible(const OUString
& rName
, bool bShow
);
305 bool IsLayerVisible(const OUString
& rName
) const;
307 void SetLayerLocked(const OUString
& rName
, bool bLock
=true);
308 bool IsLayerLocked(const OUString
& rName
) const;
310 void SetLayerPrintable(const OUString
& rName
, bool bPrn
);
311 bool IsLayerPrintable(const OUString
& rName
) const;
313 // PrePaint call forwarded from app windows
317 // Used internally for Draw/Impress/sch/chart2
318 virtual void CompleteRedraw(OutputDevice
* pOut
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
= nullptr);
320 // #i72889# used from CompleteRedraw() implementation internally, added to be able to do a complete redraw in single steps
322 // BeginCompleteRedraw returns (or even creates) a SdrPaintWindow which will then be used as the
323 // target for paints. Since paints may be buffered, use its GetTargetOutputDevice() method which will
324 // return the buffer in case it's buffered.
326 // DoCompleteRedraw then draws the DrawingLayer hierarchy
327 // EndCompleteRedraw does the necessary refreshes, paints text edit and overlay as well as destroys the
328 // SdrPaintWindow again, if needed.
329 // This means: the SdrPaintWindow is no longer safe after this closing call.
330 virtual SdrPaintWindow
* BeginCompleteRedraw(OutputDevice
* pOut
);
331 void DoCompleteRedraw(SdrPaintWindow
& rPaintWindow
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
= nullptr);
332 virtual void EndCompleteRedraw(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
);
335 // Used for the other applications basctl/sc/sw which call DrawLayer at PageViews
336 // #i74769# Interface change to use common BeginCompleteRedraw/EndCompleteRedraw
337 // #i76114# bDisableIntersect disables intersecting rReg with the Window's paint region
338 SdrPaintWindow
* BeginDrawLayers(OutputDevice
* pOut
, const vcl::Region
& rReg
, bool bDisableIntersect
= false);
340 // Used when the region passed to BeginDrawLayers needs to be changed
341 void UpdateDrawLayersRegion(OutputDevice
* pOut
, const vcl::Region
& rReg
);
342 void EndDrawLayers(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
);
346 // Used to paint the form layer after the PreRender device is flushed (painted) to the window.
347 void ImpFormLayerDrawing( SdrPaintWindow
& rPaintWindow
);
349 static vcl::Region
OptimizeDrawLayersRegion(OutputDevice
* pOut
, const vcl::Region
& rReg
, bool bDisableIntersect
);
352 /// Draw Page as a white area or not
353 bool IsPageVisible() const { return mbPageVisible
; }
355 /// Draw Page shadow or not
356 bool IsPageShadowVisible() const { return mbPageShadowVisible
; }
358 /// Draw Page as a white area or not
359 bool IsPageBorderVisible() const { return mbPageBorderVisible
; }
361 /// Draw Border line or not
362 bool IsBordVisible() const { return mbBordVisible
; }
365 bool IsGridVisible() const { return mbGridVisible
; }
367 /// Draw Grid in front of objects or behind them
368 bool IsGridFront() const { return mbGridFront
; }
370 /// Draw Help line of the Page or not
371 bool IsHlplVisible() const { return mbHlplVisible
; }
373 /// Draw Help line in front of the objects or behind them
374 bool IsHlplFront() const { return mbHlplFront
; }
376 const Color
& GetGridColor() const { return maGridColor
;}
377 void SetPageVisible(bool bOn
= true) { mbPageVisible
=bOn
; InvalidateAllWin(); }
378 void SetPageShadowVisible(bool bOn
) { mbPageShadowVisible
=bOn
; InvalidateAllWin(); }
379 void SetPageBorderVisible(bool bOn
= true) { mbPageBorderVisible
=bOn
; InvalidateAllWin(); }
380 void SetBordVisible(bool bOn
= true) { mbBordVisible
=bOn
; InvalidateAllWin(); }
381 void SetGridVisible(bool bOn
) { mbGridVisible
=bOn
; InvalidateAllWin(); }
382 void SetGridFront(bool bOn
) { mbGridFront
=bOn
; InvalidateAllWin(); }
383 void SetHlplVisible(bool bOn
= true) { mbHlplVisible
=bOn
; InvalidateAllWin(); }
384 void SetHlplFront(bool bOn
) { mbHlplFront
=bOn
; InvalidateAllWin(); }
385 void SetGlueVisible(bool bOn
= true) { if (mbGlueVisible
!=bOn
) { mbGlueVisible
=bOn
; if (!mbGlueVisible2
&& !mbGlueVisible3
&& !mbGlueVisible4
) GlueInvalidate(); } }
387 bool IsPreviewRenderer() const { return mbPreviewRenderer
; }
388 void SetPreviewRenderer(bool bOn
) { mbPreviewRenderer
=bOn
; }
390 // Access methods for calc and sw hide object modes
391 bool getHideOle() const { return mbHideOle
; }
392 bool getHideChart() const { return mbHideChart
; }
393 bool getHideDraw() const { return mbHideDraw
; }
394 bool getHideFormControl() const { return mbHideFormControl
; }
395 void setHideOle(bool bNew
) { if(bNew
!= mbHideOle
) mbHideOle
= bNew
; }
396 void setHideChart(bool bNew
) { if(bNew
!= mbHideChart
) mbHideChart
= bNew
; }
397 void setHideDraw(bool bNew
) { if(bNew
!= mbHideDraw
) mbHideDraw
= bNew
; }
398 void setHideFormControl(bool bNew
) { if(bNew
!= mbHideFormControl
) mbHideFormControl
= bNew
; }
400 void SetGridCoarse(const Size
& rSiz
) { maGridBig
=rSiz
; }
401 void SetGridFine(const Size
& rSiz
) {
403 if (maGridFin
.Height()==0) maGridFin
.Height()=maGridFin
.Width();
404 if (mbGridVisible
) InvalidateAllWin();
406 const Size
& GetGridCoarse() const { return maGridBig
; }
407 const Size
& GetGridFine() const { return maGridFin
; }
409 void InvalidateAllWin();
410 void InvalidateAllWin(const tools::Rectangle
& rRect
);
412 /// If the View should not call Invalidate() on the windows, override
413 /// the following 2 methods and do something else.
414 virtual void InvalidateOneWin(vcl::Window
& rWin
);
415 virtual void InvalidateOneWin(vcl::Window
& rWin
, const tools::Rectangle
& rRect
);
417 void SetActiveLayer(const OUString
& rName
) { maActualLayer
=rName
; }
418 const OUString
& GetActiveLayer() const { return maActualLayer
; }
420 /// Leave an object group of all visible Pages (like `chdir ..` in MSDOS)
421 void LeaveOneGroup();
423 /// Leave all entered object groups of all visible Pages (like `chdir \` in MSDOS)
424 void LeaveAllGroup();
426 /// Determine, whether Leave is useful or not
427 bool IsGroupEntered() const;
429 /// Default attributes at the View
430 /// Newly created objects are assigned these attributes by default when they are created.
431 void SetDefaultAttr(const SfxItemSet
& rAttr
, bool bReplaceAll
);
432 const SfxItemSet
& GetDefaultAttr() const { return maDefaultAttr
; }
433 void SetDefaultStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
);
435 void SetNotPersistDefaultAttr(const SfxItemSet
& rAttr
);
436 void MergeNotPersistDefaultAttr(SfxItemSet
& rAttr
) const;
438 /// Execute a swap-in of e.g. graphics asynchronously.
439 /// This does not reload all graphics like Paint does, but kicks off
440 /// the loading there. When such an object is done loading, it is displayed.
441 /// TODO: Only works at the moment, if SwapGraphics is enabled in the model.
442 /// The default = false flag is non-persistent
443 bool IsSwapAsynchron() const { return mbSwapAsynchron
; }
444 void SetSwapAsynchron(bool bJa
=true) { mbSwapAsynchron
=bJa
; }
445 virtual bool KeyInput(const KeyEvent
& rKEvt
, vcl::Window
* pWin
);
447 virtual bool MouseButtonDown(const MouseEvent
& /*rMEvt*/, vcl::Window
* /*pWin*/) { return false; }
448 virtual bool MouseButtonUp(const MouseEvent
& /*rMEvt*/, vcl::Window
* /*pWin*/) { return false; }
449 virtual bool MouseMove(const MouseEvent
& /*rMEvt*/, vcl::Window
* /*pWin*/) { return false; }
450 virtual bool Command(const CommandEvent
& /*rCEvt*/, vcl::Window
* /*pWin*/) { return false; }
452 bool GetAttributes(SfxItemSet
& rTargetSet
, bool bOnlyHardAttr
) const;
454 bool SetAttributes(const SfxItemSet
& rSet
, bool bReplaceAll
);
455 SfxStyleSheet
* GetStyleSheet() const; // SfxStyleSheet* GetStyleSheet(bool& rOk) const;
456 bool SetStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
);
458 virtual void MakeVisible(const tools::Rectangle
& rRect
, vcl::Window
& rWin
);
461 /// Is called by the Paint of the OLE object
462 virtual void DoConnect(SdrOle2Obj
* pOleObj
);
464 /// Enable/disable animations for ::Paint
465 /// Is used by e.g. SdrGrafObj, if it contains an animation
466 /// Preventing automatic animation is needed for e.g. the presentation view
467 bool IsAnimationEnabled() const { return ( SdrAnimationMode::Animate
== meAnimationMode
); }
468 void SetAnimationEnabled( bool bEnable
=true );
470 /// Set/unset pause state for animations
471 void SetAnimationPause( bool bSet
);
473 /// Mode when starting an animation in the Paint Handler:
474 /// 1. SdrAnimationMode::Animate (default): start animation normally
475 /// 2. SDR_ANIMATION_DONT_ANIMATE: only show the replacement picture
476 /// 3. SdrAnimationMode::Disable: don't start and don't show any replacement
477 void SetAnimationMode( const SdrAnimationMode eMode
);
479 /// The Browser is destroyed for bShow=false
481 void ShowItemBrowser(bool bShow
);
482 bool IsItemBrowserVisible() const { return mpItemBrowser
!=nullptr && GetItemBrowser()->IsVisible(); }
483 vcl::Window
* GetItemBrowser() const;
486 /// Must be called by the App when scrolling etc. in order for
487 /// an active FormularControl to be moved too
488 void VisAreaChanged(const OutputDevice
* pOut
);
489 void VisAreaChanged();
491 bool IsPrintPreview() const { return mbPrintPreview
; }
492 void SetPrintPreview(bool bOn
= true) { mbPrintPreview
=bOn
; }
494 const svtools::ColorConfig
& getColorConfig() const { return maColorConfig
;}
496 void onChangeColorConfig();
498 // #103834# Set background color for svx at SdrPageViews
499 void SetApplicationBackgroundColor(Color aBackgroundColor
);
501 // #103911# Set document color for svx at SdrPageViews
502 void SetApplicationDocumentColor(Color aDocumentColor
);
505 // Sets the timer for Object animations and restarts.
506 void SetAnimationTimer(sal_uInt32 nTime
);
508 // Access to Drawinglayer configuration options
509 const SvtOptionsDrawinglayer
& getOptionsDrawinglayer() const { return maDrawinglayerOpt
; }
512 #endif // INCLUDED_SVX_SVDPNTV_HXX
514 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */