NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

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

#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
 

Typedefs

typedef uint8_t MenuRedrawFlags
 

Enumerations

enum  MenuRedrawFlag {
  MENU_REDRAW_NONE = 0 , MENU_REDRAW_INDEX = 1U << 0 , MENU_REDRAW_MOTION = 1U << 1 , MENU_REDRAW_CURRENT = 1U << 2 ,
  MENU_REDRAW_FULL = 1U << 3
}
 Flags, e.g. More...
 
enum  ExpandoDataMenu { ED_MEN_PERCENTAGE }
 Expando UIDs for Menus. More...
 

Functions

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

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.

Typedef Documentation

◆ MenuRedrawFlags

typedef uint8_t MenuRedrawFlags

Definition at line 66 of file lib.h.

Enumeration Type Documentation

◆ MenuRedrawFlag

Flags, e.g.

MENU_REDRAW_INDEX

Enumerator
MENU_REDRAW_NONE 

No flags are set.

MENU_REDRAW_INDEX 

Redraw the index.

MENU_REDRAW_MOTION 

Redraw after moving the menu list.

MENU_REDRAW_CURRENT 

Redraw the current line of the menu.

MENU_REDRAW_FULL 

Redraw everything.

Definition at line 58 of file lib.h.

59{
61 MENU_REDRAW_INDEX = 1U << 0,
62 MENU_REDRAW_MOTION = 1U << 1,
63 MENU_REDRAW_CURRENT = 1U << 2,
64 MENU_REDRAW_FULL = 1U << 3,
65};
@ MENU_REDRAW_INDEX
Redraw the index.
Definition lib.h:61
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
@ MENU_REDRAW_CURRENT
Redraw the current line of the menu.
Definition lib.h:63
@ MENU_REDRAW_NONE
No flags are set.
Definition lib.h:60
@ MENU_REDRAW_MOTION
Redraw after moving the menu list.
Definition lib.h:62

◆ ExpandoDataMenu

Expando UIDs for Menus.

See also
ED_MENU, ExpandoDomain
Enumerator
ED_MEN_PERCENTAGE 

Menu.top, ...

Definition at line 73 of file lib.h.

74{
76};
@ ED_MEN_PERCENTAGE
Menu.top, ...
Definition lib.h:75

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
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 369 of file move.c.

370{
371 if (menu->max == 0)
372 {
373 mutt_error(_("No entries"));
374 return MENU_REDRAW_NONE;
375 }
376
377 int index = menu->top + menu->page_len - 1;
378 if (index > (menu->max - 1))
379 index = menu->max - 1;
380 return menu_move_selection(menu, index);
381}
#define mutt_error(...)
Definition logging2.h:94
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:98
int max
Number of entries in the menu.
Definition lib.h:88
int page_len
Number of entries per screen.
Definition lib.h:91
+ 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
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 506 of file move.c.

507{
508 if (menu->max == 0)
509 {
510 mutt_error(_("No entries"));
511 return MENU_REDRAW_NONE;
512 }
513
514 short c_menu_context = cs_subset_number(menu->sub, "menu_context");
515 if (c_menu_context > (menu->page_len / 2))
516 return MENU_REDRAW_NONE;
517
518 c_menu_context = MIN(c_menu_context, (menu->page_len / 2));
519 return menu_move_view_relative(menu, 0 - (menu->top + menu->page_len - 1 -
520 menu->current - c_menu_context));
521}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition helpers.c:143
#define MIN(a, b)
Return the minimum of two values.
Definition memory.h:40
MenuRedrawFlags menu_move_view_relative(struct Menu *menu, int relative)
Move the view relatively.
Definition move.c:257
int current
Current entry.
Definition lib.h:87
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:95
+ 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
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 486 of file move.c.

487{
488 if (menu->max == 0)
489 {
490 mutt_error(_("No entries"));
491 return MENU_REDRAW_NONE;
492 }
493
494 short c_menu_context = cs_subset_number(menu->sub, "menu_context");
495 if (c_menu_context > (menu->page_len / 2))
496 return MENU_REDRAW_NONE;
497
498 return menu_move_view_relative(menu, menu->current - (menu->top + (menu->page_len / 2)));
499}
+ 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
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 465 of file move.c.

466{
467 if (menu->max == 0)
468 {
469 mutt_error(_("No entries"));
470 return MENU_REDRAW_NONE;
471 }
472
473 short c_menu_context = cs_subset_number(menu->sub, "menu_context");
474 if (c_menu_context > (menu->page_len / 2))
475 return MENU_REDRAW_NONE;
476
477 c_menu_context = MIN(c_menu_context, (menu->page_len / 2));
478 return menu_move_view_relative(menu, menu->current - menu->top - c_menu_context);
479}
+ 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,
int count )

Move the focus to the first entry in the menu.

Parameters
menuCurrent Menu
countJump to line N (1-based) if >0, otherwise go to first entry
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 425 of file move.c.

426{
427 if (menu->max == 0)
428 {
429 mutt_error(_("No entries"));
430 return MENU_REDRAW_NONE;
431 }
432
433 if (count > 0)
434 return menu_move_selection(menu, count - 1);
435
436 return menu_move_selection(menu, 0);
437}
+ 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,
int count )

Move the focus down half a page in the menu.

Parameters
menuCurrent Menu
countNumber of half-pages to move (0 = move by 1)
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 540 of file move.c.

541{
542 return menu_move_view_relative(menu, MAX(count, 1) * (menu->page_len / 2));
543}
#define MAX(a, b)
Return the maximum of two values.
Definition memory.h:38
+ 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,
int count )

Move the focus up half a page in the menu.

Parameters
menuCurrent Menu
countNumber of half-pages to move (0 = move by 1)
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 529 of file move.c.

530{
531 return menu_move_view_relative(menu, 0 - MAX(count, 1) * (menu->page_len / 2));
532}
+ 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,
int count )

Move the focus to the last entry in the menu.

Parameters
menuCurrent Menu
countJump to line N (1-based) if >0, otherwise go to last entry
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 445 of file move.c.

446{
447 if (menu->max == 0)
448 {
449 mutt_error(_("No entries"));
450 return MENU_REDRAW_NONE;
451 }
452
453 if (count > 0)
454 return menu_move_selection(menu, count - 1);
455
456 return menu_move_selection(menu, menu->max - 1);
457}
+ 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
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 349 of file move.c.

350{
351 if (menu->max == 0)
352 {
353 mutt_error(_("No entries"));
354 return MENU_REDRAW_NONE;
355 }
356
357 int i = menu->top + menu->page_len;
358 if (i > (menu->max - 1))
359 i = menu->max - 1;
360
361 return menu_move_selection(menu, menu->top + (i - menu->top) / 2);
362}
+ 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,
int count )

Move the focus to the next item in the menu.

Parameters
menuCurrent Menu
countNumber of entries to move (0 = move by 1, show warning at boundary)
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 407 of file move.c.

408{
409 if (count > 0)
410 return menu_move_selection(menu, menu->current + count);
411
412 if (menu->current < (menu->max - 1))
413 return menu_move_selection(menu, menu->current + 1);
414
415 mutt_message(_("You are on the last entry"));
416 return MENU_REDRAW_NONE;
417}
#define mutt_message(...)
Definition logging2.h:93
+ 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,
int count )

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

Parameters
menuCurrent Menu
countNumber of lines to scroll (0 = scroll by 1, show warning at boundary)
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 565 of file move.c.

566{
567 MenuRedrawFlags flags = menu_move_view_relative(menu, MAX(count, 1));
568 if ((count == 0) && (flags == MENU_REDRAW_NONE))
569 mutt_message(_("You can't scroll down farther"));
570 return flags;
571}
uint8_t MenuRedrawFlags
Definition lib.h:66
+ 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,
int count )

Move the focus to the next page in the menu.

Parameters
menuCurrent Menu
countNumber of pages to move (0 = move by 1)
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 590 of file move.c.

591{
592 return menu_move_view_relative(menu, MAX(count, 1) * menu->page_len);
593}
+ 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,
int count )

Move the focus to the previous item in the menu.

Parameters
menuCurrent Menu
countNumber of entries to move (0 = move by 1, show warning at boundary)
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 389 of file move.c.

390{
391 if (count > 0)
392 return menu_move_selection(menu, menu->current - count);
393
394 if (menu->current > 0)
395 return menu_move_selection(menu, menu->current - 1);
396
397 mutt_message(_("You are on the first entry"));
398 return MENU_REDRAW_NONE;
399}
+ 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,
int count )

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

Parameters
menuCurrent Menu
countNumber of lines to scroll (0 = scroll by 1, show warning at boundary)
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 551 of file move.c.

552{
553 MenuRedrawFlags flags = menu_move_view_relative(menu, 0 - MAX(count, 1));
554 if ((count == 0) && (flags == MENU_REDRAW_NONE))
555 mutt_message(_("You can't scroll up farther"));
556 return flags;
557}
+ 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,
int count )

Move the focus to the previous page in the menu.

Parameters
menuCurrent Menu
countNumber of pages to move (0 = move by 1)
Return values
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 579 of file move.c.

580{
581 return menu_move_view_relative(menu, 0 - MAX(count, 1) * menu->page_len);
582}
+ 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
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 339 of file move.c.

340{
341 return menu_move_selection(menu, menu->top);
342}
+ 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 464 of file draw.c.

465{
466 struct Buffer *buf = buf_pool_get();
467 const struct AttrColor *ac = menu->color(menu, menu->current);
468
469 mutt_window_move(menu->win, menu->current - menu->top, 0);
470 menu->make_entry(menu, menu->current, menu->win->state.cols, buf);
471 menu_pad_string(menu, buf);
472
473 struct AttrColor *ac_ind = menu->show_indicator ? simple_color_get(MT_COLOR_INDICATOR) : NULL;
474 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
475 if (c_arrow_cursor)
476 {
477 mutt_curses_set_color(ac_ind);
478 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
479 mutt_window_addstr(menu->win, c_arrow_string);
481 mutt_window_addch(menu->win, ' ');
482 menu_pad_string(menu, buf);
483 print_enriched_string(menu->win, menu->current, ac, NULL, buf, menu->sub);
484 }
485 else
486 {
487 print_enriched_string(menu->win, menu->current, ac, ac_ind, buf, menu->sub);
488 }
490 buf_pool_release(&buf);
491}
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition simple.c:98
@ 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:291
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
static void menu_pad_string(struct Menu *menu, struct Buffer *buf)
Pad a string with spaces for display in the Menu.
Definition draw.c:305
static void print_enriched_string(struct MuttWindow *win, int index, const struct AttrColor *ac_def, struct AttrColor *ac_ind, struct Buffer *buf, struct ConfigSubset *sub)
Display a string with embedded colours and graphics.
Definition draw.c:127
const struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the Colour ID.
Definition mutt_curses.c:79
void mutt_curses_set_color(const struct AttrColor *ac)
Set the colour and attributes for text.
Definition mutt_curses.c:38
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
int mutt_window_addstr(struct MuttWindow *win, const char *str)
Write a string to a Window.
int mutt_window_addch(struct MuttWindow *win, int ch)
Write one character to a Window.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
A curses colour and its attributes.
Definition attr.h:65
String manipulation buffer.
Definition buffer.h:36
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
const struct AttrColor *(* color)(struct Menu *menu, int line)
Definition lib.h:151
bool show_indicator
Show the Indicator colour.
Definition lib.h:93
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition lib.h:114
struct WindowState state
Current state of the Window.
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:60
+ 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 327 of file draw.c.

328{
330 mutt_window_clear(menu->win);
331
332 menu->page_len = menu->win->state.rows;
333
335}
void mutt_window_clear(struct MuttWindow *win)
Clear a Window.
MenuRedrawFlags redraw
When to redraw the screen.
Definition lib.h:89
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 341 of file draw.c.

342{
343 struct Buffer *buf = buf_pool_get();
344 const struct AttrColor *ac = NULL;
345
346 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
347 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
348 const int arrow_width = mutt_strwidth(c_arrow_string);
349 struct AttrColor *ac_ind = menu->show_indicator ? simple_color_get(MT_COLOR_INDICATOR) : NULL;
350 for (int i = menu->top; i < (menu->top + menu->page_len); i++)
351 {
352 if (i < menu->max)
353 {
354 ac = menu->color(menu, i);
355
356 buf_reset(buf);
357 menu->make_entry(menu, i, menu->win->state.cols, buf);
358 menu_pad_string(menu, buf);
359
361 mutt_window_move(menu->win, i - menu->top, 0);
362
363 if (i == menu->current)
364 mutt_curses_set_color(ac_ind);
365
366 if (c_arrow_cursor)
367 {
368 if (i == menu->current)
369 {
370 mutt_window_addstr(menu->win, c_arrow_string);
372 mutt_window_addch(menu->win, ' ');
373 }
374 else
375 {
376 /* Print space chars to match the screen width of `$arrow_string` */
377 mutt_window_printf(menu->win, "%*s", arrow_width + 1, "");
378 }
379 }
380
381 if ((i == menu->current) && !c_arrow_cursor)
382 {
383 print_enriched_string(menu->win, i, ac, ac_ind, buf, menu->sub);
384 }
385 else
386 {
387 print_enriched_string(menu->win, i, ac, NULL, buf, menu->sub);
388 }
389 }
390 else
391 {
393 mutt_window_clearline(menu->win, i - menu->top);
394 }
395 }
397 menu->redraw = MENU_REDRAW_NONE;
398 buf_pool_release(&buf);
399}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition curs_lib.c:446
int mutt_window_printf(struct MuttWindow *win, const char *fmt,...)
Write a formatted string to a Window.
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
+ 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 405 of file draw.c.

406{
407 struct Buffer *buf = buf_pool_get();
408
409 /* Note: menu->color() for the index can end up retrieving a message
410 * over imap (if matching against ~h for instance). This can
411 * generate status messages. So we want to call it *before* we
412 * position the cursor for drawing. */
413 const struct AttrColor *old_color = menu->color(menu, menu->old_current);
414 mutt_window_move(menu->win, menu->old_current - menu->top, 0);
415 mutt_curses_set_color(old_color);
416
417 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
418 struct AttrColor *ac_ind = menu->show_indicator ? simple_color_get(MT_COLOR_INDICATOR) : NULL;
419 if (c_arrow_cursor)
420 {
421 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
422 const int arrow_width = mutt_strwidth(c_arrow_string);
423 /* clear the arrow */
424 /* Print space chars to match the screen width of `$arrow_string` */
425 mutt_window_printf(menu->win, "%*s", arrow_width + 1, "");
427
428 menu->make_entry(menu, menu->old_current, menu->win->state.cols, buf);
429 menu_pad_string(menu, buf);
430 mutt_window_move(menu->win, menu->old_current - menu->top, arrow_width + 1);
431 print_enriched_string(menu->win, menu->old_current, old_color, NULL, buf, menu->sub);
432
433 /* now draw it in the new location */
434 mutt_curses_set_color(ac_ind);
435 mutt_window_move(menu->win, menu->current - menu->top, 0);
436 mutt_window_addstr(menu->win, c_arrow_string);
437 }
438 else
439 {
441 /* erase the current indicator */
442 menu->make_entry(menu, menu->old_current, menu->win->state.cols, buf);
443 menu_pad_string(menu, buf);
444 print_enriched_string(menu->win, menu->old_current, old_color, NULL, buf, menu->sub);
445
446 /* now draw the new one to reflect the change */
447 const struct AttrColor *cur_color = menu->color(menu, menu->current);
448 cur_color = merged_color_overlay(cur_color, ac_ind);
449 buf_reset(buf);
450 menu->make_entry(menu, menu->current, menu->win->state.cols, buf);
451 menu_pad_string(menu, buf);
452 mutt_window_move(menu->win, menu->current - menu->top, 0);
453 mutt_curses_set_color(cur_color);
454 print_enriched_string(menu->win, menu->current, cur_color, ac_ind, buf, menu->sub);
455 }
457 buf_pool_release(&buf);
458}
const struct AttrColor * merged_color_overlay(const struct AttrColor *base, const struct AttrColor *over)
Combine two colours.
Definition merged.c:110
int old_current
For driver use only.
Definition lib.h:99
+ 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 499 of file draw.c.

