예제 #1
0
//*****************************************************************************
void CDbMessageText::ImportText(const char** atts)
//Add a new message text for this language if one does not exist.
{
	//There must be exactly two attribute-value pairs, 'lang' and 'text'.
	if (!atts[0] || !atts[1] || !atts[2] || !atts[3] || atts[4]) return;
	if (strcmp("lang", atts[0]) != 0) return;
	if (strcmp("text", atts[2]) != 0) return;
	if (strlen(atts[3]) == 0) return; //empty text -- do nothing

	//Look whether this message exists in the specified language.
	const Language::LANGUAGE oldLanguage = Language::GetLanguage(), eLanguage = Language::Get(atts[1]);
	Language::SetLanguage(eLanguage);
	const UINT dwFoundRowI = FindMessageText(this->eMessageID, false);
	if (dwFoundRowI != ROW_NO_MATCH)
	{
		//message text already exists -- don't overwrite
		Language::SetLanguage(oldLanguage);
		return;
	}

	ASSERT(!this->bIsDirty); //don't lose any updates to a text in memory
	
	//Add new language version of this message.
	UTF8ToUCS2(atts[3], strlen(atts[3]), this->wstrText);
	AddMessageText(this->eMessageID, this->wstrText.c_str());
	this->bIsLoaded = true;

	Language::SetLanguage(oldLanguage);
}
예제 #2
0
Node* Win32Node::open(const FileName& child)
{
    WideString wpath = m_path;
    wpath += '\\';
    UTF8ToUCS2(wpath, child.str());

    if (GetFileAttributesW(wpath.c_str()) == INVALID_FILE_ATTRIBUTES)
        Win32ThrowLastError("%s", child.c_str());

    Win32Node* node = new Win32Node(child, wpath);
    return node;
}
예제 #3
0
Node* Win32Driver::mount(const FilePath& path, const String& nativePath)
{
    if (nativePath.find('?') != NPOS ||
        nativePath.find('*') != NPOS ||
        nativePath.size() == 0)
    {
        throw InvalidFilePath(nativePath.c_str());
    }

    FileName name = path.fileName();
    WideString wpath;
    UTF8ToUCS2(wpath, nativePath);
    wpath.subst('/', '\\');
    while (wpath.back() == '\\')
        wpath.pop();
    Win32Node* node = new Win32Node(name, wpath);
    return node;
}
예제 #4
0
//******************************************************************************
bool CClipboard::GetString(
//Copies the system clipboard string into sClip
//Returns: true on success, false otherwise.
//
//Params:
	WSTRING& sClip) //(out)
{
#ifdef WIN32
	if (!OpenClipboard(NULL))
		return false;
	HGLOBAL global = GetClipboardData(CF_UNICODETEXT);
	if (global == NULL) {
		CloseClipboard();
		return false;
	}
	LPWSTR data = (LPWSTR)GlobalLock(global);
	sClip = data;
	GlobalUnlock(global);
	CloseClipboard();

	return true;

#elif defined __APPLE__
	PasteboardRef theClipboard;
    	OSStatus err = PasteboardCreate(kPasteboardClipboard, &theClipboard);
	if (err != noErr)
		return false;

	ItemCount itemCount;
	PasteboardSynchronize(theClipboard);
	PasteboardGetItemCount(theClipboard, &itemCount);
	UInt32 itemIndex = 1;

	PasteboardItemID itemID;
	PasteboardGetItemIdentifier(theClipboard, itemIndex, &itemID);

	CFArrayRef flavorTypeArray;
	PasteboardCopyItemFlavors(theClipboard, itemID, &flavorTypeArray);

	CFIndex flavorCount = CFArrayGetCount(flavorTypeArray);

	for (CFIndex flavorIndex = 0; flavorIndex < flavorCount; flavorIndex++)
	{
		CFStringRef flavorType = (CFStringRef)CFArrayGetValueAtIndex(flavorTypeArray, flavorIndex);

		if (UTTypeConformsTo(flavorType, CFSTR("public.utf8-plain-text")))
		{
			CFDataRef flavorData;
			PasteboardCopyItemFlavorData(theClipboard, itemID, flavorType, &flavorData);

			//CFIndex flavorDataSize = CFDataGetLength(flavorData);
 			const string str = (char*)CFDataGetBytePtr(flavorData);
			UTF8ToUCS2(str.c_str(), str.size(), sClip);
			CFRelease(flavorData);
			break;
		}
	}
	CFRelease (flavorTypeArray);

	return true;

#elif defined(__linux__) || defined(__FreeBSD__)
	string u8clip;
	bool bSuccess;
	if ((bSuccess = GetStringUTF8(u8clip)))
		UTF8ToUCS2(u8clip.c_str(), u8clip.length(), sClip);
	return bSuccess;

#elif defined(__native_client__)
	// Do nothing.
	return false;
#else
#error CClipboard::GetString -- Unicode not implemented
#endif
}