LCOV - code coverage report
Current view: top level - sfx2/source/appl - lnkbase2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 113 291 38.8 %
Date: 2012-08-25 Functions: 21 45 46.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 69 444 15.5 %

           Branch data     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                 :            : 
      21                 :            : #include <sfx2/lnkbase.hxx>
      22                 :            : #include <sot/exchange.hxx>
      23                 :            : #include <com/sun/star/uno/Any.hxx>
      24                 :            : #include <com/sun/star/uno/Sequence.hxx>
      25                 :            : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      26                 :            : #include <vcl/msgbox.hxx>
      27                 :            : #include <sfx2/linkmgr.hxx>
      28                 :            : #include <vcl/svapp.hxx>
      29                 :            : #include "app.hrc"
      30                 :            : #include "sfx2/sfxresid.hxx"
      31                 :            : #include <sfx2/filedlghelper.hxx>
      32                 :            : #include <tools/debug.hxx>
      33                 :            : #include <svl/svdde.hxx>
      34                 :            : 
      35                 :            : using namespace ::com::sun::star;
      36                 :            : using namespace ::com::sun::star::uno;
      37                 :            : 
      38                 :            : namespace sfx2
      39                 :            : {
      40                 :            : 
      41         [ -  + ]:         32 : TYPEINIT0( SvBaseLink )
      42                 :            : 
      43                 :            : static DdeTopic* FindTopic( const String &, sal_uInt16* = 0 );
      44                 :            : 
      45                 :            : class  ImplDdeItem;
      46                 :            : 
      47                 :            : struct BaseLink_Impl
      48                 :            : {
      49                 :            :     Link                m_aEndEditLink;
      50                 :            :     LinkManager*      m_pLinkMgr;
      51                 :            :     Window*             m_pParentWin;
      52                 :            :     FileDialogHelper*   m_pFileDlg;
      53                 :            :     bool                m_bIsConnect;
      54                 :            : 
      55                 :         40 :     BaseLink_Impl() :
      56                 :            :           m_pLinkMgr( NULL )
      57                 :            :         , m_pParentWin( NULL )
      58                 :            :         , m_pFileDlg( NULL )
      59                 :         40 :         , m_bIsConnect( false )
      60                 :         40 :         {}
      61                 :            : 
      62                 :         34 :     ~BaseLink_Impl()
      63         [ -  + ]:         34 :         { delete m_pFileDlg; }
      64                 :            : };
      65                 :            : 
      66                 :            : // only for internal management
      67                 :            : struct ImplBaseLinkData
      68                 :            : {
      69                 :            :     struct tClientType
      70                 :            :     {
      71                 :            :         // applies for all links
      72                 :            :         sal_uIntPtr nCntntType; // Update Format
      73                 :            :         // Not Ole-Links
      74                 :            :         sal_Bool    bIntrnlLnk;  // It is an internal link
      75                 :            :         sal_uInt16  nUpdateMode; // UpdateMode
      76                 :            :     };
      77                 :            : 
      78                 :            :     struct tDDEType
      79                 :            :     {
      80                 :            :         ImplDdeItem* pItem;
      81                 :            :     };
      82                 :            : 
      83                 :            :     union {
      84                 :            :         tClientType ClientType;
      85                 :            :         tDDEType DDEType;
      86                 :            :     };
      87                 :         40 :     ImplBaseLinkData()
      88                 :            :     {
      89                 :         40 :         ClientType.nCntntType = 0;
      90                 :         40 :         ClientType.bIntrnlLnk = sal_False;
      91                 :         40 :         ClientType.nUpdateMode = 0;
      92                 :         40 :         DDEType.pItem = NULL;
      93                 :         40 :     }
      94                 :            : };
      95                 :            : 
      96                 :            : 
      97                 :            : class ImplDdeItem : public DdeGetPutItem
      98                 :            : {
      99                 :            :     SvBaseLink* pLink;
     100                 :            :     DdeData aData;
     101                 :            :     Sequence< sal_Int8 > aSeq;  // Datacontainer for DdeData !!!
     102                 :            :     sal_Bool bIsValidData : 1;
     103                 :            :     sal_Bool bIsInDTOR : 1;
     104                 :            : public:
     105                 :          0 :     ImplDdeItem( SvBaseLink& rLink, const String& rStr )
     106                 :            :         : DdeGetPutItem( rStr ), pLink( &rLink ), bIsValidData( sal_False ),
     107 [ #  # ][ #  # ]:          0 :         bIsInDTOR( sal_False )
     108                 :          0 :     {}
     109                 :            :     virtual ~ImplDdeItem();
     110                 :            : 
     111                 :            :     virtual DdeData* Get( sal_uIntPtr );
     112                 :            :     virtual sal_Bool Put( const DdeData* );
     113                 :            :     virtual void AdviseLoop( sal_Bool );
     114                 :            : 
     115                 :          0 :     void Notify()
     116                 :            :     {
     117                 :          0 :         bIsValidData = sal_False;
     118                 :          0 :         DdeGetPutItem::NotifyClient();
     119                 :          0 :     }
     120                 :            : 
     121                 :          0 :     sal_Bool IsInDTOR() const { return bIsInDTOR; }
     122                 :            : };
     123                 :            : 
     124                 :            : //--------------------------------------------------------------------------
     125                 :            : 
     126         [ #  # ]:          0 : SvBaseLink::SvBaseLink()
     127                 :            : {
     128 [ #  # ][ #  # ]:          0 :     pImpl = new BaseLink_Impl();
     129                 :          0 :     nObjType = OBJECT_CLIENT_SO;
     130         [ #  # ]:          0 :     pImplData = new ImplBaseLinkData;
     131                 :          0 :     bVisible = bSynchron = bUseCache = sal_True;
     132                 :          0 :     bWasLastEditOK = sal_False;
     133                 :          0 : }
     134                 :            : 
     135                 :            : //--------------------------------------------------------------------------
     136                 :            : 
     137         [ +  - ]:         40 : SvBaseLink::SvBaseLink( sal_uInt16 nUpdateMode, sal_uIntPtr nContentType )
     138                 :            : {
     139 [ +  - ][ +  - ]:         40 :     pImpl = new BaseLink_Impl();
     140                 :         40 :     nObjType = OBJECT_CLIENT_SO;
     141         [ +  - ]:         40 :     pImplData = new ImplBaseLinkData;
     142                 :         40 :     bVisible = bSynchron = bUseCache = sal_True;
     143                 :         40 :     bWasLastEditOK = sal_False;
     144                 :            : 
     145                 :            :     // It it going to be a Ole-Link,
     146                 :         40 :     pImplData->ClientType.nUpdateMode = nUpdateMode;
     147                 :         40 :     pImplData->ClientType.nCntntType = nContentType;
     148                 :         40 :     pImplData->ClientType.bIntrnlLnk = sal_False;
     149                 :         40 : }
     150                 :            : 
     151                 :            : //--------------------------------------------------------------------------
     152                 :            : 
     153                 :          0 : SvBaseLink::SvBaseLink( const String& rLinkName, sal_uInt16 nObjectType, SvLinkSource* pObj )
     154         [ #  # ]:          0 :     : pImpl(0)
     155                 :            : {
     156                 :          0 :     bVisible = bSynchron = bUseCache = sal_True;
     157                 :          0 :     bWasLastEditOK = sal_False;
     158         [ #  # ]:          0 :     aLinkName = rLinkName;
     159         [ #  # ]:          0 :     pImplData = new ImplBaseLinkData;
     160                 :          0 :     nObjType = nObjectType;
     161                 :            : 
     162         [ #  # ]:          0 :     if( !pObj )
     163                 :            :     {
     164                 :            :         DBG_ASSERT( pObj, "Where is my left-most object" );
     165                 :          0 :         return;
     166                 :            :     }
     167                 :            : 
     168         [ #  # ]:          0 :     if( OBJECT_DDE_EXTERN == nObjType )
     169                 :            :     {
     170                 :          0 :         sal_uInt16 nItemStt = 0;
     171         [ #  # ]:          0 :         DdeTopic* pTopic = FindTopic( aLinkName, &nItemStt );
     172         [ #  # ]:          0 :         if( pTopic )
     173                 :            :         {
     174                 :            :             // then we have it all together
     175                 :            :             // MM_TODO how do I get the name
     176         [ #  # ]:          0 :             String aStr = aLinkName; // xLinkName->GetDisplayName();
     177 [ #  # ][ #  # ]:          0 :             aStr = aStr.Copy( nItemStt );
                 [ #  # ]
     178 [ #  # ][ #  # ]:          0 :             pImplData->DDEType.pItem = new ImplDdeItem( *this, aStr );
     179         [ #  # ]:          0 :             pTopic->InsertItem( pImplData->DDEType.pItem );
     180                 :            : 
     181                 :            :             // store the Advice
     182 [ #  # ][ #  # ]:          0 :             xObj = pObj;
     183                 :            :         }
     184                 :            :     }
     185 [ #  # ][ #  # ]:          0 :     else if( pObj->Connect( this ) )
     186         [ #  # ]:          0 :         xObj = pObj;
     187                 :            : }
     188                 :            : 
     189                 :            : //--------------------------------------------------------------------------
     190                 :            : 
     191 [ +  - ][ +  - ]:         34 : SvBaseLink::~SvBaseLink()
     192                 :            : {
     193         [ +  - ]:         34 :     Disconnect();
     194                 :            : 
     195         [ -  + ]:         34 :     switch( nObjType )
     196                 :            :     {
     197                 :            :     case OBJECT_DDE_EXTERN:
     198         [ #  # ]:          0 :         if( !pImplData->DDEType.pItem->IsInDTOR() )
     199 [ #  # ][ #  # ]:          0 :             delete pImplData->DDEType.pItem;
     200                 :          0 :         break;
     201                 :            :     }
     202                 :            : 
     203                 :         34 :     delete pImplData;
     204 [ +  - ][ +  - ]:         34 :     delete pImpl;
     205         [ -  + ]:         34 : }
     206                 :            : 
     207                 :          0 : IMPL_LINK( SvBaseLink, EndEditHdl, String*, _pNewName )
     208                 :            : {
     209         [ #  # ]:          0 :     String sNewName;
     210         [ #  # ]:          0 :     if ( _pNewName )
     211         [ #  # ]:          0 :         sNewName = *_pNewName;
     212 [ #  # ][ #  # ]:          0 :     if ( !ExecuteEdit( sNewName ) )
     213         [ #  # ]:          0 :         sNewName.Erase();
     214                 :          0 :     bWasLastEditOK = ( sNewName.Len() > 0 );
     215 [ #  # ][ #  # ]:          0 :     if ( pImpl->m_aEndEditLink.IsSet() )
     216         [ #  # ]:          0 :         pImpl->m_aEndEditLink.Call( this );
     217         [ #  # ]:          0 :     return 0;
     218                 :            : }
     219                 :            : 
     220                 :            : //--------------------------------------------------------------------------
     221                 :            : 
     222                 :         48 : void SvBaseLink::SetObjType( sal_uInt16 nObjTypeP )
     223                 :            : {
     224                 :            :     DBG_ASSERT( nObjType != OBJECT_CLIENT_DDE, "type already set" );
     225                 :            :     DBG_ASSERT( !xObj.Is(), "object exist" );
     226                 :            : 
     227                 :         48 :     nObjType = nObjTypeP;
     228                 :         48 : }
     229                 :            : 
     230                 :            : //--------------------------------------------------------------------------
     231                 :            : 
     232                 :         46 : void SvBaseLink::SetName( const String & rNm )
     233                 :            : {
     234                 :         46 :     aLinkName = rNm;
     235                 :         46 : }
     236                 :            : 
     237                 :            : //--------------------------------------------------------------------------
     238                 :            : 
     239                 :          5 : void SvBaseLink::SetObj( SvLinkSource * pObj )
     240                 :            : {
     241                 :            :     DBG_ASSERT( (nObjType & OBJECT_CLIENT_SO &&
     242                 :            :                 pImplData->ClientType.bIntrnlLnk) ||
     243                 :            :                 nObjType == OBJECT_CLIENT_GRF,
     244                 :            :                 "no intern link" );
     245                 :          5 :     xObj = pObj;
     246                 :          5 : }
     247                 :            : 
     248                 :            : //--------------------------------------------------------------------------
     249                 :            : 
     250                 :         16 : void SvBaseLink::SetLinkSourceName( const String & rLnkNm )
     251                 :            : {
     252         [ -  + ]:         16 :     if( aLinkName == rLnkNm )
     253                 :         16 :         return;
     254                 :            : 
     255                 :         16 :     AddNextRef(); // should be superfluous
     256                 :            :     // remove old connection
     257                 :         16 :     Disconnect();
     258                 :            : 
     259                 :         16 :     aLinkName = rLnkNm;
     260                 :            : 
     261                 :            :     // New Connection
     262                 :         16 :     _GetRealObject();
     263                 :         16 :     ReleaseRef(); // should be superfluous
     264                 :            : }
     265                 :            : 
     266                 :            : //--------------------------------------------------------------------------
     267                 :            : 
     268                 :        589 : String  SvBaseLink::GetLinkSourceName() const
     269                 :            : {
     270                 :        589 :     return aLinkName;
     271                 :            : }
     272                 :            : 
     273                 :            : //--------------------------------------------------------------------------
     274                 :            : 
     275                 :         67 : void SvBaseLink::SetUpdateMode( sal_uInt16 nMode )
     276                 :            : {
     277 [ +  - ][ +  + ]:         67 :     if( ( OBJECT_CLIENT_SO & nObjType ) &&
     278                 :            :         pImplData->ClientType.nUpdateMode != nMode )
     279                 :            :     {
     280                 :         22 :         AddNextRef();
     281                 :         22 :         Disconnect();
     282                 :            : 
     283                 :         22 :         pImplData->ClientType.nUpdateMode = nMode;
     284                 :         22 :         _GetRealObject();
     285                 :         22 :         ReleaseRef();
     286                 :            :     }
     287                 :         67 : }
     288                 :            : 
     289                 :            : // #i88291#
     290                 :          0 : void SvBaseLink::clearStreamToLoadFrom()
     291                 :            : {
     292                 :          0 :     m_xInputStreamToLoadFrom.clear();
     293         [ #  # ]:          0 :     if( xObj.Is() )
     294                 :            :     {
     295                 :          0 :         xObj->clearStreamToLoadFrom();
     296                 :            :     }
     297                 :          0 : }
     298                 :            : 
     299                 :         59 : sal_Bool SvBaseLink::Update()
     300                 :            : {
     301         [ +  - ]:         59 :     if( OBJECT_CLIENT_SO & nObjType )
     302                 :            :     {
     303                 :         59 :         AddNextRef();
     304                 :         59 :         Disconnect();
     305                 :            : 
     306                 :         59 :         _GetRealObject();
     307                 :         59 :         ReleaseRef();
     308         [ +  + ]:         59 :         if( xObj.Is() )
     309                 :            :         {
     310         [ +  - ]:         57 :             xObj->setStreamToLoadFrom(m_xInputStreamToLoadFrom,m_bIsReadOnly);
     311                 :            :             String sMimeType( SotExchange::GetFormatMimeType(
     312         [ +  - ]:         57 :                             pImplData->ClientType.nCntntType ));
     313                 :         57 :             Any aData;
     314                 :            : 
     315 [ +  - ][ +  - ]:         57 :             if( xObj->GetData( aData, sMimeType ) )
     316                 :            :             {
     317         [ +  - ]:         57 :                 UpdateResult eRes = DataChanged(sMimeType, aData);
     318                 :         57 :                 bool bSuccess = eRes == SUCCESS;
     319                 :            :                 //for manual Updates there is no need to hold the ServerObject
     320         [ +  + ]:         62 :                 if( OBJECT_CLIENT_DDE == nObjType &&
           [ -  +  #  # ]
                 [ -  + ]
     321         [ +  - ]:          5 :                     LINKUPDATE_ONCALL == GetUpdateMode() && xObj.Is() )
     322         [ #  # ]:          0 :                     xObj->RemoveAllDataAdvise( this );
     323                 :         57 :                 return bSuccess;
     324                 :            :             }
     325         [ #  # ]:          0 :             if( xObj.Is() )
     326                 :            :             {
     327                 :            :                 // should be asynschron?
     328 [ #  # ][ #  # ]:          0 :                 if( xObj->IsPending() )
     329                 :          0 :                     return sal_True;
     330                 :            : 
     331                 :            :                 // we do not need the object anymore
     332                 :          0 :                 AddNextRef();
     333         [ #  # ]:          0 :                 Disconnect();
     334         [ #  # ]:          0 :                 ReleaseRef();
     335 [ +  - ][ +  - ]:         57 :             }
                 [ -  + ]
     336                 :            :         }
     337                 :            :     }
     338                 :         59 :     return sal_False;
     339                 :            : }
     340                 :            : 
     341                 :            : 
     342                 :         22 : sal_uInt16 SvBaseLink::GetUpdateMode() const
     343                 :            : {
     344                 :            :     return ( OBJECT_CLIENT_SO & nObjType )
     345                 :            :             ? pImplData->ClientType.nUpdateMode
     346         [ +  - ]:         22 :             : sal::static_int_cast< sal_uInt16 >( LINKUPDATE_ONCALL );
     347                 :            : }
     348                 :            : 
     349                 :            : 
     350                 :         97 : void SvBaseLink::_GetRealObject( sal_Bool bConnect)
     351                 :            : {
     352         [ +  + ]:         97 :     if( !pImpl->m_pLinkMgr )
     353                 :         97 :         return;
     354                 :            : 
     355                 :            :     DBG_ASSERT( !xObj.Is(), "object already exist" );
     356                 :            : 
     357         [ +  + ]:         67 :     if( OBJECT_CLIENT_DDE == nObjType )
     358                 :            :     {
     359         [ +  - ]:          7 :         String sServer;
     360 [ +  - ][ +  - ]:         21 :         if( pImpl->m_pLinkMgr->GetDisplayNames( this, &sServer ) &&
         [ +  + ][ +  + ]
     361 [ +  - ][ +  - ]:         14 :             sServer == GetpApp()->GetAppName() )  // internal Link !!!
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     362                 :            :         {
     363                 :            :             // so that the Internal link can be created!
     364                 :          5 :             nObjType = OBJECT_INTERN;
     365 [ +  - ][ +  - ]:          5 :             xObj = pImpl->m_pLinkMgr->CreateObj( this );
                 [ +  - ]
     366                 :            : 
     367                 :          5 :             pImplData->ClientType.bIntrnlLnk = sal_True;
     368                 :          5 :             nObjType = OBJECT_CLIENT_DDE;  // so we know what it once was!
     369                 :            :         }
     370                 :            :         else
     371                 :            :         {
     372                 :          2 :             pImplData->ClientType.bIntrnlLnk = sal_False;
     373 [ +  - ][ +  - ]:          2 :             xObj = pImpl->m_pLinkMgr->CreateObj( this );
                 [ +  - ]
     374         [ +  - ]:          7 :         }
     375                 :            :     }
     376         [ +  - ]:         60 :     else if( (OBJECT_CLIENT_SO & nObjType) )
     377         [ +  - ]:         60 :         xObj = pImpl->m_pLinkMgr->CreateObj( this );
     378                 :            : 
     379 [ +  - ][ +  - ]:         67 :     if( bConnect && ( !xObj.Is() || !xObj->Connect( this ) ) )
         [ +  + ][ +  + ]
     380                 :          2 :         Disconnect();
     381                 :            : }
     382                 :            : 
     383                 :         89 : sal_uIntPtr SvBaseLink::GetContentType() const
     384                 :            : {
     385         [ +  - ]:         89 :     if( OBJECT_CLIENT_SO & nObjType )
     386                 :         89 :         return pImplData->ClientType.nCntntType;
     387                 :            : 
     388                 :         89 :     return 0;  // all Formats ?
     389                 :            : }
     390                 :            : 
     391                 :            : 
     392                 :         19 : sal_Bool SvBaseLink::SetContentType( sal_uIntPtr nType )
     393                 :            : {
     394         [ +  - ]:         19 :     if( OBJECT_CLIENT_SO & nObjType )
     395                 :            :     {
     396                 :         19 :         pImplData->ClientType.nCntntType = nType;
     397                 :         19 :         return sal_True;
     398                 :            :     }
     399                 :         19 :     return sal_False;
     400                 :            : }
     401                 :            : 
     402                 :        447 : LinkManager* SvBaseLink::GetLinkManager()
     403                 :            : {
     404                 :        447 :     return pImpl->m_pLinkMgr;
     405                 :            : }
     406                 :            : 
     407                 :          0 : const LinkManager* SvBaseLink::GetLinkManager() const
     408                 :            : {
     409                 :          0 :     return pImpl->m_pLinkMgr;
     410                 :            : }
     411                 :            : 
     412                 :        110 : void SvBaseLink::SetLinkManager( LinkManager* _pMgr )
     413                 :            : {
     414                 :        110 :     pImpl->m_pLinkMgr = _pMgr;
     415                 :        110 : }
     416                 :            : 
     417                 :        196 : void SvBaseLink::Disconnect()
     418                 :            : {
     419         [ +  + ]:        196 :     if( xObj.Is() )
     420                 :            :     {
     421                 :         61 :         xObj->RemoveAllDataAdvise( this );
     422                 :         61 :         xObj->RemoveConnectAdvise( this );
     423                 :         61 :         xObj.Clear();
     424                 :            :     }
     425                 :        196 : }
     426                 :            : 
     427                 :          0 : SvBaseLink::UpdateResult SvBaseLink::DataChanged( const String &, const ::com::sun::star::uno::Any & )
     428                 :            : {
     429         [ #  # ]:          0 :     switch( nObjType )
     430                 :            :     {
     431                 :            :     case OBJECT_DDE_EXTERN:
     432         [ #  # ]:          0 :         if( pImplData->DDEType.pItem )
     433                 :          0 :             pImplData->DDEType.pItem->Notify();
     434                 :          0 :         break;
     435                 :            :     }
     436                 :          0 :     return SUCCESS;
     437                 :            : }
     438                 :            : 
     439                 :          0 : void SvBaseLink::Edit( Window* pParent, const Link& rEndEditHdl )
     440                 :            : {
     441                 :          0 :     pImpl->m_pParentWin = pParent;
     442                 :          0 :     pImpl->m_aEndEditLink = rEndEditHdl;
     443                 :          0 :     pImpl->m_bIsConnect = ( xObj.Is() != sal_False );
     444         [ #  # ]:          0 :     if( !pImpl->m_bIsConnect )
     445         [ #  # ]:          0 :         _GetRealObject( xObj.Is() );
     446                 :            : 
     447                 :          0 :     bool bAsync = false;
     448         [ #  # ]:          0 :     Link aLink = LINK( this, SvBaseLink, EndEditHdl );
     449                 :            : 
     450 [ #  # ][ #  # ]:          0 :     if( OBJECT_CLIENT_SO & nObjType && pImplData->ClientType.bIntrnlLnk )
     451                 :            :     {
     452         [ #  # ]:          0 :         if( pImpl->m_pLinkMgr )
     453                 :            :         {
     454         [ #  # ]:          0 :             SvLinkSourceRef ref = pImpl->m_pLinkMgr->CreateObj( this );
     455         [ #  # ]:          0 :             if( ref.Is() )
     456                 :            :             {
     457         [ #  # ]:          0 :                 ref->Edit( pParent, this, aLink );
     458                 :          0 :                 bAsync = true;
     459         [ #  # ]:          0 :             }
     460                 :          0 :         }
     461                 :            :     }
     462                 :            :     else
     463                 :            :     {
     464         [ #  # ]:          0 :         xObj->Edit( pParent, this, aLink );
     465                 :          0 :         bAsync = true;
     466                 :            :     }
     467                 :            : 
     468         [ #  # ]:          0 :     if ( !bAsync )
     469                 :            :     {
     470 [ #  # ][ #  # ]:          0 :         ExecuteEdit( String() );
                 [ #  # ]
     471                 :          0 :         bWasLastEditOK = sal_False;
     472 [ #  # ][ #  # ]:          0 :         if ( pImpl->m_aEndEditLink.IsSet() )
     473         [ #  # ]:          0 :             pImpl->m_aEndEditLink.Call( this );
     474                 :            :     }
     475                 :          0 : }
     476                 :            : 
     477                 :          0 : bool SvBaseLink::ExecuteEdit( const String& _rNewName )
     478                 :            : {
     479         [ #  # ]:          0 :     if( _rNewName.Len() != 0 )
     480                 :            :     {
     481                 :          0 :         SetLinkSourceName( _rNewName );
     482         [ #  # ]:          0 :         if( !Update() )
     483                 :            :         {
     484 [ #  # ][ #  # ]:          0 :             String sApp, sTopic, sItem, sError;
         [ #  # ][ #  # ]
     485         [ #  # ]:          0 :             pImpl->m_pLinkMgr->GetDisplayNames( this, &sApp, &sTopic, &sItem );
     486         [ #  # ]:          0 :             if( nObjType == OBJECT_CLIENT_DDE )
     487                 :            :             {
     488 [ #  # ][ #  # ]:          0 :                 sError = SFX2_RESSTR(STR_DDE_ERROR);
                 [ #  # ]
     489                 :            : 
     490         [ #  # ]:          0 :                 sal_uInt16 nFndPos = sError.Search( '%' );
     491         [ #  # ]:          0 :                 if( STRING_NOTFOUND != nFndPos )
     492                 :            :                 {
     493 [ #  # ][ #  # ]:          0 :                     sError.Erase( nFndPos, 1 ).Insert( sApp, nFndPos );
     494                 :          0 :                     nFndPos = nFndPos + sApp.Len();
     495                 :            :                 }
     496 [ #  # ][ #  # ]:          0 :                 if( STRING_NOTFOUND != ( nFndPos = sError.Search( '%', nFndPos )))
     497                 :            :                 {
     498 [ #  # ][ #  # ]:          0 :                     sError.Erase( nFndPos, 1 ).Insert( sTopic, nFndPos );
     499                 :          0 :                     nFndPos = nFndPos + sTopic.Len();
     500                 :            :                 }
     501 [ #  # ][ #  # ]:          0 :                 if( STRING_NOTFOUND != ( nFndPos = sError.Search( '%', nFndPos )))
     502 [ #  # ][ #  # ]:          0 :                     sError.Erase( nFndPos, 1 ).Insert( sItem, nFndPos );
     503                 :            :             }
     504                 :            :             else
     505                 :          0 :                 return false;
     506                 :            : 
     507 [ #  # ][ #  # ]:          0 :             ErrorBox( pImpl->m_pParentWin, WB_OK, sError ).Execute();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     508                 :            :         }
     509                 :            :     }
     510         [ #  # ]:          0 :     else if( !pImpl->m_bIsConnect )
     511                 :          0 :         Disconnect();
     512                 :          0 :     pImpl->m_bIsConnect = false;
     513                 :          0 :     return true;
     514                 :            : }
     515                 :            : 
     516                 :          0 : void SvBaseLink::Closed()
     517                 :            : {
     518         [ #  # ]:          0 :     if( xObj.Is() )
     519                 :          0 :         xObj->RemoveAllDataAdvise( this );
     520                 :          0 : }
     521                 :            : 
     522                 :          0 : FileDialogHelper & SvBaseLink::GetInsertFileDialog(const String& rFactory) const
     523                 :            : {
     524         [ #  # ]:          0 :     if ( pImpl->m_pFileDlg )
     525         [ #  # ]:          0 :         delete pImpl->m_pFileDlg;
     526                 :            :     pImpl->m_pFileDlg = new FileDialogHelper(
     527                 :            :             ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
     528         [ #  # ]:          0 :             SFXWB_INSERT, rFactory);
     529                 :          0 :     return *pImpl->m_pFileDlg;
     530                 :            : }
     531                 :            : 
     532 [ #  # ][ #  # ]:          0 : ImplDdeItem::~ImplDdeItem()
     533                 :            : {
     534                 :          0 :     bIsInDTOR = sal_True;
     535                 :            :     // So that no-one gets the idea to delete the pointer when Disconnecting!
     536                 :          0 :     SvBaseLinkRef aRef( pLink );
     537 [ #  # ][ #  # ]:          0 :     aRef->Disconnect();
     538         [ #  # ]:          0 : }
     539                 :            : 
     540                 :          0 : DdeData* ImplDdeItem::Get( sal_uIntPtr nFormat )
     541                 :            : {
     542         [ #  # ]:          0 :     if( pLink->GetObj() )
     543                 :            :     {
     544                 :            :         // is it still valid?
     545 [ #  # ][ #  # ]:          0 :         if( bIsValidData && nFormat == aData.GetFormat() )
         [ #  # ][ #  # ]
     546                 :          0 :             return &aData;
     547                 :            : 
     548                 :          0 :         Any aValue;
     549         [ #  # ]:          0 :         String sMimeType( SotExchange::GetFormatMimeType( nFormat ));
     550 [ #  # ][ #  # ]:          0 :         if( pLink->GetObj()->GetData( aValue, sMimeType ) )
     551                 :            :         {
     552 [ #  # ][ #  # ]:          0 :             if( aValue >>= aSeq )
     553                 :            :             {
     554 [ #  # ][ #  # ]:          0 :                 aData = DdeData( (const char *)aSeq.getConstArray(), aSeq.getLength(), nFormat );
                 [ #  # ]
     555                 :            : 
     556                 :          0 :                 bIsValidData = sal_True;
     557                 :          0 :                 return &aData;
     558                 :            :             }
     559 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
     560                 :            :     }
     561                 :          0 :     aSeq.realloc( 0 );
     562                 :          0 :     bIsValidData = sal_False;
     563                 :          0 :     return 0;
     564                 :            : }
     565                 :            : 
     566                 :            : 
     567                 :          0 : sal_Bool ImplDdeItem::Put( const DdeData*  )
     568                 :            : {
     569                 :            :     OSL_FAIL( "ImplDdeItem::Put not implemented" );
     570                 :          0 :     return sal_False;
     571                 :            : }
     572                 :            : 
     573                 :            : 
     574                 :          0 : void ImplDdeItem::AdviseLoop( sal_Bool bOpen )
     575                 :            : {
     576                 :            :     // Connection is closed, so also unsubscribe link
     577         [ #  # ]:          0 :     if( pLink->GetObj() )
     578                 :            :     {
     579         [ #  # ]:          0 :         if( bOpen )
     580                 :            :         {
     581                 :            :             // A connection is re-established
     582         [ #  # ]:          0 :             if( OBJECT_DDE_EXTERN == pLink->GetObjType() )
     583                 :            :             {
     584 [ #  # ][ #  # ]:          0 :                 pLink->GetObj()->AddDataAdvise( pLink, rtl::OUString("text/plain;charset=utf-16"),  ADVISEMODE_NODATA );
                 [ #  # ]
     585                 :          0 :                 pLink->GetObj()->AddConnectAdvise( pLink );
     586                 :            :             }
     587                 :            :         }
     588                 :            :         else
     589                 :            :         {
     590                 :            :             // So that no-one gets the idea to delete the pointer
     591                 :            :             // when Disconnecting!
     592                 :          0 :             SvBaseLinkRef aRef( pLink );
     593 [ #  # ][ #  # ]:          0 :             aRef->Disconnect();
     594                 :            :         }
     595                 :            :     }
     596                 :          0 : }
     597                 :            : 
     598                 :            : 
     599                 :          0 : static DdeTopic* FindTopic( const String & rLinkName, sal_uInt16* pItemStt )
     600                 :            : {
     601         [ #  # ]:          0 :     if( 0 == rLinkName.Len() )
     602                 :          0 :         return 0;
     603                 :            : 
     604         [ #  # ]:          0 :     String sNm( rLinkName );
     605                 :          0 :     sal_uInt16 nTokenPos = 0;
     606 [ #  # ][ #  # ]:          0 :     rtl::OUString sService( sNm.GetToken( 0, cTokenSeperator, nTokenPos ) );
                 [ #  # ]
     607                 :            : 
     608         [ #  # ]:          0 :     DdeServices& rSvc = DdeService::GetServices();
     609 [ #  # ][ #  # ]:          0 :     for (DdeServices::iterator aI = rSvc.begin(); aI != rSvc.end(); ++aI)
     610                 :            :     {
     611                 :          0 :         DdeService* pService = *aI;
     612 [ #  # ][ #  # ]:          0 :         if( pService->GetName() == sService )
     613                 :            :         {
     614                 :            :             // then we search for the Topic
     615 [ #  # ][ #  # ]:          0 :             rtl::OUString sTopic( sNm.GetToken( 0, cTokenSeperator, nTokenPos ) );
                 [ #  # ]
     616         [ #  # ]:          0 :             if( pItemStt )
     617                 :          0 :                 *pItemStt = nTokenPos;
     618                 :            : 
     619                 :          0 :             std::vector<DdeTopic*>& rTopics = pService->GetTopics();
     620                 :            : 
     621         [ #  # ]:          0 :             for( int i = 0; i < 2; ++i )
     622                 :            :             {
     623   [ #  #  #  # ]:          0 :                 for( std::vector<DdeTopic*>::iterator iterTopic = rTopics.begin();
                 [ #  # ]
     624                 :          0 :                      iterTopic != rTopics.end(); ++iterTopic )
     625 [ #  # ][ #  # ]:          0 :                     if( (*iterTopic)->GetName() == sTopic )
                 [ #  # ]
     626         [ #  # ]:          0 :                         return *iterTopic;
     627                 :            : 
     628                 :            :                 // Topic not found?
     629                 :            :                 // then we try once to create it
     630 [ #  # ][ #  # ]:          0 :                 if( i || !pService->MakeTopic( sTopic ) )
         [ #  # ][ #  # ]
     631                 :          0 :                     break;  // did not work, exiting
     632                 :            :             }
     633         [ #  # ]:          0 :             break;
     634                 :            :         }
     635                 :            :     }
     636         [ #  # ]:          0 :     return 0;
     637                 :            : }
     638                 :            : 
     639                 :            : }
     640                 :            : 
     641                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10