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: rscstr.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_rsc.hxx"
33 /****************** I N C L U D E S **************************************/
35 // C and C++ Includes.
40 // Programmabh�ngige Includes.
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()
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
) );
65 /*************************************************************************
67 |* RscString::GetClassType()
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()
84 |* Ersterstellung MM 25.04.91
85 |* Letzte Aenderung MM 25.04.91
87 *************************************************************************/
88 ERRTYPE
RscString::SetString( const RSCINST
& rInst
, const char * pStr
){
93 ((RscStringInst
*)rInst
.pData
)->bDflt
= FALSE
;
95 pTmp
= ((RscStringInst
*)rInst
.pData
)->pStr
;
97 rtl_freeMemory( pTmp
);
102 sal_uInt32 nLen
= strlen( pStr
) +1;
103 pTmp
= (char *)rtl_allocateMemory( nLen
);
104 memcpy( pTmp
, pStr
, nLen
);
107 ((RscStringInst
*)rInst
.pData
)->pStr
= pTmp
;
113 /*************************************************************************
115 |* RscString::GetString()
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
;
127 /*************************************************************************
129 |* RscString::GetRef()
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
;
141 /*************************************************************************
143 |* RscString::SetRef()
146 |* Ersterstellung MM 15.05.91
147 |* Letzte Aenderung MM 15.05.91
149 *************************************************************************/
150 ERRTYPE
RscString::SetRef( const RSCINST
& rInst
, const RscId
& rRefId
){
152 ((RscStringInst
*)rInst
.pData
)->aRefId
= rRefId
;
153 ((RscStringInst
*)rInst
.pData
)->bDflt
= FALSE
;
156 return( ERR_REFNOTALLOWED
);
161 /*************************************************************************
163 |* RscString::Create()
166 |* Ersterstellung MM 25.04.91
167 |* Letzte Aenderung MM 25.04.91
169 *************************************************************************/
170 RSCINST
RscString::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
177 aInst
.pData
= (CLASS_DATA
)
178 rtl_allocateMemory( sizeof( RscStringInst
) );
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
;
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
;
200 /*************************************************************************
202 |* RscString::Destroy()
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()
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
;
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() )
242 BOOL bStrEmpty
= FALSE
;
243 BOOL bDefStrEmpty
= FALSE
;
246 bStrEmpty
= ('\0' == *pData
->pStr
);
251 if( pDefData
->pStr
){
252 bDefStrEmpty
= ('\0' == *pDefData
->pStr
);
257 if( !bStrEmpty
|| !bDefStrEmpty
){
267 /*************************************************************************
269 |* RscString::WriteSrc()
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() );
286 RscStringInst
* pStrI
= ((RscStringInst
*)rInst
.pData
);
288 //char * pChangeTab = RscChar::GetChangeTab();
290 sal_uInt32 nPos
, nSlashPos
;
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
] == '\\' )
305 fputc( '\"', fOutput
);
306 if( pStrI
->pStr
[ n
] ) //nocht nicht zu ende
307 fputc( '\n', fOutput
);
308 } while( pStrI
->pStr
[ n
] );
311 fprintf( fOutput
, "\"\"" );
315 /*************************************************************************
317 |* RscString::WriteRc()
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
)
328 ObjNode
* pObjNode
= NULL
;
331 if( ((RscStringInst
*)rInst
.pData
)->aRefId
.IsId() ){
332 RscId
aId( ((RscStringInst
*)rInst
.pData
)->aRefId
);
335 aTmpI
.pClass
= pRefClass
;
337 while( aError
.IsOk() && aId
.IsId() ){
338 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
340 if( nDeep
> nRefDeep
)
341 aError
= ERR_REFTODEEP
;
344 pObjNode
= pRefClass
->GetObjNode( aId
);
347 aTmpI
.pData
= pObjNode
->GetRscObj();
348 aError
= pRefClass
->GetRef( aTmpI
, &aId
);
354 ByteString
aMsg( pHS
->getString( pRefClass
->GetId() ).getStr() );
356 aMsg
+= aId
.GetName();
357 aError
= WRN_STR_REFNOTFOUND
;
358 pTC
->pEH
->Error( aError
, rInst
.pClass
,
359 RscId(), aMsg
.GetBuffer() );
373 aRefI
= RSCINST( pRefClass
, pObjNode
->GetRscObj() );
374 aError
= aRefI
.pClass
->WriteRc( aRefI
, rMem
, pTC
, nDeep
, bExtra
);
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
);
386 rMem
.PutUTF8( ((RscStringInst
*)rInst
.pData
)->pStr
);
392 //==================================================================
393 void RscString::WriteRcAccess
396 RscTypCont
* /*pTC*/,
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" );