aboutsummaryrefslogtreecommitdiffstats
path: root/src/wins.c
blob: 2f04605a1971ae4088b7a41add95fa683e7f3c71 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
/*
 * Calcurse - text-based organizer
 *
 * Copyright (c) 2004-2012 calcurse Development Team <misc@calcurse.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the
 *        following disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the
 *        following disclaimer in the documentation and/or other
 *        materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Send your feedback or comments to : misc@calcurse.org
 * Calcurse home page : http://calcurse.org
 *
 */

#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "calcurse.h"

/* Variables to handle calcurse windows. */
struct window win[NBWINS];

/* User-configurable side bar width. */
static unsigned sbarwidth_perc;

static enum win slctd_win;
static int layout;

/*
 * The screen_mutex mutex and wins_refresh(), wins_wrefresh(), wins_doupdate()
 * functions are used to prevent concurrent updates of the screen.
 * It was observed that the display could get screwed up when mulitple threads
 * tried to refresh the screen at the same time.
 *
 * Note (2010-03-21):
 * Since recent versions of ncurses (5.7), rudimentary support for threads are
 * available (use_screen(), use_window() for instance - see curs_threads(3)),
 * but to remain compatible with earlier versions, it was chosen to rely on a
 * screen-level mutex instead.
 */
static pthread_mutex_t screen_mutex = PTHREAD_MUTEX_INITIALIZER;

static unsigned screen_acquire(void)
{
  if (pthread_mutex_lock(&screen_mutex) != 0)
    return 0;
  else
    return 1;
}

static void screen_release(void)
{
  pthread_mutex_unlock(&screen_mutex);
}

int wins_refresh(void)
{
  int rc;

  if (!screen_acquire())
    return ERR;
  rc = refresh();
  screen_release();

  return rc;
}

int wins_wrefresh(WINDOW * win)
{
  int rc;

  if (!win || !screen_acquire())
    return ERR;
  rc = wrefresh(win);
  screen_release();

  return rc;
}

int wins_doupdate(void)
{
  int rc;

  if (!screen_acquire())
    return ERR;
  rc = doupdate();
  screen_release();

  return rc;
}

/* Get the current layout. */
int wins_layout(void)
{
  return layout;
}

/* Set the current layout. */
void wins_set_layout(int nb)
{
  layout = nb;
}

/* Get the current side bar width. */
unsigned wins_sbar_width(void)
{
  if (sbarwidth_perc > SBARMAXWIDTHPERC)
    return col * SBARMAXWIDTHPERC / 100;
  else {
    unsigned sbarwidth = (unsigned)(col * sbarwidth_perc / 100);
    return (sbarwidth < SBARMINWIDTH) ? SBARMINWIDTH : sbarwidth;
  }
}

/*
 * Return the side bar width in percentage of the total number of columns
 * available in calcurse's screen.
 */
unsigned wins_sbar_wperc(void)
{
  return sbarwidth_perc > SBARMAXWIDTHPERC ? SBARMAXWIDTHPERC : sbarwidth_perc;
}

/*
 * Set side bar width (unit: number of characters) given a width in percentage
 * of calcurse's screen total width.
 * The side bar could not have a width representing more than 50% of the screen,
 * and could not be less than SBARMINWIDTH characters.
 */
void wins_set_sbar_width(unsigned perc)
{
  sbarwidth_perc = perc;
}

/* Change the width of the side bar within acceptable boundaries. */
void wins_sbar_winc(void)
{
  if (sbarwidth_perc < SBARMAXWIDTHPERC)
    sbarwidth_perc++;
}

void wins_sbar_wdec(void)
{
  if (sbarwidth_perc > 0)
    sbarwidth_perc--;
}

/* Initialize the selected window in calcurse's interface. */
void wins_slctd_init(void)
{
  wins_slctd_set(CAL);
}

/* Returns an enum which corresponds to the window which is selected. */
enum win wins_slctd(void)
{
  return slctd_win;
}

/* Sets the selected window. */
void wins_slctd_set(enum win window)
{
  slctd_win = window;
}

/* TAB key was hit in the interface, need to select next window. */
void wins_slctd_next(void)
{
  if (slctd_win == TOD)
    slctd_win = CAL;
  else
    slctd_win++;
}

