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