NeoMutt  2025-12-11-949-g4870ee
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
msgcont.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdbool.h>
31#include <stddef.h>
32#include "mutt/lib.h"
33#include "core/lib.h"
34#include "msgcont.h"
35#include "module_data.h"
36#include "msgwin.h"
37#include "mutt_window.h"
38#ifdef USE_DEBUG_WINDOW
39#include "debug/lib.h"
40#endif
41
47{
52 if (mod_data)
53 mod_data->message_container = win;
54 return win;
55}
56
65{
67 if (!mod_data || !mod_data->message_container || !mod_data->bottom_bar)
68 return;
69
70 struct MuttWindow *mc = mod_data->message_container;
71 int rows = 0;
72 struct MuttWindow **wp = NULL;
73 ARRAY_FOREACH(wp, &mc->children)
74 {
75 if (!(*wp)->state.visible)
76 continue;
77 rows += MAX(0, (*wp)->req_rows);
78 }
79
80 if (rows < 1)
81 rows = 1;
82
83 mod_data->bottom_bar->req_rows = rows;
84}
85
91{
93 if (!mod_data || !mod_data->message_container)
94 return 0;
95
96 return ARRAY_SIZE(&mod_data->message_container->children);
97}
98
104{
106 if (!mod_data || !mod_data->message_container)
107 return NULL;
108
109 struct MuttWindow *mc = mod_data->message_container;
110
111 struct MuttWindow **wp_pop = ARRAY_LAST(&mc->children);
112 if (!wp_pop)
113 return NULL;
114
115 struct MuttWindow *win_pop = *wp_pop;
116
117 // Don't pop the last entry (check if there's a previous one)
118 if (ARRAY_SIZE(&mc->children) <= 1)
119 return NULL;
120
121 // Hide the old window
122 window_set_visible(win_pop, false);
123
124 // Get the window that will become top of stack
125 struct MuttWindow **wp_top = ARRAY_GET(&mc->children, ARRAY_SIZE(&mc->children) - 2);
126 struct MuttWindow *win_top = wp_top ? *wp_top : NULL;
127
128 ARRAY_REMOVE(&mc->children, wp_pop);
129
130 if (win_top)
131 {
132 window_set_visible(win_top, true);
133 win_top->actions |= WA_RECALC;
134 }
135
137
138 mutt_window_reflow(NULL);
139 window_redraw(NULL);
140#ifdef USE_DEBUG_WINDOW
142#endif
143 return win_pop;
144}
145
151{
153 if (!mod_data || !mod_data->message_container || !win)
154 return;
155
156 struct MuttWindow *mc = mod_data->message_container;
157 const bool keep_msgwin = msgwin_has_text();
158
159 // Hide all currently visible children: the new window will take over the
160 // space. If the Message Window currently holds any text, it should remain
161 // visible so the user still sees the message.
162 struct MuttWindow **wp = NULL;
163 ARRAY_FOREACH(wp, &mc->children)
164 {
165 if (!(*wp)->state.visible)
166 continue;
167 if (keep_msgwin && ((*wp)->type == WT_MESSAGE))
168 continue;
169 window_set_visible(*wp, false);
170 }
171
172 mutt_window_add_child(mc, win);
173
175
176 mutt_window_reflow(NULL);
177 window_redraw(NULL);
178#ifdef USE_DEBUG_WINDOW
180#endif
181}
182
191{
193 if (!mod_data || !mod_data->message_container)
194 return NULL;
195
196 struct MuttWindow **wp = ARRAY_FIRST(&mod_data->message_container->children);
197 if (!wp)
198 return NULL;
199
200 struct MuttWindow *win = *wp;
201 if (win->type != WT_MESSAGE)
202 return NULL;
203
204 return win;
205}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition array.h:136
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:355
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_LAST(head)
Convenience method to get the last element.
Definition array.h:145
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
Convenience wrapper for the core headers.
Convenience wrapper for the debug headers.
void debug_win_dump(void)
Dump all windows to debug output.
Definition window.c:116
Gui private Module data.
#define MAX(a, b)
Return the maximum of two values.
Definition memory.h:38
@ MODULE_ID_GUI
ModuleGui, Graphical code
Definition module_api.h:45
struct MuttWindow * msgcont_new(void)
Create a new Message Container.
Definition msgcont.c:46
int msgcont_num_windows(void)
Count the Windows in the Message Container.
Definition msgcont.c:90
void msgcont_push_window(struct MuttWindow *win)
Add a window to the Container Stack.
Definition msgcont.c:150
void msgcont_recalc_rows(void)
Recalculate the Bottom Bar height.
Definition msgcont.c:64
struct MuttWindow * msgcont_pop_window(void)
Remove the last Window from the Container Stack.
Definition msgcont.c:103
struct MuttWindow * msgcont_get_msgwin(void)
Get the Message Window.
Definition msgcont.c:190
Message Window.
bool msgwin_has_text(void)
Does the Message Window currently hold any text?
Definition msgwin.c:609
Message Window.
Convenience wrapper for the library headers.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
void window_set_visible(struct MuttWindow *win, bool visible)
Set a Window visible or hidden.
Window management.
@ WT_MESSAGE
Window for messages/errors.
Definition mutt_window.h:99
@ WT_CONTAINER
Invisible shaping container Window.
Definition mutt_window.h:73
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition mutt_window.h:38
@ WA_RECALC
Recalculate the contents of the Window.
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition mutt_window.h:52
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition mutt_window.h:48
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:666
Gui private Module data.
Definition module_data.h:32
struct MuttWindow * message_container
Message Container Window.
Definition module_data.h:38
struct MuttWindow * bottom_bar
Bottom Bar Container Window.
Definition module_data.h:37
struct MuttWindowArray children
Children Windows.
short req_rows
Number of rows required.
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Container for Accounts, Notifications.
Definition neomutt.h:41