273 lines
8.6 KiB
Groff
273 lines
8.6 KiB
Groff
|
.de It
|
||
|
.br
|
||
|
.ie \\n(.$>=3 .ne \\$3
|
||
|
.el .ne 3
|
||
|
.IP "\\$1" \\$2
|
||
|
..
|
||
|
.TH cdk_display 3 "05 Dec 1995"
|
||
|
.SH NAME
|
||
|
bindCDKObject, unbindCDKObject, checkCDKObjectBind, cleanCDKObjectBindings -
|
||
|
\f2Curses Development Kit\f1 Character Binding Capabilities.
|
||
|
.LP
|
||
|
.SH SYNOPSIS
|
||
|
.LP
|
||
|
.B cc
|
||
|
.RI "[ " "flag" " \|.\|.\|. ] " "file" " \|.\|.\|."
|
||
|
.B \-lcdk
|
||
|
.RI "[ " "library" " \|.\|.\|. ]"
|
||
|
.LP
|
||
|
#include <cdk.h>
|
||
|
.LP
|
||
|
.BI "void bindCDKObject (EObjectType" "cdkType",
|
||
|
.BI "void *" "object",
|
||
|
.BI "chtype " "key",
|
||
|
.BI "BINDFN " "function",
|
||
|
.BI "void *" "data");
|
||
|
.LP
|
||
|
.BI "void unbindCDKObject (EObjectType " "cdkType",
|
||
|
.BI "void *" "object",
|
||
|
.BI "chtype " "key");
|
||
|
.LP
|
||
|
.BI "void checkCDKObjectBind (EObjectType " "cdkType",
|
||
|
.BI "void *" "object",
|
||
|
.BI "chtype " "key");
|
||
|
.LP
|
||
|
.BI "void cleanCDKObjectBindings (EObjectType " "cdkType",
|
||
|
.BI "void *" "object");
|
||
|
.LP
|
||
|
.SH DESCRIPTION
|
||
|
Cdk has the ability to create user definable key bindings. This ability makes
|
||
|
Cdk more dynamic and usable for a wide variety of tasks. The following section
|
||
|
outlines the binding functions, their use, and their purpose.
|
||
|
|
||
|
void bindCDKObject (EObjectType \f2cdkType\f1, void *\f2object\f1, chtype \f2key\f1, BINDFN \f2function\f1, void *\f2data\f1);
|
||
|
.RS 3
|
||
|
This function creates a key binding between a specific Cdk widget (\f2object\f1)
|
||
|
given key (\f2key\f1). The parameter \f2cdkType\f1 is of type \f4EObjectType\f1
|
||
|
which is one of the following values.
|
||
|
.LP
|
||
|
.nf
|
||
|
\f2EObjectType_Value Corresponding_Widget Widget_Manual_Page\f1
|
||
|
vALPHALIST Alphalist Widget cdk_alphalist (3)
|
||
|
vCALENDAR Calendar Widget cdk_calendar (3)
|
||
|
vDIALOG Dialog Widget cdk_dialog (3)
|
||
|
vENTRY Entry Widget cdk_entry (3)
|
||
|
vFSELECT File Selector Widget cdk_fselect (3)
|
||
|
vGRAPH Graph Widget cdk_graph (3)
|
||
|
vHISTOGRAM Histogram Widget cdk_histogram (3)
|
||
|
vITEMLIST Item List Widget cdk_itemlist (3)
|
||
|
vLABEL Label Widget cdk_label (3)
|
||
|
vMARQUEE Marquee Widget cdk_marquee (3)
|
||
|
vMATRIX Matrix Widget cdk_matrix (3)
|
||
|
vMENTRY Multiple Line Entry Widget cdk_mentry (3)
|
||
|
vMENU Menu Widget cdk_menu (3)
|
||
|
vRADIO Radio List Widget cdk_radio (3)
|
||
|
vSCALE Numeric Scale Widget cdk_scale (3)
|
||
|
vSCROLL Scrolling List Widget cdk_scroll (3)
|
||
|
vSELECTION Selection List Widget cdk_selection (3)
|
||
|
vSLIDER Slider Widget cdk_slider (3)
|
||
|
vSWINDOW Scrolling Window Widget cdk_swindow (3)
|
||
|
vTEMPLATE Template Entry Widget cdk_template (3)
|
||
|
vVIEWER Viewer Widget cdk_viewer (3)
|
||
|
.fi
|
||
|
.RS 3
|
||
|
The parameter \f2function\f1 is of type \f4BINDFN\f1 which has the following
|
||
|
prototype:
|
||
|
.RE
|
||
|
|
||
|
.ce
|
||
|
\f4void function (EObjectType cdktype, void *object, void *clientData, chtype key);\f1
|
||
|
|
||
|
.RS 3
|
||
|
The parameter \f2data\f1 is a \f4void *\f1 pointer to whatever data the call-back
|
||
|
function may need. The parameter \f2key\f1 is the key hit which triggered this
|
||
|
call-back.
|
||
|
.RE
|
||
|
|
||
|
void unbindCDKObject (EObjectType \f2cdkType\f1, void *\f2object\f1, chtype \f2key\f1);
|
||
|
.RS 3
|
||
|
This function removes a specific binding to an object. The parameter names are
|
||
|
the same as the description of the function \f4bindCDKObject\f1.
|
||
|
.RE
|
||
|
|
||
|
int checkCDKObjectBind (EObjectType \f2cdkType\f1, void *\f2object\f1, chtype \f2key\f1);
|
||
|
.RS 3
|
||
|
This function returns an integer value stating whether the key \f2key\f1 has
|
||
|
been bound to the given widget, \f2object\f1.
|
||
|
.RE
|
||
|
|
||
|
void cleanCDKObjectBindings (EObjectType \f2cdkType\f1, void *\f2object\f1);
|
||
|
.RS 3
|
||
|
This function removes all user defined key bindings from the given widget.
|
||
|
.RE
|
||
|
|
||
|
.SH EXAMPLE
|
||
|
To help demonstrate how to use the key bindings I will demonstrate a simple
|
||
|
dialog box widget with help for each button. The following code segment creates
|
||
|
a dialog box and a call-back function named \f4dialogHelpCB\f1.
|
||
|
.LP
|
||
|
.nf
|
||
|
.ce
|
||
|
\f4________________________________________\f1
|
||
|
.LP
|
||
|
#include "cdk.h"
|
||
|
|
||
|
void dialogHelpCB (EObjectType cdktype, void *object, void *clientData)
|
||
|
{
|
||
|
CDKDIALOG *dialog = (CDKDIALOG *)object;
|
||
|
char *mesg[5];
|
||
|
|
||
|
/* Check which button we are on. */
|
||
|
if (dialog->currentButton == 0)
|
||
|
{
|
||
|
mesg[0] = "<C></U>Help for </U>Who<!U>.";
|
||
|
mesg[1] = "<C>When this button is picked the name of the current";
|
||
|
mesg[2] = "<C>user is displayed on the screen in a pop-up window.";
|
||
|
popupLabel (dialog->screen, mesg, 3);
|
||
|
}
|
||
|
else if (dialog->currentButton == 1)
|
||
|
{
|
||
|
mesg[0] = "<C></U>Help for </U>Time<!U>.";
|
||
|
mesg[1] = "<C>When this button is picked the current time is";
|
||
|
mesg[2] = "<C>displayed on the screen in a pop-up window.";
|
||
|
popupLabel (dialog->screen, mesg, 3);
|
||
|
}
|
||
|
else if (dialog->currentButton == 2)
|
||
|
{
|
||
|
mesg[0] = "<C></U>Help for </U>Date<!U>.";
|
||
|
mesg[1] = "<C>When this button is picked the current date is";
|
||
|
mesg[2] = "<C>displayed on the screen in a pop-up window.";
|
||
|
popupLabel (dialog->screen, mesg, 3);
|
||
|
}
|
||
|
else if (dialog->currentButton == 3)
|
||
|
{
|
||
|
mesg[0] = "<C></U>Help for </U>Quit<!U>.";
|
||
|
mesg[1] = "<C>When this button is picked the dialog box is exited.";
|
||
|
popupLabel (dialog->screen, mesg, 2);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
/* Declare variables. */
|
||
|
CDKSCREEN *cdkscreen;
|
||
|
CDKDIALOG *question;
|
||
|
WINDOW *cursesWin;
|
||
|
char *buttons[40];
|
||
|
char *message[40], *info[5], *loginName;
|
||
|
char temp[256];
|
||
|
int selection;
|
||
|
int x;
|
||
|
time_t clck;
|
||
|
struct tm *currentTime;
|
||
|
|
||
|
/* Set up CDK */
|
||
|
cursesWin = initscr();
|
||
|
cdkscreen = initCDKScreen (cursesWin);
|
||
|
|
||
|
/* Start color. */
|
||
|
initCDKColor();
|
||
|
|
||
|
/* Set up the dialog box. */
|
||
|
message[0] = "<C></U>Simple Command Interface";
|
||
|
message[1] = "Pick the command you wish to run.";
|
||
|
message[2] = "<C>Press </R>?<!R> for help.";
|
||
|
buttons[0] = "Who";
|
||
|
buttons[1] = "Time";
|
||
|
buttons[2] = "Date";
|
||
|
buttons[3] = "Quit";
|
||
|
|
||
|
/* Create the dialog box. */
|
||
|
question = newCDKDialog (cdkscreen, CENTER, CENTER,
|
||
|
message, 3, buttons, 4, A_REVERSE,
|
||
|
TRUE, TRUE, FALSE);
|
||
|
|
||
|
/* Check if we got a null value back. */
|
||
|
if (question == (CDKDIALOG *)NULL)
|
||
|
{
|
||
|
destroyCDKScreen (cdkscreen);
|
||
|
|
||
|
/* End curses... */
|
||
|
endCDK();
|
||
|
|
||
|
/* Spit out a message. */
|
||
|
printf ("Oops. Can't seem to create the dialog box. Is the window too small?\n");
|
||
|
exit (1);
|
||
|
}
|
||
|
|
||
|
/* Create the key binding. */
|
||
|
bindCDKObject (vDIALOG, question, '?', dialogHelpCB, NULL);
|
||
|
|
||
|
/* Activate the dialog box. */
|
||
|
selection = 0;
|
||
|
while (selection != 3)
|
||
|
{
|
||
|
/* Get the users button selection. */
|
||
|
selection = activateCDKDialog (question, (chtype *)NULL);
|
||
|
|
||
|
/* Check the results. */
|
||
|
if (selection == 0)
|
||
|
{
|
||
|
/* Get the users login name. */
|
||
|
info[0] = "<C> </U>Login Name<!U> ";
|
||
|
loginName = getlogin();
|
||
|
if (loginName == (char *)NULL)
|
||
|
{
|
||
|
info[1] = "<C></R>Unknown";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
sprintf (temp, "<C><%s>", loginName); info[1] = strdup (temp);
|
||
|
}
|
||
|
popupLabel (question->screen, info, 2);
|
||
|
free (info[1]);
|
||
|
}
|
||
|
else if (selection == 1)
|
||
|
{
|
||
|
/* Print out the time. */
|
||
|
time(&clck);
|
||
|
currentTime = localtime(&clck);
|
||
|
sprintf (temp, "<C>%d:%d:%d", currentTime->tm_hour,
|
||
|
currentTime->tm_min,
|
||
|
currentTime->tm_sec);
|
||
|
info[0] = "<C> </U>Current Time<!U> ";
|
||
|
info[1] = strdup (temp);
|
||
|
popupLabel (question->screen, info, 2);
|
||
|
free (info[1]);
|
||
|
}
|
||
|
else if (selection == 2)
|
||
|
{
|
||
|
/* Print out the date. */
|
||
|
time(&clck);
|
||
|
currentTime = localtime(&clck);
|
||
|
sprintf (temp, "<C>%d/%d/%d", currentTime->tm_mday,
|
||
|
currentTime->tm_mon,
|
||
|
currentTime->tm_year);
|
||
|
info[0] = "<C> </U>Current Date<!U> ";
|
||
|
info[1] = strdup (temp);
|
||
|
popupLabel (question->screen, info, 2);
|
||
|
free (info[1]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* Clean up */
|
||
|
destroyCDKDialog (question);
|
||
|
destroyCDKScreen (cdkscreen);
|
||
|
endCDK();
|
||
|
delwin (cursesWin);
|
||
|
}
|
||
|
.fi
|
||
|
.ce
|
||
|
\f4________________________________________\f1
|
||
|
|
||
|
.SH SEE ALSO
|
||
|
.BR cdk (3),
|
||
|
.BR cdk_display (3),
|
||
|
.BR cdk_screen (3)
|
||
|
.SH NOTES
|
||
|
The header file \f4<cdk.h>\f1 automatically includes the header files
|
||
|
\f4<curses.h>\f1, \f4<stdlib.h>\f1, \f4<string.h>\f1, \f4<ctype.h>\f1,
|
||
|
\f4<unistd.h>\f1, \f4<dirent.h>\f1, \f4<time.h>\f1, \f4<errno.h>\f1,
|
||
|
\f4<pwd.h>\f1, \f4<grp.h>\f1, \f4<sys/stat.h>\f1, and \f4<sys/types.h>\f1.
|
||
|
The \f4<curses.h>\f1 header file includes \f4<stdio.h>\f1 and \f4<unctrl.h>\f1.
|