MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / handleCharInput

Method handleCharInput

Engine/source/gui/controls/guiTextEditCtrl.cpp:1539–1627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1537}
1538
1539void GuiTextEditCtrl::handleCharInput( U16 ascii )
1540{
1541 S32 stringLen = mTextBuffer.length();
1542
1543 // Get the character ready to add to a UTF8 string.
1544 UTF16 convertedChar[2] = { ascii, 0 };
1545
1546 //see if it's a number field
1547 if ( mProfile->mNumbersOnly )
1548 {
1549 if (ascii == '-')
1550 {
1551 //a minus sign only exists at the beginning, and only a single minus sign
1552 if (mCursorPos != 0 && !isAllTextSelected())
1553 {
1554 invalidText();
1555 return;
1556 }
1557
1558 if (mInsertOn && (mTextBuffer.getChar(0) == '-'))
1559 {
1560 invalidText();
1561 return;
1562 }
1563 }
1564 // BJTODO: This is probably not unicode safe.
1565 else if (ascii != '.' && (ascii < '0' || ascii > '9'))
1566 {
1567 invalidText();
1568 return;
1569 }
1570 else
1571 validText();
1572 }
1573
1574 //save the current state
1575 saveUndoState();
1576
1577 bool alreadyCut = false;
1578
1579 //delete anything highlighted
1580 if ( mBlockEnd > 0 )
1581 {
1582 mTextBuffer.cut(mBlockStart, mBlockEnd-mBlockStart);
1583 mCursorPos = mBlockStart;
1584 mBlockStart = 0;
1585 mBlockEnd = 0;
1586
1587 // We just changed the string length!
1588 // Get its new value.
1589 stringLen = mTextBuffer.length();
1590
1591 // If we already had text highlighted, we just want to cut that text.
1592 // Don't cut the next character even if insert is not on.
1593 alreadyCut = true;
1594 }
1595
1596 if ( ( mInsertOn && ( stringLen < mMaxStrLen ) ) ||

Callers

nothing calls this directly

Calls 5

getCharMethod · 0.80
cutMethod · 0.80
lengthMethod · 0.45
appendMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected