X11 Work Bench Toolkit  1.0
text_object.h
Go to the documentation of this file.
1 
2 // //
3 // _ _ _ _ _ _ //
4 // | |_ ___ __ __| |_ ___ | |__ (_) ___ ___ | |_ | |__ //
5 // | __|/ _ \\ \/ /| __| / _ \ | '_ \ | | / _ \ / __|| __| | '_ \ //
6 // | |_| __/ > < | |_ | (_) || |_) || || __/| (__ | |_ _ | | | | //
7 // \__|\___|/_/\_\ \__|_____\___/ |_.__/_/ | \___| \___| \__|(_)|_| |_| //
8 // |_____| |__/ //
9 // //
10 // //
12 
13 /*****************************************************************************
14 
15  X11workbench - X11 programmer's 'work bench' application and toolkit
16  Copyright (c) 2010-2016 by Bob Frazier (aka 'Big Bad Bombastic Bob')
17  all rights reserved
18 
19  DISCLAIMER: The X11workbench application and toolkit software are supplied
20  'as-is', with no warranties, either implied or explicit.
21  Any claims to alleged functionality or features should be
22  considered 'preliminary', and might not function as advertised.
23 
24  BSD-like license:
25 
26  There is no restriction as to what you can do with this software, so long
27  as you include the above copyright notice and DISCLAIMER for any distributed
28  work that is equal to or derived from this one, along with this paragraph
29  that explains the terms of the license if the source is also being made
30  available. A "derived work" describes a work that uses a significant portion
31  of the source files or algorithms that are included with this one.
32  Specifically excluded from this are files that were generated by the software,
33  or anything that is included with the software that is part of another package
34  (such as files that were created or added during the 'configure' process).
35  Specifically included is the use of part or all of any of the X11 workbench
36  toolkit source or header files in your distributed application. If you do not
37  ship the source, the above copyright statement is still required to be placed
38  in a reasonably prominent place, such as documentation, splash screens, and/or
39  'about the application' dialog boxes.
40 
41  Use and distribution are in accordance with GPL, LGPL, and/or the above
42  BSD-like license. See COPYING and README files for more information.
43 
44 
45  Additional information at http://sourceforge.net/projects/X11workbench
46 
47 ******************************************************************************/
48 
49 
56 #ifndef _TEXT_OBJECT_H_INCLUDED_
57 #define _TEXT_OBJECT_H_INCLUDED_
58 
59 #include "window_helper.h"
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif // __cplusplus
64 
65 
66 // FILE TYPE CONSTANTS
67 
72 {
73  FileType_MAKEFILE = -1,
74  FileType_PLAIN_TEXT = 0,
75  FileType_CLANG = 1,
76  FileType_JAVA = 2, // sample
77  FileType_PERL = 3, // sample
78  FileType_PHP = 4, // sample
79  FileType_SHELL = 5, // sample
80 
81  FileType_MASK = 0x7fff,
82 
83  // and now the bit flags
84  FileType_HARDTAB = 0x10000,
85  FileType_RESERVED2 = 0x20000,
86  FileType_RESERVED3 = 0x40000,
87  FileType_RESERVED4 = 0x80000
88 };
89 
94 {
102 };
103 
108 {
113 };
114 
119 {
123 };
124 
129 {
133 };
134 
137 #define HARD_TAB_CHAR '\xa0'
141 #define DEFAULT_TAB_WIDTH 8
145 #define AUTO_HSCROLL_SIZE 8
149 #define MIN_LINE_SPACING 2
153 #define MIN_BORDER_SPACING 2
156 // define the interface for the object
157 
158 struct _text_object_; // forward declaration
159 
267 typedef struct _text_object_vtable_
268 {
273  void (* destroy)(struct _text_object_ *pThis);
274 
279  void (* init)(struct _text_object_ *pThis);
280 
287  void (* highlight_colors)(struct _text_object_ *pThis, XColor clrHFG, XColor clrHBG);
288 
296  char * (* get_text)(struct _text_object_ *pThis);
297 
309  void (* set_text)(struct _text_object_ *pThis, const char *szText, unsigned long cbLen);
310 
321  int (* get_rows)(const struct _text_object_ *pThis);
322 
335  int (* get_cols)(struct _text_object_ *pThis);
336 
344  int (* get_filetype)(const struct _text_object_ *pThis);
345 
354  void (* set_filetype)(struct _text_object_ *pThis, int iLineFeed);
355 
362  int (* get_linefeed)(const struct _text_object_ *pThis);
363 
371  void (* set_linefeed)(struct _text_object_ *pThis, int iLineFeed);
372 
377  int (* get_insmode)(const struct _text_object_ *pThis);
378 
384  void (* set_insmode)(struct _text_object_ *pThis, int iInsMode);
385 
390  int (* get_selmode)(const struct _text_object_ *pThis);
391 
397  void (* set_selmode)(struct _text_object_ *pThis, int iSelMode);
398 
409  int (* get_tab)(const struct _text_object_ *pThis);
410 
422  void (* set_tab)(struct _text_object_ *pThis, int iTab);
423 
428  int (* get_scrollmode)(const struct _text_object_ *pThis);
429 
435  void (* set_scrollmode)(struct _text_object_ *pThis, int iScrollMode);
436 
442  void (* get_select)(const struct _text_object_ *pThis, WB_RECT *pRct);
443 
449  void (* set_select)(struct _text_object_ *pThis, const WB_RECT *pRct);
450 
455  int (* has_select)(const struct _text_object_ *pThis);
456 
469  char* (* get_sel_text)(const struct _text_object_ *pThis, const WB_RECT *pRct);
470 
475  int (* get_row)(const struct _text_object_ *pThis);
476 
482  void (* set_row)(struct _text_object_ *pThis, int iRow);
483 
488  int (* get_col)(const struct _text_object_ *pThis);
489 
499  void (* set_col)(struct _text_object_ *pThis, int iCol);
500 
505  void (* del_select)(struct _text_object_ *pThis);
506 
513  void (* replace_select)(struct _text_object_ *pThis, const char *szText, unsigned long cbLen);
514 
520  void (* del_chars)(struct _text_object_ *pThis, int nChar); // delete 1 or more chars, negative deletes BEFORE cursor, 0 does nothing
521 
536  void (* ins_chars)(struct _text_object_ *pThis, const char *pChar, int nChar);
537 
546  void (* indent)(struct _text_object_ *pThis, int nCol);
547 
552  int (* can_undo)(struct _text_object_ *pThis);
553 
558  void (* undo)(struct _text_object_ *pThis);
559 
564  int (* can_redo)(struct _text_object_ *pThis);
565 
570  void (* redo)(struct _text_object_ *pThis);
571 
580  void (* get_view)(const struct _text_object_ *pThis, WB_RECT *pRct);
589  void (* set_view)(struct _text_object_ *pThis, const WB_RECT *pRct);
590 
602  void (* begin_highlight)(struct _text_object_ *pThis);
612  void (* end_highlight)(struct _text_object_ *pThis);
613 
614  // mouse conversion
615 
630  void (* mouse_click)(struct _text_object_ *pThis, int iMouseXDelta, int iMouseYDelta, int iType, int iACS);
631 
640  void (* begin_mouse_drag)(struct _text_object_ *pThis);
648  void (* end_mouse_drag)(struct _text_object_ *pThis);
649 
650  // cursor motion
651 
655  void (* cursor_up)(struct _text_object_ *pThis);
656 
660  void (* cursor_down)(struct _text_object_ *pThis);
661 
665  void (* cursor_left)(struct _text_object_ *pThis);
666 
670  void (* cursor_right)(struct _text_object_ *pThis);
671 
675  void (* page_up)(struct _text_object_ *pThis);
676 
680  void (* page_down)(struct _text_object_ *pThis);
681 
685  void (* page_left)(struct _text_object_ *pThis);
686 
690  void (* page_right)(struct _text_object_ *pThis);
691 
695  void (* cursor_home)(struct _text_object_ *pThis);
696 
700  void (* cursor_end)(struct _text_object_ *pThis);
701 
705  void (* cursor_top)(struct _text_object_ *pThis);
706 
710  void (* cursor_bottom)(struct _text_object_ *pThis);
711 
712 
713  // handling expose events for the text area
714 
749  void (* do_expose)(struct _text_object_ *pThis, Display *pDisplay, Window wID,
750  GC gc, const WB_GEOM *pPaintGeom, const WB_GEOM *pViewGeom,
751  XFontSet rFontSet);
752 
761  void (* cursor_blink)(struct _text_object_ *pThis, int bHasFocus);
762 
764 
765 
766 
770 static __inline__ const TEXT_OBJECT_VTABLE *WBGetDefaultTextObjectVTable(void)
771 {
772 extern const TEXT_OBJECT_VTABLE WBDefaultTextObjectVTable;
773 
774  return &WBDefaultTextObjectVTable;
775 }
776 
777 
781 #define TEXT_OBJECT_TAG (*((const unsigned int *)"WBTX"))
782 
783 
848 typedef struct _text_object_
849 {
851 
852  unsigned int ulTag;
853  Window wIDOwner;
856 
857  XColor clrHFG;
858  XColor clrHBG;
859 
860  int iFileType;
862  int iInsMode;
863  int iSelMode;
865  int iTab;
866 
867  // cursor position
868  int iRow;
869  int iCol;
870  int iPos;
871 
872  int iCursorX;
873  int iCursorY;
875 
878 
879  int iAsc;
880  int iDesc;
882 
883  // viewport
884 
887 
888 
889  // the data
890 
891  void *pText;
892 
893  void *pUndo;
894  void *pRedo;
895 
896 } TEXT_OBJECT;
897 
905 static __inline__ int WBIsValidTextObject(const TEXT_OBJECT *pObj)
906 {
907  return pObj && pObj->ulTag == TEXT_OBJECT_TAG;
908 }
909 
922 static __inline__ void WBInitializeInPlaceTextObject(TEXT_OBJECT *pTextObject, Window wIDOwner)
923 {
924  if(pTextObject)
925  {
926  bzero(pTextObject, sizeof(*pTextObject)); // most contained things will accept 'nulling' as "unassigned"
927 
928  pTextObject->vtable = WBGetDefaultTextObjectVTable();
929  pTextObject->vtable->init(pTextObject);
930 
931  pTextObject->wIDOwner = wIDOwner;
932  }
933 }
934 
947 static __inline__ void WBDestroyInPlaceTextObject(TEXT_OBJECT *pTextObject)
948 {
949  if(pTextObject &&
950  WBIsValidTextObject(pTextObject) &&
951  pTextObject->vtable &&
952  pTextObject->vtable->destroy)
953  {
954  pTextObject->vtable->destroy(pTextObject);
955  }
956 }
957 
958 #define TEXT_BUFFER_LINE_CACHE_SIZE 32
959 
992 typedef struct _text_buffer_
993 {
994  unsigned long nArraySize;
995  unsigned long nEntries;
996 
997  // cached information
998  unsigned int nMaxCol;
999  unsigned int nMinMaxCol;
1000  unsigned long aLineCache[TEXT_BUFFER_LINE_CACHE_SIZE];
1002  unsigned int aLineCacheLen[TEXT_BUFFER_LINE_CACHE_SIZE];
1004 
1005  char * aLines[2];
1006 
1007 } TEXT_BUFFER;
1008 
1009 
1019 TEXT_BUFFER * WBAllocTextBuffer(const char *pBuf, unsigned int cbBufSize);
1020 
1030 int WBCheckReAllocTextBuffer(TEXT_BUFFER **ppBuf, int nLinesToAdd);
1031 
1040 void WBFreeTextBuffer(TEXT_BUFFER *pBuf);
1041 
1058 void WBTextBufferLineChange(TEXT_BUFFER *pBuf, unsigned long nLine, int nNewLen);
1059 
1076 
1077 
1078 
1079 
1094 TEXT_OBJECT *WBTextObjectConstructor(unsigned long cbStructSize, const char *szText, unsigned long cbLen, Window wIDOwner);
1095 
1096 
1108 
1109 
1124 int WBTextObjectCalculateLineHeight(int iAscent, int iDescent);
1125 
1126 
1127 
1128 // MBCS-related utilities
1129 
1159 char * WBInsertMBChars(char *pString, int iCol, const char *pszMBString, int cbString,
1160  int fTab, int fOverwrite, int *piNewCol, char **ppInserted);
1161 
1162 
1177 char * WBSplitMBLine(char *pString, int iCol);
1178 
1179 
1195 char * WBJoinMBLine(char *pString, int iCol, const char *pJoin);
1196 
1197 
1222 int WBDelMBChars(char *pString, int iCol, int nDel, int *piNewCol, char **ppDeleted);
1223 
1224 
1233 int WBGetMBLength(const char *pString);
1234 
1235 
1246 char * WBGetMBCharPtr(char *pString, int iCol, int *pcbLen);
1247 
1257 int WBGetMBColIndex(const char *pString, const char *pChar);
1258 
1259 
1260 #ifdef __cplusplus
1261 };
1262 #endif // __cplusplus
1263 
1264 #endif // _TEXT_OBJECT_H_INCLUDED_
1265 
1266