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

📄 spreadwi.cpp

📁 Linux/windows 环境下跨平台开发程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		mev = (MouseEvent *) tmpl;		p.x = mev->x;				p.y = mev->y;		if((mev->StateFlags & 1) || mev->Action == MOUSE_LBUP) {			mpos2dpos(&p, &cp);			if(cp.y >= cRows || cp.x >= cCols || cp.y < 0 || cp.x < 0) return false;			}
		switch (mev->Action) {		case MOUSE_LBDOWN:
			if(m_range && (mev->StateFlags & 0x08)) mrk_offs = strlen(m_range);
			else mrk_offs = 0;			bActive = true;		new_mark = false;			if(!et_racc && CurrText && !CurrText->isInRect(&p)){				CurrText->Update(2, w, &p);			 CurrText = 0L;					DoPlot(w);				}			if(p.x < FirstWidth) cp.x = 0;			if(p.y < (w->MenuHeight+CellHeight)) cp.y = 0;			currpos.y = currpos2.y = cp.y;
			currpos.x = currpos2.x = cp.x;		case MOUSE_LBDOUBLECLICK:		case MOUSE_MOVE:			if(!bActive) return false;			if(!m_range && !CurrText && cp.y < cRows && cp.x < cCols && cp.y >= 0 && cp.x >= 0)				CurrText = etRows[cp.y][cp.x];			if(mev->Action == MOUSE_MOVE && (mev->StateFlags & 1) 				&& !(CurrText && CurrText->isInRect(&p))) {				//mark rectangular range				if(!et_racc && !m_range && CurrText) {					CurrText->Update(2, w, &p);		 CurrText = 0L;						}				if(p.x < FirstWidth || p.y < (w->MenuHeight+CellHeight)) {
					i = sprintf(TmpTxt+mrk_offs, "%s%s%d:", mrk_offs? ";" : "", Int2ColLabel(p.x < FirstWidth ? 0 : currpos.x, false),						p.y < (w->MenuHeight+CellHeight) ? 0 : currpos.y+1);					sprintf(TmpTxt+mrk_offs+i, "%s%d", Int2ColLabel(p.x < FirstWidth ? cCols-1 : cp.x, false), 						p.y < (w->MenuHeight+CellHeight) ? cRows : cp.y+1);					}				else {					i = sprintf(TmpTxt+mrk_offs, "%s%s%d:", mrk_offs? ";" : "", Int2ColLabel(currpos.x, false), currpos.y+1);					sprintf(TmpTxt+mrk_offs+i, "%s%d", Int2ColLabel(cp.x, false), cp.y+1);					}				if(!CurrText || et_racc)MarkRange(TmpTxt);				return true;				}			if(mev->Action == MOUSE_LBDOUBLECLICK) bActive = false;			if(!(mev->StateFlags & 1)) return false;			if(CurrText && CurrText->isInRect(&p)) {				return CurrText->Command(CMD_MOUSE_EVENT, o, (DataObj *)mev);				}			if(etRows[cp.y][cp.x]) 				return etRows[cp.y][cp.x]->Command(CMD_MOUSE_EVENT, o, (DataObj *)mev);			return false;		case MOUSE_LBUP:			if(bActive){
				isRowMark = p.x < FirstWidth;
				isColMark = p.y < (w->MenuHeight+CellHeight);
				if(isRowMark || isColMark) {					if(p.x < FirstWidth) {						currpos.x = 0;	cp.x = cCols-1;						}					if(p.y < (w->MenuHeight+CellHeight)) {						currpos.y = 0;	cp.y = cRows-1;						}					i = sprintf(TmpTxt+mrk_offs, "%s%s%d:", mrk_offs? ";" : "", Int2ColLabel(currpos.x, false), currpos.y+1);					sprintf(TmpTxt+mrk_offs+i, "%s%d", Int2ColLabel(cp.x, false), cp.y+1);					MarkRange(TmpTxt);
					currpos2.x = cp.x;		currpos2.y = cp.y + 1;					}
				else if((m_range) && !new_mark) HideMark(false);
				if(et_racc) {
					CurrText = et_racc;
					if(m_range && m_range[0]) {
						CurrText->Command(CMD_ADDTXT, o, (DataObj*) m_range);
						}
					else if(!m_range) {
						m_range = (char*)malloc(10);
						sprintf(m_range, "%s%d%", Int2ColLabel(currpos.x, false), currpos.y+1);
						CurrText->Command(CMD_ADDTXT, o, (DataObj*) m_range);
						free(m_range);	m_range = 0L;
						}
					}				else if(m_range) {					CurrText = etRows[currpos.y][currpos.x];	CurrText->Update(1, w, &p);					DoPlot(w);
					currpos2.x = cp.x;		currpos2.y = cp.y;
					}				else return Select(&p);				}			}		break;	case CMD_PASTE_TSV:		case CMD_PASTE_XML:	case CMD_PASTE_CSV:	case CMD_PASTE_SSV:		if(PasteRange(cmd, (char*)tmpl)) 
			return Disp->Command(CMD_SETSCROLL, 0L, w);
		return false;
	case CMD_ETRACC:
		et_racc = (EditText*) tmpl;
		if(CurrText && CurrText->parent != this) CurrText = 0L;
		return true;
	case CMD_CURRPOS:
		if(tmpl) {
			if(((POINT*)tmpl)->x < 0 && ((POINT*)tmpl)->y < 0) {
				((POINT*)tmpl)->x = currpos.x;		((POINT*)tmpl)->y = currpos.y;
				return true;
				}
			}
		return false;	case CMD_UNLOCK:		HideMark(false);
		currpos2.x = currpos.x;		currpos2.y = currpos.y;		break;	case CMD_ERROR:		err_msg = (char*)tmpl;		break;
	case CMD_UPDATE:
		bUpdate = true;
		break;
	case CMD_SAVEPOS:
		return SavePos();	case CMD_CLEAR_ERROR:		err_msg = last_err = 0L;		break;	case CMD_TOOLMODE:						//ESC pressed		HideMark(true);		if(CurrText){
			CurrText->Update(2, w, 0L);		CurrText->Update(1, w, 0L);
			}
		et_racc = 0L;		break;	case CMD_UPDHISTORY:		if(w) w->FileHistory();		break;
	case CMD_MRK_DIRTY:
		move_cr = CMD_CURRDOWN;
		last_err = 0L;
		if(Disp) return Disp->Command(cmd, tmpl, o);
		return false;	case CMD_ADDCHAR:
		if(CurrText){
			if(currpos.y < Disp->ssOrg.y) {
				Disp->ssOrg.y = currpos.y;					Disp->Command(CMD_SETSCROLL, 0L, w);
				}
			else if(currpos.y > (Disp->ssOrg.y + r_disp -3)) {
				Disp->ssOrg.y = currpos.y - (r_disp-3);
				if(Disp->ssOrg.y < 0) Disp->ssOrg.y = 0;	Disp->Command(CMD_SETSCROLL, 0L, w);
				}
			if(currpos.x < Disp->ssOrg.x) {
				Disp->ssOrg.x = currpos.x;					Disp->Command(CMD_SETSCROLL, 0L, w);
				}
			else if(currpos.x > (Disp->ssOrg.x + c_disp -3)) {				Disp->ssOrg.x = currpos.x - (c_disp-3);
				if(Disp->ssOrg.x < 0) Disp->ssOrg.x = 0;	Disp->Command(CMD_SETSCROLL, 0L, w);
				}
			currpos2.x = currpos.x;		currpos2.y = currpos.y;
			i = *((int*)tmpl);			Disp->Command(CMD_CURRPOS, &currpos, w);
			if(i == 27) return Command(CMD_TOOLMODE, tmpl, o);			if(i !=3 && i != 22 && i != 24 && i != 26) HideMark(true);	//Do not hide upon ^C, ^V, ^X, ^Z			if(i == 13) return CurrText->Command(move_cr, w, this);			switch(i) {			case 8: return CurrText->Command(CMD_BACKSP, w, this);	//Backspace			default: return CurrText->AddChar(*((int*)tmpl), w, Disp);				}			}
		else {
			currpos.x = currpos2.x = Disp->ssOrg.x;			currpos.y = currpos2.y = Disp->ssOrg.y;
			if(etRows[currpos.x] && (CurrText = etRows[currpos.x][currpos.y]))
				CurrText->Update(1, w, &p);;
			}
		Disp->Command(CMD_CURRPOS, &currpos, w);
		break;
	case CMD_SHIFTUP:
		if(Disp->ssOrg.y && currpos2.y <= Disp->ssOrg.y) {
			Disp->ssOrg.y --;						Disp->Command(CMD_SETSCROLL, 0L, w);
			}
		currpos2.y -= 2;
	case CMD_SHIFTDOWN:
		if(cmd == CMD_SHIFTDOWN && r_disp > 3 && (currpos2.y-Disp->ssOrg.y) >= (r_disp-3)) {
			Disp->ssOrg.y ++;						Disp->Command(CMD_SETSCROLL, 0L, w);
			}
		currpos2.y ++;
		if(currpos2.y >= cRows) currpos2.y --;		if(currpos2.y < 0) currpos2.y ++;
		//mark rectangular range
		i = sprintf(TmpTxt, "%s%d:", Int2ColLabel(currpos.x, false), currpos.y+1);
		sprintf(TmpTxt+i, "%s%d", Int2ColLabel(currpos2.x, false), currpos2.y+1);
		MarkRange(TmpTxt);							HideTextCursor();
		break;
	case CMD_SHIFTRIGHT:	case CMD_SHIFTLEFT:
		if(!m_range && CurrText && CurrText->Command(cmd, w, this)) break;
		if(cmd == CMD_SHIFTLEFT && c_disp > 3 && Disp->ssOrg.x && (currpos2.x-Disp->ssOrg.x) < 1) {
			Disp->ssOrg.x --;						Disp->Command(CMD_SETSCROLL, 0L, w);
			}
		if(cmd == CMD_SHIFTRIGHT && c_disp > 3 && (currpos2.x-Disp->ssOrg.x) >= (c_disp-3)) {
			Disp->ssOrg.x ++;						Disp->Command(CMD_SETSCROLL, 0L, w);
			}
		if(cmd == CMD_SHIFTLEFT) currpos2.x --;
		else currpos2.x ++;
		if(currpos2.x >= cCols) currpos2.x --;		if(currpos2.x < 0) currpos2.x ++;
		//mark rectangular range
		i = sprintf(TmpTxt, "%s%d:", Int2ColLabel(currpos.x, false), currpos.y+1);
		sprintf(TmpTxt+i, "%s%d", Int2ColLabel(currpos2.x, false), currpos2.y+1);
		MarkRange(TmpTxt);							HideTextCursor();
		break;
	case CMD_SHPGUP:
		if(Disp->ssOrg.y >0) {
			Disp->ssOrg.y -= (r_disp-2);
			if(Disp->ssOrg.y < 0) Disp->ssOrg.y = 0;
			Disp->Command(CMD_SETSCROLL, 0L, w);
			currpos2.y -= r_disp;					if(currpos2.y < 0) currpos2.y = 0;
			i = sprintf(TmpTxt, "%s%d:", Int2ColLabel(currpos.x, false), currpos.y+1);
			sprintf(TmpTxt+i, "%s%d", Int2ColLabel(currpos2.x, false), currpos2.y+1);
			MarkRange(TmpTxt);							HideTextCursor();
			}
		break;
	case CMD_SHPGDOWN:
		i = (Disp->ssOrg.y + 2*r_disp) < cRows ? r_disp-2 : cRows-r_disp - Disp->ssOrg.y+3;
		if(i > 0) {
			Disp->ssOrg.y += i;						Disp->Command(CMD_SETSCROLL, 0L, w);
			}
		if(currpos2.y < (cRows-1)) {
			currpos2.y += r_disp;					if(currpos2.y >= cRows) currpos2.y = cRows-1;
			//mark rectangular range
			i = sprintf(TmpTxt, "%s%d:", Int2ColLabel(currpos.x, false), currpos.y+1);
			sprintf(TmpTxt+i, "%s%d", Int2ColLabel(currpos2.x, false), currpos2.y+1);
			MarkRange(TmpTxt);							HideTextCursor();
			}
		break;
	case CMD_CURRIGHT:		case CMD_CURRDOWN:		move_cr = cmd;	case CMD_CURRLEFT:		case CMD_CURRUP:	case CMD_POS_FIRST:		case CMD_POS_LAST:
		if(cmd == CMD_CURRUP && Disp->ssOrg.y && CurrText && currpos.y == Disp->ssOrg.y) {
			Disp->ssOrg.y --;		currpos.y --;
			DoPlot(o);
			}		if(cmd == CMD_CURRLEFT && Disp->ssOrg.x && CurrText && (!CurrText->Cursor()) && (currpos.x == Disp->ssOrg.x)) {
			Disp->ssOrg.x --;		currpos.x --;	
			CurrText->Update(2, o, 0L);
			Disp->Command(CMD_CURRPOS, &currpos, w);
			if(etRows && etRows[currpos.y] && etRows[currpos.y][currpos.x]) 
				CurrText = etRows[currpos.y][currpos.x];
			if(CurrText){
				CurrText->Command(CMD_POS_LAST, o, this);		CurrText->Update(1, o, 0L);
				}
			DoPlot(o);		return false;
			}
		if(cmd == CMD_CURRIGHT && c_disp > 3 && (currpos.x-Disp->ssOrg.x) >= (c_disp-3)) {
			Disp->ssOrg.x ++;		currpos.y ++;			DoPlot(o);
			if(CurrText) CurrText->Command(CMD_POS_FIRST, o, this);
			}
		if(cmd == CMD_CURRDOWN && r_disp > 3 && (currpos.y-Disp->ssOrg.y) >= (r_disp-3)) {
			Disp->ssOrg.y ++;		currpos.y ++;			DoPlot(o);
			}
		Disp->Command(CMD_CURRPOS, &currpos, w);
		HideMark(false);		currpos2.x = currpos.x;								currpos2.y = currpos.y;
		if(CurrText)return CurrText->Command(cmd, w, this);		else {
			currpos.x = currpos2.x = Disp->ssOrg.x;			currpos.y = currpos2.y = Disp->ssOrg.y;
			if(etRows[currpos.y] && (CurrText = etRows[currpos.y][currpos.x]))
				CurrText->Update(1, w, &p);;
			}
		return false;	case CMD_SHTAB:		if(currpos.y >= cRows) currpos.y = cRows-1;		if(currpos.x == Disp->ssOrg.x && Disp->ssOrg.x > 0) {			Disp->ssOrg.x -= 1;			Disp->Command(CMD_SETSCROLL, 0L, w);			}		if(currpos.x > Disp->ssOrg.x && etRows[currpos.y][currpos.x]) {			currpos.x -=1;			}	case CMD_TAB:		if(currpos.y >= cRows) currpos.y = cRows-1;		if(cmd == CMD_TAB && currpos.x < (cCols-1) && etRows[currpos.y][currpos.x]) {			if((FirstWidth+(currpos.x - Disp->ssOrg.x +2)*CellWidth) > Disp->currRC.right){				Disp->ssOrg.x += 1;				Disp->Command(CMD_SETSCROLL, 0L, w);				}			currpos.x +=1;			}		if(CurrText) CurrText->Update(2, w, &p);		CurrText = etRows[currpos.y][currpos.x];		if(CurrText){			CurrText->Update(1, w, &p);			CurrText->Command(cmd == CMD_TAB ? CMD_POS_FIRST : CMD_POS_LAST, o, this);			}		Disp->Command(CMD_CURRPOS, &currpos, w);
		return true;	case CMD_UNDO:
		if(w) {
			w->MouseCursor(MC_WAIT, true);
			Undo.Restore(true, w);
			w->MouseCursor(MC_ARROW, true);
			if(et_racc) {
				CurrText = et_racc;
				CurrText->Update(1, w, 0L);
				}
			}
		return true;
	case CMD_DELETE:		if(m_range) DelRange();		else if(CurrText) return CurrText->Command(cmd, o, this);		Disp->Command(CMD_CURRPOS, &currpos, w);
		return true;	case CMD_QUERY_COPY:		case CMD_CUT:		return InitCopy(cmd, tmpl, w);	case CMD_GET_CELLDIMS:		if(tmpl) {			((int*)tmpl)[0] = FirstWidth;	((int*)tmpl)[1] = CellWidth;			((int*)tmpl)[2] = CellHeight;			}		break;	case CMD_SET_CELLDIMS:		if(tmpl) {			FirstWidth = ((int*)tmpl)[0];	CellWidth = ((int*)tmpl)[1];			CellHeight = ((int*)tmpl)[2];			}		break;
	case CMD_TEXTSIZE:		if(tmpl) return Disp->Command(cmd, tmpl, o);		return false;	case CMD_COPY_TSV:		return MemList((unsigned char**)tmpl, FF_TSV);	case CMD_COPY_SYLK:		return MemList((unsigned char**)tmpl, FF_SYLK);	case CMD_COPY_XML:		return MemList((unsigned char**)tmpl, FF_XML);
	case CMD_DOPLOT:	case CMD_REDRAW:
		if(CurrText) CurrText->Update(2, 0L, 0L);
		if(etRows && etRows[currpos.y] && currpos.y < cRows && currpos.x < cCols) 
			if(CurrText = etRows[currpos.y][currpos.x]) CurrText->Update(1,0L, 0L);
		DoPlot(o);		break;	case CMD_FILLRANGE:
		Undo.SetDisp(w);		FillSsRange(this, &m_range, Disp);
		DoPlot(o);		Undo.SetDisp(w);
		break;
	case CMD_INSROW:
		return InsertRows();
	case CMD_INSCOL:
		return InsertCols();
	case CMD_DELROW:
		return DeleteRows();
	case CMD_DELCOL:
		return DeleteCols();
	}	return true;}boolSpreadData::ReadXML(char *file, unsigned char *buffer, int type, DWORD undo_flags){	int i, row, col, tag, cpgr, spgr, ufl = 0;	bool bContinue, bRet = false, bUndo_done = false;	ReadCache *XMLcache;	POINT pt, mov;	char TmpTxt[1024], *tmp_range;
	unsigned char *pgr = 0L;
	RECT rc_undo;	if(file) {		if(!(XMLcache = new ReadCache())) return false;		if(! XMLcache->Open(file)) {			delete XMLcache;			sprintf(TmpTxt, "Error open file\n\"%s\"", file);			ErrorBox(TmpTxt);			return false;			}
		bUndo_done = true;		if(!Init(1, 1)) goto XMLError;
		etRows[0][0]->SetText("");		}	else if(buffer && type == FF_XML){		if(!(XMLcache = new MemCache(buffer))) return false;		if(buffer && bCopyCut) {			tmp_range = m_range;	m_range = c_range;			c_range = 0L;			DelRange();			m_range = tmp_range;			}		}	else return false;	pt.x = pt.y = mov.x = mov.y = 0;	cp_src_rec.left = cp_src_rec.right = cp_src_rec.top = cp_src_rec.bottom = 0;	do {		row = col = 0;		do {			TmpTxt[0] = XMLcache->Getc();			}while(TmpTxt[0] && TmpTxt[0] != '<');		for(i = 1; i < 5; TmpTxt[i++] = XMLcache->Getc());		TmpTxt[i] = 0;		if(!strcmp("<cell", TmpTxt)){
			if(!bUndo_done) {
				rc_undo.left = currpos.x;
				rc_undo.right = cp_src_rec.right - cp_src_rec.left + currpos.x;
				rc_undo.top = currpos.y;
				rc_undo.bottom = cp_src_rec.bottom - cp_src_rec.top + currpos.y;
				if(ufl == 3) Undo.DataObject(Disp, w, this, &rc_undo, undo_flags);
				bUndo_done = true;
				}
 			tag = 1;
			}		else if(!strcmp("<pos1", TmpTxt)) tag = 2;		else if(!strcmp("<pos2", TmpTxt)) tag = 3;
		else if(!strcmp("<RLPl", TmpTxt)) {
			do {
				TmpTxt[i++] = XMLcache->Getc();
				}while(TmpTxt[i-1] > 31 && TmpTxt[i-1] != '>');
			TmpTxt[i] = 0;
			row = col = 0;
			if(TmpTxt[17] = '=' && TmpTxt[13] == 'r') {
				strcpy(TmpTxt, TmpTxt+19);
				}
			else break;
			sscanf(TmpTxt, "%d", &row);
			for(i = 0; TmpTxt[i] && TmpTxt[i] != '='; i++);
			ssc

⌨️ 快捷键说明

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