1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cmdbasestream.cxx,v $
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 /*************************************************************************
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()
51 CmdBaseStream::~CmdBaseStream()
55 void CmdBaseStream::GenError (SmartId
*pUId
, comm_String
*pString
)
57 Write(comm_USHORT(SIReturnError
));
62 void CmdBaseStream::GenReturn (comm_USHORT nRet
, comm_ULONG nUId
)
64 Write(comm_USHORT(SIReturn
));
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
));
75 Write(comm_USHORT(PARAM_ULONG_1
)); // Typ der folgenden Parameter
79 void CmdBaseStream::GenReturn (comm_USHORT nRet
, SmartId
*pUId
, comm_String
*pString
)
81 Write(comm_USHORT(SIReturn
));
84 Write(comm_USHORT(PARAM_STR_1
)); // Typ der folgenden Parameter
88 void CmdBaseStream::GenReturn (comm_USHORT nRet
, SmartId
*pUId
, comm_BOOL bBool
)
90 Write(comm_USHORT(SIReturn
));
93 Write(comm_USHORT(PARAM_BOOL_1
)); // Typ der folgenden Parameter
97 void CmdBaseStream::GenReturn (comm_USHORT nRet
, SmartId
*pUId
, comm_ULONG nNr
, comm_String
*pString
, comm_BOOL bBool
)
99 Write(comm_USHORT(SIReturn
));
102 Write(comm_USHORT(PARAM_ULONG_1
|PARAM_STR_1
|PARAM_BOOL_1
)); // Typ der folgenden Parameter
109 void CmdBaseStream::GenReturn( comm_USHORT nRet
, SmartId
*pUId
, comm_USHORT nMethod
)
111 Write(comm_USHORT(SIReturn
));
114 Write(comm_USHORT(PARAM_USHORT_1
)); // Typ der folgenden Parameter
118 void CmdBaseStream::GenReturn( comm_USHORT nRet
, SmartId
*pUId
, comm_USHORT nMethod
, comm_String
*pString
)
120 Write(comm_USHORT(SIReturn
));
123 Write(comm_USHORT(PARAM_USHORT_1
|PARAM_STR_1
)); // Typ der folgenden Parameter
128 void CmdBaseStream::GenReturn( comm_USHORT nRet
, SmartId
*pUId
, comm_USHORT nMethod
, comm_String
*pString
, comm_BOOL bBool
)
130 Write(comm_USHORT(SIReturn
));
133 Write(comm_USHORT(PARAM_USHORT_1
|PARAM_STR_1
|PARAM_BOOL_1
)); // Typ der folgenden Parameter
139 void CmdBaseStream::GenReturn( comm_USHORT nRet
, SmartId
*pUId
, comm_USHORT nMethod
, comm_BOOL bBool
)
141 Write(comm_USHORT(SIReturn
));
144 Write(comm_USHORT(PARAM_USHORT_1
|PARAM_BOOL_1
)); // Typ der folgenden Parameter
149 void CmdBaseStream::GenReturn( comm_USHORT nRet
, SmartId
*pUId
, comm_USHORT nMethod
, comm_ULONG nNr
)
151 Write(comm_USHORT(SIReturn
));
154 Write(comm_USHORT(PARAM_USHORT_1
|PARAM_ULONG_1
)); // Typ der folgenden Parameter
161 void CmdBaseStream::Read (comm_USHORT
&nNr
)
165 if (pCommStream
->IsEof()) return;
167 if (nId
!= BinUSHORT
) DBG_ERROR1( "Falscher Typ im Stream: Erwartet USHORT, gefunden :%hu", nId
);
172 void CmdBaseStream::Read (comm_ULONG
&nNr
)
176 if (pCommStream
->IsEof()) return;
178 if (nId
!= BinULONG
) DBG_ERROR1( "Falscher Typ im Stream: Erwartet ULONG, gefunden :%hu", nId
);
183 void CmdBaseStream::Read (comm_UniChar
* &aString
, comm_USHORT
&nLenInChars
)
188 if (nId
!= BinString
) DBG_ERROR1( "Falscher Typ im Stream: Erwartet String, gefunden :%hu", nId
);
191 *pCommStream
>> nLenInChars
;
193 aString
= new comm_UniChar
[nLenInChars
];
194 pCommStream
->Read( aString
, ((comm_ULONG
)nLenInChars
) * sizeof( comm_UniChar
) );
196 // we have to change the byteorder
198 for ( n
= 0 ; n
< nLenInChars
; n
++ )
199 aString
[ n
] = aString
[ n
] >> 8 | aString
[ n
] << 8;
203 void CmdBaseStream::Read (comm_BOOL
&bBool
)
208 if (nId
!= BinBool
) DBG_ERROR1( "Falscher Typ im Stream: Erwartet BOOL, gefunden :%hu", nId
);
210 *pCommStream
>> bBool
;
213 comm_USHORT
CmdBaseStream::GetNextType()
217 pCommStream
->SeekRel(-2);
222 void CmdBaseStream::Write( comm_USHORT nNr
)
224 *pCommStream
<< comm_USHORT( BinUSHORT
);
228 void CmdBaseStream::Write( comm_ULONG nNr
)
230 *pCommStream
<< comm_USHORT( BinULONG
);
234 void CmdBaseStream::Write( const comm_UniChar
* aString
, comm_USHORT nLenInChars
)
236 *pCommStream
<< comm_USHORT(BinString
);
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)) )
255 aNoBiDiString
[ nNewLenInChars
] = c
;
260 *pCommStream
<< nNewLenInChars
;
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
;
271 pCommStream
->Write( aNoBiDiString
, ((comm_ULONG
)nNewLenInChars
) * sizeof( comm_UniChar
) );
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");