1cdk_binding(3)             Library Functions Manual             cdk_binding(3)
2
3
4

NAME

6       cdk_binding - Curses Development Kit Character Binding Capabilities.
7

SYNOPSIS

9       cc [ flag ... ] file ...  -lcdk [ library ... ]
10
11       #include <cdk.h>
12
13       void bindCDKObject (
14                      EObjectType cdkType,
15                      void *object,
16                      chtype key,
17                      BINDFN function,
18                      void *data);
19
20       int checkCDKObjectBind (
21                      EObjectType cdkType,
22                      void *object,
23                      chtype key);
24
25       void cleanCDKObjectBindings (
26                      EObjectType cdkType,
27                      void *object);
28
29       bool isCDKObjectBind (
30                      EObjectType cdkType,
31                      void *object,
32                      chtype key);
33
34       void unbindCDKObject (
35                      EObjectType cdkType,
36                      void *object,
37                      chtype key);
38
39       int getcCDKObject (
40                      CDKOBJS *object);
41
42       int getchCDKObject (
43                      CDKOBJS *object,
44                      boolean *functionKey);
45

DESCRIPTION

47       Cdk  has the ability to create user definable key bindings.  This abil‐
48       ity makes Cdk more dynamic and usable for a wide variety of tasks.  The
49       following  section outlines the binding functions, their use, and their
50       purpose.
51
52       bindCDKObject
53            creates a key binding between a specific Cdk widget (object) given
54            key  (key).  The parameter cdkType is of type EObjectType which is
55            one of the following values.
56
57        EObjectType_Value   Corresponding_Widget         Widget_Manual_Page
58        ──────────────────────────────────────────────────────────────────────
59        vALPHALIST          Alphalist Widget             cdk_alphalist (3)
60        vBUTTON             Button Widget                cdk_button (3)
61        vBUTTONBOX          Buttonbox Widget             cdk_buttonbox (3)
62        vCALENDAR           Calendar Widget              cdk_calendar (3)
63        vDIALOG             Dialog Widget                cdk_dialog (3)
64        vDSCALE             DoubleFloat Widget           cdk_dscale (3)
65        vENTRY              Entry Widget                 cdk_entry (3)
66
67        vFSCALE             Floating Scale Widget        cdk_fscale (3)
68        vFSELECT            File Selector Widget         cdk_fselect (3)
69        vFSLIDER            Floating Slider Widget       cdk_fslider (3)
70        vGRAPH              Graph Widget                 cdk_graph (3)
71        vHISTOGRAM          Histogram Widget             cdk_histogram (3)
72        vITEMLIST           Item List Widget             cdk_itemlist (3)
73        vLABEL              Label Widget                 cdk_label (3)
74        vMARQUEE            Marquee Widget               cdk_marquee (3)
75        vMATRIX             Matrix Widget                cdk_matrix (3)
76        vMENTRY             Multiple Line Entry Widget   cdk_mentry (3)
77        vMENU               Menu Widget                  cdk_menu (3)
78        vRADIO              Radio List Widget            cdk_radio (3)
79        vSCALE              Integer Scale Widget         cdk_scale (3)
80        vSCROLL             Scrolling List Widget        cdk_scroll (3)
81        vSELECTION          Selection List Widget        cdk_selection (3)
82        vSLIDER             Slider Widget                cdk_slider (3)
83        vSWINDOW            Scrolling Window Widget      cdk_swindow (3)
84        vTEMPLATE           Template Entry Widget        cdk_template (3)
85        vUSCALE             Unsigned Scale Widget        cdk_uscale (3)
86        vUSLIDER            Unsigned Slider Widget       cdk_uslider (3)
87        vVIEWER             Viewer Widget                cdk_viewer (3)
88        ──────────────────────────────────────────────────────────────────────
89          The parameter function is the callback function.  The parameter data
90          points  to  data passed to the callback function.  The parameter key
91          is the key hit which triggered this callback.
92
93       checkCDKObjectBind
94            check to see if a binding for the given key exists.  If  it  does,
95            Cdk  runs  the  associated command and returns its value, normally
96            TRUE.  If no binding exists, return FALSE.
97
98            The widgets which accept input, e.g., via  "inject"  methods,  use
99            this  to  check  if the injected character is bound to a function.
100            If that returns TRUE, the widget may update its exitType value: if
101            earlyExit value is set (not equal to vNEVER_ACTIVATED), the widget
102            sets exitType to that value.
103
104       cleanCDKObjectBindings
105            removes all user defined key bindings from the given widget.
106
107       isCDKObjectBind
108            check to see if a binding for the given key exists.   If  it  does
109            return TRUE.  If no binding exists, return FALSE.
110
111       unbindCDKObject
112            removes  a  specific  binding to an object.  The parameter are the
113            same as for bindCDKObject.
114
115       getcCDKObject
116            reads a keycode from the given widget.  This is  depcrecated:  use
117            getchCDKObject.
118
119       getchCDKObject
120            reads a keycode from the given widget.  It sets a flag to indicate
121            if the result is a function key.  If the keycode has been bound to
122            the  special  function  getcCDKBind, then it will be translated to
123            the value which was given for the binding data.  Otherwise, a  few
124            special cases are performed:
125
126                 ┌──────────────────────────────────────────────────────┐
127Key                         Result                    
128                 ├──────────────────────────────────────────────────────┤
129                 │CTRL-A                      KEY_HOME                  │
130                 │CTRL-B                      KEY_LEFT                  │
131                 │CTRL-E                      KEY_END                   │
132                 │CTRL-F                      KEY_RIGHT                 │
133                 │CTRL-N                      tab                       │
134                 │CTRL-P                      KEY_BTAB                  │
135                 │DEL                         KEY_DC                    │
136                 │backspace                   KEY_BACKSPACE             │
137                 │carriage return             KEY_ENTER                 │
138                 │newline                     KEY_ENTER                 │
139                 └──────────────────────────────────────────────────────┘
140       All of the widgets use getchCDKObject internally for consistency.
141

