From 601709b173d45394ded5027712959efce2fe862b Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 14 Feb 2013 10:38:28 +0100 Subject: apoint.c: Split out UI-related functions * Move UI-related functions to "ui-day.c". * Rename UI-related functions to ui_day_*(). Signed-off-by: Lukas Fleischer --- src/ui-day.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 135 insertions(+), 13 deletions(-) (limited to 'src/ui-day.c') diff --git a/src/ui-day.c b/src/ui-day.c index caf272b..c300699 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -36,6 +36,7 @@ #include "calcurse.h" +static int hilt; struct day_item day_cut[38] = { { 0, 0, { NULL } } }; /* Request the user to enter a new time. */ @@ -280,7 +281,7 @@ void ui_day_item_edit(void) struct apoint *a; int need_check_notify = 0; - p = day_get_item(apoint_hilt()); + p = day_get_item(ui_day_hilt()); switch (p->type) { case RECUR_EVNT: @@ -383,7 +384,7 @@ void ui_day_item_pipe(void) if ((pid = shell_exec(NULL, &pout, *arg, arg))) { fpout = fdopen(pout, "w"); - p = day_get_item(apoint_hilt()); + p = day_get_item(ui_day_hilt()); switch (p->type) { case RECUR_EVNT: recur_event_write(p->item.rev, fpout); @@ -496,8 +497,8 @@ void ui_day_item_add(void) } else event_new(item_mesg, 0L, date2sec(*calendar_get_slctd_day(), 0, 0), Id); - if (apoint_hilt() == 0) - apoint_hilt_increase(1); + if (ui_day_hilt() == 0) + ui_day_hilt_increase(1); } calendar_monthly_view_cache_set_invalid(); @@ -530,7 +531,7 @@ void ui_day_item_delete(unsigned *nb_events, unsigned *nb_apoints, if (nb_items == 0) return; - struct day_item *p = day_get_item(apoint_hilt()); + struct day_item *p = day_get_item(ui_day_hilt()); if (conf.confirm_delete) { if (status_ask_bool(del_app_str) != 1) { @@ -564,7 +565,7 @@ void ui_day_item_delete(unsigned *nb_events, unsigned *nb_apoints, } ui_day_item_cut_free(reg); - p = day_cut_item(date, apoint_hilt()); + p = day_cut_item(date, ui_day_hilt()); day_cut[reg].type = p->type; day_cut[reg].item = p->item; @@ -586,12 +587,12 @@ void ui_day_item_delete(unsigned *nb_events, unsigned *nb_apoints, calendar_monthly_view_cache_set_invalid(); - if (apoint_hilt() > 1) - apoint_hilt_decrease(1); + if (ui_day_hilt() > 1) + ui_day_hilt_decrease(1); if (apad.first_onscreen >= to_be_removed) apad.first_onscreen = apad.first_onscreen - to_be_removed; if (nb_items == 1) - apoint_hilt_set(0); + ui_day_hilt_set(0); } /* @@ -639,7 +640,7 @@ void ui_day_item_repeat(void) struct recur_apoint *ra; long until, date; - item_nb = apoint_hilt(); + item_nb = ui_day_hilt(); p = day_get_item(item_nb); if (p->type != APPT && p->type != EVNT) { status_mesg(wrong_type_1, wrong_type_2); @@ -768,7 +769,7 @@ void ui_day_item_copy(unsigned *nb_events, unsigned *nb_apoints, return; ui_day_item_cut_free(reg); - day_item_fork(day_get_item(apoint_hilt()), &day_cut[reg]); + day_item_fork(day_get_item(ui_day_hilt()), &day_cut[reg]); } /* Paste a previously cut item. */ @@ -793,6 +794,127 @@ void ui_day_item_paste(unsigned *nb_events, unsigned *nb_apoints, else return; - if (apoint_hilt() == 0) - apoint_hilt_increase(1); + if (ui_day_hilt() == 0) + ui_day_hilt_increase(1); +} + +/* Sets which appointment is highlighted. */ +void ui_day_hilt_set(int highlighted) +{ + hilt = highlighted; +} + +void ui_day_hilt_decrease(int n) +{ + hilt -= n; +} + +void ui_day_hilt_increase(int n) +{ + hilt += n; +} + +/* Return which appointment is highlighted. */ +int ui_day_hilt(void) +{ + return hilt; +} + +/* + * Return the line number of an item (either an appointment or an event) in + * the appointment panel. This is to help the appointment scroll function + * to place beggining of the pad correctly. + */ +static int get_item_line(int item_nb, int nb_events_inday) +{ + int separator = 2; + int line = 0; + + if (item_nb <= nb_events_inday) + line = item_nb - 1; + else + line = nb_events_inday + separator + + (item_nb - (nb_events_inday + 1)) * 3 - 1; + return line; +} + +/* + * Update (if necessary) the first displayed pad line to make the + * appointment panel scroll down next time pnoutrefresh is called. + */ +void ui_day_scroll_pad_down(int nb_events_inday, int win_length) +{ + int pad_last_line = 0; + int item_first_line = 0, item_last_line = 0; + int borders = 6; + int awin_length = win_length - borders; + + item_first_line = get_item_line(hilt, nb_events_inday); + if (hilt < nb_events_inday) + item_last_line = item_first_line; + else + item_last_line = item_first_line + 1; + pad_last_line = apad.first_onscreen + awin_length; + if (item_last_line >= pad_last_line) + apad.first_onscreen = item_last_line - awin_length; +} + +/* + * Update (if necessary) the first displayed pad line to make the + * appointment panel scroll up next time pnoutrefresh is called. + */ +void ui_day_scroll_pad_up(int nb_events_inday) +{ + int item_first_line = 0; + + item_first_line = get_item_line(hilt, nb_events_inday); + if (item_first_line < apad.first_onscreen) + apad.first_onscreen = item_first_line; +} + +/* Updates the Appointment panel */ +void ui_day_update_panel(int which_pan) +{ + int title_xpos; + int bordr = 1; + int title_lines = conf.compact_panels ? 1 : 3; + int app_width = win[APP].w - bordr; + int app_length = win[APP].h - bordr - title_lines; + long date; + struct date slctd_date; + + /* variable inits */ + slctd_date = *calendar_get_slctd_day(); + title_xpos = win[APP].w - (strlen(_(monthnames[slctd_date.mm - 1])) + 16); + if (slctd_date.dd < 10) + title_xpos++; + date = date2sec(slctd_date, 0, 0); + day_write_pad(date, app_width, app_length, (which_pan == APP) ? hilt : 0); + + /* Print current date in the top right window corner. */ + erase_window_part(win[APP].p, 1, title_lines, win[APP].w - 2, win[APP].h - 2); + custom_apply_attr(win[APP].p, ATTR_HIGHEST); + mvwprintw(win[APP].p, title_lines, title_xpos, "%s %s %d, %d", + calendar_get_pom(date), _(monthnames[slctd_date.mm - 1]), + slctd_date.dd, slctd_date.yyyy); + custom_remove_attr(win[APP].p, ATTR_HIGHEST); + + /* Draw the scrollbar if necessary. */ + if ((apad.length >= app_length) || (apad.first_onscreen > 0)) { + int sbar_length = app_length * app_length / apad.length; + int highend = app_length * apad.first_onscreen / apad.length; + unsigned hilt_bar = (which_pan == APP) ? 1 : 0; + int sbar_top = highend + title_lines + 1; + + if ((sbar_top + sbar_length) > win[APP].h - 1) + sbar_length = win[APP].h - 1 - sbar_top; + draw_scrollbar(win[APP].p, sbar_top, win[APP].w - 2, sbar_length, + title_lines + 1, win[APP].h - 1, hilt_bar); + } + + wnoutrefresh(win[APP].p); + pnoutrefresh(apad.ptrwin, apad.first_onscreen, 0, + win[APP].y + title_lines + 1, win[APP].x + bordr, + win[APP].y + win[APP].h - 2 * bordr, + win[APP].x + win[APP].w - 3 * bordr); } -- cgit v1.2.3