NeoMutt  2025-12-11-949-g4870ee
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.
 
bool msgwin_has_text (void)
 Does the Message Window currently hold any text?
 
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

Clear the displayed text. If the Message Window is not the only Window in the Message Container, it is also hidden and the Windows are reflowed.

Definition at line 554 of file msgwin.c.

555{
556 if (!win)
557 win = msgcont_get_msgwin();
558 if (!win)
559 return;
560
561 struct MsgWinWindowData *wdata = win->wdata;
562
563 // Force-clear even if the window was hidden (msgwin_set_text would skip it).
564 if (!buf_is_empty(wdata->text))
565 {
566 buf_reset(wdata->text);
567 ARRAY_FREE(&wdata->chars);
568 for (int i = 0; i < MSGWIN_MAX_ROWS; i++)
569 {
570 ARRAY_FREE(&wdata->rows[i]);
571 }
572
573 if (win->state.visible)
574 {
575 int rows = msgwin_calc_rows(wdata, win->state.cols, buf_string(wdata->text));
576 msgwin_set_rows(win, rows);
577 win->actions |= WA_RECALC;
578 }
579 }
580
581 // If the Message Window isn't alone in the stack, hide it again so the
582 // Window beneath us regains the space.
583 if (win->state.visible && (msgcont_num_windows() > 1))
584 {
585 window_set_visible(win, false);
587 window_redraw(NULL);
588 }
589}
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:89
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:298
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
int msgcont_num_windows(void)
Count the Windows in the Message Container.
Definition msgcont.c:90
void msgcont_recalc_rows(void)
Recalculate the Bottom Bar height.
Definition msgcont.c:64
struct MuttWindow * msgcont_get_msgwin(void)
Get the Message Window.
Definition msgcont.c:190
int msgwin_calc_rows(struct MsgWinWindowData *wdata, int cols, const char *str)
How many rows will a string need?
Definition msgwin.c:179
void msgwin_set_rows(struct MuttWindow *win, short rows)
Resize the Message Window.
Definition msgwin.c:310
#define MSGWIN_MAX_ROWS
Maximum number of rows to show in the message window.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
void window_set_visible(struct MuttWindow *win, bool visible)
Set a Window visible or hidden.
@ WA_RECALC
Recalculate the contents of the Window.
Message Window private Window data.
struct Buffer * text
Cached display string.
struct MwCharArray chars
Text: Breakdown of bytes and widths.
struct MwChunkArray rows[MSGWIN_MAX_ROWS]
String byte counts for each row.
struct WindowState state
Current state of the Window.
void * wdata
Private data.
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
bool visible
Window is visible.
Definition mutt_window.h:59
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_has_text()

bool msgwin_has_text ( void )

Does the Message Window currently hold any text?

Return values
trueThe Message Window currently displays a message

Used by msgcont_push_window() to decide whether the Message Window should remain visible when another Window is pushed on top of it.

Definition at line 609 of file msgwin.c.

610{
611 struct MuttWindow *win = msgcont_get_msgwin();
612 if (!win || !win->wdata)
613 return false;
614
615 const struct MsgWinWindowData *wdata = win->wdata;
616 return !buf_is_empty(wdata->text);
617}
+ 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 381 of file msgwin.c.

382{
385
386 struct MsgWinWindowData *wdata = msgwin_wdata_new();
387
388 win->wdata = wdata;
390 win->recalc = msgwin_recalc;
391 win->repaint = msgwin_repaint;
392
393 if (interactive)
395
396 // Copy the container's dimensions
398 if (mod_data && mod_data->message_container)
399 win->state = mod_data->message_container->state;
400
402
403 return win;
404}
static int msgwin_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition msgwin.c:337
static int msgwin_recalc(struct MuttWindow *win)
Recalculate the display of the Message Window - Implements MuttWindow::recalc() -.
Definition msgwin.c:162
static bool msgwin_recursor(struct MuttWindow *win)
Recursor the Message Window - Implements MuttWindow::recursor() -.
Definition msgwin.c:290
static int msgwin_repaint(struct MuttWindow *win)
Redraw the Message Window - Implements MuttWindow::repaint() -.
Definition msgwin.c:255
void msgwin_wdata_free(struct MuttWindow *win, void **ptr)
Free the private data - Implements MuttWindow::wdata_free() -.
@ MODULE_ID_GUI
ModuleGui, Graphical code
Definition module_api.h:45
struct MsgWinWindowData * msgwin_wdata_new(void)
Create new private data for the Message Window.
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.
@ 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
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:666
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:58
Gui private Module data.
Definition module_data.h:32
struct MuttWindow * message_container
Message Container Window.
Definition module_data.h:38
int(* repaint)(struct MuttWindow *win)
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
int(* recalc)(struct MuttWindow *win)
void(* wdata_free)(struct MuttWindow *win, void **ptr)
bool(* recursor)(struct MuttWindow *win)
Container for Accounts, Notifications.
Definition neomutt.h:41
+ 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 431 of file msgwin.c.

432{
433 if (!win)
434 win = msgcont_get_msgwin();
435 if (!win)
436 return;
437
438 struct MsgWinWindowData *wdata = win->wdata;
439
440 if (text)
441 {
442 buf_addstr(wdata->text, text);
443 measure(&wdata->chars, text, ac_color);
444 mutt_debug(LL_DEBUG5, "MW ADD: %zu, %s\n", buf_len(wdata->text),
445 buf_string(wdata->text));
446 }
447 else
448 {
449 int rows = msgwin_calc_rows(wdata, win->state.cols, buf_string(wdata->text));
450 msgwin_set_rows(win, rows);
451 win->actions |= WA_RECALC;
452 }
453}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:497
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:233
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
void measure(struct MwCharArray *chars, const char *str, const struct AttrColor *ac_color)
Measure a string in bytes and cells.
Definition msgwin.c:107
+ 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 462 of file msgwin.c.

464{
465 if (!win)
466 win = msgcont_get_msgwin();
467 if (!win)
468 return;
469
470 struct MsgWinWindowData *wdata = win->wdata;
471
472 if (text)
473 {
474 const char *dptr = wdata->text->dptr;
475 buf_addstr_n(wdata->text, text, bytes);
476 measure(&wdata->chars, dptr, ac_color);
477 mutt_debug(LL_DEBUG5, "MW ADD: %zu, %s\n", buf_len(wdata->text),
478 buf_string(wdata->text));
479 }
480 else
481 {
482 int rows = msgwin_calc_rows(wdata, win->state.cols, buf_string(wdata->text));
483 msgwin_set_rows(win, rows);
484 win->actions |= WA_RECALC;
485 }
486}
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:109
char * dptr
Current read/write position.
Definition buffer.h:38
+ 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 413 of file msgwin.c.

414{
415 if (!win)
416 win = msgcont_get_msgwin();
417 if (!win)
418 return NULL;
419
420 struct MsgWinWindowData *wdata = win->wdata;
421
422 return buf_string(wdata->text);
423}
+ 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 597 of file msgwin.c.

598{
599 return msgcont_get_msgwin();
600}
+ 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 310 of file msgwin.c.

311{
312 if (!win)
313 win = msgcont_get_msgwin();
314 if (!win)
315 return;
316
317 rows = CLAMP(rows, 1, MSGWIN_MAX_ROWS);
318
319 if (rows != win->req_rows)
320 {
321 win->req_rows = rows;
322
324
325 mutt_window_reflow(NULL);
326 }
327}
#define CLAMP(val, lo, hi)
Clamp a value between a lower and upper bound.
Definition memory.h:42
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
short req_rows
Number of rows required.
+ 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

If the Message Window is currently hidden (because another Window has been pushed on top of it in the Message Container) it will make itself visible and trigger a reflow so the message is shown to the user.

Definition at line 500 of file msgwin.c.

501{
502 if (!win)
503 win = msgcont_get_msgwin();
504 if (!win)
505 return;
506
507 const bool hidden = !win->state.visible;
508
509 struct MsgWinWindowData *wdata = win->wdata;
510
511 // If the text is unchanged: nothing to do, except reveal the window if it
512 // was hidden so the user actually sees it.
513 if (mutt_str_equal(buf_string(wdata->text), text) && !hidden)
514 return;
515
516 buf_strcpy(wdata->text, text);
517 ARRAY_FREE(&wdata->chars);
518 if (wdata->text)
519 {
520 const struct AttrColor *ac_normal = simple_color_get(MT_COLOR_NORMAL);
521 const struct AttrColor *ac_color = simple_color_get(color);
522 const struct AttrColor *ac_merge = merged_color_overlay(ac_normal, ac_color);
523
524 measure(&wdata->chars, buf_string(wdata->text), ac_merge);
525 }
526
527 mutt_debug(LL_DEBUG5, "MW SET: %zu, %s\n", buf_len(wdata->text),
528 buf_string(wdata->text));
529
530 // If the window was hidden, reveal it and reflow so the message is seen.
531 if (!win->state.visible)
532 {
533 window_set_visible(win, true);
534 int rows = msgwin_calc_rows(wdata, win->state.cols, buf_string(wdata->text));
535 win->req_rows = CLAMP(rows, 1, MSGWIN_MAX_ROWS);
537 win->actions |= WA_RECALC;
538 window_redraw(NULL);
539 return;
540 }
541
542 int rows = msgwin_calc_rows(wdata, win->state.cols, buf_string(wdata->text));
543 msgwin_set_rows(win, rows);
544 win->actions |= WA_RECALC;
545}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:401
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition simple.c:98
@ MT_COLOR_NORMAL
Plain text.
Definition color.h:53
const struct AttrColor * merged_color_overlay(const struct AttrColor *base, const struct AttrColor *over)
Combine two colours.
Definition merged.c:110
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
A curses colour and its attributes.
Definition attr.h:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function: