NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dialog.c
Go to the documentation of this file.
1
22
69
70#include "config.h"
71#include <stdbool.h>
72#include <stddef.h>
73#include "mutt/lib.h"
74#include "core/lib.h"
75#include "dialog.h"
76#include "module_data.h"
77#include "mutt_window.h"
78#ifdef USE_DEBUG_WINDOW
79#include "debug/lib.h"
80#endif
81
89struct MuttWindow *dialog_find(struct MuttWindow *win)
90{
91 for (; win && win->parent; win = win->parent)
92 {
93 if (win->parent->type == WT_ALL_DIALOGS)
94 return win;
95 }
96
97 return NULL;
98}
99
109void dialog_push(struct MuttWindow *dlg)
110{
111 if (!dlg)
112 return;
113
115 if (!mod_data || !mod_data->all_dialogs_window)
116 return;
117
118 struct MuttWindow *win_alldlgs = mod_data->all_dialogs_window;
119
120 struct MuttWindow **wp_last = ARRAY_LAST(&win_alldlgs->children);
121 if (wp_last)
122 (*wp_last)->state.visible = false;
123
124 ARRAY_ADD(&win_alldlgs->children, dlg);
125 notify_set_parent(dlg->notify, win_alldlgs->notify);
126
127 // Notify the world, allowing plugins to integrate
128 mutt_debug(LL_NOTIFY, "NT_WINDOW_DIALOG visible: %s, %p\n",
129 mutt_window_win_name(dlg), (void *) dlg);
130 struct EventWindow ev_w = { dlg, WN_VISIBLE };
132
133 dlg->state.visible = true;
134 dlg->parent = win_alldlgs;
135 mutt_window_reflow(win_alldlgs);
136
137#ifdef USE_DEBUG_WINDOW
139#endif
140}
141
148void dialog_pop(void)
149{
151 if (!mod_data || !mod_data->all_dialogs_window)
152 return;
153
154 struct MuttWindow *win_alldlgs = mod_data->all_dialogs_window;
155
156 struct MuttWindow **wp_last = ARRAY_LAST(&win_alldlgs->children);
157 if (!wp_last)
158 return;
159
160 struct MuttWindow *win_last = *wp_last;
161
162 // Notify the world, allowing plugins to clean up
163 mutt_debug(LL_NOTIFY, "NT_WINDOW_DIALOG hidden: %s, %p\n",
164 mutt_window_win_name(win_last), (void *) win_last);
165 struct EventWindow ev_w = { win_last, WN_HIDDEN };
166 notify_send(win_last->notify, NT_WINDOW, NT_WINDOW_DIALOG, &ev_w);
167
168 win_last->state.visible = false;
169 win_last->parent = NULL;
170 ARRAY_REMOVE(&win_alldlgs->children, wp_last);
171
172 wp_last = ARRAY_LAST(&win_alldlgs->children);
173 if (wp_last)
174 {
175 (*wp_last)->state.visible = true;
176 mutt_window_reflow(win_alldlgs);
177 }
178 else
179 {
180 win_alldlgs->focus = NULL;
181 }
182#ifdef USE_DEBUG_WINDOW
184#endif
185}
186
195{
196 if (nc->event_type != NT_WINDOW)
197 return 0;
198 if (!nc->global_data || !nc->event_data)
199 return -1;
201 return 0;
202
203 struct MuttWindow *win_alldlgs = nc->global_data;
204 struct EventWindow *ev_w = nc->event_data;
205 if (ev_w->win != win_alldlgs)
206 return 0;
207
208 notify_observer_remove(win_alldlgs->notify, alldialogs_window_observer, win_alldlgs);
209
211 if (mod_data)
212 mod_data->all_dialogs_window = NULL;
213 mutt_debug(LL_DEBUG5, "window delete done\n");
214 return 0;
215}
216
224{
228
230
232 if (mod_data)
233 mod_data->all_dialogs_window = win_alldlgs;
234
235 return win_alldlgs;
236}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:355
#define ARRAY_LAST(head)
Convenience method to get the last element.
Definition array.h:145
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
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition dialog.c:109
void dialog_pop(void)
Hide a Window from the user.
Definition dialog.c:148
struct MuttWindow * alldialogs_new(void)
Create the AllDialogs Window.
Definition dialog.c:223
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition dialog.c:89
Dialog Windows.
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int alldialogs_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition dialog.c:194
Gui private Module data.
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:50
@ MODULE_ID_GUI
ModuleGui, Graphical code
Definition module_api.h:45
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:230
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
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition notify.c:173
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition notify.c:95
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Window management.
@ WT_ALL_DIALOGS
Container for All Dialogs (nested Windows)
Definition mutt_window.h:74
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition mutt_window.h:38
@ NT_WINDOW_DIALOG
A new Dialog Window has been created, e.g. WT_DLG_INDEX.
@ NT_WINDOW_DELETE
Window is about to be deleted.
#define WN_VISIBLE
Window became visible.
#define WN_HIDDEN
Window became hidden.
#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:665
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:57
An Event that happened to a Window.
struct MuttWindow * win
Window that changed.
Gui private Module data.
Definition module_data.h:32
struct MuttWindow * all_dialogs_window
Parent of all Dialogs.
Definition module_data.h:38
struct MuttWindowArray children
Children Windows.
struct WindowState state
Current state of the Window.
struct MuttWindow * focus
Focused Window.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
struct MuttWindow * parent
Parent Window.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Container for Accounts, Notifications.
Definition neomutt.h:41
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
bool visible
Window is visible.
Definition mutt_window.h:59