From 7f536f83ea2914b062b77712fa3ccc0ce77a54b1 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 14 Jul 2010 13:56:54 +0000 Subject: [PATCH] * Time preferences : use localized time. Note this only works if your localized time use only 8-bit utf-8 codepoints. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37515 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/time/DateTimeEdit.cpp | 96 ++++++++++++--------------- src/preferences/time/Jamfile | 2 +- 2 files changed, 45 insertions(+), 53 deletions(-) diff --git a/src/preferences/time/DateTimeEdit.cpp b/src/preferences/time/DateTimeEdit.cpp index 490983e768..5331e7af05 100644 --- a/src/preferences/time/DateTimeEdit.cpp +++ b/src/preferences/time/DateTimeEdit.cpp @@ -14,6 +14,8 @@ #include +#include +#include #include #include @@ -108,69 +110,40 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus) int* fieldPositions; int fieldCount; - // be_locale_roster->GetDefaultCountry->FormatTime(&text, fieldPositions, - // fieldCount, time); + BCountry* country; + be_locale_roster->GetDefaultCountry(&country); + country->FormatTime(&text, fieldPositions, fieldCount, time, true); + // TODO : this should be cached somehow to not redo it for each field + + if (index * 2 + 1 > fieldCount) { + free(fieldPositions); + return; + } + + BString field; + // TODO : the following calculations assume chars are 8-bit. The + // fieldPositions are character index, not byte index. + field.SetTo(text.String()+fieldPositions[index * 2], + fieldPositions[index * 2 + 1] - fieldPositions[index * 2]); + + free(fieldPositions); // calc and center text in section rect - float width = be_plain_font->StringWidth(text.String()); + float width = be_plain_font->StringWidth(field.String()); BPoint offset(-((bounds.Width()- width) / 2.0) -1.0, bounds.Height() / 2.0 -6.0); SetHighColor(0, 0, 0, 255); FillRect(bounds, B_SOLID_LOW); - - BString field; - field.SetTo(text.String()+fieldPositions[index * 2], - fieldPositions[index * 2 + 1] - fieldPositions[index * 2]); DrawString(field.String(), bounds.LeftBottom() - offset); - free(fieldPositions); } -#if 0 - case 0: - // hour - if (value > 12) { - if (value < 22) - text << "0"; - text << value - 12; - } else if (value == 0) { - text << "12"; - } else { - if (value < 10) - text << "0"; - text << value; - } - break; - - case 1: - case 2: - // minute - // second - if (value < 10) - text << "0"; - text << value; - break; - - case 3: - // am/pm - value = fTime.Hour(); - if (value >= 12) - text << "PM"; - else - text << "AM"; - break; -#endif - - void TTimeEdit::DrawSeparator(uint32 index) { - if (index == 3) - return; - TSection *section = NULL; section = static_cast (fSectionList->ItemAt(index)); @@ -180,13 +153,32 @@ TTimeEdit::DrawSeparator(uint32 index) BRect bounds = section->Frame(); float sepWidth = SeparatorWidth(); - const char* sep = ":"; - if (index == 2) - sep = "-"; + BString text; + int* fieldPositions; + int fieldCount; - float width = be_plain_font->StringWidth(sep); + BCountry* country; + be_locale_roster->GetDefaultCountry(&country); + time_t time = fTime.Hour() * 3600 + fTime.Minute() * 60 + fTime.Second(); + country->FormatTime(&text, fieldPositions, fieldCount, time, true); + // TODO : this should be cached somehow to not redo it for each field + + if (index * 2 + 2 > fieldCount) { + free(fieldPositions); + return; + } + + BString field; + // TODO : the following calculations assume chars are 8-bit. The + // fieldPositions are character index, not byte index. + field.SetTo(text.String()+fieldPositions[index * 2 + 1], + fieldPositions[index * 2 + 2] - fieldPositions[index * 2 + 1]); + + free(fieldPositions); + + float width = be_plain_font->StringWidth(field); BPoint offset(-((sepWidth - width) / 2.0) -1.0, bounds.Height() / 2.0 -6.0); - DrawString(sep, bounds.RightBottom() - offset); + DrawString(field, bounds.RightBottom() - offset); } diff --git a/src/preferences/time/Jamfile b/src/preferences/time/Jamfile index 0fbc36cdd3..7b41a9451f 100644 --- a/src/preferences/time/Jamfile +++ b/src/preferences/time/Jamfile @@ -17,7 +17,7 @@ Preference Time : TimeWindow.cpp TZDisplay.cpp ZoneView.cpp - : be libshared.a $(TARGET_LIBSUPC++) + : be libshared.a $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS) : Time.rdef ;