Browse panels with user pointers
Adapted from NCURSES Programming HOWTO, by Pradeep Padala.
This program creates three windows which can be cycled through using the Tab key.
Example: Panel Window Browsing Example
#include <stdlib.h>#include <string.h>#include <panel.h>
#define NLINES 10#define NCOLS 40
static void{ int length, x, y; float temp;
if (win == NULL) if (startx != 0) x = startx; if (starty != 0) y = starty; if (width == 0) width = 80;
length = (int) strlen(string); temp = (float) (width - length) / 2; x = startx + (int) temp;}
/* Show the window with a border and a label */static void{ int height, width;
(void) height;
}
/* Put all the windows */static void{ int x, y, i; char label[80];
y = 2; x = 10; for (i = 0; i < n; ++i) { sprintf(label, "Window Number %d", i + 1); win_show(wins[i], label, i + 1); y += 3; x += 7; }}
intmain(void){ int ch;
/* Initialize curses */
/* Initialize all the colors */
init_wins(my_wins, 3);
/* Attach a panel to each window */ /* Order is bottom up */ /* Push 0, order: stdscr-0 */ /* Push 1, order: stdscr-0-1 */ /* Push 2, order: stdscr-0-1-2 */
/* Set up the user pointers to the next panel */
/* Update the stacking order. The last panel created is on top */
/* Show it on the screen */ "Use tab to browse through the windows (F1 to Exit)");
top = my_panels[2]; switch (ch) { case 9: /* Tab */ break; } } return EXIT_SUCCESS;}Using user pointers
Section titled “Using user pointers”The example uses user pointers to find the next window in the cycle. Every panel has an associated user pointer, not used by the panel code, to which you can attach application data. The pointer can point to any information you want to store. In this case each panel stores a pointer to the next panel in the cycle.
The user pointer for a panel is set with set_panel_userptr(). It can be read with panel_userptr(), which returns the user pointer for the panel given as argument. After finding the next panel in the cycle, the program brings it to the top with top_panel(), which brings the panel given as argument to the top of the deck.