1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5efeef26fSAndrew Rist * distributed with this work for additional information
6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist * software distributed under the License is distributed on an
15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17efeef26fSAndrew Rist * specific language governing permissions and limitations
18efeef26fSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20efeef26fSAndrew Rist *************************************************************/
21efeef26fSAndrew Rist
22efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <svl/zforlist.hxx>
28cdf0e10cSrcweir #include <svl/zformat.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <svx/svdmodel.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <calbck.hxx>
33cdf0e10cSrcweir #include <calc.hxx>
34cdf0e10cSrcweir #include <usrfld.hxx>
35cdf0e10cSrcweir #include <doc.hxx>
36cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
37cdf0e10cSrcweir #include <editsh.hxx>
38cdf0e10cSrcweir #include <dpage.hxx>
39cdf0e10cSrcweir #include <unofldmid.h>
40cdf0e10cSrcweir
41cdf0e10cSrcweir
42cdf0e10cSrcweir using namespace ::com::sun::star;
43cdf0e10cSrcweir using ::rtl::OUString;
44cdf0e10cSrcweir
45cdf0e10cSrcweir /*--------------------------------------------------------------------
46cdf0e10cSrcweir Beschreibung: Benutzerfelder
47cdf0e10cSrcweir --------------------------------------------------------------------*/
48cdf0e10cSrcweir
SwUserField(SwUserFieldType * pTyp,sal_uInt16 nSub,sal_uInt32 nFmt)49cdf0e10cSrcweir SwUserField::SwUserField(SwUserFieldType* pTyp, sal_uInt16 nSub, sal_uInt32 nFmt)
50cdf0e10cSrcweir : SwValueField(pTyp, nFmt),
51cdf0e10cSrcweir nSubType(nSub)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir
Expand() const55cdf0e10cSrcweir String SwUserField::Expand() const
56cdf0e10cSrcweir {
57cdf0e10cSrcweir String sStr;
58cdf0e10cSrcweir if(!(nSubType & nsSwExtendedSubType::SUB_INVISIBLE))
59cdf0e10cSrcweir sStr = ((SwUserFieldType*)GetTyp())->Expand(GetFormat(), nSubType, GetLanguage());
60cdf0e10cSrcweir
61cdf0e10cSrcweir return sStr;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir
Copy() const64cdf0e10cSrcweir SwField* SwUserField::Copy() const
65cdf0e10cSrcweir {
66cdf0e10cSrcweir SwField* pTmp = new SwUserField((SwUserFieldType*)GetTyp(), nSubType, GetFormat());
67cdf0e10cSrcweir pTmp->SetAutomaticLanguage(IsAutomaticLanguage());
68cdf0e10cSrcweir return pTmp;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
GetFieldName() const71cdf0e10cSrcweir String SwUserField::GetFieldName() const
72cdf0e10cSrcweir {
73cdf0e10cSrcweir String aStr(SwFieldType::GetTypeStr(TYP_USERFLD));
74cdf0e10cSrcweir aStr += ' ';
75cdf0e10cSrcweir aStr += GetTyp()->GetName();
76cdf0e10cSrcweir aStr.AppendAscii(" = ");
77cdf0e10cSrcweir aStr += static_cast<SwUserFieldType*>(GetTyp())->GetContent();
78cdf0e10cSrcweir return aStr;
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
GetValue() const81cdf0e10cSrcweir double SwUserField::GetValue() const
82cdf0e10cSrcweir {
83cdf0e10cSrcweir return ((SwUserFieldType*)GetTyp())->GetValue();
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
SetValue(const double & rVal)86cdf0e10cSrcweir void SwUserField::SetValue( const double& rVal )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir ((SwUserFieldType*)GetTyp())->SetValue(rVal);
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir /*--------------------------------------------------------------------
92cdf0e10cSrcweir Beschreibung: Name
93cdf0e10cSrcweir --------------------------------------------------------------------*/
94cdf0e10cSrcweir
GetPar1() const95cdf0e10cSrcweir const String& SwUserField::GetPar1() const
96cdf0e10cSrcweir {
97cdf0e10cSrcweir return ((SwUserFieldType*)GetTyp())->GetName();
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir /*--------------------------------------------------------------------
101cdf0e10cSrcweir Beschreibung: Content
102cdf0e10cSrcweir --------------------------------------------------------------------*/
103cdf0e10cSrcweir
GetPar2() const104cdf0e10cSrcweir String SwUserField::GetPar2() const
105cdf0e10cSrcweir {
106cdf0e10cSrcweir return ((SwUserFieldType*)GetTyp())->GetContent(GetFormat());
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
SetPar2(const String & rStr)109cdf0e10cSrcweir void SwUserField::SetPar2(const String& rStr)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir ((SwUserFieldType*)GetTyp())->SetContent(rStr, GetFormat());
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
GetSubType() const114cdf0e10cSrcweir sal_uInt16 SwUserField::GetSubType() const
115cdf0e10cSrcweir {
116cdf0e10cSrcweir return ((SwUserFieldType*)GetTyp())->GetType() | nSubType;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
SetSubType(sal_uInt16 nSub)119cdf0e10cSrcweir void SwUserField::SetSubType(sal_uInt16 nSub)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir ((SwUserFieldType*)GetTyp())->SetType(nSub & 0x00ff);
122cdf0e10cSrcweir nSubType = nSub & 0xff00;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir
125cdf0e10cSrcweir /*-----------------09.03.98 08:04-------------------
126cdf0e10cSrcweir
127cdf0e10cSrcweir --------------------------------------------------*/
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const128cdf0e10cSrcweir sal_Bool SwUserField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
129cdf0e10cSrcweir {
130cdf0e10cSrcweir switch( nWhichId )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir case FIELD_PROP_BOOL2:
133cdf0e10cSrcweir {
134cdf0e10cSrcweir sal_Bool bTmp = 0 != (nSubType & nsSwExtendedSubType::SUB_CMD);
135cdf0e10cSrcweir rAny.setValue(&bTmp, ::getBooleanCppuType());
136cdf0e10cSrcweir }
137cdf0e10cSrcweir break;
138cdf0e10cSrcweir case FIELD_PROP_BOOL1:
139cdf0e10cSrcweir {
140cdf0e10cSrcweir sal_Bool bTmp = 0 == (nSubType & nsSwExtendedSubType::SUB_INVISIBLE);
141cdf0e10cSrcweir rAny.setValue(&bTmp, ::getBooleanCppuType());
142cdf0e10cSrcweir }
143cdf0e10cSrcweir break;
144cdf0e10cSrcweir case FIELD_PROP_FORMAT:
145cdf0e10cSrcweir rAny <<= (sal_Int32)GetFormat();
146cdf0e10cSrcweir break;
147cdf0e10cSrcweir default:
148cdf0e10cSrcweir return SwField::QueryValue(rAny, nWhichId);
149cdf0e10cSrcweir }
150cdf0e10cSrcweir return sal_True;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir /*-----------------09.03.98 08:04-------------------
153cdf0e10cSrcweir
154cdf0e10cSrcweir --------------------------------------------------*/
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)155cdf0e10cSrcweir sal_Bool SwUserField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir switch( nWhichId )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir case FIELD_PROP_BOOL1:
160cdf0e10cSrcweir if(*(sal_Bool*) rAny.getValue())
161cdf0e10cSrcweir nSubType &= (~nsSwExtendedSubType::SUB_INVISIBLE);
162cdf0e10cSrcweir else
163cdf0e10cSrcweir nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
164cdf0e10cSrcweir break;
165cdf0e10cSrcweir case FIELD_PROP_BOOL2:
166cdf0e10cSrcweir if(*(sal_Bool*) rAny.getValue())
167cdf0e10cSrcweir nSubType |= nsSwExtendedSubType::SUB_CMD;
168cdf0e10cSrcweir else
169cdf0e10cSrcweir nSubType &= (~nsSwExtendedSubType::SUB_CMD);
170cdf0e10cSrcweir break;
171cdf0e10cSrcweir case FIELD_PROP_FORMAT:
172cdf0e10cSrcweir {
173cdf0e10cSrcweir sal_Int32 nTmp = 0;
174cdf0e10cSrcweir rAny >>= nTmp;
175cdf0e10cSrcweir SetFormat(nTmp);
176cdf0e10cSrcweir }
177cdf0e10cSrcweir break;
178cdf0e10cSrcweir default:
179cdf0e10cSrcweir return SwField::PutValue(rAny, nWhichId);
180cdf0e10cSrcweir }
181cdf0e10cSrcweir return sal_True;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
184cdf0e10cSrcweir /*--------------------------------------------------------------------
185cdf0e10cSrcweir Beschreibung: Benutzerfeldtypen
186cdf0e10cSrcweir --------------------------------------------------------------------*/
187cdf0e10cSrcweir
SwUserFieldType(SwDoc * pDocPtr,const String & aNam)188cdf0e10cSrcweir SwUserFieldType::SwUserFieldType( SwDoc* pDocPtr, const String& aNam )
189cdf0e10cSrcweir : SwValueFieldType( pDocPtr, RES_USERFLD ),
190cdf0e10cSrcweir nValue( 0 ),
191cdf0e10cSrcweir nType(nsSwGetSetExpType::GSE_STRING)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir bValidValue = bDeleted = sal_False;
194cdf0e10cSrcweir aName = aNam;
195cdf0e10cSrcweir
196cdf0e10cSrcweir if (nType & nsSwGetSetExpType::GSE_STRING)
197cdf0e10cSrcweir EnableFormat(sal_False); // Numberformatter nicht einsetzen
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
Expand(sal_uInt32 nFmt,sal_uInt16 nSubType,sal_uInt16 nLng)200cdf0e10cSrcweir String SwUserFieldType::Expand(sal_uInt32 nFmt, sal_uInt16 nSubType, sal_uInt16 nLng)
201cdf0e10cSrcweir {
202cdf0e10cSrcweir String aStr(aContent);
203cdf0e10cSrcweir if((nType & nsSwGetSetExpType::GSE_EXPR) && !(nSubType & nsSwExtendedSubType::SUB_CMD))
204cdf0e10cSrcweir {
205cdf0e10cSrcweir EnableFormat(sal_True);
206cdf0e10cSrcweir aStr = ExpandValue(nValue, nFmt, nLng);
207cdf0e10cSrcweir }
208cdf0e10cSrcweir else
209cdf0e10cSrcweir EnableFormat(sal_False); // Numberformatter nicht einsetzen
210cdf0e10cSrcweir
211cdf0e10cSrcweir return aStr;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
Copy() const214cdf0e10cSrcweir SwFieldType* SwUserFieldType::Copy() const
215cdf0e10cSrcweir {
216cdf0e10cSrcweir SwUserFieldType *pTmp = new SwUserFieldType( GetDoc(), aName );
217cdf0e10cSrcweir pTmp->aContent = aContent;
218cdf0e10cSrcweir pTmp->nType = nType;
219cdf0e10cSrcweir pTmp->bValidValue = bValidValue;
220cdf0e10cSrcweir pTmp->nValue = nValue;
221cdf0e10cSrcweir pTmp->bDeleted = bDeleted;
222cdf0e10cSrcweir
223cdf0e10cSrcweir return pTmp;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir
GetName() const226cdf0e10cSrcweir const String& SwUserFieldType::GetName() const
227cdf0e10cSrcweir {
228cdf0e10cSrcweir return aName;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)231cdf0e10cSrcweir void SwUserFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir if( !pOld && !pNew )
234cdf0e10cSrcweir ChgValid( sal_False );
235cdf0e10cSrcweir
236cdf0e10cSrcweir NotifyClients( pOld, pNew );
237*1bf9188dSOliver-Rainer Wittmann
238*1bf9188dSOliver-Rainer Wittmann // update Input Fields as there might be Input Fields depending on this User Field
239*1bf9188dSOliver-Rainer Wittmann if ( !IsModifyLocked() )
240*1bf9188dSOliver-Rainer Wittmann {
241*1bf9188dSOliver-Rainer Wittmann LockModify();
242cdf0e10cSrcweir GetDoc()->GetSysFldType( RES_INPUTFLD )->UpdateFlds();
243*1bf9188dSOliver-Rainer Wittmann UnlockModify();
244*1bf9188dSOliver-Rainer Wittmann }
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
GetValue(SwCalc & rCalc)247cdf0e10cSrcweir double SwUserFieldType::GetValue( SwCalc& rCalc )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir if(bValidValue)
250cdf0e10cSrcweir return nValue;
251cdf0e10cSrcweir
252cdf0e10cSrcweir if(!rCalc.Push( this ))
253cdf0e10cSrcweir {
254cdf0e10cSrcweir rCalc.SetCalcError( CALC_SYNTAX );
255cdf0e10cSrcweir return 0;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir nValue = rCalc.Calculate( aContent ).GetDouble();
258cdf0e10cSrcweir rCalc.Pop( this );
259cdf0e10cSrcweir
260cdf0e10cSrcweir if( !rCalc.IsCalcError() )
261cdf0e10cSrcweir bValidValue = sal_True;
262cdf0e10cSrcweir else
263cdf0e10cSrcweir nValue = 0;
264cdf0e10cSrcweir
265cdf0e10cSrcweir return nValue;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir
GetContent(sal_uInt32 nFmt)268cdf0e10cSrcweir String SwUserFieldType::GetContent( sal_uInt32 nFmt )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir if (nFmt && nFmt != SAL_MAX_UINT32)
271cdf0e10cSrcweir {
272cdf0e10cSrcweir String sFormattedValue;
273cdf0e10cSrcweir Color* pCol = 0;
274cdf0e10cSrcweir
275cdf0e10cSrcweir SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
276cdf0e10cSrcweir
277cdf0e10cSrcweir pFormatter->GetOutputString(GetValue(), nFmt, sFormattedValue, &pCol);
278cdf0e10cSrcweir return sFormattedValue;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir else
281cdf0e10cSrcweir return aContent;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
SetContent(const String & rStr,sal_uInt32 nFmt)284cdf0e10cSrcweir void SwUserFieldType::SetContent( const String& rStr, sal_uInt32 nFmt )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir if( aContent != rStr )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir aContent = rStr;
289cdf0e10cSrcweir
290cdf0e10cSrcweir if (nFmt && nFmt != SAL_MAX_UINT32)
291cdf0e10cSrcweir {
292cdf0e10cSrcweir double fValue;
293cdf0e10cSrcweir
294cdf0e10cSrcweir SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
295cdf0e10cSrcweir
296cdf0e10cSrcweir if (pFormatter->IsNumberFormat(rStr, nFmt, fValue))
297cdf0e10cSrcweir {
298cdf0e10cSrcweir SetValue(fValue);
299cdf0e10cSrcweir aContent.Erase();
300cdf0e10cSrcweir DoubleToString(aContent, fValue, nFmt);
301cdf0e10cSrcweir }
302cdf0e10cSrcweir }
303cdf0e10cSrcweir
304cdf0e10cSrcweir sal_Bool bModified = GetDoc()->IsModified();
305cdf0e10cSrcweir GetDoc()->SetModified();
306cdf0e10cSrcweir if( !bModified ) // Bug 57028
307cdf0e10cSrcweir {
308cdf0e10cSrcweir GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
309cdf0e10cSrcweir }
310cdf0e10cSrcweir }
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
313cdf0e10cSrcweir /*-----------------04.03.98 17:05-------------------
314cdf0e10cSrcweir
315cdf0e10cSrcweir --------------------------------------------------*/
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const316cdf0e10cSrcweir sal_Bool SwUserFieldType::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
317cdf0e10cSrcweir {
318cdf0e10cSrcweir switch( nWhichId )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir case FIELD_PROP_DOUBLE:
321cdf0e10cSrcweir rAny <<= (double) nValue;
322cdf0e10cSrcweir break;
323cdf0e10cSrcweir case FIELD_PROP_PAR2:
324cdf0e10cSrcweir rAny <<= rtl::OUString(aContent);
325cdf0e10cSrcweir break;
326cdf0e10cSrcweir case FIELD_PROP_BOOL1:
327cdf0e10cSrcweir {
328cdf0e10cSrcweir sal_Bool bExpression = 0 != (nsSwGetSetExpType::GSE_EXPR&nType);
329cdf0e10cSrcweir rAny.setValue(&bExpression, ::getBooleanCppuType());
330cdf0e10cSrcweir }
331cdf0e10cSrcweir break;
332cdf0e10cSrcweir default:
333cdf0e10cSrcweir DBG_ERROR("illegal property");
334cdf0e10cSrcweir }
335cdf0e10cSrcweir return sal_True;
336cdf0e10cSrcweir }
337cdf0e10cSrcweir /*-----------------04.03.98 17:05-------------------
338cdf0e10cSrcweir
339cdf0e10cSrcweir --------------------------------------------------*/
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)340cdf0e10cSrcweir sal_Bool SwUserFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir switch( nWhichId )
343cdf0e10cSrcweir {
344cdf0e10cSrcweir case FIELD_PROP_DOUBLE:
345cdf0e10cSrcweir {
346cdf0e10cSrcweir double fVal = 0;
347cdf0e10cSrcweir rAny >>= fVal;
348cdf0e10cSrcweir nValue = fVal;
349cdf0e10cSrcweir
350cdf0e10cSrcweir // Folgende Zeile ist eigentlich falsch, da die Sprache unbekannt ist
351cdf0e10cSrcweir // (haengt am Feld) und aContent daher auch eigentlich ans Feld gehoeren
352cdf0e10cSrcweir // muesste. Jedes Feld kann eine andere Sprache, aber den gleichen Inhalt
353cdf0e10cSrcweir // haben, nur die Formatierung ist unterschiedlich.
354cdf0e10cSrcweir DoubleToString(aContent, nValue, (sal_uInt16)LANGUAGE_SYSTEM);
355cdf0e10cSrcweir }
356cdf0e10cSrcweir break;
357cdf0e10cSrcweir case FIELD_PROP_PAR2:
358cdf0e10cSrcweir ::GetString( rAny, aContent );
359cdf0e10cSrcweir break;
360cdf0e10cSrcweir case FIELD_PROP_BOOL1:
361cdf0e10cSrcweir if(*(sal_Bool*)rAny.getValue())
362cdf0e10cSrcweir {
363cdf0e10cSrcweir nType |= nsSwGetSetExpType::GSE_EXPR;
364cdf0e10cSrcweir nType &= ~nsSwGetSetExpType::GSE_STRING;
365cdf0e10cSrcweir }
366cdf0e10cSrcweir else
367cdf0e10cSrcweir {
368cdf0e10cSrcweir nType &= ~nsSwGetSetExpType::GSE_EXPR;
369cdf0e10cSrcweir nType |= nsSwGetSetExpType::GSE_STRING;
370cdf0e10cSrcweir }
371cdf0e10cSrcweir break;
372cdf0e10cSrcweir default:
373cdf0e10cSrcweir DBG_ERROR("illegal property");
374cdf0e10cSrcweir }
375cdf0e10cSrcweir return sal_True;
376cdf0e10cSrcweir }
377cdf0e10cSrcweir
378cdf0e10cSrcweir
379cdf0e10cSrcweir
380