NeoMutt  2020-06-26-89-g172cd3
Teaching an old dog new tricks
DOXYGEN
mutt_window.c File Reference

Window management. More...

#include "config.h"
#include <stdarg.h>
#include <string.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "debug/lib.h"
#include "mutt_window.h"
#include "mutt_curses.h"
#include "mutt_globals.h"
#include "mutt_menu.h"
#include "options.h"
#include "reflow.h"
+ Include dependency graph for mutt_window.c:

Go to the source code of this file.

Functions

static void window_notify (struct MuttWindow *win)
 Notify observers of changes to a Window. 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 (and its children) visible or hidden. 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_free (struct MuttWindow **ptr)
 Free a Window and its children. More...
 
void mutt_window_clearline (struct MuttWindow *win, int row)
 Clear a row of a Window. More...
 
void mutt_window_clrtobot (void)
 Clear to the bottom of the Window. More...
 
void mutt_window_clrtoeol (struct MuttWindow *win)
 Clear to the end of the line. More...
 
static int mutt_dlg_rootwin_observer (struct NotifyCallback *nc)
 Listen for config changes affecting the Root Window - Implements observer_t. More...
 
void mutt_window_free_all (void)
 Free all the default Windows. More...
 
void mutt_window_get_coords (struct MuttWindow *win, int *col, int *row)
 Get the cursor position in the Window. More...
 
void mutt_window_init (void)
 Create the default Windows. 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...
 
void mutt_window_copy_size (const struct MuttWindow *win_src, struct MuttWindow *win_dst)
 Copy the size of one Window to another. More...
 
void mutt_window_reflow (struct MuttWindow *win)
 Resize a Window and its children. More...
 
void mutt_window_reflow_message_rows (int mw_rows)
 Resize the Message 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 (int ch)
 Write one character to a Window. More...
 
int mutt_window_addnstr (const char *str, int num)
 Write a partial string to a Window. More...
 
int mutt_window_addstr (const char *str)
 Write a string to a Window. More...
 
void mutt_window_move_abs (int col, int row)
 Move the cursor to an absolute screen position. More...
 
int mutt_window_printf (const char *fmt,...)
 Write a formatted string to a Window. More...
 
void mutt_window_add_child (struct MuttWindow *parent, struct MuttWindow *child)
 Add a child to Window. More...
 
struct MuttWindowmutt_window_remove_child (struct MuttWindow *parent, struct MuttWindow *child)
 Remove a child from a Window. More...
 
void mutt_winlist_free (struct MuttWindowList *head)
 Free a tree of Windows. More...
 
void mutt_window_set_root (int cols, int rows)
 Set the dimensions of the Root Window. More...
 
bool mutt_window_is_visible (struct MuttWindow *win)
 Is the Window visible? More...
 
struct MuttWindowmutt_window_dialog (struct MuttWindow *win)
 Find the parent Dialog of a Window. More...
 
struct MuttWindowmutt_window_find (struct MuttWindow *root, enum WindowType type)
 Find a Window of a given type. More...
 
void dialog_push (struct MuttWindow *dlg)
 Display a Window to the user. More...
 
void dialog_pop (void)
 Hide a Window from the user. More...
 
void window_recalc (struct MuttWindow *win)
 Recalculate a tree of Windows. More...
 
void window_repaint (struct MuttWindow *win)
 Repaint a tree of Windows. More...
 
void window_redraw (struct MuttWindow *win)
 Reflow, recalc and repaint a tree of Windows. More...
 

Variables

struct MuttWindowRootWindow = NULL
 Parent of all Windows. More...
 
struct MuttWindowMuttDialogWindow = NULL
 Parent of all Dialogs. More...
 
struct MuttWindowMuttHelpWindow = NULL
 Help Window. More...
 
struct MuttWindowMuttMessageWindow = NULL
 Message Window. 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.c.

Function Documentation

◆ window_notify()

