xref: /trunk/main/sot/source/base/filelist.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sot.hxx"
30 
31 #include<tools/list.hxx>
32 #include<tools/stream.hxx>
33 #include<tools/string.hxx>
34 #include<tools/rtti.hxx>
35 #include<sot/exchange.hxx>
36 #include<sot/filelist.hxx>
37 #include <osl/thread.h>
38 
39 TYPEINIT1_AUTOFACTORY( FileList, SvDataCopyStream );
40 
41 // String-Liste zum Speichern der Namen deklarieren
42 DECLARE_LIST( FileStringList, String* )
43 
44 
45 /*************************************************************************
46 |*
47 |*    FileList - Ctor/Dtor
48 |*
49 \*************************************************************************/
50 
51 FileList::FileList()
52 {
53 	pStrList = new FileStringList();
54 }
55 
56 FileList::~FileList()
57 {
58 	ClearAll();
59 }
60 
61 void FileList::ClearAll( void )
62 {
63 	// Strings in der Liste loeschen
64 	sal_uLong nCount = pStrList->Count();
65 	for( sal_uLong i = 0 ; i < nCount ; i++ )
66 		delete pStrList->GetObject( i );
67 
68 	// Liste loeschen
69 	delete pStrList;
70 }
71 
72 /*************************************************************************
73 |*
74 |*    FileList - Zuweisungsoperator
75 |*
76 \*************************************************************************/
77 
78 FileList& FileList::operator=( const FileList& rFileList )
79 {
80 	// Liste duplizieren
81 	*pStrList = *rFileList.pStrList;
82 
83 	// Strings in der Liste kopieren
84 	sal_uLong nCount = pStrList->Count();
85 	for( sal_uLong i = 0 ; i < nCount ; i++ )
86 		pStrList->Replace( new String( *rFileList.pStrList->GetObject( i ) ), i );
87 
88 	return *this;
89 }
90 
91 /*************************************************************************
92 |*
93 |*    FileList::GetFormatName()
94 |*
95 \*************************************************************************/
96 
97 sal_uLong FileList::GetFormat()
98 {
99 	return FORMAT_FILE_LIST;
100 }
101 
102 /******************************************************************************
103 |*
104 |*	virtuelle SvData-Methoden
105 |*
106 \******************************************************************************/
107 
108 void FileList::Load( SvStream& rIStm )
109 {
110     rIStm >> *this;
111 }
112 
113 void FileList::Save( SvStream& rOStm )
114 {
115     rOStm << *this;
116 }
117 
118 void FileList::Assign( const SvDataCopyStream& rCopyStream )
119 {
120     *this = (const FileList&)rCopyStream;
121 }
122 
123 /******************************************************************************
124 |*
125 |*	Stream-Operatoren
126 |*
127 \******************************************************************************/
128 
129 /*
130  * NOTE: to correctly handle this Protocol with Unicode, native Win32 must be called:
131  * e.g. DropQueryFile
132  */
133 
134 SvStream& operator<<( SvStream& rOStm, const FileList& /*rFileList*/ )
135 {
136     OSL_ENSURE(false, "Not implemented!");
137 	return rOStm;
138 }
139 
140 /* #i28176#
141    The Windows clipboard bridge now provides a double '\0'
142    terminated list of file names for format SOT_FORMAT_FILE_LIST
143    instead of the original Windows Sv_DROPFILES structure. All strings
144    in this list are UTF16 strings. Shell link files will be already
145    resolved by the Windows clipboard bridge.*/
146 SvStream& operator>>( SvStream& rIStm, FileList& rFileList )
147 {
148     rFileList.ClearAll();
149 	rFileList.pStrList = new FileStringList();
150 
151 	String aStr;
152 	sal_uInt16 c;
153 
154     while (!rIStm.IsEof())
155 	{
156 		aStr.Erase();
157 
158 		// read first character of filepath; c==0 > reach end of stream
159 		rIStm >> c;
160 		if (!c)
161 			break;
162 
163 		// read string till c==0
164 		while (c && !rIStm.IsEof())
165 		{
166 			aStr += (sal_Unicode)c;
167 			rIStm >> c;
168 		}
169 
170 		// append the filepath
171 		rFileList.AppendFile(aStr);
172 	}
173 	return rIStm;
174 }
175 
176 /******************************************************************************
177 |*
178 |*	Liste fuellen/abfragen
179 |*
180 \******************************************************************************/
181 
182 void FileList::AppendFile( const String& rStr )
183 {
184 	pStrList->Insert( new String( rStr ) , pStrList->Count() );
185 }
186 
187 String FileList::GetFile( sal_uLong i ) const
188 {
189 	String aStr;
190 	if( i < pStrList->Count() )
191 		aStr = *pStrList->GetObject( i );
192 	return aStr;
193 }
194 
195 sal_uLong FileList::Count( void ) const
196 {
197 	return pStrList->Count();
198 }
199 
200