2 #include <Wt/WPushButton.h> 5 #include <Wt/WCalendar.h> 10 #include "MiniMonth.h" 12 Wtx::Web::Calendar::MiniMonth::MiniMonth(
int fdow,
const Wt::WDate & date )
13 :
Wt::WContainerWidget()
15 m_firstDayOfWeek = fdow;
23 m_date = Wt::WDate(date.year(),date.month(),1);
26 addNew< Wt::WTemplate >
41 m_prev = templt()-> bindNew< Wt::WText >(
"prev",
"" );
42 m_next = templt()-> bindNew< Wt::WText >(
"next",
"" );
43 m_month = templt()-> bindNew< Wt::WText >(
"month", Wt::WDate::longMonthName( date.month() ) );
44 m_year = templt()-> bindNew< Wt::WText >(
"year",
Wtx::itos( date.year() ) );
46 m_prev-> clicked().connect( [=](){ m_prevClicked.emit(); } );
47 m_next-> clicked().connect( [=](){ m_nextClicked.emit(); } );
54 m_table = templt()-> bindNew<Wt::WTable>(
"table" );
55 table()-> addStyleClass(
"Wtx_MiniMonth" );
62 void Wtx::Web::Calendar::MiniMonth::updateView()
76 auto firstDayOfWeek = m_firstDayOfWeek % 7;
87 for(
int weekday = 0; weekday < 7; weekday++ )
89 auto w = std::make_unique< Wt::WText >(
daynames().at((weekday+firstDayOfWeek)%7).substr(0,3) );
91 w-> addStyleClass(
"Wtx_MiniMonth_dayname" );
93 table()-> elementAt( 0, weekday )-> addWidget( std::move(w) );
99 auto dow = (m_date.dayOfWeek()-firstDayOfWeek)%7;
102 std::cout << __FILE__ <<
":" << __LINE__
103 <<
" dat:" << m_date.toString()
104 <<
" dow:" << m_date.dayOfWeek()
106 <<
" fdw:" << firstDayOfWeek
116 for(
int week = 0; week < 6; week++ )
123 for(
int day = 0; day < 7; day++ )
125 auto d = m_date.addDays( (dow*-1) + ((week*7)+day) );
126 auto w = std::make_unique< DayWidget >( d );
127 m_dayWidgets.push_back( w.get() );
129 table()-> elementAt( week*7, day )-> addWidget( std::move(w) );
136 void Wtx::Web::Calendar::MiniMonth::setSelectedDate(
const Wt::WDate & date )
138 for(
auto dayWidget : m_dayWidgets )
140 if( dayWidget-> date() == date )
142 dayWidget-> setSelected(
true );
146 dayWidget-> setSelected(
false );
153 void Wtx::Web::Calendar::MiniMonth::allowPrev(
bool value )
156 m_prev-> setText(
"<<" );
158 m_prev-> setText(
"" );
161 void Wtx::Web::Calendar::MiniMonth::allowNext(
bool value )
164 m_next-> setText(
">>" );
166 m_next-> setText(
"" );
169 void Wtx::Web::Calendar::MiniMonth::allowPrevNext(
bool value )
177 Wtx::Web::Calendar::MiniMonth::DayWidget::DayWidget(
const Wt::WDate & date )
178 :
Wt::WText(
Wt::WString(
"{1}").arg( date.day() ) ),
181 addStyleClass(
"Wtx_MiniMonth_day" );
183 if( date == Wt::WDate::currentDate() )
185 addStyleClass(
"Wtx_MiniMonth_today" );
190 const Wt::WDate & Wtx::Web::Calendar::MiniMonth::DayWidget::date()
const 195 void Wtx::Web::Calendar::MiniMonth::DayWidget::setSelected(
bool value )
199 addStyleClass(
"Wtx_MiniMonth_selected" );
203 removeStyleClass(
"Wtx_MiniMonth_selected" );
207 void Wtx::Web::Calendar::MiniMonth::browseTo(
const Wt::WDate & date )
const std::vector< std::string > & daynames()
Long Day Names.
std::string itos(int value)
Convert an Integer to a String.