mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
CtrlLib: Calendar, DropDate: Fixed issue with end of month clicks, WhenWeek
git-svn-id: svn://ultimatepp.org/upp/trunk@6148 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
4b9000ab3b
commit
6c5b5a8f2e
5 changed files with 164 additions and 45 deletions
|
|
@ -72,6 +72,7 @@ void Calendar::Reset()
|
||||||
wastoday = false;
|
wastoday = false;
|
||||||
|
|
||||||
newday = oldday = nullday;
|
newday = oldday = nullday;
|
||||||
|
newweek = oldweek = -1;
|
||||||
stoday = Format("%s: %s", t_("Today"), time_mode ? Format(today) : Format(Date(today)));
|
stoday = Format("%s: %s", t_("Today"), time_mode ? Format(today) : Format(Date(today)));
|
||||||
|
|
||||||
UpdateFields();
|
UpdateFields();
|
||||||
|
|
@ -199,6 +200,31 @@ int Calendar::WeekOfYear(int day, int month, int year) /* ISO-8601 */
|
||||||
|
|
||||||
void Calendar::LeftDown(Point p, dword keyflags)
|
void Calendar::LeftDown(Point p, dword keyflags)
|
||||||
{
|
{
|
||||||
|
if(WhenWeek && newweek >= 0) {
|
||||||
|
if(PopUpCtrl::IsPopUp())
|
||||||
|
Deactivate();
|
||||||
|
Date d = view;
|
||||||
|
int wday = days[newweek][0];
|
||||||
|
d.day = wday;
|
||||||
|
if(wday < 0) {
|
||||||
|
d.day = -wday;
|
||||||
|
if(newweek == 0)
|
||||||
|
d.month--;
|
||||||
|
else
|
||||||
|
d.month++;
|
||||||
|
if(d.month < 1) {
|
||||||
|
d.month = 12;
|
||||||
|
d.year--;
|
||||||
|
}
|
||||||
|
if(d.month > 12) {
|
||||||
|
d.month = 1;
|
||||||
|
d.year++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WhenWeek(d);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool isnewday = newday != nullday;
|
bool isnewday = newday != nullday;
|
||||||
int day = 1;
|
int day = 1;
|
||||||
bool refall = false;
|
bool refall = false;
|
||||||
|
|
@ -210,7 +236,7 @@ void Calendar::LeftDown(Point p, dword keyflags)
|
||||||
if(day < 0)
|
if(day < 0)
|
||||||
{
|
{
|
||||||
view.day = -day;
|
view.day = -day;
|
||||||
if(lastrow < 3)
|
if(newday.y == 0)
|
||||||
view.month--;
|
view.month--;
|
||||||
else
|
else
|
||||||
view.month++;
|
view.month++;
|
||||||
|
|
@ -263,11 +289,11 @@ void Calendar::LeftDown(Point p, dword keyflags)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefreshDay(prevday);
|
Refresh();
|
||||||
if(istoday)
|
if(istoday)
|
||||||
SetDate(tm);
|
SetDate(tm);
|
||||||
else
|
else
|
||||||
RefreshDay(newday);
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
WhenSelect();
|
WhenSelect();
|
||||||
|
|
@ -284,7 +310,7 @@ void Calendar::MouseMove(Point p, dword keyflags)
|
||||||
if(b)
|
if(b)
|
||||||
{
|
{
|
||||||
view.day = 0;
|
view.day = 0;
|
||||||
RefreshDay(oldday);
|
Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(newday != nullday)
|
if(newday != nullday)
|
||||||
|
|
@ -293,16 +319,21 @@ void Calendar::MouseMove(Point p, dword keyflags)
|
||||||
if(b)
|
if(b)
|
||||||
{
|
{
|
||||||
view.day = Day(newday);
|
view.day = Day(newday);
|
||||||
RefreshDay(newday);
|
Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldday = newday;
|
oldday = newday;
|
||||||
}
|
}
|
||||||
|
newweek = GetWeek(p);
|
||||||
|
if(newweek != oldweek && WhenWeek) {
|
||||||
|
Refresh();
|
||||||
|
oldweek = newweek;
|
||||||
|
}
|
||||||
istoday = MouseOnToday(p);
|
istoday = MouseOnToday(p);
|
||||||
if(istoday != wastoday)
|
if(istoday != wastoday)
|
||||||
{
|
{
|
||||||
wastoday = istoday;
|
wastoday = istoday;
|
||||||
RefreshToday();
|
Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -325,29 +356,6 @@ bool Calendar::MouseOnToday(Point p)
|
||||||
return (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1);
|
return (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Calendar::RefreshDay(Point p)
|
|
||||||
{
|
|
||||||
col = p.x;
|
|
||||||
row = p.y;
|
|
||||||
|
|
||||||
int y0 = 2 + (int)((p.y + 1) * rowh + hs);
|
|
||||||
int x0 = bs + 2 + (int)((p.x + 1) * colw);
|
|
||||||
|
|
||||||
Refresh(x0, y0, cw, rh);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Calendar::RefreshToday()
|
|
||||||
{
|
|
||||||
Size sz = GetSize();
|
|
||||||
Refresh(0, sz.cy - ts, sz.cx, ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Calendar::RefreshHeader()
|
|
||||||
{
|
|
||||||
Size sz = GetSize();
|
|
||||||
Refresh(0, 0, sz.cx, hs);
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Calendar::GetDay(Point p)
|
Point Calendar::GetDay(Point p)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < rows; i++)
|
for(int i = 0; i < rows; i++)
|
||||||
|
|
@ -355,18 +363,31 @@ Point Calendar::GetDay(Point p)
|
||||||
int y0 = 2 + (int)((i + 1) * rowh + hs);
|
int y0 = 2 + (int)((i + 1) * rowh + hs);
|
||||||
int y1 = y0 + rh;
|
int y1 = y0 + rh;
|
||||||
|
|
||||||
if(p.y >= y0 && p.y < y1)
|
if(p.y >= y0 && p.y < y1) {
|
||||||
for(int j = 0; j < cols; j++)
|
for(int j = 0; j < cols; j++)
|
||||||
{
|
{
|
||||||
int x0 = bs + 2 + (int)((j + 1) * colw);
|
int x0 = bs + 2 + (int)((j + 1) * colw);
|
||||||
int x1 = x0 + cw;
|
int x1 = x0 + cw;
|
||||||
if(p.x >= x0 && p.x < x1)
|
if(p.x >= x0 && p.x < x1)
|
||||||
return Point(j, i);
|
return Point(j, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Point(-1, -1);
|
return Point(-1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Calendar::GetWeek(Point p)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
|
int y0 = 2 + (int)((i + 1) * rowh + hs);
|
||||||
|
int y1 = y0 + rh;
|
||||||
|
if(p.y >= y0 && p.y < y1 && p.x < bs + 2 + colw)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
Size Calendar::ComputeSize()
|
Size Calendar::ComputeSize()
|
||||||
{
|
{
|
||||||
const Style &st = *style;
|
const Style &st = *style;
|
||||||
|
|
@ -478,7 +499,16 @@ void Calendar::Paint(Draw &w)
|
||||||
int yc = (rh - fh) / 2;
|
int yc = (rh - fh) / 2;
|
||||||
|
|
||||||
str = AsString(WeekOfYear(d, m, y));
|
str = AsString(WeekOfYear(d, m, y));
|
||||||
w.DrawText(bs + (cw - GetTextSize(str, fnt).cx) / 2, yp + yc, str, fnt.NoBold().NoUnderline(), st.week);
|
|
||||||
|
Font wfnt = fnt;
|
||||||
|
wfnt.NoBold().NoUnderline();
|
||||||
|
Color wcolor = st.week;
|
||||||
|
if(newweek >= 0 && WhenWeek && newweek == i) {
|
||||||
|
wfnt.Bold().Underline();
|
||||||
|
wcolor = st.selectday;
|
||||||
|
}
|
||||||
|
|
||||||
|
w.DrawText(bs + (cw - GetTextSize(str, fnt).cx) / 2, yp + yc, str, wfnt, wcolor);
|
||||||
|
|
||||||
for(int j = 0; j < cols; j++)
|
for(int j = 0; j < cols; j++)
|
||||||
{
|
{
|
||||||
|
|
@ -631,7 +661,7 @@ void Calendar::MouseLeave()
|
||||||
{
|
{
|
||||||
istoday = false;
|
istoday = false;
|
||||||
wastoday = false;
|
wastoday = false;
|
||||||
RefreshToday();
|
Refresh();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
MouseMove(Point(-1, -1), 0);
|
MouseMove(Point(-1, -1), 0);
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,7 @@ private:
|
||||||
Point oldday;
|
Point oldday;
|
||||||
Point prevday;
|
Point prevday;
|
||||||
Point curday, firstday;
|
Point curday, firstday;
|
||||||
|
int newweek, oldweek;
|
||||||
|
|
||||||
String stoday;
|
String stoday;
|
||||||
Size sztoday;
|
Size sztoday;
|
||||||
|
|
@ -199,17 +200,16 @@ private:
|
||||||
virtual Image CursorImage(Point p, dword keyflags);
|
virtual Image CursorImage(Point p, dword keyflags);
|
||||||
|
|
||||||
int& Day(int x, int y) { return days[y][x]; }
|
int& Day(int x, int y) { return days[y][x]; }
|
||||||
int& Day(Point p) { return days[p.y][p.x]; }
|
int& Day(Point p) { return Day(p.x, p.y); }
|
||||||
Point GetDay(Point p);
|
Point GetDay(Point p);
|
||||||
|
int GetWeek(Point p);
|
||||||
|
|
||||||
void RefreshDay(Point p);
|
|
||||||
void RefreshToday();
|
|
||||||
void RefreshHeader();
|
|
||||||
virtual Size ComputeSize();
|
virtual Size ComputeSize();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Calendar();
|
Calendar();
|
||||||
Callback1<Time &> WhenTime;
|
Callback1<Time &> WhenTime;
|
||||||
|
Callback1<Date> WhenWeek;
|
||||||
|
|
||||||
static const Style& StyleDefault();
|
static const Style& StyleDefault();
|
||||||
|
|
||||||
|
|
@ -481,6 +481,10 @@ class DateTimeCtrl : public T {
|
||||||
r.right += diff;
|
r.right += diff;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(WhenWeek)
|
||||||
|
cc.calendar.WhenWeek = Proxy(WhenWeek);
|
||||||
|
else
|
||||||
|
cc.calendar.WhenWeek.Clear();
|
||||||
cc.PopUp(this, r);
|
cc.PopUp(this, r);
|
||||||
cc.calendar <<= this->GetData();
|
cc.calendar <<= this->GetData();
|
||||||
cc.clock <<= this->GetData();
|
cc.clock <<= this->GetData();
|
||||||
|
|
@ -488,6 +492,8 @@ class DateTimeCtrl : public T {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef DateTimeCtrl CLASSNAME;
|
typedef DateTimeCtrl CLASSNAME;
|
||||||
|
|
||||||
|
Callback1<Date> WhenWeek;
|
||||||
|
|
||||||
DateTimeCtrl(int m) : cc(m) {
|
DateTimeCtrl(int m) : cc(m) {
|
||||||
drop.AddTo(*this);
|
drop.AddTo(*this);
|
||||||
|
|
|
||||||
|
|
@ -135,9 +135,17 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
void Add(DropList& list, const VectorMap<Value, Value>& values);
|
void Add(DropList& list, const VectorMap<Value, Value>& values);
|
||||||
|
void Add(DropList& list, const VectorMap<int, String>& values);
|
||||||
void Add(MapConvert& convert, const VectorMap<Value, Value>& values);
|
void Add(MapConvert& convert, const VectorMap<Value, Value>& values);
|
||||||
|
void Add(MapConvert& convert, const VectorMap<int, String>& values);
|
||||||
void Add(DropList& list, const MapConvert& convert);
|
void Add(DropList& list, const MapConvert& convert);
|
||||||
|
|
||||||
|
void operator*=(DropList& list, const VectorMap<Value, Value>& values);
|
||||||
|
void operator*=(DropList& list, const VectorMap<int, String>& values);
|
||||||
|
void operator*=(MapConvert& convert, const VectorMap<Value, Value>& values);
|
||||||
|
void operator*=(MapConvert& convert, const VectorMap<int, String>& values);
|
||||||
|
void operator*=(DropList& list, const MapConvert& convert);
|
||||||
|
|
||||||
class DropChoice : public MultiButtonFrame {
|
class DropChoice : public MultiButtonFrame {
|
||||||
public:
|
public:
|
||||||
virtual void Serialize(Stream& s); //empty
|
virtual void Serialize(Stream& s); //empty
|
||||||
|
|
|
||||||
|
|
@ -277,10 +277,53 @@ void Add(MapConvert& convert, const VectorMap<Value, Value>& values)
|
||||||
convert.Add(values.GetKey(i), values[i]);
|
convert.Add(values.GetKey(i), values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Add(DropList& list, const VectorMap<int, String>& values)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < values.GetCount(); i++)
|
||||||
|
list.Add(values.GetKey(i), values[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Add(MapConvert& convert, const VectorMap<int, String>& values)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < values.GetCount(); i++)
|
||||||
|
convert.Add(values.GetKey(i), values[i]);
|
||||||
|
}
|
||||||
|
|
||||||
void Add(DropList& list, const MapConvert& convert)
|
void Add(DropList& list, const MapConvert& convert)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < convert.GetCount(); i++)
|
for(int i = 0; i < convert.GetCount(); i++)
|
||||||
list.Add(convert.GetKey(i), convert.GetValue(i));
|
list.Add(convert.GetKey(i), convert.GetValue(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void operator*=(DropList& list, const VectorMap<Value, Value>& values)
|
||||||
|
{
|
||||||
|
list.ClearList();
|
||||||
|
Add(list, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator*=(MapConvert& convert, const VectorMap<Value, Value>& values)
|
||||||
|
{
|
||||||
|
convert.Clear();
|
||||||
|
Add(convert, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator*=(DropList& list, const VectorMap<int, String>& values)
|
||||||
|
{
|
||||||
|
list.ClearList();
|
||||||
|
Add(list, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator*=(MapConvert& convert, const VectorMap<int, String>& values)
|
||||||
|
{
|
||||||
|
convert.Clear();
|
||||||
|
Add(convert, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator*=(DropList& list, const MapConvert& convert)
|
||||||
|
{
|
||||||
|
list.ClearList();
|
||||||
|
Add(list, convert);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
END_UPP_NAMESPACE
|
END_UPP_NAMESPACE
|
||||||
|
|
|
||||||
|
|
@ -316,18 +316,50 @@ list and MapConvert.&]
|
||||||
[s5;:Add`(DropList`&`,const VectorMap`<Value`,Value`>`&`): [@(0.0.255) void]_[* Add]([_^DropList^ D
|
[s5;:Add`(DropList`&`,const VectorMap`<Value`,Value`>`&`): [@(0.0.255) void]_[* Add]([_^DropList^ D
|
||||||
ropList][@(0.0.255) `&]_[*@3 list], [@(0.0.255) const]_[_^VectorMap^ VectorMap][@(0.0.255) <
|
ropList][@(0.0.255) `&]_[*@3 list], [@(0.0.255) const]_[_^VectorMap^ VectorMap][@(0.0.255) <
|
||||||
][_^Value^ Value], [_^Value^ Value][@(0.0.255) >`&]_[*@3 values])&]
|
][_^Value^ Value], [_^Value^ Value][@(0.0.255) >`&]_[*@3 values])&]
|
||||||
|
[s5;:Add`(DropList`&`,const VectorMap`<int`,String`>`&`): [@(0.0.255) void]_[* Add]([_^DropList^ D
|
||||||
|
ropList][@(0.0.255) `&]_[*@3 list], [@(0.0.255) const]_[_^VectorMap^ VectorMap]<[@(0.0.255) i
|
||||||
|
nt], [_^String^ String]>`&_[*@3 values])&]
|
||||||
[s2;%% Fills the DropList from VectorMap.&]
|
[s2;%% Fills the DropList from VectorMap.&]
|
||||||
[s3; &]
|
[s3; &]
|
||||||
[s4; &]
|
[s4; &]
|
||||||
[s5;:Add`(MapConvert`&`,const VectorMap`<Value`,Value`>`&`): [@(0.0.255) void]_[* Add]([_^MapConvert^ M
|
[s5;:Add`(MapConvert`&`,const VectorMap`<Value`,Value`>`&`): [@(0.0.255) void]_[* Add]([_^MapConvert^ M
|
||||||
apConvert][@(0.0.255) `&]_[*@3 convert], [@(0.0.255) const]_[_^VectorMap^ VectorMap][@(0.0.255) <
|
apConvert][@(0.0.255) `&]_[*@3 convert], [@(0.0.255) const]_[_^VectorMap^ VectorMap][@(0.0.255) <
|
||||||
][_^Value^ Value], [_^Value^ Value][@(0.0.255) >`&]_[*@3 values])&]
|
][_^Value^ Value], [_^Value^ Value][@(0.0.255) >`&]_[*@3 values])&]
|
||||||
|
[s5;:Add`(MapConvert`&`,const VectorMap`<int`,String`>`&`): [@(0.0.255) void]_[* Add]([_^MapConvert^ M
|
||||||
|
apConvert][@(0.0.255) `&]_[*@3 convert], [@(0.0.255) const]_[_^VectorMap^ VectorMap]<[@(0.0.255) i
|
||||||
|
nt], [_^String^ String]>`&_[*@3 values])&]
|
||||||
[s2;%% Fills the MapConvert from VectorMap.&]
|
[s2;%% Fills the MapConvert from VectorMap.&]
|
||||||
[s3; &]
|
[s3;%% &]
|
||||||
[s4; &]
|
[s4; &]
|
||||||
[s5;:Add`(DropList`&`,const MapConvert`&`): [@(0.0.255) void]_[* Add]([_^DropList^ DropList
|
[s5;:Add`(DropList`&`,const MapConvert`&`): [@(0.0.255) void]_[* Add]([_^DropList^ DropList
|
||||||
][@(0.0.255) `&]_[*@3 list], [@(0.0.255) const]_[_^MapConvert^ MapConvert][@(0.0.255) `&]_[*@3 c
|
][@(0.0.255) `&]_[*@3 list], [@(0.0.255) const]_[_^MapConvert^ MapConvert][@(0.0.255) `&]_[*@3 c
|
||||||
onvert])&]
|
onvert])&]
|
||||||
[s2;%% Fills the DropList from MapConvert.&]
|
[s2;%% Fills the DropList from MapConvert.&]
|
||||||
[s3; &]
|
[s3;%% &]
|
||||||
[s0; ]
|
[s4; &]
|
||||||
|
[s5;:operator`*`=`(DropList`&`,const VectorMap`<Value`,Value`>`&`): [@(0.0.255) void]_[* o
|
||||||
|
perator`*`=]([_^DropList^ DropList][@(0.0.255) `&]_[*@3 list], [@(0.0.255) const]_[_^VectorMap^ V
|
||||||
|
ectorMap]<[_^Value^ Value], [_^Value^ Value]>`&_[*@3 values])&]
|
||||||
|
[s5;:operator`*`=`(DropList`&`,const VectorMap`<int`,String`>`&`): [@(0.0.255) void]_[* o
|
||||||
|
perator`*`=]([_^DropList^ DropList][@(0.0.255) `&]_[*@3 list], [@(0.0.255) const]_[_^VectorMap^ V
|
||||||
|
ectorMap]<[@(0.0.255) int], [_^String^ String]>`&_[*@3 values])&]
|
||||||
|
[s2;%% Clears and fills the DropList from VectorMap.&]
|
||||||
|
[s3;%% &]
|
||||||
|
[s4; &]
|
||||||
|
[s5;:operator`*`=`(MapConvert`&`,const VectorMap`<Value`,Value`>`&`): [@(0.0.255) void]_
|
||||||
|
[* operator`*`=]([_^MapConvert^ MapConvert][@(0.0.255) `&]_[*@3 convert],
|
||||||
|
[@(0.0.255) const]_[_^VectorMap^ VectorMap]<[_^Value^ Value], [_^Value^ Value]>`&_[*@3 valu
|
||||||
|
es])&]
|
||||||
|
[s5;:operator`*`=`(MapConvert`&`,const VectorMap`<int`,String`>`&`): [@(0.0.255) void]_
|
||||||
|
[* operator`*`=]([_^MapConvert^ MapConvert][@(0.0.255) `&]_[*@3 convert],
|
||||||
|
[@(0.0.255) const]_[_^VectorMap^ VectorMap]<[@(0.0.255) int], [_^String^ String]>`&_[*@3 va
|
||||||
|
lues])&]
|
||||||
|
[s2;%% Clears and fills the MapConvert from VectorMap.&]
|
||||||
|
[s3;%% &]
|
||||||
|
[s4; &]
|
||||||
|
[s5;:operator`*`=`(DropList`&`,const MapConvert`&`): [@(0.0.255) void]_[* operator`*`=]([_^DropList^ D
|
||||||
|
ropList][@(0.0.255) `&]_[*@3 list], [@(0.0.255) const]_[_^MapConvert^ MapConvert][@(0.0.255) `&
|
||||||
|
]_[*@3 convert])&]
|
||||||
|
[s2;%% Clears and fills the DropList from MapConvert.&]
|
||||||
|
[s3;%% &]
|
||||||
|
[s0;%% ]]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue