Click here to Skip to main content
15,884,388 members
Articles / Desktop Programming / WTL

A fast and lightweight cell control

Rate me:
Please Sign up or sign in to vote.
4.42/5 (31 votes)
11 Mar 2008CPOL1 min read 90.9K   4.5K   81  
A fast and lightweight cell control for displaying tabular data. The cell is a custom control derived from ATL::CWindow.
#pragma once
namespace mycell{
	struct HLine
	{
		int xLeft;
		int xRight;
		int y;
		HLine():xLeft(0),xRight(0),y(0)
		{}
		HLine(int _x1,int _x2,int _y):xLeft(_x1),xRight(_x2),y(_y)
		{}
		void set(int _x1,int _x2,int _y)
		{
			xLeft=_x1;
			xRight=_x2;
			y=_y;
		}
		bool IsValid()const
		{
			return xLeft<xRight;
		}
		bool GetIntersect(HLine rhs,HLine& out)const
		{
			if(rhs.y==y){
				out.xLeft=max(xLeft,rhs.xLeft);
				out.xRight=min(xRight,rhs.xRight);
				return out.xLeft<=out.xRight;
			}
			return false;
		}
		void Xor(HLine rhs,HLine& o1,HLine& o2)const
		{
			//_ASSERT(y==rhs.y);
			o1.y=y;
			o2.y=rhs.y;
			if(y!=rhs.y || xRight<=rhs.xLeft || xLeft>=rhs.xRight){
				o1=*this;
				o2=rhs;
			}else{
				o1.xLeft=min(xLeft,rhs.xLeft);
				o1.xRight=max(xLeft,rhs.xLeft);
				o2.xLeft=min(xRight,rhs.xRight);
				o2.xRight=max(xRight,rhs.xRight);
			}
		}
	};
	struct VLine
	{
		int yTop;
		int yBottom;
		int x;
		VLine():yTop(0),yBottom(0),x(0)
		{}
		VLine(int _yTop,int _yBottom,int _x):yTop(_yTop),yBottom(_yBottom),x(_x)
		{}
		void set(int _yTop,int _yBottom,int _x)
		{
			yTop=_yTop;
			yBottom=_yBottom;
			x=_x;
		}
		void Xor(VLine rhs,VLine& o1,VLine& o2)const
		{
			//_ASSERT(x==rhs.x);
			o1.x=x;o2.x=rhs.x;
			if(x!=rhs.x || yBottom<=rhs.yTop || yTop>=rhs.yBottom){
				o1=*this;
				o2=rhs;
			}else{
				o1.yTop=min(yTop,rhs.yTop);
				o1.yBottom=max(yTop,rhs.yTop);
				o2.yTop=min(yBottom,rhs.yBottom);
				o2.yBottom=max(yBottom,rhs.yBottom);
			}
		}
	};
}//namespace mycell

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
China China
My name is Yanxueming,i live in Chengdu China.Graduated from UESTC in 1999.

Comments and Discussions