NeoMutt  2020-11-20
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 "helpbar/lib.h"
#include "mutt_curses.h"
#include "mutt_globals.h"
#include "mutt_menu.h"
#include "opcodes.h"
#include "options.h"
#include "reflow.h"
+ Include dependency graph for mutt_window.c:

Go to the source code of this file.

Functions

static bool window_was_visible (struct MuttWindow *win)
 Was the Window visible? More...
 
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 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_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_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_find (struct MuttWindow *root, enum WindowType type)
 Find a Window of a given type. More...
 
static void window_recalc (struct MuttWindow *win)
 Recalculate a tree of Windows. More...
 
static void window_repaint (struct MuttWindow *win, bool force)
 Repaint a tree of Windows. More...
 
void window_redraw (struct MuttWindow *win, bool force)
 Reflow, recalc and repaint a tree of Windows. More...
 
void window_set_focus (struct MuttWindow *win)
 Set the Window focus. More...
 
struct MuttWindowwindow_get_focus (void)
 Get the currently focussed Window. More...
 
void mutt_window_clear (struct MuttWindow *win)
 Clear a Window. More...
 

Variables

struct MuttWindowRootWindow = NULL
 Parent of all Windows. More...
 
struct MuttWindowAllDialogsWindow = NULL
 Parent of all Dialogs. More...
 
struct MuttWindowMessageWindow = NULL
 Message Window, ":set", etc. More...
 
static const struct Mapping EditorHelp []
 Help Bar for the Command Line Editor. 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_was_visible()

static bool window_was_visible ( struct MuttWindow win)
static

Was the Window visible?

Parameters
winWindow
Return values
trueIf the Window was visible

Using the WindowState old, check if a Window used to be visible. For a Window to be visible, it must have been visible and it's parent and grandparent, etc.

Definition at line 73 of file mutt_window.c.

74 {
75  if (!win)
76  return false;
77 
78  for (; win; win = win->parent)
79  {
80  if (!win->old.visible)
81  return false;
82  }
83 
84  return true;
85 }
bool visible
Window is visible.
Definition: mutt_window.h:56
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:121
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:128
+ Here is the caller graph for this function:

◆ window_notify()

static void window_notify ( struct MuttWindow win)
static

Notify observers of changes to a Window.

Parameters
winWindow

Definition at line 91 of file mutt_window.c.

92 {
93  if (!win->notify)
94  return;
95 
96  const struct WindowState *old = &win->old;
97  const struct WindowState *state = &win->state;
99 
100  const bool was_visible = window_was_visible(win);
101  const bool is_visible = mutt_window_is_visible(win);
102  if (was_visible != is_visible)
103  flags |= is_visible ? WN_VISIBLE : WN_HIDDEN;
104 
105  if ((state->row_offset != old->row_offset) || (state->col_offset != old->col_offset))
106  flags |= WN_MOVED;
107 
108  if (state->rows > old->rows)
109  flags |= WN_TALLER;
110  else if (state->rows < old->rows)
111  flags |= WN_SHORTER;
112 
113  if (state->cols > old->cols)
114  flags |= WN_WIDER;
115  else if (state->cols < old->cols)
116  flags |= WN_NARROWER;
117 
118  if (flags == WN_NO_FLAGS)
119  return;
120 
121  struct EventWindow ev_w = { win, flags };
123 }
#define WN_NARROWER
Window became narrower.
Definition: mutt_window.h:169
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:193
An Event that happened to a Window.
Definition: mutt_window.h:191
static bool is_visible(struct Email *e)
Is the message visible?
Definition: mutt_thread.c:73
static bool window_was_visible(struct MuttWindow *win)
Was the Window visible?
Definition: mutt_window.c:73
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:165
#define WN_WIDER
Window became wider.
Definition: mutt_window.h:168
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:172
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:59
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:43
struct Notify * notify
Notifications system.
Definition: mutt_window.h:131
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:183
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:120
#define WN_TALLER
Window became taller.
Definition: mutt_window.h:166
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:657
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:164
#define WN_SHORTER
Window became shorter.
Definition: mutt_window.h:167
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:121
The current, or old, state of a Window.
Definition: mutt_window.h:54
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:171
#define WN_MOVED
Window moved.
Definition: mutt_window.h:170
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:152
+ 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 129 of file mutt_window.c.

