⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thedialog.cpp

📁 Linux/windows 环境下跨平台开发程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:

TxtHSP::TxtHSP(tag_DlgObj *par, DlgInfo *desc, RECT rec, int *align)
	:Dialog(par, desc, rec)
{
	int x1 = cr.left/xbase,			x2 = ((cr.left>>1) + (cr.right>>1))/xbase-4,
		x3 = cr.right/xbase-8,		y1 = cr.top/ybase,
		y2 = ((cr.top>>1) + (cr.bottom>>1))/ybase-4,	y3 = cr.bottom/ybase-8;
	int i;
	RECT br;

	DlgInfo d1[] = {
		{1, 2, 0, ISRADIO, RADIO0, 0L, x1, y1, 8, 8},
		{2, 3, 0, ISRADIO, RADIO0, 0L, x2, y1, 8, 8},
		{3, 4, 0, ISRADIO, RADIO0, 0L, x3, y1, 8, 8},
		{4, 5, 0, ISRADIO, RADIO0, 0L, x1, y2, 8, 8},
		{5, 6, 0, ISRADIO, RADIO0, 0L, x2, y2, 8, 8},
		{6, 7, 0, ISRADIO, RADIO0, 0L, x3, y2, 8, 8},
		{7, 8, 0, ISRADIO, RADIO0, 0L, x1, y3, 8, 8},
		{8, 9, 0, ISRADIO, RADIO0, 0L, x2, y3, 8, 8},
		{9, 0, 0, ISRADIO | LASTOBJ, RADIO0, 0L, x3, y3, 8, 8}};

	txt.ColTxt = 0x00808080L;	txt.ColBg = 0x00ffffff;
	txt.fSize = 8.0;		txt.RotBL = txt.RotCHAR = 0.0;
	txt.iSize = 0;			txt.Align = TXA_HCENTER | TXA_VCENTER;
	txt.Style = TXS_NORMAL;	txt.Font = FONT_HELVETICA;
	txt.Mode = TXM_TRANSPARENT;
	txt.text = strdup("text");
	if((d2 = (DlgInfo*)malloc(9*sizeof(DlgInfo)))){
		memcpy(d2, &d1,9*sizeof(DlgInfo));
		if(align) switch(*align) {
		case 1:		d2[1].flags |= CHECKED;		break;
		case 2:		d2[2].flags |= CHECKED;		break;
		case 4:		d2[3].flags |= CHECKED;		break;
		case 5:		d2[4].flags |= CHECKED;		break;
		case 6:		d2[5].flags |= CHECKED;		break;
		case 8:		d2[6].flags |= CHECKED;		break;
		case 9:		d2[7].flags |= CHECKED;		break;
		case 10:	d2[8].flags |= CHECKED;		break;
		default:	d2[0].flags |= CHECKED;		break;
			}
		for(i = 0; i < 9; i++) {
			br.left = d2[i].x*xbase;
			br.right = br.left + d2[i].w*xbase;
			br.top = d2[i].y*ybase;
			br.bottom = br.top + d2[i].h*ybase;
			butts[i] = new RadioButton(this, &d2[i], br, 0L);
			}
		}
}

TxtHSP::~TxtHSP()
{
	int i;

	if(txt.text) free(txt.text);
	if(d2){
		for(i = 0; i < 9; i++) if(butts[i]) delete(butts[i]);
		free(d2);
		}
}

bool
TxtHSP::Command(int cmd, void *tmpl, anyOutput *o)
{
	int i;
	Dialog *d;

	switch(cmd) {
	case CMD_RADIOBUTT:
		d = (Dialog *)tmpl;
		for(i = 0; i < 9; i++) 
			if(butts[i] && butts[i] != d && butts[i]->type == d->type)
				butts[i]->SetCheck(0, o, false);
		break;
		}
	return false;
}

void
TxtHSP::DoPlot(anyOutput *o)
{
	int i;

	if(txt.text){
		o->SetTextSpec(&txt);
		o->oTextOut((cr.left + cr.right)>>1, (cr.top + cr.bottom)>>1, txt.text, 0);
		}
	for(i = 0; i < 9; i++) if(butts[i]) butts[i]->DoPlot(o);
	o->UpdateRect(&cr, false);
}

bool
TxtHSP::Select(int x, int y, anyOutput *o)
{
	int i;
	bool bRet = false;

	for(i = 0; i < 9; i++) if(butts[i] && butts[i]->Select(x, y, o)) bRet = true;
	return bRet;
}

