xref: /aoo41x/main/sw/source/ui/docvw/OverlayRanges.cxx (revision dec99bbd)
1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21 
22 
23 // MARKER(update_precomp.py): autogen include statement, do not remove
24 #include "precompiled_sw.hxx"
25 
26 #include <OverlayRanges.hxx>
27 #include <view.hxx>
28 #include <svx/sdrpaintwindow.hxx>
29 #include <svx/svdview.hxx>
30 #include <svx/sdr/overlay/overlaymanager.hxx>
31 #include <basegfx/polygon/b2dpolygon.hxx>
32 #include <basegfx/polygon/b2dpolypolygon.hxx>
33 #include <basegfx/polygon/b2dpolygontools.hxx>
34 #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
35 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
36 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 namespace
41 {
42     // combine ranges geometrically to a single, ORed polygon
impCombineRangesToPolyPolygon(const std::vector<basegfx::B2DRange> & rRanges)43     basegfx::B2DPolyPolygon impCombineRangesToPolyPolygon(const std::vector< basegfx::B2DRange >& rRanges)
44     {
45         const sal_uInt32 nCount(rRanges.size());
46         basegfx::B2DPolyPolygon aRetval;
47 
48         for(sal_uInt32 a(0); a < nCount; a++)
49         {
50             const basegfx::B2DPolygon aDiscretePolygon(basegfx::tools::createPolygonFromRect(rRanges[a]));
51 
52             if(0 == a)
53             {
54                 aRetval.append(aDiscretePolygon);
55             }
56             else
57             {
58                 aRetval = basegfx::tools::solvePolygonOperationOr(aRetval, basegfx::B2DPolyPolygon(aDiscretePolygon));
59             }
60         }
61 
62         return aRetval;
63     }
64 }
65 
66 namespace sw
67 {
68     namespace overlay
69     {
createOverlayObjectPrimitive2DSequence()70         drawinglayer::primitive2d::Primitive2DSequence OverlayRanges::createOverlayObjectPrimitive2DSequence()
71         {
72             const sal_uInt32 nCount(getRanges().size());
73             drawinglayer::primitive2d::Primitive2DSequence aRetval;
74             aRetval.realloc(nCount);
75             for ( sal_uInt32 a = 0; a < nCount; ++a )
76             {
77                 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
78                 const basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(maRanges[a]));
79                 aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(
80                     new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
81                     basegfx::B2DPolyPolygon(aPolygon),
82                     aRGBColor));
83             }
84             // embed all rectangles in transparent paint
85             const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
86             const sal_uInt16 nTransparence( aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() );
87             const double fTransparence( nTransparence / 100.0 );
88             const drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparence(
89                 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
90                 aRetval,
91                 fTransparence));
92 
93             if ( mbShowSolidBorder )
94             {
95                 const basegfx::BColor aRGBColor(getBaseColor().getBColor());
96                 const basegfx::B2DPolyPolygon aPolyPolygon(impCombineRangesToPolyPolygon(getRanges()));
97                 const drawinglayer::primitive2d::Primitive2DReference aOutline(
98                     new drawinglayer::primitive2d::PolyPolygonHairlinePrimitive2D(
99                     aPolyPolygon,
100                     aRGBColor));
101 
102                 aRetval.realloc(2);
103                 aRetval[0] = aUnifiedTransparence;
104                 aRetval[1] = aOutline;
105             }
106             else
107             {
108                 aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedTransparence, 1);
109             }
110 
111             return aRetval;
112         }
113 
CreateOverlayRange(SwView & rDocView,const Color & rColor,const std::vector<basegfx::B2DRange> & rRanges,const bool bShowSolidBorder)114         /*static*/ OverlayRanges* OverlayRanges::CreateOverlayRange(
115             SwView& rDocView,
116             const Color& rColor,
117             const std::vector< basegfx::B2DRange >& rRanges,
118             const bool bShowSolidBorder )
119         {
120             OverlayRanges* pOverlayRanges = NULL;
121 
122             SdrView* pView = rDocView.GetDrawView();
123             if ( pView != NULL )
124             {
125                 SdrPaintWindow* pCandidate = pView->GetPaintWindow(0);
126                 sdr::overlay::OverlayManager* pTargetOverlay = pCandidate->GetOverlayManager();
127 
128                 if ( pTargetOverlay != NULL )
129                 {
130                     pOverlayRanges = new sw::overlay::OverlayRanges( rColor, rRanges, bShowSolidBorder );
131                     pTargetOverlay->add( *pOverlayRanges );
132                 }
133             }
134 
135             return pOverlayRanges;
136         }
137 
OverlayRanges(const Color & rColor,const std::vector<basegfx::B2DRange> & rRanges,const bool bShowSolidBorder)138         OverlayRanges::OverlayRanges(
139             const Color& rColor,
140             const std::vector< basegfx::B2DRange >& rRanges,
141             const bool bShowSolidBorder )
142             : sdr::overlay::OverlayObject( rColor )
143             , maRanges( rRanges )
144             , mbShowSolidBorder( bShowSolidBorder )
145         {
146             // no AA for highlight overlays
147             allowAntiAliase(false);
148         }
149 
~OverlayRanges()150         OverlayRanges::~OverlayRanges()
151         {
152             if( getOverlayManager() )
153             {
154                 getOverlayManager()->remove(*this);
155             }
156         }
157 
setRanges(const std::vector<basegfx::B2DRange> & rNew)158         void OverlayRanges::setRanges(const std::vector< basegfx::B2DRange >& rNew)
159         {
160             if(rNew != maRanges)
161             {
162                 maRanges = rNew;
163                 objectChange();
164             }
165         }
166 
167 
ShowSolidBorder()168         void OverlayRanges::ShowSolidBorder()
169         {
170             if ( !mbShowSolidBorder )
171             {
172                 mbShowSolidBorder = true;
173                 objectChange();
174             }
175         }
176 
HideSolidBorder()177         void OverlayRanges::HideSolidBorder()
178         {
179             if ( mbShowSolidBorder )
180             {
181                 mbShowSolidBorder = false;
182                 objectChange();
183             }
184         }
185 
186     } // end of namespace overlay
187 } // end of namespace sdr
188 
189 //////////////////////////////////////////////////////////////////////////////
190 // eof
191