kspread

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