NeoMutt  2022-04-29-145-g9b6a0e
Teaching an old dog new tricks
DOXYGEN
lib.h File Reference

GUI present the user with a selectable list. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "type.h"
+ Include dependency graph for lib.h:

Go to the source code of this file.

Data Structures

struct  Menu
 

Macros

#define MENU_REDRAW_NO_FLAGS   0
 No flags are set. More...
 
#define MENU_REDRAW_INDEX   (1 << 0)
 Redraw the index. More...
 
#define MENU_REDRAW_MOTION   (1 << 1)
 Redraw after moving the menu list. More...
 
#define MENU_REDRAW_CURRENT   (1 << 2)
 Redraw the current line of the menu. More...
 
#define MENU_REDRAW_FULL   (1 << 3)
 Redraw everything. More...
 

Typedefs

typedef uint8_t MenuRedrawFlags
 Flags, e.g. MENU_REDRAW_INDEX. More...
 

Functions

MenuRedrawFlags menu_bottom_page (struct Menu *menu)
 Move the focus to the bottom of the page. More...
 
MenuRedrawFlags menu_current_bottom (struct Menu *menu)
 Move the current selection to the bottom of the window. More...
 
MenuRedrawFlags menu_current_middle (struct Menu *menu)
 Move the current selection to the centre of the window. More...
 
MenuRedrawFlags menu_current_top (struct Menu *menu)
 Move the current selection to the top of the window. More...
 
MenuRedrawFlags menu_first_entry (struct Menu *menu)
 Move the focus to the first entry in the menu. More...
 
MenuRedrawFlags menu_half_down (struct Menu *menu)
 Move the focus down half a page in the menu. More...
 
MenuRedrawFlags menu_half_up (struct Menu *menu)
 Move the focus up half a page in the menu. More...
 
MenuRedrawFlags menu_last_entry (struct Menu *menu)
 Move the focus to the last entry in the menu. More...
 
MenuRedrawFlags menu_middle_page (struct Menu *menu)
 Move the focus to the centre of the page. More...
 
MenuRedrawFlags menu_next_entry (struct Menu *menu)
 Move the focus to the next item in the menu. More...
 
MenuRedrawFlags menu_next_line (struct Menu *menu)
 Move the view down one line, keeping the selection the same. More...
 
MenuRedrawFlags menu_next_page (struct Menu *menu)
 Move the focus to the next page in the menu. More...
 
MenuRedrawFlags menu_prev_entry (struct Menu *menu)
 Move the focus to the previous item in the menu. More...
 
MenuRedrawFlags menu_prev_line (struct Menu *menu)
 Move the view up one line, keeping the selection the same. More...
 
MenuRedrawFlags menu_prev_page (struct Menu *menu)
 Move the focus to the previous page in the menu. More...
 
MenuRedrawFlags menu_top_page (struct Menu *menu)
 Move the focus to the top of the page. More...
 
void menu_redraw_current (struct Menu *menu)
 Redraw the current menu. More...
 
void menu_redraw_full (struct Menu *menu)
 Force the redraw of the Menu. More...
 
void menu_redraw_index (struct Menu *menu)
 Force the redraw of the index. More...
 
void menu_redraw_motion (struct Menu *menu)
 Force the redraw of the list part of the menu. More...
 
int menu_redraw (struct Menu *menu)
 Redraw the parts of the screen that have been flagged to be redrawn. More...
 
void menu_add_dialog_row (struct Menu *menu, const char *row)
 
void menu_cleanup (void)
 Free the saved Menu searches. More...
 
enum MenuType menu_get_current_type (void)
 Get the type of the current Window. More...
 
void menu_init (void)
 Initialise all the Menus. More...
 
struct MuttWindowmenu_window_new (enum MenuType type, struct ConfigSubset *sub)
 Create a new Menu Window. More...
 
int menu_get_index (struct Menu *menu)
 Get the current selection in the Menu. More...
 
