MCPcopy Create free account
hub / github.com/MyGUI/mygui / insertText

Method insertText

MyGUIEngine/src/MyGUI_EditBox.cpp:1322–1408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1320 }
1321
1322 void EditBox::insertText(const UString& _text, size_t _start, bool _history)
1323 {
1324 // сбрасываем выделение
1325 resetSelect();
1326
1327 // если строка пустая, или размер максимален
1328 if (_text.empty())
1329 return;
1330
1331 if ((!mOverflowToTheLeft) && (mTextLength == mMaxTextLength))
1332 return;
1333
1334 // история изменений
1335 VectorChangeInfo* history = nullptr;
1336 if (_history)
1337 history = new VectorChangeInfo();
1338
1339 // итератор нашей строки
1340 TextIterator iterator(getRealString(), history);
1341
1342 // дефолтный цвет
1343 UString colour;
1344 if (mClientText != nullptr)
1345 colour = TextIterator::convertTagColour(mClientText->getTextColour());
1346 // нужен ли тег текста
1347 // потом переделать через TextIterator чтобы отвязать понятие тег от эдита
1348 bool need_colour = ((_text.size() > 6) && (_text[0] == L'#') && (_text[1] != L'#'));
1349
1350 // цикл прохода по строке
1351 while (iterator.moveNext())
1352 {
1353 // текущаяя позиция
1354 size_t pos = iterator.getPosition();
1355
1356 // текущий цвет
1357 if (need_colour)
1358 iterator.getTagColour(colour);
1359
1360 // если дошли то выходим
1361 if (pos == _start)
1362 break;
1363 }
1364
1365 // если нужен цвет то вставляем
1366 if (need_colour)
1367 iterator.setTagColour(colour);
1368
1369 // а теперь вставляем строку
1370 iterator.insertText(_text, mModeMultiline || mModeWordWrap);
1371
1372 if (mOverflowToTheLeft)
1373 {
1374 iterator.cutMaxLengthFromBeginning(mMaxTextLength);
1375 }
1376 else
1377 {
1378 // обрезаем по максимальной длинне
1379 iterator.cutMaxLength(mMaxTextLength);

Callers 2

InsertTextFunction · 0.45

Calls 11

moveNextMethod · 0.80
getTagColourMethod · 0.80
setTagColourMethod · 0.80
cutMaxLengthMethod · 0.80
setCursorPositionMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
getPositionMethod · 0.45
getSizeMethod · 0.45
getTextMethod · 0.45

Tested by

no test coverage detected