NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
msgwin.c
Go to the documentation of this file.
1 
82 #include "config.h"
83 #include <stddef.h>
84 #include "mutt/lib.h"
85 #include "color.h"
86 #include "curs_lib.h"
87 #include "mutt_curses.h"
88 #include "mutt_window.h"
89 
90 struct MuttWindow *MessageWindow = NULL;
91 
96 {
97  enum ColorId color;
98  char *text;
99 };
100 
104 static int msgwin_recalc(struct MuttWindow *win)
105 {
106  if (window_is_focused(win)) // Someone else is using it
107  return 0;
108 
109  win->actions |= WA_REPAINT;
110  mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
111  return 0;
112 }
113 
117 static int msgwin_repaint(struct MuttWindow *win)
118 {
119  if (!mutt_window_is_visible(win) || window_is_focused(win)) // or someone else is using it
120  return 0;
121 
122  struct MsgWinPrivateData *priv = win->wdata;
123 
124  mutt_window_move(win, 0, 0);
125 
127  mutt_window_move(win, 0, 0);
128  mutt_paddstr(win, win->state.cols, priv->text);
130 
131  mutt_debug(LL_DEBUG5, "repaint done\n");
132  return 0;
133 }
134 
144 {
145  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
146  return -1;
147 
148  struct MuttWindow *win_msg = nc->global_data;
149  struct EventWindow *ev_w = nc->event_data;
150  if (ev_w->win != win_msg)
151  return 0;
152 
153  if (nc->event_subtype == NT_WINDOW_STATE)
154  {
155  win_msg->actions |= WA_RECALC;
156  mutt_debug(LL_NOTIFY, "window state done, request WA_RECALC\n");
157  }
158  else if (nc->event_subtype == NT_WINDOW_DELETE)
159  {
161  MessageWindow = NULL;
162  mutt_debug(LL_DEBUG5, "window delete done\n");
163  }
164  return 0;
165 }
166 
170 static void msgwin_wdata_free(struct MuttWindow *win, void **ptr)
171 {
172  struct MsgWinPrivateData *priv = *ptr;
173 
174  FREE(&priv->text);
175 
176  FREE(ptr);
177 }
178 
184 {
185  struct MsgWinPrivateData *msgwin_data =
186  mutt_mem_calloc(1, sizeof(struct MsgWinPrivateData));
187 
188  msgwin_data->color = MT_COLOR_NORMAL;
189 
190  return msgwin_data;
191 }
192 
197 struct MuttWindow *msgwin_new(void)
198 {
199  struct MuttWindow *win =
202 
203  win->wdata = msgwin_wdata_new();
205  win->recalc = msgwin_recalc;
206  win->repaint = msgwin_repaint;
207 
209 
210  MessageWindow = win;
211  return win;
212 }
213 
223 void msgwin_set_text(enum ColorId color, const char *text)
224 {
225  if (!MessageWindow)
226  return;
227 
228  struct MsgWinPrivateData *priv = MessageWindow->wdata;
229 
230  priv->color = color;
231  mutt_str_replace(&priv->text, text);
232 
233  MessageWindow->actions |= WA_RECALC;
234  window_redraw(MessageWindow);
235 }
236 
243 {
245 }
246 
254 {
255  return MessageWindow;
256 }
257 
262 size_t msgwin_get_width(void)
263 {
264  if (!MessageWindow)
265  return 0;
266 
267  return MessageWindow->state.cols;
268 }
269 
276 void msgwin_set_height(short height)
277 {
278  if (!MessageWindow)
279  return;
280 
281  if (height < 1)
282  height = 1;
283  else if (height > 3)
284  height = 3;
285 
286  MessageWindow->req_rows = height;
287  mutt_window_reflow(MessageWindow->parent);
288 }
enum ColorId color
Colour for the text, e.g. MT_COLOR_MESSAGE.
Definition: msgwin.c:97
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
Define wrapper functions around Curses/Slang.
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
Data passed to a notification function.
Definition: observer.h:39
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
Window management.
Log of notifications.
Definition: logging.h:45
GUI miscellaneous curses (window drawing) routines.
An Event that happened to a Window.
Definition: mutt_window.h:215
Window for messages/errors and command entry.
Definition: mutt_window.h:99
Window uses all available vertical space.
Definition: mutt_window.h:38
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:56
size_t msgwin_get_width(void)
Get the width of the Message Window.
Definition: msgwin.c:262
static struct MsgWinPrivateData * msgwin_wdata_new(void)
Create new private data for the Message Window.
Definition: msgwin.c:183
Window is about to be deleted.
Definition: mutt_window.h:206
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:632
struct MuttWindow * msgwin_new(void)
Create the Message Window.
Definition: msgwin.c:197
void msgwin_set_height(short height)
Resize the Message Window.
Definition: msgwin.c:276
void msgwin_clear_text(void)
Clear the text in the Message Window.
Definition: msgwin.c:242
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:310
static int msgwin_recalc(struct MuttWindow *win)
Recalculate the display of the Message Window - Implements MuttWindow::recalc() -.
Definition: msgwin.c:104
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindow * msgwin_get_window(void)
Get the Message Window pointer.
Definition: msgwin.c:253
ColorId
List of all colored objects.
Definition: color.h:39
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
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Private data for the Message Window.
Definition: msgwin.c:95
Window has a fixed size.
Definition: mutt_window.h:47
Plain text.
Definition: color.h:58
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
static int msgwin_repaint(struct MuttWindow *win)
Redraw the Message Window - Implements MuttWindow::repaint() -.
Definition: msgwin.c:117
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:529
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
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:170
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Color and attribute parsing.
void * event_data
Data from notify_send()
Definition: observer.h:44
struct MuttWindow * MessageWindow
Message Window, ":set", etc.
Definition: msgwin.c:90
static int msgwin_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: msgwin.c:143
bool window_is_focused(struct MuttWindow *win)
Does the given Window have the focus?
Definition: mutt_window.c:650
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:361
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
char * text
Cached display string.
Definition: msgwin.c:98
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
#define FREE(x)
Definition: memory.h:40
short req_rows
Number of rows required.
Definition: mutt_window.h:125
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:171
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
Log at debug level 5.
Definition: logging.h:44
Convenience wrapper for the library headers.
void * wdata
Private data.
Definition: mutt_window.h:145
void mutt_paddstr(struct MuttWindow *win, int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:890
void msgwin_set_text(enum ColorId color, const char *text)
Set the text for the Message Window.
Definition: msgwin.c:223
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110