Update ooo320-m1
[ooovba.git] / svx / source / dialog / _contdlg.cxx
bloba81eba3cb1a63ef5e97b80abaaa16c7820238d7c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _contdlg.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <vcl/wrkwin.hxx>
34 #include <sot/factory.hxx>
35 #include <tools/shl.hxx>
36 #include <vcl/salbtype.hxx> // FRound
37 #include <vcl/msgbox.hxx>
38 #include <svtools/eitem.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <svtools/miscopt.hxx>
42 #include <unotools/localedatawrapper.hxx>
43 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
44 #include <comphelper/processfactory.hxx>
45 #endif
47 #define _SDR_NOITEMS
48 #define _SDR_NOTOUCH
49 #define _SDR_NOTRANSFORM
50 #define _SDR_NOOBJECTS
51 #define _SDR_NOVIEWMARKER
52 #define _SDR_NODRAGMETHODS
53 #define _SDR_NOUNDO
54 #define _SDR_NOXOUTDEV
55 #define _XOUTBMP_STATICS_ONLY
57 #include <svx/dialmgr.hxx>
58 #include "xoutbmp.hxx"
59 #include <svx/dialogs.hrc>
60 #include <svx/svxids.hrc>
61 #include <svx/contdlg.hxx>
62 #include "contimp.hxx"
63 #include "contdlg.hrc"
64 #include "contwnd.hxx"
65 #include <svx/svdtrans.hxx>
66 #include <svx/svdopath.hxx>
67 #include "dlgutil.hxx"
68 #include <vcl/svapp.hxx>
70 /******************************************************************************/
72 inline String GetUnitString( long nVal_100, FieldUnit eFieldUnit, sal_Unicode cSep )
74 String aVal = UniString::CreateFromInt64( MetricField::ConvertValue( nVal_100, 2, MAP_100TH_MM, eFieldUnit ) );
76 while( aVal.Len() < 3 )
77 aVal.Insert( sal_Unicode('0'), 0 );
79 aVal.Insert( cSep, aVal.Len() - 2 );
80 aVal += sal_Unicode(' ');
81 aVal += SdrFormatter::GetUnitStr( eFieldUnit );
83 return aVal;
87 /******************************************************************************/
90 SFX_IMPL_FLOATINGWINDOW( SvxContourDlgChildWindow, SID_CONTOUR_DLG );
93 /******************************************************************************/
96 /*************************************************************************
98 |* ControllerItem
100 \************************************************************************/
102 SvxContourDlgItem::SvxContourDlgItem( USHORT _nId, SvxSuperContourDlg& rContourDlg, SfxBindings& rBindings ) :
103 SfxControllerItem ( _nId, rBindings ),
104 rDlg ( rContourDlg )
109 /*************************************************************************
113 \************************************************************************/
115 void SvxContourDlgItem::StateChanged( USHORT nSID, SfxItemState /*eState*/, const SfxPoolItem* pItem )
117 if ( pItem && ( SID_CONTOUR_EXEC == nSID ) )
119 const SfxBoolItem* pStateItem = PTR_CAST( SfxBoolItem, pItem );
121 DBG_ASSERT( pStateItem || pItem == 0, "SfxBoolItem erwartet");
123 rDlg.SetExecState( !pStateItem->GetValue() );
128 /******************************************************************************/
131 /*************************************************************************
133 |* Contour-Float
135 \************************************************************************/
137 SvxContourDlgChildWindow::SvxContourDlgChildWindow( Window* _pParent, USHORT nId,
138 SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
139 SfxChildWindow( _pParent, nId )
141 SvxSuperContourDlg* pDlg = new SvxSuperContourDlg( pBindings, this, _pParent, CONT_RESID( RID_SVXDLG_CONTOUR ) );
142 pWindow = pDlg;
144 if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
145 pDlg->RollUp();
147 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
149 pDlg->Initialize( pInfo );
152 /*************************************************************************
156 \************************************************************************/
158 void SvxContourDlgChildWindow::UpdateContourDlg( const Graphic& rGraphic, BOOL bGraphicLinked,
159 const PolyPolygon* pPolyPoly, void* pEditingObj )
161 if ( SfxViewFrame::Current() &&
162 SfxViewFrame::Current()->HasChildWindow( SvxContourDlgChildWindow::GetChildWindowId() ) )
163 SVXCONTOURDLG()->Update( rGraphic, bGraphicLinked, pPolyPoly, pEditingObj );
166 /*************************************************************************
170 \************************************************************************/
172 SvxContourDlg::SvxContourDlg( SfxBindings* _pBindings, SfxChildWindow* pCW,
173 Window* _pParent, const ResId& rResId ) :
175 SfxFloatingWindow ( _pBindings, pCW, _pParent, rResId )
180 /*************************************************************************
184 \************************************************************************/
186 SvxContourDlg::~SvxContourDlg()
190 /*************************************************************************
194 \************************************************************************/
196 PolyPolygon SvxContourDlg::CreateAutoContour( const Graphic& rGraphic,
197 const Rectangle* pRect,
198 const ULONG nFlags )
200 Bitmap aBmp;
201 ULONG nContourFlags = XOUTBMP_CONTOUR_HORZ;
203 if ( rGraphic.GetType() == GRAPHIC_BITMAP )
205 if( rGraphic.IsAnimated() )
207 VirtualDevice aVDev;
208 MapMode aTransMap;
209 PolyPolygon aAnimPolyPoly;
210 const Animation aAnim( rGraphic.GetAnimation() );
211 const Size& rSizePix = aAnim.GetDisplaySizePixel();
212 const USHORT nCount = aAnim.Count();
214 if ( aVDev.SetOutputSizePixel( rSizePix ) )
216 aVDev.SetLineColor( Color( COL_BLACK ) );
217 aVDev.SetFillColor( Color( COL_BLACK ) );
219 for( USHORT i = 0; i < nCount; i++ )
221 const AnimationBitmap& rStepBmp = aAnim.Get( i );
223 // Polygonausgabe an die richtige Stelle schieben;
224 // dies ist der Offset des Teilbildes innerhalb
225 // der Gesamtanimation
226 aTransMap.SetOrigin( Point( rStepBmp.aPosPix.X(), rStepBmp.aPosPix.Y() ) );
227 aVDev.SetMapMode( aTransMap );
228 aVDev.DrawPolyPolygon( CreateAutoContour( rStepBmp.aBmpEx, pRect, nFlags ) );
231 aTransMap.SetOrigin( Point() );
232 aVDev.SetMapMode( aTransMap );
233 aBmp = aVDev.GetBitmap( Point(), rSizePix );
234 aBmp.Convert( BMP_CONVERSION_1BIT_THRESHOLD );
237 else if( rGraphic.IsTransparent() )
238 aBmp = rGraphic.GetBitmapEx().GetMask();
239 else
241 aBmp = rGraphic.GetBitmap();
242 nContourFlags |= XOUTBMP_CONTOUR_EDGEDETECT;
245 else if( rGraphic.GetType() != GRAPHIC_NONE )
247 const Graphic aTmpGrf( rGraphic.GetGDIMetaFile().GetMonochromeMtf( Color( COL_BLACK ) ) );
248 VirtualDevice aVDev;
249 Size aSizePix( aVDev.LogicToPixel( aTmpGrf.GetPrefSize(), aTmpGrf.GetPrefMapMode() ) );
251 if( aSizePix.Width() && aSizePix.Height() && ( aSizePix.Width() > 512 || aSizePix.Height() > 512 ) )
253 double fWH = (double) aSizePix.Width() / aSizePix.Height();
255 if( fWH <= 1.0 )
256 aSizePix.Width() = FRound( ( aSizePix.Height() = 512 ) * fWH );
257 else
258 aSizePix.Height() = FRound( ( aSizePix.Width() = 512 ) / fWH );
261 if( aVDev.SetOutputSizePixel( aSizePix ) )
263 const Point aPt;
264 aTmpGrf.Draw( &aVDev, aPt, aSizePix );
265 aBmp = aVDev.GetBitmap( aPt, aSizePix );
268 nContourFlags |= XOUTBMP_CONTOUR_EDGEDETECT;
271 aBmp.SetPrefSize( rGraphic.GetPrefSize() );
272 aBmp.SetPrefMapMode( rGraphic.GetPrefMapMode() );
274 return PolyPolygon( XOutBitmap::GetCountour( aBmp, nContourFlags, 128, pRect ) );
278 /*************************************************************************
282 \************************************************************************/
284 void SvxContourDlg::ScaleContour( PolyPolygon& rContour, const Graphic& rGraphic,
285 const MapUnit eUnit, const Size& rDisplaySize )
287 DBG_ASSERT( rGraphic.GetType() != GRAPHIC_NONE, "Graphic is not valid!" );
289 OutputDevice* pOutDev = Application::GetDefaultDevice();
290 const MapMode aDispMap( eUnit );
291 const MapMode aGrfMap( rGraphic.GetPrefMapMode() );
292 const Size aGrfSize( rGraphic.GetPrefSize() );
293 double fScaleX;
294 double fScaleY;
295 Size aOrgSize;
296 Point aNewPoint;
297 BOOL bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
299 if ( bPixelMap )
300 aOrgSize = pOutDev->PixelToLogic( aGrfSize, aDispMap );
301 else
302 aOrgSize = pOutDev->LogicToLogic( aGrfSize, aGrfMap, aDispMap );
304 if ( aOrgSize.Width() && aOrgSize.Height() )
306 fScaleX = (double) rDisplaySize.Width() / aOrgSize.Width();
307 fScaleY = (double) rDisplaySize.Height() / aOrgSize.Height();
309 for ( USHORT j = 0, nPolyCount = rContour.Count(); j < nPolyCount; j++ )
311 Polygon& rPoly = rContour[ j ];
313 for ( USHORT i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
315 if ( bPixelMap )
316 aNewPoint = pOutDev->PixelToLogic( rPoly[ i ], aDispMap );
317 else
318 aNewPoint = pOutDev->LogicToLogic( rPoly[ i ], aGrfMap, aDispMap );
320 rPoly[ i ] = Point( FRound( aNewPoint.X() * fScaleX ), FRound( aNewPoint.Y() * fScaleY ) );
327 /*************************************************************************
329 |* Durchschleifen an SuperClass; keine virt. Methoden, um
330 |* bei IF-Aenderungen nicht inkompatibel zu werden
332 \************************************************************************/
334 void SvxContourDlg::SetExecState( BOOL bEnable )
336 pSuperClass->SetExecState( bEnable );
339 void SvxContourDlg::SetGraphic( const Graphic& rGraphic )
341 pSuperClass->SetGraphic( rGraphic );
344 void SvxContourDlg::SetGraphicLinked( BOOL bGraphicLinked )
346 pSuperClass->SetGraphicLinked( bGraphicLinked );
349 const Graphic& SvxContourDlg::GetGraphic() const
351 return pSuperClass->GetGraphic();
354 BOOL SvxContourDlg::IsGraphicChanged() const
356 return pSuperClass->IsGraphicChanged();
359 void SvxContourDlg::SetPolyPolygon( const PolyPolygon& rPolyPoly )
361 pSuperClass->SetPolyPolygon( rPolyPoly );
364 PolyPolygon SvxContourDlg::GetPolyPolygon()
366 return pSuperClass->GetPolyPolygon( TRUE );
369 void SvxContourDlg::SetEditingObject( void* pObj )
371 pSuperClass->SetEditingObject( pObj );
374 const void* SvxContourDlg::GetEditingObject() const
376 return pSuperClass->GetEditingObject();
379 void SvxContourDlg::Update( const Graphic& rGraphic, BOOL bGraphicLinked,
380 const PolyPolygon* pPolyPoly, void* pEditingObj )
382 pSuperClass->UpdateGraphic( rGraphic, bGraphicLinked, pPolyPoly, pEditingObj );
386 /*************************************************************************
390 \************************************************************************/
392 SvxSuperContourDlg::SvxSuperContourDlg( SfxBindings *_pBindings, SfxChildWindow *pCW,
393 Window* _pParent, const ResId& rResId ) :
394 SvxContourDlg ( _pBindings, pCW, _pParent, rResId ),
395 pCheckObj ( NULL ),
396 aContourItem ( SID_CONTOUR_EXEC, *this, *_pBindings ),
397 aTbx1 ( this, ResId( TBX1, *rResId.GetResMgr() ) ),
398 aMtfTolerance ( this, ResId( MTF_TOLERANCE, *rResId.GetResMgr() ) ),
399 aContourWnd ( this, ResId( CTL_CONTOUR, *rResId.GetResMgr() ) ),
400 aStbStatus ( this, WB_BORDER | WB_3DLOOK | WB_LEFT ),
401 nGrfChanged ( 0UL ),
402 bExecState ( FALSE ),
403 bGraphicLinked ( FALSE ),
404 maImageList ( SVX_RES( CD_IMAPDLG ) ),
405 maImageListH ( SVX_RES( CDH_IMAPDLG ) )
407 ApplyImageList();
409 FreeResource();
411 SvxContourDlg::SetSuperClass( *this );
413 aContourWnd.SetMousePosLink( LINK( this, SvxSuperContourDlg, MousePosHdl ) );
414 aContourWnd.SetGraphSizeLink( LINK( this, SvxSuperContourDlg, GraphSizeHdl ) );
415 aContourWnd.SetUpdateLink( LINK( this, SvxSuperContourDlg, StateHdl ) );
416 aContourWnd.SetPipetteHdl( LINK( this, SvxSuperContourDlg, PipetteHdl ) );
417 aContourWnd.SetPipetteClickHdl( LINK( this, SvxSuperContourDlg, PipetteClickHdl ) );
418 aContourWnd.SetWorkplaceClickHdl( LINK( this, SvxSuperContourDlg, WorkplaceClickHdl ) );
420 const Size aTbxSize( aTbx1.CalcWindowSizePixel() );
421 Point aPos( aTbx1.GetPosPixel() );
422 SvtMiscOptions aMiscOptions;
424 aMiscOptions.AddListener( LINK( this, SvxSuperContourDlg, MiscHdl ) );
426 aTbx1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
427 aTbx1.SetSizePixel( aTbxSize );
428 aTbx1.SetSelectHdl( LINK( this, SvxSuperContourDlg, Tbx1ClickHdl ) );
430 aPos.X() += aTbxSize.Width() + LogicToPixel( Size( 3, 0 ), MapMode( MAP_APPFONT ) ).Width();
431 aMtfTolerance.SetPosPixel( aPos );
432 aMtfTolerance.SetValue( 10L );
434 SetMinOutputSizePixel( aLastSize = GetOutputSizePixel() );
436 aStbStatus.InsertItem( 1, 130, SIB_LEFT | SIB_IN | SIB_AUTOSIZE );
437 aStbStatus.InsertItem( 2, 10 + GetTextWidth( String::CreateFromAscii( " 9999,99 cm / 9999,99 cm " ) ), SIB_CENTER | SIB_IN );
438 aStbStatus.InsertItem( 3, 10 + GetTextWidth( String::CreateFromAscii( " 9999,99 cm x 9999,99 cm " ) ), SIB_CENTER | SIB_IN );
439 aStbStatus.InsertItem( 4, 20, SIB_CENTER | SIB_IN );
441 Resize();
443 aUpdateTimer.SetTimeout( 100 );
444 aUpdateTimer.SetTimeoutHdl( LINK( this, SvxSuperContourDlg, UpdateHdl ) );
446 aCreateTimer.SetTimeout( 50 );
447 aCreateTimer.SetTimeoutHdl( LINK( this, SvxSuperContourDlg, CreateHdl ) );
451 /*************************************************************************
453 |* Dtor
455 \************************************************************************/
457 SvxSuperContourDlg::~SvxSuperContourDlg()
462 /*************************************************************************
464 |* Resize-Methode
466 \************************************************************************/
468 void SvxSuperContourDlg::Resize()
470 SfxFloatingWindow::Resize();
472 Size aMinSize( GetMinOutputSizePixel() );
473 Size aNewSize( GetOutputSizePixel() );
475 if ( aNewSize.Height() >= aMinSize.Height() )
477 Size _aSize( aStbStatus.GetSizePixel() );
478 Point aPoint( 0, aNewSize.Height() - _aSize.Height() );
480 // StatusBar positionieren
481 aStbStatus.SetPosSizePixel( aPoint, Size( aNewSize.Width(), _aSize.Height() ) );
482 aStbStatus.Show();
484 // EditWindow positionieren
485 _aSize.Width() = aNewSize.Width() - 18;
486 _aSize.Height() = aPoint.Y() - aContourWnd.GetPosPixel().Y() - 6;
487 aContourWnd.SetSizePixel( _aSize );
489 aLastSize = aNewSize;
494 /*************************************************************************
496 |* Close-Methode
498 \************************************************************************/
500 BOOL SvxSuperContourDlg::Close()
502 BOOL bRet = TRUE;
504 if ( aTbx1.IsItemEnabled( TBI_APPLY ) )
506 QueryBox aQBox( this, WB_YES_NO_CANCEL | WB_DEF_YES,
507 String( CONT_RESID( STR_CONTOURDLG_MODIFY ) ) );
508 const long nRet = aQBox.Execute();
510 if ( nRet == RET_YES )
512 SfxBoolItem aBoolItem( SID_CONTOUR_EXEC, TRUE );
513 GetBindings().GetDispatcher()->Execute(
514 SID_CONTOUR_EXEC, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
516 else if ( nRet == RET_CANCEL )
517 bRet = FALSE;
520 return( bRet ? SfxFloatingWindow::Close() : FALSE );
524 /*************************************************************************
526 |* Enabled oder disabled alle Controls
528 \************************************************************************/
530 void SvxSuperContourDlg::SetExecState( BOOL bEnable )
532 bExecState = bEnable;
536 /*************************************************************************
540 \************************************************************************/
542 void SvxSuperContourDlg::SetGraphic( const Graphic& rGraphic )
544 aUndoGraphic = aRedoGraphic = Graphic();
545 aGraphic = rGraphic;
546 nGrfChanged = 0UL;
547 aContourWnd.SetGraphic( aGraphic );
551 /*************************************************************************
555 \************************************************************************/
557 void SvxSuperContourDlg::SetPolyPolygon( const PolyPolygon& rPolyPoly )
559 DBG_ASSERT( aContourWnd.GetGraphic().GetType() != GRAPHIC_NONE, "Graphic must've been set first!" );
561 PolyPolygon aPolyPoly( rPolyPoly );
562 const MapMode aMap100( MAP_100TH_MM );
563 const MapMode aGrfMap( aGraphic.GetPrefMapMode() );
564 OutputDevice* pOutDev = Application::GetDefaultDevice();
565 BOOL bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
567 for ( USHORT j = 0, nPolyCount = aPolyPoly.Count(); j < nPolyCount; j++ )
569 Polygon& rPoly = aPolyPoly[ j ];
571 for ( USHORT i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
573 Point& rPt = rPoly[ i ];
575 if ( !bPixelMap )
576 rPt = pOutDev->LogicToPixel( rPt, aGrfMap );
578 rPt = pOutDev->PixelToLogic( rPt, aMap100 );
582 aContourWnd.SetPolyPolygon( aPolyPoly );
583 aContourWnd.GetSdrModel()->SetChanged( sal_True );
587 /*************************************************************************
591 \************************************************************************/
593 PolyPolygon SvxSuperContourDlg::GetPolyPolygon( BOOL bRescaleToGraphic )
595 PolyPolygon aRetPolyPoly( aContourWnd.GetPolyPolygon() );
597 if ( bRescaleToGraphic )
599 const MapMode aMap100( MAP_100TH_MM );
600 const MapMode aGrfMap( aGraphic.GetPrefMapMode() );
601 OutputDevice* pOutDev = Application::GetDefaultDevice();
602 BOOL bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
604 for ( USHORT j = 0, nPolyCount = aRetPolyPoly.Count(); j < nPolyCount; j++ )
606 Polygon& rPoly = aRetPolyPoly[ j ];
608 for ( USHORT i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
610 Point& rPt = rPoly[ i ];
612 rPt = pOutDev->LogicToPixel( rPt, aMap100 );
614 if ( !bPixelMap )
615 rPt = pOutDev->PixelToLogic( rPt, aGrfMap );
620 return aRetPolyPoly;
624 /*************************************************************************
628 \************************************************************************/
630 void SvxSuperContourDlg::UpdateGraphic( const Graphic& rGraphic, BOOL _bGraphicLinked,
631 const PolyPolygon* pPolyPoly, void* pEditingObj )
633 aUpdateGraphic = rGraphic;
634 bUpdateGraphicLinked = _bGraphicLinked;
635 pUpdateEditingObject = pEditingObj;
637 if ( pPolyPoly )
638 aUpdatePolyPoly = *pPolyPoly;
639 else
640 aUpdatePolyPoly = PolyPolygon();
642 aUpdateTimer.Start();
646 /*************************************************************************
650 \************************************************************************/
652 BOOL SvxSuperContourDlg::IsUndoPossible() const
654 return aUndoGraphic.GetType() != GRAPHIC_NONE;
658 /*************************************************************************
662 \************************************************************************/
664 BOOL SvxSuperContourDlg::IsRedoPossible() const
666 return aRedoGraphic.GetType() != GRAPHIC_NONE;
670 /*************************************************************************
674 \************************************************************************/
676 void SvxSuperContourDlg::DoAutoCreate()
678 aCreateTimer.Start();
682 /*************************************************************************
686 \************************************************************************/
688 void SvxSuperContourDlg::ReducePoints( const long nTol )
690 PolyPolygon aPolyPoly( GetPolyPolygon( FALSE ) );
692 if ( aPolyPoly.Count() )
694 const MapMode aMapMode( MAP_100TH_MM );
695 const long nTol2 = nTol * nTol;
696 Polygon& rPoly = aPolyPoly[ 0 ];
697 OutputDevice* pOutDev = Application::GetDefaultDevice();
698 Point aPtPix;
699 const USHORT nSize = rPoly.GetSize();
700 USHORT nCounter = 0;
702 if ( nSize )
703 aPtPix = pOutDev->LogicToPixel( rPoly[ 0 ], aMapMode );
705 for( USHORT i = 1; i < nSize; i++ )
707 const Point& rNewPt = rPoly[ i ];
708 const Point aNewPtPix( pOutDev->LogicToPixel( rNewPt, aMapMode ) );
710 const long nDistX = aNewPtPix.X() - aPtPix.X();
711 const long nDistY = aNewPtPix.Y() - aPtPix.Y();
713 if( ( nDistX * nDistX + nDistY * nDistY ) >= nTol2 )
715 rPoly[ ++nCounter ] = rNewPt;
716 aPtPix = aNewPtPix;
720 rPoly.SetSize( nCounter );
721 aContourWnd.SetPolyPolygon( aPolyPoly );
722 aContourWnd.GetSdrModel()->SetChanged( sal_True );
727 /*************************************************************************
729 |* Click-Hdl fuer ToolBox
731 \************************************************************************/
733 IMPL_LINK( SvxSuperContourDlg, Tbx1ClickHdl, ToolBox*, pTbx )
735 USHORT nNewItemId = pTbx->GetCurItemId();
737 switch( pTbx->GetCurItemId() )
739 case( TBI_APPLY ):
741 SfxBoolItem aBoolItem( SID_CONTOUR_EXEC, TRUE );
742 GetBindings().GetDispatcher()->Execute(
743 SID_CONTOUR_EXEC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
745 break;
747 case( TBI_WORKPLACE ):
749 if ( aTbx1.IsItemChecked( TBI_WORKPLACE ) )
751 QueryBox aQBox( this, WB_YES_NO | WB_DEF_NO, String( CONT_RESID( STR_CONTOURDLG_WORKPLACE ) ) );
753 if ( !aContourWnd.IsContourChanged() || ( aQBox.Execute() == RET_YES ) )
754 aContourWnd.SetWorkplaceMode( TRUE );
755 else
756 aTbx1.CheckItem( TBI_WORKPLACE, FALSE );
758 else
759 aContourWnd.SetWorkplaceMode( FALSE );
761 break;
763 case( TBI_SELECT ):
765 pTbx->CheckItem( nNewItemId, TRUE );
766 aContourWnd.SetEditMode( TRUE );
768 break;
770 case( TBI_RECT ):
772 pTbx->CheckItem( nNewItemId, TRUE );
773 aContourWnd.SetObjKind( OBJ_RECT );
775 break;
777 case( TBI_CIRCLE ):
779 pTbx->CheckItem( nNewItemId, TRUE );
780 aContourWnd.SetObjKind( OBJ_CIRC );
783 break;
785 case( TBI_POLY ):
787 pTbx->CheckItem( nNewItemId, TRUE );
788 aContourWnd.SetObjKind( OBJ_POLY );
790 break;
792 case( TBI_FREEPOLY ):
794 pTbx->CheckItem( nNewItemId, TRUE );
795 aContourWnd.SetObjKind( OBJ_FREEFILL );
797 break;
799 case( TBI_POLYEDIT ):
800 aContourWnd.SetPolyEditMode( pTbx->IsItemChecked( TBI_POLYEDIT ) ? SID_BEZIER_MOVE : 0 );
801 break;
803 case( TBI_POLYMOVE ):
804 aContourWnd.SetPolyEditMode( SID_BEZIER_MOVE );
805 break;
807 case( TBI_POLYINSERT ):
808 aContourWnd.SetPolyEditMode( SID_BEZIER_INSERT );
809 break;
811 case( TBI_POLYDELETE ):
812 aContourWnd.GetSdrView()->DeleteMarkedPoints();
813 break;
815 case( TBI_UNDO ):
817 nGrfChanged = nGrfChanged ? nGrfChanged-- : 0UL;
818 aRedoGraphic = aGraphic;
819 aGraphic = aUndoGraphic;
820 aUndoGraphic = Graphic();
821 aContourWnd.SetGraphic( aGraphic, FALSE );
823 break;
825 case( TBI_REDO ):
827 nGrfChanged++;
828 aUndoGraphic = aGraphic;
829 aGraphic = aRedoGraphic;
830 aRedoGraphic = Graphic();
831 aContourWnd.SetGraphic( aGraphic, FALSE );
833 break;
835 case( TBI_AUTOCONTOUR ):
836 aCreateTimer.Start();
837 break;
839 case( TBI_PIPETTE ):
841 BOOL bPipette = aTbx1.IsItemChecked( TBI_PIPETTE );
843 if ( !bPipette )
844 aStbStatus.Invalidate();
845 else if ( bGraphicLinked )
847 QueryBox aQBox( this, WB_YES_NO | WB_DEF_YES, String( CONT_RESID( STR_CONTOURDLG_LINKED ) ) );
849 if ( aQBox.Execute() != RET_YES )
851 aTbx1.CheckItem( TBI_PIPETTE, bPipette = FALSE );
852 aStbStatus.Invalidate();
856 aContourWnd.SetPipetteMode( bPipette );
858 break;
860 default:
861 break;
864 return 0L;
868 /*************************************************************************
872 \************************************************************************/
874 IMPL_LINK( SvxSuperContourDlg, MousePosHdl, ContourWindow*, pWnd )
876 String aStr;
877 const FieldUnit eFieldUnit = GetModuleFieldUnit();
878 const Point& rMousePos = pWnd->GetMousePos();
879 LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
880 const sal_Unicode cSep = aLocaleWrapper.getNumDecimalSep().GetChar(0);
882 aStr.Assign( GetUnitString( rMousePos.X(), eFieldUnit, cSep ) );
883 aStr.Append( String::CreateFromAscii( " / " ) );
884 aStr.Append( GetUnitString( rMousePos.Y(), eFieldUnit, cSep ) );
886 aStbStatus.SetItemText( 2, aStr );
888 return 0L;
891 /*************************************************************************
895 \************************************************************************/
897 IMPL_LINK( SvxSuperContourDlg, GraphSizeHdl, ContourWindow*, pWnd )
899 String aStr;
900 const FieldUnit eFieldUnit = GetModuleFieldUnit();
901 const Size& rSize = pWnd->GetGraphicSize();
902 LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
903 const sal_Unicode cSep = aLocaleWrapper.getNumDecimalSep().GetChar(0);
905 aStr.Assign( GetUnitString( rSize.Width(), eFieldUnit, cSep ) );
906 aStr.Append( String::CreateFromAscii( " x " ) );
907 aStr.Append( GetUnitString( rSize.Height(), eFieldUnit, cSep ) );
909 aStbStatus.SetItemText( 3, aStr );
911 return 0L;
914 /*************************************************************************
918 \************************************************************************/
920 IMPL_LINK( SvxSuperContourDlg, UpdateHdl, Timer*, EMPTYARG )
922 aUpdateTimer.Stop();
924 if ( pUpdateEditingObject != pCheckObj )
926 if( !GetEditingObject() )
927 aContourWnd.GrabFocus();
929 SetGraphic( aUpdateGraphic );
930 SetPolyPolygon( aUpdatePolyPoly );
931 SetEditingObject( pUpdateEditingObject );
932 bGraphicLinked = bUpdateGraphicLinked;
934 aUpdateGraphic = Graphic();
935 aUpdatePolyPoly = PolyPolygon();
936 bUpdateGraphicLinked = FALSE;
938 aContourWnd.GetSdrModel()->SetChanged( sal_False );
941 GetBindings().Invalidate( SID_CONTOUR_EXEC );
943 return 0L;
947 /*************************************************************************
951 \************************************************************************/
953 IMPL_LINK( SvxSuperContourDlg, CreateHdl, Timer*, EMPTYARG )
955 aCreateTimer.Stop();
957 const Rectangle aWorkRect = aContourWnd.LogicToPixel( aContourWnd.GetWorkRect(), MapMode( MAP_100TH_MM ) );
958 const Graphic& rGraphic = aContourWnd.GetGraphic();
959 const BOOL bValid = aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom();
961 EnterWait();
962 SetPolyPolygon( CreateAutoContour( rGraphic, bValid ? &aWorkRect : NULL ) );
963 LeaveWait();
965 return 0L;
969 /*************************************************************************
973 \************************************************************************/
975 IMPL_LINK( SvxSuperContourDlg, StateHdl, ContourWindow*, pWnd )
977 const SdrObject* pObj = pWnd->GetSelectedSdrObject();
978 const SdrView* pView = pWnd->GetSdrView();
979 const BOOL bPolyEdit = ( pObj != NULL ) && pObj->ISA( SdrPathObj );
980 const BOOL bDrawEnabled = !( bPolyEdit && aTbx1.IsItemChecked( TBI_POLYEDIT ) );
981 const BOOL bPipette = aTbx1.IsItemChecked( TBI_PIPETTE );
982 const BOOL bWorkplace = aTbx1.IsItemChecked( TBI_WORKPLACE );
983 const BOOL bDontHide = !( bPipette || bWorkplace );
984 const BOOL bBitmap = pWnd->GetGraphic().GetType() == GRAPHIC_BITMAP;
986 aTbx1.EnableItem( TBI_APPLY, bDontHide && bExecState && pWnd->IsChanged() );
988 aTbx1.EnableItem( TBI_WORKPLACE, !bPipette && bDrawEnabled );
990 aTbx1.EnableItem( TBI_SELECT, bDontHide && bDrawEnabled );
991 aTbx1.EnableItem( TBI_RECT, bDontHide && bDrawEnabled );
992 aTbx1.EnableItem( TBI_CIRCLE, bDontHide && bDrawEnabled );
993 aTbx1.EnableItem( TBI_POLY, bDontHide && bDrawEnabled );
994 aTbx1.EnableItem( TBI_FREEPOLY, bDontHide && bDrawEnabled );
996 aTbx1.EnableItem( TBI_POLYEDIT, bDontHide && bPolyEdit );
997 aTbx1.EnableItem( TBI_POLYMOVE, bDontHide && !bDrawEnabled );
998 aTbx1.EnableItem( TBI_POLYINSERT, bDontHide && !bDrawEnabled );
999 aTbx1.EnableItem( TBI_POLYDELETE, bDontHide && !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() );
1001 aTbx1.EnableItem( TBI_AUTOCONTOUR, bDontHide && bDrawEnabled );
1002 aTbx1.EnableItem( TBI_PIPETTE, !bWorkplace && bDrawEnabled && bBitmap );
1004 aTbx1.EnableItem( TBI_UNDO, bDontHide && IsUndoPossible() );
1005 aTbx1.EnableItem( TBI_REDO, bDontHide && IsRedoPossible() );
1007 if ( bPolyEdit )
1009 USHORT nId = 0;
1011 switch( pWnd->GetPolyEditMode() )
1013 case( SID_BEZIER_MOVE ): nId = TBI_POLYMOVE; break;
1014 case( SID_BEZIER_INSERT ): nId = TBI_POLYINSERT; break;
1016 default:
1017 break;
1020 aTbx1.CheckItem( nId, TRUE );
1022 else
1024 aTbx1.CheckItem( TBI_POLYEDIT, FALSE );
1025 aTbx1.CheckItem( TBI_POLYMOVE, TRUE );
1026 aTbx1.CheckItem( TBI_POLYINSERT, FALSE );
1027 pWnd->SetPolyEditMode( 0 );
1030 return 0L;
1034 /*************************************************************************
1038 \************************************************************************/
1040 IMPL_LINK( SvxSuperContourDlg, PipetteHdl, ContourWindow*, pWnd )
1042 const Color& rOldLineColor = aStbStatus.GetLineColor();
1043 const Color& rOldFillColor = aStbStatus.GetFillColor();
1045 Rectangle aRect( aStbStatus.GetItemRect( 4 ) );
1046 const Color& rColor = pWnd->GetPipetteColor();
1048 aStbStatus.SetLineColor( rColor );
1049 aStbStatus.SetFillColor( rColor );
1051 aRect.Left() += 4;
1052 aRect.Top() += 4;
1053 aRect.Right() -= 4;
1054 aRect.Bottom() -= 4;
1056 aStbStatus.DrawRect( aRect );
1058 aStbStatus.SetLineColor( rOldLineColor );
1059 aStbStatus.SetFillColor( rOldFillColor );
1061 return 0L;
1065 /*************************************************************************
1069 \************************************************************************/
1071 IMPL_LINK( SvxSuperContourDlg, PipetteClickHdl, ContourWindow*, pWnd )
1073 if ( pWnd->IsClickValid() )
1075 Bitmap aMask;
1076 const Color& rColor = pWnd->GetPipetteColor();
1078 EnterWait();
1080 if( aGraphic.GetType() == GRAPHIC_BITMAP )
1082 Bitmap aBmp( aGraphic.GetBitmap() );
1083 const long nTol = static_cast<long>(aMtfTolerance.GetValue() * 255L / 100L);
1085 aMask = aBmp.CreateMask( rColor, nTol );
1087 if( aGraphic.IsTransparent() )
1088 aMask.CombineSimple( aGraphic.GetBitmapEx().GetMask(), BMP_COMBINE_OR );
1090 if( !!aMask )
1092 QueryBox aQBox( this, WB_YES_NO | WB_DEF_YES, String( CONT_RESID( STR_CONTOURDLG_NEWPIPETTE ) ) );
1093 BOOL bNewContour;
1095 aRedoGraphic = Graphic();
1096 aUndoGraphic = aGraphic;
1097 aGraphic = Graphic( BitmapEx( aBmp, aMask ) );
1098 nGrfChanged++;
1100 bNewContour = ( aQBox.Execute() == RET_YES );
1101 pWnd->SetGraphic( aGraphic, bNewContour );
1103 if( bNewContour )
1104 aCreateTimer.Start();
1108 LeaveWait();
1111 aTbx1.CheckItem( TBI_PIPETTE, FALSE );
1112 pWnd->SetPipetteMode( FALSE );
1113 aStbStatus.Invalidate();
1115 return 0L;
1119 /*************************************************************************
1123 \************************************************************************/
1125 IMPL_LINK( SvxSuperContourDlg, WorkplaceClickHdl, ContourWindow*, pWnd )
1127 aTbx1.CheckItem( TBI_WORKPLACE, FALSE );
1128 aTbx1.CheckItem( TBI_SELECT, TRUE );
1129 pWnd->SetWorkplaceMode( FALSE );
1131 return 0L;
1134 void SvxSuperContourDlg::ApplyImageList()
1136 bool bHighContrast = GetDisplayBackground().GetColor().IsDark() != 0;
1138 ImageList& rImgLst = bHighContrast ? maImageListH : maImageList;
1140 aTbx1.SetImageList( rImgLst );
1143 void SvxSuperContourDlg::DataChanged( const DataChangedEvent& rDCEvt )
1145 SfxFloatingWindow::DataChanged( rDCEvt );
1147 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1148 ApplyImageList();
1151 /*************************************************************************
1155 \************************************************************************/
1157 IMPL_LINK( SvxSuperContourDlg, MiscHdl, void*, EMPTYARG )
1159 SvtMiscOptions aMiscOptions;
1160 aTbx1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
1162 return 0L;