1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _I18N_CALENDAR_GREGORIAN_HXX_
24 #define _I18N_CALENDAR_GREGORIAN_HXX_
25 
26 #include "calendarImpl.hxx"
27 #include "nativenumbersupplier.hxx"
28 
29 #include "warnings_guard_unicode_calendar.h"
30 
31 //	----------------------------------------------------
32 //	class Calendar_gregorian
33 //	----------------------------------------------------
34 
35 namespace com { namespace sun { namespace star { namespace i18n {
36 
37 struct Era {
38     sal_Int32 year;
39     sal_Int32 month;
40     sal_Int32 day;
41 };
42 
43 const sal_Int16 FIELD_INDEX_COUNT = CalendarFieldIndex::FIELD_COUNT2;
44 
45 class Calendar_gregorian : public CalendarImpl
46 {
47 public:
48 
49     // Constructors
50     Calendar_gregorian();
51     Calendar_gregorian(Era *_eraArray);
52     void SAL_CALL init(Era *_eraArray);
53 
54     /**
55     * Destructor
56     */
57     ~Calendar_gregorian();
58 
59     // Methods in XCalendar
60     virtual void SAL_CALL loadCalendar(const rtl::OUString& uniqueID, const com::sun::star::lang::Locale& rLocale) throw(com::sun::star::uno::RuntimeException);
61     virtual void SAL_CALL setDateTime(double nTimeInDays) throw(com::sun::star::uno::RuntimeException);
62     virtual double SAL_CALL getDateTime() throw(com::sun::star::uno::RuntimeException);
63     virtual void SAL_CALL setValue( sal_Int16 nFieldIndex, sal_Int16 nValue ) throw(com::sun::star::uno::RuntimeException);
64     virtual sal_Int16 SAL_CALL getValue(sal_Int16 nFieldIndex) throw(com::sun::star::uno::RuntimeException);
65     virtual void SAL_CALL addValue(sal_Int16 nFieldIndex, sal_Int32 nAmount) throw(com::sun::star::uno::RuntimeException);
66     virtual sal_Bool SAL_CALL isValid() throw (com::sun::star::uno::RuntimeException);
67     virtual Calendar SAL_CALL getLoadedCalendar() throw(com::sun::star::uno::RuntimeException);
68     virtual rtl::OUString SAL_CALL getUniqueID() throw(com::sun::star::uno::RuntimeException);
69     virtual sal_Int16 SAL_CALL getFirstDayOfWeek() throw(com::sun::star::uno::RuntimeException);
70     virtual void SAL_CALL setFirstDayOfWeek(sal_Int16 nDay) throw(com::sun::star::uno::RuntimeException);
71     virtual void SAL_CALL setMinimumNumberOfDaysForFirstWeek(sal_Int16 nDays) throw(com::sun::star::uno::RuntimeException);
72     virtual sal_Int16 SAL_CALL getMinimumNumberOfDaysForFirstWeek() throw(com::sun::star::uno::RuntimeException);
73     virtual sal_Int16 SAL_CALL getNumberOfMonthsInYear() throw(com::sun::star::uno::RuntimeException);
74     virtual sal_Int16 SAL_CALL getNumberOfDaysInWeek() throw(com::sun::star::uno::RuntimeException);
75     virtual com::sun::star::uno::Sequence < CalendarItem > SAL_CALL getMonths() throw(com::sun::star::uno::RuntimeException);
76     virtual com::sun::star::uno::Sequence < CalendarItem > SAL_CALL getDays() throw(com::sun::star::uno::RuntimeException);
77     virtual rtl::OUString SAL_CALL getDisplayName(sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType) throw(com::sun::star::uno::RuntimeException);
78 
79     // Methods in XExtendedCalendar
80     virtual rtl::OUString SAL_CALL getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) throw (com::sun::star::uno::RuntimeException);
81 
82     //XServiceInfo
83     virtual rtl::OUString SAL_CALL getImplementationName() throw(com::sun::star::uno::RuntimeException);
84     virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw(com::sun::star::uno::RuntimeException);
85     virtual com::sun::star::uno::Sequence < rtl::OUString > SAL_CALL getSupportedServiceNames() throw(com::sun::star::uno::RuntimeException);
86 
87 protected:
88     Era *eraArray;
89     icu::Calendar *body;
90     NativeNumberSupplier aNatNum;
91     const sal_Char* cCalendar;
92     com::sun::star::lang::Locale aLocale;
93     sal_uInt32 fieldSet;
94     sal_Int16 fieldValue[FIELD_INDEX_COUNT];
95     sal_Int16 fieldSetValue[FIELD_INDEX_COUNT];
96 
97     virtual void mapToGregorian() throw(com::sun::star::uno::RuntimeException);
98     virtual void mapFromGregorian() throw(com::sun::star::uno::RuntimeException);
99     void getValue() throw(com::sun::star::uno::RuntimeException);
100 
101 private:
102     Calendar aCalendar;
103 
104     /** Submit fieldSetValue array according to fieldSet. */
105     void submitFields() throw(com::sun::star::uno::RuntimeException);
106     /** Submit fieldSetValue array according to fieldSet, plus YMDhms if >=0,
107         plus zone and DST if != 0 */
108     void submitValues( sal_Int32 nYear, sal_Int32 nMonth, sal_Int32 nDay, sal_Int32 nHour, sal_Int32 nMinute, sal_Int32 nSecond, sal_Int32 nMilliSecond, sal_Int32 nZone, sal_Int32 nDST) throw(com::sun::star::uno::RuntimeException);
109     /** Set fields internally. */
110     void setValue() throw(com::sun::star::uno::RuntimeException);
111     /** Obtain combined field values for timezone offset (minutes+secondmillis)
112         in milliseconds and whether fields were set. */
113     bool getZoneOffset( sal_Int32 & o_nOffset ) const;
114     /** Obtain combined field values for DST offset (minutes+secondmillis) in
115         milliseconds and whether fields were set. */
116     bool getDSTOffset( sal_Int32 & o_nOffset ) const;
117     /** Used by getZoneOffset() and getDSTOffset(). Parent is
118         CalendarFieldIndex for offset in minutes, child is CalendarFieldIndex
119         for offset in milliseconds. */
120     bool getCombinedOffset( sal_Int32 & o_nOffset, sal_Int16 nParentFieldIndex, sal_Int16 nChildFieldIndex ) const;
121 };
122 
123 //	----------------------------------------------------
124 //	class Calendar_hanja
125 //	----------------------------------------------------
126 class Calendar_hanja : public Calendar_gregorian
127 {
128 public:
129     // Constructors
130     Calendar_hanja();
131     virtual void SAL_CALL loadCalendar(const rtl::OUString& uniqueID, const com::sun::star::lang::Locale& rLocale) throw(com::sun::star::uno::RuntimeException);
132     virtual rtl::OUString SAL_CALL getDisplayName(sal_Int16 nCalendarDisplayIndex, sal_Int16 nIdx, sal_Int16 nNameType) throw(com::sun::star::uno::RuntimeException);
133 };
134 
135 //	----------------------------------------------------
136 //	class Calendar_gengou
137 //	----------------------------------------------------
138 class Calendar_gengou : public Calendar_gregorian
139 {
140 public:
141     // Constructors
142     Calendar_gengou();
143 };
144 
145 //	----------------------------------------------------
146 //	class Calendar_ROC
147 //	----------------------------------------------------
148 class Calendar_ROC : public Calendar_gregorian
149 {
150 public:
151     // Constructors
152     Calendar_ROC();
153 };
154 
155 //	----------------------------------------------------
156 //	class Calendar_buddhist
157 //	----------------------------------------------------
158 class Calendar_buddhist : public Calendar_gregorian
159 {
160 public:
161     // Constructors
162     Calendar_buddhist();
163 
164     // Methods in XExtendedCalendar
165     virtual rtl::OUString SAL_CALL getDisplayString( sal_Int32 nCalendarDisplayCode, sal_Int16 nNativeNumberMode ) throw (com::sun::star::uno::RuntimeException);
166 };
167 
168 } } } }
169 
170 #endif
171