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