2010-07-27 02:05:39 +04:00
|
|
|
/*
|
Change Time Format Options in Deskbar preferences.
Added two new methods to the Locale Kit in order to create a custom time
formats from a format string. One method is outputs into a char* array,
the other into a BString() and you can set the timezone.
These methods should be cleaned up, we only need 2, one to get
the time in a predefined style, the other to get a custom time format.
Also should probably do the same for dates and datetimes. But I'll let
this go for now.
I added myself to the Locale.cpp file. I retained the copyright instead
of assigning it to Haiku, Inc. because the file is under the OpenBeOS
license and I don't know what the concequences of copyright sharing are
for that license, unlike MIT.
These new methods are used to generate custom time formats in Deskbar.
Instead of using a set of Radio Buttons to choose between the predefined
time options I build my own by creating a format string and passing it
to the Locale Kit. The format string is generated from 3 checkboxes,
show seconds, show day of week, and show time zone. You can mix and match
between them choose any that you like. By default they are all off.
There are 3 new deskbar settings associated with these new options:
showSeconds, showDayOfWeek, and showTimeZone. timeFormat has gone away.
The time format string gets cached and updated only when Update() gets called
on the TimeView class.
In order to fit all the options in (there is 1 more than before) I had to
reduce the font size of the clock to 11pt when all options are turned on in
12 hour mode. For those with no imagination it looks like this:
http://imagebin.org/208162
Renamed "Open time preferences..." menuitem to "Time preferences...".
Renamed "Show Time" and "Hide Time" to "Show time" and "Hide time".
Other changes include refactoring the header files a bit. There were a lot
of headers included by header files uneccessarily. For instance BarWindow.h
now only includes <Window.h> and <Deskbar.h>. This change is mainly to
to speed up the compile time since it takes a while right now.
I copy the fBarView pointer from BarWindow in the BarApp constructor and then
use that throughout the file rather than getting the pointer from the window
each time by calling BarView(). BarView() is still available in the header
for other classes though.
I moved some message constants around since it was getting a bit jumbled.
Most of the messages related to settings are in PreferenceWindow.h.
fChangeState is moved to BarView.h since that is where the ChangeState()
function is and BarView.cpp uses that constant.
The time interval and format constants are in TimeView.h.
Make some methods public in their respective classes where it made sense.
The preference window methods to update dependent items are public, that
might get called from BarWindow when a message gets received at some point.
Also made ShowHideTime() and Time() public in StatusView.h. These methods
activate showing and hiding the clock and return the fTime clock object.
No reason they should be private.
I reindented the StatusView.h and PreferenceWindow.h headers to the standard
style. Question here, are the public: protected: and private: lines inside
of classes suppose to get indented 1 tab or not? I've seen both, the style
guide says no indent but 1 indent seems reasonable and looks pretty good.
Style fixes here and there. That's enough for one commit I think.
2012-04-15 07:37:45 +04:00
|
|
|
* Copyright 2003-2012, Haiku, Inc.
|
2010-07-27 02:05:39 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2009-05-01 23:23:59 +04:00
|
|
|
#ifndef _B_LOCALE_H_
|
|
|
|
#define _B_LOCALE_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <Collator.h>
|
2010-10-24 16:57:55 +04:00
|
|
|
#include <FormattingConventions.h>
|
2010-08-02 00:28:19 +04:00
|
|
|
#include <Language.h>
|
2010-08-30 00:55:00 +04:00
|
|
|
#include <Locker.h>
|
2010-08-02 00:28:19 +04:00
|
|
|
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2011-08-19 02:13:06 +04:00
|
|
|
namespace icu {
|
2010-10-24 16:57:55 +04:00
|
|
|
class DateFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-01 23:23:59 +04:00
|
|
|
class BCatalog;
|
|
|
|
class BString;
|
2010-08-16 19:03:54 +04:00
|
|
|
class BTimeZone;
|
2009-05-01 23:23:59 +04:00
|
|
|
|
|
|
|
|
2011-09-08 01:41:57 +04:00
|
|
|
enum BDateElement {
|
2010-08-17 00:19:51 +04:00
|
|
|
B_DATE_ELEMENT_INVALID = B_BAD_DATA,
|
|
|
|
B_DATE_ELEMENT_YEAR = 0,
|
|
|
|
B_DATE_ELEMENT_MONTH,
|
|
|
|
B_DATE_ELEMENT_DAY,
|
|
|
|
B_DATE_ELEMENT_AM_PM,
|
|
|
|
B_DATE_ELEMENT_HOUR,
|
|
|
|
B_DATE_ELEMENT_MINUTE,
|
|
|
|
B_DATE_ELEMENT_SECOND
|
2011-09-08 01:41:57 +04:00
|
|
|
};
|
2010-08-17 00:19:51 +04:00
|
|
|
|
2011-09-08 01:41:57 +04:00
|
|
|
enum BNumberElement {
|
2010-08-24 21:49:12 +04:00
|
|
|
B_NUMBER_ELEMENT_INVALID = B_BAD_DATA,
|
|
|
|
B_NUMBER_ELEMENT_INTEGER = 0,
|
|
|
|
B_NUMBER_ELEMENT_FRACTIONAL,
|
|
|
|
B_NUMBER_ELEMENT_CURRENCY
|
2011-09-08 01:41:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: move this to BCalendar (should we ever have that) or BDate
|
|
|
|
enum BWeekday {
|
|
|
|
B_WEEKDAY_MONDAY = 1,
|
|
|
|
B_WEEKDAY_TUESDAY,
|
|
|
|
B_WEEKDAY_WEDNESDAY,
|
|
|
|
B_WEEKDAY_THURSDAY,
|
|
|
|
B_WEEKDAY_FRIDAY,
|
|
|
|
B_WEEKDAY_SATURDAY,
|
|
|
|
B_WEEKDAY_SUNDAY,
|
|
|
|
};
|
2010-08-24 21:49:12 +04:00
|
|
|
|
2010-08-17 00:19:51 +04:00
|
|
|
|
2009-05-02 01:56:16 +04:00
|
|
|
class BLocale {
|
2010-08-02 00:28:19 +04:00
|
|
|
public:
|
2010-10-20 01:36:44 +04:00
|
|
|
BLocale(const BLanguage* language = NULL,
|
2010-10-24 16:57:55 +04:00
|
|
|
const BFormattingConventions* conventions
|
|
|
|
= NULL);
|
2010-08-04 22:45:06 +04:00
|
|
|
BLocale(const BLocale& other);
|
2010-08-02 00:28:19 +04:00
|
|
|
~BLocale();
|
|
|
|
|
2010-11-22 16:06:36 +03:00
|
|
|
static const BLocale* Default();
|
|
|
|
|
2010-08-30 00:55:00 +04:00
|
|
|
BLocale& operator=(const BLocale& other);
|
|
|
|
|
|
|
|
status_t GetCollator(BCollator* collator) const;
|
|
|
|
status_t GetLanguage(BLanguage* language) const;
|
2010-10-24 16:57:55 +04:00
|
|
|
status_t GetFormattingConventions(
|
|
|
|
BFormattingConventions* conventions) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
|
2010-10-24 16:57:55 +04:00
|
|
|
void SetFormattingConventions(
|
|
|
|
const BFormattingConventions& conventions);
|
2010-08-04 22:45:06 +04:00
|
|
|
void SetCollator(const BCollator& newCollator);
|
2010-10-20 01:36:44 +04:00
|
|
|
void SetLanguage(const BLanguage& newLanguage);
|
|
|
|
|
2010-08-02 00:28:19 +04:00
|
|
|
// see definitions in LocaleStrings.h
|
2010-08-30 22:57:17 +04:00
|
|
|
const char* GetString(uint32 id) const;
|
2010-08-02 00:28:19 +04:00
|
|
|
|
|
|
|
void FormatString(char* target, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
char* fmt, ...) const;
|
|
|
|
void FormatString(BString* buffer, char* fmt,
|
|
|
|
...) const;
|
2010-10-24 16:57:55 +04:00
|
|
|
|
|
|
|
// DateTime
|
|
|
|
|
|
|
|
// TODO: drop some of these once BDateTimeFormat
|
|
|
|
// has been implemented!
|
|
|
|
ssize_t FormatDateTime(char* target, size_t maxSize,
|
|
|
|
time_t time, BDateFormatStyle dateStyle,
|
|
|
|
BTimeFormatStyle timeStyle) const;
|
2010-08-07 15:22:16 +04:00
|
|
|
status_t FormatDateTime(BString* buffer, time_t time,
|
2010-10-24 16:57:55 +04:00
|
|
|
BDateFormatStyle dateStyle,
|
|
|
|
BTimeFormatStyle timeStyle,
|
2010-08-30 22:57:17 +04:00
|
|
|
const BTimeZone* timeZone = NULL) const;
|
2010-08-02 00:28:19 +04:00
|
|
|
|
2010-08-04 22:45:06 +04:00
|
|
|
// Date
|
|
|
|
|
2010-08-16 19:03:54 +04:00
|
|
|
// TODO: drop some of these once BDateFormat
|
|
|
|
// has been implemented!
|
2010-10-24 16:57:55 +04:00
|
|
|
ssize_t FormatDate(char* string, size_t maxSize,
|
|
|
|
time_t time, BDateFormatStyle style) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatDate(BString* string, time_t time,
|
2010-10-24 16:57:55 +04:00
|
|
|
BDateFormatStyle style,
|
2010-08-30 22:57:17 +04:00
|
|
|
const BTimeZone* timeZone = NULL) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatDate(BString* string,
|
|
|
|
int*& fieldPositions, int& fieldCount,
|
2010-10-24 16:57:55 +04:00
|
|
|
time_t time, BDateFormatStyle style) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t GetDateFields(BDateElement*& fields,
|
2010-10-24 16:57:55 +04:00
|
|
|
int& fieldCount, BDateFormatStyle style
|
|
|
|
) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
|
2011-09-08 01:41:57 +04:00
|
|
|
status_t GetStartOfWeek(BWeekday* weekday) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
|
|
|
|
// Time
|
|
|
|
|
2010-08-16 19:03:54 +04:00
|
|
|
// TODO: drop some of these once BTimeFormat
|
|
|
|
// has been implemented!
|
2010-10-24 16:57:55 +04:00
|
|
|
ssize_t FormatTime(char* string, size_t maxSize,
|
|
|
|
time_t time, BTimeFormatStyle style) const;
|
Change Time Format Options in Deskbar preferences.
Added two new methods to the Locale Kit in order to create a custom time
formats from a format string. One method is outputs into a char* array,
the other into a BString() and you can set the timezone.
These methods should be cleaned up, we only need 2, one to get
the time in a predefined style, the other to get a custom time format.
Also should probably do the same for dates and datetimes. But I'll let
this go for now.
I added myself to the Locale.cpp file. I retained the copyright instead
of assigning it to Haiku, Inc. because the file is under the OpenBeOS
license and I don't know what the concequences of copyright sharing are
for that license, unlike MIT.
These new methods are used to generate custom time formats in Deskbar.
Instead of using a set of Radio Buttons to choose between the predefined
time options I build my own by creating a format string and passing it
to the Locale Kit. The format string is generated from 3 checkboxes,
show seconds, show day of week, and show time zone. You can mix and match
between them choose any that you like. By default they are all off.
There are 3 new deskbar settings associated with these new options:
showSeconds, showDayOfWeek, and showTimeZone. timeFormat has gone away.
The time format string gets cached and updated only when Update() gets called
on the TimeView class.
In order to fit all the options in (there is 1 more than before) I had to
reduce the font size of the clock to 11pt when all options are turned on in
12 hour mode. For those with no imagination it looks like this:
http://imagebin.org/208162
Renamed "Open time preferences..." menuitem to "Time preferences...".
Renamed "Show Time" and "Hide Time" to "Show time" and "Hide time".
Other changes include refactoring the header files a bit. There were a lot
of headers included by header files uneccessarily. For instance BarWindow.h
now only includes <Window.h> and <Deskbar.h>. This change is mainly to
to speed up the compile time since it takes a while right now.
I copy the fBarView pointer from BarWindow in the BarApp constructor and then
use that throughout the file rather than getting the pointer from the window
each time by calling BarView(). BarView() is still available in the header
for other classes though.
I moved some message constants around since it was getting a bit jumbled.
Most of the messages related to settings are in PreferenceWindow.h.
fChangeState is moved to BarView.h since that is where the ChangeState()
function is and BarView.cpp uses that constant.
The time interval and format constants are in TimeView.h.
Make some methods public in their respective classes where it made sense.
The preference window methods to update dependent items are public, that
might get called from BarWindow when a message gets received at some point.
Also made ShowHideTime() and Time() public in StatusView.h. These methods
activate showing and hiding the clock and return the fTime clock object.
No reason they should be private.
I reindented the StatusView.h and PreferenceWindow.h headers to the standard
style. Question here, are the public: protected: and private: lines inside
of classes suppose to get indented 1 tab or not? I've seen both, the style
guide says no indent but 1 indent seems reasonable and looks pretty good.
Style fixes here and there. That's enough for one commit I think.
2012-04-15 07:37:45 +04:00
|
|
|
ssize_t FormatTime(char* string, size_t maxSize,
|
|
|
|
time_t time, BString format) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatTime(BString* string, time_t time,
|
2010-10-24 16:57:55 +04:00
|
|
|
BTimeFormatStyle style,
|
2010-08-30 22:57:17 +04:00
|
|
|
const BTimeZone* timeZone = NULL) const;
|
Change Time Format Options in Deskbar preferences.
Added two new methods to the Locale Kit in order to create a custom time
formats from a format string. One method is outputs into a char* array,
the other into a BString() and you can set the timezone.
These methods should be cleaned up, we only need 2, one to get
the time in a predefined style, the other to get a custom time format.
Also should probably do the same for dates and datetimes. But I'll let
this go for now.
I added myself to the Locale.cpp file. I retained the copyright instead
of assigning it to Haiku, Inc. because the file is under the OpenBeOS
license and I don't know what the concequences of copyright sharing are
for that license, unlike MIT.
These new methods are used to generate custom time formats in Deskbar.
Instead of using a set of Radio Buttons to choose between the predefined
time options I build my own by creating a format string and passing it
to the Locale Kit. The format string is generated from 3 checkboxes,
show seconds, show day of week, and show time zone. You can mix and match
between them choose any that you like. By default they are all off.
There are 3 new deskbar settings associated with these new options:
showSeconds, showDayOfWeek, and showTimeZone. timeFormat has gone away.
The time format string gets cached and updated only when Update() gets called
on the TimeView class.
In order to fit all the options in (there is 1 more than before) I had to
reduce the font size of the clock to 11pt when all options are turned on in
12 hour mode. For those with no imagination it looks like this:
http://imagebin.org/208162
Renamed "Open time preferences..." menuitem to "Time preferences...".
Renamed "Show Time" and "Hide Time" to "Show time" and "Hide time".
Other changes include refactoring the header files a bit. There were a lot
of headers included by header files uneccessarily. For instance BarWindow.h
now only includes <Window.h> and <Deskbar.h>. This change is mainly to
to speed up the compile time since it takes a while right now.
I copy the fBarView pointer from BarWindow in the BarApp constructor and then
use that throughout the file rather than getting the pointer from the window
each time by calling BarView(). BarView() is still available in the header
for other classes though.
I moved some message constants around since it was getting a bit jumbled.
Most of the messages related to settings are in PreferenceWindow.h.
fChangeState is moved to BarView.h since that is where the ChangeState()
function is and BarView.cpp uses that constant.
The time interval and format constants are in TimeView.h.
Make some methods public in their respective classes where it made sense.
The preference window methods to update dependent items are public, that
might get called from BarWindow when a message gets received at some point.
Also made ShowHideTime() and Time() public in StatusView.h. These methods
activate showing and hiding the clock and return the fTime clock object.
No reason they should be private.
I reindented the StatusView.h and PreferenceWindow.h headers to the standard
style. Question here, are the public: protected: and private: lines inside
of classes suppose to get indented 1 tab or not? I've seen both, the style
guide says no indent but 1 indent seems reasonable and looks pretty good.
Style fixes here and there. That's enough for one commit I think.
2012-04-15 07:37:45 +04:00
|
|
|
status_t FormatTime(BString* string, time_t time,
|
|
|
|
BString format,
|
|
|
|
const BTimeZone* timeZone) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t FormatTime(BString* string,
|
|
|
|
int*& fieldPositions, int& fieldCount,
|
2010-10-24 16:57:55 +04:00
|
|
|
time_t time, BTimeFormatStyle style) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
status_t GetTimeFields(BDateElement*& fields,
|
2010-10-24 16:57:55 +04:00
|
|
|
int& fieldCount, BTimeFormatStyle style
|
|
|
|
) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
|
|
|
|
// numbers
|
|
|
|
|
2010-10-24 16:57:55 +04:00
|
|
|
ssize_t FormatNumber(char* string, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
double value) const;
|
|
|
|
status_t FormatNumber(BString* string,
|
|
|
|
double value) const;
|
2010-10-24 16:57:55 +04:00
|
|
|
ssize_t FormatNumber(char* string, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
int32 value) const;
|
|
|
|
status_t FormatNumber(BString* string,
|
|
|
|
int32 value) const;
|
2010-08-04 22:45:06 +04:00
|
|
|
|
|
|
|
// monetary
|
|
|
|
|
|
|
|
ssize_t FormatMonetary(char* string, size_t maxSize,
|
2010-08-30 22:57:17 +04:00
|
|
|
double value) const;
|
2010-08-24 21:49:12 +04:00
|
|
|
status_t FormatMonetary(BString* string,
|
2010-10-24 16:57:55 +04:00
|
|
|
double value) const;
|
2010-08-02 00:28:19 +04:00
|
|
|
|
|
|
|
// Collator short-hands
|
|
|
|
int StringCompare(const char* s1,
|
|
|
|
const char* s2) const;
|
|
|
|
int StringCompare(const BString* s1,
|
|
|
|
const BString* s2) const;
|
|
|
|
|
|
|
|
void GetSortKey(const char* string,
|
2010-10-24 16:57:55 +04:00
|
|
|
BString* sortKey) const;
|
2010-08-02 00:28:19 +04:00
|
|
|
|
2010-10-20 01:36:44 +04:00
|
|
|
private:
|
2011-08-19 02:13:06 +04:00
|
|
|
icu::DateFormat* _CreateDateFormatter(
|
2010-10-24 16:57:55 +04:00
|
|
|
const BString& format) const;
|
2011-08-19 02:13:06 +04:00
|
|
|
icu::DateFormat* _CreateTimeFormatter(
|
2010-10-24 16:57:55 +04:00
|
|
|
const BString& format) const;
|
2010-10-20 01:36:44 +04:00
|
|
|
|
2010-08-30 00:55:00 +04:00
|
|
|
mutable BLocker fLock;
|
2010-08-02 00:28:19 +04:00
|
|
|
BCollator fCollator;
|
2010-10-24 16:57:55 +04:00
|
|
|
BFormattingConventions fConventions;
|
2010-08-02 00:28:19 +04:00
|
|
|
BLanguage fLanguage;
|
2010-08-04 22:45:06 +04:00
|
|
|
};
|
2009-05-01 23:23:59 +04:00
|
|
|
|
|
|
|
|
2010-08-04 22:45:06 +04:00
|
|
|
//--- collator short-hands inlines ---
|
2009-05-01 23:23:59 +04:00
|
|
|
// #pragma mark -
|
|
|
|
|
2009-05-02 01:56:16 +04:00
|
|
|
inline int
|
2010-08-02 00:28:19 +04:00
|
|
|
BLocale::StringCompare(const char* s1, const char* s2) const
|
2009-05-01 23:23:59 +04:00
|
|
|
{
|
2010-08-02 00:28:19 +04:00
|
|
|
return fCollator.Compare(s1, s2);
|
2009-05-01 23:23:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-02 01:56:16 +04:00
|
|
|
inline int
|
2010-08-02 00:28:19 +04:00
|
|
|
BLocale::StringCompare(const BString* s1, const BString* s2) const
|
2009-05-01 23:23:59 +04:00
|
|
|
{
|
2010-08-02 00:28:19 +04:00
|
|
|
return fCollator.Compare(s1->String(), s2->String());
|
2009-05-01 23:23:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
2010-10-24 16:57:55 +04:00
|
|
|
BLocale::GetSortKey(const char* string, BString* sortKey) const
|
2009-05-01 23:23:59 +04:00
|
|
|
{
|
2010-10-24 16:57:55 +04:00
|
|
|
fCollator.GetSortKey(string, sortKey);
|
2009-05-01 23:23:59 +04:00
|
|
|
}
|
|
|
|
|
2010-08-02 00:28:19 +04:00
|
|
|
|
2009-05-01 23:23:59 +04:00
|
|
|
#endif /* _B_LOCALE_H_ */
|