NeoMutt  2022-04-29-145-g9b6a0e
Teaching an old dog new tricks
DOXYGEN
dialog.c
Go to the documentation of this file.
1 
65 #include "config.h"
66 #include <stddef.h>
67 #include <stdbool.h>
68 #include "mutt/lib.h"
69 #include "lib.h"
70 #ifdef USE_DEBUG_WINDOW
71 #include "debug/lib.h"
72 #endif
73 
74 struct MuttWindow *AllDialogsWindow = NULL;
75 
83 struct MuttWindow *dialog_find(struct MuttWindow *win)
84 {
85  for (; win && win->parent; win = win->parent)
86  {
87  if (win->parent->type == WT_ALL_DIALOGS)
88  return win;
89  }
90 
91  return NULL;
92 }
93 
103 void dialog_push(struct MuttWindow *dlg)
104 {
105  if (!dlg || !AllDialogsWindow)
106  return;
107 
108  struct MuttWindow *last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
109  if (last)
110  last->state.visible = false;
111 
114 
115  // Notify the world, allowing plugins to integrate
116  mutt_debug(LL_NOTIFY, "NT_WINDOW_DIALOG visible: %s, %p\n",
117  mutt_window_win_name(dlg), dlg);
118  struct EventWindow ev_w = { dlg, WN_VISIBLE };
120 
121  dlg->state.visible = true;
122  dlg->parent = AllDialogsWindow;
124  window_set_focus(dlg);
125 
126 #ifdef USE_DEBUG_WINDOW
127  debug_win_dump();
128 #endif
129 }
130 
137 void dialog_pop(void)
138 {
139  if (!AllDialogsWindow)
140  return;
141 
142  struct MuttWindow *last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
143  if (!last)
144  return;
145 
146  // Notify the world, allowing plugins to clean up
147  mutt_debug(LL_NOTIFY, "NT_WINDOW_DIALOG hidden: %s, %p\n",
148  mutt_window_win_name(last), last);
149  struct EventWindow ev_w = { last, WN_HIDDEN };
151 
152  last->state.visible = false;
153  last->parent = NULL;
154  TAILQ_REMOVE(&AllDialogsWindow->children, last, entries);
155 
156  last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
157  if (last)
158  {
159  last->state.visible = true;
161  window_set_focus(last);
162  }
163  else
164  {
165  AllDialogsWindow->focus = NULL;
166  }
167 #ifdef USE_DEBUG_WINDOW
168  debug_win_dump();
169 #endif
170 }
171 
180 {
181  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
182  return -1;
183 
184  if (nc->event_subtype != NT_WINDOW_DELETE)
185  return 0;
186 
187  struct MuttWindow *win_alldlgs = nc->global_data;
188  struct EventWindow *ev_w = nc->event_data;
189  if (ev_w->win != win_alldlgs)
190  return 0;
191 
192  notify_observer_remove(win_alldlgs->notify, alldialogs_window_observer, win_alldlgs);
193 
194  AllDialogsWindow = NULL;
195  mutt_debug(LL_DEBUG5, "window delete done\n");
196  return 0;
197 }
198 
206 {
210 
211  notify_observer_add(win_alldlgs->notify, NT_WINDOW, alldialogs_window_observer, win_alldlgs);
212 
213  AllDialogsWindow = win_alldlgs;
214 
215  return win_alldlgs;
216 }
217 
223 {
224  if (!AllDialogsWindow)
225  return NULL;
226 
227  struct MuttWindow *np = NULL;
228  TAILQ_FOREACH(np, &AllDialogsWindow->children, entries)
229  {
230  if (mutt_window_is_visible(np))
231  return np;
232  }
233 
234  return NULL;
235 }
Convenience wrapper for the debug headers.
void debug_win_dump(void)
Definition: window.c:95
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: dialog.c:103
void dialog_pop(void)
Hide a Window from the user.
Definition: dialog.c:137
struct MuttWindow * alldialogs_new(void)
Create the AllDialogs Window.
Definition: dialog.c:205
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: dialog.c:74
struct MuttWindow * alldialogs_get_current(void)
Get the currently active Dialog.
Definition: dialog.c:222
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition: dialog.c:83
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static int alldialogs_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dialog.c:179
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
@ LL_NOTIFY
Log of notifications.
Definition: logging.h:45
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, observer_t callback, 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
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:501
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:340
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:181
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:710
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:659
@ 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.
Definition: mutt_window.h:208
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:206
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:192
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:193
#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
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
#define TAILQ_LAST(head, headname)
Definition: queue.h:819
Key value store.
An Event that happened to a Window.
Definition: mutt_window.h:216
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
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:59