bool
TxtHSP::GetInt(int id, int *val)
{
	int i;
	bool bRet = false;

	for(i = 0; i < 9; i++) {
		if(butts[i] && butts[i]->GetCheck(i+1)) {
			bRet = true;
			switch (i) {
			case 0:		*val = 0;	break;
			case 1:		*val = 1;	break;
			case 2:		*val = 2;	break;
			case 3:		*val = 4;	break;
			case 4:		*val = 5;	break;
			case 5:		*val = 6;	break;
			case 6:		*val = 8;	break;
			case 7:		*val = 9;	break;
			case 8:		*val = 10;	break;
				}
			}
		}
	return bRet;
}

void
TxtHSP::MBtrack(MouseEvent *mev, anyOutput *o)
{
	int i;

	for(i = 0; i < 9; i++) if(butts[i]) butts[i]->MBtrack(mev, o);
}

SlideRect::SlideRect(tag_DlgObj *par, DlgInfo *desc, RECT rec, bool isVert)
	:Dialog(par, desc, rec)
{
	bV = isVert;
	if(isVert) {
		buttrc.left = cr.left+1;	buttrc.top = cr.top;
		buttrc.right = cr.right;	buttrc.bottom = cr.top + (w = h = (cr.right-cr.left));
		}
	else {
		buttrc.left = cr.left;		buttrc.top = cr.top+1;
		buttrc.right = cr.left+ (w = h = (cr.bottom - cr.top));	buttrc.bottom = cr.bottom;
		}
	dx = w>>1;		dy = h>>1;
	sLine = 1;
	puSel = pdSel = false;

}

SlideRect::~SlideRect()
{
}

bool
SlideRect::Command(int cmd, void *tmpl, anyOutput *o)
{
	int i;
	double tmp;

	switch(cmd) {
	case CMD_SETSCROLL:
		//DEBUG: replace width/height calulation by variables w and h
		tmp = *((double*)tmpl);
		if(tmp < 0.0) tmp = 0.0;	if(tmp > 1.0) tmp = 1.0;
		if(bV) {
			i = (int)((double)(cr.bottom -cr.top -7*ybase)*tmp);
			buttrc.bottom -= buttrc.top;
			buttrc.top = i + cr.top;		buttrc.bottom += (i+cr.top);
			}
		else {
			i = (int)((double)(cr.right -cr.left -7*xbase)*tmp);
			buttrc.right -= buttrc.left;
			buttrc.left = i + cr.left;		buttrc.right += (i+cr.left);
			}
		if(o)DoPlot(o);
		return true;
	case CMD_LINEUP:
		i = -sLine;
	case CMD_LINEDOWN:
		if(cmd == CMD_LINEDOWN) i = sLine;
		if(bV) {
			buttrc.top += i;
			if(buttrc.top < cr.top) buttrc.top = cr.top;
			if((buttrc.top + h) > cr.bottom) buttrc.top = cr.bottom -h;
			buttrc.bottom = buttrc.top + h;
			}
		else {
			buttrc.left += i;
			if(buttrc.left < cr.left) buttrc.left = cr.left;
			if((buttrc.left + w) > cr.right) buttrc.left = cr.right -w;
			buttrc.right = buttrc.left +w;
			}
		return true;
		}
	return false;
}


void
SlideRect::DoPlot(anyOutput *o)
{
	POINT pts[3];

	Line.color = DlgBGcolor;	Fill.color = 0x00e0e0e0L;
	o->SetLine(&Line);			o->SetFill(&Fill);
	o->oRectangle(cr.left, cr.top, cr.right, cr.bottom);
	puRC.top = cr.top;		puRC.left = cr.left;
	pdRC.right = cr.right;	pdRC.bottom = cr.bottom;
	if(bV) {
		puRC.bottom = buttrc.top;	puRC.right = cr.right;
		pdRC.top = buttrc.bottom;	pdRC.left = cr.left;
		}
	else {
		puRC.bottom = cr.bottom;	puRC.right = buttrc.left;
		pdRC.top = cr.top;			pdRC.left = buttrc.right;
		}
	Fill.color = DlgBGhigh;
	o->SetFill(&Fill);
	if(bLBdown){
		Line.color = 0x00808080L;		o->SetLine(&Line);
		o->oRectangle(buttrc.left, buttrc.top, buttrc.right, buttrc.bottom);
		}
	else {
		o->oRectangle(buttrc.left, buttrc.top, buttrc.right-1, buttrc.bottom-1);
		Line.color = 0x0L;
		o->SetLine(&Line);
		pts[0].x = buttrc.left;					pts[0].y = pts[1].y = buttrc.bottom-1;
		pts[1].x = pts[2].x = buttrc.right-1;	pts[2].y = buttrc.top-1;
		o->oPolyline(pts, 3);
		Line.color = 0x00ffffffL;
		o->SetLine(&Line);
		pts[0].x = pts[1].x = buttrc.left;
		pts[0].y = buttrc.bottom -3;
		pts[1].y = pts[2].y = buttrc.top;
		pts[2].x = buttrc.right -2;
		o->oPolyline(pts, 3);
		}
	o->UpdateRect(&cr, false);
	puSel = pdSel = false;
}

