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 #ifndef SW_FLDBAS_HXX 28 #define SW_FLDBAS_HXX 29 30 #include <i18npool/lang.h> 31 #include <tools/debug.hxx> 32 #include <tools/string.hxx> 33 #include "swdllapi.h" 34 #include <calbck.hxx> 35 #include <com/sun/star/uno/Any.hxx> 36 37 class SwDoc; 38 class SvStringsDtor; 39 class SvNumberFormatter; 40 41 42 /*-------------------------------------------------------------------- 43 Beschreibung: die ID's fuer die Feldtypen 44 --------------------------------------------------------------------*/ 45 46 enum RES_FIELDS 47 { 48 // Fuer die alten Dokumente muessen die Field-Which IDS erhalten bleiben !!!! 49 RES_FIELDS_BEGIN, 50 RES_DBFLD = RES_FIELDS_BEGIN, 51 RES_USERFLD, 52 RES_FILENAMEFLD, 53 RES_DBNAMEFLD, 54 RES_DATEFLD, 55 RES_TIMEFLD, 56 RES_PAGENUMBERFLD, 57 RES_AUTHORFLD, 58 RES_CHAPTERFLD, 59 RES_DOCSTATFLD, 60 RES_GETEXPFLD, 61 RES_SETEXPFLD, 62 RES_GETREFFLD, 63 RES_HIDDENTXTFLD, 64 RES_POSTITFLD, 65 RES_FIXDATEFLD, 66 RES_FIXTIMEFLD, 67 RES_REGFLD, 68 RES_VARREGFLD, 69 RES_SETREFFLD, 70 RES_INPUTFLD, 71 RES_MACROFLD, 72 RES_DDEFLD, 73 RES_TABLEFLD, 74 RES_HIDDENPARAFLD, 75 RES_DOCINFOFLD, 76 RES_TEMPLNAMEFLD, 77 RES_DBNEXTSETFLD, 78 RES_DBNUMSETFLD, 79 RES_DBSETNUMBERFLD, 80 RES_EXTUSERFLD, 81 RES_REFPAGESETFLD, 82 RES_REFPAGEGETFLD, 83 RES_INTERNETFLD, 84 RES_JUMPEDITFLD, 85 RES_SCRIPTFLD, 86 RES_DATETIMEFLD, 87 RES_AUTHORITY, //Table of authorities 88 RES_COMBINED_CHARS, 89 RES_DROPDOWN, 90 RES_FIELDS_END 91 }; 92 93 /*-------------------------------------------------------------------- 94 Beschreibung: Liste der FieldTypes am UI 95 --------------------------------------------------------------------*/ 96 97 enum SwFldTypesEnum 98 { 99 TYP_BEGIN, 100 TYP_DATEFLD = TYP_BEGIN, // 0 101 TYP_TIMEFLD, 102 TYP_FILENAMEFLD, 103 TYP_DBNAMEFLD, 104 TYP_CHAPTERFLD, 105 TYP_PAGENUMBERFLD, 106 TYP_DOCSTATFLD, 107 TYP_AUTHORFLD, 108 TYP_SETFLD, 109 TYP_GETFLD, 110 TYP_FORMELFLD, // 10 111 TYP_HIDDENTXTFLD, 112 TYP_SETREFFLD, 113 TYP_GETREFFLD, 114 TYP_DDEFLD, 115 TYP_MACROFLD, 116 TYP_INPUTFLD, 117 TYP_HIDDENPARAFLD, 118 TYP_DOCINFOFLD, 119 TYP_DBFLD, 120 TYP_USERFLD, // 20 121 TYP_POSTITFLD, 122 TYP_TEMPLNAMEFLD, 123 TYP_SEQFLD, 124 TYP_DBNEXTSETFLD, 125 TYP_DBNUMSETFLD, 126 TYP_DBSETNUMBERFLD, 127 TYP_CONDTXTFLD, 128 TYP_NEXTPAGEFLD, 129 TYP_PREVPAGEFLD, 130 TYP_EXTUSERFLD, // 30 131 TYP_FIXDATEFLD, 132 TYP_FIXTIMEFLD, 133 TYP_SETINPFLD, 134 TYP_USRINPFLD, 135 TYP_SETREFPAGEFLD, 136 TYP_GETREFPAGEFLD, 137 TYP_INTERNETFLD, 138 TYP_JUMPEDITFLD, 139 TYP_SCRIPTFLD, // 40 140 TYP_AUTHORITY, 141 TYP_COMBINED_CHARS, 142 TYP_DROPDOWN, 143 TYP_END 144 }; 145 146 147 enum SwFileNameFormat 148 { 149 FF_BEGIN, 150 FF_NAME = FF_BEGIN, 151 FF_PATHNAME, 152 FF_PATH, 153 FF_NAME_NOEXT, 154 FF_UI_NAME, 155 FF_UI_RANGE, 156 FF_END, 157 FF_FIXED = 0x8000 158 }; 159 160 enum SwVarFormat 161 { 162 VVF_CMD = 0x0010, // Kommando anzeigen 163 VVF_INVISIBLE = 0x0040, // unsichtbar 164 VVF_XXP = 0x0400, // 1234% 165 VVF_XX_XXP = 0x0800, // 1.234,56% 166 VVF_CLEAR = 0x000f, 167 168 // ab hier neue Formate 169 VVF_SYS = 0x2000, //Zahlenformat aus der Systemeinstellung 170 VVF_X = 0x2100, // 1234 171 VVF_X_X = 0x2200, // 1234,5 172 VVF_X_XX = 0x2300, // 1245,56 173 VVF_XX_X = 0x2400, // 1.234,5 174 VVF_XX_XX = 0x2500, // 1.234,56 175 VVF_XX_XXX = 0x2600, // 1.234,567 176 VVF_SYS_CUR = 0x2700, // W???hrungsformat aus der Systemeinstellung 177 VVF_CUR_X = 0x2800, // DM 1234 178 VVF_CUR_XX_XX = 0x2900, // DM 1234,56 DM 1234,00 179 VVF_CUR_XX_X0 = 0x2a00, // DM 1234,56 DM 1234,-- 180 VVF_X_CUR = 0x2b00, // 1234 DM 181 VVF_XX_XX_CUR = 0x2c00, // 1234,56 DM 1234,00 DM 182 VVF_XX_X0_CUR = 0x2d00, // 1234,56 DM 1234,-- DM 183 // Kompatibilitaet: 184 VF_CMD = VVF_CMD, 185 VF_INVISIBLE = VVF_INVISIBLE, 186 VF_XXP = VVF_XXP, 187 VF_XX_XXP = VVF_XX_XXP, 188 VF_VISIBLE = VVF_SYS, 189 VF_XX = VVF_X, 190 VF_XX_XX = VVF_XX_XX, 191 VF_XX_XX_CUR = VVF_SYS_CUR, 192 VF_CLEAR = VVF_CLEAR 193 194 }; 195 196 typedef sal_uInt16 SwGetSetExpType; 197 namespace nsSwGetSetExpType 198 { 199 const SwGetSetExpType GSE_STRING = 0x0001; // String 200 const SwGetSetExpType GSE_EXPR = 0x0002; // Expression 201 const SwGetSetExpType GSE_INP = 0x0004; // InputField 202 const SwGetSetExpType GSE_SEQ = 0x0008; // Sequence 203 const SwGetSetExpType GSE_FORMULA = 0x0010; // Formel 204 } 205 206 typedef sal_uInt16 SwExtendedSubType; 207 namespace nsSwExtendedSubType 208 { 209 const SwExtendedSubType SUB_CMD = 0x0100; // Kommando anzeigen 210 const SwExtendedSubType SUB_INVISIBLE = 0x0200; // unsichtbar 211 const SwExtendedSubType SUB_OWN_FMT = 0x0400; // SwDBField: Uebernimmt Formatierung nicht 212 // aus Datenbank 213 } 214 215 enum SwInputFieldSubType 216 { 217 INP_TXT = 0x01, 218 INP_USR = 0x02, 219 INP_VAR = 0x03 220 }; 221 222 223 enum SwUserType 224 { 225 UF_STRING = 0x01, 226 UF_EXPR = 0x02 227 }; 228 229 enum SwDateTimeSubType 230 { 231 FIXEDFLD = 1, 232 DATEFLD = 2, 233 TIMEFLD = 4 234 }; 235 236 237 extern sal_uInt16 __FAR_DATA aTypeTab[]; 238 239 /*-------------------------------------------------------------------- 240 Beschreibung: Allgemeine Tools 241 --------------------------------------------------------------------*/ 242 243 String GetResult(double nVal, sal_uInt32 nNumFmt, sal_uInt16 nLang = LANGUAGE_SYSTEM); 244 void SetErrorStr(const String& rStr); 245 //String ExpandDate(const Date& rDate, sal_uLong nFmt, sal_uInt16 nLang); 246 //String ExpandTime(const Time& rTime, sal_uLong nFmt, sal_uInt16 nLang); 247 String FormatNumber(sal_uInt16 nNum, sal_uInt32 nFormat); 248 249 /*-------------------------------------------------------------------- 250 Beschreibung: Instanzen von SwFields und Abgeleiteten kommen 0-n mal vor. 251 Zu jeder Klasse SwFields existiert 252 1 Instanz der zugehoerigen Typenklasse 253 Basisklasse aller Feldtypen ist SwFieldType 254 --------------------------------------------------------------------*/ 255 256 DBG_NAMEEX(SwFieldType) 257 258 class SW_DLLPUBLIC SwFieldType : public SwModify 259 { 260 sal_uInt16 nWhich; 261 262 friend void _FinitUI(); // um den Pointer zu loeschen! 263 static SvStringsDtor* pFldNames; 264 265 static void _GetFldName(); // legt die FldNames an, fldmgr.cxx! 266 267 protected: 268 // single argument ctors shall be explicit. 269 explicit SwFieldType( sal_uInt16 nWhichId ); 270 271 public: 272 273 #ifdef DBG_UTIL 274 virtual ~SwFieldType(); 275 #endif 276 static const String& GetTypeStr( sal_uInt16 nTypeId ); 277 278 // nur in abgeleiteten Klassen 279 virtual const String& GetName() const; 280 virtual SwFieldType* Copy() const = 0; 281 virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const; 282 virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ); 283 284 sal_uInt16 Which() const { return nWhich; } 285 286 inline void UpdateFlds() const; 287 }; 288 289 inline void SwFieldType::UpdateFlds() const 290 { 291 ((SwFieldType*)this)->ModifyNotification( 0, 0 ); 292 } 293 294 /*-------------------------------------------------------------------- 295 Beschreibung: Basisklasse aller Felder. 296 Ueber Which wird der Typ des Feldes abgefragt. 297 Ueber Expand() wird der expandierte Inhalt 298 des Feldes in Erfahrung gebracht. 299 --------------------------------------------------------------------*/ 300 301 class SW_DLLPUBLIC SwField 302 { 303 private: 304 mutable String m_Cache; /// #i85766# cached expansion (for clipboard) 305 sal_uInt16 nLang; // Immer ueber SetLanguage aendern! 306 sal_Bool bIsAutomaticLanguage; 307 sal_uInt32 nFormat; 308 309 SwFieldType* pType; 310 311 virtual String Expand() const = 0; 312 virtual SwField* Copy() const = 0; 313 314 protected: 315 void SetFormat(sal_uInt32 nSet) {nFormat = nSet;} 316 317 SwField(SwFieldType* pTyp, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM); 318 319 public: 320 virtual ~SwField(); 321 322 // Typ feststellen 323 inline SwFieldType* GetTyp() const; 324 325 // neuen Typ setzen (wird fuer das Kopieren zwischen Dokumenten benutzt) 326 virtual SwFieldType* ChgTyp( SwFieldType* ); 327 328 /** expand the field. 329 @param bCached return cached field value. 330 @remark most callers should use the cached field value. 331 this is because various fields need special handing 332 (ChangeExpansion()) to return correct values, and only 333 SwTxtFormatter::NewFldPortion() sets things up properly. 334 @return the generated text (suitable for display) 335 */ 336 String ExpandField(bool const bCached) const; 337 338 virtual String GetFieldName() const; 339 340 SwField * CopyField() const; 341 342 // ResId 343 sal_uInt16 Which() const 344 #ifndef DBG_UTIL 345 { return pType->Which(); } 346 #else 347 ; // in fldbas.cxx implementiert 348 #endif 349 350 // TYP_ID 351 sal_uInt16 GetTypeId() const; 352 virtual sal_uInt16 GetSubType() const; 353 virtual void SetSubType(sal_uInt16); 354 355 // Sprache an der Feldposition 356 inline sal_uInt16 GetLanguage() const; 357 virtual void SetLanguage(sal_uInt16 nLng); 358 359 // Parameter fuer Dialog und BASIC erfragen 360 inline sal_uInt32 GetFormat() const; 361 virtual const String& GetPar1() const; 362 virtual String GetPar2() const; 363 364 virtual String GetFormula() const; 365 366 virtual void ChangeFormat(sal_uInt32 n); 367 virtual void SetPar1(const String& rStr); 368 virtual void SetPar2(const String& rStr); 369 370 virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const; 371 virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ); 372 // hat das Feld eine Action auf dem ClickHandler ? (z.B. INetFelder,..) 373 sal_Bool HasClickHdl() const; 374 // ist es ein Fix-Feld? 375 sal_Bool IsFixed() const; 376 377 sal_Bool IsAutomaticLanguage() const { return bIsAutomaticLanguage;} 378 void SetAutomaticLanguage(sal_Bool bSet){bIsAutomaticLanguage = bSet;} 379 380 virtual String GetDescription() const; 381 }; 382 383 inline SwFieldType* SwField::GetTyp() const 384 { return pType; } 385 386 inline sal_uInt32 SwField::GetFormat() const 387 { return nFormat; } 388 389 inline sal_uInt16 SwField::GetLanguage() const 390 { return nLang; } 391 392 /*-------------------------------------------------------------------- 393 Beschreibung: Felder mit Values, die ueber der Numberformatter 394 formatiert werden muessen 395 --------------------------------------------------------------------*/ 396 397 class SwValueFieldType : public SwFieldType 398 { 399 SwDoc* pDoc; 400 sal_Bool bUseFormat; // Numberformatter verwenden 401 402 protected: 403 SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId ); 404 SwValueFieldType( const SwValueFieldType& rTyp ); 405 406 public: 407 inline SwDoc* GetDoc() const { return pDoc; } 408 inline void SetDoc(SwDoc* pNewDoc) { pDoc = pNewDoc; } 409 410 inline sal_Bool UseFormat() const { return bUseFormat; } 411 inline void EnableFormat(sal_Bool bFormat = sal_True) { bUseFormat = bFormat; } 412 413 String ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const; 414 void DoubleToString(String &rValue, const double &rVal, LanguageType eLng) const; 415 void DoubleToString(String &rValue, const double &rVal, sal_uInt32 nFmt) const; 416 }; 417 418 class SW_DLLPUBLIC SwValueField : public SwField 419 { 420 double fValue; 421 // String sExpand; 422 423 protected: 424 SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 ); 425 SwValueField( const SwValueField& rFld ); 426 427 public: 428 virtual ~SwValueField(); 429 430 virtual SwFieldType* ChgTyp( SwFieldType* ); 431 virtual void SetLanguage(sal_uInt16 nLng); 432 // os: wozu war das denn da? 433 // virtual void ChangeFormat(sal_uLong n); 434 435 inline SwDoc* GetDoc() const { return ((SwValueFieldType*)GetTyp())->GetDoc(); } 436 437 virtual double GetValue() const; 438 virtual void SetValue( const double& rVal ); 439 440 inline String ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const 441 { return ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, nFmt, nLng); } 442 443 static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt); 444 }; 445 446 class SW_DLLPUBLIC SwFormulaField : public SwValueField 447 { 448 String sFormula; 449 450 protected: 451 SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, const double fVal = 0.0 ); 452 SwFormulaField( const SwFormulaField& rFld ); 453 454 public: 455 virtual String GetFormula() const; 456 void SetFormula(const String& rStr); 457 458 void SetExpandedFormula(const String& rStr); 459 String GetExpandedFormula() const; 460 }; 461 462 #endif // SW_FLDBAS_HXX 463