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 : #ifndef INCLUDED_UNOTOOLS_CALENDARWRAPPER_HXX
21 : #define INCLUDED_UNOTOOLS_CALENDARWRAPPER_HXX
22 :
23 : #include <tools/datetime.hxx>
24 : #include <com/sun/star/uno/Reference.hxx>
25 : #include <com/sun/star/uno/Sequence.hxx>
26 : #include <com/sun/star/i18n/Calendar2.hpp>
27 : #include <com/sun/star/lang/Locale.hpp>
28 : #include <unotools/unotoolsdllapi.h>
29 :
30 : namespace com { namespace sun { namespace star {
31 : namespace uno {
32 : class XComponentContext;
33 : }
34 : }}}
35 :
36 : namespace com { namespace sun { namespace star {
37 : namespace i18n {
38 : class XCalendar3;
39 : }
40 : }}}
41 :
42 : class UNOTOOLS_DLLPUBLIC CalendarWrapper
43 : {
44 : ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCalendar3 > xC;
45 :
46 : DateTime aEpochStart; // 1Jan1970
47 :
48 : public:
49 : CalendarWrapper(
50 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & rxContext
51 : );
52 : ~CalendarWrapper();
53 :
54 : // wrapper implementations of XCalendar
55 :
56 : void loadDefaultCalendar( const ::com::sun::star::lang::Locale& rLocale );
57 : void loadCalendar( const OUString& rUniqueID, const ::com::sun::star::lang::Locale& rLocale );
58 : ::com::sun::star::uno::Sequence< OUString > getAllCalendars( const ::com::sun::star::lang::Locale& rLocale ) const;
59 : OUString getUniqueID() const;
60 : /// set UTC date/time
61 : void setDateTime( double fTimeInDays );
62 : /// get UTC date/time
63 : double getDateTime() const;
64 : /// convenience method to set local date/time
65 : void setLocalDateTime( double fTimeInDays );
66 : /// convenience method to get local date/time
67 : double getLocalDateTime() const;
68 :
69 : // wrapper implementations of XCalendar
70 :
71 : void setValue( sal_Int16 nFieldIndex, sal_Int16 nValue );
72 : bool isValid() const;
73 : sal_Int16 getValue( sal_Int16 nFieldIndex ) const;
74 : void addValue( sal_Int16 nFieldIndex, sal_Int32 nAmount );
75 : sal_Int16 getFirstDayOfWeek() const;
76 : sal_Int16 getNumberOfMonthsInYear() const;
77 : sal_Int16 getNumberOfDaysInWeek() const;
78 : OUString getDisplayName( sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType ) const;
79 :
80 : /** Convenience method to get timezone offset in milliseconds, taking both
81 : fields ZONE_OFFSET and ZONE_OFFSET_SECOND_MILLIS into account. */
82 : sal_Int32 getZoneOffsetInMillis() const;
83 : /** Convenience method to get DST offset in milliseconds, taking both
84 : fields DST_OFFSET and DST_OFFSET_SECOND_MILLIS into account. */
85 : sal_Int32 getDSTOffsetInMillis() const;
86 :
87 : // wrapper implementations of XExtendedCalendar
88 :
89 : OUString getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) const;
90 :
91 : // wrapper implementations of XCalendar3
92 :
93 : ::com::sun::star::i18n::Calendar2 getLoadedCalendar() const;
94 : ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > getDays() const;
95 : ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > getMonths() const;
96 : ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > getGenitiveMonths() const;
97 : ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > getPartitiveMonths() const;
98 :
99 : // convenience methods
100 :
101 : /// get epoch start (should be 01Jan1970)
102 2768 : inline const DateTime& getEpochStart() const
103 2768 : { return aEpochStart; }
104 :
105 : /// set a local (!) Gregorian DateTime
106 318 : inline void setGregorianDateTime( const DateTime& rDateTime )
107 318 : { setLocalDateTime( rDateTime - aEpochStart ); }
108 :
109 : /// get the DateTime as a local (!) Gregorian DateTime
110 : inline DateTime getGregorianDateTime() const
111 : { return aEpochStart + getLocalDateTime(); }
112 :
113 : private:
114 :
115 : /** get timezone or DST offset in milliseconds, fields are
116 : CalendarFieldIndex ZONE_OFFSET and ZONE_OFFSET_SECOND_MILLIS
117 : respectively DST_OFFSET and DST_OFFSET_SECOND_MILLIS.
118 : */
119 : sal_Int32 getCombinedOffsetInMillis( sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex ) const;
120 : };
121 :
122 : #endif
123 :
124 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|