29 #ifndef TEXT_H |
29 #ifndef TEXT_H |
30 #define TEXT_H |
30 #define TEXT_H |
31 |
31 |
32 #include "../ui/text.h" |
32 #include "../ui/text.h" |
33 #include "toolkit.h" |
33 #include "toolkit.h" |
34 #include <ucx/list.h> |
34 #include <cx/linked_list.h> |
35 #include "../common/context.h" |
35 #include "../common/context.h" |
36 |
36 |
37 #ifdef __cplusplus |
37 #ifdef __cplusplus |
38 extern "C" { |
38 extern "C" { |
39 #endif |
39 #endif |
40 |
40 |
41 #define UI_TEXTBUF_INSERT 0 |
41 #define UI_TEXTBUF_INSERT 0 |
42 #define UI_TEXTBUF_DELETE 1 |
42 #define UI_TEXTBUF_DELETE 1 |
43 typedef struct UiTextBufOp { |
43 |
|
44 typedef struct UiTextBufOp UiTextBufOp; |
|
45 struct UiTextBufOp { |
|
46 UiTextBufOp *prev; |
|
47 UiTextBufOp *next; |
44 int type; // UI_TEXTBUF_INSERT, UI_TEXTBUF_DELETE |
48 int type; // UI_TEXTBUF_INSERT, UI_TEXTBUF_DELETE |
45 int start; |
49 int start; |
46 int end; |
50 int end; |
47 int len; |
51 int len; |
48 char *text; |
52 char *text; |
49 } UiTextBufOp; |
53 }; |
50 |
54 |
51 typedef struct UiUndoMgr { |
55 typedef struct UiUndoMgr { |
52 UcxList *begin; |
56 UiTextBufOp *begin; |
53 UcxList *cur; |
57 UiTextBufOp *end; |
54 int length; |
58 UiTextBufOp *cur; |
55 int event; |
59 int length; |
|
60 int event; |
56 } UiUndoMgr; |
61 } UiUndoMgr; |
57 |
62 |
58 typedef struct UiTextArea { |
63 typedef struct UiTextArea { |
59 UiContext *ctx; |
64 UiObject *obj; |
60 UiVar *var; |
65 UiContext *ctx; |
61 int last_selection_state; |
66 UiVar *var; |
|
67 int last_selection_state; |
|
68 ui_callback onchange; |
|
69 void *onchangedata; |
62 } UiTextArea; |
70 } UiTextArea; |
63 |
71 |
64 typedef struct UiTextField { |
72 typedef struct UiTextField { |
65 UiContext *ctx; |
73 UiObject *obj; |
66 UiVar *var; |
74 UiVar *var; |
67 // TODO: validatefunc |
75 ui_callback onchange; |
|
76 void *onchangedata; |
|
77 ui_callback onactivate; |
|
78 void *onactivatedata; |
68 } UiTextField; |
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; |
69 |
110 |
70 UIWIDGET ui_textarea_var(UiObject *obj, UiVar *var); |
111 UIWIDGET ui_textarea_var(UiObject *obj, UiVar *var); |
71 void ui_textarea_destroy(GtkWidget *object, UiTextArea *textarea); |
112 void ui_textarea_destroy(GtkWidget *object, UiTextArea *textarea); |
72 |
113 |
73 char* ui_textarea_get(UiText *text); |
114 char* ui_textarea_get(UiText *text); |
74 void ui_textarea_set(UiText *text, char *str); |
115 void ui_textarea_set(UiText *text, const char *str); |
75 char* ui_textarea_getsubstr(UiText *text, int begin, int end); |
116 char* ui_textarea_getsubstr(UiText *text, int begin, int end); |
76 void ui_textarea_insert(UiText *text, int pos, char *str); |
117 void ui_textarea_insert(UiText *text, int pos, char *str); |
77 void ui_textarea_setposition(UiText *text, int pos); |
118 void ui_textarea_setposition(UiText *text, int pos); |
78 int ui_textarea_position(UiText *text); |
119 int ui_textarea_position(UiText *text); |
79 void ui_textarea_selection(UiText *text, int *begin, int *end); |
120 void ui_textarea_selection(UiText *text, int *begin, int *end); |
93 GtkTextBuffer *textbuffer, |
134 GtkTextBuffer *textbuffer, |
94 GtkTextIter *start, |
135 GtkTextIter *start, |
95 GtkTextIter *end, |
136 GtkTextIter *end, |
96 void *data); |
137 void *data); |
97 UiUndoMgr* ui_create_undomgr(); |
138 UiUndoMgr* ui_create_undomgr(); |
|
139 void ui_destroy_undomgr(UiUndoMgr *mgr); |
98 void ui_free_textbuf_op(UiTextBufOp *op); |
140 void ui_free_textbuf_op(UiTextBufOp *op); |
99 int ui_check_insertstr(char *oldstr, int oldlen, char *newstr, int newlen); |
141 int ui_check_insertstr(char *oldstr, int oldlen, char *newstr, int newlen); |
100 |
142 |
101 void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield); |
143 void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield); |
102 void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield); |
144 void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield); |
|
145 void ui_textfield_activate(GtkEntry* self, UiTextField *textfield); |
103 |
146 |
104 char* ui_textfield_get(UiString *str); |
147 char* ui_textfield_get(UiString *str); |
105 void ui_textfield_set(UiString *str, char *value); |
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); |
106 |
154 |
107 #ifdef __cplusplus |
155 #ifdef __cplusplus |
108 } |
156 } |
109 #endif |
157 #endif |
110 |
158 |