Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / dialog / contwnd.cxx
bloba21c6a1ac2cc06eaee59fa675681fb10a5ed5bf4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
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>
41 // #i75482#
42 #include "svx/sdrpaintwindow.hxx"
44 #define TRANSCOL Color( COL_WHITE )
46 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 bClickValid ( sal_False )
53 SetWinStyle( WB_SDRMODE );
56 ContourWindow::~ContourWindow()
60 void ContourWindow::SetPolyPolygon( const PolyPolygon& rPolyPoly )
62 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
63 const sal_uInt16 nPolyCount = rPolyPoly.Count();
65 // First delete all drawing objects
66 aPolyPoly = rPolyPoly;
68 // To avoid to have destroyed objects which are still selected, it is necessary to deselect
69 // them first (!)
70 pView->UnmarkAllObj();
72 pPage->Clear();
74 for ( sal_uInt16 i = 0; i < nPolyCount; i++ )
76 basegfx::B2DPolyPolygon aPolyPolygon;
77 aPolyPolygon.append(aPolyPoly[ i ].getB2DPolygon());
78 SdrPathObj* pPathObj = new SdrPathObj( OBJ_PATHFILL, aPolyPolygon );
80 if ( pPathObj )
82 SfxItemSet aSet( pModel->GetItemPool() );
84 aSet.Put( XFillStyleItem( XFILL_SOLID ) );
85 aSet.Put( XFillColorItem( String(), TRANSCOL ) );
86 aSet.Put( XFillTransparenceItem( 50 ) );
88 pPathObj->SetMergedItemSetAndBroadcast(aSet);
90 pPage->InsertObject( pPathObj );
94 if ( nPolyCount )
96 pView->MarkAll();
97 pView->CombineMarkedObjects( sal_False );
100 pModel->SetChanged( sal_False );
103 const PolyPolygon& ContourWindow::GetPolyPolygon()
105 if ( pModel->IsChanged() )
107 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
109 aPolyPoly = PolyPolygon();
111 if ( pPage && pPage->GetObjCount() )
113 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 const basegfx::B2DPolyPolygon aB2DPolyPolygon(basegfx::tools::adaptiveSubdivideByAngle(pPathObj->GetPathPoly()));
117 aPolyPoly = PolyPolygon(aB2DPolyPolygon);
120 pModel->SetChanged( sal_False );
123 return aPolyPoly;
126 void ContourWindow::InitSdrModel()
128 GraphCtrl::InitSdrModel();
130 SfxItemSet aSet( pModel->GetItemPool() );
132 aSet.Put( XFillColorItem( String(), TRANSCOL ) );
133 aSet.Put( XFillTransparenceItem( 50 ) );
134 pView->SetAttributes( aSet );
135 pView->SetFrameDragSingles( sal_True );
138 void ContourWindow::SdrObjCreated( const SdrObject& )
140 pView->MarkAll();
141 pView->CombineMarkedObjects( sal_False );
144 sal_Bool ContourWindow::IsContourChanged() const
146 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
147 sal_Bool bRet = sal_False;
149 if ( pPage && pPage->GetObjCount() )
150 bRet = ( (SdrPathObj*) pPage->GetObj( 0 ) )->GetPathPoly().count() && pModel->IsChanged();
152 return bRet;
155 void ContourWindow::MouseButtonDown( const MouseEvent& rMEvt )
157 if ( bWorkplaceMode )
159 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
161 SetPolyPolygon( PolyPolygon() );
162 aWorkRect = Rectangle( aLogPt, aLogPt );
163 Paint( Rectangle( Point(), GetGraphicSize() ) );
164 SetEditMode( sal_True );
167 if ( !bPipetteMode )
168 GraphCtrl::MouseButtonDown( rMEvt );
171 void ContourWindow::MouseMove( const MouseEvent& rMEvt )
173 bClickValid = sal_False;
175 if ( bPipetteMode )
177 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
179 aPipetteColor = GetPixel( aLogPt );
180 Control::MouseMove( rMEvt );
182 if ( aPipetteLink.IsSet() && Rectangle( Point(), GetGraphicSize() ).IsInside( aLogPt ) )
184 SetPointer( POINTER_REFHAND );
185 aPipetteLink.Call( this );
188 else
189 GraphCtrl::MouseMove( rMEvt );
192 void ContourWindow::MouseButtonUp(const MouseEvent& rMEvt)
194 Point aTmpPoint;
195 const Rectangle aGraphRect( aTmpPoint, GetGraphicSize() );
196 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
198 bClickValid = aGraphRect.IsInside( aLogPt );
199 ReleaseMouse();
201 if ( bPipetteMode )
203 Control::MouseButtonUp( rMEvt );
205 if ( aPipetteClickLink.IsSet() )
206 aPipetteClickLink.Call( this );
208 else if ( bWorkplaceMode )
210 GraphCtrl::MouseButtonUp( rMEvt );
212 aWorkRect.Right() = aLogPt.X();
213 aWorkRect.Bottom() = aLogPt.Y();
214 aWorkRect.Intersection( aGraphRect );
215 aWorkRect.Justify();
217 if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
219 PolyPolygon _aPolyPoly( GetPolyPolygon() );
221 _aPolyPoly.Clip( aWorkRect );
222 SetPolyPolygon( _aPolyPoly );
223 pView->SetWorkArea( aWorkRect );
225 else
226 pView->SetWorkArea( aGraphRect );
228 Invalidate( aGraphRect );
230 if ( aWorkplaceClickLink.IsSet() )
231 aWorkplaceClickLink.Call( this );
233 else
234 GraphCtrl::MouseButtonUp( rMEvt );
237 void ContourWindow::Paint( const Rectangle& rRect )
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 SdrPaintWindow* pPaintWindow = pView->BeginCompleteRedraw(this);
243 OutputDevice& rTarget = pPaintWindow->GetTargetOutputDevice();
245 const Graphic& rGraphic = GetGraphic();
246 const Color& rOldLineColor = GetLineColor();
247 const Color& rOldFillColor = GetFillColor();
249 rTarget.SetLineColor( Color( COL_BLACK ) );
250 rTarget.SetFillColor( Color( COL_WHITE ) );
252 rTarget.DrawRect( Rectangle( Point(), GetGraphicSize() ) );
254 rTarget.SetLineColor( rOldLineColor );
255 rTarget.SetFillColor( rOldFillColor );
257 if ( rGraphic.GetType() != GRAPHIC_NONE )
258 rGraphic.Draw( &rTarget, Point(), GetGraphicSize() );
260 if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
262 PolyPolygon _aPolyPoly( 2, 2 );
263 const Color aOldFillColor( GetFillColor() );
265 _aPolyPoly.Insert( Rectangle( Point(), GetGraphicSize() ) );
266 _aPolyPoly.Insert( aWorkRect );
268 rTarget.SetFillColor( COL_LIGHTRED );
269 rTarget.DrawTransparent( _aPolyPoly, 50 );
270 rTarget.SetFillColor( aOldFillColor );
273 // #i75482#
274 const Region aRepaintRegion(rRect);
275 pView->DoCompleteRedraw(*pPaintWindow, aRepaintRegion);
276 pView->EndCompleteRedraw(*pPaintWindow, true);
279 // eof
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */