NeoMutt  2025-12-11-980-ge38c27
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
window.c
Go to the documentation of this file.
1
22
67
68#include "config.h"
69#include <stdbool.h>
70#include "private.h"
71#include "mutt/lib.h"
72#include "config/lib.h"
73#include "gui/lib.h"
74#include "lib.h"
75
76struct MenuDefinition;
77
81static int menu_recalc(struct MuttWindow *win)
82{
83 if (win->type != WT_MENU)
84 return 0;
85
86 win->actions |= WA_REPAINT;
87 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
88 return 0;
89}
90
94static int menu_repaint(struct MuttWindow *win)
95{
96 if (win->type != WT_MENU)
97 return 0;
98
99 struct Menu *menu = win->wdata;
100 menu->redraw |= MENU_REDRAW_FULL;
101 menu_redraw(menu);
102 menu->redraw = MENU_REDRAW_NONE;
103
104 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
105 const bool c_braille_friendly = cs_subset_bool(menu->sub, "braille_friendly");
106
107 /* move the cursor out of the way */
108 if (c_arrow_cursor)
109 {
110 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
111 const int arrow_width = mutt_strwidth(c_arrow_string);
112 mutt_window_move(menu->win, menu->current - menu->top, arrow_width);
113 }
114 else if (c_braille_friendly)
115 {
116 mutt_window_move(menu->win, menu->current - menu->top, 0);
117 }
118 else
119 {
120 mutt_window_move(menu->win, menu->current - menu->top, menu->win->state.cols - 1);
121 }
122
123 mutt_debug(LL_DEBUG5, "repaint done\n");
124 return 0;
125}
126
130static void menu_wdata_free(struct MuttWindow *win, void **ptr)
131{
132 menu_free((struct Menu **) ptr);
133}
134
141struct MuttWindow *menu_window_new(const struct MenuDefinition *md, struct ConfigSubset *sub)
142{
146
147 struct Menu *menu = menu_new(md, win, sub);
148
151 win->wdata = menu;
153
154 return win;
155}
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
Convenience wrapper for the config headers.
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition curs_lib.c:449
int menu_redraw(struct Menu *menu)
Redraw the parts of the screen that have been flagged to be redrawn.
Definition draw.c:486
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
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:130
Convenience wrapper for the gui headers.
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
GUI present the user with a selectable list.
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
@ MENU_REDRAW_NONE
No flags are set.
Definition lib.h:60
struct Menu * menu_new(const struct MenuDefinition *md, struct MuttWindow *win, struct ConfigSubset *sub)
Create a new Menu.
Definition menu.c:127
void menu_free(struct Menu **ptr)
Free a Menu.
Definition menu.c:105
Private Menu functions.
struct MuttWindow * menu_window_new(const struct MenuDefinition *md, struct ConfigSubset *sub)
Create a new Menu Window.
Definition window.c:141
Convenience wrapper for the library headers.
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
@ WT_MENU
An Window containing a Menu.
Definition mutt_window.h:98
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition mutt_window.h:38
@ WA_REPAINT
Redraw the contents of the Window.
#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
A set of inherited config items.
Definition subset.h:46
Functions for a Dialog or Window.
Definition menudef.h:44
Definition lib.h:86
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
int current
Current entry.
Definition lib.h:87
MenuRedrawFlags redraw
When to redraw the screen.
Definition lib.h:89
int top
Entry that is the top of the current page.
Definition lib.h:98
const struct MenuDefinition * md
Menu definition for keymap entries.
Definition lib.h:90
struct ConfigSubset * sub
Inherited config items.
Definition lib.h:95
int(* repaint)(struct MuttWindow *win)
struct WindowState state
Current state of the Window.
void * wdata
Private data.
int(* recalc)(struct MuttWindow *win)
void(* wdata_free)(struct MuttWindow *win, void **ptr)
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:60