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