bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / dialogs / linkdlg.cxx
blobf1652f82d9eb2af0f0eafe30f5b8af70a04d8e61
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <linkdlg.hxx>
21 #include <vcl/svapp.hxx>
22 #include "helpid.hrc"
24 #include <tools/urlobj.hxx>
25 #include <svtools/svmedit.hxx>
26 #include <vcl/dialog.hxx>
27 #include <vcl/button.hxx>
28 #include <vcl/fixed.hxx>
29 #include <vcl/group.hxx>
30 #include <vcl/lstbox.hxx>
31 #include <vcl/msgbox.hxx>
32 #include <vcl/timer.hxx>
33 #include <vcl/idle.hxx>
34 #include <svtools/svtabbx.hxx>
35 #include "svtools/treelistentry.hxx"
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>
44 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
45 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
46 #include <comphelper/processfactory.hxx>
48 #include <dialmgr.hxx>
51 #define FILEOBJECT ( OBJECT_CLIENT_FILE & ~OBJECT_CLIENT_SO )
53 using namespace sfx2;
54 using namespace ::com::sun::star;
56 class SvBaseLinkMemberList {
57 private:
58 std::vector<SvBaseLink*> mLinks;
60 public:
61 ~SvBaseLinkMemberList()
63 for( std::vector<SvBaseLink*>::const_iterator it = mLinks.begin(); it != mLinks.end(); ++it )
65 SvBaseLink* p = *it;
66 if( p )
67 p->ReleaseRef();
71 size_t size() const { return mLinks.size(); }
73 SvBaseLink *operator[](size_t i) const { return mLinks[i]; }
75 void push_back(SvBaseLink* p)
77 mLinks.push_back(p);
78 p->AddFirstRef();
82 // attention, this array is indexed directly (0, 1, ...) in the code
83 static long nTabs[] =
84 { 4, // Number of Tabs
85 0, 77, 144, 209
89 SvBaseLinksDlg::SvBaseLinksDlg( vcl::Window * pParent, LinkManager* pMgr, bool bHtml )
90 : ModalDialog( pParent, "BaseLinksDialog", "cui/ui/baselinksdialog.ui"),
91 aStrAutolink( CUI_RES( STR_AUTOLINK ) ),
92 aStrManuallink( CUI_RES( STR_MANUALLINK ) ),
93 aStrBrokenlink( CUI_RES( STR_BROKENLINK ) ),
94 aStrGraphiclink( CUI_RES( STR_GRAPHICLINK ) ),
95 aStrButtonclose( CUI_RES( STR_BUTTONCLOSE ) ),
96 aStrCloselinkmsg( CUI_RES( STR_CLOSELINKMSG ) ),
97 aStrCloselinkmsgMulti( CUI_RES( STR_CLOSELINKMSG_MULTI ) ),
98 aStrWaitinglink( CUI_RES( STR_WAITINGLINK ) ),
99 pLinkMgr( NULL ),
100 bHtmlMode(bHtml)
102 get(m_pTbLinks, "TB_LINKS");
103 Size aSize(LogicToPixel(Size(257, 87), MAP_APPFONT));
104 m_pTbLinks->set_width_request(aSize.Width());
105 m_pTbLinks->set_height_request(aSize.Height());
106 get(m_pFtFullFileName, "FULL_FILE_NAME");
107 get(m_pFtFullSourceName, "FULL_SOURCE_NAME");
108 get(m_pFtFullTypeName, "FULL_TYPE_NAME");
109 get(m_pRbAutomatic, "AUTOMATIC");
110 get(m_pRbManual, "MANUAL");
111 get(m_pPbUpdateNow, "UPDATE_NOW");
112 get(m_pPbOpenSource, "OPEN");
113 get(m_pPbChangeSource, "CHANGE_SOURCE");
114 get(m_pPbBreakLink, "BREAK_LINK");
116 m_pTbLinks->SetSelectionMode( MULTIPLE_SELECTION );
117 m_pTbLinks->SetTabs( &nTabs[0], MAP_APPFONT );
118 FixedText *pFtFiles = get<FixedText>("FILES");
119 pFtFiles->set_width_request(LogicToPixel(Size(nTabs[2] - nTabs[1] - 2, 0), MAP_APPFONT).Width());
120 FixedText *pFtLinks = get<FixedText>("LINKS");
121 pFtLinks->set_width_request(LogicToPixel(Size(nTabs[3] - nTabs[2] - 2, 0), MAP_APPFONT).Width());
122 FixedText *pFtTypes = get<FixedText>("TYPE");
123 pFtTypes->set_width_request(LogicToPixel(Size(nTabs[4] - nTabs[3] - 2, 0), MAP_APPFONT).Width());
124 m_pTbLinks->Resize(); // OS: hack for correct selection
126 // UpdateTimer for DDE-/Grf-links, which are waited for
127 aUpdateIdle.SetIdleHdl( LINK( this, SvBaseLinksDlg, UpdateWaitingHdl ) );
128 aUpdateIdle.SetPriority( SchedulerPriority::LOWEST );
130 m_pPbOpenSource->Hide();
132 m_pTbLinks->SetSelectHdl( LINK( this, SvBaseLinksDlg, LinksSelectHdl ) );
133 m_pTbLinks->SetDoubleClickHdl( LINK( this, SvBaseLinksDlg, LinksDoubleClickHdl ) );
134 m_pRbAutomatic->SetClickHdl( LINK( this, SvBaseLinksDlg, AutomaticClickHdl ) );
135 m_pRbManual->SetClickHdl( LINK( this, SvBaseLinksDlg, ManualClickHdl ) );
136 m_pPbUpdateNow->SetClickHdl( LINK( this, SvBaseLinksDlg, UpdateNowClickHdl ) );
137 m_pPbChangeSource->SetClickHdl( LINK( this, SvBaseLinksDlg, ChangeSourceClickHdl ) );
138 if(!bHtmlMode)
139 m_pPbBreakLink->SetClickHdl( LINK( this, SvBaseLinksDlg, BreakLinkClickHdl ) );
140 else
141 m_pPbBreakLink->Hide();
143 SetManager( pMgr );
146 SvBaseLinksDlg::~SvBaseLinksDlg()
148 disposeOnce();
151 void SvBaseLinksDlg::dispose()
153 m_pTbLinks.clear();
154 m_pFtFullFileName.clear();
155 m_pFtFullSourceName.clear();
156 m_pFtFullTypeName.clear();
157 m_pRbAutomatic.clear();
158 m_pRbManual.clear();
159 m_pPbUpdateNow.clear();
160 m_pPbOpenSource.clear();
161 m_pPbChangeSource.clear();
162 m_pPbBreakLink.clear();
163 ModalDialog::dispose();
166 /*************************************************************************
167 |* SvBaseLinksDlg::Handler()
168 *************************************************************************/
169 IMPL_LINK( SvBaseLinksDlg, LinksSelectHdl, SvTabListBox *, pSvTabListBox )
171 sal_uLong nSelectionCount = pSvTabListBox ?
172 pSvTabListBox->GetSelectionCount() : 0;
173 if(nSelectionCount > 1)
175 // possibly deselect old entries in case of multi-selection
176 SvTreeListEntry* pEntry = 0;
177 SvBaseLink* pLink = 0;
178 pEntry = pSvTabListBox->GetHdlEntry();
179 pLink = static_cast<SvBaseLink*>(pEntry->GetUserData());
180 sal_uInt16 nObjectType = pLink->GetObjType();
181 if((OBJECT_CLIENT_FILE & nObjectType) != OBJECT_CLIENT_FILE)
183 pSvTabListBox->SelectAll(false);
184 pSvTabListBox->Select(pEntry);
185 nSelectionCount = 1;
187 else
189 for( sal_uLong i = 0; i < nSelectionCount; i++)
191 pEntry = i == 0 ? pSvTabListBox->FirstSelected() :
192 pSvTabListBox->NextSelected(pEntry);
193 DBG_ASSERT(pEntry, "Wo ist der Entry?");
194 if (!pEntry)
195 continue;
196 pLink = static_cast<SvBaseLink*>(pEntry->GetUserData());
197 DBG_ASSERT(pLink, "Wo ist der Link?");
198 if (!pLink)
199 continue;
200 if( (OBJECT_CLIENT_FILE & pLink->GetObjType()) != OBJECT_CLIENT_FILE )
201 pSvTabListBox->Select( pEntry, false );
206 m_pPbUpdateNow->Enable();
208 m_pRbAutomatic->Disable();
209 m_pRbManual->Check();
210 m_pRbManual->Disable();
212 else
214 sal_uLong nPos;
215 SvBaseLink* pLink = GetSelEntry( &nPos );
216 if( !pLink )
217 return 0;
219 m_pPbUpdateNow->Enable();
221 OUString sType, sLink;
222 OUString *pLinkNm = &sLink, *pFilter = 0;
224 if( FILEOBJECT & pLink->GetObjType() )
226 m_pRbAutomatic->Disable();
227 m_pRbManual->Check();
228 m_pRbManual->Disable();
229 if( OBJECT_CLIENT_GRF == pLink->GetObjType() )
230 pLinkNm = 0, pFilter = &sLink;
232 else
234 m_pRbAutomatic->Enable();
235 m_pRbManual->Enable();
237 if( SfxLinkUpdateMode::ALWAYS == pLink->GetUpdateMode() )
238 m_pRbAutomatic->Check();
239 else
240 m_pRbManual->Check();
243 OUString aFileName;
244 sfx2::LinkManager::GetDisplayNames( pLink, &sType, &aFileName, pLinkNm, pFilter );
245 aFileName = INetURLObject::decode(aFileName, INetURLObject::DECODE_UNAMBIGUOUS);
246 m_pFtFullFileName->SetText( aFileName );
247 m_pFtFullSourceName->SetText( sLink );
248 m_pFtFullTypeName->SetText( sType );
250 return 0;
253 IMPL_LINK( SvBaseLinksDlg, LinksDoubleClickHdl, SvTabListBox *, pSvTabListBox )
255 (void)pSvTabListBox;
257 ChangeSourceClickHdl( 0 );
258 return 0;
261 IMPL_LINK( SvBaseLinksDlg, AutomaticClickHdl, RadioButton *, pRadioButton )
263 (void)pRadioButton;
265 sal_uLong nPos;
266 SvBaseLink* pLink = GetSelEntry( &nPos );
267 if( pLink && !( FILEOBJECT & pLink->GetObjType() ) &&
268 SfxLinkUpdateMode::ALWAYS != pLink->GetUpdateMode() )
269 SetType( *pLink, nPos, SfxLinkUpdateMode::ALWAYS );
270 return 0;
273 IMPL_LINK( SvBaseLinksDlg, ManualClickHdl, RadioButton *, pRadioButton )
275 (void)pRadioButton;
277 sal_uLong nPos;
278 SvBaseLink* pLink = GetSelEntry( &nPos );
279 if( pLink && !( FILEOBJECT & pLink->GetObjType() ) &&
280 SfxLinkUpdateMode::ONCALL != pLink->GetUpdateMode())
281 SetType( *pLink, nPos, SfxLinkUpdateMode::ONCALL );
282 return 0;
285 IMPL_LINK_NOARG(SvBaseLinksDlg, UpdateNowClickHdl)
287 SvTabListBox& rListBox = *m_pTbLinks;
288 sal_uLong nSelCnt = rListBox.GetSelectionCount();
289 if( 255 < nSelCnt )
290 nSelCnt = 255;
292 std::vector< SvBaseLink* > aLnkArr;
293 std::vector< sal_Int16 > aPosArr;
295 SvTreeListEntry* pE = rListBox.FirstSelected();
296 while( pE )
298 sal_uLong nFndPos = rListBox.GetModel()->GetAbsPos( pE );
299 if( TREELIST_ENTRY_NOTFOUND != nFndPos )
301 aLnkArr.push_back( static_cast< SvBaseLink* >( pE->GetUserData() ) );
302 aPosArr.push_back( nFndPos );
304 pE = rListBox.NextSelected( pE );
307 if( !aLnkArr.empty() )
309 for( size_t n = 0; n < aLnkArr.size(); ++n )
311 SvBaseLinkRef xLink = aLnkArr[ n ];
313 // first look for the entry in the array
314 for( size_t i = 0; i < pLinkMgr->GetLinks().size(); ++i )
315 if( &xLink == *pLinkMgr->GetLinks()[ i ] )
317 xLink->SetUseCache( false );
318 SetType( *xLink, aPosArr[ n ], xLink->GetUpdateMode() );
319 xLink->SetUseCache( true );
320 break;
324 // if somebody is of the opinion to swap his links (SD)
325 LinkManager* pNewMgr = pLinkMgr;
326 pLinkMgr = 0;
327 SetManager( pNewMgr );
330 if( 0 == (pE = rListBox.GetEntry( aPosArr[ 0 ] )) ||
331 pE->GetUserData() != aLnkArr[ 0 ] )
333 // search the link
334 pE = rListBox.First();
335 while( pE )
337 if( pE->GetUserData() == aLnkArr[ 0 ] )
338 break;
339 pE = rListBox.Next( pE );
342 if( !pE )
343 pE = rListBox.FirstSelected();
346 if( pE )
348 SvTreeListEntry* pSelEntry = rListBox.FirstSelected();
349 if( pE != pSelEntry )
350 rListBox.Select( pSelEntry, false );
351 rListBox.Select( pE );
352 rListBox.MakeVisible( pE );
355 pNewMgr->CloseCachedComps();
357 return 0;
360 IMPL_LINK( SvBaseLinksDlg, ChangeSourceClickHdl, PushButton *, pPushButton )
362 (void)pPushButton;
364 sal_uLong nSelectionCount = m_pTbLinks->GetSelectionCount();
365 if(nSelectionCount > 1)
369 uno::Reference<ui::dialogs::XFolderPicker2> xFolderPicker = ui::dialogs::FolderPicker::create(comphelper::getProcessComponentContext());
371 OUString sType, sFile, sLinkName;
372 OUString sFilter;
373 SvTreeListEntry* pEntry = m_pTbLinks->FirstSelected();
374 SvBaseLink* pLink = static_cast<SvBaseLink*>(pEntry->GetUserData());
375 sfx2::LinkManager::GetDisplayNames( pLink, &sType, &sFile, 0, 0 );
376 INetURLObject aUrl(sFile);
377 if(aUrl.GetProtocol() == INetProtocol::File)
379 OUString sOldPath(aUrl.PathToFileName());
380 sal_Int32 nLen = aUrl.GetName().getLength();
381 sOldPath = sOldPath.copy(0, sOldPath.getLength() - nLen);
382 xFolderPicker->setDisplayDirectory(sOldPath);
384 if (xFolderPicker->execute() == ui::dialogs::ExecutableDialogResults::OK)
386 OUString aPath = xFolderPicker->getDirectory();
388 for( sal_uLong i = 0; i < nSelectionCount; i++)
390 pEntry = i==0 ?
391 m_pTbLinks->FirstSelected() :
392 m_pTbLinks->NextSelected( pEntry );
393 DBG_ASSERT(pEntry,"Where is the entry?");
394 if (!pEntry)
395 continue;
396 pLink = static_cast<SvBaseLink*>(pEntry->GetUserData());
397 DBG_ASSERT(pLink,"Where is the link?");
398 if (!pLink)
399 continue;
400 sfx2::LinkManager::GetDisplayNames( pLink, &sType, &sFile, &sLinkName, &sFilter );
401 INetURLObject aUrl_(sFile);
402 INetURLObject aUrl2(aPath, INetProtocol::File);
403 aUrl2.insertName( aUrl_.getName() );
404 OUString sNewLinkName;
405 MakeLnkName( sNewLinkName, 0 ,
406 aUrl2.GetMainURL(INetURLObject::DECODE_TO_IURI), sLinkName, &sFilter);
407 pLink->SetLinkSourceName( sNewLinkName );
408 pLink->Update();
410 if( pLinkMgr->GetPersist() )
411 pLinkMgr->GetPersist()->SetModified();
412 LinkManager* pNewMgr = pLinkMgr;
413 pLinkMgr = 0;
414 SetManager( pNewMgr );
417 catch (uno::Exception & e)
419 SAL_WARN("cui.dialogs", "SvBaseLinksDlg: caught UNO exception: " << e.Message);
422 else
424 sal_uLong nPos;
425 SvBaseLink* pLink = GetSelEntry( &nPos );
426 if ( pLink && !pLink->GetLinkSourceName().isEmpty() )
427 pLink->Edit( this, LINK( this, SvBaseLinksDlg, EndEditHdl ) );
429 return 0;
432 IMPL_LINK( SvBaseLinksDlg, BreakLinkClickHdl, PushButton *, pPushButton )
434 (void)pPushButton;
436 bool bModified = false;
437 if(m_pTbLinks->GetSelectionCount() <= 1)
439 sal_uLong nPos;
440 SvBaseLinkRef xLink = GetSelEntry( &nPos );
441 if( !xLink.Is() )
442 return 0;
444 ScopedVclPtrInstance< QueryBox > aBox( this, WB_YES_NO | WB_DEF_YES, Closelinkmsg() );
446 if( RET_YES == aBox->Execute() )
448 m_pTbLinks->GetModel()->Remove( m_pTbLinks->GetEntry( nPos ) );
450 // close object, if it's still existing
451 bool bNewLnkMgr = OBJECT_CLIENT_FILE == xLink->GetObjType();
453 // tell the link that it will be resolved!
454 xLink->Closed();
456 // if somebody has forgotten to deregister himself
457 if( xLink.Is() )
458 pLinkMgr->Remove( &xLink );
460 if( bNewLnkMgr )
462 LinkManager* pNewMgr = pLinkMgr;
463 pLinkMgr = 0;
464 SetManager( pNewMgr );
466 SvTreeListEntry* pEntry = m_pTbLinks->GetEntry( nPos ? --nPos : 0 );
467 if( pEntry )
468 m_pTbLinks->SetCurEntry( pEntry );
470 bModified = true;
473 else
475 ScopedVclPtrInstance< QueryBox > aBox( this, WB_YES_NO | WB_DEF_YES, CloselinkmsgMulti() );
477 if( RET_YES == aBox->Execute() )
480 SvBaseLinkMemberList aLinkList;
481 SvTreeListEntry* pEntry = m_pTbLinks->FirstSelected();
482 while ( pEntry )
484 void * pUD = pEntry->GetUserData();
485 if( pUD )
486 aLinkList.push_back( static_cast<SvBaseLink*>(pUD) );
487 pEntry = m_pTbLinks->NextSelected(pEntry);
489 m_pTbLinks->RemoveSelection();
490 for( sal_uLong i = 0; i < aLinkList.size(); i++ )
492 SvBaseLinkRef xLink = aLinkList[i];
493 // tell the link that it will be resolved!
494 xLink->Closed();
496 // if somebody has forgotten to deregister himself
497 pLinkMgr->Remove( &xLink );
498 bModified = true;
500 // then remove all selected entries
503 if(bModified)
505 if( !m_pTbLinks->GetEntryCount() )
507 m_pRbAutomatic->Disable();
508 m_pRbManual->Disable();
509 m_pPbUpdateNow->Disable();
510 m_pPbChangeSource->Disable();
511 m_pPbBreakLink->Disable();
513 OUString aEmpty;
514 m_pFtFullSourceName->SetText( aEmpty );
515 m_pFtFullTypeName->SetText( aEmpty );
517 if( pLinkMgr && pLinkMgr->GetPersist() )
518 pLinkMgr->GetPersist()->SetModified();
520 return 0;
523 IMPL_LINK_NOARG_TYPED( SvBaseLinksDlg, UpdateWaitingHdl, Idle*, void )
525 m_pTbLinks->SetUpdateMode(false);
526 for( sal_uLong nPos = m_pTbLinks->GetEntryCount(); nPos; )
528 SvTreeListEntry* pBox = m_pTbLinks->GetEntry( --nPos );
529 SvBaseLinkRef xLink( static_cast<SvBaseLink*>(pBox->GetUserData()) );
530 if( xLink.Is() )
532 OUString sCur( ImplGetStateStr( *xLink ) ),
533 sOld( SvTabListBox::GetEntryText( pBox, 3 ) );
534 if( sCur != sOld )
535 m_pTbLinks->SetEntryText( sCur, pBox, 3 );
538 m_pTbLinks->SetUpdateMode(true);
541 IMPL_LINK( SvBaseLinksDlg, EndEditHdl, sfx2::SvBaseLink*, _pLink )
543 sal_uLong nPos;
544 GetSelEntry( &nPos );
546 if( _pLink && _pLink->WasLastEditOK() )
548 // StarImpress/Draw swap the LinkObjects themselves!
549 // So search for the link in the manager; if it does not exist
550 // anymore, fill the list completely new. Otherwise only the
551 // edited link needs to be refreshed.
552 bool bLinkFnd = false;
553 for( size_t n = pLinkMgr->GetLinks().size(); n; )
554 if( _pLink == &(*pLinkMgr->GetLinks()[ --n ]) )
556 bLinkFnd = true;
557 break;
560 if( bLinkFnd )
562 m_pTbLinks->SetUpdateMode(false);
563 m_pTbLinks->GetModel()->Remove( m_pTbLinks->GetEntry( nPos ) );
564 SvTreeListEntry* pToUnselect = m_pTbLinks->FirstSelected();
565 InsertEntry( *_pLink, nPos, true );
566 if(pToUnselect)
567 m_pTbLinks->Select(pToUnselect, false);
568 m_pTbLinks->SetUpdateMode(true);
570 else
572 LinkManager* pNewMgr = pLinkMgr;
573 pLinkMgr = 0;
574 SetManager( pNewMgr );
576 if (pLinkMgr && pLinkMgr->GetPersist())
577 pLinkMgr->GetPersist()->SetModified();
579 return 0;
582 OUString SvBaseLinksDlg::ImplGetStateStr( const SvBaseLink& rLnk )
584 OUString sRet;
585 if( !rLnk.GetObj() )
586 sRet = Brokenlink();
587 else if( rLnk.GetObj()->IsPending() )
589 sRet = Waitinglink();
590 StartUpdateTimer();
592 else if( SfxLinkUpdateMode::ALWAYS == rLnk.GetUpdateMode() )
593 sRet = Autolink();
594 else
595 sRet = Manuallink();
597 return sRet;
600 void SvBaseLinksDlg::SetManager( LinkManager* pNewMgr )
602 if( pLinkMgr == pNewMgr )
603 return;
605 if( pNewMgr )
606 // update has to be stopped before clear
607 m_pTbLinks->SetUpdateMode( false );
609 m_pTbLinks->Clear();
610 pLinkMgr = pNewMgr;
612 if( pLinkMgr )
614 SvBaseLinks& rLnks = (SvBaseLinks&)pLinkMgr->GetLinks();
615 for( size_t n = 0; n < rLnks.size(); ++n )
617 SvBaseLinkRef* pLinkRef = rLnks[ n ];
618 if( !pLinkRef->Is() )
620 rLnks.erase( rLnks.begin() + n );
621 --n;
622 continue;
624 if( (*pLinkRef)->IsVisible() )
625 InsertEntry( **pLinkRef );
628 if( !rLnks.empty() )
630 SvTreeListEntry* pEntry = m_pTbLinks->GetEntry( 0 );
631 m_pTbLinks->SetCurEntry( pEntry );
632 m_pTbLinks->Select( pEntry );
633 LinksSelectHdl( 0 );
635 m_pTbLinks->SetUpdateMode( true );
636 m_pTbLinks->Invalidate();
641 void SvBaseLinksDlg::InsertEntry( const SvBaseLink& rLink, sal_uLong nPos, bool bSelect )
643 OUString aEntry, sFileNm, sLinkNm, sTypeNm, sFilter;
645 sfx2::LinkManager::GetDisplayNames( &rLink, &sTypeNm, &sFileNm, &sLinkNm, &sFilter );
647 // GetTab(0) gives the position of the bitmap which is automatically inserted by the TabListBox.
648 // So the first text column's width is Tab(2)-Tab(1).
649 long nWidthPixel = m_pTbLinks->GetLogicTab( 2 ) - m_pTbLinks->GetLogicTab( 1 );
650 nWidthPixel -= SV_TAB_BORDER;
651 OUString aTxt = m_pTbLinks->GetEllipsisString( sFileNm, nWidthPixel, DrawTextFlags::PathEllipsis );
652 INetURLObject aPath( sFileNm, INetProtocol::File );
653 OUString aFileName = aPath.getName();
654 aFileName = INetURLObject::decode(aFileName, INetURLObject::DECODE_UNAMBIGUOUS);
656 if( aFileName.getLength() > aTxt.getLength() )
657 aTxt = aFileName;
658 else if( aTxt.indexOf( aFileName, aTxt.getLength() - aFileName.getLength() ) == -1 )
659 // filename not in string
660 aTxt = aFileName;
662 aEntry = aTxt;
663 aEntry += "\t";
664 if( OBJECT_CLIENT_GRF == rLink.GetObjType() )
665 aEntry += sFilter;
666 else
667 aEntry += sLinkNm;
668 aEntry += "\t";
669 aEntry += sTypeNm;
670 aEntry += "\t";
671 aEntry += ImplGetStateStr( rLink );
673 SvTreeListEntry * pE = m_pTbLinks->InsertEntryToColumn( aEntry, nPos );
674 pE->SetUserData( (void*)&rLink );
675 if(bSelect)
676 m_pTbLinks->Select(pE);
679 SvBaseLink* SvBaseLinksDlg::GetSelEntry( sal_uLong* pPos )
681 SvTreeListEntry* pE = m_pTbLinks->FirstSelected();
682 sal_uLong nPos;
683 if( pE && TREELIST_ENTRY_NOTFOUND !=
684 ( nPos = m_pTbLinks->GetModel()->GetAbsPos( pE ) ) )
686 DBG_ASSERT( pE, "wo kommt der leere Eintrag her?" );
688 if( pPos )
689 *pPos = nPos;
690 return static_cast<SvBaseLink*>(pE->GetUserData());
692 return 0;
695 void SvBaseLinksDlg::SetType( SvBaseLink& rLink,
696 sal_uLong nSelPos,
697 SfxLinkUpdateMode nType )
699 rLink.SetUpdateMode( nType );
700 rLink.Update();
701 SvTreeListEntry* pBox = m_pTbLinks->GetEntry( nSelPos );
702 m_pTbLinks->SetEntryText( ImplGetStateStr( rLink ), pBox, 3 );
703 if( pLinkMgr->GetPersist() )
704 pLinkMgr->GetPersist()->SetModified();
707 void SvBaseLinksDlg::SetActLink( SvBaseLink * pLink )
709 if( pLinkMgr )
711 const SvBaseLinks& rLnks = pLinkMgr->GetLinks();
712 sal_uLong nSelect = 0;
713 for( size_t n = 0; n < rLnks.size(); ++n )
715 SvBaseLinkRef* pLinkRef = rLnks[ n ];
716 // #109573# only visible links have been inserted into the TreeListBox,
717 // invisible ones have to be skipped here
718 if( (*pLinkRef)->IsVisible() )
720 if( pLink == *pLinkRef )
722 m_pTbLinks->Select( m_pTbLinks->GetEntry( nSelect ) );
723 LinksSelectHdl( 0 );
724 return ;
726 nSelect++;
732 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */