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