ui/win32/text.c

changeset 940
105bccb3dc66
parent 938
be4c88ded783
equal deleted inserted replaced
939:fdc6a46100a3 940:105bccb3dc66
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "text.h" 29 #include "text.h"
30 30
31 static W32WidgetClass textarea_widget_class = {
32 .eventproc = ui_textarea_eventproc,
33 .enable = w32_widget_default_enable,
34 .show = w32_widget_default_show,
35 .get_preferred_size = ui_textarea_get_preferred_size,
36 .destroy = w32_widget_default_destroy
37 };
38
39 UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs *args) {
40 HINSTANCE hInstance = GetModuleHandle(NULL);
41 UiContainerPrivate *container = ui_obj_container(obj);
42 HWND parent = ui_container_get_parent(container);
43 UiLayout layout = UI_ARGS2LAYOUT(args);
44
45 int width = args->width >= 0 ? args->width : 100;
46 int height = args->height >= 0 ? args->height : 100;
47
48 HWND hwnd = CreateWindowEx(
49 0,
50 "EDIT",
51 "",
52 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL,
53 0, 0, width, height,
54 parent,
55 (HMENU)0,
56 hInstance,
57 NULL);
58 ui_win32_set_ui_font(hwnd);
59
60 W32Widget *widget = w32_widget_create(&textarea_widget_class, hwnd, sizeof(UiTextArea));
61 ui_container_add(container, widget, &layout);
62
63 UiTextArea *textarea = (UiTextArea*)widget;
64 textarea->width = width;
65 textarea->widget.var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_TEXT);
66 textarea->widget.callback = args->onchange;
67 textarea->widget.callbackdata = args->onchangedata;
68
69 if (textarea->widget.var) {
70 UiText *t = textarea->widget.var->value;
71
72 if (t->value.ptr) {
73 // TODO: set textarea string
74 }
75 t->obj = widget;
76 t->save = ui_textarea_save;
77 t->destroy = ui_textarea_destroy;
78 t->restore = ui_textarea_restore;
79 t->get = ui_textarea_get;
80 t->set = ui_textarea_set;
81 t->getsubstr = ui_textarea_getsubstr;
82 t->insert = ui_textarea_insert;
83 t->setposition = ui_textarea_setposition;
84 t->position = ui_textarea_position;
85 t->setselection = ui_textarea_setselection;
86 t->selection = ui_textarea_selection;
87 t->length = ui_textarea_length;
88 t->remove = ui_textarea_remove;
89 }
90
91 return widget;
92 }
93
94 W32Size ui_textarea_get_preferred_size(W32Widget *widget) {
95 W32Size size;
96 UiTextArea *textarea = (UiTextArea*)widget;
97 size.width = textarea->width;
98 size.height = textarea->height;
99 return size;
100 }
101
102 int ui_textarea_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
103 return 0;
104 }
105
106 void ui_textarea_save(UiText *text) {
107
108 }
109
110 void ui_textarea_destroy(UiText *text) {
111
112 }
113
114 void ui_textarea_restore(UiText *text) {
115
116 }
117
118 void ui_textarea_set(UiText *text, const char *str) {
119
120 }
121
122 char* ui_textarea_get(UiText *text) {
123 return NULL;
124 }
125
126 char* ui_textarea_getsubstr(UiText *text, int begin, int end) {
127 return NULL;
128 }
129
130 void ui_textarea_insert(UiText *text, int pos, char *str) {
131
132 }
133
134 void ui_textarea_setposition(UiText *text, int pos) {
135
136 }
137
138 int ui_textarea_position(UiText *text) {
139 return 0;
140 }
141
142 void ui_textarea_setselection(UiText *text, int begin, int end) {
143
144 }
145
146 void ui_textarea_selection(UiText *text, int *begin, int *end) {
147
148 }
149
150 int ui_textarea_length(UiText *text) {
151 return 0;
152 }
153
154 void ui_textarea_remove(UiText *text, int begin, int end) {
155
156 }
157
158 /* ----------------------------- TextField ----------------------------- */
159
31 static W32WidgetClass textfield_widget_class = { 160 static W32WidgetClass textfield_widget_class = {
32 .eventproc = ui_textfield_eventproc, 161 .eventproc = ui_textfield_eventproc,
33 .enable = w32_widget_default_enable, 162 .enable = w32_widget_default_enable,
34 .show = w32_widget_default_show, 163 .show = w32_widget_default_show,
35 .get_preferred_size = ui_textfield_get_preferred_size, 164 .get_preferred_size = ui_textfield_get_preferred_size,

mercurial