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
{ namespace sun
{ namespace star
{ namespace awt
{
43 class XControlContainer
;
45 namespace sdr
{ namespace overlay
{ class OverlayManager
; } }
54 enum class GraphicManagerDrawFlags
;
60 namespace sdr
{ namespace contact
{
61 class ViewObjectContactRedirector
;
65 // Defines for AnimationMode
66 enum class SdrAnimationMode
79 class ViewObjectContactRedirector
;
84 class SvxViewChangedHint final
: public SfxHint
87 explicit SvxViewChangedHint();
93 * Helper to convert any GDIMetaFile to a good quality BitmapEx,
94 * using default parameters and graphic::XPrimitive2DRenderer
96 BitmapEx
convertMetafileToBitmapEx(
97 const GDIMetaFile
& rMtf
,
98 const basegfx::B2DRange
& rTargetRange
,
99 const sal_uInt32 nMaximumQuadraticPixels
);
101 ////////////////////////////////////////////////////////////////////////////////////////////////////
120 // sd::View (may have more?)
125 class SVX_DLLPUBLIC SdrPaintView
: public SfxListener
, public SfxRepeatTarget
, public SfxBroadcaster
, public ::utl::ConfigurationListener
128 friend class SdrPageView
;
129 friend class SdrGrafObj
;
131 // the SdrModel this view was created with, unchanged during lifetime
132 SdrModel
& mrSdrModelFromSdrView
;
134 std::unique_ptr
<SdrPageView
> mpPageView
;
138 VclPtr
<SdrItemBrowser
> mpItemBrowser
;
140 VclPtr
<OutputDevice
> mpActualOutDev
; // Only for comparison
141 VclPtr
<OutputDevice
> mpDragWin
;
142 SfxStyleSheet
* mpDefaultStyleSheet
;
144 OUString maActualLayer
; // Current drawing layer
145 OUString maMeasureLayer
; // Current layer for measurements
147 // Container aPagV; // List of SdrPageViews
149 // All windows this view is displayed on
150 std::vector
< std::unique_ptr
<SdrPaintWindow
> > maPaintWindows
;
152 Size maGridBig
; // FIXME: We need to get rid of this eventually
153 Size maGridFin
; // FIXME: We need to get rid of this eventually
154 SdrDragStat maDragStat
;
155 tools::Rectangle maMaxWorkArea
;
156 SfxItemSet maDefaultAttr
;
159 SdrAnimationMode meAnimationMode
;
161 sal_uInt16 mnHitTolPix
;
162 sal_uInt16 mnMinMovPix
;
163 sal_uInt16 mnHitTolLog
;
164 sal_uInt16 mnMinMovLog
;
166 // Hold an incarnation of Drawinglayer configuration options
167 SvtOptionsDrawinglayer
const maDrawinglayerOpt
;
169 bool mbPageVisible
: 1;
170 bool mbPageShadowVisible
: 1;
171 bool mbPageBorderVisible
: 1;
172 bool mbBordVisible
: 1;
173 bool mbGridVisible
: 1;
174 bool mbGridFront
: 1;
175 bool mbHlplVisible
: 1;
176 bool mbHlplFront
: 1;
177 bool mbGlueVisible
: 1; // Persistent; show glue points
178 bool mbGlueVisible2
: 1; // Also show glue points for GluePointEdit
179 bool mbGlueVisible3
: 1; // Also show glue points for EdgeTool
180 bool mbGlueVisible4
: 1; // Show glue points, if one edge is selected
181 bool mbSomeObjChgdFlag
: 1;
182 bool mbSwapAsynchron
: 1;
183 bool mbPrintPreview
: 1;
185 // These bools manage, the status that is displayed
187 bool mbAnimationPause
: 1;
189 // Flag which decides if buffered output for this view is allowed. When
190 // set, PreRendering for PageView rendering will be used. Default is sal_False
191 bool mbBufferedOutputAllowed
: 1;
193 // Flag which decides if buffered overlay for this view is allowed. When
194 // set, the output will be buffered in an overlay vdev. When not, overlay is
195 // directly painted to OutDev. Default is sal_False.
196 bool mbBufferedOverlayAllowed
: 1;
198 // Allow page painting at all?
199 bool mbPagePaintingAllowed
: 1;
201 // Is this a preview renderer?
202 bool mbPreviewRenderer
: 1;
204 // Flags for calc and sw for suppressing OLE, CHART or DRAW objects
206 bool mbHideChart
: 1;
207 bool mbHideDraw
: 1; // hide draw objects other than form controls
208 bool mbHideFormControl
: 1; // hide form controls only
211 // Interface for PagePaintingAllowed flag
212 bool IsBufferedOutputAllowed() const;
213 void SetBufferedOutputAllowed(bool bNew
);
215 // Interface for BufferedOverlayAllowed flag
216 bool IsBufferedOverlayAllowed() const;
217 void SetBufferedOverlayAllowed(bool bNew
);
219 // Allow page painting at all?
220 bool IsPagePaintingAllowed() const { return mbPagePaintingAllowed
;}
221 void SetPagePaintingAllowed(bool bNew
);
223 virtual rtl::Reference
<sdr::overlay::OverlayManager
> CreateOverlayManager(OutputDevice
& rDevice
) const;
226 svtools::ColorConfig maColorConfig
;
229 // Interface to SdrPaintWindow
230 void DeletePaintWindow(SdrPaintWindow
& rOld
);
231 void ConfigurationChanged( ::utl::ConfigurationBroadcaster
*, ConfigurationHints
) override
;
232 void InitOverlayManager(rtl::Reference
<sdr::overlay::OverlayManager
> xOverlayManager
) const;
235 sal_uInt32
PaintWindowCount() const { return maPaintWindows
.size(); }
236 SdrPaintWindow
* FindPaintWindow(const OutputDevice
& rOut
) const;
237 SdrPaintWindow
* GetPaintWindow(sal_uInt32 nIndex
) const;
238 // Replacement for GetWin(0), may return 0L (!)
239 OutputDevice
* GetFirstOutputDevice() const;
242 SVX_DLLPRIVATE
void ImpClearVars();
243 DECL_LINK(ImpComeBackHdl
, Timer
*, void);
246 sal_uInt16
ImpGetMinMovLogic(short nMinMov
, const OutputDevice
* pOut
) const;
247 sal_uInt16
ImpGetHitTolLogic(short nHitTol
, const OutputDevice
* pOut
) const;
249 // If one does not want to wait for the IdleState of the system (cheated as const)
250 void FlushComeBackTimer() const;
251 void TheresNewMapMode();
252 void ImpSetGlueVisible2(bool bOn
) { if (mbGlueVisible2
!=bOn
) { mbGlueVisible2
=bOn
; if (!mbGlueVisible
&& !mbGlueVisible3
&& !mbGlueVisible4
) GlueInvalidate(); } }
253 void ImpSetGlueVisible3(bool bOn
) { if (mbGlueVisible3
!=bOn
) { mbGlueVisible3
=bOn
; if (!mbGlueVisible
&& !mbGlueVisible2
&& !mbGlueVisible4
) GlueInvalidate(); } }
254 void ImpSetGlueVisible4(bool bOn
) { if (mbGlueVisible4
!=bOn
) { mbGlueVisible4
=bOn
; if (!mbGlueVisible
&& !mbGlueVisible2
&& !mbGlueVisible3
) GlueInvalidate(); } }
257 bool ImpIsGlueVisible() { return mbGlueVisible
|| mbGlueVisible2
|| mbGlueVisible3
|| mbGlueVisible4
; }
260 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
261 void GlueInvalidate() const;
263 // ModelHasChanged is called, as soon as the system is idle again after many SdrHintKind::ObjectChange.
265 // Any sub-class override this method, MUST call the base class' ModelHasChanged() method
266 virtual void ModelHasChanged();
268 // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
269 // A SdrView always needs a SdrModel for lifetime (Pool, ...)
270 SdrPaintView(SdrModel
& rSdrModel
, OutputDevice
* pOut
);
271 virtual ~SdrPaintView() override
;
274 // SdrModel access on SdrView level
275 SdrModel
& getSdrModelFromSdrView() const { return mrSdrModelFromSdrView
; }
277 virtual void ClearPageView();
278 SdrModel
* GetModel() const { return mpModel
; }
280 virtual bool IsAction() const;
281 virtual void MovAction(const Point
& rPnt
);
282 virtual void EndAction();
283 virtual void BckAction();
284 virtual void BrkAction(); // Cancel all Actions (e.g. cancel dragging)
285 virtual void TakeActionRect(tools::Rectangle
& rRect
) const;
287 // Info about TextEdit. Default is sal_False.
288 virtual bool IsTextEdit() const;
290 // Must be called for every Window change as well as MapMode (Scaling) change:
291 // If the SdrView is shown in multiple windows at the same time (e.g.
292 // using the split pane), so that I can convert my pixel values to logical
294 void SetActualWin(const OutputDevice
* pWin
);
295 void SetMinMoveDistancePixel(sal_uInt16 nVal
) { mnMinMovPix
=nVal
; TheresNewMapMode(); }
296 void SetHitTolerancePixel(sal_uInt16 nVal
) { mnHitTolPix
=nVal
; TheresNewMapMode(); }
297 sal_uInt16
GetHitTolerancePixel() const { return mnHitTolPix
; }
299 // Data read access on logic HitTolerance and MinMoveTolerance
300 sal_uInt16
getHitTolLog() const { return mnHitTolLog
; }
302 // Using the DragState we can tell e.g. which distance was
304 const SdrDragStat
& GetDragStat() const { return maDragStat
; }
306 // Registering/de-registering a PageView at a View
308 // The same Page cannot be registered multiple times.
310 // Methods ending in PgNum expect being passed a Page number.
311 // Methods ending in PvNum, instead, expect the number of the
312 // PageView at the SdrView (iterating over all registered Pages).
313 virtual SdrPageView
* ShowSdrPage(SdrPage
* pPage
);
314 virtual void HideSdrPage();
316 // Iterate over all registered PageViews
317 SdrPageView
* GetSdrPageView() const { return mpPageView
.get(); }
319 // A SdrView can be displayed on multiple Windows at the same time
320 virtual void AddWindowToPaintView(OutputDevice
* pNewWin
, vcl::Window
* pWindow
);
321 virtual void DeleteWindowFromPaintView(OutputDevice
* pOldWin
);
323 void SetLayerVisible(const OUString
& rName
, bool bShow
);
324 bool IsLayerVisible(const OUString
& rName
) const;
326 void SetLayerLocked(const OUString
& rName
, bool bLock
=true);
327 bool IsLayerLocked(const OUString
& rName
) const;
329 void SetLayerPrintable(const OUString
& rName
, bool bPrn
);
330 bool IsLayerPrintable(const OUString
& rName
) const;
332 // PrePaint call forwarded from app windows
336 // Used internally for Draw/Impress/sch/chart2
337 virtual void CompleteRedraw(OutputDevice
* pOut
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
= nullptr);
339 // #i72889# used from CompleteRedraw() implementation internally, added to be able to do a complete redraw in single steps
341 // BeginCompleteRedraw returns (or even creates) a SdrPaintWindow which will then be used as the
342 // target for paints. Since paints may be buffered, use its GetTargetOutputDevice() method which will
343 // return the buffer in case it's buffered.
345 // DoCompleteRedraw then draws the DrawingLayer hierarchy
346 // EndCompleteRedraw does the necessary refreshes, paints text edit and overlay as well as destroys the
347 // SdrPaintWindow again, if needed.
348 // This means: the SdrPaintWindow is no longer safe after this closing call.
349 virtual SdrPaintWindow
* BeginCompleteRedraw(OutputDevice
* pOut
);
350 void DoCompleteRedraw(SdrPaintWindow
& rPaintWindow
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
= nullptr);
351 virtual void EndCompleteRedraw(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
);
354 // Used for the other applications basctl/sc/sw which call DrawLayer at PageViews
355 // #i74769# Interface change to use common BeginCompleteRedraw/EndCompleteRedraw
356 // #i76114# bDisableIntersect disables intersecting rReg with the Window's paint region
357 SdrPaintWindow
* BeginDrawLayers(OutputDevice
* pOut
, const vcl::Region
& rReg
, bool bDisableIntersect
= false);
359 // Used when the region passed to BeginDrawLayers needs to be changed
360 void UpdateDrawLayersRegion(OutputDevice
* pOut
, const vcl::Region
& rReg
);
361 void EndDrawLayers(SdrPaintWindow
& rPaintWindow
, bool bPaintFormLayer
);
365 // Used to paint the form layer after the PreRender device is flushed (painted) to the window.
366 void ImpFormLayerDrawing( SdrPaintWindow
& rPaintWindow
);
368 static vcl::Region
OptimizeDrawLayersRegion(OutputDevice
* pOut
, const vcl::Region
& rReg
, bool bDisableIntersect
);
371 /// Draw Page as a white area or not
372 bool IsPageVisible() const { return mbPageVisible
; }
374 /// Draw Page shadow or not
375 bool IsPageShadowVisible() const { return mbPageShadowVisible
; }
377 /// Draw Page as a white area or not
378 bool IsPageBorderVisible() const { return mbPageBorderVisible
; }
380 /// Draw Border line or not
381 bool IsBordVisible() const { return mbBordVisible
; }
384 bool IsGridVisible() const { return mbGridVisible
; }
386 /// Draw Grid in front of objects or behind them
387 bool IsGridFront() const { return mbGridFront
; }
389 /// Draw Help line of the Page or not
390 bool IsHlplVisible() const { return mbHlplVisible
; }
392 /// Draw Help line in front of the objects or behind them
393 bool IsHlplFront() const { return mbHlplFront
; }
395 const Color
& GetGridColor() const { return maGridColor
;}
396 void SetPageVisible(bool bOn
= true) { mbPageVisible
=bOn
; InvalidateAllWin(); }
397 void SetPageShadowVisible(bool bOn
) { mbPageShadowVisible
=bOn
; InvalidateAllWin(); }
398 void SetPageBorderVisible(bool bOn
= true) { mbPageBorderVisible
=bOn
; InvalidateAllWin(); }
399 void SetBordVisible(bool bOn
= true) { mbBordVisible
=bOn
; InvalidateAllWin(); }
400 void SetGridVisible(bool bOn
) { mbGridVisible
=bOn
; InvalidateAllWin(); }
401 void SetGridFront(bool bOn
) { mbGridFront
=bOn
; InvalidateAllWin(); }
402 void SetHlplVisible(bool bOn
= true) { mbHlplVisible
=bOn
; InvalidateAllWin(); }
403 void SetHlplFront(bool bOn
) { mbHlplFront
=bOn
; InvalidateAllWin(); }
404 void SetGlueVisible(bool bOn
= true) { if (mbGlueVisible
!=bOn
) { mbGlueVisible
=bOn
; if (!mbGlueVisible2
&& !mbGlueVisible3
&& !mbGlueVisible4
) GlueInvalidate(); } }
406 bool IsPreviewRenderer() const { return mbPreviewRenderer
; }
407 void SetPreviewRenderer(bool bOn
) { mbPreviewRenderer
=bOn
; }
409 // Access methods for calc and sw hide object modes
410 bool getHideOle() const { return mbHideOle
; }
411 bool getHideChart() const { return mbHideChart
; }
412 bool getHideDraw() const { return mbHideDraw
; }
413 bool getHideFormControl() const { return mbHideFormControl
; }
414 void setHideOle(bool bNew
) { if(bNew
!= mbHideOle
) mbHideOle
= bNew
; }
415 void setHideChart(bool bNew
) { if(bNew
!= mbHideChart
) mbHideChart
= bNew
; }
416 void setHideDraw(bool bNew
) { if(bNew
!= mbHideDraw
) mbHideDraw
= bNew
; }
417 void setHideFormControl(bool bNew
) { if(bNew
!= mbHideFormControl
) mbHideFormControl
= bNew
; }
419 void SetGridCoarse(const Size
& rSiz
) { maGridBig
=rSiz
; }
420 void SetGridFine(const Size
& rSiz
) {
422 if (maGridFin
.Height()==0) maGridFin
.setHeight(maGridFin
.Width());
423 if (mbGridVisible
) InvalidateAllWin();
425 const Size
& GetGridCoarse() const { return maGridBig
; }
426 const Size
& GetGridFine() const { return maGridFin
; }
428 void InvalidateAllWin();
429 void InvalidateAllWin(const tools::Rectangle
& rRect
);
431 /// If the View should not call Invalidate() on the windows, override
432 /// the following 2 methods and do something else.
433 virtual void InvalidateOneWin(OutputDevice
& rWin
);
434 virtual void InvalidateOneWin(OutputDevice
& rWin
, const tools::Rectangle
& rRect
);
436 void SetActiveLayer(const OUString
& rName
) { maActualLayer
=rName
; }
437 const OUString
& GetActiveLayer() const { return maActualLayer
; }
439 /// Leave an object group of all visible Pages (like `chdir ..` in MS-DOS)
440 void LeaveOneGroup();
442 /// Leave all entered object groups of all visible Pages (like `chdir \` in MS-DOS)
443 void LeaveAllGroup();
445 /// Determine, whether Leave is useful or not
446 bool IsGroupEntered() const;
448 /// Default attributes at the View
449 /// Newly created objects are assigned these attributes by default when they are created.
450 void SetDefaultAttr(const SfxItemSet
& rAttr
, bool bReplaceAll
);
451 const SfxItemSet
& GetDefaultAttr() const { return maDefaultAttr
; }
452 void SetDefaultStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
);
454 void SetNotPersistDefaultAttr(const SfxItemSet
& rAttr
);
455 void MergeNotPersistDefaultAttr(SfxItemSet
& rAttr
) const;
457 /// Execute a swap-in of e.g. graphics asynchronously.
458 /// This does not reload all graphics like Paint does, but kicks off
459 /// the loading there. When such an object is done loading, it is displayed.
460 /// TODO: Only works at the moment, if SwapGraphics is enabled in the model.
461 /// The default = false flag is non-persistent
462 bool IsSwapAsynchron() const { return mbSwapAsynchron
; }
463 void SetSwapAsynchron(bool bJa
=true) { mbSwapAsynchron
=bJa
; }
464 virtual bool KeyInput(const KeyEvent
& rKEvt
, vcl::Window
* pWin
);
466 virtual bool MouseButtonDown(const MouseEvent
& /*rMEvt*/, OutputDevice
* /*pWin*/) { return false; }
467 virtual bool MouseButtonUp(const MouseEvent
& /*rMEvt*/, OutputDevice
* /*pWin*/) { return false; }
468 virtual bool MouseMove(const MouseEvent
& /*rMEvt*/, OutputDevice
* /*pWin*/) { return false; }
469 virtual bool RequestHelp(const HelpEvent
& /*rHEvt*/) { return false; }
470 virtual bool Command(const CommandEvent
& /*rCEvt*/, vcl::Window
* /*pWin*/) { return false; }
472 void GetAttributes(SfxItemSet
& rTargetSet
, bool bOnlyHardAttr
) const;
474 void SetAttributes(const SfxItemSet
& rSet
, bool bReplaceAll
);
475 SfxStyleSheet
* GetStyleSheet() const; // SfxStyleSheet* GetStyleSheet(bool& rOk) const;
476 void SetStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
);
478 virtual void MakeVisible(const tools::Rectangle
& rRect
, vcl::Window
& rWin
);
481 /// Is called by the Paint of the OLE object
482 virtual void DoConnect(SdrOle2Obj
* pOleObj
);
484 /// Enable/disable animations for ::Paint
485 /// Is used by e.g. SdrGrafObj, if it contains an animation
486 /// Preventing automatic animation is needed for e.g. the presentation view
487 bool IsAnimationEnabled() const { return ( SdrAnimationMode::Animate
== meAnimationMode
); }
488 void SetAnimationEnabled( bool bEnable
=true );
490 /// Set/unset pause state for animations
491 void SetAnimationPause( bool bSet
);
493 /// Mode when starting an animation in the Paint Handler:
494 /// 1. SdrAnimationMode::Animate (default): start animation normally
495 /// 2. SDR_ANIMATION_DONT_ANIMATE: only show the replacement picture
496 /// 3. SdrAnimationMode::Disable: don't start and don't show any replacement
497 void SetAnimationMode( const SdrAnimationMode eMode
);
499 /// The Browser is destroyed for bShow=false
501 void ShowItemBrowser(bool bShow
);
502 bool IsItemBrowserVisible() const { return mpItemBrowser
!=nullptr && GetItemBrowser()->IsVisible(); }
503 vcl::Window
* GetItemBrowser() const;
506 /// Must be called by the App when scrolling etc. in order for
507 /// an active FormControl to be moved too
508 void VisAreaChanged(const OutputDevice
* pOut
);
509 void VisAreaChanged();
511 bool IsPrintPreview() const { return mbPrintPreview
; }
512 void SetPrintPreview(bool bOn
= true) { mbPrintPreview
=bOn
; }
514 const svtools::ColorConfig
& getColorConfig() const { return maColorConfig
;}
516 void onChangeColorConfig();
518 // #103834# Set background color for svx at SdrPageViews
519 void SetApplicationBackgroundColor(Color aBackgroundColor
);
521 // #103911# Set document color for svx at SdrPageViews
522 void SetApplicationDocumentColor(Color aDocumentColor
);
525 // Sets the timer for Object animations and restarts.
526 void SetAnimationTimer(sal_uInt32 nTime
);
528 // Access to Drawinglayer configuration options
529 const SvtOptionsDrawinglayer
& getOptionsDrawinglayer() const { return maDrawinglayerOpt
; }
532 #endif // INCLUDED_SVX_SVDPNTV_HXX
534 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */