| 15685 | |
| 15686 | |
| 15687 | ResultType GuiControlType::LV_InsertModifyDeleteCol(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount) |
| 15688 | // Returns: 1 on success and 0 on failure. |
| 15689 | // Parameters: |
| 15690 | // 1: Column index (one-based when it comes in). |
| 15691 | // 2: String of options |
| 15692 | // 3: New text of column |
| 15693 | // There are also some special modes when only zero or one parameter is present, see below. |
| 15694 | { |
| 15695 | auto mode = BuiltInFunctionID(aID); |
| 15696 | LPTSTR buf = _f_number_buf; // Resolve macro early for maintainability. |
| 15697 | aResultToken.SetValue(0); // Set default return value. |
| 15698 | |
| 15699 | GuiControlType &control = *this; |
| 15700 | GuiType &gui = *control.gui; |
| 15701 | lv_attrib_type &lv_attrib = *control.union_lv_attrib; |
| 15702 | DWORD view_mode = mode != 'D' ? ListView_GetView(control.hwnd) : 0; |
| 15703 | |
| 15704 | int index; |
| 15705 | if (!ParamIndexIsOmitted(0)) |
| 15706 | index = ParamIndexToInt(0) - 1; // -1 to convert to zero-based. |
| 15707 | else // Zero parameters. Load-time validation has ensured that the 'D' (delete) mode cannot have zero params. |
| 15708 | { |
| 15709 | if (mode == FID_LV_ModifyCol) |
| 15710 | { |
| 15711 | if (view_mode != LV_VIEW_DETAILS) |
| 15712 | _o_return_retval; // Return 0 to indicate failure. |
| 15713 | // Otherwise: |
| 15714 | // v1.0.36.03: Don't attempt to auto-size the columns while the view is not report-view because |
| 15715 | // that causes any subsequent switch to the "list" view to be corrupted (invisible icons and items): |
| 15716 | for (int i = 0; ; ++i) // Don't limit it to lv_attrib.col_count in case script added extra columns via direct API calls. |
| 15717 | if (!ListView_SetColumnWidth(control.hwnd, i, LVSCW_AUTOSIZE)) // Failure means last column has already been processed. |
| 15718 | break; |
| 15719 | _o_return(1); // Always successful, regardless of what happened in the loop above. |
| 15720 | } |
| 15721 | // Since above didn't return, mode must be 'I' (insert). |
| 15722 | index = lv_attrib.col_count; // When no insertion index was specified, append to the end of the list. |
| 15723 | } |
| 15724 | |
| 15725 | // Do this prior to checking if index is in bounds so that it can support columns beyond LV_MAX_COLUMNS: |
| 15726 | if (mode == FID_LV_DeleteCol) // Delete a column. In this mode, index parameter was made mandatory via load-time validation. |
| 15727 | { |
| 15728 | if (ListView_DeleteColumn(control.hwnd, index)) // Returns TRUE/FALSE. |
| 15729 | { |
| 15730 | // It's important to note that when the user slides columns around via drag and drop, the |
| 15731 | // column index as seen by the script is not changed. This is fortunate because otherwise, |
| 15732 | // the lv_attrib.col array would get out of sync with the column indices. Testing shows that |
| 15733 | // all of the following operations respect the original column index, regardless of where the |
| 15734 | // user may have moved the column physically: InsertCol, DeleteCol, ModifyCol. Insert and Delete |
| 15735 | // shifts the indices of those columns that *originally* lay to the right of the affected column. |
| 15736 | if (lv_attrib.col_count > 0) // Avoid going negative, which would otherwise happen if script previously added columns by calling the API directly. |
| 15737 | --lv_attrib.col_count; // Must be done prior to the below. |
| 15738 | if (index < lv_attrib.col_count) // When a column other than the last was removed, adjust the array so that it stays in sync with actual columns. |
| 15739 | MoveMemory(lv_attrib.col+index, lv_attrib.col+index+1, sizeof(lv_col_type)*(lv_attrib.col_count-index)); |
| 15740 | _f_set_retval_i(1); |
| 15741 | } |
| 15742 | _o_return_retval; |
| 15743 | } |
| 15744 | // Do this prior to checking if index is in bounds so that it can support columns beyond LV_MAX_COLUMNS: |
nothing calls this directly
no test coverage detected