Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / dialog / contwnd.cxx
blob41fb49896454b27703371447ddea670a9b4b2664
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>
31 #include "svx/sdrpaintwindow.hxx"
33 #define TRANSCOL Color( COL_WHITE )
35 ContourWindow::ContourWindow( Window* pParent, const ResId& rResId ) :
36 GraphCtrl ( pParent, rResId ),
37 aWorkRect ( 0, 0, 0, 0 ),
38 bPipetteMode ( false ),
39 bWorkplaceMode ( false ),
40 bClickValid ( false )
42 SetWinStyle( WB_SDRMODE );
45 ContourWindow::~ContourWindow()
49 void ContourWindow::SetPolyPolygon( const PolyPolygon& rPolyPoly )
51 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
52 const sal_uInt16 nPolyCount = rPolyPoly.Count();
54 // First delete all drawing objects
55 aPolyPoly = rPolyPoly;
57 // To avoid to have destroyed objects which are still selected, it is necessary to deselect
58 // them first (!)
59 pView->UnmarkAllObj();
61 pPage->Clear();
63 for ( sal_uInt16 i = 0; i < nPolyCount; i++ )
65 basegfx::B2DPolyPolygon aPolyPolygon;
66 aPolyPolygon.append(aPolyPoly[ i ].getB2DPolygon());
67 SdrPathObj* pPathObj = new SdrPathObj( OBJ_PATHFILL, aPolyPolygon );
69 if ( pPathObj )
71 SfxItemSet aSet( pModel->GetItemPool() );
73 aSet.Put( XFillStyleItem( XFILL_SOLID ) );
74 aSet.Put( XFillColorItem( "", TRANSCOL ) );
75 aSet.Put( XFillTransparenceItem( 50 ) );
77 pPathObj->SetMergedItemSetAndBroadcast(aSet);
79 pPage->InsertObject( pPathObj );
83 if ( nPolyCount )
85 pView->MarkAll();
86 pView->CombineMarkedObjects( false );
89 pModel->SetChanged( false );
92 const PolyPolygon& ContourWindow::GetPolyPolygon()
94 if ( pModel->IsChanged() )
96 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
98 aPolyPoly = PolyPolygon();
100 if ( pPage && pPage->GetObjCount() )
102 SdrPathObj* pPathObj = (SdrPathObj*)pPage->GetObj(0L);
103 // Not sure if subdivision is needed for ContourWindow, but maybe it cannot handle
104 // curves at all. Keeping subdivision here for security
105 const basegfx::B2DPolyPolygon aB2DPolyPolygon(basegfx::tools::adaptiveSubdivideByAngle(pPathObj->GetPathPoly()));
106 aPolyPoly = PolyPolygon(aB2DPolyPolygon);
109 pModel->SetChanged( false );
112 return aPolyPoly;
115 void ContourWindow::InitSdrModel()
117 GraphCtrl::InitSdrModel();
119 SfxItemSet aSet( pModel->GetItemPool() );
121 aSet.Put( XFillColorItem( "", TRANSCOL ) );
122 aSet.Put( XFillTransparenceItem( 50 ) );
123 pView->SetAttributes( aSet );
124 pView->SetFrameDragSingles( true );
127 void ContourWindow::SdrObjCreated( const SdrObject& )
129 pView->MarkAll();
130 pView->CombineMarkedObjects( false );
133 bool ContourWindow::IsContourChanged() const
135 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
136 bool bRet = false;
138 if ( pPage && pPage->GetObjCount() )
139 bRet = ( (SdrPathObj*) pPage->GetObj( 0 ) )->GetPathPoly().count() && pModel->IsChanged();
141 return bRet;
144 void ContourWindow::MouseButtonDown( const MouseEvent& rMEvt )
146 if ( bWorkplaceMode )
148 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
150 SetPolyPolygon( PolyPolygon() );
151 aWorkRect = Rectangle( aLogPt, aLogPt );
152 Paint( Rectangle( Point(), GetGraphicSize() ) );
153 SetEditMode( true );
156 if ( !bPipetteMode )
157 GraphCtrl::MouseButtonDown( rMEvt );
160 void ContourWindow::MouseMove( const MouseEvent& rMEvt )
162 bClickValid = false;
164 if ( bPipetteMode )
166 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
168 aPipetteColor = GetPixel( aLogPt );
169 Control::MouseMove( rMEvt );
171 if ( aPipetteLink.IsSet() && Rectangle( Point(), GetGraphicSize() ).IsInside( aLogPt ) )
173 SetPointer( POINTER_REFHAND );
174 aPipetteLink.Call( this );
177 else
178 GraphCtrl::MouseMove( rMEvt );
181 void ContourWindow::MouseButtonUp(const MouseEvent& rMEvt)
183 Point aTmpPoint;
184 const Rectangle aGraphRect( aTmpPoint, GetGraphicSize() );
185 const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
187 bClickValid = aGraphRect.IsInside( aLogPt );
188 ReleaseMouse();
190 if ( bPipetteMode )
192 Control::MouseButtonUp( rMEvt );
194 if ( aPipetteClickLink.IsSet() )
195 aPipetteClickLink.Call( this );
197 else if ( bWorkplaceMode )
199 GraphCtrl::MouseButtonUp( rMEvt );
201 aWorkRect.Right() = aLogPt.X();
202 aWorkRect.Bottom() = aLogPt.Y();
203 aWorkRect.Intersection( aGraphRect );
204 aWorkRect.Justify();
206 if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
208 PolyPolygon _aPolyPoly( GetPolyPolygon() );
210 _aPolyPoly.Clip( aWorkRect );
211 SetPolyPolygon( _aPolyPoly );
212 pView->SetWorkArea( aWorkRect );
214 else
215 pView->SetWorkArea( aGraphRect );
217 Invalidate( aGraphRect );
219 if ( aWorkplaceClickLink.IsSet() )
220 aWorkplaceClickLink.Call( this );
222 else
223 GraphCtrl::MouseButtonUp( rMEvt );
226 void ContourWindow::Paint( const Rectangle& rRect )
228 // #i75482#
229 // encapsulate the redraw using Begin/End and use the returned
230 // data to get the target output device (e.g. when pre-rendering)
231 SdrPaintWindow* pPaintWindow = pView->BeginCompleteRedraw(this);
232 OutputDevice& rTarget = pPaintWindow->GetTargetOutputDevice();
234 const Graphic& rGraphic = GetGraphic();
235 const Color& rOldLineColor = GetLineColor();
236 const Color& rOldFillColor = GetFillColor();
238 rTarget.SetLineColor( Color( COL_BLACK ) );
239 rTarget.SetFillColor( Color( COL_WHITE ) );
241 rTarget.DrawRect( Rectangle( Point(), GetGraphicSize() ) );
243 rTarget.SetLineColor( rOldLineColor );
244 rTarget.SetFillColor( rOldFillColor );
246 if ( rGraphic.GetType() != GRAPHIC_NONE )
247 rGraphic.Draw( &rTarget, Point(), GetGraphicSize() );
249 if ( aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom() )
251 PolyPolygon _aPolyPoly( 2, 2 );
252 const Color aOldFillColor( GetFillColor() );
254 _aPolyPoly.Insert( Rectangle( Point(), GetGraphicSize() ) );
255 _aPolyPoly.Insert( aWorkRect );
257 rTarget.SetFillColor( COL_LIGHTRED );
258 rTarget.DrawTransparent( _aPolyPoly, 50 );
259 rTarget.SetFillColor( aOldFillColor );
262 // #i75482#
263 const Region aRepaintRegion(rRect);
264 pView->DoCompleteRedraw(*pPaintWindow, aRepaintRegion);
265 pView->EndCompleteRedraw(*pPaintWindow, true);
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */