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