patch by Julun:

* fixed more style issues
* fixed small memory leaks
* refactoring
+ some small changes by myself, added back Michael Berg and Andrew McCall as
  likely authors of most files which had no author information


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22232 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2007-09-14 09:04:03 +00:00
parent b86754c363
commit fd7c0c2ed7
25 changed files with 523 additions and 544 deletions

View File

@ -21,9 +21,8 @@ class OffscreenClock : public BView {
OffscreenClock(BRect frame, const char *name); OffscreenClock(BRect frame, const char *name);
~OffscreenClock(); ~OffscreenClock();
void SetTo(int32 hour, int32 minute, int32 second); void SetTime(int32 hour, int32 minute, int32 second);
bool IsDirty() const bool IsDirty() const { return fDirty; }
{ return fDirty; }
void DrawClock(); void DrawClock();
private: private:
@ -54,7 +53,7 @@ OffscreenClock::~OffscreenClock()
void void
OffscreenClock::SetTo(int32 hour, int32 minute, int32 second) OffscreenClock::SetTime(int32 hour, int32 minute, int32 second)
{ {
if (fHours == hour && fMinutes == minute && fSeconds == second) if (fHours == hour && fMinutes == minute && fSeconds == second)
return; return;
@ -233,7 +232,7 @@ TAnalogClock::MessageReceived(BMessage *message)
if (message->FindInt32("hour", &hour) == B_OK if (message->FindInt32("hour", &hour) == B_OK
&& message->FindInt32("minute", &minute) == B_OK && message->FindInt32("minute", &minute) == B_OK
&& message->FindInt32("second", &second) == B_OK) && message->FindInt32("second", &second) == B_OK)
SetTo(hour, minute, second); SetTime(hour, minute, second);
break; break;
} }
default: default:
@ -260,10 +259,10 @@ TAnalogClock::Draw(BRect /*updateRect*/)
void void
TAnalogClock::SetTo(int32 hour, int32 minute, int32 second) TAnalogClock::SetTime(int32 hour, int32 minute, int32 second)
{ {
if (fClock) if (fClock)
fClock->SetTo(hour, minute, second); fClock->SetTime(hour, minute, second);
Invalidate(); Invalidate();
} }

View File

@ -27,7 +27,7 @@ class TAnalogClock : public BView {
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
void SetTo(int32 hour, int32 minute, int32 second); void SetTime(int32 hour, int32 minute, int32 second);
private: private:
void _InitView(BRect frame); void _InitView(BRect frame);

View File

@ -3,6 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */

View File

@ -3,6 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */
#ifndef ANALOG_CLOCK_H #ifndef ANALOG_CLOCK_H

View File

@ -146,7 +146,7 @@ TDay::Draw(BRect updaterect)
SetHighColor(bgcolor); SetHighColor(bgcolor);
FillRect(bounds); FillRect(bounds);
if (f_day> 0) { if (f_day > 0) {
if (!(Value() == 1)) if (!(Value() == 1))
SetHighColor(0, 0, 0, 255); SetHighColor(0, 0, 0, 255);
else else
@ -207,7 +207,7 @@ TDay::SetTo(int day, bool selected)
f_day = day; f_day = day;
SetValue(selected); SetValue(selected);
if (Value() == 1) { if (Value() == 1) {
SetFlags(Flags()|B_NAVIGABLE); SetFlags(Flags() | B_NAVIGABLE);
} else { } else {
SetFlags(Flags() & ~B_NAVIGABLE); SetFlags(Flags() & ~B_NAVIGABLE);
} }
@ -224,7 +224,7 @@ TCalendarView::TCalendarView(BRect frame, const char *name,
, f_firstday(0) , f_firstday(0)
, f_month(0) , f_month(0)
, f_day(0) , f_day(0)
,f_year(0) , f_year(0)
{ {
InitView(); InitView();
} }
@ -338,20 +338,19 @@ TCalendarView::Draw(BRect updaterect)
{ {
BRect bounds(0.0, 0.0, f_dayrect.Width(), f_dayrect.Height()); BRect bounds(0.0, 0.0, f_dayrect.Width(), f_dayrect.Height());
float width = 0;
float x = bounds.Width()/2.0;
BPoint drawpt;
BString day;
SetLowColor(ViewColor()); SetLowColor(ViewColor());
SetHighColor(0, 0, 0); SetHighColor(0, 0, 0);
float offset = FontHeight(this, true); BPoint drawpt;
drawpt.y = (bounds.top + bounds.bottom + FontHeight(this, true)) / 2.0;
float width = 0;
float x = bounds.Width() / 2.0;
BString day;
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
day = BString(&kDays[i], 1); day = BString(&kDays[i], 1);
width = be_plain_font->StringWidth(day.String()); width = be_plain_font->StringWidth(day.String());
drawpt.x = bounds.left + (x - width / 2.0 + 2); drawpt.x = bounds.left + (x - width / 2.0 + 2);
drawpt.y = bounds.bottom - offset / 2.0;
DrawString(day.String(), drawpt); DrawString(day.String(), drawpt);
bounds.OffsetBy(bounds.Width() + 1, 0); bounds.OffsetBy(bounds.Width() + 1, 0);
} }

View File

@ -1,9 +1,20 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de>
*/
#ifndef CALENDAR_VIEW_H #ifndef CALENDAR_VIEW_H
#define CALENDAR_VIEW_H #define CALENDAR_VIEW_H
#include <Control.h> #include <Control.h>
#include <View.h> #include <View.h>
class TDay: public BControl { class TDay: public BControl {
public: public:
TDay(BRect frame, int day); TDay(BRect frame, int day);

View File

@ -1,37 +1,38 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de>
*
*/
#include "DateTimeEdit.h" #include "DateTimeEdit.h"
#include "DateUtils.h" #include "DateUtils.h"
#include <List.h>
#include <String.h> #include <String.h>
#include <stdio.h>
#define YEAR_DELTA_MAX 110 #define YEAR_DELTA_MAX 110
#define YEAR_DELTA_MIN 64 #define YEAR_DELTA_MIN 64
TDateTimeSection::TDateTimeSection(BRect frame, uint32 data) class TDateTimeSection : public TSection {
: TSection(frame), public:
fData(data) TDateTimeSection(BRect frame, uint32 data = 0)
{ : TSection(frame), fData(data) { }
} ~TDateTimeSection();
uint32 Data() const { return fData; }
void SetData(uint32 data) { fData = data; }
private:
TDateTimeSection::~TDateTimeSection() uint32 fData;
{ };
}
uint32
TDateTimeSection::Data() const
{
return fData;
}
void
TDateTimeSection::SetData(uint32 data)
{
fData = data;
}
// #pragma mark - // #pragma mark -
@ -46,32 +47,25 @@ TTimeEdit::TTimeEdit(BRect frame, const char *name, uint32 sections)
TTimeEdit::~TTimeEdit() TTimeEdit::~TTimeEdit()
{ {
TSection *section;
if (f_sections->CountItems() > 0) {
for (int32 idx = 0; (section = (TSection *)f_sections->ItemAt(idx)); idx++)
delete section;
}
delete f_sections;
} }
void void
TTimeEdit::InitView() TTimeEdit::InitView()
{ {
// make sure we call the base class method, as it
// will create the arrow bitmaps and the section list
TSectionEdit::InitView(); TSectionEdit::InitView();
SetSections(f_sectionsarea); SetSections(fSectionArea);
} }
void void
TTimeEdit::DrawSection(uint32 index, bool hasFocus) TTimeEdit::DrawSection(uint32 index, bool hasFocus)
{ {
if (f_sections->CountItems() == 0)
printf("No Sections!!!\n");
// user defined section drawing // user defined section drawing
TDateTimeSection *section; TDateTimeSection *section;
section = (TDateTimeSection *)f_sections->ItemAt(index); section = (TDateTimeSection *)fSectionList->ItemAt(index);
BRect bounds = section->Frame(); BRect bounds = section->Frame();
@ -81,7 +75,7 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
if (hasFocus) { if (hasFocus) {
SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
value = f_holdvalue; value = fHoldValue;
} else { } else {
SetLowColor(ViewColor()); SetLowColor(ViewColor());
value = section->Data(); value = section->Data();
@ -112,7 +106,7 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
break; break;
case 3: // am/pm case 3: // am/pm
value = ((TDateTimeSection *)f_sections->ItemAt(0))->Data(); value = ((TDateTimeSection *)fSectionList->ItemAt(0))->Data();
if (value >= 12) if (value >= 12)
text << "PM"; text << "PM";
else else
@ -125,10 +119,9 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
} }
// 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()/2.0 -width/2.0) -1.0, bounds.Height()/2.0 -6.0); BPoint offset(-(bounds.Width() / 2.0 -width / 2.0) -1.0, bounds.Height() / 2.0 -6.0);
BPoint drawpt(bounds.LeftBottom() -offset); BPoint drawpt(bounds.LeftBottom() -offset);
@ -138,27 +131,31 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
} }
/*
DrawSeperator(uint32 index) user drawn seperator. Section is the
index of the section in fSectionList or the section to the seps left
*/
void void
TTimeEdit::DrawSeperator(uint32 index) TTimeEdit::DrawSeperator(uint32 index)
{ {
/* user drawn seperator. section is the index of the section if (index == 3)
in f_sections or the section to the seps left return;
*/
TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(index);
if (index >= 2)
return; // no seperator for am/pm
BString text(":");
uint32 sep;
GetSeperatorWidth(&sep);
TDateTimeSection *section = (TDateTimeSection *)f_sections->ItemAt(index);
BRect bounds = section->Frame(); BRect bounds = section->Frame();
float sepWidth = SeperatorWidth();
char* sep = ":";
if (index == 2)
sep = "-";
float width = be_plain_font->StringWidth(sep);
float width = be_plain_font->StringWidth(text.String()); BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0, bounds.Height() / 2.0 -6.0);
BPoint offset(-(sep/2.0 -width/2.0) -1.0, bounds.Height()/2.0 -6.0);
BPoint drawpt(bounds.RightBottom() -offset); BPoint drawpt(bounds.RightBottom() -offset);
DrawString(text.String(), drawpt); DrawString(sep, drawpt);
} }
@ -169,67 +166,63 @@ TTimeEdit::SetSections(BRect area)
BRect bounds(area); BRect bounds(area);
// no comp for sep width // no comp for sep width
uint32 sep_width; float sepWidth = SeperatorWidth();
GetSeperatorWidth(&sep_width);
float sep_2 = ceil(sep_width/f_sectioncount +1); float sep_2 = ceil(sepWidth / fSectionCount +1);
float width = bounds.Width()/f_sectioncount -sep_2; float width = bounds.Width() / fSectionCount -sep_2;
bounds.right = bounds.left +(width -sep_width/f_sectioncount); bounds.right = bounds.left + (width -sepWidth / fSectionCount);
TDateTimeSection *section; for (uint32 idx = 0; idx < fSectionCount; idx++) {
fSectionList->AddItem(new TDateTimeSection(bounds));
for (uint32 idx = 0; idx < f_sectioncount; idx++) {
section = new TDateTimeSection(bounds);
f_sections->AddItem(section);
bounds.left = bounds.right +sep_width; bounds.left = bounds.right + sepWidth;
if (idx == f_sectioncount -2) if (idx == fSectionCount -2)
bounds.right = area.right -1; bounds.right = area.right -1;
else else
bounds.right = bounds.left +(width -sep_2); bounds.right = bounds.left + (width -sep_2);
} }
} }
void float
TTimeEdit::GetSeperatorWidth(uint32 *width) TTimeEdit::SeperatorWidth() const
{ {
*width = 8; return 8.0f;
} }
void void
TTimeEdit::SectionFocus(uint32 index) TTimeEdit::SectionFocus(uint32 index)
{ {
f_focus = index; fFocus = index;
// update hold value // update hold value
f_holdvalue = ((TDateTimeSection *)f_sections->ItemAt(f_focus))->Data(); fHoldValue = ((TDateTimeSection *)fSectionList->ItemAt(fFocus))->Data();
Draw(Bounds()); Draw(Bounds());
} }
void void
TTimeEdit::SetTo(uint32 hour, uint32 minute, uint32 second) TTimeEdit::SetTime(uint32 hour, uint32 minute, uint32 second)
{ {
if (f_sections->CountItems()> 0) if (fSectionList->CountItems()> 0)
{ {
bool update = false; bool update = false;
TDateTimeSection *section = (TDateTimeSection *)f_sections->ItemAt(0); TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(0);
if (section->Data() != hour) { if (section->Data() != hour) {
section->SetData(hour); section->SetData(hour);
update = true; update = true;
} }
section = (TDateTimeSection *)f_sections->ItemAt(1); section = (TDateTimeSection *)fSectionList->ItemAt(1);
if (section->Data() != minute) { if (section->Data() != minute) {
section->SetData(minute); section->SetData(minute);
update = true; update = true;
} }
section = (TDateTimeSection *)f_sections->ItemAt(2); section = (TDateTimeSection *)fSectionList->ItemAt(2);
if (section->Data() != second) { if (section->Data() != second) {
section->SetData(second); section->SetData(second);
update = true; update = true;
@ -244,11 +237,11 @@ TTimeEdit::SetTo(uint32 hour, uint32 minute, uint32 second)
void void
TTimeEdit::DoUpPress() TTimeEdit::DoUpPress()
{ {
if (f_focus == -1) if (fFocus == -1)
SectionFocus(0); SectionFocus(0);
// update displayed value // update displayed value
f_holdvalue += 1; fHoldValue += 1;
CheckRange(); CheckRange();
@ -260,11 +253,11 @@ TTimeEdit::DoUpPress()
void void
TTimeEdit::DoDownPress() TTimeEdit::DoDownPress()
{ {
if (f_focus == -1) if (fFocus == -1)
SectionFocus(0); SectionFocus(0);
// update display value // update display value
f_holdvalue -= 1; fHoldValue -= 1;
CheckRange(); CheckRange();
@ -276,20 +269,18 @@ TTimeEdit::DoDownPress()
void void
TTimeEdit::BuildDispatch(BMessage *message) TTimeEdit::BuildDispatch(BMessage *message)
{ {
static const char *fields[4] = {"hour", "minute", "second", "isam"}; const char *fields[4] = {"hour", "minute", "second", "isam"};
message->AddBool("time", true); message->AddBool("time", true);
for (int32 idx = 0; idx < f_sections->CountItems() -1; idx++) { for (int32 idx = 0; idx < fSectionList->CountItems() -1; idx++) {
uint32 data; uint32 data = ((TDateTimeSection *)fSectionList->ItemAt(idx))->Data();
if (f_focus == idx) if (fFocus == idx)
data = f_holdvalue; data = fHoldValue;
else
data = ((TDateTimeSection *)f_sections->ItemAt(idx))->Data();
if (idx == 3) // isam if (idx == 3) // isam
message->AddBool("isam", data == 1); message->AddBool(fields[idx], data == 1);
else else
message->AddInt32(fields[idx], data); message->AddInt32(fields[idx], data);
} }
@ -299,12 +290,12 @@ TTimeEdit::BuildDispatch(BMessage *message)
void void
TTimeEdit::CheckRange() TTimeEdit::CheckRange()
{ {
int32 value = f_holdvalue; int32 value = fHoldValue;
switch (f_focus) { switch (fFocus) {
case 0: // hour case 0: // hour
if (value> 23) if (value> 23)
value = 0; value = 0;
else if (value < 0) else if (value < 0)
value = 23; value = 23;
break; break;
@ -325,22 +316,22 @@ TTimeEdit::CheckRange()
case 3: case 3:
// modify hour value to reflect change in am/pm // modify hour value to reflect change in am/pm
value = ((TDateTimeSection *)f_sections->ItemAt(0))->Data(); value = ((TDateTimeSection *)fSectionList->ItemAt(0))->Data();
if (value < 13) if (value < 13)
value += 12; value += 12;
else else
value -= 12; value -= 12;
if (value == 24) if (value == 24)
value = 0; value = 0;
((TDateTimeSection *)f_sections->ItemAt(0))->SetData(value); ((TDateTimeSection *)fSectionList->ItemAt(0))->SetData(value);
break; break;
default: default:
return; return;
} }
((TDateTimeSection *)f_sections->ItemAt(f_focus))->SetData(value); ((TDateTimeSection *)fSectionList->ItemAt(fFocus))->SetData(value);
f_holdvalue = value; fHoldValue = value;
Invalidate(Bounds()); Invalidate(Bounds());
} }
@ -348,12 +339,7 @@ TTimeEdit::CheckRange()
// #pragma mark - // #pragma mark -
const char *months[] = {
"January", "Febuary", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
TDateEdit::TDateEdit(BRect frame, const char *name, uint32 sections) TDateEdit::TDateEdit(BRect frame, const char *name, uint32 sections)
: TSectionEdit(frame, name, sections) : TSectionEdit(frame, name, sections)
{ {
@ -363,32 +349,25 @@ TDateEdit::TDateEdit(BRect frame, const char *name, uint32 sections)
TDateEdit::~TDateEdit() TDateEdit::~TDateEdit()
{ {
TSection *section;
if (f_sections->CountItems() > 0) {
for (int32 idx = 0; (section = (TSection *)f_sections->ItemAt(idx)); idx++)
delete section;
}
delete f_sections;
} }
void void
TDateEdit::InitView() TDateEdit::InitView()
{ {
// make sure we call the base class method, as it
// will create the arrow bitmaps and the section list
TSectionEdit::InitView(); TSectionEdit::InitView();
SetSections(f_sectionsarea); SetSections(fSectionArea);
} }
void void
TDateEdit::DrawSection(uint32 index, bool hasFocus) TDateEdit::DrawSection(uint32 index, bool hasFocus)
{ {
if (f_sections->CountItems() == 0)
printf("No Sections!!!\n");
// user defined section drawing // user defined section drawing
TDateTimeSection *section; TDateTimeSection *section;
section = (TDateTimeSection *)f_sections->ItemAt(index); section = (TDateTimeSection *)fSectionList->ItemAt(index);
BRect bounds = section->Frame(); BRect bounds = section->Frame();
@ -398,147 +377,141 @@ TDateEdit::DrawSection(uint32 index, bool hasFocus)
if (hasFocus) { if (hasFocus) {
SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT));
value = f_holdvalue; value = fHoldValue;
} else { } else {
SetLowColor(ViewColor()); SetLowColor(ViewColor());
value = section->Data(); value = section->Data();
} }
char text[64]; BString text;
// format value (new method?)
switch (index) { switch (index) {
case 0: // month case 0:
{ // month
struct tm tm; struct tm tm;
tm.tm_mon = value; tm.tm_mon = value;
strftime(text, sizeof(text), "%B", &tm);
break; char buffer[64];
memset(buffer, 0, sizeof(buffer));
strftime(buffer, sizeof(buffer), "%B", &tm);
text.SetTo(buffer);
} break;
case 1: // day case 1: // day
snprintf(text, sizeof(text), "%lu", value); text << value;
break; break;
case 2: // year case 2: // year
snprintf(text, sizeof(text), "%lu", value + 1900); text << (value + 1900);
break; break;
default: default:
return; return;
} }
// calc and center text in section rect // calc and center text in section rect
float width = StringWidth(text.String());
float width = StringWidth(text); BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0, (bounds.Height() / 2.0 - 6.0));
BPoint offset(-(bounds.Width() - width) /2.0 - 1.0, (bounds.Height() / 2.0 - 6.0));
if (index == 0) if (index == 0)
offset.x = -(bounds.Width() - width) ; offset.x = -(bounds.Width() - width) ;
SetHighColor(0, 0, 0, 255); SetHighColor(0, 0, 0, 255);
FillRect(bounds, B_SOLID_LOW); FillRect(bounds, B_SOLID_LOW);
DrawString(text, bounds.LeftBottom() - offset); DrawString(text.String(), bounds.LeftBottom() - offset);
} }
/*
DrawSeperator(uint32 index) user drawn seperator. Section is the
index of the section in fSectionList or the section to the seps left
*/
void void
TDateEdit::DrawSeperator(uint32 index) TDateEdit::DrawSeperator(uint32 index)
{ {
/* user drawn seperator. section is the index of the section if (index == 3)
in f_sections or the section to the seps left
*/
if (index == 3) {
// no seperator for am/pm
return; return;
}
BString text("/"); TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(index);
uint32 sep;
GetSeperatorWidth(&sep);
TDateTimeSection *section = (TDateTimeSection *)f_sections->ItemAt(index);
BRect bounds = section->Frame(); BRect bounds = section->Frame();
float width = be_plain_font->StringWidth(text.String()); float sepWidth = SeperatorWidth();
BPoint offset(-(sep/2.0 -width/2.0) -1.0, bounds.Height()/2.0 -6.0); float width = be_plain_font->StringWidth("/");
BPoint drawpt(bounds.RightBottom() -offset);
DrawString(text.String(), drawpt); BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0, bounds.Height() / 2.0 -6.0);
BPoint drawpt(bounds.RightBottom() - offset);
DrawString("/", drawpt);
} }
void void
TDateEdit::SetSections(BRect area) TDateEdit::SetSections(BRect area)
{ {
TDateTimeSection *section;
// create sections // create sections
for (uint32 idx = 0; idx < f_sectioncount; idx++) { for (uint32 idx = 0; idx < fSectionCount; idx++)
section = new TDateTimeSection(area); fSectionList->AddItem(new TDateTimeSection(area));
f_sections->AddItem(section);
}
BRect bounds(area); BRect bounds(area);
float width;
// year // year
width = be_plain_font->StringWidth("0000") +6; float width = be_plain_font->StringWidth("0000") +6;
bounds.right = area.right; bounds.right = area.right;
bounds.left = bounds.right -width; bounds.left = bounds.right -width;
((TDateTimeSection *)f_sections->ItemAt(2))->SetBounds(bounds); ((TDateTimeSection *)fSectionList->ItemAt(2))->SetFrame(bounds);
uint32 sep; float sepWidth = SeperatorWidth();
GetSeperatorWidth(&sep);
// day // day
width = be_plain_font->StringWidth("00") +6; width = be_plain_font->StringWidth("00") +6;
bounds.right = bounds.left -sep; bounds.right = bounds.left -sepWidth;
bounds.left = bounds.right -width; bounds.left = bounds.right -width;
((TDateTimeSection *)f_sections->ItemAt(1))->SetBounds(bounds); ((TDateTimeSection *)fSectionList->ItemAt(1))->SetFrame(bounds);
// month // month
bounds.right = bounds.left -sep; bounds.right = bounds.left - sepWidth;
bounds.left = area.left; bounds.left = area.left;
((TDateTimeSection *)f_sections->ItemAt(0))->SetBounds(bounds); ((TDateTimeSection *)fSectionList->ItemAt(0))->SetFrame(bounds);
} }
void float
TDateEdit::GetSeperatorWidth(uint32 *width) TDateEdit::SeperatorWidth() const
{ {
*width = 8; return 8.0f;
} }
void void
TDateEdit::SectionFocus(uint32 index) TDateEdit::SectionFocus(uint32 index)
{ {
f_focus = index; fFocus = index;
// update hold value // update hold value
f_holdvalue = ((TDateTimeSection *)f_sections->ItemAt(f_focus))->Data(); fHoldValue = ((TDateTimeSection *)fSectionList->ItemAt(fFocus))->Data();
Draw(Bounds()); Draw(Bounds());
} }
void void
TDateEdit::SetTo(uint32 year, uint32 month, uint32 day) TDateEdit::SetDate(uint32 year, uint32 month, uint32 day)
{ {
if (f_sections->CountItems() > 0) { if (fSectionList->CountItems() > 0) {
bool update = false; bool update = false;
TDateTimeSection *section = (TDateTimeSection *)f_sections->ItemAt(0); TDateTimeSection *section = (TDateTimeSection *)fSectionList->ItemAt(0);
if (section->Data() != month) { if (section->Data() != month) {
section->SetData(month); section->SetData(month);
update = true; update = true;
} }
section = (TDateTimeSection *)f_sections->ItemAt(1); section = (TDateTimeSection *)fSectionList->ItemAt(1);
if (section->Data() != day) { if (section->Data() != day) {
section->SetData(day); section->SetData(day);
update = true; update = true;
} }
section = (TDateTimeSection *)f_sections->ItemAt(2); section = (TDateTimeSection *)fSectionList->ItemAt(2);
if (section->Data() != year) { if (section->Data() != year) {
section->SetData(year); section->SetData(year);
update = true; update = true;
@ -553,11 +526,11 @@ TDateEdit::SetTo(uint32 year, uint32 month, uint32 day)
void void
TDateEdit::DoUpPress() TDateEdit::DoUpPress()
{ {
if (f_focus == -1) if (fFocus == -1)
SectionFocus(0); SectionFocus(0);
// update displayed value // update displayed value
f_holdvalue += 1; fHoldValue += 1;
CheckRange(); CheckRange();
@ -569,11 +542,11 @@ TDateEdit::DoUpPress()
void void
TDateEdit::DoDownPress() TDateEdit::DoDownPress()
{ {
if (f_focus == -1) if (fFocus == -1)
SectionFocus(0); SectionFocus(0);
// update display value // update display value
f_holdvalue -= 1; fHoldValue -= 1;
CheckRange(); CheckRange();
@ -585,17 +558,15 @@ TDateEdit::DoDownPress()
void void
TDateEdit::BuildDispatch(BMessage *message) TDateEdit::BuildDispatch(BMessage *message)
{ {
static const char *fields[3] = {"month", "day", "year"}; const char *fields[3] = {"month", "day", "year"};
message->AddBool("time", false); message->AddBool("time", false);
for (int32 idx = 0; idx < f_sections->CountItems(); idx++) { for (int32 idx = 0; idx < fSectionList->CountItems(); idx++) {
uint32 data; uint32 data = ((TDateTimeSection *)fSectionList->ItemAt(idx))->Data();
if (f_focus == idx) if (fFocus == idx)
data = f_holdvalue; data = fHoldValue;
else
data = ((TDateTimeSection *)f_sections->ItemAt(idx))->Data();
message->AddInt32(fields[idx], data); message->AddInt32(fields[idx], data);
} }
@ -605,9 +576,9 @@ TDateEdit::BuildDispatch(BMessage *message)
void void
TDateEdit::CheckRange() TDateEdit::CheckRange()
{ {
int32 value = f_holdvalue; int32 value = fHoldValue;
switch (f_focus) { switch (fFocus) {
case 0: // month case 0: // month
{ {
if (value > 11) if (value > 11)
@ -619,8 +590,8 @@ TDateEdit::CheckRange()
case 1: //day case 1: //day
{ {
uint32 month = ((TDateTimeSection *)f_sections->ItemAt(0))->Data(); uint32 month = ((TDateTimeSection *)fSectionList->ItemAt(0))->Data();
uint32 year = ((TDateTimeSection *)f_sections->ItemAt(2))->Data(); uint32 year = ((TDateTimeSection *)fSectionList->ItemAt(2))->Data();
int daycnt = getDaysInMonth(month, year); int daycnt = getDaysInMonth(month, year);
if (value > daycnt) if (value > daycnt)
@ -643,8 +614,8 @@ TDateEdit::CheckRange()
return; return;
} }
((TDateTimeSection *)f_sections->ItemAt(f_focus))->SetData(value); ((TDateTimeSection *)fSectionList->ItemAt(fFocus))->SetData(value);
f_holdvalue = value; fHoldValue = value;
Draw(Bounds()); Draw(Bounds());
} }

View File

@ -1,66 +1,66 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de>
*
*/
#ifndef DATETIME_H #ifndef DATETIME_H
#define DATETIME_H #define DATETIME_H
#include "SectionEdit.h" #include "SectionEdit.h"
// TSection descendent to hold uint32 value
class TDateTimeSection : public TSection {
public:
TDateTimeSection(BRect frame, uint32 data = 0);
~TDateTimeSection();
uint32 Data() const;
void SetData(uint32 data);
private:
uint32 fData;
};
// TSectionEdit descendent to edit time
class TTimeEdit : public TSectionEdit { class TTimeEdit : public TSectionEdit {
public: public:
TTimeEdit(BRect frame, const char *name, uint32 sections); TTimeEdit(BRect frame, const char *name, uint32 sections);
~TTimeEdit(); virtual ~TTimeEdit();
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 DrawSeperator(uint32 index);
virtual void SetSections(BRect area); virtual void SetSections(BRect area);
virtual void SectionFocus(uint32 index); virtual void SectionFocus(uint32 index);
virtual void GetSeperatorWidth(uint32 *width); virtual float SeperatorWidth() const;
void CheckRange(); void CheckRange();
virtual void DoUpPress(); virtual void DoUpPress();
virtual void DoDownPress(); virtual void DoDownPress();
virtual void BuildDispatch(BMessage *message); virtual void BuildDispatch(BMessage *message);
void SetTo(uint32 hour, uint32 minute, uint32 second); void SetTime(uint32 hour, uint32 minute, uint32 second);
}; };
// TSectionEdit descendent to edit Date
class TDateEdit : public TSectionEdit { class TDateEdit : public TSectionEdit {
public: public:
TDateEdit(BRect frame, const char *name, uint32 sections); TDateEdit(BRect frame, const char *name, uint32 sections);
~TDateEdit(); virtual ~TDateEdit();
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 DrawSeperator(uint32 index);
virtual void SetSections(BRect area); virtual void SetSections(BRect area);
virtual void SectionFocus(uint32 index); virtual void SectionFocus(uint32 index);
virtual void GetSeperatorWidth(uint32 *width); virtual float SeperatorWidth() const;
void CheckRange(); void CheckRange();
virtual void DoUpPress(); virtual void DoUpPress();
virtual void DoDownPress(); virtual void DoDownPress();
virtual void BuildDispatch(BMessage *message); virtual void BuildDispatch(BMessage *message);
void SetTo(uint32 hour, uint32 minute, uint32 second); void SetDate(uint32 year, uint32 month, uint32 day);
}; };
#endif // DATETIME_H #endif // DATETIME_H

View File

@ -1,3 +1,11 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
*/
#include "DateUtils.h" #include "DateUtils.h"
#include "math.h" #include "math.h"
@ -7,16 +15,15 @@ bool
isLeapYear(const int year) isLeapYear(const int year)
{ {
int realYear = year + 1900; int realYear = year + 1900;
return ((realYear % 400 == 0)||(realYear % 4 == 0 && realYear % 100 != 0)); return ((realYear % 400 == 0) || (realYear % 4 == 0 && realYear % 100 != 0));
} }
int int
getDaysInMonth(const int month, const int year) getDaysInMonth(const int month, const int year)
{ {
if (month == 1 && isLeapYear(year)) { if (month == 1 && isLeapYear(year))
return 29; return 29;
}
static const int DaysinMonth[12] = static const int DaysinMonth[12] =
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
@ -44,3 +51,4 @@ getFirstDay(const int month, const int year)
return tm.tm_wday; return tm.tm_wday;
} }

View File

@ -1,8 +1,20 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
*
*/
#ifndef CAL_HELPERS #ifndef CAL_HELPERS
#define CAL_HELPERS #define CAL_HELPERS
bool isLeapYear(const int year); bool isLeapYear(const int year);
int getDaysInMonth(const int month, const int year); int getDaysInMonth(const int month, const int year);
int getFirstDay(const int month, const int year); int getFirstDay(const int month, const int year);
#endif //CAL_HELPERS #endif //CAL_HELPERS

View File

@ -1,54 +1,50 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* Julun <host.haiku@gmx.de>
*
*/
#include "SectionEdit.h"
#include "Bitmaps.h"
#include "TimeMessages.h"
#include <Bitmap.h> #include <Bitmap.h>
#include <List.h>
#include <Window.h> #include <Window.h>
#include "Bitmaps.h"
#include "SectionEdit.h"
#include "TimeMessages.h"
const uint32 kArrowAreaWidth = 16; const uint32 kArrowAreaWidth = 16;
const uint32 kSeperatorWidth = 8; const uint32 kSeperatorWidth = 8;
TSection::TSection(BRect frame)
: f_frame(frame)
{
}
void
TSection::SetBounds(BRect frame)
{
f_frame = frame;
}
BRect
TSection::Bounds() const
{
BRect bounds(f_frame);
return bounds.OffsetByCopy(B_ORIGIN);
}
BRect
TSection::Frame() const
{
return f_frame;
}
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) : BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW),
, f_focus(-1) fUpArrow(NULL),
fDownArrow(NULL),
fSectionList(NULL),
fFocus(-1),
fSectionCount(sections)
{ {
f_sectioncount = sections;
InitView(); InitView();
} }
TSectionEdit::~TSectionEdit() TSectionEdit::~TSectionEdit()
{ {
delete fUpArrow;
delete fDownArrow;
int32 count = fSectionList->CountItems();
if (count > 0) {
for (int32 index = 0; index < count; index++)
delete (TSection*)fSectionList->ItemAt(index);
}
delete fSectionList;
} }
@ -57,8 +53,8 @@ TSectionEdit::AttachedToWindow()
{ {
if (Parent()) { if (Parent()) {
SetViewColor(Parent()->ViewColor()); SetViewColor(Parent()->ViewColor());
ReplaceTransparentColor(f_up, ViewColor()); ReplaceTransparentColor(fUpArrow, ViewColor());
ReplaceTransparentColor(f_down, ViewColor()); ReplaceTransparentColor(fDownArrow, ViewColor());
} }
} }
@ -67,10 +63,10 @@ void
TSectionEdit::Draw(BRect updaterect) TSectionEdit::Draw(BRect updaterect)
{ {
DrawBorder(); DrawBorder();
for (uint32 idx = 0; idx < f_sectioncount; idx++) for (uint32 idx = 0; idx < fSectionCount; idx++)
{ {
DrawSection(idx, ((uint32)f_focus == idx) && IsFocus()); DrawSection(idx, ((uint32)fFocus == idx) && IsFocus());
if (idx <f_sectioncount -1) if (idx <fSectionCount -1)
DrawSeperator(idx); DrawSeperator(idx);
} }
} }
@ -80,14 +76,14 @@ void
TSectionEdit::MouseDown(BPoint where) TSectionEdit::MouseDown(BPoint where)
{ {
MakeFocus(true); MakeFocus(true);
if (f_uprect.Contains(where)) if (fUpRect.Contains(where))
DoUpPress(); DoUpPress();
else if (f_downrect.Contains(where)) else if (fDownRect.Contains(where))
DoDownPress(); DoDownPress();
else if (f_sections->CountItems()> 0) { else if (fSectionList->CountItems()> 0) {
TSection *section; TSection *section;
for (uint32 idx = 0; idx < f_sectioncount; idx++) { for (uint32 idx = 0; idx < fSectionCount; idx++) {
section = (TSection *)f_sections->ItemAt(idx); section = (TSection *)fSectionList->ItemAt(idx);
if (section->Frame().Contains(where)) { if (section->Frame().Contains(where)) {
SectionFocus(idx); SectionFocus(idx);
return; return;
@ -100,22 +96,22 @@ TSectionEdit::MouseDown(BPoint where)
void void
TSectionEdit::KeyDown(const char *bytes, int32 numbytes) TSectionEdit::KeyDown(const char *bytes, int32 numbytes)
{ {
if (f_focus == -1) if (fFocus == -1)
SectionFocus(0); SectionFocus(0);
switch (bytes[0]) { switch (bytes[0]) {
case B_LEFT_ARROW: case B_LEFT_ARROW:
f_focus -= 1; fFocus -= 1;
if (f_focus < 0) if (fFocus < 0)
f_focus = f_sectioncount -1; fFocus = fSectionCount -1;
SectionFocus(f_focus); SectionFocus(fFocus);
break; break;
case B_RIGHT_ARROW: case B_RIGHT_ARROW:
f_focus += 1; fFocus += 1;
if ((uint32)f_focus >= f_sectioncount) if ((uint32)fFocus >= fSectionCount)
f_focus = 0; fFocus = 0;
SectionFocus(f_focus); SectionFocus(fFocus);
break; break;
case B_UP_ARROW: case B_UP_ARROW:
@ -146,14 +142,14 @@ TSectionEdit::DispatchMessage()
uint32 uint32
TSectionEdit::CountSections() const TSectionEdit::CountSections() const
{ {
return f_sections->CountItems(); return fSectionList->CountItems();
} }
int32 int32
TSectionEdit::FocusIndex() const TSectionEdit::FocusIndex() const
{ {
return f_focus; return fFocus;
} }
@ -162,33 +158,31 @@ TSectionEdit::InitView()
{ {
// create arrow bitmaps // create arrow bitmaps
f_up = new BBitmap(BRect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1), kUpArrowColorSpace); fUpArrow = new BBitmap(BRect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1), kUpArrowColorSpace);
f_up->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0, kUpArrowColorSpace); fUpArrow->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0, kUpArrowColorSpace);
f_down = new BBitmap(BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2), kDownArrowColorSpace); fDownArrow = new BBitmap(BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2), kDownArrowColorSpace);
f_down->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight), 0, kDownArrowColorSpace); fDownArrow->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight), 0, kDownArrowColorSpace);
// setup sections // setup sections
f_sections = new BList(f_sectioncount); fSectionList = new BList(fSectionCount);
f_sectionsarea = Bounds().InsetByCopy(2, 2); fSectionArea = Bounds().InsetByCopy(2, 2);
f_sectionsarea.right -= (kArrowAreaWidth); fSectionArea.right -= kArrowAreaWidth;
} }
void void
TSectionEdit::Draw3DFrame(BRect frame, bool inset) TSectionEdit::Draw3DFrame(BRect frame, bool inset)
{ {
rgb_color color1, color2; rgb_color color1 = LowColor();
rgb_color color2 = HighColor();
if (inset) { if (inset) {
color1 = HighColor(); color1 = HighColor();
color2 = LowColor(); color2 = LowColor();
} else {
color1 = LowColor();
color2 = HighColor();
} }
BeginLineArray(4); BeginLineArray(4);
// left side // left side
AddLine(frame.LeftBottom(), frame.LeftTop(), color2); AddLine(frame.LeftBottom(), frame.LeftTop(), color2);
@ -210,17 +204,18 @@ TSectionEdit::DrawBorder()
rgb_color dark = tint_color(bgcolor, B_DARKEN_1_TINT); rgb_color dark = tint_color(bgcolor, B_DARKEN_1_TINT);
rgb_color darker = tint_color(bgcolor, B_DARKEN_3_TINT); rgb_color darker = tint_color(bgcolor, B_DARKEN_3_TINT);
BRect bounds(Bounds());
SetHighColor(light); SetHighColor(light);
SetLowColor(dark); SetLowColor(dark);
BRect bounds(Bounds());
Draw3DFrame(bounds, true); Draw3DFrame(bounds, true);
StrokeLine(bounds.LeftBottom(), bounds.LeftBottom(), B_SOLID_LOW); StrokeLine(bounds.LeftBottom(), bounds.LeftBottom(), B_SOLID_LOW);
bounds.InsetBy(1, 1); bounds.InsetBy(1, 1);
bounds.right -= kArrowAreaWidth; bounds.right -= kArrowAreaWidth;
f_showfocus = (IsFocus() && Window() && Window()->IsActive()); fShowFocus = (IsFocus() && Window() && Window()->IsActive());
if (f_showfocus) { if (fShowFocus) {
rgb_color navcolor = keyboard_navigation_color(); rgb_color navcolor = keyboard_navigation_color();
SetHighColor(navcolor); SetHighColor(navcolor);
@ -234,13 +229,16 @@ TSectionEdit::DrawBorder()
// draw up/down control // draw up/down control
SetHighColor(light); SetHighColor(light);
bounds.left = bounds.right +1;// -kArrowAreaWidth; bounds.left = bounds.right +1;
bounds.right = Bounds().right -1; bounds.right = Bounds().right -1;
f_uprect.Set(bounds.left +3, bounds.top +2, bounds.right, bounds.bottom /2.0); fUpRect.Set(bounds.left +3, bounds.top +2, bounds.right, bounds.bottom /2.0);
f_downrect = f_uprect.OffsetByCopy(0, f_uprect.Height()+2); fDownRect = fUpRect.OffsetByCopy(0, fUpRect.Height()+2);
DrawBitmap(f_up, f_uprect.LeftTop()); if (fUpArrow)
DrawBitmap(f_down, f_downrect.LeftTop()); DrawBitmap(fUpArrow, fUpRect.LeftTop());
if (fDownArrow)
DrawBitmap(fDownArrow, fDownRect.LeftTop());
Draw3DFrame(bounds, false); Draw3DFrame(bounds, false);
SetHighColor(dark); SetHighColor(dark);
@ -251,51 +249,9 @@ TSectionEdit::DrawBorder()
} }
void float
TSectionEdit::SetSections(BRect) TSectionEdit::SeperatorWidth() const
{
}
void
TSectionEdit::GetSeperatorWidth(uint32 *width)
{
*width = 0;
}
void
TSectionEdit::DrawSection(uint32 index, bool isfocus)
{
}
void
TSectionEdit::DrawSeperator(uint32 index)
{
}
void
TSectionEdit::SectionFocus(uint32 index)
{
}
void
TSectionEdit::SectionChange(uint32 section, uint32 value)
{
}
void
TSectionEdit::DoUpPress()
{
}
void
TSectionEdit::DoDownPress()
{ {
return 0.0f;
} }

View File

@ -1,67 +1,94 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* Julun <host.haiku@gmx.de>
*
*/
#ifndef SECTIONEDIT_H #ifndef SECTIONEDIT_H
#define SECTIONEDIT_H #define SECTIONEDIT_H
#include <Control.h> #include <Control.h>
#include <List.h>
class BBitmap;
class BList;
class TSection { class TSection {
public: public:
TSection(BRect frame); TSection(BRect frame)
: fFrame(frame) {}
void SetBounds(BRect frame); BRect Bounds() const
{
BRect frame(fFrame);
return frame.OffsetByCopy(B_ORIGIN);
}
void SetFrame(BRect frame)
{ fFrame = frame; }
BRect Bounds() const; BRect Frame() const
BRect Frame() const; { return fFrame; }
private: private:
BRect f_frame; BRect fFrame;
}; };
class TSectionEdit: public BControl { class TSectionEdit: public BControl {
public: public:
TSectionEdit(BRect frame, const char *name, uint32 sections); TSectionEdit(BRect frame, const char *name, uint32 sections);
~TSectionEdit(); virtual ~TSectionEdit();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void Draw(BRect); virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint); virtual void MouseDown(BPoint point);
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();
virtual void DrawSection(uint32 index, bool isfocus); virtual void DrawSection(uint32 index, bool isFocus) {}
virtual void DrawSeperator(uint32 index); virtual void DrawSeperator(uint32 index) {}
virtual void Draw3DFrame(BRect frame, bool inset); 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 void GetSeperatorWidth(uint32 *width); virtual float SeperatorWidth() const;
virtual void DoUpPress(); virtual void DoUpPress() {}
virtual void DoDownPress(); virtual void DoDownPress() {}
virtual void DispatchMessage(); virtual void DispatchMessage();
virtual void BuildDispatch(BMessage *) = 0; virtual void BuildDispatch(BMessage *message) = 0;
BBitmap *f_up; protected:
BBitmap *f_down; BBitmap *fUpArrow;
BList *f_sections; BBitmap *fDownArrow;
BList *fSectionList;
BRect f_uprect; BRect fUpRect;
BRect f_downrect; BRect fDownRect;
BRect f_sectionsarea; BRect fSectionArea;
int32 f_focus; int32 fFocus;
uint32 f_sectioncount; uint32 fSectionCount;
uint32 f_holdvalue; uint32 fHoldValue;
bool f_showfocus; bool fShowFocus;
}; };
#endif #endif

View File

@ -3,7 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* <unkown> * probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */
@ -201,7 +202,7 @@ TSettingsView::UpdateDateTime(BMessage *message)
&& message->FindInt32("day", &day) == B_OK && message->FindInt32("day", &day) == B_OK
&& message->FindInt32("year", &year) == B_OK) && message->FindInt32("year", &year) == B_OK)
{ {
fDateEdit->SetTo(year, month, day); fDateEdit->SetDate(year, month, day);
fCalendar->SetTo(year, month, day); fCalendar->SetTo(year, month, day);
} }
@ -212,8 +213,8 @@ TSettingsView::UpdateDateTime(BMessage *message)
&& message->FindInt32("minute", &minute) == B_OK && message->FindInt32("minute", &minute) == B_OK
&& message->FindInt32("second", &second) == B_OK) && message->FindInt32("second", &second) == B_OK)
{ {
fTimeEdit->SetTo(hour, minute, second); fTimeEdit->SetTime(hour, minute, second);
fClock->SetTo(hour, minute, second); fClock->SetTime(hour, minute, second);
} }
} }

View File

@ -3,7 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* <unkown> * probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */
#ifndef SETTINGS_VIEW_H #ifndef SETTINGS_VIEW_H

View File

@ -1,24 +1,35 @@
#include<Message.h> /*
#include <String.h> * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
#include <stdio.h> * Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de>
*
*/
#include <math.h>
#include "TimeMessages.h"
#include "TZDisplay.h" #include "TZDisplay.h"
TTZDisplay::TTZDisplay(BRect frame, const char *name, namespace {
uint32 resizingmode, uint32 flags, float _FontHeight()
const char *label, const char *text, {
int32 hour, int32 minute) font_height fontHeight;
: BView(frame, name, resizingmode, flags) be_plain_font->GetHeight(&fontHeight);
float height = ceil(fontHeight.descent) + ceil(fontHeight.ascent)
+ ceil(fontHeight.leading);
return height;
}
}
TTZDisplay::TTZDisplay(BRect frame, const char *name, const char *label)
: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
fLabel(label),
fText(""),
fTime("")
{ {
f_label = new BString(label);
f_text = new BString(text);
f_time = new BString();
SetTo(hour, minute);
} }
@ -35,117 +46,88 @@ TTZDisplay::AttachedToWindow()
} }
void
TTZDisplay::MessageReceived(BMessage *message)
{
switch(message->what) {
default:
BView::MessageReceived(message);
break;
}
}
static float
fontheight()
{
font_height finfo;
be_plain_font->GetHeight(&finfo);
float height = ceil(finfo.descent) +ceil(finfo.ascent) +ceil(finfo.leading);
return height;
}
void void
TTZDisplay::ResizeToPreferred() TTZDisplay::ResizeToPreferred()
{ {
float height = fontheight(); float height = _FontHeight();
ResizeTo(Bounds().Width(), height *2); ResizeTo(Bounds().Width(), height *2);
} }
void void
TTZDisplay::Draw(BRect updaterect) TTZDisplay::Draw(BRect /* updateRect */)
{ {
BRect bounds(Bounds()); BRect bounds(Bounds());
SetLowColor(ViewColor()); SetLowColor(ViewColor());
FillRect(bounds, B_SOLID_LOW); FillRect(bounds, B_SOLID_LOW);
float height = fontheight(); float height = _FontHeight();
BPoint drawpt(bounds.left +2, height/2.0 +1); BPoint drawpt(bounds.left +2, height /2.0 +1);
DrawString(f_label->String(), drawpt); DrawString(fLabel.String(), drawpt);
drawpt.y += fontheight() +2; drawpt.y += height +2;
DrawString(f_text->String(), drawpt); DrawString(fText.String(), drawpt);
drawpt.x = bounds.right -be_plain_font->StringWidth(f_time->String()) - 2; drawpt.x = bounds.right -be_plain_font->StringWidth(fTime.String()) - 2;
DrawString(f_time->String(), drawpt); DrawString(fTime.String(), drawpt);
}
const char*
TTZDisplay::Label() const
{
return fLabel.String();
} }
void void
TTZDisplay::SetLabel(const char *label) TTZDisplay::SetLabel(const char *label)
{ {
f_label->SetTo(label); fLabel.SetTo(label);
Draw(Bounds()); Draw(Bounds());
} }
const char*
TTZDisplay::Text() const
{
return fText.String();
}
void void
TTZDisplay::SetText(const char *text) TTZDisplay::SetText(const char *text)
{ {
f_text->SetTo(text); fText.SetTo(text);
Draw(Bounds()); Draw(Bounds());
} }
void const char*
TTZDisplay::SetTo(int32 hour, int32 minute) TTZDisplay::Time() const
{
return fTime.String();
}
void
TTZDisplay::SetTime(int32 hour, int32 minute)
{ {
// format time into f_time
if (f_time == NULL)
f_time = new BString();
else
f_time->SetTo("");
int32 ahour = hour; int32 ahour = hour;
if (hour> 12) if (hour > 12)
ahour = hour -12; ahour = hour -12;
if (ahour == 0) if (ahour == 0)
ahour = 12; ahour = 12;
char *ap; char *ap = "AM";
if (hour> 11) if (hour > 11)
ap = "PM"; ap = "PM";
else
ap = "AM";
char *time = f_time->LockBuffer(8); fTime.SetTo("");
sprintf(time, "%02lu:%02lu %s", ahour, minute, ap); fTime << ahour << ":" << minute << ":" << ap;
f_time->UnlockBuffer(8);
Invalidate(); Invalidate();
} }
const char *
TTZDisplay::Text() const
{
return f_text->String();
}
const char *
TTZDisplay::Label() const
{
return f_label->String();
}
const char *
TTZDisplay::Time() const
{
return f_time->String();
}

View File

@ -1,34 +1,45 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* probably Mike Berg <mike@agamemnon.homelinux.net>
* and/or Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de>
*
*/
#ifndef TTZDISPLAY_H #ifndef TTZDISPLAY_H
#define TTZDISPLAY_H #define TTZDISPLAY_H
#include <View.h> #include <View.h>
#include <String.h>
class TTZDisplay: public BView
{ class TTZDisplay : public BView {
public: public:
TTZDisplay(BRect frame, const char *name, uint32 resizing, uint32 flags, TTZDisplay(BRect frame, const char *name, const char *label);
const char *label = B_EMPTY_STRING, virtual ~TTZDisplay();
const char *name = B_EMPTY_STRING,
int32 hour = 0, int32 minute = 0); virtual void AttachedToWindow();
~TTZDisplay(); virtual void ResizeToPreferred();
virtual void AttachedToWindow(); virtual void Draw(BRect updateRect);
virtual void MessageReceived(BMessage *message);
virtual void ResizeToPreferred(); const char* Label() const;
void SetLabel(const char *label);
virtual void Draw(BRect);
const char* Text() const;
void SetText(const char *text);
const char* Time() const;
void SetTime(int32 hour, int32 minute);
virtual void SetLabel(const char *label);
virtual void SetText(const char *text);
virtual void SetTo(int32 hour, int32 minute);
virtual const char *Label() const;
virtual const char *Text() const;
virtual const char *Time() const;
private: private:
BString *f_label; BString fLabel;
BString *f_text; BString fText;
BString *f_time; BString fTime;
}; };
#endif //TTZDISPLAY_H #endif // TTZDISPLAY_H

View File

@ -3,8 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Andrew McCall, mccall@digitalparadise.co.uk * Andrew McCall <mccall@digitalparadise.co.uk>
* Mike Berg (inseculous) * Mike Berg <mike@agamemnon.homelinux.net>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */

View File

@ -4,7 +4,7 @@
* *
* Authors: * Authors:
* Andrew McCall, mccall@digitalparadise.co.uk * Andrew McCall, mccall@digitalparadise.co.uk
* Mike Berg (inseculous) * Mike Berg <mike@agamemnon.homelinux.net>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */
#ifndef TIME_H #ifndef TIME_H

View File

@ -4,7 +4,7 @@
* *
* Authors: * Authors:
* Andrew McCall, mccall@digitalparadise.co.uk * Andrew McCall, mccall@digitalparadise.co.uk
* Mike Berg (inseculous) * Mike Berg <mike@agamemnon.homelinux.net>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */
#ifndef TIME_MESSAGES_H #ifndef TIME_MESSAGES_H

View File

@ -4,7 +4,7 @@
* *
* Authors: * Authors:
* Andrew McCall, mccall@digitalparadise.co.uk * Andrew McCall, mccall@digitalparadise.co.uk
* Mike Berg (inseculous) * Mike Berg <mike@agamemnon.homelinux.net>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */

View File

@ -4,7 +4,7 @@
* *
* Authors: * Authors:
* Andrew McCall, mccall@digitalparadise.co.uk * Andrew McCall, mccall@digitalparadise.co.uk
* Mike Berg (inseculous) * Mike Berg <mike@agamemnon.homelinux.net>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */
#ifndef TIME_SETTINGS_H #ifndef TIME_SETTINGS_H

View File

@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* mccall@@digitalparadise.co.uk * Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */

View File

@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* mccall@@digitalparadise.co.uk * Andrew McCall <mccall@@digitalparadise.co.uk>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */
#ifndef TIME_WINDOW_H #ifndef TIME_WINDOW_H

View File

@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Mike Berg (inseculous) * Mike Berg <mike@agamemnon.homelinux.net>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */
@ -43,7 +43,7 @@
#include <stdlib.h> #include <stdlib.h>
class TZoneItem: public BStringItem { class TZoneItem : public BStringItem {
public: public:
TZoneItem(const char *text, const char *zone) TZoneItem(const char *text, const char *zone)
: BStringItem(text), fZone(new BPath(zone)) { } : BStringItem(text), fZone(new BPath(zone)) { }
@ -154,7 +154,7 @@ TZoneView::UpdateDateTime(BMessage *message)
if (fHour != hour || fMinute != minute) { if (fHour != hour || fMinute != minute) {
fHour = hour; fHour = hour;
fMinute = minute; fMinute = minute;
fCurrent->SetTo(hour, minute); fCurrent->SetTime(hour, minute);
// do calc to get other zone time // do calc to get other zone time
if (fCityList->CurrentSelection() > -1) if (fCityList->CurrentSelection() > -1)
@ -205,14 +205,12 @@ TZoneView::InitView()
frameRight.top = frameLeft.top; frameRight.top = frameLeft.top;
// Time Displays // Time Displays
fCurrent = new TTZDisplay(frameRight, "current", fCurrent = new TTZDisplay(frameRight, "current", "Current time:");
B_FOLLOW_NONE, B_WILL_DRAW, "Current time zone:", B_EMPTY_STRING);
AddChild(fCurrent); AddChild(fCurrent);
fCurrent->ResizeToPreferred(); fCurrent->ResizeToPreferred();
frameRight.OffsetBy(0, (textHeight) * 3 +10.0); frameRight.OffsetBy(0, (textHeight) * 3 +10.0);
fPreview = new TTZDisplay(frameRight, "preview", fPreview = new TTZDisplay(frameRight, "preview", "Preview time:");
B_FOLLOW_NONE, B_WILL_DRAW, "Time in: ", B_EMPTY_STRING);
AddChild(fPreview); AddChild(fPreview);
fPreview->ResizeToPreferred(); fPreview->ResizeToPreferred();
@ -391,27 +389,25 @@ TZoneView::ReadTimeZoneLink()
void void
TZoneView::SetPreview() TZoneView::SetPreview()
{ {
// calc and display time based on users selection in city list
int32 selection = fCityList->CurrentSelection(); int32 selection = fCityList->CurrentSelection();
if (selection>= 0) { if (selection >= 0) {
TZoneItem *item = (TZoneItem *)fCityList->ItemAt(selection); TZoneItem *item = (TZoneItem *)fCityList->ItemAt(selection);
BString text; // set timezone to selection
text = item->Text();
time_t current;
struct tm *ltime;
// calc time to display and update
SetTimeZone(item->Path()); SetTimeZone(item->Path());
current = time(0);
ltime = localtime(&current); // calc preview time
time_t current = time(0);
struct tm *ltime = localtime(&current);
// update prview
fPreview->SetText(item->Text());
fPreview->SetTime(ltime->tm_hour, ltime->tm_min);
// set timezone back to current
SetTimeZone(fCurrentZone.Path()); SetTimeZone(fCurrentZone.Path());
fPreview->SetTo(ltime->tm_hour, ltime->tm_min); fSetZone->SetEnabled((strcmp(fCurrent->Text(), item->Text()) != 0));
fPreview->SetText(text.String());
fSetZone->SetEnabled((strcmp(fCurrent->Text(), text.String()) != 0));
} }
} }
@ -420,11 +416,12 @@ void
TZoneView::SetCurrent(const char *text) TZoneView::SetCurrent(const char *text)
{ {
SetTimeZone(fCurrentZone.Path()); SetTimeZone(fCurrentZone.Path());
time_t current = time(0); time_t current = time(0);
struct tm *ltime = localtime(&current); struct tm *ltime = localtime(&current);
fCurrent->SetTo(ltime->tm_hour, ltime->tm_min);
fCurrent->SetText(text); fCurrent->SetText(text);
fCurrent->SetTime(ltime->tm_hour, ltime->tm_min);
} }

View File

@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Mike Berg (inseculous) * Mike Berg <mike@agamemnon.homelinux.net>
* Julun <host.haiku@gmx.de> * Julun <host.haiku@gmx.de>
*/ */
#ifndef ZONE_VIEW_H #ifndef ZONE_VIEW_H