static void wins_init_panels(void)
{
  win[CAL].p = newwin(CALHEIGHT, wins_sbar_width(), win[CAL].y, win[CAL].x);
  wins_show(win[CAL].p, _("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);

  win[TOD].p = newwin(win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x);
  wins_show(win[TOD].p, _("ToDo"));

  /* Enable function keys (i.e. arrow keys) in those windows */
  keypad(win[CAL].p, TRUE);
  keypad(win[APP].p, TRUE);
  keypad(win[TOD].p, TRUE);
}

/* Create all the windows. */
void wins_init(void)
{
  wins_init_panels();
  win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);

  keypad(win[STA].p, TRUE);

  /* Notify that the curses mode is now launched. */
  ui_mode = UI_CURSES;
}

/*
 * Create a new window and its associated pad, which is used to make the
 * scrolling faster.
 */
void wins_scrollwin_init(struct scrollwin *sw)
{
  EXIT_IF(sw == NULL, "null pointer");
  sw->win.p = newwin(sw->win.h, sw->win.w, sw->win.y, sw->win.x);
  sw->pad.p = newpad(sw->pad.h, sw->pad.w);
  sw->first_visible_line = 0;
  sw->total_lines = 0;
}

/* Free an already created scrollwin. */
void wins_scrollwin_delete(struct scrollwin *sw)
{
  EXIT_IF(sw == NULL, "null pointer");
  delwin(sw->win.p);
  delwin(sw->pad.p);
}

/* Display a scrolling window. */
void wins_scrollwin_display(struct scrollwin *sw)
{
  const int visible_lines = sw->win.h - sw->pad.y - 1;

  if (sw->total_lines > visible_lines) {
    float ratio = ((float)visible_lines) / ((float)sw->total_lines);
    int sbar_length = (int)(ratio * visible_lines);
    int highend = (int)(ratio * sw->first_visible_line);
    int sbar_top = highend + sw->pad.y + 1;

    if ((sbar_top + sbar_length) > sw->win.h - 1)
      sbar_length = sw->win.h - sbar_top;
    draw_scrollbar(sw->win.p, sbar_top, sw->win.w + sw->win.x - 2,
                   sbar_length, sw->pad.y + 1, sw->win.h - 1, 1);
  }
  wmove(win[STA].p, 0, 0);
  wnoutrefresh(sw->win.p);
  pnoutrefresh(sw->pad.p, sw->first_visible_line, 0, sw->pad.y, sw->pad.x,
               sw->win.h - sw->pad.y + 1, sw->win.w - sw->win.x);
  wins_doupdate();
}

void wins_scrollwin_up(struct scrollwin *sw, int amount)
{
  if (sw->first_visible_line > 0)
    sw->first_visible_line -= amount;
}

void wins_scrollwin_down(struct scrollwin *sw, int amount)
{
  if (sw->total_lines > (sw->first_visible_line + sw->win.h - sw->pad.y - 1))
    sw->first_visible_line += amount;
}

void wins_reinit_panels(void)
{
  delwin(win[CAL].p);
  delwin(win[APP].p);
  delwin(apad.ptrwin);
  delwin(win[TOD].p);
  wins_get_config();
  wins_init_panels();
}

/*
 * Delete the existing windows and recreate them with their new
 * size and placement.
 */
void wins_reinit(void)
{
  delwin(win[CAL].p);
  delwin(win[APP].p);
  delwin(apad.ptrwin);
  delwin(win[TOD].p);
  delwin(win[STA].p);
  wins_get_config();
  wins_init();
  if (notify_bar())
    notify_reinit_bar();
}

/* Show the window with a border and a label. */
void wins_show(WINDOW * win, const char *label)
{
  int width = getmaxx(win);

  box(win, 0, 0);
  mvwaddch(win, 2, 0, ACS_LTEE);
  mvwhline(win, 2, 1, ACS_HLINE, width - 2);
  mvwaddch(win, 2, width - 1, ACS_RTEE);

  print_in_middle(win, 1, 0, width, label);
}

/*
 * Get the screen size and recalculate the windows configurations.
 */
void wins_get_config(void)
{
  /* Get the screen configuration */
  getmaxyx(stdscr, row, col);

  /* fixed values for status, notification bars and calendar */
  win[STA].h = STATUSHEIGHT;
  win[STA].w = col;
  win[STA].y = row - win[STA].h;
  win[STA].x = 0;

  if (notify_bar()) {
    win[NOT].h = 1;
    win[NOT].w = col;
    win[NOT].y = win[STA].y - 1;
    win[NOT].x = 0;
  } else {
    win[NOT].h = 0;
    win[NOT].w = 0;
    win[NOT].y = 0;
    win[NOT].x = 0;
  }

  win[CAL].w = wins_sbar_width();
  win[CAL].h = CALHEIGHT;

  if (layout <= 4) {            /* APPOINTMENT is the biggest panel */
    win[APP].w = col - win[CAL].w;
    win[APP].h = row - (win[STA].h + win[NOT].h);
    win[TOD].w = win[CAL].w;
    win[TOD].h = row - (win[CAL].h + win[STA].h + win[NOT].h);
  } else {                      /* TODO is the biggest panel */
    win[TOD].w = col - win[CAL].w;
    win[TOD].h = row - (win[STA].h + win[NOT].h);
    win[APP].w = win[CAL].w;
    win[APP].h = row - (win[CAL].h + win[STA].h + win[NOT].h);
  }

  /* defining the layout */
  switch (layout) {
  case 1:
    win[APP].y = 0;
    win[APP].x = 0;
    win[CAL].y = 0;
    win[TOD].x = win[APP].w;
    win[TOD].y = win[CAL].h;
    win[CAL].x = win[APP].w;
    break;
  case 2:
    win[APP].y = 0;
    win[APP].x = 0;
    win[TOD].y = 0;
    win[TOD].x = win[APP].w;
    win[CAL].x = win[APP].w;
    win[CAL].y = win[TOD].h;
    break;
  case 3:
    win[APP].y = 0;
    win[TOD].x = 0;
    win[CAL].x = 0;
    win[CAL].y = 0;
    win[APP].x = win[CAL].w;
    win[TOD].y = win[CAL].h;
    break;
  case 4:
    win[APP].y = 0;
    win[TOD].x = 0;
    win[TOD].y = 0;
    win[CAL].x = 0;
    win[APP].x = win[CAL].w;
    win[CAL].y = win[TOD].h;
    break;
  case 5:
    win[TOD].y = 0;
    win[TOD].x = 0;
    win[CAL].y = 0;
    win[APP].y = win[CAL].h;
    win[APP].x = win[TOD].w;
    win[CAL].x = win[TOD].w;
    break;
  case 6:
    win[TOD].y = 0;
    win[TOD].x = 0;
    win[APP].y = 0;
    win[APP].x = win[TOD].w;
    win[CAL].x = win[TOD].w;
    win[CAL].y = win[APP].h;
    break;
  case 7:
    win[TOD].y = 0;
    win[APP].x = 0;
    win[CAL].x = 0;
    win[CAL].y = 0;
    win[TOD].x = win[CAL].w;
    win[APP].y = win[CAL].h;
    break;
  case 8:
    win[TOD].y = 0;
    win[APP].x = 0;
    win[CAL].x = 0;
    win[APP].y = 0;
    win[TOD].x = win[CAL].w;
    win[CAL].y = win[APP].h;
    break;
  }
}

/* draw panel border in color */
static void border_color(WINDOW * window)
{
  int color_attr = A_BOLD;
  int no_color_attr = A_BOLD;

  if (colorize) {
    wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
    box(window, 0, 0);
  } else {
    wattron(window, no_color_attr);
    box(window, 0, 0);
  }
  if (colorize) {
    wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
  } else {
    wattroff(window, no_color_attr);
  }
  wnoutrefresh(window);
}

/* draw panel border without any color */
static void border_nocolor(WINDOW * window)
{
  int color_attr = A_BOLD;
  int no_color_attr = A_DIM;

  if (colorize) {
    wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
  } else {
    wattron(window, no_color_attr);
  }
  box(window, 0, 0);
  if (colorize) {
    wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
  } else {
    wattroff(window, no_color_attr);
  }
  wnoutrefresh(window);
}

void wins_update_border(int flags)
{
  if (flags & FLAG_CAL) {
    if (slctd_win == CAL)
      border_color(win[CAL].p);
    else
      border_nocolor(win[CAL].p);
  }
  if (flags & FLAG_APP) {
    if (slctd_win == APP)
      border_color(win[APP].p);
    else
      border_nocolor(win[APP].p);
  }
  if (flags & FLAG_TOD) {
    if (slctd_win == TOD)
      border_color(win[TOD].p);
    else
      border_nocolor(win[TOD].p);
  }
}

void wins_update_panels(int flags)
{
  if (flags & FLAG_APP)
    apoint_update_panel(slctd_win);
  if (flags & FLAG_TOD)
    todo_update_panel(slctd_win);
  if (flags & FLAG_CAL)
    calendar_update_panel(&win[CAL]);
}

/*
 * Update all of the three windows and put a border around the
 * selected window.
 */
void wins_update(int flags)
{
  wins_update_border(flags);
  wins_update_panels(flags);
  if (flags & FLAG_STA)
    wins_status_bar();
  if ((flags & FLAG_NOT) && notify_bar())
    notify_update_bar();
  wmove(win[STA].p, 0, 0);
  wins_doupdate();
}

/* Reset the screen, needed when resizing terminal for example. */
void wins_reset(void)
{
  endwin();
  wins_refresh();
  curs_set(0);
  wins_reinit();
  wins_update(FLAG_ALL);
}

/* Prepare windows for the execution of an external command. */
void wins_prepare_external(void)
{
  if (notify_bar())
    notify_stop_main_thread();
  def_prog_mode();
  ui_mode = UI_CMDLINE;
  clear();
  wins_refresh();
  endwin();
}

/* Restore windows when returning from an external command. */
void wins_unprepare_external(void)
{
  reset_prog_mode();
  clearok(curscr, TRUE);
  curs_set(0);
  ui_mode = UI_CURSES;
  wins_refresh();
  if (notify_bar())
    notify_start_main_thread();
}

/*
 * While inside interactive mode, launch the external command cmd on the given
 * file.
 */
void wins_launch_external(const char *file, const char *cmd)
{
  const char *arg[] = { cmd, file, NULL };
  int pid;

  wins_prepare_external();
  if ((pid = shell_exec(NULL, NULL, *arg, arg)))
    child_wait(NULL, NULL, pid);
  wins_unprepare_external();
}

#define NB_CAL_CMDS    27       /* number of commands while in cal view */
#define NB_APP_CMDS    32       /* same thing while in appointment view */
#define NB_TOD_CMDS    31       /* same thing while in todo view */

static unsigned status_page;

/*
 * Draws the status bar.
 * To add a keybinding, insert a new binding_t item, add it in the *binding
 * table, and update the NB_CAL_CMDS, NB_APP_CMDS or NB_TOD_CMDS defines,
 * depending on which panel the added keybind is assigned to.
 */
void wins_status_bar(void)
{
  struct binding help = { _("Help"), KEY_GENERIC_HELP };
  struct binding quit = { _("Quit"), KEY_GENERIC_QUIT };
  struct binding save = { _("Save"), KEY_GENERIC_SAVE };
  struct binding copy = { _("Copy"), KEY_GENERIC_COPY };
  struct binding paste = { _("Paste"), KEY_GENERIC_PASTE };
  struct binding chgvu = { _("Chg Win"), KEY_GENERIC_CHANGE_VIEW };
  struct binding import = { _("Import"), KEY_GENERIC_IMPORT };
  struct binding export = { _("Export"), KEY_GENERIC_EXPORT };
  struct binding togo = { _("Go to"), KEY_GENERIC_GOTO };
  struct binding conf = { _("Config"), KEY_GENERIC_CONFIG_MENU };
  struct binding draw = { _("Redraw"), KEY_GENERIC_REDRAW };
  struct binding appt = { _("Add Appt"), KEY_GENERIC_ADD_APPT };
  struct binding todo = { _("Add Todo"), KEY_GENERIC_ADD_TODO };
  struct binding gpday = { _("-1 Day"), KEY_GENERIC_PREV_DAY };
  struct binding gnday = { _("+1 Day"), KEY_GENERIC_NEXT_DAY };
  struct binding gpweek = { _("-1 Week"), KEY_GENERIC_PREV_WEEK };
  struct binding gnweek = { _("+1 Week"), KEY_GENERIC_NEXT_WEEK };
  struct binding gpmonth = { _("-1 Month"), KEY_GENERIC_PREV_MONTH };
  struct binding gnmonth = { _("+1 Month"), KEY_GENERIC_NEXT_MONTH };
  struct binding gpyear = { _("-1 Year"), KEY_GENERIC_PREV_YEAR };
  struct binding gnyear = { _("+1 Year"), KEY_GENERIC_NEXT_YEAR };
  struct binding today = { _("Today"), KEY_GENERIC_GOTO_TODAY };
  struct binding nview = { _("Nxt View"), KEY_GENERIC_SCROLL_DOWN };
  struct binding pview = { _("Prv View"), KEY_GENERIC_SCROLL_UP };
  struct binding up = { _("Up"), KEY_MOVE_UP };
  struct binding down = { _("Down"), KEY_MOVE_DOWN };
  struct binding left = { _("Left"), KEY_MOVE_LEFT };
  struct binding right = { _("Right"), KEY_MOVE_RIGHT };
  struct binding weekb = { _("beg Week"), KEY_START_OF_WEEK };
  struct binding weeke = { _("end Week"), KEY_END_OF_WEEK };
  struct binding add = { _("Add Item"), KEY_ADD_ITEM };
  struct binding del = { _("Del Item"), KEY_DEL_ITEM };
  struct binding edit = { _("Edit Itm"), KEY_EDIT_ITEM };
  struct binding view = { _("View"), KEY_VIEW_ITEM };
  struct binding pipe = { _("Pipe"), KEY_PIPE_ITEM };
  struct binding flag = { _("Flag Itm"), KEY_FLAG_ITEM };
  struct binding rept = { _("Repeat"), KEY_REPEAT_ITEM };
  struct binding enote = { _("EditNote"), KEY_EDIT_NOTE };
  struct binding vnote = { _("ViewNote"), KEY_VIEW_NOTE };
  struct binding rprio = { _("Prio.+"), KEY_RAISE_PRIORITY };
  struct binding lprio = { _("Prio.-"), KEY_LOWER_PRIORITY };
  struct binding othr = { _("OtherCmd"), KEY_GENERIC_OTHER_CMD };

  struct binding *bindings_cal[] = {
    &help, &quit, &save, &chgvu, &nview, &pview, &up, &down, &left, &right,
    &togo, &import, &export, &weekb, &weeke, &appt, &todo, &gpday, &gnday,
    &gpweek, &gnweek, &gpmonth, &gnmonth, &gpyear, &gnyear, &draw, &today,
    &conf
  };

  struct binding *bindings_apoint[] = {
    &help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
    &pipe, &draw, &rept, &flag, &enote, &vnote, &up, &down, &gpday, &gnday,
    &gpweek, &gnweek, &gpmonth, &gnmonth, &gpyear, &gnyear, &togo, &today,
    &conf, &appt, &todo, &copy, &paste
  };

  struct binding *bindings_todo[] = {
    &help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
    &pipe, &flag, &rprio, &lprio, &enote, &vnote, &up, &down, &gpday, &gnday,
    &gpweek, &gnweek, &gpmonth, &gnmonth, &gpyear, &gnyear, &togo, &today,
    &conf, &appt, &todo, &draw
  };

  enum win active_panel = wins_slctd();

  struct binding **bindings;
  int bindings_size;

  switch (active_panel) {
  case CAL:
    bindings = bindings_cal;
    bindings_size = sizeof(bindings_cal) / sizeof(bindings_cal[0]);
    break;
  case APP:
    bindings = bindings_apoint;
    bindings_size = sizeof(bindings_apoint) / sizeof(bindings_apoint[0]);
    break;
  case TOD:
    bindings = bindings_todo;
    bindings_size = sizeof(bindings_todo) / sizeof(bindings_todo[0]);
    break;
  default:
    EXIT(_("unknown panel"));
    /* NOTREACHED */
  }

  keys_display_bindings_bar(win[STA].p, bindings, bindings_size,
                            (KEYS_CMDS_PER_LINE * 2 - 1) * (status_page - 1),
                            KEYS_CMDS_PER_LINE * 2, &othr);
}

/* Erase status bar. */
void wins_erase_status_bar(void)
{
  erase_window_part(win[STA].p, 0, 0, col, STATUSHEIGHT);
}

/* Update the status bar page number to display other commands. */
void wins_other_status_page(int panel)
{
  int nb_item, max_page;

  switch (panel) {
  case CAL:
    nb_item = NB_CAL_CMDS;
    break;
  case APP:
    nb_item = NB_APP_CMDS;
    break;
  case TOD:
    nb_item = NB_TOD_CMDS;
    break;
  default:
    EXIT(_("unknown panel"));
    /* NOTREACHED */
  }
  max_page = nb_item / (KEYS_CMDS_PER_LINE * 2 - 1) + 1;
  status_page = (status_page % max_page) + 1;
}

/* Reset the status bar page. */
void wins_reset_status_page(void)
{
  status_page = 1;
}

#undef NB_CAL_CMDS
#undef NB_APP_CMDS
#undef NB_TOD_CMDS