update dev300-m58
[ooovba.git] / sot / source / base / filelist.cxx
blob0b42218b222230c037c0f1743f8ab49b87bae352
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filelist.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sot.hxx"
34 #include<tools/list.hxx>
35 #include<tools/stream.hxx>
36 #include<tools/string.hxx>
37 #include<tools/rtti.hxx>
38 #include<sot/exchange.hxx>
39 #include<filelist.hxx>
40 #include <osl/thread.h>
42 TYPEINIT1_AUTOFACTORY( FileList, SvDataCopyStream );
44 // String-Liste zum Speichern der Namen deklarieren
45 DECLARE_LIST( FileStringList, String* )
48 /*************************************************************************
50 |* FileList - Ctor/Dtor
52 \*************************************************************************/
54 FileList::FileList()
56 pStrList = new FileStringList();
59 FileList::~FileList()
61 ClearAll();
64 void FileList::ClearAll( void )
66 // Strings in der Liste loeschen
67 ULONG nCount = pStrList->Count();
68 for( ULONG i = 0 ; i < nCount ; i++ )
69 delete pStrList->GetObject( i );
71 // Liste loeschen
72 delete pStrList;
75 /*************************************************************************
77 |* FileList - Zuweisungsoperator
79 \*************************************************************************/
81 FileList& FileList::operator=( const FileList& rFileList )
83 // Liste duplizieren
84 *pStrList = *rFileList.pStrList;
86 // Strings in der Liste kopieren
87 ULONG nCount = pStrList->Count();
88 for( ULONG i = 0 ; i < nCount ; i++ )
89 pStrList->Replace( new String( *rFileList.pStrList->GetObject( i ) ), i );
91 return *this;
94 /*************************************************************************
96 |* FileList::GetFormatName()
98 \*************************************************************************/
100 ULONG FileList::GetFormat()
102 return FORMAT_FILE_LIST;
105 /******************************************************************************
107 |* virtuelle SvData-Methoden
109 \******************************************************************************/
111 void FileList::Load( SvStream& rIStm )
113 rIStm >> *this;
116 void FileList::Save( SvStream& rOStm )
118 rOStm << *this;
121 void FileList::Assign( const SvDataCopyStream& rCopyStream )
123 *this = (const FileList&)rCopyStream;
126 /******************************************************************************
128 |* Stream-Operatoren
130 \******************************************************************************/
133 * NOTE: to correctly handle this Protocol with Unicode, native Win32 must be called:
134 * e.g. DropQueryFile
137 SvStream& operator<<( SvStream& rOStm, const FileList& /*rFileList*/ )
139 OSL_ENSURE(false, "Not implemented!");
140 return rOStm;
143 /* #i28176#
144 The Windows clipboard bridge now provides a double '\0'
145 terminated list of file names for format SOT_FORMAT_FILE_LIST
146 instead of the original Windows Sv_DROPFILES structure. All strings
147 in this list are UTF16 strings. Shell link files will be already
148 resolved by the Windows clipboard bridge.*/
149 SvStream& operator>>( SvStream& rIStm, FileList& rFileList )
151 rFileList.ClearAll();
152 rFileList.pStrList = new FileStringList();
154 String aStr;
155 sal_uInt16 c;
157 while (!rIStm.IsEof())
159 aStr.Erase();
161 // read first character of filepath; c==0 > reach end of stream
162 rIStm >> c;
163 if (!c)
164 break;
166 // read string till c==0
167 while (c && !rIStm.IsEof())
169 aStr += (sal_Unicode)c;
170 rIStm >> c;
173 // append the filepath
174 rFileList.AppendFile(aStr);
176 return rIStm;
179 /******************************************************************************
181 |* Liste fuellen/abfragen
183 \******************************************************************************/
185 void FileList::AppendFile( const String& rStr )
187 pStrList->Insert( new String( rStr ) , pStrList->Count() );
190 String FileList::GetFile( ULONG i ) const
192 String aStr;
193 if( i < pStrList->Count() )
194 aStr = *pStrList->GetObject( i );
195 return aStr;
198 ULONG FileList::Count( void ) const
200 return pStrList->Count();