Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtTerm / TermPrim / TermPrimAction.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 #ifndef lint
24 #ifdef  VERBOSE_REV_INFO
25 static char rcs_id[] = "$XConsortium: TermPrimAction.c /main/1 1996/04/21 19:16:44 drk $";
26 #endif  /* VERBOSE_REV_INFO */
27 #endif  /* lint */
28
29 /*                                                                      *
30  * (c) Copyright 1993, 1994, 1996 Hewlett-Packard Company               *
31  * (c) Copyright 1993, 1994, 1996 International Business Machines Corp. *
32  * (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc.                *
33  * (c) Copyright 1993, 1994, 1996 Novell, Inc.                          *
34  * (c) Copyright 1996 Digital Equipment Corporation.                    *
35  * (c) Copyright 1996 FUJITSU LIMITED.                                  *
36  * (c) Copyright 1996 Hitachi.                                          *
37  */
38
39 #include "TermHeader.h"
40 #include "TermPrimDebug.h"
41 #include "TermPrimP.h"
42 #include "TermPrimI.h"
43 #include "TermPrimData.h"
44 #include "TermPrimAction.h"
45 #include "TermPrimFunction.h"
46
47 static void
48 invokeAction(Widget w, char *transmitString, TermFunction function, int count)
49 {
50     DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
51     struct termData *tpd = tw->term.tpd;
52
53     if (KEYBOARD_LOCKED(tpd->keyboardLocked)) {
54         /* keyboard locked -- ring the bell...
55          */
56         (void) _DtTermPrimBell(w);
57     } else if (tpd->transmitFunctions && transmitString) {
58         /* transmit functions mode -- transmit them...
59          */
60         (void) _DtTermPrimSendInput(w, (unsigned char *) transmitString,
61                 strlen(transmitString));
62     } else {
63         /* perform the function...
64          */
65         (*function)(w, count, fromAction);
66
67 #ifdef  NOTDEF
68         /* we need to wait for the scroll to complete before turning
69          * on the cursor...
70          */
71         (void) _DtTermPrimScrollComplete(w, True);
72 #endif  /* NOTDEF */
73         (void) _DtTermPrimCursorOn(w);
74     }
75     return;
76 }
77
78 typedef struct {
79     const char *string;
80     char value;
81 } EnumType;
82
83 static int
84 stringToEnum(char *c, EnumType *enumTypes, int numEnumTypes)
85 {
86     int i;
87
88     for (i = 0; i < numEnumTypes; i++) {
89         if (!strcmp(enumTypes[i].string, c))
90             return(i);
91     }
92
93     return(-1);
94 }
95
96 \f
97 /*** INSERT CHAR/LINE *********************************************************
98  * 
99  *     #    #    #   ####   ######  #####    #####
100  *     #    ##   #  #       #       #    #     #
101  *     #    # #  #   ####   #####   #    #     #
102  *     #    #  # #       #  #       #####      #
103  *     #    #   ##  #    #  #       #   #      #
104  *     #    #    #   ####   ######  #    #     #
105  * 
106  *                                       #
107  *   ####   #    #    ##    #####       #   #          #    #    #  ######
108  *  #    #  #    #   #  #   #    #     #    #          #    ##   #  #
109  *  #       ######  #    #  #    #    #     #          #    # #  #  #####
110  *  #       #    #  ######  #####    #      #          #    #  # #  #
111  *  #    #  #    #  #    #  #   #   #       #          #    #   ##  #
112  *   ####   #    #  #    #  #    # #        ######     #    #    #  ######
113  */
114
115 void
116 _DtTermPrimActionInsert(Widget w, XEvent *event,
117         String *params, Cardinal *num_params)
118 {
119     Debug('i', fprintf(stderr,
120             ">>_DtTermPrimActionInsert: not yet implemented\n"));
121 }
122
123
124 \f
125 /*** CURSOR MOTION ************************************************************
126  * 
127  *   ####   #    #  #####    ####    ####   #####
128  *  #    #  #    #  #    #  #       #    #  #    #
129  *  #       #    #  #    #   ####   #    #  #    #
130  *  #       #    #  #####        #  #    #  #####
131  *  #    #  #    #  #   #   #    #  #    #  #   #
132  *   ####    ####   #    #   ####    ####   #    #
133  * 
134  * 
135  *  #    #   ####    #####     #     ####   #    #
136  *  ##  ##  #    #     #       #    #    #  ##   #
137  *  # ## #  #    #     #       #    #    #  # #  #
138  *  #    #  #    #     #       #    #    #  #  # #
139  *  #    #  #    #     #       #    #    #  #   ##
140  *  #    #   ####      #       #     ####   #    #
141  */
142
143 void
144 _DtTermPrimActionRedrawDisplay(Widget w, XEvent *event,
145         String *params, Cardinal *num_params)
146 {
147     (void) invokeAction(w, NULL, _DtTermPrimFuncRedrawDisplay, 1);
148     return;
149 }
150
151
152 void
153 _DtTermPrimActionReturn(Widget w, XEvent *event,
154         String *params, Cardinal *num_params)
155 {
156     Debug('i', fprintf(stderr,
157             ">>_DtTermPrimActionReturn: not yet implemented\n"));
158     return;
159 }
160
161 void
162 _DtTermPrimActionTab(Widget w, XEvent *event,
163         String *params, Cardinal *num_params)
164 {
165     DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
166     struct termData *tpd = tw->term.tpd;
167     Boolean shiftedTab = False;
168     Boolean numericTab = False;
169     int i;
170
171     (void) _DtTermPrimSendInput(w, (unsigned char *) "\t", 1);
172     return;
173 }
174
175 \f
176 /*** STRING *******************************************************************
177  *  
178  *   ####    #####  #####      #    #    #   ####
179  *  #          #    #    #     #    ##   #  #    #
180  *   ####      #    #    #     #    # #  #  #
181  *       #     #    #####      #    #  # #  #  ###
182  *  #    #     #    #   #      #    #   ##  #    #
183  *   ####      #    #    #     #    #    #   ####
184  */
185
186 void
187 _DtTermPrimActionString(Widget w, XEvent *event, String *params, Cardinal *num_params)
188 {
189     unsigned char *c;
190     unsigned char hexVal;
191
192     /* this is based on the functionality offered by xterm...
193      */
194
195     if (*num_params != 1)
196         return;
197
198     /* process hex values... */
199     if (((*params)[0] == '0') &&
200             (((*params)[1] == 'x') || ((*params)[1] == 'X')) &&
201             ((*params)[2] != '\0')) {
202         for (hexVal = 0, c = (unsigned char *) (*params + 2); *c; c++) {
203             hexVal *= 16;
204             *c = tolower(*c);
205             if ((*c >= '0') && (*c <= '9')) {
206                 hexVal += *c - '0';
207             } else if ((*c >= 'a') && (*c <= 'f')) {
208                 hexVal += *c - 'a' + 10;
209             } else {
210                 break;
211             }
212         }
213         /* if we hit the end of the string, send the hex value... */
214         if (*c == '\0') {
215             (void) _DtTermPrimSendInput(w, &hexVal, 1);
216         }
217     } else {
218         (void) _DtTermPrimSendInput(w, (unsigned char *) *params, strlen(*params));
219     }
220     return;
221 }
222             
223 \f
224 /*** KEYMAP *******************************************************************
225  * 
226  *  #    #  ######   #   #  #    #    ##    #####
227  *  #   #   #         # #   ##  ##   #  #   #    #
228  *  ####    #####      #    # ## #  #    #  #    #
229  *  #  #    #          #    #    #  ######  #####
230  *  #   #   #          #    #    #  #    #  #
231  *  #    #  ######     #    #    #  #    #  #
232  */
233
234 void
235 _DtTermPrimActionKeymap(Widget w, XEvent *event, String *params, Cardinal *num_params)
236 {
237     XtTranslations keymap;
238     char buffer[BUFSIZ];
239     static XtTranslations original = (XtTranslations) 0;
240     static XtResource key_resources[] = {
241         {XtNtranslations, XtCTranslations, XtRTranslationTable,
242                 sizeof(XtTranslations), 0, XtRTranslationTable, (caddr_t) NULL}
243     };
244     char mapName[BUFSIZ];
245     char mapClass[BUFSIZ];
246
247     if (*num_params != 1) {
248         return;
249     }
250
251     _DtTermProcessLock();
252     if (original == (XtTranslations) 0) {
253         original = w->core.tm.translations;
254     }
255     _DtTermProcessUnlock();
256
257     if (!strcmp(params[0], "None")) {
258         (void) XtOverrideTranslations(w, original);
259         return;
260     }
261
262     (void) sprintf(mapName, "%sKeymap", params[0]);
263     (void) strcpy(mapClass, mapName);
264     mapClass[0] = toupper(mapClass[0]);
265     (void) XtGetSubresources(w, (XtPointer) &keymap, mapName, mapClass,
266             key_resources, XtNumber(key_resources), NULL, (Cardinal) 0);
267
268     if (keymap != NULL) {
269         (void) XtOverrideTranslations(w, keymap);
270     }
271     return;
272 }