这个主要是解决在属性列表中,按键盘的上下键获取节点的值出错的问题
duilib的源码
void CListUI::DoEvent(TEventUI& event)
{
if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) {
if( m_pParent != NULL ) m_pParent->DoEvent(event);
else CVerticalLayoutUI::DoEvent(event);
return;
}
if( event.Type == UIEVENT_SETFOCUS )
{
m_bFocused = true;
return;
}
if( event.Type == UIEVENT_KILLFOCUS )
{
m_bFocused = false;
return;
}
if( event.Type == UIEVENT_KEYDOWN )
{
if (IsKeyboardEnabled() && IsEnabled()) {
switch( event.chKey ) {
case VK_UP:
SelectItem(FindSelectable(m_iCurSel - 1, false), true);
case VK_DOWN:
SelectItem(FindSelectable(m_iCurSel + 1, true), true);
case VK_PRIOR:
PageUp();
case VK_NEXT:
PageDown();
case VK_HOME:
SelectItem(FindSelectable(0, false), true);
case VK_END:
SelectItem(FindSelectable(GetCount() - 1, true), true);
case VK_RETURN:
if( m_iCurSel != -1 ) GetItemAt(m_iCurSel)->Activate();
}
return;
}
}
if( event.Type == UIEVENT_SCROLLWHEEL )
{
if (IsEnabled()) {
switch( LOWORD(event.wParam) ) {
case SB_LINEUP:
if( m_bScrollSelect ) SelectItem(FindSelectable(m_iCurSel - 1, false), true);
else LineUp();
return;
case SB_LINEDOWN:
if( m_bScrollSelect ) SelectItem(FindSelectable(m_iCurSel + 1, true), true);
else LineDown();
return;
}
}
}
CVerticalLayoutUI::DoEvent(event);
}
改进之后
void CListUI::DoEvent(TEventUI& event)
{
if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) {
if( m_pParent != NULL ) m_pParent->DoEvent(event);
else CVerticalLayoutUI::DoEvent(event);
return;
}
if( event.Type == UIEVENT_SETFOCUS )
{
m_bFocused = true;
return;
}
if( event.Type == UIEVENT_KILLFOCUS )
{
m_bFocused = false;
return;
}
if( event.Type == UIEVENT_KEYDOWN )
{
if (IsKeyboardEnabled() && IsEnabled()) {
*switch( event.chKey ) {
case VK_UP:
SelectItem(FindSelectable(m_iCurSel - 1, false), true);
if (m_iCurSel != -1) GetItemAt(m_iCurSel)->Activate();
break;
case VK_DOWN:
SelectItem(FindSelectable(m_iCurSel + 1, true), true);
if (m_iCurSel != -1) GetItemAt(m_iCurSel)->Activate();
break;
case VK_PRIOR:
PageUp();
if (m_iCurSel != -1) GetItemAt(m_iCurSel)->Activate();
break;
case VK_NEXT:
PageDown();
if (m_iCurSel != -1) GetItemAt(m_iCurSel)->Activate();
break;
case VK_HOME:
SelectItem(FindSelectable(0, false), true);
if (m_iCurSel != -1) GetItemAt(m_iCurSel)->Activate();
break;
case VK_END:
SelectItem(FindSelectable(GetCount() - 1, true), true);
if (m_iCurSel != -1) GetItemAt(m_iCurSel)->Activate();
break;
case VK_RETURN:
if( m_iCurSel != -1 ) GetItemAt(m_iCurSel)->Activate();
break;*
}
return;
}
}
if( event.Type == UIEVENT_SCROLLWHEEL )
{
if (IsEnabled()) {
switch( LOWORD(event.wParam) ) {
case SB_LINEUP:
if( m_bScrollSelect ) SelectItem(FindSelectable(m_iCurSel - 1, false), true);
else LineUp();
return;
case SB_LINEDOWN:
if( m_bScrollSelect ) SelectItem(FindSelectable(m_iCurSel + 1, true), true);
else LineDown();
return;
}
}
}
CVerticalLayoutUI::DoEvent(event);
}