/src/libreoffice/sw/source/uibase/docvw/OverlayRanges.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include "OverlayRanges.hxx" |
21 | | #include <view.hxx> |
22 | | #include <svx/sdrpaintwindow.hxx> |
23 | | #include <svx/svdview.hxx> |
24 | | #include <svx/sdr/overlay/overlaymanager.hxx> |
25 | | #include <basegfx/polygon/b2dpolygon.hxx> |
26 | | #include <basegfx/polygon/b2dpolypolygon.hxx> |
27 | | #include <basegfx/polygon/b2dpolygontools.hxx> |
28 | | #include <basegfx/polygon/b2dpolypolygoncutter.hxx> |
29 | | #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx> |
30 | | #include <drawinglayer/primitive2d/PolyPolygonHairlinePrimitive2D.hxx> |
31 | | #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx> |
32 | | #include <svtools/optionsdrawinglayer.hxx> |
33 | | |
34 | | namespace sw::overlay |
35 | | { |
36 | | drawinglayer::primitive2d::Primitive2DContainer OverlayRanges::createOverlayObjectPrimitive2DSequence() |
37 | 0 | { |
38 | 0 | const sal_uInt32 nCount(getRanges().size()); |
39 | 0 | drawinglayer::primitive2d::Primitive2DContainer aRetval; |
40 | 0 | aRetval.resize(nCount); |
41 | 0 | for ( sal_uInt32 a = 0; a < nCount; ++a ) |
42 | 0 | { |
43 | 0 | const basegfx::BColor aRGBColor(getBaseColor().getBColor()); |
44 | 0 | const basegfx::B2DPolygon aPolygon(basegfx::utils::createPolygonFromRect(maRanges[a])); |
45 | 0 | aRetval[a] = |
46 | 0 | new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D( |
47 | 0 | basegfx::B2DPolyPolygon(aPolygon), |
48 | 0 | aRGBColor); |
49 | 0 | } |
50 | | // embed all rectangles in transparent paint |
51 | 0 | const sal_uInt16 nTransparence( SvtOptionsDrawinglayer::GetTransparentSelectionPercent() ); |
52 | 0 | const double fTransparence( nTransparence / 100.0 ); |
53 | 0 | const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence( |
54 | 0 | new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D( |
55 | 0 | std::move(aRetval), |
56 | 0 | fTransparence)); |
57 | |
|
58 | 0 | if ( mbShowSolidBorder ) |
59 | 0 | { |
60 | 0 | const basegfx::BColor aRGBColor(getBaseColor().getBColor()); |
61 | 0 | basegfx::B2DPolyPolygon aPolyPolygon(basegfx::utils::combineRectanglesToPolyPolygon(getRanges())); |
62 | 0 | const drawinglayer::primitive2d::Primitive2DReference aOutline( |
63 | 0 | new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D( |
64 | 0 | std::move(aPolyPolygon), |
65 | 0 | aRGBColor)); |
66 | |
|
67 | 0 | aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence, aOutline }; |
68 | 0 | } |
69 | 0 | else |
70 | 0 | { |
71 | 0 | aRetval = drawinglayer::primitive2d::Primitive2DContainer { aUnifiedTransparence }; |
72 | 0 | } |
73 | |
|
74 | 0 | return aRetval; |
75 | 0 | } |
76 | | |
77 | | /*static*/ std::unique_ptr<OverlayRanges> OverlayRanges::CreateOverlayRange( |
78 | | SwView const & rDocView, |
79 | | const Color& rColor, |
80 | | std::vector< basegfx::B2DRange >&& rRanges, |
81 | | const bool bShowSolidBorder ) |
82 | 0 | { |
83 | 0 | std::unique_ptr<OverlayRanges> pOverlayRanges; |
84 | |
|
85 | 0 | SdrView* pView = rDocView.GetDrawView(); |
86 | 0 | if ( pView != nullptr ) |
87 | 0 | { |
88 | 0 | SdrPaintWindow* pCandidate = pView->GetPaintWindow(0); |
89 | 0 | const rtl::Reference<sdr::overlay::OverlayManager>& xTargetOverlay = pCandidate->GetOverlayManager(); |
90 | |
|
91 | 0 | if ( xTargetOverlay.is() ) |
92 | 0 | { |
93 | 0 | pOverlayRanges.reset(new sw::overlay::OverlayRanges( rColor, std::move(rRanges), bShowSolidBorder )); |
94 | 0 | xTargetOverlay->add( *pOverlayRanges ); |
95 | 0 | } |
96 | 0 | } |
97 | |
|
98 | 0 | return pOverlayRanges; |
99 | 0 | } |
100 | | |
101 | | OverlayRanges::OverlayRanges( |
102 | | const Color& rColor, |
103 | | std::vector< basegfx::B2DRange >&& rRanges, |
104 | | const bool bShowSolidBorder ) |
105 | 0 | : sdr::overlay::OverlayObject( rColor ) |
106 | 0 | , maRanges( std::move(rRanges) ) |
107 | 0 | , mbShowSolidBorder( bShowSolidBorder ) |
108 | 0 | { |
109 | | // no AA for highlight overlays |
110 | 0 | allowAntiAliase(false); |
111 | 0 | } |
112 | | |
113 | | OverlayRanges::~OverlayRanges() |
114 | 0 | { |
115 | 0 | if( getOverlayManager() ) |
116 | 0 | { |
117 | 0 | getOverlayManager()->remove(*this); |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | | void OverlayRanges::setRanges(std::vector< basegfx::B2DRange >&& rNew) |
122 | 0 | { |
123 | 0 | if(rNew != maRanges) |
124 | 0 | { |
125 | 0 | maRanges = std::move(rNew); |
126 | 0 | objectChange(); |
127 | 0 | } |
128 | 0 | } |
129 | | |
130 | | void OverlayRanges::ShowSolidBorder() |
131 | 0 | { |
132 | 0 | if ( !mbShowSolidBorder ) |
133 | 0 | { |
134 | 0 | mbShowSolidBorder = true; |
135 | 0 | objectChange(); |
136 | 0 | } |
137 | 0 | } |
138 | | |
139 | | void OverlayRanges::HideSolidBorder() |
140 | 0 | { |
141 | 0 | if ( mbShowSolidBorder ) |
142 | 0 | { |
143 | 0 | mbShowSolidBorder = false; |
144 | 0 | objectChange(); |
145 | 0 | } |
146 | 0 | } |
147 | | |
148 | | } // end of namespace sw::overlay |
149 | | |
150 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |