NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
dialog.c
Go to the documentation of this file.
1 
67 #include "config.h"
68 #include <stddef.h>
69 #include <stdbool.h>
70 #include "mutt/lib.h"
71 #include "lib.h"
72 #ifdef USE_DEBUG_WINDOW
73 #include "debug/lib.h"
74 #endif
75 
76 struct MuttWindow *AllDialogsWindow = NULL;
77 
85 struct MuttWindow *dialog_find(struct MuttWindow *win)
86 {
87  for (; win && win->parent; win = win->parent)
88  {
89  if (win->parent->type == WT_ALL_DIALOGS)
90  return win;
91  }
92 
93  return NULL;
94 }
95 
105 void dialog_push(struct MuttWindow *dlg)
106 {
107  if (!dlg || !AllDialogsWindow)
108  return;
109 
110  struct MuttWindow *last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
111  if (last)
112  last->state.visible = false;
113 
114  TAILQ_INSERT_TAIL(&AllDialogsWindow->children, dlg, entries);
115  notify_set_parent(dlg->notify, AllDialogsWindow->notify);
116 
117  // Notify the world, allowing plugins to integrate
118  mutt_debug(LL_NOTIFY, "NT_WINDOW_DIALOG visible: %s, %p\n",
119  mutt_window_win_name(dlg), dlg);
120  struct EventWindow ev_w = { dlg, WN_VISIBLE };
122 
123  dlg->state.visible = true;
124  dlg->parent = AllDialogsWindow;
125  mutt_window_reflow(AllDialogsWindow);
126  window_set_focus(dlg);
127 
128 #ifdef USE_DEBUG_WINDOW
129  debug_win_dump();
130 #endif
131 }
132 
139 void dialog_pop(void)
140 {
141  if (!AllDialogsWindow)
142  return;
143 
144  struct MuttWindow *last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
145  if (!last)
146  return;
147 
148  // Notify the world, allowing plugins to clean up
149  mutt_debug(LL_NOTIFY, "NT_WINDOW_DIALOG hidden: %s, %p\n",
150  mutt_window_win_name(last), last);
151  struct EventWindow ev_w = { last, WN_HIDDEN };
153 
154  last->state.visible = false;
155  last->parent = NULL;
156  TAILQ_REMOVE(&AllDialogsWindow->children, last, entries);
157 
158  last = TAILQ_LAST(&AllDialogsWindow->children, MuttWindowList);
159  if (last)
160  {
161  last->state.visible = true;
162  mutt_window_reflow(AllDialogsWindow);
163  window_set_focus(last);
164  }
165  else
166  {
167  AllDialogsWindow->focus = NULL;
168  }
169 #ifdef USE_DEBUG_WINDOW
170  debug_win_dump();
171 #endif
172 }
173 
182 {
183  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
184  return -1;
185 
186  if (nc->event_subtype != NT_WINDOW_DELETE)
187  return 0;
188 
189  struct MuttWindow *win_alldlgs = nc->global_data;
190  struct EventWindow *ev_w = nc->event_data;
191  if (ev_w->win != win_alldlgs)
192  return 0;
193 
194  notify_observer_remove(win_alldlgs->notify, alldialogs_window_observer, win_alldlgs);
195 
196  AllDialogsWindow = NULL;
197  mutt_debug(LL_DEBUG5, "window delete done\n");
198  return 0;
199 }
200 
208 {
209  struct MuttWindow *win_alldlgs =
212 
213  notify_observer_add(win_alldlgs->notify, NT_WINDOW, alldialogs_window_observer, win_alldlgs);
214 
215  AllDialogsWindow = win_alldlgs;
216 
217  return win_alldlgs;
218 }
219 
225 {
226  if (!AllDialogsWindow)
227  return NULL;
228 
229  struct MuttWindow *np = NULL;
230  TAILQ_FOREACH(np, &AllDialogsWindow->children, entries)
231  {
232  if (mutt_window_is_visible(np))
233  return np;
234  }
235 
236  return NULL;
237 }
Convenience wrapper for the gui headers.
A new Dialog Window has been created, e.g. WT_DLG_INDEX.
Definition: mutt_window.h:208
Data passed to a notification function.
Definition: observer.h:39
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
Log of notifications.
Definition: logging.h:45
An Event that happened to a Window.
Definition: mutt_window.h:215
#define TAILQ_LAST(head, headname)
Definition: queue.h:819
struct MuttWindow * alldialogs_new(void)
Create the AllDialogs Window.
Definition: dialog.c:207
Window uses all available vertical space.
Definition: mutt_window.h:38
static int alldialogs_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: dialog.c:181
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:680
Window is about to be deleted.
Definition: mutt_window.h:206
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:193
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
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
struct MuttWindow * focus
Focussed Window.
Definition: mutt_window.h:140
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: dialog.c:105
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
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool visible
Window is visible.
Definition: mutt_window.h:59
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
struct MuttWindow * alldialogs_get_current(void)
Get the currently active Dialog.
Definition: dialog.c:224
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: dialog.c:76
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Container for All Dialogs (nested Windows)
Definition: mutt_window.h:74
void * event_data
Data from notify_send()
Definition: observer.h:44
Convenience wrapper for the debug headers.
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
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:192
void dialog_pop(void)
Hide a Window from the user.
Definition: dialog.c:139
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
void debug_win_dump(void)
Definition: window.c:91
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.
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:731
Window wants as much space as possible.
Definition: mutt_window.h:48
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition: dialog.c:85
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