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.

756 lines
20KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2006 Raphael Langerhorst <raphael.langerhorst@kdemail.net>
  3. (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
  4. (C) 1999-2003 Laurent Montel <montel@kde.org>
  5. (C) 2002-2003 Norbert Andres <nandres@web.de>
  6. (C) 2002-2003 Philipp Mueller <philipp.mueller@gmx.de>
  7. (C) 2002-2003 John Dailey <dailey@vt.edu>
  8. (C) 1999-2003 David Faure <faure@kde.org>
  9. (C) 1999-2001 Simon Hausmann <hausmann@kde.org>
  10. (C) 1998-2000 Torben Weis <weis@kde.org>
  11. This library is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU Library General Public
  13. License as published by the Free Software Foundation; either
  14. version 2 of the License, or (at your option) any later version.
  15. This library is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. Library General Public License for more details.
  19. You should have received a copy of the GNU Library General Public License
  20. along with this library; see the file COPYING.LIB. If not, write to
  21. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301, USA.
  23. */
  24. #ifndef KSPREAD_VIEW
  25. #define KSPREAD_VIEW
  26. #include <tqpoint.h>
  27. #include <tqptrlist.h>
  28. #include <tqstringlist.h>
  29. #include <tqvaluelist.h>
  30. #include <kprinter.h>
  31. #include <tdeprint/kprintdialogpage.h>
  32. #include <KoPoint.h>
  33. #include <KoView.h>
  34. class TQScrollBar;
  35. class KoDocumentEntry;
  36. class KoTabBar;
  37. class SheetSelectWidget;
  38. namespace KSpread
  39. {
  40. class Cell;
  41. class Damage;
  42. class Sheet;
  43. class Canvas;
  44. class Child;
  45. class Doc;
  46. class EditWidget;
  47. class HBorder;
  48. class LocationEditWidget;
  49. class Region;
  50. class Selection;
  51. class VBorder;
  52. class View;
  53. class ComboboxLocationEditWidget;
  54. class EmbeddedKOfficeObject;
  55. class EmbeddedObject;
  56. /**
  57. * \class KPSheetSelectPage
  58. * \brief Print dialog page for selecting sheets to print.
  59. * @author raphael.langerhorst@kdemail.net
  60. * @see SheetSelectWidget
  61. *
  62. * This dialog is shown in the print dialog and allows the user
  63. * to select the sheets that should be printed and in which order
  64. * they should be printed.
  65. */
  66. class KPSheetSelectPage : public KPrintDialogPage
  67. {
  68. Q_OBJECT
  69. public:
  70. KPSheetSelectPage( TQWidget *parent = 0 );
  71. // ~KPSheetSelectPage();
  72. // //reimplement virtual functions
  73. /**
  74. * @see printOptionPrefix()
  75. */
  76. void getOptions( TQMap<TQString,TQString>& opts, bool incldef = false );
  77. /**
  78. * @see printOptionPrefix()
  79. */
  80. void setOptions( const TQMap<TQString,TQString>& opts );
  81. /**
  82. * @return false if no sheet is selected for printing.
  83. */
  84. bool isValid( TQString& msg );
  85. /**
  86. * @return list of sheets that will be printed, in correct order.
  87. */
  88. TQStringList selectedSheets();
  89. /**
  90. * Removes all sheets from the list of selected sheets.
  91. */
  92. void clearSelection();
  93. /**
  94. * The print order of the sheets is stored in the option map,
  95. * using a prefix plus the index of the sheet, like the following:
  96. * \li sheetprintorder0
  97. * \li sheetprintorder1
  98. * \li sheetprintorder2
  99. * Please note that this is just the key to the value, not the value
  100. * itself. The value of the option is the sheetname itself.
  101. * @param index the index of the print order, starting at 0
  102. * @return the string that is used in the printoption for given index
  103. */
  104. static TQString printOptionForIndex(unsigned int index);
  105. /**
  106. * @param prt the printer from which the options should be read.
  107. * @return list of sheets to print in correct order configured for given printer.
  108. */
  109. static TQStringList selectedSheets(KPrinter &prt);
  110. public slots:
  111. /**
  112. * Inserts given sheet to the list of available sheets.
  113. */
  114. void prependAvailableSheet(const TQString& sheetname);
  115. /**
  116. * Inserts given sheet to the list of sheets for printing at the top.
  117. */
  118. void prependSelectedSheet(const TQString& sheetname);
  119. protected slots:
  120. // The following slots just implement the code for the buttons
  121. void selectAll();
  122. void select();
  123. void remove();
  124. void removeAll();
  125. void moveTop();
  126. void moveUp();
  127. void moveDown();
  128. void moveBottom();
  129. private:
  130. /**
  131. * The widget used, includes two lists of sheet names and
  132. * buttons to move sheets between and within the lists.
  133. */
  134. SheetSelectWidget* gui;
  135. };
  136. /** @class View
  137. *
  138. * @brief The View class displays a KSpread document.
  139. *
  140. *
  141. * View is used to display a spreadsheet document and provide
  142. * the interface for the user to perform editing and data analysis.
  143. *
  144. * A view consists of several parts:
  145. * \li canvas to display cells in a sheet
  146. * \li line editor to display and edit cell contents
  147. * \li location editor to show marker and/or selection
  148. * \li column header to show columns
  149. * \li row header to show rows
  150. * \li horizontal and vertical scrollbars for navigation
  151. * \li tab bar to select active worksheet
  152. *
  153. */
  154. class KSPREAD_EXPORT View : public KoView
  155. {
  156. friend class Canvas;
  157. Q_OBJECT
  158. public:
  159. /** Creates a new view */
  160. View( TQWidget *_parent, const char *_name,
  161. Doc *doc );
  162. /** Destroys the view */
  163. ~View();
  164. Doc* doc() const;
  165. /** Returns the canvas of the view */
  166. Canvas* canvasWidget() const;
  167. /** Returns the column header */
  168. HBorder* hBorderWidget() const;
  169. /** Returns the row header */
  170. VBorder* vBorderWidget() const;
  171. /** Returns the horizontal scrollbar */
  172. TQScrollBar* horzScrollBar() const;
  173. /** Returns the vertical scrollbar */
  174. TQScrollBar* vertScrollBar() const;
  175. /** Returns the editor widget */
  176. KSpread::EditWidget* editWidget() const;
  177. /** Returns the location widget */
  178. ComboboxLocationEditWidget* posWidget() const;
  179. /** Returns the tab bar */
  180. KoTabBar* tabBar() const;
  181. void setZoom( int zoom, bool updateViews ); // change the zoom value
  182. void addSheet( Sheet *_t );
  183. //void removesheet( Sheet *_t );
  184. void removeAllSheets();
  185. void setActiveSheet( Sheet *_t,bool updatesheet=true );
  186. const Sheet* activeSheet() const;
  187. Sheet* activeSheet();
  188. void openPopupMenu( const TQPoint &_global );
  189. void popupRowMenu(const TQPoint & _point ) ;
  190. void popupColumnMenu( const TQPoint & _point);
  191. // void showFormulaToolBar( bool show );
  192. /**
  193. * Used by @ref EditWidget. Sets the text of the active cell(s).
  194. */
  195. void setText( const TQString& _text, bool array = false );
  196. void enableUndo( bool _b );
  197. void enableRedo( bool _b );
  198. void enableInsertColumn( bool _b );
  199. void enableInsertRow( bool _b );
  200. /**
  201. *
  202. * @param _geometry is the zoomed geometry of the new child.
  203. * @param _entry is the entry to insert.
  204. *
  205. * @todo check validity of @p _entry docs.
  206. */
  207. void insertChart( const TQRect& _geometry, KoDocumentEntry& _entry );
  208. /**
  209. *
  210. * @param _geometry is the geometry of the new child.
  211. * @param _entry is the entry to insert.
  212. *
  213. * @todo check validity of @p _entry docs.
  214. */
  215. void insertChild( const TQRect& _geometry, KoDocumentEntry& _entry );
  216. // void insertPicture( const TQRect& _geometry, KURL& _file );
  217. virtual void print( KPrinter &printer );
  218. virtual void setupPrinter( KPrinter &printer );
  219. /**
  220. * Fills the @ref EditWidget with the current cells
  221. * content. This function is usually called after the
  222. * cursor moved.
  223. */
  224. void updateEditWidget();
  225. /**
  226. * Same as updateEditEidget() but no update of menus and toolbars
  227. */
  228. void updateEditWidgetOnPress();
  229. /**
  230. * Called before saving, to finish the current edition (if any)
  231. */
  232. void deleteEditor( bool saveChanges = true );
  233. void closeEditor();
  234. virtual DCOPObject* dcopObject();
  235. virtual TQWidget *canvas() const;
  236. virtual int canvasXOffset() const;
  237. virtual int canvasYOffset() const;
  238. /**
  239. * @reimp
  240. */
  241. KoDocument *hitTest( const TQPoint &pos );
  242. void initConfig();
  243. void initCalcMenu();
  244. void changeNbOfRecentFiles(int _nb);
  245. void updateBorderButton();
  246. void removeSheet( Sheet *_t );
  247. void insertSheet( Sheet* sheet );
  248. TQColor borderColor() const;
  249. Selection* selectionInfo() const;
  250. Selection* choice() const;
  251. void updateShowSheetMenu();
  252. /**
  253. * Mark all selected cells / regions of cells as 'dirty' (ie. requiring a repaint)
  254. * They will be repainted on the next call to paintUpdates()
  255. */
  256. void markSelectionAsDirty();
  257. /**
  258. * Repaint any cell with the paintDirty flag that is visible in this view
  259. */
  260. void paintUpdates();
  261. /**
  262. * Resets the internal handle pointer, called from InsertHandler destructor
  263. */
  264. void resetInsertHandle();
  265. bool isInsertingObject();
  266. bool showSheet(const TQString& sheetName);
  267. /**
  268. * @return marker for @p sheet
  269. */
  270. TQPoint markerFromSheet( Sheet* sheet ) const;
  271. /**
  272. * @return scroll offset for @p sheet
  273. */
  274. KoPoint offsetFromSheet( Sheet* sheet ) const;
  275. /**
  276. * Save current sheet selection.
  277. * Call when we change sheet, or before save in OpenDocument format.
  278. */
  279. void saveCurrentSheetSelection();
  280. void deleteSelectedObjects();
  281. /**
  282. * Returns the default color for highlighting cells and column / row headers
  283. */
  284. static TQColor highlightColor();
  285. public slots:
  286. /**
  287. * refresh view when you hide/show vertical scrollbar
  288. */
  289. void refreshView();
  290. void initialPosition();
  291. /**
  292. * Actions
  293. */
  294. void createTemplate();
  295. void transformPart();
  296. void copySelection();
  297. void cutSelection();
  298. void deleteSelection();
  299. void clearTextSelection();
  300. void clearCommentSelection();
  301. void clearValiditySelection();
  302. void clearConditionalSelection();
  303. void fillRight();
  304. void fillLeft();
  305. void fillUp();
  306. void fillDown();
  307. void recalcWorkBook();
  308. void recalcWorkSheet();
  309. void paste();
  310. void specialPaste();
  311. void editCell();
  312. void setAreaName();
  313. void showAreaName();
  314. void adjust();
  315. void defaultSelection();
  316. void paperLayoutDlg();
  317. void styleDialog();
  318. void definePrintRange();
  319. void resetPrintRange();
  320. void insertObject();
  321. void insertFromDatabase();
  322. void insertFromTextfile();
  323. void insertFromClipboard();
  324. void insertSpecialChar();
  325. void togglePageBorders( bool );
  326. void toggleProtectSheet( bool );
  327. void toggleProtectDoc( bool );
  328. void viewZoom( const TQString & );
  329. void find();
  330. void findNext();
  331. void findPrevious();
  332. void replace();
  333. void conditional();
  334. void validity();
  335. void insertSeries();
  336. void sort();
  337. void insertHyperlink();
  338. void removeHyperlink();
  339. void goalSeek();
  340. void multipleOperations();
  341. void subtotals();
  342. void textToColumns();
  343. void consolidate();
  344. void insertSheet();
  345. void removeSheet();
  346. void hideSheet();
  347. void showSheet();
  348. void helpUsing();
  349. void insertChart();
  350. void insertPicture();
  351. void moneyFormat(bool b);
  352. void alignLeft( bool b );
  353. void alignRight( bool b );
  354. void alignCenter( bool b );
  355. void alignTop( bool b );
  356. void alignMiddle( bool b );
  357. void alignBottom( bool b );
  358. void wrapText( bool b );
  359. void precisionMinus();
  360. void precisionPlus();
  361. void createStyleFromCell();
  362. void styleSelected( const TQString & );
  363. void setSelectionPrecision(int delta);
  364. void percent(bool b);
  365. void fontSelected( const TQString &_font );
  366. void fontSizeSelected( int size );
  367. void bold( bool b );
  368. void italic( bool b );
  369. void underline( bool b );
  370. void strikeOut( bool b );
  371. void deleteColumn();
  372. void insertColumn();
  373. void deleteRow();
  374. void insertRow();
  375. void hideRow();
  376. void showRow();
  377. void showSelRows();
  378. void hideColumn();
  379. void showColumn();
  380. void showSelColumns();
  381. void insertMathExpr();
  382. void formulaSelection( const TQString &_math );
  383. void changeTextColor();
  384. void changeBackgroundColor();
  385. void sortInc();
  386. void sortDec();
  387. void layoutDlg();
  388. void extraProperties();
  389. void borderBottom();
  390. void borderRight();
  391. void borderLeft();
  392. void borderTop();
  393. void borderOutline();
  394. void borderAll();
  395. void borderRemove();
  396. void changeBorderColor();
  397. void sheetFormat();
  398. void autoSum();
  399. void resizeRow();
  400. void resizeColumn();
  401. void increaseFontSize();
  402. void decreaseFontSize();
  403. void setSelectionFontSize(int size);
  404. void setSelectionTextColor(const TQColor &txtColor);
  405. void setSelectionBackgroundColor(const TQColor &bgColor);
  406. void setSelectionBorderColor(const TQColor &bdColor);
  407. void setSelectionLeftBorderColor(const TQColor &color);
  408. void setSelectionRightBorderColor(const TQColor &color);
  409. void setSelectionTopBorderColor(const TQColor &color);
  410. void setSelectionBottomBorderColor(const TQColor &color);
  411. void setSelectionAllBorderColor(const TQColor &color);
  412. void setSelectionOutlineBorderColor(const TQColor &color);
  413. void upper();
  414. void lower();
  415. void equalizeColumn();
  416. void equalizeRow();
  417. void preference();
  418. void firstLetterUpper();
  419. void verticalText(bool );
  420. void addModifyComment();
  421. void setSelectionComment(TQString comment);
  422. void removeComment();
  423. void changeAngle();
  424. void setSelectionAngle(int angle);
  425. /**
  426. * Merges selected cells into one cell. This will not work if only one
  427. * cell is selected. An entire row or column can't be merged as well.
  428. *
  429. * \sa dissociateCell
  430. */
  431. void mergeCell();
  432. void mergeCellHorizontal();
  433. void mergeCellVertical();
  434. /**
  435. * Breaks merged cell. Obviously this can be done only on merged cells.
  436. *
  437. * \sa mergeCell
  438. */
  439. void dissociateCell();
  440. void gotoCell();
  441. void increaseIndent();
  442. void decreaseIndent();
  443. void copyAsText();
  444. void moveSheet( unsigned sheet, unsigned target );
  445. /**
  446. * Shows the sheet properties dialog.
  447. */
  448. void sheetProperties();
  449. /**
  450. * Switch the active sheet to the name. This slot is connected to the tab bar
  451. * and activated when the user selects a new sheet in the tab bar.
  452. */
  453. void changeSheet( const TQString& _name );
  454. /**
  455. * Switch the active sheet to the next visible sheet. Does nothing if the current
  456. * active sheet is the last visible sheet in the workbook.
  457. */
  458. void nextSheet();
  459. /**
  460. * Switch the active sheet to the previous visible sheet. Does nothing if the current
  461. * active sheet is the first visible sheet in the workbook.
  462. */
  463. void previousSheet();
  464. /**
  465. * Switch the active sheet to the first visible sheet in the workbook. Does nothing
  466. * if the current active sheet is already the first one.
  467. */
  468. void firstSheet();
  469. /**
  470. * Switch the active sheet to the last visible sheet in the workbook. Does nothing
  471. * if the current active sheet is already the last one.
  472. */
  473. void lastSheet();
  474. void sortList();
  475. void statusBarClicked(int _id);
  476. void menuCalc(bool);
  477. /**
  478. * Shows the status bar if b is true, otherwise the status bar will be hidden.
  479. */
  480. void showStatusBar( bool b );
  481. /**
  482. * Shows the tab bar if b is true, otherwise the tab bar will be hidden.
  483. */
  484. void showTabBar( bool b );
  485. /**
  486. * Shows the formula bar if b is true, otherwise the formula bar will be hidden.
  487. */
  488. void showFormulaBar( bool b );
  489. /**
  490. * Shows context menu when tabbar is double-clicked.
  491. */
  492. void popupTabBarMenu( const TQPoint& );
  493. void handleDamages( const TQValueList<Damage*>& damages );
  494. void runInternalTests();
  495. void runInspector();
  496. void initialiseMarkerFromSheet( Sheet *_sheet, const TQPoint &point );
  497. /**
  498. * write in statusBar result of calc (Min, or Max, average, sum, count)
  499. */
  500. void calcStatusBarOp();
  501. protected slots:
  502. /**
  503. * Popup menu
  504. */
  505. void slotActivateTool( int _id );
  506. void slotInsert();
  507. void slotInsertCellCopy();
  508. void slotRemove();
  509. void slotRename();
  510. /**
  511. * Invoked if the popup menu for an embedded document should be opened.
  512. */
  513. void popupChildMenu( KoChild*, const TQPoint& global_pos );
  514. /**
  515. * Invoked when the "Delete Embedded Document" option from an embedded document's
  516. * popup menu is selected.
  517. */
  518. void slotPopupDeleteChild();
  519. /**
  520. * Border popup menu
  521. */
  522. void slotPopupAdjustColumn();
  523. void slotPopupAdjustRow();
  524. /**
  525. * list from list choose
  526. */
  527. void slotItemSelected( int );
  528. void slotListChoosePopupMenu( );
  529. /**
  530. * Called by find/replace (findNext) when it found a match
  531. */
  532. void slotHighlight( const TQString &text, int matchingIndex, int matchedLength );
  533. /**
  534. * Called when replacing text in a cell
  535. */
  536. void slotReplace( const TQString &newText, int, int, int );
  537. void slotSpecialChar( TQChar c, const TQString & _font );
  538. void slotSpecialCharDlgClosed();
  539. void propertiesOk();
  540. void objectSelectedChanged();
  541. protected slots:
  542. void slotChildSelected( KoDocumentChild* ch );
  543. void slotChildUnselected( KoDocumentChild* );
  544. public slots:
  545. // Document signals
  546. void slotRefreshView();
  547. void slotUpdateView( Sheet *_sheet );
  548. void slotUpdateView( Sheet *_sheet, const Region& );
  549. void slotUpdateView( EmbeddedObject* obj );
  550. void slotUpdateHBorder( Sheet *_sheet );
  551. void slotUpdateVBorder( Sheet *_sheet );
  552. void slotChangeSelection(const Region&);
  553. void slotChangeChoice(const Region&);
  554. void slotScrollChoice(const Region&);
  555. void slotAddSheet( Sheet *_sheet );
  556. void slotUpdateChildGeometry( EmbeddedKOfficeObject *_child );
  557. void slotSheetRenamed( Sheet* sheet, const TQString& old_name );
  558. void slotSheetHidden( Sheet*_sheet );
  559. void slotSheetShown( Sheet*_sheet );
  560. void slotSheetRemoved( Sheet*_sheet );
  561. void refreshLocale();
  562. void extraSpelling();
  563. void spellCheckerReady();
  564. void spellCheckerMisspelling( const TQString &, const TQStringList &, unsigned int);
  565. void spellCheckerCorrected( const TQString &, const TQString &, unsigned int);
  566. void spellCheckerDone( const TQString & );
  567. void spellCheckerFinished( );
  568. void spellCheckerIgnoreAll( const TQString & word);
  569. void spellCheckerReplaceAll( const TQString &, const TQString &);
  570. void startKSpell();
  571. /**
  572. * Updates the view and the action. This is typically connected
  573. * to KoCommandHistory::commandExecuted() signal.
  574. */
  575. void commandExecuted();
  576. virtual int leftBorder() const;
  577. virtual int rightBorder() const;
  578. virtual int topBorder() const;
  579. virtual int bottomBorder() const;
  580. protected:
  581. virtual void keyPressEvent ( TQKeyEvent * _ev );
  582. virtual void resizeEvent( TQResizeEvent *_ev );
  583. virtual TQWMatrix matrix() const;
  584. /**
  585. * Returns the position of the top-left point of the currently selected cell in document coordinates.
  586. * This is used when inserting some types of objects or pasting images into the document (so that the newly
  587. * pasted object's top-left point will be aligned with the top-left point of the currently selected cell)
  588. *
  589. */
  590. KoPoint markerDocumentPosition();
  591. /**
  592. * Activates the formula editor for the current cell.
  593. * This function is usually called if the user presses
  594. * a button in the formula toolbar.
  595. */
  596. void activateFormulaEditor();
  597. virtual void updateReadWrite( bool readwrite );
  598. virtual void guiActivateEvent( KParts::GUIActivateEvent *ev );
  599. void initFindReplace();
  600. Cell* findNextCell();
  601. private:
  602. class Private;
  603. Private* d;
  604. // don't allow copy or assignment
  605. View( const View& );
  606. View& operator=( const View& );
  607. void initView();
  608. bool spellSwitchToOtherSheet();
  609. void spellCleanup();
  610. /**
  611. * @return @c true if document is being loaded. It is useful to supress scrolling
  612. * while the "View loading" process.
  613. */
  614. bool isLoading() const;
  615. Cell* nextFindValidCell( int col, int row );
  616. friend class Private;
  617. };
  618. } // namespace KSpread
  619. #endif // KSPREAD_VIEW