예제 #1
0
//*****************************************************************************
UINT CDrodFileDialogWidget::GetExtensionType(const WSTRING& wFilename)
//Determine file type based on file name extension.
{
	UINT ext;
	for (ext = 0; ext < FileExtension::EXT_COUNT; ++ext)
	{
		WSTRING wstrExt = wszPeriod;
		wstrExt += g_pTheDB->GetMessageText(fileExtension[ext]);
		if (!WCSicmp(wFilename.c_str() + WCSlen(wFilename.c_str()) - wstrExt.size(), wstrExt.c_str()))
		{
			//Recognized file extension.
			return ext;
		}
	}

	//On older OSes, only 3-character extensions are recognized.
	//If none of the above matches worked, try matching against shortened extensions.
	for (ext = 0; ext < FileExtension::EXT_COUNT; ++ext)
	{
		WSTRING wstrExt = wszPeriod;
		wstrExt += g_pTheDB->GetMessageText(fileExtension[ext]);
		if (wstrExt.length() > 4) //don't retest extensions that were already short enough
		{
			wstrExt.resize(4); //.ext
			if (!WCSicmp(wFilename.c_str() + WCSlen(wFilename.c_str()) - wstrExt.size(), wstrExt.c_str()))
			{
				//Recognized file extension.
				return ext;
			}
		}
	}

	return FileExtension::EXT_COUNT; //extension not recognized
}
예제 #2
0
//******************************************************************************
bool CClipboard::SetString(
//Copies the given string into the system clipboard
//Returns: true on success, false otherwise.
//
//Params:
	const WSTRING& sClip)  //(in)
{
#ifdef WIN32
	if (!OpenClipboard(NULL))
		return false;
	EmptyClipboard();

	HGLOBAL global = GlobalAlloc(GMEM_ZEROINIT, (sClip.size()+1)*sizeof(WCHAR));

	if (global == NULL) {
		CloseClipboard();
		return false;
	}

	LPWSTR data = (LPWSTR)GlobalLock(global);

	WCScpy(data, sClip.c_str());

	GlobalUnlock(global);
	SetClipboardData(CF_UNICODETEXT, global);
	CloseClipboard();

	return true;
#elif defined(__APPLE__)
	PasteboardRef theClipboard;
    	OSStatus err = PasteboardCreate(kPasteboardClipboard, &theClipboard);
	if (err != noErr)
		return false;
	PasteboardClear(theClipboard);
	PasteboardSynchronize(theClipboard);
	BYTE *pbOutStr = NULL;
	if (to_utf8(sClip.c_str(), pbOutStr)) {
		CFDataRef data = CFDataCreate(kCFAllocatorDefault, (UInt8*)pbOutStr, sClip.size() + 1);
		PasteboardPutItemFlavor(theClipboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), data, 0);
	}
	delete[] pbOutStr;
	return true;
#elif defined(__linux__) || defined(__FreeBSD__)
	bool bSuccess = false;
	BYTE *pbOutStr = NULL;
	if (to_utf8(sClip.c_str(), pbOutStr))
		bSuccess = SetStringUTF8((const char*)pbOutStr);
	delete[] pbOutStr;
	return bSuccess;

#elif defined(__native_client__)
	return false;
