Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / dialog / imapwnd.cxx
blobe591947ae94167231dc443c63d8a1d4dcc63cb8e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/urlobj.hxx>
21 #include <vcl/msgbox.hxx>
22 #include <vcl/help.hxx>
23 #include <sfx2/sfxsids.hrc>
24 #include <svtools/imaprect.hxx>
25 #include <svtools/imapcirc.hxx>
26 #include <svtools/imappoly.hxx>
27 #include <svl/urlbmk.hxx>
29 #include <svx/xoutbmp.hxx>
30 #include <svx/dialmgr.hxx>
31 #include <svx/dialogs.hrc>
32 #include <svx/svxids.hrc>
33 #include <imapdlg.hrc>
34 #include <imapwnd.hxx>
35 #include <svx/svdpage.hxx>
36 #include <svx/svdorect.hxx>
37 #include <svx/svdocirc.hxx>
38 #include <svx/svdopath.hxx>
39 #include <svx/xfltrit.hxx>
40 #include <svx/svdpagv.hxx>
41 #include <svl/urihelper.hxx>
42 #include <svx/xfillit.hxx>
43 #include <svx/xlineit.hxx>
44 #include <sfx2/evntconf.hxx>
46 #include <sot/formats.hxx>
48 #include <svx/svxdlg.hxx>
49 #include <basegfx/point/b2dpoint.hxx>
50 #include <basegfx/polygon/b2dpolygon.hxx>
52 using ::com::sun::star::frame::XFrame;
53 using ::com::sun::star::uno::Reference;
55 #define TRANSCOL Color( COL_WHITE )
57 IMapWindow::IMapWindow( Window* pParent, const ResId& rResId, const Reference< XFrame >& rxDocumentFrame ) :
58 GraphCtrl( pParent, rResId ),
59 DropTargetHelper( this ),
60 mxDocumentFrame( rxDocumentFrame )
62 SetWinStyle( WB_SDRMODE );
64 pItemInfo = new SfxItemInfo[ 1 ];
65 memset( pItemInfo, 0, sizeof( SfxItemInfo ) );
66 pIMapPool = new SfxItemPool( OUString("IMapItemPool"),
67 SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, pItemInfo );
68 pIMapPool->FreezeIdRanges();
71 IMapWindow::~IMapWindow()
73 SfxItemPool::Free(pIMapPool);
74 delete[] pItemInfo;
77 void IMapWindow::SetImageMap( const ImageMap& rImageMap )
79 ReplaceImageMap( rImageMap, false );
82 void IMapWindow::ReplaceImageMap( const ImageMap& rImageMap, bool /*bScaleToGraphic*/ )
84 SdrPage* pPage = 0;
85 aIMap = rImageMap;
87 if(GetSdrModel())
89 // try to access page
90 pPage = GetSdrModel()->GetPage(0L);
93 if(pPage)
95 // clear all draw objects
96 pPage->Clear();
99 if(GetSdrView())
101 // #i63762# reset selection at view
102 GetSdrView()->UnmarkAllObj();
105 // create new drawing objects
106 const sal_uInt16 nCount(rImageMap.GetIMapObjectCount());
108 for ( sal_uInt16 i(nCount); i > 0; i-- )
110 SdrObject* pNewObj = CreateObj( rImageMap.GetIMapObject( i - 1 ) );
112 if (pNewObj && pPage)
114 pPage->InsertObject( pNewObj );
119 bool IMapWindow::ReplaceActualIMapInfo( const NotifyInfo& rNewInfo )
121 const SdrObject* pSdrObj = GetSelectedSdrObject();
122 IMapObject* pIMapObj;
123 bool bRet = false;
125 if ( pSdrObj && ( ( pIMapObj = GetIMapObj( pSdrObj ) ) != NULL ) )
127 pIMapObj->SetURL( rNewInfo.aMarkURL );
128 pIMapObj->SetAltText( rNewInfo.aMarkAltText );
129 pIMapObj->SetTarget( rNewInfo.aMarkTarget );
130 pModel->SetChanged( true );
131 UpdateInfo( false );
133 bRet = true;
136 return bRet;
139 const ImageMap& IMapWindow::GetImageMap()
141 if ( pModel->IsChanged() )
143 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
145 if ( pPage )
147 const long nCount = pPage->GetObjCount();
149 aIMap.ClearImageMap();
151 for ( long i = nCount - 1; i > -1; i-- )
152 aIMap.InsertIMapObject( *( ( (IMapUserData*) pPage->GetObj( i )->GetUserData( 0 ) )->GetObject() ) );
155 pModel->SetChanged( false );
158 return aIMap;
161 void IMapWindow::SetTargetList( TargetList& rTargetList )
163 // Delete old List
164 aTargetList.clear();
166 // Fill with the provided list
167 for( size_t i = 0, n = rTargetList.size(); i < n; ++i )
168 aTargetList.push_back( rTargetList[ i ] );
170 pModel->SetChanged( false );
173 SdrObject* IMapWindow::CreateObj( const IMapObject* pIMapObj )
175 Point aPoint;
176 Rectangle aClipRect( aPoint, GetGraphicSize() );
177 SdrObject* pSdrObj = NULL;
178 IMapObjectPtr pCloneIMapObj;
180 switch( pIMapObj->GetType() )
182 case( IMAP_OBJ_RECTANGLE ):
184 IMapRectangleObject* pIMapRectObj = (IMapRectangleObject*) pIMapObj;
185 Rectangle aDrawRect( pIMapRectObj->GetRectangle( false ) );
187 // clipped on CanvasPane
188 aDrawRect.Intersection( aClipRect );
190 pSdrObj = (SdrObject*) new SdrRectObj( aDrawRect );
191 pCloneIMapObj.reset((IMapObject*) new IMapRectangleObject( *pIMapRectObj ));
193 break;
195 case( IMAP_OBJ_CIRCLE ):
197 IMapCircleObject* pIMapCircleObj = (IMapCircleObject*) pIMapObj;
198 const Point aCenter( pIMapCircleObj->GetCenter( false ) );
199 const long nRadius = pIMapCircleObj->GetRadius( false );
200 const Point aOffset( nRadius, nRadius );
201 Rectangle aCircle( aCenter - aOffset, aCenter + aOffset );
203 // limited to CanvasPane
204 aCircle.Intersection( aClipRect );
206 pSdrObj = (SdrObject*) new SdrCircObj( OBJ_CIRC, aCircle, 0, 36000 );
207 pCloneIMapObj.reset((IMapObject*) new IMapCircleObject( *pIMapCircleObj ));
209 break;
211 case( IMAP_OBJ_POLYGON ):
213 IMapPolygonObject* pIMapPolyObj = (IMapPolygonObject*) pIMapObj;
215 // If it actually is an ellipse, then another ellipse is created again
216 if ( pIMapPolyObj->HasExtraEllipse() )
218 Rectangle aDrawRect( pIMapPolyObj->GetExtraEllipse() );
220 // clipped on CanvasPane
221 aDrawRect.Intersection( aClipRect );
223 pSdrObj = (SdrObject*) new SdrCircObj( OBJ_CIRC, aDrawRect, 0, 36000 );
225 else
227 const Polygon& rPoly = pIMapPolyObj->GetPolygon( false );
228 Polygon aDrawPoly( rPoly );
230 // clipped on CanvasPane
231 aDrawPoly.Clip( aClipRect );
233 basegfx::B2DPolygon aPolygon;
234 aPolygon.append(aDrawPoly.getB2DPolygon());
235 pSdrObj = (SdrObject*)new SdrPathObj(OBJ_POLY, basegfx::B2DPolyPolygon(aPolygon));
238 pCloneIMapObj.reset((IMapObject*) new IMapPolygonObject( *pIMapPolyObj ));
240 break;
242 default:
243 break;
246 if ( pSdrObj )
248 SfxItemSet aSet( pModel->GetItemPool() );
250 aSet.Put( XFillStyleItem( XFILL_SOLID ) );
251 aSet.Put( XFillColorItem( "", TRANSCOL ) );
253 if ( !pIMapObj->IsActive() )
255 aSet.Put( XFillTransparenceItem( 100 ) );
256 aSet.Put( XLineColorItem( "", Color( COL_RED ) ) );
258 else
260 aSet.Put( XFillTransparenceItem( 50 ) );
261 aSet.Put( XLineColorItem( "", Color( COL_BLACK ) ) );
264 pSdrObj->SetMergedItemSetAndBroadcast(aSet);
266 pSdrObj->AppendUserData( new IMapUserData( pCloneIMapObj ) );
267 pSdrObj->SetUserCall( GetSdrUserCall() );
270 return pSdrObj;
273 void IMapWindow::InitSdrModel()
275 GraphCtrl::InitSdrModel();
277 SfxItemSet aSet( pModel->GetItemPool() );
279 aSet.Put( XFillColorItem( "", TRANSCOL ) );
280 aSet.Put( XFillTransparenceItem( 50 ) );
281 pView->SetAttributes( aSet );
282 pView->SetFrameDragSingles( true );
285 void IMapWindow::SdrObjCreated( const SdrObject& rObj )
287 switch( rObj.GetObjIdentifier() )
289 case( OBJ_RECT ):
291 SdrRectObj* pRectObj = (SdrRectObj*) &rObj;
292 IMapRectangleObject* pObj = new IMapRectangleObject( pRectObj->GetLogicRect(), "", "", "", "", "", true, false );
294 pRectObj->AppendUserData( new IMapUserData( IMapObjectPtr(pObj) ) );
296 break;
298 case( OBJ_CIRC ):
300 SdrCircObj* pCircObj = (SdrCircObj*) &rObj;
301 SdrPathObj* pPathObj = (SdrPathObj*) pCircObj->ConvertToPolyObj( false, false );
302 Polygon aPoly(pPathObj->GetPathPoly().getB2DPolygon(0L));
303 delete pPathObj;
305 IMapPolygonObject* pObj = new IMapPolygonObject( Polygon(aPoly), "", "", "", "", "", true, false );
306 pObj->SetExtraEllipse( aPoly.GetBoundRect() );
307 pCircObj->AppendUserData( new IMapUserData( IMapObjectPtr(pObj) ) );
309 break;
311 case( OBJ_POLY ):
312 case( OBJ_FREEFILL ):
313 case( OBJ_PATHPOLY ):
314 case( OBJ_PATHFILL ):
316 SdrPathObj* pPathObj = (SdrPathObj*) &rObj;
317 const basegfx::B2DPolyPolygon& rXPolyPoly = pPathObj->GetPathPoly();
319 if ( rXPolyPoly.count() )
321 Polygon aPoly(rXPolyPoly.getB2DPolygon(0L));
322 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, "", "", "", "", "", true, false );
323 pPathObj->AppendUserData( new IMapUserData( IMapObjectPtr(pObj) ) );
326 break;
328 default:
329 break;
333 void IMapWindow::SdrObjChanged( const SdrObject& rObj )
335 IMapUserData* pUserData = (IMapUserData*) rObj.GetUserData( 0 );
337 if ( pUserData )
339 OUString aURL;
340 OUString aAltText;
341 OUString aDesc;
342 OUString aTarget;
343 IMapObjectPtr pIMapObj = pUserData->GetObject();
344 bool bActive = true;
346 if ( pIMapObj.get() )
348 aURL = pIMapObj->GetURL();
349 aAltText = pIMapObj->GetAltText();
350 aDesc = pIMapObj->GetDesc();
351 aTarget = pIMapObj->GetTarget();
352 bActive = pIMapObj->IsActive();
355 switch( rObj.GetObjIdentifier() )
357 case( OBJ_RECT ):
359 pUserData->ReplaceObject( IMapObjectPtr(new IMapRectangleObject( ( (const SdrRectObj&) rObj ).GetLogicRect(),
360 aURL, aAltText, aDesc, aTarget, "", bActive, false ) ) );
362 break;
364 case( OBJ_CIRC ):
366 const SdrCircObj& rCircObj = (const SdrCircObj&) rObj;
367 SdrPathObj* pPathObj = (SdrPathObj*) rCircObj.ConvertToPolyObj( false, false );
368 Polygon aPoly(pPathObj->GetPathPoly().getB2DPolygon(0L));
370 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, "", bActive, false );
371 pObj->SetExtraEllipse( aPoly.GetBoundRect() );
373 // was only created by us temporarily
374 delete pPathObj;
375 pUserData->ReplaceObject( IMapObjectPtr(pObj) );
377 break;
379 case( OBJ_POLY ):
380 case( OBJ_FREEFILL ):
381 case( OBJ_PATHPOLY ):
382 case( OBJ_PATHFILL ):
384 const SdrPathObj& rPathObj = (const SdrPathObj&) rObj;
385 const basegfx::B2DPolyPolygon& rXPolyPoly = rPathObj.GetPathPoly();
387 if ( rXPolyPoly.count() )
389 Polygon aPoly(rPathObj.GetPathPoly().getB2DPolygon(0L));
390 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, "", bActive, false );
391 pUserData->ReplaceObject( IMapObjectPtr(pObj) );
394 break;
396 default:
397 break;
402 void IMapWindow::MouseButtonUp(const MouseEvent& rMEvt)
404 GraphCtrl::MouseButtonUp( rMEvt );
405 UpdateInfo( true );
408 void IMapWindow::MarkListHasChanged()
410 GraphCtrl::MarkListHasChanged();
411 UpdateInfo( false );
414 SdrObject* IMapWindow::GetHitSdrObj( const Point& rPosPixel ) const
416 SdrObject* pObj = NULL;
417 Point aPt = PixelToLogic( rPosPixel );
419 if ( Rectangle( Point(), GetGraphicSize() ).IsInside( aPt ) )
421 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
422 sal_uIntPtr nCount;
424 if ( pPage && ( ( nCount = pPage->GetObjCount() ) > 0 ) )
426 for ( long i = nCount - 1; i >= 0; i-- )
428 SdrObject* pTestObj = pPage->GetObj( i );
429 IMapObject* pIMapObj = GetIMapObj( pTestObj );
431 if ( pIMapObj && pIMapObj->IsHit( aPt ) )
433 pObj = pTestObj;
434 break;
440 return pObj;
443 IMapObject* IMapWindow::GetIMapObj( const SdrObject* pSdrObj ) const
445 IMapObject* pIMapObj = NULL;
447 if ( pSdrObj )
449 IMapUserData* pUserData = (IMapUserData*) pSdrObj->GetUserData( 0 );
451 if ( pUserData )
452 pIMapObj = pUserData->GetObject().get();
455 return pIMapObj;
458 void IMapWindow::Command(const CommandEvent& rCEvt)
460 Region aRegion;
462 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
464 PopupMenu aMenu( SVX_RES( RID_SVXMN_IMAP ) );
465 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
466 sal_uIntPtr nMarked = rMarkList.GetMarkCount();
468 aMenu.EnableItem( MN_URL, false );
469 aMenu.EnableItem( MN_ACTIVATE, false );
470 aMenu.EnableItem( MN_MACRO, false );
471 aMenu.EnableItem( MN_MARK_ALL, pModel->GetPage( 0 )->GetObjCount() != pView->GetMarkedObjectCount() );
473 if ( !nMarked )
475 aMenu.EnableItem( MN_POSITION, false );
476 aMenu.EnableItem( MN_FRAME_TO_TOP, false );
477 aMenu.EnableItem( MN_MOREFRONT, false );
478 aMenu.EnableItem( MN_MOREBACK, false );
479 aMenu.EnableItem( MN_FRAME_TO_BOTTOM, false );
480 aMenu.EnableItem( MN_DELETE1, false );
482 else
484 if ( nMarked == 1 )
486 SdrObject* pSdrObj = GetSelectedSdrObject();
488 aMenu.EnableItem( MN_URL, true );
489 aMenu.EnableItem( MN_ACTIVATE, true );
490 aMenu.EnableItem( MN_MACRO, true );
491 aMenu.CheckItem( MN_ACTIVATE, GetIMapObj( pSdrObj )->IsActive() );
494 aMenu.EnableItem( MN_POSITION, true );
495 aMenu.EnableItem( MN_FRAME_TO_TOP, true );
496 aMenu.EnableItem( MN_MOREFRONT, true );
497 aMenu.EnableItem( MN_MOREBACK, true );
498 aMenu.EnableItem( MN_FRAME_TO_BOTTOM, true );
499 aMenu.EnableItem( MN_DELETE1, true );
502 aMenu.SetSelectHdl( LINK( this, IMapWindow, MenuSelectHdl ) );
503 aMenu.Execute( this, rCEvt.GetMousePosPixel() );
505 else
506 Window::Command(rCEvt);
509 sal_Int8 IMapWindow::AcceptDrop( const AcceptDropEvent& rEvt )
511 return( ( GetHitSdrObj( rEvt.maPosPixel ) != NULL ) ? rEvt.mnAction : DND_ACTION_NONE );
514 sal_Int8 IMapWindow::ExecuteDrop( const ExecuteDropEvent& rEvt )
516 sal_Int8 nRet = DND_ACTION_NONE;
518 if( IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) )
520 const OUString aString;
521 INetBookmark aBookMark( aString, aString );
522 SdrObject* pSdrObj = GetHitSdrObj( rEvt.maPosPixel );
524 if( pSdrObj && TransferableDataHelper( rEvt.maDropEvent.Transferable ).GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aBookMark ) )
526 IMapObject* pIMapObj = GetIMapObj( pSdrObj );
528 pIMapObj->SetURL( aBookMark.GetURL() );
529 pIMapObj->SetAltText( aBookMark.GetDescription() );
530 pModel->SetChanged( true );
531 pView->UnmarkAll();
532 pView->MarkObj( pSdrObj, pView->GetSdrPageView() );
533 UpdateInfo( true );
534 nRet = rEvt.mnAction;
538 return nRet;
541 void IMapWindow::RequestHelp( const HelpEvent& rHEvt )
543 Point aPos = PixelToLogic( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
545 if ( Help::IsBalloonHelpEnabled() || Help::IsQuickHelpEnabled() )
547 SdrObject* pSdrObj = NULL;
548 SdrPageView* pPageView = NULL;
549 if ( pView->PickObj( aPos, pView->getHitTolLog(), pSdrObj, pPageView ) )
551 const IMapObject* pIMapObj = GetIMapObj( pSdrObj );
552 OUString aStr;
554 if ( pIMapObj && !( aStr = pIMapObj->GetURL() ).isEmpty() )
556 Rectangle aLogicPix( LogicToPixel( Rectangle( Point(), GetGraphicSize() ) ) );
557 Rectangle aScreenRect( OutputToScreenPixel( aLogicPix.TopLeft() ),
558 OutputToScreenPixel( aLogicPix.BottomRight() ) );
560 if ( Help::IsBalloonHelpEnabled() )
561 Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), aScreenRect, aStr );
562 else if ( Help::IsQuickHelpEnabled() )
563 Help::ShowQuickHelp( this, aScreenRect, aStr );
566 else
567 Window::RequestHelp( rHEvt );
571 void IMapWindow::SetCurrentObjState( bool bActive )
573 SdrObject* pObj = GetSelectedSdrObject();
575 if ( pObj )
577 SfxItemSet aSet( pModel->GetItemPool() );
579 GetIMapObj( pObj )->SetActive( bActive );
581 aSet.Put( XFillColorItem( "", TRANSCOL ) );
583 if ( !bActive )
585 aSet.Put( XFillTransparenceItem( 100 ) );
586 aSet.Put( XLineColorItem( "", Color( COL_RED ) ) );
588 else
590 aSet.Put( XFillTransparenceItem( 50 ) );
591 aSet.Put( XLineColorItem( "", Color( COL_BLACK ) ) );
594 pView->SetAttributes( aSet, false );
598 void IMapWindow::UpdateInfo( bool bNewObj )
600 if ( aInfoLink.IsSet() )
602 const SdrObject* pSdrObj = GetSelectedSdrObject();
603 const IMapObject* pIMapObj = pSdrObj ? GetIMapObj( pSdrObj ) : NULL;
605 aInfo.bNewObj = bNewObj;
607 if ( pIMapObj )
609 aInfo.bOneMarked = true;
610 aInfo.aMarkURL = pIMapObj->GetURL();
611 aInfo.aMarkAltText = pIMapObj->GetAltText();
612 aInfo.aMarkTarget = pIMapObj->GetTarget();
613 aInfo.bActivated = pIMapObj->IsActive();
614 aInfoLink.Call( this );
616 else
618 aInfo.aMarkURL = aInfo.aMarkAltText = aInfo.aMarkTarget = "";
619 aInfo.bOneMarked = false;
620 aInfo.bActivated = false;
623 aInfoLink.Call( this );
627 void IMapWindow::DoMacroAssign()
629 SdrObject* pSdrObj = GetSelectedSdrObject();
631 if ( pSdrObj )
633 SfxItemSet aSet( *pIMapPool, SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 );
635 SfxEventNamesItem aNamesItem(SID_EVENTCONFIG);
636 aNamesItem.AddEvent( "MouseOver", "", SFX_EVENT_MOUSEOVER_OBJECT );
637 aNamesItem.AddEvent( "MouseOut", "", SFX_EVENT_MOUSEOUT_OBJECT );
638 aSet.Put( aNamesItem );
640 SvxMacroItem aMacroItem(SID_ATTR_MACROITEM);
641 IMapObject* pIMapObj = GetIMapObj( pSdrObj );
642 aMacroItem.SetMacroTable( pIMapObj->GetMacroTable() );
643 aSet.Put( aMacroItem, SID_ATTR_MACROITEM );
645 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
646 SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( this, aSet, mxDocumentFrame, SID_EVENTCONFIG );
648 if ( pMacroDlg && pMacroDlg->Execute() == RET_OK )
650 const SfxItemSet* pOutSet = pMacroDlg->GetOutputItemSet();
651 pIMapObj->SetMacroTable( ((const SvxMacroItem& )pOutSet->Get( SID_ATTR_MACROITEM )).GetMacroTable() );
652 pModel->SetChanged( true );
653 UpdateInfo( false );
656 delete pMacroDlg;
660 void IMapWindow::DoPropertyDialog()
662 SdrObject* pSdrObj = GetSelectedSdrObject();
664 if ( pSdrObj )
666 IMapObject* pIMapObj = GetIMapObj( pSdrObj );
667 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
668 if(pFact)
670 AbstractURLDlg* aDlg = pFact->CreateURLDialog( this, pIMapObj->GetURL(), pIMapObj->GetAltText(), pIMapObj->GetDesc(),
671 pIMapObj->GetTarget(), pIMapObj->GetName(), aTargetList );
672 DBG_ASSERT(aDlg, "Dialogdiet fail!");
673 if ( aDlg->Execute() == RET_OK )
675 const OUString aURLText( aDlg->GetURL() );
677 if ( !aURLText.isEmpty() )
679 INetURLObject aObj( aURLText, INET_PROT_FILE );
680 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL" );
681 pIMapObj->SetURL( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
683 else
684 pIMapObj->SetURL( aURLText );
686 pIMapObj->SetAltText( aDlg->GetAltText() );
687 pIMapObj->SetDesc( aDlg->GetDesc() );
688 pIMapObj->SetTarget( aDlg->GetTarget() );
689 pIMapObj->SetName( aDlg->GetName() );
690 pModel->SetChanged( true );
691 UpdateInfo( true );
693 delete aDlg;
698 IMPL_LINK( IMapWindow, MenuSelectHdl, Menu*, pMenu )
700 if (pMenu)
702 sal_uInt16 nId = pMenu->GetCurItemId();
704 switch(nId)
706 case( MN_URL ):
707 DoPropertyDialog();
708 break;
710 case( MN_MACRO ):
711 DoMacroAssign();
712 break;
714 case( MN_ACTIVATE ):
716 const bool bNewState = !pMenu->IsItemChecked( MN_ACTIVATE );
718 pMenu->CheckItem( MN_ACTIVATE, bNewState );
719 SetCurrentObjState( bNewState );
720 UpdateInfo( false );
723 case( MN_FRAME_TO_TOP ):
724 pView->PutMarkedToTop();
725 break;
727 case( MN_MOREFRONT ):
728 pView->MovMarkedToTop();
729 break;
731 case( MN_MOREBACK ):
732 pView->MovMarkedToBtm();
733 break;
735 case( MN_FRAME_TO_BOTTOM ):
736 pView->PutMarkedToBtm();
737 break;
739 case( MN_MARK_ALL ):
740 pView->MarkAll();
741 break;
743 case( MN_DELETE1 ):
744 pView->DeleteMarked();
746 default :
747 break;
751 return 0;
754 void IMapWindow::CreateDefaultObject()
756 SdrPageView* pPageView = pView->GetSdrPageView();
758 if(pPageView)
760 // calc position and size
761 Point aPagePos(0, 0); // = pPageView->GetOffset();
762 Size aPageSize = pPageView->GetPage()->GetSize();
763 sal_uInt32 nDefaultObjectSizeWidth = aPageSize.Width() / 4;
764 sal_uInt32 nDefaultObjectSizeHeight = aPageSize.Height() / 4;
765 aPagePos.X() += (aPageSize.Width() / 2) - (nDefaultObjectSizeWidth / 2);
766 aPagePos.Y() += (aPageSize.Height() / 2) - (nDefaultObjectSizeHeight / 2);
767 Rectangle aNewObjectRectangle(aPagePos, Size(nDefaultObjectSizeWidth, nDefaultObjectSizeHeight));
769 SdrObject* pObj = SdrObjFactory::MakeNewObject( pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(), 0L, pModel);
770 pObj->SetLogicRect(aNewObjectRectangle);
772 switch( pObj->GetObjIdentifier() )
774 case OBJ_POLY:
775 case OBJ_PATHPOLY:
777 basegfx::B2DPolygon aInnerPoly;
778 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.BottomLeft().X(), aNewObjectRectangle.BottomLeft().Y()));
779 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.TopLeft().X(), aNewObjectRectangle.TopLeft().Y()));
780 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.TopCenter().X(), aNewObjectRectangle.TopCenter().Y()));
781 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.Center().X(), aNewObjectRectangle.Center().Y()));
782 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.RightCenter().X(), aNewObjectRectangle.RightCenter().Y()));
783 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.BottomRight().X(), aNewObjectRectangle.BottomRight().Y()));
784 aInnerPoly.setClosed(true);
785 ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aInnerPoly));
786 break;
788 case OBJ_FREEFILL:
789 case OBJ_PATHFILL:
791 sal_Int32 nWdt(aNewObjectRectangle.GetWidth() / 2);
792 sal_Int32 nHgt(aNewObjectRectangle.GetHeight() / 2);
793 basegfx::B2DPolygon aInnerPoly(XPolygon(aNewObjectRectangle.Center(), nWdt, nHgt).getB2DPolygon());
794 ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aInnerPoly));
795 break;
800 pView->InsertObjectAtView(pObj, *pPageView);
801 SdrObjCreated( *pObj );
802 SetCurrentObjState( true );
803 pView->MarkObj( pObj, pPageView );
807 void IMapWindow::KeyInput( const KeyEvent& rKEvt )
809 GraphCtrl::KeyInput( rKEvt );
812 void IMapWindow::SelectFirstObject()
814 SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
815 if( pPage->GetObjCount() != 0 )
817 GrabFocus();
818 pView->UnmarkAllObj();
819 pView->MarkNextObj(true);
823 void IMapWindow::StartPolyEdit()
825 GrabFocus();
827 if( !pView->AreObjectsMarked() )
828 pView->MarkNextObj(true);
830 const SdrHdlList& rHdlList = pView->GetHdlList();
831 SdrHdl* pHdl = rHdlList.GetFocusHdl();
833 if(!pHdl)
835 ((SdrHdlList&)rHdlList).TravelFocusHdl(true);
839 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */