NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
msgwin.h File Reference

Message Window. More...

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

Go to the source code of this file.

Functions

void msgwin_clear_text (struct MuttWindow *win)
 Clear the text in the Message Window.
 
struct MuttWindowmsgwin_new (bool interactive)
 Create the Message Window.
 
void msgwin_add_text (struct MuttWindow *win, const char *text, const struct AttrColor *ac_color)
 Add text to the Message Window.
 
void msgwin_add_text_n (struct MuttWindow *win, const char *text, int bytes, const struct AttrColor *ac_color)
 Add some text to the Message Window.
 
const char * msgwin_get_text (struct MuttWindow *win)
 Get the text from the Message Window.
 
struct MuttWindowmsgwin_get_window (void)
 Get the Message Window pointer.
 
void msgwin_set_rows (struct MuttWindow *win, short rows)
 Resize the Message Window.
 
void msgwin_set_text (struct MuttWindow *win, const char *text, enum ColorId color)
 Set the text for the Message Window.
 

Detailed Description

Message Window.

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

Function Documentation

◆ msgwin_clear_text()

void msgwin_clear_text ( struct MuttWindow win)

Clear the text in the Message Window.

Parameters
winMessage Window

Definition at line 515 of file msgwin.c.

516{
518}
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:57
void msgwin_set_text(struct MuttWindow *win, const char *text, enum ColorId color)
Set the text for the Message Window.
Definition: msgwin.c:486
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgwin_new()

struct MuttWindow * msgwin_new ( bool  interactive)

Create the Message Window.

Return values
ptrNew Window

Definition at line 373 of file msgwin.c.

374{
377
378 struct MsgWinWindowData *wdata = msgwin_wdata_new();
379
380 win->wdata = wdata;
382 win->recalc = msgwin_recalc;
383 win->repaint = msgwin_repaint;
384
385 if (interactive)
387
388 // Copy the container's dimensions
390
392
393 return win;
394}
static int msgwin_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: msgwin.c:329
static int msgwin_recalc(struct MuttWindow *win)
Recalculate the display of the Message Window - Implements MuttWindow::recalc() -.
Definition: msgwin.c:163
static bool msgwin_recursor(struct MuttWindow *win)
Recursor the Message Window - Implements MuttWindow::recursor() -.
Definition: msgwin.c:285
static int msgwin_repaint(struct MuttWindow *win)
Redraw the Message Window - Implements MuttWindow::repaint() -.
Definition: msgwin.c:253
void msgwin_wdata_free(struct MuttWindow *win, void **ptr)
Free the private data attached to the Message Window - Implements MuttWindow::wdata_free() -.
Definition: msgwin_wdata.c:37
struct MuttWindow * MessageContainer
Window acting as a stack for the message windows.
Definition: msgcont.c:40
struct MsgWinWindowData * msgwin_wdata_new(void)
Create new private data for the Message Window.
Definition: msgwin_wdata.c:60
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:191
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:182
@ WT_MESSAGE
Window for messages/errors.
Definition: mutt_window.h:99
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:47
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
Message Window private Window data.
Definition: msgwin_wdata.h:66
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:187
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:173
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
bool(* recursor)(struct MuttWindow *win)
Definition: mutt_window.h:205
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgwin_add_text()

void msgwin_add_text ( struct MuttWindow win,
const char *  text,
const struct AttrColor ac_color 
)

Add text to the Message Window.

Parameters
winMessage Window
textText to add
ac_colorColour for text

Definition at line 421 of file msgwin.c.

422{
423 if (!win)
424 win = msgcont_get_msgwin();
425 if (!win)
426 return;
427
428 struct MsgWinWindowData *wdata = win->wdata;
429
430 if (text)
431 {
432 buf_addstr(wdata->text, text);
433 measure(&wdata->chars, text, ac_color);
434 mutt_debug(LL_DEBUG1, "MW ADD: %zu, %s\n", buf_len(wdata->text),
435 buf_string(wdata->text));
436 }
437 else
438 {
439 int rows = msgwin_calc_rows(wdata, win->state.cols, buf_string(wdata->text));
440 msgwin_set_rows(win, rows);
441 win->actions |= WA_RECALC;
442 }
443}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:466
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:238
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
struct MuttWindow * msgcont_get_msgwin(void)
Get the Message Window.
Definition: msgcont.c:117
int msgwin_calc_rows(struct MsgWinWindowData *wdata, int cols, const char *str)
How many rows will a string need?
Definition: msgwin.c:180
void measure(struct MwCharArray *chars, const char *str, const struct AttrColor *ac_color)
Measure a string in bytes and cells.
Definition: msgwin.c:106
void msgwin_set_rows(struct MuttWindow *win, short rows)
Resize the Message Window.
Definition: msgwin.c:305
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
struct Buffer * text
Cached display string.
Definition: msgwin_wdata.h:67
struct MwCharArray chars
Text: Breakdown of bytes and widths.
Definition: msgwin_wdata.h:68
struct MwChunkArray rows[MSGWIN_MAX_ROWS]
String byte counts for each row.
Definition: msgwin_wdata.h:69
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgwin_add_text_n()

