29 TString monthNames[12] = {
"January",
"February",
"March",
"April",
30 "May",
"June",
"July",
"August",
"September",
31 "October",
"November",
"December"};
44 HtmlDayName(
const char *day);
45 virtual ~HtmlDayName() {}
47 TString Html()
const {
return fHtml; }
53 HtmlDayName::HtmlDayName(
const char *day) : fDay(day), fAlign(
"middle"),
54 fBgColor(
"#000000"), fFontSize(
"4"), fFontColor(
"#FFFFFF")
58 fHtml +=
"<TH width=14%";
59 fHtml +=
" align=" + fAlign;
60 fHtml +=
" bgcolor=" + fBgColor +
">";
61 fHtml +=
"<font size=" + fFontSize;
62 fHtml +=
" color=" + fFontColor +
">";
64 fHtml +=
"</font></TH>\n";
69 class HtmlMonthTable {
90 virtual ~HtmlMonthTable() {}
93 TString Html()
const {
return fHtml; }
99 HtmlMonthTable::HtmlMonthTable(
Int_t year,
Int_t month) : fYear(year),
100 fMonth(month), fBorder(
"2"), fBgColor(
"#aaaaaa"), fCellpadding(
"5"),
101 fCellFontSize(
"3"), fCellBgcolor(
"#eeeeee"), fTodayColor(
"#ffff00")
109 void HtmlMonthTable::SetDate(
Int_t year,
Int_t month)
119 void HtmlMonthTable::Build()
123 fHtml =
"<TABLE width=100%";
124 fHtml +=
" border=" + fBorder;
125 fHtml +=
" bgcolor=" + fBgColor;
126 fHtml +=
" cellpadding=" + fCellpadding;
132 fHtml +=
"</TBODY></TABLE>\n";
136 void HtmlMonthTable::BuildDayNames()
141 fHtml += HtmlDayName(
"Sunday").Html();
142 fHtml += HtmlDayName(
"Monday").Html();
143 fHtml += HtmlDayName(
"Tuesday").Html();
144 fHtml += HtmlDayName(
"Wednesday").Html();
145 fHtml += HtmlDayName(
"Thursday").Html();
146 fHtml += HtmlDayName(
"Friday").Html();
147 fHtml += HtmlDayName(
"Saturday").Html();
152 void HtmlMonthTable::BuildDays()
156 static Int_t maxdays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
158 Int_t maxday = maxdays[fMonth-1];
164 for (
int week = 0; week < 6; week++) {
167 for (
int weekday = 0; weekday < 7; weekday++) {
168 Int_t day = week*7 + weekday - first + 1;
170 if ((day > maxday) && !weekday)
break;
172 fHtml +=
"<TD align=left width=14% ";
175 if ((fToday.GetYear() == fYear) &&
176 (fToday.GetMonth() == fMonth) &&
177 (fToday.GetDay() == day)) {
178 fHtml +=
" bgcolor=" + fTodayColor;
180 fHtml +=
" bgcolor=" + fCellBgcolor;
185 if ((day <= 0) || (day > maxday)) {
186 fHtml +=
" </TD>";
190 fHtml +=
"<font size=" + fCellFontSize +
">";
191 fHtml +=
Form(
"%d", day);
192 fHtml +=
"</font></TD>\n";
204 HtmlMonthTable fMonthTable;
215 virtual ~HtmlCalendar() {}
218 TString Html()
const {
return fHtml; }
224 HtmlCalendar::HtmlCalendar(
Int_t year,
Int_t month) : fMonthTable(year, month)
235 fHtml += fMonthTable.Html();
240 void HtmlCalendar::SetDate(
Int_t year,
Int_t month)
247 fMonthTable.SetDate(year, month);
251 fHtml += fMonthTable.Html();
256 void HtmlCalendar::MakeHeader()
260 fTitle = monthNames[fMonth-1] +
Form(
" %d", fYear);
261 fHeader =
"<html><head><title>";
263 fHeader +=
"</title></head><body>\n";
264 fHeader +=
"<center><H2>" + fTitle +
"</H2></center>";
268 void HtmlCalendar::MakeFooter()
272 fFooter =
"<br><p><br><center><strong><font size=2 color=#2222ee>";
273 fFooter +=
"Example of using Html widget to display tabular data.";
274 fFooter +=
"</font></strong></center></body></html>";
281 class CalendarWindow {
284 HtmlCalendar *fHtmlText;
294 virtual ~CalendarWindow();
303 CalendarWindow::~CalendarWindow()
312 CalendarWindow::CalendarWindow()
328 fHtml =
new TGHtml(fMain, 1, 1);
333 fHtml->ParseText((
char*)fHtmlText->Html().Data());
341 for (
int i = 0; i < 12; i++) {
342 fMonthBox->AddEntry(monthNames[i].
Data(), i+1);
344 fMonthBox->Select(today.
GetMonth());
353 fMonthBox->Resize(100, fYearEntry->GetHeight());
359 Int_t fontsize = atoi(fHtmlText->fMonthTable.fCellFontSize.Data());
362 TGNumberFormat::kNEAPositive,
372 gClient->GetColorByName(fHtmlText->fMonthTable.fBgColor.Data(), color);
381 gClient->GetColorByName(fHtmlText->fMonthTable.fCellBgcolor.Data(), color);
387 fMonthBox->Connect(
"Selected(Int_t)",
"CalendarWindow",
this,
389 fYearEntry->GetNumberEntry()->Connect(
"TextChanged(char*)",
"CalendarWindow",
390 this,
"UpdateHTML()");
391 fFontEntry->GetNumberEntry()->Connect(
"TextChanged(char*)",
"CalendarWindow",
392 this,
"UpdateHTML()");
393 fTableColor->Connect(
"ColorSelected(Pixel_t)",
"CalendarWindow",
this,
395 fCellColor->Connect(
"ColorSelected(Pixel_t)",
"CalendarWindow",
this,
399 fMain->Connect(
"CloseWindow()",
"TApplication",
gApplication,
"Terminate()");
400 fMain->DontCallClose();
402 fMain->MapSubwindows();
403 fMain->Resize(600, 333);
406 fMain->SetWMSizeHints(controls->
GetDefaultWidth(), fMain->GetDefaultHeight(),
409 TString title =
"Calendar for ";
410 title += fHtmlText->fTitle;
411 fMain->SetWindowName(title.
Data());
416 void CalendarWindow::UpdateHTML()
420 Int_t month = fMonthBox->GetSelected();
421 Int_t year = atoi(fYearEntry->GetNumberEntry()->GetText());
422 fHtmlText->fMonthTable.fCellFontSize = fFontEntry->GetNumberEntry()->GetText();
432 fHtmlText->fMonthTable.fBgColor = color->
AsHexString();
436 pixel = fCellColor->GetColor();
440 fHtmlText->fMonthTable.fCellBgcolor = color->
AsHexString();
444 fHtmlText->SetDate(year, month);
448 fHtml->ParseText((
char*)fHtmlText->Html().Data());
452 TString title =
"Calendar for ";
453 title += fHtmlText->fTitle;
454 fMain->SetWindowName(title.
Data());
462 new CalendarWindow();
Bool_t IsLeapYear(Bool_t inUTC=kTRUE, Int_t secOffset=0) const
Is the year a leap year.
R__EXTERN TApplication * gApplication
Int_t GetDayOfWeek(Bool_t inUTC=kTRUE, Int_t secOffset=0) const
Method is using Zeller's formula for calculating the day number.
#define ClassDef(name, id)
std::vector< std::vector< double > > Data
virtual UInt_t GetDefaultWidth() const
char * Form(const char *fmt,...)
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb"...
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
The color creation and management class.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
const char * AsHexString() const
Return color as hexadecimal string.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
const char * Data() const