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: dateitem.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_svtools.hxx"
34 // include ---------------------------------------------------------------
36 #define _DATETIMEITEM_CXX
37 #include <svtools/dateitem.hxx>
39 #include <unotools/intlwrapper.hxx>
40 #include <comphelper/processfactory.hxx>
43 #include <tools/stream.hxx>
44 #include <tools/debug.hxx>
45 #include <tools/datetime.hxx>
46 #include <com/sun/star/uno/Any.hxx>
47 #include <com/sun/star/util/DateTime.hpp>
48 #include <com/sun/star/lang/Locale.hpp>
51 #include <vcl/svapp.hxx>
53 #include <svtools/svtdata.hxx>
54 #include <svtools/svtools.hrc>
56 // STATIC DATA -----------------------------------------------------------
58 DBG_NAME(SfxDateTimeItem
)
61 // -----------------------------------------------------------------------
63 TYPEINIT1(SfxDateTimeItem
, SfxPoolItem
);
65 // -----------------------------------------------------------------------
67 SfxDateTimeItem::SfxDateTimeItem( USHORT which
) :
70 DBG_CTOR(SfxDateTimeItem
, 0);
73 // -----------------------------------------------------------------------
75 SfxDateTimeItem::SfxDateTimeItem( USHORT which
, const DateTime
& rDT
) :
80 DBG_CTOR(SfxDateTimeItem
, 0);
83 // -----------------------------------------------------------------------
85 SfxDateTimeItem::SfxDateTimeItem( const SfxDateTimeItem
& rItem
) :
87 aDateTime( rItem
.aDateTime
)
89 DBG_CTOR(SfxDateTimeItem
, 0);
92 // -----------------------------------------------------------------------
94 int SfxDateTimeItem::operator==( const SfxPoolItem
& rItem
) const
96 DBG_CHKTHIS(SfxDateTimeItem
, 0);
97 DBG_ASSERT( SfxPoolItem::operator==( rItem
), "unequal type" );
98 return ( ( (SfxDateTimeItem
&)rItem
).aDateTime
== aDateTime
);
101 // -----------------------------------------------------------------------
103 int SfxDateTimeItem::Compare( const SfxPoolItem
& rItem
) const
105 DBG_CHKTHIS(SfxDateTimeItem
, 0);
106 DBG_ASSERT( SfxPoolItem::operator==( rItem
), "unequal type" );
108 // da X.Compare( Y ) am String einem Compare( Y, X ) entspricht,
109 // vergleichen wir hier Y mit X
110 if ( ( (const SfxDateTimeItem
&)rItem
).aDateTime
< aDateTime
)
112 else if ( ( (const SfxDateTimeItem
&)rItem
).aDateTime
== aDateTime
)
118 // -----------------------------------------------------------------------
120 SfxPoolItem
* SfxDateTimeItem::Create( SvStream
& rStream
, USHORT
) const
122 DBG_CHKTHIS(SfxDateTimeItem
, 0);
123 sal_uInt32 nDate
= 0;
127 DateTime
aDT(nDate
, nTime
);
128 return new SfxDateTimeItem( Which(), aDT
);
131 // -----------------------------------------------------------------------
133 SvStream
& SfxDateTimeItem::Store( SvStream
& rStream
, USHORT
) const
135 DBG_CHKTHIS(SfxDateTimeItem
, 0);
136 rStream
<< aDateTime
.GetDate();
137 rStream
<< aDateTime
.GetTime();
141 // -----------------------------------------------------------------------
143 SfxPoolItem
* SfxDateTimeItem::Clone( SfxItemPool
* ) const
145 DBG_CHKTHIS(SfxDateTimeItem
, 0);
146 return new SfxDateTimeItem( *this );
149 // -----------------------------------------------------------------------
151 SfxItemPresentation
SfxDateTimeItem::GetPresentation
153 SfxItemPresentation
/*ePresentation*/,
154 SfxMapUnit
/*eCoreMetric*/,
155 SfxMapUnit
/*ePresentationMetric*/,
157 const IntlWrapper
* pIntlWrapper
160 DBG_CHKTHIS(SfxDateTimeItem
, 0);
161 if (aDateTime
.IsValid())
164 rText
= pIntlWrapper
->getLocaleData()->getDate(aDateTime
);
165 rText
.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
166 rText
+= pIntlWrapper
->getLocaleData()->getTime(aDateTime
);
170 DBG_WARNING("SfxDateTimeItem::GetPresentation():"
171 " Using default en_US IntlWrapper");
172 const IntlWrapper
aIntlWrapper(
173 ::comphelper::getProcessServiceFactory(), LANGUAGE_ENGLISH_US
);
174 rText
= aIntlWrapper
.getLocaleData()->getDate(aDateTime
);
175 rText
.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
176 rText
+= aIntlWrapper
.getLocaleData()->getTime(aDateTime
);
180 return SFX_ITEM_PRESENTATION_NAMELESS
;
183 //----------------------------------------------------------------------------
185 BOOL
SfxDateTimeItem::PutValue( const com::sun::star::uno::Any
& rVal
,
188 nMemberId
&= ~CONVERT_TWIPS
;
189 com::sun::star::util::DateTime aValue
;
190 if ( rVal
>>= aValue
)
192 aDateTime
= DateTime( Date( aValue
.Day
,
198 aValue
.HundredthSeconds
) );
202 DBG_ERROR( "SfxDateTimeItem::PutValue - Wrong type!" );
206 //----------------------------------------------------------------------------
208 BOOL
SfxDateTimeItem::QueryValue( com::sun::star::uno::Any
& rVal
,
209 BYTE nMemberId
) const
211 nMemberId
&= ~CONVERT_TWIPS
;
212 com::sun::star::util::DateTime
aValue( aDateTime
.Get100Sec(),
217 aDateTime
.GetMonth(),
218 aDateTime
.GetYear() );
223 // -----------------------------------------------------------------------
224 // -----------------------------------------------------------------------
225 // -----------------------------------------------------------------------
227 TYPEINIT1(SfxColumnDateTimeItem
, SfxDateTimeItem
);
230 SfxColumnDateTimeItem::SfxColumnDateTimeItem( USHORT which
) :
231 SfxDateTimeItem( which
)
234 SfxColumnDateTimeItem::SfxColumnDateTimeItem( USHORT which
, const DateTime
& rDT
) :
235 SfxDateTimeItem( which
, rDT
)
238 SfxColumnDateTimeItem::SfxColumnDateTimeItem( const SfxDateTimeItem
& rCpy
) :
239 SfxDateTimeItem( rCpy
)
242 SfxPoolItem
* SfxColumnDateTimeItem::Clone( SfxItemPool
* ) const
244 return new SfxColumnDateTimeItem( *this );
247 SfxItemPresentation
SfxColumnDateTimeItem::GetPresentation
249 SfxItemPresentation
/*ePresentation*/,
250 SfxMapUnit
/*eCoreMetric*/,
251 SfxMapUnit
/*ePresentationMetric*/,
253 const IntlWrapper
* pIntlWrapper
256 DBG_ASSERT(pIntlWrapper
,
257 "SfxColumnDateTimeItem::GetPresentation():"
258 " Using default en_US IntlWrapper");
260 ::com::sun::star::lang::Locale aLocale
;
261 if (GetDateTime() == DateTime(Date(1, 2, 3), Time(3, 2, 1)))
262 rText
= String(SvtResId(STR_COLUM_DT_AUTO
,
264 pIntlWrapper
->getLocale() :
266 else if (pIntlWrapper
)
268 rText
= pIntlWrapper
->getLocaleData()->getDate(GetDateTime());
269 rText
.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
270 rText
+= pIntlWrapper
->getLocaleData()->getTime(GetDateTime());
274 const IntlWrapper
aIntlWrapper(
275 ::comphelper::getProcessServiceFactory(), LANGUAGE_ENGLISH_US
);
276 rText
= aIntlWrapper
.getLocaleData()->getDate(GetDateTime());
277 rText
.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
278 rText
+= aIntlWrapper
.getLocaleData()->getTime(GetDateTime());
280 return SFX_ITEM_PRESENTATION_NAMELESS
;