summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore 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
@@ -208,769 +208,770 @@ bool ExcelBook::OpenFile(char *Filename)
208 Names.resize(0); 208 Names.resize(0);
209 Sheets.resize(0); 209 Sheets.resize(0);
210 if(File==NULL) return false; 210 if(File==NULL) return false;
211 printf("Opened excel file!\r\n"); 211 printf("Opened excel file!\r\n");
212 return true; 212 return true;
213}; 213};
214 214
215bool ExcelBook::CloseFile(void) 215bool ExcelBook::CloseFile(void)
216{ 216{
217 int w1; 217 int w1;
218 for(w1=0;w1<(int)XFRecords.count();w1++) 218 for(w1=0;w1<(int)XFRecords.count();w1++)
219 { 219 {
220 if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;}; 220 if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;};
221 }; 221 };
222 for(w1=0;w1<(int)SharedStrings.count();w1++) 222 for(w1=0;w1<(int)SharedStrings.count();w1++)
223 { 223 {
224 if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;}; 224 if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;};
225 }; 225 };
226 for(w1=0;w1<(int)Names.count();w1++) 226 for(w1=0;w1<(int)Names.count();w1++)
227 { 227 {
228 if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;}; 228 if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;};
229 }; 229 };
230 for(w1=0;w1<(int)Sheets.count();w1++) 230 for(w1=0;w1<(int)Sheets.count();w1++)
231 { 231 {
232 if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;}; 232 if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;};
233 }; 233 };
234 XFRecords.resize(0); 234 XFRecords.resize(0);
235 SharedStrings.resize(0); 235 SharedStrings.resize(0);
236 Names.resize(0); 236 Names.resize(0);
237 Sheets.resize(0); 237 Sheets.resize(0);
238 fclose(File); 238 fclose(File);
239 printf("closed excel file!\r\n"); 239 printf("closed excel file!\r\n");
240 if(File==NULL) return true; 240 if(File==NULL) return true;
241 return false; 241 return false;
242}; 242};
243 243
244void ExcelBook::SeekPosition(int pos) 244void ExcelBook::SeekPosition(int pos)
245{ 245{
246 if(!feof(File)) 246 if(!feof(File))
247 { 247 {
248 Position=pos; 248 Position=pos;
249 //printf("SeekPosition:Pos:%d\r\n",Position); 249 //printf("SeekPosition:Pos:%d\r\n",Position);
250 fseek(File,pos,SEEK_SET); 250 fseek(File,pos,SEEK_SET);
251 }; 251 };
252}; 252};
253 253
254void ExcelBook::SeekSkip(int pos) 254void ExcelBook::SeekSkip(int pos)
255{ 255{
256 if(!feof(File)) 256 if(!feof(File))
257 { 257 {
258 Position=Position+pos; 258 Position=Position+pos;
259 //printf("SeekSkip:Pos:%d\r\n",Position); 259 //printf("SeekSkip:Pos:%d\r\n",Position);
260 fseek(File, Position, SEEK_SET); 260 fseek(File, Position, SEEK_SET);
261 }; 261 };
262}; 262};
263 263
264int ExcelBook::FileEOF(void) 264int ExcelBook::FileEOF(void)
265{ 265{
266 if(File!=NULL) return(feof(File)); else return 0; 266 if(File!=NULL) return(feof(File)); else return 0;
267 //EOF is defined in stdlib as -1 267 //EOF is defined in stdlib as -1
268}; 268};
269 269
270int ExcelBook::Get2Bytes(void) 270int ExcelBook::Get2Bytes(void)
271{ 271{
272 int i1,i2; 272 int i1,i2;
273 i1=0; i2=0; 273 i1=0; i2=0;
274 if (!feof(File)) 274 if (!feof(File))
275 { 275 {
276 i1=fgetc(File); 276 i1=fgetc(File);
277 Position++; 277 Position++;
278 }; 278 };
279 if (!feof(File)) 279 if (!feof(File))
280 { 280 {
281 i2=fgetc(File); 281 i2=fgetc(File);
282 Position++; 282 Position++;
283 }; 283 };
284 return Integer2Byte(i1,i2); 284 return Integer2Byte(i1,i2);
285}; 285};
286 286
287char* ExcelBook::Read(int pos, int length) 287char* ExcelBook::Read(int pos, int length)
288{ 288{
289 int i; 289 int i;
290 char *data; 290 char *data;
291 data= new char[length]; 291 data= new char[length];
292 SeekPosition(pos); 292 SeekPosition(pos);
293 for(i=0; i<length; i++) 293 for(i=0; i<length; i++)
294 { 294 {
295 if(!feof(File)) data[i]=fgetc(File); 295 if(!feof(File)) data[i]=fgetc(File);
296 }; 296 };
297 Position= Position+length; 297 Position= Position+length;
298 return data; 298 return data;
299}; 299};
300 300
301QString ExcelBook::ReadUnicodeChar(int pos, int length) 301QString ExcelBook::ReadUnicodeChar(int pos, int length)
302{ 302{
303 int i; 303 int i;
304 QString data; 304 QString data;
305 int i1=' ',i2=' ',ii; 305 int i1=' ',i2=' ',ii;
306 SeekPosition(pos); 306 SeekPosition(pos);
307 for(i=0; i<length; i++) 307 for(i=0; i<length; i++)
308 { 308 {
309 if(!feof(File)) i1=fgetc(File); 309 if(!feof(File)) i1=fgetc(File);
310 if(!feof(File)) i2=fgetc(File); 310 if(!feof(File)) i2=fgetc(File);
311 ii=Integer2Byte(i1,i2); 311 ii=Integer2Byte(i1,i2);
312 data.append(ii); 312 data.append(ii);
313 Position+=2; 313 Position+=2;
314 }; 314 };
315 return data; 315 return data;
316}; 316};
317 317
318QString* ExcelBook::GetString(int num) 318QString* ExcelBook::GetString(int num)
319{ 319{
320 if(num>=0 && num<(int)SharedStrings.count()) 320 if(num>=0 && num<(int)SharedStrings.count())
321 { 321 {
322 return SharedStrings[num]; 322 return SharedStrings[num];
323 }; 323 };
324 return new QString(""); 324 return new QString("");
325}; 325};
326 326
327int ExcelBook::SeekBOF(void) 327int ExcelBook::SeekBOF(void)
328{ 328{
329 int opcode,version,streamtype,length,ret=0; 329 int opcode,version,streamtype,length,ret=0;
330 char *data; 330 char *data;
331 while(!feof(File)) 331 while(!feof(File))
332 { 332 {
333 opcode=Get2Bytes(); 333 opcode=Get2Bytes();
334 if(opcode==XL_BOF) 334 if(opcode==XL_BOF)
335 { 335 {
336 length=Get2Bytes(); 336 length=Get2Bytes();
337 data=Read(Position,length); 337 data=Read(Position,length);
338 version=Integer2Byte(data[0], data[1]); 338 version=Integer2Byte(data[0], data[1]);
339 streamtype=Integer2Byte(data[2], data[3]); 339 streamtype=Integer2Byte(data[2], data[3]);
340 printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version); 340 printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version);
341 delete data; data=NULL; 341 delete data; data=NULL;
342 if (version==BIFF8) ret=8; 342 if (version==BIFF8) ret=8;
343 else if(version==BIFF7) ret=7; 343 else if(version==BIFF7) ret=7;
344 printf("SEEKBOF:versionBIFF%d\r\n",ret); 344 printf("SEEKBOF:versionBIFF%d\r\n",ret);
345 if(streamtype==WBKGLOBAL) return ret *2; 345 if(streamtype==WBKGLOBAL) return ret *2;
346 else if(streamtype==WRKSHEET) return ret *1; 346 else if(streamtype==WRKSHEET) return ret *1;
347 return 1; 347 return 1;
348 }; 348 };
349 }; 349 };
350 return 0; 350 return 0;
351}; 351};
352 352
353ExcelBREC* ExcelBook::GetBREC(void) 353ExcelBREC* ExcelBook::GetBREC(void)
354{ 354{
355 ExcelBREC* rec; 355 ExcelBREC* rec;
356 rec= new ExcelBREC; 356 rec= new ExcelBREC;
357 if(FileEOF()) return NULL; 357 if(FileEOF()) return NULL;
358 rec->data=NULL; 358 rec->data=NULL;
359 rec->code=Get2Bytes(); 359 rec->code=Get2Bytes();
360 rec->length=Get2Bytes(); 360 rec->length=Get2Bytes();
361 rec->position=Position; 361 rec->position=Position;
362 SeekSkip(rec->length); 362 SeekSkip(rec->length);
363 return rec; 363 return rec;
364}; 364};
365 365
366ExcelBREC* ExcelBook::PeekBREC(void) 366ExcelBREC* ExcelBook::PeekBREC(void)
367{ 367{
368 int oldpos; 368 int oldpos;
369 ExcelBREC* NextRec; 369 ExcelBREC* NextRec;
370 oldpos=Position; 370 oldpos=Position;
371 NextRec=GetBREC(); 371 NextRec=GetBREC();
372 SeekPosition(oldpos); 372 SeekPosition(oldpos);
373 return NextRec; 373 return NextRec;
374}; 374};
375 375
376char* ExcelBook::GetDataOfBREC(ExcelBREC* record) 376char* ExcelBook::GetDataOfBREC(ExcelBREC* record)
377{ 377{
378 if(record->data==NULL) 378 if(record->data==NULL)
379 { 379 {
380 ConvertCharToArray(record,Read(record->position,record->length),record->length); 380 ConvertCharToArray(record,Read(record->position,record->length),record->length);
381 }; 381 };
382 return record->data;//new? 382 return record->data;//new?
383}; 383};
384 384
385void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) 385void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length)
386{ 386{
387 record->data=new char[length]; 387 record->data=new char[length];
388 for(int w1=0;w1<=length-1;w1++) 388 for(int w1=0;w1<=length-1;w1++)
389 record->data[w1]=chars[w1]; 389 record->data[w1]=chars[w1];
390}; 390};
391 391
392 392
393bool ExcelSheet::InitCells() 393bool ExcelSheet::InitCells()
394{ 394{
395 int r; 395 int r;
396 Cells.resize(rows * cols + cols+1); 396 Cells.resize(rows * cols + cols+1);
397 if(Cells.count()==0) return false; 397 if(Cells.count()==0) return false;
398 for(r=0;r < Cells.count();r++) 398 for(r=0;r < Cells.count();r++)
399 { 399 {
400 Cells[r]=NULL; 400 Cells[r]=NULL;
401 }; 401 };
402 return true; 402 return true;
403}; 403};
404 404
405void ExcelSheet::Set(int row, int col, ExcelCell* cell) 405void ExcelSheet::Set(int row, int col, ExcelCell* cell)
406{ 406{
407 if(cell!=NULL&&(row*cols+col)<Cells.count()) 407 if(cell!=NULL&&(row*cols+col)<Cells.count())
408 { 408 {
409 Cells[row*cols+col]=cell; 409 Cells[row*cols+col]=cell;
410 }; 410 };
411}; 411};
412 412
413ExcelCell* ExcelSheet::Get(int row, int col) 413ExcelCell* ExcelSheet::Get(int row, int col)
414{ 414{
415 ExcelCell* cell; 415 ExcelCell* cell;
416 cell=Cells[row*cols+col]; 416 cell=Cells[row*cols+col];
417 if(cell==NULL) return NULL; 417 if(cell==NULL) return NULL;
418 return cell; 418 return cell;
419}; 419};
420 420
421int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) 421int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record)
422{ 422{
423 char* data=NULL; 423 char* data=NULL;
424 switch (record->code) 424 switch (record->code)
425 { 425 {
426 case XL_DIMENSION: 426 case XL_DIMENSION:
427 data = GetDataOfBREC(record); 427 data = GetDataOfBREC(record);
428 if (record->length == 10) 428 if (record->length == 10)
429 { 429 {
430 sheet->rows = Integer2Byte(data[2], data[3]); 430 sheet->rows = Integer2Byte(data[2], data[3]);
431 sheet->cols = Integer2Byte(data[6], data[7]); 431 sheet->cols = Integer2Byte(data[6], data[7]);
432 } 432 }
433 else 433 else
434 { 434 {
435 sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); 435 sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]);
436 sheet->cols = Integer2Byte(data[10], data[11]); 436 sheet->cols = Integer2Byte(data[10], data[11]);
437 } 437 }
438 sheet->InitCells(); 438 sheet->InitCells();
439 break; 439 break;
440 440
441 case XL_LABELSST: 441 case XL_LABELSST:
442 HandleLabelSST(sheet, record); 442 HandleLabelSST(sheet, record);
443 break; 443 break;
444 444
445 case XL_RK: 445 case XL_RK:
446 case XL_RK2: 446 case XL_RK2:
447 HandleRK(sheet, record); 447 HandleRK(sheet, record);
448 break; 448 break;
449 449
450 case XL_MULRK: 450 case XL_MULRK:
451 HandleMulrk(sheet, record); 451 HandleMulrk(sheet, record);
452 break; 452 break;
453 453
454 case XL_ROW: 454 case XL_ROW:
455 break; 455 break;
456 456
457 case XL_NUMBER: 457 case XL_NUMBER:
458 HandleNumber(sheet, record); 458 HandleNumber(sheet, record);
459 break; 459 break;
460 460
461 case XL_BOOLERR: 461 case XL_BOOLERR:
462 break; 462 break;
463 463
464 case XL_CONTINUE: 464 case XL_CONTINUE:
465 break; 465 break;
466 466
467 case XL_FORMULA: 467 case XL_FORMULA:
468 case XL_FORMULA2: 468 case XL_FORMULA2:
469 HandleFormula(sheet, record); 469 HandleFormula(sheet, record);
470 break; 470 break;
471 471
472 case XL_LABEL: 472 case XL_LABEL:
473 break; 473 break;
474 474
475 case XL_NAME: 475 case XL_NAME:
476 HandleName(sheet, record); 476 HandleName(sheet, record);
477 break; 477 break;
478 478
479 case XL_BOF: 479 case XL_BOF:
480 break; 480 break;
481 case XL_EOF: 481 case XL_EOF:
482 return 0; 482 return 0;
483 default: 483 default:
484 break; 484 break;
485 }; 485 };
486 return 1; 486 return 1;
487}; 487};
488 488
489int ExcelBook::ReadSheet(ExcelSheet* sheet) 489int ExcelBook::ReadSheet(ExcelSheet* sheet)
490{ 490{
491 ExcelBREC* record; 491 ExcelBREC* record;
492 int oldpos; 492 int oldpos;
493 oldpos = Position; 493 oldpos = Position;
494 SeekPosition(sheet->position); 494 SeekPosition(sheet->position);
495 record = GetBREC(); 495 record = GetBREC();
496 while (record!=NULL) 496 while (record!=NULL)
497 { 497 {
498 if (!SheetHandleRecord(sheet, record)) break; 498 if (!SheetHandleRecord(sheet, record)) break;
499 record=GetBREC(); 499 record=GetBREC();
500 }; 500 };
501 SeekPosition(oldpos); 501 SeekPosition(oldpos);
502 return 1; 502 return 1;
503}; 503};
504 504
505ExcelSheet* ExcelBook::GetSheet(void) 505ExcelSheet* ExcelBook::GetSheet(void)
506{ 506{
507 ExcelSheet* sh=NULL; 507 ExcelSheet* sh=NULL;
508 int type; 508 int type;
509 type=SeekBOF(); 509 type=SeekBOF();
510 Version=type; 510 Version=type;
511 sh=new ExcelSheet; 511 sh=new ExcelSheet;
512 if(type) 512 if(type)
513 { 513 {
514 sh->type=type; 514 sh->type=type;
515 sh->position=Position; 515 sh->position=Position;
516 sh->name=QString(""); 516 sh->name=QString("");
517 }; 517 };
518 if(type==8||type==7) 518 if(type==8||type==7)
519 { 519 {
520 ReadSheet(sh); 520 ReadSheet(sh);
521 }; 521 };
522 return sh; 522 return sh;
523}; 523};
524 524
525void ExcelBook::ParseSheets(void) 525void ExcelBook::ParseSheets(void)
526{ 526{
527 int BOFs; 527 int BOFs;
528 ExcelBREC* r; 528 ExcelBREC* r;
529 BOFs=1; 529 BOFs=1;
530 r=GetBREC(); 530 r=GetBREC();
531 while(BOFs) 531 while(BOFs)
532 { 532 {
533 r=GetBREC(); 533 r=GetBREC();
534 switch(r->code) 534 switch(r->code)
535 { 535 {
536 case XL_SST: 536 case XL_SST:
537 HandleSST(r); 537 HandleSST(r);
538 break; 538 break;
539 539
540 case XL_TXO: 540 case XL_TXO:
541 break; 541 break;
542 case XL_NAME: 542 case XL_NAME:
543 break; 543 break;
544 case XL_ROW: 544 case XL_ROW:
545 break; 545 break;
546 546
547 case XL_FORMAT: 547 case XL_FORMAT:
548 HandleFormat(r); 548 HandleFormat(r);
549 break; 549 break;
550 550
551 case XL_XF: 551 case XL_XF:
552 HandleXF(r); 552 HandleXF(r);
553 break; 553 break;
554 554
555 case XL_BOUNDSHEET: 555 case XL_BOUNDSHEET:
556 HandleBoundSheet(r); 556 HandleBoundSheet(r);
557 break; 557 break;
558 558
559 case XL_EXTSST: 559 case XL_EXTSST:
560 break; 560 break;
561 case XL_CONTINUE: 561 case XL_CONTINUE:
562 break; 562 break;
563 563
564 case XL_EOF: 564 case XL_EOF:
565 BOFs--; 565 BOFs--;
566 break; 566 break;
567 567
568 default: 568 default:
569 break; 569 break;
570 }; 570 };
571 }; 571 };
572}; 572};
573 573
574void ExcelBook::GetSheets(void) 574void ExcelBook::GetSheets(void)
575{ 575{
576 ExcelSheet* sheet; 576 ExcelSheet* sheet;
577 Sheets.resize(0); 577 Sheets.resize(0);
578 sheet=GetSheet(); 578 sheet=GetSheet();
579 while (sheet->Cells.count()!= 0 ) 579 while (sheet->Cells.count()!= 0 )
580 { 580 {
581 Sheets.resize(Sheets.count()+1); 581 Sheets.resize(Sheets.count()+1);
582 Sheets[Sheets.count()-1]=sheet; 582 Sheets[Sheets.count()-1]=sheet;
583 sheet->name=*Names[Sheets.count()-1]; 583 sheet->name=*Names[Sheets.count()-1];
584 sheet=GetSheet(); 584 sheet=GetSheet();
585 }; 585 };
586}; 586};
587 587
588bool ExcelBook::ParseBook(char *file) 588bool ExcelBook::ParseBook(char *file)
589{ 589{
590 dateformat=QString(""); 590 dateformat=QString("");
591 DetectEndian(); 591 DetectEndian();
592 OpenFile(file); 592 if ( !OpenFile( file ) )
593 return false;
593 SeekBOF(); 594 SeekBOF();
594 ParseSheets(); 595 ParseSheets();
595 GetSheets(); 596 GetSheets();
596 return true; 597 return true;
597}; 598};
598 599
599QString ExcelBook::GetASCII(char* inbytes, int pos, int chars) 600QString ExcelBook::GetASCII(char* inbytes, int pos, int chars)
600{ 601{
601 int i; 602 int i;
602 QString outstr=""; 603 QString outstr="";
603 for (i = 0; i < chars; i++) 604 for (i = 0; i < chars; i++)
604 { 605 {
605 outstr.append(inbytes[i+pos]); 606 outstr.append(inbytes[i+pos]);
606 }; 607 };
607 return outstr; 608 return outstr;
608}; 609};
609 610
610QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars) 611QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars)
611{ 612{
612 QString outstr=""; 613 QString outstr="";
613 int i; 614 int i;
614 int rc; 615 int rc;
615 for (i=0; i<chars*2; i++) 616 for (i=0; i<chars*2; i++)
616 { 617 {
617 rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]); 618 rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]);
618 outstr.append(QChar(rc)); 619 outstr.append(QChar(rc));
619 i++; 620 i++;
620 }; 621 };
621 return outstr; 622 return outstr;
622}; 623};
623 624
624 625
625void ExcelBook::HandleBoundSheet(ExcelBREC* rec) 626void ExcelBook::HandleBoundSheet(ExcelBREC* rec)
626{ 627{
627 char* data; 628 char* data;
628 int type; 629 int type;
629 int visibility; 630 int visibility;
630 int length; 631 int length;
631 int pos; 632 int pos;
632 QString name; 633 QString name;
633 pos = 8; 634 pos = 8;
634 data = GetDataOfBREC(rec); 635 data = GetDataOfBREC(rec);
635 type = data[4]; 636 type = data[4];
636 visibility = data[5]; 637 visibility = data[5];
637 length = data[6]; 638 length = data[6];
638 if(data[7]==0) 639 if(data[7]==0)
639 { 640 {
640 //ascii 641 //ascii
641 name=GetASCII(data,pos,length); 642 name=GetASCII(data,pos,length);
642 } 643 }
643 else 644 else
644 { 645 {
645 name=GetUnicode(data,pos,length); 646 name=GetUnicode(data,pos,length);
646 }; 647 };
647 Names.resize(Names.count()+1); 648 Names.resize(Names.count()+1);
648 Names[Names.count()-1]=new QString(name); 649 Names[Names.count()-1]=new QString(name);
649}; 650};
650 651
651void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec) 652void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec)
652{ 653{
653 char* data; 654 char* data;
654 QString name; 655 QString name;
655 int length; 656 int length;
656 int pos; 657 int pos;
657 pos = 15; 658 pos = 15;
658 data = GetDataOfBREC(rec); 659 data = GetDataOfBREC(rec);
659 length = data[3]; 660 length = data[3];
660 name = GetASCII(data,pos,length); 661 name = GetASCII(data,pos,length);
661 662
662 663
663}; 664};
664 665
665ExcelFormat* ExcelBook::GetFormatting(int xf) 666ExcelFormat* ExcelBook::GetFormatting(int xf)
666{ 667{
667 int i; 668 int i;
668 ExcelFormat* rec; 669 ExcelFormat* rec;
669 rec=new ExcelFormat(); 670 rec=new ExcelFormat();
670 for (i = 0; formatter[i].code != 0; i++) 671 for (i = 0; formatter[i].code != 0; i++)
671 { 672 {
672 if (xf == formatter[i].code) break; 673 if (xf == formatter[i].code) break;
673 }; 674 };
674 if (formatter[i].format ==NULL) return NULL; 675 if (formatter[i].format ==NULL) return NULL;
675 rec->code = xf; 676 rec->code = xf;
676 rec->type = formatter[i].type; 677 rec->type = formatter[i].type;
677 rec->format = formatter[i].format; 678 rec->format = formatter[i].format;
678 return rec; 679 return rec;
679}; 680};
680 681
681void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes) 682void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes)
682{ 683{
683 QString str=QString(""); 684 QString str=QString("");
684 char* data; 685 char* data;
685 int chars, pos, options, i; 686 int chars, pos, options, i;
686 int richstring, fareaststring, runlength=0; 687 int richstring, fareaststring, runlength=0;
687 int richruns=0,fareastsize=0; 688 int richruns=0,fareastsize=0;
688 int totalstrings; 689 int totalstrings;
689 int uniquestrings; 690 int uniquestrings;
690 data = GetDataOfBREC(rec); 691 data = GetDataOfBREC(rec);
691 totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]); 692 totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]);
692 uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]); 693 uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]);
693 pos = 8; 694 pos = 8;
694 for (i = 0; i < uniquestrings; i++) 695 for (i = 0; i < uniquestrings; i++)
695 { 696 {
696 richruns=0; fareastsize=0; 697 richruns=0; fareastsize=0;
697 chars = Integer2Byte(data[pos], data[pos+1]); 698 chars = Integer2Byte(data[pos], data[pos+1]);
698 pos += 2; 699 pos += 2;
699 options = data[pos]; 700 options = data[pos];
700 pos++; 701 pos++;
701 fareaststring = ((options & 0x04) != 0); 702 fareaststring = ((options & 0x04) != 0);
702 richstring = ((options & 0x08) != 0); 703 richstring = ((options & 0x08) != 0);
703 if(richstring) 704 if(richstring)
704 { 705 {
705 richruns= Integer2Byte(data[pos],data[pos+1]); 706 richruns= Integer2Byte(data[pos],data[pos+1]);
706 pos+=2; 707 pos+=2;
707 }; 708 };
708 if(fareaststring) 709 if(fareaststring)
709 { 710 {
710 fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]); 711 fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]);
711 pos+=4; 712 pos+=4;
712 }; 713 };
713 714
714 if ((options & 0x01) == 0) //8 bit chars 715 if ((options & 0x01) == 0) //8 bit chars
715 { 716 {
716 /* ascii */ 717 /* ascii */
717 str = GetASCII(bytes,pos,chars); 718 str = GetASCII(bytes,pos,chars);
718 pos=pos+chars; 719 pos=pos+chars;
719 if(str[0]=='=') str[0]=' '; 720 if(str[0]=='=') str[0]=' ';
720 }else //16 bit chars 721 }else //16 bit chars
721 { 722 {
722 /* unicode */ 723 /* unicode */
723 str = GetUnicode(bytes,pos,chars); 724 str = GetUnicode(bytes,pos,chars);
724 pos=pos+chars*2; 725 pos=pos+chars*2;
725 }; 726 };
726 // HERE TO PUT richformat handling 727 // HERE TO PUT richformat handling
727 if (richstring) 728 if (richstring)
728 { 729 {
729 pos += 4 * richruns; 730 pos += 4 * richruns;
730 }; 731 };
731 if (fareaststring) 732 if (fareaststring)
732 { 733 {
733 pos += fareastsize; 734 pos += fareastsize;
734 }; 735 };
735 //printf("String=%s, length=%d first=0x%x\r\n",str.ascii(),str.length(),str[0].unicode()); 736 //printf("String=%s, length=%d first=0x%x\r\n",str.ascii(),str.length(),str[0].unicode());
736 SharedStrings.resize(SharedStrings.count()+1); 737 SharedStrings.resize(SharedStrings.count()+1);
737 SharedStrings[SharedStrings.count()-1]=new QString(str); 738 SharedStrings[SharedStrings.count()-1]=new QString(str);
738 } 739 }
739}; 740};
740 741
741 742
742char* ExcelBook::MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont) 743char* ExcelBook::MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont)
743{ 744{
744 int i, pos; 745 int i, pos;
745 int length; 746 int length;
746 747
747 char* data; 748 char* data;
748 char* bytes; 749 char* bytes;
749 length = rec->length; 750 length = rec->length;
750 for (i = 0; i < (int) cont->rec.count(); i++) 751 for (i = 0; i < (int) cont->rec.count(); i++)
751 { 752 {
752 length += cont->rec[i]->length; 753 length += cont->rec[i]->length;
753 } 754 }
754 bytes = GetDataOfBREC(rec); 755 bytes = GetDataOfBREC(rec);
755 pos = rec->length; 756 pos = rec->length;
756 for (i = 0; i < (int) cont->rec.count(); i++) 757 for (i = 0; i < (int) cont->rec.count(); i++)
757 { 758 {
758 data = GetDataOfBREC(cont->rec[i]); 759 data = GetDataOfBREC(cont->rec[i]);
759 *bytes += pos; 760 *bytes += pos;
760 bytes = data; 761 bytes = data;
761 pos += cont->rec[i]->length; 762 pos += cont->rec[i]->length;
762 } 763 }
763 return bytes; 764 return bytes;
764}; 765};
765 766
766 767
767void ExcelBook::HandleSST(ExcelBREC* rec) 768void ExcelBook::HandleSST(ExcelBREC* rec)
768{ 769{
769 char* bytes; 770 char* bytes;
770 SSTList* cont; 771 SSTList* cont;
771 cont= new SSTList; 772 cont= new SSTList;
772 ExcelBREC* nr; 773 ExcelBREC* nr;
773 nr = PeekBREC(); 774 nr = PeekBREC();
774 while (nr->code == XL_CONTINUE) 775 while (nr->code == XL_CONTINUE)
775 { 776 {
776 cont->rec.resize(cont->rec.count()+1); 777 cont->rec.resize(cont->rec.count()+1);
777 cont->rec[cont->rec.count()-1]=GetBREC(); 778 cont->rec[cont->rec.count()-1]=GetBREC();
778 nr = PeekBREC(); 779 nr = PeekBREC();
779 } 780 }
780 bytes = MergeBytesFromSSTs(rec,cont); 781 bytes = MergeBytesFromSSTs(rec,cont);
781 HandleSetOfSST(rec, bytes); 782 HandleSetOfSST(rec, bytes);
782 for(int w1=0;w1<(int)cont->rec.count();w1++) 783 for(int w1=0;w1<(int)cont->rec.count();w1++)
783 { 784 {
784 if(cont->rec[w1]!=NULL) {delete cont->rec[w1];cont->rec[w1]=NULL;}; 785 if(cont->rec[w1]!=NULL) {delete cont->rec[w1];cont->rec[w1]=NULL;};
785 }; 786 };
786 cont->rec.resize(0); 787 cont->rec.resize(0);
787}; 788};
788 789
789void ExcelBook::HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec) 790void ExcelBook::HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec)
790{ 791{
791 int index, row, col; 792 int index, row, col;
792 char* data; 793 char* data;
793 data = GetDataOfBREC(rec); 794 data = GetDataOfBREC(rec);
794 index = Integer4Byte(data[6], data[7], data[8], data[9]); 795 index = Integer4Byte(data[6], data[7], data[8], data[9]);
795 row = Integer2Byte(data[0], data[1]); 796 row = Integer2Byte(data[0], data[1]);
796 col = Integer2Byte(data[2], data[3]); 797 col = Integer2Byte(data[2], data[3]);
797 sheet->Set(row,col, CellLabel(row, col, *GetString(index))); 798 sheet->Set(row,col, CellLabel(row, col, *GetString(index)));
798}; 799};
799 800
800ExcelCell* ExcelBook::CellLabel(int row, int col, QString str) 801ExcelCell* ExcelBook::CellLabel(int row, int col, QString str)
801{ 802{
802 ExcelCell* c; 803 ExcelCell* c;
803 c= new ExcelCell; 804 c= new ExcelCell;
804 c->row = row; 805 c->row = row;
805 c->col = col; 806 c->col = col;
806 c->type = CELL_LABEL; 807 c->type = CELL_LABEL;
807 c->valuec = str; 808 c->valuec = str;
808 return c; 809 return c;
809}; 810};
810 811
811ExcelCell* ExcelBook::CellNumber(int row, int col, int index, double d) 812ExcelCell* ExcelBook::CellNumber(int row, int col, int index, double d)
812{ 813{
813 ExcelCell* c; 814 ExcelCell* c;
814 c=new ExcelCell; 815 c=new ExcelCell;
815 c->row = row; 816 c->row = row;
816 c->col = col; 817 c->col = col;
817 c->xfindex = index; 818 c->xfindex = index;
818 c->type = CELL_NUMBER; 819 c->type = CELL_NUMBER;
819 c->valued = d; 820 c->valued = d;
820 return c; 821 return c;
821}; 822};
822 823
823QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col) 824QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col)
824{ 825{
825 time_t date; 826 time_t date;
826 struct tm *tmptr; 827 struct tm *tmptr;
827 ExcelCell* c; 828 ExcelCell* c;
828 char str[128]; 829 char str[128];
829 QString format; 830 QString format;
830 int precision; 831 int precision;
831 int utcOffsetDays = 25569; 832 int utcOffsetDays = 25569;
832 int sInADay = 24 * 60 * 60; 833 int sInADay = 24 * 60 * 60;
833 c = sh->Get(row,col); 834 c = sh->Get(row,col);
834 if (c == NULL) return new QString(""); 835 if (c == NULL) return new QString("");
835 switch (c->type) 836 switch (c->type)
836 { 837 {
837 case CELL_LABEL: 838 case CELL_LABEL:
838 return new QString(c->valuec); 839 return new QString(c->valuec);
839 case CELL_NUMBER: 840 case CELL_NUMBER:
840 if (XFRecords[c->xfindex]->type == DATEFORMAT) 841 if (XFRecords[c->xfindex]->type == DATEFORMAT)
841 { 842 {
842 843
843 format = XFRecords[c->xfindex]->format; 844 format = XFRecords[c->xfindex]->format;
844 date = (time_t) ((c->valued - utcOffsetDays) * sInADay); 845 date = (time_t) ((c->valued - utcOffsetDays) * sInADay);
845 tmptr = gmtime(&date); 846 tmptr = gmtime(&date);
846 if (dateformat) 847 if (dateformat)
847 { 848 {
848 strftime(str,1024,dateformat.ascii(),tmptr); 849 strftime(str,1024,dateformat.ascii(),tmptr);
849 } 850 }
850 else 851 else
851 { 852 {
852 strftime(str,1024,format.ascii(),tmptr); 853 strftime(str,1024,format.ascii(),tmptr);
853 }; 854 };
854 } 855 }
855 else 856 else
856 if (XFRecords[c->xfindex]->type == NUMBERFORMAT) 857 if (XFRecords[c->xfindex]->type == NUMBERFORMAT)
857 { 858 {
858 format = XFRecords[c->xfindex]->format; 859 format = XFRecords[c->xfindex]->format;
859 //sprintf(str,format.ascii(),c->valued); 860 //sprintf(str,format.ascii(),c->valued);
860 // the real format is ignored... 861 // the real format is ignored...
861 // because there is more work to be done in the field 862 // because there is more work to be done in the field
862 precision = CellGetPrecision(c->valued); 863 precision = CellGetPrecision(c->valued);
863 sprintf(str,"%.*f",precision,c->valued); 864 sprintf(str,"%.*f",precision,c->valued);
864 } 865 }
865 else 866 else
866 { 867 {
867 precision = CellGetPrecision(c->valued); 868 precision = CellGetPrecision(c->valued);
868 sprintf(str,"%.*f",precision,c->valued); 869 sprintf(str,"%.*f",precision,c->valued);
869 }; 870 };
870 break; 871 break;
871 case CELL_DATE: 872 case CELL_DATE:
872 break; 873 break;
873 case CELL_BOOLEAN: 874 case CELL_BOOLEAN:
874 break; 875 break;
875 case CELL_ERROR: 876 case CELL_ERROR:
876 break; 877 break;
877 } 878 }
878 return new QString(str); 879 return new QString(str);
879}; 880};
880 881
881int ExcelBook::CellGetPrecision(double d) 882int ExcelBook::CellGetPrecision(double d)
882{ 883{
883 double t; 884 double t;
884 int i,x; 885 int i,x;
885 int count; 886 int count;
886 if (d < 0) d *= -1; 887 if (d < 0) d *= -1;
887 i = (int)d; 888 i = (int)d;
888 t = d - (double)i; 889 t = d - (double)i;
889 if (t <= 0) 890 if (t <= 0)
890 { 891 {
891 return 0; 892 return 0;
892 }; 893 };
893 count = 0; 894 count = 0;
894 for (x = 6; x > 1; x--) 895 for (x = 6; x > 1; x--)
895 { 896 {
896 i = (int)d; 897 i = (int)d;
897 t = d - (double)i; 898 t = d - (double)i;
898 t *= pow(10,x - 2); 899 t *= pow(10,x - 2);
899 i = (int)t; 900 i = (int)t;
900 t = t - (double)i; 901 t = t - (double)i;
901 t *= 10; 902 t *= 10;
902 i = (int)t; 903 i = (int)t;
903 if (i > 0) break; 904 if (i > 0) break;
904 count++; 905 count++;
905 }; 906 };
906 return (5 - count); 907 return (5 - count);
907}; 908};
908 909
909 910
910void ExcelBook::CellSetDateFormat(char *d) 911void ExcelBook::CellSetDateFormat(char *d)
911{ 912{
912 dateformat = QString(d); 913 dateformat = QString(d);
913}; 914};
914 915
915void ExcelBook::HandleMulrk(ExcelSheet* sheet, ExcelBREC* record) 916void ExcelBook::HandleMulrk(ExcelSheet* sheet, ExcelBREC* record)
916{ 917{
917 struct mulrk mulrk; 918 struct mulrk mulrk;
918 char* data; 919 char* data;
919 ExcelCell* cell; 920 ExcelCell* cell;
920 int len; 921 int len;
921 int i; 922 int i;
922 len = record->length; 923 len = record->length;
923 data = GetDataOfBREC(record); 924 data = GetDataOfBREC(record);
924 mulrk.row = Integer2Byte(data[0],data[1]); 925 mulrk.row = Integer2Byte(data[0],data[1]);
925 mulrk.first = Integer2Byte(data[2],data[3]); 926 mulrk.first = Integer2Byte(data[2],data[3]);
926 mulrk.last = Integer2Byte(data[len - 2],data[len - 1]); 927 mulrk.last = Integer2Byte(data[len - 2],data[len - 1]);
927 mulrk.numrks = mulrk.last - mulrk.first + 1; 928 mulrk.numrks = mulrk.last - mulrk.first + 1;
928 MulrkRead(&mulrk, data); 929 MulrkRead(&mulrk, data);
929 for (i = 0; i < mulrk.numrks; i++) 930 for (i = 0; i < mulrk.numrks; i++)
930 { 931 {
931 cell = CellNumber(mulrk.row, mulrk.first + i, mulrk.xfindices[i], mulrk.rkdbls[i]); 932 cell = CellNumber(mulrk.row, mulrk.first + i, mulrk.xfindices[i], mulrk.rkdbls[i]);
932 sheet->Set(mulrk.row,mulrk.first+ i, cell); 933 sheet->Set(mulrk.row,mulrk.first+ i, cell);
933 //printf("handleMULRK:row=%d,col=%d,val=%f\r\n",mulrk.row,mulrk.first+i,mulrk.rkdbls[i]); 934 //printf("handleMULRK:row=%d,col=%d,val=%f\r\n",mulrk.row,mulrk.first+i,mulrk.rkdbls[i]);
934 } 935 }
935 //delete(mulrk.xfindices); 936 //delete(mulrk.xfindices);
936 //delete(mulrk.rkdbls); 937 //delete(mulrk.rkdbls);
937}; 938};
938 939
939void ExcelBook::MulrkRead(struct mulrk *mulrk, char* data) 940void ExcelBook::MulrkRead(struct mulrk *mulrk, char* data)
940{ 941{
941 double d; 942 double d;
942 int i; 943 int i;
943 int pos; 944 int pos;
944 pos = 4; 945 pos = 4;
945 mulrk->xfindices.resize(mulrk->numrks); 946 mulrk->xfindices.resize(mulrk->numrks);
946 mulrk->rkdbls.resize(mulrk->numrks); 947 mulrk->rkdbls.resize(mulrk->numrks);
947 for (i = 0; i < mulrk->numrks; i++) 948 for (i = 0; i < mulrk->numrks; i++)
948 { 949 {
949 mulrk->xfindices[i] = Integer2Byte(data[pos], data[pos+1]); 950 mulrk->xfindices[i] = Integer2Byte(data[pos], data[pos+1]);
950 d=Double4Byte(data[pos+2], data[pos+3], data[pos+4], data[pos+5]); 951 d=Double4Byte(data[pos+2], data[pos+3], data[pos+4], data[pos+5]);
951 //printf("double:%f\r\n",d); 952 //printf("double:%f\r\n",d);
952 mulrk->rkdbls[i] = d; 953 mulrk->rkdbls[i] = d;
953 pos += 6; 954 pos += 6;
954 } 955 }
955}; 956};
956 957
957 958
958void ExcelBook::HandleNumber(ExcelSheet* sheet, ExcelBREC* record) 959void ExcelBook::HandleNumber(ExcelSheet* sheet, ExcelBREC* record)
959{ 960{
960 int xfindex, row, col; 961 int xfindex, row, col;
961 char* data; 962 char* data;
962 double d; 963 double d;
963 data = GetDataOfBREC(record); 964 data = GetDataOfBREC(record);
964 row = Integer2Byte(data[0], data[1]); 965 row = Integer2Byte(data[0], data[1]);
965 col = Integer2Byte(data[2], data[3]); 966 col = Integer2Byte(data[2], data[3]);
966 xfindex = Integer2Byte(data[4], data[5]); 967 xfindex = Integer2Byte(data[4], data[5]);
967#if defined(__arm__) && !defined(__vfp__) 968#if defined(__arm__) && !defined(__vfp__)
968 d=Double8Byte(data[10], data[11], data[12], data[13],data[6], data[7], data[8], data[9]); 969 d=Double8Byte(data[10], data[11], data[12], data[13],data[6], data[7], data[8], data[9]);
969#else 970#else
970 d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]); 971 d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]);
971#endif 972#endif
972 //even if ARM is little endian... doubles are been placed as bigendian words. 973 //even if ARM is little endian... doubles are been placed as bigendian words.
973 //thanks pb_ for that. :) 974 //thanks pb_ for that. :)
974 sheet->Set(row,col, CellNumber(row,col,xfindex,d)); 975 sheet->Set(row,col, CellNumber(row,col,xfindex,d));
975 //printf("handleNumber:row=%d,col=%d,val=%f\r\n",row,col,d); 976 //printf("handleNumber:row=%d,col=%d,val=%f\r\n",row,col,d);
976}; 977};
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
@@ -496,533 +496,536 @@ void MainWindow::initMenu()
496 addFlyAction(tr("IF(compare,val1,val2)"), tr("IF(compare,val1,val2)"), "IF(", submenuFuncLogic); 496 addFlyAction(tr("IF(compare,val1,val2)"), tr("IF(compare,val1,val2)"), "IF(", submenuFuncLogic);
497 addFlyAction(tr("INDEX(range,index)"),tr("INDEX(range,index)"), "INDEX(", submenuFuncLogic); 497 addFlyAction(tr("INDEX(range,index)"),tr("INDEX(range,index)"), "INDEX(", submenuFuncLogic);
498 addFlyAction(tr("ISBLANK(x)"), tr("ISBLANK(x)"), "ISBLANK(", submenuFuncLogic); 498 addFlyAction(tr("ISBLANK(x)"), tr("ISBLANK(x)"), "ISBLANK(", submenuFuncLogic);
499 addFlyAction(tr("ISNUMBER(x)"), tr("ISNUMBER(x)"), "ISNUMBER(", submenuFuncLogic); 499 addFlyAction(tr("ISNUMBER(x)"), tr("ISNUMBER(x)"), "ISNUMBER(", submenuFuncLogic);
500 addFlyAction(tr("EVEN(x)"), tr("EVEN(x)"), "EVEN(", submenuFuncLogic); 500 addFlyAction(tr("EVEN(x)"), tr("EVEN(x)"), "EVEN(", submenuFuncLogic);
501 addFlyAction(tr("ISEVEN(x)"), tr("ISEVEN(x)"), "ISEVEN(", submenuFuncLogic); 501 addFlyAction(tr("ISEVEN(x)"), tr("ISEVEN(x)"), "ISEVEN(", submenuFuncLogic);
502 addFlyAction(tr("ODD(x)"), tr("ODD(x)"), "ODD(", submenuFuncLogic); 502 addFlyAction(tr("ODD(x)"), tr("ODD(x)"), "ODD(", submenuFuncLogic);
503 addFlyAction(tr("ISODD(x)"), tr("ISODD(x)"), "ISODD(", submenuFuncLogic); 503 addFlyAction(tr("ISODD(x)"), tr("ISODD(x)"), "ISODD(", submenuFuncLogic);
504 submenuFunc->insertItem(tr("Logical-&Information"), submenuFuncLogic); 504 submenuFunc->insertItem(tr("Logical-&Information"), submenuFuncLogic);
505 505
506 submenuFuncTrig=new QPopupMenu; 506 submenuFuncTrig=new QPopupMenu;
507 addFlyAction(tr("SIN(x)"), tr("SIN(x)"), "SIN(", submenuFuncTrig); 507 addFlyAction(tr("SIN(x)"), tr("SIN(x)"), "SIN(", submenuFuncTrig);
508 addFlyAction(tr("COS(x)"), tr("COS(x)"), "COS(", submenuFuncTrig); 508 addFlyAction(tr("COS(x)"), tr("COS(x)"), "COS(", submenuFuncTrig);
509 addFlyAction(tr("TAN(x)"), tr("TAN(x)"), "TAN(", submenuFuncTrig); 509 addFlyAction(tr("TAN(x)"), tr("TAN(x)"), "TAN(", submenuFuncTrig);
510 addFlyAction(tr("ASIN(x)"), tr("ASIN(x)"), "ASIN(", submenuFuncTrig); 510 addFlyAction(tr("ASIN(x)"), tr("ASIN(x)"), "ASIN(", submenuFuncTrig);
511 addFlyAction(tr("ACOS(x)"), tr("ACOS(x)"), "ACOS(", submenuFuncTrig); 511 addFlyAction(tr("ACOS(x)"), tr("ACOS(x)"), "ACOS(", submenuFuncTrig);
512 addFlyAction(tr("ATAN(x)"), tr("ATAN(x)"), "ATAN(", submenuFuncTrig); 512 addFlyAction(tr("ATAN(x)"), tr("ATAN(x)"), "ATAN(", submenuFuncTrig);
513 addFlyAction(tr("ATAN2(x,y)"), tr("ATAN2(x,y)"), "ATAN2(", submenuFuncTrig); 513 addFlyAction(tr("ATAN2(x,y)"), tr("ATAN2(x,y)"), "ATAN2(", submenuFuncTrig);
514 submenuFuncTrig->insertSeparator(); 514 submenuFuncTrig->insertSeparator();
515 addFlyAction(tr("SINH(x)"), tr("SINH(x)"), "SINH(", submenuFuncTrig); 515 addFlyAction(tr("SINH(x)"), tr("SINH(x)"), "SINH(", submenuFuncTrig);
516 addFlyAction(tr("COSH(x)"), tr("COSH(x)"), "COSH(", submenuFuncTrig); 516 addFlyAction(tr("COSH(x)"), tr("COSH(x)"), "COSH(", submenuFuncTrig);
517 addFlyAction(tr("TANH(x)"), tr("TANH(x)"), "TANH(", submenuFuncTrig); 517 addFlyAction(tr("TANH(x)"), tr("TANH(x)"), "TANH(", submenuFuncTrig);
518 addFlyAction(tr("ACOSH(x)"), tr("ACOSH(x)"), "ACOSH(", submenuFuncTrig); 518 addFlyAction(tr("ACOSH(x)"), tr("ACOSH(x)"), "ACOSH(", submenuFuncTrig);
519 addFlyAction(tr("ASINH(x)"), tr("ASINH(x)"), "ASINH(", submenuFuncTrig); 519 addFlyAction(tr("ASINH(x)"), tr("ASINH(x)"), "ASINH(", submenuFuncTrig);
520 addFlyAction(tr("ATANH(x)"), tr("ATANH(x)"), "ATANH(", submenuFuncTrig); 520 addFlyAction(tr("ATANH(x)"), tr("ATANH(x)"), "ATANH(", submenuFuncTrig);
521 submenuFunc->insertItem(tr("&Trigonometric"), submenuFuncTrig); 521 submenuFunc->insertItem(tr("&Trigonometric"), submenuFuncTrig);
522 522
523 submenuFuncString=new QPopupMenu; 523 submenuFuncString=new QPopupMenu;
524 addFlyAction(tr("LEN(s)"), tr("LEN(s)"), "LEN(",submenuFuncString); 524 addFlyAction(tr("LEN(s)"), tr("LEN(s)"), "LEN(",submenuFuncString);
525 addFlyAction(tr("LEFT(s,num)"), tr("LEFT(s,num)"), "LEFT(",submenuFuncString); 525 addFlyAction(tr("LEFT(s,num)"), tr("LEFT(s,num)"), "LEFT(",submenuFuncString);
526 addFlyAction(tr("RIGHT(s,num)"), tr("RIGHT(s,num)"), "RIGHT(",submenuFuncString); 526 addFlyAction(tr("RIGHT(s,num)"), tr("RIGHT(s,num)"), "RIGHT(",submenuFuncString);
527 addFlyAction(tr("MID(s,pos,len)"), tr("MID(s,pos,len)"), "MID(",submenuFuncString); 527 addFlyAction(tr("MID(s,pos,len)"), tr("MID(s,pos,len)"), "MID(",submenuFuncString);
528 submenuFuncString->insertSeparator(); 528 submenuFuncString->insertSeparator();
529 addFlyAction(tr("CONCATENATE(s1,s2..)"), tr("CONCATENATE(s1,s2..)"), "CONCATENATE(",submenuFuncString); 529 addFlyAction(tr("CONCATENATE(s1,s2..)"), tr("CONCATENATE(s1,s2..)"), "CONCATENATE(",submenuFuncString);
530 addFlyAction(tr("EXACT(s1,s2)"), tr("EXACT(s1,s2)"), "EXACT(",submenuFuncString); 530 addFlyAction(tr("EXACT(s1,s2)"), tr("EXACT(s1,s2)"), "EXACT(",submenuFuncString);
531 addFlyAction(tr("FIND(what,where,pos)"), 531 addFlyAction(tr("FIND(what,where,pos)"),
532 tr("FIND(what,where,pos)"), "FIND(",submenuFuncString); 532 tr("FIND(what,where,pos)"), "FIND(",submenuFuncString);
533 addFlyAction(tr("REPLACE(s,pos,len,ns)"), tr("REPLACE(s,pos,len,ns)"), "REPLACE(",submenuFuncString); 533 addFlyAction(tr("REPLACE(s,pos,len,ns)"), tr("REPLACE(s,pos,len,ns)"), "REPLACE(",submenuFuncString);
534 addFlyAction(tr("REPT(s,n)"), tr("REPT(s,n)"), "REPT(",submenuFuncString); 534 addFlyAction(tr("REPT(s,n)"), tr("REPT(s,n)"), "REPT(",submenuFuncString);
535 submenuFuncString->insertSeparator(); 535 submenuFuncString->insertSeparator();
536 addFlyAction(tr("UPPER(s)"), tr("UPPER(s)"), "UPPER(",submenuFuncString); 536 addFlyAction(tr("UPPER(s)"), tr("UPPER(s)"), "UPPER(",submenuFuncString);
537 addFlyAction(tr("LOWER(s)"), tr("LOWER(s)"), "LOWER(",submenuFuncString); 537 addFlyAction(tr("LOWER(s)"), tr("LOWER(s)"), "LOWER(",submenuFuncString);
538 submenuFunc->insertItem(tr("&Strings"), submenuFuncString); 538 submenuFunc->insertItem(tr("&Strings"), submenuFuncString);
539 539
540 submenuFuncStat=new QPopupMenu; 540 submenuFuncStat=new QPopupMenu;
541 addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat); 541 addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat);
542 addFlyAction(tr("COUNT(range)"), tr("COUNT(range)"), "COUNT(",submenuFuncStat); 542 addFlyAction(tr("COUNT(range)"), tr("COUNT(range)"), "COUNT(",submenuFuncStat);
543 addFlyAction(tr("COUNTIF(range,eqls)"), tr("COUNTIF(range,eqls)"), "COUNTIF(",submenuFuncStat); 543 addFlyAction(tr("COUNTIF(range,eqls)"), tr("COUNTIF(range,eqls)"), "COUNTIF(",submenuFuncStat);
544 addFlyAction(tr("MAX(range)"), tr("MAX(range)"), "MAX(",submenuFuncStat); 544 addFlyAction(tr("MAX(range)"), tr("MAX(range)"), "MAX(",submenuFuncStat);
545 addFlyAction(tr("MIN(range)"), tr("MIN(range)"), "MIN(",submenuFuncStat); 545 addFlyAction(tr("MIN(range)"), tr("MIN(range)"), "MIN(",submenuFuncStat);
546 addFlyAction(tr("SUM(range)"), tr("SUM(range)"), "SUM(",submenuFuncStat); 546 addFlyAction(tr("SUM(range)"), tr("SUM(range)"), "SUM(",submenuFuncStat);
547 addFlyAction(tr("SUMSQ(range)"), tr("SUMSQ(range)"), "SUMSQ(",submenuFuncStat); 547 addFlyAction(tr("SUMSQ(range)"), tr("SUMSQ(range)"), "SUMSQ(",submenuFuncStat);
548 submenuFuncStat->insertSeparator(); 548 submenuFuncStat->insertSeparator();
549 addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat); 549 addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat);
550 addFlyAction(tr("VAR(range)"), tr("VAR(range)"), "VAR(",submenuFuncStat); 550 addFlyAction(tr("VAR(range)"), tr("VAR(range)"), "VAR(",submenuFuncStat);
551 addFlyAction(tr("VARP(range)"), tr("VARP(range)"), "VARP(",submenuFuncStat); 551 addFlyAction(tr("VARP(range)"), tr("VARP(range)"), "VARP(",submenuFuncStat);
552 addFlyAction(tr("STDEV(range)"), tr("STDEV(range)"), "STDEV(",submenuFuncStat); 552 addFlyAction(tr("STDEV(range)"), tr("STDEV(range)"), "STDEV(",submenuFuncStat);
553 addFlyAction(tr("STDEVP(range)"), tr("STDEVP(range)"), "STDEVP(",submenuFuncStat); 553 addFlyAction(tr("STDEVP(range)"), tr("STDEVP(range)"), "STDEVP(",submenuFuncStat);
554 addFlyAction(tr("SKEW(range)"), tr("SKEW(range)"), "SKEW(",submenuFuncStat); 554 addFlyAction(tr("SKEW(range)"), tr("SKEW(range)"), "SKEW(",submenuFuncStat);
555 addFlyAction(tr("KURT(range)"), tr("KURT(range)"), "KURT(",submenuFuncStat); 555 addFlyAction(tr("KURT(range)"), tr("KURT(range)"), "KURT(",submenuFuncStat);
556 submenuFunc->insertItem(tr("Sta&tistical"), submenuFuncStat); 556 submenuFunc->insertItem(tr("Sta&tistical"), submenuFuncStat);
557 557
558 submenuFuncScientific=new QPopupMenu; 558 submenuFuncScientific=new QPopupMenu;
559 addFlyAction(tr("BESSELI(x,n)"), tr("BESSELI(x,n)"), "BESSELI(",submenuFuncScientific); 559 addFlyAction(tr("BESSELI(x,n)"), tr("BESSELI(x,n)"), "BESSELI(",submenuFuncScientific);
560 addFlyAction(tr("BESSELJ(x,n)"), tr("BESSELJ(x,n)"), "BESSELJ(",submenuFuncScientific); 560 addFlyAction(tr("BESSELJ(x,n)"), tr("BESSELJ(x,n)"), "BESSELJ(",submenuFuncScientific);
561 addFlyAction(tr("BESSELK(x,n)"), tr("BESSELK(x,n)"), "BESSELK(",submenuFuncScientific); 561 addFlyAction(tr("BESSELK(x,n)"), tr("BESSELK(x,n)"), "BESSELK(",submenuFuncScientific);
562 addFlyAction(tr("BESSELY(x,n)"), tr("BESSELY(x,n)"), "BESSELY(",submenuFuncScientific); 562 addFlyAction(tr("BESSELY(x,n)"), tr("BESSELY(x,n)"), "BESSELY(",submenuFuncScientific);
563 submenuFuncScientific->insertSeparator(); 563 submenuFuncScientific->insertSeparator();
564 addFlyAction(tr("BETAI(x,a,b)"), tr("BETAI(x,a,b)"), "BETAI(",submenuFuncScientific); 564 addFlyAction(tr("BETAI(x,a,b)"), tr("BETAI(x,a,b)"), "BETAI(",submenuFuncScientific);
565 addFlyAction(tr("ERF(a,b)"), tr("ERF(a,b)"), "ERF(",submenuFuncScientific); 565 addFlyAction(tr("ERF(a,b)"), tr("ERF(a,b)"), "ERF(",submenuFuncScientific);
566 addFlyAction(tr("ERFC(a,b)"), tr("ERFC(a,b)"), "ERFC(",submenuFuncScientific); 566 addFlyAction(tr("ERFC(a,b)"), tr("ERFC(a,b)"), "ERFC(",submenuFuncScientific);
567 addFlyAction(tr("GAMMALN(x)"), tr("GAMMALN(x)"), "GAMMALN(",submenuFuncScientific); 567 addFlyAction(tr("GAMMALN(x)"), tr("GAMMALN(x)"), "GAMMALN(",submenuFuncScientific);
568 addFlyAction(tr("GAMMAP(x,a)"), tr("GAMMAP(x,a)"), "GAMMAP(",submenuFuncScientific); 568 addFlyAction(tr("GAMMAP(x,a)"), tr("GAMMAP(x,a)"), "GAMMAP(",submenuFuncScientific);
569 addFlyAction(tr("GAMMAQ(x,a)"), tr("GAMMAQ(x,a)"), "GAMMAQ(",submenuFuncScientific); 569 addFlyAction(tr("GAMMAQ(x,a)"), tr("GAMMAQ(x,a)"), "GAMMAQ(",submenuFuncScientific);
570 submenuFunc->insertItem(tr("Scienti&fic"), submenuFuncScientific); 570 submenuFunc->insertItem(tr("Scienti&fic"), submenuFuncScientific);
571 571
572 submenuFuncDistr=new QPopupMenu; 572 submenuFuncDistr=new QPopupMenu;
573 addFlyAction(tr("BETADIST(z,a,b,Q?)"), tr("BETADIST(z,a,b,Q?)"), "BETADIST(",submenuFuncDistr); 573 addFlyAction(tr("BETADIST(z,a,b,Q?)"), tr("BETADIST(z,a,b,Q?)"), "BETADIST(",submenuFuncDistr);
574 addFlyAction(tr("CHI2DIST(x,n,Q?)"), tr("CHI2DIST(x,n,Q?)"), "CHI2DIST(",submenuFuncDistr); 574 addFlyAction(tr("CHI2DIST(x,n,Q?)"), tr("CHI2DIST(x,n,Q?)"), "CHI2DIST(",submenuFuncDistr);
575 addFlyAction(tr("CHIDIST(x,n,Q?)"), tr("CHIDIST(x,n,Q?)"), "CHIDIST(",submenuFuncDistr); 575 addFlyAction(tr("CHIDIST(x,n,Q?)"), tr("CHIDIST(x,n,Q?)"), "CHIDIST(",submenuFuncDistr);
576 addFlyAction(tr("FDIST(z,deg1,deg2,Q?)"), tr("FDIST(z,deg1,deg2,Q?)"), "FDIST(",submenuFuncDistr); 576 addFlyAction(tr("FDIST(z,deg1,deg2,Q?)"), tr("FDIST(z,deg1,deg2,Q?)"), "FDIST(",submenuFuncDistr);
577 addFlyAction(tr("GAMMADIST(x,a,b,Q?)"), tr("GAMMADIST(x,a,b,Q?)"), "GAMMADIST(",submenuFuncDistr); 577 addFlyAction(tr("GAMMADIST(x,a,b,Q?)"), tr("GAMMADIST(x,a,b,Q?)"), "GAMMADIST(",submenuFuncDistr);
578 addFlyAction(tr("NORMALDIST(x,m,s,Q?)"), tr("NORMALDIST(x,m,s,Q?)"), "NORMALDIST(",submenuFuncDistr); 578 addFlyAction(tr("NORMALDIST(x,m,s,Q?)"), tr("NORMALDIST(x,m,s,Q?)"), "NORMALDIST(",submenuFuncDistr);
579 addFlyAction(tr("PHI(x,Q?)"), tr("PHI(x,Q?)"), "PHI(",submenuFuncDistr); 579 addFlyAction(tr("PHI(x,Q?)"), tr("PHI(x,Q?)"), "PHI(",submenuFuncDistr);
580 addFlyAction(tr("POISSON(x,n,Q?)"), tr("POISSON(x,n,Q?)"), "POISSON(",submenuFuncDistr); 580 addFlyAction(tr("POISSON(x,n,Q?)"), tr("POISSON(x,n,Q?)"), "POISSON(",submenuFuncDistr);
581 submenuFunc->insertItem(tr("&Distributions"), submenuFuncDistr); 581 submenuFunc->insertItem(tr("&Distributions"), submenuFuncDistr);
582 582
583 583
584 584
585 menuInsert->insertSeparator(); 585 menuInsert->insertSeparator();
586 insertCells->addTo(menuInsert); 586 insertCells->addTo(menuInsert);
587 insertRows->addTo(menuInsert); 587 insertRows->addTo(menuInsert);
588 insertCols->addTo(menuInsert); 588 insertCols->addTo(menuInsert);
589 insertSheets->addTo(menuInsert); 589 insertSheets->addTo(menuInsert);
590} 590}
591 591
592void MainWindow::initStandardToolbar() 592void MainWindow::initStandardToolbar()
593{ 593{
594 toolbarStandard=new QToolBar(this); 594 toolbarStandard=new QToolBar(this);
595 toolbarStandard->setHorizontalStretchable(TRUE); 595 toolbarStandard->setHorizontalStretchable(TRUE);
596 moveToolBar(toolbarStandard, Top); 596 moveToolBar(toolbarStandard, Top);
597 597
598 fileNew->addTo(toolbarStandard); 598 fileNew->addTo(toolbarStandard);
599 fileOpen->addTo(toolbarStandard); 599 fileOpen->addTo(toolbarStandard);
600 fileSave->addTo(toolbarStandard); 600 fileSave->addTo(toolbarStandard);
601 601
602 comboSheets=new QComboBox(toolbarStandard); 602 comboSheets=new QComboBox(toolbarStandard);
603 toolbarStandard->setStretchableWidget(comboSheets); 603 toolbarStandard->setStretchableWidget(comboSheets);
604 connect(comboSheets, SIGNAL(activated(const QString&)), this, SLOT(slotSheetChanged(const QString&))); 604 connect(comboSheets, SIGNAL(activated(const QString&)), this, SLOT(slotSheetChanged(const QString&)));
605} 605}
606 606
607void MainWindow::initFunctionsToolbar() 607void MainWindow::initFunctionsToolbar()
608{ 608{
609 toolbarFunctions=new QToolBar(this); 609 toolbarFunctions=new QToolBar(this);
610 toolbarFunctions->setHorizontalStretchable(TRUE); 610 toolbarFunctions->setHorizontalStretchable(TRUE);
611 moveToolBar(toolbarFunctions, Bottom); 611 moveToolBar(toolbarFunctions, Bottom);
612 612
613 funcEqual->addTo(toolbarFunctions); 613 funcEqual->addTo(toolbarFunctions);
614 funcPlus->addTo(toolbarFunctions); 614 funcPlus->addTo(toolbarFunctions);
615 funcMinus->addTo(toolbarFunctions); 615 funcMinus->addTo(toolbarFunctions);
616 funcCross->addTo(toolbarFunctions); 616 funcCross->addTo(toolbarFunctions);
617 funcDivide->addTo(toolbarFunctions); 617 funcDivide->addTo(toolbarFunctions);
618 funcParanOpen->addTo(toolbarFunctions); 618 funcParanOpen->addTo(toolbarFunctions);
619 funcParanClose->addTo(toolbarFunctions); 619 funcParanClose->addTo(toolbarFunctions);
620 funcComma->addTo(toolbarFunctions); 620 funcComma->addTo(toolbarFunctions);
621 621
622 toolFunction=new QToolButton(toolbarFunctions); 622 toolFunction=new QToolButton(toolbarFunctions);
623 toolFunction->setPixmap(Resource::loadPixmap( "opie-sheet/func-func" )); 623 toolFunction->setPixmap(Resource::loadPixmap( "opie-sheet/func-func" ));
624 toolFunction->setTextLabel(tr("Functions")); 624 toolFunction->setTextLabel(tr("Functions"));
625 toolFunction->setPopup(submenuFunc); 625 toolFunction->setPopup(submenuFunc);
626 toolFunction->setPopupDelay(0); 626 toolFunction->setPopupDelay(0);
627} 627}
628 628
629void MainWindow::initEditToolbar() 629void MainWindow::initEditToolbar()
630{ 630{
631 toolbarEdit=new QToolBar(this); 631 toolbarEdit=new QToolBar(this);
632 toolbarEdit->setHorizontalStretchable(TRUE); 632 toolbarEdit->setHorizontalStretchable(TRUE);
633 moveToolBar(toolbarEdit, Bottom); 633 moveToolBar(toolbarEdit, Bottom);
634 634
635 editAccept->addTo(toolbarEdit); 635 editAccept->addTo(toolbarEdit);
636 editCancel->addTo(toolbarEdit); 636 editCancel->addTo(toolbarEdit);
637 637
638 editData=new QLineEdit(toolbarEdit); 638 editData=new QLineEdit(toolbarEdit);
639 toolbarEdit->setStretchableWidget(editData); 639 toolbarEdit->setStretchableWidget(editData);
640 connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept())); 640 connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept()));
641 641
642 editCellSelect->addTo(toolbarEdit); 642 editCellSelect->addTo(toolbarEdit);
643} 643}
644 644
645void MainWindow::slotHelpAbout() 645void MainWindow::slotHelpAbout()
646{ 646{
647 QDialog dialogAbout(this, 0, TRUE); 647 QDialog dialogAbout(this, 0, TRUE);
648 dialogAbout.resize(width()-40, height()-80); 648 dialogAbout.resize(width()-40, height()-80);
649 dialogAbout.setCaption(tr("About Opie Sheet")); 649 dialogAbout.setCaption(tr("About Opie Sheet"));
650 650
651 QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nRelease 1.0.2\nRelease Date: October 08, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout); 651 QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nRelease 1.0.2\nRelease Date: October 08, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout);
652 label.setGeometry(dialogAbout.rect()); 652 label.setGeometry(dialogAbout.rect());
653 label.setAlignment(Qt::AlignCenter | Qt::WordBreak); 653 label.setAlignment(Qt::AlignCenter | Qt::WordBreak);
654 654
655 dialogAbout.exec(); 655 dialogAbout.exec();
656} 656}
657 657
658void MainWindow::initSheet() 658void MainWindow::initSheet()
659{ 659{
660 sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this); 660 sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this);
661 setCentralWidget(sheet); 661 setCentralWidget(sheet);
662 662
663 connect(sheet, SIGNAL(currentDataChanged(const QString&)), editData, SLOT(setText(const QString&))); 663 connect(sheet, SIGNAL(currentDataChanged(const QString&)), editData, SLOT(setText(const QString&)));
664 connect(sheet, SIGNAL(cellClicked(const QString&)), this, SLOT(slotCellClicked(const QString&))); 664 connect(sheet, SIGNAL(cellClicked(const QString&)), this, SLOT(slotCellClicked(const QString&)));
665 connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified())); 665 connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified()));
666 666
667 connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut())); 667 connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut()));
668 connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy())); 668 connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy()));
669 connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear())); 669 connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear()));
670} 670}
671 671
672void MainWindow::slotEditAccept() 672void MainWindow::slotEditAccept()
673{ 673{
674 sheet->setData(editData->text()); 674 sheet->setData(editData->text());
675} 675}
676 676
677void MainWindow::slotEditCancel() 677void MainWindow::slotEditCancel()
678{ 678{
679 editData->setText(sheet->getData()); 679 editData->setText(sheet->getData());
680} 680}
681 681
682void MainWindow::slotCellSelect(bool lock) 682void MainWindow::slotCellSelect(bool lock)
683{ 683{
684 sheet->lockClicks(lock); 684 sheet->lockClicks(lock);
685} 685}
686 686
687void MainWindow::addToData(const QString &data) 687void MainWindow::addToData(const QString &data)
688{ 688{
689 editData->setText(editData->text().insert(editData->cursorPosition(), data)); 689 editData->setText(editData->text().insert(editData->cursorPosition(), data));
690} 690}
691 691
692void MainWindow::slotFuncOutput() 692void MainWindow::slotFuncOutput()
693{ 693{
694 if (sender()->isA("QAction")) 694 if (sender()->isA("QAction"))
695 addToData(((QAction *)sender())->toolTip()); 695 addToData(((QAction *)sender())->toolTip());
696} 696}
697 697
698void MainWindow::slotInsertRows() 698void MainWindow::slotInsertRows()
699{ 699{
700 NumberDialog dialogNumber(this); 700 NumberDialog dialogNumber(this);
701 if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted) 701 if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted)
702 sheet->insertRows(dialogNumber.getValue()); 702 sheet->insertRows(dialogNumber.getValue());
703} 703}
704 704
705void MainWindow::slotInsertCols() 705void MainWindow::slotInsertCols()
706{ 706{
707 NumberDialog dialogNumber(this); 707 NumberDialog dialogNumber(this);
708 if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted) 708 if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted)
709 sheet->insertColumns(dialogNumber.getValue()); 709 sheet->insertColumns(dialogNumber.getValue());
710} 710}
711 711
712void MainWindow::slotInsertSheets() 712void MainWindow::slotInsertSheets()
713{ 713{
714 NumberDialog dialogNumber(this); 714 NumberDialog dialogNumber(this);
715 if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted) 715 if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted)
716 for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet(); 716 for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet();
717} 717}
718 718
719void MainWindow::slotCellClicked(const QString &cell) 719void MainWindow::slotCellClicked(const QString &cell)
720{ 720{
721 editCellSelect->setOn(FALSE); 721 editCellSelect->setOn(FALSE);
722 addToData(cell); 722 addToData(cell);
723} 723}
724 724
725typeSheet *MainWindow::createNewSheet() 725typeSheet *MainWindow::createNewSheet()
726{ 726{
727 typeSheet *newSheet=new typeSheet; 727 typeSheet *newSheet=new typeSheet;
728 int currentNo=1, tempNo=0; 728 int currentNo=1, tempNo=0;
729 bool ok; 729 bool ok;
730 730
731 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) 731 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
732 if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok) 732 if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok)
733 currentNo=tempNo+1; 733 currentNo=tempNo+1;
734 734
735 newSheet->name=tr("Sheet")+QString::number(currentNo); 735 newSheet->name=tr("Sheet")+QString::number(currentNo);
736 newSheet->data.setAutoDelete(TRUE); 736 newSheet->data.setAutoDelete(TRUE);
737 737
738 comboSheets->insertItem(newSheet->name); 738 comboSheets->insertItem(newSheet->name);
739 listSheets.append(newSheet); 739 listSheets.append(newSheet);
740 return newSheet; 740 return newSheet;
741} 741}
742 742
743typeSheet *MainWindow::findSheet(const QString &name) 743typeSheet *MainWindow::findSheet(const QString &name)
744{ 744{
745 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) 745 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
746 if (tempSheet->name==name) 746 if (tempSheet->name==name)
747 return tempSheet; 747 return tempSheet;
748 return NULL; 748 return NULL;
749} 749}
750 750
751void MainWindow::slotSheetChanged(const QString &name) 751void MainWindow::slotSheetChanged(const QString &name)
752{ 752{
753 sheet->copySheetData(&findSheet(sheet->getName())->data); 753 sheet->copySheetData(&findSheet(sheet->getName())->data);
754 sheet->setName(name); 754 sheet->setName(name);
755 sheet->setSheetData(&findSheet(name)->data); 755 sheet->setSheetData(&findSheet(name)->data);
756 sheet->ReCalc(); 756 sheet->ReCalc();
757} 757}
758 758
759void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w) 759void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w)
760{ 760{
761 QAction *action=new QAction(text, menuText, 0, this); 761 QAction *action=new QAction(text, menuText, 0, this);
762 action->setToolTip(tip); 762 action->setToolTip(tip);
763 connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput())); 763 connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
764 action->addTo(w); 764 action->addTo(w);
765} 765}
766 766
767void MainWindow::slotFormatCells() 767void MainWindow::slotFormatCells()
768{ 768{
769 CellFormat dialogCellFormat(this); 769 CellFormat dialogCellFormat(this);
770 QPEApplication::showDialog( &dialogCellFormat ); 770 QPEApplication::showDialog( &dialogCellFormat );
771 dialogCellFormat.exec(sheet); 771 dialogCellFormat.exec(sheet);
772} 772}
773 773
774void MainWindow::slotEditPaste() 774void MainWindow::slotEditPaste()
775{ 775{
776 sheet->editPaste(); 776 sheet->editPaste();
777} 777}
778 778
779void MainWindow::slotEditPasteContents() 779void MainWindow::slotEditPasteContents()
780{ 780{
781 sheet->editPaste(TRUE); 781 sheet->editPaste(TRUE);
782} 782}
783 783
784void MainWindow::slotRowHeight() 784void MainWindow::slotRowHeight()
785{ 785{
786 int row1, row2, col1, col2; 786 int row1, row2, col1, col2;
787 sheet->getSelection(&row1, &col1, &row2, &col2); 787 sheet->getSelection(&row1, &col1, &row2, &col2);
788 788
789 NumberDialog dialogNumber(this); 789 NumberDialog dialogNumber(this);
790 if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted) 790 if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted)
791 { 791 {
792 int newHeight=dialogNumber.getValue(), row; 792 int newHeight=dialogNumber.getValue(), row;
793 for (row=row1; row<=row2; ++row) 793 for (row=row1; row<=row2; ++row)
794 sheet->setRowHeight(row, newHeight); 794 sheet->setRowHeight(row, newHeight);
795 } 795 }
796} 796}
797 797
798void MainWindow::slotRowAdjust() 798void MainWindow::slotRowAdjust()
799{ 799{
800 int row1, row2, col1, col2; 800 int row1, row2, col1, col2;
801 sheet->getSelection(&row1, &col1, &row2, &col2); 801 sheet->getSelection(&row1, &col1, &row2, &col2);
802 802
803 for (int row=row1; row<=row2; ++row) 803 for (int row=row1; row<=row2; ++row)
804 sheet->adjustRow(row); 804 sheet->adjustRow(row);
805} 805}
806 806
807void MainWindow::slotRowShow() 807void MainWindow::slotRowShow()
808{ 808{
809 int row1, row2, col1, col2; 809 int row1, row2, col1, col2;
810 sheet->getSelection(&row1, &col1, &row2, &col2); 810 sheet->getSelection(&row1, &col1, &row2, &col2);
811 811
812 for (int row=row1; row<=row2; ++row) 812 for (int row=row1; row<=row2; ++row)
813 sheet->showRow(row); 813 sheet->showRow(row);
814} 814}
815 815
816void MainWindow::slotRowHide() 816void MainWindow::slotRowHide()
817{ 817{
818 int row1, row2, col1, col2; 818 int row1, row2, col1, col2;
819 sheet->getSelection(&row1, &col1, &row2, &col2); 819 sheet->getSelection(&row1, &col1, &row2, &col2);
820 820
821 for (int row=row1; row<=row2; ++row) 821 for (int row=row1; row<=row2; ++row)
822 sheet->hideRow(row); 822 sheet->hideRow(row);
823} 823}
824 824
825void MainWindow::slotColumnWidth() 825void MainWindow::slotColumnWidth()
826{ 826{
827 int row1, row2, col1, col2; 827 int row1, row2, col1, col2;
828 sheet->getSelection(&row1, &col1, &row2, &col2); 828 sheet->getSelection(&row1, &col1, &row2, &col2);
829 829
830 NumberDialog dialogNumber(this); 830 NumberDialog dialogNumber(this);
831 if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted) 831 if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted)
832 { 832 {
833 int newWidth=dialogNumber.getValue(), col; 833 int newWidth=dialogNumber.getValue(), col;
834 for (col=col1; col<=col2; ++col) 834 for (col=col1; col<=col2; ++col)
835 sheet->setColumnWidth(col, newWidth); 835 sheet->setColumnWidth(col, newWidth);
836 } 836 }
837} 837}
838 838
839void MainWindow::slotColumnAdjust() 839void MainWindow::slotColumnAdjust()
840{ 840{
841 int row1, row2, col1, col2; 841 int row1, row2, col1, col2;
842 sheet->getSelection(&row1, &col1, &row2, &col2); 842 sheet->getSelection(&row1, &col1, &row2, &col2);
843 843
844 for (int col=col1; col<=col2; ++col) 844 for (int col=col1; col<=col2; ++col)
845 sheet->adjustColumn(col); 845 sheet->adjustColumn(col);
846} 846}
847 847
848void MainWindow::slotColumnShow() 848void MainWindow::slotColumnShow()
849{ 849{
850 int row1, row2, col1, col2; 850 int row1, row2, col1, col2;
851 sheet->getSelection(&row1, &col1, &row2, &col2); 851 sheet->getSelection(&row1, &col1, &row2, &col2);
852 852
853 for (int col=col1; col<=col2; ++col) 853 for (int col=col1; col<=col2; ++col)
854 sheet->showColumn(col); 854 sheet->showColumn(col);
855} 855}
856 856
857void MainWindow::slotColumnHide() 857void MainWindow::slotColumnHide()
858{ 858{
859 int row1, row2, col1, col2; 859 int row1, row2, col1, col2;
860 sheet->getSelection(&row1, &col1, &row2, &col2); 860 sheet->getSelection(&row1, &col1, &row2, &col2);
861 861
862 for (int col=col1; col<=col2; ++col) 862 for (int col=col1; col<=col2; ++col)
863 sheet->hideColumn(col); 863 sheet->hideColumn(col);
864} 864}
865 865
866void MainWindow::slotFileSaveAs() 866void MainWindow::slotFileSaveAs()
867{ 867{
868 TextDialog dialogText(this); 868 TextDialog dialogText(this);
869 if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; 869 if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
870 870
871 currentDoc->setName(dialogText.getValue()); 871 currentDoc->setName(dialogText.getValue());
872 currentDoc->setFile(QString::null); 872 currentDoc->setFile(QString::null);
873 currentDoc->setLinkFile(QString::null); 873 currentDoc->setLinkFile(QString::null);
874 documentSave(currentDoc); 874 documentSave(currentDoc);
875} 875}
876 876
877void MainWindow::slotImportExcel(const DocLnk &lnkDoc) 877void MainWindow::slotImportExcel(const DocLnk &lnkDoc)
878{ 878{
879 ExcelBook file1; 879 ExcelBook file1;
880 file1.ParseBook((char *)lnkDoc.file().ascii()); 880 if ( !file1.ParseBook((char *)lnkDoc.file().ascii()) ){
881 QMessageBox::critical(this, tr("Error"), tr("<td>Unable to open or parse file!</td>"));
882 return;
883 }
881 int NumOfSheets=file1.Sheets.count(); 884 int NumOfSheets=file1.Sheets.count();
882 printf("OpieSheet::NumberOfSheets:%d\r\n",NumOfSheets); 885 printf("OpieSheet::NumberOfSheets:%d\r\n",NumOfSheets);
883 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; 886 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
884 if (currentDoc) delete currentDoc; 887 if (currentDoc) delete currentDoc;
885 currentDoc = new DocLnk(); 888 currentDoc = new DocLnk();
886 listSheets.clear(); 889 listSheets.clear();
887 comboSheets->clear(); 890 comboSheets->clear();
888 int w1,r,c; 891 int w1,r,c;
889 ExcelSheet* sh1; 892 ExcelSheet* sh1;
890 typeSheet* newSheet; 893 typeSheet* newSheet;
891 QString* str; 894 QString* str;
892 typeCellData* newCell; 895 typeCellData* newCell;
893 for(w1=1;w1<=NumOfSheets;w1++) 896 for(w1=1;w1<=NumOfSheets;w1++)
894 { 897 {
895 sh1=file1.Sheets[w1-1]; 898 sh1=file1.Sheets[w1-1];
896 printf("OpieSheet:newSheet:%x,r=%d,c=%d\r\n",sh1,sh1->rows,sh1->cols); 899 // printf("OpieSheet:newSheet:%x,r=%d,c=%d\r\n",sh1, sh1->rows,sh1->cols);
897 newSheet=new typeSheet; 900 newSheet=new typeSheet;
898 newSheet->data.setAutoDelete(TRUE); 901 newSheet->data.setAutoDelete(TRUE);
899 newSheet->name=sh1->name; 902 newSheet->name=sh1->name;
900 printf("OpieSheet:Sheetname:%s\r\n",sh1->name.ascii()); 903 printf("OpieSheet:Sheetname:%s\r\n",sh1->name.ascii());
901 comboSheets->insertItem(newSheet->name); 904 comboSheets->insertItem(newSheet->name);
902 for(r=1; r <= sh1->rows; r++) 905 for(r=1; r <= sh1->rows; r++)
903 { 906 {
904 for(c=1;c <= sh1->cols; c++) 907 for(c=1;c <= sh1->cols; c++)
905 { 908 {
906 str=file1.CellDataString(sh1,r-1,c-1); 909 str=file1.CellDataString(sh1,r-1,c-1);
907 if(str!=NULL && r<DEFAULT_NUM_ROWS && c<DEFAULT_NUM_COLS) 910 if(str!=NULL && r<DEFAULT_NUM_ROWS && c<DEFAULT_NUM_COLS)
908 { 911 {
909 newCell=new typeCellData; 912 newCell=new typeCellData;
910 newCell->row=r-1; 913 newCell->row=r-1;
911 newCell->col=c-1; 914 newCell->col=c-1;
912 if(str!=NULL) newCell->data=QString(*str); else newCell->data=QString(""); 915 if(str!=NULL) newCell->data=QString(*str); else newCell->data=QString("");
913 newCell->background=QBrush(Qt::white, Qt::SolidPattern); 916 newCell->background=QBrush(Qt::white, Qt::SolidPattern);
914 newCell->alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); 917 newCell->alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop);
915 newCell->fontColor=Qt::black; 918 newCell->fontColor=Qt::black;
916 newCell->font=font(); 919 newCell->font=font();
917 newCell->borders.right=QPen(Qt::gray, 1, Qt::SolidLine); 920 newCell->borders.right=QPen(Qt::gray, 1, Qt::SolidLine);
918 newCell->borders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); 921 newCell->borders.bottom=QPen(Qt::gray, 1, Qt::SolidLine);
919 newSheet->data.append(newCell); 922 newSheet->data.append(newCell);
920 //there is no format parsing at the moment or style parsing 923 //there is no format parsing at the moment or style parsing
921 //printf("OpieSheetNumber:row=%d,col=%d,val=%s\r\n",r,c,str->latin1()); 924 //printf("OpieSheetNumber:row=%d,col=%d,val=%s\r\n",r,c,str->latin1());
922 }; 925 };
923 }; 926 };
924 }; 927 };
925 listSheets.append(newSheet); 928 listSheets.append(newSheet);
926 if (w1==1)//if i==0 link sheet1 with sheetview 929 if (w1==1)//if i==0 link sheet1 with sheetview
927 { 930 {
928 sheet->setName(newSheet->name); 931 sheet->setName(newSheet->name);
929 sheet->setSheetData(&newSheet->data); 932 sheet->setSheetData(&newSheet->data);
930 sheet->ReCalc(); 933 sheet->ReCalc();
931 }; 934 };
932 935
933 }; 936 };
934 file1.CloseFile(); 937 file1.CloseFile();
935 printf("Excel FILE read OK\r\n"); 938 printf("Excel FILE read OK\r\n");
936 documentModified=TRUE; 939 documentModified=TRUE;
937 940
938 941
939} 942}
940 943
941void MainWindow::slotSheetRename() 944void MainWindow::slotSheetRename()
942{ 945{
943 TextDialog dialogText(this); 946 TextDialog dialogText(this);
944 if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; 947 if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
945 QString newName=dialogText.getValue(); 948 QString newName=dialogText.getValue();
946 949
947 typeSheet *tempSheet=findSheet(newName); 950 typeSheet *tempSheet=findSheet(newName);
948 if (tempSheet) 951 if (tempSheet)
949 { 952 {
950 QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\'')); 953 QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\''));
951 return; 954 return;
952 } 955 }
953 956
954 tempSheet=findSheet(sheet->getName()); 957 tempSheet=findSheet(sheet->getName());
955 for (int i=0; i<comboSheets->count(); ++i) 958 for (int i=0; i<comboSheets->count(); ++i)
956 if (comboSheets->text(i)==tempSheet->name) 959 if (comboSheets->text(i)==tempSheet->name)
957 { 960 {
958 comboSheets->changeItem(newName, i); 961 comboSheets->changeItem(newName, i);
959 break; 962 break;
960 } 963 }
961 tempSheet->name=newName; 964 tempSheet->name=newName;
962 sheet->setName(newName); 965 sheet->setName(newName);
963} 966}
964 967
965void MainWindow::slotSheetRemove() 968void MainWindow::slotSheetRemove()
966{ 969{
967 if (comboSheets->count()<2) 970 if (comboSheets->count()<2)
968 { 971 {
969 QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!")); 972 QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!"));
970 return; 973 return;
971 } 974 }
972 if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) 975 if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
973 { 976 {
974 typeSheet *tempSheet=findSheet(sheet->getName()); 977 typeSheet *tempSheet=findSheet(sheet->getName());
975 for (int i=0; i<comboSheets->count(); ++i) 978 for (int i=0; i<comboSheets->count(); ++i)
976 if (comboSheets->text(i)==tempSheet->name) 979 if (comboSheets->text(i)==tempSheet->name)
977 { 980 {
978 comboSheets->removeItem(i); 981 comboSheets->removeItem(i);
979 break; 982 break;
980 } 983 }
981 comboSheets->setCurrentItem(0); 984 comboSheets->setCurrentItem(0);
982 slotSheetChanged(comboSheets->currentText()); 985 slotSheetChanged(comboSheets->currentText());
983 listSheets.remove(tempSheet); 986 listSheets.remove(tempSheet);
984 } 987 }
985} 988}
986 989
987void MainWindow::slotDataSort() 990void MainWindow::slotDataSort()
988{ 991{
989 SortDialog dialogSort(this); 992 SortDialog dialogSort(this);
990 QPEApplication::showDialog( &dialogSort ); 993 QPEApplication::showDialog( &dialogSort );
991 dialogSort.exec(sheet); 994 dialogSort.exec(sheet);
992} 995}
993 996
994void MainWindow::slotDocModified() 997void MainWindow::slotDocModified()
995{ 998{
996 documentModified=TRUE; 999 documentModified=TRUE;
997} 1000}
998 1001
999void MainWindow::slotInsertCells() 1002void MainWindow::slotInsertCells()
1000{ 1003{
1001 QDialog dialogInsert(this, 0, TRUE); 1004 QDialog dialogInsert(this, 0, TRUE);
1002 dialogInsert.resize(180, 130); 1005 dialogInsert.resize(180, 130);
1003 dialogInsert.setCaption(tr("Insert Cells")); 1006 dialogInsert.setCaption(tr("Insert Cells"));
1004 1007
1005 QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert); 1008 QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert);
1006 group->setGeometry(10, 10, 160, 110); 1009 group->setGeometry(10, 10, 160, 110);
1007 QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group); 1010 QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group);
1008 radio=new QRadioButton(tr("Shift cells &right"), group); 1011 radio=new QRadioButton(tr("Shift cells &right"), group);
1009 radio=new QRadioButton(tr("Entire ro&w"), group); 1012 radio=new QRadioButton(tr("Entire ro&w"), group);
1010 radio=new QRadioButton(tr("Entire &column"), group); 1013 radio=new QRadioButton(tr("Entire &column"), group);
1011 group->setButton(0); 1014 group->setButton(0);
1012 1015
1013 if (dialogInsert.exec()==QDialog::Accepted) 1016 if (dialogInsert.exec()==QDialog::Accepted)
1014 switch (group->id(group->selected())) 1017 switch (group->id(group->selected()))
1015 { 1018 {
1016 case 0: sheet->insertRows(1, FALSE); break; 1019 case 0: sheet->insertRows(1, FALSE); break;
1017 case 1: sheet->insertColumns(1, FALSE); break; 1020 case 1: sheet->insertColumns(1, FALSE); break;
1018 case 2: sheet->insertRows(1, TRUE); break; 1021 case 2: sheet->insertRows(1, TRUE); break;
1019 case 3: sheet->insertColumns(1, TRUE); break; 1022 case 3: sheet->insertColumns(1, TRUE); break;
1020 } 1023 }
1021} 1024}
1022 1025
1023void MainWindow::slotDataFindReplace() 1026void MainWindow::slotDataFindReplace()
1024{ 1027{
1025 FindDialog dialogFind(this); 1028 FindDialog dialogFind(this);
1026 QPEApplication::showDialog( &dialogFind ); 1029 QPEApplication::showDialog( &dialogFind );
1027 dialogFind.exec(sheet); 1030 dialogFind.exec(sheet);
1028} 1031}