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

📄 thedialog.cpp

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

void
Config::DoPlot(anyOutput *o)
{
	POINT pts[2];

	if(!o || flags & HIDDEN) return;
	Line.width = 0.0;
	Line.color = DlgBGcolor;		Fill.color = DlgBGcolor;
	o->SetLine(&Line);		o->SetFill(&Fill);
	o->oRectangle(hcr.left+2, hcr.top, hcr.right, hcr.bottom);
	Line.color = 0x00000000L;		Fill.color = bLBdown ? 0x00ffffff : 0x00e8e8e8L;
	o->SetLine(&Line);		o->SetFill(&Fill);
	o->oRectangle(cr.left+3, cr.top+3, cr.right-3, cr.bottom-3);
	o->oRectangle(cr.left+8, cr.top+6, cr.left+11, cr.top+9);
	o->oRectangle(cr.left+8, cr.top+10, cr.left+11, cr.top+13);
	o->oRectangle(cr.left+8, cr.top+14, cr.left+11, cr.top+17);
	o->oRectangle(cr.left+7, cr.top+18, cr.right-7, cr.bottom-5);
	pts[0].x = cr.left + 14;					pts[1].x = cr.right - 8;
	pts[0].y = pts[1].y = cr.top + 7;			o->oSolidLine(pts);
	pts[0].y = pts[1].y = cr.top + 11;			o->oSolidLine(pts);
	pts[0].y = pts[1].y = cr.top + 15;			o->oSolidLine(pts);
	o->UpdateRect(&cr, false);
}

bool
Config::Select(int x, int y, anyOutput *o)
{
	if(!(flags & HIDDEN) && IsInRect(&hcr, x, y)) {
		if((flags & TOUCHEXIT) && parent) 
			parent->Command(CMD_ENDDIALOG, (void *)this, o);
		bLBdown=false;				DoPlot(o);
		return true;
		}
	return false;
}

RadioButton::RadioButton(tag_DlgObj *par, DlgInfo * desc, RECT rec, char *text)
	:Dialog(par, desc, rec)
{
	if(text) Text = strdup(text);
	else Text = 0L;
	switch(type) {
	case RADIO0:
		hcr.left = cr.left+4;		hcr.right = cr.left+13;
		hcr.top = cr.top+4;			hcr.bottom = cr.top+13;
		break;
	case RADIO1:
		hcr.left = cr.left+2;		hcr.right = cr.left+15;
		hcr.top = cr.top+3;			hcr.bottom = cr.top+16;
		break;
	case RADIO2:
		hcr.left = cr.left;			hcr.right = cr.left+15;
		hcr.top = cr.top+1;			hcr.bottom = cr.top+16;
		break;
		}
	flags |= ISRADIO;
}

RadioButton::~RadioButton()
{
	if(Text) free (Text);
}

bool
RadioButton::Command(int cmd, void *tmpl, anyOutput *o)
{
	switch(cmd) {
	case CMD_SETTEXT:
		if(Text) free(Text);
		if(tmpl)Text = strdup((char *)tmpl);
		else Text = 0L;
		return true;
		}
	return false;
}

void
RadioButton::DoPlot(anyOutput *o)
{
	if(flags & HIDDEN) return;
	Line.color = 0x00000000L;
	Line.width = 0.0;
	Fill.color = bLBdown ? DlgBGcolor : 0x00ffffffL;
	if(bActive) {
		o->SetLine(&Line);
		o->SetFill(&Fill);
		o->oCircle(hcr.left, hcr.top, hcr.right, hcr.bottom);
		if(bChecked) {
			Fill.color = 0x00000000L;		o->SetFill(&Fill);
			switch (type) {
			case RADIO0:
				o->oCircle(cr.left+6, cr.top+6, cr.left+11, cr.top+11);
				break;
			case RADIO1:
				o->oCircle(cr.left+5, cr.top+6, cr.left+12, cr.top+13);
				break;
			case RADIO2:
				o->oCircle(cr.left+3, cr.top+4, cr.left+12, cr.top+13);
				break;
				}	
			}
		}
	if(Text) {
		o->SetTextSpec(&TextDef);
		o->oTextOut(cr.left + 20, cr.top + 1, Text, strlen(Text));
		}
	o->UpdateRect(&cr, false);
}

