update credits
[LibreOffice.git] / svx / source / dialog / _contdlg.cxx
blob1b961bee01358715ddcb4e96ddce03ac3fe6c411
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 <vcl/wrkwin.hxx>
21 #include <sot/factory.hxx>
22 #include <tools/shl.hxx>
23 #include <tools/helpers.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <svl/eitem.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <svtools/miscopt.hxx>
29 #include <unotools/localedatawrapper.hxx>
30 #include <comphelper/processfactory.hxx>
32 #include <svx/dialmgr.hxx>
33 #include "svx/xoutbmp.hxx"
34 #include <svx/dialogs.hrc>
35 #include <svx/svxids.hrc>
36 #include <svx/contdlg.hxx>
37 #include "contimp.hxx"
38 #include "contdlg.hrc"
39 #include "contwnd.hxx"
40 #include <svx/svdtrans.hxx>
41 #include <svx/svdopath.hxx>
42 #include "svx/dlgutil.hxx"
43 #include <vcl/svapp.hxx>
44 #include <vcl/virdev.hxx>
45 #include "dlgunit.hxx"
47 SFX_IMPL_FLOATINGWINDOW_WITHID( SvxContourDlgChildWindow, SID_CONTOUR_DLG );
50 /******************************************************************************/
52 SvxContourDlgItem::SvxContourDlgItem( sal_uInt16 _nId, SvxSuperContourDlg& rContourDlg, SfxBindings& rBindings ) :
53 SfxControllerItem ( _nId, rBindings ),
54 rDlg ( rContourDlg )
58 void SvxContourDlgItem::StateChanged( sal_uInt16 nSID, SfxItemState /*eState*/, const SfxPoolItem* pItem )
60 if ( pItem && ( SID_CONTOUR_EXEC == nSID ) )
62 const SfxBoolItem* pStateItem = PTR_CAST( SfxBoolItem, pItem );
64 DBG_ASSERT( pStateItem || pItem == 0, "SfxBoolItem expected ");
66 rDlg.SetExecState( !pStateItem->GetValue() );
71 /******************************************************************************/
73 SvxContourDlgChildWindow::SvxContourDlgChildWindow( Window* _pParent, sal_uInt16 nId,
74 SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
75 SfxChildWindow( _pParent, nId )
77 SvxSuperContourDlg* pDlg = new SvxSuperContourDlg( pBindings, this, _pParent, CONT_RESID( RID_SVXDLG_CONTOUR ) );
78 pWindow = pDlg;
80 if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
81 pDlg->RollUp();
83 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
85 pDlg->Initialize( pInfo );
88 SvxContourDlg::SvxContourDlg( SfxBindings* _pBindings, SfxChildWindow* pCW,
89 Window* _pParent, const ResId& rResId ) :
91 SfxFloatingWindow ( _pBindings, pCW, _pParent, rResId )
96 SvxContourDlg::~SvxContourDlg()
100 PolyPolygon SvxContourDlg::CreateAutoContour( const Graphic& rGraphic,
101 const Rectangle* pRect,
102 const sal_uIntPtr nFlags )
104 Bitmap aBmp;
105 sal_uIntPtr nContourFlags = XOUTBMP_CONTOUR_HORZ;
107 if ( rGraphic.GetType() == GRAPHIC_BITMAP )
109 if( rGraphic.IsAnimated() )
111 VirtualDevice aVDev;
112 MapMode aTransMap;
113 const Animation aAnim( rGraphic.GetAnimation() );
114 const Size& rSizePix = aAnim.GetDisplaySizePixel();
115 const sal_uInt16 nCount = aAnim.Count();
117 if ( aVDev.SetOutputSizePixel( rSizePix ) )
119 aVDev.SetLineColor( Color( COL_BLACK ) );
120 aVDev.SetFillColor( Color( COL_BLACK ) );
122 for( sal_uInt16 i = 0; i < nCount; i++ )
124 const AnimationBitmap& rStepBmp = aAnim.Get( i );
126 // Push Polygon output to the right place; this is the
127 // offset of the sub-image within the total animation
128 aTransMap.SetOrigin( Point( rStepBmp.aPosPix.X(), rStepBmp.aPosPix.Y() ) );
129 aVDev.SetMapMode( aTransMap );
130 aVDev.DrawPolyPolygon( CreateAutoContour( rStepBmp.aBmpEx, pRect, nFlags ) );
133 aTransMap.SetOrigin( Point() );
134 aVDev.SetMapMode( aTransMap );
135 aBmp = aVDev.GetBitmap( Point(), rSizePix );
136 aBmp.Convert( BMP_CONVERSION_1BIT_THRESHOLD );
139 else if( rGraphic.IsTransparent() )
140 aBmp = rGraphic.GetBitmapEx().GetMask();
141 else
143 aBmp = rGraphic.GetBitmap();
144 nContourFlags |= XOUTBMP_CONTOUR_EDGEDETECT;
147 else if( rGraphic.GetType() != GRAPHIC_NONE )
149 const Graphic aTmpGrf( rGraphic.GetGDIMetaFile().GetMonochromeMtf( Color( COL_BLACK ) ) );
150 VirtualDevice aVDev;
151 Size aSizePix( aVDev.LogicToPixel( aTmpGrf.GetPrefSize(), aTmpGrf.GetPrefMapMode() ) );
153 if( aSizePix.Width() && aSizePix.Height() && ( aSizePix.Width() > 512 || aSizePix.Height() > 512 ) )
155 double fWH = (double) aSizePix.Width() / aSizePix.Height();
157 if( fWH <= 1.0 )
158 aSizePix.Width() = FRound( ( aSizePix.Height() = 512 ) * fWH );
159 else
160 aSizePix.Height() = FRound( ( aSizePix.Width() = 512 ) / fWH );
163 if( aVDev.SetOutputSizePixel( aSizePix ) )
165 const Point aPt;
166 aTmpGrf.Draw( &aVDev, aPt, aSizePix );
167 aBmp = aVDev.GetBitmap( aPt, aSizePix );
170 nContourFlags |= XOUTBMP_CONTOUR_EDGEDETECT;
173 aBmp.SetPrefSize( rGraphic.GetPrefSize() );
174 aBmp.SetPrefMapMode( rGraphic.GetPrefMapMode() );
176 return PolyPolygon( XOutBitmap::GetCountour( aBmp, nContourFlags, 128, pRect ) );
179 // Loop through to super class, no virtual Methods to not become incompatible
180 // due to IF changes
182 const Graphic& SvxContourDlg::GetGraphic() const
184 return pSuperClass->GetGraphic();
187 sal_Bool SvxContourDlg::IsGraphicChanged() const
189 return pSuperClass->IsGraphicChanged();
192 PolyPolygon SvxContourDlg::GetPolyPolygon()
194 return pSuperClass->GetPolyPolygon( true );
197 const void* SvxContourDlg::GetEditingObject() const
199 return pSuperClass->GetEditingObject();
202 void SvxContourDlg::Update( const Graphic& rGraphic, sal_Bool bGraphicLinked,
203 const PolyPolygon* pPolyPoly, void* pEditingObj )
205 pSuperClass->UpdateGraphic( rGraphic, bGraphicLinked, pPolyPoly, pEditingObj );
208 SvxSuperContourDlg::SvxSuperContourDlg( SfxBindings *_pBindings, SfxChildWindow *pCW,
209 Window* _pParent, const ResId& rResId ) :
210 SvxContourDlg ( _pBindings, pCW, _pParent, rResId ),
211 pCheckObj ( NULL ),
212 aContourItem ( SID_CONTOUR_EXEC, *this, *_pBindings ),
213 aTbx1 ( this, ResId( TBX1, *rResId.GetResMgr() ) ),
214 aMtfTolerance ( this, ResId( MTF_TOLERANCE, *rResId.GetResMgr() ) ),
215 aContourWnd ( this, ResId( CTL_CONTOUR, *rResId.GetResMgr() ) ),
216 aStbStatus ( this, WB_BORDER | WB_3DLOOK | WB_LEFT ),
217 nGrfChanged ( 0UL ),
218 bExecState ( sal_False ),
219 bGraphicLinked ( sal_False ),
220 maImageList ( SVX_RES( CD_IMAPDLG ) )
222 ApplyImageList();
224 FreeResource();
226 SvxContourDlg::SetSuperClass( *this );
228 aContourWnd.SetMousePosLink( LINK( this, SvxSuperContourDlg, MousePosHdl ) );
229 aContourWnd.SetGraphSizeLink( LINK( this, SvxSuperContourDlg, GraphSizeHdl ) );
230 aContourWnd.SetUpdateLink( LINK( this, SvxSuperContourDlg, StateHdl ) );
231 aContourWnd.SetPipetteHdl( LINK( this, SvxSuperContourDlg, PipetteHdl ) );
232 aContourWnd.SetPipetteClickHdl( LINK( this, SvxSuperContourDlg, PipetteClickHdl ) );
233 aContourWnd.SetWorkplaceClickHdl( LINK( this, SvxSuperContourDlg, WorkplaceClickHdl ) );
235 const Size aTbxSize( aTbx1.CalcWindowSizePixel() );
236 Point aPos( aTbx1.GetPosPixel() );
237 SvtMiscOptions aMiscOptions;
239 aMiscOptions.AddListenerLink( LINK( this, SvxSuperContourDlg, MiscHdl ) );
241 aTbx1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
242 aTbx1.SetSizePixel( aTbxSize );
243 aTbx1.SetSelectHdl( LINK( this, SvxSuperContourDlg, Tbx1ClickHdl ) );
245 aPos.X() += aTbxSize.Width() + LogicToPixel( Size( 3, 0 ), MapMode( MAP_APPFONT ) ).Width();
246 aMtfTolerance.SetPosPixel( aPos );
247 aMtfTolerance.SetValue( 10L );
249 SetMinOutputSizePixel( aLastSize = GetOutputSizePixel() );
251 aStbStatus.InsertItem( 1, 130, SIB_LEFT | SIB_IN | SIB_AUTOSIZE );
252 aStbStatus.InsertItem( 2, 10 + GetTextWidth( OUString(" 9999,99 cm / 9999,99 cm ") ), SIB_CENTER | SIB_IN );
253 aStbStatus.InsertItem( 3, 10 + GetTextWidth( OUString(" 9999,99 cm x 9999,99 cm ") ), SIB_CENTER | SIB_IN );
254 aStbStatus.InsertItem( 4, 20, SIB_CENTER | SIB_IN );
256 Resize();
258 aUpdateTimer.SetTimeout( 100 );
259 aUpdateTimer.SetTimeoutHdl( LINK( this, SvxSuperContourDlg, UpdateHdl ) );
261 aCreateTimer.SetTimeout( 50 );
262 aCreateTimer.SetTimeoutHdl( LINK( this, SvxSuperContourDlg, CreateHdl ) );
265 SvxSuperContourDlg::~SvxSuperContourDlg()
267 SvtMiscOptions aMiscOptions;
268 aMiscOptions.RemoveListenerLink( LINK(this, SvxSuperContourDlg, MiscHdl) );
271 // Resize methods
273 void SvxSuperContourDlg::Resize()
275 SfxFloatingWindow::Resize();
277 Size aMinSize( GetMinOutputSizePixel() );
278 Size aNewSize( GetOutputSizePixel() );
280 if ( aNewSize.Height() >= aMinSize.Height() )
282 Size _aSize( aStbStatus.GetSizePixel() );
283 Point aPoint( 0, aNewSize.Height() - _aSize.Height() );
285 // Position the StatusBar
286 aStbStatus.SetPosSizePixel( aPoint, Size( aNewSize.Width(), _aSize.Height() ) );
287 aStbStatus.Show();
289 // Position the EditWindow
290 _aSize.Width() = aNewSize.Width() - 18;
291 _aSize.Height() = aPoint.Y() - aContourWnd.GetPosPixel().Y() - 6;
292 aContourWnd.SetSizePixel( _aSize );
294 aLastSize = aNewSize;
298 // Close methods
300 sal_Bool SvxSuperContourDlg::Close()
302 sal_Bool bRet = sal_True;
304 if ( aTbx1.IsItemEnabled( TBI_APPLY ) )
306 QueryBox aQBox( this, WB_YES_NO_CANCEL | WB_DEF_YES,
307 String( CONT_RESID( STR_CONTOURDLG_MODIFY ) ) );
308 const long nRet = aQBox.Execute();
310 if ( nRet == RET_YES )
312 SfxBoolItem aBoolItem( SID_CONTOUR_EXEC, sal_True );
313 GetBindings().GetDispatcher()->Execute(
314 SID_CONTOUR_EXEC, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
316 else if ( nRet == RET_CANCEL )
317 bRet = sal_False;
320 return( bRet ? SfxFloatingWindow::Close() : sal_False );
323 // Enabled or disabled all Controls
325 void SvxSuperContourDlg::SetExecState( sal_Bool bEnable )
327 bExecState = bEnable;
330 void SvxSuperContourDlg::SetGraphic( const Graphic& rGraphic )
332 aUndoGraphic = aRedoGraphic = Graphic();
333 aGraphic = rGraphic;
334 nGrfChanged = 0UL;
335 aContourWnd.SetGraphic( aGraphic );
338 void SvxSuperContourDlg::SetPolyPolygon( const PolyPolygon& rPolyPoly )
340 DBG_ASSERT( aContourWnd.GetGraphic().GetType() != GRAPHIC_NONE, "Graphic must've been set first!" );
342 PolyPolygon aPolyPoly( rPolyPoly );
343 const MapMode aMap100( MAP_100TH_MM );
344 const MapMode aGrfMap( aGraphic.GetPrefMapMode() );
345 OutputDevice* pOutDev = Application::GetDefaultDevice();
346 sal_Bool bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
348 for ( sal_uInt16 j = 0, nPolyCount = aPolyPoly.Count(); j < nPolyCount; j++ )
350 Polygon& rPoly = aPolyPoly[ j ];
352 for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
354 Point& rPt = rPoly[ i ];
356 if ( !bPixelMap )
357 rPt = pOutDev->LogicToPixel( rPt, aGrfMap );
359 rPt = pOutDev->PixelToLogic( rPt, aMap100 );
363 aContourWnd.SetPolyPolygon( aPolyPoly );
364 aContourWnd.GetSdrModel()->SetChanged( sal_True );
367 PolyPolygon SvxSuperContourDlg::GetPolyPolygon( bool bRescaleToGraphic )
369 PolyPolygon aRetPolyPoly( aContourWnd.GetPolyPolygon() );
371 if ( bRescaleToGraphic )
373 const MapMode aMap100( MAP_100TH_MM );
374 const MapMode aGrfMap( aGraphic.GetPrefMapMode() );
375 OutputDevice* pOutDev = Application::GetDefaultDevice();
376 sal_Bool bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
378 for ( sal_uInt16 j = 0, nPolyCount = aRetPolyPoly.Count(); j < nPolyCount; j++ )
380 Polygon& rPoly = aRetPolyPoly[ j ];
382 for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
384 Point& rPt = rPoly[ i ];
386 rPt = pOutDev->LogicToPixel( rPt, aMap100 );
388 if ( !bPixelMap )
389 rPt = pOutDev->PixelToLogic( rPt, aGrfMap );
394 return aRetPolyPoly;
397 void SvxSuperContourDlg::UpdateGraphic( const Graphic& rGraphic, sal_Bool _bGraphicLinked,
398 const PolyPolygon* pPolyPoly, void* pEditingObj )
400 aUpdateGraphic = rGraphic;
401 bUpdateGraphicLinked = _bGraphicLinked;
402 pUpdateEditingObject = pEditingObj;
404 if ( pPolyPoly )
405 aUpdatePolyPoly = *pPolyPoly;
406 else
407 aUpdatePolyPoly = PolyPolygon();
409 aUpdateTimer.Start();
412 bool SvxSuperContourDlg::IsUndoPossible() const
414 return aUndoGraphic.GetType() != GRAPHIC_NONE;
417 bool SvxSuperContourDlg::IsRedoPossible() const
419 return aRedoGraphic.GetType() != GRAPHIC_NONE;
422 // Click handler for ToolBox
424 IMPL_LINK( SvxSuperContourDlg, Tbx1ClickHdl, ToolBox*, pTbx )
426 sal_uInt16 nNewItemId = pTbx->GetCurItemId();
428 switch( pTbx->GetCurItemId() )
430 case( TBI_APPLY ):
432 SfxBoolItem aBoolItem( SID_CONTOUR_EXEC, sal_True );
433 GetBindings().GetDispatcher()->Execute(
434 SID_CONTOUR_EXEC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
436 break;
438 case( TBI_WORKPLACE ):
440 if ( aTbx1.IsItemChecked( TBI_WORKPLACE ) )
442 QueryBox aQBox( this, WB_YES_NO | WB_DEF_NO, String( CONT_RESID( STR_CONTOURDLG_WORKPLACE ) ) );
444 if ( !aContourWnd.IsContourChanged() || ( aQBox.Execute() == RET_YES ) )
445 aContourWnd.SetWorkplaceMode( sal_True );
446 else
447 aTbx1.CheckItem( TBI_WORKPLACE, sal_False );
449 else
450 aContourWnd.SetWorkplaceMode( sal_False );
452 break;
454 case( TBI_SELECT ):
456 pTbx->CheckItem( nNewItemId, sal_True );
457 aContourWnd.SetEditMode( sal_True );
459 break;
461 case( TBI_RECT ):
463 pTbx->CheckItem( nNewItemId, sal_True );
464 aContourWnd.SetObjKind( OBJ_RECT );
466 break;
468 case( TBI_CIRCLE ):
470 pTbx->CheckItem( nNewItemId, sal_True );
471 aContourWnd.SetObjKind( OBJ_CIRC );
474 break;
476 case( TBI_POLY ):
478 pTbx->CheckItem( nNewItemId, sal_True );
479 aContourWnd.SetObjKind( OBJ_POLY );
481 break;
483 case( TBI_FREEPOLY ):
485 pTbx->CheckItem( nNewItemId, sal_True );
486 aContourWnd.SetObjKind( OBJ_FREEFILL );
488 break;
490 case( TBI_POLYEDIT ):
491 aContourWnd.SetPolyEditMode( pTbx->IsItemChecked( TBI_POLYEDIT ) ? SID_BEZIER_MOVE : 0 );
492 break;
494 case( TBI_POLYMOVE ):
495 aContourWnd.SetPolyEditMode( SID_BEZIER_MOVE );
496 break;
498 case( TBI_POLYINSERT ):
499 aContourWnd.SetPolyEditMode( SID_BEZIER_INSERT );
500 break;
502 case( TBI_POLYDELETE ):
503 aContourWnd.GetSdrView()->DeleteMarkedPoints();
504 break;
506 case( TBI_UNDO ):
508 nGrfChanged = nGrfChanged ? nGrfChanged - 1 : 0UL;
509 aRedoGraphic = aGraphic;
510 aGraphic = aUndoGraphic;
511 aUndoGraphic = Graphic();
512 aContourWnd.SetGraphic( aGraphic, sal_False );
514 break;
516 case( TBI_REDO ):
518 nGrfChanged++;
519 aUndoGraphic = aGraphic;
520 aGraphic = aRedoGraphic;
521 aRedoGraphic = Graphic();
522 aContourWnd.SetGraphic( aGraphic, sal_False );
524 break;
526 case( TBI_AUTOCONTOUR ):
527 aCreateTimer.Start();
528 break;
530 case( TBI_PIPETTE ):
532 sal_Bool bPipette = aTbx1.IsItemChecked( TBI_PIPETTE );
534 if ( !bPipette )
535 aStbStatus.Invalidate();
536 else if ( bGraphicLinked )
538 QueryBox aQBox( this, WB_YES_NO | WB_DEF_YES, String( CONT_RESID( STR_CONTOURDLG_LINKED ) ) );
540 if ( aQBox.Execute() != RET_YES )
542 aTbx1.CheckItem( TBI_PIPETTE, bPipette = sal_False );
543 aStbStatus.Invalidate();
547 aContourWnd.SetPipetteMode( bPipette );
549 break;
551 default:
552 break;
555 return 0L;
558 IMPL_LINK( SvxSuperContourDlg, MousePosHdl, ContourWindow*, pWnd )
560 String aStr;
561 const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
562 const Point& rMousePos = pWnd->GetMousePos();
563 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
564 const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
566 aStr.Assign( GetUnitString( rMousePos.X(), eFieldUnit, cSep ) );
567 aStr.Append( OUString(" / ") );
568 aStr.Append( GetUnitString( rMousePos.Y(), eFieldUnit, cSep ) );
570 aStbStatus.SetItemText( 2, aStr );
572 return 0L;
575 IMPL_LINK( SvxSuperContourDlg, GraphSizeHdl, ContourWindow*, pWnd )
577 String aStr;
578 const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
579 const Size& rSize = pWnd->GetGraphicSize();
580 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
581 const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
583 aStr.Assign( GetUnitString( rSize.Width(), eFieldUnit, cSep ) );
584 aStr.Append( OUString(" x ") );
585 aStr.Append( GetUnitString( rSize.Height(), eFieldUnit, cSep ) );
587 aStbStatus.SetItemText( 3, aStr );
589 return 0L;
592 IMPL_LINK_NOARG(SvxSuperContourDlg, UpdateHdl)
594 aUpdateTimer.Stop();
596 if ( pUpdateEditingObject != pCheckObj )
598 if( !GetEditingObject() )
599 aContourWnd.GrabFocus();
601 SetGraphic( aUpdateGraphic );
602 SetPolyPolygon( aUpdatePolyPoly );
603 SetEditingObject( pUpdateEditingObject );
604 bGraphicLinked = bUpdateGraphicLinked;
606 aUpdateGraphic = Graphic();
607 aUpdatePolyPoly = PolyPolygon();
608 bUpdateGraphicLinked = sal_False;
610 aContourWnd.GetSdrModel()->SetChanged( sal_False );
613 GetBindings().Invalidate( SID_CONTOUR_EXEC );
615 return 0L;
618 IMPL_LINK_NOARG(SvxSuperContourDlg, CreateHdl)
620 aCreateTimer.Stop();
622 const Rectangle aWorkRect = aContourWnd.LogicToPixel( aContourWnd.GetWorkRect(), MapMode( MAP_100TH_MM ) );
623 const Graphic& rGraphic = aContourWnd.GetGraphic();
624 const sal_Bool bValid = aWorkRect.Left() != aWorkRect.Right() && aWorkRect.Top() != aWorkRect.Bottom();
626 EnterWait();
627 SetPolyPolygon( CreateAutoContour( rGraphic, bValid ? &aWorkRect : NULL ) );
628 LeaveWait();
630 return 0L;
633 IMPL_LINK( SvxSuperContourDlg, StateHdl, ContourWindow*, pWnd )
635 const SdrObject* pObj = pWnd->GetSelectedSdrObject();
636 const SdrView* pView = pWnd->GetSdrView();
637 const sal_Bool bPolyEdit = ( pObj != NULL ) && pObj->ISA( SdrPathObj );
638 const sal_Bool bDrawEnabled = !( bPolyEdit && aTbx1.IsItemChecked( TBI_POLYEDIT ) );
639 const sal_Bool bPipette = aTbx1.IsItemChecked( TBI_PIPETTE );
640 const sal_Bool bWorkplace = aTbx1.IsItemChecked( TBI_WORKPLACE );
641 const sal_Bool bDontHide = !( bPipette || bWorkplace );
642 const sal_Bool bBitmap = pWnd->GetGraphic().GetType() == GRAPHIC_BITMAP;
644 aTbx1.EnableItem( TBI_APPLY, bDontHide && bExecState && pWnd->IsChanged() );
646 aTbx1.EnableItem( TBI_WORKPLACE, !bPipette && bDrawEnabled );
648 aTbx1.EnableItem( TBI_SELECT, bDontHide && bDrawEnabled );
649 aTbx1.EnableItem( TBI_RECT, bDontHide && bDrawEnabled );
650 aTbx1.EnableItem( TBI_CIRCLE, bDontHide && bDrawEnabled );
651 aTbx1.EnableItem( TBI_POLY, bDontHide && bDrawEnabled );
652 aTbx1.EnableItem( TBI_FREEPOLY, bDontHide && bDrawEnabled );
654 aTbx1.EnableItem( TBI_POLYEDIT, bDontHide && bPolyEdit );
655 aTbx1.EnableItem( TBI_POLYMOVE, bDontHide && !bDrawEnabled );
656 aTbx1.EnableItem( TBI_POLYINSERT, bDontHide && !bDrawEnabled );
657 aTbx1.EnableItem( TBI_POLYDELETE, bDontHide && !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() );
659 aTbx1.EnableItem( TBI_AUTOCONTOUR, bDontHide && bDrawEnabled );
660 aTbx1.EnableItem( TBI_PIPETTE, !bWorkplace && bDrawEnabled && bBitmap );
662 aTbx1.EnableItem( TBI_UNDO, bDontHide && IsUndoPossible() );
663 aTbx1.EnableItem( TBI_REDO, bDontHide && IsRedoPossible() );
665 if ( bPolyEdit )
667 sal_uInt16 nId = 0;
669 switch( pWnd->GetPolyEditMode() )
671 case( SID_BEZIER_MOVE ): nId = TBI_POLYMOVE; break;
672 case( SID_BEZIER_INSERT ): nId = TBI_POLYINSERT; break;
674 default:
675 break;
678 aTbx1.CheckItem( nId, sal_True );
680 else
682 aTbx1.CheckItem( TBI_POLYEDIT, sal_False );
683 aTbx1.CheckItem( TBI_POLYMOVE, sal_True );
684 aTbx1.CheckItem( TBI_POLYINSERT, sal_False );
685 pWnd->SetPolyEditMode( 0 );
688 return 0L;
691 IMPL_LINK( SvxSuperContourDlg, PipetteHdl, ContourWindow*, pWnd )
693 const Color& rOldLineColor = aStbStatus.GetLineColor();
694 const Color& rOldFillColor = aStbStatus.GetFillColor();
696 Rectangle aRect( aStbStatus.GetItemRect( 4 ) );
697 const Color& rColor = pWnd->GetPipetteColor();
699 aStbStatus.SetLineColor( rColor );
700 aStbStatus.SetFillColor( rColor );
702 aRect.Left() += 4;
703 aRect.Top() += 4;
704 aRect.Right() -= 4;
705 aRect.Bottom() -= 4;
707 aStbStatus.DrawRect( aRect );
709 aStbStatus.SetLineColor( rOldLineColor );
710 aStbStatus.SetFillColor( rOldFillColor );
712 return 0L;
715 IMPL_LINK( SvxSuperContourDlg, PipetteClickHdl, ContourWindow*, pWnd )
717 if ( pWnd->IsClickValid() )
719 Bitmap aMask;
720 const Color& rColor = pWnd->GetPipetteColor();
722 EnterWait();
724 if( aGraphic.GetType() == GRAPHIC_BITMAP )
726 Bitmap aBmp( aGraphic.GetBitmap() );
727 const long nTol = static_cast<long>(aMtfTolerance.GetValue() * 255L / 100L);
729 aMask = aBmp.CreateMask( rColor, nTol );
731 if( aGraphic.IsTransparent() )
732 aMask.CombineSimple( aGraphic.GetBitmapEx().GetMask(), BMP_COMBINE_OR );
734 if( !!aMask )
736 QueryBox aQBox( this, WB_YES_NO | WB_DEF_YES, String( CONT_RESID( STR_CONTOURDLG_NEWPIPETTE ) ) );
737 sal_Bool bNewContour;
739 aRedoGraphic = Graphic();
740 aUndoGraphic = aGraphic;
741 aGraphic = Graphic( BitmapEx( aBmp, aMask ) );
742 nGrfChanged++;
744 bNewContour = ( aQBox.Execute() == RET_YES );
745 pWnd->SetGraphic( aGraphic, bNewContour );
747 if( bNewContour )
748 aCreateTimer.Start();
752 LeaveWait();
755 aTbx1.CheckItem( TBI_PIPETTE, sal_False );
756 pWnd->SetPipetteMode( sal_False );
757 aStbStatus.Invalidate();
759 return 0L;
762 IMPL_LINK( SvxSuperContourDlg, WorkplaceClickHdl, ContourWindow*, pWnd )
764 aTbx1.CheckItem( TBI_WORKPLACE, sal_False );
765 aTbx1.CheckItem( TBI_SELECT, sal_True );
766 pWnd->SetWorkplaceMode( sal_False );
768 return 0L;
771 void SvxSuperContourDlg::ApplyImageList()
773 ImageList& rImgLst = maImageList;
775 aTbx1.SetImageList( rImgLst );
778 void SvxSuperContourDlg::DataChanged( const DataChangedEvent& rDCEvt )
780 SfxFloatingWindow::DataChanged( rDCEvt );
782 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
783 ApplyImageList();
786 IMPL_LINK_NOARG(SvxSuperContourDlg, MiscHdl)
788 SvtMiscOptions aMiscOptions;
789 aTbx1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
791 return 0L;
794 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */