| 6835 | |
| 6836 | |
| 6837 | void GuiType::ControlAddItems(GuiControlType &aControl, Array *aObj) |
| 6838 | { |
| 6839 | if (!aObj) |
| 6840 | return; |
| 6841 | |
| 6842 | UINT msg_add; |
| 6843 | int requested_index = 0; |
| 6844 | |
| 6845 | switch (aControl.type) |
| 6846 | { |
| 6847 | case GUI_CONTROL_TAB: // These cases must be listed anyway to do a break vs. return, so might as well init conditionally rather than unconditionally. |
| 6848 | requested_index = TabCtrl_GetItemCount(aControl.hwnd); // So that tabs are "appended at the end of the control's list", as documented for GuiControl. |
| 6849 | // Fall through: |
| 6850 | case GUI_CONTROL_LISTVIEW: |
| 6851 | msg_add = 0; |
| 6852 | break; |
| 6853 | case GUI_CONTROL_DROPDOWNLIST: |
| 6854 | case GUI_CONTROL_COMBOBOX: |
| 6855 | msg_add = CB_ADDSTRING; |
| 6856 | break; |
| 6857 | case GUI_CONTROL_LISTBOX: |
| 6858 | msg_add = LB_ADDSTRING; |
| 6859 | break; |
| 6860 | default: // Do nothing for any other control type that somehow makes its way here. |
| 6861 | return; |
| 6862 | } |
| 6863 | |
| 6864 | LRESULT item_index; |
| 6865 | TCHAR num_buf[MAX_NUMBER_SIZE]; |
| 6866 | Array::index_t obj_index; |
| 6867 | ExprTokenType tok; |
| 6868 | |
| 6869 | // For tab controls: |
| 6870 | TCITEM tci; |
| 6871 | tci.mask = TCIF_TEXT | TCIF_IMAGE; // Simpler just to init unconditionally rather than checking control type. |
| 6872 | tci.iImage = -1; |
| 6873 | |
| 6874 | // For ListView: |
| 6875 | LVCOLUMN lvc; |
| 6876 | lvc.mask = LVCF_TEXT; // Simpler just to init unconditionally rather than checking control type. |
| 6877 | |
| 6878 | // Check *this_field at the top too, in case list ends in delimiter. |
| 6879 | for (obj_index = 0; aObj->ItemToToken(obj_index, tok); ++obj_index) |
| 6880 | { |
| 6881 | LPTSTR this_field = TokenToString(tok, num_buf); |
| 6882 | |
| 6883 | // Add the item: |
| 6884 | switch (aControl.type) |
| 6885 | { |
| 6886 | case GUI_CONTROL_TAB: |
| 6887 | if (requested_index > MAX_TABS_PER_CONTROL - 1) // Unlikely, but indicate failure if so. |
| 6888 | item_index = -1; |
| 6889 | else |
| 6890 | { |
| 6891 | tci.pszText = this_field; |
| 6892 | item_index = TabCtrl_InsertItem(aControl.hwnd, requested_index, &tci); |
| 6893 | if (item_index != -1) // item_index is used later below as an indicator of success. |
| 6894 | ++requested_index; |
no test coverage detected