1cdk_binding(3) Library Functions Manual cdk_binding(3)
2
3
4
6 cdk_binding - Curses Development Kit Character Binding Capabilities.
7
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
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 deprecated: use
117 getchCDKObject.
118
119 getchCDKObject
120 reads a keycode from the given widget, and sets a flag via the
121 functionKey parameter to indicate if the result is a function key.
122 The functionKey parameter may be null; the keycode is returned
123 whether or not the flag can be set.
124
125 If the keycode has been bound to the special function getcCDKBind,
126 then it will be translated to the value which was given for the
127 binding data. Otherwise, a few special cases are performed:
128
129 ┌──────────────────────────────────────────────────────┐
130 │Key Result │
131 ├──────────────────────────────────────────────────────┤
132 │CTRL-A KEY_HOME │
133 │CTRL-B KEY_LEFT │
134 │CTRL-E KEY_END │
135 │CTRL-F KEY_RIGHT │
136 │CTRL-N tab │
137 │CTRL-P KEY_BTAB │
138 │DEL KEY_DC │
139 │backspace KEY_BACKSPACE │
140 │carriage return KEY_ENTER │
141 │newline KEY_ENTER │
142 └──────────────────────────────────────────────────────┘
143 All of the widgets use getchCDKObject internally for consistency.
144
146 To help demonstrate how to use the key bindings I will demonstrate a
147 simple dialog box widget with help for each button. The following code
148 segment creates a dialog box and a callback function named
149 dialogHelpCB.
150
151 ________________________________________
152
153 #include <cdk.h>
154
155 #ifdef HAVE_XCURSES
156 char *XCursesProgramName="bind_ex";
157 #endif
158
159 static int dialogHelpCB (EObjectType cdktype GCC_UNUSED, void *object, void *clientData GCC_UNUSED, chtype key GCC_UNUSED)
160 {
161 CDKDIALOG *dialog = (CDKDIALOG *)object;
162 char *mesg[5];
163
164 /* Check which button we are on. */
165 if (dialog->currentButton == 0)
166 {
167 mesg[0] = "<C></U>Help for </U>Who<!U>.";
168 mesg[1] = "<C>When this button is picked the name of the current";
169 mesg[2] = "<C>user is displayed on the screen in a popup window.";
170 popupLabel (ScreenOf(dialog), mesg, 3);
171 }
172 else if (dialog->currentButton == 1)
173 {
174 mesg[0] = "<C></U>Help for </U>Time<!U>.";
175 mesg[1] = "<C>When this button is picked the current time is";
176 mesg[2] = "<C>displayed on the screen in a popup window.";
177 popupLabel (ScreenOf(dialog), mesg, 3);
178 }
179 else if (dialog->currentButton == 2)
180 {
181 mesg[0] = "<C></U>Help for </U>Date<!U>.";
182 mesg[1] = "<C>When this button is picked the current date is";
183 mesg[2] = "<C>displayed on the screen in a popup window.";
184 popupLabel (ScreenOf(dialog), mesg, 3);
185 }
186 else if (dialog->currentButton == 3)
187 {
188 mesg[0] = "<C></U>Help for </U>Quit<!U>.";
189 mesg[1] = "<C>When this button is picked the dialog box is exited.";
190 popupLabel (ScreenOf(dialog), mesg, 2);
191 }
192 return (FALSE);
193 }
194
195 int main (void)
196 {
197 /* Declare variables. */
198 CDKSCREEN *cdkscreen;
199 CDKDIALOG *question;
200 char *buttons[40];
201 char *message[40], *info[5], *loginName;
202 char temp[256];
203 int selection;
204 time_t clck;
205 struct tm *currentTime;
206
207 cdkscreen = initCDKScreen (NULL);
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 endCDK();
299 exit (0);
300 }
301 ________________________________________
302
303
305 cdk(3), cdk_display(3), cdk_screen(3)
306
307
308
309 cdk_binding(3)