Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / dialog / _contdlg.cxx
blob817202e4e3f1cd59cd611befd8dfc87da1d1496d
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/settings.hxx>
45 #include <vcl/virdev.hxx>
46 #include "dlgunit.hxx"
47 #include <vcl/layout.hxx>
49 SFX_IMPL_FLOATINGWINDOW_WITHID( SvxContourDlgChildWindow, SID_CONTOUR_DLG );
52 /******************************************************************************/
54 SvxContourDlgItem::SvxContourDlgItem( sal_uInt16 _nId, SvxSuperContourDlg& rContourDlg, SfxBindings& rBindings ) :
55 SfxControllerItem ( _nId, rBindings ),
56 rDlg ( rContourDlg )
60 void SvxContourDlgItem::StateChanged( sal_uInt16 nSID, SfxItemState /*eState*/, const SfxPoolItem* pItem )
62 if ( pItem && ( SID_CONTOUR_EXEC == nSID ) )
64 const SfxBoolItem* pStateItem = PTR_CAST( SfxBoolItem, pItem );
65 assert(pStateItem); //SfxBoolItem expected
66 if (pStateItem)
67 rDlg.SetExecState(!pStateItem->GetValue());
71 SvxContourDlgChildWindow::SvxContourDlgChildWindow( Window* _pParent, sal_uInt16 nId,
72 SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
73 SfxChildWindow( _pParent, nId )
75 SvxSuperContourDlg* pDlg = new SvxSuperContourDlg( pBindings, this, _pParent, CONT_RESID( RID_SVXDLG_CONTOUR ) );
76 pWindow = pDlg;
78 if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
79 pDlg->RollUp();
81 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
83 pDlg->Initialize( pInfo );
86 SvxContourDlg::SvxContourDlg( SfxBindings* _pBindings, SfxChildWindow* pCW,
87 Window* _pParent, const ResId& rResId )
88 : SfxFloatingWindow(_pBindings, pCW, _pParent, rResId)
89 , pSuperClass(NULL)
93 SvxContourDlg::~SvxContourDlg()
97 PolyPolygon SvxContourDlg::CreateAutoContour( const Graphic& rGraphic,
98 const Rectangle* pRect,
99 const sal_uIntPtr nFlags )
101 Bitmap aBmp;
102 sal_uIntPtr nContourFlags = XOUTBMP_CONTOUR_HORZ;
104 if ( rGraphic.GetType() == GRAPHIC_BITMAP )
106 if( rGraphic.IsAnimated() )
108 VirtualDevice aVDev;
109 MapMode aTransMap;
110 const Animation aAnim( rGraphic.GetAnimation() );
111 const Size& rSizePix = aAnim.GetDisplaySizePixel();
112 const sal_uInt16 nCount = aAnim.Count();
114 if ( aVDev.SetOutputSizePixel( rSizePix ) )
116 aVDev.SetLineColor( Color( COL_BLACK ) );
117 aVDev.SetFillColor( Color( COL_BLACK ) );
119 for( sal_uInt16 i = 0; i < nCount; i++ )
121 const AnimationBitmap& rStepBmp = aAnim.Get( i );
123 // Push Polygon output to the right place; this is the
124 // offset of the sub-image within the total animation
125 aTransMap.SetOrigin( Point( rStepBmp.aPosPix.X(), rStepBmp.aPosPix.Y() ) );
126 aVDev.SetMapMode( aTransMap );
127 aVDev.DrawPolyPolygon( CreateAutoContour( rStepBmp.aBmpEx, pRect, nFlags ) );
130 aTransMap.SetOrigin( Point() );
131 aVDev.SetMapMode( aTransMap );
132 aBmp = aVDev.GetBitmap( Point(), rSizePix );
133 aBmp.Convert( BMP_CONVERSION_1BIT_THRESHOLD );
136 else if( rGraphic.IsTransparent() )
137 aBmp = rGraphic.GetBitmapEx().GetMask();
138 else
140 aBmp = rGraphic.GetBitmap();
141 nContourFlags |= XOUTBMP_CONTOUR_EDGEDETECT;
144 else if( rGraphic.GetType() != GRAPHIC_NONE )
146 const Graphic aTmpGrf( rGraphic.GetGDIMetaFile().GetMonochromeMtf( Color( COL_BLACK ) ) );
147 VirtualDevice aVDev;
148 Size aSizePix( aVDev.LogicToPixel( aTmpGrf.GetPrefSize(), aTmpGrf.GetPrefMapMode() ) );
150 if( aSizePix.Width() && aSizePix.Height() && ( aSizePix.Width() > 512 || aSizePix.Height() > 512 ) )
152 double fWH = (double) aSizePix.Width() / aSizePix.Height();
154 if( fWH <= 1.0 )
155 aSizePix.Width() = FRound( ( aSizePix.Height() = 512 ) * fWH );
156 else
157 aSizePix.Height() = FRound( ( aSizePix.Width() = 512 ) / fWH );
160 if( aVDev.SetOutputSizePixel( aSizePix ) )
162 const Point aPt;
163 aTmpGrf.Draw( &aVDev, aPt, aSizePix );
164 aBmp = aVDev.GetBitmap( aPt, aSizePix );
167 nContourFlags |= XOUTBMP_CONTOUR_EDGEDETECT;
170 aBmp.SetPrefSize( rGraphic.GetPrefSize() );
171 aBmp.SetPrefMapMode( rGraphic.GetPrefMapMode() );
173 return PolyPolygon( XOutBitmap::GetCountour( aBmp, nContourFlags, 128, pRect ) );
176 // Loop through to super class, no virtual Methods to not become incompatible
177 // due to IF changes
179 const Graphic& SvxContourDlg::GetGraphic() const
181 return pSuperClass->GetGraphic();
184 bool SvxContourDlg::IsGraphicChanged() const
186 return pSuperClass->IsGraphicChanged();
189 PolyPolygon SvxContourDlg::GetPolyPolygon()
191 return pSuperClass->GetPolyPolygon( true );
194 const void* SvxContourDlg::GetEditingObject() const
196 return pSuperClass->GetEditingObject();
199 void SvxContourDlg::Update( const Graphic& rGraphic, bool bGraphicLinked,
200 const PolyPolygon* pPolyPoly, void* pEditingObj )
202 pSuperClass->UpdateGraphic( rGraphic, bGraphicLinked, pPolyPoly, pEditingObj );
205 SvxSuperContourDlg::SvxSuperContourDlg( SfxBindings *_pBindings, SfxChildWindow *pCW,
206 Window* _pParent, const ResId& rResId ) :
207 SvxContourDlg ( _pBindings, pCW, _pParent, rResId ),
208 pUpdateEditingObject( NULL ),
209 pCheckObj ( NULL ),
210 aContourItem ( SID_CONTOUR_EXEC, *this, *_pBindings ),
211 aTbx1 ( this, ResId( TBX1, *rResId.GetResMgr() ) ),
212 aMtfTolerance ( this, ResId( MTF_TOLERANCE, *rResId.GetResMgr() ) ),
213 aContourWnd ( this, ResId( CTL_CONTOUR, *rResId.GetResMgr() ) ),
214 aStbStatus ( this, WB_BORDER | WB_3DLOOK | WB_LEFT ),
215 nGrfChanged ( 0UL ),
216 bExecState ( false ),
217 bUpdateGraphicLinked( false ),
218 bGraphicLinked ( false ),
219 maImageList ( SVX_RES( CD_IMAPDLG ) )
221 ApplyImageList();
223 FreeResource();
225 SvxContourDlg::SetSuperClass( *this );
227 aContourWnd.SetMousePosLink( LINK( this, SvxSuperContourDlg, MousePosHdl ) );
228 aContourWnd.SetGraphSizeLink( LINK( this, SvxSuperContourDlg, GraphSizeHdl ) );
229 aContourWnd.SetUpdateLink( LINK( this, SvxSuperContourDlg, StateHdl ) );
230 aContourWnd.SetPipetteHdl( LINK( this, SvxSuperContourDlg, PipetteHdl ) );
231 aContourWnd.SetPipetteClickHdl( LINK( this, SvxSuperContourDlg, PipetteClickHdl ) );
232 aContourWnd.SetWorkplaceClickHdl( LINK( this, SvxSuperContourDlg, WorkplaceClickHdl ) );
234 const Size aTbxSize( aTbx1.CalcWindowSizePixel() );
235 Point aPos( aTbx1.GetPosPixel() );
236 SvtMiscOptions aMiscOptions;
238 aMiscOptions.AddListenerLink( LINK( this, SvxSuperContourDlg, MiscHdl ) );
240 aTbx1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
241 aTbx1.SetSizePixel( aTbxSize );
242 aTbx1.SetSelectHdl( LINK( this, SvxSuperContourDlg, Tbx1ClickHdl ) );
244 aPos.X() += aTbxSize.Width() + LogicToPixel( Size( 3, 0 ), MapMode( MAP_APPFONT ) ).Width();
245 aMtfTolerance.SetPosPixel( aPos );
246 aMtfTolerance.SetValue( 10L );
248 SetMinOutputSizePixel( aLastSize = GetOutputSizePixel() );
250 aStbStatus.InsertItem( 1, 130, SIB_LEFT | SIB_IN | SIB_AUTOSIZE );
251 aStbStatus.InsertItem( 2, 10 + GetTextWidth( OUString(" 9999,99 cm / 9999,99 cm ") ), SIB_CENTER | SIB_IN );
252 aStbStatus.InsertItem( 3, 10 + GetTextWidth( OUString(" 9999,99 cm x 9999,99 cm ") ), SIB_CENTER | SIB_IN );
253 aStbStatus.InsertItem( 4, 20, SIB_CENTER | SIB_IN );
255 Resize();
257 aUpdateTimer.SetTimeout( 100 );
258 aUpdateTimer.SetTimeoutHdl( LINK( this, SvxSuperContourDlg, UpdateHdl ) );
260 aCreateTimer.SetTimeout( 50 );
261 aCreateTimer.SetTimeoutHdl( LINK( this, SvxSuperContourDlg, CreateHdl ) );
264 SvxSuperContourDlg::~SvxSuperContourDlg()
266 SvtMiscOptions aMiscOptions;
267 aMiscOptions.RemoveListenerLink( LINK(this, SvxSuperContourDlg, MiscHdl) );
270 // Resize methods
272 void SvxSuperContourDlg::Resize()
274 SfxFloatingWindow::Resize();
276 Size aMinSize( GetMinOutputSizePixel() );
277 Size aNewSize( GetOutputSizePixel() );
279 if ( aNewSize.Height() >= aMinSize.Height() )
281 Size _aSize( aStbStatus.GetSizePixel() );
282 Point aPoint( 0, aNewSize.Height() - _aSize.Height() );
284 // Position the StatusBar
285 aStbStatus.SetPosSizePixel( aPoint, Size( aNewSize.Width(), _aSize.Height() ) );
286 aStbStatus.Show();
288 // Position the EditWindow
289 _aSize.Width() = aNewSize.Width() - 18;
290 _aSize.Height() = aPoint.Y() - aContourWnd.GetPosPixel().Y() - 6;
291 aContourWnd.SetSizePixel( _aSize );
293 aLastSize = aNewSize;
297 // Close methods
299 bool SvxSuperContourDlg::Close()
301 bool bRet = true;
303 if ( aTbx1.IsItemEnabled( TBI_APPLY ) )
305 MessageDialog aQBox( this,"QuerySaveContourChangesDialog","svx/ui/querysavecontchangesdialog.ui");
306 const long nRet = aQBox.Execute();
308 if ( nRet == RET_YES )
310 SfxBoolItem aBoolItem( SID_CONTOUR_EXEC, true );
311 GetBindings().GetDispatcher()->Execute(
312 SID_CONTOUR_EXEC, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
314 else if ( nRet == RET_CANCEL )
315 bRet = false;
318 return( bRet ? SfxFloatingWindow::Close() : sal_False );
321 // Enabled or disabled all Controls
323 void SvxSuperContourDlg::SetExecState( bool bEnable )
325 bExecState = bEnable;
328 void SvxSuperContourDlg::SetGraphic( const Graphic& rGraphic )
330 aUndoGraphic = aRedoGraphic = Graphic();
331 aGraphic = rGraphic;
332 nGrfChanged = 0UL;
333 aContourWnd.SetGraphic( aGraphic );
336 void SvxSuperContourDlg::SetPolyPolygon( const PolyPolygon& rPolyPoly )
338 DBG_ASSERT( aContourWnd.GetGraphic().GetType() != GRAPHIC_NONE, "Graphic must've been set first!" );
340 PolyPolygon aPolyPoly( rPolyPoly );
341 const MapMode aMap100( MAP_100TH_MM );
342 const MapMode aGrfMap( aGraphic.GetPrefMapMode() );
343 OutputDevice* pOutDev = Application::GetDefaultDevice();
344 bool bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
346 for ( sal_uInt16 j = 0, nPolyCount = aPolyPoly.Count(); j < nPolyCount; j++ )
348 Polygon& rPoly = aPolyPoly[ j ];
350 for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
352 Point& rPt = rPoly[ i ];
354 if ( !bPixelMap )
355 rPt = pOutDev->LogicToPixel( rPt, aGrfMap );
357 rPt = pOutDev->PixelToLogic( rPt, aMap100 );
361 aContourWnd.SetPolyPolygon( aPolyPoly );
362 aContourWnd.GetSdrModel()->SetChanged( true );
365 PolyPolygon SvxSuperContourDlg::GetPolyPolygon( bool bRescaleToGraphic )
367 PolyPolygon aRetPolyPoly( aContourWnd.GetPolyPolygon() );
369 if ( bRescaleToGraphic )
371 const MapMode aMap100( MAP_100TH_MM );
372 const MapMode aGrfMap( aGraphic.GetPrefMapMode() );
373 OutputDevice* pOutDev = Application::GetDefaultDevice();
374 bool bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
376 for ( sal_uInt16 j = 0, nPolyCount = aRetPolyPoly.Count(); j < nPolyCount; j++ )
378 Polygon& rPoly = aRetPolyPoly[ j ];
380 for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
382 Point& rPt = rPoly[ i ];
384 rPt = pOutDev->LogicToPixel( rPt, aMap100 );
386 if ( !bPixelMap )
387 rPt = pOutDev->PixelToLogic( rPt, aGrfMap );
392 return aRetPolyPoly;
395 void SvxSuperContourDlg::UpdateGraphic( const Graphic& rGraphic, bool _bGraphicLinked,
396 const PolyPolygon* pPolyPoly, void* pEditingObj )
398 aUpdateGraphic = rGraphic;
399 bUpdateGraphicLinked = _bGraphicLinked;
400 pUpdateEditingObject = pEditingObj;
402 if ( pPolyPoly )
403 aUpdatePolyPoly = *pPolyPoly;
404 else
405 aUpdatePolyPoly = PolyPolygon();
407 aUpdateTimer.Start();
410 bool SvxSuperContourDlg::IsUndoPossible() const
412 return aUndoGraphic.GetType() != GRAPHIC_NONE;
415 bool SvxSuperContourDlg::IsRedoPossible() const
417 return aRedoGraphic.GetType() != GRAPHIC_NONE;
420 // Click handler for ToolBox
422 IMPL_LINK( SvxSuperContourDlg, Tbx1ClickHdl, ToolBox*, pTbx )
424 sal_uInt16 nNewItemId = pTbx->GetCurItemId();
426 switch( pTbx->GetCurItemId() )
428 case( TBI_APPLY ):
430 SfxBoolItem aBoolItem( SID_CONTOUR_EXEC, true );
431 GetBindings().GetDispatcher()->Execute(
432 SID_CONTOUR_EXEC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
434 break;
436 case( TBI_WORKPLACE ):
438 if ( aTbx1.IsItemChecked( TBI_WORKPLACE ) )
440 MessageDialog aQBox( this,"QueryDeleteContourDialog","svx/ui/querydeletecontourdialog.ui");
442 if ( !aContourWnd.IsContourChanged() || ( aQBox.Execute() == RET_YES ) )
443 aContourWnd.SetWorkplaceMode( true );
444 else
445 aTbx1.CheckItem( TBI_WORKPLACE, false );
447 else
448 aContourWnd.SetWorkplaceMode( false );
450 break;
452 case( TBI_SELECT ):
454 pTbx->CheckItem( nNewItemId, true );
455 aContourWnd.SetEditMode( true );
457 break;
459 case( TBI_RECT ):
461 pTbx->CheckItem( nNewItemId, true );
462 aContourWnd.SetObjKind( OBJ_RECT );
464 break;
466 case( TBI_CIRCLE ):
468 pTbx->CheckItem( nNewItemId, true );
469 aContourWnd.SetObjKind( OBJ_CIRC );
472 break;
474 case( TBI_POLY ):
476 pTbx->CheckItem( nNewItemId, true );
477 aContourWnd.SetObjKind( OBJ_POLY );
479 break;
481 case( TBI_FREEPOLY ):
483 pTbx->CheckItem( nNewItemId, true );
484 aContourWnd.SetObjKind( OBJ_FREEFILL );
486 break;
488 case( TBI_POLYEDIT ):
489 aContourWnd.SetPolyEditMode( pTbx->IsItemChecked( TBI_POLYEDIT ) ? SID_BEZIER_MOVE : 0 );
490 break;
492 case( TBI_POLYMOVE ):
493 aContourWnd.SetPolyEditMode( SID_BEZIER_MOVE );
494 break;
496 case( TBI_POLYINSERT ):
497 aContourWnd.SetPolyEditMode( SID_BEZIER_INSERT );
498 break;
500 case( TBI_POLYDELETE ):
501 aContourWnd.GetSdrView()->DeleteMarkedPoints();
502 break;
504 case( TBI_UNDO ):
506 nGrfChanged = nGrfChanged ? nGrfChanged - 1 : 0UL;
507 aRedoGraphic = aGraphic;
508 aGraphic = aUndoGraphic;
509 aUndoGraphic = Graphic();
510 aContourWnd.SetGraphic( aGraphic, false );
512 break;
514 case( TBI_REDO ):
516 nGrfChanged++;
517 aUndoGraphic = aGraphic;
518 aGraphic = aRedoGraphic;
519 aRedoGraphic = Graphic();
520 aContourWnd.SetGraphic( aGraphic, false );
522 break;
524 case( TBI_AUTOCONTOUR ):
525 aCreateTimer.Start();
526 break;
528 case( TBI_PIPETTE ):
530 bool bPipette = aTbx1.IsItemChecked( TBI_PIPETTE );
532 if ( !bPipette )
533 aStbStatus.Invalidate();
534 else if ( bGraphicLinked )
536 MessageDialog aQBox(this, "QueryUnlinkGraphicsDialog",
537 "svx/ui/queryunlinkgraphicsdialog.ui");
539 if (aQBox.Execute() != RET_YES)
541 bPipette = false;
542 aTbx1.CheckItem(TBI_PIPETTE, bPipette);
543 aStbStatus.Invalidate();
547 aContourWnd.SetPipetteMode( bPipette );
549 break;
551 default:
552 break;
555 return 0L;
558 IMPL_LINK( SvxSuperContourDlg, MousePosHdl, ContourWindow*, pWnd )
560 OUString 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 = GetUnitString( rMousePos.X(), eFieldUnit, cSep );
567 aStr += " / ";
568 aStr += GetUnitString( rMousePos.Y(), eFieldUnit, cSep );
570 aStbStatus.SetItemText( 2, aStr );
572 return 0L;
575 IMPL_LINK( SvxSuperContourDlg, GraphSizeHdl, ContourWindow*, pWnd )
577 OUString 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 = GetUnitString( rSize.Width(), eFieldUnit, cSep );
584 aStr += " x ";
585 aStr += 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 = false;
610 aContourWnd.GetSdrModel()->SetChanged( 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 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 bool bPolyEdit = ( pObj != NULL ) && pObj->ISA( SdrPathObj );
638 const bool bDrawEnabled = !( bPolyEdit && aTbx1.IsItemChecked( TBI_POLYEDIT ) );
639 const bool bPipette = aTbx1.IsItemChecked( TBI_PIPETTE );
640 const bool bWorkplace = aTbx1.IsItemChecked( TBI_WORKPLACE );
641 const bool bDontHide = !( bPipette || bWorkplace );
642 const 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, true );
680 else
682 aTbx1.CheckItem( TBI_POLYEDIT, false );
683 aTbx1.CheckItem( TBI_POLYMOVE, true );
684 aTbx1.CheckItem( TBI_POLYINSERT, 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 MessageDialog aQBox( this,"QueryNewContourDialog","svx/ui/querynewcontourdialog.ui");
737 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, false );
756 pWnd->SetPipetteMode( false );
757 aStbStatus.Invalidate();
759 return 0L;
762 IMPL_LINK( SvxSuperContourDlg, WorkplaceClickHdl, ContourWindow*, pWnd )
764 aTbx1.CheckItem( TBI_WORKPLACE, false );
765 aTbx1.CheckItem( TBI_SELECT, true );
766 pWnd->SetWorkplaceMode( 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: */