void TextField::OnFocusGain() { KeyboardCursor::GetInstance().SetHwndId(GetHwndId()); UIManager::GetInstance().DirtyRenderList(mHwndId); auto mani = UIManager::GetInstance().GetTextManipulator(); mani->AddObserver(ITextManipulatorObserver::Default, std::dynamic_pointer_cast<ITextManipulatorObserver>(mSelfPtr.lock())); mani->SetText(&mTextw); auto propertyList = IsInPropertyList(); if (propertyList) { ListItem* listItem = (ListItem*)GetParent().get(); propertyList->SetFocusRow(listItem->GetRowIndex()); } KeyboardCursor::GetInstance().SetScissorRegion(GetScissorRegion()); }
void TextField::OnFocusLost() { UIManager::GetInstance().DirtyRenderList(mHwndId); auto mani = UIManager::GetInstance().GetTextManipulator(); auto propertyList = IsInPropertyList(); if (propertyList) { auto parent = GetParent(); assert(parent && parent->GetType() == ComponentType::ListItem); ListItem* valueItem = (ListItem*)parent.get(); auto index = valueItem->GetRowIndex(); propertyList->RemoveHighlight(index); auto uiEditor = UIManager::GetInstance().GetUIEditor(); auto editingUI = uiEditor->GetCurSelected(); std::string key, value; propertyList->GetCurKeyValue(key, value); if (editingUI) { char buf[UIManager::PROPERTY_BUF_SIZE] = { 0 }; auto prop = UIProperty::IsUIProperty(key.c_str()); if (prop != UIProperty::COUNT) { auto got = editingUI->GetProperty(prop, buf, UIManager::PROPERTY_BUF_SIZE, false); if (got) SetText(AnsiToWide(buf)); } else { auto e = UIEvents::IsUIEvents(key.c_str()); if (e != UIEvents::EVENT_NUM) { auto szEvent = editingUI->GetEvent(e); editingUI->SetEvent(e, szEvent); } } } } mani->SetText(0); mani->RemoveObserver(ITextManipulatorObserver::Default, std::dynamic_pointer_cast<ITextManipulatorObserver>(mSelfPtr.lock())); TriggerRedraw(); }