kword

KWView.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2001 David Faure <faure@kde.org>
4 Copyright (C) 2005 Thomas Zander <zander@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA
20*/
21
22#undef Unsorted
23
24#include "KWView.h"
25
26#include "KWordViewIface.h"
27#include "KWConfigFootNoteDia.h"
28#include "defs.h"
29#include "KWDeleteDia.h"
30#include "KWDocStruct.h"
31#include "KWFootNoteDia.h"
32#include "KWInsertDia.h"
33#include "KWAnchor.h"
34#include "KoTextBookmark.h"
35#include "KWCanvas.h"
36#include "KWCommand.h"
37#include "KWConfig.h"
38#include "KWCreateBookmarkDia.h"
39#include "KWDocument.h"
40#include "KWEditPersonnalExpression.h"
41#include "KWFormulaFrameSet.h"
42#include "KWFrame.h"
43#include "KWPictureFrameSet.h"
44#include "KWFrameStyle.h"
45#include "KWFrameStyleManager.h"
46#include "KWImportStyleDia.h"
47#include "KWInsertPageDia.h"
48#include "KWInsertPicDia.h"
49#include "KWPartFrameSet.h"
50#include "KWStyleManager.h"
51#include "KWTableFrameSet.h"
52#include "KWTableStyle.h"
53#include "KWTableStyleManager.h"
54#include "KWTextDocument.h"
55#include "KWVariable.h"
56#include "KWViewMode.h"
57#include "KWMailMergeDataBase.h"
58#include "KWMailMergeLabelAction.h"
59#include "KWResizeTableDia.h"
60#include "KWFindReplace.h"
61#include "KWSortDia.h"
62#include "KWSplitCellDia.h"
63#include "KWTableDia.h"
64#include "KWCollectFramesetsVisitor.h"
65#include "KWOasisLoader.h"
66#include "KWOasisSaver.h"
67#include "KWFrameList.h"
68#include "KWPageManager.h"
69#include "KWPage.h"
70#include "KWFrameViewManager.h"
71#include "KWFrameView.h"
72#include "KWStatisticsDialog.h"
73
74#include <kformuladocument.h>
75#include <kformulamimesource.h>
76
77#include <KoRichText.h>
78#include <KoAutoFormat.h>
79#include <KoAutoFormatDia.h>
80#include <KoChangeCaseDia.h>
81#include <KoCharSelectDia.h>
82#include <KoCommentDia.h>
83#include <KoCreateStyleDia.h>
84#include <KoDocumentInfo.h>
85#include <KoFontDia.h>
86#include <KoFrame.h>
87#include <KoInsertLink.h>
88#include <KoMainWindow.h>
89#include <KoParagDia.h>
90#include <KoPartSelectAction.h>
91#include <KoPictureFilePreview.h>
92#include <KoSearchDia.h>
93#include <KoStore.h>
94#include <KoStoreDrag.h>
95#include <KoTemplateCreateDia.h>
96#include <KoCompletionDia.h>
97#include <KoVariable.h>
98#include <KoCustomVariablesDia.h>
99#include <KoTextObject.h>
100#include <tkcoloractions.h>
101#include <KoSpeaker.h>
102
103#include <tdeparts/partmanager.h>
104#include <tdeaccelgen.h>
105#include <kcolordialog.h>
106#include <kdebug.h>
107#include <tdefiledialog.h>
108#include <kimageio.h>
109#include <kinputdialog.h>
110#include <tdeio/netaccess.h>
111#include <tdemessagebox.h>
112#include <tdeparts/event.h>
113#include <kstandarddirs.h>
114#include <kstatusbar.h>
115#include <tdestdaccel.h>
116#include <kstdaction.h>
117#include <tdetempfile.h>
118#include <kurldrag.h>
119#include <tdeversion.h>
120#include <kiconloader.h>
121
122#include <tqclipboard.h>
123#include <tqapplication.h>
124#include <tqgroupbox.h>
125#include <tqlayout.h>
126#include <tqpaintdevicemetrics.h>
127#include <tqprogressdialog.h>
128#include <tqregexp.h>
129#include <tqtimer.h>
130#include <tqbuffer.h>
131
132#include <stdlib.h>
133
134#include <tdespell2/dialog.h>
135#include <tdespell2/defaultdictionary.h>
136#include "KoSpell.h"
137
138using namespace KSpell2;
139
140/******************************************************************/
141/* Class: TableInfo */
142/******************************************************************/
143class TableInfo {
144 public:
145 TableInfo( const TQValueList<KWFrameView*>& selectedFrames ) {
146 m_protectContent = false;
147 //m_views = selectedFrames;
148 int amountSelected = 0;
149 m_cell = 0;
150 TQMap<KWTableFrameSet*, TQValueList<unsigned int> > tableRows, tableCols;
151
152 TQValueList<KWFrameView*>::const_iterator framesIterator = selectedFrames.begin();
153 for(;framesIterator != selectedFrames.end(); ++framesIterator) {
154 KWFrameView *view = *framesIterator;
155 if(!view->selected()) continue;
156 KWFrameSet *fs = view->frame()->frameSet();
157 Q_ASSERT(fs);
158 KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell*>(fs);
159 if(cell == 0) continue;
160 amountSelected++;
161 if(cell->protectContent())
162 m_protectContent=true;
163
164 if(! tableRows.contains(fs->groupmanager())) { // create empty lists.
165 TQValueList<unsigned int> rows;
166 for(unsigned int i=fs->groupmanager()->getRows(); i != 0; i--)
167 rows.append(0);
168 tableRows.insert(fs->groupmanager(), rows);
169 TQValueList<unsigned int> cols;
170 for(unsigned int i=fs->groupmanager()->getColumns(); i != 0; i--)
171 cols.append(0);
172 tableCols.insert(fs->groupmanager(), cols);
173 }
174 TQValueList<unsigned int> rows = tableRows[fs->groupmanager()];
175 for(unsigned int r=cell->firstRow(); r <= cell->lastRow(); r++)
176 rows[r] = rows[r] + 1;
177 tableRows[fs->groupmanager()] = rows;
178 TQValueList<unsigned int> columns = tableCols[fs->groupmanager()];
179 for(unsigned int c=cell->firstColumn(); c <= cell->lastColumn(); c++)
180 columns[c] = columns[c] + 1;
181 tableCols[fs->groupmanager()] = columns;
182
183 if(m_cell == 0 || m_cell->firstRow() > cell->firstRow() ||
184 m_cell->firstRow() == cell->firstRow() &&
185 m_cell->firstColumn() > cell->firstColumn())
186 m_cell = cell;
187 }
188
189 m_selected = amountSelected != 0;
190 m_oneCellSelected = amountSelected == 1;
191 if(amountSelected == 0) return;
192
193 for(TQMapIterator<KWTableFrameSet*, TQValueList<unsigned int> > iter = tableRows.begin();
194 iter != tableRows.end(); ++iter) {
195 TQValueList<unsigned int> rows = iter.data();
196 TQValueListIterator<unsigned int> rowsIter = rows.begin();
197 for(int x=0;rowsIter != rows.end(); ++rowsIter, x++)
198 if(*rowsIter == iter.key()->getColumns())
199 m_rows.append(x);
200
201 TQValueList<unsigned int> columns = tableCols[iter.key()];
202 TQValueListIterator<unsigned int> colsIter = columns.begin();
203 for(int x=0;colsIter != columns.end(); ++colsIter, x++)
204 if(*colsIter == iter.key()->getRows())
205 m_columns.append(x);
206 }
207 }
208
209 int tableCellsSelected() { return m_selected; }
210 int amountRowsSelected() { return m_rows.count(); }
211 int amountColumnsSelected() { return m_columns.count(); }
212 bool oneCellSelected() { return m_oneCellSelected; }
213 bool protectContentEnabled() { return m_protectContent; }
214 TQValueList<uint> selectedRows() { return m_rows; }
215 TQValueList<uint> selectedColumns() { return m_columns; }
216 KWTableFrameSet::Cell *firstSelectedCell() { return m_cell; }
217 private:
218 //TQValueList<KWFrameView*> m_views;
219 bool m_oneCellSelected, m_selected, m_protectContent;
220 TQValueList<uint> m_rows, m_columns;
221 KWTableFrameSet::Cell *m_cell;
222};
223
224/******************************************************************/
225/* Class: KWView */
226/******************************************************************/
227KWView::KWView( const TQString& viewMode, TQWidget *parent, const char *name, KWDocument* doc )
228 : KoView( doc, parent, name )
229{
230 m_doc = doc;
231 m_gui = 0;
232
233 m_dcop = 0;
234 dcopObject(); // build it
235 m_fsInline=0;
236 m_spell.kospell = 0;
237 m_spell.dlg = 0;
238 m_broker = Broker::openBroker( TDESharedConfig::openConfig( "kwordrc" ) );
239 m_spell.macroCmdSpellCheck=0L;
240 m_spell.textIterator = 0L;
241 m_currentPage = m_doc->pageManager()->page(m_doc->startPage());
242 m_specialCharDlg=0L;
243 m_searchEntry = 0L;
244 m_replaceEntry = 0L;
245 m_findReplace = 0L;
246 m_fontDlg = 0L;
247 m_paragDlg = 0L;
248 m_tableSplit.columns = 1;
249 m_tableSplit.rows = 1;
250
251 m_actionList.setAutoDelete( true );
252 m_variableActionList.setAutoDelete( true );
253 // Default values.
254 m_zoomViewModeNormal.m_zoom = m_doc->zoom();
255 m_zoomViewModeNormal.m_zoomMode = m_doc->zoomMode();
256 m_zoomViewModePreview.m_zoom = 33; // TODO: bad to leave hardcoded...
257 m_zoomViewModePreview.m_zoomMode = KoZoomMode::ZOOM_CONSTANT;
258
259 m_viewFrameBorders = m_doc->viewFrameBorders();
260 KoView::setZoom( m_doc->zoomedResolutionY() /* KoView only supports one zoom */ ); // initial value
261 //m_viewTableGrid = true;
262
263 setInstance( KWFactory::instance() );
264 if ( !m_doc->isReadWrite() )
265 setXMLFile( "kword_readonly.rc" );
266 else
267 setXMLFile( "kword.rc" );
268
269
270 TQObject::connect( this, TQ_SIGNAL( embeddImage( const TQString & ) ),
271 this, TQ_SLOT( slotEmbedImage( const TQString & ) ) );
272
273 setKeyCompression( true );
274 setAcceptDrops( true );
275
276 setupActions();
277
278 m_gui = new KWGUI( viewMode, this, this );
279 m_gui->setGeometry( 0, 0, width(), height() );
280 m_gui->show();
281
282 m_sbPageLabel = 0;
283 m_sbModifiedLabel = 0;
284 m_sbFramesLabel = 0;
285 m_sbOverwriteLabel = 0;
286 m_sbZoomLabel = 0;
287 m_sbUnitLabel = 0;
288 if ( KStatusBar* sb = statusBar() ) // No statusbar in e.g. konqueror
289 {
290 m_sbPageLabel = new KStatusBarLabel( TQString(), 0, sb );
291 m_sbPageLabel->setAlignment( AlignLeft | AlignVCenter );
292 addStatusBarItem( m_sbPageLabel, 0 );
293
294 m_sbModifiedLabel = new KStatusBarLabel( " ", 0, sb );
295 m_sbModifiedLabel->setAlignment( AlignLeft | AlignVCenter );
296 addStatusBarItem( m_sbModifiedLabel, 0 );
297
298 m_sbFramesLabel = new KStatusBarLabel( TQString(), 0, sb );
299 m_sbFramesLabel->setAlignment( AlignLeft | AlignVCenter );
300 addStatusBarItem( m_sbFramesLabel, 1 );
301
302 m_sbOverwriteLabel = new KStatusBarLabel( ' ' + i18n( "INSRT" ) + ' ', 0, sb );
303 m_sbOverwriteLabel->setAlignment( AlignHCenter | AlignVCenter );
304 addStatusBarItem( m_sbOverwriteLabel, 0 );
305
306 m_sbZoomLabel = new KStatusBarLabel( ' ' + TQString::number( m_doc->zoom() ) + "% ", 0, sb );
307 m_sbZoomLabel->setAlignment( AlignHCenter | AlignVCenter );
308 addStatusBarItem( m_sbZoomLabel, 0 );
309
310 m_sbUnitLabel = new KStatusBarLabel( ' ' + KoUnit::unitDescription( m_doc->unit() ) + ' ', 0, sb );
311 m_sbUnitLabel->setAlignment( AlignHCenter | AlignVCenter );
312 addStatusBarItem( m_sbUnitLabel, 0 );
313 }
314
315 connect( m_doc, TQ_SIGNAL( modified( bool ) ),
316 this, TQ_SLOT( documentModified( bool )) );
317
318 connect( m_doc, TQ_SIGNAL( numPagesChanged() ),
319 this, TQ_SLOT( numPagesChanged()) );
320
321 connect( m_doc, TQ_SIGNAL( pageLayoutChanged( const KoPageLayout& ) ),
322 this, TQ_SLOT( slotPageLayoutChanged( const KoPageLayout& )) );
323
324 connect( m_doc, TQ_SIGNAL( docStructureChanged(int) ),
325 this, TQ_SLOT( docStructChanged(int)) );
326
327 connect( m_doc, TQ_SIGNAL( unitChanged(KoUnit::Unit) ),
328 this, TQ_SLOT( slotUnitChanged(KoUnit::Unit) ) );
329
330 connect( m_doc, TQ_SIGNAL( sig_refreshMenuCustomVariable()),
331 this, TQ_SLOT( refreshCustomMenu()));
332
333 connect( m_doc, TQ_SIGNAL( completed() ),
334 this, TQ_SLOT( slotDocumentLoadingCompleted() ) );
335
336 connect( frameViewManager(), TQ_SIGNAL(sigFrameSelectionChanged()),
337 this, TQ_SLOT( frameSelectedChanged()));
338
339 connect( frameViewManager(), TQ_SIGNAL(sigFrameSetRenamed()),
340 this, TQ_SLOT( updateFrameStatusBarItem()));
341
342 connect( TQApplication::clipboard(), TQ_SIGNAL( dataChanged() ),
343 this, TQ_SLOT( clipboardDataChanged() ) );
344
345 connect( m_gui->canvasWidget(), TQ_SIGNAL(currentFrameSetEditChanged()),
346 this, TQ_SLOT(slotFrameSetEditChanged()) );
347
348 connect( m_gui->canvasWidget(), TQ_SIGNAL( currentMouseModeChanged(int) ),
349 this, TQ_SLOT( showMouseMode(int) ) );
350
351 connect( m_gui->canvasWidget(), TQ_SIGNAL( overwriteModeChanged( bool ) ),
352 this, TQ_SLOT( changeOverwriteMode( bool ) ) );
353
354 // Cut and copy are directly connected to the selectionChanged signal
355 if ( m_doc->isReadWrite() )
356 {
357 connect( m_gui->canvasWidget(), TQ_SIGNAL(selectionChanged(bool)),
358 this, TQ_SLOT(slotChangeCutState(bool )) );
359 connect (m_gui->canvasWidget(), TQ_SIGNAL(selectionChanged(bool)),
360 this, TQ_SLOT(slotChangeCaseState(bool )));
361 }
362 else
363 {
364 m_actionEditCut->setEnabled( false );
365 m_actionChangeCase->setEnabled( false );
366 }
367
368 connect( m_gui->canvasWidget(), TQ_SIGNAL(selectionChanged(bool)),
369 m_actionEditCopy, TQ_SLOT(setEnabled(bool)) );
370
371 //connect (m_gui->canvasWidget(), TQ_SIGNAL(selectionChanged(bool)),
372 // m_actionCreateStyleFromSelection, TQ_SLOT(setEnabled(bool)));
373
374 connect (m_gui->canvasWidget(), TQ_SIGNAL(selectionChanged(bool)),
375 m_actionConvertToTextBox, TQ_SLOT(setEnabled(bool)));
376 connect (m_gui->canvasWidget(), TQ_SIGNAL(selectionChanged(bool)),
377 m_actionAddPersonalExpression, TQ_SLOT(setEnabled(bool )));
378 connect (m_gui->canvasWidget(), TQ_SIGNAL(selectionChanged(bool)),
379 m_actionSortText, TQ_SLOT(setEnabled(bool )));
380
381 connect( m_gui->canvasWidget(), TQ_SIGNAL(docStructChanged(int)),
382 this, TQ_SLOT(docStructChanged(int)));
383
384 connect( m_gui->canvasWidget(), TQ_SIGNAL(updateRuler()),
385 this, TQ_SLOT(slotUpdateRuler()));
386
387 if ( shell() )
388 {
389 connect( shell(), TQ_SIGNAL( documentSaved()), m_doc,TQ_SLOT(slotDocumentInfoModifed() ) );
390 changeNbOfRecentFiles( m_doc->maxRecentFiles() );
391 }
392
393 m_gui->canvasWidget()->updateCurrentFormat();
394 setFocusProxy( m_gui->canvasWidget() );
395
396 //when kword is embedded into konqueror apply a zoom=100
397 //in konqueror we can't change zoom -- ### TODO ?
398 if(!m_doc->isReadWrite())
399 {
400 setZoom( 100, true );
401 slotUpdateRuler();
402 initGui();
403 }
404
405 // Determine initial scroll position
406 // We do this delayed, so that the GUI has been fully constructed
407 // (and e.g. the statusbar can repaint).
408 TQTimer::singleShot( 0, this, TQ_SLOT( slotSetInitialPosition() ) );
409 TQTimer::singleShot( 0, this, TQ_SLOT( updateZoom() ) );
410}
411
412KWView::~KWView()
413{
414 delete m_tableActionList.first(); // the first one is the separator.
415 clearSpellChecker();
416
417 delete m_searchEntry;
418 m_searchEntry = 0L;
419 delete m_replaceEntry;
420 m_replaceEntry = 0L;
421 if ( m_specialCharDlg )
422 m_specialCharDlg->closeDialog(); // will call slotSpecialCharDlgClosed
423
424 // Abort any find/replace
425 delete m_findReplace;
426 // Delete gui while we still exist ( it needs documentDeleted() )
427 delete m_gui;
428 delete m_sbPageLabel;
429 delete m_sbFramesLabel;
430 delete m_fsInline;
431 delete m_dcop;
432 delete m_fontDlg;
433 delete m_paragDlg;
434}
435
436DCOPObject* KWView::dcopObject()
437{
438 if ( !m_dcop )
439 m_dcop = new KWordViewIface( this );
440
441 return m_dcop;
442}
443
444void KWView::slotChangeCutState(bool b)
445{
446 KWTextFrameSetEdit * edit = currentTextEdit();
447 if ( edit && edit->textFrameSet()->protectContent())
448 m_actionEditCut->setEnabled( false );
449 else
450 m_actionEditCut->setEnabled( b );
451}
452
453void KWView::slotChangeCaseState(bool b)
454{
455 KWTextFrameSetEdit * edit = currentTextEdit();
456 if ( edit && edit->textFrameSet()->protectContent())
457 m_actionChangeCase->setEnabled( false );
458 else
459 m_actionChangeCase->setEnabled( b );
460}
461
462void KWView::slotSetInitialPosition()
463{
464 KWTextFrameSetEdit* textedit = dynamic_cast<KWTextFrameSetEdit *>(m_gui->canvasWidget()->currentFrameSetEdit());
465 if ( textedit )
466 textedit->ensureCursorVisible();
467 else
468 m_gui->canvasWidget()->setContentsPos( 0, 0 );
469}
470
471void KWView::changeNbOfRecentFiles(int nb)
472{
473 if ( shell() ) // 0 when embedded into konq !
474 shell()->setMaxRecentItems( nb );
475}
476
477KWViewMode* KWView::viewMode() const
478{
479 return m_gui->canvasWidget()->viewMode();
480}
481
482void KWView::initGui()
483{
484 clipboardDataChanged();
485 if ( m_gui )
486 m_gui->showGUI();
487 showMouseMode( KWCanvas::MM_EDIT );
488 initGUIButton();
489 m_actionFormatDecreaseIndent->setEnabled(false);
490 //setNoteType(m_doc->getNoteType(), false);
491
492 m_actionFormatColor->setCurrentColor( TQt::black );
493
494 updateGridButton();
495
496 //refresh zoom combobox
497 updateZoomControls();
498
499
500 // This is probably to emit currentMouseModeChanged and set the cursor
501 m_gui->canvasWidget()->setMouseMode( m_gui->canvasWidget()->mouseMode() );
502
503 bool editingFormula = dynamic_cast<KWFormulaFrameSetEdit *>( m_gui->canvasWidget()->currentFrameSetEdit() ) != 0;
504 //showFormulaToolbar( false ); // not called, to avoid creating the formula-document if not necessary
505 if(shell())
506 shell()->showToolbar( "formula_toolbar", editingFormula );
507
508 if ( !editingFormula )
509 {
510 kWordDocument()->formulaDocumentWrapper()->setEnabled(false);
511 kWordDocument()->formulaDocumentWrapper()->enableMatrixActions(false);
512 kWordDocument()->formulaDocumentWrapper()->getSyntaxHighlightingAction()->setEnabled(false);
513 }
514
515 // Prevention against applyMainWindowSettings hiding the statusbar
516 if ( KStatusBar* sb = statusBar() )
517 sb->show();
518
519 updatePageInfo();
520 slotFrameSetEditChanged();
521 frameSelectedChanged();
522 updateTocActionText(m_doc->tocPresent());
523 //at the beginning m_actionBackgroundColor should be active
524 m_actionBackgroundColor->setEnabled(true);
525 updateBgSpellCheckingState();
526 updateDirectCursorButton();
527 m_actionCreateFrameStyle->setEnabled(false);
528}
529
530
531void KWView::updateBgSpellCheckingState()
532{
533 m_actionAllowBgSpellCheck->setChecked( m_doc->backgroundSpellCheckEnabled() );
534}
535
536
537void KWView::initGUIButton()
538{
539 m_actionViewFrameBorders->setChecked( viewFrameBorders() );
540 m_actionViewFormattingChars->setChecked( m_doc->viewFormattingChars() );
541 m_actionShowDocStruct->setChecked(m_doc->showdocStruct());
542 m_actionShowRuler->setChecked(m_doc->showRuler());
543
544 updateHeaderFooterButton();
545 m_actionAllowAutoFormat->setChecked( m_doc->allowAutoFormat() );
546
547 if ( !m_doc->isEmbedded() ) {
548 TQString mode = viewMode()->type();
549 if (mode=="ModePreview")
550 m_actionViewPreviewMode->setChecked(true);
551 else if (mode=="ModeText")
552 m_actionViewTextMode->setChecked(true);
553 else //if (mode=="ModeNormal")
554 m_actionViewPageMode->setChecked(true);
555 switchModeView();
556 }
557}
558
559void KWView::setupActions()
560{
561 // The actions here are grouped by menu, because this helps noticing
562 // accelerator clashes.
563
564 // -------------- File menu
565 m_actionExtraCreateTemplate = new TDEAction( i18n( "&Create Template From Document..." ), 0,
566 this, TQ_SLOT( extraCreateTemplate() ),
567 actionCollection(), "extra_template" );
568 m_actionExtraCreateTemplate->setToolTip( i18n( "Save this document and use it later as a template" ) );
569 m_actionExtraCreateTemplate->setWhatsThis( i18n( "You can save this document as a template.<br><br>You can use this new template as a starting point for another document." ) );
570
571 m_actionFileStatistics = new TDEAction( i18n( "Statistics" ), 0, this, TQ_SLOT( fileStatistics() ), actionCollection(), "file_statistics" );
572 m_actionFileStatistics->setToolTip( i18n( "Sentence, word and letter counts for this document" ) );
573 m_actionFileStatistics->setWhatsThis( i18n( "Information on the number of letters, words, syllables and sentences for this document.<p>Evaluates readability using the Flesch reading score." ) );
574 // -------------- Edit actions
575 m_actionEditCut = KStdAction::cut( this, TQ_SLOT( editCut() ), actionCollection(), "edit_cut" );
576 m_actionEditCopy = KStdAction::copy( this, TQ_SLOT( editCopy() ), actionCollection(), "edit_copy" );
577 m_actionEditPaste = KStdAction::paste( this, TQ_SLOT( editPaste() ), actionCollection(), "edit_paste" );
578 m_actionEditFind = KStdAction::find( this, TQ_SLOT( editFind() ), actionCollection(), "edit_find" );
579 m_actionEditFindNext = KStdAction::findNext( this, TQ_SLOT( editFindNext() ), actionCollection(), "edit_findnext" );
580 m_actionEditFindPrevious = KStdAction::findPrev( this, TQ_SLOT( editFindPrevious() ), actionCollection(), "edit_findprevious" );
581 m_actionEditReplace = KStdAction::replace( this, TQ_SLOT( editReplace() ), actionCollection(), "edit_replace" );
582 m_actionEditSelectAll = KStdAction::selectAll( this, TQ_SLOT( editSelectAll() ), actionCollection(), "edit_selectall" );
583 new TDEAction( i18n( "Select All Frames" ), 0, this, TQ_SLOT( editSelectAllFrames() ), actionCollection(), "edit_selectallframes" );
584 m_actionEditSelectCurrentFrame = new TDEAction( i18n( "Select Frame" ), 0,
585 0, this, TQ_SLOT( editSelectCurrentFrame() ),
586 actionCollection(), "edit_selectcurrentframe" );
587 m_actionSpellCheck = KStdAction::spelling( this, TQ_SLOT( slotSpellCheck() ), actionCollection(), "extra_spellcheck" );
588 m_actionDeletePage = new TDEAction( i18n( "Delete Page" ), "delslide", 0,
589 this, TQ_SLOT( deletePage() ),
590 actionCollection(), "delete_page" );
591 kdDebug() << m_doc->pageCount() << " " << (m_doc->processingType() == KWDocument::DTP) << endl;
592
593 (void) new TDEAction( i18n( "Configure Mai&l Merge..." ), "configure",0,
594 this, TQ_SLOT( editMailMergeDataBase() ),
595 actionCollection(), "edit_sldatabase" );
596
597
598 (void) new KWMailMergeLabelAction( i18n("Drag Mail Merge Variable"), 0,
599 this, TQ_SLOT(editMailMergeDataBase()), actionCollection(), "mailmerge_draglabel" );
600
601// (void) new KWMailMergeComboAction::KWMailMergeComboAction(i18n("Insert Mailmerge Var"),0,this, TQ_SLOT(JWJWJW()),actionCollection(),"mailmerge_varchooser");
602
603 // -------------- Frame menu
604 m_actionEditDelFrame = new TDEAction( i18n( "&Delete Frame" ), 0,
605 this, TQ_SLOT( editDeleteFrame() ),
606 actionCollection(), "edit_delframe" );
607 m_actionEditDelFrame->setToolTip( i18n( "Delete the currently selected frame(s)." ) );
608 m_actionEditDelFrame->setWhatsThis( i18n( "Delete the currently selected frame(s)." ) );
609
610 m_actionCreateLinkedFrame = new TDEAction( i18n( "Create Linked Copy" ), 0, this, TQ_SLOT( createLinkedFrame() ), actionCollection(), "create_linked_frame" );
611 m_actionCreateLinkedFrame->setToolTip( i18n( "Create a copy of the current frame, always showing the same contents" ) );
612 m_actionCreateLinkedFrame->setWhatsThis( i18n("Create a copy of the current frame, that remains linked to it. This means they always show the same contents: modifying the contents in such a frame will update all its linked copies.") );
613
614 m_actionRaiseFrame = new TDEAction( i18n( "Ra&ise Frame" ), "raise",
615 TQt::CTRL +TQt::SHIFT+ TQt::Key_R, this, TQ_SLOT( raiseFrame() ),
616 actionCollection(), "raiseframe" );
617 m_actionRaiseFrame->setToolTip( i18n( "Raise the currently selected frame so that it appears above all the other frames" ) );
618 m_actionRaiseFrame->setWhatsThis( i18n( "Raise the currently selected frame so that it appears above all the other frames. This is only useful if frames overlap each other. If multiple frames are selected they are all raised in turn." ) );
619
620 m_actionLowerFrame = new TDEAction( i18n( "&Lower Frame" ), "lower",
621 TQt::CTRL +TQt::SHIFT+ TQt::Key_L, this, TQ_SLOT( lowerFrame() ),
622 actionCollection(), "lowerframe" );
623 m_actionLowerFrame->setToolTip( i18n( "Lower the currently selected frame so that it disappears under any frame that overlaps it" ) );
624 m_actionLowerFrame->setWhatsThis( i18n( "Lower the currently selected frame so that it disappears under any frame that overlaps it. If multiple frames are selected they are all lowered in turn." ) );
625
626 m_actionBringToFront= new TDEAction( i18n( "Bring to Front" ), "bring_forward",
627 0, this, TQ_SLOT( bringToFront() ),
628 actionCollection(), "bring_tofront_frame" );
629
630 m_actionSendBackward= new TDEAction( i18n( "Send to Back" ), "send_backward",
631 0, this, TQ_SLOT( sendToBack() ),
632 actionCollection(), "send_toback_frame" );
633
634
635 // -------------- View menu
636
637 if ( !m_doc->isEmbedded() ) {
638
639 m_actionViewTextMode = new TDEToggleAction( i18n( "Text Mode" ), 0,
640 this, TQ_SLOT( viewTextMode() ),
641 actionCollection(), "view_textmode" );
642 m_actionViewTextMode->setToolTip( i18n( "Only show the text of the document." ) );
643 m_actionViewTextMode->setWhatsThis( i18n( "Do not show any pictures, formatting or layout. KWord will display only the text for editing." ) );
644
645 m_actionViewTextMode->setExclusiveGroup( "viewmodes" );
646 m_actionViewPageMode = new TDEToggleAction( i18n( "&Page Mode" ), 0,
647 this, TQ_SLOT( viewPageMode() ),
648 actionCollection(), "view_pagemode" );
649 m_actionViewPageMode->setWhatsThis( i18n( "Switch to page mode.<br><br> Page mode is designed to make editing your text easy.<br><br>This function is most frequently used to return to text editing after switching to preview mode." ) );
650 m_actionViewPageMode->setToolTip( i18n( "Switch to page editing mode." ) );
651
652 m_actionViewPageMode->setExclusiveGroup( "viewmodes" );
653 m_actionViewPageMode->setChecked( true );
654 m_actionViewPreviewMode = new TDEToggleAction( i18n( "Pre&view Mode" ), 0,
655 this, TQ_SLOT( viewPreviewMode() ),
656 actionCollection(), "view_previewmode" );
657 m_actionViewPreviewMode->setWhatsThis( i18n( "Zoom out from your document to get a look at several pages of your document.<br><br>The number of pages per line can be customized." ) );
658 m_actionViewPreviewMode->setToolTip( i18n( "Zoom out to a multiple page view." ) );
659
660 m_actionViewPreviewMode->setExclusiveGroup( "viewmodes" );
661 }
662 else // no viewmode switching when embedded; at least "Page" makes no sense
663 {
664 m_actionViewTextMode = 0;
665 m_actionViewPageMode = 0;
666 m_actionViewPreviewMode = 0;
667 }
668
669 m_actionViewFormattingChars = new TDEToggleAction( i18n( "&Formatting Characters" ), 0,
670 this, TQ_SLOT( slotViewFormattingChars() ),
671 actionCollection(), "view_formattingchars" );
672 m_actionViewFormattingChars->setToolTip( i18n( "Toggle the display of non-printing characters." ) );
673 m_actionViewFormattingChars->setWhatsThis( i18n( "Toggle the display of non-printing characters.<br><br>When this is enabled, KWord shows you tabs, spaces, carriage returns and other non-printing characters." ) );
674
675 m_actionViewFrameBorders = new TDEToggleAction( i18n( "Frame &Borders" ), 0,
676 this, TQ_SLOT( slotViewFrameBorders() ),
677 actionCollection(), "view_frameborders" );
678 m_actionViewFrameBorders->setToolTip( i18n( "Turns the border display on and off." ) );
679 m_actionViewFrameBorders->setWhatsThis( i18n( "Turns the border display on and off.<br><br>The borders are never printed. This option is useful to see how the document will appear on the printed page." ) );
680
681 m_actionViewHeader = new TDEToggleAction( i18n( "Enable Document &Headers" ), 0,
682 this, TQ_SLOT( viewHeader() ),
683 actionCollection(), "format_header" );
684 m_actionViewHeader->setCheckedState(i18n("Disable Document &Headers"));
685 m_actionViewHeader->setToolTip( i18n( "Shows and hides header display." ) );
686 m_actionViewHeader->setWhatsThis( i18n( "Selecting this option toggles the display of headers in KWord.<br><br>Headers are special frames at the top of each page which can contain page numbers or other information." ) );
687
688 m_actionViewFooter = new TDEToggleAction( i18n( "Enable Document Foo&ters" ), 0,
689 this, TQ_SLOT( viewFooter() ),
690 actionCollection(), "format_footer" );
691 m_actionViewFooter->setCheckedState(i18n("Disable Document Foo&ters"));
692 m_actionViewFooter->setToolTip( i18n( "Shows and hides footer display." ) );
693 m_actionViewFooter->setWhatsThis( i18n( "Selecting this option toggles the display of footers in KWord. <br><br>Footers are special frames at the bottom of each page which can contain page numbers or other information." ) );
694
695 m_actionViewZoom = new TDESelectAction( i18n( "Zoom" ), "viewmag", 0,
696 actionCollection(), "view_zoom" );
697
698 connect( m_actionViewZoom, TQ_SIGNAL( activated( const TQString & ) ),
699 this, TQ_SLOT( viewZoom( const TQString & ) ) );
700 m_actionViewZoom->setEditable(true);
701 changeZoomMenu( );
702
703 // -------------- Insert menu
704 m_actionInsertSpecialChar = new TDEAction( i18n( "Sp&ecial Character..." ), "char",
705 TQt::ALT + TQt::SHIFT + TQt::Key_C,
706 this, TQ_SLOT( insertSpecialChar() ),
707 actionCollection(), "insert_specialchar" );
708 m_actionInsertSpecialChar->setToolTip( i18n( "Insert one or more symbols or letters not found on the keyboard." ) );
709 m_actionInsertSpecialChar->setWhatsThis( i18n( "Insert one or more symbols or letters not found on the keyboard." ) );
710
711 m_actionInsertFrameBreak = new TDEAction( TQString(), TQt::CTRL + TQt::Key_Return,
712 this, TQ_SLOT( insertFrameBreak() ),
713 actionCollection(), "insert_framebreak" );
714 if ( m_doc->processingType() == KWDocument::WP ) {
715 m_actionInsertFrameBreak->setText( i18n( "Page Break" ) );
716 m_actionInsertFrameBreak->setToolTip( i18n( "Force the remainder of the text into the next page." ) );
717 m_actionInsertFrameBreak->setWhatsThis( i18n( "This inserts a non-printing character at the current cursor position. All text after this point will be moved into the next page." ) );
718 } else {
719 m_actionInsertFrameBreak->setText( i18n( "&Hard Frame Break" ) );
720 m_actionInsertFrameBreak->setToolTip( i18n( "Force the remainder of the text into the next frame." ) );
721 m_actionInsertFrameBreak->setWhatsThis( i18n( "This inserts a non-printing character at the current cursor position. All text after this point will be moved into the next frame in the frameset." ) );
722 }
723
724 /*actionInsertPage =*/ new TDEAction( m_doc->processingType() == KWDocument::WP ? i18n( "Page" ) : i18n( "Page..." ), "page", 0,
725 this, TQ_SLOT( insertPage() ),
726 actionCollection(), "insert_page" );
727
728 m_actionInsertLink = new TDEAction( i18n( "Link..." ), 0,
729 this, TQ_SLOT( insertLink() ),
730 actionCollection(), "insert_link" );
731 m_actionInsertLink->setToolTip( i18n( "Insert a Web address, email address or hyperlink to a file." ) );
732 m_actionInsertLink->setWhatsThis( i18n( "Insert a Web address, email address or hyperlink to a file." ) );
733
734 m_actionInsertComment = new TDEAction( i18n( "Comment..." ), 0,
735 this, TQ_SLOT( insertComment() ),
736 actionCollection(), "insert_comment" );
737 m_actionInsertComment->setToolTip( i18n( "Insert a comment about the selected text." ) );
738 m_actionInsertComment->setWhatsThis( i18n( "Insert a comment about the selected text. These comments are not designed to appear on the final page." ) );
739
740 m_actionEditComment = new TDEAction( i18n("Edit Comment..."), 0,
741 this, TQ_SLOT(editComment()),
742 actionCollection(), "edit_comment");
743 m_actionEditComment->setToolTip( i18n( "Change the content of a comment." ) );
744 m_actionEditComment->setWhatsThis( i18n( "Change the content of a comment." ) );
745
746 m_actionRemoveComment = new TDEAction( i18n("Remove Comment"), 0,
747 this, TQ_SLOT(removeComment()),
748 actionCollection(), "remove_comment");
749 m_actionRemoveComment->setToolTip( i18n( "Remove the selected document comment." ) );
750 m_actionRemoveComment->setWhatsThis( i18n( "Remove the selected document comment." ) );
751 m_actionCopyTextOfComment = new TDEAction( i18n("Copy Text of Comment..."), 0,
752 this, TQ_SLOT(copyTextOfComment()),
753 actionCollection(), "copy_text_comment");
754
755
756 m_actionInsertFootEndNote = new TDEAction( i18n( "&Footnote/Endnote..." ), 0,
757 this, TQ_SLOT( insertFootNote() ),
758 actionCollection(), "insert_footendnote" );
759 m_actionInsertFootEndNote->setToolTip( i18n( "Insert a footnote referencing the selected text." ) );
760 m_actionInsertFootEndNote->setWhatsThis( i18n( "Insert a footnote referencing the selected text." ) );
761
762 m_actionInsertContents = new TDEAction( i18n( "Table of &Contents" ), 0,
763 this, TQ_SLOT( insertContents() ),
764 actionCollection(), "insert_contents" );
765 m_actionInsertContents->setToolTip( i18n( "Insert table of contents at the current cursor position." ) );
766 m_actionInsertContents->setWhatsThis( i18n( "Insert table of contents at the current cursor position." ) );
767
768 m_variableDefMap.clear();
769 actionInsertVariable = new TDEActionMenu( i18n( "&Variable" ),
770 actionCollection(), "insert_variable" );
771
772 // The last argument is only needed if a submenu is to be created
773 addVariableActions( VT_FIELD, KoFieldVariable::actionTexts(), actionInsertVariable, i18n("Document &Information") );
774 addVariableActions( VT_DATE, KoDateVariable::actionTexts(), actionInsertVariable, i18n("&Date") );
775 addVariableActions( VT_TIME, KoTimeVariable::actionTexts(), actionInsertVariable, i18n("&Time") );
776 addVariableActions( VT_PGNUM, KoPageVariable::actionTexts(), actionInsertVariable, i18n("&Page") );
777 addVariableActions( VT_STATISTIC, KWStatisticVariable::actionTexts(), actionInsertVariable, i18n("&Statistic") );
778
779 m_actionInsertCustom = new TDEActionMenu( i18n( "&Custom" ),
780 actionCollection(), "insert_custom" );
781 actionInsertVariable->insert(m_actionInsertCustom);
782
783 //addVariableActions( VT_CUSTOM, KWCustomVariable::actionTexts(), actionInsertVariable, TQString() );
784
785 addVariableActions( VT_MAILMERGE, KoMailMergeVariable::actionTexts(), actionInsertVariable, TQString() );
786
787 actionInsertVariable->popupMenu()->insertSeparator();
788 m_actionRefreshAllVariable = new TDEAction( i18n( "&Refresh All Variables" ), 0,
789 this, TQ_SLOT( refreshAllVariable() ),
790 actionCollection(), "refresh_all_variable" );
791 m_actionRefreshAllVariable->setToolTip( i18n( "Update all variables to current values." ) );
792 m_actionRefreshAllVariable->setWhatsThis( i18n( "Update all variables in the document to current values.<br><br>This will update page numbers, dates or any other variables that need updating." ) );
793
794 actionInsertVariable->insert(m_actionRefreshAllVariable);
795
796 m_actionInsertExpression = new TDEActionMenu( i18n( "&Expression" ),
797 actionCollection(), "insert_expression" );
798 loadexpressionActions( m_actionInsertExpression);
799
800 m_actionToolsCreateText = new TDEToggleAction( i18n( "Te&xt Frame" ), "frame_text", TQt::Key_F10 /*same as kpr*/,
801 this, TQ_SLOT( toolsCreateText() ),
802 actionCollection(), "tools_createtext" );
803 m_actionToolsCreateText->setToolTip( i18n( "Create a new text frame." ) );
804 m_actionToolsCreateText->setWhatsThis( i18n( "Create a new text frame." ) );
805
806 m_actionToolsCreateText->setExclusiveGroup( "tools" );
807 m_actionInsertFormula = new TDEAction( i18n( "For&mula" ), "frame_formula", TQt::Key_F4,
808 this, TQ_SLOT( insertFormula() ),
809 actionCollection(), "tools_formula" );
810 m_actionInsertFormula->setToolTip( i18n( "Insert a formula into a new frame." ) );
811 m_actionInsertFormula->setWhatsThis( i18n( "Insert a formula into a new frame." ) );
812
813 m_actionInsertTable = new TDEAction( i18n( "&Table..." ), "inline_table",
814 TQt::Key_F5,
815 this, TQ_SLOT( insertTable() ),
816 actionCollection(), "insert_table" );
817 m_actionInsertTable->setToolTip( i18n( "Create a table." ) );
818 m_actionInsertTable->setWhatsThis( i18n( "Create a table.<br><br>The table can either exist in a frame of its own or inline." ) );
819
820 m_actionToolsCreatePix = new TDEToggleAction( i18n( "P&icture..." ), "frame_image", // or inline_image ?
821 TQt::SHIFT + TQt::Key_F5 /*same as kpr*/,
822 this, TQ_SLOT( insertPicture() ),
823 actionCollection(), "insert_picture" );
824 m_actionToolsCreatePix->setToolTip( i18n( "Create a new frame for a picture." ) );
825 m_actionToolsCreatePix->setWhatsThis( i18n( "Create a new frame for a picture or diagram." ) );
826 m_actionToolsCreatePix->setExclusiveGroup( "tools" );
827
828 m_actionToolsCreatePart = new KoPartSelectAction( i18n( "&Object Frame" ), "frame_query",
829 this, TQ_SLOT( toolsPart() ),
830 actionCollection(), "tools_part" );
831 m_actionToolsCreatePart->setToolTip( i18n( "Insert an object into a new frame." ) );
832 m_actionToolsCreatePart->setWhatsThis( i18n( "Insert an object into a new frame." ) );
833
834 m_actionInsertFile = new TDEAction( i18n( "Fi&le..." ), 0,
835 this, TQ_SLOT( insertFile() ),
836 actionCollection(), "insert_file" );
837
838
839 // ------------------------- Format menu
840 m_actionFormatFont = new TDEAction( i18n( "&Font..." ), TQt::ALT + TQt::CTRL + TQt::Key_F,
841 this, TQ_SLOT( formatFont() ),
842 actionCollection(), "format_font" );
843 m_actionFormatFont->setToolTip( i18n( "Change character size, font, boldface, italics etc." ) );
844 m_actionFormatFont->setWhatsThis( i18n( "Change the attributes of the currently selected characters." ) );
845
846 m_actionFormatParag = new TDEAction( i18n( "&Paragraph..." ), TQt::ALT + TQt::CTRL + TQt::Key_P,
847 this, TQ_SLOT( formatParagraph() ),
848 actionCollection(), "format_paragraph" );
849 m_actionFormatParag->setToolTip( i18n( "Change paragraph margins, text flow, borders, bullets, numbering etc." ) );
850 m_actionFormatParag->setWhatsThis( i18n( "Change paragraph margins, text flow, borders, bullets, numbering etc.<p>Select text in multiple paragraphs to change the formatting of all selected paragraphs.<p>If no text is selected, the paragraph where the cursor is located will be changed." ) );
851
852 m_actionFormatFrameSet = new TDEAction( i18n( "F&rame/Frameset Properties" ), 0,
853 this, TQ_SLOT( formatFrameSet() ),
854 actionCollection(), "format_frameset" );
855 m_actionFormatFrameSet->setToolTip( i18n( "Alter frameset properties." ) );
856 m_actionFormatFrameSet->setWhatsThis( i18n( "Alter frameset properties.<p>Currently you can change the frame background." ) );
857
858 m_actionFormatPage = new TDEAction( i18n( "Page &Layout..." ), 0,
859 this, TQ_SLOT( formatPage() ),
860 actionCollection(), "format_page" );
861 m_actionFormatPage->setToolTip( i18n( "Change properties of entire page." ) );
862 m_actionFormatPage->setWhatsThis( i18n( "Change properties of the entire page.<p>Currently you can change paper size, paper orientation, header and footer sizes, and column settings." ) );
863
864
865 m_actionFormatFrameStylist = new TDEAction( i18n( "&Frame Style Manager" ), 0 /*shortcut?*/,
866 this, TQ_SLOT( extraFrameStylist() ),
867 actionCollection(), "frame_stylist" );
868 m_actionFormatFrameStylist->setToolTip( i18n( "Change attributes of framestyles." ) );
869 m_actionFormatFrameStylist->setWhatsThis( i18n( "Change background and borders of framestyles.<p>Multiple framestyles can be changed using the dialog box." ) );
870
871
872 m_actionFormatStylist = new TDEAction( i18n( "&Style Manager" ), TQt::ALT + TQt::CTRL + TQt::Key_S,
873 this, TQ_SLOT( extraStylist() ),
874 actionCollection(), "format_stylist" );
875 m_actionFormatStylist->setToolTip( i18n( "Change attributes of styles." ) );
876 m_actionFormatStylist->setWhatsThis( i18n( "Change font and paragraph attributes of styles.<p>Multiple styles can be changed using the dialog box." ) );
877
878 m_actionFormatFontSize = new TDEFontSizeAction( i18n( "Font Size" ), 0,
879 actionCollection(), "format_fontsize" );
880 connect( m_actionFormatFontSize, TQ_SIGNAL( fontSizeChanged( int ) ),
881 this, TQ_SLOT( textSizeSelected( int ) ) );
882
883 m_actionFontSizeIncrease = new TDEAction( i18n("Increase Font Size"), "fontsizeup", TQt::CTRL + TQt::Key_Greater, this, TQ_SLOT( increaseFontSize() ), actionCollection(), "increase_fontsize" );
884 m_actionFontSizeDecrease = new TDEAction( i18n("Decrease Font Size"), "fontsizedown", TQt::CTRL + TQt::Key_Less, this, TQ_SLOT( decreaseFontSize() ), actionCollection(), "decrease_fontsize" );
885
886#ifdef KFONTACTION_HAS_CRITERIA_ARG
887 m_actionFormatFontFamily = new TDEFontAction( TDEFontChooser::SmoothScalableFonts,
888 i18n( "Font Family" ), 0,
889 actionCollection(), "format_fontfamily" );
890#else
891 m_actionFormatFontFamily = new TDEFontAction( i18n( "Font Family" ), 0,
892 actionCollection(), "format_fontfamily" );
893#endif
894 connect( m_actionFormatFontFamily, TQ_SIGNAL( activated( const TQString & ) ),
895 this, TQ_SLOT( textFontSelected( const TQString & ) ) );
896
897 m_actionFormatStyleMenu = new TDEActionMenu( i18n( "St&yle" ), 0,
898 actionCollection(), "format_stylemenu" );
899 m_actionFormatStyle = new TDESelectAction( i18n( "St&yle" ), 0,
900 actionCollection(), "format_style" );
901 // In fact, binding a key to this action will simply re-apply the current style. Why not.
902 //m_actionFormatStyle->setShortcutConfigurable( false );
903 connect( m_actionFormatStyle, TQ_SIGNAL( activated( int ) ),
904 this, TQ_SLOT( textStyleSelected( int ) ) );
905 updateStyleList();
906
907 m_actionFormatDefault=new TDEAction( i18n( "Default Format" ), 0,
908 this, TQ_SLOT( textDefaultFormat() ),
909 actionCollection(), "text_default" );
910 m_actionFormatDefault->setToolTip( i18n( "Change font and paragraph attributes to their default values." ) );
911 m_actionFormatDefault->setWhatsThis( i18n( "Change font and paragraph attributes to their default values." ) );
912
913 // ----------------------- More format actions, for the toolbar only
914
915 m_actionFormatBold = new TDEToggleAction( i18n( "&Bold" ), "format-text-bold", TQt::CTRL + TQt::Key_B,
916 this, TQ_SLOT( textBold() ),
917 actionCollection(), "format_bold" );
918 m_actionFormatItalic = new TDEToggleAction( i18n( "&Italic" ), "format-text-italic", TQt::CTRL + TQt::Key_I,
919 this, TQ_SLOT( textItalic() ),
920 actionCollection(), "format_italic" );
921 m_actionFormatUnderline = new TDEToggleAction( i18n( "&Underline" ), "format-text-underline", TQt::CTRL + TQt::Key_U,
922 this, TQ_SLOT( textUnderline() ),
923 actionCollection(), "format_underline" );
924 m_actionFormatStrikeOut = new TDEToggleAction( i18n( "&Strike Out" ), "format-text-strikethrough", 0 ,
925 this, TQ_SLOT( textStrikeOut() ),
926 actionCollection(), "format_strike" );
927
928 m_actionFormatAlignLeft = new TDEToggleAction( i18n( "Align &Left" ), "format-text-direction-ltr", TQt::CTRL + TQt::Key_L,
929 this, TQ_SLOT( textAlignLeft() ),
930 actionCollection(), "format_alignleft" );
931 m_actionFormatAlignLeft->setExclusiveGroup( "align" );
932 m_actionFormatAlignLeft->setChecked( true );
933 m_actionFormatAlignCenter = new TDEToggleAction( i18n( "Align &Center" ), "text_center", TQt::CTRL + TQt::ALT + TQt::Key_C,
934 this, TQ_SLOT( textAlignCenter() ),
935 actionCollection(), "format_aligncenter" );
936 m_actionFormatAlignCenter->setExclusiveGroup( "align" );
937 m_actionFormatAlignRight = new TDEToggleAction( i18n( "Align &Right" ), "format-text-direction-rtl", TQt::CTRL + TQt::ALT + TQt::Key_R,
938 this, TQ_SLOT( textAlignRight() ),
939 actionCollection(), "format_alignright" );
940 m_actionFormatAlignRight->setExclusiveGroup( "align" );
941 m_actionFormatAlignBlock = new TDEToggleAction( i18n( "Align &Block" ), "text_block", TQt::CTRL + TQt::Key_J,
942 this, TQ_SLOT( textAlignBlock() ),
943 actionCollection(), "format_alignblock" );
944 m_actionFormatAlignBlock->setExclusiveGroup( "align" );
945
946 m_actionFormatSpacingSingle = new TDEToggleAction( i18n( "Line Spacing &1" ), "spacesimple", TQt::CTRL + TQt::Key_1,
947 this, TQ_SLOT( textSpacingSingle() ),
948 actionCollection(), "format_spacingsingle" );
949 m_actionFormatSpacingSingle->setExclusiveGroup( "spacing" );
950 m_actionFormatSpacingOneAndHalf = new TDEToggleAction( i18n( "Line Spacing 1.&5" ), "spacedouble", TQt::CTRL + TQt::Key_5,
951 this, TQ_SLOT( textSpacingOneAndHalf() ),
952 actionCollection(), "format_spacing15" );
953 m_actionFormatSpacingOneAndHalf->setExclusiveGroup( "spacing" );
954 m_actionFormatSpacingDouble = new TDEToggleAction( i18n( "Line Spacing &2" ), "spacetriple", TQt::CTRL + TQt::Key_2,
955 this, TQ_SLOT( textSpacingDouble() ),
956 actionCollection(), "format_spacingdouble" );
957 m_actionFormatSpacingDouble->setExclusiveGroup( "spacing" );
958
959 m_actionFormatSuper = new TDEToggleAction( i18n( "Superscript" ), "super", 0,
960 this, TQ_SLOT( textSuperScript() ),
961 actionCollection(), "format_super" );
962 //m_actionFormatSuper->setExclusiveGroup( "valign" );
963 m_actionFormatSub = new TDEToggleAction( i18n( "Subscript" ), "sub", 0,
964 this, TQ_SLOT( textSubScript() ),
965 actionCollection(), "format_sub" );
966 //m_actionFormatSub->setExclusiveGroup( "valign" );
967
968 m_actionFormatIncreaseIndent= new TDEAction( i18n( "Increase Indent" ),
969 TQApplication::reverseLayout() ? "format_decreaseindent" : "format_increaseindent", 0,
970 this, TQ_SLOT( textIncreaseIndent() ),
971 actionCollection(), "format_increaseindent" );
972
973 m_actionFormatDecreaseIndent= new TDEAction( i18n( "Decrease Indent" ),
974 TQApplication::reverseLayout() ? "format_increaseindent" :"format_decreaseindent", 0,
975 this, TQ_SLOT( textDecreaseIndent() ),
976 actionCollection(), "format_decreaseindent" );
977
978 m_actionFormatColor = new TTDESelectColorAction( i18n( "Text Color..." ), TTDESelectColorAction::TextColor,
979 this, TQ_SLOT( textColor() ),
980 actionCollection(), "format_color", true );
981 m_actionFormatColor->setDefaultColor(TQColor());
982
983
984 //actionFormatList = new TDEToggleAction( i18n( "List" ), "enumList", 0,
985 // this, TQ_SLOT( textList() ),
986 // actionCollection(), "format_list" );
987 //actionFormatList->setExclusiveGroup( "style" );
988
989 m_actionFormatNumber = new TDEActionMenu( i18n( "Number" ),
990 "enumList", actionCollection(), "format_number" );
991 m_actionFormatNumber->setDelayed( false );
992 m_actionFormatBullet = new TDEActionMenu( i18n( "Bullet" ),
993 "unsortedList", actionCollection(), "format_bullet" );
994 m_actionFormatBullet->setDelayed( false );
995 TQPtrList<KoCounterStyleWidget::StyleRepresenter> stylesList;
996 KoCounterStyleWidget::makeCounterRepresenterList( stylesList );
997 TQPtrListIterator<KoCounterStyleWidget::StyleRepresenter> styleIt( stylesList );
998 for ( ; styleIt.current() ; ++styleIt ) {
999 // Dynamically create toggle-actions for each list style.
1000 // This approach allows to edit toolbars and extract separate actions from this menu
1001 TDEToggleAction* act = new TDEToggleAction( styleIt.current()->name(), /*TODO icon,*/
1002 0, this, TQ_SLOT( slotCounterStyleSelected() ),
1003 actionCollection(), TQString("counterstyle_%1").arg( styleIt.current()->style() ).latin1() );
1004 act->setExclusiveGroup( "counterstyle" );
1005 // Add to the right menu: both for "none", bullet for bullets, numbers otherwise
1006 if ( styleIt.current()->style() == KoParagCounter::STYLE_NONE ) {
1007 m_actionFormatBullet->insert( act );
1008 m_actionFormatNumber->insert( act );
1009 } else if ( styleIt.current()->isBullet() )
1010 m_actionFormatBullet->insert( act );
1011 else
1012 m_actionFormatNumber->insert( act );
1013 }
1014
1015 // ---------------------------- frame toolbar actions
1016
1017 m_actionFrameStyleMenu = new TDEActionMenu( i18n( "Fra&mestyle" ), 0,
1018 actionCollection(), "frame_stylemenu" );
1019 m_actionFrameStyle = new TDESelectAction( i18n( "Framest&yle" ), 0,
1020 actionCollection(), "frame_style" );
1021 connect( m_actionFrameStyle, TQ_SIGNAL( activated( int ) ),
1022 this, TQ_SLOT( frameStyleSelected( int ) ) );
1023 updateFrameStyleList();
1024 m_actionBorderOutline = new TDEToggleAction( i18n( "Border Outline" ), "borderoutline",
1025 0, this, TQ_SLOT( borderOutline() ), actionCollection(), "border_outline" );
1026 m_actionBorderLeft = new TDEToggleAction( i18n( "Border Left" ), "borderleft",
1027 0, this, TQ_SLOT( borderLeft() ), actionCollection(), "border_left" );
1028 m_actionBorderRight = new TDEToggleAction( i18n( "Border Right" ), "borderright",
1029 0, this, TQ_SLOT( borderRight() ), actionCollection(), "border_right" );
1030 m_actionBorderTop = new TDEToggleAction( i18n( "Border Top" ), "bordertop",
1031 0, this, TQ_SLOT( borderTop() ), actionCollection(), "border_top" );
1032 m_actionBorderBottom = new TDEToggleAction( i18n( "Border Bottom" ), "borderbottom",
1033 0, this, TQ_SLOT( borderBottom() ), actionCollection(), "border_bottom" );
1034 m_actionBorderStyle = new TDESelectAction( i18n( "Border Style" ),
1035 0, actionCollection(), "border_style" );
1036
1037 TQStringList lst;
1038 lst << KoBorder::getStyle( KoBorder::SOLID );
1039 lst << KoBorder::getStyle( KoBorder::DASH );
1040 lst << KoBorder::getStyle( KoBorder::DOT );
1041 lst << KoBorder::getStyle( KoBorder::DASH_DOT );
1042 lst << KoBorder::getStyle( KoBorder::DASH_DOT_DOT );
1043 lst << KoBorder::getStyle( KoBorder::DOUBLE_LINE );
1044 m_actionBorderStyle->setItems( lst );
1045 m_actionBorderWidth = new TDESelectAction( i18n( "Border Width" ), 0,
1046 actionCollection(), "border_width" );
1047 lst.clear();
1048 for ( unsigned int i = 1; i < 10; i++ )
1049 lst << TQString::number( i );
1050 m_actionBorderWidth->setItems( lst );
1051 m_actionBorderWidth->setCurrentItem( 0 );
1052
1053 m_actionBorderColor = new TTDESelectColorAction( i18n("Border Color"), TTDESelectColorAction::LineColor, actionCollection(), "border_color", true );
1054 m_actionBorderColor->setDefaultColor(TQColor());
1055
1056
1057 m_actionBackgroundColor = new TTDESelectColorAction( i18n( "Text Background Color..." ), TTDESelectColorAction::FillColor, actionCollection(),"border_backgroundcolor", true);
1058 m_actionBackgroundColor->setToolTip( i18n( "Change background color for currently selected text." ) );
1059 m_actionBackgroundColor->setWhatsThis( i18n( "Change background color for currently selected text." ) );
1060
1061 connect(m_actionBackgroundColor,TQ_SIGNAL(activated()),TQ_SLOT(backgroundColor() ));
1062 m_actionBackgroundColor->setDefaultColor(TQColor());
1063
1064 // ---------------------- Table menu
1065 m_actionTablePropertiesMenu = new TDEAction( i18n( "&Properties" ), 0,
1066 this, TQ_SLOT( tableProperties() ),
1067 actionCollection(), "table_propertiesmenu" );
1068 m_actionTablePropertiesMenu->setToolTip( i18n( "Adjust properties of the current table." ) );
1069 m_actionTablePropertiesMenu->setWhatsThis( i18n( "Adjust properties of the current table." ) );
1070
1071 m_actionTableInsertRow = new TDEAction( i18n( "&Insert Row..." ), "insert_table_row", 0,
1072 this, TQ_SLOT( tableInsertRow() ),
1073 actionCollection(), "table_insrow" );
1074 m_actionTableInsertRow->setToolTip( i18n( "Insert one or more rows at cursor location." ) );
1075 m_actionTableInsertRow->setWhatsThis( i18n( "Insert one or more rows at current cursor location." ) );
1076
1077 m_actionTableInsertCol = new TDEAction( i18n( "I&nsert Column..." ), "insert_table_col", 0,
1078 this, TQ_SLOT( tableInsertCol() ),
1079 actionCollection(), "table_inscol" );
1080 m_actionTableInsertCol->setToolTip( i18n( "Insert one or more columns into the current table." ) );
1081 m_actionTableInsertCol->setWhatsThis( i18n( "Insert one or more columns into the current table." ) );
1082
1083 m_actionTableDelRow = new TDEAction( 0, "delete_table_row", 0,
1084 this, TQ_SLOT( tableDeleteRow() ),
1085 actionCollection(), "table_delrow" );
1086 m_actionTableDelRow->setToolTip( i18n( "Delete selected rows from the current table." ) );
1087 m_actionTableDelRow->setWhatsThis( i18n( "Delete selected rows from the current table." ) );
1088
1089 m_actionTableDelCol = new TDEAction( 0, "delete_table_col", 0,
1090 this, TQ_SLOT( tableDeleteCol() ),
1091 actionCollection(), "table_delcol" );
1092 m_actionTableDelCol->setToolTip( i18n( "Delete selected columns from the current table." ) );
1093 m_actionTableDelCol->setWhatsThis( i18n( "Delete selected columns from the current table." ) );
1094
1095 m_actionTableResizeCol = new TDEAction( i18n( "Resize Column..." ), 0,
1096 this, TQ_SLOT( tableResizeCol() ),
1097 actionCollection(), "table_resizecol" );
1098 m_actionTableResizeCol->setToolTip( i18n( "Change the width of the currently selected column." ) );
1099 m_actionTableResizeCol->setWhatsThis( i18n( "Change the width of the currently selected column." ) );
1100
1101
1102 m_actionTableJoinCells = new TDEAction( i18n( "&Join Cells" ), 0,
1103 this, TQ_SLOT( tableJoinCells() ),
1104 actionCollection(), "table_joincells" );
1105 m_actionTableJoinCells->setToolTip( i18n( "Join two or more cells into one large cell." ) );
1106 m_actionTableJoinCells->setWhatsThis( i18n( "Join two or more cells into one large cell.<p>This is a good way to create titles and labels within a table." ) );
1107
1108 m_actionTableSplitCells= new TDEAction( i18n( "&Split Cell..." ), 0,
1109 this, TQ_SLOT( tableSplitCells() ),
1110 actionCollection(), "table_splitcells" );
1111 m_actionTableSplitCells->setToolTip( i18n( "Split one cell into two or more cells." ) );
1112 m_actionTableSplitCells->setWhatsThis( i18n( "Split one cell into two or more cells.<p>Cells can be split horizontally, vertically or both directions at once." ) );
1113
1114 m_actionTableProtectCells= new TDEToggleAction( i18n( "Protect Cells" ), 0, 0, 0,
1115 actionCollection(), "table_protectcells" );
1116 m_actionTableProtectCells->setToolTip( i18n( "Prevent changes to content of selected cells." ) );
1117 connect (m_actionTableProtectCells, TQ_SIGNAL( toggled(bool) ), this,
1118 TQ_SLOT( tableProtectCells(bool) ));
1119
1120 m_actionTableProtectCells->setWhatsThis( i18n( "Toggles cell protection on and off.<br><br>When cell protection is on, the user can not alter the content or formatting of the text within the cell." ) );
1121
1122 m_actionTableUngroup = new TDEAction( i18n( "&Ungroup Table" ), 0,
1123 this, TQ_SLOT( tableUngroupTable() ),
1124 actionCollection(), "table_ungroup" );
1125 m_actionTableUngroup->setToolTip( i18n( "Break a table into individual frames." ) );
1126 m_actionTableUngroup->setWhatsThis( i18n( "Break a table into individual frames<p>Each frame can be moved independently around the page." ) );
1127
1128 m_actionTableDelete = new TDEAction( i18n( "Delete &Table" ), 0,
1129 this, TQ_SLOT( tableDelete() ),
1130 actionCollection(), "table_delete" );
1131 m_actionTableDelete->setToolTip( i18n( "Delete the entire table." ) );
1132 m_actionTableDelete->setWhatsThis( i18n( "Deletes all cells and the content within the cells of the currently selected table." ) );
1133
1134
1135 m_actionTableStylist = new TDEAction( i18n( "T&able Style Manager" ), 0,
1136 this, TQ_SLOT( tableStylist() ),
1137 actionCollection(), "table_stylist" );
1138 m_actionTableStylist->setToolTip( i18n( "Change attributes of tablestyles." ) );
1139 m_actionTableStylist->setWhatsThis( i18n( "Change textstyle and framestyle of the tablestyles.<p>Multiple tablestyles can be changed using the dialog box." ) );
1140
1141 m_actionTableStyleMenu = new TDEActionMenu( i18n( "Table&style" ), 0,
1142 actionCollection(), "table_stylemenu" );
1143 m_actionTableStyle = new TDESelectAction( i18n( "Table&style" ), 0,
1144 actionCollection(), "table_style" );
1145 connect( m_actionTableStyle, TQ_SIGNAL( activated( int ) ),
1146 this, TQ_SLOT( tableStyleSelected( int ) ) );
1147 updateTableStyleList();
1148
1149 m_actionConvertTableToText = new TDEAction( i18n( "Convert Table to Text" ), 0,
1150 this, TQ_SLOT( convertTableToText() ),
1151 actionCollection(), "convert_table_to_text" );
1152 m_actionSortText= new TDEAction( i18n( "Sort Text..." ), 0,
1153 this, TQ_SLOT( sortText() ),
1154 actionCollection(), "sort_text" );
1155
1156 m_actionAddPersonalExpression= new TDEAction( i18n( "Add Expression" ), 0,
1157 this, TQ_SLOT( addPersonalExpression() ),
1158 actionCollection(), "add_personal_expression" );
1159
1160
1161 // ---------------------- Tools menu
1162
1163
1164 m_actionAllowAutoFormat = new TDEToggleAction( i18n( "Enable Autocorrection" ), 0,
1165 this, TQ_SLOT( slotAllowAutoFormat() ),
1166 actionCollection(), "enable_autocorrection" );
1167 m_actionAllowAutoFormat->setCheckedState(i18n("Disable Autocorrection"));
1168 m_actionAllowAutoFormat->setToolTip( i18n( "Toggle autocorrection on and off." ) );
1169 m_actionAllowAutoFormat->setWhatsThis( i18n( "Toggle autocorrection on and off." ) );
1170
1171 m_actionAutoFormat = new TDEAction( i18n( "Configure &Autocorrection..." ), 0,
1172 this, TQ_SLOT( extraAutoFormat() ),
1173 actionCollection(), "configure_autocorrection" );
1174 m_actionAutoFormat->setToolTip( i18n( "Change autocorrection options." ) );
1175 m_actionAutoFormat->setWhatsThis( i18n( "Change autocorrection options including:<p> <UL><LI><P>exceptions to autocorrection</P> <LI><P>add/remove autocorrection replacement text</P> <LI><P>and basic autocorrection options</P>." ) );
1176
1177 m_actionEditCustomVarsEdit = new TDEAction( i18n( "Custom &Variables..." ), 0,
1178 this, TQ_SLOT( editCustomVars() ), // TODO: new dialog w add etc.
1179 actionCollection(), "custom_vars" );
1180
1181 m_actionEditPersonnalExpr=new TDEAction( i18n( "Edit &Personal Expressions..." ), 0,
1182 this, TQ_SLOT( editPersonalExpr() ),
1183 actionCollection(), "personal_expr" );
1184 m_actionEditPersonnalExpr->setToolTip( i18n( "Add or change one or more personal expressions." ) );
1185 m_actionEditPersonnalExpr->setWhatsThis( i18n( "Add or change one or more personal expressions.<p>Personal expressions are a way to quickly insert commonly used phrases or text into your document." ) );
1186
1187 m_actionChangeCase=new TDEAction( i18n( "Change Case..." ), 0,
1188 this, TQ_SLOT( changeCaseOfText() ),
1189 actionCollection(), "change_case" );
1190 m_actionChangeCase->setToolTip( i18n( "Alter the capitalization of selected text." ) );
1191 m_actionChangeCase->setWhatsThis( i18n( "Alter the capitalization of selected text to one of five pre-defined patterns.<p>You can also switch all letters from upper case to lower case and from lower case to upper case in one move." ) );
1192
1193 //------------------------ Settings menu
1194 m_actionConfigure = KStdAction::preferences(this, TQ_SLOT(configure()), actionCollection(), "configure" );
1195
1196 //------------------------ Menu frameSet
1197 TDEAction *actionChangePicture=new TDEAction( i18n( "Change Picture..." ),"frame_image",0,
1198 this, TQ_SLOT( changePicture() ),
1199 actionCollection(), "change_picture" );
1200 actionChangePicture->setToolTip( i18n( "Change the picture in the currently selected frame." ) );
1201 actionChangePicture->setWhatsThis( i18n( "You can specify a different picture in the current frame.<br><br>KWord automatically resizes the new picture to fit within the old frame." ) );
1202
1203 m_actionConfigureHeaderFooter=new TDEAction( i18n( "Configure Header/Footer..." ), 0,
1204 this, TQ_SLOT( configureHeaderFooter() ),
1205 actionCollection(), "configure_headerfooter" );
1206 m_actionConfigureHeaderFooter->setToolTip( i18n( "Configure the currently selected header or footer." ) );
1207 m_actionConfigureHeaderFooter->setWhatsThis( i18n( "Configure the currently selected header or footer." ) );
1208
1209 m_actionInlineFrame = new TDEToggleAction( i18n( "Inline Frame" ), 0,
1210 this, TQ_SLOT( inlineFrame() ),
1211 actionCollection(), "inline_frame" );
1212 m_actionInlineFrame->setToolTip( i18n( "Convert current frame to an inline frame." ) );
1213 m_actionInlineFrame->setWhatsThis( i18n( "Convert the current frame to an inline frame.<br><br>Place the inline frame within the text at the point nearest to the frames current position." ) );
1214
1215 m_actionOpenLink = new TDEAction( i18n( "Open Link" ), 0,
1216 this, TQ_SLOT( openLink() ),
1217 actionCollection(), "open_link" );
1218 m_actionOpenLink->setToolTip( i18n( "Open the link with the appropriate application." ) );
1219 m_actionOpenLink->setWhatsThis( i18n( "Open the link with the appropriate application.<br><br>Web addresses are opened in a browser.<br>Email addresses begin a new message addressed to the link.<br>File links are opened by the appropriate viewer or editor." ) );
1220
1221 m_actionChangeLink=new TDEAction( i18n("Change Link..."), 0,
1222 this, TQ_SLOT(changeLink()),
1223 actionCollection(), "change_link");
1224 m_actionChangeLink->setToolTip( i18n( "Change the content of the currently selected link." ) );
1225 m_actionChangeLink->setWhatsThis( i18n( "Change the details of the currently selected link." ) );
1226
1227 m_actionCopyLink = new TDEAction( i18n( "Copy Link" ), 0,
1228 this, TQ_SLOT( copyLink() ),
1229 actionCollection(), "copy_link" );
1230
1231 m_actionAddLinkToBookmak = new TDEAction( i18n( "Add to Bookmark" ), 0,
1232 this, TQ_SLOT( addToBookmark() ),
1233 actionCollection(), "add_to_bookmark" );
1234
1235 m_actionRemoveLink = new TDEAction( i18n( "Remove Link" ), 0,
1236 this, TQ_SLOT( removeLink() ),
1237 actionCollection(), "remove_link" );
1238
1239 m_actionShowDocStruct = new TDEToggleAction( i18n( "Show Doc Structure" ), 0,
1240 this, TQ_SLOT( showDocStructure() ),
1241 actionCollection(), "show_docstruct" );
1242 m_actionShowDocStruct->setCheckedState(i18n("Hide Doc Structure"));
1243 m_actionShowDocStruct->setToolTip( i18n( "Open document structure sidebar." ) );
1244 m_actionShowDocStruct->setWhatsThis( i18n( "Open document structure sidebar.<p>This sidebar helps you organize your document and quickly find pictures, tables etc." ) );
1245
1246 m_actionShowRuler = new TDEToggleAction( i18n( "Show Rulers" ), 0,
1247 this, TQ_SLOT( showRuler() ),
1248 actionCollection(), "show_ruler" );
1249 m_actionShowRuler->setCheckedState(i18n("Hide Rulers"));
1250 m_actionShowRuler->setToolTip( i18n( "Shows or hides rulers." ) );
1251 m_actionShowRuler->setWhatsThis( i18n("The rulers are the white measuring spaces top and left of the "
1252 "document. The rulers show the position and width of pages and of frames and can "
1253 "be used to position tabulators among others.<p>Uncheck this to disable "
1254 "the rulers from being displayed." ) );
1255
1256 m_actionViewShowGrid = new TDEToggleAction( i18n( "Show Grid" ), 0,
1257 this, TQ_SLOT( viewGrid() ),
1258 actionCollection(), "view_grid" );
1259 m_actionViewShowGrid->setCheckedState(i18n("Hide Grid"));
1260
1261 m_actionViewSnapToGrid= new TDEToggleAction( i18n( "Snap to Grid" ), 0,
1262 this, TQ_SLOT(viewSnapToGrid() ),
1263 actionCollection(), "view_snaptogrid" );
1264
1265 m_actionConfigureCompletion = new TDEAction( i18n( "Configure C&ompletion..." ), 0,
1266 this, TQ_SLOT( configureCompletion() ),
1267 actionCollection(), "configure_completion" );
1268 m_actionConfigureCompletion->setToolTip( i18n( "Change the words and options for autocompletion." ) );
1269 m_actionConfigureCompletion->setWhatsThis( i18n( "Add words or change the options for autocompletion." ) );
1270
1271
1272 // ------------------- Actions with a key binding and no GUI item
1273 new TDEAction( i18n( "Insert Non-Breaking Space" ), TQt::CTRL+TQt::Key_Space,
1274 this, TQ_SLOT( slotNonbreakingSpace() ), actionCollection(), "nonbreaking_space" );
1275 new TDEAction( i18n( "Insert Non-Breaking Hyphen" ), TQt::CTRL+TQt::SHIFT+TQt::Key_Minus,
1276 this, TQ_SLOT( slotNonbreakingHyphen() ), actionCollection(), "nonbreaking_hyphen" );
1277 new TDEAction( i18n( "Insert Soft Hyphen" ), TQt::CTRL+TQt::Key_Minus,
1278 this, TQ_SLOT( slotSoftHyphen() ), actionCollection(), "soft_hyphen" );
1279 new TDEAction( i18n( "Line Break" ), TQt::SHIFT+TQt::Key_Return,
1280 this, TQ_SLOT( slotLineBreak() ), actionCollection(), "line_break" );
1281
1282 new TDEAction( i18n( "Completion" ), TDEStdAccel::shortcut(TDEStdAccel::TextCompletion), this, TQ_SLOT( slotCompletion() ), actionCollection(), "completion" );
1283
1284 new TDEAction( i18n( "Increase Numbering Level" ), TQt::ALT+TQt::Key_Right,
1285 this, TQ_SLOT( slotIncreaseNumberingLevel() ), actionCollection(), "increase_numbering_level" );
1286 new TDEAction( i18n( "Decrease Numbering Level" ), TQt::ALT+TQt::Key_Left,
1287 this, TQ_SLOT( slotDecreaseNumberingLevel() ), actionCollection(), "decrease_numbering_level" );
1288
1289
1290 // --------
1291 m_actionEditCustomVars = new TDEAction( i18n( "Edit Variable..." ), 0,
1292 this, TQ_SLOT( editCustomVariable() ),
1293 actionCollection(), "edit_customvars" );
1294 m_actionApplyAutoFormat= new TDEAction( i18n( "Apply Autocorrection" ), 0,
1295 this, TQ_SLOT( applyAutoFormat() ),
1296 actionCollection(), "apply_autoformat" );
1297 m_actionApplyAutoFormat->setToolTip( i18n( "Manually force KWord to scan the entire document and apply autocorrection." ) );
1298 m_actionApplyAutoFormat->setWhatsThis( i18n( "Manually force KWord to scan the entire document and apply autocorrection." ) );
1299
1300 m_actionCreateStyleFromSelection = new TDEAction( i18n( "Create Style From Selection..." ), 0,
1301 this, TQ_SLOT( createStyleFromSelection()),
1302 actionCollection(), "create_style" );
1303 m_actionCreateStyleFromSelection->setToolTip( i18n( "Create a new style based on the currently selected text." ) );
1304 m_actionCreateStyleFromSelection->setWhatsThis( i18n( "Create a new style based on the currently selected text." ) ); // ## "on the current paragraph, taking the formatting from where the cursor is. Selecting text isn't even needed."
1305
1306 m_actionConfigureFootEndNote = new TDEAction( i18n( "&Footnote..." ), 0,
1307 this, TQ_SLOT( configureFootEndNote()),
1308 actionCollection(), "format_footendnote" );
1309 m_actionConfigureFootEndNote->setToolTip( i18n( "Change the look of footnotes." ) );
1310 m_actionConfigureFootEndNote->setWhatsThis( i18n( "Change the look of footnotes." ) );
1311
1312 m_actionEditFootEndNote= new TDEAction( i18n("Edit Footnote"), 0,
1313 this, TQ_SLOT( editFootEndNote()),
1314 actionCollection(), "edit_footendnote" );
1315 m_actionEditFootEndNote->setToolTip( i18n( "Change the content of the currently selected footnote." ) );
1316 m_actionEditFootEndNote->setWhatsThis( i18n( "Change the content of the currently selected footnote." ) );
1317
1318
1319 m_actionChangeFootNoteType = new TDEAction( i18n("Change Footnote/Endnote Parameter"), 0,
1320 this, TQ_SLOT( changeFootNoteType() ),
1321 actionCollection(), "change_footendtype");
1322
1323 m_actionSavePicture= new TDEAction( i18n("Save Picture As..."), 0,
1324 this, TQ_SLOT( savePicture() ),
1325 actionCollection(), "save_picture");
1326 m_actionSavePicture->setToolTip( i18n( "Save the picture in a separate file." ) );
1327 m_actionSavePicture->setWhatsThis( i18n( "Save the picture in the currently selected frame in a separate file, outside the KWord document." ) );
1328
1329 m_actionAllowBgSpellCheck = new TDEToggleAction( i18n( "Autospellcheck" ), 0,
1330 this, TQ_SLOT( autoSpellCheck() ),
1331 actionCollection(), "tool_auto_spellcheck" );
1332
1333
1334 m_actionGoToFootEndNote = new TDEAction( TQString() /*set dynamically*/, 0,
1335 this, TQ_SLOT( goToFootEndNote() ),
1336 actionCollection(), "goto_footendnote" );
1337
1338 // Document Structure Area popup menu.
1339 m_actionDocStructEdit = new TDEAction( i18n( "Edit Text" ), 0,
1340 this, TQ_SLOT( docStructEdit() ),
1341 actionCollection(), "docstruct_edit" );
1342 m_actionDocStructSpeak = new TDEAction( i18n("Speak Text" ), 0,
1343 this, TQ_SLOT( docStructSpeak() ),
1344 actionCollection(), "docstruct_speak" );
1345 m_actionDocStructSelect = new TDEAction( i18n( "Show" ), 0,
1346 this, TQ_SLOT( docStructSelect() ),
1347 actionCollection(), "docstruct_select" );
1348 m_actionDocStructDelete = new TDEAction( i18n( "Delete Frame" ), 0,
1349 this, TQ_SLOT( docStructDelete() ),
1350 actionCollection(), "docstruct_delete" );
1351 m_actionDocStructProperties = new TDEAction( i18n( "Properties" ), 0,
1352 this, TQ_SLOT( docStructProperties() ),
1353 actionCollection(), "docstruct_properties" );
1354
1355 m_actionAddBookmark= new TDEAction( i18n( "&Bookmark..." ), 0,
1356 this, TQ_SLOT( addBookmark() ),
1357 actionCollection(), "add_bookmark" );
1358 m_actionSelectBookmark= new TDEAction( i18n( "Select &Bookmark..." ), 0,
1359 this, TQ_SLOT( selectBookmark() ),
1360 actionCollection(), "select_bookmark" );
1361
1362 m_actionImportStyle= new TDEAction( i18n( "Import Styles..." ), 0,
1363 this, TQ_SLOT( importStyle() ),
1364 actionCollection(), "import_style" );
1365
1366 m_actionCreateFrameStyle = new TDEAction( i18n( "&Create Framestyle From Frame..." ), 0,
1367 this, TQ_SLOT( createFrameStyle()),
1368 actionCollection(), "create_framestyle" );
1369 m_actionCreateFrameStyle->setToolTip( i18n( "Create a new style based on the currently selected frame." ) );
1370 m_actionCreateFrameStyle->setWhatsThis( i18n( "Create a new framestyle based on the currently selected frame." ) );
1371
1372#if 0 // re-enable after fixing
1373 m_actionInsertDirectCursor = new TDEToggleAction( i18n( "Type Anywhere Cursor" ), 0,
1374 this, TQ_SLOT( insertDirectCursor() ),
1375 actionCollection(), "direct_cursor" );
1376#endif
1377
1378 m_actionConvertToTextBox = new TDEAction( i18n( "Convert to Text Box" ), 0,
1379 this, TQ_SLOT( convertToTextBox() ),
1380 actionCollection(), "convert_to_text_box" );
1381
1382
1383 m_actionSpellIgnoreAll = new TDEAction( i18n( "Ignore All" ), 0,
1384 this, TQ_SLOT( slotAddIgnoreAllWord() ),
1385 actionCollection(), "ignore_all" );
1386
1387 m_actionAddWordToPersonalDictionary=new TDEAction( i18n( "Add Word to Dictionary" ),0,
1388 this, TQ_SLOT( addWordToDictionary() ),
1389 actionCollection(), "add_word_to_dictionary" );
1390
1391 m_actionEmbeddedStoreInternal=new TDEToggleAction( i18n( "Store Document Internally" ),0,
1392 this, TQ_SLOT( embeddedStoreInternal() ),
1393 actionCollection(), "embedded_store_internal" );
1394
1395 m_actionGoToDocumentStructure=new TDEAction( i18n( "Go to Document Structure" ), TDEShortcut("Alt+1"),
1396 this, TQ_SLOT( goToDocumentStructure() ),
1397 actionCollection(), "goto_document_structure" );
1398 m_actionGoToDocument=new TDEAction( i18n( "Go to Document" ), TDEShortcut("Alt+2"),
1399 this, TQ_SLOT( goToDocument() ),
1400 actionCollection(), "goto_document" );
1401
1402 // For RMB inside a cell, see KWFrameView::showPopup
1403 // This isn't a dynamic list; it's only plugged/unplugged depending on the context.
1404 // If you change the contents of that list, check ~KWView.
1405 m_tableActionList.append( new TDEActionSeparator(actionCollection()) );
1406 m_tableActionList.append( m_actionTableInsertRow );
1407 m_tableActionList.append( m_actionTableDelRow );
1408 m_tableActionList.append( m_actionTableInsertCol );
1409 m_tableActionList.append( m_actionTableDelCol );
1410}
1411
1412void KWView::refreshMenuExpression()
1413{
1414 loadexpressionActions( m_actionInsertExpression);
1415}
1416
1417void KWView::updateGridButton()
1418{
1419 m_actionViewShowGrid->setChecked( m_doc->showGrid() );
1420 m_actionViewSnapToGrid->setChecked ( m_doc->snapToGrid() );
1421}
1422
1423void KWView::loadexpressionActions( TDEActionMenu * parentMenu)
1424{
1425 TDEActionPtrList lst = actionCollection()->actions("expression-action");
1426 TQValueList<TDEAction *> actions = lst;
1427 TQValueList<TDEAction *>::ConstIterator it = lst.begin();
1428 TQValueList<TDEAction *>::ConstIterator end = lst.end();
1429 // Delete all actions but keep their shortcuts in mind
1430 TQMap<TQString, TDEShortcut> personalShortCuts;
1431 for (; it != end; ++it )
1432 {
1433 personalShortCuts.insert( (*it)->text(), (*it)->shortcut() );
1434 delete *it;
1435 }
1436
1437 parentMenu->popupMenu()->clear();
1438 TQStringList path = m_doc->personalExpressionPath();
1439 TQStringList files;
1440 for ( TQStringList::Iterator it = path.begin(); it != path.end(); ++it )
1441 {
1442 TQDir dir( *it );
1443 if ( dir.exists() )
1444 {
1445 TQStringList tmp = dir.entryList("*.xml");
1446 for ( TQStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2 )
1447 files.append( TQString( (*it) + (*it2) ));
1448 }
1449 }
1450
1451 //TQStringList files = KWFactory::instance()->dirs()->findAllResources( "expression", "*.xml", true );
1452 int i = 0;
1453 int nbFile = 0;
1454 for( TQStringList::Iterator it = files.begin(); it != files.end(); ++it,nbFile++ )
1455 createExpressionActions( parentMenu,*it, i,(nbFile<(int)files.count()-1), personalShortCuts );
1456}
1457
1458void KWView::createExpressionActions( TDEActionMenu * parentMenu,const TQString& filename,int &i, bool insertSepar, const TQMap<TQString, TDEShortcut>& personalShortCut )
1459{
1460 TQFile file( filename );
1461 if ( !file.exists() || !file.open( IO_ReadOnly ) )
1462 return;
1463
1464 TQDomDocument doc;
1465 doc.setContent( &file );
1466 file.close();
1467
1468 bool expressionExist =false;
1469 TQDomNode n = doc.documentElement().firstChild();
1470 for( ; !n.isNull(); n = n.nextSibling() )
1471 {
1472 if ( n.isElement() )
1473 {
1474 TQDomElement e = n.toElement();
1475 if ( e.tagName() == "Type" )
1476 {
1477 expressionExist =true;
1478 TQString group = i18n( e.namedItem( "TypeName" ).toElement().text().utf8() );
1479 TDEActionMenu * subMenu = new TDEActionMenu( group, actionCollection() );
1480 parentMenu->insert( subMenu );
1481
1482 TQDomNode n2 = e.firstChild();
1483 for( ; !n2.isNull(); n2 = n2.nextSibling() )
1484 {
1485
1486 if ( n2.isElement() )
1487 {
1488 TQDomElement e2 = n2.toElement();
1489 if ( e2.tagName() == "Expression" )
1490 {
1491 TQString text = i18n( e2.namedItem( "Text" ).toElement().text().utf8() );
1492 TDEAction * act = new TDEAction( text, 0, this, TQ_SLOT( insertExpression() ),
1493 actionCollection(),
1494 TQString("expression-action_%1").arg(i).latin1() );
1495 if ( personalShortCut.contains(text) )
1496 act->setShortcut( personalShortCut[text] );
1497 i++;
1498 act->setGroup("expression-action");
1499 subMenu->insert( act );
1500 }
1501 }
1502 }
1503 }
1504 }
1505 }
1506 if(expressionExist && insertSepar)
1507 parentMenu->popupMenu()->insertSeparator();
1508}
1509
1510void KWView::insertExpression()
1511{
1512 KWTextFrameSetEdit * edit = currentTextEdit();
1513 if ( edit )
1514 {
1515 TDEAction * act = (TDEAction *)(sender());
1516 edit->insertExpression(act->text());
1517 }
1518}
1519
1520
1521void KWView::addVariableActions( int type, const TQStringList & texts,
1522 TDEActionMenu * parentMenu, const TQString & menuText )
1523{
1524 // Single items go directly into parentMenu.
1525 // For multiple items we create a submenu.
1526 if ( texts.count() > 1 && !menuText.isEmpty() )
1527 {
1528 TDEActionMenu * subMenu = new TDEActionMenu( menuText, actionCollection() );
1529 parentMenu->insert( subMenu );
1530 parentMenu = subMenu;
1531 }
1532 TQStringList::ConstIterator it = texts.begin();
1533 for ( int i = 0; it != texts.end() ; ++it, ++i )
1534 {
1535 if ( !(*it).isEmpty() ) // in case of removed subtypes or placeholders
1536 {
1537 VariableDef v;
1538 v.type = type;
1539 v.subtype = i;
1540 TQCString actionName;
1541 actionName.sprintf( "var-action-%d-%d", type, i );
1542 TDEAction * act = new TDEAction( (*it), 0, this, TQ_SLOT( insertVariable() ),
1543 actionCollection(), actionName );
1544 // Mainly for KEditToolbar
1545 act->setToolTip( i18n( "Insert variable \"%1\" into the text" ).arg( *it ) );
1546 m_variableDefMap.insert( act, v );
1547 parentMenu->insert( act );
1548 }
1549 }
1550}
1551
1552void KWView::refreshCustomMenu()
1553{
1554 TDEActionPtrList lst2 = actionCollection()->actions("custom-variable-action");
1555 TQValueList<TDEAction *> actions = lst2;
1556 TQValueList<TDEAction *>::ConstIterator it2 = lst2.begin();
1557 TQValueList<TDEAction *>::ConstIterator end = lst2.end();
1558 TQMap<TQString, TDEShortcut> shortCuts;
1559
1560 for (; it2 != end; ++it2 )
1561 {
1562 shortCuts.insert((*it2)->text(), (*it2)->shortcut());
1563 delete *it2;
1564 }
1565
1566 delete m_actionInsertCustom;
1567 m_actionInsertCustom = new TDEActionMenu( i18n( "&Custom" ),
1568 actionCollection(), "insert_custom" );
1569 actionInsertVariable->insert(m_actionInsertCustom, 0);
1570
1571 m_actionInsertCustom->popupMenu()->clear();
1572 TQPtrListIterator<KoVariable> it( m_doc->variableCollection()->getVariables() );
1573 TDEAction * act=0;
1574 TQStringList lst;
1575 TQString varName;
1576 int i = 0;
1577 for ( ; it.current() ; ++it )
1578 {
1579 KoVariable *var = it.current();
1580 if ( var->type() == VT_CUSTOM )
1581 {
1582 varName=( (KoCustomVariable*) var )->name();
1583 if ( !lst.contains( varName) )
1584 {
1585 lst.append( varName );
1586 TQCString name = TQString("custom-action_%1").arg(i).latin1();
1587 act = new TDEAction( varName, shortCuts[varName], this, TQ_SLOT( insertCustomVariable() ),actionCollection(), name );
1588 act->setGroup( "custom-variable-action" );
1589 m_actionInsertCustom->insert( act );
1590 i++;
1591 }
1592 }
1593 }
1594 bool state=!lst.isEmpty();
1595 if(state)
1596 m_actionInsertCustom->popupMenu()->insertSeparator();
1597
1598 act = new TDEAction( i18n("New..."), 0, this, TQ_SLOT( insertNewCustomVariable() ), actionCollection(),TQString("custom-action_%1").arg(i).latin1());
1599 act->setGroup( "custom-variable-action" );
1600
1601
1602 m_actionEditCustomVarsEdit->setEnabled( state );
1603
1604 m_actionInsertCustom->insert( act );
1605
1606}
1607
1608
1609void KWView::insertCustomVariable()
1610{
1611 KWTextFrameSetEdit * edit = currentTextEdit();
1612 if ( edit )
1613 {
1614 TDEAction * act = (TDEAction *)(sender());
1615 edit->insertCustomVariable(act->text());
1616 }
1617}
1618
1619void KWView::insertNewCustomVariable()
1620{
1621 KWTextFrameSetEdit * edit = currentTextEdit();
1622 if ( edit )
1623 edit->insertVariable( VT_CUSTOM, 0 );
1624}
1625
1626void KWView::showFormulaToolbar( bool show )
1627{
1628 m_doc->formulaDocument()->setEnabled( show );
1629 m_doc->formulaDocumentWrapper()->enableMatrixActions( show );
1630 m_doc->formulaDocumentWrapper()->getSyntaxHighlightingAction()->setEnabled( true );
1631 if(shell())
1632 shell()->showToolbar( "formula_toolbar", show );
1633}
1634
1635void KWView::updatePageInfo()
1636{
1637 if ( m_sbPageLabel )
1638 {
1639 KWFrameSetEdit * edit = m_gui->canvasWidget()->currentFrameSetEdit();
1640 if ( edit && edit->currentFrame() )
1641 m_currentPage = m_doc->pageManager()->page(edit->currentFrame());
1642 else {
1643 KWFrameView *view = frameViewManager()->selectedFrame();
1644 if(view)
1645 m_currentPage = m_doc->pageManager()->page(view->frame());
1646 }
1647 /*kdDebug() << (void*)this << " KWView::updatePageInfo "
1648 << " edit: " << edit << " " << ( edit?edit->frameSet()->name():TQString())
1649 << " currentFrame: " << (edit?edit->currentFrame():0L)
1650 << " m_currentPage=" << currentPage() << " m_sbPageLabel=" << m_sbPageLabel
1651 << endl;*/
1652
1653 TQString oldText = m_sbPageLabel->text();
1654 TQString newText;
1655 if ( viewMode()->hasPages() )
1656 newText = ' ' + i18n( "Page %1 of %2" ).arg(m_currentPage->pageNumber())
1657 .arg(m_doc->pageCount()) + ' ';
1658
1659 if ( newText != oldText )
1660 {
1661 m_sbPageLabel->setText( newText );
1662 // Need to repaint immediately. Otherwise when deleting 100 pages
1663 // at once, there's no feedback.
1664 m_sbPageLabel->repaint();
1665 }
1666 }
1667 slotUpdateRuler();
1668}
1669
1670void KWView::numPagesChanged()
1671{
1672 docStructChanged(TextFrames);
1673 updatePageInfo();
1674 int pages = m_doc->pageCount();
1675 kdDebug() << pages << " " << (m_doc->processingType() == KWDocument::DTP) << endl;
1676 refreshDeletePageAction();
1677}
1678
1679void KWView::updateFrameStatusBarItem()
1680{
1681 KStatusBar * sb = statusBar();
1682 int nbFrame=frameViewManager()->selectedFrames().count();
1683 if ( m_doc->showStatusBar() && sb && nbFrame > 0 )
1684 {
1685 if ( nbFrame == 1 )
1686 {
1687 KoUnit::Unit unit = m_doc->unit();
1688 TQString unitName = m_doc->unitName();
1689 KWFrame * frame = frameViewManager()->selectedFrames()[0]->frame();
1690 m_sbFramesLabel->setText( ' ' + i18n( "Statusbar info", "%1: %2, %3 - %4, %5 (width: %6, height: %7)" )
1691 .arg( frame->frameSet()->name() )
1692 .arg( KoUnit::toUserStringValue( frame->left(), unit ) )
1693 .arg( KoUnit::toUserStringValue( frame->top() - m_doc->pageManager()->topOfPage(
1694 m_doc->pageManager()->pageNumber(frame->rect()) ), unit) )
1695 .arg( KoUnit::toUserStringValue( frame->right(), unit ) )
1696 .arg( KoUnit::toUserStringValue( frame->bottom(), unit ) )
1697 .arg( KoUnit::toUserStringValue( frame->width(), unit ) )
1698 .arg( KoUnit::toUserStringValue( frame->height(), unit ) ) );
1699 } else
1700 m_sbFramesLabel->setText( ' ' + i18n( "%1 frames selected" ).arg( nbFrame ) );
1701 }
1702 else if ( sb && m_sbFramesLabel )
1703 m_sbFramesLabel->setText( TQString() );
1704}
1705
1706void KWView::setTemporaryStatusBarText(const TQString &text)
1707{
1708 if ( statusBar() && m_sbFramesLabel )
1709 m_sbFramesLabel->setText( text );
1710}
1711
1712void KWView::clipboardDataChanged()
1713{
1714 if ( !m_gui || !m_doc->isReadWrite() )
1715 {
1716 m_actionEditPaste->setEnabled(false);
1717 return;
1718 }
1719 KWFrameSetEdit * edit = m_gui->canvasWidget()->currentFrameSetEdit();
1720 // Is there plain text in the clipboard ?
1721 if ( edit && !TQApplication::clipboard()->text().isEmpty() )
1722 {
1723 m_actionEditPaste->setEnabled(true);
1724 return;
1725 }
1726 TQMimeSource *data = TQApplication::clipboard()->data();
1727 const int provides = checkClipboard( data );
1728 if ( provides & ( ProvidesImage | ProvidesOasis | ProvidesFormula ) )
1729 m_actionEditPaste->setEnabled( true );
1730 else
1731 {
1732 // Plain text requires a framesetedit
1733 m_actionEditPaste->setEnabled( edit && ( provides & ProvidesPlainText ) );
1734 }
1735}
1736
1737int KWView::checkClipboard( TQMimeSource *data )
1738{
1739 int provides = 0;
1740 TQValueList<TQCString> formats;
1741 const char* fmt;
1742 for (int i=0; (fmt = data->format(i)); i++)
1743 formats.append( TQCString( fmt ) );
1744
1745 if ( TQImageDrag::canDecode( data ) )
1746 provides |= ProvidesImage;
1747 if ( formats.findIndex( KFormula::MimeSource::selectionMimeType() ) != -1 )
1748 provides |= ProvidesFormula;
1749 if ( formats.findIndex( "text/plain" ) != -1 )
1750 provides |= ProvidesPlainText;
1751 TQCString returnedTypeMime = KoTextObject::providesOasis( data );
1752 if ( !returnedTypeMime.isEmpty() )
1753 provides |= ProvidesOasis;
1754 //kdDebug(32001) << "KWView::checkClipboard provides=" << provides << endl;
1755 return provides;
1756}
1757
1758/*=========================== file print =======================*/
1759void KWView::setupPrinter( KPrinter &prt )
1760{
1761 //recalc time and date variable before to print
1762 //it's necessary otherwise we print a document
1763 //with a bad date and time
1764 //TODO call once this function
1765 m_doc->recalcVariables( VT_TIME );
1766 m_doc->recalcVariables( VT_DATE );
1767 m_doc->recalcVariables( VT_STATISTIC );
1768
1769 prt.setPageSelection( KPrinter::ApplicationSide );
1770 prt.setCurrentPage( currentPage() );
1771 prt.setMinMax( m_doc->startPage(), m_doc->lastPage() );
1772
1773 KoPageLayout pgLayout = m_doc->pageLayout();
1774
1775 prt.setPageSize( static_cast<KPrinter::PageSize>( KoPageFormat::printerPageSize( pgLayout.format ) ) );
1776
1777 if ( pgLayout.orientation == PG_LANDSCAPE || pgLayout.format == PG_SCREEN )
1778 prt.setOrientation( KPrinter::Landscape );
1779 else
1780 prt.setOrientation( KPrinter::Portrait );
1781}
1782
1783void KWView::print( KPrinter &prt )
1784{
1785 bool displayFieldCode = m_doc->variableCollection()->variableSetting()->displayFieldCode();
1786 if ( displayFieldCode )
1787 {
1788 m_doc->variableCollection()->variableSetting()->setDisplayFieldCode(false);
1789 m_doc->recalcVariables( VT_ALL );
1790 }
1791
1792// Don't repaint behind the print dialog until we're done zooming/unzooming the doc
1793 m_gui->canvasWidget()->setUpdatesEnabled(false);
1794 m_gui->canvasWidget()->viewport()->setCursor( waitCursor );
1795
1796 prt.setFullPage( true );
1797
1798 // ### HACK: disable zooming-when-printing if embedded parts are used.
1799 // No koffice app supports zooming in paintContent currently.
1800 // Disable in ALL cases now
1801 bool doZoom = false;
1802 /*TQPtrListIterator<KWFrameSet> fit = m_doc->framesetsIterator();
1803 for ( ; fit.current() && doZoom ; ++fit )
1804 if ( fit.current()->type() == FT_PART )
1805 doZoom = false;*/
1806
1807 int oldZoom = m_doc->zoom();
1808 // We don't get valid metrics from the printer - and we want a better resolution
1809 // anyway (it's the PS driver that takes care of the printer resolution).
1810 TQPaintDeviceMetrics metrics( &prt );
1811
1812 //int dpiX = metrics.logicalDpiX();
1813 //int dpiY = metrics.logicalDpiY();
1814 int dpiX = doZoom ? 300 : KoGlobal::dpiX();
1815 int dpiY = doZoom ? 300 : KoGlobal::dpiY();
1818 m_doc->setZoomAndResolution( 100, dpiX, dpiY );
1819 m_doc->newZoomAndResolution( false, true /* for printing*/ );
1820 //kdDebug() << "KWView::print metrics: " << metrics.logicalDpiX() << "," << metrics.logicalDpiY() << endl;
1821 //kdDebug() << "x11AppDPI: " << KoGlobal::dpiX() << "," << KoGlobal::dpiY() << endl;
1822
1823 bool serialLetter = false;
1824
1825 TQPtrList<KoVariable> vars = m_doc->variableCollection()->getVariables();
1826 KoVariable *v = 0;
1827 for ( v = vars.first(); v; v = vars.next() ) {
1828 if ( v->type() == VT_MAILMERGE ) {
1829 serialLetter = true;
1830 break;
1831 }
1832 }
1833
1834 if ( !m_doc->mailMergeDataBase() ) serialLetter=false;
1835 else
1836 {
1837 m_doc->mailMergeDataBase()->refresh(false);
1838 if (m_doc->mailMergeDataBase()->getNumRecords() == 0 ) serialLetter = false;
1839 }
1840
1841 //float left_margin = 0.0;
1842 //float top_margin = 0.0;
1843
1844 KoPageLayout pgLayout;
1845 KoColumns cl;
1846 KoKWHeaderFooter hf;
1847 m_doc->getPageLayout( pgLayout, cl, hf );
1848 KoPageLayout oldPGLayout = pgLayout;
1849
1850 if ( pgLayout.format == PG_SCREEN )
1851 {
1852 //left_margin = 25.8;
1853 //top_margin = 15.0;
1854 pgLayout.ptLeft += 25.8; // Not sure why we need this....
1855 pgLayout.ptRight += 15.0;
1856 m_doc->setPageLayout( pgLayout, cl, hf, false );
1857 }
1858
1859 TQPainter painter;
1860 painter.begin( &prt );
1861
1862 kdDebug(32001) << "KWView::print scaling by " << (double)metrics.logicalDpiX() / (double)dpiX
1863 << "," << (double)metrics.logicalDpiY() / (double)dpiY << endl;
1864 painter.scale( (double)metrics.logicalDpiX() / (double)dpiX,
1865 (double)metrics.logicalDpiY() / (double)dpiY );
1866
1867 bool canceled = false;
1868 // Breaks wysiwyg, obviously - trying without
1869//#define KW_PASS_PAINTER_TO_TQRT
1870#ifdef KW_PASS_PAINTER_TO_TQRT
1871 int paragraphs = 0;
1872 fit.toFirst();
1873 for ( ; fit.current() ; ++fit )
1874 if ( fit.current()->isVisible() )
1875 paragraphs += fit.current()->paragraphs();
1876 kdDebug() << "KWView::print total paragraphs: " << paragraphs << endl;
1877
1878 // This can take a lot of time (reformatting everything), so a progress dialog is needed
1879 TQProgressDialog progress( i18n( "Printing..." ), i18n( "Cancel" ), paragraphs, this );
1880 progress.setProgress( 0 );
1881 int processedParags = 0;
1882 fit.toFirst();
1883 for ( ; fit.current() ; ++fit )
1884 if ( fit.current()->isVisible() )
1885 {
1886 tqApp->processEvents();
1887 if ( progress.wasCancelled() ) {
1888 canceled = true;
1889 break;
1890 }
1891
1892 kdDebug() << "KWView::print preparePrinting " << fit.current()->name() << endl;
1893 fit.current()->preparePrinting( &painter, &progress, processedParags );
1894 }
1895#endif
1896
1897 if ( !canceled )
1898 {
1899 if ( !serialLetter )
1900 m_gui->canvasWidget()->print( &painter, &prt );
1901 else
1902 {
1903 for ( int i = 0; i < m_doc->mailMergeDataBase()->getNumRecords(); ++i ) {
1904 m_doc->setMailMergeRecord( i );
1905 m_doc->variableCollection()->recalcVariables(VT_MAILMERGE);
1906 m_gui->canvasWidget()->print( &painter, &prt );
1907 if ( i < m_doc->mailMergeDataBase()->getNumRecords() - 1 )
1908 prt.newPage();
1909 }
1910 m_doc->setMailMergeRecord( -1 );
1911 }
1912 }
1913
1914 if ( pgLayout.format == PG_SCREEN )
1915 m_doc->setPageLayout( oldPGLayout, cl, hf, false );
1916
1917#ifdef KW_PASS_PAINTER_TO_TQRT
1918 fit.toFirst();
1919 for ( ; fit.current() ; ++fit )
1920 if ( fit.current()->isVisible() )
1921 fit.current()->preparePrinting( 0L, 0L, processedParags );
1922#endif
1923
1924 m_doc->setZoomAndResolution( oldZoom, KoGlobal::dpiX(), KoGlobal::dpiY() );
1925 m_doc->newZoomAndResolution( false, false );
1926 kdDebug() << "KWView::print zoom&res reset" << endl;
1927
1928 m_gui->canvasWidget()->setUpdatesEnabled(true);
1929 m_gui->canvasWidget()->viewport()->setCursor( ibeamCursor );
1930 m_doc->repaintAllViews();
1931
1932 if ( displayFieldCode )
1933 {
1934 m_doc->variableCollection()->variableSetting()->setDisplayFieldCode(true);
1935 m_doc->recalcVariables( VT_ALL );
1936 }
1937 else
1938 m_doc->variableCollection()->recalcVariables(VT_MAILMERGE);
1939
1940 painter.end(); // this is what triggers the printing
1941 m_doc->variableCollection()->variableSetting()->setLastPrintingDate(TQDateTime::currentDateTime());
1942 m_doc->recalcVariables( VT_DATE );
1943}
1944
1945void KWView::showFormat( const KoTextFormat &currentFormat )
1946{
1947 // update the gui with the current format.
1948 //kdDebug() << "KWView::setFormat font family=" << currentFormat.font().family() << endl;
1949 if (m_actionFormatFontFamily->font() != currentFormat.font().family())
1950 m_actionFormatFontFamily->setFont( currentFormat.font().family() );
1951 if (m_actionFormatFontSize->fontSize() != currentFormat.pointSize())
1952 m_actionFormatFontSize->setFontSize( currentFormat.pointSize() );
1953 m_actionFormatBold->setChecked( currentFormat.font().bold());
1954 m_actionFormatItalic->setChecked( currentFormat.font().italic() );
1955 m_actionFormatUnderline->setChecked( currentFormat.underline());
1956 m_actionFormatStrikeOut->setChecked( currentFormat.strikeOut());
1957 TQColor col=currentFormat.textBackgroundColor();
1958 //m_actionBackgroundColor->setEnabled(true);
1959 m_actionBackgroundColor->setCurrentColor( col.isValid() ? col : TQApplication::palette().color( TQPalette::Active, TQColorGroup::Base ));
1960
1961 if ( m_gui /* if not in constructor */ && frameViewManager()->selectedFrames().count() > 0)
1962 m_actionBackgroundColor->setText(i18n("Frame Background Color..."));
1963 else
1964 m_actionBackgroundColor->setText(i18n("Text Background Color..."));
1965 switch(currentFormat.vAlign())
1966 {
1967 case KoTextFormat::AlignSuperScript:
1968 {
1969 m_actionFormatSub->setChecked( false );
1970 m_actionFormatSuper->setChecked( true );
1971 break;
1972 }
1973 case KoTextFormat::AlignSubScript:
1974 {
1975 m_actionFormatSub->setChecked( true );
1976 m_actionFormatSuper->setChecked( false );
1977 break;
1978 }
1979 case KoTextFormat::AlignNormal:
1980 default:
1981 {
1982 m_actionFormatSub->setChecked( false );
1983 m_actionFormatSuper->setChecked( false );
1984 break;
1985 }
1986 }
1987
1988}
1989
1990void KWView::showRulerIndent( double leftMargin, double firstLine, double rightMargin, bool rtl )
1991{
1992 KoRuler * hRuler = m_gui ? m_gui->getHorzRuler() : 0;
1993 if ( hRuler )
1994 {
1995 hRuler->setFirstIndent( KoUnit::toUserValue( firstLine, m_doc->unit() ) );
1996 hRuler->setLeftIndent( KoUnit::toUserValue( leftMargin, m_doc->unit() ) );
1997 hRuler->setRightIndent( KoUnit::toUserValue( rightMargin, m_doc->unit() ) );
1998 hRuler->setDirection( rtl );
1999 m_actionFormatDecreaseIndent->setEnabled( leftMargin>0);
2000 }
2001}
2002
2003void KWView::showAlign( int align ) {
2004 switch ( align ) {
2005 case TQt::AlignAuto: // In left-to-right mode it's align left. TODO: alignright if text->isRightToLeft()
2006 kdWarning() << k_funcinfo << "shouldn't be called with AlignAuto" << endl;
2007 // fallthrough
2008 case TQt::AlignLeft:
2009 m_actionFormatAlignLeft->setChecked( true );
2010 break;
2011 case TQt::AlignHCenter:
2012 m_actionFormatAlignCenter->setChecked( true );
2013 break;
2014 case TQt::AlignRight:
2015 m_actionFormatAlignRight->setChecked( true );
2016 break;
2017 case TQt::AlignJustify:
2018 m_actionFormatAlignBlock->setChecked( true );
2019 break;
2020 }
2021}
2022
2023void KWView::showSpacing( int spacing ) {
2024 switch ( spacing )
2025 {
2026 case KoParagLayout::LS_SINGLE:
2027 m_actionFormatSpacingSingle->setChecked( true );
2028 break;
2029 case KoParagLayout::LS_ONEANDHALF:
2030 m_actionFormatSpacingOneAndHalf->setChecked( true );
2031 break;
2032 case KoParagLayout::LS_DOUBLE:
2033 m_actionFormatSpacingDouble->setChecked( true );
2034 break;
2035 default:
2036 m_actionFormatSpacingSingle->setChecked( false );
2037 m_actionFormatSpacingOneAndHalf->setChecked( false );
2038 m_actionFormatSpacingDouble->setChecked( false );
2039 }
2040}
2041
2042void KWView::showCounter( KoParagCounter &c )
2043{
2044 TQString styleStr("counterstyle_");
2045 styleStr += TQString::number( c.style() );
2046 //kdDebug() << "KWView::showCounter styleStr=" << styleStr << endl;
2047 TDEToggleAction* act = static_cast<TDEToggleAction *>( actionCollection()->action( styleStr.latin1() ) );
2048 Q_ASSERT( act );
2049 if ( act )
2050 act->setChecked( true );
2051}
2052
2053void KWView::updateBorderButtons( const KoBorder& left, const KoBorder& right,
2054 const KoBorder& top, const KoBorder& bottom )
2055{
2056 m_actionBorderLeft->setChecked( left.penWidth() > 0 );
2057 m_actionBorderRight->setChecked( right.penWidth() > 0 );
2058 m_actionBorderTop->setChecked( top.penWidth() > 0 );
2059 m_actionBorderBottom->setChecked( bottom.penWidth() > 0 );
2060 m_actionBorderOutline->setChecked(
2061 m_actionBorderLeft->isChecked() &&
2062 m_actionBorderRight->isChecked() &&
2063 m_actionBorderTop->isChecked() &&
2064 m_actionBorderBottom->isChecked());
2065
2066 KoBorder border = left;
2067 if(left.penWidth() > 0)
2068 border = left;
2069 else if(right.penWidth() > 0)
2070 border = right;
2071 else if(top.penWidth() > 0)
2072 border = top;
2073 else if(bottom.penWidth() > 0)
2074 border = bottom;
2075 else
2076 return;// then don't update since they are all empty.
2077
2078 m_actionBorderWidth->setCurrentItem( (int)border.penWidth() - 1 );
2079 m_actionBorderStyle->setCurrentItem( (int)border.getStyle() );
2080 m_actionBorderColor->setCurrentColor( border.color );
2081}
2082
2083void KWView::updateReadWrite( bool readwrite )
2084{
2085 // First disable or enable everything
2086 TQValueList<TDEAction*> actions = actionCollection()->actions();
2087 // Also grab actions from the document
2088 actions += m_doc->actionCollection()->actions();
2089 TQValueList<TDEAction*>::ConstIterator aIt = actions.begin();
2090 TQValueList<TDEAction*>::ConstIterator aEnd = actions.end();
2091 for (; aIt != aEnd; ++aIt )
2092 (*aIt)->setEnabled( readwrite );
2093
2094 if ( !readwrite )
2095 {
2096 // Readonly -> re-enable a few harmless actions
2097 m_actionFileStatistics->setEnabled( true );
2098 m_actionExtraCreateTemplate->setEnabled( true );
2099 m_actionViewPageMode->setEnabled( true );
2100 m_actionViewPreviewMode->setEnabled( true );
2101
2102 m_actionViewTextMode->setEnabled( true );
2103 m_actionShowRuler->setEnabled( true );
2104 m_actionEditFind->setEnabled( true );
2105 m_actionViewFormattingChars->setEnabled( true );
2106 m_actionViewFrameBorders->setEnabled( true );
2107 // that's not readonly, in fact, it modifies the doc
2108 //m_actionViewHeader->setEnabled( true );
2109 //m_actionViewFooter->setEnabled( true );
2110 m_actionViewZoom->setEnabled( true );
2111 m_actionInsertComment->setEnabled( true );
2112 m_actionAllowAutoFormat->setEnabled( true );
2113 m_actionShowDocStruct->setEnabled( true );
2114 m_actionConfigureCompletion->setEnabled( true );
2115 m_actionFormatBullet->setEnabled(true);
2116 m_actionFormatNumber->setEnabled( true);
2117 m_actionSelectBookmark->setEnabled( true );
2118 TDEAction* act = actionCollection()->action("edit_sldatabase");
2119 if (act)
2120 act->setEnabled( true );
2121
2122 // In fact the new view could be readwrite, so this is too dangerous
2123 // (e.g. during spellchecking or during search-n-replace)
2124 //act = actionCollection()->action("view_newview");
2125 //if (act)
2126 // act->setEnabled( true );
2127 }
2128 else
2129 {
2130 frameSelectedChanged();
2131 slotFrameSetEditChanged();
2132 refreshCustomMenu();
2133 refreshDeletePageAction();
2134 // Correctly enable or disable undo/redo actions again
2135 m_doc->commandHistory()->updateActions();
2136 }
2137}
2138
2139void KWView::refreshDeletePageAction()
2140{
2141 m_actionDeletePage->setEnabled( m_doc->pageCount() > 1 && m_doc->processingType() == KWDocument::DTP );
2142}
2143
2144void KWView::showMouseMode( int mouseMode )
2145{
2146 switch ( mouseMode ) {
2147 case KWCanvas::MM_EDIT:
2148 case KWCanvas::MM_CREATE_TABLE:
2149 case KWCanvas::MM_CREATE_FORMULA:
2150 case KWCanvas::MM_CREATE_PART:
2151 // No tool to activate for this mode -> deselect all the others
2152 m_actionToolsCreateText->setChecked( false );
2153 m_actionToolsCreatePix->setChecked( false );
2154 //m_actionToolsCreatePart->setChecked( false );
2155 break;
2156 case KWCanvas::MM_CREATE_TEXT:
2157 m_actionToolsCreateText->setChecked( true );
2158 break;
2159 case KWCanvas::MM_CREATE_PIX:
2160 m_actionToolsCreatePix->setChecked( true );
2161 break;
2162 //case KWCanvas::MM_CREATE_PART:
2163 //m_actionToolsCreatePart->setChecked( true );
2164 break;
2165 }
2166
2167 m_actionTableJoinCells->setEnabled( false );
2168 m_actionTableSplitCells->setEnabled( false );
2169 m_actionTableProtectCells->setEnabled( false );
2170 m_actionFormatFrameSet->setEnabled(false);
2171 m_actionTablePropertiesMenu->setEnabled( false );
2172 m_actionConvertTableToText->setEnabled( false );
2173}
2174
2175void KWView::showStyle( const TQString & styleName )
2176{
2177 KoParagStyle* style = m_doc->styleCollection()->findStyle( styleName );
2178 if ( style ) {
2179 int pos = m_doc->styleCollection()->indexOf( style );
2180 // Select style in combo
2181 m_actionFormatStyle->setCurrentItem( pos );
2182 // Check the appropriate action among the m_actionFormatStyleMenu actions
2183 TDEToggleAction* act = dynamic_cast<TDEToggleAction *>(actionCollection()->action(style->name().utf8().data()));
2184 if ( act )
2185 act->setChecked( true );
2186 }
2187}
2188
2189// used to avoid action naming conflicts
2190static const char* PARAGSTYLE_ACTION_PREFIX = "paragstyle_";
2191static const char* FRAMESTYLE_ACTION_PREFIX = "framestyle_";
2192static const char* TABLESTYLE_ACTION_PREFIX = "tablestyle_";
2193
2194void KWView::updateStyleList()
2195{
2196 TQString currentStyle = m_actionFormatStyle->currentText();
2197 // Generate list of styles
2198 const TQStringList lst = m_doc->styleCollection()->displayNameList();
2199 const int pos = lst.findIndex( currentStyle );
2200 // Fill the combo - using a TDESelectAction
2201 m_actionFormatStyle->setItems( lst );
2202 if ( pos > -1 )
2203 m_actionFormatStyle->setCurrentItem( pos );
2204
2205 // Fill the menu - using a TDEActionMenu, so that it's possible to bind keys
2206 // to individual actions
2207 TQStringList lstWithAccels;
2208 // Generate unique accelerators for the menu items
2209 TDEAccelGen::generate( lst, lstWithAccels );
2210 TQMap<TQString, TDEShortcut> shortCuts;
2211
2212 TDEActionPtrList lst2 = actionCollection()->actions("styleList");
2213 TQValueList<TDEAction *> actions = lst2;
2214 TQValueList<TDEAction *>::ConstIterator it = lst2.begin();
2215 const TQValueList<TDEAction *>::ConstIterator end = lst2.end();
2216 for (; it != end; ++it )
2217 {
2218 shortCuts.insert( TQString::fromUtf8( (*it)->name() ), (*it)->shortcut() );
2219 m_actionFormatStyleMenu->remove( *it );
2220 delete *it;
2221 }
2222 uint i = 0;
2223 for ( TQStringList::Iterator it = lstWithAccels.begin(); it != lstWithAccels.end(); ++it, ++i )
2224 {
2225 // The list lst was created (unsorted) from the style collection, so we have still the same order.
2226 KoParagStyle *style = m_doc->styleCollection()->styleAt( i );
2227 if ( style )
2228 {
2229 TQString name = PARAGSTYLE_ACTION_PREFIX + style->name();
2230 TDEToggleAction* act = new TDEToggleAction( (*it),
2231 shortCuts[name], this, TQ_SLOT( slotStyleSelected() ),
2232 actionCollection(), name.utf8() );
2233 act->setGroup( "styleList" );
2234 act->setExclusiveGroup( "styleListAction" );
2235 act->setToolTip( i18n( "Apply a paragraph style" ) );
2236 m_actionFormatStyleMenu->insert( act );
2237 }
2238 else
2239 kdWarning() << "No style found for " << *it << endl;
2240 }
2241}
2242
2243// Called when selecting a style in the Format / Style menu
2244void KWView::slotStyleSelected()
2245{
2246 TQString actionName = TQString::fromUtf8(sender()->name());
2247 const TQString prefix = PARAGSTYLE_ACTION_PREFIX;
2248 if ( actionName.startsWith( prefix ) ) {
2249 actionName = actionName.mid( prefix.length() );
2250 kdDebug(32001) << "KWView::slotStyleSelected " << actionName << endl;
2251 textStyleSelected( m_doc->styleCollection()->findStyle( actionName ) );
2252 }
2253}
2254
2255void KWView::updateFrameStyleList()
2256{
2257 // Remember selected style (by name; better would be by pointer, but what if it got deleted?)
2258 // This is all in case the index of the selected style has changed.
2259 const TQString currentStyle = m_actionFrameStyle->currentText();
2260 // Generate list of styles
2261 const TQStringList lst = m_doc->frameStyleCollection()->displayNameList();
2262 const int pos = lst.findIndex( currentStyle );
2263 // Fill the combo
2264 m_actionFrameStyle->setItems( lst );
2265 if ( pos > -1 )
2266 m_actionFrameStyle->setCurrentItem( pos );
2267
2268 // Fill the menu - using a TDEActionMenu, so that it's possible to bind keys
2269 // to individual actions
2270 TQStringList lstWithAccels;
2271 // Generate unique accelerators for the menu items
2272 TDEAccelGen::generate( lst, lstWithAccels );
2273 TQMap<TQString, TDEShortcut> shortCuts; // style (internal) name -> shortcut
2274
2275
2276 TDEActionPtrList lst2 = actionCollection()->actions("frameStyleList");
2277 TQValueList<TDEAction *> actions = lst2;
2278 TQValueList<TDEAction *>::ConstIterator it = lst2.begin();
2279 TQValueList<TDEAction *>::ConstIterator end = lst2.end();
2280 for (; it != end; ++it )
2281 {
2282 shortCuts.insert( TQString::fromUtf8( (*it)->name() ), (*it)->shortcut() );
2283 m_actionFrameStyleMenu->remove( *it );
2284 delete *it;
2285 }
2286
2287 uint i = 0;
2288 for ( TQStringList::Iterator it = lstWithAccels.begin(); it != lstWithAccels.end(); ++it, ++i )
2289 {
2290 // The list lst was created (unsorted) from the frame style collection, so we have still the same order.
2291 KWFrameStyle *style = m_doc->frameStyleCollection()->frameStyleAt( i );
2292 if ( style )
2293 {
2294 TQString name = FRAMESTYLE_ACTION_PREFIX + style->name();
2295 TDEToggleAction* act = new TDEToggleAction( (*it),
2296 shortCuts[name], // KDE4: use value()
2297 this, TQ_SLOT( slotFrameStyleSelected() ),
2298 actionCollection(), name.utf8() /*KDE4: remove conversion*/ );
2299 act->setGroup( "frameStyleList" );
2300 act->setExclusiveGroup( "frameStyleList" );
2301 act->setToolTip( i18n( "Apply a frame style" ) );
2302 m_actionFrameStyleMenu->insert( act );
2303 }
2304 else
2305 kdWarning() << "No frame style found for " << *it << endl;
2306 }
2307}
2308
2309
2310void KWView::updateTableStyleList()
2311{
2312 const TQString currentStyle = m_actionTableStyle->currentText();
2313 // Generate list of styles
2314 const TQStringList lst = m_doc->tableStyleCollection()->displayNameList();
2315 const int pos = lst.findIndex( currentStyle );
2316 // Fill the combo
2317 m_actionTableStyle->setItems( lst );
2318 if ( pos > -1 )
2319 m_actionTableStyle->setCurrentItem( pos );
2320
2321 // Fill the menu - using a TDEActionMenu, so that it's possible to bind keys
2322 // to individual actions
2323 TQStringList lstWithAccels;
2324 // Generate unique accelerators for the menu items
2325 TDEAccelGen::generate( lst, lstWithAccels );
2326 TQMap<TQString, TDEShortcut> shortCuts;
2327
2328 TQValueList<TDEAction *> actions = actionCollection()->actions("tableStyleList");
2329 TQValueList<TDEAction *>::ConstIterator it = actions.begin();
2330 const TQValueList<TDEAction *>::ConstIterator end = actions.end();
2331 for (; it != end; ++it )
2332 {
2333 shortCuts.insert( TQString::fromUtf8( (*it)->name() ), (*it)->shortcut() );
2334 m_actionTableStyleMenu->remove( *it );
2335 delete *it;
2336 }
2337
2338 uint i = 0;
2339 for ( TQStringList::Iterator it = lstWithAccels.begin(); it != lstWithAccels.end(); ++it, ++i )
2340 {
2341 // The list lst was created (unsorted) from the table style collection, so we have still the same order.
2342 KWTableStyle *style = m_doc->tableStyleCollection()->tableStyleAt( i );
2343 if ( style )
2344 {
2345 TQString name = TABLESTYLE_ACTION_PREFIX + style->name();
2346 TDEToggleAction* act = new TDEToggleAction( (*it),
2347 shortCuts[name], this, TQ_SLOT( slotTableStyleSelected() ),
2348 actionCollection(), name.utf8() );
2349 act->setExclusiveGroup( "tableStyleList" );
2350 act->setGroup( "tableStyleList" );
2351 act->setToolTip( i18n( "Apply a table style" ) );
2352 m_actionTableStyleMenu->insert( act );
2353 }
2354 else
2355 kdWarning() << "No table style found for " << *it << endl;
2356 }
2357}
2358
2359void KWView::editCut()
2360{
2361 KWFrameSetEdit * edit = currentTextEdit();
2362 if ( edit )
2363 edit->cut();
2364 else {
2365 TQDragObject *drag = m_doc->dragSelected( frameViewManager()->selectedFrames() );
2366 TQApplication::clipboard()->setData( drag );
2367 deleteFrame(false);
2368 }
2369}
2370
2371void KWView::editCopy()
2372{
2373 KWTextFrameSetEdit * edit = currentTextEdit();
2374 if ( edit )
2375 edit->copy();
2376 else {
2377 TQDragObject *drag = m_doc->dragSelected( frameViewManager()->selectedFrames() );
2378 TQApplication::clipboard()->setData( drag );
2379 }
2380}
2381
2382void KWView::editPaste()
2383{
2384 TQMimeSource *data = TQApplication::clipboard()->data();
2385 pasteData( data, false );
2386}
2387
2388// paste or drop
2389void KWView::pasteData( TQMimeSource* data, bool drop )
2390{
2391 int provides = checkClipboard( data );
2392 Q_ASSERT( provides != 0 );
2393
2394 // formula must be the first as a formula is also available as image
2395 if ( provides & ProvidesFormula ) {
2396 KWFrameSetEdit * edit = m_gui->canvasWidget()->currentFrameSetEdit();
2397 if ( edit && edit->frameSet()->type() == FT_FORMULA ) {
2398 edit->pasteData( data, ProvidesFormula, drop );
2399 }
2400 else {
2401 insertFormula( data );
2402 }
2403 }
2404 else // pasting text and/or frames
2405 {
2406 deselectAllFrames();
2407 // let the user select paste format if the clipboard contains an image URL
2408 if ( (provides & ProvidesImage) && (provides & ProvidesPlainText) && !( provides & ProvidesOasis ) )
2409 {
2410 TQStringList list;
2411 list.append( i18n("Image") );
2412 list.append( i18n("Plain text") );
2413 bool ok;
2414 TQString result = KInputDialog::getItem( i18n("Paste"), i18n("Select paste format:"), list, 0, false, &ok );
2415 if (!ok)
2416 return;
2417 if ( result == list.first() )
2418 {
2419 provides = ProvidesImage;
2420 } else {
2421 provides = ProvidesPlainText;
2422 }
2423 if ( !drop ) // get it again, to avoid crashes
2424 data = TQApplication::clipboard()->data();
2425 }
2426 KWTextFrameSetEdit * edit = currentTextEdit();
2427 if ( edit && ( provides & ProvidesPlainText ) ) {
2428 edit->pasteData( data, provides, drop );
2429 } else if ( provides & ProvidesOasis ) {
2430 // Not editing a frameset? We can't paste plain text then... only entire frames.
2431 TQCString returnedTypeMime = KoTextObject::providesOasis( data );
2432 if ( !returnedTypeMime.isEmpty() )
2433 {
2434 const TQByteArray arr = data->encodedData( returnedTypeMime );
2435 if( !arr.isEmpty() )
2436 {
2437 TQBuffer buffer( arr );
2438 KoStore * store = KoStore::createStore( &buffer, KoStore::Read );
2439 KWOasisLoader oasisLoader( m_doc );
2440 TQValueList<KWFrame *> frames = oasisLoader.insertOasisData( store, 0 /* no cursor */ );
2441 delete store;
2442 TQValueList<KWFrame *>::ConstIterator it = frames.begin();
2443 KMacroCommand* macroCmd = 0L;
2444 for ( ; it != frames.end() ; ++it )
2445 {
2446 if ( !macroCmd )
2447 macroCmd = new KMacroCommand( i18n( "Paste" ) );
2448
2449 KWCreateFrameCommand *cmd = new KWCreateFrameCommand( i18n( "Paste" ), *it );
2450 macroCmd->addCommand( cmd );
2451
2452 frameViewManager()->view(*it)->setSelected(true);
2453 (*it)->frameSet()->updateFrames();
2454 }
2455
2456 if ( macroCmd ) {
2457 m_doc->addCommand( macroCmd );
2459 return;
2460 }
2461 }
2462 }
2463 }
2464 if ( provides & ProvidesImage )
2465 { // providesImage, must be after providesOasis
2466 KoPoint docPoint( m_currentPage->leftMargin(),
2467 m_currentPage->offsetInDocument() + m_currentPage->topMargin());
2468 m_gui->canvasWidget()->pasteImage( data, docPoint );
2469 }
2470 }
2471}
2472
2473void KWView::editSelectAll()
2474{
2475 KWFrameSetEdit * edit = m_gui->canvasWidget()->currentFrameSetEdit();
2476 if ( edit )
2477 edit->selectAll();
2478}
2479
2480void KWView::editSelectAllFrames()
2481{
2482 m_gui->canvasWidget()->selectAllFrames( true );
2483}
2484
2485void KWView::editSelectCurrentFrame()
2486{
2487 if (!m_gui) return;
2488 KWFrameSetEdit* edit = m_gui->canvasWidget()->currentFrameSetEdit();
2489 KWFrame* frame = edit->currentFrame();
2490 if (!frame) return;
2491 KWFrameView *view = frameViewManager()->view(frame);
2492 if (!view) return;
2493 view->setSelected(true);
2494}
2495
2496void KWView::editFind()
2497{
2498 if (!m_searchEntry)
2499 m_searchEntry = new KoSearchContext();
2500 KWTextFrameSetEdit * edit = currentTextEdit();
2501 bool hasSelection = edit && edit->textFrameSet()->hasSelection();
2502 bool hasCursor = edit != 0L;
2503
2504 KoSearchDia dialog( m_gui->canvasWidget(), "find", m_searchEntry, hasSelection, hasCursor );
2505 if ( dialog.exec() == TQDialog::Accepted )
2506 {
2507 delete m_findReplace;
2508 m_findReplace = new KWFindReplace( m_gui->canvasWidget(), &dialog, m_gui->canvasWidget()->kWordDocument()->visibleTextObjects(viewMode()), edit);
2509 editFindNext();
2510 }
2511}
2512
2513void KWView::editReplace()
2514{
2515 if (!m_searchEntry)
2516 m_searchEntry = new KoSearchContext();
2517 if (!m_replaceEntry)
2518 m_replaceEntry = new KoSearchContext();
2519
2520 KWTextFrameSetEdit * edit = currentTextEdit();
2521 bool hasSelection = edit && edit->textFrameSet()->hasSelection();
2522 bool hasCursor = edit != 0L;
2523
2524 KoReplaceDia dialog( m_gui->canvasWidget(), "replace", m_searchEntry, m_replaceEntry, hasSelection, hasCursor );
2525 if ( dialog.exec() == TQDialog::Accepted )
2526 {
2527 delete m_findReplace;
2528 m_findReplace = new KWFindReplace( m_gui->canvasWidget(), &dialog, m_gui->canvasWidget()->kWordDocument()->visibleTextObjects(viewMode()), edit);
2529 editFindNext();
2530 }
2531}
2532
2533void KWView::editFindNext()
2534{
2535 if ( !m_findReplace ) // shouldn't be called before find or replace is activated
2536 {
2537 editFind();
2538 return;
2539 }
2540 (void) m_findReplace->findNext();
2541}
2542
2543void KWView::editFindPrevious()
2544{
2545 if ( !m_findReplace ) // shouldn't be called before find or replace is activated
2546 {
2547 editFind();
2548 return;
2549 }
2550 (void) m_findReplace->findPrevious();
2551}
2552
2553void KWView::adjustZOrderOfSelectedFrames(MoveFrameType moveType) {
2554 KMacroCommand* macroCmd = 0L;
2555 // For each selected frame...
2556 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
2557 if(selectedFrames.count()==0) return;
2558
2559 KWPage *page = m_doc->pageManager()->page(selectedFrames[0]->frame());
2560 TQPtrList<KWFrame> frames;
2561 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
2562 while(framesIterator != selectedFrames.end()) {
2563 // include all frames in case of table.
2564 frames.append((*framesIterator)->frame());
2565 KWFrameSet *table = (*framesIterator)->frame()->frameSet()->groupmanager();
2566 if(table) {
2567 for (TQPtrListIterator<KWFrame> cellIt(table->frameIterator() ); cellIt.current() ; ++cellIt ) {
2568 KWFrame *frame = cellIt.current();
2569 if(page->rect().contains(*frame) && !frames.contains(frame))
2570 frames.append(frame);
2571 }
2572 }
2573 ++framesIterator;
2574 }
2575
2576 int lowestZOrder=10000;
2577 TQString actionName;
2578 framesIterator = selectedFrames.begin();
2579 while(framesIterator != selectedFrames.end()) {
2580 KWFrame* frame = (*framesIterator)->frame();
2581 int newZOrder=0;
2582 switch(moveType) {
2583 case RaiseFrame:
2584 newZOrder=raiseFrame(frames,frame);
2585 actionName=i18n("Raise Frame");
2586 break;
2587 case LowerFrame:
2588 newZOrder=lowerFrame(frames,frame);
2589 actionName=i18n("Lower Frame");
2590 break;
2591 case BringToFront:
2592 newZOrder=bringToFront(frames,frame);
2593 actionName=i18n("Bring to Front");
2594 break;
2595 case SendToBack:
2596 newZOrder=sendToBack(frames,frame);
2597 actionName=i18n("Send to Back");
2598 break;
2599 }
2600
2601 if ( newZOrder != frame->zOrder() ) { // only if changed.
2602 lowestZOrder=TQMIN(lowestZOrder, newZOrder);
2603
2604 KWFrame* frameCopy = frame->getCopy();
2605 frame->setZOrder( newZOrder );
2606 frame->frameStack()->update();
2607
2608 KWFramePropertiesCommand* cmd = new KWFramePropertiesCommand( TQString(), frameCopy, frame);
2609 if(!macroCmd)
2610 macroCmd = new KMacroCommand( actionName );
2611 macroCmd->addCommand(cmd);
2612
2613 frameCopy = frame->getCopy();
2614 frame->setZOrder( newZOrder );
2615
2616 cmd = new KWFramePropertiesCommand( TQString(), frameCopy, frame );
2617 if(!macroCmd)
2618 macroCmd = new KMacroCommand( actionName );
2619 macroCmd->addCommand(cmd);
2620 }
2621 ++framesIterator;
2622 }
2623
2624 if ( macroCmd )
2625 {
2626 m_doc->addCommand(macroCmd);
2627 // Calling updateFrames() on the selected frames' framesets isn't enough,
2628 // we also need other framesets to notice the new frames on top.
2629 m_doc->updateAllFrames();
2630 m_doc->layout();
2631 m_doc->repaintAllViews();
2632 }
2633
2634 if(lowestZOrder != 10000 && m_doc->processingType() == KWDocument::WP) {
2635 m_doc->lowerMainFrames( page->pageNumber(), lowestZOrder );
2636 }
2637}
2638
2639// Make room for refZOrder, by raising all z-orders above it by 1
2640void KWView::increaseAllZOrdersAbove(int refZOrder, int pageNum, const TQPtrList<KWFrame>& frameSelection) {
2641 TQPtrList<KWFrame> framesInPage = m_doc->framesInPage( pageNum, false );
2642 for ( TQPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
2643 if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore frames we selected.
2644 if(frameIt.current()->zOrder() >= refZOrder) {
2645 frameIt.current()->setZOrder( frameIt.current()->zOrder() + 1 );
2646 }
2647 }
2648}
2649
2650// Make room for refZOrder, by lowering all z-orders below it by 1
2651void KWView::decreaseAllZOrdersUnder(int refZOrder, int pageNum, const TQPtrList<KWFrame>& frameSelection) {
2652 TQPtrList<KWFrame> framesInPage = m_doc->framesInPage( pageNum, false );
2653 for ( TQPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
2654 if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore frames we selected.
2655 if(frameIt.current()->zOrder() <= refZOrder) {
2656 frameIt.current()->setZOrder( frameIt.current()->zOrder() - 1 );
2657 }
2658 }
2659}
2660
2661int KWView::raiseFrame(const TQPtrList<KWFrame>& frameSelection, const KWFrame *frame) {
2662 int newZOrder = 10000;
2663 TQValueList<int> zorders;
2664 TQPtrList<KWFrame> framesInPage = m_doc->framesInPage( frame->pageNumber(), false );
2665 for ( TQPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
2666 if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore other frames we selected.
2667 if(! frameIt.current()->intersects(*frame)) continue; // only frames that I intersect with.
2668 int z = frameIt.current()->zOrder();
2669 if(z > frame->zOrder()) {
2670 newZOrder=TQMIN(newZOrder, z + 1);
2671 }
2672 zorders.append( z );
2673 }
2674 if(newZOrder==10000) return frame->zOrder();
2675 // Ensure that newZOrder is "free"
2676 if ( zorders.find( newZOrder ) != zorders.end() )
2677 increaseAllZOrdersAbove( newZOrder, frame->pageNumber(), frameSelection );
2678 return newZOrder;
2679}
2680
2681int KWView::lowerFrame(const TQPtrList<KWFrame>& frameSelection, const KWFrame *frame) {
2682 int newZOrder = -10000;
2683 TQValueList<int> zorders;
2684 TQPtrList<KWFrame> framesInPage = m_doc->framesInPage( frame->pageNumber(), false );
2685 for ( TQPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
2686 if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore other frames we selected.
2687 if(frameIt.current()->frameSet()->isMainFrameset()) continue; // ignore main frameset.
2688 if(! frameIt.current()->intersects(*frame)) continue; // only frames that I intersect with.
2689 int z = frameIt.current()->zOrder();
2690 if(z < frame->zOrder()) {
2691 newZOrder=TQMAX(newZOrder, z -1);
2692 }
2693 zorders.append( z );
2694 }
2695 if(newZOrder==-10000) return frame->zOrder();
2696 // Ensure that newZOrder is "free"
2697 if ( zorders.find( newZOrder ) != zorders.end() )
2698 decreaseAllZOrdersUnder( newZOrder, frame->pageNumber(), frameSelection );
2699 return newZOrder;
2700}
2701
2702int KWView::bringToFront(const TQPtrList<KWFrame>& frameSelection, const KWFrame *frame) {
2703 int newZOrder = frame->zOrder();
2704 TQPtrList<KWFrame> framesInPage = m_doc->framesInPage( frame->pageNumber(), false );
2705 for ( TQPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
2706 if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore other frames we selected.
2707 if(! frameIt.current()->intersects(*frame)) continue; // only frames that I intersect with.
2708 newZOrder=TQMAX(newZOrder, frameIt.current()->zOrder()+1);
2709 }
2710 return newZOrder;
2711}
2712
2713int KWView::sendToBack(const TQPtrList<KWFrame>& frameSelection, const KWFrame *frame) {
2714 int newZOrder = frame->zOrder();
2715 TQPtrList<KWFrame> framesInPage = m_doc->framesInPage( frame->pageNumber(), false );
2716 for ( TQPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
2717 if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore other frames we selected.
2718 if(frameIt.current()->frameSet()->isMainFrameset()) continue; // ignore main frameset.
2719 if(! frameIt.current()->intersects(*frame)) continue; // only frames that I intersect with.
2720 newZOrder=TQMIN(newZOrder, frameIt.current()->zOrder()-1);
2721 }
2722 return newZOrder;
2723}
2724
2725void KWView::editDeleteFrame()
2726{
2727 deleteFrame();
2728}
2729
2730void KWView::deleteFrame( bool warning )
2731{
2732 if ( !m_doc->isReadWrite() )
2733 return;
2734
2735 TQValueList<KWFrameView*> frames = frameViewManager()->selectedFrames();
2736 if( frames.count() < 1) {
2737 kdWarning() << "KWView::deleteFrame: no frame selected" << endl;
2738 return;
2739 }
2740 if(frames.count()==1)
2741 {
2742 KWFrame *theFrame = frames[0]->frame();
2743 KWFrameSet *fs = theFrame->frameSet();
2744
2745 Q_ASSERT( !fs->isAHeader() ); // the action is disabled for such cases
2746 Q_ASSERT( !fs->isAFooter() );
2747 if ( fs->isMainFrameset() || fs->isAFooter() || fs->isAHeader() || fs->isFootEndNote())
2748 return;
2749
2750 // frame is part of a table?
2751 if ( fs->groupmanager() )
2752 {
2753 int result = KMessageBox::warningContinueCancel(
2754 this,
2755 i18n( "You are about to delete a table.\n"
2756 "Doing so will delete all the text in the table.\n"
2757 "Are you sure you want to do that?"),
2758 i18n("Delete Table"), KStdGuiItem::del(),
2759 "DeleteTableConfirmation",
2760 true );
2761 if (result != KMessageBox::Continue)
2762 return;
2763 m_doc->deleteTable( fs->groupmanager() );
2764 return;
2765 }
2766
2767 if ( fs->frameCount() == 1 && fs->type() == FT_TEXT) {
2768 if ( fs->isMainFrameset())
2769 return; // if primairy FS, we can't delete it :)
2770
2771 KWTextFrameSet * textfs = dynamic_cast<KWTextFrameSet *>(fs);
2772 Q_ASSERT(textfs);
2773 if ( !textfs )
2774 return;
2775
2776 KoTextDocument * textdoc = textfs->textDocument();
2777 if ( textdoc->length() > 0 )
2778 {
2779 int result = KMessageBox::warningContinueCancel(
2780 this,
2781 i18n( "You are about to delete the last Frame of the "
2782 "Frameset '%1'. "
2783 "The contents of this Frameset will not appear "
2784 "anymore!\n"
2785 "Are you sure you want to do that?").arg(fs->name()),
2786 i18n("Delete Frame"), KStdGuiItem::del());
2787
2788 if (result != KMessageBox::Continue)
2789 return;
2790
2791 m_doc->deleteFrame( theFrame );
2792 return;
2793 }
2794
2795 }
2796
2797 if(warning)
2798 {
2799 int result = KMessageBox::warningContinueCancel(
2800 this,
2801 i18n("Do you want to delete this frame?"),
2802 i18n("Delete Frame"),
2803 KGuiItem(i18n("&Delete"),"edit-delete"),
2804 "DeleteLastFrameConfirmation",
2805 true );
2806 if (result != KMessageBox::Continue)
2807 return;
2808 }
2809 m_doc->deleteFrame( theFrame );
2810 }
2811 else
2812 {
2813 //several frame
2814 if(warning)
2815 {
2816 int result = KMessageBox::warningContinueCancel(
2817 this,
2818 i18n("Do you want to delete this frame?"),
2819 i18n("Delete Frame"),
2820 KGuiItem(i18n("&Delete"),"edit-delete"),
2821 "DeleteLastFrameConfirmation",
2822 true );
2823 if (result != KMessageBox::Continue)
2824 return;
2825 }
2826
2827 deleteSelectedFrames();
2828 }
2829}
2830
2831void KWView::createLinkedFrame()
2832{
2833 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
2834 if (selectedFrames.count() != 1)
2835 return; // action is disabled in such a case
2836 KWFrame* frame = selectedFrames[0]->frame();
2837 KWFrame* newFrame = new KWFrame(0L, frame->x() + m_gui->getVertRuler()->minimumSizeHint().width(), frame->y() + m_gui->getHorzRuler()->minimumSizeHint().height(), frame->width(), frame->height() );
2838 newFrame->setZOrder( m_doc->maxZOrder( newFrame->pageNumber(m_doc) ) + 1 ); // make sure it's on top
2839 newFrame->setCopy(true);
2840 newFrame->setNewFrameBehavior( KWFrame::Copy );
2841 frame->frameSet()->addFrame( newFrame );
2842
2843 frameViewManager()->view(newFrame)->setSelected(true);
2844
2845 KWCreateFrameCommand *cmd = new KWCreateFrameCommand( i18n("Create Linked Copy"), newFrame );
2846 m_doc->addCommand( cmd );
2847
2848 m_doc->frameChanged( newFrame );
2849}
2850
2851void KWView::editCustomVariable()
2852{
2853 KWTextFrameSetEdit * edit = currentTextEdit();
2854 if (edit)
2855 {
2856 KoCustomVariable *var = static_cast<KoCustomVariable *>(edit->variable());
2857 if (var)
2858 {
2859 TQString oldvalue = var->value();
2860 KoCustomVarDialog dia( this, var );
2861 if ( dia.exec() )
2862 {
2863 m_doc->recalcVariables( VT_CUSTOM );
2864 if( var->value() != oldvalue )
2865 {
2866 KWChangeCustomVariableValue *cmd=new KWChangeCustomVariableValue(i18n( "Change Custom Variable" ),m_doc, oldvalue, var->value(), var );
2867 m_doc->addCommand(cmd);
2868 }
2869 }
2870 }
2871 }
2872}
2873
2874void KWView::editCustomVars()
2875{
2876 KoCustomVariablesDia dia( this, m_doc->variableCollection()->getVariables() );
2877 TQStringList listOldCustomValue;
2878 TQPtrListIterator<KoVariable> oldIt( m_doc->variableCollection()->getVariables() );
2879 for ( ; oldIt.current() ; ++oldIt )
2880 {
2881 if(oldIt.current()->type()==VT_CUSTOM)
2882 listOldCustomValue.append(((KoCustomVariable*)oldIt.current())->value());
2883 }
2884 if(dia.exec())
2885 {
2886 m_doc->recalcVariables( VT_CUSTOM );
2887 //temporaly hack, for the moment we can't undo/redo change custom variables
2888 TQPtrListIterator<KoVariable> it( m_doc->variableCollection()->getVariables() );
2889 KMacroCommand * macroCommand = 0L;
2890 int i=0;
2891 for ( ; it.current() ; ++it )
2892 {
2893 if(it.current()->type() == VT_CUSTOM )
2894 {
2895 if(((KoCustomVariable*)it.current())->value()!=*(listOldCustomValue.at(i)))
2896 {
2897 if(!macroCommand)
2898 macroCommand = new KMacroCommand( i18n( "Change Custom Variable" ) );
2899 KWChangeCustomVariableValue *cmd=new KWChangeCustomVariableValue(i18n( "Change Custom Variable" ),m_doc,*(listOldCustomValue.at(i)), ((KoCustomVariable*)it.current())->value() ,((KoCustomVariable*)it.current()));
2900 macroCommand->addCommand(cmd);
2901 }
2902 i++;
2903 }
2904 }
2905 if(macroCommand)
2906 m_doc->addCommand(macroCommand);
2907 }
2908}
2909
2910void KWView::editMailMergeDataBase()
2911{
2912 m_doc->mailMergeDataBase()->showConfigDialog(this);
2913#if 0
2914 KWMailMergeEditor *dia = new KWMailMergeEditor( this, m_doc->mailMergeDataBase() );
2915 dia->exec();
2916 // Don't know if we really need this so it's commented out (SL)
2917 // m_gui->canvasWidget()->repaintAll( false );
2918 delete dia;
2919#endif
2920}
2921
2922void KWView::viewTextMode()
2923{
2924 if ( m_actionViewTextMode->isChecked() )
2925 {
2927 if ( fs ) { // TODO: disable the action when there is no text frameset available
2928 if ( dynamic_cast<KWViewModePreview *>(viewMode()) )
2929 {
2930 m_zoomViewModePreview.m_zoom = m_doc->zoom();
2931 m_zoomViewModePreview.m_zoomMode = m_doc->zoomMode();
2932 }
2933 else
2934 {
2935 m_zoomViewModeNormal.m_zoom = m_doc->zoom();
2936 m_zoomViewModeNormal.m_zoomMode = m_doc->zoomMode();
2937 }
2938 // we don't know ZOOM_PAGE in the new view. so
2939 // we use ZOOM_CONSTANT in that case
2940 switch(m_zoomViewModeNormal.m_zoomMode)
2941 {
2942 case KoZoomMode::ZOOM_WIDTH:
2943 m_doc->setZoomMode(KoZoomMode::ZOOM_WIDTH);
2944 TQTimer::singleShot( 0, this, TQ_SLOT( updateZoom() ) );
2945 break;
2946 case KoZoomMode::ZOOM_PAGE: // no break
2947 m_zoomViewModeNormal.m_zoomMode = KoZoomMode::ZOOM_CONSTANT;
2948 case KoZoomMode::ZOOM_CONSTANT:
2949 m_doc->setZoomMode(KoZoomMode::ZOOM_CONSTANT);
2950 showZoom( m_zoomViewModeNormal.m_zoom );
2951 setZoom( m_zoomViewModeNormal.m_zoom, false );
2952 break;
2953 }
2954 m_doc->switchViewMode( "ModeText" );
2955 } else
2956 initGUIButton(); // ensure we show the current viewmode
2957 }
2958 else
2959 m_actionViewTextMode->setChecked( true ); // always one has to be checked !
2960}
2961
2962void KWView::viewPageMode()
2963{
2964 if ( m_actionViewPageMode->isChecked() )
2965 {
2966 if ( dynamic_cast<KWViewModePreview *>(viewMode()) )
2967 {
2968 m_zoomViewModePreview.m_zoom = m_doc->zoom();
2969 m_zoomViewModePreview.m_zoomMode = m_doc->zoomMode();
2970 }
2971 else
2972 {
2973 m_zoomViewModeNormal.m_zoom = m_doc->zoom();
2974 m_zoomViewModeNormal.m_zoomMode = m_doc->zoomMode();
2975 }
2976 switch(m_zoomViewModeNormal.m_zoomMode)
2977 {
2978 case KoZoomMode::ZOOM_WIDTH:
2979 m_doc->setZoomMode(KoZoomMode::ZOOM_WIDTH);
2980 TQTimer::singleShot( 0, this, TQ_SLOT( updateZoom() ) );
2981 break;
2982 case KoZoomMode::ZOOM_PAGE:
2983 m_doc->setZoomMode(KoZoomMode::ZOOM_PAGE);
2984 TQTimer::singleShot( 0, this, TQ_SLOT( updateZoom() ) );
2985 break;
2986 case KoZoomMode::ZOOM_CONSTANT:
2987 m_doc->setZoomMode(KoZoomMode::ZOOM_CONSTANT);
2988 showZoom( m_zoomViewModeNormal.m_zoom );
2989 setZoom( m_zoomViewModeNormal.m_zoom, false );
2990 break;
2991 }
2992 m_doc->switchViewMode( "ModeNormal" );
2993 }
2994 else
2995 m_actionViewPageMode->setChecked( true ); // always one has to be checked !
2996}
2997
2998void KWView::viewPreviewMode()
2999{
3000 if ( m_actionViewPreviewMode->isChecked() )
3001 {
3002 m_zoomViewModeNormal.m_zoom = m_doc->zoom();
3003 m_zoomViewModeNormal.m_zoomMode = m_doc->zoomMode();
3004 switch(m_zoomViewModePreview.m_zoomMode)
3005 {
3006 case KoZoomMode::ZOOM_WIDTH:
3007 m_doc->setZoomMode(KoZoomMode::ZOOM_WIDTH);
3008 TQTimer::singleShot( 0, this, TQ_SLOT( updateZoom() ) );
3009 break;
3010 case KoZoomMode::ZOOM_PAGE:
3011 m_doc->setZoomMode(KoZoomMode::ZOOM_PAGE);
3012 TQTimer::singleShot( 0, this, TQ_SLOT( updateZoom() ) );
3013 break;
3014 case KoZoomMode::ZOOM_CONSTANT:
3015 m_doc->setZoomMode(KoZoomMode::ZOOM_CONSTANT);
3016 showZoom( m_zoomViewModePreview.m_zoom );
3017 setZoom( m_zoomViewModePreview.m_zoom, false );
3018 break;
3019 }
3020 m_doc->switchViewMode( "ModePreview" );
3021 }
3022 else
3023 m_actionViewPreviewMode->setChecked( true ); // always one has to be checked !
3024}
3025
3026void KWView::updateZoomControls()
3027{
3028 switch(m_doc->zoomMode())
3029 {
3030 case KoZoomMode::ZOOM_WIDTH:
3031 case KoZoomMode::ZOOM_PAGE:
3032 showZoom( KoZoomMode::toString(m_doc->zoomMode()) );
3033 break;
3034 case KoZoomMode::ZOOM_CONSTANT:
3035 changeZoomMenu( m_doc->zoom() );
3036 showZoom( m_doc->zoom() );
3037 break;
3038 }
3039}
3040
3041void KWView::changeZoomMenu( int zoom )
3042{
3043 TQString mode;
3044 if ( m_gui && m_gui->canvasWidget() && viewMode())
3045 mode = viewMode()->type();
3046
3047 TQStringList lst;
3048 lst << KoZoomMode::toString(KoZoomMode::ZOOM_WIDTH);
3049 if ( mode!="ModeText" )
3050 lst << KoZoomMode::toString(KoZoomMode::ZOOM_PAGE);
3051
3052 if(zoom>0)
3053 {
3054 TQValueList<int> list;
3055 bool ok;
3056 const TQStringList itemsList ( m_actionViewZoom->items() );
3057 TQRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
3058
3059 for (TQStringList::ConstIterator it = itemsList.begin() ; it != itemsList.end() ; ++it)
3060 {
3061 regexp.search(*it);
3062 const int val=regexp.cap(1).toInt(&ok);
3063 //zoom : limit inferior=10
3064 if(ok && val>9 && list.contains(val)==0)
3065 list.append( val );
3066 }
3067 //necessary at the beginning when we read config
3068 //this value is not in combo list
3069 if(list.contains(zoom)==0)
3070 list.append( zoom );
3071
3072 qHeapSort( list );
3073
3074 for (TQValueList<int>::Iterator it = list.begin() ; it != list.end() ; ++it)
3075 lst.append( i18n("%1%").arg(*it) );
3076 }
3077 else
3078 {
3079 lst << i18n("%1%").arg("33");
3080 lst << i18n("%1%").arg("50");
3081 lst << i18n("%1%").arg("75");
3082 lst << i18n("%1%").arg("100");
3083 lst << i18n("%1%").arg("125");
3084 lst << i18n("%1%").arg("150");
3085 lst << i18n("%1%").arg("200");
3086 lst << i18n("%1%").arg("250");
3087 lst << i18n("%1%").arg("350");
3088 lst << i18n("%1%").arg("400");
3089 lst << i18n("%1%").arg("450");
3090 lst << i18n("%1%").arg("500");
3091 }
3092 m_actionViewZoom->setItems( lst );
3093}
3094
3095void KWView::showZoom( int zoom )
3096{
3097 TQStringList list = m_actionViewZoom->items();
3098 TQString zoomStr( i18n("%1%").arg( zoom ) );
3099 m_actionViewZoom->setCurrentItem( list.findIndex(zoomStr) );
3100}
3101
3102void KWView::showZoom( const TQString& zoom )
3103{
3104 TQStringList list = m_actionViewZoom->items();
3105 m_actionViewZoom->setCurrentItem( list.findIndex( zoom ) );
3106}
3107
3108void KWView::slotViewFormattingChars()
3109{
3110 m_doc->setViewFormattingChars(m_actionViewFormattingChars->isChecked());
3111 m_doc->layout(); // Due to the different formatting when this option is activated
3112 m_doc->repaintAllViews();
3113}
3114
3115void KWView::slotViewFrameBorders()
3116{
3117 setViewFrameBorders(m_actionViewFrameBorders->isChecked());
3118 m_gui->canvasWidget()->repaintAll();
3119}
3120
3121void KWView::viewHeader()
3122{
3123 bool state = m_actionViewHeader->isChecked();
3124 m_doc->setHeaderVisible( state );
3125 KWHideShowHeader *cmd=new KWHideShowHeader( state ? i18n("Enable Document Headers"):i18n("Disable Document Headers"), m_doc, state);
3126 m_doc->addCommand(cmd);
3127 updateHeader();
3128}
3129
3130void KWView::updateHeader()
3131{
3132 KWTextFrameSetEdit * edit = currentTextEdit();
3133 bool state = m_actionViewHeader->isChecked();
3134 if(!state )
3135 {
3136 KWFrameSet *frameSet=0L;
3137 if(edit)
3138 {
3139 frameSet=edit->frameSet();
3140 if (frameSet->isAHeader())
3141 m_doc->terminateEditing( frameSet );
3142 else
3143 {
3144 KWTableFrameSet *table = frameSet->frame(0)->frameSet()->groupmanager();
3145 if (table)
3146 {
3147 if (table->isFloating() && table->anchorFrameset()->isAHeader())
3148 m_doc->terminateEditing( table );
3149 }
3150 }
3151
3152 }
3153 else
3154 {
3155 KWFormulaFrameSetEdit * editFormula = dynamic_cast<KWFormulaFrameSetEdit *>(m_gui->canvasWidget()->currentFrameSetEdit());
3156 if(editFormula)
3157 {
3158 frameSet= editFormula->frameSet();
3159 if(frameSet->type()==FT_FORMULA && frameSet->isFloating())
3160 m_doc->terminateEditing( frameSet );
3161 }
3162
3163 }
3164 }
3165}
3166
3167
3168void KWView::viewFooter()
3169{
3170 bool state=m_actionViewFooter->isChecked();
3171 m_doc->setFooterVisible( state );
3172 KWHideShowFooter *cmd=new KWHideShowFooter( state ? i18n("Enable Document Footers"):i18n("Disable Document Footers"), m_doc, state);
3173 m_doc->addCommand(cmd);
3174 updateFooter();
3175}
3176
3177void KWView::updateFooter()
3178{
3179 bool state=m_actionViewFooter->isChecked();
3180 KWTextFrameSetEdit * edit = currentTextEdit();
3181 if(!state )
3182 {
3183 KWFrameSet *frameSet=0L;
3184 if(edit)
3185 {
3186 frameSet=edit->frameSet();
3187 if (frameSet->isAFooter())
3188 m_doc->terminateEditing( frameSet );
3189 else
3190 {
3191 KWTableFrameSet *table = frameSet->frame(0)->frameSet()->groupmanager();
3192 if (table)
3193 {
3194 if (table->isFloating() && table->anchorFrameset()->isAFooter())
3195 m_doc->terminateEditing( table );
3196 }
3197 }
3198 }
3199 else
3200 {
3201 KWFormulaFrameSetEdit * editFormula = dynamic_cast<KWFormulaFrameSetEdit *>(m_gui->canvasWidget()->currentFrameSetEdit());
3202 if(editFormula)
3203 {
3204 frameSet= editFormula->frameSet();
3205 if(frameSet->type()==FT_FORMULA && frameSet->isFloating())
3206 m_doc->terminateEditing( frameSet );
3207
3208 }
3209
3210 }
3211 }
3212
3213}
3214
3215void KWView::updateZoom( ) {
3216 viewZoom(m_actionViewZoom->currentText());
3217}
3218
3219void KWView::viewZoom( const TQString &s )
3220{
3221 bool ok=false;
3222 KWCanvas * canvas = m_gui->canvasWidget();
3223 int zoom = 0;
3224
3225 if ( s == KoZoomMode::toString(KoZoomMode::ZOOM_WIDTH) )
3226 {
3227 m_doc->setZoomMode(KoZoomMode::ZOOM_WIDTH);
3228 zoom = tqRound( static_cast<double>(canvas->visibleWidth() * 100 ) / (m_doc->resolutionX() * m_currentPage->width() ) ) - 1;
3229
3230 if(zoom != m_doc->zoom() && !canvas->verticalScrollBar() ||
3231 !canvas->verticalScrollBar()->isVisible()) { // has no vertical scrollbar
3232 // we have to do this twice to take into account a possibly appearing vertical scrollbar
3233 TQTimer::singleShot( 0, this, TQ_SLOT( updateZoom() ) );
3234 }
3235 ok = true;
3236 }
3237 else if ( s == KoZoomMode::toString(KoZoomMode::ZOOM_PAGE) )
3238 {
3239 m_doc->setZoomMode(KoZoomMode::ZOOM_PAGE);
3240 double height = m_doc->resolutionY() * m_currentPage->height();
3241 double width = m_doc->resolutionX() * m_currentPage->width();
3242 zoom = TQMIN( tqRound( static_cast<double>(canvas->visibleHeight() * 100 ) / height ),
3243 tqRound( static_cast<double>(canvas->visibleWidth() * 100 ) / width ) ) - 1;
3244
3245 ok = true;
3246 }
3247 else
3248 {
3249 m_doc->setZoomMode(KoZoomMode::ZOOM_CONSTANT);
3250 TQRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
3251 regexp.search(s);
3252 zoom=regexp.cap(1).toInt(&ok);
3253 }
3254
3255 if( !ok || zoom<10 ) //zoom should be valid and >10
3256 zoom = m_doc->zoom();
3257 if ( !KoZoomMode::isConstant(s) )
3258 showZoom( s ); //set current menu item
3259 else
3260 {
3261 changeZoomMenu( zoom ); //add current zoom value to the menu
3262 showZoom( zoom ); //set current menu item
3263 }
3264
3265 //apply zoom if zoom!=m_doc->zoom()
3266 if( zoom != m_doc->zoom() )
3267 {
3268 setZoom( zoom, true );
3269
3270 KWTextFrameSetEdit * edit = currentTextEdit();
3271 if ( edit )
3272 edit->ensureCursorVisible();
3273 }
3274
3275 m_gui->canvasWidget()->setFocus();
3276
3277}
3278
3279void KWView::setZoom( int zoom, bool updateViews )
3280{
3281 m_doc->setZoomAndResolution( zoom, KoGlobal::dpiX(), KoGlobal::dpiY());
3282 m_doc->newZoomAndResolution( updateViews, false );
3283 m_doc->updateZoomRuler();
3284
3285 if ( statusBar() )
3286 m_sbZoomLabel->setText( ' ' + TQString::number( zoom ) + "% " );
3287
3288 // Also set the zoom in KoView (for embedded views)
3289 kdDebug() << "KWView::setZoom " << zoom << " setting koview zoom to " << m_doc->zoomedResolutionY() << endl;
3290 KoView::setZoom( m_doc->zoomedResolutionY() /* KoView only supports one zoom */ );
3291}
3292
3293void KWView::insertPicture()
3294{
3295 if ( m_actionToolsCreatePix->isChecked() )
3296 {
3297 KWInsertPicDia dia( this,m_gui->canvasWidget()->pictureInline(),m_gui->canvasWidget()->pictureKeepRatio(),m_doc );
3298 if ( dia.exec() == TQDialog::Accepted && !dia.picture().isNull() )
3299 {
3300 insertPicture( dia.picture(), dia.makeInline(), dia.keepRatio(), 0, 0 );
3301 m_gui->canvasWidget()->setPictureInline( dia.makeInline());
3302 m_gui->canvasWidget()->setPictureKeepRatio( dia.keepRatio() );
3303 }
3304 else
3305 m_gui->canvasWidget()->setMouseMode( KWCanvas::MM_EDIT );
3306 }
3307 else
3308 {
3309 // clicked on the already active tool -> abort
3310 m_gui->canvasWidget()->setMouseMode( KWCanvas::MM_EDIT );
3311 }
3312}
3313
3314
3315void KWView::slotEmbedImage( const TQString &filename )
3316{
3317 KoPicture picture;
3318 KoPictureKey key;
3319 key.setKeyFromFile( filename );
3320 picture.setKey( key );
3321 picture.loadFromFile( filename );
3322 insertPicture( picture, false, true, 0, 0 );
3323}
3324
3325void KWView::insertPicture( const KoPicture& picture, const bool makeInline, const bool keepRatio, int suggestedWidth, int suggestedHeight )
3326{
3327 TQSize pixmapSize( picture.getOriginalSize() );
3328 if ( suggestedWidth > 0 && suggestedHeight > 0 )
3329 pixmapSize = TQSize( suggestedWidth, suggestedHeight );
3330
3331 if ( makeInline )
3332 {
3333 const double widthLimit = m_currentPage->width() - m_currentPage->leftMargin() -
3334 m_currentPage->rightMargin() - 10;
3335 const double heightLimit = m_currentPage->height() - m_currentPage->topMargin() -
3336 m_currentPage->bottomMargin() - 10;
3337 m_fsInline = 0;
3338 KWPictureFrameSet *frameset = new KWPictureFrameSet( m_doc, TQString() );
3339
3340 frameset->insertPicture( picture );
3341
3342 // This ensures 1-1 at 100% on screen, but allows zooming and printing with correct DPI values
3343 // ### TODO/FIXME: is the tqRound really necessary?
3344 double width = m_doc->unzoomItX( tqRound( (double)pixmapSize.width() * m_doc->zoomedResolutionX() / POINT_TO_INCH( KoGlobal::dpiX() ) ) );
3345 double height = m_doc->unzoomItY( tqRound( (double)pixmapSize.height() * m_doc->zoomedResolutionY() / POINT_TO_INCH( KoGlobal::dpiY() ) ) );
3346
3347 frameset->setKeepAspectRatio( keepRatio);
3348
3349
3350 if ( keepRatio && ((width > widthLimit) || (height > heightLimit)) )
3351 {
3352 // size too big => adjust the size and keep ratio
3353 const double ratioX = width / widthLimit;
3354 const double ratioY = height / heightLimit;
3355 const double ratioPicture = width / height;
3356
3357 if ( ratioPicture == 0 ) // unlikely
3358 {
3359 width = widthLimit;
3360 height = heightLimit;
3361 }
3362 else
3363 if ( ratioX > ratioY ) // restrict width and calculate height
3364 {
3365 width = widthLimit;
3366 height = widthLimit/ratioPicture;
3367 }
3368 else // restrict height and calculate width
3369 {
3370 width = heightLimit*ratioPicture;
3371 height = heightLimit;
3372 }
3373 }
3374 else
3375 {
3376 // Apply reasonable limits
3377 width = kMin( width, widthLimit );
3378 height = kMin( height, heightLimit );
3379 }
3380
3381 m_fsInline = frameset;
3382 KWFrame *frame = new KWFrame ( m_fsInline, 0, 0, width, height );
3383 m_fsInline->addFrame( frame, false );
3384 m_gui->canvasWidget()->inlinePictureStarted();
3385 showMouseMode( KWCanvas::MM_EDIT );
3386
3387 displayFrameInlineInfo();
3388
3389#if 0
3390 edit->insertFloatingFrameSet( fs, i18n("Insert Picture Inline") );
3391 fs->finalize(); // done last since it triggers a redraw
3392 showMouseMode( KWCanvas::MM_EDIT );
3393 m_doc->refreshDocStructure(Pictures);
3394#endif
3395 }
3396 else
3397 {
3398 m_gui->canvasWidget()->insertPicture( picture, pixmapSize, keepRatio );
3399 }
3400}
3401
3402bool KWView::insertInlinePicture()
3403{
3404 Q_ASSERT( m_fsInline );
3405 KWTextFrameSetEdit * edit = currentTextEdit();
3406 if(edit)
3407 {
3408 if ( edit->textFrameSet()->textObject()->protectContent() )
3409 return false;
3410
3411 m_doc->addFrameSet( m_fsInline, false ); // done first since the frame number is stored in the undo/redo
3412#if 0
3413 KWFrame *frame = new KWFrame( m_fsInline, 0, 0, m_doc->unzoomItX( width ), m_doc->unzoomItY( height ) );
3414 m_fsInline->addFrame( frame, false );
3415#endif
3416 edit->insertFloatingFrameSet( m_fsInline, i18n("Insert Picture Inline") );
3417 m_fsInline->finalize(); // done last since it triggers a redraw
3418 showMouseMode( KWCanvas::MM_EDIT );
3419 m_doc->refreshDocStructure(Pictures);
3420 m_fsInline=0;
3421 updateFrameStatusBarItem();
3422 }
3423 else
3424 {
3425 delete m_fsInline;
3426 m_fsInline=0;
3427 updateFrameStatusBarItem();
3428 }
3429 return true;
3430}
3431
3432void KWView::displayFrameInlineInfo()
3433{
3434 KMessageBox::information(this,
3435 i18n("Set cursor where you want to insert inline frame."),
3436 i18n("Insert Inline Frame"),
3437 "SetCursorInsertInlineFrame",true);
3438
3439 if ( statusBar() && m_sbFramesLabel )
3440 m_sbFramesLabel->setText( ' ' + i18n("Set cursor where you want to insert inline frame." ) );
3441}
3442
3443void KWView::insertSpecialChar()
3444{
3445 KWTextFrameSetEdit *edit=currentTextEdit();
3446 if ( !edit )
3447 return;
3448 TQString f = edit->textFontFamily();
3449 TQChar c=' ';
3450 if (m_specialCharDlg==0)
3451 {
3452 m_specialCharDlg = new KoCharSelectDia( this, "insert special char", f, c, false );
3453 connect( m_specialCharDlg, TQ_SIGNAL(insertChar(TQChar,const TQString &)),
3454 this, TQ_SLOT(slotSpecialChar(TQChar,const TQString &)));
3455 connect( m_specialCharDlg, TQ_SIGNAL( finished() ),
3456 this, TQ_SLOT( slotSpecialCharDlgClosed() ) );
3457 }
3458 m_specialCharDlg->show();
3459}
3460
3461void KWView::slotSpecialCharDlgClosed()
3462{
3463 if ( m_specialCharDlg )
3464 {
3465 disconnect( m_specialCharDlg, TQ_SIGNAL(insertChar(TQChar,const TQString &)),
3466 this, TQ_SLOT(slotSpecialChar(TQChar,const TQString &)));
3467 disconnect( m_specialCharDlg, TQ_SIGNAL( finished() ),
3468 this, TQ_SLOT( slotSpecialCharDlgClosed() ) );
3469 m_specialCharDlg->deleteLater();
3470 m_specialCharDlg = 0L;
3471 }
3472}
3473
3474void KWView::slotSpecialChar(TQChar c, const TQString &font)
3475{
3476 KWTextFrameSetEdit *edit=currentTextEdit();
3477 if ( !edit )
3478 return;
3479 edit->insertSpecialChar(c, font);
3480}
3481
3482void KWView::insertFrameBreak()
3483{
3484 KWTextFrameSetEdit *edit=currentTextEdit();
3485 if ( !edit )
3486 return;
3487 edit->insertFrameBreak();
3488}
3489
3490void KWView::insertPage()
3491{
3492 if ( m_doc->processingType() == KWDocument::WP )
3493 {
3494 m_gui->canvasWidget()->editFrameSet( m_doc->frameSet(0) );
3495 KWTextFrameSetEdit *edit = currentTextEdit();
3496 Q_ASSERT(edit);
3497 if ( edit )
3498 edit->insertWPPage();
3499 } else {
3500 KWInsertPageDia dlg( this, "insertpage");
3501 if ( dlg.exec())
3502 {
3503 // If 'before', subtract 1 to the page number
3504 int page = m_currentPage->pageNumber();
3505 KCommand* cmd = new KWInsertRemovePageCommand( m_doc, KWInsertRemovePageCommand::Insert, dlg.insertPagePos()==KW_INSERTPAGEAFTER ? page : (page -1));
3506 cmd->execute();
3507 m_doc->addCommand( cmd );
3508 }
3509 }
3510}
3511
3512void KWView::deletePage()
3513{
3514 KCommand* cmd = new KWInsertRemovePageCommand( m_doc, KWInsertRemovePageCommand::Remove, m_currentPage->pageNumber() );
3515 cmd->execute();
3516 m_doc->addCommand( cmd );
3517 if(m_doc->lastPage() > m_currentPage->pageNumber())
3518 m_currentPage = m_doc->pageManager()->page( m_doc->lastPage() );
3519}
3520
3521void KWView::insertLink()
3522{
3523 KWTextFrameSetEdit *edit=currentTextEdit();
3524 if ( !edit )
3525 return;
3526 TQString link;
3527 TQString ref;
3528 if ( edit->textFrameSet()->hasSelection() )
3529 {
3530 TQString selectedText = edit->textFrameSet()->textObject()->selectedText();
3531 if ( edit->textFrameSet()->textObject()->selectionHasCustomItems() || selectedText.contains('\n') )
3532 return;
3533 if ( selectedText.startsWith( "mailto:/" ) ||
3534 selectedText.startsWith( "ftp:/" ) ||
3535 selectedText.startsWith( "http:/" ) )
3536 {
3537 link=selectedText;
3538 ref = selectedText;
3539 }
3540 else
3541 {
3542 //Just add text as link name and not url
3543 link = selectedText;
3544 }
3545 }
3546
3547 if(KoInsertLinkDia::createLinkDia(link, ref, m_doc->listOfBookmarkName(0), true, this))
3548 {
3549 if(!link.isEmpty() && !ref.isEmpty())
3550 edit->insertLink(link, ref);
3551 }
3552}
3553
3554void KWView::insertComment()
3555{
3556 KWTextFrameSetEdit *edit=currentTextEdit();
3557 if ( !edit )
3558 return;
3559 TQString authorName;
3560 KoDocumentInfo * info = m_doc->documentInfo();
3561 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
3562 if ( !authorPage )
3563 kdWarning() << "Author information not found in documentInfo !" << endl;
3564 else
3565 authorName = authorPage->fullName();
3566
3567 KoCommentDia *commentDia = new KoCommentDia( this, TQString(),authorName );
3568 if( commentDia->exec() )
3569 {
3570 edit->insertComment(commentDia->commentText());
3571 }
3572 delete commentDia;
3573}
3574
3575
3576void KWView::insertVariable()
3577{
3578 KWTextFrameSetEdit * edit = currentTextEdit();
3579 if ( edit )
3580 {
3581 TDEAction * act = (TDEAction *)(sender());
3582 VariableDefMap::Iterator it = m_variableDefMap.find( act );
3583 if ( it == m_variableDefMap.end() )
3584 kdWarning() << "Action not found in m_variableDefMap." << endl;
3585 else
3586 {
3587 if ( (*it).type == VT_FIELD )
3588 edit->insertVariable( (*it).type, KoFieldVariable::fieldSubType( (*it).subtype ) );
3589 else
3590 edit->insertVariable( (*it).type, (*it).subtype );
3591 }
3592 }
3593}
3594
3595void KWView::insertFootNote()
3596{
3597 KWTextFrameSetEdit * edit = currentTextEdit();
3598 //Q_ASSERT( edit ); // the action should be disabled if we're not editing a textframeset...
3599 if ( edit ) // test for dcop call !
3600 {
3601 if ( edit->frameSet() != m_doc->frameSet(0) )
3602 {
3603 KMessageBox::sorry( this,
3604 i18n( "You can only insert footnotes or "
3605 "endnotes into the first frameset."),
3606 i18n("Insert Footnote"));
3607 } else {
3608 KWFootNoteDia dia( m_gui->canvasWidget()->footNoteType(), m_gui->canvasWidget()->numberingFootNoteType(), TQString(), this, m_doc, 0 );
3609 TQPtrListIterator<KoTextCustomItem> it( edit->textDocument()->allCustomItems() );
3610 for ( ; it.current() ; ++it )
3611 {
3612 KWFootNoteVariable *fnv = dynamic_cast<KWFootNoteVariable *>( it.current() );
3613 if (fnv && !fnv->isDeleted() && fnv->frameSet() && !fnv->frameSet()->isDeleted() &&
3614 fnv->numberingType()==KWFootNoteVariable::Manual )
3615 dia.appendManualFootNote( fnv->text() );
3616 }
3617 if ( dia.exec() ) {
3618 edit->insertFootNote( dia.noteType(), dia.numberingType(), dia.manualString() );
3619 m_gui->canvasWidget()->setFootNoteType( dia.noteType() );
3620 m_gui->canvasWidget()->setNumberingFootNoteType( dia.numberingType() );
3621 }
3622 }
3623 }
3624}
3625
3626void KWView::updateTocActionText(bool hasToc)
3627{
3628 TDEActionCollection * coll = actionCollection();
3629 TQString name= hasToc ? i18n("Update Table of &Contents"):i18n("Table of &Contents");
3630 coll->action("insert_contents")->setText(name);
3631}
3632
3633void KWView::insertContents()
3634{
3635 KWTextFrameSetEdit *edit = currentTextEdit();
3636 if (edit)
3637 edit->insertTOC();
3638}
3639
3640void KWView::formatFont()
3641{
3642 KoTextFormatInterface* textIface = applicableTextInterfaces().first();
3643
3644 if ( !textIface || !textIface->currentFormat() )
3645 return;
3646
3647 delete m_fontDlg;
3648 m_fontDlg = new KoFontDia( *textIface->currentFormat()
3649 , m_broker
3650 , this, "" );
3651
3652 connect( m_fontDlg, TQ_SIGNAL( applyFont() ),
3653 this, TQ_SLOT( slotApplyFont() ) );
3654
3655 m_fontDlg->exec();
3656 delete m_fontDlg;
3657 m_fontDlg=0L;
3658
3659 //m_gui->canvasWidget()->setFocus();
3660}
3661
3662void KWView::slotApplyFont()
3663{
3664 int flags = m_fontDlg->changedFlags();
3665 if ( flags )
3666 {
3667 KMacroCommand *globalCmd = new KMacroCommand(i18n("Change Font"));
3668 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
3669 TQPtrListIterator<KoTextFormatInterface> it( lst );
3670 for ( ; it.current() ; ++it )
3671 {
3672 KoTextFormat newFormat = m_fontDlg->newFormat();
3673 KCommand *cmd = it.current()->setFormatCommand( &newFormat, flags, true);
3674 if (cmd)
3675 globalCmd->addCommand(cmd);
3676 }
3677 m_doc->addCommand(globalCmd);
3678 m_gui->canvasWidget()->setFocus(); // the combo keeps focus...
3679 }
3680
3681}
3682
3683void KWView::formatParagraph()
3684{
3685 showParagraphDialog();
3686}
3687
3688void KWView::showParagraphDialog( int initialPage, double initialTabPos )
3689{
3690 KWTextFrameSetEdit *edit = currentTextEdit();
3691 if (edit)
3692 {
3693 delete m_paragDlg;
3694 bool showFrameEndOptions = !edit->frameSet()->isHeaderOrFooter() &&
3695 !edit->frameSet()->groupmanager();
3696 m_paragDlg = new KoParagDia( this, "",
3697 KoParagDia::PD_SPACING | KoParagDia::PD_ALIGN |
3698 KoParagDia::PD_DECORATION | KoParagDia::PD_NUMBERING |
3699 KoParagDia::PD_TABS,
3700 m_doc->unit(),
3701 edit->textFrameSet()->frame(0)->width(),
3702 showFrameEndOptions,
3703 edit->frameSet()->isFootEndNote());
3704 m_paragDlg->setCaption( i18n( "Paragraph Settings" ) );
3705
3706 // Initialize the dialog from the current paragraph's settings
3707 m_paragDlg->setParagLayout( edit->cursor()->parag()->paragLayout() );
3708
3709 // Set initial page and initial tabpos if necessary
3710 if ( initialPage != -1 )
3711 {
3712 m_paragDlg->setCurrentPage( initialPage );
3713 if ( initialPage == KoParagDia::PD_TABS )
3714 m_paragDlg->tabulatorsWidget()->setCurrentTab( initialTabPos );
3715 }
3716 connect( m_paragDlg, TQ_SIGNAL( applyParagStyle() ), this, TQ_SLOT( slotApplyParag()));
3717
3718 m_paragDlg->exec();
3719 delete m_paragDlg;
3720 m_paragDlg=0L;
3721 }
3722
3723}
3724
3725void KWView::slotApplyParag()
3726{
3727 KWTextFrameSetEdit *edit = currentTextEdit();
3728 if( !edit)
3729 return;
3730 KMacroCommand * macroCommand = 0L;
3731 KCommand *cmd=0L;
3732 if(m_paragDlg->isLeftMarginChanged())
3733 {
3734 cmd=edit->setMarginCommand( TQStyleSheetItem::MarginLeft, m_paragDlg->leftIndent() );
3735 if(cmd)
3736 {
3737 if ( !macroCommand )
3738 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3739 macroCommand->addCommand(cmd);
3740 }
3741 m_gui->getHorzRuler()->setLeftIndent( KoUnit::toUserValue( m_paragDlg->leftIndent(), m_doc->unit() ) );
3742
3743 }
3744
3745 if(m_paragDlg->isRightMarginChanged())
3746 {
3747 cmd=edit->setMarginCommand( TQStyleSheetItem::MarginRight, m_paragDlg->rightIndent() );
3748 if(cmd)
3749 {
3750 if ( !macroCommand )
3751 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3752 macroCommand->addCommand(cmd);
3753 }
3754 m_gui->getHorzRuler()->setRightIndent( KoUnit::toUserValue( m_paragDlg->rightIndent(), m_doc->unit() ) );
3755 }
3756 if(m_paragDlg->isSpaceBeforeChanged())
3757 {
3758 cmd=edit->setMarginCommand( TQStyleSheetItem::MarginTop, m_paragDlg->spaceBeforeParag() );
3759 if(cmd)
3760 {
3761 if ( !macroCommand )
3762 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3763 macroCommand->addCommand(cmd);
3764 }
3765 }
3766 if(m_paragDlg->isSpaceAfterChanged())
3767 {
3768 cmd=edit->setMarginCommand( TQStyleSheetItem::MarginBottom, m_paragDlg->spaceAfterParag() );
3769 if(cmd)
3770 {
3771 if ( !macroCommand )
3772 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3773 macroCommand->addCommand(cmd);
3774 }
3775 }
3776 if(m_paragDlg->isFirstLineChanged())
3777 {
3778 cmd=edit->setMarginCommand( TQStyleSheetItem::MarginFirstLine, m_paragDlg->firstLineIndent());
3779 if(cmd)
3780 {
3781 if ( !macroCommand )
3782 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3783 macroCommand->addCommand(cmd);
3784 }
3785 m_gui->getHorzRuler()->setFirstIndent(
3786 KoUnit::toUserValue( m_paragDlg->firstLineIndent(), m_doc->unit() ) );
3787 }
3788
3789 if(m_paragDlg->isAlignChanged())
3790 {
3791 cmd=edit->setAlignCommand( m_paragDlg->align() );
3792 if(cmd)
3793 {
3794 if ( !macroCommand )
3795 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3796 macroCommand->addCommand(cmd);
3797 }
3798 }
3799 if(m_paragDlg->isCounterChanged())
3800 {
3801 cmd=edit->setCounterCommand( m_paragDlg->counter() );
3802 if(cmd)
3803 {
3804 if ( !macroCommand )
3805 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3806 macroCommand->addCommand(cmd);
3807 }
3808 }
3809 if(m_paragDlg->listTabulatorChanged())
3810 {
3811 cmd=edit->setTabListCommand( m_paragDlg->tabListTabulator() );
3812 if(cmd)
3813 {
3814 if ( !macroCommand )
3815 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3816 macroCommand->addCommand(cmd);
3817 }
3818 }
3819
3820 if(m_paragDlg->isLineSpacingChanged())
3821 {
3822 cmd=edit->setLineSpacingCommand( m_paragDlg->lineSpacing(),m_paragDlg->lineSpacingType() );
3823 if(cmd)
3824 {
3825 if ( !macroCommand )
3826 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3827
3828 macroCommand->addCommand(cmd);
3829 }
3830 }
3831 if(m_paragDlg->isBorderChanged())
3832 {
3833 cmd=edit->setBordersCommand( m_paragDlg->leftBorder(),
3834 m_paragDlg->rightBorder(),
3835 m_paragDlg->topBorder(),
3836 m_paragDlg->bottomBorder() );
3837 if(cmd)
3838 {
3839 if ( !macroCommand )
3840 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3841
3842 macroCommand->addCommand(cmd);
3843 }
3844 }
3845 if( m_paragDlg->isJoinBorderChanged() )
3846 {
3847 cmd=edit->setJoinBordersCommand( m_paragDlg->joinBorder() );
3848 if(cmd)
3849 {
3850 if ( !macroCommand )
3851 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3852
3853 macroCommand->addCommand(cmd);
3854 }
3855 }
3856 if ( m_paragDlg->isPageBreakingChanged() )
3857 {
3858 cmd=edit->setPageBreakingCommand( m_paragDlg->pageBreaking() );
3859 if(cmd)
3860 {
3861 if ( !macroCommand )
3862 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3863
3864 macroCommand->addCommand(cmd);
3865 }
3866 }
3867
3868 if ( m_paragDlg->isBackgroundColorChanged() )
3869 {
3870 cmd=edit->setBackgroundColorCommand( m_paragDlg->backgroundColor() );
3871 if(cmd)
3872 {
3873 if ( !macroCommand )
3874 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
3875
3876 macroCommand->addCommand(cmd);
3877 }
3878 }
3879
3880 if(macroCommand)
3881 m_doc->addCommand(macroCommand);
3882 // Set "oldLayout" in KoParagDia from the current paragraph's settings
3883 // Otherwise "isBlahChanged" will return wrong things when doing A -> B -> A
3884 m_paragDlg->setParagLayout( edit->cursor()->parag()->paragLayout() );
3885}
3886
3887// This handles Tabulators _only_
3888void KWView::slotHRulerDoubleClicked( double ptpos )
3889{
3890 showParagraphDialog( KoParagDia::PD_TABS, ptpos );
3891}
3892
3893// This handles either:
3894// - Indents
3895// - Page Layout
3896//
3897// This does _not_ handle Tabulators!
3898void KWView::slotHRulerDoubleClicked()
3899{
3900 TQString mode = viewMode()->type();
3901 bool state = (mode!="ModeText");
3902 if ( !state )
3903 return;
3904
3905 KoRuler *ruler = m_gui->getHorzRuler ();
3906 if ( (ruler->flags() & KoRuler::F_INDENTS) && currentTextEdit() ) {
3907 if ( ruler->doubleClickedIndent () ) {
3908 formatParagraph();
3909 return;
3910 }
3911 }
3912
3913 formatPage();
3914}
3915
3916void KWView::formatPage()
3917{
3918 if( !m_doc->isReadWrite())
3919 return;
3920 TQString mode = viewMode()->type();
3921 bool state = (mode!="ModeText");
3922 if ( !state )
3923 return;
3924
3925 KoPageLayout pgLayout;
3926 KoColumns cl;
3927 KoKWHeaderFooter kwhf;
3928 m_doc->getPageLayout( pgLayout, cl, kwhf );
3929
3930 KWPageLayoutStruct oldLayout( pgLayout, cl, kwhf );
3931
3932 KoHeadFoot hf;
3933 int flags = FORMAT_AND_BORDERS | DISABLE_UNIT;
3934 if ( m_doc->processingType() == KWDocument::WP )
3935 flags |= KW_HEADER_AND_FOOTER | COLUMNS;
3936 else
3937 flags |= DISABLE_BORDERS;
3938
3939 KoUnit::Unit unit = m_doc->unit();
3940 KoUnit::Unit oldUnit = unit;
3941
3942 if ( KoPageLayoutDia::pageLayout( pgLayout, hf, cl, kwhf, flags, unit, this ) )
3943 {
3944 if( !(oldLayout._pgLayout==pgLayout) ||
3945 oldLayout._cl != cl ||
3946 oldLayout._hf != kwhf )
3947 {
3948 KWPageLayoutStruct newLayout( pgLayout, cl, kwhf );
3949
3950 KWTextFrameSetEdit *edit = currentTextEdit();
3951 if (edit)
3952 edit->textFrameSet()->clearUndoRedoInfo();
3953 KCommand *cmd =new KWPageLayoutCommand( i18n("Change Layout"),
3954 m_doc, oldLayout, newLayout );
3955 m_doc->addCommand(cmd);
3956
3957 m_doc->setPageLayout( pgLayout, cl, kwhf );
3958 }
3959 if ( unit != oldUnit )
3960 m_doc->setUnit( unit ); // ##### needs undo/redo support
3961 }
3962}
3963
3964void KWView::formatFrameSet()
3965{
3966 if ( frameViewManager()->selectedFrame() )
3967 {
3968 m_gui->canvasWidget()->editFrameProperties();
3969 }
3970 else // Should never happen, the action is disabled
3971 KMessageBox::sorry( this,
3972 i18n("You must select a frame first."),
3973 i18n("Format Frameset"));
3974}
3975
3976void KWView::slotSpellCheck()
3977{
3978 if (m_spell.kospell) return; // Already in progress
3979 //m_doc->setReadWrite(false); // prevent editing text - not anymore
3980 m_spell.macroCmdSpellCheck = 0L;
3981 m_spell.replaceAll.clear();
3982 TQValueList<KoTextObject *> objects;
3983 KWTextFrameSetEdit * edit = currentTextEdit();
3984 if (!edit)
3985 return;
3986 int options = 0;
3987 if ( edit && edit->textFrameSet()->hasSelection() )
3988 {
3989 objects.append(edit->textFrameSet()->textObject());
3990 options = KFindDialog::SelectedText;
3991 }
3992 else
3993 {
3994 objects = m_gui->canvasWidget()->kWordDocument()->visibleTextObjects(viewMode());
3995 }
3996 m_spell.textIterator = new KoTextIterator( objects, edit, options );
3997 kdDebug()<<"Created iterator with "<< objects.count() <<endl;
3998 startKSpell();
3999}
4000
4001void KWView::extraAutoFormat()
4002{
4003 m_doc->autoFormat()->readConfig();
4004 KoAutoFormatDia dia( this, 0, m_doc->autoFormat() );
4005 dia.exec();
4006 m_doc->startBackgroundSpellCheck(); // will do so if enabled
4007}
4008
4009void KWView::extraFrameStylist()
4010{
4011 KWTextFrameSetEdit * edit = currentTextEdit();
4012 if ( edit )
4013 edit->hideCursor();
4014 KWFrameStyleManager * frameStyleManager = new KWFrameStyleManager( this, m_doc, TQString() );
4015 frameStyleManager->exec();
4016 delete frameStyleManager;
4017 if ( edit )
4018 edit->showCursor();
4019}
4020
4021void KWView::createFrameStyle()
4022{
4023
4024 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
4025 if (selectedFrames.count() != 1)
4026 return;
4027
4028 KWFrame* frame = selectedFrames[0]->frame();
4029
4030 KoCreateStyleDia *dia = new KoCreateStyleDia( m_doc->frameStyleCollection()->displayNameList(), this, 0 );
4031 if ( dia->exec() )
4032 {
4033 KWFrameStyle *style= new KWFrameStyle( dia->nameOfNewStyle(), frame );
4034 m_doc->frameStyleCollection()->addStyle( style );
4035 m_doc->updateAllFrameStyleLists();
4036 }
4037 delete dia;
4038}
4039
4040void KWView::extraStylist()
4041{
4042 KWTextFrameSetEdit * edit = currentTextEdit();
4043 TQString activeStyleName = TQString();
4044 if ( edit )
4045 {
4046 edit->hideCursor();
4047 if (edit->cursor() && edit->cursor()->parag() && edit->cursor()->parag()->style())
4048 activeStyleName = edit->cursor()->parag()->style()->displayName();
4049 }
4050 KWStyleManager * styleManager = new KWStyleManager( this, m_doc->unit(),m_doc, *m_doc->styleCollection(), activeStyleName );
4051 styleManager->exec();
4052 delete styleManager;
4053 if ( edit )
4054 edit->showCursor();
4055}
4056
4057void KWView::extraCreateTemplate()
4058{
4059 int width = 60;
4060 int height = 60;
4061 TQPixmap pix = m_doc->generatePreview(TQSize(width, height));
4062
4063 KTempFile tempFile( TQString(), ".odt" );
4064 tempFile.setAutoDelete(true);
4065
4066 m_doc->saveNativeFormat( tempFile.name() );
4067
4068 KoTemplateCreateDia::createTemplate( "kword_template", KWFactory::instance(),
4069 tempFile.name(), pix, this );
4070
4071 KWFactory::instance()->dirs()->addResourceType("kword_template",
4072 TDEStandardDirs::kde_default( "data" ) +
4073 "kword/templates/");
4074}
4075
4076void KWView::toolsCreateText()
4077{
4078 if ( m_actionToolsCreateText->isChecked() )
4079 m_gui->canvasWidget()->setMouseMode( KWCanvas::MM_CREATE_TEXT );
4080 else
4081 {
4082 // clicked on the already active tool -> abort
4083 m_gui->canvasWidget()->setMouseMode( KWCanvas::MM_EDIT );
4084 }
4085}
4086
4087void KWView::insertTable()
4088{
4089 KWCanvas * canvas = m_gui->canvasWidget();
4090 canvas->setMouseMode( KWCanvas::MM_EDIT );
4091 KWTableDia *tableDia = new KWTableDia( this, 0, KWTableDia::NEW, canvas, m_doc,
4092 canvas->tableRows(),
4093 canvas->tableCols(),
4094 canvas->tableWidthMode(),
4095 canvas->tableHeightMode(),
4096 canvas->tableIsFloating(),
4097 canvas->tableTemplateName(),
4098 canvas->tableFormat());
4099 tableDia->setCaption( i18n( "Insert Table" ) );
4100 if ( tableDia->exec() == TQDialog::Rejected )
4101 canvas->setMouseMode( KWCanvas::MM_EDIT );
4102 delete tableDia;
4103}
4104
4105void KWView::insertFormula( TQMimeSource* source )
4106{
4107 KWTextFrameSetEdit *edit = currentTextEdit();
4108 if (edit)
4109 {
4110 KWFormulaFrameSet *frameset = new KWFormulaFrameSet( m_doc, TQString() );
4111 m_doc->addFrameSet( frameset, false ); // done first since the frame number is stored in the undo/redo
4112 if ( source ) {
4113 TQByteArray data = source->encodedData( KFormula::MimeSource::selectionMimeType() );
4114 TQDomDocument formula;
4115 formula.setContent( data );
4116 TQDomElement formulaElem = formula.namedItem("math").toElement();
4117 frameset->paste( formulaElem );
4118 }
4119 KWFrame *frame = new KWFrame(frameset, 0, 0, 10, 10 );
4120 frame->setZOrder( m_doc->maxZOrder( frame->pageNumber(m_doc) ) + 1 ); // make sure it's on top
4121 frameset->addFrame( frame, false );
4122 edit->insertFloatingFrameSet( frameset, i18n("Insert Formula") );
4123 frameset->finalize(); // done last since it triggers a redraw
4124 m_doc->refreshDocStructure(FT_FORMULA);
4125
4126 m_gui->canvasWidget()->editFrameSet( frameset );
4127 frameset->setChanged();
4128 m_gui->canvasWidget()->repaintChanged( frameset, true );
4129 }
4130}
4131
4132void KWView::toolsPart()
4133{
4134 m_gui->canvasWidget()->insertPart( m_actionToolsCreatePart->documentEntry() );
4135}
4136
4137
4138int KWView::tableSelectCell(const TQString &tableName, uint row, uint col)
4139{
4140 if(!m_doc || !m_gui)
4141 return -1;
4142 KWFrameSet *fs = m_doc->frameSetByName(tableName);
4143 if(!fs)
4144 return -1;
4145 KWTableFrameSet *table = dynamic_cast<KWTableFrameSet*>(fs);
4146 if(!table)
4147 return -1;
4148 if (row >= table->getRows() || col >= table->getColumns())
4149 return -1;
4150
4151 KWTableFrameSet::Cell *cell = table->cell(row, col);
4152
4153 KWCanvas *canvas = m_gui->canvasWidget();
4154 if(!canvas)
4155 return -1;
4156 canvas->tableSelectCell(table, cell);
4157 return 0;
4158}
4159
4160int KWView::tableDeleteRow(const TQValueList<uint>& rows, KWTableFrameSet *table )
4161{
4162 if(!table)
4163 table = m_gui->canvasWidget()->getCurrentTable();
4164
4165 if (!m_doc || !table)
4166 return -1;
4167
4168 if(rows.count() >= table->getRows()) {
4169 m_doc->deleteTable(table);
4170 return 0;
4171 }
4172
4173 KMacroCommand *macro = new KMacroCommand(i18n("Remove Rows"));
4174
4175 for (int i = rows.count() - 1; i >= 0 ; i--) {
4176 KWRemoveRowCommand *cmd = new KWRemoveRowCommand( i18n("Remove Row"),
4177 table, rows[i] );
4178 macro->addCommand(cmd);
4179 }
4180
4181 macro->execute();
4182 m_doc->addCommand(macro);
4183 return 0;
4184}
4185
4186int KWView::tableDeleteCol(const TQValueList<uint>& cols, KWTableFrameSet *table)
4187{
4188 if(!table)
4189 table = m_gui->canvasWidget()->getCurrentTable();
4190
4191 if (!m_doc || !table)
4192 return -1;
4193
4194 if(cols.count() >= table->getColumns()) {
4195 m_doc->deleteTable(table);
4196 return 0;
4197 }
4198
4199 KMacroCommand *macro = new KMacroCommand(i18n("Remove Columns"));
4200
4201 for (int i = cols.count() - 1; i >= 0; i--) {
4202 KWRemoveColumnCommand *cmd = new KWRemoveColumnCommand( i18n("Remove Column"),
4203 table, cols[i] );
4204 macro->addCommand(cmd);
4205 }
4206
4207 macro->execute();
4208 m_doc->addCommand(macro);
4209 return 0;
4210}
4211
4212void KWView::tableProperties()
4213{
4214 KWCanvas * canvas = m_gui->canvasWidget();
4215 KWTableFrameSet *table = canvas->getCurrentTable();
4216 if (table)
4217 {
4218 canvas->setMouseMode( KWCanvas::MM_EDIT );
4219 KWTableDia *tableDia = new KWTableDia( this, 0, KWTableDia::EDIT, canvas, m_doc,
4220 table->getRows(),
4221 table->getColumns(),
4222 canvas->tableWidthMode(),
4223 canvas->tableHeightMode(),
4224 canvas->tableIsFloating(),
4225 canvas->tableTemplateName(),
4226 canvas->tableFormat());
4227 tableDia->setCaption( i18n( "Adjust Table" ) );
4228 if ( tableDia->exec() == TQDialog::Rejected )
4229 canvas->setMouseMode( KWCanvas::MM_EDIT );
4230 delete tableDia;
4231 }
4232}
4233
4234void KWView::tableInsertRow()
4235{
4236 TableInfo ti(frameViewManager()->selectedFrames());
4237 KWTableFrameSet::Cell *cell = ti.firstSelectedCell();
4238 if(! cell) return;
4239
4240 KWInsertDia dia( this, cell->groupmanager(), KWInsertDia::insertRow, cell->firstRow());
4241 dia.exec();
4242}
4243
4244void KWView::tableInsertRow(uint row, KWTableFrameSet *table)
4245{
4246 if(!table)
4247 table = m_gui->canvasWidget()->getCurrentTable();
4248
4249 if (!m_doc || !table)
4250 return;
4251
4252 if(row > table->getRows())
4253 return;
4254
4255 KWInsertRowCommand *cmd = new KWInsertRowCommand( i18n("Insert Row"), table, row);
4256 cmd->execute();
4257 m_doc->addCommand(cmd);
4258}
4259
4260
4261void KWView::tableInsertCol()
4262{
4263 TableInfo ti(frameViewManager()->selectedFrames());
4264 KWTableFrameSet::Cell *cell = ti.firstSelectedCell();
4265 if(! cell) return;
4266
4267 KWInsertDia dia( this, cell->groupmanager(), KWInsertDia::insertColumn, cell->firstColumn());
4268 dia.exec();
4269}
4270
4271void KWView::tableInsertCol(uint col, KWTableFrameSet *table )
4272{
4273 if(!table)
4274 table = m_gui->canvasWidget()->getCurrentTable();
4275
4276 if (!m_doc || !table)
4277 return;
4278
4279 if(col > table->getColumns())
4280 return;
4281
4282 // we pass as last parameter the maximum offset that the table can use.
4283 // this offset is the max right offset of the containing frame in the case
4284 // of an inline (floating) table, the size of the page for other tables.
4285 double maxRightOffset;
4286 if (table->isFloating()) // inline table: max offset of containing frame
4287 maxRightOffset = table->anchorFrameset()->frame(0)->right();
4288 else { // non inline table: max offset of the page
4289 KWPage *page = m_doc->pageManager()->page( table->cell(0,0)->frame(0) );
4290 maxRightOffset = page->width() - page->rightMargin();
4291 }
4292
4293 KWInsertColumnCommand *cmd = new KWInsertColumnCommand( i18n("Insert Column"),
4294 table, col, maxRightOffset);
4295 cmd->execute();
4296 m_doc->addCommand(cmd);
4297}
4298
4299void KWView::tableDeleteRow()
4300{
4301 TableInfo ti( frameViewManager()->selectedFrames() );
4302 if(ti.amountRowsSelected() == 0) return;
4303
4304 KWDeleteDia dia( this, ti.firstSelectedCell()->groupmanager(),
4305 KWDeleteDia::deleteRow, ti.selectedRows() );
4306 dia.exec();
4307}
4308
4309void KWView::tableDeleteCol()
4310{
4311 TableInfo ti( frameViewManager()->selectedFrames() );
4312 if(ti.amountColumnsSelected() == 0) return;
4313
4314 KWDeleteDia dia( this, ti.firstSelectedCell()->groupmanager(),
4315 KWDeleteDia::deleteColumn, ti.selectedColumns() );
4316 dia.exec();
4317}
4318
4319void KWView::tableResizeCol()
4320{
4321 TableInfo ti( frameViewManager()->selectedFrames() );
4322 KWTableFrameSet::Cell *cell = ti.firstSelectedCell();
4323 if(cell == 0)
4324 return;
4325 KWResizeTableDia dia(this, cell->groupmanager(), m_doc, cell->firstColumn());
4326 dia.exec();
4327}
4328
4329void KWView::tableJoinCells()
4330{
4331 KWTableFrameSet *table = 0;
4332 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
4333 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
4334 unsigned int x1=10000, y1=10000, x2=0, y2=0;
4335 for(;framesIterator != selectedFrames.end(); ++framesIterator) {
4336 KWFrameView *view = *framesIterator;
4337 if(!view->selected()) continue;
4338 KWFrameSet *fs = view->frame()->frameSet();
4339 Q_ASSERT(fs);
4340 KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell*>(fs);
4341 if(cell == 0) continue;
4342 if(!table)
4343 table = cell->groupmanager();
4344 else if(table != cell->groupmanager()) { // more then one table has selected cells
4345 KMessageBox::sorry( this,
4346 i18n( "More then one table has selected cells, please make sure "
4347 "the selected cells are in one table and are connecting"),
4348 i18n( "Join Cells Failed" ) );
4349 return;
4350 }
4351
4352 if(cell->firstRow() < y1) y1 = cell->firstRow();
4353 if(cell->firstColumn() < x1) x1 = cell->firstColumn();
4354 if(cell->lastRow() > y2) y2 = cell->lastRow();
4355 if(cell->lastColumn() > x2) x2 = cell->lastColumn();
4356 }
4357
4358 Q_ASSERT(table);
4359 if (!table)
4360 return;
4361 KCommand * cmd=table->joinCells(x1, y1, x2, y2);
4362 if ( !cmd )
4363 {
4364 KMessageBox::sorry( this,
4365 i18n( "You have to select some cells which are next to each other "
4366 "and are not already joined." ),
4367 i18n( "Join Cells" ) );
4368 return;
4369 }
4370 m_doc->addCommand(cmd);
4371 m_doc->layout();
4372}
4373
4374void KWView::tableSplitCells() {
4375 KWSplitCellDia *splitDia=new KWSplitCellDia( this,"split cell",
4376 m_tableSplit.columns, m_tableSplit.rows );
4377 if(splitDia->exec()) {
4378 m_tableSplit.rows = splitDia->rows();
4379 m_tableSplit.columns = splitDia->columns();
4380 tableSplitCells( m_tableSplit.columns, m_tableSplit.rows );
4381 }
4382 delete splitDia;
4383}
4384
4385void KWView::tableSplitCells(int cols, int rows)
4386{
4387 TableInfo ti( frameViewManager()->selectedFrames() );
4388 if(! ti.oneCellSelected()) {
4389 KMessageBox::sorry( this,
4390 i18n( "You have to put the cursor into a table "
4391 "before splitting cells." ),
4392 i18n( "Split Cells" ) );
4393 return;
4394 }
4395
4396 KWTableFrameSet::Cell *cell = ti.firstSelectedCell();
4397 KCommand *cmd=cell->groupmanager()->splitCell(rows, cols, cell->firstColumn(), cell->firstRow());
4398 if ( !cmd ) {
4399 KMessageBox::sorry( this,
4400 i18n("There is not enough space to split the cell into that many parts, make it bigger first"),
4401 i18n("Split Cells") );
4402 return;
4403 }
4404 m_doc->addCommand(cmd);
4405 m_doc->updateAllFrames();
4406 m_doc->layout();
4407 frameViewManager()->view(cell->frame(0))->setSelected(true);
4408}
4409
4410void KWView::tableUngroupTable()
4411{
4412 m_gui->canvasWidget()->setMouseMode( KWCanvas::MM_EDIT );
4413
4414 KWTableFrameSet *table = m_gui->canvasWidget()->getCurrentTable();
4415 Q_ASSERT(table);
4416 if (!table)
4417 return;
4418
4419 // Use a macro command because we may have to make the table non-floating first
4420 KMacroCommand * macroCmd = new KMacroCommand( i18n( "Ungroup Table" ) );
4421
4422 if ( table->isFloating() )
4423 {
4424 KWFrameSetInlineCommand *cmd = new KWFrameSetInlineCommand( TQString(), table, false );
4425 macroCmd->addCommand(cmd);
4426 }
4427
4428 KWUngroupTableCommand *cmd = new KWUngroupTableCommand( TQString(), table );
4429 macroCmd->addCommand( cmd );
4430 m_doc->addCommand( macroCmd );
4431 macroCmd->execute(); // do it all
4432}
4433
4434void KWView::tableDelete()
4435{
4436 KWTableFrameSet *table = m_gui->canvasWidget()->getCurrentTable();
4437 Q_ASSERT(table);
4438 if (!table)
4439 return;
4440 m_doc->deleteTable( table );
4441}
4442
4443void KWView::tableStylist()
4444{
4445 KWTextFrameSetEdit * edit = currentTextEdit();
4446 if ( edit )
4447 edit->hideCursor();
4448 KWTableStyleManager * tableStyleManager = new KWTableStyleManager( this, m_doc );
4449 tableStyleManager->exec();
4450 delete tableStyleManager;
4451 if ( edit )
4452 edit->showCursor();
4453}
4454
4455void KWView::tableProtectCells(bool on)
4456{
4457 KMacroCommand *macro = 0;
4458 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
4459 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
4460 for(;framesIterator != selectedFrames.end(); ++framesIterator) {
4461 KWFrameView *view = *framesIterator;
4462 KWFrameSet *fs = view->frame()->frameSet();
4463 Q_ASSERT(fs);
4464 KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell*>(fs);
4465 if(cell == 0) continue;
4466 if(cell->protectContent() != on) {
4467 KWProtectContentCommand *cmd = new KWProtectContentCommand( i18n("Protect Content"), cell , on);
4468 if ( !macro )
4469 macro = new KMacroCommand( i18n("Protect Content"));
4470 macro->addCommand( cmd );
4471 }
4472 }
4473 if(macro) {
4474 macro->execute();
4475 m_doc->addCommand( macro );
4476 }
4477}
4478
4479void KWView::textStyleSelected( KoParagStyle *sty )
4480{
4481 if ( !sty )
4482 return;
4483
4484 if ( m_gui->canvasWidget()->currentFrameSetEdit() )
4485 {
4486 KWTextFrameSetEdit * edit = dynamic_cast<KWTextFrameSetEdit *>(m_gui->canvasWidget()->currentFrameSetEdit()->currentTextEdit());
4487 if ( edit )
4488 edit->applyStyle( sty );
4489 }
4490 else
4491 { // it might be that a frame (or several frames) are selected
4492 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
4493 if (selectedFrames.count() <= 0)
4494 return; // nope, no frames are selected.
4495 // yes, indeed frames are selected.
4496
4497 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
4498 KMacroCommand *globalCmd = 0L;
4499 while(framesIterator != selectedFrames.end()) {
4500 KWFrame *curFrame = (*framesIterator)->frame();
4501 KWFrameSet *curFrameSet = curFrame->frameSet();
4502 if (curFrameSet->type() == FT_TEXT)
4503 {
4504 KoTextObject *textObject = ((KWTextFrameSet*)curFrameSet)->textObject();
4505 textObject->textDocument()->selectAll( KoTextDocument::Temp );
4506 KCommand *cmd = textObject->applyStyleCommand( 0L, sty , KoTextDocument::Temp, KoParagLayout::All, KoTextFormat::Format, true, true );
4507 textObject->textDocument()->removeSelection( KoTextDocument::Temp );
4508 if (cmd)
4509 {
4510 if ( !globalCmd )
4511 globalCmd = new KMacroCommand( selectedFrames.count() == 1 ? i18n("Apply Style to Frame") : i18n("Apply Style to Frames"));
4512 globalCmd->addCommand( cmd );
4513 }
4514 }
4515 ++framesIterator;
4516 }
4517 if ( globalCmd )
4518 m_doc->addCommand( globalCmd );
4519 }
4520 m_gui->canvasWidget()->setFocus(); // the combo keeps focus...*/
4521
4522}
4523
4524// Called by the above, and when selecting a style in the style combobox
4525void KWView::textStyleSelected( int index )
4526{
4527 textStyleSelected( m_doc->styleCollection()->styleAt( index ) );
4528}
4529
4530// Slot is called when selecting a framestyle in the Frames / Framestyle menu
4531void KWView::slotFrameStyleSelected()
4532{
4533 TQString actionName = TQString::fromUtf8(sender()->name());
4534 const TQString prefix = FRAMESTYLE_ACTION_PREFIX;
4535 if ( actionName.startsWith( prefix ) ) {
4536 actionName = actionName.mid( prefix.length() );
4537 frameStyleSelected( m_doc->frameStyleCollection()->findStyle( actionName ) );
4538 }
4539}
4540
4541void KWView::frameStyleSelected( int index )
4542{
4543 frameStyleSelected( m_doc->frameStyleCollection()->frameStyleAt( index ) );
4544}
4545
4546
4547// Called by the above, and when selecting a style in the framestyle combobox
4548void KWView::frameStyleSelected( KWFrameStyle *sty )
4549{
4550 if ( !sty )
4551 return;
4552
4553 if ( m_gui->canvasWidget()->currentFrameSetEdit() )
4554 {
4555 KWFrame * single = m_gui->canvasWidget()->currentFrameSetEdit()->currentFrame();
4556 if ( single ) {
4557
4558 KCommand *cmd = new KWFrameStyleCommand( i18n("Apply Framestyle to Frame"), single, sty );
4559 if (cmd) {
4560 m_doc->addCommand( cmd );
4561 cmd->execute();
4562 }
4563 }
4564 }
4565 else
4566 { // it might be that a frame (or several frames) are selected
4567 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
4568 if (selectedFrames.count() <= 0)
4569 return; // nope, no frames are selected.
4570 // yes, indeed frames are selected.
4571
4572 KMacroCommand *globalCmd = new KMacroCommand( selectedFrames.count() == 1 ? i18n("Apply Framestyle to Frame") : i18n("Apply Framestyle to Frames"));
4573
4574 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
4575 while(framesIterator != selectedFrames.end()) {
4576 KWFrame *curFrame = (*framesIterator)->frame();
4577 KCommand *cmd = new KWFrameStyleCommand( i18n("Apply Framestyle"), curFrame, sty );
4578 if (cmd)
4579 globalCmd->addCommand( cmd );
4580 ++framesIterator;
4581 }
4582 m_doc->addCommand( globalCmd );
4583 globalCmd->execute();
4584 }
4585
4586 m_gui->canvasWidget()->repaintAll();
4587 m_gui->canvasWidget()->setFocus(); // the combo keeps focus...*/
4588
4589 // Adjust GUI
4590 const int pos = m_doc->frameStyleCollection()->indexOf( sty );
4591 Q_ASSERT( pos >= 0 );
4592 m_actionFrameStyle->setCurrentItem( pos );
4593 TDEToggleAction* act = dynamic_cast<TDEToggleAction *>(actionCollection()->action( sty->name().utf8().data() ));
4594 if ( act )
4595 act->setChecked( true );
4596}
4597
4598
4599// Called when selecting a tablestyle in the Table / Tablestyle menu
4600void KWView::slotTableStyleSelected()
4601{
4602 TQString actionName = TQString::fromUtf8(sender()->name());
4603 const TQString prefix = TABLESTYLE_ACTION_PREFIX;
4604 if ( actionName.startsWith( prefix ) ) {
4605 actionName = actionName.mid( prefix.length() );
4606 tableStyleSelected( m_doc->tableStyleCollection()->findStyle( actionName ) );
4607 }
4608}
4609
4610void KWView::tableStyleSelected( int index )
4611{
4612 tableStyleSelected( m_doc->tableStyleCollection()->tableStyleAt( index ) );
4613}
4614
4615// Called by the above, and when selecting a style in the framestyle combobox
4616void KWView::tableStyleSelected( KWTableStyle *sty )
4617{
4618 if ( !sty )
4619 return;
4620
4621 if ( m_gui->canvasWidget()->currentFrameSetEdit() )
4622 {
4623 KWFrame * single = m_gui->canvasWidget()->currentFrameSetEdit()->currentFrame();
4624 if ( (single) && ( single->frameSet()->type() == FT_TEXT ) )
4625 {
4626 KCommand *cmd = new KWTableStyleCommand( i18n("Apply Tablestyle to Frame"), single, sty );
4627 if (cmd) {
4628 m_doc->addCommand( cmd );
4629 cmd->execute();
4630 }
4631 }
4632 }
4633 else
4634 {
4635 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
4636 if (selectedFrames.count() <= 0)
4637 return; // nope, no frames are selected.
4638
4639 KMacroCommand *globalCmd = new KMacroCommand( selectedFrames.count() == 1 ? i18n("Apply Tablestyle to Frame") : i18n("Apply Tablestyle to Frames"));
4640
4641 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
4642 while(framesIterator != selectedFrames.end() ) {
4643 KWFrame *curFrame = (*framesIterator)->frame();
4644 if(dynamic_cast<KWTextFrameSet*>(curFrame->frameSet())) {
4645 KCommand *cmd = new KWTableStyleCommand( i18n("Apply Tablestyle to Frame"),
4646 curFrame, sty );
4647 if (cmd)
4648 globalCmd->addCommand( cmd );
4649 }
4650 ++framesIterator;
4651 }
4652 m_doc->addCommand( globalCmd );
4653 globalCmd->execute();
4654 }
4655
4656 m_gui->canvasWidget()->repaintAll();
4657 m_gui->canvasWidget()->setFocus(); // the combo keeps focus...*/
4658
4659 // Adjust GUI
4660 int pos = m_doc->tableStyleCollection()->indexOf( sty );
4661 m_actionTableStyle->setCurrentItem( pos );
4662 TDEToggleAction* act = dynamic_cast<TDEToggleAction *>(actionCollection()->action( sty->name().utf8().data() ));
4663 if ( act )
4664 act->setChecked( true );
4665}
4666
4667void KWView::increaseFontSize()
4668{
4669 KWTextFrameSetEdit * edit = currentTextEdit();
4670 KoTextFormat *format = edit->currentFormat();
4671 if ( edit )
4672 textSizeSelected( edit->textFrameSet()->textObject()->docFontSize( format ) + 1 );
4673}
4674
4675void KWView::decreaseFontSize()
4676{
4677 KWTextFrameSetEdit * edit = currentTextEdit();
4678 KoTextFormat *format = edit->currentFormat();
4679 if ( edit )
4680 textSizeSelected( edit->textFrameSet()->textObject()->docFontSize( format ) - 1 );
4681}
4682
4683void KWView::textSizeSelected( int size )
4684{
4685 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4686 TQPtrListIterator<KoTextFormatInterface> it( lst );
4687 KMacroCommand *globalCmd = new KMacroCommand(i18n("Change Text Size"));
4688 for ( ; it.current() ; ++it )
4689 {
4690 KCommand *cmd = it.current()->setPointSizeCommand( size );
4691 if (cmd)
4692 globalCmd->addCommand(cmd);
4693 }
4694 m_doc->addCommand(globalCmd);
4695 m_gui->canvasWidget()->setFocus(); // the combo keeps focus...
4696}
4697
4698void KWView::textFontSelected( const TQString & font )
4699{
4700 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4701 if ( lst.isEmpty() ) return;
4702 TQPtrListIterator<KoTextFormatInterface> it( lst );
4703 KMacroCommand* macroCmd = 0L;
4704 for ( ; it.current() ; ++it )
4705 {
4706 KCommand *cmd = it.current()->setFamilyCommand( font );
4707 if (cmd)
4708 {
4709 if ( !macroCmd )
4710 macroCmd = new KMacroCommand( i18n("Change Text Font") );
4711 macroCmd->addCommand( cmd );
4712 }
4713 }
4714 if ( macroCmd )
4715 m_doc->addCommand( macroCmd );
4716 m_gui->canvasWidget()->setFocus(); // the combo keeps focus...
4717}
4718
4719TQPtrList<KoTextFormatInterface> KWView::applicableTextInterfaces() const
4720{
4721 TQPtrList<KoTextFormatInterface> lst;
4722 if (currentTextEdit())
4723 {
4724 if ( !currentTextEdit()->textObject()->protectContent())
4725 {
4726 // simply return the current textEdit
4727 lst.append( currentTextEdit() );
4728 //kdDebug() << "text frame name: " << currentTextEdit()->textFrameSet()->name() << endl;
4729 KWCollectFramesetsVisitor visitor;
4730 currentTextEdit()->textDocument()->visitSelection( KoTextDocument::Standard, &visitor ); //find all framesets in the selection
4731 const TQValueList<KWFrameSet *>& frameset = visitor.frameSets();
4732 for ( TQValueList<KWFrameSet *>::ConstIterator it = frameset.begin(); it != frameset.end(); ++it )
4733 {
4734 if ( (*it)->type() == FT_TABLE )
4735 {
4736 KWTableFrameSet* kwtableframeset = static_cast<KWTableFrameSet *>( *it );
4737 //kdDebug() << "table found: " << kwtableframeset->frameCount() << endl;
4738 int const rows = kwtableframeset->getRows();
4739 int const cols = kwtableframeset->getColumns();
4740 //finding all cells and add them to the interface list
4741 for (int r=0; r<rows; ++r)
4742 {
4743 for (int c=0; c<cols; ++c)
4744 {
4745 KWTableFrameSet::Cell *cell = kwtableframeset->cell(r,c);
4746 if (cell)
4747 {
4748 kdDebug() << "adding (" << r << "," << c << ")" << endl;
4749 lst.append(cell);
4750 }
4751 }
4752 }
4753 }
4754 }
4755 }
4756 }
4757 else
4758 { // it might be that a frame (or several frames) are selected
4759 // in that case, list the text framesets behind them
4760 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
4761 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
4762 while(framesIterator != selectedFrames.end()) {
4763 KWTextFrameSet* fs = dynamic_cast<KWTextFrameSet *>( (*framesIterator)->frame()->frameSet() );
4764 if ( fs && !lst.contains( fs )&& !fs->protectContent() )
4765 lst.append( fs );
4766 ++framesIterator;
4767 }
4768 }
4769 return lst;
4770}
4771
4772void KWView::textBold()
4773{
4774 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4775 if ( lst.isEmpty() ) return;
4776 TQPtrListIterator<KoTextFormatInterface> it( lst );
4777 KMacroCommand* macroCmd = 0L;
4778 for ( ; it.current() ; ++it )
4779 {
4780 KCommand *cmd = it.current()->setBoldCommand( m_actionFormatBold->isChecked() );
4781 if (cmd)
4782 {
4783 if ( !macroCmd )
4784 macroCmd = new KMacroCommand( i18n("Make Text Bold") );
4785 macroCmd->addCommand(cmd);
4786 }
4787 }
4788 if(macroCmd)
4789 m_doc->addCommand(macroCmd);
4790
4791}
4792
4793void KWView::textItalic()
4794{
4795 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4796 TQPtrListIterator<KoTextFormatInterface> it( lst );
4797 KMacroCommand* macroCmd = 0L;
4798 for ( ; it.current() ; ++it )
4799 {
4800 KCommand *cmd = it.current()->setItalicCommand( m_actionFormatItalic->isChecked() );
4801 if (cmd)
4802 {
4803 if ( !macroCmd )
4804 macroCmd = new KMacroCommand( i18n("Make Text Italic") );
4805 macroCmd->addCommand( cmd );
4806 }
4807 }
4808 if( macroCmd)
4809 m_doc->addCommand( macroCmd );
4810}
4811
4812void KWView::textUnderline()
4813{
4814 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4815 TQPtrListIterator<KoTextFormatInterface> it( lst );
4816 KMacroCommand* macroCmd = 0L;
4817
4818 for ( ; it.current() ; ++it )
4819 {
4820 KCommand *cmd = it.current()->setUnderlineCommand( m_actionFormatUnderline->isChecked() );
4821 if ( cmd )
4822 {
4823 if ( !macroCmd )
4824 macroCmd = new KMacroCommand( i18n("Underline Text") );
4825 macroCmd->addCommand( cmd );
4826 }
4827 }
4828 if(macroCmd)
4829 m_doc->addCommand( macroCmd );
4830}
4831
4832void KWView::textStrikeOut()
4833{
4834 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4835 TQPtrListIterator<KoTextFormatInterface> it( lst );
4836 KMacroCommand* macroCmd = 0L;
4837 for ( ; it.current() ; ++it )
4838 {
4839 KCommand *cmd = it.current()->setStrikeOutCommand( m_actionFormatStrikeOut->isChecked() );
4840 if ( cmd )
4841 {
4842 if ( !macroCmd )
4843 macroCmd = new KMacroCommand( i18n("Strike Out Text") );
4844 macroCmd->addCommand( cmd );
4845 }
4846 }
4847 if( macroCmd)
4848 m_doc->addCommand( macroCmd );
4849}
4850
4851void KWView::textColor()
4852{
4853 /* TQColor color = edit->textColor();
4854 if ( KColorDialog::getColor( color ) ) {
4855 m_actionFormatColor->setColor( color );
4856 edit->setTextColor( color );
4857 }
4858 */
4859 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4860 if ( lst.isEmpty() ) return;
4861 TQPtrListIterator<KoTextFormatInterface> it( lst );
4862 KMacroCommand* macroCmd = 0L;
4863 for ( ; it.current() ; ++it )
4864 {
4865 KCommand *cmd = it.current()->setTextColorCommand( m_actionFormatColor->color() );
4866 if ( cmd )
4867 {
4868 if ( !macroCmd )
4869 macroCmd = new KMacroCommand( i18n("Set Text Color") );
4870 macroCmd->addCommand( cmd );
4871 }
4872 }
4873 if( macroCmd)
4874 m_doc->addCommand( macroCmd );
4875}
4876
4877void KWView::textAlignLeft()
4878{
4879 if ( m_actionFormatAlignLeft->isChecked() )
4880 {
4881 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4882 TQPtrListIterator<KoTextFormatInterface> it( lst );
4883 KMacroCommand* macroCmd = 0L;
4884 for ( ; it.current() ; ++it )
4885 {
4886 KCommand *cmd = it.current()->setAlignCommand( TQt::AlignLeft );
4887 if (cmd)
4888 {
4889 if ( !macroCmd)
4890 macroCmd = new KMacroCommand( i18n("Left-Align Text") );
4891 macroCmd->addCommand( cmd );
4892 }
4893 }
4894 if( macroCmd )
4895 m_doc->addCommand( macroCmd );
4896 }
4897 else
4898 m_actionFormatAlignLeft->setChecked( true );
4899}
4900
4901void KWView::textAlignCenter()
4902{
4903 if ( m_actionFormatAlignCenter->isChecked() )
4904 {
4905 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4906 TQPtrListIterator<KoTextFormatInterface> it( lst );
4907 KMacroCommand* macroCmd = 0L;
4908 for ( ; it.current() ; ++it )
4909 {
4910 KCommand *cmd = it.current()->setAlignCommand( TQt::AlignHCenter );
4911 if (cmd)
4912 {
4913 if ( !macroCmd )
4914 macroCmd = new KMacroCommand( i18n("Center Text") );
4915 macroCmd->addCommand( cmd );
4916 }
4917 }
4918 if( macroCmd )
4919 m_doc->addCommand( macroCmd );
4920 }
4921 else
4922 m_actionFormatAlignCenter->setChecked( true );
4923}
4924
4925void KWView::textAlignRight()
4926{
4927 if ( m_actionFormatAlignRight->isChecked() )
4928 {
4929 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4930 TQPtrListIterator<KoTextFormatInterface> it( lst );
4931 KMacroCommand* macroCmd = 0L;
4932 for ( ; it.current() ; ++it )
4933 {
4934 KCommand *cmd = it.current()->setAlignCommand( TQt::AlignRight );
4935 if ( cmd )
4936 {
4937 if (!macroCmd )
4938 macroCmd = new KMacroCommand( i18n("Right-Align Text") );
4939 macroCmd->addCommand( cmd );
4940 }
4941 }
4942 if( macroCmd)
4943 m_doc->addCommand( macroCmd );
4944 }
4945 else
4946 m_actionFormatAlignRight->setChecked( true );
4947}
4948
4949void KWView::textAlignBlock()
4950{
4951 if ( m_actionFormatAlignBlock->isChecked() )
4952 {
4953 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4954 TQPtrListIterator<KoTextFormatInterface> it( lst );
4955 KMacroCommand* macroCmd = 0L;
4956 for ( ; it.current() ; ++it )
4957 {
4958 KCommand *cmd = it.current()->setAlignCommand( TQt::AlignJustify );
4959 if ( cmd )
4960 {
4961 if ( !macroCmd )
4962 macroCmd = new KMacroCommand( i18n("Justify Text") );
4963 macroCmd->addCommand( cmd );
4964 }
4965 }
4966 if( macroCmd)
4967 m_doc->addCommand( macroCmd );
4968 }
4969 else
4970 m_actionFormatAlignBlock->setChecked( true );
4971}
4972
4973void KWView::setSpacing( KoParagLayout::SpacingType spacing, const TQString& commandName)
4974{
4975 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
4976 if ( lst.isEmpty() ) return;
4977 TQPtrListIterator<KoTextFormatInterface> it( lst );
4978 KMacroCommand* macroCmd = 0L;
4979 for ( ; it.current() ; ++it )
4980 {
4981 KoParagLayout layout( *it.current()->currentParagLayoutFormat() );
4982 layout.lineSpacingType = spacing;
4983
4984 KCommand *cmd = it.current()->setParagLayoutFormatCommand( &layout, KoParagLayout::LineSpacing );
4985 if (cmd)
4986 {
4987 if ( !macroCmd )
4988 macroCmd = new KMacroCommand( commandName );
4989 macroCmd->addCommand(cmd);
4990 }
4991 }
4992 if( macroCmd)
4993 m_doc->addCommand(macroCmd);
4994}
4995
4996void KWView::textSpacingSingle()
4997{
4998 if ( m_actionFormatSpacingSingle->isChecked() )
4999 setSpacing( KoParagLayout::LS_SINGLE, i18n("Set Single Line Spacing") );
5000 else
5001 m_actionFormatSpacingSingle->setChecked( true );
5002}
5003
5004void KWView::textSpacingOneAndHalf()
5005{
5006 if ( m_actionFormatSpacingOneAndHalf->isChecked() )
5007 setSpacing( KoParagLayout::LS_ONEANDHALF, i18n("Set One and a Half Line Spacing") );
5008 else
5009 m_actionFormatSpacingOneAndHalf->setChecked( true );
5010}
5011
5012void KWView::textSpacingDouble()
5013{
5014 if ( m_actionFormatSpacingDouble->isChecked() )
5015 setSpacing( KoParagLayout::LS_DOUBLE, i18n("Set Double Line Spacing") );
5016 else
5017 m_actionFormatSpacingDouble->setChecked( true );
5018}
5019
5020void KWView::slotCounterStyleSelected()
5021{
5022 TQString actionName = TQString::fromLatin1(sender()->name());
5023 TQString styleStr = actionName.mid(13);
5024 //kdDebug() << "KWView::slotCounterStyleSelected styleStr=" << styleStr << endl;
5025 KoParagCounter::Style style = (KoParagCounter::Style)(styleStr.toInt());
5026 KoParagCounter c;
5027 if ( style == KoParagCounter::STYLE_NONE )
5028 c.setNumbering( KoParagCounter::NUM_NONE );
5029 else {
5030 c.setNumbering( KoParagCounter::NUM_LIST );
5031 c.setStyle( style );
5032 if ( c.isBullet() )
5033 c.setSuffix( TQString() );
5034 else
5035 c.setSuffix( "." );
5036 // TODO save this setting, to use the last one selected in the dialog?
5037 // (same for custom bullet char etc.)
5038
5039 // 68927: restart numbering, by default, if last parag wasn't numbered
5040 // (and if we're not applying this to a selection)
5041 if ( currentTextEdit() && !currentTextEdit()->textFrameSet()->hasSelection() ) {
5042 KoTextParag* parag = currentTextEdit()->cursor()->parag();
5043 if ( parag->prev() && !parag->prev()->counter() )
5044 c.setRestartCounter(true);
5045 }
5046 }
5047
5048 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5049 TQPtrListIterator<KoTextFormatInterface> it( lst );
5050 KMacroCommand* macroCmd = 0L;
5051 for ( ; it.current() ; ++it )
5052 {
5053 KCommand *cmd = it.current()->setCounterCommand( c );
5054 if ( cmd )
5055 {
5056 if ( !macroCmd )
5057 macroCmd=new KMacroCommand( i18n("Change List Type") );
5058 macroCmd->addCommand( cmd );
5059 }
5060 }
5061 if( macroCmd)
5062 m_doc->addCommand( macroCmd );
5063}
5064
5065void KWView::textSuperScript()
5066{
5067 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5068 if ( lst.isEmpty() ) return;
5069 TQPtrListIterator<KoTextFormatInterface> it( lst );
5070 KMacroCommand* macroCmd = 0L;
5071 for ( ; it.current() ; ++it )
5072 {
5073 KCommand *cmd = it.current()->setTextSuperScriptCommand(m_actionFormatSuper->isChecked());
5074 if (cmd)
5075 {
5076 if ( !macroCmd )
5077 macroCmd = new KMacroCommand( i18n("Make Text Superscript") );
5078 macroCmd->addCommand(cmd);
5079 }
5080 }
5081 if( macroCmd)
5082 m_doc->addCommand(macroCmd);
5083 if (m_actionFormatSuper->isChecked() )
5084 m_actionFormatSub->setChecked( false );
5085}
5086
5087void KWView::textSubScript()
5088{
5089 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5090 if ( lst.isEmpty() ) return;
5091 TQPtrListIterator<KoTextFormatInterface> it( lst );
5092 KMacroCommand* macroCmd = 0L;
5093 for ( ; it.current() ; ++it )
5094 {
5095 KCommand *cmd = it.current()->setTextSubScriptCommand(m_actionFormatSub->isChecked());
5096 if (cmd)
5097 {
5098 if ( !macroCmd )
5099 macroCmd = new KMacroCommand( i18n("Make Text Subscript") );
5100 macroCmd->addCommand(cmd);
5101 }
5102 }
5103 if( macroCmd )
5104 m_doc->addCommand(macroCmd);
5105 if (m_actionFormatSub->isChecked() )
5106 m_actionFormatSuper->setChecked( false );
5107}
5108
5109void KWView::changeCaseOfText()
5110{
5111 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5112 if ( lst.isEmpty() ) return;
5113 TQPtrListIterator<KoTextFormatInterface> it( lst );
5114 KoChangeCaseDia *caseDia=new KoChangeCaseDia( this,"change case" );
5115 if(caseDia->exec())
5116 {
5117 KMacroCommand* macroCmd = 0L;
5118 for ( ; it.current() ; ++it )
5119 {
5120 KCommand *cmd = it.current()->setChangeCaseOfTextCommand(caseDia->getTypeOfCase());
5121 if (cmd)
5122 {
5123 if ( !macroCmd )
5124 macroCmd = new KMacroCommand( i18n("Change Case of Text") );
5125 macroCmd->addCommand(cmd);
5126 }
5127 }
5128 if( macroCmd )
5129 m_doc->addCommand(macroCmd);
5130 }
5131 delete caseDia;
5132}
5133
5134void KWView::editPersonalExpr()
5135{
5136 KWEditPersonnalExpression *personalDia=new KWEditPersonnalExpression( this );
5137 if(personalDia->exec())
5138 m_doc->refreshMenuExpression();
5139 delete personalDia;
5140}
5141
5142
5143void KWView::textIncreaseIndent()
5144{
5145 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5146 if ( lst.isEmpty() ) return;
5147 TQPtrListIterator<KoTextFormatInterface> it( lst );
5148 double leftMargin=0.0;
5149 if(!lst.isEmpty())
5150 leftMargin=lst.first()->currentParagLayoutFormat()->margins[TQStyleSheetItem::MarginLeft];
5151 double indent = m_doc->indentValue();
5152 double newVal = leftMargin + indent;
5153 KMacroCommand* macroCmd = 0L;
5154 for ( ; it.current() ; ++it )
5155 {
5156 KCommand *cmd = it.current()->setMarginCommand( TQStyleSheetItem::MarginLeft, newVal );
5157 if (cmd)
5158 {
5159 if ( !macroCmd )
5160 macroCmd = new KMacroCommand( i18n("Increase Paragraph Depth") );
5161 macroCmd->addCommand(cmd);
5162 }
5163 }
5164 if( macroCmd)
5165 m_doc->addCommand(macroCmd);
5166 if(!lst.isEmpty())
5167 {
5168 const KoParagLayout *layout=lst.first()->currentParagLayoutFormat();
5169 showRulerIndent( layout->margins[TQStyleSheetItem::MarginLeft], layout->margins[TQStyleSheetItem::MarginFirstLine], layout->margins[TQStyleSheetItem::MarginRight], lst.first()->rtl());
5170 }
5171#if 0
5172
5173
5174 KWTextFrameSetEdit * edit = currentTextEdit();
5175 if ( edit )
5176 {
5177 double leftMargin = edit->currentLeftMargin();
5178 double indent = m_doc->indentValue();
5179 double newVal = leftMargin + indent;
5180 // Test commented out. This breaks with the DTP case... The user can put
5181 // a frame anywhere, even closer to the edges than left/right border allows (DF).
5182 //if( newVal <= (m_doc->ptPaperWidth()-m_doc->ptRightBorder()-m_doc->ptLeftBorder()))
5183 {
5184 KCommand *cmd=edit->setMarginCommand( TQStyleSheetItem::MarginLeft, newVal );
5185 if(cmd)
5186 m_doc->addCommand(cmd);
5187 }
5188 }
5189#endif
5190}
5191
5192void KWView::textDecreaseIndent()
5193{
5194 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5195 if ( lst.isEmpty() ) return;
5196 TQPtrListIterator<KoTextFormatInterface> it( lst );
5197 double leftMargin=0.0;
5198 if(!lst.isEmpty())
5199 leftMargin=lst.first()->currentParagLayoutFormat()->margins[TQStyleSheetItem::MarginLeft];
5200 double indent = m_doc->indentValue();
5201 double newVal = leftMargin - indent;
5202 KMacroCommand* macroCmd = 0L;
5203 for ( ; it.current() ; ++it )
5204 {
5205 KCommand *cmd = it.current()->setMarginCommand( TQStyleSheetItem::MarginLeft, TQMAX( newVal, 0 ) );
5206 if (cmd)
5207 {
5208 if ( !macroCmd )
5209 macroCmd = new KMacroCommand( i18n("Decrease Paragraph Depth") );
5210 macroCmd->addCommand(cmd);
5211 }
5212 }
5213 if( macroCmd)
5214 m_doc->addCommand(macroCmd);
5215 if(!lst.isEmpty())
5216 {
5217 const KoParagLayout *layout=lst.first()->currentParagLayoutFormat();
5218 showRulerIndent( layout->margins[TQStyleSheetItem::MarginLeft], layout->margins[TQStyleSheetItem::MarginFirstLine], layout->margins[TQStyleSheetItem::MarginRight], lst.first()->rtl());
5219 }
5220
5221
5222#if 0
5223 KWTextFrameSetEdit * edit = currentTextEdit();
5224 if ( edit )
5225 {
5226 double leftMargin = edit->currentLeftMargin();
5227 if ( leftMargin > 0 )
5228 {
5229 double indent = m_doc->indentValue();
5230 double newVal = leftMargin - indent;
5231 KCommand *cmd=edit->setMarginCommand( TQStyleSheetItem::MarginLeft, TQMAX( newVal, 0 ) );
5232 if(cmd)
5233 m_doc->addCommand(cmd);
5234 }
5235 }
5236#endif
5237}
5238
5239
5240void KWView::textDefaultFormat()
5241{
5242 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5243 if ( lst.isEmpty() ) return;
5244 TQPtrListIterator<KoTextFormatInterface> it( lst );
5245 KMacroCommand* macroCmd = 0L;
5246 for ( ; it.current() ; ++it )
5247 {
5248 KCommand *cmd = it.current()->setDefaultFormatCommand();
5249 if (cmd)
5250 {
5251 if ( !macroCmd )
5252 macroCmd = new KMacroCommand( i18n("Default Format") );
5253 macroCmd->addCommand(cmd);
5254 }
5255 }
5256 if( macroCmd)
5257 m_doc->addCommand(macroCmd);
5258}
5259
5260
5261void KWView::borderOutline()
5262{
5263 bool on = m_actionBorderOutline->isChecked();
5264 if(m_actionBorderLeft->isChecked() != on) {
5265 m_actionBorderLeft->setChecked(on);
5266 borderLeft();
5267 }
5268 if(m_actionBorderRight->isChecked() != on) {
5269 m_actionBorderRight->setChecked(on);
5270 borderRight();
5271 }
5272 if(m_actionBorderTop->isChecked() != on) {
5273 m_actionBorderTop->setChecked(on);
5274 borderTop();
5275 }
5276 if(m_actionBorderBottom->isChecked() != on) {
5277 m_actionBorderBottom->setChecked(on);
5278 borderBottom();
5279 }
5280}
5281
5282void KWView::borderLeft() {
5283 borderChanged(KoBorder::LeftBorder);
5284}
5285
5286void KWView::borderRight() {
5287 borderChanged(KoBorder::RightBorder);
5288}
5289
5290void KWView::borderTop() {
5291 borderChanged(KoBorder::TopBorder);
5292}
5293
5294void KWView::borderBottom() {
5295 borderChanged(KoBorder::BottomBorder);
5296}
5297
5298void KWView::borderChanged(KoBorder::BorderType type) {
5299 KoBorder border;
5300 border.setPenWidth( m_actionBorderWidth->currentText().toInt() );
5301 border.color = m_actionBorderColor->color();
5302 border.setStyle( KoBorder::getStyle( m_actionBorderStyle->currentText() ) );
5303 bool enabled = false;
5304 TQString comment;
5305 switch(type) {
5306 case KoBorder::LeftBorder:
5307 enabled = m_actionBorderLeft->isChecked();
5308 comment = i18n("Change Left Frame Border");
5309 break;
5310 case KoBorder::RightBorder:
5311 enabled = m_actionBorderRight->isChecked();
5312 comment = i18n("Change Right Frame Border");
5313 break;
5314 case KoBorder::TopBorder:
5315 enabled = m_actionBorderTop->isChecked();
5316 comment = i18n("Change Top Frame Border");
5317 break;
5318 case KoBorder::BottomBorder:
5319 default:
5320 enabled = m_actionBorderBottom->isChecked();
5321 comment = i18n("Change Bottom Frame Border");
5322 break;
5323 }
5324 if(!enabled)
5325 border.setPenWidth(0);
5326
5327 KCommand *cmd = 0;
5328 KWTextFrameSetEdit *edit = currentTextEdit();
5329 if ( edit ) {
5330 KoBorder left = edit->border(KoBorder::LeftBorder);
5331 KoBorder right = edit->border(KoBorder::RightBorder);
5332 KoBorder top = edit->border(KoBorder::TopBorder);
5333 KoBorder bottom = edit->border(KoBorder::BottomBorder);
5334 if(type == KoBorder::LeftBorder)
5335 left = border;
5336 else if(type == KoBorder::RightBorder)
5337 right = border;
5338 else if(type == KoBorder::TopBorder)
5339 top = border;
5340 else
5341 bottom = border;
5342 cmd=edit->setBordersCommand( left, right, top, bottom );
5343 }
5344 else {
5345 TQPtrList<FrameIndex> indexes;
5346 TQPtrList<KWFrameBorderCommand::FrameBorderTypeStruct> borders;
5347 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
5348 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
5349 for(;framesIterator != selectedFrames.end(); ++framesIterator) {
5350 if( !(*framesIterator)->selected() ) continue;
5351 KWFrame *frame = (*framesIterator)->frame();
5352 indexes.append(new FrameIndex( frame ));
5353 KWFrameBorderCommand::FrameBorderTypeStruct *bts =
5354 new KWFrameBorderCommand::FrameBorderTypeStruct;
5355 bts->m_EFrameType = type;
5356 if(type == KoBorder::LeftBorder)
5357 bts->m_OldBorder=frame->leftBorder();
5358 else if(type == KoBorder::RightBorder)
5359 bts->m_OldBorder=frame->rightBorder();
5360 else if(type == KoBorder::TopBorder)
5361 bts->m_OldBorder=frame->topBorder();
5362 else
5363 bts->m_OldBorder=frame->bottomBorder();
5364 borders.append(bts);
5365 }
5366 if(indexes.count() > 0)
5367 cmd=new KWFrameBorderCommand(comment, indexes, borders, border);
5368 }
5369 if(cmd) {
5370 cmd->execute();
5371 m_doc->addCommand( cmd );
5372 }
5373 // update actions.
5374 m_actionBorderOutline->setChecked(
5375 m_actionBorderLeft->isChecked() && m_actionBorderRight->isChecked() &&
5376 m_actionBorderTop->isChecked() && m_actionBorderBottom->isChecked());
5377}
5378
5379void KWView::backgroundColor()
5380{
5381 TQColor backColor = m_actionBackgroundColor->color();
5382 // ### TODO port to applicableTextInterfaces ? Hmm, careful with the "frame" case.
5383 KWTextFrameSetEdit *edit = currentTextEdit();
5384 if ( m_gui)
5385 {
5386 if(edit)
5387 {
5388 KCommand *cmd=edit->setTextBackgroundColorCommand(backColor);
5389 if( cmd)
5390 m_doc->addCommand( cmd );
5391 }
5392 else
5393 m_gui->canvasWidget()->setFrameBackgroundColor( backColor );
5394 }
5395}
5396
5397void KWView::resizeEvent( TQResizeEvent *e )
5398{
5399 TQWidget::resizeEvent( e );
5400 if ( m_gui )
5401 {
5402 m_gui->resize( width(), height() );
5403 TQString s = m_actionViewZoom->currentText();
5404 if ( !KoZoomMode::isConstant(s) )
5405 viewZoom( s );
5406 }
5407}
5408
5409void KWView::guiActivateEvent( KParts::GUIActivateEvent *ev )
5410{
5411 if ( ev->activated() )
5412 {
5413 initGui();
5414 if (m_doc->isEmbedded() ) {
5415 // Get zoom level from KoView, i.e. from the parent view
5416 const int zoom = tqRound( KoView::zoom() * 100 );
5417 setZoom( zoom, true );
5418 showZoom( zoom );
5419 }
5420 }
5421 KoView::guiActivateEvent( ev );
5422}
5423
5424void KWView::tabListChanged( const KoTabulatorList & tabList )
5425{
5426 if(!m_doc->isReadWrite())
5427 return;
5428 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5429 if ( lst.isEmpty() ) return;
5430 TQPtrListIterator<KoTextFormatInterface> it( lst );
5431 KMacroCommand* macroCmd = 0L;
5432 for ( ; it.current() ; ++it )
5433 {
5434 KCommand *cmd = it.current()->setTabListCommand( tabList );
5435 if (cmd)
5436 {
5437 if ( !macroCmd )
5438 macroCmd = new KMacroCommand(i18n("Change Tabulator") );
5439 macroCmd->addCommand(cmd);
5440 }
5441 }
5442 if(macroCmd)
5443 m_doc->addCommand(macroCmd);
5444}
5445
5446void KWView::newPageLayout( const KoPageLayout &layout )
5447{
5448 TQString mode = viewMode()->type();
5449 bool state = (mode!="ModeText");
5450 if ( !state )
5451 return;
5452
5453 KoPageLayout pgLayout;
5454 KoColumns cl;
5455 KoKWHeaderFooter hf;
5456 m_doc->getPageLayout( pgLayout, cl, hf );
5457
5458 if(layout==pgLayout)
5459 return;
5460
5461 KWPageLayoutStruct oldLayout( pgLayout, cl, hf );
5462
5463 m_doc->setPageLayout( layout, cl, hf );
5464
5465 KWPageLayoutStruct newLayout( layout, cl, hf );
5466
5467 KWTextFrameSetEdit *edit = currentTextEdit();
5468 if (edit)
5469 edit->textFrameSet()->clearUndoRedoInfo();
5470 KCommand *cmd = new KWPageLayoutCommand( i18n("Change Layout"), m_doc, oldLayout, newLayout );
5471 m_doc->addCommand(cmd);
5472}
5473
5474void KWView::slotPageLayoutChanged( const KoPageLayout& layout )
5475{
5476 // This is connected to a signal of KWDocument, so that when the
5477 // above method, or any other way of changing the page layout happens,
5478 // the rulers are updated in all views.
5479 viewMode()->setPageLayout( m_gui->getHorzRuler(), m_gui->getVertRuler(), layout );
5480 m_gui->canvasWidget()->repaintAll();
5481}
5482
5483void KWView::newFirstIndent( double firstIndent )
5484{
5485 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5486 if ( lst.isEmpty() ) return;
5487 TQPtrListIterator<KoTextFormatInterface> it( lst );
5488 KMacroCommand* macroCmd = 0L;
5489 for ( ; it.current() ; ++it )
5490 {
5491 KCommand *cmd = it.current()->setMarginCommand( TQStyleSheetItem::MarginFirstLine, firstIndent );
5492 if (cmd)
5493 {
5494 if ( !macroCmd )
5495 macroCmd = new KMacroCommand(i18n("Change First Line Indent"));
5496 macroCmd->addCommand(cmd);
5497 }
5498 }
5499 if(macroCmd)
5500 m_doc->addCommand(macroCmd);
5501}
5502
5503void KWView::newLeftIndent( double leftIndent )
5504{
5505 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5506 if ( lst.isEmpty() ) return;
5507 TQPtrListIterator<KoTextFormatInterface> it( lst );
5508 KMacroCommand* macroCmd = 0L;
5509 for ( ; it.current() ; ++it )
5510 {
5511 KCommand *cmd = it.current()->setMarginCommand( TQStyleSheetItem::MarginLeft, leftIndent );
5512 if (cmd)
5513 {
5514 if ( !macroCmd )
5515 macroCmd = new KMacroCommand(i18n("Change Indent") );
5516 macroCmd->addCommand(cmd);
5517 }
5518 }
5519 if(macroCmd)
5520 m_doc->addCommand(macroCmd);
5521
5522}
5523
5524void KWView::newRightIndent( double rightIndent)
5525{
5526
5527 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5528 if ( lst.isEmpty() ) return;
5529 TQPtrListIterator<KoTextFormatInterface> it( lst );
5530 KMacroCommand* macroCmd = 0L;
5531 for ( ; it.current() ; ++it )
5532 {
5533 KCommand *cmd = it.current()->setMarginCommand( TQStyleSheetItem::MarginRight, rightIndent );
5534 if (cmd)
5535 {
5536 if ( !macroCmd )
5537 macroCmd = new KMacroCommand(i18n("Change Indent") );
5538 macroCmd->addCommand(cmd);
5539 }
5540 }
5541 if(macroCmd)
5542 m_doc->addCommand(macroCmd);
5543}
5544
5545TQPopupMenu * KWView::popupMenu( const TQString& name )
5546{
5547 // factory() is 0 when right-clicking on the kword document while
5548 // an embedded object is active. KoPartManager lets the click through,
5549 // without activating us - so let's do that first.
5550 if ( !factory() )
5551 partManager()->setActivePart( m_doc, this );
5552 Q_ASSERT( factory() );
5553 if ( factory() )
5554 return ((TQPopupMenu*)factory()->container( name, this ));
5555 return 0;
5556}
5557
5558void KWView::startKSpell()
5559{
5560 if ( !m_spell.kospell )
5561 m_spell.kospell = new KoSpell( m_broker, this );
5562
5563 // Spell-check the next paragraph
5564 Q_ASSERT( m_spell.textIterator );
5565
5566 m_spell.kospell->check( m_spell.textIterator, true );
5567 delete m_spell.dlg;
5568 m_spell.dlg = new KSpell2::Dialog( m_spell.kospell, this );
5569 m_spell.dlg->activeAutoCorrect( true );
5570
5571 TQObject::connect( m_spell.dlg, TQ_SIGNAL(misspelling(const TQString&, int)),
5572 this, TQ_SLOT(spellCheckerMisspelling(const TQString&, int)) );
5573 TQObject::connect( m_spell.dlg, TQ_SIGNAL(replace(const TQString&, int, const TQString&)),
5574 this, TQ_SLOT(spellCheckerCorrected(const TQString&, int, const TQString&)) );
5575 TQObject::connect( m_spell.dlg, TQ_SIGNAL(done(const TQString&) ),
5576 this, TQ_SLOT(spellCheckerDone(const TQString&)) );
5577 TQObject::connect( m_spell.dlg, TQ_SIGNAL(cancel() ),
5578 this, TQ_SLOT( spellCheckerCancel() ) );
5579 TQObject::connect( m_spell.dlg, TQ_SIGNAL(autoCorrect(const TQString &, const TQString & ) ),
5580 this, TQ_SLOT( spellAddAutoCorrect (const TQString &, const TQString &) ) );
5581
5582 m_spell.dlg->show();
5583 //clearSpellChecker();
5584}
5585
5586void KWView::spellCheckerMisspelling( const TQString &old, int pos )
5587{
5588 //kdDebug(32001) << "KWView::spellCheckerMisspelling old=" << old << " pos=" << pos << endl;
5589 KoTextObject* textobj = m_spell.kospell->currentTextObject();
5590 KoTextParag* parag = m_spell.kospell->currentParag();
5591 Q_ASSERT( textobj );
5592 Q_ASSERT( parag );
5593 if ( !textobj || !parag ) return;
5594 KWTextDocument *textdoc=static_cast<KWTextDocument *>( textobj->textDocument() );
5595 Q_ASSERT( textdoc );
5596 if ( !textdoc ) return;
5597 pos += m_spell.kospell->currentStartIndex();
5598 kdDebug(32001) << "KWView::spellCheckerMisspelling parag=" << parag->paragId() << " pos=" << pos << " length=" << old.length() << endl;
5599 textdoc->textFrameSet()->highlightPortion( parag, pos, old.length(), m_gui->canvasWidget() );
5600}
5601
5602void KWView::spellCheckerCorrected( const TQString &old, int pos , const TQString &corr )
5603{
5604 //kdDebug(32001) << "KWView::spellCheckerCorrected old=" << old << " corr=" << corr << " pos=" << pos << endl;
5605 KoTextObject* textobj = m_spell.kospell->currentTextObject();
5606 KoTextParag* parag = m_spell.kospell->currentParag();
5607 Q_ASSERT( textobj );
5608 Q_ASSERT( parag );
5609 if ( !textobj || !parag ) return;
5610 KWTextDocument *textdoc=static_cast<KWTextDocument *>( textobj->textDocument() );
5611 Q_ASSERT( textdoc );
5612 if ( !textdoc ) return;
5613 pos += m_spell.kospell->currentStartIndex();
5614 textdoc->textFrameSet()->highlightPortion( parag, pos, old.length(), m_gui->canvasWidget() );
5615
5616 KoTextCursor cursor( textdoc );
5617 cursor.setParag( parag );
5618 cursor.setIndex( pos );
5619 if(!m_spell.macroCmdSpellCheck)
5620 m_spell.macroCmdSpellCheck=new KMacroCommand(i18n("Correct Misspelled Word"));
5621 m_spell.macroCmdSpellCheck->addCommand(textobj->replaceSelectionCommand(
5622 &cursor, corr, TQString(), KoTextDocument::HighlightSelection));
5623}
5624
5625void KWView::spellCheckerDone( const TQString & )
5626{
5627 //kdDebug(32001) << "KWView::spellCheckerDone" << endl;
5628 KWTextDocument *textdoc=static_cast<KWTextDocument *>( m_spell.kospell->textDocument() );
5629 Q_ASSERT( textdoc );
5630 if ( textdoc )
5631 textdoc->textFrameSet()->removeHighlight();
5632
5633 clearSpellChecker();
5634}
5635
5636void KWView::clearSpellChecker(bool cancelSpellCheck)
5637{
5638 kdDebug(32001) << "KWView::clearSpellChecker" << endl;
5639
5640 delete m_spell.textIterator;
5641 m_spell.textIterator = 0L;
5642 delete m_spell.kospell;
5643 m_spell.kospell = 0;
5644
5645 if ( m_spell.macroCmdSpellCheck )
5646 {
5647 if ( !cancelSpellCheck )
5648 m_doc->addCommand(m_spell.macroCmdSpellCheck);
5649 else
5650 {
5651 //reverte all changes
5652 m_spell.macroCmdSpellCheck->unexecute();
5653 delete m_spell.macroCmdSpellCheck;
5654 }
5655 }
5656 m_spell.macroCmdSpellCheck=0L;
5657 m_spell.replaceAll.clear();
5658 //m_doc->setReadWrite(true);
5659}
5660
5661void KWView::spellCheckerCancel()
5662{
5663 kdDebug()<<"void KWView::spellCheckerCancel() \n";
5664 spellCheckerRemoveHighlight();
5665 //we add command :( => don't add command and reverte changes
5666 clearSpellChecker(true);
5667}
5668
5669
5670void KWView::spellCheckerRemoveHighlight()
5671{
5672 KoTextObject* textobj = m_spell.kospell->currentTextObject();
5673 if ( textobj ) {
5674 KWTextDocument *textdoc=static_cast<KWTextDocument *>( textobj->textDocument() );
5675 if ( textdoc )
5676 textdoc->textFrameSet()->removeHighlight();
5677 }
5678 KWTextFrameSetEdit * edit = currentTextEdit();
5679 if (edit)
5680 edit->drawCursor( true );
5681}
5682
5683void KWView::spellAddAutoCorrect (const TQString & originalword, const TQString & newword)
5684{
5685 m_doc->autoFormat()->addAutoFormatEntry( originalword, newword );
5686}
5687
5688void KWView::configure()
5689{
5690 KWConfig configDia( this );
5691 configDia.exec();
5692}
5693
5694KWTextFrameSetEdit *KWView::currentTextEdit() const
5695{
5696 if (!m_gui)
5697 return 0L;
5698 KWFrameSetEdit * edit = m_gui->canvasWidget()->currentFrameSetEdit();
5699 if ( edit )
5700 return dynamic_cast<KWTextFrameSetEdit *>(edit->currentTextEdit());
5701 return 0L;
5702}
5703
5704void KWView::slotFrameSetEditChanged()
5705{
5706 KWTextFrameSetEdit * edit = currentTextEdit();
5707 bool rw = koDocument()->isReadWrite();
5708 bool selectedFrames = frameViewManager()->selectedFrames().count() > 0;
5709 bool hasSelection = false;
5710 if ( edit ) {
5711 hasSelection = edit->textFrameSet()->hasSelection();
5712 if ( edit->textFrameSet()->textObject()->protectContent())
5713 rw = false;
5714 }
5715 else {
5716 KWFrameSetEdit * e = m_gui->canvasWidget()->currentFrameSetEdit();
5717 if ( e && e->frameSet()->type() == FT_FORMULA ) {
5718 hasSelection = true;
5719 }
5720 }
5721 m_actionEditCut->setEnabled( hasSelection && rw );
5722
5723 m_actionEditCopy->setEnabled( hasSelection );
5724 m_actionEditReplace->setEnabled( /*edit &&*/ rw );
5725 clipboardDataChanged(); // for paste
5726
5727 bool state = (edit != 0 | selectedFrames) && rw;
5728 m_actionEditSelectAll->setEnabled(state);
5729 m_actionEditSelectCurrentFrame->setEnabled(state);
5730 m_actionInsertComment->setEnabled( state );
5731 m_actionFormatDefault->setEnabled( state );
5732 m_actionFormatFont->setEnabled( state );
5733 m_actionFormatFontSize->setEnabled( state );
5734 m_actionFormatFontFamily->setEnabled( state );
5735 m_actionAddBookmark->setEnabled(state);
5736 m_actionBackgroundColor->setEnabled( state );
5737 m_actionFormatStyleMenu->setEnabled( state );
5738 m_actionFormatBold->setEnabled( state );
5739 m_actionFormatItalic->setEnabled( state );
5740 m_actionFormatUnderline->setEnabled( state );
5741 m_actionFormatStrikeOut->setEnabled( state );
5742 m_actionFormatColor->setEnabled( state );
5743 m_actionFormatAlignLeft->setEnabled( state );
5744 m_actionFormatAlignCenter->setEnabled( state );
5745 m_actionFormatAlignRight->setEnabled( state );
5746 m_actionFormatAlignBlock->setEnabled( state );
5747
5748 m_actionBorderLeft->setEnabled( state );
5749 m_actionBorderRight->setEnabled( state );
5750 m_actionBorderTop->setEnabled( state );
5751 m_actionBorderBottom->setEnabled( state );
5752 m_actionBorderOutline->setEnabled( state );
5753 m_actionBorderColor->setEnabled( state );
5754 m_actionBorderWidth->setEnabled( state );
5755 m_actionBorderStyle->setEnabled( state );
5756
5757
5758 //m_actionFormatIncreaseIndent->setEnabled(state);
5759 m_actionInsertLink->setEnabled(state);
5760 m_actionCreateStyleFromSelection->setEnabled( state /*&& hasSelection*/);
5761 m_actionConvertToTextBox->setEnabled( state && hasSelection);
5762 m_actionAddPersonalExpression->setEnabled( state && hasSelection);
5763 m_actionSortText->setEnabled( state && hasSelection);
5764 bool goodleftMargin=false;
5765 if(state && edit)
5766 goodleftMargin=(edit->currentLeftMargin()>0);
5767
5768 m_actionFormatDecreaseIndent->setEnabled(goodleftMargin);
5769 const bool canChangeCounter = rw && ( !edit || !edit->textFrameSet()->isFootEndNote() );
5770 m_actionFormatBullet->setEnabled(canChangeCounter);
5771 m_actionFormatNumber->setEnabled(canChangeCounter);
5772 m_actionFormatStyle->setEnabled(rw);
5773 m_actionFormatSpacingSingle->setEnabled(rw);
5774 m_actionFormatSpacingOneAndHalf->setEnabled(rw);
5775 m_actionFormatSpacingDouble->setEnabled(rw);
5776 m_actionFormatSuper->setEnabled(rw);
5777 m_actionFormatSub->setEnabled(rw);
5778 m_actionFormatParag->setEnabled(state);
5779 m_actionInsertSpecialChar->setEnabled(state);
5780 m_actionSpellCheck->setEnabled(state);
5781
5782 m_actionChangeCase->setEnabled( (rw && !edit)|| (state && hasSelection) );
5783
5784 if ( edit && edit->textFrameSet()->protectContent())
5785 {
5786 m_actionChangeCase->setEnabled( false );
5787 m_actionEditCut->setEnabled( false );
5788 }
5789 else
5790 m_actionChangeCase->setEnabled( true );
5791
5792 updateTableActions( frameViewManager()->selectedFrames() ) ;
5793
5794 m_actionInsertFormula->setEnabled(state && (viewMode()->type()!="ModeText"));
5795 actionInsertVariable->setEnabled(state);
5796 m_actionInsertExpression->setEnabled(state);
5797
5798 changeFootEndNoteState();
5799 //frameset different of header/footer
5800 state= state && edit && edit->frameSet() && !edit->frameSet()->isHeaderOrFooter() && !edit->frameSet()->groupmanager() && !edit->frameSet()->isFootEndNote();
5801 m_actionInsertContents->setEnabled(state);
5802 m_actionInsertFrameBreak->setEnabled( state );
5803 updatePageInfo();
5804}
5805
5806void KWView::changeFootEndNoteState()
5807{
5808 bool rw = koDocument()->isReadWrite();
5809 KWTextFrameSetEdit * edit = currentTextEdit();
5810 TQString mode = viewMode()->type();
5811
5812 bool isEditableFrameset = edit && edit->frameSet() && edit->frameSet()->isMainFrameset();
5813 bool ok = rw && isEditableFrameset && (mode!="ModeText");
5814 m_actionInsertFootEndNote->setEnabled( ok );
5815 m_actionEditFootEndNote->setEnabled( ok );
5816}
5817
5818void KWView::changeFootNoteMenuItem( bool footnote)
5819{
5820 m_actionEditFootEndNote->setText( footnote? i18n("Edit Footnote"): i18n("Edit Endnote"));
5821 m_actionChangeFootNoteType->setText( footnote? i18n("Change Footnote Parameter"):i18n("Change Endnote Parameter"));
5822}
5823
5824void KWView::slotUpdateRuler()
5825{
5826 KWCanvas* canvas = m_gui->canvasWidget();
5827 TQRect r( canvas->viewMode()->rulerFrameRect() );
5828 if ( !r.isNull() )
5829 {
5830 m_gui->getHorzRuler()->setFrameStartEnd( r.left(), r.right() );
5831 m_gui->getVertRuler()->setFrameStartEnd( r.top(), r.bottom() );
5832 }
5833 canvas->updateRulerOffsets();
5834}
5835
5836void KWView::frameSelectedChanged()
5837{
5838 bool rw = koDocument()->isReadWrite();
5839 TQValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
5840
5841 m_actionFormatFrameSet->setEnabled( selectedFrames.count() >= 1 );
5842 if ( rw && selectedFrames.count() >= 1 )
5843 {
5844 bool okForDelete = true;
5845 bool okForCopy = true;
5846 bool okForLowerRaise = false;
5847 bool okForChangeParagStyle = true;
5848 bool okForChangeInline = true;
5849 bool containsCellFrame = false;
5850 bool containsMainFrame = false;
5851
5852 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
5853 while(framesIterator != selectedFrames.end() && (okForDelete || okForLowerRaise ||
5854 okForChangeParagStyle || okForChangeInline) ) {
5855 // Check we selected no footer nor header
5856 bool isFootNote = (*framesIterator)->frame()->frameSet()->isFootEndNote();
5857 bool headerFooterFootNote = isFootNote ||
5858 (*framesIterator)->frame()->frameSet()->isHeaderOrFooter();
5859 bool isMainWPFrame = (*framesIterator)->frame()->frameSet()->isMainFrameset();
5860 okForChangeParagStyle &= !isFootNote;
5861 okForCopy &= !headerFooterFootNote;
5862
5863 okForDelete &= !headerFooterFootNote;
5864 okForDelete &= !isMainWPFrame;
5865
5866 // Check we selected a frame we can lower raise.
5867 // The header, footer, main frameset, footnotes and inline frames can't be raised.
5868 // As soon as we find one who we can lower/raise open the option.
5869 okForLowerRaise |= !(isMainWPFrame || headerFooterFootNote || (*framesIterator)->frame()->frameSet()->isFloating());
5870 okForChangeInline &= !(isMainWPFrame || headerFooterFootNote );
5871
5872 if ( (*framesIterator)->frame()->frameSet()->groupmanager() )
5873 containsCellFrame = true;
5874 if ( isMainWPFrame )
5875 containsMainFrame = true;
5876 ++framesIterator;
5877 }
5878 m_actionEditDelFrame->setEnabled( okForDelete );
5879 m_actionEditCut->setEnabled( okForDelete && !containsCellFrame );
5880 m_actionEditCopy->setEnabled( selectedFrames.count() >= 1 && okForCopy && !containsMainFrame && !containsCellFrame);
5881
5882 m_actionLowerFrame->setEnabled( okForLowerRaise );
5883 m_actionRaiseFrame->setEnabled( okForLowerRaise );
5884 m_actionSendBackward->setEnabled( okForLowerRaise );
5885 m_actionBringToFront->setEnabled( okForLowerRaise );
5886 m_actionFormatBullet->setEnabled( okForChangeParagStyle );
5887 m_actionFormatNumber->setEnabled( okForChangeParagStyle );
5888 m_actionFormatStyle->setEnabled( okForChangeParagStyle);
5889 m_actionInlineFrame->setEnabled( okForChangeInline);
5890
5891 KWFrame *frame = selectedFrames[0]->frame();
5892 updateBorderButtons(frame->leftBorder(), frame->rightBorder(), frame->topBorder(),
5893 frame->bottomBorder());
5894 } else
5895 { // readonly document, or no frame selected -> disable
5896 m_actionEditDelFrame->setEnabled( false );
5897 m_actionInlineFrame->setEnabled(false);
5898 m_actionEditCut->setEnabled( false );
5899 m_actionLowerFrame->setEnabled( false );
5900 m_actionRaiseFrame->setEnabled( false );
5901 m_actionSendBackward->setEnabled( false );
5902 m_actionBringToFront->setEnabled( false );
5903
5904 }
5905 bool frameDifferentOfPart=false;
5906 if(selectedFrames.count() >= 1)
5907 {
5908 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
5909 while(framesIterator != selectedFrames.end()) {
5910 if ( (*framesIterator)->frame()->frameSet()->type()!=FT_PART &&
5911 (*framesIterator)->frame()->frameSet()->type()!= FT_PICTURE) {
5912 frameDifferentOfPart=true;
5913 break;
5914 }
5915 ++framesIterator;
5916 }
5917 }
5918
5919 m_actionBackgroundColor->setEnabled( (selectedFrames.count() >= 1) && frameDifferentOfPart);
5920 m_actionBackgroundColor->setText(i18n("Frame Background Color..."));
5921
5922 if ( frameDifferentOfPart ) {
5923 KWFrame *frame = selectedFrames[0]->frame();
5924 TQColor frameCol=frame->backgroundColor().color();
5925 //m_actionBackgroundColor->setText(i18n("Frame Background Color..."));
5926 m_actionBackgroundColor->setCurrentColor( frameCol.isValid()? frame->backgroundColor().color() : TQApplication::palette().color( TQPalette::Active, TQColorGroup::Base ));
5927 }
5928
5929 m_actionCreateFrameStyle->setEnabled( selectedFrames.count()==1 );
5930 m_actionCreateLinkedFrame->setEnabled( selectedFrames.count()==1 );
5931
5932 updateTableActions( selectedFrames );
5933 updatePageInfo(); // takes care of slotUpdateRuler()
5934 updateFrameStatusBarItem();
5935
5936 TQPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
5937 if ( !lst.isEmpty() )
5938 {
5939 TQPtrListIterator<KoTextFormatInterface> it( lst );
5940 KoTextFormat format=*(lst.first()->currentFormat());
5941 showFormat( format );
5942
5943 const KoParagLayout * paragLayout=lst.first()->currentParagLayoutFormat();
5944 KoParagCounter counter;
5945 if(paragLayout->counter)
5946 counter = *(paragLayout->counter);
5947 showCounter( counter );
5948 int align = paragLayout->alignment;
5949 if ( align == TQt::AlignAuto )
5950 align = TQt::AlignLeft; // ## seems hard to detect RTL here
5951 showAlign( align );
5952 KoParagLayout::SpacingType spacing=paragLayout->lineSpacingType;
5953 showSpacing( spacing );
5954 }
5955
5956 m_gui->canvasWidget()->repaintAll(false);
5957}
5958
5959
5960void KWView::updateTableActions( TQValueList<KWFrameView*> selectedFrames)
5961{
5962 TableInfo ti(selectedFrames);
5963 KWTableFrameSet *table = m_gui->canvasWidget()->getCurrentTable();
5964 m_actionTableJoinCells->setEnabled( ti.tableCellsSelected());
5965 m_actionConvertTableToText->setEnabled( table && table->isFloating() );
5966
5967 m_actionTableSplitCells->setEnabled( ti.oneCellSelected() );
5968
5969 m_actionTableInsertRow->setEnabled( ti.amountRowsSelected() );
5970 m_actionTableDelRow->setEnabled( ti.amountRowsSelected() );
5971 m_actionTableInsertCol->setEnabled( ti.amountColumnsSelected() );
5972
5973 if(ti.amountColumnsSelected() == 1)
5974 m_actionTableDelCol->setText(i18n("D&elete Current Column..."));
5975 else
5976 m_actionTableDelCol->setText(i18n("D&elete Selected Columns..."));
5977 m_actionTableDelCol->setEnabled( ti.amountColumnsSelected() > 0 );
5978 if(ti.amountRowsSelected() == 1)
5979 m_actionTableDelRow->setText(i18n("&Delete Current Row..."));
5980 else
5981 m_actionTableDelRow->setText(i18n("&Delete Selected Rows..."));
5982 m_actionTableDelRow->setEnabled( ti.amountRowsSelected() > 0 );
5983
5984 m_actionTableResizeCol->setEnabled( ti.tableCellsSelected() );
5985 m_actionTableDelete->setEnabled( ti.tableCellsSelected() );
5986 m_actionTablePropertiesMenu->setEnabled( ti.tableCellsSelected() );
5987
5988 m_actionTableUngroup->setEnabled( ti.tableCellsSelected() );
5989 m_actionTableProtectCells->setEnabled( ti.tableCellsSelected() );
5990 m_actionTableProtectCells->setChecked( ti.protectContentEnabled() );
5991}
5992
5993void KWView::docStructChanged(int type)
5994{
5995 KWDocStruct *m_pDocStruct=m_gui->getDocStruct();
5996 if(m_pDocStruct)
5997 m_pDocStruct->refreshTree(type);
5998 m_doc->recalcVariables( VT_STATISTIC );
5999}
6000
6001void KWView::documentModified( bool b )
6002{
6003 if ( !statusBar() )
6004 return;
6005
6006 if ( b )
6007 m_sbModifiedLabel->setPixmap( TDEGlobal::iconLoader()->loadIcon( "action-modified", TDEIcon::Small ) );
6008 else
6009 m_sbModifiedLabel->setText( " " );
6010}
6011
6012void KWView::changeOverwriteMode( bool b )
6013{
6014 if ( !statusBar() )
6015 return;
6016
6017 if ( b )
6018 m_sbOverwriteLabel->setText( ' ' + i18n( "OVER" ) + ' ' );
6019 else
6020 m_sbOverwriteLabel->setText( ' ' + i18n( "INSRT" ) + ' ' );
6021}
6022
6023void KWView::setViewFrameBorders(bool b)
6024{
6025 m_viewFrameBorders = b;
6026 // Store setting in doc, for further views and for saving
6027 m_doc->setViewFrameBorders( b );
6028}
6029
6030bool KWView::doubleClickActivation() const
6031{
6032 return true;
6033}
6034
6035TQWidget* KWView::canvas() const
6036{
6037 // used to be ->viewport(), but this makes no sense.
6038 // active embedded objects must be positioned relative to the real view,
6039 // to scroll around with it, instead of being children of the fixed viewport.
6040 return m_gui->canvasWidget();
6041}
6042
6043int KWView::canvasXOffset() const
6044{
6045 return m_gui->canvasWidget()->contentsX();
6046}
6047
6048int KWView::canvasYOffset() const
6049{
6050 return m_gui->canvasWidget()->contentsY();
6051}
6052
6053void KWView::canvasAddChild( KoViewChild * child )
6054{
6055 connect( m_gui->canvasWidget(), TQ_SIGNAL( viewTransformationsChanged() ),
6056 child, TQ_SLOT( reposition() ) );
6057 // Not necessary anymore
6058 //m_gui->canvasWidget()->addChild( child->frame() );
6059}
6060
6061void KWView::changePicture()
6062{
6063 KWFrameView *view = frameViewManager()->selectedFrame();
6064 KWFrame *frame = view == 0 ? 0 : view->frame();
6065 if( !frame )
6066 return;
6067 KWPictureFrameSet *frameset = static_cast<KWPictureFrameSet *>(frame->frameSet());
6068 KoPictureKey oldKey ( frameset->picture().getKey() );
6069 TQString oldFile ( oldKey.filename() );
6070 KURL url;
6071 url.setPath( oldFile );
6072 if (!TQDir(url.directory()).exists())
6073 oldFile = url.fileName();
6074
6075 KoPicture picture ( KWInsertPicDia::selectPictureDia( oldFile, this ) );
6076 if ( !picture.isNull() )
6077 {
6078 KWFrameChangePictureCommand *cmd= new KWFrameChangePictureCommand( i18n("Change Picture"), FrameIndex(frame), oldKey, picture.getKey() ) ;
6079
6080 frameset->insertPicture( picture );
6081 m_doc->frameChanged( frame );
6082 m_doc->refreshDocStructure( FT_PICTURE );
6083 m_doc->addCommand(cmd);
6084 }
6085 else
6086 kdDebug() << "KWView::changePicture cancelled" << endl;
6087}
6088
6089void KWView::savePicture()
6090{
6091 KWFrameView *view = frameViewManager()->selectedFrame();
6092 KWFrame *frame = view == 0 ? 0 : view->frame();
6093 if ( frame )//test for dcop call
6094 {
6095 KWPictureFrameSet *frameset = static_cast<KWPictureFrameSet *>(frame->frameSet());
6096 TQString oldFile = frameset->picture().getKey().filename();
6097 KURL url;
6098 url.setPath( oldFile );
6099 if ( !TQDir(url.directory()).exists() )
6100 oldFile = url.fileName();
6101
6102 KoPicture picture( frameset->picture() );
6103 TQString mimetype = picture.getMimeType();
6104 kdDebug() << "Picture has mime type: " << mimetype << endl;
6105 TQStringList mimetypes;
6106 mimetypes << mimetype;
6107 KFileDialog fd( oldFile, TQString(), this, 0, true );
6108 fd.setMimeFilter( mimetypes );
6109 fd.setCaption(i18n("Save Picture"));
6110 fd.setOperationMode(KFileDialog::Saving);
6111 if ( fd.exec() == TQDialog::Accepted )
6112 {
6113 url = fd.selectedURL();
6114 if ( url.isValid() )
6115 {
6116 if ( url.isLocalFile() )
6117 {
6118 TQFile file( url.path() );
6119 if ( file.open( IO_ReadWrite ) )
6120 {
6121 picture.save( &file );
6122 file.close();
6123 }
6124 else
6125 {
6126 KMessageBox::error(this,
6127 i18n("Error during saving. Could not open '%1' for writing").arg ( url.path() ),
6128 i18n("Save Picture"));
6129 }
6130 }
6131 else
6132 {
6133 KTempFile tempFile;
6134 tempFile.setAutoDelete( true );
6135 if ( tempFile.status() == 0 )
6136 {
6137 TQFile file( tempFile.name() );
6138 if ( file.open( IO_ReadWrite ) )
6139 {
6140 picture.save( &file );
6141 file.close();
6142 if ( !TDEIO::NetAccess::upload( tempFile.name(), url, this ) )
6143 {
6144 KMessageBox::sorry( this, i18n(
6145 "Unable to save the file to '%1'. %2.").arg( url.prettyURL() ).arg( TDEIO::NetAccess::lastErrorString() ),
6146 i18n("Save Failed") );
6147 }
6148 }
6149 else
6150 KMessageBox::error(this,
6151 i18n("Error during saving. Could not open '%1' temporary file for writing").arg ( file.name() ),
6152 i18n("Save Picture"));
6153 }
6154 else
6155 KMessageBox::sorry( this, i18n(
6156 "Error during saving. Could not create temporary file: %1.").arg( strerror( tempFile.status() ) ),
6157 i18n("Save Picture") );
6158 }
6159 }
6160 else
6161 KMessageBox::sorry( this, i18n("URL %1 is invalid.").arg( url.prettyURL() ), i18n("Save Picture") );
6162 }
6163 }
6164}
6165
6166void KWView::configureHeaderFooter()
6167{
6168 KoPageLayout pgLayout;
6169 KoColumns cl;
6170 KoKWHeaderFooter kwhf;
6171 m_doc->getPageLayout( pgLayout, cl, kwhf );
6172
6173 KWPageLayoutStruct oldLayout( pgLayout, cl, kwhf );
6174
6175 KoHeadFoot hf;
6176 int flags = KW_HEADER_AND_FOOTER;
6177 KoUnit::Unit unit = m_doc->unit();
6178 KoUnit::Unit oldUnit = unit;
6179
6180 if ( KoPageLayoutDia::pageLayout( pgLayout, hf, cl, kwhf, flags, unit ) ) {
6181 if( oldLayout._hf != kwhf )
6182 {
6183 KWPageLayoutStruct newLayout( pgLayout, cl, kwhf );
6184
6185 KCommand *cmd = new KWPageLayoutCommand( i18n("Change Layout"), m_doc,
6186 oldLayout, newLayout );
6187 m_doc->addCommand(cmd);
6188
6189 m_doc->setPageLayout( pgLayout, cl, kwhf );
6190 }
6191 if ( unit != oldUnit )
6192 m_doc->setUnit( unit ); // needs undo/redo support
6193 }
6194
6195}
6196
6197void KWView::inlineFrame()
6198{
6199 KWFrameView *view = frameViewManager()->selectedFrame();
6200 KWFrame *frame = view == 0 ? 0 : view->frame();
6201 if( !frame)
6202 return;
6203 KWFrameSet * fs = frame->frameSet();
6204 KWFrameSet * parentFs = fs->groupmanager() ? fs->groupmanager() : fs;
6205
6206 if(m_actionInlineFrame->isChecked())
6207 {
6208
6209 KMacroCommand* macroCmd = new KMacroCommand( i18n("Make Frameset Inline") );
6210 TQValueList<FrameIndex> frameindexList;
6211 TQValueList<FrameMoveStruct> frameindexMove;
6212
6213 KoPoint initialPos = frame->topLeft();
6214 // turn non-floating frame into floating frame
6215 KWFrameSetInlineCommand *cmd = new KWFrameSetInlineCommand( i18n("Make Frameset Inline"), parentFs, true );
6216 cmd->execute();
6217
6218 frameindexList.append( FrameIndex( frame ) );
6219 frameindexMove.append( FrameMoveStruct( initialPos, frame->topLeft() ) );
6220
6221 KWFrameMoveCommand *cmdMoveFrame = new KWFrameMoveCommand( i18n("Move Frame"), frameindexList, frameindexMove );
6222
6223 macroCmd->addCommand(cmdMoveFrame);
6224 macroCmd->addCommand(cmd);
6225 m_doc->addCommand(macroCmd);
6226 }
6227 else
6228 {
6229 KWFrameSetInlineCommand *cmd = new KWFrameSetInlineCommand( i18n("Make Frameset Non-Inline"), parentFs, false );
6230 m_doc->addCommand(cmd);
6231 cmd->execute();
6232 }
6233}
6234
6235void KWView::openLink()
6236{
6237 KWTextFrameSetEdit * edit = currentTextEdit();
6238 if ( edit )
6239 edit->openLink();
6240}
6241
6242void KWView::changeLink()
6243{
6244 KWTextFrameSetEdit * edit = currentTextEdit();
6245 if ( edit )
6246 {
6247 KoLinkVariable * var=edit->linkVariable();
6248 if(var)
6249 {
6250 TQString oldhref= var->url();
6251 TQString oldLinkName=var->value();
6252 TQString link=oldLinkName;
6253 TQString ref=oldhref;
6254 if(KoInsertLinkDia::createLinkDia(link, ref, m_doc->listOfBookmarkName(0), true, this))
6255 {
6256 if(!link.isEmpty() && !ref.isEmpty())
6257 {
6258 if( ref != oldhref || link!=oldLinkName)
6259 {
6260 KWChangeLinkVariable*cmd=new KWChangeLinkVariable( i18n("Change Link"), m_doc,oldhref, ref, oldLinkName,link, var);
6261 cmd->execute();
6262 m_doc->addCommand(cmd);
6263 }
6264 }
6265 }
6266 }
6267 }
6268}
6269
6270void KWView::copyLink()
6271{
6272 KWTextFrameSetEdit * edit = currentTextEdit();
6273 if ( edit )
6274 edit->copyLink();
6275}
6276
6277void KWView::removeLink()
6278{
6279 KWTextFrameSetEdit * edit = currentTextEdit();
6280 if ( edit )
6281 edit->removeLink();
6282}
6283
6284void KWView::addToBookmark()
6285{
6286 KWTextFrameSetEdit * edit = currentTextEdit();
6287 if ( edit )
6288 {
6289 KoLinkVariable * var=edit->linkVariable();
6290 if(var)
6291 {
6292 edit->addBookmarks(var->url());
6293 }
6294 }
6295}
6296
6297void KWView::showDocStructure()
6298{
6299 m_doc->setShowDocStruct(m_actionShowDocStruct->isChecked());
6300 m_doc->reorganizeGUI();
6301 TQTimer::singleShot( 0, this, TQ_SLOT( updateZoom() ) );
6302}
6303
6304void KWView::showRuler()
6305{
6306 m_doc->setShowRuler( m_actionShowRuler->isChecked());
6307 m_doc->reorganizeGUI();
6308 TQTimer::singleShot( 0, this, TQ_SLOT( updateZoom() ) );
6309}
6310
6311void KWView::viewGrid()
6312{
6313 m_doc->setShowGrid( m_actionViewShowGrid->isChecked() );
6314 m_doc->setModified( true );
6315 m_doc->updateGridButton();
6316 m_doc->repaintAllViews(false);
6317}
6318
6319void KWView::viewSnapToGrid()
6320{
6321 m_doc->setSnapToGrid( m_actionViewSnapToGrid->isChecked() );
6322 m_doc->setModified( true );
6323 m_doc->updateGridButton();
6324}
6325
6326void KWView::slotSoftHyphen()
6327{
6328 KWTextFrameSetEdit * edit = currentTextEdit();
6329 if ( edit )
6330 edit->insertSoftHyphen();
6331}
6332
6333void KWView::slotNonbreakingSpace()
6334{
6335 KWTextFrameSetEdit * edit = currentTextEdit();
6336 if ( edit )
6337 edit->insertNonbreakingSpace();
6338}
6339
6340void KWView::slotNonbreakingHyphen()
6341{
6342 KWTextFrameSetEdit * edit = currentTextEdit();
6343 if ( edit )
6344 edit->insertNonbreakingHyphen();
6345}
6346
6347void KWView::slotLineBreak()
6348{
6349 KWTextFrameSetEdit * edit = currentTextEdit();
6350 if ( edit )
6351 edit->insertLineBreak();
6352}
6353
6354void KWView::slotIncreaseNumberingLevel()
6355{
6356 KWTextFrameSetEdit * edit = currentTextEdit();
6357 if ( edit )
6358 edit->increaseNumberingLevel( m_doc->styleCollection() );
6359}
6360
6361void KWView::slotDecreaseNumberingLevel()
6362{
6363 KWTextFrameSetEdit * edit = currentTextEdit();
6364 if ( edit )
6365 edit->decreaseNumberingLevel( m_doc->styleCollection() );
6366}
6367
6368void KWView::refreshAllVariable()
6369{
6370 m_doc->recalcVariables( VT_ALL );
6371}
6372
6373void KWView::slotAllowAutoFormat()
6374{
6375 bool state = m_actionAllowAutoFormat->isChecked();
6376 m_doc->setAllowAutoFormat( state );
6377}
6378
6379void KWView::slotCompletion()
6380{
6381 KWTextFrameSetEdit * edit = currentTextEdit();
6382 if ( edit )
6383 edit->completion();
6384}
6385
6386void KWView::updateHeaderFooterButton()
6387{
6388 m_actionViewHeader->setChecked(m_doc->isHeaderVisible());
6389 m_actionViewFooter->setChecked(m_doc->isFooterVisible());
6390}
6391
6392void KWView::editComment()
6393{
6394 KWTextFrameSetEdit * edit = currentTextEdit();
6395 if ( edit )
6396 {
6397 KoVariable * tmpVar=edit->variable();
6398 KoNoteVariable * var = dynamic_cast<KoNoteVariable *>(tmpVar);
6399 if(var)
6400 {
6401 TQString authorName;
6402 KoDocumentInfo * info = m_doc->documentInfo();
6403 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
6404 if ( !authorPage )
6405 kdWarning() << "Author information not found in documentInfo !" << endl;
6406 else
6407 authorName = authorPage->fullName();
6408 TQString oldValue = var->note();
6409 TQString createDate = var->createdNote();
6410 KoCommentDia *commentDia = new KoCommentDia( this, oldValue, authorName, createDate);
6411 if( commentDia->exec() )
6412 {
6413 if ( oldValue != commentDia->commentText())
6414 {
6415 KWChangeVariableNoteText *cmd = new KWChangeVariableNoteText( i18n("Change Note Text"), m_doc, oldValue,commentDia->commentText(), var);
6416 m_doc->addCommand( cmd );
6417 cmd->execute();
6418 }
6419 }
6420 delete commentDia;
6421 }
6422 }
6423}
6424
6425void KWView::fileStatistics()
6426{
6427 KWStatisticsDialog *statisticsDialog = new KWStatisticsDialog( this, m_doc );
6428 if ( !statisticsDialog->wasCanceled() )
6429 statisticsDialog->exec();
6430 delete statisticsDialog;
6431}
6432
6433void KWView::removeComment()
6434{
6435 KWTextFrameSetEdit * edit = currentTextEdit();
6436 if ( edit )
6437 {
6438 edit->removeComment();
6439 }
6440}
6441
6442void KWView::copyTextOfComment()
6443{
6444 KWTextFrameSetEdit * edit = currentTextEdit();
6445 if ( edit )
6446 {
6447 edit->copyTextOfComment();
6448 }
6449}
6450
6451void KWView::configureCompletion()
6452{
6453 m_doc->autoFormat()->readConfig();
6454 KoCompletionDia dia( this, 0, m_doc->autoFormat() );
6455 dia.exec();
6456}
6457
6458void KWView::applyAutoFormat()
6459{
6460 m_doc->autoFormat()->readConfig();
6461 KMacroCommand *macro = 0L;
6462 TQValueList<KoTextObject *> list(m_doc->visibleTextObjects(viewMode()));
6463 TQValueList<KoTextObject *>::Iterator fit = list.begin();
6464 for ( ; fit != list.end() ; ++fit )
6465 {
6466 KCommand *cmd = m_doc->autoFormat()->applyAutoFormat( *fit );
6467 if ( cmd )
6468 {
6469 if ( !macro )
6470 macro = new KMacroCommand( i18n("Apply Autoformat"));
6471 macro->addCommand( cmd );
6472 }
6473 }
6474 if ( macro )
6475 m_doc->addCommand( macro );
6476}
6477
6478void KWView::createStyleFromSelection()
6479{
6480 KWTextFrameSetEdit * edit = currentTextEdit();
6481 if ( edit )
6482 {
6483 KoStyleCollection* coll = m_doc->styleCollection();
6484 KoCreateStyleDia *dia = new KoCreateStyleDia( TQStringList(), this, 0 );
6485 if ( dia->exec() )
6486 {
6487 TQString name = dia->nameOfNewStyle();
6488 KoParagStyle* style = coll->findStyleByDisplayName( name );
6489 if ( style ) // update existing style
6490 {
6491 // TODO confirmation message box
6492 edit->updateStyleFromSelection( style );
6493 }
6494 else // create new style
6495 {
6496 style = edit->createStyleFromSelection( name );
6497 m_doc->styleCollection()->addStyle( style );
6498 m_doc->updateAllStyleLists();
6499 }
6500 showStyle( name );
6501 }
6502 delete dia;
6503 }
6504}
6505
6506// Initially called by initGUIButton
6507void KWView::switchModeView()
6508{
6509 KWCanvas* canvas = m_gui->canvasWidget();
6510 slotUpdateRuler();
6511
6512 // Now update the actions appropriately
6513 TQString mode = canvas->viewMode()->type();
6514 bool isTextMode = mode == "ModeText";
6515 bool state = !isTextMode;
6516 m_actionToolsCreateText->setEnabled(state);
6517 m_actionToolsCreatePix->setEnabled(state);
6518 m_actionToolsCreatePart->setEnabled(state);
6519 m_actionInsertFormula->setEnabled(state);
6520 m_actionInsertTable->setEnabled(state);
6521 changeFootEndNoteState();
6522 m_actionViewFooter->setEnabled( state && m_doc->processingType() == KWDocument::WP );
6523 m_actionViewHeader->setEnabled( state && m_doc->processingType() == KWDocument::WP );
6524 //m_actionViewTextMode->setEnabled(m_doc->processingType()==KWDocument::WP);
6525 m_actionShowDocStruct->setEnabled(state);
6526 m_actionFormatPage->setEnabled(state);
6527 m_actionInsertContents->setEnabled( state );
6528 m_actionFrameStyle->setEnabled( state );
6529 m_actionTableStyle->setEnabled ( state );
6530 m_actionViewShowGrid->setEnabled( state );
6531 m_actionViewSnapToGrid->setEnabled( mode == "ModeNormal" || mode == "ModeEmbedded" ); // TODO fix snapping in preview mode
6532 if ( m_gui->getHorzRuler())
6533 {
6534 m_gui->getHorzRuler()->setPageLayoutMenuItemEnabled( state );
6535 if ( !koDocument()->isReadWrite())
6536 m_gui->getHorzRuler()->changeFlags( KoRuler::F_NORESIZE );
6537 else
6538 {
6539 if ( state )
6540 m_gui->getHorzRuler()->changeFlags( m_gui->getHorzRuler()->flags() & ~(KoRuler::F_NORESIZE) );
6541 else
6542 m_gui->getHorzRuler()->changeFlags( m_gui->getHorzRuler()->flags() | KoRuler::F_NORESIZE );
6543 }
6544 }
6545 if ( m_gui->getVertRuler() )
6546 {
6547 m_gui->getVertRuler()->setPageLayoutMenuItemEnabled( state );
6548 if ( !koDocument()->isReadWrite())
6549 m_gui->getVertRuler()->changeFlags( KoRuler::F_NORESIZE );
6550 else
6551 {
6552 if ( state )
6553 m_gui->getVertRuler()->changeFlags( m_gui->getVertRuler()->flags() & ~(KoRuler::F_NORESIZE) );
6554 else
6555 m_gui->getVertRuler()->changeFlags( m_gui->getVertRuler()->flags() | KoRuler::F_NORESIZE );
6556
6557 }
6558 }
6559
6560 if ( isTextMode )
6561 {
6562 if ( m_doc->showdocStruct() )
6563 {
6564 m_doc->setShowDocStruct(false);
6565 m_doc->reorganizeGUI();
6566 }
6567 }
6568 else
6569 {
6570 m_doc->setShowDocStruct(m_actionShowDocStruct->isChecked());
6571 m_doc->reorganizeGUI();
6572 }
6573 //recalc pgnum variable when we swith viewmode
6574 //because in text mode view we display field code and not value
6575 //normal because we don't have real page in this mode
6576 m_doc->recalcVariables( VT_PGNUM );
6577 if ( isTextMode )
6578 {
6579 // Make sure we edit the same frameset as the one shown in the textview ;-)
6580 canvas->editFrameSet( static_cast<KWViewModeText* >(canvas->viewMode())->textFrameSet() );
6581
6582 }
6583 //remove/add "zoom to page". Not necessary in text mode view.
6584 updateZoomControls();
6585
6586 updatePageInfo();
6587 // set page layout in rulers
6588 canvas->viewMode()->setPageLayout( m_gui->getHorzRuler(), m_gui->getVertRuler(), m_doc->pageLayout() );
6589}
6590
6591void KWView::configureFootEndNote()
6592{
6593 KWConfigFootNoteDia *dia = new KWConfigFootNoteDia( this, "configfootnote", m_doc );
6594 dia->exec();
6595 delete dia;
6596}
6597
6598void KWView::editFootEndNote()
6599{
6600 KWTextFrameSetEdit * edit = currentTextEdit();
6601 if ( edit )
6602 {
6603 KWFootNoteVariable * var = dynamic_cast<KWFootNoteVariable *>( edit->variable() );
6604 if ( var && var->frameSet() )
6605 {
6606 m_gui->canvasWidget()->editFrameSet( var->frameSet() );
6607 KWTextFrameSetEdit* textedit = currentTextEdit();
6608 if ( textedit )
6609 textedit->ensureCursorVisible();
6610 }
6611 }
6612}
6613
6614void KWView::changeFootNoteType()
6615{
6616 KWTextFrameSetEdit * edit = currentTextEdit();
6617 if ( edit )
6618 {
6619 KoVariable * tmpVar=edit->variable();
6620 KWFootNoteVariable * var = dynamic_cast<KWFootNoteVariable *>(tmpVar);
6621 if(var && var->frameSet())
6622 {
6623 KWFootNoteDia dia( var->noteType(), var->numberingType(), (var->numberingType()==KWFootNoteVariable::Auto) ? TQString() : var->manualString(), this, m_doc, 0 );
6624 TQPtrListIterator<KoTextCustomItem> it( edit->textDocument()->allCustomItems() );
6625 for ( ; it.current() ; ++it )
6626 {
6627 KWFootNoteVariable *fnv = dynamic_cast<KWFootNoteVariable *>( it.current() );
6628 if (fnv && !fnv->isDeleted() && fnv->frameSet() && !fnv->frameSet()->isDeleted() &&
6629 fnv->numberingType()==KWFootNoteVariable::Manual && fnv != var)
6630 dia.appendManualFootNote( fnv->text() );
6631 }
6632 if ( dia.exec() )
6633 {
6634 FootNoteParameter oldParam( var );
6635 FootNoteParameter newParam(dia.noteType(), dia.numberingType(), dia.manualString() );
6636 KWChangeFootNoteParametersCommand * cmd = new KWChangeFootNoteParametersCommand( i18n("Change Footnote Parameters"), var , oldParam, newParam, m_doc);
6637 cmd->execute();
6638 m_doc->addCommand ( cmd );
6639 }
6640 }
6641 }
6642}
6643
6644
6645void KWView::autoSpellCheck()
6646{
6647 autoSpellCheck( m_actionAllowBgSpellCheck->isChecked() );
6648}
6649
6650void KWView::autoSpellCheck(bool b)
6651{
6652 m_doc->changeBgSpellCheckingState( b );
6653}
6654
6655void KWView::goToFootEndNote()
6656{
6657 KWFrameView *view = frameViewManager()->selectedFrame();
6658 KWFrame *frame = view == 0 ? 0 : view->frame();
6659 if( !frame)
6660 return;
6661 KWFootNoteFrameSet *footNoteFrameSet = dynamic_cast<KWFootNoteFrameSet *>(frame->frameSet());
6662 if ( footNoteFrameSet )
6663 {
6664 KWFootNoteVariable* var=footNoteFrameSet->footNoteVariable();
6665 KoTextParag *parag = var->paragraph();
6666 int index = var->index();
6667 KWTextDocument *textDoc = static_cast<KWTextDocument *>(var->textDocument());
6668 KWTextFrameSet *frameSet =textDoc->textFrameSet();
6669 m_gui->canvasWidget()->editTextFrameSet( frameSet, parag, index );
6670 }
6671}
6672
6673void KWView::openDocStructurePopupMenu( const TQPoint &p, KWFrameSet *frameset, KWTextParag *parag)
6674{
6675 bool rw = koDocument()->isReadWrite();
6676 bool kttsdInstalled = KoSpeaker::isKttsdInstalled();
6677 if (!rw && !kttsdInstalled)
6678 return;
6679 bool hasText = (frameset->type()==FT_TEXT || frameset->type()==FT_TABLE || frameset->type()==FT_FORMULA );
6680
6681 m_actionDocStructEdit->setEnabled( rw && hasText );
6682 m_actionDocStructDelete->setEnabled( (rw && !parag && !frameset->isMainFrameset() &&
6683 !frameset->isFootEndNote() && !frameset->isHeaderOrFooter()) );
6684 m_actionDocStructSpeak->setEnabled( hasText && kttsdInstalled );
6685
6686 TQPopupMenu* popup = static_cast<TQPopupMenu *>(factory()->container("docstruct_popup",this));
6687 if ( popup )
6688 popup->exec(p);
6689}
6690
6691void KWView::docStructSelect()
6692{
6693 if ( m_gui->getDocStruct() )
6694 {
6695 m_gui->getDocStruct()->selectItem();
6696 }
6697}
6698
6699void KWView::docStructEdit()
6700{
6701 if ( m_gui->getDocStruct() )
6702 {
6703 m_gui->getDocStruct()->editItem();
6704 //return focus to canvas.
6705 m_gui->canvasWidget()->setFocus();
6706 }
6707}
6708
6709void KWView::docStructProperties()
6710{
6711 if ( m_gui->getDocStruct() )
6712 {
6713 m_gui->getDocStruct()->editProperties();
6714 }
6715}
6716
6717void KWView::docStructDelete()
6718{
6719 if ( m_gui->getDocStruct() )
6720 {
6721 m_gui->getDocStruct()->deleteItem();
6722 }
6723}
6724
6725void KWView::docStructSpeak()
6726{
6727 if ( m_gui->getDocStruct() )
6728 {
6729 m_gui->getDocStruct()->speakItem();
6730 }
6731}
6732
6733void KWView::insertFile()
6734{
6735 KFileDialog fd( TQString(), TQString(), this, 0, true );
6736 fd.setMimeFilter( "application/x-kword" );
6737 fd.setCaption(i18n("Insert File"));
6738 KURL url;
6739 if ( fd.exec() != TQDialog::Accepted )
6740 return;
6741 url = fd.selectedURL();
6742 if( url.isEmpty() )
6743 {
6744 KMessageBox::sorry( this,
6745 i18n("File name is empty."),
6746 i18n("Insert File"));
6747 return;
6748 }
6749 insertFile( url );
6750}
6751
6752void KWView::insertFile(const KURL& url)
6753{
6754 KMacroCommand* macroCmd = 0L;
6755 bool hasFixedFramesets = false;
6756 KoStore* store=KoStore::createStore( this, url, KoStore::Read );
6757
6758 // TODO: this code only supports KWord-1.3 stores, it needs to support OASIS too.
6759
6760 // ###### All of this should be ported to use the pasting code instead.
6761
6762 TQString maindoc = "maindoc.xml";
6763 if ( store )
6764 {
6765 // We need to load the pictures before we treat framesets
6766 // because KWDocument::pasteFrames() calls processPictureRequests().
6767 bool b = store->open(maindoc);
6768 if ( !b )
6769 {
6770 KMessageBox::sorry( this,
6771 i18n("This file is not a KWord file!"),
6772 i18n("Insert File"));
6773 delete store;
6774 return;
6775 }
6776
6777 TQDomDocument doc;
6778 doc.setContent( store->device() );
6779 TQDomElement word = doc.documentElement();
6780
6781 m_doc->loadPictureMap( word );
6782 store->close();
6783 m_doc->loadImagesFromStore( store );
6784 }
6785 if ( store )
6786 {
6787 bool b = store->open(maindoc);
6788 if ( !b )
6789 {
6790 KMessageBox::sorry( this,
6791 i18n("File name is not a KWord file!"),
6792 i18n("Insert File"));
6793 delete store;
6794 return;
6795 }
6796 TQDomDocument doc;
6797 doc.setContent( store->device() );
6798 TQDomElement word = doc.documentElement();
6799
6800 TQDomElement framesets = word.namedItem( "FRAMESETS" ).toElement();
6801 if ( !framesets.isNull() )
6802 {
6803 TQDomElement framesetElem = framesets.firstChild().toElement();
6804 // just in case
6805 while ( !framesetElem.isNull() && framesetElem.tagName() != "FRAMESET" )
6806 framesetElem = framesetElem.nextSibling().toElement();
6807
6808 if ( !framesetElem.isNull() )
6809 {
6810 KWTextFrameSet *textFrameSet = dynamic_cast<KWTextFrameSet *>( m_doc->frameSet(0) );
6811 KoTextCursor insertionCursor( textFrameSet->textDocument() );
6812 KWTextFrameSetEdit* edit = currentTextEdit();
6813 if ( edit && !edit->textFrameSet()->protectContent()) {
6814 textFrameSet = edit->textFrameSet();
6815 insertionCursor = *edit->cursor();
6816 }
6817 // Handle the main textframeset special - concatenate the text
6818 TQDomDocument domDoc( "PARAGRAPHS" );
6819 TQDomElement paragsElem = domDoc.createElement( "PARAGRAPHS" );
6820 domDoc.appendChild( paragsElem );
6821
6822 // Need an intermediate list otherwise nextSibling doesn't work after moving the node
6823 // to the other DOM tree ;)
6824 TQValueList<TQDomElement> paragList;
6825 TQValueList<TQString> inlineFsNames;
6826 TQDomElement fsElem;
6827
6828 TQDomNode n = framesetElem.firstChild().toElement();
6829 while( !n.isNull() )
6830 {
6831 TQDomElement e = n.toElement(); // try to convert the node to an element.
6832 if ( !e.isNull() && e.tagName() == "PARAGRAPH" )
6833 {
6834 paragList.append( e );
6835 // Handle inline framesets
6836 TQDomElement formatsElem = e.namedItem( "FORMATS" ).toElement();
6837 if ( !formatsElem.isNull() )
6838 {
6839 // Get references to inline framesets
6840 TQDomElement formatElem = formatsElem.firstChild().toElement();
6841 for ( ; !formatElem.isNull() ; formatElem = formatElem.nextSibling().toElement() )
6842 {
6843 TQDomElement anchorElem = formatElem.namedItem( "ANCHOR" ).toElement();
6844 if ( !anchorElem.isNull() )
6845 {
6846 TQString type = anchorElem.attribute( "type" );
6847 if ( type == "grpMgr" /* old syntax */ || type == "frameset" )
6848 {
6849 TQString iName = anchorElem.attribute( "instance" );
6850 inlineFsNames.append( iName );
6851 // inline framsets shall appear after the paragraph
6852 TQString tableName;
6853 TQDomElement table;
6854 fsElem = framesetElem.nextSibling().toElement();
6855 for ( ; !fsElem.isNull() ; fsElem = fsElem.nextSibling().toElement() )
6856 {
6857 if ( fsElem.tagName() == "FRAMESET" )
6858 {
6859 TQString name = fsElem.attribute( "name" );
6860 TQString grpMgr = fsElem.attribute( "grpMgr" );
6861 if ( name == iName )
6862 {
6863 paragList.append( fsElem );
6864 //kdDebug()<<k_funcinfo<<" Inline frameset: "<<name<<" added"<<endl;
6865 }
6866 else if ( grpMgr == iName )
6867 { // Table so we need to create table framset if it is new
6868 if ( grpMgr != tableName )
6869 {
6870 tableName = grpMgr;
6871 table = domDoc.createElement("FRAMESET");
6872 table.setAttribute("frameType", FT_TABLE);
6873 table.setAttribute("frameInfo", 0);
6874 table.setAttribute("protectSize", fsElem.attribute("protectSize","0"));
6875 table.setAttribute("name", tableName);
6876 table.setAttribute("visible", fsElem.attribute("visible","1"));
6877 paragList.append( table ); // same level as paragraphs, so it goes into the paragList
6878 //kdDebug()<<k_funcinfo<<" paragList Added new table: "<<grpMgr<<endl;
6879 }
6880
6881 table.appendChild( fsElem.cloneNode() ); // add the cell as child to the table frameset
6882 //kdDebug()<<k_funcinfo<<" Inline table: "<<grpMgr<<" Added new cell: "<<name<<endl;
6883 }
6884 //else kdDebug()<<k_funcinfo<<" Fixed frameset: "<<name<<endl;
6885 }
6886 //else kdDebug()<<k_funcinfo<<" Not frameset: "<<fsElem.tagName()<<endl;
6887 }
6888 //kdDebug()<<k_funcinfo<<" Treated "<<i<<" frameset elements"<<endl;
6889 }
6890 }
6891 }
6892 }
6893 }
6894 n = n.nextSibling();
6895 }
6896
6897 TQValueList<TQDomElement>::Iterator it = paragList.begin();
6898 TQValueList<TQDomElement>::Iterator end = paragList.end();
6899 for ( ; it!= end ; ++it )
6900 {
6901 //kdDebug()<<k_funcinfo<<" paragList tag: "<<(*it).tagName()<<" name: "<<(*it).attribute( "name" )<<" grpMgr: "<<(*it).attribute( "grpMgr" )<<endl;
6902 paragsElem.appendChild( *it );
6903 }
6904 //kdDebug() << k_funcinfo << "Paragraphs:\n" << domDoc.toCString() << endl;
6905
6906 // The fixed framesets
6907 // doctype SELECTION is used for fixed framesets
6908 TQDomDocument domDocFrames( "SELECTION" ); // see KWCanvas::copySelectedFrames
6909 TQDomElement topElem = domDocFrames.createElement( "SELECTION" );
6910 domDocFrames.appendChild( topElem );
6911 TQString tableName;
6912 TQDomElement table;
6913 TQValueList<TQString> fsInHeader;
6914 TQValueList<TQDomElement> framesetsList;
6915
6916 framesetElem = framesetElem.nextSibling().toElement();
6917 for ( ; !framesetElem.isNull() ; framesetElem = framesetElem.nextSibling().toElement() )
6918 {
6919 if ( framesetElem.tagName() == "FRAMESET" )
6920 {
6921 FrameSetType frameSetType = static_cast<FrameSetType>( KWDocument::getAttribute( framesetElem, "frameType", FT_BASE ) );
6922 KWFrameSet::Info info = static_cast<KWFrameSet::Info>( framesetElem.attribute("frameInfo").toInt() );
6923 if ( frameSetType == FT_TEXT &&
6924 (info == KWFrameSet::FI_FIRST_HEADER ||
6925 info == KWFrameSet::FI_EVEN_HEADER ||
6926 info == KWFrameSet::FI_ODD_HEADER ||
6927 info == KWFrameSet::FI_FIRST_FOOTER ||
6928 info == KWFrameSet::FI_EVEN_FOOTER ||
6929 info == KWFrameSet::FI_ODD_FOOTER)
6930 )
6931 fsInHeader += getInlineFramesets( framesetElem );
6932
6933 TQString name = framesetElem.attribute( "name" );
6934 TQString grpMgr = framesetElem.attribute( "grpMgr" );
6935 if ( !inlineFsNames.contains(name) && !inlineFsNames.contains(grpMgr) )
6936 { // fixed frameset
6937 if ( !grpMgr.isEmpty() )
6938 { // Table cell
6939 if ( grpMgr != tableName )
6940 { // New table (first cell)
6941 tableName = grpMgr;
6942 table = domDocFrames.createElement("FRAMESET");
6943 table.setAttribute("frameType", FT_TABLE);
6944 table.setAttribute("frameInfo", 0);
6945 table.setAttribute("protectSize", framesetElem.attribute("protectSize","0"));
6946 table.setAttribute("name", tableName);
6947 table.setAttribute("visible", framesetElem.attribute("visible","1"));
6948 framesetsList.append( table );
6949 //kdDebug()<<k_funcinfo<<" framesetsList Added new table: "<<grpMgr<<endl;
6950 }
6951 table.appendChild( framesetElem.cloneNode() ); // add the cell as child to the table frameset
6952 //kdDebug()<<k_funcinfo<<" Fixed table '"<<grpMgr<<"': Added new cell: '"<<name<<"'"<<endl;
6953 }
6954 else // other frameset type
6955 {
6956 framesetsList.append( framesetElem );
6957 //kdDebug()<<k_funcinfo<<" Fixed frameset: '"<<name<<"' added"<<endl;
6958 }
6959 }
6960 //else kdDebug()<<k_funcinfo<<" Inline frameset, skipped: "<<name<<endl;
6961 }
6962 //else kdDebug()<<k_funcinfo<<" Not frameset element, skipped: "<<framesetElem.tagName()<<endl;
6963 }
6964 it = framesetsList.begin();
6965 end = framesetsList.end();
6966 for ( ; it != end ; ++it )
6967 {
6968 framesetElem = (*it);
6969 FrameSetType frameSetType = static_cast<FrameSetType>( KWDocument::getAttribute( framesetElem, "frameType", FT_BASE ) );
6970 KWFrameSet::Info info = static_cast<KWFrameSet::Info>( framesetElem.attribute("frameInfo").toInt() );
6971 TQString name = framesetElem.attribute("name");
6972 TQString grpMgr = framesetElem.attribute( "grpMgr" );
6973 // We skip headers, footers and framsets/tables inside theese
6974 if ( !fsInHeader.contains(name) && !fsInHeader.contains(grpMgr) &&
6975 !( frameSetType == FT_TEXT &&
6976 (info == KWFrameSet::FI_FIRST_HEADER ||
6977 info == KWFrameSet::FI_EVEN_HEADER ||
6978 info == KWFrameSet::FI_ODD_HEADER ||
6979 info == KWFrameSet::FI_FIRST_FOOTER ||
6980 info == KWFrameSet::FI_EVEN_FOOTER ||
6981 info == KWFrameSet::FI_ODD_FOOTER) )
6982 )
6983 {
6984 hasFixedFramesets = true;
6985 topElem.appendChild( framesetElem );
6986 }
6987 }
6988 // Embedded documents
6989 TQDomDocument embeddedDoc( "SELECTION" );
6990 TQDomElement selElem = embeddedDoc.createElement( "SELECTION" );
6991 embeddedDoc.appendChild( selElem );
6992
6993 TQValueList<TQDomElement> embeddedList;
6994 TQDomElement embeddedElem = word.namedItem( "EMBEDDED" ).toElement();
6995 for ( ; !embeddedElem.isNull() ; embeddedElem = embeddedElem.nextSibling().toElement() )
6996 {
6997 if ( embeddedElem.tagName() == "EMBEDDED" )
6998 {
6999 embeddedList.append( embeddedElem );
7000 }
7001 }
7002 it = embeddedList.begin();
7003 end = embeddedList.end();
7004 bool hasEmbedded = false;
7005 for ( ; it!= end ; ++it )
7006 {
7007 selElem.appendChild( *it );
7008 hasEmbedded = true;
7009 }
7010 store->close();
7011
7012
7013 // Now we do the insertion
7014 if ( !macroCmd )
7015 macroCmd = new KMacroCommand( i18n("Insert File") );
7016
7017 if ( hasFixedFramesets )
7018 {
7019 // insert fixed framesets
7020 //kdDebug() << k_funcinfo << domDocFrames.toCString() << endl;
7021 m_doc->pasteFrames( topElem, macroCmd, false, false, false /* don't select frames */ );
7022 }
7023 if ( hasEmbedded )
7024 {
7025 //kdDebug()<<k_funcinfo<<" Embedded: \n"<<embeddedDoc.toCString()<<endl;
7026 if ( !macroCmd )
7027 macroCmd = new KMacroCommand( i18n("Insert File") );
7028 m_doc->insertEmbedded( store, selElem, macroCmd, 0 );
7029 }
7030
7031 // insert paragraphs and inline framesets (we always have at least one paragraph)
7032 KCommand *cmd = textFrameSet->pasteOasis( &insertionCursor, domDoc.toCString(), true );
7033
7034 if ( cmd ) {
7035 macroCmd->addCommand( cmd );
7036 }
7037 m_doc->addCommand( macroCmd );
7038
7039 }
7040 }
7041
7042 m_doc->loadImagesFromStore( store );
7043 m_doc->completePasting();
7044
7045 }
7046 delete store;
7047}
7048
7049TQValueList<TQString> KWView::getInlineFramesets( const TQDomNode &framesetElem)
7050{
7051 //kdDebug()<<k_funcinfo<<" Frameset: "<<framesetElem.toElement().attribute("name")<<endl;
7052 TQValueList<TQString> list;
7053 TQDomNode n = framesetElem.firstChild().toElement();
7054 for( ; !n.isNull(); n = n.nextSibling() )
7055 {
7056 TQDomElement e = n.toElement(); // try to convert the node to an element.
7057 if ( !e.isNull() && e.tagName() == "PARAGRAPH" )
7058 {
7059 TQDomElement formatsElem = e.namedItem( "FORMATS" ).toElement();
7060 if ( !formatsElem.isNull() )
7061 {
7062 // Get references to inline framesets
7063 TQDomElement formatElem = formatsElem.firstChild().toElement();
7064 for ( ; !formatElem.isNull() ; formatElem = formatElem.nextSibling().toElement() )
7065 {
7066 TQDomElement anchorElem = formatElem.namedItem( "ANCHOR" ).toElement();
7067 if ( !anchorElem.isNull() )
7068 {
7069 TQString type = anchorElem.attribute( "type" );
7070 if ( type == "grpMgr" /* old syntax */ || type == "frameset" )
7071 {
7072 TQString iName = anchorElem.attribute( "instance" );
7073 list.append( iName );
7074 //kdDebug()<<k_funcinfo<<" added: "<<iName<<endl;
7075 }
7076 }
7077 }
7078 }
7079 }
7080 }
7081 return list;
7082}
7083
7084void KWView::addBookmark()
7085{
7086 KWTextFrameSetEdit * edit = currentTextEdit();
7087 if ( edit )
7088 {
7089 //don't create list against viewmode. We must list all bookmarks.
7090 KWCreateBookmarkDia dia( m_doc->listOfBookmarkName(0L), this, 0 );
7091 if ( dia.exec() ) {
7092 TQString bookName = dia.bookmarkName();
7093 KoTextCursor start, end;
7094 if ( edit->textDocument()->hasSelection( KoTextDocument::Standard ) ) {
7095 start = edit->textDocument()->selectionStartCursor( KoTextDocument::Standard );
7096 end = edit->textDocument()->selectionEndCursor( KoTextDocument::Standard );
7097 } else {
7098 start = *edit->cursor();
7099 end = start;
7100 }
7101 int startSel = start.index();
7102 int endSel = end.index();
7103 m_doc->insertBookmark(bookName, start.parag(),end.parag(), startSel, endSel);
7104 }
7105 }
7106}
7107
7108void KWView::selectBookmark()
7109{
7110 KWSelectBookmarkDia dia( m_doc->listOfBookmarkName(viewMode()), m_doc, this, 0 );
7111 if ( dia.exec() ) {
7112 TQString bookName = dia.bookmarkSelected();
7113 const KoTextBookmark * book = m_doc->bookmarkByName( bookName );
7114 Q_ASSERT( book );
7115 if ( book )
7116 {
7117 Q_ASSERT( book->startParag() );
7118 Q_ASSERT( book->endParag() );
7119 if ( !book->startParag() || !book->endParag() )
7120 return;
7121 KWTextFrameSet* textfs = static_cast<KWTextDocument *>( book->textDocument() )->textFrameSet();
7122 m_gui->canvasWidget()->editTextFrameSet( textfs, book->startParag(), book->bookmarkStartIndex() );
7123 KWTextFrameSetEdit * edit = currentTextEdit();
7124 Q_ASSERT( edit );
7125 if ( edit )
7126 {
7127 edit->textDocument()->removeSelection( KoTextDocument::Standard );
7128 edit->textDocument()->setSelectionStart( KoTextDocument::Standard, edit->cursor() );
7129 edit->cursor()->setParag( book->endParag());
7130 edit->cursor()->setIndex(book->bookmarkEndIndex() );
7131 edit->textDocument()->setSelectionEnd( KoTextDocument::Standard, edit->cursor() );
7132 book->startParag()->setChanged( true );
7133 book->endParag()->setChanged( true );
7134 m_doc->slotRepaintChanged( edit->frameSet() );
7135 }
7136 }
7137 }
7138}
7139
7140void KWView::importStyle()
7141{
7142 KWImportStyleDia dia( m_doc, m_doc->styleCollection(), this );
7143 if ( dia.exec() && !dia.importedStyles().isEmpty() ) {
7144 m_doc->styleCollection()->importStyles( dia.importedStyles() );
7145 m_doc->setModified( true );
7146 m_doc->updateAllStyleLists();
7147 }
7148}
7149
7150void KWView::testAndCloseAllFrameSetProtectedContent()
7151{
7152 KWTextFrameSetEdit* edit = currentTextEdit();
7153 if ( edit && edit->textFrameSet()->protectContent()) {
7154 m_doc->terminateEditing( edit->frameSet());
7155 }
7156}
7157
7158void KWView::updateRulerInProtectContentMode()
7159{
7160 KWTextFrameSetEdit* edit = currentTextEdit();
7161 KoRuler * hRuler = m_gui ? m_gui->getHorzRuler() : 0;
7162
7163 if ( edit && hRuler) {
7164 if ( !edit->textFrameSet()->protectContent() )
7165 hRuler->changeFlags(KoRuler::F_INDENTS | KoRuler::F_TABS);
7166 else
7167 hRuler->changeFlags(0);
7168 hRuler->repaint();
7169 }
7170}
7171
7172void KWView::deselectAllFrames()
7173{
7174 m_gui->canvasWidget()->selectAllFrames( false );
7175}
7176
7177void KWView::insertDirectCursor()
7178{
7179#if 0
7180 insertDirectCursor( m_actionInsertDirectCursor->isChecked());
7181#endif
7182}
7183
7184void KWView::insertDirectCursor(bool b)
7185{
7186 m_doc->setInsertDirectCursor(b);
7187}
7188
7189void KWView::updateDirectCursorButton()
7190{
7191#if 0
7192 m_actionInsertDirectCursor->setChecked(m_doc->insertDirectCursor());
7193#endif
7194}
7195
7196void KWView::convertTableToText()
7197{
7198 KWCanvas * canvas = m_gui->canvasWidget();
7199 KWTableFrameSet *table = canvas->getCurrentTable();
7200 if ( table && table->isFloating() )
7201 {
7202 const TQByteArray arr = table->convertTableToText();
7203 KWAnchor * anchor = table->findAnchor( 0 );
7204 if ( anchor && arr.size() )
7205 {
7206 KWTextFrameSet *frameset = table->anchorFrameset();
7207 KoTextParag *parag = anchor->paragraph();
7208 int pos = anchor->index();
7209 KMacroCommand *macro = new KMacroCommand(i18n("Convert Table to Text"));
7210 KCommand *cmd = table->anchorFrameset()->deleteAnchoredFrame( anchor );
7211 if ( cmd )
7212 macro->addCommand( cmd);
7213
7214 m_gui->canvasWidget()->editTextFrameSet( frameset, parag, pos );
7215
7216 KWTextFrameSetEdit* edit = currentTextEdit();
7217 if ( edit && edit->textFrameSet())
7218 {
7219 cmd = edit->textFrameSet()->pasteOasis( edit->cursor(), arr, true );
7220 if ( cmd )
7221 macro->addCommand( cmd );
7222 }
7223 m_doc->addCommand(macro);
7224 }
7225 }
7226}
7227
7228void KWView::convertToTextBox()
7229{
7230 KWTextFrameSetEdit* edit = currentTextEdit();
7231 if ( !edit )
7232 return;
7233
7234 KWTextFrameSet* textfs = edit->textFrameSet();
7235 if( textfs->protectContent() || !textfs->textObject()->hasSelection() )
7236 return;
7237
7238 KWOasisSaver oasisSaver( m_doc );
7239 textfs->textDocument()->copySelection( oasisSaver.bodyWriter(), oasisSaver.savingContext(), KoTextDocument::Standard );
7240 if ( !oasisSaver.finish() )
7241 return;
7242 const TQByteArray arr = oasisSaver.data();
7243 if ( !arr.size() )
7244 return;
7245
7246 KCommand *cmd = textfs->textObject()->removeSelectedTextCommand( edit->textView()->cursor(), KoTextDocument::Standard );
7247 Q_ASSERT( cmd );
7248 KMacroCommand* macro = new KMacroCommand( i18n("Convert to Text Box"));
7249 macro->addCommand( cmd );
7250 // Where to place the resulting text box? Maybe it should be made inline?
7251 cmd = m_gui->canvasWidget()->createTextBox( KoRect(30,30,300,300) );
7252 Q_ASSERT( cmd );
7253 if ( cmd )
7254 macro->addCommand( cmd );
7255
7256 edit = currentTextEdit();
7257 Q_ASSERT( edit ); // if it can really be 0, we need to undo the above...
7258 if ( edit )
7259 {
7260 cmd = edit->textFrameSet()->pasteOasis( edit->textView()->cursor(), arr, true );
7261 if ( cmd )
7262 macro->addCommand( cmd );
7263 // Auto-resize the frame from its contents
7264 edit->textFrameSet()->layout();
7265 }
7266 m_doc->addCommand( macro );
7267}
7268
7269void KWView::slotAddIgnoreAllWord()
7270{
7271 KWTextFrameSetEdit* edit = currentTextEdit();
7272 if ( edit )
7273 m_doc->addSpellCheckIgnoreWord( edit->currentWordOrSelection() );
7274}
7275
7276void KWView::sortText()
7277{
7278 KWTextFrameSetEdit* edit = currentTextEdit();
7279 if ( edit && edit->textFrameSet()->hasSelection() )
7280 {
7281 KWSortDia dlg( this, "sort dia" );
7282 if ( dlg.exec() )
7283 {
7284 const TQByteArray arr = edit->textFrameSet()->sortText(dlg.getSortType());
7285 if ( arr.size() )
7286 {
7287 KCommand *cmd = edit->textFrameSet()->pasteOasis( edit->cursor(), arr, true );
7288 if ( cmd )
7289 m_doc->addCommand(cmd);
7290 }
7291 }
7292 }
7293}
7294
7295void KWView::addPersonalExpression()
7296{
7297 KWTextFrameSetEdit* edit = currentTextEdit();
7298 if ( !(edit && edit->textFrameSet()->hasSelection()))
7299 return;
7300
7301 TQString newExpression = edit->textFrameSet()->textObject()->selectedText();
7302 //load file !!!
7303 TQString tmp=locateLocal("data","kword/expression/perso.xml");
7304 TQFile file( tmp );
7305 if ( !file.open( IO_ReadOnly ) )
7306 return;
7307 TQDomDocument doc;
7308 doc.setContent( &file );
7309 file.close();
7310
7311 TQString group;
7312 TQMap<TQString, TQStringList>lstOfPersonalExp;
7313 TQStringList list;
7314 TQDomNode n = doc.documentElement().firstChild();
7315 for( ; !n.isNull(); n = n.nextSibling() )
7316 {
7317 if ( n.isElement() )
7318 {
7319 TQDomElement e = n.toElement();
7320 if ( e.tagName() == "Type" )
7321 {
7322 list.clear();
7323 group = i18n( e.namedItem( "TypeName" ).toElement().text().utf8() );
7324
7325 TQDomNode n2 = e.firstChild();
7326 for( ; !n2.isNull(); n2 = n2.nextSibling() )
7327 {
7328
7329 if ( n2.isElement() )
7330 {
7331 TQDomElement e2 = n2.toElement();
7332 if ( e2.tagName() == "Expression" )
7333 {
7334 TQString text = i18n( e2.namedItem( "Text" ).toElement().text().utf8() );
7335 list<<text;
7336 }
7337 }
7338 }
7339 lstOfPersonalExp.insert(group,list);
7340 group = "";
7341 }
7342 }
7343 }
7344 //save
7345 doc = TQDomDocument( "KWordExpression" );
7346 TQDomElement begin = doc.createElement( "KWordExpression" );
7347 doc.appendChild( begin );
7348 TQMapIterator<TQString, TQStringList> itPersonalExp = lstOfPersonalExp.find(i18n("Normal"));
7349 if ( itPersonalExp != lstOfPersonalExp.end())
7350 {
7351 list = itPersonalExp.data();
7352 list<<newExpression;
7353 lstOfPersonalExp.replace( i18n("Normal"), list);
7354 }
7355 else
7356 {
7357 list.clear();
7358 list<<newExpression;
7359 lstOfPersonalExp.insert( i18n("Normal"), list);
7360 }
7361
7362
7363 itPersonalExp = lstOfPersonalExp.begin();
7364 for ( ; itPersonalExp != lstOfPersonalExp.end(); ++itPersonalExp )
7365 {
7366 TQDomElement type = doc.createElement( "Type" );
7367 begin.appendChild( type );
7368 TQDomElement typeName = doc.createElement( "TypeName" );
7369 type.appendChild( typeName );
7370 typeName.appendChild( doc.createTextNode(itPersonalExp.key() ) );
7371 list=itPersonalExp.data();
7372 for( uint i=0;i<list.count();i++ )
7373 {
7374 TQDomElement expr = doc.createElement( "Expression" );
7375 type.appendChild( expr );
7376 TQDomElement text = doc.createElement( "Text" );
7377 expr.appendChild( text );
7378 text.appendChild( doc.createTextNode(list[i] ) );
7379 }
7380 }
7381 TQCString s = doc.toCString();
7382
7383 if ( !file.open( IO_WriteOnly ) )
7384 {
7385 kdDebug()<<"Error in addPersonalExpression()\n";
7386 return;
7387 }
7388 file.writeBlock(s,s.length());
7389 file.close();
7390 m_doc->refreshMenuExpression();
7391}
7392
7393void KWView::addWordToDictionary()
7394{
7395 KWTextFrameSetEdit* edit = currentTextEdit();
7396 if ( edit )
7397 {
7398 TQString word = edit->wordUnderCursor( *edit->cursor() );
7399 if ( !word.isEmpty() )
7400 m_doc->addWordToDictionary( word );
7401 }
7402}
7403
7404void KWView::embeddedStoreInternal()
7405{
7406 kdDebug(31001)<<k_funcinfo<<endl;
7407 KWFrameView *view = frameViewManager()->selectedFrame();
7408 KWFrame *frame = view == 0 ? 0 : view->frame();
7409 if( !frame)
7410 return;
7411 KWPartFrameSet *part = static_cast<KWPartFrameSet *>(frame->frameSet());
7412 part->storeInternal();
7413}
7414
7415void KWView::goToDocumentStructure()
7416{
7417 KWDocStruct* docStruct = getGUI()->getDocStruct();
7418 if (docStruct) docStruct->setFocusHere();
7419}
7420
7421void KWView::goToDocument()
7422{
7423 KWCanvas* canvas = getGUI()->canvasWidget();
7424 if (!canvas) return;
7425 canvas->setFocus();
7426}
7427
7428void KWView::deleteFrameSet( KWFrameSet * frameset)
7429{
7430 if ( frameset && frameset->frame(0))
7431 {
7432 frameViewManager()->view(frameset->frame(0))->setSelected( true );
7433 deleteFrame();
7434 }
7435}
7436
7437TQPtrList<TDEAction> KWView::listOfResultOfCheckWord( const TQString &word )
7438{
7439 TQPtrList<TDEAction> listAction;
7440 DefaultDictionary *dict = m_broker->defaultDictionary();
7441 const TQStringList lst = dict->suggest( word );
7442 if ( !lst.contains( word ) )
7443 {
7444 TQStringList::ConstIterator it = lst.begin();
7445 const TQStringList::ConstIterator end = lst.end();
7446 for ( ; it != end ; ++it )
7447 {
7448 if ( !(*it).isEmpty() ) // in case of removed subtypes or placeholders
7449 {
7450 TDEAction * act = new TDEAction( *it );
7451 connect( act, TQ_SIGNAL(activated()), this, TQ_SLOT(slotCorrectWord()) );
7452 listAction.append( act );
7453 }
7454 }
7455 }
7456 return listAction;
7457}
7458
7459void KWView::slotCorrectWord()
7460{
7461 TDEAction * act = (TDEAction *)(sender());
7462 KWTextFrameSetEdit* edit = currentTextEdit();
7463 if ( edit )
7464 {
7465 edit->selectWordUnderCursor( *(edit->cursor()) );
7466 m_doc->addCommand( edit->textObject()->replaceSelectionCommand( edit->cursor(), act->text(), i18n("Replace Word") ));
7467 }
7468}
7469
7470void KWView::slotChildActivated( bool a )
7471{
7472 // Same hack as in KoView
7473 KoViewChild* ch = child( (KoView*)sender() );
7474 if ( !ch )
7475 return;
7476 KWDocumentChild* kwchild = static_cast<KWDocumentChild *>( ch->documentChild() );
7477 KWPartFrameSet* fs = kwchild->partFrameSet();
7478 //kdDebug() << "KWView::slotChildActivated fs=" << fs << endl;
7479 Q_ASSERT( fs );
7480 if ( fs ) {
7481 if ( a )
7482 fs->startEditing();
7483 else
7484 fs->endEditing();
7485 }
7486 KoView::slotChildActivated( a );
7487}
7488
7489Broker *KWView::broker() const
7490{
7491 return m_broker;
7492}
7493
7494void KWView::slotUnitChanged( KoUnit::Unit unit )
7495{
7496 getGUI()->getHorzRuler()->setUnit( unit );
7497 getGUI()->getVertRuler()->setUnit( unit );
7498 if ( m_sbUnitLabel )
7499 m_sbUnitLabel->setText( ' ' + KoUnit::unitDescription( unit ) + ' ' );
7500}
7501
7502KWFrameViewManager* KWView::frameViewManager() const {
7503 return getGUI()->canvasWidget()->frameViewManager();
7504}
7505
7506void KWView::deleteSelectedFrames() {
7507 int nbCommand=0;
7508
7509 int docItem=0; // bitmask for changed doc items.
7510
7511 KMacroCommand * macroCmd = new KMacroCommand( i18n("Delete Frames") );
7512 KWFrameViewManager *fvMgr = frameViewManager();
7513 while (KWFrameView *frameView = fvMgr->selectedFrame()) {
7514 KWFrame *frame = frameView->frame();
7515 KWFrameSet *fs = frame->frameSet();
7516 if ( fs->isAFooter() || fs->isAHeader() )
7517 continue;
7518 KWTableFrameSet *table=fs->groupmanager();
7519 if ( table ) {
7520 docItem|=m_doc->typeItemDocStructure(table->type());
7521
7522 if ( table->isFloating() ) {
7523 docItem|=m_doc->typeItemDocStructure(fs->type());
7524
7525 KWAnchor * anchor = table->findAnchor( 0 );
7526 KCommand * cmd=table->anchorFrameset()->deleteAnchoredFrame( anchor );
7527 macroCmd->addCommand(cmd);
7528 nbCommand++;
7529 }
7530 else {
7531 KWDeleteTableCommand *cmd = new KWDeleteTableCommand( i18n("Delete Table"), table );
7532 cmd->execute();
7533 macroCmd->addCommand(cmd);
7534 nbCommand++;
7535 }
7536 }
7537 else { // a simple frame
7538 if ( fs->isMainFrameset() )
7539 continue;
7540
7541 docItem|=m_doc->typeItemDocStructure(fs->type());
7542
7543 if ( fs->isFloating() ) {
7544 KWAnchor * anchor = fs->findAnchor( 0 );
7545 KCommand *cmd=fs->anchorFrameset()->deleteAnchoredFrame( anchor );
7546 macroCmd->addCommand(cmd);
7547 nbCommand++;
7548 }
7549 else {
7550 KWDeleteFrameCommand *cmd = new KWDeleteFrameCommand( i18n("Delete Frame"), frame );
7551 cmd->execute();
7552 macroCmd->addCommand(cmd);
7553 nbCommand++;
7554 }
7555 }
7556 }
7557 if( nbCommand ) {
7558 m_doc->addCommand(macroCmd);
7559 m_doc->refreshDocStructure(docItem);
7560 }
7561 else
7562 delete macroCmd;
7563}
7564
7565
7566/******************************************************************/
7567/* Class: KWViewWidget */
7568/******************************************************************/
7569KWViewWidget::KWViewWidget( TQWidget *parent, KWView *view )
7570 : TQWidget( parent ),
7571 m_view ( view )
7572{
7573}
7574
7575void KWViewWidget::resizeEvent( TQResizeEvent *e )
7576{
7577 // Update zoom if width changes and fit width is used
7578 if ( ( e->size().width() != e->oldSize().width() )
7579 && ( m_view->kWordDocument()->zoomMode() == KoZoomMode::ZOOM_WIDTH ) )
7580 {
7581 TQTimer::singleShot( 0, m_view, TQ_SLOT( updateZoom() ) );
7582 }
7583
7584 TQWidget::resizeEvent( e );
7585}
7586
7587
7588/******************************************************************/
7589/* Class: KWGUI */
7590/******************************************************************/
7591KWGUI::KWGUI( const TQString& viewMode, TQWidget *parent, KWView *daView )
7592 : TQHBox( parent, "" ),
7593 m_view ( daView )
7594{
7595
7596 KWDocument * doc = m_view->kWordDocument();
7597
7598 m_horRuler = 0;
7599 m_vertRuler = 0;
7600
7601 // The splitter
7602 m_panner = new TQSplitter( TQt::Horizontal, this );
7603
7604 // The left side
7605 m_docStruct = new KWDocStruct( m_panner, doc, this );
7606 m_docStruct->setMinimumWidth( 0 );
7607
7608 // The right side
7609 m_right = new KWViewWidget( m_panner, m_view );
7610 TQGridLayout *gridLayout = new TQGridLayout( m_right, 2, 2 );
7611 m_canvas = new KWCanvas( viewMode, m_right, doc, this );
7612 gridLayout->addWidget( m_canvas, 1, 1 );
7613
7614 TQValueList<int> l;
7615 l << 10;
7616 l << 90;
7617 m_panner->setSizes( l );
7618
7619 KoPageLayout layout = doc->pageLayout();
7620
7621 m_tabChooser = new KoTabChooser( m_right, KoTabChooser::TAB_ALL );
7622 m_tabChooser->setReadWrite(doc->isReadWrite());
7623 gridLayout->addWidget( m_tabChooser, 0, 0 );
7624
7625 m_horRuler = new KoRuler( m_right, m_canvas->viewport(), TQt::Horizontal, layout,
7626 KoRuler::F_INDENTS | KoRuler::F_TABS,
7627 doc->unit(), m_tabChooser );
7628 m_horRuler->setReadWrite(doc->isReadWrite());
7629 gridLayout->addWidget( m_horRuler, 0, 1 );
7630
7631 m_vertRuler = new KoRuler( m_right, m_canvas->viewport(), TQt::Vertical, layout,
7632 0, doc->unit() );
7633 m_vertRuler->setReadWrite(doc->isReadWrite());
7634 gridLayout->addWidget( m_vertRuler, 1, 0 );
7635
7636 m_horRuler->setZoom( doc->zoomedResolutionX() );
7637 m_vertRuler->setZoom( doc->zoomedResolutionY() );
7638
7639 m_horRuler->setGridSize(doc->gridX());
7640
7641 connect( m_horRuler, TQ_SIGNAL( newPageLayout( const KoPageLayout & ) ), m_view, TQ_SLOT( newPageLayout( const KoPageLayout & ) ) );
7642 connect( m_horRuler, TQ_SIGNAL( newLeftIndent( double ) ), m_view, TQ_SLOT( newLeftIndent( double ) ) );
7643 connect( m_horRuler, TQ_SIGNAL( newFirstIndent( double ) ), m_view, TQ_SLOT( newFirstIndent( double ) ) );
7644 connect( m_horRuler, TQ_SIGNAL( newRightIndent( double ) ), m_view, TQ_SLOT( newRightIndent( double ) ) );
7645
7646 connect( m_horRuler, TQ_SIGNAL( doubleClicked() ), m_view, TQ_SLOT( slotHRulerDoubleClicked() ) );
7647 connect( m_horRuler, TQ_SIGNAL( doubleClicked(double) ), m_view, TQ_SLOT( slotHRulerDoubleClicked(double) ) );
7648 connect( m_horRuler, TQ_SIGNAL( unitChanged( KoUnit::Unit ) ), this, TQ_SLOT( unitChanged( KoUnit::Unit ) ) );
7649 connect( m_vertRuler, TQ_SIGNAL( newPageLayout( const KoPageLayout & ) ), m_view, TQ_SLOT( newPageLayout( const KoPageLayout & ) ) );
7650 connect( m_vertRuler, TQ_SIGNAL( doubleClicked() ), m_view, TQ_SLOT( formatPage() ) );
7651 connect( m_vertRuler, TQ_SIGNAL( unitChanged( KoUnit::Unit ) ), this, TQ_SLOT( unitChanged( KoUnit::Unit ) ) );
7652
7653 m_horRuler->hide();
7654 m_vertRuler->hide();
7655
7656 m_canvas->show();
7657
7658 reorganize();
7659
7660 connect( m_horRuler, TQ_SIGNAL( tabListChanged( const KoTabulatorList & ) ), m_view,
7661 TQ_SLOT( tabListChanged( const KoTabulatorList & ) ) );
7662
7663 setKeyCompression( true );
7664 setAcceptDrops( true );
7665 setFocusPolicy( TQWidget::NoFocus );
7666}
7667
7668void KWGUI::showGUI()
7669{
7670 reorganize();
7671}
7672
7673void KWGUI::resizeEvent( TQResizeEvent *e )
7674{
7675 TQWidget::resizeEvent( e );
7676 reorganize();
7677}
7678
7679void KWGUI::reorganize()
7680{
7681 int hSpace = m_vertRuler->minimumSizeHint().width();
7682 int vSpace = m_horRuler->minimumSizeHint().height();
7683 if(m_view->kWordDocument()->showRuler())
7684 {
7685 m_vertRuler->show();
7686 m_horRuler->show();
7687 m_tabChooser->show();
7688 m_tabChooser->setGeometry( 0, 0, hSpace, vSpace );
7689 }
7690 else
7691 {
7692 m_vertRuler->hide();
7693 m_horRuler->hide();
7694 m_tabChooser->hide();
7695 hSpace = 0;
7696 vSpace = 0;
7697 }
7698
7699 if(m_view->kWordDocument()->showdocStruct()) {
7700 if(m_docStruct->isHidden()) {
7701 m_docStruct->show();
7702 if(m_panner->sizes()[0] < 50) {
7703 TQValueList<int> l;
7704 l << 100;
7705 l << width()-100;
7706 m_panner->setSizes( l );
7707 }
7708 }
7709 } else
7710 m_docStruct->hide();
7711
7712 if( m_view->statusBar())
7713 {
7714 if(m_view->kWordDocument()->showStatusBar())
7715 m_view->statusBar()->show();
7716 else
7717 m_view->statusBar()->hide();
7718 }
7719
7720 if ( m_view->kWordDocument()->showScrollBar())
7721 {
7722 m_canvas->setVScrollBarMode(TQScrollView::Auto);
7723 m_canvas->setHScrollBarMode(TQScrollView::Auto);
7724 }
7725 else
7726 {
7727 m_canvas->setVScrollBarMode(TQScrollView::AlwaysOff);
7728 m_canvas->setHScrollBarMode(TQScrollView::AlwaysOff);
7729 }
7730}
7731
7732void KWGUI::unitChanged( KoUnit::Unit u )
7733{
7734 m_view->kWordDocument()->setUnit( u );
7735}
7736
7737TQPoint KWView::applyViewTransformations( const TQPoint& p ) const
7738{
7739 return viewMode()->normalToView( m_doc->zoomPoint( KoPoint( p ) ) );
7740}
7741
7742TQPoint KWView::reverseViewTransformations( const TQPoint& p ) const
7743{
7744 return m_doc->unzoomPoint( viewMode()->viewToNormal( p ) ).toTQPoint();
7745}
7746
7747int KWView::currentPage() const {
7748 return m_currentPage->pageNumber();
7749}
7750
7751void KWView::slotDocumentLoadingCompleted()
7752{
7753 updateStyleList();
7754}
7755
7756#include "KWView.moc"
An anchor is a special character, or 'custom item'.
Definition KWAnchor.h:35
Class: KWCanvas This class is responsible for the rendering of the frames to the screen as well as th...
Definition KWCanvas.h:61
KWTableFrameSet * getCurrentTable() const
The current table (either because one or more cells are selected, or because the cursor is in a table...
Definition KWCanvas.h:162
Command created when creating a frame.
Definition KWCommand.h:436
Command created when deleting a frame.
Definition KWCommand.h:415
Command created when deleting a table.
Definition KWCommand.h:465
This class implements the 'find' functionality ( the "search next, prompt" loop ) and the 'replace' f...
The variable showing the footnote number in superscript, in the text.
Definition KWVariable.h:106
KWFootNoteFrameSet * frameSet() const
The frameset that contains the text for this footnote.
Definition KWVariable.h:126
Command created when changing frame border.
Definition KWCommand.h:111
Command created when we changed a clipart or picture.
Definition KWCommand.h:246
static void recalcAllFrames(KWDocument *doc)
Update the z-ordering for all frames of the whole document.
void update()
Update the z-ordering around the frame we host the framelist for.
Command created when one or more frames are moved.
Definition KWCommand.h:273
Command created when the properties of a frame are changed (e.g.
Definition KWCommand.h:297
This object is created to edit a particular frameset in a particular view The view's canvas creates i...
virtual KWFrameSetEdit * currentTextEdit()
Return the current most-low-level text edit object.
This command makes a frameset floating and non-floating.
Definition KWCommand.h:366
Class: KWFrameSet Base type, a frameset holds content as well as frames to show that content.
Definition KWFrameSet.h:62
KWAnchor * findAnchor(int frameNum)
Return the anchor object for this frame number.
virtual FrameSetType type() const
The type of frameset.
Definition KWFrameSet.h:76
Info
The different types of textFramesets (that TEXT is important here!) FI_BODY = normal text frames.
Definition KWFrameSet.h:91
const TQPtrList< KWFrame > & frameIterator() const
Iterator over the child frames.
Definition KWFrameSet.h:159
unsigned int frameCount() const
Get number of child frames.
Definition KWFrameSet.h:163
bool isFloating() const
Return true if this frameset is floating (inline), false if it's fixed.
Definition KWFrameSet.h:372
KWTableFrameSet * groupmanager() const
returns the groupManager this frameset belongs to.
Definition KWFrameSet.h:408
KWTextFrameSet * anchorFrameset() const
Return the frameset in which our anchor is - assuming isFloating()
Definition KWFrameSet.h:374
KWFrame * frame(unsigned int _num) const
get a frame by number
TQString name() const
get/set frameset name. For tables in particular, this must be unique
Definition KWFrameSet.h:428
Command created when applying a framestyle.
Definition KWCommand.h:153
The user-visible style for frames (borders and background)
Class that knows about all the (visible) frames in the document and will act as a manager between the...
KWFrameView * selectedFrame() const
Returns the first selected frame.
an instance of a KWFrameView represents the view in the MVC model of a frame; there can be multiple K...
Definition KWFrameView.h:82
void setSelected(bool selected, MouseMeaning selectPolicy=MEANING_MOUSE_SELECT)
Set the selected state of this frameView.
KWFrame * frame() const
returns the frame this frameView represents
bool selected() const
returns if this frameView is selected. A selected frame is shown differently on screen.
Definition KWFrameView.h:93
This class represents a single frame.
Definition KWFrame.h:68
KWFrameSet * frameSet() const
Data stucture methods.
Definition KWFrame.h:143
void setZOrder(int z)
The z-order of the frame, relative to the other frames on the same page.
Definition KWFrame.h:155
int pageNumber() const
The page on which this frame is.
Definition KWFrame.cpp:116
const KoBorder & leftBorder() const
All borders can be custom drawn with their own colors etc.
Definition KWFrame.h:170
const KoRect & rect() const
Return the rectangle for this frame.
Definition KWFrame.h:201
KWFrame * getCopy()
returns a copy of self
Definition KWFrame.cpp:135
Command created when inserting a column.
Definition KWCommand.h:495
Command created when inserting a row.
Definition KWCommand.h:517
This is used to save a bunch of paragraphs into a oasis store in memory, as some features do (e....
Command created when changing the page layout.
Definition KWCommand.h:397
This class represents a printed page of the document.
Definition KWPage.h:30
int pageNumber() const
returns the number of this page as it will be shown to the user.
Definition KWPage.h:102
double width() const
return the width of this page (in pt)
Definition KWPage.cpp:38
double rightMargin() const
return the width of the margin at left (in pt);
Definition KWPage.cpp:108
const KoRect rect() const
return a KoRect with the (pt) sizes of this page. Margins are ignored for this function.
Definition KWPage.cpp:137
A frameset that contains an embedded object (a KWDocumentChild)
void startEditing()
Called by KWView when the object is being edited (activated).
void endEditing()
Called by KWView when the object is not being edited anymore (deactivated).
Command created when removing a column.
Definition KWCommand.h:552
Command created when removing a row.
Definition KWCommand.h:535
A dialog that can be used to resize columns of a table using numeric input.
A class that calculates and show the statistics for a certain KWDocument.
This class implements tables by acting as the manager for the frame(set)s which make up the table cel...
virtual FrameSetType type() const
The type of frameset.
KCommand * splitCell(unsigned int intoRows, unsigned int intoColumns, unsigned int column, unsigned int row, TQPtrList< KWFrameSet > listFrameSet=TQPtrList< KWFrameSet >(), TQPtrList< KWFrame >listFrame=TQPtrList< KWFrame >())
split one cell into a number of cells and return a command for undo purposes.
unsigned int getColumns() const
returns the number of columns
KCommand * joinCells(unsigned int firstColumn, unsigned int firstRow, unsigned int endColumn, unsigned int endRow)
merge cells to one cell.
unsigned int getRows() const
returns the number of rows
Command created when applying a tablestyle.
Definition KWCommand.h:174
Table style (can created/modified/deleted by the user) A table style is simply a paragraph style and ...
This is our KoTextDocument reimplementation, to create KWTextParag instead of KoTextParags,...
KWTextFrameSet * textFrameSet() const
Return the text frameset in which this document is.
Object that is created to edit a Text frame set (KWTextFrameSet).
KoBorder border(KoBorder::BorderType type)
Return the requested border of the paragraph that the cursor currently is in.
bool openLink(KoLinkVariable *variable)
Called by KoTextView when clicking on a link.
Class: KWTextFrameSet Contains text (KoTextObject) and frames to display that text.
bool hasSelection() const
return true if some text is selected
TQByteArray sortText(SortType type) const
Sort selected paragraphs Return a complete OASIS store, ready for "pasting".
KoTextObject * textObject() const
Return the contained text object.
virtual void layout()
Invalidate all paragraphs and start re-formatting.
virtual void finalize()
Called once the frameset has been completely loaded or constructed.
void highlightPortion(KoTextParag *parag, int index, int length, KWCanvas *canvas, bool repaint=true, KDialogBase *dialog=0)
Highlighting support (for search/replace, spellchecking etc.)
This class extends KoTextParag for KWord-specific formatting stuff, custom items, loading and saving.
Definition KWTextParag.h:41
Command created when ungrouping a table.
Definition KWCommand.h:449
A mode for previewing the overall document Pages are organized in a grid (mostly useful when zooming ...
Definition KWViewMode.h:223
The 'edit only one text frameset' view mode.
Definition KWViewMode.h:253
static KWTextFrameSet * determineTextFrameSet(KWDocument *doc)
Return a text frameset that the user has either selected or is currently editing, returning the main ...
Abstract base class for KWCanvas's view modes.
Definition KWViewMode.h:48
virtual void setPageLayout(KoRuler *hRuler, KoRuler *vRuler, const KoPageLayout &layout)
Called when the page layout is set, or changes.
virtual TQRect rulerFrameRect()
The result of this is passed to setFrameStartEnd for both rulers (after adjustement with pageCorner()...
virtual const TQString type() const =0
Return the name of the viewmode, used for loading/saving.
Identifies a frame.
Definition KWCommand.h:98