NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
mutt_window.h File Reference

Window management. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include "mutt/lib.h"
+ Include dependency graph for mutt_window.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  WindowState
 The current, or old, state of a Window. More...
 
struct  MuttWindow
 
struct  EventWindow
 An Event that happened to a Window. More...
 

Macros

#define MUTT_WIN_SIZE_UNLIMITED   -1
 Use as much space as possible. More...
 
#define WA_NO_FLAGS   0
 No flags are set. More...
 
#define WA_REFLOW   (1 << 0)
 Reflow the Window and its children. More...
 
#define WA_RECALC   (1 << 1)
 Recalculate the contents of the Window. More...
 
#define WA_REPAINT   (1 << 2)
 Redraw the contents of the Window. More...
 
#define WN_NO_FLAGS   0
 No flags are set. More...
 
#define WN_TALLER   (1 << 0)
 Window became taller. More...
 
#define WN_SHORTER   (1 << 1)
 Window became shorter. More...
 
#define WN_WIDER   (1 << 2)
 Window became wider. More...
 
#define WN_NARROWER   (1 << 3)
 Window became narrower. More...
 
#define WN_MOVED   (1 << 4)
 Window moved. More...
 
#define WN_VISIBLE   (1 << 5)
 Window became visible. More...
 
#define WN_HIDDEN   (1 << 6)
 Window became hidden. More...
 

Typedefs

typedef uint8_t WindowActionFlags
 Flags for Actions waiting to be performed on a MuttWindow, e.g. WA_REFLOW. More...
 
typedef uint8_t WindowNotifyFlags
 Flags for Changes to a MuttWindow, e.g. WN_TALLER. More...
 

Enumerations

enum  MuttWindowOrientation { MUTT_WIN_ORIENT_VERTICAL = 1 , MUTT_WIN_ORIENT_HORIZONTAL }
 Which way does the Window expand? More...
 
enum  MuttWindowSize { MUTT_WIN_SIZE_FIXED = 1 , MUTT_WIN_SIZE_MAXIMISE , MUTT_WIN_SIZE_MINIMISE }
 Control the allocation of Window space. More...
 
enum  WindowType {
  WT_ROOT , WT_CONTAINER , WT_ALL_DIALOGS , WT_DLG_ALIAS ,
  WT_DLG_ATTACH , WT_DLG_AUTOCRYPT , WT_DLG_BROWSER , WT_DLG_CERTIFICATE ,
  WT_DLG_COMPOSE , WT_DLG_CRYPT_GPGME , WT_DLG_DO_PAGER , WT_DLG_HISTORY ,
  WT_DLG_INDEX , WT_DLG_PATTERN , WT_DLG_PGP , WT_DLG_POSTPONE ,
  WT_DLG_QUERY , WT_DLG_REMAILER , WT_DLG_SMIME , WT_CUSTOM ,
  WT_HELP_BAR , WT_INDEX , WT_MENU , WT_MESSAGE ,
  WT_PAGER , WT_SIDEBAR , WT_STATUS_BAR
}
 Type of Window. More...
 
enum  NotifyWindow {
  NT_WINDOW_ADD = 1 , NT_WINDOW_DELETE , NT_WINDOW_STATE , NT_WINDOW_DIALOG ,
  NT_WINDOW_FOCUS
}
 Window notification types. More...
 

Functions

 TAILQ_HEAD (MuttWindowList, MuttWindow)
 
void mutt_window_add_child (struct MuttWindow *parent, struct MuttWindow *child)
 Add a child to Window. More...
 
void mutt_window_free (struct MuttWindow **ptr)
 Free a Window and its children. More...
 
void mutt_window_get_coords (struct MuttWindow *win, int *col, int *row)
 Get the cursor position in the Window. More...
 
