1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 #include <tools/urlobj.hxx> 31 #include <vcl/msgbox.hxx> 32 #include <vcl/help.hxx> 33 #include <sfx2/sfxsids.hrc> // SID_ATTR_MACROITEM 34 #define _ANIMATION 35 #include <svtools/imaprect.hxx> 36 #include <svtools/imapcirc.hxx> 37 #include <svtools/imappoly.hxx> 38 #include <svl/urlbmk.hxx> 39 40 #include <svx/xoutbmp.hxx> 41 #include <svx/dialmgr.hxx> 42 #include <svx/dialogs.hrc> 43 #include <svx/svxids.hrc> 44 #include <imapdlg.hrc> 45 #include <imapwnd.hxx> 46 #include <svx/svdpage.hxx> 47 #include <svx/svdorect.hxx> 48 #include <svx/svdocirc.hxx> 49 #include <svx/svdopath.hxx> 50 #include <svx/xfltrit.hxx> 51 #include <svx/svdpagv.hxx> 52 #include <svl/urihelper.hxx> 53 #include <svx/xfillit.hxx> 54 #include <svx/xlineit.hxx> 55 #include <sfx2/evntconf.hxx> 56 57 #include <sot/formats.hxx> 58 59 #include <svx/svxdlg.hxx> 60 #include <svx/dialogs.hrc> 61 #include <basegfx/point/b2dpoint.hxx> 62 #include <basegfx/polygon/b2dpolygon.hxx> 63 64 using ::com::sun::star::frame::XFrame; 65 using ::com::sun::star::uno::Reference; 66 67 #define TRANSCOL Color( COL_WHITE ) 68 69 /************************************************************************* 70 |* 71 |* 72 |* 73 \************************************************************************/ 74 75 IMapWindow::IMapWindow( Window* pParent, const ResId& rResId, const Reference< XFrame >& rxDocumentFrame ) : 76 GraphCtrl( pParent, rResId ), 77 DropTargetHelper( this ), 78 mxDocumentFrame( rxDocumentFrame ) 79 { 80 SetWinStyle( WB_SDRMODE ); 81 82 pItemInfo = new SfxItemInfo[ 1 ]; 83 memset( pItemInfo, 0, sizeof( SfxItemInfo ) ); 84 pIMapPool = new SfxItemPool( String::CreateFromAscii( "IMapItemPool" ), 85 SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, pItemInfo ); 86 pIMapPool->FreezeIdRanges(); 87 } 88 89 /************************************************************************* 90 |* 91 |* 92 |* 93 \************************************************************************/ 94 95 IMapWindow::~IMapWindow() 96 { 97 // Liste loeschen 98 for( String* pStr = aTargetList.First(); pStr; pStr = aTargetList.Next() ) 99 delete pStr; 100 101 SfxItemPool::Free(pIMapPool); 102 delete[] pItemInfo; 103 } 104 105 /************************************************************************* 106 |* 107 |* 108 |* 109 \************************************************************************/ 110 111 void IMapWindow::SetImageMap( const ImageMap& rImageMap ) 112 { 113 ReplaceImageMap( rImageMap, sal_False ); 114 } 115 116 /************************************************************************* 117 |* 118 |* 119 |* 120 \************************************************************************/ 121 122 void IMapWindow::ReplaceImageMap( const ImageMap& rImageMap, sal_Bool /*bScaleToGraphic*/ ) 123 { 124 SdrPage* pPage = 0; 125 aIMap = rImageMap; 126 127 if(GetSdrModel()) 128 { 129 // try to access page 130 pPage = GetSdrModel()->GetPage(0L); 131 } 132 133 if(pPage) 134 { 135 // clear all draw objects 136 pPage->Clear(); 137 } 138 139 if(GetSdrView()) 140 { 141 // #i63762# reset selection at view 142 GetSdrView()->UnmarkAllObj(); 143 } 144 145 // create new drawing objects 146 const sal_uInt16 nCount(rImageMap.GetIMapObjectCount()); 147 148 for ( sal_uInt16 i(nCount); i > 0; i-- ) 149 { 150 SdrObject* pNewObj = CreateObj( rImageMap.GetIMapObject( i - 1 ) ); 151 152 if ( pNewObj ) 153 { 154 pPage->InsertObject( pNewObj ); 155 } 156 } 157 } 158 159 /************************************************************************* 160 |* 161 |* 162 |* 163 \************************************************************************/ 164 165 sal_Bool IMapWindow::ReplaceActualIMapInfo( const NotifyInfo& rNewInfo ) 166 { 167 const SdrObject* pSdrObj = GetSelectedSdrObject(); 168 IMapObject* pIMapObj; 169 sal_Bool bRet = sal_False; 170 171 if ( pSdrObj && ( ( pIMapObj = GetIMapObj( pSdrObj ) ) != NULL ) ) 172 { 173 pIMapObj->SetURL( rNewInfo.aMarkURL ); 174 pIMapObj->SetAltText( rNewInfo.aMarkAltText ); 175 pIMapObj->SetTarget( rNewInfo.aMarkTarget ); 176 pModel->SetChanged( sal_True ); 177 UpdateInfo( sal_False ); 178 179 bRet = sal_True; 180 } 181 182 return bRet; 183 } 184 185 /************************************************************************* 186 |* 187 |* 188 |* 189 \************************************************************************/ 190 191 const ImageMap& IMapWindow::GetImageMap() 192 { 193 if ( pModel->IsChanged() ) 194 { 195 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 ); 196 197 if ( pPage ) 198 { 199 const long nCount = pPage->GetObjCount(); 200 201 aIMap.ClearImageMap(); 202 203 for ( long i = nCount - 1; i > -1; i-- ) 204 aIMap.InsertIMapObject( *( ( (IMapUserData*) pPage->GetObj( i )->GetUserData( 0 ) )->GetObject() ) ); 205 } 206 207 pModel->SetChanged( sal_False ); 208 } 209 210 return aIMap; 211 } 212 213 /************************************************************************* 214 |* 215 |* 216 |* 217 \************************************************************************/ 218 219 void IMapWindow::SetTargetList( TargetList& rTargetList ) 220 { 221 String* pStr; 222 223 // alte Liste loeschen 224 for( pStr = aTargetList.First(); pStr; pStr = aTargetList.Next() ) 225 delete pStr; 226 227 aTargetList.Clear(); 228 229 // mit uebergebener Liste fuellen 230 for( pStr = rTargetList.First(); pStr; pStr = rTargetList.Next() ) 231 aTargetList.Insert( new String( *pStr ) ); 232 233 pModel->SetChanged( sal_False ); 234 } 235 236 /************************************************************************* 237 |* 238 |* 239 |* 240 \************************************************************************/ 241 242 SdrObject* IMapWindow::CreateObj( const IMapObject* pIMapObj ) 243 { 244 Point aPoint; 245 Rectangle aClipRect( aPoint, GetGraphicSize() ); 246 SdrObject* pSdrObj = NULL; 247 IMapObjectPtr pCloneIMapObj; 248 249 switch( pIMapObj->GetType() ) 250 { 251 case( IMAP_OBJ_RECTANGLE ): 252 { 253 IMapRectangleObject* pIMapRectObj = (IMapRectangleObject*) pIMapObj; 254 Rectangle aDrawRect( pIMapRectObj->GetRectangle( sal_False ) ); 255 256 // auf Zeichenflaeche clippen 257 aDrawRect.Intersection( aClipRect ); 258 259 pSdrObj = (SdrObject*) new SdrRectObj( aDrawRect ); 260 pCloneIMapObj.reset((IMapObject*) new IMapRectangleObject( *pIMapRectObj )); 261 } 262 break; 263 264 case( IMAP_OBJ_CIRCLE ): 265 { 266 IMapCircleObject* pIMapCircleObj = (IMapCircleObject*) pIMapObj; 267 const Point aCenter( pIMapCircleObj->GetCenter( sal_False ) ); 268 const long nRadius = pIMapCircleObj->GetRadius( sal_False ); 269 const Point aOffset( nRadius, nRadius ); 270 Rectangle aCircle( aCenter - aOffset, aCenter + aOffset ); 271 272 // auf Zeichenflaeche begrenzen 273 aCircle.Intersection( aClipRect ); 274 275 pSdrObj = (SdrObject*) new SdrCircObj( OBJ_CIRC, aCircle, 0, 36000 ); 276 pCloneIMapObj.reset((IMapObject*) new IMapCircleObject( *pIMapCircleObj )); 277 } 278 break; 279 280 case( IMAP_OBJ_POLYGON ): 281 { 282 IMapPolygonObject* pIMapPolyObj = (IMapPolygonObject*) pIMapObj; 283 284 // Falls wir eigentlich eine Ellipse sind, 285 // erzeugen wir auch wieder eine Ellipse 286 if ( pIMapPolyObj->HasExtraEllipse() ) 287 { 288 Rectangle aDrawRect( pIMapPolyObj->GetExtraEllipse() ); 289 290 // auf Zeichenflaeche clippen 291 aDrawRect.Intersection( aClipRect ); 292 293 pSdrObj = (SdrObject*) new SdrCircObj( OBJ_CIRC, aDrawRect, 0, 36000 ); 294 } 295 else 296 { 297 const Polygon& rPoly = pIMapPolyObj->GetPolygon( sal_False ); 298 Polygon aDrawPoly( rPoly ); 299 300 // auf Zeichenflaeche clippen 301 aDrawPoly.Clip( aClipRect ); 302 303 basegfx::B2DPolygon aPolygon; 304 aPolygon.append(aDrawPoly.getB2DPolygon()); 305 pSdrObj = (SdrObject*)new SdrPathObj(OBJ_POLY, basegfx::B2DPolyPolygon(aPolygon)); 306 } 307 308 pCloneIMapObj.reset((IMapObject*) new IMapPolygonObject( *pIMapPolyObj )); 309 } 310 break; 311 312 default: 313 break; 314 } 315 316 if ( pSdrObj ) 317 { 318 SfxItemSet aSet( pModel->GetItemPool() ); 319 320 aSet.Put( XFillStyleItem( XFILL_SOLID ) ); 321 aSet.Put( XFillColorItem( String(), TRANSCOL ) ); 322 323 if ( !pIMapObj->IsActive() ) 324 { 325 aSet.Put( XFillTransparenceItem( 100 ) ); 326 aSet.Put( XLineColorItem( String(), Color( COL_RED ) ) ); 327 } 328 else 329 { 330 aSet.Put( XFillTransparenceItem( 50 ) ); 331 aSet.Put( XLineColorItem( String(), Color( COL_BLACK ) ) ); 332 } 333 334 //pSdrObj->SetItemSetAndBroadcast(aSet); 335 pSdrObj->SetMergedItemSetAndBroadcast(aSet); 336 337 pSdrObj->InsertUserData( new IMapUserData( pCloneIMapObj ) ); 338 pSdrObj->SetUserCall( GetSdrUserCall() ); 339 } 340 341 return pSdrObj; 342 } 343 344 /************************************************************************* 345 |* 346 |* 347 |* 348 \************************************************************************/ 349 350 void IMapWindow::InitSdrModel() 351 { 352 GraphCtrl::InitSdrModel(); 353 354 SfxItemSet aSet( pModel->GetItemPool() ); 355 356 aSet.Put( XFillColorItem( String(), TRANSCOL ) ); 357 aSet.Put( XFillTransparenceItem( 50 ) ); 358 pView->SetAttributes( aSet ); 359 pView->SetFrameDragSingles( sal_True ); 360 } 361 362 /************************************************************************* 363 |* 364 |* 365 |* 366 \************************************************************************/ 367 368 void IMapWindow::SdrObjCreated( const SdrObject& rObj ) 369 { 370 switch( rObj.GetObjIdentifier() ) 371 { 372 case( OBJ_RECT ): 373 { 374 SdrRectObj* pRectObj = (SdrRectObj*) &rObj; 375 IMapRectangleObject* pObj = new IMapRectangleObject( pRectObj->GetLogicRect(), 376 String(), String(), String(), String(), String(), sal_True, sal_False ); 377 378 pRectObj->InsertUserData( new IMapUserData( IMapObjectPtr(pObj) ) ); 379 } 380 break; 381 382 case( OBJ_CIRC ): 383 { 384 SdrCircObj* pCircObj = (SdrCircObj*) &rObj; 385 SdrPathObj* pPathObj = (SdrPathObj*) pCircObj->ConvertToPolyObj( sal_False, sal_False ); 386 Polygon aPoly(pPathObj->GetPathPoly().getB2DPolygon(0L)); 387 delete pPathObj; 388 389 IMapPolygonObject* pObj = new IMapPolygonObject( Polygon(aPoly), String(), String(), String(), String(), String(), sal_True, sal_False ); 390 pObj->SetExtraEllipse( aPoly.GetBoundRect() ); 391 pCircObj->InsertUserData( new IMapUserData( IMapObjectPtr(pObj) ) ); 392 } 393 break; 394 395 case( OBJ_POLY ): 396 case( OBJ_FREEFILL ): 397 case( OBJ_PATHPOLY ): 398 case( OBJ_PATHFILL ): 399 { 400 SdrPathObj* pPathObj = (SdrPathObj*) &rObj; 401 const basegfx::B2DPolyPolygon& rXPolyPoly = pPathObj->GetPathPoly(); 402 403 if ( rXPolyPoly.count() ) 404 { 405 Polygon aPoly(rXPolyPoly.getB2DPolygon(0L)); 406 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, String(), String(), String(), String(), String(), sal_True, sal_False ); 407 pPathObj->InsertUserData( new IMapUserData( IMapObjectPtr(pObj) ) ); 408 } 409 } 410 break; 411 412 default: 413 break; 414 } 415 } 416 417 /************************************************************************* 418 |* 419 |* 420 |* 421 \************************************************************************/ 422 423 void IMapWindow::SdrObjChanged( const SdrObject& rObj ) 424 { 425 IMapUserData* pUserData = (IMapUserData*) rObj.GetUserData( 0 ); 426 427 if ( pUserData ) 428 { 429 String aURL; 430 String aAltText; 431 String aDesc; 432 String aTarget; 433 IMapObjectPtr pIMapObj = pUserData->GetObject(); 434 sal_Bool bActive = sal_True; 435 436 if ( pIMapObj.get() ) 437 { 438 aURL = pIMapObj->GetURL(); 439 aAltText = pIMapObj->GetAltText(); 440 aDesc = pIMapObj->GetDesc(); 441 aTarget = pIMapObj->GetTarget(); 442 bActive = pIMapObj->IsActive(); 443 } 444 445 switch( rObj.GetObjIdentifier() ) 446 { 447 case( OBJ_RECT ): 448 { 449 pUserData->ReplaceObject( IMapObjectPtr(new IMapRectangleObject( ( (const SdrRectObj&) rObj ).GetLogicRect(), 450 aURL, aAltText, aDesc, aTarget, String(), bActive, sal_False ) ) ); 451 } 452 break; 453 454 case( OBJ_CIRC ): 455 { 456 const SdrCircObj& rCircObj = (const SdrCircObj&) rObj; 457 SdrPathObj* pPathObj = (SdrPathObj*) rCircObj.ConvertToPolyObj( sal_False, sal_False ); 458 Polygon aPoly(pPathObj->GetPathPoly().getB2DPolygon(0L)); 459 460 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, String(), bActive, sal_False ); 461 pObj->SetExtraEllipse( aPoly.GetBoundRect() ); 462 463 // wurde von uns nur temporaer angelegt 464 delete pPathObj; 465 pUserData->ReplaceObject( IMapObjectPtr(pObj) ); 466 } 467 break; 468 469 case( OBJ_POLY ): 470 case( OBJ_FREEFILL ): 471 case( OBJ_PATHPOLY ): 472 case( OBJ_PATHFILL ): 473 { 474 const SdrPathObj& rPathObj = (const SdrPathObj&) rObj; 475 const basegfx::B2DPolyPolygon& rXPolyPoly = rPathObj.GetPathPoly(); 476 477 if ( rXPolyPoly.count() ) 478 { 479 Polygon aPoly(rPathObj.GetPathPoly().getB2DPolygon(0L)); 480 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, String(), bActive, sal_False ); 481 pUserData->ReplaceObject( IMapObjectPtr(pObj) ); 482 } 483 } 484 break; 485 486 default: 487 break; 488 } 489 } 490 } 491 492 /************************************************************************* 493 |* 494 |* 495 |* 496 \************************************************************************/ 497 498 void IMapWindow::MouseButtonUp(const MouseEvent& rMEvt) 499 { 500 GraphCtrl::MouseButtonUp( rMEvt ); 501 UpdateInfo( sal_True ); 502 } 503 504 /************************************************************************* 505 |* 506 |* 507 |* 508 \************************************************************************/ 509 510 void IMapWindow::MarkListHasChanged() 511 { 512 GraphCtrl::MarkListHasChanged(); 513 UpdateInfo( sal_False ); 514 } 515 516 /************************************************************************* 517 |* 518 |* 519 |* 520 \************************************************************************/ 521 522 SdrObject* IMapWindow::GetHitSdrObj( const Point& rPosPixel ) const 523 { 524 SdrObject* pObj = NULL; 525 Point aPt = PixelToLogic( rPosPixel ); 526 527 if ( Rectangle( Point(), GetGraphicSize() ).IsInside( aPt ) ) 528 { 529 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 ); 530 sal_uIntPtr nCount; 531 532 if ( pPage && ( ( nCount = pPage->GetObjCount() ) > 0 ) ) 533 { 534 for ( long i = nCount - 1; i >= 0; i-- ) 535 { 536 SdrObject* pTestObj = pPage->GetObj( i ); 537 IMapObject* pIMapObj = GetIMapObj( pTestObj ); 538 539 if ( pIMapObj && pIMapObj->IsHit( aPt ) ) 540 { 541 pObj = pTestObj; 542 break; 543 } 544 } 545 } 546 } 547 548 return pObj; 549 } 550 551 /************************************************************************* 552 |* 553 |* 554 |* 555 \************************************************************************/ 556 557 IMapObject* IMapWindow::GetIMapObj( const SdrObject* pSdrObj ) const 558 { 559 IMapObject* pIMapObj = NULL; 560 561 if ( pSdrObj ) 562 { 563 IMapUserData* pUserData = (IMapUserData*) pSdrObj->GetUserData( 0 ); 564 565 if ( pUserData ) 566 pIMapObj = pUserData->GetObject().get(); 567 } 568 569 return pIMapObj; 570 } 571 572 /************************************************************************* 573 |* 574 |* 575 |* 576 \************************************************************************/ 577 578 SdrObject* IMapWindow::GetSdrObj( const IMapObject* pIMapObj ) const 579 { 580 SdrObject* pSdrObj = NULL; 581 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 ); 582 sal_uIntPtr nCount; 583 584 if ( pPage && ( ( nCount = pPage->GetObjCount() ) > 0 ) ) 585 { 586 for ( sal_uIntPtr i = 0; i < nCount; i++ ) 587 { 588 SdrObject* pTestObj = pPage->GetObj( i ); 589 590 if ( pIMapObj == GetIMapObj( pTestObj ) ) 591 { 592 pSdrObj = pTestObj; 593 break; 594 } 595 } 596 } 597 598 return pSdrObj; 599 } 600 601 /************************************************************************* 602 |* 603 |* 604 |* 605 \************************************************************************/ 606 607 void IMapWindow::Command(const CommandEvent& rCEvt) 608 { 609 Region aRegion; 610 611 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 612 { 613 PopupMenu aMenu( SVX_RES( RID_SVXMN_IMAP ) ); 614 const SdrMarkList& rMarkList = pView->GetMarkedObjectList(); 615 sal_uIntPtr nMarked = rMarkList.GetMarkCount(); 616 617 aMenu.EnableItem( MN_URL, sal_False ); 618 aMenu.EnableItem( MN_ACTIVATE, sal_False ); 619 aMenu.EnableItem( MN_MACRO, sal_False ); 620 aMenu.EnableItem( MN_MARK_ALL, pModel->GetPage( 0 )->GetObjCount() != pView->GetMarkedObjectCount() ); 621 622 if ( !nMarked ) 623 { 624 aMenu.EnableItem( MN_POSITION, sal_False ); 625 aMenu.EnableItem( MN_FRAME_TO_TOP, sal_False ); 626 aMenu.EnableItem( MN_MOREFRONT, sal_False ); 627 aMenu.EnableItem( MN_MOREBACK, sal_False ); 628 aMenu.EnableItem( MN_FRAME_TO_BOTTOM, sal_False ); 629 aMenu.EnableItem( MN_DELETE1, sal_False ); 630 } 631 else 632 { 633 if ( nMarked == 1 ) 634 { 635 SdrObject* pSdrObj = GetSelectedSdrObject(); 636 637 aMenu.EnableItem( MN_URL, sal_True ); 638 aMenu.EnableItem( MN_ACTIVATE, sal_True ); 639 aMenu.EnableItem( MN_MACRO, sal_True ); 640 aMenu.CheckItem( MN_ACTIVATE, GetIMapObj( pSdrObj )->IsActive() ); 641 } 642 643 aMenu.EnableItem( MN_POSITION, sal_True ); 644 aMenu.EnableItem( MN_FRAME_TO_TOP, sal_True ); 645 aMenu.EnableItem( MN_MOREFRONT, sal_True ); 646 aMenu.EnableItem( MN_MOREBACK, sal_True ); 647 aMenu.EnableItem( MN_FRAME_TO_BOTTOM, sal_True ); 648 aMenu.EnableItem( MN_DELETE1, sal_True ); 649 } 650 651 aMenu.SetSelectHdl( LINK( this, IMapWindow, MenuSelectHdl ) ); 652 aMenu.Execute( this, rCEvt.GetMousePosPixel() ); 653 } 654 else 655 Window::Command(rCEvt); 656 } 657 658 /************************************************************************* 659 |* 660 |* 661 |* 662 \************************************************************************/ 663 664 sal_Int8 IMapWindow::AcceptDrop( const AcceptDropEvent& rEvt ) 665 { 666 return( ( GetHitSdrObj( rEvt.maPosPixel ) != NULL ) ? rEvt.mnAction : DND_ACTION_NONE ); 667 } 668 669 /************************************************************************* 670 |* 671 |* 672 |* 673 \************************************************************************/ 674 675 sal_Int8 IMapWindow::ExecuteDrop( const ExecuteDropEvent& rEvt ) 676 { 677 sal_Int8 nRet = DND_ACTION_NONE; 678 679 if( IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) ) 680 { 681 const String aString; 682 INetBookmark aBookMark( aString, aString ); 683 SdrObject* pSdrObj = GetHitSdrObj( rEvt.maPosPixel ); 684 685 if( pSdrObj && TransferableDataHelper( rEvt.maDropEvent.Transferable ).GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aBookMark ) ) 686 { 687 IMapObject* pIMapObj = GetIMapObj( pSdrObj ); 688 689 pIMapObj->SetURL( aBookMark.GetURL() ); 690 pIMapObj->SetAltText( aBookMark.GetDescription() ); 691 pModel->SetChanged( sal_True ); 692 pView->UnmarkAll(); 693 pView->MarkObj( pSdrObj, pView->GetSdrPageView() ); 694 UpdateInfo( sal_True ); 695 nRet = rEvt.mnAction; 696 } 697 } 698 699 return nRet; 700 } 701 702 /************************************************************************* 703 |* 704 |* 705 |* 706 \************************************************************************/ 707 708 void IMapWindow::RequestHelp( const HelpEvent& rHEvt ) 709 { 710 SdrObject* pSdrObj = NULL; 711 SdrPageView* pPageView = NULL; 712 Point aPos = PixelToLogic( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) ); 713 714 if ( Help::IsBalloonHelpEnabled() || Help::IsQuickHelpEnabled() ) 715 { 716 if ( pView->PickObj( aPos, pView->getHitTolLog(), pSdrObj, pPageView ) ) 717 { 718 const IMapObject* pIMapObj = GetIMapObj( pSdrObj ); 719 String aStr; 720 721 if ( pIMapObj && ( aStr = pIMapObj->GetURL() ).Len() ) 722 { 723 String aDescr( pIMapObj->GetAltText() ); 724 Rectangle aLogicPix( LogicToPixel( Rectangle( Point(), GetGraphicSize() ) ) ); 725 Rectangle aScreenRect( OutputToScreenPixel( aLogicPix.TopLeft() ), 726 OutputToScreenPixel( aLogicPix.BottomRight() ) ); 727 728 if ( Help::IsBalloonHelpEnabled() ) 729 Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), aScreenRect, aStr ); 730 else if ( Help::IsQuickHelpEnabled() ) 731 Help::ShowQuickHelp( this, aScreenRect, aStr ); 732 } 733 } 734 else 735 Window::RequestHelp( rHEvt ); 736 } 737 } 738 739 /************************************************************************* 740 |* 741 |* 742 |* 743 \************************************************************************/ 744 745 void IMapWindow::SetCurrentObjState( sal_Bool bActive ) 746 { 747 SdrObject* pObj = GetSelectedSdrObject(); 748 749 if ( pObj ) 750 { 751 SfxItemSet aSet( pModel->GetItemPool() ); 752 753 GetIMapObj( pObj )->SetActive( bActive ); 754 755 aSet.Put( XFillColorItem( String(), TRANSCOL ) ); 756 757 if ( !bActive ) 758 { 759 aSet.Put( XFillTransparenceItem( 100 ) ); 760 aSet.Put( XLineColorItem( String(), Color( COL_RED ) ) ); 761 } 762 else 763 { 764 aSet.Put( XFillTransparenceItem( 50 ) ); 765 aSet.Put( XLineColorItem( String(), Color( COL_BLACK ) ) ); 766 } 767 768 pView->SetAttributes( aSet, sal_False ); 769 } 770 } 771 772 /************************************************************************* 773 |* 774 |* 775 |* 776 \************************************************************************/ 777 778 void IMapWindow::UpdateInfo( sal_Bool bNewObj ) 779 { 780 if ( aInfoLink.IsSet() ) 781 { 782 const SdrObject* pSdrObj = GetSelectedSdrObject(); 783 const IMapObject* pIMapObj = pSdrObj ? GetIMapObj( pSdrObj ) : NULL; 784 785 aInfo.bNewObj = bNewObj; 786 787 if ( pIMapObj ) 788 { 789 aInfo.bOneMarked = sal_True; 790 aInfo.aMarkURL = pIMapObj->GetURL(); 791 aInfo.aMarkAltText = pIMapObj->GetAltText(); 792 aInfo.aMarkTarget = pIMapObj->GetTarget(); 793 aInfo.bActivated = pIMapObj->IsActive(); 794 aInfoLink.Call( this ); 795 } 796 else 797 { 798 aInfo.aMarkURL = aInfo.aMarkAltText = aInfo.aMarkTarget = String(); 799 aInfo.bOneMarked = sal_False; 800 aInfo.bActivated = sal_False; 801 } 802 803 aInfoLink.Call( this ); 804 } 805 } 806 807 /************************************************************************* 808 |* 809 |* 810 |* 811 \************************************************************************/ 812 813 void IMapWindow::DoMacroAssign() 814 { 815 SdrObject* pSdrObj = GetSelectedSdrObject(); 816 817 if ( pSdrObj ) 818 { 819 SfxItemSet aSet( *pIMapPool, SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 ); 820 821 SfxEventNamesItem aNamesItem(SID_EVENTCONFIG); 822 aNamesItem.AddEvent( String::CreateFromAscii( "MouseOver" ), String(), SFX_EVENT_MOUSEOVER_OBJECT ); 823 aNamesItem.AddEvent( String::CreateFromAscii( "MouseOut" ), String(), SFX_EVENT_MOUSEOUT_OBJECT ); 824 aSet.Put( aNamesItem ); 825 826 SvxMacroItem aMacroItem(SID_ATTR_MACROITEM); 827 IMapObject* pIMapObj = GetIMapObj( pSdrObj ); 828 aMacroItem.SetMacroTable( pIMapObj->GetMacroTable() ); 829 aSet.Put( aMacroItem, SID_ATTR_MACROITEM ); 830 831 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 832 SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( this, aSet, mxDocumentFrame, SID_EVENTCONFIG ); 833 834 if ( pMacroDlg && pMacroDlg->Execute() == RET_OK ) 835 { 836 const SfxItemSet* pOutSet = pMacroDlg->GetOutputItemSet(); 837 pIMapObj->SetMacroTable( ((const SvxMacroItem& )pOutSet->Get( SID_ATTR_MACROITEM )).GetMacroTable() ); 838 pModel->SetChanged( sal_True ); 839 UpdateInfo( sal_False ); 840 } 841 842 delete pMacroDlg; 843 } 844 } 845 846 /************************************************************************* 847 |* 848 |* 849 |* 850 \************************************************************************/ 851 852 void IMapWindow::DoPropertyDialog() 853 { 854 SdrObject* pSdrObj = GetSelectedSdrObject(); 855 856 if ( pSdrObj ) 857 { 858 IMapObject* pIMapObj = GetIMapObj( pSdrObj ); 859 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 860 if(pFact) 861 { 862 AbstractURLDlg* aDlg = pFact->CreateURLDialog( this, pIMapObj->GetURL(), pIMapObj->GetAltText(), pIMapObj->GetDesc(), 863 pIMapObj->GetTarget(), pIMapObj->GetName(), aTargetList ); 864 DBG_ASSERT(aDlg, "Dialogdiet fail!"); 865 if ( aDlg->Execute() == RET_OK ) 866 { 867 const String aURLText( aDlg->GetURL() ); 868 869 if ( aURLText.Len() ) 870 { 871 INetURLObject aObj( aURLText, INET_PROT_FILE ); 872 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL" ); 873 pIMapObj->SetURL( aObj.GetMainURL( INetURLObject::NO_DECODE ) ); 874 } 875 else 876 pIMapObj->SetURL( aURLText ); 877 878 pIMapObj->SetAltText( aDlg->GetAltText() ); 879 pIMapObj->SetDesc( aDlg->GetDesc() ); 880 pIMapObj->SetTarget( aDlg->GetTarget() ); 881 pIMapObj->SetName( aDlg->GetName() ); 882 pModel->SetChanged( sal_True ); 883 UpdateInfo( sal_True ); 884 } 885 delete aDlg; //add by CHINA001 886 } 887 } 888 } 889 890 /************************************************************************* 891 |* 892 |* 893 |* 894 \************************************************************************/ 895 896 IMPL_LINK( IMapWindow, MenuSelectHdl, Menu*, pMenu ) 897 { 898 if (pMenu) 899 { 900 sal_uInt16 nId = pMenu->GetCurItemId(); 901 902 switch(nId) 903 { 904 case( MN_URL ): 905 DoPropertyDialog(); 906 break; 907 908 case( MN_MACRO ): 909 DoMacroAssign(); 910 break; 911 912 case( MN_ACTIVATE ): 913 { 914 const sal_Bool bNewState = !pMenu->IsItemChecked( MN_ACTIVATE ); 915 916 pMenu->CheckItem( MN_ACTIVATE, bNewState ); 917 SetCurrentObjState( bNewState ); 918 UpdateInfo( sal_False ); 919 } 920 921 case( MN_FRAME_TO_TOP ): 922 pView->PutMarkedToTop(); 923 break; 924 925 case( MN_MOREFRONT ): 926 pView->MovMarkedToTop(); 927 break; 928 929 case( MN_MOREBACK ): 930 pView->MovMarkedToBtm(); 931 break; 932 933 case( MN_FRAME_TO_BOTTOM ): 934 pView->PutMarkedToBtm(); 935 break; 936 937 case( MN_MARK_ALL ): 938 pView->MarkAll(); 939 break; 940 941 case( MN_DELETE1 ): 942 pView->DeleteMarked(); 943 944 default : 945 break; 946 } 947 } 948 949 return 0; 950 } 951 952 void IMapWindow::CreateDefaultObject() 953 { 954 SdrPageView* pPageView = pView->GetSdrPageView(); 955 956 if(pPageView) 957 { 958 // calc position and size 959 Point aPagePos(0, 0); // = pPageView->GetOffset(); 960 Size aPageSize = pPageView->GetPage()->GetSize(); 961 sal_uInt32 nDefaultObjectSizeWidth = aPageSize.Width() / 4; 962 sal_uInt32 nDefaultObjectSizeHeight = aPageSize.Height() / 4; 963 aPagePos.X() += (aPageSize.Width() / 2) - (nDefaultObjectSizeWidth / 2); 964 aPagePos.Y() += (aPageSize.Height() / 2) - (nDefaultObjectSizeHeight / 2); 965 Rectangle aNewObjectRectangle(aPagePos, Size(nDefaultObjectSizeWidth, nDefaultObjectSizeHeight)); 966 967 SdrObject* pObj = SdrObjFactory::MakeNewObject( pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(), 0L, pModel); 968 pObj->SetLogicRect(aNewObjectRectangle); 969 970 switch( pObj->GetObjIdentifier() ) 971 { 972 case OBJ_POLY: 973 case OBJ_PATHPOLY: 974 { 975 basegfx::B2DPolygon aInnerPoly; 976 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.BottomLeft().X(), aNewObjectRectangle.BottomLeft().Y())); 977 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.TopLeft().X(), aNewObjectRectangle.TopLeft().Y())); 978 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.TopCenter().X(), aNewObjectRectangle.TopCenter().Y())); 979 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.Center().X(), aNewObjectRectangle.Center().Y())); 980 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.RightCenter().X(), aNewObjectRectangle.RightCenter().Y())); 981 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.BottomRight().X(), aNewObjectRectangle.BottomRight().Y())); 982 aInnerPoly.setClosed(true); 983 ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aInnerPoly)); 984 break; 985 } 986 case OBJ_FREEFILL: 987 case OBJ_PATHFILL: 988 { 989 sal_Int32 nWdt(aNewObjectRectangle.GetWidth() / 2); 990 sal_Int32 nHgt(aNewObjectRectangle.GetHeight() / 2); 991 basegfx::B2DPolygon aInnerPoly(XPolygon(aNewObjectRectangle.Center(), nWdt, nHgt).getB2DPolygon()); 992 ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aInnerPoly)); 993 break; 994 } 995 996 } 997 998 pView->InsertObjectAtView(pObj, *pPageView); 999 SdrObjCreated( *pObj ); 1000 SetCurrentObjState( true ); 1001 pView->MarkObj( pObj, pPageView ); 1002 } 1003 } 1004 1005 void IMapWindow::KeyInput( const KeyEvent& rKEvt ) 1006 { 1007 KeyCode aCode = rKEvt.GetKeyCode(); 1008 1009 /* 1010 switch(aCode.GetCode()) 1011 { 1012 case KEY_ESCAPE: 1013 { 1014 if ( pView->IsAction() ) 1015 { 1016 pView->BrkAction(); 1017 return; 1018 } 1019 else if ( pView->AreObjectsMarked() ) 1020 { 1021 const SdrHdlList& rHdlList = pView->GetHdlList(); 1022 SdrHdl* pHdl = rHdlList.GetFocusHdl(); 1023 1024 if(pHdl) 1025 { 1026 ((SdrHdlList&)rHdlList).ResetFocusHdl(); 1027 } 1028 else 1029 { 1030 pView->UnmarkAllObj(); 1031 ((Dialog*)GetParent())->GrabFocusToFirstControl(); 1032 } 1033 1034 return; 1035 } 1036 } 1037 break; 1038 1039 } 1040 */ 1041 GraphCtrl::KeyInput( rKEvt ); 1042 } 1043 1044 void IMapWindow::SelectFirstObject() 1045 { 1046 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 ); 1047 if( pPage->GetObjCount() != 0 ) 1048 { 1049 GrabFocus(); 1050 pView->UnmarkAllObj(); 1051 pView->MarkNextObj(sal_True); 1052 } 1053 } 1054 1055 void IMapWindow::StartPolyEdit() 1056 { 1057 GrabFocus(); 1058 1059 if( !pView->AreObjectsMarked() ) 1060 pView->MarkNextObj(sal_True); 1061 1062 const SdrHdlList& rHdlList = pView->GetHdlList(); 1063 SdrHdl* pHdl = rHdlList.GetFocusHdl(); 1064 1065 if(!pHdl) 1066 { 1067 ((SdrHdlList&)rHdlList).TravelFocusHdl(true); 1068 } 1069 } 1070