From 1a5b433b3e600dd419ccdb078121ca91bb1ac698 Mon Sep 17 00:00:00 2001 From: David Freese Date: Wed, 15 Nov 2017 06:38:13 -0600 Subject: [PATCH] Calendar widget * Fix to year display bug --- src/flmsg_dialog.cxx | 69 ++++++++++++++++++++++++++++---------- src/include/flmsg_dialog.h | 1 + src/widgets/calendar.cxx | 3 +- src/widgets/date.cxx | 31 ++++++++++------- 4 files changed, 72 insertions(+), 32 deletions(-) diff --git a/src/flmsg_dialog.cxx b/src/flmsg_dialog.cxx index 2f1bd72..1f4e6df 100644 --- a/src/flmsg_dialog.cxx +++ b/src/flmsg_dialog.cxx @@ -1519,6 +1519,7 @@ Fl_Round_Button *btn_dtformat0 = (Fl_Round_Button *)0; Fl_Round_Button *btn_dtformat1 = (Fl_Round_Button *)0; Fl_Round_Button *btn_dtformat2 = (Fl_Round_Button *)0; Fl_Round_Button *btn_dtformat3 = (Fl_Round_Button *)0; +Fl_Round_Button *btn_dtformat4 = (Fl_Round_Button *)0; Fl_Round_Button *btn_utc_format0 = (Fl_Round_Button *)0; Fl_Round_Button *btn_utc_format1 = (Fl_Round_Button *)0; Fl_Round_Button *btn_utc_format2 = (Fl_Round_Button *)0; @@ -1561,46 +1562,75 @@ void set_datetime_widgets() static void cb_btn_dtformat0(Fl_Round_Button* o, void*) { + btn_dtformat3->value(0); + btn_dtformat1->value(0); + btn_dtformat2->value(0); + btn_dtformat4->value(0); if (o->value()) { progStatus.dtformat = 0; - btn_dtformat1->value(0); - btn_dtformat2->value(0); - btn_dtformat3->value(0); - set_datetime_widgets(); + } else { + btn_dtformat4->value(1); + progStatus.dtformat = 4; } + set_datetime_widgets(); } static void cb_btn_dtformat1(Fl_Round_Button* o, void*) { + btn_dtformat0->value(0); + btn_dtformat3->value(0); + btn_dtformat2->value(0); + btn_dtformat4->value(0); if (o->value()) { progStatus.dtformat = 1; - btn_dtformat0->value(0); - btn_dtformat2->value(0); - btn_dtformat3->value(0); - set_datetime_widgets(); + } else { + btn_dtformat4->value(1); + progStatus.dtformat = 4; } + set_datetime_widgets(); } static void cb_btn_dtformat2(Fl_Round_Button* o, void*) { + btn_dtformat0->value(0); + btn_dtformat1->value(0); + btn_dtformat3->value(0); + btn_dtformat4->value(0); if (o->value()) { progStatus.dtformat = 2; - btn_dtformat0->value(0); - btn_dtformat1->value(0); - btn_dtformat3->value(0); - set_datetime_widgets(); + } else { + btn_dtformat4->value(1); + progStatus.dtformat = 4; } + set_datetime_widgets(); } static void cb_btn_dtformat3(Fl_Round_Button* o, void*) { + btn_dtformat0->value(0); + btn_dtformat1->value(0); + btn_dtformat2->value(0); + btn_dtformat4->value(0); if (o->value()) { progStatus.dtformat = 3; - btn_dtformat0->value(0); - btn_dtformat1->value(0); - btn_dtformat2->value(0); - set_datetime_widgets(); + } else { + btn_dtformat4->value(1); + progStatus.dtformat = 4; } + set_datetime_widgets(); +} + +static void cb_btn_dtformat4(Fl_Round_Button* o, void*) +{ + btn_dtformat0->value(0); + btn_dtformat1->value(0); + btn_dtformat2->value(0); + btn_dtformat3->value(0); + btn_dtformat4->value(1); + + progStatus.dtformat = 4; + + set_datetime_widgets(); } static void cb_btn_utc_format0(Fl_Round_Button* o, void*) @@ -1785,7 +1815,12 @@ Fl_Group *create_tab_date_time(int X, int Y, int W, int H, const char *title) btn_dtformat2->callback((Fl_Callback*)cb_btn_dtformat2); if (progStatus.dtformat == 2) btn_dtformat2->value(1); else btn_dtformat2->value(0); - btn_caplocal = new Fl_Check_Button(X, Y+118, 70, 20, _("CAP Local time")); + btn_dtformat4 = new Fl_Round_Button(X, Y+96, 70, 20, _("YYYYMMDD")); + btn_dtformat4->down_box(FL_ROUND_DOWN_BOX); + btn_dtformat4->callback((Fl_Callback*)cb_btn_dtformat4); + if (progStatus.dtformat == 4) btn_dtformat4->value(1); else btn_dtformat4->value(0); + + btn_caplocal = new Fl_Check_Button(X, Y+140, 70, 20, _("CAP Local date/time")); btn_caplocal->tooltip(_("Check to use local date/time\ndefault Zulu")); btn_caplocal->callback((Fl_Callback*)cb_caplocal); diff --git a/src/include/flmsg_dialog.h b/src/include/flmsg_dialog.h index d5493de..c8d7610 100644 --- a/src/include/flmsg_dialog.h +++ b/src/include/flmsg_dialog.h @@ -127,6 +127,7 @@ extern Fl_Round_Button *btn_dtformat0; extern Fl_Round_Button *btn_dtformat1; extern Fl_Round_Button *btn_dtformat2; extern Fl_Round_Button *btn_dtformat3; +extern Fl_Round_Button *btn_dtformat4; extern Fl_Round_Button *btn_utc_format0; extern Fl_Round_Button *btn_utc_format1; extern Fl_Round_Button *btn_utc_format2; diff --git a/src/widgets/calendar.cxx b/src/widgets/calendar.cxx index 240d9da..8b9cb7e 100644 --- a/src/widgets/calendar.cxx +++ b/src/widgets/calendar.cxx @@ -521,8 +521,7 @@ Fl_DateInput::fl_popcal() sscanf(Input->value(),"%4d%2d%2d", &y, &m, &d); break; } - if (y < 10) y+=2000; - if (y < 100) y+=1900; + if (y < 100) y+=2000; Cal->setDate (m,d,y); Cal->popcalfmt (popcalfmt_); diff --git a/src/widgets/date.cxx b/src/widgets/date.cxx index 9cd9000..f2efc3d 100644 --- a/src/widgets/date.cxx +++ b/src/widgets/date.cxx @@ -39,18 +39,18 @@ const int Date::jdays[2][13] = { const char *Date::month_name[] = { - "January", - "Febuary", - "March", - "April", + "Jan", + "Feb", + "Mar", + "Apr", "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December" + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec" }; bool date_local_ = false; @@ -141,7 +141,6 @@ bool Date::leapYear( int y ) bool Date::isvalid( int m, int d, int y ) { - if( y > 2035 ) return false; if( m < 1 || m > 12 ) return false; if( d < 1 ) return false; if( leapYear( y ) ){ @@ -276,11 +275,17 @@ char *Date::szDate (int fmt) month); break; case 4 : + snprintf (temp, sizeof(temp), "%4d%02d%02d", + year, + month, + day); + break; + case 5 : strcpy (szMonth, month_name [month - 1]); szMonth[3] = 0; snprintf (temp, sizeof(temp), "%s %2d, %4d", szMonth, day, year); break; - case 5 : + case 6 : strcpy (szMonth, month_name [month - 1]); szMonth[3] = 0; for (int i = 0; i < 3; i++) szMonth[i] = toupper(szMonth[i]);