convert line ends
[canaan.git] / prj / tech / libsrc / gadget / uitexted.h
blob3fef17d32b1f652a0de5c41597a78e0ca527ae8c
1 #ifndef __UITEXTED_H
2 #define __UITEXTED_H
3 /*
4 * $Source: x:/prj/tech/libsrc/gadget/RCS/uitexted.h $
5 * $Revision: 1.5 $
6 * $Author: JAEMZ $
7 * $Date: 1998/01/12 12:41:29 $
9 */
11 #include <gadget.h>
12 #include <uibutton.h>
13 #include <region.h>
14 #include <event.h>
16 struct _TextGadg;
17 //**************************************
18 // UI TEXT EDITOR GADGET
19 // MAHK 1/95
20 // TO GO INTO THE UI LIBRARY SOME DAY
21 // ------------------------------------
22 // This text editor gadget provides support for
23 // automatically displaying and editing text in a region.
25 // Every text editor lives in its own region. The text editor
26 // dispatches USER_DEFINED gadget events to the region under certain
27 // circumstances. The events have the following format.
30 struct _TextGadgEvent;
31 typedef struct _TextGadgEvent
33 UIEVFRONT
34 ushort signaller; // ignore if not equal to TEXTED_SIGNALLER
35 ushort action; // defined below
36 ushort data; // action-specific data
37 UIEVBACK(2*sizeof(short));
38 } TextGadgEvent;
40 // Text gadget actions
41 #define TEXTGADG_SPECKEY 0 // A special key was pressed, "data" field contains cooked keycode
42 #define TEXTGADG_SELECT 1 // Text was "selected" (Not yet supported)
43 #define TEXTGADG_BUTTON 2 // button events
44 #define TEXTGADG_SPECKEY_PRE 3 // A special key was pressed before the parsing
47 //------------------------------------------------------------
48 // Text Editor Gadget Structure
51 struct _buffer
53 char* buf;
54 int len;
57 typedef struct _TextGadg
59 ButtonGadg butt; // gadget's box
60 short edit; // edit flags
61 ulong flags; // special flags, see below.
62 struct _buffer text; // text being displayed/edited
63 int cursor; // character index of "cursor"
64 int last_char; // character index of last char in buffer
65 int rep_count; // current editor repeat count
66 bool at_end; // are we out of space?
67 short* speckeys; // special keys
68 } TextGadg;
70 // -----
71 // Flags
72 // -----
74 #define TEXTGADG_BORDER_FLAG 0x0002 // should there be a border?
75 #define TEXTGADG_FOCUS_FLAG 0x0004 // should the gadget grab focus on click?
76 #define TEXTGADG_MOUSE_DOWNS 0x0008 // should we send mouse downs
77 #define TEXTGADG_PRESCREEN_FLAG 0x0010 // Prescreen the events
79 #define TEXTGADG_ALIGN_MASK 0xF000 // text alignment
80 #define TEXTGADG_ALIGN_LEFT 0x1000 // left alignment
81 #define TEXTGADG_ALIGN_RIGHT 0x2000 // right alignment
82 #define TEXTGADG_ALIGN_TOP 0x4000 // top alignment
83 #define TEXTGADG_ALIGN_BOTTOM 0x8000 // bottom alignment
85 #define TEXTGADG_EDIT_EDITABLE 0x0001 // can you edit things
86 #define TEXTGADG_EDIT_OVERMODE 0x0002 // are we in insert mode
87 #define TEXTGADG_EDIT_BRANDNEW 0x0004 // most keystrokes wipe initial text
88 #define TEXTGADG_EDIT_NOSPACES 0x0008 // prohibit whitespace?
91 #define tgadg_edit_flg(t,flg) (t->edit&TEXTGADG_EDIT_##flg##)
93 //----------
94 // Accessors
95 //----------
97 #define TextGadgRegion(pgadg) (VB(pgadg)->r)
98 #define TextGadgEditing(pgadg) ((pgadg)->edit)
99 #define TextGadgText(pgadg) ((pgadg)->text.buf)
100 #define TextGadgTextLen(pgadg) ((pgadg)->text.len)
101 #define TextGadgCursor(pgadg) ((pgadg)->cursor)
102 #define TextGadgFlags(pgadg) ((pgadg)->flags)
104 #define TextGadgSetCursor(pgadg,intval) ((pgadg)->cursor = (intval))
105 #define TextGadgSetFlag(pgadg,flg) ((pgadg)->edit |= (flg))
106 #define TextGadgClrFlag(pgadg,flg) ((pgadg)->edit &= ~(flg))
108 // Set the list of cooked keycodes that generate "special key" events.
109 // Must be a null terminated array of keycodes
111 #define TextGadgSetSpecialKeys(pgadg,keys) ((pgadg)->speckeys = (keys))
113 //-----------------------------------------------------
114 // TextGadgInit()
116 // Initializes a text gadget
117 // parent: gadget's parent region
118 // gadg: gadget to be initialized
119 // area: coordinates of gadget's bounding rectangle
120 // z: gadget's region z coordinate
121 // buf: buffer containing initial value of string to be edited.
122 // buflen: size of buf's memory
123 // flags: flags, as defined above
125 EXTERN errtype TextGadgInit(Region* parent, TextGadg* gadg, Rect* area, int z, char* buf, int buflen, ulong flags);
127 //-----------------------------------------------------
128 // TextGadgDestroy()
130 // invalidates a text gadget, performing any necessary shutdown.
132 EXTERN errtype TextGadgDestroy(TextGadg* gadg);
134 // notify textgadg that you've changed it's text.
136 EXTERN errtype TextGadgUpdate(TextGadg* gadg);
138 // grab focus with a textgadg, unfocusing all others
140 EXTERN errtype TextGadgFocus(TextGadg* gadg);
142 EXTERN errtype TextGadgUnfocus(TextGadg* gadg);
145 #endif // __UITEXTED_H