#else
#error CClipboard::SetString -- Unicode not implemented
#endif
}
예제 #3
0
//*****************************************************************************
WSTRING CFileDialogWidget::GetSelectedFileName() const
//Returns: the full file name
{
	WSTRING filename = this->dirpath;
	filename += wszSlash;
	filename += this->pFilenameTextBox->GetText();

	//Add extension if it's missing.
	WSTRING ext;
	UINT i;
	for (i=0; i<pExtensionListBoxWidget->GetItemCount(); ++i)
	{
		ext = wszPeriod;
		ext += this->extensions[pExtensionListBoxWidget->GetKeyAtLine(i)];
		if (!WCSicmp(filename.c_str() + WCSlen(filename.c_str()) - ext.size(), ext.c_str()))
			break;
	}
	if (i==pExtensionListBoxWidget->GetItemCount())
	{
		//Extension is missing.  Add the selected one.
		ext = wszPeriod;
		ext += this->extensions[pExtensionListBoxWidget->GetSelectedItem()];
		filename += ext.c_str();
	}

	return filename;
}
예제 #4
0
//*****************************************************************************
void CFileDialogWidget::GoToDirectory()
//Go to selected directory.
{
	const WSTRING wstrDirname = this->pDirListBoxWidget->GetSelectedItemText();
	if (wstrDirname.empty()) return; //nothing is selected
	if (!WCScmp(wszParentDir,wstrDirname.c_str()))
	{
		//Go up a directory.
		const int nSlashLoc=this->dirpath.rfind(wszSlash);
		if (nSlashLoc<0)
			this->dirpath.resize(0);
#ifndef WIN32
		else if (nSlashLoc == 0)
			this->dirpath.resize(1); // go to root dir
#endif
		else
			this->dirpath.resize(nSlashLoc);
#if defined(WIN32) || defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
	} else if (wstrDirname[0] == W_t('[')) {
		//Switch drives.
		WSTRING newDrive = wstrDirname.c_str() + 2;
		newDrive.resize(newDrive.size()-2);
		SetDirectory(newDrive.c_str());
		return;
#endif
	} else {
		//Go down a directory.
		if (this->dirpath.c_str() &&
				(this->dirpath.c_str()[this->dirpath.length()-1] != wszSlash[0]))
			this->dirpath += wszSlash;
		this->dirpath += wstrDirname;
	}

	SetDirectory();
}
예제 #5
0
//*****************************************************************************
vector<WSTRING> CFileDialogWidget::GetSelectedFileNames() const
//Returns: a vector of full file names
{
	vector<WSTRING> wFilenames = this->pFileListBoxWidget->GetSelectedItemTexts();
	if (wFilenames.empty())
	{
		//No files selected, so use the written text only.
		wFilenames.push_back(GetSelectedFileName());
		return wFilenames;
	}

	for (vector<WSTRING>::iterator wFilename = wFilenames.begin();
			wFilename != wFilenames.end(); ++wFilename)
	{
		WSTRING filename = this->dirpath;
		filename += wszSlash;
		filename += *wFilename;

		//Add extension if it's missing.
		WSTRING ext;
		UINT i;
		for (i=0; i<pExtensionListBoxWidget->GetItemCount(); ++i)
		{
			ext = wszPeriod;
			ext += this->extensions[pExtensionListBoxWidget->GetKeyAtLine(i)];
			if (!WCSicmp(filename.c_str() + WCSlen(filename.c_str()) - ext.size(), ext.c_str()))
				break;
		}
		if (i==pExtensionListBoxWidget->GetItemCount())
		{
			//Extension is missing.  Add the selected one.
			ext = wszPeriod;
			ext += this->extensions[pExtensionListBoxWidget->GetSelectedItem()];
			filename += ext.c_str();
		}

		(*wFilename) = filename;
	}

	return wFilenames;
}
예제 #6
0
Uint32 CHTMLWidget::TranslateColor(
//Returns: SDL numeric color value
//
//Params:
	SDL_Surface *pSurface,  //(in)
	const WSTRING& wstr)  //string of hex RGB values (i.e. "ffffff")
