forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppanel.c
151 lines (134 loc) · 4.38 KB
/
ppanel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* @file
* Pager Panel
*
* @authors
* Copyright (C) 2021-2023 Richard Russon <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @page pager_ppanel Pager Panel
*
* The Pager Panel is a non-interactive container around the email list and a
* status bar.
*
* ## Windows
*
* | Name | Type | Constructor |
* | :---------- | :-------- | :----------- |
* | Pager Panel | #WT_PAGER | ppanel_new() |
*
* **Parent**
* - @ref index_dlg_index
*
* **Children**
* - @ref pager_pager
* - @ref pager_pbar
*
* ## Data
* - #PagerPrivateData
*
* ## Events
*
* Once constructed, it is controlled by the following events:
*
* | Event Type | Handler |
* | :---------- | :----------------------- |
* | #NT_CONFIG | ppanel_config_observer() |
* | #NT_WINDOW | ppanel_window_observer() |
*
* The Pager Panel does not implement MuttWindow::recalc() or MuttWindow::repaint().
*/
#include "config.h"
#include <stdbool.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "pbar.h"
#include "private_data.h"
struct IndexSharedData;
/**
* ppanel_config_observer - Notification that a Config Variable has changed - Implements ::observer_t - @ingroup observer_api
*/
static int ppanel_config_observer(struct NotifyCallback *nc)
{
if (nc->event_type != NT_CONFIG)
return 0;
if (!nc->global_data || !nc->event_data)
return -1;
struct EventConfig *ev_c = nc->event_data;
struct MuttWindow *panel_pager = nc->global_data;
if (mutt_str_equal(ev_c->name, "status_on_top"))
{
window_status_on_top(panel_pager, NeoMutt->sub);
mutt_debug(LL_DEBUG5, "config done\n");
}
return 0;
}
/**
* ppanel_window_observer - Notification that a Window has changed - Implements ::observer_t - @ingroup observer_api
*/
static int ppanel_window_observer(struct NotifyCallback *nc)
{
if (nc->event_type != NT_WINDOW)
return 0;
if (!nc->global_data || !nc->event_data)
return -1;
if (nc->event_subtype != NT_WINDOW_DELETE)
return 0;
struct MuttWindow *panel_pager = nc->global_data;
struct EventWindow *ev_w = nc->event_data;
if (ev_w->win != panel_pager)
return 0;
notify_observer_remove(NeoMutt->sub->notify, ppanel_config_observer, panel_pager);
notify_observer_remove(panel_pager->notify, ppanel_window_observer, panel_pager);
mutt_debug(LL_DEBUG5, "window delete done\n");
return 0;
}
/**
* ppanel_new - Create the Windows for the Pager panel
* @param status_on_top true, if the Pager bar should be on top
* @param shared Shared Index data
* @retval ptr New Pager Panel
*/
struct MuttWindow *ppanel_new(bool status_on_top, struct IndexSharedData *shared)
{
struct MuttWindow *panel_pager = mutt_window_new(WT_PAGER, MUTT_WIN_ORIENT_VERTICAL,
MUTT_WIN_SIZE_MAXIMISE, MUTT_WIN_SIZE_UNLIMITED,
MUTT_WIN_SIZE_UNLIMITED);
panel_pager->state.visible = false; // The Pager and Pager Bar are initially hidden
struct PagerPrivateData *priv = pager_private_data_new();
panel_pager->wdata = priv;
panel_pager->wdata_free = pager_private_data_free;
struct MuttWindow *win_pager = pager_window_new(shared, priv);
panel_pager->focus = win_pager;
struct MuttWindow *win_pbar = pbar_new(shared, priv);
if (status_on_top)
{
mutt_window_add_child(panel_pager, win_pbar);
mutt_window_add_child(panel_pager, win_pager);
}
else
{
mutt_window_add_child(panel_pager, win_pager);
mutt_window_add_child(panel_pager, win_pbar);
}
notify_observer_add(NeoMutt->sub->notify, NT_CONFIG, ppanel_config_observer, panel_pager);
notify_observer_add(panel_pager->notify, NT_WINDOW, ppanel_window_observer, panel_pager);
return panel_pager;
}