Remove Unixware and openserver support
[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 libraries 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
205 /* 
206 ** Truncate the specified line to the desired width, return 
207 **
208 ** Inputs:
209 **      tb  - term buffer to act on
210 **      row - row to truncate
211 **
212 ** Returns:
213 **      True/False to indicate success or failure
214 */
215 extern Boolean
216 _DtTermPrimBufferClearLine
217 (
218     const TermBuffer  tb,
219     const short       row,
220           short       newWidth
221 );
222
223 /* 
224 ** Create a new term buffer of the desired dimensions.
225 ** 
226 ** Inputs:
227 **      rows - desired number of rows
228 **      cols - desired number of columns
229 **      sizeOfBuffer - bytes per 
230 **      sizeOfLine   - bytes per line record
231 **      sizeOfEnh    - bytes per enhancement chunk
232 **
233 ** Returns:
234 **      pointer to new TermBuffer, else NULL
235 */
236 extern TermBuffer
237 _DtTermPrimBufferCreateBuffer
238 (
239     const Widget  w,
240     const short   rows,
241     const short   cols,
242     const short   sizeOfBuffer,
243     const short   sizeOfLine,
244     const short   sizeOfEnh
245 );
246     
247 /*
248 ** replace all characters between startCol, and endCol with spaces,
249 */
250 void
251 _DtTermPrimBufferErase
252 (
253     TermBuffer tb,
254     short      row,
255     short      startCol,
256     short      stopCol
257 );
258
259 /*
260 ** replace all wide characters between startCol, and endCol with spaces,
261 */
262 void
263 _DtTermPrimBufferEraseWc
264 (
265     TermBuffer tb,
266     short      row,
267     short      startCol,
268     short      stopCol
269 );
270
271
272 /* 
273 ** Free all storage allocated to the specified buffer.
274 **
275 ** Inputs:
276 **      tb - TermBuffer to free
277 */
278 extern void
279 _DtTermPrimBufferFreeBuffer
280 (
281     const TermBuffer  tb
282 );
283     
284 /* 
285 ** Change the dimensions of the specified buffer to the new size.
286 **
287 ** Inputs:
288 **      *tb      - pointer to term buffer to resize
289 **      *newRows - number of rows desired
290 **      *newCols - number of cols desired
291 **      
292 ** Returns:
293 **      potentially adjusted values for newRows and newCols
294 */
295 extern void
296 _DtTermPrimBufferResizeBuffer
297 (
298     TermBuffer *tb,
299     short      *newRows,
300     short      *newCols
301 );
302
303 /* 
304 ** Create an enhancement chunk at the specified position.
305 **
306 ** Inputs:
307 **      tb      - term buffer
308 **      row,col - coordinates of new enhancement chunk
309 **
310 ** Returns:
311 **      True/False depending on success/failure
312 */
313 extern Boolean
314 _DtTermPrimBufferCreateEnhancement
315 (
316     TermBuffer  tb,
317     short       row,
318     short       col
319 );
320
321 /* 
322 ** Free the enhancement chunk at the specified position.
323 **
324 ** Inputs:
325 **      tb      - term buffer
326 **      row,col - coordinates of new enhancement chunk
327 **
328 ** Returns:
329 **      True/False depending on success/failure
330 */
331 extern Boolean
332 _DtTermPrimBufferFreeEnhancement
333 (
334     const TermBuffer  tb,
335     const short       row,
336     const short       col
337 );   
338
339 /* 
340 ** Get text from the buffer.
341 ** 
342 ** Inputs:
343 **      tb           - term buffer
344 **      row,col      - coordinates to get text from
345 **      length       - length of buffer
346 **      needWideChar - true if need wide characters (not multi-byte chars)
347 **
348 ** Outputs:
349 **      buffer  - pointer to buffer containing text
350 **
351 ** Returns:
352 **      the actual number of characters in the buffer
353 */
354 extern short
355 _DtTermPrimBufferGetText
356 (
357     const TermBuffer      tb,
358     const short           row,
359     const short           col,
360     const short           length,
361     char                 *buffer,
362     const Boolean         needWideChar
363 );
364
365 /*
366 ** Return a pointer to the character at the specified position.
367 **
368 ** Inputs:
369 **      tb      - term buffer
370 **      row,col - coordinates of desired character
371 **
372 ** Returns:
373 **      pointer to desired character
374 */
375 extern termChar *
376 _DtTermPrimBufferGetCharacterPointer
377 (
378     const TermBuffer  tb,
379     const short       row,
380     const short       col
381 );
382
383 /* 
384 ** Insert 'numChar' characters into the buffer at the specified position.
385 ** 
386 ** 
387 */
388 extern short
389 _DtTermPrimBufferInsert
390 (
391     const TermBuffer  tb,
392     const short       row,
393     const short       col,
394     const termChar   *newChars,
395           short       numChars,
396           Boolean     insertFlag,   /* if TRUE, insert, else overwrite        */
397           termChar  **returnChars,  /* pointer to overflow buffer             */
398           short      *returnCount   /* count of characters in overflow buffer */
399 );
400
401 /* 
402 ** Delete enough characters from the buffer to exceed width.
403 **
404 ** If returnChars != NULL then the deleted characters are returned
405 ** in a buffer pointed to by returnChars.  It is the responsibility
406 ** of the calling function to XtFree the buffer containing returned
407 ** characters when they are no longer needed.
408 */
409 extern void
410 _DtTermPrimBufferDelete
411 (
412     TermBuffer  tb,
413     short      *row,
414     short      *col,
415     short      *count,
416     termChar  **returnChars,  /* pointer to delete buffer        */
417     short      *returnCount   /* count of bytes in delete buffer */
418 );
419
420 extern void
421 _DtTermPrimBufferDeleteWc
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 Boolean
432 _DtTermPrimBufferSetLineWidth
433 (
434     const TermBuffer      tb,
435     const short           row,
436           short           newWidth
437 );
438
439 extern short
440 _DtTermPrimBufferGetLineLength
441 (
442     const TermBuffer      tb,
443     const short           row
444 );
445
446 extern short
447 _DtTermPrimBufferGetLineWidth
448 (
449     const TermBuffer      tb,
450     const short           row
451 );
452
453 extern int
454 _DtTermPrimBufferSetEnhancement
455 (
456     const TermBuffer      tb,
457     const short           row,
458     const short           col,
459     const unsigned char   id,
460     const enhValue        value
461 );
462
463 extern Boolean
464 _DtTermPrimBufferGetEnhancement
465 (
466     const TermBuffer      tb,
467     const short           row,
468     const short           col,
469           enhValue      **values,
470           short          *count,
471     const countSpec       countWhich
472 );
473
474 /*
475 ** Return the number of rows allocated to the term buffer.
476 */
477 extern short
478 _DtTermPrimBufferGetRows
479 (
480     const TermBuffer      tb
481 );
482
483 /*
484 ** Return the number of columns allocated to the term buffer.
485 */
486 extern short
487 _DtTermPrimBufferGetCols
488 (
489     const TermBuffer    tb
490 );
491
492 /*
493 ** Set the value of the term buffer's nextBuffer and prevBuffer pointers.
494 */
495 extern void
496 _DtTermPrimBufferSetLinks
497 (
498     const TermBuffer    tb,
499     const TermBuffer    prev,
500     const TermBuffer    next
501 );
502
503 /*
504 ** Set the value of the term buffer's selectInfo pointer.
505 */
506 extern void
507 _DtTermPrimBufferSetSelectInfo
508 (
509     const TermBuffer        tb,
510     const TermSelectInfo    si
511 );
512
513 extern void
514 _DtTermPrimBufferMoveLockArea
515 (
516     const TermBuffer        tb,
517     const short             dest,
518     const short             src,
519     const short             length
520 );
521
522 typedef enum {
523     insertFromTop,
524     insertFromBottom
525 } InsertSource;
526
527 extern void
528 _DtTermPrimBufferInsertLine
529 (
530     const TermBuffer        tb,
531     const short             dest,
532     const short             length,
533     const short             src
534 );
535
536 extern void
537 _DtTermPrimBufferInsertLineFromTB
538 (
539     const TermBuffer        tb,
540     const short             dest,
541     const short             length,
542     const InsertSource    insertSource
543 );
544
545 extern void
546 _DtTermPrimBufferDeleteLine
547 (
548     const TermBuffer        tb,
549     const short             source,
550     const short             length,
551     const short             lastUsedRow
552 );
553
554 extern void
555 _DtTermPrimBufferPadLine
556 (
557     const TermBuffer  tb,
558     const short       row,
559     const short       newWidth
560 );
561
562 extern void
563 _DtTermPrimBufferPadLineWc
564 (
565     const TermBuffer  tb,
566     const short       row,
567     const short       newWidth
568 );
569
570 extern Boolean
571 _DtTermPrimGetCharacterInfo
572 (
573     TermBuffer      tb,
574     short           row,
575     short           col,
576     TermCharInfo    charInfo
577 );
578
579 extern short
580 _DtTermPrimBufferGetNextTab
581 (
582     const TermBuffer    tb,
583           short         col
584 );
585
586 extern short
587 _DtTermPrimBufferGetPreviousTab
588 (
589     const TermBuffer    tb,
590           short         col
591 );
592
593 extern Boolean
594 _DtTermPrimBufferSetTab
595 (
596     const TermBuffer    tb,
597     const short         col
598 );
599
600 extern Boolean
601 _DtTermPrimBufferClearTab
602 (
603     const TermBuffer    tb,
604     const short         col
605 );
606
607 extern Boolean
608 _DtTermPrimBufferClearAllTabs
609 (
610     const TermBuffer    tb
611 );
612
613 /*
614 ** Return the value of the line wrap flag for the current line
615 */
616 extern Boolean
617 _DtTermPrimBufferTestLineWrapFlag
618 (
619     TermBuffer  tb,
620     short       row
621 );
622
623 /*
624 ** set the line wrap flag to the desired state
625 */
626 void
627 _DtTermPrimBufferSetLineWrapFlag
628 (
629     TermBuffer  tb,
630     short       row,
631     Boolean     state
632 );
633
634 /*
635 ** Return the value of the in selection flag for the current line
636 */
637 extern TermLineSelection
638 _DtTermPrimBufferGetInSelectionFlag
639 (
640     TermBuffer  tb,
641     short       row
642 );
643
644 /*
645 ** set the in selection flag to the desired state
646 */
647 void
648 _DtTermPrimBufferSetInSelectionFlag
649 (
650     TermBuffer  tb,
651     short       row,
652     TermLineSelection     state
653 );
654
655 extern void
656 _DtTermPrimBufferSetSelectLines
657 (
658     TermBuffer tb,
659     short beginRow,
660     short beginCol,
661     short endRow,
662     short endCol
663 );
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... */