bool
RadioButton::Select(int x, int y, anyOutput *o)
{
	if(bActive && !(flags & HIDDEN) && IsInRect(&hcr, x, y)) {
		bChecked = true;		bLBdown = false;
		DoPlot(o);
		if(parent) parent->Command(CMD_RADIOBUTT, (void *)this, o);
		if((flags & TOUCHEXIT) && parent) 
			parent->Command(CMD_ENDDIALOG, (void *)this, o);
		return true;
		}
	return false;
}

void
RadioButton::SetColor(int id, DWORD color)
{
	TextDef.ColTxt = color;
}

Text::Text(tag_DlgObj *par, DlgInfo * desc, RECT rec, char *text)
	:Dialog(par, desc, rec)
{
	if(text) txt = strdup(text);
	else txt = 0L;
	switch (type) {
	case RTEXT:		TextDef.Align = TXA_HRIGHT | TXA_VTOP;	break;
	case CTEXT:		TextDef.Align = TXA_HCENTER | TXA_VTOP;	break;
	default:		TextDef.Align = TXA_HLEFT | TXA_VTOP;	break;
		}
}

Text::~Text()
{
	if(txt) free(txt);
}

bool
Text::Command(int cmd, void *tmpl, anyOutput *o)
{
	switch(cmd) {
	case CMD_SETTEXT:
		if(txt) free(txt);
		if(tmpl)txt = strdup((char *)tmpl);
		else txt = 0L;
		return true;
		}
	return false;
}

void
Text::DoPlot(anyOutput *o)
{
	if(WWWbrowser && WWWbrowser[0] && (flags & HREF)) {
		TextDef.ColTxt = 0x00ff0000L;
		TextDef.Style |= TXS_UNDERLINE;
		}
	if(txt){
		o->SetTextSpec(&TextDef);
		switch(type) {
		case RTEXT: o->oTextOut(cr.right - 2, cr.top + 1, txt, 0);				break;
		case CTEXT: o->oTextOut((cr.left + cr.right)/2, cr.top + 1, txt, 0);	break;
		default:	o->oTextOut(cr.left + 2, cr.top + 1, txt, 0);				break;
			}
		o->UpdateRect(&cr, false);
		}
}

bool
Text::Select(int x, int y, anyOutput *o)
{
	if(WWWbrowser && WWWbrowser[0] && txt && (flags & HREF) && IsInRect(&cr, x, y)) {
		sprintf(TmpTxt, "%s %s", WWWbrowser, txt);
		if(parent)parent->Command(CMD_CONTINUE, 0L, o);
#ifdef _WINDOWS
		WinExec(TmpTxt, SW_SHOWMAXIMIZED); 
#else
		strcat(TmpTxt, " &");
		system(TmpTxt);
#endif
		if(parent)parent->Command(CMD_ENDDIALOG, 0L, o);
		return true;
		}
	return false;
}

void
Text::SetColor(int id, DWORD color)
{
	TextDef.ColTxt = color;
}

InputText::InputText(tag_DlgObj *par, DlgInfo * desc, RECT rec, char *text)
	:Dialog(par, desc, rec)
{
	RECT rc;

	rc.left = rec.left+1;				rc.top = rec.top+1;
	rc.right = rec.right-1;				rc.bottom = rec.bottom-1;
	if(type == INCDECVAL1) cr.right = rc.right = cr.right - 7*xbase;
	Line.color = 0x00000000L;
	if(Text = new EditText(0L, text, -1, -1)) Text->SetRec(&rc);
	Disp = 0L;
}

InputText::~InputText()
{
	if(Text) delete (Text);		Text = 0L;
}

