Пример #1
0
//***************************************************************************
void CGuiHeaderCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC		*pDC	=	CDC::FromHandle(lpDrawItemStruct->hDC);
	CRect	rcitem	=	lpDrawItemStruct->rcItem;
	UINT	uState	=	lpDrawItemStruct->itemState;
	int     nItemID =   lpDrawItemStruct->itemID;
	CBrush	m_brush;
	CString m_caption;
	CSize	siImg=CSize(0,0);
	TCHAR caption[256];
	IMAGEINFO pImageInfo;
	int OldMode=pDC->SetBkMode(TRANSPARENT);
	m_brush.CreateSysColorBrush(COLOR_3DFACE);
	pDC->FillRect(rcitem,&m_brush);
	HDITEM hdi;
	hdi.mask = HDI_TEXT | HDI_FORMAT|HDI_IMAGE| HDI_ORDER;
	hdi.pszText = caption;
	hdi.cchTextMax = 255;
	GetItem( nItemID, &hdi );
	//---------------------------------------------------------
	//se mueve la imagen para dar la sensacion
	//de seleccion del item
	//---------------------------------------------------------
	if (uState == ODS_SELECTED) 
	{
		rcitem.left+=1;
		rcitem.top+=1;
	}

	if (m_nNumbottomSelect==nItemID)
	{
		DrawArrow(pDC,rcitem,m_bSentido);
		rcitem.right-=12;
	}
	
	if (hdi.iImage > -1)
	{
		m_img.GetImageInfo(hdi.iImage,&pImageInfo);
		CRect rcima =pImageInfo.rcImage;
		siImg=CSize(rcima.Width(),rcima.Height());
		CPoint pti(rcitem.left+2,rcitem.top+1);
		m_img.Draw(pDC, hdi.iImage, pti, ILD_TRANSPARENT);
	}
	if (lstrlen(caption) > 0)
		{
			CRect m_rctext=rcitem;
			m_rctext.left+=siImg.cx+4;
			m_rctext.bottom-=2;
			DrawTextExt(caption,pDC,&m_rctext,DT_SINGLELINE|DT_BOTTOM);
			
		}
	pDC->SetBkMode(OldMode);

	
}
Пример #2
0
//***************************************************************************
BOOL CHeaderView::DrawItem(HDITEM hdi,CGDI* pDC)
{
	CRect	rcitem;
	CSize	siImg=CSize(0,0);
	IMAGEINFO pImageInfo;
	int OldMode=pDC->SetBkMode(TRANSPARENT);
	GetItemRect(hdi.iOrder, rcitem);
	HFONT m_fontOldBold;
	HFONT m_fontOld;
	(void)m_fontOldBold;
	(void)m_fontOld;
	//---------------------------------------------------------
	//se mueve la imagen para dar la sensacion
	//de seleccion del item
	//---------------------------------------------------------
	if (m_nNumbottomSelect==hdi.iOrder)
	{
		DrawArrow(pDC,rcitem,m_bSentido);
		rcitem.right-=12;
	}
	
	if (hdi.iImage > -1)
	{
		m_img.GetImageInfo(hdi.iImage,&pImageInfo);
		CRect rcima =pImageInfo.rcImage;
		siImg=CSize(rcima.Width(),rcima.Height());
		CPoint pti(rcitem.left+2,rcitem.top+1);
		m_img.Draw( hdi.iImage,pDC->m_hDC, pti, ILD_TRANSPARENT);
	}
	
	if (hdi.cchTextMax > 0)
		{
			
			CRect m_rctext=rcitem;
			m_rctext.left+=siImg.cx+4;
			m_rctext.bottom-=2;
			if (m_bMouserOver && m_selected==hdi.iOrder)
				m_fontOldBold=pDC->SelectFont(m_cfontBold);
			else
				m_fontOld=pDC->SelectFont(m_cfontNormal);

			DrawTextExt(hdi.pszText,pDC,&rcitem);
		}

	
	
	pDC->SetBkMode(OldMode);
	return TRUE;
	
}
Пример #3
0
int main( int argc, const char** argv)
{
	try
	{
		g_errorBuffer = strus::createErrorBuffer_standard( 0, 1);
		if (!g_errorBuffer)
		{
			std::cerr << "construction of error buffer failed" << std::endl;
			return -1;
		}
		else if (argc > 3)
		{
			printUsage( argc, argv);
			std::cerr << "too many arguments" << std::endl;
			return 1;
		}
		else if (argc < 3)
		{
			printUsage( argc, argv);
			std::cerr << "too few arguments" << std::endl;
			return 1;
		}
		// Create objects:
		std::auto_ptr<strus::TokenPatternMatchInterface> pti( strus::createTokenPatternMatch_standard( g_errorBuffer));
		if (!pti.get()) throw std::runtime_error("failed to create pattern matcher");
		std::auto_ptr<strus::CharRegexMatchInterface> cri( strus::createCharRegexMatch_standard( g_errorBuffer));
		if (!cri.get()) throw std::runtime_error("failed to create char regex matcher");
		std::auto_ptr<strus::PatternMatchProgramInterface> ppi( strus::createPatternMatchProgram_standard( pti.get(), cri.get(), g_errorBuffer));
		if (!ppi.get()) throw std::runtime_error("failed to create pattern program loader");
		std::auto_ptr<strus::PatternMatchProgramInstanceInterface> pii( ppi->createInstance());
		if (!pii.get()) throw std::runtime_error("failed to create pattern program loader instance");

		// Load program:
		std::string programfile( argv[ 1]);
		std::string programsrc;
		unsigned int ec;
		ec = strus::readFile( programfile, programsrc);
		if (ec)
		{
			char errmsg[ 256];
			::snprintf( errmsg, sizeof(errmsg), "error (%u) reading program source '%s': %s", ec, programfile.c_str(), ::strerror(ec));
			throw std::runtime_error( errmsg);
		}
		if (!pii->load( programsrc))
		{
			throw std::runtime_error( "error loading pattern match program source");
		}
		if (!pii->compile())
		{
			throw std::runtime_error( "error compiling pattern match program");
		}

		// Load input:
		std::string inputfile( argv[ 2]);
		std::string inputsrc;
		ec = strus::readFile( inputfile, inputsrc);
		if (ec)
		{
			char errmsg[ 256];
			::snprintf( errmsg, sizeof(errmsg), "error (%u) reading input file '%s': %s", ec, inputfile.c_str(), ::strerror(ec));
			throw std::runtime_error( errmsg);
		}

		// Load expected output:
		char const* argv2ext = std::strchr( argv[ 2], '.');
		if (argv2ext)
		{
			char const* aa = std::strchr( argv2ext+1, '.');
			while (aa)
			{
				argv2ext = aa;
				aa = std::strchr( argv2ext+1, '.');
			}
		}
		else
		{
			argv2ext = std::strchr( argv[ 2], '\0');
		}
		std::string expectedfile( argv[ 2], argv2ext - argv[ 2]);
		expectedfile.append( ".res");
		std::string expectedsrc;
		ec = strus::readFile( expectedfile, expectedsrc);
		if (ec)
		{
			char errmsg[ 256];
			::snprintf( errmsg, sizeof(errmsg), "error (%u) reading expected file '%s': %s", ec, expectedfile.c_str(), ::strerror(ec));
			throw std::runtime_error( errmsg);
		}

		// Scan source with char regex automaton for tokens:
		const strus::CharRegexMatchInstanceInterface* crinst = pii->getCharRegexMatchInstance();
		std::auto_ptr<strus::CharRegexMatchContextInterface> crctx( crinst->createContext());

		std::vector<strus::stream::PatternMatchToken> crmatches = crctx->match( inputsrc.c_str(), inputsrc.size());
		if (crmatches.size() == 0 && g_errorBuffer->hasError())
		{
			throw std::runtime_error( "failed to scan for tokens with char regex match automaton");
		}
		std::ostringstream resultstrbuf;

		// Scan tokens with token pattern match automaton and print results:
		const strus::TokenPatternMatchInstanceInterface* ptinst = pii->getTokenPatternMatchInstance();
		std::auto_ptr<strus::TokenPatternMatchContextInterface> ptctx( ptinst->createContext());
		std::vector<strus::stream::PatternMatchToken>::const_iterator
			ci = crmatches.begin(), ce = crmatches.end();
		for (; ci != ce; ++ci)
		{
			std::string tokstr( std::string( inputsrc.c_str() + ci->origpos(), ci->origsize()));
			resultstrbuf << "token " << pii->tokenName(ci->id()) << "(" << ci->id() << ") at " << ci->ordpos() 
					<< "[" << ci->origpos() << ":" << ci->origsize() << "] '"
					<< tokstr << "'" << std::endl;
			ptctx->putInput( *ci);
		}
		std::vector<strus::stream::TokenPatternMatchResult> results = ptctx->fetchResults();
		if (results.size() == 0 && g_errorBuffer->hasError())
		{
			throw std::runtime_error( "failed to scan for patterns with token pattern match automaton");
		}

		// Print results to buffer:
		strus::utils::printResults( resultstrbuf, results, inputsrc.c_str());
		strus::stream::TokenPatternMatchStatistics stats = ptctx->getStatistics();
		strus::utils::printStatistics( resultstrbuf, stats);

		// Print result to stdout and verify result by comparing it with the expected output:
		std::string resultstr = resultstrbuf.str();
		std::cout << resultstr << std::endl;
		if (!diffContent( expectedsrc, resultstr))
		{
			throw std::runtime_error( "output and expected result differ");
		}

		if (g_errorBuffer->hasError())
		{
			throw std::runtime_error( "uncaught error");
		}
		std::cerr << "OK" << std::endl;
		delete g_errorBuffer;
		return 0;
	}
	catch (const std::runtime_error& err)
	{
		if (g_errorBuffer->hasError())
		{
			std::cerr << "error processing pattern matching: "
					<< g_errorBuffer->fetchError() << " (" << err.what()
					<< ")" << std::endl;
		}
		else
		{
			std::cerr << "error processing pattern matching: "
					<< err.what() << std::endl;
		}
	}
	catch (const std::bad_alloc&)
	{
		std::cerr << "out of memory processing pattern matching" << std::endl;
	}
	delete g_errorBuffer;
	return -1;
}
Пример #4
0
void CGuiToolBarWnd::OnPaint()
{

	CPaintDC dc(this);  	
	CRect rcBtn;
	
	int nBtn=GetToolBarCtrl().GetButtonCount();
	int iBitmap;
	UINT nID;
	UINT nStyle;
	WORD wStyle, wState;
	DWORD dwBarStyle = GetToolBarCtrl().GetStyle();
	BOOL mbIsPress;
	BOOL mbIsEnabled;
	CBrush cb;
	CImageList m_imgList;
	CRect rcUpdate;
	int iUltbot;
	CRect rcClient;
	GetClientRect(&rcClient);
	cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorXP());
	
    // draw borders in non-client area
    CRect rcDraw = rcClient;
 
	dc.FillRect(rcDraw, &cb);
	
	
	HIMAGELIST hiImg = 0;
	iBitmap=0;
	hiImg = HIMAGELIST(SendMessage(TB_GETIMAGELIST));
	m_imgList.Attach(hiImg);
	int j=0;
	for(int i=0; i < nBtn; i++)
	{
		
		bOver=FALSE;
		GetItemRect(i,&rcBtn);
		GetButtonInfo(i,nID,nStyle,iBitmap);
		wStyle= LOWORD(nStyle);
		wState= HIWORD(nStyle);
		if (wState & TBSTATE_HIDDEN) continue;
		if (wStyle == TBSTYLE_SEP)
		{
			if (!(wState & TBSTATE_WRAP) || ! IsFloating() )
			{
				CRect m_Separ;
				m_Separ=rcBtn;
				
				//si existe un separador vertical
				if (m_dwStyle & CBRS_ORIENT_HORZ)
				{
					dc.FillRect(&rcBtn,&cb);
					int nhalf=(m_Separ.Width()/2)-1;
					m_Separ.top-=1;
					m_Separ.left+=nhalf;
					m_Separ.right=m_Separ.left+1;
					m_Separ.bottom+=1;
					
				}
				else
				{
					int nhalf=(m_Separ.Width()/2)-1;
					int iHeigh=m_Separ.Height();
					
					m_Separ.left=0;
					m_Separ.right=m_Separ.left+m_Separ.Height()+1;
					m_Separ.top=iUltbot;
					m_Separ.bottom=m_Separ.top+m_Separ.Width();			
					dc.FillRect(&m_Separ,&cb);
					
					m_Separ.left=0;
					m_Separ.right=m_Separ.left+iHeigh+1;
					m_Separ.top=iUltbot+nhalf;
					m_Separ.bottom=m_Separ.top+1;
					
					
				}
				CBrush cbt;
				cbt.CreateSolidBrush(RGB(167, 167, 167));
				dc.FillRect(m_Separ,&cbt);
				continue;
				
			}
			
				 
		}
		else {
			
			mbIsPress=(wState & TBSTATE_CHECKED) || (wState & TBSTATE_PRESSED);
			mbIsEnabled= GetToolBarCtrl().IsButtonEnabled((int)nID);
			CPoint pt;
			GetCursorPos(&pt);
			ScreenToClient(&pt);
			CBrush cblu;
			if(!rcBtn.PtInRect(pt))
			{
				if (wState & TBSTATE_CHECKED)
				{
					cblu.CreateSolidBrush(GuiDrawLayer::GetRGBPressBXP());
					dc.FillRect(rcBtn,&cblu);					
				}
				else
				{
					dc.FillRect(rcBtn,&cb);
				}
			}
			else
			{
				
				if (bPressDown)
					dc.Draw3dRect(rcBtn,GuiDrawLayer::GetRGBColorShadow(),GuiDrawLayer::GetRGBColorShadow());
				else
					dc.Draw3dRect(rcBtn,GuiDrawLayer::GetRGBCaptionXP(),GuiDrawLayer::GetRGBCaptionXP());
				rcBtn.DeflateRect(1,1);
				if (wState & TBSTATE_CHECKED)
				{
					cblu.CreateSolidBrush(GuiDrawLayer::GetRGBFondoXP());
					dc.FillRect(rcBtn,&cblu);					
				}
				else
				{
					
					if (bPressDown)
					{
						cblu.CreateSolidBrush(GuiDrawLayer::GetRGBColorXP());
						dc.FillRect(rcBtn,&cblu);
					}
					else
					{
						cblu.CreateSolidBrush(mbIsPress?GuiDrawLayer::GetRGBPressBXP():GuiDrawLayer::GetRGBFondoXP());
						dc.FillRect(rcBtn,&cblu);					
					}
					if (wStyle == 8) 
					{
						
						CRect rcCli=rcBtn;
						int dif=rcBtn.right-_afxDropDownWidth;
						rcCli.left=dif+1;
						
						if (!bPressDown)
						{
							CPen Cp( PS_SOLID, 1, GuiDrawLayer::GetRGBCaptionXP());
							CPen* oldPen= dc.SelectObject(&Cp);
							dc.MoveTo(dif,rcBtn.top);
							dc.LineTo(dif,rcBtn.bottom);
							dc.SelectObject(oldPen);
						}
						
					}
					if (!mbIsPress && !bPressDown)
						bOver=TRUE;
					else
						bOver=FALSE;
					if (!bPressDown) 
						SetTimer(1,10,NULL);
					else
						KillTimer(1);		

				}
				rcBtn.InflateRect(1,1);
				
			}

		}

		if (wStyle != TBSTYLE_SEP)
	{
			
			int OldMode=dc.SetBkMode(TRANSPARENT);
			IMAGEINFO pImageInfo;
			m_imgList.GetImageInfo(iBitmap,&pImageInfo);
			CRect rcima =pImageInfo.rcImage;
			CSize siImg=CSize(rcima.Width(),rcima.Height());
			/* Modified By SunZhenyu 2003/6/27, Replace by the next 5 lines, CPoint pti(rcBtn.left+2,rcBtn.top+4); */
			CPoint pti(rcBtn.left+(rcBtn.Width()-siImg.cx)/2,rcBtn.top+4);
			if( dwBarStyle & TBSTYLE_LIST ) // ÎÄ×ÖÔÚÓÒ±ß
				pti = CPoint(rcBtn.left+4,rcBtn.top+(rcBtn.Height()-siImg.cy)/2);
			else if( wStyle & TBSTYLE_DROPDOWN )
				pti.x -= _AfxGetDropDownWidth()/2;
			CString mszText=GetButtonText(i);
			CFont* m_fontOld=dc.SelectObject(&m_cfont);
			if (!(wState & TBSTATE_ENABLED))
			{
				if (bOver==TRUE)
				{
					pti.x+=1;
					pti.y+=1;
					dc.DrawState(pti,siImg,m_imgList.ExtractIcon(iBitmap),DSS_MONO,CBrush (GuiDrawLayer::GetRGBColorShadow()));
							pti.x-=2;					pti.y-=2;
				
				}
				m_imgList.Draw(&dc, iBitmap, pti, ILD_TRANSPARENT);
				if (mszText.GetLength() > 0 && !bVertDocked)
				{
					CRect m_rctext=rcBtn;
					/* Modified By SunZhenyu 2003/6/27, Replace by the next 6 line, m_rctext.left+=siImg.cx+4; */
					if( dwBarStyle & TBSTYLE_LIST )
						m_rctext.left += siImg.cx+4;
					else
						m_rctext.top += siImg.cy+4;
					if( wStyle & TBSTYLE_DROPDOWN )
						m_rctext.right -= _AfxGetDropDownWidth();
					m_rctext.bottom-=1;
					/* Modified By SunZhenyu 2003/6/27, Replace by the next 5 line
					dc.DrawText(mszText,&m_rctext,DT_SINGLELINE|DT_BOTTOM|DT_CENTER);
					*/
					m_rctext.right-=1;
					if( dwBarStyle & TBSTYLE_LIST )
						dc.DrawText(mszText,&m_rctext,DT_SINGLELINE|DT_VCENTER|DT_RIGHT);
					else
						dc.DrawText(mszText,&m_rctext,DT_SINGLELINE|DT_BOTTOM|DT_CENTER);
				}
			}
			else
			{
				dc.DrawState(pti,siImg,m_imgList.ExtractIcon(iBitmap),DSS_DISABLED,(CBrush*)NULL);
				CRect m_rctext=rcBtn;
				/* Modified By SunZhenyu 2003/6/27, Replace by the next 5 line, m_rctext.left+=siImg.cx+4; */
				if( dwBarStyle & TBSTYLE_LIST )
					m_rctext.left += siImg.cx+4;
				else
					m_rctext.top += siImg.cy+4;
				m_rctext.bottom-=1;
				CSize szText=dc.GetTextExtent(mszText);
				/* Modified By SunZhenyu 2003/6/27, Replace by the next 4 lines,
				pti.x= m_rctext.left+2;
				pti.y= (m_rctext.Height()/2)-1;
				*/
				pti.x = m_rctext.left+(m_rctext.Width()-szText.cx)/2;
				if( wStyle & TBSTYLE_DROPDOWN )
					pti.x = m_rctext.left+(m_rctext.Width()-szText.cx-_AfxGetDropDownWidth())/2;
				pti.y= m_rctext.top+(m_rctext.Height()-szText.cy)/2;
				//DrawState(pt, m_Csize, m_szCaption, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
				dc.DrawState(pti,szText,mszText,DSS_DISABLED,TRUE,0,(HBRUSH)NULL);
			}
			
			if (wStyle == TBSTYLE_DROPDOWN) 
				DrawArrow(&dc,rcBtn);
			dc.SetBkMode(OldMode);
			// Modified By SunZhenyu
			dc.SelectObject(m_fontOld);
			iBitmap++;
			iUltbot=rcBtn.bottom;
			j++;
		}
	}
	m_imgList.Detach();
	
	
    ReleaseDC(&dc);

  
}