MenuRedrawFlags menu_set_index (struct Menu *menu, int index)
 Set the current selection in the Menu. More...
 
MenuRedrawFlags menu_move_selection (struct Menu *menu, int index)
 Move the selection, keeping within between [0, menu->max]. More...
 
void menu_queue_redraw (struct Menu *menu, MenuRedrawFlags redraw)
 Queue a request for a redraw. More...
 
MenuRedrawFlags menu_move_view_relative (struct Menu *menu, int relative)
 Move the view relatively. More...
 
MenuRedrawFlags menu_set_and_notify (struct Menu *menu, int top, int index)
 Set the Menu selection/view and notify others. More...
 
void menu_adjust (struct Menu *menu)
 Reapply the config to the Menu. More...
 
int menu_function_dispatcher (struct MuttWindow *win, int op)
 Perform a Menu function - Implements function_dispatcher_t -. More...
 
int menu_tagging_dispatcher (struct MuttWindow *win, int op)
 Perform tagging operations on the Menu - Implements function_dispatcher_t -. More...
 

Detailed Description

GUI present the user with a selectable list.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file lib.h.

Macro Definition Documentation

◆ MENU_REDRAW_NO_FLAGS

#define MENU_REDRAW_NO_FLAGS   0

No flags are set.

Definition at line 55 of file lib.h.

◆ MENU_REDRAW_INDEX

#define MENU_REDRAW_INDEX   (1 << 0)

Redraw the index.

Definition at line 56 of file lib.h.

◆ MENU_REDRAW_MOTION

#define MENU_REDRAW_MOTION   (1 << 1)

Redraw after moving the menu list.

Definition at line 57 of file lib.h.

◆ MENU_REDRAW_CURRENT

#define MENU_REDRAW_CURRENT   (1 << 2)

Redraw the current line of the menu.

Definition at line 58 of file lib.h.

◆ MENU_REDRAW_FULL

#define MENU_REDRAW_FULL   (1 << 3)

Redraw everything.

Definition at line 59 of file lib.h.

Typedef Documentation

◆ MenuRedrawFlags

typedef uint8_t MenuRedrawFlags

Flags, e.g. MENU_REDRAW_INDEX.

Definition at line 54 of file lib.h.

Function Documentation

◆ menu_bottom_page()

MenuRedrawFlags menu_bottom_page ( struct Menu menu)

Move the focus to the bottom of the page.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 363 of file move.c.

364 {
365  if (menu->max == 0)
366  {
367  mutt_error(_("No entries"));
368  return MENU_REDRAW_NO_FLAGS;
369  }
370 
371  int index = menu->top + menu->page_len - 1;
372  if (index > (menu->max - 1))
373  index = menu->max - 1;
374  return menu_move_selection(menu, index);
375 }
#define mutt_error(...)
Definition: logging.h:87
#define MENU_REDRAW_NO_FLAGS
No flags are set.
Definition: lib.h:55
MenuRedrawFlags menu_move_selection(struct Menu *menu, int index)
Move the selection, keeping within between [0, menu->max].
Definition: move.c:236
#define _(a)
Definition: message.h:28
int top
Entry that is the top of the current page.
Definition: lib.h:80
int max
Number of entries in the menu.
Definition: lib.h:71
int page_len
Number of entries per screen.
Definition: lib.h:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_current_bottom()

MenuRedrawFlags menu_current_bottom ( struct Menu menu)

Move the current selection to the bottom of the window.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 484 of file move.c.

485 {
486  if (menu->max == 0)
487  {
488  mutt_error(_("No entries"));
489  return MENU_REDRAW_NO_FLAGS;
490  }
491 
492  short context = cs_subset_number(menu->sub, "menu_context");
493  if (context > (menu->page_len / 2))
494  return MENU_REDRAW_NO_FLAGS;
495 
496  context = MIN(context, (menu->page_len / 2));
497  return menu_move_view_relative(menu, 0 - (menu->top + menu->page_len - 1 -
498  menu->current - context));
499 }
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
#define MIN(a, b)
Definition: memory.h:31
MenuRedrawFlags menu_move_view_relative(struct Menu *menu, int relative)
Move the view relatively.
Definition: move.c:254
int current
Current entry.
Definition: lib.h:70
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_current_middle()

