|
|
To enable your application program to associate arbitrary data with a given panel, the ETI panel subsystem automatically allocates a pointer associated with each newly created panel. Initially, the value of this user pointer is NULL. You can set its value to whatever you want or not use it at all.
SYNOPSIS
int set_panel_userptr (panel, ptr) PANEL panel; /* Panel whose user pointer to set */ char ptr; /* user-defined pointer */The user pointer has no meaning to the panels subsystem. Once the panel is created, the user pointer is neither changed nor accessed by the subsystem.char panel_userptr (panel) PANEL panel; /* Panel whose user pointer to fetch */
Function set_panel_userptr sets the user pointer of a given panel to
the value of your choice.
The function returns
OK
if the operation
is successful, and
ERR
if the panel pointer is
NULL.
Function panel_userptr returns the user pointer for a given panel. If the panel pointer is NULL, the function returns NULL.
You can use these routines to store and retrieve a pointer to an arbitrary structure that holds information for your application. For example, you might use them to store a title or, as in ``Example using panel user pointer'', create a hidden panel for pop-up messages.
PANEL *msg_panel; char *message = "Pop-up Message Here"; /* initialize message */int display_deck (show_it) int show_it; { WINDOW *w; int rows, cols;
if (show_it) { show_panel (msg_panel); /* reinstate panel */ w = panel_window (msg_panel); /* fetch associated window */
getmaxyx (w, rows, cols); /* fetch window size */
/* center cursor */ wmove (w, (rows-1), ((cols-1) - strlen(message))/2);
/* fetch and write pop-up message */ waddstr (w, panel_userptr (msg_panel)); } update_panels(); /* display deck with message, if called for */ doupdate(); if (show_it) hide_panel (msg_panel); /* hide panel again, if necessary */ } main() { int show_mess = FALSE;
msg_panel = new_panel (newwin (10, 10, 5, 60)); set_panel_userptr (msg_panel, message); /*associate message with panel */ hide_panel (msg_panel); /* remove from visible deck */
/* if condition to display pop-up message is satisfied, set show_mess to TRUE */
display_deck (show_mess);
Example using panel user pointer
After creating a window and its associated panel, main calls set_panel_userptr to set the panel user pointer to point to the panel's pop-up message string. Function hide_panel hides the panel from the deck so that it is not normally displayed. Later, the application-defined routine display_deck checks if the message is to be displayed. If so, it calls show_panel which returns the panel to the deck and enables the panel to become visible on the next update and refresh. The message string returned by panel_userptr is then written to the panel window. Finally, update_panels adjusts the relative visibility of all panels in the deck and doupdate refreshes the screen. If called for, the pop-up message is now visible.