📄 fl_calendar.cxx
字号:
nxt_year->labelsize(10); nxt_year->down_box(FL_THIN_DOWN_BOX);#else nxt_year->label_size(10);#endif nxt_year->callback((Fl_Callback *) & fl_calendar_nxt_year_cb, (void *) this); caption = new Fl_Box(x, y, (w / 7) * 3 + oi, (h / 8)); caption->box(FL_THIN_UP_BOX);#if FL_MAJOR_VERSION == 1 caption->labelfont(FL_HELVETICA_BOLD); caption->labelsize(10);#else caption->label_size(10);#endif#endif /* PIXIL */#ifdef PIXIL if (m_bCaption) Fl_Calendar_Base::csize(x, y + (2 * h / m_nRows), w, (6 * h / m_nRows)); else Fl_Calendar_Base::csize(x, y + (h / m_nRows), w, (6 * h / m_nRows));#else Fl_Calendar_Base::csize(x, y + title_height + (h - title_height) / 7, w, h - title_height - (h - title_height) / 7);#endif update();}voidFl_Calendar::csize(int cx, int cy, int cw, int ch){ int i;#ifdef PIXIL for (i = 0; i < 7; i++) { weekdays[i] = new Fl_Box((cw / 7) * (i % 7) + cx, (ch / m_nRows) * ((i / 7) + 1) + cy, (cw / 7), (ch / m_nRows)); NxApp::DefaultFont((Fl_Widget *) weekdays[i]); } if (m_bCaption) { prv_month->resize(cx + (cw / 10), cy, (cw / 10), (ch / 8)); nxt_month->resize(cx + (cw / 10) * 8, cy, (cw / 10), (ch / 8)); prv_year->resize(cx, cy, (cw / 10), (ch / 8)); nxt_year->resize(cx + (cw / 10) * 9, cy, (cw / 10), (ch / 8)); caption->resize(cx + (cw / 10) * 2, cy, (cw / 10) * 6, (ch / 8)); } Fl_Calendar_Base::csize(cx, cy + (2 * ch / m_nRows), cw, (6 * ch / m_nRows));#else int oi = (cw - (7 * (int) (cw / 7))) / 2; int of = (cw - (7 * (int) (cw / 7))) - oi; int xi, wxi; for (i = 0; i < 7; i++) { if (i == 0) xi = 0; else xi = oi; if (i == 0) wxi = oi; else if (i == 6) wxi = of; else wxi = 0; weekdays[i] = new Fl_Box((cw / 7) * (i % 7) + cx + xi, (ch / 8) * ((i / 7) + 1) + cy, (cw / 7) + wxi, (ch / 8)); } prv_month->resize(cx + (cw / 10), cy, (cw / 10), (ch / 8)); nxt_month->resize(cx + (cw / 10) * 8, cy, (cw / 10), (ch / 8)); prv_year->resize(cx, cy, (cw / 10), (ch / 8)); nxt_year->resize(cx + (cw / 10) * 9, cy, (cw / 10), (ch / 8)); caption->resize(cx + (cw / 10) * 2, cy, (cw / 10) * 6, (ch / 8)); Fl_Calendar_Base::csize(cx, cy + (2 * ch / 8), cw, (6 * ch / 8));#endif}voidFl_Calendar::update(){#ifdef PIXIL int dow = date.day_of_week(date.year(), date.month(), 1); int dim = date.days_in_month(date.month(), date.leap_year(date.year()));#else int dow = day_of_week(year(), month(), 1); int dim = days_in_month(month(), leap_year(year()));#endif int i; for (i = dow; i < (dim + dow); i++) { char t[8]; sprintf(t, "%d", (i - dow + 1)); days[i]->label(strdup(t)); } char tmp[32]; sprintf(tmp, "%.3s %d", month_name[month() - 1], year()); //sprintf (tmp, "%s %d", month_name[month ()-1], year ());#ifdef PIXIL update_buttons();#else Fl_Calendar_Base::update();#endif#ifdef PIXIL if (m_bCaption) { if (caption->label()) free((void *) caption->label()); caption->label(strdup(tmp)); }#else if (caption->label()) free((void *) caption->label()); caption->label(strdup(tmp));#endif redraw();}#ifdef PIXILvoidFl_Calendar::update_buttons(){#ifdef PIXIL int dow = date.day_of_week(date.year(), date.month(), 1); int dim = date.days_in_month(date.month(), date.leap_year(date.year()));#else int dow = day_of_week(year(), month(), 1); int dim = days_in_month(month(), leap_year(year()));#endif int i; int val = 0; for (i = 0; i < dow; i++) { days[i]->hide(); } for (i = (dim + dow); i < (6 * 7); i++) { days[i]->hide(); } for (i = dow; i < (dim + dow); i++) { char t[8]; sprintf(t, "%d", (i - dow + 1)); days[i]->label(strdup(t)); days[i]->color(NxApp::GlobalColor(APP_BG)); days[i]->labelcolor(NxApp::GlobalColor(APP_FG)); if ((i - dow + 1) == day()) { days[i]->color(NxApp::GlobalColor(HILIGHT)); days[i]->labelcolor(NxApp::GlobalColor(APP_BG)); days[i]->selection_color(NxApp::GlobalColor(APP_BG)); val = (i - dow + 1); } days[i]->redraw(); days[i]->show(); } if (WEEK == _type) { set_week_buttons(this, val); } redraw();}#endifvoidFl_Calendar::previous_month(){#ifdef PIXIL date.previous_month();#else previous_month();#endif update();}voidFl_Calendar::next_month(){#ifdef PIXIL date.next_month();#else next_month();#endif update();}voidFl_Calendar::previous_year(){#ifdef PIXIL date.previous_year();#else previous_year();#endif update();}voidFl_Calendar::next_year(){#ifdef PIXIL date.next_year();#else next_year();#endif update();}intFl_Calendar::handle(int event){ int m, d, y, o = 0, md; switch (event) { case FL_FOCUS: case FL_UNFOCUS: return 1; case FL_KEYBOARD: m = month(); d = day(); y = year(); switch (Fl::event_key()) { case FL_Enter: selected_day_ = d; do_callback(this, d); break; case FL_Up: o = -7; break; case FL_Down: o = 7; break; case FL_Right: o = 1; break; case FL_Left: o = -1; break; case FL_Page_Up: previous_month(); return 1; case FL_Page_Down: next_month(); return 1; default: return Fl_Group::handle(event); }#ifdef PIXIL if (date.valid(y, m, d + o)) date.set_date(y, m, d + o); else { if (o < 0) { previous_month(); m = date.month(); y = date.year(); md = date.days_in_month(m, date.leap_year(y)); d = d + o + md; date.set_date(y, m, d); } else { md = date.days_in_month(m, date.leap_year(y)); next_month(); m = date.month(); y = date.year(); d = d + o - md; date.set_date(y, m, d); } }#else if (valid(y, m, d + o)) set_date(y, m, d + o); else { if (o < 0) { previous_month(); m = month(); y = year(); md = days_in_month(m, leap_year(y)); d = d + o + md; set_date(y, m, d); } else { md = days_in_month(m, leap_year(y)); next_month(); m = month(); y = year(); d = d + o - md; set_date(y, m, d); } }#endif update(); return 1; } return Fl_Group::handle(event);}// The following can be static since the popup calendar behaves// as a modal dialogstruct datestruct{ int flag; int m; int d; int y; char szDte[20];};static datestruct seldate;static Fl_Window *popcal_form;static Fl_Calendar *popcal;static voidpopcal_cb(Fl_Calendar * c, long d){ if (d) { seldate.flag = 1; seldate.m = c->month(); seldate.d = c->day(); seldate.y = c->year(); }}static voidmakepopcal(){ if (popcal_form) return; Fl_Window *w = popcal_form = new Fl_Window(7 * 20 + 4, 8 * 20 + 4); w->clear_border(); w->box(FL_UP_BOX); (popcal = new Fl_Calendar(2, 2)); popcal->callback((Fl_Callback *) popcal_cb); w->end(); w->set_modal(); return;}static datestruct *fl_popcal(int popcalfmt){ makepopcal(); seldate.flag = -1; popcal_form->show(); for (;;) { Fl::wait(); if (seldate.flag > -1) break; } popcal_form->hide(); if (seldate.flag == 1) strcpy(seldate.szDte, popcal->to_string(popcalfmt)); else seldate.szDte[0] = 0; return &seldate;}#include "pixmaps/calendar.xpm"voidFl_Date_Input::btnDate_Input_cb_i(){ datestruct *retdate = fl_popcal(popcalfmt); if (retdate->flag == 1) Input.value(retdate->szDte); return;}// button callback has to execute the real callback contained in// the parent Group widgetvoidbtnDate_Input_cb(Fl_Widget * v, void *d){ ((Fl_Date_Input *) (v->parent()))->btnDate_Input_cb_i(); return;}Fl_Date_Input::Fl_Date_Input(int X, int Y, int W, int H, char *L): Fl_Group(X, Y, W, H, L),Input(X, Y, W - H, H), Btn(X + W - H + 1, Y + 1, H - 2, H - 2){ xpos = X; ypos = Y; width = W; height = H; (new Fl_Pixmap(calendar_xpm))->label(&Btn); Btn.callback((Fl_Callback *) btnDate_Input_cb, 0); popcalfmt = 0; end();}// Date_Input value is contained in the Input widgetvoidFl_Date_Input::value(const char *s){ Input.value(s);}const char *Fl_Date_Input::value(){ return (Input.value());}#if FL_MAJOR_VERSION == 1voidFl_Date_Input::text_font(int tf){ Input.textfont(tf);}#elsevoidFl_Date_Input::text_font(Fl_Font tf){ Input.text_font(tf);}#endif#if FL_MAJOR_VERSION == 1voidFl_Date_Input::text_size(int sz){ Input.textsize(sz);}#elsevoidFl_Date_Input::text_size(int sz){ Input.text_size(sz);}#endifvoidFl_Date_Input::format(int fmt){ switch (fmt) { case 0: case 1: case 2: case 3: case 4: popcalfmt = fmt; break; default: popcalfmt = 0; }}Fl_Agenda_Calendar::Fl_Agenda_Calendar(int x, int y, int w, int h, const char *l, int title_height):Fl_Calendar(x, y, w, h, l){ if (title_height < 0) { title_height = h / 8; } int i; for (i = 0; i < 7; i++) { weekdays[i]->size(weekdays[i]->w(), (h - title_height) / 7); } prv_year->size(prv_year->w(), title_height); prv_year->label("Y-"); prv_month->size(prv_month->w(), title_height); prv_month->label("M-"); nxt_month->size(nxt_month->w(), title_height); nxt_month->label("M+"); nxt_year->size(nxt_year->w(), title_height); nxt_year->label("Y+"); caption->size(caption->w(), title_height); Fl_Calendar_Base::csize(x, y + title_height + (h - title_height) / 7, w, h - title_height - (h - title_height) / 7); update();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -