Annotation of othersrc/dist/cdk/binding.c, revision 1.1.1.1
1.1 garbled 1: #include <cdk.h>
2:
3: /*
4: * $Author: tom $
5: * $Date: 2000/02/18 23:20:55 $
6: * $Revision: 1.38 $
7: */
8:
9: /*
10: * Declare file local prototypes.
11: */
12: static int mapChtype (chtype key);
13:
14: /*
15: * This inserts a binding.
16: */
17: void bindCDKObject (EObjectType cdktype, void *object, chtype key, BINDFN function, void * data)
18: {
19: int Index = mapChtype (key);
20: CDKOBJS *obj = (CDKOBJS *)object;
21:
22: /*
23: * When an alarm is set and this function is entered, a very wild
24: * value for the key is provided, and the index gets messed up big time.
25: * So we will make sure that index is a valid value before using it.
26: */
27: if ((Index >= 0) && (Index < MAX_BINDINGS))
28: {
29: if (cdktype == vFSELECT)
30: {
31: bindCDKObject (vENTRY, ((CDKFSELECT *)object)->entryField, key, function, data);
32: }
33: else if (cdktype == vALPHALIST)
34: {
35: bindCDKObject (vENTRY, ((CDKALPHALIST *)object)->entryField, key, function, data);
36: }
37: else
38: {
39: if (Index >= obj->bindingCount)
40: {
41: unsigned next = (Index + 1);
42: unsigned need = next * sizeof(CDKBINDING);
43:
44: if (obj->bindingList != 0)
45: obj->bindingList = (CDKBINDING *)realloc(obj->bindingList, need);
46: else
47: obj->bindingList = (CDKBINDING *)malloc(need);
48:
49: memset(&(obj->bindingList[obj->bindingCount]), 0,
50: (next - obj->bindingCount) * sizeof(CDKBINDING));
51: obj->bindingCount = next;
52: }
53:
54: if (obj->bindingList != 0)
55: {
56: obj->bindingList[Index].bindFunction = function;
57: obj->bindingList[Index].bindData = data;
58: }
59: }
60: }
61: }
62:
63: /*
64: * This removes a binding on an object.
65: */
66: void unbindCDKObject (EObjectType cdktype, void *object, chtype key)
67: {
68: int Index = mapChtype(key);
69: CDKOBJS *obj = (CDKOBJS *)object;
70:
71: /*
72: * When an alarm is set and this function is entered, a very wild
73: * value for the key is provided, and the index gets messed up big time.
74: * So we will make sure that index is a valid value before using it.
75: */
76: if (cdktype == vFSELECT)
77: {
78: unbindCDKObject (vENTRY, ((CDKFSELECT *)object)->entryField, key);
79: }
80: else if (cdktype == vALPHALIST)
81: {
82: unbindCDKObject (vENTRY, ((CDKALPHALIST *)object)->entryField, key);
83: }
84: else if (Index >= 0 && Index < obj->bindingCount)
85: {
86: obj->bindingList[Index].bindFunction = 0;
87: obj->bindingList[Index].bindData = 0;
88: }
89: }
90:
91: /*
92: * This sets all the bindings for the given objects.
93: */
94: void cleanCDKObjectBindings (EObjectType cdktype, void *object)
95: {
96: /*
97: * Since dereferencing a void pointer is a no-no, we have to cast
98: * our pointer correctly.
99: */
100: if (cdktype == vFSELECT)
101: {
102: cleanCDKObjectBindings (vENTRY, ((CDKFSELECT *)object)->entryField);
103: cleanCDKObjectBindings (vSCROLL, ((CDKFSELECT *)object)->scrollField);
104: }
105: else if (cdktype == vALPHALIST)
106: {
107: cleanCDKObjectBindings (vENTRY, ((CDKALPHALIST *)object)->entryField);
108: cleanCDKObjectBindings (vSCROLL, ((CDKALPHALIST *)object)->scrollField);
109: }
110: else
111: {
112: int x;
113: CDKOBJS *obj = (CDKOBJS *)object;
114: for (x=0; x < obj->bindingCount; x++)
115: {
116: (obj)->bindingList[x].bindFunction = 0;
117: (obj)->bindingList[x].bindData = 0;
118: }
119: }
120: }
121:
122: /*
123: * This checks to see iof the binding for the key exists. If it does then it
124: * runs the command and returns a TRUE. If it doesn't it returns a FALSE. This
125: * way we can 'overwrite' coded bindings.
126: */
127: int checkCDKObjectBind (EObjectType cdktype, void *object, chtype key)
128: {
129: int Index = mapChtype (key);
130: CDKOBJS *obj = (CDKOBJS *)object;
131:
132: /*
133: * When an alarm is set and this function is entered, a very wild
134: * value for the key is provided, and the index gets messed up big time.
135: * So we will make sure that index is a valid value before using it.
136: */
137: if ((Index >= 0) && (Index < obj->bindingCount))
138: {
139: if ( (obj)->bindingList[Index].bindFunction != 0 )
140: {
141: BINDFN function = obj->bindingList[Index].bindFunction;
142: void * data = obj->bindingList[Index].bindData;
143: function (cdktype, object, data, key);
144: return (TRUE);
145: }
146: }
147: return (FALSE);
148: }
149:
150: /*
151: * This translates non ascii characters like KEY_UP to an 'equivalent'
152: * ascii value.
153: */
154: static int mapChtype (chtype key)
155: {
156: static const struct {
157: int key_out;
158: chtype key_in;
159: } table[] = {
160: { 257, KEY_UP },
161: { 258, KEY_DOWN },
162: { 259, KEY_LEFT },
163: { 260, KEY_RIGHT },
164: { 261, KEY_NPAGE },
165: { 262, KEY_PPAGE },
166: { 263, KEY_HOME },
167: { 264, KEY_END },
168: { 265, KEY_F0 },
169: { 266, KEY_F1 },
170: { 267, KEY_F2 },
171: { 268, KEY_F3 },
172: { 269, KEY_F4 },
173: { 270, KEY_F5 },
174: { 271, KEY_F6 },
175: { 272, KEY_F7 },
176: { 273, KEY_A1 },
177: { 274, KEY_A3 },
178: { 275, KEY_B2 },
179: { 276, KEY_C1 },
180: { 277, KEY_C3 },
181: { 278, KEY_ESC },
182: };
183: unsigned n;
184:
185: for (n = 0; n < sizeof(table)/sizeof(table[0]); n++)
186: {
187: if (table[n].key_in == key)
188: {
189: key = table[n].key_out;
190: break;
191: }
192: }
193: return (key);
194: }
CVSweb <webmaster@jp.NetBSD.org>