Update ooo320-m1
[ooovba.git] / svx / source / dialog / imapwnd.cxx
blob85fe1b9057243b66dfd6407a743d025c94c6bd51
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: imapwnd.cxx,v $
10 * $Revision: 1.26 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <tools/urlobj.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <vcl/help.hxx>
36 #include <sfx2/sfxsids.hrc> // SID_ATTR_MACROITEM
37 #define _ANIMATION
38 #include <svtools/imaprect.hxx>
39 #include <svtools/imapcirc.hxx>
40 #include <svtools/imappoly.hxx>
41 #include <svtools/urlbmk.hxx>
43 #include <xoutbmp.hxx>
44 #include <svx/dialmgr.hxx>
45 #include <svx/dialogs.hrc>
46 #include <svx/svxids.hrc>
47 #include <imapdlg.hrc>
48 #include <imapwnd.hxx>
49 #include <svx/svdpage.hxx>
50 #include <svx/svdorect.hxx>
51 #include <svx/svdocirc.hxx>
52 #include <svx/svdopath.hxx>
53 #include <svx/xfltrit.hxx>
54 #include <svx/svdpagv.hxx>
55 #include <svtools/urihelper.hxx>
56 #include <svx/xfillit.hxx>
57 #include <svx/xlineit.hxx>
58 #include <sfx2/evntconf.hxx>
60 #include <sot/formats.hxx>
62 #include <svx/svxdlg.hxx>
63 #include <svx/dialogs.hrc>
64 #include <basegfx/point/b2dpoint.hxx>
65 #include <basegfx/polygon/b2dpolygon.hxx>
67 using ::com::sun::star::frame::XFrame;
68 using ::com::sun::star::uno::Reference;
70 #define TRANSCOL Color( COL_WHITE )
72 /*************************************************************************
76 \************************************************************************/
78 IMapWindow::IMapWindow( Window* pParent, const ResId& rResId, const Reference< XFrame >& rxDocumentFrame ) :
79 GraphCtrl( pParent, rResId ),
80 DropTargetHelper( this ),
81 mxDocumentFrame( rxDocumentFrame )
83 SetWinStyle( WB_SDRMODE );
85 pItemInfo = new SfxItemInfo[ 1 ];
86 memset( pItemInfo, 0, sizeof( SfxItemInfo ) );
87 pIMapPool = new SfxItemPool( String::CreateFromAscii( "IMapItemPool" ),
88 SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, pItemInfo );
89 pIMapPool->FreezeIdRanges();
92 /*************************************************************************
96 \************************************************************************/
98 IMapWindow::~IMapWindow()
100 // Liste loeschen
101 for( String* pStr = aTargetList.First(); pStr; pStr = aTargetList.Next() )
102 delete pStr;
104 SfxItemPool::Free(pIMapPool);
105 delete[] pItemInfo;
108 /*************************************************************************
112 \************************************************************************/
114 void IMapWindow::SetImageMap( const ImageMap& rImageMap )
116 ReplaceImageMap( rImageMap, FALSE );
119 /*************************************************************************
123 \************************************************************************/
125 void IMapWindow::ReplaceImageMap( const ImageMap& rImageMap, BOOL /*bScaleToGraphic*/ )
127 SdrPage* pPage = 0;
128 aIMap = rImageMap;
130 if(GetSdrModel())
132 // try to access page
133 pPage = GetSdrModel()->GetPage(0L);
136 if(pPage)
138 // clear all draw objects
139 pPage->Clear();
142 if(GetSdrView())
144 // #i63762# reset selection at view
145 GetSdrView()->UnmarkAllObj();
148 // create new drawing objects
149 const USHORT nCount(rImageMap.GetIMapObjectCount());
151 for ( USHORT i(nCount); i > 0; i-- )
153 SdrObject* pNewObj = CreateObj( rImageMap.GetIMapObject( i - 1 ) );
155 if ( pNewObj )
157 pPage->InsertObject( pNewObj );
162 /*************************************************************************
166 \************************************************************************/
168 BOOL IMapWindow::ReplaceActualIMapInfo( const NotifyInfo& rNewInfo )
170 const SdrObject* pSdrObj = GetSelectedSdrObject();
171 IMapObject* pIMapObj;
172 BOOL bRet = FALSE;
174 if ( pSdrObj && ( ( pIMapObj = GetIMapObj( pSdrObj ) ) != NULL ) )
176 pIMapObj->SetURL( rNewInfo.aMarkURL );
177 pIMapObj->SetAltText( rNewInfo.aMarkAltText );
178 pIMapObj->SetTarget( rNewInfo.aMarkTarget );
179 pModel->SetChanged( sal_True );
180 UpdateInfo( FALSE );
182 bRet = TRUE;
185 return bRet;
188 /*************************************************************************
192 \************************************************************************/
194 const ImageMap& IMapWindow::GetImageMap()
196 if ( pModel->IsChanged() )
198 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
200 if ( pPage )
202 const long nCount = pPage->GetObjCount();
204 aIMap.ClearImageMap();
206 for ( long i = nCount - 1; i > -1; i-- )
207 aIMap.InsertIMapObject( *( ( (IMapUserData*) pPage->GetObj( i )->GetUserData( 0 ) )->GetObject() ) );
210 pModel->SetChanged( sal_False );
213 return aIMap;
216 /*************************************************************************
220 \************************************************************************/
222 void IMapWindow::SetTargetList( TargetList& rTargetList )
224 String* pStr;
226 // alte Liste loeschen
227 for( pStr = aTargetList.First(); pStr; pStr = aTargetList.Next() )
228 delete pStr;
230 aTargetList.Clear();
232 // mit uebergebener Liste fuellen
233 for( pStr = rTargetList.First(); pStr; pStr = rTargetList.Next() )
234 aTargetList.Insert( new String( *pStr ) );
236 pModel->SetChanged( sal_False );
239 /*************************************************************************
243 \************************************************************************/
245 SdrObject* IMapWindow::CreateObj( const IMapObject* pIMapObj )
247 Point aPoint;
248 Rectangle aClipRect( aPoint, GetGraphicSize() );
249 SdrObject* pSdrObj = NULL;
250 IMapObjectPtr pCloneIMapObj;
252 switch( pIMapObj->GetType() )
254 case( IMAP_OBJ_RECTANGLE ):
256 IMapRectangleObject* pIMapRectObj = (IMapRectangleObject*) pIMapObj;
257 Rectangle aDrawRect( pIMapRectObj->GetRectangle( FALSE ) );
259 // auf Zeichenflaeche clippen
260 aDrawRect.Intersection( aClipRect );
262 pSdrObj = (SdrObject*) new SdrRectObj( aDrawRect );
263 pCloneIMapObj.reset((IMapObject*) new IMapRectangleObject( *pIMapRectObj ));
265 break;
267 case( IMAP_OBJ_CIRCLE ):
269 IMapCircleObject* pIMapCircleObj = (IMapCircleObject*) pIMapObj;
270 const Point aCenter( pIMapCircleObj->GetCenter( FALSE ) );
271 const long nRadius = pIMapCircleObj->GetRadius( FALSE );
272 const Point aOffset( nRadius, nRadius );
273 Rectangle aCircle( aCenter - aOffset, aCenter + aOffset );
275 // auf Zeichenflaeche begrenzen
276 aCircle.Intersection( aClipRect );
278 pSdrObj = (SdrObject*) new SdrCircObj( OBJ_CIRC, aCircle, 0, 36000 );
279 pCloneIMapObj.reset((IMapObject*) new IMapCircleObject( *pIMapCircleObj ));
281 break;
283 case( IMAP_OBJ_POLYGON ):
285 IMapPolygonObject* pIMapPolyObj = (IMapPolygonObject*) pIMapObj;
287 // Falls wir eigentlich eine Ellipse sind,
288 // erzeugen wir auch wieder eine Ellipse
289 if ( pIMapPolyObj->HasExtraEllipse() )
291 Rectangle aDrawRect( pIMapPolyObj->GetExtraEllipse() );
293 // auf Zeichenflaeche clippen
294 aDrawRect.Intersection( aClipRect );
296 pSdrObj = (SdrObject*) new SdrCircObj( OBJ_CIRC, aDrawRect, 0, 36000 );
298 else
300 const Polygon& rPoly = pIMapPolyObj->GetPolygon( FALSE );
301 Polygon aDrawPoly( rPoly );
303 // auf Zeichenflaeche clippen
304 aDrawPoly.Clip( aClipRect );
306 basegfx::B2DPolygon aPolygon;
307 aPolygon.append(aDrawPoly.getB2DPolygon());
308 pSdrObj = (SdrObject*)new SdrPathObj(OBJ_POLY, basegfx::B2DPolyPolygon(aPolygon));
311 pCloneIMapObj.reset((IMapObject*) new IMapPolygonObject( *pIMapPolyObj ));
313 break;
315 default:
316 break;
319 if ( pSdrObj )
321 SfxItemSet aSet( pModel->GetItemPool() );
323 aSet.Put( XFillStyleItem( XFILL_SOLID ) );
324 aSet.Put( XFillColorItem( String(), TRANSCOL ) );
326 if ( !pIMapObj->IsActive() )
328 aSet.Put( XFillTransparenceItem( 100 ) );
329 aSet.Put( XLineColorItem( String(), Color( COL_RED ) ) );
331 else
333 aSet.Put( XFillTransparenceItem( 50 ) );
334 aSet.Put( XLineColorItem( String(), Color( COL_BLACK ) ) );
337 //pSdrObj->SetItemSetAndBroadcast(aSet);
338 pSdrObj->SetMergedItemSetAndBroadcast(aSet);
340 pSdrObj->InsertUserData( new IMapUserData( pCloneIMapObj ) );
341 pSdrObj->SetUserCall( GetSdrUserCall() );
344 return pSdrObj;
347 /*************************************************************************
351 \************************************************************************/
353 void IMapWindow::InitSdrModel()
355 GraphCtrl::InitSdrModel();
357 SfxItemSet aSet( pModel->GetItemPool() );
359 aSet.Put( XFillColorItem( String(), TRANSCOL ) );
360 aSet.Put( XFillTransparenceItem( 50 ) );
361 pView->SetAttributes( aSet );
362 pView->SetFrameDragSingles( TRUE );
365 /*************************************************************************
369 \************************************************************************/
371 void IMapWindow::SdrObjCreated( const SdrObject& rObj )
373 switch( rObj.GetObjIdentifier() )
375 case( OBJ_RECT ):
377 SdrRectObj* pRectObj = (SdrRectObj*) &rObj;
378 IMapRectangleObject* pObj = new IMapRectangleObject( pRectObj->GetLogicRect(),
379 String(), String(), String(), String(), String(), TRUE, FALSE );
381 pRectObj->InsertUserData( new IMapUserData( IMapObjectPtr(pObj) ) );
383 break;
385 case( OBJ_CIRC ):
387 SdrCircObj* pCircObj = (SdrCircObj*) &rObj;
388 SdrPathObj* pPathObj = (SdrPathObj*) pCircObj->ConvertToPolyObj( FALSE, FALSE );
389 Polygon aPoly(pPathObj->GetPathPoly().getB2DPolygon(0L));
390 delete pPathObj;
392 IMapPolygonObject* pObj = new IMapPolygonObject( Polygon(aPoly), String(), String(), String(), String(), String(), TRUE, FALSE );
393 pObj->SetExtraEllipse( aPoly.GetBoundRect() );
394 pCircObj->InsertUserData( new IMapUserData( IMapObjectPtr(pObj) ) );
396 break;
398 case( OBJ_POLY ):
399 case( OBJ_FREEFILL ):
400 case( OBJ_PATHPOLY ):
401 case( OBJ_PATHFILL ):
403 SdrPathObj* pPathObj = (SdrPathObj*) &rObj;
404 const basegfx::B2DPolyPolygon& rXPolyPoly = pPathObj->GetPathPoly();
406 if ( rXPolyPoly.count() )
408 Polygon aPoly(rXPolyPoly.getB2DPolygon(0L));
409 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, String(), String(), String(), String(), String(), TRUE, FALSE );
410 pPathObj->InsertUserData( new IMapUserData( IMapObjectPtr(pObj) ) );
413 break;
415 default:
416 break;
420 /*************************************************************************
424 \************************************************************************/
426 void IMapWindow::SdrObjChanged( const SdrObject& rObj )
428 IMapUserData* pUserData = (IMapUserData*) rObj.GetUserData( 0 );
430 if ( pUserData )
432 String aURL;
433 String aAltText;
434 String aDesc;
435 String aTarget;
436 IMapObjectPtr pIMapObj = pUserData->GetObject();
437 BOOL bActive = TRUE;
439 if ( pIMapObj.get() )
441 aURL = pIMapObj->GetURL();
442 aAltText = pIMapObj->GetAltText();
443 aDesc = pIMapObj->GetDesc();
444 aTarget = pIMapObj->GetTarget();
445 bActive = pIMapObj->IsActive();
448 switch( rObj.GetObjIdentifier() )
450 case( OBJ_RECT ):
452 pUserData->ReplaceObject( IMapObjectPtr(new IMapRectangleObject( ( (const SdrRectObj&) rObj ).GetLogicRect(),
453 aURL, aAltText, aDesc, aTarget, String(), bActive, FALSE ) ) );
455 break;
457 case( OBJ_CIRC ):
459 const SdrCircObj& rCircObj = (const SdrCircObj&) rObj;
460 SdrPathObj* pPathObj = (SdrPathObj*) rCircObj.ConvertToPolyObj( FALSE, FALSE );
461 Polygon aPoly(pPathObj->GetPathPoly().getB2DPolygon(0L));
463 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, String(), bActive, FALSE );
464 pObj->SetExtraEllipse( aPoly.GetBoundRect() );
466 // wurde von uns nur temporaer angelegt
467 delete pPathObj;
468 pUserData->ReplaceObject( IMapObjectPtr(pObj) );
470 break;
472 case( OBJ_POLY ):
473 case( OBJ_FREEFILL ):
474 case( OBJ_PATHPOLY ):
475 case( OBJ_PATHFILL ):
477 const SdrPathObj& rPathObj = (const SdrPathObj&) rObj;
478 const basegfx::B2DPolyPolygon& rXPolyPoly = rPathObj.GetPathPoly();
480 if ( rXPolyPoly.count() )
482 Polygon aPoly(rPathObj.GetPathPoly().getB2DPolygon(0L));
483 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, String(), bActive, FALSE );
484 pUserData->ReplaceObject( IMapObjectPtr(pObj) );
487 break;
489 default:
490 break;
495 /*************************************************************************
499 \************************************************************************/
501 void IMapWindow::MouseButtonUp(const MouseEvent& rMEvt)
503 GraphCtrl::MouseButtonUp( rMEvt );
504 UpdateInfo( TRUE );
507 /*************************************************************************
511 \************************************************************************/
513 void IMapWindow::MarkListHasChanged()
515 GraphCtrl::MarkListHasChanged();
516 UpdateInfo( FALSE );
519 /*************************************************************************
523 \************************************************************************/
525 SdrObject* IMapWindow::GetHitSdrObj( const Point& rPosPixel ) const
527 SdrObject* pObj = NULL;
528 Point aPt = PixelToLogic( rPosPixel );
530 if ( Rectangle( Point(), GetGraphicSize() ).IsInside( aPt ) )
532 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
533 ULONG nCount;
535 if ( pPage && ( ( nCount = pPage->GetObjCount() ) > 0 ) )
537 for ( long i = nCount - 1; i >= 0; i-- )
539 SdrObject* pTestObj = pPage->GetObj( i );
540 IMapObject* pIMapObj = GetIMapObj( pTestObj );
542 if ( pIMapObj && pIMapObj->IsHit( aPt ) )
544 pObj = pTestObj;
545 break;
551 return pObj;
554 /*************************************************************************
558 \************************************************************************/
560 IMapObject* IMapWindow::GetIMapObj( const SdrObject* pSdrObj ) const
562 IMapObject* pIMapObj = NULL;
564 if ( pSdrObj )
566 IMapUserData* pUserData = (IMapUserData*) pSdrObj->GetUserData( 0 );
568 if ( pUserData )
569 pIMapObj = pUserData->GetObject().get();
572 return pIMapObj;
575 /*************************************************************************
579 \************************************************************************/
581 SdrObject* IMapWindow::GetSdrObj( const IMapObject* pIMapObj ) const
583 SdrObject* pSdrObj = NULL;
584 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
585 ULONG nCount;
587 if ( pPage && ( ( nCount = pPage->GetObjCount() ) > 0 ) )
589 for ( ULONG i = 0; i < nCount; i++ )
591 SdrObject* pTestObj = pPage->GetObj( i );
593 if ( pIMapObj == GetIMapObj( pTestObj ) )
595 pSdrObj = pTestObj;
596 break;
601 return pSdrObj;
604 /*************************************************************************
608 \************************************************************************/
610 void IMapWindow::Command(const CommandEvent& rCEvt)
612 Region aRegion;
614 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
616 PopupMenu aMenu( SVX_RES( RID_SVXMN_IMAP ) );
617 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
618 ULONG nMarked = rMarkList.GetMarkCount();
620 aMenu.EnableItem( MN_URL, FALSE );
621 aMenu.EnableItem( MN_ACTIVATE, FALSE );
622 aMenu.EnableItem( MN_MACRO, FALSE );
623 aMenu.EnableItem( MN_MARK_ALL, pModel->GetPage( 0 )->GetObjCount() != pView->GetMarkedObjectCount() );
625 if ( !nMarked )
627 aMenu.EnableItem( MN_POSITION, FALSE );
628 aMenu.EnableItem( MN_FRAME_TO_TOP, FALSE );
629 aMenu.EnableItem( MN_MOREFRONT, FALSE );
630 aMenu.EnableItem( MN_MOREBACK, FALSE );
631 aMenu.EnableItem( MN_FRAME_TO_BOTTOM, FALSE );
632 aMenu.EnableItem( MN_DELETE1, FALSE );
634 else
636 if ( nMarked == 1 )
638 SdrObject* pSdrObj = GetSelectedSdrObject();
640 aMenu.EnableItem( MN_URL, TRUE );
641 aMenu.EnableItem( MN_ACTIVATE, TRUE );
642 aMenu.EnableItem( MN_MACRO, TRUE );
643 aMenu.CheckItem( MN_ACTIVATE, GetIMapObj( pSdrObj )->IsActive() );
646 aMenu.EnableItem( MN_POSITION, TRUE );
647 aMenu.EnableItem( MN_FRAME_TO_TOP, TRUE );
648 aMenu.EnableItem( MN_MOREFRONT, TRUE );
649 aMenu.EnableItem( MN_MOREBACK, TRUE );
650 aMenu.EnableItem( MN_FRAME_TO_BOTTOM, TRUE );
651 aMenu.EnableItem( MN_DELETE1, TRUE );
654 aMenu.SetSelectHdl( LINK( this, IMapWindow, MenuSelectHdl ) );
655 aMenu.Execute( this, rCEvt.GetMousePosPixel() );
657 else
658 Window::Command(rCEvt);
661 /*************************************************************************
665 \************************************************************************/
667 sal_Int8 IMapWindow::AcceptDrop( const AcceptDropEvent& rEvt )
669 return( ( GetHitSdrObj( rEvt.maPosPixel ) != NULL ) ? rEvt.mnAction : DND_ACTION_NONE );
672 /*************************************************************************
676 \************************************************************************/
678 sal_Int8 IMapWindow::ExecuteDrop( const ExecuteDropEvent& rEvt )
680 sal_Int8 nRet = DND_ACTION_NONE;
682 if( IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) )
684 const String aString;
685 INetBookmark aBookMark( aString, aString );
686 SdrObject* pSdrObj = GetHitSdrObj( rEvt.maPosPixel );
688 if( pSdrObj && TransferableDataHelper( rEvt.maDropEvent.Transferable ).GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aBookMark ) )
690 IMapObject* pIMapObj = GetIMapObj( pSdrObj );
692 pIMapObj->SetURL( aBookMark.GetURL() );
693 pIMapObj->SetAltText( aBookMark.GetDescription() );
694 pModel->SetChanged( sal_True );
695 pView->UnmarkAll();
696 pView->MarkObj( pSdrObj, pView->GetSdrPageView() );
697 UpdateInfo( TRUE );
698 nRet = rEvt.mnAction;
702 return nRet;
705 /*************************************************************************
709 \************************************************************************/
711 void IMapWindow::RequestHelp( const HelpEvent& rHEvt )
713 SdrObject* pSdrObj = NULL;
714 SdrPageView* pPageView = NULL;
715 Point aPos = PixelToLogic( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
717 if ( Help::IsBalloonHelpEnabled() || Help::IsQuickHelpEnabled() )
719 if ( pView->PickObj( aPos, pView->getHitTolLog(), pSdrObj, pPageView ) )
721 const IMapObject* pIMapObj = GetIMapObj( pSdrObj );
722 String aStr;
724 if ( pIMapObj && ( aStr = pIMapObj->GetURL() ).Len() )
726 String aDescr( pIMapObj->GetAltText() );
727 Rectangle aLogicPix( LogicToPixel( Rectangle( Point(), GetGraphicSize() ) ) );
728 Rectangle aScreenRect( OutputToScreenPixel( aLogicPix.TopLeft() ),
729 OutputToScreenPixel( aLogicPix.BottomRight() ) );
731 if ( Help::IsBalloonHelpEnabled() )
732 Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), aScreenRect, aStr );
733 else if ( Help::IsQuickHelpEnabled() )
734 Help::ShowQuickHelp( this, aScreenRect, aStr );
737 else
738 Window::RequestHelp( rHEvt );
742 /*************************************************************************
746 \************************************************************************/
748 void IMapWindow::SetCurrentObjState( BOOL bActive )
750 SdrObject* pObj = GetSelectedSdrObject();
752 if ( pObj )
754 SfxItemSet aSet( pModel->GetItemPool() );
756 GetIMapObj( pObj )->SetActive( bActive );
758 aSet.Put( XFillColorItem( String(), TRANSCOL ) );
760 if ( !bActive )
762 aSet.Put( XFillTransparenceItem( 100 ) );
763 aSet.Put( XLineColorItem( String(), Color( COL_RED ) ) );
765 else
767 aSet.Put( XFillTransparenceItem( 50 ) );
768 aSet.Put( XLineColorItem( String(), Color( COL_BLACK ) ) );
771 pView->SetAttributes( aSet, FALSE );
775 /*************************************************************************
779 \************************************************************************/
781 void IMapWindow::UpdateInfo( BOOL bNewObj )
783 if ( aInfoLink.IsSet() )
785 const SdrObject* pSdrObj = GetSelectedSdrObject();
786 const IMapObject* pIMapObj = pSdrObj ? GetIMapObj( pSdrObj ) : NULL;
788 aInfo.bNewObj = bNewObj;
790 if ( pIMapObj )
792 aInfo.bOneMarked = TRUE;
793 aInfo.aMarkURL = pIMapObj->GetURL();
794 aInfo.aMarkAltText = pIMapObj->GetAltText();
795 aInfo.aMarkTarget = pIMapObj->GetTarget();
796 aInfo.bActivated = pIMapObj->IsActive();
797 aInfoLink.Call( this );
799 else
801 aInfo.aMarkURL = aInfo.aMarkAltText = aInfo.aMarkTarget = String();
802 aInfo.bOneMarked = FALSE;
803 aInfo.bActivated = FALSE;
806 aInfoLink.Call( this );
810 /*************************************************************************
814 \************************************************************************/
816 void IMapWindow::DoMacroAssign()
818 SdrObject* pSdrObj = GetSelectedSdrObject();
820 if ( pSdrObj )
822 SfxItemSet aSet( *pIMapPool, SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 );
824 SfxEventNamesItem aNamesItem(SID_EVENTCONFIG);
825 aNamesItem.AddEvent( String::CreateFromAscii( "MouseOver" ), String(), SFX_EVENT_MOUSEOVER_OBJECT );
826 aNamesItem.AddEvent( String::CreateFromAscii( "MouseOut" ), String(), SFX_EVENT_MOUSEOUT_OBJECT );
827 aSet.Put( aNamesItem );
829 SvxMacroItem aMacroItem(SID_ATTR_MACROITEM);
830 IMapObject* pIMapObj = GetIMapObj( pSdrObj );
831 aMacroItem.SetMacroTable( pIMapObj->GetMacroTable() );
832 aSet.Put( aMacroItem, SID_ATTR_MACROITEM );
834 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
835 SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( this, aSet, mxDocumentFrame, SID_EVENTCONFIG );
837 if ( pMacroDlg && pMacroDlg->Execute() == RET_OK )
839 const SfxItemSet* pOutSet = pMacroDlg->GetOutputItemSet();
840 pIMapObj->SetMacroTable( ((const SvxMacroItem& )pOutSet->Get( SID_ATTR_MACROITEM )).GetMacroTable() );
841 pModel->SetChanged( sal_True );
842 UpdateInfo( FALSE );
845 delete pMacroDlg;
849 /*************************************************************************
853 \************************************************************************/
855 void IMapWindow::DoPropertyDialog()
857 SdrObject* pSdrObj = GetSelectedSdrObject();
859 if ( pSdrObj )
861 IMapObject* pIMapObj = GetIMapObj( pSdrObj );
862 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
863 if(pFact)
865 AbstractURLDlg* aDlg = pFact->CreateURLDialog( this, pIMapObj->GetURL(), pIMapObj->GetAltText(), pIMapObj->GetDesc(),
866 pIMapObj->GetTarget(), pIMapObj->GetName(), aTargetList );
867 DBG_ASSERT(aDlg, "Dialogdiet fail!");
868 if ( aDlg->Execute() == RET_OK )
870 const String aURLText( aDlg->GetURL() );
872 if ( aURLText.Len() )
874 INetURLObject aObj( aURLText, INET_PROT_FILE );
875 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL" );
876 pIMapObj->SetURL( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
878 else
879 pIMapObj->SetURL( aURLText );
881 pIMapObj->SetAltText( aDlg->GetAltText() );
882 pIMapObj->SetDesc( aDlg->GetDesc() );
883 pIMapObj->SetTarget( aDlg->GetTarget() );
884 pIMapObj->SetName( aDlg->GetName() );
885 pModel->SetChanged( sal_True );
886 UpdateInfo( TRUE );
888 delete aDlg; //add by CHINA001
893 /*************************************************************************
897 \************************************************************************/
899 IMPL_LINK( IMapWindow, MenuSelectHdl, Menu*, pMenu )
901 if (pMenu)
903 USHORT nId = pMenu->GetCurItemId();
905 switch(nId)
907 case( MN_URL ):
908 DoPropertyDialog();
909 break;
911 case( MN_MACRO ):
912 DoMacroAssign();
913 break;
915 case( MN_ACTIVATE ):
917 const BOOL bNewState = !pMenu->IsItemChecked( MN_ACTIVATE );
919 pMenu->CheckItem( MN_ACTIVATE, bNewState );
920 SetCurrentObjState( bNewState );
921 UpdateInfo( FALSE );
924 case( MN_FRAME_TO_TOP ):
925 pView->PutMarkedToTop();
926 break;
928 case( MN_MOREFRONT ):
929 pView->MovMarkedToTop();
930 break;
932 case( MN_MOREBACK ):
933 pView->MovMarkedToBtm();
934 break;
936 case( MN_FRAME_TO_BOTTOM ):
937 pView->PutMarkedToBtm();
938 break;
940 case( MN_MARK_ALL ):
941 pView->MarkAll();
942 break;
944 case( MN_DELETE1 ):
945 pView->DeleteMarked();
947 default :
948 break;
952 return 0;
955 void IMapWindow::CreateDefaultObject()
957 SdrPageView* pPageView = pView->GetSdrPageView();
959 if(pPageView)
961 // calc position and size
962 Point aPagePos(0, 0); // = pPageView->GetOffset();
963 Size aPageSize = pPageView->GetPage()->GetSize();
964 sal_uInt32 nDefaultObjectSizeWidth = aPageSize.Width() / 4;
965 sal_uInt32 nDefaultObjectSizeHeight = aPageSize.Height() / 4;
966 aPagePos.X() += (aPageSize.Width() / 2) - (nDefaultObjectSizeWidth / 2);
967 aPagePos.Y() += (aPageSize.Height() / 2) - (nDefaultObjectSizeHeight / 2);
968 Rectangle aNewObjectRectangle(aPagePos, Size(nDefaultObjectSizeWidth, nDefaultObjectSizeHeight));
970 SdrObject* pObj = SdrObjFactory::MakeNewObject( pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(), 0L, pModel);
971 pObj->SetLogicRect(aNewObjectRectangle);
973 switch( pObj->GetObjIdentifier() )
975 case OBJ_POLY:
976 case OBJ_PATHPOLY:
978 basegfx::B2DPolygon aInnerPoly;
979 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.BottomLeft().X(), aNewObjectRectangle.BottomLeft().Y()));
980 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.TopLeft().X(), aNewObjectRectangle.TopLeft().Y()));
981 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.TopCenter().X(), aNewObjectRectangle.TopCenter().Y()));
982 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.Center().X(), aNewObjectRectangle.Center().Y()));
983 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.RightCenter().X(), aNewObjectRectangle.RightCenter().Y()));
984 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.BottomRight().X(), aNewObjectRectangle.BottomRight().Y()));
985 aInnerPoly.setClosed(true);
986 ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aInnerPoly));
987 break;
989 case OBJ_FREEFILL:
990 case OBJ_PATHFILL:
992 sal_Int32 nWdt(aNewObjectRectangle.GetWidth() / 2);
993 sal_Int32 nHgt(aNewObjectRectangle.GetHeight() / 2);
994 basegfx::B2DPolygon aInnerPoly(XPolygon(aNewObjectRectangle.Center(), nWdt, nHgt).getB2DPolygon());
995 ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aInnerPoly));
996 break;
1001 pView->InsertObjectAtView(pObj, *pPageView);
1002 SdrObjCreated( *pObj );
1003 SetCurrentObjState( true );
1004 pView->MarkObj( pObj, pPageView );
1008 void IMapWindow::KeyInput( const KeyEvent& rKEvt )
1010 KeyCode aCode = rKEvt.GetKeyCode();
1013 switch(aCode.GetCode())
1015 case KEY_ESCAPE:
1017 if ( pView->IsAction() )
1019 pView->BrkAction();
1020 return;
1022 else if ( pView->AreObjectsMarked() )
1024 const SdrHdlList& rHdlList = pView->GetHdlList();
1025 SdrHdl* pHdl = rHdlList.GetFocusHdl();
1027 if(pHdl)
1029 ((SdrHdlList&)rHdlList).ResetFocusHdl();
1031 else
1033 pView->UnmarkAllObj();
1034 ((Dialog*)GetParent())->GrabFocusToFirstControl();
1037 return;
1040 break;
1044 GraphCtrl::KeyInput( rKEvt );
1047 void IMapWindow::SelectFirstObject()
1049 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
1050 if( pPage->GetObjCount() != 0 )
1052 GrabFocus();
1053 pView->UnmarkAllObj();
1054 pView->MarkNextObj(TRUE);
1058 void IMapWindow::StartPolyEdit()
1060 GrabFocus();
1062 if( !pView->AreObjectsMarked() )
1063 pView->MarkNextObj(TRUE);
1065 const SdrHdlList& rHdlList = pView->GetHdlList();
1066 SdrHdl* pHdl = rHdlList.GetFocusHdl();
1068 if(!pHdl)
1070 ((SdrHdlList&)rHdlList).TravelFocusHdl(true);