update credits
[LibreOffice.git] / svx / source / dialog / contwnd.cxx
blobdeb6740223074a431680f970a81960482e1aa607
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/xoutbmp.hxx>
21 #include <svx/dialogs.hrc>
22 #include <svx/svxids.hrc>
23 #include <contdlg.hrc>
24 #include <contwnd.hxx>
25 #include <svx/svdpage.hxx>
26 #include <svx/svdopath.hxx>
27 #include <svx/xfltrit.hxx>
28 #include <svx/xfillit.hxx>
29 #include <basegfx/polygon/b2dpolygon.hxx>
30 #include <basegfx/polygon/b2dpolypolygontools.hxx>
32 // #i75482#
33 #include "svx/sdrpaintwindow.hxx"
35 #define TRANSCOL Color( COL_WHITE )
37 ContourWindow::ContourWindow( Window* pParent, const ResId& rResId ) :
38 GraphCtrl ( pParent, rResId ),
39 aWorkRect ( 0, 0, 0, 0 ),
40 bPipetteMode ( sal_False ),
41 bWorkplaceMode ( sal_False ),
42 bClickValid ( sal_False )
44 SetWinStyle( WB_SDRMODE );
47 ContourWindow::~ContourWindow()
51 void ContourWindow::SetPolyPolygon( const PolyPolygon& rPolyPoly )
53 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
54 const sal_uInt16 nPolyCount = rPolyPoly.Count();
56 // First delete all drawing objects
57 aPolyPoly = rPolyPoly;
59 // To avoid to have destroyed objects which are still selected, it is necessary to deselect
60 // them first (!)
61 pView->UnmarkAllObj();
63 pPage->Clear();
65 for ( sal_uInt16 i = 0; i < nPolyCount; i++ )
67 basegfx::B2DPolyPolygon aPolyPolygon;
68 aPolyPolygon.append(aPolyPoly[ i ].getB2DPolygon());
69 SdrPathObj* pPathObj = new SdrPathObj( OBJ_PATHFILL, aPolyPolygon );
71 if ( pPathObj )
73 SfxItemSet aSet( pModel->GetItemPool() );
75 aSet.Put( XFillStyleItem( XFILL_SOLID ) );
76 aSet.Put( XFillColorItem( String(), TRANSCOL ) );
77 aSet.Put( XFillTransparenceItem( 50 ) );
79 pPathObj->SetMergedItemSetAndBroadcast(aSet);
81 pPage->InsertObject( pPathObj );
85 if ( nPolyCount )
87 pView->MarkAll();
88 pView->CombineMarkedObjects( sal_False );
91 pModel->SetChanged( sal_False );
94 const PolyPolygon& ContourWindow::GetPolyPolygon()
96 if ( pModel->IsChanged() )
98 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
100 aPolyPoly = PolyPolygon();
102 if ( pPage && pPage->GetObjCount() )
104 SdrPathObj* pPathObj = (SdrPathObj*)pPage->GetObj(0L);
105 // Not sure if subdivision is needed for ContourWindow, but maybe it cannot handle
106 // curves at all. Keeping subdivision here for security
107 const basegfx::B2DPolyPolygon aB2DPolyPolygon(basegfx::tools::adaptiveSubdivideByAngle(pPathObj->GetPathPoly()));
108 aPolyPoly = PolyPolygon(aB2DPolyPolygon);
111 pModel->SetChanged( sal_False );
114 return aPolyPoly;
117 void ContourWindow::InitSdrModel()
119 GraphCtrl::InitSdrModel();
121 SfxItemSet aSet( pModel->GetItemPool() );
123 aSet.Put( XFillColorItem( String(), TRANSCOL ) );
124 aSet.Put( XFillTransparenceItem( 50 ) );
125 pView->SetAttributes( aSet );
126 pView->SetFrameDragSingles( sal_True );
129 void ContourWindow::SdrObjCreated( const SdrObject& )
131 pView->MarkAll();
132 pView->CombineMarkedObjects( sal_False );
135 bool ContourWindow::IsContourChanged() const
137 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
138 bool bRet = false;
140 if ( pPage && pPage->GetObjCount() )
141 bRet = ( (SdrPathObj*) pPage->GetObj( 0 ) )->GetPathPoly().count() && pModel->IsChanged();
143 return bRet;
146 void ContourWindow::MouseButtonDown( const MouseEvent& rMEvt )
148 if ( bWorkplaceMode )
150 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
152 SetPolyPolygon( PolyPolygon() );
153 aWorkRect = Rectangle( aLogPt, aLogPt );
154 Paint( Rectangle( Point(), GetGraphicSize() ) );
155 SetEditMode( sal_True );
158 if ( !bPipetteMode )
159 GraphCtrl::MouseButtonDown( rMEvt );
162 void ContourWindow::MouseMove( const MouseEvent& rMEvt )
164 bClickValid = sal_False;
166 if ( bPipetteMode )
168 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
170 aPipetteColor = GetPixel( aLogPt );
171 Control::MouseMove( rMEvt );
173 if ( aPipetteLink.IsSet() && Rectangle( Point(), GetGraphicSize() ).IsInside( aLogPt ) )
175 SetPointer( POINTER_REFHAND );
176 aPipetteLink.Call( this );
179 else
180 GraphCtrl::MouseMove( rMEvt );
183 void ContourWindow::MouseButtonUp(const MouseEvent& rMEvt)
185 Point aTmpPoint;
186 const Rectangle aGraphRect( aTmpPoint, GetGraphicSize() );
187 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
189 bClickValid = aGraphRect.IsInside( aLogPt );
190 ReleaseMouse();
192 if ( bPipetteMode )
194 Control::MouseButtonUp( rMEvt );
196 if ( aPipetteClickLink.IsSet() )
197 aPipetteClickLink.Call( this );
199 else if ( bWorkplaceMode )
201 GraphCtrl::MouseButtonUp( rMEvt );
203 aWorkRect.Right() = aLogPt.X();
204 aWorkRect.Bottom() = aLogPt.Y();
205 aWorkRect.Intersection( aGraphRect );
206 aWorkRect.Justify();
208 if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
210 PolyPolygon _aPolyPoly( GetPolyPolygon() );
212 _aPolyPoly.Clip( aWorkRect );
213 SetPolyPolygon( _aPolyPoly );
214 pView->SetWorkArea( aWorkRect );
216 else
217 pView->SetWorkArea( aGraphRect );
219 Invalidate( aGraphRect );
221 if ( aWorkplaceClickLink.IsSet() )
222 aWorkplaceClickLink.Call( this );
224 else
225 GraphCtrl::MouseButtonUp( rMEvt );
228 void ContourWindow::Paint( const Rectangle& rRect )
230 // #i75482#
231 // encapsulate the redraw using Begin/End and use the returned
232 // data to get the target output device (e.g. when pre-rendering)
233 SdrPaintWindow* pPaintWindow = pView->BeginCompleteRedraw(this);
234 OutputDevice& rTarget = pPaintWindow->GetTargetOutputDevice();
236 const Graphic& rGraphic = GetGraphic();
237 const Color& rOldLineColor = GetLineColor();
238 const Color& rOldFillColor = GetFillColor();
240 rTarget.SetLineColor( Color( COL_BLACK ) );
241 rTarget.SetFillColor( Color( COL_WHITE ) );
243 rTarget.DrawRect( Rectangle( Point(), GetGraphicSize() ) );
245 rTarget.SetLineColor( rOldLineColor );
246 rTarget.SetFillColor( rOldFillColor );
248 if ( rGraphic.GetType() != GRAPHIC_NONE )
249 rGraphic.Draw( &rTarget, Point(), GetGraphicSize() );
251 if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
253 PolyPolygon _aPolyPoly( 2, 2 );
254 const Color aOldFillColor( GetFillColor() );
256 _aPolyPoly.Insert( Rectangle( Point(), GetGraphicSize() ) );
257 _aPolyPoly.Insert( aWorkRect );
259 rTarget.SetFillColor( COL_LIGHTRED );
260 rTarget.DrawTransparent( _aPolyPoly, 50 );
261 rTarget.SetFillColor( aOldFillColor );
264 // #i75482#
265 const Region aRepaintRegion(rRect);
266 pView->DoCompleteRedraw(*pPaintWindow, aRepaintRegion);
267 pView->EndCompleteRedraw(*pPaintWindow, true);
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */