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

📄 spreadwi.cpp

📁 Linux/windows 环境下跨平台开发程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		mp->y += CellHeight;		}	if(mp->x > (Disp->currRC.right-w->MenuHeight-10) && Disp->ssOrg.x < (cCols-2)) {		Disp->ssOrg.x += 1;		if(CurrText) CurrText->Update(2, w, mp);		CurrText = 0L;		Disp->Command(CMD_SETSCROLL, 0L, w);		mp->x -= CellWidth;		}	if(mp->y > (Disp->currRC.bottom-10) && Disp->ssOrg.y < (cRows-5)) {		Disp->ssOrg.y += 1;		do {			mp->y -= CellHeight;		} while(mp->y > (Disp->currRC.bottom-CellHeight));		if(CurrText) CurrText->Update(2, w, mp);		CurrText = 0L;		Disp->Command(CMD_SETSCROLL, 0L, w);		}	dp->y = (mp->y - w->MenuHeight - CellHeight)/CellHeight + Disp->ssOrg.y;	dp->x = (mp->x - FirstWidth)/CellWidth + Disp->ssOrg.x;	if(dp->y >= cRows) dp->y = cRows-1;		if(dp->x >= cCols) dp->x = cCols-1;	return true;}

boolSpreadData::Select(POINT *p){	if(CurrText && CurrText->isInRect(p)){		CurrText->Update(1, w, p);		Disp->Command(CMD_CURRPOS, &currpos, w);
		if(CurrText->isFormula() && CurrText->hasMark()) et_racc = CurrText;
		return true;		}	mpos2dpos(p, &currpos);	if(currpos.y < cRows && currpos.x < cCols && currpos.y >= 0 && currpos.x >= 0) {		if(etRows[currpos.y][currpos.x]) {			if(etRows[currpos.y][currpos.x] == CurrText) CurrText->Update(1, w, p);			else {				if(CurrText) CurrText->Update(2, w, p);				CurrText = etRows[currpos.y][currpos.x];				DoPlot(w);				CurrText->Update(1, w, p);				}			Disp->Command(CMD_CURRPOS, &currpos, w);
			return true;			}		}	if(CurrText) CurrText->Update(2, w, p);		CurrText = 0L;	return false;}voidSpreadData::MarkRange(char *range){	AccRange *nr, *oldr;	int r, c;
	oldr = nr = 0L;	if(m_range && range && !strcmp(m_range, range)) return;		//no change	if(m_range) oldr = new AccRange(m_range);	if(range) nr = new AccRange(range);	if(oldr && nr && oldr->GetFirst(&c, &r)) {		for( ; oldr->GetNext(&c, &r); ) {			if(r >= Disp->ssOrg.y && r < (r_disp +Disp->ssOrg.y) && c >= Disp->ssOrg.x 				&& c < (c_disp + Disp->ssOrg.x) && !nr->IsInRange(c, r) && etRows[r] && etRows[r][c]){				etRows[r][c]->Mark(w, etRows[r][c] != CurrText ? 0 : 1);				}			}		}	if(nr && nr->GetFirst(&c, &r)) {		for( ; nr->GetNext(&c, &r); ) {			if(r >= Disp->ssOrg.y && r < (r_disp +Disp->ssOrg.y) && c >= Disp->ssOrg.x 				&& c < (c_disp + Disp->ssOrg.x) && r < cRows && c < cCols)				etRows[r][c]->Mark(w, etRows[r][c] != CurrText ? 2 : 3);			}		}
	if(range && (m_range = (char*)realloc(m_range, strlen(range)+6)))
		strcpy(m_range, range);	else if (m_range) m_range[0] = 0;
	if(oldr) delete(oldr);	if(nr) delete(nr);	new_mark = true;}voidSpreadData::HideMark(bool cclp){	if(cclp && c_range && c_range != m_range){		free(c_range);	c_range = 0L;		rcCopy.left = rcCopy.top = 0;		rcCopy.bottom = cRows;		rcCopy.right = cCols;		}	if(m_range){		free(m_range);	m_range = 0L;		DoPlot(w);		}	if(cclp) EmptyClip();	new_mark = false;}boolSpreadData::WriteData(char *FileName){	FILE *File;	int i, j;	char tmp[800];	unsigned char *buff = 0L;	if(!cRows || !cCols || !etRows) return false;	BackupFile(FileName);	if(!(File = fopen(FileName, "w")))return false;	HideMark(true);	rcCopy.left = rcCopy.top = 0;	rcCopy.bottom = cRows;		rcCopy.right = cCols;	i = strlen(FileName);	//test for xml extension	if(!strcmp(".xml", FileName+i-4) || !strcmp(".XML", FileName+i-4)) {		MemList(&buff, FF_XML);		if(buff){			fprintf(File, "%s", buff);			free(buff);					fclose(File);			return true;			}
		return false;		}	//test for tsv extension	if(!strcmp(".tsv", FileName+i-4) || !strcmp(".TSV", FileName+i-4)) {		MemList(&buff, FF_TSV);		if(buff){			fprintf(File, "%s", buff);			free(buff);					fclose(File);			return true;			}
		return false;		}
	//test for rlw extension
	if(!strcmp(".rlw", FileName+i-4) || !strcmp(".RLW", FileName+i-4)) {
		MemList(&buff, FF_RLW);
		if(buff){
			fprintf(File, "%s", buff);
			free(buff);					fclose(File);
			return true;
			}
		return false;
		}
	//else write csv	for(i = 0; i < cRows; i++) {		for(j = 0; j < cCols; j++) {			if(etRows[i][j] && etRows[i][j]->GetItem(tmp, sizeof(tmp)))				fprintf(File, "%s", tmp);			if(j < (cCols-1)) fprintf(File, ",");			}		fprintf(File, "\n");		}	fclose(File);	return true;}boolSpreadData::ReadData(char *FileName, unsigned char *buffer, int type){	int i, j, l;	char ItemText[20];	bool success;	POINT pt;	if(FileName) {		//read disk file
		Disp->Command(CMD_CAN_DELETE, 0L, 0L);
		if(0 == strcmp(".xml", FileName+strlen(FileName)-4) ||			0 == strcmp(".XML", FileName+strlen(FileName)-4) ||
			0 == strcmp(".rlw", FileName+strlen(FileName)-4) ||
			0 == strcmp(".RLW", FileName+strlen(FileName)-4) ||
			IsXmlFile(FileName)){			if(ReadXML(FileName, buffer, type, 0L)){				rcCopy.left = rcCopy.top = 0;				rcCopy.right = cCols;			rcCopy.bottom = cRows;				return true;				}			return false;			}		if(0 == strcmp(".tsv", FileName+strlen(FileName)-4) ||			0 == strcmp(".TSV", FileName+strlen(FileName)-4)){			if(ReadTSV(FileName, buffer, type)){				rcCopy.left = rcCopy.top = 0;				rcCopy.right = cCols;			rcCopy.bottom = cRows;				return true;				}			return false;			}		if(!(Cache = new ReadCache())) return false;		if(! Cache->Open(FileName)) {			delete Cache;			sprintf(TmpTxt, "Error open data file\n\"%s\"", FileName);			ErrorBox(TmpTxt);			return false;			}		if(!Init(1, 1)) goto ReadError;		}	else if(buffer) {	//read memory buffer		switch(type) {		case FF_TSV:			return ReadTSV(FileName, buffer, type);		case FF_XML:			return ReadXML(FileName, buffer, type, 0L);		case FF_CSV:			if(!(Cache = new MemCache(buffer))) return false;			break;		default:			ErrorBox("Read from buffer with\nunknown format failed.");			return false;			}		}	else return false;	i = j = 0;	pt.x = pt.y = 0;		//pt is a dummy argument only	do {		if((success = GetItemCSV(ItemText, sizeof(ItemText)-1)) || ItemText[0]){			if(j >= cCols && !AddCols(j+1)) goto ReadError;			if(i >= cRows && !AddRows(i+1)) goto ReadError;			if(etRows[i][j]) etRows[i][j]->SetText("");			l = strlen(ItemText);			if(l>1 && ItemText[0] == '"') {				ItemText[l-1] = 0;				etRows[i][j]->SetText(ItemText+1);				etRows[i][j]->Update(20, 0L, &pt);				}			else if(l){				etRows[i][j]->SetText(ItemText);				etRows[i][j]->Update(10, 0L, &pt);				}			j++;			}		if(!success && !Cache->IsEOF()) {i++; j = 0;}	//eol		}while (ItemText[0] || !Cache->IsEOF());		//eof	Cache->Close();	delete Cache;	Cache = 0L;	if(FileName) {		rcCopy.left = rcCopy.top = 0;		rcCopy.right = cCols;		rcCopy.bottom = cRows;		}	Disp->ssOrg.x = Disp->ssOrg.y = 0;	return true;ReadError:	Cache->Close();	delete Cache;	Cache = 0L;	return false;}boolSpreadData::AddCols(int nCols){	EditText **NewRow;	int i, j;	if (nCols <= cCols || !etRows || !etRows[0] || !etRows[0][cCols-1]) return false;	for(i = 0; i < cRows; i++) {		if(NewRow = (EditText **)realloc(etRows[i], nCols * sizeof(EditText*))){			for(j = cCols; j < nCols; j++) {				NewRow[j] = new EditText(this, 0L, i, j);				}			etRows[i] = NewRow;			}		else return false;						//memory allocation error		}	cCols = nCols;	return true;}boolSpreadData::AddRows(int nRows){	int i, j;	EditText ***NewRows;	if (nRows <= cRows || !etRows || !etRows[cRows-1] || !etRows[cRows-1][0] ) return false;	NewRows = (EditText ***)realloc(etRows, nRows * sizeof(EditText **));	if(NewRows) etRows = NewRows;	else return false;					//memory allocation error
	for(i = cRows; i < nRows; i++){		etRows[i] = (EditText **)calloc(cCols, sizeof(EditText *));		if(etRows[i]) {			for(j = 0; j < cCols; j++) etRows[i][j] = new EditText(this, 0L, i, j);			}		else {							//memory allocation error			cRows = i-1;			return false;			}		}	cRows = nRows;	return true;}boolSpreadData::ChangeSize(int nCols, int nRows, bool bUndo){	int i, j;	bool RetVal = true;	
	if(nCols == cCols && nRows == cRows) return true;
	if(bUndo) Undo.DataObject(Disp, w, this, 0L, 0L);	if(nRows && nRows < cRows) {		for (i = nRows; i < cRows; i++) {			if(etRows[i]) for (j = 0; j < cCols; j++) {				if(etRows[i][j]) delete etRows[i][j];				etRows[i][j] = NULL;				}			free(etRows[i]);			etRows[i] = NULL;			}		cRows = nRows;		}	if(nCols && nCols < cCols) {		for (i = 0; i < cRows; i++) {			for (j = nCols; j < cCols; j++) {				if(etRows[i][j]) delete etRows[i][j];				etRows[i][j] = NULL;				}			}		cCols = nCols;		}	if(nCols > cCols) if(!AddCols(nCols))RetVal = false;	if(RetVal && nRows > cRows) if(!AddRows(nRows))RetVal = false;	if(w) {		sprintf(TmpTxt, "%d00", nRows);		w->oGetTextExtent(TmpTxt, 0, &i, &j);		if(i > FirstWidth) FirstWidth = i;		Disp->Command(CMD_SETSCROLL, 0L, w);		}	return RetVal;}
bool
SpreadData::DeleteCols()
{
	int i, j, r0, c0, c1, c2, cn, dc, nc;
	RECT rc;
	lfPOINT *cs;

	AccRange * ar;
	if(!isColMark || !m_range || !m_range[0]){
		InfoBox("No columns selected!");
		return false;
		}
	Undo.DataObject(Disp, w, this, 0L, 0L);
	Undo.String(0L, &m_range, UNDO_CONTINUE);
	if(!(ar = new AccRange(m_range))) return false;
	ar->BoundRec(&rc);
	if(!(cs = (lfPOINT*)malloc((rc.right-rc.left+2)*sizeof(lfPOINT)))) {
		delete ar;			return false;
		}
	if(!(ar->GetFirst(&c0, &r0))) {
		free(cs);			delete ar;			return false;
		}
	ar->NextCol(&c1);		cn = c1;			nc = 0;
	do {
		for(c0 = c1 = c2 = cn; ar->NextCol(&c2); ) {
			if(c2 > c1+1 || c2 < c0) break;
			c1 = c2;
			}
		dc = c1-c0+1;		cn = c2;
		cs[nc].fx = c0;		cs[nc].fy = c1;		nc++;
		}while(c2!=c1);
	SortFpArray(nc, cs);	nc--;
	do {
		c0 = (int)cs[nc].fx;	c1 = (int)cs[nc].fy;	dc = c1-c0+1;
		for(i = 0; i < cRows; i++) {
			for(j = c0+dc; j <cCols; j++) {
				if(etRows && etRows[i] && etRows[i][j] && etRows[i][j-dc]) {
					switch(etRows[i][j]->type) {
					default:
						etRows[i][j-dc]->SetText(etRows[i][j]->text);
						break;
					case ET_VALUE:
						etRows[i][j-dc]->SetText(etRows[i][j]->text);
						etRows[i][j-dc]->Value = etRows[i][j]->Value; 
						etRows[i][j-dc]->type = ET_VALUE;
						break;
					case ET_FORMULA:
						MoveFormula(this, etRows[i][j]->text, TmpTxt, -dc, 0, -1, c0);
						etRows[i][j-dc]->SetText(TmpTxt);	etRows[i][j]->type = ET_FORMULA;
						break;
						}
					}
				}
			}
		for(i = 0; i < cRows; i++) {
			if(etRows[i]){
				for(j = cCols-dc; j < cCols; j++) if(etRows[i][j]) {
					delete(etRows[i][j]);
					etRows[i][j] = 0L;
					}
				}
			}
		cCols -= dc;
		MoveFormula(this, m_range, TmpTxt, -dc, 0, -1, c0+1);
		strcpy(m_range, TmpTxt);		nc--;
		for(i = 0; i < c0; i++) for(j = 0; j < c0; j++) {
			if(etRows && etRows[i] && etRows[i][j] && etRows[i][j]->type == ET_FORMULA) {
				MoveFormula(this, etRows[i][j]->text, TmpTxt, -dc, 0, -1, c0);
				etRows[i][j]->SetText(TmpTxt);			etRows[i][j]->type = ET_FORMULA;
				}
			}
		}while(nc >= 0);
	delete ar;
	Disp->Command(CMD_SETSCROLL, 0L, w);		Disp->Command(CMD_MRK_DIRTY, 0L, w);
	return true;
}

bool
SpreadData::InsertCols()
{
	int i, j, r0, c0, c1, c2, cn, dc, nc;
	RECT rc;
	lfPOINT *cs;

⌨️ 快捷键说明

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