const
{
	//Skip '#', or any other non-hex chars at front of string
	UINT wIndex = 0;
	while (!iswxdigit(wstr[wIndex]))
		++wIndex;

	//Convert hex chars to byte values.
	ASSERT(wstr.size() - wIndex == 6);
	const BYTE nR = getXdigit(wstr[wIndex]) * 16 + getXdigit(wstr[wIndex+1]);
	const BYTE nG = getXdigit(wstr[wIndex+2]) * 16 + getXdigit(wstr[wIndex+3]);
	const BYTE nB = getXdigit(wstr[wIndex+4]) * 16 + getXdigit(wstr[wIndex+5]);

	return SDL_MapRGB(pSurface->format, nR, nG, nB);
}
예제 #7
0
//*****************************************************************************
void CHTMLWidget::StartElement(
//Expat callback function: Process XML start tag, and attributes.
//
//Params:
	const XML_Char *name, const XML_Char **atts)
{
	//Get tag type (assume no special chars).
	const HTMLTagType eTagType = ParseTag(name);

	if (wstrBuffer.length()) Flush();

	++aeTagLevel[eTagType];

	//Get id/name attribute
	{
		static const WCHAR wszID[] = {We('i'),We('d'),We(0)};
		static const WCHAR wszNAME[] = {We('n'),We('a'),We('m'),We('e'),We(0)};
		WSTRING tmp = GetAttr(wszID, atts);
		if (tmp.empty())
			tmp = GetAttr(wszNAME, atts);
		if (!tmp.empty())
			mIdmap.insert(std::make_pair(tmp, this->wY));
	}

	switch (eTagType)
	{
		case BODY_Tag:
		{
			static const WCHAR wszBgcolor[] = {We('b'),We('g'),We('c'),We('o'),We('l'),We('o'),We('r'),We(0)};
			WSTRING bgcolor = GetAttr(wszBgcolor, atts);
			if (bgcolor.size())
				this->wstrBGColor = bgcolor;
			break;
		}
		case UL_Tag:
		case OL_Tag:
			this->swOLstack.push(this->wOLcounter);
			this->wOLcounter = (eTagType == OL_Tag ? 1 : 0);
			this->wMargin += LISTINDENT;
			NewLine(this->swOLstack.size() == 1);
			break;
		case H1_Tag:
		case H2_Tag:
		case H3_Tag:
			NewLine();
			break;
		case TITLE_Tag:
			wstrTitle = wszEmpty;
			break;
		case A_Tag:
			swstrLink.push(GetAttr(wszHREF, atts));
			break;
		case B_Tag:
			break;
		case HR_Tag:
		case BR_Tag:
			NewLine(true);
			break;
		case IMG_Tag:
		{
			static const WCHAR wszSrc[] = {We('s'),We('r'),We('c'),We(0)};
			WSTRING imageURL = this->wstrBasePath;
			imageURL += wszSlash;
			imageURL += GetAttr(wszSrc, atts);
			CImageWidget *pImage = new CImageWidget(0, this->wX + this->wMargin, this->wY, imageURL.c_str());
			ASSERT(pImage);
			AddWidget(pImage);
			this->wY += pImage->GetH();
			this->wX = 0;  //next thing goes on new line
			break;
		}
		case P_Tag:
			this->wY += static_cast<UINT>(g_pTheFM->GetFontLineHeight(FONTLIB::F_Text) * 2/3);
			break;
		case LI_Tag:
		{
			//Use image as bullet in stead ?
			static const WCHAR wszItem[] = {We('*'),We(' '),We(0)};
			NewLine();
			if (this->wOLcounter)
			{
				WCHAR wszBuf[33];
				wstrBuffer = (WSTRING)_itow(this->wOLcounter, wszBuf, 10)
					+ wszPeriod + wszSpace;
				++this->wOLcounter;
			}
			else wstrBuffer = wszItem;
			Flush(true);
			this->bSkipSpace = true;
			break;
		}
		case TABLE_Tag:
			NewLine();
			vwColumns.clear();
			//Fall through
		case TR_Tag:
			this->wCurrentColumn = 0;
			break;
		case TD_Tag:
		{
			if (this->wCurrentColumn >= vwColumns.size())
			{
				static const WCHAR wszWidth[] = {We('w'),We('i'),We('d'),We('t'),We('h'),We(0)};
				WSTRING wstrWidthAttr = GetAttr(wszWidth, atts);
				this->wTDWidth = wstrWidthAttr.length() > 0 ?
					_Wtoi(wstrWidthAttr.c_str()) : 0;
				vwColumns.push_back(this->wX += 32);
			}
			else
			{
				this->wX = vwColumns[this->wCurrentColumn];
				this->wTDWidth = 0;
			}
			++this->wCurrentColumn;
			this->bSkipSpace = true;
			break;
		}
		default:
			break;
	}
}