bool
SlideRect::Select(int x, int y, anyOutput *o)
{
	if(IsInRect(&buttrc, x, y)) {
		bLBdown = false;
		DoPlot(o);
		return true;
		}
	else if(bLBdown || puSel || pdSel) {
		bLBdown = false;
		DoPlot(o);
		}
	if(IsInRect(&puRC, x, y) && parent) parent->Command(CMD_PAGEUP, 0L, o);
	else if(IsInRect(&pdRC, x, y) && parent) parent->Command(CMD_PAGEDOWN, 0L, o);
	return false;
}

bool
SlideRect::GetValue(int id, double *val)
{
	double res;

	if(bV) {
		res = ((double)(buttrc.top - cr.top))/
			((double)(cr.bottom-cr.top-(cr.right-cr.left)));
		}
	else {
		res = ((double)(buttrc.left - cr.left))/
			((double)(cr.right-cr.left-(cr.bottom-cr.top)));
		}
	*val = res;
	return true;
}

void
SlideRect::MBtrack(MouseEvent *mev, anyOutput *o)
{
	bool bLBstate = false;

	if(mev->Action == MOUSE_LBDOUBLECLICK) {
		bLBdown = false;
		DoPlot(o);
		return;
		}
	if(mev->StateFlags &1) bLBstate = true;
	if(IsInRect(&buttrc, mev->x, mev->y)){
		if(mev->Action == MOUSE_LBDOWN){
			dx = mev->x-buttrc.left;	dy = mev->y - buttrc.top;
			}
		if(bLBstate && !bLBdown){
			bLBdown = bLBstate;
			DoPlot(o);
			return;
			}
		}
	if(IsInRect(&puRC, mev->x, mev->y)){
		if(pdSel) DoPlot(o);
		Line.color = Fill.color = bLBstate ? DlgBGcolor : 0x00e0e0e0L;
		o->SetLine(&Line);			o->SetFill(&Fill);
		o->oRectangle(puRC.left+3, puRC.top+3, puRC.right-3, puRC.bottom-3);
		o->UpdateRect(&puRC, false);
		puSel = true;
		}
	else if(puSel) DoPlot(o);
	if(IsInRect(&pdRC, mev->x, mev->y)){
		if(puSel) DoPlot(o);
		Line.color = Fill.color = bLBstate ? DlgBGcolor : 0x00e0e0e0L;
		o->SetLine(&Line);			o->SetFill(&Fill);
		o->oRectangle(pdRC.left+3, pdRC.top+3, pdRC.right-3, pdRC.bottom-3);
		o->UpdateRect(&pdRC, false);
		pdSel = true;
		}
	else if(pdSel) DoPlot(o);
	if(bLBdown && IsInRect(&cr, mev->x, mev->y)){
		if(bV) {
			buttrc.top = mev->y - dy;
			if(buttrc.top < cr.top) buttrc.top = cr.top;
			if((buttrc.top + h) > cr.bottom) buttrc.top = cr.bottom -h;
			buttrc.bottom = buttrc.top + h;
			}
		else {
			buttrc.left = mev->x - dx;
			if(buttrc.left < cr.left) buttrc.left = cr.left;
			if((buttrc.left + w) > cr.right) buttrc.left = cr.right -w;
			buttrc.right = buttrc.left +w;
			}
		if(parent && ((Dialog*)parent)->parent && 
			((Dialog*)parent)->parent->Command(CMD_REDRAW, 0L, o));
		else DoPlot(o);
		}
	else if(bLBdown){
		bLBdown = false;
		DoPlot(o);
		}
}

