merge the formfield patch from ooo-build
[ooovba.git] / svx / source / dialog / contwnd.cxx
blob692a961cf0283521d0db494d7606c2d2b727ab31
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: contwnd.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <xoutbmp.hxx>
34 #include <svx/dialogs.hrc>
35 #include <svx/svxids.hrc>
36 #include <contdlg.hrc>
37 #include <contwnd.hxx>
38 #include <svx/svdpage.hxx>
39 #include <svx/svdopath.hxx>
40 #include <svx/xfltrit.hxx>
41 #include <svx/xfillit.hxx>
42 #include <basegfx/polygon/b2dpolygon.hxx>
43 #include <basegfx/polygon/b2dpolypolygontools.hxx>
45 // #i75482#
46 #include "sdrpaintwindow.hxx"
48 #define TRANSCOL Color( COL_WHITE )
50 /*************************************************************************
54 \************************************************************************/
56 ContourWindow::ContourWindow( Window* pParent, const ResId& rResId ) :
57 GraphCtrl ( pParent, rResId ),
58 aWorkRect ( 0, 0, 0, 0 ),
59 bPipetteMode ( FALSE ),
60 bWorkplaceMode ( FALSE ),
61 bClickValid ( FALSE )
63 SetWinStyle( WB_SDRMODE );
67 /*************************************************************************
71 \************************************************************************/
73 ContourWindow::~ContourWindow()
78 /*************************************************************************
82 \************************************************************************/
84 void ContourWindow::SetPolyPolygon( const PolyPolygon& rPolyPoly )
86 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
87 const USHORT nPolyCount = rPolyPoly.Count();
89 // zuerst alle Zeichenobjekte loeschen
90 aPolyPoly = rPolyPoly;
92 // #117412#
93 // To avoid to have destroyed objects which are still selected, it is necessary to deselect
94 // them first (!)
95 pView->UnmarkAllObj();
97 pPage->Clear();
99 for ( USHORT i = 0; i < nPolyCount; i++ )
101 basegfx::B2DPolyPolygon aPolyPolygon;
102 aPolyPolygon.append(aPolyPoly[ i ].getB2DPolygon());
103 SdrPathObj* pPathObj = new SdrPathObj( OBJ_PATHFILL, aPolyPolygon );
105 if ( pPathObj )
107 SfxItemSet aSet( pModel->GetItemPool() );
109 aSet.Put( XFillStyleItem( XFILL_SOLID ) );
110 aSet.Put( XFillColorItem( String(), TRANSCOL ) );
111 aSet.Put( XFillTransparenceItem( 50 ) );
113 //pPathObj->SetItemSetAndBroadcast(aSet);
114 pPathObj->SetMergedItemSetAndBroadcast(aSet);
116 pPage->InsertObject( pPathObj );
120 if ( nPolyCount )
122 pView->MarkAll();
123 pView->CombineMarkedObjects( sal_False );
126 pModel->SetChanged( sal_False );
130 /*************************************************************************
134 \************************************************************************/
136 const PolyPolygon& ContourWindow::GetPolyPolygon()
138 if ( pModel->IsChanged() )
140 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
142 aPolyPoly = PolyPolygon();
144 if ( pPage && pPage->GetObjCount() )
146 SdrPathObj* pPathObj = (SdrPathObj*)pPage->GetObj(0L);
147 // Not sure if subdivision is needed for ContourWindow, but maybe it cannot handle
148 // curves at all. Keeping subdivision here for security
149 const basegfx::B2DPolyPolygon aB2DPolyPolygon(basegfx::tools::adaptiveSubdivideByAngle(pPathObj->GetPathPoly()));
150 aPolyPoly = PolyPolygon(aB2DPolyPolygon);
153 pModel->SetChanged( sal_False );
156 return aPolyPoly;
160 /*************************************************************************
164 \************************************************************************/
166 void ContourWindow::InitSdrModel()
168 GraphCtrl::InitSdrModel();
170 SfxItemSet aSet( pModel->GetItemPool() );
172 aSet.Put( XFillColorItem( String(), TRANSCOL ) );
173 aSet.Put( XFillTransparenceItem( 50 ) );
174 pView->SetAttributes( aSet );
175 pView->SetFrameDragSingles( TRUE );
179 /*************************************************************************
183 \************************************************************************/
185 void ContourWindow::SdrObjCreated( const SdrObject& )
187 pView->MarkAll();
188 pView->CombineMarkedObjects( sal_False );
192 /*************************************************************************
196 \************************************************************************/
198 BOOL ContourWindow::IsContourChanged() const
200 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
201 BOOL bRet = FALSE;
203 if ( pPage && pPage->GetObjCount() )
204 bRet = ( (SdrPathObj*) pPage->GetObj( 0 ) )->GetPathPoly().count() && pModel->IsChanged();
206 return bRet;
210 /*************************************************************************
214 \************************************************************************/
216 void ContourWindow::MouseButtonDown( const MouseEvent& rMEvt )
218 if ( bWorkplaceMode )
220 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
222 SetPolyPolygon( PolyPolygon() );
223 aWorkRect = Rectangle( aLogPt, aLogPt );
224 Paint( Rectangle( Point(), GetGraphicSize() ) );
225 SetEditMode( TRUE );
228 if ( !bPipetteMode )
229 GraphCtrl::MouseButtonDown( rMEvt );
233 /*************************************************************************
237 \************************************************************************/
239 void ContourWindow::MouseMove( const MouseEvent& rMEvt )
241 bClickValid = FALSE;
243 if ( bPipetteMode )
245 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
247 aPipetteColor = GetPixel( aLogPt );
248 Control::MouseMove( rMEvt );
250 if ( aPipetteLink.IsSet() && Rectangle( Point(), GetGraphicSize() ).IsInside( aLogPt ) )
252 SetPointer( POINTER_REFHAND );
253 aPipetteLink.Call( this );
256 else
257 GraphCtrl::MouseMove( rMEvt );
261 /*************************************************************************
265 \************************************************************************/
267 void ContourWindow::MouseButtonUp(const MouseEvent& rMEvt)
269 Point aTmpPoint;
270 const Rectangle aGraphRect( aTmpPoint, GetGraphicSize() );
271 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
273 bClickValid = aGraphRect.IsInside( aLogPt );
274 ReleaseMouse();
276 if ( bPipetteMode )
278 Control::MouseButtonUp( rMEvt );
280 if ( aPipetteClickLink.IsSet() )
281 aPipetteClickLink.Call( this );
283 else if ( bWorkplaceMode )
285 GraphCtrl::MouseButtonUp( rMEvt );
287 aWorkRect.Right() = aLogPt.X();
288 aWorkRect.Bottom() = aLogPt.Y();
289 aWorkRect.Intersection( aGraphRect );
290 aWorkRect.Justify();
292 if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
294 PolyPolygon _aPolyPoly( GetPolyPolygon() );
296 _aPolyPoly.Clip( aWorkRect );
297 SetPolyPolygon( _aPolyPoly );
298 pView->SetWorkArea( aWorkRect );
300 else
301 pView->SetWorkArea( aGraphRect );
303 Invalidate( aGraphRect );
305 if ( aWorkplaceClickLink.IsSet() )
306 aWorkplaceClickLink.Call( this );
308 else
309 GraphCtrl::MouseButtonUp( rMEvt );
313 /*************************************************************************
317 \************************************************************************/
319 void ContourWindow::Paint( const Rectangle& rRect )
321 // #i75482#
322 // encapsulate the redraw using Begin/End and use the returned
323 // data to get the target output device (e.g. when pre-rendering)
324 SdrPaintWindow* pPaintWindow = pView->BeginCompleteRedraw(this);
325 OutputDevice& rTarget = pPaintWindow->GetTargetOutputDevice();
327 const Graphic& rGraphic = GetGraphic();
328 const Color& rOldLineColor = GetLineColor();
329 const Color& rOldFillColor = GetFillColor();
331 rTarget.SetLineColor( Color( COL_BLACK ) );
332 rTarget.SetFillColor( Color( COL_WHITE ) );
334 rTarget.DrawRect( Rectangle( Point(), GetGraphicSize() ) );
336 rTarget.SetLineColor( rOldLineColor );
337 rTarget.SetFillColor( rOldFillColor );
339 if ( rGraphic.GetType() != GRAPHIC_NONE )
340 rGraphic.Draw( &rTarget, Point(), GetGraphicSize() );
342 if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
344 PolyPolygon _aPolyPoly( 2, 2 );
345 const Color aOldFillColor( GetFillColor() );
347 _aPolyPoly.Insert( Rectangle( Point(), GetGraphicSize() ) );
348 _aPolyPoly.Insert( aWorkRect );
350 rTarget.SetFillColor( COL_LIGHTRED );
351 rTarget.DrawTransparent( _aPolyPoly, 50 );
352 rTarget.SetFillColor( aOldFillColor );
355 // #i75482#
356 const Region aRepaintRegion(rRect);
357 pView->DoCompleteRedraw(*pPaintWindow, aRepaintRegion);
358 pView->EndCompleteRedraw(*pPaintWindow, true);
361 // eof