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_EXPFLD_HXX 28 #define SW_EXPFLD_HXX 29 30 #include <svl/svarray.hxx> 31 #include "swdllapi.h" 32 #include <fldbas.hxx> 33 #include <cellfml.hxx> 34 35 class SfxPoolItem; 36 class SwTxtNode; 37 class SwFrm; 38 struct SwPosition; 39 class SwTxtFld; 40 class SwDoc; 41 class SwFmtFld; 42 class _SetGetExpFlds; 43 class SwEditShell; 44 45 // Vorwaertsdeklaration: besorge den "Body-TextNode", fuer Exp.Fld in Fly's 46 // Header/Footers/Footnodes 47 const SwTxtNode* GetBodyTxtNode( const SwDoc& pDoc, SwPosition& rPos, 48 const SwFrm& rFrm ); 49 // Wandlung Address -> Adressen 50 void ReplacePoint(String& sTmpName, sal_Bool bWithCommandType = sal_False); 51 52 struct _SeqFldLstElem 53 { 54 String sDlgEntry; 55 sal_uInt16 nSeqNo; 56 57 _SeqFldLstElem( const String& rStr, sal_uInt16 nNo ) 58 : sDlgEntry( rStr ), nSeqNo( nNo ) 59 {} 60 }; 61 SV_DECL_PTRARR_DEL( _SwSeqFldList, _SeqFldLstElem*, 10, 10 ) 62 63 class SW_DLLPUBLIC SwSeqFldList : public _SwSeqFldList 64 { 65 public: 66 SwSeqFldList() : _SwSeqFldList( 10, 10 ) {} 67 68 sal_Bool InsertSort( _SeqFldLstElem* ); 69 sal_Bool SeekEntry( const _SeqFldLstElem& , sal_uInt16* pPos = 0 ); 70 }; 71 72 /*-------------------------------------------------------------------- 73 Beschreibung: Ausdruck 74 --------------------------------------------------------------------*/ 75 76 class SwGetExpFieldType : public SwValueFieldType 77 { 78 public: 79 SwGetExpFieldType(SwDoc* pDoc); 80 virtual SwFieldType* Copy() const; 81 82 // ueberlagert, weil das Get-Field nicht veraendert werden kann 83 // und dann auch nicht aktualisiert werden muss. Aktualisierung 84 // erfolgt beim Aendern von Set-Werten ! 85 protected: 86 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ); 87 }; 88 89 /*-------------------------------------------------------------------- 90 Beschreibung: GetExperession 91 --------------------------------------------------------------------*/ 92 93 class SW_DLLPUBLIC SwGetExpField : public SwFormulaField 94 { 95 String sExpand; 96 sal_Bool bIsInBodyTxt; 97 sal_uInt16 nSubType; 98 99 bool bLateInitialization; // #i82544# 100 101 virtual String Expand() const; 102 virtual SwField* Copy() const; 103 104 public: 105 SwGetExpField( SwGetExpFieldType*, const String& rFormel, 106 sal_uInt16 nSubType = nsSwGetSetExpType::GSE_EXPR, sal_uLong nFmt = 0); 107 108 virtual void SetValue( const double& rVal ); 109 virtual void SetLanguage(sal_uInt16 nLng); 110 111 inline const String& GetExpStr() const; 112 inline void ChgExpStr(const String& rExpand); 113 114 // wird von der Formatierung abgefragt 115 inline sal_Bool IsInBodyTxt() const; 116 // wird von UpdateExpFlds gesetzt (dort ist die Node-Position bekannt) 117 inline void ChgBodyTxtFlag( sal_Bool bIsInBody ); 118 // fuer Felder in Header/Footer/Footnotes/Flys: 119 // (wird nur von der Formatierung aufgerufen!!) 120 void ChangeExpansion( const SwFrm&, const SwTxtFld& ); 121 122 virtual String GetFieldName() const; 123 124 // Die Formel aendern 125 virtual String GetPar2() const; 126 virtual void SetPar2(const String& rStr); 127 128 virtual sal_uInt16 GetSubType() const; 129 virtual void SetSubType(sal_uInt16 nType); 130 virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const; 131 virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ); 132 133 static sal_uInt16 GetReferenceTextPos( const SwFmtFld& rFmt, SwDoc& rDoc); 134 // #i82544# 135 void SetLateInitialization() { bLateInitialization = true;} 136 }; 137 138 inline void SwGetExpField::ChgExpStr(const String& rExpand) 139 { sExpand = rExpand;} 140 141 inline const String& SwGetExpField::GetExpStr() const 142 { return sExpand; } 143 144 // wird von der Formatierung abgefragt 145 inline sal_Bool SwGetExpField::IsInBodyTxt() const 146 { return bIsInBodyTxt; } 147 148 // wird von UpdateExpFlds gesetzt (dort ist die Node-Position bekannt) 149 inline void SwGetExpField::ChgBodyTxtFlag( sal_Bool bIsInBody ) 150 { bIsInBodyTxt = bIsInBody; } 151 152 153 /*-------------------------------------------------------------------- 154 Beschreibung: Ausdruck setzen 155 --------------------------------------------------------------------*/ 156 157 class SwSetExpField; 158 159 class SW_DLLPUBLIC SwSetExpFieldType : public SwValueFieldType 160 { 161 String sName; 162 const SwNode* pOutlChgNd; 163 String sDelim; 164 sal_uInt16 nType; 165 sal_uInt8 nLevel; 166 sal_Bool bDeleted; 167 168 protected: 169 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ); 170 171 public: 172 SwSetExpFieldType( SwDoc* pDoc, const String& rName, 173 sal_uInt16 nType = nsSwGetSetExpType::GSE_EXPR ); 174 virtual SwFieldType* Copy() const; 175 virtual const String& GetName() const; 176 177 inline void SetType(sal_uInt16 nTyp); 178 inline sal_uInt16 GetType() const; 179 180 void SetSeqFormat(sal_uLong nFormat); 181 sal_uLong GetSeqFormat(); 182 183 sal_Bool IsDeleted() const { return bDeleted; } 184 void SetDeleted( sal_Bool b ) { bDeleted = b; } 185 186 // ueberlagert, weil das Set-Field selbst dafuer sorgt, das 187 // es aktualisiert wird. 188 inline const String& GetSetRefName() const; 189 190 sal_uInt16 SetSeqRefNo( SwSetExpField& rFld ); 191 192 sal_uInt16 GetSeqFldList( SwSeqFldList& rList ); 193 String MakeSeqName( sal_uInt16 nSeqNo ); 194 195 // Seqencefelder ggfs. Kapitelweise numerieren 196 // sal_Unicode GetDelimiter() const { return cDelim; } 197 // void SetDelimiter( sal_Unicode c ) { cDelim = c; } 198 const String& GetDelimiter() const { return sDelim; } 199 void SetDelimiter( const String& s ) { sDelim = s; } 200 sal_uInt8 GetOutlineLvl() const { return nLevel; } 201 void SetOutlineLvl( sal_uInt8 n ) { nLevel = n; } 202 void SetChapter( SwSetExpField& rFld, const SwNode& rNd ); 203 // Member nur fuers SwDoc::UpdateExpFld - wird nur waehrend der Laufzeit 204 // von SequencefeldTypen benoetigt!!! 205 const SwNode* GetOutlineChgNd() const { return pOutlChgNd; } 206 void SetOutlineChgNd( const SwNode* p ) { pOutlChgNd = p; } 207 208 virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const; 209 virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ); 210 }; 211 212 inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp ) 213 { 214 nType = nTyp; 215 EnableFormat( !(nType & (nsSwGetSetExpType::GSE_SEQ|nsSwGetSetExpType::GSE_STRING))); 216 } 217 218 inline sal_uInt16 SwSetExpFieldType::GetType() const 219 { return nType; } 220 221 inline const String& SwSetExpFieldType::GetSetRefName() const 222 { return sName; } 223 224 225 /*-------------------------------------------------------------------- 226 Beschreibung: Ausdruck 227 --------------------------------------------------------------------*/ 228 229 class SW_DLLPUBLIC SwSetExpField : public SwFormulaField 230 { 231 String sExpand; 232 String aPText; 233 String aSeqText; 234 sal_Bool bInput; 235 sal_uInt16 nSeqNo; 236 sal_uInt16 nSubType; 237 238 virtual String Expand() const; 239 virtual SwField* Copy() const; 240 241 public: 242 SwSetExpField(SwSetExpFieldType*, const String& rFormel, sal_uLong nFmt = 0); 243 244 virtual void SetValue( const double& rVal ); 245 246 inline const String& GetExpStr() const; 247 248 inline void ChgExpStr( const String& rExpand ); 249 250 inline void SetPromptText(const String& rStr); 251 inline const String& GetPromptText() const; 252 253 inline void SetInputFlag(sal_Bool bInp); 254 inline sal_Bool GetInputFlag() const; 255 256 virtual String GetFieldName() const; 257 258 virtual sal_uInt16 GetSubType() const; 259 virtual void SetSubType(sal_uInt16 nType); 260 261 inline sal_Bool IsSequenceFld() const; 262 263 // fuer SequenceFelder - logische Nummer 264 inline void SetSeqNumber( sal_uInt16 n ) { nSeqNo = n; } 265 inline sal_uInt16 GetSeqNumber() const { return nSeqNo; } 266 267 // Der Name nur erfragen 268 virtual const String& GetPar1() const; 269 270 // Die Formel 271 virtual String GetPar2() const; 272 virtual void SetPar2(const String& rStr); 273 virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const; 274 virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ); 275 }; 276 277 inline const String& SwSetExpField::GetExpStr() const 278 { return sExpand; } 279 280 inline void SwSetExpField::ChgExpStr( const String& rExpand ) 281 { sExpand = rExpand; } 282 283 inline void SwSetExpField::SetPromptText(const String& rStr) 284 { aPText = rStr; } 285 286 inline const String& SwSetExpField::GetPromptText() const 287 { return aPText; } 288 289 inline void SwSetExpField::SetInputFlag(sal_Bool bInp) 290 { bInput = bInp; } 291 292 inline sal_Bool SwSetExpField::GetInputFlag() const 293 { return bInput; } 294 295 inline sal_Bool SwSetExpField::IsSequenceFld() const 296 { return 0 != (nsSwGetSetExpType::GSE_SEQ & ((SwSetExpFieldType*)GetTyp())->GetType()); } 297 298 /*-------------------------------------------------------------------- 299 Beschreibung: Eingabe im Text/Variable setzen 300 --------------------------------------------------------------------*/ 301 302 class SwInputFieldType : public SwFieldType 303 { 304 SwDoc* pDoc; 305 public: 306 SwInputFieldType( SwDoc* pDoc ); 307 308 virtual SwFieldType* Copy() const; 309 310 SwDoc* GetDoc() const { return pDoc; } 311 }; 312 313 /*-------------------------------------------------------------------- 314 Beschreibung: Eingabefeld 315 --------------------------------------------------------------------*/ 316 317 class SW_DLLPUBLIC SwInputField : public SwField 318 { 319 String aContent; 320 String aPText; 321 String aHelp; 322 String aToolTip; 323 sal_uInt16 nSubType; 324 325 virtual String Expand() const; 326 virtual SwField* Copy() const; 327 328 public: 329 // Direkte Eingabe ueber Dialog alten Wert loeschen 330 SwInputField(SwInputFieldType*, const String& rContent , 331 const String& rPrompt, sal_uInt16 nSubType = 0, 332 sal_uLong nFmt = 0); 333 334 virtual String GetFieldName() const; 335 336 // Content 337 virtual const String& GetPar1() const; 338 virtual void SetPar1(const String& rStr); 339 340 // aPromptText 341 virtual String GetPar2() const; 342 virtual void SetPar2(const String& rStr); 343 344 virtual String GetHelp() const; 345 virtual void SetHelp(const String & rStr); 346 347 virtual String GetToolTip() const; 348 virtual void SetToolTip(const String & rStr); 349 350 virtual sal_Bool isFormField() const; 351 352 virtual sal_uInt16 GetSubType() const; 353 virtual void SetSubType(sal_uInt16 nSub); 354 virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const; 355 virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ); 356 }; 357 358 /*-------------------------------------------------------------------- 359 Description: Sorted list of input fields and DropDown fields 360 --------------------------------------------------------------------*/ 361 362 class SwInputFieldList 363 { 364 public: 365 SwInputFieldList( SwEditShell* pShell, sal_Bool bBuildTmpLst = sal_False ); 366 ~SwInputFieldList(); 367 368 sal_uInt16 Count() const; 369 SwField* GetField(sal_uInt16 nId); 370 371 void GotoFieldPos(sal_uInt16 nId); 372 void PushCrsr(); 373 void PopCrsr(); 374 375 // vergleiche TmpLst mit akt Feldern. Alle neue kommen in die SortLst 376 // damit sie geupdatet werden koennen. Returnt die Anzahl. 377 // (Fuer Textbausteine: nur seine Input-Felder aktualisieren) 378 sal_uInt16 BuildSortLst(); 379 380 // Alle unselektierten Felder aus Liste entfernen 381 void RemoveUnselectedFlds(); 382 383 private: 384 SwEditShell* pSh; 385 _SetGetExpFlds* pSrtLst; 386 SvPtrarr aTmpLst; 387 }; 388 389 /*-------------------------------------------------------------------- 390 Beschreibung: Tabellen-Formelfeld 391 (Implementierung steht in tblcalc.cxx) 392 --------------------------------------------------------------------*/ 393 394 class SwTblFieldType : public SwValueFieldType 395 { 396 public: 397 SwTblFieldType(SwDoc* pDocPtr); 398 virtual SwFieldType* Copy() const; 399 }; 400 401 402 // MSC will den hier nicht 403 //typedef void (SwField:: *FnScanFormel)( const SwTable&, String&, 404 // String&, String* = 0, void* = 0 ); 405 406 407 class SwTblField : public SwValueField, public SwTableFormula 408 { 409 String sExpand; 410 sal_uInt16 nSubType; 411 412 virtual String Expand() const; 413 virtual SwField* Copy() const; 414 415 // suche den TextNode, in dem das Feld steht 416 virtual const SwNode* GetNodeOfFormula() const; 417 418 String GetCommand(); 419 420 public: 421 SwTblField( SwTblFieldType*, const String& rFormel, 422 sal_uInt16 nSubType = 0, sal_uLong nFmt = 0); 423 424 virtual void SetValue( const double& rVal ); 425 virtual sal_uInt16 GetSubType() const; 426 virtual void SetSubType(sal_uInt16 nType); 427 428 const String& GetExpStr() const { return sExpand; } 429 void ChgExpStr(const String& rStr) { sExpand = rStr; } 430 431 // berechne sich selbst 432 void CalcField( SwTblCalcPara& rCalcPara ); 433 434 virtual String GetFieldName() const; 435 436 // Die Formel 437 virtual String GetPar2() const; 438 virtual void SetPar2(const String& rStr); 439 virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const; 440 virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ); 441 }; 442 443 444 #endif // SW_EXPFLD_HXX 445