| 164 // bind the listview to the provided UiList |
164 // bind the listview to the provided UiList |
| 165 if (listview->var) { |
165 if (listview->var) { |
| 166 UiList *list = listview->var->value; |
166 UiList *list = listview->var->value; |
| 167 list->obj = listview; |
167 list->obj = listview; |
| 168 list->update = ui_listview_update; |
168 list->update = ui_listview_update; |
| 169 list->getselection = ui_listview_getselection; |
169 list->getselection = ui_listview_getselection_impl; |
| 170 list->setselection = ui_listview_setselection; |
170 list->setselection = ui_listview_setselection_impl; |
| 171 |
171 |
| 172 ui_listview_update(list, -1); |
172 ui_listview_update(list, -1); |
| 173 } else if (!table && args->static_elements && args->static_nelm > 0) { |
173 } else if (!table && args->static_elements && args->static_nelm > 0) { |
| 174 char **static_elements = args->static_elements; |
174 char **static_elements = args->static_elements; |
| 175 size_t static_nelm = args->static_nelm; |
175 size_t static_nelm = args->static_nelm; |
| 186 } |
186 } |
| 187 |
187 |
| 188 return (W32Widget*)listview; |
188 return (W32Widget*)listview; |
| 189 } |
189 } |
| 190 |
190 |
| 191 static UiListSelection listview_get_selection(UiListView *listview) { |
191 static UiListSelection listview_get_selection2(HWND hwnd) { |
| 192 UiListSelection sel = { 0, NULL }; |
192 UiListSelection sel = { 0, NULL }; |
| 193 HWND hwnd = listview->widget.hwnd; |
|
| 194 |
193 |
| 195 CX_ARRAY_DECLARE(int, indices); |
194 CX_ARRAY_DECLARE(int, indices); |
| 196 cx_array_initialize(indices, 8); |
195 cx_array_initialize(indices, 8); |
| 197 |
196 |
| 198 int index = -1; |
197 int index = -1; |
| 204 sel.rows = indices; |
203 sel.rows = indices; |
| 205 sel.count = indices_size; |
204 sel.count = indices_size; |
| 206 } |
205 } |
| 207 |
206 |
| 208 return sel; |
207 return sel; |
| |
208 } |
| |
209 |
| |
210 static UiListSelection listview_get_selection(UiListView *listview) { |
| |
211 HWND hwnd = listview->widget.hwnd; |
| |
212 return listview_get_selection2(hwnd); |
| 209 } |
213 } |
| 210 |
214 |
| 211 // listview class event proc |
215 // listview class event proc |
| 212 int ui_listview_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { |
216 int ui_listview_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { |
| 213 UiListView *listview = (UiListView*)widget; |
217 UiListView *listview = (UiListView*)widget; |
| 338 for (int i=0;i<model->columns;i++) { |
342 for (int i=0;i<model->columns;i++) { |
| 339 ListView_SetColumnWidth(hwnd, i, LVSCW_AUTOSIZE); |
343 ListView_SetColumnWidth(hwnd, i, LVSCW_AUTOSIZE); |
| 340 } |
344 } |
| 341 } |
345 } |
| 342 |
346 |
| 343 UiListSelection ui_listview_getselection(UiList *list) { |
347 UiListSelection ui_listview_getselection_impl(UiList *list) { |
| 344 UiListView *listview = (UiListView*)list->obj; |
348 UiListView *listview = (UiListView*)list->obj; |
| 345 return listview_get_selection(listview); |
349 return listview_get_selection(listview); |
| 346 } |
350 } |
| 347 |
351 |
| 348 void ui_listview_setselection(UiList *list, UiListSelection selection) { |
352 void ui_listview_setselection_impl(UiList *list, UiListSelection selection) { |
| 349 |
353 |
| 350 } |
354 } |
| 351 |
355 |
| 352 // public API |
356 // public API |
| 353 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) { |
357 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) { |
| 357 // public API |
361 // public API |
| 358 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) { |
362 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) { |
| 359 return listview_create(obj, args, TRUE); |
363 return listview_create(obj, args, TRUE); |
| 360 } |
364 } |
| 361 |
365 |
| |
366 void ui_listview_select(UIWIDGET listview, int index) { |
| |
367 |
| |
368 } |
| |
369 |
| |
370 int ui_listview_selection(UIWIDGET listview) { |
| |
371 W32Widget *w = (W32Widget*)listview; |
| |
372 UiListSelection sel = listview_get_selection2(w->hwnd); |
| |
373 int index = -1; |
| |
374 if (sel.count > 0) { |
| |
375 index = sel.rows[0]; |
| |
376 } |
| |
377 free(sel.rows); |
| |
378 return index; |
| |
379 } |
| 362 |
380 |
| 363 /* ------------------------------------ DropDown ------------------------------------*/ |
381 /* ------------------------------------ DropDown ------------------------------------*/ |
| 364 |
382 |
| 365 static W32WidgetClass dropdown_widget_class = { |
383 static W32WidgetClass dropdown_widget_class = { |
| 366 .eventproc = ui_dropdown_eventproc, |
384 .eventproc = ui_dropdown_eventproc, |
| 394 // bind the dropdown to the provided UiList |
412 // bind the dropdown to the provided UiList |
| 395 if (dropdown->var) { |
413 if (dropdown->var) { |
| 396 UiList *list = dropdown->var->value; |
414 UiList *list = dropdown->var->value; |
| 397 list->obj = dropdown; |
415 list->obj = dropdown; |
| 398 list->update = ui_dropdown_update; |
416 list->update = ui_dropdown_update; |
| 399 list->getselection = ui_dropdown_getselection; |
417 list->getselection = ui_dropdown_getselection_impl; |
| 400 list->setselection = ui_dropdown_setselection; |
418 list->setselection = ui_dropdown_setselection_impl; |
| 401 |
419 |
| 402 ui_dropdown_update(list, -1); |
420 ui_dropdown_update(list, -1); |
| 403 } else if (args->static_elements && args->static_nelm > 0) { |
421 } else if (args->static_elements && args->static_nelm > 0) { |
| 404 char **static_elements = args->static_elements; |
422 char **static_elements = args->static_elements; |
| 405 size_t static_nelm = args->static_nelm; |
423 size_t static_nelm = args->static_nelm; |
| 455 void *elm = list->get(list, row); |
473 void *elm = list->get(list, row); |
| 456 dropdown_insert_item(list, row, elm); |
474 dropdown_insert_item(list, row, elm); |
| 457 } |
475 } |
| 458 } |
476 } |
| 459 |
477 |
| 460 UiListSelection ui_dropdown_getselection(UiList *list) { |
478 UiListSelection ui_dropdown_getselection_impl(UiList *list) { |
| 461 UiListSelection sel = { 0, NULL }; |
479 UiListSelection sel = { 0, NULL }; |
| 462 UiListView *listview = (UiListView*)list->obj; |
480 UiListView *listview = (UiListView*)list->obj; |
| 463 int index = (int)SendMessage(listview->widget.hwnd, CB_GETCURSEL, 0, 0); |
481 int index = (int)SendMessage(listview->widget.hwnd, CB_GETCURSEL, 0, 0); |
| 464 if (index >= 0) { |
482 if (index >= 0) { |
| 465 sel.rows = malloc(sizeof(int)); |
483 sel.rows = malloc(sizeof(int)); |
| 467 sel.count = 1; |
485 sel.count = 1; |
| 468 } |
486 } |
| 469 return sel; |
487 return sel; |
| 470 } |
488 } |
| 471 |
489 |
| 472 void ui_dropdown_setselection(UiList *list, UiListSelection selection) { |
490 void ui_dropdown_setselection_impl(UiList *list, UiListSelection selection) { |
| 473 UiListView *listview = (UiListView*)list->obj; |
491 UiListView *listview = (UiListView*)list->obj; |
| 474 SendMessage(listview->widget.hwnd, CB_SETCURSEL, 0, 0); |
492 SendMessage(listview->widget.hwnd, CB_SETCURSEL, 0, 0); |
| 475 } |
493 } |
| |
494 |
| |
495 void ui_dropdown_select(UIWIDGET dropdown, int index) { |
| |
496 SendMessage(dropdown->hwnd, CB_SETCURSEL, 0, 0); |
| |
497 } |
| |
498 |
| |
499 int ui_dropdown_selection(UIWIDGET dropdown) { |
| |
500 return SendMessage(dropdown->hwnd, CB_GETCURSEL, 0, 0); |
| |
501 } |