static void window_notify ( struct MuttWindow win)
static

Notify observers of changes to a Window.

Parameters
winWindow

Definition at line 52 of file mutt_window.c.

53 {
54  if (!win->notify)
55  return;
56 
57  const struct WindowState *old = &win->old;
58  const struct WindowState *new = &win->state;
60 
61  if (new->visible != old->visible)
62  flags |= new->visible ? WN_VISIBLE : WN_HIDDEN;
63 
64  if ((new->row_offset != old->row_offset) || (new->col_offset != old->col_offset))
65  flags |= WN_MOVED;
66 
67  if (new->rows > old->rows)
68  flags |= WN_TALLER;
69  else if (new->rows < old->rows)
70  flags |= WN_SHORTER;
71 
72  if (new->cols > old->cols)
73  flags |= WN_WIDER;
74  else if (new->cols < old->cols)
75  flags |= WN_NARROWER;
76 
77  if (flags == WN_NO_FLAGS)
78  return;
79 
80  struct EventWindow ev_w = { win, flags };
82  win->old = win->state;
83 }
#define WN_NARROWER
Window became narrower.
Definition: mutt_window.h:156
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:179
An Event that happened to a Window.
Definition: mutt_window.h:177
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:152
#define WN_WIDER
Window became wider.
Definition: mutt_window.h:155
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:159
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:59
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:41
struct Notify * notify
Notifications system.
Definition: mutt_window.h:130
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:170
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
#define WN_TALLER
Window became taller.
Definition: mutt_window.h:153
bool visible
Window is visible.
Definition: mutt_window.h:56
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:60
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58
uint8_t WindowNotifyFlags
Changes to a MuttWindow.
Definition: mutt_window.h:151
#define WN_SHORTER
Window became shorter.
Definition: mutt_window.h:154
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:120
The current, or old, state of a Window.
Definition: mutt_window.h:54
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:158
#define WN_MOVED
Window moved.
Definition: mutt_window.h:157
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:137
+ Here is the call graph for this function:
+ 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 89 of file mutt_window.c.