MenuRedrawFlags menu_current_middle ( struct Menu menu)

Move the current selection to the centre of the window.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 464 of file move.c.

465 {
466  if (menu->max == 0)
467  {
468  mutt_error(_("No entries"));
469  return MENU_REDRAW_NO_FLAGS;
470  }
471 
472  short context = cs_subset_number(menu->sub, "menu_context");
473  if (context > (menu->page_len / 2))
474  return MENU_REDRAW_NO_FLAGS;
475 
476  return menu_move_view_relative(menu, menu->current - (menu->top + (menu->page_len / 2)));
477 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_current_top()

MenuRedrawFlags menu_current_top ( struct Menu menu)

Move the current selection to the top of the window.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 443 of file move.c.

444 {
445  if (menu->max == 0)
446  {
447  mutt_error(_("No entries"));
448  return MENU_REDRAW_NO_FLAGS;
449  }
450 
451  short context = cs_subset_number(menu->sub, "menu_context");
452  if (context > (menu->page_len / 2))
453  return MENU_REDRAW_NO_FLAGS;
454 
455  context = MIN(context, (menu->page_len / 2));
456  return menu_move_view_relative(menu, menu->current - menu->top - context);
457 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_first_entry()

MenuRedrawFlags menu_first_entry ( struct Menu menu)

Move the focus to the first entry in the menu.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 410 of file move.c.

411 {
412  if (menu->max == 0)
413  {
414  mutt_error(_("No entries"));
415  return MENU_REDRAW_NO_FLAGS;
416  }
417 
418  return menu_move_selection(menu, 0);
419 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_half_down()

MenuRedrawFlags menu_half_down ( struct Menu menu)

Move the focus down half a page in the menu.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 516 of file move.c.

517 {
518  return menu_move_view_relative(menu, (menu->page_len / 2));
519 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_half_up()

MenuRedrawFlags menu_half_up ( struct Menu menu)

Move the focus up half a page in the menu.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 506 of file move.c.

507 {
508  return menu_move_view_relative(menu, 0 - (menu->page_len / 2));
509 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_last_entry()

MenuRedrawFlags menu_last_entry ( struct Menu menu)

Move the focus to the last entry in the menu.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 426 of file move.c.

427 {
428  if (menu->max == 0)
429  {
430  mutt_error(_("No entries"));
431  return MENU_REDRAW_NO_FLAGS;
432  }
433 
434  return menu_move_selection(menu, menu->max - 1);
435 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_middle_page()

MenuRedrawFlags menu_middle_page ( struct Menu menu)

Move the focus to the centre of the page.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 343 of file move.c.

344 {
345  if (menu->max == 0)
346  {
347  mutt_error(_("No entries"));
348  return MENU_REDRAW_NO_FLAGS;
349  }
350 
351  int i = menu->top + menu->page_len;
352  if (i > (menu->max - 1))
353  i = menu->max - 1;
354 
355  return menu_move_selection(menu, menu->top + (i - menu->top) / 2);
356 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_next_entry()

MenuRedrawFlags menu_next_entry ( struct Menu menu)

Move the focus to the next item in the menu.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 396 of file move.c.

397 {
398  if (menu->current < (menu->max - 1))
399  return menu_move_selection(menu, menu->current + 1);
400 
401  mutt_message(_("You are on the last entry"));
402  return MENU_REDRAW_NO_FLAGS;
403 }
#define mutt_message(...)
Definition: logging.h:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_next_line()

MenuRedrawFlags menu_next_line ( struct Menu menu)

Move the view down one line, keeping the selection the same.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 539 of file move.c.

540 {
541  MenuRedrawFlags flags = menu_move_view_relative(menu, 1);
542  if (flags == MENU_REDRAW_NO_FLAGS)
543  mutt_message(_("You can't scroll down farther"));
544  return flags;
545 }
uint8_t MenuRedrawFlags
Flags, e.g. MENU_REDRAW_INDEX.
Definition: lib.h:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_next_page()

MenuRedrawFlags menu_next_page ( struct Menu menu)

Move the focus to the next page in the menu.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 562 of file move.c.

563 {
564  return menu_move_view_relative(menu, menu->page_len);
565 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_prev_entry()

MenuRedrawFlags menu_prev_entry ( struct Menu menu)

Move the focus to the previous item in the menu.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 382 of file move.c.

383 {
384  if (menu->current > 0)
385  return menu_move_selection(menu, menu->current - 1);
386 
387  mutt_message(_("You are on the first entry"));
388  return MENU_REDRAW_NO_FLAGS;
389 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_prev_line()

MenuRedrawFlags menu_prev_line ( struct Menu menu)

Move the view up one line, keeping the selection the same.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 526 of file move.c.

527 {
528  MenuRedrawFlags flags = menu_move_view_relative(menu, -1);
529  if (flags == MENU_REDRAW_NO_FLAGS)
530  mutt_message(_("You can't scroll up farther"));
531  return flags;
532 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_prev_page()

MenuRedrawFlags menu_prev_page ( struct Menu menu)

Move the focus to the previous page in the menu.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 552 of file move.c.

553 {
554  return menu_move_view_relative(menu, 0 - menu->page_len);
555 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_top_page()

MenuRedrawFlags menu_top_page ( struct Menu menu)

Move the focus to the top of the page.

Parameters
menuCurrent Menu
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 333 of file move.c.

334 {
335  return menu_move_selection(menu, menu->top);
336 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_current()

void menu_redraw_current ( struct Menu menu)

Redraw the current menu.

Parameters
menuCurrent Menu

Definition at line 445 of file draw.c.

446 {
447  char buf[1024];
448  struct AttrColor *ac = menu->color(menu, menu->current);
449 
450  mutt_window_move(menu->win, 0, menu->current - menu->top);
451  menu->make_entry(menu, buf, sizeof(buf), menu->current);
452  menu_pad_string(menu, buf, sizeof(buf));
453 
455  const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
456  const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
457  if (c_arrow_cursor)
458  {
459  mutt_curses_set_color(ac_ind);
460  mutt_window_addstr(menu->win, c_arrow_string);
462  mutt_window_addch(menu->win, ' ');
463  menu_pad_string(menu, buf, sizeof(buf));
464  print_enriched_string(menu->win, menu->current, ac, NULL,
465  (unsigned char *) buf, menu->sub);
466  }
467  else
468  {
469  print_enriched_string(menu->win, menu->current, ac, ac_ind,
470  (unsigned char *) buf, menu->sub);
471  }
473 }
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:74
@ MT_COLOR_INDICATOR
Selected item in list.
Definition: color.h:49
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:53
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
static void print_enriched_string(struct MuttWindow *win, int index, struct AttrColor *ac_def, struct AttrColor *ac_ind, unsigned char *s, struct ConfigSubset *sub)
Display a string with embedded colours and graphics.
Definition: draw.c:118
static void menu_pad_string(struct Menu *menu, char *buf, size_t buflen)
Pad a string with spaces for display in the Menu.
Definition: draw.c:297
void mutt_curses_set_color(struct AttrColor *ac)
Set the colour and attributes for text.
Definition: mutt_curses.c:40
struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:81
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:293
int mutt_window_addstr(struct MuttWindow *win, const char *str)
Write a string to a Window.
Definition: mutt_window.c:409
int mutt_window_addch(struct MuttWindow *win, int ch)
Write one character to a Window.
Definition: mutt_window.c:381
A curses colour and its attributes.
Definition: attr.h:35
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:96
struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:133
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_full()

void menu_redraw_full ( struct Menu menu)

Force the redraw of the Menu.

Parameters
menuCurrent Menu

Definition at line 315 of file draw.c.

316 {
318  mutt_window_clear(menu->win);
319 
320  menu->page_len = menu->win->state.rows;
321 
322  menu->redraw = MENU_REDRAW_INDEX;
323 }
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:56
void mutt_window_clear(struct MuttWindow *win)
Clear a Window.
Definition: mutt_window.c:695
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_index()

void menu_redraw_index ( struct Menu menu)

Force the redraw of the index.

Parameters
menuCurrent Menu

Definition at line 329 of file draw.c.

330 {
331  char buf[1024];
332  struct AttrColor *ac = NULL;
333 
334  const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
335  const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
337  for (int i = menu->top; i < (menu->top + menu->page_len); i++)
338  {
339  if (i < menu->max)
340  {
341  ac = menu->color(menu, i);
342 
343  menu->make_entry(menu, buf, sizeof(buf), i);
344  menu_pad_string(menu, buf, sizeof(buf));
345 
347  mutt_window_move(menu->win, 0, i - menu->top);
348 
349  if (i == menu->current)
350  mutt_curses_set_color(ac_ind);
351 
352  if (c_arrow_cursor)
353  {
354  if (i == menu->current)
355  {
356  mutt_window_addstr(menu->win, c_arrow_string);
358  mutt_window_addch(menu->win, ' ');
359  }
360  else
361  {
362  /* Print space chars to match the screen width of `$arrow_string` */
363  mutt_window_printf(menu->win, "%*s", mutt_strwidth(c_arrow_string) + 1, "");
364  }
365  }
366 
367  if ((i == menu->current) && !c_arrow_cursor)
368  print_enriched_string(menu->win, i, ac, ac_ind, (unsigned char *) buf, menu->sub);
369  else
370  print_enriched_string(menu->win, i, ac, NULL, (unsigned char *) buf, menu->sub);
371  }
372  else
373  {
375  mutt_window_clearline(menu->win, i - menu->top);
376  }
377  }
380 }
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition: curs_lib.c:904
int mutt_window_printf(struct MuttWindow *win, const char *fmt,...)
Write a formatted string to a Window.
Definition: mutt_window.c:424
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:230
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_motion()

void menu_redraw_motion ( struct Menu menu)

Force the redraw of the list part of the menu.

Parameters
menuCurrent Menu

Definition at line 386 of file draw.c.

387 {
388  char buf[1024];
389 
390  /* Note: menu->color() for the index can end up retrieving a message
391  * over imap (if matching against ~h for instance). This can
392  * generate status messages. So we want to call it *before* we
393  * position the cursor for drawing. */
394  struct AttrColor *old_color = menu->color(menu, menu->old_current);
395  mutt_window_move(menu->win, 0, menu->old_current - menu->top);
396  mutt_curses_set_color(old_color);
397 
398  const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
399  const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
401  if (c_arrow_cursor)
402  {
403  /* clear the arrow */
404  /* Print space chars to match the screen width of `$arrow_string` */
405  mutt_window_printf(menu->win, "%*s", mutt_strwidth(c_arrow_string) + 1, "");
407 
408  menu->make_entry(menu, buf, sizeof(buf), menu->old_current);
409  menu_pad_string(menu, buf, sizeof(buf));
410  mutt_window_move(menu->win, mutt_strwidth(c_arrow_string) + 1,
411  menu->old_current - menu->top);
412  print_enriched_string(menu->win, menu->old_current, old_color, NULL,
413  (unsigned char *) buf, menu->sub);
414 
415  /* now draw it in the new location */
416  mutt_curses_set_color(ac_ind);
417  mutt_window_mvaddstr(menu->win, 0, menu->current - menu->top, c_arrow_string);
418  }
419  else
420  {
422  /* erase the current indicator */
423  menu->make_entry(menu, buf, sizeof(buf), menu->old_current);
424  menu_pad_string(menu, buf, sizeof(buf));
425  print_enriched_string(menu->win, menu->old_current, old_color, NULL,
426  (unsigned char *) buf, menu->sub);
427 
428  /* now draw the new one to reflect the change */
429  struct AttrColor *cur_color = menu->color(menu, menu->current);
430  cur_color = merged_color_overlay(cur_color, ac_ind);
431  menu->make_entry(menu, buf, sizeof(buf), menu->current);
432  menu_pad_string(menu, buf, sizeof(buf));
433  mutt_window_move(menu->win, 0, menu->current - menu->top);
434  mutt_curses_set_color(cur_color);
435  print_enriched_string(menu->win, menu->current, cur_color, ac_ind,
436  (unsigned char *) buf, menu->sub);
437  }
439 }
struct AttrColor * merged_color_overlay(struct AttrColor *base, struct AttrColor *over)
Combine two colours.
Definition: merged.c:109
int mutt_window_mvaddstr(struct MuttWindow *win, int col, int row, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:307
int old_current
For driver use only.
Definition: lib.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw()

int menu_redraw ( struct Menu menu)

Redraw the parts of the screen that have been flagged to be redrawn.

Parameters
menuMenu to redraw
Return values
OP_NULLMenu was redrawn
OP_REDRAWFull redraw required

Definition at line 481 of file draw.c.

482 {
483  /* See if all or part of the screen needs to be updated. */
484  if (menu->redraw & MENU_REDRAW_FULL)
485  menu_redraw_full(menu);
486 
487  if (menu->redraw & MENU_REDRAW_INDEX)
488  menu_redraw_index(menu);
489  else if (menu->redraw & MENU_REDRAW_MOTION)
490  menu_redraw_motion(menu);
491  else if (menu->redraw == MENU_REDRAW_CURRENT)
492  menu_redraw_current(menu);
493 
494  return OP_NULL;
495 }
void menu_redraw_current(struct Menu *menu)
Redraw the current menu.
Definition: draw.c:445
void menu_redraw_index(struct Menu *menu)
Force the redraw of the index.
Definition: draw.c:329
void menu_redraw_full(struct Menu *menu)
Force the redraw of the Menu.
Definition: draw.c:315
void menu_redraw_motion(struct Menu *menu)
Force the redraw of the list part of the menu.
Definition: draw.c:386
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:59
#define MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition: lib.h:58
#define MENU_REDRAW_MOTION
Redraw after moving the menu list.
Definition: lib.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_add_dialog_row()

void menu_add_dialog_row ( struct Menu menu,
const char *  row 
)

◆ menu_cleanup()

void menu_cleanup ( void  )

Free the saved Menu searches.

Definition at line 65 of file menu.c.

66 {
67  for (int i = 0; i < MENU_MAX; i++)
68  FREE(&SearchBuffers[i]);
69 }
#define FREE(x)
Definition: memory.h:43
char * SearchBuffers[MENU_MAX]
Definition: menu.c:39
@ MENU_MAX
Definition: type.h:59
+ Here is the caller graph for this function:

◆ menu_get_current_type()

enum MenuType menu_get_current_type ( void  )

Get the type of the current Window.

Return values
enumMenu Type, e.g. MENU_PAGER

Definition at line 74 of file menu.c.

85 {
86  struct MuttWindow *win = alldialogs_get_current();
87  while (win && win->focus)
88  win = win->focus;
89 
90  // This should only happen before the first window is created
91  if (!win)
92  return MENU_INDEX;
93 
94  if ((win->type == WT_CUSTOM) && (win->parent->type == WT_PAGER))
95  return MENU_PAGER;
96 
97  if (win->type != WT_MENU)
98  return MENU_GENERIC;
99 
100  struct Menu *menu = win->wdata;
101  if (!menu)
102  return MENU_GENERIC;
103 
104  return menu->type;
105 }
struct MuttWindow * alldialogs_get_current(void)
Get the currently active Dialog.
Definition: dialog.c:222
@ WT_CUSTOM
Window with a custom drawing function.
Definition: mutt_window.h:95
@ WT_PAGER
A panel containing the Pager Window.
Definition: mutt_window.h:100
@ WT_MENU
An Window containing a Menu.
Definition: mutt_window.h:98
Definition: lib.h:69
enum MenuType type
Menu definition for keymap entries.
Definition: lib.h:73
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:50
@ MENU_GENERIC
Generic selection list.
Definition: type.h:45
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:54
+ Here is the caller graph for this function:

◆ menu_init()

void menu_init ( void  )

Initialise all the Menus.

Definition at line 74 of file menu.c.

75 {
76  for (int i = 0; i < MENU_MAX; i++)
77  SearchBuffers[i] = NULL;
78 }
+ Here is the caller graph for this function:

◆ menu_window_new()

struct MuttWindow* menu_window_new ( enum MenuType  type,
struct ConfigSubset sub 
)

Create a new Menu Window.

Parameters
typeMenu type, e.g. MENU_PAGER
subConfig items
Return values
ptrNew MuttWindow wrapping a Menu

Definition at line 136 of file window.c.

137 {
141 
142  struct Menu *menu = menu_new(type, win, sub);
143 
146  win->wdata = menu;
148  win->actions |= WA_RECALC;
149 
150  return win;
151 }
static int menu_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: window.c:80
static int menu_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition: window.c:95
static void menu_wdata_free(struct MuttWindow *win, void **ptr)
Destroy a Menu Window - Implements MuttWindow::wdata_free() -.
Definition: window.c:125
struct Menu * menu_new(enum MenuType type, struct MuttWindow *win, struct ConfigSubset *sub)
Create a new Menu.
Definition: menu.c:130
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:181
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:48
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:171
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_get_index()

int menu_get_index ( struct Menu menu)

Get the current selection in the Menu.

Parameters
menuMenu
Return values
numIndex of selection

Definition at line 154 of file menu.c.

155 {
156  if (!menu)
157  return -1;
158 
159  return menu->current;
160 }

◆ menu_set_index()

MenuRedrawFlags menu_set_index ( struct Menu menu,
int  index 
)

Set the current selection in the Menu.

Parameters
menuMenu
indexItem to select
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_INDEX

Definition at line 168 of file menu.c.

169 {
170  return menu_move_selection(menu, index);
171 }
MenuRedrawFlags menu_move_selection(struct Menu *menu, int index)
Move the selection, keeping within between [0, menu->max].
Definition: move.c:236
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_move_selection()

MenuRedrawFlags menu_move_selection ( struct Menu menu,
int  index 
)

Move the selection, keeping within between [0, menu->max].

Parameters
menuMenu
indexNew selection
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 236 of file move.c.

237 {
238  if (index < 0)
239  index = 0;
240  else if (index >= menu->max)
241  index = menu->max - 1;
242 
243  int top = menu_drag_view(menu, menu->top, index);
244 
245  return menu_set_and_notify(menu, top, index);
246 }
MenuRedrawFlags menu_set_and_notify(struct Menu *menu, int top, int index)
Set the Menu selection/view and notify others.
Definition: move.c:66
static int menu_drag_view(struct Menu *menu, int top, int index)
Move the view around the selection.
Definition: move.c:111
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_queue_redraw()

void menu_queue_redraw ( struct Menu menu,
MenuRedrawFlags  redraw 
)

Queue a request for a redraw.

Parameters
menuMenu
redrawItem to redraw, e.g. MENU_REDRAW_CURRENT

Definition at line 178 of file menu.c.

179 {
180  if (!menu)
181  return;
182 
183  menu->redraw |= redraw;
184  menu->win->actions |= WA_RECALC;
185 }

◆ menu_move_view_relative()

MenuRedrawFlags menu_move_view_relative ( struct Menu menu,
int  relative 
)

Move the view relatively.

Parameters
menuMenu
relativeRelative number of lines to move
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 254 of file move.c.

255 {
256  const bool c_menu_move_off = cs_subset_bool(menu->sub, "menu_move_off");
257 
258  short context = cs_subset_number(menu->sub, "menu_context");
259  context = MIN(context, (menu->page_len / 2));
260 
261  // Move and range-check the view
262  int top = menu->top + relative;
263  if (top < 0)
264  {
265  top = 0;
266  }
267  else if (c_menu_move_off && (top >= (menu->max - context)))
268  {
269  top = menu->max - context - 1;
270  }
271  else if (!c_menu_move_off && ((top + menu->page_len) >= menu->max))
272  {
273  top = menu->max - menu->page_len;
274  }
275  if (top < 0)
276  top = 0;
277 
278  // Move the selection on-screen
279  int index = menu->current;
280  if (index < top)
281  index = top;
282  else if (index >= (top + menu->page_len))
283  index = top + menu->page_len - 1;
284 
285  // Check for top/bottom limits
286  if (index < context)
287  {
288  top = 0;
289  index = menu->current;
290  }
291  else if (!c_menu_move_off && (index > (menu->max - context)))
292  {
293  top = menu->max - menu->page_len;
294  index = menu->current;
295  }
296 
297  if (top == menu->top)
298  {
299  // Can't move the view; move the selection
300  index = calc_fit_selection_to_view(menu, top, index + relative);
301  }
302  else if (index > (top + menu->page_len - context - 1))
303  {
304  index = calc_fit_selection_to_view(menu, top, index + relative);
305  }
306  else
307  {
308  // Drag the selection into the view
309  index = calc_fit_selection_to_view(menu, top, index);
310  }
311 
312  return menu_set_and_notify(menu, top, index);
313 }
static int calc_fit_selection_to_view(struct Menu *menu, int top, int index)
Move the selection into the view.
Definition: move.c:164
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_set_and_notify()

MenuRedrawFlags menu_set_and_notify ( struct Menu menu,
int  top,
int  index 
)

Set the Menu selection/view and notify others.

Parameters
menuMenu
topIndex of item at the top of the view
indexSelected item
Return values
numMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 66 of file move.c.

67 {
69 
70  if (top != menu->top)
71  {
72  menu->top = top;
73  flags |= MENU_REDRAW_FULL;
74  }
75 
76  if (index != menu->current)
77  {
78  menu->old_current = menu->current;
79  menu->current = index;
80 
81  if (menu->redraw == MENU_REDRAW_NO_FLAGS)
82  {
83  // If this is the only change
84  flags |= MENU_REDRAW_MOTION;
85  }
86  else
87  {
88  // otherwise, redraw completely
89  flags |= MENU_REDRAW_FULL;
90  }
91  }
92 
93  if (flags != MENU_REDRAW_NO_FLAGS)
94  {
95  menu->redraw |= flags;
96  menu->win->actions |= WA_REPAINT;
97 
98  mutt_debug(LL_NOTIFY, "NT_MENU\n");
99  notify_send(menu->notify, NT_MENU, flags, NULL);
100  }
101  return flags;
102 }
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_NOTIFY
Log of notifications.
Definition: logging.h:45
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
@ NT_MENU
Menu has changed, MenuRedrawFlags.
Definition: notify_type.h:51
struct Notify * notify
Notifications.
Definition: lib.h:135
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_adjust()

void menu_adjust ( struct Menu menu)

Reapply the config to the Menu.

Parameters
menuMenu

Definition at line 319 of file move.c.

320 {
321  int top = calc_move_view(menu, 0);
322  top = menu_drag_view(menu, top, menu->current);
323 
324  menu_set_and_notify(menu, top, menu->current);
325 }
static int calc_move_view(struct Menu *menu, int relative)
Move the view.
Definition: move.c:194
+ Here is the call graph for this function:
+ Here is the caller graph for this function: