LCOV - code coverage report
Current view: top level - svx/source/dialog - imapwnd.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 422 0.2 %
Date: 2014-04-11 Functions: 2 32 6.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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>
      28             : 
      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>
      45             : 
      46             : #include <sot/formats.hxx>
      47             : 
      48             : #include <svx/svxdlg.hxx>
      49             : #include <basegfx/point/b2dpoint.hxx>
      50             : #include <basegfx/polygon/b2dpolygon.hxx>
      51             : 
      52             : using ::com::sun::star::frame::XFrame;
      53             : using ::com::sun::star::uno::Reference;
      54             : 
      55             : #define TRANSCOL Color( COL_WHITE )
      56             : 
      57           0 : IMapWindow::IMapWindow( Window* pParent, const ResId& rResId, const Reference< XFrame >& rxDocumentFrame ) :
      58             :             GraphCtrl( pParent, rResId ),
      59             :             DropTargetHelper( this ),
      60           0 :             mxDocumentFrame( rxDocumentFrame )
      61             : {
      62           0 :     SetWinStyle( WB_SDRMODE );
      63             : 
      64           0 :     pItemInfo = new SfxItemInfo[ 1 ];
      65           0 :     memset( pItemInfo, 0, sizeof( SfxItemInfo ) );
      66             :     pIMapPool = new SfxItemPool( OUString("IMapItemPool"),
      67           0 :                                  SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, pItemInfo );
      68           0 :     pIMapPool->FreezeIdRanges();
      69           0 : }
      70             : 
      71           0 : IMapWindow::~IMapWindow()
      72             : {
      73           0 :     SfxItemPool::Free(pIMapPool);
      74           0 :     delete[] pItemInfo;
      75           0 : }
      76             : 
      77           0 : void IMapWindow::SetImageMap( const ImageMap& rImageMap )
      78             : {
      79           0 :     ReplaceImageMap( rImageMap, sal_False );
      80           0 : }
      81             : 
      82           0 : void IMapWindow::ReplaceImageMap( const ImageMap& rImageMap, sal_Bool /*bScaleToGraphic*/ )
      83             : {
      84           0 :     SdrPage* pPage = 0;
      85           0 :     aIMap = rImageMap;
      86             : 
      87           0 :     if(GetSdrModel())
      88             :     {
      89             :         // try to access page
      90           0 :         pPage = GetSdrModel()->GetPage(0L);
      91             :     }
      92             : 
      93           0 :     if(pPage)
      94             :     {
      95             :         // clear all draw objects
      96           0 :         pPage->Clear();
      97             :     }
      98             : 
      99           0 :     if(GetSdrView())
     100             :     {
     101             :         // #i63762# reset selection at view
     102           0 :         GetSdrView()->UnmarkAllObj();
     103             :     }
     104             : 
     105             :     // create new drawing objects
     106           0 :     const sal_uInt16 nCount(rImageMap.GetIMapObjectCount());
     107             : 
     108           0 :     for ( sal_uInt16 i(nCount); i > 0; i-- )
     109             :     {
     110           0 :         SdrObject* pNewObj = CreateObj( rImageMap.GetIMapObject( i - 1 ) );
     111             : 
     112           0 :         if ( pNewObj )
     113             :         {
     114           0 :             pPage->InsertObject( pNewObj );
     115             :         }
     116             :     }
     117           0 : }
     118             : 
     119           0 : sal_Bool IMapWindow::ReplaceActualIMapInfo( const NotifyInfo& rNewInfo )
     120             : {
     121           0 :     const SdrObject*    pSdrObj = GetSelectedSdrObject();
     122             :     IMapObject*         pIMapObj;
     123           0 :     sal_Bool                bRet = sal_False;
     124             : 
     125           0 :     if ( pSdrObj && ( ( pIMapObj = GetIMapObj( pSdrObj ) ) != NULL ) )
     126             :     {
     127           0 :         pIMapObj->SetURL( rNewInfo.aMarkURL );
     128           0 :         pIMapObj->SetAltText( rNewInfo.aMarkAltText );
     129           0 :         pIMapObj->SetTarget( rNewInfo.aMarkTarget );
     130           0 :         pModel->SetChanged( true );
     131           0 :         UpdateInfo( sal_False );
     132             : 
     133           0 :         bRet = sal_True;
     134             :     }
     135             : 
     136           0 :     return bRet;
     137             : }
     138             : 
     139           0 : const ImageMap& IMapWindow::GetImageMap()
     140             : {
     141           0 :     if ( pModel->IsChanged() )
     142             :     {
     143           0 :         SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
     144             : 
     145           0 :         if ( pPage )
     146             :         {
     147           0 :             const long nCount = pPage->GetObjCount();
     148             : 
     149           0 :             aIMap.ClearImageMap();
     150             : 
     151           0 :             for ( long i = nCount - 1; i > -1; i-- )
     152           0 :                 aIMap.InsertIMapObject( *( ( (IMapUserData*) pPage->GetObj( i )->GetUserData( 0 ) )->GetObject() ) );
     153             :         }
     154             : 
     155           0 :         pModel->SetChanged( false );
     156             :     }
     157             : 
     158           0 :     return aIMap;
     159             : }
     160             : 
     161           0 : void IMapWindow::SetTargetList( TargetList& rTargetList )
     162             : {
     163             :     // Delete old List
     164           0 :     aTargetList.clear();
     165             : 
     166             :     // Fill with the provided list
     167           0 :     for( size_t i = 0, n = rTargetList.size(); i < n; ++i )
     168           0 :         aTargetList.push_back( rTargetList[ i ] );
     169             : 
     170           0 :     pModel->SetChanged( false );
     171           0 : }
     172             : 
     173           0 : SdrObject* IMapWindow::CreateObj( const IMapObject* pIMapObj )
     174             : {
     175           0 :     Point       aPoint;
     176           0 :     Rectangle   aClipRect( aPoint, GetGraphicSize() );
     177           0 :     SdrObject*  pSdrObj = NULL;
     178           0 :     IMapObjectPtr pCloneIMapObj;
     179             : 
     180           0 :     switch( pIMapObj->GetType() )
     181             :     {
     182             :         case( IMAP_OBJ_RECTANGLE ):
     183             :         {
     184           0 :             IMapRectangleObject*    pIMapRectObj = (IMapRectangleObject*) pIMapObj;
     185           0 :             Rectangle               aDrawRect( pIMapRectObj->GetRectangle( false ) );
     186             : 
     187             :             // clipped on CanvasPane
     188           0 :             aDrawRect.Intersection( aClipRect );
     189             : 
     190           0 :             pSdrObj = (SdrObject*) new SdrRectObj( aDrawRect );
     191           0 :             pCloneIMapObj.reset((IMapObject*) new IMapRectangleObject( *pIMapRectObj ));
     192             :         }
     193           0 :         break;
     194             : 
     195             :         case( IMAP_OBJ_CIRCLE ):
     196             :         {
     197           0 :             IMapCircleObject*   pIMapCircleObj = (IMapCircleObject*) pIMapObj;
     198           0 :             const Point         aCenter( pIMapCircleObj->GetCenter( false ) );
     199           0 :             const long          nRadius = pIMapCircleObj->GetRadius( false );
     200           0 :             const Point         aOffset( nRadius, nRadius );
     201           0 :             Rectangle           aCircle( aCenter - aOffset, aCenter + aOffset );
     202             : 
     203             :             // limited to CanvasPane
     204           0 :             aCircle.Intersection( aClipRect );
     205             : 
     206           0 :             pSdrObj = (SdrObject*) new SdrCircObj( OBJ_CIRC, aCircle, 0, 36000 );
     207           0 :             pCloneIMapObj.reset((IMapObject*) new IMapCircleObject( *pIMapCircleObj ));
     208             :         }
     209           0 :         break;
     210             : 
     211             :         case( IMAP_OBJ_POLYGON ):
     212             :         {
     213           0 :             IMapPolygonObject*  pIMapPolyObj = (IMapPolygonObject*) pIMapObj;
     214             : 
     215             :             // If it actually is an ellipse, then another ellipse is created again
     216           0 :             if ( pIMapPolyObj->HasExtraEllipse() )
     217             :             {
     218           0 :                 Rectangle aDrawRect( pIMapPolyObj->GetExtraEllipse() );
     219             : 
     220             :                 // clipped on CanvasPane
     221           0 :                 aDrawRect.Intersection( aClipRect );
     222             : 
     223           0 :                 pSdrObj = (SdrObject*) new SdrCircObj( OBJ_CIRC, aDrawRect, 0, 36000 );
     224             :             }
     225             :             else
     226             :             {
     227           0 :                 const Polygon&  rPoly = pIMapPolyObj->GetPolygon( false );
     228           0 :                 Polygon         aDrawPoly( rPoly );
     229             : 
     230             :                 // clipped on CanvasPane
     231           0 :                 aDrawPoly.Clip( aClipRect );
     232             : 
     233           0 :                 basegfx::B2DPolygon aPolygon;
     234           0 :                 aPolygon.append(aDrawPoly.getB2DPolygon());
     235           0 :                 pSdrObj = (SdrObject*)new SdrPathObj(OBJ_POLY, basegfx::B2DPolyPolygon(aPolygon));
     236             :             }
     237             : 
     238           0 :             pCloneIMapObj.reset((IMapObject*) new IMapPolygonObject( *pIMapPolyObj ));
     239             :         }
     240           0 :         break;
     241             : 
     242             :         default:
     243           0 :         break;
     244             :     }
     245             : 
     246           0 :     if ( pSdrObj )
     247             :     {
     248           0 :         SfxItemSet aSet( pModel->GetItemPool() );
     249             : 
     250           0 :         aSet.Put( XFillStyleItem( XFILL_SOLID ) );
     251           0 :         aSet.Put( XFillColorItem( "", TRANSCOL ) );
     252             : 
     253           0 :         if ( !pIMapObj->IsActive() )
     254             :         {
     255           0 :             aSet.Put( XFillTransparenceItem( 100 ) );
     256           0 :             aSet.Put( XLineColorItem( "", Color( COL_RED ) ) );
     257             :         }
     258             :         else
     259             :         {
     260           0 :             aSet.Put( XFillTransparenceItem( 50 ) );
     261           0 :             aSet.Put( XLineColorItem( "", Color( COL_BLACK ) ) );
     262             :         }
     263             : 
     264           0 :         pSdrObj->SetMergedItemSetAndBroadcast(aSet);
     265             : 
     266           0 :         pSdrObj->AppendUserData( new IMapUserData( pCloneIMapObj ) );
     267           0 :         pSdrObj->SetUserCall( GetSdrUserCall() );
     268             :     }
     269             : 
     270           0 :     return pSdrObj;
     271             : }
     272             : 
     273           0 : void IMapWindow::InitSdrModel()
     274             : {
     275           0 :     GraphCtrl::InitSdrModel();
     276             : 
     277           0 :     SfxItemSet aSet( pModel->GetItemPool() );
     278             : 
     279           0 :     aSet.Put( XFillColorItem( "", TRANSCOL ) );
     280           0 :     aSet.Put( XFillTransparenceItem( 50 ) );
     281           0 :     pView->SetAttributes( aSet );
     282           0 :     pView->SetFrameDragSingles( true );
     283           0 : }
     284             : 
     285           0 : void IMapWindow::SdrObjCreated( const SdrObject& rObj )
     286             : {
     287           0 :     switch( rObj.GetObjIdentifier() )
     288             :     {
     289             :         case( OBJ_RECT ):
     290             :         {
     291           0 :             SdrRectObj*          pRectObj = (SdrRectObj*) &rObj;
     292           0 :             IMapRectangleObject* pObj = new IMapRectangleObject( pRectObj->GetLogicRect(), "", "", "", "", "", true, false );
     293             : 
     294           0 :             pRectObj->AppendUserData( new IMapUserData( IMapObjectPtr(pObj) ) );
     295             :         }
     296           0 :         break;
     297             : 
     298             :         case( OBJ_CIRC ):
     299             :         {
     300           0 :             SdrCircObj* pCircObj = (SdrCircObj*) &rObj;
     301           0 :             SdrPathObj* pPathObj = (SdrPathObj*) pCircObj->ConvertToPolyObj( false, false );
     302           0 :             Polygon aPoly(pPathObj->GetPathPoly().getB2DPolygon(0L));
     303           0 :             delete pPathObj;
     304             : 
     305           0 :             IMapPolygonObject* pObj = new IMapPolygonObject( Polygon(aPoly), "", "", "", "", "", true, false );
     306           0 :             pObj->SetExtraEllipse( aPoly.GetBoundRect() );
     307           0 :             pCircObj->AppendUserData( new IMapUserData( IMapObjectPtr(pObj) ) );
     308             :         }
     309           0 :         break;
     310             : 
     311             :         case( OBJ_POLY ):
     312             :         case( OBJ_FREEFILL ):
     313             :         case( OBJ_PATHPOLY ):
     314             :         case( OBJ_PATHFILL ):
     315             :         {
     316           0 :             SdrPathObj* pPathObj = (SdrPathObj*) &rObj;
     317           0 :             const basegfx::B2DPolyPolygon& rXPolyPoly = pPathObj->GetPathPoly();
     318             : 
     319           0 :             if ( rXPolyPoly.count() )
     320             :             {
     321           0 :                 Polygon aPoly(rXPolyPoly.getB2DPolygon(0L));
     322           0 :                 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, "", "", "", "", "", true, false );
     323           0 :                 pPathObj->AppendUserData( new IMapUserData( IMapObjectPtr(pObj) ) );
     324             :             }
     325             :         }
     326           0 :         break;
     327             : 
     328             :         default:
     329           0 :         break;
     330             :     }
     331           0 : }
     332             : 
     333           0 : void IMapWindow::SdrObjChanged( const SdrObject& rObj )
     334             : {
     335           0 :     IMapUserData* pUserData = (IMapUserData*) rObj.GetUserData( 0 );
     336             : 
     337           0 :     if ( pUserData )
     338             :     {
     339           0 :         OUString        aURL;
     340           0 :         OUString        aAltText;
     341           0 :         OUString        aDesc;
     342           0 :         OUString        aTarget;
     343           0 :         IMapObjectPtr   pIMapObj = pUserData->GetObject();
     344           0 :         sal_Bool        bActive = sal_True;
     345             : 
     346           0 :         if ( pIMapObj.get() )
     347             :         {
     348           0 :             aURL = pIMapObj->GetURL();
     349           0 :             aAltText = pIMapObj->GetAltText();
     350           0 :             aDesc = pIMapObj->GetDesc();
     351           0 :             aTarget = pIMapObj->GetTarget();
     352           0 :             bActive = pIMapObj->IsActive();
     353             :         }
     354             : 
     355           0 :         switch( rObj.GetObjIdentifier() )
     356             :         {
     357             :             case( OBJ_RECT ):
     358             :             {
     359           0 :                 pUserData->ReplaceObject( IMapObjectPtr(new IMapRectangleObject( ( (const SdrRectObj&) rObj ).GetLogicRect(),
     360           0 :                           aURL, aAltText, aDesc, aTarget, "", bActive, false ) ) );
     361             :             }
     362           0 :             break;
     363             : 
     364             :             case( OBJ_CIRC ):
     365             :             {
     366           0 :                 const SdrCircObj& rCircObj = (const SdrCircObj&) rObj;
     367           0 :                 SdrPathObj* pPathObj = (SdrPathObj*) rCircObj.ConvertToPolyObj( false, false );
     368           0 :                 Polygon aPoly(pPathObj->GetPathPoly().getB2DPolygon(0L));
     369             : 
     370           0 :                 IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, "", bActive, false );
     371           0 :                 pObj->SetExtraEllipse( aPoly.GetBoundRect() );
     372             : 
     373             :                 // was only created by us temporarily
     374           0 :                 delete pPathObj;
     375           0 :                 pUserData->ReplaceObject( IMapObjectPtr(pObj) );
     376             :             }
     377           0 :             break;
     378             : 
     379             :             case( OBJ_POLY ):
     380             :             case( OBJ_FREEFILL ):
     381             :             case( OBJ_PATHPOLY ):
     382             :             case( OBJ_PATHFILL ):
     383             :             {
     384           0 :                 const SdrPathObj& rPathObj = (const SdrPathObj&) rObj;
     385           0 :                 const basegfx::B2DPolyPolygon& rXPolyPoly = rPathObj.GetPathPoly();
     386             : 
     387           0 :                 if ( rXPolyPoly.count() )
     388             :                 {
     389           0 :                     Polygon aPoly(rPathObj.GetPathPoly().getB2DPolygon(0L));
     390           0 :                     IMapPolygonObject*  pObj = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, "", bActive, false );
     391           0 :                     pUserData->ReplaceObject( IMapObjectPtr(pObj) );
     392             :                 }
     393             :             }
     394           0 :             break;
     395             : 
     396             :             default:
     397           0 :             break;
     398           0 :         }
     399             :     }
     400           0 : }
     401             : 
     402           0 : void IMapWindow::MouseButtonUp(const MouseEvent& rMEvt)
     403             : {
     404           0 :     GraphCtrl::MouseButtonUp( rMEvt );
     405           0 :     UpdateInfo( sal_True );
     406           0 : }
     407             : 
     408           0 : void IMapWindow::MarkListHasChanged()
     409             : {
     410           0 :     GraphCtrl::MarkListHasChanged();
     411           0 :     UpdateInfo( sal_False );
     412           0 : }
     413             : 
     414           0 : SdrObject* IMapWindow::GetHitSdrObj( const Point& rPosPixel ) const
     415             : {
     416           0 :     SdrObject*  pObj = NULL;
     417           0 :     Point       aPt = PixelToLogic( rPosPixel );
     418             : 
     419           0 :     if ( Rectangle( Point(), GetGraphicSize() ).IsInside( aPt ) )
     420             :     {
     421           0 :         SdrPage* pPage = (SdrPage*) pModel->GetPage( 0 );
     422             :         sal_uIntPtr  nCount;
     423             : 
     424           0 :         if ( pPage && ( ( nCount = pPage->GetObjCount() ) > 0 ) )
     425             :         {
     426           0 :             for ( long i = nCount - 1; i >= 0; i-- )
     427             :             {
     428           0 :                 SdrObject*  pTestObj = pPage->GetObj( i );
     429           0 :                 IMapObject* pIMapObj = GetIMapObj( pTestObj );
     430             : 
     431           0 :                 if ( pIMapObj && pIMapObj->IsHit( aPt ) )
     432             :                 {
     433           0 :                     pObj = pTestObj;
     434           0 :                     break;
     435             :                 }
     436             :             }
     437             :         }
     438             :     }
     439             : 
     440           0 :     return pObj;
     441             : }
     442             : 
     443           0 : IMapObject* IMapWindow::GetIMapObj( const SdrObject* pSdrObj ) const
     444             : {
     445           0 :     IMapObject* pIMapObj = NULL;
     446             : 
     447           0 :     if ( pSdrObj )
     448             :     {
     449           0 :         IMapUserData* pUserData = (IMapUserData*) pSdrObj->GetUserData( 0 );
     450             : 
     451           0 :         if ( pUserData )
     452           0 :             pIMapObj = pUserData->GetObject().get();
     453             :     }
     454             : 
     455           0 :     return pIMapObj;
     456             : }
     457             : 
     458           0 : void IMapWindow::Command(const CommandEvent& rCEvt)
     459             : {
     460           0 :     Region  aRegion;
     461             : 
     462           0 :     if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
     463             :     {
     464           0 :         PopupMenu           aMenu( SVX_RES( RID_SVXMN_IMAP ) );
     465           0 :         const SdrMarkList&  rMarkList = pView->GetMarkedObjectList();
     466           0 :         sal_uIntPtr             nMarked = rMarkList.GetMarkCount();
     467             : 
     468           0 :         aMenu.EnableItem( MN_URL, false );
     469           0 :         aMenu.EnableItem( MN_ACTIVATE, false );
     470           0 :         aMenu.EnableItem( MN_MACRO, false );
     471           0 :         aMenu.EnableItem( MN_MARK_ALL, pModel->GetPage( 0 )->GetObjCount() != pView->GetMarkedObjectCount() );
     472             : 
     473           0 :         if ( !nMarked )
     474             :         {
     475           0 :             aMenu.EnableItem( MN_POSITION, false );
     476           0 :             aMenu.EnableItem( MN_FRAME_TO_TOP, false );
     477           0 :             aMenu.EnableItem( MN_MOREFRONT, false );
     478           0 :             aMenu.EnableItem( MN_MOREBACK, false );
     479           0 :             aMenu.EnableItem( MN_FRAME_TO_BOTTOM, false );
     480           0 :             aMenu.EnableItem( MN_DELETE1, false );
     481             :         }
     482             :         else
     483             :         {
     484           0 :             if ( nMarked == 1 )
     485             :             {
     486           0 :                 SdrObject*  pSdrObj = GetSelectedSdrObject();
     487             : 
     488           0 :                 aMenu.EnableItem( MN_URL, true );
     489           0 :                 aMenu.EnableItem( MN_ACTIVATE, true );
     490           0 :                 aMenu.EnableItem( MN_MACRO, true );
     491           0 :                 aMenu.CheckItem( MN_ACTIVATE, GetIMapObj( pSdrObj )->IsActive() );
     492             :             }
     493             : 
     494           0 :             aMenu.EnableItem( MN_POSITION, true );
     495           0 :             aMenu.EnableItem( MN_FRAME_TO_TOP, true );
     496           0 :             aMenu.EnableItem( MN_MOREFRONT, true );
     497           0 :             aMenu.EnableItem( MN_MOREBACK, true );
     498           0 :             aMenu.EnableItem( MN_FRAME_TO_BOTTOM, true );
     499           0 :             aMenu.EnableItem( MN_DELETE1, true );
     500             :         }
     501             : 
     502           0 :         aMenu.SetSelectHdl( LINK( this, IMapWindow, MenuSelectHdl ) );
     503           0 :         aMenu.Execute( this, rCEvt.GetMousePosPixel() );
     504             :     }
     505             :     else
     506           0 :         Window::Command(rCEvt);
     507           0 : }
     508             : 
     509           0 : sal_Int8 IMapWindow::AcceptDrop( const AcceptDropEvent& rEvt )
     510             : {
     511           0 :     return( ( GetHitSdrObj( rEvt.maPosPixel ) != NULL ) ? rEvt.mnAction : DND_ACTION_NONE );
     512             : }
     513             : 
     514           0 : sal_Int8 IMapWindow::ExecuteDrop( const ExecuteDropEvent& rEvt )
     515             : {
     516           0 :     sal_Int8 nRet = DND_ACTION_NONE;
     517             : 
     518           0 :     if( IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) )
     519             :     {
     520           0 :         const OUString  aString;
     521           0 :         INetBookmark    aBookMark( aString, aString );
     522           0 :         SdrObject*      pSdrObj = GetHitSdrObj( rEvt.maPosPixel );
     523             : 
     524           0 :         if( pSdrObj && TransferableDataHelper( rEvt.maDropEvent.Transferable ).GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aBookMark ) )
     525             :         {
     526           0 :             IMapObject* pIMapObj = GetIMapObj( pSdrObj );
     527             : 
     528           0 :             pIMapObj->SetURL( aBookMark.GetURL() );
     529           0 :             pIMapObj->SetAltText( aBookMark.GetDescription() );
     530           0 :             pModel->SetChanged( true );
     531           0 :             pView->UnmarkAll();
     532           0 :             pView->MarkObj( pSdrObj, pView->GetSdrPageView() );
     533           0 :             UpdateInfo( sal_True );
     534           0 :             nRet =  rEvt.mnAction;
     535           0 :         }
     536             :     }
     537             : 
     538           0 :     return nRet;
     539             : }
     540             : 
     541           0 : void IMapWindow::RequestHelp( const HelpEvent& rHEvt )
     542             : {
     543           0 :     Point               aPos = PixelToLogic( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
     544             : 
     545           0 :     if ( Help::IsBalloonHelpEnabled() || Help::IsQuickHelpEnabled() )
     546             :     {
     547           0 :         SdrObject*          pSdrObj = NULL;
     548           0 :         SdrPageView*        pPageView = NULL;
     549           0 :         if ( pView->PickObj( aPos, pView->getHitTolLog(), pSdrObj, pPageView ) )
     550             :         {
     551           0 :             const IMapObject*   pIMapObj = GetIMapObj( pSdrObj );
     552           0 :             OUString            aStr;
     553             : 
     554           0 :             if ( pIMapObj && !( aStr = pIMapObj->GetURL() ).isEmpty() )
     555             :             {
     556           0 :                 Rectangle   aLogicPix( LogicToPixel( Rectangle( Point(), GetGraphicSize() ) ) );
     557           0 :                 Rectangle   aScreenRect( OutputToScreenPixel( aLogicPix.TopLeft() ),
     558           0 :                                          OutputToScreenPixel( aLogicPix.BottomRight() ) );
     559             : 
     560           0 :                 if ( Help::IsBalloonHelpEnabled() )
     561           0 :                     Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), aScreenRect, aStr );
     562           0 :                 else if ( Help::IsQuickHelpEnabled() )
     563           0 :                     Help::ShowQuickHelp( this, aScreenRect, aStr );
     564           0 :             }
     565             :         }
     566             :         else
     567           0 :             Window::RequestHelp( rHEvt );
     568             :     }
     569           0 : }
     570             : 
     571           0 : void IMapWindow::SetCurrentObjState( sal_Bool bActive )
     572             : {
     573           0 :     SdrObject* pObj = GetSelectedSdrObject();
     574             : 
     575           0 :     if ( pObj )
     576             :     {
     577           0 :         SfxItemSet aSet( pModel->GetItemPool() );
     578             : 
     579           0 :         GetIMapObj( pObj )->SetActive( bActive );
     580             : 
     581           0 :         aSet.Put( XFillColorItem( "", TRANSCOL ) );
     582             : 
     583           0 :         if ( !bActive )
     584             :         {
     585           0 :             aSet.Put( XFillTransparenceItem( 100 ) );
     586           0 :             aSet.Put( XLineColorItem( "", Color( COL_RED ) ) );
     587             :         }
     588             :         else
     589             :         {
     590           0 :             aSet.Put( XFillTransparenceItem( 50 ) );
     591           0 :             aSet.Put( XLineColorItem( "", Color( COL_BLACK ) ) );
     592             :         }
     593             : 
     594           0 :         pView->SetAttributes( aSet, false );
     595             :     }
     596           0 : }
     597             : 
     598           0 : void IMapWindow::UpdateInfo( sal_Bool bNewObj )
     599             : {
     600           0 :     if ( aInfoLink.IsSet() )
     601             :     {
     602           0 :         const SdrObject*    pSdrObj = GetSelectedSdrObject();
     603           0 :         const IMapObject*   pIMapObj = pSdrObj ? GetIMapObj( pSdrObj ) : NULL;
     604             : 
     605           0 :         aInfo.bNewObj = bNewObj;
     606             : 
     607           0 :         if ( pIMapObj )
     608             :         {
     609           0 :             aInfo.bOneMarked = sal_True;
     610           0 :             aInfo.aMarkURL = pIMapObj->GetURL();
     611           0 :             aInfo.aMarkAltText = pIMapObj->GetAltText();
     612           0 :             aInfo.aMarkTarget = pIMapObj->GetTarget();
     613           0 :             aInfo.bActivated = pIMapObj->IsActive();
     614           0 :             aInfoLink.Call( this );
     615             :         }
     616             :         else
     617             :         {
     618           0 :             aInfo.aMarkURL = aInfo.aMarkAltText = aInfo.aMarkTarget = "";
     619           0 :             aInfo.bOneMarked = sal_False;
     620           0 :             aInfo.bActivated = sal_False;
     621             :         }
     622             : 
     623           0 :         aInfoLink.Call( this );
     624             :     }
     625           0 : }
     626             : 
     627           0 : void IMapWindow::DoMacroAssign()
     628             : {
     629           0 :     SdrObject*  pSdrObj = GetSelectedSdrObject();
     630             : 
     631           0 :     if ( pSdrObj )
     632             :     {
     633           0 :         SfxItemSet      aSet( *pIMapPool, SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 );
     634             : 
     635           0 :         SfxEventNamesItem aNamesItem(SID_EVENTCONFIG);
     636           0 :         aNamesItem.AddEvent( "MouseOver", "", SFX_EVENT_MOUSEOVER_OBJECT );
     637           0 :         aNamesItem.AddEvent( "MouseOut", "", SFX_EVENT_MOUSEOUT_OBJECT );
     638           0 :         aSet.Put( aNamesItem );
     639             : 
     640           0 :         SvxMacroItem    aMacroItem(SID_ATTR_MACROITEM);
     641           0 :         IMapObject*     pIMapObj = GetIMapObj( pSdrObj );
     642           0 :         aMacroItem.SetMacroTable( pIMapObj->GetMacroTable() );
     643           0 :         aSet.Put( aMacroItem, SID_ATTR_MACROITEM );
     644             : 
     645           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     646           0 :         SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( this, aSet, mxDocumentFrame, SID_EVENTCONFIG );
     647             : 
     648           0 :         if ( pMacroDlg && pMacroDlg->Execute() == RET_OK )
     649             :         {
     650           0 :             const SfxItemSet* pOutSet = pMacroDlg->GetOutputItemSet();
     651           0 :             pIMapObj->SetMacroTable( ((const SvxMacroItem& )pOutSet->Get( SID_ATTR_MACROITEM )).GetMacroTable() );
     652           0 :             pModel->SetChanged( true );
     653           0 :             UpdateInfo( sal_False );
     654             :         }
     655             : 
     656           0 :         delete pMacroDlg;
     657             :     }
     658           0 : }
     659             : 
     660           0 : void IMapWindow::DoPropertyDialog()
     661             : {
     662           0 :     SdrObject*  pSdrObj = GetSelectedSdrObject();
     663             : 
     664           0 :     if ( pSdrObj )
     665             :     {
     666           0 :         IMapObject* pIMapObj = GetIMapObj( pSdrObj );
     667           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     668           0 :         if(pFact)
     669             :         {
     670           0 :             AbstractURLDlg* aDlg = pFact->CreateURLDialog( this, pIMapObj->GetURL(), pIMapObj->GetAltText(), pIMapObj->GetDesc(),
     671           0 :                                             pIMapObj->GetTarget(), pIMapObj->GetName(), aTargetList );
     672             :             DBG_ASSERT(aDlg, "Dialogdiet fail!");
     673           0 :             if ( aDlg->Execute() == RET_OK )
     674             :             {
     675           0 :                 const OUString aURLText( aDlg->GetURL() );
     676             : 
     677           0 :                 if ( !aURLText.isEmpty() )
     678             :                 {
     679           0 :                     INetURLObject aObj( aURLText, INET_PROT_FILE );
     680             :                     DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL" );
     681           0 :                     pIMapObj->SetURL( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
     682             :                 }
     683             :                 else
     684           0 :                     pIMapObj->SetURL( aURLText );
     685             : 
     686           0 :                 pIMapObj->SetAltText( aDlg->GetAltText() );
     687           0 :                 pIMapObj->SetDesc( aDlg->GetDesc() );
     688           0 :                 pIMapObj->SetTarget( aDlg->GetTarget() );
     689           0 :                 pIMapObj->SetName( aDlg->GetName() );
     690           0 :                 pModel->SetChanged( true );
     691           0 :                 UpdateInfo( sal_True );
     692             :             }
     693           0 :             delete aDlg;
     694             :         }
     695             :     }
     696           0 : }
     697             : 
     698           0 : IMPL_LINK( IMapWindow, MenuSelectHdl, Menu*, pMenu )
     699             : {
     700           0 :     if (pMenu)
     701             :     {
     702           0 :         sal_uInt16  nId = pMenu->GetCurItemId();
     703             : 
     704           0 :         switch(nId)
     705             :         {
     706             :             case( MN_URL ):
     707           0 :                 DoPropertyDialog();
     708           0 :             break;
     709             : 
     710             :             case( MN_MACRO ):
     711           0 :                 DoMacroAssign();
     712           0 :             break;
     713             : 
     714             :             case( MN_ACTIVATE ):
     715             :             {
     716           0 :                 const sal_Bool bNewState = !pMenu->IsItemChecked( MN_ACTIVATE );
     717             : 
     718           0 :                 pMenu->CheckItem( MN_ACTIVATE, bNewState );
     719           0 :                 SetCurrentObjState( bNewState );
     720           0 :                 UpdateInfo( sal_False );
     721             :             }
     722             : 
     723             :             case( MN_FRAME_TO_TOP ):
     724           0 :                 pView->PutMarkedToTop();
     725           0 :             break;
     726             : 
     727             :             case( MN_MOREFRONT ):
     728           0 :                 pView->MovMarkedToTop();
     729           0 :             break;
     730             : 
     731             :             case( MN_MOREBACK ):
     732           0 :                 pView->MovMarkedToBtm();
     733           0 :             break;
     734             : 
     735             :             case( MN_FRAME_TO_BOTTOM ):
     736           0 :                 pView->PutMarkedToBtm();
     737           0 :             break;
     738             : 
     739             :             case( MN_MARK_ALL ):
     740           0 :                 pView->MarkAll();
     741           0 :             break;
     742             : 
     743             :             case( MN_DELETE1 ):
     744           0 :                 pView->DeleteMarked();
     745             : 
     746             :             default :
     747           0 :             break;
     748             :         }
     749             :     }
     750             : 
     751           0 :     return 0;
     752             : }
     753             : 
     754           0 : void IMapWindow::CreateDefaultObject()
     755             : {
     756           0 :     SdrPageView* pPageView = pView->GetSdrPageView();
     757             : 
     758           0 :     if(pPageView)
     759             :     {
     760             :         // calc position and size
     761           0 :         Point aPagePos(0, 0); // = pPageView->GetOffset();
     762           0 :         Size aPageSize = pPageView->GetPage()->GetSize();
     763           0 :         sal_uInt32 nDefaultObjectSizeWidth = aPageSize.Width() / 4;
     764           0 :         sal_uInt32 nDefaultObjectSizeHeight = aPageSize.Height() / 4;
     765           0 :         aPagePos.X() += (aPageSize.Width() / 2) - (nDefaultObjectSizeWidth / 2);
     766           0 :         aPagePos.Y() += (aPageSize.Height() / 2) - (nDefaultObjectSizeHeight / 2);
     767           0 :         Rectangle aNewObjectRectangle(aPagePos, Size(nDefaultObjectSizeWidth, nDefaultObjectSizeHeight));
     768             : 
     769           0 :         SdrObject* pObj = SdrObjFactory::MakeNewObject( pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(), 0L, pModel);
     770           0 :         pObj->SetLogicRect(aNewObjectRectangle);
     771             : 
     772           0 :         switch( pObj->GetObjIdentifier() )
     773             :         {
     774             :         case OBJ_POLY:
     775             :         case OBJ_PATHPOLY:
     776             :             {
     777           0 :                 basegfx::B2DPolygon aInnerPoly;
     778           0 :                 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.BottomLeft().X(), aNewObjectRectangle.BottomLeft().Y()));
     779           0 :                 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.TopLeft().X(), aNewObjectRectangle.TopLeft().Y()));
     780           0 :                 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.TopCenter().X(), aNewObjectRectangle.TopCenter().Y()));
     781           0 :                 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.Center().X(), aNewObjectRectangle.Center().Y()));
     782           0 :                 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.RightCenter().X(), aNewObjectRectangle.RightCenter().Y()));
     783           0 :                 aInnerPoly.append(basegfx::B2DPoint(aNewObjectRectangle.BottomRight().X(), aNewObjectRectangle.BottomRight().Y()));
     784           0 :                 aInnerPoly.setClosed(true);
     785           0 :                 ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aInnerPoly));
     786           0 :                 break;
     787             :             }
     788             :         case OBJ_FREEFILL:
     789             :         case OBJ_PATHFILL:
     790             :             {
     791           0 :                 sal_Int32 nWdt(aNewObjectRectangle.GetWidth() / 2);
     792           0 :                 sal_Int32 nHgt(aNewObjectRectangle.GetHeight() / 2);
     793           0 :                 basegfx::B2DPolygon aInnerPoly(XPolygon(aNewObjectRectangle.Center(), nWdt, nHgt).getB2DPolygon());
     794           0 :                 ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aInnerPoly));
     795           0 :                 break;
     796             :             }
     797             : 
     798             :         }
     799             : 
     800           0 :         pView->InsertObjectAtView(pObj, *pPageView);
     801           0 :         SdrObjCreated( *pObj );
     802           0 :         SetCurrentObjState( true );
     803           0 :         pView->MarkObj( pObj, pPageView );
     804             :     }
     805           0 : }
     806             : 
     807           0 : void IMapWindow::KeyInput( const KeyEvent& rKEvt )
     808             : {
     809           0 :     GraphCtrl::KeyInput( rKEvt );
     810           0 : }
     811             : 
     812           0 : void IMapWindow::SelectFirstObject()
     813             : {
     814           0 :     SdrPage*    pPage = (SdrPage*) pModel->GetPage( 0 );
     815           0 :     if( pPage->GetObjCount() != 0 )
     816             :     {
     817           0 :         GrabFocus();
     818           0 :         pView->UnmarkAllObj();
     819           0 :         pView->MarkNextObj(true);
     820             :     }
     821           0 : }
     822             : 
     823           0 : void IMapWindow::StartPolyEdit()
     824             : {
     825           0 :     GrabFocus();
     826             : 
     827           0 :     if( !pView->AreObjectsMarked() )
     828           0 :         pView->MarkNextObj(true);
     829             : 
     830           0 :     const SdrHdlList& rHdlList = pView->GetHdlList();
     831           0 :     SdrHdl* pHdl = rHdlList.GetFocusHdl();
     832             : 
     833           0 :     if(!pHdl)
     834             :     {
     835           0 :         ((SdrHdlList&)rHdlList).TravelFocusHdl(true);
     836             :     }
     837         255 : }
     838             : 
     839             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10