158 e.document = event->event.obj->ctx->document; |
158 e.document = event->event.obj->ctx->document; |
159 e.eventdata = event->list->list->get(event->list->list, cbs->item_position - 1); |
159 e.eventdata = event->list->list->get(event->list->list, cbs->item_position - 1); |
160 e.intval = cbs->item_position - 1; |
160 e.intval = cbs->item_position - 1; |
161 event->event.callback(&e, event->event.userdata); |
161 event->event.callback(&e, event->event.userdata); |
162 } |
162 } |
|
163 |
|
164 |
|
165 /* --------------------------- ComboBox --------------------------- */ |
|
166 |
|
167 UIWIDGET ui_combobox_str(UiObject *obj, UiList *list, ui_callback f, void *udata) { |
|
168 return ui_combobox(obj, list, ui_strmodel_getvalue, f, udata); |
|
169 } |
|
170 |
|
171 UIWIDGET ui_combobox(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { |
|
172 UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr)); |
|
173 listptr->list = list; |
|
174 return ui_combobox_var(obj, listptr, getvalue, f, udata); |
|
175 } |
|
176 |
|
177 UIWIDGET ui_combobox_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { |
|
178 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST); |
|
179 if(var) { |
|
180 UiListVar *value = var->value; |
|
181 return ui_combobox_var(obj, value->listptr, getvalue, f, udata); |
|
182 } else { |
|
183 // TODO: error |
|
184 } |
|
185 return NULL; |
|
186 } |
|
187 |
|
188 UIWIDGET ui_combobox_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) { |
|
189 UiListView *listview = ucx_mempool_malloc( |
|
190 obj->ctx->mempool, |
|
191 sizeof(UiListView)); |
|
192 |
|
193 UiContainer *ct = uic_get_current_container(obj); |
|
194 Arg args[16]; |
|
195 int n = 0; |
|
196 XtSetArg(args[n], XmNindicatorOn, XmINDICATOR_NONE); |
|
197 n++; |
|
198 XtSetArg(args[n], XmNtraversalOn, FALSE); |
|
199 n++; |
|
200 XtSetArg(args[n], XmNwidth, 160); |
|
201 n++; |
|
202 Widget parent = ct->prepare(ct, args, &n, FALSE); |
|
203 Widget combobox = XmCreateDropDownList(parent, "combobox", args, n); |
|
204 XtManageChild(combobox); |
|
205 listview->widget = combobox; |
|
206 listview->list = list; |
|
207 listview->getvalue = getvalue; |
|
208 |
|
209 ui_listview_update(NULL, listview); |
|
210 |
|
211 list->list->observers = ui_add_observer( |
|
212 list->list->observers, |
|
213 (ui_callback)ui_listview_update, |
|
214 listview); |
|
215 |
|
216 } |