From d54dd2ee73de03bddadaeb345c0e2d5c87bae06a Mon Sep 17 00:00:00 2001 From: Frederic Culot Date: Sat, 20 Dec 2008 19:27:31 +0000 Subject: new layout configuration menu --- ChangeLog | 7 +++ TODO | 3 +- src/calcurse.c | 4 +- src/custom.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++++-------- src/custom.h | 4 +- src/help.c | 4 +- src/help.h | 3 +- src/utils.c | 6 +- 8 files changed, 180 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee98800..2194d47 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-12-20 Frederic Culot + + * TODO: update for 2.4 + + * src/custom.c (custom_layout_config, display_layout_config) + (layout_selection_bar): new functions + 2008-12-18 Frederic Culot * src/notify.c (notify_check_next_app): create thread detached to diff --git a/TODO b/TODO index 6bdd2e3..2439ba7 100755 --- a/TODO +++ b/TODO @@ -11,8 +11,8 @@ this list. High ---- - o Add a week view in the calendar panel o Add support for UTF-8 + o Allow events and appointments to be moved from one date to another Average @@ -23,6 +23,7 @@ Average o Add an auto-save function o Add support for CalDAV protocol (rfc4791) o Implement categories to classify appointments and tasks + o Add a week view in the calendar panel Low diff --git a/src/calcurse.c b/src/calcurse.c index 2257d3c..451d616 100755 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -1,4 +1,4 @@ -/* $calcurse: calcurse.c,v 1.72 2008/12/07 09:20:38 culot Exp $ */ +/* $calcurse: calcurse.c,v 1.73 2008/12/20 19:27:31 culot Exp $ */ /* * Calcurse - text-based organizer @@ -262,7 +262,7 @@ main (int argc, char **argv) break; case 'L': case 'l': - layout_config (); + custom_layout_config (); break; case 'G': case 'g': diff --git a/src/custom.c b/src/custom.c index 5a7477c..a7b4eae 100755 --- a/src/custom.c +++ b/src/custom.c @@ -1,4 +1,4 @@ -/* $calcurse: custom.c,v 1.30 2008/12/14 15:54:51 culot Exp $ */ +/* $calcurse: custom.c,v 1.31 2008/12/20 19:27:31 culot Exp $ */ /* * Calcurse - text-based organizer @@ -34,6 +34,7 @@ #include "utils.h" #include "keys.h" #include "apoint.h" +#include "help.h" static struct attribute_s attr; @@ -365,35 +366,171 @@ custom_config_bar (void) doupdate (); } -/* Choose the layout */ -void -layout_config (void) +static void +layout_selection_bar (void) { - int ch; - char *layout_mesg = - _("Pick the desired layout on next screen [press ENTER]"); - char *choice_mesg = - _("('A'= Appointment panel, 'C'= calendar panel, 'T'= todo panel)"); - char *layout_up_mesg = - _(" AC AT CA TA TC TA CT AT"); - char *layout_down_mesg = - _(" [1]AT [2]AC [3]TA [4]CA [5]TA [6]TC [7]AT [8]CT"); - - status_mesg (layout_mesg, choice_mesg); - (void)wgetch (win[STA].p); - status_mesg (layout_up_mesg, layout_down_mesg); + binding_t quit = {_("Exit"), KEY_GENERIC_QUIT}; + binding_t select = {_("Select"), KEY_GENERIC_SELECT}; + binding_t up = {_("Up"), KEY_MOVE_UP}; + binding_t down = {_("Down"), KEY_MOVE_DOWN}; + binding_t left = {_("Left"), KEY_MOVE_LEFT}; + binding_t right = {_("Right"), KEY_MOVE_RIGHT}; + binding_t help = {_("Help"), KEY_GENERIC_HELP}; + + binding_t *binding[] = {&quit, &select, &up, &down, &left, &right, &help}; + int binding_size = sizeof (binding) / sizeof (binding[0]); + + keys_display_bindings_bar (win[STA].p, binding, 0, binding_size); +} + +#define NBLAYOUTS 8 +#define LAYOUTSPERCOL 2 + +/* Used to display available layouts in layout configuration menu. */ +static void +display_layout_config (window_t *lwin, int mark, int cursor, int need_reset) +{ +#define CURSOR (32 | A_REVERSE) +#define MARK 88 +#define LAYOUTH 5 +#define LAYOUTW 9 + char *box = "[ ]"; + const int BOXSIZ = strlen (box); + const int NBCOLS = NBLAYOUTS / LAYOUTSPERCOL; + const int COLSIZ = LAYOUTW + BOXSIZ + 1; + const int XSPC = (col - NBCOLS * COLSIZ) / (NBCOLS + 1); + const int XOFST = (col - NBCOLS * (XSPC + COLSIZ)) / 2; + const int YSPC = (row - 8 - LAYOUTSPERCOL * LAYOUTH) / (LAYOUTSPERCOL + 1); + const int YOFST = (row - LAYOUTSPERCOL * (YSPC + LAYOUTH)) / 2; + enum {YPOS, XPOS, NBPOS}; + int pos[NBLAYOUTS][NBPOS]; + char *layouts[LAYOUTH][NBLAYOUTS] = { + {"+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+"}, + {"| | c |", "| | t |", "| c | |", "| t | |", "| | c |", "| | a |", "| c | |", "| a | |"}, + {"| a +---+", "| a +---+", "+---+ a |", "|---+ a |", "| t +---+", "| t +---+", "+---+ t |", "+---+ t |"}, + {"| | t |", "| | c |", "| t | |", "| c | |", "| | a |", "| | c |", "| a | |", "| c | |"}, + {"+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+", "+---+---+"} + }; + int i; + + for (i = 0; i < NBLAYOUTS; i++) + { + pos[i][YPOS] = YOFST + (i % LAYOUTSPERCOL) * (YSPC + LAYOUTH); + pos[i][XPOS] = XOFST + (i / LAYOUTSPERCOL) * (XSPC + COLSIZ); + } + + if (need_reset) + { + char label[BUFSIZ]; + + if (lwin->p != NULL) + delwin (lwin->p); + snprintf (label, BUFSIZ, _("CalCurse %s | layout configuration"), + VERSION); + custom_confwin_init (lwin, label); + } + + for (i = 0; i < NBLAYOUTS; i++) + { + int j; + + mvwprintw (lwin->p, pos[i][YPOS] + 2, pos[i][XPOS], box); + if (i == mark) + custom_apply_attr (lwin->p, ATTR_HIGHEST); + for (j = 0; j < LAYOUTH; j++) + { + mvwprintw (lwin->p, pos[i][YPOS] + j, pos[i][XPOS] + BOXSIZ + 1, + layouts[j][i]); + } + if (i == mark) + custom_remove_attr (lwin->p, ATTR_HIGHEST); + } + mvwaddch (lwin->p, pos[mark][YPOS] + 2, pos[mark][XPOS] + 1, MARK); + mvwaddch (lwin->p, pos[cursor][YPOS] + 2, pos[cursor][XPOS] + 1, CURSOR); + + layout_selection_bar (); wnoutrefresh (win[STA].p); + wnoutrefresh (lwin->p); doupdate (); - while ((ch = wgetch (win[STA].p)) != 'q') + if (notify_bar ()) + notify_update_bar (); +} + +/* Choose the layout */ +void +custom_layout_config (void) +{ + scrollwin_t hwin; + window_t conf_win; + int ch, mark, cursor, need_reset; + char *help_text = + _("With this configuration menu, one can choose where panels will be\n" + "displayed inside calcurse screen. \n" + "It is possible to choose between eight different configurations.\n" + "\nIn the configuration representations, letters correspond to:\n\n" + " 'c' -> calendar panel\n\n" + " 'a' -> appointment panel\n\n" + " 't' -> todo panel\n\n"); + + need_reset = 1; + conf_win.p = (WINDOW *)0; + cursor = mark = wins_layout () - 1; + clear (); + display_layout_config (&conf_win, mark, cursor, need_reset); + + while ((ch = keys_getch (win[STA].p)) != KEY_GENERIC_QUIT) { - if (ch <= '8' && ch >= '1') + need_reset = 0; + switch (ch) { - wins_set_layout (ch - '0'); - return; + case KEY_RESIZE: + endwin (); + refresh (); + curs_set (0); + need_reset = 1; + break; + case KEY_GENERIC_HELP: + help_wins_init (&hwin, 0, 0, + (notify_bar ()) ? row - 3 : row - 2, col); + mvwprintw (hwin.pad.p, 1, 0, "%s", help_text); + hwin.total_lines = 7; + wins_scrollwin_display (&hwin); + wgetch (hwin.win.p); + wins_scrollwin_delete (&hwin); + need_reset = 1; + break; + case KEY_GENERIC_SELECT: + mark = cursor; + break; + case KEY_MOVE_DOWN: + if (cursor % LAYOUTSPERCOL < LAYOUTSPERCOL - 1) + cursor++; + break; + case KEY_MOVE_UP: + if (cursor % LAYOUTSPERCOL > 0) + cursor--; + break; + case KEY_MOVE_LEFT: + if (cursor >= LAYOUTSPERCOL) + cursor -= LAYOUTSPERCOL; + break; + case KEY_MOVE_RIGHT: + if (cursor < NBLAYOUTS - LAYOUTSPERCOL) + cursor += LAYOUTSPERCOL; + break; + case KEY_GENERIC_CANCEL: + need_reset = 1; + break; } + display_layout_config (&conf_win, mark, cursor, need_reset); } + wins_set_layout (mark + 1); + delwin (conf_win.p); } +#undef NBLAYOUTS +#undef LAYOUTSPERCOL + /* * Create a configuration window and initialize status and notification bar * (useful in case of window resize). @@ -417,7 +554,7 @@ custom_confwin_init (window_t *confwin, char *label) } static void -custom_color_config_bar (void) +color_selection_bar (void) { binding_t quit = {_("Exit"), KEY_GENERIC_QUIT}; binding_t select = {_("Select"), KEY_GENERIC_SELECT}; @@ -559,7 +696,7 @@ display_color_config (window_t *cwin, int *mark_fore, int *mark_back, } mvwaddch (cwin->p, pos[cursor][YPOS], pos[cursor][XPOS] + 1, CURSOR); - custom_color_config_bar (); + color_selection_bar (); wnoutrefresh (win[STA].p); wnoutrefresh (cwin->p); doupdate (); diff --git a/src/custom.h b/src/custom.h index 470eadf..89ca4fc 100755 --- a/src/custom.h +++ b/src/custom.h @@ -1,4 +1,4 @@ -/* $calcurse: custom.h,v 1.13 2008/11/23 20:38:56 culot Exp $ */ +/* $calcurse: custom.h,v 1.14 2008/12/20 19:27:31 culot Exp $ */ /* * Calcurse - text-based organizer @@ -77,7 +77,7 @@ void custom_apply_attr (WINDOW *, int); void custom_remove_attr (WINDOW *, int); void custom_load_conf (conf_t *, int); void custom_config_bar (void); -void layout_config (void); +void custom_layout_config (void); void custom_color_config (void); void custom_color_theme_name (char *); void custom_confwin_init (window_t *, char *); diff --git a/src/help.c b/src/help.c index 4679b68..a8fa336 100755 --- a/src/help.c +++ b/src/help.c @@ -1,4 +1,4 @@ -/* $calcurse: help.c,v 1.34 2008/12/03 19:31:03 culot Exp $ */ +/* $calcurse: help.c,v 1.35 2008/12/20 19:27:31 culot Exp $ */ /* * Calcurse - text-based organizer @@ -130,7 +130,7 @@ help_write_pad (window_t *win, char *title, char *text, keys_e action) * Create and init help screen and its pad, which is used to make the scrolling * faster. */ -static void +void help_wins_init (scrollwin_t *hwin, int x, int y, int h, int w) { const int PADOFFSET = 4; diff --git a/src/help.h b/src/help.h index 99710cd..ae7e98e 100755 --- a/src/help.h +++ b/src/help.h @@ -1,4 +1,4 @@ -/* $calcurse: help.h,v 1.8 2008/12/03 19:31:03 culot Exp $ */ +/* $calcurse: help.h,v 1.9 2008/12/20 19:27:31 culot Exp $ */ /* * Calcurse - text-based organizer @@ -36,6 +36,7 @@ typedef struct { char text[HELPTEXTSIZ]; } help_page_t; +void help_wins_init (scrollwin_t *, int, int, int, int); void help_screen (void); #endif /* CALCURSE_HELP_H */ diff --git a/src/utils.c b/src/utils.c index f4d82fe..4779a4f 100755 --- a/src/utils.c +++ b/src/utils.c @@ -1,4 +1,4 @@ -/* $calcurse: utils.c,v 1.60 2008/12/15 20:02:00 culot Exp $ */ +/* $calcurse: utils.c,v 1.61 2008/12/20 19:27:31 culot Exp $ */ /* * Calcurse - text-based organizer @@ -136,12 +136,12 @@ popup (int pop_row, int pop_col, int pop_y, int pop_x, char *title, char *msg, popup_win = newwin (pop_row, pop_col, pop_y, pop_x); keypad (popup_win, TRUE); + if (msg) + mvwprintw (popup_win, MSGXPOS, (pop_col - strlen (msg)) / 2, "%s", msg); custom_apply_attr (popup_win, ATTR_HIGHEST); box (popup_win, 0, 0); snprintf (label, BUFSIZ, "%s", title); wins_show (popup_win, label); - if (msg) - mvwprintw (popup_win, MSGXPOS, (pop_col - strlen (msg)) / 2, "%s", msg); if (hint) mvwprintw (popup_win, pop_row - 2, pop_col - (strlen (any_key) + 1), "%s", any_key); -- cgit v1.2.3