* adjust TruncTimeBase() in libtracker's WidgetAttributeText to use
  the BString-based versions of BLocale's date formatting methods
* restored the 6 different formats Tracker used to try and fit into
  a date column (i. e. it now behaves pretty much as it did before the 
  introduction of the Locale Kit)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39649 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe 2010-11-26 15:22:40 +00:00
parent 37ba7e5389
commit eaab4bd5e9

View File

@ -185,27 +185,41 @@ template <class View>
float
TruncTimeBase(BString* result, int64 value, const View* view, float width)
{
float resultWidth = 0;
char buffer[256];
float resultWidth = width + 1;
time_t timeValue = (time_t)value;
if (BLocale::Default()->FormatDateTime(buffer, 256, timeValue,
B_FULL_DATE_FORMAT, B_MEDIUM_TIME_FORMAT) == B_OK)
resultWidth = view->StringWidth(buffer);
struct {
BDateFormatStyle dateStyle;
BTimeFormatStyle timeStyle;
} formats[5] = {
{ B_FULL_DATE_FORMAT, B_MEDIUM_TIME_FORMAT },
{ B_LONG_DATE_FORMAT, B_MEDIUM_TIME_FORMAT },
{ B_LONG_DATE_FORMAT, B_SHORT_TIME_FORMAT },
{ B_MEDIUM_DATE_FORMAT, B_SHORT_TIME_FORMAT },
{ B_SHORT_DATE_FORMAT, B_SHORT_TIME_FORMAT },
};
BString date;
for (int i = 0; resultWidth > width && i < 5; ++i) {
if (BLocale::Default()->FormatDateTime(&date, timeValue,
formats[i].dateStyle, formats[i].timeStyle) == B_OK) {
resultWidth = view->StringWidth(date.String(), date.Length());
}
}
if (resultWidth > width
&& BLocale::Default()->FormatDateTime(buffer, 256, timeValue,
B_SHORT_DATE_FORMAT, B_SHORT_TIME_FORMAT) == B_OK) {
resultWidth = view->StringWidth(buffer);
&& BLocale::Default()->FormatDate(&date, timeValue,
B_SHORT_DATE_FORMAT) == B_OK) {
resultWidth = view->StringWidth(date.String(), date.Length());
}
if (resultWidth > width) {
// even the shortest format string didn't do it, insert ellipsis
resultWidth = TruncStringBase(result, buffer, (ssize_t)strlen(buffer),
view, width);
resultWidth = TruncStringBase(result, date.String(),
(ssize_t)date.Length(), view, width);
} else
*result = buffer;
*result = date;
return resultWidth;
}