1 #include <Wt/WServer.h> 2 #include <Wt/WApplication.h> 3 #include <Wt/WEnvironment.h> 4 #include <Wt/WContainerWidget.h> 5 #include <Wt/WBootstrapTheme.h> 6 #include <Wt/WTemplate.h> 10 #include <Wt/WTableView.h> 13 #define COUT_(X) std::cout << __FILE__ << "::" << __LINE__ << " " << X << std::endl; 14 #define COUT_LINE COUT_(""); 30 :
public Wt::WContainerWidget
56 const Wt::WDate & date()
const;
58 Wt::WTemplate * templt();
61 Wt::WContainerWidget * body();
69 Wt::WTemplate * m_templt =
nullptr;
70 Wt::WText * m_day =
nullptr;
71 Wt::WText * m_header =
nullptr;
72 Wt::WContainerWidget * m_body =
nullptr;
73 Wt::WText * m_footer =
nullptr;
77 CalendarDay::CalendarDay(
const Wt::WDate & d )
80 addStyleClass(
"divTableCell" );
82 m_templt = addNew<Wt::WTemplate>( Wt::WString::tr(
"Calendar.day.cell" ) );
84 m_day = m_templt-> bindNew<Wt::WText>(
"day", Wt::WString(
"{1}").arg( date().day() ) );
85 m_day-> addStyleClass(
"divDay" );
87 m_header = m_templt-> bindNew<Wt::WText>(
"header" );
88 m_header-> addStyleClass(
"divHeader" );
90 m_body = m_templt-> bindNew<Wt::WContainerWidget>(
"body" );
91 m_body-> addStyleClass(
"divBody" );
93 m_footer = m_templt-> bindNew<Wt::WText>(
"footer" );
94 m_footer-> addStyleClass(
"divFooter" );
98 const Wt::WDate & CalendarDay::date()
const 103 Wt::WTemplate * CalendarDay::templt()
108 Wt::WText * CalendarDay::day()
113 Wt::WText * CalendarDay::header()
118 Wt::WContainerWidget * CalendarDay::body()
123 Wt::WText * CalendarDay::footer()
143 CalendarWeek::CalendarWeek(
const Wt::WDate & date )
145 addStyleClass(
"divTableRow" );
155 const std::vector< CalendarDay * > & days()
const;
161 std::vector< CalendarDay * > m_days;
164 CalendarMonth::CalendarMonth(
const Wt::WDate & selectedDate )
166 addStyleClass(
"divTable" );
167 addStyleClass(
"blueTable" );
169 Wt::WDate first( selectedDate.year(), selectedDate.month(), 1 );
170 Wt::WDate start = first.addDays( first.dayOfWeek() * -1 );
173 auto cwHeader = addNew<Wt::WContainerWidget>();
174 cwHeader-> addStyleClass(
"divTableHeading" );
176 auto cwRow = cwHeader-> addNew<Wt::WContainerWidget>();
177 cwRow-> addStyleClass(
"divTableRow" );
179 static const std::vector<std::string>
daynames =
189 for(
int weekday = 0; weekday < 7; weekday++ )
191 auto cwDay = cwRow-> addNew<Wt::WContainerWidget>();
192 cwDay-> addStyleClass(
"divTableHead" );
194 cwDay-> addNew<Wt::WText>( daynames.at(weekday) );
198 int cellDate = first.dayOfWeek() * -1;
204 for(
int week = 0; week < 5; week++ )
206 auto currentWeek = start.addDays( week*7 );
208 auto cwWeek = addNew<CalendarWeek>( currentWeek );
214 for(
int day = 0; day < 7; day++ )
220 auto currentDay = start.addDays( (week*7)+day );
226 auto cwDay = cwWeek-> addNew<CalendarDay>( currentDay );
234 if( currentDay.month() != selectedDate.month() )
236 cwDay-> day()-> setText
238 Wt::WString(
"{1} {2}")
239 .arg( Wt::WDate::shortMonthName( currentDay.month() ) )
240 .arg( currentDay.day() )
249 if( currentDay.month() < selectedDate.month() )
251 cwDay-> addStyleClass(
"divPreviousMonth" );
259 if( currentDay.month() > selectedDate.month() )
261 cwDay-> addStyleClass(
"divNextMonth" );
269 if( currentDay == selectedDate )
271 cwDay-> addStyleClass(
"divCurrentDay" );
278 m_days.push_back( cwDay );
288 const std::vector< CalendarDay * > & CalendarMonth::days()
const 294 :
public Wt::WContainerWidget
304 Wt::WTemplate * m_templt =
nullptr;
306 Wt::WContainerWidget * m_dayPicker =
nullptr;
309 CalendarWidget::CalendarWidget()
311 m_templt = addNew<Wt::WTemplate>( Wt::WString::tr(
"Calendar.widget" ) );
313 m_dayPicker = m_templt-> bindNew<Wt::WContainerWidget>(
"dayPicker" );
314 m_monthView = m_templt-> bindNew<CalendarMonth>(
"monthView", Wt::WDate::currentDate() );
316 std::map< Wt::WDate, std::string > holidays =
318 { Wt::WDate( 2018, 5, 5 ),
"Cinco de Mayo" },
319 { Wt::WDate( 2018, 5, 10 ),
"Ascension Day" },
320 { Wt::WDate( 2018, 5, 13 ),
"Mother's Day" },
321 { Wt::WDate( 2018, 5, 21 ),
"Victoria Day (Canada)" },
322 { Wt::WDate( 2018, 5, 28 ),
"Memorial Day (USA)" }
325 for(
auto calendarDay : m_monthView-> days() )
327 auto holidayItem = holidays.find( calendarDay-> date() );
328 if( holidayItem != holidays.end() )
330 calendarDay-> header()-> setText( holidayItem-> second );
334 std::map< Wt::WDate, std::string > moon =
336 { Wt::WDate( 2018, 5, 7 ),
"Last Quarter Moon" },
337 { Wt::WDate( 2018, 5, 15 ),
"New Moon" },
338 { Wt::WDate( 2018, 5, 21 ),
"New Quarter Moon" },
339 { Wt::WDate( 2018, 5, 29 ),
"Full Moon" }
342 for(
auto calendarDay : m_monthView-> days() )
344 auto moonItem = moon.find( calendarDay-> date() );
345 if( moonItem != moon.end() )
347 calendarDay-> footer()-> setText( moonItem-> second );
358 :
public Wt::WApplication
361 DevApp(
const Wt::WEnvironment &env)
362 :
Wt::WApplication( env )
364 auto bootstrapTheme = std::make_shared<Wt::WBootstrapTheme>();
365 bootstrapTheme-> setVersion( Wt::BootstrapVersion::v3 );
366 bootstrapTheme-> setResponsive(
true);
367 setTheme( bootstrapTheme );
368 useStyleSheet(
"resources/themes/bootstrap/3/bootstrap-theme.min.css" );
369 useStyleSheet(
"styles/calendar.css" );
370 messageResourceBundle().use(
"calendar" );
371 setTitle(
"Calendar" );
373 auto calendarWidget = root()-> addNew<CalendarWidget>();
375 COUT_( calendarWidget-> monthView()-> days().size() );
380 int main(
int argc,
char** argv)
384 Wt::WServer server( argc, argv );
388 Wt::EntryPointType::Application,
389 [](
const Wt::WEnvironment &env)
391 return std::make_unique<DevApp>(env);
398 catch( Wt::WServer::Exception & e )
400 std::cerr << e.what() << std::endl;
const std::vector< std::string > & daynames()
Long Day Names.