2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller-text-updater.h>
22 #include <dali/integration-api/debug.h>
26 #include <dali-toolkit/internal/text/character-set-conversion.h>
27 #include <dali-toolkit/internal/text/markup-processor.h>
28 #include <dali-toolkit/internal/text/text-controller-impl.h>
29 #include <dali-toolkit/internal/text/text-controller-placeholder-handler.h>
30 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
34 #if defined(DEBUG_ENABLED)
35 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
46 void Controller::TextUpdater::SetText(Controller& controller, const std::string& text)
48 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::SetText\n");
50 Controller::Impl& impl = *controller.mImpl;
52 // Reset keyboard as text changed
53 impl.ResetInputMethodContext();
55 // Remove the previously set text and style.
56 ResetText(controller);
59 impl.ClearStyleData();
61 CharacterIndex lastCursorIndex = 0u;
63 EventData*& eventData = impl.mEventData;
65 if(nullptr != eventData)
67 // If popup shown then hide it by switching to Editing state
68 if((EventData::SELECTING == eventData->mState) ||
69 (EventData::EDITING_WITH_POPUP == eventData->mState) ||
70 (EventData::EDITING_WITH_GRAB_HANDLE == eventData->mState) ||
71 (EventData::EDITING_WITH_PASTE_POPUP == eventData->mState))
73 if((impl.mSelectableControlInterface != nullptr) && (EventData::SELECTING == eventData->mState))
75 impl.mSelectableControlInterface->SelectionChanged(eventData->mLeftSelectionPosition, eventData->mRightSelectionPosition, eventData->mPrimaryCursorPosition, eventData->mPrimaryCursorPosition);
78 impl.ChangeState(EventData::EDITING);
84 ModelPtr& model = impl.mModel;
85 LogicalModelPtr& logicalModel = model->mLogicalModel;
86 model->mVisualModel->SetTextColor(impl.mTextColor);
88 MarkupProcessData markupProcessData(logicalModel->mColorRuns,
89 logicalModel->mFontDescriptionRuns,
90 logicalModel->mEmbeddedItems,
91 logicalModel->mAnchors,
92 logicalModel->mUnderlinedCharacterRuns,
93 logicalModel->mBackgroundColorRuns,
94 logicalModel->mStrikethroughCharacterRuns,
95 logicalModel->mBoundedParagraphRuns,
96 logicalModel->mCharacterSpacingCharacterRuns);
99 const uint8_t* utf8 = NULL;
100 if(impl.mMarkupProcessorEnabled)
102 ProcessMarkupString(text, markupProcessData);
103 textSize = markupProcessData.markupProcessedText.size();
105 // This is a bit horrible but std::string returns a (signed) char*
106 utf8 = reinterpret_cast<const uint8_t*>(markupProcessData.markupProcessedText.c_str());
110 textSize = text.size();
112 // This is a bit horrible but std::string returns a (signed) char*
113 utf8 = reinterpret_cast<const uint8_t*>(text.c_str());
116 // Convert text into UTF-32
117 Vector<Character>& utf32Characters = logicalModel->mText;
118 utf32Characters.Resize(textSize);
120 // Transform a text array encoded in utf8 into an array encoded in utf32.
121 // It returns the actual number of characters.
122 Length characterCount = Utf8ToUtf32(utf8, textSize, utf32Characters.Begin());
123 utf32Characters.Resize(characterCount);
125 DALI_ASSERT_DEBUG(textSize >= characterCount && "Invalid UTF32 conversion length");
126 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", &controller, textSize, logicalModel->mText.Count());
128 // The characters to be added.
129 impl.mTextUpdateInfo.mNumberOfCharactersToAdd = logicalModel->mText.Count();
131 // To reset the cursor position
132 lastCursorIndex = characterCount;
134 // Update the rest of the model during size negotiation
135 impl.QueueModifyEvent(ModifyEvent::TEXT_REPLACED);
137 // The natural size needs to be re-calculated.
138 impl.mRecalculateNaturalSize = true;
140 // The text direction needs to be updated.
141 impl.mUpdateTextDirection = true;
143 // Apply modifications to the model
144 impl.mOperationsPending = ALL_OPERATIONS;
148 PlaceholderHandler::ShowPlaceholderText(impl);
151 unsigned int oldCursorPos = (nullptr != eventData ? eventData->mPrimaryCursorPosition : 0);
153 // Resets the cursor position.
154 controller.ResetCursorPosition(lastCursorIndex);
156 // Scrolls the text to make the cursor visible.
157 impl.ResetScrollPosition();
159 impl.RequestRelayout();
161 if(nullptr != eventData)
163 // Cancel previously queued events
164 eventData->mEventQueue.clear();
167 // Do this last since it provides callbacks into application code.
168 if(NULL != impl.mEditableControlInterface)
170 impl.mEditableControlInterface->CursorPositionChanged(oldCursorPos, lastCursorIndex);
171 impl.mEditableControlInterface->TextChanged(true);
175 void Controller::TextUpdater::InsertText(Controller& controller, const std::string& text, Controller::InsertType type)
177 Controller::Impl& impl = *controller.mImpl;
178 EventData*& eventData = impl.mEventData;
180 DALI_ASSERT_DEBUG(nullptr != eventData && "Unexpected InsertText")
182 if(NULL == eventData)
187 bool removedPrevious = false;
188 bool removedSelected = false;
189 bool maxLengthReached = false;
190 unsigned int oldCursorPos = eventData->mPrimaryCursorPosition;
192 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n", &controller, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"), eventData->mPrimaryCursorPosition, eventData->mPreEditFlag, eventData->mPreEditStartPosition, eventData->mPreEditLength);
194 ModelPtr& model = impl.mModel;
195 LogicalModelPtr& logicalModel = model->mLogicalModel;
197 // TODO: At the moment the underline runs are only for pre-edit.
198 model->mVisualModel->mUnderlineRuns.Clear();
200 // Remove the previous InputMethodContext pre-edit.
201 if(eventData->mPreEditFlag && (0u != eventData->mPreEditLength))
203 removedPrevious = RemoveText(controller,
204 -static_cast<int>(eventData->mPrimaryCursorPosition - eventData->mPreEditStartPosition),
205 eventData->mPreEditLength,
206 DONT_UPDATE_INPUT_STYLE);
208 eventData->mPrimaryCursorPosition = eventData->mPreEditStartPosition;
209 eventData->mPreEditLength = 0u;
213 // Remove the previous Selection.
214 removedSelected = RemoveSelectedText(controller);
217 Vector<Character> utf32Characters;
218 Length characterCount = 0u;
222 // Convert text into UTF-32
223 utf32Characters.Resize(text.size());
225 // This is a bit horrible but std::string returns a (signed) char*
226 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>(text.c_str());
228 // Transform a text array encoded in utf8 into an array encoded in utf32.
229 // It returns the actual number of characters.
230 characterCount = Utf8ToUtf32(utf8, text.size(), utf32Characters.Begin());
231 utf32Characters.Resize(characterCount);
233 DALI_ASSERT_DEBUG(text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length");
234 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count());
237 if(0u != utf32Characters.Count()) // Check if Utf8ToUtf32 conversion succeeded
239 // The placeholder text is no longer needed
240 if(impl.IsShowingPlaceholderText())
242 ResetText(controller);
245 impl.ChangeState(EventData::EDITING);
247 // Handle the InputMethodContext (predicitive text) state changes
250 // InputMethodContext is no longer handling key-events
251 impl.ClearPreEditFlag();
255 if(!eventData->mPreEditFlag)
257 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Entered PreEdit state\n");
259 // Record the start of the pre-edit text
260 eventData->mPreEditStartPosition = eventData->mPrimaryCursorPosition;
263 eventData->mPreEditLength = utf32Characters.Count();
264 eventData->mPreEditFlag = true;
266 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", eventData->mPreEditStartPosition, eventData->mPreEditLength);
269 const Length numberOfCharactersInModel = logicalModel->mText.Count();
271 // Restrict new text to fit within Maximum characters setting.
272 Length temp_length = (impl.mMaximumNumberOfCharacters > numberOfCharactersInModel ? impl.mMaximumNumberOfCharacters - numberOfCharactersInModel : 0);
273 Length maxSizeOfNewText = std::min(temp_length, characterCount);
274 maxLengthReached = (characterCount > maxSizeOfNewText);
276 // The cursor position.
277 CharacterIndex& cursorIndex = eventData->mPrimaryCursorPosition;
279 // Update the text's style.
281 // Updates the text style runs by adding characters.
282 logicalModel->UpdateTextStyleRuns(cursorIndex, maxSizeOfNewText);
284 // Get the character index from the cursor index.
285 const CharacterIndex styleIndex = (cursorIndex > 0u) ? cursorIndex - 1u : 0u;
287 // Retrieve the text's style for the given index.
289 impl.RetrieveDefaultInputStyle(style);
290 logicalModel->RetrieveStyle(styleIndex, style);
292 InputStyle& inputStyle = eventData->mInputStyle;
294 // Whether to add a new text color run.
295 const bool addColorRun = (style.textColor != inputStyle.textColor) && !inputStyle.isDefaultColor;
297 // Whether to add a new font run.
298 const bool addFontNameRun = (style.familyName != inputStyle.familyName) && inputStyle.isFamilyDefined;
299 const bool addFontWeightRun = (style.weight != inputStyle.weight) && inputStyle.isWeightDefined;
300 const bool addFontWidthRun = (style.width != inputStyle.width) && inputStyle.isWidthDefined;
301 const bool addFontSlantRun = (style.slant != inputStyle.slant) && inputStyle.isSlantDefined;
302 const bool addFontSizeRun = (style.size != inputStyle.size) && inputStyle.isSizeDefined;
307 const VectorBase::SizeType numberOfRuns = logicalModel->mColorRuns.Count();
308 logicalModel->mColorRuns.Resize(numberOfRuns + 1u);
310 ColorRun& colorRun = *(logicalModel->mColorRuns.Begin() + numberOfRuns);
311 colorRun.color = inputStyle.textColor;
312 colorRun.characterRun.characterIndex = cursorIndex;
313 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
322 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
323 logicalModel->mFontDescriptionRuns.Resize(numberOfRuns + 1u);
325 FontDescriptionRun& fontDescriptionRun = *(logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns);
329 fontDescriptionRun.familyLength = inputStyle.familyName.size();
330 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
331 memcpy(fontDescriptionRun.familyName, inputStyle.familyName.c_str(), fontDescriptionRun.familyLength);
332 fontDescriptionRun.familyDefined = true;
334 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
339 fontDescriptionRun.weight = inputStyle.weight;
340 fontDescriptionRun.weightDefined = true;
345 fontDescriptionRun.width = inputStyle.width;
346 fontDescriptionRun.widthDefined = true;
351 fontDescriptionRun.slant = inputStyle.slant;
352 fontDescriptionRun.slantDefined = true;
357 fontDescriptionRun.size = static_cast<PointSize26Dot6>(inputStyle.size * impl.GetFontSizeScale() * 64.f);
358 fontDescriptionRun.sizeDefined = true;
361 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
362 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
365 // Insert at current cursor position.
366 Vector<Character>& modifyText = logicalModel->mText;
368 auto pos = modifyText.End();
369 if(cursorIndex < numberOfCharactersInModel)
371 pos = modifyText.Begin() + cursorIndex;
373 unsigned int realPos = pos - modifyText.Begin();
374 modifyText.Insert(pos, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText);
376 if(NULL != impl.mEditableControlInterface)
378 impl.mEditableControlInterface->TextInserted(realPos, maxSizeOfNewText, text);
381 TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
383 // Mark the first paragraph to be updated.
384 if(Layout::Engine::SINGLE_LINE_BOX == impl.mLayoutEngine.GetLayout())
386 textUpdateInfo.mCharacterIndex = 0;
387 textUpdateInfo.mNumberOfCharactersToRemove = textUpdateInfo.mPreviousNumberOfCharacters;
388 textUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
389 textUpdateInfo.mClearAll = true;
393 textUpdateInfo.mCharacterIndex = std::min(cursorIndex, textUpdateInfo.mCharacterIndex);
394 textUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
397 if(impl.mMarkupProcessorEnabled)
399 InsertTextAnchor(controller, maxSizeOfNewText, cursorIndex);
402 // Update the cursor index.
403 cursorIndex += maxSizeOfNewText;
405 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, logicalModel->mText.Count(), eventData->mPrimaryCursorPosition);
408 if((0u == logicalModel->mText.Count()) &&
409 impl.IsPlaceholderAvailable())
411 // Show place-holder if empty after removing the pre-edit text
412 PlaceholderHandler::ShowPlaceholderText(impl);
413 eventData->mUpdateCursorPosition = true;
414 impl.ClearPreEditFlag();
416 else if(removedPrevious ||
418 (0 != utf32Characters.Count()))
420 // Queue an inserted event
421 impl.QueueModifyEvent(ModifyEvent::TEXT_INSERTED);
423 eventData->mUpdateCursorPosition = true;
426 eventData->mScrollAfterDelete = true;
430 eventData->mScrollAfterUpdatePosition = true;
434 if(nullptr != impl.mEditableControlInterface)
436 impl.mEditableControlInterface->CursorPositionChanged(oldCursorPos, eventData->mPrimaryCursorPosition);
441 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", logicalModel->mText.Count());
443 impl.ResetInputMethodContext();
445 if(NULL != impl.mEditableControlInterface)
447 // Do this last since it provides callbacks into application code
448 impl.mEditableControlInterface->MaxLengthReached();
453 void Controller::TextUpdater::PasteText(Controller& controller, const std::string& stringToPaste)
455 InsertText(controller, stringToPaste, Text::Controller::COMMIT);
456 Controller::Impl& impl = *controller.mImpl;
457 impl.ChangeState(EventData::EDITING);
458 impl.RequestRelayout();
460 if(NULL != impl.mEditableControlInterface)
462 // Do this last since it provides callbacks into application code
463 impl.mEditableControlInterface->TextChanged(true);
467 bool Controller::TextUpdater::RemoveText(
468 Controller& controller,
470 int numberOfCharacters,
471 UpdateInputStyleType type)
473 bool removed = false;
475 Controller::Impl& impl = *controller.mImpl;
476 EventData*& eventData = impl.mEventData;
478 if(nullptr == eventData)
483 ModelPtr& model = impl.mModel;
484 LogicalModelPtr& logicalModel = model->mLogicalModel;
486 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n", &controller, logicalModel->mText.Count(), eventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters);
488 if(!impl.IsShowingPlaceholderText())
490 // Delete at current cursor position
491 Vector<Character>& currentText = logicalModel->mText;
492 CharacterIndex& previousCursorIndex = eventData->mPrimaryCursorPosition;
494 CharacterIndex cursorIndex = 0;
496 // Validate the cursor position & number of characters
497 if((static_cast<int>(eventData->mPrimaryCursorPosition) + cursorOffset) >= 0)
499 cursorIndex = eventData->mPrimaryCursorPosition + cursorOffset;
502 if((cursorIndex + numberOfCharacters) > currentText.Count())
504 numberOfCharacters = currentText.Count() - cursorIndex;
507 TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
509 if(eventData->mPreEditFlag || // If the preedit flag is enabled, it means two (or more) of them came together i.e. when two keys have been pressed at the same time.
510 ((cursorIndex + numberOfCharacters) <= textUpdateInfo.mPreviousNumberOfCharacters))
512 // Mark the paragraphs to be updated.
513 if(Layout::Engine::SINGLE_LINE_BOX == impl.mLayoutEngine.GetLayout())
515 textUpdateInfo.mCharacterIndex = 0;
516 textUpdateInfo.mNumberOfCharactersToRemove = textUpdateInfo.mPreviousNumberOfCharacters;
517 textUpdateInfo.mNumberOfCharactersToAdd = textUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
518 textUpdateInfo.mClearAll = true;
522 textUpdateInfo.mCharacterIndex = std::min(cursorIndex, textUpdateInfo.mCharacterIndex);
523 textUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
526 // Update the input style and remove the text's style before removing the text.
528 if(UPDATE_INPUT_STYLE == type)
530 InputStyle& eventDataInputStyle = eventData->mInputStyle;
532 // Keep a copy of the current input style.
533 InputStyle currentInputStyle;
534 currentInputStyle.Copy(eventDataInputStyle);
536 // Set first the default input style.
537 impl.RetrieveDefaultInputStyle(eventDataInputStyle);
539 // Update the input style.
540 logicalModel->RetrieveStyle(cursorIndex, eventDataInputStyle);
542 // Compare if the input style has changed.
543 const bool hasInputStyleChanged = !currentInputStyle.Equal(eventDataInputStyle);
545 if(hasInputStyleChanged)
547 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask(eventDataInputStyle);
548 // Queue the input style changed signal.
549 eventData->mInputStyleChangedQueue.PushBack(styleChangedMask);
553 // If the number of current text and the number of characters to be deleted are same,
554 // it means all texts should be removed and all Preedit variables should be initialized.
555 if((currentText.Count() - numberOfCharacters == 0) && (cursorIndex == 0))
557 impl.ClearPreEditFlag();
558 textUpdateInfo.mNumberOfCharactersToAdd = 0;
561 // Updates the text style runs by removing characters. Runs with no characters are removed.
562 logicalModel->UpdateTextStyleRuns(cursorIndex, -numberOfCharacters);
564 // Remove the characters.
565 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
566 Vector<Character>::Iterator last = first + numberOfCharacters;
568 if(NULL != impl.mEditableControlInterface)
571 Utf32ToUtf8(first, numberOfCharacters, utf8);
572 impl.mEditableControlInterface->TextDeleted(cursorIndex, numberOfCharacters, utf8);
575 currentText.Erase(first, last);
577 if(impl.mMarkupProcessorEnabled)
579 RemoveTextAnchor(controller, cursorOffset, numberOfCharacters, previousCursorIndex);
582 if(nullptr != impl.mEditableControlInterface)
584 impl.mEditableControlInterface->CursorPositionChanged(previousCursorIndex, cursorIndex);
587 // Cursor position retreat
588 previousCursorIndex = cursorIndex;
590 eventData->mScrollAfterDelete = true;
592 if(EventData::INACTIVE == eventData->mState)
594 impl.ChangeState(EventData::EDITING);
597 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", &controller, numberOfCharacters);
605 bool Controller::TextUpdater::RemoveSelectedText(Controller& controller)
607 bool textRemoved(false);
609 Controller::Impl& impl = *controller.mImpl;
611 if(EventData::SELECTING == impl.mEventData->mState)
613 std::string removedString;
614 uint32_t oldSelStart = impl.mEventData->mLeftSelectionPosition;
615 uint32_t oldSelEnd = impl.mEventData->mRightSelectionPosition;
617 impl.RetrieveSelection(removedString, true);
619 if(!removedString.empty())
622 impl.ChangeState(EventData::EDITING);
624 if(impl.mMarkupProcessorEnabled)
626 int cursorOffset = -1;
627 int numberOfCharacters = removedString.length();
628 CharacterIndex& cursorIndex = impl.mEventData->mPrimaryCursorPosition;
629 CharacterIndex previousCursorIndex = cursorIndex + numberOfCharacters;
631 RemoveTextAnchor(controller, cursorOffset, numberOfCharacters, previousCursorIndex);
634 if(impl.mSelectableControlInterface != nullptr)
636 impl.mSelectableControlInterface->SelectionChanged(oldSelStart, oldSelEnd, impl.mEventData->mPrimaryCursorPosition, impl.mEventData->mPrimaryCursorPosition);
644 void Controller::TextUpdater::ResetText(Controller& controller)
646 Controller::Impl& impl = *controller.mImpl;
647 LogicalModelPtr& logicalModel = impl.mModel->mLogicalModel;
650 logicalModel->mText.Clear();
652 // Reset the embedded images buffer.
653 logicalModel->ClearEmbeddedImages();
655 // Reset the anchors buffer.
656 logicalModel->ClearAnchors();
658 // We have cleared everything including the placeholder-text
659 impl.PlaceholderCleared();
661 impl.mTextUpdateInfo.mCharacterIndex = 0u;
662 impl.mTextUpdateInfo.mNumberOfCharactersToRemove = impl.mTextUpdateInfo.mPreviousNumberOfCharacters;
663 impl.mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
665 // Clear any previous text.
666 impl.mTextUpdateInfo.mClearAll = true;
668 // The natural size needs to be re-calculated.
669 impl.mRecalculateNaturalSize = true;
671 // The text direction needs to be updated.
672 impl.mUpdateTextDirection = true;
674 // Apply modifications to the model
675 impl.mOperationsPending = ALL_OPERATIONS;
678 void Controller::TextUpdater::InsertTextAnchor(Controller& controller, int numberOfCharacters, CharacterIndex previousCursorIndex)
680 Controller::Impl& impl = *controller.mImpl;
681 ModelPtr& model = impl.mModel;
682 LogicalModelPtr& logicalModel = model->mLogicalModel;
684 for(auto& anchor : logicalModel->mAnchors)
686 if(anchor.endIndex < previousCursorIndex) // [anchor] CUR
690 if(anchor.startIndex < previousCursorIndex) // [anCURr]
692 anchor.endIndex += numberOfCharacters;
696 anchor.startIndex += numberOfCharacters;
697 anchor.endIndex += numberOfCharacters;
699 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::InsertTextAnchor[%p] Anchor[%s] start[%d] end[%d]\n", &controller, anchor.href, anchor.startIndex, anchor.endIndex);
703 void Controller::TextUpdater::RemoveTextAnchor(Controller& controller, int cursorOffset, int numberOfCharacters, CharacterIndex previousCursorIndex)
705 Controller::Impl& impl = *controller.mImpl;
706 ModelPtr& model = impl.mModel;
707 LogicalModelPtr& logicalModel = model->mLogicalModel;
708 Vector<Anchor>::Iterator it = logicalModel->mAnchors.Begin();
710 while(it != logicalModel->mAnchors.End())
712 Anchor& anchor = *it;
714 if(anchor.endIndex <= previousCursorIndex && cursorOffset == 0) // [anchor] CUR >>
718 else if(anchor.endIndex <= previousCursorIndex && cursorOffset == -1) // [anchor] << CUR
720 int endIndex = anchor.endIndex;
721 int offset = previousCursorIndex - endIndex;
722 int index = endIndex - (numberOfCharacters - offset);
729 if((int)anchor.startIndex >= endIndex)
733 delete[] anchor.href;
735 it = logicalModel->mAnchors.Erase(it);
740 anchor.endIndex = endIndex;
743 else if(anchor.startIndex >= previousCursorIndex && cursorOffset == -1) // << CUR [anchor]
745 anchor.startIndex -= numberOfCharacters;
746 anchor.endIndex -= numberOfCharacters;
748 else if(anchor.startIndex >= previousCursorIndex && cursorOffset == 0) // CUR >> [anchor]
750 int startIndex = anchor.startIndex;
751 int endIndex = anchor.endIndex;
752 int index = previousCursorIndex + numberOfCharacters - 1;
754 if(startIndex > index)
756 anchor.startIndex -= numberOfCharacters;
757 anchor.endIndex -= numberOfCharacters;
759 else if(endIndex > index + 1)
761 anchor.endIndex -= numberOfCharacters;
767 delete[] anchor.href;
769 it = logicalModel->mAnchors.Erase(it);
773 else if(cursorOffset == -1) // [<< CUR]
775 int startIndex = anchor.startIndex;
776 int index = previousCursorIndex - numberOfCharacters;
778 if(startIndex >= index)
780 anchor.startIndex = index;
782 anchor.endIndex -= numberOfCharacters;
784 else if(cursorOffset == 0) // [CUR >>]
786 anchor.endIndex -= numberOfCharacters;
790 // When this condition is reached, someting is wrong.
791 DALI_LOG_ERROR("Controller::RemoveTextAnchor[%p] Invaild state cursorOffset[%d]\n", &controller, cursorOffset);
794 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveTextAnchor[%p] Anchor[%s] start[%d] end[%d]\n", &controller, anchor.href, anchor.startIndex, anchor.endIndex);
802 } // namespace Toolkit