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

Method ControlSetContents

source/script_gui.cpp:1421–1507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1419
1420
1421ResultType GuiType::ControlSetContents(GuiControlType &aControl, ExprTokenType &aValue, ResultToken &aResultToken, bool aIsText)
1422// aContents: The content as a string.
1423// aResultToken: Used only to set an exit result in the event of an error.
1424{
1425 LPTSTR aContents = TokenToString(aValue, aResultToken.buf);
1426 // Control types for which Text and Value both have special handling:
1427 switch (aControl.type)
1428 {
1429 case GUI_CONTROL_DROPDOWNLIST:
1430 case GUI_CONTROL_COMBOBOX:
1431 case GUI_CONTROL_LISTBOX:
1432 case GUI_CONTROL_TAB:
1433 return ControlSetChoice(aControl, aContents, aResultToken, aIsText);
1434
1435 case GUI_CONTROL_EDIT:
1436 return ControlSetEdit(aControl, aContents, aResultToken, aIsText);
1437
1438 case GUI_CONTROL_DATETIME:
1439 if (aIsText)
1440 _o_throw(ERR_GUI_NOT_FOR_THIS_TYPE); // Let the user know the control doesn't support this.
1441 else
1442 return ControlSetDateTime(aControl, aContents, aResultToken);
1443
1444 case GUI_CONTROL_TEXT:
1445 // It seems sensible to treat the caption text of a Text control as its "value",
1446 // since displaying text is its only purpose; it's just for output only, whereas
1447 // an Edit control can be for input or output.
1448 aIsText = true;
1449 break;
1450 }
1451 // The remaining control types have no need for special handling of the Text property,
1452 // either because they have normal caption text, or because they have no "text version"
1453 // of the value, or no "value" at all.
1454 if (aIsText)
1455 {
1456 SetWindowText(aControl.hwnd, aContents);
1457 if (aControl.background_color == CLR_TRANSPARENT) // +BackgroundTrans
1458 ControlRedraw(aControl);
1459 return OK;
1460 }
1461 // Otherwise, this is the Value property.
1462 switch (aControl.type)
1463 {
1464 case GUI_CONTROL_PIC: return ControlSetPic(aControl, aContents, aResultToken);
1465 case GUI_CONTROL_MONTHCAL: return ControlSetMonthCal(aControl, aContents, aResultToken);
1466 case GUI_CONTROL_HOTKEY: return ControlSetHotkey(aControl, aContents, aResultToken);
1467
1468 case GUI_CONTROL_RADIO: // Same as below.
1469 case GUI_CONTROL_CHECKBOX:
1470 case GUI_CONTROL_UPDOWN:
1471 case GUI_CONTROL_SLIDER:
1472 case GUI_CONTROL_PROGRESS:
1473 {
1474 if (!TokenIsNumeric(aValue))
1475 _o_throw_type(_T("Number"), aValue);
1476 int value = (int)TokenToInt64(aValue);
1477 switch (aControl.type)
1478 {

Callers 1

InvokeMethod · 0.80

Calls 3

TokenToStringFunction · 0.85
TokenIsNumericFunction · 0.85
TokenToInt64Function · 0.85

Tested by

no test coverage detected