void CEmptyStringException::CHECK(WSTRING& string, C_TROUBLESPOT& troublespot) throw()
{
  if (string.empty())
  {
    throw CEmptyStringException(CTroublespot(troublespot).AppendNote(MAKE_NOTE()));
  }
}
Example #2
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();
}
Example #3
0
//*****************************************************************************
void CFileDialogWidget::SelectFile()
//Selects the file selected in the list box.
{
	const WSTRING wFilename = this->pFileListBoxWidget->GetSelectedItemText();
	if (!wFilename.empty())
		this->pFilenameTextBox->SetText(wFilename.c_str());
	CheckTextBox();
}
Example #4
0
void CNamespace::Construct(WSTRING& naming)
{
  if (!naming.empty())
  {
    auto list = SString::SPLIT(naming, L'.');

    for (auto space : list)
    {
      Add(space);
    }
  }
}
Example #5
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;
	}
}
Example #6
0
//*****************************************************************************
bool CHTMLWidget::LoadFile(
//Load a file and parse it.
//
//Params:
	const WCHAR *pwczFileName,    //(in)   File to load, or NULL to load index.
	bool bNewLink,                //(in)   Whether page is new (not from the
	                              //       forward/back lists).
	UINT wScrollY)                //(in)   Pixels to scroll down page initially
	                              //       (ignored if the filename contains a
	                              //        valid in-page anchor reference)
//
//Returns: whether page load was successful.
{
	bool bFullPath = false;

	if (!pwczFileName)
		pwczFileName = this->wstrIndexPage.c_str();  //default = index page
	if (!WCSlen(pwczFileName)) return false;  //empty name

	WSTRING wNewPage = pwczFileName;
	WSTRING wGoToId;
	UINT refpos = (UINT)-1;

	//Very simple path finder
	for (UINT i = WCSlen(pwczFileName); i--;)
	{
		if (pwczFileName[i] == SLASH)
		{
			bFullPath = true;
			this->wstrBasePath = wNewPage.substr(0, i);
			break;
		}
		else if (pwczFileName[i] == '#')
		{
			refpos = i;
			wGoToId = &pwczFileName[i+1];
		}
	}

	if (refpos != (UINT)-1)
		wNewPage = refpos ? wNewPage.substr(0, refpos) : this->wstrCurrentPage;
	if (refpos && !bFullPath)
		wNewPage = this->wstrBasePath + wszSlash + wNewPage;

	if (bNewLink)
	{
		//Add previous page to back list.  Clear forward history.
		GetScrollOffset(this->nOffsetX, this->nOffsetY);
		SHTMLPos prev;
		prev.wstrLink = this->wstrCurrentPage;
		prev.wY = -this->nOffsetY;
		if (!this->wstrCurrentPage.empty())
			this->swstrBackLink.push(prev);
		while (!swstrForwardLink.empty())
			this->swstrForwardLink.pop();
	}

	//Only load if page requested isn't already being shown.
	if (WCScmp(wNewPage.c_str(), this->wstrCurrentPage.c_str()))
	{
		CStretchyBuffer text;
		CFiles files;
		if (!files.ReadFileIntoBuffer(wNewPage.c_str(), text))
			return false;

		this->wstrCurrentPage = wNewPage;
		this->wstrCurrentId = wGoToId;

		VERIFY(Parse(text));  //parse should be successful, but return true in any case
	}

	//Scroll to id or specified Y-position, if possible
	if (this->pParent && this->pParent->GetType() == WT_Scrollable)
	{
		if (!wGoToId.empty())
		{
			HTMLIDMAP::const_iterator idit = mIdmap.find(wGoToId);
			if (idit != mIdmap.end())
				wScrollY = (*idit).second;
		}

		CScrollableWidget *pContainer = DYN_CAST(CScrollableWidget*, CWidget*, this->pParent);
		pContainer->ScrollAbsolute(0, 0);
		pContainer->ScrollDownPixels(wScrollY);
	}

	return true;
}