Line data Source code
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 <sfx2/app.hxx>
22 : #include <svl/zforlist.hxx>
23 : #include <svx/pageitem.hxx>
24 : #include <svx/dataaccessdescriptor.hxx>
25 : #include <com/sun/star/sdbc/DataType.hpp>
26 : #include <fmtfld.hxx>
27 : #include <txtfld.hxx>
28 : #include <doc.hxx>
29 : #include <docary.hxx>
30 : #include <frame.hxx>
31 : #include <fldbas.hxx>
32 : #include <pam.hxx>
33 : #include <ndtxt.hxx>
34 : #include <dbfld.hxx>
35 : #include <dbmgr.hxx>
36 : #include <docfld.hxx>
37 : #include <expfld.hxx>
38 : #include <txtatr.hxx>
39 : #include <unofldmid.h>
40 : #include <switerator.hxx>
41 :
42 : using namespace ::com::sun::star::sdbc;
43 : using namespace ::com::sun::star;
44 :
45 : /// replace database separator by dots for display
46 15 : static String lcl_DBTrennConv(const String& aContent)
47 : {
48 15 : String sTmp(aContent);
49 15 : sal_Unicode* pStr = sTmp.GetBufferAccess();
50 98 : for( sal_uInt16 i = sTmp.Len(); i; --i, ++pStr )
51 83 : if( DB_DELIM == *pStr )
52 2 : *pStr = '.';
53 15 : return sTmp;
54 : }
55 :
56 : // database field type
57 :
58 9 : SwDBFieldType::SwDBFieldType(SwDoc* pDocPtr, const String& rNam, const SwDBData& rDBData ) :
59 : SwValueFieldType( pDocPtr, RES_DBFLD ),
60 : aDBData(rDBData),
61 : sColumn(rNam),
62 9 : nRefCnt(0)
63 : {
64 9 : if(!aDBData.sDataSource.isEmpty() || !aDBData.sCommand.isEmpty())
65 : {
66 27 : sName = OUStringBuffer(aDBData.sDataSource).append(DB_DELIM).
67 27 : append(aDBData.sCommand).append(DB_DELIM).makeStringAndClear();
68 : }
69 9 : sName += GetColumnName();
70 9 : }
71 :
72 14 : SwDBFieldType::~SwDBFieldType()
73 : {
74 14 : }
75 :
76 5 : SwFieldType* SwDBFieldType::Copy() const
77 : {
78 5 : SwDBFieldType* pTmp = new SwDBFieldType(GetDoc(), sColumn, aDBData);
79 5 : return pTmp;
80 : }
81 :
82 11 : const OUString& SwDBFieldType::GetName() const
83 : {
84 11 : return sName;
85 : }
86 :
87 23 : void SwDBFieldType::ReleaseRef()
88 : {
89 : OSL_ENSURE(nRefCnt > 0, "RefCount < 0!");
90 :
91 23 : if (--nRefCnt <= 0)
92 : {
93 4 : sal_uInt16 nPos = GetDoc()->GetFldTypes()->GetPos(this);
94 :
95 4 : if (nPos != USHRT_MAX)
96 : {
97 3 : GetDoc()->RemoveFldType(nPos);
98 3 : delete this;
99 : }
100 : }
101 23 : }
102 :
103 13 : bool SwDBFieldType::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
104 : {
105 13 : switch( nWhichId )
106 : {
107 : case FIELD_PROP_PAR1:
108 4 : rAny <<= aDBData.sDataSource;
109 4 : break;
110 : case FIELD_PROP_PAR2:
111 3 : rAny <<= aDBData.sCommand;
112 3 : break;
113 : case FIELD_PROP_PAR3:
114 3 : rAny <<= OUString(sColumn);
115 3 : break;
116 : case FIELD_PROP_SHORT1:
117 3 : rAny <<= aDBData.nCommandType;
118 3 : break;
119 : default:
120 : OSL_FAIL("illegal property");
121 : }
122 13 : return true;
123 : }
124 :
125 4 : bool SwDBFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
126 : {
127 4 : switch( nWhichId )
128 : {
129 : case FIELD_PROP_PAR1:
130 1 : rAny >>= aDBData.sDataSource;
131 1 : break;
132 : case FIELD_PROP_PAR2:
133 1 : rAny >>= aDBData.sCommand;
134 1 : break;
135 : case FIELD_PROP_PAR3:
136 : {
137 1 : String sTmp;
138 1 : ::GetString( rAny, sTmp );
139 1 : if( sTmp != sColumn )
140 : {
141 1 : sColumn = sTmp;
142 1 : SwIterator<SwFmtFld,SwFieldType> aIter( *this );
143 1 : SwFmtFld* pFld = aIter.First();
144 2 : while(pFld)
145 : {
146 : // field in Undo?
147 0 : SwTxtFld *pTxtFld = pFld->GetTxtFld();
148 0 : if(pTxtFld && pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
149 : {
150 0 : SwDBField* pDBField = (SwDBField*)pFld->GetFld();
151 0 : pDBField->ClearInitialized();
152 0 : pDBField->InitContent();
153 : }
154 0 : pFld = aIter.Next();
155 1 : }
156 1 : }
157 : }
158 1 : break;
159 : case FIELD_PROP_SHORT1:
160 1 : rAny >>= aDBData.nCommandType;
161 1 : break;
162 : default:
163 : OSL_FAIL("illegal property");
164 : }
165 4 : return true;
166 : }
167 :
168 : // database field
169 :
170 22 : SwDBField::SwDBField(SwDBFieldType* pTyp, sal_uLong nFmt)
171 : : SwValueField(pTyp, nFmt),
172 : nSubType(0),
173 : bIsInBodyTxt(true),
174 : bValidValue(false),
175 22 : bInitialized(false)
176 : {
177 22 : if (GetTyp())
178 22 : ((SwDBFieldType*)GetTyp())->AddRef();
179 22 : InitContent();
180 22 : }
181 :
182 66 : SwDBField::~SwDBField()
183 : {
184 22 : if (GetTyp())
185 22 : ((SwDBFieldType*)GetTyp())->ReleaseRef();
186 44 : }
187 :
188 22 : void SwDBField::InitContent()
189 : {
190 22 : if (!IsInitialized())
191 : {
192 66 : aContent = OUStringBuffer().append('<')
193 66 : .append(((const SwDBFieldType*)GetTyp())->GetColumnName())
194 44 : .append('>').makeStringAndClear();
195 : }
196 22 : }
197 :
198 3 : void SwDBField::InitContent(const String& rExpansion)
199 : {
200 3 : if (rExpansion.Len() > 2)
201 : {
202 0 : if (rExpansion.GetChar(0) == '<' &&
203 0 : rExpansion.GetChar(rExpansion.Len() - 1) == '>')
204 : {
205 0 : String sColumn( rExpansion.Copy( 1, rExpansion.Len() - 2 ) );
206 0 : if( ::GetAppCmpStrIgnore().isEqual( sColumn,
207 0 : ((SwDBFieldType *)GetTyp())->GetColumnName() ))
208 : {
209 0 : InitContent();
210 3 : return;
211 0 : }
212 : }
213 : }
214 3 : SetExpansion( rExpansion );
215 : }
216 :
217 20 : String SwDBField::Expand() const
218 : {
219 20 : String sRet;
220 :
221 20 : if(0 ==(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE))
222 14 : sRet = lcl_DBTrennConv(aContent);
223 20 : return sRet;
224 : }
225 :
226 19 : SwField* SwDBField::Copy() const
227 : {
228 19 : SwDBField *pTmp = new SwDBField((SwDBFieldType*)GetTyp(), GetFormat());
229 19 : pTmp->aContent = aContent;
230 19 : pTmp->bIsInBodyTxt = bIsInBodyTxt;
231 19 : pTmp->bValidValue = bValidValue;
232 19 : pTmp->bInitialized = bInitialized;
233 19 : pTmp->nSubType = nSubType;
234 19 : pTmp->SetValue(GetValue());
235 19 : pTmp->sFieldCode = sFieldCode;
236 :
237 19 : return pTmp;
238 : }
239 :
240 1 : String SwDBField::GetFieldName() const
241 : {
242 1 : const String& rDBName = static_cast<SwDBFieldType*>(GetTyp())->GetName();
243 :
244 2 : String sContent( rDBName.GetToken(0, DB_DELIM) );
245 :
246 1 : if (sContent.Len() > 1)
247 : {
248 1 : sContent += DB_DELIM;
249 1 : sContent += rDBName.GetToken(1, DB_DELIM);
250 1 : sContent += DB_DELIM;
251 1 : sContent += rDBName.GetToken(2, DB_DELIM);
252 : }
253 2 : return lcl_DBTrennConv(sContent);
254 : }
255 :
256 0 : void SwDBField::ChgValue( double d, bool bVal )
257 : {
258 0 : bValidValue = bVal;
259 0 : SetValue(d);
260 :
261 0 : if( bValidValue )
262 0 : aContent = ((SwValueFieldType*)GetTyp())->ExpandValue(d, GetFormat(), GetLanguage());
263 0 : }
264 :
265 1 : SwFieldType* SwDBField::ChgTyp( SwFieldType* pNewType )
266 : {
267 1 : SwFieldType* pOld = SwValueField::ChgTyp( pNewType );
268 :
269 1 : ((SwDBFieldType*)pNewType)->AddRef();
270 1 : ((SwDBFieldType*)pOld)->ReleaseRef();
271 :
272 1 : return pOld;
273 : }
274 :
275 : /// get current field value and cache it
276 0 : void SwDBField::Evaluate()
277 : {
278 0 : SwNewDBMgr* pMgr = GetDoc()->GetNewDBMgr();
279 :
280 : // first delete
281 0 : bValidValue = false;
282 0 : double nValue = DBL_MAX;
283 0 : const SwDBData& aTmpData = GetDBData();
284 :
285 0 : if(!pMgr || !pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_True))
286 0 : return ;
287 :
288 : sal_uInt32 nFmt;
289 :
290 : // search corresponding column name
291 0 : String aColNm( ((SwDBFieldType*)GetTyp())->GetColumnName() );
292 :
293 0 : SvNumberFormatter* pDocFormatter = GetDoc()->GetNumberFormatter();
294 0 : pMgr->GetMergeColumnCnt(aColNm, GetLanguage(), aContent, &nValue, &nFmt);
295 0 : if( !( nSubType & nsSwExtendedSubType::SUB_OWN_FMT ) )
296 : SetFormat( nFmt = pMgr->GetColumnFmt( aTmpData.sDataSource, aTmpData.sCommand,
297 0 : aColNm, pDocFormatter, GetLanguage() ));
298 :
299 0 : if( DBL_MAX != nValue )
300 : {
301 0 : sal_Int32 nColumnType = pMgr->GetColumnType(aTmpData.sDataSource, aTmpData.sCommand, aColNm);
302 0 : if( DataType::DATE == nColumnType || DataType::TIME == nColumnType ||
303 : DataType::TIMESTAMP == nColumnType)
304 :
305 : {
306 0 : Date aStandard(1,1,1900);
307 0 : if (*pDocFormatter->GetNullDate() != aStandard)
308 0 : nValue += (aStandard - *pDocFormatter->GetNullDate());
309 : }
310 0 : bValidValue = true;
311 0 : SetValue(nValue);
312 0 : aContent = ((SwValueFieldType*)GetTyp())->ExpandValue(nValue, GetFormat(), GetLanguage());
313 : }
314 : else
315 : {
316 0 : SwSbxValue aVal;
317 0 : aVal.PutString( aContent );
318 :
319 0 : if (aVal.IsNumeric())
320 : {
321 0 : SetValue(aVal.GetDouble());
322 :
323 0 : SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
324 0 : if (nFmt && nFmt != SAL_MAX_UINT32 && !pFormatter->IsTextFormat(nFmt))
325 0 : bValidValue = true; // because of bug #60339 not for all strings
326 : }
327 : else
328 : {
329 : // if string length > 0 then true, else false
330 0 : SetValue(aContent.isEmpty() ? 0 : 1);
331 0 : }
332 : }
333 0 : bInitialized = true;
334 : }
335 :
336 : /// get name
337 0 : const OUString& SwDBField::GetPar1() const
338 : {
339 0 : return ((const SwDBFieldType*)GetTyp())->GetName();
340 : }
341 :
342 41 : sal_uInt16 SwDBField::GetSubType() const
343 : {
344 41 : return nSubType;
345 : }
346 :
347 7 : void SwDBField::SetSubType(sal_uInt16 nType)
348 : {
349 7 : nSubType = nType;
350 7 : }
351 :
352 42 : bool SwDBField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
353 : {
354 42 : switch( nWhichId )
355 : {
356 : case FIELD_PROP_BOOL1:
357 : {
358 7 : sal_Bool bTemp = 0 == (GetSubType()&nsSwExtendedSubType::SUB_OWN_FMT);
359 7 : rAny.setValue(&bTemp, ::getBooleanCppuType());
360 : }
361 7 : break;
362 : case FIELD_PROP_BOOL2:
363 : {
364 7 : sal_Bool bVal = 0 == (GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE);
365 7 : rAny.setValue(&bVal, ::getBooleanCppuType());
366 : }
367 7 : break;
368 : case FIELD_PROP_FORMAT:
369 7 : rAny <<= (sal_Int32)GetFormat();
370 7 : break;
371 : case FIELD_PROP_PAR1:
372 14 : rAny <<= OUString(aContent);
373 14 : break;
374 : case FIELD_PROP_PAR2:
375 7 : rAny <<= OUString(sFieldCode);
376 7 : break;
377 : default:
378 : OSL_FAIL("illegal property");
379 : }
380 42 : return true;
381 : }
382 :
383 12 : bool SwDBField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
384 : {
385 12 : switch( nWhichId )
386 : {
387 : case FIELD_PROP_BOOL1:
388 2 : if( *(sal_Bool*)rAny.getValue() )
389 1 : SetSubType(GetSubType()&~nsSwExtendedSubType::SUB_OWN_FMT);
390 : else
391 1 : SetSubType(GetSubType()|nsSwExtendedSubType::SUB_OWN_FMT);
392 2 : break;
393 : case FIELD_PROP_BOOL2:
394 : {
395 2 : sal_uInt16 nSubTyp = GetSubType();
396 2 : sal_Bool bVisible = sal_False;
397 2 : if(!(rAny >>= bVisible))
398 0 : return false;
399 2 : if(bVisible)
400 1 : nSubTyp &= ~nsSwExtendedSubType::SUB_INVISIBLE;
401 : else
402 1 : nSubTyp |= nsSwExtendedSubType::SUB_INVISIBLE;
403 2 : SetSubType(nSubTyp);
404 : //invalidate text node
405 2 : if(GetTyp())
406 : {
407 2 : SwIterator<SwFmtFld,SwFieldType> aIter( *GetTyp() );
408 2 : SwFmtFld* pFld = aIter.First();
409 4 : while(pFld)
410 : {
411 2 : SwTxtFld *pTxtFld = pFld->GetTxtFld();
412 2 : if(pTxtFld && (SwDBField*)pFld->GetFld() == this )
413 : {
414 : //notify the change
415 2 : pTxtFld->NotifyContentChange(*pFld);
416 2 : break;
417 : }
418 0 : pFld = aIter.Next();
419 2 : }
420 : }
421 : }
422 2 : break;
423 : case FIELD_PROP_FORMAT:
424 : {
425 2 : sal_Int32 nTemp = 0;
426 2 : rAny >>= nTemp;
427 2 : SetFormat(nTemp);
428 : }
429 2 : break;
430 : case FIELD_PROP_PAR1:
431 4 : rAny >>= aContent;
432 4 : break;
433 : case FIELD_PROP_PAR2:
434 2 : rAny >>= sFieldCode;
435 2 : break;
436 : default:
437 : OSL_FAIL("illegal property");
438 : }
439 12 : return true;
440 : }
441 :
442 : // base class for all further database fields
443 :
444 0 : SwDBNameInfField::SwDBNameInfField(SwFieldType* pTyp, const SwDBData& rDBData, sal_uLong nFmt) :
445 : SwField(pTyp, nFmt),
446 : aDBData(rDBData),
447 0 : nSubType(0)
448 : {
449 0 : }
450 :
451 0 : SwDBData SwDBNameInfField::GetDBData(SwDoc* pDoc)
452 : {
453 0 : SwDBData aRet;
454 0 : if(!aDBData.sDataSource.isEmpty())
455 0 : aRet = aDBData;
456 : else
457 0 : aRet = pDoc->GetDBData();
458 0 : return aRet;
459 : }
460 :
461 0 : void SwDBNameInfField::SetDBData(const SwDBData & rDBData)
462 : {
463 0 : aDBData = rDBData;
464 0 : }
465 :
466 0 : String SwDBNameInfField::GetFieldName() const
467 : {
468 0 : String sStr( SwField::GetFieldName() );
469 0 : if (!aDBData.sDataSource.isEmpty())
470 : {
471 0 : sStr += ':';
472 0 : sStr += String(aDBData.sDataSource);
473 0 : sStr += DB_DELIM;
474 0 : sStr += String(aDBData.sCommand);
475 : }
476 0 : return lcl_DBTrennConv(sStr);
477 : }
478 :
479 0 : bool SwDBNameInfField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
480 : {
481 0 : switch( nWhichId )
482 : {
483 : case FIELD_PROP_PAR1:
484 0 : rAny <<= aDBData.sDataSource;
485 0 : break;
486 : case FIELD_PROP_PAR2:
487 0 : rAny <<= aDBData.sCommand;
488 0 : break;
489 : case FIELD_PROP_SHORT1:
490 0 : rAny <<= aDBData.nCommandType;
491 0 : break;
492 : case FIELD_PROP_BOOL2:
493 : {
494 0 : sal_Bool bVal = 0 == (GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE);
495 0 : rAny.setValue(&bVal, ::getBooleanCppuType());
496 : }
497 0 : break;
498 : default:
499 : OSL_FAIL("illegal property");
500 : }
501 0 : return true;
502 : }
503 :
504 0 : bool SwDBNameInfField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
505 : {
506 0 : switch( nWhichId )
507 : {
508 : case FIELD_PROP_PAR1:
509 0 : rAny >>= aDBData.sDataSource;
510 0 : break;
511 : case FIELD_PROP_PAR2:
512 0 : rAny >>= aDBData.sCommand;
513 0 : break;
514 : case FIELD_PROP_SHORT1:
515 0 : rAny >>= aDBData.nCommandType;
516 0 : break;
517 : case FIELD_PROP_BOOL2:
518 : {
519 0 : sal_uInt16 nSubTyp = GetSubType();
520 0 : sal_Bool bVisible = sal_False;
521 0 : if(!(rAny >>= bVisible))
522 0 : return false;
523 0 : if(bVisible)
524 0 : nSubTyp &= ~nsSwExtendedSubType::SUB_INVISIBLE;
525 : else
526 0 : nSubTyp |= nsSwExtendedSubType::SUB_INVISIBLE;
527 0 : SetSubType(nSubTyp);
528 : }
529 0 : break;
530 : default:
531 : OSL_FAIL("illegal property");
532 : }
533 0 : return true;
534 : }
535 :
536 0 : sal_uInt16 SwDBNameInfField::GetSubType() const
537 : {
538 0 : return nSubType;
539 : }
540 :
541 0 : void SwDBNameInfField::SetSubType(sal_uInt16 nType)
542 : {
543 0 : nSubType = nType;
544 0 : }
545 :
546 : // next dataset
547 :
548 898 : SwDBNextSetFieldType::SwDBNextSetFieldType()
549 898 : : SwFieldType( RES_DBNEXTSETFLD )
550 : {
551 898 : }
552 :
553 0 : SwFieldType* SwDBNextSetFieldType::Copy() const
554 : {
555 0 : SwDBNextSetFieldType* pTmp = new SwDBNextSetFieldType();
556 0 : return pTmp;
557 : }
558 :
559 : // SwDBSetField
560 :
561 0 : SwDBNextSetField::SwDBNextSetField(SwDBNextSetFieldType* pTyp,
562 : const String& rCond,
563 : const String& ,
564 : const SwDBData& rDBData) :
565 0 : SwDBNameInfField(pTyp, rDBData), aCond(rCond), bCondValid(true)
566 0 : {}
567 :
568 0 : String SwDBNextSetField::Expand() const
569 : {
570 0 : return aEmptyStr;
571 : }
572 :
573 0 : SwField* SwDBNextSetField::Copy() const
574 : {
575 0 : SwDBNextSetField *pTmp = new SwDBNextSetField((SwDBNextSetFieldType*)GetTyp(),
576 0 : aCond, aEmptyStr, GetDBData());
577 0 : pTmp->SetSubType(GetSubType());
578 0 : pTmp->bCondValid = bCondValid;
579 0 : return pTmp;
580 : }
581 :
582 0 : void SwDBNextSetField::Evaluate(SwDoc* pDoc)
583 : {
584 0 : SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
585 0 : const SwDBData& rData = GetDBData();
586 0 : if( !bCondValid ||
587 0 : !pMgr || !pMgr->IsDataSourceOpen(rData.sDataSource, rData.sCommand, sal_False))
588 0 : return ;
589 0 : pMgr->ToNextRecord(rData.sDataSource, rData.sCommand);
590 : }
591 :
592 : /// get condition
593 0 : const OUString& SwDBNextSetField::GetPar1() const
594 : {
595 0 : return aCond;
596 : }
597 :
598 : /// set condition
599 0 : void SwDBNextSetField::SetPar1(const OUString& rStr)
600 : {
601 0 : aCond = rStr;
602 0 : }
603 :
604 0 : bool SwDBNextSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
605 : {
606 0 : bool bRet = true;
607 0 : switch( nWhichId )
608 : {
609 : case FIELD_PROP_PAR3:
610 0 : rAny <<= OUString(aCond);
611 0 : break;
612 : default:
613 0 : bRet = SwDBNameInfField::QueryValue( rAny, nWhichId );
614 : }
615 0 : return bRet;
616 : }
617 :
618 0 : bool SwDBNextSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
619 : {
620 0 : bool bRet = true;
621 0 : switch( nWhichId )
622 : {
623 : case FIELD_PROP_PAR3:
624 0 : rAny >>= aCond;
625 0 : break;
626 : default:
627 0 : bRet = SwDBNameInfField::PutValue( rAny, nWhichId );
628 : }
629 0 : return bRet;
630 : }
631 :
632 : // dataset with certain ID
633 :
634 898 : SwDBNumSetFieldType::SwDBNumSetFieldType() :
635 898 : SwFieldType( RES_DBNUMSETFLD )
636 : {
637 898 : }
638 :
639 0 : SwFieldType* SwDBNumSetFieldType::Copy() const
640 : {
641 0 : SwDBNumSetFieldType* pTmp = new SwDBNumSetFieldType();
642 0 : return pTmp;
643 : }
644 :
645 : // SwDBNumSetField
646 :
647 0 : SwDBNumSetField::SwDBNumSetField(SwDBNumSetFieldType* pTyp,
648 : const String& rCond,
649 : const String& rDBNum,
650 : const SwDBData& rDBData) :
651 : SwDBNameInfField(pTyp, rDBData),
652 : aCond(rCond),
653 : aPar2(rDBNum),
654 0 : bCondValid(true)
655 0 : {}
656 :
657 0 : String SwDBNumSetField::Expand() const
658 : {
659 0 : return aEmptyStr;
660 : }
661 :
662 0 : SwField* SwDBNumSetField::Copy() const
663 : {
664 0 : SwDBNumSetField *pTmp = new SwDBNumSetField((SwDBNumSetFieldType*)GetTyp(),
665 0 : aCond, aPar2, GetDBData());
666 0 : pTmp->bCondValid = bCondValid;
667 0 : pTmp->SetSubType(GetSubType());
668 0 : return pTmp;
669 : }
670 :
671 0 : void SwDBNumSetField::Evaluate(SwDoc* pDoc)
672 : {
673 0 : SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
674 0 : const SwDBData& aTmpData = GetDBData();
675 :
676 0 : if( bCondValid && pMgr && pMgr->IsInMerge() &&
677 0 : pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_True))
678 : { // Bedingug OK -> aktuellen Set einstellen
679 0 : pMgr->ToRecordId(std::max((sal_uInt16)aPar2.ToInt32(), sal_uInt16(1))-1);
680 : }
681 0 : }
682 :
683 : /// get LogDBName
684 0 : const OUString& SwDBNumSetField::GetPar1() const
685 : {
686 0 : return aCond;
687 : }
688 :
689 : /// set LogDBName
690 0 : void SwDBNumSetField::SetPar1(const OUString& rStr)
691 : {
692 0 : aCond = rStr;
693 0 : }
694 :
695 : /// get condition
696 0 : OUString SwDBNumSetField::GetPar2() const
697 : {
698 0 : return aPar2;
699 : }
700 :
701 : /// set condition
702 0 : void SwDBNumSetField::SetPar2(const OUString& rStr)
703 : {
704 0 : aPar2 = rStr;
705 0 : }
706 :
707 0 : bool SwDBNumSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
708 : {
709 0 : bool bRet = true;
710 0 : switch( nWhichId )
711 : {
712 : case FIELD_PROP_PAR3:
713 0 : rAny <<= OUString(aCond);
714 0 : break;
715 : case FIELD_PROP_FORMAT:
716 0 : rAny <<= (sal_Int32)aPar2.ToInt32();
717 0 : break;
718 : default:
719 0 : bRet = SwDBNameInfField::QueryValue(rAny, nWhichId );
720 : }
721 0 : return bRet;
722 : }
723 :
724 0 : bool SwDBNumSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
725 : {
726 0 : bool bRet = true;
727 0 : switch( nWhichId )
728 : {
729 : case FIELD_PROP_PAR3:
730 0 : rAny >>= aCond;
731 0 : break;
732 : case FIELD_PROP_FORMAT:
733 : {
734 0 : sal_Int32 nVal = 0;
735 0 : rAny >>= nVal;
736 0 : aPar2 = OUString::number(nVal);
737 : }
738 0 : break;
739 : default:
740 0 : bRet = SwDBNameInfField::PutValue(rAny, nWhichId );
741 : }
742 0 : return bRet;
743 : }
744 :
745 : // SwDBNameFieldType
746 :
747 898 : SwDBNameFieldType::SwDBNameFieldType(SwDoc* pDocument)
748 898 : : SwFieldType( RES_DBNAMEFLD )
749 : {
750 898 : pDoc = pDocument;
751 898 : }
752 :
753 0 : String SwDBNameFieldType::Expand(sal_uLong ) const
754 : {
755 0 : const SwDBData aData = pDoc->GetDBData();
756 0 : String sRet(aData.sDataSource);
757 0 : sRet += '.';
758 0 : sRet += (String)aData.sCommand;
759 0 : return sRet;
760 : }
761 :
762 0 : SwFieldType* SwDBNameFieldType::Copy() const
763 : {
764 0 : SwDBNameFieldType *pTmp = new SwDBNameFieldType(pDoc);
765 0 : return pTmp;
766 : }
767 :
768 : // name of the connected database
769 :
770 0 : SwDBNameField::SwDBNameField(SwDBNameFieldType* pTyp, const SwDBData& rDBData, sal_uLong nFmt)
771 0 : : SwDBNameInfField(pTyp, rDBData, nFmt)
772 0 : {}
773 :
774 0 : String SwDBNameField::Expand() const
775 : {
776 0 : String sRet;
777 0 : if(0 ==(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE))
778 0 : sRet = ((SwDBNameFieldType*)GetTyp())->Expand(GetFormat());
779 0 : return sRet;
780 : }
781 :
782 0 : SwField* SwDBNameField::Copy() const
783 : {
784 0 : SwDBNameField *pTmp = new SwDBNameField((SwDBNameFieldType*)GetTyp(), GetDBData());
785 0 : pTmp->ChangeFormat(GetFormat());
786 0 : pTmp->SetLanguage(GetLanguage());
787 0 : pTmp->SetSubType(GetSubType());
788 0 : return pTmp;
789 : }
790 :
791 0 : bool SwDBNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
792 : {
793 0 : return SwDBNameInfField::QueryValue(rAny, nWhichId );
794 : }
795 :
796 0 : bool SwDBNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
797 : {
798 0 : return SwDBNameInfField::PutValue(rAny, nWhichId );
799 : }
800 :
801 : // SwDBSetNumberFieldType
802 :
803 898 : SwDBSetNumberFieldType::SwDBSetNumberFieldType()
804 898 : : SwFieldType( RES_DBSETNUMBERFLD )
805 : {
806 898 : }
807 :
808 0 : SwFieldType* SwDBSetNumberFieldType::Copy() const
809 : {
810 0 : SwDBSetNumberFieldType *pTmp = new SwDBSetNumberFieldType;
811 0 : return pTmp;
812 : }
813 :
814 : // set-number of the connected database
815 :
816 0 : SwDBSetNumberField::SwDBSetNumberField(SwDBSetNumberFieldType* pTyp,
817 : const SwDBData& rDBData,
818 : sal_uLong nFmt)
819 0 : : SwDBNameInfField(pTyp, rDBData, nFmt), nNumber(0)
820 0 : {}
821 :
822 0 : String SwDBSetNumberField::Expand() const
823 : {
824 0 : if(0 !=(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE) || nNumber == 0)
825 0 : return aEmptyStr;
826 : else
827 0 : return FormatNumber((sal_uInt16)nNumber, GetFormat());
828 : }
829 :
830 0 : void SwDBSetNumberField::Evaluate(SwDoc* pDoc)
831 : {
832 0 : SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
833 :
834 0 : const SwDBData& aTmpData = GetDBData();
835 0 : if (!pMgr || !pMgr->IsInMerge() ||
836 0 : !pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_False))
837 0 : return;
838 0 : nNumber = pMgr->GetSelectedRecordId();
839 : }
840 :
841 0 : SwField* SwDBSetNumberField::Copy() const
842 : {
843 : SwDBSetNumberField *pTmp =
844 0 : new SwDBSetNumberField((SwDBSetNumberFieldType*)GetTyp(), GetDBData(), GetFormat());
845 0 : pTmp->SetLanguage(GetLanguage());
846 0 : pTmp->SetSetNumber(nNumber);
847 0 : pTmp->SetSubType(GetSubType());
848 0 : return pTmp;
849 : }
850 :
851 0 : bool SwDBSetNumberField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
852 : {
853 0 : bool bRet = true;
854 0 : switch( nWhichId )
855 : {
856 : case FIELD_PROP_USHORT1:
857 0 : rAny <<= (sal_Int16)GetFormat();
858 0 : break;
859 : case FIELD_PROP_FORMAT:
860 0 : rAny <<= nNumber;
861 0 : break;
862 : default:
863 0 : bRet = SwDBNameInfField::QueryValue( rAny, nWhichId );
864 : }
865 0 : return bRet;
866 : }
867 :
868 0 : bool SwDBSetNumberField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
869 : {
870 0 : bool bRet = true;
871 0 : switch( nWhichId )
872 : {
873 : case FIELD_PROP_USHORT1:
874 : {
875 0 : sal_Int16 nSet = 0;
876 0 : rAny >>= nSet;
877 0 : if(nSet < (sal_Int16) SVX_NUMBER_NONE )
878 0 : SetFormat(nSet);
879 : else {
880 : }
881 : }
882 0 : break;
883 : case FIELD_PROP_FORMAT:
884 0 : rAny >>= nNumber;
885 0 : break;
886 : default:
887 0 : bRet = SwDBNameInfField::PutValue( rAny, nWhichId );
888 : }
889 0 : return bRet;
890 99 : }
891 :
892 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|