ui/motif/text.c

changeset 12
fe94e0fb9ef3
parent 9
e70e855cea89
child 22
bcf880b29bc3
equal deleted inserted replaced
11:979c0e0ee853 12:fe94e0fb9ef3
46 Widget text_area = XmCreateScrolledText(parent, "text_area", args, n); 46 Widget text_area = XmCreateScrolledText(parent, "text_area", args, n);
47 XtManageChild(text_area); 47 XtManageChild(text_area);
48 48
49 // bind value 49 // bind value
50 if(value) { 50 if(value) {
51 value->set = ui_textarea_set;
51 value->get = ui_textarea_get; 52 value->get = ui_textarea_get;
52 value->set = ui_textarea_set; 53 value->getsubstr = ui_textarea_getsubstr;
54 value->insert = ui_textarea_insert;
53 value->value = NULL; 55 value->value = NULL;
54 value->obj = text_area; 56 value->obj = text_area;
55 57
56 if(!value->undomgr) { 58 if(!value->undomgr) {
57 value->undomgr = ui_create_undomgr(); 59 value->undomgr = ui_create_undomgr();
77 } 79 }
78 80
79 void ui_textarea_set(UiText *text, char *str) { 81 void ui_textarea_set(UiText *text, char *str) {
80 if(text->value) { 82 if(text->value) {
81 XtFree(text->value); 83 XtFree(text->value);
82 text->value = NULL;
83 } 84 }
84 text->value = NULL; 85 text->value = NULL;
85 XmTextSetString(text->obj, str); 86 XmTextSetString(text->obj, str);
87 }
88
89 char* ui_textarea_getsubstr(UiText *text, int begin, int end) {
90 if(text->value) {
91 XtFree(text->value);
92 }
93 int length = end - begin;
94 char *str = XtMalloc(length + 1);
95 XmTextGetSubstring(text->obj, begin, length, length + 1, str);
96 text->value = str;
97 return str;
98 }
99
100 void ui_textarea_insert(UiText *text, int pos, char *str) {
101 if(text->value) {
102 XtFree(text->value);
103 }
104 text->value = NULL;
105 XmTextInsert(text->obj, pos, str);
86 } 106 }
87 107
88 UiUndoMgr* ui_create_undomgr() { 108 UiUndoMgr* ui_create_undomgr() {
89 UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr)); 109 UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr));
90 mgr->begin = NULL; 110 mgr->begin = NULL;

mercurial