void Button::AddedToParent()
{
	Component::AddedToParent();
	SetButtonFlags(ButtonFlag_ButtonDown | ButtonFlag_MouseOver,false);

	// Make sure all of the focus issues with the radio buttons are handled.
	// A checked radio wants the focus, and an unchecked radio doesn't want
	// the focus.  However, if no radio in the group is checked then one of
	// the radios should still want the focus.
	if(IsRadio())
	{
		SetCheck(IsChecked());
		bool aRadioWantsFocus = false;
		if(!WantFocus())
		{
			Button *aRadio = GetEndRadio(false);				
			while(aRadio!=NULL)
			{
				if(aRadio->WantFocus())
				{
					aRadioWantsFocus = true;
					break;
				}
				
				aRadio = aRadio->GetNextRadio(true);
			}
			
			if(!aRadioWantsFocus)
				SetComponentFlags(ComponentFlag_WantFocus,true);
		}
	}
}
Button* Button::GetEndRadio(bool forward)
{
	Button *curRadio = this;
	Button *nextRadio = NULL;
	while(true)
	{
		nextRadio = curRadio->GetNextRadio(forward);
		if(nextRadio==NULL)
			return curRadio;
		
		curRadio = nextRadio;
	}	
}
void Button::SetCheck(bool checked, bool sendEvent)
{
	if(IsRadio())
	{
		SetComponentFlags(ComponentFlag_WantFocus,checked);
		if(checked)
		{
			// Make sure all other radio buttons in the group are not checked.
			Button *aRadio = GetEndRadio(false);				
			while(aRadio!=NULL)
			{
				if(aRadio!=this)
				{
					aRadio->SetComponentFlags(ComponentFlag_WantFocus,false);
					if(aRadio->IsChecked())
					{
						aRadio->SetButtonFlags(ButtonFlag_Checked, false);
						aRadio->Invalidate();
					}
				}
				
				aRadio = aRadio->GetNextRadio(true);
			}

			RequestFocus();
		}
	}

	if(sendEvent)
		FireEvent(ComponentEvent_ButtonPressed); // button pressed event
	
	if(IsChecked()==checked)
		return;

	SetButtonFlags(ButtonFlag_Checked, checked);
	Invalidate();
}