1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: usrfld.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <svtools/zforlist.hxx>
36 #include <svtools/zformat.hxx>
37 #include <svx/svdmodel.hxx>
47 #include <unofldmid.h>
50 using namespace ::com::sun::star
;
51 using ::rtl::OUString
;
52 /*--------------------------------------------------------------------
53 Beschreibung: Benutzerfelder
54 --------------------------------------------------------------------*/
56 SwUserField::SwUserField(SwUserFieldType
* pTyp
, sal_uInt16 nSub
, sal_uInt32 nFmt
)
57 : SwValueField(pTyp
, nFmt
),
62 String
SwUserField::Expand() const
65 if(!(nSubType
& nsSwExtendedSubType::SUB_INVISIBLE
))
66 sStr
= ((SwUserFieldType
*)GetTyp())->Expand(GetFormat(), nSubType
, GetLanguage());
71 SwField
* SwUserField::Copy() const
73 SwField
* pTmp
= new SwUserField((SwUserFieldType
*)GetTyp(), nSubType
, GetFormat());
74 pTmp
->SetAutomaticLanguage(IsAutomaticLanguage());
78 String
SwUserField::GetCntnt(sal_Bool bName
) const
81 { String
aStr(SwFieldType::GetTypeStr(TYP_USERFLD
));
83 aStr
+= GetTyp()->GetName();
84 aStr
.AppendAscii(" = ");
85 aStr
+= ((SwUserFieldType
*)GetTyp())->GetContent();
91 double SwUserField::GetValue() const
93 return ((SwUserFieldType
*)GetTyp())->GetValue();
96 void SwUserField::SetValue( const double& rVal
)
98 ((SwUserFieldType
*)GetTyp())->SetValue(rVal
);
101 /*--------------------------------------------------------------------
103 --------------------------------------------------------------------*/
105 const String
& SwUserField::GetPar1() const
107 return ((SwUserFieldType
*)GetTyp())->GetName();
110 /*--------------------------------------------------------------------
111 Beschreibung: Content
112 --------------------------------------------------------------------*/
114 String
SwUserField::GetPar2() const
116 return ((SwUserFieldType
*)GetTyp())->GetContent(GetFormat());
119 void SwUserField::SetPar2(const String
& rStr
)
121 ((SwUserFieldType
*)GetTyp())->SetContent(rStr
, GetFormat());
124 sal_uInt16
SwUserField::GetSubType() const
126 return ((SwUserFieldType
*)GetTyp())->GetType() | nSubType
;
129 void SwUserField::SetSubType(sal_uInt16 nSub
)
131 ((SwUserFieldType
*)GetTyp())->SetType(nSub
& 0x00ff);
132 nSubType
= nSub
& 0xff00;
135 /*-----------------09.03.98 08:04-------------------
137 --------------------------------------------------*/
138 BOOL
SwUserField::QueryValue( uno::Any
& rAny
, USHORT nWhichId
) const
142 case FIELD_PROP_BOOL2
:
144 BOOL bTmp
= 0 != (nSubType
& nsSwExtendedSubType::SUB_CMD
);
145 rAny
.setValue(&bTmp
, ::getBooleanCppuType());
148 case FIELD_PROP_BOOL1
:
150 BOOL bTmp
= 0 == (nSubType
& nsSwExtendedSubType::SUB_INVISIBLE
);
151 rAny
.setValue(&bTmp
, ::getBooleanCppuType());
154 case FIELD_PROP_FORMAT
:
155 rAny
<<= (sal_Int32
)GetFormat();
158 return SwField::QueryValue(rAny
, nWhichId
);
162 /*-----------------09.03.98 08:04-------------------
164 --------------------------------------------------*/
165 sal_Bool
SwUserField::PutValue( const uno::Any
& rAny
, USHORT nWhichId
)
169 case FIELD_PROP_BOOL1
:
170 if(*(sal_Bool
*) rAny
.getValue())
171 nSubType
&= (~nsSwExtendedSubType::SUB_INVISIBLE
);
173 nSubType
|= nsSwExtendedSubType::SUB_INVISIBLE
;
175 case FIELD_PROP_BOOL2
:
176 if(*(sal_Bool
*) rAny
.getValue())
177 nSubType
|= nsSwExtendedSubType::SUB_CMD
;
179 nSubType
&= (~nsSwExtendedSubType::SUB_CMD
);
181 case FIELD_PROP_FORMAT
:
189 return SwField::PutValue(rAny
, nWhichId
);
194 /*--------------------------------------------------------------------
195 Beschreibung: Benutzerfeldtypen
196 --------------------------------------------------------------------*/
198 SwUserFieldType::SwUserFieldType( SwDoc
* pDocPtr
, const String
& aNam
)
199 : SwValueFieldType( pDocPtr
, RES_USERFLD
),
201 nType(nsSwGetSetExpType::GSE_STRING
)
203 bValidValue
= bDeleted
= sal_False
;
206 if (nType
& nsSwGetSetExpType::GSE_STRING
)
207 EnableFormat(sal_False
); // Numberformatter nicht einsetzen
210 String
SwUserFieldType::Expand(sal_uInt32 nFmt
, sal_uInt16 nSubType
, sal_uInt16 nLng
)
212 String
aStr(aContent
);
213 if((nType
& nsSwGetSetExpType::GSE_EXPR
) && !(nSubType
& nsSwExtendedSubType::SUB_CMD
))
215 EnableFormat(sal_True
);
216 aStr
= ExpandValue(nValue
, nFmt
, nLng
);
219 EnableFormat(sal_False
); // Numberformatter nicht einsetzen
224 SwFieldType
* SwUserFieldType::Copy() const
226 SwUserFieldType
*pTmp
= new SwUserFieldType( GetDoc(), aName
);
227 pTmp
->aContent
= aContent
;
229 pTmp
->bValidValue
= bValidValue
;
230 pTmp
->nValue
= nValue
;
231 pTmp
->bDeleted
= bDeleted
;
236 const String
& SwUserFieldType::GetName() const
241 void SwUserFieldType::Modify( SfxPoolItem
* pOld
, SfxPoolItem
* pNew
)
244 ChgValid( sal_False
);
246 SwModify::Modify( pOld
, pNew
);
247 // und ggfs. am UserFeld haengende InputFelder updaten!
248 GetDoc()->GetSysFldType( RES_INPUTFLD
)->UpdateFlds();
251 double SwUserFieldType::GetValue( SwCalc
& rCalc
)
256 if(!rCalc
.Push( this ))
258 rCalc
.SetCalcError( CALC_SYNTAX
);
261 nValue
= rCalc
.Calculate( aContent
).GetDouble();
264 if( !rCalc
.IsCalcError() )
265 bValidValue
= sal_True
;
272 String
SwUserFieldType::GetContent( sal_uInt32 nFmt
)
274 if (nFmt
&& nFmt
!= SAL_MAX_UINT32
)
276 String sFormattedValue
;
279 SvNumberFormatter
* pFormatter
= GetDoc()->GetNumberFormatter();
281 pFormatter
->GetOutputString(GetValue(), nFmt
, sFormattedValue
, &pCol
);
282 return sFormattedValue
;
288 void SwUserFieldType::SetContent( const String
& rStr
, sal_uInt32 nFmt
)
290 if( aContent
!= rStr
)
294 if (nFmt
&& nFmt
!= SAL_MAX_UINT32
)
298 SvNumberFormatter
* pFormatter
= GetDoc()->GetNumberFormatter();
300 if (pFormatter
->IsNumberFormat(rStr
, nFmt
, fValue
))
304 DoubleToString(aContent
, fValue
, nFmt
);
308 sal_Bool bModified
= GetDoc()->IsModified();
309 GetDoc()->SetModified();
310 if( !bModified
) // Bug 57028
311 GetDoc()->SetUndoNoResetModified();
315 /*-----------------04.03.98 17:05-------------------
317 --------------------------------------------------*/
318 BOOL
SwUserFieldType::QueryValue( uno::Any
& rAny
, USHORT nWhichId
) const
322 case FIELD_PROP_DOUBLE
:
323 rAny
<<= (double) nValue
;
325 case FIELD_PROP_PAR2
:
326 rAny
<<= rtl::OUString(aContent
);
328 case FIELD_PROP_BOOL1
:
330 BOOL bExpression
= 0 != (nsSwGetSetExpType::GSE_EXPR
&nType
);
331 rAny
.setValue(&bExpression
, ::getBooleanCppuType());
335 DBG_ERROR("illegal property");
339 /*-----------------04.03.98 17:05-------------------
341 --------------------------------------------------*/
342 BOOL
SwUserFieldType::PutValue( const uno::Any
& rAny
, USHORT nWhichId
)
346 case FIELD_PROP_DOUBLE
:
352 // Folgende Zeile ist eigentlich falsch, da die Sprache unbekannt ist
353 // (haengt am Feld) und aContent daher auch eigentlich ans Feld gehoeren
354 // muesste. Jedes Feld kann eine andere Sprache, aber den gleichen Inhalt
355 // haben, nur die Formatierung ist unterschiedlich.
356 DoubleToString(aContent
, nValue
, (sal_uInt16
)LANGUAGE_SYSTEM
);
359 case FIELD_PROP_PAR2
:
360 ::GetString( rAny
, aContent
);
362 case FIELD_PROP_BOOL1
:
363 if(*(sal_Bool
*)rAny
.getValue())
365 nType
|= nsSwGetSetExpType::GSE_EXPR
;
366 nType
&= ~nsSwGetSetExpType::GSE_STRING
;
370 nType
&= ~nsSwGetSetExpType::GSE_EXPR
;
371 nType
|= nsSwGetSetExpType::GSE_STRING
;
375 DBG_ERROR("illegal property");