LCOV - code coverage report
Current view: top level - libreoffice/cui/source/dialogs - linkdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 389 0.0 %
Date: 2012-12-17 Functions: 0 30 0.0 %
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 <linkdlg.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : #include "helpid.hrc"
      23             : 
      24             : #include <tools/urlobj.hxx>
      25             : #include <svtools/svmedit.hxx>
      26             : #include <svtools/filedlg.hxx>
      27             : #include <vcl/dialog.hxx>
      28             : #include <vcl/button.hxx>
      29             : #include <vcl/fixed.hxx>
      30             : #include <vcl/group.hxx>
      31             : #include <vcl/lstbox.hxx>
      32             : #include <vcl/msgbox.hxx>
      33             : #include <vcl/timer.hxx>
      34             : #include <svtools/svtabbx.hxx>
      35             : #include "svtools/treelistentry.hxx"
      36             : 
      37             : #include <svuidlg.hrc>
      38             : #include <sfx2/linkmgr.hxx>
      39             : #include <sfx2/linksrc.hxx>
      40             : #include <svtools/soerr.hxx>
      41             : #include <sfx2/lnkbase.hxx>
      42             : #include <sfx2/objsh.hxx>
      43             : 
      44             : #include <dialmgr.hxx>
      45             : 
      46             : 
      47             : #define FILEOBJECT ( OBJECT_CLIENT_FILE & ~OBJECT_CLIENT_SO )
      48             : 
      49             : using namespace sfx2;
      50             : 
      51           0 : class SvBaseLinkMemberList : private std::vector<SvBaseLink*> {
      52             : public:
      53           0 :     ~SvBaseLinkMemberList()
      54           0 :     {
      55           0 :         for( const_iterator it = begin(); it != end(); ++it )
      56             :         {
      57           0 :             SvBaseLink* p = *it;
      58           0 :             if( p )
      59           0 :                 p->ReleaseReference();
      60             :         }
      61           0 :     }
      62             : 
      63             :     using std::vector<SvBaseLink*>::size;
      64             :     using std::vector<SvBaseLink*>::operator[];
      65             : 
      66           0 :     void push_back(SvBaseLink* p) { std::vector<SvBaseLink*>::push_back(p); p->AddRef(); }
      67             : };
      68             : 
      69             : // attention, this array is indexed directly (0, 1, ...) in the code
      70             : static long nTabs[] =
      71             :     {   4, // Number of Tabs
      72             :         0, 77, 144, 209
      73             :     };
      74             : 
      75             : 
      76           0 : SvBaseLinksDlg::SvBaseLinksDlg( Window * pParent, LinkManager* pMgr, sal_Bool bHtml )
      77           0 :     : ModalDialog( pParent, CUI_RES( MD_UPDATE_BASELINKS ) ),
      78           0 :     aFtFiles( this, CUI_RES( FT_FILES ) ),
      79           0 :     aFtLinks( this, CUI_RES( FT_LINKS ) ),
      80           0 :     aFtType( this, CUI_RES( FT_TYPE ) ),
      81           0 :     aFtStatus( this, CUI_RES( FT_STATUS ) ),
      82           0 :     aTbLinks( this, CUI_RES(TB_LINKS ) ),
      83           0 :     aFtFiles2( this, CUI_RES( FT_FILES2 ) ),
      84           0 :     aFtFullFileName( this, CUI_RES( FT_FULL_FILE_NAME ) ),
      85           0 :     aFtSource2( this, CUI_RES( FT_SOURCE2 ) ),
      86           0 :     aFtFullSourceName( this, CUI_RES( FT_FULL_SOURCE_NAME ) ),
      87           0 :     aFtType2( this, CUI_RES( FT_TYPE2 ) ),
      88           0 :     aFtFullTypeName( this, CUI_RES( FT_FULL_TYPE_NAME ) ),
      89           0 :     aFtUpdate( this, CUI_RES( FT_UPDATE ) ),
      90           0 :     aRbAutomatic( this, CUI_RES( RB_AUTOMATIC ) ),
      91           0 :     aRbManual( this, CUI_RES( RB_MANUAL ) ),
      92           0 :     aCancelButton1( this, CUI_RES( 1 ) ),
      93           0 :     aHelpButton1( this, CUI_RES( 1 ) ),
      94           0 :     aPbUpdateNow( this, CUI_RES( PB_UPDATE_NOW ) ),
      95           0 :     aPbOpenSource( this, CUI_RES( PB_OPEN_SOURCE ) ),
      96           0 :     aPbChangeSource( this, CUI_RES( PB_CHANGE_SOURCE ) ),
      97           0 :     aPbBreakLink( this, CUI_RES( PB_BREAK_LINK ) ),
      98           0 :     aStrAutolink( CUI_RES( STR_AUTOLINK ) ),
      99           0 :     aStrManuallink( CUI_RES( STR_MANUALLINK ) ),
     100           0 :     aStrBrokenlink( CUI_RES( STR_BROKENLINK ) ),
     101           0 :     aStrGraphiclink( CUI_RES( STR_GRAPHICLINK ) ),
     102           0 :     aStrButtonclose( CUI_RES( STR_BUTTONCLOSE ) ),
     103           0 :     aStrCloselinkmsg( CUI_RES( STR_CLOSELINKMSG ) ),
     104           0 :     aStrCloselinkmsgMulti( CUI_RES( STR_CLOSELINKMSG_MULTI ) ),
     105           0 :     aStrWaitinglink( CUI_RES( STR_WAITINGLINK ) ),
     106             :     pLinkMgr( NULL ),
     107           0 :     bHtmlMode(bHtml)
     108             : {
     109           0 :     FreeResource();
     110             : 
     111           0 :     aTbLinks.SetHelpId(HID_LINKDLG_TABLB);
     112           0 :     aTbLinks.SetSelectionMode( MULTIPLE_SELECTION );
     113           0 :     aTbLinks.SetTabs( &nTabs[0], MAP_APPFONT );
     114           0 :     aTbLinks.Resize();  // OS: hack for correct selection
     115             : 
     116             :     // UpdateTimer for DDE-/Grf-links, which are waited for
     117           0 :     aUpdateTimer.SetTimeoutHdl( LINK( this, SvBaseLinksDlg, UpdateWaitingHdl ) );
     118           0 :     aUpdateTimer.SetTimeout( 1000 );
     119             : 
     120             :     // Set the ZOrder, and accessible name to the dialog's title
     121           0 :     aTbLinks.SetZOrder(0, WINDOW_ZORDER_FIRST);
     122           0 :     aTbLinks.SetAccessibleName(this->GetText());
     123           0 :     aTbLinks.SetAccessibleRelationLabeledBy(&aFtFiles);
     124             : 
     125           0 :     OpenSource().Hide();
     126             : 
     127           0 :     Links().SetSelectHdl( LINK( this, SvBaseLinksDlg, LinksSelectHdl ) );
     128           0 :     Links().SetDoubleClickHdl( LINK( this, SvBaseLinksDlg, LinksDoubleClickHdl ) );
     129           0 :     Automatic().SetClickHdl( LINK( this, SvBaseLinksDlg, AutomaticClickHdl ) );
     130           0 :     Manual().SetClickHdl( LINK( this, SvBaseLinksDlg, ManualClickHdl ) );
     131           0 :     UpdateNow().SetClickHdl( LINK( this, SvBaseLinksDlg, UpdateNowClickHdl ) );
     132           0 :     ChangeSource().SetClickHdl( LINK( this, SvBaseLinksDlg, ChangeSourceClickHdl ) );
     133           0 :     if(!bHtmlMode)
     134           0 :         BreakLink().SetClickHdl( LINK( this, SvBaseLinksDlg, BreakLinkClickHdl ) );
     135             :     else
     136           0 :         BreakLink().Hide();
     137             : 
     138           0 :     SetManager( pMgr );
     139           0 : }
     140             : 
     141           0 : SvBaseLinksDlg::~SvBaseLinksDlg()
     142             : {
     143           0 : }
     144             : 
     145             : /*************************************************************************
     146             : |*    SvBaseLinksDlg::Handler()
     147             : *************************************************************************/
     148           0 : IMPL_LINK( SvBaseLinksDlg, LinksSelectHdl, SvTabListBox *, pSvTabListBox )
     149             : {
     150             :     sal_uInt16 nSelectionCount = pSvTabListBox ?
     151           0 :         (sal_uInt16)pSvTabListBox->GetSelectionCount() : 0;
     152           0 :     if(nSelectionCount > 1)
     153             :     {
     154             :         // possibly deselect old entries in case of multi-selection
     155           0 :         SvTreeListEntry* pEntry = 0;
     156           0 :         SvBaseLink* pLink = 0;
     157           0 :         pEntry = pSvTabListBox->GetHdlEntry();
     158           0 :         pLink = (SvBaseLink*)pEntry->GetUserData();
     159           0 :         sal_uInt16 nObjectType = pLink->GetObjType();
     160           0 :         if((OBJECT_CLIENT_FILE & nObjectType) != OBJECT_CLIENT_FILE)
     161             :         {
     162           0 :             pSvTabListBox->SelectAll(sal_False);
     163           0 :             pSvTabListBox->Select(pEntry);
     164           0 :             nSelectionCount = 1;
     165             :         }
     166             :         else
     167             :         {
     168           0 :             for( sal_uInt16 i = 0; i < nSelectionCount; i++)
     169             :             {
     170           0 :                 pEntry = i == 0 ? pSvTabListBox->FirstSelected() :
     171           0 :                                     pSvTabListBox->NextSelected(pEntry);
     172             :                 DBG_ASSERT(pEntry, "Wo ist der Entry?");
     173           0 :                 pLink = (SvBaseLink*)pEntry->GetUserData();
     174             :                 DBG_ASSERT(pLink, "Wo ist der Link?");
     175           0 :                 if( (OBJECT_CLIENT_FILE & pLink->GetObjType()) != OBJECT_CLIENT_FILE )
     176           0 :                     pSvTabListBox->Select( pEntry, sal_False );
     177             : 
     178             :             }
     179             :         }
     180             : 
     181           0 :         UpdateNow().Enable();
     182             : 
     183           0 :         Automatic().Disable();
     184           0 :         Manual().Check();
     185           0 :         Manual().Disable();
     186             :     }
     187             :     else
     188             :     {
     189             :         sal_uInt16 nPos;
     190           0 :         SvBaseLink* pLink = GetSelEntry( &nPos );
     191           0 :         if( !pLink )
     192           0 :             return 0;
     193             : 
     194           0 :         UpdateNow().Enable();
     195             : 
     196           0 :         String sType, sLink;
     197           0 :         String *pLinkNm = &sLink, *pFilter = 0;
     198             : 
     199           0 :         if( FILEOBJECT & pLink->GetObjType() )
     200             :         {
     201           0 :             Automatic().Disable();
     202           0 :             Manual().Check();
     203           0 :             Manual().Disable();
     204           0 :             if( OBJECT_CLIENT_GRF == pLink->GetObjType() )
     205           0 :                 pLinkNm = 0, pFilter = &sLink;
     206             :         }
     207             :         else
     208             :         {
     209           0 :             Automatic().Enable();
     210           0 :             Manual().Enable();
     211             : 
     212           0 :             if( LINKUPDATE_ALWAYS == pLink->GetUpdateMode() )
     213           0 :                 Automatic().Check();
     214             :             else
     215           0 :                 Manual().Check();
     216             :         }
     217             : 
     218           0 :         String aFileName;
     219           0 :         pLinkMgr->GetDisplayNames( pLink, &sType, &aFileName, pLinkNm, pFilter );
     220           0 :         aFileName = INetURLObject::decode(aFileName, INET_HEX_ESCAPE, INetURLObject::DECODE_UNAMBIGUOUS);
     221           0 :         FileName().SetText( aFileName );
     222           0 :         SourceName().SetText( sLink );
     223           0 :         TypeName().SetText( sType );
     224             :     }
     225           0 :     return 0;
     226             : }
     227             : 
     228           0 : IMPL_LINK_INLINE_START( SvBaseLinksDlg, LinksDoubleClickHdl, SvTabListBox *, pSvTabListBox )
     229             : {
     230             :     (void)pSvTabListBox;
     231             : 
     232           0 :     ChangeSourceClickHdl( 0 );
     233           0 :     return 0;
     234             : }
     235           0 : IMPL_LINK_INLINE_END( SvBaseLinksDlg, LinksDoubleClickHdl, SvTabListBox *, pSvTabListBox )
     236             : 
     237           0 : IMPL_LINK_INLINE_START( SvBaseLinksDlg, AutomaticClickHdl, RadioButton *, pRadioButton )
     238             : {
     239             :     (void)pRadioButton;
     240             : 
     241             :     sal_uInt16 nPos;
     242           0 :     SvBaseLink* pLink = GetSelEntry( &nPos );
     243           0 :     if( pLink && !( FILEOBJECT & pLink->GetObjType() ) &&
     244           0 :         LINKUPDATE_ALWAYS != pLink->GetUpdateMode() )
     245           0 :         SetType( *pLink, nPos, LINKUPDATE_ALWAYS );
     246           0 :     return 0;
     247             : }
     248           0 : IMPL_LINK_INLINE_END( SvBaseLinksDlg, AutomaticClickHdl, RadioButton *, pRadioButton )
     249             : 
     250           0 : IMPL_LINK_INLINE_START( SvBaseLinksDlg, ManualClickHdl, RadioButton *, pRadioButton )
     251             : {
     252             :     (void)pRadioButton;
     253             : 
     254             :     sal_uInt16 nPos;
     255           0 :     SvBaseLink* pLink = GetSelEntry( &nPos );
     256           0 :     if( pLink && !( FILEOBJECT & pLink->GetObjType() ) &&
     257           0 :         LINKUPDATE_ONCALL != pLink->GetUpdateMode())
     258           0 :         SetType( *pLink, nPos, LINKUPDATE_ONCALL );
     259           0 :     return 0;
     260             : }
     261           0 : IMPL_LINK_INLINE_END( SvBaseLinksDlg, ManualClickHdl, RadioButton *, pRadioButton )
     262             : 
     263           0 : IMPL_LINK_NOARG(SvBaseLinksDlg, UpdateNowClickHdl)
     264             : {
     265           0 :     SvTabListBox& rListBox = Links();
     266           0 :     sal_uInt16 nSelCnt = (sal_uInt16)rListBox.GetSelectionCount();
     267           0 :     if( 255 < nSelCnt )
     268           0 :         nSelCnt = 255;
     269             : 
     270           0 :     std::vector< SvBaseLink* > aLnkArr;
     271           0 :     std::vector< sal_uInt16 > aPosArr;
     272             : 
     273           0 :     SvTreeListEntry* pE = rListBox.FirstSelected();
     274           0 :     while( pE )
     275             :     {
     276           0 :         sal_uInt16 nFndPos = (sal_uInt16)rListBox.GetModel()->GetAbsPos( pE );
     277           0 :         if( LISTBOX_ENTRY_NOTFOUND != nFndPos )
     278             :         {
     279           0 :             aLnkArr.push_back( static_cast< SvBaseLink* >( pE->GetUserData() ) );
     280           0 :             aPosArr.push_back( nFndPos );
     281             :         }
     282           0 :         pE = rListBox.NextSelected( pE );
     283             :     }
     284             : 
     285           0 :     if( !aLnkArr.empty() )
     286             :     {
     287           0 :         for( sal_uInt16 n = 0; n < aLnkArr.size(); ++n )
     288             :         {
     289           0 :             SvBaseLinkRef xLink = aLnkArr[ n ];
     290             : 
     291             :             // first look for the entry in the array
     292           0 :             for( sal_uInt16 i = 0; i < pLinkMgr->GetLinks().size(); ++i )
     293           0 :                 if( &xLink == *pLinkMgr->GetLinks()[ i ] )
     294             :                 {
     295           0 :                     xLink->SetUseCache( sal_False );
     296           0 :                     SetType( *xLink, aPosArr[ n ], xLink->GetUpdateMode() );
     297           0 :                     xLink->SetUseCache( sal_True );
     298           0 :                     break;
     299             :                 }
     300           0 :         }
     301             : 
     302             :         // if somebody is of the opinion to swap his links (SD)
     303           0 :         LinkManager* pNewMgr = pLinkMgr;
     304           0 :         pLinkMgr = 0;
     305           0 :         SetManager( pNewMgr );
     306             : 
     307             : 
     308           0 :         if( 0 == (pE = rListBox.GetEntry( aPosArr[ 0 ] )) ||
     309           0 :             pE->GetUserData() != aLnkArr[ 0 ] )
     310             :         {
     311             :             // search the link
     312           0 :             pE = rListBox.First();
     313           0 :             while( pE )
     314             :             {
     315           0 :                 if( pE->GetUserData() == aLnkArr[ 0 ] )
     316           0 :                     break;
     317           0 :                 pE = rListBox.Next( pE );
     318             :             }
     319             : 
     320           0 :             if( !pE )
     321           0 :                 pE = rListBox.FirstSelected();
     322             :         }
     323             : 
     324           0 :         if( pE )
     325             :         {
     326           0 :             SvTreeListEntry* pSelEntry = rListBox.FirstSelected();
     327           0 :             if( pE != pSelEntry )
     328           0 :                 rListBox.Select( pSelEntry, sal_False );
     329           0 :             rListBox.Select( pE );
     330           0 :             rListBox.MakeVisible( pE );
     331             :         }
     332             : 
     333           0 :         pNewMgr->CloseCachedComps();
     334             :     }
     335           0 :     return 0;
     336             : }
     337             : 
     338           0 : IMPL_LINK( SvBaseLinksDlg, ChangeSourceClickHdl, PushButton *, pPushButton )
     339             : {
     340             :     (void)pPushButton;
     341             : 
     342           0 :     sal_uInt16 nSelectionCount = (sal_uInt16)Links().GetSelectionCount();
     343           0 :     if(nSelectionCount > 1)
     344             :     {
     345           0 :         PathDialog aPathDlg( this );
     346           0 :         String sType, sFile, sLinkName;
     347           0 :         String  sFilter;
     348           0 :         SvTreeListEntry* pEntry = Links().FirstSelected();
     349           0 :         SvBaseLink* pLink = (SvBaseLink*)pEntry->GetUserData();
     350           0 :         pLinkMgr->GetDisplayNames( pLink, &sType, &sFile, 0, 0 );
     351           0 :         INetURLObject aUrl(sFile);
     352           0 :         if(aUrl.GetProtocol() == INET_PROT_FILE)
     353             :         {
     354           0 :             rtl::OUString sOldPath(aUrl.PathToFileName());
     355           0 :             sal_Int32 nLen = aUrl.GetName().getLength();
     356           0 :             sOldPath = sOldPath.copy(0, sOldPath.getLength() - nLen);
     357           0 :             aPathDlg.SetPath(sOldPath);
     358             :         }
     359           0 :         if(aPathDlg.Execute() == RET_OK)
     360             :         {
     361           0 :             String aPath = aPathDlg.GetPath();
     362             : 
     363           0 :             for( sal_uInt16 i = 0; i < nSelectionCount; i++)
     364             :             {
     365             :                 pEntry = i==0 ?
     366           0 :                         Links().FirstSelected() :
     367           0 :                             Links().NextSelected( pEntry );
     368             :                 DBG_ASSERT(pEntry,"Wo ist der Entry");
     369           0 :                 pLink = (SvBaseLink*)pEntry->GetUserData();
     370             :                 DBG_ASSERT(pLink,"Wo ist der Link");
     371           0 :                 pLinkMgr->GetDisplayNames( pLink, &sType, &sFile, &sLinkName, &sFilter );
     372           0 :                 INetURLObject aUrl_(sFile);
     373           0 :                 INetURLObject aUrl2(aPath, INET_PROT_FILE);
     374           0 :                 aUrl2.insertName( aUrl_.getName() );
     375           0 :                 String sNewLinkName;
     376             :                 MakeLnkName( sNewLinkName, 0 ,
     377           0 :                         aUrl2.GetMainURL(INetURLObject::DECODE_TO_IURI), sLinkName, &sFilter);
     378           0 :                 pLink->SetLinkSourceName( sNewLinkName );
     379           0 :                 pLink->Update();
     380           0 :             }
     381           0 :             if( pLinkMgr->GetPersist() )
     382           0 :                 pLinkMgr->GetPersist()->SetModified();
     383           0 :             LinkManager* pNewMgr = pLinkMgr;
     384           0 :             pLinkMgr = 0;
     385           0 :             SetManager( pNewMgr );
     386           0 :         }
     387             :     }
     388             :     else
     389             :     {
     390             :         sal_uInt16 nPos;
     391           0 :         SvBaseLink* pLink = GetSelEntry( &nPos );
     392           0 :         if ( pLink && (pLink->GetLinkSourceName().Len() != 0) )
     393           0 :             pLink->Edit( this, LINK( this, SvBaseLinksDlg, EndEditHdl ) );
     394             :     }
     395           0 :     return 0;
     396             : }
     397             : 
     398           0 : IMPL_LINK( SvBaseLinksDlg, BreakLinkClickHdl, PushButton *, pPushButton )
     399             : {
     400             :     (void)pPushButton;
     401             : 
     402           0 :     sal_Bool bModified = sal_False;
     403           0 :     if(Links().GetSelectionCount() <= 1)
     404             :     {
     405             :         sal_uInt16 nPos;
     406           0 :         SvBaseLinkRef xLink = GetSelEntry( &nPos );
     407           0 :         if( !xLink.Is() )
     408           0 :             return 0;
     409             : 
     410           0 :         QueryBox aBox( this, WB_YES_NO | WB_DEF_YES, Closelinkmsg() );
     411             : 
     412           0 :         if( RET_YES == aBox.Execute() )
     413             :         {
     414           0 :             Links().GetModel()->Remove( Links().GetEntry( nPos ) );
     415             : 
     416             :             // close object, if it's still existing
     417           0 :             sal_Bool bNewLnkMgr = OBJECT_CLIENT_FILE == xLink->GetObjType();
     418             : 
     419             :             // tell the link that it will be resolved!
     420           0 :             xLink->Closed();
     421             : 
     422             :             // if somebody has forgotten to deregister himself
     423           0 :             if( xLink.Is() )
     424           0 :                 pLinkMgr->Remove( &xLink );
     425             : 
     426           0 :             if( bNewLnkMgr )
     427             :             {
     428           0 :                 LinkManager* pNewMgr = pLinkMgr;
     429           0 :                 pLinkMgr = 0;
     430           0 :                 SetManager( pNewMgr );
     431             : 
     432           0 :                 SvTreeListEntry* pEntry = Links().GetEntry( nPos ? --nPos : 0 );
     433           0 :                 if( pEntry )
     434           0 :                     Links().SetCurEntry( pEntry );
     435             :             }
     436           0 :             bModified = sal_True;
     437           0 :         }
     438             :     }
     439             :     else
     440             :     {
     441           0 :         QueryBox aBox( this, WB_YES_NO | WB_DEF_YES, CloselinkmsgMulti() );
     442             : 
     443           0 :         if( RET_YES == aBox.Execute() )
     444             :         {
     445             : 
     446           0 :             SvBaseLinkMemberList aLinkList;
     447           0 :             SvTreeListEntry* pEntry = Links().FirstSelected();
     448           0 :             while ( pEntry )
     449             :             {
     450           0 :                 void * pUD = pEntry->GetUserData();
     451           0 :                 if( pUD )
     452           0 :                     aLinkList.push_back( (SvBaseLink*)pUD );
     453           0 :                 pEntry = Links().NextSelected(pEntry);
     454             :             }
     455           0 :             Links().RemoveSelection();
     456           0 :             for( sal_uLong i = 0; i < aLinkList.size(); i++ )
     457             :             {
     458           0 :                 SvBaseLinkRef xLink = aLinkList[i];
     459             :                 // tell the link that it will be resolved!
     460           0 :                 xLink->Closed();
     461             : 
     462             :                 // if somebody has forgotten to deregister himself
     463           0 :                 pLinkMgr->Remove( &xLink );
     464           0 :                 bModified = sal_True;
     465           0 :             }
     466             :             // then remove all selected entries
     467           0 :         }
     468             :     }
     469           0 :     if(bModified)
     470             :     {
     471           0 :         if( !Links().GetEntryCount() )
     472             :         {
     473           0 :             Automatic().Disable();
     474           0 :             Manual().Disable();
     475           0 :             UpdateNow().Disable();
     476           0 :             ChangeSource().Disable();
     477           0 :             BreakLink().Disable();
     478             : 
     479           0 :             String aEmpty;
     480           0 :             SourceName().SetText( aEmpty );
     481           0 :             TypeName().SetText( aEmpty );
     482             :         }
     483           0 :         if( pLinkMgr->GetPersist() )
     484           0 :             pLinkMgr->GetPersist()->SetModified();
     485             :     }
     486           0 :     return 0;
     487             : }
     488             : 
     489           0 : IMPL_LINK( SvBaseLinksDlg, UpdateWaitingHdl, Timer*, pTimer )
     490             : {
     491             :     (void)pTimer;
     492             : 
     493           0 :     Links().SetUpdateMode(sal_False);
     494           0 :     for( sal_uLong nPos = Links().GetEntryCount(); nPos; )
     495             :     {
     496           0 :         SvTreeListEntry* pBox = Links().GetEntry( --nPos );
     497           0 :         SvBaseLinkRef xLink( (SvBaseLink*)pBox->GetUserData() );
     498           0 :         if( xLink.Is() )
     499             :         {
     500           0 :             String sCur( ImplGetStateStr( *xLink ) ),
     501           0 :                     sOld( Links().GetEntryText( pBox, 3 ) );
     502           0 :             if( sCur != sOld )
     503           0 :                 Links().SetEntryText( sCur, pBox, 3 );
     504             :         }
     505           0 :     }
     506           0 :     Links().SetUpdateMode(sal_True);
     507           0 :     return 0;
     508             : }
     509             : 
     510           0 : IMPL_LINK( SvBaseLinksDlg, EndEditHdl, sfx2::SvBaseLink*, _pLink )
     511             : {
     512             :     sal_uInt16 nPos;
     513           0 :     GetSelEntry( &nPos );
     514             : 
     515           0 :     if( _pLink && _pLink->WasLastEditOK() )
     516             :     {
     517             :         // StarImpress/Draw swap the LinkObjects themselves!
     518             :         // So search for the link in the manager; if it does not exist
     519             :         // anymore, fill the list completely new. Otherwise only the
     520             :         // edited link needs to be refreshed.
     521           0 :         sal_Bool bLinkFnd = sal_False;
     522           0 :         for( sal_uInt16 n = pLinkMgr->GetLinks().size(); n;  )
     523           0 :             if( _pLink == &(*pLinkMgr->GetLinks()[ --n ]) )
     524             :             {
     525           0 :                 bLinkFnd = sal_True;
     526           0 :                 break;
     527             :             }
     528             : 
     529           0 :         if( bLinkFnd )
     530             :         {
     531           0 :             Links().SetUpdateMode(sal_False);
     532           0 :             Links().GetModel()->Remove( Links().GetEntry( nPos ) );
     533           0 :             SvTreeListEntry* pToUnselect = Links().FirstSelected();
     534           0 :             InsertEntry( *_pLink, nPos, sal_True );
     535           0 :             if(pToUnselect)
     536           0 :                 Links().Select(pToUnselect, sal_False);
     537           0 :             Links().SetUpdateMode(sal_True);
     538             :         }
     539             :         else
     540             :         {
     541           0 :             LinkManager* pNewMgr = pLinkMgr;
     542           0 :             pLinkMgr = 0;
     543           0 :             SetManager( pNewMgr );
     544             :         }
     545           0 :         if( pLinkMgr->GetPersist() )
     546           0 :             pLinkMgr->GetPersist()->SetModified();
     547             :     }
     548           0 :     return 0;
     549             : }
     550             : 
     551           0 : String SvBaseLinksDlg::ImplGetStateStr( const SvBaseLink& rLnk )
     552             : {
     553           0 :     String sRet;
     554           0 :     if( !rLnk.GetObj() )
     555           0 :         sRet = Brokenlink();
     556           0 :     else if( rLnk.GetObj()->IsPending() )
     557             :     {
     558           0 :         sRet = Waitinglink();
     559           0 :         StartUpdateTimer();
     560             :     }
     561           0 :     else if( LINKUPDATE_ALWAYS == rLnk.GetUpdateMode() )
     562           0 :         sRet = Autolink();
     563             :     else
     564           0 :         sRet = Manuallink();
     565             : 
     566           0 :     return sRet;
     567             : }
     568             : 
     569           0 : void SvBaseLinksDlg::SetManager( LinkManager* pNewMgr )
     570             : {
     571           0 :     if( pLinkMgr == pNewMgr )
     572           0 :         return;
     573             : 
     574           0 :     if( pNewMgr )
     575             :         // update has to be stopped before clear
     576           0 :         Links().SetUpdateMode( sal_False );
     577             : 
     578           0 :     Links().Clear();
     579           0 :     pLinkMgr = pNewMgr;
     580             : 
     581           0 :     if( pLinkMgr )
     582             :     {
     583           0 :         SvBaseLinks& rLnks = (SvBaseLinks&)pLinkMgr->GetLinks();
     584           0 :         for( sal_uInt16 n = 0; n < rLnks.size(); ++n )
     585             :         {
     586           0 :             SvBaseLinkRef* pLinkRef = rLnks[ n ];
     587           0 :             if( !pLinkRef->Is() )
     588             :             {
     589           0 :                 rLnks.erase( rLnks.begin() + n );
     590           0 :                 --n;
     591           0 :                 continue;
     592             :             }
     593           0 :             if( (*pLinkRef)->IsVisible() )
     594           0 :                 InsertEntry( **pLinkRef );
     595             :         }
     596             : 
     597           0 :         if( !rLnks.empty() )
     598             :         {
     599           0 :             SvTreeListEntry* pEntry = Links().GetEntry( 0 );
     600           0 :             Links().SetCurEntry( pEntry );
     601           0 :             Links().Select( pEntry );
     602           0 :             LinksSelectHdl( 0 );
     603             :         }
     604           0 :         Links().SetUpdateMode( sal_True );
     605           0 :         Links().Invalidate();
     606             :     }
     607             : }
     608             : 
     609             : 
     610           0 : void SvBaseLinksDlg::InsertEntry( const SvBaseLink& rLink, sal_uInt16 nPos, sal_Bool bSelect )
     611             : {
     612           0 :     String aEntry, sFileNm, sLinkNm, sTypeNm, sFilter;
     613             : 
     614           0 :     pLinkMgr->GetDisplayNames( (SvBaseLink*)&rLink, &sTypeNm, &sFileNm, &sLinkNm, &sFilter );
     615             : 
     616             :     // GetTab(0) gives the position of the bitmap which is automatically inserted by the TabListBox.
     617             :     // So the first text column's width is Tab(2)-Tab(1).
     618           0 :     long nWidthPixel = Links().GetLogicTab( 2 ) - Links().GetLogicTab( 1 );
     619           0 :     nWidthPixel -= SV_TAB_BORDER;
     620           0 :     XubString aTxt = Links().GetEllipsisString( sFileNm, nWidthPixel, TEXT_DRAW_PATHELLIPSIS );
     621           0 :     INetURLObject aPath( sFileNm, INET_PROT_FILE );
     622           0 :     String aFileName = aPath.getName();
     623           0 :     aFileName = INetURLObject::decode(aFileName, INET_HEX_ESCAPE, INetURLObject::DECODE_UNAMBIGUOUS);
     624             : 
     625           0 :     if( aFileName.Len() > aTxt.Len() )
     626           0 :         aTxt = aFileName;
     627           0 :     else if( aTxt.Search( aFileName, aTxt.Len() - aFileName.Len() ) == STRING_NOTFOUND )
     628             :         // filename not in string
     629           0 :         aTxt = aFileName;
     630             : 
     631           0 :     aEntry = aTxt;
     632           0 :     aEntry += '\t';
     633           0 :     if( OBJECT_CLIENT_GRF == rLink.GetObjType() )
     634           0 :         aEntry += sFilter;
     635             :     else
     636           0 :         aEntry += sLinkNm;
     637           0 :     aEntry += '\t';
     638           0 :     aEntry += sTypeNm;
     639           0 :     aEntry += '\t';
     640           0 :     aEntry += ImplGetStateStr( rLink );
     641             : 
     642           0 :     SvTreeListEntry * pE = Links().InsertEntryToColumn( aEntry, nPos );
     643           0 :     pE->SetUserData( (void*)&rLink );
     644           0 :     if(bSelect)
     645           0 :         Links().Select(pE);
     646           0 : }
     647             : 
     648           0 : SvBaseLink* SvBaseLinksDlg::GetSelEntry( sal_uInt16* pPos )
     649             : {
     650           0 :     SvTreeListEntry* pE = Links().FirstSelected();
     651             :     sal_uInt16 nPos;
     652           0 :     if( pE && LISTBOX_ENTRY_NOTFOUND !=
     653           0 :         ( nPos = (sal_uInt16)Links().GetModel()->GetAbsPos( pE ) ) )
     654             :     {
     655             :         DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
     656             : 
     657           0 :         if( pPos )
     658           0 :             *pPos = nPos;
     659           0 :         return (SvBaseLink*)pE->GetUserData();
     660             :     }
     661           0 :     return 0;
     662             : }
     663             : 
     664           0 : void SvBaseLinksDlg::SetType( SvBaseLink& rLink,
     665             :                                     sal_uInt16 nSelPos,
     666             :                                     sal_uInt16 nType )
     667             : {
     668           0 :     rLink.SetUpdateMode( nType );
     669           0 :     rLink.Update();
     670           0 :     SvTreeListEntry* pBox = Links().GetEntry( nSelPos );
     671           0 :     Links().SetEntryText( ImplGetStateStr( rLink ), pBox, 3 );
     672           0 :     if( pLinkMgr->GetPersist() )
     673           0 :         pLinkMgr->GetPersist()->SetModified();
     674           0 : }
     675             : 
     676           0 : void SvBaseLinksDlg::SetActLink( SvBaseLink * pLink )
     677             : {
     678           0 :     if( pLinkMgr )
     679             :     {
     680           0 :         const SvBaseLinks& rLnks = pLinkMgr->GetLinks();
     681           0 :         sal_uInt16 nSelect = 0;
     682           0 :         for( sal_uInt16 n = 0; n < rLnks.size(); ++n )
     683             :         {
     684           0 :             SvBaseLinkRef* pLinkRef = rLnks[ n ];
     685             :             // #109573# only visible links have been inserted into the TreeListBox,
     686             :             // invisible ones have to be skipped here
     687           0 :             if( (*pLinkRef)->IsVisible() )
     688             :             {
     689           0 :                 if( pLink == *pLinkRef )
     690             :                 {
     691           0 :                     Links().Select( Links().GetEntry( nSelect ) );
     692           0 :                     LinksSelectHdl( 0 );
     693           0 :                     return ;
     694             :                 }
     695           0 :                 nSelect++;
     696             :             }
     697             :         }
     698             :     }
     699             : }
     700             : 
     701             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10