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 <svl/dateitem.hxx>
21 : #include <svl/svl.hrc>
22 :
23 : #include <unotools/intlwrapper.hxx>
24 : #include <comphelper/processfactory.hxx>
25 :
26 : #include <tools/stream.hxx>
27 : #include <tools/debug.hxx>
28 : #include <tools/datetime.hxx>
29 : #include <com/sun/star/uno/Any.hxx>
30 : #include <com/sun/star/util/DateTime.hpp>
31 : #include <com/sun/star/lang/Locale.hpp>
32 :
33 : // STATIC DATA -----------------------------------------------------------
34 :
35 : DBG_NAME(SfxDateTimeItem)
36 :
37 :
38 : // -----------------------------------------------------------------------
39 :
40 0 : TYPEINIT1(SfxDateTimeItem, SfxPoolItem);
41 :
42 : // -----------------------------------------------------------------------
43 :
44 0 : SfxDateTimeItem::SfxDateTimeItem( sal_uInt16 which, const DateTime& rDT ) :
45 : SfxPoolItem( which ),
46 0 : aDateTime( rDT )
47 :
48 : {
49 : DBG_CTOR(SfxDateTimeItem, 0);
50 0 : }
51 :
52 : // -----------------------------------------------------------------------
53 :
54 0 : SfxDateTimeItem::SfxDateTimeItem( const SfxDateTimeItem& rItem ) :
55 : SfxPoolItem( rItem ),
56 0 : aDateTime( rItem.aDateTime )
57 : {
58 : DBG_CTOR(SfxDateTimeItem, 0);
59 0 : }
60 :
61 : // -----------------------------------------------------------------------
62 :
63 0 : int SfxDateTimeItem::operator==( const SfxPoolItem& rItem ) const
64 : {
65 : DBG_CHKTHIS(SfxDateTimeItem, 0);
66 : DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
67 0 : return ( ( (SfxDateTimeItem&)rItem ).aDateTime == aDateTime );
68 : }
69 :
70 : // -----------------------------------------------------------------------
71 :
72 0 : int SfxDateTimeItem::Compare( const SfxPoolItem& rItem ) const
73 : {
74 : DBG_CHKTHIS(SfxDateTimeItem, 0);
75 : DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
76 :
77 : // da X.Compare( Y ) am String einem Compare( Y, X ) entspricht,
78 : // vergleichen wir hier Y mit X
79 0 : if ( ( (const SfxDateTimeItem&)rItem ).aDateTime < aDateTime )
80 0 : return -1;
81 0 : else if ( ( (const SfxDateTimeItem&)rItem ).aDateTime == aDateTime )
82 0 : return 0;
83 : else
84 0 : return 1;
85 : }
86 :
87 : // -----------------------------------------------------------------------
88 :
89 0 : SfxPoolItem* SfxDateTimeItem::Create( SvStream& rStream, sal_uInt16 ) const
90 : {
91 : DBG_CHKTHIS(SfxDateTimeItem, 0);
92 0 : sal_uInt32 nDate = 0;
93 0 : sal_Int32 nTime = 0;
94 0 : rStream >> nDate;
95 0 : rStream >> nTime;
96 0 : DateTime aDT(nDate, nTime);
97 0 : return new SfxDateTimeItem( Which(), aDT );
98 : }
99 :
100 : // -----------------------------------------------------------------------
101 :
102 0 : SvStream& SfxDateTimeItem::Store( SvStream& rStream, sal_uInt16 ) const
103 : {
104 : DBG_CHKTHIS(SfxDateTimeItem, 0);
105 0 : rStream << aDateTime.GetDate();
106 0 : rStream << aDateTime.GetTime();
107 0 : return rStream;
108 : }
109 :
110 : // -----------------------------------------------------------------------
111 :
112 0 : SfxPoolItem* SfxDateTimeItem::Clone( SfxItemPool* ) const
113 : {
114 : DBG_CHKTHIS(SfxDateTimeItem, 0);
115 0 : return new SfxDateTimeItem( *this );
116 : }
117 :
118 : // -----------------------------------------------------------------------
119 :
120 0 : SfxItemPresentation SfxDateTimeItem::GetPresentation
121 : (
122 : SfxItemPresentation /*ePresentation*/,
123 : SfxMapUnit /*eCoreMetric*/,
124 : SfxMapUnit /*ePresentationMetric*/,
125 : XubString& rText,
126 : const IntlWrapper * pIntlWrapper
127 : ) const
128 : {
129 : DBG_CHKTHIS(SfxDateTimeItem, 0);
130 0 : if (aDateTime.IsValidDate())
131 0 : if (pIntlWrapper)
132 : {
133 0 : rText = pIntlWrapper->getLocaleData()->getDate(aDateTime);
134 0 : rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
135 0 : rText += pIntlWrapper->getLocaleData()->getTime(aDateTime);
136 : }
137 : else
138 : {
139 : DBG_WARNING("SfxDateTimeItem::GetPresentation():"
140 : " Using default en_US IntlWrapper");
141 0 : const IntlWrapper aIntlWrapper( LanguageTag( LANGUAGE_ENGLISH_US) );
142 0 : rText = aIntlWrapper.getLocaleData()->getDate(aDateTime);
143 0 : rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
144 0 : rText += aIntlWrapper.getLocaleData()->getTime(aDateTime);
145 : }
146 : else
147 0 : rText.Erase();
148 0 : return SFX_ITEM_PRESENTATION_NAMELESS;
149 : }
150 :
151 : //----------------------------------------------------------------------------
152 : // virtual
153 0 : bool SfxDateTimeItem::PutValue( const com::sun::star::uno::Any& rVal,
154 : sal_uInt8 nMemberId )
155 : {
156 0 : nMemberId &= ~CONVERT_TWIPS;
157 0 : com::sun::star::util::DateTime aValue;
158 0 : if ( rVal >>= aValue )
159 : {
160 : aDateTime = DateTime( Date( aValue.Day,
161 : aValue.Month,
162 : aValue.Year ),
163 : Time( aValue.Hours,
164 : aValue.Minutes,
165 : aValue.Seconds,
166 0 : aValue.HundredthSeconds ) );
167 0 : return true;
168 : }
169 :
170 : OSL_FAIL( "SfxDateTimeItem::PutValue - Wrong type!" );
171 0 : return false;
172 : }
173 :
174 : //----------------------------------------------------------------------------
175 : // virtual
176 0 : bool SfxDateTimeItem::QueryValue( com::sun::star::uno::Any& rVal,
177 : sal_uInt8 nMemberId ) const
178 : {
179 0 : nMemberId &= ~CONVERT_TWIPS;
180 0 : com::sun::star::util::DateTime aValue( aDateTime.Get100Sec(),
181 0 : aDateTime.GetSec(),
182 0 : aDateTime.GetMin(),
183 0 : aDateTime.GetHour(),
184 0 : aDateTime.GetDay(),
185 0 : aDateTime.GetMonth(),
186 0 : aDateTime.GetYear() );
187 0 : rVal <<= aValue;
188 0 : return true;
189 : }
190 :
191 :
192 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|