90 {
91  if (!win)
92  win = RootWindow;
93 
94  window_notify(win);
95 
96  struct MuttWindow *np = NULL;
97  TAILQ_FOREACH(np, &win->children, entries)
98  {
100  }
101 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
A division of the screen.
Definition: mutt_window.h:114
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:43
static void window_notify(struct MuttWindow *win)
Notify observers of changes to a Window.
Definition: mutt_window.c:52
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:89
struct MuttWindowList children
Children Windows.
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 (and its children) visible or hidden.

Parameters
winWindow
visibleIf true, make Window visible, otherwise hidden

Definition at line 108 of file mutt_window.c.

109 {
110  if (!win)
111  win = RootWindow;
112 
113  win->state.visible = visible;
114 
115  struct MuttWindow *np = NULL;
116  TAILQ_FOREACH(np, &win->children, entries)
117  {
118  window_set_visible(np, visible);
119  }
120 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
A division of the screen.
Definition: mutt_window.h:114
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:43
bool visible
Window is visible.
Definition: mutt_window.h:56
void window_set_visible(struct MuttWindow *win, bool visible)
Set a Window (and its children) visible or hidden.
Definition: mutt_window.c:108
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
+ Here is the call graph for this function:
+ 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 131 of file mutt_window.c.

133 {
134  struct MuttWindow *win = mutt_mem_calloc(1, sizeof(struct MuttWindow));
135 
136  win->type = type;
137  win->orient = orient;
138  win->size = size;
139  win->req_rows = rows;
140  win->req_cols = cols;
141  win->state.visible = true;
142  win->notify = notify_new();
143  TAILQ_INIT(&win->children);
144  return win;
145 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:122
A division of the screen.
Definition: mutt_window.h:114
struct Notify * notify
Notifications system.
Definition: mutt_window.h:130
#define TAILQ_INIT(head)
Definition: queue.h:758
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
bool visible
Window is visible.
Definition: mutt_window.h:56
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:123
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
short req_rows
Number of rows required.
Definition: mutt_window.h:117
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:132
short req_cols
Number of columns required.
Definition: mutt_window.h:116
+ 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 151 of file mutt_window.c.

152 {
153  if (!ptr || !*ptr)
154  return;
155 
156  struct MuttWindow *win = *ptr;
157 
158  struct EventWindow ev_w = { win, WN_NO_FLAGS };
160 
162 
163  if (win->wdata && win->wdata_free)
164  win->wdata_free(win, &win->wdata); // Custom function to free private data
165 
166  notify_free(&win->notify);
167 
168  FREE(ptr);
169 }
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Callback function to free private data.
Definition: mutt_window.h:134
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:179
An Event that happened to a Window.
Definition: mutt_window.h:177
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:152
Window is about to be deleted.
Definition: mutt_window.h:169
A division of the screen.
Definition: mutt_window.h:114
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:41
struct Notify * notify
Notifications system.
Definition: mutt_window.h:130
void mutt_winlist_free(struct MuttWindowList *head)
Free a tree of Windows.
Definition: mutt_window.c:600
#define FREE(x)
Definition: memory.h:40
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
void * wdata
Private data.
Definition: mutt_window.h:133
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:137
+ Here is the call graph for this function:
+ 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 194 of file mutt_window.c.

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

◆ mutt_window_clrtobot()

void mutt_window_clrtobot ( void  )

Clear to the bottom of the Window.

Note
Assumes the cursor has already been positioned within the Window.

Definition at line 205 of file mutt_window.c.

206 {
207  clrtobot();
208 }
+ 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 216 of file mutt_window.c.

217 {
218  if (!win || !stdscr)
219  return;
220 
221  if (win->state.col_offset + win->state.cols == COLS)
222  clrtoeol();
223  else
224  {
225  int row = 0;
226  int col = 0;
227  getyx(stdscr, row, col);
228  int curcol = col;
229  while (curcol < (win->state.col_offset + win->state.cols))
230  {
231  addch(' ');
232  curcol++;
233  }
234  move(row, col);
235  }
236 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:59
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
+ Here is the caller graph for this function:

◆ mutt_dlg_rootwin_observer()

static int mutt_dlg_rootwin_observer ( struct NotifyCallback nc)
static

Listen for config changes affecting the Root Window - Implements observer_t.

Definition at line 241 of file mutt_window.c.

242 {
243  if (!nc->event_data || !nc->global_data)
244  return -1;
245  if (nc->event_type != NT_CONFIG)
246  return 0;
247 
248  struct EventConfig *ec = nc->event_data;
249  struct MuttWindow *root_win = nc->global_data;
250 
251  if (mutt_str_equal(ec->name, "help"))
252  {
254  goto reflow;
255  }
256 
257  if (mutt_str_equal(ec->name, "status_on_top"))
258  {
259  struct MuttWindow *first = TAILQ_FIRST(&root_win->children);
260  if (!first)
261  return -1;
262 
263  if ((C_StatusOnTop && (first->type == WT_HELP_BAR)) ||
264  (!C_StatusOnTop && (first->type != WT_HELP_BAR)))
265  {
266  // Swap the HelpLine and the Dialogs Container
267  struct MuttWindow *next = TAILQ_NEXT(first, entries);
268  if (!next)
269  return -1;
270  TAILQ_REMOVE(&root_win->children, next, entries);
271  TAILQ_INSERT_HEAD(&root_win->children, next, entries);
272  }
273  }
274 
275 reflow:
276  mutt_window_reflow(root_win);
277  return 0;
278 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:876
#define TAILQ_FIRST(head)
Definition: queue.h:716
A config-change event.
Definition: subset.h:70
struct MuttWindow * MuttHelpWindow
Help Window.
Definition: mutt_window.c:45
A division of the screen.
Definition: mutt_window.h:114
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:41
void * global_data
Data from notify_observer_add()
Definition: observer.h:44
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
bool visible
Window is visible.
Definition: mutt_window.h:56
Help Bar containing list of useful key bindings.
Definition: mutt_window.h:92
void * event_data
Data from notify_send()
Definition: observer.h:43
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:36
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:789
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:429
WHERE bool C_StatusOnTop
Config: Display the status bar at the top.
Definition: mutt_globals.h:166
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
#define TAILQ_NEXT(elm, field)
Definition: queue.h:825
WHERE bool C_Help
Config: Display a help line with common key bindings.
Definition: mutt_globals.h:153
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:132
const char * name
Name of config item that changed.
Definition: subset.h:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_free_all()

void mutt_window_free_all ( void  )

Free all the default Windows.

Definition at line 283 of file mutt_window.c.

284 {
285  if (NeoMutt)
287  MuttDialogWindow = NULL;
288  MuttHelpWindow = NULL;
289  MuttMessageWindow = NULL;
291 }
static int mutt_dlg_rootwin_observer(struct NotifyCallback *nc)
Listen for config changes affecting the Root Window - Implements observer_t.
Definition: mutt_window.c:241
struct MuttWindow * MuttHelpWindow
Help Window.
Definition: mutt_window.c:45
Container for Accounts, Notifications.
Definition: neomutt.h:36
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:151
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:43
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:185
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:46
struct MuttWindow * MuttDialogWindow
Parent of all Dialogs.
Definition: mutt_window.c:44
+ 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 302 of file mutt_window.c.

303 {
304  int x = 0;
305  int y = 0;
306 
307  getyx(stdscr, y, x);
308  if (col)
309  *col = x - win->state.col_offset;
310  if (row)
311  *row = y - win->state.row_offset;
312 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:59
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:60
+ Here is the caller graph for this function:

◆ mutt_window_init()

void mutt_window_init ( void  )

Create the default Windows.

Create the Help, Index, Status, Message and Sidebar Windows.

Definition at line 319 of file mutt_window.c.

320 {
321  if (RootWindow)
322  return;
323 
324  RootWindow =
327 
331 
335 
338 
339  if (C_StatusOnTop)
340  {
343  }
344  else
345  {
348  }
349 
352 }
static int mutt_dlg_rootwin_observer(struct NotifyCallback *nc)
Listen for config changes affecting the Root Window - Implements observer_t.
Definition: mutt_window.c:241
Window for messages/errors and command entry.
Definition: mutt_window.h:95
Window uses all available vertical space.
Definition: mutt_window.h:35
Parent of All Windows.
Definition: mutt_window.h:69
struct MuttWindow * MuttHelpWindow
Help Window.
Definition: mutt_window.c:45
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Notify * notify
Notifications system.
Definition: mutt_window.h:130
Window has a fixed size.
Definition: mutt_window.h:44
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:43
bool visible
Window is visible.
Definition: mutt_window.h:56
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:49
Help Bar containing list of useful key bindings.
Definition: mutt_window.h:92
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Container for All Dialogs (nested Windows)
Definition: mutt_window.h:71
bool notify_observer_add(struct Notify *notify, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:153
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:561
WHERE bool C_StatusOnTop
Config: Display the status bar at the top.
Definition: mutt_globals.h:166
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:46
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:131
Window wants as much space as possible.
Definition: mutt_window.h:45
struct MuttWindow * MuttDialogWindow
Parent of all Dialogs.
Definition: mutt_window.c:44
WHERE bool C_Help
Config: Display a help line with common key bindings.
Definition: mutt_globals.h:153
+ Here is the call graph for this function:
+ 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 362 of file mutt_window.c.

363 {
364  return move(win->state.row_offset + row, win->state.col_offset + col);
365 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:59
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:60
+ 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 376 of file mutt_window.c.

377 {
378 #ifdef USE_SLANG_CURSES
379  return mvaddstr(win->state.row_offset + row, win->state.col_offset + col, (char *) str);
380 #else
381  return mvaddstr(win->state.row_offset + row, win->state.col_offset + col, str);
382 #endif
383 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:59
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:60
+ 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 395 of file mutt_window.c.

396 {
397  int rc = mutt_window_move(win, col, row);
398  if (rc == ERR)
399  return rc;
400 
401  va_list ap;
402  va_start(ap, fmt);
403  rc = vw_printw(stdscr, fmt, ap);
404  va_end(ap);
405 
406  return rc;
407 }
static int const char * fmt
Definition: acutest.h:488
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:362
va_start(args, fmt)
va_end(args)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_copy_size()

void mutt_window_copy_size ( const struct MuttWindow win_src,
struct MuttWindow win_dst 
)

Copy the size of one Window to another.

Parameters
win_srcWindow to copy
win_dstWindow to resize

Definition at line 414 of file mutt_window.c.

415 {
416  if (!win_src || !win_dst)
417  return;
418 
419  win_dst->state.rows = win_src->state.rows;
420  win_dst->state.cols = win_src->state.cols;
421  win_dst->state.row_offset = win_src->state.row_offset;
422  win_dst->state.col_offset = win_src->state.col_offset;
423 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:59
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:60
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58

◆ mutt_window_reflow()

void mutt_window_reflow ( struct MuttWindow win)

Resize a Window and its children.

Parameters
winWindow to resize

Definition at line 429 of file mutt_window.c.

430 {
431  if (OptNoCurses)
432  return;
433 
434  if (!win)
435  win = RootWindow;
436 
437  mutt_debug(LL_DEBUG2, "entering\n");
438  window_reflow(win);
439  window_notify_all(win);
440 
442  /* the pager menu needs this flag set to recalc line_info */
444 #ifdef USE_DEBUG_WINDOW
445  debug_win_dump();
446 #endif
447 }
#define REDRAW_FLOW
Used by pager to reflow text.
Definition: mutt_menu.h:47
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:48
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:222
Log at debug level 2.
Definition: logging.h:41
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:43
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:89
void debug_win_dump(void)
Definition: window.c:87
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_reflow_message_rows()

void mutt_window_reflow_message_rows ( int  mw_rows)

Resize the Message Window.

Parameters
mw_rowsNumber of rows required

Resize the other Windows to allow a multi-line message to be displayed.

Definition at line 455 of file mutt_window.c.

456 {
457  MuttMessageWindow->req_rows = mw_rows;
459 
460  /* We don't also set REDRAW_FLOW because this function only
461  * changes rows and is a temporary adjustment. */
463 }
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:429
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:127
short req_rows
Number of rows required.
Definition: mutt_window.h:117
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:46
+ 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 473 of file mutt_window.c.

474 {
475  if (wrap < 0)
476  return (width > -wrap) ? (width + wrap) : width;
477  if (wrap)
478  return (wrap < width) ? wrap : width;
479  return width;
480 }
+ Here is the caller graph for this function:

◆ mutt_window_addch()

int mutt_window_addch ( int  ch)

Write one character to a Window.

Parameters
chCharacter to write
Return values
0Success
-1Error

Definition at line 488 of file mutt_window.c.

489 {
490  return addch(ch);
491 }
+ Here is the caller graph for this function:

◆ mutt_window_addnstr()

int mutt_window_addnstr ( const char *  str,
int  num 
)

Write a partial string to a Window.

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

Definition at line 500 of file mutt_window.c.

501 {
502  if (!str)
503  return -1;
504 
505 #ifdef USE_SLANG_CURSES
506  return addnstr((char *) str, num);
507 #else
508  return addnstr(str, num);
509 #endif
510 }
+ Here is the caller graph for this function:

◆ mutt_window_addstr()

int mutt_window_addstr ( const char *  str)

Write a string to a Window.

Parameters
strString
Return values
0Success
-1Error

Definition at line 518 of file mutt_window.c.

519 {
520  if (!str)
521  return -1;
522 
523 #ifdef USE_SLANG_CURSES
524  return addstr((char *) str);
525 #else
526  return addstr(str);
527 #endif
528 }
+ Here is the caller graph for this function:

◆ mutt_window_move_abs()

void mutt_window_move_abs ( int  col,
int  row 
)

Move the cursor to an absolute screen position.

Parameters
colScreen column (0-based)
rowScreen row (0-based)

Definition at line 535 of file mutt_window.c.

536 {
537  move(row, col);
538 }
+ Here is the caller graph for this function:

◆ mutt_window_printf()

int mutt_window_printf ( const char *  fmt,
  ... 
)

Write a formatted string to a Window.

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

Definition at line 546 of file mutt_window.c.

547 {
548  va_list ap;
549  va_start(ap, fmt);
550  int rc = vw_printw(stdscr, fmt, ap);
551  va_end(ap);
552 
553  return rc;
554 }
static int const char * fmt
Definition: acutest.h:488
va_start(args, fmt)
va_end(args)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 561 of file mutt_window.c.

562 {
563  if (!parent || !child)
564  return;
565 
566  TAILQ_INSERT_TAIL(&parent->children, child, entries);
567  child->parent = parent;
568 
569  notify_set_parent(child->notify, parent->notify);
570 
571  struct EventWindow ev_w = { child, WN_NO_FLAGS };
572  notify_send(child->notify, NT_WINDOW, NT_WINDOW_NEW, &ev_w);
573 }
An Event that happened to a Window.
Definition: mutt_window.h:177
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:152
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:41
struct Notify * notify
Notifications system.
Definition: mutt_window.h:130
New Window has been added.
Definition: mutt_window.h:168
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:802
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:127
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:137
+ 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

Definition at line 580 of file mutt_window.c.

581 {
582  if (!parent || !child)
583  return NULL;
584 
585  struct EventWindow ev_w = { child, WN_NO_FLAGS };
586  notify_send(child->notify, NT_WINDOW, NT_WINDOW_DELETE, &ev_w);
587 
588  TAILQ_REMOVE(&parent->children, child, entries);
589  child->parent = NULL;
590 
591  notify_set_parent(child->notify, NULL);
592 
593  return child;
594 }
An Event that happened to a Window.
Definition: mutt_window.h:177
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:152
Window is about to be deleted.
Definition: mutt_window.h:169
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:41
struct Notify * notify
Notifications system.
Definition: mutt_window.h:130
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:127
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:137
+ Here is the call graph for this function:
+ 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 600 of file mutt_window.c.

601 {
602  if (!head)
603  return;
604 
605  struct MuttWindow *np = NULL;
606  struct MuttWindow *tmp = NULL;
607  TAILQ_FOREACH_SAFE(np, head, entries, tmp)
608  {
609  TAILQ_REMOVE(head, np, entries);
611  mutt_window_free(&np);
612  }
613 }
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:728
A division of the screen.
Definition: mutt_window.h:114
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:151
void mutt_winlist_free(struct MuttWindowList *head)
Free a tree of Windows.
Definition: mutt_window.c:600
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_set_root()

void mutt_window_set_root ( int  cols,
int  rows 
)

Set the dimensions of the Root Window.

Parameters
rows
cols

Definition at line 620 of file mutt_window.c.

621 {
622  if (!RootWindow)
623  return;
624 
625  bool changed = false;
626 
627  if (RootWindow->state.rows != rows)
628  {
629  RootWindow->state.rows = rows;
630  changed = true;
631  }
632 
633  if (RootWindow->state.cols != cols)
634  {
635  RootWindow->state.cols = cols;
636  changed = true;
637  }
638 
639  if (changed)
640  {
642  }
643 }
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:43
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:429
+ Here is the call graph for this function:
+ 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
trueIf the Window is visible

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

Definition at line 653 of file mutt_window.c.

654 {
655  if (!win)
656  return false;
657 
658  for (; win; win = win->parent)
659  {
660  if (!win->state.visible)
661  return false;
662  }
663 
664  return true;
665 }
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
bool visible
Window is visible.
Definition: mutt_window.h:56
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:127
+ Here is the caller graph for this function:

◆ mutt_window_dialog()

struct MuttWindow* mutt_window_dialog ( struct MuttWindow win)

Find the parent Dialog of a Window.

Parameters
winWindow
Return values
ptrDialog

Dialog Windows will be owned by a MuttWindow of type WT_ALL_DIALOGS.

Definition at line 674 of file mutt_window.c.

675 {
676  for (; win && win->parent; win = win->parent)
677  {
678  if (win->parent->type == WT_ALL_DIALOGS)
679  return win;
680  }
681 
682  return NULL;
683 }
Container for All Dialogs (nested Windows)
Definition: mutt_window.h:71
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:127
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:132
+ Here is the caller graph for this function:

◆ mutt_window_find()

struct MuttWindow* mutt_window_find ( struct MuttWindow root,
enum WindowType  type 
)

Find a Window of a given type.

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

Definition at line 692 of file mutt_window.c.

693 {
694  if (!root)
695  return NULL;
696  if (root->type == type)
697  return root;
698 
699  struct MuttWindow *np = NULL;
700  struct MuttWindow *match = NULL;
701  TAILQ_FOREACH(np, &root->children, entries)
702  {
703  match = mutt_window_find(np, type);
704  if (match)
705  return match;
706  }
707 
708  return NULL;
709 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
struct MuttWindow * mutt_window_find(struct MuttWindow *root, enum WindowType type)
Find a Window of a given type.
Definition: mutt_window.c:692
A division of the screen.
Definition: mutt_window.h:114
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:132
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dialog_push()

void dialog_push ( struct MuttWindow dlg)

Display a Window to the user.

Parameters
dlgWindow to display

The Dialog Windows are kept in a stack. The topmost is visible to the user, whilst the others are hidden.

When a Window is pushed, the old Window is marked as not visible.

Definition at line 720 of file mutt_window.c.

721 {
722  if (!dlg || !MuttDialogWindow)
723  return;
724 
725  struct MuttWindow *last = TAILQ_LAST(&MuttDialogWindow->children, MuttWindowList);
726  if (last)
727  last->state.visible = false;
728 
731 
732  // Notify the world, allowing plugins to integrate
733  struct EventWindow ev_w = { dlg, WN_VISIBLE };
735 
736  dlg->state.visible = true;
737  dlg->parent = MuttDialogWindow;
739 #ifdef USE_DEBUG_WINDOW
740  debug_win_dump();
741 #endif
742 }
A new Dialog Window has been created, e.g. WT_DLG_INDEX.
Definition: mutt_window.h:171
An Event that happened to a Window.
Definition: mutt_window.h:177
#define TAILQ_LAST(head, headname)
Definition: queue.h:812
A division of the screen.
Definition: mutt_window.h:114
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:41
struct Notify * notify
Notifications system.
Definition: mutt_window.h:130
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
bool visible
Window is visible.
Definition: mutt_window.h:56
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:802
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:429
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:127
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:158
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
void debug_win_dump(void)
Definition: window.c:87
struct MuttWindow * MuttDialogWindow
Parent of all Dialogs.
Definition: mutt_window.c:44
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dialog_pop()

void dialog_pop ( void  )

Hide a Window from the user.

The topmost (visible) Window is removed from the stack and the next Window is marked as visible.

Definition at line 750 of file mutt_window.c.

751 {
752  if (!MuttDialogWindow)
753  return;
754 
755  struct MuttWindow *last = TAILQ_LAST(&MuttDialogWindow->children, MuttWindowList);
756  if (!last)
757  return;
758 
759  // Notify the world, allowing plugins to clean up
760  struct EventWindow ev_w = { last, WN_HIDDEN };
762 
763  last->state.visible = false;
764  last->parent = NULL;
765  TAILQ_REMOVE(&MuttDialogWindow->children, last, entries);
766 
767  last = TAILQ_LAST(&MuttDialogWindow->children, MuttWindowList);
768  if (last)
769  {
770  last->state.visible = true;
772  }
774 #ifdef USE_DEBUG_WINDOW
775  debug_win_dump();
776 #endif
777 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
A new Dialog Window has been created, e.g. WT_DLG_INDEX.
Definition: mutt_window.h:171
An Event that happened to a Window.
Definition: mutt_window.h:177
#define TAILQ_LAST(head, headname)
Definition: queue.h:812
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:159
A division of the screen.
Definition: mutt_window.h:114
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:41
struct Notify * notify
Notifications system.
Definition: mutt_window.h:130
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:119
bool visible
Window is visible.
Definition: mutt_window.h:56
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:429
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:127
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
void debug_win_dump(void)
Definition: window.c:87
struct MuttWindow * MuttDialogWindow
Parent of all Dialogs.
Definition: mutt_window.c:44
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_recalc()

void window_recalc ( struct MuttWindow win)

Recalculate a tree of Windows.

Parameters
winWindow to start at

Definition at line 783 of file mutt_window.c.

784 {
785  if (!win)
786  return;
787 
788  if (win->recalc)
789  win->recalc(win, false);
790 
791  struct MuttWindow *np = NULL;
792  TAILQ_FOREACH(np, &win->children, entries)
793  {
794  if (np->recalc)
795  np->recalc(np, false);
796  }
797 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
A division of the screen.
Definition: mutt_window.h:114
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
int(* recalc)(struct MuttWindow *win, bool all)
Recalculate the Window data.
Definition: mutt_window.h:141
+ Here is the caller graph for this function:

◆ window_repaint()

void window_repaint ( struct MuttWindow win)

Repaint a tree of Windows.

Parameters
winWindow to start at

Definition at line 803 of file mutt_window.c.

804 {
805  if (!win)
806  return;
807 
808  if (win->repaint)
809  win->repaint(win, false);
810 
811  struct MuttWindow *np = NULL;
812  TAILQ_FOREACH(np, &win->children, entries)
813  {
814  if (np->repaint)
815  np->repaint(np, false);
816  }
817 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
A division of the screen.
Definition: mutt_window.h:114
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:128
int(* repaint)(struct MuttWindow *win, bool all)
Repaint the Window.
Definition: mutt_window.h:148
+ 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

Definition at line 823 of file mutt_window.c.

824 {
825  if (!win)
826  return;
827 
828  window_reflow(win);
829  window_notify_all(win);
830 
831  window_recalc(win);
832  window_repaint(win);
833 }
void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
Definition: mutt_window.c:783
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:222
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:89
void window_repaint(struct MuttWindow *win)
Repaint a tree of Windows.
Definition: mutt_window.c:803
+ Here is the call graph for this function:

Variable Documentation

◆ RootWindow

struct MuttWindow* RootWindow = NULL

Parent of all Windows.

Definition at line 43 of file mutt_window.c.

◆ MuttDialogWindow

struct MuttWindow* MuttDialogWindow = NULL

Parent of all Dialogs.

Definition at line 44 of file mutt_window.c.

◆ MuttHelpWindow

struct MuttWindow* MuttHelpWindow = NULL

Help Window.

Definition at line 45 of file mutt_window.c.

◆ MuttMessageWindow

struct MuttWindow* MuttMessageWindow = NULL

Message Window.

Definition at line 46 of file mutt_window.c.