Пример #1
0
TFastIni::TFastIni(TStringList *SL) :
    m_LastSectionIndex(-1)
{
    m_Sections = new TList();

    LoadFromString(SL);
}
Пример #2
0
bool cPrefabPiecePool::LoadFromString(const AString & a_Contents, const AString & a_FileName, bool a_LogWarnings)
{
	// If the contents start with GZip signature, ungzip and retry:
	if (a_Contents.substr(0, 3) == "\x1f\x8b\x08")
	{
		AString Uncompressed;
		auto res = UncompressStringGZIP(a_Contents.data(), a_Contents.size(), Uncompressed);
		if (res == Z_OK)
		{
			return LoadFromString(Uncompressed, a_FileName, a_LogWarnings);
		}
		else
		{
			CONDWARNING(a_LogWarnings, "Failed to decompress Gzip data in file %s: %d", a_FileName.c_str(), res);
			return false;
		}
	}

	// Search the first 8 KiB of the file for the format auto-detection string:
	auto Header = a_Contents.substr(0, 8192);
	if (Header.find("CubesetFormatVersion =") != AString::npos)
	{
		return LoadFromCubeset(a_Contents, a_FileName, a_LogWarnings);
	}
	CONDWARNING(a_LogWarnings, "Cannot load prefabs from file %s, unknown file format", a_FileName.c_str());
	return false;
}
BOOL CReportEntityPicture::FromString( const CString& str )
/* ============================================================
	Function :		CReportEntityPicture::FromString
	Description :	Sets the data of the object from "str".
	Access :		Public

	Return :		BOOL				-	"TRUE" if the string
											represents an object 
											of this type.
	Parameters :	const CString& str	-	String to parse
					
	Usage :			Call to load objects from a file.

   ============================================================*/
{

	BOOL result = FALSE;
	CString data( str );
	if( LoadFromString( data ) )
	{

		CTokenizer tok( data );

		double		 borderthickness;
		unsigned int borderstyle;
		unsigned int  bordercolor;
		CString		filename;

		int	count = 0;
		tok.GetAt( count++, borderthickness );
		int aaa;
		tok.GetAt( count++, aaa );
		borderstyle=aaa;
		tok.GetAt( count++, aaa );
		bordercolor=aaa;
		tok.GetAt( count++, filename );

		int bt = CUnitConversion::InchesToPixels( borderthickness );
		SetBorderThickness( bt );
		SetBorderStyle( borderstyle );
		SetBorderColor( bordercolor );
		UnmakeSaveString( filename );

		SetFilename( filename );

		int left = CUnitConversion::InchesToPixels( GetLeft() );
		int right = CUnitConversion::InchesToPixels( GetRight() );
		int top = CUnitConversion::InchesToPixels( GetTop() );
		int bottom = CUnitConversion::InchesToPixels( GetBottom() );

		CRect rect( left, top, right, bottom );
		SetRect( rect );

		result = TRUE;

	}

	return result;

}
Пример #4
0
Image GetImage(PasteClip& clip)
{
	GuiLock __;
	Image m;
	if(Accept<Image>(clip)) {
		LoadFromString(m, ~clip);
		if(!m.IsEmpty())
			return m;
	}
	if(clip.Accept("dib")) {
		String data = ~clip;
		if((unsigned)data.GetCount() < sizeof(BITMAPINFO)) return Null;
		BITMAPINFO *lpBI = 	(BITMAPINFO *)~data;
		BITMAPINFOHEADER& hdr = lpBI->bmiHeader;
		byte *bits = (byte *)lpBI + hdr.biSize;
		if(hdr.biBitCount <= 8)
			bits += (hdr.biClrUsed ? hdr.biClrUsed : 1 << hdr.biBitCount) * sizeof(RGBQUAD);
		if(hdr.biBitCount >= 16 || hdr.biBitCount == 32) {
			if(hdr.biCompression == 3)
				bits += 12;
			if(hdr.biClrUsed != 0)
				bits += hdr.biClrUsed * sizeof(RGBQUAD);
		}
		int h = abs((int)hdr.biHeight);
		ImageDraw   iw(hdr.biWidth, h);
		::StretchDIBits(iw.GetHandle(),
			0, 0, hdr.biWidth, h,
			0, 0, hdr.biWidth, h,
			bits, lpBI, DIB_RGB_COLORS, SRCCOPY);
		return iw;
	}
	return Null;
}
Пример #5
0
	void Shader::LoadFromFile(const ShaderType type, const std::string fname) {
		std::ifstream fp;
		fp.open(fname, std::ios_base::in);
		if (fp.is_open()) {
			std::string buffer(std::istreambuf_iterator<char>(fp), (std::istreambuf_iterator<char>()));
			LoadFromString(type, buffer);
		}
	}
Пример #6
0
void LuaData::Register()
{
	if( !m_bWasSet )
		return;

	LoadFromString( m_sSerializedData, m_bSandboxed );
	m_sSerializedData.erase( m_sSerializedData.begin(), m_sSerializedData.end() );
}
Пример #7
0
bool
NOAAStore::LoadFromProfile()
{
  const TCHAR *stations = Profile::Get(szProfileWeatherStations);
  if (stations == NULL)
    return false;

  return LoadFromString(stations);
}
Пример #8
0
bool
NOAAStore::LoadFromProfile()
{
  const char *stations = Profile::Get(ProfileKeys::WeatherStations);
  if (stations == NULL)
    return false;

  return LoadFromString(stations);
}
Пример #9
0
	bool INI::LoadFromFile(std::string filename)
	{
		std::ifstream file(filename, std::ios::in);
		if (!file) return false;
		std::string data((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
		file.close();
		LoadFromString(data);
		return true;
	}
Пример #10
0
	std::weak_ptr<Shader> Shader::CreateFromString(const std::string name,
		std::list<std::pair<Shader::ShaderType, std::string>> source_code) {
		auto s = std::make_shared<Shader>();
		for (auto pair : source_code) {
			s->LoadFromString(pair.first, pair.second);
		}
		s->Build();
		ShaderMap::Set(name, s);
		return s;
	}
Пример #11
0
bool cPrefabPiecePool::LoadFromFile(const AString & a_FileName, bool a_LogWarnings)
{
	// Read the file into a string buffer, load from string:
	auto contents = cFile::ReadWholeFile(a_FileName);
	if (contents.empty())
	{
		CONDWARNING(a_LogWarnings, "Cannot read data from file %s", a_FileName.c_str());
		return false;
	}
	return LoadFromString(contents, a_FileName, a_LogWarnings);
}
Пример #12
0
// This code reads up the file, discards the bookends, and saves only the gibberish itself.
bool OTASCIIArmor::LoadFrom_ifstream(std::ifstream & fin)
{
	std::stringstream buffer;
	buffer << fin.rdbuf();
	
	std::string contents(buffer.str());
	
	OTString theString;
	theString.Set(contents.c_str());
	
	return LoadFromString(theString);
}
Пример #13
0
TFastIni::TFastIni(AnsiString FN) :
    m_LastSectionIndex(-1)
{
    m_Sections = new TList();

    TStringList *SL = new TStringList();
    if (FileExists(FN)){
        SL->LoadFromFile(FN);
    }

    LoadFromString(SL);

    delete SL;
}
Пример #14
0
 void GLSLShader::LoadFromFile(GLenum whichShader, const string& filename) {
     ifstream fp;
     fp.open(filename.c_str(), ios_base::in);
     if (fp) {
         string line, buffer;
         while (getline(fp, line)) {
             buffer.append(line);
             buffer.append("\r\n");
         }
         LoadFromString(whichShader, buffer);
     }
     else {
         cerr << "Error loading shader: " << filename << endl;
     }
 }
Пример #15
0
void GLSLShader::LoadFromFile(GLenum whichShader, const string& filename){
	ifstream fp;
	fp.open(filename.c_str(), ios_base::in);
	if(fp) {		 
		/*string line, buffer;
		while(getline(fp, line)) {
			buffer.append(line);
			buffer.append("\r\n");
		}		*/
		string buffer(std::istreambuf_iterator<char>(fp), (std::istreambuf_iterator<char>()));
		//copy to source
		LoadFromString(whichShader, buffer);		
	} else {
		cerr<<"Error loading shader: "<<filename<<endl;
	}
}
Пример #16
0
void TextBanner::LoadFromSong( const Song* pSong )
{
	Init();

	CString sDisplayTitle = pSong ? pSong->GetDisplayMainTitle() : CString("");
	CString sTranslitTitle = pSong ? pSong->GetTranslitMainTitle() : CString("");
	CString sDisplaySubTitle = pSong ? pSong->GetDisplaySubTitle() : CString("");
	CString sTranslitSubTitle = pSong ? pSong->GetTranslitSubTitle() : CString("");
	CString sDisplayArtist = pSong ? (CString)ARTIST_PREPEND_STRING + pSong->GetDisplayArtist() : CString("");
	CString sTranslitArtist = pSong ? (CString)ARTIST_PREPEND_STRING + pSong->GetTranslitArtist() : CString("");

	LoadFromString( 
		sDisplayTitle, sTranslitTitle, 
		sDisplaySubTitle, sTranslitSubTitle, 
		sDisplayArtist, sTranslitArtist );
}
Пример #17
0
void Shader::LoadFromFile(GLenum whichShader, const std::string& filename)
{
	ifstream fp(filename, ifstream::in);
	if (fp.is_open()) 
	{
		string line, buffer;
		while (getline(fp, line)) 
		{
			buffer.append(line);
			buffer.append("\r\n");
		}
		//copy to source
		LoadFromString(whichShader, buffer);
	}
	else 
	{
		cerr << "Error loading shader: " << filename << endl;
	}
}
Пример #18
0
BOOL CXmlManager::LoadFromFile( LPCTSTR szfilename )
{
	BOOL ret = FALSE;
	CAtlFile file;
	if(S_OK == file.Create(szfilename, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING) )
	{
		int nsize = ::GetFileSize(file, NULL);
		char* szbuf = new char[nsize + 1];
		if(szbuf)
		{
			if(S_OK == file.Read(szbuf, nsize))
			{
				szbuf[nsize] = 0;
				ret = LoadFromString(szbuf, nsize);
			}
			delete [] szbuf;
		}
	}
	return ret;
}
// This code reads up the file, discards the bookends, and saves only the gibberish itself.
bool OTASCIIArmor::LoadFromFile(const OTString & foldername, const OTString & filename)
{	
	/*
	std::ifstream fin(filename.Get(), std::ios::binary);
		
	if (!fin.is_open())
	{
		OTLog::vError("Error opening file in OTASCIIArmor::LoadFromFile: %s\n", filename.Get());
		return false;
	}

	return LoadFromifstream(fin);	
	 */
	
	OT_ASSERT(foldername.Exists());
	OT_ASSERT(filename.Exists());
	
	// --------------------------------------------------------------------
	
	if (false == OTDB::Exists(foldername.Get(), filename.Get()))
	{
		OTLog::vError("OTASCIIArmor::LoadFromFile: File does not exist: %s%s%s\n", 
					  foldername.Get(), OTLog::PathSeparator(), filename.Get());
		return false;
	}

	// --------------------------------------------------------------------
	//
	OTString strFileContents(OTDB::QueryPlainString(foldername.Get(), filename.Get())); // <=== LOADING FROM DATA STORE.
	
	if (strFileContents.GetLength() < 2)
	{
		OTLog::vError("OTASCIIArmor::LoadFromFile: Error reading file: %s%s%s\n", 
					  foldername.Get(), OTLog::PathSeparator(), filename.Get());
		return false;
	}

	// --------------------------------------------------------------------
	
	return LoadFromString(strFileContents);	
}
Пример #20
0
bool Lua::RunExpression( const CString &str )
{
	if( setjmp(jbuf) )
		RageException::Throw( "Error running \"%s\": %s", str.c_str(), jbuf_error.c_str() );
	lua_State *L = lua_open();
	ASSERT( L );

	lua_atpanic( L, LuaPanic );
	
	luaopen_base( L );
	luaopen_math( L );
	luaopen_string( L );
	lua_settop(L, 0); // luaopen_* pushes stuff onto the stack that we don't need

	Lua::RegisterFunctions( L );

	LoadFromString( L, "return " + str );
	ASSERT_M( lua_gettop(L) == 1, ssprintf("%i", lua_gettop(L)) );

	int ret = lua_pcall(L, 0, 1, 0);
	if( ret )
	{
		CString err;
		Lua::PopStack( L, err );
		RageException::Throw( "Runtime error running \"%s\": %s", str.c_str(), err.c_str() );
	}

	ASSERT_M( lua_gettop(L) == 1, ssprintf("%i", lua_gettop(L)) );

	/* Don't accept a function as a return value; if you really want to use a function
	 * as a boolean, convert it before returning. */
	if( lua_isfunction( L, -1 ) )
		RageException::Throw( "Error running \"%s\": result is a function; did you forget \"()\"?", str.c_str() );

	bool result = !!lua_toboolean( L, -1 );
	lua_pop( L, -1 );

	lua_close( L );

	return result;
}
Пример #21
0
void Shader::LoadFromFile(Type type, std::string filename)
{
	std::string src;
	std::ifstream File(filename, std::ifstream::in);
	
	if (!File.is_open())
	{
		std::cerr <<"Shader Source File does not exist: " <<filename <<"\n";
		return;
	}
	
	while (!File.eof())
	{
		char buf[1024];
		
		File.getline(buf, sizeof(buf));
		src +=buf + std::string("\n");
	}
	
	LoadFromString(type, src);
}
Пример #22
0
/**
* parse primitve. this method parses the values, that are stored inside the Xml-document
* handled by the XmlParser \p p.
* @param p the parser holding the xml document
* @return the Value contained in the xml document
*/
Value XmlRpcParser::ParsePrimitive(XmlParser& p) {
	Value v,vv;
	if(p.IsText()) {
		return Value(p.ReadText());
	}
	for(int i=0;i<7;i++) {
		if(p.Tag(primitives[i])) {
			switch(i) {
			case 0: //string
				v=Value(p.ReadText());
				break;
			case 1: //int
			case 2: //i4
				v = Value(atoi(p.ReadText()));
				break;
			case 3: //boolean
				v = Value((bool)atoi(p.ReadText()));
				break;
			case 4: //double
				v = Value(atof(p.ReadText()));
				break;
			case 5: //dateTime.iso8601
				p.ReadTextE();
				v=Value(Date(1970,1,1));
				break;
			case 6: //base64
				LoadFromString(vv, p.ReadText());
				v = Value(vv);
				break;
			default:
				throw Exc("unexpected Error");
				break;
			}
			p.PassEnd();
			return Value(v);
		}
	}
	throw Exc("unknown primitive");
}
Пример #23
0
BOOL CDiagramPort::FromString(const CString& str) {
	BOOL result = FALSE;
	CString data(str);
	if (LoadFromString(data)) {

		CTokenizer	tok(data);

		int lSerialPort0;
		int lSerialPort1;
		int lUSB;
		int lI2C;
		int lSPI;
		int lEthernet;


		int count = 0;

		tok.GetAt(count++, lSerialPort0);
		tok.GetAt(count++, lSerialPort1);
		tok.GetAt(count++, lUSB);
		tok.GetAt(count++, lI2C);
		tok.GetAt(count++, lSPI);
		tok.GetAt(count++, lEthernet);

		
		this->mSerialPort0 = lSerialPort0;
		this->mSerialPort1 = lSerialPort1;
		this->mUSB = lUSB;
		this->mI2C = lI2C;
		this->mSPI = lSPI;
		this->mEthernet = lEthernet;

		result = TRUE;

	}

	return result;
}
Пример #24
0
// This code reads up the file, discards the bookends, and saves only the gibberish itself.
bool OTASCIIArmor::LoadFromFile(const OTString & foldername, const OTString & filename)
{		
	OT_ASSERT(foldername.Exists());
	OT_ASSERT(filename.Exists());
	// --------------------------------------------------------------------
	if (false == OTDB::Exists(foldername.Get(), filename.Get()))
	{
		OTLog::vError("OTASCIIArmor::LoadFromFile: File does not exist: %s%s%s\n", 
					  foldername.Get(), OTLog::PathSeparator(), filename.Get());
		return false;
	}
	// --------------------------------------------------------------------
	OTString strFileContents(OTDB::QueryPlainString(foldername.Get(), filename.Get())); // <=== LOADING FROM DATA STORE.
	
	if (strFileContents.GetLength() < 2)
	{
		OTLog::vError("OTASCIIArmor::LoadFromFile: Error reading file: %s%s%s\n", 
					  foldername.Get(), OTLog::PathSeparator(), filename.Get());
		return false;
	}
	// --------------------------------------------------------------------
	return LoadFromString(strFileContents);
}
Пример #25
0
BOOL CSkin::LoadFromResource(HINSTANCE hInstance, UINT nResourceID)
{
	HMODULE hModule = hInstance != NULL ? (HMODULE)hInstance : GetModuleHandle( NULL );
	HRSRC hRes = FindResource( hModule, MAKEINTRESOURCE( nResourceID ), MAKEINTRESOURCE( 23 ) );
	
	if ( hRes == NULL ) return FALSE;
	
	CString strBody;
	
	DWORD nSize			= SizeofResource( hModule, hRes );
	HGLOBAL hMemory		= ::LoadResource( hModule, hRes );
	LPTSTR pszOutput	= strBody.GetBuffer( nSize + 1 );
	LPCSTR pszInput		= (LPCSTR)LockResource( hMemory );
	
	while ( nSize-- ) *pszOutput++ = *pszInput++;
	*pszOutput++ = 0;
	
	strBody.ReleaseBuffer();

	CString strPath;
	strPath.Format( _T("%lu$"), (DWORD)hModule );
	
	return LoadFromString( strBody, strPath );
}
Пример #26
0
// This code reads up the file, discards the bookends, and saves only the
// gibberish itself.
bool OTASCIIArmor::LoadFromFile(const String& foldername,
                                const String& filename)
{
    OT_ASSERT(foldername.Exists());
    OT_ASSERT(filename.Exists());

    if (!OTDB::Exists(foldername.Get(), filename.Get())) {
        otErr << "OTASCIIArmor::LoadFromFile: File does not exist: "
              << foldername << "" << Log::PathSeparator() << "" << filename
              << "\n";
        return false;
    }

    String strFileContents(OTDB::QueryPlainString(
        foldername.Get(), filename.Get())); // <=== LOADING FROM DATA STORE.

    if (strFileContents.GetLength() < 2) {
        otErr << "OTASCIIArmor::LoadFromFile: Error reading file: "
              << foldername << Log::PathSeparator() << filename << "\n";
        return false;
    }

    return LoadFromString(strFileContents);
}
Пример #27
0
void FormEdit::UpdateChildCount(int count)
{
	for (int i = 0; i < _Ctrls.GetCount(); ++i)
		_CtrlContainer.RemoveChild(&_Ctrls[i]);

	_Ctrls.Clear();
	_ItemList.Clear();
	_Temporaries.Clear();

	if (!_View.IsLayout())
	{
		UpdateItemList();
		return;
	}

//	if (_ViewMode == VIEW_MODE_WIREFRAME)
//		return;

	for (int i = 0; i < count; ++i)
	{
		if (!_View.GetObject(i))
			continue;

		String type = (*_View.GetObjects())[i].Get("Type");
		Font font = _View.GetFont();
		int h = _View.ZoomY((*_View.GetObjects())[i].GetNumber("Font.Height"));
		if (h != 0) font.Height(h);
		if (font.GetHeight() == 0) font.Height(StdFont().GetHeight());

		_ItemList.AddRow(type, (*_View.GetObjects())[i].Get("Variable"));

		if ((*_View.GetObjects())[i].GetBool("OutlineDraw", false)
			&& _ViewMode != VIEW_MODE_AS_IS)
		{
			if (_ViewMode != VIEW_MODE_WIREFRAME)
				_CtrlContainer.Add( _Ctrls.Create<StaticRect>() );
		}
		else if (type == "Button")
		{
			Button* b = &_Ctrls.Create<Button>();
			b->SetFont(font);
			if (_ViewMode == VIEW_MODE_AS_IS)
				b->SetLabel((*_View.GetObjects())[i].Get("Label"));
			if (_ViewMode != VIEW_MODE_WIREFRAME)
				_CtrlContainer.Add( b->NoWantFocus() );
		}
		else if (type == "DropDate")
		{
			DropDate *b = &_Ctrls.Create<DropDate>();
			b->SetFont(font);
			if (_ViewMode != VIEW_MODE_WIREFRAME)
				_CtrlContainer.Add( b->NoWantFocus() );
		}
		else if (type == "GridCtrl")
		{
			GridCtrl *b = &_Ctrls.Create<GridCtrl>();
			// b->SetFont(font); TODO

#ifdef PLATFORM_WIN32
			b->Chameleon();
#endif

			String src = (*_View.GetObjects())[i].Get("Grid.Columns");
			ReplaceString(src, ";", "\r\n");
			StringStream s;
			s.Open(src);
			IniFile f;
			f.Load(s);

			Vector<String> names = f.EnumNames("Columns");

			for (int j = 0; j < names.GetCount(); ++j)
			{
				int n = ScanInt(names[j]);

				Vector<String> values = f.GetArray("Columns", names[j]);
				if (values.GetCount() != 3)
					continue;

				if (values[1] == "Left") b->AddColumn(values[0]).HeaderAlignCenterLeft();
				else if (values[1] == "Right") b->AddColumn(values[0]).HeaderAlignCenterRight();
				else b->AddColumn(values[0]).HeaderAlignCenter();
			}

			if (_ViewMode != VIEW_MODE_WIREFRAME)
				_CtrlContainer.Add( b->NoWantFocus() );
		}
		else if (type == "EditField")
		{
			EditField *b = &_Ctrls.Create<EditField>();
			b->SetFont(font);
			if (_ViewMode == VIEW_MODE_AS_IS)
				b->SetText((*_View.GetObjects())[i].Get("DefaultData"));
			if (_ViewMode != VIEW_MODE_WIREFRAME)
				_CtrlContainer.Add( b->NoWantFocus() );
		}
		else if (type == "EditInt")
		{
			EditInt *b = &_Ctrls.Create<EditInt>();
			b->SetFont(font);
			if (_ViewMode == VIEW_MODE_AS_IS)
				b->SetText((*_View.GetObjects())[i].Get("DefaultData"));
			if (_ViewMode != VIEW_MODE_WIREFRAME)
				_CtrlContainer.Add( b->NoWantFocus() );
		}
		else if (type == "ProgressBar")
		{
			ProgressIndicator *b = &_Ctrls.Create<ProgressIndicator>();
			b->Set(0, 100);
			if (_ViewMode != VIEW_MODE_WIREFRAME)
				_CtrlContainer.Add( b->NoWantFocus() );
		}
		else if (type == "TabCtrl")
		{
			TabCtrl* e = &_Ctrls.Create<TabCtrl>();
			TabCtrl::Style& style = e->StyleDefault().Write();
			style.font = font;
			style.tabheight = font.GetHeight() + VertLayoutZoom(10);
			e->SetStyle(style);

			String src = (*_View.GetObjects())[i].Get("Tab.Content");
			ReplaceString(src, ";", "\r\n");
			StringStream s;
			s.Open(src);
			IniFile f;
			f.Load(s);

			Vector<String> names = f.EnumNames("Tabs");
			VectorMap<int, Vector<String> > cache;

			int tabCount = 0;
			for (int j = 0; j < names.GetCount(); ++j)
			{
				int n = ScanInt(names[j]);

				if (AsString(n) != names[j])
					continue;

				Vector<String> values = f.GetArray("Tabs", names[j]);
				if (values.GetCount() != 3)
					continue;

				Container *cont = &_Temporaries.Create<Container>();
				Form *f = &_Temporaries.Create<Form>();

					if (values[0] != t_("Current form"))
					{
						if (!f->Load(GetFileDirectory(_File) + "\\" + values[0]))
							continue;
					}
					else
					{
						int lay = _View.HasLayout(values[1]);
						if (lay < 0)
							continue;

						f->GetLayouts().Add() <<= _View.GetLayouts()[lay];
					}

				if (!f->Layout(values[1], font))
					continue;

				cont->Set(*f, f->GetSize());
				cont->SizePos();
				e->Add(*cont, values[2]);

				tabCount++;
			}

			int activeTab = -1;

			if (tabCount)
			{
				activeTab = (*_View.GetObjects())[i].GetNumber("Tab.Active", 0, 0);
				if (activeTab >= tabCount)
				{
					activeTab = tabCount - 1;
					e->Set(activeTab);
				}
				e->Set(activeTab);
			}

			(*_View.GetObjects())[i].SetNumber("Tab.Active", activeTab);
			(*_View.GetObjects())[i].SetNumber("Tab.Count", tabCount);

			if (_ViewMode != VIEW_MODE_WIREFRAME)
				_CtrlContainer.Add( e->NoWantFocus() );
		}
		else if (type == "Form")
		{
			Form f;
			String path = (*_View.GetObjects())[i].Get("Form.Path");
			(*_View.GetObjects())[i].Get("Form.PathType") == "Relative"
				? f.Load(::GetFileDirectory(_File) + "\\" + path)
				: f.Load(path);
			f.Layout((*_View.GetObjects())[i].Get("Form.Layout"), font);
			ImageDraw w(f.GetSize());
			f.DrawCtrl(w);
			ImageBuffer buf(w);
			StaticImage *s = &_Ctrls.Create<StaticImage>();
			s->SetImage(buf);

			if (_ViewMode != VIEW_MODE_WIREFRAME)
				_CtrlContainer.AddChild( s );
		}
		else
		{
			Label *b = &_Ctrls.Create<Label>();
			b->SetFont(font);
			Color fontColor = DefaultInk();
			LoadFromString(fontColor, Decode64((*_View.GetObjects())[i].Get("Font.Color",
				StoreAsString(fontColor))));
			b->SetInk(fontColor);
			String align = (*_View.GetObjects())[i].Get("Text.Align");
			if (align == "Center") b->SetAlign(ALIGN_CENTER);
			if (align == "Right") b->SetAlign(ALIGN_RIGHT);
			if (align == "Left") b->SetAlign(ALIGN_LEFT);
			if (_ViewMode == VIEW_MODE_AS_IS)
				b->SetLabel((*_View.GetObjects())[i].Get("Label"));
			if (_ViewMode != VIEW_MODE_WIREFRAME)
				_CtrlContainer.Add( b->NoWantFocus() );
		}

		String frame = (*_View.GetObjects())[i].Get("Frame");
		Ctrl* c = NULL;
		if (_Ctrls.GetCount())
			c = &_Ctrls[_Ctrls.GetCount() - 1];

		if (c)
		{
			if (frame == "Null frame")             c->SetFrame(NullFrame());
			if (frame == "Field frame")            c->SetFrame(FieldFrame());
			if (frame == "Inset frame")            c->SetFrame(InsetFrame());
			if (frame == "Outset frame")           c->SetFrame(OutsetFrame());
			if (frame == "Thin inset frame")       c->SetFrame(ThinInsetFrame());
			if (frame == "Thin outset frame")      c->SetFrame(ThinOutsetFrame());
			if (frame == "Black frame")            c->SetFrame(BlackFrame());
			if (frame == "Button frame")           c->SetFrame(ButtonFrame());
			if (frame == "Top separator frame")    c->SetFrame(TopSeparatorFrame());
			if (frame == "Left separator frame")   c->SetFrame(LeftSeparatorFrame());
			if (frame == "Right separator frame")  c->SetFrame(RightSeparatorFrame());
			if (frame == "Bottom separator frame") c->SetFrame(BottomSeparatorFrame());
		}
	}

	UpdateItemList();
	UpdateChildAllPos();
}
Пример #28
0
void PropertiesWindow::Generate(FormObject* pI, int index)
{
	if (!pI) return;

	_Properties.Clear();
	_Options.Clear();

	_Item  = pI;
	_Index = index;

	String type = pI->Get("Type");
	if (type.IsEmpty()) return;

	Property("Variable", t_("Variable:"), "EditField", Array<String>() << pI->Get("Variable"));

	if (_Headers.GetRowCount() != 1)
	{
		_Headers.Clear();
		_Headers.AddRow(t_("Type:"), type);
	}

	Property("Font.Height", t_("Font height:"), "EditInt", Array<String>()
		<< AsString(pI->GetNumber("Font.Height", 0, 0, 500)));

	if (type == "EditField")
	{
		Property("Style", t_("Style:"), "DropList", Array<String>()
			<< pI->Get("Style") << "Text Field" << "Password");
		Property("TextAlign", t_("Text align:"), "DropList",
			Array<String>() << pI->Get("TextAlign") << "Left" << "Right");
		Property("Tip", t_("Tip:"), "EditField", Array<String>() << pI->Get("Tip"));
		Property("NotNull", t_("Not null:"), "Option", Array<String>() << pI->Get("NotNull",
			"0"));
	}

	if (type == "EditInt")
	{
		Property("Min", t_("Min:"), "EditInt", Array<String>() << pI->Get("Min"));
		Property("Max", t_("Max:"), "EditInt", Array<String>() << pI->Get("Max"));
		Property("Tip", t_("Tip:"), "EditField", Array<String>() << pI->Get("Tip"));
		Property("NotNull", t_("Not null:"), "Option", Array<String>() << pI->Get("NotNull",
			"0"));
	}

	if (type == "Label")
	{
		Color src = DefaultInk();
		LoadFromString( src, Decode64(pI->Get("Font.Color", Encode64(StoreAsString(src)))) );
		Property("Label", t_("Label:"), "EditField", Array<String>() << pI->Get("Label"));
		Property("Text.Align", t_("Text align:"), "DropList",
			Array<String>() << pI->Get("Text.Align") << "Left" << "Center" << "Right");
		Property("Font.Color", t_("Font color:"), "EditColor", src);
	}

	if (type == "Button")
	{
		Property("Label", t_("Label:"), "EditField", Array<String>() << pI->Get("Label"));
		Property("Action", t_("Action:"), "EditField", Array<String>() << pI->Get("Action"));
		Property("Tip", t_("Tip:"), "EditField", Array<String>() << pI->Get("Tip"));
	}

	if (type == "Form")
	{
		Property("Form.PathType", t_("Type of path:"), "DropList",
			Array<String>() << pI->Get("Form.PathType") << "Relative" << "Absolute");
		Property("Form.Path", t_("Path:"), "EditField", Array<String>() << pI->Get("Form.Path"));
		Property("Form.Layout", t_("Layout:"), "EditField", Array<String>() << pI->Get("Form.Layout"));
	}

	if (type == "TabCtrl")
	{
		Property("Tab.Content", t_("Tabs:"), "EditTabs", Array<String>()
			<< pI->Get("Tab.Content", "[Tabs];"));
	}

	if (type == "GridCtrl")
	{
		Property("Grid.Columns", t_("Columns:"), "EditColumns", Array<String>()
			<< pI->Get("Grid.Columns", "[Columns];"));
	}

	Property("Frame", t_("Frame:"), "DropList",
		Array<String>()
			<< pI->Get("Frame")
			<< "Default frame"
			<< "Null frame"
			<< "Top separator frame"
			<< "Left separator frame"
			<< "Right separator frame"
			<< "Bottom separator frame"
			<< "Field frame"
			<< "Inset frame"
			<< "Outset frame"
			<< "Thin inset frame"
			<< "Thin outset frame"
			<< "Black frame"
			<< "Button frame");

	_Options.HideRow(0);
	_Headers.SetCursor(0);
	_Headers.StartEdit();
	_Options.SetCursor(0);
}
Пример #29
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Operand* ConstantFolder::LoadFromOffset(Initializer* initializer, const Type* sourceType,
										const Type* loadType, __int64 offset) {
	DebugValidator::IsNotNull(initializer);
	DebugValidator::IsLargerOrEqual(offset, 0);

	// If the initializer is an initializer list, try to see at which position
	// the initializer indicated by the offset is found.
	if(initializer->IsInitializerList()) {
		auto initList = static_cast<InitializerList*>(initializer);
		
		if(auto arrayType = sourceType->As<ArrayType>()) {
			// If it's an array type we can compute the index directly.
			auto elementType = arrayType->ElementType();
			__int64 elemSize = TypeInfo::GetSize(elementType, target_);
			__int64 childIndex = offset / elemSize;
			DebugValidator::IsSmaller(childIndex, arrayType->Size());

			// We need to test for the case in which the offset lies between
			// two elements in an array. Consider the following case:
			// const int a[] = {1,2,3,4};
			// *((short*)((char*)a + 3)) - data from both 1 and 2 is loaded.
			if((elementType->IsArray() || elementType->IsRecord()) == false) {
				__int64 childOffset = offset % elemSize;
				__int64 loadSize = TypeInfo::GetSize(loadType, target_);

				// Note that this also catches the case when the data to be loaded
				// is larger than the size of the array element.
				if((childOffset + loadSize) > elemSize) {
					return LoadFromMultipleArray(initList, childIndex, childOffset,
												 arrayType, loadType);
				}
			}

			return LoadFromOffset((*initList)[childIndex], arrayType->ElementType(),
								  loadType, offset - (childIndex * elemSize));
		}
		else if(auto recordType = sourceType->As<RecordType>()) {
			// For records we need to iterate all the fields 
			// until we find a suitable one.
			auto& fields = recordType->Fields();

			for(int i = 0; i < fields.Count(); i++) {
				const RecordField& field = fields[i];
				__int64 fieldOffset = field.FieldOffset;
				__int64 fieldSize = TypeInfo::GetSize(field.FieldType, target_);

				if(offset < (fieldOffset + fieldSize)) {
					// If we need to load from two fields we give up; most of the time
					// it can't be performed (there may be padding between fields),
					// it would be complicated and this situation shouldn't actually
					// occur in a standard-conforming application.
					__int64 loadSize = TypeInfo::GetSize(loadType, target_);

					if((offset + loadSize) > (fieldOffset + fieldSize)) {
                        return nullptr;
                    }

					return LoadFromOffset((*initList)[i], field.FieldType, 
										  loadType, offset - fieldOffset);
				}
			}
		}

		// The offset is invalid, give up.
		return nullptr;
	}

	if(initializer->Conversion() == InitConv_PointerToPointer) {
		// Frequently used for strings, like in the following example:
		// var a int8* = ptop("abcd", int8*)
		if(auto stringConst = initializer->Value()->As<StringConstant>()) {
			return LoadFromString(stringConst, loadType, offset);
		}

		// All other cases are not supported.
		return nullptr;
	}

	// We should load the operand from the initializer.
	return LoadFromInitializer(initializer, loadType, offset);
}
Пример #30
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Operand* ConstantFolder::LoadFromInitializer(Initializer* initializer, const Type* loadType, 
											 __int64 offset) {
	DebugValidator::IsFalse(initializer->IsInitializerList());
	bool isNull = false;
	bool isZero = false;
	
	// We may be loading from string constant.
	if(auto stringConst = initializer->Value()->As<StringConstant>()) {
		return LoadFromString(stringConst, loadType, offset);
	}

	// Exclude initializers that have an incompatible conversion.
	if(initializer->Conversion() == InitConv_PointerToInt) {
		if(initializer->Value()->IsNullConstant()) {
			isZero = true;
		}
		else {
			// Definitely not a constant operand.
			return nullptr;
		}
	}
	else if((initializer->Conversion() == InitConv_PointerToPointer) ||
			(initializer->Conversion() == InitConv_IntToPointer)) {
		if(initializer->Value()->IsNullConstant() || MatchInt(0)(initializer->Value())) {
			isNull = true;
		}
		else {
			// Definitely not a constant operand.
			return nullptr;
		}
	}

	// It's undefined behavior if we try to load from a null pointer.
	if(isNull) {
        return GetNullptr(loadType);
    }
	else if(isZero) {
        return GetZeroInt(loadType);
    }

	// Obtain the value from the initializer. If the offset is not 0, or the
	// types don't match, we must extract the value.
	// Not that we give up if we are requested to extract a value that is larger
	// than the one in the initializer, or if the offset is too large.
	Operand* value = initializer->Value();
	auto valueType = value->GetType();

	if((offset == 0) && (loadType == initializer->Value()->GetType())) {
		return initializer->Value();
	}
	else if((offset > TypeInfo::GetSize(valueType, target_)) ||
		    (TypeInfo::GetSize(loadType, target_) > 
			 TypeInfo::GetSize(valueType, target_))) {
		// This is undefined behavior, because we want to read something that is 
		// in memory located after the operand, and there are no constraints
		// on the way global variables are laid out int memory.
		return GetUndefined(loadType);
	}
	
    return ExtractFromOperand(value, loadType, offset);
}