1 /* 2 * Copyright 2003-2011, Haiku, Inc. 3 * Distributed under the terms of the MIT Licence. 4 */ 5 #ifndef _FORMATTING_CONVENTIONS_H_ 6 #define _FORMATTING_CONVENTIONS_H_ 7 8 9 #include <Archivable.h> 10 #include <List.h> 11 #include <LocaleStrings.h> 12 #include <String.h> 13 #include <SupportDefs.h> 14 15 16 class BBitmap; 17 class BLanguage; 18 class BMessage; 19 20 #ifndef U_ICU_NAMESPACE 21 #define U_ICU_NAMESPACE icu 22 #endif 23 namespace U_ICU_NAMESPACE { 24 class DateFormat; 25 class Locale; 26 } 27 28 29 enum BMeasurementKind { 30 B_METRIC = 0, 31 B_US 32 }; 33 34 35 enum BDateFormatStyle { 36 B_FULL_DATE_FORMAT = 0, 37 B_LONG_DATE_FORMAT, 38 B_MEDIUM_DATE_FORMAT, 39 B_SHORT_DATE_FORMAT, 40 41 B_DATE_FORMAT_STYLE_COUNT 42 }; 43 44 45 enum BTimeFormatStyle { 46 B_FULL_TIME_FORMAT = 0, 47 B_LONG_TIME_FORMAT, 48 B_MEDIUM_TIME_FORMAT, 49 B_SHORT_TIME_FORMAT, 50 51 B_TIME_FORMAT_STYLE_COUNT 52 }; 53 54 55 class BFormattingConventions : public BArchivable { 56 public: 57 BFormattingConventions(const char* id = NULL); 58 BFormattingConventions( 59 const BFormattingConventions& other); 60 BFormattingConventions(const BMessage* archive); 61 62 BFormattingConventions& operator=( 63 const BFormattingConventions& other); 64 65 ~BFormattingConventions(); 66 67 bool operator==( 68 const BFormattingConventions& other) const; 69 bool operator!=( 70 const BFormattingConventions& other) const; 71 72 const char* ID() const; 73 const char* LanguageCode() const; 74 const char* CountryCode() const; 75 76 bool AreCountrySpecific() const; 77 78 status_t GetNativeName(BString& name) const; 79 status_t GetName(BString& name, 80 const BLanguage* displayLanguage = NULL 81 ) const; 82 83 const char* GetString(uint32 id) const; 84 85 status_t GetDateFormat(BDateFormatStyle style, 86 BString& outFormat) const; 87 status_t GetTimeFormat(BTimeFormatStyle style, 88 BString& outFormat) const; 89 status_t GetDateTimeFormat(BDateFormatStyle dateStyle, 90 BTimeFormatStyle timeStyle, 91 BString& outFormat) const; 92 status_t GetNumericFormat(BString& outFormat) const; 93 status_t GetMonetaryFormat(BString& outFormat) const; 94 95 void SetExplicitDateFormat(BDateFormatStyle style, 96 const BString& format); 97 void SetExplicitTimeFormat(BTimeFormatStyle style, 98 const BString& format); 99 void SetExplicitDateTimeFormat( 100 BDateFormatStyle dateStyle, 101 BTimeFormatStyle timeStyle, 102 const BString& format); 103 void SetExplicitNumericFormat(const BString& format); 104 void SetExplicitMonetaryFormat( 105 const BString& format); 106 107 BMeasurementKind MeasurementKind() const; 108 109 bool UseStringsFromPreferredLanguage() const; 110 void SetUseStringsFromPreferredLanguage(bool value); 111 112 bool Use24HourClock() const; 113 void SetExplicitUse24HourClock(bool value); 114 void UnsetExplicitUse24HourClock(); 115 116 virtual status_t Archive(BMessage* archive, 117 bool deep = true) const; 118 119 class Private; 120 private: 121 friend class Private; 122 123 mutable BString fCachedDateFormats[B_DATE_FORMAT_STYLE_COUNT]; 124 mutable BString fCachedTimeFormats[B_TIME_FORMAT_STYLE_COUNT]; 125 mutable BString fCachedDateTimeFormats 126 [B_DATE_FORMAT_STYLE_COUNT] 127 [B_TIME_FORMAT_STYLE_COUNT]; 128 mutable BString fCachedNumericFormat; 129 mutable BString fCachedMonetaryFormat; 130 mutable int8 fCachedUse24HourClock; 131 132 BString fExplicitDateFormats[B_DATE_FORMAT_STYLE_COUNT]; 133 BString fExplicitTimeFormats[B_TIME_FORMAT_STYLE_COUNT]; 134 BString fExplicitDateTimeFormats 135 [B_DATE_FORMAT_STYLE_COUNT] 136 [B_TIME_FORMAT_STYLE_COUNT]; 137 BString fExplicitNumericFormat; 138 BString fExplicitMonetaryFormat; 139 int8 fExplicitUse24HourClock; 140 141 bool fUseStringsFromPreferredLanguage; 142 143 U_ICU_NAMESPACE::Locale* fICULocale; 144 void CoerceFormatForClock(BString& outFormat) const; 145 }; 146 147 148 #endif /* _FORMATTING_CONVENTIONS_H_ */ 149