NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
DOXYGEN
msgwin.c
Go to the documentation of this file.
1
80#include "config.h"
81#include "mutt/lib.h"
82#include "msgwin.h"
83#include "color/lib.h"
84#include "mutt_curses.h"
85#include "mutt_window.h"
86
88static struct MuttWindow *MessageWindow = NULL;
89
94{
95 enum ColorId cid;
96 char *text;
97};
98
102static int msgwin_recalc(struct MuttWindow *win)
103{
104 if (window_is_focused(win)) // Someone else is using it
105 return 0;
106
107 win->actions |= WA_REPAINT;
108 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
109 return 0;
110}
111
115static int msgwin_repaint(struct MuttWindow *win)
116{
117 if (window_is_focused(win)) // someone else is using it
118 return 0;
119
120 struct MsgWinPrivateData *priv = win->wdata;
121
122 mutt_window_move(win, 0, 0);
123
125 mutt_window_move(win, 0, 0);
126 mutt_window_addstr(win, priv->text);
129
130 mutt_debug(LL_DEBUG5, "repaint done\n");
131 return 0;
132}
133
143{
144 if (nc->event_type != NT_WINDOW)
145 return 0;
146 if (!nc->global_data || !nc->event_data)
147 return -1;
148
149 struct MuttWindow *win_msg = nc->global_data;
150 struct EventWindow *ev_w = nc->event_data;
151 if (ev_w->win != win_msg)
152 return 0;
153
155 {
156 win_msg->actions |= WA_RECALC;
157 mutt_debug(LL_NOTIFY, "window state done, request WA_RECALC\n");
158 }
159 else if (nc->event_subtype == NT_WINDOW_DELETE)
160 {
162 MessageWindow = NULL;
163 mutt_debug(LL_DEBUG5, "window delete done\n");
164 }
165 return 0;
166}
167
171static void msgwin_wdata_free(struct MuttWindow *win, void **ptr)
172{
173 struct MsgWinPrivateData *priv = *ptr;
174
175 FREE(&priv->text);
176
177 FREE(ptr);
178}
179
185{
186 struct MsgWinPrivateData *msgwin_data = mutt_mem_calloc(1, sizeof(struct MsgWinPrivateData));
187
188 msgwin_data->cid = MT_COLOR_NORMAL;
189
190 return msgwin_data;
191}
192
198{
205
207
208 return MessageWindow;
209}
210
216const char *msgwin_get_text(void)
217{
218 if (!MessageWindow)
219 return NULL;
220
221 struct MsgWinPrivateData *priv = MessageWindow->wdata;
222
223 return priv->text;
224}
225
233void msgwin_set_text(enum ColorId cid, const char *text)
234{
235 if (!MessageWindow)
236 return;
237
238 struct MsgWinPrivateData *priv = MessageWindow->wdata;
239
240 priv->cid = cid;
241 mutt_str_replace(&priv->text, text);
242
244}
245
250{
252}
253
261{
262 return MessageWindow;
263}
264
270{
271 if (!MessageWindow)
272 return 0;
273
274 return MessageWindow->state.cols;
275}
276
283void msgwin_set_height(short height)
284{
285 if (!MessageWindow)
286 return;
287
288 if (height < 1)
289 height = 1;
290 else if (height > 3)
291 height = 3;
292
293 struct MuttWindow *win_cont = MessageWindow->parent;
294
295 win_cont->req_rows = height;
296 mutt_window_reflow(win_cont->parent);
297}
Color and attribute parsing.
ColorId
List of all colored objects.
Definition: color.h:38
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:57
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static int msgwin_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: msgwin.c:142
static int msgwin_recalc(struct MuttWindow *win)
Recalculate the display of the Message Window - Implements MuttWindow::recalc() -.
Definition: msgwin.c:102
static int msgwin_repaint(struct MuttWindow *win)
Redraw the Message Window - Implements MuttWindow::repaint() -.
Definition: msgwin.c:115
static void msgwin_wdata_free(struct MuttWindow *win, void **ptr)
Free the private data attached to the Message Window - Implements MuttWindow::wdata_free() -.
Definition: msgwin.c:171
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
@ LL_NOTIFY
Log of notifications.
Definition: logging.h:45
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:43
void msgwin_set_text(enum ColorId cid, const char *text)
Set the text for the Message Window.
Definition: msgwin.c:233
void msgwin_set_height(short height)
Resize the Message Window.
Definition: msgwin.c:283
const char * msgwin_get_text(void)
Get the text from the Message Window.
Definition: msgwin.c:216
static struct MuttWindow * MessageWindow
Message Window for messages, warnings, errors etc.
Definition: msgwin.c:88
static struct MsgWinPrivateData * msgwin_wdata_new(void)
Create new private data for the Message Window.
Definition: msgwin.c:184
size_t msgwin_get_width(void)
Get the width of the Message Window.
Definition: msgwin.c:269
struct MuttWindow * msgwin_get_window(void)
Get the Message Window pointer.
Definition: msgwin.c:260
struct MuttWindow * msgwin_new(void)
Create the Message Window.
Definition: msgwin.c:197
void msgwin_clear_text(void)
Clear the text in the Message Window.
Definition: msgwin.c:249
Message Window.
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:228
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:189
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:326
struct AttrColor * mutt_curses_set_normal_backed_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:65
struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:81
Define wrapper functions around Curses.
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:341
bool window_is_focused(const struct MuttWindow *win)
Does the given Window have the focus?
Definition: mutt_window.c:630
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:180
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:294
int mutt_window_addstr(struct MuttWindow *win, const char *str)
Write a string to a Window.
Definition: mutt_window.c:410
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:241
Window management.
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
@ WT_MESSAGE
Window for messages/errors and command entry.
Definition: mutt_window.h:99
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:206
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:205
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
#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:55
An Event that happened to a Window.
Definition: mutt_window.h:215
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:216
Private data for the Message Window.
Definition: msgwin.c:94
char * text
Cached display string.
Definition: msgwin.c:96
enum ColorId cid
Colour for the text, e.g. MT_COLOR_MESSAGE.
Definition: msgwin.c:95
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:181
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
short req_rows
Number of rows required.
Definition: mutt_window.h:125
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:170
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:37
void * global_data
Data from notify_observer_add()
Definition: observer.h:39
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60