Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtTerm / TermPrim / TermPrimBuffer.h
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 /* 
24 ** $XConsortium: TermPrimBuffer.h /main/1 1996/04/21 19:16:53 drk $
25 */
26
27 /*                                                                      *
28  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
29  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
30  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
31  * (c) Copyright 1993, 1994 Novell, Inc.                                *
32  */
33
34 #ifndef   _Dt_TermPrimBuffer_h
35 #define   _Dt_TermPrimBuffer_h
36
37 typedef struct _TermLineSelectionRec *TermLineSelection;
38 typedef struct _TermBufferRec   *TermBuffer;
39 typedef struct _TermEnhInfoRec  *TermEnhInfo;
40 typedef struct _TermCharInfoRec *TermCharInfo;
41
42 #include  <Xm/Xm.h>
43 #include  "TermPrimOSDepI.h"
44 #include  "TermPrimRender.h"
45 #include  "TermPrimSelect.h"
46
47 #define TermENH_SECURE                  (1 << 0)
48 #define TermENH_UNDERLINE               (1 << 1)
49 #define TermENH_OVERSTRIKE              (1 << 2)
50
51 #define TermIS_SECURE(flags)            ((flags) & TermENH_SECURE)
52 #define TermIS_UNDERLINE(flags)         ((flags) & TermENH_UNDERLINE)
53 #define TermIS_OVERSTRIKE(flags)        ((flags) & TermENH_OVERSTRIKE)
54
55 typedef unsigned char   enhValue;
56 typedef enhValue       *enhValues;
57
58 typedef enum _countSpec
59 {
60     countAll, countNew
61 } countSpec;
62
63 #ifdef     __cplusplus
64 extern "C" {
65 #endif  /* __cplusplus */
66
67 typedef unsigned char termChar;
68
69 typedef struct _TermEnhInfoRec {
70     Pixel fg;
71     Pixel bg;
72     TermFont font;
73     unsigned long flags;
74 } TermEnhInfoRec;
75
76 typedef struct _TermCharInfoRec {
77     union 
78     {
79         termChar *ptc;
80         char     *pc;
81         wchar_t  *pwc;
82     } u;
83     short       idx;        /* index into line buffer   */
84     short       len;        /* bytes per character      */
85     short       startCol;
86     short       width;
87     enhValue    enh;
88     short       enhLen;
89 } TermCharInfoRec;
90
91 typedef TermBuffer  
92 (*BufferCreateProc)
93 (
94     const Widget,
95     const short,
96     const short,
97     const short,
98     const short,
99     const short
100 );
101
102 typedef void
103 (*BufferFreeProc)
104 (
105     const TermBuffer
106 );
107
108 typedef void
109 (*BufferResizeProc)
110 (
111     TermBuffer, short *, short *
112 );
113
114 typedef void
115 (*TermEnhProc)
116 (
117     Widget, enhValues, TermEnhInfo
118 );
119
120 typedef void
121 (*TermEnhClear)
122 (
123     TermBuffer,
124     short,
125     short,
126     short
127 );
128
129 typedef void
130 (*TermEnhInsert)
131 (
132     const TermBuffer,
133     const short,
134     const short, 
135     short,
136     const Boolean
137 );
138
139 typedef void
140 (*TermEnhDelete)
141 (
142     TermBuffer,
143     short,
144     short,
145     short
146 );
147
148 typedef int
149 (*TermEnhSet)
150 (
151     TermBuffer,
152     short,
153     short,
154     unsigned char,
155     enhValue
156 );
157
158 typedef Boolean 
159 (*TermEnhGet)
160 (
161     const TermBuffer,
162     const short,
163     const short,
164           enhValue **,
165           short *, 
166     const countSpec
167 );
168
169 typedef Boolean
170 (*TermLineSetLen)
171 (
172     TermBuffer,
173     short,
174     short
175 );
176
177 typedef Boolean
178 (*TermLineSetWidth)
179 (
180     TermBuffer,
181     short,
182     short
183 );
184
185 typedef Boolean
186 (*TermLineClear)
187 (
188     TermBuffer,
189     short,
190     short
191 );
192
193 #ifdef USE_SUN_WCWIDTH_PATCH
194 /* 
195 **  A small workaround for systems that don't have wcwidth...
196 */
197 int
198 sun_wcwidth
199 (
200     const wchar_t wc
201 );
202 #endif /*  USE_SUN_WCWIDTH_PATCH */
203
204 #ifdef USE_USL_WCWIDTH_PATCH
205 /* 
206 **  A small workaround for systems that don't have wcwidth...
207 */
208 int
209 usl_wcwidth
210 (
211     const wchar_t wc
212 );
213 #endif /*  USE_USL_WCWIDTH_PATCH */
214
215
216 /* 
217 ** Truncate the specified line to the desired width, return 
218 **
219 ** Inputs:
220 **      tb  - term buffer to act on
221 **      row - row to truncate
222 **
223 ** Returns:
224 **      True/False to indicate success or failure
225 */
226 extern Boolean
227 _DtTermPrimBufferClearLine
228 (
229     const TermBuffer  tb,
230     const short       row,
231           short       newWidth
232 );
233
234 /* 
235 ** Create a new term buffer of the desired dimensions.
236 ** 
237 ** Inputs:
238 **      rows - desired number of rows
239 **      cols - desired number of columns
240 **      sizeOfBuffer - bytes per 
241 **      sizeOfLine   - bytes per line record
242 **      sizeOfEnh    - bytes per enhancement chunk
243 **
244 ** Returns:
245 **      pointer to new TermBuffer, else NULL
246 */
247 extern TermBuffer
248 _DtTermPrimBufferCreateBuffer
249 (
250     const Widget  w,
251     const short   rows,
252     const short   cols,
253     const short   sizeOfBuffer,
254     const short   sizeOfLine,
255     const short   sizeOfEnh
256 );
257     
258 /*
259 ** replace all characters between startCol, and endCol with spaces,
260 */
261 void
262 _DtTermPrimBufferErase
263 (
264     TermBuffer tb,
265     short      row,
266     short      startCol,
267     short      stopCol
268 );
269
270 /*
271 ** replace all wide characters between startCol, and endCol with spaces,
272 */
273 void
274 _DtTermPrimBufferEraseWc
275 (
276     TermBuffer tb,
277     short      row,
278     short      startCol,
279     short      stopCol
280 );
281
282
283 /* 
284 ** Free all storage allocated to the specified buffer.
285 **
286 ** Inputs:
287 **      tb - TermBuffer to free
288 */
289 extern void
290 _DtTermPrimBufferFreeBuffer
291 (
292     const TermBuffer  tb
293 );
294     
295 /* 
296 ** Change the dimensions of the specified buffer to the new size.
297 **
298 ** Inputs:
299 **      *tb      - pointer to term buffer to resize
300 **      *newRows - number of rows desired
301 **      *newCols - number of cols desired
302 **      
303 ** Returns:
304 **      potentially adjusted values for newRows and newCols
305 */
306 extern void
307 _DtTermPrimBufferResizeBuffer
308 (
309     TermBuffer *tb,
310     short      *newRows,
311     short      *newCols
312 );
313
314 /* 
315 ** Create an enhancement chunk at the specified position.
316 **
317 ** Inputs:
318 **      tb      - term buffer
319 **      row,col - coordinates of new enhancement chunk
320 **
321 ** Returns:
322 **      True/False depending on success/failure
323 */
324 extern Boolean
325 _DtTermPrimBufferCreateEnhancement
326 (
327     TermBuffer  tb,
328     short       row,
329     short       col
330 );
331
332 /* 
333 ** Free the enhancement chunk at the specified position.
334 **
335 ** Inputs:
336 **      tb      - term buffer
337 **      row,col - coordinates of new enhancement chunk
338 **
339 ** Returns:
340 **      True/False depending on success/failure
341 */
342 extern Boolean
343 _DtTermPrimBufferFreeEnhancement
344 (
345     const TermBuffer  tb,
346     const short       row,
347     const short       col
348 );   
349
350 /* 
351 ** Get text from the buffer.
352 ** 
353 ** Inputs:
354 **      tb           - term buffer
355 **      row,col      - coordinates to get text from
356 **      length       - length of buffer
357 **      needWideChar - true if need wide characters (not multi-byte chars)
358 **
359 ** Outputs:
360 **      buffer  - pointer to buffer containing text
361 **
362 ** Returns:
363 **      the actual number of characters in the buffer
364 */
365 extern short
366 _DtTermPrimBufferGetText
367 (
368     const TermBuffer      tb,
369     const short           row,
370     const short           col,
371     const short           length,
372     char                 *buffer,
373     const Boolean         needWideChar
374 );
375
376 /*
377 ** Return a pointer to the character at the specified position.
378 **
379 ** Inputs:
380 **      tb      - term buffer
381 **      row,col - coordinates of desired character
382 **
383 ** Returns:
384 **      pointer to desired character
385 */
386 extern termChar *
387 _DtTermPrimBufferGetCharacterPointer
388 (
389     const TermBuffer  tb,
390     const short       row,
391     const short       col
392 );
393
394 /* 
395 ** Insert 'numChar' characters into the buffer at the specified position.
396 ** 
397 ** 
398 */
399 extern short
400 _DtTermPrimBufferInsert
401 (
402     const TermBuffer  tb,
403     const short       row,
404     const short       col,
405     const termChar   *newChars,
406           short       numChars,
407           Boolean     insertFlag,   /* if TRUE, insert, else overwrite        */
408           termChar  **returnChars,  /* pointer to overflow buffer             */
409           short      *returnCount   /* count of characters in overflow buffer */
410 );
411
412 /* 
413 ** Delete enough characters from the buffer to exceed width.
414 **
415 ** If returnChars != NULL then the deleted characters are returned
416 ** in a buffer pointed to by returnChars.  It is the responsibility
417 ** of the calling function to XtFree the buffer containing returned
418 ** characters when they are no longer needed.
419 */
420 extern void
421 _DtTermPrimBufferDelete
422 (
423     TermBuffer  tb,
424     short      *row,
425     short      *col,
426     short      *count,
427     termChar  **returnChars,  /* pointer to delete buffer        */
428     short      *returnCount   /* count of bytes in delete buffer */
429 );
430
431 extern void
432 _DtTermPrimBufferDeleteWc
433 (
434     TermBuffer  tb,
435     short      *row,
436     short      *col,
437     short      *count,
438     termChar  **returnChars,  /* pointer to delete buffer        */
439     short      *returnCount   /* count of bytes in delete buffer */
440 );
441
442 extern Boolean
443 _DtTermPrimBufferSetLineWidth
444 (
445     const TermBuffer      tb,
446     const short           row,
447           short           newWidth
448 );
449
450 extern short
451 _DtTermPrimBufferGetLineLength
452 (
453     const TermBuffer      tb,
454     const short           row
455 );
456
457 extern short
458 _DtTermPrimBufferGetLineWidth
459 (
460     const TermBuffer      tb,
461     const short           row
462 );
463
464 extern int
465 _DtTermPrimBufferSetEnhancement
466 (
467     const TermBuffer      tb,
468     const short           row,
469     const short           col,
470     const unsigned char   id,
471     const enhValue        value
472 );
473
474 extern Boolean
475 _DtTermPrimBufferGetEnhancement
476 (
477     const TermBuffer      tb,
478     const short           row,
479     const short           col,
480           enhValue      **values,
481           short          *count,
482     const countSpec       countWhich
483 );
484
485 /*
486 ** Return the number of rows allocated to the term buffer.
487 */
488 extern short
489 _DtTermPrimBufferGetRows
490 (
491     const TermBuffer      tb
492 );
493
494 /*
495 ** Return the number of columns allocated to the term buffer.
496 */
497 extern short
498 _DtTermPrimBufferGetCols
499 (
500     const TermBuffer    tb
501 );
502
503 /*
504 ** Set the value of the term buffer's nextBuffer and prevBuffer pointers.
505 */
506 extern void
507 _DtTermPrimBufferSetLinks
508 (
509     const TermBuffer    tb,
510     const TermBuffer    prev,
511     const TermBuffer    next
512 );
513
514 /*
515 ** Set the value of the term buffer's selectInfo pointer.
516 */
517 extern void
518 _DtTermPrimBufferSetSelectInfo
519 (
520     const TermBuffer        tb,
521     const TermSelectInfo    si
522 );
523
524 extern void
525 _DtTermPrimBufferMoveLockArea
526 (
527     const TermBuffer        tb,
528     const short             dest,
529     const short             src,
530     const short             length
531 );
532
533 typedef enum {
534     insertFromTop,
535     insertFromBottom
536 } InsertSource;
537
538 extern void
539 _DtTermPrimBufferInsertLine
540 (
541     const TermBuffer        tb,
542     const short             dest,
543     const short             length,
544     const short             src
545 );
546
547 extern void
548 _DtTermPrimBufferInsertLineFromTB
549 (
550     const TermBuffer        tb,
551     const short             dest,
552     const short             length,
553     const InsertSource    insertSource
554 );
555
556 extern void
557 _DtTermPrimBufferDeleteLine
558 (
559     const TermBuffer        tb,
560     const short             source,
561     const short             length,
562     const short             lastUsedRow
563 );
564
565 extern void
566 _DtTermPrimBufferPadLine
567 (
568     const TermBuffer  tb,
569     const short       row,
570     const short       newWidth
571 );
572
573 extern void
574 _DtTermPrimBufferPadLineWc
575 (
576     const TermBuffer  tb,
577     const short       row,
578     const short       newWidth
579 );
580
581 extern Boolean
582 _DtTermPrimGetCharacterInfo
583 (
584     TermBuffer      tb,
585     short           row,
586     short           col,
587     TermCharInfo    charInfo
588 );
589
590 extern short
591 _DtTermPrimBufferGetNextTab
592 (
593     const TermBuffer    tb,
594           short         col
595 );
596
597 extern short
598 _DtTermPrimBufferGetPreviousTab
599 (
600     const TermBuffer    tb,
601           short         col
602 );
603
604 extern Boolean
605 _DtTermPrimBufferSetTab
606 (
607     const TermBuffer    tb,
608     const short         col
609 );
610
611 extern Boolean
612 _DtTermPrimBufferClearTab
613 (
614     const TermBuffer    tb,
615     const short         col
616 );
617
618 extern Boolean
619 _DtTermPrimBufferClearAllTabs
620 (
621     const TermBuffer    tb
622 );
623
624 /*
625 ** Return the value of the line wrap flag for the current line
626 */
627 extern Boolean
628 _DtTermPrimBufferTestLineWrapFlag
629 (
630     TermBuffer  tb,
631     short       row
632 );
633
634 /*
635 ** set the line wrap flag to the desired state
636 */
637 void
638 _DtTermPrimBufferSetLineWrapFlag
639 (
640     TermBuffer  tb,
641     short       row,
642     Boolean     state
643 );
644
645 /*
646 ** Return the value of the in selection flag for the current line
647 */
648 extern TermLineSelection
649 _DtTermPrimBufferGetInSelectionFlag
650 (
651     TermBuffer  tb,
652     short       row
653 );
654
655 /*
656 ** set the in selection flag to the desired state
657 */
658 void
659 _DtTermPrimBufferSetInSelectionFlag
660 (
661     TermBuffer  tb,
662     short       row,
663     TermLineSelection     state
664 );
665 #ifdef  __cplusplus
666 } /* close scope of 'extern "C"'... */
667 #endif  /* __cplusplus */
668
669 #endif /* _Dt_TermPrimBuffer_h */
670 /* DON'T ADD ANYTHING AFTER THIS #endif... */