update dev300-m58
[ooovba.git] / automation / source / server / cmdbasestream.cxx
blobe6899ad2da1a651c4c5c6aedcc036a29cf2f2eb5
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: cmdbasestream.cxx,v $
10 * $Revision: 1.7 $
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_automation.hxx"
34 /*************************************************************************
36 * ATTENTION
37 * This file is intended to work inside and outside the StarOffice environment.
38 * Only adaption of file commtypes.hxx should be necessary. Else it is a bug!
40 ************************************************************************/
41 #include <osl/endian.h>
43 #include "cmdbasestream.hxx"
44 #include "rcontrol.hxx"
46 CmdBaseStream::CmdBaseStream()
47 : pCommStream( NULL )
51 CmdBaseStream::~CmdBaseStream()
55 void CmdBaseStream::GenError (SmartId *pUId, comm_String *pString )
57 Write(comm_USHORT(SIReturnError));
58 Write(pUId);
59 Write(pString);
62 void CmdBaseStream::GenReturn (comm_USHORT nRet, comm_ULONG nUId )
64 Write(comm_USHORT(SIReturn));
65 Write(nRet);
66 Write(nUId);
67 Write(comm_USHORT(PARAM_NONE)); // Typ der folgenden Parameter
70 void CmdBaseStream::GenReturn (comm_USHORT nRet, SmartId *pUId, comm_ULONG nNr )
72 Write(comm_USHORT(SIReturn));
73 Write(nRet);
74 Write(pUId);
75 Write(comm_USHORT(PARAM_ULONG_1)); // Typ der folgenden Parameter
76 Write(nNr);
79 void CmdBaseStream::GenReturn (comm_USHORT nRet, SmartId *pUId, comm_String *pString )
81 Write(comm_USHORT(SIReturn));
82 Write(nRet);
83 Write(pUId);
84 Write(comm_USHORT(PARAM_STR_1)); // Typ der folgenden Parameter
85 Write(pString);
88 void CmdBaseStream::GenReturn (comm_USHORT nRet, SmartId *pUId, comm_BOOL bBool )
90 Write(comm_USHORT(SIReturn));
91 Write(nRet);
92 Write(pUId);
93 Write(comm_USHORT(PARAM_BOOL_1)); // Typ der folgenden Parameter
94 Write(bBool);
97 void CmdBaseStream::GenReturn (comm_USHORT nRet, SmartId *pUId, comm_ULONG nNr, comm_String *pString, comm_BOOL bBool )
99 Write(comm_USHORT(SIReturn));
100 Write(nRet);
101 Write(pUId);
102 Write(comm_USHORT(PARAM_ULONG_1|PARAM_STR_1|PARAM_BOOL_1)); // Typ der folgenden Parameter
103 Write(nNr);
104 Write(pString);
105 Write(bBool);
108 // MacroRecorder
109 void CmdBaseStream::GenReturn( comm_USHORT nRet, SmartId *pUId, comm_USHORT nMethod )
111 Write(comm_USHORT(SIReturn));
112 Write(nRet);
113 Write(pUId);
114 Write(comm_USHORT(PARAM_USHORT_1)); // Typ der folgenden Parameter
115 Write(nMethod);
118 void CmdBaseStream::GenReturn( comm_USHORT nRet, SmartId *pUId, comm_USHORT nMethod, comm_String *pString )
120 Write(comm_USHORT(SIReturn));
121 Write(nRet);
122 Write(pUId);
123 Write(comm_USHORT(PARAM_USHORT_1|PARAM_STR_1)); // Typ der folgenden Parameter
124 Write(nMethod);
125 Write(pString);
128 void CmdBaseStream::GenReturn( comm_USHORT nRet, SmartId *pUId, comm_USHORT nMethod, comm_String *pString, comm_BOOL bBool )
130 Write(comm_USHORT(SIReturn));
131 Write(nRet);
132 Write(pUId);
133 Write(comm_USHORT(PARAM_USHORT_1|PARAM_STR_1|PARAM_BOOL_1)); // Typ der folgenden Parameter
134 Write(nMethod);
135 Write(pString);
136 Write(bBool);
139 void CmdBaseStream::GenReturn( comm_USHORT nRet, SmartId *pUId, comm_USHORT nMethod, comm_BOOL bBool )
141 Write(comm_USHORT(SIReturn));
142 Write(nRet);
143 Write(pUId);
144 Write(comm_USHORT(PARAM_USHORT_1|PARAM_BOOL_1)); // Typ der folgenden Parameter
145 Write(nMethod);
146 Write(bBool);
149 void CmdBaseStream::GenReturn( comm_USHORT nRet, SmartId *pUId, comm_USHORT nMethod, comm_ULONG nNr )
151 Write(comm_USHORT(SIReturn));
152 Write(nRet);
153 Write(pUId);
154 Write(comm_USHORT(PARAM_USHORT_1|PARAM_ULONG_1)); // Typ der folgenden Parameter
155 Write(nMethod);
156 Write(nNr);
161 void CmdBaseStream::Read (comm_USHORT &nNr)
163 comm_USHORT nId;
164 *pCommStream >> nId;
165 if (pCommStream->IsEof()) return;
166 #ifdef DBG_UTIL
167 if (nId != BinUSHORT) DBG_ERROR1( "Falscher Typ im Stream: Erwartet USHORT, gefunden :%hu", nId );
168 #endif
169 *pCommStream >> nNr;
172 void CmdBaseStream::Read (comm_ULONG &nNr)
174 comm_USHORT nId;
175 *pCommStream >> nId;
176 if (pCommStream->IsEof()) return;
177 #ifdef DBG_UTIL
178 if (nId != BinULONG) DBG_ERROR1( "Falscher Typ im Stream: Erwartet ULONG, gefunden :%hu", nId );
179 #endif
180 *pCommStream >> nNr;
183 void CmdBaseStream::Read (comm_UniChar* &aString, comm_USHORT &nLenInChars )
185 comm_USHORT nId;
186 *pCommStream >> nId;
187 #ifdef DBG_UTIL
188 if (nId != BinString) DBG_ERROR1( "Falscher Typ im Stream: Erwartet String, gefunden :%hu", nId );
189 #endif
191 *pCommStream >> nLenInChars;
193 aString = new comm_UniChar [nLenInChars];
194 pCommStream->Read( aString, ((comm_ULONG)nLenInChars) * sizeof( comm_UniChar ) );
195 #ifdef OSL_BIGENDIAN
196 // we have to change the byteorder
197 comm_USHORT n;
198 for ( n = 0 ; n < nLenInChars ; n++ )
199 aString[ n ] = aString[ n ] >> 8 | aString[ n ] << 8;
200 #endif
203 void CmdBaseStream::Read (comm_BOOL &bBool)
205 comm_USHORT nId;
206 *pCommStream >> nId;
207 #ifdef DBG_UTIL
208 if (nId != BinBool) DBG_ERROR1( "Falscher Typ im Stream: Erwartet BOOL, gefunden :%hu", nId );
209 #endif
210 *pCommStream >> bBool;
213 comm_USHORT CmdBaseStream::GetNextType()
215 comm_USHORT nId;
216 *pCommStream >> nId;
217 pCommStream->SeekRel(-2);
218 return nId;
222 void CmdBaseStream::Write( comm_USHORT nNr )
224 *pCommStream << comm_USHORT( BinUSHORT );
225 *pCommStream << nNr;
228 void CmdBaseStream::Write( comm_ULONG nNr )
230 *pCommStream << comm_USHORT( BinULONG );
231 *pCommStream << nNr;
234 void CmdBaseStream::Write( const comm_UniChar* aString, comm_USHORT nLenInChars )
236 *pCommStream << comm_USHORT(BinString);
238 comm_USHORT n;
240 // remove BiDi and zero-width-markers 0x200B - 0x200F
241 // remove BiDi and paragraph-markers 0x2028 - 0x202E
243 comm_UniChar* aNoBiDiString;
244 aNoBiDiString = new comm_UniChar [nLenInChars];
245 comm_USHORT nNewLenInChars = 0;
246 for ( n = 0 ; n < nLenInChars ; n++ )
248 comm_UniChar c = aString[ n ];
249 if ( ((c >= 0x200B) && (c <= 0x200F))
250 ||((c >= 0x2028) && (c <= 0x202E)) )
251 { //Ignore character
253 else
255 aNoBiDiString[ nNewLenInChars ] = c;
256 nNewLenInChars++;
260 *pCommStream << nNewLenInChars;
262 #ifdef OSL_BIGENDIAN
263 // we have to change the byteorder
264 comm_UniChar* aNewString;
265 aNewString = new comm_UniChar [nNewLenInChars];
266 for ( n = 0 ; n < nNewLenInChars ; n++ )
267 aNewString[ n ] = aNoBiDiString[ n ] >> 8 | aNoBiDiString[ n ] << 8;
268 pCommStream->Write( aNewString, ((comm_ULONG)nNewLenInChars) * sizeof( comm_UniChar ) );
269 delete [] aNewString;
270 #else
271 pCommStream->Write( aNoBiDiString, ((comm_ULONG)nNewLenInChars) * sizeof( comm_UniChar ) );
272 #endif
274 delete [] aNoBiDiString;
277 void CmdBaseStream::Write( comm_BOOL bBool )
279 *pCommStream << comm_USHORT( BinBool );
280 *pCommStream << bBool;
283 void CmdBaseStream::Read ( comm_String* &pString )
285 (void) pString; /* avoid warning about unused parameter */
286 DBG_ERROR("Read ( comm_String* &pString ) Not Implemented");
288 void CmdBaseStream::Read ( SmartId* &pId )
290 (void) pId; /* avoid warning about unused parameter */
291 DBG_ERROR("Read ( SmartId* &pId ) Not Implemented");
294 void CmdBaseStream::Write( comm_String *pString )
296 (void) pString; /* avoid warning about unused parameter */
297 DBG_ERROR("Write( comm_String *pString ) Not Implemented");
299 void CmdBaseStream::Write( SmartId* pId )
301 (void) pId; /* avoid warning about unused parameter */
302 DBG_ERROR("Write( SmartId* pId ) Not Implemented");