mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-08-17 17:02:51 +08:00
more convenient API for wxGenericValidator + wxLB_SINGLE
For a single-selection wxListBox, using an int to transfer data to/from wxGenericValidator is more convenient than wxArrayInt.
This commit is contained in:
@@ -21,6 +21,9 @@
|
||||
For example, wxButton and wxTextCtrl transfer data to and from a
|
||||
wxString variable; wxListBox uses a wxArrayInt; wxCheckBox uses a boolean.
|
||||
|
||||
@since 3.2.5
|
||||
A wxLB_SINGLE wxListBox can also use an int.
|
||||
|
||||
For more information, please see @ref overview_validator.
|
||||
|
||||
@library{wxcore}
|
||||
|
||||
@@ -377,6 +377,17 @@ bool wxGenericValidator::TransferToWindow()
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!(pControl->GetWindowStyle() & (wxLB_MULTIPLE || wxLB_EXTENDED)),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
pControl->Check(*m_pInt);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
@@ -398,6 +409,17 @@ bool wxGenericValidator::TransferToWindow()
|
||||
for ( i = 0 ; i < count; i++ )
|
||||
pControl->SetSelection(m_pArrayInt->Item(i));
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!(pControl->GetWindowStyle() & (wxLB_MULTIPLE || wxLB_EXTENDED)),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
pControl->SetSelection(*m_pInt);
|
||||
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
@@ -654,6 +676,26 @@ bool wxGenericValidator::TransferFromWindow()
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!(pControl->GetWindowStyle()& (wxLB_MULTIPLE || wxLB_EXTENDED)),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
|
||||
size_t i,
|
||||
count = pControl->GetCount();
|
||||
for ( i = 0; i < count; i++ )
|
||||
{
|
||||
if (pControl->IsChecked(i))
|
||||
{
|
||||
*m_pInt = i;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
@@ -676,6 +718,18 @@ bool wxGenericValidator::TransferFromWindow()
|
||||
m_pArrayInt->Add(i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!(pControl->GetWindowStyle() & (wxLB_MULTIPLE || wxLB_EXTENDED)),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
|
||||
*m_pInt = pControl->GetSelection();
|
||||
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
|
||||
Reference in New Issue
Block a user