bool
ESSimpleRenderView::AddTextStyle(_string sName, const _string sFontName, bool bItalic, bool bUnderLine, bool bBold, int nFontHeight){
	ESSimpleRenderView_TextStyle* pStyle	= new ESSimpleRenderView_TextStyle();
	pStyle->m_bItalic						= bItalic;
	pStyle->m_bUnderLine					= bUnderLine;
	pStyle->m_bBold							= bBold;
	pStyle->m_nFontHeight					= nFontHeight;
	pStyle->m_sStyleName					= sName;
	pStyle->m_sFontName						= sFontName;

	LOGFONT lf;
	memset(&lf, 0, sizeof(LOGFONT));
	lf.lfHeight			= nFontHeight;
	_tcscpy(lf.lfFaceName, sFontName.c_str());
	lf.lfWeight			= bBold ? FW_BOLD : FW_NORMAL;
	lf.lfCharSet		= ANSI_CHARSET;
	lf.lfItalic			= bItalic;
	lf.lfUnderline		= bUnderLine;
	lf.lfStrikeOut		= 0;
	lf.lfQuality		= PROOF_QUALITY;
	lf.lfPitchAndFamily = DEFAULT_PITCH;
	pStyle->m_font.CreateFontIndirect(&lf);

	m_listTextStyles.Add(pStyle);
	return true;
	}
bool
ESSimpleRenderView::AddImage(_string sStyleName, _Size szImage, float fCX, float fPosX, int nVAlign, int nHAlign, bool bRedraw){
	ESSimpleRenderView_ImageStyle* pStyle = (ESSimpleRenderView_ImageStyle*)GetImageStyleByName(sStyleName.c_str());
	if( !pStyle ) return false;
	if( !m_pLastLine ){
		m_pLastLine				= new RenderLine();
		m_pRootLine->m_pNextLine= m_pLastLine;
		}

	RenderItemImage* pItemNew	= new RenderItemImage();
	pItemNew->m_pLine			= m_pLastLine;
	pItemNew->m_pStyle			= pStyle;
	pItemNew->m_nVAlign			= nVAlign;
	pItemNew->m_nHAlign			= nHAlign;
	pItemNew->m_szItem			= szImage;
	pItemNew->m_fPosX			= fPosX;
	pItemNew->m_fCX				= fCX;

	if( szImage.cx <= 0 || szImage.cy <= 0 )
		pItemNew->m_szItem	= pStyle->m_szImage;
	else
		pItemNew->m_szItem	= szImage;

	RenderItem* pItem = m_pLastLine->m_pFirstItem;
	if( pItem ){
		while(pItem->m_pNext)
			pItem = pItem->m_pNext;
		pItem->m_pNext		= pItemNew;
		pItemNew->m_pPrev	= pItem;
		}
	else
		m_pLastLine->m_pFirstItem = pItemNew;

	int nHeightOld		= m_pLastLine->m_szLine.cy; 
	CalcLineSize(m_pLastLine);
	m_nContentHeight	+= m_pLastLine->m_szLine.cy;
	m_nTopFullOffsetY	= 0;
	m_szView.cy			= m_nContentHeight;
	if( IsCreated() )
		AdjustScrollBarPos(false);
	return true;
	}
void
ESSimpleRenderView::AddText(_string sStyleName, _string sText, bool bLineBreak, COLORREF crText, _Size szText, float fCX, float fPosX /*= 0.0f*/, int nVAlign, int nHAlign, bool bRedraw){
	ESSimpleRenderView_TextStyle* pStyle = (ESSimpleRenderView_TextStyle*)GetTextStyleByName(sStyleName.c_str());
	if( !pStyle ) return;
	/*
	if( !m_pLastLine ){
		m_pLastLine					= new RenderLine();
		m_pRootLine->m_pNextLine	= m_pLastLine;
		m_pLastLine->m_bLineBreak	= bLineBreak;
		bLineBreak					= false;
		}*/

	CStringArray arrStrings;
	StringHelper::Split(&sText, _T("\r\n"), arrStrings);

	RenderItemText* pItemNew	= NULL;
	RenderItem*		pItemPrev	= NULL;
	RenderLine*		pLine		= m_pLastLine;
	bool			bNewLine	= false;

	if( !pLine || pLine->m_bLineBreak ){
		RenderLine* pNewLine	= new RenderLine();
		pNewLine->m_pPrevLine	= pLine;

		if( !pLine ){
			m_pLastLine					= pNewLine;
			m_pRootLine->m_pNextLine	= m_pLastLine;
			m_pLastLine->m_bLineBreak	= bLineBreak;
			}
		else{
			pLine->m_pNextLine			= pNewLine;
			}

		pLine					= pNewLine;
		bNewLine				= true;
		}

	pItemPrev = pLine->m_pFirstItem;
	if( pItemPrev ){
		while(pItemPrev->m_pNext)
			pItemPrev = pItemPrev->m_pNext;
		}

	int nHeightOld	= pLine->m_szLine.cy; 
	for(int i=0; i<arrStrings.size(); i++){
		RenderItemText* pItemNew	= new RenderItemText();
		pItemNew->m_pLine			= pLine;
		pItemNew->m_pStyle			= pStyle;
		pItemNew->m_sText			= arrStrings.at(i);
		pItemNew->m_sTextLocal		= pItemNew->m_sText;
		ESLocalizationMan::ParseText(pItemNew->m_sTextLocal);
		pItemNew->m_nHAlign			= nHAlign;
		pItemNew->m_nVAlign			= nVAlign;
		pItemNew->m_crText			= crText;
		pItemNew->m_fPosX			= fPosX;
		pItemNew->m_fCX				= fCX;

		pStyle->m_font.GetTextSize(&pItemNew->m_sTextLocal, pItemNew->m_szText);
		pItemNew->m_szItem			= pItemNew->m_szText;
		pItemNew->m_szItem.cy		+= 2*m_nTextMarginTopBottom;
		
		if( i > 0 ){
			// Break line on previous item.
			pItemPrev->m_bBreakLine	= true;
			// Set offset of item.
			pItemNew->m_ptOffset.SetPoint(0, pLine->m_szLine.cy);
			// Set size of line height.
			pLine->m_szLine.cy		+= pItemNew->m_szText.cy;
			}
		else{
			pLine->m_szLine.cx		+= pItemNew->m_szItem.cx;
			pLine->m_szLine.cy		= std::max(pLine->m_szLine.cy, pItemNew->m_szItem.cy);
			}
		
		if( pItemPrev )
			pItemPrev->m_pNext = pItemNew;
		else
			pLine->m_pFirstItem = pItemNew;
		pItemNew->m_pPrev = pItemPrev;
		pItemPrev = pItemNew;		
		}

	CalcLineSize(pLine);
	if( bNewLine ){
		m_nContentHeight	+= pLine->m_szLine.cy;
		m_pLastLine			= pLine;
		}
	else
		m_nContentHeight	+= (pLine->m_szLine.cy - nHeightOld);

	m_nTopFullOffsetY	= 0;
	if( m_szView.cy != m_nContentHeight ){
		m_szView.cy		= m_nContentHeight;
		if( IsCreated() )
			AdjustScrollBarPos(bRedraw);
		}

	pLine->m_bLineBreak = bLineBreak;
	if( bRedraw ){
		_Rect rcLine;
		if( IsLineVisible(pLine, rcLine) )
			RedrawRect(rcLine, false);
		//Redraw(true);
		}
	}
Example #4
0
__declspec(dllexport) BOOL runApplication(LPCTSTR cmdline, const RunOptions * options)
{
    try {
        if (options->size != sizeof(RunOptions) ||
            ((options->user != NULL) ^ (options->password != NULL)) ||
            ((options->stdIn != NULL) ^ (options->stdOut != NULL))) {
                throw WinApiException(_T(""),ERROR_INVALID_PARAMETER);
        }
        init();
        setRestrictions(job,options);
        Process process(cmdline);
        process.setDesktop(getDesktop(options->useDefaultDesktop != FALSE));
        if (options->user != NULL && options->password != NULL)
            process.setCredentials(options->user,options->password);
        if (options->stdIn != NULL && options->stdOut != NULL)
            process.redirect(options->stdIn,options->stdOut);
        process.load();
        job->assignMainProcess(process);
        process.resume();
        CAutoPtr<ConsoleWindow> wnd;
        if (options->showStatusWindow) {
            ConsoleWindow * pWnd = new ConsoleWindow(CRect(-28,0,-1,5));
            wnd.Attach(pWnd);
            wnd->show();
        }
        while (job->active()) {
            job->waitForEvent(30);
            if (options->showStatusWindow) {
                _stringstream msg;
                msg << dec << fixed << showpoint << setprecision(1);
                msg << _T("Time elapsed:  ") << setw(6) << job->infoElapsedTime() << _T("\n");
                msg << _T("Time used:     ") << setw(6) << job->infoCPUTime() << _T("\n");
                msg << _T("Memory used:   ") << setw(6) << job->infoMemoryUsage()/1024 << _T("Kb\n");
                wnd->setMessage(msg.str());
                wnd->redraw();
            }
            if (options->callback != NULL ) {
                RunStatus status;
                status.elapsedTime = job->infoElapsedTime();
                status.cpuTime = job->infoCPUTime();
                status.memoryUsed = job->infoMemoryUsage();
                status.peakMemoryUsed = job->infoMemoryUsagePeak();
                if (!options->callback(&status)) {
                    job->terminate();
                }
            }
        }
        if (options->showStatusWindow)
            wnd->hide();
        JobResult jobresult = job->result();
        if (jobresult.result() == JobResult::OK) {
            DWORD code = process.exitCode();
            if (code != 0) {
                jobresult = JobResult(JobResult::RE, RuntimeErrorMessages::getFullMessage(code));
            }
        }
        job->gatherInfo();
        result.resultcode = jobresult.result();
        result.exitcode = process.exitCode();
        resultMessage = jobresult.info();
        result.message = resultMessage.c_str();
        result.elapsedTime = job->infoElapsedTime();
        result.cpuTime = job->infoCPUTime();
        result.memoryUsed = job->infoMemoryUsagePeak();
        result.exception = false;
    }
    catch (WinApiException e) {
        result.exception = true;
        result.exitcode = e.errorCode();
        resultMessage = e.message();
        result.message = resultMessage.c_str();
    }
    return !result.exception;
}