MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / LV_AddInsertModify

Method LV_AddInsertModify

source/script2.cpp:15405–15664  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15403
15404
15405ResultType GuiControlType::LV_AddInsertModify(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount)
15406// Returns: 1 on success and 0 on failure.
15407// Parameters:
15408// 1: For Add(), this is the options. For Insert/Modify, it's the row index (one-based when it comes in).
15409// 2: For Add(), this is the first field's text. For Insert/Modify, it's the options.
15410// 3 and beyond: Additional field text.
15411// In Add/Insert mode, if there are no text fields present, a blank for is appended/inserted.
15412{
15413 GuiControlType &control = *this;
15414 auto mode = BuiltInFunctionID(aID);
15415 LPTSTR buf = _f_number_buf; // Resolve macro early for maintainability.
15416
15417 int index;
15418 if (mode == FID_LV_Add) // For Add mode, use INT_MAX as a signal to append the item rather than inserting it.
15419 {
15420 index = INT_MAX;
15421 mode = FID_LV_Insert; // Add has now been set up to be the same as insert, so change the mode to simplify other things.
15422 }
15423 else // Insert or Modify: the target row-index is their first parameter, which load-time has ensured is present.
15424 {
15425 index = ParamIndexToInt(0) - 1; // -1 to convert to zero-based.
15426 if (index < -1 || (mode != FID_LV_Modify && index < 0)) // Allow -1 to mean "all rows" when in modify mode.
15427 _o_throw_param(0);
15428 ++aParam; // Remove the first parameter from further consideration to make Insert/Modify symmetric with Add.
15429 --aParamCount;
15430 }
15431
15432 LPTSTR options = ParamIndexToOptionalString(0, buf);
15433 bool ensure_visible = false, is_checked = false; // Checkmark.
15434 int col_start_index = 0;
15435 LVITEM lvi;
15436 lvi.mask = LVIF_STATE; // LVIF_STATE: state member is valid, but only to the extent that corresponding bits are set in stateMask (the rest will be ignored).
15437 lvi.stateMask = 0;
15438 lvi.state = 0;
15439
15440 // Parse list of space-delimited options:
15441 TCHAR *next_option, *option_end, orig_char;
15442 bool adding; // Whether this option is being added (+) or removed (-).
15443
15444 for (next_option = options; *next_option; next_option = omit_leading_whitespace(option_end))
15445 {
15446 if (*next_option == '-')
15447 {
15448 adding = false;
15449 // omit_leading_whitespace() is not called, which enforces the fact that the option word must
15450 // immediately follow the +/- sign. This is done to allow the flexibility to have options
15451 // omit the plus/minus sign, and also to reserve more flexibility for future option formats.
15452 ++next_option; // Point it to the option word itself.
15453 }
15454 else
15455 {
15456 // Assume option is being added in the absence of either sign. However, when we were
15457 // called by GuiControl(), the first option in the list must begin with +/- otherwise the cmd
15458 // would never have been properly detected as GUICONTROL_CMD_OPTIONS in the first place.
15459 adding = true;
15460 if (*next_option == '+')
15461 ++next_option; // Point it to the option word itself.
15462 //else do not increment, under the assumption that the plus has been omitted from a valid

Callers

nothing calls this directly

Calls 5

omit_leading_whitespaceFunction · 0.85
StrChrAnyFunction · 0.85
ATOIFunction · 0.85
ValueErrorMethod · 0.80
BuiltInFunctionIDEnum · 0.70

Tested by

no test coverage detected