Update ooo320-m1
[ooovba.git] / rsc / source / res / rscstr.cxx
blobc44b2835089d689a1cb7690f1b74aaccde40c785
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: rscstr.cxx,v $
10 * $Revision: 1.8 $
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_rsc.hxx"
33 /****************** I N C L U D E S **************************************/
35 // C and C++ Includes.
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
40 // Programmabh�ngige Includes.
41 #include <rscdb.hxx>
42 #include <rscstr.hxx>
44 #include <rtl/textcvt.h>
45 #include <rtl/textenc.h>
47 /****************** C O D E **********************************************/
48 /****************** R s c S t r i n g ************************************/
49 /*************************************************************************
51 |* RscString::RscString()
53 |* Beschreibung
54 |* Ersterstellung MM 25.04.91
55 |* Letzte Aenderung MM 25.04.91
57 *************************************************************************/
58 RscString::RscString( Atom nId, sal_uInt32 nTypeId )
59 : RscTop( nId, nTypeId )
61 nSize = ALIGNED_SIZE( sizeof( RscStringInst ) );
62 pRefClass = NULL;
65 /*************************************************************************
67 |* RscString::GetClassType()
69 |* Beschreibung
70 |* Ersterstellung MM 25.04.91
71 |* Letzte Aenderung MM 25.04.91
73 *************************************************************************/
74 RSCCLASS_TYPE RscString::GetClassType() const
76 return RSCCLASS_STRING;
79 /*************************************************************************
81 |* RscString::SetNumber()
83 |* Beschreibung
84 |* Ersterstellung MM 25.04.91
85 |* Letzte Aenderung MM 25.04.91
87 *************************************************************************/
88 ERRTYPE RscString::SetString( const RSCINST & rInst, const char * pStr ){
89 char * pTmp;
90 ERRTYPE aError;
92 if( aError.IsOk() ){
93 ((RscStringInst *)rInst.pData)->bDflt = FALSE;
95 pTmp = ((RscStringInst *)rInst.pData)->pStr;
96 if( pTmp ){
97 rtl_freeMemory( pTmp );
98 pTmp = NULL;
101 if( pStr ){
102 sal_uInt32 nLen = strlen( pStr ) +1;
103 pTmp = (char *)rtl_allocateMemory( nLen );
104 memcpy( pTmp, pStr, nLen );
107 ((RscStringInst *)rInst.pData)->pStr = pTmp;
110 return( aError );
113 /*************************************************************************
115 |* RscString::GetString()
117 |* Beschreibung
118 |* Ersterstellung MM 25.04.91
119 |* Letzte Aenderung MM 25.04.91
121 *************************************************************************/
122 ERRTYPE RscString::GetString( const RSCINST & rInst, char ** ppStr ){
123 *ppStr = ((RscStringInst *)rInst.pData)->pStr;
124 return( ERR_OK );
127 /*************************************************************************
129 |* RscString::GetRef()
131 |* Beschreibung
132 |* Ersterstellung MM 22.07.91
133 |* Letzte Aenderung MM 22.07.91
135 *************************************************************************/
136 ERRTYPE RscString::GetRef( const RSCINST & rInst, RscId * pRscId ){
137 *pRscId = ((RscStringInst *)rInst.pData)->aRefId;
138 return( ERR_OK );
141 /*************************************************************************
143 |* RscString::SetRef()
145 |* Beschreibung
146 |* Ersterstellung MM 15.05.91
147 |* Letzte Aenderung MM 15.05.91
149 *************************************************************************/
150 ERRTYPE RscString::SetRef( const RSCINST & rInst, const RscId & rRefId ){
151 if( pRefClass ){
152 ((RscStringInst *)rInst.pData)->aRefId = rRefId;
153 ((RscStringInst *)rInst.pData)->bDflt = FALSE;
155 else
156 return( ERR_REFNOTALLOWED );
158 return ERR_OK;
161 /*************************************************************************
163 |* RscString::Create()
165 |* Beschreibung
166 |* Ersterstellung MM 25.04.91
167 |* Letzte Aenderung MM 25.04.91
169 *************************************************************************/
170 RSCINST RscString::Create( RSCINST * pInst, const RSCINST & rDflt,
171 BOOL bOwnClass )
173 RSCINST aInst;
175 if( !pInst ){
176 aInst.pClass = this;
177 aInst.pData = (CLASS_DATA)
178 rtl_allocateMemory( sizeof( RscStringInst ) );
180 else
181 aInst = *pInst;
182 if( !bOwnClass && rDflt.IsInst() )
183 bOwnClass = rDflt.pClass->InHierarchy( this );
185 ((RscStringInst *)aInst.pData)->aRefId.Create();
186 ((RscStringInst *)aInst.pData)->pStr = NULL;
187 ((RscStringInst *)aInst.pData)->bDflt = TRUE;
189 if( bOwnClass ){
190 ((RscStringInst *)aInst.pData)->aRefId =
191 ((RscStringInst *)rDflt.pData)->aRefId;
192 SetString( aInst, ((RscStringInst *)rDflt.pData)->pStr );
193 ((RscStringInst *)aInst.pData)->bDflt =
194 ((RscStringInst *)rDflt.pData)->bDflt ;
197 return( aInst );
200 /*************************************************************************
202 |* RscString::Destroy()
204 |* Beschreibung
205 |* Ersterstellung MM 15.05.91
206 |* Letzte Aenderung MM 15.05.91
208 *************************************************************************/
209 void RscString::Destroy( const RSCINST & rInst ){
210 if( ((RscStringInst *)rInst.pData)->pStr )
211 rtl_freeMemory( ((RscStringInst *)rInst.pData)->pStr );
212 ((RscStringInst *)rInst.pData)->aRefId.Destroy();
215 /*************************************************************************
217 |* RscString::IsValueDefault()
219 |* Beschreibung
220 |* Ersterstellung MM 15.01.92
221 |* Letzte Aenderung MM 15.01.92
223 *************************************************************************/
224 BOOL RscString::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ){
225 RscStringInst * pData = (RscStringInst*)rInst.pData;
226 RscStringInst * pDefData = (RscStringInst*)pDef;
228 if( pDef ){
229 if( pData->aRefId.IsId() || pDefData->aRefId.IsId() )
231 if( pData->aRefId.aExp.IsNumber()
232 && pDefData->aRefId.aExp.IsNumber() )
234 // Sind die Referenzidentifier gleich
235 if( pData->aRefId.GetNumber() == pDefData->aRefId.GetNumber() )
237 return TRUE;
241 else {
242 BOOL bStrEmpty = FALSE;
243 BOOL bDefStrEmpty = FALSE;
245 if( pData->pStr ){
246 bStrEmpty = ('\0' == *pData->pStr);
248 else
249 bStrEmpty = TRUE;
251 if( pDefData->pStr ){
252 bDefStrEmpty = ('\0' == *pDefData->pStr);
254 else
255 bDefStrEmpty = TRUE;
257 if( !bStrEmpty || !bDefStrEmpty ){
258 return FALSE;
260 return TRUE;
264 return FALSE;
267 /*************************************************************************
269 |* RscString::WriteSrc()
271 |* Beschreibung
272 |* Ersterstellung MM 25.04.91
273 |* Letzte Aenderung MM 25.04.91
275 *************************************************************************/
276 void RscString::WriteSrc( const RSCINST & rInst, FILE * fOutput,
277 RscTypCont *, sal_uInt32, const char * )
279 if ( ((RscStringInst *)rInst.pData)->aRefId.IsId() )
281 fprintf( fOutput, "%s",
282 ((RscStringInst *)rInst.pData)->aRefId.GetName().GetBuffer() );
284 else
286 RscStringInst * pStrI = ((RscStringInst *)rInst.pData);
287 if( pStrI->pStr ){
288 //char * pChangeTab = RscChar::GetChangeTab();
289 sal_uInt32 n = 0;
290 sal_uInt32 nPos, nSlashPos;
292 do {
293 fputc( '\"', fOutput );
294 nSlashPos = nPos = 0;
295 while( pStrI->pStr[ n ]
296 && (nPos < 72 || nPos - nSlashPos <= 3) )
297 { // nach \ mindesten 3 Zeichen wegeb \xa7
298 fputc( pStrI->pStr[ n ], fOutput );
299 if( pStrI->pStr[ n ] == '\\' )
300 nSlashPos = nPos;
301 n++;
302 nPos++;
305 fputc( '\"', fOutput );
306 if( pStrI->pStr[ n ] ) //nocht nicht zu ende
307 fputc( '\n', fOutput );
308 } while( pStrI->pStr[ n ] );
310 else
311 fprintf( fOutput, "\"\"" );
315 /*************************************************************************
317 |* RscString::WriteRc()
319 |* Beschreibung
320 |* Ersterstellung MM 15.04.91
321 |* Letzte Aenderung MM 15.04.91
323 *************************************************************************/
324 ERRTYPE RscString::WriteRc( const RSCINST & rInst, RscWriteRc & rMem,
325 RscTypCont * pTC, sal_uInt32 nDeep, BOOL bExtra )
327 ERRTYPE aError;
328 ObjNode * pObjNode = NULL;
331 if( ((RscStringInst *)rInst.pData)->aRefId.IsId() ){
332 RscId aId( ((RscStringInst *)rInst.pData)->aRefId );
333 RSCINST aTmpI;
335 aTmpI.pClass = pRefClass;
337 while( aError.IsOk() && aId.IsId() ){
338 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
339 nDeep++;
340 if( nDeep > nRefDeep )
341 aError = ERR_REFTODEEP;
342 else
344 pObjNode = pRefClass->GetObjNode( aId );
345 if( pObjNode )
347 aTmpI.pData = pObjNode->GetRscObj();
348 aError = pRefClass->GetRef( aTmpI, &aId );
350 else
352 if( pTC )
354 ByteString aMsg( pHS->getString( pRefClass->GetId() ).getStr() );
355 aMsg += ' ';
356 aMsg += aId.GetName();
357 aError = WRN_STR_REFNOTFOUND;
358 pTC->pEH->Error( aError, rInst.pClass,
359 RscId(), aMsg.GetBuffer() );
361 break;
367 if( aError.IsOk() )
369 if( pObjNode )
371 RSCINST aRefI;
373 aRefI = RSCINST( pRefClass, pObjNode->GetRscObj() );
374 aError = aRefI.pClass->WriteRc( aRefI, rMem, pTC, nDeep, bExtra );
376 else
378 if( ((RscStringInst *)rInst.pData)->pStr && pTC )
380 char * pStr = RscChar::MakeUTF8( ((RscStringInst *)rInst.pData)->pStr,
381 pTC->GetSourceCharSet() );
382 rMem.PutUTF8( pStr );
383 rtl_freeMemory( pStr );
385 else
386 rMem.PutUTF8( ((RscStringInst *)rInst.pData)->pStr );
389 return( aError );
392 //==================================================================
393 void RscString::WriteRcAccess
395 FILE * fOutput,
396 RscTypCont * /*pTC*/,
397 const char * pName
400 fprintf( fOutput, "\t\tString aStr( (const char*)(pResData+nOffset) );\n" );
401 fprintf( fOutput, "\t\tSet%s( aStr );\n", pName );
402 fprintf( fOutput, "\t\tnOffset += GetStringSizeRes( aStr );\n" );