ScrollBar::ScrollBar(tag_DlgObj *par, DlgInfo *desc, RECT rec, bool isVert)
	:Dialog(par, desc, rec)
{
	int ab1 = 1, ab2 = 2, ab3 = 3, ab4 = 4;
	static DlgInfo ab[] = {
		{1, 2, 0, 0x0L, ARROWBUTT, (void*)0L, 0, 0, 0, 0},
		{2, 0, 0, 0x0L, ARROWBUTT, (void*)0L, 0, 0, 0, 0},
		{3, 0, 0, LASTOBJ, NONE, 0L, 0, 0, 0, 0}};
	RECT br, sr;

	if(isVert) {
		sr.left = cr.left;		sr.right = cr.right;
		br.left = cr.left+1;	br.right = cr.right+1;
		br.top = cr.top+1;		br.bottom = sr.top = br.top + 5*ybase + 1;
		sr.top--;	hcr.top = sr.top;
		butts[0] = new ArrowButton(this, &ab[0], br, &ab1);
		br.top = cr.bottom-5*ybase;		br.bottom = cr.bottom+1;
		butts[1] = new ArrowButton(this, &ab[1], br, &ab2);
		br.bottom -= 5*ybase;	br.top -= 5*ybase;
		hcr.bottom = sr.bottom = br.top;
		butts[2] = new ArrowButton(this, &ab[0], br, &ab1);
		}
	else {
		sr.top = cr.top;		sr.bottom = cr.bottom;
		br.left = cr.left+1;	br.right = sr.left = br.left + 5*xbase;
		sr.left--;	hcr.left = sr.left;
		br.top = cr.top+1;		br.bottom = cr.bottom+1;
		butts[0] = new ArrowButton(this, &ab[0], br, &ab3);
		br.left = cr.right - 5*xbase;	br.right = cr.right+1;
		butts[1] = new ArrowButton(this, &ab[1], br, &ab4);
		br.left -= 5*xbase;		br.right -= 5*xbase;
		hcr.right = sr.right = br.left;
		butts[2] = new ArrowButton(this, &ab[0], br, &ab3);
		}
	slrc = new SlideRect(this, &ab[2], sr, isVert);
	sLine = 1;		sPage = 8;
}

ScrollBar::~ScrollBar()
{
	int i;

	for(i = 0; i < 3; i++) if(butts[i]) delete butts[i];
	if(slrc) delete slrc;
}

bool
ScrollBar::Command(int cmd, void *tmpl, anyOutput *o)
{
	int i;

	switch(cmd) {
	case CMD_ENDDIALOG:
		if(!tmpl || !slrc) return false;
		i = ((Dialog*)tmpl)->Id;
		switch(i) {
		case 1:	return slrc->Command(CMD_LINEUP, 0L, o);
		case 2:	return slrc->Command(CMD_LINEDOWN, 0L, o);
		default:	return false;
			}
	case CMD_PAGEUP:
	case CMD_PAGEDOWN:
		if(parent)return parent->Command(cmd, tmpl, o);
		break;
	case CMD_SETSCROLL:
		if(slrc) return slrc->Command(cmd, tmpl, o);
		break;
		}
	return false;
}

void
ScrollBar::DoPlot(anyOutput *o)
{
	int i;

	for(i = 0; i < 3; i++) if(butts[i]) butts[i]->DoPlot(o);
	if(slrc){
		slrc->sLine = sLine;
		slrc->DoPlot(o);
		}
}

bool
ScrollBar::Select(int x, int y, anyOutput *o)
{
	int i;
	bool bRet = false;

	if(!IsInRect(&cr, x, y)) return false;
	for(i = 0; i < 3; i++) if(butts[i] && butts[i]->Select(x, y, o)) bRet = true;
	if(!bRet && slrc) bRet = slrc->Select(x, y, o);
	if(bRet && parent) parent->Command(CMD_REDRAW, 0L, o);
	return bRet;
}

bool
ScrollBar::GetValue(int id, double *val)
{
	if(slrc) return slrc->GetValue(id, val);
	return false;
}

void
ScrollBar::MBtrack(MouseEvent *mev, anyOutput *o)
{
	int i;

	for(i = 0; i < 3; i++) if(butts[i]) butts[i]->MBtrack(mev, o);
	if(slrc) slrc->MBtrack(mev, o);
}

Icon::Icon(tag_DlgObj *par, DlgInfo * desc, RECT rec, int *ico)
	:Dialog(par, desc, rec)
{
	icon = ico ? *ico : 0;
}

void
Icon::DoPlot(anyOutput *o)
{
	o->oDrawIcon(icon, cr.left, cr.top);
	o->UpdateRect(&cr, false);
}

Group::Group(tag_DlgObj *par, DlgInfo *desc, RECT rec)
	:Dialog(par, desc, rec)
{
	numChildren = 5;
	Children = (Dialog **)calloc(numChildren, sizeof(Dialog *));
	TextFocus = 0L;
}

Group::~Group()
{
	//pointers to child objects are allocated and freed by parent:
	//  pointers are copies and we do not care further;
	if(Children) free(Children);
}

bool
Group::Command(int cmd, void *tmpl, anyOutput *o)
{
	Dialog *d, **tmp;

	int i;

	switch (cmd) {
	case CMD_FLUSH:
		if(Children) for(i = 0; i < numChildren; Children[i++] = 0L);
		break;
	case CMD_CONTINUE:
	case CMD_ENDDIALOG:
	case CMD_TABDLG:
	case CMD_NOTABDLG:
		if(parent) return parent->Command(cmd, tmpl, o);
		else return false;
	case CMD_ADDCHILD:
		if(Children && numChildren && (d = (Dialog*)tmpl)) {
			d->parent = t

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -