示例#1
0
//static
void TBRadioCheckBox::UpdateGroupWidgets(TBWidget *new_leader)
{
	assert(new_leader->GetValue() && new_leader->GetGroupID());

	// Find the group root widget.
	TBWidget *group = new_leader;
	while (group && !group->GetIsGroupRoot() && group->GetParent())
		group = group->GetParent();

	for (TBWidget *child = group; child; child = child->GetNextDeep(group))
		if (child != new_leader && child->GetGroupID() == new_leader->GetGroupID())
			child->SetValue(0);
}
void TBRadioCheckBox::SetValue(int value)
{
	if (m_value == value)
		return;
	m_value = value;

	SetState(WIDGET_STATE_SELECTED, value ? true : false);

	Invalidate();
	TBWidgetEvent ev(EVENT_TYPE_CHANGED);
	InvokeEvent(ev);

	if (!value || !GetGroupID())
		return;
	// Toggle all other widgets in the same group. First get a root widget
	// for the search.
	TBWidget *group = this;
	while (group && !group->GetIsGroupRoot())
		group = group->GetParent();
	if (group)
	{
		ToggleGroup(group, this);
	}
}