xref: /haiku/headers/os/locale/FormattingConventions.h (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
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			GetNumericFormat(BString& outFormat) const;
87 			status_t			GetMonetaryFormat(BString& outFormat) const;
88 
89 			void				SetExplicitDateFormat(BDateFormatStyle style,
90 									const BString& format);
91 			void				SetExplicitTimeFormat(BTimeFormatStyle style,
92 									const BString& format);
93 			void				SetExplicitNumericFormat(const BString& format);
94 			void				SetExplicitMonetaryFormat(
95 									const BString& format);
96 
97 			BMeasurementKind	MeasurementKind() const;
98 
99 			bool				UseStringsFromPreferredLanguage() const;
100 			void				SetUseStringsFromPreferredLanguage(bool value);
101 
102 			bool				Use24HourClock() const;
103 			void				SetExplicitUse24HourClock(bool value);
104 			void				UnsetExplicitUse24HourClock();
105 
106 	virtual	status_t			Archive(BMessage* archive,
107 									bool deep = true) const;
108 
109 			class Private;
110 private:
111 	friend	class Private;
112 
113 	mutable	BString				fCachedDateFormats[B_DATE_FORMAT_STYLE_COUNT];
114 	mutable	BString				fCachedTimeFormats[B_TIME_FORMAT_STYLE_COUNT];
115 	mutable	BString				fCachedNumericFormat;
116 	mutable	BString				fCachedMonetaryFormat;
117 	mutable	int8				fCachedUse24HourClock;
118 
119 			BString				fExplicitDateFormats[B_DATE_FORMAT_STYLE_COUNT];
120 			BString				fExplicitTimeFormats[B_TIME_FORMAT_STYLE_COUNT];
121 			BString				fExplicitNumericFormat;
122 			BString				fExplicitMonetaryFormat;
123 			int8				fExplicitUse24HourClock;
124 
125 			bool				fUseStringsFromPreferredLanguage;
126 
127 			icu::Locale*		fICULocale;
128 };
129 
130 
131 #endif	/* _FORMATTING_CONVENTIONS_H_ */
132