1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 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 **************************************/ 31 32 // C and C++ Includes. 33 #include <stdlib.h> 34 #include <stdio.h> 35 #include <string.h> 36 37 #include <rscflag.hxx> 38 39 /****************** C O D E **********************************************/ 40 /****************** R s c F l a g ****************************************/ 41 /************************************************************************* 42 |* 43 |* RscFlag::RscFlag() 44 |* 45 |* Beschreibung 46 |* Ersterstellung MM 03.04.91 47 |* Letzte Aenderung MM 03.04.91 48 |* 49 *************************************************************************/ 50 RscFlag::RscFlag( Atom nId, sal_uInt32 nTypeId ) 51 : RscConst( nId, nTypeId ) 52 {} 53 54 /************************************************************************* 55 |* 56 |* RscFlag::Size() 57 |* 58 |* Beschreibung Die Groe�e der Instanzdaten richtet sich nach 59 |* der Anzahl der Flags 60 |* Ersterstellung MM 03.04.91 61 |* Letzte Aenderung MM 03.04.91 62 |* 63 *************************************************************************/ 64 sal_uInt32 RscFlag::Size() 65 { 66 return( ALIGNED_SIZE( sizeof( RscFlagInst ) * 67 ( 1 + (nEntries -1) / (sizeof( sal_uInt32 ) * 8) ) ) ); 68 } 69 70 /************************************************************************* 71 |* 72 |* RscFlag::SetNotConst() 73 |* 74 |* Beschreibung 75 |* Ersterstellung MM 03.04.91 76 |* Letzte Aenderung MM 03.04.91 77 |* 78 *************************************************************************/ 79 ERRTYPE RscFlag::SetNotConst( const RSCINST & rInst, Atom nConst ) 80 { 81 sal_uInt32 i = 0, nFlag = 0; 82 83 if( nEntries != (i = GetConstPos( nConst )) ){ 84 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) ); 85 i = i / (sizeof( sal_uInt32 ) * 8); 86 ((RscFlagInst *)rInst.pData)[ i ].nFlags &= ~nFlag; 87 ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags &= ~nFlag; 88 return( ERR_OK ); 89 }; 90 91 return( ERR_RSCFLAG ); 92 } 93 94 /************************************************************************* 95 |* 96 |* RscFlag::SetConst() 97 |* 98 |* Beschreibung 99 |* Ersterstellung MM 03.04.91 100 |* Letzte Aenderung MM 03.04.91 101 |* 102 *************************************************************************/ 103 ERRTYPE RscFlag::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ ) 104 { 105 sal_uInt32 i = 0, nFlag = 0; 106 107 if( nEntries != (i = GetConstPos( nConst )) ){ 108 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) ); 109 i = i / (sizeof( sal_uInt32 ) * 8); 110 ((RscFlagInst *)rInst.pData)[ i ].nFlags |= nFlag; 111 ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags &= ~nFlag; 112 return( ERR_OK ); 113 }; 114 115 return( ERR_RSCFLAG ); 116 } 117 118 /************************************************************************* 119 |* 120 |* RscFlag::CreateBasic() 121 |* 122 |* Beschreibung 123 |* Ersterstellung MM 16.01.92 124 |* Letzte Aenderung MM 16.01.92 125 |* 126 *************************************************************************/ 127 RSCINST RscFlag::CreateBasic( RSCINST * pInst ) 128 { 129 RSCINST aInst; 130 131 if( !pInst ){ 132 aInst.pClass = this; 133 aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() ); 134 } 135 else 136 aInst = *pInst; 137 138 return( aInst ); 139 } 140 141 /************************************************************************* 142 |* 143 |* RscFlag::Create() 144 |* 145 |* Beschreibung 146 |* Ersterstellung MM 03.04.91 147 |* Letzte Aenderung MM 16.01.92 148 |* 149 *************************************************************************/ 150 RSCINST RscFlag::Create( RSCINST * pInst, const RSCINST & rDflt, sal_Bool bOwnClass ) 151 { 152 RSCINST aInst = CreateBasic( pInst ); 153 sal_uInt32 i = 0; 154 155 if( !bOwnClass && rDflt.IsInst() ) 156 bOwnClass = rDflt.pClass->InHierarchy( this ); 157 158 if( bOwnClass ) 159 memmove( aInst.pData, rDflt.pData, Size() ); 160 else 161 { 162 for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ ) 163 { 164 ((RscFlagInst *)aInst.pData)[ i ].nFlags = 0; 165 ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags = 0xFFFFFFFF; 166 } 167 }; 168 169 return( aInst ); 170 } 171 172 /************************************************************************* 173 |* 174 |* RscFlag::CreateClient() 175 |* 176 |* Beschreibung 177 |* Ersterstellung MM 16.01.92 178 |* Letzte Aenderung MM 16.01.92 179 |* 180 *************************************************************************/ 181 RSCINST RscFlag::CreateClient( RSCINST * pInst, const RSCINST & rDfltI, 182 sal_Bool bOwnClass, Atom nConstId ) 183 { 184 RSCINST aInst = CreateBasic( pInst ); 185 sal_uInt32 i = 0, nFlag = 0; 186 187 if( !bOwnClass && rDfltI.IsInst() ) 188 bOwnClass = rDfltI.pClass->InHierarchy( this ); 189 190 if( nEntries != (i = GetConstPos( nConstId )) ){ 191 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) ); 192 i = i / (sizeof( sal_uInt32 ) * 8); 193 if( bOwnClass ){ 194 ((RscFlagInst *)aInst.pData)[ i ].nFlags &= 195 ~nFlag | ((RscFlagInst *)rDfltI.pData)[ i ].nFlags; 196 ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags &= 197 ~nFlag | ((RscFlagInst *)rDfltI.pData)[ i ].nDfltFlags; 198 } 199 else{ 200 ((RscFlagInst *)aInst.pData)[ i ].nFlags &= ~nFlag; 201 ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags |= nFlag; 202 } 203 } 204 205 return( aInst ); 206 } 207 208 /************************************************************************* 209 |* 210 |* RscFlag::SetToDefault() 211 |* 212 |* Beschreibung 213 |* Ersterstellung MM 03.04.91 214 |* Letzte Aenderung MM 03.04.91 215 |* 216 *************************************************************************/ 217 void RscFlag::SetToDefault( const RSCINST & rInst ) 218 { 219 sal_uInt32 i = 0; 220 221 for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ ) 222 ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags = 0xFFFFFFFF; 223 } 224 225 /************************************************************************* 226 |* 227 |* RscFlag::IsDlft() 228 |* 229 |* Beschreibung 230 |* Ersterstellung MM 03.04.91 231 |* Letzte Aenderung MM 03.04.91 232 |* 233 *************************************************************************/ 234 sal_Bool RscFlag::IsDefault( const RSCINST & rInst ) 235 { 236 sal_uInt32 i = 0; 237 238 for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ ) 239 if( ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags != 0xFFFFFFFF ) 240 return( sal_False ); 241 return( sal_True ); 242 } 243 244 sal_Bool RscFlag::IsDefault( const RSCINST & rInst, Atom nConstId ) 245 { 246 sal_uInt32 i = 0, nFlag = 0; 247 248 if( nEntries != (i = GetConstPos( nConstId )) ){ 249 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) ); 250 i = i / (sizeof( sal_uInt32 ) * 8); 251 if( ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags & nFlag ) 252 return( sal_True ); 253 else 254 return( sal_False ); 255 }; 256 return( sal_True ); 257 } 258 259 /************************************************************************* 260 |* 261 |* RscFlag::IsValueDefault() 262 |* 263 |* Beschreibung 264 |* Ersterstellung MM 25.04.91 265 |* Letzte Aenderung MM 25.04.91 266 |* 267 *************************************************************************/ 268 sal_Bool RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef, 269 Atom nConstId ) 270 { 271 sal_uInt32 i = 0, nFlag = 0; 272 273 if( nEntries != (i = GetConstPos( nConstId )) ){ 274 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) ); 275 i = i / (sizeof( sal_uInt32 ) * 8); 276 277 if( pDef ){ 278 if( (((RscFlagInst *)rInst.pData)[ i ].nFlags & nFlag) 279 == (((RscFlagInst *)pDef)[ i ].nFlags & nFlag) ) 280 { 281 return sal_True; 282 } 283 } 284 }; 285 286 return sal_False; 287 } 288 289 sal_Bool RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ) 290 { 291 sal_uInt32 i = 0; 292 293 if( pDef ){ 294 sal_uInt32 Flag = 0, nIndex = 0; 295 296 Flag = 1; 297 for( i = 0; i < nEntries; i++ ){ 298 nIndex = i / (sizeof( sal_uInt32 ) * 8); 299 if( (((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag) 300 != (((RscFlagInst *)pDef)[ nIndex ].nFlags & Flag) ) 301 { 302 return sal_False; 303 } 304 Flag <<= 1; 305 if( !Flag ) 306 Flag = 1; 307 }; 308 } 309 else 310 return sal_False; 311 312 return sal_True; 313 } 314 315 /************************************************************************* 316 |* 317 |* RscFlag::IsSet() 318 |* 319 |* Beschreibung 320 |* Ersterstellung MM 10.04.91 321 |* Letzte Aenderung MM 10.04.91 322 |* 323 *************************************************************************/ 324 sal_Bool RscFlag::IsSet( const RSCINST & rInst, Atom nConstId ) 325 { 326 sal_uInt32 i = 0, nFlag = 0; 327 328 if( nEntries != (i = GetConstPos( nConstId )) ){ 329 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) ); 330 i = i / (sizeof( sal_uInt32 ) * 8); 331 if( ((RscFlagInst *)rInst.pData)[ i ].nFlags & nFlag ) 332 return( sal_True ); 333 else 334 return( sal_False ); 335 }; 336 return( sal_True ); 337 } 338 339 /************************************************************************* 340 |* 341 |* RscFlag::WriteSrc() 342 |* 343 |* Beschreibung 344 |* Ersterstellung MM 08.04.91 345 |* Letzte Aenderung MM 08.04.91 346 |* 347 *************************************************************************/ 348 void RscFlag::WriteSrc( const RSCINST & rInst, FILE * fOutput, 349 RscTypCont *, sal_uInt32, const char * ) 350 { 351 sal_uInt32 i = 0, Flag = 0, nIndex = 0; 352 sal_Bool bComma = sal_False; 353 354 Flag = 1; 355 for( i = 0; i < nEntries; i++ ){ 356 nIndex = i / (sizeof( sal_uInt32 ) * 8); 357 if( !( ((RscFlagInst *)rInst.pData)[ nIndex ].nDfltFlags & Flag) ){ 358 if( bComma ) 359 fprintf( fOutput, ", " ); 360 if( ((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag ) 361 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() ); 362 else{ 363 fprintf( fOutput, "not " ); 364 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() ); 365 } 366 bComma = sal_True; 367 } 368 Flag <<= 1; 369 if( !Flag ) 370 Flag = 1; 371 }; 372 } 373 374 /************************************************************************* 375 |* 376 |* RscFlag::WriteRc() 377 |* 378 |* Beschreibung 379 |* Ersterstellung MM 15.04.91 380 |* Letzte Aenderung MM 15.04.91 381 |* 382 *************************************************************************/ 383 ERRTYPE RscFlag::WriteRc( const RSCINST & rInst, RscWriteRc & aMem, 384 RscTypCont *, sal_uInt32, sal_Bool ) 385 { 386 sal_Int32 lVal = 0; 387 sal_uInt32 i = 0, Flag = 0, nIndex = 0; 388 389 Flag = 1; 390 for( i = 0; i < nEntries; i++ ){ 391 nIndex = i / (sizeof( sal_uInt32 ) * 8); 392 if( ((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag ) 393 lVal |= pVarArray[ i ].lValue; 394 395 Flag <<= 1; 396 if( !Flag ) 397 Flag = 1; 398 }; 399 400 aMem.Put( (sal_Int32)lVal ); 401 return( ERR_OK ); 402 } 403 404 /************************************************************************* 405 |* 406 |* RscClient::RscClient() 407 |* 408 |* Beschreibung 409 |* Ersterstellung MM 08.04.91 410 |* Letzte Aenderung MM 08.04.91 411 |* 412 *************************************************************************/ 413 RscClient::RscClient( Atom nId, sal_uInt32 nTypeId, RscFlag * pClass, 414 Atom nConstantId ) 415 : RscTop ( nId, nTypeId ) 416 { 417 pRefClass = pClass; 418 nConstId = nConstantId; 419 } 420 421 /************************************************************************* 422 |* 423 |* RscClient::GetClassType() 424 |* 425 |* Beschreibung 426 |* Ersterstellung MM 08.04.91 427 |* Letzte Aenderung MM 08.04.91 428 |* 429 *************************************************************************/ 430 RSCCLASS_TYPE RscClient::GetClassType() const 431 { 432 return RSCCLASS_BOOL; 433 } 434 435 /************************************************************************* 436 |* 437 |* RscClient::WriteSrc() 438 |* 439 |* Beschreibung 440 |* Ersterstellung MM 08.04.91 441 |* Letzte Aenderung MM 08.04.91 442 |* 443 *************************************************************************/ 444 void RscClient::WriteSrc( const RSCINST & rInst, FILE * fOutput, 445 RscTypCont *, sal_uInt32, const char * ) 446 { 447 if( pRefClass->IsSet( rInst, nConstId ) ) 448 fprintf( fOutput, "TRUE" ); 449 else 450 fprintf( fOutput, "FALSE" ); 451 } 452 453 /************************************************************************* 454 |* 455 |* RscClient::Create() 456 |* 457 |* Beschreibung 458 |* Ersterstellung MM 08.04.91 459 |* Letzte Aenderung MM 08.04.91 460 |* 461 *************************************************************************/ 462 RSCINST RscClient::Create( RSCINST * pInst, const RSCINST & rDflt, 463 sal_Bool bOwnClass ) 464 { 465 RSCINST aTmpI, aDfltI; 466 467 if( pInst ){ 468 aTmpI.pClass = pRefClass; 469 aTmpI.pData = pInst->pData; 470 } 471 472 if( !bOwnClass && rDflt.IsInst() ){ 473 bOwnClass = rDflt.pClass->InHierarchy( this ); 474 if( bOwnClass ){ 475 aDfltI.pClass = pRefClass; 476 aDfltI.pData = rDflt.pData; 477 } 478 } 479 480 if( pInst ) 481 aTmpI = pRefClass->CreateClient( &aTmpI, aDfltI, 482 bOwnClass, nConstId ); 483 else 484 aTmpI = pRefClass->CreateClient( NULL, aDfltI, 485 bOwnClass, nConstId ); 486 aTmpI.pClass = this; 487 488 return( aTmpI ); 489 } 490 491