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_(""); 29 :
public Wt::WContainerWidget
55 const Wt::WDate & date()
const;
57 Wt::WTemplate * templt();
60 Wt::WContainerWidget * body();
68 Wt::WTemplate * m_templt =
nullptr;
69 Wt::WText * m_day =
nullptr;
70 Wt::WText * m_header =
nullptr;
71 Wt::WContainerWidget * m_body =
nullptr;
72 Wt::WText * m_footer =
nullptr;
76 CalendarDay::CalendarDay(
const Wt::WDate & d )
79 addStyleClass(
"divTableCell" );
81 m_templt = addNew<Wt::WTemplate>( Wt::WString::tr(
"Calendar.day.cell" ) );
83 m_day = m_templt-> bindNew<Wt::WText>(
"day", Wt::WString(
"{1}").arg( date().day() ) );
84 m_day-> addStyleClass(
"divDay" );
86 m_header = m_templt-> bindNew<Wt::WText>(
"header" );
87 m_header-> addStyleClass(
"divHeader" );
89 m_body = m_templt-> bindNew<Wt::WContainerWidget>(
"body" );
90 m_body-> addStyleClass(
"divBody" );
92 m_footer = m_templt-> bindNew<Wt::WText>(
"footer" );
93 m_footer-> addStyleClass(
"divFooter" );
97 const Wt::WDate & CalendarDay::date()
const 102 Wt::WTemplate * CalendarDay::templt()
107 Wt::WText * CalendarDay::day()
112 Wt::WText * CalendarDay::header()
117 Wt::WContainerWidget * CalendarDay::body()
122 Wt::WText * CalendarDay::footer()
142 CalendarWeek::CalendarWeek(
const Wt::WDate & date )
144 addStyleClass(
"divTableRow" );
154 const std::vector< CalendarDay * > & days()
const;
160 std::vector< CalendarDay * > m_days;
163 CalendarMonth::CalendarMonth(
const Wt::WDate & selectedDate )
165 addStyleClass(
"divTable" );
166 addStyleClass(
"blueTable" );
168 Wt::WDate first( selectedDate.year(), selectedDate.month(), 1 );
169 Wt::WDate start = first.addDays( first.dayOfWeek() * -1 );
172 auto cwHeader = addNew<Wt::WContainerWidget>();
173 cwHeader-> addStyleClass(
"divTableHeading" );
175 auto cwRow = cwHeader-> addNew<Wt::WContainerWidget>();
176 cwRow-> addStyleClass(
"divTableRow" );
178 static const std::vector<std::string> daynames =
188 for(
int weekday = 0; weekday < 7; weekday++ )
190 auto cwDay = cwRow-> addNew<Wt::WContainerWidget>();
191 cwDay-> addStyleClass(
"divTableHead" );
193 cwDay-> addNew<Wt::WText>( daynames.at(weekday) );
197 int cellDate = first.dayOfWeek() * -1;
203 for(
int week = 0; week < 5; week++ )
205 auto currentWeek = start.addDays( week*7 );
207 auto cwWeek = addNew<CalendarWeek>( currentWeek );
213 for(
int day = 0; day < 7; day++ )
219 auto currentDay = start.addDays( (week*7)+day );
225 auto cwDay = cwWeek-> addNew<CalendarDay>( currentDay );
233 if( currentDay.month() != selectedDate.month() )
235 cwDay-> day()-> setText
237 Wt::WString(
"{1} {2}")
238 .arg( Wt::WDate::shortMonthName( currentDay.month() ) )
239 .arg( currentDay.day() )
248 if( currentDay.month() < selectedDate.month() )
250 cwDay-> addStyleClass(
"divPreviousMonth" );
258 if( currentDay.month() > selectedDate.month() )
260 cwDay-> addStyleClass(
"divNextMonth" );
268 if( currentDay == selectedDate )
270 cwDay-> addStyleClass(
"divCurrentDay" );
277 m_days.push_back( cwDay );
287 const std::vector< CalendarDay * > & CalendarMonth::days()
const 293 :
public Wt::WContainerWidget
303 Wt::WTemplate * m_templt =
nullptr;
305 Wt::WContainerWidget * m_dayPicker =
nullptr;
308 CalendarWidget::CalendarWidget()
310 m_templt = addNew<Wt::WTemplate>( Wt::WString::tr(
"Calendar.widget" ) );
312 m_dayPicker = m_templt-> bindNew<Wt::WContainerWidget>(
"dayPicker" );
313 m_monthView = m_templt-> bindNew<CalendarMonth>(
"monthView", Wt::WDate::currentDate() );
315 std::map< Wt::WDate, std::string > holidays =
317 { Wt::WDate( 2018, 5, 5 ),
"Cinco de Mayo" },
318 { Wt::WDate( 2018, 5, 10 ),
"Ascension Day" },
319 { Wt::WDate( 2018, 5, 13 ),
"Mother's Day" },
320 { Wt::WDate( 2018, 5, 21 ),
"Victoria Day (Canada)" },
321 { Wt::WDate( 2018, 5, 28 ),
"Memorial Day (USA)" }
324 for(
auto calendarDay : m_monthView-> days() )
326 auto holidayItem = holidays.find( calendarDay-> date() );
327 if( holidayItem != holidays.end() )
329 calendarDay-> header()-> setText( holidayItem-> second );
333 std::map< Wt::WDate, std::string > moon =
335 { Wt::WDate( 2018, 5, 7 ),
"Last Quarter Moon" },
336 { Wt::WDate( 2018, 5, 15 ),
"New Moon" },
337 { Wt::WDate( 2018, 5, 21 ),
"New Quarter Moon" },
338 { Wt::WDate( 2018, 5, 29 ),
"Full Moon" }
341 for(
auto calendarDay : m_monthView-> days() )
343 auto moonItem = moon.find( calendarDay-> date() );
344 if( moonItem != moon.end() )
346 calendarDay-> footer()-> setText( moonItem-> second );
357 :
public Wt::WApplication
360 DevApp(
const Wt::WEnvironment &env)
361 : Wt::WApplication( env )
363 auto bootstrapTheme = std::make_shared<Wt::WBootstrapTheme>();
364 bootstrapTheme-> setVersion( Wt::BootstrapVersion::v3 );
365 bootstrapTheme-> setResponsive(
true);
366 setTheme( bootstrapTheme );
367 useStyleSheet(
"resources/themes/bootstrap/3/bootstrap-theme.min.css" );
368 useStyleSheet(
"styles/calendar.css" );
369 messageResourceBundle().use(
"calendar" );
370 setTitle(
"Calendar" );
372 auto calendarWidget = root()-> addNew<CalendarWidget>();
374 COUT_( calendarWidget-> monthView()-> days().size() );
379 int main(
int argc,
char** argv)
383 Wt::WServer server( argc, argv );
387 Wt::EntryPointType::Application,
388 [](
const Wt::WEnvironment &env)
390 return std::make_unique<DevApp>(env);
397 catch( Wt::WServer::Exception & e )
399 std::cerr << e.what() << std::endl;