panel_impl.h revision 1.3 1 /* $NetBSD: panel_impl.h,v 1.3 2022/04/19 20:32:17 rillig Exp $ */
2
3 /*
4 * Copyright (c) 2015 Valery Ushakov
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef _PANEL_IMPL_H_
29 #define _PANEL_IMPL_H_
30
31 #include "panel.h"
32
33 #include <sys/queue.h>
34
35 #define DECK_HEAD(head) TAILQ_HEAD(head, __panel)
36 #define DECK_ENTRY TAILQ_ENTRY(__panel)
37
38
39 /*
40 * Panels are just curses windows with Z-order added.
41 * See update_panels() for details.
42 */
43 struct __panel {
44 WINDOW *win;
45 char *user;
46 DECK_ENTRY zorder;
47 };
48
49
50 /* Deck of panels in Z-order from bottom to top. */
51 DECK_HEAD(deck);
52 extern struct deck _deck __dso_hidden;
53
54 /* Fake stdscr panel at the bottom, not user visible */
55 extern PANEL _stdscr_panel __dso_hidden;
56
57
58 /*
59 * Hidden panels are not in the deck. <sys/queue.h> macros don't have
60 * a concept of an entry not on the list, so provide a kludge that
61 * digs into internals.
62 */
63 #define TAILQ_REMOVE_NP(head, elm, field) do { \
64 TAILQ_REMOVE((head), (elm), field); \
65 (elm)->field.tqe_next = NULL; \
66 (elm)->field.tqe_prev = NULL; \
67 } while (0)
68
69 #define TAILQ_LINKED_NP(elm, field) \
70 (((elm)->field.tqe_prev) != NULL)
71
72
73 #define DECK_INSERT_TOP(p) do { \
74 TAILQ_INSERT_TAIL(&_deck, (p), zorder); \
75 } while (0)
76
77 #define DECK_INSERT_BOTTOM(p) do { \
78 TAILQ_INSERT_AFTER(&_deck, &_stdscr_panel, (p), zorder); \
79 } while (0)
80
81 #define DECK_REMOVE(p) do { \
82 TAILQ_REMOVE_NP(&_deck, (p), zorder); \
83 } while (0)
84
85
86 #define PANEL_ABOVE(p) (TAILQ_NEXT((p), zorder))
87 #define PANEL_BELOW(p) (TAILQ_PREV((p), deck, zorder))
88 #define PANEL_HIDDEN(p) (!TAILQ_LINKED_NP((p), zorder))
89
90 #define FOREACH_PANEL(var) TAILQ_FOREACH(var, &_deck, zorder)
91
92 #endif /* _PANEL_IMPL_H_ */
93