130 {
131  if (!win)
132  win = RootWindow;
133 
134  window_notify(win);
135 
136  struct MuttWindow *np = NULL;
137  TAILQ_FOREACH(np, &win->children, entries)
138  {
139  window_notify_all(np);
140  }
141  win->old = win->state;
142 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
A division of the screen.
Definition: mutt_window.h:115
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:45
static void window_notify(struct MuttWindow *win)
Notify observers of changes to a Window.
Definition: mutt_window.c:91
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:121
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:129
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
+ 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 149 of file mutt_window.c.

150 {
151  if (!win)
152  win = RootWindow;
153 
154  win->state.visible = visible;
155 }
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:45
bool visible
Window is visible.
Definition: mutt_window.h:56
+ 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 166 of file mutt_window.c.

168 {
169  struct MuttWindow *win = mutt_mem_calloc(1, sizeof(struct MuttWindow));
170 
171  win->type = type;
172  win->orient = orient;
173  win->size = size;
174  win->req_rows = rows;
175  win->req_cols = cols;
176  win->state.visible = true;
177  win->notify = notify_new();
178  TAILQ_INIT(&win->children);
179  return win;
180 }
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:123
A division of the screen.
Definition: mutt_window.h:115
struct Notify * notify
Notifications system.
Definition: mutt_window.h:131
#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:120
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:124
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
short req_rows
Number of rows required.
Definition: mutt_window.h:118
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:137
short req_cols
Number of columns required.
Definition: mutt_window.h:117
+ 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 186 of file mutt_window.c.

187 {
188  if (!ptr || !*ptr)
189  return;
190 
191  struct MuttWindow *win = *ptr;
192 
193  if (win->parent && (win->parent->focus == win))
194  win->parent->focus = NULL;
195 
196  struct EventWindow ev_w = { win, WN_NO_FLAGS };
198 
200 
201  if (win->wdata && win->wdata_free)
202  win->wdata_free(win, &win->wdata); // Custom function to free private data
203 
204  notify_free(&win->notify);
205 
206  FREE(ptr);
207 }
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Free the private data attached to the MuttWindow.
Definition: mutt_window.h:145
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:193
An Event that happened to a Window.
Definition: mutt_window.h:191
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:165
Window is about to be deleted.
Definition: mutt_window.h:182
A division of the screen.
Definition: mutt_window.h:115
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:43
struct MuttWindow * focus
Focussed Window.
Definition: mutt_window.h:133
struct Notify * notify
Notifications system.
Definition: mutt_window.h:131
void mutt_winlist_free(struct MuttWindowList *head)
Free a tree of Windows.
Definition: mutt_window.c:604
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:128
#define FREE(x)
Definition: memory.h:40
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
void * wdata
Private data.
Definition: mutt_window.h:138
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:152
+ 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 232 of file mutt_window.c.

233 {
234  mutt_window_move(win, 0, row);
236 }
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:244
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:382
+ 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 244 of file mutt_window.c.

245 {
246  if (!win || !stdscr)
247  return;
248 
249  if (win->state.col_offset + win->state.cols == COLS)
250  clrtoeol();
251  else
252  {
253  int row = 0;
254  int col = 0;
255  getyx(stdscr, row, col);
256  int curcol = col;
257  while (curcol < (win->state.col_offset + win->state.cols))
258  {
259  addch(' ');
260  curcol++;
261  }
262  move(row, col);
263  }
264 }
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:120
+ 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 269 of file mutt_window.c.

270 {
271  if (!nc->event_data || !nc->global_data)
272  return -1;
273  if (nc->event_type != NT_CONFIG)
274  return 0;
275 
276  struct EventConfig *ec = nc->event_data;
277  struct MuttWindow *root_win = nc->global_data;
278 
279  if (mutt_str_equal(ec->name, "status_on_top"))
280  {
281  struct MuttWindow *first = TAILQ_FIRST(&root_win->children);
282  if (!first)
283  return -1;
284 
285  if ((C_StatusOnTop && (first->type == WT_HELP_BAR)) ||
286  (!C_StatusOnTop && (first->type != WT_HELP_BAR)))
287  {
288  // Swap the HelpLine and the Dialogs Container
289  struct MuttWindow *next = TAILQ_NEXT(first, entries);
290  if (!next)
291  return -1;
292  TAILQ_REMOVE(&root_win->children, next, entries);
293  TAILQ_INSERT_HEAD(&root_win->children, next, entries);
294  }
295  }
296 
297  mutt_window_reflow(root_win);
298  return 0;
299 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
#define TAILQ_FIRST(head)
Definition: queue.h:716
A config-change event.
Definition: subset.h:70
A division of the screen.
Definition: mutt_window.h:115
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
Help Bar containing list of useful key bindings.
Definition: mutt_window.h:93
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:37
#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:433
WHERE bool C_StatusOnTop
Config: Display the status bar at the top.
Definition: mutt_globals.h:164
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
#define TAILQ_NEXT(elm, field)
Definition: queue.h:825
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:137
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 304 of file mutt_window.c.

305 {
306  if (NeoMutt)
308  AllDialogsWindow = NULL;
309  MessageWindow = NULL;
311 }
static int mutt_dlg_rootwin_observer(struct NotifyCallback *nc)
Listen for config changes affecting the Root Window - Implements observer_t.
Definition: mutt_window.c:269
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:186
struct MuttWindow * MessageWindow
Message Window, ":set", etc.
Definition: mutt_window.c:47
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:45
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: mutt_window.c:46
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:207
+ 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 322 of file mutt_window.c.

323 {
324  int x = 0;
325  int y = 0;
326 
327  getyx(stdscr, y, x);
328  if (col)
329  *col = x - win->state.col_offset;
330  if (row)
331  *row = y - win->state.row_offset;
332 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:59
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
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 339 of file mutt_window.c.

340 {
341  if (RootWindow)
342  return;
343 
344  RootWindow =
347 
348  struct MuttWindow *win_helpbar = helpbar_create();
349 
353 
358 
359  if (C_StatusOnTop)
360  {
362  mutt_window_add_child(RootWindow, win_helpbar);
363  }
364  else
365  {
366  mutt_window_add_child(RootWindow, win_helpbar);
368  }
369 
372 }
static int mutt_dlg_rootwin_observer(struct NotifyCallback *nc)
Listen for config changes affecting the Root Window - Implements observer_t.
Definition: mutt_window.c:269
Window for messages/errors and command entry.
Definition: mutt_window.h:96
int help_menu
Menu for key bindings, e.g. MENU_PAGER.
Definition: mutt_window.h:134
Window uses all available vertical space.
Definition: mutt_window.h:35
Parent of All Windows.
Definition: mutt_window.h:69
static const struct Mapping EditorHelp[]
Help Bar for the Command Line Editor.
Definition: mutt_window.c:50
A division of the screen.
Definition: mutt_window.h:115
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Notify * notify
Notifications system.
Definition: mutt_window.h:131
struct MuttWindow * helpbar_create(void)
Create the Help Bar Window.
Definition: helpbar.c:263
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:169
Window has a fixed size.
Definition: mutt_window.h:44
struct MuttWindow * MessageWindow
Message Window, ":set", etc.
Definition: mutt_window.c:47
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:45
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:49
const struct Mapping * help_data
Data for the Help Bar.
Definition: mutt_window.h:135
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Container for All Dialogs (nested Windows)
Definition: mutt_window.h:71
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: mutt_window.c:46
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:565
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:37
WHERE bool C_StatusOnTop
Config: Display the status bar at the top.
Definition: mutt_globals.h:164
Text entry area.
Definition: keymap.h:77
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
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:166
Window wants as much space as possible.
Definition: mutt_window.h:45
+ 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 382 of file mutt_window.c.

383 {
384  return move(win->state.row_offset + row, win->state.col_offset + col);
385 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:59
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
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 396 of file mutt_window.c.

397 {
398 #ifdef USE_SLANG_CURSES
399  return mvaddstr(win->state.row_offset + row, win->state.col_offset + col, (char *) str);
400 #else
401  return mvaddstr(win->state.row_offset + row, win->state.col_offset + col, str);
402 #endif
403 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:59
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
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 415 of file mutt_window.c.

416 {
417  int rc = mutt_window_move(win, col, row);
418  if (rc == ERR)
419  return rc;
420 
421  va_list ap;
422  va_start(ap, fmt);
423  rc = vw_printw(stdscr, fmt, ap);
424  va_end(ap);
425 
426  return rc;
427 }
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:382
+ 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 433 of file mutt_window.c.

434 {
435  if (OptNoCurses)
436  return;
437 
438  if (!win)
439  win = RootWindow;
440 
441  mutt_debug(LL_DEBUG2, "entering\n");
442  window_reflow(win);
443  window_notify_all(win);
444 
446  /* the pager menu needs this flag set to recalc line_info */
448 #ifdef USE_DEBUG_WINDOW
449  debug_win_dump();
450 #endif
451 }
#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
Log at debug level 2.
Definition: logging.h:41
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:222
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:45
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:129
void debug_win_dump(void)
Definition: window.c:88
#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 459 of file mutt_window.c.

460 {
461  MessageWindow->req_rows = mw_rows;
463 
464  /* We don't also set REDRAW_FLOW because this function only
465  * changes rows and is a temporary adjustment. */
467 }
struct MuttWindow * MessageWindow
Message Window, ":set", etc.
Definition: mutt_window.c:47
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:433
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:128
short req_rows
Number of rows required.
Definition: mutt_window.h:118
+ 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 477 of file mutt_window.c.

478 {
479  if (wrap < 0)
480  return (width > -wrap) ? (width + wrap) : width;
481  if (wrap)
482  return (wrap < width) ? wrap : width;
483  return width;
484 }
+ 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 492 of file mutt_window.c.

493 {
494  return addch(ch);
495 }
+ 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 504 of file mutt_window.c.

505 {
506  if (!str)
507  return -1;
508 
509 #ifdef USE_SLANG_CURSES
510  return addnstr((char *) str, num);
511 #else
512  return addnstr(str, num);
513 #endif
514 }
+ 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 522 of file mutt_window.c.

523 {
524  if (!str)
525  return -1;
526 
527 #ifdef USE_SLANG_CURSES
528  return addstr((char *) str);
529 #else
530  return addstr(str);
531 #endif
532 }
+ 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 539 of file mutt_window.c.

540 {
541  move(row, col);
542 }
+ 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 550 of file mutt_window.c.

551 {
552  va_list ap;
553  va_start(ap, fmt);
554  int rc = vw_printw(stdscr, fmt, ap);
555  va_end(ap);
556 
557  return rc;
558 }
+ 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 565 of file mutt_window.c.

566 {
567  if (!parent || !child)
568  return;
569 
570  TAILQ_INSERT_TAIL(&parent->children, child, entries);
571  child->parent = parent;
572 
573  notify_set_parent(child->notify, parent->notify);
574 
575  struct EventWindow ev_w = { child, WN_NO_FLAGS };
576  notify_send(child->notify, NT_WINDOW, NT_WINDOW_NEW, &ev_w);
577 }
An Event that happened to a Window.
Definition: mutt_window.h:191
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:165
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:43
struct Notify * notify
Notifications system.
Definition: mutt_window.h:131
New Window has been added.
Definition: mutt_window.h:181
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:802
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:128
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
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:152
+ 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 584 of file mutt_window.c.

585 {
586  if (!parent || !child)
587  return NULL;
588 
589  struct EventWindow ev_w = { child, WN_NO_FLAGS };
590  notify_send(child->notify, NT_WINDOW, NT_WINDOW_DELETE, &ev_w);
591 
592  TAILQ_REMOVE(&parent->children, child, entries);
593  child->parent = NULL;
594 
595  notify_set_parent(child->notify, NULL);
596 
597  return child;
598 }
An Event that happened to a Window.
Definition: mutt_window.h:191
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:165
Window is about to be deleted.
Definition: mutt_window.h:182
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:43
struct Notify * notify
Notifications system.
Definition: mutt_window.h:131
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:128
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
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:152
+ 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 604 of file mutt_window.c.

605 {
606  if (!head)
607  return;
608 
609  struct MuttWindow *np = NULL;
610  struct MuttWindow *tmp = NULL;
611  TAILQ_FOREACH_SAFE(np, head, entries, tmp)
612  {
613  TAILQ_REMOVE(head, np, entries);
615  mutt_window_free(&np);
616  }
617 }
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:728
A division of the screen.
Definition: mutt_window.h:115
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:186
void mutt_winlist_free(struct MuttWindowList *head)
Free a tree of Windows.
Definition: mutt_window.c:604
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
+ 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 624 of file mutt_window.c.

625 {
626  if (!RootWindow)
627  return;
628 
629  bool changed = false;
630 
631  if (RootWindow->state.rows != rows)
632  {
633  RootWindow->state.rows = rows;
634  changed = true;
635  }
636 
637  if (RootWindow->state.cols != cols)
638  {
639  RootWindow->state.cols = cols;
640  changed = true;
641  }
642 
643  if (changed)
644  {
646  }
647 }
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:120
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:45
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:433
+ 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 657 of file mutt_window.c.

658 {
659  if (!win)
660  return false;
661 
662  for (; win; win = win->parent)
663  {
664  if (!win->state.visible)
665  return false;
666  }
667 
668  return true;
669 }
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
bool visible
Window is visible.
Definition: mutt_window.h:56
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:128
+ 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 678 of file mutt_window.c.

679 {
680  if (!root)
681  return NULL;
682  if (root->type == type)
683  return root;
684 
685  struct MuttWindow *np = NULL;
686  struct MuttWindow *match = NULL;
687  TAILQ_FOREACH(np, &root->children, entries)
688  {
689  match = mutt_window_find(np, type);
690  if (match)
691  return match;
692  }
693 
694  return NULL;
695 }
#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:678
A division of the screen.
Definition: mutt_window.h:115
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_recalc()

static void window_recalc ( struct MuttWindow win)
static

Recalculate a tree of Windows.

Parameters
winWindow to start at

Definition at line 701 of file mutt_window.c.

702 {
703  if (!win)
704  return;
705 
706  if (win->recalc)
707  {
708  win->recalc(win);
709  win->actions &= ~WA_RECALC;
710  }
711 
712  struct MuttWindow *np = NULL;
713  TAILQ_FOREACH(np, &win->children, entries)
714  {
715  window_recalc(np);
716  }
717 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
A division of the screen.
Definition: mutt_window.h:115
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:125
static void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
Definition: mutt_window.c:701
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
int(* recalc)(struct MuttWindow *win)
Recalculate the Window data.
Definition: mutt_window.h:153
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:107
+ Here is the caller graph for this function:

◆ window_repaint()

static void window_repaint ( struct MuttWindow win,
bool  force 
)
static

Repaint a tree of Windows.

Parameters
winWindow to start at
forceRepaint everything

Definition at line 724 of file mutt_window.c.

725 {
726  if (!win)
727  return;
728 
729  if (win->repaint && (force || (win->actions & WA_REPAINT)))
730  {
731  win->repaint(win);
732  win->actions &= ~WA_REPAINT;
733  }
734 
735  struct MuttWindow *np = NULL;
736  TAILQ_FOREACH(np, &win->children, entries)
737  {
738  window_repaint(np, force);
739  }
740 }
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:108
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
A division of the screen.
Definition: mutt_window.h:115
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:125
static void window_repaint(struct MuttWindow *win, bool force)
Repaint a tree of Windows.
Definition: mutt_window.c:724
int(* repaint)(struct MuttWindow *win)
Repaint the Window.
Definition: mutt_window.h:161
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:129
+ Here is the caller graph for this function:

◆ window_redraw()

void window_redraw ( struct MuttWindow win,
bool  force 
)

Reflow, recalc and repaint a tree of Windows.

Parameters
winWindow to start at
forceRepaint everything

Definition at line 747 of file mutt_window.c.

748 {
749  if (!win)
750  return;
751 
752  window_reflow(win);
753  window_notify_all(win);
754 
755  window_recalc(win);
756  window_repaint(win, force);
757 }
static void window_repaint(struct MuttWindow *win, bool force)
Repaint a tree of Windows.
Definition: mutt_window.c:724
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:222
static void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
Definition: mutt_window.c:701
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:129
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_set_focus()

void window_set_focus ( struct MuttWindow win)

Set the Window focus.

Parameters
winWindow to focus

Definition at line 763 of file mutt_window.c.

764 {
765  if (!win)
766  return;
767 
768  struct MuttWindow *parent = win->parent;
769  struct MuttWindow *child = win;
770 
771  // Set the chain of focus, all the way to the root
772  for (; parent; child = parent, parent = parent->parent)
773  parent->focus = child;
774 
775  // Find the most focussed Window
776  while (win && win->focus)
777  win = win->focus;
778 
779  struct EventWindow ev_w = { win, WN_NO_FLAGS };
781 #ifdef USE_DEBUG_WINDOW
782  debug_win_dump();
783 #endif
784 }
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:193
An Event that happened to a Window.
Definition: mutt_window.h:191
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:165
Window focus has changed.
Definition: mutt_window.h:185
A division of the screen.
Definition: mutt_window.h:115
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:43
struct MuttWindow * focus
Focussed Window.
Definition: mutt_window.h:133
struct Notify * notify
Notifications system.
Definition: mutt_window.h:131
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:128
void debug_win_dump(void)
Definition: window.c:88
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:152
+ 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 focussed Window.

Return values
ptrWindow with focus

Definition at line 790 of file mutt_window.c.

791 {
792  struct MuttWindow *win = RootWindow;
793 
794  while (win && win->focus)
795  win = win->focus;
796 
797  return win;
798 }
A division of the screen.
Definition: mutt_window.h:115
struct MuttWindow * focus
Focussed Window.
Definition: mutt_window.h:133
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:45
+ 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 806 of file mutt_window.c.

807 {
808  if (!mutt_window_is_visible(win))
809  return;
810 
811  for (int i = 0; i < win->state.rows; i++)
812  mutt_window_clearline(win, i);
813 }
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:232
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:657
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ RootWindow

struct MuttWindow* RootWindow = NULL

Parent of all Windows.

Definition at line 45 of file mutt_window.c.

◆ AllDialogsWindow

struct MuttWindow* AllDialogsWindow = NULL

Parent of all Dialogs.

Definition at line 46 of file mutt_window.c.

◆ MessageWindow

struct MuttWindow* MessageWindow = NULL

Message Window, ":set", etc.

Definition at line 47 of file mutt_window.c.

◆ EditorHelp

const struct Mapping EditorHelp[]
static
Initial value:
= {
{ N_("Complete"), OP_EDITOR_COMPLETE },
{ N_("Hist Up"), OP_EDITOR_HISTORY_UP },
{ N_("Hist Down"), OP_EDITOR_HISTORY_DOWN },
{ N_("Hist Search"), OP_EDITOR_HISTORY_SEARCH },
{ N_("Begin Line"), OP_EDITOR_BOL },
{ N_("End Line"), OP_EDITOR_EOL },
{ N_("Kill Line"), OP_EDITOR_KILL_LINE },
{ N_("Kill Word"), OP_EDITOR_KILL_WORD },
{ NULL, 0 },
}
#define N_(a)
Definition: message.h:32

Help Bar for the Command Line Editor.

Definition at line 50 of file mutt_window.c.