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