summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/Excel.cpp3
-rw-r--r--noncore/apps/opie-sheet/mainwindow.cpp7
2 files changed, 7 insertions, 3 deletions
diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp
index 57aef20..338bc30 100644
--- a/noncore/apps/opie-sheet/Excel.cpp
+++ b/noncore/apps/opie-sheet/Excel.cpp
@@ -400,385 +400,386 @@ bool ExcelSheet::InitCells()
Cells[r]=NULL;
};
return true;
};
void ExcelSheet::Set(int row, int col, ExcelCell* cell)
{
if(cell!=NULL&&(row*cols+col)<Cells.count())
{
Cells[row*cols+col]=cell;
};
};
ExcelCell* ExcelSheet::Get(int row, int col)
{
ExcelCell* cell;
cell=Cells[row*cols+col];
if(cell==NULL) return NULL;
return cell;
};
int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record)
{
char* data=NULL;
switch (record->code)
{
case XL_DIMENSION:
data = GetDataOfBREC(record);
if (record->length == 10)
{
sheet->rows = Integer2Byte(data[2], data[3]);
sheet->cols = Integer2Byte(data[6], data[7]);
}
else
{
sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]);
sheet->cols = Integer2Byte(data[10], data[11]);
}
sheet->InitCells();
break;
case XL_LABELSST:
HandleLabelSST(sheet, record);
break;
case XL_RK:
case XL_RK2:
HandleRK(sheet, record);
break;
case XL_MULRK:
HandleMulrk(sheet, record);
break;
case XL_ROW:
break;
case XL_NUMBER:
HandleNumber(sheet, record);
break;
case XL_BOOLERR:
break;
case XL_CONTINUE:
break;
case XL_FORMULA:
case XL_FORMULA2:
HandleFormula(sheet, record);
break;
case XL_LABEL:
break;
case XL_NAME:
HandleName(sheet, record);
break;
case XL_BOF:
break;
case XL_EOF:
return 0;
default:
break;
};
return 1;
};
int ExcelBook::ReadSheet(ExcelSheet* sheet)
{
ExcelBREC* record;
int oldpos;
oldpos = Position;
SeekPosition(sheet->position);
record = GetBREC();
while (record!=NULL)
{
if (!SheetHandleRecord(sheet, record)) break;
record=GetBREC();
};
SeekPosition(oldpos);
return 1;
};
ExcelSheet* ExcelBook::GetSheet(void)
{
ExcelSheet* sh=NULL;
int type;
type=SeekBOF();
Version=type;
sh=new ExcelSheet;
if(type)
{
sh->type=type;
sh->position=Position;
sh->name=QString("");
};
if(type==8||type==7)
{
ReadSheet(sh);
};
return sh;
};
void ExcelBook::ParseSheets(void)
{
int BOFs;
ExcelBREC* r;
BOFs=1;
r=GetBREC();
while(BOFs)
{
r=GetBREC();
switch(r->code)
{
case XL_SST:
HandleSST(r);
break;
case XL_TXO:
break;
case XL_NAME:
break;
case XL_ROW:
break;
case XL_FORMAT:
HandleFormat(r);
break;
case XL_XF:
HandleXF(r);
break;
case XL_BOUNDSHEET:
HandleBoundSheet(r);
break;
case XL_EXTSST:
break;
case XL_CONTINUE:
break;
case XL_EOF:
BOFs--;
break;
default:
break;
};
};
};
void ExcelBook::GetSheets(void)
{
ExcelSheet* sheet;
Sheets.resize(0);
sheet=GetSheet();
while (sheet->Cells.count()!= 0 )
{
Sheets.resize(Sheets.count()+1);
Sheets[Sheets.count()-1]=sheet;
sheet->name=*Names[Sheets.count()-1];
sheet=GetSheet();
};
};
bool ExcelBook::ParseBook(char *file)
{
dateformat=QString("");
DetectEndian();
- OpenFile(file);
+ if ( !OpenFile( file ) )
+ return false;
SeekBOF();
ParseSheets();
GetSheets();
return true;
};
QString ExcelBook::GetASCII(char* inbytes, int pos, int chars)
{
int i;
QString outstr="";
for (i = 0; i < chars; i++)
{
outstr.append(inbytes[i+pos]);
};
return outstr;
};
QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars)
{
QString outstr="";
int i;
int rc;
for (i=0; i<chars*2; i++)
{
rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]);
outstr.append(QChar(rc));
i++;
};
return outstr;
};
void ExcelBook::HandleBoundSheet(ExcelBREC* rec)
{
char* data;
int type;
int visibility;
int length;
int pos;
QString name;
pos = 8;
data = GetDataOfBREC(rec);
type = data[4];
visibility = data[5];
length = data[6];
if(data[7]==0)
{
//ascii
name=GetASCII(data,pos,length);
}
else
{
name=GetUnicode(data,pos,length);
};
Names.resize(Names.count()+1);
Names[Names.count()-1]=new QString(name);
};
void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec)
{
char* data;
QString name;
int length;
int pos;
pos = 15;
data = GetDataOfBREC(rec);
length = data[3];
name = GetASCII(data,pos,length);
};
ExcelFormat* ExcelBook::GetFormatting(int xf)
{
int i;
ExcelFormat* rec;
rec=new ExcelFormat();
for (i = 0; formatter[i].code != 0; i++)
{
if (xf == formatter[i].code) break;
};
if (formatter[i].format ==NULL) return NULL;
rec->code = xf;
rec->type = formatter[i].type;
rec->format = formatter[i].format;
return rec;
};
void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes)
{
QString str=QString("");
char* data;
int chars, pos, options, i;
int richstring, fareaststring, runlength=0;
int richruns=0,fareastsize=0;
int totalstrings;
int uniquestrings;
data = GetDataOfBREC(rec);
totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]);
uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]);
pos = 8;
for (i = 0; i < uniquestrings; i++)
{
richruns=0; fareastsize=0;
chars = Integer2Byte(data[pos], data[pos+1]);
pos += 2;
options = data[pos];
pos++;
fareaststring = ((options & 0x04) != 0);
richstring = ((options & 0x08) != 0);
if(richstring)
{
richruns= Integer2Byte(data[pos],data[pos+1]);
pos+=2;
};
if(fareaststring)
{
fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]);
pos+=4;
};
if ((options & 0x01) == 0) //8 bit chars
{
/* ascii */
str = GetASCII(bytes,pos,chars);
pos=pos+chars;
if(str[0]=='=') str[0]=' ';
}else //16 bit chars
{
/* unicode */
str = GetUnicode(bytes,pos,chars);
pos=pos+chars*2;
};
// HERE TO PUT richformat handling
if (richstring)
{
pos += 4 * richruns;
};
if (fareaststring)
{
pos += fareastsize;
};
//printf("String=%s, length=%d first=0x%x\r\n",str.ascii(),str.length(),str[0].unicode());
SharedStrings.resize(SharedStrings.count()+1);
SharedStrings[SharedStrings.count()-1]=new QString(str);
}
};
char* ExcelBook::MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont)
{
int i, pos;
int length;
char* data;
char* bytes;
length = rec->length;
for (i = 0; i < (int) cont->rec.count(); i++)
{
length += cont->rec[i]->length;
}
bytes = GetDataOfBREC(rec);
pos = rec->length;
for (i = 0; i < (int) cont->rec.count(); i++)
{
data = GetDataOfBREC(cont->rec[i]);
*bytes += pos;
bytes = data;
pos += cont->rec[i]->length;
}
return bytes;
};
void ExcelBook::HandleSST(ExcelBREC* rec)
{
char* bytes;
SSTList* cont;
cont= new SSTList;
ExcelBREC* nr;
nr = PeekBREC();
while (nr->code == XL_CONTINUE)
{
cont->rec.resize(cont->rec.count()+1);
cont->rec[cont->rec.count()-1]=GetBREC();
nr = PeekBREC();
}
bytes = MergeBytesFromSSTs(rec,cont);
HandleSetOfSST(rec, bytes);
for(int w1=0;w1<(int)cont->rec.count();w1++)
{
if(cont->rec[w1]!=NULL) {delete cont->rec[w1];cont->rec[w1]=NULL;};
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp
index 7394623..3095142 100644
--- a/noncore/apps/opie-sheet/mainwindow.cpp
+++ b/noncore/apps/opie-sheet/mainwindow.cpp
@@ -688,341 +688,344 @@ void MainWindow::addToData(const QString &data)
{
editData->setText(editData->text().insert(editData->cursorPosition(), data));
}
void MainWindow::slotFuncOutput()
{
if (sender()->isA("QAction"))
addToData(((QAction *)sender())->toolTip());
}
void MainWindow::slotInsertRows()
{
NumberDialog dialogNumber(this);
if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted)
sheet->insertRows(dialogNumber.getValue());
}
void MainWindow::slotInsertCols()
{
NumberDialog dialogNumber(this);
if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted)
sheet->insertColumns(dialogNumber.getValue());
}
void MainWindow::slotInsertSheets()
{
NumberDialog dialogNumber(this);
if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted)
for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet();
}
void MainWindow::slotCellClicked(const QString &cell)
{
editCellSelect->setOn(FALSE);
addToData(cell);
}
typeSheet *MainWindow::createNewSheet()
{
typeSheet *newSheet=new typeSheet;
int currentNo=1, tempNo=0;
bool ok;
for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok)
currentNo=tempNo+1;
newSheet->name=tr("Sheet")+QString::number(currentNo);
newSheet->data.setAutoDelete(TRUE);
comboSheets->insertItem(newSheet->name);
listSheets.append(newSheet);
return newSheet;
}
typeSheet *MainWindow::findSheet(const QString &name)
{
for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
if (tempSheet->name==name)
return tempSheet;
return NULL;
}
void MainWindow::slotSheetChanged(const QString &name)
{
sheet->copySheetData(&findSheet(sheet->getName())->data);
sheet->setName(name);
sheet->setSheetData(&findSheet(name)->data);
sheet->ReCalc();
}
void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w)
{
QAction *action=new QAction(text, menuText, 0, this);
action->setToolTip(tip);
connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
action->addTo(w);
}
void MainWindow::slotFormatCells()
{
CellFormat dialogCellFormat(this);
QPEApplication::showDialog( &dialogCellFormat );
dialogCellFormat.exec(sheet);
}
void MainWindow::slotEditPaste()
{
sheet->editPaste();
}
void MainWindow::slotEditPasteContents()
{
sheet->editPaste(TRUE);
}
void MainWindow::slotRowHeight()
{
int row1, row2, col1, col2;
sheet->getSelection(&row1, &col1, &row2, &col2);
NumberDialog dialogNumber(this);
if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted)
{
int newHeight=dialogNumber.getValue(), row;
for (row=row1; row<=row2; ++row)
sheet->setRowHeight(row, newHeight);
}
}
void MainWindow::slotRowAdjust()
{
int row1, row2, col1, col2;
sheet->getSelection(&row1, &col1, &row2, &col2);
for (int row=row1; row<=row2; ++row)
sheet->adjustRow(row);
}
void MainWindow::slotRowShow()
{
int row1, row2, col1, col2;
sheet->getSelection(&row1, &col1, &row2, &col2);
for (int row=row1; row<=row2; ++row)
sheet->showRow(row);
}
void MainWindow::slotRowHide()
{
int row1, row2, col1, col2;
sheet->getSelection(&row1, &col1, &row2, &col2);
for (int row=row1; row<=row2; ++row)
sheet->hideRow(row);
}
void MainWindow::slotColumnWidth()
{
int row1, row2, col1, col2;
sheet->getSelection(&row1, &col1, &row2, &col2);
NumberDialog dialogNumber(this);
if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted)
{
int newWidth=dialogNumber.getValue(), col;
for (col=col1; col<=col2; ++col)
sheet->setColumnWidth(col, newWidth);
}
}
void MainWindow::slotColumnAdjust()
{
int row1, row2, col1, col2;
sheet->getSelection(&row1, &col1, &row2, &col2);
for (int col=col1; col<=col2; ++col)
sheet->adjustColumn(col);
}
void MainWindow::slotColumnShow()
{
int row1, row2, col1, col2;
sheet->getSelection(&row1, &col1, &row2, &col2);
for (int col=col1; col<=col2; ++col)
sheet->showColumn(col);
}
void MainWindow::slotColumnHide()
{
int row1, row2, col1, col2;
sheet->getSelection(&row1, &col1, &row2, &col2);
for (int col=col1; col<=col2; ++col)
sheet->hideColumn(col);
}
void MainWindow::slotFileSaveAs()
{
TextDialog dialogText(this);
if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
currentDoc->setName(dialogText.getValue());
currentDoc->setFile(QString::null);
currentDoc->setLinkFile(QString::null);
documentSave(currentDoc);
}
void MainWindow::slotImportExcel(const DocLnk &lnkDoc)
{
ExcelBook file1;
- file1.ParseBook((char *)lnkDoc.file().ascii());
+ if ( !file1.ParseBook((char *)lnkDoc.file().ascii()) ){
+ QMessageBox::critical(this, tr("Error"), tr("<td>Unable to open or parse file!</td>"));
+ return;
+ }
int NumOfSheets=file1.Sheets.count();
printf("OpieSheet::NumberOfSheets:%d\r\n",NumOfSheets);
if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
if (currentDoc) delete currentDoc;
currentDoc = new DocLnk();
listSheets.clear();
comboSheets->clear();
int w1,r,c;
ExcelSheet* sh1;
typeSheet* newSheet;
QString* str;
typeCellData* newCell;
for(w1=1;w1<=NumOfSheets;w1++)
{
sh1=file1.Sheets[w1-1];
- printf("OpieSheet:newSheet:%x,r=%d,c=%d\r\n",sh1,sh1->rows,sh1->cols);
+ // printf("OpieSheet:newSheet:%x,r=%d,c=%d\r\n",sh1, sh1->rows,sh1->cols);
newSheet=new typeSheet;
newSheet->data.setAutoDelete(TRUE);
newSheet->name=sh1->name;
printf("OpieSheet:Sheetname:%s\r\n",sh1->name.ascii());
comboSheets->insertItem(newSheet->name);
for(r=1; r <= sh1->rows; r++)
{
for(c=1;c <= sh1->cols; c++)
{
str=file1.CellDataString(sh1,r-1,c-1);
if(str!=NULL && r<DEFAULT_NUM_ROWS && c<DEFAULT_NUM_COLS)
{
newCell=new typeCellData;
newCell->row=r-1;
newCell->col=c-1;
if(str!=NULL) newCell->data=QString(*str); else newCell->data=QString("");
newCell->background=QBrush(Qt::white, Qt::SolidPattern);
newCell->alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop);
newCell->fontColor=Qt::black;
newCell->font=font();
newCell->borders.right=QPen(Qt::gray, 1, Qt::SolidLine);
newCell->borders.bottom=QPen(Qt::gray, 1, Qt::SolidLine);
newSheet->data.append(newCell);
//there is no format parsing at the moment or style parsing
//printf("OpieSheetNumber:row=%d,col=%d,val=%s\r\n",r,c,str->latin1());
};
};
};
listSheets.append(newSheet);
if (w1==1)//if i==0 link sheet1 with sheetview
{
sheet->setName(newSheet->name);
sheet->setSheetData(&newSheet->data);
sheet->ReCalc();
};
};
file1.CloseFile();
printf("Excel FILE read OK\r\n");
documentModified=TRUE;
}
void MainWindow::slotSheetRename()
{
TextDialog dialogText(this);
if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
QString newName=dialogText.getValue();
typeSheet *tempSheet=findSheet(newName);
if (tempSheet)
{
QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\''));
return;
}
tempSheet=findSheet(sheet->getName());
for (int i=0; i<comboSheets->count(); ++i)
if (comboSheets->text(i)==tempSheet->name)
{
comboSheets->changeItem(newName, i);
break;
}
tempSheet->name=newName;
sheet->setName(newName);
}
void MainWindow::slotSheetRemove()
{
if (comboSheets->count()<2)
{
QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!"));
return;
}
if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
{
typeSheet *tempSheet=findSheet(sheet->getName());
for (int i=0; i<comboSheets->count(); ++i)
if (comboSheets->text(i)==tempSheet->name)
{
comboSheets->removeItem(i);
break;
}
comboSheets->setCurrentItem(0);
slotSheetChanged(comboSheets->currentText());
listSheets.remove(tempSheet);
}
}
void MainWindow::slotDataSort()
{
SortDialog dialogSort(this);
QPEApplication::showDialog( &dialogSort );
dialogSort.exec(sheet);
}
void MainWindow::slotDocModified()
{
documentModified=TRUE;
}
void MainWindow::slotInsertCells()
{
QDialog dialogInsert(this, 0, TRUE);
dialogInsert.resize(180, 130);
dialogInsert.setCaption(tr("Insert Cells"));
QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert);
group->setGeometry(10, 10, 160, 110);
QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group);
radio=new QRadioButton(tr("Shift cells &right"), group);
radio=new QRadioButton(tr("Entire ro&w"), group);
radio=new QRadioButton(tr("Entire &column"), group);
group->setButton(0);
if (dialogInsert.exec()==QDialog::Accepted)
switch (group->id(group->selected()))
{
case 0: sheet->insertRows(1, FALSE); break;
case 1: sheet->insertColumns(1, FALSE); break;
case 2: sheet->insertRows(1, TRUE); break;
case 3: sheet->insertColumns(1, TRUE); break;
}
}
void MainWindow::slotDataFindReplace()
{
FindDialog dialogFind(this);
QPEApplication::showDialog( &dialogFind );
dialogFind.exec(sheet);
}