LibreOffice Module sw (master)  1
dbfld.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <float.h>
21 #include <o3tl/any.hxx>
22 #include <sfx2/app.hxx>
23 #include <svl/zforlist.hxx>
24 #include <svx/pageitem.hxx>
26 #include <com/sun/star/sdbc/DataType.hpp>
27 #include <fmtfld.hxx>
28 #include <txtfld.hxx>
29 #include <doc.hxx>
31 #include <docary.hxx>
32 #include <frame.hxx>
33 #include <fldbas.hxx>
34 #include <pam.hxx>
35 #include <ndtxt.hxx>
36 #include <dbfld.hxx>
37 #include <dbmgr.hxx>
38 #include <docfld.hxx>
39 #include <expfld.hxx>
40 #include <txtatr.hxx>
41 #include <unofldmid.h>
42 #include <calbck.hxx>
43 
44 using namespace ::com::sun::star::sdbc;
45 using namespace ::com::sun::star;
46 
48 static OUString lcl_DBSeparatorConvert(const OUString& aContent)
49 {
50  return aContent.replaceAll(OUStringLiteral1(DB_DELIM), ".");
51 }
52 
53 // database field type
54 
55 SwDBFieldType::SwDBFieldType(SwDoc* pDocPtr, const OUString& rNam, const SwDBData& rDBData ) :
57  m_aDBData(rDBData),
58  m_sName(rNam),
59  m_sColumn(rNam),
60  m_nRefCnt(0)
61 {
62  if(!m_aDBData.sDataSource.isEmpty() || !m_aDBData.sCommand.isEmpty())
63  {
65  + OUStringLiteral1(DB_DELIM)
67  + OUStringLiteral1(DB_DELIM)
68  + m_sName;
69  }
70 }
71 
73 {
74 }
75 
76 std::unique_ptr<SwFieldType> SwDBFieldType::Copy() const
77 {
78  return std::make_unique<SwDBFieldType>(GetDoc(), m_sColumn, m_aDBData);
79 }
80 
81 OUString SwDBFieldType::GetName() const
82 {
83  return m_sName;
84 }
85 
87 {
88  OSL_ENSURE(m_nRefCnt > 0, "RefCount < 0!");
89 
90  if (--m_nRefCnt <= 0)
91  {
92  size_t nPos = 0;
93  for (auto const & pFieldType : *GetDoc()->getIDocumentFieldsAccess().GetFieldTypes())
94  {
95  if (pFieldType.get() == this)
96  break;
97  ++nPos;
98  }
99  if (nPos < GetDoc()->getIDocumentFieldsAccess().GetFieldTypes()->size())
100  {
102  delete this;
103  }
104  }
105 }
106 
107 void SwDBFieldType::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
108 {
109  switch( nWhichId )
110  {
111  case FIELD_PROP_PAR1:
112  rAny <<= m_aDBData.sDataSource;
113  break;
114  case FIELD_PROP_PAR2:
115  rAny <<= m_aDBData.sCommand;
116  break;
117  case FIELD_PROP_PAR3:
118  rAny <<= m_sColumn;
119  break;
120  case FIELD_PROP_SHORT1:
121  rAny <<= m_aDBData.nCommandType;
122  break;
123  default:
124  assert(false);
125  }
126 }
127 
128 void SwDBFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
129 {
130  switch( nWhichId )
131  {
132  case FIELD_PROP_PAR1:
133  rAny >>= m_aDBData.sDataSource;
134  break;
135  case FIELD_PROP_PAR2:
136  rAny >>= m_aDBData.sCommand;
137  break;
138  case FIELD_PROP_PAR3:
139  {
140  OUString sTmp;
141  rAny >>= sTmp;
142  if( sTmp != m_sColumn )
143  {
144  m_sColumn = sTmp;
146  SwFormatField* pFormatField = aIter.First();
147  while(pFormatField)
148  {
149  // field in Undo?
150  SwTextField *pTextField = pFormatField->GetTextField();
151  if(pTextField && pTextField->GetTextNode().GetNodes().IsDocNodes() )
152  {
153  SwDBField* pDBField = static_cast<SwDBField*>(pFormatField->GetField());
154  pDBField->ClearInitialized();
155  pDBField->InitContent();
156  }
157  pFormatField = aIter.Next();
158  }
159  }
160  }
161  break;
162  case FIELD_PROP_SHORT1:
163  rAny >>= m_aDBData.nCommandType;
164  break;
165  default:
166  assert(false);
167  }
168 }
169 
170 // database field
171 
172 SwDBField::SwDBField(SwDBFieldType* pTyp, sal_uInt32 nFormat)
173  : SwValueField(pTyp, nFormat),
174  m_nSubType(0),
175  m_bIsInBodyText(true),
176  m_bValidValue(false),
177  m_bInitialized(false)
178 {
179  if (GetTyp())
180  static_cast<SwDBFieldType*>(GetTyp())->AddRef();
181  InitContent();
182 }
183 
185 {
186  if (GetTyp())
187  static_cast<SwDBFieldType*>(GetTyp())->ReleaseRef();
188 }
189 
191 {
192  if (!IsInitialized())
193  {
194  m_aContent = "<" + static_cast<const SwDBFieldType*>(GetTyp())->GetColumnName() + ">";
195  }
196 }
197 
198 void SwDBField::InitContent(const OUString& rExpansion)
199 {
200  if (rExpansion.startsWith("<") && rExpansion.endsWith(">"))
201  {
202  const OUString sColumn( rExpansion.copy( 1, rExpansion.getLength() - 2 ) );
203  if( ::GetAppCmpStrIgnore().isEqual( sColumn,
204  static_cast<SwDBFieldType *>(GetTyp())->GetColumnName() ))
205  {
206  InitContent();
207  return;
208  }
209  }
210  SetExpansion( rExpansion );
211 }
212 
213 OUString SwDBField::ExpandImpl(SwRootFrame const*const) const
214 {
217  return OUString();
218 }
219 
220 std::unique_ptr<SwField> SwDBField::Copy() const
221 {
222  std::unique_ptr<SwDBField> pTmp(new SwDBField(static_cast<SwDBFieldType*>(GetTyp()), GetFormat()));
223  pTmp->m_aContent = m_aContent;
224  pTmp->m_bIsInBodyText = m_bIsInBodyText;
225  pTmp->m_bValidValue = m_bValidValue;
226  pTmp->m_bInitialized = m_bInitialized;
227  pTmp->m_nSubType = m_nSubType;
228  pTmp->SetValue(GetValue());
229  pTmp->m_sFieldCode = m_sFieldCode;
230 
231  return std::unique_ptr<SwField>(pTmp.release());
232 }
233 
234 OUString SwDBField::GetFieldName() const
235 {
236  const OUString rDBName = static_cast<SwDBFieldType*>(GetTyp())->GetName();
237 
238  OUString sContent( rDBName.getToken(0, DB_DELIM) );
239 
240  if (sContent.getLength() > 1)
241  {
242  sContent += OUStringLiteral1(DB_DELIM)
243  + rDBName.getToken(1, DB_DELIM)
244  + OUStringLiteral1(DB_DELIM)
245  + rDBName.getToken(2, DB_DELIM);
246  }
247  return lcl_DBSeparatorConvert(sContent);
248 }
249 
250 void SwDBField::ChgValue( double d, bool bVal )
251 {
252  m_bValidValue = bVal;
253  SetValue(d);
254 
255  if( m_bValidValue )
256  m_aContent = static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(d, GetFormat(), GetLanguage());
257 }
258 
260 {
261  SwFieldType* pOld = SwValueField::ChgTyp( pNewType );
262 
263  static_cast<SwDBFieldType*>(pNewType)->AddRef();
264  static_cast<SwDBFieldType*>(pOld)->ReleaseRef();
265 
266  return pOld;
267 }
268 
269 bool SwDBField::FormatValue( SvNumberFormatter const * pDocFormatter, OUString const &aString, sal_uInt32 nFormat,
270  double &aNumber, sal_Int32 nColumnType, SwDBField *pField )
271 {
272  bool bValidValue = false;
273 
274  if( DBL_MAX != aNumber )
275  {
276  if( DataType::DATE == nColumnType || DataType::TIME == nColumnType ||
277  DataType::TIMESTAMP == nColumnType )
278  {
279  Date aStandard( 1, 1, 1900 );
280  if( pDocFormatter->GetNullDate() != aStandard )
281  aNumber += (aStandard - pDocFormatter->GetNullDate());
282  }
283  bValidValue = true;
284  if( pField )
285  pField->SetValue( aNumber );
286  }
287  else
288  {
289  SwSbxValue aVal;
290  aVal.PutString( aString );
291 
292  if (aVal.IsNumeric())
293  {
294  if( pField )
295  pField->SetValue(aVal.GetDouble());
296  else
297  aNumber = aVal.GetDouble();
298 
299  if (nFormat && nFormat != SAL_MAX_UINT32 && !pDocFormatter->IsTextFormat(nFormat))
300  bValidValue = true; // because of bug #60339 not for all strings
301  }
302  else
303  {
304  // if string length > 0 then true, else false
305  if( pField )
306  pField->SetValue(aString.isEmpty() ? 0 : 1);
307  else
308  aNumber = aString.isEmpty() ? 0 : 1;
309  }
310  }
311 
312  return bValidValue;
313 }
314 
317 {
318  SwDBManager* pMgr = GetDoc()->GetDBManager();
319 
320  // first delete
321  m_bValidValue = false;
322  double nValue = DBL_MAX;
323  const SwDBData& aTmpData = GetDBData();
324 
325  if(!pMgr || !pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, true))
326  return ;
327 
328  sal_uInt32 nFormat = 0;
329 
330  // search corresponding column name
331  OUString aColNm( static_cast<SwDBFieldType*>(GetTyp())->GetColumnName() );
332 
333  SvNumberFormatter* pDocFormatter = GetDoc()->GetNumberFormatter();
334  pMgr->GetMergeColumnCnt(aColNm, GetLanguage(), m_aContent, &nValue);
336  {
337  nFormat = pMgr->GetColumnFormat( aTmpData.sDataSource, aTmpData.sCommand,
338  aColNm, pDocFormatter, GetLanguage() );
339  SetFormat( nFormat );
340  }
341 
342  sal_Int32 nColumnType = nValue == DBL_MAX
343  ? 0
344  : pMgr->GetColumnType(aTmpData.sDataSource, aTmpData.sCommand, aColNm);
345 
346  m_bValidValue = FormatValue( pDocFormatter, m_aContent, nFormat, nValue, nColumnType, this );
347 
348  if( DBL_MAX != nValue )
349  m_aContent = static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(nValue, GetFormat(), GetLanguage());
350 
351  m_bInitialized = true;
352 }
353 
355 OUString SwDBField::GetPar1() const
356 {
357  return static_cast<const SwDBFieldType*>(GetTyp())->GetName();
358 }
359 
360 sal_uInt16 SwDBField::GetSubType() const
361 {
362  return m_nSubType;
363 }
364 
365 void SwDBField::SetSubType(sal_uInt16 nType)
366 {
367  m_nSubType = nType;
368 }
369 
370 bool SwDBField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
371 {
372  switch( nWhichId )
373  {
374  case FIELD_PROP_BOOL1:
376  break;
377  case FIELD_PROP_BOOL2:
379  break;
380  case FIELD_PROP_FORMAT:
381  rAny <<= static_cast<sal_Int32>(GetFormat());
382  break;
383  case FIELD_PROP_PAR1:
384  rAny <<= m_aContent;
385  break;
386  case FIELD_PROP_PAR2:
387  rAny <<= m_sFieldCode;
388  break;
389  default:
390  OSL_FAIL("illegal property");
391  }
392  return true;
393 }
394 
395 bool SwDBField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
396 {
397  switch( nWhichId )
398  {
399  case FIELD_PROP_BOOL1:
400  if( *o3tl::doAccess<bool>(rAny) )
402  else
404  break;
405  case FIELD_PROP_BOOL2:
406  {
407  sal_uInt16 nSubTyp = GetSubType();
408  bool bVisible = false;
409  if(!(rAny >>= bVisible))
410  return false;
411  if(bVisible)
413  else
415  SetSubType(nSubTyp);
416  //invalidate text node
417  if(GetTyp())
418  {
420  SwFormatField* pFormatField = aIter.First();
421  while(pFormatField)
422  {
423  SwTextField *pTextField = pFormatField->GetTextField();
424  if(pTextField && static_cast<SwDBField*>(pFormatField->GetField()) == this )
425  {
426  //notify the change
427  pTextField->NotifyContentChange(*pFormatField);
428  break;
429  }
430  pFormatField = aIter.Next();
431  }
432  }
433  }
434  break;
435  case FIELD_PROP_FORMAT:
436  {
437  sal_Int32 nTemp = 0;
438  rAny >>= nTemp;
439  SetFormat(nTemp);
440  }
441  break;
442  case FIELD_PROP_PAR1:
443  rAny >>= m_aContent;
444  break;
445  case FIELD_PROP_PAR2:
446  rAny >>= m_sFieldCode;
447  break;
448  default:
449  OSL_FAIL("illegal property");
450  }
451  return true;
452 }
453 
454 // base class for all further database fields
455 
456 SwDBNameInfField::SwDBNameInfField(SwFieldType* pTyp, const SwDBData& rDBData, sal_uInt32 nFormat) :
457  SwField(pTyp, nFormat),
458  m_aDBData(rDBData),
459  m_nSubType(0)
460 {
461 }
462 
464 {
465  SwDBData aRet;
466  if(!m_aDBData.sDataSource.isEmpty())
467  aRet = m_aDBData;
468  else
469  aRet = pDoc->GetDBData();
470  return aRet;
471 }
472 
474 {
475  m_aDBData = rDBData;
476 }
477 
479 {
480  OUString sStr( SwField::GetFieldName() );
481  if (!m_aDBData.sDataSource.isEmpty())
482  {
483  sStr += ":"
485  + OUStringLiteral1(DB_DELIM)
487  }
488  return lcl_DBSeparatorConvert(sStr);
489 }
490 
491 bool SwDBNameInfField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
492 {
493  switch( nWhichId )
494  {
495  case FIELD_PROP_PAR1:
496  rAny <<= m_aDBData.sDataSource;
497  break;
498  case FIELD_PROP_PAR2:
499  rAny <<= m_aDBData.sCommand;
500  break;
501  case FIELD_PROP_SHORT1:
502  rAny <<= m_aDBData.nCommandType;
503  break;
504  case FIELD_PROP_BOOL2:
506  break;
507  default:
508  assert(false);
509  }
510  return true;
511 }
512 
513 bool SwDBNameInfField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
514 {
515  switch( nWhichId )
516  {
517  case FIELD_PROP_PAR1:
518  rAny >>= m_aDBData.sDataSource;
519  break;
520  case FIELD_PROP_PAR2:
521  rAny >>= m_aDBData.sCommand;
522  break;
523  case FIELD_PROP_SHORT1:
524  rAny >>= m_aDBData.nCommandType;
525  break;
526  case FIELD_PROP_BOOL2:
527  {
528  sal_uInt16 nSubTyp = GetSubType();
529  bool bVisible = false;
530  if(!(rAny >>= bVisible))
531  return false;
532  if(bVisible)
534  else
536  SetSubType(nSubTyp);
537  }
538  break;
539  default:
540  assert(false);
541  }
542  return true;
543 }
544 
546 {
547  return m_nSubType;
548 }
549 
550 void SwDBNameInfField::SetSubType(sal_uInt16 nType)
551 {
552  m_nSubType = nType;
553 }
554 
555 // next dataset
556 
559 {
560 }
561 
562 std::unique_ptr<SwFieldType> SwDBNextSetFieldType::Copy() const
563 {
564  return std::make_unique<SwDBNextSetFieldType>();
565 }
566 
567 // SwDBSetField
568 
570  const OUString& rCond,
571  const SwDBData& rDBData) :
572  SwDBNameInfField(pTyp, rDBData), m_aCond(rCond), m_bCondValid(true)
573 {}
574 
575 OUString SwDBNextSetField::ExpandImpl(SwRootFrame const*const) const
576 {
577  return OUString();
578 }
579 
580 std::unique_ptr<SwField> SwDBNextSetField::Copy() const
581 {
582  std::unique_ptr<SwDBNextSetField> pTmp(new SwDBNextSetField(static_cast<SwDBNextSetFieldType*>(GetTyp()),
583  m_aCond, GetDBData()));
584  pTmp->SetSubType(GetSubType());
585  pTmp->m_bCondValid = m_bCondValid;
586  return std::unique_ptr<SwField>(pTmp.release());
587 }
588 
590 {
591  SwDBManager* pMgr = pDoc->GetDBManager();
592  const SwDBData& rData = GetDBData();
593  if( !m_bCondValid ||
594  !pMgr || !pMgr->IsDataSourceOpen(rData.sDataSource, rData.sCommand, false))
595  return ;
596  pMgr->ToNextRecord(rData.sDataSource, rData.sCommand);
597 }
598 
601 {
602  return m_aCond;
603 }
604 
606 void SwDBNextSetField::SetPar1(const OUString& rStr)
607 {
608  m_aCond = rStr;
609 }
610 
611 bool SwDBNextSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
612 {
613  bool bRet = true;
614  switch( nWhichId )
615  {
616  case FIELD_PROP_PAR3:
617  rAny <<= m_aCond;
618  break;
619  default:
620  bRet = SwDBNameInfField::QueryValue( rAny, nWhichId );
621  }
622  return bRet;
623 }
624 
625 bool SwDBNextSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
626 {
627  bool bRet = true;
628  switch( nWhichId )
629  {
630  case FIELD_PROP_PAR3:
631  rAny >>= m_aCond;
632  break;
633  default:
634  bRet = SwDBNameInfField::PutValue( rAny, nWhichId );
635  }
636  return bRet;
637 }
638 
639 // dataset with certain ID
640 
643 {
644 }
645 
646 std::unique_ptr<SwFieldType> SwDBNumSetFieldType::Copy() const
647 {
648  return std::make_unique<SwDBNumSetFieldType>();
649 }
650 
652  const OUString& rCond,
653  const OUString& rDBNum,
654  const SwDBData& rDBData) :
655  SwDBNameInfField(pTyp, rDBData),
656  m_aCond(rCond),
657  m_aPar2(rDBNum),
658  m_bCondValid(true)
659 {}
660 
661 OUString SwDBNumSetField::ExpandImpl(SwRootFrame const*const) const
662 {
663  return OUString();
664 }
665 
666 std::unique_ptr<SwField> SwDBNumSetField::Copy() const
667 {
668  std::unique_ptr<SwDBNumSetField> pTmp(new SwDBNumSetField(static_cast<SwDBNumSetFieldType*>(GetTyp()),
669  m_aCond, m_aPar2, GetDBData()));
670  pTmp->m_bCondValid = m_bCondValid;
671  pTmp->SetSubType(GetSubType());
672  return std::unique_ptr<SwField>(pTmp.release());
673 }
674 
676 {
677  SwDBManager* pMgr = pDoc->GetDBManager();
678  const SwDBData& aTmpData = GetDBData();
679 
680  if( m_bCondValid && pMgr && pMgr->IsInMerge() &&
681  pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, true))
682  { // condition OK -> adjust current Set
683  pMgr->ToRecordId(std::max(static_cast<sal_uInt16>(m_aPar2.toInt32()), sal_uInt16(1))-1);
684  }
685 }
686 
688 OUString SwDBNumSetField::GetPar1() const
689 {
690  return m_aCond;
691 }
692 
694 void SwDBNumSetField::SetPar1(const OUString& rStr)
695 {
696  m_aCond = rStr;
697 }
698 
700 OUString SwDBNumSetField::GetPar2() const
701 {
702  return m_aPar2;
703 }
704 
706 void SwDBNumSetField::SetPar2(const OUString& rStr)
707 {
708  m_aPar2 = rStr;
709 }
710 
711 bool SwDBNumSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
712 {
713  bool bRet = true;
714  switch( nWhichId )
715  {
716  case FIELD_PROP_PAR3:
717  rAny <<= m_aCond;
718  break;
719  case FIELD_PROP_FORMAT:
720  rAny <<= m_aPar2.toInt32();
721  break;
722  default:
723  bRet = SwDBNameInfField::QueryValue(rAny, nWhichId );
724  }
725  return bRet;
726 }
727 
728 bool SwDBNumSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
729 {
730  bool bRet = true;
731  switch( nWhichId )
732  {
733  case FIELD_PROP_PAR3:
734  rAny >>= m_aCond;
735  break;
736  case FIELD_PROP_FORMAT:
737  {
738  sal_Int32 nVal = 0;
739  rAny >>= nVal;
740  m_aPar2 = OUString::number(nVal);
741  }
742  break;
743  default:
744  bRet = SwDBNameInfField::PutValue(rAny, nWhichId );
745  }
746  return bRet;
747 }
748 
751 {
752  m_pDoc = pDocument;
753 }
754 
756 {
757  const SwDBData aData = m_pDoc->GetDBData();
758  return aData.sDataSource + "." + aData.sCommand;
759 }
760 
761 std::unique_ptr<SwFieldType> SwDBNameFieldType::Copy() const
762 {
763  return std::make_unique<SwDBNameFieldType>(m_pDoc);
764 }
765 
766 // name of the connected database
767 
769  : SwDBNameInfField(pTyp, rDBData, 0)
770 {}
771 
772 OUString SwDBNameField::ExpandImpl(SwRootFrame const*const) const
773 {
775  return static_cast<SwDBNameFieldType*>(GetTyp())->Expand();
776  return OUString();
777 }
778 
779 std::unique_ptr<SwField> SwDBNameField::Copy() const
780 {
781  std::unique_ptr<SwDBNameField> pTmp(new SwDBNameField(static_cast<SwDBNameFieldType*>(GetTyp()), GetDBData()));
782  pTmp->ChangeFormat(GetFormat());
783  pTmp->SetLanguage(GetLanguage());
784  pTmp->SetSubType(GetSubType());
785  return std::unique_ptr<SwField>(pTmp.release());
786 }
787 
788 bool SwDBNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
789 {
790  return SwDBNameInfField::QueryValue(rAny, nWhichId );
791 }
792 
793 bool SwDBNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
794 {
795  return SwDBNameInfField::PutValue(rAny, nWhichId );
796 }
797 
800 {
801 }
802 
803 std::unique_ptr<SwFieldType> SwDBSetNumberFieldType::Copy() const
804 {
805  return std::make_unique<SwDBSetNumberFieldType>();
806 }
807 
808 // set-number of the connected database
809 
811  const SwDBData& rDBData,
812  sal_uInt32 nFormat)
813  : SwDBNameInfField(pTyp, rDBData, nFormat), m_nNumber(0)
814 {}
815 
816 OUString SwDBSetNumberField::ExpandImpl(SwRootFrame const*const) const
817 {
819  return OUString();
820  return FormatNumber(m_nNumber, static_cast<SvxNumType>(GetFormat()));
821 }
822 
824 {
825  SwDBManager* pMgr = pDoc->GetDBManager();
826 
827  const SwDBData& aTmpData = GetDBData();
828  if (!pMgr || !pMgr->IsInMerge() ||
829  !pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, false))
830  return;
831  m_nNumber = pMgr->GetSelectedRecordId();
832 }
833 
834 std::unique_ptr<SwField> SwDBSetNumberField::Copy() const
835 {
836  std::unique_ptr<SwDBSetNumberField> pTmp(
837  new SwDBSetNumberField(static_cast<SwDBSetNumberFieldType*>(GetTyp()), GetDBData(), GetFormat()));
838  pTmp->SetLanguage(GetLanguage());
839  pTmp->SetSetNumber(m_nNumber);
840  pTmp->SetSubType(GetSubType());
841  return std::unique_ptr<SwField>(pTmp.release());
842 }
843 
844 bool SwDBSetNumberField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
845 {
846  bool bRet = true;
847  switch( nWhichId )
848  {
849  case FIELD_PROP_USHORT1:
850  rAny <<= static_cast<sal_Int16>(GetFormat());
851  break;
852  case FIELD_PROP_FORMAT:
853  rAny <<= m_nNumber;
854  break;
855  default:
856  bRet = SwDBNameInfField::QueryValue( rAny, nWhichId );
857  }
858  return bRet;
859 }
860 
861 bool SwDBSetNumberField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
862 {
863  bool bRet = true;
864  switch( nWhichId )
865  {
866  case FIELD_PROP_USHORT1:
867  {
868  sal_Int16 nSet = 0;
869  rAny >>= nSet;
870  if(nSet < css::style::NumberingType::NUMBER_NONE )
871  SetFormat(nSet);
872  }
873  break;
874  case FIELD_PROP_FORMAT:
875  rAny >>= m_nNumber;
876  break;
877  default:
878  bRet = SwDBNameInfField::PutValue( rAny, nWhichId );
879  }
880  return bRet;
881 }
882 
883 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool m_bInitialized
Definition: dbfld.hxx:63
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:233
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:711
const ::utl::TransliterationWrapper & GetAppCmpStrIgnore()
Definition: init.cxx:834
void ChgValue(double d, bool bVal)
For calculations in expressions.
Definition: dbfld.cxx:250
sal_Int32 nCommandType
Definition: swdbdata.hxx:32
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: dbfld.cxx:803
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:491
const SwField * GetField() const
Definition: fmtfld.hxx:71
SwDBData m_aDBData
Definition: dbfld.hxx:123
void Evaluate(SwDoc const *)
Definition: dbfld.cxx:675
bool m_bCondValid
Definition: dbfld.hxx:161
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:392
void Evaluate(SwDoc const *)
Definition: dbfld.cxx:589
static bool FormatValue(SvNumberFormatter const *pDocFormatter, OUString const &aString, sal_uInt32 nFormat, double &aNumber, sal_Int32 nColumnType, SwDBField *pField=nullptr)
Definition: dbfld.cxx:269
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:387
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Definition: doc.hxx:1399
const SwExtendedSubType SUB_INVISIBLE
Invisible.
Definition: fldbas.hxx:205
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:513
bool IsInitialized() const
Definition: dbfld.hxx:94
OUString sDataSource
Definition: swdbdata.hxx:30
virtual OUString GetPar2() const override
get condition
Definition: dbfld.cxx:700
OUString m_sColumn
Definition: dbfld.hxx:33
SwDoc * m_pDoc
Definition: dbfld.hxx:236
Base class of all fields.
Definition: fldbas.hxx:279
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set a new type.
Definition: fldbas.cxx:576
OUString m_sName
only used in ::GetName() !
Definition: dbfld.hxx:32
#define FIELD_PROP_USHORT1
Definition: unofldmid.h:31
virtual void SetSubType(sal_uInt16 nType) override
Definition: dbfld.cxx:365
Definition: doc.hxx:185
TElementType * Next()
Definition: calbck.hxx:376
virtual std::unique_ptr< SwField > Copy() const override
Definition: dbfld.cxx:220
SwDBNameFieldType(SwDoc *)
Definition: dbfld.cxx:749
virtual std::unique_ptr< SwField > Copy() const override
Definition: dbfld.cxx:580
const SwDBData & GetDBData() const
Definition: dbfld.hxx:127
virtual std::unique_ptr< SwField > Copy() const override
Definition: dbfld.cxx:666
static OUString lcl_DBSeparatorConvert(const OUString &aContent)
replace database separator by dots for display
Definition: dbfld.cxx:48
OUString m_sFieldCode
contains Word's field code
Definition: dbfld.hxx:59
void ReleaseRef()
Definition: dbfld.cxx:86
bool IsInMerge() const
Definition: dbmgr.hxx:341
virtual void SetPar1(const OUString &rStr) override
set LogDBName
Definition: dbfld.cxx:694
SwDoc * GetDoc() const
Definition: fldbas.hxx:443
SwDBNumSetField(SwDBNumSetFieldType *, const OUString &rCond, const OUString &rDBNum, const SwDBData &rDBData)
Definition: dbfld.cxx:651
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:395
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
long m_nRefCnt
Definition: dbfld.hxx:34
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: dbfld.cxx:761
virtual OUString GetPar1() const override
get condition
Definition: dbfld.cxx:600
#define FIELD_PROP_FORMAT
Definition: unofldmid.h:26
virtual std::unique_ptr< SwField > Copy() const override
Definition: dbfld.cxx:834
#define SAL_MAX_UINT32
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:389
SwDBFieldType(SwDoc *pDocPtr, const OUString &rColumnName, const SwDBData &rDBData)
Definition: dbfld.cxx:55
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: dbfld.cxx:575
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:107
virtual OUString GetFieldName() const override
get name or content
Definition: dbfld.cxx:234
bool m_bCondValid
Definition: dbfld.hxx:202
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:89
virtual void SetSubType(sal_uInt16 nType) override
Definition: dbfld.cxx:550
void SetDBData(const SwDBData &rDBData)
Definition: dbfld.cxx:473
sal_uInt16 m_nSubType
Definition: dbfld.hxx:124
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
expand numbering
Definition: fldbas.cxx:444
OUString Expand() const
Definition: dbfld.cxx:755
sal_Int32 GetColumnType(const OUString &rDBName, const OUString &rTableName, const OUString &rColNm)
Definition: dbmgr.cxx:1902
void Evaluate(SwDoc const *)
Definition: dbfld.cxx:823
OUString m_aContent
Definition: dbfld.hxx:58
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: dbfld.cxx:562
double GetDouble() const
Definition: calc.cxx:1412
SwDBSetNumberField(SwDBSetNumberFieldType *, const SwDBData &rDBData, sal_uInt32 nFormat=0)
Definition: dbfld.cxx:810
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:788
bool IsNumeric() const
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: dbfld.cxx:661
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:611
SwDBData const & GetDBData()
Definition: docfld.cxx:354
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:861
virtual ~SwDBField() override
Definition: dbfld.cxx:184
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:844
void Evaluate()
Get the evaluation via DBManager string.
Definition: dbfld.cxx:316
bool GetMergeColumnCnt(const OUString &rColumnName, LanguageType nLanguage, OUString &rResult, double *pNumber)
Definition: dbmgr.cxx:2174
bool m_bIsInBodyText
Definition: dbfld.hxx:61
#define FIELD_PROP_BOOL2
Definition: unofldmid.h:29
bool IsTextFormat(sal_uInt32 nFIndex) const
TElementType * First()
Definition: calbck.hxx:345
SwFieldIds
Definition: fldbas.hxx:38
SwDBNextSetField(SwDBNextSetFieldType *, const OUString &rCond, const SwDBData &rDBData)
Definition: dbfld.cxx:569
OUString m_aCond
Definition: dbfld.hxx:160
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:293
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: dbfld.cxx:646
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: dbfld.cxx:816
SwDBData m_aDBData
Definition: dbfld.hxx:31
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:693
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set a new type.
Definition: dbfld.cxx:259
virtual const SwFieldTypes * GetFieldTypes() const =0
SwDBNameInfField(SwFieldType *pTyp, const SwDBData &rDBData, sal_uInt32 nFormat=0)
Definition: dbfld.cxx:456
static sal_uLong GetColumnFormat(css::uno::Reference< css::sdbc::XDataSource > const &xSource, css::uno::Reference< css::sdbc::XConnection > const &xConnection, css::uno::Reference< css::beans::XPropertySet > const &xColumn, SvNumberFormatter *pNFormatr, LanguageType nLanguage)
GUIDCNamePair const aData
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: dbfld.cxx:772
SwDoc * GetDoc() const
Definition: fldbas.hxx:409
void InitContent()
Evaluation for header and footer.
Definition: dbfld.cxx:190
#define DB_DELIM
Definition: swtypes.hxx:141
virtual OUString GetName() const override
Only in derived classes.
Definition: dbfld.cxx:81
#define FIELD_PROP_PAR3
Definition: unofldmid.h:25
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:728
SwFieldType * GetTyp() const
Definition: fldbas.hxx:382
bool ToRecordId(sal_Int32 nSet)
Definition: dbmgr.cxx:2363
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:370
#define FIELD_PROP_BOOL1
Definition: unofldmid.h:28
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:398
virtual std::unique_ptr< SwField > Copy() const override
Definition: dbfld.cxx:779
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:128
#define FIELD_PROP_PAR1
Definition: unofldmid.h:23
sal_uInt32 GetSelectedRecordId(const OUString &rDataSource, const OUString &rTableOrQuery, sal_Int32 nCommandType=-1)
Definition: dbmgr.cxx:2449
#define FIELD_PROP_PAR2
Definition: unofldmid.h:24
virtual sal_uInt16 GetSubType() const override
Definition: dbfld.cxx:545
void SetExpansion(const OUString &rStr)
Current text.
Definition: dbfld.hxx:113
const SwDBData & GetDBData() const
DBName.
Definition: dbfld.hxx:105
virtual void NotifyContentChange(SwFormatField &rFormatField)
Definition: atrfld.cxx:493
bool m_bValidValue
Definition: dbfld.hxx:62
bool PutString(const OUString &)
sal_uInt16 m_nSubType
Definition: dbfld.hxx:60
virtual ~SwDBFieldType() override
Definition: dbfld.cxx:72
void ClearInitialized()
Definition: dbfld.hxx:95
const SwExtendedSubType SUB_OWN_FMT
SwDBField: Don't accept formatting from database.
Definition: fldbas.hxx:206
virtual OUString GetFieldName() const
get name or content
Definition: fldbas.cxx:255
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:625
virtual OUString GetPar1() const override
Get name.
Definition: dbfld.cxx:355
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: dbfld.cxx:213
bool IsDataSourceOpen(const OUString &rDataSource, const OUString &rTableOrQuery, bool bMergeShell)
check if a data source is open
Definition: dbmgr.cxx:2090
virtual void SetPar2(const OUString &rStr) override
set condition
Definition: dbfld.cxx:706
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2336
virtual void SetValue(const double &rVal)
Definition: fldbas.cxx:680
virtual void SetPar1(const OUString &rStr) override
set condition
Definition: dbfld.cxx:606
SwDBField(SwDBFieldType *, sal_uInt32 nFormat=0)
Definition: dbfld.cxx:172
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
OUString m_aPar2
Definition: dbfld.hxx:201
const Date & GetNullDate() const
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
Definition: fldbas.hxx:450
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: dbfld.cxx:76
sal_Int32 nPos
OUString m_aCond
Definition: dbfld.hxx:200
virtual double GetValue() const
Definition: fldbas.cxx:675
OUString sCommand
Definition: swdbdata.hxx:31
virtual OUString GetFieldName() const override
get name or content
Definition: dbfld.cxx:478
SwDBManager * GetDBManager() const
Definition: doc.hxx:664
virtual void RemoveFieldType(size_t nField)=0
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:793
SwDBNameField(SwDBNameFieldType *, const SwDBData &rDBData)
Definition: dbfld.cxx:768
virtual sal_uInt16 GetSubType() const override
Definition: dbfld.cxx:360
#define FIELD_PROP_SHORT1
Definition: unofldmid.h:37
void ToNextRecord(const OUString &rDataSource, const OUString &rTableOrQuery)
Definition: dbmgr.cxx:2257
virtual OUString GetPar1() const override
get LogDBName
Definition: dbfld.cxx:688
const OUString m_sName