bool
InputText::Command(int cmd, void *tmpl, anyOutput *o)
{
	double tmpVal;
	bool bRet;

	switch(cmd) {
	case CMD_CURRLEFT:	case CMD_CURRIGHT:	case CMD_DELETE:
	case CMD_POS_FIRST:	case CMD_POS_LAST:	case CMD_SHIFTLEFT:
	case CMD_SHIFTRIGHT:
		if(Text && bActive && !(flags & NOEDIT)){
			o->SetTextSpec(&TextDef);
			bRet = Text->Command(cmd, o, NULL);
			if(bRet && (flags & TOUCHEXIT)) parent->Command(CMD_ENDDIALOG, (void *)this, o);
			return bRet;
			}
		break;
	case CMD_SETFONT:	case CMD_SETSTYLE:
		if(Text) return Text->Command(cmd, o, tmpl);
		return false;
	case CMD_UPDATE:
		if(Text && bActive && o) Text->Command(cmd, o, 0L);
		break;
	case CMD_COPY:		case CMD_PASTE:
		if(Text && bActive && !(flags & NOEDIT)) return  Text->Command(cmd, o, NULL);
		return false;
	case CMD_ADDCHAR:
		if(Text && bActive && !(flags & NOEDIT)){
			if(flags & TOUCHEXIT) parent->Command(CMD_ENDDIALOG, (void *)this, o);
			o->SetTextSpec(&TextDef);
			switch(*((int*)tmpl)) {
			case 8: return Text->Command(CMD_BACKSP, o, NULL);	//Backspace
			default: return Text->AddChar(*((int*)tmpl), o, 0L);
				}
			}
		return false;
	case CMD_SETTEXT:
		if(Text) return Text->SetText((char*)tmpl);
		break;
	case CMD_ENDDIALOG:		//we should come here for IncDecValue class only
		if(type == INCDECVAL1 && GetValue(Id, &tmpVal)) {
			if(((Dialog*)tmpl)->Id == 1) tmpVal *= 1.2;
			else tmpVal /= 1.2;
			tmpVal = NiceValue(tmpVal);
			if(fabs(tmpVal) < 0.0001) switch(defs.cUnits) {
				case 1:		tmpVal = 0.01;	break;
				case 2:		tmpVal = 0.004;	break;
				default:	tmpVal = 0.1;	break;
				}
			WriteNatFloatToBuff(TmpTxt, tmpVal);
			if(Text) {
				if(Text->text) free(Text->text);
				Text->text = strdup(TmpTxt+1);
				DoPlot(o);
				}
			}
		break;
		}
	return false;
}

void
InputText::DoPlot(anyOutput *o)
{
	POINT pts[5];

	if(!o) return;
	Disp = o;
	pts[0].x = pts[0].y = 0;		//that means no caret with update(5)
	o->SetTextSpec(&TextDef);
	if(Text) Text->Update(bActive ? 5 : 2, o, &pts[0]);
	o->SetLine(&Line);
	pts[0].x = pts[1].x = pts[4].x = cr.left;
	pts[0].y = pts[3].y = pts[4].y = cr.top;
	pts[1].y = pts[2].y = cr.bottom-1;
	pts[2].x = pts[3].x = cr.right-1;
	o->oPolyline(pts, 5);
	o->UpdateRect(&cr, false);
	if(parent && bActive)parent->Command(CMD_TABDLG, this, o);
}

bool
InputText::Select(int x, int y, anyOutput *o)
{
	POINT p1;

	p1.x = x;		p1.y = y;
	if(bActive && IsInRect(&cr, x, y) && !(flags & NOEDIT)) {
		DialogFocus = DialogTabStop = this;
		if(parent) parent->Command(CMD_FOCTXT, (void*)this, 0L);
		o->SetTextSpec(&TextDef);
		if(Text) Text->Update(1, o, &p1); 
		if(flags & TOUCHEXIT) parent->Command(CMD_ENDDIALOG, (void *)this, o);
		return true;
		}
	return false;
}

bool
InputText::GetValue(int id, double *val)
{
	if(Text) {
		Text->Update(20, NULL, 0L);			//convert string to value
		return Text->GetValue(val);
		}
	return false;
}

bool
InputText::GetInt(int id, int *val)
{
	if(type == EDTEXT) {
		if(Text) *val = Text->Cursor();
		else *val = 0;
		return true;
		}
	if(Text && Text->text) {
		sscanf(Text->text, "%d", val);
		return true;
		}
	return false;
}

bool
InputText::GetText(int id, char *txt)
{
	if(Text && Text->text && Text->text[0]) {
		strcpy(txt, Text->text);
		return true;
		}
	return false;
}

void
InputText::MBtrack(MouseEvent *mev, anyOutput *o)
{
	bool bLBstate;
	int x, y;

	x = mev->x;						y = mev->y;
	if(mev->StateFlags &1) bLBstate = true;
	else bLBstate = false;
	if(bActive && IsInRect(&cr, x, y) && !(flags & NOEDIT) && 
		bLBstate && Text) {
		DialogFocus = this;
		if(parent) parent->Command(CMD_FOCTXT, (void*)this, 0L);
		o->SetTextSpec(&TextDef);
		Text->Command(CMD_MOUSE_EVENT, o, (DataObj *)mev);
		}
}

void
InputText::Activate(int id, bool activate)
{
	bActive = activate;
	if(Text && Disp) {
		Disp->SetTextSpec(&TextDef);
		if(bActive){
			Text->Update(1, Disp, 0L);
			DialogFocus = DialogTabStop = this;
			if(parent) parent->Command(CMD_FOCTXT, this, Disp);
			}
		else Text->Update(2, Disp, 0L);
		}
}

RangeInput::RangeInput(tag_DlgObj *par, DlgInfo * desc, RECT rec, char *text)
	:InputText(par, desc, rec, text)
{
	data = 0L;
}

RangeInput::~RangeInput()
{
	if(data) data->Command(CMD_ETRACC, 0L, 0L);
	if(Text) delete (Text);		Text = 0L;
}

bool
RangeInput::Command(int cmd, void *tmpl, anyOutput *o)
{
	switch(cmd) {
	case CMD_SET_DATAOBJ:
		data = (DataObj*)tmpl;
		return true;
		}
	return InputText::Command(cmd, tmpl, o);
}

bool
RangeInput::Select(int x, int y, anyOutput *o)
{
	bool bRes;

	bRes = InputText::Select(x, y, o);
	if(bRes && data) {
		if(DialogFocus == this) data->Command(CMD_ETRACC, Text, 0L);
		else data->Command(CMD_ETRACC, 0L, 0L);
		}
	return bRes;
}

void
RangeInput::Activate(int id, bool activate)
{
	InputText::Activate(id, activate);
	if(activate && data) data->Command(CMD_ETRACC, Text, 0L);
}

InputValue::InputValue(tag_DlgObj *par, DlgInfo * desc, RECT rec, double *value)
	:InputText(par, desc, rec, 0L)
{
	WriteNatFloatToBuff(TmpTxt, *value);
	if(Text) Text->text = strdup(TmpTxt+1);
}

InputValue::~InputValue()
{
	if(Text) delete (Text);
	Text = 0L;					//in fact the destructor of InputText is also
								//  called. This prevents a double delete of Text.
}

IncDecValue::IncDecValue(tag_DlgObj *par, DlgInfo * desc, RECT rec, double *value)
	:InputText(par, desc, rec, 0L)
{
	int ab1 = 1, ab2 = 2;
	static DlgInfo ab[] = {
		{1, 2, 0, 0x0L, ARROWBUTT, (void*)&ab1, 0, 0, 0, 0},
		{2, 0, 0, LASTOBJ, ARROWBUTT, (void*)&ab2, 0, 0, 0, 0}};
	RECT br;

	WriteNatFloatToBuff(TmpTxt, *value);
	if(Text) Text->text = strdup(TmpTxt+1);
	br.left = cr.right+1;		br.right = br.left + 7*xbase;
	br.top = cr.top+1;			br.bottom = br.top + 5*ybase;
	butts[0] = new ArrowButton(this, &ab[0], br, &ab1);
	br.top += 5*ybase;			br.bottom += 5*ybase;
	butts[1] = new ArrowButton(this, &ab[1], br, &ab2);
}

IncDecValue::~IncDecValue()
{
	if(Text) delete (Text);
	if(butts[0]) delete (butts[0]);
	if(butts[1]) delete (butts[1]);
	Text = 0L;
}

void
IncDecValue::DoPlot(anyOutput *o)
{
	InputText::DoPlot(o);
	if(butts[0]) butts[0]->DoPlot(o);
	if(butts[1]) butts[1]->DoPlot(o);
}

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

	if(x > cr.right) {
		if(butts[0]) bRet = butts[0]->Select(x, y, o);
		if(!bRet && butts[1]) bRet = butts[1]->Select(x, y, o);
		}
	else return InputText::Select(x, y, o);
	if(bRet && parent) {
		DialogFocus = DialogTabStop = 0L;
		if(parent) parent->Command(CMD_FOCTXT, (void*)0L, 0L);
		if(flags & TOUCHEXIT) parent->Command(CMD_ENDDIALOG, (void *)this, o);
		}
	return bRet;
}

void
IncDecValue::MBtrack(MouseEvent *mev, anyOutput *o)
{
	if(mev->x >cr.right) {
		if(butts[0]) butts[0]->MBtrack(mev, o);
		if(butts[1]) butts[1]->MBtrack(mev, o);
		}
	else InputText::MBtrack(mev, o);
}

⌨️ 快捷键说明

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