500{
501 /* See if all or part of the screen needs to be updated. */
502 if (menu->redraw & MENU_REDRAW_FULL)
503 menu_redraw_full(menu);
504
505 if (menu->redraw & MENU_REDRAW_INDEX)
506 menu_redraw_index(menu);
507 else if (menu->redraw & MENU_REDRAW_MOTION)
508 menu_redraw_motion(menu);
509 else if (menu->redraw == MENU_REDRAW_CURRENT)
511
512 return OP_NULL;
513}
void menu_redraw_current(struct Menu *menu)
Redraw the current menu.
Definition draw.c:464
void menu_redraw_index(struct Menu *menu)
Force the redraw of the index.
Definition draw.c:341
void menu_redraw_full(struct Menu *menu)
Force the redraw of the Menu.
Definition draw.c:327
void menu_redraw_motion(struct Menu *menu)
Force the redraw of the list part of the menu.
Definition draw.c:405
+ Here is the call graph for this function:
+ 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 82 of file menu.c.

83{
84 struct MuttWindow *win = window_get_focus();
85
86 // This should only happen before the first window is created
87 if (!win)
88 return MENU_INDEX;
89
90 if ((win->type == WT_CUSTOM) && (win->parent->type == WT_PAGER))
91 return MENU_PAGER;
92
93 if (win->type != WT_MENU)
94 return MENU_GENERIC;
95
96 struct Menu *menu = win->wdata;
97 if (!menu)
98 return MENU_GENERIC;
99
100 return menu->md->id;
101}
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
@ WT_CUSTOM
Window with a custom drawing function.
Definition mutt_window.h:95
@ WT_PAGER
A panel containing the Pager Window.
@ WT_MENU
An Window containing a Menu.
Definition mutt_window.h:98
int id
Menu ID, e.g. MENU_ALIAS.
Definition menu.h:78
Definition lib.h:86
const struct MenuDefinition * md
Menu definition for keymap entries.
Definition lib.h:90
void * wdata
Private data.
struct MuttWindow * parent
Parent Window.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
@ MENU_INDEX
Index panel (list of emails)
Definition type.h:44
@ MENU_GENERIC
Generic selection list.
Definition type.h:43
@ MENU_PAGER
Pager pager (email viewer)
Definition type.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_init2()

void menu_init2 ( char ** search_buffers)

Initialise all the Menus.

Parameters
search_buffersArray of search buffer pointers to initialise

Definition at line 72 of file menu.c.

73{
74 for (int i = 0; i < MENU_MAX; i++)
75 search_buffers[i] = NULL;
76}
@ MENU_MAX
Definition type.h:52
+ Here is the caller graph for this function:

◆ menu_window_new()

struct MuttWindow * menu_window_new ( const struct MenuDefinition * md,
struct ConfigSubset * sub )

Create a new Menu Window.

Parameters
mdMenu Definition
subConfig items
Return values
ptrNew MuttWindow wrapping a Menu

Definition at line 140 of file window.c.

