xref: /trunk/main/svx/source/dialog/_contdlg.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include <vcl/wrkwin.hxx>
31 #include <sot/factory.hxx>
32 #include <tools/shl.hxx>
33 #include <vcl/salbtype.hxx>     // FRound
34 #include <vcl/msgbox.hxx>
35 #include <svl/eitem.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <svtools/miscopt.hxx>
39 #include <unotools/localedatawrapper.hxx>
40 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
41 #include <comphelper/processfactory.hxx>
42 #endif
43 
44 #define _SDR_NOITEMS
45 #define _SDR_NOTOUCH
46 #define _SDR_NOTRANSFORM
47 #define _SDR_NOOBJECTS
48 #define _SDR_NOVIEWMARKER
49 #define _SDR_NODRAGMETHODS
50 #define _SDR_NOUNDO
51 #define _SDR_NOXOUTDEV
52 #define _XOUTBMP_STATICS_ONLY
53 
54 #include <svx/dialmgr.hxx>
55 #include "svx/xoutbmp.hxx"
56 #include <svx/dialogs.hrc>
57 #include <svx/svxids.hrc>
58 #include <svx/contdlg.hxx>
59 #include "contimp.hxx"
60 #include "contdlg.hrc"
61 #include "contwnd.hxx"
62 #include <svx/svdtrans.hxx>
63 #include <svx/svdopath.hxx>
64 #include "svx/dlgutil.hxx"
65 #include <vcl/svapp.hxx>
66 
67 /******************************************************************************/
68 
69 inline String GetUnitString( long nVal_100, FieldUnit eFieldUnit, sal_Unicode cSep )
70 {
71     String aVal = UniString::CreateFromInt64( MetricField::ConvertValue( nVal_100, 2, MAP_100TH_MM, eFieldUnit ) );
72 
73     while( aVal.Len() < 3 )
74         aVal.Insert( sal_Unicode('0'), 0 );
75 
76     aVal.Insert( cSep, aVal.Len() - 2 );
77     aVal += sal_Unicode(' ');
78     aVal += SdrFormatter::GetUnitStr( eFieldUnit );
79 
80     return aVal;
81 }
82 
83 
84 /******************************************************************************/
85 
86 
87 SFX_IMPL_FLOATINGWINDOW( SvxContourDlgChildWindow, SID_CONTOUR_DLG );
88 
89 
90 /******************************************************************************/
91 
92 
93 /*************************************************************************
94 |*
95 |* ControllerItem
96 |*
97 \************************************************************************/
98 
99 SvxContourDlgItem::SvxContourDlgItem( sal_uInt16 _nId, SvxSuperContourDlg& rContourDlg, SfxBindings& rBindings ) :
100             SfxControllerItem   ( _nId, rBindings ),
101             rDlg                ( rContourDlg )
102 {
103 }
104 
105 
106 /*************************************************************************
107 |*
108 |*
109 |*
110 \************************************************************************/
111 
112 void SvxContourDlgItem::StateChanged( sal_uInt16 nSID, SfxItemState /*eState*/, const SfxPoolItem* pItem )
113 {
114     if ( pItem && ( SID_CONTOUR_EXEC == nSID ) )
115     {
116         const SfxBoolItem* pStateItem = PTR_CAST( SfxBoolItem, pItem );
117 
118         DBG_ASSERT( pStateItem || pItem == 0, "SfxBoolItem erwartet");
119 
120         rDlg.SetExecState( !pStateItem->GetValue() );
121     }
122 }
123 
124 
125 /******************************************************************************/
126 
127 
128 /*************************************************************************
129 |*
130 |* Contour-Float
131 |*
132 \************************************************************************/
133 
134 SvxContourDlgChildWindow::SvxContourDlgChildWindow( Window* _pParent, sal_uInt16 nId,
135                                                     SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
136             SfxChildWindow( _pParent, nId )
137 {
138     SvxSuperContourDlg* pDlg = new SvxSuperContourDlg( pBindings, this, _pParent, CONT_RESID( RID_SVXDLG_CONTOUR ) );
139     pWindow = pDlg;
140 
141     if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
142         pDlg->RollUp();
143 
144     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
145 
146     pDlg->Initialize( pInfo );
147 }
148 
149 /*************************************************************************
150 |*
151 |*
152 |*
153 \************************************************************************/
154 
155 void SvxContourDlgChildWindow::UpdateContourDlg( const Graphic& rGraphic, sal_Bool bGraphicLinked,
156                                                  const PolyPolygon* pPolyPoly, void* pEditingObj )
157 {
158     if ( SfxViewFrame::Current() &&
159          SfxViewFrame::Current()->HasChildWindow( SvxContourDlgChildWindow::GetChildWindowId() ) )
160         SVXCONTOURDLG()->Update( rGraphic, bGraphicLinked, pPolyPoly, pEditingObj );
161 }
162 
163 /*************************************************************************
164 |*
165 |*
166 |*
167 \************************************************************************/
168 
169 SvxContourDlg::SvxContourDlg( SfxBindings* _pBindings, SfxChildWindow* pCW,
170                               Window* _pParent, const ResId& rResId ) :
171 
172     SfxFloatingWindow   ( _pBindings, pCW, _pParent, rResId )
173 
174 {
175 }
176 
177 /*************************************************************************
178 |*
179 |*
180 |*
181 \************************************************************************/
182 
183 SvxContourDlg::~SvxContourDlg()
184 {
185 }
186 
187 /*************************************************************************
188 |*
189 |*
190 |*
191 \************************************************************************/
192 
193 PolyPolygon SvxContourDlg::CreateAutoContour( const Graphic& rGraphic,
194                                               const Rectangle* pRect,
195                                               const sal_uIntPtr nFlags )
196 {
197     Bitmap  aBmp;
198     sal_uIntPtr nContourFlags = XOUTBMP_CONTOUR_HORZ;
199 
200     if ( rGraphic.GetType() == GRAPHIC_BITMAP )
201     {
202         if( rGraphic.IsAnimated() )
203         {
204             VirtualDevice       aVDev;
205             MapMode             aTransMap;
206             PolyPolygon         aAnimPolyPoly;
207             const Animation     aAnim( rGraphic.GetAnimation() );
208             const Size&         rSizePix = aAnim.GetDisplaySizePixel();
209             const sal_uInt16        nCount = aAnim.Count();
210 
211             if ( aVDev.SetOutputSizePixel( rSizePix ) )
212             {
213                 aVDev.SetLineColor( Color( COL_BLACK ) );
214                 aVDev.SetFillColor( Color( COL_BLACK ) );
215 
216                 for( sal_uInt16 i = 0; i < nCount; i++ )
217                 {
218                     const AnimationBitmap& rStepBmp = aAnim.Get( i );
219 
220                     // Polygonausgabe an die richtige Stelle schieben;
221                     // dies ist der Offset des Teilbildes innerhalb
222                     // der Gesamtanimation
223                     aTransMap.SetOrigin( Point( rStepBmp.aPosPix.X(), rStepBmp.aPosPix.Y() ) );
224                     aVDev.SetMapMode( aTransMap );
225                     aVDev.DrawPolyPolygon( CreateAutoContour( rStepBmp.aBmpEx, pRect, nFlags ) );
226                 }
227 
228                 aTransMap.SetOrigin( Point() );
229                 aVDev.SetMapMode( aTransMap );
230                 aBmp = aVDev.GetBitmap( Point(), rSizePix );
231                 aBmp.Convert( BMP_CONVERSION_1BIT_THRESHOLD );
232             }
233         }
234         else if( rGraphic.IsTransparent() )
235             aBmp = rGraphic.GetBitmapEx().GetMask();
236         else
237         {
238             aBmp = rGraphic.GetBitmap();
239             nContourFlags |= XOUTBMP_CONTOUR_EDGEDETECT;
240         }
241     }
242     else if( rGraphic.GetType() != GRAPHIC_NONE )
243     {
244         const Graphic   aTmpGrf( rGraphic.GetGDIMetaFile().GetMonochromeMtf( Color( COL_BLACK ) ) );
245         VirtualDevice   aVDev;
246         Size            aSizePix( aVDev.LogicToPixel( aTmpGrf.GetPrefSize(), aTmpGrf.GetPrefMapMode() ) );
247 
248         if( aSizePix.Width() && aSizePix.Height() && ( aSizePix.Width() > 512 || aSizePix.Height() > 512 ) )
249         {
250             double fWH = (double) aSizePix.Width() / aSizePix.Height();
251 
252             if( fWH <= 1.0 )
253                 aSizePix.Width() = FRound( ( aSizePix.Height() = 512 ) * fWH );
254             else
255                 aSizePix.Height() = FRound( ( aSizePix.Width() = 512 ) / fWH );
256         }
257 
258         if( aVDev.SetOutputSizePixel( aSizePix ) )
259         {
260             const Point aPt;
261             aTmpGrf.Draw( &aVDev, aPt, aSizePix );
262             aBmp = aVDev.GetBitmap( aPt, aSizePix );
263         }
264 
265         nContourFlags |= XOUTBMP_CONTOUR_EDGEDETECT;
266     }
267 
268     aBmp.SetPrefSize( rGraphic.GetPrefSize() );
269     aBmp.SetPrefMapMode( rGraphic.GetPrefMapMode() );
270 
271     return PolyPolygon( XOutBitmap::GetCountour( aBmp, nContourFlags, 128, pRect ) );
272 }
273 
274 
275 /*************************************************************************
276 |*
277 |*
278 |*
279 \************************************************************************/
280 
281 void SvxContourDlg::ScaleContour( PolyPolygon& rContour, const Graphic& rGraphic,
282                                   const MapUnit eUnit, const Size& rDisplaySize )
283 {
284     DBG_ASSERT( rGraphic.GetType() != GRAPHIC_NONE, "Graphic is not valid!" );
285 
286     OutputDevice*   pOutDev = Application::GetDefaultDevice();
287     const MapMode   aDispMap( eUnit );
288     const MapMode   aGrfMap( rGraphic.GetPrefMapMode() );
289     const Size      aGrfSize( rGraphic.GetPrefSize() );
290     double          fScaleX;
291     double          fScaleY;
292     Size            aOrgSize;
293     Point           aNewPoint;
294     sal_Bool            bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
295 
296     if ( bPixelMap )
297         aOrgSize = pOutDev->PixelToLogic( aGrfSize, aDispMap );
298     else
299         aOrgSize = pOutDev->LogicToLogic( aGrfSize, aGrfMap, aDispMap );
300 
301     if ( aOrgSize.Width() && aOrgSize.Height() )
302     {
303         fScaleX = (double) rDisplaySize.Width() / aOrgSize.Width();
304         fScaleY = (double) rDisplaySize.Height() / aOrgSize.Height();
305 
306         for ( sal_uInt16 j = 0, nPolyCount = rContour.Count(); j < nPolyCount; j++ )
307         {
308             Polygon& rPoly = rContour[ j ];
309 
310             for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
311             {
312                 if ( bPixelMap )
313                     aNewPoint = pOutDev->PixelToLogic( rPoly[ i ], aDispMap  );
314                 else
315                     aNewPoint = pOutDev->LogicToLogic( rPoly[ i ], aGrfMap, aDispMap  );
316 
317                 rPoly[ i ] = Point( FRound( aNewPoint.X() * fScaleX ), FRound( aNewPoint.Y() * fScaleY ) );
318             }
319         }
320     }
321 }
322 
323 
324 /*************************************************************************
325 |*
326 |* Durchschleifen an SuperClass; keine virt. Methoden, um
327 |* bei IF-Aenderungen nicht inkompatibel zu werden
328 |*
329 \************************************************************************/
330 
331 void SvxContourDlg::SetExecState( sal_Bool bEnable )
332 {
333     pSuperClass->SetExecState( bEnable );
334 }
335 
336 void SvxContourDlg::SetGraphic( const Graphic& rGraphic )
337 {
338     pSuperClass->SetGraphic( rGraphic );
339 }
340 
341 void SvxContourDlg::SetGraphicLinked( sal_Bool bGraphicLinked )
342 {
343     pSuperClass->SetGraphicLinked( bGraphicLinked );
344 }
345 
346 const Graphic& SvxContourDlg::GetGraphic() const
347 {
348     return pSuperClass->GetGraphic();
349 }
350 
351 sal_Bool SvxContourDlg::IsGraphicChanged() const
352 {
353     return pSuperClass->IsGraphicChanged();
354 }
355 
356 void SvxContourDlg::SetPolyPolygon( const PolyPolygon& rPolyPoly )
357 {
358     pSuperClass->SetPolyPolygon( rPolyPoly );
359 }
360 
361 PolyPolygon SvxContourDlg::GetPolyPolygon()
362 {
363     return pSuperClass->GetPolyPolygon( sal_True );
364 }
365 
366 void SvxContourDlg::SetEditingObject( void* pObj )
367 {
368     pSuperClass->SetEditingObject( pObj );
369 }
370 
371 const void* SvxContourDlg::GetEditingObject() const
372 {
373     return pSuperClass->GetEditingObject();
374 }
375 
376 void SvxContourDlg::Update( const Graphic& rGraphic, sal_Bool bGraphicLinked,
377                             const PolyPolygon* pPolyPoly, void* pEditingObj )
378 {
379     pSuperClass->UpdateGraphic( rGraphic, bGraphicLinked, pPolyPoly, pEditingObj );
380 }
381 
382 
383 /*************************************************************************
384 |*
385 |*
386 |*
387 \************************************************************************/
388 
389 SvxSuperContourDlg::SvxSuperContourDlg( SfxBindings *_pBindings, SfxChildWindow *pCW,
390                                         Window* _pParent, const ResId& rResId ) :
391         SvxContourDlg       ( _pBindings, pCW, _pParent, rResId ),
392         pCheckObj           ( NULL ),
393         aContourItem        ( SID_CONTOUR_EXEC, *this, *_pBindings ),
394         aTbx1               ( this, ResId( TBX1, *rResId.GetResMgr() ) ),
395         aMtfTolerance       ( this, ResId( MTF_TOLERANCE, *rResId.GetResMgr() ) ),
396         aContourWnd         ( this, ResId( CTL_CONTOUR, *rResId.GetResMgr() ) ),
397         aStbStatus          ( this, WB_BORDER | WB_3DLOOK | WB_LEFT ),
398         nGrfChanged         ( 0UL ),
399         bExecState          ( sal_False ),
400         bGraphicLinked      ( sal_False ),
401         maImageList         ( SVX_RES( CD_IMAPDLG ) ),
402         maImageListH        ( SVX_RES( CDH_IMAPDLG ) )
403 {
404     ApplyImageList();
405 
406     FreeResource();
407 
408     SvxContourDlg::SetSuperClass( *this );
409 
410     aContourWnd.SetMousePosLink( LINK( this, SvxSuperContourDlg, MousePosHdl ) );
411     aContourWnd.SetGraphSizeLink( LINK( this, SvxSuperContourDlg, GraphSizeHdl ) );
412     aContourWnd.SetUpdateLink( LINK( this, SvxSuperContourDlg, StateHdl ) );
413     aContourWnd.SetPipetteHdl( LINK( this, SvxSuperContourDlg, PipetteHdl ) );
414     aContourWnd.SetPipetteClickHdl( LINK( this, SvxSuperContourDlg, PipetteClickHdl ) );
415     aContourWnd.SetWorkplaceClickHdl( LINK( this, SvxSuperContourDlg, WorkplaceClickHdl ) );
416 
417     const Size      aTbxSize( aTbx1.CalcWindowSizePixel() );
418     Point           aPos( aTbx1.GetPosPixel() );
419     SvtMiscOptions  aMiscOptions;
420 
421     aMiscOptions.AddListenerLink( LINK( this, SvxSuperContourDlg, MiscHdl ) );
422 
423     aTbx1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
424     aTbx1.SetSizePixel( aTbxSize );
425     aTbx1.SetSelectHdl( LINK( this, SvxSuperContourDlg, Tbx1ClickHdl ) );
426 
427     aPos.X() += aTbxSize.Width() + LogicToPixel( Size( 3, 0 ), MapMode( MAP_APPFONT ) ).Width();
428     aMtfTolerance.SetPosPixel( aPos );
429     aMtfTolerance.SetValue( 10L );
430 
431     SetMinOutputSizePixel( aLastSize = GetOutputSizePixel() );
432 
433     aStbStatus.InsertItem( 1, 130, SIB_LEFT | SIB_IN | SIB_AUTOSIZE );
434     aStbStatus.InsertItem( 2, 10 + GetTextWidth( String::CreateFromAscii( " 9999,99 cm / 9999,99 cm " ) ), SIB_CENTER | SIB_IN );
435     aStbStatus.InsertItem( 3, 10 + GetTextWidth( String::CreateFromAscii( " 9999,99 cm x 9999,99 cm " ) ), SIB_CENTER | SIB_IN );
436     aStbStatus.InsertItem( 4, 20, SIB_CENTER | SIB_IN );
437 
438     Resize();
439 
440     aUpdateTimer.SetTimeout( 100 );
441     aUpdateTimer.SetTimeoutHdl( LINK( this, SvxSuperContourDlg, UpdateHdl ) );
442 
443     aCreateTimer.SetTimeout( 50 );
444     aCreateTimer.SetTimeoutHdl( LINK( this, SvxSuperContourDlg, CreateHdl ) );
445 }
446 
447 
448 /*************************************************************************
449 |*
450 |* Dtor
451 |*
452 \************************************************************************/
453 
454 SvxSuperContourDlg::~SvxSuperContourDlg()
455 {
456 }
457 
458 
459 /*************************************************************************
460 |*
461 |* Resize-Methode
462 |*
463 \************************************************************************/
464 
465 void SvxSuperContourDlg::Resize()
466 {
467     SfxFloatingWindow::Resize();
468 
469     Size aMinSize( GetMinOutputSizePixel() );
470     Size aNewSize( GetOutputSizePixel() );
471 
472     if ( aNewSize.Height() >= aMinSize.Height() )
473     {
474         Size    _aSize( aStbStatus.GetSizePixel() );
475         Point   aPoint( 0, aNewSize.Height() - _aSize.Height() );
476 
477         // StatusBar positionieren
478         aStbStatus.SetPosSizePixel( aPoint, Size( aNewSize.Width(), _aSize.Height() ) );
479         aStbStatus.Show();
480 
481         // EditWindow positionieren
482         _aSize.Width() = aNewSize.Width() - 18;
483         _aSize.Height() = aPoint.Y() - aContourWnd.GetPosPixel().Y() - 6;
484         aContourWnd.SetSizePixel( _aSize );
485 
486         aLastSize = aNewSize;
487     }
488 }
489 
490 
491 /*************************************************************************
492 |*
493 |* Close-Methode
494 |*
495 \************************************************************************/
496 
497 sal_Bool SvxSuperContourDlg::Close()
498 {
499     sal_Bool bRet = sal_True;
500 
501     if ( aTbx1.IsItemEnabled( TBI_APPLY ) )
502     {
503         QueryBox    aQBox( this, WB_YES_NO_CANCEL | WB_DEF_YES,
504                            String( CONT_RESID( STR_CONTOURDLG_MODIFY ) ) );
505         const long  nRet = aQBox.Execute();
506 
507         if ( nRet == RET_YES )
508         {
509             SfxBoolItem aBoolItem( SID_CONTOUR_EXEC, sal_True );
510             GetBindings().GetDispatcher()->Execute(
511                 SID_CONTOUR_EXEC, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
512         }
513         else if ( nRet == RET_CANCEL )
514             bRet = sal_False;
515     }
516 
517     return( bRet ? SfxFloatingWindow::Close() : sal_False );
518 }
519 
520 
521 /*************************************************************************
522 |*
523 |* Enabled oder disabled alle Controls
524 |*
525 \************************************************************************/
526 
527 void SvxSuperContourDlg::SetExecState( sal_Bool bEnable )
528 {
529     bExecState = bEnable;
530 }
531 
532 
533 /*************************************************************************
534 |*
535 |*
536 |*
537 \************************************************************************/
538 
539 void SvxSuperContourDlg::SetGraphic( const Graphic& rGraphic )
540 {
541     aUndoGraphic = aRedoGraphic = Graphic();
542     aGraphic = rGraphic;
543     nGrfChanged = 0UL;
544     aContourWnd.SetGraphic( aGraphic );
545 }
546 
547 
548 /*************************************************************************
549 |*
550 |*
551 |*
552 \************************************************************************/
553 
554 void SvxSuperContourDlg::SetPolyPolygon( const PolyPolygon& rPolyPoly )
555 {
556     DBG_ASSERT(  aContourWnd.GetGraphic().GetType() != GRAPHIC_NONE, "Graphic must've been set first!" );
557 
558     PolyPolygon     aPolyPoly( rPolyPoly );
559     const MapMode   aMap100( MAP_100TH_MM );
560     const MapMode   aGrfMap( aGraphic.GetPrefMapMode() );
561     OutputDevice*   pOutDev = Application::GetDefaultDevice();
562     sal_Bool            bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
563 
564     for ( sal_uInt16 j = 0, nPolyCount = aPolyPoly.Count(); j < nPolyCount; j++ )
565     {
566         Polygon& rPoly = aPolyPoly[ j ];
567 
568         for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
569         {
570             Point& rPt = rPoly[ i ];
571 
572             if ( !bPixelMap )
573                 rPt = pOutDev->LogicToPixel( rPt, aGrfMap );
574 
575             rPt = pOutDev->PixelToLogic( rPt, aMap100 );
576         }
577     }
578 
579     aContourWnd.SetPolyPolygon( aPolyPoly );
580     aContourWnd.GetSdrModel()->SetChanged( sal_True );
581 }
582 
583 
584 /*************************************************************************
585 |*
586 |*
587 |*
588 \************************************************************************/
589 
590 PolyPolygon SvxSuperContourDlg::GetPolyPolygon( sal_Bool bRescaleToGraphic )
591 {
592     PolyPolygon aRetPolyPoly( aContourWnd.GetPolyPolygon() );
593 
594     if ( bRescaleToGraphic )
595     {
596         const MapMode   aMap100( MAP_100TH_MM );
597         const MapMode   aGrfMap( aGraphic.GetPrefMapMode() );
598         OutputDevice*   pOutDev = Application::GetDefaultDevice();
599         sal_Bool            bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
600 
601         for ( sal_uInt16 j = 0, nPolyCount = aRetPolyPoly.Count(); j < nPolyCount; j++ )
602         {
603             Polygon& rPoly = aRetPolyPoly[ j ];
604 
605             for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
606             {
607                 Point& rPt = rPoly[ i ];
608 
609                 rPt = pOutDev->LogicToPixel( rPt, aMap100  );
610 
611                 if ( !bPixelMap )
612                     rPt = pOutDev->PixelToLogic( rPt, aGrfMap  );
613             }
614         }
615     }
616 
617     return aRetPolyPoly;
618 }
619 
620 
621 /*************************************************************************
622 |*
623 |*
624 |*
625 \************************************************************************/
626 
627 void SvxSuperContourDlg::UpdateGraphic( const Graphic& rGraphic, sal_Bool _bGraphicLinked,
628                                  const PolyPolygon* pPolyPoly, void* pEditingObj )
629 {
630     aUpdateGraphic = rGraphic;
631     bUpdateGraphicLinked = _bGraphicLinked;
632     pUpdateEditingObject = pEditingObj;
633 
634     if ( pPolyPoly )
635         aUpdatePolyPoly = *pPolyPoly;
636     else
637         aUpdatePolyPoly = PolyPolygon();
638 
639     aUpdateTimer.Start();
640 }
641 
642 
643 /*************************************************************************
644 |*
645 |*
646 |*
647 \************************************************************************/
648 
649 sal_Bool SvxSuperContourDlg::IsUndoPossible() const
650 {
651     return aUndoGraphic.GetType() != GRAPHIC_NONE;
652 }
653 
654 
655 /*************************************************************************
656 |*
657 |*
658 |*
659 \************************************************************************/
660 
661 sal_Bool SvxSuperContourDlg::IsRedoPossible() const
662 {
663     return aRedoGraphic.GetType() != GRAPHIC_NONE;
664 }
665 
666 
667 /*************************************************************************
668 |*
669 |*
670 |*
671 \************************************************************************/
672 
673 void SvxSuperContourDlg::DoAutoCreate()
674 {
675     aCreateTimer.Start();
676 }
677 
678 
679 /*************************************************************************
680 |*
681 |*
682 |*
683 \************************************************************************/
684 
685 void SvxSuperContourDlg::ReducePoints( const long nTol )
686 {
687     PolyPolygon aPolyPoly( GetPolyPolygon( sal_False ) );
688 
689     if ( aPolyPoly.Count() )
690     {
691         const MapMode   aMapMode( MAP_100TH_MM );
692         const long      nTol2 = nTol * nTol;
693         Polygon&        rPoly = aPolyPoly[ 0 ];
694         OutputDevice*   pOutDev = Application::GetDefaultDevice();
695         Point           aPtPix;
696         const sal_uInt16    nSize = rPoly.GetSize();
697         sal_uInt16          nCounter = 0;
698 
699         if ( nSize )
700             aPtPix = pOutDev->LogicToPixel( rPoly[ 0 ], aMapMode );
701 
702         for( sal_uInt16 i = 1; i < nSize; i++ )
703         {
704             const Point&    rNewPt = rPoly[ i ];
705             const Point     aNewPtPix( pOutDev->LogicToPixel( rNewPt, aMapMode ) );
706 
707             const long nDistX = aNewPtPix.X() - aPtPix.X();
708             const long nDistY = aNewPtPix.Y() - aPtPix.Y();
709 
710             if( ( nDistX * nDistX + nDistY * nDistY ) >= nTol2 )
711             {
712                 rPoly[ ++nCounter ] = rNewPt;
713                 aPtPix = aNewPtPix;
714             }
715         }
716 
717         rPoly.SetSize( nCounter );
718         aContourWnd.SetPolyPolygon( aPolyPoly );
719         aContourWnd.GetSdrModel()->SetChanged( sal_True );
720     }
721 }
722 
723 
724 /*************************************************************************
725 |*
726 |* Click-Hdl fuer ToolBox
727 |*
728 \************************************************************************/
729 
730 IMPL_LINK( SvxSuperContourDlg, Tbx1ClickHdl, ToolBox*, pTbx )
731 {
732     sal_uInt16 nNewItemId = pTbx->GetCurItemId();
733 
734     switch( pTbx->GetCurItemId() )
735     {
736         case( TBI_APPLY ):
737         {
738             SfxBoolItem aBoolItem( SID_CONTOUR_EXEC, sal_True );
739             GetBindings().GetDispatcher()->Execute(
740                 SID_CONTOUR_EXEC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
741         }
742         break;
743 
744         case( TBI_WORKPLACE ):
745         {
746             if ( aTbx1.IsItemChecked( TBI_WORKPLACE ) )
747             {
748                 QueryBox aQBox( this, WB_YES_NO | WB_DEF_NO, String( CONT_RESID( STR_CONTOURDLG_WORKPLACE ) ) );
749 
750                 if ( !aContourWnd.IsContourChanged() || ( aQBox.Execute() == RET_YES ) )
751                     aContourWnd.SetWorkplaceMode( sal_True );
752                 else
753                     aTbx1.CheckItem( TBI_WORKPLACE, sal_False );
754             }
755             else
756                 aContourWnd.SetWorkplaceMode( sal_False );
757         }
758         break;
759 
760         case( TBI_SELECT ):
761         {
762             pTbx->CheckItem( nNewItemId, sal_True );
763             aContourWnd.SetEditMode( sal_True );
764         }
765         break;
766 
767         case( TBI_RECT ):
768         {
769             pTbx->CheckItem( nNewItemId, sal_True );
770             aContourWnd.SetObjKind( OBJ_RECT );
771         }
772         break;
773 
774         case( TBI_CIRCLE ):
775         {
776             pTbx->CheckItem( nNewItemId, sal_True );
777             aContourWnd.SetObjKind( OBJ_CIRC );
778 
779         }
780         break;
781 
782         case( TBI_POLY ):
783         {
784             pTbx->CheckItem( nNewItemId, sal_True );
785             aContourWnd.SetObjKind( OBJ_POLY );
786         }
787         break;
788 
789         case( TBI_FREEPOLY ):
790         {
791             pTbx->CheckItem( nNewItemId, sal_True );
792             aContourWnd.SetObjKind( OBJ_FREEFILL );
793         }
794         break;
795 
796         case( TBI_POLYEDIT ):
797             aContourWnd.SetPolyEditMode( pTbx->IsItemChecked( TBI_POLYEDIT ) ? SID_BEZIER_MOVE : 0 );
798         break;
799 
800         case( TBI_POLYMOVE ):
801             aContourWnd.SetPolyEditMode( SID_BEZIER_MOVE );
802         break;
803 
804         case( TBI_POLYINSERT ):
805             aContourWnd.SetPolyEditMode( SID_BEZIER_INSERT );
806         break;
807 
808         case( TBI_POLYDELETE ):
809             aContourWnd.GetSdrView()->DeleteMarkedPoints();
810         break;
811 
812         case( TBI_UNDO ):
813         {
814             nGrfChanged = nGrfChanged ? nGrfChanged-- : 0UL;
815             aRedoGraphic = aGraphic;
816             aGraphic = aUndoGraphic;
817             aUndoGraphic = Graphic();
818             aContourWnd.SetGraphic( aGraphic, sal_False );
819         }
820         break;
821 
822         case( TBI_REDO ):
823         {
824             nGrfChanged++;
825             aUndoGraphic = aGraphic;
826             aGraphic = aRedoGraphic;
827             aRedoGraphic = Graphic();
828             aContourWnd.SetGraphic( aGraphic, sal_False );
829         }
830         break;
831 
832         case( TBI_AUTOCONTOUR ):
833             aCreateTimer.Start();
834         break;
835 
836         case( TBI_PIPETTE ):
837         {
838             sal_Bool bPipette = aTbx1.IsItemChecked( TBI_PIPETTE );
839 
840             if ( !bPipette )
841                 aStbStatus.Invalidate();
842             else if ( bGraphicLinked )
843             {
844                 QueryBox aQBox( this, WB_YES_NO | WB_DEF_YES, String( CONT_RESID( STR_CONTOURDLG_LINKED ) ) );
845 
846                 if ( aQBox.Execute() != RET_YES )
847                 {
848                     aTbx1.CheckItem( TBI_PIPETTE, bPipette = sal_False );
849                     aStbStatus.Invalidate();
850                 }
851             }
852 
853             aContourWnd.SetPipetteMode( bPipette );
854         }
855         break;
856 
857         default:
858         break;
859     }
860 
861     return 0L;
862 }
863 
864 
865 /*************************************************************************
866 |*
867 |*
868 |*
869 \************************************************************************/
870 
871 IMPL_LINK( SvxSuperContourDlg, MousePosHdl, ContourWindow*, pWnd )
872 {
873     String aStr;
874     const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
875     const Point& rMousePos = pWnd->GetMousePos();
876     LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
877     const sal_Unicode cSep = aLocaleWrapper.getNumDecimalSep().GetChar(0);
878 
879     aStr.Assign( GetUnitString( rMousePos.X(), eFieldUnit, cSep ) );
880     aStr.Append( String::CreateFromAscii( " / " ) );
881     aStr.Append( GetUnitString( rMousePos.Y(), eFieldUnit, cSep ) );
882 
883     aStbStatus.SetItemText( 2, aStr );
884 
885     return 0L;
886 }
887 
888 /*************************************************************************
889 |*
890 |*
891 |*
892 \************************************************************************/
893 
894 IMPL_LINK( SvxSuperContourDlg, GraphSizeHdl, ContourWindow*, pWnd )
895 {
896     String aStr;
897     const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
898     const Size& rSize = pWnd->GetGraphicSize();
899     LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
900     const sal_Unicode cSep = aLocaleWrapper.getNumDecimalSep().GetChar(0);
901 
902     aStr.Assign( GetUnitString( rSize.Width(), eFieldUnit, cSep ) );
903     aStr.Append( String::CreateFromAscii( " x " ) );
904     aStr.Append( GetUnitString( rSize.Height(), eFieldUnit, cSep ) );
905 
906     aStbStatus.SetItemText( 3, aStr );
907 
908     return 0L;
909 }
910 
911 /*************************************************************************
912 |*
913 |*
914 |*
915 \************************************************************************/
916 
917 IMPL_LINK( SvxSuperContourDlg, UpdateHdl, Timer*, EMPTYARG )
918 {
919     aUpdateTimer.Stop();
920 
921     if ( pUpdateEditingObject != pCheckObj )
922     {
923         if( !GetEditingObject() )
924             aContourWnd.GrabFocus();
925 
926         SetGraphic( aUpdateGraphic );
927         SetPolyPolygon( aUpdatePolyPoly );
928         SetEditingObject( pUpdateEditingObject );
929         bGraphicLinked = bUpdateGraphicLinked;
930 
931         aUpdateGraphic = Graphic();
932         aUpdatePolyPoly = PolyPolygon();
933         bUpdateGraphicLinked = sal_False;
934 
935         aContourWnd.GetSdrModel()->SetChanged( sal_False );
936     }
937 
938     GetBindings().Invalidate( SID_CONTOUR_EXEC );
939 
940     return 0L;
941 }
942 
943 
944 /*************************************************************************
945 |*
946 |*
947 |*
948 \************************************************************************/
949 
950 IMPL_LINK( SvxSuperContourDlg, CreateHdl, Timer*, EMPTYARG )
951 {
952     aCreateTimer.Stop();
953 
954     const Rectangle aWorkRect = aContourWnd.LogicToPixel( aContourWnd.GetWorkRect(), MapMode( MAP_100TH_MM ) );
955     const Graphic&  rGraphic = aContourWnd.GetGraphic();
956     const sal_Bool      bValid = aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom();
957 
958     EnterWait();
959     SetPolyPolygon( CreateAutoContour( rGraphic, bValid ? &aWorkRect : NULL ) );
960     LeaveWait();
961 
962     return 0L;
963 }
964 
965 
966 /*************************************************************************
967 |*
968 |*
969 |*
970 \************************************************************************/
971 
972 IMPL_LINK( SvxSuperContourDlg, StateHdl, ContourWindow*, pWnd )
973 {
974     const SdrObject*    pObj = pWnd->GetSelectedSdrObject();
975     const SdrView*      pView = pWnd->GetSdrView();
976     const sal_Bool          bPolyEdit = ( pObj != NULL ) && pObj->ISA( SdrPathObj );
977     const sal_Bool          bDrawEnabled = !( bPolyEdit && aTbx1.IsItemChecked( TBI_POLYEDIT ) );
978     const sal_Bool          bPipette = aTbx1.IsItemChecked( TBI_PIPETTE );
979     const sal_Bool          bWorkplace = aTbx1.IsItemChecked( TBI_WORKPLACE );
980     const sal_Bool          bDontHide = !( bPipette || bWorkplace );
981     const sal_Bool          bBitmap = pWnd->GetGraphic().GetType() == GRAPHIC_BITMAP;
982 
983     aTbx1.EnableItem( TBI_APPLY, bDontHide && bExecState && pWnd->IsChanged() );
984 
985     aTbx1.EnableItem( TBI_WORKPLACE, !bPipette && bDrawEnabled );
986 
987     aTbx1.EnableItem( TBI_SELECT, bDontHide && bDrawEnabled );
988     aTbx1.EnableItem( TBI_RECT, bDontHide && bDrawEnabled );
989     aTbx1.EnableItem( TBI_CIRCLE, bDontHide && bDrawEnabled );
990     aTbx1.EnableItem( TBI_POLY, bDontHide && bDrawEnabled );
991     aTbx1.EnableItem( TBI_FREEPOLY, bDontHide && bDrawEnabled );
992 
993     aTbx1.EnableItem( TBI_POLYEDIT, bDontHide && bPolyEdit );
994     aTbx1.EnableItem( TBI_POLYMOVE, bDontHide && !bDrawEnabled );
995     aTbx1.EnableItem( TBI_POLYINSERT, bDontHide && !bDrawEnabled );
996     aTbx1.EnableItem( TBI_POLYDELETE, bDontHide && !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() );
997 
998     aTbx1.EnableItem( TBI_AUTOCONTOUR, bDontHide && bDrawEnabled );
999     aTbx1.EnableItem( TBI_PIPETTE, !bWorkplace && bDrawEnabled && bBitmap );
1000 
1001     aTbx1.EnableItem( TBI_UNDO, bDontHide && IsUndoPossible() );
1002     aTbx1.EnableItem( TBI_REDO, bDontHide && IsRedoPossible() );
1003 
1004     if ( bPolyEdit )
1005     {
1006         sal_uInt16 nId = 0;
1007 
1008         switch( pWnd->GetPolyEditMode() )
1009         {
1010             case( SID_BEZIER_MOVE ): nId = TBI_POLYMOVE; break;
1011             case( SID_BEZIER_INSERT ): nId = TBI_POLYINSERT; break;
1012 
1013             default:
1014             break;
1015         }
1016 
1017         aTbx1.CheckItem( nId, sal_True );
1018     }
1019     else
1020     {
1021         aTbx1.CheckItem( TBI_POLYEDIT, sal_False );
1022         aTbx1.CheckItem( TBI_POLYMOVE, sal_True );
1023         aTbx1.CheckItem( TBI_POLYINSERT, sal_False );
1024         pWnd->SetPolyEditMode( 0 );
1025     }
1026 
1027     return 0L;
1028 }
1029 
1030 
1031 /*************************************************************************
1032 |*
1033 |*
1034 |*
1035 \************************************************************************/
1036 
1037 IMPL_LINK( SvxSuperContourDlg, PipetteHdl, ContourWindow*, pWnd )
1038 {
1039     const Color& rOldLineColor = aStbStatus.GetLineColor();
1040     const Color& rOldFillColor = aStbStatus.GetFillColor();
1041 
1042     Rectangle       aRect( aStbStatus.GetItemRect( 4 ) );
1043     const Color&    rColor = pWnd->GetPipetteColor();
1044 
1045     aStbStatus.SetLineColor( rColor );
1046     aStbStatus.SetFillColor( rColor );
1047 
1048     aRect.Left() += 4;
1049     aRect.Top() += 4;
1050     aRect.Right() -= 4;
1051     aRect.Bottom() -= 4;
1052 
1053     aStbStatus.DrawRect( aRect );
1054 
1055     aStbStatus.SetLineColor( rOldLineColor );
1056     aStbStatus.SetFillColor( rOldFillColor );
1057 
1058     return 0L;
1059 }
1060 
1061 
1062 /*************************************************************************
1063 |*
1064 |*
1065 |*
1066 \************************************************************************/
1067 
1068 IMPL_LINK( SvxSuperContourDlg, PipetteClickHdl, ContourWindow*, pWnd )
1069 {
1070     if ( pWnd->IsClickValid() )
1071     {
1072         Bitmap          aMask;
1073         const Color&    rColor = pWnd->GetPipetteColor();
1074 
1075         EnterWait();
1076 
1077         if( aGraphic.GetType() == GRAPHIC_BITMAP )
1078         {
1079             Bitmap      aBmp( aGraphic.GetBitmap() );
1080             const long  nTol = static_cast<long>(aMtfTolerance.GetValue() * 255L / 100L);
1081 
1082             aMask = aBmp.CreateMask( rColor, nTol );
1083 
1084             if( aGraphic.IsTransparent() )
1085                 aMask.CombineSimple( aGraphic.GetBitmapEx().GetMask(), BMP_COMBINE_OR );
1086 
1087             if( !!aMask )
1088             {
1089                 QueryBox    aQBox( this, WB_YES_NO | WB_DEF_YES, String( CONT_RESID( STR_CONTOURDLG_NEWPIPETTE ) ) );
1090                 sal_Bool        bNewContour;
1091 
1092                 aRedoGraphic = Graphic();
1093                 aUndoGraphic = aGraphic;
1094                 aGraphic = Graphic( BitmapEx( aBmp, aMask ) );
1095                 nGrfChanged++;
1096 
1097                 bNewContour = ( aQBox.Execute() == RET_YES );
1098                 pWnd->SetGraphic( aGraphic, bNewContour );
1099 
1100                 if( bNewContour )
1101                     aCreateTimer.Start();
1102             }
1103         }
1104 
1105         LeaveWait();
1106     }
1107 
1108     aTbx1.CheckItem( TBI_PIPETTE, sal_False );
1109     pWnd->SetPipetteMode( sal_False );
1110     aStbStatus.Invalidate();
1111 
1112     return 0L;
1113 }
1114 
1115 
1116 /*************************************************************************
1117 |*
1118 |*
1119 |*
1120 \************************************************************************/
1121 
1122 IMPL_LINK( SvxSuperContourDlg, WorkplaceClickHdl, ContourWindow*, pWnd )
1123 {
1124     aTbx1.CheckItem( TBI_WORKPLACE, sal_False );
1125     aTbx1.CheckItem( TBI_SELECT, sal_True );
1126     pWnd->SetWorkplaceMode( sal_False );
1127 
1128     return 0L;
1129 }
1130 
1131 void SvxSuperContourDlg::ApplyImageList()
1132 {
1133     bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
1134 
1135     ImageList& rImgLst = bHighContrast ? maImageListH : maImageList;
1136 
1137     aTbx1.SetImageList( rImgLst );
1138 }
1139 
1140 void SvxSuperContourDlg::DataChanged( const DataChangedEvent& rDCEvt )
1141 {
1142     SfxFloatingWindow::DataChanged( rDCEvt );
1143 
1144     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1145             ApplyImageList();
1146 }
1147 
1148 /*************************************************************************
1149 |*
1150 |*
1151 |*
1152 \************************************************************************/
1153 
1154 IMPL_LINK( SvxSuperContourDlg, MiscHdl, void*, EMPTYARG )
1155 {
1156     SvtMiscOptions aMiscOptions;
1157     aTbx1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
1158 
1159     return 0L;
1160 }
1161 
1162