KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3002 lines
75KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. * Boston, MA 02110-1301, USA.
  15. */
  16. #include "kspread_cell.h"
  17. #include "kspread_doc.h"
  18. #include "kspread_global.h"
  19. #include "kspread_locale.h"
  20. #include "kspread_map.h"
  21. #include "kspread_sheet.h"
  22. #include "kspread_sheetprint.h"
  23. #include "kspread_style.h"
  24. #include "kspread_style_manager.h"
  25. #include "kspread_util.h"
  26. #include "kspread_undo.h"
  27. using namespace KSpread;
  28. bool operator < (const TQPoint& pointA , const TQPoint& pointB)
  29. {
  30. if (pointA.y() == pointB.y())
  31. return ( pointA.x() < pointB.x() );
  32. else
  33. return ( pointA.y() < pointB.y() );
  34. }
  35. /****************************************************************************
  36. *
  37. * Undo
  38. *
  39. ***************************************************************************/
  40. Undo::Undo( Doc *_doc )
  41. {
  42. m_pDoc = _doc;
  43. m_stckUndo.setAutoDelete( false );
  44. m_stckRedo.setAutoDelete( false );
  45. }
  46. Undo::~Undo()
  47. {
  48. clear();
  49. }
  50. void Undo::appendUndo( UndoAction *_action )
  51. {
  52. if ( isLocked() )
  53. return;
  54. m_stckRedo.setAutoDelete( true );
  55. m_stckRedo.clear();
  56. m_stckRedo.setAutoDelete( false );
  57. m_stckUndo.push( _action );
  58. if ( m_pDoc )
  59. {
  60. m_pDoc->enableUndo( hasUndoActions() );
  61. m_pDoc->enableRedo( hasRedoActions() );
  62. m_pDoc->setModified( true );
  63. }
  64. }
  65. void Undo::clear()
  66. {
  67. if ( isLocked() )
  68. return;
  69. m_stckUndo.setAutoDelete( true );
  70. m_stckRedo.setAutoDelete( true );
  71. m_stckUndo.clear();
  72. m_stckRedo.clear();
  73. m_stckUndo.setAutoDelete( false );
  74. m_stckRedo.setAutoDelete( false );
  75. }
  76. void Undo::undo()
  77. {
  78. if ( m_stckUndo.isEmpty() )
  79. return;
  80. //Don't show error dialogs on undo
  81. bool origErrorMessages = true;
  82. if ( m_pDoc )
  83. {
  84. origErrorMessages = m_pDoc->getShowMessageError();
  85. m_pDoc->setShowMessageError( false );
  86. }
  87. UndoAction *a = m_stckUndo.pop();
  88. a->undo();
  89. m_stckRedo.push( a );
  90. if ( m_pDoc )
  91. {
  92. m_pDoc->setShowMessageError( origErrorMessages );
  93. m_pDoc->enableUndo( hasUndoActions() );
  94. m_pDoc->enableRedo( hasRedoActions() );
  95. }
  96. }
  97. void Undo::redo()
  98. {
  99. if ( m_stckRedo.isEmpty() )
  100. return;
  101. UndoAction *a = m_stckRedo.pop();
  102. a->redo();
  103. m_stckUndo.push( a );
  104. if ( m_pDoc )
  105. {
  106. m_pDoc->enableUndo( hasUndoActions() );
  107. m_pDoc->enableRedo( hasRedoActions() );
  108. }
  109. }
  110. void Undo::lock()
  111. {
  112. m_pDoc->undoLock();
  113. }
  114. void Undo::unlock()
  115. {
  116. m_pDoc->undoUnlock();
  117. }
  118. bool Undo::isLocked() const
  119. {
  120. return m_pDoc->undoLocked();
  121. }
  122. TQString Undo::getRedoName()
  123. {
  124. if ( m_stckRedo.isEmpty() )
  125. return TQString("");
  126. return m_stckRedo.current()->getName();
  127. }
  128. TQString Undo::getUndoName()
  129. {
  130. if ( m_stckUndo.isEmpty() )
  131. return TQString("");
  132. return m_stckUndo.current()->getName();
  133. }
  134. /****************************************************************************
  135. *
  136. * MacroUndoAction
  137. *
  138. ***************************************************************************/
  139. MacroUndoAction::MacroUndoAction( Doc *_doc, const TQString& _name ):
  140. UndoAction( _doc )
  141. {
  142. name=_name;
  143. }
  144. MacroUndoAction::~MacroUndoAction()
  145. {
  146. m_commands.setAutoDelete( true );
  147. }
  148. void MacroUndoAction::addCommand(UndoAction *command)
  149. {
  150. m_commands.append(command);
  151. }
  152. void MacroUndoAction::undo()
  153. {
  154. TQPtrListIterator<UndoAction> it(m_commands);
  155. for ( ; it.current() ; ++it )
  156. it.current()->undo();
  157. }
  158. void MacroUndoAction::redo()
  159. {
  160. TQPtrListIterator<UndoAction> it(m_commands);
  161. for ( ; it.current() ; ++it )
  162. it.current()->redo();
  163. }
  164. /****************************************************************************
  165. *
  166. * UndoInsertRemoveAction
  167. *
  168. ***************************************************************************/
  169. UndoInsertRemoveAction::UndoInsertRemoveAction( Doc * _doc ) :
  170. UndoAction( _doc )
  171. {
  172. }
  173. UndoInsertRemoveAction::~UndoInsertRemoveAction()
  174. {
  175. }
  176. void UndoInsertRemoveAction::saveFormulaReference( Sheet *_sheet,
  177. int col, int row, TQString & formula )
  178. {
  179. if ( _sheet == 0 )
  180. return;
  181. TQString sheetName = _sheet->sheetName();
  182. m_lstFormulaCells.append( FormulaOfCell( sheetName, col, row, formula ) );
  183. }
  184. void UndoInsertRemoveAction::undoFormulaReference()
  185. {
  186. TQValueList<FormulaOfCell>::iterator it;
  187. for ( it = m_lstFormulaCells.begin(); it != m_lstFormulaCells.end(); ++it )
  188. {
  189. Sheet* sheet = doc()->map()->findSheet( (*it).sheetName() );
  190. if ( sheet )
  191. {
  192. Cell * cell = sheet->cellAt( (*it).col(), (*it).row() );
  193. if ( cell && !cell->isDefault() )
  194. {
  195. cell->setCellText( (*it).formula() );
  196. }
  197. }
  198. }
  199. }
  200. /****************************************************************************
  201. *
  202. * UndoRemoveColumn
  203. *
  204. ***************************************************************************/
  205. UndoRemoveColumn::UndoRemoveColumn( Doc *_doc, Sheet *_sheet, int _column,int _nbCol ) :
  206. UndoInsertRemoveAction( _doc )
  207. {
  208. name=i18n("Remove Columns");
  209. m_sheetName = _sheet->sheetName();
  210. m_iColumn= _column;
  211. m_iNbCol = _nbCol;
  212. m_printRange = _sheet->print()->printRange();
  213. m_printRepeatColumns = _sheet->print()->printRepeatColumns();
  214. TQRect selection;
  215. selection.setCoords( _column, 1, _column+m_iNbCol, KS_rowMax );
  216. TQDomDocument doc = _sheet->saveCellRegion( selection );
  217. // Save to buffer
  218. TQString buffer;
  219. TQTextStream str( &buffer, IO_WriteOnly );
  220. str << doc;
  221. // This is a terrible hack to store tqunicode
  222. // data in a TQCString in a way that
  223. // TQCString::length() == TQCString().size().
  224. // This allows us to treat the TQCString like a TQByteArray later on.
  225. m_data = buffer.utf8();
  226. int len = m_data.length();
  227. char tmp = m_data[ len - 1 ];
  228. m_data.resize( len );
  229. *( m_data.data() + len - 1 ) = tmp;
  230. }
  231. UndoRemoveColumn::~UndoRemoveColumn()
  232. {
  233. }
  234. void UndoRemoveColumn::undo()
  235. {
  236. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  237. if ( !sheet )
  238. return;
  239. doc()->undoLock();
  240. sheet->insertColumn( m_iColumn,m_iNbCol);
  241. TQPoint pastePoint( m_iColumn, 1 );
  242. sheet->paste( m_data, TQRect( pastePoint, pastePoint ) );
  243. if(sheet->getAutoCalc()) sheet->recalc();
  244. sheet->print()->setPrintRange( m_printRange );
  245. sheet->print()->setPrintRepeatColumns( m_printRepeatColumns );
  246. doc()->undoUnlock();
  247. undoFormulaReference();
  248. }
  249. void UndoRemoveColumn::redo()
  250. {
  251. doc()->undoLock();
  252. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  253. if ( !sheet )
  254. return;
  255. sheet->removeColumn( m_iColumn,m_iNbCol );
  256. doc()->undoUnlock();
  257. }
  258. /****************************************************************************
  259. *
  260. * UndoInsertColumn
  261. *
  262. ***************************************************************************/
  263. UndoInsertColumn::UndoInsertColumn( Doc *_doc, Sheet *_sheet, int _column, int _nbCol ) :
  264. UndoInsertRemoveAction( _doc )
  265. {
  266. name=i18n("Insert Columns");
  267. m_sheetName = _sheet->sheetName();
  268. m_iColumn= _column;
  269. m_iNbCol=_nbCol;
  270. }
  271. UndoInsertColumn::~UndoInsertColumn()
  272. {
  273. }
  274. void UndoInsertColumn::undo()
  275. {
  276. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  277. if ( !sheet )
  278. return;
  279. doc()->undoLock();
  280. sheet->removeColumn( m_iColumn,m_iNbCol );
  281. doc()->undoUnlock();
  282. undoFormulaReference();
  283. }
  284. void UndoInsertColumn::redo()
  285. {
  286. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  287. if ( !sheet )
  288. return;
  289. doc()->undoLock();
  290. sheet->insertColumn( m_iColumn,m_iNbCol);
  291. doc()->undoUnlock();
  292. }
  293. /****************************************************************************
  294. *
  295. * UndoRemoveRow
  296. *
  297. ***************************************************************************/
  298. UndoRemoveRow::UndoRemoveRow( Doc *_doc, Sheet *_sheet, int _row,int _nbRow) :
  299. UndoInsertRemoveAction( _doc )
  300. {
  301. name=i18n("Remove Rows");
  302. m_sheetName = _sheet->sheetName();
  303. m_iRow = _row;
  304. m_iNbRow= _nbRow;
  305. m_printRange=_sheet->print()->printRange();
  306. m_printRepeatRows = _sheet->print()->printRepeatRows();
  307. TQRect selection;
  308. selection.setCoords( 1, _row, KS_colMax, _row+m_iNbRow );
  309. TQDomDocument doc = _sheet->saveCellRegion( selection );
  310. // Save to buffer
  311. TQString buffer;
  312. TQTextStream str( &buffer, IO_WriteOnly );
  313. str << doc;
  314. // This is a terrible hack to store tqunicode
  315. // data in a TQCString in a way that
  316. // TQCString::length() == TQCString().size().
  317. // This allows us to treat the TQCString like a TQByteArray later on.
  318. m_data = buffer.utf8();
  319. int len = m_data.length();
  320. char tmp = m_data[ len - 1 ];
  321. m_data.resize( len );
  322. *( m_data.data() + len - 1 ) = tmp;
  323. // printf("UNDO {{{%s}}}\n", buffer.latin1() );
  324. // printf("UNDO2 %i bytes, length %i {{{%s}}}\n", m_data.length(), m_data.size(), (const char*)m_data );
  325. // printf("length=%i, size=%i", m_data.length(), m_data.size() );
  326. // printf("Last characters are %i %i %i\n", (int)m_data[ m_data.size() - 3 ],
  327. // (int)m_data[ m_data.size() - 2 ], (int)m_data[ m_data.size() - 1 ] );
  328. }
  329. UndoRemoveRow::~UndoRemoveRow()
  330. {
  331. }
  332. void UndoRemoveRow::undo()
  333. {
  334. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  335. if ( !sheet )
  336. return;
  337. doc()->undoLock();
  338. sheet->insertRow( m_iRow,m_iNbRow );
  339. TQPoint pastePoint( 1, m_iRow );
  340. sheet->paste( m_data, TQRect(pastePoint, pastePoint) );
  341. sheet->print()->setPrintRange( m_printRange );
  342. sheet->print()->setPrintRepeatRows( m_printRepeatRows );
  343. if(sheet->getAutoCalc()) sheet->recalc();
  344. doc()->undoUnlock();
  345. undoFormulaReference();
  346. }
  347. void UndoRemoveRow::redo()
  348. {
  349. doc()->undoLock();
  350. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  351. if ( !sheet )
  352. return;
  353. sheet->removeRow( m_iRow,m_iNbRow );
  354. doc()->undoUnlock();
  355. }
  356. /****************************************************************************
  357. *
  358. * UndoInsertRow
  359. *
  360. ***************************************************************************/
  361. UndoInsertRow::UndoInsertRow( Doc *_doc, Sheet *_sheet, int _row,int _nbRow ) :
  362. UndoInsertRemoveAction( _doc )
  363. {
  364. name=i18n("Insert Rows");
  365. m_sheetName = _sheet->sheetName();
  366. m_iRow = _row;
  367. m_iNbRow=_nbRow;
  368. }
  369. UndoInsertRow::~UndoInsertRow()
  370. {
  371. }
  372. void UndoInsertRow::undo()
  373. {
  374. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  375. if ( !sheet )
  376. return;
  377. doc()->undoLock();
  378. sheet->removeRow( m_iRow,m_iNbRow );
  379. doc()->undoUnlock();
  380. undoFormulaReference();
  381. }
  382. void UndoInsertRow::redo()
  383. {
  384. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  385. if ( !sheet )
  386. return;
  387. doc()->undoLock();
  388. sheet->insertRow( m_iRow,m_iNbRow );
  389. doc()->undoUnlock();
  390. }
  391. /****************************************************************************
  392. *
  393. * UndoHideRow
  394. *
  395. ***************************************************************************/
  396. /*UndoHideRow::UndoHideRow( Doc *_doc, Sheet *_sheet, int _row, int _nbRow , TQValueList<int>_listRow) :
  397. UndoAction( _doc )
  398. {
  399. name=i18n("Hide Rows");
  400. m_sheetName = _sheet->sheetName();
  401. m_iRow= _row;
  402. m_iNbRow=_nbRow;
  403. if(m_iNbRow!=-1)
  404. createList( listRow ,_sheet );
  405. else
  406. listRow=TQValueList<int>(_listRow);
  407. }
  408. UndoHideRow::~UndoHideRow()
  409. {
  410. }
  411. void UndoHideRow::createList( TQValueList<int>&list,Sheet *tab )
  412. {
  413. RowFormat *rl;
  414. for(int i=m_iRow;i<=(m_iRow+m_iNbRow);i++)
  415. {
  416. rl= tab->nonDefaultRowFormat( i );
  417. if(!rl->isHide())
  418. list.append(rl->row());
  419. }
  420. }
  421. void UndoHideRow::undo()
  422. {
  423. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  424. if ( !sheet )
  425. return;
  426. doc()->undoLock();
  427. sheet->showRow( 0,-1,listRow );
  428. doc()->undoUnlock();
  429. }
  430. void UndoHideRow::redo()
  431. {
  432. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  433. if ( !sheet )
  434. return;
  435. doc()->undoLock();
  436. sheet->hideRow(0,-1, listRow );
  437. doc()->undoUnlock();
  438. }*/
  439. /****************************************************************************
  440. *
  441. * UndoHideColumn
  442. *
  443. ***************************************************************************/
  444. /*UndoHideColumn::UndoHideColumn( Doc *_doc, Sheet *_sheet, int _column, int _nbCol, TQValueList<int>_listCol ) :
  445. UndoAction( _doc )
  446. {
  447. name=i18n("Hide Columns");
  448. m_sheetName = _sheet->sheetName();
  449. m_iColumn= _column;
  450. m_iNbCol=_nbCol;
  451. if(m_iNbCol!=-1)
  452. createList( listCol ,_sheet );
  453. else
  454. listCol=TQValueList<int>(_listCol);
  455. }
  456. UndoHideColumn::~UndoHideColumn()
  457. {
  458. }
  459. void UndoHideColumn::createList( TQValueList<int>&list,Sheet *tab )
  460. {
  461. ColumnFormat *cl;
  462. for(int i=m_iColumn;i<=(m_iColumn+m_iNbCol);i++)
  463. {
  464. cl= tab->nonDefaultColumnFormat( i );
  465. if(!cl->isHide())
  466. list.append(cl->column());
  467. }
  468. }
  469. void UndoHideColumn::undo()
  470. {
  471. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  472. if ( !sheet )
  473. return;
  474. doc()->undoLock();
  475. sheet->showColumn(0,-1,listCol);
  476. doc()->undoUnlock();
  477. }
  478. void UndoHideColumn::redo()
  479. {
  480. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  481. if ( !sheet )
  482. return;
  483. doc()->undoLock();
  484. sheet->hideColumn(0,-1,listCol);
  485. doc()->undoUnlock();
  486. }*/
  487. /****************************************************************************
  488. *
  489. * UndoShowRow
  490. *
  491. ***************************************************************************/
  492. /*UndoShowRow::UndoShowRow( Doc *_doc, Sheet *_sheet, int _row, int _nbRow, TQValueList<int>_listRow ) :
  493. UndoAction( _doc )
  494. {
  495. name=i18n("Show Rows");
  496. m_sheetName = _sheet->sheetName();
  497. m_iRow= _row;
  498. m_iNbRow=_nbRow;
  499. if(m_iNbRow!=-1)
  500. createList( listRow ,_sheet );
  501. else
  502. listRow=TQValueList<int>(_listRow);
  503. }
  504. UndoShowRow::~UndoShowRow()
  505. {
  506. }
  507. void UndoShowRow::createList( TQValueList<int>&list,Sheet *tab )
  508. {
  509. RowFormat *rl;
  510. for(int i=m_iRow;i<=(m_iRow+m_iNbRow);i++)
  511. {
  512. rl= tab->nonDefaultRowFormat( i );
  513. if(rl->isHide())
  514. list.append(rl->row());
  515. }
  516. }
  517. void UndoShowRow::undo()
  518. {
  519. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  520. if ( !sheet )
  521. return;
  522. doc()->undoLock();
  523. sheet->hideRow(0,-1,listRow);
  524. doc()->undoUnlock();
  525. }
  526. void UndoShowRow::redo()
  527. {
  528. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  529. if ( !sheet )
  530. return;
  531. doc()->undoLock();
  532. sheet->showRow(0,-1,listRow);
  533. doc()->undoUnlock();
  534. }*/
  535. /****************************************************************************
  536. *
  537. * UndoShowColumn
  538. *
  539. ***************************************************************************/
  540. /*UndoShowColumn::UndoShowColumn( Doc *_doc, Sheet *_sheet, int _column, int _nbCol,TQValueList<int>_listCol ) :
  541. UndoAction( _doc )
  542. {
  543. name=i18n("Show Columns");
  544. m_sheetName = _sheet->sheetName();
  545. m_iColumn= _column;
  546. m_iNbCol=_nbCol;
  547. if(m_iNbCol!=-1)
  548. createList( listCol ,_sheet );
  549. else
  550. listCol=TQValueList<int>(_listCol);
  551. }
  552. UndoShowColumn::~UndoShowColumn()
  553. {
  554. }
  555. void UndoShowColumn::createList( TQValueList<int>&list,Sheet *tab )
  556. {
  557. ColumnFormat *cl;
  558. for(int i=m_iColumn;i<=(m_iColumn+m_iNbCol);i++)
  559. {
  560. cl= tab->nonDefaultColumnFormat( i );
  561. if(cl->isHide())
  562. list.append(cl->column());
  563. }
  564. }
  565. void UndoShowColumn::undo()
  566. {
  567. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  568. if ( !sheet )
  569. return;
  570. doc()->undoLock();
  571. sheet->hideColumn( 0,-1,listCol );
  572. doc()->undoUnlock();
  573. }
  574. void UndoShowColumn::redo()
  575. {
  576. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  577. if ( !sheet )
  578. return;
  579. doc()->undoLock();
  580. sheet->showColumn(0,-1,listCol);
  581. doc()->undoUnlock();
  582. }*/
  583. /****************************************************************************
  584. *
  585. * UndoPaperLayout
  586. *
  587. ***************************************************************************/
  588. UndoPaperLayout::UndoPaperLayout( Doc *_doc, Sheet *_sheet )
  589. : UndoAction( _doc )
  590. {
  591. name=i18n("Set Page Layout");
  592. m_sheetName = _sheet->sheetName();
  593. m_pl = _sheet->print()->paperLayout();
  594. m_hf = _sheet->print()->headFootLine();
  595. m_unit = doc()->unit();
  596. m_printGrid = _sheet->print()->printGrid();
  597. m_printCommentIndicator = _sheet->print()->printCommentIndicator();
  598. m_printFormulaIndicator = _sheet->print()->printFormulaIndicator();
  599. m_printRange = _sheet->print()->printRange();
  600. m_printRepeatColumns = _sheet->print()->printRepeatColumns();
  601. m_printRepeatRows = _sheet->print()->printRepeatRows();
  602. m_dZoom = _sheet->print()->zoom();
  603. m_iPageLimitX = _sheet->print()->pageLimitX();
  604. m_iPageLimitY = _sheet->print()->pageLimitY();
  605. }
  606. UndoPaperLayout::~UndoPaperLayout()
  607. {
  608. }
  609. void UndoPaperLayout::undo()
  610. {
  611. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  612. if ( !sheet )
  613. return;
  614. SheetPrint* print = sheet->print();
  615. doc()->undoLock();
  616. m_plRedo = print->paperLayout();
  617. print->setPaperLayout( m_pl.ptLeft, m_pl.ptTop,
  618. m_pl.ptRight, m_pl.ptBottom,
  619. m_pl.format, m_pl.orientation );
  620. m_hfRedo = print->headFootLine();
  621. print->setHeadFootLine( m_hf.headLeft, m_hf.headMid, m_hf.headRight,
  622. m_hf.footLeft, m_hf.footMid, m_hf.footRight );
  623. m_unitRedo = doc()->unit();
  624. doc()->setUnit( m_unit );
  625. m_printGridRedo = print->printGrid();
  626. print->setPrintGrid( m_printGrid );
  627. m_printCommentIndicatorRedo = print->printCommentIndicator();
  628. print->setPrintCommentIndicator( m_printCommentIndicator );
  629. m_printFormulaIndicatorRedo = print->printFormulaIndicator();
  630. print->setPrintFormulaIndicator( m_printFormulaIndicator );
  631. m_printRangeRedo = print->printRange();
  632. print->setPrintRange( m_printRange );
  633. m_printRepeatColumnsRedo = print->printRepeatColumns();
  634. print->setPrintRepeatColumns( m_printRepeatColumns );
  635. m_printRepeatRowsRedo = print->printRepeatRows();
  636. print->setPrintRepeatRows( m_printRepeatRows );
  637. m_dZoomRedo = print->zoom();
  638. print->setZoom( m_dZoom );
  639. m_iPageLimitXRedo = print->pageLimitX();
  640. print->setPageLimitX( m_iPageLimitX );
  641. m_iPageLimitYRedo = print->pageLimitY();
  642. print->setPageLimitY( m_iPageLimitY );
  643. doc()->undoUnlock();
  644. }
  645. void UndoPaperLayout::redo()
  646. {
  647. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  648. if ( !sheet )
  649. return;
  650. SheetPrint* print = sheet->print();
  651. doc()->undoLock();
  652. print->setPaperLayout( m_plRedo.ptLeft, m_plRedo.ptTop,
  653. m_plRedo.ptRight, m_plRedo.ptBottom,
  654. m_plRedo.format, m_plRedo.orientation );
  655. print->setHeadFootLine( m_hfRedo.headLeft, m_hfRedo.headMid, m_hfRedo.headRight,
  656. m_hfRedo.footLeft, m_hfRedo.footMid, m_hfRedo.footRight );
  657. doc()->setUnit( m_unitRedo );
  658. print->setPrintGrid( m_printGridRedo );
  659. print->setPrintCommentIndicator( m_printCommentIndicatorRedo );
  660. print->setPrintFormulaIndicator( m_printFormulaIndicatorRedo );
  661. print->setPrintRange( m_printRangeRedo );
  662. print->setPrintRepeatColumns( m_printRepeatColumnsRedo );
  663. print->setPrintRepeatRows( m_printRepeatRowsRedo );
  664. print->setZoom( m_dZoomRedo );
  665. print->setPageLimitX( m_iPageLimitX );
  666. print->setPageLimitY( m_iPageLimitY );
  667. doc()->undoUnlock();
  668. }
  669. /****************************************************************************
  670. *
  671. * UndoSetText
  672. *
  673. ***************************************************************************/
  674. UndoSetText::UndoSetText( Doc *_doc, Sheet *_sheet, const TQString& _text, int _column, int _row,FormatType _formatType ) :
  675. UndoAction( _doc )
  676. {
  677. name=i18n("Change Text");
  678. m_strText = _text;
  679. m_iColumn= _column;
  680. m_iRow = _row;
  681. m_sheetName = _sheet->sheetName();
  682. m_eFormatType=_formatType;
  683. }
  684. UndoSetText::~UndoSetText()
  685. {
  686. }
  687. void UndoSetText::undo()
  688. {
  689. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  690. if ( !sheet )
  691. return;
  692. doc()->undoLock();
  693. doc()->emitBeginOperation();
  694. Cell *cell = sheet->nonDefaultCell( m_iColumn, m_iRow );
  695. m_strRedoText = cell->text();
  696. m_eFormatTypeRedo=cell->format()->getFormatType( m_iColumn, m_iRow );
  697. cell->format()->setFormatType(m_eFormatType);
  698. if ( m_strText.isNull() )
  699. cell->setCellText( "" );
  700. else
  701. cell->setCellText( m_strText );
  702. sheet->updateView( TQRect( m_iColumn, m_iRow, 1, 1 ) );
  703. doc()->undoUnlock();
  704. }
  705. void UndoSetText::redo()
  706. {
  707. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  708. if ( !sheet )
  709. return;
  710. doc()->undoLock();
  711. doc()->emitBeginOperation();
  712. Cell *cell = sheet->nonDefaultCell( m_iColumn, m_iRow );
  713. m_strText = cell->text();
  714. m_eFormatType=cell->format()->getFormatType( m_iColumn, m_iRow );
  715. if ( m_strRedoText.isNull() )
  716. cell->setCellText( "" );
  717. else
  718. cell->setCellText( m_strRedoText );
  719. cell->format()->setFormatType(m_eFormatTypeRedo);
  720. sheet->updateView( TQRect( m_iColumn, m_iRow, 1, 1 ) );
  721. doc()->undoUnlock();
  722. }
  723. /****************************************************************************
  724. *
  725. * UndoCellFormat
  726. *
  727. ***************************************************************************/
  728. UndoCellFormat::UndoCellFormat( Doc * _doc,
  729. Sheet * _sheet,
  730. const Region & _selection,
  731. const TQString & _name ) :
  732. UndoAction( _doc )
  733. {
  734. if ( _name.isEmpty())
  735. name = i18n("Change Format");
  736. else
  737. name = _name;
  738. m_region = _selection;
  739. m_sheetName = _sheet->sheetName();
  740. copyFormat( m_lstFormats, m_lstColFormats, m_lstRowFormats, _sheet );
  741. }
  742. void UndoCellFormat::copyFormat(TQValueList<layoutCell> & list,
  743. TQValueList<layoutColumn> & listCol,
  744. TQValueList<layoutRow> & listRow,
  745. Sheet * sheet )
  746. {
  747. TQValueList<layoutCell>::Iterator it2;
  748. for ( it2 = list.begin(); it2 != list.end(); ++it2 )
  749. {
  750. delete (*it2).l;
  751. }
  752. list.clear();
  753. Cell * cell;
  754. Region::ConstIterator endOfList(m_region.constEnd());
  755. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  756. {
  757. TQRect range = (*it)->rect().normalize();
  758. int bottom = range.bottom();
  759. int right = range.right();
  760. if ( util_isColumnSelected( range ) )
  761. {
  762. /* Don't need to go through the loop twice...
  763. for (int i = range.left(); i <= right; ++i)
  764. {
  765. layoutColumn tmptqlayout;
  766. tmptqlayout.col = i;
  767. tmptqlayout.l = new ColumnFormat( sheet, i );
  768. tmptqlayout.l->copy( *(sheet->columnFormat( i )) );
  769. listCol.append(tmptqlayout);
  770. }
  771. */
  772. for ( int c = range.left(); c <= right; ++c )
  773. {
  774. layoutColumn tmptqlayout;
  775. tmptqlayout.col = c;
  776. tmptqlayout.l = new ColumnFormat( sheet, c );
  777. tmptqlayout.l->copy( *(sheet->columnFormat( c )) );
  778. listCol.append(tmptqlayout);
  779. cell = sheet->getFirstCellColumn( c );
  780. while ( cell )
  781. {
  782. if ( cell->isPartOfMerged() )
  783. {
  784. cell = sheet->getNextCellDown( c, cell->row() );
  785. continue;
  786. }
  787. layoutCell tmptqlayout;
  788. tmptqlayout.col = c;
  789. tmptqlayout.row = cell->row();
  790. tmptqlayout.l = new Format( sheet, 0 );
  791. tmptqlayout.l->copy( *(sheet->cellAt( tmptqlayout.col, tmptqlayout.row )->format()) );
  792. list.append(tmptqlayout);
  793. cell = sheet->getNextCellDown( c, cell->row() );
  794. }
  795. }
  796. /*
  797. Cell * c = sheet->firstCell();
  798. for( ; c; c = c->nextCell() )
  799. {
  800. int col = c->column();
  801. if ( range.left() <= col && right >= col
  802. && !c->isPartOfMerged())
  803. {
  804. layoutCell tmptqlayout;
  805. tmptqlayout.col = c->column();
  806. tmptqlayout.row = c->row();
  807. tmptqlayout.l = new Format( sheet, 0 );
  808. tmptqlayout.l->copy( *(sheet->cellAt( tmptqlayout.col, tmptqlayout.row )) );
  809. list.append(tmptqlayout);
  810. }
  811. }
  812. */
  813. }
  814. else if (util_isRowSelected( range ) )
  815. {
  816. for ( int row = range.top(); row <= bottom; ++row )
  817. {
  818. layoutRow tmptqlayout;
  819. tmptqlayout.row = row;
  820. tmptqlayout.l = new RowFormat( sheet, row );
  821. tmptqlayout.l->copy( *(sheet->rowFormat( row )) );
  822. listRow.append(tmptqlayout);
  823. cell = sheet->getFirstCellRow( row );
  824. while ( cell )
  825. {
  826. if ( cell->isPartOfMerged() )
  827. {
  828. cell = sheet->getNextCellRight( cell->column(), row );
  829. continue;
  830. }
  831. layoutCell tmptqlayout;
  832. tmptqlayout.col = cell->column();
  833. tmptqlayout.row = row;
  834. tmptqlayout.l = new Format( sheet, 0 );
  835. tmptqlayout.l->copy( *(sheet->cellAt( cell->column(), row )->format()) );
  836. list.append(tmptqlayout);
  837. cell = sheet->getNextCellRight( cell->column(), row );
  838. }
  839. }
  840. /*
  841. Cell * c = sheet->firstCell();
  842. for( ; c; c = c->nextCell() )
  843. {
  844. int row = c->row();
  845. if ( range.top() <= row && bottom >= row
  846. && !c->isPartOfMerged())
  847. {
  848. layoutCell tmptqlayout;
  849. tmptqlayout.col = c->column();
  850. tmptqlayout.row = c->row();
  851. tmptqlayout.l = new Format( sheet, 0 );
  852. tmptqlayout.l->copy( *(sheet->cellAt( tmptqlayout.col, tmptqlayout.row )) );
  853. list.append(tmptqlayout);
  854. }
  855. }
  856. */
  857. }
  858. else
  859. {
  860. for ( int y = range.top(); y <= bottom; ++y )
  861. for ( int x = range.left(); x <= right; ++x )
  862. {
  863. Cell * cell = sheet->nonDefaultCell( x, y );
  864. if ( !cell->isPartOfMerged() )
  865. {
  866. layoutCell tmptqlayout;
  867. tmptqlayout.col = x;
  868. tmptqlayout.row = y;
  869. tmptqlayout.l = new Format( sheet, 0 );
  870. tmptqlayout.l->copy( *(sheet->cellAt( x, y )->format()) );
  871. list.append(tmptqlayout);
  872. }
  873. }
  874. }
  875. }
  876. }
  877. UndoCellFormat::~UndoCellFormat()
  878. {
  879. TQValueList<layoutCell>::Iterator it2;
  880. for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
  881. {
  882. delete (*it2).l;
  883. }
  884. m_lstFormats.clear();
  885. for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
  886. {
  887. delete (*it2).l;
  888. }
  889. m_lstRedoFormats.clear();
  890. TQValueList<layoutColumn>::Iterator it3;
  891. for ( it3 = m_lstColFormats.begin(); it3 != m_lstColFormats.end(); ++it3 )
  892. {
  893. delete (*it3).l;
  894. }
  895. m_lstColFormats.clear();
  896. for ( it3 = m_lstRedoColFormats.begin(); it3 != m_lstRedoColFormats.end(); ++it3 )
  897. {
  898. delete (*it3).l;
  899. }
  900. m_lstRedoColFormats.clear();
  901. TQValueList<layoutRow>::Iterator it4;
  902. for ( it4 = m_lstRowFormats.begin(); it4 != m_lstRowFormats.end(); ++it4 )
  903. {
  904. delete (*it4).l;
  905. }
  906. m_lstRowFormats.clear();
  907. for ( it4 = m_lstRedoRowFormats.begin(); it4 != m_lstRedoRowFormats.end(); ++it4 )
  908. {
  909. delete (*it4).l;
  910. }
  911. m_lstRedoRowFormats.clear();
  912. }
  913. void UndoCellFormat::undo()
  914. {
  915. Sheet * sheet = doc()->map()->findSheet( m_sheetName );
  916. if ( !sheet )
  917. return;
  918. doc()->undoLock();
  919. doc()->emitBeginOperation();
  920. copyFormat( m_lstRedoFormats, m_lstRedoColFormats, m_lstRedoRowFormats, sheet );
  921. Region::ConstIterator endOfList(m_region.constEnd());
  922. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  923. {
  924. TQRect range = (*it)->rect().normalize();
  925. if( util_isColumnSelected( range ) )
  926. {
  927. TQValueList<layoutColumn>::Iterator it2;
  928. for ( it2 = m_lstColFormats.begin(); it2 != m_lstColFormats.end(); ++it2 )
  929. {
  930. ColumnFormat * col = sheet->nonDefaultColumnFormat( (*it2).col );
  931. col->copy( *(*it2).l );
  932. }
  933. }
  934. else if( util_isRowSelected( range ) )
  935. {
  936. TQValueList<layoutRow>::Iterator it2;
  937. for ( it2 = m_lstRowFormats.begin(); it2 != m_lstRowFormats.end(); ++it2 )
  938. {
  939. RowFormat * row = sheet->nonDefaultRowFormat( (*it2).row );
  940. row->copy( *(*it2).l );
  941. }
  942. }
  943. TQValueList<layoutCell>::Iterator it2;
  944. for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
  945. {
  946. Cell *cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
  947. cell->format()->copy( *(*it2).l );
  948. cell->setLayoutDirtyFlag();
  949. cell->setDisplayDirtyFlag();
  950. sheet->updateCell( cell, (*it2).col, (*it2).row );
  951. }
  952. }
  953. sheet->setRegionPaintDirty( m_region );
  954. sheet->updateView( &m_region );
  955. doc()->undoUnlock();
  956. }
  957. void UndoCellFormat::redo()
  958. {
  959. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  960. if ( !sheet )
  961. return;
  962. doc()->undoLock();
  963. doc()->emitBeginOperation();
  964. Region::ConstIterator endOfList(m_region.constEnd());
  965. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  966. {
  967. TQRect range = (*it)->rect().normalize();
  968. if ( util_isColumnSelected( range ) )
  969. {
  970. TQValueList<layoutColumn>::Iterator it2;
  971. for ( it2 = m_lstRedoColFormats.begin(); it2 != m_lstRedoColFormats.end(); ++it2 )
  972. {
  973. ColumnFormat * col = sheet->nonDefaultColumnFormat( (*it2).col );
  974. col->copy( *(*it2).l );
  975. }
  976. }
  977. else if( util_isRowSelected( range ) )
  978. {
  979. TQValueList<layoutRow>::Iterator it2;
  980. for ( it2 = m_lstRedoRowFormats.begin(); it2 != m_lstRedoRowFormats.end(); ++it2 )
  981. {
  982. RowFormat * row = sheet->nonDefaultRowFormat( (*it2).row );
  983. row->copy( *(*it2).l );
  984. }
  985. }
  986. TQValueList<layoutCell>::Iterator it2;
  987. for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
  988. {
  989. Cell * cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
  990. cell->format()->copy( *(*it2).l );
  991. cell->setLayoutDirtyFlag();
  992. cell->setDisplayDirtyFlag();
  993. sheet->updateCell( cell, (*it2).col, (*it2).row );
  994. }
  995. }
  996. sheet->setRegionPaintDirty( m_region );
  997. sheet->updateView( &m_region );
  998. doc()->undoUnlock();
  999. }
  1000. /****************************************************************************
  1001. *
  1002. * UndoChangeAngle
  1003. *
  1004. ***************************************************************************/
  1005. UndoChangeAngle::UndoChangeAngle( Doc * _doc,
  1006. Sheet * _sheet,
  1007. const Region & _selection ) :
  1008. UndoAction( _doc )
  1009. {
  1010. name = i18n("Change Angle");
  1011. m_layoutUndo = new UndoCellFormat( _doc, _sheet, _selection, TQString() );
  1012. m_resizeUndo = new UndoResizeColRow( _doc, _sheet, _selection );
  1013. }
  1014. UndoChangeAngle::~UndoChangeAngle()
  1015. {
  1016. delete m_resizeUndo;
  1017. delete m_layoutUndo;
  1018. }
  1019. void UndoChangeAngle::undo()
  1020. {
  1021. m_layoutUndo->undo();
  1022. m_resizeUndo->undo();
  1023. }
  1024. void UndoChangeAngle::redo()
  1025. {
  1026. m_layoutUndo->redo();
  1027. m_resizeUndo->redo();
  1028. }
  1029. /****************************************************************************
  1030. *
  1031. * UndoSort
  1032. *
  1033. ***************************************************************************/
  1034. UndoSort::UndoSort( Doc * _doc, Sheet * _sheet, const TQRect & _selection ) :
  1035. UndoAction( _doc )
  1036. {
  1037. name = i18n("Sort");
  1038. m_rctRect = _selection;
  1039. m_sheetName = _sheet->sheetName();
  1040. copyAll( m_lstFormats, m_lstColFormats, m_lstRowFormats, _sheet );
  1041. }
  1042. void UndoSort::copyAll(TQValueList<layoutTextCell> & list, TQValueList<layoutColumn> & listCol,
  1043. TQValueList<layoutRow> & listRow, Sheet * sheet )
  1044. {
  1045. TQValueList<layoutTextCell>::Iterator it2;
  1046. for ( it2 = list.begin(); it2 != list.end(); ++it2 )
  1047. {
  1048. delete (*it2).l;
  1049. }
  1050. list.clear();
  1051. if ( util_isColumnSelected( m_rctRect ) )
  1052. {
  1053. Cell * c;
  1054. for (int col = m_rctRect.left(); col <= m_rctRect.right(); ++col)
  1055. {
  1056. layoutColumn tmptqlayout;
  1057. tmptqlayout.col = col;
  1058. tmptqlayout.l = new ColumnFormat( sheet, col );
  1059. tmptqlayout.l->copy( *(sheet->columnFormat( col )) );
  1060. listCol.append(tmptqlayout);
  1061. c = sheet->getFirstCellColumn( col );
  1062. while ( c )
  1063. {
  1064. if ( !c->isPartOfMerged() )
  1065. {
  1066. layoutTextCell tmptqlayout;
  1067. tmptqlayout.col = col;
  1068. tmptqlayout.row = c->row();
  1069. tmptqlayout.l = new Format( sheet, 0 );
  1070. tmptqlayout.l->copy( *(sheet->cellAt( tmptqlayout.col, tmptqlayout.row )->format()) );
  1071. tmptqlayout.text = c->text();
  1072. list.append(tmptqlayout);
  1073. }
  1074. c = sheet->getNextCellDown( col, c->row() );
  1075. }
  1076. }
  1077. }
  1078. else if ( util_isRowSelected( m_rctRect ) )
  1079. {
  1080. Cell * c;
  1081. for ( int row = m_rctRect.top(); row <= m_rctRect.bottom(); ++row)
  1082. {
  1083. layoutRow tmptqlayout;
  1084. tmptqlayout.row = row;
  1085. tmptqlayout.l = new RowFormat( sheet, row );
  1086. tmptqlayout.l->copy( *(sheet->rowFormat( row )) );
  1087. listRow.append(tmptqlayout);
  1088. c = sheet->getFirstCellRow( row );
  1089. while ( c )
  1090. {
  1091. if ( !c->isPartOfMerged() )
  1092. {
  1093. layoutTextCell tmptqlayout;
  1094. tmptqlayout.col = c->column();
  1095. tmptqlayout.row = row;
  1096. tmptqlayout.l = new Format( sheet, 0 );
  1097. tmptqlayout.l->copy( *(sheet->cellAt( tmptqlayout.col, tmptqlayout.row )->format()) );
  1098. tmptqlayout.text = c->text();
  1099. list.append(tmptqlayout);
  1100. }
  1101. c = sheet->getNextCellRight( c->column(), row );
  1102. }
  1103. }
  1104. }
  1105. else
  1106. {
  1107. int bottom = m_rctRect.bottom();
  1108. int right = m_rctRect.right();
  1109. Cell * cell;
  1110. for ( int y = m_rctRect.top(); y <= bottom; ++y )
  1111. for ( int x = m_rctRect.left(); x <= right; ++x )
  1112. {
  1113. cell = sheet->nonDefaultCell( x, y );
  1114. if (!cell->isPartOfMerged())
  1115. {
  1116. layoutTextCell tmptqlayout;
  1117. tmptqlayout.col = x;
  1118. tmptqlayout.row = y;
  1119. tmptqlayout.l = new Format( sheet, 0 );
  1120. tmptqlayout.l->copy( *(sheet->cellAt( x, y )->format()) );
  1121. tmptqlayout.text = cell->text();
  1122. list.append(tmptqlayout);
  1123. }
  1124. }
  1125. }
  1126. }
  1127. UndoSort::~UndoSort()
  1128. {
  1129. TQValueList<layoutTextCell>::Iterator it2;
  1130. for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
  1131. {
  1132. delete (*it2).l;
  1133. }
  1134. m_lstFormats.clear();
  1135. for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
  1136. {
  1137. delete (*it2).l;
  1138. }
  1139. m_lstRedoFormats.clear();
  1140. TQValueList<layoutColumn>::Iterator it3;
  1141. for ( it3 = m_lstColFormats.begin(); it3 != m_lstColFormats.end(); ++it3 )
  1142. {
  1143. delete (*it3).l;
  1144. }
  1145. m_lstColFormats.clear();
  1146. for ( it3 = m_lstRedoColFormats.begin(); it3 != m_lstRedoColFormats.end(); ++it3 )
  1147. {
  1148. delete (*it3).l;
  1149. }
  1150. m_lstRedoColFormats.clear();
  1151. TQValueList<layoutRow>::Iterator it4;
  1152. for ( it4 = m_lstRowFormats.begin(); it4 != m_lstRowFormats.end(); ++it4 )
  1153. {
  1154. delete (*it4).l;
  1155. }
  1156. m_lstRowFormats.clear();
  1157. for ( it4 = m_lstRedoRowFormats.begin(); it4 != m_lstRedoRowFormats.end(); ++it4 )
  1158. {
  1159. delete (*it4).l;
  1160. }
  1161. m_lstRedoRowFormats.clear();
  1162. }
  1163. void UndoSort::undo()
  1164. {
  1165. Sheet * sheet = doc()->map()->findSheet( m_sheetName );
  1166. if ( !sheet )
  1167. return;
  1168. doc()->undoLock();
  1169. doc()->emitBeginOperation();
  1170. copyAll( m_lstRedoFormats, m_lstRedoColFormats,
  1171. m_lstRedoRowFormats, sheet );
  1172. if ( util_isColumnSelected( m_rctRect ) )
  1173. {
  1174. TQValueList<layoutColumn>::Iterator it2;
  1175. for ( it2 = m_lstColFormats.begin(); it2 != m_lstColFormats.end(); ++it2 )
  1176. {
  1177. ColumnFormat * col = sheet->nonDefaultColumnFormat( (*it2).col );
  1178. col->copy( *(*it2).l );
  1179. }
  1180. }
  1181. else if( util_isRowSelected( m_rctRect ) )
  1182. {
  1183. TQValueList<layoutRow>::Iterator it2;
  1184. for ( it2 = m_lstRowFormats.begin(); it2 != m_lstRowFormats.end(); ++it2 )
  1185. {
  1186. RowFormat *row= sheet->nonDefaultRowFormat( (*it2).row );
  1187. row->copy( *(*it2).l );
  1188. }
  1189. }
  1190. TQValueList<layoutTextCell>::Iterator it2;
  1191. for ( it2 = m_lstFormats.begin(); it2 != m_lstFormats.end(); ++it2 )
  1192. {
  1193. Cell *cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
  1194. if ( (*it2).text.isEmpty() )
  1195. {
  1196. if(!cell->text().isEmpty())
  1197. cell->setCellText( "" );
  1198. }
  1199. else
  1200. cell->setCellText( (*it2).text );
  1201. cell->format()->copy( *(*it2).l );
  1202. cell->setLayoutDirtyFlag();
  1203. cell->setDisplayDirtyFlag();
  1204. sheet->updateCell( cell, (*it2).col, (*it2).row );
  1205. }
  1206. sheet->setRegionPaintDirty(m_rctRect);
  1207. sheet->updateView( m_rctRect );
  1208. doc()->undoUnlock();
  1209. }
  1210. void UndoSort::redo()
  1211. {
  1212. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1213. if ( !sheet )
  1214. return;
  1215. doc()->undoLock();
  1216. doc()->emitBeginOperation();
  1217. if( util_isColumnSelected( m_rctRect ) )
  1218. {
  1219. TQValueList<layoutColumn>::Iterator it2;
  1220. for ( it2 = m_lstRedoColFormats.begin(); it2 != m_lstRedoColFormats.end(); ++it2 )
  1221. {
  1222. ColumnFormat *col= sheet->nonDefaultColumnFormat( (*it2).col );
  1223. col->copy( *(*it2).l );
  1224. }
  1225. }
  1226. else if( util_isRowSelected( m_rctRect ) )
  1227. {
  1228. TQValueList<layoutRow>::Iterator it2;
  1229. for ( it2 = m_lstRedoRowFormats.begin(); it2 != m_lstRedoRowFormats.end(); ++it2 )
  1230. {
  1231. RowFormat *row= sheet->nonDefaultRowFormat( (*it2).row );
  1232. row->copy( *(*it2).l );
  1233. }
  1234. }
  1235. TQValueList<layoutTextCell>::Iterator it2;
  1236. for ( it2 = m_lstRedoFormats.begin(); it2 != m_lstRedoFormats.end(); ++it2 )
  1237. {
  1238. Cell *cell = sheet->nonDefaultCell( (*it2).col,(*it2).row );
  1239. if ( (*it2).text.isEmpty() )
  1240. {
  1241. if(!cell->text().isEmpty())
  1242. cell->setCellText( "" );
  1243. }
  1244. else
  1245. cell->setCellText( (*it2).text );
  1246. cell->format()->copy( *(*it2).l );
  1247. cell->setLayoutDirtyFlag();
  1248. cell->setDisplayDirtyFlag();
  1249. sheet->updateCell( cell, (*it2).col, (*it2).row );
  1250. }
  1251. sheet->setRegionPaintDirty(m_rctRect);
  1252. sheet->updateView( m_rctRect );
  1253. doc()->undoUnlock();
  1254. }
  1255. /****************************************************************************
  1256. *
  1257. * UndoDelete
  1258. *
  1259. ***************************************************************************/
  1260. UndoDelete::UndoDelete( Doc *_doc, Sheet* sheet, const Region& region)
  1261. : UndoAction( _doc )
  1262. {
  1263. name=i18n("Delete");
  1264. m_sheetName = sheet->sheetName();
  1265. m_region = region;
  1266. createListCell(m_data, m_lstColumn, m_lstRow, sheet);
  1267. }
  1268. UndoDelete::~UndoDelete()
  1269. {
  1270. }
  1271. void UndoDelete::createListCell( TQCString &listCell,TQValueList<columnSize> &listCol,TQValueList<rowSize> &listRow, Sheet* sheet )
  1272. {
  1273. listRow.clear();
  1274. listCol.clear();
  1275. Region::ConstIterator endOfList = m_region.constEnd();
  1276. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  1277. {
  1278. TQRect range = (*it)->rect().normalize();
  1279. // copy column(s)
  1280. if ((*it)->isColumn())
  1281. {
  1282. for( int y = range.left() ; y <= range.right() ; ++y )
  1283. {
  1284. ColumnFormat * cl = sheet->columnFormat( y );
  1285. if ( !cl->isDefault() )
  1286. {
  1287. columnSize tmpSize;
  1288. tmpSize.columnNumber=y;
  1289. tmpSize.columnWidth=cl->dblWidth();
  1290. listCol.append(tmpSize);
  1291. }
  1292. }
  1293. }
  1294. // copy row(s)
  1295. else if ((*it)->isRow())
  1296. {
  1297. //save size of row(s)
  1298. for( int y = range.top() ; y <= range.bottom() ; ++y )
  1299. {
  1300. RowFormat *rw=sheet->rowFormat(y);
  1301. if(!rw->isDefault())
  1302. {
  1303. rowSize tmpSize;
  1304. tmpSize.rowNumber=y;
  1305. tmpSize.rowHeight=rw->dblHeight();
  1306. listRow.append(tmpSize);
  1307. }
  1308. }
  1309. }
  1310. }
  1311. //save all cells in area
  1312. TQDomDocument doc = sheet->saveCellRegion( m_region );
  1313. // Save to buffer
  1314. TQString buffer;
  1315. TQTextStream str( &buffer, IO_WriteOnly );
  1316. str << doc;
  1317. // This is a terrible hack to store tqunicode
  1318. // data in a TQCString in a way that
  1319. // TQCString::length() == TQCString().size().
  1320. // This allows us to treat the TQCString like a TQByteArray later on.
  1321. listCell = buffer.utf8();
  1322. int len = listCell.length();
  1323. char tmp = listCell[ len - 1 ];
  1324. listCell.resize( len );
  1325. *( listCell.data() + len - 1 ) = tmp;
  1326. }
  1327. void UndoDelete::undo()
  1328. {
  1329. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1330. if ( !sheet )
  1331. return;
  1332. createListCell( m_dataRedo, m_lstRedoColumn, m_lstRedoRow, sheet );
  1333. doc()->undoLock();
  1334. doc()->emitBeginOperation();
  1335. {
  1336. TQValueList<columnSize>::Iterator it2;
  1337. for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
  1338. {
  1339. ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
  1340. cl->setDblWidth((*it2).columnWidth);
  1341. }
  1342. }
  1343. {
  1344. TQValueList<rowSize>::Iterator it2;
  1345. for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 )
  1346. {
  1347. RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
  1348. rw->setDblHeight((*it2).rowHeight);
  1349. }
  1350. }
  1351. sheet->deleteCells(m_region);
  1352. sheet->paste( m_data, m_region.boundingRect() );
  1353. sheet->updateView( );
  1354. if(sheet->getAutoCalc()) sheet->recalc();
  1355. doc()->undoUnlock();
  1356. }
  1357. void UndoDelete::redo()
  1358. {
  1359. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1360. if ( !sheet )
  1361. return;
  1362. doc()->undoLock();
  1363. doc()->emitBeginOperation();
  1364. {
  1365. TQValueList<columnSize>::Iterator it2;
  1366. for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
  1367. {
  1368. ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
  1369. cl->setDblWidth((*it2).columnWidth);
  1370. }
  1371. }
  1372. {
  1373. TQValueList<rowSize>::Iterator it2;
  1374. for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 )
  1375. {
  1376. RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
  1377. rw->setDblHeight((*it2).rowHeight);
  1378. }
  1379. }
  1380. //move next line to refreshView
  1381. //because I must know what is the real rect
  1382. //that I must refresh, when there is cell Merged
  1383. sheet->paste( m_dataRedo, m_region.boundingRect() );
  1384. //sheet->deleteCells( m_selection );
  1385. sheet->updateView();
  1386. sheet->refreshView( m_region ); // deletes the cells in region!
  1387. doc()->undoUnlock();
  1388. }
  1389. /****************************************************************************
  1390. *
  1391. * UndoDragDrop
  1392. *
  1393. ***************************************************************************/
  1394. UndoDragDrop::UndoDragDrop( Doc * _doc, Sheet * _sheet,
  1395. const Region& _source,
  1396. const Region& _target )
  1397. : UndoAction( _doc ),
  1398. m_selectionSource( _source ),
  1399. m_selectionTarget( _target )
  1400. {
  1401. name = i18n( "Drag & Drop" );
  1402. m_sheetName = _sheet->sheetName();
  1403. saveCellRect( m_dataTarget, _sheet, _target );
  1404. saveCellRect( m_dataSource, _sheet, _source );
  1405. }
  1406. UndoDragDrop::~UndoDragDrop()
  1407. {
  1408. }
  1409. void UndoDragDrop::saveCellRect( TQCString & cells, Sheet * sheet,
  1410. const Region& region )
  1411. {
  1412. TQDomDocument doc = sheet->saveCellRegion(region);
  1413. // Save to buffer
  1414. TQString buffer;
  1415. TQTextStream str( &buffer, IO_WriteOnly );
  1416. str << doc;
  1417. cells = buffer.utf8();
  1418. int len = cells.length();
  1419. char tmp = cells[ len - 1 ];
  1420. cells.resize( len );
  1421. *( cells.data() + len - 1 ) = tmp;
  1422. }
  1423. void UndoDragDrop::undo()
  1424. {
  1425. Sheet * sheet = doc()->map()->findSheet( m_sheetName );
  1426. if ( !sheet )
  1427. return;
  1428. saveCellRect( m_dataRedoSource, sheet, m_selectionSource );
  1429. saveCellRect( m_dataRedoTarget, sheet, m_selectionTarget );
  1430. doc()->undoLock();
  1431. doc()->emitBeginOperation();
  1432. sheet->deleteCells( m_selectionTarget );
  1433. sheet->paste( m_dataTarget, m_selectionTarget.boundingRect() );
  1434. sheet->deleteCells( m_selectionSource );
  1435. sheet->paste( m_dataSource, m_selectionSource.boundingRect() );
  1436. sheet->updateView();
  1437. if ( sheet->getAutoCalc() )
  1438. sheet->recalc();
  1439. doc()->undoUnlock();
  1440. }
  1441. void UndoDragDrop::redo()
  1442. {
  1443. Sheet * sheet = doc()->map()->findSheet( m_sheetName );
  1444. if ( !sheet )
  1445. return;
  1446. doc()->undoLock();
  1447. doc()->emitBeginOperation();
  1448. //move next line to refreshView
  1449. //because I must know what is the real rect
  1450. //that I must refresh, when there is cell Merged
  1451. sheet->deleteCells( m_selectionTarget );
  1452. sheet->paste( m_dataRedoTarget, m_selectionTarget.boundingRect() );
  1453. sheet->deleteCells( m_selectionSource );
  1454. sheet->paste( m_dataRedoSource, m_selectionSource.boundingRect() );
  1455. sheet->updateView();
  1456. if ( sheet->getAutoCalc() )
  1457. sheet->recalc();
  1458. doc()->undoUnlock();
  1459. }
  1460. /****************************************************************************
  1461. *
  1462. * UndoResizeColRow
  1463. *
  1464. ***************************************************************************/
  1465. UndoResizeColRow::UndoResizeColRow( Doc *_doc, Sheet *_sheet, const Region &_selection ) :
  1466. UndoAction( _doc )
  1467. {
  1468. name=i18n("Resize");
  1469. m_region = _selection;
  1470. m_sheetName = _sheet->sheetName();
  1471. createList( m_lstColumn,m_lstRow, _sheet );
  1472. }
  1473. void UndoResizeColRow::createList( TQValueList<columnSize> &listCol,TQValueList<rowSize> &listRow, Sheet* sheet )
  1474. {
  1475. listCol.clear();
  1476. listRow.clear();
  1477. Region::ConstIterator endOfList(m_region.constEnd());
  1478. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  1479. {
  1480. TQRect m_rctRect = (*it)->rect().normalize();
  1481. if( util_isColumnSelected( m_rctRect ) ) // entire column(s)
  1482. {
  1483. for( int y = m_rctRect.left(); y <= m_rctRect.right(); y++ )
  1484. {
  1485. ColumnFormat *cl=sheet->columnFormat(y);
  1486. if(!cl->isHide())
  1487. {
  1488. columnSize tmpSize;
  1489. tmpSize.columnNumber=y;
  1490. tmpSize.columnWidth=cl->dblWidth();
  1491. listCol.append(tmpSize);
  1492. }
  1493. }
  1494. }
  1495. else if( util_isRowSelected( m_rctRect ) ) // entire row(s)
  1496. {
  1497. for( int y = m_rctRect.top(); y <= m_rctRect.bottom(); y++ )
  1498. {
  1499. RowFormat *rw=sheet->rowFormat(y);
  1500. if(!rw->isHide())
  1501. {
  1502. rowSize tmpSize;
  1503. tmpSize.rowNumber=y;
  1504. tmpSize.rowHeight=rw->dblHeight();
  1505. listRow.append(tmpSize);
  1506. }
  1507. }
  1508. }
  1509. else //row and column
  1510. {
  1511. for( int y = m_rctRect.left(); y <= m_rctRect.right(); y++ )
  1512. {
  1513. ColumnFormat *cl=sheet->columnFormat(y);
  1514. if(!cl->isHide())
  1515. {
  1516. columnSize tmpSize;
  1517. tmpSize.columnNumber=y;
  1518. tmpSize.columnWidth=cl->dblWidth();
  1519. listCol.append(tmpSize);
  1520. }
  1521. }
  1522. for( int y = m_rctRect.top(); y <= m_rctRect.bottom(); y++ )
  1523. {
  1524. RowFormat *rw=sheet->rowFormat(y);
  1525. if(!rw->isHide())
  1526. {
  1527. rowSize tmpSize;
  1528. tmpSize.rowNumber=y;
  1529. tmpSize.rowHeight=rw->dblHeight();
  1530. listRow.append(tmpSize);
  1531. }
  1532. }
  1533. }
  1534. }
  1535. }
  1536. UndoResizeColRow::~UndoResizeColRow()
  1537. {
  1538. }
  1539. void UndoResizeColRow::undo()
  1540. {
  1541. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1542. if ( !sheet )
  1543. return;
  1544. doc()->undoLock();
  1545. createList( m_lstRedoColumn,m_lstRedoRow, sheet );
  1546. Region::ConstIterator endOfList(m_region.constEnd());
  1547. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  1548. {
  1549. TQRect m_rctRect = (*it)->rect().normalize();
  1550. if( util_isColumnSelected( m_rctRect ) ) // complete column(s)
  1551. {
  1552. TQValueList<columnSize>::Iterator it2;
  1553. for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
  1554. {
  1555. ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
  1556. cl->setDblWidth((*it2).columnWidth);
  1557. }
  1558. }
  1559. else if( util_isRowSelected( m_rctRect ) ) // complete row(s)
  1560. {
  1561. TQValueList<rowSize>::Iterator it2;
  1562. for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 )
  1563. {
  1564. RowFormat *rw=sheet->rowFormat((*it2).rowNumber);
  1565. rw->setDblHeight((*it2).rowHeight);
  1566. }
  1567. }
  1568. else // row and column
  1569. {
  1570. TQValueList<columnSize>::Iterator it2;
  1571. for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
  1572. {
  1573. ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
  1574. cl->setDblWidth((*it2).columnWidth);
  1575. }
  1576. TQValueList<rowSize>::Iterator it1;
  1577. for ( it1 = m_lstRow.begin(); it1 != m_lstRow.end(); ++it1 )
  1578. {
  1579. RowFormat *rw=sheet->rowFormat((*it1).rowNumber);
  1580. rw->setDblHeight((*it1).rowHeight);
  1581. }
  1582. }
  1583. }
  1584. doc()->undoUnlock();
  1585. }
  1586. void UndoResizeColRow::redo()
  1587. {
  1588. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1589. if ( !sheet )
  1590. return;
  1591. doc()->undoLock();
  1592. Region::ConstIterator endOfList(m_region.constEnd());
  1593. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  1594. {
  1595. TQRect m_rctRect = (*it)->rect().normalize();
  1596. if( util_isColumnSelected( m_rctRect ) ) // complete column(s)
  1597. {
  1598. TQValueList<columnSize>::Iterator it2;
  1599. for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
  1600. {
  1601. ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
  1602. cl->setDblWidth((*it2).columnWidth);
  1603. }
  1604. }
  1605. else if( util_isRowSelected( m_rctRect ) ) // complete row(s)
  1606. {
  1607. TQValueList<rowSize>::Iterator it2;
  1608. for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 )
  1609. {
  1610. RowFormat *rw=sheet->rowFormat((*it2).rowNumber);
  1611. rw->setDblHeight((*it2).rowHeight);
  1612. }
  1613. }
  1614. else // row and column
  1615. {
  1616. TQValueList<columnSize>::Iterator it2;
  1617. for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
  1618. {
  1619. ColumnFormat *cl=sheet->columnFormat((*it2).columnNumber);
  1620. cl->setDblWidth((*it2).columnWidth);
  1621. }
  1622. TQValueList<rowSize>::Iterator it1;
  1623. for ( it1 = m_lstRedoRow.begin(); it1 != m_lstRedoRow.end(); ++it1 )
  1624. {
  1625. RowFormat *rw=sheet->rowFormat((*it1).rowNumber);
  1626. rw->setDblHeight((*it1).rowHeight);
  1627. }
  1628. }
  1629. }
  1630. doc()->undoUnlock();
  1631. }
  1632. /****************************************************************************
  1633. *
  1634. * UndoChangeAreaTextCell
  1635. *
  1636. ***************************************************************************/
  1637. UndoChangeAreaTextCell::UndoChangeAreaTextCell( Doc *_doc, Sheet *_sheet, const Region &_selection ) :
  1638. UndoAction( _doc )
  1639. {
  1640. name=i18n("Change Text");
  1641. m_region = _selection;
  1642. m_sheetName = _sheet->sheetName();
  1643. createList( m_lstTextCell, _sheet );
  1644. }
  1645. void UndoChangeAreaTextCell::createList( TQMap<TQPoint,TQString> &map, Sheet* sheet )
  1646. {
  1647. map.clear();
  1648. Region::ConstIterator endOfList(m_region.constEnd());
  1649. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  1650. {
  1651. TQRect m_rctRect = (*it)->rect().normalize();
  1652. int bottom = m_rctRect.bottom();
  1653. int right = m_rctRect.right();
  1654. if( util_isColumnSelected( m_rctRect ) )
  1655. {
  1656. Cell * c;
  1657. for ( int col = m_rctRect.left(); col <= right; ++col )
  1658. {
  1659. c = sheet->getFirstCellColumn( col );
  1660. while ( c )
  1661. {
  1662. if ( !c->isPartOfMerged() )
  1663. {
  1664. //textOfCell tmpText;
  1665. //tmpText.col = col;
  1666. //tmpText.row = c->row();
  1667. //tmpText.text = c->text();
  1668. map.insert( TQPoint(col,c->row()) , c->text() );
  1669. }
  1670. c = sheet->getNextCellDown( col, c->row() );
  1671. }
  1672. }
  1673. }
  1674. else if ( util_isRowSelected( m_rctRect ) )
  1675. {
  1676. Cell * c;
  1677. for ( int row = m_rctRect.top(); row <= bottom; ++row )
  1678. {
  1679. c = sheet->getFirstCellRow( row );
  1680. while ( c )
  1681. {
  1682. if ( !c->isPartOfMerged() )
  1683. {
  1684. //textOfCell tmpText;
  1685. //tmpText.col = c->column();
  1686. //tmpText.row = row;
  1687. //tmpText.text = c->text();
  1688. map.insert( TQPoint(c->column(),row) , c->text() );
  1689. }
  1690. c = sheet->getNextCellRight( c->column(), row );
  1691. }
  1692. }
  1693. }
  1694. else
  1695. {
  1696. Cell * cell;
  1697. for ( int x = m_rctRect.left(); x <= right; ++x )
  1698. {
  1699. cell = sheet->getFirstCellColumn( x );
  1700. if ( !cell )
  1701. continue;
  1702. while ( cell && cell->row() <= bottom )
  1703. {
  1704. if ( !cell->isObscured() )
  1705. {
  1706. //textOfCell tmpText;
  1707. //tmpText.col = x;
  1708. //tmpText.row = cell->row();
  1709. //tmpText.text = cell->text();
  1710. map.insert( TQPoint(x,cell->row()) , cell->text());
  1711. }
  1712. cell = sheet->getNextCellDown( x, cell->row() );
  1713. }
  1714. }
  1715. }
  1716. }
  1717. }
  1718. UndoChangeAreaTextCell::~UndoChangeAreaTextCell()
  1719. {
  1720. }
  1721. void UndoChangeAreaTextCell::undo()
  1722. {
  1723. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1724. if ( !sheet )
  1725. return;
  1726. doc()->undoLock();
  1727. doc()->emitBeginOperation();
  1728. sheet->setRegionPaintDirty(m_region);
  1729. kdDebug() << "creating redo list..." << endl;
  1730. createList( m_lstRedoTextCell, sheet );
  1731. kdDebug() << "created redo list..." << endl;
  1732. Region::ConstIterator endOfList(m_region.constEnd());
  1733. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  1734. {
  1735. TQRect m_rctRect = (*it)->rect().normalize();
  1736. if ( !util_isRowSelected( m_rctRect )
  1737. && !util_isColumnSelected( m_rctRect ) )
  1738. {
  1739. for ( int x = m_rctRect.left(); x <= m_rctRect.right(); ++x )
  1740. for ( int y = m_rctRect.top(); y <= m_rctRect.bottom(); ++y )
  1741. {
  1742. Cell* cell = sheet->nonDefaultCell( x, y );
  1743. const TQPoint location(x,y);
  1744. if ( m_lstTextCell.contains(location) )
  1745. cell->setCellText( m_lstTextCell[location] );
  1746. else
  1747. cell->setCellText( "",true );
  1748. /*bool found = false;
  1749. TQValueList<textOfCell>::Iterator it;
  1750. for( it = m_lstTextCell.begin(); it != m_lstTextCell.end(); ++it )
  1751. if ( (*it).col == x && (*it).row == y && !found )
  1752. {
  1753. cell->setCellText( (*it).text );
  1754. found = true;
  1755. }
  1756. if( !found )
  1757. cell->setCellText( "", true );*/
  1758. }
  1759. }
  1760. else
  1761. {
  1762. TQMap<TQPoint,TQString>::Iterator it2;
  1763. for ( it2 = m_lstTextCell.begin(); it2 != m_lstTextCell.end(); ++it2 )
  1764. {
  1765. Cell *cell = sheet->nonDefaultCell( it2.key().x(), it2.key().y() );
  1766. if ( it2.data().isEmpty() )
  1767. {
  1768. if ( !cell->text().isEmpty() )
  1769. cell->setCellText( "" );
  1770. }
  1771. else
  1772. cell->setCellText( it2.data() );
  1773. }
  1774. }
  1775. }
  1776. //sheet->updateView();
  1777. doc()->emitEndOperation();
  1778. doc()->undoUnlock();
  1779. }
  1780. void UndoChangeAreaTextCell::redo()
  1781. {
  1782. Sheet * sheet = doc()->map()->findSheet( m_sheetName );
  1783. if ( !sheet )
  1784. return;
  1785. doc()->undoLock();
  1786. doc()->emitBeginOperation();
  1787. sheet->setRegionPaintDirty(m_region);
  1788. Region::ConstIterator endOfList(m_region.constEnd());
  1789. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  1790. {
  1791. TQRect m_rctRect = (*it)->rect().normalize();
  1792. if ( !util_isRowSelected( m_rctRect )
  1793. && !util_isColumnSelected( m_rctRect ) )
  1794. {
  1795. for ( int x = m_rctRect.left(); x <= m_rctRect.right(); ++x )
  1796. for ( int y = m_rctRect.top(); y <= m_rctRect.bottom(); ++y )
  1797. {
  1798. Cell* cell = sheet->nonDefaultCell( x, y );
  1799. const TQPoint location(x,y);
  1800. if (m_lstRedoTextCell.contains(location))
  1801. cell->setCellText( m_lstRedoTextCell[location] );
  1802. else
  1803. cell->setCellText( "" , true );
  1804. /*bool found = false;
  1805. TQValueList<textOfCell>::Iterator it;
  1806. for( it = m_lstRedoTextCell.begin(); it != m_lstRedoTextCell.end(); ++it )
  1807. if ( (*it).col == x && (*it).row == y && !found )
  1808. {
  1809. cell->setCellText( (*it).text );
  1810. found = true;
  1811. }
  1812. if( !found )
  1813. cell->setCellText( "", true );*/
  1814. }
  1815. }
  1816. else
  1817. {
  1818. TQMap<TQPoint,TQString>::Iterator it2;
  1819. for ( it2 = m_lstRedoTextCell.begin(); it2 != m_lstRedoTextCell.end(); ++it2 )
  1820. {
  1821. Cell *cell = sheet->nonDefaultCell( it2.key().x(), it2.key().y() );
  1822. if ( it2.data().isEmpty() )
  1823. {
  1824. if ( !cell->text().isEmpty() )
  1825. cell->setCellText( "" );
  1826. }
  1827. else
  1828. cell->setCellText( it2.data() );
  1829. }
  1830. }
  1831. }
  1832. //sheet->updateView();
  1833. doc()->emitEndOperation();
  1834. doc()->undoUnlock();
  1835. }
  1836. /****************************************************************************
  1837. *
  1838. * UndoMergedCell
  1839. *
  1840. ***************************************************************************/
  1841. UndoMergedCell::UndoMergedCell( Doc *_doc, Sheet *_sheet, int _column, int _row , int _extraX,int _extraY) :
  1842. UndoAction( _doc )
  1843. {
  1844. name=i18n("Merge Cells");
  1845. m_sheetName = _sheet->sheetName();
  1846. m_iRow=_row;
  1847. m_iCol=_column;
  1848. m_iExtraX=_extraX;
  1849. m_iExtraY=_extraY;
  1850. }
  1851. UndoMergedCell::~UndoMergedCell()
  1852. {
  1853. }
  1854. void UndoMergedCell::undo()
  1855. {
  1856. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1857. if ( !sheet )
  1858. return;
  1859. doc()->undoLock();
  1860. Cell *cell = sheet->nonDefaultCell( m_iCol, m_iRow );
  1861. m_iExtraRedoX=cell->extraXCells();
  1862. m_iExtraRedoY=cell->extraYCells();
  1863. sheet->changeMergedCell( m_iCol, m_iRow, m_iExtraX,m_iExtraY);
  1864. doc()->undoUnlock();
  1865. }
  1866. void UndoMergedCell::redo()
  1867. {
  1868. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1869. if ( !sheet )
  1870. return;
  1871. doc()->undoLock();
  1872. sheet->changeMergedCell( m_iCol, m_iRow, m_iExtraRedoX,m_iExtraRedoY);
  1873. doc()->undoUnlock();
  1874. }
  1875. /****************************************************************************
  1876. *
  1877. * UndoAutofill
  1878. *
  1879. ***************************************************************************/
  1880. UndoAutofill::UndoAutofill( Doc *_doc, Sheet* sheet, const TQRect & _selection)
  1881. : UndoAction( _doc )
  1882. {
  1883. name=i18n("Autofill");
  1884. m_sheetName = sheet->sheetName();
  1885. m_selection = _selection;
  1886. createListCell( m_data, sheet );
  1887. }
  1888. UndoAutofill::~UndoAutofill()
  1889. {
  1890. }
  1891. void UndoAutofill::createListCell( TQCString &list, Sheet* sheet )
  1892. {
  1893. TQDomDocument doc = sheet->saveCellRegion( m_selection );
  1894. // Save to buffer
  1895. TQString buffer;
  1896. TQTextStream str( &buffer, IO_WriteOnly );
  1897. str << doc;
  1898. // This is a terrible hack to store tqunicode
  1899. // data in a TQCString in a way that
  1900. // TQCString::length() == TQCString().size().
  1901. // This allows us to treat the TQCString like a TQByteArray later on.
  1902. list = buffer.utf8();
  1903. int len = list.length();
  1904. char tmp = list[ len - 1 ];
  1905. list.resize( len );
  1906. *( list.data() + len - 1 ) = tmp;
  1907. }
  1908. void UndoAutofill::undo()
  1909. {
  1910. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1911. if ( !sheet )
  1912. return;
  1913. createListCell( m_dataRedo, sheet );
  1914. doc()->undoLock();
  1915. doc()->emitBeginOperation();
  1916. sheet->deleteCells( m_selection );
  1917. sheet->paste( m_data, m_selection );
  1918. //if(sheet->getAutoCalc()) sheet->recalc();
  1919. doc()->emitEndOperation();
  1920. //sheet->updateView();
  1921. doc()->undoUnlock();
  1922. }
  1923. void UndoAutofill::redo()
  1924. {
  1925. doc()->undoLock();
  1926. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1927. if ( !sheet )
  1928. return;
  1929. doc()->emitBeginOperation();
  1930. sheet->deleteCells( m_selection );
  1931. doc()->undoLock();
  1932. sheet->paste( m_dataRedo, m_selection );
  1933. if ( sheet->getAutoCalc() )
  1934. sheet->recalc();
  1935. sheet->updateView();
  1936. doc()->undoUnlock();
  1937. }
  1938. /****************************************************************************
  1939. *
  1940. * UndoInsertCellRow
  1941. *
  1942. ***************************************************************************/
  1943. UndoInsertCellRow::UndoInsertCellRow( Doc *_doc, Sheet *_sheet, const TQRect &_rect ) :
  1944. UndoInsertRemoveAction( _doc )
  1945. {
  1946. name=i18n("Insert Cell");
  1947. m_sheetName = _sheet->sheetName();
  1948. m_rect=_rect;
  1949. }
  1950. UndoInsertCellRow::~UndoInsertCellRow()
  1951. {
  1952. }
  1953. void UndoInsertCellRow::undo()
  1954. {
  1955. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1956. if ( !sheet )
  1957. return;
  1958. doc()->undoLock();
  1959. sheet->unshiftRow( m_rect);
  1960. doc()->undoUnlock();
  1961. undoFormulaReference();
  1962. }
  1963. void UndoInsertCellRow::redo()
  1964. {
  1965. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1966. if ( !sheet )
  1967. return;
  1968. doc()->undoLock();
  1969. sheet->shiftRow( m_rect);
  1970. doc()->undoUnlock();
  1971. }
  1972. /****************************************************************************
  1973. *
  1974. * UndoInsertCellCol
  1975. *
  1976. ***************************************************************************/
  1977. UndoInsertCellCol::UndoInsertCellCol( Doc *_doc, Sheet *_sheet, const TQRect &_rect ) :
  1978. UndoInsertRemoveAction( _doc )
  1979. {
  1980. name=i18n("Insert Cell");
  1981. m_sheetName = _sheet->sheetName();
  1982. m_rect=_rect;
  1983. }
  1984. UndoInsertCellCol::~UndoInsertCellCol()
  1985. {
  1986. }
  1987. void UndoInsertCellCol::undo()
  1988. {
  1989. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  1990. if ( !sheet )
  1991. return;
  1992. doc()->undoLock();
  1993. sheet->unshiftColumn( m_rect);
  1994. doc()->undoUnlock();
  1995. undoFormulaReference();
  1996. }
  1997. void UndoInsertCellCol::redo()
  1998. {
  1999. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2000. if ( !sheet )
  2001. return;
  2002. doc()->undoLock();
  2003. sheet->shiftColumn( m_rect );
  2004. doc()->undoUnlock();
  2005. }
  2006. /****************************************************************************
  2007. *
  2008. * UndoRemoveCellRow
  2009. *
  2010. ***************************************************************************/
  2011. UndoRemoveCellRow::UndoRemoveCellRow( Doc *_doc, Sheet *_sheet, const TQRect &rect ) :
  2012. UndoInsertRemoveAction( _doc )
  2013. {
  2014. name=i18n("Remove Cell");
  2015. m_sheetName = _sheet->sheetName();
  2016. m_rect=rect;
  2017. TQDomDocument doc = _sheet->saveCellRegion( m_rect );
  2018. // Save to buffer
  2019. TQString buffer;
  2020. TQTextStream str( &buffer, IO_WriteOnly );
  2021. str << doc;
  2022. // This is a terrible hack to store tqunicode
  2023. // data in a TQCString in a way that
  2024. // TQCString::length() == TQCString().size().
  2025. // This allows us to treat the TQCString like a TQByteArray later on.
  2026. m_data = buffer.utf8();
  2027. int len = m_data.length();
  2028. char tmp = m_data[ len - 1 ];
  2029. m_data.resize( len );
  2030. *( m_data.data() + len - 1 ) = tmp;
  2031. }
  2032. UndoRemoveCellRow::~UndoRemoveCellRow()
  2033. {
  2034. }
  2035. void UndoRemoveCellRow::undo()
  2036. {
  2037. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2038. if ( !sheet )
  2039. return;
  2040. doc()->undoLock();
  2041. sheet->shiftRow( m_rect );
  2042. sheet->paste( m_data, m_rect );
  2043. doc()->undoUnlock();
  2044. undoFormulaReference();
  2045. }
  2046. void UndoRemoveCellRow::redo()
  2047. {
  2048. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2049. if ( !sheet )
  2050. return;
  2051. doc()->undoLock();
  2052. sheet->unshiftRow( m_rect);
  2053. doc()->undoUnlock();
  2054. }
  2055. /****************************************************************************
  2056. *
  2057. * UndoRemoveCellCol
  2058. *
  2059. ***************************************************************************/
  2060. UndoRemoveCellCol::UndoRemoveCellCol( Doc *_doc, Sheet *_sheet, const TQRect &_rect ) :
  2061. UndoInsertRemoveAction( _doc )
  2062. {
  2063. name=i18n("Remove Cell");
  2064. m_sheetName = _sheet->sheetName();
  2065. m_rect=_rect;
  2066. TQDomDocument doc = _sheet->saveCellRegion( m_rect );
  2067. // Save to buffer
  2068. TQString buffer;
  2069. TQTextStream str( &buffer, IO_WriteOnly );
  2070. str << doc;
  2071. // This is a terrible hack to store tqunicode
  2072. // data in a TQCString in a way that
  2073. // TQCString::length() == TQCString().size().
  2074. // This allows us to treat the TQCString like a TQByteArray later on.
  2075. m_data = buffer.utf8();
  2076. int len = m_data.length();
  2077. char tmp = m_data[ len - 1 ];
  2078. m_data.resize( len );
  2079. *( m_data.data() + len - 1 ) = tmp;
  2080. }
  2081. UndoRemoveCellCol::~UndoRemoveCellCol()
  2082. {
  2083. }
  2084. void UndoRemoveCellCol::undo()
  2085. {
  2086. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2087. if ( !sheet )
  2088. return;
  2089. doc()->undoLock();
  2090. sheet->shiftColumn( m_rect );
  2091. sheet->paste( m_data, m_rect );
  2092. doc()->undoUnlock();
  2093. undoFormulaReference();
  2094. }
  2095. void UndoRemoveCellCol::redo()
  2096. {
  2097. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2098. if ( !sheet )
  2099. return;
  2100. doc()->undoLock();
  2101. sheet->unshiftColumn( m_rect );
  2102. doc()->undoUnlock();
  2103. }
  2104. /****************************************************************************
  2105. *
  2106. * UndoConditional
  2107. *
  2108. ***************************************************************************/
  2109. UndoConditional::UndoConditional( Doc *_doc, Sheet* sheet, const Region & _selection)
  2110. : UndoAction( _doc )
  2111. {
  2112. name=i18n("Conditional Cell Attribute");
  2113. m_sheetName = sheet->sheetName();
  2114. m_region = _selection;
  2115. createListCell( m_data, sheet );
  2116. }
  2117. UndoConditional::~UndoConditional()
  2118. {
  2119. }
  2120. void UndoConditional::createListCell( TQCString &list, Sheet* sheet )
  2121. {
  2122. // Save to buffer
  2123. TQString buffer;
  2124. TQTextStream str( &buffer, IO_WriteOnly );
  2125. TQDomDocument doc = sheet->saveCellRegion( m_region );
  2126. str << doc;
  2127. // This is a terrible hack to store tqunicode
  2128. // data in a TQCString in a way that
  2129. // TQCString::length() == TQCString().size().
  2130. // This allows us to treat the TQCString like a TQByteArray later on.
  2131. list = buffer.utf8();
  2132. int len = list.length();
  2133. char tmp = list[ len - 1 ];
  2134. list.resize( len );
  2135. *( list.data() + len - 1 ) = tmp;
  2136. }
  2137. void UndoConditional::undo()
  2138. {
  2139. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2140. if ( !sheet )
  2141. return;
  2142. createListCell( m_dataRedo, sheet );
  2143. doc()->undoLock();
  2144. sheet->paste(m_data, m_region.boundingRect());
  2145. if (sheet->getAutoCalc())
  2146. {
  2147. sheet->recalc();
  2148. }
  2149. doc()->undoUnlock();
  2150. }
  2151. void UndoConditional::redo()
  2152. {
  2153. doc()->undoLock();
  2154. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2155. if ( !sheet )
  2156. return;
  2157. doc()->undoLock();
  2158. sheet->paste(m_dataRedo, m_region.boundingRect());
  2159. if (sheet->getAutoCalc())
  2160. {
  2161. sheet->recalc();
  2162. }
  2163. doc()->undoUnlock();
  2164. }
  2165. /****************************************************************************
  2166. *
  2167. * UndoCellPaste
  2168. *
  2169. ***************************************************************************/
  2170. UndoCellPaste::UndoCellPaste(Doc *_doc, Sheet* sheet,
  2171. int _xshift, int _yshift,
  2172. const Region& region, bool insert, int _insertTo)
  2173. : UndoAction( _doc )
  2174. {
  2175. if(!insert)
  2176. name=i18n("Paste");
  2177. else
  2178. name=i18n("Paste & Insert");
  2179. m_sheetName = sheet->sheetName();
  2180. m_region = region;
  2181. xshift=_xshift;
  2182. yshift=_yshift;
  2183. b_insert=insert;
  2184. m_iInsertTo=_insertTo;
  2185. if( !b_insert)
  2186. createListCell( m_data, m_lstColumn,m_lstRow,sheet );
  2187. }
  2188. UndoCellPaste::~UndoCellPaste()
  2189. {
  2190. }
  2191. void UndoCellPaste::createListCell(TQCString& listCell,
  2192. TQValueList<columnSize>& listCol,
  2193. TQValueList<rowSize>& listRow,
  2194. Sheet* sheet)
  2195. {
  2196. listCol.clear();
  2197. listRow.clear();
  2198. Region::ConstIterator endOfList = m_region.constEnd();
  2199. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  2200. {
  2201. int nbCol = 0;
  2202. int nbRow = 0;
  2203. TQRect range = (*it)->rect().normalize();
  2204. if ((*it)->isColumn())
  2205. {
  2206. nbCol = range.width();
  2207. }
  2208. else if ((*it)->isRow())
  2209. {
  2210. nbRow = range.height();
  2211. }
  2212. // copy column(s)
  2213. if (nbCol != 0)
  2214. {
  2215. //save size of columns
  2216. for( int y = 1; y <=nbCol ; ++y )
  2217. {
  2218. ColumnFormat *cl=sheet->columnFormat(y);
  2219. if(!cl->isDefault())
  2220. {
  2221. columnSize tmpSize;
  2222. tmpSize.columnNumber=y;
  2223. tmpSize.columnWidth=cl->dblWidth();
  2224. listCol.append(tmpSize);
  2225. }
  2226. }
  2227. }
  2228. //copy a row(s)
  2229. else if (nbRow != 0)
  2230. {
  2231. //save size of columns
  2232. for ( int y = 1; y <=nbRow ; ++y )
  2233. {
  2234. RowFormat *rw=sheet->rowFormat(y);
  2235. if (!rw->isDefault())
  2236. {
  2237. rowSize tmpSize;
  2238. tmpSize.rowNumber=y;
  2239. tmpSize.rowHeight=rw->dblHeight();
  2240. listRow.append(tmpSize);
  2241. }
  2242. }
  2243. }
  2244. }
  2245. //save all cells in area
  2246. TQDomDocument doc = sheet->saveCellRegion(m_region);
  2247. // Save to buffer
  2248. TQString buffer;
  2249. TQTextStream str( &buffer, IO_WriteOnly );
  2250. str << doc;
  2251. // This is a terrible hack to store tqunicode
  2252. // data in a TQCString in a way that
  2253. // TQCString::length() == TQCString().size().
  2254. // This allows us to treat the TQCString like a TQByteArray later on.
  2255. listCell = buffer.utf8();
  2256. int len = listCell.length();
  2257. char tmp = listCell[ len - 1 ];
  2258. listCell.resize( len );
  2259. *( listCell.data() + len - 1 ) = tmp;
  2260. }
  2261. void UndoCellPaste::undo()
  2262. {
  2263. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2264. if ( !sheet )
  2265. return;
  2266. createListCell( m_dataRedo, m_lstRedoColumn, m_lstRedoRow, sheet );
  2267. doc()->undoLock();
  2268. doc()->emitBeginOperation();
  2269. uint numCols = 0;
  2270. uint numRows = 0;
  2271. Region::ConstIterator endOfList = m_region.constEnd();
  2272. for (Region::ConstIterator it = --m_region.constEnd(); it != endOfList; --it)
  2273. {
  2274. TQRect range = (*it)->rect().normalize();
  2275. if ((*it)->isColumn())
  2276. {
  2277. if (!b_insert)
  2278. {
  2279. TQValueList<columnSize>::Iterator it2;
  2280. for ( it2 = m_lstColumn.begin(); it2 != m_lstColumn.end(); ++it2 )
  2281. {
  2282. ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
  2283. cl->setDblWidth((*it2).columnWidth);
  2284. }
  2285. }
  2286. else
  2287. {
  2288. numCols += range.width();
  2289. }
  2290. }
  2291. else if ((*it)->isRow())
  2292. {
  2293. if (!b_insert)
  2294. {
  2295. TQValueList<rowSize>::Iterator it2;
  2296. for ( it2 = m_lstRow.begin(); it2 != m_lstRow.end(); ++it2 )
  2297. {
  2298. RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
  2299. rw->setDblHeight((*it2).rowHeight);
  2300. }
  2301. }
  2302. else
  2303. {
  2304. numRows += range.height();
  2305. }
  2306. }
  2307. if (!b_insert)
  2308. {
  2309. sheet->deleteCells(range);
  2310. }
  2311. } // for (Region::...
  2312. if (b_insert) // with insertion
  2313. {
  2314. TQRect rect = m_region.boundingRect();
  2315. if (m_iInsertTo == -1 && numCols == 0 && numRows == 0)
  2316. {
  2317. // substract already removed columns
  2318. rect.setWidth(rect.width());
  2319. sheet->unshiftRow(rect);
  2320. }
  2321. else if (m_iInsertTo == 1 && numCols == 0 && numRows == 0)
  2322. {
  2323. // substract already removed rows
  2324. rect.setHeight(rect.height());
  2325. sheet->unshiftColumn(rect);
  2326. }
  2327. // delete columns
  2328. else if (m_iInsertTo == 0 && numCols == 0 && numRows > 0)
  2329. {
  2330. sheet->removeRow(rect.top(), rect.height() - 1, false);
  2331. }
  2332. // delete rows
  2333. else if (m_iInsertTo == 0 && numCols > 0 && numRows == 0)
  2334. {
  2335. sheet->removeColumn(rect.left(), rect.width() - 1, false);
  2336. }
  2337. }
  2338. else // without insertion
  2339. {
  2340. sheet->paste(m_data, m_region.boundingRect());
  2341. }
  2342. if (sheet->getAutoCalc())
  2343. {
  2344. sheet->recalc();
  2345. }
  2346. sheet->updateView();
  2347. doc()->undoUnlock();
  2348. }
  2349. void UndoCellPaste::redo()
  2350. {
  2351. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2352. if ( !sheet )
  2353. return;
  2354. doc()->undoLock();
  2355. doc()->emitBeginOperation();
  2356. uint numCols = 0;
  2357. uint numRows = 0;
  2358. Region::ConstIterator endOfList(m_region.constEnd());
  2359. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  2360. {
  2361. TQRect range = (*it)->rect().normalize();
  2362. if ((*it)->isColumn())
  2363. {
  2364. numCols += range.width();
  2365. }
  2366. else if ((*it)->isRow())
  2367. {
  2368. numRows += range.height();
  2369. }
  2370. else
  2371. {
  2372. if (!b_insert)
  2373. {
  2374. sheet->deleteCells( range );
  2375. }
  2376. }
  2377. } // for (Region::...
  2378. if (b_insert)
  2379. {
  2380. TQRect rect = m_region.boundingRect();
  2381. if (m_iInsertTo == -1 && numCols == 0 && numRows == 0)
  2382. {
  2383. rect.setWidth(rect.width());
  2384. sheet->shiftRow(rect);
  2385. }
  2386. else if (m_iInsertTo == 1 && numCols == 0 && numRows == 0)
  2387. {
  2388. rect.setHeight(rect.height());
  2389. sheet->shiftColumn(rect);
  2390. }
  2391. // insert columns
  2392. else if (m_iInsertTo == 0 && numCols == 0 && numRows > 0)
  2393. {
  2394. sheet->insertRow(rect.top(), rect.height() - 1, false);
  2395. }
  2396. // insert rows
  2397. else if (m_iInsertTo == 0 && numCols > 0 && numRows == 0)
  2398. {
  2399. sheet->insertColumn(rect.left(), rect.width() - 1, false);
  2400. }
  2401. }
  2402. for (Region::ConstIterator it = m_region.constBegin(); it != endOfList; ++it)
  2403. {
  2404. if ((*it)->isColumn())
  2405. {
  2406. TQValueList<columnSize>::Iterator it2;
  2407. for ( it2 = m_lstRedoColumn.begin(); it2 != m_lstRedoColumn.end(); ++it2 )
  2408. {
  2409. ColumnFormat *cl=sheet->nonDefaultColumnFormat((*it2).columnNumber);
  2410. cl->setDblWidth((*it2).columnWidth);
  2411. }
  2412. }
  2413. else if ((*it)->isRow())
  2414. {
  2415. TQValueList<rowSize>::Iterator it2;
  2416. for ( it2 = m_lstRedoRow.begin(); it2 != m_lstRedoRow.end(); ++it2 )
  2417. {
  2418. RowFormat *rw=sheet->nonDefaultRowFormat((*it2).rowNumber);
  2419. rw->setDblHeight((*it2).rowHeight);
  2420. }
  2421. }
  2422. } // for (Region::...
  2423. sheet->paste( m_dataRedo, m_region.boundingRect() );
  2424. if (sheet->getAutoCalc())
  2425. {
  2426. sheet->recalc();
  2427. }
  2428. sheet->updateView();
  2429. doc()->undoUnlock();
  2430. }
  2431. /****************************************************************************
  2432. *
  2433. * UndoStyleCell
  2434. *
  2435. ***************************************************************************/
  2436. UndoStyleCell::UndoStyleCell( Doc *_doc, Sheet* sheet, const TQRect & _selection)
  2437. : UndoAction( _doc )
  2438. {
  2439. name=i18n("Style of Cell");
  2440. m_sheetName = sheet->sheetName();
  2441. m_selection = _selection;
  2442. createListCell( m_lstStyleCell, sheet );
  2443. }
  2444. UndoStyleCell::~UndoStyleCell()
  2445. {
  2446. }
  2447. void UndoStyleCell::createListCell( TQValueList<styleCell> &listCell, Sheet* sheet )
  2448. {
  2449. int bottom = m_selection.bottom();
  2450. int right = m_selection.right();
  2451. if ( util_isColumnSelected( m_selection ) )
  2452. {
  2453. Cell * c;
  2454. for ( int col = m_selection.left(); col <= right; ++ col )
  2455. {
  2456. c = sheet->getFirstCellColumn( col );
  2457. while ( c )
  2458. {
  2459. if ( !c->isPartOfMerged() )
  2460. {
  2461. styleCell tmpStyleCell;
  2462. tmpStyleCell.row = c->row();
  2463. tmpStyleCell.col = col;
  2464. listCell.append(tmpStyleCell);
  2465. }
  2466. c = sheet->getNextCellDown( col, c->row() );
  2467. }
  2468. }
  2469. }
  2470. else if ( util_isRowSelected( m_selection ) )
  2471. {
  2472. Cell * c;
  2473. for ( int row = m_selection.top(); row <= bottom; ++row )
  2474. {
  2475. c = sheet->getFirstCellRow( row );
  2476. while ( c )
  2477. {
  2478. if ( !c->isPartOfMerged() )
  2479. {
  2480. styleCell tmpStyleCell;
  2481. tmpStyleCell.row = row;
  2482. tmpStyleCell.col = c->column();
  2483. listCell.append(tmpStyleCell);
  2484. }
  2485. c = sheet->getNextCellRight( c->column(), row );
  2486. }
  2487. }
  2488. }
  2489. else
  2490. {
  2491. Cell * cell;
  2492. for ( int i = m_selection.top(); i <= bottom; ++i)
  2493. for ( int j = m_selection.left(); j <= right; ++j )
  2494. {
  2495. cell = sheet->nonDefaultCell( j, i);
  2496. styleCell tmpStyleCell;
  2497. tmpStyleCell.row = i;
  2498. tmpStyleCell.col = j;
  2499. listCell.append(tmpStyleCell);
  2500. }
  2501. }
  2502. }
  2503. void UndoStyleCell::undo()
  2504. {
  2505. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2506. if ( !sheet )
  2507. return;
  2508. createListCell( m_lstRedoStyleCell, sheet );
  2509. doc()->undoLock();
  2510. doc()->emitBeginOperation();
  2511. TQValueList<styleCell>::Iterator it2;
  2512. for ( it2 = m_lstStyleCell.begin(); it2 != m_lstStyleCell.end(); ++it2 )
  2513. {
  2514. sheet->nonDefaultCell( (*it2).col, (*it2).row);
  2515. }
  2516. sheet->setRegionPaintDirty(m_selection);
  2517. sheet->updateView( m_selection );
  2518. doc()->undoUnlock();
  2519. }
  2520. void UndoStyleCell::redo()
  2521. {
  2522. doc()->undoLock();
  2523. Sheet* sheet = doc()->map()->findSheet( m_sheetName );
  2524. if ( !sheet )
  2525. return;
  2526. doc()->undoLock();
  2527. doc()->emitBeginOperation();
  2528. TQValueList<styleCell>::Iterator it2;
  2529. for ( it2 = m_lstRedoStyleCell.begin(); it2 != m_lstRedoStyleCell.end(); ++it2 )
  2530. {
  2531. sheet->nonDefaultCell( (*it2).col, (*it2).row);
  2532. }
  2533. sheet->setRegionPaintDirty(m_selection);
  2534. sheet->updateView();
  2535. doc()->undoUnlock();
  2536. }
  2537. UndoInsertData::UndoInsertData( Doc * _doc, Sheet * _sheet, TQRect & _selection )
  2538. : UndoChangeAreaTextCell( _doc, _sheet, _selection )
  2539. {
  2540. name = i18n("Insert Data From Database");
  2541. }