Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************** |
michael@0 | 3 | * Copyright (C) 2005-2013, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ******************************************************************************** |
michael@0 | 6 | * |
michael@0 | 7 | * File WINDTFMT.H |
michael@0 | 8 | * |
michael@0 | 9 | ******************************************************************************** |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | #ifndef __WINDTFMT |
michael@0 | 13 | #define __WINDTFMT |
michael@0 | 14 | |
michael@0 | 15 | #include "unicode/utypes.h" |
michael@0 | 16 | |
michael@0 | 17 | #if U_PLATFORM_HAS_WIN32_API |
michael@0 | 18 | |
michael@0 | 19 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 20 | |
michael@0 | 21 | #include "unicode/format.h" |
michael@0 | 22 | #include "unicode/datefmt.h" |
michael@0 | 23 | #include "unicode/calendar.h" |
michael@0 | 24 | #include "unicode/ustring.h" |
michael@0 | 25 | #include "unicode/locid.h" |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * \file |
michael@0 | 29 | * \brief C++ API: Format dates using Windows API. |
michael@0 | 30 | */ |
michael@0 | 31 | |
michael@0 | 32 | U_CDECL_BEGIN |
michael@0 | 33 | // Forward declarations for Windows types... |
michael@0 | 34 | typedef struct _SYSTEMTIME SYSTEMTIME; |
michael@0 | 35 | typedef struct _TIME_ZONE_INFORMATION TIME_ZONE_INFORMATION; |
michael@0 | 36 | U_CDECL_END |
michael@0 | 37 | |
michael@0 | 38 | U_NAMESPACE_BEGIN |
michael@0 | 39 | |
michael@0 | 40 | class Win32DateFormat : public DateFormat |
michael@0 | 41 | { |
michael@0 | 42 | public: |
michael@0 | 43 | Win32DateFormat(DateFormat::EStyle timeStyle, DateFormat::EStyle dateStyle, const Locale &locale, UErrorCode &status); |
michael@0 | 44 | |
michael@0 | 45 | Win32DateFormat(const Win32DateFormat &other); |
michael@0 | 46 | |
michael@0 | 47 | virtual ~Win32DateFormat(); |
michael@0 | 48 | |
michael@0 | 49 | virtual Format *clone(void) const; |
michael@0 | 50 | |
michael@0 | 51 | Win32DateFormat &operator=(const Win32DateFormat &other); |
michael@0 | 52 | |
michael@0 | 53 | UnicodeString &format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const; |
michael@0 | 54 | |
michael@0 | 55 | UnicodeString& format(UDate date, UnicodeString& appendTo) const; |
michael@0 | 56 | |
michael@0 | 57 | void parse(const UnicodeString& text, Calendar& cal, ParsePosition& pos) const; |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * Set the calendar to be used by this date format. Initially, the default |
michael@0 | 61 | * calendar for the specified or default locale is used. The caller should |
michael@0 | 62 | * not delete the Calendar object after it is adopted by this call. |
michael@0 | 63 | * |
michael@0 | 64 | * @param calendarToAdopt Calendar object to be adopted. |
michael@0 | 65 | */ |
michael@0 | 66 | virtual void adoptCalendar(Calendar* calendarToAdopt); |
michael@0 | 67 | |
michael@0 | 68 | /** |
michael@0 | 69 | * Set the calendar to be used by this date format. Initially, the default |
michael@0 | 70 | * calendar for the specified or default locale is used. |
michael@0 | 71 | * |
michael@0 | 72 | * @param newCalendar Calendar object to be set. |
michael@0 | 73 | */ |
michael@0 | 74 | virtual void setCalendar(const Calendar& newCalendar); |
michael@0 | 75 | |
michael@0 | 76 | /** |
michael@0 | 77 | * Sets the time zone for the calendar of this DateFormat object. The caller |
michael@0 | 78 | * no longer owns the TimeZone object and should not delete it after this call. |
michael@0 | 79 | * |
michael@0 | 80 | * @param zoneToAdopt the TimeZone to be adopted. |
michael@0 | 81 | */ |
michael@0 | 82 | virtual void adoptTimeZone(TimeZone* zoneToAdopt); |
michael@0 | 83 | |
michael@0 | 84 | /** |
michael@0 | 85 | * Sets the time zone for the calendar of this DateFormat object. |
michael@0 | 86 | * @param zone the new time zone. |
michael@0 | 87 | */ |
michael@0 | 88 | virtual void setTimeZone(const TimeZone& zone); |
michael@0 | 89 | |
michael@0 | 90 | /** |
michael@0 | 91 | * Return the class ID for this class. This is useful only for comparing to |
michael@0 | 92 | * a return value from getDynamicClassID(). For example: |
michael@0 | 93 | * <pre> |
michael@0 | 94 | * . Base* polymorphic_pointer = createPolymorphicObject(); |
michael@0 | 95 | * . if (polymorphic_pointer->getDynamicClassID() == |
michael@0 | 96 | * . erived::getStaticClassID()) ... |
michael@0 | 97 | * </pre> |
michael@0 | 98 | * @return The class ID for all objects of this class. |
michael@0 | 99 | */ |
michael@0 | 100 | U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void); |
michael@0 | 101 | |
michael@0 | 102 | /** |
michael@0 | 103 | * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This |
michael@0 | 104 | * method is to implement a simple version of RTTI, since not all C++ |
michael@0 | 105 | * compilers support genuine RTTI. Polymorphic operator==() and clone() |
michael@0 | 106 | * methods call this method. |
michael@0 | 107 | * |
michael@0 | 108 | * @return The class ID for this object. All objects of a |
michael@0 | 109 | * given class have the same class ID. Objects of |
michael@0 | 110 | * other classes have different class IDs. |
michael@0 | 111 | */ |
michael@0 | 112 | virtual UClassID getDynamicClassID(void) const; |
michael@0 | 113 | |
michael@0 | 114 | private: |
michael@0 | 115 | void formatDate(const SYSTEMTIME *st, UnicodeString &appendTo) const; |
michael@0 | 116 | void formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const; |
michael@0 | 117 | |
michael@0 | 118 | UnicodeString setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const; |
michael@0 | 119 | UnicodeString* getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) const; |
michael@0 | 120 | |
michael@0 | 121 | UnicodeString *fDateTimeMsg; |
michael@0 | 122 | DateFormat::EStyle fTimeStyle; |
michael@0 | 123 | DateFormat::EStyle fDateStyle; |
michael@0 | 124 | Locale fLocale; |
michael@0 | 125 | int32_t fLCID; |
michael@0 | 126 | UnicodeString fZoneID; |
michael@0 | 127 | TIME_ZONE_INFORMATION *fTZI; |
michael@0 | 128 | }; |
michael@0 | 129 | |
michael@0 | 130 | inline UnicodeString &Win32DateFormat::format(UDate date, UnicodeString& appendTo) const { |
michael@0 | 131 | return DateFormat::format(date, appendTo); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | U_NAMESPACE_END |
michael@0 | 135 | |
michael@0 | 136 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
michael@0 | 137 | |
michael@0 | 138 | #endif // U_PLATFORM_HAS_WIN32_API |
michael@0 | 139 | |
michael@0 | 140 | #endif // __WINDTFMT |