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