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