void msgwin_add_text_n ( struct MuttWindow win,
const char *  text,
int  bytes,
const struct AttrColor ac_color 
)

Add some text to the Message Window.

Parameters
winMessage Window
textText to add
bytesNumber of bytes of text to add
ac_colorColour for text

Definition at line 452 of file msgwin.c.

454{
455 if (!win)
456 win = msgcont_get_msgwin();
457 if (!win)
458 return;
459
460 struct MsgWinWindowData *wdata = win->wdata;
461
462 if (text)
463 {
464 const char *dptr = wdata->text->dptr;
465 buf_addstr_n(wdata->text, text, bytes);
466 measure(&wdata->chars, dptr, ac_color);
467 mutt_debug(LL_DEBUG1, "MW ADD: %zu, %s\n", buf_len(wdata->text),
468 buf_string(wdata->text));
469 }
470 else
471 {
472 int rows = msgwin_calc_rows(wdata, win->state.cols, buf_string(wdata->text));
473 msgwin_set_rows(win, rows);
474 win->actions |= WA_RECALC;
475 }
476}
size_t buf_addstr_n(struct Buffer *buf, const char *s, size_t len)
Add a string to a Buffer, expanding it if necessary.
Definition: buffer.c:108
char * dptr
Current read/write position.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgwin_get_text()

const char * msgwin_get_text ( struct MuttWindow win)

Get the text from the Message Window.

Parameters
winMessage Window
Return values
ptrWindow text
Note
Do not free the returned string

Definition at line 403 of file msgwin.c.

404{
405 if (!win)
406 win = msgcont_get_msgwin();
407 if (!win)
408 return NULL;
409
410 struct MsgWinWindowData *wdata = win->wdata;
411
412 return buf_string(wdata->text);
413}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgwin_get_window()

struct MuttWindow * msgwin_get_window ( void  )

Get the Message Window pointer.

Return values
ptrMessage Window

Allow some users direct access to the Message Window.

Definition at line 526 of file msgwin.c.

527{
528 return msgcont_get_msgwin();
529}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgwin_set_rows()

void msgwin_set_rows ( struct MuttWindow win,
short  rows 
)

Resize the Message Window.

Parameters
winMessage Window
rowsNumber of rows required

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

Note
rows will be clamped between 1 and 3 (MSGWIN_MAX_ROWS) inclusive

Definition at line 305 of file msgwin.c.

306{
307 if (!win)
308 win = msgcont_get_msgwin();
309 if (!win)
310 return;
311
312 rows = CLAMP(rows, 1, MSGWIN_MAX_ROWS);
313
314 if (rows != win->state.rows)
315 {
316 win->req_rows = rows;
317 mutt_window_reflow(NULL);
318 }
319}
#define CLAMP(val, lo, hi)
Definition: memory.h:33
#define MSGWIN_MAX_ROWS
Definition: msgwin_wdata.h:30
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:344
short req_rows
Number of rows required.
Definition: mutt_window.h:125
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgwin_set_text()

void msgwin_set_text ( struct MuttWindow win,
const char *  text,
enum ColorId  color 
)

Set the text for the Message Window.

Parameters
winMessage Window
textText to set
colorColour for text
Note
The text string will be copied

Definition at line 486 of file msgwin.c.

487{
488 if (!win)
489 win = msgcont_get_msgwin();
490 if (!win)
491 return;
492
493 struct MsgWinWindowData *wdata = win->wdata;
494
495 buf_strcpy(wdata->text, text);
496 ARRAY_FREE(&wdata->chars);
497 if (wdata->text)
498 {
499 const struct AttrColor *ac_color = simple_color_get(MT_COLOR_PROMPT);
500 measure(&wdata->chars, buf_string(wdata->text), ac_color);
501 }
502
503 mutt_debug(LL_DEBUG1, "MW SET: %zu, %s\n", buf_len(wdata->text),
504 buf_string(wdata->text));
505
506 int rows = msgwin_calc_rows(wdata, win->state.cols, buf_string(wdata->text));
507 msgwin_set_rows(win, rows);
508 win->actions |= WA_RECALC;
509}
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:203
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:407
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:81
@ MT_COLOR_PROMPT
Question/user input.
Definition: color.h:60
A curses colour and its attributes.
Definition: attr.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function: