LCOV - code coverage report
Current view: top level - sfx2/source/appl - appdde.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 124 16.9 %
Date: 2012-08-25 Functions: 5 28 17.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 177 6.8 %

           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                 :            : #include <vcl/wrkwin.hxx>
      21                 :            : #include <svl/rectitem.hxx>
      22                 :            : #include <svl/eitem.hxx>
      23                 :            : #include <svl/intitem.hxx>
      24                 :            : #include <basic/sbstar.hxx>
      25                 :            : #include <svl/stritem.hxx>
      26                 :            : #include <svl/svdde.hxx>
      27                 :            : #include <sfx2/lnkbase.hxx>
      28                 :            : #include <sfx2/linkmgr.hxx>
      29                 :            : 
      30                 :            : #include <tools/urlobj.hxx>
      31                 :            : #include <tools/diagnose_ex.h>
      32                 :            : #include <unotools/pathoptions.hxx>
      33                 :            : 
      34                 :            : #include <sfx2/app.hxx>
      35                 :            : #include "appdata.hxx"
      36                 :            : #include <sfx2/objsh.hxx>
      37                 :            : #include <sfx2/viewfrm.hxx>
      38                 :            : #include <sfx2/dispatch.hxx>
      39                 :            : #include "sfxtypes.hxx"
      40                 :            : #include <sfx2/sfxsids.hrc>
      41                 :            : #include "helper.hxx"
      42                 :            : #include <sfx2/docfile.hxx>
      43                 :            : #include <comphelper/string.hxx>
      44                 :            : #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
      45                 :            : 
      46                 :            : //========================================================================
      47                 :            : 
      48                 :          0 : String SfxDdeServiceName_Impl( const String& sIn )
      49                 :            : {
      50                 :          0 :     String sReturn;
      51                 :            : 
      52         [ #  # ]:          0 :     for ( sal_uInt16 n = sIn.Len(); n; --n )
      53                 :            :     {
      54                 :          0 :         sal_Unicode cChar = sIn.GetChar(n-1);
      55 [ #  # ][ #  # ]:          0 :         if (comphelper::string::isalnumAscii(cChar))
      56         [ #  # ]:          0 :             sReturn += cChar;
      57                 :            :     }
      58                 :            : 
      59                 :          0 :     return sReturn;
      60                 :            : }
      61                 :            : 
      62                 :            : #if defined( WNT )
      63                 :            : class ImplDdeService : public DdeService
      64                 :            : {
      65                 :            : public:
      66                 :            :     ImplDdeService( const String& rNm )
      67                 :            :         : DdeService( rNm )
      68                 :            :     {}
      69                 :            :     virtual sal_Bool MakeTopic( const rtl::OUString& );
      70                 :            : 
      71                 :            :     virtual String  Topics();
      72                 :            : 
      73                 :            :     virtual sal_Bool SysTopicExecute( const String* pStr );
      74                 :            : };
      75                 :            : 
      76                 :            : //--------------------------------------------------------------------
      77                 :            : namespace
      78                 :            : {
      79                 :            :     sal_Bool lcl_IsDocument( const String& rContent )
      80                 :            :     {
      81                 :            :         using namespace com::sun::star;
      82                 :            : 
      83                 :            :         sal_Bool bRet = sal_False;
      84                 :            :         INetURLObject aObj( rContent );
      85                 :            :         DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
      86                 :            : 
      87                 :            :         try
      88                 :            :         {
      89                 :            :             ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
      90                 :            :             bRet = aCnt.isDocument();
      91                 :            :         }
      92                 :            :         catch( const ucb::CommandAbortedException& )
      93                 :            :         {
      94                 :            :             DBG_WARNING( "CommandAbortedException" );
      95                 :            :         }
      96                 :            :         catch( const ucb::IllegalIdentifierException& )
      97                 :            :         {
      98                 :            :             DBG_WARNING( "IllegalIdentifierException" );
      99                 :            :         }
     100                 :            :         catch( const ucb::ContentCreationException& )
     101                 :            :         {
     102                 :            :             DBG_WARNING( "IllegalIdentifierException" );
     103                 :            :         }
     104                 :            :         catch( const uno::Exception& )
     105                 :            :         {
     106                 :            :             SAL_WARN( "sfx2.appl", "Any other exception" );
     107                 :            :         }
     108                 :            : 
     109                 :            :         return bRet;
     110                 :            :     }
     111                 :            : }
     112                 :            : 
     113                 :            : sal_Bool ImplDdeService::MakeTopic( const rtl::OUString& rNm )
     114                 :            : {
     115                 :            :     // Workaround for Event after Main() under OS/2
     116                 :            :     // happens when exiting starts the App again
     117                 :            :     if ( !Application::IsInExecute() )
     118                 :            :         return sal_False;
     119                 :            : 
     120                 :            :     // The Topic rNm is sought, do we have it?
     121                 :            :     // First only loop over the ObjectShells to find those
     122                 :            :     // with the specific name:
     123                 :            :     sal_Bool bRet = sal_False;
     124                 :            :     String sNm( rNm );
     125                 :            :     sNm.ToLowerAscii();
     126                 :            :     TypeId aType( TYPE(SfxObjectShell) );
     127                 :            :     SfxObjectShell* pShell = SfxObjectShell::GetFirst( &aType );
     128                 :            :     while( pShell )
     129                 :            :     {
     130                 :            :         String sTmp( pShell->GetTitle(SFX_TITLE_FULLNAME) );
     131                 :            :         sTmp.ToLowerAscii();
     132                 :            :         if( sTmp == sNm )
     133                 :            :         {
     134                 :            :             SFX_APP()->AddDdeTopic( pShell );
     135                 :            :             bRet = sal_True;
     136                 :            :             break;
     137                 :            :         }
     138                 :            :         pShell = SfxObjectShell::GetNext( *pShell, &aType );
     139                 :            :     }
     140                 :            : 
     141                 :            :     if( !bRet )
     142                 :            :     {
     143                 :            :         INetURLObject aWorkPath( SvtPathOptions().GetWorkPath() );
     144                 :            :         INetURLObject aFile;
     145                 :            :         if ( aWorkPath.GetNewAbsURL( rNm, &aFile ) &&
     146                 :            :              lcl_IsDocument( aFile.GetMainURL( INetURLObject::NO_DECODE ) ) )
     147                 :            :         {
     148                 :            :             // File exists? then try to load it:
     149                 :            :             SfxStringItem aName( SID_FILE_NAME, aFile.GetMainURL( INetURLObject::NO_DECODE ) );
     150                 :            :             SfxBoolItem aNewView(SID_OPEN_NEW_VIEW, sal_True);
     151                 :            : 
     152                 :            :             SfxBoolItem aSilent(SID_SILENT, sal_True);
     153                 :            :             SfxDispatcher* pDispatcher = SFX_APP()->GetDispatcher_Impl();
     154                 :            :             const SfxPoolItem* pRet = pDispatcher->Execute( SID_OPENDOC,
     155                 :            :                     SFX_CALLMODE_SYNCHRON,
     156                 :            :                     &aName, &aNewView,
     157                 :            :                     &aSilent, 0L );
     158                 :            : 
     159                 :            :             if( pRet && pRet->ISA( SfxViewFrameItem ) &&
     160                 :            :                 ((SfxViewFrameItem*)pRet)->GetFrame() &&
     161                 :            :                 0 != ( pShell = ((SfxViewFrameItem*)pRet)
     162                 :            :                     ->GetFrame()->GetObjectShell() ) )
     163                 :            :             {
     164                 :            :                 SFX_APP()->AddDdeTopic( pShell );
     165                 :            :                 bRet = sal_True;
     166                 :            :             }
     167                 :            :         }
     168                 :            :     }
     169                 :            :     return bRet;
     170                 :            : }
     171                 :            : 
     172                 :            : String ImplDdeService::Topics()
     173                 :            : {
     174                 :            :     String sRet;
     175                 :            :     if( GetSysTopic() )
     176                 :            :         sRet += GetSysTopic()->GetName();
     177                 :            : 
     178                 :            :     TypeId aType( TYPE(SfxObjectShell) );
     179                 :            :     SfxObjectShell* pShell = SfxObjectShell::GetFirst( &aType );
     180                 :            :     while( pShell )
     181                 :            :     {
     182                 :            :         if( SfxViewFrame::GetFirst( pShell ) )
     183                 :            :         {
     184                 :            :             if( sRet.Len() )
     185                 :            :                 sRet += '\t';
     186                 :            :             sRet += pShell->GetTitle(SFX_TITLE_FULLNAME);
     187                 :            :         }
     188                 :            :         pShell = SfxObjectShell::GetNext( *pShell, &aType );
     189                 :            :     }
     190                 :            :     if( sRet.Len() )
     191                 :            :         sRet += DEFINE_CONST_UNICODE("\r\n");
     192                 :            :     return sRet;
     193                 :            : }
     194                 :            : 
     195                 :            : sal_Bool ImplDdeService::SysTopicExecute( const String* pStr )
     196                 :            : {
     197                 :            :     return (sal_Bool)SFX_APP()->DdeExecute( *pStr );
     198                 :            : }
     199                 :            : #endif
     200                 :            : 
     201         [ #  # ]:          0 : class SfxDdeTriggerTopic_Impl : public DdeTopic
     202                 :            : {
     203                 :            : public:
     204                 :            :     SfxDdeTriggerTopic_Impl()
     205                 :            :     : DdeTopic( DEFINE_CONST_UNICODE("TRIGGER") )
     206                 :            :     {}
     207                 :            : 
     208                 :            :     virtual sal_Bool Execute( const String* );
     209                 :            : };
     210                 :            : 
     211 [ #  # ][ #  # ]:          0 : class SfxDdeDocTopic_Impl : public DdeTopic
                 [ #  # ]
     212                 :            : {
     213                 :            : public:
     214                 :            :     SfxObjectShell* pSh;
     215                 :            :     DdeData aData;
     216                 :            :     ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
     217                 :            : 
     218                 :            :     SfxDdeDocTopic_Impl( SfxObjectShell* pShell )
     219                 :            :         : DdeTopic( pShell->GetTitle(SFX_TITLE_FULLNAME) ), pSh( pShell )
     220                 :            :     {}
     221                 :            : 
     222                 :            :     virtual DdeData* Get( sal_uIntPtr );
     223                 :            :     virtual sal_Bool Put( const DdeData* );
     224                 :            :     virtual sal_Bool Execute( const String* );
     225                 :            :     virtual sal_Bool StartAdviseLoop();
     226                 :            :     virtual sal_Bool MakeItem( const rtl::OUString& rItem );
     227                 :            : };
     228                 :            : 
     229                 :            : 
     230                 :          0 : class SfxDdeDocTopics_Impl : public std::vector<SfxDdeDocTopic_Impl*> {};
     231                 :            : 
     232                 :            : //========================================================================
     233                 :            : 
     234                 :          0 : sal_Bool SfxAppEvent_Impl( ApplicationEvent &rAppEvent,
     235                 :            :                            const String &rCmd, const String &rEvent,
     236                 :            :                            ApplicationEvent::Type eType )
     237                 :            : 
     238                 :            : /*  [Description]
     239                 :            : 
     240                 :            :     Checks if 'rCmd' of the event 'rEvent' is (without '(') and then assemble
     241                 :            :     this data into a <ApplicationEvent>, which can be excecuted through
     242                 :            :     <Application::AppEvent()>. If 'rCmd' is the given event 'rEvent', then
     243                 :            :     TRUE is returned, otherwise FALSE.
     244                 :            : 
     245                 :            :     [Example]
     246                 :            : 
     247                 :            :     rCmd = "Open(\"d:\doc\doc.sdw\")"
     248                 :            :     rEvent = "Open"
     249                 :            : */
     250                 :            : 
     251                 :            : {
     252         [ #  # ]:          0 :     String aEvent( rEvent );
     253         [ #  # ]:          0 :     aEvent += '(';
     254 [ #  # ][ #  # ]:          0 :     if ( rCmd.CompareIgnoreCaseToAscii( aEvent, aEvent.Len() ) == COMPARE_EQUAL )
     255                 :            :     {
     256 [ #  # ][ #  # ]:          0 :         ::rtl::OUStringBuffer aData( rCmd );
     257         [ #  # ]:          0 :         aData.remove( 0, aEvent.Len() );
     258         [ #  # ]:          0 :         if ( aData.getLength() > 2 )
     259                 :            :         {
     260                 :            :             // Transform into the ApplicationEvent Format
     261         [ #  # ]:          0 :             aData.remove( aData.getLength() - 1, 1 );
     262         [ #  # ]:          0 :             for ( sal_Int32 n = 0; n < aData.getLength(); )
     263                 :            :             {
     264      [ #  #  # ]:          0 :                 switch ( aData[n] )
     265                 :            :                 {
     266                 :            :                 case '"':
     267         [ #  # ]:          0 :                     aData.remove( n, 1 );
     268 [ #  # ][ #  # ]:          0 :                     while ( n < aData.getLength() && aData[n] != '"' )
                 [ #  # ]
     269                 :          0 :                         ++n;
     270         [ #  # ]:          0 :                     if ( n < aData.getLength() )
     271         [ #  # ]:          0 :                         aData.remove( n, 1 );
     272                 :          0 :                     break;
     273                 :            :                 case ' ':
     274                 :          0 :                     aData[n++] = '\n';
     275                 :          0 :                     break;
     276                 :            :                 default:
     277                 :          0 :                     ++n;
     278                 :          0 :                     break;
     279                 :            :                 }
     280                 :            :             }
     281                 :            : 
     282 [ #  # ][ #  # ]:          0 :             rAppEvent = ApplicationEvent(eType, aData.makeStringAndClear());
                 [ #  # ]
     283                 :          0 :             return sal_True;
     284         [ #  # ]:          0 :         }
     285                 :            :     }
     286                 :            : 
     287         [ #  # ]:          0 :     return sal_False;
     288                 :            : }
     289                 :            : 
     290                 :            : #if defined( WNT )
     291                 :            : long SfxApplication::DdeExecute
     292                 :            : (
     293                 :            :     const String&   rCmd  // Expressed in our BASIC-Syntax
     294                 :            : )
     295                 :            : 
     296                 :            : /*  Description]
     297                 :            : 
     298                 :            :     This method can be overloaded by application developers, to receive
     299                 :            :     DDE-commands directed to thier SfxApplication subclass.
     300                 :            : 
     301                 :            :     The base implementation understands the API functionality of the
     302                 :            :     relevant SfxApplication subclass in BASIC syntax. Return values can
     303                 :            :     not be transferred, unfortunately.
     304                 :            : */
     305                 :            : 
     306                 :            : {
     307                 :            :     // Print or Open-Event?
     308                 :            :     ApplicationEvent aAppEvent;
     309                 :            :     if ( SfxAppEvent_Impl( aAppEvent, rCmd, DEFINE_CONST_UNICODE("Print"), ApplicationEvent::TYPE_PRINT ) ||
     310                 :            :          SfxAppEvent_Impl( aAppEvent, rCmd, DEFINE_CONST_UNICODE("Open"), ApplicationEvent::TYPE_OPEN ) )
     311                 :            :         GetpApp()->AppEvent( aAppEvent );
     312                 :            :     else
     313                 :            :     {
     314                 :            :         // all others are BASIC
     315                 :            :         StarBASIC* pBasic = GetBasic();
     316                 :            :         DBG_ASSERT( pBasic, "Where is the Basic???" );
     317                 :            :         SbxVariable* pRet = pBasic->Execute( rCmd );
     318                 :            :         if( !pRet )
     319                 :            :         {
     320                 :            :             SbxBase::ResetError();
     321                 :            :             return 0;
     322                 :            :         }
     323                 :            :     }
     324                 :            :     return 1;
     325                 :            : }
     326                 :            : #endif
     327                 :            : 
     328                 :          0 : long SfxObjectShell::DdeExecute
     329                 :            : (
     330                 :            :     const String&   rCmd  // Expressed in our BASIC-Syntax
     331                 :            : )
     332                 :            : 
     333                 :            : /*  [Description]
     334                 :            : 
     335                 :            :     This method can be overloaded by application developers, to receive
     336                 :            :     DDE-commands directed to the thier SfxApplication subclass.
     337                 :            : 
     338                 :            :     The base implementation does nothing and returns 0.
     339                 :            : */
     340                 :            : 
     341                 :            : {
     342                 :            : #ifdef DISABLE_SCRIPTING
     343                 :            :     (void) rCmd;
     344                 :            : #else
     345                 :          0 :     StarBASIC* pBasic = GetBasic();
     346                 :            :     DBG_ASSERT( pBasic, "Where is the Basic???" ) ;
     347                 :          0 :     SbxVariable* pRet = pBasic->Execute( rCmd );
     348         [ #  # ]:          0 :     if( !pRet )
     349                 :            :     {
     350                 :          0 :         SbxBase::ResetError();
     351                 :          0 :         return 0;
     352                 :            :     }
     353                 :            : #endif
     354                 :          0 :     return 1;
     355                 :            : }
     356                 :            : 
     357                 :            : //--------------------------------------------------------------------
     358                 :            : 
     359                 :          0 : long SfxObjectShell::DdeGetData
     360                 :            : (
     361                 :            :     const String&,              // the Item to be addressed
     362                 :            :     const String&,              // in: Format
     363                 :            :     ::com::sun::star::uno::Any& // out: requested data
     364                 :            : )
     365                 :            : 
     366                 :            : /*  [Description]
     367                 :            : 
     368                 :            :     This method can be overloaded by application developers, to receive
     369                 :            :     DDE-data-requests directed to thier SfxApplication subclass.
     370                 :            : 
     371                 :            :     The base implementation provides no data and returns 0.
     372                 :            : */
     373                 :            : 
     374                 :            : {
     375                 :          0 :     return 0;
     376                 :            : }
     377                 :            : 
     378                 :            : //--------------------------------------------------------------------
     379                 :            : 
     380                 :          0 : long SfxObjectShell::DdeSetData
     381                 :            : (
     382                 :            :     const String&,                    // the Item to be addressed
     383                 :            :     const String&,                    // in: Format
     384                 :            :     const ::com::sun::star::uno::Any& // out: requested data
     385                 :            : )
     386                 :            : 
     387                 :            : /*  [Description]
     388                 :            : 
     389                 :            :     This method can be overloaded by application developers, to receive
     390                 :            :     DDE-data directed to thier SfxApplication subclass.
     391                 :            : 
     392                 :            :     The base implementation is not receiving any data and returns 0.
     393                 :            : */
     394                 :            : 
     395                 :            : {
     396                 :          0 :     return 0;
     397                 :            : }
     398                 :            : 
     399                 :            : //--------------------------------------------------------------------
     400                 :          0 : ::sfx2::SvLinkSource* SfxObjectShell::DdeCreateLinkSource
     401                 :            : (
     402                 :            :     const String&  // the Item to be addressed
     403                 :            : )
     404                 :            : 
     405                 :            : /*  [Description]
     406                 :            : 
     407                 :            :     This method can be overloaded by application developers, to establish
     408                 :            :     a DDE-hotlink to thier SfxApplication subclass.
     409                 :            : 
     410                 :            :     The base implementation is not generate a link and returns 0.
     411                 :            : */
     412                 :            : 
     413                 :            : {
     414                 :          0 :     return 0;
     415                 :            : }
     416                 :            : 
     417                 :       1593 : void SfxObjectShell::ReconnectDdeLink(SfxObjectShell& /*rServer*/)
     418                 :            : {
     419                 :       1593 : }
     420                 :            : 
     421                 :        880 : void SfxObjectShell::ReconnectDdeLinks(SfxObjectShell& rServer)
     422                 :            : {
     423         [ +  - ]:        880 :     TypeId aType = TYPE(SfxObjectShell);
     424         [ +  - ]:        880 :     SfxObjectShell* p = GetFirst(&aType, false);
     425         [ +  + ]:       5828 :     while (p)
     426                 :            :     {
     427         [ +  + ]:       4948 :         if (&rServer != p)
     428         [ +  - ]:       4068 :             p->ReconnectDdeLink(rServer);
     429                 :            : 
     430         [ +  - ]:       4948 :         p = GetNext(*p, &aType, false);
     431                 :            :     }
     432                 :        880 : }
     433                 :            : 
     434                 :            : //========================================================================
     435                 :            : 
     436                 :          0 : long SfxViewFrame::DdeExecute
     437                 :            : (
     438                 :            :     const String&   rCmd  // Expressed in our BASIC-Syntax
     439                 :            : )
     440                 :            : 
     441                 :            : /*  [Description]
     442                 :            : 
     443                 :            :     This method can be overloaded by application developers, to receive
     444                 :            :     DDE-commands directed to the thier SfxApplication subclass.
     445                 :            : 
     446                 :            :     The base implementation understands the API functionality of the
     447                 :            :     relevant SfxViewFrame, which is shown and the relevant SfxViewShell
     448                 :            :     and the relevant SfxApplication subclass in BASIC syntax. Return
     449                 :            :     values can not be transferred, unfortunately.
     450                 :            : */
     451                 :            : 
     452                 :            : {
     453         [ #  # ]:          0 :     if ( GetObjectShell() )
     454                 :          0 :         return GetObjectShell()->DdeExecute( rCmd );
     455                 :            : 
     456                 :          0 :     return 0;
     457                 :            : }
     458                 :            : 
     459                 :            : //--------------------------------------------------------------------
     460                 :            : 
     461                 :          0 : long SfxViewFrame::DdeGetData
     462                 :            : (
     463                 :            :     const String&,              // the Item to be addressed
     464                 :            :     const String&,              // in: Format
     465                 :            :     ::com::sun::star::uno::Any& // out: requested data
     466                 :            : )
     467                 :            : 
     468                 :            : /*  [Description]
     469                 :            : 
     470                 :            :     This method can be overloaded by application developers, to receive
     471                 :            :     DDE-data-requests directed to thier SfxApplication subclass.
     472                 :            : 
     473                 :            :     The base implementation provides no data and returns 0.
     474                 :            : */
     475                 :            : 
     476                 :            : {
     477                 :          0 :     return 0;
     478                 :            : }
     479                 :            : 
     480                 :            : //--------------------------------------------------------------------
     481                 :            : 
     482                 :          0 : long SfxViewFrame::DdeSetData
     483                 :            : (
     484                 :            :     const String&,                    // the Item to be addressed
     485                 :            :     const String&,                    // in: Format
     486                 :            :     const ::com::sun::star::uno::Any& // out: requested data
     487                 :            : )
     488                 :            : 
     489                 :            : /*  [Description]
     490                 :            : 
     491                 :            :     This method can be overloaded by application developers, to receive
     492                 :            :     DDE-data directed to thier SfxApplication subclass.
     493                 :            : 
     494                 :            :     The base implementation is not receiving any data and returns 0.
     495                 :            : */
     496                 :            : 
     497                 :            : {
     498                 :          0 :     return 0;
     499                 :            : }
     500                 :            : 
     501                 :            : //--------------------------------------------------------------------
     502                 :            : 
     503                 :          0 : ::sfx2::SvLinkSource* SfxViewFrame::DdeCreateLinkSource
     504                 :            : (
     505                 :            :     const String&  // the Item to be addressed
     506                 :            : )
     507                 :            : 
     508                 :            : /*  [Description]
     509                 :            : 
     510                 :            :     This method can be overloaded by application developers, to establish
     511                 :            :     a DDE-hotlink to thier SfxApplication subclass.
     512                 :            : 
     513                 :            :     The base implementation is not generate a link and returns 0.
     514                 :            : */
     515                 :            : 
     516                 :            : {
     517                 :          0 :     return 0;
     518                 :            : }
     519                 :            : 
     520                 :            : //========================================================================
     521                 :            : 
     522                 :        233 : sal_Bool SfxApplication::InitializeDde()
     523                 :            : {
     524                 :        233 :     int nError = 0;
     525                 :            : #if defined( WNT )
     526                 :            :     DBG_ASSERT( !pAppData_Impl->pDdeService,
     527                 :            :                 "Dde can not be initialized multiple times" );
     528                 :            : 
     529                 :            :     pAppData_Impl->pDdeService = new ImplDdeService( Application::GetAppName() );
     530                 :            :     nError = pAppData_Impl->pDdeService->GetError();
     531                 :            :     if( !nError )
     532                 :            :     {
     533                 :            :         pAppData_Impl->pDocTopics = new SfxDdeDocTopics_Impl;
     534                 :            : 
     535                 :            :         // we certainly want to support RTF!
     536                 :            :         pAppData_Impl->pDdeService->AddFormat( FORMAT_RTF );
     537                 :            : 
     538                 :            :         // Config path as a topic becauseof multiple starts
     539                 :            :         INetURLObject aOfficeLockFile( SvtPathOptions().GetUserConfigPath() );
     540                 :            :         aOfficeLockFile.insertName( DEFINE_CONST_UNICODE( "soffice.lck" ) );
     541                 :            :         String aService( SfxDdeServiceName_Impl(
     542                 :            :                     aOfficeLockFile.GetMainURL(INetURLObject::DECODE_TO_IURI) ) );
     543                 :            :         aService.ToUpperAscii();
     544                 :            :         pAppData_Impl->pDdeService2 = new ImplDdeService( aService );
     545                 :            :         pAppData_Impl->pTriggerTopic = new SfxDdeTriggerTopic_Impl;
     546                 :            :         pAppData_Impl->pDdeService2->AddTopic( *pAppData_Impl->pTriggerTopic );
     547                 :            :     }
     548                 :            : #endif
     549                 :        233 :     return !nError;
     550                 :            : }
     551                 :            : 
     552                 :        158 : void SfxAppData_Impl::DeInitDDE()
     553                 :            : {
     554         [ -  + ]:        158 :     DELETEZ( pTriggerTopic );
     555         [ -  + ]:        158 :     DELETEZ( pDdeService2 );
     556         [ -  + ]:        158 :     DELETEZ( pDocTopics );
     557         [ -  + ]:        158 :     DELETEZ( pDdeService );
     558                 :        158 : }
     559                 :            : 
     560                 :            : #if defined( WNT )
     561                 :            : void SfxApplication::AddDdeTopic( SfxObjectShell* pSh )
     562                 :            : {
     563                 :            :     DBG_ASSERT( pAppData_Impl->pDocTopics, "There is no Dde-Service" );
     564                 :            :     //OV: DDE is disconnected in server mode!
     565                 :            :     if( !pAppData_Impl->pDocTopics )
     566                 :            :         return;
     567                 :            : 
     568                 :            :     // prevent double submit
     569                 :            :     String sShellNm;
     570                 :            :     sal_Bool bFnd = sal_False;
     571                 :            :     for (size_t n = pAppData_Impl->pDocTopics->size(); n;)
     572                 :            :     {
     573                 :            :         if( (*pAppData_Impl->pDocTopics)[ --n ]->pSh == pSh )
     574                 :            :         {
     575                 :            :             // If the document is untitled, is still a new Topic is created!
     576                 :            :             if( !bFnd )
     577                 :            :             {
     578                 :            :                 bFnd = sal_True;
     579                 :            :                 (sShellNm = pSh->GetTitle(SFX_TITLE_FULLNAME)).ToLowerAscii();
     580                 :            :             }
     581                 :            :             String sNm( (*pAppData_Impl->pDocTopics)[ n ]->GetName() );
     582                 :            :             if( sShellNm == sNm.ToLowerAscii() )
     583                 :            :                 return ;
     584                 :            :         }
     585                 :            :     }
     586                 :            : 
     587                 :            :     SfxDdeDocTopic_Impl *const pTopic = new SfxDdeDocTopic_Impl(pSh);
     588                 :            :     pAppData_Impl->pDocTopics->push_back(pTopic);
     589                 :            :     pAppData_Impl->pDdeService->AddTopic( *pTopic );
     590                 :            : }
     591                 :            : #endif
     592                 :            : 
     593                 :          0 : void SfxApplication::RemoveDdeTopic( SfxObjectShell* pSh )
     594                 :            : {
     595                 :            :     DBG_ASSERT( pAppData_Impl->pDocTopics, "There is no Dde-Service" );
     596                 :            :     //OV: DDE is disconnected in server mode!
     597         [ #  # ]:          0 :     if( !pAppData_Impl->pDocTopics )
     598                 :          0 :         return;
     599                 :            : 
     600         [ #  # ]:          0 :     for (size_t n = pAppData_Impl->pDocTopics->size(); n; )
     601                 :            :     {
     602                 :          0 :         SfxDdeDocTopic_Impl *const pTopic = (*pAppData_Impl->pDocTopics)[ --n ];
     603         [ #  # ]:          0 :         if (pTopic->pSh == pSh)
     604                 :            :         {
     605                 :          0 :             pAppData_Impl->pDdeService->RemoveTopic( *pTopic );
     606         [ #  # ]:          0 :             delete pTopic;
     607 [ #  # ][ #  # ]:          0 :             pAppData_Impl->pDocTopics->erase( pAppData_Impl->pDocTopics->begin() + n );
     608                 :            :         }
     609                 :            :     }
     610                 :            : }
     611                 :            : 
     612                 :          0 : const DdeService* SfxApplication::GetDdeService() const
     613                 :            : {
     614                 :          0 :     return pAppData_Impl->pDdeService;
     615                 :            : }
     616                 :            : 
     617                 :       3403 : DdeService* SfxApplication::GetDdeService()
     618                 :            : {
     619                 :       3403 :     return pAppData_Impl->pDdeService;
     620                 :            : }
     621                 :            : 
     622                 :            : //--------------------------------------------------------------------
     623                 :            : 
     624                 :          0 : sal_Bool SfxDdeTriggerTopic_Impl::Execute( const String* )
     625                 :            : {
     626                 :          0 :     return sal_True;
     627                 :            : }
     628                 :            : 
     629                 :            : //--------------------------------------------------------------------
     630                 :          0 : DdeData* SfxDdeDocTopic_Impl::Get( sal_uIntPtr nFormat )
     631                 :            : {
     632         [ #  # ]:          0 :     String sMimeType( SotExchange::GetFormatMimeType( nFormat ));
     633                 :          0 :     ::com::sun::star::uno::Any aValue;
     634 [ #  # ][ #  # ]:          0 :     long nRet = pSh->DdeGetData( GetCurItem(), sMimeType, aValue );
                 [ #  # ]
     635 [ #  # ][ #  # ]:          0 :     if( nRet && aValue.hasValue() && ( aValue >>= aSeq ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     636                 :            :     {
     637 [ #  # ][ #  # ]:          0 :         aData = DdeData( aSeq.getConstArray(), aSeq.getLength(), nFormat );
                 [ #  # ]
     638                 :          0 :         return &aData;
     639                 :            :     }
     640         [ #  # ]:          0 :     aSeq.realloc( 0 );
     641         [ #  # ]:          0 :     return 0;
     642                 :            : }
     643                 :            : 
     644                 :          0 : sal_Bool SfxDdeDocTopic_Impl::Put( const DdeData* pData )
     645                 :            : {
     646                 :            :     aSeq = ::com::sun::star::uno::Sequence< sal_Int8 >(
     647         [ #  # ]:          0 :                             (sal_Int8*)(const void*)*pData, (long)*pData );
     648                 :            :     sal_Bool bRet;
     649         [ #  # ]:          0 :     if( aSeq.getLength() )
     650                 :            :     {
     651                 :          0 :         ::com::sun::star::uno::Any aValue;
     652         [ #  # ]:          0 :         aValue <<= aSeq;
     653 [ #  # ][ #  # ]:          0 :         String sMimeType( SotExchange::GetFormatMimeType( pData->GetFormat() ));
     654 [ #  # ][ #  # ]:          0 :         bRet = 0 != pSh->DdeSetData( GetCurItem(), sMimeType, aValue );
         [ #  # ][ #  # ]
     655                 :            :     }
     656                 :            :     else
     657                 :          0 :         bRet = sal_False;
     658                 :          0 :     return bRet;
     659                 :            : }
     660                 :            : 
     661                 :          0 : sal_Bool SfxDdeDocTopic_Impl::Execute( const String* pStr )
     662                 :            : {
     663         [ #  # ]:          0 :     long nRet = pStr ? pSh->DdeExecute( *pStr ) : 0;
     664                 :          0 :     return 0 != nRet;
     665                 :            : }
     666                 :            : 
     667                 :          0 : sal_Bool SfxDdeDocTopic_Impl::MakeItem( const rtl::OUString& rItem )
     668                 :            : {
     669 [ #  # ][ #  # ]:          0 :     AddItem( DdeItem( rItem ) );
                 [ #  # ]
     670                 :          0 :     return sal_True;
     671                 :            : }
     672                 :            : 
     673                 :          0 : sal_Bool SfxDdeDocTopic_Impl::StartAdviseLoop()
     674                 :            : {
     675                 :          0 :     sal_Bool bRet = sal_False;
     676         [ #  # ]:          0 :     ::sfx2::SvLinkSource* pNewObj = pSh->DdeCreateLinkSource( GetCurItem() );
     677         [ #  # ]:          0 :     if( pNewObj )
     678                 :            :     {
     679                 :            :         // then we also establish a corresponding SvBaseLink
     680 [ #  # ][ #  # ]:          0 :         String sNm, sTmp( Application::GetAppName() );
     681 [ #  # ][ #  # ]:          0 :         ::sfx2::MakeLnkName( sNm, &sTmp, pSh->GetTitle(SFX_TITLE_FULLNAME), GetCurItem() );
         [ #  # ][ #  # ]
                 [ #  # ]
     682 [ #  # ][ #  # ]:          0 :         new ::sfx2::SvBaseLink( sNm, OBJECT_DDE_EXTERN, pNewObj );
     683 [ #  # ][ #  # ]:          0 :         bRet = sal_True;
     684                 :            :     }
     685                 :          0 :     return bRet;
     686                 :            : }
     687                 :            : 
     688                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10