NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dialog.c
Go to the documentation of this file.
1
70#include "config.h"
71#include <stdbool.h>
72#include <stddef.h>
73#include "mutt/lib.h"
74#include "dialog.h"
75#include "mutt_window.h"
76#ifdef USE_DEBUG_WINDOW
77#include "debug/lib.h"
78#endif
79
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 || !AllDialogsWindow)
112 return;
113
114 struct MuttWindow *last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
115 if (last)
116 last->state.visible = false;
117
120
121 // Notify the world, allowing plugins to integrate
122 mutt_debug(LL_NOTIFY, "NT_WINDOW_DIALOG visible: %s, %p\n",
123 mutt_window_win_name(dlg), (void *) dlg);
124 struct EventWindow ev_w = { dlg, WN_VISIBLE };
126
127 dlg->state.visible = true;
130
131#ifdef USE_DEBUG_WINDOW
133#endif
134}
135
142void dialog_pop(void)
143{
144 if (!AllDialogsWindow)
145 return;
146
147 struct MuttWindow *last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
148 if (!last)
149 return;
150
151 // Notify the world, allowing plugins to clean up
152 mutt_debug(LL_NOTIFY, "NT_WINDOW_DIALOG hidden: %s, %p\n",
153 mutt_window_win_name(last), (void *) last);
154 struct EventWindow ev_w = { last, WN_HIDDEN };
156
157 last->state.visible = false;
158 last->parent = NULL;
159 TAILQ_REMOVE(&AllDialogsWindow->children, last, entries);
160
161 last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
162 if (last)
163 {
164 last->state.visible = true;
166 }
167 else
168 {
169 AllDialogsWindow->focus = NULL;
170 }
171#ifdef USE_DEBUG_WINDOW
173#endif
174}
175
184{
185 if (nc->event_type != NT_WINDOW)
186 return 0;
187 if (!nc->global_data || !nc->event_data)
188 return -1;
190 return 0;
191
192 struct MuttWindow *win_alldlgs = nc->global_data;
193 struct EventWindow *ev_w = nc->event_data;
194 if (ev_w->win != win_alldlgs)
195 return 0;
196
197 notify_observer_remove(win_alldlgs->notify, alldialogs_window_observer, win_alldlgs);
198
199 AllDialogsWindow = NULL;
200 mutt_debug(LL_DEBUG5, "window delete done\n");
201 return 0;
202}
203
211{
215
217
218 AllDialogsWindow = win_alldlgs;
219
220 return win_alldlgs;
221}
Convenience wrapper for the debug headers.
void debug_win_dump(void)
Definition: window.c:96
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:142
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: dialog.c:80
struct MuttWindow * alldialogs_new(void)
Create the AllDialogs Window.
Definition: dialog.c:210
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:89
static int alldialogs_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dialog.c:183
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
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.
Definition: mutt_window.c:344
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:735
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:182
Window management.
@ WT_ALL_DIALOGS
Container for All Dialogs (nested Windows)
Definition: mutt_window.h:75
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:39
@ NT_WINDOW_DIALOG
A new Dialog Window has been created, e.g. WT_DLG_INDEX.
Definition: mutt_window.h:231
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:215
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:216
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:53
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:49
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:827
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:862
#define TAILQ_LAST(head, headname)
Definition: queue.h:837
An Event that happened to a Window.
Definition: mutt_window.h:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
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:60