//-----------------------------------------------------------------------------
// Purpose: 
// Input  : code - 
//-----------------------------------------------------------------------------
void CBuddyButton::OnMouseReleased(vgui::MouseCode code)
{
	if (m_bDragging)
	{
		// make sure we're over a valid panel
		VPanel *imouseOver = input()->GetMouseOver();
		if (imouseOver)
		{
			Panel *mouseOver = ipanel()->Client(imouseOver)->GetPanel();
			KeyValues *keyVal = new KeyValues("DragDrop", "type", "TrackerFriend");
			keyVal->SetInt("friendID", m_iBuddyID);

			if (mouseOver->RequestInfo(keyVal))
			{
				Panel *acceptPanel = (Panel *)keyVal->GetPtr("AcceptPanel");
				if (acceptPanel)
				{
					PostMessage(acceptPanel, keyVal);
					keyVal = NULL;
				}
			}

			if (keyVal)
			{
				keyVal->deleteThis();
			}
		}

		input()->SetMouseCapture(NULL);
	}

	m_bDragging = false;
	
	BaseClass::OnMouseReleased(code);
}
//-----------------------------------------------------------------------------
// Purpose: Shortcut function to get data in child controls
//-----------------------------------------------------------------------------
int EditablePanel::GetControlInt(const char *controlName, int defaultState)
{
	Panel *control = FindChildByName(controlName);
	if (control)
	{
		KeyValues &data = *(new KeyValues("GetState"));
		if (control->RequestInfo(&data))
		{
			return data.GetInt("state", defaultState);
		}
	}

	return defaultState;
}
//-----------------------------------------------------------------------------
// Purpose: Shortcut function to get data in child controls
//-----------------------------------------------------------------------------
int EditablePanel::GetControlInt(const char *controlName, int defaultState)
{
	Panel *control = FindChildByName(controlName);
	if (control)
	{
		KeyValues *data = new KeyValues("GetState");
		if (control->RequestInfo(data))
		{
			int state = data->GetInt("state", defaultState);
			data->deleteThis();
			return state;
		}
	}
	return defaultState;
}
//-----------------------------------------------------------------------------
// Purpose: Shortcut function to get data in child controls
//-----------------------------------------------------------------------------
void EditablePanel::GetControlString(const char *controlName, char *buf, int bufSize, const char *defaultString)
{
	Panel *control = FindChildByName(controlName);
	KeyValues *data = new KeyValues("GetText");
	if (control && control->RequestInfo(data))
	{
		strncpy(buf, data->GetString("text", defaultString), bufSize - 1);
	}
	else
	{
		// no value found, copy in default text
		strncpy(buf, defaultString, bufSize - 1);
	}

	// ensure null termination of string
	buf[bufSize - 1] = 0;

	// free
	data->deleteThis();
}