update credits
[LibreOffice.git] / svtools / source / contnr / fileview.cxx
blobf8104b65e2e25be6b615ac3914f9d234b763e08b
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 "fileview.hxx"
21 #include "sal/config.h"
22 #include "svtools/treelistentry.hxx"
23 #include <svtools/fileview.hxx>
24 #include <svtools/svtresid.hxx>
25 #include <svtools/imagemgr.hxx>
26 #include <svtools/headbar.hxx>
27 #include <svtools/svtabbx.hxx>
28 #include <svtools/svtools.hrc>
29 #include "svtools/viewdataentry.hxx"
30 #include "fileview.hrc"
31 #include "contentenumeration.hxx"
32 #include <svtools/AccessibleBrowseBoxObjType.hxx>
33 #include <com/sun/star/util/DateTime.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/task/InteractionHandler.hpp>
36 #include <com/sun/star/ucb/XProgressHandler.hpp>
37 #include <com/sun/star/sdbc/XResultSet.hpp>
38 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
39 #include <com/sun/star/ucb/XContentAccess.hpp>
40 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
41 #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
42 #include <com/sun/star/sdbc/XRow.hpp>
43 #include <com/sun/star/container/XChild.hpp>
44 #include <com/sun/star/ucb/CommandAbortedException.hpp>
45 #include <com/sun/star/ucb/ContentCreationException.hpp>
46 #include <vcl/waitobj.hxx>
47 #include <com/sun/star/io/XPersist.hpp>
48 #include <com/sun/star/beans/XPropertySet.hpp>
49 #include <com/sun/star/ucb/XCommandInfo.hpp>
50 #include <com/sun/star/beans/XPropertySetInfo.hpp>
51 #include <com/sun/star/beans/PropertyAttribute.hpp>
53 #include <algorithm>
54 #include <memory>
55 #include <vector>
56 #include <tools/urlobj.hxx>
57 #include <comphelper/processfactory.hxx>
58 #include <comphelper/string.hxx>
59 #include <unotools/localfilehelper.hxx>
60 #include <ucbhelper/content.hxx>
61 #include <ucbhelper/commandenvironment.hxx>
62 #include <vcl/msgbox.hxx>
63 #include <rtl/math.hxx>
64 #include <tools/config.hxx>
65 #include <osl/mutex.hxx>
66 #include <osl/conditn.hxx>
67 #include <salhelper/timer.hxx>
68 #include <vcl/svapp.hxx>
69 #include <unotools/ucbhelper.hxx>
70 #include <unotools/intlwrapper.hxx>
71 #include <unotools/syslocale.hxx>
72 #include <svl/urlfilter.hxx>
73 #include <boost/ptr_container/ptr_set.hpp>
75 using namespace ::com::sun::star::lang;
76 using namespace ::com::sun::star::sdbc;
77 using namespace ::com::sun::star::task;
78 using namespace ::com::sun::star::ucb;
79 using namespace ::com::sun::star::uno;
80 using namespace ::com::sun::star::io;
81 using namespace ::com::sun::star::beans;
82 using namespace ::comphelper;
83 using ::svt::SortingData_Impl;
84 using ::svt::FolderDescriptor;
86 #define ALL_FILES_FILTER "*.*"
88 #define COLUMN_TITLE 1
89 #define COLUMN_TYPE 2
90 #define COLUMN_SIZE 3
91 #define COLUMN_DATE 4
93 #define SEPARATOR_STR "----------------------------------"
95 #define ROW_HEIGHT 17 // the height of a row has to be a little higher than the bitmap
96 #define QUICK_SEARCH_TIMEOUT 1500 // time in mSec before the quicksearch string will be reseted
98 namespace
100 //====================================================================
101 //= ITimeoutHandler
102 //====================================================================
103 class CallbackTimer;
104 class ITimeoutHandler
106 public:
107 virtual void onTimeout( CallbackTimer* _pInstigator ) = 0;
109 protected:
110 ~ITimeoutHandler() {}
113 //====================================================================
114 //= CallbackTimer
115 //====================================================================
116 class CallbackTimer : public ::salhelper::Timer
118 protected:
119 ITimeoutHandler* m_pTimeoutHandler;
121 public:
122 CallbackTimer( ITimeoutHandler* _pHandler ) : m_pTimeoutHandler( _pHandler ) { }
124 protected:
125 virtual void SAL_CALL onShot();
128 //--------------------------------------------------------------------
129 void SAL_CALL CallbackTimer::onShot()
131 OSL_ENSURE( m_pTimeoutHandler, "CallbackTimer::onShot: nobody interested in?" );
132 ITimeoutHandler* pHandler( m_pTimeoutHandler );
133 if ( pHandler )
134 pHandler->onTimeout( this );
139 // -----------------------------------------------------------------------
141 void FilterMatch::createWildCardFilterList(const OUString& _rFilterList,::std::vector< WildCard >& _rFilters)
143 if( _rFilterList.getLength() )
145 // filter is given
146 sal_Int32 nIndex = 0;
147 OUString sToken;
150 sToken = _rFilterList.getToken( 0, ';', nIndex );
151 if ( !sToken.isEmpty() )
153 _rFilters.push_back( WildCard( sToken.toAsciiUpperCase() ) );
156 while ( nIndex >= 0 );
158 else
160 // no filter is given -> match all
161 _rFilters.push_back( WildCard(OUString("*")) );
164 // class ViewTabListBox_Impl ---------------------------------------------
166 class ViewTabListBox_Impl : public SvHeaderTabListBox
168 private:
169 Reference< XCommandEnvironment > mxCmdEnv;
171 ::osl::Mutex maMutex;
172 HeaderBar* mpHeaderBar;
173 SvtFileView_Impl* mpParent;
174 Timer maResetQuickSearch;
175 OUString maQuickSearchText;
176 String msAccessibleDescText;
177 String msFolder;
178 String msFile;
179 sal_uInt32 mnSearchIndex;
180 sal_Bool mbResizeDisabled : 1;
181 sal_Bool mbAutoResize : 1;
182 sal_Bool mbEnableDelete : 1;
183 sal_Bool mbEnableRename : 1;
184 bool mbShowHeader;
186 void DeleteEntries();
187 void DoQuickSearch( const sal_Unicode& rChar );
188 sal_Bool Kill( const OUString& rURL );
190 protected:
191 virtual sal_Bool DoubleClickHdl();
192 virtual OUString GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eType, sal_Int32 _nPos ) const;
194 public:
195 ViewTabListBox_Impl( Window* pParentWin, SvtFileView_Impl* pParent, sal_Int16 nFlags );
196 ~ViewTabListBox_Impl();
198 virtual void Resize();
199 virtual void KeyInput( const KeyEvent& rKEvt );
200 virtual sal_Bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText );
202 void ClearAll();
203 HeaderBar* GetHeaderBar() const { return mpHeaderBar; }
205 void EnableAutoResize() { mbAutoResize = sal_True; }
206 void EnableDelete( sal_Bool bEnable ) { mbEnableDelete = bEnable; }
207 void EnableRename( sal_Bool bEnable ) { mbEnableRename = bEnable; }
208 sal_Bool IsDeleteOrContextMenuEnabled() { return mbEnableDelete || IsContextMenuHandlingEnabled(); }
210 Reference< XCommandEnvironment > GetCommandEnvironment() const { return mxCmdEnv; }
212 DECL_LINK(ResetQuickSearch_Impl, void *);
214 virtual PopupMenu* CreateContextMenu( void );
215 virtual void ExcecuteContextMenuAction( sal_uInt16 nSelectedPopentry );
218 // class HashedEntry --------------------------------------------------
220 class HashedEntry
221 { // just a special String which can be compared on equality much faster
222 protected:
223 OUString maName;
224 sal_Int32 mnHashCode;
225 public:
226 inline HashedEntry( const OUString& rName );
227 inline HashedEntry( const INetURLObject& rURL );
228 inline HashedEntry( const HashedEntry& rCopy );
229 virtual ~HashedEntry();
231 inline bool operator ==( const HashedEntry& rRef ) const;
232 inline bool operator !=( const HashedEntry& rRef ) const;
233 inline bool operator <( const HashedEntry& rRef ) const;
235 inline const OUString& GetName() const;
238 inline HashedEntry::HashedEntry( const OUString& rName ): maName( rName ), mnHashCode( rName.hashCode() )
242 inline HashedEntry::HashedEntry( const INetURLObject& rURL ):
243 maName( rURL.GetMainURL( INetURLObject::NO_DECODE ) ),
244 mnHashCode( maName.hashCode() )
248 inline HashedEntry::HashedEntry( const HashedEntry& r ): maName( r.maName ), mnHashCode( r.mnHashCode )
252 HashedEntry::~HashedEntry()
256 inline bool HashedEntry::operator ==( const HashedEntry& rRef ) const
258 return mnHashCode == rRef.mnHashCode && maName.reverseCompareTo( rRef.maName ) == 0;
261 inline bool HashedEntry::operator !=( const HashedEntry& rRef ) const
263 return mnHashCode != rRef.mnHashCode || maName.reverseCompareTo( rRef.maName ) != 0;
266 inline bool HashedEntry::operator <( const HashedEntry& rRef ) const
268 if( mnHashCode == rRef.mnHashCode )
269 return maName.reverseCompareTo( rRef.maName ) < 0;
270 else
271 return mnHashCode < rRef.mnHashCode;
274 inline const OUString& HashedEntry::GetName() const
276 return maName;
279 // class HashedEntryList ----------------------------------------------
280 // provides a list of _unique_ Entries
281 class HashedEntryList : public boost::ptr_set<HashedEntry> {};
283 // class NameTranslationEntry -----------------------------------------
285 class NameTranslationEntry : public HashedEntry
286 {// a fast compareble String and another String, which is used to get a substitution for a given String
287 protected:
288 OUString maTranslatedName;
289 public:
290 inline NameTranslationEntry( const OUString& rOriginalName, const OUString& rTranslatedName );
291 inline NameTranslationEntry( const OString& rOriginalName, const OString& rTranslatedName );
293 inline const OUString& GetTranslation() const;
296 inline NameTranslationEntry::NameTranslationEntry( const OUString& rOrg, const OUString& rTrans ):
297 HashedEntry( rOrg ),
298 maTranslatedName( rTrans )
302 inline NameTranslationEntry::NameTranslationEntry( const OString& rOrg, const OString& rTrans )
303 : HashedEntry(OStringToOUString(rOrg, RTL_TEXTENCODING_ASCII_US))
304 , maTranslatedName(OStringToOUString(rTrans, RTL_TEXTENCODING_UTF8))
308 inline const OUString& NameTranslationEntry::GetTranslation() const
310 return maTranslatedName;
313 // class NameTranslationList -----------------------------------------
315 class NameTranslationList : protected HashedEntryList
316 { // contains a list of substitutes of strings for a given folder (as URL)
317 // explanation of the circumstances see in remarks for Init();
318 protected:
319 INetURLObject maTransFile; // URL of file with translation entries
320 HashedEntry maHashedURL; // for future purposes when dealing with a set of cached
321 // NameTranslationLists
322 private:
323 const String maTransFileName;
324 void Init(); // reads the translation file and fills the (internal) list
326 public:
327 NameTranslationList( const INetURLObject& rBaseURL );
328 // rBaseURL: path to folder for which the translation of the entries
329 // should be done
331 using HashedEntryList::operator==;
332 using HashedEntryList::operator!=;
333 inline bool operator ==( const HashedEntry& rRef ) const;
334 inline bool operator !=( const HashedEntry& rRef ) const;
336 const OUString* Translate( const OUString& rName ) const;
337 // returns NULL, if rName can't be found
339 inline void Update(); // clears list and init
341 inline const String& GetTransTableFileName() const;
342 // returns the name for the file, which contains the translation strings
345 inline const String& NameTranslationList::GetTransTableFileName() const
347 return maTransFileName;
350 void NameTranslationList::Init()
352 // Tries to read the file ".nametranslation.table" in the base folder. Complete path/name is in maTransFile.
353 // Further on, the found entries in the section "TRANSLATIONNAMES" are used to replace names in the
354 // base folder by translated ones. The translation must be given in UTF8
355 // See examples of such a files in the samples-folder of an Office installation
359 ::ucbhelper::Content aTestContent( maTransFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext() );
361 if( aTestContent.isDocument() )
363 // ... also tests the existence of maTransFile by throwing an Exception
364 String aFsysName( maTransFile.getFSysPath( INetURLObject::FSYS_DETECT ) );
365 Config aConfig( aFsysName );
367 aConfig.SetGroup( OString(RTL_CONSTASCII_STRINGPARAM("TRANSLATIONNAMES")) );
369 sal_uInt16 nKeyCnt = aConfig.GetKeyCount();
371 for( sal_uInt16 nCnt = 0 ; nCnt < nKeyCnt ; ++nCnt )
372 insert( new NameTranslationEntry( aConfig.GetKeyName( nCnt ), aConfig.ReadKey( nCnt ) ) );
375 catch( Exception const & ) {}
378 NameTranslationList::NameTranslationList( const INetURLObject& rBaseURL ):
379 maTransFile( rBaseURL ),
380 maHashedURL( rBaseURL ),
381 maTransFileName( OUString(".nametranslation.table") )
383 maTransFile.insertName( maTransFileName );
384 Init();
387 inline bool NameTranslationList::operator ==( const HashedEntry& rRef ) const
389 return maHashedURL == rRef;
392 inline bool NameTranslationList::operator !=( const HashedEntry& rRef ) const
394 return maHashedURL != rRef;
397 const OUString* NameTranslationList::Translate( const OUString& rName ) const
399 HashedEntry aRef( rName );
400 const NameTranslationEntry* pSearch = NULL;
401 for( const_iterator it = begin(); it != end(); ++it )
402 if( (*it) == aRef )
404 pSearch = static_cast<const NameTranslationEntry*>(&*it);
407 return pSearch ? &pSearch->GetTranslation() : NULL;
410 inline void NameTranslationList::Update()
412 clear();
413 Init();
416 // class NameTranslator_Impl ------------------------------------------
418 // enables the user to get string substitutions (translations for the content) for a given folder
419 // see more explanations above in the description for NameTranslationList
420 class NameTranslator_Impl : public ::svt::IContentTitleTranslation
422 private:
423 NameTranslationList* mpActFolder;
424 public:
425 NameTranslator_Impl( const INetURLObject& rActualFolder );
426 virtual ~NameTranslator_Impl();
428 // IContentTitleTranslation
429 virtual sal_Bool GetTranslation( const OUString& rOriginalName, OUString& rTranslatedName ) const;
431 void SetActualFolder( const INetURLObject& rActualFolder );
432 const String* GetTransTableFileName() const;
433 // returns the name for the file, which contains the translation strings
436 //====================================================================
437 //= SvtFileView_Impl
438 //====================================================================
440 class SvtFileView_Impl :public ::svt::IEnumerationResultHandler
441 ,public ITimeoutHandler
443 protected:
444 SvtFileView* mpAntiImpl;
445 Link m_aSelectHandler;
447 ::rtl::Reference< ::svt::FileViewContentEnumerator >
448 m_pContentEnumerator;
449 Link m_aCurrentAsyncActionHandler;
450 ::osl::Condition m_aAsyncActionFinished;
451 ::rtl::Reference< ::salhelper::Timer > m_pCancelAsyncTimer;
452 ::svt::EnumerationResult m_eAsyncActionResult;
453 bool m_bRunningAsyncAction;
454 bool m_bAsyncActionCancelled;
457 public:
459 ::std::vector< SortingData_Impl* > maContent;
460 ::osl::Mutex maMutex;
462 ViewTabListBox_Impl* mpView;
463 NameTranslator_Impl* mpNameTrans;
464 sal_uInt16 mnSortColumn;
465 sal_Bool mbAscending : 1;
466 sal_Bool mbOnlyFolder : 1;
467 sal_Bool mbReplaceNames : 1; // translate folder names or display doc-title instead of file name
468 sal_Int16 mnSuspendSelectCallback : 1;
469 sal_Bool mbIsFirstResort : 1;
471 IntlWrapper aIntlWrapper;
473 String maViewURL;
474 String maAllFilter;
475 String maCurrentFilter;
476 Image maFolderImage;
477 Link maOpenDoneLink;
478 Reference< XCommandEnvironment > mxCmdEnv;
480 SvtFileView_Impl( SvtFileView* pAntiImpl, Reference < XCommandEnvironment > xEnv,
481 sal_Int16 nFlags,
482 sal_Bool bOnlyFolder );
483 virtual ~SvtFileView_Impl();
485 void Clear();
487 FileViewResult GetFolderContent_Impl(
488 const String& rFolder,
489 const FileViewAsyncAction* pAsyncDescriptor,
490 const ::com::sun::star::uno::Sequence< OUString >& rBlackList = ::com::sun::star::uno::Sequence< OUString >() );
492 FileViewResult GetFolderContent_Impl(
493 const FolderDescriptor& _rFolder,
494 const FileViewAsyncAction* pAsyncDescriptor,
495 const ::com::sun::star::uno::Sequence< OUString >& rBlackList = ::com::sun::star::uno::Sequence< OUString >());
496 void FilterFolderContent_Impl( const OUString &rFilter );
497 void CancelRunningAsyncAction();
499 void OpenFolder_Impl();
500 // #83004# -------
501 void ReplaceTabWithString( OUString& aValue );
502 void CreateDisplayText_Impl();
503 void CreateVector_Impl( const Sequence < OUString > &rList );
504 void SortFolderContent_Impl();
506 void EntryRemoved( const OUString& rURL );
507 void EntryRenamed( OUString& rURL,
508 const OUString& rName );
509 String FolderInserted( const OUString& rURL,
510 const OUString& rTitle );
512 sal_uLong GetEntryPos( const OUString& rURL );
514 inline void EnableContextMenu( sal_Bool bEnable );
515 inline void EnableDelete( sal_Bool bEnable );
517 void Resort_Impl( sal_Int16 nColumn, sal_Bool bAscending );
518 sal_Bool SearchNextEntry( sal_uInt32 &nIndex,
519 const OUString& rTitle,
520 sal_Bool bWrapAround );
522 inline sal_Bool EnableNameReplacing( sal_Bool bEnable = sal_True ); // returns false, if action wasn't possible
523 void SetActualFolder( const INetURLObject& rActualFolder );
525 sal_Bool GetDocTitle( const OUString& rTargetURL, OUString& rDocTitle ) const;
527 void SetSelectHandler( const Link& _rHdl );
529 void InitSelection();
530 void ResetCursor();
532 inline void EndEditing( bool _bCancel );
534 protected:
535 DECL_LINK( SelectionMultiplexer, void* );
537 protected:
538 // IEnumerationResultHandler overridables
539 virtual void enumerationDone( ::svt::EnumerationResult _eResult );
540 void implEnumerationSuccess();
542 // ITimeoutHandler
543 virtual void onTimeout( CallbackTimer* _pInstigator );
546 inline void SvtFileView_Impl::EnableContextMenu( sal_Bool bEnable )
548 mpView->EnableContextMenuHandling( bEnable );
549 if( bEnable )
550 mbReplaceNames = sal_False;
553 inline void SvtFileView_Impl::EnableDelete( sal_Bool bEnable )
555 mpView->EnableDelete( bEnable );
556 if( bEnable )
557 mbReplaceNames = sal_False;
560 inline sal_Bool SvtFileView_Impl::EnableNameReplacing( sal_Bool bEnable )
562 mpView->EnableRename( bEnable );
564 sal_Bool bRet;
565 if( mpView->IsDeleteOrContextMenuEnabled() )
567 DBG_ASSERT( !mbReplaceNames, "SvtFileView_Impl::EnableNameReplacing(): state should be not possible!" );
568 bRet = !bEnable; // only for enabling this is an unsuccessful result
570 else
572 mbReplaceNames = bEnable;
573 bRet = sal_True;
576 return bRet;
579 inline void SvtFileView_Impl::EndEditing( bool _bCancel )
581 if ( mpView->IsEditingActive() )
582 mpView->EndEditing( _bCancel != false );
585 // functions -------------------------------------------------------------
587 OUString CreateExactSizeText( sal_Int64 nSize )
589 double fSize( ( double ) nSize );
590 int nDec;
592 long nMega = 1024 * 1024;
593 long nGiga = nMega * 1024;
595 OUString aUnitStr(' ');
597 if ( nSize < 10000 )
599 aUnitStr += SVT_RESSTR(STR_SVT_BYTES );
600 nDec = 0;
602 else if ( nSize < nMega )
604 fSize /= 1024;
605 aUnitStr += SVT_RESSTR(STR_SVT_KB);
606 nDec = 1;
608 else if ( nSize < nGiga )
610 fSize /= nMega;
611 aUnitStr += SVT_RESSTR(STR_SVT_MB);
612 nDec = 2;
614 else
616 fSize /= nGiga;
617 aUnitStr += SVT_RESSTR(STR_SVT_GB);
618 nDec = 3;
621 OUString aSizeStr( ::rtl::math::doubleToUString( fSize,
622 rtl_math_StringFormat_F, nDec,
623 SvtSysLocale().GetLocaleData().getNumDecimalSep()[0]) );
624 aSizeStr += aUnitStr;
626 return aSizeStr;
629 // -----------------------------------------------------------------------
630 // class ViewTabListBox_Impl ---------------------------------------------
631 // -----------------------------------------------------------------------
633 ViewTabListBox_Impl::ViewTabListBox_Impl( Window* pParentWin,
634 SvtFileView_Impl* pParent,
635 sal_Int16 nFlags ) :
637 SvHeaderTabListBox( pParentWin, WB_TABSTOP ),
639 mpHeaderBar ( NULL ),
640 mpParent ( pParent ),
641 msAccessibleDescText( SVT_RESSTR(STR_SVT_ACC_DESC_FILEVIEW) ),
642 msFolder ( SVT_RESSTR(STR_SVT_ACC_DESC_FOLDER) ),
643 msFile ( SVT_RESSTR(STR_SVT_ACC_DESC_FILE) ),
644 mnSearchIndex ( 0 ),
645 mbResizeDisabled ( sal_False ),
646 mbAutoResize ( sal_False ),
647 mbEnableDelete ( sal_True ),
648 mbEnableRename ( sal_True ),
649 mbShowHeader ( (nFlags & FILEVIEW_SHOW_NONE) == 0 )
651 Size aBoxSize = pParentWin->GetSizePixel();
652 mpHeaderBar = new HeaderBar( pParentWin, WB_BUTTONSTYLE | WB_BOTTOMBORDER );
653 mpHeaderBar->SetPosSizePixel( Point( 0, 0 ), mpHeaderBar->CalcWindowSizePixel() );
655 HeaderBarItemBits nBits = ( HIB_LEFT | HIB_VCENTER | HIB_CLICKABLE );
656 if (nFlags & FILEVIEW_SHOW_ONLYTITLE)
658 long pTabs[] = { 2, 20, 600 };
659 SetTabs(&pTabs[0], MAP_PIXEL);
661 mpHeaderBar->InsertItem(COLUMN_TITLE, SVT_RESSTR(STR_SVT_FILEVIEW_COLUMN_TITLE), 600, nBits | HIB_UPARROW);
663 else
665 long pTabs[] = { 5, 20, 180, 320, 400, 600 };
666 SetTabs(&pTabs[0], MAP_PIXEL);
667 SetTabJustify(2, AdjustRight); // column "Size"
669 mpHeaderBar->InsertItem(COLUMN_TITLE, SVT_RESSTR(STR_SVT_FILEVIEW_COLUMN_TITLE), 180, nBits | HIB_UPARROW);
670 mpHeaderBar->InsertItem(COLUMN_TYPE, SVT_RESSTR(STR_SVT_FILEVIEW_COLUMN_TYPE), 140, nBits);
671 mpHeaderBar->InsertItem(COLUMN_SIZE, SVT_RESSTR(STR_SVT_FILEVIEW_COLUMN_SIZE), 80, nBits);
672 mpHeaderBar->InsertItem(COLUMN_DATE, SVT_RESSTR(STR_SVT_FILEVIEW_COLUMN_DATE), 500, nBits);
675 Size aHeadSize = mpHeaderBar->GetSizePixel();
676 SetPosSizePixel( Point( 0, aHeadSize.Height() ),
677 Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) );
678 InitHeaderBar( mpHeaderBar );
679 SetHighlightRange();
680 SetEntryHeight( ROW_HEIGHT );
681 if (nFlags & FILEVIEW_MULTISELECTION)
682 SetSelectionMode( MULTIPLE_SELECTION );
684 Show();
685 if( mbShowHeader )
686 mpHeaderBar->Show();
688 maResetQuickSearch.SetTimeout( QUICK_SEARCH_TIMEOUT );
689 maResetQuickSearch.SetTimeoutHdl( LINK( this, ViewTabListBox_Impl, ResetQuickSearch_Impl ) );
691 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
692 Reference< XInteractionHandler > xInteractionHandler(
693 InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW );
695 mxCmdEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
697 EnableContextMenuHandling();
700 // -----------------------------------------------------------------------
702 ViewTabListBox_Impl::~ViewTabListBox_Impl()
704 maResetQuickSearch.Stop();
706 delete mpHeaderBar;
709 // -----------------------------------------------------------------------
711 IMPL_LINK_NOARG(ViewTabListBox_Impl, ResetQuickSearch_Impl)
713 ::osl::MutexGuard aGuard( maMutex );
715 maQuickSearchText = OUString();
716 mnSearchIndex = 0;
718 return 0;
721 // -----------------------------------------------------------------------
723 void ViewTabListBox_Impl::Resize()
725 SvTabListBox::Resize();
726 Size aBoxSize = Control::GetParent()->GetOutputSizePixel();
728 if ( mbResizeDisabled || !aBoxSize.Width() )
729 return;
731 Size aBarSize;
732 if ( mbShowHeader )
734 aBarSize = mpHeaderBar->GetSizePixel();
735 aBarSize.Width() = mbAutoResize ? aBoxSize.Width() : GetSizePixel().Width();
736 mpHeaderBar->SetSizePixel( aBarSize );
739 if ( mbAutoResize )
741 mbResizeDisabled = sal_True;
742 SetPosSizePixel( Point( 0, aBarSize.Height() ),
743 Size( aBoxSize.Width(), aBoxSize.Height() - aBarSize.Height() ) );
744 mbResizeDisabled = sal_False;
748 // -----------------------------------------------------------------------
750 void ViewTabListBox_Impl::KeyInput( const KeyEvent& rKEvt )
752 bool bHandled = false;
754 const KeyCode& rKeyCode = rKEvt.GetKeyCode();
755 if ( 0 == rKeyCode.GetModifier() )
757 if ( rKeyCode.GetCode() == KEY_RETURN )
759 ResetQuickSearch_Impl( NULL );
760 GetDoubleClickHdl().Call( this );
761 bHandled = true;
763 else if ( ( rKeyCode.GetCode() == KEY_DELETE ) &&
764 mbEnableDelete )
766 ResetQuickSearch_Impl( NULL );
767 DeleteEntries();
768 bHandled = true;
770 else if ( ( rKEvt.GetKeyCode().GetGroup() == KEYGROUP_NUM ) ||
771 ( rKEvt.GetKeyCode().GetGroup() == KEYGROUP_ALPHA ) )
773 DoQuickSearch( rKEvt.GetCharCode() );
774 bHandled = true;
778 if ( !bHandled )
780 ResetQuickSearch_Impl( NULL );
781 SvHeaderTabListBox::KeyInput( rKEvt );
785 // -----------------------------------------------------------------------
787 PopupMenu* ViewTabListBox_Impl::CreateContextMenu( void )
789 bool bEnableDelete = mbEnableDelete;
790 bool bEnableRename = mbEnableRename;
792 if ( bEnableDelete || bEnableRename )
794 sal_Int32 nSelectedEntries = GetSelectionCount();
795 bEnableDelete &= nSelectedEntries > 0;
796 bEnableRename &= nSelectedEntries == 1;
799 if ( bEnableDelete || bEnableRename )
801 SvTreeListEntry* pEntry = FirstSelected();
802 while ( pEntry )
804 ::ucbhelper::Content aCnt;
807 OUString aURL( static_cast< SvtContentEntry * >(
808 pEntry->GetUserData() )->maURL );
809 aCnt = ::ucbhelper::Content( aURL, mxCmdEnv, comphelper::getProcessComponentContext() );
811 catch( Exception const & )
813 bEnableDelete = bEnableRename = false;
816 if ( bEnableDelete )
820 Reference< XCommandInfo > aCommands = aCnt.getCommands();
821 if ( aCommands.is() )
822 bEnableDelete
823 = aCommands->hasCommandByName(
824 OUString( "delete" ) );
825 else
826 bEnableDelete = false;
828 catch( Exception const & )
830 bEnableDelete = false;
834 if ( bEnableRename )
838 Reference< XPropertySetInfo > aProps = aCnt.getProperties();
839 if ( aProps.is() )
841 Property aProp
842 = aProps->getPropertyByName(
843 OUString( "Title" ) );
844 bEnableRename
845 = !( aProp.Attributes & PropertyAttribute::READONLY );
847 else
848 bEnableRename = false;
850 catch( Exception const & )
852 bEnableRename = false;
856 pEntry = ( bEnableDelete || bEnableRename )
857 ? NextSelected( pEntry )
858 : 0;
862 if ( bEnableDelete || bEnableRename )
864 PopupMenu * pRet
865 = new PopupMenu( SvtResId( RID_FILEVIEW_CONTEXTMENU ) );
866 pRet->EnableItem( MID_FILEVIEW_DELETE, bEnableDelete );
867 pRet->EnableItem( MID_FILEVIEW_RENAME, bEnableRename );
868 pRet->RemoveDisabledEntries( sal_True, sal_True );
869 return pRet;
872 return NULL;
875 // -----------------------------------------------------------------------
877 void ViewTabListBox_Impl::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
879 switch ( nSelectedPopupEntry )
881 case MID_FILEVIEW_DELETE :
882 DeleteEntries();
883 break;
885 case MID_FILEVIEW_RENAME :
886 EditEntry( FirstSelected() );
887 break;
891 // -----------------------------------------------------------------------
893 void ViewTabListBox_Impl::ClearAll()
895 for ( sal_uInt16 i = 0; i < GetEntryCount(); ++i )
896 delete (SvtContentEntry*)GetEntry(i)->GetUserData();
897 Clear();
900 // -----------------------------------------------------------------------
901 void ViewTabListBox_Impl::DeleteEntries()
903 svtools::QueryDeleteResult_Impl eResult = svtools::QUERYDELETE_YES;
904 SvTreeListEntry* pEntry = FirstSelected();
905 String aURL;
907 OString sDialogPosition;
908 while ( pEntry && ( eResult != svtools::QUERYDELETE_CANCEL ) )
910 SvTreeListEntry *pCurEntry = pEntry;
911 pEntry = NextSelected( pEntry );
913 if ( pCurEntry->GetUserData() )
914 aURL = ( (SvtContentEntry*)pCurEntry->GetUserData() )->maURL;
916 if ( !aURL.Len() )
917 continue;
919 bool canDelete = true;
922 ::ucbhelper::Content aCnt( aURL, mxCmdEnv, comphelper::getProcessComponentContext() );
923 Reference< XCommandInfo > aCommands = aCnt.getCommands();
924 if ( aCommands.is() )
925 canDelete
926 = aCommands->hasCommandByName(
927 OUString( "delete" ) );
928 else
929 canDelete = false;
931 catch( Exception const & )
933 canDelete = false;
936 if (!canDelete)
937 continue; // process next entry
939 if ( eResult != svtools::QUERYDELETE_ALL )
941 INetURLObject aObj( aURL );
942 svtools::QueryDeleteDlg_Impl aDlg( NULL, aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ) );
943 if ( sDialogPosition.getLength() )
944 aDlg.SetWindowState( sDialogPosition );
946 if ( GetSelectionCount() > 1 )
947 aDlg.EnableAllButton();
949 if ( aDlg.Execute() == RET_OK )
950 eResult = aDlg.GetResult();
951 else
952 eResult = svtools::QUERYDELETE_CANCEL;
954 sDialogPosition = aDlg.GetWindowState( );
957 if ( ( eResult == svtools::QUERYDELETE_ALL ) ||
958 ( eResult == svtools::QUERYDELETE_YES ) )
960 if ( Kill( aURL ) )
962 delete (SvtContentEntry*)pCurEntry->GetUserData();
963 GetModel()->Remove( pCurEntry );
964 mpParent->EntryRemoved( aURL );
970 // -----------------------------------------------------------------------
971 sal_Bool ViewTabListBox_Impl::EditedEntry( SvTreeListEntry* pEntry,
972 const OUString& rNewText )
974 sal_Bool bRet = sal_False;
976 OUString aURL;
977 SvtContentEntry* pData = (SvtContentEntry*)pEntry->GetUserData();
979 if ( pData )
980 aURL = OUString( pData->maURL );
982 if ( aURL.isEmpty() )
983 return bRet;
987 OUString aPropName( "Title" );
988 bool canRename = true;
989 ::ucbhelper::Content aContent( aURL, mxCmdEnv, comphelper::getProcessComponentContext() );
993 Reference< XPropertySetInfo > aProps = aContent.getProperties();
994 if ( aProps.is() )
996 Property aProp = aProps->getPropertyByName( aPropName );
997 canRename = !( aProp.Attributes & PropertyAttribute::READONLY );
999 else
1001 canRename = false;
1004 catch ( Exception const & )
1006 canRename = false;
1009 if ( canRename )
1011 Any aValue;
1012 aValue <<= rNewText;
1013 aContent.setPropertyValue( aPropName, aValue );
1014 mpParent->EntryRenamed( aURL, rNewText );
1016 pData->maURL = aURL;
1017 pEntry->SetUserData( pData );
1019 bRet = sal_True;
1022 catch( Exception const & )
1026 return bRet;
1029 // -----------------------------------------------------------------------
1030 void ViewTabListBox_Impl::DoQuickSearch( const sal_Unicode& rChar )
1032 ::osl::MutexGuard aGuard( maMutex );
1034 maResetQuickSearch.Stop();
1036 OUString aLastText = maQuickSearchText;
1037 sal_uInt32 aLastPos = mnSearchIndex;
1039 maQuickSearchText += OUString(rChar).toAsciiLowerCase();
1041 sal_Bool bFound = mpParent->SearchNextEntry( mnSearchIndex, maQuickSearchText, sal_False );
1043 if ( !bFound && ( aLastText.getLength() == 1 ) &&
1044 ( aLastText == OUString(rChar) ) )
1046 mnSearchIndex = aLastPos + 1;
1047 maQuickSearchText = aLastText;
1048 bFound = mpParent->SearchNextEntry( mnSearchIndex, maQuickSearchText, sal_True );
1051 if ( bFound )
1053 SvTreeListEntry* pEntry = GetEntry( mnSearchIndex );
1054 if ( pEntry )
1056 SelectAll( sal_False );
1057 Select( pEntry );
1058 SetCurEntry( pEntry );
1059 MakeVisible( pEntry );
1063 maResetQuickSearch.Start();
1066 // -----------------------------------------------------------------------
1067 sal_Bool ViewTabListBox_Impl::DoubleClickHdl()
1069 SvHeaderTabListBox::DoubleClickHdl();
1070 return sal_False;
1071 // this means "do no additional handling". Especially this means that the SvImpLBox does not
1072 // recognize that the entry at the double click position change after the handler call (which is
1073 // the case if in the handler, our content was replaced)
1074 // If it _would_ recognize this change, it would take this as a reason to select the entry, again
1075 // - which is not what in the case of content replace
1076 // (I really doubt that this behaviour of the SvImpLBox does make any sense at all, but
1077 // who knows ...)
1080 OUString ViewTabListBox_Impl::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eType, sal_Int32 _nPos ) const
1082 OUString sRet = SvHeaderTabListBox::GetAccessibleObjectDescription( _eType, _nPos );
1083 if ( ::svt::BBTYPE_TABLECELL == _eType )
1085 sal_Int32 nRow = -1;
1086 const sal_uInt16 nColumnCount = GetColumnCount();
1087 if (nColumnCount > 0)
1088 nRow = _nPos / nColumnCount;
1089 SvTreeListEntry* pEntry = GetEntry( nRow );
1090 if ( pEntry )
1092 SvtContentEntry* pData = (SvtContentEntry*)pEntry->GetUserData();
1093 if ( pData )
1095 const String sVar1( RTL_CONSTASCII_USTRINGPARAM( "%1" ) );
1096 const String sVar2( RTL_CONSTASCII_USTRINGPARAM( "%2" ) );
1097 String aText( msAccessibleDescText );
1098 aText.SearchAndReplace( sVar1, pData->mbIsFolder ? msFolder : msFile );
1099 aText.SearchAndReplace( sVar2, pData->maURL );
1100 sRet += OUString( aText );
1105 return sRet;
1108 // -----------------------------------------------------------------------
1109 sal_Bool ViewTabListBox_Impl::Kill( const OUString& rContent )
1111 sal_Bool bRet = sal_True;
1115 ::ucbhelper::Content aCnt( rContent, mxCmdEnv, comphelper::getProcessComponentContext() );
1116 aCnt.executeCommand( OUString( "delete" ), makeAny( sal_Bool( sal_True ) ) );
1118 catch( ::com::sun::star::ucb::CommandAbortedException const & )
1120 DBG_WARNING( "CommandAbortedException" );
1121 bRet = sal_False;
1123 catch( Exception const & )
1125 DBG_WARNING( "Any other exception" );
1126 bRet = sal_False;
1129 return bRet;
1135 // -----------------------------------------------------------------------
1136 // class SvtFileView -----------------------------------------------------
1137 // -----------------------------------------------------------------------
1139 SvtFileView::SvtFileView( Window* pParent, const ResId& rResId,
1140 sal_Bool bOnlyFolder, sal_Bool bMultiSelection ) :
1142 Control( pParent, rResId )
1144 sal_Int8 nFlags = 0;
1145 if ( bOnlyFolder )
1146 nFlags |= FILEVIEW_ONLYFOLDER;
1147 if ( bMultiSelection )
1148 nFlags |= FILEVIEW_MULTISELECTION;
1150 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1151 Reference< XInteractionHandler > xInteractionHandler(
1152 InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW );
1153 Reference < XCommandEnvironment > xCmdEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
1155 mpImp = new SvtFileView_Impl( this, xCmdEnv, nFlags, bOnlyFolder );
1156 mpImp->mpView->ForbidEmptyText();
1157 SetSortColumn( true );
1159 HeaderBar* pHeaderBar = mpImp->mpView->GetHeaderBar();
1160 pHeaderBar->SetSelectHdl( LINK( this, SvtFileView, HeaderSelect_Impl ) );
1161 pHeaderBar->SetEndDragHdl( LINK( this, SvtFileView, HeaderEndDrag_Impl ) );
1164 SvtFileView::SvtFileView( Window* pParent, const ResId& rResId, sal_uInt8 nFlags ) :
1166 Control( pParent, rResId )
1168 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1169 Reference< XInteractionHandler > xInteractionHandler(
1170 InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW );
1171 Reference < XCommandEnvironment > xCmdEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
1173 mpImp = new SvtFileView_Impl( this, xCmdEnv, nFlags, nFlags & FILEVIEW_ONLYFOLDER );
1175 SetSortColumn( (nFlags & FILEVIEW_SHOW_NONE) == 0 );
1177 HeaderBar *pHeaderBar = mpImp->mpView->GetHeaderBar();
1178 pHeaderBar->SetSelectHdl( LINK( this, SvtFileView, HeaderSelect_Impl ) );
1179 pHeaderBar->SetEndDragHdl( LINK( this, SvtFileView, HeaderEndDrag_Impl ) );
1182 // -----------------------------------------------------------------------
1184 SvtFileView::~SvtFileView()
1186 // use temp pointer to prevent access of deleted member (GetFocus())
1187 SvtFileView_Impl* pTemp = mpImp;
1188 mpImp = NULL;
1189 delete pTemp;
1192 // -----------------------------------------------------------------------
1194 String SvtFileView::GetURL( SvTreeListEntry* pEntry ) const
1196 String aURL;
1197 if ( pEntry && pEntry->GetUserData() )
1198 aURL = ( (SvtContentEntry*)pEntry->GetUserData() )->maURL;
1199 return aURL;
1202 // -----------------------------------------------------------------------
1204 String SvtFileView::GetCurrentURL() const
1206 String aURL;
1207 SvTreeListEntry* pEntry = mpImp->mpView->FirstSelected();
1208 if ( pEntry && pEntry->GetUserData() )
1209 aURL = ( (SvtContentEntry*)pEntry->GetUserData() )->maURL;
1210 return aURL;
1212 // -----------------------------------------------------------------------------
1214 void SvtFileView::CreatedFolder( const String& rUrl, const String& rNewFolder )
1216 String sEntry = mpImp->FolderInserted( rUrl, rNewFolder );
1217 SvTreeListEntry* pEntry = mpImp->mpView->InsertEntry( sEntry, mpImp->maFolderImage, mpImp->maFolderImage );
1218 SvtContentEntry* pUserData = new SvtContentEntry( rUrl, sal_True );
1219 pEntry->SetUserData( pUserData );
1220 mpImp->mpView->MakeVisible( pEntry );
1223 // -----------------------------------------------------------------------
1225 FileViewResult SvtFileView::PreviousLevel( const FileViewAsyncAction* pAsyncDescriptor )
1227 FileViewResult eResult = eFailure;
1229 String sParentURL;
1230 if ( GetParentURL( sParentURL ) )
1231 eResult = Initialize( sParentURL, mpImp->maCurrentFilter, pAsyncDescriptor, mpBlackList );
1233 return eResult;
1236 // -----------------------------------------------------------------------
1238 sal_Bool SvtFileView::GetParentURL( String& rParentURL ) const
1240 sal_Bool bRet = sal_False;
1243 ::ucbhelper::Content aCnt( mpImp->maViewURL, mpImp->mxCmdEnv, comphelper::getProcessComponentContext() );
1244 Reference< XContent > xContent( aCnt.get() );
1245 Reference< com::sun::star::container::XChild > xChild( xContent, UNO_QUERY );
1246 if ( xChild.is() )
1248 Reference< XContent > xParent( xChild->getParent(), UNO_QUERY );
1249 if ( xParent.is() )
1251 rParentURL = String( xParent->getIdentifier()->getContentIdentifier() );
1252 bRet = ( rParentURL.Len() > 0 && rParentURL != mpImp->maViewURL );
1256 catch( Exception const & )
1258 // perhaps an unknown url protocol (e.g. "private:newdoc")
1261 return bRet;
1264 // -----------------------------------------------------------------------
1266 const OString& SvtFileView::GetHelpId( ) const
1268 return mpImp->mpView->GetHelpId( );
1271 // -----------------------------------------------------------------------
1273 void SvtFileView::SetHelpId( const OString& rHelpId )
1275 mpImp->mpView->SetHelpId( rHelpId );
1278 // -----------------------------------------------------------------------
1280 void SvtFileView::SetSizePixel( const Size& rNewSize )
1282 Control::SetSizePixel( rNewSize );
1283 mpImp->mpView->SetSizePixel( rNewSize );
1286 // -----------------------------------------------------------------------
1288 void SvtFileView::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
1290 SetPosPixel( rNewPos );
1291 SetSizePixel( rNewSize );
1294 // -----------------------------------------------------------------------------
1295 sal_Bool SvtFileView::Initialize( const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent>& _xContent, const String& rFilter )
1297 WaitObject aWaitCursor( this );
1299 mpImp->Clear();
1300 ::ucbhelper::Content aContent(_xContent, mpImp->mxCmdEnv, comphelper::getProcessComponentContext() );
1301 FileViewResult eResult = mpImp->GetFolderContent_Impl( FolderDescriptor( aContent ), NULL );
1302 OSL_ENSURE( eResult != eStillRunning, "SvtFileView::Initialize: this was expected to be synchronous!" );
1303 if ( eResult != eSuccess )
1304 return sal_False;
1306 mpImp->FilterFolderContent_Impl( rFilter );
1308 mpImp->SortFolderContent_Impl(); // possibly not necessary!!!!!!!!!!
1309 mpImp->CreateDisplayText_Impl();
1310 mpImp->OpenFolder_Impl();
1312 mpImp->maOpenDoneLink.Call( this );
1313 return sal_True;
1316 // -----------------------------------------------------------------------
1317 FileViewResult SvtFileView::Initialize(
1318 const String& rURL,
1319 const String& rFilter,
1320 const FileViewAsyncAction* pAsyncDescriptor,
1321 const ::com::sun::star::uno::Sequence< OUString >& rBlackList )
1323 WaitObject aWaitCursor( this );
1324 mpBlackList = rBlackList;
1326 String sPushURL( mpImp->maViewURL );
1328 mpImp->maViewURL = rURL;
1329 FileViewResult eResult = ExecuteFilter( rFilter, pAsyncDescriptor );
1330 switch ( eResult )
1332 case eFailure:
1333 case eTimeout:
1334 mpImp->maViewURL = sPushURL;
1335 return eResult;
1337 case eStillRunning:
1338 OSL_ENSURE( pAsyncDescriptor, "SvtFileView::Initialize: we told it to read synchronously!" );
1339 case eSuccess:
1340 return eResult;
1343 OSL_FAIL( "SvtFileView::Initialize: unreachable!" );
1344 return eFailure;
1347 // -----------------------------------------------------------------------
1348 FileViewResult SvtFileView::Initialize(
1349 const String& rURL,
1350 const String& rFilter,
1351 const FileViewAsyncAction* pAsyncDescriptor )
1353 return Initialize( rURL, rFilter, pAsyncDescriptor, ::com::sun::star::uno::Sequence< OUString >());
1356 // -----------------------------------------------------------------------
1358 // -----------------------------------------------------------------------
1359 sal_Bool SvtFileView::Initialize( const Sequence< OUString >& aContents )
1361 WaitObject aWaitCursor( this );
1363 mpImp->maViewURL = String();
1364 mpImp->maCurrentFilter = mpImp->maAllFilter;
1366 mpImp->Clear();
1367 mpImp->CreateVector_Impl( aContents );
1368 if( GetSortColumn() )
1369 mpImp->SortFolderContent_Impl();
1371 mpImp->OpenFolder_Impl();
1373 mpImp->maOpenDoneLink.Call( this );
1375 return sal_True;
1378 // -----------------------------------------------------------------------
1380 FileViewResult SvtFileView::ExecuteFilter( const String& rFilter, const FileViewAsyncAction* pAsyncDescriptor )
1382 mpImp->maCurrentFilter = rFilter;
1383 mpImp->maCurrentFilter.ToLowerAscii();
1385 mpImp->Clear();
1386 FileViewResult eResult = mpImp->GetFolderContent_Impl( mpImp->maViewURL, pAsyncDescriptor, mpBlackList );
1387 OSL_ENSURE( ( eResult != eStillRunning ) || pAsyncDescriptor, "SvtFileView::ExecuteFilter: we told it to read synchronously!" );
1388 return eResult;
1391 // -----------------------------------------------------------------------
1393 void SvtFileView::CancelRunningAsyncAction()
1395 mpImp->CancelRunningAsyncAction();
1398 // -----------------------------------------------------------------------
1400 void SvtFileView::SetNoSelection()
1402 mpImp->mpView->SelectAll( sal_False );
1405 // -----------------------------------------------------------------------
1407 void SvtFileView::GetFocus()
1409 Control::GetFocus();
1410 if ( mpImp && mpImp->mpView )
1411 mpImp->mpView->GrabFocus();
1414 // -----------------------------------------------------------------------
1416 void SvtFileView::SetSelectHdl( const Link& rHdl )
1418 mpImp->SetSelectHandler( rHdl );
1421 // -----------------------------------------------------------------------
1423 void SvtFileView::SetDoubleClickHdl( const Link& rHdl )
1425 mpImp->mpView->SetDoubleClickHdl( rHdl );
1428 // -----------------------------------------------------------------------
1430 sal_uLong SvtFileView::GetSelectionCount() const
1432 return mpImp->mpView->GetSelectionCount();
1435 // -----------------------------------------------------------------------
1437 SvTreeListEntry* SvtFileView::FirstSelected() const
1439 return mpImp->mpView->FirstSelected();
1442 // -----------------------------------------------------------------------
1444 SvTreeListEntry* SvtFileView::NextSelected( SvTreeListEntry* pEntry ) const
1446 return mpImp->mpView->NextSelected( pEntry );
1449 // -----------------------------------------------------------------------
1451 void SvtFileView::EnableAutoResize()
1453 mpImp->mpView->EnableAutoResize();
1456 // -----------------------------------------------------------------------
1458 void SvtFileView::SetFocus()
1460 mpImp->mpView->GrabFocus();
1463 // -----------------------------------------------------------------------
1464 const String& SvtFileView::GetViewURL() const
1466 return mpImp->maViewURL;
1469 // -----------------------------------------------------------------------
1470 void SvtFileView::SetOpenDoneHdl( const Link& rHdl )
1472 mpImp->maOpenDoneLink = rHdl;
1475 // -----------------------------------------------------------------------
1476 void SvtFileView::EnableContextMenu( sal_Bool bEnable )
1478 mpImp->EnableContextMenu( bEnable );
1481 // -----------------------------------------------------------------------
1482 void SvtFileView::EnableDelete( sal_Bool bEnable )
1484 mpImp->EnableDelete( bEnable );
1487 void SvtFileView::EnableNameReplacing( sal_Bool bEnable )
1489 mpImp->EnableNameReplacing( bEnable );
1492 // -----------------------------------------------------------------------
1493 void SvtFileView::EndInplaceEditing( bool _bCancel )
1495 return mpImp->EndEditing( _bCancel );
1498 // -----------------------------------------------------------------------
1499 IMPL_LINK( SvtFileView, HeaderSelect_Impl, HeaderBar*, pBar )
1501 DBG_ASSERT( pBar, "no headerbar" );
1502 sal_uInt16 nItemID = pBar->GetCurItemId();
1504 HeaderBarItemBits nBits;
1506 // clear the arrow of the recently used column
1507 if ( nItemID != mpImp->mnSortColumn )
1509 if ( !nItemID )
1511 // first call -> remove arrow from title column,
1512 // because another column is the sort column
1513 nItemID = mpImp->mnSortColumn;
1514 mpImp->mnSortColumn = COLUMN_TITLE;
1516 nBits = pBar->GetItemBits( mpImp->mnSortColumn );
1517 nBits &= ~( HIB_UPARROW | HIB_DOWNARROW );
1518 pBar->SetItemBits( mpImp->mnSortColumn, nBits );
1521 nBits = pBar->GetItemBits( nItemID );
1523 sal_Bool bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
1525 if ( bUp )
1527 nBits &= ~HIB_UPARROW;
1528 nBits |= HIB_DOWNARROW;
1530 else
1532 nBits &= ~HIB_DOWNARROW;
1533 nBits |= HIB_UPARROW;
1536 pBar->SetItemBits( nItemID, nBits );
1537 mpImp->Resort_Impl( nItemID, !bUp );
1538 return 1;
1541 // -----------------------------------------------------------------------
1542 IMPL_LINK( SvtFileView, HeaderEndDrag_Impl, HeaderBar*, pBar )
1544 if ( !pBar->IsItemMode() )
1546 Size aSize;
1547 sal_uInt16 nTabs = pBar->GetItemCount();
1548 long nTmpSize = 0;
1550 for ( sal_uInt16 i = 1; i <= nTabs; ++i )
1552 long nWidth = pBar->GetItemSize(i);
1553 aSize.Width() = nWidth + nTmpSize;
1554 nTmpSize += nWidth;
1555 mpImp->mpView->SetTab( i, aSize.Width(), MAP_PIXEL );
1559 return 0;
1562 // -----------------------------------------------------------------------
1563 String SvtFileView::GetConfigString() const
1565 String sRet;
1566 HeaderBar* pBar = mpImp->mpView->GetHeaderBar();
1567 DBG_ASSERT( pBar, "invalid headerbar" );
1569 // sort order
1570 sRet += OUString::number( mpImp->mnSortColumn );
1571 sRet += ';';
1572 HeaderBarItemBits nBits = pBar->GetItemBits( mpImp->mnSortColumn );
1573 sal_Bool bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
1574 sRet += bUp ? '1' : '0';
1575 sRet += ';';
1577 sal_uInt16 nCount = pBar->GetItemCount();
1578 for ( sal_uInt16 i = 0; i < nCount; ++i )
1580 sal_uInt16 nId = pBar->GetItemId(i);
1581 sRet += OUString::number( nId );
1582 sRet += ';';
1583 sRet += OUString::number( pBar->GetItemSize( nId ) );
1584 sRet += ';';
1587 sRet = comphelper::string::stripEnd(sRet, ';');
1588 return sRet;
1591 // -----------------------------------------------------------------------
1592 void SvtFileView::SetConfigString( const String& rCfgStr )
1594 HeaderBar* pBar = mpImp->mpView->GetHeaderBar();
1595 DBG_ASSERT( pBar, "invalid headerbar" );
1597 sal_Int32 nIdx = 0;
1598 mpImp->mnSortColumn = (sal_uInt16)rCfgStr.GetToken( 0, ';', nIdx ).ToInt32();
1599 sal_Bool bUp = (sal_Bool)(sal_uInt16)rCfgStr.GetToken( 0, ';', nIdx ).ToInt32();
1600 HeaderBarItemBits nBits = pBar->GetItemBits( mpImp->mnSortColumn );
1602 if ( bUp )
1604 nBits &= ~HIB_UPARROW;
1605 nBits |= HIB_DOWNARROW;
1607 else
1609 nBits &= ~HIB_DOWNARROW;
1610 nBits |= HIB_UPARROW;
1612 pBar->SetItemBits( mpImp->mnSortColumn, nBits );
1614 while ( nIdx != -1 )
1616 sal_uInt16 nItemId = (sal_uInt16)rCfgStr.GetToken( 0, ';', nIdx ).ToInt32();
1617 pBar->SetItemSize( nItemId, rCfgStr.GetToken( 0, ';', nIdx ).ToInt32() );
1620 HeaderSelect_Impl( pBar );
1621 HeaderEndDrag_Impl( pBar );
1624 // -----------------------------------------------------------------------
1625 void SvtFileView::StateChanged( StateChangedType nStateChange )
1627 if ( nStateChange == STATE_CHANGE_ENABLE )
1628 Invalidate();
1629 Control::StateChanged( nStateChange );
1632 // -----------------------------------------------------------------------
1633 // class NameTranslator_Impl
1634 // -----------------------------------------------------------------------
1636 NameTranslator_Impl::NameTranslator_Impl( const INetURLObject& rActualFolder )
1638 mpActFolder = new NameTranslationList( rActualFolder );
1641 NameTranslator_Impl::~NameTranslator_Impl()
1643 if( mpActFolder )
1644 delete mpActFolder;
1647 void NameTranslator_Impl::SetActualFolder( const INetURLObject& rActualFolder )
1649 HashedEntry aActFolder( rActualFolder );
1651 if( mpActFolder )
1653 if( *mpActFolder != aActFolder )
1655 delete mpActFolder;
1656 mpActFolder = new NameTranslationList( rActualFolder );
1659 else
1660 mpActFolder = new NameTranslationList( rActualFolder );
1663 sal_Bool NameTranslator_Impl::GetTranslation( const OUString& rOrg, OUString& rTrans ) const
1665 sal_Bool bRet = sal_False;
1667 if( mpActFolder )
1669 const OUString* pTrans = mpActFolder->Translate( rOrg );
1670 if( pTrans )
1672 rTrans = *pTrans;
1673 bRet = sal_True;
1677 return bRet;
1680 const String* NameTranslator_Impl::GetTransTableFileName() const
1682 return mpActFolder? &mpActFolder->GetTransTableFileName() : NULL;
1685 // -----------------------------------------------------------------------
1686 // class SvtFileView_Impl
1687 // -----------------------------------------------------------------------
1689 SvtFileView_Impl::SvtFileView_Impl( SvtFileView* pAntiImpl, Reference < XCommandEnvironment > xEnv, sal_Int16 nFlags, sal_Bool bOnlyFolder )
1691 :mpAntiImpl ( pAntiImpl )
1692 ,m_eAsyncActionResult ( ::svt::ERROR )
1693 ,m_bRunningAsyncAction ( false )
1694 ,m_bAsyncActionCancelled ( false )
1695 ,mpNameTrans ( NULL )
1696 ,mnSortColumn ( COLUMN_TITLE )
1697 ,mbAscending ( sal_True )
1698 ,mbOnlyFolder ( bOnlyFolder )
1699 ,mbReplaceNames ( sal_False )
1700 ,mnSuspendSelectCallback ( 0 )
1701 ,mbIsFirstResort ( sal_True )
1702 ,aIntlWrapper ( Application::GetSettings().GetLanguageTag() )
1703 ,maFolderImage ( SvtResId( IMG_SVT_FOLDER ) )
1704 ,mxCmdEnv ( xEnv )
1707 maAllFilter = OUString("*.*");
1708 mpView = new ViewTabListBox_Impl( mpAntiImpl, this, nFlags );
1709 mpView->EnableCellFocus();
1712 // -----------------------------------------------------------------------
1713 SvtFileView_Impl::~SvtFileView_Impl()
1715 Clear();
1717 // use temp pointer to prevent access of deleted member (GetFocus())
1718 ViewTabListBox_Impl* pTemp = mpView;
1719 mpView = NULL;
1720 delete pTemp;
1723 // -----------------------------------------------------------------------
1724 void SvtFileView_Impl::Clear()
1726 ::osl::MutexGuard aGuard( maMutex );
1728 std::vector< SortingData_Impl* >::iterator aIt;
1730 for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
1731 delete (*aIt);
1733 maContent.clear();
1735 if( mpNameTrans )
1736 DELETEZ( mpNameTrans );
1739 // -----------------------------------------------------------------------
1740 FileViewResult SvtFileView_Impl::GetFolderContent_Impl(
1741 const String& rFolder,
1742 const FileViewAsyncAction* pAsyncDescriptor,
1743 const ::com::sun::star::uno::Sequence< OUString >& rBlackList )
1745 ::osl::ClearableMutexGuard aGuard( maMutex );
1746 INetURLObject aFolderObj( rFolder );
1747 DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
1749 // prepare name translation
1750 SetActualFolder( aFolderObj );
1752 FolderDescriptor aFolder( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ) );
1754 aGuard.clear();
1755 return GetFolderContent_Impl( aFolder, pAsyncDescriptor, rBlackList );
1758 // -----------------------------------------------------------------------
1759 FileViewResult SvtFileView_Impl::GetFolderContent_Impl(
1760 const FolderDescriptor& _rFolder,
1761 const FileViewAsyncAction* pAsyncDescriptor,
1762 const ::com::sun::star::uno::Sequence< OUString >& rBlackList )
1764 DBG_TESTSOLARMUTEX();
1765 ::osl::ClearableMutexGuard aGuard( maMutex );
1767 OSL_ENSURE( !m_pContentEnumerator.is(), "SvtFileView_Impl::GetFolderContent_Impl: still running another enumeration!" );
1768 m_pContentEnumerator = new ::svt::FileViewContentEnumerator(
1769 mpView->GetCommandEnvironment(), maContent, maMutex, mbReplaceNames ? mpNameTrans : NULL );
1770 // TODO: should we cache and re-use this thread?
1772 if ( !pAsyncDescriptor )
1774 ::svt::EnumerationResult eResult = m_pContentEnumerator->enumerateFolderContentSync( _rFolder, rBlackList );
1775 if ( ::svt::SUCCESS == eResult )
1777 implEnumerationSuccess();
1778 m_pContentEnumerator.clear();
1779 return eSuccess;
1781 m_pContentEnumerator.clear();
1782 return eFailure;
1785 m_bRunningAsyncAction = true;
1786 m_bAsyncActionCancelled = false;
1787 m_eAsyncActionResult = ::svt::ERROR;
1788 m_aAsyncActionFinished.reset();
1790 // don't (yet) set m_aCurrentAsyncActionHandler to pTimeout->aFinishHandler.
1791 // By definition, this handler *only* get's called when the result cannot be obtained
1792 // during the minimum wait time, so it is only set below, when needed.
1793 m_aCurrentAsyncActionHandler = Link();
1795 // minimum time to wait
1796 ::std::auto_ptr< TimeValue > pTimeout( new TimeValue );
1797 sal_Int32 nMinTimeout = pAsyncDescriptor->nMinTimeout;
1798 OSL_ENSURE( nMinTimeout > 0, "SvtFileView_Impl::GetFolderContent_Impl: invalid minimum timeout!" );
1799 if ( nMinTimeout <= 0 )
1800 nMinTimeout = sal_Int32( 1000L );
1801 pTimeout->Seconds = nMinTimeout / 1000L;
1802 pTimeout->Nanosec = ( nMinTimeout % 1000L ) * 1000000L;
1804 m_pContentEnumerator->enumerateFolderContent( _rFolder, this );
1806 // wait until the enumeration is finished
1807 // for this, release our own mutex (which is used by the enumerator thread)
1808 aGuard.clear();
1810 ::osl::Condition::Result eResult = ::osl::Condition::result_ok;
1812 // also release the SolarMutex. Not all code which is needed during the enumeration
1813 // is Solar-Thread-Safe, in particular there is some code which needs to access
1814 // string resources (and our resource system relies on the SolarMutex :()
1815 SolarMutexReleaser aSolarRelease;
1817 // now wait. Note that if we didn't get an pAsyncDescriptor, then this is an infinite wait.
1818 eResult = m_aAsyncActionFinished.wait( pTimeout.get() );
1821 ::osl::MutexGuard aGuard2( maMutex );
1822 if ( ::osl::Condition::result_timeout == eResult )
1824 // maximum time to wait
1825 OSL_ENSURE( !m_pCancelAsyncTimer.get(), "SvtFileView_Impl::GetFolderContent_Impl: there's still a previous timer!" );
1826 m_pCancelAsyncTimer = new CallbackTimer( this );
1827 sal_Int32 nMaxTimeout = pAsyncDescriptor->nMaxTimeout;
1828 OSL_ENSURE( nMaxTimeout > nMinTimeout,
1829 "SvtFileView_Impl::GetFolderContent_Impl: invalid maximum timeout!" );
1830 if ( nMaxTimeout <= nMinTimeout )
1831 nMaxTimeout = nMinTimeout + 5000;
1832 m_pCancelAsyncTimer->setRemainingTime( salhelper::TTimeValue( nMaxTimeout - nMinTimeout ) );
1833 // we already waited for nMinTimeout milliseconds, so take this into account
1834 m_pCancelAsyncTimer->start();
1836 m_aCurrentAsyncActionHandler = pAsyncDescriptor->aFinishHandler;
1837 DBG_ASSERT( m_aCurrentAsyncActionHandler.IsSet(), "SvtFileView_Impl::GetFolderContent_Impl: nobody interested when it's finished?" );
1838 mpView->ClearAll();
1839 return eStillRunning;
1842 m_bRunningAsyncAction = false;
1843 switch ( m_eAsyncActionResult )
1845 case ::svt::SUCCESS:
1846 return eSuccess;
1848 case ::svt::ERROR:
1849 return eFailure;
1851 case ::svt::RUNNING:
1852 return eStillRunning;
1855 SAL_WARN( "svtools.contnr", "SvtFileView_Impl::GetFolderContent_Impl: unreachable!" );
1856 return eFailure;
1859 // -----------------------------------------------------------------------
1860 void SvtFileView_Impl::FilterFolderContent_Impl( const OUString &rFilter )
1862 sal_Bool bHideTransFile = mbReplaceNames && mpNameTrans;
1864 String sHideEntry;
1865 if( bHideTransFile )
1867 const String* pTransTableFileName = mpNameTrans->GetTransTableFileName();
1868 if( pTransTableFileName )
1870 sHideEntry = *pTransTableFileName;
1871 sHideEntry.ToUpperAscii();
1873 else
1874 bHideTransFile = sal_False;
1877 if ( !bHideTransFile &&
1878 ( rFilter.isEmpty() || ( rFilter.compareToAscii( ALL_FILES_FILTER ) == COMPARE_EQUAL ) ) )
1879 // when replacing names, there is always something to filter (no view of ".nametranslation.table")
1880 return;
1882 ::osl::MutexGuard aGuard( maMutex );
1884 if ( maContent.empty() )
1885 return;
1887 // count (estimate) the number of filter tokens
1888 sal_Int32 nTokens=0;
1889 const sal_Unicode* pStart = rFilter.getStr();
1890 const sal_Unicode* pEnd = pStart + rFilter.getLength();
1891 while ( pStart != pEnd )
1892 if ( *pStart++ == ';' )
1893 ++nTokens;
1895 // collect the filter tokens
1896 ::std::vector< WildCard > aFilters;
1897 FilterMatch::createWildCardFilterList(rFilter,aFilters);
1900 // do the filtering
1901 ::std::vector< SortingData_Impl* >::iterator aContentLoop = maContent.begin();
1902 String sCompareString;
1905 if ( (*aContentLoop)->mbIsFolder )
1906 ++aContentLoop;
1907 else
1909 // normalize the content title (we always match case-insensitive)
1910 // 91872 - 11.09.2001 - frank.schoenheit@sun.com
1911 sCompareString = (*aContentLoop)->GetFileName(); // filter works on file name, not on title!
1912 sal_Bool bDelete;
1914 if( bHideTransFile && sCompareString == sHideEntry )
1915 bDelete = sal_True;
1916 else
1918 // search for the first filter which matches
1919 ::std::vector< WildCard >::const_iterator pMatchingFilter =
1920 ::std::find_if(
1921 aFilters.begin(),
1922 aFilters.end(),
1923 FilterMatch( sCompareString )
1926 bDelete = aFilters.end() == pMatchingFilter;
1929 if( bDelete )
1931 // none of the filters did match
1932 delete (*aContentLoop);
1934 if ( maContent.begin() == aContentLoop )
1936 maContent.erase( aContentLoop );
1937 aContentLoop = maContent.begin();
1939 else
1941 std::vector< SortingData_Impl* >::iterator aDelete = aContentLoop;
1942 --aContentLoop; // move the iterator to a position which is not invalidated by the erase
1943 maContent.erase( aDelete );
1944 ++aContentLoop; // this is now the next one ....
1947 else
1948 ++aContentLoop;
1951 while ( aContentLoop != maContent.end() );
1954 // -----------------------------------------------------------------------
1955 IMPL_LINK( SvtFileView_Impl, SelectionMultiplexer, void*, _pSource )
1957 return mnSuspendSelectCallback ? 0L : m_aSelectHandler.Call( _pSource );
1960 // -----------------------------------------------------------------------
1961 void SvtFileView_Impl::SetSelectHandler( const Link& _rHdl )
1963 m_aSelectHandler = _rHdl;
1965 Link aMasterHandler;
1966 if ( m_aSelectHandler.IsSet() )
1967 aMasterHandler = LINK( this, SvtFileView_Impl, SelectionMultiplexer );
1969 mpView->SetSelectHdl( aMasterHandler );
1972 // -----------------------------------------------------------------------
1973 void SvtFileView_Impl::InitSelection()
1975 mpView->SelectAll( sal_False );
1976 SvTreeListEntry* pFirst = mpView->First();
1977 if ( pFirst )
1978 mpView->SetCursor( pFirst, sal_True );
1981 // -----------------------------------------------------------------------
1982 void SvtFileView_Impl::OpenFolder_Impl()
1984 ::osl::MutexGuard aGuard( maMutex );
1986 mpView->SetUpdateMode( sal_False );
1987 mpView->ClearAll();
1989 std::vector< SortingData_Impl* >::iterator aIt;
1991 for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
1993 if ( mbOnlyFolder && ! (*aIt)->mbIsFolder )
1994 continue;
1996 // insert entry and set user data
1997 SvTreeListEntry* pEntry = mpView->InsertEntry( (*aIt)->maDisplayText,
1998 (*aIt)->maImage,
1999 (*aIt)->maImage );
2001 SvtContentEntry* pUserData = new SvtContentEntry( (*aIt)->maTargetURL,
2002 (*aIt)->mbIsFolder );
2003 pEntry->SetUserData( pUserData );
2006 InitSelection();
2008 ++mnSuspendSelectCallback;
2009 mpView->SetUpdateMode( sal_True );
2010 --mnSuspendSelectCallback;
2012 ResetCursor();
2015 // -----------------------------------------------------------------------
2016 void SvtFileView_Impl::ResetCursor()
2018 // deselect
2019 SvTreeListEntry* pEntry = mpView->FirstSelected();
2020 if ( pEntry )
2021 mpView->Select( pEntry, sal_False );
2022 // set cursor to the first entry
2023 mpView->SetCursor( mpView->First(), sal_True );
2024 mpView->Update();
2027 // -----------------------------------------------------------------------
2028 void SvtFileView_Impl::CancelRunningAsyncAction()
2030 DBG_TESTSOLARMUTEX();
2031 ::osl::MutexGuard aGuard( maMutex );
2032 if ( !m_pContentEnumerator.is() )
2033 return;
2035 m_bAsyncActionCancelled = true;
2036 m_pContentEnumerator->cancel();
2037 m_bRunningAsyncAction = false;
2039 m_pContentEnumerator.clear();
2040 if ( m_pCancelAsyncTimer.is() && m_pCancelAsyncTimer->isTicking() )
2041 m_pCancelAsyncTimer->stop();
2042 m_pCancelAsyncTimer = NULL;
2045 //-----------------------------------------------------------------------
2046 void SvtFileView_Impl::onTimeout( CallbackTimer* )
2048 SolarMutexGuard aSolarGuard;
2049 ::osl::MutexGuard aGuard( maMutex );
2050 if ( !m_bRunningAsyncAction )
2051 // there might have been a race condition while we waited for the mutex
2052 return;
2054 CancelRunningAsyncAction();
2056 if ( m_aCurrentAsyncActionHandler.IsSet() )
2058 Application::PostUserEvent( m_aCurrentAsyncActionHandler, reinterpret_cast< void* >( eTimeout ) );
2059 m_aCurrentAsyncActionHandler = Link();
2063 //-----------------------------------------------------------------------
2064 void SvtFileView_Impl::enumerationDone( ::svt::EnumerationResult _eResult )
2066 SolarMutexGuard aSolarGuard;
2067 ::osl::MutexGuard aGuard( maMutex );
2069 m_pContentEnumerator.clear();
2070 if ( m_pCancelAsyncTimer.is() && m_pCancelAsyncTimer->isTicking() )
2071 m_pCancelAsyncTimer->stop();
2072 m_pCancelAsyncTimer = NULL;
2074 if ( m_bAsyncActionCancelled )
2075 // this is to prevent race conditions
2076 return;
2078 m_eAsyncActionResult = _eResult;
2079 m_bRunningAsyncAction = false;
2081 m_aAsyncActionFinished.set();
2083 if ( svt::SUCCESS == _eResult )
2084 implEnumerationSuccess();
2086 if ( m_aCurrentAsyncActionHandler.IsSet() )
2088 Application::PostUserEvent( m_aCurrentAsyncActionHandler, reinterpret_cast< void* >( m_eAsyncActionResult ) );
2089 m_aCurrentAsyncActionHandler = Link();
2093 //-----------------------------------------------------------------------
2094 void SvtFileView_Impl::implEnumerationSuccess()
2096 FilterFolderContent_Impl( maCurrentFilter );
2097 SortFolderContent_Impl();
2098 CreateDisplayText_Impl();
2099 OpenFolder_Impl();
2100 maOpenDoneLink.Call( mpAntiImpl );
2103 // -----------------------------------------------------------------------
2104 void SvtFileView_Impl::ReplaceTabWithString( OUString& aValue )
2106 OUString aTab( "\t" );
2107 OUString aTabString( "%09" );
2108 sal_Int32 iPos;
2110 while ( ( iPos = aValue.indexOf( aTab ) ) >= 0 )
2111 aValue = aValue.replaceAt( iPos, 1, aTabString );
2114 // -----------------------------------------------------------------------
2115 void SvtFileView_Impl::CreateDisplayText_Impl()
2117 ::osl::MutexGuard aGuard( maMutex );
2119 OUString aValue;
2120 OUString aTab( "\t" );
2121 OUString aDateSep( ", " );
2123 std::vector< SortingData_Impl* >::iterator aIt;
2125 for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
2127 // title, type, size, date
2128 aValue = (*aIt)->GetTitle();
2129 // #83004# --------------------
2130 ReplaceTabWithString( aValue );
2131 aValue += aTab;
2132 aValue += (*aIt)->maType;
2133 aValue += aTab;
2134 // folders don't have a size
2135 if ( ! (*aIt)->mbIsFolder )
2136 aValue += CreateExactSizeText( (*aIt)->maSize );
2137 aValue += aTab;
2138 // set the date, but volumes have no date
2139 if ( ! (*aIt)->mbIsFolder || ! (*aIt)->mbIsVolume )
2141 SvtSysLocale aSysLocale;
2142 const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
2143 aValue += rLocaleData.getDate( (*aIt)->maModDate );
2144 aValue += aDateSep;
2145 aValue += rLocaleData.getTime( (*aIt)->maModDate );
2147 (*aIt)->maDisplayText = aValue;
2149 // detect image
2150 if ( (*aIt)->mbIsFolder )
2152 ::svtools::VolumeInfo aVolInfo( (*aIt)->mbIsVolume, (*aIt)->mbIsRemote,
2153 (*aIt)->mbIsRemoveable, (*aIt)->mbIsFloppy,
2154 (*aIt)->mbIsCompactDisc );
2155 (*aIt)->maImage = SvFileInformationManager::GetFolderImage( aVolInfo, sal_False );
2157 else
2158 (*aIt)->maImage = SvFileInformationManager::GetFileImage( INetURLObject( (*aIt)->maTargetURL ), sal_False );
2162 // -----------------------------------------------------------------------
2163 // this function converts the sequence of strings into a vector of SortingData
2164 // the string should have the form :
2165 // title \t type \t size \t date \t target url \t is folder \t image url
2167 void SvtFileView_Impl::CreateVector_Impl( const Sequence < OUString > &rList )
2169 ::osl::MutexGuard aGuard( maMutex );
2171 OUString aTab( "\t" );
2173 sal_uInt32 nCount = (sal_uInt32) rList.getLength();
2175 for( sal_uInt32 i = 0; i < nCount; i++ )
2177 SortingData_Impl* pEntry = new SortingData_Impl;
2178 OUString aValue = rList[i];
2179 OUString aDisplayText;
2180 sal_Int32 nIndex = 0;
2182 // get the title
2183 pEntry->SetNewTitle( aValue.getToken( 0, '\t', nIndex ) );
2184 aDisplayText = pEntry->GetTitle();
2185 ReplaceTabWithString( aDisplayText );
2186 aDisplayText += aTab;
2188 // get the type
2189 if ( nIndex >= 0 )
2191 pEntry->maType = aValue.getToken( 0, '\t', nIndex );
2192 aDisplayText += pEntry->maType;
2194 aDisplayText += aTab;
2196 // get the size
2197 if ( nIndex >= 0 )
2199 OUString aSize = aValue.getToken( 0, '\t', nIndex );
2200 aDisplayText += aSize;
2202 if ( !aSize.isEmpty() )
2203 pEntry->maSize = aSize.toInt64();
2205 aDisplayText += aTab;
2207 // get the date
2208 if ( nIndex >= 0 )
2210 OUString aDate = aValue.getToken( 0, '\t', nIndex );
2211 aDisplayText += aDate;
2213 if ( !aDate.isEmpty() )
2215 SAL_WARN( "svtools.contnr", "Don't know, how to convert date" );
2216 ;// convert date string to date
2219 // get the target url
2220 if ( nIndex >= 0 )
2222 pEntry->maTargetURL = aValue.getToken( 0, '\t', nIndex );
2224 // get the size
2225 if ( nIndex >= 0 )
2227 OUString aBool = aValue.getToken( 0, '\t', nIndex );
2228 if ( !aBool.isEmpty() )
2229 pEntry->mbIsFolder = aBool.toBoolean();
2231 // get the image url
2232 if ( nIndex >= 0 )
2234 pEntry->maImageURL = aValue.getToken( 0, '\t', nIndex );
2237 // set the display text
2238 pEntry->maDisplayText = aDisplayText;
2240 // detect the image
2241 if( aValue != SEPARATOR_STR )
2243 INetURLObject aObj( !pEntry->maImageURL.isEmpty() ? pEntry->maImageURL : pEntry->maTargetURL );
2244 pEntry->maImage = SvFileInformationManager::GetImage( aObj, sal_False );
2246 maContent.push_back( pEntry );
2250 // -----------------------------------------------------------------------
2251 void SvtFileView_Impl::Resort_Impl( sal_Int16 nColumn, sal_Bool bAscending )
2253 ::osl::MutexGuard aGuard( maMutex );
2255 if ( ( nColumn == mnSortColumn ) &&
2256 ( bAscending == mbAscending ) )
2257 return;
2259 // reset the quick search index
2260 mpView->ResetQuickSearch_Impl( NULL );
2262 String aEntryURL;
2263 SvTreeListEntry* pEntry = mpView->GetCurEntry();
2264 if ( pEntry && pEntry->GetUserData() )
2265 aEntryURL = ( (SvtContentEntry*)pEntry->GetUserData() )->maURL;
2267 mnSortColumn = nColumn;
2268 mbAscending = bAscending;
2270 SortFolderContent_Impl();
2271 OpenFolder_Impl();
2273 if ( !mbIsFirstResort )
2275 sal_uLong nPos = GetEntryPos( aEntryURL );
2276 if ( nPos < mpView->GetEntryCount() )
2278 pEntry = mpView->GetEntry( nPos );
2280 ++mnSuspendSelectCallback; // #i15668#
2281 mpView->SetCurEntry( pEntry );
2282 --mnSuspendSelectCallback;
2285 else
2286 mbIsFirstResort = sal_False;
2289 // -----------------------------------------------------------------------
2290 static sal_Bool gbAscending = sal_True;
2291 static sal_Int16 gnColumn = COLUMN_TITLE;
2292 static const CollatorWrapper* pCollatorWrapper = NULL;
2294 /* this functions returns true, if aOne is less then aTwo
2296 sal_Bool CompareSortingData_Impl( SortingData_Impl* const aOne, SortingData_Impl* const aTwo )
2298 DBG_ASSERT( pCollatorWrapper, "*CompareSortingData_Impl(): Can't work this way!" );
2300 sal_Int32 nComp;
2301 sal_Bool bRet = sal_False;
2302 sal_Bool bEqual = sal_False;
2304 if ( aOne->mbIsFolder != aTwo->mbIsFolder )
2306 if ( aOne->mbIsFolder )
2307 bRet = sal_True;
2308 else
2309 bRet = sal_False;
2311 // !!! pb: #100376# folder always on top
2312 if ( !gbAscending )
2313 bRet = !bRet;
2315 else
2317 switch ( gnColumn )
2319 case COLUMN_TITLE:
2320 // compare case insensitive first
2321 nComp = pCollatorWrapper->compareString( aOne->GetLowerTitle(), aTwo->GetLowerTitle() );
2323 if ( nComp == 0 )
2324 nComp = pCollatorWrapper->compareString( aOne->GetTitle(), aTwo->GetTitle() );
2326 if ( nComp < 0 )
2327 bRet = sal_True;
2328 else if ( nComp > 0 )
2329 bRet = sal_False;
2330 else
2331 bEqual = sal_True;
2332 break;
2333 case COLUMN_TYPE:
2334 nComp = pCollatorWrapper->compareString( aOne->maType, aTwo->maType );
2335 if ( nComp < 0 )
2336 bRet = sal_True;
2337 else if ( nComp > 0 )
2338 bRet = sal_False;
2339 else
2340 bEqual = sal_True;
2341 break;
2342 case COLUMN_SIZE:
2343 if ( aOne->maSize < aTwo->maSize )
2344 bRet = sal_True;
2345 else if ( aOne->maSize > aTwo->maSize )
2346 bRet = sal_False;
2347 else
2348 bEqual = sal_True;
2349 break;
2350 case COLUMN_DATE:
2351 if ( aOne->maModDate < aTwo->maModDate )
2352 bRet = sal_True;
2353 else if ( aOne->maModDate > aTwo->maModDate )
2354 bRet = sal_False;
2355 else
2356 bEqual = sal_True;
2357 break;
2358 default:
2359 DBG_WARNING( "CompareSortingData_Impl: Compare unknown type!" );
2360 bRet = sal_False;
2364 // when the two elements are equal, we must not return sal_True (which would
2365 // happen if we just return ! ( a < b ) when not sorting ascending )
2366 if ( bEqual )
2367 return sal_False;
2369 return gbAscending ? bRet : !bRet;
2372 // -----------------------------------------------------------------------
2373 void SvtFileView_Impl::SortFolderContent_Impl()
2375 ::osl::MutexGuard aGuard( maMutex );
2377 sal_uInt32 nSize = maContent.size();
2379 if ( nSize > 1 )
2381 gbAscending = mbAscending;
2382 gnColumn = mnSortColumn;
2383 pCollatorWrapper = aIntlWrapper.getCaseCollator();
2385 std::stable_sort( maContent.begin(), maContent.end(), CompareSortingData_Impl );
2387 pCollatorWrapper = NULL;
2391 // -----------------------------------------------------------------------
2392 void SvtFileView_Impl::EntryRemoved( const OUString& rURL )
2394 ::osl::MutexGuard aGuard( maMutex );
2396 std::vector< SortingData_Impl* >::iterator aIt;
2398 for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
2400 if ( (*aIt)->maTargetURL == rURL )
2402 maContent.erase( aIt );
2403 break;
2408 // -----------------------------------------------------------------------
2409 void SvtFileView_Impl::EntryRenamed( OUString& rURL,
2410 const OUString& rTitle )
2412 ::osl::MutexGuard aGuard( maMutex );
2414 std::vector< SortingData_Impl* >::iterator aIt;
2416 for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
2418 if ( (*aIt)->maTargetURL == rURL )
2420 (*aIt)->SetNewTitle( rTitle );
2421 OUString aDisplayText = (*aIt)->maDisplayText;
2422 sal_Int32 nIndex = aDisplayText.indexOf( '\t' );
2424 if ( nIndex > 0 )
2425 (*aIt)->maDisplayText = aDisplayText.replaceAt( 0, nIndex, rTitle );
2427 INetURLObject aURLObj( rURL );
2428 aURLObj.SetName( rTitle, INetURLObject::ENCODE_ALL );
2430 rURL = aURLObj.GetMainURL( INetURLObject::NO_DECODE );
2432 (*aIt)->maTargetURL = rURL;
2433 break;
2438 // -----------------------------------------------------------------------
2439 String SvtFileView_Impl::FolderInserted( const OUString& rURL, const OUString& rTitle )
2441 ::osl::MutexGuard aGuard( maMutex );
2443 SortingData_Impl* pData = new SortingData_Impl;
2445 pData->SetNewTitle( rTitle );
2446 pData->maSize = 0;
2447 pData->mbIsFolder = sal_True;
2448 pData->maTargetURL = rURL;
2450 INetURLObject aURLObj( rURL );
2452 ::svtools::VolumeInfo aVolInfo;
2453 pData->maType = SvFileInformationManager::GetFolderDescription( aVolInfo );
2454 pData->maImage = SvFileInformationManager::GetFolderImage( aVolInfo, sal_False );
2456 OUString aValue;
2457 OUString aTab( "\t" );
2458 OUString aDateSep( ", " );
2460 // title, type, size, date
2461 aValue = pData->GetTitle();
2462 ReplaceTabWithString( aValue );
2463 aValue += aTab;
2464 aValue += pData->maType;
2465 aValue += aTab;
2466 // folders don't have a size
2467 aValue += aTab;
2468 // set the date
2469 SvtSysLocale aSysLocale;
2470 const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
2471 aValue += rLocaleData.getDate( pData->maModDate );
2472 aValue += aDateSep;
2473 aValue += rLocaleData.getTime( pData->maModDate );
2475 pData->maDisplayText = aValue;
2476 maContent.push_back( pData );
2478 return String( aValue );
2481 // -----------------------------------------------------------------------
2482 sal_uLong SvtFileView_Impl::GetEntryPos( const OUString& rURL )
2484 ::osl::MutexGuard aGuard( maMutex );
2486 std::vector< SortingData_Impl* >::iterator aIt;
2487 sal_uLong nPos = 0;
2489 for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
2491 if ( (*aIt)->maTargetURL == rURL )
2492 return nPos;
2493 nPos += 1;
2496 return nPos;
2499 // -----------------------------------------------------------------------
2500 sal_Bool SvtFileView_Impl::SearchNextEntry( sal_uInt32& nIndex, const OUString& rTitle, sal_Bool bWrapAround )
2502 ::osl::MutexGuard aGuard( maMutex );
2504 sal_uInt32 nEnd = maContent.size();
2505 sal_uInt32 nStart = nIndex;
2506 while ( nIndex < nEnd )
2508 SortingData_Impl* pData = maContent[ nIndex ];
2509 if ( rTitle.compareTo( pData->GetLowerTitle(), rTitle.getLength() ) == 0 )
2510 return sal_True;
2511 nIndex += 1;
2514 if ( bWrapAround )
2516 nIndex = 0;
2517 while ( nIndex < nEnd && nIndex <= nStart )
2519 SortingData_Impl* pData = maContent[ nIndex ];
2520 if ( rTitle.compareTo( pData->GetLowerTitle(), rTitle.getLength() ) == 0 )
2521 return sal_True;
2522 nIndex += 1;
2526 return sal_False;
2529 // -----------------------------------------------------------------------
2530 void SvtFileView_Impl::SetActualFolder( const INetURLObject& rActualFolder )
2532 if( mbReplaceNames )
2534 if( mpNameTrans )
2535 mpNameTrans->SetActualFolder( rActualFolder );
2536 else
2537 mpNameTrans = new NameTranslator_Impl( rActualFolder );
2541 namespace svtools {
2543 // -----------------------------------------------------------------------
2544 // QueryDeleteDlg_Impl
2545 // -----------------------------------------------------------------------
2547 QueryDeleteDlg_Impl::QueryDeleteDlg_Impl
2549 Window* pParent,
2550 const String& rName // entry name
2553 ModalDialog( pParent, SvtResId( DLG_SVT_QUERYDELETE ) ),
2555 _aEntryLabel ( this, SvtResId( TXT_ENTRY ) ),
2556 _aEntry ( this, SvtResId( TXT_ENTRYNAME ) ),
2557 _aQueryMsg ( this, SvtResId( TXT_QUERYMSG ) ),
2558 _aYesButton ( this, SvtResId( BTN_YES ) ),
2559 _aAllButton ( this, SvtResId( BTN_ALL ) ),
2560 _aNoButton ( this, SvtResId( BTN_NO ) ),
2561 _aCancelButton( this, SvtResId( BTN_CANCEL ) )
2564 FreeResource();
2566 // Handler
2567 Link aLink( STATIC_LINK( this, QueryDeleteDlg_Impl, ClickLink ) );
2568 _aYesButton.SetClickHdl( aLink );
2569 _aAllButton.SetClickHdl( aLink );
2570 _aNoButton.SetClickHdl( aLink );
2572 // display specified texts
2574 WinBits nTmpStyle = _aEntry.GetStyle();
2575 nTmpStyle |= WB_PATHELLIPSIS;
2576 _aEntry.SetStyle( nTmpStyle );
2577 _aEntry.SetText( rName );
2580 // -----------------------------------------------------------------------
2582 IMPL_STATIC_LINK( QueryDeleteDlg_Impl, ClickLink, PushButton*, pBtn )
2584 if ( pBtn == &pThis->_aYesButton )
2585 pThis->_eResult = QUERYDELETE_YES;
2586 else if ( pBtn == &pThis->_aNoButton )
2587 pThis->_eResult = QUERYDELETE_NO;
2588 else if ( pBtn == &pThis->_aAllButton )
2589 pThis->_eResult = QUERYDELETE_ALL;
2590 else if ( pBtn == &pThis->_aCancelButton )
2591 pThis->_eResult = QUERYDELETE_CANCEL;
2593 pThis->EndDialog( RET_OK );
2595 return 0;
2600 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */