From eaab4bd5e9d31da73c8dbf899e4b54e0489137dd Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Fri, 26 Nov 2010 15:22:40 +0000 Subject: [PATCH] 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 --- src/kits/tracker/WidgetAttributeText.cpp | 36 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/kits/tracker/WidgetAttributeText.cpp b/src/kits/tracker/WidgetAttributeText.cpp index 0c01a49ee7..66b7d74af5 100644 --- a/src/kits/tracker/WidgetAttributeText.cpp +++ b/src/kits/tracker/WidgetAttributeText.cpp @@ -185,27 +185,41 @@ template 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; }