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