| 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) { |
| |
174 char **static_elements = args->static_elements; |
| |
175 size_t static_nelm = args->static_nelm; |
| |
176 LVITEM item; |
| |
177 item.mask = LVIF_TEXT; |
| |
178 item.iSubItem = 0; |
| |
179 for (int i=0;i<static_nelm;i++) { |
| |
180 item.iItem = i; |
| |
181 item.pszText = static_elements[i]; |
| |
182 ListView_InsertItem(hwnd, &item); |
| |
183 } |
| |
184 listview->getvalue = strmodel_getvalue; |
| |
185 listview->getvaluedata = NULL; |
| 173 } |
186 } |
| 174 |
187 |
| 175 return (W32Widget*)listview; |
188 return (W32Widget*)listview; |
| 176 } |
189 } |
| 177 |
190 |
| 178 static UiListSelection listview_get_selection(UiListView *listview) { |
191 static UiListSelection listview_get_selection2(HWND hwnd) { |
| 179 UiListSelection sel = { 0, NULL }; |
192 UiListSelection sel = { 0, NULL }; |
| 180 HWND hwnd = listview->widget.hwnd; |
|
| 181 |
193 |
| 182 CX_ARRAY_DECLARE(int, indices); |
194 CX_ARRAY_DECLARE(int, indices); |
| 183 cx_array_initialize(indices, 8); |
195 cx_array_initialize(indices, 8); |
| 184 |
196 |
| 185 int index = -1; |
197 int index = -1; |
| 191 sel.rows = indices; |
203 sel.rows = indices; |
| 192 sel.count = indices_size; |
204 sel.count = indices_size; |
| 193 } |
205 } |
| 194 |
206 |
| 195 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); |
| 196 } |
213 } |
| 197 |
214 |
| 198 // listview class event proc |
215 // listview class event proc |
| 199 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) { |
| 200 UiListView *listview = (UiListView*)widget; |
217 UiListView *listview = (UiListView*)widget; |
| 325 for (int i=0;i<model->columns;i++) { |
342 for (int i=0;i<model->columns;i++) { |
| 326 ListView_SetColumnWidth(hwnd, i, LVSCW_AUTOSIZE); |
343 ListView_SetColumnWidth(hwnd, i, LVSCW_AUTOSIZE); |
| 327 } |
344 } |
| 328 } |
345 } |
| 329 |
346 |
| 330 UiListSelection ui_listview_getselection(UiList *list) { |
347 UiListSelection ui_listview_getselection_impl(UiList *list) { |
| 331 UiListView *listview = (UiListView*)list->obj; |
348 UiListView *listview = (UiListView*)list->obj; |
| 332 return listview_get_selection(listview); |
349 return listview_get_selection(listview); |
| 333 } |
350 } |
| 334 |
351 |
| 335 void ui_listview_setselection(UiList *list, UiListSelection selection) { |
352 void ui_listview_setselection_impl(UiList *list, UiListSelection selection) { |
| 336 |
353 |
| 337 } |
354 } |
| 338 |
355 |
| 339 // public API |
356 // public API |
| 340 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) { |
357 UIWIDGET ui_listview_create(UiObject *obj, UiListArgs *args) { |
| 344 // public API |
361 // public API |
| 345 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) { |
362 UIWIDGET ui_table_create(UiObject *obj, UiListArgs *args) { |
| 346 return listview_create(obj, args, TRUE); |
363 return listview_create(obj, args, TRUE); |
| 347 } |
364 } |
| 348 |
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 } |
| 349 |
380 |
| 350 /* ------------------------------------ DropDown ------------------------------------*/ |
381 /* ------------------------------------ DropDown ------------------------------------*/ |
| 351 |
382 |
| 352 static W32WidgetClass dropdown_widget_class = { |
383 static W32WidgetClass dropdown_widget_class = { |
| 353 .eventproc = ui_dropdown_eventproc, |
384 .eventproc = ui_dropdown_eventproc, |
| 381 // bind the dropdown to the provided UiList |
412 // bind the dropdown to the provided UiList |
| 382 if (dropdown->var) { |
413 if (dropdown->var) { |
| 383 UiList *list = dropdown->var->value; |
414 UiList *list = dropdown->var->value; |
| 384 list->obj = dropdown; |
415 list->obj = dropdown; |
| 385 list->update = ui_dropdown_update; |
416 list->update = ui_dropdown_update; |
| 386 list->getselection = ui_dropdown_getselection; |
417 list->getselection = ui_dropdown_getselection_impl; |
| 387 list->setselection = ui_dropdown_setselection; |
418 list->setselection = ui_dropdown_setselection_impl; |
| 388 |
419 |
| 389 ui_dropdown_update(list, -1); |
420 ui_dropdown_update(list, -1); |
| 390 } |
421 } else if (args->static_elements && args->static_nelm > 0) { |
| 391 |
422 char **static_elements = args->static_elements; |
| |
423 size_t static_nelm = args->static_nelm; |
| |
424 for (int i=0;i<static_nelm;i++) { |
| |
425 SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)static_elements[i]); |
| |
426 } |
| |
427 dropdown->getvalue = strmodel_getvalue; |
| |
428 dropdown->getvaluedata = NULL; |
| |
429 } |
| 392 |
430 |
| 393 return (W32Widget*)dropdown; |
431 return (W32Widget*)dropdown; |
| 394 } |
432 } |
| 395 |
433 |
| 396 int ui_dropdown_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { |
434 int ui_dropdown_eventproc(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { |
| 435 void *elm = list->get(list, row); |
473 void *elm = list->get(list, row); |
| 436 dropdown_insert_item(list, row, elm); |
474 dropdown_insert_item(list, row, elm); |
| 437 } |
475 } |
| 438 } |
476 } |
| 439 |
477 |
| 440 UiListSelection ui_dropdown_getselection(UiList *list) { |
478 UiListSelection ui_dropdown_getselection_impl(UiList *list) { |
| 441 UiListSelection sel = { 0, NULL }; |
479 UiListSelection sel = { 0, NULL }; |
| 442 UiListView *listview = (UiListView*)list->obj; |
480 UiListView *listview = (UiListView*)list->obj; |
| 443 int index = (int)SendMessage(listview->widget.hwnd, CB_GETCURSEL, 0, 0); |
481 int index = (int)SendMessage(listview->widget.hwnd, CB_GETCURSEL, 0, 0); |
| 444 if (index >= 0) { |
482 if (index >= 0) { |
| 445 sel.rows = malloc(sizeof(int)); |
483 sel.rows = malloc(sizeof(int)); |
| 447 sel.count = 1; |
485 sel.count = 1; |
| 448 } |
486 } |
| 449 return sel; |
487 return sel; |
| 450 } |
488 } |
| 451 |
489 |
| 452 void ui_dropdown_setselection(UiList *list, UiListSelection selection) { |
490 void ui_dropdown_setselection_impl(UiList *list, UiListSelection selection) { |
| 453 UiListView *listview = (UiListView*)list->obj; |
491 UiListView *listview = (UiListView*)list->obj; |
| 454 SendMessage(listview->widget.hwnd, CB_SETCURSEL, 0, 0); |
492 SendMessage(listview->widget.hwnd, CB_SETCURSEL, 0, 0); |
| 455 } |
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 } |