struct MuttWindowmutt_window_new (enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
 Create a new Window. More...
 
void mutt_window_reflow (struct MuttWindow *win)
 Resize a Window and its children. More...
 
struct MuttWindowmutt_window_remove_child (struct MuttWindow *parent, struct MuttWindow *child)
 Remove a child from a Window. More...
 
int mutt_window_wrap_cols (int width, short wrap)
 Calculate the wrap column for a given screen width. More...
 
int mutt_window_addch (struct MuttWindow *win, int ch)
 Write one character to a Window. More...
 
int mutt_window_addnstr (struct MuttWindow *win, const char *str, int num)
 Write a partial string to a Window. More...
 
int mutt_window_addstr (struct MuttWindow *win, const char *str)
 Write a string to a Window. More...
 
void mutt_window_clearline (struct MuttWindow *win, int row)
 Clear a row of a Window. More...
 
void mutt_window_clear (struct MuttWindow *win)
 Clear a Window. More...
 
void mutt_window_clrtoeol (struct MuttWindow *win)
 Clear to the end of the line. More...
 
int mutt_window_move (struct MuttWindow *win, int col, int row)
 Move the cursor in a Window. More...
 
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. More...
 
int mutt_window_mvprintw (struct MuttWindow *win, int col, int row, const char *fmt,...)
 Move the cursor and write a formatted string to a Window. More...
 
int mutt_window_printf (struct MuttWindow *win, const char *format,...)
 Write a formatted string to a Window. More...
 
bool mutt_window_is_visible (struct MuttWindow *win)
 Is the Window visible? More...
 
void mutt_winlist_free (struct MuttWindowList *head)
 Free a tree of Windows. More...
 
struct MuttWindowwindow_find_child (struct MuttWindow *win, enum WindowType type)
 Recursively find a child Window of a given type. More...
 
struct MuttWindowwindow_find_parent (struct MuttWindow *win, enum WindowType type)
 Find a (grand-)parent of a Window by type. More...
 
void window_notify_all (struct MuttWindow *win)
 Notify observers of changes to a Window and its children. More...
 
void window_set_visible (struct MuttWindow *win, bool visible)
 Set a Window visible or hidden. More...
 
struct MuttWindowwindow_set_focus (struct MuttWindow *win)
 Set the Window focus. More...
 
struct MuttWindowwindow_get_focus (void)
 Get the currently focused Window. More...
 
bool window_is_focused (const struct MuttWindow *win)
 Does the given Window have the focus? More...
 
void window_redraw (struct MuttWindow *win)
 Reflow, recalc and repaint a tree of Windows. More...
 
void window_invalidate_all (void)
 Mark all windows as in need of repaint. More...
 
const char * mutt_window_win_name (const struct MuttWindow *win)
 Get the name of a Window. More...
 
bool window_status_on_top (struct MuttWindow *panel, struct ConfigSubset *sub)
 Organise windows according to config variable. More...
 

Detailed Description

Window management.

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 mutt_window.h.

Macro Definition Documentation

◆ MUTT_WIN_SIZE_UNLIMITED

#define MUTT_WIN_SIZE_UNLIMITED   -1

Use as much space as possible.

Definition at line 52 of file mutt_window.h.

◆ WA_NO_FLAGS

#define WA_NO_FLAGS   0

No flags are set.

Definition at line 108 of file mutt_window.h.

◆ WA_REFLOW

#define WA_REFLOW   (1 << 0)

Reflow the Window and its children.

Definition at line 109 of file mutt_window.h.

◆ WA_RECALC

#define WA_RECALC   (1 << 1)

Recalculate the contents of the Window.

Definition at line 110 of file mutt_window.h.

◆ WA_REPAINT

#define WA_REPAINT   (1 << 2)

Redraw the contents of the Window.

Definition at line 111 of file mutt_window.h.

◆ WN_NO_FLAGS

#define WN_NO_FLAGS   0

No flags are set.

Definition at line 185 of file mutt_window.h.

◆ WN_TALLER

#define WN_TALLER   (1 << 0)

Window became taller.

Definition at line 186 of file mutt_window.h.

◆ WN_SHORTER

#define WN_SHORTER   (1 << 1)

Window became shorter.

Definition at line 187 of file mutt_window.h.

◆ WN_WIDER

#define WN_WIDER   (1 << 2)

Window became wider.

Definition at line 188 of file mutt_window.h.

◆ WN_NARROWER

#define WN_NARROWER   (1 << 3)

Window became narrower.

Definition at line 189 of file mutt_window.h.

◆ WN_MOVED

#define WN_MOVED   (1 << 4)

Window moved.

Definition at line 190 of file mutt_window.h.

◆ WN_VISIBLE

#define WN_VISIBLE   (1 << 5)

Window became visible.

Definition at line 191 of file mutt_window.h.

◆ WN_HIDDEN

#define WN_HIDDEN   (1 << 6)

Window became hidden.

Definition at line 192 of file mutt_window.h.

Typedef Documentation

◆ WindowActionFlags

typedef uint8_t WindowActionFlags

Flags for Actions waiting to be performed on a MuttWindow, e.g. WA_REFLOW.

Definition at line 107 of file mutt_window.h.

◆ WindowNotifyFlags

typedef uint8_t WindowNotifyFlags

Flags for Changes to a MuttWindow, e.g. WN_TALLER.

Definition at line 184 of file mutt_window.h.

Enumeration Type Documentation

◆ MuttWindowOrientation

Which way does the Window expand?

Enumerator
MUTT_WIN_ORIENT_VERTICAL 

Window uses all available vertical space.

MUTT_WIN_ORIENT_HORIZONTAL 

Window uses all available horizontal space.

Definition at line 36 of file mutt_window.h.

37{
40};
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
@ MUTT_WIN_ORIENT_HORIZONTAL
Window uses all available horizontal space.
Definition: mutt_window.h:39

◆ MuttWindowSize

Control the allocation of Window space.

Enumerator
MUTT_WIN_SIZE_FIXED 

Window has a fixed size.

MUTT_WIN_SIZE_MAXIMISE 

Window wants as much space as possible.

MUTT_WIN_SIZE_MINIMISE 

Window size depends on its children.

Definition at line 45 of file mutt_window.h.

46{
50};
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:47
@ MUTT_WIN_SIZE_MINIMISE
Window size depends on its children.
Definition: mutt_window.h:49
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:48

◆ WindowType

enum WindowType

Type of Window.

Enumerator
WT_ROOT 

Parent of All Windows.

WT_CONTAINER 

Invisible shaping container Window.

WT_ALL_DIALOGS 

Container for All Dialogs (nested Windows)

WT_DLG_ALIAS 

Alias Dialog, dlg_select_alias()

WT_DLG_ATTACH 

Attach Dialog, dlg_select_attachment()

WT_DLG_AUTOCRYPT 

Autocrypt Dialog, dlg_select_autocrypt_account()

WT_DLG_BROWSER 

Browser Dialog, buf_select_file()

WT_DLG_CERTIFICATE 

Certificate Dialog, dlg_verify_certificate()

WT_DLG_COMPOSE 

Compose Dialog, mutt_compose_menu()

WT_DLG_CRYPT_GPGME 

Crypt-GPGME Dialog, dlg_select_gpgme_key()

WT_DLG_DO_PAGER 

Pager Dialog, mutt_do_pager()

WT_DLG_HISTORY 

History Dialog, dlg_select_history()

WT_DLG_INDEX 

Index Dialog, index_pager_init()

WT_DLG_PATTERN 

Pattern Dialog, create_pattern_menu()

WT_DLG_PGP 

Pgp Dialog, dlg_select_pgp_key()

WT_DLG_POSTPONE 

Postpone Dialog, dlg_select_postponed_email()

WT_DLG_QUERY 

Query Dialog, dlg_select_query()

WT_DLG_REMAILER 

Remailer Dialog, dlg_mixmaster()

WT_DLG_SMIME 

Smime Dialog, dlg_select_smime_key()

WT_CUSTOM 

Window with a custom drawing function.

WT_HELP_BAR 

Help Bar containing list of useful key bindings.

WT_INDEX 

A panel containing the Index Window.

WT_MENU 

An Window containing a Menu.

WT_MESSAGE 

Window for messages/errors and command entry.

WT_PAGER 

A panel containing the Pager Window.

WT_SIDEBAR 

Side panel containing Accounts or groups of data.

WT_STATUS_BAR 

Status Bar containing extra info about the Index/Pager/etc.

Definition at line 69 of file mutt_window.h.

70{
71 // Structural Windows
72 WT_ROOT,
75
76 // Dialogs (nested Windows) displayed to the user
93
94 // Common Windows
95 WT_CUSTOM,
97 WT_INDEX,
98 WT_MENU,
100 WT_PAGER,
101 WT_SIDEBAR,
103};
@ WT_DLG_REMAILER
Remailer Dialog, dlg_mixmaster()
Definition: mutt_window.h:91
@ WT_CUSTOM
Window with a custom drawing function.
Definition: mutt_window.h:95
@ WT_ROOT
Parent of All Windows.
Definition: mutt_window.h:72
@ WT_DLG_ALIAS
Alias Dialog, dlg_select_alias()
Definition: mutt_window.h:77
@ WT_ALL_DIALOGS
Container for All Dialogs (nested Windows)
Definition: mutt_window.h:74
@ WT_DLG_BROWSER
Browser Dialog, buf_select_file()
Definition: mutt_window.h:80
@ WT_MESSAGE
Window for messages/errors and command entry.
Definition: mutt_window.h:99
@ WT_DLG_SMIME
Smime Dialog, dlg_select_smime_key()
Definition: mutt_window.h:92
@ WT_DLG_QUERY
Query Dialog, dlg_select_query()
Definition: mutt_window.h:90
@ WT_DLG_HISTORY
History Dialog, dlg_select_history()
Definition: mutt_window.h:85
@ WT_DLG_PGP
Pgp Dialog, dlg_select_pgp_key()
Definition: mutt_window.h:88
@ WT_CONTAINER
Invisible shaping container Window.
Definition: mutt_window.h:73
@ WT_DLG_CERTIFICATE
Certificate Dialog, dlg_verify_certificate()
Definition: mutt_window.h:81
@ WT_DLG_COMPOSE
Compose Dialog, mutt_compose_menu()
Definition: mutt_window.h:82
@ WT_DLG_INDEX
Index Dialog, index_pager_init()
Definition: mutt_window.h:86
@ WT_PAGER
A panel containing the Pager Window.
Definition: mutt_window.h:100
@ WT_DLG_CRYPT_GPGME
Crypt-GPGME Dialog, dlg_select_gpgme_key()
Definition: mutt_window.h:83
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ WT_HELP_BAR
Help Bar containing list of useful key bindings.
Definition: mutt_window.h:96
@ WT_DLG_POSTPONE
Postpone Dialog, dlg_select_postponed_email()
Definition: mutt_window.h:89
@ WT_INDEX
A panel containing the Index Window.
Definition: mutt_window.h:97
@ WT_DLG_ATTACH
Attach Dialog, dlg_select_attachment()
Definition: mutt_window.h:78
@ WT_SIDEBAR
Side panel containing Accounts or groups of data.
Definition: mutt_window.h:101
@ WT_DLG_DO_PAGER
Pager Dialog, mutt_do_pager()
Definition: mutt_window.h:84
@ WT_DLG_AUTOCRYPT
Autocrypt Dialog, dlg_select_autocrypt_account()
Definition: mutt_window.h:79
@ WT_MENU
An Window containing a Menu.
Definition: mutt_window.h:98
@ WT_DLG_PATTERN
Pattern Dialog, create_pattern_menu()
Definition: mutt_window.h:87

◆ NotifyWindow

Window notification types.

Observers of NT_WINDOW will be passed an EventWindow.

Note
Delete notifications are sent before the object is deleted.
Other notifications are sent after the event.
Enumerator
NT_WINDOW_ADD 

New Window has been added.

NT_WINDOW_DELETE 

Window is about to be deleted.

NT_WINDOW_STATE 

Window state has changed, e.g. WN_VISIBLE.

NT_WINDOW_DIALOG 

A new Dialog Window has been created, e.g. WT_DLG_INDEX.

NT_WINDOW_FOCUS 

Window focus has changed.

Definition at line 202 of file mutt_window.h.

203{
204 NT_WINDOW_ADD = 1,
209};
@ NT_WINDOW_DIALOG
A new Dialog Window has been created, e.g. WT_DLG_INDEX.
Definition: mutt_window.h:207
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:206
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:205
@ NT_WINDOW_FOCUS
Window focus has changed.
Definition: mutt_window.h:208
@ NT_WINDOW_ADD
New Window has been added.
Definition: mutt_window.h:204

Function Documentation

◆ TAILQ_HEAD()

TAILQ_HEAD ( MuttWindowList  ,
MuttWindow   
)

◆ mutt_window_add_child()

void mutt_window_add_child ( struct MuttWindow parent,
struct MuttWindow child 
)

Add a child to Window.

Parameters
parentWindow to add to
childWindow to add

Definition at line 440 of file mutt_window.c.

441{
442 if (!parent || !child)
443 return;
444
445 TAILQ_INSERT_TAIL(&parent->children, child, entries);
446 child->parent = parent;
447
448 notify_set_parent(child->notify, parent->notify);
449
450 mutt_debug(LL_NOTIFY, "NT_WINDOW_NEW: %s, %p\n", mutt_window_win_name(child), child);
451 struct EventWindow ev_w = { child, WN_NO_FLAGS };
452 notify_send(child->notify, NT_WINDOW, NT_WINDOW_ADD, &ev_w);
453}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
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
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:711
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:185
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
An Event that happened to a Window.
Definition: mutt_window.h:215
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_free()

void mutt_window_free ( struct MuttWindow **  ptr)

Free a Window and its children.

Parameters
ptrWindow to free

Definition at line 200 of file mutt_window.c.

201{
202 if (!ptr || !*ptr)
203 return;
204
205 struct MuttWindow *win = *ptr;
206
207 if (win->parent && (win->parent->focus == win))
208 win->parent->focus = NULL;
209
210 mutt_debug(LL_NOTIFY, "NT_WINDOW_DELETE: %s, %p\n", mutt_window_win_name(win), win);
211 struct EventWindow ev_w = { win, WN_NO_FLAGS };
213
215
216 if (win->wdata_free && win->wdata)
217 win->wdata_free(win, &win->wdata); // Custom function to free private data
218
220
221 FREE(ptr);
222}
#define FREE(x)
Definition: memory.h:43
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
void mutt_winlist_free(struct MuttWindowList *head)
Free a tree of Windows.
Definition: mutt_window.c:479
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:216
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_get_coords()

void mutt_window_get_coords ( struct MuttWindow win,
int *  col,
int *  row 
)

Get the cursor position in the Window.

Parameters
[in]winWindow
[out]colColumn in Window
[out]rowRow in Window

Assumes the current position is inside the window. Otherwise it will happily return negative or values outside the window boundaries

Definition at line 274 of file mutt_window.c.

275{
276 int x = 0;
277 int y = 0;
278
279 getyx(stdscr, y, x);
280 if (col)
281 *col = x - win->state.col_offset;
282 if (row)
283 *row = y - win->state.row_offset;
284}
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:63
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:62
+ Here is the caller graph for this function:

◆ mutt_window_new()

struct MuttWindow * mutt_window_new ( enum WindowType  type,
enum MuttWindowOrientation  orient,
enum MuttWindowSize  size,
int  cols,
int  rows 
)

Create a new Window.

Parameters
typeWindow type, e.g. WT_ROOT
orientWindow orientation, e.g. MUTT_WIN_ORIENT_VERTICAL
sizeWindow size, e.g. MUTT_WIN_SIZE_MAXIMISE
colsInitial number of columns to allocate, can be MUTT_WIN_SIZE_UNLIMITED
rowsInitial number of rows to allocate, can be MUTT_WIN_SIZE_UNLIMITED
Return values
ptrNew Window

Definition at line 180 of file mutt_window.c.

182{
183 struct MuttWindow *win = mutt_mem_calloc(1, sizeof(struct MuttWindow));
184
185 win->type = type;
186 win->orient = orient;
187 win->size = size;
188 win->req_rows = rows;
189 win->req_cols = cols;
190 win->state.visible = true;
191 win->notify = notify_new();
192 TAILQ_INIT(&win->children);
193 return win;
194}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:60
#define TAILQ_INIT(head)
Definition: queue.h:765
short req_cols
Number of columns required.
Definition: mutt_window.h:124
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:130
short req_rows
Number of rows required.
Definition: mutt_window.h:125
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
bool visible
Window is visible.
Definition: mutt_window.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_reflow()

void mutt_window_reflow ( struct MuttWindow win)

Resize a Window and its children.

Parameters
winWindow to resize

Definition at line 341 of file mutt_window.c.

342{
343 if (OptNoCurses)
344 return;
345
346 if (!win)
347 win = RootWindow;
348
349 mutt_debug(LL_DEBUG2, "entering\n");
350 window_reflow(win);
352
353#ifdef USE_DEBUG_WINDOW
355#endif
356}
void debug_win_dump(void)
Definition: window.c:78
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:82
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:143
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:220
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_remove_child()

struct MuttWindow * mutt_window_remove_child ( struct MuttWindow parent,
struct MuttWindow child 
)

Remove a child from a Window.

Parameters
parentWindow to remove from
childWindow to remove
Return values
ptrChild Window

Definition at line 461 of file mutt_window.c.

462{
463 if (!parent || !child)
464 return NULL;
465
466 // A notification will be sent when the Window is freed
467 TAILQ_REMOVE(&parent->children, child, entries);
468 child->parent = NULL;
469
470 notify_set_parent(child->notify, NULL);
471
472 return child;
473}
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_wrap_cols()

int mutt_window_wrap_cols ( int  width,
short  wrap 
)

Calculate the wrap column for a given screen width.

Parameters
widthScreen width
wrapWrap config
Return values
numColumn that text should be wrapped at

The wrap variable can be negative, meaning there should be a right margin.

Definition at line 366 of file mutt_window.c.

367{
368 if (wrap < 0)
369 return (width > -wrap) ? (width + wrap) : width;
370 if (wrap)
371 return (wrap < width) ? wrap : width;
372 return width;
373}
+ Here is the caller graph for this function:

◆ mutt_window_addch()

int mutt_window_addch ( struct MuttWindow win,
int  ch 
)

Write one character to a Window.

Parameters
winWindow
chCharacter to write
Return values
0Success
-1Error

Definition at line 382 of file mutt_window.c.

383{
384 return addch(ch);
385}
+ Here is the caller graph for this function:

◆ mutt_window_addnstr()

int mutt_window_addnstr ( struct MuttWindow win,
const char *  str,
int  num 
)

Write a partial string to a Window.

Parameters
winWindow
strString
numMaximum number of characters to write
Return values
0Success
-1Error

Definition at line 395 of file mutt_window.c.

396{
397 if (!str)
398 return -1;
399
400 return addnstr(str, num);
401}
+ Here is the caller graph for this function:

◆ mutt_window_addstr()

int mutt_window_addstr ( struct MuttWindow win,
const char *  str 
)

Write a string to a Window.

Parameters
winWindow
strString
Return values
0Success
-1Error

Definition at line 410 of file mutt_window.c.

411{
412 if (!str)
413 return -1;
414
415 return addstr(str);
416}
+ Here is the caller graph for this function:

◆ mutt_window_clearline()

void mutt_window_clearline ( struct MuttWindow win,
int  row 
)

Clear a row of a Window.

Parameters
winWindow
rowRow to clear

Definition at line 229 of file mutt_window.c.

230{
231 mutt_window_move(win, 0, row);
233}
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:294
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:241
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_clear()

void mutt_window_clear ( struct MuttWindow win)

Clear a Window.

Parameters
winWindow

If the Window isn't visible, it won't be cleared.

Definition at line 696 of file mutt_window.c.

697{
698 if (!mutt_window_is_visible(win))
699 return;
700
701 for (int i = 0; i < win->state.rows; i++)
702 mutt_window_clearline(win, i);
703}
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:502
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:229
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:

◆ mutt_window_clrtoeol()

void mutt_window_clrtoeol ( struct MuttWindow win)

Clear to the end of the line.

Parameters
winWindow
Note
Assumes the cursor has already been positioned within the window.

Definition at line 241 of file mutt_window.c.

242{
243 if (!win || !stdscr)
244 return;
245
246 if ((win->state.col_offset + win->state.cols) == COLS)
247 {
248 clrtoeol();
249 }
250 else
251 {
252 int row = 0;
253 int col = 0;
254 getyx(stdscr, row, col);
255 int curcol = col;
256 while (curcol < (win->state.col_offset + win->state.cols))
257 {
258 addch(' ');
259 curcol++;
260 }
261 move(row, col);
262 }
263}
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
+ Here is the caller graph for this function:

◆ mutt_window_move()

int mutt_window_move ( struct MuttWindow win,
int  col,
int  row 
)

Move the cursor in a Window.

Parameters
winWindow
colColumn to move to
rowRow to move to
Return values
OKSuccess
ERRError

Definition at line 294 of file mutt_window.c.

295{
296 return move(win->state.row_offset + row, win->state.col_offset + col);
297}
+ Here is the caller graph for this function:

◆ mutt_window_mvaddstr()

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.

Parameters
winWindow to write to
colColumn to move to
rowRow to move to
strString to write
Return values
OKSuccess
ERRError

Definition at line 308 of file mutt_window.c.

309{
310 return mvaddstr(win->state.row_offset + row, win->state.col_offset + col, str);
311}
+ Here is the caller graph for this function:

◆ mutt_window_mvprintw()

int mutt_window_mvprintw ( struct MuttWindow win,
int  col,
int  row,
const char *  fmt,
  ... 
)

Move the cursor and write a formatted string to a Window.

Parameters
winWindow to write to
colColumn to move to
rowRow to move to
fmtprintf format string
...printf arguments
Return values
numSuccess, characters written
ERRError, move failed

Definition at line 323 of file mutt_window.c.

324{
325 int rc = mutt_window_move(win, col, row);
326 if (rc == ERR)
327 return rc;
328
329 va_list ap;
330 va_start(ap, fmt);
331 rc = vw_printw(stdscr, fmt, ap);
332 va_end(ap);
333
334 return rc;
335}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_printf()

int mutt_window_printf ( struct MuttWindow win,
const char *  fmt,
  ... 
)

Write a formatted string to a Window.

Parameters
winWindow
fmtFormat string
...Arguments
Return values
numNumber of characters written

Definition at line 425 of file mutt_window.c.

426{
427 va_list ap;
428 va_start(ap, fmt);
429 int rc = vw_printw(stdscr, fmt, ap);
430 va_end(ap);
431
432 return rc;
433}
+ Here is the caller graph for this function:

◆ mutt_window_is_visible()

bool mutt_window_is_visible ( struct MuttWindow win)

Is the Window visible?

Parameters
winWindow
Return values
trueThe Window is visible

For a Window to be visible, it must be visible and its parent and grandparent, etc.

Definition at line 502 of file mutt_window.c.

503{
504 if (!win)
505 return false;
506
507 for (; win; win = win->parent)
508 {
509 if (!win->state.visible)
510 return false;
511 }
512
513 return true;
514}
+ Here is the caller graph for this function:

◆ mutt_winlist_free()

void mutt_winlist_free ( struct MuttWindowList *  head)

Free a tree of Windows.

Parameters
headWindowList to free

Definition at line 479 of file mutt_window.c.

480{
481 if (!head)
482 return;
483
484 struct MuttWindow *np = NULL;
485 struct MuttWindow *tmp = NULL;
486 TAILQ_FOREACH_SAFE(np, head, entries, tmp)
487 {
488 TAILQ_REMOVE(head, np, entries);
490 mutt_window_free(&np);
491 }
492}
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:200
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_find_child()

struct MuttWindow * window_find_child ( struct MuttWindow win,
enum WindowType  type 
)

Recursively find a child Window of a given type.

Parameters
winWindow to start searching
typeWindow type to find, e.g. WT_STATUS_BAR
Return values
ptrMatching Window
NULLNo match

Definition at line 523 of file mutt_window.c.

524{
525 if (!win)
526 return NULL;
527 if (win->type == type)
528 return win;
529
530 struct MuttWindow *np = NULL;
531 struct MuttWindow *match = NULL;
532 TAILQ_FOREACH(np, &win->children, entries)
533 {
534 match = window_find_child(np, type);
535 if (match)
536 return match;
537 }
538
539 return NULL;
540}
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:523
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_find_parent()

struct MuttWindow * window_find_parent ( struct MuttWindow win,
enum WindowType  type 
)

Find a (grand-)parent of a Window by type.

Parameters
winWindow
typeWindow type, e.g. WT_DLG_INDEX
Return values
ptrWindow

Definition at line 548 of file mutt_window.c.

549{
550 for (; win; win = win->parent)
551 {
552 if (win->type == type)
553 return win;
554 }
555
556 return NULL;
557}
+ Here is the caller graph for this function:

◆ window_notify_all()

void window_notify_all ( struct MuttWindow win)

Notify observers of changes to a Window and its children.

Parameters
winWindow

Definition at line 143 of file mutt_window.c.

144{
145 if (!win)
146 win = RootWindow;
147
148 window_notify(win);
149
150 struct MuttWindow *np = NULL;
151 TAILQ_FOREACH(np, &win->children, entries)
152 {
154 }
155 win->old = win->state;
156}
static void window_notify(struct MuttWindow *win)
Notify observers of changes to a Window.
Definition: mutt_window.c:104
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:128
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_set_visible()

void window_set_visible ( struct MuttWindow win,
bool  visible 
)

Set a Window visible or hidden.

Parameters
winWindow
visibleIf true, make Window visible, otherwise hidden

Definition at line 163 of file mutt_window.c.

164{
165 if (!win)
166 win = RootWindow;
167
168 win->state.visible = visible;
169}
+ Here is the caller graph for this function:

◆ window_set_focus()

struct MuttWindow * window_set_focus ( struct MuttWindow win)

Set the Window focus.

Parameters
winWindow to focus
Return values
ptrOld focused Window
NULLError, or focus not changed

Definition at line 660 of file mutt_window.c.

661{
662 if (!win)
663 return NULL;
664
665 struct MuttWindow *old_focus = window_get_focus();
666
667 struct MuttWindow *parent = win->parent;
668 struct MuttWindow *child = win;
669
670 // Set the chain of focus, all the way to the root
671 for (; parent; child = parent, parent = parent->parent)
672 parent->focus = child;
673
674 // Find the most focused Window
675 while (win && win->focus)
676 win = win->focus;
677
678 if (win == old_focus)
679 return NULL;
680
681 mutt_debug(LL_NOTIFY, "NT_WINDOW_FOCUS: %s, %p\n", mutt_window_win_name(win), win);
682 struct EventWindow ev_w = { win, WN_NO_FLAGS };
684#ifdef USE_DEBUG_WINDOW
686#endif
687 return old_focus;
688}
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
Definition: mutt_window.c:644
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_get_focus()

struct MuttWindow * window_get_focus ( void  )

Get the currently focused Window.

Return values
ptrWindow with focus

Definition at line 644 of file mutt_window.c.

645{
646 struct MuttWindow *win = RootWindow;
647
648 while (win && win->focus)
649 win = win->focus;
650
651 return win;
652}
+ Here is the caller graph for this function:

◆ window_is_focused()

bool window_is_focused ( const struct MuttWindow win)

Does the given Window have the focus?

Parameters
winWindow to check
Return values
trueWindow has focus

Definition at line 630 of file mutt_window.c.

631{
632 if (!win)
633 return false;
634
635 struct MuttWindow *win_focus = window_get_focus();
636
637 return (win_focus == win);
638}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_redraw()

void window_redraw ( struct MuttWindow win)

Reflow, recalc and repaint a tree of Windows.

Parameters
winWindow to start at
Note
If win is NULL, all windows will be redrawn

Definition at line 605 of file mutt_window.c.

606{
607 if (!win)
608 win = RootWindow;
609
610 if (SigWinch)
611 {
612 SigWinch = false;
615 }
616
617 window_reflow(win);
619
620 window_recalc(win);
621 window_repaint(win);
622 mutt_refresh();
623}
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:141
SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.c:60
void mutt_resize_screen(void)
Update NeoMutt's opinion about the window size (CURSES)
Definition: resize.c:72
static void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
Definition: mutt_window.c:563
static void window_repaint(struct MuttWindow *win)
Repaint a tree of Windows.
Definition: mutt_window.c:583
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:743
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_invalidate_all()

void window_invalidate_all ( void  )

Mark all windows as in need of repaint.

Definition at line 743 of file mutt_window.c.

744{
746 clearok(stdscr, true);
747 keypad(stdscr, true);
748}
static void window_invalidate(struct MuttWindow *win)
Mark a window as in need of repaint.
Definition: mutt_window.c:726
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_win_name()

const char * mutt_window_win_name ( const struct MuttWindow win)

Get the name of a Window.

Parameters
winWindow
Return values
ptrString describing Window
NULLError, or unknown

Definition at line 711 of file mutt_window.c.

712{
713 if (!win)
714 return "UNKNOWN";
715
716 const char *name = mutt_map_get_name(win->type, WindowNames);
717 if (name)
718 return name;
719 return "UNKNOWN";
720}
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
static const struct Mapping WindowNames[]
Lookups for Window Names.
Definition: mutt_window.c:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_status_on_top()

bool window_status_on_top ( struct MuttWindow panel,
struct ConfigSubset sub 
)

Organise windows according to config variable.

Parameters
panelWindow containing WT_MENU and WT_STATUS_BAR
subConfig Subset
Return values
trueWindow order was changed

Set the positions of two Windows based on a config variable $status_on_top.

Note
The children are expected to have types: WT_MENU, WT_STATUS_BAR

Definition at line 760 of file mutt_window.c.

761{
762 const bool c_status_on_top = cs_subset_bool(sub, "status_on_top");
763
764 struct MuttWindow *win = TAILQ_FIRST(&panel->children);
765
766 if ((c_status_on_top && (win->type == WT_STATUS_BAR)) ||
767 (!c_status_on_top && (win->type != WT_STATUS_BAR)))
768 {
769 return false;
770 }
771
772 if (c_status_on_top)
773 {
774 win = TAILQ_LAST(&panel->children, MuttWindowList);
775 TAILQ_REMOVE(&panel->children, win, entries);
776 TAILQ_INSERT_HEAD(&panel->children, win, entries);
777 }
778 else
779 {
780 TAILQ_REMOVE(&panel->children, win, entries);
781 TAILQ_INSERT_TAIL(&panel->children, win, entries);
782 }
783
784 mutt_window_reflow(panel);
786 return true;
787}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:341
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_LAST(head, headname)
Definition: queue.h:819
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:796
+ Here is the call graph for this function:
+ Here is the caller graph for this function: