1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sot.hxx"
26
27 #include<tools/list.hxx>
28 #include<tools/stream.hxx>
29 #include<tools/string.hxx>
30 #include<tools/rtti.hxx>
31 #include<sot/exchange.hxx>
32 #include<sot/filelist.hxx>
33 #include <osl/thread.h>
34
35 TYPEINIT1_AUTOFACTORY( FileList, SvDataCopyStream );
36
37 // String-Liste zum Speichern der Namen deklarieren
DECLARE_LIST(FileStringList,String *)38 DECLARE_LIST( FileStringList, String* )
39
40
41 /*************************************************************************
42 |*
43 |* FileList - Ctor/Dtor
44 |*
45 \*************************************************************************/
46
47 FileList::FileList()
48 {
49 pStrList = new FileStringList();
50 }
51
~FileList()52 FileList::~FileList()
53 {
54 ClearAll();
55 }
56
ClearAll(void)57 void FileList::ClearAll( void )
58 {
59 // Strings in der Liste loeschen
60 sal_uLong nCount = pStrList->Count();
61 for( sal_uLong i = 0 ; i < nCount ; i++ )
62 delete pStrList->GetObject( i );
63
64 // Liste loeschen
65 delete pStrList;
66 }
67
68 /*************************************************************************
69 |*
70 |* FileList - Zuweisungsoperator
71 |*
72 \*************************************************************************/
73
operator =(const FileList & rFileList)74 FileList& FileList::operator=( const FileList& rFileList )
75 {
76 // Liste duplizieren
77 *pStrList = *rFileList.pStrList;
78
79 // Strings in der Liste kopieren
80 sal_uLong nCount = pStrList->Count();
81 for( sal_uLong i = 0 ; i < nCount ; i++ )
82 pStrList->Replace( new String( *rFileList.pStrList->GetObject( i ) ), i );
83
84 return *this;
85 }
86
87 /*************************************************************************
88 |*
89 |* FileList::GetFormatName()
90 |*
91 \*************************************************************************/
92
GetFormat()93 sal_uLong FileList::GetFormat()
94 {
95 return FORMAT_FILE_LIST;
96 }
97
98 /******************************************************************************
99 |*
100 |* virtuelle SvData-Methoden
101 |*
102 \******************************************************************************/
103
Load(SvStream & rIStm)104 void FileList::Load( SvStream& rIStm )
105 {
106 rIStm >> *this;
107 }
108
Save(SvStream & rOStm)109 void FileList::Save( SvStream& rOStm )
110 {
111 rOStm << *this;
112 }
113
Assign(const SvDataCopyStream & rCopyStream)114 void FileList::Assign( const SvDataCopyStream& rCopyStream )
115 {
116 *this = (const FileList&)rCopyStream;
117 }
118
119 /******************************************************************************
120 |*
121 |* Stream-Operatoren
122 |*
123 \******************************************************************************/
124
125 /*
126 * NOTE: to correctly handle this Protocol with Unicode, native Win32 must be called:
127 * e.g. DropQueryFile
128 */
129
operator <<(SvStream & rOStm,const FileList &)130 SvStream& operator<<( SvStream& rOStm, const FileList& /*rFileList*/ )
131 {
132 OSL_ENSURE(false, "Not implemented!");
133 return rOStm;
134 }
135
136 /* #i28176#
137 The Windows clipboard bridge now provides a double '\0'
138 terminated list of file names for format SOT_FORMAT_FILE_LIST
139 instead of the original Windows Sv_DROPFILES structure. All strings
140 in this list are UTF16 strings. Shell link files will be already
141 resolved by the Windows clipboard bridge.*/
operator >>(SvStream & rIStm,FileList & rFileList)142 SvStream& operator>>( SvStream& rIStm, FileList& rFileList )
143 {
144 rFileList.ClearAll();
145 rFileList.pStrList = new FileStringList();
146
147 String aStr;
148 sal_uInt16 c;
149
150 while (!rIStm.IsEof())
151 {
152 aStr.Erase();
153
154 // read first character of filepath; c==0 > reach end of stream
155 rIStm >> c;
156 if (!c)
157 break;
158
159 // read string till c==0
160 while (c && !rIStm.IsEof())
161 {
162 aStr += (sal_Unicode)c;
163 rIStm >> c;
164 }
165
166 // append the filepath
167 rFileList.AppendFile(aStr);
168 }
169 return rIStm;
170 }
171
172 /******************************************************************************
173 |*
174 |* Liste fuellen/abfragen
175 |*
176 \******************************************************************************/
177
AppendFile(const String & rStr)178 void FileList::AppendFile( const String& rStr )
179 {
180 pStrList->Insert( new String( rStr ) , pStrList->Count() );
181 }
182
GetFile(sal_uLong i) const183 String FileList::GetFile( sal_uLong i ) const
184 {
185 String aStr;
186 if( i < pStrList->Count() )
187 aStr = *pStrList->GetObject( i );
188 return aStr;
189 }
190
Count(void) const191 sal_uLong FileList::Count( void ) const
192 {
193 return pStrList->Count();
194 }
195
196