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.
37 // Programmabh�ngige Includes.
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()
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
) );
62 /*************************************************************************
64 |* RscString::GetClassType()
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()
81 |* Ersterstellung MM 25.04.91
82 |* Letzte Aenderung MM 25.04.91
84 *************************************************************************/
85 ERRTYPE
RscString::SetString( const RSCINST
& rInst
, const char * pStr
){
90 ((RscStringInst
*)rInst
.pData
)->bDflt
= sal_False
;
92 pTmp
= ((RscStringInst
*)rInst
.pData
)->pStr
;
94 rtl_freeMemory( pTmp
);
99 sal_uInt32 nLen
= strlen( pStr
) +1;
100 pTmp
= (char *)rtl_allocateMemory( nLen
);
101 memcpy( pTmp
, pStr
, nLen
);
104 ((RscStringInst
*)rInst
.pData
)->pStr
= pTmp
;
110 /*************************************************************************
112 |* RscString::GetString()
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
;
124 /*************************************************************************
126 |* RscString::GetRef()
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
;
138 /*************************************************************************
140 |* RscString::SetRef()
143 |* Ersterstellung MM 15.05.91
144 |* Letzte Aenderung MM 15.05.91
146 *************************************************************************/
147 ERRTYPE
RscString::SetRef( const RSCINST
& rInst
, const RscId
& rRefId
){
149 ((RscStringInst
*)rInst
.pData
)->aRefId
= rRefId
;
150 ((RscStringInst
*)rInst
.pData
)->bDflt
= sal_False
;
153 return( ERR_REFNOTALLOWED
);
158 /*************************************************************************
160 |* RscString::Create()
163 |* Ersterstellung MM 25.04.91
164 |* Letzte Aenderung MM 25.04.91
166 *************************************************************************/
167 RSCINST
RscString::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
174 aInst
.pData
= (CLASS_DATA
)
175 rtl_allocateMemory( sizeof( RscStringInst
) );
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
;
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
;
197 /*************************************************************************
199 |* RscString::Destroy()
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()
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
;
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() )
239 sal_Bool bStrEmpty
= sal_False
;
240 sal_Bool bDefStrEmpty
= sal_False
;
243 bStrEmpty
= ('\0' == *pData
->pStr
);
246 bStrEmpty
= sal_True
;
248 if( pDefData
->pStr
){
249 bDefStrEmpty
= ('\0' == *pDefData
->pStr
);
252 bDefStrEmpty
= sal_True
;
254 if( !bStrEmpty
|| !bDefStrEmpty
){
264 /*************************************************************************
266 |* RscString::WriteSrc()
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() );
283 RscStringInst
* pStrI
= ((RscStringInst
*)rInst
.pData
);
285 //char * pChangeTab = RscChar::GetChangeTab();
287 sal_uInt32 nPos
, nSlashPos
;
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
] == '\\' )
302 fputc( '\"', fOutput
);
303 if( pStrI
->pStr
[ n
] ) //nocht nicht zu ende
304 fputc( '\n', fOutput
);
305 } while( pStrI
->pStr
[ n
] );
308 fprintf( fOutput
, "\"\"" );
312 /*************************************************************************
314 |* RscString::WriteRc()
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
)
325 ObjNode
* pObjNode
= NULL
;
328 if( ((RscStringInst
*)rInst
.pData
)->aRefId
.IsId() ){
329 RscId
aId( ((RscStringInst
*)rInst
.pData
)->aRefId
);
332 aTmpI
.pClass
= pRefClass
;
334 while( aError
.IsOk() && aId
.IsId() ){
335 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
337 if( nDeep
> nRefDeep
)
338 aError
= ERR_REFTODEEP
;
341 pObjNode
= pRefClass
->GetObjNode( aId
);
344 aTmpI
.pData
= pObjNode
->GetRscObj();
345 aError
= pRefClass
->GetRef( aTmpI
, &aId
);
351 ByteString
aMsg( pHS
->getString( pRefClass
->GetId() ).getStr() );
353 aMsg
+= aId
.GetName();
354 aError
= WRN_STR_REFNOTFOUND
;
355 pTC
->pEH
->Error( aError
, rInst
.pClass
,
356 RscId(), aMsg
.GetBuffer() );
370 aRefI
= RSCINST( pRefClass
, pObjNode
->GetRscObj() );
371 aError
= aRefI
.pClass
->WriteRc( aRefI
, rMem
, pTC
, nDeep
, bExtra
);
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
);
383 rMem
.PutUTF8( ((RscStringInst
*)rInst
.pData
)->pStr
);
389 //==================================================================
390 void RscString::WriteRcAccess
393 RscTypCont
* /*pTC*/,
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" );