NeoMutt  2018-07-16 +952-a2da0a
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/mutt.h"
#include "mutt_window.h"
#include "globals.h"
#include "menu.h"
#include "options.h"
+ Include dependency graph for mutt_window.c:

Go to the source code of this file.

Functions

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...
 
void mutt_window_free (void)
 Free the default Windows. More...
 
void mutt_window_getxy (struct MuttWindow *win, int *x, int *y)
 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 row, int col)
 Move the cursor in a Window. More...
 
int mutt_window_mvaddch (struct MuttWindow *win, int row, int col, const chtype ch)
 Move the cursor and write a character to a Window. More...
 
int mutt_window_mvaddstr (struct MuttWindow *win, int row, int col, const char *str)
 Move the cursor and write a fixed string to a Window. More...
 
int mutt_window_mvprintw (struct MuttWindow *win, int row, int col, const char *fmt,...)
 Move the cursor and write a formatted string to a Window. More...
 
void mutt_window_reflow (void)
 Resize the Windows to fit the screen. More...
 
void mutt_window_reflow_message_rows (int mw_rows)
 Resize the Message Window. More...
 
int mutt_window_wrap_cols (struct MuttWindow *win, short wrap)
 Calculate the wrap column for a Window. More...
 

Variables

struct MuttWindowMuttHelpWindow = NULL
 Help Window. More...
 
struct MuttWindowMuttIndexWindow = NULL
 Index Window. More...
 
struct MuttWindowMuttStatusWindow = NULL
 Status Window. More...
 
struct MuttWindowMuttMessageWindow = NULL
 Message Window. More...
 
struct MuttWindowMuttSidebarWindow = NULL
 Sidebar 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

void mutt_window_clearline ( struct MuttWindow win,
int  row 
)

Clear a row of a Window.

Parameters
winWindow
rowRow to clear

Definition at line 69 of file mutt_window.c.

70 {
71  mutt_window_move(win, row, 0);
73 }
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:81
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

82 {
83  if (!win || !stdscr)
84  return;
85 
86  if (win->col_offset + win->cols == COLS)
87  clrtoeol();
88  else
89  {
90  int row = 0;
91  int col = 0;
92  getyx(stdscr, row, col);
93  int curcol = col;
94  while (curcol < (win->col_offset + win->cols))
95  {
96  addch(' ');
97  curcol++;
98  }
99  move(row, col);
100  }
101 }
int col_offset
Definition: mutt_window.h:38

+ Here is the caller graph for this function:

void mutt_window_free ( void  )

Free the default Windows.

Definition at line 106 of file mutt_window.c.

107 {
112 #ifdef USE_SIDEBAR
114 #endif
115 }
struct MuttWindow * MuttStatusWindow
Status Window.
Definition: mutt_window.c:40
struct MuttWindow * MuttHelpWindow
Help Window.
Definition: mutt_window.c:38
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
struct MuttWindow * MuttSidebarWindow
Sidebar Window.
Definition: mutt_window.c:43
#define FREE(x)
Definition: memory.h:46
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41

+ Here is the caller graph for this function:

void mutt_window_getxy ( struct MuttWindow win,
int *  x,
int *  y 
)

Get the cursor position in the Window.

Parameters
[in]winWindow
[out]xX-Coordinate
[out]yY-Coordinate

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

Definition at line 126 of file mutt_window.c.

127 {
128  int row = 0;
129  int col = 0;
130 
131  getyx(stdscr, row, col);
132  if (x)
133  *x = col - win->col_offset;
134  if (y)
135  *y = row - win->row_offset;
136 }
int row_offset
Definition: mutt_window.h:37
int col_offset
Definition: mutt_window.h:38

+ Here is the caller graph for this function:

void mutt_window_init ( void  )

Create the default Windows.

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

Definition at line 143 of file mutt_window.c.

