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.

7546 lines
226KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2005-2006 Raphael Langerhorst <raphael.langerhorst@kdemail.net>
  3. (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
  4. (C) 2002-2005 Ariya Hidayat <ariya@kde.org>
  5. (C) 1999-2003 Laurent Montel <montel@kde.org>
  6. (C) 2002-2003 Norbert Andres <nandres@web.de>
  7. (C) 2002-2003 Philipp Mueller <philipp.mueller@gmx.de>
  8. (C) 2002-2003 John Dailey <dailey@vt.edu>
  9. (C) 1999-2003 David Faure <faure@kde.org>
  10. (C) 1999-2001 Simon Hausmann <hausmann@kde.org>
  11. (C) 1998-2000 Torben Weis <weis@kde.org>
  12. This library is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU Library General Public
  14. License as published by the Free Software Foundation; either
  15. version 2 of the License, or (at your option) any later version.
  16. This library is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. Library General Public License for more details.
  20. You should have received a copy of the GNU Library General Public License
  21. along with this library; see the file COPYING.LIB. If not, write to
  22. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301, USA.
  24. */
  25. #include <kprinter.h> // has to be first
  26. // standard C/C++ includes
  27. #include <assert.h>
  28. #include <stdlib.h>
  29. #include <time.h>
  30. // TQt includes
  31. #include <tqbuffer.h>
  32. #include <tqclipboard.h>
  33. #include <tqcursor.h>
  34. #include <tqlayout.h>
  35. #include <tqpaintdevicemetrics.h>
  36. #include <tqregexp.h>
  37. #include <tqtimer.h>
  38. #include <tqtoolbutton.h>
  39. #include <tqsqldatabase.h>
  40. #include <tqlistview.h>
  41. #include <tqsizepolicy.h>
  42. // KDE includes
  43. #include <dcopclient.h>
  44. #include <dcopref.h>
  45. #include <tdeapplication.h>
  46. #include <tdeconfig.h>
  47. #include <kdebug.h>
  48. #include <kfind.h>
  49. #include <kfinddialog.h>
  50. #include <tdefontdialog.h>
  51. #include <kinputdialog.h>
  52. #include <tdemessagebox.h>
  53. #include <knotifyclient.h>
  54. #include <kpassdlg.h>
  55. #include <kprocio.h>
  56. #include <kreplace.h>
  57. #include <kreplacedialog.h>
  58. #include <tdespell.h>
  59. #include <tdespelldlg.h>
  60. #include <kstatusbar.h>
  61. #include <kstdaction.h>
  62. #include <kstandarddirs.h>
  63. #include <tdetempfile.h>
  64. #include <tdeparts/partmanager.h>
  65. #include <tdelistview.h>
  66. #include <kpushbutton.h>
  67. // KOffice includes
  68. #include <tkcoloractions.h>
  69. #include <kdatatool.h>
  70. #include <KoCharSelectDia.h>
  71. #include <KoCommandHistory.h>
  72. #include <KoMainWindow.h>
  73. #include <KoOasisLoadingContext.h>
  74. #include <KoOasisStore.h>
  75. #include <KoOasisStyles.h>
  76. #include <KoPartSelectAction.h>
  77. #include <KoStoreDrag.h>
  78. #include <KoTabBar.h>
  79. #include <kspread_toolbox.h>
  80. #include <KoTemplateCreateDia.h>
  81. #include <KoZoomAction.h>
  82. // KSpread includes
  83. #include "commands.h"
  84. #include "damages.h"
  85. #include "digest.h"
  86. #include "inspector.h"
  87. #include "ksploadinginfo.h"
  88. #include "kspread_canvas.h"
  89. #include "kspread_editors.h"
  90. #include "kspread_events.h"
  91. #include "kspread_global.h"
  92. #include "kspread_handler.h"
  93. #include "kspread_locale.h"
  94. #include "kspread_map.h"
  95. #include "selection.h"
  96. #include "kspread_sheetprint.h"
  97. #include "kspread_style.h"
  98. #include "kspread_style_manager.h"
  99. #include "kspread_undo.h"
  100. #include "testrunner.h"
  101. #include "valuecalc.h"
  102. #include "valueconverter.h"
  103. // dialogs
  104. #include "dialogs/kspread_dlg_angle.h"
  105. #include "dialogs/kspread_dlg_area.h"
  106. #include "dialogs/kspread_dlg_comment.h"
  107. #include "dialogs/kspread_dlg_conditional.h"
  108. #include "dialogs/kspread_dlg_cons.h"
  109. #include "dialogs/kspread_dlg_csv.h"
  110. #include "dialogs/kspread_dlg_database.h"
  111. #include "dialogs/kspread_dlg_format.h"
  112. #include "dialogs/kspread_dlg_formula.h"
  113. #include "dialogs/kspread_dlg_goalseek.h"
  114. #include "dialogs/kspread_dlg_goto.h"
  115. #include "dialogs/kspread_dlg_insert.h"
  116. #include "dialogs/kspread_dlg_layout.h"
  117. #include "dialogs/kspread_dlg_list.h"
  118. //#include "dialogs/kspread_dlg_multipleop.h"
  119. #include "dialogs/kspread_dlg_paperlayout.h"
  120. #include "dialogs/kspread_dlg_pasteinsert.h"
  121. #include "dialogs/kspread_dlg_preference.h"
  122. #include "dialogs/kspread_dlg_reference.h"
  123. #include "dialogs/kspread_dlg_resize2.h"
  124. #include "dialogs/kspread_dlg_series.h"
  125. #include "dialogs/kspread_dlg_show.h"
  126. #include "dialogs/kspread_dlg_showColRow.h"
  127. #include "dialogs/kspread_dlg_sort.h"
  128. #include "dialogs/kspread_dlg_special.h"
  129. #include "dialogs/kspread_dlg_styles.h"
  130. #include "dialogs/kspread_dlg_subtotal.h"
  131. #include "dialogs/kspread_dlg_validity.h"
  132. #include "dialogs/link.h"
  133. #include "dialogs/sheet_properties.h"
  134. #include "dialogs/kspread_dlg_find.h"
  135. #include "dialogs/SheetSelectWidget.h"
  136. #include "kspread_propertyEditor.h"
  137. #include "kspread_generalProperty.h"
  138. // KSpread DCOP
  139. #include "KSpreadViewIface.h"
  140. #include "kspread_view.h"
  141. namespace KSpread
  142. {
  143. class ViewActions;
  144. class View::Private
  145. {
  146. public:
  147. View* view;
  148. Doc* doc;
  149. DCOPObject* dcop;
  150. // the active sheet, may be 0
  151. // this is the sheet which has the input focus
  152. Sheet* activeSheet;
  153. // GUI elements
  154. TQWidget *frame;
  155. TQFrame *toolWidget;
  156. Canvas *canvas;
  157. VBorder *vBorderWidget;
  158. HBorder *hBorderWidget;
  159. TQScrollBar *horzScrollBar;
  160. TQScrollBar *vertScrollBar;
  161. KoTabBar *tabBar;
  162. KStatusBarLabel* calcLabel;
  163. // formulabar, consists of:
  164. TQHBoxLayout* formulaBarLayout;
  165. ComboboxLocationEditWidget *posWidget;
  166. TQButton* formulaButton;
  167. TQButton *okButton;
  168. TQButton *cancelButton;
  169. KSpread::EditWidget *editWidget;
  170. TQGridLayout* viewLayout;
  171. TQHBoxLayout* tabScrollBarLayout;
  172. // all UI actions
  173. ViewActions* actions;
  174. // If updateEditWidget is called it changes some TDEToggleActions.
  175. // That causes them to emit a signal. If this lock is true, then these
  176. // signals are ignored.
  177. bool toolbarLock;
  178. // if true, kspread is still loading the document
  179. // don't try to refresh the view
  180. bool loading;
  181. // selection/marker
  182. Selection* selection;
  183. Selection* choice;
  184. TQMap<Sheet*, TQPoint> savedAnchors;
  185. TQMap<Sheet*, TQPoint> savedMarkers;
  186. TQMap<Sheet*, KoPoint> savedOffsets;
  187. // Find and Replace context. We remember the options and
  188. // the strings used previously.
  189. long findOptions;
  190. TQStringList findStrings;
  191. TQStringList replaceStrings;
  192. FindOption::searchTypeValue typeValue;
  193. FindOption::searchDirectionValue directionValue;
  194. // Current "find" operation
  195. KFind* find;
  196. KReplace* replace;
  197. int findLeftColumn;
  198. int findRightColumn;
  199. TQPoint findPos;
  200. TQPoint findEnd;
  201. InsertHandler* insertHandler;
  202. // Insert special character dialog
  203. KoCharSelectDia* specialCharDlg;
  204. // Holds a guarded pointer to the transformation toolbox.
  205. TQGuardedPtr<KoTransformToolBox> transformToolBox;
  206. // the last popup menu (may be 0).
  207. // Since only one popup menu can be opened at once, its pointer is stored here.
  208. // Delete the old one before you store a pointer to anotheron here.
  209. TQPopupMenu *popupMenu;
  210. int popupMenuFirstToolId;
  211. TQPopupMenu *popupRow;
  212. TQPopupMenu *popupColumn;
  213. TQPopupMenu* popupChild; // for embedded children
  214. TQPopupMenu* popupListChoose; // for list of choose
  215. // the child for which the popup menu has been opened.
  216. Child* popupChildObject;
  217. // spell-check context
  218. struct
  219. {
  220. KSpell * tdespell;
  221. Sheet * firstSpellSheet;
  222. Sheet * currentSpellSheet;
  223. Cell * currentCell;
  224. MacroUndoAction *macroCmdSpellCheck;
  225. unsigned int spellCurrCellX;
  226. unsigned int spellCurrCellY;
  227. unsigned int spellStartCellX;
  228. unsigned int spellStartCellY;
  229. unsigned int spellEndCellX;
  230. unsigned int spellEndCellY;
  231. bool spellCheckSelection;
  232. TQStringList replaceAll;
  233. } spell;
  234. struct
  235. {
  236. Sheet * currentSheet;
  237. Sheet * firstSheet;
  238. } searchInSheets;
  239. // the tools
  240. struct ToolEntry
  241. {
  242. TQString command;
  243. KDataToolInfo info;
  244. };
  245. TQPtrList<ToolEntry> toolList;
  246. void initActions();
  247. void adjustActions( bool mode );
  248. void adjustActions( Sheet* sheet, Cell* cell );
  249. void adjustWorkbookActions( bool mode );
  250. void updateButton( Cell *cell, int column, int row);
  251. TQButton* newIconButton( const char *_file, bool _kbutton = false, TQWidget *_parent = 0L );
  252. PropertyEditor *m_propertyEditor;
  253. // On timeout this will execute the status bar operation (e.g. SUM).
  254. // This is delayed to speed up the selection.
  255. TQTimer statusBarOpTimer;
  256. };
  257. class ViewActions
  258. {
  259. public:
  260. // cell formatting
  261. TDEAction* cellLayout;
  262. TDEAction *actionExtraProperties;
  263. TDEAction* defaultFormat;
  264. TDEToggleAction* bold;
  265. TDEToggleAction* italic;
  266. TDEToggleAction* underline;
  267. TDEToggleAction* strikeOut;
  268. TDEFontAction* selectFont;
  269. TDEFontSizeAction* selectFontSize;
  270. TDEAction* fontSizeUp;
  271. TDEAction* fontSizeDown;
  272. TTDESelectColorAction* textColor;
  273. TDEToggleAction* alignLeft;
  274. TDEToggleAction* alignCenter;
  275. TDEToggleAction* alignRight;
  276. TDEToggleAction* alignTop;
  277. TDEToggleAction* alignMiddle;
  278. TDEToggleAction* alignBottom;
  279. TDEToggleAction* wrapText;
  280. TDEToggleAction* verticalText;
  281. TDEAction* increaseIndent;
  282. TDEAction* decreaseIndent;
  283. TDEAction* changeAngle;
  284. TDEToggleAction* percent;
  285. TDEAction* precplus;
  286. TDEAction* precminus;
  287. TDEToggleAction* money;
  288. TDEAction* upper;
  289. TDEAction* lower;
  290. TDEAction* firstLetterUpper;
  291. TTDESelectColorAction* bgColor;
  292. TDEAction* borderLeft;
  293. TDEAction* borderRight;
  294. TDEAction* borderTop;
  295. TDEAction* borderBottom;
  296. TDEAction* borderAll;
  297. TDEAction* borderOutline;
  298. TDEAction* borderRemove;
  299. TTDESelectColorAction* borderColor;
  300. TDESelectAction* selectStyle;
  301. TDEAction* createStyle;
  302. // cell operations
  303. TDEAction* editCell;
  304. TDEAction* insertCell;
  305. TDEAction* removeCell;
  306. TDEAction* deleteCell;
  307. TDEToolBarPopupAction* mergeCell;
  308. TDEAction* mergeCellHorizontal;
  309. TDEAction* mergeCellVertical;
  310. TDEAction* dissociateCell;
  311. TDEAction* clearText;
  312. TDEAction* conditional;
  313. TDEAction* clearConditional;
  314. TDEAction* validity;
  315. TDEAction* clearValidity;
  316. TDEAction* addModifyComment;
  317. TDEAction* removeComment;
  318. TDEAction* clearComment;
  319. // column & row operations
  320. TDEAction* resizeColumn;
  321. TDEAction* insertColumn;
  322. TDEAction* deleteColumn;
  323. TDEAction* hideColumn;
  324. TDEAction* showColumn;
  325. TDEAction* equalizeColumn;
  326. TDEAction* showSelColumns;
  327. TDEAction* resizeRow;
  328. TDEAction* insertRow;
  329. TDEAction* deleteRow;
  330. TDEAction* hideRow;
  331. TDEAction* showRow;
  332. TDEAction* equalizeRow;
  333. TDEAction* showSelRows;
  334. TDEAction* adjust;
  335. // sheet/workbook operations
  336. TDEAction* sheetProperties;
  337. TDEAction* insertSheet;
  338. TDEAction* menuInsertSheet;
  339. TDEAction* removeSheet;
  340. TDEAction* renameSheet;
  341. TDEAction* hideSheet;
  342. TDEAction* showSheet;
  343. TDEAction* autoFormat;
  344. TDEAction* areaName;
  345. TDEAction* showArea;
  346. TDEAction* insertSeries;
  347. TDEAction* insertFunction;
  348. TDEAction* insertSpecialChar;
  349. TDEAction* insertFromDatabase;
  350. TDEAction* insertFromTextfile;
  351. TDEAction* insertFromClipboard;
  352. TDEAction* transform;
  353. TDEAction* sort;
  354. TDEAction* sortDec;
  355. TDEAction* sortInc;
  356. TDEAction* fillRight;
  357. TDEAction* fillLeft;
  358. TDEAction* fillUp;
  359. TDEAction* fillDown;
  360. TDEAction* paperLayout;
  361. TDEAction* definePrintRange;
  362. TDEAction* resetPrintRange;
  363. TDEToggleAction* showPageBorders;
  364. TDEAction* recalcWorksheet;
  365. TDEAction* recalcWorkbook;
  366. TDEToggleAction* protectSheet;
  367. TDEToggleAction* protectDoc;
  368. // general editing
  369. TDEAction* cut;
  370. TDEAction* copy;
  371. TDEAction* paste;
  372. TDEAction* specialPaste;
  373. TDEAction* insertCellCopy;
  374. TDEAction* find;
  375. TDEAction* replace;
  376. // navigation
  377. TDEAction* gotoCell;
  378. TDEAction* nextSheet;
  379. TDEAction* prevSheet;
  380. TDEAction* firstSheet;
  381. TDEAction* lastSheet;
  382. // misc
  383. TDEAction* styleDialog;
  384. TDEAction* autoSum;
  385. TDESelectAction* formulaSelection;
  386. TDEAction* insertLink;
  387. TDEAction* removeLink;
  388. TDEAction* consolidate;
  389. TDEAction* goalSeek;
  390. TDEAction* subTotals;
  391. TDEAction* textToColumns;
  392. TDEAction* multipleOperations;
  393. TDEAction* createTemplate;
  394. KoPartSelectAction *insertPart;
  395. TDEToggleAction* insertChartFrame;
  396. TDEAction* insertPicture;
  397. TDEAction* customList;
  398. TDEAction* spellChecking;
  399. TDEAction* internalTests;
  400. TDEAction* inspector;
  401. // settings
  402. KoZoomAction* viewZoom;
  403. TDEToggleAction* showStatusBar;
  404. TDEToggleAction* showTabBar;
  405. TDEToggleAction* showFormulaBar;
  406. TDEAction* preference;
  407. // running calculation
  408. TDEToggleAction* calcNone;
  409. TDEToggleAction* calcMin;
  410. TDEToggleAction* calcMax;
  411. TDEToggleAction* calcAverage;
  412. TDEToggleAction* calcCount;
  413. TDEToggleAction* calcSum;
  414. TDEToggleAction* calcCountA;
  415. };
  416. void View::Private::initActions()
  417. {
  418. actions = new ViewActions;
  419. TDEActionCollection* ac = view->actionCollection();
  420. // -- cell formatting actions --
  421. actions->cellLayout = new TDEAction( i18n("Cell Format..."), "cell_layout",
  422. TQt::CTRL+ TQt::ALT+ TQt::Key_F, TQT_TQOBJECT(view), TQT_SLOT( layoutDlg() ), ac, "cellLayout" );
  423. actions->cellLayout->setToolTip( i18n("Set the cell formatting.") );
  424. actions->actionExtraProperties = new TDEAction( i18n( "&Properties" ), "penbrush", 0,
  425. TQT_TQOBJECT(view), TQT_SLOT( extraProperties() ), ac, "extra_properties" );
  426. actions->defaultFormat = new TDEAction( i18n("Default"),
  427. 0, TQT_TQOBJECT(view), TQT_SLOT( defaultSelection() ), ac, "default" );
  428. actions->defaultFormat->setToolTip( i18n("Resets to the default format.") );
  429. actions->bold = new TDEToggleAction( i18n("Bold"), "format-text-bold",
  430. TQt::CTRL+TQt::Key_B, ac, "bold");
  431. TQT_BASE_OBJECT_NAME::connect( actions->bold, TQT_SIGNAL( toggled( bool) ),
  432. TQT_TQOBJECT(view), TQT_SLOT( bold( bool ) ) );
  433. actions->italic = new TDEToggleAction( i18n("Italic"), "format-text-italic",
  434. TQt::CTRL+TQt::Key_I, ac, "italic");
  435. TQT_BASE_OBJECT_NAME::connect( actions->italic, TQT_SIGNAL( toggled( bool) ),
  436. TQT_TQOBJECT(view), TQT_SLOT( italic( bool ) ) );
  437. actions->underline = new TDEToggleAction( i18n("Underline"), "format-text-underline",
  438. TQt::CTRL+TQt::Key_U, ac, "underline");
  439. TQT_BASE_OBJECT_NAME::connect( actions->underline, TQT_SIGNAL( toggled( bool) ),
  440. TQT_TQOBJECT(view), TQT_SLOT( underline( bool ) ) );
  441. actions->strikeOut = new TDEToggleAction( i18n("Strike Out"), "format-text-strikethrough",
  442. 0, ac, "strikeout");
  443. TQT_BASE_OBJECT_NAME::connect( actions->strikeOut, TQT_SIGNAL( toggled( bool) ),
  444. TQT_TQOBJECT(view), TQT_SLOT( strikeOut( bool ) ) );
  445. actions->selectFont = new TDEFontAction( i18n("Select Font..."),
  446. 0, ac, "selectFont" );
  447. TQT_BASE_OBJECT_NAME::connect( actions->selectFont, TQT_SIGNAL( activated( const TQString& ) ),
  448. TQT_TQOBJECT(view), TQT_SLOT( fontSelected( const TQString& ) ) );
  449. actions->selectFontSize = new TDEFontSizeAction( i18n("Select Font Size"),
  450. 0, ac, "selectFontSize" );
  451. TQT_BASE_OBJECT_NAME::connect( actions->selectFontSize, TQT_SIGNAL( fontSizeChanged( int ) ),
  452. TQT_TQOBJECT(view), TQT_SLOT( fontSizeSelected( int ) ) );
  453. actions->fontSizeUp = new TDEAction( i18n("Increase Font Size"), "fontsizeup",
  454. 0, TQT_TQOBJECT(view), TQT_SLOT( increaseFontSize() ), ac, "increaseFontSize" );
  455. actions->fontSizeDown = new TDEAction( i18n("Decrease Font Size"), "fontsizedown",
  456. 0, TQT_TQOBJECT(view), TQT_SLOT( decreaseFontSize() ), ac, "decreaseFontSize" );
  457. actions->textColor = new TTDESelectColorAction( i18n("Text Color"),
  458. TTDESelectColorAction::TextColor, TQT_TQOBJECT(view), TQT_SLOT( changeTextColor() ),
  459. ac, "textColor",true );
  460. actions->textColor->setDefaultColor(TQColor());
  461. actions->alignLeft = new TDEToggleAction( i18n("Align Left"), "format-text-direction-ltr",
  462. 0, ac, "left");
  463. TQT_BASE_OBJECT_NAME::connect( actions->alignLeft, TQT_SIGNAL( toggled( bool ) ),
  464. TQT_TQOBJECT(view), TQT_SLOT( alignLeft( bool ) ) );
  465. actions->alignLeft->setExclusiveGroup( "Align" );
  466. actions->alignLeft->setToolTip(i18n("Left justify the cell contents."));
  467. actions->alignCenter = new TDEToggleAction( i18n("Align Center"), "text_center",
  468. 0, ac, "center");
  469. TQT_BASE_OBJECT_NAME::connect( actions->alignCenter, TQT_SIGNAL( toggled( bool ) ),
  470. TQT_TQOBJECT(view), TQT_SLOT( alignCenter( bool ) ) );
  471. actions->alignCenter->setExclusiveGroup( "Align" );
  472. actions->alignCenter->setToolTip(i18n("Center the cell contents."));
  473. actions->alignRight = new TDEToggleAction( i18n("Align Right"), "format-text-direction-rtl",
  474. 0, ac, "right");
  475. TQT_BASE_OBJECT_NAME::connect( actions->alignRight, TQT_SIGNAL( toggled( bool ) ),
  476. TQT_TQOBJECT(view), TQT_SLOT( alignRight( bool ) ) );
  477. actions->alignRight->setExclusiveGroup( "Align" );
  478. actions->alignRight->setToolTip(i18n("Right justify the cell contents."));
  479. actions->alignTop = new TDEToggleAction( i18n("Align Top"), "text_top",
  480. 0, ac, "top");
  481. TQT_BASE_OBJECT_NAME::connect( actions->alignTop, TQT_SIGNAL( toggled( bool ) ),
  482. TQT_TQOBJECT(view), TQT_SLOT( alignTop( bool ) ) );
  483. actions->alignTop->setExclusiveGroup( "Pos" );
  484. actions->alignTop->setToolTip(i18n("Align cell contents along the top of the cell."));
  485. actions->alignMiddle = new TDEToggleAction( i18n("Align Middle"), "middle",
  486. 0, ac, "middle");
  487. TQT_BASE_OBJECT_NAME::connect( actions->alignMiddle, TQT_SIGNAL( toggled( bool ) ),
  488. TQT_TQOBJECT(view), TQT_SLOT( alignMiddle( bool ) ) );
  489. actions->alignMiddle->setExclusiveGroup( "Pos" );
  490. actions->alignMiddle->setToolTip(i18n("Align cell contents centered in the cell."));
  491. actions->alignBottom = new TDEToggleAction( i18n("Align Bottom"), "text_bottom",
  492. 0, ac, "bottom");
  493. TQT_BASE_OBJECT_NAME::connect( actions->alignBottom, TQT_SIGNAL( toggled( bool ) ),
  494. TQT_TQOBJECT(view), TQT_SLOT( alignBottom( bool ) ) );
  495. actions->alignBottom->setExclusiveGroup( "Pos" );
  496. actions->alignBottom->setToolTip(i18n("Align cell contents along the bottom of the cell."));
  497. actions->wrapText = new TDEToggleAction( i18n("Wrap Text"), "multirow",
  498. 0, ac, "multiRow" );
  499. TQT_BASE_OBJECT_NAME::connect( actions->wrapText, TQT_SIGNAL( toggled( bool ) ),
  500. TQT_TQOBJECT(view), TQT_SLOT( wrapText( bool ) ) );
  501. actions->wrapText->setToolTip(i18n("Make the cell text wrap onto multiple lines."));
  502. actions->verticalText = new TDEToggleAction( i18n("Vertical Text"),"vertical_text" ,
  503. 0 ,ac, "verticaltext" );
  504. TQT_BASE_OBJECT_NAME::connect( actions->verticalText, TQT_SIGNAL( toggled( bool ) ),
  505. TQT_TQOBJECT(view), TQT_SLOT( verticalText( bool ) ) );
  506. actions->verticalText->setToolTip(i18n("Print cell contents vertically."));
  507. actions->increaseIndent = new TDEAction( i18n("Increase Indent"),
  508. TQApplication::reverseLayout() ? "format_decreaseindent":"format_increaseindent",
  509. 0, TQT_TQOBJECT(view), TQT_SLOT( increaseIndent() ), ac, "increaseindent" );
  510. actions->increaseIndent->setToolTip(i18n("Increase the indentation."));
  511. actions->decreaseIndent = new TDEAction( i18n("Decrease Indent"),
  512. TQApplication::reverseLayout() ? "format_increaseindent" : "format_decreaseindent",
  513. 0, TQT_TQOBJECT(view), TQT_SLOT( decreaseIndent() ), ac, "decreaseindent");
  514. actions->decreaseIndent->setToolTip(i18n("Decrease the indentation."));
  515. actions->changeAngle = new TDEAction( i18n("Change Angle..."),
  516. 0, TQT_TQOBJECT(view), TQT_SLOT( changeAngle() ), ac, "changeangle" );
  517. actions->changeAngle->setToolTip(i18n("Change the angle that cell contents are printed."));
  518. actions->percent = new TDEToggleAction( i18n("Percent Format"), "percent",
  519. 0, ac, "percent");
  520. TQT_BASE_OBJECT_NAME::connect( actions->percent, TQT_SIGNAL( toggled( bool ) ),
  521. TQT_TQOBJECT(view), TQT_SLOT( percent( bool ) ) );
  522. actions->percent->setToolTip(i18n("Set the cell formatting to look like a percentage."));
  523. actions->precplus = new TDEAction( i18n("Increase Precision"), "prec_plus",
  524. 0, TQT_TQOBJECT(view), TQT_SLOT( precisionPlus() ), ac, "precplus");
  525. actions->precplus->setToolTip(i18n("Increase the decimal precision shown onscreen."));
  526. actions->precminus = new TDEAction( i18n("Decrease Precision"), "prec_minus",
  527. 0, TQT_TQOBJECT(view), TQT_SLOT( precisionMinus() ), ac, "precminus");
  528. actions->precminus->setToolTip(i18n("Decrease the decimal precision shown onscreen."));
  529. actions->money = new TDEToggleAction( i18n("Money Format"), "money",
  530. 0, ac, "money");
  531. TQT_BASE_OBJECT_NAME::connect( actions->money, TQT_SIGNAL( toggled( bool ) ),
  532. TQT_TQOBJECT(view), TQT_SLOT( moneyFormat( bool ) ) );
  533. actions->money->setToolTip(i18n("Set the cell formatting to look like your local currency."));
  534. actions->upper = new TDEAction( i18n("Upper Case"), "fontsizeup",
  535. 0, TQT_TQOBJECT(view), TQT_SLOT( upper() ), ac, "upper" );
  536. actions->upper->setToolTip(i18n("Convert all letters to upper case."));
  537. actions->lower = new TDEAction( i18n("Lower Case"), "fontsizedown",
  538. 0, TQT_TQOBJECT(view), TQT_SLOT( lower() ), ac, "lower" );
  539. actions->lower->setToolTip(i18n("Convert all letters to lower case."));
  540. actions->firstLetterUpper = new TDEAction( i18n("Convert First Letter to Upper Case"), "first_letter_upper",
  541. 0, TQT_TQOBJECT(view), TQT_SLOT( firstLetterUpper() ),ac, "firstletterupper" );
  542. actions->firstLetterUpper->setToolTip(i18n("Capitalize the first letter."));
  543. actions->bgColor = new TTDESelectColorAction( i18n("Background Color"),
  544. TTDESelectColorAction::FillColor, ac, "backgroundColor", true );
  545. TQT_BASE_OBJECT_NAME::connect(actions->bgColor, TQT_SIGNAL( activated() ),
  546. TQT_TQOBJECT(view), TQT_SLOT( changeBackgroundColor() ) );
  547. actions->bgColor->setDefaultColor(TQColor());
  548. actions->bgColor->setToolTip(i18n("Set the background color."));
  549. actions->borderLeft = new TDEAction( i18n("Border Left"), "border_left",
  550. 0, TQT_TQOBJECT(view), TQT_SLOT( borderLeft() ), ac, "borderLeft" );
  551. actions->borderLeft->setToolTip(i18n("Set a left border to the selected area."));
  552. actions->borderRight = new TDEAction( i18n("Border Right"), "border_right",
  553. 0, TQT_TQOBJECT(view), TQT_SLOT( borderRight() ), ac, "borderRight" );
  554. actions->borderRight->setToolTip(i18n("Set a right border to the selected area."));
  555. actions->borderTop = new TDEAction( i18n("Border Top"), "border_top",
  556. 0, TQT_TQOBJECT(view), TQT_SLOT( borderTop() ), ac, "borderTop" );
  557. actions->borderTop->setToolTip(i18n("Set a top border to the selected area."));
  558. actions->borderBottom = new TDEAction( i18n("Border Bottom"), "border_bottom",
  559. 0, TQT_TQOBJECT(view), TQT_SLOT( borderBottom() ), ac, "borderBottom" );
  560. actions->borderBottom->setToolTip(i18n("Set a bottom border to the selected area."));
  561. actions->borderAll = new TDEAction( i18n("All Borders"), "border_all",
  562. 0, TQT_TQOBJECT(view), TQT_SLOT( borderAll() ), ac, "borderAll" );
  563. actions->borderAll->setToolTip(i18n("Set a border around all cells in the selected area."));
  564. actions->borderRemove = new TDEAction( i18n("Remove Borders"), "border_remove",
  565. 0, TQT_TQOBJECT(view), TQT_SLOT( borderRemove() ), ac, "borderRemove" );
  566. actions->borderRemove->setToolTip(i18n("Remove all borders in the selected area."));
  567. actions->borderOutline = new TDEAction( i18n("Border Outline"), ("border_outline"),
  568. 0, TQT_TQOBJECT(view), TQT_SLOT( borderOutline() ), ac, "borderOutline" );
  569. actions->borderOutline->setToolTip(i18n("Set a border to the outline of the selected area."));
  570. actions->borderColor = new TTDESelectColorAction( i18n("Border Color"),
  571. TTDESelectColorAction::LineColor, ac, "borderColor" );
  572. TQT_BASE_OBJECT_NAME::connect( actions->borderColor, TQT_SIGNAL( activated() ),
  573. TQT_TQOBJECT(view), TQT_SLOT( changeBorderColor() ) );
  574. actions->borderColor->setToolTip( i18n( "Select a new border color." ) );
  575. actions->selectStyle = new TDESelectAction( i18n( "St&yle" ),
  576. 0, ac, "stylemenu" );
  577. actions->selectStyle->setToolTip( i18n( "Apply a predefined style to the selected cells." ) );
  578. TQT_BASE_OBJECT_NAME::connect( actions->selectStyle, TQT_SIGNAL( activated( const TQString & ) ),
  579. TQT_TQOBJECT(view), TQT_SLOT( styleSelected( const TQString & ) ) );
  580. actions->createStyle = new TDEAction( i18n( "Create Style From Cell..." ),
  581. 0, TQT_TQOBJECT(view), TQT_SLOT( createStyleFromCell()), ac, "createStyle" );
  582. actions->createStyle->setToolTip( i18n( "Create a new style based on the currently selected cell." ) );
  583. // -- cell operation actions --
  584. actions->editCell = new TDEAction( i18n("Modify Cell"),"cell_edit",
  585. TQt::CTRL+TQt::Key_M, TQT_TQOBJECT(view), TQT_SLOT( editCell() ), ac, "editCell" );
  586. actions->editCell->setToolTip(i18n("Edit the highlighted cell."));
  587. actions->insertCell = new TDEAction( i18n("Insert Cells..."), "insertcell",
  588. 0, TQT_TQOBJECT(view), TQT_SLOT( slotInsert() ), ac, "insertCell" );
  589. actions->insertCell->setToolTip(i18n("Insert a blank cell into the spreadsheet."));
  590. actions->removeCell = new TDEAction( i18n("Remove Cells..."), "removecell",
  591. 0, TQT_TQOBJECT(view), TQT_SLOT( slotRemove() ), ac, "removeCell" );
  592. actions->removeCell->setToolTip(i18n("Removes the current cell from the spreadsheet."));
  593. actions->deleteCell = new TDEAction( i18n("Delete"), "deletecell",
  594. 0, TQT_TQOBJECT(view), TQT_SLOT( deleteSelection() ), ac, "delete" );
  595. actions->deleteCell->setToolTip(i18n("Delete all contents and formatting of the current cell."));
  596. actions->mergeCell = new TDEToolBarPopupAction( i18n("Merge Cells"),"mergecell",
  597. 0, TQT_TQOBJECT(view), TQT_SLOT( mergeCell() ), ac, "mergecell" );
  598. actions->mergeCell->setToolTip(i18n("Merge the selected region."));
  599. actions->mergeCell->plug( actions->mergeCell->popupMenu() );
  600. actions->mergeCellHorizontal = new TDEAction( i18n("Merge Cells Horizontally"),"mergecell-horizontal",
  601. 0, TQT_TQOBJECT(view), TQT_SLOT( mergeCellHorizontal() ), ac, "mergecellHorizontal" );
  602. actions->mergeCellHorizontal->setToolTip(i18n("Merge the selected region horizontally."));
  603. actions->mergeCellHorizontal->plug( actions->mergeCell->popupMenu() );
  604. actions->mergeCellVertical = new TDEAction( i18n("Merge Cells Vertically"),"mergecell-vertical",
  605. 0, TQT_TQOBJECT(view), TQT_SLOT( mergeCellVertical() ), ac, "mergecellVertical" );
  606. actions->mergeCellVertical->setToolTip(i18n("Merge the selected region vertically."));
  607. actions->mergeCellVertical->plug( actions->mergeCell->popupMenu() );
  608. actions->dissociateCell = new TDEAction( i18n("Dissociate Cells"),"dissociatecell",
  609. 0, TQT_TQOBJECT(view), TQT_SLOT( dissociateCell() ), ac, "dissociatecell" );
  610. actions->dissociateCell->setToolTip(i18n("Unmerge the selected region."));
  611. actions->clearText = new TDEAction( i18n("Text"),
  612. 0, TQT_TQOBJECT(view), TQT_SLOT( clearTextSelection() ), ac, "cleartext" );
  613. actions->clearText->setToolTip(i18n("Remove the contents of the current cell."));
  614. actions->conditional = new TDEAction( i18n("Conditional Cell Attributes..."),
  615. 0, TQT_TQOBJECT(view), TQT_SLOT( conditional() ), ac, "conditional" );
  616. actions->conditional->setToolTip(i18n("Set cell format based on certain conditions."));
  617. actions->clearConditional = new TDEAction( i18n("Conditional Cell Attributes"),
  618. 0, TQT_TQOBJECT(view), TQT_SLOT( clearConditionalSelection() ), ac, "clearconditional" );
  619. actions->clearConditional->setToolTip(i18n("Remove the conditional cell formatting."));
  620. actions->validity = new TDEAction( i18n("Validity..."),
  621. 0, TQT_TQOBJECT(view), TQT_SLOT( validity() ), ac, "validity" );
  622. actions->validity->setToolTip(i18n("Set tests to confirm cell data is valid."));
  623. actions->clearValidity = new TDEAction( i18n("Validity"),
  624. 0, TQT_TQOBJECT(view), TQT_SLOT( clearValiditySelection() ), ac, "clearvalidity" );
  625. actions->clearValidity->setToolTip(i18n("Remove the validity tests on this cell."));
  626. actions->addModifyComment = new TDEAction( i18n("&Add/Modify Comment..."),"comment",
  627. 0, TQT_TQOBJECT(view), TQT_SLOT( addModifyComment() ), ac, "addmodifycomment" );
  628. actions->addModifyComment->setToolTip(i18n("Edit a comment for this cell."));
  629. actions->removeComment = new TDEAction( i18n("&Remove Comment"),"removecomment",
  630. 0, TQT_TQOBJECT(view), TQT_SLOT( removeComment() ), ac, "removecomment" );
  631. actions->removeComment->setToolTip(i18n("Remove this cell's comment."));
  632. actions->clearComment = new TDEAction( i18n("Comment"),
  633. 0, TQT_TQOBJECT(view), TQT_SLOT( clearCommentSelection() ), ac, "clearcomment" );
  634. actions->clearComment->setToolTip(i18n("Remove this cell's comment."));
  635. // -- column & row actions --
  636. actions->resizeColumn = new TDEAction( i18n("Resize Column..."), "resizecol",
  637. 0, TQT_TQOBJECT(view), TQT_SLOT( resizeColumn() ), ac, "resizeCol" );
  638. actions->resizeColumn->setToolTip(i18n("Change the width of a column."));
  639. actions->insertColumn = new TDEAction( i18n("Insert Columns"), "insert_table_col",
  640. 0, TQT_TQOBJECT(view), TQT_SLOT( insertColumn() ), ac, "insertColumn" );
  641. actions->insertColumn->setToolTip(i18n("Inserts a new column into the spreadsheet."));
  642. actions->deleteColumn = new TDEAction( i18n("Delete Columns"), "delete_table_col",
  643. 0, TQT_TQOBJECT(view), TQT_SLOT( deleteColumn() ), ac, "deleteColumn" );
  644. actions->deleteColumn->setToolTip(i18n("Removes a column from the spreadsheet."));
  645. actions->hideColumn = new TDEAction( i18n("Hide Columns"), "hide_table_column",
  646. 0, TQT_TQOBJECT(view), TQT_SLOT( hideColumn() ), ac, "hideColumn" );
  647. actions->hideColumn->setToolTip(i18n("Hide the column from view."));
  648. actions->showColumn = new TDEAction( i18n("Show Columns..."), "show_table_column",
  649. 0, TQT_TQOBJECT(view), TQT_SLOT( showColumn() ), ac, "showColumn" );
  650. actions->showColumn->setToolTip(i18n("Show hidden columns."));
  651. actions->equalizeColumn = new TDEAction( i18n("Equalize Column"), "adjustcol",
  652. 0, TQT_TQOBJECT(view), TQT_SLOT( equalizeColumn() ), ac, "equalizeCol" );
  653. actions->equalizeColumn->setToolTip(i18n("Resizes selected columns to be the same size."));
  654. actions->showSelColumns = new TDEAction( i18n("Show Columns"), "show_sheet_column",
  655. 0, TQT_TQOBJECT(view), TQT_SLOT( showSelColumns() ), ac, "showSelColumns" );
  656. actions->showSelColumns->setToolTip(i18n("Show hidden columns in the selection."));
  657. actions->showSelColumns->setEnabled(false);
  658. actions->resizeRow = new TDEAction( i18n("Resize Row..."), "resizerow",
  659. 0, TQT_TQOBJECT(view), TQT_SLOT( resizeRow() ), ac, "resizeRow" );
  660. actions->resizeRow->setToolTip(i18n("Change the height of a row."));
  661. actions->insertRow = new TDEAction( i18n("Insert Rows"), "insert_table_row",
  662. 0, TQT_TQOBJECT(view), TQT_SLOT( insertRow() ), ac, "insertRow" );
  663. actions->insertRow->setToolTip(i18n("Inserts a new row into the spreadsheet."));
  664. actions->deleteRow = new TDEAction( i18n("Delete Rows"), "delete_table_row",
  665. 0, TQT_TQOBJECT(view), TQT_SLOT( deleteRow() ), ac, "deleteRow" );
  666. actions->deleteRow->setToolTip(i18n("Removes a row from the spreadsheet."));
  667. actions->hideRow = new TDEAction( i18n("Hide Rows"), "hide_table_row",
  668. 0, TQT_TQOBJECT(view), TQT_SLOT( hideRow() ), ac, "hideRow" );
  669. actions->hideRow->setToolTip(i18n("Hide a row from view."));
  670. actions->showRow = new TDEAction( i18n("Show Rows..."), "show_table_row",
  671. 0, TQT_TQOBJECT(view), TQT_SLOT( showRow() ), ac, "showRow" );
  672. actions->showRow->setToolTip(i18n("Show hidden rows."));
  673. actions->equalizeRow = new TDEAction( i18n("Equalize Row"), "adjustrow",
  674. 0, TQT_TQOBJECT(view), TQT_SLOT( equalizeRow() ), ac, "equalizeRow" );
  675. actions->equalizeRow->setToolTip(i18n("Resizes selected rows to be the same size."));
  676. actions->showSelRows = new TDEAction( i18n("Show Rows"), "show_table_row",
  677. 0, TQT_TQOBJECT(view), TQT_SLOT( showSelRows() ), ac, "showSelRows" );
  678. actions->showSelRows->setEnabled(false);
  679. actions->showSelRows->setToolTip(i18n("Show hidden rows in the selection."));
  680. actions->adjust = new TDEAction( i18n("Adjust Row && Column"),
  681. 0, TQT_TQOBJECT(view), TQT_SLOT( adjust() ), ac, "adjust" );
  682. actions->adjust->setToolTip(i18n("Adjusts row/column size so that the contents will fit."));
  683. // -- sheet/workbook actions --
  684. actions->sheetProperties = new TDEAction( i18n("Sheet Properties"),
  685. 0, TQT_TQOBJECT(view), TQT_SLOT( sheetProperties() ), ac, "sheetProperties" );
  686. actions->sheetProperties->setToolTip(i18n("Modify current sheet's properties."));
  687. actions->insertSheet = new TDEAction( i18n("Insert Sheet"),"inserttable",
  688. 0, TQT_TQOBJECT(view), TQT_SLOT( insertSheet() ), ac, "insertSheet" );
  689. actions->insertSheet->setToolTip(i18n("Insert a new sheet."));
  690. // same action as insertSheet, but without 'insert' in the caption
  691. actions->menuInsertSheet = new TDEAction( i18n("&Sheet"),"inserttable",
  692. 0, TQT_TQOBJECT(view), TQT_SLOT( insertSheet() ), ac, "menuInsertSheet" );
  693. actions->menuInsertSheet->setToolTip(i18n("Insert a new sheet."));
  694. actions->removeSheet = new TDEAction( i18n("Remove Sheet"), "delete_table",
  695. 0, TQT_TQOBJECT(view), TQT_SLOT( removeSheet() ), ac, "removeSheet" );
  696. actions->removeSheet->setToolTip(i18n("Remove the active sheet."));
  697. actions->renameSheet=new TDEAction( i18n("Rename Sheet..."),
  698. 0, TQT_TQOBJECT(view), TQT_SLOT( slotRename() ), ac, "renameSheet" );
  699. actions->renameSheet->setToolTip(i18n("Rename the active sheet."));
  700. actions->showSheet = new TDEAction(i18n("Show Sheet..."),
  701. 0, TQT_TQOBJECT(view), TQT_SLOT( showSheet()), ac, "showSheet" );
  702. actions->showSheet->setToolTip(i18n("Show a hidden sheet."));
  703. actions->hideSheet = new TDEAction(i18n("Hide Sheet"),
  704. 0, TQT_TQOBJECT(view), TQT_SLOT( hideSheet() ), ac, "hideSheet" );
  705. actions->hideSheet->setToolTip(i18n("Hide the active sheet."));
  706. actions->autoFormat = new TDEAction( i18n("AutoFormat..."),
  707. 0, TQT_TQOBJECT(view), TQT_SLOT( sheetFormat() ), ac, "sheetFormat" );
  708. actions->autoFormat->setToolTip(i18n("Set the worksheet formatting."));
  709. actions->areaName = new TDEAction( i18n("Area Name..."),
  710. 0, TQT_TQOBJECT(view), TQT_SLOT( setAreaName() ), ac, "areaname" );
  711. actions->areaName->setToolTip(i18n("Set a name for a region of the spreadsheet."));
  712. actions->showArea = new TDEAction( i18n("Show Area..."),
  713. 0, TQT_TQOBJECT(view), TQT_SLOT( showAreaName() ), ac, "showArea" );
  714. actions->showArea->setToolTip(i18n("Display a named area."));
  715. actions->insertFunction = new TDEAction( i18n("&Function..."), "funct",
  716. 0, TQT_TQOBJECT(view), TQT_SLOT( insertMathExpr() ), ac, "insertMathExpr" );
  717. actions->insertFunction->setToolTip(i18n("Insert math expression."));
  718. actions->insertSeries = new TDEAction( i18n("&Series..."),"series",
  719. 0, TQT_TQOBJECT(view), TQT_SLOT( insertSeries() ), ac, "series");
  720. actions->insertSeries ->setToolTip(i18n("Insert a series."));
  721. actions->insertLink = new TDEAction( i18n("&Link..."), "insert_link",
  722. 0, TQT_TQOBJECT(view), TQT_SLOT( insertHyperlink() ), ac, "insertHyperlink" );
  723. actions->insertLink->setToolTip(i18n("Insert an Internet hyperlink."));
  724. actions->removeLink = new TDEAction( i18n("&Remove Link"),
  725. 0, TQT_TQOBJECT(view), TQT_SLOT( removeHyperlink() ), ac, "removeHyperlink" );
  726. actions->removeLink->setToolTip(i18n("Remove a link."));
  727. actions->insertSpecialChar = new TDEAction( i18n( "S&pecial Character..." ), "char",
  728. TQT_TQOBJECT(view), TQT_SLOT( insertSpecialChar() ), ac, "insertSpecialChar" );
  729. actions->insertSpecialChar->setToolTip( i18n( "Insert one or more symbols or letters not found on the keyboard." ) );
  730. actions->insertPart = new KoPartSelectAction( i18n("&Object"), "frame_query",
  731. TQT_TQOBJECT(view), TQT_SLOT( insertObject() ), ac, "insertPart");
  732. actions->insertPart->setToolTip(i18n("Insert an object from another program."));
  733. actions->insertChartFrame = new TDEToggleAction( i18n("&Chart"), "insert_chart",
  734. 0, TQT_TQOBJECT(view), TQT_SLOT( insertChart() ), ac, "insertChart" );
  735. actions->insertChartFrame->setToolTip(i18n("Insert a chart."));
  736. actions->insertPicture = new TDEAction( i18n("&Picture"),
  737. 0, TQT_TQOBJECT(view), TQT_SLOT( insertPicture() ), ac, "insertPicture" );
  738. actions->insertPicture->setToolTip(i18n("Insert a picture."));
  739. #ifndef TQT_NO_SQL
  740. actions->insertFromDatabase = new TDEAction( i18n("From &Database..."),
  741. 0, TQT_TQOBJECT(view), TQT_SLOT( insertFromDatabase() ), ac, "insertFromDatabase");
  742. actions->insertFromDatabase->setToolTip(i18n("Insert data from a SQL database."));
  743. #endif
  744. actions->insertFromTextfile = new TDEAction( i18n("From &Text File..."),
  745. 0, TQT_TQOBJECT(view), TQT_SLOT( insertFromTextfile() ), ac, "insertFromTextfile");
  746. actions->insertFromTextfile->setToolTip(i18n("Insert data from a text file to the current cursor position/selection."));
  747. actions->insertFromClipboard = new TDEAction( i18n("From &Clipboard..."),
  748. 0, TQT_TQOBJECT(view), TQT_SLOT( insertFromClipboard() ), ac, "insertFromClipboard");
  749. actions->insertFromClipboard->setToolTip(i18n("Insert CSV data from the clipboard to the current cursor position/selection."));
  750. // actions->transform = new TDEAction( i18n("Transform Object..."), "rotate",
  751. // 0, TQT_TQOBJECT(view), TQT_SLOT( transformPart() ), ac, "transform" );
  752. // actions->transform->setToolTip(i18n("Rotate the contents of the cell."));
  753. // actions->transform->setEnabled( false );
  754. actions->sort = new TDEAction( i18n("&Sort..."),
  755. 0, TQT_TQOBJECT(view), TQT_SLOT( sort() ), ac, "sort" );
  756. actions->sort->setToolTip(i18n("Sort a group of cells."));
  757. actions->sortDec = new TDEAction( i18n("Sort &Decreasing"), "sort_decrease",
  758. 0, TQT_TQOBJECT(view), TQT_SLOT( sortDec() ), ac, "sortDec" );
  759. actions->sortDec->setToolTip(i18n("Sort a group of cells in decreasing (last to first) order."));
  760. actions->sortInc = new TDEAction( i18n("Sort &Increasing"), "sort_incr",
  761. 0, TQT_TQOBJECT(view), TQT_SLOT( sortInc() ), ac, "sortInc" );
  762. actions->sortInc->setToolTip(i18n("Sort a group of cells in ascending (first to last) order."));
  763. actions->paperLayout = new TDEAction( i18n("Page Layout..."),
  764. 0, TQT_TQOBJECT(view), TQT_SLOT( paperLayoutDlg() ), ac, "paperLayout" );
  765. actions->paperLayout->setToolTip(i18n("Specify the layout of the spreadsheet for a printout."));
  766. actions->definePrintRange = new TDEAction( i18n("Define Print Range"),
  767. 0, TQT_TQOBJECT(view), TQT_SLOT( definePrintRange() ), ac, "definePrintRange" );
  768. actions->definePrintRange->setToolTip(i18n("Define the print range in the current sheet."));
  769. actions->resetPrintRange = new TDEAction( i18n("Reset Print Range"),
  770. 0, TQT_TQOBJECT(view), TQT_SLOT( resetPrintRange() ), ac, "resetPrintRange" );
  771. actions->definePrintRange->setToolTip(i18n("Define the print range in the current sheet."));
  772. actions->showPageBorders = new TDEToggleAction( i18n("Show Page Borders"),
  773. 0, ac, "showPageBorders");
  774. actions->showPageBorders->setCheckedState(i18n("Hide Page Borders"));
  775. TQT_BASE_OBJECT_NAME::connect( actions->showPageBorders, TQT_SIGNAL( toggled( bool ) ),
  776. TQT_TQOBJECT(view), TQT_SLOT( togglePageBorders( bool ) ) );
  777. actions->showPageBorders->setToolTip( i18n( "Show on the spreadsheet where the page borders will be." ) );
  778. actions->recalcWorksheet = new TDEAction( i18n("Recalculate Sheet"),
  779. TQt::SHIFT + TQt::Key_F9, TQT_TQOBJECT(view), TQT_SLOT( recalcWorkSheet() ), ac, "RecalcWorkSheet" );
  780. actions->recalcWorksheet->setToolTip(i18n("Recalculate the value of every cell in the current worksheet."));
  781. actions->recalcWorkbook = new TDEAction( i18n("Recalculate Document"),
  782. TQt::Key_F9, TQT_TQOBJECT(view), TQT_SLOT( recalcWorkBook() ), ac, "RecalcWorkBook" );
  783. actions->recalcWorkbook->setToolTip(i18n("Recalculate the value of every cell in all worksheets."));
  784. actions->protectSheet = new TDEToggleAction( i18n( "Protect &Sheet..." ),
  785. 0, ac, "protectSheet" );
  786. actions->protectSheet->setToolTip( i18n( "Protect the sheet from being modified." ) );
  787. TQT_BASE_OBJECT_NAME::connect( actions->protectSheet, TQT_SIGNAL( toggled( bool ) ),
  788. TQT_TQOBJECT(view), TQT_SLOT( toggleProtectSheet( bool ) ) );
  789. actions->protectDoc = new TDEToggleAction( i18n( "Protect &Document..." ),
  790. 0, ac, "protectDoc" );
  791. actions->protectDoc->setToolTip( i18n( "Protect the document from being modified." ) );
  792. TQT_BASE_OBJECT_NAME::connect( actions->protectDoc, TQT_SIGNAL( toggled( bool ) ),
  793. TQT_TQOBJECT(view), TQT_SLOT( toggleProtectDoc( bool ) ) );
  794. // -- editing actions --
  795. actions->copy = KStdAction::copy( TQT_TQOBJECT(view), TQT_SLOT( copySelection() ), ac, "copy" );
  796. actions->copy->setToolTip(i18n("Copy the cell object to the clipboard."));
  797. actions->paste = KStdAction::paste( TQT_TQOBJECT(view), TQT_SLOT( paste() ), ac, "paste" );
  798. actions->paste->setToolTip(i18n("Paste the contents of the clipboard at the cursor."));
  799. actions->cut = KStdAction::cut( TQT_TQOBJECT(view), TQT_SLOT( cutSelection() ), ac, "cut" );
  800. actions->cut->setToolTip(i18n("Move the cell object to the clipboard."));
  801. actions->specialPaste = new TDEAction( i18n("Special Paste..."), "special_paste",
  802. 0, TQT_TQOBJECT(view), TQT_SLOT( specialPaste() ), ac, "specialPaste" );
  803. actions->specialPaste->setToolTip(i18n("Paste the contents of the clipboard with special options."));
  804. actions->insertCellCopy = new TDEAction( i18n("Paste with Insertion"), "insertcellcopy",
  805. 0, TQT_TQOBJECT(view), TQT_SLOT( slotInsertCellCopy() ), ac, "insertCellCopy" );
  806. actions->insertCellCopy->setToolTip(i18n("Inserts a cell from the clipboard into the spreadsheet."));
  807. actions->find = KStdAction::find( TQT_TQOBJECT(view), TQT_SLOT(find()), ac );
  808. /*actions->findNext =*/ KStdAction::findNext( TQT_TQOBJECT(view), TQT_SLOT( findNext() ), ac );
  809. /*actions->findPrevious =*/ KStdAction::findPrev( TQT_TQOBJECT(view), TQT_SLOT( findPrevious() ), ac );
  810. actions->replace = KStdAction::replace( TQT_TQOBJECT(view), TQT_SLOT(replace()), ac );
  811. actions->fillRight = new TDEAction( i18n( "&Right" ), 0,
  812. 0, TQT_TQOBJECT(view), TQT_SLOT( fillRight() ), ac, "fillRight" );
  813. actions->fillLeft = new TDEAction( i18n( "&Left" ), 0,
  814. 0, TQT_TQOBJECT(view), TQT_SLOT( fillLeft() ), ac, "fillLeft" );
  815. actions->fillDown = new TDEAction( i18n( "&Down" ), 0,
  816. 0, TQT_TQOBJECT(view), TQT_SLOT( fillDown() ), ac, "fillDown" );
  817. actions->fillUp = new TDEAction( i18n( "&Up" ), 0,
  818. 0, TQT_TQOBJECT(view), TQT_SLOT( fillUp() ), ac, "fillUp" );
  819. // -- misc actions --
  820. actions->styleDialog = new TDEAction( i18n( "Style Manager" ),
  821. 0, TQT_TQOBJECT(view), TQT_SLOT( styleDialog() ), ac, "styles" );
  822. actions->styleDialog->setToolTip( i18n( "Edit and organize cell styles." ) );
  823. actions->autoSum = new TDEAction( i18n("Autosum"), "black_sum",
  824. 0, TQT_TQOBJECT(view), TQT_SLOT( autoSum() ), ac, "autoSum" );
  825. actions->autoSum->setToolTip(i18n("Insert the 'sum' function"));
  826. actions->spellChecking = KStdAction::spelling( TQT_TQOBJECT(view), TQT_SLOT( extraSpelling() ),
  827. ac, "spelling" );
  828. actions->spellChecking->setToolTip(i18n("Check the spelling."));
  829. actions->formulaSelection = new TDESelectAction(i18n("Formula Selection"),
  830. 0, ac, "formulaSelection");
  831. actions->formulaSelection->setToolTip(i18n("Insert a function."));
  832. TQStringList lst;
  833. lst.append( "SUM");
  834. lst.append( "AVERAGE");
  835. lst.append( "IF");
  836. lst.append( "COUNT");
  837. lst.append( "MIN");
  838. lst.append( "MAX");
  839. lst.append( i18n("Others...") );
  840. ((TDESelectAction*) actions->formulaSelection)->setItems( lst );
  841. actions->formulaSelection->setComboWidth( 80 );
  842. actions->formulaSelection->setCurrentItem(0);
  843. TQT_BASE_OBJECT_NAME::connect( actions->formulaSelection, TQT_SIGNAL( activated( const TQString& ) ),
  844. TQT_TQOBJECT(view), TQT_SLOT( formulaSelection( const TQString& ) ) );
  845. actions->viewZoom = new KoZoomAction( i18n( "Zoom" ), "viewmag", 0, ac, "view_zoom" );
  846. TQT_BASE_OBJECT_NAME::connect( actions->viewZoom, TQT_SIGNAL( zoomChanged( const TQString & ) ),
  847. TQT_TQOBJECT(view), TQT_SLOT( viewZoom( const TQString & ) ) );
  848. actions->consolidate = new TDEAction( i18n("&Consolidate..."),
  849. 0, TQT_TQOBJECT(view), TQT_SLOT( consolidate() ), ac, "consolidate" );
  850. actions->consolidate->setToolTip(i18n("Create a region of summary data from a group of similar regions."));
  851. actions->goalSeek = new TDEAction( i18n("&Goal Seek..."),
  852. 0, TQT_TQOBJECT(view), TQT_SLOT( goalSeek() ), ac, "goalSeek" );
  853. actions->goalSeek->setToolTip( i18n("Repeating calculation to find a specific value.") );
  854. actions->subTotals = new TDEAction( i18n("&Subtotals..."),
  855. 0, TQT_TQOBJECT(view), TQT_SLOT( subtotals() ), ac, "subtotals" );
  856. actions->subTotals->setToolTip( i18n("Create different kind of subtotals to a list or database.") );
  857. actions->textToColumns = new TDEAction( i18n("&Text to Columns..."),
  858. 0, TQT_TQOBJECT(view), TQT_SLOT( textToColumns() ), ac, "textToColumns" );
  859. actions->textToColumns->setToolTip( i18n("Expand the content of cells to multiple columns.") );
  860. actions->multipleOperations = new TDEAction( i18n("&Multiple Operations..."),
  861. 0, TQT_TQOBJECT(view), TQT_SLOT( multipleOperations() ), ac, "multipleOperations" );
  862. actions->multipleOperations->setToolTip( i18n("Apply the same formula to various cells using different values for the parameter.") );
  863. actions->createTemplate = new TDEAction( i18n( "&Create Template From Document..." ),
  864. 0, TQT_TQOBJECT(view), TQT_SLOT( createTemplate() ), ac, "createTemplate" );
  865. actions->customList = new TDEAction( i18n("Custom Lists..."),
  866. 0, TQT_TQOBJECT(view), TQT_SLOT( sortList() ), ac, "sortlist" );
  867. actions->customList->setToolTip(i18n("Create custom lists for sorting or autofill."));
  868. // -- navigation actions --
  869. actions->gotoCell = new TDEAction( i18n("Goto Cell..."),"goto",
  870. 0, TQT_TQOBJECT(view), TQT_SLOT( gotoCell() ), ac, "gotoCell" );
  871. actions->gotoCell->setToolTip(i18n("Move to a particular cell."));
  872. actions->nextSheet = new TDEAction( i18n("Next Sheet"), "forward",
  873. TQt::CTRL+TQt::Key_PageDown, TQT_TQOBJECT(view), TQT_SLOT( nextSheet() ), ac, "nextSheet");
  874. actions->nextSheet->setToolTip(i18n("Move to the next sheet."));
  875. actions->prevSheet = new TDEAction( i18n("Previous Sheet"), "back",
  876. TQt::CTRL+TQt::Key_PageUp, TQT_TQOBJECT(view), TQT_SLOT( previousSheet() ), ac, "previousSheet");
  877. actions->prevSheet->setToolTip(i18n("Move to the previous sheet."));
  878. actions->firstSheet = new TDEAction( i18n("First Sheet"), "go-first",
  879. 0, TQT_TQOBJECT(view), TQT_SLOT( firstSheet() ), ac, "firstSheet");
  880. actions->firstSheet->setToolTip(i18n("Move to the first sheet."));
  881. actions->lastSheet = new TDEAction( i18n("Last Sheet"), "go-last",
  882. 0, TQT_TQOBJECT(view), TQT_SLOT( lastSheet() ), ac, "lastSheet");
  883. actions->lastSheet->setToolTip(i18n("Move to the last sheet."));
  884. // -- settings actions --
  885. actions->showStatusBar = new TDEToggleAction( i18n("Show Status Bar"),
  886. 0, ac, "showStatusBar" );
  887. actions->showStatusBar->setCheckedState(i18n("Hide Status Bar"));
  888. TQT_BASE_OBJECT_NAME::connect( actions->showStatusBar, TQT_SIGNAL( toggled( bool ) ),
  889. TQT_TQOBJECT(view), TQT_SLOT( showStatusBar( bool ) ) );
  890. actions->showStatusBar->setToolTip(i18n("Show the status bar."));
  891. actions->showTabBar = new TDEToggleAction( i18n("Show Tab Bar"),
  892. 0, ac, "showTabBar" );
  893. actions->showTabBar->setCheckedState(i18n("Hide Tab Bar"));
  894. TQT_BASE_OBJECT_NAME::connect( actions->showTabBar, TQT_SIGNAL( toggled( bool ) ),
  895. TQT_TQOBJECT(view), TQT_SLOT( showTabBar( bool ) ) );
  896. actions->showTabBar->setToolTip(i18n("Show the tab bar."));
  897. actions->showFormulaBar = new TDEToggleAction( i18n("Show Formula Bar"),
  898. 0, ac, "showFormulaBar" );
  899. actions->showFormulaBar->setCheckedState(i18n("Hide Formula Bar"));
  900. TQT_BASE_OBJECT_NAME::connect( actions->showFormulaBar, TQT_SIGNAL( toggled( bool ) ),
  901. TQT_TQOBJECT(view), TQT_SLOT( showFormulaBar( bool ) ) );
  902. actions->showFormulaBar->setToolTip(i18n("Show the formula bar."));
  903. actions->preference = new TDEAction( i18n("Configure KSpread..."),"configure",
  904. 0, TQT_TQOBJECT(view), TQT_SLOT( preference() ), ac, "preference" );
  905. actions->preference->setToolTip(i18n("Set various KSpread options."));
  906. // -- running calculation actions --
  907. actions->calcNone = new TDEToggleAction( i18n("None"), 0, ac, "menu_none");
  908. TQT_BASE_OBJECT_NAME::connect( actions->calcNone, TQT_SIGNAL( toggled( bool ) ),
  909. TQT_TQOBJECT(view), TQT_SLOT( menuCalc( bool ) ) );
  910. actions->calcNone->setExclusiveGroup( "Calc" );
  911. actions->calcNone->setToolTip(i18n("No calculation"));
  912. actions->calcSum = new TDEToggleAction( i18n("Sum"), 0, ac, "menu_sum");
  913. TQT_BASE_OBJECT_NAME::connect( actions->calcSum, TQT_SIGNAL( toggled( bool ) ),
  914. TQT_TQOBJECT(view), TQT_SLOT( menuCalc( bool ) ) );
  915. actions->calcSum->setExclusiveGroup( "Calc" );
  916. actions->calcSum->setToolTip(i18n("Calculate using sum."));
  917. actions->calcMin = new TDEToggleAction( i18n("Min"), 0, ac, "menu_min");
  918. TQT_BASE_OBJECT_NAME::connect( actions->calcMin, TQT_SIGNAL( toggled( bool ) ),
  919. TQT_TQOBJECT(view), TQT_SLOT( menuCalc( bool ) ) );
  920. actions->calcMin->setExclusiveGroup( "Calc" );
  921. actions->calcMin->setToolTip(i18n("Calculate using minimum."));
  922. actions->calcMax = new TDEToggleAction( i18n("Max"), 0, ac, "menu_max");
  923. TQT_BASE_OBJECT_NAME::connect( actions->calcMax, TQT_SIGNAL( toggled( bool ) ),
  924. TQT_TQOBJECT(view), TQT_SLOT( menuCalc( bool ) ) );
  925. actions->calcMax->setExclusiveGroup( "Calc" );
  926. actions->calcMax->setToolTip(i18n("Calculate using maximum."));
  927. actions->calcAverage = new TDEToggleAction( i18n("Average"), 0, ac, "menu_average");
  928. TQT_BASE_OBJECT_NAME::connect( actions->calcAverage, TQT_SIGNAL( toggled( bool ) ),
  929. TQT_TQOBJECT(view), TQT_SLOT( menuCalc( bool ) ) );
  930. actions->calcAverage->setExclusiveGroup( "Calc" );
  931. actions->calcAverage->setToolTip(i18n("Calculate using average."));
  932. actions->calcCount = new TDEToggleAction( i18n("Count"), 0, ac, "menu_count");
  933. TQT_BASE_OBJECT_NAME::connect( actions->calcCount, TQT_SIGNAL( toggled( bool ) ),
  934. TQT_TQOBJECT(view), TQT_SLOT( menuCalc( bool ) ) );
  935. actions->calcCount->setExclusiveGroup( "Calc" );
  936. actions->calcCount->setToolTip(i18n("Calculate using the count."));
  937. actions->calcCountA = new TDEToggleAction( i18n("CountA"), 0, ac, "menu_counta");
  938. TQT_BASE_OBJECT_NAME::connect( actions->calcCountA, TQT_SIGNAL( toggled( bool ) ),
  939. TQT_TQOBJECT(view), TQT_SLOT( menuCalc( bool ) ) );
  940. actions->calcCountA->setExclusiveGroup( "Calc" );
  941. actions->calcCountA->setToolTip(i18n("Calculate using the countA."));
  942. // -- special action, only for developers --
  943. actions->internalTests = new TDEAction( i18n("Run Internal Tests..."), "internalTests",
  944. TQt::CTRL+ TQt::SHIFT + TQt::Key_T, TQT_TQOBJECT(view), TQT_SLOT( runInternalTests() ), ac, "internalTests" );
  945. actions->inspector = new TDEAction( i18n("Run Inspector..."), "inspector",
  946. TQt::CTRL+ TQt::SHIFT + TQt::Key_I, TQT_TQOBJECT(view), TQT_SLOT( runInspector() ), ac, "inspector" );
  947. m_propertyEditor = 0;
  948. }
  949. void View::Private::adjustActions( bool mode )
  950. {
  951. actions->replace->setEnabled( mode );
  952. actions->insertSeries->setEnabled( mode );
  953. actions->insertLink->setEnabled( mode );
  954. actions->insertSpecialChar->setEnabled( mode );
  955. actions->insertFunction->setEnabled( mode );
  956. actions->removeComment->setEnabled( mode );
  957. actions->decreaseIndent->setEnabled( mode );
  958. actions->bold->setEnabled( mode );
  959. actions->italic->setEnabled( mode );
  960. actions->underline->setEnabled( mode );
  961. actions->strikeOut->setEnabled( mode );
  962. actions->percent->setEnabled( mode );
  963. actions->precplus->setEnabled( mode );
  964. actions->precminus->setEnabled( mode );
  965. actions->money->setEnabled( mode );
  966. actions->alignLeft->setEnabled( mode );
  967. actions->alignCenter->setEnabled( mode );
  968. actions->alignRight->setEnabled( mode );
  969. actions->alignTop->setEnabled( mode );
  970. actions->alignMiddle->setEnabled( mode );
  971. actions->alignBottom->setEnabled( mode );
  972. actions->paste->setEnabled( mode );
  973. actions->cut->setEnabled( mode );
  974. actions->specialPaste->setEnabled( mode );
  975. actions->deleteCell->setEnabled( mode );
  976. actions->clearText->setEnabled( mode );
  977. actions->clearComment->setEnabled( mode );
  978. actions->clearValidity->setEnabled( mode );
  979. actions->clearConditional->setEnabled( mode );
  980. actions->recalcWorkbook->setEnabled( mode );
  981. actions->recalcWorksheet->setEnabled( mode );
  982. actions->adjust->setEnabled( mode );
  983. actions->editCell->setEnabled( mode );
  984. actions->paperLayout->setEnabled( mode );
  985. actions->styleDialog->setEnabled( mode );
  986. actions->definePrintRange->setEnabled( mode );
  987. actions->resetPrintRange->setEnabled( mode );
  988. actions->insertFromDatabase->setEnabled( mode );
  989. actions->insertFromTextfile->setEnabled( mode );
  990. actions->insertFromClipboard->setEnabled( mode );
  991. actions->conditional->setEnabled( mode );
  992. actions->validity->setEnabled( mode );
  993. actions->goalSeek->setEnabled( mode );
  994. actions->subTotals->setEnabled( mode );
  995. actions->multipleOperations->setEnabled( mode );
  996. actions->textToColumns->setEnabled( mode );
  997. actions->consolidate->setEnabled( mode );
  998. actions->insertCellCopy->setEnabled( mode );
  999. actions->wrapText->setEnabled( mode );
  1000. actions->selectFont->setEnabled( mode );
  1001. actions->selectFontSize->setEnabled( mode );
  1002. actions->deleteColumn->setEnabled( mode );
  1003. actions->hideColumn->setEnabled( mode );
  1004. actions->showColumn->setEnabled( mode );
  1005. actions->showSelColumns->setEnabled( mode );
  1006. actions->insertColumn->setEnabled( mode );
  1007. actions->deleteRow->setEnabled( mode );
  1008. actions->insertRow->setEnabled( mode );
  1009. actions->hideRow->setEnabled( mode );
  1010. actions->showRow->setEnabled( mode );
  1011. actions->showSelRows->setEnabled( mode );
  1012. actions->formulaSelection->setEnabled( mode );
  1013. actions->textColor->setEnabled( mode );
  1014. actions->bgColor->setEnabled( mode );
  1015. actions->cellLayout->setEnabled( mode );
  1016. actions->borderLeft->setEnabled( mode );
  1017. actions->borderRight->setEnabled( mode );
  1018. actions->borderTop->setEnabled( mode );
  1019. actions->borderBottom->setEnabled( mode );
  1020. actions->borderAll->setEnabled( mode );
  1021. actions->borderOutline->setEnabled( mode );
  1022. actions->borderRemove->setEnabled( mode );
  1023. actions->borderColor->setEnabled( mode );
  1024. actions->removeSheet->setEnabled( mode );
  1025. actions->autoSum->setEnabled( mode );
  1026. actions->defaultFormat->setEnabled( mode );
  1027. actions->areaName->setEnabled( mode );
  1028. actions->resizeRow->setEnabled( mode );
  1029. actions->resizeColumn->setEnabled( mode );
  1030. actions->fontSizeUp->setEnabled( mode );
  1031. actions->fontSizeDown->setEnabled( mode );
  1032. actions->upper->setEnabled( mode );
  1033. actions->lower->setEnabled( mode );
  1034. actions->equalizeRow->setEnabled( mode );
  1035. actions->equalizeColumn->setEnabled( mode );
  1036. actions->verticalText->setEnabled( mode );
  1037. actions->addModifyComment->setEnabled( mode );
  1038. actions->removeComment->setEnabled( mode );
  1039. actions->insertCell->setEnabled( mode );
  1040. actions->removeCell->setEnabled( mode );
  1041. actions->changeAngle->setEnabled( mode );
  1042. actions->dissociateCell->setEnabled( mode );
  1043. actions->increaseIndent->setEnabled( mode );
  1044. actions->decreaseIndent->setEnabled( mode );
  1045. actions->spellChecking->setEnabled( mode );
  1046. actions->calcMin->setEnabled( mode );
  1047. actions->calcMax->setEnabled( mode );
  1048. actions->calcAverage->setEnabled( mode );
  1049. actions->calcCount->setEnabled( mode );
  1050. actions->calcCountA->setEnabled( mode );
  1051. actions->calcSum->setEnabled( mode );
  1052. actions->calcNone->setEnabled( mode );
  1053. actions->insertPart->setEnabled( mode );
  1054. actions->createStyle->setEnabled( mode );
  1055. actions->selectStyle->setEnabled( mode );
  1056. actions->insertChartFrame->setEnabled( mode );
  1057. actions->autoFormat->setEnabled( false );
  1058. actions->sort->setEnabled( false );
  1059. actions->mergeCell->setEnabled( false );
  1060. actions->mergeCellHorizontal->setEnabled( false );
  1061. actions->mergeCellVertical->setEnabled( false );
  1062. actions->sortDec->setEnabled( false );
  1063. actions->sortInc->setEnabled( false );
  1064. // actions->transform->setEnabled( false );
  1065. actions->fillRight->setEnabled( false );
  1066. actions->fillLeft->setEnabled( false );
  1067. actions->fillUp->setEnabled( false );
  1068. actions->fillDown->setEnabled( false );
  1069. if ( mode && !view->doc()->map()->isProtected() )
  1070. actions->renameSheet->setEnabled( true );
  1071. else
  1072. actions->renameSheet->setEnabled( false );
  1073. actions->showStatusBar->setChecked( view->doc()->showStatusBar() );
  1074. actions->showTabBar->setChecked( view->doc()->showTabBar() );
  1075. actions->showFormulaBar->setChecked( view->doc()->showFormulaBar() );
  1076. formulaButton->setEnabled( mode );
  1077. if ( activeSheet )
  1078. {
  1079. selection->update();
  1080. view->objectSelectedChanged();
  1081. }
  1082. }
  1083. void View::Private::adjustActions( Sheet* sheet, Cell* cell )
  1084. {
  1085. if ( sheet->isProtected() && !cell->isDefault() && cell->format()->notProtected( cell->column(), cell->row() ) )
  1086. {
  1087. if ( selection->isSingular() )
  1088. {
  1089. if ( !actions->bold->isEnabled() )
  1090. adjustActions( true );
  1091. }
  1092. else
  1093. {
  1094. if ( actions->bold->isEnabled() )
  1095. adjustActions( false );
  1096. }
  1097. }
  1098. else if ( sheet->isProtected() )
  1099. {
  1100. if ( actions->bold->isEnabled() )
  1101. adjustActions( false );
  1102. }
  1103. }
  1104. void View::Private::adjustWorkbookActions( bool mode )
  1105. {
  1106. tabBar->setReadOnly( !view->doc()->isReadWrite() || view->doc()->map()->isProtected() );
  1107. actions->hideSheet->setEnabled( mode );
  1108. actions->showSheet->setEnabled( mode );
  1109. actions->insertSheet->setEnabled( mode );
  1110. actions->menuInsertSheet->setEnabled( mode );
  1111. actions->removeSheet->setEnabled( mode );
  1112. if ( mode )
  1113. {
  1114. if ( activeSheet && !activeSheet->isProtected() )
  1115. {
  1116. bool state = ( view->doc()->map()->visibleSheets().count() > 1 );
  1117. actions->removeSheet->setEnabled( state );
  1118. actions->hideSheet->setEnabled( state );
  1119. }
  1120. actions->showSheet->setEnabled( view->doc()->map()->hiddenSheets().count() > 0 );
  1121. actions->renameSheet->setEnabled( activeSheet && !activeSheet->isProtected() );
  1122. }
  1123. }
  1124. // TODO this should be merged with adjustActions
  1125. void View::Private::updateButton( Cell *cell, int column, int row)
  1126. {
  1127. toolbarLock = true;
  1128. // workaround for bug #59291 (crash upon starting from template)
  1129. // certain TQt and Fontconfig combination fail miserably if can not
  1130. // find the font name (e.g. not installed in the system)
  1131. TQStringList fontList;
  1132. TDEFontChooser::getFontList( fontList, 0 );
  1133. TQString fontFamily = cell->format()->textFontFamily( column,row );
  1134. for ( TQStringList::Iterator it = fontList.begin(); it != fontList.end(); ++it )
  1135. if ((*it).lower() == fontFamily.lower())
  1136. {
  1137. actions->selectFont->setFont( fontFamily );
  1138. break;
  1139. }
  1140. actions->selectFontSize->setFontSize( cell->format()->textFontSize( column, row ) );
  1141. actions->bold->setChecked( cell->format()->textFontBold( column, row ) );
  1142. actions->italic->setChecked( cell->format()->textFontItalic( column, row) );
  1143. actions->underline->setChecked( cell->format()->textFontUnderline( column, row ) );
  1144. actions->strikeOut->setChecked( cell->format()->textFontStrike( column, row ) );
  1145. actions->alignLeft->setChecked( cell->format()->align( column, row ) == Format::Left );
  1146. actions->alignCenter->setChecked( cell->format()->align( column, row ) == Format::Center );
  1147. actions->alignRight->setChecked( cell->format()->align( column, row ) == Format::Right );
  1148. actions->alignTop->setChecked( cell->format()->alignY( column, row ) == Format::Top );
  1149. actions->alignMiddle->setChecked( cell->format()->alignY( column, row ) == Format::Middle );
  1150. actions->alignBottom->setChecked( cell->format()->alignY( column, row ) == Format::Bottom );
  1151. actions->verticalText->setChecked( cell->format()->verticalText( column,row ) );
  1152. actions->wrapText->setChecked( cell->format()->multiRow( column,row ) );
  1153. FormatType ft = cell->formatType();
  1154. actions->percent->setChecked( ft == Percentage_format );
  1155. actions->money->setChecked( ft == Money_format );
  1156. if ( activeSheet && !activeSheet->isProtected() )
  1157. actions->removeComment->setEnabled( !cell->format()->comment(column,row).isEmpty() );
  1158. if ( activeSheet && !activeSheet->isProtected() )
  1159. actions->decreaseIndent->setEnabled( cell->format()->getIndent( column, row ) > 0.0 );
  1160. toolbarLock = false;
  1161. if ( activeSheet )
  1162. adjustActions( activeSheet, cell );
  1163. }
  1164. TQButton* View::Private::newIconButton( const char *_file, bool _kbutton, TQWidget *_parent )
  1165. {
  1166. if ( _parent == 0L )
  1167. _parent = view;
  1168. if ( !_kbutton ) {
  1169. TQPushButton* pb = new TQPushButton( _parent );
  1170. pb->setIconSet( SmallIconSet(_file) );
  1171. return pb;
  1172. } else {
  1173. TQToolButton* pb = new TQToolButton( _parent );
  1174. pb->setIconSet( SmallIconSet(_file) );
  1175. return pb;
  1176. }
  1177. }
  1178. KPSheetSelectPage::KPSheetSelectPage( TQWidget *parent )
  1179. : KPrintDialogPage(parent),
  1180. gui(new SheetSelectWidget(this))
  1181. {
  1182. setTitle(gui->caption());
  1183. //disabling automated sorting
  1184. gui->ListViewAvailable->setSorting(-1);
  1185. gui->ListViewSelected->setSorting(-1);
  1186. //connect buttons
  1187. connect(gui->ButtonSelectAll,TQT_SIGNAL(clicked()),this,TQT_SLOT(selectAll()));
  1188. connect(gui->ButtonSelect,TQT_SIGNAL(clicked()),this,TQT_SLOT(select()));
  1189. connect(gui->ButtonRemove,TQT_SIGNAL(clicked()),this,TQT_SLOT(remove()));
  1190. connect(gui->ButtonRemoveAll,TQT_SIGNAL(clicked()),this,TQT_SLOT(removeAll()));
  1191. connect(gui->ButtonMoveTop,TQT_SIGNAL(clicked()),this,TQT_SLOT(moveTop()));
  1192. connect(gui->ButtonMoveUp,TQT_SIGNAL(clicked()),this,TQT_SLOT(moveUp()));
  1193. connect(gui->ButtonMoveDown,TQT_SIGNAL(clicked()),this,TQT_SLOT(moveDown()));
  1194. connect(gui->ButtonMoveBottom,TQT_SIGNAL(clicked()),this,TQT_SLOT(moveBottom()));
  1195. }
  1196. // KPSheetSelectPage::~KPSheetSelectPage()
  1197. // {
  1198. // }
  1199. void KPSheetSelectPage::getOptions( TQMap<TQString,TQString>& opts, bool /*incldef*/ )
  1200. {
  1201. TQStringList sheetlist = this->selectedSheets();
  1202. TQStringList::iterator it;
  1203. unsigned int i = 0;
  1204. for (it = sheetlist.begin(); it != sheetlist.end(); ++it, i++)
  1205. {
  1206. opts.insert(printOptionForIndex(i),*it);
  1207. }
  1208. }
  1209. void KPSheetSelectPage::setOptions( const TQMap<TQString,TQString>& opts )
  1210. {
  1211. unsigned int i = 0;
  1212. TQStringList sheetlist;
  1213. while (opts.contains(printOptionForIndex(i)))
  1214. {
  1215. sheetlist.prepend(opts[printOptionForIndex(i++)]);
  1216. }
  1217. TQStringList::iterator it;
  1218. for (it = sheetlist.begin(); it != sheetlist.end(); ++it)
  1219. {
  1220. kdDebug() << " adding sheet to list of printed sheets: " << *it << endl;
  1221. this->prependSelectedSheet(*it);
  1222. }
  1223. }
  1224. bool KPSheetSelectPage::isValid(TQString& /*msg*/)
  1225. {
  1226. // we print the activeSheet() by default if no sheet is selected,
  1227. // so we return true in any case
  1228. // Q_ASSERT(gui);
  1229. // if (gui->ListViewSelected->childCount() < 1)
  1230. // {
  1231. // msg = i18n("No sheets selected for printing!");
  1232. // return false;
  1233. // }
  1234. return true;
  1235. }
  1236. TQString KPSheetSelectPage::printOptionForIndex(unsigned int index)
  1237. {
  1238. return TQString("sheetprintorder%1").arg(index);
  1239. }
  1240. void KPSheetSelectPage::prependAvailableSheet(const TQString& sheetname)
  1241. {
  1242. Q_ASSERT(gui);
  1243. new TQListViewItem(gui->ListViewAvailable,sheetname);
  1244. }
  1245. void KPSheetSelectPage::prependSelectedSheet(const TQString& sheetname)
  1246. {
  1247. Q_ASSERT(gui);
  1248. new TQListViewItem(gui->ListViewSelected,sheetname);
  1249. }
  1250. TQStringList KPSheetSelectPage::selectedSheets()
  1251. {
  1252. Q_ASSERT(gui);
  1253. TQStringList list;
  1254. TQListViewItem* item = gui->ListViewSelected->firstChild();
  1255. while (item)
  1256. {
  1257. list.append(item->text(0));
  1258. item = item->nextSibling();
  1259. }
  1260. return list;
  1261. }
  1262. TQStringList KPSheetSelectPage::selectedSheets(KPrinter &prt)
  1263. {
  1264. TQStringList list;
  1265. unsigned int index;
  1266. const TQMap<TQString,TQString>& options = prt.options();
  1267. for (index = 0; options.contains(KPSheetSelectPage::printOptionForIndex(index)); index++)
  1268. {
  1269. list.append(options[KPSheetSelectPage::printOptionForIndex(index)]);
  1270. }
  1271. return list;
  1272. }
  1273. void KPSheetSelectPage::clearSelection()
  1274. {
  1275. gui->ListViewSelected->clear();
  1276. }
  1277. void KPSheetSelectPage::selectAll()
  1278. {
  1279. //we have to add all the stuff in reverse order
  1280. // because inserted items (prependSelectedSheet) are prepended
  1281. TQStringList list;
  1282. TQListViewItem* item = gui->ListViewAvailable->firstChild();
  1283. while (item)
  1284. {
  1285. list.prepend(item->text(0));
  1286. item = item->nextSibling();
  1287. }
  1288. TQStringList::iterator it;
  1289. for (it = list.begin(); it != list.end(); ++it)
  1290. {
  1291. this->prependSelectedSheet(*it);
  1292. }
  1293. }
  1294. void KPSheetSelectPage::select()
  1295. {
  1296. //we have to add all the stuff in reverse order
  1297. // because inserted items (prependSelectedSheet) are prepended
  1298. TQStringList list;
  1299. TQListViewItem* item = gui->ListViewAvailable->firstChild();
  1300. while (item)
  1301. {
  1302. if (item->isSelected())
  1303. list.prepend(item->text(0));
  1304. item = item->nextSibling();
  1305. }
  1306. TQStringList::iterator it;
  1307. for (it = list.begin(); it != list.end(); ++it)
  1308. {
  1309. this->prependSelectedSheet(*it);
  1310. }
  1311. }
  1312. void KPSheetSelectPage::remove()
  1313. {
  1314. TQListViewItem* item = gui->ListViewSelected->firstChild();
  1315. TQListViewItem* nextitem = NULL;
  1316. while (item)
  1317. {
  1318. nextitem = item->nextSibling();
  1319. if (item->isSelected())
  1320. delete item;
  1321. item = nextitem;
  1322. }
  1323. }
  1324. void KPSheetSelectPage::removeAll()
  1325. {
  1326. gui->ListViewSelected->clear();
  1327. }
  1328. void KPSheetSelectPage::moveTop()
  1329. {
  1330. //this creates a temporary new list (selected first, then rest)
  1331. // which replaces the existing one, to avoid the need of an additional sort column
  1332. TQValueList<TQListViewItem*> newlist;
  1333. TQListViewItem* item = gui->ListViewSelected->firstChild();
  1334. TQListViewItem* nextitem = NULL;
  1335. // kdDebug() << "Filling new list with selected items first" << endl;
  1336. while (item)
  1337. {
  1338. nextitem = item->nextSibling();
  1339. if (item->isSelected())
  1340. {
  1341. newlist.prepend(item);
  1342. gui->ListViewSelected->takeItem(item);
  1343. }
  1344. item = nextitem;
  1345. }
  1346. // kdDebug() << "Appending the rest" << endl;
  1347. item = gui->ListViewSelected->firstChild();
  1348. while (item)
  1349. {
  1350. // kdDebug() << " processing item " << item->text(0) << endl;
  1351. nextitem = item->nextSibling();
  1352. if (!item->isSelected())
  1353. {
  1354. newlist.prepend(item);
  1355. gui->ListViewSelected->takeItem(item);
  1356. }
  1357. item = nextitem;
  1358. }
  1359. // kdDebug() << "Refill the view with the correctly ordered list" << endl;
  1360. //the view is empty now, refill in correct order (reversed!!)
  1361. TQValueList<TQListViewItem*>::iterator it;
  1362. for (it = newlist.begin(); it != newlist.end(); ++it)
  1363. {
  1364. // kdDebug() << " adding " << (*it)->text(0) << endl;
  1365. gui->ListViewSelected->insertItem(*it);
  1366. }
  1367. }
  1368. void KPSheetSelectPage::moveUp()
  1369. {
  1370. //this creates a temporary new list
  1371. // which replaces the existing one, to avoid the need of an additional sort column
  1372. TQValueList<TQListViewItem*> newlist;
  1373. TQListViewItem* item = gui->ListViewSelected->firstChild();
  1374. TQListViewItem* nextitem = NULL;
  1375. while (item)
  1376. {
  1377. nextitem = item->nextSibling();
  1378. if (!item->isSelected())
  1379. {
  1380. while (nextitem && nextitem->isSelected())
  1381. {
  1382. TQListViewItem* nextnextitem = nextitem->nextSibling();
  1383. newlist.prepend(nextitem);
  1384. gui->ListViewSelected->takeItem(nextitem);
  1385. nextitem = nextnextitem;
  1386. }
  1387. }
  1388. newlist.prepend(item);
  1389. gui->ListViewSelected->takeItem(item);
  1390. item = nextitem;
  1391. }
  1392. // kdDebug() << "Refill the view with the correctly ordered list" << endl;
  1393. //the view is empty now, refill in correct order (reversed!!)
  1394. TQValueList<TQListViewItem*>::iterator it;
  1395. for (it = newlist.begin(); it != newlist.end(); ++it)
  1396. {
  1397. // kdDebug() << " adding " << (*it)->text(0) << endl;
  1398. gui->ListViewSelected->insertItem(*it);
  1399. }
  1400. }
  1401. void KPSheetSelectPage::moveDown()
  1402. {
  1403. TQListViewItem* item = gui->ListViewSelected->lastItem();
  1404. // while (item)
  1405. // {
  1406. // nextitem = item->nextSibling();
  1407. // if (previousitem && previousitem->isSelected())
  1408. // {
  1409. // previousitem->moveItem(item);
  1410. // }
  1411. // previousitem = item;
  1412. // item = nextitem;
  1413. // }
  1414. while (item)
  1415. {
  1416. while (item && !item->isSelected() && item->itemAbove() && item->itemAbove()->isSelected())
  1417. {
  1418. TQListViewItem* tempitem = item->itemAbove();
  1419. tempitem->moveItem(item);
  1420. }
  1421. if (item)
  1422. item = item->itemAbove();
  1423. }
  1424. }
  1425. void KPSheetSelectPage::moveBottom()
  1426. {
  1427. //this creates a temporary new list (unselected first, then rest)
  1428. // which replaces the existing one, to avoid the need of an additional sort column
  1429. TQValueList<TQListViewItem*> newlist;
  1430. TQListViewItem* item = gui->ListViewSelected->firstChild();
  1431. TQListViewItem* nextitem = NULL;
  1432. // kdDebug() << "Filling new list with unselected items first" << endl;
  1433. while (item)
  1434. {
  1435. // kdDebug() << " processing item " << item->text(0) << endl;
  1436. nextitem = item->nextSibling();
  1437. if (!item->isSelected())
  1438. {
  1439. newlist.prepend(item);
  1440. gui->ListViewSelected->takeItem(item);
  1441. }
  1442. item = nextitem;
  1443. }
  1444. // kdDebug() << "Appending the rest" << endl;
  1445. item = gui->ListViewSelected->firstChild();
  1446. while (item)
  1447. {
  1448. nextitem = item->nextSibling();
  1449. if (item->isSelected())
  1450. {
  1451. newlist.prepend(item);
  1452. gui->ListViewSelected->takeItem(item);
  1453. }
  1454. item = nextitem;
  1455. }
  1456. // kdDebug() << "Refill the view with the correctly ordered list" << endl;
  1457. //the view is empty now, refill in correct order (reversed!!)
  1458. TQValueList<TQListViewItem*>::iterator it;
  1459. for (it = newlist.begin(); it != newlist.end(); ++it)
  1460. {
  1461. // kdDebug() << " adding " << (*it)->text(0) << endl;
  1462. gui->ListViewSelected->insertItem(*it);
  1463. }
  1464. }
  1465. /*****************************************************************************
  1466. *
  1467. * View
  1468. *
  1469. *****************************************************************************/
  1470. View::View( TQWidget *_parent, const char *_name,
  1471. Doc *_doc )
  1472. : KoView( _doc, _parent, _name )
  1473. {
  1474. ElapsedTime et( "View constructor" );
  1475. kdDebug(36001) << "sizeof(Cell)=" << sizeof(Cell) <<endl;
  1476. d = new Private;
  1477. d->view = this;
  1478. d->doc = _doc;
  1479. d->dcop = 0;
  1480. d->activeSheet = 0;
  1481. d->toolbarLock = false;
  1482. d->loading = true;
  1483. d->selection = new Selection( this );
  1484. d->choice = new Selection( this );
  1485. d->choice->setMultipleSelection(true);
  1486. connect(d->selection, TQT_SIGNAL(changed(const Region&)), this, TQT_SLOT(slotChangeSelection(const Region&)));
  1487. connect(d->choice, TQT_SIGNAL(changed(const Region&)), this, TQT_SLOT(slotChangeChoice(const Region&)));
  1488. connect(d->choice, TQT_SIGNAL(changed(const Region&)), this, TQT_SLOT(slotScrollChoice(const Region&)));
  1489. d->findOptions = 0;
  1490. d->findLeftColumn = 0;
  1491. d->findRightColumn = 0;
  1492. d->typeValue = FindOption::Value;
  1493. d->directionValue = FindOption::Row;
  1494. d->find = 0;
  1495. d->replace = 0;
  1496. d->popupMenuFirstToolId = 0;
  1497. d->popupMenu = 0;
  1498. d->popupColumn = 0;
  1499. d->popupRow = 0;
  1500. d->popupChild = 0;
  1501. d->popupListChoose = 0;
  1502. d->popupChildObject = 0;
  1503. d->searchInSheets.currentSheet = 0;
  1504. d->searchInSheets.firstSheet = 0;
  1505. // spell-check context
  1506. d->spell.tdespell = 0;
  1507. d->spell.macroCmdSpellCheck = 0;
  1508. d->spell.firstSpellSheet = 0;
  1509. d->spell.currentSpellSheet = 0;
  1510. d->spell.currentCell = 0;
  1511. d->spell.spellStartCellX = 0;
  1512. d->spell.spellStartCellY = 0;
  1513. d->spell.spellEndCellX = 0;
  1514. d->spell.spellEndCellY = 0;
  1515. d->spell.spellCheckSelection = false;
  1516. d->insertHandler = 0L;
  1517. d->specialCharDlg = 0;
  1518. setInstance( Factory::global() );
  1519. if ( doc()->isReadWrite() )
  1520. setXMLFile( "kspread.rc" );
  1521. else
  1522. setXMLFile( "kspread_readonly.rc" );
  1523. // build the DCOP object
  1524. dcopObject();
  1525. connect( doc()->commandHistory(), TQT_SIGNAL( commandExecuted() ),
  1526. this, TQT_SLOT( commandExecuted() ) );
  1527. // GUI Initializations
  1528. initView();
  1529. d->initActions();
  1530. // Handler for moving and resizing embedded parts
  1531. KoContainerHandler* h = new KoContainerHandler( this, d->canvas );
  1532. connect( h, TQT_SIGNAL( popupMenu( KoChild*, const TQPoint& ) ), this, TQT_SLOT( popupChildMenu( KoChild*, const TQPoint& ) ) );
  1533. connect( this, TQT_SIGNAL( childSelected( KoDocumentChild* ) ),
  1534. this, TQT_SLOT( slotChildSelected( KoDocumentChild* ) ) );
  1535. connect( this, TQT_SIGNAL( childUnselected( KoDocumentChild* ) ),
  1536. this, TQT_SLOT( slotChildUnselected( KoDocumentChild* ) ) );
  1537. // If a selected part becomes active this is like it is deselected
  1538. // just before.
  1539. connect( this, TQT_SIGNAL( childActivated( KoDocumentChild* ) ),
  1540. this, TQT_SLOT( slotChildUnselected( KoDocumentChild* ) ) );
  1541. connect( d->canvas, TQT_SIGNAL( objectSelectedChanged() ),
  1542. this, TQT_SLOT( objectSelectedChanged() ) );
  1543. TQT_BASE_OBJECT_NAME::connect( doc()->map(), TQT_SIGNAL( sig_addSheet( Sheet* ) ), TQT_SLOT( slotAddSheet( Sheet* ) ) );
  1544. TQT_BASE_OBJECT_NAME::connect( doc(), TQT_SIGNAL( sig_refreshView( ) ), this, TQT_SLOT( slotRefreshView() ) );
  1545. TQT_BASE_OBJECT_NAME::connect( doc(), TQT_SIGNAL( sig_refreshLocale() ), this, TQT_SLOT( refreshLocale()));
  1546. TQT_BASE_OBJECT_NAME::connect( doc(), TQT_SIGNAL( sig_addAreaName( const TQString & ) ), d->posWidget, TQT_SLOT( slotAddAreaName( const TQString & ) ) );
  1547. TQT_BASE_OBJECT_NAME::connect( doc(), TQT_SIGNAL( sig_removeAreaName( const TQString & ) ), d->posWidget, TQT_SLOT( slotRemoveAreaName( const TQString & ) ) );
  1548. TQT_BASE_OBJECT_NAME::connect( doc(), TQT_SIGNAL( damagesFlushed( const TQValueList<Damage*>& ) ),
  1549. this, TQT_SLOT( handleDamages( const TQValueList<Damage*>& ) ) );
  1550. //KoView::setZoom( doc()->zoomedResolutionY() /* KoView only supports one zoom */ ); // initial value
  1551. //when kspread is embedded into konqueror apply a zoom=100
  1552. //in konqueror we can't change zoom -- ### TODO ?
  1553. if (!doc()->isReadWrite())
  1554. {
  1555. setZoom( 100, true );
  1556. }
  1557. viewZoom( TQString::number( doc()->zoom() ) );
  1558. // ## Might be wrong, if doc isn't loaded yet
  1559. d->actions->selectStyle->setItems( d->doc->styleManager()->styleNames() );
  1560. // Delay the setting of the initial position, because
  1561. // we have to wait for the widget to be shown. Otherwise,
  1562. // we get a wrong widget size.
  1563. // This is the last operation for the "View loading" process.
  1564. // The loading flag will be unset at its end.
  1565. if ( !doc()->map()->sheetList().isEmpty() )
  1566. TQTimer::singleShot(50, this, TQT_SLOT(initialPosition()));
  1567. connect (&d->statusBarOpTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(calcStatusBarOp()));
  1568. }
  1569. View::~View()
  1570. {
  1571. // ElapsedTime el( "~View" );
  1572. if ( doc()->isReadWrite() ) // make sure we're not embedded in Konq
  1573. deleteEditor( true );
  1574. if ( !d->transformToolBox.isNull() )
  1575. delete (&*d->transformToolBox);
  1576. /*if (d->calcLabel)
  1577. {
  1578. disconnect(d->calcLabel,TQT_SIGNAL(pressed( int )),this,TQT_SLOT(statusBarClicked(int)));
  1579. }*/
  1580. delete d->spell.tdespell;
  1581. d->canvas->endChoose();
  1582. d->activeSheet = 0; // set the active sheet to 0L so that when during destruction
  1583. // of embedded child documents possible repaints in Sheet are not
  1584. // performed. The repains can happen if you delete an embedded document,
  1585. // which leads to an regionInvalidated() signal emission in KoView, which calls
  1586. // repaint, etc.etc. :-) (Simon)
  1587. delete d->selection;
  1588. delete d->choice;
  1589. delete d->popupColumn;
  1590. delete d->popupRow;
  1591. delete d->popupMenu;
  1592. delete d->popupChild;
  1593. delete d->popupListChoose;
  1594. delete d->calcLabel;
  1595. delete d->dcop;
  1596. delete d->insertHandler;
  1597. d->insertHandler = 0L;
  1598. delete d->actions;
  1599. // NOTE Stefan: Delete the Canvas explicitly, even if it has this view as
  1600. // parent. Otherwise, it leads to crashes, because it tries to
  1601. // access this View in some events (Bug #126492).
  1602. delete d->canvas;
  1603. delete d;
  1604. }
  1605. Doc* View::doc() const
  1606. {
  1607. return d->doc;
  1608. }
  1609. // should be called only once, from the constructor
  1610. /*
  1611. * Top part is the formula bar.
  1612. * Central part is the canvas, row header and vertical scrollbar.
  1613. * Bottom part is the tab bar and horizontal scrollbar.
  1614. *
  1615. * Note that canvas must the one to be created, since other
  1616. * widgets might depend on it.
  1617. */
  1618. void View::initView()
  1619. {
  1620. d->viewLayout = new TQGridLayout( this, 3, 4 );
  1621. // Vert. Scroll Bar
  1622. d->calcLabel = 0;
  1623. d->vertScrollBar = new TQScrollBar( this, "ScrollBar_2" );
  1624. d->vertScrollBar->setRange( 0, 4096 );
  1625. d->vertScrollBar->setOrientation( Qt::Vertical );
  1626. d->vertScrollBar->setLineStep(60); //just random guess based on what feels okay
  1627. d->vertScrollBar->setPageStep(60); //This should be controlled dynamically, depending on how many rows are shown
  1628. // Edit Bar
  1629. d->toolWidget = new TQFrame( this );
  1630. d->formulaBarLayout = new TQHBoxLayout( d->toolWidget );
  1631. d->formulaBarLayout->setMargin( 4 );
  1632. d->formulaBarLayout->addSpacing( 2 );
  1633. d->posWidget = new ComboboxLocationEditWidget( d->toolWidget, this );
  1634. d->posWidget->setMinimumWidth( 100 );
  1635. d->formulaBarLayout->addWidget( d->posWidget );
  1636. d->formulaBarLayout->addSpacing( 6 );
  1637. d->formulaButton = d->newIconButton( "funct", true, d->toolWidget );
  1638. d->formulaBarLayout->addWidget( d->formulaButton );
  1639. d->formulaBarLayout->addSpacing( 2 );
  1640. connect( d->formulaButton, TQT_SIGNAL( clicked() ), TQT_SLOT( insertMathExpr() ) );
  1641. d->cancelButton = d->newIconButton( "cancel", true, d->toolWidget );
  1642. d->formulaBarLayout->addWidget( d->cancelButton );
  1643. d->okButton = d->newIconButton( "ok", true, d->toolWidget );
  1644. d->formulaBarLayout->addWidget( d->okButton );
  1645. d->formulaBarLayout->addSpacing( 6 );
  1646. // The widget on which we display the sheet
  1647. d->canvas = new Canvas( this );
  1648. // The line-editor that appears above the sheet and allows to
  1649. // edit the cells content. It knows about the two buttons.
  1650. d->editWidget = new EditWidget( d->toolWidget, d->canvas, d->cancelButton, d->okButton );
  1651. d->editWidget->setFocusPolicy( TQ_StrongFocus );
  1652. d->formulaBarLayout->addWidget( d->editWidget, 2 );
  1653. d->formulaBarLayout->addSpacing( 2 );
  1654. d->canvas->setEditWidget( d->editWidget );
  1655. d->hBorderWidget = new HBorder( this, d->canvas,this );
  1656. d->vBorderWidget = new VBorder( this, d->canvas ,this );
  1657. d->hBorderWidget->setSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Minimum );
  1658. d->vBorderWidget->setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Expanding );
  1659. d->canvas->setFocusPolicy( TQ_StrongFocus );
  1660. TQWidget::setFocusPolicy( TQ_StrongFocus );
  1661. setFocusProxy( d->canvas );
  1662. connect( this, TQT_SIGNAL( invalidated() ), d->canvas, TQT_SLOT( update() ) );
  1663. TQWidget* bottomPart = new TQWidget( this );
  1664. d->tabScrollBarLayout = new TQHBoxLayout( bottomPart );
  1665. d->tabScrollBarLayout->setAutoAdd( true );
  1666. d->tabBar = new KoTabBar( bottomPart );
  1667. d->horzScrollBar = new TQScrollBar( bottomPart, "ScrollBar_1" );
  1668. d->horzScrollBar->setRange( 0, 4096 );
  1669. d->horzScrollBar->setOrientation( Qt::Horizontal );
  1670. d->horzScrollBar->setLineStep(60); //just random guess based on what feels okay
  1671. d->horzScrollBar->setPageStep(60);
  1672. TQT_BASE_OBJECT_NAME::connect( d->tabBar, TQT_SIGNAL( tabChanged( const TQString& ) ), this, TQT_SLOT( changeSheet( const TQString& ) ) );
  1673. TQT_BASE_OBJECT_NAME::connect( d->tabBar, TQT_SIGNAL( tabMoved( unsigned, unsigned ) ),
  1674. this, TQT_SLOT( moveSheet( unsigned, unsigned ) ) );
  1675. TQT_BASE_OBJECT_NAME::connect( d->tabBar, TQT_SIGNAL( contextMenu( const TQPoint& ) ),
  1676. this, TQT_SLOT( popupTabBarMenu( const TQPoint& ) ) );
  1677. TQT_BASE_OBJECT_NAME::connect( d->tabBar, TQT_SIGNAL( doubleClicked() ),
  1678. this, TQT_SLOT( slotRename() ) );
  1679. d->viewLayout->setColStretch( 1, 10 );
  1680. d->viewLayout->setRowStretch( 2, 10 );
  1681. d->viewLayout->addMultiCellWidget( d->toolWidget, 0, 0, 0, 2 );
  1682. d->viewLayout->addMultiCellWidget( d->hBorderWidget, 1, 1, 1, 2 );
  1683. d->viewLayout->addWidget( d->vBorderWidget, 2, 0 );
  1684. d->viewLayout->addWidget( d->canvas, 2, 1 );
  1685. d->viewLayout->addWidget( d->vertScrollBar, 2, 2 );
  1686. d->viewLayout->addMultiCellWidget( bottomPart, 3, 3, 0, 2 );
  1687. KStatusBar * sb = statusBar();
  1688. Q_ASSERT(sb);
  1689. d->calcLabel = sb ? new KStatusBarLabel( TQString(), 0, sb ) : 0;
  1690. addStatusBarItem( d->calcLabel, 0 );
  1691. if (d->calcLabel)
  1692. connect(d->calcLabel ,TQT_SIGNAL(itemPressed( int )),this,TQT_SLOT(statusBarClicked(int)));
  1693. // signal slot
  1694. TQT_BASE_OBJECT_NAME::connect( d->vertScrollBar, TQT_SIGNAL( valueChanged(int) ), d->canvas, TQT_SLOT( slotScrollVert(int) ) );
  1695. TQT_BASE_OBJECT_NAME::connect( d->horzScrollBar, TQT_SIGNAL( valueChanged(int) ), d->canvas, TQT_SLOT( slotScrollHorz(int) ) );
  1696. }
  1697. Canvas* View::canvasWidget() const
  1698. {
  1699. return d->canvas;
  1700. }
  1701. HBorder* View::hBorderWidget()const
  1702. {
  1703. return d->hBorderWidget;
  1704. }
  1705. VBorder* View::vBorderWidget()const
  1706. {
  1707. return d->vBorderWidget;
  1708. }
  1709. TQScrollBar* View::horzScrollBar()const
  1710. {
  1711. return d->horzScrollBar;
  1712. }
  1713. TQScrollBar* View::vertScrollBar()const
  1714. {
  1715. return d->vertScrollBar;
  1716. }
  1717. EditWidget* View::editWidget()const
  1718. {
  1719. return d->editWidget;
  1720. }
  1721. ComboboxLocationEditWidget* View::posWidget()const
  1722. {
  1723. return d->posWidget;
  1724. }
  1725. KoTabBar* View::tabBar() const
  1726. {
  1727. return d->tabBar;
  1728. }
  1729. bool View::isLoading() const
  1730. {
  1731. return d->loading;
  1732. }
  1733. Selection* View::selectionInfo() const
  1734. {
  1735. return d->selection;
  1736. }
  1737. Selection* View::choice() const
  1738. {
  1739. return d->choice;
  1740. }
  1741. void View::resetInsertHandle()
  1742. {
  1743. d->actions->insertChartFrame->setChecked( false );
  1744. // d->actions->insertPicture->setChecked( false );
  1745. d->insertHandler = 0;
  1746. }
  1747. bool View::isInsertingObject()
  1748. {
  1749. return d->insertHandler;
  1750. }
  1751. const Sheet* View::activeSheet() const
  1752. {
  1753. return d->activeSheet;
  1754. }
  1755. Sheet* View::activeSheet()
  1756. {
  1757. return d->activeSheet;
  1758. }
  1759. void View::initConfig()
  1760. {
  1761. TDEConfig *config = Factory::global()->config();
  1762. if ( config->hasGroup("Parameters" ))
  1763. {
  1764. config->setGroup( "Parameters" );
  1765. if ( !doc()->configLoadFromFile() )
  1766. doc()->setShowHorizontalScrollBar(config->readBoolEntry("Horiz ScrollBar",true));
  1767. if ( !doc()->configLoadFromFile() )
  1768. doc()->setShowVerticalScrollBar(config->readBoolEntry("Vert ScrollBar",true));
  1769. doc()->setShowColHeader(config->readBoolEntry("Column Header",true));
  1770. doc()->setShowRowHeader(config->readBoolEntry("Row Header",true));
  1771. if ( !doc()->configLoadFromFile() )
  1772. doc()->setCompletionMode((TDEGlobalSettings::Completion)config->readNumEntry("Completion Mode",(int)(TDEGlobalSettings::CompletionAuto)));
  1773. doc()->setMoveToValue((KSpread::MoveTo)config->readNumEntry("Move",(int)(Bottom)));
  1774. doc()->setIndentValue( config->readDoubleNumEntry( "Indent", 10.0 ) );
  1775. doc()->setTypeOfCalc((MethodOfCalc)config->readNumEntry("Method of Calc",(int)(SumOfNumber)));
  1776. if ( !doc()->configLoadFromFile() )
  1777. doc()->setShowTabBar(config->readBoolEntry("Tabbar",true));
  1778. doc()->setShowMessageError(config->readBoolEntry( "Msg error" ,false) );
  1779. doc()->setShowFormulaBar(config->readBoolEntry("Formula bar",true));
  1780. doc()->setShowStatusBar(config->readBoolEntry("Status bar",true));
  1781. changeNbOfRecentFiles(config->readNumEntry("NbRecentFile",10));
  1782. //autosave value is stored as a minute.
  1783. //but default value is stored as seconde.
  1784. doc()->setAutoSave(config->readNumEntry("AutoSave",KoDocument::defaultAutoSave()/60)*60);
  1785. doc()->setBackupFile( config->readBoolEntry("BackupFile",true));
  1786. }
  1787. if ( config->hasGroup("KSpread Color" ) )
  1788. {
  1789. config->setGroup( "KSpread Color" );
  1790. TQColor _col(TQt::lightGray);
  1791. _col = config->readColorEntry("GridColor", &_col);
  1792. doc()->setGridColor(_col);
  1793. TQColor _pbCol(TQt::red);
  1794. _pbCol = config->readColorEntry("PageBorderColor", &_pbCol);
  1795. doc()->changePageBorderColor(_pbCol);
  1796. }
  1797. // Do we need a Page Layout in the congiguration file? Isn't this already in the template? Philipp
  1798. /*
  1799. if ( config->hasGroup("KSpread Page Layout" ) )
  1800. {
  1801. config->setGroup( "KSpread Page Layout" );
  1802. if ( d->activeSheet->isEmpty())
  1803. {
  1804. d->activeSheet->setPaperFormat((KoFormat)config->readNumEntry("Default size page",1));
  1805. d->activeSheet->setPaperOrientation((KoOrientation)config->readNumEntry("Default orientation page",0));
  1806. d->activeSheet->setPaperUnit((KoUnit::Unit)config->readNumEntry("Default unit page",0));
  1807. }
  1808. }
  1809. */
  1810. initCalcMenu();
  1811. calcStatusBarOp();
  1812. }
  1813. void View::changeNbOfRecentFiles(int _nb)
  1814. {
  1815. if (shell())
  1816. shell()->setMaxRecentItems( _nb );
  1817. }
  1818. void View::initCalcMenu()
  1819. {
  1820. switch( doc()->getTypeOfCalc())
  1821. {
  1822. case SumOfNumber:
  1823. d->actions->calcSum->setChecked(true);
  1824. break;
  1825. case Min:
  1826. d->actions->calcMin->setChecked(true);
  1827. break;
  1828. case Max:
  1829. d->actions->calcMax->setChecked(true);
  1830. break;
  1831. case Average:
  1832. d->actions->calcAverage->setChecked(true);
  1833. break;
  1834. case Count:
  1835. d->actions->calcCount->setChecked(true);
  1836. break;
  1837. case CountA:
  1838. d->actions->calcCountA->setChecked(true);
  1839. break;
  1840. case NoneCalc:
  1841. d->actions->calcNone->setChecked(true);
  1842. break;
  1843. default :
  1844. d->actions->calcSum->setChecked(true);
  1845. break;
  1846. }
  1847. }
  1848. void View::recalcWorkBook()
  1849. {
  1850. if (!activeSheet())
  1851. return;
  1852. Sheet * tbl;
  1853. doc()->emitBeginOperation( true );
  1854. for ( tbl = doc()->map()->firstSheet();
  1855. tbl != 0L;
  1856. tbl = doc()->map()->nextSheet() )
  1857. {
  1858. // bool b = tbl->getAutoCalc();
  1859. // tbl->setAutoCalc( true );
  1860. tbl->recalc( /*force recalculation = */ true);
  1861. // tbl->setAutoCalc( b );
  1862. }
  1863. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  1864. }
  1865. void View::refreshLocale()
  1866. {
  1867. doc()->emitBeginOperation(true);
  1868. Sheet *tbl;
  1869. for ( tbl = doc()->map()->firstSheet();
  1870. tbl != 0L;
  1871. tbl = doc()->map()->nextSheet() )
  1872. {
  1873. tbl->updateLocale();
  1874. }
  1875. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  1876. }
  1877. void View::recalcWorkSheet()
  1878. {
  1879. if ( d->activeSheet != 0 )
  1880. {
  1881. doc()->emitBeginOperation( true );
  1882. // bool b = d->activeSheet->getAutoCalc();
  1883. // d->activeSheet->setAutoCalc( true );
  1884. d->activeSheet->recalc( /*force recalculation = */ true);
  1885. // d->activeSheet->setAutoCalc( b );
  1886. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  1887. }
  1888. }
  1889. void View::extraSpelling()
  1890. {
  1891. if ( d->spell.tdespell )
  1892. return; // Already in progress
  1893. if (d->activeSheet == 0L)
  1894. return;
  1895. d->spell.macroCmdSpellCheck = 0L;
  1896. d->spell.firstSpellSheet = d->activeSheet;
  1897. d->spell.currentSpellSheet = d->spell.firstSpellSheet;
  1898. TQRect selection = d->selection->selection();
  1899. // if nothing is selected, check every cell
  1900. if (d->selection->isSingular())
  1901. {
  1902. d->spell.spellStartCellX = 0;
  1903. d->spell.spellStartCellY = 0;
  1904. d->spell.spellEndCellX = 0;
  1905. d->spell.spellEndCellY = 0;
  1906. d->spell.spellCheckSelection = false;
  1907. d->spell.currentCell = d->activeSheet->firstCell();
  1908. }
  1909. else
  1910. {
  1911. d->spell.spellStartCellX = selection.left();
  1912. d->spell.spellStartCellY = selection.top();
  1913. d->spell.spellEndCellX = selection.right();
  1914. d->spell.spellEndCellY = selection.bottom();
  1915. d->spell.spellCheckSelection = true;
  1916. d->spell.currentCell = 0L;
  1917. // "-1" because X gets increased every time we go into spellCheckReady()
  1918. d->spell.spellCurrCellX = d->spell.spellStartCellX - 1;
  1919. d->spell.spellCurrCellY = d->spell.spellStartCellY;
  1920. }
  1921. startKSpell();
  1922. }
  1923. void View::startKSpell()
  1924. {
  1925. if ( doc()->getKSpellConfig() )
  1926. {
  1927. doc()->getKSpellConfig()->setIgnoreList( doc()->spellListIgnoreAll() );
  1928. doc()->getKSpellConfig()->setReplaceAllList( d->spell.replaceAll );
  1929. }
  1930. d->spell.tdespell = new KSpell( this, i18n( "Spell Checking" ), TQT_TQOBJECT(this),
  1931. TQT_SLOT( spellCheckerReady() ),
  1932. doc()->getKSpellConfig() );
  1933. d->spell.tdespell->setIgnoreUpperWords( doc()->dontCheckUpperWord() );
  1934. d->spell.tdespell->setIgnoreTitleCase( doc()->dontCheckTitleCase() );
  1935. TQT_BASE_OBJECT_NAME::connect( d->spell.tdespell, TQT_SIGNAL( death() ),
  1936. this, TQT_SLOT( spellCheckerFinished() ) );
  1937. TQT_BASE_OBJECT_NAME::connect( d->spell.tdespell, TQT_SIGNAL( misspelling( const TQString &,
  1938. const TQStringList &,
  1939. unsigned int) ),
  1940. this, TQT_SLOT( spellCheckerMisspelling( const TQString &,
  1941. const TQStringList &,
  1942. unsigned int) ) );
  1943. TQT_BASE_OBJECT_NAME::connect( d->spell.tdespell, TQT_SIGNAL( corrected( const TQString &,
  1944. const TQString &,
  1945. unsigned int) ),
  1946. this, TQT_SLOT( spellCheckerCorrected( const TQString &,
  1947. const TQString &,
  1948. unsigned int ) ) );
  1949. TQT_BASE_OBJECT_NAME::connect( d->spell.tdespell, TQT_SIGNAL( done( const TQString & ) ),
  1950. this, TQT_SLOT( spellCheckerDone( const TQString & ) ) );
  1951. TQT_BASE_OBJECT_NAME::connect( d->spell.tdespell, TQT_SIGNAL( ignoreall (const TQString & ) ),
  1952. this, TQT_SLOT( spellCheckerIgnoreAll( const TQString & ) ) );
  1953. TQT_BASE_OBJECT_NAME::connect( d->spell.tdespell, TQT_SIGNAL( replaceall( const TQString & , const TQString & )), this, TQT_SLOT( spellCheckerReplaceAll( const TQString & , const TQString & )));
  1954. }
  1955. void View::spellCheckerReplaceAll( const TQString &orig, const TQString & replacement)
  1956. {
  1957. d->spell.replaceAll.append( orig);
  1958. d->spell.replaceAll.append( replacement);
  1959. }
  1960. void View::spellCheckerIgnoreAll( const TQString & word)
  1961. {
  1962. doc()->addIgnoreWordAll( word );
  1963. }
  1964. void View::spellCheckerReady()
  1965. {
  1966. if (d->canvas)
  1967. d->canvas->setCursor( WaitCursor );
  1968. // go on to the next cell
  1969. if (!d->spell.spellCheckSelection)
  1970. {
  1971. // if nothing is selected we have to check every cell
  1972. // we use a different way to make it faster
  1973. while ( d->spell.currentCell )
  1974. {
  1975. // check text only
  1976. if ( d->spell.currentCell->value().isString() )
  1977. {
  1978. d->spell.tdespell->check( d->spell.currentCell->text(), true );
  1979. return;
  1980. }
  1981. d->spell.currentCell = d->spell.currentCell->nextCell();
  1982. if ( d->spell.currentCell && d->spell.currentCell->isDefault() )
  1983. kdDebug() << "checking default cell!!" << endl << endl;
  1984. }
  1985. if (spellSwitchToOtherSheet())
  1986. spellCheckerReady();
  1987. else
  1988. spellCleanup();
  1989. return;
  1990. }
  1991. // if something is selected:
  1992. ++d->spell.spellCurrCellX;
  1993. if (d->spell.spellCurrCellX > d->spell.spellEndCellX)
  1994. {
  1995. d->spell.spellCurrCellX = d->spell.spellStartCellX;
  1996. ++d->spell.spellCurrCellY;
  1997. }
  1998. unsigned int y;
  1999. unsigned int x;
  2000. for ( y = d->spell.spellCurrCellY; y <= d->spell.spellEndCellY; ++y )
  2001. {
  2002. for ( x = d->spell.spellCurrCellX; x <= d->spell.spellEndCellX; ++x )
  2003. {
  2004. Cell * cell = d->spell.currentSpellSheet->cellAt( x, y );
  2005. // check text only
  2006. if (cell->isDefault() || !cell->value().isString())
  2007. continue;
  2008. d->spell.spellCurrCellX = x;
  2009. d->spell.spellCurrCellY = y;
  2010. d->spell.tdespell->check( cell->text(), true );
  2011. return;
  2012. }
  2013. d->spell.spellCurrCellX = d->spell.spellStartCellX;
  2014. }
  2015. // if the user selected something to be checked we are done
  2016. // otherwise ask for checking the next sheet if any
  2017. if (d->spell.spellCheckSelection)
  2018. {
  2019. // Done
  2020. spellCleanup();
  2021. }
  2022. else
  2023. {
  2024. if (spellSwitchToOtherSheet())
  2025. spellCheckerReady();
  2026. else
  2027. spellCleanup();
  2028. }
  2029. }
  2030. void View::spellCleanup()
  2031. {
  2032. if ( d->canvas )
  2033. d->canvas->setCursor( ArrowCursor );
  2034. d->spell.tdespell->cleanUp();
  2035. delete d->spell.tdespell;
  2036. d->spell.tdespell = 0L;
  2037. d->spell.firstSpellSheet = 0L;
  2038. d->spell.currentSpellSheet = 0L;
  2039. d->spell.currentCell = 0L;
  2040. d->spell.replaceAll.clear();
  2041. KMessageBox::information( this, i18n( "Spell checking is complete." ) );
  2042. if ( d->spell.macroCmdSpellCheck )
  2043. doc()->addCommand( d->spell.macroCmdSpellCheck );
  2044. d->spell.macroCmdSpellCheck=0L;
  2045. }
  2046. bool View::spellSwitchToOtherSheet()
  2047. {
  2048. // there is no other sheet
  2049. if ( doc()->map()->count() == 1 )
  2050. return false;
  2051. // for optimization
  2052. TQPtrList<Sheet> sheetList = doc()->map()->sheetList();
  2053. unsigned int curIndex = sheetList.findRef(d->spell.currentSpellSheet);
  2054. ++curIndex;
  2055. // last sheet? then start at the beginning
  2056. if ( curIndex >= sheetList.count() )
  2057. d->spell.currentSpellSheet = sheetList.first();
  2058. else
  2059. d->spell.currentSpellSheet = sheetList.at(curIndex);
  2060. // if the current sheet is the first one again, we are done.
  2061. if ( d->spell.currentSpellSheet == d->spell.firstSpellSheet )
  2062. {
  2063. setActiveSheet( d->spell.firstSpellSheet );
  2064. return false;
  2065. }
  2066. if (d->spell.spellCheckSelection)
  2067. {
  2068. d->spell.spellEndCellX = d->spell.currentSpellSheet->maxColumn();
  2069. d->spell.spellEndCellY = d->spell.currentSpellSheet->maxRow();
  2070. d->spell.spellCurrCellX = d->spell.spellStartCellX - 1;
  2071. d->spell.spellCurrCellY = d->spell.spellStartCellY;
  2072. }
  2073. else
  2074. {
  2075. d->spell.currentCell = d->spell.currentSpellSheet->firstCell();
  2076. }
  2077. if ( KMessageBox::questionYesNo( this,
  2078. i18n( "Do you want to check the spelling in the next sheet?") )
  2079. != KMessageBox::Yes )
  2080. return false;
  2081. setActiveSheet( d->spell.currentSpellSheet );
  2082. return true;
  2083. }
  2084. void View::spellCheckerMisspelling( const TQString &,
  2085. const TQStringList &,
  2086. unsigned int )
  2087. {
  2088. // scroll to the cell
  2089. if ( !d->spell.spellCheckSelection )
  2090. {
  2091. d->spell.spellCurrCellX = d->spell.currentCell->column();
  2092. d->spell.spellCurrCellY = d->spell.currentCell->row();
  2093. }
  2094. d->selection->initialize(TQPoint(d->spell.spellCurrCellX, d->spell.spellCurrCellY));
  2095. }
  2096. void View::spellCheckerCorrected( const TQString & old, const TQString & corr,
  2097. unsigned int pos )
  2098. {
  2099. Cell * cell;
  2100. if (d->spell.spellCheckSelection)
  2101. {
  2102. cell = d->spell.currentSpellSheet->cellAt( d->spell.spellCurrCellX,
  2103. d->spell.spellCurrCellY );
  2104. }
  2105. else
  2106. {
  2107. cell = d->spell.currentCell;
  2108. d->spell.spellCurrCellX = cell->column();
  2109. d->spell.spellCurrCellY = cell->row();
  2110. }
  2111. Q_ASSERT( cell );
  2112. if ( !cell )
  2113. return;
  2114. doc()->emitBeginOperation(false);
  2115. TQString content( cell->text() );
  2116. UndoSetText* undo = new UndoSetText( doc(), d->activeSheet,
  2117. content,
  2118. d->spell.spellCurrCellX,
  2119. d->spell.spellCurrCellY,
  2120. cell->formatType());
  2121. content.replace( pos, old.length(), corr );
  2122. cell->setCellText( content );
  2123. d->editWidget->setText( content );
  2124. if ( !d->spell.macroCmdSpellCheck )
  2125. d->spell.macroCmdSpellCheck = new MacroUndoAction( doc(), i18n("Correct Misspelled Word") );
  2126. d->spell.macroCmdSpellCheck->addCommand( undo );
  2127. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  2128. }
  2129. void View::spellCheckerDone( const TQString & )
  2130. {
  2131. int result = d->spell.tdespell->dlgResult();
  2132. d->spell.tdespell->cleanUp();
  2133. delete d->spell.tdespell;
  2134. d->spell.tdespell = 0L;
  2135. if ( result != KS_CANCEL && result != KS_STOP )
  2136. {
  2137. if (d->spell.spellCheckSelection)
  2138. {
  2139. if ( (d->spell.spellCurrCellY <= d->spell.spellEndCellY)
  2140. && (d->spell.spellCurrCellX <= d->spell.spellEndCellX) )
  2141. {
  2142. startKSpell();
  2143. return;
  2144. }
  2145. }
  2146. else
  2147. {
  2148. if ( d->spell.currentCell )
  2149. {
  2150. d->spell.currentCell = d->spell.currentCell->nextCell();
  2151. startKSpell();
  2152. return;
  2153. }
  2154. }
  2155. }
  2156. d->spell.replaceAll.clear();
  2157. if ( d->spell.macroCmdSpellCheck )
  2158. {
  2159. doc()->addCommand( d->spell.macroCmdSpellCheck );
  2160. }
  2161. d->spell.macroCmdSpellCheck=0L;
  2162. }
  2163. void View::spellCheckerFinished()
  2164. {
  2165. if (d->canvas)
  2166. d->canvas->setCursor( ArrowCursor );
  2167. KSpell::spellStatus status = d->spell.tdespell->status();
  2168. d->spell.tdespell->cleanUp();
  2169. delete d->spell.tdespell;
  2170. d->spell.tdespell = 0L;
  2171. d->spell.replaceAll.clear();
  2172. bool tdespellNotConfigured=false;
  2173. if (status == KSpell::Error)
  2174. {
  2175. KMessageBox::sorry(this, i18n("ISpell could not be started.\n"
  2176. "Please make sure you have ISpell properly configured and in your PATH."));
  2177. tdespellNotConfigured=true;
  2178. }
  2179. else if (status == KSpell::Crashed)
  2180. {
  2181. KMessageBox::sorry(this, i18n("ISpell seems to have crashed."));
  2182. }
  2183. if (d->spell.macroCmdSpellCheck)
  2184. {
  2185. doc()->addCommand( d->spell.macroCmdSpellCheck );
  2186. }
  2187. d->spell.macroCmdSpellCheck=0L;
  2188. if (tdespellNotConfigured)
  2189. {
  2190. PreferenceDialog configDlg( this, 0 );
  2191. configDlg.openPage( PreferenceDialog::KS_SPELLING);
  2192. configDlg.exec();
  2193. }
  2194. }
  2195. void View::initialPosition()
  2196. {
  2197. // Loading completed, pick initial worksheet
  2198. TQPtrListIterator<Sheet> it( doc()->map()->sheetList() );
  2199. for( ; it.current(); ++it )
  2200. addSheet( it.current() );
  2201. // Set the initial X and Y offsets for the view (OpenDocument loading)
  2202. if ( KSPLoadingInfo* loadingInfo = doc()->loadingInfo() )
  2203. {
  2204. d->savedAnchors = loadingInfo->cursorPositions();
  2205. d->savedMarkers = loadingInfo->cursorPositions();
  2206. d->savedOffsets = loadingInfo->scrollingOffsets();
  2207. }
  2208. Sheet * tbl = 0L;
  2209. if ( doc()->isEmbedded() )
  2210. {
  2211. tbl = doc()->displaySheet();
  2212. }
  2213. if ( !tbl )
  2214. tbl = doc()->map()->initialActiveSheet();
  2215. if ( tbl )
  2216. setActiveSheet( tbl );
  2217. else
  2218. {
  2219. //activate first table which is not hiding
  2220. tbl = doc()->map()->findSheet( doc()->map()->visibleSheets().first());
  2221. if ( !tbl )
  2222. {
  2223. tbl = doc()->map()->firstSheet();
  2224. if ( tbl )
  2225. {
  2226. tbl->setHidden( false );
  2227. TQString tabName = tbl->sheetName();
  2228. d->tabBar->addTab( tabName );
  2229. }
  2230. }
  2231. setActiveSheet( tbl );
  2232. }
  2233. refreshView();
  2234. // Set the initial X and Y offsets for the view (Native format loading)
  2235. if ( !doc()->loadingInfo() )
  2236. {
  2237. double offsetX = doc()->map()->initialXOffset();
  2238. double offsetY = doc()->map()->initialYOffset();
  2239. // Set the initial position for the marker as stored in the XML file,
  2240. // (1,1) otherwise
  2241. int col = doc()->map()->initialMarkerColumn();
  2242. if ( col <= 0 )
  2243. col = 1;
  2244. int row = doc()->map()->initialMarkerRow();
  2245. if ( row <= 0 )
  2246. row = 1;
  2247. d->canvas->setXOffset( offsetX );
  2248. d->canvas->setYOffset( offsetY );
  2249. d->horzScrollBar->setValue( (int)offsetX );
  2250. d->vertScrollBar->setValue( (int)offsetY );
  2251. d->selection->initialize( TQPoint(col, row) );
  2252. }
  2253. updateBorderButton();
  2254. updateShowSheetMenu();
  2255. d->actions->autoFormat->setEnabled(false);
  2256. d->actions->sort->setEnabled(false);
  2257. d->actions->mergeCell->setEnabled(false);
  2258. d->actions->mergeCellHorizontal->setEnabled(false);
  2259. d->actions->mergeCellVertical->setEnabled(false);
  2260. d->actions->createStyle->setEnabled(false);
  2261. d->actions->fillUp->setEnabled( false );
  2262. d->actions->fillRight->setEnabled( false );
  2263. d->actions->fillDown->setEnabled( false );
  2264. d->actions->fillLeft->setEnabled( false );
  2265. // make paint effective:
  2266. doc()->decreaseNumOperation();
  2267. TQRect vr( activeSheet()->visibleRect( d->canvas ) );
  2268. doc()->emitBeginOperation( false );
  2269. activeSheet()->setRegionPaintDirty( vr );
  2270. doc()->emitEndOperation( vr );
  2271. if ( koDocument()->isReadWrite() )
  2272. initConfig();
  2273. d->adjustActions( !d->activeSheet->isProtected() );
  2274. d->adjustWorkbookActions( !doc()->map()->isProtected() );
  2275. // finish the "View Loading" process
  2276. d->loading = false;
  2277. doc()->deleteLoadingInfo();
  2278. }
  2279. void View::updateEditWidgetOnPress()
  2280. {
  2281. if (!d->activeSheet)
  2282. return;
  2283. int column = d->canvas->markerColumn();
  2284. int row = d->canvas->markerRow();
  2285. Cell* cell = d->activeSheet->cellAt( column, row );
  2286. if ( !cell )
  2287. {
  2288. d->editWidget->setText( "" );
  2289. return;
  2290. }
  2291. if ( d->activeSheet->isProtected() && cell->format()->isHideFormula( column, row ) )
  2292. d->editWidget->setText( cell->strOutText() );
  2293. else if ( d->activeSheet->isProtected() && cell->format()->isHideAll( column, row ) )
  2294. d->editWidget->setText( "" );
  2295. else
  2296. d->editWidget->setText( cell->text() );
  2297. d->updateButton(cell, column, row);
  2298. d->adjustActions( d->activeSheet, cell );
  2299. }
  2300. void View::updateEditWidget()
  2301. {
  2302. if (!d->activeSheet)
  2303. return;
  2304. int column = d->canvas->markerColumn();
  2305. int row = d->canvas->markerRow();
  2306. Cell * cell = d->activeSheet->cellAt( column, row );
  2307. bool active = activeSheet()->getShowFormula()
  2308. && !( d->activeSheet->isProtected() && cell && cell->format()->isHideFormula( column, row ) );
  2309. if ( d->activeSheet && !d->activeSheet->isProtected() )
  2310. {
  2311. d->actions->alignLeft->setEnabled(!active);
  2312. d->actions->alignCenter->setEnabled(!active);
  2313. d->actions->alignRight->setEnabled(!active);
  2314. }
  2315. if ( !cell )
  2316. {
  2317. d->editWidget->setText( "" );
  2318. if ( d->activeSheet->isProtected() )
  2319. d->editWidget->setEnabled( false );
  2320. else
  2321. d->editWidget->setEnabled( true );
  2322. return;
  2323. }
  2324. if ( d->activeSheet->isProtected() && cell->format()->isHideFormula( column, row ) )
  2325. d->editWidget->setText( cell->strOutText() );
  2326. else if ( d->activeSheet->isProtected() && cell->format()->isHideAll( column, row ) )
  2327. d->editWidget->setText( "" );
  2328. else
  2329. d->editWidget->setText( cell->text() );
  2330. if ( d->activeSheet->isProtected() && !cell->format()->notProtected( column, row ) )
  2331. d->editWidget->setEnabled( false );
  2332. else
  2333. d->editWidget->setEnabled( true );
  2334. if ( d->canvas->editor() )
  2335. {
  2336. d->canvas->editor()->setEditorFont(cell->format()->textFont(column, row), true);
  2337. d->canvas->editor()->setFocus();
  2338. }
  2339. d->updateButton(cell, column, row);
  2340. d->adjustActions( d->activeSheet, cell );
  2341. }
  2342. void View::activateFormulaEditor()
  2343. {
  2344. }
  2345. void View::objectSelectedChanged()
  2346. {
  2347. if ( d->canvas->isObjectSelected() )
  2348. d->actions->actionExtraProperties->setEnabled( true );
  2349. else
  2350. d->actions->actionExtraProperties->setEnabled( false );
  2351. }
  2352. void View::updateReadWrite( bool readwrite )
  2353. {
  2354. // d->cancelButton->setEnabled( readwrite );
  2355. // d->okButton->setEnabled( readwrite );
  2356. d->editWidget->setEnabled( readwrite );
  2357. TQValueList<TDEAction*> actions = actionCollection()->actions();
  2358. TQValueList<TDEAction*>::ConstIterator aIt = actions.begin();
  2359. TQValueList<TDEAction*>::ConstIterator aEnd = actions.end();
  2360. for (; aIt != aEnd; ++aIt )
  2361. (*aIt)->setEnabled( readwrite );
  2362. // d->actions->transform->setEnabled( false );
  2363. if ( !doc() || !doc()->map() || doc()->map()->isProtected() )
  2364. {
  2365. d->actions->showSheet->setEnabled( false );
  2366. d->actions->hideSheet->setEnabled( false );
  2367. }
  2368. else
  2369. {
  2370. d->actions->showSheet->setEnabled( true );
  2371. d->actions->hideSheet->setEnabled( true );
  2372. }
  2373. d->actions->gotoCell->setEnabled( true );
  2374. d->actions->viewZoom->setEnabled( true );
  2375. d->actions->showPageBorders->setEnabled( true );
  2376. d->actions->find->setEnabled( true);
  2377. d->actions->replace->setEnabled( readwrite );
  2378. if ( !doc()->isReadWrite())
  2379. d->actions->copy->setEnabled( true );
  2380. // d->actions->newView->setEnabled( true );
  2381. //doc()->KXMLGUIClient::action( "newView" )->setEnabled( true ); // obsolete (Werner)
  2382. }
  2383. void View::createTemplate()
  2384. {
  2385. int width = 60;
  2386. int height = 60;
  2387. TQPixmap pix = doc()->generatePreview(TQSize(width, height));
  2388. KTempFile tempFile( TQString(), ".kst" );
  2389. //Check that creation of temp file was successful
  2390. if (tempFile.status() != 0)
  2391. {
  2392. tqWarning("Creation of temprary file to store template failed.");
  2393. return;
  2394. }
  2395. tempFile.setAutoDelete(true);
  2396. doc()->saveNativeFormat( tempFile.name() );
  2397. KoTemplateCreateDia::createTemplate( "kspread_template", Factory::global(),
  2398. tempFile.name(), pix, this );
  2399. Factory::global()->dirs()->addResourceType("kspread_template",
  2400. TDEStandardDirs::kde_default( "data" ) +
  2401. "kspread/templates/");
  2402. }
  2403. void View::sheetFormat()
  2404. {
  2405. FormatDialog dlg( this );
  2406. dlg.exec();
  2407. }
  2408. void View::autoSum()
  2409. {
  2410. if (!activeSheet())
  2411. return;
  2412. // ######## Torben: Make sure that this can not be called
  2413. // when canvas has a running editor
  2414. if ( d->canvas->editor() )
  2415. return;
  2416. //Get the selected range and remove the current cell from it (as that is
  2417. //where the result of the autosum will be stored - perhaps change
  2418. //this behaviour??)
  2419. Range rg;
  2420. //rg.sheet=activeSheet();
  2421. TQRect sel = d->selection->selection(false);
  2422. if (sel.height() > 1)
  2423. {
  2424. if (d->selection->marker().y()==sel.top())
  2425. sel.setTop(sel.top()+1);
  2426. if (d->selection->marker().y()==sel.bottom())
  2427. sel.setBottom(sel.bottom()-1);
  2428. }
  2429. else
  2430. {
  2431. if (sel.width() > 1)
  2432. {
  2433. if (d->selection->marker().x()==sel.left())
  2434. sel.setLeft(sel.left()+1);
  2435. if (d->selection->marker().x()==sel.right())
  2436. sel.setRight(sel.right()-1);
  2437. }
  2438. else
  2439. {
  2440. sel=TQRect();
  2441. // only 1 cell selected
  2442. // try to automagically find cells the user wants to sum up
  2443. int start = -1, end = -1;
  2444. if ( (d->selection->marker().y() > 1) && activeSheet()->cellAt(d->selection->marker().x(), d->selection->marker().y()-1)->value().isNumber() )
  2445. {
  2446. // check cells above the current one
  2447. start = end = d->selection->marker().y()-1;
  2448. for (start--; (start > 0) && activeSheet()->cellAt(d->selection->marker().x(), start)->value().isNumber(); start--) ;
  2449. Point startPoint, endPoint;
  2450. startPoint.setRow(start+1);
  2451. startPoint.setColumn(d->selection->marker().x());
  2452. endPoint.setRow(end);
  2453. endPoint.setColumn(d->selection->marker().x());
  2454. TQString str = Range(startPoint, endPoint).toString();
  2455. d->canvas->createEditor( Canvas::CellEditor , true , true );
  2456. d->canvas->editor()->setText("=SUM(" + str + ")");
  2457. d->canvas->editor()->setCursorPosition(5 + str.length());
  2458. return;
  2459. }
  2460. else if ( (d->selection->marker().x() > 1) && activeSheet()->cellAt(d->selection->marker().x()-1, d->selection->marker().y())->value().isNumber() )
  2461. {
  2462. // check cells to the left of the current one
  2463. start = end = d->selection->marker().x()-1;
  2464. for (start--; (start > 0) && activeSheet()->cellAt(start, d->selection->marker().y())->value().isNumber(); start--) ;
  2465. Point startPoint, endPoint;
  2466. startPoint.setColumn(start+1);
  2467. startPoint.setRow(d->selection->marker().y());
  2468. endPoint.setColumn(end);
  2469. endPoint.setRow(d->selection->marker().y());
  2470. TQString str = Range(startPoint, endPoint).toString();
  2471. d->canvas->createEditor( Canvas::CellEditor , true , true );
  2472. d->canvas->editor()->setText("=SUM(" + str + ")");
  2473. d->canvas->editor()->setCursorPosition(5 + str.length());
  2474. return;
  2475. }
  2476. }
  2477. }
  2478. if ( (sel.width() > 1) && (sel.height() > 1) )
  2479. sel=TQRect();
  2480. rg.setRange(sel);
  2481. d->canvas->createEditor( Canvas::CellEditor , true , true );
  2482. if ( (rg.range().isValid() ) && (!rg.range().isEmpty()) )
  2483. {
  2484. d->canvas->editor()->setText( "=SUM("+rg.toString()+")" );
  2485. d->canvas->deleteEditor(true);
  2486. }
  2487. else
  2488. {
  2489. d->canvas->startChoose();
  2490. d->canvas->editor()->setText( "=SUM()" );
  2491. d->canvas->editor()->setCursorPosition( 5 );
  2492. }
  2493. }
  2494. /*
  2495. void View::oszilloscope()
  2496. {
  2497. TQDialog* dlg = new OsziDlg( this );
  2498. dlg->show();
  2499. }
  2500. */
  2501. void View::changeTextColor()
  2502. {
  2503. if ( d->activeSheet != 0L )
  2504. {
  2505. doc()->emitBeginOperation(false);
  2506. d->activeSheet->setSelectionTextColor( selectionInfo(), d->actions->textColor->color() );
  2507. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  2508. }
  2509. }
  2510. void View::setSelectionTextColor(const TQColor &txtColor)
  2511. {
  2512. if (d->activeSheet != 0L)
  2513. {
  2514. doc()->emitBeginOperation(false);
  2515. d->activeSheet->setSelectionTextColor( selectionInfo(), txtColor );
  2516. markSelectionAsDirty();
  2517. doc()->emitEndOperation();
  2518. }
  2519. }
  2520. void View::changeBackgroundColor()
  2521. {
  2522. if ( d->activeSheet != 0L )
  2523. {
  2524. doc()->emitBeginOperation(false);
  2525. d->activeSheet->setSelectionbgColor( selectionInfo(), d->actions->bgColor->color() );
  2526. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  2527. }
  2528. }
  2529. void View::setSelectionBackgroundColor(const TQColor &bgColor)
  2530. {
  2531. if (d->activeSheet != 0L)
  2532. {
  2533. doc()->emitBeginOperation(false);
  2534. d->activeSheet->setSelectionbgColor( selectionInfo(), bgColor );
  2535. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  2536. }
  2537. }
  2538. void View::changeBorderColor()
  2539. {
  2540. if ( d->activeSheet != 0L )
  2541. {
  2542. doc()->emitBeginOperation(false);
  2543. d->activeSheet->setSelectionBorderColor( selectionInfo(), d->actions->borderColor->color() );
  2544. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  2545. }
  2546. }
  2547. void View::setSelectionBorderColor(const TQColor &bdColor)
  2548. {
  2549. if (d->activeSheet != 0L)
  2550. {
  2551. doc()->emitBeginOperation(false);
  2552. d->activeSheet->setSelectionBorderColor( selectionInfo(), bdColor );
  2553. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  2554. }
  2555. }
  2556. void View::helpUsing()
  2557. {
  2558. kapp->invokeHelp( );
  2559. }
  2560. void View::enableUndo( bool _b )
  2561. {
  2562. TDEAction* action = actionCollection()->action( "office_undo" );
  2563. if( action ) action->setEnabled( _b );
  2564. }
  2565. void View::enableRedo( bool _b )
  2566. {
  2567. TDEAction* action = actionCollection()->action( "office_redo" );
  2568. if( action ) action->setEnabled( _b );
  2569. }
  2570. void View::enableInsertColumn( bool _b )
  2571. {
  2572. if ( d->activeSheet && !d->activeSheet->isProtected() )
  2573. d->actions->insertColumn->setEnabled( _b );
  2574. }
  2575. void View::enableInsertRow( bool _b )
  2576. {
  2577. if ( d->activeSheet && !d->activeSheet->isProtected() )
  2578. d->actions->insertRow->setEnabled( _b );
  2579. }
  2580. void View::deleteColumn()
  2581. {
  2582. if ( !d->activeSheet )
  2583. return;
  2584. doc()->emitBeginOperation( false );
  2585. TQRect r( d->selection->selection() );
  2586. d->activeSheet->removeColumn( r.left(), ( r.right()-r.left() ) );
  2587. updateEditWidget();
  2588. // Stefan: update the selection after deleting (a) column(s)
  2589. d->selection->update();
  2590. TQRect vr( d->activeSheet->visibleRect( d->canvas ) );
  2591. vr.setLeft( r.left() );
  2592. doc()->emitEndOperation( vr );
  2593. }
  2594. void View::deleteRow()
  2595. {
  2596. if ( !d->activeSheet )
  2597. return;
  2598. doc()->emitBeginOperation( false );
  2599. TQRect r( d->selection->selection() );
  2600. d->activeSheet->removeRow( r.top(),(r.bottom()-r.top()) );
  2601. updateEditWidget();
  2602. // Stefan: update the selection after deleting (a) column(s)
  2603. d->selection->update();
  2604. TQRect vr( d->activeSheet->visibleRect( d->canvas ) );
  2605. vr.setTop( r.top() );
  2606. doc()->emitEndOperation( vr );
  2607. }
  2608. void View::insertColumn()
  2609. {
  2610. if ( !d->activeSheet )
  2611. return;
  2612. doc()->emitBeginOperation( false );
  2613. TQRect r( d->selection->selection() );
  2614. d->activeSheet->insertColumn( r.left(), ( r.right()-r.left() ) );
  2615. updateEditWidget();
  2616. TQRect vr( d->activeSheet->visibleRect( d->canvas ) );
  2617. vr.setLeft( r.left() - 1 );
  2618. doc()->emitEndOperation( vr );
  2619. }
  2620. void View::hideColumn()
  2621. {
  2622. if ( !d->activeSheet )
  2623. return;
  2624. if ( d->selection->isRowSelected() )
  2625. {
  2626. KMessageBox::error( this, i18n( "Area is too large." ) );
  2627. return;
  2628. }
  2629. d->activeSheet->hideColumn(*selectionInfo());
  2630. }
  2631. void View::showColumn()
  2632. {
  2633. if ( !d->activeSheet )
  2634. return;
  2635. ShowColRow dlg( this, "showCol", ShowColRow::Column );
  2636. dlg.exec();
  2637. }
  2638. void View::showSelColumns()
  2639. {
  2640. if ( !d->activeSheet )
  2641. return;
  2642. d->activeSheet->showColumn(*selectionInfo());
  2643. }
  2644. void View::insertRow()
  2645. {
  2646. if ( !d->activeSheet )
  2647. return;
  2648. doc()->emitBeginOperation( false );
  2649. TQRect r( d->selection->selection() );
  2650. d->activeSheet->insertRow( r.top(), ( r.bottom() - r.top() ) );
  2651. updateEditWidget();
  2652. TQRect vr( d->activeSheet->visibleRect( d->canvas ) );
  2653. vr.setTop( r.top() - 1 );
  2654. doc()->emitEndOperation( vr );
  2655. }
  2656. void View::hideRow()
  2657. {
  2658. if ( !d->activeSheet )
  2659. return;
  2660. if ( d->selection->isColumnSelected() )
  2661. {
  2662. KMessageBox::error( this, i18n( "Area is too large." ) );
  2663. return;
  2664. }
  2665. d->activeSheet->hideRow(*selectionInfo());
  2666. }
  2667. void View::showRow()
  2668. {
  2669. if ( !d->activeSheet )
  2670. return;
  2671. ShowColRow dlg( this, "showRow", ShowColRow::Row );
  2672. dlg.exec();
  2673. }
  2674. void View::showSelRows()
  2675. {
  2676. if ( !d->activeSheet )
  2677. return;
  2678. d->activeSheet->showRow(*selectionInfo());
  2679. }
  2680. void View::fontSelected( const TQString & _font )
  2681. {
  2682. if ( d->toolbarLock )
  2683. return;
  2684. doc()->emitBeginOperation(false);
  2685. if ( d->activeSheet != 0L )
  2686. d->activeSheet->setSelectionFont( d->selection, _font.latin1() );
  2687. // Dont leave the focus in the toolbars combo box ...
  2688. if ( d->canvas->editor() )
  2689. {
  2690. Cell * cell = d->activeSheet->cellAt( d->selection->marker() );
  2691. d->canvas->editor()->setEditorFont( cell->format()->textFont( cell->column(), cell->row() ), true );
  2692. d->canvas->editor()->setFocus();
  2693. }
  2694. else
  2695. d->canvas->setFocus();
  2696. markSelectionAsDirty();
  2697. doc()->emitEndOperation();
  2698. }
  2699. void View::decreaseFontSize()
  2700. {
  2701. setSelectionFontSize( -1 );
  2702. }
  2703. void View::increaseFontSize()
  2704. {
  2705. setSelectionFontSize( 1 );
  2706. }
  2707. void View::setSelectionFontSize( int size )
  2708. {
  2709. if ( d->activeSheet != NULL )
  2710. {
  2711. d->activeSheet->setSelectionSize( selectionInfo(), size );
  2712. }
  2713. }
  2714. void View::lower()
  2715. {
  2716. if ( !d->activeSheet )
  2717. return;
  2718. doc()->emitBeginOperation( false );
  2719. d->activeSheet->setSelectionUpperLower( selectionInfo(), -1 );
  2720. updateEditWidget();
  2721. markSelectionAsDirty();
  2722. doc()->emitEndOperation();
  2723. }
  2724. void View::upper()
  2725. {
  2726. if ( !d->activeSheet )
  2727. return;
  2728. doc()->emitBeginOperation( false );
  2729. d->activeSheet->setSelectionUpperLower( selectionInfo(), 1 );
  2730. updateEditWidget();
  2731. markSelectionAsDirty();
  2732. doc()->emitEndOperation();
  2733. }
  2734. void View::firstLetterUpper()
  2735. {
  2736. if ( !d->activeSheet )
  2737. return;
  2738. doc()->emitBeginOperation( false );
  2739. d->activeSheet->setSelectionfirstLetterUpper( selectionInfo() );
  2740. updateEditWidget();
  2741. markSelectionAsDirty();
  2742. doc()->emitEndOperation();
  2743. }
  2744. void View::verticalText(bool b)
  2745. {
  2746. if ( !d->activeSheet )
  2747. return;
  2748. doc()->emitBeginOperation( false );
  2749. d->activeSheet->setSelectionVerticalText( selectionInfo(), b );
  2750. d->activeSheet->adjustArea(*selectionInfo());
  2751. updateEditWidget(); // TODO Stefan: nescessary?
  2752. markSelectionAsDirty();
  2753. doc()->emitEndOperation();
  2754. }
  2755. void View::insertSpecialChar()
  2756. {
  2757. TQString f( d->actions->selectFont->font() );
  2758. TQChar c = ' ';
  2759. if ( d->specialCharDlg == 0 )
  2760. {
  2761. d->specialCharDlg = new KoCharSelectDia( this, "insert special char", f, c, false );
  2762. connect( d->specialCharDlg, TQT_SIGNAL( insertChar( TQChar, const TQString & ) ),
  2763. this, TQT_SLOT( slotSpecialChar( TQChar, const TQString & ) ) );
  2764. connect( d->specialCharDlg, TQT_SIGNAL( finished() ),
  2765. this, TQT_SLOT( slotSpecialCharDlgClosed() ) );
  2766. }
  2767. d->specialCharDlg->show();
  2768. }
  2769. void View::slotSpecialCharDlgClosed()
  2770. {
  2771. if ( d->specialCharDlg )
  2772. {
  2773. disconnect( d->specialCharDlg, TQT_SIGNAL(insertChar(TQChar,const TQString &)),
  2774. this, TQT_SLOT(slotSpecialChar(TQChar,const TQString &)));
  2775. disconnect( d->specialCharDlg, TQT_SIGNAL( finished() ),
  2776. this, TQT_SLOT( slotSpecialCharDlgClosed() ) );
  2777. d->specialCharDlg->deleteLater();
  2778. d->specialCharDlg = 0L;
  2779. }
  2780. }
  2781. void View::slotSpecialChar( TQChar c, const TQString & _font )
  2782. {
  2783. if ( d->activeSheet )
  2784. {
  2785. TQPoint marker( d->selection->marker() );
  2786. Cell * cell = d->activeSheet->nonDefaultCell( marker );
  2787. if ( cell->format()->textFont( marker.x(), marker.y() ).family() != _font )
  2788. {
  2789. cell->format()->setTextFontFamily( _font );
  2790. }
  2791. EditWidget * edit = d->editWidget;
  2792. TQKeyEvent ev( TQEvent::KeyPress, 0, 0, 0, TQString( c ) );
  2793. TQApplication::sendEvent( edit, &ev );
  2794. }
  2795. }
  2796. void View::insertMathExpr()
  2797. {
  2798. if ( d->activeSheet == 0L )
  2799. return;
  2800. FormulaDialog * dlg = new FormulaDialog( this, "Function" );
  2801. dlg->show();
  2802. /* TODO - because I search on 'TODO's :-) */
  2803. // #### Is the dialog deleted when it's closed ? (David)
  2804. // Torben thinks that not.
  2805. }
  2806. void View::formulaSelection( const TQString &_math )
  2807. {
  2808. if ( d->activeSheet == 0 )
  2809. return;
  2810. if ( _math == i18n("Others...") )
  2811. {
  2812. insertMathExpr();
  2813. return;
  2814. }
  2815. FormulaDialog *dlg = new FormulaDialog( this, "Formula Editor", _math );
  2816. dlg->exec();
  2817. }
  2818. void View::fontSizeSelected( int _size )
  2819. {
  2820. if ( d->toolbarLock )
  2821. return;
  2822. doc()->emitBeginOperation( false );
  2823. if ( d->activeSheet != 0L )
  2824. d->activeSheet->setSelectionFont( selectionInfo(), 0L, _size );
  2825. // Dont leave the focus in the toolbars combo box ...
  2826. if ( d->canvas->editor() )
  2827. {
  2828. Cell * cell = d->activeSheet->cellAt( d->selection->marker() );
  2829. d->canvas->editor()->setEditorFont( cell->format()->textFont( d->canvas->markerColumn(),
  2830. d->canvas->markerRow() ), true );
  2831. d->canvas->editor()->setFocus();
  2832. }
  2833. else
  2834. d->canvas->setFocus();
  2835. markSelectionAsDirty();
  2836. doc()->emitEndOperation();
  2837. }
  2838. void View::bold( bool b )
  2839. {
  2840. if ( d->toolbarLock )
  2841. return;
  2842. if ( d->activeSheet == 0 )
  2843. return;
  2844. doc()->emitBeginOperation( false );
  2845. int col = d->canvas->markerColumn();
  2846. int row = d->canvas->markerRow();
  2847. d->activeSheet->setSelectionFont( selectionInfo(), 0L, -1, b );
  2848. if ( d->canvas->editor() )
  2849. {
  2850. Cell * cell = d->activeSheet->cellAt( col, row );
  2851. d->canvas->editor()->setEditorFont( cell->format()->textFont( col, row ), true );
  2852. }
  2853. markSelectionAsDirty();
  2854. doc()->emitEndOperation();
  2855. }
  2856. void View::underline( bool b )
  2857. {
  2858. if ( d->toolbarLock )
  2859. return;
  2860. if ( d->activeSheet == 0 )
  2861. return;
  2862. doc()->emitBeginOperation( false );
  2863. int col = d->canvas->markerColumn();
  2864. int row = d->canvas->markerRow();
  2865. d->activeSheet->setSelectionFont( selectionInfo(), 0L, -1, -1, -1 ,b );
  2866. if ( d->canvas->editor() )
  2867. {
  2868. Cell * cell = d->activeSheet->cellAt( col, row );
  2869. d->canvas->editor()->setEditorFont( cell->format()->textFont( col, row ), true );
  2870. }
  2871. markSelectionAsDirty();
  2872. doc()->emitEndOperation();
  2873. }
  2874. void View::strikeOut( bool b )
  2875. {
  2876. if ( d->toolbarLock )
  2877. return;
  2878. if ( d->activeSheet == 0 )
  2879. return;
  2880. doc()->emitBeginOperation( false );
  2881. int col = d->canvas->markerColumn();
  2882. int row = d->canvas->markerRow();
  2883. d->activeSheet->setSelectionFont( selectionInfo(), 0L, -1, -1, -1 ,-1, b );
  2884. if ( d->canvas->editor() )
  2885. {
  2886. Cell * cell = d->activeSheet->cellAt( col, row );
  2887. d->canvas->editor()->setEditorFont( cell->format()->textFont( col, row ), true );
  2888. }
  2889. markSelectionAsDirty();
  2890. doc()->emitEndOperation();
  2891. }
  2892. void View::italic( bool b )
  2893. {
  2894. if ( d->toolbarLock )
  2895. return;
  2896. if ( d->activeSheet == 0 )
  2897. return;
  2898. doc()->emitBeginOperation( false );
  2899. int col = d->canvas->markerColumn();
  2900. int row = d->canvas->markerRow();
  2901. d->activeSheet->setSelectionFont( selectionInfo(), 0L, -1, -1, b );
  2902. if ( d->canvas->editor() )
  2903. {
  2904. Cell * cell = d->activeSheet->cellAt( col, row );
  2905. d->canvas->editor()->setEditorFont( cell->format()->textFont( col, row ), true );
  2906. }
  2907. markSelectionAsDirty();
  2908. doc()->emitEndOperation();
  2909. }
  2910. void View::sortInc()
  2911. {
  2912. if (!activeSheet())
  2913. return;
  2914. TQRect range = d->selection->selection();
  2915. if ( d->selection->isSingular() )
  2916. {
  2917. KMessageBox::error( this, i18n( "You must select multiple cells." ) );
  2918. return;
  2919. }
  2920. doc()->emitBeginOperation( false );
  2921. // Entire row(s) selected ? Or just one row ?
  2922. if ( d->selection->isRowSelected() || range.top() == range.bottom() )
  2923. activeSheet()->sortByRow( range, range.top(), Sheet::Increase );
  2924. else
  2925. activeSheet()->sortByColumn( range, range.left(), Sheet::Increase );
  2926. updateEditWidget();
  2927. markSelectionAsDirty();
  2928. doc()->emitEndOperation();
  2929. }
  2930. void View::sortDec()
  2931. {
  2932. TQRect range = d->selection->selection();
  2933. if ( d->selection->isSingular() )
  2934. {
  2935. KMessageBox::error( this, i18n( "You must select multiple cells." ) );
  2936. return;
  2937. }
  2938. doc()->emitBeginOperation( false );
  2939. // Entire row(s) selected ? Or just one row ?
  2940. if ( d->selection->isRowSelected() || range.top() == range.bottom() )
  2941. activeSheet()->sortByRow( range, range.top(), Sheet::Decrease );
  2942. else
  2943. activeSheet()->sortByColumn( range, range.left(), Sheet::Decrease );
  2944. updateEditWidget();
  2945. markSelectionAsDirty();
  2946. doc()->emitEndOperation();
  2947. }
  2948. void View::borderBottom()
  2949. {
  2950. if ( d->activeSheet != 0L )
  2951. {
  2952. doc()->emitBeginOperation( false );
  2953. d->activeSheet->borderBottom( d->selection, d->actions->borderColor->color() );
  2954. markSelectionAsDirty();
  2955. doc()->emitEndOperation();
  2956. }
  2957. }
  2958. void View::setSelectionBottomBorderColor( const TQColor & color )
  2959. {
  2960. if ( d->activeSheet != 0L )
  2961. {
  2962. doc()->emitBeginOperation( false );
  2963. d->activeSheet->borderBottom( selectionInfo(), color );
  2964. markSelectionAsDirty();
  2965. doc()->emitEndOperation();
  2966. }
  2967. }
  2968. void View::borderRight()
  2969. {
  2970. if ( d->activeSheet != 0L )
  2971. {
  2972. doc()->emitBeginOperation( false );
  2973. if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
  2974. d->activeSheet->borderLeft( d->selection, d->actions->borderColor->color() );
  2975. else
  2976. d->activeSheet->borderRight( d->selection, d->actions->borderColor->color() );
  2977. markSelectionAsDirty();
  2978. doc()->emitEndOperation();
  2979. }
  2980. }
  2981. void View::setSelectionRightBorderColor( const TQColor & color )
  2982. {
  2983. if ( d->activeSheet != 0L )
  2984. {
  2985. doc()->emitBeginOperation( false );
  2986. if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
  2987. d->activeSheet->borderLeft( selectionInfo(), color );
  2988. else
  2989. d->activeSheet->borderRight( selectionInfo(), color );
  2990. markSelectionAsDirty();
  2991. doc()->emitEndOperation();
  2992. }
  2993. }
  2994. void View::borderLeft()
  2995. {
  2996. if ( d->activeSheet != 0L )
  2997. {
  2998. doc()->emitBeginOperation( false );
  2999. if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
  3000. d->activeSheet->borderRight( d->selection, d->actions->borderColor->color() );
  3001. else
  3002. d->activeSheet->borderLeft( d->selection, d->actions->borderColor->color() );
  3003. markSelectionAsDirty();
  3004. doc()->emitEndOperation();
  3005. }
  3006. }
  3007. void View::setSelectionLeftBorderColor( const TQColor & color )
  3008. {
  3009. if ( d->activeSheet != 0L )
  3010. {
  3011. doc()->emitBeginOperation( false );
  3012. if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
  3013. d->activeSheet->borderRight( selectionInfo(), color );
  3014. else
  3015. d->activeSheet->borderLeft( selectionInfo(), color );
  3016. markSelectionAsDirty();
  3017. doc()->emitEndOperation();
  3018. }
  3019. }
  3020. void View::borderTop()
  3021. {
  3022. if ( d->activeSheet != 0L )
  3023. {
  3024. doc()->emitBeginOperation( false );
  3025. d->activeSheet->borderTop( d->selection, d->actions->borderColor->color() );
  3026. markSelectionAsDirty();
  3027. doc()->emitEndOperation();
  3028. }
  3029. }
  3030. void View::setSelectionTopBorderColor( const TQColor & color )
  3031. {
  3032. if ( d->activeSheet != 0L )
  3033. {
  3034. doc()->emitBeginOperation( false );
  3035. d->activeSheet->borderTop( selectionInfo(), color );
  3036. markSelectionAsDirty();
  3037. doc()->emitEndOperation();
  3038. }
  3039. }
  3040. void View::borderOutline()
  3041. {
  3042. if ( d->activeSheet != 0L )
  3043. {
  3044. doc()->emitBeginOperation( false );
  3045. d->activeSheet->borderOutline( d->selection, d->actions->borderColor->color() );
  3046. markSelectionAsDirty();
  3047. doc()->emitEndOperation();
  3048. }
  3049. }
  3050. void View::setSelectionOutlineBorderColor( const TQColor & color )
  3051. {
  3052. if ( d->activeSheet != 0L )
  3053. {
  3054. doc()->emitBeginOperation( false );
  3055. d->activeSheet->borderOutline( selectionInfo(), color );
  3056. markSelectionAsDirty();
  3057. doc()->emitEndOperation();
  3058. }
  3059. }
  3060. void View::borderAll()
  3061. {
  3062. if ( d->activeSheet != 0L )
  3063. {
  3064. doc()->emitBeginOperation( false );
  3065. d->activeSheet->borderAll( d->selection, d->actions->borderColor->color() );
  3066. markSelectionAsDirty();
  3067. doc()->emitEndOperation();
  3068. }
  3069. }
  3070. void View::setSelectionAllBorderColor( const TQColor & color )
  3071. {
  3072. if ( d->activeSheet != 0L )
  3073. {
  3074. doc()->emitBeginOperation( false );
  3075. d->activeSheet->borderAll( selectionInfo(), color );
  3076. markSelectionAsDirty();
  3077. doc()->emitEndOperation();
  3078. }
  3079. }
  3080. void View::borderRemove()
  3081. {
  3082. if ( d->activeSheet != 0L )
  3083. {
  3084. doc()->emitBeginOperation(false);
  3085. d->activeSheet->borderRemove( d->selection );
  3086. markSelectionAsDirty();
  3087. doc()->emitEndOperation();
  3088. }
  3089. }
  3090. void View::addSheet( Sheet * _t )
  3091. {
  3092. doc()->emitBeginOperation( false );
  3093. insertSheet( _t );
  3094. // Connect some signals
  3095. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_refreshView() ), TQT_SLOT( slotRefreshView() ) );
  3096. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_updateView( Sheet* ) ), TQT_SLOT( slotUpdateView( Sheet* ) ) );
  3097. TQT_BASE_OBJECT_NAME::connect( _t->print(), TQT_SIGNAL( sig_updateView( Sheet* ) ), TQT_SLOT( slotUpdateView( Sheet* ) ) );
  3098. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_updateView( Sheet *, const Region& ) ),
  3099. TQT_SLOT( slotUpdateView( Sheet*, const Region& ) ) );
  3100. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_updateView( EmbeddedObject* )), TQT_SLOT( slotUpdateView( EmbeddedObject* ) ) );
  3101. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_updateHBorder( Sheet * ) ),
  3102. TQT_SLOT( slotUpdateHBorder( Sheet * ) ) );
  3103. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_updateVBorder( Sheet * ) ),
  3104. TQT_SLOT( slotUpdateVBorder( Sheet * ) ) );
  3105. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_nameChanged( Sheet*, const TQString& ) ),
  3106. this, TQT_SLOT( slotSheetRenamed( Sheet*, const TQString& ) ) );
  3107. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_SheetHidden( Sheet* ) ),
  3108. this, TQT_SLOT( slotSheetHidden( Sheet* ) ) );
  3109. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_SheetShown( Sheet* ) ),
  3110. this, TQT_SLOT( slotSheetShown( Sheet* ) ) );
  3111. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_SheetRemoved( Sheet* ) ),
  3112. this, TQT_SLOT( slotSheetRemoved( Sheet* ) ) );
  3113. // ########### Why do these signals not send a pointer to the sheet?
  3114. // This will lead to bugs.
  3115. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_updateChildGeometry( EmbeddedKOfficeObject* ) ),
  3116. TQT_SLOT( slotUpdateChildGeometry( EmbeddedKOfficeObject* ) ) );
  3117. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_maxColumn( int ) ), d->canvas, TQT_SLOT( slotMaxColumn( int ) ) );
  3118. TQT_BASE_OBJECT_NAME::connect( _t, TQT_SIGNAL( sig_maxRow( int ) ), d->canvas, TQT_SLOT( slotMaxRow( int ) ) );
  3119. if ( !d->loading )
  3120. updateBorderButton();
  3121. if ( !d->activeSheet )
  3122. {
  3123. doc()->emitEndOperation();
  3124. return;
  3125. }
  3126. doc()->emitEndOperation( *selectionInfo() );
  3127. }
  3128. void View::slotSheetRemoved( Sheet *_t )
  3129. {
  3130. doc()->emitBeginOperation( false );
  3131. TQString m_sheetName=_t->sheetName();
  3132. d->tabBar->removeTab( _t->sheetName() );
  3133. if (doc()->map()->findSheet( doc()->map()->visibleSheets().first()))
  3134. setActiveSheet( doc()->map()->findSheet( doc()->map()->visibleSheets().first() ));
  3135. else
  3136. d->activeSheet = 0L;
  3137. TQValueList<Reference>::Iterator it;
  3138. TQValueList<Reference> area=doc()->listArea();
  3139. for ( it = area.begin(); it != area.end(); ++it )
  3140. {
  3141. //remove Area Name when sheet target is removed
  3142. if ( (*it).sheet_name == m_sheetName )
  3143. {
  3144. doc()->removeArea( (*it).ref_name );
  3145. //now area name is used in formula
  3146. //so you must recalc sheets when remove areaname
  3147. Sheet * tbl;
  3148. for ( tbl = doc()->map()->firstSheet(); tbl != 0L; tbl = doc()->map()->nextSheet() )
  3149. {
  3150. tbl->refreshRemoveAreaName((*it).ref_name);
  3151. }
  3152. }
  3153. }
  3154. doc()->emitEndOperation( *selectionInfo() );
  3155. }
  3156. void View::removeAllSheets()
  3157. {
  3158. doc()->emitBeginOperation(false);
  3159. d->tabBar->clear();
  3160. setActiveSheet( 0L );
  3161. doc()->emitEndOperation();
  3162. }
  3163. void View::setActiveSheet( Sheet * _t, bool updateSheet )
  3164. {
  3165. if ( _t == d->activeSheet )
  3166. return;
  3167. doc()->emitBeginOperation(false);
  3168. saveCurrentSheetSelection();
  3169. Sheet * oldSheet = d->activeSheet;
  3170. d->activeSheet = _t;
  3171. if ( d->activeSheet == 0L )
  3172. {
  3173. doc()->emitEndOperation();
  3174. return;
  3175. }
  3176. if ( oldSheet && oldSheet->layoutDirection()==Sheet::RightToLeft != d->activeSheet->layoutDirection()==Sheet::RightToLeft )
  3177. refreshView();
  3178. doc()->setDisplaySheet( d->activeSheet );
  3179. if ( updateSheet )
  3180. {
  3181. d->tabBar->setActiveTab( _t->sheetName() );
  3182. d->vBorderWidget->repaint();
  3183. d->hBorderWidget->repaint();
  3184. d->activeSheet->setRegionPaintDirty(TQRect(TQPoint(0,0), TQPoint(KS_colMax, KS_rowMax)));
  3185. d->canvas->slotMaxColumn( d->activeSheet->maxColumn() );
  3186. d->canvas->slotMaxRow( d->activeSheet->maxRow() );
  3187. }
  3188. d->actions->showPageBorders->setChecked( d->activeSheet->isShowPageBorders() );
  3189. d->actions->protectSheet->setChecked( d->activeSheet->isProtected() );
  3190. d->actions->protectDoc->setChecked( doc()->map()->isProtected() );
  3191. d->adjustActions( !d->activeSheet->isProtected() );
  3192. d->adjustWorkbookActions( !doc()->map()->isProtected() );
  3193. /* see if there was a previous selection on this other sheet */
  3194. TQMapIterator<Sheet*, TQPoint> it = d->savedAnchors.find(d->activeSheet);
  3195. TQMapIterator<Sheet*, TQPoint> it2 = d->savedMarkers.find(d->activeSheet);
  3196. TQMapIterator<Sheet*, KoPoint> it3 = d->savedOffsets.find(d->activeSheet);
  3197. // TODO Stefan: store the save markers/anchors in the Selection?
  3198. TQPoint newAnchor = (it == d->savedAnchors.end()) ? TQPoint(1,1) : *it;
  3199. TQPoint newMarker = (it2 == d->savedMarkers.end()) ? TQPoint(1,1) : *it2;
  3200. d->selection->clear();
  3201. d->selection->setSheet( d->activeSheet );
  3202. d->selection->initialize(TQRect(newMarker, newAnchor));
  3203. d->canvas->scrollToCell(newMarker);
  3204. if (it3 != d->savedOffsets.end())
  3205. {
  3206. d->canvas->setXOffset((*it3).x());
  3207. d->canvas->setYOffset((*it3).y());
  3208. d->horzScrollBar->setValue((int)(*it3).x());
  3209. d->vertScrollBar->setValue((int)(*it3).y());
  3210. }
  3211. calcStatusBarOp();
  3212. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  3213. }
  3214. void View::slotSheetRenamed( Sheet* sheet, const TQString& old_name )
  3215. {
  3216. doc()->emitBeginOperation( false );
  3217. d->tabBar->renameTab( old_name, sheet->sheetName() );
  3218. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  3219. }
  3220. void View::slotSheetHidden( Sheet* )
  3221. {
  3222. doc()->emitBeginOperation(false);
  3223. updateShowSheetMenu();
  3224. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  3225. }
  3226. void View::slotSheetShown( Sheet* )
  3227. {
  3228. doc()->emitBeginOperation(false);
  3229. d->tabBar->setTabs( doc()->map()->visibleSheets() );
  3230. updateShowSheetMenu();
  3231. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  3232. }
  3233. void View::changeSheet( const TQString& _name )
  3234. {
  3235. if ( activeSheet()->sheetName() == _name )
  3236. return;
  3237. Sheet *t = doc()->map()->findSheet( _name );
  3238. if ( !t )
  3239. {
  3240. kdDebug(36001) << "Unknown sheet " << _name << endl;
  3241. return;
  3242. }
  3243. doc()->emitBeginOperation(false);
  3244. d->canvas->closeEditor(); // for selection mode
  3245. setActiveSheet( t, false /* False: Endless loop because of setActiveTab() => do the visual area update manually*/);
  3246. d->canvas->updateEditor(); // for choose mode
  3247. updateEditWidget();
  3248. //refresh toggle button
  3249. updateBorderButton();
  3250. //update visible area
  3251. d->vBorderWidget->repaint();
  3252. d->hBorderWidget->repaint();
  3253. d->canvas->slotMaxColumn( d->activeSheet->maxColumn() );
  3254. d->canvas->slotMaxRow( d->activeSheet->maxRow() );
  3255. t->setRegionPaintDirty( t->visibleRect( d->canvas ) );
  3256. doc()->emitEndOperation();
  3257. }
  3258. void View::moveSheet( unsigned sheet, unsigned target )
  3259. {
  3260. if( doc()->map()->isProtected() ) return;
  3261. TQStringList vs = doc()->map()->visibleSheets();
  3262. if( target >= vs.count() )
  3263. doc()->map()->moveSheet( vs[ sheet ], vs[ vs.count()-1 ], false );
  3264. else
  3265. doc()->map()->moveSheet( vs[ sheet ], vs[ target ], true );
  3266. d->tabBar->moveTab( sheet, target );
  3267. }
  3268. void View::sheetProperties()
  3269. {
  3270. // sanity check, shouldn't happen
  3271. if( doc()->map()->isProtected() ) return;
  3272. if( d->activeSheet->isProtected() ) return;
  3273. bool directionChanged = false;
  3274. SheetPropertiesDialog* dlg = new SheetPropertiesDialog( this );
  3275. dlg->setLayoutDirection( d->activeSheet->layoutDirection() );
  3276. dlg->setAutoCalc( d->activeSheet->getAutoCalc() );
  3277. dlg->setShowGrid( d->activeSheet->getShowGrid() );
  3278. dlg->setShowPageBorders( d->activeSheet->isShowPageBorders() );
  3279. dlg->setShowFormula( d->activeSheet->getShowFormula() );
  3280. dlg->setHideZero( d->activeSheet->getHideZero() );
  3281. dlg->setShowFormulaIndicator( d->activeSheet->getShowFormulaIndicator() );
  3282. dlg->setShowCommentIndicator( d->activeSheet->getShowCommentIndicator() );
  3283. dlg->setColumnAsNumber( d->activeSheet->getShowColumnNumber() );
  3284. dlg->setLcMode( d->activeSheet->getLcMode() );
  3285. dlg->setCapitalizeFirstLetter( d->activeSheet->getFirstLetterUpper() );
  3286. if( dlg->exec() )
  3287. {
  3288. SheetPropertiesCommand* command = new SheetPropertiesCommand( doc(), d->activeSheet );
  3289. if ( d->activeSheet->layoutDirection() != dlg->layoutDirection() )
  3290. directionChanged = true;
  3291. command->setLayoutDirection( dlg->layoutDirection() );
  3292. command->setAutoCalc( dlg->autoCalc() );
  3293. command->setShowGrid( dlg->showGrid() );
  3294. command->setShowPageBorders( dlg->showPageBorders() );
  3295. command->setShowFormula( dlg->showFormula() );
  3296. command->setHideZero( dlg->hideZero() );
  3297. command->setShowFormulaIndicator( dlg->showFormulaIndicator() );
  3298. command->setShowCommentIndicator( dlg->showCommentIndicator() );
  3299. command->setColumnAsNumber( dlg->columnAsNumber() );
  3300. command->setLcMode( dlg->lcMode() );
  3301. command->setCapitalizeFirstLetter( dlg->capitalizeFirstLetter() );
  3302. doc()->addCommand( command );
  3303. command->execute();
  3304. }
  3305. delete dlg;
  3306. if ( directionChanged )
  3307. {
  3308. // the scrollbar and hborder remain reversed otherwise
  3309. d->horzScrollBar->setValue( d->horzScrollBar->maxValue() -
  3310. d->horzScrollBar->value() );
  3311. d->hBorderWidget->update();
  3312. }
  3313. }
  3314. void View::insertSheet()
  3315. {
  3316. if ( doc()->map()->isProtected() )
  3317. {
  3318. KMessageBox::error( 0, i18n ( "You cannot change a protected sheet." ) );
  3319. return;
  3320. }
  3321. doc()->emitBeginOperation( false );
  3322. d->canvas->closeEditor();
  3323. Sheet * t = doc()->map()->createSheet();
  3324. KCommand* command = new AddSheetCommand( t );
  3325. doc()->addCommand( command );
  3326. updateEditWidget();
  3327. setActiveSheet( t );
  3328. if ( doc()->map()->visibleSheets().count() > 1 )
  3329. {
  3330. d->actions->removeSheet->setEnabled( true );
  3331. d->actions->hideSheet->setEnabled( true );
  3332. }
  3333. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  3334. }
  3335. void View::hideSheet()
  3336. {
  3337. if ( !d->activeSheet )
  3338. return;
  3339. if ( doc()->map()->visibleSheets().count() == 1)
  3340. {
  3341. KMessageBox::error( this, i18n("You cannot hide the last visible sheet.") );
  3342. return;
  3343. }
  3344. TQStringList vs = doc()->map()->visibleSheets();
  3345. int i = vs.findIndex( d->activeSheet->tableName() ) - 1;
  3346. if( i < 0 ) i = 1;
  3347. TQString sn = vs[i];
  3348. doc()->emitBeginOperation(false);
  3349. KCommand* command = new HideSheetCommand( activeSheet() );
  3350. doc()->addCommand( command );
  3351. command->execute();
  3352. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  3353. d->tabBar->removeTab( d->activeSheet->sheetName() );
  3354. d->tabBar->setActiveTab( sn );
  3355. }
  3356. void View::showSheet()
  3357. {
  3358. if ( !d->activeSheet )
  3359. return;
  3360. ShowDialog dlg( this, "Sheet show");
  3361. dlg.exec();
  3362. }
  3363. void View::copySelection()
  3364. {
  3365. if ( !d->activeSheet )
  3366. return;
  3367. if ( canvasWidget()->isObjectSelected() )
  3368. {
  3369. canvasWidget()->copyOasisObjects();
  3370. return;
  3371. }
  3372. if ( !d->canvas->editor() )
  3373. {
  3374. d->activeSheet->copySelection( selectionInfo() );
  3375. updateEditWidget();
  3376. }
  3377. else
  3378. d->canvas->editor()->copy();
  3379. }
  3380. void View::copyAsText()
  3381. {
  3382. if ( !d->activeSheet )
  3383. return;
  3384. d->activeSheet->copyAsText( selectionInfo() );
  3385. }
  3386. void View::cutSelection()
  3387. {
  3388. if ( !d->activeSheet )
  3389. return;
  3390. //don't used this function when we edit a cell.
  3391. doc()->emitBeginOperation(false);
  3392. if ( canvasWidget()->isObjectSelected() )
  3393. {
  3394. canvasWidget()->copyOasisObjects();
  3395. markSelectionAsDirty();
  3396. doc()->emitEndOperation();
  3397. KMacroCommand * macroCommand = 0L;
  3398. TQPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
  3399. for ( ; it.current() ; ++it )
  3400. {
  3401. if ( it.current()->sheet() == canvasWidget()->activeSheet() && it.current()->isSelected() )
  3402. {
  3403. if( !macroCommand )
  3404. macroCommand = new KMacroCommand( i18n( "Cut Objects" ) );
  3405. RemoveObjectCommand *cmd = new RemoveObjectCommand( it.current(), true );
  3406. macroCommand->addCommand( cmd );
  3407. }
  3408. }
  3409. if ( macroCommand )
  3410. {
  3411. doc()->addCommand( macroCommand );
  3412. canvasWidget()->setMouseSelectedObject( false );
  3413. macroCommand->execute();
  3414. }
  3415. return;
  3416. }
  3417. if ( !d->canvas->editor())
  3418. {
  3419. d->activeSheet->cutSelection( selectionInfo() );
  3420. calcStatusBarOp();
  3421. updateEditWidget();
  3422. }
  3423. else
  3424. d->canvas->editor()->cut();
  3425. markSelectionAsDirty();
  3426. doc()->emitEndOperation();
  3427. }
  3428. void View::paste()
  3429. {
  3430. if ( !d->activeSheet )
  3431. return;
  3432. if (!koDocument()->isReadWrite()) // don't paste into a read only document
  3433. return;
  3434. TQMimeSource *data = TQApplication::clipboard()->data( TQClipboard::Clipboard );
  3435. for ( int i=0; data->format(i) != 0; i++ )
  3436. kdDebug() << "format:" << data->format(i) << endl;
  3437. if ( data->provides( KoStoreDrag::mimeType("application/vnd.oasis.opendocument.spreadsheet" ) ))
  3438. {
  3439. canvasWidget()->deselectAllObjects();
  3440. TQCString returnedTypeMime = "application/vnd.oasis.opendocument.spreadsheet";
  3441. const TQByteArray arr = data->encodedData( returnedTypeMime );
  3442. if( arr.isEmpty() )
  3443. return;
  3444. TQBuffer buffer( arr );
  3445. KoStore * store = KoStore::createStore( TQT_TQIODEVICE(&buffer), KoStore::Read );
  3446. KoOasisStore oasisStore( store );
  3447. TQDomDocument doc;
  3448. TQString errorMessage;
  3449. bool ok = oasisStore.loadAndParse( "content.xml", doc, errorMessage );
  3450. if ( !ok ) {
  3451. kdError(32001) << "Error parsing content.xml: " << errorMessage << endl;
  3452. return;
  3453. }
  3454. KoOasisStyles oasisStyles;
  3455. TQDomDocument stylesDoc;
  3456. (void)oasisStore.loadAndParse( "styles.xml", stylesDoc, errorMessage );
  3457. // Load styles from style.xml
  3458. oasisStyles.createStyleMap( stylesDoc, true );
  3459. // Also load styles from content.xml
  3460. oasisStyles.createStyleMap( doc, false );
  3461. // from KSpreadDoc::loadOasis:
  3462. TQDomElement content = doc.documentElement();
  3463. TQDomElement realBody ( KoDom::namedItemNS( content, KoXmlNS::office, "body" ) );
  3464. if ( realBody.isNull() )
  3465. {
  3466. kdDebug() << "Invalid OASIS OpenDocument file. No office:body tag found." << endl;
  3467. return;
  3468. }
  3469. TQDomElement body = KoDom::namedItemNS( realBody, KoXmlNS::office, "spreadsheet" );
  3470. if ( body.isNull() )
  3471. {
  3472. kdError(32001) << "No office:spreadsheet found!" << endl;
  3473. TQDomElement childElem;
  3474. TQString localName;
  3475. forEachElement( childElem, realBody ) {
  3476. localName = childElem.localName();
  3477. }
  3478. return;
  3479. }
  3480. KoOasisLoadingContext context( d->doc, oasisStyles, store );
  3481. Q_ASSERT( !oasisStyles.officeStyle().isNull() );
  3482. //load in first
  3483. d->doc->styleManager()->loadOasisStyleTemplate( oasisStyles );
  3484. // // TODO check versions and mimetypes etc.
  3485. d->doc->loadOasisAreaName( body );
  3486. d->doc->loadOasisCellValidation( body );
  3487. // all <sheet:sheet> goes to workbook
  3488. bool result = d->doc->map()->loadOasis( body, context );
  3489. if (!result)
  3490. return;
  3491. }
  3492. else
  3493. {
  3494. //TODO: What if the clipboard data is available in both pixmap and OASIS format? (ie. for embedded parts)
  3495. TQPixmap clipboardPixmap = TQApplication::clipboard()->pixmap( TQClipboard::Clipboard );
  3496. if (!clipboardPixmap.isNull())
  3497. {
  3498. d->activeSheet->insertPicture( markerDocumentPosition() , clipboardPixmap );
  3499. }
  3500. }
  3501. doc()->emitBeginOperation( false );
  3502. if ( !d->canvas->editor() )
  3503. {
  3504. //kdDebug(36001) << "Pasting. Rect= " << d->selection->selection(false) << " bytes" << endl;
  3505. d->activeSheet->paste( d->selection->lastRange(), true,
  3506. Paste::Normal, Paste::OverWrite,
  3507. false, 0, true );
  3508. calcStatusBarOp();
  3509. updateEditWidget();
  3510. }
  3511. else
  3512. {
  3513. d->canvas->editor()->paste();
  3514. }
  3515. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  3516. }
  3517. void View::specialPaste()
  3518. {
  3519. if ( !d->activeSheet )
  3520. return;
  3521. SpecialDialog dlg( this, "Special Paste" );
  3522. if ( dlg.exec() )
  3523. {
  3524. if ( d->activeSheet->getAutoCalc() )
  3525. {
  3526. doc()->emitBeginOperation( false );
  3527. d->activeSheet->recalc();
  3528. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  3529. }
  3530. calcStatusBarOp();
  3531. updateEditWidget();
  3532. }
  3533. }
  3534. void View::removeComment()
  3535. {
  3536. if ( !d->activeSheet )
  3537. return;
  3538. doc()->emitBeginOperation(false);
  3539. d->activeSheet->setSelectionRemoveComment( selectionInfo() );
  3540. updateEditWidget();
  3541. markSelectionAsDirty();
  3542. doc()->emitEndOperation();
  3543. }
  3544. void View::changeAngle()
  3545. {
  3546. if ( !d->activeSheet )
  3547. return;
  3548. AngleDialog dlg( this, "Angle" ,
  3549. TQPoint( d->canvas->markerColumn(), d->canvas->markerRow() ));
  3550. if ( dlg.exec() )
  3551. {
  3552. //TODO Stefan: where is the angle operation?
  3553. d->activeSheet->adjustArea(*selectionInfo());
  3554. }
  3555. }
  3556. void View::setSelectionAngle( int angle )
  3557. {
  3558. doc()->emitBeginOperation( false );
  3559. if ( d->activeSheet != NULL )
  3560. {
  3561. d->activeSheet->setSelectionAngle( selectionInfo(), angle );
  3562. d->activeSheet->adjustArea(*selectionInfo());
  3563. }
  3564. markSelectionAsDirty();
  3565. doc()->emitEndOperation();
  3566. }
  3567. void View::mergeCell()
  3568. {
  3569. // sanity check
  3570. if( !d->activeSheet )
  3571. return;
  3572. d->activeSheet->mergeCells(*selectionInfo());
  3573. }
  3574. void View::mergeCellHorizontal()
  3575. {
  3576. // sanity check
  3577. if( !d->activeSheet )
  3578. return;
  3579. d->activeSheet->mergeCells(*selectionInfo(), true);
  3580. }
  3581. void View::mergeCellVertical()
  3582. {
  3583. // sanity check
  3584. if( !d->activeSheet )
  3585. return;
  3586. d->activeSheet->mergeCells(*selectionInfo(), false, true);
  3587. }
  3588. void View::dissociateCell()
  3589. {
  3590. // sanity check
  3591. if( !d->activeSheet )
  3592. return;
  3593. d->activeSheet->dissociateCells(*selectionInfo());
  3594. }
  3595. void View::increaseIndent()
  3596. {
  3597. if ( !d->activeSheet )
  3598. return;
  3599. doc()->emitBeginOperation( false );
  3600. d->activeSheet->increaseIndent( d->selection );
  3601. updateEditWidget();
  3602. markSelectionAsDirty();
  3603. doc()->emitEndOperation();
  3604. }
  3605. void View::decreaseIndent()
  3606. {
  3607. if ( !d->activeSheet )
  3608. return;
  3609. doc()->emitBeginOperation( false );
  3610. int column = d->canvas->markerColumn();
  3611. int row = d->canvas->markerRow();
  3612. d->activeSheet->decreaseIndent( d->selection );
  3613. Cell * cell = d->activeSheet->cellAt( column, row );
  3614. if ( cell )
  3615. if ( !d->activeSheet->isProtected() )
  3616. d->actions->decreaseIndent->setEnabled( cell->format()->getIndent( column, row ) > 0.0 );
  3617. markSelectionAsDirty();
  3618. doc()->emitEndOperation();
  3619. }
  3620. void View::goalSeek()
  3621. {
  3622. if ( d->canvas->editor() )
  3623. {
  3624. d->canvas->deleteEditor( true ); // save changes
  3625. }
  3626. GoalSeekDialog * dlg
  3627. = new GoalSeekDialog( this, TQPoint( d->canvas->markerColumn(),
  3628. d->canvas->markerRow() ),
  3629. "GoalSeekDialog" );
  3630. dlg->show();
  3631. /* dialog autodeletes itself */
  3632. }
  3633. void View::subtotals()
  3634. {
  3635. if (!activeSheet())
  3636. return;
  3637. TQRect selection( d->selection->selection() );
  3638. if ( ( selection.width() < 2 ) || ( selection.height() < 2 ) )
  3639. {
  3640. KMessageBox::error( this, i18n("You must select multiple cells.") );
  3641. return;
  3642. }
  3643. SubtotalDialog dlg(this, selection, "SubtotalDialog" );
  3644. if ( dlg.exec() )
  3645. {
  3646. doc()->emitBeginOperation( false );
  3647. d->selection->initialize( TQRect(dlg.selection().topLeft(), dlg.selection().bottomRight()));//, dlg.sheet() );
  3648. doc()->emitEndOperation( selection );
  3649. }
  3650. }
  3651. void View::multipleOperations()
  3652. {
  3653. if ( d->canvas->editor() )
  3654. {
  3655. d->canvas->deleteEditor( true ); // save changes
  3656. }
  3657. // MultipleOpDlg * dlg = new MultipleOpDlg( this, "MultipleOpDlg" );
  3658. // dlg->show();
  3659. }
  3660. void View::textToColumns()
  3661. {
  3662. if (!activeSheet())
  3663. return;
  3664. d->canvas->closeEditor();
  3665. TQRect area=d->selection->selection();
  3666. //Only use the first column
  3667. area.setRight(area.left());
  3668. /* if ( area.width() > 1 )
  3669. {
  3670. //Only use the first column
  3671. KMessageBox::error( this, i18n("You must not select an area containing more than one column.") );
  3672. return;
  3673. }*/
  3674. CSVDialog dialog( this, "CSVDialog", area, CSVDialog::Column );
  3675. if( !dialog.cancelled() )
  3676. dialog.exec();
  3677. }
  3678. void View::consolidate()
  3679. {
  3680. d->canvas->closeEditor();
  3681. ConsolidateDialog * dlg = new ConsolidateDialog( this, "ConsolidateDialog" );
  3682. dlg->show();
  3683. // dlg destroys itself
  3684. }
  3685. void View::sortList()
  3686. {
  3687. if (!activeSheet()) return;
  3688. ListDialog dlg( this, "List selection" );
  3689. dlg.exec();
  3690. }
  3691. void View::gotoCell()
  3692. {
  3693. if (!activeSheet()) return;
  3694. GotoDialog dlg( this, "GotoCell" );
  3695. dlg.exec();
  3696. }
  3697. void View::find()
  3698. {
  3699. if (!activeSheet()) return;
  3700. FindDlg dlg( this, "Find", d->findOptions, d->findStrings );
  3701. dlg.setHasSelection( !d->selection->isSingular() );
  3702. dlg.setHasCursor( true );
  3703. if ( KFindDialog::Accepted != dlg.exec() )
  3704. return;
  3705. // Save for next time
  3706. d->findOptions = dlg.options();
  3707. d->findStrings = dlg.findHistory();
  3708. d->typeValue = dlg.searchType();
  3709. d->directionValue = dlg.searchDirection();
  3710. // Create the KFind object
  3711. delete d->find;
  3712. delete d->replace;
  3713. d->find = new KFind( dlg.pattern(), dlg.options(), this );
  3714. d->replace = 0L;
  3715. d->searchInSheets.currentSheet = activeSheet();
  3716. d->searchInSheets.firstSheet = d->searchInSheets.currentSheet;
  3717. initFindReplace();
  3718. findNext();
  3719. }
  3720. // Initialize a find or replace operation, using d->find or d->replace,
  3721. // and d->findOptions.
  3722. void View::initFindReplace()
  3723. {
  3724. KFind* findObj = d->find ? d->find : d->replace;
  3725. Q_ASSERT( findObj );
  3726. connect(findObj, TQT_SIGNAL( highlight( const TQString &, int, int ) ),
  3727. this, TQT_SLOT( slotHighlight( const TQString &, int, int ) ) );
  3728. connect(findObj, TQT_SIGNAL( findNext() ),
  3729. this, TQT_SLOT( findNext() ) );
  3730. bool bck = d->findOptions & KFindDialog::FindBackwards;
  3731. Sheet* currentSheet = d->searchInSheets.currentSheet;
  3732. TQRect region = ( d->findOptions & KFindDialog::SelectedText )
  3733. ? d->selection->selection()
  3734. : TQRect( 1, 1, currentSheet->maxColumn(), currentSheet->maxRow() ); // All cells
  3735. int colStart = !bck ? region.left() : region.right();
  3736. int colEnd = !bck ? region.right() : region.left();
  3737. int rowStart = !bck ? region.top() :region.bottom();
  3738. int rowEnd = !bck ? region.bottom() : region.top();
  3739. if ( d->findOptions & KFindDialog::FromCursor ) {
  3740. TQPoint marker( d->selection->marker() );
  3741. colStart = marker.x();
  3742. rowStart = marker.y();
  3743. }
  3744. d->findLeftColumn = region.left();
  3745. d->findRightColumn = region.right();
  3746. d->findPos = TQPoint( colStart, rowStart );
  3747. d->findEnd = TQPoint( colEnd, rowEnd );
  3748. //kdDebug() << k_funcinfo << d->findPos << " to " << d->findEnd << endl;
  3749. //kdDebug() << k_funcinfo << "leftcol=" << d->findLeftColumn << " rightcol=" << d->findRightColumn << endl;
  3750. }
  3751. void View::findNext()
  3752. {
  3753. KFind* findObj = d->find ? d->find : d->replace;
  3754. if ( !findObj ) {
  3755. find();
  3756. return;
  3757. }
  3758. KFind::Result res = KFind::NoMatch;
  3759. Cell* cell = findNextCell();
  3760. bool forw = ! ( d->findOptions & KFindDialog::FindBackwards );
  3761. while ( res == KFind::NoMatch && cell )
  3762. {
  3763. if ( findObj->needData() )
  3764. {
  3765. if ( d->typeValue == FindOption::Note )
  3766. findObj->setData( cell->format()->comment( cell->column(), cell->row() ) );
  3767. else
  3768. findObj->setData( cell->text() );
  3769. d->findPos = TQPoint( cell->column(), cell->row() );
  3770. //kdDebug() << "setData(cell " << d->findPos << ")" << endl;
  3771. }
  3772. // Let KFind inspect the text fragment, and display a dialog if a match is found
  3773. if ( d->find )
  3774. res = d->find->find();
  3775. else
  3776. res = d->replace->replace();
  3777. if ( res == KFind::NoMatch ) {
  3778. // Go to next cell, skipping unwanted cells
  3779. if ( d->directionValue == FindOption::Row )
  3780. {
  3781. if ( forw )
  3782. ++d->findPos.rx();
  3783. else
  3784. --d->findPos.rx();
  3785. }
  3786. else
  3787. {
  3788. if ( forw )
  3789. ++d->findPos.ry();
  3790. else
  3791. --d->findPos.ry();
  3792. }
  3793. cell = findNextCell();
  3794. }
  3795. }
  3796. if ( res == KFind::NoMatch )
  3797. {
  3798. //emitUndoRedo();
  3799. //removeHighlight();
  3800. if ( findObj->shouldRestart() ) {
  3801. d->findOptions &= ~KFindDialog::FromCursor;
  3802. findObj->resetCounts();
  3803. findNext();
  3804. }
  3805. else { // done, close the 'find next' dialog
  3806. if ( d->find )
  3807. d->find->closeFindNextDialog();
  3808. else
  3809. d->replace->closeReplaceNextDialog();
  3810. }
  3811. }
  3812. }
  3813. Cell* View::nextFindValidCell( int col, int row )
  3814. {
  3815. Cell *cell = d->searchInSheets.currentSheet->cellAt( col, row );
  3816. if ( cell->isDefault() || cell->isObscured() || cell->isFormula() )
  3817. cell = 0L;
  3818. if ( d->typeValue == FindOption::Note && cell && cell->format()->comment(col, row).isEmpty())
  3819. cell = 0L;
  3820. return cell;
  3821. }
  3822. Cell* View::findNextCell()
  3823. {
  3824. // getFirstCellRow / getNextCellRight would be faster at doing that,
  3825. // but it doesn't seem to be easy to combine it with 'start a column d->find.x()'...
  3826. Sheet* sheet = d->searchInSheets.currentSheet;
  3827. Cell* cell = 0L;
  3828. bool forw = ! ( d->findOptions & KFindDialog::FindBackwards );
  3829. int col = d->findPos.x();
  3830. int row = d->findPos.y();
  3831. int maxRow = sheet->maxRow();
  3832. //kdDebug() << "findNextCell starting at " << col << "," << row << " forw=" << forw << endl;
  3833. if ( d->directionValue == FindOption::Row )
  3834. {
  3835. while ( !cell && row != d->findEnd.y() && (forw ? row < maxRow : row >= 0) )
  3836. {
  3837. while ( !cell && (forw ? col <= d->findRightColumn : col >= d->findLeftColumn) )
  3838. {
  3839. cell = nextFindValidCell( col, row );
  3840. if ( forw ) ++col;
  3841. else --col;
  3842. }
  3843. if ( cell )
  3844. break;
  3845. // Prepare looking in the next row
  3846. if ( forw ) {
  3847. col = d->findLeftColumn;
  3848. ++row;
  3849. } else {
  3850. col = d->findRightColumn;
  3851. --row;
  3852. }
  3853. //kdDebug() << "next row: " << col << "," << row << endl;
  3854. }
  3855. }
  3856. else
  3857. {
  3858. while ( !cell && (forw ? col <= d->findRightColumn : col >= d->findLeftColumn) )
  3859. {
  3860. while ( !cell && row != d->findEnd.y() && (forw ? row < maxRow : row >= 0) )
  3861. {
  3862. cell = nextFindValidCell( col, row );
  3863. if ( forw ) ++row;
  3864. else --row;
  3865. }
  3866. if ( cell )
  3867. break;
  3868. // Prepare looking in the next col
  3869. if ( forw ) {
  3870. row = 0;
  3871. ++col;
  3872. } else {
  3873. col = maxRow;
  3874. --col;
  3875. }
  3876. //kdDebug() << "next row: " << col << "," << row << endl;
  3877. }
  3878. }
  3879. // if ( !cell )
  3880. // No more next cell - TODO go to next sheet (if not looking in a selection)
  3881. // (and make d->findEnd (max,max) in that case...)
  3882. //kdDebug() << k_funcinfo << " returning " << cell << endl;
  3883. return cell;
  3884. }
  3885. void View::findPrevious()
  3886. {
  3887. KFind* findObj = d->find ? d->find : d->replace;
  3888. if ( !findObj ) {
  3889. find();
  3890. return;
  3891. }
  3892. //kdDebug() << "findPrevious" << endl;
  3893. int opt = d->findOptions;
  3894. bool forw = ! ( opt & KFindDialog::FindBackwards );
  3895. if ( forw )
  3896. d->findOptions = ( opt | KFindDialog::FindBackwards );
  3897. else
  3898. d->findOptions = ( opt & ~KFindDialog::FindBackwards );
  3899. findNext();
  3900. d->findOptions = opt; // restore initial options
  3901. }
  3902. void View::replace()
  3903. {
  3904. if (!d->activeSheet)
  3905. return;
  3906. SearchDlg dlg( this, "Replace", d->findOptions, d->findStrings, d->replaceStrings );
  3907. dlg.setHasSelection( !d->selection->isSingular() );
  3908. dlg.setHasCursor( true );
  3909. if ( KReplaceDialog::Accepted != dlg.exec() )
  3910. return;
  3911. d->findOptions = dlg.options();
  3912. d->findStrings = dlg.findHistory();
  3913. d->replaceStrings = dlg.replacementHistory();
  3914. d->typeValue = dlg.searchType();
  3915. delete d->find;
  3916. delete d->replace;
  3917. d->find = 0L;
  3918. // NOTE Stefan: Avoid beginning of line replacements with nothing which
  3919. // will lead to an infinite loop (Bug #125535). The reason
  3920. // for this is unclear to me, but who cares and who would
  3921. // want to do something like this, häh?!
  3922. if (dlg.pattern() == "^" && dlg.replacement().isEmpty())
  3923. return;
  3924. d->replace = new KReplace( dlg.pattern(), dlg.replacement(), dlg.options() );
  3925. d->searchInSheets.currentSheet = activeSheet();
  3926. d->searchInSheets.firstSheet = d->searchInSheets.currentSheet;
  3927. initFindReplace();
  3928. connect( d->replace, TQT_SIGNAL( replace( const TQString &, int, int, int ) ),
  3929. this, TQT_SLOT( slotReplace( const TQString &, int, int, int ) ) );
  3930. if ( !doc()->undoLocked() )
  3931. {
  3932. TQRect region( d->findPos, d->findEnd );
  3933. //TODO create undo/redo for comment
  3934. UndoChangeAreaTextCell *undo = new UndoChangeAreaTextCell( doc(), d->searchInSheets.currentSheet, region );
  3935. doc()->addCommand( undo );
  3936. }
  3937. findNext();
  3938. #if 0
  3939. // Refresh the editWidget
  3940. // TODO - after a replacement only?
  3941. Cell *cell = activeSheet()->cellAt( canvasWidget()->markerColumn(),
  3942. canvasWidget()->markerRow() );
  3943. if ( cell->text() != 0L )
  3944. d->editWidget->setText( cell->text() );
  3945. else
  3946. d->editWidget->setText( "" );
  3947. #endif
  3948. }
  3949. void View::slotHighlight( const TQString &/*text*/, int /*matchingIndex*/, int /*matchedLength*/ )
  3950. {
  3951. d->selection->initialize( d->findPos );
  3952. KDialogBase *baseDialog=0L;
  3953. if ( d->find )
  3954. baseDialog = d->find->findNextDialog();
  3955. else
  3956. baseDialog = d->replace->replaceNextDialog();
  3957. kdDebug()<<" baseDialog :"<<baseDialog<<endl;
  3958. TQRect globalRect( d->findPos, d->findEnd );
  3959. globalRect.moveTopLeft( canvasWidget()->mapToGlobal( globalRect.topLeft() ) );
  3960. KDialog::avoidArea( baseDialog, TQRect( d->findPos, d->findEnd ));
  3961. }
  3962. void View::slotReplace( const TQString &newText, int, int, int )
  3963. {
  3964. // Which cell was this again?
  3965. Cell *cell = d->searchInSheets.currentSheet->cellAt( d->findPos );
  3966. // ...now I remember, update it!
  3967. cell->setDisplayDirtyFlag();
  3968. if ( d->typeValue == FindOption::Value )
  3969. cell->setCellText( newText );
  3970. else if ( d->typeValue == FindOption::Note )
  3971. cell->format()->setComment( newText );
  3972. cell->clearDisplayDirtyFlag();
  3973. }
  3974. void View::conditional()
  3975. {
  3976. TQRect rect( d->selection->selection() );
  3977. if ( util_isRowOrColumnSelected(rect))
  3978. {
  3979. KMessageBox::error( this, i18n("Area is too large.") );
  3980. }
  3981. else
  3982. {
  3983. ConditionalDialog dlg( this, "ConditionalDialog", rect);
  3984. dlg.exec();
  3985. }
  3986. }
  3987. void View::validity()
  3988. {
  3989. TQRect rect( d->selection->selection() );
  3990. if (d->selection->isColumnOrRowSelected())
  3991. {
  3992. KMessageBox::error( this, i18n("Area is too large."));
  3993. }
  3994. else
  3995. {
  3996. DlgValidity dlg( this,"validity",rect);
  3997. dlg.exec();
  3998. }
  3999. }
  4000. void View::insertSeries()
  4001. {
  4002. d->canvas->closeEditor();
  4003. SeriesDlg dlg( this, "Series", TQPoint( d->canvas->markerColumn(), d->canvas->markerRow() ) );
  4004. dlg.exec();
  4005. }
  4006. void View::sort()
  4007. {
  4008. if ( d->selection->isSingular() )
  4009. {
  4010. KMessageBox::error( this, i18n("You must select multiple cells.") );
  4011. return;
  4012. }
  4013. SortDialog dlg( this, "Sort" );
  4014. dlg.exec();
  4015. }
  4016. void View::removeHyperlink()
  4017. {
  4018. TQPoint marker( d->selection->marker() );
  4019. Cell * cell = d->activeSheet->cellAt( marker );
  4020. if( !cell ) return;
  4021. if( cell->link().isEmpty() ) return;
  4022. LinkCommand* command = new LinkCommand( cell, TQString(), TQString() );
  4023. doc()->addCommand( command );
  4024. command->execute();
  4025. canvasWidget()->setFocus();
  4026. d->editWidget->setText( cell->text() );
  4027. }
  4028. void View::insertHyperlink()
  4029. {
  4030. if (!activeSheet())
  4031. return;
  4032. d->canvas->closeEditor();
  4033. TQPoint marker( d->selection->marker() );
  4034. Cell* cell = d->activeSheet->cellAt( marker );
  4035. LinkDialog* dlg = new LinkDialog( this );
  4036. dlg->setCaption( i18n( "Insert Link" ) );
  4037. if( cell )
  4038. {
  4039. dlg->setText( cell->text() );
  4040. if( !cell->link().isEmpty() )
  4041. {
  4042. dlg->setCaption( i18n( "Edit Link" ) );
  4043. dlg->setLink( cell->link() );
  4044. }
  4045. }
  4046. if( dlg->exec() == KDialog::Accepted )
  4047. {
  4048. cell = d->activeSheet->nonDefaultCell( marker );
  4049. LinkCommand* command = new LinkCommand( cell, dlg->text(), dlg->link() );
  4050. doc()->addCommand( command );
  4051. command->execute();
  4052. //refresh editWidget
  4053. canvasWidget()->setFocus();
  4054. d->editWidget->setText( cell->text() );
  4055. }
  4056. delete dlg;
  4057. }
  4058. void View::insertFromDatabase()
  4059. {
  4060. #ifndef TQT_NO_SQL
  4061. d->canvas->closeEditor();
  4062. TQRect rect = d->selection->selection();
  4063. TQStringList str = TQSqlDatabase::drivers();
  4064. if ( str.isEmpty() )
  4065. {
  4066. KMessageBox::error( this, i18n("No database drivers available. To use this feature you need "
  4067. "to install the necessary TQt 3 database drivers.") );
  4068. return;
  4069. }
  4070. doc()->doNotPaint( true );
  4071. DatabaseDialog dlg(this, rect, "DatabaseDialog");
  4072. dlg.exec();
  4073. doc()->doNotPaint( false );
  4074. #endif
  4075. }
  4076. void View::insertFromTextfile()
  4077. {
  4078. d->canvas->closeEditor();
  4079. //KMessageBox::information( this, "Not implemented yet, work in progress...");
  4080. doc()->doNotPaint( true );
  4081. CSVDialog dialog( this, "CSVDialog", d->selection->selection(), CSVDialog::File );
  4082. if( !dialog.cancelled() )
  4083. dialog.exec();
  4084. doc()->doNotPaint( false );
  4085. }
  4086. void View::insertFromClipboard()
  4087. {
  4088. d->canvas->closeEditor();
  4089. doc()->doNotPaint( true );
  4090. CSVDialog dialog( this, "CSVDialog", d->selection->selection(), CSVDialog::Clipboard );
  4091. if( !dialog.cancelled() )
  4092. dialog.exec();
  4093. doc()->doNotPaint( false );
  4094. }
  4095. void View::setupPrinter( KPrinter &prt )
  4096. {
  4097. if (!activeSheet())
  4098. return;
  4099. SheetPrint* print = d->activeSheet->print();
  4100. //apply page layout parameters
  4101. KoFormat pageFormat = print->paperFormat();
  4102. prt.setPageSize( static_cast<KPrinter::PageSize>( KoPageFormat::printerPageSize( pageFormat ) ) );
  4103. if ( print->orientation() == PG_LANDSCAPE || pageFormat == PG_SCREEN )
  4104. prt.setOrientation( KPrinter::Landscape );
  4105. else
  4106. prt.setOrientation( KPrinter::Portrait );
  4107. prt.setFullPage( true );
  4108. //add possibility to select the sheets to print:
  4109. // kdDebug() << "Adding sheet selection page." << endl;
  4110. KPSheetSelectPage* sheetpage = new KPSheetSelectPage();
  4111. prt.addDialogPage(sheetpage);
  4112. // kdDebug() << "Iterating through available sheets and initializing list of available sheets." << endl;
  4113. TQPtrList<Sheet> sheetlist = doc()->map()->sheetList();
  4114. Sheet* sheet = sheetlist.last();
  4115. while ( sheet )
  4116. {
  4117. kdDebug() << "Adding " << sheet->sheetName() << endl;
  4118. sheetpage->prependAvailableSheet(sheet->sheetName());
  4119. sheet = sheetlist.prev();
  4120. }
  4121. }
  4122. void View::print( KPrinter &prt )
  4123. {
  4124. if (!activeSheet())
  4125. return;
  4126. //save the current active sheet for later, so we can restore it at the end
  4127. Sheet* selectedsheet = this->activeSheet();
  4128. //print all sheets in the order given by the print dialog (Sheet Selection)
  4129. TQStringList sheetlist = KPSheetSelectPage::selectedSheets(prt);
  4130. if (sheetlist.empty())
  4131. {
  4132. kdDebug() << "No sheet for printing selected, printing active sheet" << endl;
  4133. sheetlist.append(d->activeSheet->sheetName());
  4134. }
  4135. TQPainter painter;
  4136. painter.begin( &prt );
  4137. bool firstpage = true;
  4138. TQStringList::iterator sheetlistiterator;
  4139. for (sheetlistiterator = sheetlist.begin(); sheetlistiterator != sheetlist.end(); ++sheetlistiterator)
  4140. {
  4141. kdDebug() << " printing sheet " << *sheetlistiterator << endl;
  4142. Sheet* sheet = doc()->map()->findSheet(*sheetlistiterator);
  4143. if (sheet == NULL)
  4144. {
  4145. kdWarning() << i18n("Sheet %1 could not be found for printing").arg(*sheetlistiterator) << endl;
  4146. continue;
  4147. }
  4148. setActiveSheet(sheet,FALSE);
  4149. SheetPrint* print = d->activeSheet->print();
  4150. if (firstpage)
  4151. firstpage=false;
  4152. else
  4153. {
  4154. kdDebug() << " inserting new page" << endl;
  4155. prt.newPage();
  4156. }
  4157. if ( d->canvas->editor() )
  4158. {
  4159. d->canvas->deleteEditor( true ); // save changes
  4160. }
  4161. int oldZoom = doc()->zoom();
  4162. //Comment from KWord
  4163. // We don't get valid metrics from the printer - and we want a better resolution
  4164. // anyway (it's the PS driver that takes care of the printer resolution).
  4165. //But KSpread uses fixed 300 dpis, so we can use it.
  4166. TQPaintDeviceMetrics metrics( &prt );
  4167. int dpiX = metrics.logicalDpiX();
  4168. int dpiY = metrics.logicalDpiY();
  4169. doc()->setZoomAndResolution( int( print->zoom() * 100 ), dpiX, dpiY );
  4170. //store the current setting in a temporary variable
  4171. KoOrientation _orient = print->orientation();
  4172. //use the current orientation from print dialog
  4173. if ( prt.orientation() == KPrinter::Landscape )
  4174. {
  4175. print->setPaperOrientation( PG_LANDSCAPE );
  4176. }
  4177. else
  4178. {
  4179. print->setPaperOrientation( PG_PORTRAIT );
  4180. }
  4181. bool result = print->print( painter, &prt );
  4182. //Restore original orientation
  4183. print->setPaperOrientation( _orient );
  4184. doc()->setZoomAndResolution( oldZoom, KoGlobal::dpiX(), KoGlobal::dpiY() );
  4185. doc()->newZoomAndResolution( true, false );
  4186. // Repaint at correct zoom
  4187. doc()->emitBeginOperation( false );
  4188. setZoom( oldZoom, false );
  4189. doc()->emitEndOperation();
  4190. // Nothing to print
  4191. if( !result )
  4192. {
  4193. if( !prt.previewOnly() )
  4194. {
  4195. KMessageBox::information( 0,
  4196. i18n("Nothing to print for sheet %1.").arg(
  4197. d->activeSheet->sheetName()) );
  4198. //@todo: make sure we really can comment this out,
  4199. // what to do with partially broken printouts?
  4200. // prt.abort();
  4201. }
  4202. }
  4203. }
  4204. painter.end();
  4205. this->setActiveSheet(selectedsheet);
  4206. }
  4207. void View::insertChart( const TQRect& _geometry, KoDocumentEntry& _e )
  4208. {
  4209. if ( !d->activeSheet )
  4210. return;
  4211. // Transform the view coordinates to document coordinates
  4212. KoRect unzoomedRect = doc()->unzoomRect( _geometry );
  4213. unzoomedRect.moveBy( d->canvas->xOffset(), d->canvas->yOffset() );
  4214. InsertObjectCommand *cmd = 0;
  4215. if ( d->selection->isColumnOrRowSelected() )
  4216. {
  4217. KMessageBox::error( this, i18n("Area is too large."));
  4218. return;
  4219. }
  4220. else
  4221. cmd = new InsertObjectCommand( unzoomedRect, _e, d->selection->selection(), d->canvas );
  4222. doc()->addCommand( cmd );
  4223. cmd->execute();
  4224. }
  4225. void View::insertChild( const TQRect& _geometry, KoDocumentEntry& _e )
  4226. {
  4227. if ( !d->activeSheet )
  4228. return;
  4229. // Transform the view coordinates to document coordinates
  4230. KoRect unzoomedRect = doc()->unzoomRect( _geometry );
  4231. unzoomedRect.moveBy( d->canvas->xOffset(), d->canvas->yOffset() );
  4232. InsertObjectCommand *cmd = new InsertObjectCommand( unzoomedRect, _e, d->canvas );
  4233. doc()->addCommand( cmd );
  4234. cmd->execute();
  4235. }
  4236. KoPoint View::markerDocumentPosition()
  4237. {
  4238. TQPoint marker=selectionInfo()->marker();
  4239. return KoPoint( d->activeSheet->dblColumnPos(marker.x()),
  4240. d->activeSheet->dblRowPos(marker.y()) );
  4241. }
  4242. void View::insertPicture()
  4243. {
  4244. //Note: We don't use the usual insert handler here (which allows the user to drag-select the target area
  4245. //for the object) because when inserting raster graphics, it is usually desireable to insert at 100% size,
  4246. //since the graphic won't look right if inserted with an incorrect aspect ratio or if blurred due to the
  4247. //scaling. If the user wishes to change the size and/or aspect ratio, they can do that afterwards.
  4248. //This behaviour can be seen in other spreadsheets.
  4249. //-- Robert Knight 12/02/06 <robertknight@gmail.com>
  4250. KURL file = KFileDialog::getImageOpenURL( TQString(), d->canvas );
  4251. if (file.isEmpty())
  4252. return;
  4253. if ( !d->activeSheet )
  4254. return;
  4255. InsertObjectCommand *cmd = new InsertObjectCommand( KoRect(markerDocumentPosition(),KoSize(0,0)) , file, d->canvas );
  4256. doc()->addCommand( cmd );
  4257. cmd->execute();
  4258. }
  4259. void View::slotUpdateChildGeometry( EmbeddedKOfficeObject */*_child*/ )
  4260. {
  4261. // ##############
  4262. // TODO
  4263. /*
  4264. if ( _child->sheet() != d->activeSheet )
  4265. return;
  4266. // Find frame for child
  4267. ChildFrame *f = 0L;
  4268. TQPtrListIterator<ChildFrame> it( m_lstFrames );
  4269. for ( ; it.current() && !f; ++it )
  4270. if ( it.current()->child() == _child )
  4271. f = it.current();
  4272. assert( f != 0L );
  4273. // Are we already up to date ?
  4274. if ( _child->geometry() == f->partGeometry() )
  4275. return;
  4276. // TODO zooming
  4277. f->setPartGeometry( _child->geometry() );
  4278. */
  4279. }
  4280. void View::toggleProtectDoc( bool mode )
  4281. {
  4282. if ( !doc() || !doc()->map() )
  4283. return;
  4284. TQCString passwd;
  4285. if ( mode )
  4286. {
  4287. int result = KPasswordDialog::getNewPassword( passwd, i18n( "Protect Document" ) );
  4288. if ( result != KPasswordDialog::Accepted )
  4289. {
  4290. d->actions->protectDoc->setChecked( false );
  4291. return;
  4292. }
  4293. TQCString hash( "" );
  4294. TQString password( passwd );
  4295. if ( password.length() > 0 )
  4296. SHA1::getHash( password, hash );
  4297. doc()->map()->setProtected( hash );
  4298. }
  4299. else
  4300. {
  4301. int result = KPasswordDialog::getPassword( passwd, i18n( "Unprotect Document" ) );
  4302. if ( result != KPasswordDialog::Accepted )
  4303. {
  4304. d->actions->protectDoc->setChecked( true );
  4305. return;
  4306. }
  4307. TQCString hash( "" );
  4308. TQString password( passwd );
  4309. if ( password.length() > 0 )
  4310. SHA1::getHash( password, hash );
  4311. if ( !doc()->map()->checkPassword( hash ) )
  4312. {
  4313. KMessageBox::error( 0, i18n( "Password is incorrect." ) );
  4314. d->actions->protectDoc->setChecked( true );
  4315. return;
  4316. }
  4317. doc()->map()->setProtected( TQCString() );
  4318. }
  4319. doc()->setModified( true );
  4320. d->adjustWorkbookActions( !mode );
  4321. }
  4322. void View::toggleProtectSheet( bool mode )
  4323. {
  4324. if ( !d->activeSheet )
  4325. return;
  4326. TQCString passwd;
  4327. if ( mode )
  4328. {
  4329. int result = KPasswordDialog::getNewPassword( passwd, i18n( "Protect Sheet" ) );
  4330. if ( result != KPasswordDialog::Accepted )
  4331. {
  4332. d->actions->protectSheet->setChecked( false );
  4333. return;
  4334. }
  4335. TQCString hash( "" );
  4336. TQString password( passwd );
  4337. if ( password.length() > 0 )
  4338. SHA1::getHash( password, hash );
  4339. d->activeSheet->setProtected( hash );
  4340. }
  4341. else
  4342. {
  4343. int result = KPasswordDialog::getPassword( passwd, i18n( "Unprotect Sheet" ) );
  4344. if ( result != KPasswordDialog::Accepted )
  4345. {
  4346. d->actions->protectSheet->setChecked( true );
  4347. return;
  4348. }
  4349. TQCString hash( "" );
  4350. TQString password( passwd );
  4351. if ( password.length() > 0 )
  4352. SHA1::getHash( password, hash );
  4353. if ( !d->activeSheet->checkPassword( hash ) )
  4354. {
  4355. KMessageBox::error( 0, i18n( "Password is incorrect." ) );
  4356. d->actions->protectSheet->setChecked( true );
  4357. return;
  4358. }
  4359. d->activeSheet->setProtected( TQCString() );
  4360. }
  4361. doc()->setModified( true );
  4362. d->adjustActions( !mode );
  4363. doc()->emitBeginOperation();
  4364. // d->activeSheet->setRegionPaintDirty( TQRect(TQPoint( 0, 0 ), TQPoint( KS_colMax, KS_rowMax ) ) );
  4365. refreshView();
  4366. updateEditWidget();
  4367. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  4368. }
  4369. void View::togglePageBorders( bool mode )
  4370. {
  4371. if ( !d->activeSheet )
  4372. return;
  4373. doc()->emitBeginOperation( false );
  4374. d->activeSheet->setShowPageBorders( mode );
  4375. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  4376. }
  4377. void View::viewZoom( const TQString & s )
  4378. {
  4379. int oldZoom = doc()->zoom();
  4380. bool ok = false;
  4381. TQRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
  4382. regexp.search(s);
  4383. int newZoom=regexp.cap(1).toInt(&ok);
  4384. if ( !ok || newZoom < 10 ) //zoom should be valid and >10
  4385. newZoom = oldZoom;
  4386. if ( newZoom != oldZoom )
  4387. {
  4388. d->actions->viewZoom->setZoom( newZoom );
  4389. doc()->emitBeginOperation( false );
  4390. d->canvas->closeEditor();
  4391. setZoom( newZoom, true );
  4392. if (activeSheet())
  4393. {
  4394. TQRect r( d->activeSheet->visibleRect( d->canvas ) );
  4395. r.setWidth( r.width() + 2 );
  4396. doc()->emitEndOperation( r );
  4397. }
  4398. }
  4399. }
  4400. void View::setZoom( int zoom, bool /*updateViews*/ )
  4401. {
  4402. kdDebug() << "---------SetZoom: " << zoom << endl;
  4403. // Set the zoom in KoView (for embedded views)
  4404. doc()->emitBeginOperation( false );
  4405. doc()->setZoomAndResolution( zoom, KoGlobal::dpiX(), KoGlobal::dpiY());
  4406. //KoView::setZoom( doc()->zoomedResolutionY() /* KoView only supports one zoom */ );
  4407. Q_ASSERT(d->activeSheet);
  4408. if (d->activeSheet) //this is 0 when viewing a document in konqueror!? (see Q_ASSERT above)
  4409. d->activeSheet->setRegionPaintDirty(TQRect(TQPoint(0,0), TQPoint(KS_colMax, KS_rowMax)));
  4410. doc()->refreshInterface();
  4411. doc()->emitEndOperation();
  4412. }
  4413. void View::showStatusBar( bool b )
  4414. {
  4415. doc()->setShowStatusBar( b );
  4416. refreshView();
  4417. }
  4418. void View::showTabBar( bool b )
  4419. {
  4420. doc()->setShowTabBar( b );
  4421. refreshView();
  4422. }
  4423. void View::showFormulaBar( bool b )
  4424. {
  4425. doc()->setShowFormulaBar( b );
  4426. refreshView();
  4427. }
  4428. void View::preference()
  4429. {
  4430. if ( !d->activeSheet )
  4431. return;
  4432. PreferenceDialog dlg( this, "Preference" );
  4433. if ( dlg.exec() )
  4434. {
  4435. doc()->emitBeginOperation( false );
  4436. d->activeSheet->refreshPreference();
  4437. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  4438. }
  4439. }
  4440. void View::addModifyComment()
  4441. {
  4442. if ( !d->activeSheet )
  4443. return;
  4444. CommentDialog dlg( this, "comment",
  4445. TQPoint( d->canvas->markerColumn(),
  4446. d->canvas->markerRow() ) );
  4447. if ( dlg.exec() )
  4448. updateEditWidget();
  4449. }
  4450. void View::setSelectionComment( TQString comment )
  4451. {
  4452. if ( d->activeSheet != NULL )
  4453. {
  4454. doc()->emitBeginOperation( false );
  4455. d->activeSheet->setSelectionComment( selectionInfo(), comment.stripWhiteSpace() );
  4456. updateEditWidget();
  4457. markSelectionAsDirty();
  4458. doc()->emitEndOperation();
  4459. }
  4460. }
  4461. void View::editCell()
  4462. {
  4463. if ( d->canvas->editor() )
  4464. return;
  4465. d->canvas->createEditor(true);
  4466. }
  4467. bool View::showSheet(const TQString& sheetName) {
  4468. Sheet *t=doc()->map()->findSheet(sheetName);
  4469. if ( !t )
  4470. {
  4471. kdDebug(36001) << "Unknown sheet " <<sheetName<< endl;
  4472. return false;
  4473. }
  4474. d->canvas->closeEditor();
  4475. setActiveSheet( t );
  4476. return true;
  4477. }
  4478. void View::nextSheet()
  4479. {
  4480. Sheet * t = doc()->map()->nextSheet( activeSheet() );
  4481. if ( !t )
  4482. {
  4483. kdDebug(36001) << "Unknown sheet " << endl;
  4484. return;
  4485. }
  4486. d->canvas->closeEditor();
  4487. setActiveSheet( t );
  4488. d->tabBar->setActiveTab( t->sheetName() );
  4489. d->tabBar->ensureVisible( t->sheetName() );
  4490. }
  4491. void View::previousSheet()
  4492. {
  4493. Sheet * t = doc()->map()->previousSheet( activeSheet() );
  4494. if ( !t )
  4495. {
  4496. kdDebug(36001) << "Unknown sheet " << endl;
  4497. return;
  4498. }
  4499. d->canvas->closeEditor();
  4500. setActiveSheet( t );
  4501. d->tabBar->setActiveTab( t->sheetName() );
  4502. d->tabBar->ensureVisible( t->sheetName() );
  4503. }
  4504. void View::firstSheet()
  4505. {
  4506. Sheet *t = doc()->map()->firstSheet();
  4507. if ( !t )
  4508. {
  4509. kdDebug(36001) << "Unknown sheet " << endl;
  4510. return;
  4511. }
  4512. d->canvas->closeEditor();
  4513. setActiveSheet( t );
  4514. d->tabBar->setActiveTab( t->sheetName() );
  4515. d->tabBar->ensureVisible( t->sheetName() );
  4516. }
  4517. void View::lastSheet()
  4518. {
  4519. Sheet *t = doc()->map()->lastSheet( );
  4520. if ( !t )
  4521. {
  4522. kdDebug(36001) << "Unknown sheet " << endl;
  4523. return;
  4524. }
  4525. d->canvas->closeEditor();
  4526. setActiveSheet( t );
  4527. d->tabBar->setActiveTab( t->sheetName() );
  4528. d->tabBar->ensureVisible( t->sheetName() );
  4529. }
  4530. void View::keyPressEvent ( TQKeyEvent* _ev )
  4531. {
  4532. // Dont eat accelerators
  4533. if ( _ev->state() & ( TQt::AltButton | TQt::ControlButton ) )
  4534. {
  4535. if ( _ev->state() & ( TQt::ControlButton ) )
  4536. {
  4537. switch( _ev->key() )
  4538. {
  4539. #ifndef NDEBUG
  4540. case TQt::Key_V: // Ctrl+Shift+V to show debug (similar to KWord)
  4541. if ( _ev->state() & TQt::ShiftButton )
  4542. d->activeSheet->printDebug();
  4543. #endif
  4544. default:
  4545. TQWidget::keyPressEvent( _ev );
  4546. return;
  4547. }
  4548. }
  4549. TQWidget::keyPressEvent( _ev );
  4550. }
  4551. else
  4552. TQApplication::sendEvent( d->canvas, _ev );
  4553. }
  4554. KoDocument * View::hitTest( const TQPoint& /*pos*/ )
  4555. {
  4556. // // Code copied from KoView::hitTest
  4557. // KoViewChild *viewChild;
  4558. //
  4559. // TQWMatrix m = matrix();
  4560. // m.translate( d->canvas->xOffset() / doc()->zoomedResolutionX(),
  4561. // d->canvas->yOffset() / doc()->zoomedResolutionY() );
  4562. //
  4563. // KoDocumentChild *docChild = selectedChild();
  4564. // if ( docChild )
  4565. // {
  4566. // if ( ( viewChild = child( docChild->document() ) ) )
  4567. // {
  4568. // if ( viewChild->frameRegion( m ).contains( pos ) )
  4569. // return 0;
  4570. // }
  4571. // else
  4572. // if ( docChild->frameRegion( m ).contains( pos ) )
  4573. // return 0;
  4574. // }
  4575. //
  4576. // docChild = activeChild();
  4577. // if ( docChild )
  4578. // {
  4579. // if ( ( viewChild = child( docChild->document() ) ) )
  4580. // {
  4581. // if ( viewChild->frameRegion( m ).contains( pos ) )
  4582. // return 0;
  4583. // }
  4584. // else
  4585. // if ( docChild->frameRegion( m ).contains( pos ) )
  4586. // return 0;
  4587. // }
  4588. //
  4589. // TQPtrListIterator<KoDocumentChild> it( doc()->children() );
  4590. // for (; it.current(); ++it )
  4591. // {
  4592. // // Is the child document on the visible sheet ?
  4593. // if ( ((EmbeddedKOfficeObject*)it.current())->sheet() == d->activeSheet )
  4594. // {
  4595. // KoDocument *doc = it.current()->hitTest( pos, m );
  4596. // if ( doc )
  4597. // return doc;
  4598. // }
  4599. // }
  4600. //
  4601. return doc();
  4602. }
  4603. int View::leftBorder() const
  4604. {
  4605. return int( d->canvas->doc()->zoomItX( YBORDER_WIDTH ) );
  4606. }
  4607. int View::rightBorder() const
  4608. {
  4609. return d->vertScrollBar->width();
  4610. }
  4611. int View::topBorder() const
  4612. {
  4613. return d->toolWidget->height() + int( d->canvas->doc()->zoomItX( Format::globalRowHeight() + 2 ) );
  4614. }
  4615. int View::bottomBorder() const
  4616. {
  4617. return d->horzScrollBar->height();
  4618. }
  4619. void View::refreshView()
  4620. {
  4621. kdDebug() << "refreshing view" << endl;
  4622. Sheet * sheet = activeSheet();
  4623. if ( !sheet )
  4624. return;
  4625. d->adjustActions( !sheet->isProtected() );
  4626. d->actions->viewZoom->setZoom( doc()->zoom() );
  4627. bool active = sheet->getShowFormula();
  4628. if ( sheet && !sheet->isProtected() )
  4629. {
  4630. d->actions->alignLeft->setEnabled( !active );
  4631. d->actions->alignCenter->setEnabled( !active );
  4632. d->actions->alignRight->setEnabled( !active );
  4633. }
  4634. d->tabBar->setReadOnly( !doc()->isReadWrite() || doc()->map()->isProtected() );
  4635. d->toolWidget->setShown( doc()->showFormulaBar() );
  4636. d->editWidget->showEditWidget( doc()->showFormulaBar() );
  4637. d->hBorderWidget->setShown( doc()->showColumnHeader() );
  4638. d->vBorderWidget->setShown( doc()->showRowHeader() );
  4639. d->vertScrollBar->setShown( doc()->showVerticalScrollBar() );
  4640. d->horzScrollBar->setShown( doc()->showHorizontalScrollBar() );
  4641. d->tabBar->setShown( doc()->showTabBar() );
  4642. if ( statusBar() ) statusBar()->setShown( doc()->showStatusBar() );
  4643. d->canvas->updatePosWidget();
  4644. d->hBorderWidget->setMinimumHeight( doc()->zoomItY( KoGlobal::defaultFont().pointSizeFloat() + 5 ) );
  4645. d->vBorderWidget->setMinimumWidth( doc()->zoomItX( YBORDER_WIDTH ) );
  4646. Sheet::LayoutDirection sheetDir = sheet->layoutDirection();
  4647. bool interfaceIsRTL = TQApplication::reverseLayout();
  4648. kdDebug()<<" sheetDir == Sheet::LeftToRight :"<<( sheetDir == Sheet::LeftToRight )<<endl;
  4649. if ((sheetDir == Sheet::LeftToRight && !interfaceIsRTL) ||
  4650. (sheetDir == Sheet::RightToLeft && interfaceIsRTL))
  4651. {
  4652. d->formulaBarLayout->setDirection( TQBoxLayout::LeftToRight );
  4653. d->viewLayout->setOrigin( TQGridLayout::TopLeft );
  4654. d->tabScrollBarLayout->setDirection( TQBoxLayout::LeftToRight );
  4655. d->tabBar->setReverseLayout( interfaceIsRTL );
  4656. }
  4657. else
  4658. {
  4659. d->formulaBarLayout->setDirection( TQBoxLayout::RightToLeft );
  4660. d->viewLayout->setOrigin( TQGridLayout::TopRight );
  4661. d->tabScrollBarLayout->setDirection( TQBoxLayout::RightToLeft );
  4662. d->tabBar->setReverseLayout( !interfaceIsRTL );
  4663. }
  4664. }
  4665. void View::resizeEvent( TQResizeEvent * )
  4666. {
  4667. }
  4668. void View::popupChildMenu( KoChild* child, const TQPoint& /*global_pos*/ )
  4669. {
  4670. if ( !child )
  4671. return;
  4672. delete d->popupChild;
  4673. // d->popupChildObject = static_cast<EmbeddedKOfficeObject*>(child);
  4674. //
  4675. // d->popupChild = new TQPopupMenu( this );
  4676. //
  4677. // d->popupChild->insertItem( i18n("Delete Embedded Document"), this, TQT_SLOT( slotPopupDeleteChild() ) );
  4678. //
  4679. // d->popupChild->popup( global_pos );
  4680. }
  4681. void View::slotPopupDeleteChild()
  4682. {
  4683. // if ( !d->popupChildObject || !d->popupChildObject->sheet() )
  4684. // return;
  4685. //Removed popup warning dialog because
  4686. // a) It is annoying from a user's persepective
  4687. // b) The behaviour should be consistant with other KOffice apps
  4688. /*int ret = KMessageBox::warningContinueCancel(this,i18n("You are about to remove this embedded document.\nDo you want to continue?"),i18n("Delete Embedded Document"),KGuiItem(i18n("&Delete"),"edit-delete"));
  4689. if ( ret == KMessageBox::Continue )
  4690. {
  4691. }*/
  4692. // doc()->emitBeginOperation(false);
  4693. // d->popupChildObject->sheet()->deleteChild( d->popupChildObject );
  4694. // d->popupChildObject = 0;
  4695. // doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  4696. }
  4697. void View::popupColumnMenu( const TQPoint & _point )
  4698. {
  4699. assert( d->activeSheet );
  4700. if ( !koDocument()->isReadWrite() )
  4701. return;
  4702. delete d->popupColumn ;
  4703. d->popupColumn = new TQPopupMenu( this );
  4704. bool isProtected = d->activeSheet->isProtected();
  4705. if ( !isProtected )
  4706. {
  4707. d->actions->cellLayout->plug( d->popupColumn );
  4708. d->popupColumn->insertSeparator();
  4709. d->actions->cut->plug( d->popupColumn );
  4710. }
  4711. d->actions->copy->plug( d->popupColumn );
  4712. if ( !isProtected )
  4713. {
  4714. d->actions->paste->plug( d->popupColumn );
  4715. d->actions->specialPaste->plug( d->popupColumn );
  4716. d->actions->insertCellCopy->plug( d->popupColumn );
  4717. d->popupColumn->insertSeparator();
  4718. d->actions->defaultFormat->plug( d->popupColumn );
  4719. // If there is no selection
  4720. if (!d->selection->isColumnOrRowSelected())
  4721. {
  4722. d->actions->areaName->plug( d->popupColumn );
  4723. }
  4724. d->actions->resizeColumn->plug( d->popupColumn );
  4725. d->popupColumn->insertItem( i18n("Adjust Column"), this, TQT_SLOT(slotPopupAdjustColumn() ) );
  4726. d->popupColumn->insertSeparator();
  4727. d->actions->insertColumn->plug( d->popupColumn );
  4728. d->actions->deleteColumn->plug( d->popupColumn );
  4729. d->actions->hideColumn->plug( d->popupColumn );
  4730. d->actions->showSelColumns->setEnabled(false);
  4731. ColumnFormat* format;
  4732. //kdDebug(36001) << "Column: L: " << rect.left() << endl;
  4733. Region::ConstIterator endOfList = d->selection->constEnd();
  4734. for (Region::ConstIterator it = d->selection->constBegin(); it != endOfList; ++it)
  4735. {
  4736. TQRect range = (*it)->rect().normalize();
  4737. int col;
  4738. for (col = range.left(); col < range.right(); ++col)
  4739. {
  4740. format = activeSheet()->columnFormat(col);
  4741. if ( format->isHide() )
  4742. {
  4743. d->actions->showSelColumns->setEnabled( true );
  4744. d->actions->showSelColumns->plug( d->popupColumn );
  4745. break;
  4746. }
  4747. }
  4748. if (range.left() > 1 && col == range.right())
  4749. {
  4750. bool allHidden = true;
  4751. for (col = 1; col < range.left(); ++col)
  4752. {
  4753. format = activeSheet()->columnFormat(col);
  4754. allHidden &= format->isHide();
  4755. }
  4756. if (allHidden)
  4757. {
  4758. d->actions->showSelColumns->setEnabled( true );
  4759. d->actions->showSelColumns->plug( d->popupColumn );
  4760. break;
  4761. }
  4762. }
  4763. else
  4764. {
  4765. break;
  4766. }
  4767. }
  4768. }
  4769. TQT_BASE_OBJECT_NAME::connect( d->popupColumn, TQT_SIGNAL(activated( int ) ), this, TQT_SLOT( slotActivateTool( int ) ) );
  4770. d->popupColumn->popup( _point );
  4771. }
  4772. void View::slotPopupAdjustColumn()
  4773. {
  4774. if ( !d->activeSheet )
  4775. return;
  4776. d->activeSheet->adjustColumn(*selectionInfo());
  4777. }
  4778. void View::popupRowMenu( const TQPoint & _point )
  4779. {
  4780. assert( d->activeSheet );
  4781. if ( !koDocument()->isReadWrite() )
  4782. return;
  4783. delete d->popupRow ;
  4784. d->popupRow= new TQPopupMenu();
  4785. bool isProtected = d->activeSheet->isProtected();
  4786. if ( !isProtected )
  4787. {
  4788. d->actions->cellLayout->plug( d->popupRow );
  4789. d->popupRow->insertSeparator();
  4790. d->actions->cut->plug( d->popupRow );
  4791. }
  4792. d->actions->copy->plug( d->popupRow );
  4793. if ( !isProtected )
  4794. {
  4795. d->actions->paste->plug( d->popupRow );
  4796. d->actions->specialPaste->plug( d->popupRow );
  4797. d->actions->insertCellCopy->plug( d->popupRow );
  4798. d->popupRow->insertSeparator();
  4799. d->actions->defaultFormat->plug( d->popupRow );
  4800. // If there is no selection
  4801. if (!d->selection->isColumnOrRowSelected())
  4802. {
  4803. d->actions->areaName->plug(d->popupRow);
  4804. }
  4805. d->actions->resizeRow->plug( d->popupRow );
  4806. d->popupRow->insertItem( i18n("Adjust Row"), this, TQT_SLOT( slotPopupAdjustRow() ) );
  4807. d->popupRow->insertSeparator();
  4808. d->actions->insertRow->plug( d->popupRow );
  4809. d->actions->deleteRow->plug( d->popupRow );
  4810. d->actions->hideRow->plug( d->popupRow );
  4811. d->actions->showSelColumns->setEnabled(false);
  4812. RowFormat* format;
  4813. Region::ConstIterator endOfList = d->selection->constEnd();
  4814. for (Region::ConstIterator it = d->selection->constBegin(); it != endOfList; ++it)
  4815. {
  4816. TQRect range = (*it)->rect().normalize();
  4817. int row;
  4818. for (row = range.top(); row < range.bottom(); ++row)
  4819. {
  4820. format = activeSheet()->rowFormat(row);
  4821. if ( format->isHide() )
  4822. {
  4823. d->actions->showSelRows->setEnabled( true );
  4824. d->actions->showSelRows->plug( d->popupRow );
  4825. break;
  4826. }
  4827. }
  4828. if (range.top() > 1 && row == range.bottom())
  4829. {
  4830. bool allHidden = true;
  4831. for (row = 1; row < range.top(); ++row)
  4832. {
  4833. format = activeSheet()->rowFormat(row);
  4834. allHidden &= format->isHide();
  4835. }
  4836. if (allHidden)
  4837. {
  4838. d->actions->showSelRows->setEnabled( true );
  4839. d->actions->showSelRows->plug( d->popupRow );
  4840. break;
  4841. }
  4842. }
  4843. else
  4844. {
  4845. break;
  4846. }
  4847. }
  4848. }
  4849. TQT_BASE_OBJECT_NAME::connect( d->popupRow, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( slotActivateTool( int ) ) );
  4850. d->popupRow->popup( _point );
  4851. }
  4852. void View::slotPopupAdjustRow()
  4853. {
  4854. if ( !d->activeSheet )
  4855. return;
  4856. d->activeSheet->adjustRow(*selectionInfo());
  4857. }
  4858. void View::slotListChoosePopupMenu( )
  4859. {
  4860. if ( !koDocument()->isReadWrite() )
  4861. return;
  4862. assert( d->activeSheet );
  4863. delete d->popupListChoose;
  4864. d->popupListChoose = new TQPopupMenu();
  4865. int id = 0;
  4866. TQRect selection( d->selection->selection() );
  4867. Cell * cell = d->activeSheet->cellAt( d->canvas->markerColumn(), d->canvas->markerRow() );
  4868. TQString tmp = cell->text();
  4869. TQStringList itemList;
  4870. for ( int col = selection.left(); col <= selection.right(); ++col )
  4871. {
  4872. Cell * c = d->activeSheet->getFirstCellColumn( col );
  4873. while ( c )
  4874. {
  4875. if ( !c->isPartOfMerged()
  4876. && !( col == d->canvas->markerColumn()
  4877. && c->row() == d->canvas->markerRow()) )
  4878. {
  4879. if ( c->value().isString() && c->text() != tmp && !c->text().isEmpty() )
  4880. {
  4881. if ( itemList.findIndex( c->text() ) == -1 )
  4882. itemList.append(c->text());
  4883. }
  4884. }
  4885. c = d->activeSheet->getNextCellDown( col, c->row() );
  4886. }
  4887. }
  4888. /* TODO: remove this later:
  4889. for( ;c; c = c->nextCell() )
  4890. {
  4891. int col = c->column();
  4892. if ( selection.left() <= col && selection.right() >= col
  4893. &&!c->isPartOfMerged()&& !(col==d->canvas->markerColumn()&& c->row()==d->canvas->markerRow()))
  4894. {
  4895. if (c->isString() && c->text()!=tmp && !c->text().isEmpty())
  4896. {
  4897. if (itemList.findIndex(c->text())==-1)
  4898. itemList.append(c->text());
  4899. }
  4900. }
  4901. }
  4902. */
  4903. for ( TQStringList::Iterator it = itemList.begin(); it != itemList.end();++it )
  4904. d->popupListChoose->insertItem( (*it), id++ );
  4905. if ( id == 0 )
  4906. return;
  4907. RowFormat * rl = d->activeSheet->rowFormat( d->canvas->markerRow());
  4908. double tx = d->activeSheet->dblColumnPos( d->canvas->markerColumn(), d->canvas );
  4909. double ty = d->activeSheet->dblRowPos(d->canvas->markerRow(), d->canvas );
  4910. double h = rl->dblHeight( d->canvas );
  4911. if ( cell->extraYCells() )
  4912. h = cell->extraHeight();
  4913. ty += h;
  4914. if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
  4915. {
  4916. tx = canvasWidget()->width() - tx;
  4917. }
  4918. TQPoint p( (int)tx, (int)ty );
  4919. TQPoint p2 = d->canvas->mapToGlobal( p );
  4920. if ( d->activeSheet->layoutDirection()==Sheet::RightToLeft )
  4921. {
  4922. p2.setX( p2.x() - d->popupListChoose->sizeHint().width() + 1 );
  4923. }
  4924. d->popupListChoose->popup( p2 );
  4925. TQT_BASE_OBJECT_NAME::connect( d->popupListChoose, TQT_SIGNAL( activated( int ) ),
  4926. this, TQT_SLOT( slotItemSelected( int ) ) );
  4927. }
  4928. void View::slotItemSelected( int id )
  4929. {
  4930. TQString tmp = d->popupListChoose->text( id );
  4931. int x = d->canvas->markerColumn();
  4932. int y = d->canvas->markerRow();
  4933. Cell * cell = d->activeSheet->nonDefaultCell( x, y );
  4934. if ( tmp == cell->text() )
  4935. return;
  4936. doc()->emitBeginOperation( false );
  4937. if ( !doc()->undoLocked() )
  4938. {
  4939. UndoSetText* undo = new UndoSetText( doc(), d->activeSheet, cell->text(),
  4940. x, y, cell->formatType() );
  4941. doc()->addCommand( undo );
  4942. }
  4943. cell->setCellText( tmp );
  4944. d->editWidget->setText( tmp );
  4945. doc()->emitEndOperation( TQRect( x, y, 1, 1 ) );
  4946. }
  4947. void View::openPopupMenu( const TQPoint & _point )
  4948. {
  4949. assert( d->activeSheet );
  4950. delete d->popupMenu;
  4951. if ( !koDocument()->isReadWrite() )
  4952. return;
  4953. d->popupMenu = new TQPopupMenu();
  4954. EmbeddedObject *obj;
  4955. if ( d->canvas->isObjectSelected() && ( obj = d->canvas->getObject( d->canvas->mapFromGlobal( _point ), d->activeSheet ) ) && obj->isSelected() )
  4956. {
  4957. d->actions->deleteCell->plug( d->popupMenu );
  4958. d->popupMenu->insertSeparator();
  4959. d->actions->cut->plug( d->popupMenu );
  4960. d->actions->copy->plug( d->popupMenu );
  4961. d->actions->paste->plug( d->popupMenu );
  4962. d->popupMenu->popup( _point );
  4963. d->popupMenu->insertSeparator();
  4964. d->actions->actionExtraProperties->plug( d->popupMenu );
  4965. return;
  4966. }
  4967. Cell * cell = d->activeSheet->cellAt( d->canvas->markerColumn(), d->canvas->markerRow() );
  4968. bool isProtected = d->activeSheet->isProtected();
  4969. if ( !cell->isDefault() && cell->format()->notProtected( d->canvas->markerColumn(), d->canvas->markerRow() )
  4970. && d->selection->isSingular() )
  4971. isProtected = false;
  4972. if ( !isProtected )
  4973. {
  4974. d->actions->cellLayout->plug( d->popupMenu );
  4975. d->popupMenu->insertSeparator();
  4976. d->actions->cut->plug( d->popupMenu );
  4977. }
  4978. d->actions->copy->plug( d->popupMenu );
  4979. if ( !isProtected )
  4980. d->actions->paste->plug( d->popupMenu );
  4981. if ( !isProtected )
  4982. {
  4983. d->actions->specialPaste->plug( d->popupMenu );
  4984. d->actions->insertCellCopy->plug( d->popupMenu );
  4985. d->popupMenu->insertSeparator();
  4986. d->actions->deleteCell->plug( d->popupMenu );
  4987. d->actions->adjust->plug( d->popupMenu );
  4988. d->actions->defaultFormat->plug( d->popupMenu );
  4989. // If there is no selection
  4990. if (!d->selection->isColumnOrRowSelected())
  4991. {
  4992. d->actions->areaName->plug( d->popupMenu );
  4993. d->popupMenu->insertSeparator();
  4994. d->actions->insertCell->plug( d->popupMenu );
  4995. d->actions->removeCell->plug( d->popupMenu );
  4996. }
  4997. d->popupMenu->insertSeparator();
  4998. d->actions->addModifyComment->plug( d->popupMenu );
  4999. if ( !cell->format()->comment(d->canvas->markerColumn(), d->canvas->markerRow()).isEmpty() )
  5000. {
  5001. d->actions->removeComment->plug( d->popupMenu );
  5002. }
  5003. if (activeSheet()->testListChoose(selectionInfo()))
  5004. {
  5005. d->popupMenu->insertSeparator();
  5006. d->popupMenu->insertItem( i18n("Selection List..."), this, TQT_SLOT( slotListChoosePopupMenu() ) );
  5007. }
  5008. }
  5009. // Remove informations about the last tools we offered
  5010. d->toolList.clear();
  5011. d->toolList.setAutoDelete( true );
  5012. if ( !isProtected && !activeSheet()->getWordSpelling( selectionInfo() ).isEmpty() )
  5013. {
  5014. d->popupMenuFirstToolId = 10;
  5015. int i = 0;
  5016. TQValueList<KDataToolInfo> tools = KDataToolInfo::query( TQSTRING_OBJECT_NAME_STRING, "text/plain", doc()->instance() );
  5017. if ( tools.count() > 0 )
  5018. {
  5019. d->popupMenu->insertSeparator();
  5020. TQValueList<KDataToolInfo>::Iterator entry = tools.begin();
  5021. for( ; entry != tools.end(); ++entry )
  5022. {
  5023. TQStringList lst = (*entry).userCommands();
  5024. TQStringList::ConstIterator it = lst.begin();
  5025. // ### Torben: Insert pixmaps here, too
  5026. for (; it != lst.end(); ++it )
  5027. d->popupMenu->insertItem( *it, d->popupMenuFirstToolId + i++ );
  5028. lst = (*entry).commands();
  5029. it = lst.begin();
  5030. for (; it != lst.end(); ++it )
  5031. {
  5032. Private::ToolEntry *t = new Private::ToolEntry;
  5033. t->command = *it;
  5034. t->info = *entry;
  5035. d->toolList.append( t );
  5036. }
  5037. }
  5038. TQT_BASE_OBJECT_NAME::connect( d->popupMenu, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( slotActivateTool( int ) ) );
  5039. }
  5040. }
  5041. d->popupMenu->popup( _point );
  5042. }
  5043. void View::slotActivateTool( int _id )
  5044. {
  5045. if (!activeSheet()) return;
  5046. // Is it the id of a tool in the latest popupmenu ?
  5047. if ( _id < d->popupMenuFirstToolId )
  5048. return;
  5049. Private::ToolEntry* entry = d->toolList.at( _id - d->popupMenuFirstToolId );
  5050. KDataTool* tool = entry->info.createTool();
  5051. if ( !tool )
  5052. {
  5053. kdDebug(36001) << "Could not create Tool" << endl;
  5054. return;
  5055. }
  5056. TQString text = activeSheet()->getWordSpelling( selectionInfo() );
  5057. if ( tool->run( entry->command, &text, TQSTRING_OBJECT_NAME_STRING, "text/plain") )
  5058. {
  5059. doc()->emitBeginOperation(false);
  5060. activeSheet()->setWordSpelling( selectionInfo(), text);
  5061. Cell *cell = d->activeSheet->cellAt( d->canvas->markerColumn(), d->canvas->markerRow() );
  5062. d->editWidget->setText( cell->text() );
  5063. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5064. }
  5065. }
  5066. void View::deleteSelection()
  5067. {
  5068. if (!activeSheet()) return;
  5069. if ( canvasWidget()->isObjectSelected() )
  5070. {
  5071. deleteSelectedObjects();
  5072. return;
  5073. }
  5074. doc()->emitBeginOperation( false );
  5075. d->activeSheet->deleteSelection( selectionInfo() );
  5076. calcStatusBarOp();
  5077. updateEditWidget();
  5078. markSelectionAsDirty();
  5079. doc()->emitEndOperation();
  5080. }
  5081. void View::deleteSelectedObjects()
  5082. {
  5083. KMacroCommand * macroCommand = 0L;
  5084. TQPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
  5085. for ( ; it.current() ; ++it )
  5086. {
  5087. if ( it.current()->sheet() == canvasWidget()->activeSheet() && it.current()->isSelected() )
  5088. {
  5089. // d->activeSheet->setRegionPaintDirty( it.
  5090. if( !macroCommand )
  5091. macroCommand = new KMacroCommand( i18n( "Remove Object" ) );
  5092. RemoveObjectCommand *cmd = new RemoveObjectCommand( it.current() );
  5093. macroCommand->addCommand( cmd );
  5094. }
  5095. }
  5096. if ( macroCommand )
  5097. {
  5098. doc()->addCommand( macroCommand );
  5099. canvasWidget()->setMouseSelectedObject( false );
  5100. macroCommand->execute();
  5101. }
  5102. }
  5103. void View::adjust()
  5104. {
  5105. if ( !d->activeSheet )
  5106. return;
  5107. d->activeSheet->adjustArea(*selectionInfo());
  5108. }
  5109. void View::clearTextSelection()
  5110. {
  5111. if (!activeSheet())
  5112. return;
  5113. doc()->emitBeginOperation( false );
  5114. d->activeSheet->clearTextSelection( selectionInfo() );
  5115. updateEditWidget();
  5116. markSelectionAsDirty();
  5117. doc()->emitEndOperation();
  5118. }
  5119. void View::clearCommentSelection()
  5120. {
  5121. if (!activeSheet())
  5122. return;
  5123. doc()->emitBeginOperation( false );
  5124. d->activeSheet->setSelectionRemoveComment( selectionInfo() );
  5125. updateEditWidget();
  5126. markSelectionAsDirty();
  5127. doc()->emitEndOperation();
  5128. }
  5129. void View::clearValiditySelection()
  5130. {
  5131. if (!activeSheet())
  5132. return;
  5133. doc()->emitBeginOperation( false );
  5134. d->activeSheet->clearValiditySelection( selectionInfo() );
  5135. updateEditWidget();
  5136. markSelectionAsDirty();
  5137. doc()->emitEndOperation();
  5138. }
  5139. void View::clearConditionalSelection()
  5140. {
  5141. if (!activeSheet())
  5142. return;
  5143. doc()->emitBeginOperation( false );
  5144. d->activeSheet->clearConditionalSelection( selectionInfo() );
  5145. updateEditWidget();
  5146. markSelectionAsDirty();
  5147. doc()->emitEndOperation();
  5148. }
  5149. void View::fillRight()
  5150. {
  5151. if (!activeSheet())
  5152. return;
  5153. doc()->emitBeginOperation( false );
  5154. d->activeSheet->fillSelection( selectionInfo(), Sheet::Right );
  5155. markSelectionAsDirty();
  5156. doc()->emitEndOperation();
  5157. }
  5158. void View::fillLeft()
  5159. {
  5160. if (!activeSheet())
  5161. return;
  5162. doc()->emitBeginOperation( false );
  5163. d->activeSheet->fillSelection( selectionInfo(), Sheet::Left );
  5164. markSelectionAsDirty();
  5165. doc()->emitEndOperation();
  5166. }
  5167. void View::fillUp()
  5168. {
  5169. if (!activeSheet())
  5170. return;
  5171. doc()->emitBeginOperation( false );
  5172. d->activeSheet->fillSelection( selectionInfo(), Sheet::Up );
  5173. markSelectionAsDirty();
  5174. doc()->emitEndOperation();
  5175. }
  5176. void View::fillDown()
  5177. {
  5178. if (!activeSheet())
  5179. return;
  5180. doc()->emitBeginOperation( false );
  5181. d->activeSheet->fillSelection( selectionInfo(), Sheet::Down );
  5182. markSelectionAsDirty();
  5183. doc()->emitEndOperation();
  5184. }
  5185. void View::defaultSelection()
  5186. {
  5187. if (!activeSheet())
  5188. return;
  5189. doc()->emitBeginOperation( false );
  5190. d->activeSheet->defaultSelection( selectionInfo() );
  5191. updateEditWidget();
  5192. markSelectionAsDirty();
  5193. doc()->emitEndOperation();
  5194. }
  5195. void View::slotInsert()
  5196. {
  5197. TQRect r( d->selection->selection() );
  5198. InsertDialog dlg( this, "InsertDialog", r, InsertDialog::Insert );
  5199. dlg.exec();
  5200. }
  5201. void View::slotRemove()
  5202. {
  5203. TQRect r( d->selection->selection() );
  5204. InsertDialog dlg( this, "Remove", r, InsertDialog::Remove );
  5205. dlg.exec();
  5206. }
  5207. void View::slotInsertCellCopy()
  5208. {
  5209. if ( !d->activeSheet )
  5210. return;
  5211. if ( !d->activeSheet->testAreaPasteInsert() )
  5212. {
  5213. doc()->emitBeginOperation( false );
  5214. d->activeSheet->paste( d->selection->lastRange(), true,
  5215. Paste::Normal, Paste::OverWrite, true );
  5216. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5217. }
  5218. else
  5219. {
  5220. PasteInsertDialog dlg( this, "Remove", d->selection->selection() );
  5221. dlg.exec();
  5222. }
  5223. if ( d->activeSheet->getAutoCalc() )
  5224. {
  5225. doc()->emitBeginOperation( false );
  5226. d->activeSheet->recalc();
  5227. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5228. }
  5229. updateEditWidget();
  5230. }
  5231. void View::setAreaName()
  5232. {
  5233. AreaDialog dlg( this, "Area Name",TQPoint(d->canvas->markerColumn(), d->canvas->markerRow()) );
  5234. dlg.exec();
  5235. }
  5236. void View::showAreaName()
  5237. {
  5238. reference dlg( this, "Show Area" );
  5239. dlg.exec();
  5240. }
  5241. void View::resizeRow()
  5242. {
  5243. if (!activeSheet()) return;
  5244. if ( d->selection->isColumnSelected() )
  5245. KMessageBox::error( this, i18n("Area is too large."));
  5246. else
  5247. {
  5248. ResizeRow dlg( this );
  5249. dlg.exec();
  5250. }
  5251. }
  5252. void View::resizeColumn()
  5253. {
  5254. if (!activeSheet()) return;
  5255. if ( d->selection->isRowSelected() )
  5256. KMessageBox::error( this, i18n( "Area is too large." ) );
  5257. else
  5258. {
  5259. ResizeColumn dlg( this );
  5260. dlg.exec();
  5261. }
  5262. }
  5263. void View::equalizeRow()
  5264. {
  5265. if (!activeSheet()) return;
  5266. if ( d->selection->isColumnSelected() )
  5267. KMessageBox::error( this, i18n( "Area is too large." ) );
  5268. else
  5269. {
  5270. doc()->emitBeginOperation( false );
  5271. canvasWidget()->equalizeRow();
  5272. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5273. }
  5274. }
  5275. void View::equalizeColumn()
  5276. {
  5277. if (!activeSheet())
  5278. return;
  5279. if ( d->selection->isRowSelected() )
  5280. KMessageBox::error( this, i18n( "Area is too large." ) );
  5281. else
  5282. {
  5283. doc()->emitBeginOperation( false );
  5284. canvasWidget()->equalizeColumn();
  5285. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5286. }
  5287. }
  5288. void View::layoutDlg()
  5289. {
  5290. if (!activeSheet())
  5291. return;
  5292. CellFormatDialog dlg( this, d->activeSheet );
  5293. }
  5294. void View::extraProperties()
  5295. {
  5296. if (!activeSheet())
  5297. return;
  5298. //d->canvas->setToolEditMode( TEM_MOUSE );
  5299. d->m_propertyEditor = new PropertyEditor( this, "KPrPropertyEditor", d->activeSheet, doc() );
  5300. d->m_propertyEditor->setCaption( i18n( "Properties" ) );
  5301. connect( d->m_propertyEditor, TQT_SIGNAL( propertiesOk() ), this, TQT_SLOT( propertiesOk() ) );
  5302. d->m_propertyEditor->exec();
  5303. disconnect( d->m_propertyEditor, TQT_SIGNAL( propertiesOk() ), this, TQT_SLOT( propertiesOk() ) );
  5304. delete d->m_propertyEditor;
  5305. d->m_propertyEditor = 0;
  5306. }
  5307. void View::propertiesOk()
  5308. {
  5309. KCommand *cmd = d->m_propertyEditor->getCommand();
  5310. if ( cmd )
  5311. {
  5312. cmd->execute();
  5313. doc()->addCommand( cmd );
  5314. }
  5315. }
  5316. void View::styleDialog()
  5317. {
  5318. StyleDlg dlg( this, doc()->styleManager() );
  5319. dlg.exec();
  5320. d->actions->selectStyle->setItems( doc()->styleManager()->styleNames() );
  5321. if ( d->activeSheet )
  5322. {
  5323. d->activeSheet->setLayoutDirtyFlag();
  5324. d->activeSheet->setRegionPaintDirty( d->activeSheet->visibleRect( d->canvas ) );
  5325. }
  5326. if ( d->canvas )
  5327. d->canvas->repaint();
  5328. }
  5329. void View::paperLayoutDlg()
  5330. {
  5331. if ( d->canvas->editor() )
  5332. {
  5333. d->canvas->deleteEditor( true ); // save changes
  5334. }
  5335. SheetPrint* print = d->activeSheet->print();
  5336. KoPageLayout pl;
  5337. pl.format = print->paperFormat();
  5338. pl.orientation = print->orientation();
  5339. pl.ptWidth = MM_TO_POINT( print->paperWidth() );
  5340. pl.ptHeight = MM_TO_POINT( print->paperHeight() );
  5341. pl.ptLeft = MM_TO_POINT( print->leftBorder() );
  5342. pl.ptRight = MM_TO_POINT( print->rightBorder() );
  5343. pl.ptTop = MM_TO_POINT( print->topBorder() );
  5344. pl.ptBottom = MM_TO_POINT( print->bottomBorder() );
  5345. KoHeadFoot hf;
  5346. hf.headLeft = print->localizeHeadFootLine( print->headLeft() );
  5347. hf.headRight = print->localizeHeadFootLine( print->headRight() );
  5348. hf.headMid = print->localizeHeadFootLine( print->headMid() );
  5349. hf.footLeft = print->localizeHeadFootLine( print->footLeft() );
  5350. hf.footRight = print->localizeHeadFootLine( print->footRight() );
  5351. hf.footMid = print->localizeHeadFootLine( print->footMid() );
  5352. KoUnit::Unit unit = doc()->unit();
  5353. PaperLayout * dlg
  5354. = new PaperLayout( this, "PageLayout", pl, hf,
  5355. FORMAT_AND_BORDERS | HEADER_AND_FOOTER,
  5356. unit, d->activeSheet, this );
  5357. dlg->show();
  5358. // dlg destroys itself
  5359. }
  5360. void View::definePrintRange()
  5361. {
  5362. d->activeSheet->print()->definePrintRange( selectionInfo() );
  5363. }
  5364. void View::resetPrintRange()
  5365. {
  5366. d->activeSheet->print()->resetPrintRange();
  5367. }
  5368. void View::wrapText( bool b )
  5369. {
  5370. if ( d->toolbarLock )
  5371. return;
  5372. if ( d->activeSheet != 0L )
  5373. {
  5374. doc()->emitBeginOperation( false );
  5375. d->activeSheet->setSelectionMultiRow( selectionInfo(), b );
  5376. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5377. }
  5378. }
  5379. void View::alignLeft( bool b )
  5380. {
  5381. if ( d->toolbarLock )
  5382. return;
  5383. if ( d->activeSheet != 0L )
  5384. {
  5385. doc()->emitBeginOperation( false );
  5386. if ( !b )
  5387. d->activeSheet->setSelectionAlign( selectionInfo(),
  5388. Format::Undefined );
  5389. else
  5390. d->activeSheet->setSelectionAlign( selectionInfo(),
  5391. Format::Left );
  5392. markSelectionAsDirty();
  5393. doc()->emitEndOperation();
  5394. }
  5395. }
  5396. void View::alignRight( bool b )
  5397. {
  5398. if ( d->toolbarLock )
  5399. return;
  5400. if ( d->activeSheet != 0L )
  5401. {
  5402. doc()->emitBeginOperation( false );
  5403. if ( !b )
  5404. d->activeSheet->setSelectionAlign( selectionInfo(), Format::Undefined );
  5405. else
  5406. d->activeSheet->setSelectionAlign( selectionInfo(), Format::Right );
  5407. markSelectionAsDirty();
  5408. doc()->emitEndOperation();
  5409. }
  5410. }
  5411. void View::alignCenter( bool b )
  5412. {
  5413. if ( d->toolbarLock )
  5414. return;
  5415. if ( d->activeSheet != 0L )
  5416. {
  5417. doc()->emitBeginOperation( false );
  5418. if ( !b )
  5419. d->activeSheet->setSelectionAlign( selectionInfo(), Format::Undefined );
  5420. else
  5421. d->activeSheet->setSelectionAlign( selectionInfo(), Format::Center );
  5422. markSelectionAsDirty();
  5423. doc()->emitEndOperation();
  5424. }
  5425. }
  5426. void View::alignTop( bool b )
  5427. {
  5428. if ( d->toolbarLock )
  5429. return;
  5430. if ( d->activeSheet != 0L )
  5431. {
  5432. doc()->emitBeginOperation( false );
  5433. if ( !b )
  5434. d->activeSheet->setSelectionAlignY( selectionInfo(), Format::UndefinedY );
  5435. else
  5436. d->activeSheet->setSelectionAlignY( selectionInfo(), Format::Top );
  5437. markSelectionAsDirty();
  5438. doc()->emitEndOperation();
  5439. }
  5440. }
  5441. void View::alignBottom( bool b )
  5442. {
  5443. if ( d->toolbarLock )
  5444. return;
  5445. if ( d->activeSheet != 0L )
  5446. {
  5447. doc()->emitBeginOperation( false );
  5448. if ( !b )
  5449. d->activeSheet->setSelectionAlignY( selectionInfo(), Format::UndefinedY );
  5450. else
  5451. d->activeSheet->setSelectionAlignY( selectionInfo(), Format::Bottom );
  5452. markSelectionAsDirty();
  5453. doc()->emitEndOperation();
  5454. }
  5455. }
  5456. void View::alignMiddle( bool b )
  5457. {
  5458. if ( d->toolbarLock )
  5459. return;
  5460. if ( d->activeSheet != 0L )
  5461. {
  5462. doc()->emitBeginOperation( false );
  5463. if ( !b )
  5464. d->activeSheet->setSelectionAlignY( selectionInfo(), Format::UndefinedY );
  5465. else
  5466. d->activeSheet->setSelectionAlignY( selectionInfo(), Format::Middle );
  5467. markSelectionAsDirty();
  5468. doc()->emitEndOperation();
  5469. }
  5470. }
  5471. void View::moneyFormat(bool b)
  5472. {
  5473. if ( d->toolbarLock )
  5474. return;
  5475. doc()->emitBeginOperation( false );
  5476. if ( d->activeSheet != 0L )
  5477. d->activeSheet->setSelectionMoneyFormat( selectionInfo(), b );
  5478. updateEditWidget();
  5479. markSelectionAsDirty();
  5480. doc()->emitEndOperation();
  5481. }
  5482. void View::createStyleFromCell()
  5483. {
  5484. if ( !d->activeSheet )
  5485. return;
  5486. TQPoint p( d->selection->selection().topLeft() );
  5487. Cell * cell = d->activeSheet->nonDefaultCell( p.x(), p.y() );
  5488. bool ok = false;
  5489. TQString styleName( "" );
  5490. while( true )
  5491. {
  5492. styleName = KInputDialog::getText( i18n( "Create Style From Cell" ),
  5493. i18n( "Enter name:" ), styleName, &ok, this );
  5494. if ( !ok ) // User pushed an OK button.
  5495. return;
  5496. styleName = styleName.stripWhiteSpace();
  5497. if ( styleName.length() < 1 )
  5498. {
  5499. KNotifyClient::beep();
  5500. KMessageBox::sorry( this, i18n( "The style name cannot be empty." ) );
  5501. continue;
  5502. }
  5503. if ( doc()->styleManager()->style( styleName ) != 0 )
  5504. {
  5505. KNotifyClient::beep();
  5506. KMessageBox::sorry( this, i18n( "A style with this name already exists." ) );
  5507. continue;
  5508. }
  5509. break;
  5510. }
  5511. CustomStyle * style = new CustomStyle( cell->format()->style(), styleName );
  5512. doc()->styleManager()->m_styles[ styleName ] = style;
  5513. cell->format()->setStyle( style );
  5514. TQStringList lst( d->actions->selectStyle->items() );
  5515. lst.push_back( styleName );
  5516. d->actions->selectStyle->setItems( lst );
  5517. }
  5518. void View::styleSelected( const TQString & style )
  5519. {
  5520. if (d->activeSheet )
  5521. {
  5522. Style * s = doc()->styleManager()->style( style );
  5523. if ( s )
  5524. {
  5525. doc()->emitBeginOperation(false);
  5526. d->activeSheet->setSelectionStyle( selectionInfo(), s );
  5527. markSelectionAsDirty();
  5528. doc()->emitEndOperation();
  5529. }
  5530. }
  5531. }
  5532. void View::precisionPlus()
  5533. {
  5534. setSelectionPrecision( 1 );
  5535. }
  5536. void View::precisionMinus()
  5537. {
  5538. setSelectionPrecision( -1 );
  5539. }
  5540. void View::setSelectionPrecision( int delta )
  5541. {
  5542. if ( d->activeSheet != NULL )
  5543. {
  5544. doc()->emitBeginOperation( false );
  5545. d->activeSheet->setSelectionPrecision( selectionInfo(), delta );
  5546. markSelectionAsDirty();
  5547. doc()->emitEndOperation();
  5548. }
  5549. }
  5550. void View::percent( bool b )
  5551. {
  5552. if ( d->toolbarLock )
  5553. return;
  5554. doc()->emitBeginOperation( false );
  5555. if ( d->activeSheet != 0L )
  5556. d->activeSheet->setSelectionPercent( selectionInfo() ,b );
  5557. updateEditWidget();
  5558. markSelectionAsDirty();
  5559. doc()->emitEndOperation();
  5560. }
  5561. void View::insertObject()
  5562. {
  5563. if (!activeSheet())
  5564. return;
  5565. doc()->emitBeginOperation( false );
  5566. KoDocumentEntry e = d->actions->insertPart->documentEntry();//KoPartSelectDia::selectPart( d->canvas );
  5567. if ( e.isEmpty() )
  5568. {
  5569. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5570. return;
  5571. }
  5572. //Don't start handles more than once
  5573. delete d->insertHandler;
  5574. d->insertHandler = new InsertPartHandler( this, d->canvas, e );
  5575. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5576. }
  5577. void View::insertChart()
  5578. {
  5579. if (!activeSheet())
  5580. return;
  5581. if ( d->selection->isColumnOrRowSelected() )
  5582. {
  5583. KMessageBox::error( this, i18n("Area too large."));
  5584. return;
  5585. }
  5586. TQValueList<KoDocumentEntry> vec = KoDocumentEntry::query( true, "'KOfficeChart' in ServiceTypes" );
  5587. if ( vec.isEmpty() )
  5588. {
  5589. KMessageBox::error( this, i18n("No charting component registered.") );
  5590. return;
  5591. }
  5592. //Don't start handles more than once
  5593. delete d->insertHandler;
  5594. doc()->emitBeginOperation( false );
  5595. d->insertHandler = new InsertChartHandler( this, d->canvas, vec[0] );
  5596. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5597. }
  5598. /*
  5599. // TODO Use KoView setScaling/xScaling/yScaling instead
  5600. void View::zoomMinus()
  5601. {
  5602. if ( m_fZoom <= 0.25 )
  5603. return;
  5604. m_fZoom -= 0.25;
  5605. if ( d->activeSheet != 0L )
  5606. d->activeSheet->setLayoutDirtyFlag();
  5607. d->canvas->repaint();
  5608. d->vBorderWidget->repaint();
  5609. d->hBorderWidget->repaint();
  5610. }
  5611. void View::zoomPlus()
  5612. {
  5613. if ( m_fZoom >= 3 )
  5614. return;
  5615. m_fZoom += 0.25;
  5616. if ( d->activeSheet != 0L )
  5617. d->activeSheet->setLayoutDirtyFlag();
  5618. d->canvas->repaint();
  5619. d->vBorderWidget->repaint();
  5620. d->hBorderWidget->repaint();
  5621. }
  5622. */
  5623. void View::removeSheet()
  5624. {
  5625. if ( doc()->map()->count() <= 1 || ( doc()->map()->visibleSheets().count() <= 1 ) )
  5626. {
  5627. KNotifyClient::beep();
  5628. KMessageBox::sorry( this, i18n("You cannot delete the only sheet."), i18n("Remove Sheet") ); // FIXME bad english? no english!
  5629. return;
  5630. }
  5631. KNotifyClient::beep();
  5632. int ret = KMessageBox::warningContinueCancel( this, i18n( "You are about to remove the active sheet.\nDo you want to continue?" ),
  5633. i18n( "Remove Sheet" ),KGuiItem(i18n("&Delete"),"edit-delete") );
  5634. if ( ret == KMessageBox::Continue )
  5635. {
  5636. doc()->emitBeginOperation( false );
  5637. if ( d->canvas->editor() )
  5638. {
  5639. d->canvas->deleteEditor( false );
  5640. }
  5641. doc()->setModified( true );
  5642. Sheet * tbl = activeSheet();
  5643. KCommand* command = new RemoveSheetCommand( tbl );
  5644. doc()->addCommand( command );
  5645. command->execute();
  5646. #if 0
  5647. UndoRemoveSheet * undo = new UndoRemoveSheet( doc(), tbl );
  5648. doc()->addCommand( undo );
  5649. tbl->doc()->map()->takeSheet( tbl );
  5650. doc()->takeSheet( tbl );
  5651. #endif
  5652. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5653. }
  5654. }
  5655. void View::slotRename()
  5656. {
  5657. Sheet * sheet = activeSheet();
  5658. if( sheet->isProtected() )
  5659. {
  5660. KMessageBox::error( 0, i18n ( "You cannot change a protected sheet." ) );
  5661. return;
  5662. }
  5663. bool ok;
  5664. TQString activeName = sheet->sheetName();
  5665. TQString newName = KInputDialog::getText( i18n("Rename Sheet"),i18n("Enter name:"), activeName, &ok, this );
  5666. if( !ok ) return;
  5667. while (!util_validateSheetName(newName))
  5668. {
  5669. KNotifyClient::beep();
  5670. KMessageBox::information( this, i18n("Sheet name contains illegal characters. Only numbers and letters are allowed."),
  5671. i18n("Change Sheet Name") );
  5672. newName = newName.simplifyWhiteSpace();
  5673. int n = newName.find('-');
  5674. if ( n > -1 ) newName[n] = '_';
  5675. n = newName.find('!');
  5676. if ( n > -1 ) newName[n] = '_';
  5677. n = newName.find('$');
  5678. if ( n > -1 ) newName[n] = '_';
  5679. newName = KInputDialog::getText( i18n("Rename Sheet"),i18n("Enter name:"), newName, &ok, this );
  5680. if ( !ok ) return;
  5681. }
  5682. if ( (newName.stripWhiteSpace()).isEmpty() ) // Sheet name is empty.
  5683. {
  5684. KNotifyClient::beep();
  5685. KMessageBox::information( this, i18n("Sheet name cannot be empty."), i18n("Change Sheet Name") );
  5686. // Recursion
  5687. slotRename();
  5688. }
  5689. else if ( newName != activeName ) // Sheet name changed.
  5690. {
  5691. // Is the name already used
  5692. if ( doc()->map()->findSheet( newName ) )
  5693. {
  5694. KNotifyClient::beep();
  5695. KMessageBox::information( this, i18n("This name is already used."), i18n("Change Sheet Name") );
  5696. // Recursion
  5697. slotRename();
  5698. return;
  5699. }
  5700. KCommand* command = new RenameSheetCommand( sheet, newName );
  5701. doc()->addCommand( command );
  5702. command->execute();
  5703. //sheet->setSheetName( newName );
  5704. doc()->emitBeginOperation(false);
  5705. updateEditWidget();
  5706. doc()->setModified( true );
  5707. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5708. }
  5709. }
  5710. void View::setText (const TQString & _text, bool array)
  5711. {
  5712. if ( d->activeSheet == 0L )
  5713. return;
  5714. if (array) {
  5715. // array version
  5716. d->activeSheet->setArrayFormula (d->selection, _text);
  5717. }
  5718. else
  5719. {
  5720. // non-array version
  5721. int x = d->canvas->markerColumn();
  5722. int y = d->canvas->markerRow();
  5723. d->activeSheet->setText( y, x, _text );
  5724. Cell * cell = d->activeSheet->cellAt( x, y );
  5725. if ( cell->value().isString() && !_text.isEmpty() && !_text.at(0).isDigit() && !cell->isFormula() )
  5726. doc()->addStringCompletion( _text );
  5727. }
  5728. }
  5729. //------------------------------------------------
  5730. //
  5731. // Document signals
  5732. //
  5733. //------------------------------------------------
  5734. void View::slotAddSheet( Sheet *_sheet )
  5735. {
  5736. addSheet( _sheet );
  5737. }
  5738. void View::slotRefreshView()
  5739. {
  5740. refreshView();
  5741. d->canvas->repaint();
  5742. d->vBorderWidget->repaint();
  5743. d->hBorderWidget->repaint();
  5744. }
  5745. void View::slotUpdateView( Sheet *_sheet )
  5746. {
  5747. // Do we display this sheet ?
  5748. if ( ( !activeSheet() ) || ( _sheet != d->activeSheet ) )
  5749. return;
  5750. d->activeSheet->setRegionPaintDirty( d->activeSheet->visibleRect( d->canvas ) );
  5751. doc()->emitEndOperation();
  5752. }
  5753. void View::slotUpdateView( Sheet * _sheet, const Region& region )
  5754. {
  5755. // tqDebug("void View::slotUpdateView( Sheet *_sheet, const TQRect& %i %i|%i %i )\n",_rect.left(),_rect.top(),_rect.right(),_rect.bottom());
  5756. // Do we display this sheet ?
  5757. if ( _sheet != d->activeSheet )
  5758. return;
  5759. // doc()->emitBeginOperation( false );
  5760. d->activeSheet->setRegionPaintDirty( region );
  5761. doc()->emitEndOperation( region );
  5762. }
  5763. void View::slotUpdateView( EmbeddedObject *obj )
  5764. {
  5765. d->canvas->repaintObject( obj );
  5766. }
  5767. void View::slotUpdateHBorder( Sheet * _sheet )
  5768. {
  5769. // kdDebug(36001)<<"void View::slotUpdateHBorder( Sheet *_sheet )\n";
  5770. // Do we display this sheet ?
  5771. if ( _sheet != d->activeSheet )
  5772. return;
  5773. doc()->emitBeginOperation(false);
  5774. d->hBorderWidget->update();
  5775. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5776. }
  5777. void View::slotUpdateVBorder( Sheet *_sheet )
  5778. {
  5779. // kdDebug("void View::slotUpdateVBorder( Sheet *_sheet )\n";
  5780. // Do we display this sheet ?
  5781. if ( _sheet != d->activeSheet )
  5782. return;
  5783. doc()->emitBeginOperation( false );
  5784. d->vBorderWidget->update();
  5785. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5786. }
  5787. void View::slotChangeSelection(const KSpread::Region& changedRegion)
  5788. {
  5789. // kdDebug() << *selectionInfo() << endl;
  5790. if (!changedRegion.isValid())
  5791. {
  5792. return;
  5793. }
  5794. doc()->emitBeginOperation( false );
  5795. bool colSelected = d->selection->isColumnSelected();
  5796. bool rowSelected = d->selection->isRowSelected();
  5797. if (d->activeSheet && !d->activeSheet->isProtected())
  5798. {
  5799. // Activate or deactivate some actions.
  5800. d->actions->insertRow->setEnabled( !colSelected );
  5801. d->actions->deleteRow->setEnabled( !colSelected );
  5802. d->actions->resizeRow->setEnabled( !colSelected );
  5803. d->actions->equalizeRow->setEnabled( !colSelected );
  5804. d->actions->hideRow->setEnabled( !colSelected );
  5805. d->actions->validity->setEnabled( !colSelected && !rowSelected);
  5806. d->actions->conditional->setEnabled( !colSelected && !rowSelected);
  5807. d->actions->insertColumn->setEnabled( !rowSelected );
  5808. d->actions->deleteColumn->setEnabled( !rowSelected );
  5809. d->actions->resizeColumn->setEnabled( !rowSelected );
  5810. d->actions->equalizeColumn->setEnabled( !rowSelected );
  5811. d->actions->hideColumn->setEnabled( !rowSelected );
  5812. d->actions->textToColumns->setEnabled( !rowSelected );
  5813. bool simpleSelection = d->selection->isSingular() || colSelected || rowSelected;
  5814. d->actions->autoFormat->setEnabled( !simpleSelection );
  5815. d->actions->sort->setEnabled( !simpleSelection );
  5816. d->actions->mergeCell->setEnabled( !simpleSelection );
  5817. d->actions->mergeCellHorizontal->setEnabled( !simpleSelection );
  5818. d->actions->mergeCellVertical->setEnabled( !simpleSelection );
  5819. d->actions->fillRight->setEnabled( !simpleSelection );
  5820. d->actions->fillUp->setEnabled( !simpleSelection );
  5821. d->actions->fillDown->setEnabled( !simpleSelection );
  5822. d->actions->fillLeft->setEnabled( !simpleSelection );
  5823. d->actions->sortDec->setEnabled( !simpleSelection );
  5824. d->actions->sortInc->setEnabled( !simpleSelection);
  5825. d->actions->createStyle->setEnabled( simpleSelection ); // just from one cell
  5826. bool contiguousSelection = d->selection->isContiguous();
  5827. d->actions->subTotals->setEnabled(contiguousSelection);
  5828. }
  5829. d->actions->selectStyle->setCurrentItem( -1 );
  5830. // delayed recalculation of the operation shown in the status bar
  5831. d->statusBarOpTimer.start(250, true);
  5832. // Send some event around. This is read for example
  5833. // by the calculator plugin.
  5834. // SelectionChanged ev(*selectionInfo(), activeSheet()->name());
  5835. // TQApplication::sendEvent( this, &ev );
  5836. d->canvas->setSelectionChangePaintDirty( d->activeSheet, changedRegion );
  5837. d->vBorderWidget->update();
  5838. d->hBorderWidget->update();
  5839. if (colSelected || rowSelected)
  5840. {
  5841. doc()->emitEndOperation(/* *selectionInfo() */);
  5842. return;
  5843. }
  5844. d->canvas->validateSelection();
  5845. //Don't scroll to the marker if there is an active embedded object, since this may cause
  5846. //the canvas to scroll so that the object isn't in the visible area.
  5847. //There is still the problem of the object no longer being visible immediately after deactivating the child
  5848. //as the sheet jumps back to the marker though.
  5849. if (!activeChild())
  5850. d->canvas->scrollToCell(selectionInfo()->marker());
  5851. // Perhaps the user is entering a value in the cell.
  5852. // In this case we may not touch the EditWidget
  5853. if ( !d->canvas->editor() && !d->canvas->chooseMode() )
  5854. {
  5855. updateEditWidgetOnPress();
  5856. }
  5857. d->canvas->updatePosWidget();
  5858. doc()->emitEndOperation(/* *selectionInfo() */);
  5859. }
  5860. void View::slotChangeChoice(const KSpread::Region& changedRegion)
  5861. {
  5862. if (!changedRegion.isValid())
  5863. {
  5864. return;
  5865. }
  5866. doc()->emitBeginOperation( false );
  5867. d->canvas->updateEditor();
  5868. d->canvas->setSelectionChangePaintDirty( d->activeSheet, changedRegion );
  5869. doc()->emitEndOperation( *choice() );
  5870. kdDebug() << "Choice: " << *choice() << endl;
  5871. }
  5872. void View::slotScrollChoice( const KSpread::Region& changedRegion )
  5873. {
  5874. if ( !changedRegion.isValid() )
  5875. return;
  5876. d->canvas->scrollToCell( choice()->marker() );
  5877. }
  5878. void View::calcStatusBarOp()
  5879. {
  5880. Sheet * sheet = activeSheet();
  5881. ValueCalc* calc = d->doc->calc();
  5882. Value val;
  5883. TQRect tmpRect(d->selection->selection());
  5884. MethodOfCalc tmpMethod = doc()->getTypeOfCalc();
  5885. if ( tmpMethod != NoneCalc )
  5886. {
  5887. Value range = sheet->valueRange (tmpRect.left(), tmpRect.top(),
  5888. tmpRect.right(), tmpRect.bottom());
  5889. switch (tmpMethod)
  5890. {
  5891. case SumOfNumber:
  5892. val = calc->sum (range);
  5893. break;
  5894. case Average:
  5895. val = calc->avg (range);
  5896. break;
  5897. case Min:
  5898. val = calc->min (range);
  5899. break;
  5900. case Max:
  5901. val = calc->max (range);
  5902. break;
  5903. case CountA:
  5904. val = Value (calc->count (range));
  5905. break;
  5906. case Count:
  5907. val = Value (calc->count (range, false));
  5908. case NoneCalc:
  5909. break;
  5910. default:
  5911. break;
  5912. }
  5913. }
  5914. TQString res = d->doc->converter()->asString (val).asString ();
  5915. TQString tmp;
  5916. switch(tmpMethod )
  5917. {
  5918. case SumOfNumber:
  5919. tmp = i18n("Sum: ") + res;
  5920. break;
  5921. case Average:
  5922. tmp = i18n("Average: ") + res;
  5923. break;
  5924. case Min:
  5925. tmp = i18n("Min: ") + res;
  5926. break;
  5927. case Max:
  5928. tmp = i18n("Max: ") + res;
  5929. break;
  5930. case Count:
  5931. tmp = i18n("Count: ") + res;
  5932. break;
  5933. case CountA:
  5934. tmp = i18n("CountA: ") + res;
  5935. break;
  5936. case NoneCalc:
  5937. tmp = "";
  5938. break;
  5939. }
  5940. //doc()->emitBeginOperation();
  5941. if ( d->calcLabel )
  5942. d->calcLabel->setText(TQString(" ") + tmp + ' ');
  5943. //doc()->emitEndOperation();
  5944. }
  5945. void View::statusBarClicked(int _id)
  5946. {
  5947. if ( !koDocument()->isReadWrite() || !factory() )
  5948. return;
  5949. if ( _id == 0 ) //menu calc
  5950. {
  5951. TQPoint mousepos = TQCursor::pos();
  5952. ((TQPopupMenu*)factory()->container( "calc_popup" , this ) )->popup( mousepos );
  5953. }
  5954. }
  5955. void View::menuCalc( bool )
  5956. {
  5957. doc()->emitBeginOperation(false);
  5958. if ( d->actions->calcMin->isChecked() )
  5959. {
  5960. doc()->setTypeOfCalc( Min );
  5961. }
  5962. else if ( d->actions->calcMax->isChecked() )
  5963. {
  5964. doc()->setTypeOfCalc( Max );
  5965. }
  5966. else if ( d->actions->calcCount->isChecked() )
  5967. {
  5968. doc()->setTypeOfCalc( Count );
  5969. }
  5970. else if ( d->actions->calcAverage->isChecked() )
  5971. {
  5972. doc()->setTypeOfCalc( Average );
  5973. }
  5974. else if ( d->actions->calcSum->isChecked() )
  5975. {
  5976. doc()->setTypeOfCalc( SumOfNumber );
  5977. }
  5978. else if ( d->actions->calcCountA->isChecked() )
  5979. {
  5980. doc()->setTypeOfCalc( CountA );
  5981. }
  5982. else if ( d->actions->calcNone->isChecked() )
  5983. doc()->setTypeOfCalc( NoneCalc );
  5984. calcStatusBarOp();
  5985. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  5986. }
  5987. TQWMatrix View::matrix() const
  5988. {
  5989. TQWMatrix m;
  5990. m.scale( d->doc->zoomedResolutionX(),
  5991. d->doc->zoomedResolutionY() );
  5992. m.translate( - d->canvas->xOffset(), - d->canvas->yOffset() );
  5993. return m;
  5994. }
  5995. void View::transformPart()
  5996. {
  5997. Q_ASSERT( selectedChild() );
  5998. if ( d->transformToolBox.isNull() )
  5999. {
  6000. d->transformToolBox = new KoTransformToolBox( selectedChild(), topLevelWidget() );
  6001. d->transformToolBox->show();
  6002. d->transformToolBox->setDocumentChild( selectedChild() );
  6003. }
  6004. else
  6005. {
  6006. d->transformToolBox->show();
  6007. d->transformToolBox->raise();
  6008. }
  6009. }
  6010. void View::slotChildSelected( KoDocumentChild* /*ch*/ )
  6011. {
  6012. // if ( d->activeSheet && !d->activeSheet->isProtected() )
  6013. // {
  6014. // d->actions->transform->setEnabled( true );
  6015. //
  6016. // if ( !d->transformToolBox.isNull() )
  6017. // {
  6018. // d->transformToolBox->setEnabled( true );
  6019. // d->transformToolBox->setDocumentChild( ch );
  6020. // }
  6021. // }
  6022. doc()->emitBeginOperation( false );
  6023. d->activeSheet->setRegionPaintDirty(TQRect(TQPoint(0,0), TQPoint(KS_colMax, KS_rowMax)));
  6024. doc()->emitEndOperation();
  6025. paintUpdates();
  6026. }
  6027. void View::slotChildUnselected( KoDocumentChild* )
  6028. {
  6029. // if ( d->activeSheet && !d->activeSheet->isProtected() )
  6030. // {
  6031. // d->actions->transform->setEnabled( false );
  6032. //
  6033. // if ( !d->transformToolBox.isNull() )
  6034. // {
  6035. // d->transformToolBox->setEnabled( false );
  6036. // }
  6037. // deleteEditor( true );
  6038. // }
  6039. doc()->emitBeginOperation( false );
  6040. d->activeSheet->setRegionPaintDirty(TQRect(TQPoint(0,0), TQPoint(KS_colMax, KS_rowMax)));
  6041. doc()->emitEndOperation();
  6042. paintUpdates();
  6043. }
  6044. void View::deleteEditor( bool saveChanges )
  6045. {
  6046. doc()->emitBeginOperation( false );
  6047. d->canvas->deleteEditor( saveChanges );
  6048. markSelectionAsDirty();
  6049. doc()->emitEndOperation();
  6050. }
  6051. DCOPObject * View::dcopObject()
  6052. {
  6053. if ( !d->dcop )
  6054. d->dcop = new ViewIface( this );
  6055. return d->dcop;
  6056. }
  6057. TQWidget * View::canvas() const
  6058. {
  6059. return canvasWidget();
  6060. }
  6061. int View::canvasXOffset() const
  6062. {
  6063. if (!d->activeSheet)
  6064. return 0;
  6065. double zoomedResX = d->activeSheet->doc()->zoomedResolutionX();
  6066. return int( canvasWidget()->xOffset() * zoomedResX );
  6067. }
  6068. int View::canvasYOffset() const
  6069. {
  6070. if (!d->activeSheet)
  6071. return 0;
  6072. double zoomedResY = d->activeSheet->doc()->zoomedResolutionY();
  6073. return int( canvasWidget()->yOffset() * zoomedResY );
  6074. }
  6075. void View::guiActivateEvent( KParts::GUIActivateEvent *ev )
  6076. {
  6077. if ( d->activeSheet )
  6078. {
  6079. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  6080. if ( ev->activated() )
  6081. {
  6082. if ( d->calcLabel )
  6083. calcStatusBarOp();
  6084. }
  6085. else
  6086. {
  6087. /*if (d->calcLabel)
  6088. {
  6089. disconnect(d->calcLabel,TQT_SIGNAL(pressed( int )),this,TQT_SLOT(statusBarClicked(int)));
  6090. }*/
  6091. }
  6092. }
  6093. KoView::guiActivateEvent( ev );
  6094. }
  6095. void View::popupTabBarMenu( const TQPoint & _point )
  6096. {
  6097. if ( !koDocument()->isReadWrite() || !factory() )
  6098. return;
  6099. if ( d->tabBar )
  6100. {
  6101. bool state = ( doc()->map()->visibleSheets().count() > 1 );
  6102. if ( d->activeSheet && d->activeSheet->isProtected() )
  6103. {
  6104. d->actions->removeSheet->setEnabled( false );
  6105. d->actions->hideSheet->setEnabled( false );
  6106. d->actions->showSheet->setEnabled( false );
  6107. }
  6108. else
  6109. {
  6110. d->actions->removeSheet->setEnabled( state);
  6111. d->actions->hideSheet->setEnabled( state );
  6112. d->actions->showSheet->setEnabled( doc()->map()->hiddenSheets().count()>0 );
  6113. }
  6114. if ( !doc() || !doc()->map() || doc()->map()->isProtected() )
  6115. {
  6116. d->actions->insertSheet->setEnabled( false );
  6117. d->actions->renameSheet->setEnabled( false );
  6118. d->actions->showSheet->setEnabled( false );
  6119. d->actions->hideSheet->setEnabled( false );
  6120. d->actions->removeSheet->setEnabled( false );
  6121. }
  6122. static_cast<TQPopupMenu*>(factory()->container("menupage_popup",this))->popup(_point);
  6123. }
  6124. }
  6125. void View::updateBorderButton()
  6126. {
  6127. // doc()->emitBeginOperation( false );
  6128. if ( d->activeSheet )
  6129. d->actions->showPageBorders->setChecked( d->activeSheet->isShowPageBorders() );
  6130. // doc()->emitEndOperation();
  6131. }
  6132. void View::removeSheet( Sheet *_t )
  6133. {
  6134. doc()->emitBeginOperation(false);
  6135. TQString m_tablName=_t->sheetName();
  6136. d->tabBar->removeTab( m_tablName );
  6137. setActiveSheet( doc()->map()->findSheet( doc()->map()->visibleSheets().first() ));
  6138. bool state = doc()->map()->visibleSheets().count() > 1;
  6139. d->actions->removeSheet->setEnabled( state );
  6140. d->actions->hideSheet->setEnabled( state );
  6141. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  6142. }
  6143. void View::insertSheet( Sheet* sheet )
  6144. {
  6145. doc()->emitBeginOperation( false );
  6146. TQString tabName = sheet->sheetName();
  6147. if ( !sheet->isHidden() )
  6148. {
  6149. d->tabBar->addTab( tabName );
  6150. }
  6151. bool state = ( doc()->map()->visibleSheets().count() > 1 );
  6152. d->actions->removeSheet->setEnabled( state );
  6153. d->actions->hideSheet->setEnabled( state );
  6154. doc()->emitEndOperation( sheet->visibleRect( d->canvas ) );
  6155. }
  6156. TQColor View::borderColor() const
  6157. {
  6158. return d->actions->borderColor->color();
  6159. }
  6160. void View::updateShowSheetMenu()
  6161. {
  6162. doc()->emitBeginOperation( false );
  6163. if ( d->activeSheet->isProtected() )
  6164. d->actions->showSheet->setEnabled( false );
  6165. else
  6166. d->actions->showSheet->setEnabled( doc()->map()->hiddenSheets().count() > 0 );
  6167. doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
  6168. }
  6169. void View::closeEditor()
  6170. {
  6171. if ( d->activeSheet ) { // #45822
  6172. doc()->emitBeginOperation( false );
  6173. d->canvas->closeEditor();
  6174. markSelectionAsDirty();
  6175. doc()->emitEndOperation();
  6176. }
  6177. }
  6178. void View::markSelectionAsDirty()
  6179. {
  6180. if (!d->activeSheet)
  6181. return;
  6182. d->activeSheet->setRegionPaintDirty( *selectionInfo() );
  6183. }
  6184. void View::paintUpdates()
  6185. {
  6186. /* don't do any begin/end operation here -- this is what is called at an
  6187. endOperation
  6188. */
  6189. d->canvas->paintUpdates();
  6190. }
  6191. void View::commandExecuted()
  6192. {
  6193. updateEditWidget();
  6194. calcStatusBarOp();
  6195. }
  6196. void View::initialiseMarkerFromSheet( Sheet *_sheet, const TQPoint &point )
  6197. {
  6198. d->savedMarkers.replace( _sheet, point);
  6199. }
  6200. TQPoint View::markerFromSheet( Sheet* sheet ) const
  6201. {
  6202. TQMapIterator<Sheet*, TQPoint> it = d->savedMarkers.find(sheet);
  6203. TQPoint newMarker = (it == d->savedMarkers.end()) ? TQPoint(1,1) : *it;
  6204. return newMarker;
  6205. }
  6206. KoPoint View::offsetFromSheet( Sheet* sheet ) const
  6207. {
  6208. TQMapIterator<Sheet*, KoPoint> it = d->savedOffsets.find(sheet);
  6209. KoPoint offset = (it == d->savedOffsets.end()) ? KoPoint() : *it;
  6210. return offset;
  6211. }
  6212. void View::saveCurrentSheetSelection()
  6213. {
  6214. /* save the current selection on this sheet */
  6215. if (d->activeSheet != NULL)
  6216. {
  6217. d->savedAnchors.replace(d->activeSheet, d->selection->anchor());
  6218. kdDebug() << " Current scrollbar vert value: " << d->canvas->vertScrollBar()->value() << endl;
  6219. kdDebug() << "Saving marker pos: " << d->selection->marker() << endl;
  6220. d->savedMarkers.replace(d->activeSheet, d->selection->marker());
  6221. d->savedOffsets.replace(d->activeSheet, KoPoint(d->canvas->xOffset(),
  6222. d->canvas->yOffset()));
  6223. }
  6224. }
  6225. void View::handleDamages( const TQValueList<Damage*>& damages )
  6226. {
  6227. TQValueList<Damage*>::ConstIterator it;
  6228. for( it = damages.begin(); it != damages.end(); ++it )
  6229. {
  6230. Damage* damage = *it;
  6231. if( !damage ) continue;
  6232. if( damage->type() == Damage::Cell )
  6233. {
  6234. CellDamage* cd = static_cast<CellDamage*>( damage );
  6235. Cell* damagedCell = cd->cell();
  6236. Sheet* damagedSheet = damagedCell->sheet();
  6237. TQRect drect( damagedCell->column(), damagedCell->row(), 1, 1 );
  6238. damagedSheet->setRegionPaintDirty( drect );
  6239. paintUpdates();
  6240. }
  6241. if( damage->type() == Damage::Sheet )
  6242. {
  6243. SheetDamage* sd = static_cast<SheetDamage*>( damage );
  6244. Sheet* damagedSheet = sd->sheet();
  6245. if( sd->action() == SheetDamage::PropertiesChanged )
  6246. {
  6247. CellBinding * b = 0;
  6248. for ( b = damagedSheet->firstCellBinding(); b != 0;
  6249. b = damagedSheet->nextCellBinding() )
  6250. b->cellChanged( 0 );
  6251. d->activeSheet->setRegionPaintDirty( TQRect(TQPoint(0,0),
  6252. TQPoint(KS_colMax, KS_rowMax)));
  6253. paintUpdates();
  6254. refreshView();
  6255. }
  6256. }
  6257. }
  6258. }
  6259. void View::runInternalTests()
  6260. {
  6261. // run various tests, only for developers
  6262. KSpread::TestRunner* runner = new KSpread::TestRunner();
  6263. runner->exec();
  6264. delete runner;
  6265. }
  6266. void View::runInspector()
  6267. {
  6268. // useful to inspect objects
  6269. if(!d->activeSheet) return;
  6270. Cell * cell = d->activeSheet->cellAt( d->selection->marker() );
  6271. KSpread::Inspector* ins = new KSpread::Inspector( cell );
  6272. ins->exec();
  6273. delete ins;
  6274. }
  6275. TQColor View::highlightColor()
  6276. {
  6277. return TQApplication::palette().active().highlight().light( 175 );
  6278. }
  6279. } // namespace KSpread
  6280. #include "kspread_view.moc"