Fix #6758:
* 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:
parent
37ba7e5389
commit
eaab4bd5e9
@ -185,27 +185,41 @@ template <class View>
|
|||||||
float
|
float
|
||||||
TruncTimeBase(BString* result, int64 value, const View* view, float width)
|
TruncTimeBase(BString* result, int64 value, const View* view, float width)
|
||||||
{
|
{
|
||||||
float resultWidth = 0;
|
float resultWidth = width + 1;
|
||||||
char buffer[256];
|
|
||||||
|
|
||||||
time_t timeValue = (time_t)value;
|
time_t timeValue = (time_t)value;
|
||||||
|
|
||||||
if (BLocale::Default()->FormatDateTime(buffer, 256, timeValue,
|
struct {
|
||||||
B_FULL_DATE_FORMAT, B_MEDIUM_TIME_FORMAT) == B_OK)
|
BDateFormatStyle dateStyle;
|
||||||
resultWidth = view->StringWidth(buffer);
|
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
|
if (resultWidth > width
|
||||||
&& BLocale::Default()->FormatDateTime(buffer, 256, timeValue,
|
&& BLocale::Default()->FormatDate(&date, timeValue,
|
||||||
B_SHORT_DATE_FORMAT, B_SHORT_TIME_FORMAT) == B_OK) {
|
B_SHORT_DATE_FORMAT) == B_OK) {
|
||||||
resultWidth = view->StringWidth(buffer);
|
resultWidth = view->StringWidth(date.String(), date.Length());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultWidth > width) {
|
if (resultWidth > width) {
|
||||||
// even the shortest format string didn't do it, insert ellipsis
|
// even the shortest format string didn't do it, insert ellipsis
|
||||||
resultWidth = TruncStringBase(result, buffer, (ssize_t)strlen(buffer),
|
resultWidth = TruncStringBase(result, date.String(),
|
||||||
view, width);
|
(ssize_t)date.Length(), view, width);
|
||||||
} else
|
} else
|
||||||
*result = buffer;
|
*result = date;
|
||||||
|
|
||||||
return resultWidth;
|
return resultWidth;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user