#define ISLEAP(y) (!((y)%4) && (((y) % 100) || (!((y)% 400))))
+/*static */Array<const String> veryShortDaysNames
+{ [
+ $"Sunday"."S", $"Monday"."M", $"Tuesday"."T", $"Wednesday"."W",
+ $"Thursday"."T", $"Friday"."F", $"Saturday"."S"
+] };
+
public class CalendarControl : CommonControl
{
class_property(icon) = "<:ecere>controls/calendar.png";
public:
- virtual void Window::NotifyChanged(bool close);
+ virtual void Window::NotifyChanged(CalendarControl calendarControl, bool close);
Date dateValue;
Month shownMonth;
int shownYear;
dateValue.day = now.day;
dateValue.month = now.month;
shownYear = dateValue.year = now.year;
- shownMonth = dateValue.month;
+ shownMonth = dateValue.month;
}
return true;
}
-
+
RepButton leftArrow
{
- this,
+ this,
position = { 3, 8 };
size = { 16, 16 };
bevel = false;
inactive = true;
background = background;
- font = { "Verdana", 8.25f, true };
+ font = { $"Verdana", 8.25f, true };
foreground = navy;
offset = false;
text = "«";
hotKey = pageUp;
-
+
bool NotifyClicked(Button button, int x, int y, ecere::gui::Modifiers mods)
{
shownMonth--;
if(shownMonth < january) { shownMonth = december; shownYear--; yearBox.Refresh(); }
- monthBox.Refresh();
+ monthBox.Refresh();
Update(null);
dateBox.Activate();
return true;
};
RepButton rightArrow
{
- this,
+ this,
anchor = { right = 8, top = 8 };
size = { 16, 16 };
bevel = false;
inactive = true;
offset = false;
background = background;
- font = { "Verdana", 8.25f, true };
+ font = { $"Verdana", 8.25f, true };
foreground = navy;
text = "»";
hotKey = pageDown;
dateBox.Activate();
return true;
}
- };
+ };
DataBox monthBox
{
this, type = class(Month), data = &shownMonth, position = { 25, 5 }, size = { 75, 20 };
background = background;
foreground = navy;
- font = { "Verdana", 8.25f, true };
+ font = { $"Verdana", 8.25f, true };
bool OnPostCreate()
{
return true;
}
- bool NotifyChanged(bool closingDropDown)
+ bool NotifyChanged(DataBox dataBox, bool closingDropDown)
{
Update(null);
if(closingDropDown)
DataBox yearBox
{
this, type = class(int), data = &shownYear, position = { 100, 5 }, size = { 38, 20 };
- font = { "Verdana", 8.25f, true };
+ font = { $"Verdana", 8.25f, true };
background = background;
foreground = navy;
}
return true;
}
-
+
bool OnPostCreate()
{
DataBox::OnPostCreate();
return true;
}
- bool NotifyChanged(bool closingDropDown)
+ bool NotifyChanged(DataBox dataBox, bool closingDropDown)
{
if(shownYear < 100)
{
shownYear += (time.year / 100) * 100;
if(Abs(shownYear - time.year) >= 50)
shownYear -= 100;
- yearBox.Refresh();
+ yearBox.Refresh();
}
Update(null);
dateBox.Activate();
monthBox.Refresh();
yearBox.Refresh();
- NotifyChanged(master, closeCalendar);
+ NotifyChanged(master, this, closeCalendar);
return;
}
if(++day.day > monthLengths[ISLEAP(day.year)][day.month])
{
if(mods.left && !mods.isSideEffect)
((CalendarControl)master).FindDate(x, y, false, false);
- return true;
+ return true;
}
bool OnLeftButtonDown(int x, int y, Modifiers mods)
{
surface.SetForeground(black);
for(d = sunday; d <= saturday; d++)
- surface.CenterTextf(Width / 2 + d * Width, 0, "%c", toupper(daysNames[d][0]));
+ {
+ surface.CenterTextf(Width / 2 + d * Width, 0, "%s", veryShortDaysNames[d]);
+ }
surface.SetBackground(Color { 238, 238, 238 } /*whiteSmoke*/);
surface.Area(0, Height, Width, clientSize.h);
surface.Area(6 * Width, Height, 7*Width, clientSize.h);
-
+
surface.SetForeground(lightGray);
surface.DrawLine(0, Height, clientSize.w, Height);
surface.DrawLine(0, Height, 0, clientSize.h);
}
}
}
- }
+ }
}
};
case down:
if(dateBox.active)
{
- if(key == left) dateValue.day--;
+ if(shownMonth != dateValue.month || shownYear != dateValue.year)
+ {
+ dateValue.month = shownMonth;
+ dateValue.year = shownYear;
+ dateValue.day = 1;
+ }
+ else if(key == left) dateValue.day--;
else if(key == right) dateValue.day++;
else if(key == up) dateValue.day-=7;
else if(key == down) dateValue.day+=7;
}
shownMonth = dateValue.month;
shownYear = dateValue.year;
- NotifyChanged(master, false);
+ NotifyChanged(master, this, false);
monthBox.Refresh();
yearBox.Refresh();