* Fix the time preflet to work in all languages, including ones with the AM/PM field before the time (try chinese for example).

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37527 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues 2010-07-15 11:04:21 +00:00
parent e4c638f650
commit 3c000b968a
1 changed files with 19 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved. * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -7,11 +7,12 @@
* Mike Berg <mike@berg-net.us> * Mike Berg <mike@berg-net.us>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
* Clemens <mail@Clemens-Zeidler.de> * Clemens <mail@Clemens-Zeidler.de>
* * Adrien Destugues <pulkomandy@pulkomandy.cx>
*/ */
#include "DateTimeEdit.h" #include "DateTimeEdit.h"
#include <stdlib.h>
#include <List.h> #include <List.h>
#include <Locale.h> #include <Locale.h>
@ -20,9 +21,6 @@
#include <Window.h> #include <Window.h>
#include <stdlib.h>
using BPrivate::B_LOCAL_TIME; using BPrivate::B_LOCAL_TIME;
@ -89,7 +87,6 @@ TTimeEdit::InitView()
void void
TTimeEdit::DrawSection(uint32 index, bool hasFocus) TTimeEdit::DrawSection(uint32 index, bool hasFocus)
{ {
// user defined section drawing
TSection *section = NULL; TSection *section = NULL;
section = static_cast<TSection*> (fSectionList->ItemAt(index)); section = static_cast<TSection*> (fSectionList->ItemAt(index));
@ -97,14 +94,12 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
return; return;
BRect bounds = section->Frame(); BRect bounds = section->Frame();
uint32 value = _SectionValue(index);
time_t time = fTime.Hour() * 3600 + fTime.Minute() * 60 + fTime.Second(); time_t time = fTime.Hour() * 3600 + fTime.Minute() * 60 + fTime.Second();
SetLowColor(ViewColor()); SetLowColor(ViewColor());
if (hasFocus) { BString field;
if (hasFocus)
SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
value = fHoldValue;
}
BString text; BString text;
int* fieldPositions; int* fieldPositions;
@ -115,12 +110,11 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
country->FormatTime(&text, fieldPositions, fieldCount, time, true); country->FormatTime(&text, fieldPositions, fieldCount, time, true);
// TODO : this should be cached somehow to not redo it for each field // TODO : this should be cached somehow to not redo it for each field
if (index * 2 + 1 >= fieldCount) { if (index * 2 + 1 > fieldCount) {
free(fieldPositions); free(fieldPositions);
return; return;
} }
BString field;
text.CopyCharsInto(field, fieldPositions[index * 2], text.CopyCharsInto(field, fieldPositions[index * 2],
fieldPositions[index * 2 + 1] - fieldPositions[index * 2]); fieldPositions[index * 2 + 1] - fieldPositions[index * 2]);
@ -285,8 +279,18 @@ TTimeEdit::BuildDispatch(BMessage *message)
if (fFocus == index) if (fFocus == index)
data = fHoldValue; data = fHoldValue;
if (dateFormat[index] < 3) switch(dateFormat[index]) {
message->AddInt32(fields[dateFormat[index]], data); case B_HOUR:
message->AddInt32(fields[0], data);
break;
case B_MINUTE:
message->AddInt32(fields[1], data);
break;
case B_SECOND:
message->AddInt32(fields[2], data);
default:
break;
}
} }
free(dateFormat); free(dateFormat);
@ -470,8 +474,7 @@ TDateEdit::KeyDown(const char* bytes, int32 numBytes)
if (_IsValidDoubleDigi(doubleDigi)) if (_IsValidDoubleDigi(doubleDigi))
number = doubleDigi; number = doubleDigi;
fLastKeyDownTime = 0; fLastKeyDownTime = 0;
} } else {
else {
fLastKeyDownTime = currentTime; fLastKeyDownTime = currentTime;
fLastKeyDownInt = number; fLastKeyDownInt = number;
} }