EXAMPLE

143       To  help  demonstrate  how to use the key bindings I will demonstrate a
144       simple dialog box widget with help for each button.  The following code
145       segment   creates   a   dialog   box  and  a  callback  function  named
146       dialogHelpCB.
147
148                      ________________________________________
149
150       #include <cdk.h>
151
152       #ifdef HAVE_XCURSES
153       char *XCursesProgramName="bind_ex";
154       #endif
155
156       static int dialogHelpCB (EObjectType cdktype GCC_UNUSED, void *object, void *clientData GCC_UNUSED, chtype key GCC_UNUSED)
157       {
158          CDKDIALOG *dialog = (CDKDIALOG *)object;
159          char *mesg[5];
160
161          /* Check which button we are on. */
162          if (dialog->currentButton == 0)
163          {
164             mesg[0] = "<C></U>Help for </U>Who<!U>.";
165             mesg[1] = "<C>When this button is picked the name of the current";
166             mesg[2] = "<C>user is displayed on the screen in a popup window.";
167             popupLabel (ScreenOf(dialog), mesg, 3);
168          }
169          else if (dialog->currentButton == 1)
170          {
171             mesg[0] = "<C></U>Help for </U>Time<!U>.";
172             mesg[1] = "<C>When this button is picked the current time is";
173             mesg[2] = "<C>displayed on the screen in a popup window.";
174             popupLabel (ScreenOf(dialog), mesg, 3);
175          }
176          else if (dialog->currentButton == 2)
177          {
178             mesg[0] = "<C></U>Help for </U>Date<!U>.";
179             mesg[1] = "<C>When this button is picked the current date is";
180             mesg[2] = "<C>displayed on the screen in a popup window.";
181             popupLabel (ScreenOf(dialog), mesg, 3);
182          }
183          else if (dialog->currentButton == 3)
184          {
185             mesg[0] = "<C></U>Help for </U>Quit<!U>.";
186             mesg[1] = "<C>When this button is picked the dialog box is exited.";
187             popupLabel (ScreenOf(dialog), mesg, 2);
188          }
189          return (FALSE);
190       }
191
192       int main (void)
193       {
194          /* Declare variables. */
195          CDKSCREEN     *cdkscreen;
196          CDKDIALOG     *question;
197          WINDOW        *cursesWin;
198          char          *buttons[40];
199          char          *message[40], *info[5], *loginName;
200          char          temp[256];
201          int           selection;
202          time_t        clck;
203          struct tm     *currentTime;
204
205          /* Set up CDK. */
206          cursesWin = initscr();
207          cdkscreen = initCDKScreen (cursesWin);
208
209          /* Start color. */
210          initCDKColor();
211
212          /* Set up the dialog box. */
213          message[0] = "<C></U>Simple Command Interface";
214          message[1] = "Pick the command you wish to run.";
215          message[2] = "<C>Press </R>?<!R> for help.";
216          buttons[0] = "Who";
217          buttons[1] = "Time";
218          buttons[2] = "Date";
219          buttons[3] = "Quit";
220
221          /* Create the dialog box. */
222          question      = newCDKDialog (cdkscreen, CENTER, CENTER,
223                                        message, 3, buttons, 4, A_REVERSE,
224                                        TRUE, TRUE, FALSE);
225
226          /* Check if we got a null value back. */
227          if (question == (CDKDIALOG *)0)
228          {
229             destroyCDKScreen (cdkscreen);
230
231             /* End curses... */
232             endCDK();
233
234             /* Spit out a message. */
235             printf ("Oops. Can't seem to create the dialog box. Is the window too small?\n");
236             exit (1);
237          }
238
239          /* Create the key binding. */
240          bindCDKObject (vDIALOG, question, '?', dialogHelpCB, 0);
241
242          /* Activate the dialog box. */
243          selection = 0;
244          while (selection != 3)
245          {
246             /* Get the users button selection. */
247             selection = activateCDKDialog (question, (chtype *)0);
248
249             /* Check the results. */
250             if (selection == 0)
251             {
252                 /* Get the users login name. */
253                 info[0] = "<C>     </U>Login Name<!U>     ";
254                 loginName = getlogin();
255                 if (loginName == (char *)0)
256                 {
257                    strcpy (temp, "<C></R>Unknown");
258                 }
259                 else
260                 {
261                     sprintf (temp, "<C><%s>", loginName);
262                 }
263                 info[1] = copyChar (temp);
264                 popupLabel (ScreenOf(question), info, 2);
265                 freeChar (info[1]);
266             }
267             else if (selection == 1)
268             {
269                 /* Print out the time. */
270                 time(&clck);
271                 currentTime = localtime(&clck);
272                 sprintf (temp, "<C>%d:%d:%d", currentTime->tm_hour,
273                                                currentTime->tm_min,
274                                                currentTime->tm_sec);
275                 info[0] = "<C>   </U>Current Time<!U>   ";
276                 info[1] = copyChar (temp);
277                 popupLabel (ScreenOf(question), info, 2);
278                 freeChar (info[1]);
279             }
280             else if (selection == 2)
281             {
282                 /* Print out the date. */
283                 time(&clck);
284                 currentTime = localtime(&clck);
285                 sprintf (temp, "<C>%d/%d/%02d", currentTime->tm_mday,
286                                                currentTime->tm_mon,
287                                                currentTime->tm_year % 100);
288                 info[0] = "<C>   </U>Current Date<!U>   ";
289                 info[1] = copyChar (temp);
290                 popupLabel (ScreenOf(question), info, 2);
291                 freeChar (info[1]);
292             }
293          }
294
295          /* Clean up. */
296          destroyCDKDialog (question);
297          destroyCDKScreen (cdkscreen);
298          delwin (cursesWin);
299          endCDK();
300          exit (0);
301       }
302                      ________________________________________
303
304

SEE ALSO

306       cdk(3), cdk_display(3), cdk_screen(3)
307
308
309
310                                                                cdk_binding(3)
Impressum