141{
145
146 struct Menu *menu = menu_new(md, win, sub);
147
150 win->wdata = menu;
152
153 return win;
154}
static int menu_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition window.c:81
static int menu_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition window.c:94
static void menu_wdata_free(struct MuttWindow *win, void **ptr)
Free the Menu - Implements MuttWindow::wdata_free() -.
Definition window.c:129
struct Menu * menu_new(const struct MenuDefinition *md, struct MuttWindow *win, struct ConfigSubset *sub)
Create a new Menu.
Definition menu.c:129
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
@ 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)
int(* recalc)(struct MuttWindow *win)
void(* wdata_free)(struct MuttWindow *win, void **ptr)
+ 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 155 of file menu.c.

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

◆ 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
enumMenuRedrawFlags, e.g. MENU_REDRAW_INDEX

Definition at line 169 of file menu.c.

170{
171 return menu_move_selection(menu, index);
172}
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:

◆ 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
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 236 of file move.c.

237{
238 if (menu->max == 0)
239 return MENU_REDRAW_NONE;
240
241 if (index < 0)
242 index = 0;
243 else if (index >= menu->max)
244 index = menu->max - 1;
245
246 int top = menu_drag_view(menu, menu->top, index);
247
248 return menu_set_and_notify(menu, top, index);
249}
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 179 of file menu.c.

180{
181 if (!menu)
182 return;
183
184 menu->redraw |= redraw;
185 menu->win->actions |= WA_RECALC;
186}
@ WA_RECALC
Recalculate the contents of the Window.
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.

◆ 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
enumMenuRedrawFlags, e.g. MENU_REDRAW_CURRENT

Definition at line 257 of file move.c.

258{
259 if (menu->max <= menu->page_len)
260 return menu_move_selection(menu, menu->current + relative);
261
262 const bool c_menu_move_off = cs_subset_bool(menu->sub, "menu_move_off");
263
264 short c_menu_context = cs_subset_number(menu->sub, "menu_context");
265 c_menu_context = MIN(c_menu_context, (menu->page_len / 2));
266
267 // Move and range-check the view
268 int top = menu->top + relative;
269 if (top < 0)
270 {
271 top = 0;
272 }
273 else if (c_menu_move_off && (top >= (menu->max - c_menu_context)))
274 {
275 top = menu->max - c_menu_context - 1;
276 }
277 else if (!c_menu_move_off && ((top + menu->page_len) >= menu->max))
278 {
279 top = menu->max - menu->page_len;
280 }
281 if (top < 0)
282 top = 0;
283
284 // Move the selection on-screen
285 int index = menu->current;
286 if (index < top)
287 index = top;
288 else if (index >= (top + menu->page_len))
289 index = top + menu->page_len - 1;
290
291 // Check for top/bottom limits
292 if (index < c_menu_context)
293 {
294 top = 0;
295 index = menu->current;
296 }
297 else if (!c_menu_move_off && (index > (menu->max - c_menu_context)))
298 {
299 top = menu->max - menu->page_len;
300 index = menu->current;
301 }
302
303 if (top == menu->top)
304 {
305 // Can't move the view; move the selection
306 index = calc_fit_selection_to_view(menu, top, index + relative);
307 }
308 else if (index > (top + menu->page_len - c_menu_context - 1))
309 {
310 index = calc_fit_selection_to_view(menu, top, index + relative);
311 }
312 else
313 {
314 // Drag the selection into the view
315 index = calc_fit_selection_to_view(menu, top, index);
316 }
317
318 return menu_set_and_notify(menu, top, index);
319}
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
enumMenuRedrawFlags, 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_NONE)
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_NONE)
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 logging2.h:91
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:50
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition notify.c:173
@ WA_REPAINT
Redraw the contents of the Window.
@ NT_MENU
Menu has changed, MenuRedrawFlags.
Definition notify_type.h:52
struct Notify * notify
Notifications.
Definition lib.h:153
+ 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 325 of file move.c.

326{
327 int top = calc_move_view(menu, 0);
328 top = menu_drag_view(menu, top, menu->current);
329
330 menu_set_and_notify(menu, top, menu->current);
331}
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: