* Made TSectionEdit use be_control_look to draw its frame. Also, it no longer
uses those ugly bitmaps for the up/down buttons - while the updated drawing is far from nice either, it at least fits our UI style a lot better. * Fixed typo "seperator" -> "separator". * Coding style cleanup (still some stuff left). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31374 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -24,9 +24,10 @@
|
|||||||
using BPrivate::B_LOCAL_TIME;
|
using BPrivate::B_LOCAL_TIME;
|
||||||
|
|
||||||
|
|
||||||
TTimeEdit::TTimeEdit(BRect frame, const char *name, uint32 sections)
|
TTimeEdit::TTimeEdit(BRect frame, const char* name, uint32 sections)
|
||||||
: TSectionEdit(frame, name, sections),
|
:
|
||||||
fLastKeyDownTime(0)
|
TSectionEdit(frame, name, sections),
|
||||||
|
fLastKeyDownTime(0)
|
||||||
{
|
{
|
||||||
InitView();
|
InitView();
|
||||||
fTime = BTime::CurrentTime(B_LOCAL_TIME);
|
fTime = BTime::CurrentTime(B_LOCAL_TIME);
|
||||||
@@ -51,7 +52,7 @@ TTimeEdit::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
int32 section = FocusIndex();
|
int32 section = FocusIndex();
|
||||||
if (section < 0 || section > 2)
|
if (section < 0 || section > 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bigtime_t currentTime = system_time();
|
bigtime_t currentTime = system_time();
|
||||||
if (currentTime - fLastKeyDownTime < 1000000) {
|
if (currentTime - fLastKeyDownTime < 1000000) {
|
||||||
int32 doubleDigi = number + fLastKeyDownInt * 10;
|
int32 doubleDigi = number + fLastKeyDownInt * 10;
|
||||||
@@ -63,12 +64,12 @@ TTimeEdit::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
fLastKeyDownTime = currentTime;
|
fLastKeyDownTime = currentTime;
|
||||||
fLastKeyDownInt = number;
|
fLastKeyDownInt = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update display value
|
// update display value
|
||||||
fHoldValue = number;
|
fHoldValue = number;
|
||||||
|
|
||||||
_CheckRange();
|
_CheckRange();
|
||||||
|
|
||||||
// send message to change time
|
// send message to change time
|
||||||
DispatchMessage();
|
DispatchMessage();
|
||||||
}
|
}
|
||||||
@@ -105,8 +106,8 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
|
|||||||
|
|
||||||
BString text;
|
BString text;
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
{ // hour
|
// hour
|
||||||
if (value > 12) {
|
if (value > 12) {
|
||||||
if (value < 22)
|
if (value < 22)
|
||||||
text << "0";
|
text << "0";
|
||||||
@@ -117,67 +118,65 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
|
|||||||
if (value < 10)
|
if (value < 10)
|
||||||
text << "0";
|
text << "0";
|
||||||
text << value;
|
text << value;
|
||||||
}
|
}
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
{ // minute
|
// minute
|
||||||
// second
|
// second
|
||||||
if (value < 10)
|
if (value < 10)
|
||||||
text << "0";
|
text << "0";
|
||||||
text << value;
|
text << value;
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
{ // am/pm
|
// am/pm
|
||||||
value = fTime.Hour();
|
value = fTime.Hour();
|
||||||
if (value >= 12)
|
if (value >= 12)
|
||||||
text << "PM";
|
text << "PM";
|
||||||
else
|
else
|
||||||
text << "AM";
|
text << "AM";
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// calc and center text in section rect
|
// calc and center text in section rect
|
||||||
float width = be_plain_font->StringWidth(text.String());
|
float width = be_plain_font->StringWidth(text.String());
|
||||||
|
|
||||||
BPoint offset(-((bounds.Width()- width) / 2.0) -1.0
|
BPoint offset(-((bounds.Width()- width) / 2.0) -1.0,
|
||||||
, bounds.Height() / 2.0 -6.0);
|
bounds.Height() / 2.0 -6.0);
|
||||||
|
|
||||||
SetHighColor(0, 0, 0, 255);
|
SetHighColor(0, 0, 0, 255);
|
||||||
FillRect(bounds, B_SOLID_LOW);
|
FillRect(bounds, B_SOLID_LOW);
|
||||||
DrawString(text.String(), bounds.LeftBottom() - offset);
|
DrawString(text.String(), bounds.LeftBottom() - offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeEdit::DrawSeperator(uint32 index)
|
TTimeEdit::DrawSeparator(uint32 index)
|
||||||
{
|
{
|
||||||
if (index == 3)
|
if (index == 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TSection *section = NULL;
|
TSection *section = NULL;
|
||||||
section = static_cast<TSection*> (fSectionList->ItemAt(index));
|
section = static_cast<TSection*> (fSectionList->ItemAt(index));
|
||||||
|
|
||||||
if (!section)
|
if (!section)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BRect bounds = section->Frame();
|
BRect bounds = section->Frame();
|
||||||
float sepWidth = SeperatorWidth();
|
float sepWidth = SeparatorWidth();
|
||||||
|
|
||||||
char* sep = ":";
|
char* sep = ":";
|
||||||
if (index == 2)
|
if (index == 2)
|
||||||
sep = "-";
|
sep = "-";
|
||||||
|
|
||||||
float width = be_plain_font->StringWidth(sep);
|
float width = be_plain_font->StringWidth(sep);
|
||||||
BPoint offset(-((sepWidth - width) / 2.0) -1.0
|
BPoint offset(-((sepWidth - width) / 2.0) -1.0, bounds.Height() / 2.0 -6.0);
|
||||||
, bounds.Height() / 2.0 -6.0);
|
DrawString(sep, bounds.RightBottom() - offset);
|
||||||
DrawString(sep, bounds.RightBottom() - offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -186,16 +185,16 @@ TTimeEdit::SetSections(BRect area)
|
|||||||
{
|
{
|
||||||
// by default divide up the sections evenly
|
// by default divide up the sections evenly
|
||||||
BRect bounds(area);
|
BRect bounds(area);
|
||||||
|
|
||||||
float sepWidth = SeperatorWidth();
|
float sepWidth = SeparatorWidth();
|
||||||
|
|
||||||
float sep_2 = ceil(sepWidth / fSectionCount +1);
|
float sep_2 = ceil(sepWidth / fSectionCount +1);
|
||||||
float width = bounds.Width() / fSectionCount -sep_2;
|
float width = bounds.Width() / fSectionCount -sep_2;
|
||||||
bounds.right = bounds.left + (width -sepWidth / fSectionCount);
|
bounds.right = bounds.left + (width -sepWidth / fSectionCount);
|
||||||
|
|
||||||
for (uint32 idx = 0; idx < fSectionCount; idx++) {
|
for (uint32 idx = 0; idx < fSectionCount; idx++) {
|
||||||
fSectionList->AddItem(new TSection(bounds));
|
fSectionList->AddItem(new TSection(bounds));
|
||||||
|
|
||||||
bounds.left = bounds.right + sepWidth;
|
bounds.left = bounds.right + sepWidth;
|
||||||
if (idx == fSectionCount -2)
|
if (idx == fSectionCount -2)
|
||||||
bounds.right = area.right -1;
|
bounds.right = area.right -1;
|
||||||
@@ -206,7 +205,7 @@ TTimeEdit::SetSections(BRect area)
|
|||||||
|
|
||||||
|
|
||||||
float
|
float
|
||||||
TTimeEdit::SeperatorWidth() const
|
TTimeEdit::SeparatorWidth() const
|
||||||
{
|
{
|
||||||
return 10.0f;
|
return 10.0f;
|
||||||
}
|
}
|
||||||
@@ -225,7 +224,7 @@ TTimeEdit::SectionFocus(uint32 index)
|
|||||||
void
|
void
|
||||||
TTimeEdit::SetTime(int32 hour, int32 minute, int32 second)
|
TTimeEdit::SetTime(int32 hour, int32 minute, int32 second)
|
||||||
{
|
{
|
||||||
if (fTime.Hour() == hour && fTime.Minute() == minute
|
if (fTime.Hour() == hour && fTime.Minute() == minute
|
||||||
&& fTime.Second() == second)
|
&& fTime.Second() == second)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -239,17 +238,17 @@ TTimeEdit::DoUpPress()
|
|||||||
{
|
{
|
||||||
if (fFocus == -1)
|
if (fFocus == -1)
|
||||||
SectionFocus(0);
|
SectionFocus(0);
|
||||||
|
|
||||||
// update displayed value
|
// update displayed value
|
||||||
fHoldValue += 1;
|
fHoldValue += 1;
|
||||||
|
|
||||||
_CheckRange();
|
_CheckRange();
|
||||||
|
|
||||||
// send message to change time
|
// send message to change time
|
||||||
DispatchMessage();
|
DispatchMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeEdit::DoDownPress()
|
TTimeEdit::DoDownPress()
|
||||||
{
|
{
|
||||||
@@ -258,27 +257,27 @@ TTimeEdit::DoDownPress()
|
|||||||
|
|
||||||
// update display value
|
// update display value
|
||||||
fHoldValue -= 1;
|
fHoldValue -= 1;
|
||||||
|
|
||||||
_CheckRange();
|
_CheckRange();
|
||||||
|
|
||||||
// send message to change time
|
// send message to change time
|
||||||
DispatchMessage();
|
DispatchMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeEdit::BuildDispatch(BMessage *message)
|
TTimeEdit::BuildDispatch(BMessage *message)
|
||||||
{
|
{
|
||||||
const char *fields[3] = { "hour", "minute", "second" };
|
const char *fields[3] = { "hour", "minute", "second" };
|
||||||
|
|
||||||
message->AddBool("time", true);
|
message->AddBool("time", true);
|
||||||
|
|
||||||
for (int32 index = 0; index < fSectionList->CountItems() -1; ++index) {
|
for (int32 index = 0; index < fSectionList->CountItems() -1; ++index) {
|
||||||
uint32 data = _SectionValue(index);
|
uint32 data = _SectionValue(index);
|
||||||
|
|
||||||
if (fFocus == index)
|
if (fFocus == index)
|
||||||
data = fHoldValue;
|
data = fHoldValue;
|
||||||
|
|
||||||
message->AddInt32(fields[index], data);
|
message->AddInt32(fields[index], data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,37 +289,37 @@ TTimeEdit::_CheckRange()
|
|||||||
int32 value = fHoldValue;
|
int32 value = fHoldValue;
|
||||||
switch (fFocus) {
|
switch (fFocus) {
|
||||||
case 0:
|
case 0:
|
||||||
{ // hour
|
// hour
|
||||||
if (value > 23)
|
if (value > 23)
|
||||||
value = 0;
|
value = 0;
|
||||||
else if (value < 0)
|
else if (value < 0)
|
||||||
value = 23;
|
value = 23;
|
||||||
|
|
||||||
fTime.SetTime(value, fTime.Minute(), fTime.Second());
|
fTime.SetTime(value, fTime.Minute(), fTime.Second());
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{ // minute
|
// minute
|
||||||
if (value> 59)
|
if (value> 59)
|
||||||
value = 0;
|
value = 0;
|
||||||
else if (value < 0)
|
else if (value < 0)
|
||||||
value = 59;
|
value = 59;
|
||||||
|
|
||||||
fTime.SetTime(fTime.Hour(), value, fTime.Second());
|
fTime.SetTime(fTime.Hour(), value, fTime.Second());
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{ // second
|
// second
|
||||||
if (value > 59)
|
if (value > 59)
|
||||||
value = 0;
|
value = 0;
|
||||||
else if (value < 0)
|
else if (value < 0)
|
||||||
value = 59;
|
value = 59;
|
||||||
|
|
||||||
fTime.SetTime(fTime.Hour(), fTime.Minute(), value);
|
fTime.SetTime(fTime.Hour(), fTime.Minute(), value);
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
{
|
// AM/PM
|
||||||
value = fTime.Hour();
|
value = fTime.Hour();
|
||||||
if (value < 13)
|
if (value < 13)
|
||||||
value += 12;
|
value += 12;
|
||||||
@@ -331,7 +330,7 @@ TTimeEdit::_CheckRange()
|
|||||||
|
|
||||||
// modify hour value to reflect change in am/ pm
|
// modify hour value to reflect change in am/ pm
|
||||||
fTime.SetTime(value, fTime.Minute(), fTime.Second());
|
fTime.SetTime(value, fTime.Minute(), fTime.Second());
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@@ -348,22 +347,22 @@ TTimeEdit::_IsValidDoubleDigi(int32 value)
|
|||||||
bool isInRange = false;
|
bool isInRange = false;
|
||||||
switch (fFocus) {
|
switch (fFocus) {
|
||||||
case 0:
|
case 0:
|
||||||
{ // hour
|
// hour
|
||||||
if (value <= 23)
|
if (value <= 23)
|
||||||
isInRange = true;
|
isInRange = true;
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{ // minute
|
// minute
|
||||||
if (value <= 59)
|
if (value <= 59)
|
||||||
isInRange = true;
|
isInRange = true;
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{ // second
|
// second
|
||||||
if (value <= 59)
|
if (value <= 59)
|
||||||
isInRange = true;
|
isInRange = true;
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return isInRange;
|
return isInRange;
|
||||||
@@ -381,7 +380,7 @@ TTimeEdit::_SectionValue(int32 index) const
|
|||||||
case 0:
|
case 0:
|
||||||
value = fTime.Hour();
|
value = fTime.Hour();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
value = fTime.Minute();
|
value = fTime.Minute();
|
||||||
break;
|
break;
|
||||||
@@ -428,7 +427,7 @@ TDateEdit::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
int32 section = FocusIndex();
|
int32 section = FocusIndex();
|
||||||
if (section < 1 || section > 2)
|
if (section < 1 || section > 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bigtime_t currentTime = system_time();
|
bigtime_t currentTime = system_time();
|
||||||
if (currentTime - fLastKeyDownTime < 1000000) {
|
if (currentTime - fLastKeyDownTime < 1000000) {
|
||||||
int32 doubleDigi = number + fLastKeyDownInt * 10;
|
int32 doubleDigi = number + fLastKeyDownInt * 10;
|
||||||
@@ -440,7 +439,7 @@ TDateEdit::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
fLastKeyDownTime = currentTime;
|
fLastKeyDownTime = currentTime;
|
||||||
fLastKeyDownInt = number;
|
fLastKeyDownInt = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if year add 2000
|
// if year add 2000
|
||||||
if (section == 2) {
|
if (section == 2) {
|
||||||
int32 oldCentury = int32(fHoldValue / 100) * 100;
|
int32 oldCentury = int32(fHoldValue / 100) * 100;
|
||||||
@@ -450,9 +449,9 @@ TDateEdit::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
}
|
}
|
||||||
// update display value
|
// update display value
|
||||||
fHoldValue = number;
|
fHoldValue = number;
|
||||||
|
|
||||||
_CheckRange();
|
_CheckRange();
|
||||||
|
|
||||||
// send message to change time
|
// send message to change time
|
||||||
DispatchMessage();
|
DispatchMessage();
|
||||||
}
|
}
|
||||||
@@ -496,17 +495,17 @@ TDateEdit::DrawSection(uint32 index, bool hasFocus)
|
|||||||
|
|
||||||
// calc and center text in section rect
|
// calc and center text in section rect
|
||||||
float width = StringWidth(text.String());
|
float width = StringWidth(text.String());
|
||||||
BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0
|
BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0,
|
||||||
, (bounds.Height() / 2.0 - 6.0));
|
(bounds.Height() / 2.0 - 6.0));
|
||||||
|
|
||||||
SetHighColor(0, 0, 0, 255);
|
SetHighColor(0, 0, 0, 255);
|
||||||
FillRect(bounds, B_SOLID_LOW);
|
FillRect(bounds, B_SOLID_LOW);
|
||||||
DrawString(text.String(), bounds.LeftBottom() - offset);
|
DrawString(text.String(), bounds.LeftBottom() - offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateEdit::DrawSeperator(uint32 index)
|
TDateEdit::DrawSeparator(uint32 index)
|
||||||
{
|
{
|
||||||
if (index == 3)
|
if (index == 3)
|
||||||
return;
|
return;
|
||||||
@@ -515,14 +514,14 @@ TDateEdit::DrawSeperator(uint32 index)
|
|||||||
section = static_cast<TSection*> (fSectionList->ItemAt(index));
|
section = static_cast<TSection*> (fSectionList->ItemAt(index));
|
||||||
BRect bounds = section->Frame();
|
BRect bounds = section->Frame();
|
||||||
|
|
||||||
float sepWidth = SeperatorWidth();
|
float sepWidth = SeparatorWidth();
|
||||||
float width = be_plain_font->StringWidth("/");
|
float width = be_plain_font->StringWidth("/");
|
||||||
|
|
||||||
BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0
|
BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0,
|
||||||
, bounds.Height() / 2.0 -6.0);
|
bounds.Height() / 2.0 -6.0);
|
||||||
|
|
||||||
SetHighColor(0, 0, 0, 255);
|
SetHighColor(0, 0, 0, 255);
|
||||||
DrawString("/", bounds.RightBottom() - offset);
|
DrawString("/", bounds.RightBottom() - offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -534,7 +533,7 @@ TDateEdit::SetSections(BRect area)
|
|||||||
fSectionList->AddItem(new TSection(area));
|
fSectionList->AddItem(new TSection(area));
|
||||||
|
|
||||||
BRect bounds(area);
|
BRect bounds(area);
|
||||||
float sepWidth = SeperatorWidth();
|
float sepWidth = SeparatorWidth();
|
||||||
|
|
||||||
// year
|
// year
|
||||||
TSection *section = NULL;
|
TSection *section = NULL;
|
||||||
@@ -560,7 +559,7 @@ TDateEdit::SetSections(BRect area)
|
|||||||
|
|
||||||
|
|
||||||
float
|
float
|
||||||
TDateEdit::SeperatorWidth() const
|
TDateEdit::SeparatorWidth() const
|
||||||
{
|
{
|
||||||
return 10.0f;
|
return 10.0f;
|
||||||
}
|
}
|
||||||
@@ -602,7 +601,7 @@ TDateEdit::DoUpPress()
|
|||||||
DispatchMessage();
|
DispatchMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateEdit::DoDownPress()
|
TDateEdit::DoDownPress()
|
||||||
{
|
{
|
||||||
@@ -617,8 +616,8 @@ TDateEdit::DoDownPress()
|
|||||||
// send message to change Date
|
// send message to change Date
|
||||||
DispatchMessage();
|
DispatchMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TDateEdit::BuildDispatch(BMessage *message)
|
TDateEdit::BuildDispatch(BMessage *message)
|
||||||
{
|
{
|
||||||
@@ -642,22 +641,21 @@ void
|
|||||||
TDateEdit::_CheckRange()
|
TDateEdit::_CheckRange()
|
||||||
{
|
{
|
||||||
int32 value = fHoldValue;
|
int32 value = fHoldValue;
|
||||||
|
|
||||||
switch (fFocus) {
|
switch (fFocus) {
|
||||||
case 0:
|
case 0:
|
||||||
{
|
// month
|
||||||
// month
|
|
||||||
if (value > 12)
|
if (value > 12)
|
||||||
value = 1;
|
value = 1;
|
||||||
else if (value < 1)
|
else if (value < 1)
|
||||||
value = 12;
|
value = 12;
|
||||||
|
|
||||||
fDate.SetDate(fDate.Year(), value, fDate.Day());
|
fDate.SetDate(fDate.Year(), value, fDate.Day());
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
//day
|
// day
|
||||||
int32 days = fDate.DaysInMonth();
|
int32 days = fDate.DaysInMonth();
|
||||||
if (value > days)
|
if (value > days)
|
||||||
value = 1;
|
value = 1;
|
||||||
@@ -665,18 +663,18 @@ TDateEdit::_CheckRange()
|
|||||||
value = days;
|
value = days;
|
||||||
|
|
||||||
fDate.SetDate(fDate.Year(), fDate.Month(), value);
|
fDate.SetDate(fDate.Year(), fDate.Month(), value);
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{
|
// year
|
||||||
//year
|
|
||||||
if (value > 2037)
|
if (value > 2037)
|
||||||
value = 2037;
|
value = 2037;
|
||||||
else if (value < 1970)
|
else if (value < 1970)
|
||||||
value = 1970;
|
value = 1970;
|
||||||
|
|
||||||
fDate.SetDate(value, fDate.Month(), fDate.Day());
|
fDate.SetDate(value, fDate.Month(), fDate.Day());
|
||||||
} break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@@ -694,19 +692,22 @@ TDateEdit::_IsValidDoubleDigi(int32 value)
|
|||||||
int32 year = 0;
|
int32 year = 0;
|
||||||
switch (fFocus) {
|
switch (fFocus) {
|
||||||
case 1:
|
case 1:
|
||||||
{ // day
|
{
|
||||||
//day
|
// day
|
||||||
int32 days = fDate.DaysInMonth();
|
int32 days = fDate.DaysInMonth();
|
||||||
if (value <= days)
|
if (value <= days)
|
||||||
isInRange = true;
|
isInRange = true;
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{ //year
|
{
|
||||||
|
// year
|
||||||
year = int32(fHoldValue / 100) * 100 + value;
|
year = int32(fHoldValue / 100) * 100 + value;
|
||||||
if (year <= 2037 && year >= 1970)
|
if (year <= 2037 && year >= 1970)
|
||||||
isInRange = true;
|
isInRange = true;
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return isInRange;
|
return isInRange;
|
||||||
|
|||||||
@@ -30,11 +30,11 @@ class TTimeEdit : public TSectionEdit {
|
|||||||
|
|
||||||
virtual void InitView();
|
virtual void InitView();
|
||||||
virtual void DrawSection(uint32 index, bool isfocus);
|
virtual void DrawSection(uint32 index, bool isfocus);
|
||||||
virtual void DrawSeperator(uint32 index);
|
virtual void DrawSeparator(uint32 index);
|
||||||
|
|
||||||
virtual void SetSections(BRect area);
|
virtual void SetSections(BRect area);
|
||||||
virtual void SectionFocus(uint32 index);
|
virtual void SectionFocus(uint32 index);
|
||||||
virtual float SeperatorWidth() const;
|
virtual float SeparatorWidth() const;
|
||||||
|
|
||||||
virtual void DoUpPress();
|
virtual void DoUpPress();
|
||||||
virtual void DoDownPress();
|
virtual void DoDownPress();
|
||||||
@@ -63,11 +63,11 @@ class TDateEdit : public TSectionEdit {
|
|||||||
|
|
||||||
virtual void InitView();
|
virtual void InitView();
|
||||||
virtual void DrawSection(uint32 index, bool isfocus);
|
virtual void DrawSection(uint32 index, bool isfocus);
|
||||||
virtual void DrawSeperator(uint32 index);
|
virtual void DrawSeparator(uint32 index);
|
||||||
|
|
||||||
virtual void SetSections(BRect area);
|
virtual void SetSections(BRect area);
|
||||||
virtual void SectionFocus(uint32 index);
|
virtual void SectionFocus(uint32 index);
|
||||||
virtual float SeperatorWidth() const;
|
virtual float SeparatorWidth() const;
|
||||||
|
|
||||||
virtual void DoUpPress();
|
virtual void DoUpPress();
|
||||||
virtual void DoDownPress();
|
virtual void DoDownPress();
|
||||||
|
|||||||
@@ -9,25 +9,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SectionEdit.h"
|
#include "SectionEdit.h"
|
||||||
#include "Bitmaps.h"
|
|
||||||
#include "TimeMessages.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
#include <ControlLook.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include "TimeMessages.h"
|
||||||
|
|
||||||
|
|
||||||
const uint32 kArrowAreaWidth = 16;
|
const uint32 kArrowAreaWidth = 16;
|
||||||
|
|
||||||
|
|
||||||
TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
|
TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
|
||||||
: BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW),
|
:
|
||||||
fUpArrow(NULL),
|
BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW),
|
||||||
fDownArrow(NULL),
|
fSectionList(NULL),
|
||||||
fSectionList(NULL),
|
fFocus(-1),
|
||||||
fFocus(-1),
|
fSectionCount(sections)
|
||||||
fSectionCount(sections)
|
|
||||||
{
|
{
|
||||||
InitView();
|
InitView();
|
||||||
}
|
}
|
||||||
@@ -35,9 +34,6 @@ TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
|
|||||||
|
|
||||||
TSectionEdit::~TSectionEdit()
|
TSectionEdit::~TSectionEdit()
|
||||||
{
|
{
|
||||||
delete fUpArrow;
|
|
||||||
delete fDownArrow;
|
|
||||||
|
|
||||||
int32 count = fSectionList->CountItems();
|
int32 count = fSectionList->CountItems();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
for (int32 index = 0; index < count; index++)
|
for (int32 index = 0; index < count; index++)
|
||||||
@@ -50,22 +46,20 @@ TSectionEdit::~TSectionEdit()
|
|||||||
void
|
void
|
||||||
TSectionEdit::AttachedToWindow()
|
TSectionEdit::AttachedToWindow()
|
||||||
{
|
{
|
||||||
if (Parent()) {
|
if (Parent())
|
||||||
SetViewColor(Parent()->ViewColor());
|
SetViewColor(Parent()->ViewColor());
|
||||||
ReplaceTransparentColor(fUpArrow, ViewColor());
|
|
||||||
ReplaceTransparentColor(fDownArrow, ViewColor());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TSectionEdit::Draw(BRect updateRect)
|
TSectionEdit::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
DrawBorder();
|
DrawBorder(updateRect);
|
||||||
|
|
||||||
for (uint32 idx = 0; idx < fSectionCount; idx++) {
|
for (uint32 idx = 0; idx < fSectionCount; idx++) {
|
||||||
DrawSection(idx, ((uint32)fFocus == idx) && IsFocus());
|
DrawSection(idx, ((uint32)fFocus == idx) && IsFocus());
|
||||||
if (idx < fSectionCount -1)
|
if (idx < fSectionCount -1)
|
||||||
DrawSeperator(idx);
|
DrawSeparator(idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +68,7 @@ void
|
|||||||
TSectionEdit::MouseDown(BPoint where)
|
TSectionEdit::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
MakeFocus(true);
|
MakeFocus(true);
|
||||||
|
|
||||||
if (fUpRect.Contains(where))
|
if (fUpRect.Contains(where))
|
||||||
DoUpPress();
|
DoUpPress();
|
||||||
else if (fDownRect.Contains(where))
|
else if (fDownRect.Contains(where))
|
||||||
@@ -87,7 +81,7 @@ TSectionEdit::MouseDown(BPoint where)
|
|||||||
SectionFocus(idx);
|
SectionFocus(idx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +93,7 @@ TSectionEdit::MakeFocus(bool focused)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
BControl::MakeFocus(focused);
|
BControl::MakeFocus(focused);
|
||||||
|
|
||||||
if (fFocus == -1)
|
if (fFocus == -1)
|
||||||
SectionFocus(0);
|
SectionFocus(0);
|
||||||
else
|
else
|
||||||
@@ -112,33 +106,33 @@ TSectionEdit::KeyDown(const char *bytes, int32 numbytes)
|
|||||||
{
|
{
|
||||||
if (fFocus == -1)
|
if (fFocus == -1)
|
||||||
SectionFocus(0);
|
SectionFocus(0);
|
||||||
|
|
||||||
switch (bytes[0]) {
|
switch (bytes[0]) {
|
||||||
case B_LEFT_ARROW:
|
case B_LEFT_ARROW:
|
||||||
fFocus -= 1;
|
fFocus -= 1;
|
||||||
if (fFocus < 0)
|
if (fFocus < 0)
|
||||||
fFocus = fSectionCount -1;
|
fFocus = fSectionCount -1;
|
||||||
SectionFocus(fFocus);
|
SectionFocus(fFocus);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_RIGHT_ARROW:
|
case B_RIGHT_ARROW:
|
||||||
fFocus += 1;
|
fFocus += 1;
|
||||||
if ((uint32)fFocus >= fSectionCount)
|
if ((uint32)fFocus >= fSectionCount)
|
||||||
fFocus = 0;
|
fFocus = 0;
|
||||||
SectionFocus(fFocus);
|
SectionFocus(fFocus);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_UP_ARROW:
|
case B_UP_ARROW:
|
||||||
DoUpPress();
|
DoUpPress();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_DOWN_ARROW:
|
case B_DOWN_ARROW:
|
||||||
DoDownPress();
|
DoDownPress();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BControl::KeyDown(bytes, numbytes);
|
BControl::KeyDown(bytes, numbytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
@@ -170,103 +164,60 @@ TSectionEdit::FocusIndex() const
|
|||||||
void
|
void
|
||||||
TSectionEdit::InitView()
|
TSectionEdit::InitView()
|
||||||
{
|
{
|
||||||
// create arrow bitmaps
|
|
||||||
BRect rect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1);
|
|
||||||
fUpArrow = new BBitmap(rect, kUpArrowColorSpace);
|
|
||||||
fUpArrow->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0
|
|
||||||
, kUpArrowColorSpace);
|
|
||||||
|
|
||||||
rect = BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2);
|
|
||||||
fDownArrow = new BBitmap(rect, kDownArrowColorSpace);
|
|
||||||
fDownArrow->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight)
|
|
||||||
, 0, kDownArrowColorSpace);
|
|
||||||
|
|
||||||
// setup sections
|
// setup sections
|
||||||
fSectionList = new BList(fSectionCount);
|
fSectionList = new BList(fSectionCount);
|
||||||
fSectionArea = Bounds().InsetByCopy(2, 2);
|
fSectionArea = Bounds().InsetByCopy(2, 2);
|
||||||
fSectionArea.right -= kArrowAreaWidth;
|
fSectionArea.right -= kArrowAreaWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TSectionEdit::Draw3DFrame(BRect frame, bool inset)
|
TSectionEdit::DrawBorder(const BRect& updateRect)
|
||||||
{
|
{
|
||||||
rgb_color color1 = LowColor();
|
|
||||||
rgb_color color2 = HighColor();
|
|
||||||
|
|
||||||
if (inset) {
|
|
||||||
color1 = HighColor();
|
|
||||||
color2 = LowColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
BeginLineArray(4);
|
|
||||||
// left side
|
|
||||||
AddLine(frame.LeftBottom(), frame.LeftTop(), color2);
|
|
||||||
// right side
|
|
||||||
AddLine(frame.RightTop(), frame.RightBottom(), color1);
|
|
||||||
// bottom side
|
|
||||||
AddLine(frame.RightBottom(), frame.LeftBottom(), color1);
|
|
||||||
// top side
|
|
||||||
AddLine(frame.LeftTop(), frame.RightTop(), color2);
|
|
||||||
EndLineArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TSectionEdit::DrawBorder()
|
|
||||||
{
|
|
||||||
rgb_color bgcolor = ViewColor();
|
|
||||||
rgb_color light = tint_color(bgcolor, B_LIGHTEN_MAX_TINT);
|
|
||||||
rgb_color dark = tint_color(bgcolor, B_DARKEN_1_TINT);
|
|
||||||
rgb_color darker = tint_color(bgcolor, B_DARKEN_3_TINT);
|
|
||||||
|
|
||||||
SetHighColor(light);
|
|
||||||
SetLowColor(dark);
|
|
||||||
|
|
||||||
BRect bounds(Bounds());
|
BRect bounds(Bounds());
|
||||||
Draw3DFrame(bounds, true);
|
|
||||||
StrokeLine(bounds.LeftBottom(), bounds.LeftBottom(), B_SOLID_LOW);
|
|
||||||
|
|
||||||
bounds.InsetBy(1, 1);
|
|
||||||
bounds.right -= kArrowAreaWidth;
|
|
||||||
|
|
||||||
fShowFocus = (IsFocus() && Window() && Window()->IsActive());
|
fShowFocus = (IsFocus() && Window() && Window()->IsActive());
|
||||||
if (fShowFocus) {
|
|
||||||
rgb_color navcolor = keyboard_navigation_color();
|
be_control_look->DrawBorder(this, bounds, updateRect, ViewColor(),
|
||||||
|
B_FANCY_BORDER, fShowFocus ? BControlLook::B_FOCUSED : 0);
|
||||||
SetHighColor(navcolor);
|
|
||||||
StrokeRect(bounds);
|
|
||||||
} else {
|
|
||||||
// draw border thickening (erase focus)
|
|
||||||
SetHighColor(darker);
|
|
||||||
SetLowColor(bgcolor);
|
|
||||||
Draw3DFrame(bounds, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw up/down control
|
// draw up/down control
|
||||||
SetHighColor(light);
|
|
||||||
bounds.left = bounds.right +1;
|
bounds.left = bounds.right - kArrowAreaWidth;
|
||||||
bounds.right = Bounds().right -1;
|
bounds.right = Bounds().right - 2;
|
||||||
fUpRect.Set(bounds.left +3, bounds.top +2, bounds.right, bounds.bottom /2.0);
|
fUpRect.Set(bounds.left + 3, bounds.top + 2, bounds.right,
|
||||||
fDownRect = fUpRect.OffsetByCopy(0, fUpRect.Height()+2);
|
bounds.bottom / 2.0);
|
||||||
|
fDownRect = fUpRect.OffsetByCopy(0, fUpRect.Height() + 2);
|
||||||
if (fUpArrow)
|
|
||||||
DrawBitmap(fUpArrow, fUpRect.LeftTop());
|
BPoint middle(floorf(fUpRect.left + fUpRect.Width() / 2), fUpRect.top + 1);
|
||||||
|
BPoint left(fUpRect.left + 3, fUpRect.bottom - 1);
|
||||||
if (fDownArrow)
|
BPoint right(left.x + 2 * (middle.x - left.x), fUpRect.bottom - 1);
|
||||||
DrawBitmap(fDownArrow, fDownRect.LeftTop());
|
|
||||||
|
SetPenSize(2);
|
||||||
Draw3DFrame(bounds, false);
|
|
||||||
SetHighColor(dark);
|
if (updateRect.Intersects(fUpRect)) {
|
||||||
StrokeLine(bounds.LeftBottom(), bounds.RightBottom());
|
FillRect(fUpRect, B_SOLID_LOW);
|
||||||
StrokeLine(bounds.RightBottom(), bounds.RightTop());
|
BeginLineArray(2);
|
||||||
SetHighColor(light);
|
AddLine(left, middle, HighColor());
|
||||||
StrokeLine(bounds.RightTop(), bounds.RightTop());
|
AddLine(middle, right, HighColor());
|
||||||
|
EndLineArray();
|
||||||
|
}
|
||||||
|
if (updateRect.Intersects(fDownRect)) {
|
||||||
|
middle.y = fDownRect.bottom - 1;
|
||||||
|
left.y = right.y = fDownRect.top + 1;
|
||||||
|
|
||||||
|
FillRect(fDownRect, B_SOLID_LOW);
|
||||||
|
BeginLineArray(2);
|
||||||
|
AddLine(left, middle, HighColor());
|
||||||
|
AddLine(middle, right, HighColor());
|
||||||
|
EndLineArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
SetPenSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float
|
float
|
||||||
TSectionEdit::SeperatorWidth() const
|
TSectionEdit::SeparatorWidth() const
|
||||||
{
|
{
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ class TSection {
|
|||||||
public:
|
public:
|
||||||
TSection(BRect frame)
|
TSection(BRect frame)
|
||||||
: fFrame(frame) {}
|
: fFrame(frame) {}
|
||||||
|
|
||||||
BRect Bounds() const
|
BRect Bounds() const
|
||||||
{
|
{
|
||||||
BRect frame(fFrame);
|
BRect frame(fFrame);
|
||||||
return frame.OffsetByCopy(B_ORIGIN);
|
return frame.OffsetByCopy(B_ORIGIN);
|
||||||
@@ -31,7 +31,7 @@ class TSection {
|
|||||||
|
|
||||||
void SetFrame(BRect frame)
|
void SetFrame(BRect frame)
|
||||||
{ fFrame = frame; }
|
{ fFrame = frame; }
|
||||||
|
|
||||||
BRect Frame() const
|
BRect Frame() const
|
||||||
{ return fFrame; }
|
{ return fFrame; }
|
||||||
|
|
||||||
@@ -44,50 +44,47 @@ class TSectionEdit: public BControl {
|
|||||||
public:
|
public:
|
||||||
TSectionEdit(BRect frame, const char *name, uint32 sections);
|
TSectionEdit(BRect frame, const char *name, uint32 sections);
|
||||||
virtual ~TSectionEdit();
|
virtual ~TSectionEdit();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
virtual void MouseDown(BPoint point);
|
virtual void MouseDown(BPoint point);
|
||||||
virtual void MakeFocus(bool focused = true);
|
virtual void MakeFocus(bool focused = true);
|
||||||
virtual void KeyDown(const char *bytes, int32 numBytes);
|
virtual void KeyDown(const char *bytes, int32 numBytes);
|
||||||
|
|
||||||
uint32 CountSections() const;
|
uint32 CountSections() const;
|
||||||
int32 FocusIndex() const;
|
int32 FocusIndex() const;
|
||||||
BRect SectionArea() const;
|
BRect SectionArea() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void InitView();
|
virtual void InitView();
|
||||||
|
|
||||||
//hooks
|
// hooks
|
||||||
virtual void DrawBorder();
|
virtual void DrawBorder(const BRect& updateRect);
|
||||||
virtual void DrawSection(uint32 index, bool isFocus) {}
|
virtual void DrawSection(uint32 index, bool isFocus) {}
|
||||||
virtual void DrawSeperator(uint32 index) {}
|
virtual void DrawSeparator(uint32 index) {}
|
||||||
virtual void Draw3DFrame(BRect frame, bool inset);
|
|
||||||
|
|
||||||
virtual void SectionFocus(uint32 index) {}
|
virtual void SectionFocus(uint32 index) {}
|
||||||
virtual void SectionChange(uint32 index, uint32 value) {}
|
virtual void SectionChange(uint32 index, uint32 value) {}
|
||||||
virtual void SetSections(BRect area) {}
|
virtual void SetSections(BRect area) {}
|
||||||
virtual float SeperatorWidth() const;
|
virtual float SeparatorWidth() const;
|
||||||
|
|
||||||
virtual void DoUpPress() {}
|
virtual void DoUpPress() {}
|
||||||
virtual void DoDownPress() {}
|
virtual void DoDownPress() {}
|
||||||
|
|
||||||
virtual void DispatchMessage();
|
virtual void DispatchMessage();
|
||||||
virtual void BuildDispatch(BMessage *message) = 0;
|
virtual void BuildDispatch(BMessage *message) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BBitmap *fUpArrow;
|
|
||||||
BBitmap *fDownArrow;
|
|
||||||
BList *fSectionList;
|
BList *fSectionList;
|
||||||
|
|
||||||
BRect fUpRect;
|
BRect fUpRect;
|
||||||
BRect fDownRect;
|
BRect fDownRect;
|
||||||
BRect fSectionArea;
|
BRect fSectionArea;
|
||||||
|
|
||||||
int32 fFocus;
|
int32 fFocus;
|
||||||
uint32 fSectionCount;
|
uint32 fSectionCount;
|
||||||
uint32 fHoldValue;
|
uint32 fHoldValue;
|
||||||
|
|
||||||
bool fShowFocus;
|
bool fShowFocus;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user