bool TBClipboard::GetText(TBStr &text)
{
	if (GLFWwindow *window = glfwGetCurrentContext())
	{
		if (const char *str = glfwGetClipboardString(window))
			return text.Set(str);
	}
	return false;
}
Exemple #2
0
void TBValue::SetFromStringAuto(const char *str, SET set)
{
	if (!str)
		SetNull();
	else if (is_number_only(str))
	{
		if (is_number_float(str))
			SetFloat((float)atof(str));
		else
			SetInt(atoi(str));
	}
	else if (is_start_of_number(str) && contains_non_trailing_space(str))
	{
		// If the number has nontrailing space, we'll assume a list of numbers (example: "10 -4 3.5")
		SetNull();
		if (TBValueArray *arr = new TBValueArray)
		{
			TBStr tmpstr;
			char *s3;
			if (tmpstr.Set(str))
			{
				char * pch = strtok_r(tmpstr, ", ", &s3);
				while (pch)
				{
					if (TBValue *new_val = arr->AddValue())
						new_val->SetFromStringAuto(pch, SET_NEW_COPY);
					pch = strtok_r(NULL, ", ", &s3);
				}
			}
			SetArray(arr, SET_TAKE_OWNERSHIP);
		}
	}
	else if (*str == '[')
	{
		SetNull();
		if (TBValueArray *arr = new TBValueArray)
		{
			assert(!"not implemented! Split out the tokenizer code above!");
			SetArray(arr, SET_TAKE_OWNERSHIP);
		}
	}
	else
	{
		SetString(str, set);
		return;
	}
	// We didn't set as string, so we might need to deal with the passed in string data.
	if (set == SET_TAKE_OWNERSHIP)
	{
		// Delete the passed in data
		TBValue tmp;
		tmp.SetString(str, SET_TAKE_OWNERSHIP);
	}
}
bool TBClipboard::GetText(TBStr &text)
{
    bool success = false;
    if (HasText() && OpenClipboard(NULL))
    {
        if (HANDLE hClipboardData = GetClipboardData(CF_UNICODETEXT))
        {
            wchar_t *pchData = (wchar_t*) GlobalLock(hClipboardData);
            int len = WideCharToMultiByte(CP_UTF8, 0, pchData, -1, NULL, 0, NULL, NULL);
            if (char *utf8 = new char[len])
            {
                WideCharToMultiByte(CP_UTF8, 0, pchData, -1, utf8, len, NULL, NULL);
                success = text.Set(utf8);
                delete [] utf8;
            }
            GlobalUnlock(hClipboardData);
        }
        CloseClipboard();
    }
    return success;
}
Exemple #4
0
bool TBClipboard::GetText(TBStr &text)
{
	return text.Set(clipboard);
}
Exemple #5
0
bool TBClipboard::SetText(const char *text)
{
	return clipboard.Set(text);
}