phenomenon
Recently, duilib based on NetEase's open source maintenance has made a client. After it went online, users reported a series of problems. The strangest problem is that RichEdit sometimes cannot be input.
survey
After testing with the official example, it was found that there are also problems:
The XML of these two RichEdits are as follows:
<!-- 单行文本 -->
<RichEdit class="simple input" height="30" margin="0,3" padding="6,6,6" promptmode="true" prompttext="Single line text control" promptcolor="lightcolor"/>
<!-- 多行文本 -->
<RichEdit class="prompt" name="edit" bkcolor="bk_wnd_lightcolor" width="stretch" height="stretch"
multiline="true" vscrollbar="true" hscrollbar="true" autovscroll="true"
normaltextcolor="darkcolor" wantreturnmsg="true" rich="true"/>
Solution
After constantly changing the style test, there are 2 ways:
- Change the class="simple input" in the single-line text to class="input"
- The simple style is defined in global.xml, find the definition of simple in this file, and remove wanttab="false"
<Class name="simple" multiline="false" autohscroll="true" wantreturnmsg="true" rich="false" normaltextcolor="darkcolor" disabledtextcolor="textdefaultdisablecolor"/>
<!-- <Class name="simple" multiline="false" autohscroll="true" wantreturnmsg="true" wanttab="false" rich="false" normaltextcolor="darkcolor" disabledtextcolor="textdefaultdisablecolor"/> -->
Therefore, it is finally determined that there is a relationship with wanttab="false".
Follow-up question
After removing wanttab="false", I found that the user name and password input box, when pressing Tab when the user name, will append a \t tab instead of a new line , so I need to continue to solve it.
After carefully reading the relevant code of duilib after NetEase's modification, manually process it in RichEdit\t to wrap.
void RichEdit::OnChar(EventArgs& event)
{
//TAB
if (::GetKeyState(VK_TAB) < 0) {
if (!m_bWantTab) {
if (m_pWindow != NULL)
m_pWindow->SendNotify((Control*)this, kEventTab);
return;
}
// added_by [email protected] 2021-01-28 tab ignore
// m_bWantTabEx是新增的属性,需要外部主动赋值。
if (!m_bWantTabEx) {
if (m_pWindow != NULL)
m_pWindow->SetNextTabControl(::GetKeyState(VK_SHIFT) >= 0);
return;
}
}
//Number
if (m_bNumberOnly) {
if (event.wParam < '0' || event.wParam > '9')
return;
}
TxSendMessage(WM_CHAR, event.wParam, event.lParam, NULL);
}
Assuming that the login interface is called LoginForm, in InitWindow, call SetWantTabEx (additional function added to solve the problem that some computers cannot input) to set it.
void LoginForm::InitWindow() {
// ...
passwd_ = static_cast<ui::RichEdit*>(FindControl(L"passwd"));
ed_phone_ = static_cast<ui::RichEdit*>(FindControl(L"ed_phone"));
ed_sms_ = static_cast<ui::RichEdit*>(FindControl(L"ed_sms"));
// SetWantTabEx是新增的函数,自己可以在RichEdit.h中新增即可。
ed_phone_->SetWantTabEx(false);
passwd_->SetWantTabEx(false);
ed_sms_->SetWantTabEx(false);
// ...
}
postscript
The official website hasn't been updated for more than a year, and I have maintained all the problems found in the README.md of this branch. If you need it, please move: