CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / rsc / source / res / rscstr.cxx
blobad668ac2b3cb5c917c63378eb6e7d1b8c956c762
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_rsc.hxx"
30 /****************** I N C L U D E S **************************************/
32 // C and C++ Includes.
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
37 // Programmabh�ngige Includes.
38 #include <rscdb.hxx>
39 #include <rscstr.hxx>
41 #include <rtl/textcvt.h>
42 #include <rtl/textenc.h>
44 /****************** C O D E **********************************************/
45 /****************** R s c S t r i n g ************************************/
46 /*************************************************************************
48 |* RscString::RscString()
50 |* Beschreibung
51 |* Ersterstellung MM 25.04.91
52 |* Letzte Aenderung MM 25.04.91
54 *************************************************************************/
55 RscString::RscString( Atom nId, sal_uInt32 nTypeId )
56 : RscTop( nId, nTypeId )
58 nSize = ALIGNED_SIZE( sizeof( RscStringInst ) );
59 pRefClass = NULL;
62 /*************************************************************************
64 |* RscString::GetClassType()
66 |* Beschreibung
67 |* Ersterstellung MM 25.04.91
68 |* Letzte Aenderung MM 25.04.91
70 *************************************************************************/
71 RSCCLASS_TYPE RscString::GetClassType() const
73 return RSCCLASS_STRING;
76 /*************************************************************************
78 |* RscString::SetNumber()
80 |* Beschreibung
81 |* Ersterstellung MM 25.04.91
82 |* Letzte Aenderung MM 25.04.91
84 *************************************************************************/
85 ERRTYPE RscString::SetString( const RSCINST & rInst, const char * pStr ){
86 char * pTmp;
87 ERRTYPE aError;
89 if( aError.IsOk() ){
90 ((RscStringInst *)rInst.pData)->bDflt = sal_False;
92 pTmp = ((RscStringInst *)rInst.pData)->pStr;
93 if( pTmp ){
94 rtl_freeMemory( pTmp );
95 pTmp = NULL;
98 if( pStr ){
99 sal_uInt32 nLen = strlen( pStr ) +1;
100 pTmp = (char *)rtl_allocateMemory( nLen );
101 memcpy( pTmp, pStr, nLen );
104 ((RscStringInst *)rInst.pData)->pStr = pTmp;
107 return( aError );
110 /*************************************************************************
112 |* RscString::GetString()
114 |* Beschreibung
115 |* Ersterstellung MM 25.04.91
116 |* Letzte Aenderung MM 25.04.91
118 *************************************************************************/
119 ERRTYPE RscString::GetString( const RSCINST & rInst, char ** ppStr ){
120 *ppStr = ((RscStringInst *)rInst.pData)->pStr;
121 return( ERR_OK );
124 /*************************************************************************
126 |* RscString::GetRef()
128 |* Beschreibung
129 |* Ersterstellung MM 22.07.91
130 |* Letzte Aenderung MM 22.07.91
132 *************************************************************************/
133 ERRTYPE RscString::GetRef( const RSCINST & rInst, RscId * pRscId ){
134 *pRscId = ((RscStringInst *)rInst.pData)->aRefId;
135 return( ERR_OK );
138 /*************************************************************************
140 |* RscString::SetRef()
142 |* Beschreibung
143 |* Ersterstellung MM 15.05.91
144 |* Letzte Aenderung MM 15.05.91
146 *************************************************************************/
147 ERRTYPE RscString::SetRef( const RSCINST & rInst, const RscId & rRefId ){
148 if( pRefClass ){
149 ((RscStringInst *)rInst.pData)->aRefId = rRefId;
150 ((RscStringInst *)rInst.pData)->bDflt = sal_False;
152 else
153 return( ERR_REFNOTALLOWED );
155 return ERR_OK;
158 /*************************************************************************
160 |* RscString::Create()
162 |* Beschreibung
163 |* Ersterstellung MM 25.04.91
164 |* Letzte Aenderung MM 25.04.91
166 *************************************************************************/
167 RSCINST RscString::Create( RSCINST * pInst, const RSCINST & rDflt,
168 sal_Bool bOwnClass )
170 RSCINST aInst;
172 if( !pInst ){
173 aInst.pClass = this;
174 aInst.pData = (CLASS_DATA)
175 rtl_allocateMemory( sizeof( RscStringInst ) );
177 else
178 aInst = *pInst;
179 if( !bOwnClass && rDflt.IsInst() )
180 bOwnClass = rDflt.pClass->InHierarchy( this );
182 ((RscStringInst *)aInst.pData)->aRefId.Create();
183 ((RscStringInst *)aInst.pData)->pStr = NULL;
184 ((RscStringInst *)aInst.pData)->bDflt = sal_True;
186 if( bOwnClass ){
187 ((RscStringInst *)aInst.pData)->aRefId =
188 ((RscStringInst *)rDflt.pData)->aRefId;
189 SetString( aInst, ((RscStringInst *)rDflt.pData)->pStr );
190 ((RscStringInst *)aInst.pData)->bDflt =
191 ((RscStringInst *)rDflt.pData)->bDflt ;
194 return( aInst );
197 /*************************************************************************
199 |* RscString::Destroy()
201 |* Beschreibung
202 |* Ersterstellung MM 15.05.91
203 |* Letzte Aenderung MM 15.05.91
205 *************************************************************************/
206 void RscString::Destroy( const RSCINST & rInst ){
207 if( ((RscStringInst *)rInst.pData)->pStr )
208 rtl_freeMemory( ((RscStringInst *)rInst.pData)->pStr );
209 ((RscStringInst *)rInst.pData)->aRefId.Destroy();
212 /*************************************************************************
214 |* RscString::IsValueDefault()
216 |* Beschreibung
217 |* Ersterstellung MM 15.01.92
218 |* Letzte Aenderung MM 15.01.92
220 *************************************************************************/
221 sal_Bool RscString::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ){
222 RscStringInst * pData = (RscStringInst*)rInst.pData;
223 RscStringInst * pDefData = (RscStringInst*)pDef;
225 if( pDef ){
226 if( pData->aRefId.IsId() || pDefData->aRefId.IsId() )
228 if( pData->aRefId.aExp.IsNumber()
229 && pDefData->aRefId.aExp.IsNumber() )
231 // Sind die Referenzidentifier gleich
232 if( pData->aRefId.GetNumber() == pDefData->aRefId.GetNumber() )
234 return sal_True;
238 else {
239 sal_Bool bStrEmpty = sal_False;
240 sal_Bool bDefStrEmpty = sal_False;
242 if( pData->pStr ){
243 bStrEmpty = ('\0' == *pData->pStr);
245 else
246 bStrEmpty = sal_True;
248 if( pDefData->pStr ){
249 bDefStrEmpty = ('\0' == *pDefData->pStr);
251 else
252 bDefStrEmpty = sal_True;
254 if( !bStrEmpty || !bDefStrEmpty ){
255 return sal_False;
257 return sal_True;
261 return sal_False;
264 /*************************************************************************
266 |* RscString::WriteSrc()
268 |* Beschreibung
269 |* Ersterstellung MM 25.04.91
270 |* Letzte Aenderung MM 25.04.91
272 *************************************************************************/
273 void RscString::WriteSrc( const RSCINST & rInst, FILE * fOutput,
274 RscTypCont *, sal_uInt32, const char * )
276 if ( ((RscStringInst *)rInst.pData)->aRefId.IsId() )
278 fprintf( fOutput, "%s",
279 ((RscStringInst *)rInst.pData)->aRefId.GetName().GetBuffer() );
281 else
283 RscStringInst * pStrI = ((RscStringInst *)rInst.pData);
284 if( pStrI->pStr ){
285 //char * pChangeTab = RscChar::GetChangeTab();
286 sal_uInt32 n = 0;
287 sal_uInt32 nPos, nSlashPos;
289 do {
290 fputc( '\"', fOutput );
291 nSlashPos = nPos = 0;
292 while( pStrI->pStr[ n ]
293 && (nPos < 72 || nPos - nSlashPos <= 3) )
294 { // nach \ mindesten 3 Zeichen wegeb \xa7
295 fputc( pStrI->pStr[ n ], fOutput );
296 if( pStrI->pStr[ n ] == '\\' )
297 nSlashPos = nPos;
298 n++;
299 nPos++;
302 fputc( '\"', fOutput );
303 if( pStrI->pStr[ n ] ) //nocht nicht zu ende
304 fputc( '\n', fOutput );
305 } while( pStrI->pStr[ n ] );
307 else
308 fprintf( fOutput, "\"\"" );
312 /*************************************************************************
314 |* RscString::WriteRc()
316 |* Beschreibung
317 |* Ersterstellung MM 15.04.91
318 |* Letzte Aenderung MM 15.04.91
320 *************************************************************************/
321 ERRTYPE RscString::WriteRc( const RSCINST & rInst, RscWriteRc & rMem,
322 RscTypCont * pTC, sal_uInt32 nDeep, sal_Bool bExtra )
324 ERRTYPE aError;
325 ObjNode * pObjNode = NULL;
328 if( ((RscStringInst *)rInst.pData)->aRefId.IsId() ){
329 RscId aId( ((RscStringInst *)rInst.pData)->aRefId );
330 RSCINST aTmpI;
332 aTmpI.pClass = pRefClass;
334 while( aError.IsOk() && aId.IsId() ){
335 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
336 nDeep++;
337 if( nDeep > nRefDeep )
338 aError = ERR_REFTODEEP;
339 else
341 pObjNode = pRefClass->GetObjNode( aId );
342 if( pObjNode )
344 aTmpI.pData = pObjNode->GetRscObj();
345 aError = pRefClass->GetRef( aTmpI, &aId );
347 else
349 if( pTC )
351 ByteString aMsg( pHS->getString( pRefClass->GetId() ).getStr() );
352 aMsg += ' ';
353 aMsg += aId.GetName();
354 aError = WRN_STR_REFNOTFOUND;
355 pTC->pEH->Error( aError, rInst.pClass,
356 RscId(), aMsg.GetBuffer() );
358 break;
364 if( aError.IsOk() )
366 if( pObjNode )
368 RSCINST aRefI;
370 aRefI = RSCINST( pRefClass, pObjNode->GetRscObj() );
371 aError = aRefI.pClass->WriteRc( aRefI, rMem, pTC, nDeep, bExtra );
373 else
375 if( ((RscStringInst *)rInst.pData)->pStr && pTC )
377 char * pStr = RscChar::MakeUTF8( ((RscStringInst *)rInst.pData)->pStr,
378 pTC->GetSourceCharSet() );
379 rMem.PutUTF8( pStr );
380 rtl_freeMemory( pStr );
382 else
383 rMem.PutUTF8( ((RscStringInst *)rInst.pData)->pStr );
386 return( aError );
389 //==================================================================
390 void RscString::WriteRcAccess
392 FILE * fOutput,
393 RscTypCont * /*pTC*/,
394 const char * pName
397 fprintf( fOutput, "\t\tString aStr( (const char*)(pResData+nOffset) );\n" );
398 fprintf( fOutput, "\t\tSet%s( aStr );\n", pName );
399 fprintf( fOutput, "\t\tnOffset += GetStringSizeRes( aStr );\n" );