2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 #ifdef VERBOSE_REV_INFO
25 static char rcs_id[] = "$XConsortium: TermPrimFunction.c /main/1 1996/04/21 19:17:27 drk $";
26 #endif /* VERBOSE_REV_INFO */
30 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
31 * (c) Copyright 1993, 1994 International Business Machines Corp. *
32 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
33 * (c) Copyright 1993, 1994 Novell, Inc. *
36 #include "TermHeader.h"
37 #include "TermPrimDebug.h"
38 #include "TermPrimP.h"
39 #include "TermPrimData.h"
40 #include "TermPrimFunction.h"
41 #include "TermPrimSetPty.h"
43 /******************************************************************************
47 * # # # ### # ##### ###
50 * #### # # # ###### # #
53 * ##### #### ##### ## #####
55 * ##### #### ### # # # #####
56 * # # # ### # ###### # #
58 * ##### #### # # # # #####
62 _DtTermPrimFuncLF(Widget w, int count, FunctionSource functionSource)
64 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget)w;
65 struct termData *tpd = tw->term.tpd;
68 ** move the insert point...
70 if (++tpd->cursorRow >= tw->term.rows)
75 (void) _DtTermPrimScrollText(w, 1);
76 tpd->cursorRow = tw->term.rows - 1;
78 (void) _DtTermPrimFillScreenGap(w);
83 _DtTermPrimFuncBackspace(Widget w, int count, FunctionSource functionSource)
85 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget)w;
86 struct termData *tpd = tw->term.tpd;
88 if (tpd->cursorColumn > 0) {
89 (void) tpd->cursorColumn--;
95 _DtTermPrimFuncCR(Widget w, int count, FunctionSource functionSource)
97 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget)w;
98 struct termData *tpd = tw->term.tpd;
100 tpd->cursorColumn = tpd->leftMargin;
105 /*** CURSOR MOTION ************************************************************
107 * #### # # ##### #### #### #####
108 * # # # # # # # # # # #
109 * # # # # # #### # # # #
110 * # # # ##### # # # #####
111 * # # # # # # # # # # # #
112 * #### #### # # #### #### # #
115 * # # #### ##### # #### # #
116 * ## ## # # # # # # ## #
117 * # ## # # # # # # # # # #
118 * # # # # # # # # # # #
119 * # # # # # # # # # ##
120 * # # #### # # #### # #
124 _DtTermPrimFuncNextLine(Widget w, int count, FunctionSource functionSource)
126 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
127 struct termData *tpd = tw->term.tpd;
131 (void) _DtTermPrimCursorOff(w);
132 while (count-- > 0) {
133 if (tpd->cursorRow < tw->term.rows - 1) {
134 (void) tpd->cursorRow++;
144 _DtTermPrimFuncPreviousLine(Widget w, int count, FunctionSource functionSource)
146 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
147 struct termData *tpd = tw->term.tpd;
151 (void) _DtTermPrimCursorOff(w);
152 while (count-- > 0) {
153 if (tpd->cursorRow > 0) {
156 tpd->cursorRow = tw->term.rows - 1;
163 _DtTermPrimFuncBackwardCharacter(Widget w, int count, FunctionSource functionSource)
165 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
166 struct termData *tpd = tw->term.tpd;
170 (void) _DtTermPrimCursorOff(w);
171 while (count-- > 0) {
172 if (tpd->cursorColumn > 0) {
173 (void) tpd->cursorColumn--;
175 /* past left edge -- wrap up... */
176 tpd->cursorColumn = tw->term.columns - 1;
177 if (tpd->cursorRow > 0) {
178 (void) tpd->cursorRow--;
180 /* past first line -- wrap to bottom of screen... */
181 tpd->cursorRow = tw->term.rows - 1;
189 _DtTermPrimFuncForwardCharacter(Widget w, int count, FunctionSource functionSource)
191 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
192 struct termData *tpd = tw->term.tpd;
196 (void) _DtTermPrimCursorOff(w);
197 while (count-- > 0) {
198 if (tpd->cursorColumn < tw->term.columns - 1) {
199 (void) tpd->cursorColumn++;
201 /* past right edge -- wrap... */
202 tpd->cursorColumn = 0;
203 if (tpd->cursorRow < tw->term.rows - 1) {
204 (void) tpd->cursorRow++;
206 /* past last line -- wrap to top of screen... */
216 _DtTermPrimFuncReturn(Widget w, int count, FunctionSource functionSource)
218 Debug('i', fprintf(stderr,
219 ">>_DtTermPrimFuncReturn: not yet implemented\n"));
224 _DtTermPrimFuncTab(Widget w, int count, FunctionSource functionSource)
226 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget)w;
227 struct termData *tpd = tw->term.tpd;
228 TermBuffer tBuffer = tpd->termBuffer;
231 (void) _DtTermPrimCursorOff(w);
233 if (tpd->cursorColumn < tpd->leftMargin) {
234 /* move to left margin on current line... */
235 tpd->cursorColumn = tpd->leftMargin;
237 /* Move to the next tab stop. Note that this cursor motion is
238 * similar to the right arrow cursor motion in that
239 * it doesn't set the line length until a character is entered.
241 /* DKS: this code currently enforces tabs at every 8 character
242 * positions. It needs to be worked on to support the margins/tabs
245 nextTab = _DtTermPrimBufferGetNextTab(tBuffer, tpd->cursorColumn);
247 /* check to see if we are past the end of the line... */
248 if ((nextTab <= 0) || (nextTab >= tpd->rightMargin)) {
249 /* wrap to next line...
251 tpd->cursorColumn = tpd->leftMargin;
253 /* check to see if we scrolled off the bottom of the screen... */
254 if (++tpd->cursorRow >= tw->term.rows) {
255 /* scroll one line...
257 (void)_DtTermPrimScrollText(w, 1);
258 tpd->cursorRow = tw->term.rows - 1;
260 /* fill any screen gap... */
261 if (tpd->topRow + tpd->cursorRow >= tpd->lastUsedRow) {
262 (void) _DtTermPrimFillScreenGap(w);
265 tpd->cursorColumn = nextTab;
273 /*** TAB FUNCTIONS ************************************************************
283 * ###### # # # # #### ##### # #### # # ####
284 * # # # ## # # # # # # # ## # #
285 * ##### # # # # # # # # # # # # # ####
286 * # # # # # # # # # # # # # # #
287 * # # # # ## # # # # # # # ## # #
288 * # #### # # #### # # #### # # ####
292 _DtTermPrimFuncTabSet(Widget w, int count, FunctionSource functionSource)
294 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
295 struct termData *tpd = tw->term.tpd;
297 (void) _DtTermPrimBufferSetTab(tpd->termBuffer, tpd->cursorColumn);
301 _DtTermPrimFuncTabClear(Widget w, int count, FunctionSource functionSource)
303 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
304 struct termData *tpd = tw->term.tpd;
306 (void) _DtTermPrimBufferClearTab(tpd->termBuffer, tpd->cursorColumn);
310 _DtTermPrimFuncTabClearAll(Widget w, int count, FunctionSource functionSource)
312 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
313 struct termData *tpd = tw->term.tpd;
315 (void) _DtTermPrimBufferClearAllTabs(tpd->termBuffer);
319 /*** REDRAW DISPLAY ***********************************************************
321 * # # ## ##### #### # # #
322 * ## ## # # # # # # # ## #
323 * # ## # # # # # # # # # #
324 * # # ###### ##### # ### # # # #
325 * # # # # # # # # # # ##
326 * # # # # # # #### # # #
329 * ###### # # # # #### ##### # #### # # ####
330 * # # # ## # # # # # # # ## # #
331 * ##### # # # # # # # # # # # # # ####
332 * # # # # # # # # # # # # # # #
333 * # # # # ## # # # # # # # ## # #
334 * # #### # # #### # # #### # # ####
337 _DtTermPrimFuncMarginSetLeft(Widget w, int count, FunctionSource functionSource)
339 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
340 struct termData *tpd = tw->term.tpd;
342 if (tpd->cursorColumn < tpd->rightMargin) {
343 tpd->leftMargin = tpd->cursorColumn;
351 _DtTermPrimFuncMarginSetRight(Widget w, int count, FunctionSource functionSource)
353 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
354 struct termData *tpd = tw->term.tpd;
356 if (tpd->cursorColumn > tpd->leftMargin) {
357 tpd->rightMargin = tpd->cursorColumn;
365 _DtTermPrimFuncMarginClear(Widget w, int count, FunctionSource functionSource)
367 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget)w;
368 struct termData *tpd = tw->term.tpd;
371 tpd->rightMargin = tw->term.columns - 1;
376 /*** REDRAW DISPLAY ***********************************************************
378 * ##### ###### ##### ##### ## # #
379 * # # # # # # # # # # #
380 * # # ##### # # # # # # # #
381 * ##### # # # ##### ###### # ## #
382 * # # # # # # # # # ## ##
383 * # # ###### ##### # # # # # #
386 * ##### # #### ##### # ## # #
387 * # # # # # # # # # # #
388 * # # # #### # # # # # #
389 * # # # # ##### # ###### #
390 * # # # # # # # # # #
391 * ##### # #### # ###### # # #
395 _DtTermPrimFuncRedrawDisplay(Widget w, int count, FunctionSource functionSource)
397 DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
398 struct termData *tpd = tw->term.tpd;
400 (void) XClearArea(XtDisplay(w), XtWindow(w), 0, 0, 0, 0, True);