Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svx/xoutbmp.hxx>
30 : : #include <svx/dialogs.hrc>
31 : : #include <svx/svxids.hrc>
32 : : #include <contdlg.hrc>
33 : : #include <contwnd.hxx>
34 : : #include <svx/svdpage.hxx>
35 : : #include <svx/svdopath.hxx>
36 : : #include <svx/xfltrit.hxx>
37 : : #include <svx/xfillit.hxx>
38 : : #include <basegfx/polygon/b2dpolygon.hxx>
39 : : #include <basegfx/polygon/b2dpolypolygontools.hxx>
40 : :
41 : : // #i75482#
42 : : #include "svx/sdrpaintwindow.hxx"
43 : :
44 : : #define TRANSCOL Color( COL_WHITE )
45 : :
46 : 0 : ContourWindow::ContourWindow( Window* pParent, const ResId& rResId ) :
47 : : GraphCtrl ( pParent, rResId ),
48 : : aWorkRect ( 0, 0, 0, 0 ),
49 : : bPipetteMode ( sal_False ),
50 : : bWorkplaceMode ( sal_False ),
51 [ # # ][ # # ]: 0 : bClickValid ( sal_False )
[ # # ][ # # ]
[ # # ]
52 : : {
53 [ # # ]: 0 : SetWinStyle( WB_SDRMODE );
54 : 0 : }
55 : :
56 [ # # ]: 0 : ContourWindow::~ContourWindow()
57 : : {
58 [ # # ]: 0 : }
59 : :
60 : 0 : void ContourWindow::SetPolyPolygon( const PolyPolygon& rPolyPoly )
61 : : {
62 : 0 : SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
63 : 0 : const sal_uInt16 nPolyCount = rPolyPoly.Count();
64 : :
65 : : // First delete all drawing objects
66 : 0 : aPolyPoly = rPolyPoly;
67 : :
68 : : // To avoid to have destroyed objects which are still selected, it is necessary to deselect
69 : : // them first (!)
70 : 0 : pView->UnmarkAllObj();
71 : :
72 : 0 : pPage->Clear();
73 : :
74 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nPolyCount; i++ )
75 : : {
76 [ # # ]: 0 : basegfx::B2DPolyPolygon aPolyPolygon;
77 [ # # ][ # # ]: 0 : aPolyPolygon.append(aPolyPoly[ i ].getB2DPolygon());
[ # # ][ # # ]
78 [ # # ][ # # ]: 0 : SdrPathObj* pPathObj = new SdrPathObj( OBJ_PATHFILL, aPolyPolygon );
79 : :
80 [ # # ]: 0 : if ( pPathObj )
81 : : {
82 [ # # ]: 0 : SfxItemSet aSet( pModel->GetItemPool() );
83 : :
84 [ # # ][ # # ]: 0 : aSet.Put( XFillStyleItem( XFILL_SOLID ) );
[ # # ]
85 [ # # ][ # # ]: 0 : aSet.Put( XFillColorItem( String(), TRANSCOL ) );
[ # # ][ # # ]
[ # # ]
86 [ # # ][ # # ]: 0 : aSet.Put( XFillTransparenceItem( 50 ) );
[ # # ]
87 : :
88 [ # # ]: 0 : pPathObj->SetMergedItemSetAndBroadcast(aSet);
89 : :
90 [ # # ][ # # ]: 0 : pPage->InsertObject( pPathObj );
91 : : }
92 [ # # ]: 0 : }
93 : :
94 [ # # ]: 0 : if ( nPolyCount )
95 : : {
96 : 0 : pView->MarkAll();
97 : 0 : pView->CombineMarkedObjects( sal_False );
98 : : }
99 : :
100 : 0 : pModel->SetChanged( sal_False );
101 : 0 : }
102 : :
103 : 0 : const PolyPolygon& ContourWindow::GetPolyPolygon()
104 : : {
105 [ # # ]: 0 : if ( pModel->IsChanged() )
106 : : {
107 : 0 : SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
108 : :
109 [ # # ]: 0 : aPolyPoly = PolyPolygon();
110 : :
111 [ # # ][ # # ]: 0 : if ( pPage && pPage->GetObjCount() )
[ # # ]
112 : : {
113 [ # # ]: 0 : SdrPathObj* pPathObj = (SdrPathObj*)pPage->GetObj(0L);
114 : : // Not sure if subdivision is needed for ContourWindow, but maybe it cannot handle
115 : : // curves at all. Keeping subdivision here for security
116 [ # # ]: 0 : const basegfx::B2DPolyPolygon aB2DPolyPolygon(basegfx::tools::adaptiveSubdivideByAngle(pPathObj->GetPathPoly()));
117 [ # # ][ # # ]: 0 : aPolyPoly = PolyPolygon(aB2DPolyPolygon);
[ # # ][ # # ]
118 : : }
119 : :
120 : 0 : pModel->SetChanged( sal_False );
121 : : }
122 : :
123 : 0 : return aPolyPoly;
124 : : }
125 : :
126 : 0 : void ContourWindow::InitSdrModel()
127 : : {
128 [ # # ]: 0 : GraphCtrl::InitSdrModel();
129 : :
130 [ # # ]: 0 : SfxItemSet aSet( pModel->GetItemPool() );
131 : :
132 [ # # ][ # # ]: 0 : aSet.Put( XFillColorItem( String(), TRANSCOL ) );
[ # # ][ # # ]
[ # # ]
133 [ # # ][ # # ]: 0 : aSet.Put( XFillTransparenceItem( 50 ) );
[ # # ]
134 [ # # ]: 0 : pView->SetAttributes( aSet );
135 [ # # ][ # # ]: 0 : pView->SetFrameDragSingles( sal_True );
136 : 0 : }
137 : :
138 : 0 : void ContourWindow::SdrObjCreated( const SdrObject& )
139 : : {
140 : 0 : pView->MarkAll();
141 : 0 : pView->CombineMarkedObjects( sal_False );
142 : 0 : }
143 : :
144 : 0 : sal_Bool ContourWindow::IsContourChanged() const
145 : : {
146 : 0 : SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
147 : 0 : sal_Bool bRet = sal_False;
148 : :
149 [ # # ][ # # ]: 0 : if ( pPage && pPage->GetObjCount() )
[ # # ]
150 [ # # ][ # # ]: 0 : bRet = ( (SdrPathObj*) pPage->GetObj( 0 ) )->GetPathPoly().count() && pModel->IsChanged();
151 : :
152 : 0 : return bRet;
153 : : }
154 : :
155 : 0 : void ContourWindow::MouseButtonDown( const MouseEvent& rMEvt )
156 : : {
157 [ # # ]: 0 : if ( bWorkplaceMode )
158 : : {
159 [ # # ]: 0 : const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
160 : :
161 [ # # ][ # # ]: 0 : SetPolyPolygon( PolyPolygon() );
[ # # ]
162 [ # # ]: 0 : aWorkRect = Rectangle( aLogPt, aLogPt );
163 [ # # ][ # # ]: 0 : Paint( Rectangle( Point(), GetGraphicSize() ) );
164 [ # # ]: 0 : SetEditMode( sal_True );
165 : : }
166 : :
167 [ # # ]: 0 : if ( !bPipetteMode )
168 : 0 : GraphCtrl::MouseButtonDown( rMEvt );
169 : 0 : }
170 : :
171 : 0 : void ContourWindow::MouseMove( const MouseEvent& rMEvt )
172 : : {
173 : 0 : bClickValid = sal_False;
174 : :
175 [ # # ]: 0 : if ( bPipetteMode )
176 : : {
177 [ # # ]: 0 : const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
178 : :
179 [ # # ]: 0 : aPipetteColor = GetPixel( aLogPt );
180 [ # # ]: 0 : Control::MouseMove( rMEvt );
181 : :
182 [ # # ][ # # ]: 0 : if ( aPipetteLink.IsSet() && Rectangle( Point(), GetGraphicSize() ).IsInside( aLogPt ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
183 : : {
184 [ # # ]: 0 : SetPointer( POINTER_REFHAND );
185 [ # # ]: 0 : aPipetteLink.Call( this );
186 : : }
187 : : }
188 : : else
189 : 0 : GraphCtrl::MouseMove( rMEvt );
190 : 0 : }
191 : :
192 : 0 : void ContourWindow::MouseButtonUp(const MouseEvent& rMEvt)
193 : : {
194 : 0 : Point aTmpPoint;
195 [ # # ]: 0 : const Rectangle aGraphRect( aTmpPoint, GetGraphicSize() );
196 [ # # ]: 0 : const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
197 : :
198 [ # # ]: 0 : bClickValid = aGraphRect.IsInside( aLogPt );
199 [ # # ]: 0 : ReleaseMouse();
200 : :
201 [ # # ]: 0 : if ( bPipetteMode )
202 : : {
203 [ # # ]: 0 : Control::MouseButtonUp( rMEvt );
204 : :
205 [ # # ][ # # ]: 0 : if ( aPipetteClickLink.IsSet() )
206 [ # # ]: 0 : aPipetteClickLink.Call( this );
207 : : }
208 [ # # ]: 0 : else if ( bWorkplaceMode )
209 : : {
210 [ # # ]: 0 : GraphCtrl::MouseButtonUp( rMEvt );
211 : :
212 : 0 : aWorkRect.Right() = aLogPt.X();
213 : 0 : aWorkRect.Bottom() = aLogPt.Y();
214 [ # # ]: 0 : aWorkRect.Intersection( aGraphRect );
215 [ # # ]: 0 : aWorkRect.Justify();
216 : :
217 [ # # ][ # # ]: 0 : if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
[ # # ]
218 : : {
219 [ # # ][ # # ]: 0 : PolyPolygon _aPolyPoly( GetPolyPolygon() );
220 : :
221 [ # # ]: 0 : _aPolyPoly.Clip( aWorkRect );
222 [ # # ]: 0 : SetPolyPolygon( _aPolyPoly );
223 [ # # ]: 0 : pView->SetWorkArea( aWorkRect );
224 : : }
225 : : else
226 : 0 : pView->SetWorkArea( aGraphRect );
227 : :
228 [ # # ]: 0 : Invalidate( aGraphRect );
229 : :
230 [ # # ][ # # ]: 0 : if ( aWorkplaceClickLink.IsSet() )
231 [ # # ]: 0 : aWorkplaceClickLink.Call( this );
232 : : }
233 : : else
234 [ # # ]: 0 : GraphCtrl::MouseButtonUp( rMEvt );
235 : 0 : }
236 : :
237 : 0 : void ContourWindow::Paint( const Rectangle& rRect )
238 : : {
239 : : // #i75482#
240 : : // encapsulate the redraw using Begin/End and use the returned
241 : : // data to get the target output device (e.g. when pre-rendering)
242 [ # # ]: 0 : SdrPaintWindow* pPaintWindow = pView->BeginCompleteRedraw(this);
243 : 0 : OutputDevice& rTarget = pPaintWindow->GetTargetOutputDevice();
244 : :
245 : 0 : const Graphic& rGraphic = GetGraphic();
246 : 0 : const Color& rOldLineColor = GetLineColor();
247 : 0 : const Color& rOldFillColor = GetFillColor();
248 : :
249 [ # # ]: 0 : rTarget.SetLineColor( Color( COL_BLACK ) );
250 [ # # ]: 0 : rTarget.SetFillColor( Color( COL_WHITE ) );
251 : :
252 [ # # ][ # # ]: 0 : rTarget.DrawRect( Rectangle( Point(), GetGraphicSize() ) );
253 : :
254 [ # # ]: 0 : rTarget.SetLineColor( rOldLineColor );
255 [ # # ]: 0 : rTarget.SetFillColor( rOldFillColor );
256 : :
257 [ # # ][ # # ]: 0 : if ( rGraphic.GetType() != GRAPHIC_NONE )
258 [ # # ]: 0 : rGraphic.Draw( &rTarget, Point(), GetGraphicSize() );
259 : :
260 [ # # ][ # # ]: 0 : if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
[ # # ]
261 : : {
262 [ # # ]: 0 : PolyPolygon _aPolyPoly( 2, 2 );
263 : 0 : const Color aOldFillColor( GetFillColor() );
264 : :
265 [ # # ][ # # ]: 0 : _aPolyPoly.Insert( Rectangle( Point(), GetGraphicSize() ) );
[ # # ][ # # ]
266 [ # # ][ # # ]: 0 : _aPolyPoly.Insert( aWorkRect );
[ # # ]
267 : :
268 [ # # ]: 0 : rTarget.SetFillColor( COL_LIGHTRED );
269 [ # # ]: 0 : rTarget.DrawTransparent( _aPolyPoly, 50 );
270 [ # # ][ # # ]: 0 : rTarget.SetFillColor( aOldFillColor );
271 : : }
272 : :
273 : : // #i75482#
274 [ # # ]: 0 : const Region aRepaintRegion(rRect);
275 [ # # ]: 0 : pView->DoCompleteRedraw(*pPaintWindow, aRepaintRegion);
276 [ # # ][ # # ]: 0 : pView->EndCompleteRedraw(*pPaintWindow, true);
277 : 0 : }
278 : :
279 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|