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