1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef TEXT_H
30 #define TEXT_H
31
32 #include "../ui/text.h"
33 #include "toolkit.h"
34 #include <cx/linked_list.h>
35 #include "../common/context.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #define UI_TEXTBUF_INSERT 0
42 #define UI_TEXTBUF_DELETE 1
43
44 typedef struct UiTextBufOp UiTextBufOp;
45 struct UiTextBufOp {
46 UiTextBufOp *prev;
47 UiTextBufOp *next;
48 int type;
49 int start;
50 int end;
51 int len;
52 char *text;
53 };
54
55 typedef struct UiUndoMgr {
56 UiTextBufOp *begin;
57 UiTextBufOp *end;
58 UiTextBufOp *cur;
59 int length;
60 int event;
61 } UiUndoMgr;
62
63 typedef struct UiTextArea {
64 UiObject *obj;
65 UiContext *ctx;
66 UiVar *var;
67 int last_selection_state;
68 ui_callback onchange;
69 void *onchangedata;
70 } UiTextArea;
71
72 typedef struct UiTextField {
73 UiObject *obj;
74 UiVar *var;
75 ui_callback onchange;
76 void *onchangedata;
77 ui_callback onactivate;
78 void *onactivatedata;
79 } UiTextField;
80
81 typedef struct UiPathTextField {
82 UiObject *obj;
83
84 GtkWidget *stack;
85 GtkWidget *hbox;
86 GtkWidget *entry_box;
87 GtkWidget *entry;
88 #if GTK_MAJOR_VERSION ==
3
89 GtkWidget *buttonbox;
90 #endif
91
92 char *current_path;
93 UiPathElm *current_pathelms;
94 GtkWidget **current_path_buttons;
95 size_t current_nelm;
96
97 ui_pathelm_func getpathelm;
98 void* getpathelmdata;
99
100 ui_callback onactivate;
101 void* onactivatedata;
102
103 ui_callback ondragstart;
104 void* ondragstartdata;
105 ui_callback ondragcomplete;
106 void* ondragcompletedata;
107 ui_callback ondrop;
108 void* ondropdata;
109 } UiPathTextField;
110
111 UIWIDGET ui_textarea_var(UiObject *obj, UiVar *var);
112 void ui_textarea_destroy(GtkWidget *object, UiTextArea *textarea);
113
114 char* ui_textarea_get(UiText *text);
115 void ui_textarea_set(UiText *text,
const char *str);
116 char* ui_textarea_getsubstr(UiText *text,
int begin,
int end);
117 void ui_textarea_insert(UiText *text,
int pos,
char *str);
118 void ui_textarea_setposition(UiText *text,
int pos);
119 int ui_textarea_position(UiText *text);
120 void ui_textarea_selection(UiText *text,
int *begin,
int *end);
121 int ui_textarea_length(UiText *text);
122 void ui_textarea_remove(UiText *text,
int begin,
int end);
123
124 void ui_textarea_realize_event(GtkWidget *widget, gpointer data);
125 void ui_textbuf_changed(GtkTextBuffer *textbuffer, UiTextArea *textarea);
126
127 void ui_textbuf_insert(
128 GtkTextBuffer *textbuffer,
129 GtkTextIter *location,
130 char *text,
131 int len,
132 void *data);
133 void ui_textbuf_delete(
134 GtkTextBuffer *textbuffer,
135 GtkTextIter *start,
136 GtkTextIter *end,
137 void *data);
138 UiUndoMgr* ui_create_undomgr();
139 void ui_destroy_undomgr(UiUndoMgr *mgr);
140 void ui_free_textbuf_op(UiTextBufOp *op);
141 int ui_check_insertstr(
char *oldstr,
int oldlen,
char *newstr,
int newlen);
142
143 void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield);
144 void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield);
145 void ui_textfield_activate(GtkEntry* self, UiTextField *textfield);
146
147 char* ui_textfield_get(UiString *str);
148 void ui_textfield_set(UiString *str,
const char *value);
149
150 int ui_pathtextfield_update(UiPathTextField* pathtf,
const char *full_path);
151 int ui_pathtextfield_update_widget(UiPathTextField* pathtf);
152 char* ui_path_textfield_get(UiString *str);
153 void ui_path_textfield_set(UiString *str,
const char *value);
154
155 #ifdef __cplusplus
156 }
157 #endif
158
159 #endif
160
161