144 {
145  MuttHelpWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
146  MuttIndexWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
147  MuttStatusWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
148  MuttMessageWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
149 #ifdef USE_SIDEBAR
150  MuttSidebarWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
151 #endif
152 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
struct MuttWindow * MuttStatusWindow
Status Window.
Definition: mutt_window.c:40
struct MuttWindow * MuttHelpWindow
Help Window.
Definition: mutt_window.c:38
A division of the screen.
Definition: mutt_window.h:33
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
struct MuttWindow * MuttSidebarWindow
Sidebar Window.
Definition: mutt_window.c:43
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Move the cursor in a Window.

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

Definition at line 162 of file mutt_window.c.

163 {
164  return move(win->row_offset + row, win->col_offset + col);
165 }
int row_offset
Definition: mutt_window.h:37
int col_offset
Definition: mutt_window.h:38

+ Here is the caller graph for this function:

int mutt_window_mvaddch ( struct MuttWindow win,
int  row,
int  col,
const chtype  ch 
)

Move the cursor and write a character to a Window.

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

Definition at line 176 of file mutt_window.c.

177 {
178  return mvaddch(win->row_offset + row, win->col_offset + col, ch);
179 }
int row_offset
Definition: mutt_window.h:37
int col_offset
Definition: mutt_window.h:38
int mutt_window_mvaddstr ( struct MuttWindow win,
int  row,
int  col,
const char *  str 
)

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

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

Definition at line 190 of file mutt_window.c.

191 {
192  return mvaddstr(win->row_offset + row, win->col_offset + col, str);
193 }
int row_offset
Definition: mutt_window.h:37
int col_offset
Definition: mutt_window.h:38

+ Here is the caller graph for this function:

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

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

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

Definition at line 205 of file mutt_window.c.

206 {
207  int rc = mutt_window_move(win, row, col);
208  if (rc == ERR)
209  return rc;
210 
211  va_list ap;
212  va_start(ap, fmt);
213  rc = vw_printw(stdscr, fmt, ap);
214  va_end(ap);
215 
216  return rc;
217 }
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_window_reflow ( void  )

Resize the Windows to fit the screen.

Definition at line 222 of file mutt_window.c.

223 {
224  if (OptNoCurses)
225  return;
226 
227  mutt_debug(2, "entering\n");
228 
229  MuttStatusWindow->rows = 1;
230  MuttStatusWindow->cols = COLS;
231  MuttStatusWindow->row_offset = StatusOnTop ? 0 : LINES - 2;
233 
234  memcpy(MuttHelpWindow, MuttStatusWindow, sizeof(struct MuttWindow));
235  if (!Help)
236  MuttHelpWindow->rows = 0;
237  else
238  MuttHelpWindow->row_offset = StatusOnTop ? LINES - 2 : 0;
239 
240  memcpy(MuttMessageWindow, MuttStatusWindow, sizeof(struct MuttWindow));
241  MuttMessageWindow->row_offset = LINES - 1;
242 
243  memcpy(MuttIndexWindow, MuttStatusWindow, sizeof(struct MuttWindow));
248 
249 #ifdef USE_SIDEBAR
250  if (SidebarVisible)
251  {
252  memcpy(MuttSidebarWindow, MuttIndexWindow, sizeof(struct MuttWindow));
255 
256  if (SidebarOnRight)
257  {
259  }
260  else
261  {
263  }
264  }
265 #endif
266 
268  /* the pager menu needs this flag set to recalc line_info */
270 }
struct MuttWindow * MuttStatusWindow
Status Window.
Definition: mutt_window.c:40
WHERE bool Help
Config: Display a help line with common key bindings.
Definition: globals.h:222
WHERE bool SidebarOnRight
Config: (sidebar) Display the sidebar on the right.
Definition: globals.h:255
struct MuttWindow * MuttHelpWindow
Help Window.
Definition: mutt_window.c:38
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:45
A division of the screen.
Definition: mutt_window.h:33
WHERE bool SidebarVisible
Config: (sidebar) Show the sidebar.
Definition: globals.h:254
#define MAX(a, b)
Definition: memory.h:30
WHERE short SidebarWidth
Config: (sidebar) Width of the sidebar.
Definition: globals.h:160
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
WHERE bool StatusOnTop
Config: Display the status bar at the top.
Definition: globals.h:257
struct MuttWindow * MuttSidebarWindow
Sidebar Window.
Definition: mutt_window.c:43
int row_offset
Definition: mutt_window.h:37
int col_offset
Definition: mutt_window.h:38
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
#define mutt_debug(LEVEL,...)
Definition: logging.h:85

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

279 {
280  MuttMessageWindow->rows = mw_rows;
281  MuttMessageWindow->row_offset = LINES - mw_rows;
282 
283  MuttStatusWindow->row_offset = StatusOnTop ? 0 : LINES - mw_rows - 1;
284 
285  if (Help)
286  MuttHelpWindow->row_offset = StatusOnTop ? LINES - mw_rows - 1 : 0;
287 
290 
291 #ifdef USE_SIDEBAR
292  if (SidebarVisible)
294 #endif
295 
296  /* We don't also set REDRAW_FLOW because this function only
297  * changes rows and is a temporary adjustment. */
299 }
struct MuttWindow * MuttStatusWindow
Status Window.
Definition: mutt_window.c:40
WHERE bool Help
Config: Display a help line with common key bindings.
Definition: globals.h:222
struct MuttWindow * MuttHelpWindow
Help Window.
Definition: mutt_window.c:38
WHERE bool SidebarVisible
Config: (sidebar) Show the sidebar.
Definition: globals.h:254
#define MAX(a, b)
Definition: memory.h:30
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
WHERE bool StatusOnTop
Config: Display the status bar at the top.
Definition: globals.h:257
struct MuttWindow * MuttSidebarWindow
Sidebar Window.
Definition: mutt_window.c:43
int row_offset
Definition: mutt_window.h:37
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_window_wrap_cols ( struct MuttWindow win,
short  wrap 
)

Calculate the wrap column for a Window.

Parameters
winWindow
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 309 of file mutt_window.c.

310 {
311  if (wrap < 0)
312  return (win->cols > -wrap) ? (win->cols + wrap) : win->cols;
313  else if (wrap)
314  return (wrap < win->cols) ? wrap : win->cols;
315  else
316  return win->cols;
317 }

+ Here is the caller graph for this function:

Variable Documentation

struct MuttWindow* MuttHelpWindow = NULL

Help Window.

Definition at line 38 of file mutt_window.c.

struct MuttWindow* MuttIndexWindow = NULL

Index Window.

Definition at line 39 of file mutt_window.c.

struct MuttWindow* MuttStatusWindow = NULL

Status Window.

Definition at line 40 of file mutt_window.c.

struct MuttWindow* MuttMessageWindow = NULL

Message Window.

Definition at line 41 of file mutt_window.c.

struct MuttWindow* MuttSidebarWindow = NULL

Sidebar Window.

Definition at line 43 of file mutt_window.c.