summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/args.c4
-rw-r--r--src/calcurse.c126
-rw-r--r--src/calcurse.h52
-rw-r--r--src/day.c106
-rw-r--r--src/ui-day.c234
-rw-r--r--src/wins.c28
6 files changed, 188 insertions, 362 deletions
diff --git a/src/args.c b/src/args.c
index 76bae34..13ab738 100644
--- a/src/args.c
+++ b/src/args.c
@@ -307,7 +307,9 @@ app_arg(int add_line, struct date *day, long date, const char *fmt_apt,
if (date == 0)
date = get_sec_date(*day);
- int n = day_store_items(date, NULL, NULL, regex);
+ day_store_items(date, regex);
+
+ int n = day_item_count();
if (n > 0) {
if (add_line)
diff --git a/src/calcurse.c b/src/calcurse.c
index 3bab0af..de0d5a5 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -40,44 +40,25 @@
#define HANDLE_KEY(key, fn) case key: fn(); break;
-struct day_items_nb inday;
int count, reg;
/*
* Store the events and appointments for the selected day and reset the
* appointment highlight pointer if a new day was selected.
*/
-static struct day_items_nb do_storage(int day_changed)
+static void do_storage(int day_changed)
{
- struct day_items_nb inday =
- day_process_storage(ui_calendar_get_slctd_day(),
- day_changed);
+ day_process_storage(ui_calendar_get_slctd_day(), day_changed);
+ ui_day_load_items();
- if (day_changed) {
- if ((inday.nb_events + inday.nb_apoints) > 0)
- ui_day_hilt_set(1);
- else
- ui_day_hilt_set(0);
- }
-
- return inday;
+ if (day_changed)
+ ui_day_sel_reset();
}
static inline void key_generic_change_view(void)
{
wins_reset_status_page();
wins_slctd_next();
-
- /* Select the event to highlight. */
- switch (wins_slctd()) {
- case APP:
- if ((ui_day_hilt() == 0)
- && ((inday.nb_events + inday.nb_apoints) > 0))
- ui_day_hilt_set(1);
- break;
- default:
- break;
- }
wins_update(FLAG_ALL);
}
@@ -92,7 +73,7 @@ static inline void key_generic_goto(void)
wins_erase_status_bar();
ui_calendar_set_current_date();
ui_calendar_change_day(conf.input_datefmt);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
@@ -101,14 +82,14 @@ static inline void key_generic_goto_today(void)
wins_erase_status_bar();
ui_calendar_set_current_date();
ui_calendar_goto_today();
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
static inline void key_view_item(void)
{
- if ((wins_slctd() == APP) && (ui_day_hilt() != 0))
- day_popup_item(day_get_item(ui_day_hilt()));
+ if (wins_slctd() == APP)
+ ui_day_popup_item();
else if (wins_slctd() == TOD)
ui_todo_popup_item();
wins_update(FLAG_ALL);
@@ -118,14 +99,14 @@ static inline void key_generic_config_menu(void)
{
wins_erase_status_bar();
custom_config_main();
- inday = do_storage(0);
+ do_storage(0);
wins_update(FLAG_ALL);
}
static inline void key_generic_add_appt(void)
{
ui_day_item_add();
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
@@ -140,7 +121,7 @@ static inline void key_add_item(void)
switch (wins_slctd()) {
case APP:
ui_day_item_add();
- inday = do_storage(0);
+ do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
break;
case TOD:
@@ -154,9 +135,9 @@ static inline void key_add_item(void)
static inline void key_edit_item(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0) {
+ if (wins_slctd() == APP) {
ui_day_item_edit();
- inday = do_storage(0);
+ do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
} else if (wins_slctd() == TOD) {
ui_todo_edit();
@@ -166,10 +147,9 @@ static inline void key_edit_item(void)
static inline void key_del_item(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0) {
- ui_day_item_delete(&inday.nb_events, &inday.nb_apoints,
- reg);
- inday = do_storage(0);
+ if (wins_slctd() == APP) {
+ ui_day_item_delete(reg);
+ do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
} else if (wins_slctd() == TOD) {
ui_todo_delete();
@@ -179,9 +159,9 @@ static inline void key_del_item(void)
static inline void key_generic_copy(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0) {
- ui_day_item_copy(&inday.nb_events, &inday.nb_apoints, reg);
- inday = do_storage(0);
+ if (wins_slctd() == APP) {
+ ui_day_item_copy(reg);
+ do_storage(0);
wins_update(FLAG_CAL | FLAG_APP);
}
}
@@ -189,26 +169,25 @@ static inline void key_generic_copy(void)
static inline void key_generic_paste(void)
{
if (wins_slctd() == APP) {
- ui_day_item_paste(&inday.nb_events, &inday.nb_apoints,
- reg);
- inday = do_storage(0);
+ ui_day_item_paste(reg);
+ do_storage(0);
wins_update(FLAG_CAL | FLAG_APP);
}
}
static inline void key_repeat_item(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0)
+ if (wins_slctd() == APP)
ui_day_item_repeat();
- inday = do_storage(0);
+ do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
static inline void key_flag_item(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0) {
- day_item_switch_notify(day_get_item(ui_day_hilt()));
- inday = do_storage(0);
+ if (wins_slctd() == APP) {
+ ui_day_flag();
+ do_storage(0);
wins_update(FLAG_APP);
} else if (wins_slctd() == TOD) {
ui_todo_flag();
@@ -218,7 +197,7 @@ static inline void key_flag_item(void)
static inline void key_pipe_item(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0)
+ if (wins_slctd() == APP)
ui_day_item_pipe();
else if (wins_slctd() == TOD)
ui_todo_pipe();
@@ -245,9 +224,9 @@ static inline void key_lower_priority(void)
static inline void key_edit_note(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0) {
- day_edit_note(day_get_item(ui_day_hilt()), conf.editor);
- inday = do_storage(0);
+ if (wins_slctd() == APP) {
+ ui_day_edit_note();
+ do_storage(0);
} else if (wins_slctd() == TOD) {
ui_todo_edit_note();
}
@@ -256,8 +235,8 @@ static inline void key_edit_note(void)
static inline void key_view_note(void)
{
- if (wins_slctd() == APP && ui_day_hilt() != 0)
- day_view_note(day_get_item(ui_day_hilt()), conf.pager);
+ if (wins_slctd() == APP)
+ ui_day_view_note();
else if (wins_slctd() == TOD)
ui_todo_view_note();
wins_update(FLAG_ALL);
@@ -280,7 +259,7 @@ static inline void key_generic_import(void)
wins_erase_status_bar();
io_import_data(IO_IMPORT_ICAL, NULL);
ui_calendar_monthly_view_cache_set_invalid();
- inday = do_storage(0);
+ do_storage(0);
wins_update(FLAG_ALL);
}
@@ -304,14 +283,14 @@ static inline void key_generic_export()
break;
}
- inday = do_storage(0);
+ do_storage(0);
wins_update(FLAG_ALL);
}
static inline void key_generic_prev_day(void)
{
ui_calendar_move(DAY_PREV, count);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
@@ -324,7 +303,7 @@ static inline void key_move_left(void)
static inline void key_generic_next_day(void)
{
ui_calendar_move(DAY_NEXT, count);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
@@ -337,7 +316,7 @@ static inline void key_move_right(void)
static inline void key_generic_prev_week(void)
{
ui_calendar_move(WEEK_PREV, count);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
@@ -346,10 +325,7 @@ static inline void key_move_up(void)
if (wins_slctd() == CAL) {
key_generic_prev_week();
} else if (wins_slctd() == APP) {
- if (count >= ui_day_hilt())
- count = ui_day_hilt() - 1;
- ui_day_hilt_decrease(count);
- ui_day_scroll_pad_up(inday.nb_events);
+ ui_day_sel_move(-1);
wins_update(FLAG_APP);
} else if (wins_slctd() == TOD) {
ui_todo_sel_move(-1);
@@ -360,7 +336,7 @@ static inline void key_move_up(void)
static inline void key_generic_next_week(void)
{
ui_calendar_move(WEEK_NEXT, count);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
@@ -369,13 +345,7 @@ static inline void key_move_down(void)
if (wins_slctd() == CAL) {
key_generic_next_week();
} else if (wins_slctd() == APP) {
- if (count >
- inday.nb_events + inday.nb_apoints - ui_day_hilt())
- count =
- inday.nb_events + inday.nb_apoints -
- ui_day_hilt();
- ui_day_hilt_increase(count);
- ui_day_scroll_pad_down(inday.nb_events, win[APP].h);
+ ui_day_sel_move(1);
wins_update(FLAG_APP);
} else if (wins_slctd() == TOD) {
ui_todo_sel_move(1);
@@ -386,28 +356,28 @@ static inline void key_move_down(void)
static inline void key_generic_prev_month(void)
{
ui_calendar_move(MONTH_PREV, count);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_generic_next_month(void)
{
ui_calendar_move(MONTH_NEXT, count);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_generic_prev_year(void)
{
ui_calendar_move(YEAR_PREV, count);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_generic_next_year(void)
{
ui_calendar_move(YEAR_NEXT, count);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
@@ -415,7 +385,7 @@ static inline void key_start_of_week(void)
{
if (wins_slctd() == CAL) {
ui_calendar_move(WEEK_START, count);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
}
@@ -424,7 +394,7 @@ static inline void key_end_of_week(void)
{
if (wins_slctd() == CAL) {
ui_calendar_move(WEEK_END, count);
- inday = do_storage(1);
+ do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
}
@@ -629,7 +599,7 @@ int main(int argc, char **argv)
wins_update(FLAG_ALL);
io_startup_screen(no_data_file);
}
- inday = day_process_storage(0, 0);
+ do_storage(1);
wins_slctd_set(conf.default_panel);
wins_update(FLAG_ALL);
diff --git a/src/calcurse.h b/src/calcurse.h
index 54344bb..07f6b78 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -323,12 +323,6 @@ struct todo {
char *note;
};
-/* Number of items in current day. */
-struct day_items_nb {
- unsigned nb_events;
- unsigned nb_apoints;
-};
-
struct excp {
long st; /* beggining of the considered day, in seconds */
};
@@ -632,21 +626,14 @@ struct apoint *apoint_dup(struct apoint *);
void apoint_free(struct apoint *);
void apoint_llist_init(void);
void apoint_llist_free(void);
-void ui_day_hilt_set(int);
-void ui_day_hilt_decrease(int);
-void ui_day_hilt_increase(int);
-int ui_day_hilt(void);
struct apoint *apoint_new(char *, char *, long, long, char);
unsigned apoint_inday(struct apoint *, long *);
void apoint_sec2str(struct apoint *, long, char *, char *);
void apoint_write(struct apoint *, FILE *);
struct apoint *apoint_scan(FILE *, struct tm, struct tm, char, char *);
void apoint_delete(struct apoint *);
-void ui_day_scroll_pad_down(int, int);
-void ui_day_scroll_pad_up(int);
struct notify_app *apoint_check_next(struct notify_app *, long);
void apoint_switch_notify(struct apoint *);
-void ui_day_update_panel(int, struct date);
void apoint_paste_item(struct apoint *, long);
/* args.c */
@@ -705,9 +692,10 @@ long day_item_get_duration(struct day_item *);
int day_item_get_state(struct day_item *);
void day_item_add_exc(struct day_item *, long);
void day_item_fork(struct day_item *, struct day_item *);
-int day_store_items(long, unsigned *, unsigned *, regex_t *);
-struct day_items_nb day_process_storage(struct date *, unsigned);
-void day_write_pad(long, int, int, int);
+void day_store_items(long, regex_t *);
+void day_process_storage(struct date *, unsigned);
+void day_display_item_date(struct day_item *, WINDOW *, int, long, int, int);
+void day_display_item(struct day_item *, WINDOW *, int, int, int, int);
void day_write_stdout(long, const char *, const char *, const char *,
const char *, int *);
void day_popup_item(struct day_item *);
@@ -716,6 +704,7 @@ unsigned day_chk_busy_slices(struct date, int, int *);
struct day_item *day_cut_item(long, int);
int day_paste_item(struct day_item *, long);
struct day_item *day_get_item(int);
+unsigned day_item_count(void);
void day_edit_note(struct day_item *, const char *);
void day_view_note(struct day_item *, const char *);
void day_item_switch_notify(struct day_item *);
@@ -750,16 +739,6 @@ void ical_import_data(FILE *, FILE *, unsigned *, unsigned *, unsigned *,
unsigned *, unsigned *);
void ical_export_data(FILE *);
-/* interaction.c */
-void ui_day_item_add(void);
-void ui_day_item_delete(unsigned *, unsigned *, unsigned);
-void ui_day_item_edit(void);
-void ui_day_item_pipe(void);
-void ui_day_item_repeat(void);
-void ui_day_item_cut_free(unsigned);
-void ui_day_item_copy(unsigned *, unsigned *, unsigned);
-void ui_day_item_paste(unsigned *, unsigned *, unsigned);
-
/* io.c */
unsigned io_fprintln(const char *, const char *, ...);
void io_init(const char *, const char *);
@@ -959,6 +938,26 @@ void todo_free(struct todo *);
void todo_init_list(void);
void todo_free_list(void);
+/* ui-day.c */
+void ui_day_item_add(void);
+void ui_day_item_delete(unsigned);
+void ui_day_item_edit(void);
+void ui_day_item_pipe(void);
+void ui_day_item_repeat(void);
+void ui_day_item_cut_free(unsigned);
+void ui_day_item_copy(unsigned);
+void ui_day_item_paste(unsigned);
+void ui_day_load_items(void);
+void ui_day_sel_reset(void);
+void ui_day_sel_move(int);
+void ui_day_draw(int, WINDOW *, int, int, void *);
+int ui_day_height(int, void *);
+void ui_day_update_panel(int);
+void ui_day_popup_item(void);
+void ui_day_flag(void);
+void ui_day_view_note(void);
+void ui_day_edit_note(void);
+
/* ui-todo.c */
void ui_todo_add(void);
void ui_todo_delete(void);
@@ -1058,6 +1057,7 @@ void vars_init(void);
/* wins.c */
extern struct window win[NBWINS];
extern struct scrollwin sw_cal;
+extern struct listbox lb_apt;
extern struct listbox lb_todo;
unsigned wins_nbar_lock(void);
void wins_nbar_unlock(void);
diff --git a/src/day.c b/src/day.c
index 20e2e71..25b898b 100644
--- a/src/day.c
+++ b/src/day.c
@@ -65,8 +65,11 @@ void day_free_vector(void)
VECTOR_FREE(&day_items);
}
-static int day_cmp_start(struct day_item *a, struct day_item *b)
+static int day_cmp_start(struct day_item **pa, struct day_item **pb)
{
+ struct day_item *a = *pa;
+ struct day_item *b = *pb;
+
if (a->type <= EVNT) {
if (b->type <= EVNT)
return 0;
@@ -334,29 +337,18 @@ static int day_store_recur_apoints(long date, regex_t * regex)
* and the length of the new pad to write is returned.
* The number of events and appointments in the current day are also updated.
*/
-int
-day_store_items(long date, unsigned *pnb_events, unsigned *pnb_apoints,
- regex_t * regex)
+void
+day_store_items(long date, regex_t * regex)
{
- int nb_events, nb_recur_events;
- int nb_apoints, nb_recur_apoints;
-
day_free_vector();
day_init_vector();
- nb_recur_events = day_store_recur_events(date, regex);
- nb_events = day_store_events(date, regex);
- nb_recur_apoints = day_store_recur_apoints(date, regex);
- nb_apoints = day_store_apoints(date, regex);
+ day_store_recur_events(date, regex);
+ day_store_events(date, regex);
+ day_store_recur_apoints(date, regex);
+ day_store_apoints(date, regex);
VECTOR_SORT(&day_items, day_cmp_start);
-
- if (pnb_apoints)
- *pnb_apoints = nb_apoints + nb_recur_apoints;
- if (pnb_events)
- *pnb_events = nb_events + nb_recur_events;
-
- return nb_events + nb_recur_events + nb_apoints + nb_recur_apoints;
}
/*
@@ -364,12 +356,10 @@ day_store_items(long date, unsigned *pnb_events, unsigned *pnb_apoints,
* those items in a pad. If selected day is null, then store items for current
* day. This is useful to speed up the appointment panel update.
*/
-struct day_items_nb day_process_storage(struct date *slctd_date,
- unsigned day_changed)
+void day_process_storage(struct date *slctd_date, unsigned day_changed)
{
long date;
struct date day;
- struct day_items_nb inday;
if (slctd_date)
day = *slctd_date;
@@ -383,25 +373,16 @@ struct day_items_nb day_process_storage(struct date *slctd_date,
delwin(apad.ptrwin);
/* Store the events and appointments (recursive and normal items). */
- day_store_items(date, &inday.nb_events, &inday.nb_apoints, NULL);
- apad.length = (inday.nb_events + 1 + 3 * inday.nb_apoints);
-
- /* Create the new pad with its new length. */
- if (day_changed)
- apad.first_onscreen = 0;
- apad.ptrwin = newpad(apad.length, apad.width);
-
- return inday;
+ day_store_items(date, NULL);
}
/*
* Print an item date in the appointment panel.
*/
-static void
-display_item_date(struct day_item *day, int incolor, long date, int y,
- int x)
+void
+day_display_item_date(struct day_item *day, WINDOW *win, int incolor,
+ long date, int y, int x)
{
- WINDOW *win;
char a_st[100], a_end[100];
char ch_recur, ch_notify;
@@ -411,7 +392,6 @@ display_item_date(struct day_item *day, int incolor, long date, int y,
apt_tmp.start = day->start;
apt_tmp.dur = day_item_get_duration(day);
- win = apad.ptrwin;
apoint_sec2str(&apt_tmp, date, a_st, a_end);
if (incolor == 0)
custom_apply_attr(win, ATTR_HIGHEST);
@@ -428,10 +408,10 @@ display_item_date(struct day_item *day, int incolor, long date, int y,
/*
* Print an item description in the corresponding panel window.
*/
-static void
-display_item(struct day_item *day, int incolor, int width, int y, int x)
+void
+day_display_item(struct day_item *day, WINDOW *win, int incolor, int width,
+ int y, int x)
{
- WINDOW *win;
int ch_recur, ch_note;
char buf[width * UTF8_MAXLEN];
int i;
@@ -441,7 +421,6 @@ display_item(struct day_item *day, int incolor, int width, int y, int x)
char *mesg = day_item_get_mesg(day);
- win = apad.ptrwin;
ch_recur = (day->type == RECUR_EVNT
|| day->type == RECUR_APPT) ? '*' : ' ';
ch_note = day_item_get_note(day) ? '>' : ' ';
@@ -465,48 +444,6 @@ display_item(struct day_item *day, int incolor, int width, int y, int x)
custom_remove_attr(win, ATTR_HIGHEST);
}
-/*
- * Write the appointments and events for the selected day in a pad.
- * An horizontal line is drawn between events and appointments, and the
- * item selected by user is highlighted.
- */
-void day_write_pad(long date, int width, int length, int incolor)
-{
- int i;
- int line, item_number;
- const int x_pos = 0;
- unsigned draw_line = 0;
-
- line = item_number = 0;
-
- VECTOR_FOREACH(&day_items, i) {
- struct day_item *day = VECTOR_NTH(&day_items, i);
-
- /* First print the events for current day. */
- if (day->type < RECUR_APPT) {
- item_number++;
- display_item(day, item_number - incolor, width - 7,
- line, x_pos);
- line++;
- draw_line = 1;
- } else {
- /* Draw a line between events and appointments. */
- if (line > 0 && draw_line) {
- wmove(apad.ptrwin, line, 0);
- whline(apad.ptrwin, 0, width);
- draw_line = 0;
- }
- /* Last print the appointments for current day. */
- item_number++;
- display_item_date(day, item_number - incolor, date,
- line + 1, x_pos);
- display_item(day, item_number - incolor, width - 7,
- line + 2, x_pos);
- line += 3;
- }
- }
-}
-
/* Write the appointments and events for the selected day to stdout. */
void day_write_stdout(long date, const char *fmt_apt, const char *fmt_rapt,
const char *fmt_ev, const char *fmt_rev, int *limit)
@@ -729,7 +666,12 @@ int day_paste_item(struct day_item *p, long date)
/* Returns a structure containing the selected item. */
struct day_item *day_get_item(int item_number)
{
- return VECTOR_NTH(&day_items, item_number - 1);
+ return VECTOR_NTH(&day_items, item_number);
+}
+
+unsigned day_item_count(void)
+{
+ return VECTOR_COUNT(&day_items);
}
/* Attach a note to an appointment or event. */
diff --git a/src/ui-day.c b/src/ui-day.c
index 3562637..d1e5843 100644
--- a/src/ui-day.c
+++ b/src/ui-day.c
@@ -36,7 +36,6 @@
#include "calcurse.h"
-static int hilt;
struct day_item day_cut[38] = { {0, 0, {NULL}} };
/* Request the user to enter a new time. */
@@ -293,14 +292,16 @@ static void update_rept(struct rpt **rpt, const long start)
/* Edit an already existing item. */
void ui_day_item_edit(void)
{
- struct day_item *p;
struct recur_event *re;
struct event *e;
struct recur_apoint *ra;
struct apoint *a;
int need_check_notify = 0;
- p = day_get_item(ui_day_hilt());
+ if (day_item_count() <= 0)
+ return;
+
+ struct day_item *p = day_get_item(listbox_get_sel(&lb_apt));
switch (p->type) {
case RECUR_EVNT:
@@ -408,7 +409,11 @@ void ui_day_item_pipe(void)
int pout;
int pid;
FILE *fpout;
- struct day_item *p;
+
+ if (day_item_count() <= 0)
+ return;
+
+ struct day_item *p = day_get_item(listbox_get_sel(&lb_apt));
status_mesg(_("Pipe item to external command:"), "");
if (getstring(win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID)
@@ -418,7 +423,6 @@ void ui_day_item_pipe(void)
if ((pid = shell_exec(NULL, &pout, *arg, arg))) {
fpout = fdopen(pout, "w");
- p = day_get_item(ui_day_hilt());
switch (p->type) {
case RECUR_EVNT:
recur_event_write(p->item.rev, fpout);
@@ -541,9 +545,6 @@ void ui_day_item_add(void)
date2sec(*ui_calendar_get_slctd_day(), 0,
0), 1);
}
-
- if (ui_day_hilt() == 0)
- ui_day_hilt_increase(1);
}
ui_calendar_monthly_view_cache_set_invalid();
@@ -552,8 +553,7 @@ void ui_day_item_add(void)
}
/* Delete an item from the appointment list. */
-void ui_day_item_delete(unsigned *nb_events, unsigned *nb_apoints,
- unsigned reg)
+void ui_day_item_delete(unsigned reg)
{
const char *del_app_str =
_("Do you really want to delete this item?");
@@ -569,15 +569,12 @@ void ui_day_item_delete(unsigned *nb_events, unsigned *nb_apoints,
"Delete (i)tem or just its (n)ote?");
const char *note_choices = _("[in]");
const int nb_note_choices = 2;
-
long date = ui_calendar_get_slctd_day_sec();
- int nb_items = *nb_apoints + *nb_events;
- int to_be_removed = 0;
- if (nb_items == 0)
+ if (day_item_count() <= 0)
return;
- struct day_item *p = day_get_item(ui_day_hilt());
+ struct day_item *p = day_get_item(listbox_get_sel(&lb_apt));
if (conf.confirm_delete) {
if (status_ask_bool(del_app_str) != 1) {
@@ -613,34 +610,11 @@ void ui_day_item_delete(unsigned *nb_events, unsigned *nb_apoints,
}
ui_day_item_cut_free(reg);
- p = day_cut_item(date, ui_day_hilt());
+ p = day_cut_item(date, listbox_get_sel(&lb_apt));
day_cut[reg].type = p->type;
day_cut[reg].item = p->item;
- switch (p->type) {
- case EVNT:
- case RECUR_EVNT:
- (*nb_events)--;
- to_be_removed = 1;
- break;
- case APPT:
- case RECUR_APPT:
- (*nb_apoints)--;
- to_be_removed = 3;
- break;
- default:
- EXIT(_("no such type"));
- /* NOTREACHED */
- }
-
ui_calendar_monthly_view_cache_set_invalid();
-
- 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)
- ui_day_hilt_set(0);
}
/*
@@ -690,7 +664,10 @@ void ui_day_item_repeat(void)
struct recur_apoint *ra;
long until, date;
- item_nb = ui_day_hilt();
+ if (day_item_count() <= 0)
+ return;
+
+ item_nb = listbox_get_sel(&lb_apt);
p = day_get_item(item_nb);
if (p->type != APPT && p->type != EVNT) {
status_mesg(wrong_type_1, wrong_type_2);
@@ -810,165 +787,110 @@ void ui_day_item_cut_free(unsigned reg)
}
/* Copy an item, so that it can be pasted somewhere else later. */
-void ui_day_item_copy(unsigned *nb_events, unsigned *nb_apoints,
- unsigned reg)
+void ui_day_item_copy(unsigned reg)
{
- const int NBITEMS = *nb_apoints + *nb_events;
-
- if (NBITEMS == 0 || reg == REG_BLACK_HOLE)
+ if (day_item_count() <= 0 || reg == REG_BLACK_HOLE)
return;
+ struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
ui_day_item_cut_free(reg);
- day_item_fork(day_get_item(ui_day_hilt()), &day_cut[reg]);
+ day_item_fork(item, &day_cut[reg]);
}
/* Paste a previously cut item. */
-void ui_day_item_paste(unsigned *nb_events, unsigned *nb_apoints,
- unsigned reg)
+void ui_day_item_paste(unsigned reg)
{
- int item_type;
struct day_item day;
if (reg == REG_BLACK_HOLE || !day_cut[reg].type)
return;
day_item_fork(&day_cut[reg], &day);
- item_type = day_paste_item(&day, ui_calendar_get_slctd_day_sec());
+ day_paste_item(&day, ui_calendar_get_slctd_day_sec());
ui_calendar_monthly_view_cache_set_invalid();
+}
- if (item_type == EVNT || item_type == RECUR_EVNT)
- (*nb_events)++;
- else if (item_type == APPT || item_type == RECUR_APPT)
- (*nb_apoints)++;
- else
- return;
+void ui_day_load_items(void)
+{
+ listbox_load_items(&lb_apt, day_item_count());
+}
- if (ui_day_hilt() == 0)
- ui_day_hilt_increase(1);
+void ui_day_sel_reset(void)
+{
+ listbox_set_sel(&lb_apt, 0);
}
-/* Sets which appointment is highlighted. */
-void ui_day_hilt_set(int highlighted)
+void ui_day_sel_move(int delta)
{
- hilt = highlighted;
+ listbox_sel_move(&lb_apt, delta);
}
-void ui_day_hilt_decrease(int n)
+/* Display appointments in the corresponding panel. */
+void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data)
{
- hilt -= n;
+ struct date slctd_date = *ui_calendar_get_slctd_day();
+ long date = date2sec(slctd_date, 0, 0);
+ struct day_item *item = day_get_item(n);
+ int width = lb_apt.sw.w;
+
+ if (item->type < RECUR_APPT) {
+ day_display_item(item, win, !hilt, width, y, 1);
+ } else {
+ day_display_item_date(item, win, !hilt, date, y + 1, 1);
+ day_display_item(item, win, !hilt, width, y + 2, 1);
+ }
+
}
-void ui_day_hilt_increase(int n)
+int ui_day_height(int n, void *cb_data)
{
- hilt += n;
+ struct day_item *item = day_get_item(n);
+
+ if (item->type < RECUR_APPT)
+ return 1;
+ else
+ return 3;
}
-/* Return which appointment is highlighted. */
-int ui_day_hilt(void)
+/* Updates the Appointment panel */
+void ui_day_update_panel(int which_pan)
{
- return hilt;
+ listbox_display(&lb_apt);
}
-/*
- * 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)
+void ui_day_popup_item(void)
{
- int separator = 2;
- int line = 0;
+ if (day_item_count() <= 0)
+ return;
- 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;
+ struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
+ day_popup_item(item);
}
-/*
- * 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)
+void ui_day_flag(void)
{
- 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;
+ if (day_item_count() <= 0)
+ return;
+
+ struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
+ day_item_switch_notify(item);
}
-/*
- * 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)
+void ui_day_view_note(void)
{
- int item_first_line = 0;
+ if (day_item_count() <= 0)
+ return;
- item_first_line = get_item_line(hilt, nb_events_inday);
- if (item_first_line < apad.first_onscreen)
- apad.first_onscreen = item_first_line;
+ struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
+ day_view_note(item, conf.pager);
}
-/* Updates the Appointment panel */
-void ui_day_update_panel(int which_pan, struct date slctd_date)
+void ui_day_edit_note(void)
{
- 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;
-
- /* variable inits */
- 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",
- ui_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);
- }
+ if (day_item_count() <= 0)
+ return;
- 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);
+ struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
+ day_edit_note(item, conf.editor);
}
diff --git a/src/wins.c b/src/wins.c
index a690fe2..e84bc08 100644
--- a/src/wins.c
+++ b/src/wins.c
@@ -51,6 +51,7 @@
/* Variables to handle calcurse windows. */
struct window win[NBWINS];
struct scrollwin sw_cal;
+struct listbox lb_apt;
struct listbox lb_todo;
/* User-configurable side bar width. */
@@ -248,18 +249,13 @@ static void wins_init_panels(void)
CALHEIGHT + (conf.compact_panels ? 2 : 4),
wins_sbar_width(), _("Calendar"));
- win[APP].p =
- newwin(win[APP].h, win[APP].w, win[APP].y, win[APP].x);
- wins_show(win[APP].p, _("Appointments"));
- apad.width = win[APP].w - 3;
- apad.ptrwin = newpad(apad.length, apad.width);
+ listbox_init(&lb_apt, win[APP].y, win[APP].x, win[APP].h, win[APP].w,
+ _("Appointments"), ui_day_height, ui_day_draw);
+ ui_day_load_items();
listbox_init(&lb_todo, win[TOD].y, win[TOD].x, win[TOD].h, win[TOD].w,
_("TODO"), ui_todo_height, ui_todo_draw);
ui_todo_load_items();
-
- /* Enable function keys (i.e. arrow keys) in those windows */
- keypad(win[APP].p, TRUE);
}
/* Create all the windows. */
@@ -401,8 +397,7 @@ void wins_scrollwin_ensure_visible(struct scrollwin *sw, unsigned line)
void wins_reinit_panels(void)
{
wins_scrollwin_delete(&sw_cal);
- delwin(win[APP].p);
- delwin(apad.ptrwin);
+ listbox_delete(&lb_apt);
listbox_delete(&lb_todo);
wins_get_config();
wins_init_panels();
@@ -415,8 +410,7 @@ void wins_reinit_panels(void)
void wins_reinit(void)
{
wins_scrollwin_delete(&sw_cal);
- delwin(win[APP].p);
- delwin(apad.ptrwin);
+ listbox_delete(&lb_apt);
listbox_delete(&lb_todo);
delwin(win[STA].p);
delwin(win[KEY].p);
@@ -547,12 +541,8 @@ void wins_update_border(int flags)
wins_scrollwin_draw_deco(&sw_cal, (slctd_win == CAL));
WINS_CALENDAR_UNLOCK;
}
- if (flags & FLAG_APP) {
- if (slctd_win == APP)
- border_color(win[APP].p);
- else
- border_nocolor(win[APP].p);
- }
+ if (flags & FLAG_APP)
+ listbox_draw_deco(&lb_apt, (slctd_win == APP));
if (flags & FLAG_TOD)
listbox_draw_deco(&lb_todo, (slctd_win == TOD));
}
@@ -560,7 +550,7 @@ void wins_update_border(int flags)
void wins_update_panels(int flags)
{
if (flags & FLAG_APP)
- ui_day_update_panel(slctd_win, *ui_calendar_get_slctd_day());
+ ui_day_update_panel(slctd_win);
if (flags & FLAG_TOD)
ui_todo_update_panel(slctd_win);
if (flags & FLAG_CAL)