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