kword

KWView.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003    Copyright (C) 2001 David Faure <faure@kde.org>
00004    Copyright (C) 2005 Thomas Zander <zander@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA
00020 */
00021 
00022 #undef Unsorted
00023 
00024 #include "KWView.h"
00025 
00026 #include "KWordViewIface.h"
00027 #include "KWConfigFootNoteDia.h"
00028 #include "defs.h"
00029 #include "KWDeleteDia.h"
00030 #include "KWDocStruct.h"
00031 #include "KWFootNoteDia.h"
00032 #include "KWInsertDia.h"
00033 #include "KWAnchor.h"
00034 #include "KoTextBookmark.h"
00035 #include "KWCanvas.h"
00036 #include "KWCommand.h"
00037 #include "KWConfig.h"
00038 #include "KWCreateBookmarkDia.h"
00039 #include "KWDocument.h"
00040 #include "KWEditPersonnalExpression.h"
00041 #include "KWFormulaFrameSet.h"
00042 #include "KWFrame.h"
00043 #include "KWPictureFrameSet.h"
00044 #include "KWFrameStyle.h"
00045 #include "KWFrameStyleManager.h"
00046 #include "KWImportStyleDia.h"
00047 #include "KWInsertPageDia.h"
00048 #include "KWInsertPicDia.h"
00049 #include "KWPartFrameSet.h"
00050 #include "KWStyleManager.h"
00051 #include "KWTableFrameSet.h"
00052 #include "KWTableStyle.h"
00053 #include "KWTableStyleManager.h"
00054 #include "KWTextDocument.h"
00055 #include "KWVariable.h"
00056 #include "KWViewMode.h"
00057 #include "KWMailMergeDataBase.h"
00058 #include "KWMailMergeLabelAction.h"
00059 #include "KWResizeTableDia.h"
00060 #include "KWFindReplace.h"
00061 #include "KWSortDia.h"
00062 #include "KWSplitCellDia.h"
00063 #include "KWTableDia.h"
00064 #include "KWCollectFramesetsVisitor.h"
00065 #include "KWOasisLoader.h"
00066 #include "KWOasisSaver.h"
00067 #include "KWFrameList.h"
00068 #include "KWPageManager.h"
00069 #include "KWPage.h"
00070 #include "KWFrameViewManager.h"
00071 #include "KWFrameView.h"
00072 #include "KWStatisticsDialog.h"
00073 
00074 #include <kformuladocument.h>
00075 #include <kformulamimesource.h>
00076 
00077 #include <KoRichText.h>
00078 #include <KoAutoFormat.h>
00079 #include <KoAutoFormatDia.h>
00080 #include <KoChangeCaseDia.h>
00081 #include <KoCharSelectDia.h>
00082 #include <KoCommentDia.h>
00083 #include <KoCreateStyleDia.h>
00084 #include <KoDocumentInfo.h>
00085 #include <KoFontDia.h>
00086 #include <KoFrame.h>
00087 #include <KoInsertLink.h>
00088 #include <KoMainWindow.h>
00089 #include <KoParagDia.h>
00090 #include <KoPartSelectAction.h>
00091 #include <KoPictureFilePreview.h>
00092 #include <KoSearchDia.h>
00093 #include <KoStore.h>
00094 #include <KoStoreDrag.h>
00095 #include <KoTemplateCreateDia.h>
00096 #include <KoCompletionDia.h>
00097 #include <KoVariable.h>
00098 #include <KoCustomVariablesDia.h>
00099 #include <KoTextObject.h>
00100 #include <tkcoloractions.h>
00101 #include <KoSpeaker.h>
00102 
00103 #include <kparts/partmanager.h>
00104 #include <kaccelgen.h>
00105 #include <kcolordialog.h>
00106 #include <kdebug.h>
00107 #include <kfiledialog.h>
00108 #include <kimageio.h>
00109 #include <kinputdialog.h>
00110 #include <kio/netaccess.h>
00111 #include <kmessagebox.h>
00112 #include <kparts/event.h>
00113 #include <kstandarddirs.h>
00114 #include <kstatusbar.h>
00115 #include <kstdaccel.h>
00116 #include <kstdaction.h>
00117 #include <ktempfile.h>
00118 #include <kurldrag.h>
00119 #include <kdeversion.h>
00120 #include <kiconloader.h>
00121 
00122 #include <qclipboard.h>
00123 #include <qapplication.h>
00124 #include <qgroupbox.h>
00125 #include <qlayout.h>
00126 #include <qpaintdevicemetrics.h>
00127 #include <qprogressdialog.h>
00128 #include <qregexp.h>
00129 #include <qtimer.h>
00130 #include <qbuffer.h>
00131 
00132 #include <stdlib.h>
00133 
00134 #include <kspell2/dialog.h>
00135 #include <kspell2/defaultdictionary.h>
00136 #include "KoSpell.h"
00137 
00138 using namespace KSpell2;
00139 
00140 /******************************************************************/
00141 /* Class: TableInfo                                               */
00142 /******************************************************************/
00143 class TableInfo {
00144     public:
00145         TableInfo( const QValueList<KWFrameView*>& selectedFrames ) {
00146             m_protectContent = false;
00147             //m_views = selectedFrames;
00148             int amountSelected = 0;
00149             m_cell = 0;
00150             QMap<KWTableFrameSet*, QValueList<unsigned int> > tableRows, tableCols;
00151 
00152             QValueList<KWFrameView*>::const_iterator framesIterator = selectedFrames.begin();
00153             for(;framesIterator != selectedFrames.end(); ++framesIterator) {
00154                 KWFrameView *view = *framesIterator;
00155                 if(!view->selected()) continue;
00156                 KWFrameSet *fs = view->frame()->frameSet();
00157                 Q_ASSERT(fs);
00158                 KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell*>(fs);
00159                 if(cell == 0) continue;
00160                 amountSelected++;
00161                 if(cell->protectContent())
00162                     m_protectContent=true;
00163 
00164                 if(! tableRows.contains(fs->groupmanager())) { // create empty lists.
00165                     QValueList<unsigned int> rows;
00166                     for(unsigned int i=fs->groupmanager()->getRows(); i != 0; i--)
00167                         rows.append(0);
00168                     tableRows.insert(fs->groupmanager(), rows);
00169                     QValueList<unsigned int> cols;
00170                     for(unsigned int i=fs->groupmanager()->getColumns(); i != 0; i--)
00171                         cols.append(0);
00172                     tableCols.insert(fs->groupmanager(), cols);
00173                 }
00174                 QValueList<unsigned int> rows = tableRows[fs->groupmanager()];
00175                 for(unsigned int r=cell->firstRow(); r <= cell->lastRow(); r++)
00176                     rows[r] = rows[r] + 1;
00177                 tableRows[fs->groupmanager()] = rows;
00178                 QValueList<unsigned int> columns = tableCols[fs->groupmanager()];
00179                 for(unsigned int c=cell->firstColumn(); c <= cell->lastColumn(); c++)
00180                     columns[c] = columns[c] + 1;
00181                 tableCols[fs->groupmanager()] = columns;
00182 
00183                 if(m_cell == 0 || m_cell->firstRow() > cell->firstRow() ||
00184                         m_cell->firstRow() == cell->firstRow() &&
00185                         m_cell->firstColumn() > cell->firstColumn())
00186                     m_cell = cell;
00187             }
00188 
00189             m_selected = amountSelected != 0;
00190             m_oneCellSelected = amountSelected == 1;
00191             if(amountSelected == 0) return;
00192 
00193             for(QMapIterator<KWTableFrameSet*, QValueList<unsigned int> > iter = tableRows.begin();
00194                     iter != tableRows.end(); ++iter) {
00195                 QValueList<unsigned int> rows = iter.data();
00196                 QValueListIterator<unsigned int> rowsIter = rows.begin();
00197                 for(int x=0;rowsIter != rows.end(); ++rowsIter, x++)
00198                     if(*rowsIter == iter.key()->getColumns())
00199                         m_rows.append(x);
00200 
00201                 QValueList<unsigned int> columns = tableCols[iter.key()];
00202                 QValueListIterator<unsigned int> colsIter = columns.begin();
00203                 for(int x=0;colsIter != columns.end(); ++colsIter, x++)
00204                     if(*colsIter == iter.key()->getRows())
00205                         m_columns.append(x);
00206             }
00207         }
00208 
00209         int tableCellsSelected() { return m_selected; }
00210         int amountRowsSelected() { return m_rows.count(); }
00211         bool amountColumnsSelected() { return m_columns.count(); }
00212         bool oneCellSelected() { return m_oneCellSelected; }
00213         bool protectContentEnabled() { return m_protectContent; }
00214         QValueList<uint> selectedRows() { return m_rows; }
00215         QValueList<uint> selectedColumns() { return m_columns; }
00216         KWTableFrameSet::Cell *firstSelectedCell() { return m_cell; }
00217     private:
00218         //QValueList<KWFrameView*> m_views;
00219         bool m_oneCellSelected, m_selected, m_protectContent;
00220         QValueList<uint> m_rows, m_columns;
00221         KWTableFrameSet::Cell *m_cell;
00222 };
00223 
00224 /******************************************************************/
00225 /* Class: KWView                                                  */
00226 /******************************************************************/
00227 KWView::KWView( const QString& viewMode, QWidget *parent, const char *name, KWDocument* doc )
00228     : KoView( doc, parent, name )
00229 {
00230     m_doc = doc;
00231     m_gui = 0;
00232 
00233     m_dcop = 0;
00234     dcopObject(); // build it
00235     m_fsInline=0;
00236     m_spell.kospell = 0;
00237     m_spell.dlg = 0;
00238     m_broker = Broker::openBroker( KSharedConfig::openConfig( "kwordrc" ) );
00239     m_spell.macroCmdSpellCheck=0L;
00240     m_spell.textIterator = 0L;
00241     m_currentPage = m_doc->pageManager()->page(m_doc->startPage());
00242     m_specialCharDlg=0L;
00243     m_searchEntry = 0L;
00244     m_replaceEntry = 0L;
00245     m_findReplace = 0L;
00246     m_fontDlg = 0L;
00247     m_paragDlg = 0L;
00248     m_tableSplit.columns = 1;
00249     m_tableSplit.rows = 1;
00250 
00251     m_actionList.setAutoDelete( true );
00252     m_variableActionList.setAutoDelete( true );
00253     // Default values.
00254     m_zoomViewModeNormal.m_zoom = m_doc->zoom();
00255     m_zoomViewModeNormal.m_zoomMode = m_doc->zoomMode();
00256     m_zoomViewModePreview.m_zoom = 33; // TODO: bad to leave hardcoded...
00257     m_zoomViewModePreview.m_zoomMode = KoZoomMode::ZOOM_CONSTANT;
00258 
00259     m_viewFrameBorders = m_doc->viewFrameBorders();
00260     KoView::setZoom( m_doc->zoomedResolutionY() /* KoView only supports one zoom */ ); // initial value
00261     //m_viewTableGrid = true;
00262 
00263     setInstance( KWFactory::instance() );
00264     if ( !m_doc->isReadWrite() )
00265         setXMLFile( "kword_readonly.rc" );
00266     else
00267         setXMLFile( "kword.rc" );
00268 
00269 
00270     QObject::connect( this, SIGNAL( embeddImage( const QString & ) ),
00271                       this, SLOT( slotEmbedImage( const QString & ) ) );
00272 
00273     setKeyCompression( TRUE );
00274     setAcceptDrops( TRUE );
00275 
00276     setupActions();
00277 
00278     m_gui = new KWGUI( viewMode, this, this );
00279     m_gui->setGeometry( 0, 0, width(), height() );
00280     m_gui->show();
00281 
00282     m_sbPageLabel = 0;
00283     m_sbModifiedLabel = 0;
00284     m_sbFramesLabel = 0;
00285     m_sbOverwriteLabel = 0;
00286     m_sbZoomLabel = 0;
00287     m_sbUnitLabel = 0;
00288     if ( KStatusBar* sb = statusBar() ) // No statusbar in e.g. konqueror
00289     {
00290         m_sbPageLabel = new KStatusBarLabel( QString::null, 0, sb );
00291         m_sbPageLabel->setAlignment( AlignLeft | AlignVCenter );
00292         addStatusBarItem( m_sbPageLabel, 0 );
00293 
00294         m_sbModifiedLabel = new KStatusBarLabel( "   ", 0, sb );
00295         m_sbModifiedLabel->setAlignment( AlignLeft | AlignVCenter );
00296         addStatusBarItem( m_sbModifiedLabel, 0 );
00297 
00298         m_sbFramesLabel = new KStatusBarLabel( QString::null, 0, sb );
00299         m_sbFramesLabel->setAlignment( AlignLeft | AlignVCenter );
00300         addStatusBarItem( m_sbFramesLabel, 1 );
00301 
00302         m_sbOverwriteLabel = new KStatusBarLabel( ' ' + i18n( "INSRT" ) + ' ', 0, sb );
00303         m_sbOverwriteLabel->setAlignment( AlignHCenter | AlignVCenter );
00304         addStatusBarItem( m_sbOverwriteLabel, 0 );
00305 
00306         m_sbZoomLabel = new KStatusBarLabel( ' ' + QString::number( m_doc->zoom() ) + "% ", 0, sb );
00307         m_sbZoomLabel->setAlignment( AlignHCenter | AlignVCenter );
00308         addStatusBarItem( m_sbZoomLabel, 0 );
00309 
00310         m_sbUnitLabel = new KStatusBarLabel( ' ' + KoUnit::unitDescription( m_doc->unit() ) + ' ', 0, sb );
00311         m_sbUnitLabel->setAlignment( AlignHCenter | AlignVCenter );
00312         addStatusBarItem( m_sbUnitLabel, 0 );
00313     }
00314 
00315     connect( m_doc, SIGNAL( modified( bool ) ),
00316              this, SLOT( documentModified( bool )) );
00317 
00318     connect( m_doc, SIGNAL( numPagesChanged() ),
00319              this, SLOT( numPagesChanged()) );
00320 
00321     connect( m_doc, SIGNAL( pageLayoutChanged( const KoPageLayout& ) ),
00322              this, SLOT( slotPageLayoutChanged( const KoPageLayout& )) );
00323 
00324     connect( m_doc, SIGNAL( docStructureChanged(int) ),
00325              this, SLOT( docStructChanged(int)) );
00326 
00327     connect( m_doc, SIGNAL( unitChanged(KoUnit::Unit) ),
00328              this, SLOT( slotUnitChanged(KoUnit::Unit) ) );
00329 
00330     connect( m_doc, SIGNAL( sig_refreshMenuCustomVariable()),
00331              this, SLOT( refreshCustomMenu()));
00332 
00333     connect( m_doc, SIGNAL( completed() ),
00334              this, SLOT( slotDocumentLoadingCompleted() ) );
00335 
00336     connect( frameViewManager(), SIGNAL(sigFrameSelectionChanged()),
00337              this, SLOT( frameSelectedChanged()));
00338 
00339     connect( frameViewManager(), SIGNAL(sigFrameSetRenamed()),
00340              this, SLOT( updateFrameStatusBarItem()));
00341 
00342     connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
00343              this, SLOT( clipboardDataChanged() ) );
00344 
00345     connect( m_gui->canvasWidget(), SIGNAL(currentFrameSetEditChanged()),
00346              this, SLOT(slotFrameSetEditChanged()) );
00347 
00348     connect( m_gui->canvasWidget(), SIGNAL( currentMouseModeChanged(int) ),
00349              this, SLOT( showMouseMode(int) ) );
00350 
00351     connect( m_gui->canvasWidget(), SIGNAL( overwriteModeChanged( bool ) ),
00352              this, SLOT( changeOverwriteMode( bool ) ) );
00353 
00354     // Cut and copy are directly connected to the selectionChanged signal
00355     if ( m_doc->isReadWrite() )
00356     {
00357         connect( m_gui->canvasWidget(), SIGNAL(selectionChanged(bool)),
00358                  this, SLOT(slotChangeCutState(bool )) );
00359         connect (m_gui->canvasWidget(), SIGNAL(selectionChanged(bool)),
00360                  this, SLOT(slotChangeCaseState(bool )));
00361     }
00362     else
00363     {
00364         m_actionEditCut->setEnabled( false );
00365         m_actionChangeCase->setEnabled( false );
00366     }
00367 
00368     connect( m_gui->canvasWidget(), SIGNAL(selectionChanged(bool)),
00369              m_actionEditCopy, SLOT(setEnabled(bool)) );
00370 
00371     //connect (m_gui->canvasWidget(), SIGNAL(selectionChanged(bool)),
00372     //         m_actionCreateStyleFromSelection, SLOT(setEnabled(bool)));
00373 
00374     connect (m_gui->canvasWidget(), SIGNAL(selectionChanged(bool)),
00375              m_actionConvertToTextBox, SLOT(setEnabled(bool)));
00376     connect (m_gui->canvasWidget(), SIGNAL(selectionChanged(bool)),
00377              m_actionAddPersonalExpression, SLOT(setEnabled(bool )));
00378     connect (m_gui->canvasWidget(), SIGNAL(selectionChanged(bool)),
00379              m_actionSortText, SLOT(setEnabled(bool )));
00380 
00381     connect( m_gui->canvasWidget(), SIGNAL(docStructChanged(int)),
00382              this, SLOT(docStructChanged(int)));
00383 
00384     connect( m_gui->canvasWidget(), SIGNAL(updateRuler()),
00385              this, SLOT(slotUpdateRuler()));
00386 
00387     if ( shell() )
00388     {
00389         connect( shell(), SIGNAL( documentSaved()), m_doc,SLOT(slotDocumentInfoModifed() ) );
00390         changeNbOfRecentFiles( m_doc->maxRecentFiles() );
00391     }
00392 
00393     m_gui->canvasWidget()->updateCurrentFormat();
00394     setFocusProxy( m_gui->canvasWidget() );
00395 
00396     //when kword is embedded into konqueror apply a zoom=100
00397     //in konqueror we can't change zoom -- ### TODO ?
00398     if(!m_doc->isReadWrite())
00399     {
00400         setZoom( 100, true );
00401         slotUpdateRuler();
00402         initGui();
00403     }
00404 
00405     // Determine initial scroll position
00406     // We do this delayed, so that the GUI has been fully constructed
00407     // (and e.g. the statusbar can repaint).
00408     QTimer::singleShot( 0, this, SLOT( slotSetInitialPosition() ) );
00409     QTimer::singleShot( 0, this, SLOT( updateZoom() ) );
00410 }
00411 
00412 KWView::~KWView()
00413 {
00414     delete m_tableActionList.first(); // the first one is the separator.
00415     clearSpellChecker();
00416 
00417     delete m_searchEntry;
00418     m_searchEntry = 0L;
00419     delete m_replaceEntry;
00420     m_replaceEntry = 0L;
00421     if ( m_specialCharDlg )
00422         m_specialCharDlg->closeDialog(); // will call slotSpecialCharDlgClosed
00423 
00424     // Abort any find/replace
00425     delete m_findReplace;
00426     // Delete gui while we still exist ( it needs documentDeleted() )
00427     delete m_gui;
00428     delete m_sbPageLabel;
00429     delete m_sbFramesLabel;
00430     delete m_fsInline;
00431     delete m_dcop;
00432     delete m_fontDlg;
00433     delete m_paragDlg;
00434 }
00435 
00436 DCOPObject* KWView::dcopObject()
00437 {
00438     if ( !m_dcop )
00439         m_dcop = new KWordViewIface( this );
00440 
00441     return m_dcop;
00442 }
00443 
00444 void KWView::slotChangeCutState(bool b)
00445 {
00446     KWTextFrameSetEdit * edit = currentTextEdit();
00447     if ( edit && edit->textFrameSet()->protectContent())
00448         m_actionEditCut->setEnabled( false );
00449     else
00450         m_actionEditCut->setEnabled( b );
00451 }
00452 
00453 void KWView::slotChangeCaseState(bool b)
00454 {
00455     KWTextFrameSetEdit * edit = currentTextEdit();
00456     if ( edit && edit->textFrameSet()->protectContent())
00457         m_actionChangeCase->setEnabled( false );
00458     else
00459         m_actionChangeCase->setEnabled( b );
00460 }
00461 
00462 void KWView::slotSetInitialPosition()
00463 {
00464     KWTextFrameSetEdit* textedit = dynamic_cast<KWTextFrameSetEdit *>(m_gui->canvasWidget()->currentFrameSetEdit());
00465     if ( textedit )
00466         textedit->ensureCursorVisible();
00467     else
00468         m_gui->canvasWidget()->setContentsPos( 0, 0 );
00469 }
00470 
00471 void KWView::changeNbOfRecentFiles(int nb)
00472 {
00473     if ( shell() ) // 0 when embedded into konq !
00474         shell()->setMaxRecentItems( nb );
00475 }
00476 
00477 KWViewMode* KWView::viewMode() const
00478 {
00479     return m_gui->canvasWidget()->viewMode();
00480 }
00481 
00482 void KWView::initGui()
00483 {
00484     clipboardDataChanged();
00485     if ( m_gui )
00486         m_gui->showGUI();
00487     showMouseMode( KWCanvas::MM_EDIT );
00488     initGUIButton();
00489     m_actionFormatDecreaseIndent->setEnabled(false);
00490     //setNoteType(m_doc->getNoteType(), false);
00491 
00492     m_actionFormatColor->setCurrentColor( Qt::black );
00493 
00494     updateGridButton();
00495 
00496     //refresh zoom combobox
00497     updateZoomControls();
00498 
00499 
00500     // This is probably to emit currentMouseModeChanged and set the cursor
00501     m_gui->canvasWidget()->setMouseMode( m_gui->canvasWidget()->mouseMode() );
00502 
00503     bool editingFormula = dynamic_cast<KWFormulaFrameSetEdit *>( m_gui->canvasWidget()->currentFrameSetEdit() ) != 0;
00504     //showFormulaToolbar( FALSE ); // not called, to avoid creating the formula-document if not necessary
00505     if(shell())
00506         shell()->showToolbar( "formula_toolbar", editingFormula );
00507 
00508     if ( !editingFormula )
00509     {
00510        kWordDocument()->formulaDocumentWrapper()->setEnabled(false);
00511        kWordDocument()->formulaDocumentWrapper()->enableMatrixActions(false);
00512        kWordDocument()->formulaDocumentWrapper()->getSyntaxHighlightingAction()->setEnabled(false);
00513     }
00514 
00515     // Prevention against applyMainWindowSettings hiding the statusbar
00516     if ( KStatusBar* sb = statusBar() )
00517         sb->show();
00518 
00519     updatePageInfo();
00520     slotFrameSetEditChanged();
00521     frameSelectedChanged();
00522     updateTocActionText(m_doc->tocPresent());
00523     //at the beginning m_actionBackgroundColor should be active
00524     m_actionBackgroundColor->setEnabled(true);
00525     updateBgSpellCheckingState();
00526     updateDirectCursorButton();
00527     m_actionCreateFrameStyle->setEnabled(false);
00528 }
00529 
00530 
00531 void KWView::updateBgSpellCheckingState()
00532 {
00533     m_actionAllowBgSpellCheck->setChecked( m_doc->backgroundSpellCheckEnabled() );
00534 }
00535 
00536 
00537 void KWView::initGUIButton()
00538 {
00539     m_actionViewFrameBorders->setChecked( viewFrameBorders() );
00540     m_actionViewFormattingChars->setChecked( m_doc->viewFormattingChars() );
00541     m_actionShowDocStruct->setChecked(m_doc->showdocStruct());
00542     m_actionShowRuler->setChecked(m_doc->showRuler());
00543 
00544     updateHeaderFooterButton();
00545     m_actionAllowAutoFormat->setChecked( m_doc->allowAutoFormat() );
00546 
00547     if ( !m_doc->isEmbedded() ) {
00548         QString mode = viewMode()->type();
00549         if (mode=="ModePreview")
00550             m_actionViewPreviewMode->setChecked(true);
00551         else if (mode=="ModeText")
00552             m_actionViewTextMode->setChecked(true);
00553         else //if (mode=="ModeNormal")
00554             m_actionViewPageMode->setChecked(true);
00555         switchModeView();
00556     }
00557 }
00558 
00559 void KWView::setupActions()
00560 {
00561     // The actions here are grouped by menu, because this helps noticing
00562     // accelerator clashes.
00563 
00564     // -------------- File menu
00565     m_actionExtraCreateTemplate = new KAction( i18n( "&Create Template From Document..." ), 0,
00566                                              this, SLOT( extraCreateTemplate() ),
00567                                              actionCollection(), "extra_template" );
00568     m_actionExtraCreateTemplate->setToolTip( i18n( "Save this document and use it later as a template" ) );
00569     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." ) );
00570 
00571     m_actionFileStatistics = new KAction( i18n( "Statistics" ), 0, this, SLOT( fileStatistics() ), actionCollection(), "file_statistics" );
00572     m_actionFileStatistics->setToolTip( i18n( "Sentence, word and letter counts for this document" ) );
00573     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." ) );
00574     // -------------- Edit actions
00575     m_actionEditCut = KStdAction::cut( this, SLOT( editCut() ), actionCollection(), "edit_cut" );
00576     m_actionEditCopy = KStdAction::copy( this, SLOT( editCopy() ), actionCollection(), "edit_copy" );
00577     m_actionEditPaste = KStdAction::paste( this, SLOT( editPaste() ), actionCollection(), "edit_paste" );
00578     m_actionEditFind = KStdAction::find( this, SLOT( editFind() ), actionCollection(), "edit_find" );
00579     m_actionEditFindNext = KStdAction::findNext( this, SLOT( editFindNext() ), actionCollection(), "edit_findnext" );
00580     m_actionEditFindPrevious = KStdAction::findPrev( this, SLOT( editFindPrevious() ), actionCollection(), "edit_findprevious" );
00581     m_actionEditReplace = KStdAction::replace( this, SLOT( editReplace() ), actionCollection(), "edit_replace" );
00582     m_actionEditSelectAll = KStdAction::selectAll( this, SLOT( editSelectAll() ), actionCollection(), "edit_selectall" );
00583     new KAction( i18n( "Select All Frames" ), 0, this, SLOT( editSelectAllFrames() ), actionCollection(), "edit_selectallframes" );
00584     m_actionEditSelectCurrentFrame = new KAction( i18n( "Select Frame" ), 0,
00585         0, this, SLOT( editSelectCurrentFrame() ),
00586         actionCollection(), "edit_selectcurrentframe" );
00587     m_actionSpellCheck = KStdAction::spelling( this, SLOT( slotSpellCheck() ), actionCollection(), "extra_spellcheck" );
00588     m_actionDeletePage = new KAction( i18n( "Delete Page" ), "delslide", 0,
00589                                     this, SLOT( deletePage() ),
00590                                     actionCollection(), "delete_page" );
00591     kdDebug() <<  m_doc->pageCount() <<  " " << (m_doc->processingType() == KWDocument::DTP) << endl;
00592 
00593     (void) new KAction( i18n( "Configure Mai&l Merge..." ), "configure",0,
00594                         this, SLOT( editMailMergeDataBase() ),
00595                         actionCollection(), "edit_sldatabase" );
00596 
00597 
00598     (void) new KWMailMergeLabelAction::KWMailMergeLabelAction( i18n("Drag Mail Merge Variable"), 0,
00599                     this, SLOT(editMailMergeDataBase()), actionCollection(), "mailmerge_draglabel" );
00600 
00601 //    (void) new KWMailMergeComboAction::KWMailMergeComboAction(i18n("Insert Mailmerge Var"),0,this,SLOT(JWJWJW()),actionCollection(),"mailmerge_varchooser");
00602 
00603     // -------------- Frame menu
00604     m_actionEditDelFrame = new KAction( i18n( "&Delete Frame" ), 0,
00605                                       this, SLOT( editDeleteFrame() ),
00606                                       actionCollection(), "edit_delframe" );
00607     m_actionEditDelFrame->setToolTip( i18n( "Delete the currently selected frame(s)." ) );
00608     m_actionEditDelFrame->setWhatsThis( i18n( "Delete the currently selected frame(s)." ) );
00609 
00610     m_actionCreateLinkedFrame = new KAction( i18n( "Create Linked Copy" ), 0, this, SLOT( createLinkedFrame() ), actionCollection(), "create_linked_frame" );
00611     m_actionCreateLinkedFrame->setToolTip( i18n( "Create a copy of the current frame, always showing the same contents" ) );
00612     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.") );
00613 
00614     m_actionRaiseFrame = new KAction( i18n( "Ra&ise Frame" ), "raise",
00615                                     Qt::CTRL +Qt::SHIFT+ Qt::Key_R, this, SLOT( raiseFrame() ),
00616                                     actionCollection(), "raiseframe" );
00617     m_actionRaiseFrame->setToolTip( i18n( "Raise the currently selected frame so that it appears above all the other frames" ) );
00618     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." ) );
00619 
00620     m_actionLowerFrame = new KAction( i18n( "&Lower Frame" ), "lower",
00621                                     Qt::CTRL +Qt::SHIFT+ Qt::Key_L, this, SLOT( lowerFrame() ),
00622                                     actionCollection(), "lowerframe" );
00623     m_actionLowerFrame->setToolTip( i18n( "Lower the currently selected frame so that it disappears under any frame that overlaps it" ) );
00624     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." ) );
00625 
00626     m_actionBringToFront= new KAction( i18n( "Bring to Front" ), "bring_forward",
00627                                           0, this, SLOT( bringToFront() ),
00628                                           actionCollection(), "bring_tofront_frame" );
00629 
00630     m_actionSendBackward= new KAction( i18n( "Send to Back" ), "send_backward",
00631                                           0, this, SLOT( sendToBack() ),
00632                                           actionCollection(), "send_toback_frame" );
00633 
00634 
00635     // -------------- View menu
00636 
00637     if ( !m_doc->isEmbedded() ) {
00638 
00639         m_actionViewTextMode = new KToggleAction( i18n( "Text Mode" ), 0,
00640                                                   this, SLOT( viewTextMode() ),
00641                                                   actionCollection(), "view_textmode" );
00642         m_actionViewTextMode->setToolTip( i18n( "Only show the text of the document." ) );
00643         m_actionViewTextMode->setWhatsThis( i18n( "Do not show any pictures, formatting or layout. KWord will display only the text for editing." ) );
00644 
00645         m_actionViewTextMode->setExclusiveGroup( "viewmodes" );
00646         m_actionViewPageMode = new KToggleAction( i18n( "&Page Mode" ), 0,
00647                                                   this, SLOT( viewPageMode() ),
00648                                                   actionCollection(), "view_pagemode" );
00649         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." ) );
00650         m_actionViewPageMode->setToolTip( i18n( "Switch to page editing mode." ) );
00651 
00652         m_actionViewPageMode->setExclusiveGroup( "viewmodes" );
00653         m_actionViewPageMode->setChecked( true );
00654         m_actionViewPreviewMode = new KToggleAction( i18n( "Pre&view Mode" ), 0,
00655                                                      this, SLOT( viewPreviewMode() ),
00656                                                      actionCollection(), "view_previewmode" );
00657         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." ) );
00658         m_actionViewPreviewMode->setToolTip( i18n( "Zoom out to a multiple page view." ) );
00659 
00660         m_actionViewPreviewMode->setExclusiveGroup( "viewmodes" );
00661     }
00662     else // no viewmode switching when embedded; at least "Page" makes no sense
00663     {
00664         m_actionViewTextMode = 0;
00665         m_actionViewPageMode = 0;
00666         m_actionViewPreviewMode = 0;
00667     }
00668 
00669     m_actionViewFormattingChars = new KToggleAction( i18n( "&Formatting Characters" ), 0,
00670                                                    this, SLOT( slotViewFormattingChars() ),
00671                                                    actionCollection(), "view_formattingchars" );
00672     m_actionViewFormattingChars->setToolTip( i18n( "Toggle the display of non-printing characters." ) );
00673     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." ) );
00674 
00675     m_actionViewFrameBorders = new KToggleAction( i18n( "Frame &Borders" ), 0,
00676                                                    this, SLOT( slotViewFrameBorders() ),
00677                                                    actionCollection(), "view_frameborders" );
00678     m_actionViewFrameBorders->setToolTip( i18n( "Turns the border display on and off." ) );
00679     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." ) );
00680 
00681     m_actionViewHeader = new KToggleAction( i18n( "Enable Document &Headers" ), 0,
00682                                           this, SLOT( viewHeader() ),
00683                                           actionCollection(), "format_header" );
00684     m_actionViewHeader->setCheckedState(i18n("Disable Document &Headers"));
00685     m_actionViewHeader->setToolTip( i18n( "Shows and hides header display." ) );
00686     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." ) );
00687 
00688     m_actionViewFooter = new KToggleAction( i18n( "Enable Document Foo&ters" ), 0,
00689                                           this, SLOT( viewFooter() ),
00690                                           actionCollection(), "format_footer" );
00691     m_actionViewFooter->setCheckedState(i18n("Disable Document Foo&ters"));
00692     m_actionViewFooter->setToolTip( i18n( "Shows and hides footer display." ) );
00693     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." ) );
00694 
00695     m_actionViewZoom = new KSelectAction( i18n( "Zoom" ), "viewmag", 0,
00696                                         actionCollection(), "view_zoom" );
00697 
00698     connect( m_actionViewZoom, SIGNAL( activated( const QString & ) ),
00699              this, SLOT( viewZoom( const QString & ) ) );
00700     m_actionViewZoom->setEditable(true);
00701     changeZoomMenu( );
00702 
00703     // -------------- Insert menu
00704     m_actionInsertSpecialChar = new KAction( i18n( "Sp&ecial Character..." ), "char",
00705                         Qt::ALT + Qt::SHIFT + Qt::Key_C,
00706                         this, SLOT( insertSpecialChar() ),
00707                         actionCollection(), "insert_specialchar" );
00708     m_actionInsertSpecialChar->setToolTip( i18n( "Insert one or more symbols or letters not found on the keyboard." ) );
00709     m_actionInsertSpecialChar->setWhatsThis( i18n( "Insert one or more symbols or letters not found on the keyboard." ) );
00710 
00711     m_actionInsertFrameBreak = new KAction( QString::null, Qt::CTRL + Qt::Key_Return,
00712                                           this, SLOT( insertFrameBreak() ),
00713                                           actionCollection(), "insert_framebreak" );
00714     if ( m_doc->processingType() == KWDocument::WP ) {
00715         m_actionInsertFrameBreak->setText( i18n( "Page Break" ) );
00716         m_actionInsertFrameBreak->setToolTip( i18n( "Force the remainder of the text into the next page." ) );
00717         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." ) );
00718     } else {
00719         m_actionInsertFrameBreak->setText( i18n( "&Hard Frame Break" ) );
00720         m_actionInsertFrameBreak->setToolTip( i18n( "Force the remainder of the text into the next frame." ) );
00721         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." ) );
00722     }
00723 
00724     /*actionInsertPage =*/ new KAction( m_doc->processingType() == KWDocument::WP ? i18n( "Page" ) : i18n( "Page..." ), "page", 0,
00725                                     this, SLOT( insertPage() ),
00726                                     actionCollection(), "insert_page" );
00727 
00728     m_actionInsertLink = new KAction( i18n( "Link..." ), 0,
00729                                     this, SLOT( insertLink() ),
00730                                     actionCollection(), "insert_link" );
00731     m_actionInsertLink->setToolTip( i18n( "Insert a Web address, email address or hyperlink to a file." ) );
00732     m_actionInsertLink->setWhatsThis( i18n( "Insert a Web address, email address or hyperlink to a file." ) );
00733 
00734     m_actionInsertComment = new KAction( i18n( "Comment..." ), 0,
00735                                     this, SLOT( insertComment() ),
00736                                     actionCollection(), "insert_comment" );
00737     m_actionInsertComment->setToolTip( i18n( "Insert a comment about the selected text." ) );
00738     m_actionInsertComment->setWhatsThis( i18n( "Insert a comment about the selected text. These comments are not designed to appear on the final page." ) );
00739 
00740     m_actionEditComment = new KAction( i18n("Edit Comment..."), 0,
00741                                   this,SLOT(editComment()),
00742                                   actionCollection(), "edit_comment");
00743     m_actionEditComment->setToolTip( i18n( "Change the content of a comment." ) );
00744     m_actionEditComment->setWhatsThis( i18n( "Change the content of a comment." ) );
00745 
00746     m_actionRemoveComment = new KAction( i18n("Remove Comment"), 0,
00747                                      this,SLOT(removeComment()),
00748                                      actionCollection(), "remove_comment");
00749     m_actionRemoveComment->setToolTip( i18n( "Remove the selected document comment." ) );
00750     m_actionRemoveComment->setWhatsThis( i18n( "Remove the selected document comment." ) );
00751     m_actionCopyTextOfComment = new KAction( i18n("Copy Text of Comment..."), 0,
00752                                   this,SLOT(copyTextOfComment()),
00753                                   actionCollection(), "copy_text_comment");
00754 
00755 
00756     m_actionInsertFootEndNote = new KAction( i18n( "&Footnote/Endnote..." ), 0,
00757                                            this, SLOT( insertFootNote() ),
00758                                            actionCollection(), "insert_footendnote" );
00759     m_actionInsertFootEndNote->setToolTip( i18n( "Insert a footnote referencing the selected text." ) );
00760     m_actionInsertFootEndNote->setWhatsThis( i18n( "Insert a footnote referencing the selected text." ) );
00761 
00762     m_actionInsertContents = new KAction( i18n( "Table of &Contents" ), 0,
00763                                         this, SLOT( insertContents() ),
00764                                         actionCollection(), "insert_contents" );
00765     m_actionInsertContents->setToolTip( i18n( "Insert table of contents at the current cursor position." ) );
00766     m_actionInsertContents->setWhatsThis( i18n( "Insert table of contents at the current cursor position." ) );
00767 
00768     m_variableDefMap.clear();
00769     actionInsertVariable = new KActionMenu( i18n( "&Variable" ),
00770                                             actionCollection(), "insert_variable" );
00771 
00772     // The last argument is only needed if a submenu is to be created
00773     addVariableActions( VT_FIELD, KoFieldVariable::actionTexts(), actionInsertVariable, i18n("Document &Information") );
00774     addVariableActions( VT_DATE, KoDateVariable::actionTexts(), actionInsertVariable, i18n("&Date") );
00775     addVariableActions( VT_TIME, KoTimeVariable::actionTexts(), actionInsertVariable, i18n("&Time") );
00776     addVariableActions( VT_PGNUM, KoPageVariable::actionTexts(), actionInsertVariable, i18n("&Page") );
00777     addVariableActions( VT_STATISTIC, KWStatisticVariable::actionTexts(), actionInsertVariable, i18n("&Statistic") );
00778 
00779     m_actionInsertCustom = new KActionMenu( i18n( "&Custom" ),
00780                                             actionCollection(), "insert_custom" );
00781     actionInsertVariable->insert(m_actionInsertCustom);
00782 
00783     //addVariableActions( VT_CUSTOM, KWCustomVariable::actionTexts(), actionInsertVariable, QString::null );
00784 
00785     addVariableActions( VT_MAILMERGE, KoMailMergeVariable::actionTexts(), actionInsertVariable, QString::null );
00786 
00787     actionInsertVariable->popupMenu()->insertSeparator();
00788     m_actionRefreshAllVariable = new KAction( i18n( "&Refresh All Variables" ), 0,
00789                                     this, SLOT( refreshAllVariable() ),
00790                                     actionCollection(), "refresh_all_variable" );
00791     m_actionRefreshAllVariable->setToolTip( i18n( "Update all variables to current values." ) );
00792     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." ) );
00793 
00794     actionInsertVariable->insert(m_actionRefreshAllVariable);
00795 
00796     m_actionInsertExpression = new KActionMenu( i18n( "&Expression" ),
00797                                             actionCollection(), "insert_expression" );
00798     loadexpressionActions( m_actionInsertExpression);
00799 
00800     m_actionToolsCreateText = new KToggleAction( i18n( "Te&xt Frame" ), "frame_text", Qt::Key_F10 /*same as kpr*/,
00801                                                this, SLOT( toolsCreateText() ),
00802                                                actionCollection(), "tools_createtext" );
00803     m_actionToolsCreateText->setToolTip( i18n( "Create a new text frame." ) );
00804     m_actionToolsCreateText->setWhatsThis( i18n( "Create a new text frame." ) );
00805 
00806     m_actionToolsCreateText->setExclusiveGroup( "tools" );
00807     m_actionInsertFormula = new KAction( i18n( "For&mula" ), "frame_formula", Qt::Key_F4,
00808                                        this, SLOT( insertFormula() ),
00809                                        actionCollection(), "tools_formula" );
00810     m_actionInsertFormula->setToolTip( i18n( "Insert a formula into a new frame." ) );
00811     m_actionInsertFormula->setWhatsThis( i18n( "Insert a formula into a new frame." ) );
00812 
00813     m_actionInsertTable = new KAction( i18n( "&Table..." ), "inline_table",
00814                         Qt::Key_F5,
00815                         this, SLOT( insertTable() ),
00816                         actionCollection(), "insert_table" );
00817     m_actionInsertTable->setToolTip( i18n( "Create a table." ) );
00818     m_actionInsertTable->setWhatsThis( i18n( "Create a table.<br><br>The table can either exist in a frame of its own or inline." ) );
00819 
00820     m_actionToolsCreatePix = new KToggleAction( i18n( "P&icture..." ), "frame_image", // or inline_image ?
00821                                               Qt::SHIFT + Qt::Key_F5 /*same as kpr*/,
00822                                               this, SLOT( insertPicture() ),
00823                                               actionCollection(), "insert_picture" );
00824     m_actionToolsCreatePix->setToolTip( i18n( "Create a new frame for a picture." ) );
00825     m_actionToolsCreatePix->setWhatsThis( i18n( "Create a new frame for a picture or diagram." ) );
00826     m_actionToolsCreatePix->setExclusiveGroup( "tools" );
00827 
00828     m_actionToolsCreatePart = new KoPartSelectAction( i18n( "&Object Frame" ), "frame_query",
00829                                                     this, SLOT( toolsPart() ),
00830                                                     actionCollection(), "tools_part" );
00831     m_actionToolsCreatePart->setToolTip( i18n( "Insert an object into a new frame." ) );
00832     m_actionToolsCreatePart->setWhatsThis( i18n( "Insert an object into a new frame." ) );
00833 
00834     m_actionInsertFile = new KAction( i18n( "Fi&le..." ), 0,
00835                                    this, SLOT( insertFile() ),
00836                                    actionCollection(), "insert_file" );
00837 
00838 
00839     // ------------------------- Format menu
00840     m_actionFormatFont = new KAction( i18n( "&Font..." ), Qt::ALT + Qt::CTRL + Qt::Key_F,
00841                                     this, SLOT( formatFont() ),
00842                                     actionCollection(), "format_font" );
00843     m_actionFormatFont->setToolTip( i18n( "Change character size, font, boldface, italics etc." ) );
00844     m_actionFormatFont->setWhatsThis( i18n( "Change the attributes of the currently selected characters." ) );
00845 
00846     m_actionFormatParag = new KAction( i18n( "&Paragraph..." ), Qt::ALT + Qt::CTRL + Qt::Key_P,
00847                                      this, SLOT( formatParagraph() ),
00848                                      actionCollection(), "format_paragraph" );
00849     m_actionFormatParag->setToolTip( i18n( "Change paragraph margins, text flow, borders, bullets, numbering etc." ) );
00850     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." ) );
00851 
00852     m_actionFormatFrameSet = new KAction( i18n( "F&rame/Frameset Properties" ), 0,
00853                                      this, SLOT( formatFrameSet() ),
00854                                      actionCollection(), "format_frameset" );
00855     m_actionFormatFrameSet->setToolTip( i18n( "Alter frameset properties." ) );
00856     m_actionFormatFrameSet->setWhatsThis( i18n( "Alter frameset properties.<p>Currently you can change the frame background." ) );
00857 
00858     m_actionFormatPage = new KAction( i18n( "Page &Layout..." ), 0,
00859                         this, SLOT( formatPage() ),
00860                         actionCollection(), "format_page" );
00861     m_actionFormatPage->setToolTip( i18n( "Change properties of entire page." ) );
00862     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." ) );
00863 
00864 
00865     m_actionFormatFrameStylist = new KAction( i18n( "&Frame Style Manager" ), 0 /*shortcut?*/,
00866                                 this, SLOT( extraFrameStylist() ),
00867                                 actionCollection(), "frame_stylist" );
00868     m_actionFormatFrameStylist->setToolTip( i18n( "Change attributes of framestyles." ) );
00869     m_actionFormatFrameStylist->setWhatsThis( i18n( "Change background and borders of framestyles.<p>Multiple framestyles can be changed using the dialog box." ) );
00870 
00871 
00872     m_actionFormatStylist = new KAction( i18n( "&Style Manager" ), Qt::ALT + Qt::CTRL + Qt::Key_S,
00873                         this, SLOT( extraStylist() ),
00874                         actionCollection(), "format_stylist" );
00875     m_actionFormatStylist->setToolTip( i18n( "Change attributes of styles." ) );
00876     m_actionFormatStylist->setWhatsThis( i18n( "Change font and paragraph attributes of styles.<p>Multiple styles can be changed using the dialog box." ) );
00877 
00878     m_actionFormatFontSize = new KFontSizeAction( i18n( "Font Size" ), 0,
00879                                               actionCollection(), "format_fontsize" );
00880     connect( m_actionFormatFontSize, SIGNAL( fontSizeChanged( int ) ),
00881              this, SLOT( textSizeSelected( int ) ) );
00882 
00883     m_actionFontSizeIncrease = new KAction( i18n("Increase Font Size"), "fontsizeup", Qt::CTRL + Qt::Key_Greater, this, SLOT( increaseFontSize() ), actionCollection(), "increase_fontsize" );
00884     m_actionFontSizeDecrease = new KAction( i18n("Decrease Font Size"), "fontsizedown", Qt::CTRL + Qt::Key_Less, this, SLOT( decreaseFontSize() ), actionCollection(), "decrease_fontsize" );
00885 
00886 #ifdef KFONTACTION_HAS_CRITERIA_ARG
00887     m_actionFormatFontFamily = new KFontAction( KFontChooser::SmoothScalableFonts,
00888                                               i18n( "Font Family" ), 0,
00889                                               actionCollection(), "format_fontfamily" );
00890 #else
00891     m_actionFormatFontFamily = new KFontAction( i18n( "Font Family" ), 0,
00892                                               actionCollection(), "format_fontfamily" );
00893 #endif
00894     connect( m_actionFormatFontFamily, SIGNAL( activated( const QString & ) ),
00895              this, SLOT( textFontSelected( const QString & ) ) );
00896 
00897     m_actionFormatStyleMenu = new KActionMenu( i18n( "St&yle" ), 0,
00898                                            actionCollection(), "format_stylemenu" );
00899     m_actionFormatStyle = new KSelectAction( i18n( "St&yle" ), 0,
00900                                            actionCollection(), "format_style" );
00901     // In fact, binding a key to this action will simply re-apply the current style. Why not.
00902     //m_actionFormatStyle->setShortcutConfigurable( false );
00903     connect( m_actionFormatStyle, SIGNAL( activated( int ) ),
00904              this, SLOT( textStyleSelected( int ) ) );
00905     updateStyleList();
00906 
00907     m_actionFormatDefault=new KAction( i18n( "Default Format" ), 0,
00908                                           this, SLOT( textDefaultFormat() ),
00909                                           actionCollection(), "text_default" );
00910     m_actionFormatDefault->setToolTip( i18n( "Change font and paragraph attributes to their default values." ) );
00911     m_actionFormatDefault->setWhatsThis( i18n( "Change font and paragraph attributes to their default values." ) );
00912 
00913     // ----------------------- More format actions, for the toolbar only
00914 
00915     m_actionFormatBold = new KToggleAction( i18n( "&Bold" ), "text_bold", Qt::CTRL + Qt::Key_B,
00916                                            this, SLOT( textBold() ),
00917                                            actionCollection(), "format_bold" );
00918     m_actionFormatItalic = new KToggleAction( i18n( "&Italic" ), "text_italic", Qt::CTRL + Qt::Key_I,
00919                                            this, SLOT( textItalic() ),
00920                                            actionCollection(), "format_italic" );
00921     m_actionFormatUnderline = new KToggleAction( i18n( "&Underline" ), "text_under", Qt::CTRL + Qt::Key_U,
00922                                            this, SLOT( textUnderline() ),
00923                                            actionCollection(), "format_underline" );
00924     m_actionFormatStrikeOut = new KToggleAction( i18n( "&Strike Out" ), "text_strike", 0 ,
00925                                            this, SLOT( textStrikeOut() ),
00926                                            actionCollection(), "format_strike" );
00927 
00928     m_actionFormatAlignLeft = new KToggleAction( i18n( "Align &Left" ), "text_left", Qt::CTRL + Qt::Key_L,
00929                                        this, SLOT( textAlignLeft() ),
00930                                        actionCollection(), "format_alignleft" );
00931     m_actionFormatAlignLeft->setExclusiveGroup( "align" );
00932     m_actionFormatAlignLeft->setChecked( TRUE );
00933     m_actionFormatAlignCenter = new KToggleAction( i18n( "Align &Center" ), "text_center", Qt::CTRL + Qt::ALT + Qt::Key_C,
00934                                          this, SLOT( textAlignCenter() ),
00935                                          actionCollection(), "format_aligncenter" );
00936     m_actionFormatAlignCenter->setExclusiveGroup( "align" );
00937     m_actionFormatAlignRight = new KToggleAction( i18n( "Align &Right" ), "text_right", Qt::CTRL + Qt::ALT + Qt::Key_R,
00938                                         this, SLOT( textAlignRight() ),
00939                                         actionCollection(), "format_alignright" );
00940     m_actionFormatAlignRight->setExclusiveGroup( "align" );
00941     m_actionFormatAlignBlock = new KToggleAction( i18n( "Align &Block" ), "text_block", Qt::CTRL + Qt::Key_J,
00942                                         this, SLOT( textAlignBlock() ),
00943                                         actionCollection(), "format_alignblock" );
00944     m_actionFormatAlignBlock->setExclusiveGroup( "align" );
00945 
00946     m_actionFormatSpacingSingle = new KToggleAction( i18n( "Line Spacing &1" ), "spacesimple", Qt::CTRL + Qt::Key_1,
00947                                            this, SLOT( textSpacingSingle() ),
00948                                            actionCollection(), "format_spacingsingle" );
00949     m_actionFormatSpacingSingle->setExclusiveGroup( "spacing" );
00950     m_actionFormatSpacingOneAndHalf = new KToggleAction( i18n( "Line Spacing 1.&5" ), "spacedouble", Qt::CTRL + Qt::Key_5,
00951                                        this, SLOT( textSpacingOneAndHalf() ),
00952                                        actionCollection(), "format_spacing15" );
00953     m_actionFormatSpacingOneAndHalf->setExclusiveGroup( "spacing" );
00954     m_actionFormatSpacingDouble = new KToggleAction( i18n( "Line Spacing &2" ), "spacetriple", Qt::CTRL + Qt::Key_2,
00955                                            this, SLOT( textSpacingDouble() ),
00956                                            actionCollection(), "format_spacingdouble" );
00957     m_actionFormatSpacingDouble->setExclusiveGroup( "spacing" );
00958 
00959     m_actionFormatSuper = new KToggleAction( i18n( "Superscript" ), "super", 0,
00960                                               this, SLOT( textSuperScript() ),
00961                                               actionCollection(), "format_super" );
00962     //m_actionFormatSuper->setExclusiveGroup( "valign" );
00963     m_actionFormatSub = new KToggleAction( i18n( "Subscript" ), "sub", 0,
00964                                               this, SLOT( textSubScript() ),
00965                                               actionCollection(), "format_sub" );
00966     //m_actionFormatSub->setExclusiveGroup( "valign" );
00967 
00968     m_actionFormatIncreaseIndent= new KAction( i18n( "Increase Indent" ),
00969             QApplication::reverseLayout() ? "format_decreaseindent" : "format_increaseindent", 0,
00970                                              this, SLOT( textIncreaseIndent() ),
00971                                              actionCollection(), "format_increaseindent" );
00972 
00973     m_actionFormatDecreaseIndent= new KAction( i18n( "Decrease Indent" ),
00974                                              QApplication::reverseLayout() ? "format_increaseindent" :"format_decreaseindent", 0,
00975                                              this, SLOT( textDecreaseIndent() ),
00976                                              actionCollection(), "format_decreaseindent" );
00977 
00978     m_actionFormatColor = new TKSelectColorAction( i18n( "Text Color..." ), TKSelectColorAction::TextColor,
00979                                      this, SLOT( textColor() ),
00980                                      actionCollection(), "format_color", true );
00981     m_actionFormatColor->setDefaultColor(QColor());
00982 
00983 
00984     //actionFormatList = new KToggleAction( i18n( "List" ), "enumList", 0,
00985     //                                          this, SLOT( textList() ),
00986     //                                          actionCollection(), "format_list" );
00987     //actionFormatList->setExclusiveGroup( "style" );
00988 
00989     m_actionFormatNumber = new KActionMenu( i18n( "Number" ),
00990                                           "enumList", actionCollection(), "format_number" );
00991     m_actionFormatNumber->setDelayed( false );
00992     m_actionFormatBullet = new KActionMenu( i18n( "Bullet" ),
00993                                           "unsortedList", actionCollection(), "format_bullet" );
00994     m_actionFormatBullet->setDelayed( false );
00995     QPtrList<KoCounterStyleWidget::StyleRepresenter> stylesList;
00996     KoCounterStyleWidget::makeCounterRepresenterList( stylesList );
00997     QPtrListIterator<KoCounterStyleWidget::StyleRepresenter> styleIt( stylesList );
00998     for ( ; styleIt.current() ; ++styleIt ) {
00999         // Dynamically create toggle-actions for each list style.
01000         // This approach allows to edit toolbars and extract separate actions from this menu
01001         KToggleAction* act = new KToggleAction( styleIt.current()->name(), /*TODO icon,*/
01002                                                 0, this, SLOT( slotCounterStyleSelected() ),
01003                                                 actionCollection(), QString("counterstyle_%1").arg( styleIt.current()->style() ).latin1() );
01004         act->setExclusiveGroup( "counterstyle" );
01005         // Add to the right menu: both for "none", bullet for bullets, numbers otherwise
01006         if ( styleIt.current()->style() == KoParagCounter::STYLE_NONE ) {
01007             m_actionFormatBullet->insert( act );
01008             m_actionFormatNumber->insert( act );
01009         } else if ( styleIt.current()->isBullet() )
01010             m_actionFormatBullet->insert( act );
01011         else
01012             m_actionFormatNumber->insert( act );
01013     }
01014 
01015     // ---------------------------- frame toolbar actions
01016 
01017     m_actionFrameStyleMenu = new KActionMenu( i18n( "Fra&mestyle" ), 0,
01018                                            actionCollection(), "frame_stylemenu" );
01019     m_actionFrameStyle = new KSelectAction( i18n( "Framest&yle" ), 0,
01020                                            actionCollection(), "frame_style" );
01021     connect( m_actionFrameStyle, SIGNAL( activated( int ) ),
01022              this, SLOT( frameStyleSelected( int ) ) );
01023     updateFrameStyleList();
01024     m_actionBorderOutline = new KToggleAction( i18n( "Border Outline" ), "borderoutline",
01025                             0, this, SLOT( borderOutline() ), actionCollection(), "border_outline" );
01026     m_actionBorderLeft = new KToggleAction( i18n( "Border Left" ), "borderleft",
01027                             0, this, SLOT( borderLeft() ), actionCollection(), "border_left" );
01028     m_actionBorderRight = new KToggleAction( i18n( "Border Right" ), "borderright",
01029                             0, this, SLOT( borderRight() ), actionCollection(), "border_right" );
01030     m_actionBorderTop = new KToggleAction( i18n( "Border Top" ), "bordertop",
01031                             0, this, SLOT( borderTop() ), actionCollection(), "border_top" );
01032     m_actionBorderBottom = new KToggleAction( i18n( "Border Bottom" ), "borderbottom",
01033                             0, this, SLOT( borderBottom() ),  actionCollection(), "border_bottom" );
01034     m_actionBorderStyle = new KSelectAction( i18n( "Border Style" ),
01035                             0,  actionCollection(), "border_style" );
01036 
01037     QStringList lst;
01038     lst << KoBorder::getStyle( KoBorder::SOLID );
01039     lst << KoBorder::getStyle( KoBorder::DASH );
01040     lst << KoBorder::getStyle( KoBorder::DOT );
01041     lst << KoBorder::getStyle( KoBorder::DASH_DOT );
01042     lst << KoBorder::getStyle( KoBorder::DASH_DOT_DOT );
01043     lst << KoBorder::getStyle( KoBorder::DOUBLE_LINE );
01044     m_actionBorderStyle->setItems( lst );
01045     m_actionBorderWidth = new KSelectAction( i18n( "Border Width" ), 0,
01046                                                  actionCollection(), "border_width" );
01047     lst.clear();
01048     for ( unsigned int i = 1; i < 10; i++ )
01049         lst << QString::number( i );
01050     m_actionBorderWidth->setItems( lst );
01051     m_actionBorderWidth->setCurrentItem( 0 );
01052 
01053     m_actionBorderColor = new TKSelectColorAction( i18n("Border Color"), TKSelectColorAction::LineColor, actionCollection(), "border_color", true );
01054     m_actionBorderColor->setDefaultColor(QColor());
01055 
01056 
01057     m_actionBackgroundColor = new TKSelectColorAction( i18n( "Text Background Color..." ), TKSelectColorAction::FillColor, actionCollection(),"border_backgroundcolor", true);
01058     m_actionBackgroundColor->setToolTip( i18n( "Change background color for currently selected text." ) );
01059     m_actionBackgroundColor->setWhatsThis( i18n( "Change background color for currently selected text." ) );
01060 
01061     connect(m_actionBackgroundColor,SIGNAL(activated()),SLOT(backgroundColor() ));
01062     m_actionBackgroundColor->setDefaultColor(QColor());
01063 
01064     // ---------------------- Table menu
01065     m_actionTablePropertiesMenu = new KAction( i18n( "&Properties" ), 0,
01066                                this, SLOT( tableProperties() ),
01067                                actionCollection(), "table_propertiesmenu" );
01068     m_actionTablePropertiesMenu->setToolTip( i18n( "Adjust properties of the current table." ) );
01069     m_actionTablePropertiesMenu->setWhatsThis( i18n( "Adjust properties of the current table." ) );
01070 
01071     m_actionTableInsertRow = new KAction( i18n( "&Insert Row..." ), "insert_table_row", 0,
01072                                this, SLOT( tableInsertRow() ),
01073                                actionCollection(), "table_insrow" );
01074     m_actionTableInsertRow->setToolTip( i18n( "Insert one or more rows at cursor location." ) );
01075     m_actionTableInsertRow->setWhatsThis( i18n( "Insert one or more rows at current cursor location." ) );
01076 
01077     m_actionTableInsertCol = new KAction( i18n( "I&nsert Column..." ), "insert_table_col", 0,
01078                                this, SLOT( tableInsertCol() ),
01079                                actionCollection(), "table_inscol" );
01080     m_actionTableInsertCol->setToolTip( i18n( "Insert one or more columns into the current table." ) );
01081     m_actionTableInsertCol->setWhatsThis( i18n( "Insert one or more columns into the current table." ) );
01082 
01083     m_actionTableDelRow = new KAction( 0, "delete_table_row", 0,
01084                                      this, SLOT( tableDeleteRow() ),
01085                                      actionCollection(), "table_delrow" );
01086     m_actionTableDelRow->setToolTip( i18n( "Delete selected rows from the current table." ) );
01087     m_actionTableDelRow->setWhatsThis( i18n( "Delete selected rows from the current table." ) );
01088 
01089     m_actionTableDelCol = new KAction( 0, "delete_table_col", 0,
01090                                      this, SLOT( tableDeleteCol() ),
01091                                      actionCollection(), "table_delcol" );
01092     m_actionTableDelCol->setToolTip( i18n( "Delete selected columns from the current table." ) );
01093     m_actionTableDelCol->setWhatsThis( i18n( "Delete selected columns from the current table." ) );
01094 
01095     m_actionTableResizeCol = new KAction( i18n( "Resize Column..." ), 0,
01096                                this, SLOT( tableResizeCol() ),
01097                                actionCollection(), "table_resizecol" );
01098     m_actionTableResizeCol->setToolTip( i18n( "Change the width of the currently selected column." ) );
01099     m_actionTableResizeCol->setWhatsThis( i18n( "Change the width of the currently selected column." ) );
01100 
01101 
01102     m_actionTableJoinCells = new KAction( i18n( "&Join Cells" ), 0,
01103                                         this, SLOT( tableJoinCells() ),
01104                                         actionCollection(), "table_joincells" );
01105     m_actionTableJoinCells->setToolTip( i18n( "Join two or more cells into one large cell." ) );
01106     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." ) );
01107 
01108     m_actionTableSplitCells= new KAction( i18n( "&Split Cell..." ), 0,
01109                                          this, SLOT( tableSplitCells() ),
01110                                          actionCollection(), "table_splitcells" );
01111     m_actionTableSplitCells->setToolTip( i18n( "Split one cell into two or more cells." ) );
01112     m_actionTableSplitCells->setWhatsThis( i18n( "Split one cell into two or more cells.<p>Cells can be split horizontally, vertically or both directions at once." ) );
01113 
01114     m_actionTableProtectCells= new KToggleAction( i18n( "Protect Cells" ), 0, 0, 0,
01115                                          actionCollection(), "table_protectcells" );
01116     m_actionTableProtectCells->setToolTip( i18n( "Prevent changes to content of selected cells." ) );
01117     connect (m_actionTableProtectCells, SIGNAL( toggled(bool) ), this,
01118             SLOT( tableProtectCells(bool) ));
01119 
01120     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." ) );
01121 
01122     m_actionTableUngroup = new KAction( i18n( "&Ungroup Table" ), 0,
01123                                       this, SLOT( tableUngroupTable() ),
01124                                       actionCollection(), "table_ungroup" );
01125     m_actionTableUngroup->setToolTip( i18n( "Break a table into individual frames." ) );
01126     m_actionTableUngroup->setWhatsThis( i18n( "Break a table into individual frames<p>Each frame can be moved independently around the page." ) );
01127 
01128     m_actionTableDelete = new KAction( i18n( "Delete &Table" ), 0,
01129                                      this, SLOT( tableDelete() ),
01130                                      actionCollection(), "table_delete" );
01131     m_actionTableDelete->setToolTip( i18n( "Delete the entire table." ) );
01132     m_actionTableDelete->setWhatsThis( i18n( "Deletes all cells and the content within the cells of the currently selected table." ) );
01133 
01134 
01135     m_actionTableStylist = new KAction( i18n( "T&able Style Manager" ), 0,
01136                         this, SLOT( tableStylist() ),
01137                         actionCollection(), "table_stylist" );
01138     m_actionTableStylist->setToolTip( i18n( "Change attributes of tablestyles." ) );
01139     m_actionTableStylist->setWhatsThis( i18n( "Change textstyle and framestyle of the tablestyles.<p>Multiple tablestyles can be changed using the dialog box." ) );
01140 
01141     m_actionTableStyleMenu = new KActionMenu( i18n( "Table&style" ), 0,
01142                                            actionCollection(), "table_stylemenu" );
01143     m_actionTableStyle = new KSelectAction( i18n( "Table&style" ), 0,
01144                                            actionCollection(), "table_style" );
01145     connect( m_actionTableStyle, SIGNAL( activated( int ) ),
01146              this, SLOT( tableStyleSelected( int ) ) );
01147     updateTableStyleList();
01148 
01149     m_actionConvertTableToText = new KAction( i18n( "Convert Table to Text" ), 0,
01150                                             this, SLOT( convertTableToText() ),
01151                                             actionCollection(), "convert_table_to_text" );
01152     m_actionSortText= new KAction( i18n( "Sort Text..." ), 0,
01153                                  this, SLOT( sortText() ),
01154                                  actionCollection(), "sort_text" );
01155 
01156     m_actionAddPersonalExpression= new KAction( i18n( "Add Expression" ), 0,
01157                                               this, SLOT( addPersonalExpression() ),
01158                                               actionCollection(), "add_personal_expression" );
01159 
01160 
01161     // ---------------------- Tools menu
01162 
01163 
01164     m_actionAllowAutoFormat = new KToggleAction( i18n( "Enable Autocorrection" ), 0,
01165                                              this, SLOT( slotAllowAutoFormat() ),
01166                                           actionCollection(), "enable_autocorrection" );
01167     m_actionAllowAutoFormat->setCheckedState(i18n("Disable Autocorrection"));
01168     m_actionAllowAutoFormat->setToolTip( i18n( "Toggle autocorrection on and off." ) );
01169     m_actionAllowAutoFormat->setWhatsThis( i18n( "Toggle autocorrection on and off." ) );
01170 
01171     m_actionAutoFormat = new KAction( i18n( "Configure &Autocorrection..." ), 0,
01172                         this, SLOT( extraAutoFormat() ),
01173                         actionCollection(), "configure_autocorrection" );
01174     m_actionAutoFormat->setToolTip( i18n( "Change autocorrection options." ) );
01175     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>." ) );
01176 
01177     m_actionEditCustomVarsEdit = new KAction( i18n( "Custom &Variables..." ), 0,
01178                                         this, SLOT( editCustomVars() ), // TODO: new dialog w add etc.
01179                                         actionCollection(), "custom_vars" );
01180 
01181     m_actionEditPersonnalExpr=new KAction( i18n( "Edit &Personal Expressions..." ), 0,
01182                                          this, SLOT( editPersonalExpr() ),
01183                                      actionCollection(), "personal_expr" );
01184     m_actionEditPersonnalExpr->setToolTip( i18n( "Add or change one or more personal expressions." ) );
01185     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." ) );
01186 
01187     m_actionChangeCase=new KAction( i18n( "Change Case..." ), 0,
01188                                      this, SLOT( changeCaseOfText() ),
01189                                      actionCollection(), "change_case" );
01190     m_actionChangeCase->setToolTip( i18n( "Alter the capitalization of selected text." ) );
01191     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." ) );
01192 
01193     //------------------------ Settings menu
01194     m_actionConfigure = KStdAction::preferences(this, SLOT(configure()), actionCollection(), "configure" );
01195 
01196     //------------------------ Menu frameSet
01197     KAction *actionChangePicture=new KAction( i18n( "Change Picture..." ),"frame_image",0,
01198                                      this, SLOT( changePicture() ),
01199                                      actionCollection(), "change_picture" );
01200     actionChangePicture->setToolTip( i18n( "Change the picture in the currently selected frame." ) );
01201     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." ) );
01202 
01203     m_actionConfigureHeaderFooter=new KAction( i18n( "Configure Header/Footer..." ), 0,
01204                                      this, SLOT( configureHeaderFooter() ),
01205                                      actionCollection(), "configure_headerfooter" );
01206     m_actionConfigureHeaderFooter->setToolTip( i18n( "Configure the currently selected header or footer." ) );
01207     m_actionConfigureHeaderFooter->setWhatsThis( i18n( "Configure the currently selected header or footer." ) );
01208 
01209     m_actionInlineFrame = new KToggleAction( i18n( "Inline Frame" ), 0,
01210                                             this, SLOT( inlineFrame() ),
01211                                             actionCollection(), "inline_frame" );
01212     m_actionInlineFrame->setToolTip( i18n( "Convert current frame to an inline frame." ) );
01213     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." ) );
01214 
01215     m_actionOpenLink = new KAction( i18n( "Open Link" ), 0,
01216                                      this, SLOT( openLink() ),
01217                                      actionCollection(), "open_link" );
01218     m_actionOpenLink->setToolTip( i18n( "Open the link with the appropriate application." ) );
01219     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." ) );
01220 
01221     m_actionChangeLink=new KAction( i18n("Change Link..."), 0,
01222                                   this,SLOT(changeLink()),
01223                                   actionCollection(), "change_link");
01224     m_actionChangeLink->setToolTip( i18n( "Change the content of the currently selected link." ) );
01225     m_actionChangeLink->setWhatsThis( i18n( "Change the details of the currently selected link." ) );
01226 
01227     m_actionCopyLink = new KAction( i18n( "Copy Link" ), 0,
01228                                      this, SLOT( copyLink() ),
01229                                      actionCollection(), "copy_link" );
01230 
01231     m_actionAddLinkToBookmak = new KAction( i18n( "Add to Bookmark" ), 0,
01232                                      this, SLOT( addToBookmark() ),
01233                                      actionCollection(), "add_to_bookmark" );
01234 
01235     m_actionRemoveLink = new KAction( i18n( "Remove Link" ), 0,
01236                                      this, SLOT( removeLink() ),
01237                                      actionCollection(), "remove_link" );
01238 
01239     m_actionShowDocStruct = new KToggleAction( i18n( "Show Doc Structure" ), 0,
01240                                             this, SLOT( showDocStructure() ),
01241                                             actionCollection(), "show_docstruct" );
01242     m_actionShowDocStruct->setCheckedState(i18n("Hide Doc Structure"));
01243     m_actionShowDocStruct->setToolTip( i18n( "Open document structure sidebar." ) );
01244     m_actionShowDocStruct->setWhatsThis( i18n( "Open document structure sidebar.<p>This sidebar helps you organize your document and quickly find pictures, tables etc." ) );
01245 
01246     m_actionShowRuler = new KToggleAction( i18n( "Show Rulers" ), 0,
01247             this, SLOT( showRuler() ),
01248             actionCollection(), "show_ruler" );
01249     m_actionShowRuler->setCheckedState(i18n("Hide Rulers"));
01250     m_actionShowRuler->setToolTip( i18n( "Shows or hides rulers." ) );
01251     m_actionShowRuler->setWhatsThis( i18n("The rulers are the white measuring spaces top and left of the "
01252                     "document. The rulers show the position and width of pages and of frames and can "
01253                     "be used to position tabulators among others.<p>Uncheck this to disable "
01254                     "the rulers from being displayed." ) );
01255 
01256     m_actionViewShowGrid = new KToggleAction( i18n( "Show Grid" ), 0,
01257                                             this, SLOT( viewGrid() ),
01258                                             actionCollection(), "view_grid" );
01259     m_actionViewShowGrid->setCheckedState(i18n("Hide Grid"));
01260 
01261     m_actionViewSnapToGrid= new KToggleAction( i18n( "Snap to Grid" ), 0,
01262                                              this, SLOT(viewSnapToGrid() ),
01263                                              actionCollection(), "view_snaptogrid" );
01264 
01265     m_actionConfigureCompletion = new KAction( i18n( "Configure C&ompletion..." ), 0,
01266                         this, SLOT( configureCompletion() ),
01267                         actionCollection(), "configure_completion" );
01268     m_actionConfigureCompletion->setToolTip( i18n( "Change the words and options for autocompletion." ) );
01269     m_actionConfigureCompletion->setWhatsThis( i18n( "Add words or change the options for autocompletion." ) );
01270 
01271 
01272     // ------------------- Actions with a key binding and no GUI item
01273     new KAction( i18n( "Insert Non-Breaking Space" ), Qt::CTRL+Qt::Key_Space,
01274                  this, SLOT( slotNonbreakingSpace() ), actionCollection(), "nonbreaking_space" );
01275     new KAction( i18n( "Insert Non-Breaking Hyphen" ), Qt::CTRL+Qt::SHIFT+Qt::Key_Minus,
01276                  this, SLOT( slotNonbreakingHyphen() ), actionCollection(), "nonbreaking_hyphen" );
01277     new KAction( i18n( "Insert Soft Hyphen" ), Qt::CTRL+Qt::Key_Minus,
01278                  this, SLOT( slotSoftHyphen() ), actionCollection(), "soft_hyphen" );
01279     new KAction( i18n( "Line Break" ), Qt::SHIFT+Qt::Key_Return,
01280                  this, SLOT( slotLineBreak() ), actionCollection(), "line_break" );
01281 
01282     new KAction( i18n( "Completion" ), KStdAccel::shortcut(KStdAccel::TextCompletion), this, SLOT( slotCompletion() ), actionCollection(), "completion" );
01283 
01284     new KAction( i18n( "Increase Numbering Level" ), Qt::ALT+Qt::Key_Right,
01285                  this, SLOT( slotIncreaseNumberingLevel() ), actionCollection(), "increase_numbering_level" );
01286     new KAction( i18n( "Decrease Numbering Level" ), Qt::ALT+Qt::Key_Left,
01287                  this, SLOT( slotDecreaseNumberingLevel() ), actionCollection(), "decrease_numbering_level" );
01288 
01289 
01290     // --------
01291     m_actionEditCustomVars = new KAction( i18n( "Edit Variable..." ), 0,
01292                                         this, SLOT( editCustomVariable() ),
01293                                         actionCollection(), "edit_customvars" );
01294     m_actionApplyAutoFormat= new KAction( i18n( "Apply Autocorrection" ), 0,
01295                                         this, SLOT( applyAutoFormat() ),
01296                                         actionCollection(), "apply_autoformat" );
01297     m_actionApplyAutoFormat->setToolTip( i18n( "Manually force KWord to scan the entire document and apply autocorrection." ) );
01298     m_actionApplyAutoFormat->setWhatsThis( i18n( "Manually force KWord to scan the entire document and apply autocorrection." ) );
01299 
01300     m_actionCreateStyleFromSelection = new KAction( i18n( "Create Style From Selection..." ), 0,
01301                                         this, SLOT( createStyleFromSelection()),
01302                                         actionCollection(), "create_style" );
01303     m_actionCreateStyleFromSelection->setToolTip( i18n( "Create a new style based on the currently selected text." ) );
01304     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."
01305 
01306     m_actionConfigureFootEndNote = new KAction( i18n( "&Footnote..." ), 0,
01307                                         this, SLOT( configureFootEndNote()),
01308                                         actionCollection(), "format_footendnote" );
01309     m_actionConfigureFootEndNote->setToolTip( i18n( "Change the look of footnotes." ) );
01310     m_actionConfigureFootEndNote->setWhatsThis( i18n( "Change the look of footnotes." ) );
01311 
01312     m_actionEditFootEndNote= new KAction( i18n("Edit Footnote"), 0,
01313                                         this, SLOT( editFootEndNote()),
01314                                         actionCollection(), "edit_footendnote" );
01315     m_actionEditFootEndNote->setToolTip( i18n( "Change the content of the currently selected footnote." ) );
01316     m_actionEditFootEndNote->setWhatsThis( i18n( "Change the content of the currently selected footnote." ) );
01317 
01318 
01319     m_actionChangeFootNoteType = new KAction( i18n("Change Footnote/Endnote Parameter"), 0,
01320                                         this, SLOT( changeFootNoteType() ),
01321                                             actionCollection(), "change_footendtype");
01322 
01323     m_actionSavePicture= new KAction( i18n("Save Picture As..."), 0,
01324                                     this, SLOT( savePicture() ),
01325                                     actionCollection(), "save_picture");
01326     m_actionSavePicture->setToolTip( i18n( "Save the picture in a separate file." ) );
01327     m_actionSavePicture->setWhatsThis( i18n( "Save the picture in the currently selected frame in a separate file, outside the KWord document." ) );
01328 
01329     m_actionAllowBgSpellCheck = new KToggleAction( i18n( "Autospellcheck" ), 0,
01330                                             this, SLOT( autoSpellCheck() ),
01331                                             actionCollection(), "tool_auto_spellcheck" );
01332 
01333 
01334     m_actionGoToFootEndNote = new KAction( QString::null /*set dynamically*/, 0,
01335                                             this, SLOT( goToFootEndNote() ),
01336                                             actionCollection(), "goto_footendnote" );
01337 
01338     // Document Structure Area popup menu.
01339     m_actionDocStructEdit = new KAction( i18n( "Edit Text" ), 0,
01340                                          this, SLOT( docStructEdit() ),
01341                                          actionCollection(), "docstruct_edit" );
01342     m_actionDocStructSpeak = new KAction( i18n("Speak Text" ), 0,
01343                                           this, SLOT( docStructSpeak() ),
01344                                           actionCollection(), "docstruct_speak" );
01345     m_actionDocStructSelect = new KAction( i18n( "Show" ), 0,
01346                                            this, SLOT( docStructSelect() ),
01347                                            actionCollection(), "docstruct_select" );
01348     m_actionDocStructDelete = new KAction( i18n( "Delete Frame" ), 0,
01349                                            this, SLOT( docStructDelete() ),
01350                                            actionCollection(), "docstruct_delete" );
01351     m_actionDocStructProperties = new KAction( i18n( "Properties" ), 0,
01352                                                this, SLOT( docStructProperties() ),
01353                                                actionCollection(), "docstruct_properties" );
01354 
01355     m_actionAddBookmark= new KAction( i18n( "&Bookmark..." ), 0,
01356                                             this, SLOT( addBookmark() ),
01357                                             actionCollection(), "add_bookmark" );
01358     m_actionSelectBookmark= new KAction( i18n( "Select &Bookmark..." ), 0,
01359                                             this, SLOT( selectBookmark() ),
01360                                             actionCollection(), "select_bookmark" );
01361 
01362     m_actionImportStyle= new KAction( i18n( "Import Styles..." ), 0,
01363                                             this, SLOT( importStyle() ),
01364                                             actionCollection(), "import_style" );
01365 
01366     m_actionCreateFrameStyle = new KAction( i18n( "&Create Framestyle From Frame..." ), 0,
01367                                         this, SLOT( createFrameStyle()),
01368                                         actionCollection(), "create_framestyle" );
01369     m_actionCreateFrameStyle->setToolTip( i18n( "Create a new style based on the currently selected frame." ) );
01370     m_actionCreateFrameStyle->setWhatsThis( i18n( "Create a new framestyle based on the currently selected frame." ) );
01371 
01372 #if 0 // re-enable after fixing
01373     m_actionInsertDirectCursor = new KToggleAction( i18n( "Type Anywhere Cursor" ), 0,
01374                                                   this, SLOT( insertDirectCursor() ),
01375                                                   actionCollection(), "direct_cursor" );
01376 #endif
01377 
01378     m_actionConvertToTextBox = new KAction( i18n( "Convert to Text Box" ), 0,
01379                                                   this, SLOT( convertToTextBox() ),
01380                                                   actionCollection(), "convert_to_text_box" );
01381 
01382 
01383     m_actionSpellIgnoreAll = new KAction( i18n( "Ignore All" ), 0,
01384                                         this, SLOT( slotAddIgnoreAllWord() ),
01385                                         actionCollection(), "ignore_all" );
01386 
01387     m_actionAddWordToPersonalDictionary=new KAction( i18n( "Add Word to Dictionary" ),0,
01388                                                    this, SLOT( addWordToDictionary() ),
01389                                                    actionCollection(), "add_word_to_dictionary" );
01390 
01391     m_actionEmbeddedStoreInternal=new KToggleAction( i18n( "Store Document Internally" ),0,
01392                                             this, SLOT( embeddedStoreInternal() ),
01393                                             actionCollection(), "embedded_store_internal" );
01394 
01395     m_actionGoToDocumentStructure=new KAction( i18n( "Go to Document Structure" ), KShortcut("Alt+1"),
01396                                              this, SLOT( goToDocumentStructure() ),
01397                                              actionCollection(), "goto_document_structure" );
01398     m_actionGoToDocument=new KAction( i18n( "Go to Document" ), KShortcut("Alt+2"),
01399                                     this, SLOT( goToDocument() ),
01400                                     actionCollection(), "goto_document" );
01401 
01402     // For RMB inside a cell, see KWFrameView::showPopup
01403     // This isn't a dynamic list; it's only plugged/unplugged depending on the context.
01404     // If you change the contents of that list, check ~KWView.
01405     m_tableActionList.append( new KActionSeparator(actionCollection()) );
01406     m_tableActionList.append( m_actionTableInsertRow );
01407     m_tableActionList.append( m_actionTableDelRow );
01408     m_tableActionList.append( m_actionTableInsertCol );
01409     m_tableActionList.append( m_actionTableDelCol );
01410 }
01411 
01412 void KWView::refreshMenuExpression()
01413 {
01414     loadexpressionActions( m_actionInsertExpression);
01415 }
01416 
01417 void KWView::updateGridButton()
01418 {
01419     m_actionViewShowGrid->setChecked( m_doc->showGrid() );
01420     m_actionViewSnapToGrid->setChecked ( m_doc->snapToGrid() );
01421 }
01422 
01423 void KWView::loadexpressionActions( KActionMenu * parentMenu)
01424 {
01425     KActionPtrList lst = actionCollection()->actions("expression-action");
01426     QValueList<KAction *> actions = lst;
01427     QValueList<KAction *>::ConstIterator it = lst.begin();
01428     QValueList<KAction *>::ConstIterator end = lst.end();
01429     // Delete all actions but keep their shortcuts in mind
01430     QMap<QString, KShortcut> personalShortCuts;
01431     for (; it != end; ++it )
01432     {
01433         personalShortCuts.insert( (*it)->text(), (*it)->shortcut() );
01434         delete *it;
01435     }
01436 
01437     parentMenu->popupMenu()->clear();
01438     QStringList path = m_doc->personalExpressionPath();
01439     QStringList files;
01440     for ( QStringList::Iterator it = path.begin(); it != path.end(); ++it )
01441     {
01442         QDir dir( *it );
01443         if ( dir.exists() )
01444         {
01445             QStringList tmp = dir.entryList("*.xml");
01446             for ( QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2 )
01447                 files.append( QString( (*it) + (*it2) ));
01448         }
01449     }
01450 
01451     //QStringList files = KWFactory::instance()->dirs()->findAllResources( "expression", "*.xml", TRUE );
01452     int i = 0;
01453     int nbFile = 0;
01454     for( QStringList::Iterator it = files.begin(); it != files.end(); ++it,nbFile++ )
01455         createExpressionActions( parentMenu,*it, i,(nbFile<(int)files.count()-1), personalShortCuts );
01456 }
01457 
01458 void KWView::createExpressionActions( KActionMenu * parentMenu,const QString& filename,int &i, bool insertSepar, const QMap<QString, KShortcut>& personalShortCut )
01459 {
01460     QFile file( filename );
01461     if ( !file.exists() || !file.open( IO_ReadOnly ) )
01462         return;
01463 
01464     QDomDocument doc;
01465     doc.setContent( &file );
01466     file.close();
01467 
01468     bool expressionExist =false;
01469     QDomNode n = doc.documentElement().firstChild();
01470     for( ; !n.isNull(); n = n.nextSibling() )
01471     {
01472         if ( n.isElement() )
01473         {
01474             QDomElement e = n.toElement();
01475             if ( e.tagName() == "Type" )
01476             {
01477                 expressionExist =true;
01478                 QString group = i18n( e.namedItem( "TypeName" ).toElement().text().utf8() );
01479                 KActionMenu * subMenu = new KActionMenu( group, actionCollection() );
01480                 parentMenu->insert( subMenu );
01481 
01482                 QDomNode n2 = e.firstChild();
01483                 for( ; !n2.isNull(); n2 = n2.nextSibling() )
01484                 {
01485 
01486                     if ( n2.isElement() )
01487                     {
01488                         QDomElement e2 = n2.toElement();
01489                         if ( e2.tagName() == "Expression" )
01490                         {
01491                             QString text = i18n( e2.namedItem( "Text" ).toElement().text().utf8() );
01492                             KAction * act = new KAction( text, 0, this, SLOT( insertExpression() ),
01493                                                          actionCollection(),
01494                                                          QString("expression-action_%1").arg(i).latin1() );
01495                             if ( personalShortCut.contains(text) )
01496                                 act->setShortcut( personalShortCut[text] );
01497                             i++;
01498                             act->setGroup("expression-action");
01499                             subMenu->insert( act );
01500                         }
01501                     }
01502                 }
01503             }
01504         }
01505     }
01506     if(expressionExist && insertSepar)
01507         parentMenu->popupMenu()->insertSeparator();
01508 }
01509 
01510 void KWView::insertExpression()
01511 {
01512  KWTextFrameSetEdit * edit = currentTextEdit();
01513     if ( edit )
01514     {
01515         KAction * act = (KAction *)(sender());
01516         edit->insertExpression(act->text());
01517     }
01518 }
01519 
01520 
01521 void KWView::addVariableActions( int type, const QStringList & texts,
01522                                  KActionMenu * parentMenu, const QString & menuText )
01523 {
01524     // Single items go directly into parentMenu.
01525     // For multiple items we create a submenu.
01526     if ( texts.count() > 1 && !menuText.isEmpty() )
01527     {
01528         KActionMenu * subMenu = new KActionMenu( menuText, actionCollection() );
01529         parentMenu->insert( subMenu );
01530         parentMenu = subMenu;
01531     }
01532     QStringList::ConstIterator it = texts.begin();
01533     for ( int i = 0; it != texts.end() ; ++it, ++i )
01534     {
01535         if ( !(*it).isEmpty() ) // in case of removed subtypes or placeholders
01536         {
01537             VariableDef v;
01538             v.type = type;
01539             v.subtype = i;
01540             QCString actionName;
01541             actionName.sprintf( "var-action-%d-%d", type, i );
01542             KAction * act = new KAction( (*it), 0, this, SLOT( insertVariable() ),
01543                                          actionCollection(), actionName );
01544             // Mainly for KEditToolbar
01545             act->setToolTip( i18n( "Insert variable \"%1\" into the text" ).arg( *it ) );
01546             m_variableDefMap.insert( act, v );
01547             parentMenu->insert( act );
01548         }
01549     }
01550 }
01551 
01552 void KWView::refreshCustomMenu()
01553 {
01554     KActionPtrList lst2 = actionCollection()->actions("custom-variable-action");
01555     QValueList<KAction *> actions = lst2;
01556     QValueList<KAction *>::ConstIterator it2 = lst2.begin();
01557     QValueList<KAction *>::ConstIterator end = lst2.end();
01558     QMap<QString, KShortcut> shortCuts;
01559 
01560     for (; it2 != end; ++it2 )
01561     {
01562         shortCuts.insert((*it2)->text(), (*it2)->shortcut());
01563         delete *it2;
01564     }
01565 
01566     delete m_actionInsertCustom;
01567     m_actionInsertCustom = new KActionMenu( i18n( "&Custom" ),
01568                                             actionCollection(), "insert_custom" );
01569     actionInsertVariable->insert(m_actionInsertCustom, 0);
01570 
01571     m_actionInsertCustom->popupMenu()->clear();
01572     QPtrListIterator<KoVariable> it( m_doc->variableCollection()->getVariables() );
01573     KAction * act=0;
01574     QStringList lst;
01575     QString varName;
01576     int i = 0;
01577     for ( ; it.current() ; ++it )
01578     {
01579         KoVariable *var = it.current();
01580         if ( var->type() == VT_CUSTOM )
01581         {
01582             varName=( (KoCustomVariable*) var )->name();
01583             if ( !lst.contains( varName) )
01584             {
01585                  lst.append( varName );
01586                  QCString name = QString("custom-action_%1").arg(i).latin1();
01587                  act = new KAction( varName, shortCuts[varName], this, SLOT( insertCustomVariable() ),actionCollection(), name );
01588                  act->setGroup( "custom-variable-action" );
01589                  m_actionInsertCustom->insert( act );
01590                  i++;
01591             }
01592         }
01593     }
01594     bool state=!lst.isEmpty();
01595     if(state)
01596         m_actionInsertCustom->popupMenu()->insertSeparator();
01597 
01598     act = new KAction( i18n("New..."), 0, this, SLOT( insertNewCustomVariable() ), actionCollection(),QString("custom-action_%1").arg(i).latin1());
01599     act->setGroup( "custom-variable-action" );
01600 
01601 
01602     m_actionEditCustomVarsEdit->setEnabled( state );
01603 
01604     m_actionInsertCustom->insert( act );
01605 
01606 }
01607 
01608 
01609 void KWView::insertCustomVariable()
01610 {
01611     KWTextFrameSetEdit * edit = currentTextEdit();
01612     if ( edit )
01613     {
01614         KAction * act = (KAction *)(sender());
01615         edit->insertCustomVariable(act->text());
01616     }
01617 }
01618 
01619 void KWView::insertNewCustomVariable()
01620 {
01621     KWTextFrameSetEdit * edit = currentTextEdit();
01622     if ( edit )
01623         edit->insertVariable( VT_CUSTOM, 0 );
01624 }
01625 
01626 void KWView::showFormulaToolbar( bool show )
01627 {
01628     m_doc->formulaDocument()->setEnabled( show );
01629     m_doc->formulaDocumentWrapper()->enableMatrixActions( show );
01630     m_doc->formulaDocumentWrapper()->getSyntaxHighlightingAction()->setEnabled( true );
01631     if(shell())
01632       shell()->showToolbar( "formula_toolbar", show );
01633 }
01634 
01635 void KWView::updatePageInfo()
01636 {
01637     if ( m_sbPageLabel )
01638     {
01639         KWFrameSetEdit * edit = m_gui->canvasWidget()->currentFrameSetEdit();
01640         if ( edit && edit->currentFrame() )
01641             m_currentPage = m_doc->pageManager()->page(edit->currentFrame());
01642         else {
01643             KWFrameView *view = frameViewManager()->selectedFrame();
01644             if(view)
01645                 m_currentPage = m_doc->pageManager()->page(view->frame());
01646         }
01647         /*kdDebug() << (void*)this << " KWView::updatePageInfo "
01648                   << " edit: " << edit << " " << ( edit?edit->frameSet()->name():QString::null)
01649                   << " currentFrame: " << (edit?edit->currentFrame():0L)
01650                   << " m_currentPage=" << currentPage() << " m_sbPageLabel=" << m_sbPageLabel
01651                   << endl;*/
01652 
01653         QString oldText = m_sbPageLabel->text();
01654         QString newText;
01655         if ( viewMode()->hasPages() )
01656             newText = ' ' + i18n( "Page %1 of %2" ).arg(m_currentPage->pageNumber())
01657                 .arg(m_doc->pageCount()) + ' ';
01658 
01659         if ( newText != oldText )
01660         {
01661             m_sbPageLabel->setText( newText );
01662             // Need to repaint immediately. Otherwise when deleting 100 pages
01663             // at once, there's no feedback.
01664             m_sbPageLabel->repaint();
01665         }
01666     }
01667     slotUpdateRuler();
01668 }
01669 
01670 void KWView::numPagesChanged()
01671 {
01672      docStructChanged(TextFrames);
01673      updatePageInfo();
01674      int pages = m_doc->pageCount();
01675      kdDebug() <<  pages <<  " " << (m_doc->processingType() == KWDocument::DTP) << endl;
01676      refreshDeletePageAction();
01677 }
01678 
01679 void KWView::updateFrameStatusBarItem()
01680 {
01681     KStatusBar * sb = statusBar();
01682     int nbFrame=frameViewManager()->selectedFrames().count();
01683     if ( m_doc->showStatusBar() && sb && nbFrame > 0 )
01684     {
01685         if ( nbFrame == 1 )
01686         {
01687             KoUnit::Unit unit = m_doc->unit();
01688             QString unitName = m_doc->unitName();
01689             KWFrame * frame = frameViewManager()->selectedFrames()[0]->frame();
01690             m_sbFramesLabel->setText( ' ' + i18n( "Statusbar info", "%1: %2, %3 - %4, %5 (width: %6, height: %7)" )
01691                     .arg( frame->frameSet()->name() )
01692                     .arg( KoUnit::toUserStringValue( frame->left(), unit ) )
01693                     .arg( KoUnit::toUserStringValue( frame->top() - m_doc->pageManager()->topOfPage(
01694                                 m_doc->pageManager()->pageNumber(frame->rect()) ), unit) )
01695                     .arg( KoUnit::toUserStringValue( frame->right(), unit ) )
01696                     .arg( KoUnit::toUserStringValue( frame->bottom(), unit ) )
01697                     .arg( KoUnit::toUserStringValue( frame->width(), unit ) )
01698                     .arg( KoUnit::toUserStringValue( frame->height(), unit ) ) );
01699         } else
01700             m_sbFramesLabel->setText( ' ' + i18n( "%1 frames selected" ).arg( nbFrame ) );
01701     }
01702     else if ( sb && m_sbFramesLabel )
01703         m_sbFramesLabel->setText( QString::null );
01704 }
01705 
01706 void KWView::setTemporaryStatusBarText(const QString &text)
01707 {
01708     if ( statusBar() && m_sbFramesLabel )
01709         m_sbFramesLabel->setText( text );
01710 }
01711 
01712 void KWView::clipboardDataChanged()
01713 {
01714     if ( !m_gui || !m_doc->isReadWrite() )
01715     {
01716         m_actionEditPaste->setEnabled(false);
01717         return;
01718     }
01719     KWFrameSetEdit * edit = m_gui->canvasWidget()->currentFrameSetEdit();
01720     // Is there plain text in the clipboard ?
01721     if ( edit && !QApplication::clipboard()->text().isEmpty() )
01722     {
01723         m_actionEditPaste->setEnabled(true);
01724         return;
01725     }
01726     QMimeSource *data = QApplication::clipboard()->data();
01727     const int provides = checkClipboard( data );
01728     if ( provides & ( ProvidesImage | ProvidesOasis | ProvidesFormula ) )
01729         m_actionEditPaste->setEnabled( true );
01730     else
01731     {
01732         // Plain text requires a framesetedit
01733         m_actionEditPaste->setEnabled( edit && ( provides & ProvidesPlainText ) );
01734     }
01735 }
01736 
01737 int KWView::checkClipboard( QMimeSource *data )
01738 {
01739     int provides = 0;
01740     QValueList<QCString> formats;
01741     const char* fmt;
01742     for (int i=0; (fmt = data->format(i)); i++)
01743         formats.append( QCString( fmt ) );
01744 
01745 #if 0 // not needed anymore
01746     // QImageDrag::canDecode( data ) is very very slow in Qt 2 (n*m roundtrips)
01747     // Workaround....
01748     QStrList fileFormats = QImageIO::inputFormats();
01749     for ( fileFormats.first() ; fileFormats.current() && !provides ; fileFormats.next() )
01750     {
01751         QCString format = fileFormats.current();
01752         QCString type = "image/" + format.lower();
01753         if ( ( formats.findIndex( type ) != -1 ) )
01754             provides |= ProvidesImage;
01755     }
01756 #endif
01757     if ( QImageDrag::canDecode( data ) )
01758         provides |= ProvidesImage;
01759     if ( formats.findIndex( KFormula::MimeSource::selectionMimeType() ) != -1 )
01760         provides |= ProvidesFormula;
01761     if ( formats.findIndex( "text/plain" ) != -1 )
01762         provides |= ProvidesPlainText;
01763     QCString returnedTypeMime = KoTextObject::providesOasis( data );
01764     if ( !returnedTypeMime.isEmpty() )
01765         provides |= ProvidesOasis;
01766     //kdDebug(32001) << "KWView::checkClipboard provides=" << provides << endl;
01767     return provides;
01768 }
01769 
01770 /*=========================== file print =======================*/
01771 void KWView::setupPrinter( KPrinter &prt )
01772 {
01773     //recalc time and date variable before to print
01774     //it's necessary otherwise we print a document
01775     //with a bad date and time
01776     //TODO call once this function
01777     m_doc->recalcVariables(  VT_TIME );
01778     m_doc->recalcVariables(  VT_DATE );
01779     m_doc->recalcVariables(  VT_STATISTIC );
01780 
01781     prt.setPageSelection( KPrinter::ApplicationSide );
01782     prt.setCurrentPage( currentPage() );
01783     prt.setMinMax( m_doc->startPage(), m_doc->lastPage() );
01784 
01785     KoPageLayout pgLayout = m_doc->pageLayout();
01786 
01787     prt.setPageSize( static_cast<KPrinter::PageSize>( KoPageFormat::printerPageSize( pgLayout.format ) ) );
01788 
01789     if ( pgLayout.orientation == PG_LANDSCAPE || pgLayout.format == PG_SCREEN )
01790         prt.setOrientation( KPrinter::Landscape );
01791     else
01792         prt.setOrientation( KPrinter::Portrait );
01793 }
01794 
01795 void KWView::print( KPrinter &prt )
01796 {
01797     bool displayFieldCode = m_doc->variableCollection()->variableSetting()->displayFieldCode();
01798     if ( displayFieldCode )
01799     {
01800         m_doc->variableCollection()->variableSetting()->setDisplayFieldCode(false);
01801         m_doc->recalcVariables(  VT_ALL );
01802     }
01803 
01804 // Don't repaint behind the print dialog until we're done zooming/unzooming the doc
01805     m_gui->canvasWidget()->setUpdatesEnabled(false);
01806     m_gui->canvasWidget()->viewport()->setCursor( waitCursor );
01807 
01808     prt.setFullPage( true );
01809 
01810     // ### HACK: disable zooming-when-printing if embedded parts are used.
01811     // No koffice app supports zooming in paintContent currently.
01812     // Disable in ALL cases now
01813     bool doZoom = false;
01814     /*QPtrListIterator<KWFrameSet> fit = m_doc->framesetsIterator();
01815     for ( ; fit.current() && doZoom ; ++fit )
01816         if ( fit.current()->type() == FT_PART )
01817             doZoom = false;*/
01818 
01819     int oldZoom = m_doc->zoom();
01820     // We don't get valid metrics from the printer - and we want a better resolution
01821     // anyway (it's the PS driver that takes care of the printer resolution).
01822     QPaintDeviceMetrics metrics( &prt );
01823 
01824     //int dpiX = metrics.logicalDpiX();
01825     //int dpiY = metrics.logicalDpiY();
01826     int dpiX = doZoom ? 300 : KoGlobal::dpiX();
01827     int dpiY = doZoom ? 300 : KoGlobal::dpiY();
01830     m_doc->setZoomAndResolution( 100, dpiX, dpiY );
01831     m_doc->newZoomAndResolution( false, true /* for printing*/ );
01832     //kdDebug() << "KWView::print metrics: " << metrics.logicalDpiX() << "," << metrics.logicalDpiY() << endl;
01833     //kdDebug() << "x11AppDPI: " << KoGlobal::dpiX() << "," << KoGlobal::dpiY() << endl;
01834 
01835     bool serialLetter = FALSE;
01836 
01837     QPtrList<KoVariable> vars = m_doc->variableCollection()->getVariables();
01838     KoVariable *v = 0;
01839     for ( v = vars.first(); v; v = vars.next() ) {
01840         if ( v->type() == VT_MAILMERGE ) {
01841             serialLetter = TRUE;
01842             break;
01843         }
01844     }
01845 
01846     if ( !m_doc->mailMergeDataBase() ) serialLetter=FALSE;
01847     else
01848     {
01849         m_doc->mailMergeDataBase()->refresh(false);
01850         if (m_doc->mailMergeDataBase()->getNumRecords() == 0 )  serialLetter = FALSE;
01851     }
01852 
01853     //float left_margin = 0.0;
01854     //float top_margin = 0.0;
01855 
01856     KoPageLayout pgLayout;
01857     KoColumns cl;
01858     KoKWHeaderFooter hf;
01859     m_doc->getPageLayout( pgLayout, cl, hf );
01860     KoPageLayout oldPGLayout = pgLayout;
01861 
01862     if ( pgLayout.format == PG_SCREEN )
01863     {
01864         //left_margin = 25.8;
01865         //top_margin = 15.0;
01866         pgLayout.ptLeft += 25.8;         // Not sure why we need this....
01867         pgLayout.ptRight += 15.0;
01868         m_doc->setPageLayout( pgLayout, cl, hf, false );
01869     }
01870 
01871     QPainter painter;
01872     painter.begin( &prt );
01873 
01874     kdDebug(32001) << "KWView::print scaling by " << (double)metrics.logicalDpiX() / (double)dpiX
01875                    << "," << (double)metrics.logicalDpiY() / (double)dpiY << endl;
01876     painter.scale( (double)metrics.logicalDpiX() / (double)dpiX,
01877                    (double)metrics.logicalDpiY() / (double)dpiY );
01878 
01879     bool canceled = false;
01880     // Breaks wysiwyg, obviously - trying without
01881 //#define KW_PASS_PAINTER_TO_QRT
01882 #ifdef KW_PASS_PAINTER_TO_QRT
01883     int paragraphs = 0;
01884     fit.toFirst();
01885     for ( ; fit.current() ; ++fit )
01886         if ( fit.current()->isVisible() )
01887             paragraphs += fit.current()->paragraphs();
01888     kdDebug() << "KWView::print total paragraphs: " << paragraphs << endl;
01889 
01890     // This can take a lot of time (reformatting everything), so a progress dialog is needed
01891     QProgressDialog progress( i18n( "Printing..." ), i18n( "Cancel" ), paragraphs, this );
01892     progress.setProgress( 0 );
01893     int processedParags = 0;
01894     fit.toFirst();
01895     for ( ; fit.current() ; ++fit )
01896         if ( fit.current()->isVisible() )
01897         {
01898             qApp->processEvents();
01899             if ( progress.wasCancelled() ) {
01900                 canceled = true;
01901                 break;
01902             }
01903 
01904             kdDebug() << "KWView::print preparePrinting " << fit.current()->name() << endl;
01905             fit.current()->preparePrinting( &painter, &progress, processedParags );
01906         }
01907 #endif
01908 
01909     if ( !canceled )
01910     {
01911         if ( !serialLetter )
01912             m_gui->canvasWidget()->print( &painter, &prt );
01913         else
01914         {
01915             for ( int i = 0; i < m_doc->mailMergeDataBase()->getNumRecords(); ++i ) {
01916                 m_doc->setMailMergeRecord( i );
01917                 m_doc->variableCollection()->recalcVariables(VT_MAILMERGE);
01918                 m_gui->canvasWidget()->print( &painter, &prt );
01919                 if ( i < m_doc->mailMergeDataBase()->getNumRecords() - 1 )
01920                     prt.newPage();
01921             }
01922             m_doc->setMailMergeRecord( -1 );
01923         }
01924     }
01925 
01926     if ( pgLayout.format == PG_SCREEN )
01927         m_doc->setPageLayout( oldPGLayout, cl, hf, false );
01928 
01929 #ifdef KW_PASS_PAINTER_TO_QRT
01930     fit.toFirst();
01931     for ( ; fit.current() ; ++fit )
01932         if ( fit.current()->isVisible() )
01933             fit.current()->preparePrinting( 0L, 0L, processedParags );
01934 #endif
01935 
01936     m_doc->setZoomAndResolution( oldZoom, KoGlobal::dpiX(), KoGlobal::dpiY() );
01937     m_doc->newZoomAndResolution( false, false );
01938     kdDebug() << "KWView::print zoom&res reset" << endl;
01939 
01940     m_gui->canvasWidget()->setUpdatesEnabled(true);
01941     m_gui->canvasWidget()->viewport()->setCursor( ibeamCursor );
01942     m_doc->repaintAllViews();
01943 
01944     if ( displayFieldCode )
01945     {
01946         m_doc->variableCollection()->variableSetting()->setDisplayFieldCode(true);
01947         m_doc->recalcVariables(  VT_ALL );
01948     }
01949     else
01950         m_doc->variableCollection()->recalcVariables(VT_MAILMERGE);
01951 
01952     painter.end(); // this is what triggers the printing
01953     m_doc->variableCollection()->variableSetting()->setLastPrintingDate(QDateTime::currentDateTime());
01954     m_doc->recalcVariables( VT_DATE );
01955 }
01956 
01957 void KWView::showFormat( const KoTextFormat &currentFormat )
01958 {
01959     // update the gui with the current format.
01960     //kdDebug() << "KWView::setFormat font family=" << currentFormat.font().family() << endl;
01961     if (m_actionFormatFontFamily->font() != currentFormat.font().family())
01962         m_actionFormatFontFamily->setFont( currentFormat.font().family() );
01963     if (m_actionFormatFontSize->fontSize() != currentFormat.pointSize())
01964         m_actionFormatFontSize->setFontSize( currentFormat.pointSize() );
01965     m_actionFormatBold->setChecked( currentFormat.font().bold());
01966     m_actionFormatItalic->setChecked( currentFormat.font().italic() );
01967     m_actionFormatUnderline->setChecked( currentFormat.underline());
01968     m_actionFormatStrikeOut->setChecked( currentFormat.strikeOut());
01969     QColor col=currentFormat.textBackgroundColor();
01970     //m_actionBackgroundColor->setEnabled(true);
01971     m_actionBackgroundColor->setCurrentColor( col.isValid() ? col : QApplication::palette().color( QPalette::Active, QColorGroup::Base ));
01972 
01973     if ( m_gui /* if not in constructor */ && frameViewManager()->selectedFrames().count() > 0)
01974         m_actionBackgroundColor->setText(i18n("Frame Background Color..."));
01975     else
01976         m_actionBackgroundColor->setText(i18n("Text Background Color..."));
01977     switch(currentFormat.vAlign())
01978       {
01979       case KoTextFormat::AlignSuperScript:
01980         {
01981           m_actionFormatSub->setChecked( false );
01982           m_actionFormatSuper->setChecked( true );
01983           break;
01984         }
01985       case KoTextFormat::AlignSubScript:
01986         {
01987           m_actionFormatSub->setChecked( true );
01988           m_actionFormatSuper->setChecked( false );
01989           break;
01990         }
01991       case KoTextFormat::AlignNormal:
01992       default:
01993         {
01994           m_actionFormatSub->setChecked( false );
01995           m_actionFormatSuper->setChecked( false );
01996           break;
01997         }
01998       }
01999 
02000 }
02001 
02002 void KWView::showRulerIndent( double leftMargin, double firstLine, double rightMargin, bool rtl )
02003 {
02004   KoRuler * hRuler = m_gui ? m_gui->getHorzRuler() : 0;
02005   if ( hRuler )
02006   {
02007       hRuler->setFirstIndent( KoUnit::toUserValue( firstLine, m_doc->unit() ) );
02008       hRuler->setLeftIndent( KoUnit::toUserValue( leftMargin, m_doc->unit() ) );
02009       hRuler->setRightIndent( KoUnit::toUserValue( rightMargin, m_doc->unit() ) );
02010       hRuler->setDirection( rtl );
02011       m_actionFormatDecreaseIndent->setEnabled( leftMargin>0);
02012   }
02013 }
02014 
02015 void KWView::showAlign( int align ) {
02016     switch ( align ) {
02017         case Qt::AlignAuto: // In left-to-right mode it's align left. TODO: alignright if text->isRightToLeft()
02018             kdWarning() << k_funcinfo << "shouldn't be called with AlignAuto" << endl;
02019             // fallthrough
02020         case Qt::AlignLeft:
02021             m_actionFormatAlignLeft->setChecked( TRUE );
02022             break;
02023         case Qt::AlignHCenter:
02024             m_actionFormatAlignCenter->setChecked( TRUE );
02025             break;
02026         case Qt::AlignRight:
02027             m_actionFormatAlignRight->setChecked( TRUE );
02028             break;
02029         case Qt::AlignJustify:
02030             m_actionFormatAlignBlock->setChecked( TRUE );
02031             break;
02032     }
02033 }
02034 
02035 void KWView::showSpacing( int spacing ) {
02036   switch ( spacing )
02037   {
02038     case KoParagLayout::LS_SINGLE:
02039       m_actionFormatSpacingSingle->setChecked( TRUE );
02040       break;
02041     case KoParagLayout::LS_ONEANDHALF:
02042       m_actionFormatSpacingOneAndHalf->setChecked( TRUE );
02043       break;
02044     case KoParagLayout::LS_DOUBLE:
02045       m_actionFormatSpacingDouble->setChecked( TRUE );
02046       break;
02047     default:
02048       m_actionFormatSpacingSingle->setChecked( FALSE );
02049       m_actionFormatSpacingOneAndHalf->setChecked( FALSE );
02050       m_actionFormatSpacingDouble->setChecked( FALSE );
02051   }
02052 }
02053 
02054 void KWView::showCounter( KoParagCounter &c )
02055 {
02056     QString styleStr("counterstyle_");
02057     styleStr += QString::number( c.style() );
02058     //kdDebug() << "KWView::showCounter styleStr=" << styleStr << endl;
02059     KToggleAction* act = static_cast<KToggleAction *>( actionCollection()->action( styleStr.latin1() ) );
02060     Q_ASSERT( act );
02061     if ( act )
02062         act->setChecked( true );
02063 }
02064 
02065 void KWView::updateBorderButtons( const KoBorder& left, const KoBorder& right,
02066                                const KoBorder& top, const KoBorder& bottom )
02067 {
02068     m_actionBorderLeft->setChecked( left.penWidth() > 0 );
02069     m_actionBorderRight->setChecked( right.penWidth() > 0 );
02070     m_actionBorderTop->setChecked( top.penWidth() > 0 );
02071     m_actionBorderBottom->setChecked( bottom.penWidth() > 0 );
02072     m_actionBorderOutline->setChecked(
02073             m_actionBorderLeft->isChecked() &&
02074             m_actionBorderRight->isChecked() &&
02075             m_actionBorderTop->isChecked() &&
02076             m_actionBorderBottom->isChecked());
02077 
02078     KoBorder border = left;
02079     if(left.penWidth() > 0)
02080         border = left;
02081     else if(right.penWidth() > 0)
02082         border = right;
02083     else if(top.penWidth() > 0)
02084         border = top;
02085     else if(bottom.penWidth() > 0)
02086         border = bottom;
02087     else
02088         return;// then don't update since they are all empty.
02089 
02090     m_actionBorderWidth->setCurrentItem( (int)border.penWidth() - 1 );
02091     m_actionBorderStyle->setCurrentItem( (int)border.getStyle() );
02092     m_actionBorderColor->setCurrentColor( border.color );
02093 }
02094 
02095 void KWView::updateReadWrite( bool readwrite )
02096 {
02097     // First disable or enable everything
02098     QValueList<KAction*> actions = actionCollection()->actions();
02099     // Also grab actions from the document
02100     actions += m_doc->actionCollection()->actions();
02101     QValueList<KAction*>::ConstIterator aIt = actions.begin();
02102     QValueList<KAction*>::ConstIterator aEnd = actions.end();
02103     for (; aIt != aEnd; ++aIt )
02104         (*aIt)->setEnabled( readwrite );
02105 
02106     if ( !readwrite )
02107     {
02108         // Readonly -> re-enable a few harmless actions
02109         m_actionFileStatistics->setEnabled( true );
02110         m_actionExtraCreateTemplate->setEnabled( true );
02111         m_actionViewPageMode->setEnabled( true );
02112         m_actionViewPreviewMode->setEnabled( true );
02113 
02114         m_actionViewTextMode->setEnabled( true );
02115         m_actionShowRuler->setEnabled( true );
02116         m_actionEditFind->setEnabled( true );
02117         m_actionViewFormattingChars->setEnabled( true );
02118         m_actionViewFrameBorders->setEnabled( true );
02119         // that's not readonly, in fact, it modifies the doc
02120         //m_actionViewHeader->setEnabled( true );
02121         //m_actionViewFooter->setEnabled( true );
02122         m_actionViewZoom->setEnabled( true );
02123         m_actionInsertComment->setEnabled( true );
02124         m_actionAllowAutoFormat->setEnabled( true );
02125         m_actionShowDocStruct->setEnabled( true );
02126         m_actionConfigureCompletion->setEnabled( true );
02127         m_actionFormatBullet->setEnabled(true);
02128         m_actionFormatNumber->setEnabled( true);
02129         m_actionSelectBookmark->setEnabled( true );
02130         KAction* act = actionCollection()->action("edit_sldatabase");
02131         if (act)
02132             act->setEnabled( true );
02133 
02134         // In fact the new view could be readwrite, so this is too dangerous
02135         // (e.g. during spellchecking or during search-n-replace)
02136         //act = actionCollection()->action("view_newview");
02137         //if (act)
02138         //    act->setEnabled( true );
02139     }
02140     else
02141     {
02142         frameSelectedChanged();
02143         slotFrameSetEditChanged();
02144         refreshCustomMenu();
02145         refreshDeletePageAction();
02146         // Correctly enable or disable undo/redo actions again
02147         m_doc->commandHistory()->updateActions();
02148     }
02149 }
02150 
02151 void KWView::refreshDeletePageAction()
02152 {
02153     m_actionDeletePage->setEnabled( m_doc->pageCount() > 1 && m_doc->processingType() == KWDocument::DTP );
02154 }
02155 
02156 void KWView::showMouseMode( int mouseMode )
02157 {
02158     switch ( mouseMode ) {
02159     case KWCanvas::MM_EDIT:
02160     case KWCanvas::MM_CREATE_TABLE:
02161     case KWCanvas::MM_CREATE_FORMULA:
02162     case KWCanvas::MM_CREATE_PART:
02163         // No tool to activate for this mode -> deselect all the others
02164         m_actionToolsCreateText->setChecked( false );
02165         m_actionToolsCreatePix->setChecked( false );
02166         //m_actionToolsCreatePart->setChecked( false );
02167         break;
02168     case KWCanvas::MM_CREATE_TEXT:
02169         m_actionToolsCreateText->setChecked( true );
02170         break;
02171     case KWCanvas::MM_CREATE_PIX:
02172         m_actionToolsCreatePix->setChecked( true );
02173         break;
02174         //case KWCanvas::MM_CREATE_PART:
02175         //m_actionToolsCreatePart->setChecked( true );
02176         break;
02177     }
02178 
02179     m_actionTableJoinCells->setEnabled( FALSE );
02180     m_actionTableSplitCells->setEnabled( FALSE );
02181     m_actionTableProtectCells->setEnabled( false );
02182     m_actionFormatFrameSet->setEnabled(FALSE);
02183     m_actionTablePropertiesMenu->setEnabled( false );
02184     m_actionConvertTableToText->setEnabled( false );
02185 }
02186 
02187 void KWView::showStyle( const QString & styleName )
02188 {
02189     KoParagStyle* style = m_doc->styleCollection()->findStyle( styleName );
02190     if ( style ) {
02191         int pos = m_doc->styleCollection()->indexOf( style );
02192         // Select style in combo
02193         m_actionFormatStyle->setCurrentItem( pos );
02194         // Check the appropriate action among the m_actionFormatStyleMenu actions
02195         KToggleAction* act = dynamic_cast<KToggleAction *>(actionCollection()->action(style->name().utf8()));
02196         if ( act )
02197             act->setChecked( true );
02198     }
02199 }
02200 
02201 // used to avoid action naming conflicts
02202 static const char* PARAGSTYLE_ACTION_PREFIX = "paragstyle_";
02203 static const char* FRAMESTYLE_ACTION_PREFIX = "framestyle_";
02204 static const char* TABLESTYLE_ACTION_PREFIX = "tablestyle_";
02205 
02206 void KWView::updateStyleList()
02207 {
02208     QString currentStyle = m_actionFormatStyle->currentText();
02209     // Generate list of styles
02210     const QStringList lst = m_doc->styleCollection()->displayNameList();
02211     const int pos = lst.findIndex( currentStyle );
02212     // Fill the combo - using a KSelectAction
02213     m_actionFormatStyle->setItems( lst );
02214     if ( pos > -1 )
02215         m_actionFormatStyle->setCurrentItem( pos );
02216 
02217     // Fill the menu - using a KActionMenu, so that it's possible to bind keys
02218     // to individual actions
02219     QStringList lstWithAccels;
02220     // Generate unique accelerators for the menu items
02221     KAccelGen::generate( lst, lstWithAccels );
02222     QMap<QString, KShortcut> shortCuts;
02223 
02224     KActionPtrList lst2 = actionCollection()->actions("styleList");
02225     QValueList<KAction *> actions = lst2;
02226     QValueList<KAction *>::ConstIterator it = lst2.begin();
02227     const QValueList<KAction *>::ConstIterator end = lst2.end();
02228     for (; it != end; ++it )
02229     {
02230         shortCuts.insert( QString::fromUtf8( (*it)->name() ), (*it)->shortcut() );
02231         m_actionFormatStyleMenu->remove( *it );
02232         delete *it;
02233     }
02234     uint i = 0;
02235     for ( QStringList::Iterator it = lstWithAccels.begin(); it != lstWithAccels.end(); ++it, ++i )
02236     {
02237         // The list lst was created (unsorted) from the style collection, so we have still the same order.
02238         KoParagStyle *style = m_doc->styleCollection()->styleAt( i );
02239         if ( style )
02240         {
02241             QString name = PARAGSTYLE_ACTION_PREFIX + style->name();
02242             KToggleAction* act = new KToggleAction( (*it),
02243                                      shortCuts[name], this, SLOT( slotStyleSelected() ),
02244                                      actionCollection(), name.utf8() );
02245             act->setGroup( "styleList" );
02246             act->setExclusiveGroup( "styleListAction" );
02247             act->setToolTip( i18n( "Apply a paragraph style" ) );
02248             m_actionFormatStyleMenu->insert( act );
02249         }
02250         else
02251             kdWarning() << "No style found for " << *it << endl;
02252     }
02253 }
02254 
02255 // Called when selecting a style in the Format / Style menu
02256 void KWView::slotStyleSelected()
02257 {
02258     QString actionName = QString::fromUtf8(sender()->name());
02259     const QString prefix = PARAGSTYLE_ACTION_PREFIX;
02260     if ( actionName.startsWith( prefix ) ) {
02261         actionName = actionName.mid( prefix.length() );
02262         kdDebug(32001) << "KWView::slotStyleSelected " << actionName << endl;
02263         textStyleSelected( m_doc->styleCollection()->findStyle( actionName ) );
02264     }
02265 }
02266 
02267 void KWView::updateFrameStyleList()
02268 {
02269     // Remember selected style (by name; better would be by pointer, but what if it got deleted?)
02270     // This is all in case the index of the selected style has changed.
02271     const QString currentStyle = m_actionFrameStyle->currentText();
02272     // Generate list of styles
02273     const QStringList lst = m_doc->frameStyleCollection()->displayNameList();
02274     const int pos = lst.findIndex( currentStyle );
02275     // Fill the combo
02276     m_actionFrameStyle->setItems( lst );
02277     if ( pos > -1 )
02278         m_actionFrameStyle->setCurrentItem( pos );
02279 
02280     // Fill the menu - using a KActionMenu, so that it's possible to bind keys
02281     // to individual actions
02282     QStringList lstWithAccels;
02283     // Generate unique accelerators for the menu items
02284     KAccelGen::generate( lst, lstWithAccels );
02285     QMap<QString, KShortcut> shortCuts; // style (internal) name -> shortcut
02286 
02287 
02288     KActionPtrList lst2 = actionCollection()->actions("frameStyleList");
02289     QValueList<KAction *> actions = lst2;
02290     QValueList<KAction *>::ConstIterator it = lst2.begin();
02291     QValueList<KAction *>::ConstIterator end = lst2.end();
02292     for (; it != end; ++it )
02293     {
02294         shortCuts.insert( QString::fromUtf8( (*it)->name() ), (*it)->shortcut() );
02295         m_actionFrameStyleMenu->remove( *it );
02296         delete *it;
02297     }
02298 
02299     uint i = 0;
02300     for ( QStringList::Iterator it = lstWithAccels.begin(); it != lstWithAccels.end(); ++it, ++i )
02301     {
02302         // The list lst was created (unsorted) from the frame style collection, so we have still the same order.
02303         KWFrameStyle *style = m_doc->frameStyleCollection()->frameStyleAt( i );
02304         if ( style )
02305         {
02306             QString name = FRAMESTYLE_ACTION_PREFIX + style->name();
02307             KToggleAction* act = new KToggleAction( (*it),
02308                                                     shortCuts[name], // KDE4: use value()
02309                                                     this, SLOT( slotFrameStyleSelected() ),
02310                                                     actionCollection(), name.utf8() /*KDE4: remove conversion*/ );
02311             act->setGroup( "frameStyleList" );
02312             act->setExclusiveGroup( "frameStyleList" );
02313             act->setToolTip( i18n( "Apply a frame style" ) );
02314             m_actionFrameStyleMenu->insert( act );
02315         }
02316         else
02317             kdWarning() << "No frame style found for " << *it << endl;
02318     }
02319 }
02320 
02321 
02322 void KWView::updateTableStyleList()
02323 {
02324     const QString currentStyle = m_actionTableStyle->currentText();
02325     // Generate list of styles
02326     const QStringList lst = m_doc->tableStyleCollection()->displayNameList();
02327     const int pos = lst.findIndex( currentStyle );
02328     // Fill the combo
02329     m_actionTableStyle->setItems( lst );
02330     if ( pos > -1 )
02331         m_actionTableStyle->setCurrentItem( pos );
02332 
02333     // Fill the menu - using a KActionMenu, so that it's possible to bind keys
02334     // to individual actions
02335     QStringList lstWithAccels;
02336     // Generate unique accelerators for the menu items
02337     KAccelGen::generate( lst, lstWithAccels );
02338     QMap<QString, KShortcut> shortCuts;
02339 
02340     QValueList<KAction *> actions = actionCollection()->actions("tableStyleList");
02341     QValueList<KAction *>::ConstIterator it = actions.begin();
02342     const QValueList<KAction *>::ConstIterator end = actions.end();
02343     for (; it != end; ++it )
02344     {
02345         shortCuts.insert( QString::fromUtf8( (*it)->name() ), (*it)->shortcut() );
02346         m_actionTableStyleMenu->remove( *it );
02347         delete *it;
02348     }
02349 
02350     uint i = 0;
02351     for ( QStringList::Iterator it = lstWithAccels.begin(); it != lstWithAccels.end(); ++it, ++i )
02352     {
02353         // The list lst was created (unsorted) from the table style collection, so we have still the same order.
02354         KWTableStyle *style = m_doc->tableStyleCollection()->tableStyleAt( i );
02355         if ( style )
02356         {
02357             QString name = TABLESTYLE_ACTION_PREFIX + style->name();
02358             KToggleAction* act = new KToggleAction( (*it),
02359                                      shortCuts[name], this, SLOT( slotTableStyleSelected() ),
02360                                      actionCollection(), name.utf8() );
02361             act->setExclusiveGroup( "tableStyleList" );
02362             act->setGroup( "tableStyleList" );
02363             act->setToolTip( i18n( "Apply a table style" ) );
02364             m_actionTableStyleMenu->insert( act );
02365         }
02366         else
02367             kdWarning() << "No table style found for " << *it << endl;
02368     }
02369 }
02370 
02371 void KWView::editCut()
02372 {
02373     KWFrameSetEdit * edit = currentTextEdit();
02374     if ( edit )
02375         edit->cut();
02376     else {
02377         QDragObject *drag = m_doc->dragSelected( frameViewManager()->selectedFrames() );
02378         QApplication::clipboard()->setData( drag );
02379         deleteFrame(false);
02380     }
02381 }
02382 
02383 void KWView::editCopy()
02384 {
02385     KWTextFrameSetEdit * edit = currentTextEdit();
02386     if ( edit )
02387         edit->copy();
02388     else {
02389         QDragObject *drag = m_doc->dragSelected( frameViewManager()->selectedFrames() );
02390         QApplication::clipboard()->setData( drag );
02391     }
02392 }
02393 
02394 void KWView::editPaste()
02395 {
02396     QMimeSource *data = QApplication::clipboard()->data();
02397     pasteData( data, false );
02398 }
02399 
02400 // paste or drop
02401 void KWView::pasteData( QMimeSource* data, bool drop )
02402 {
02403     int provides = checkClipboard( data );
02404     Q_ASSERT( provides != 0 );
02405 
02406     // formula must be the first as a formula is also available as image
02407     if ( provides & ProvidesFormula ) {
02408         KWFrameSetEdit * edit = m_gui->canvasWidget()->currentFrameSetEdit();
02409         if ( edit && edit->frameSet()->type() == FT_FORMULA ) {
02410             edit->pasteData( data, ProvidesFormula, drop );
02411         }
02412         else {
02413             insertFormula( data );
02414         }
02415     }
02416     else // pasting text and/or frames
02417     {
02418         deselectAllFrames();
02419         // let the user select paste format if the clipboard contains an image URL
02420         if ( (provides & ProvidesImage) && (provides & ProvidesPlainText) && !( provides & ProvidesOasis ) )
02421         {
02422             QStringList list;
02423             list.append( i18n("Image") );
02424             list.append( i18n("Plain text") );
02425             bool ok;
02426             QString result = KInputDialog::getItem( i18n("Paste"), i18n("Select paste format:"), list, 0, false, &ok );
02427             if (!ok)
02428                 return;
02429             if ( result == list.first() )
02430             {
02431                 provides = ProvidesImage;
02432                 data = QApplication::clipboard()->data();
02433             }
02434         }
02435         KWTextFrameSetEdit * edit = currentTextEdit();
02436         if ( edit && ( provides & ProvidesPlainText ) ) {
02437             edit->pasteData( data, provides, drop );
02438         } else if ( provides & ProvidesOasis ) {
02439             // Not editing a frameset? We can't paste plain text then... only entire frames.
02440             QCString returnedTypeMime = KoTextObject::providesOasis( data );
02441             if ( !returnedTypeMime.isEmpty() )
02442             {
02443                 const QByteArray arr = data->encodedData( returnedTypeMime );
02444                 if( !arr.isEmpty() )
02445                 {
02446                     QBuffer buffer( arr );
02447                     KoStore * store = KoStore::createStore( &buffer, KoStore::Read );
02448                     KWOasisLoader oasisLoader( m_doc );
02449                     QValueList<KWFrame *> frames = oasisLoader.insertOasisData( store, 0 /* no cursor */ );
02450                     delete store;
02451                     QValueList<KWFrame *>::ConstIterator it = frames.begin();
02452                     KMacroCommand* macroCmd = 0L;
02453                     for ( ; it != frames.end() ; ++it )
02454                     {
02455                         if ( !macroCmd )
02456                             macroCmd = new KMacroCommand( i18n( "Paste" ) );
02457 
02458                         KWCreateFrameCommand *cmd = new KWCreateFrameCommand( i18n( "Paste" ), *it );
02459                         macroCmd->addCommand( cmd );
02460 
02461                         frameViewManager()->view(*it)->setSelected(true);
02462                         (*it)->frameSet()->updateFrames();
02463                     }
02464 
02465                     if ( macroCmd ) {
02466                         m_doc->addCommand( macroCmd );
02467                         KWFrameList::recalcAllFrames(m_doc);
02468                         return;
02469                     }
02470                 }
02471             }
02472         }
02473         if ( provides & ProvidesImage )
02474         { // providesImage, must be after providesOasis
02475             KoPoint docPoint( m_currentPage->leftMargin(),
02476                     m_currentPage->offsetInDocument() + m_currentPage->topMargin());
02477             m_gui->canvasWidget()->pasteImage( data, docPoint );
02478         }
02479     }
02480 }
02481 
02482 void KWView::editSelectAll()
02483 {
02484     KWFrameSetEdit * edit = m_gui->canvasWidget()->currentFrameSetEdit();
02485     if ( edit )
02486         edit->selectAll();
02487 }
02488 
02489 void KWView::editSelectAllFrames()
02490 {
02491     m_gui->canvasWidget()->selectAllFrames( true );
02492 }
02493 
02494 void KWView::editSelectCurrentFrame()
02495 {
02496     if (!m_gui) return;
02497     KWFrameSetEdit* edit = m_gui->canvasWidget()->currentFrameSetEdit();
02498     KWFrame* frame = edit->currentFrame();
02499     if (!frame) return;
02500     KWFrameView *view = frameViewManager()->view(frame);
02501     if (!view) return;
02502     view->setSelected(true);
02503 }
02504 
02505 void KWView::editFind()
02506 {
02507     if (!m_searchEntry)
02508         m_searchEntry = new KoSearchContext();
02509     KWTextFrameSetEdit * edit = currentTextEdit();
02510     bool hasSelection = edit && edit->textFrameSet()->hasSelection();
02511     bool hasCursor = edit != 0L;
02512 
02513     KoSearchDia dialog( m_gui->canvasWidget(), "find", m_searchEntry, hasSelection, hasCursor );
02514     if ( dialog.exec() == QDialog::Accepted )
02515     {
02516         delete m_findReplace;
02517         m_findReplace = new KWFindReplace( m_gui->canvasWidget(), &dialog, m_gui->canvasWidget()->kWordDocument()->visibleTextObjects(viewMode()), edit);
02518         editFindNext();
02519     }
02520 }
02521 
02522 void KWView::editReplace()
02523 {
02524     if (!m_searchEntry)
02525         m_searchEntry = new KoSearchContext();
02526     if (!m_replaceEntry)
02527         m_replaceEntry = new KoSearchContext();
02528 
02529     KWTextFrameSetEdit * edit = currentTextEdit();
02530     bool hasSelection = edit && edit->textFrameSet()->hasSelection();
02531     bool hasCursor = edit != 0L;
02532 
02533     KoReplaceDia dialog( m_gui->canvasWidget(), "replace", m_searchEntry, m_replaceEntry, hasSelection, hasCursor );
02534     if ( dialog.exec() == QDialog::Accepted )
02535     {
02536         delete m_findReplace;
02537         m_findReplace = new KWFindReplace( m_gui->canvasWidget(), &dialog, m_gui->canvasWidget()->kWordDocument()->visibleTextObjects(viewMode()), edit);
02538         editFindNext();
02539     }
02540 }
02541 
02542 void KWView::editFindNext()
02543 {
02544     if ( !m_findReplace ) // shouldn't be called before find or replace is activated
02545     {
02546         editFind();
02547         return;
02548     }
02549     (void) m_findReplace->findNext();
02550 }
02551 
02552 void KWView::editFindPrevious()
02553 {
02554     if ( !m_findReplace ) // shouldn't be called before find or replace is activated
02555     {
02556         editFind();
02557         return;
02558     }
02559     (void) m_findReplace->findPrevious();
02560 }
02561 
02562 void KWView::adjustZOrderOfSelectedFrames(MoveFrameType moveType) {
02563     KMacroCommand* macroCmd = 0L;
02564     // For each selected frame...
02565     QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
02566     if(selectedFrames.count()==0) return;
02567 
02568     KWPage *page = m_doc->pageManager()->page(selectedFrames[0]->frame());
02569     QPtrList<KWFrame> frames;
02570     QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
02571     while(framesIterator != selectedFrames.end()) {
02572         // include all frames in case of table.
02573         frames.append((*framesIterator)->frame());
02574         KWFrameSet *table = (*framesIterator)->frame()->frameSet()->groupmanager();
02575         if(table) {
02576             for (QPtrListIterator<KWFrame> cellIt(table->frameIterator()  ); cellIt.current() ; ++cellIt ) {
02577                 KWFrame *frame = cellIt.current();
02578                 if(page->rect().contains(*frame) && !frames.contains(frame))
02579                     frames.append(frame);
02580             }
02581         }
02582         ++framesIterator;
02583     }
02584 
02585     int lowestZOrder=10000;
02586     QString actionName;
02587     framesIterator = selectedFrames.begin();
02588     while(framesIterator != selectedFrames.end()) {
02589         KWFrame* frame = (*framesIterator)->frame();
02590         int newZOrder=0;
02591         switch(moveType) {
02592             case RaiseFrame:
02593                 newZOrder=raiseFrame(frames,frame);
02594                 actionName=i18n("Raise Frame");
02595                 break;
02596             case LowerFrame:
02597                 newZOrder=lowerFrame(frames,frame);
02598                 actionName=i18n("Lower Frame");
02599                 break;
02600             case BringToFront:
02601                 newZOrder=bringToFront(frames,frame);
02602                 actionName=i18n("Bring to Front");
02603                 break;
02604             case SendToBack:
02605                 newZOrder=sendToBack(frames,frame);
02606                 actionName=i18n("Send to Back");
02607                 break;
02608         }
02609 
02610         if ( newZOrder != frame->zOrder() ) { // only if changed.
02611             lowestZOrder=QMIN(lowestZOrder, newZOrder);
02612 
02613             KWFrame* frameCopy = frame->getCopy();
02614             frame->setZOrder( newZOrder );
02615             frame->frameStack()->update();
02616 
02617             KWFramePropertiesCommand* cmd = new KWFramePropertiesCommand( QString::null, frameCopy, frame);
02618             if(!macroCmd)
02619                 macroCmd = new KMacroCommand( actionName );
02620             macroCmd->addCommand(cmd);
02621 
02622             frameCopy = frame->getCopy();
02623             frame->setZOrder( newZOrder );
02624 
02625             cmd = new KWFramePropertiesCommand( QString::null, frameCopy, frame );
02626             if(!macroCmd)
02627                 macroCmd = new KMacroCommand( actionName );
02628             macroCmd->addCommand(cmd);
02629         }
02630         ++framesIterator;
02631     }
02632 
02633     if ( macroCmd )
02634     {
02635         m_doc->addCommand(macroCmd);
02636         // Calling updateFrames() on the selected frames' framesets isn't enough,
02637         // we also need other framesets to notice the new frames on top.
02638         m_doc->updateAllFrames();
02639         m_doc->layout();
02640         m_doc->repaintAllViews();
02641     }
02642 
02643     if(lowestZOrder != 10000 && m_doc->processingType() == KWDocument::WP) {
02644         m_doc->lowerMainFrames( page->pageNumber(), lowestZOrder );
02645     }
02646 }
02647 
02648 // Make room for refZOrder, by raising all z-orders above it by 1
02649 void KWView::increaseAllZOrdersAbove(int refZOrder, int pageNum, const QPtrList<KWFrame>& frameSelection) {
02650     QPtrList<KWFrame> framesInPage = m_doc->framesInPage( pageNum, false );
02651     for ( QPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
02652         if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore frames we selected.
02653         if(frameIt.current()->zOrder() >= refZOrder) {
02654             frameIt.current()->setZOrder( frameIt.current()->zOrder() + 1 );
02655         }
02656     }
02657 }
02658 
02659 // Make room for refZOrder, by lowering all z-orders below it by 1
02660 void KWView::decreaseAllZOrdersUnder(int refZOrder, int pageNum, const QPtrList<KWFrame>& frameSelection) {
02661     QPtrList<KWFrame> framesInPage = m_doc->framesInPage( pageNum, false );
02662     for ( QPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
02663         if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore frames we selected.
02664         if(frameIt.current()->zOrder() <= refZOrder) {
02665             frameIt.current()->setZOrder( frameIt.current()->zOrder() - 1 );
02666         }
02667     }
02668 }
02669 
02670 int KWView::raiseFrame(const QPtrList<KWFrame>& frameSelection, const KWFrame *frame) {
02671     int newZOrder = 10000;
02672     QValueList<int> zorders;
02673     QPtrList<KWFrame> framesInPage = m_doc->framesInPage( frame->pageNumber(), false );
02674     for ( QPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
02675         if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore other frames we selected.
02676         if(! frameIt.current()->intersects(*frame)) continue; // only frames that I intersect with.
02677         int z = frameIt.current()->zOrder();
02678         if(z > frame->zOrder()) {
02679             newZOrder=QMIN(newZOrder, z + 1);
02680         }
02681         zorders.append( z );
02682     }
02683     if(newZOrder==10000) return frame->zOrder();
02684     // Ensure that newZOrder is "free"
02685     if ( zorders.find( newZOrder ) != zorders.end() )
02686         increaseAllZOrdersAbove( newZOrder, frame->pageNumber(), frameSelection );
02687     return newZOrder;
02688 }
02689 
02690 int KWView::lowerFrame(const QPtrList<KWFrame>& frameSelection, const KWFrame *frame) {
02691     int newZOrder = -10000;
02692     QValueList<int> zorders;
02693     QPtrList<KWFrame> framesInPage = m_doc->framesInPage( frame->pageNumber(), false );
02694     for ( QPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
02695         if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore other frames we selected.
02696         if(frameIt.current()->frameSet()->isMainFrameset()) continue; // ignore main frameset.
02697         if(! frameIt.current()->intersects(*frame)) continue; // only frames that I intersect with.
02698         int z = frameIt.current()->zOrder();
02699         if(z < frame->zOrder()) {
02700             newZOrder=QMAX(newZOrder, z -1);
02701         }
02702         zorders.append( z );
02703     }
02704     if(newZOrder==-10000) return frame->zOrder();
02705     // Ensure that newZOrder is "free"
02706     if ( zorders.find( newZOrder ) != zorders.end() )
02707         decreaseAllZOrdersUnder( newZOrder, frame->pageNumber(), frameSelection );
02708     return newZOrder;
02709 }
02710 
02711 int KWView::bringToFront(const QPtrList<KWFrame>& frameSelection, const KWFrame *frame) {
02712     int newZOrder = frame->zOrder();
02713     QPtrList<KWFrame> framesInPage = m_doc->framesInPage( frame->pageNumber(), false );
02714     for ( QPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
02715         if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore other frames we selected.
02716         if(! frameIt.current()->intersects(*frame)) continue; // only frames that I intersect with.
02717         newZOrder=QMAX(newZOrder, frameIt.current()->zOrder()+1);
02718     }
02719     return newZOrder;
02720 }
02721 
02722 int KWView::sendToBack(const QPtrList<KWFrame>& frameSelection, const KWFrame *frame) {
02723     int newZOrder = frame->zOrder();
02724     QPtrList<KWFrame> framesInPage = m_doc->framesInPage( frame->pageNumber(), false );
02725     for ( QPtrListIterator<KWFrame> frameIt( framesInPage ); frameIt.current(); ++frameIt ) {
02726         if(frameSelection.contains(frameIt.current()) > 0) continue; // ignore other frames we selected.
02727         if(frameIt.current()->frameSet()->isMainFrameset()) continue; // ignore main frameset.
02728         if(! frameIt.current()->intersects(*frame)) continue; // only frames that I intersect with.
02729         newZOrder=QMIN(newZOrder, frameIt.current()->zOrder()-1);
02730     }
02731     return newZOrder;
02732 }
02733 
02734 void KWView::editDeleteFrame()
02735 {
02736     deleteFrame();
02737 }
02738 
02739 void KWView::deleteFrame( bool warning )
02740 {
02741     if ( !m_doc->isReadWrite() )
02742         return;
02743 
02744     QValueList<KWFrameView*> frames = frameViewManager()->selectedFrames();
02745     if( frames.count() < 1) {
02746         kdWarning() << "KWView::deleteFrame: no frame selected" << endl;
02747         return;
02748     }
02749     if(frames.count()==1)
02750     {
02751         KWFrame *theFrame = frames[0]->frame();
02752         KWFrameSet *fs = theFrame->frameSet();
02753 
02754         Q_ASSERT( !fs->isAHeader() ); // the action is disabled for such cases
02755         Q_ASSERT( !fs->isAFooter() );
02756         if ( fs->isMainFrameset() || fs->isAFooter() || fs->isAHeader() || fs->isFootEndNote())
02757             return;
02758 
02759         // frame is part of a table?
02760         if ( fs->groupmanager() )
02761         {
02762             int result = KMessageBox::warningContinueCancel(
02763                 this,
02764                 i18n( "You are about to delete a table.\n"
02765                       "Doing so will delete all the text in the table.\n"
02766                       "Are you sure you want to do that?"),
02767                 i18n("Delete Table"), KStdGuiItem::del(),
02768                 "DeleteTableConfirmation",
02769                 true );
02770             if (result != KMessageBox::Continue)
02771                 return;
02772             m_doc->deleteTable( fs->groupmanager() );
02773             return;
02774         }
02775 
02776         if ( fs->frameCount() == 1 && fs->type() == FT_TEXT) {
02777             if ( fs->isMainFrameset())
02778                 return; // if primairy FS, we can't delete it :)
02779 
02780             KWTextFrameSet * textfs = dynamic_cast<KWTextFrameSet *>(fs);
02781             Q_ASSERT(textfs);
02782             if ( !textfs )
02783                 return;
02784 
02785             KoTextDocument * textdoc = textfs->textDocument();
02786             if ( textdoc->length() > 0 )
02787             {
02788                 int result = KMessageBox::warningContinueCancel(
02789                     this,
02790                     i18n( "You are about to delete the last Frame of the "
02791                           "Frameset '%1'. "
02792                           "The contents of this Frameset will not appear "
02793                           "anymore!\n"
02794                           "Are you sure you want to do that?").arg(fs->name()),
02795                     i18n("Delete Frame"), KStdGuiItem::del());
02796 
02797                 if (result != KMessageBox::Continue)
02798                     return;
02799 
02800                 m_doc->deleteFrame( theFrame );
02801                 return;
02802             }
02803 
02804         }
02805 
02806         if(warning)
02807         {
02808             int result = KMessageBox::warningContinueCancel(
02809                 this,
02810                 i18n("Do you want to delete this frame?"),
02811                 i18n("Delete Frame"),
02812                 KGuiItem(i18n("&Delete"),"editdelete"),
02813                 "DeleteLastFrameConfirmation",
02814                 true );
02815             if (result != KMessageBox::Continue)
02816                 return;
02817         }
02818         m_doc->deleteFrame( theFrame );
02819     }
02820     else
02821     {
02822         //several frame
02823         if(warning)
02824         {
02825             int result = KMessageBox::warningContinueCancel(
02826                 this,
02827                 i18n("Do you want to delete this frame?"),
02828                 i18n("Delete Frame"),
02829                 KGuiItem(i18n("&Delete"),"editdelete"),
02830                 "DeleteLastFrameConfirmation",
02831                 true );
02832             if (result != KMessageBox::Continue)
02833                 return;
02834         }
02835 
02836         deleteSelectedFrames();
02837     }
02838 }
02839 
02840 void KWView::createLinkedFrame()
02841 {
02842     QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
02843     if (selectedFrames.count() != 1)
02844         return; // action is disabled in such a case
02845     KWFrame* frame = selectedFrames[0]->frame();
02846     KWFrame* newFrame = new KWFrame(0L, frame->x() + m_gui->getVertRuler()->minimumSizeHint().width(), frame->y() + m_gui->getHorzRuler()->minimumSizeHint().height(), frame->width(), frame->height() );
02847     newFrame->setZOrder( m_doc->maxZOrder( newFrame->pageNumber(m_doc) ) + 1 ); // make sure it's on top
02848     newFrame->setCopy(true);
02849     newFrame->setNewFrameBehavior( KWFrame::Copy );
02850     frame->frameSet()->addFrame( newFrame );
02851 
02852     frameViewManager()->view(newFrame)->setSelected(true);
02853 
02854     KWCreateFrameCommand *cmd = new KWCreateFrameCommand( i18n("Create Linked Copy"), newFrame );
02855     m_doc->addCommand( cmd );
02856 
02857     m_doc->frameChanged( newFrame );
02858 }
02859 
02860 void KWView::editCustomVariable()
02861 {
02862     KWTextFrameSetEdit * edit = currentTextEdit();
02863     if (edit)
02864     {
02865         KoCustomVariable *var = static_cast<KoCustomVariable *>(edit->variable());
02866         if (var)
02867         {
02868             QString oldvalue = var->value();
02869             KoCustomVarDialog dia( this, var );
02870             if ( dia.exec() )
02871             {
02872                 m_doc->recalcVariables( VT_CUSTOM );
02873                 if( var->value() != oldvalue )
02874                 {
02875                     KWChangeCustomVariableValue *cmd=new KWChangeCustomVariableValue(i18n( "Change Custom Variable" ),m_doc, oldvalue, var->value(), var );
02876                     m_doc->addCommand(cmd);
02877                 }
02878             }
02879         }
02880     }
02881 }
02882 
02883 void KWView::editCustomVars()
02884 {
02885     KoCustomVariablesDia dia( this, m_doc->variableCollection()->getVariables() );
02886     QStringList listOldCustomValue;
02887     QPtrListIterator<KoVariable> oldIt( m_doc->variableCollection()->getVariables() );
02888     for ( ; oldIt.current() ; ++oldIt )
02889     {
02890         if(oldIt.current()->type()==VT_CUSTOM)
02891             listOldCustomValue.append(((KoCustomVariable*)oldIt.current())->value());
02892     }
02893     if(dia.exec())
02894     {
02895         m_doc->recalcVariables( VT_CUSTOM );
02896         //temporaly hack, for the moment we can't undo/redo change custom variables
02897         QPtrListIterator<KoVariable> it( m_doc->variableCollection()->getVariables() );
02898         KMacroCommand * macroCommand = 0L;
02899         int i=0;
02900         for ( ; it.current() ; ++it )
02901         {
02902             if(it.current()->type() == VT_CUSTOM )
02903             {
02904                 if(((KoCustomVariable*)it.current())->value()!=*(listOldCustomValue.at(i)))
02905                 {
02906                     if(!macroCommand)
02907                         macroCommand = new KMacroCommand( i18n( "Change Custom Variable" ) );
02908                     KWChangeCustomVariableValue *cmd=new KWChangeCustomVariableValue(i18n( "Change Custom Variable" ),m_doc,*(listOldCustomValue.at(i)), ((KoCustomVariable*)it.current())->value() ,((KoCustomVariable*)it.current()));
02909                     macroCommand->addCommand(cmd);
02910                 }
02911                 i++;
02912             }
02913         }
02914         if(macroCommand)
02915             m_doc->addCommand(macroCommand);
02916     }
02917 }
02918 
02919 void KWView::editMailMergeDataBase()
02920 {
02921     m_doc->mailMergeDataBase()->showConfigDialog(this);
02922 #if 0
02923     KWMailMergeEditor *dia = new KWMailMergeEditor( this, m_doc->mailMergeDataBase() );
02924     dia->exec();
02925     // Don't know if we really need this so it's commented out (SL)
02926     // m_gui->canvasWidget()->repaintAll( FALSE );
02927     delete dia;
02928 #endif
02929 }
02930 
02931 void KWView::viewTextMode()
02932 {
02933     if ( m_actionViewTextMode->isChecked() )
02934     {
02935         KWTextFrameSet* fs = KWViewModeText::determineTextFrameSet( m_doc );
02936         if ( fs ) { // TODO: disable the action when there is no text frameset available
02937             if ( dynamic_cast<KWViewModePreview *>(viewMode()) )
02938             {
02939                 m_zoomViewModePreview.m_zoom = m_doc->zoom();
02940                 m_zoomViewModePreview.m_zoomMode = m_doc->zoomMode();
02941             }
02942             else
02943             {
02944                 m_zoomViewModeNormal.m_zoom = m_doc->zoom();
02945                 m_zoomViewModeNormal.m_zoomMode = m_doc->zoomMode();
02946             }
02947             // we don't know ZOOM_PAGE in the new view. so
02948             // we use ZOOM_CONSTANT in that case
02949             switch(m_zoomViewModeNormal.m_zoomMode)
02950             {
02951                 case KoZoomMode::ZOOM_WIDTH:
02952                     m_doc->setZoomMode(KoZoomMode::ZOOM_WIDTH);
02953                     QTimer::singleShot( 0, this, SLOT( updateZoom() ) );
02954                     break;
02955                 case KoZoomMode::ZOOM_PAGE: // no break
02956                     m_zoomViewModeNormal.m_zoomMode = KoZoomMode::ZOOM_CONSTANT;
02957                 case KoZoomMode::ZOOM_CONSTANT:
02958                     m_doc->setZoomMode(KoZoomMode::ZOOM_CONSTANT);
02959                     showZoom( m_zoomViewModeNormal.m_zoom );
02960                     setZoom( m_zoomViewModeNormal.m_zoom, false );
02961                     break;
02962             }
02963             m_doc->switchViewMode( "ModeText" );
02964         } else
02965             initGUIButton(); // ensure we show the current viewmode
02966     }
02967     else
02968         m_actionViewTextMode->setChecked( true ); // always one has to be checked !
02969 }
02970 
02971 void KWView::viewPageMode()
02972 {
02973     if ( m_actionViewPageMode->isChecked() )
02974     {
02975         if ( dynamic_cast<KWViewModePreview *>(viewMode()) )
02976         {
02977             m_zoomViewModePreview.m_zoom = m_doc->zoom();
02978             m_zoomViewModePreview.m_zoomMode = m_doc->zoomMode();
02979         }
02980         else
02981         {
02982             m_zoomViewModeNormal.m_zoom = m_doc->zoom();
02983             m_zoomViewModeNormal.m_zoomMode = m_doc->zoomMode();
02984         }
02985         switch(m_zoomViewModeNormal.m_zoomMode)
02986         {
02987             case KoZoomMode::ZOOM_WIDTH:
02988                 m_doc->setZoomMode(KoZoomMode::ZOOM_WIDTH);
02989                 QTimer::singleShot( 0, this, SLOT( updateZoom() ) );
02990                 break;
02991             case KoZoomMode::ZOOM_PAGE:
02992                 m_doc->setZoomMode(KoZoomMode::ZOOM_PAGE);
02993                 QTimer::singleShot( 0, this, SLOT( updateZoom() ) );
02994                 break;
02995             case KoZoomMode::ZOOM_CONSTANT:
02996                 m_doc->setZoomMode(KoZoomMode::ZOOM_CONSTANT);
02997                 showZoom( m_zoomViewModeNormal.m_zoom );
02998                 setZoom( m_zoomViewModeNormal.m_zoom, false );
02999                 break;
03000         }
03001         m_doc->switchViewMode( "ModeNormal" );
03002     }
03003     else
03004         m_actionViewPageMode->setChecked( true ); // always one has to be checked !
03005 }
03006 
03007 void KWView::viewPreviewMode()
03008 {
03009     if ( m_actionViewPreviewMode->isChecked() )
03010     {
03011         m_zoomViewModeNormal.m_zoom = m_doc->zoom();
03012         m_zoomViewModeNormal.m_zoomMode = m_doc->zoomMode();
03013         switch(m_zoomViewModePreview.m_zoomMode)
03014         {
03015             case KoZoomMode::ZOOM_WIDTH:
03016                 m_doc->setZoomMode(KoZoomMode::ZOOM_WIDTH);
03017                 QTimer::singleShot( 0, this, SLOT( updateZoom() ) );
03018                 break;
03019             case KoZoomMode::ZOOM_PAGE:
03020                 m_doc->setZoomMode(KoZoomMode::ZOOM_PAGE);
03021                 QTimer::singleShot( 0, this, SLOT( updateZoom() ) );
03022                 break;
03023             case KoZoomMode::ZOOM_CONSTANT:
03024                 m_doc->setZoomMode(KoZoomMode::ZOOM_CONSTANT);
03025                 showZoom( m_zoomViewModePreview.m_zoom );
03026                 setZoom( m_zoomViewModePreview.m_zoom, false );
03027                 break;
03028         }
03029         m_doc->switchViewMode( "ModePreview" );
03030     }
03031     else
03032         m_actionViewPreviewMode->setChecked( true ); // always one has to be checked !
03033 }
03034 
03035 void KWView::updateZoomControls()
03036 {
03037     switch(m_doc->zoomMode())
03038     {
03039         case KoZoomMode::ZOOM_WIDTH:
03040         case KoZoomMode::ZOOM_PAGE:
03041             showZoom( KoZoomMode::toString(m_doc->zoomMode()) );
03042             break;
03043         case KoZoomMode::ZOOM_CONSTANT:
03044             changeZoomMenu( m_doc->zoom() );
03045             showZoom( m_doc->zoom() );
03046             break;
03047     }
03048 }
03049 
03050 void KWView::changeZoomMenu( int zoom )
03051 {
03052     QString mode;
03053     if ( m_gui && m_gui->canvasWidget() && viewMode())
03054         mode = viewMode()->type();
03055 
03056     QStringList lst;
03057     lst << KoZoomMode::toString(KoZoomMode::ZOOM_WIDTH);
03058     if ( mode!="ModeText" )
03059         lst << KoZoomMode::toString(KoZoomMode::ZOOM_PAGE);
03060 
03061     if(zoom>0)
03062     {
03063         QValueList<int> list;
03064         bool ok;
03065         const QStringList itemsList ( m_actionViewZoom->items() );
03066         QRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
03067 
03068         for (QStringList::ConstIterator it = itemsList.begin() ; it != itemsList.end() ; ++it)
03069         {
03070             regexp.search(*it);
03071             const int val=regexp.cap(1).toInt(&ok);
03072             //zoom : limit inferior=10
03073             if(ok && val>9 && list.contains(val)==0)
03074                 list.append( val );
03075         }
03076         //necessary at the beginning when we read config
03077         //this value is not in combo list
03078         if(list.contains(zoom)==0)
03079             list.append( zoom );
03080 
03081         qHeapSort( list );
03082 
03083         for (QValueList<int>::Iterator it = list.begin() ; it != list.end() ; ++it)
03084             lst.append( i18n("%1%").arg(*it) );
03085     }
03086     else
03087     {
03088         lst << i18n("%1%").arg("33");
03089         lst << i18n("%1%").arg("50");
03090         lst << i18n("%1%").arg("75");
03091         lst << i18n("%1%").arg("100");
03092         lst << i18n("%1%").arg("125");
03093         lst << i18n("%1%").arg("150");
03094         lst << i18n("%1%").arg("200");
03095         lst << i18n("%1%").arg("250");
03096         lst << i18n("%1%").arg("350");
03097         lst << i18n("%1%").arg("400");
03098         lst << i18n("%1%").arg("450");
03099         lst << i18n("%1%").arg("500");
03100     }
03101     m_actionViewZoom->setItems( lst );
03102 }
03103 
03104 void KWView::showZoom( int zoom )
03105 {
03106     QStringList list = m_actionViewZoom->items();
03107     QString zoomStr( i18n("%1%").arg( zoom ) );
03108     m_actionViewZoom->setCurrentItem( list.findIndex(zoomStr)  );
03109 }
03110 
03111 void KWView::showZoom( const QString& zoom )
03112 {
03113     QStringList list = m_actionViewZoom->items();
03114     m_actionViewZoom->setCurrentItem( list.findIndex( zoom )  );
03115 }
03116 
03117 void KWView::slotViewFormattingChars()
03118 {
03119     m_doc->setViewFormattingChars(m_actionViewFormattingChars->isChecked());
03120     m_doc->layout(); // Due to the different formatting when this option is activated
03121     m_doc->repaintAllViews();
03122 }
03123 
03124 void KWView::slotViewFrameBorders()
03125 {
03126     setViewFrameBorders(m_actionViewFrameBorders->isChecked());
03127     m_gui->canvasWidget()->repaintAll();
03128 }
03129 
03130 void KWView::viewHeader()
03131 {
03132     bool state = m_actionViewHeader->isChecked();
03133     m_doc->setHeaderVisible( state );
03134     KWHideShowHeader *cmd=new KWHideShowHeader( state ? i18n("Enable Document Headers"):i18n("Disable Document Headers"), m_doc, state);
03135     m_doc->addCommand(cmd);
03136     updateHeader();
03137 }
03138 
03139 void KWView::updateHeader()
03140 {
03141     KWTextFrameSetEdit * edit = currentTextEdit();
03142     bool state = m_actionViewHeader->isChecked();
03143     if(!state )
03144     {
03145         KWFrameSet *frameSet=0L;
03146         if(edit)
03147         {
03148             frameSet=edit->frameSet();
03149             if (frameSet->isAHeader())
03150                 m_doc->terminateEditing( frameSet );
03151             else
03152             {
03153                 KWTableFrameSet *table = frameSet->frame(0)->frameSet()->groupmanager();
03154                 if (table)
03155                 {
03156                     if (table->isFloating() && table->anchorFrameset()->isAHeader())
03157                         m_doc->terminateEditing( table );
03158                 }
03159             }
03160 
03161         }
03162         else
03163         {
03164             KWFormulaFrameSetEdit * editFormula = dynamic_cast<KWFormulaFrameSetEdit *>(m_gui->canvasWidget()->currentFrameSetEdit());
03165             if(editFormula)
03166             {
03167                 frameSet= editFormula->frameSet();
03168                 if(frameSet->type()==FT_FORMULA && frameSet->isFloating())
03169                     m_doc->terminateEditing( frameSet );
03170             }
03171 
03172         }
03173     }
03174 }
03175 
03176 
03177 void KWView::viewFooter()
03178 {
03179     bool state=m_actionViewFooter->isChecked();
03180     m_doc->setFooterVisible( state );
03181     KWHideShowFooter *cmd=new KWHideShowFooter( state ? i18n("Enable Document Footers"):i18n("Disable Document Footers"), m_doc, state);
03182     m_doc->addCommand(cmd);
03183     updateFooter();
03184 }
03185 
03186 void KWView::updateFooter()
03187 {
03188     bool state=m_actionViewFooter->isChecked();
03189     KWTextFrameSetEdit * edit = currentTextEdit();
03190     if(!state )
03191     {
03192         KWFrameSet *frameSet=0L;
03193         if(edit)
03194         {
03195             frameSet=edit->frameSet();
03196             if (frameSet->isAFooter())
03197                 m_doc->terminateEditing( frameSet );
03198             else
03199             {
03200                 KWTableFrameSet *table = frameSet->frame(0)->frameSet()->groupmanager();
03201                 if (table)
03202                 {
03203                     if (table->isFloating() && table->anchorFrameset()->isAFooter())
03204                         m_doc->terminateEditing( table );
03205                 }
03206             }
03207         }
03208         else
03209         {
03210             KWFormulaFrameSetEdit * editFormula = dynamic_cast<KWFormulaFrameSetEdit *>(m_gui->canvasWidget()->currentFrameSetEdit());
03211             if(editFormula)
03212             {
03213                 frameSet= editFormula->frameSet();
03214                 if(frameSet->type()==FT_FORMULA && frameSet->isFloating())
03215                     m_doc->terminateEditing( frameSet );
03216 
03217             }
03218 
03219         }
03220     }
03221 
03222 }
03223 
03224 void KWView::updateZoom( ) {
03225     viewZoom(m_actionViewZoom->currentText());
03226 }
03227 
03228 void KWView::viewZoom( const QString &s )
03229 {
03230     bool ok=false;
03231     KWCanvas * canvas = m_gui->canvasWidget();
03232     int zoom = 0;
03233 
03234     if ( s == KoZoomMode::toString(KoZoomMode::ZOOM_WIDTH) )
03235     {
03236         m_doc->setZoomMode(KoZoomMode::ZOOM_WIDTH);
03237         zoom = qRound( static_cast<double>(canvas->visibleWidth() * 100 ) / (m_doc->resolutionX() * m_currentPage->width() ) ) - 1;
03238 
03239         if(zoom != m_doc->zoom() && !canvas->verticalScrollBar() ||
03240                 !canvas->verticalScrollBar()->isVisible()) { // has no vertical scrollbar
03241             // we have to do this twice to take into account a possibly appearing vertical scrollbar
03242             QTimer::singleShot( 0, this, SLOT( updateZoom() ) );
03243         }
03244         ok = true;
03245     }
03246     else if ( s == KoZoomMode::toString(KoZoomMode::ZOOM_PAGE) )
03247     {
03248         m_doc->setZoomMode(KoZoomMode::ZOOM_PAGE);
03249         double height = m_doc->resolutionY() * m_currentPage->height();
03250         double width = m_doc->resolutionX() * m_currentPage->height();
03251         zoom = QMIN( qRound( static_cast<double>(canvas->visibleHeight() * 100 ) / height ),
03252                      qRound( static_cast<double>(canvas->visibleWidth() * 100 ) / width ) ) - 1;
03253 
03254         ok = true;
03255     }
03256     else
03257     {
03258         m_doc->setZoomMode(KoZoomMode::ZOOM_CONSTANT);
03259         QRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
03260         regexp.search(s);
03261         zoom=regexp.cap(1).toInt(&ok);
03262     }
03263 
03264     if( !ok || zoom<10 ) //zoom should be valid and >10
03265         zoom = m_doc->zoom();
03266     if ( !KoZoomMode::isConstant(s) )
03267         showZoom( s ); //set current menu item
03268     else
03269     {
03270         changeZoomMenu( zoom ); //add current zoom value to the menu
03271         showZoom( zoom ); //set current menu item
03272     }
03273 
03274     //apply zoom if zoom!=m_doc->zoom()
03275     if( zoom != m_doc->zoom() )
03276     {
03277         setZoom( zoom, true );
03278 
03279         KWTextFrameSetEdit * edit = currentTextEdit();
03280         if ( edit )
03281             edit->ensureCursorVisible();
03282     }
03283 
03284     m_gui->canvasWidget()->setFocus();
03285 
03286 }
03287 
03288 void KWView::setZoom( int zoom, bool updateViews )
03289 {
03290     m_doc->setZoomAndResolution( zoom, KoGlobal::dpiX(), KoGlobal::dpiY());
03291     m_doc->newZoomAndResolution( updateViews, false );
03292     m_doc->updateZoomRuler();
03293 
03294     if ( statusBar() )
03295         m_sbZoomLabel->setText( ' ' + QString::number( zoom ) + "% " );
03296 
03297     // Also set the zoom in KoView (for embedded views)
03298     kdDebug() << "KWView::setZoom " << zoom << " setting koview zoom to " << m_doc->zoomedResolutionY() << endl;
03299     KoView::setZoom( m_doc->zoomedResolutionY() /* KoView only supports one zoom */ );
03300 }
03301 
03302 void KWView::insertPicture()
03303 {
03304     if ( m_actionToolsCreatePix->isChecked() )
03305     {
03306         KWInsertPicDia dia( this,m_gui->canvasWidget()->pictureInline(),m_gui->canvasWidget()->pictureKeepRatio(),m_doc );
03307         if ( dia.exec() == QDialog::Accepted && !dia.picture().isNull() )
03308         {
03309             insertPicture( dia.picture(), dia.makeInline(), dia.keepRatio(), 0, 0 );
03310             m_gui->canvasWidget()->setPictureInline( dia.makeInline());
03311             m_gui->canvasWidget()->setPictureKeepRatio( dia.keepRatio() );
03312         }
03313         else
03314             m_gui->canvasWidget()->setMouseMode( KWCanvas::MM_EDIT );
03315     }
03316     else
03317     {
03318         // clicked on the already active tool -> abort
03319         m_gui->canvasWidget()->setMouseMode( KWCanvas::MM_EDIT );
03320     }
03321 }
03322 
03323 
03324 void KWView::slotEmbedImage( const QString &filename )
03325 {
03326     KoPicture picture;
03327     KoPictureKey key;
03328     key.setKeyFromFile( filename );
03329     picture.setKey( key );
03330     picture.loadFromFile( filename );
03331     insertPicture( picture, false, true, 0, 0 );
03332 }
03333 
03334 void KWView::insertPicture( const KoPicture& picture, const bool makeInline, const bool keepRatio, int suggestedWidth, int suggestedHeight )
03335 {
03336     QSize pixmapSize( picture.getOriginalSize() );
03337     if ( suggestedWidth > 0 && suggestedHeight > 0 )
03338         pixmapSize = QSize( suggestedWidth, suggestedHeight );
03339 
03340     if ( makeInline )
03341     {
03342         const double widthLimit = m_currentPage->width() - m_currentPage->leftMargin() -
03343             m_currentPage->rightMargin() - 10;
03344         const double heightLimit = m_currentPage->height() - m_currentPage->topMargin() -
03345             m_currentPage->bottomMargin() - 10;
03346         m_fsInline = 0;
03347         KWPictureFrameSet *frameset = new KWPictureFrameSet( m_doc, QString::null );
03348 
03349         frameset->insertPicture( picture );
03350 
03351         // This ensures 1-1 at 100% on screen, but allows zooming and printing with correct DPI values
03352         // ### TODO/FIXME: is the qRound really necessary?
03353         double width = m_doc->unzoomItX( qRound( (double)pixmapSize.width() * m_doc->zoomedResolutionX() / POINT_TO_INCH( KoGlobal::dpiX() ) ) );
03354         double height = m_doc->unzoomItY( qRound( (double)pixmapSize.height() * m_doc->zoomedResolutionY() / POINT_TO_INCH( KoGlobal::dpiY() ) ) );
03355 
03356         frameset->setKeepAspectRatio( keepRatio);
03357 
03358 
03359         if ( keepRatio && ((width > widthLimit) || (height > heightLimit)) )
03360         {
03361             // size too big => adjust the size and keep ratio
03362             const double ratioX = width / widthLimit;
03363             const double ratioY = height / heightLimit;
03364             const double ratioPicture = width / height;
03365 
03366             if ( ratioPicture == 0 )  // unlikely
03367             {
03368                 width = widthLimit;
03369                 height = heightLimit;
03370             }
03371             else
03372                 if ( ratioX > ratioY )  // restrict width and calculate height
03373                 {
03374                     width = widthLimit;
03375                     height = widthLimit/ratioPicture;
03376                 }
03377                 else   // restrict height and calculate width
03378                 {
03379                     width = heightLimit*ratioPicture;
03380                     height = heightLimit;
03381                 }
03382         }
03383         else
03384         {
03385             // Apply reasonable limits
03386             width = kMin( width, widthLimit );
03387             height = kMin( height, heightLimit );
03388         }
03389 
03390         m_fsInline = frameset;
03391         KWFrame *frame = new KWFrame ( m_fsInline, 0, 0, width, height );
03392         m_fsInline->addFrame( frame, false );
03393         m_gui->canvasWidget()->inlinePictureStarted();
03394         showMouseMode( KWCanvas::MM_EDIT );
03395 
03396         displayFrameInlineInfo();
03397 
03398 #if 0
03399         edit->insertFloatingFrameSet( fs, i18n("Insert Picture Inline") );
03400         fs->finalize(); // done last since it triggers a redraw
03401         showMouseMode( KWCanvas::MM_EDIT );
03402         m_doc->refreshDocStructure(Pictures);
03403 #endif
03404     }
03405     else
03406     {
03407         m_gui->canvasWidget()->insertPicture( picture, pixmapSize, keepRatio );
03408     }
03409 }
03410 
03411 bool KWView::insertInlinePicture()
03412 {
03413     Q_ASSERT( m_fsInline );
03414     KWTextFrameSetEdit * edit = currentTextEdit();
03415     if(edit)
03416     {
03417         if ( edit->textFrameSet()->textObject()->protectContent() )
03418             return false;
03419 
03420         m_doc->addFrameSet( m_fsInline, false ); // done first since the frame number is stored in the undo/redo
03421 #if 0
03422         KWFrame *frame = new KWFrame( m_fsInline, 0, 0, m_doc->unzoomItX( width ), m_doc->unzoomItY( height ) );
03423         m_fsInline->addFrame( frame, false );
03424 #endif
03425         edit->insertFloatingFrameSet( m_fsInline, i18n("Insert Picture Inline") );
03426         m_fsInline->finalize(); // done last since it triggers a redraw
03427         showMouseMode( KWCanvas::MM_EDIT );
03428         m_doc->refreshDocStructure(Pictures);
03429         m_fsInline=0;
03430         updateFrameStatusBarItem();
03431     }
03432     else
03433     {
03434         delete m_fsInline;
03435         m_fsInline=0;
03436         updateFrameStatusBarItem();
03437     }
03438     return true;
03439 }
03440 
03441 void KWView::displayFrameInlineInfo()
03442 {
03443     KMessageBox::information(this,
03444                              i18n("Set cursor where you want to insert inline frame."),
03445                              i18n("Insert Inline Frame"),
03446                              "SetCursorInsertInlineFrame",true);
03447 
03448     if ( statusBar() && m_sbFramesLabel )
03449         m_sbFramesLabel->setText( ' ' + i18n("Set cursor where you want to insert inline frame." ) );
03450 }
03451 
03452 void KWView::insertSpecialChar()
03453 {
03454     KWTextFrameSetEdit *edit=currentTextEdit();
03455     if ( !edit )
03456         return;
03457     QString f = edit->textFontFamily();
03458     QChar c=' ';
03459     if (m_specialCharDlg==0)
03460     {
03461         m_specialCharDlg = new KoCharSelectDia( this, "insert special char", f, c, false );
03462         connect( m_specialCharDlg, SIGNAL(insertChar(QChar,const QString &)),
03463                  this, SLOT(slotSpecialChar(QChar,const QString &)));
03464         connect( m_specialCharDlg, SIGNAL( finished() ),
03465                  this, SLOT( slotSpecialCharDlgClosed() ) );
03466     }
03467     m_specialCharDlg->show();
03468 }
03469 
03470 void KWView::slotSpecialCharDlgClosed()
03471 {
03472     if ( m_specialCharDlg )
03473     {
03474         disconnect( m_specialCharDlg, SIGNAL(insertChar(QChar,const QString &)),
03475                     this, SLOT(slotSpecialChar(QChar,const QString &)));
03476         disconnect( m_specialCharDlg, SIGNAL( finished() ),
03477                     this, SLOT( slotSpecialCharDlgClosed() ) );
03478         m_specialCharDlg->deleteLater();
03479         m_specialCharDlg = 0L;
03480     }
03481 }
03482 
03483 void KWView::slotSpecialChar(QChar c, const QString &font)
03484 {
03485     KWTextFrameSetEdit *edit=currentTextEdit();
03486     if ( !edit )
03487         return;
03488     edit->insertSpecialChar(c, font);
03489 }
03490 
03491 void KWView::insertFrameBreak()
03492 {
03493     KWTextFrameSetEdit *edit=currentTextEdit();
03494     if ( !edit )
03495         return;
03496     edit->insertFrameBreak();
03497 }
03498 
03499 void KWView::insertPage()
03500 {
03501     if ( m_doc->processingType() == KWDocument::WP )
03502     {
03503         m_gui->canvasWidget()->editFrameSet( m_doc->frameSet(0) );
03504         KWTextFrameSetEdit *edit = currentTextEdit();
03505         Q_ASSERT(edit);
03506         if ( edit )
03507             edit->insertWPPage();
03508     } else {
03509         KWInsertPageDia dlg( this, "insertpage");
03510         if ( dlg.exec())
03511         {
03512             // If 'before', subtract 1 to the page number
03513             int page = m_currentPage->pageNumber();
03514             KCommand* cmd = new KWInsertRemovePageCommand( m_doc, KWInsertRemovePageCommand::Insert, dlg.insertPagePos()==KW_INSERTPAGEAFTER ?  page : (page -1));
03515             cmd->execute();
03516             m_doc->addCommand( cmd );
03517         }
03518     }
03519 }
03520 
03521 void KWView::deletePage()
03522 {
03523     KCommand* cmd = new KWInsertRemovePageCommand( m_doc, KWInsertRemovePageCommand::Remove, m_currentPage->pageNumber() );
03524     cmd->execute();
03525     m_doc->addCommand( cmd );
03526     if(m_doc->lastPage() > m_currentPage->pageNumber())
03527         m_currentPage = m_doc->pageManager()->page( m_doc->lastPage() );
03528 }
03529 
03530 void KWView::insertLink()
03531 {
03532     KWTextFrameSetEdit *edit=currentTextEdit();
03533     if ( !edit )
03534         return;
03535     QString link;
03536     QString ref;
03537     if ( edit->textFrameSet()->hasSelection() )
03538     {
03539         QString selectedText = edit->textFrameSet()->textObject()->selectedText();
03540         if ( edit->textFrameSet()->textObject()->selectionHasCustomItems() || selectedText.contains('\n') )
03541             return;
03542         if ( selectedText.startsWith( "mailto:/" ) ||
03543              selectedText.startsWith( "ftp:/" ) ||
03544              selectedText.startsWith( "http:/" ) )
03545         {
03546             link=selectedText;
03547             ref = selectedText;
03548         }
03549         else
03550         {
03551             //Just add text as link name and not url
03552             link = selectedText;
03553         }
03554     }
03555 
03556     if(KoInsertLinkDia::createLinkDia(link, ref, m_doc->listOfBookmarkName(0), true, this))
03557     {
03558         if(!link.isEmpty() && !ref.isEmpty())
03559             edit->insertLink(link, ref);
03560     }
03561 }
03562 
03563 void KWView::insertComment()
03564 {
03565     KWTextFrameSetEdit *edit=currentTextEdit();
03566     if ( !edit )
03567         return;
03568     QString authorName;
03569     KoDocumentInfo * info = m_doc->documentInfo();
03570     KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
03571     if ( !authorPage )
03572         kdWarning() << "Author information not found in documentInfo !" << endl;
03573     else
03574         authorName = authorPage->fullName();
03575 
03576     KoCommentDia *commentDia = new KoCommentDia( this, QString::null,authorName );
03577     if( commentDia->exec() )
03578     {
03579         edit->insertComment(commentDia->commentText());
03580     }
03581     delete commentDia;
03582 }
03583 
03584 
03585 void KWView::insertVariable()
03586 {
03587     KWTextFrameSetEdit * edit = currentTextEdit();
03588     if ( edit )
03589     {
03590         KAction * act = (KAction *)(sender());
03591         VariableDefMap::Iterator it = m_variableDefMap.find( act );
03592         if ( it == m_variableDefMap.end() )
03593             kdWarning() << "Action not found in m_variableDefMap." << endl;
03594         else
03595         {
03596             if ( (*it).type == VT_FIELD )
03597                 edit->insertVariable( (*it).type, KoFieldVariable::fieldSubType( (*it).subtype ) );
03598             else
03599                 edit->insertVariable( (*it).type, (*it).subtype );
03600         }
03601     }
03602 }
03603 
03604 void KWView::insertFootNote()
03605 {
03606     KWTextFrameSetEdit * edit = currentTextEdit();
03607     //Q_ASSERT( edit ); // the action should be disabled if we're not editing a textframeset...
03608     if ( edit ) // test for dcop call !
03609     {
03610         if ( edit->frameSet() != m_doc->frameSet(0) )
03611         {
03612             KMessageBox::sorry( this,
03613                                 i18n( "You can only insert footnotes or "
03614                                       "endnotes into the first frameset."),
03615                                 i18n("Insert Footnote"));
03616         } else {
03617             KWFootNoteDia dia( m_gui->canvasWidget()->footNoteType(), m_gui->canvasWidget()->numberingFootNoteType(), QString::null, this, m_doc, 0 );
03618             QPtrListIterator<KoTextCustomItem> it( edit->textDocument()->allCustomItems() );
03619             for ( ; it.current() ; ++it )
03620             {
03621                 KWFootNoteVariable *fnv = dynamic_cast<KWFootNoteVariable *>( it.current() );
03622                 if (fnv && !fnv->isDeleted() && fnv->frameSet() && !fnv->frameSet()->isDeleted() &&
03623                  fnv->numberingType()==KWFootNoteVariable::Manual )
03624                     dia.appendManualFootNote( fnv->text() );
03625             }
03626             if ( dia.exec() ) {
03627                 edit->insertFootNote( dia.noteType(), dia.numberingType(), dia.manualString() );
03628                 m_gui->canvasWidget()->setFootNoteType( dia.noteType() );
03629                 m_gui->canvasWidget()->setNumberingFootNoteType( dia.numberingType() );
03630             }
03631         }
03632     }
03633 }
03634 
03635 void KWView::updateTocActionText(bool hasToc)
03636 {
03637    KActionCollection * coll = actionCollection();
03638    QString name= hasToc ? i18n("Update Table of &Contents"):i18n("Table of &Contents");
03639    coll->action("insert_contents")->setText(name);
03640 }
03641 
03642 void KWView::insertContents()
03643 {
03644     KWTextFrameSetEdit *edit = currentTextEdit();
03645     if (edit)
03646         edit->insertTOC();
03647 }
03648 
03649 void KWView::formatFont()
03650 {
03651     KoTextFormatInterface* textIface = applicableTextInterfaces().first();
03652 
03653     if ( !textIface || !textIface->currentFormat() )
03654         return;
03655 
03656     delete m_fontDlg;
03657     m_fontDlg = new KoFontDia( *textIface->currentFormat()
03658                                , m_broker
03659                                , this, "" );
03660 
03661     connect( m_fontDlg, SIGNAL( applyFont() ),
03662                  this, SLOT( slotApplyFont() ) );
03663 
03664     m_fontDlg->exec();
03665     delete m_fontDlg;
03666     m_fontDlg=0L;
03667 
03668     //m_gui->canvasWidget()->setFocus();
03669 }
03670 
03671 void KWView::slotApplyFont()
03672 {
03673     int flags = m_fontDlg->changedFlags();
03674     if ( flags )
03675     {
03676         KMacroCommand *globalCmd = new KMacroCommand(i18n("Change Font"));
03677         QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
03678         QPtrListIterator<KoTextFormatInterface> it( lst );
03679         for ( ; it.current() ; ++it )
03680         {
03681             KoTextFormat newFormat = m_fontDlg->newFormat();
03682             KCommand *cmd = it.current()->setFormatCommand( &newFormat, flags, true);
03683             if (cmd)
03684                 globalCmd->addCommand(cmd);
03685         }
03686         m_doc->addCommand(globalCmd);
03687         m_gui->canvasWidget()->setFocus(); // the combo keeps focus...
03688     }
03689 
03690 }
03691 
03692 void KWView::formatParagraph()
03693 {
03694     showParagraphDialog();
03695 }
03696 
03697 void KWView::showParagraphDialog( int initialPage, double initialTabPos )
03698 {
03699     KWTextFrameSetEdit *edit = currentTextEdit();
03700     if (edit)
03701     {
03702         delete m_paragDlg;
03703         bool showFrameEndOptions = !edit->frameSet()->isHeaderOrFooter() &&
03704                                    !edit->frameSet()->groupmanager();
03705         m_paragDlg = new KoParagDia( this, "",
03706                                      KoParagDia::PD_SPACING | KoParagDia::PD_ALIGN |
03707                                      KoParagDia::PD_DECORATION | KoParagDia::PD_NUMBERING |
03708                                      KoParagDia::PD_TABS,
03709                                      m_doc->unit(),
03710                                      edit->textFrameSet()->frame(0)->width(),
03711                                      showFrameEndOptions,
03712                                      edit->frameSet()->isFootEndNote());
03713         m_paragDlg->setCaption( i18n( "Paragraph Settings" ) );
03714 
03715         // Initialize the dialog from the current paragraph's settings
03716         m_paragDlg->setParagLayout( edit->cursor()->parag()->paragLayout() );
03717 
03718         // Set initial page and initial tabpos if necessary
03719         if ( initialPage != -1 )
03720         {
03721             m_paragDlg->setCurrentPage( initialPage );
03722             if ( initialPage == KoParagDia::PD_TABS )
03723                 m_paragDlg->tabulatorsWidget()->setCurrentTab( initialTabPos );
03724         }
03725         connect( m_paragDlg, SIGNAL( applyParagStyle() ), this, SLOT( slotApplyParag()));
03726 
03727         m_paragDlg->exec();
03728         delete m_paragDlg;
03729         m_paragDlg=0L;
03730     }
03731 
03732 }
03733 
03734 void KWView::slotApplyParag()
03735 {
03736     KWTextFrameSetEdit *edit = currentTextEdit();
03737     if( !edit)
03738         return;
03739     KMacroCommand * macroCommand = 0L;
03740     KCommand *cmd=0L;
03741     if(m_paragDlg->isLeftMarginChanged())
03742     {
03743         cmd=edit->setMarginCommand( QStyleSheetItem::MarginLeft, m_paragDlg->leftIndent() );
03744         if(cmd)
03745         {
03746             if ( !macroCommand )
03747                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03748             macroCommand->addCommand(cmd);
03749         }
03750         m_gui->getHorzRuler()->setLeftIndent( KoUnit::toUserValue( m_paragDlg->leftIndent(), m_doc->unit() ) );
03751 
03752     }
03753 
03754     if(m_paragDlg->isRightMarginChanged())
03755     {
03756         cmd=edit->setMarginCommand( QStyleSheetItem::MarginRight, m_paragDlg->rightIndent() );
03757         if(cmd)
03758         {
03759             if ( !macroCommand )
03760                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03761             macroCommand->addCommand(cmd);
03762         }
03763         m_gui->getHorzRuler()->setRightIndent( KoUnit::toUserValue( m_paragDlg->rightIndent(), m_doc->unit() ) );
03764     }
03765     if(m_paragDlg->isSpaceBeforeChanged())
03766     {
03767         cmd=edit->setMarginCommand( QStyleSheetItem::MarginTop, m_paragDlg->spaceBeforeParag() );
03768         if(cmd)
03769         {
03770             if ( !macroCommand )
03771                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03772             macroCommand->addCommand(cmd);
03773         }
03774     }
03775     if(m_paragDlg->isSpaceAfterChanged())
03776     {
03777         cmd=edit->setMarginCommand( QStyleSheetItem::MarginBottom, m_paragDlg->spaceAfterParag() );
03778         if(cmd)
03779         {
03780             if ( !macroCommand )
03781                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03782             macroCommand->addCommand(cmd);
03783         }
03784     }
03785     if(m_paragDlg->isFirstLineChanged())
03786     {
03787         cmd=edit->setMarginCommand( QStyleSheetItem::MarginFirstLine, m_paragDlg->firstLineIndent());
03788         if(cmd)
03789         {
03790             if ( !macroCommand )
03791                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03792             macroCommand->addCommand(cmd);
03793         }
03794         m_gui->getHorzRuler()->setFirstIndent(
03795             KoUnit::toUserValue( m_paragDlg->firstLineIndent(), m_doc->unit() ) );
03796     }
03797 
03798     if(m_paragDlg->isAlignChanged())
03799     {
03800         cmd=edit->setAlignCommand( m_paragDlg->align() );
03801         if(cmd)
03802         {
03803             if ( !macroCommand )
03804                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03805             macroCommand->addCommand(cmd);
03806         }
03807     }
03808     if(m_paragDlg->isCounterChanged())
03809     {
03810         cmd=edit->setCounterCommand( m_paragDlg->counter() );
03811         if(cmd)
03812         {
03813             if ( !macroCommand )
03814                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03815             macroCommand->addCommand(cmd);
03816         }
03817     }
03818     if(m_paragDlg->listTabulatorChanged())
03819     {
03820         cmd=edit->setTabListCommand( m_paragDlg->tabListTabulator() );
03821         if(cmd)
03822         {
03823             if ( !macroCommand )
03824                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03825             macroCommand->addCommand(cmd);
03826         }
03827     }
03828 
03829     if(m_paragDlg->isLineSpacingChanged())
03830     {
03831         cmd=edit->setLineSpacingCommand( m_paragDlg->lineSpacing(),m_paragDlg->lineSpacingType() );
03832         if(cmd)
03833         {
03834             if ( !macroCommand )
03835                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03836 
03837             macroCommand->addCommand(cmd);
03838         }
03839     }
03840     if(m_paragDlg->isBorderChanged())
03841     {
03842         cmd=edit->setBordersCommand( m_paragDlg->leftBorder(),
03843                                      m_paragDlg->rightBorder(),
03844                                      m_paragDlg->topBorder(),
03845                                      m_paragDlg->bottomBorder() );
03846         if(cmd)
03847         {
03848             if ( !macroCommand )
03849                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03850 
03851             macroCommand->addCommand(cmd);
03852         }
03853     }
03854     if( m_paragDlg->isJoinBorderChanged() )
03855     {
03856         cmd=edit->setJoinBordersCommand( m_paragDlg->joinBorder() );
03857         if(cmd)
03858         {
03859             if ( !macroCommand )
03860                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03861 
03862             macroCommand->addCommand(cmd);
03863         }
03864     }
03865     if ( m_paragDlg->isPageBreakingChanged() )
03866     {
03867         cmd=edit->setPageBreakingCommand( m_paragDlg->pageBreaking() );
03868         if(cmd)
03869         {
03870             if ( !macroCommand )
03871                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03872 
03873             macroCommand->addCommand(cmd);
03874         }
03875     }
03876 
03877     if ( m_paragDlg->isBackgroundColorChanged() )
03878     {
03879         cmd=edit->setBackgroundColorCommand( m_paragDlg->backgroundColor() );
03880         if(cmd)
03881         {
03882             if ( !macroCommand )
03883                 macroCommand = new KMacroCommand( i18n( "Paragraph Settings" ) );
03884 
03885             macroCommand->addCommand(cmd);
03886         }
03887     }
03888 
03889     if(macroCommand)
03890         m_doc->addCommand(macroCommand);
03891     // Set "oldLayout" in KoParagDia from the current paragraph's settings
03892     // Otherwise "isBlahChanged" will return wrong things when doing A -> B -> A
03893     m_paragDlg->setParagLayout( edit->cursor()->parag()->paragLayout() );
03894 }
03895 
03896 // This handles Tabulators _only_
03897 void KWView::slotHRulerDoubleClicked( double ptpos )
03898 {
03899     showParagraphDialog( KoParagDia::PD_TABS, ptpos );
03900 }
03901 
03902 // This handles either:
03903 // - Indents
03904 // - Page Layout
03905 //
03906 // This does _not_ handle Tabulators!
03907 void KWView::slotHRulerDoubleClicked()
03908 {
03909     QString mode = viewMode()->type();
03910     bool state = (mode!="ModeText");
03911     if ( !state )
03912         return;
03913 
03914     KoRuler *ruler = m_gui->getHorzRuler ();
03915     if ( (ruler->flags() & KoRuler::F_INDENTS) && currentTextEdit() ) {
03916         if ( ruler->doubleClickedIndent () ) {
03917             formatParagraph();
03918             return;
03919         }
03920     }
03921 
03922     formatPage();
03923 }
03924 
03925 void KWView::formatPage()
03926 {
03927     if( !m_doc->isReadWrite())
03928         return;
03929     QString mode = viewMode()->type();
03930     bool state = (mode!="ModeText");
03931     if ( !state )
03932         return;
03933 
03934     KoPageLayout pgLayout;
03935     KoColumns cl;
03936     KoKWHeaderFooter kwhf;
03937     m_doc->getPageLayout( pgLayout, cl, kwhf );
03938 
03939     KWPageLayoutStruct oldLayout( pgLayout, cl, kwhf );
03940 
03941     KoHeadFoot hf;
03942     int flags = FORMAT_AND_BORDERS | DISABLE_UNIT;
03943     if ( m_doc->processingType() == KWDocument::WP )
03944         flags |= KW_HEADER_AND_FOOTER | COLUMNS;
03945     else
03946         flags |= DISABLE_BORDERS;
03947 
03948     KoUnit::Unit unit = m_doc->unit();
03949     KoUnit::Unit oldUnit = unit;
03950 
03951     if ( KoPageLayoutDia::pageLayout( pgLayout, hf, cl, kwhf, flags, unit, this ) )
03952     {
03953         if( !(oldLayout._pgLayout==pgLayout) ||
03954             oldLayout._cl != cl ||
03955             oldLayout._hf != kwhf )
03956         {
03957             KWPageLayoutStruct newLayout( pgLayout, cl, kwhf );
03958 
03959             KWTextFrameSetEdit *edit = currentTextEdit();
03960             if (edit)
03961                 edit->textFrameSet()->clearUndoRedoInfo();
03962             KCommand *cmd =new KWPageLayoutCommand( i18n("Change Layout"),
03963                                                     m_doc, oldLayout, newLayout );
03964             m_doc->addCommand(cmd);
03965 
03966             m_doc->setPageLayout( pgLayout, cl, kwhf );
03967         }
03968         if ( unit != oldUnit )
03969             m_doc->setUnit( unit ); // ##### needs undo/redo support
03970     }
03971 }
03972 
03973 void KWView::formatFrameSet()
03974 {
03975     if ( frameViewManager()->selectedFrame() )
03976     {
03977         m_gui->canvasWidget()->editFrameProperties();
03978     }
03979     else // Should never happen, the action is disabled
03980         KMessageBox::sorry( this,
03981                             i18n("You must select a frame first."),
03982                             i18n("Format Frameset"));
03983 }
03984 
03985 void KWView::slotSpellCheck()
03986 {
03987     if (m_spell.kospell) return; // Already in progress
03988     //m_doc->setReadWrite(false); // prevent editing text - not anymore
03989     m_spell.macroCmdSpellCheck = 0L;
03990     m_spell.replaceAll.clear();
03991     QValueList<KoTextObject *> objects;
03992     KWTextFrameSetEdit * edit = currentTextEdit();
03993     if (!edit)
03994         return;
03995     int options = 0;
03996     if ( edit && edit->textFrameSet()->hasSelection() )
03997     {
03998         objects.append(edit->textFrameSet()->textObject());
03999         options = KFindDialog::SelectedText;
04000     }
04001     else
04002     {
04003         objects = m_gui->canvasWidget()->kWordDocument()->visibleTextObjects(viewMode());
04004     }
04005     m_spell.textIterator = new KoTextIterator( objects, edit, options );
04006     kdDebug()<<"Created iterator with "<< objects.count() <<endl;
04007     startKSpell();
04008 }
04009 
04010 void KWView::extraAutoFormat()
04011 {
04012     m_doc->autoFormat()->readConfig();
04013     KoAutoFormatDia dia( this, 0, m_doc->autoFormat() );
04014     dia.exec();
04015     m_doc->startBackgroundSpellCheck(); // will do so if enabled
04016 }
04017 
04018 void KWView::extraFrameStylist()
04019 {
04020     KWTextFrameSetEdit * edit = currentTextEdit();
04021     if ( edit )
04022         edit->hideCursor();
04023     KWFrameStyleManager * frameStyleManager = new KWFrameStyleManager( this, m_doc, QString::null );
04024     frameStyleManager->exec();
04025     delete frameStyleManager;
04026     if ( edit )
04027         edit->showCursor();
04028 }
04029 
04030 void KWView::createFrameStyle()
04031 {
04032 
04033     QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
04034     if (selectedFrames.count() != 1)
04035         return;
04036 
04037     KWFrame* frame = selectedFrames[0]->frame();
04038 
04039     KoCreateStyleDia *dia = new KoCreateStyleDia( m_doc->frameStyleCollection()->displayNameList(), this, 0 );
04040     if ( dia->exec() )
04041     {
04042         KWFrameStyle *style= new KWFrameStyle( dia->nameOfNewStyle(), frame );
04043         m_doc->frameStyleCollection()->addStyle( style );
04044         m_doc->updateAllFrameStyleLists();
04045     }
04046     delete dia;
04047 }
04048 
04049 void KWView::extraStylist()
04050 {
04051     KWTextFrameSetEdit * edit = currentTextEdit();
04052     QString activeStyleName  = QString::null;
04053     if ( edit )
04054     {
04055         edit->hideCursor();
04056         if (edit->cursor() && edit->cursor()->parag() && edit->cursor()->parag()->style())
04057             activeStyleName = edit->cursor()->parag()->style()->displayName();
04058     }
04059     KWStyleManager * styleManager = new KWStyleManager( this, m_doc->unit(),m_doc, *m_doc->styleCollection(), activeStyleName );
04060     styleManager->exec();
04061     delete styleManager;
04062     if ( edit )
04063         edit->showCursor();
04064 }
04065 
04066 void KWView::extraCreateTemplate()
04067 {
04068     int width = 60;
04069     int height = 60;
04070     QPixmap pix = m_doc->generatePreview(QSize(width, height));
04071 
04072     KTempFile tempFile( QString::null, ".odt" );
04073     tempFile.setAutoDelete(true);
04074 
04075     m_doc->saveNativeFormat( tempFile.name() );
04076 
04077     KoTemplateCreateDia::createTemplate( "kword_template", KWFactory::instance(),
04078                                          tempFile.name(), pix, this );
04079 
04080     KWFactory::instance()->dirs()->addResourceType("kword_template",
04081                                                     KStandardDirs::kde_default( "data" ) +
04082                                                     "kword/templates/");
04083 }
04084 
04085 void KWView::toolsCreateText()
04086 {
04087     if ( m_actionToolsCreateText->isChecked() )
04088         m_gui->canvasWidget()->setMouseMode( KWCanvas::MM_CREATE_TEXT );
04089     else
04090     {
04091         // clicked on the already active tool -> abort
04092         m_gui->canvasWidget()->setMouseMode( KWCanvas::MM_EDIT );
04093     }
04094 }
04095 
04096 void KWView::insertTable()
04097 {
04098     KWCanvas * canvas = m_gui->canvasWidget();
04099     canvas->setMouseMode( KWCanvas::MM_EDIT );
04100     KWTableDia *tableDia = new KWTableDia( this, 0, KWTableDia::NEW, canvas, m_doc,
04101                                            canvas->tableRows(),
04102                                            canvas->tableCols(),
04103                                            canvas->tableWidthMode(),
04104                                            canvas->tableHeightMode(),
04105                                            canvas->tableIsFloating(),
04106                                            canvas->tableTemplateName(),
04107                                            canvas->tableFormat());
04108     tableDia->setCaption( i18n( "Insert Table" ) );
04109     if ( tableDia->exec() == QDialog::Rejected )
04110         canvas->setMouseMode( KWCanvas::MM_EDIT );
04111     delete tableDia;
04112 }
04113 
04114 void KWView::insertFormula( QMimeSource* source )
04115 {
04116     KWTextFrameSetEdit *edit = currentTextEdit();
04117     if (edit)
04118     {
04119         KWFormulaFrameSet *frameset = new KWFormulaFrameSet( m_doc, QString::null );
04120         m_doc->addFrameSet( frameset, false ); // done first since the frame number is stored in the undo/redo
04121         if ( source ) {
04122             QByteArray data = source->encodedData( KFormula::MimeSource::selectionMimeType() );
04123             QDomDocument formula;
04124             formula.setContent( data );
04125             QDomElement formulaElem = formula.namedItem("KFORMULA").toElement();
04126             frameset->paste( formulaElem );
04127         }
04128         KWFrame *frame = new KWFrame(frameset, 0, 0, 10, 10 );
04129         frame->setZOrder( m_doc->maxZOrder( frame->pageNumber(m_doc) ) + 1 ); // make sure it's on top
04130         frameset->addFrame( frame, false );
04131         edit->insertFloatingFrameSet( frameset, i18n("Insert Formula") );
04132         frameset->finalize(); // done last since it triggers a redraw
04133         m_doc->refreshDocStructure(FT_FORMULA);
04134 
04135         m_gui->canvasWidget()->editFrameSet( frameset );
04136         frameset->setChanged();
04137         m_gui->canvasWidget()->repaintChanged( frameset, true );
04138     }
04139 }
04140 
04141 void KWView::toolsPart()
04142 {
04143     m_gui->canvasWidget()->insertPart( m_actionToolsCreatePart->documentEntry() );
04144 }
04145 
04146 
04147 int KWView::tableSelectCell(const QString &tableName, uint row, uint col)
04148 {
04149     if(!m_doc || !m_gui)
04150         return -1;
04151     KWFrameSet *fs = m_doc->frameSetByName(tableName);
04152     if(!fs)
04153         return -1;
04154     KWTableFrameSet *table = dynamic_cast<KWTableFrameSet*>(fs);
04155     if(!table)
04156         return -1;
04157     if (row >= table->getRows() || col >= table->getColumns())
04158         return -1;
04159 
04160     KWTableFrameSet::Cell *cell = table->cell(row, col);
04161 
04162     KWCanvas *canvas = m_gui->canvasWidget();
04163     if(!canvas)
04164         return -1;
04165     canvas->tableSelectCell(table, cell);
04166     return 0;
04167 }
04168 
04169 int KWView::tableDeleteRow(const QValueList<uint>& rows, KWTableFrameSet *table )
04170 {
04171     if(!table)
04172         table = m_gui->canvasWidget()->getCurrentTable();
04173 
04174     if (!m_doc || !table)
04175         return -1;
04176 
04177     if(rows.count() >= table->getRows()) {
04178         m_doc->deleteTable(table);
04179         return 0;
04180     }
04181 
04182     KMacroCommand *macro = new KMacroCommand(i18n("Remove Rows"));
04183 
04184     for (int i = rows.count() - 1; i >= 0 ; i--) {
04185         KWRemoveRowCommand *cmd = new KWRemoveRowCommand( i18n("Remove Row"),
04186             table, rows[i] );
04187         macro->addCommand(cmd);
04188     }
04189 
04190     macro->execute();
04191     m_doc->addCommand(macro);
04192     return 0;
04193 }
04194 
04195 int KWView::tableDeleteCol(const QValueList<uint>& cols, KWTableFrameSet *table)
04196 {
04197     if(!table)
04198         table = m_gui->canvasWidget()->getCurrentTable();
04199 
04200     if (!m_doc || !table)
04201         return -1;
04202 
04203     if(cols.count() >= table->getColumns()) {
04204         m_doc->deleteTable(table);
04205         return 0;
04206     }
04207 
04208     KMacroCommand *macro = new KMacroCommand(i18n("Remove Columns"));
04209 
04210     for (int i = cols.count() - 1;  i >= 0; i--) {
04211         KWRemoveColumnCommand *cmd = new KWRemoveColumnCommand( i18n("Remove Column"),
04212             table, cols[i] );
04213         macro->addCommand(cmd);
04214     }
04215 
04216     macro->execute();
04217     m_doc->addCommand(macro);
04218     return 0;
04219 }
04220 
04221 void KWView::tableProperties()
04222 {
04223     KWCanvas * canvas = m_gui->canvasWidget();
04224     KWTableFrameSet *table = canvas->getCurrentTable();
04225     if (table)
04226     {
04227         canvas->setMouseMode( KWCanvas::MM_EDIT );
04228         KWTableDia *tableDia = new KWTableDia( this, 0, KWTableDia::EDIT, canvas, m_doc,
04229                                                table->getRows(),
04230                                                table->getColumns(),
04231                                                canvas->tableWidthMode(),
04232                                                canvas->tableHeightMode(),
04233                                                canvas->tableIsFloating(),
04234                                                canvas->tableTemplateName(),
04235                                                canvas->tableFormat());
04236         tableDia->setCaption( i18n( "Adjust Table" ) );
04237         if ( tableDia->exec() == QDialog::Rejected )
04238             canvas->setMouseMode( KWCanvas::MM_EDIT );
04239         delete tableDia;
04240     }
04241 }
04242 
04243 void KWView::tableInsertRow()
04244 {
04245     TableInfo ti(frameViewManager()->selectedFrames());
04246     KWTableFrameSet::Cell *cell = ti.firstSelectedCell();
04247     if(! cell) return;
04248 
04249     KWInsertDia dia( this, cell->groupmanager(), KWInsertDia::insertRow,  cell->firstRow());
04250     dia.exec();
04251 }
04252 
04253 void KWView::tableInsertRow(uint row, KWTableFrameSet *table)
04254 {
04255     if(!table)
04256         table = m_gui->canvasWidget()->getCurrentTable();
04257 
04258     if (!m_doc || !table)
04259         return;
04260 
04261     if(row > table->getRows())
04262         return;
04263 
04264     KWInsertRowCommand *cmd = new KWInsertRowCommand( i18n("Insert Row"), table, row);
04265     cmd->execute();
04266     m_doc->addCommand(cmd);
04267 }
04268 
04269 
04270 void KWView::tableInsertCol()
04271 {
04272     TableInfo ti(frameViewManager()->selectedFrames());
04273     KWTableFrameSet::Cell *cell = ti.firstSelectedCell();
04274     if(! cell) return;
04275 
04276     KWInsertDia dia( this, cell->groupmanager(), KWInsertDia::insertColumn,  cell->firstColumn());
04277     dia.exec();
04278 }
04279 
04280 void KWView::tableInsertCol(uint col,  KWTableFrameSet *table  )
04281 {
04282     if(!table)
04283         table = m_gui->canvasWidget()->getCurrentTable();
04284 
04285     if (!m_doc || !table)
04286         return;
04287 
04288     if(col > table->getColumns())
04289         return;
04290 
04291     // we pass as last parameter the maximum offset that the table can use.
04292     // this offset is the max right offset of the containing frame in the case
04293     // of an inline (floating) table, the size of the page for other tables.
04294     double maxRightOffset;
04295     if (table->isFloating())    // inline table: max offset of containing frame
04296         maxRightOffset = table->anchorFrameset()->frame(0)->right();
04297     else {                      // non inline table: max offset of the page
04298         KWPage *page = m_doc->pageManager()->page( table->cell(0,0)->frame(0) );
04299         maxRightOffset = page->width() - page->rightMargin();
04300     }
04301 
04302     KWInsertColumnCommand *cmd = new KWInsertColumnCommand( i18n("Insert Column"),
04303         table, col,  maxRightOffset);
04304     cmd->execute();
04305     m_doc->addCommand(cmd);
04306 }
04307 
04308 void KWView::tableDeleteRow()
04309 {
04310     TableInfo ti( frameViewManager()->selectedFrames() );
04311     if(ti.amountRowsSelected() == 0) return;
04312 
04313     KWDeleteDia dia( this, ti.firstSelectedCell()->groupmanager(),
04314             KWDeleteDia::deleteRow, ti.selectedRows() );
04315     dia.exec();
04316 }
04317 
04318 void KWView::tableDeleteCol()
04319 {
04320     TableInfo ti( frameViewManager()->selectedFrames() );
04321     if(ti.amountColumnsSelected() == 0) return;
04322 
04323     KWDeleteDia dia( this, ti.firstSelectedCell()->groupmanager(),
04324             KWDeleteDia::deleteColumn, ti.selectedColumns() );
04325     dia.exec();
04326 }
04327 
04328 void KWView::tableResizeCol()
04329 {
04330     TableInfo ti( frameViewManager()->selectedFrames() );
04331     KWTableFrameSet::Cell *cell = ti.firstSelectedCell();
04332     if(cell == 0)
04333         return;
04334     KWResizeTableDia dia(this, cell->groupmanager(), m_doc, cell->firstColumn());
04335     dia.exec();
04336 }
04337 
04338 void KWView::tableJoinCells()
04339 {
04340     KWTableFrameSet *table = 0;
04341     QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
04342     QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
04343     unsigned int x1=10000, y1=10000, x2=0, y2=0;
04344     for(;framesIterator != selectedFrames.end(); ++framesIterator) {
04345         KWFrameView *view = *framesIterator;
04346         if(!view->selected()) continue;
04347         KWFrameSet *fs = view->frame()->frameSet();
04348         Q_ASSERT(fs);
04349         KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell*>(fs);
04350         if(cell == 0) continue;
04351         if(!table)
04352             table = cell->groupmanager();
04353         else if(table != cell->groupmanager()) { // more then one table has selected cells
04354             KMessageBox::sorry( this,
04355                     i18n( "More then one table has selected cells, please make sure "
04356                         "the selected cells are in one table and are connecting"),
04357                     i18n( "Join Cells Failed" ) );
04358             return;
04359         }
04360 
04361         if(cell->firstRow() < y1)  y1 = cell->firstRow();
04362         if(cell->firstColumn() < x1)  x1 = cell->firstColumn();
04363         if(cell->lastRow() > y2) y2 = cell->lastRow();
04364         if(cell->lastColumn() > x2) x2 = cell->lastColumn();
04365     }
04366 
04367     Q_ASSERT(table);
04368     if (!table)
04369         return;
04370     KCommand * cmd=table->joinCells(x1, y1, x2, y2);
04371     if ( !cmd )
04372     {
04373         KMessageBox::sorry( this,
04374                             i18n( "You have to select some cells which are next to each other "
04375                                   "and are not already joined." ),
04376                             i18n( "Join Cells" ) );
04377         return;
04378     }
04379     m_doc->addCommand(cmd);
04380     m_doc->layout();
04381 }
04382 
04383 void KWView::tableSplitCells() {
04384     KWSplitCellDia *splitDia=new KWSplitCellDia( this,"split cell",
04385             m_tableSplit.columns, m_tableSplit.rows );
04386     if(splitDia->exec()) {
04387         m_tableSplit.rows = splitDia->rows();
04388         m_tableSplit.columns = splitDia->columns();
04389         tableSplitCells( m_tableSplit.columns, m_tableSplit.rows );
04390     }
04391     delete splitDia;
04392 }
04393 
04394 void KWView::tableSplitCells(int cols, int rows)
04395 {
04396     TableInfo ti( frameViewManager()->selectedFrames() );
04397     if(! ti.oneCellSelected()) {
04398         KMessageBox::sorry( this,
04399                             i18n( "You have to put the cursor into a table "
04400                                   "before splitting cells." ),
04401                             i18n( "Split Cells" ) );
04402         return;
04403     }
04404 
04405     KWTableFrameSet::Cell *cell = ti.firstSelectedCell();
04406     KCommand *cmd=cell->groupmanager()->splitCell(rows, cols, cell->firstColumn(), cell->firstRow());
04407     if ( !cmd ) {
04408         KMessageBox::sorry( this,
04409                             i18n("There is not enough space to split the cell into that many parts, make it bigger first"),
04410                             i18n("Split Cells") );
04411         return;
04412     }
04413     m_doc->addCommand(cmd);
04414     m_doc->updateAllFrames();
04415     m_doc->layout();
04416     frameViewManager()->view(cell->frame(0))->setSelected(true);
04417 }
04418 
04419 void KWView::tableUngroupTable()
04420 {
04421     m_gui->canvasWidget()->setMouseMode( KWCanvas::MM_EDIT );
04422 
04423     KWTableFrameSet *table = m_gui->canvasWidget()->getCurrentTable();
04424     Q_ASSERT(table);
04425     if (!table)
04426         return;
04427 
04428     // Use a macro command because we may have to make the table non-floating first
04429     KMacroCommand * macroCmd = new KMacroCommand( i18n( "Ungroup Table" ) );
04430 
04431     if ( table->isFloating() )
04432     {
04433         KWFrameSetInlineCommand *cmd = new KWFrameSetInlineCommand( QString::null, table, false );
04434         macroCmd->addCommand(cmd);
04435     }
04436 
04437     KWUngroupTableCommand *cmd = new KWUngroupTableCommand( QString::null, table );
04438     macroCmd->addCommand( cmd );
04439     m_doc->addCommand( macroCmd );
04440     macroCmd->execute(); // do it all
04441 }
04442 
04443 void KWView::tableDelete()
04444 {
04445     KWTableFrameSet *table = m_gui->canvasWidget()->getCurrentTable();
04446     Q_ASSERT(table);
04447     if (!table)
04448         return;
04449     m_doc->deleteTable( table );
04450 }
04451 
04452 void KWView::tableStylist()
04453 {
04454     KWTextFrameSetEdit * edit = currentTextEdit();
04455     if ( edit )
04456         edit->hideCursor();
04457     KWTableStyleManager * tableStyleManager = new KWTableStyleManager( this, m_doc );
04458     tableStyleManager->exec();
04459     delete tableStyleManager;
04460     if ( edit )
04461         edit->showCursor();
04462 }
04463 
04464 void KWView::tableProtectCells(bool on)
04465 {
04466     KMacroCommand *macro = 0;
04467     QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
04468     QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
04469     for(;framesIterator != selectedFrames.end(); ++framesIterator) {
04470         KWFrameView *view = *framesIterator;
04471         KWFrameSet *fs = view->frame()->frameSet();
04472         Q_ASSERT(fs);
04473         KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell*>(fs);
04474         if(cell == 0) continue;
04475         if(cell->protectContent() != on) {
04476             KWProtectContentCommand *cmd = new KWProtectContentCommand( i18n("Protect Content"), cell , on);
04477             if ( !macro )
04478                 macro = new KMacroCommand( i18n("Protect Content"));
04479             macro->addCommand( cmd );
04480         }
04481     }
04482     if(macro) {
04483         macro->execute();
04484         m_doc->addCommand( macro );
04485     }
04486 }
04487 
04488 void KWView::textStyleSelected( KoParagStyle *sty )
04489 {
04490     if ( !sty )
04491         return;
04492 
04493     if ( m_gui->canvasWidget()->currentFrameSetEdit() )
04494     {
04495         KWTextFrameSetEdit * edit = dynamic_cast<KWTextFrameSetEdit *>(m_gui->canvasWidget()->currentFrameSetEdit()->currentTextEdit());
04496         if ( edit )
04497             edit->applyStyle( sty );
04498     }
04499     else
04500     { // it might be that a frame (or several frames) are selected
04501         QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
04502         if (selectedFrames.count() <= 0)
04503             return; // nope, no frames are selected.
04504         // yes, indeed frames are selected.
04505 
04506         QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
04507         KMacroCommand *globalCmd = 0L;
04508         while(framesIterator != selectedFrames.end()) {
04509             KWFrame *curFrame = (*framesIterator)->frame();
04510             KWFrameSet *curFrameSet = curFrame->frameSet();
04511             if (curFrameSet->type() == FT_TEXT)
04512             {
04513                 KoTextObject *textObject = ((KWTextFrameSet*)curFrameSet)->textObject();
04514                 textObject->textDocument()->selectAll( KoTextDocument::Temp );
04515                 KCommand *cmd = textObject->applyStyleCommand( 0L, sty , KoTextDocument::Temp, KoParagLayout::All, KoTextFormat::Format, true, true );
04516                 textObject->textDocument()->removeSelection( KoTextDocument::Temp );
04517                 if (cmd)
04518                 {
04519                     if ( !globalCmd )
04520                         globalCmd = new KMacroCommand( selectedFrames.count() == 1 ? i18n("Apply Style to Frame") : i18n("Apply Style to Frames"));
04521                     globalCmd->addCommand( cmd );
04522                 }
04523             }
04524             ++framesIterator;
04525         }
04526         if ( globalCmd )
04527             m_doc->addCommand( globalCmd );
04528     }
04529     m_gui->canvasWidget()->setFocus(); // the combo keeps focus...*/
04530 
04531 }
04532 
04533 // Called by the above, and when selecting a style in the style combobox
04534 void KWView::textStyleSelected( int index )
04535 {
04536     textStyleSelected( m_doc->styleCollection()->styleAt( index ) );
04537 }
04538 
04539 // Slot is called when selecting a framestyle in the Frames / Framestyle menu
04540 void KWView::slotFrameStyleSelected()
04541 {
04542     QString actionName = QString::fromUtf8(sender()->name());
04543     const QString prefix = FRAMESTYLE_ACTION_PREFIX;
04544     if ( actionName.startsWith( prefix ) ) {
04545         actionName = actionName.mid( prefix.length() );
04546         frameStyleSelected( m_doc->frameStyleCollection()->findStyle( actionName ) );
04547     }
04548 }
04549 
04550 void KWView::frameStyleSelected( int index )
04551 {
04552     frameStyleSelected( m_doc->frameStyleCollection()->frameStyleAt( index ) );
04553 }
04554 
04555 
04556 // Called by the above, and when selecting a style in the framestyle combobox
04557 void KWView::frameStyleSelected( KWFrameStyle *sty )
04558 {
04559     if ( !sty )
04560         return;
04561 
04562     if ( m_gui->canvasWidget()->currentFrameSetEdit() )
04563     {
04564         KWFrame * single = m_gui->canvasWidget()->currentFrameSetEdit()->currentFrame();
04565         if ( single ) {
04566 
04567             KCommand *cmd = new KWFrameStyleCommand( i18n("Apply Framestyle to Frame"), single, sty );
04568             if (cmd) {
04569                 m_doc->addCommand( cmd );
04570                 cmd->execute();
04571             }
04572         }
04573     }
04574     else
04575     { // it might be that a frame (or several frames) are selected
04576         QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
04577         if (selectedFrames.count() <= 0)
04578             return; // nope, no frames are selected.
04579         // yes, indeed frames are selected.
04580 
04581         KMacroCommand *globalCmd = new KMacroCommand( selectedFrames.count() == 1 ? i18n("Apply Framestyle to Frame") : i18n("Apply Framestyle to Frames"));
04582 
04583         QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
04584         while(framesIterator != selectedFrames.end()) {
04585             KWFrame *curFrame = (*framesIterator)->frame();
04586             KCommand *cmd = new KWFrameStyleCommand( i18n("Apply Framestyle"), curFrame, sty );
04587             if (cmd)
04588                 globalCmd->addCommand( cmd );
04589             ++framesIterator;
04590         }
04591         m_doc->addCommand( globalCmd );
04592         globalCmd->execute();
04593     }
04594 
04595     m_gui->canvasWidget()->repaintAll();
04596     m_gui->canvasWidget()->setFocus(); // the combo keeps focus...*/
04597 
04598     // Adjust GUI
04599     const int pos = m_doc->frameStyleCollection()->indexOf( sty );
04600     Q_ASSERT( pos >= 0 );
04601     m_actionFrameStyle->setCurrentItem( pos );
04602     KToggleAction* act = dynamic_cast<KToggleAction *>(actionCollection()->action( sty->name().utf8() ));
04603     if ( act )
04604         act->setChecked( true );
04605 }
04606 
04607 
04608 // Called when selecting a tablestyle in the Table / Tablestyle menu
04609 void KWView::slotTableStyleSelected()
04610 {
04611     QString actionName = QString::fromUtf8(sender()->name());
04612     const QString prefix = TABLESTYLE_ACTION_PREFIX;
04613     if ( actionName.startsWith( prefix ) ) {
04614         actionName = actionName.mid( prefix.length() );
04615         tableStyleSelected( m_doc->tableStyleCollection()->findStyle( actionName ) );
04616     }
04617 }
04618 
04619 void KWView::tableStyleSelected( int index )
04620 {
04621     tableStyleSelected( m_doc->tableStyleCollection()->tableStyleAt( index ) );
04622 }
04623 
04624 // Called by the above, and when selecting a style in the framestyle combobox
04625 void KWView::tableStyleSelected( KWTableStyle *sty )
04626 {
04627     if ( !sty )
04628         return;
04629 
04630     if ( m_gui->canvasWidget()->currentFrameSetEdit() )
04631     {
04632         KWFrame * single = m_gui->canvasWidget()->currentFrameSetEdit()->currentFrame();
04633         if ( (single) && ( single->frameSet()->type() == FT_TEXT ) )
04634         {
04635             KCommand *cmd = new KWTableStyleCommand( i18n("Apply Tablestyle to Frame"), single, sty );
04636             if (cmd) {
04637                 m_doc->addCommand( cmd );
04638                 cmd->execute();
04639             }
04640         }
04641     }
04642     else
04643     {
04644         QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
04645         if (selectedFrames.count() <= 0)
04646             return; // nope, no frames are selected.
04647 
04648         KMacroCommand *globalCmd = new KMacroCommand( selectedFrames.count() == 1 ? i18n("Apply Tablestyle to Frame") : i18n("Apply Tablestyle to Frames"));
04649 
04650         QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
04651         while(framesIterator != selectedFrames.end() ) {
04652             KWFrame *curFrame = (*framesIterator)->frame();
04653             if(dynamic_cast<KWTextFrameSet*>(curFrame->frameSet()))  {
04654                 KCommand *cmd = new KWTableStyleCommand( i18n("Apply Tablestyle to Frame"),
04655                         curFrame, sty );
04656                 if (cmd)
04657                     globalCmd->addCommand( cmd );
04658             }
04659             ++framesIterator;
04660         }
04661         m_doc->addCommand( globalCmd );
04662         globalCmd->execute();
04663     }
04664 
04665     m_gui->canvasWidget()->repaintAll();
04666     m_gui->canvasWidget()->setFocus(); // the combo keeps focus...*/
04667 
04668     // Adjust GUI
04669     int pos = m_doc->tableStyleCollection()->indexOf( sty );
04670     m_actionTableStyle->setCurrentItem( pos );
04671     KToggleAction* act = dynamic_cast<KToggleAction *>(actionCollection()->action( sty->name().utf8() ));
04672     if ( act )
04673         act->setChecked( true );
04674 }
04675 
04676 void KWView::increaseFontSize()
04677 {
04678     KWTextFrameSetEdit * edit = currentTextEdit();
04679     KoTextFormat *format = edit->currentFormat();
04680     if ( edit )
04681         textSizeSelected( edit->textFrameSet()->textObject()->docFontSize( format ) + 1 );
04682 }
04683 
04684 void KWView::decreaseFontSize()
04685 {
04686     KWTextFrameSetEdit * edit = currentTextEdit();
04687     KoTextFormat *format = edit->currentFormat();
04688     if ( edit )
04689         textSizeSelected( edit->textFrameSet()->textObject()->docFontSize( format ) - 1 );
04690 }
04691 
04692 void KWView::textSizeSelected( int size )
04693 {
04694     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04695     QPtrListIterator<KoTextFormatInterface> it( lst );
04696     KMacroCommand *globalCmd = new KMacroCommand(i18n("Change Text Size"));
04697     for ( ; it.current() ; ++it )
04698     {
04699         KCommand *cmd = it.current()->setPointSizeCommand( size );
04700         if (cmd)
04701             globalCmd->addCommand(cmd);
04702     }
04703     m_doc->addCommand(globalCmd);
04704     m_gui->canvasWidget()->setFocus(); // the combo keeps focus...
04705 }
04706 
04707 void KWView::textFontSelected( const QString & font )
04708 {
04709     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04710     if ( lst.isEmpty() ) return;
04711     QPtrListIterator<KoTextFormatInterface> it( lst );
04712     KMacroCommand* macroCmd = 0L;
04713     for ( ; it.current() ; ++it )
04714     {
04715         KCommand *cmd = it.current()->setFamilyCommand( font );
04716         if (cmd)
04717         {
04718             if ( !macroCmd )
04719                 macroCmd = new KMacroCommand( i18n("Change Text Font") );
04720             macroCmd->addCommand( cmd );
04721         }
04722     }
04723     if ( macroCmd )
04724         m_doc->addCommand( macroCmd );
04725     m_gui->canvasWidget()->setFocus(); // the combo keeps focus...
04726 }
04727 
04728 QPtrList<KoTextFormatInterface> KWView::applicableTextInterfaces() const
04729 {
04730     QPtrList<KoTextFormatInterface> lst;
04731     if (currentTextEdit())
04732     {
04733         if ( !currentTextEdit()->textObject()->protectContent())
04734         {
04735             // simply return the current textEdit
04736             lst.append( currentTextEdit() );
04737             //kdDebug() << "text frame name: " << currentTextEdit()->textFrameSet()->name() << endl;
04738             KWCollectFramesetsVisitor visitor;
04739             currentTextEdit()->textDocument()->visitSelection( KoTextDocument::Standard, &visitor ); //find all framesets in the selection
04740             const QValueList<KWFrameSet *>& frameset = visitor.frameSets();
04741             for ( QValueList<KWFrameSet *>::ConstIterator it = frameset.begin(); it != frameset.end(); ++it )
04742             {
04743                 if ( (*it)->type() == FT_TABLE )
04744                 {
04745                     KWTableFrameSet* kwtableframeset = static_cast<KWTableFrameSet *>( *it );
04746                     //kdDebug() << "table found: " << kwtableframeset->frameCount() << endl;
04747                     int const rows  = kwtableframeset->getRows();
04748                     int const cols = kwtableframeset->getColumns();
04749                     //finding all cells and add them to the interface list
04750                     for (int r=0; r<rows; ++r)
04751                     {
04752                         for (int c=0; c<cols; ++c)
04753                         {
04754                             KWTableFrameSet::Cell *cell = kwtableframeset->cell(r,c);
04755                             if (cell)
04756                             {
04757                                 kdDebug() << "adding (" << r << "," << c << ")" << endl;
04758                                 lst.append(cell);
04759                             }
04760                         }
04761                     }
04762                 }
04763             }
04764         }
04765     }
04766     else
04767     {   // it might be that a frame (or several frames) are selected
04768         // in that case, list the text framesets behind them
04769         QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
04770         QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
04771         while(framesIterator != selectedFrames.end()) {
04772             KWTextFrameSet* fs = dynamic_cast<KWTextFrameSet *>( (*framesIterator)->frame()->frameSet() );
04773             if ( fs && !lst.contains( fs )&& !fs->protectContent() )
04774                 lst.append( fs );
04775             ++framesIterator;
04776         }
04777     }
04778     return lst;
04779 }
04780 
04781 void KWView::textBold()
04782 {
04783     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04784     if ( lst.isEmpty() ) return;
04785     QPtrListIterator<KoTextFormatInterface> it( lst );
04786     KMacroCommand* macroCmd = 0L;
04787     for ( ; it.current() ; ++it )
04788     {
04789         KCommand *cmd = it.current()->setBoldCommand( m_actionFormatBold->isChecked() );
04790         if (cmd)
04791         {
04792             if ( !macroCmd )
04793                 macroCmd = new KMacroCommand( i18n("Make Text Bold") );
04794             macroCmd->addCommand(cmd);
04795         }
04796     }
04797     if(macroCmd)
04798         m_doc->addCommand(macroCmd);
04799 
04800 }
04801 
04802 void KWView::textItalic()
04803 {
04804     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04805     QPtrListIterator<KoTextFormatInterface> it( lst );
04806     KMacroCommand* macroCmd = 0L;
04807     for ( ; it.current() ; ++it )
04808     {
04809         KCommand *cmd = it.current()->setItalicCommand( m_actionFormatItalic->isChecked() );
04810         if (cmd)
04811         {
04812             if ( !macroCmd )
04813                 macroCmd = new KMacroCommand( i18n("Make Text Italic") );
04814             macroCmd->addCommand( cmd );
04815         }
04816     }
04817     if( macroCmd)
04818         m_doc->addCommand( macroCmd );
04819 }
04820 
04821 void KWView::textUnderline()
04822 {
04823     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04824     QPtrListIterator<KoTextFormatInterface> it( lst );
04825     KMacroCommand* macroCmd = 0L;
04826 
04827     for ( ; it.current() ; ++it )
04828     {
04829         KCommand *cmd = it.current()->setUnderlineCommand( m_actionFormatUnderline->isChecked() );
04830         if ( cmd )
04831         {
04832             if ( !macroCmd )
04833                 macroCmd = new KMacroCommand( i18n("Underline Text") );
04834             macroCmd->addCommand( cmd );
04835         }
04836     }
04837     if(macroCmd)
04838         m_doc->addCommand( macroCmd );
04839 }
04840 
04841 void KWView::textStrikeOut()
04842 {
04843     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04844     QPtrListIterator<KoTextFormatInterface> it( lst );
04845     KMacroCommand* macroCmd = 0L;
04846     for ( ; it.current() ; ++it )
04847     {
04848         KCommand *cmd = it.current()->setStrikeOutCommand( m_actionFormatStrikeOut->isChecked() );
04849         if ( cmd )
04850         {
04851             if ( !macroCmd )
04852                 macroCmd = new KMacroCommand( i18n("Strike Out Text") );
04853             macroCmd->addCommand( cmd );
04854         }
04855     }
04856     if( macroCmd)
04857         m_doc->addCommand( macroCmd );
04858 }
04859 
04860 void KWView::textColor()
04861 {
04862     /*        QColor color = edit->textColor();
04863               if ( KColorDialog::getColor( color ) ) {
04864               m_actionFormatColor->setColor( color );
04865               edit->setTextColor( color );
04866               }
04867     */
04868     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04869     if ( lst.isEmpty() ) return;
04870     QPtrListIterator<KoTextFormatInterface> it( lst );
04871     KMacroCommand* macroCmd = 0L;
04872     for ( ; it.current() ; ++it )
04873     {
04874         KCommand *cmd = it.current()->setTextColorCommand( m_actionFormatColor->color() );
04875         if ( cmd )
04876         {
04877             if ( !macroCmd )
04878                 macroCmd = new KMacroCommand( i18n("Set Text Color") );
04879             macroCmd->addCommand( cmd );
04880         }
04881     }
04882     if( macroCmd)
04883         m_doc->addCommand( macroCmd );
04884 }
04885 
04886 void KWView::textAlignLeft()
04887 {
04888     if ( m_actionFormatAlignLeft->isChecked() )
04889     {
04890         QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04891         QPtrListIterator<KoTextFormatInterface> it( lst );
04892         KMacroCommand* macroCmd = 0L;
04893         for ( ; it.current() ; ++it )
04894         {
04895             KCommand *cmd = it.current()->setAlignCommand( Qt::AlignLeft );
04896             if (cmd)
04897             {
04898                 if ( !macroCmd)
04899                     macroCmd = new KMacroCommand( i18n("Left-Align Text") );
04900                 macroCmd->addCommand( cmd );
04901             }
04902         }
04903         if( macroCmd )
04904             m_doc->addCommand( macroCmd );
04905     }
04906     else
04907         m_actionFormatAlignLeft->setChecked( true );
04908 }
04909 
04910 void KWView::textAlignCenter()
04911 {
04912     if ( m_actionFormatAlignCenter->isChecked() )
04913     {
04914         QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04915         QPtrListIterator<KoTextFormatInterface> it( lst );
04916         KMacroCommand* macroCmd = 0L;
04917         for ( ; it.current() ; ++it )
04918         {
04919             KCommand *cmd = it.current()->setAlignCommand( Qt::AlignHCenter );
04920             if (cmd)
04921             {
04922                 if ( !macroCmd )
04923                     macroCmd = new KMacroCommand( i18n("Center Text") );
04924                 macroCmd->addCommand( cmd );
04925             }
04926         }
04927         if( macroCmd )
04928             m_doc->addCommand( macroCmd );
04929     }
04930     else
04931         m_actionFormatAlignCenter->setChecked( true );
04932 }
04933 
04934 void KWView::textAlignRight()
04935 {
04936     if ( m_actionFormatAlignRight->isChecked() )
04937     {
04938         QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04939         QPtrListIterator<KoTextFormatInterface> it( lst );
04940         KMacroCommand* macroCmd = 0L;
04941         for ( ; it.current() ; ++it )
04942         {
04943             KCommand *cmd = it.current()->setAlignCommand( Qt::AlignRight );
04944             if ( cmd )
04945             {
04946                 if (!macroCmd )
04947                     macroCmd = new KMacroCommand( i18n("Right-Align Text") );
04948                 macroCmd->addCommand( cmd );
04949             }
04950         }
04951         if( macroCmd)
04952             m_doc->addCommand( macroCmd );
04953     }
04954     else
04955         m_actionFormatAlignRight->setChecked( true );
04956 }
04957 
04958 void KWView::textAlignBlock()
04959 {
04960     if ( m_actionFormatAlignBlock->isChecked() )
04961     {
04962         QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04963         QPtrListIterator<KoTextFormatInterface> it( lst );
04964         KMacroCommand* macroCmd = 0L;
04965         for ( ; it.current() ; ++it )
04966         {
04967             KCommand *cmd = it.current()->setAlignCommand( Qt::AlignJustify );
04968             if ( cmd )
04969             {
04970                 if ( !macroCmd )
04971                     macroCmd = new KMacroCommand( i18n("Justify Text") );
04972                 macroCmd->addCommand( cmd );
04973             }
04974         }
04975         if( macroCmd)
04976             m_doc->addCommand( macroCmd );
04977     }
04978     else
04979         m_actionFormatAlignBlock->setChecked( true );
04980 }
04981 
04982 void KWView::setSpacing( KoParagLayout::SpacingType spacing, const QString& commandName)
04983 {
04984   QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
04985   if ( lst.isEmpty() ) return;
04986   QPtrListIterator<KoTextFormatInterface> it( lst );
04987   KMacroCommand* macroCmd = 0L;
04988   for ( ; it.current() ; ++it )
04989   {
04990     KoParagLayout layout( *it.current()->currentParagLayoutFormat() );
04991     layout.lineSpacingType = spacing;
04992 
04993     KCommand *cmd = it.current()->setParagLayoutFormatCommand( &layout, KoParagLayout::LineSpacing );
04994     if (cmd)
04995     {
04996       if ( !macroCmd )
04997         macroCmd = new KMacroCommand( commandName );
04998       macroCmd->addCommand(cmd);
04999     }
05000   }
05001   if( macroCmd)
05002     m_doc->addCommand(macroCmd);
05003 }
05004 
05005 void KWView::textSpacingSingle()
05006 {
05007   if ( m_actionFormatSpacingSingle->isChecked() )
05008     setSpacing( KoParagLayout::LS_SINGLE, i18n("Set Single Line Spacing") );
05009   else
05010     m_actionFormatSpacingSingle->setChecked( true );
05011 }
05012 
05013 void KWView::textSpacingOneAndHalf()
05014 {
05015   if ( m_actionFormatSpacingOneAndHalf->isChecked() )
05016     setSpacing( KoParagLayout::LS_ONEANDHALF, i18n("Set One and a Half Line Spacing") );
05017   else
05018     m_actionFormatSpacingOneAndHalf->setChecked( true );
05019 }
05020 
05021 void KWView::textSpacingDouble()
05022 {
05023   if ( m_actionFormatSpacingDouble->isChecked() )
05024     setSpacing( KoParagLayout::LS_DOUBLE, i18n("Set Double Line Spacing") );
05025   else
05026     m_actionFormatSpacingDouble->setChecked( true );
05027 }
05028 
05029 void KWView::slotCounterStyleSelected()
05030 {
05031     QString actionName = QString::fromLatin1(sender()->name());
05032     QString styleStr = actionName.mid(13);
05033     //kdDebug() << "KWView::slotCounterStyleSelected styleStr=" << styleStr << endl;
05034     KoParagCounter::Style style = (KoParagCounter::Style)(styleStr.toInt());
05035     KoParagCounter c;
05036     if ( style == KoParagCounter::STYLE_NONE )
05037         c.setNumbering( KoParagCounter::NUM_NONE );
05038     else {
05039         c.setNumbering( KoParagCounter::NUM_LIST );
05040         c.setStyle( style );
05041         if ( c.isBullet() )
05042             c.setSuffix( QString::null );
05043         else
05044             c.setSuffix( "." );
05045         // TODO save this setting, to use the last one selected in the dialog?
05046         // (same for custom bullet char etc.)
05047 
05048         // 68927: restart numbering, by default, if last parag wasn't numbered
05049         // (and if we're not applying this to a selection)
05050         if ( currentTextEdit() && !currentTextEdit()->textFrameSet()->hasSelection() ) {
05051             KoTextParag* parag = currentTextEdit()->cursor()->parag();
05052             if ( parag->prev() && !parag->prev()->counter() )
05053                 c.setRestartCounter(true);
05054         }
05055     }
05056 
05057     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05058     QPtrListIterator<KoTextFormatInterface> it( lst );
05059     KMacroCommand* macroCmd = 0L;
05060     for ( ; it.current() ; ++it )
05061     {
05062         KCommand *cmd = it.current()->setCounterCommand( c );
05063         if ( cmd )
05064         {
05065             if ( !macroCmd )
05066                 macroCmd=new KMacroCommand( i18n("Change List Type") );
05067             macroCmd->addCommand( cmd );
05068         }
05069     }
05070     if( macroCmd)
05071         m_doc->addCommand( macroCmd );
05072 }
05073 
05074 void KWView::textSuperScript()
05075 {
05076     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05077     if ( lst.isEmpty() ) return;
05078     QPtrListIterator<KoTextFormatInterface> it( lst );
05079     KMacroCommand* macroCmd = 0L;
05080     for ( ; it.current() ; ++it )
05081     {
05082         KCommand *cmd = it.current()->setTextSuperScriptCommand(m_actionFormatSuper->isChecked());
05083         if (cmd)
05084         {
05085             if ( !macroCmd )
05086                 macroCmd = new KMacroCommand( i18n("Make Text Superscript") );
05087             macroCmd->addCommand(cmd);
05088         }
05089     }
05090     if( macroCmd)
05091         m_doc->addCommand(macroCmd);
05092     if (m_actionFormatSuper->isChecked() )
05093         m_actionFormatSub->setChecked( false );
05094 }
05095 
05096 void KWView::textSubScript()
05097 {
05098     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05099     if ( lst.isEmpty() ) return;
05100     QPtrListIterator<KoTextFormatInterface> it( lst );
05101     KMacroCommand* macroCmd = 0L;
05102     for ( ; it.current() ; ++it )
05103     {
05104         KCommand *cmd = it.current()->setTextSubScriptCommand(m_actionFormatSub->isChecked());
05105         if (cmd)
05106         {
05107             if ( !macroCmd )
05108                 macroCmd = new KMacroCommand( i18n("Make Text Subscript") );
05109             macroCmd->addCommand(cmd);
05110         }
05111     }
05112     if( macroCmd )
05113         m_doc->addCommand(macroCmd);
05114     if (m_actionFormatSub->isChecked() )
05115         m_actionFormatSuper->setChecked( false );
05116 }
05117 
05118 void KWView::changeCaseOfText()
05119 {
05120     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05121     if ( lst.isEmpty() ) return;
05122     QPtrListIterator<KoTextFormatInterface> it( lst );
05123     KoChangeCaseDia *caseDia=new KoChangeCaseDia( this,"change case" );
05124     if(caseDia->exec())
05125     {
05126         KMacroCommand* macroCmd = 0L;
05127         for ( ; it.current() ; ++it )
05128         {
05129             KCommand *cmd = it.current()->setChangeCaseOfTextCommand(caseDia->getTypeOfCase());
05130             if (cmd)
05131             {
05132                 if ( !macroCmd )
05133                     macroCmd = new KMacroCommand( i18n("Change Case of Text") );
05134                 macroCmd->addCommand(cmd);
05135             }
05136         }
05137         if( macroCmd )
05138             m_doc->addCommand(macroCmd);
05139     }
05140     delete caseDia;
05141 }
05142 
05143 void KWView::editPersonalExpr()
05144 {
05145    KWEditPersonnalExpression *personalDia=new KWEditPersonnalExpression( this );
05146    if(personalDia->exec())
05147        m_doc->refreshMenuExpression();
05148    delete personalDia;
05149 }
05150 
05151 
05152 void KWView::textIncreaseIndent()
05153 {
05154     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05155     if ( lst.isEmpty() ) return;
05156     QPtrListIterator<KoTextFormatInterface> it( lst );
05157     double leftMargin=0.0;
05158     if(!lst.isEmpty())
05159         leftMargin=lst.first()->currentParagLayoutFormat()->margins[QStyleSheetItem::MarginLeft];
05160     double indent = m_doc->indentValue();
05161     double newVal = leftMargin + indent;
05162     KMacroCommand* macroCmd = 0L;
05163     for ( ; it.current() ; ++it )
05164     {
05165         KCommand *cmd = it.current()->setMarginCommand( QStyleSheetItem::MarginLeft, newVal );
05166         if (cmd)
05167         {
05168             if ( !macroCmd )
05169                 macroCmd = new KMacroCommand( i18n("Increase Paragraph Depth") );
05170             macroCmd->addCommand(cmd);
05171         }
05172     }
05173     if( macroCmd)
05174         m_doc->addCommand(macroCmd);
05175     if(!lst.isEmpty())
05176     {
05177         const KoParagLayout *layout=lst.first()->currentParagLayoutFormat();
05178         showRulerIndent( layout->margins[QStyleSheetItem::MarginLeft], layout->margins[QStyleSheetItem::MarginFirstLine], layout->margins[QStyleSheetItem::MarginRight], lst.first()->rtl());
05179     }
05180 #if 0
05181 
05182 
05183     KWTextFrameSetEdit * edit = currentTextEdit();
05184     if ( edit )
05185     {
05186         double leftMargin = edit->currentLeftMargin();
05187         double indent = m_doc->indentValue();
05188         double newVal = leftMargin + indent;
05189         // Test commented out. This breaks with the DTP case... The user can put
05190         // a frame anywhere, even closer to the edges than left/right border allows (DF).
05191         //if( newVal <= (m_doc->ptPaperWidth()-m_doc->ptRightBorder()-m_doc->ptLeftBorder()))
05192         {
05193             KCommand *cmd=edit->setMarginCommand( QStyleSheetItem::MarginLeft, newVal );
05194             if(cmd)
05195                 m_doc->addCommand(cmd);
05196         }
05197     }
05198 #endif
05199 }
05200 
05201 void KWView::textDecreaseIndent()
05202 {
05203     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05204     if ( lst.isEmpty() ) return;
05205     QPtrListIterator<KoTextFormatInterface> it( lst );
05206     double leftMargin=0.0;
05207     if(!lst.isEmpty())
05208         leftMargin=lst.first()->currentParagLayoutFormat()->margins[QStyleSheetItem::MarginLeft];
05209     double indent = m_doc->indentValue();
05210     double newVal = leftMargin - indent;
05211     KMacroCommand* macroCmd = 0L;
05212     for ( ; it.current() ; ++it )
05213     {
05214         KCommand *cmd = it.current()->setMarginCommand( QStyleSheetItem::MarginLeft, QMAX( newVal, 0 ) );
05215         if (cmd)
05216         {
05217             if ( !macroCmd )
05218                 macroCmd = new KMacroCommand( i18n("Decrease Paragraph Depth") );
05219             macroCmd->addCommand(cmd);
05220         }
05221     }
05222     if( macroCmd)
05223         m_doc->addCommand(macroCmd);
05224     if(!lst.isEmpty())
05225     {
05226         const KoParagLayout *layout=lst.first()->currentParagLayoutFormat();
05227         showRulerIndent( layout->margins[QStyleSheetItem::MarginLeft], layout->margins[QStyleSheetItem::MarginFirstLine], layout->margins[QStyleSheetItem::MarginRight], lst.first()->rtl());
05228     }
05229 
05230 
05231 #if 0
05232     KWTextFrameSetEdit * edit = currentTextEdit();
05233     if ( edit )
05234     {
05235         double leftMargin = edit->currentLeftMargin();
05236         if ( leftMargin > 0 )
05237         {
05238             double indent = m_doc->indentValue();
05239             double newVal = leftMargin - indent;
05240             KCommand *cmd=edit->setMarginCommand( QStyleSheetItem::MarginLeft, QMAX( newVal, 0 ) );
05241             if(cmd)
05242                 m_doc->addCommand(cmd);
05243         }
05244     }
05245 #endif
05246 }
05247 
05248 
05249 void KWView::textDefaultFormat()
05250 {
05251     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05252     if ( lst.isEmpty() ) return;
05253     QPtrListIterator<KoTextFormatInterface> it( lst );
05254     KMacroCommand* macroCmd = 0L;
05255     for ( ; it.current() ; ++it )
05256     {
05257         KCommand *cmd = it.current()->setDefaultFormatCommand();
05258         if (cmd)
05259         {
05260             if ( !macroCmd )
05261                 macroCmd = new KMacroCommand( i18n("Default Format") );
05262             macroCmd->addCommand(cmd);
05263         }
05264     }
05265     if( macroCmd)
05266         m_doc->addCommand(macroCmd);
05267 }
05268 
05269 
05270 void KWView::borderOutline()
05271 {
05272     bool on = m_actionBorderOutline->isChecked();
05273     if(m_actionBorderLeft->isChecked() != on) {
05274         m_actionBorderLeft->setChecked(on);
05275         borderLeft();
05276     }
05277     if(m_actionBorderRight->isChecked() != on) {
05278         m_actionBorderRight->setChecked(on);
05279         borderRight();
05280     }
05281     if(m_actionBorderTop->isChecked() != on) {
05282         m_actionBorderTop->setChecked(on);
05283         borderTop();
05284     }
05285     if(m_actionBorderBottom->isChecked() != on) {
05286         m_actionBorderBottom->setChecked(on);
05287         borderBottom();
05288     }
05289 }
05290 
05291 void KWView::borderLeft() {
05292     borderChanged(KoBorder::LeftBorder);
05293 }
05294 
05295 void KWView::borderRight() {
05296     borderChanged(KoBorder::RightBorder);
05297 }
05298 
05299 void KWView::borderTop() {
05300     borderChanged(KoBorder::TopBorder);
05301 }
05302 
05303 void KWView::borderBottom() {
05304     borderChanged(KoBorder::BottomBorder);
05305 }
05306 
05307 void KWView::borderChanged(KoBorder::BorderType type) {
05308     KoBorder border;
05309     border.setPenWidth( m_actionBorderWidth->currentText().toInt() );
05310     border.color = m_actionBorderColor->color();
05311     border.setStyle( KoBorder::getStyle( m_actionBorderStyle->currentText() ) );
05312     bool enabled = false;
05313     QString comment;
05314     switch(type) {
05315         case KoBorder::LeftBorder:
05316             enabled = m_actionBorderLeft->isChecked();
05317             comment = i18n("Change Left Frame Border");
05318             break;
05319         case KoBorder::RightBorder:
05320             enabled = m_actionBorderRight->isChecked();
05321             comment = i18n("Change Right Frame Border");
05322             break;
05323         case KoBorder::TopBorder:
05324             enabled = m_actionBorderTop->isChecked();
05325             comment = i18n("Change Top Frame Border");
05326             break;
05327         case KoBorder::BottomBorder:
05328         default:
05329             enabled = m_actionBorderBottom->isChecked();
05330             comment = i18n("Change Bottom Frame Border");
05331             break;
05332     }
05333     if(!enabled)
05334         border.setPenWidth(0);
05335 
05336     KCommand *cmd = 0;
05337     KWTextFrameSetEdit *edit = currentTextEdit();
05338     if ( edit ) {
05339         KoBorder left = edit->border(KoBorder::LeftBorder);
05340         KoBorder right = edit->border(KoBorder::RightBorder);
05341         KoBorder top = edit->border(KoBorder::TopBorder);
05342         KoBorder bottom = edit->border(KoBorder::BottomBorder);
05343         if(type == KoBorder::LeftBorder)
05344             left = border;
05345         else if(type == KoBorder::RightBorder)
05346             right = border;
05347         else if(type == KoBorder::TopBorder)
05348             top = border;
05349         else
05350             bottom = border;
05351         cmd=edit->setBordersCommand( left, right, top, bottom );
05352     }
05353     else {
05354         QPtrList<FrameIndex> indexes;
05355         QPtrList<KWFrameBorderCommand::FrameBorderTypeStruct> borders;
05356         QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
05357         QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
05358         for(;framesIterator != selectedFrames.end(); ++framesIterator) {
05359             if( !(*framesIterator)->selected() ) continue;
05360             KWFrame *frame = (*framesIterator)->frame();
05361             indexes.append(new FrameIndex( frame ));
05362             KWFrameBorderCommand::FrameBorderTypeStruct *bts =
05363                 new KWFrameBorderCommand::FrameBorderTypeStruct;
05364             bts->m_EFrameType = type;
05365             if(type == KoBorder::LeftBorder)
05366                 bts->m_OldBorder=frame->leftBorder();
05367             else if(type == KoBorder::RightBorder)
05368                 bts->m_OldBorder=frame->rightBorder();
05369             else if(type == KoBorder::TopBorder)
05370                 bts->m_OldBorder=frame->topBorder();
05371             else
05372                 bts->m_OldBorder=frame->bottomBorder();
05373             borders.append(bts);
05374         }
05375         if(indexes.count() > 0)
05376             cmd=new KWFrameBorderCommand(comment, indexes, borders, border);
05377     }
05378     if(cmd) {
05379         cmd->execute();
05380         m_doc->addCommand( cmd );
05381     }
05382     // update actions.
05383     m_actionBorderOutline->setChecked(
05384             m_actionBorderLeft->isChecked() && m_actionBorderRight->isChecked() &&
05385             m_actionBorderTop->isChecked() && m_actionBorderBottom->isChecked());
05386 }
05387 
05388 void KWView::backgroundColor()
05389 {
05390     QColor backColor = m_actionBackgroundColor->color();
05391     // ### TODO port to applicableTextInterfaces ? Hmm, careful with the "frame" case.
05392     KWTextFrameSetEdit *edit = currentTextEdit();
05393     if ( m_gui)
05394     {
05395         if(edit)
05396         {
05397             KCommand *cmd=edit->setTextBackgroundColorCommand(backColor);
05398             if( cmd)
05399                 m_doc->addCommand( cmd );
05400         }
05401         else
05402             m_gui->canvasWidget()->setFrameBackgroundColor( backColor );
05403     }
05404 }
05405 
05406 void KWView::resizeEvent( QResizeEvent *e )
05407 {
05408     QWidget::resizeEvent( e );
05409     if ( m_gui )
05410     {
05411         m_gui->resize( width(), height() );
05412         QString s = m_actionViewZoom->currentText();
05413         if ( !KoZoomMode::isConstant(s) )
05414             viewZoom( s );
05415     }
05416 }
05417 
05418 void KWView::guiActivateEvent( KParts::GUIActivateEvent *ev )
05419 {
05420     if ( ev->activated() )
05421     {
05422         initGui();
05423         if (m_doc->isEmbedded() ) {
05424             // Get zoom level from KoView, i.e. from the parent view
05425             const int zoom = qRound( KoView::zoom() * 100 );
05426             setZoom( zoom, true );
05427             showZoom( zoom );
05428         }
05429     }
05430     KoView::guiActivateEvent( ev );
05431 }
05432 
05433 void KWView::tabListChanged( const KoTabulatorList & tabList )
05434 {
05435     if(!m_doc->isReadWrite())
05436         return;
05437     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05438     if ( lst.isEmpty() ) return;
05439     QPtrListIterator<KoTextFormatInterface> it( lst );
05440     KMacroCommand* macroCmd = 0L;
05441     for ( ; it.current() ; ++it )
05442     {
05443         KCommand *cmd = it.current()->setTabListCommand( tabList );
05444         if (cmd)
05445         {
05446             if ( !macroCmd )
05447                 macroCmd = new KMacroCommand(i18n("Change Tabulator") );
05448             macroCmd->addCommand(cmd);
05449         }
05450     }
05451     if(macroCmd)
05452         m_doc->addCommand(macroCmd);
05453 }
05454 
05455 void KWView::newPageLayout( const KoPageLayout &layout )
05456 {
05457     QString mode = viewMode()->type();
05458     bool state = (mode!="ModeText");
05459     if ( !state )
05460         return;
05461 
05462     KoPageLayout pgLayout;
05463     KoColumns cl;
05464     KoKWHeaderFooter hf;
05465     m_doc->getPageLayout( pgLayout, cl, hf );
05466 
05467     if(layout==pgLayout)
05468         return;
05469 
05470     KWPageLayoutStruct oldLayout( pgLayout, cl, hf );
05471 
05472     m_doc->setPageLayout( layout, cl, hf );
05473 
05474     KWPageLayoutStruct newLayout( layout, cl, hf );
05475 
05476     KWTextFrameSetEdit *edit = currentTextEdit();
05477     if (edit)
05478         edit->textFrameSet()->clearUndoRedoInfo();
05479     KCommand *cmd = new KWPageLayoutCommand( i18n("Change Layout"), m_doc, oldLayout, newLayout );
05480     m_doc->addCommand(cmd);
05481 }
05482 
05483 void KWView::slotPageLayoutChanged( const KoPageLayout& layout )
05484 {
05485     // This is connected to a signal of KWDocument, so that when the
05486     // above method, or any other way of changing the page layout happens,
05487     // the rulers are updated in all views.
05488     viewMode()->setPageLayout( m_gui->getHorzRuler(), m_gui->getVertRuler(), layout );
05489     m_gui->canvasWidget()->repaintAll();
05490 }
05491 
05492 void KWView::newFirstIndent( double firstIndent )
05493 {
05494     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05495     if ( lst.isEmpty() ) return;
05496     QPtrListIterator<KoTextFormatInterface> it( lst );
05497     KMacroCommand* macroCmd = 0L;
05498     for ( ; it.current() ; ++it )
05499     {
05500         KCommand *cmd = it.current()->setMarginCommand( QStyleSheetItem::MarginFirstLine, firstIndent );
05501         if (cmd)
05502         {
05503             if ( !macroCmd )
05504                 macroCmd = new KMacroCommand(i18n("Change First Line Indent"));
05505             macroCmd->addCommand(cmd);
05506         }
05507     }
05508     if(macroCmd)
05509         m_doc->addCommand(macroCmd);
05510 }
05511 
05512 void KWView::newLeftIndent( double leftIndent )
05513 {
05514     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05515     if ( lst.isEmpty() ) return;
05516     QPtrListIterator<KoTextFormatInterface> it( lst );
05517     KMacroCommand* macroCmd = 0L;
05518     for ( ; it.current() ; ++it )
05519     {
05520         KCommand *cmd = it.current()->setMarginCommand( QStyleSheetItem::MarginLeft, leftIndent );
05521         if (cmd)
05522         {
05523             if ( !macroCmd )
05524                 macroCmd = new KMacroCommand(i18n("Change Indent") );
05525             macroCmd->addCommand(cmd);
05526         }
05527     }
05528     if(macroCmd)
05529         m_doc->addCommand(macroCmd);
05530 
05531 }
05532 
05533 void KWView::newRightIndent( double rightIndent)
05534 {
05535 
05536     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05537     if ( lst.isEmpty() ) return;
05538     QPtrListIterator<KoTextFormatInterface> it( lst );
05539     KMacroCommand* macroCmd = 0L;
05540     for ( ; it.current() ; ++it )
05541     {
05542         KCommand *cmd = it.current()->setMarginCommand( QStyleSheetItem::MarginRight, rightIndent );
05543         if (cmd)
05544         {
05545             if ( !macroCmd )
05546                 macroCmd = new KMacroCommand(i18n("Change Indent") );
05547             macroCmd->addCommand(cmd);
05548         }
05549     }
05550     if(macroCmd)
05551         m_doc->addCommand(macroCmd);
05552 }
05553 
05554 QPopupMenu * KWView::popupMenu( const QString& name )
05555 {
05556     // factory() is 0 when right-clicking on the kword document while
05557     // an embedded object is active. KoPartManager lets the click through,
05558     // without activating us - so let's do that first.
05559     if ( !factory() )
05560         partManager()->setActivePart( m_doc, this );
05561     Q_ASSERT( factory() );
05562     if ( factory() )
05563         return ((QPopupMenu*)factory()->container( name, this ));
05564     return 0;
05565 }
05566 
05567 void KWView::startKSpell()
05568 {
05569     if ( !m_spell.kospell )
05570         m_spell.kospell = new KoSpell( m_broker, this  );
05571 
05572     // Spell-check the next paragraph
05573     Q_ASSERT( m_spell.textIterator );
05574 
05575     m_spell.kospell->check( m_spell.textIterator, true );
05576     delete m_spell.dlg;
05577     m_spell.dlg = new KSpell2::Dialog( m_spell.kospell, this );
05578     m_spell.dlg->activeAutoCorrect( true );
05579 
05580     QObject::connect( m_spell.dlg, SIGNAL(misspelling(const QString&, int)),
05581                       this, SLOT(spellCheckerMisspelling(const QString&, int)) );
05582     QObject::connect( m_spell.dlg, SIGNAL(replace(const QString&, int, const QString&)),
05583                       this, SLOT(spellCheckerCorrected(const QString&, int, const QString&)) );
05584     QObject::connect( m_spell.dlg, SIGNAL(done(const QString&) ),
05585                       this, SLOT(spellCheckerDone(const QString&)) );
05586     QObject::connect( m_spell.dlg, SIGNAL(cancel() ),
05587                       this, SLOT( spellCheckerCancel() ) );
05588     QObject::connect( m_spell.dlg, SIGNAL(autoCorrect(const QString &, const QString & ) ),
05589                       this, SLOT( spellAddAutoCorrect (const QString &, const QString &) ) );
05590 
05591     m_spell.dlg->show();
05592     //clearSpellChecker();
05593 }
05594 
05595 void KWView::spellCheckerMisspelling( const QString &old, int pos )
05596 {
05597     //kdDebug(32001) << "KWView::spellCheckerMisspelling old=" << old << " pos=" << pos << endl;
05598     KoTextObject* textobj = m_spell.kospell->currentTextObject();
05599     KoTextParag* parag = m_spell.kospell->currentParag();
05600     Q_ASSERT( textobj );
05601     Q_ASSERT( parag );
05602     if ( !textobj || !parag ) return;
05603     KWTextDocument *textdoc=static_cast<KWTextDocument *>( textobj->textDocument() );
05604     Q_ASSERT( textdoc );
05605     if ( !textdoc ) return;
05606     pos += m_spell.kospell->currentStartIndex();
05607     kdDebug(32001) << "KWView::spellCheckerMisspelling parag=" << parag->paragId() << " pos=" << pos << " length=" << old.length() << endl;
05608     textdoc->textFrameSet()->highlightPortion( parag, pos, old.length(), m_gui->canvasWidget() );
05609 }
05610 
05611 void KWView::spellCheckerCorrected( const QString &old, int pos , const QString &corr )
05612 {
05613     //kdDebug(32001) << "KWView::spellCheckerCorrected old=" << old << " corr=" << corr << " pos=" << pos << endl;
05614     KoTextObject* textobj = m_spell.kospell->currentTextObject();
05615     KoTextParag* parag = m_spell.kospell->currentParag();
05616     Q_ASSERT( textobj );
05617     Q_ASSERT( parag );
05618     if ( !textobj || !parag ) return;
05619     KWTextDocument *textdoc=static_cast<KWTextDocument *>( textobj->textDocument() );
05620     Q_ASSERT( textdoc );
05621     if ( !textdoc ) return;
05622     pos += m_spell.kospell->currentStartIndex();
05623     textdoc->textFrameSet()->highlightPortion( parag, pos, old.length(), m_gui->canvasWidget() );
05624 
05625     KoTextCursor cursor( textdoc );
05626     cursor.setParag( parag );
05627     cursor.setIndex( pos );
05628     if(!m_spell.macroCmdSpellCheck)
05629         m_spell.macroCmdSpellCheck=new KMacroCommand(i18n("Correct Misspelled Word"));
05630     m_spell.macroCmdSpellCheck->addCommand(textobj->replaceSelectionCommand(
05631         &cursor, corr, QString::null, KoTextDocument::HighlightSelection));
05632 }
05633 
05634 void KWView::spellCheckerDone( const QString & )
05635 {
05636     //kdDebug(32001) << "KWView::spellCheckerDone" << endl;
05637     KWTextDocument *textdoc=static_cast<KWTextDocument *>( m_spell.kospell->textDocument() );
05638     Q_ASSERT( textdoc );
05639     if ( textdoc )
05640         textdoc->textFrameSet()->removeHighlight();
05641 
05642     clearSpellChecker();
05643 }
05644 
05645 void KWView::clearSpellChecker(bool cancelSpellCheck)
05646 {
05647     kdDebug(32001) << "KWView::clearSpellChecker" << endl;
05648 
05649     delete m_spell.textIterator;
05650     m_spell.textIterator = 0L;
05651     delete m_spell.kospell;
05652     m_spell.kospell = 0;
05653 
05654     if ( m_spell.macroCmdSpellCheck )
05655     {
05656         if ( !cancelSpellCheck )
05657             m_doc->addCommand(m_spell.macroCmdSpellCheck);
05658         else
05659         {
05660             //reverte all changes
05661             m_spell.macroCmdSpellCheck->unexecute();
05662             delete m_spell.macroCmdSpellCheck;
05663         }
05664     }
05665     m_spell.macroCmdSpellCheck=0L;
05666     m_spell.replaceAll.clear();
05667     //m_doc->setReadWrite(true);
05668 }
05669 
05670 void KWView::spellCheckerCancel()
05671 {
05672     kdDebug()<<"void KWView::spellCheckerCancel() \n";
05673     spellCheckerRemoveHighlight();
05674     //we add command :( => don't add command and reverte changes
05675     clearSpellChecker(true);
05676 }
05677 
05678 
05679 void KWView::spellCheckerRemoveHighlight()
05680 {
05681     KoTextObject* textobj = m_spell.kospell->currentTextObject();
05682     if ( textobj ) {
05683         KWTextDocument *textdoc=static_cast<KWTextDocument *>( textobj->textDocument() );
05684         if ( textdoc )
05685             textdoc->textFrameSet()->removeHighlight();
05686     }
05687     KWTextFrameSetEdit * edit = currentTextEdit();
05688     if (edit)
05689         edit->drawCursor( TRUE );
05690 }
05691 
05692 void KWView::spellAddAutoCorrect (const QString & originalword, const QString & newword)
05693 {
05694     m_doc->autoFormat()->addAutoFormatEntry( originalword, newword );
05695 }
05696 
05697 void KWView::configure()
05698 {
05699     KWConfig configDia( this );
05700     configDia.exec();
05701 }
05702 
05703 KWTextFrameSetEdit *KWView::currentTextEdit() const
05704 {
05705     if (!m_gui)
05706         return 0L;
05707     KWFrameSetEdit * edit = m_gui->canvasWidget()->currentFrameSetEdit();
05708     if ( edit )
05709         return dynamic_cast<KWTextFrameSetEdit *>(edit->currentTextEdit());
05710     return 0L;
05711 }
05712 
05713 void KWView::slotFrameSetEditChanged()
05714 {
05715     KWTextFrameSetEdit * edit = currentTextEdit();
05716     bool rw = koDocument()->isReadWrite();
05717     bool selectedFrames = frameViewManager()->selectedFrames().count() > 0;
05718     bool hasSelection = false;
05719     if ( edit ) {
05720         hasSelection = edit->textFrameSet()->hasSelection();
05721         if ( edit->textFrameSet()->textObject()->protectContent())
05722             rw = false;
05723     }
05724     else {
05725         KWFrameSetEdit * e = m_gui->canvasWidget()->currentFrameSetEdit();
05726         if ( e && e->frameSet()->type() == FT_FORMULA ) {
05727             hasSelection = true;
05728         }
05729     }
05730     m_actionEditCut->setEnabled( hasSelection && rw );
05731 
05732     m_actionEditCopy->setEnabled( hasSelection );
05733     m_actionEditReplace->setEnabled( /*edit &&*/ rw );
05734     clipboardDataChanged(); // for paste
05735 
05736     bool state = (edit != 0 | selectedFrames) && rw;
05737     m_actionEditSelectAll->setEnabled(state);
05738     m_actionEditSelectCurrentFrame->setEnabled(state);
05739     m_actionInsertComment->setEnabled( state );
05740     m_actionFormatDefault->setEnabled( state );
05741     m_actionFormatFont->setEnabled( state );
05742     m_actionFormatFontSize->setEnabled( state );
05743     m_actionFormatFontFamily->setEnabled( state );
05744     m_actionAddBookmark->setEnabled(state);
05745     m_actionBackgroundColor->setEnabled( state );
05746     m_actionFormatStyleMenu->setEnabled( state );
05747     m_actionFormatBold->setEnabled( state );
05748     m_actionFormatItalic->setEnabled( state );
05749     m_actionFormatUnderline->setEnabled( state );
05750     m_actionFormatStrikeOut->setEnabled( state );
05751     m_actionFormatColor->setEnabled( state );
05752     m_actionFormatAlignLeft->setEnabled( state );
05753     m_actionFormatAlignCenter->setEnabled( state );
05754     m_actionFormatAlignRight->setEnabled( state );
05755     m_actionFormatAlignBlock->setEnabled( state );
05756 
05757     m_actionBorderLeft->setEnabled( state );
05758     m_actionBorderRight->setEnabled( state );
05759     m_actionBorderTop->setEnabled( state );
05760     m_actionBorderBottom->setEnabled( state );
05761     m_actionBorderOutline->setEnabled( state );
05762     m_actionBorderColor->setEnabled( state );
05763     m_actionBorderWidth->setEnabled( state );
05764     m_actionBorderStyle->setEnabled( state );
05765 
05766 
05767     //m_actionFormatIncreaseIndent->setEnabled(state);
05768     m_actionInsertLink->setEnabled(state);
05769     m_actionCreateStyleFromSelection->setEnabled( state /*&& hasSelection*/);
05770     m_actionConvertToTextBox->setEnabled( state && hasSelection);
05771     m_actionAddPersonalExpression->setEnabled( state && hasSelection);
05772     m_actionSortText->setEnabled( state && hasSelection);
05773     bool goodleftMargin=false;
05774     if(state && edit)
05775         goodleftMargin=(edit->currentLeftMargin()>0);
05776 
05777     m_actionFormatDecreaseIndent->setEnabled(goodleftMargin);
05778     bool isFootNoteSelected = ((rw && edit && !edit->textFrameSet()->isFootEndNote())||(!edit&& rw));
05779     m_actionFormatBullet->setEnabled(isFootNoteSelected);
05780     m_actionFormatNumber->setEnabled(isFootNoteSelected);
05781     m_actionFormatStyle->setEnabled(isFootNoteSelected);
05782     m_actionFormatSpacingSingle->setEnabled(rw);
05783     m_actionFormatSpacingOneAndHalf->setEnabled(rw);
05784     m_actionFormatSpacingDouble->setEnabled(rw);
05785     m_actionFormatSuper->setEnabled(rw);
05786     m_actionFormatSub->setEnabled(rw);
05787     m_actionFormatParag->setEnabled(state);
05788     m_actionInsertSpecialChar->setEnabled(state);
05789     m_actionSpellCheck->setEnabled(state);
05790 
05791     m_actionChangeCase->setEnabled( (rw && !edit)|| (state && hasSelection) );
05792 
05793     if ( edit && edit->textFrameSet()->protectContent())
05794     {
05795         m_actionChangeCase->setEnabled( false );
05796         m_actionEditCut->setEnabled( false );
05797     }
05798     else
05799         m_actionChangeCase->setEnabled( true );
05800 
05801     updateTableActions( frameViewManager()->selectedFrames() ) ;
05802 
05803     m_actionInsertFormula->setEnabled(state && (viewMode()->type()!="ModeText"));
05804     actionInsertVariable->setEnabled(state);
05805     m_actionInsertExpression->setEnabled(state);
05806 
05807     changeFootEndNoteState();
05808     //frameset different of header/footer
05809     state= state && edit && edit->frameSet() && !edit->frameSet()->isHeaderOrFooter() && !edit->frameSet()->groupmanager() && !edit->frameSet()->isFootEndNote();
05810     m_actionInsertContents->setEnabled(state);
05811     m_actionInsertFrameBreak->setEnabled( state );
05812     updatePageInfo();
05813 }
05814 
05815 void KWView::changeFootEndNoteState()
05816 {
05817     bool rw = koDocument()->isReadWrite();
05818     KWTextFrameSetEdit * edit = currentTextEdit();
05819     QString mode = viewMode()->type();
05820 
05821     bool isEditableFrameset = edit && edit->frameSet() && edit->frameSet()->isMainFrameset();
05822     bool ok = rw && isEditableFrameset && (mode!="ModeText");
05823     m_actionInsertFootEndNote->setEnabled( ok );
05824     m_actionEditFootEndNote->setEnabled( ok );
05825 }
05826 
05827 void KWView::changeFootNoteMenuItem( bool footnote)
05828 {
05829     m_actionEditFootEndNote->setText( footnote? i18n("Edit Footnote"): i18n("Edit Endnote"));
05830     m_actionChangeFootNoteType->setText( footnote? i18n("Change Footnote Parameter"):i18n("Change Endnote Parameter"));
05831 }
05832 
05833 void KWView::slotUpdateRuler()
05834 {
05835     KWCanvas* canvas = m_gui->canvasWidget();
05836     QRect r( canvas->viewMode()->rulerFrameRect() );
05837     if ( !r.isNull() )
05838     {
05839         m_gui->getHorzRuler()->setFrameStartEnd( r.left(), r.right() );
05840         m_gui->getVertRuler()->setFrameStartEnd( r.top(), r.bottom() );
05841     }
05842     canvas->updateRulerOffsets();
05843 }
05844 
05845 void KWView::frameSelectedChanged()
05846 {
05847     bool rw = koDocument()->isReadWrite();
05848     QValueList<KWFrameView*> selectedFrames = frameViewManager()->selectedFrames();
05849 
05850     m_actionFormatFrameSet->setEnabled( selectedFrames.count() >= 1 );
05851     if ( rw && selectedFrames.count() >= 1 )
05852     {
05853         bool okForDelete = true;
05854         bool okForCopy = true;
05855         bool okForLowerRaise = false;
05856         bool okForChangeParagStyle = true;
05857         bool okForChangeInline = true;
05858         bool containsCellFrame = false;
05859         bool containsMainFrame = false;
05860 
05861         QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
05862         while(framesIterator != selectedFrames.end() && (okForDelete || okForLowerRaise ||
05863                     okForChangeParagStyle || okForChangeInline) ) {
05864             // Check we selected no footer nor header
05865             bool isFootNote = (*framesIterator)->frame()->frameSet()->isFootEndNote();
05866             bool headerFooterFootNote = isFootNote ||
05867                 (*framesIterator)->frame()->frameSet()->isHeaderOrFooter();
05868             bool isMainWPFrame = (*framesIterator)->frame()->frameSet()->isMainFrameset();
05869             okForChangeParagStyle &= !isFootNote;
05870             okForCopy &= !headerFooterFootNote;
05871 
05872             okForDelete &= !headerFooterFootNote;
05873             okForDelete &= !isMainWPFrame;
05874 
05875             // Check we selected a frame we can lower raise.
05876             // The header, footer, main frameset, footnotes and inline frames can't be raised.
05877             // As soon as we find one who we can lower/raise open the option.
05878             okForLowerRaise |= !(isMainWPFrame || headerFooterFootNote || (*framesIterator)->frame()->frameSet()->isFloating());
05879             okForChangeInline &= !(isMainWPFrame || headerFooterFootNote );
05880 
05881             if ( (*framesIterator)->frame()->frameSet()->groupmanager() )
05882                 containsCellFrame = true;
05883             if ( isMainWPFrame )
05884                 containsMainFrame = true;
05885             ++framesIterator;
05886         }
05887         m_actionEditDelFrame->setEnabled( okForDelete );
05888         m_actionEditCut->setEnabled( okForDelete && !containsCellFrame );
05889         m_actionEditCopy->setEnabled( selectedFrames.count() >= 1 && okForCopy && !containsMainFrame && !containsCellFrame);
05890 
05891         m_actionLowerFrame->setEnabled( okForLowerRaise );
05892         m_actionRaiseFrame->setEnabled( okForLowerRaise );
05893         m_actionSendBackward->setEnabled( okForLowerRaise );
05894         m_actionBringToFront->setEnabled( okForLowerRaise );
05895         m_actionFormatBullet->setEnabled( okForChangeParagStyle );
05896         m_actionFormatNumber->setEnabled( okForChangeParagStyle );
05897         m_actionFormatStyle->setEnabled( okForChangeParagStyle);
05898         m_actionInlineFrame->setEnabled( okForChangeInline);
05899 
05900         KWFrame *frame = selectedFrames[0]->frame();
05901         updateBorderButtons(frame->leftBorder(), frame->rightBorder(), frame->topBorder(),
05902                 frame->bottomBorder());
05903     } else
05904     {   // readonly document, or no frame selected -> disable
05905         m_actionEditDelFrame->setEnabled( false );
05906         m_actionInlineFrame->setEnabled(false);
05907         m_actionEditCut->setEnabled( false );
05908         m_actionLowerFrame->setEnabled( false );
05909         m_actionRaiseFrame->setEnabled( false );
05910         m_actionSendBackward->setEnabled( false );
05911         m_actionBringToFront->setEnabled( false );
05912 
05913     }
05914     bool frameDifferentOfPart=false;
05915     if(selectedFrames.count() >= 1)
05916     {
05917         QValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
05918         while(framesIterator != selectedFrames.end()) {
05919             if ( (*framesIterator)->frame()->frameSet()->type()!=FT_PART &&
05920                     (*framesIterator)->frame()->frameSet()->type()!= FT_PICTURE) {
05921                 frameDifferentOfPart=true;
05922                 break;
05923             }
05924             ++framesIterator;
05925         }
05926     }
05927 
05928     m_actionBackgroundColor->setEnabled( (selectedFrames.count() >= 1) && frameDifferentOfPart);
05929     m_actionBackgroundColor->setText(i18n("Frame Background Color..."));
05930 
05931     if ( frameDifferentOfPart ) {
05932         KWFrame *frame = selectedFrames[0]->frame();
05933         QColor frameCol=frame->backgroundColor().color();
05934         //m_actionBackgroundColor->setText(i18n("Frame Background Color..."));
05935         m_actionBackgroundColor->setCurrentColor( frameCol.isValid()? frame->backgroundColor().color() :  QApplication::palette().color( QPalette::Active, QColorGroup::Base ));
05936     }
05937 
05938     m_actionCreateFrameStyle->setEnabled( selectedFrames.count()==1 );
05939     m_actionCreateLinkedFrame->setEnabled( selectedFrames.count()==1 );
05940 
05941     updateTableActions( selectedFrames );
05942     updatePageInfo(); // takes care of slotUpdateRuler()
05943     updateFrameStatusBarItem();
05944 
05945     QPtrList<KoTextFormatInterface> lst = applicableTextInterfaces();
05946     if ( !lst.isEmpty() )
05947     {
05948         QPtrListIterator<KoTextFormatInterface> it( lst );
05949         KoTextFormat format=*(lst.first()->currentFormat());
05950         showFormat( format );
05951 
05952         const KoParagLayout * paragLayout=lst.first()->currentParagLayoutFormat();
05953         KoParagCounter counter;
05954         if(paragLayout->counter)
05955             counter = *(paragLayout->counter);
05956         showCounter( counter );
05957         int align = paragLayout->alignment;
05958         if ( align == Qt::AlignAuto )
05959             align = Qt::AlignLeft; // ## seems hard to detect RTL here
05960         showAlign( align );
05961         KoParagLayout::SpacingType spacing=paragLayout->lineSpacingType;
05962         showSpacing( spacing );
05963     }
05964 
05965     m_gui->canvasWidget()->repaintAll(false);
05966 }
05967 
05968 
05969 void KWView::updateTableActions( QValueList<KWFrameView*> selectedFrames)
05970 {
05971     TableInfo ti(selectedFrames);
05972     KWTableFrameSet *table = m_gui->canvasWidget()->getCurrentTable();
05973     m_actionTableJoinCells->setEnabled( ti.tableCellsSelected());
05974     m_actionConvertTableToText->setEnabled( table && table->isFloating() );
05975 
05976     m_actionTableSplitCells->setEnabled( ti.oneCellSelected() );
05977 
05978     m_actionTableInsertRow->setEnabled( ti.amountRowsSelected() );
05979     m_actionTableDelRow->setEnabled( ti.amountRowsSelected() );
05980     m_actionTableInsertCol->setEnabled( ti.amountColumnsSelected() );
05981 
05982     if(ti.amountColumnsSelected() == 1)
05983         m_actionTableDelCol->setText(i18n("D&elete Current Column..."));
05984     else
05985         m_actionTableDelCol->setText(i18n("D&elete Selected Columns..."));
05986     m_actionTableDelCol->setEnabled( ti.amountColumnsSelected() > 0 );
05987     if(ti.amountRowsSelected() == 1)
05988         m_actionTableDelRow->setText(i18n("&Delete Current Row..."));
05989     else
05990         m_actionTableDelRow->setText(i18n("&Delete Selected Rows..."));
05991     m_actionTableDelRow->setEnabled( ti.amountRowsSelected() > 0 );
05992 
05993     m_actionTableResizeCol->setEnabled( ti.tableCellsSelected() );
05994     m_actionTableDelete->setEnabled( ti.tableCellsSelected() );
05995     m_actionTablePropertiesMenu->setEnabled( ti.tableCellsSelected() );
05996 
05997     m_actionTableUngroup->setEnabled( ti.tableCellsSelected() );
05998     m_actionTableProtectCells->setEnabled( ti.tableCellsSelected() );
05999     m_actionTableProtectCells->setChecked( ti.protectContentEnabled() );
06000 }
06001 
06002 void KWView::docStructChanged(int type)
06003 {
06004     KWDocStruct *m_pDocStruct=m_gui->getDocStruct();
06005     if(m_pDocStruct)
06006         m_pDocStruct->refreshTree(type);
06007     m_doc->recalcVariables(  VT_STATISTIC );
06008 }
06009 
06010 void KWView::documentModified( bool b )
06011 {
06012     if ( !statusBar() )
06013         return;
06014 
06015     if ( b )
06016         m_sbModifiedLabel->setPixmap( KGlobal::iconLoader()->loadIcon( "action-modified", KIcon::Small ) );
06017     else
06018         m_sbModifiedLabel->setText( "   " );
06019 }
06020 
06021 void KWView::changeOverwriteMode( bool b )
06022 {
06023     if ( !statusBar() )
06024         return;
06025 
06026     if ( b )
06027         m_sbOverwriteLabel->setText( ' ' + i18n( "OVER" ) + ' ' );
06028     else
06029         m_sbOverwriteLabel->setText( ' ' + i18n( "INSRT" ) + ' ' );
06030 }
06031 
06032 void KWView::setViewFrameBorders(bool b)
06033 {
06034     m_viewFrameBorders = b;
06035     // Store setting in doc, for further views and for saving
06036     m_doc->setViewFrameBorders( b );
06037 }
06038 
06039 bool KWView::doubleClickActivation() const
06040 {
06041     return TRUE;
06042 }
06043 
06044 QWidget* KWView::canvas() const
06045 {
06046     // used to be ->viewport(), but this makes no sense.
06047     // active embedded objects must be positioned relative to the real view,
06048     // to scroll around with it, instead of being children of the fixed viewport.
06049     return m_gui->canvasWidget();
06050 }
06051 
06052 int KWView::canvasXOffset() const
06053 {
06054     return m_gui->canvasWidget()->contentsX();
06055 }
06056 
06057 int KWView::canvasYOffset() const
06058 {
06059     return m_gui->canvasWidget()->contentsY();
06060 }
06061 
06062 void KWView::canvasAddChild( KoViewChild * child )
06063 {
06064     connect( m_gui->canvasWidget(), SIGNAL( viewTransformationsChanged() ),
06065              child, SLOT( reposition() ) );
06066     // Not necessary anymore
06067     //m_gui->canvasWidget()->addChild( child->frame() );
06068 }
06069 
06070 void KWView::changePicture()
06071 {
06072     KWFrameView *view = frameViewManager()->selectedFrame();
06073     KWFrame *frame = view == 0 ? 0 : view->frame();
06074     if( !frame )
06075         return;
06076     KWPictureFrameSet *frameset = static_cast<KWPictureFrameSet *>(frame->frameSet());
06077     KoPictureKey oldKey ( frameset->picture().getKey() );
06078     QString oldFile ( oldKey.filename() );
06079     KURL url;
06080     url.setPath( oldFile );
06081     if (!QDir(url.directory()).exists())
06082         oldFile = url.fileName();
06083 
06084     KoPicture picture ( KWInsertPicDia::selectPictureDia( oldFile, this ) );
06085     if ( !picture.isNull() )
06086     {
06087         KWFrameChangePictureCommand *cmd= new KWFrameChangePictureCommand( i18n("Change Picture"), FrameIndex(frame), oldKey, picture.getKey() ) ;
06088 
06089         frameset->insertPicture( picture );
06090         m_doc->frameChanged( frame );
06091         m_doc->refreshDocStructure( FT_PICTURE );
06092         m_doc->addCommand(cmd);
06093     }
06094     else
06095         kdDebug() << "KWView::changePicture cancelled" << endl;
06096 }
06097 
06098 void KWView::savePicture()
06099 {
06100     KWFrameView *view = frameViewManager()->selectedFrame();
06101     KWFrame *frame = view == 0 ? 0 : view->frame();
06102     if ( frame )//test for dcop call
06103     {
06104         KWPictureFrameSet *frameset = static_cast<KWPictureFrameSet *>(frame->frameSet());
06105         QString oldFile = frameset->picture().getKey().filename();
06106         KURL url;
06107         url.setPath( oldFile );
06108         if ( !QDir(url.directory()).exists() )
06109             oldFile = url.fileName();
06110 
06111         KoPicture picture( frameset->picture() );
06112         QString mimetype = picture.getMimeType();
06113         kdDebug() << "Picture has mime type: " << mimetype << endl;
06114         QStringList mimetypes;
06115         mimetypes << mimetype;
06116         KFileDialog fd( oldFile, QString::null, this, 0, TRUE );
06117         fd.setMimeFilter( mimetypes );
06118         fd.setCaption(i18n("Save Picture"));
06119         fd.setOperationMode(KFileDialog::Saving);
06120         if ( fd.exec() == QDialog::Accepted )
06121         {
06122             url = fd.selectedURL();
06123             if ( url.isValid() )
06124             {
06125                 if ( url.isLocalFile() )
06126                 {
06127                     QFile file( url.path() );
06128                     if ( file.open( IO_ReadWrite ) )
06129                     {
06130                         picture.save( &file );
06131                         file.close();
06132                     }
06133                     else
06134                     {
06135                         KMessageBox::error(this,
06136                                    i18n("Error during saving. Could not open '%1' for writing").arg ( url.path() ),
06137                                    i18n("Save Picture"));
06138                     }
06139                 }
06140                 else
06141                 {
06142                     KTempFile tempFile;
06143                     tempFile.setAutoDelete( true );
06144                     if ( tempFile.status() == 0 )
06145                     {
06146                         QFile file( tempFile.name() );
06147                         if ( file.open( IO_ReadWrite ) )
06148                         {
06149                             picture.save( &file );
06150                             file.close();
06151                             if ( !KIO::NetAccess::upload( tempFile.name(), url, this ) )
06152                             {
06153                               KMessageBox::sorry( this, i18n(
06154                                   "Unable to save the file to '%1'. %2.").arg( url.prettyURL() ).arg( KIO::NetAccess::lastErrorString() ),
06155                                   i18n("Save Failed") );
06156                             }
06157                         }
06158                         else
06159                             KMessageBox::error(this,
06160                                 i18n("Error during saving. Could not open '%1' temporary file for writing").arg ( file.name() ),
06161                                 i18n("Save Picture"));
06162                     }
06163                     else
06164                         KMessageBox::sorry( this, i18n(
06165                             "Error during saving. Could not create temporary file: %1.").arg( strerror( tempFile.status() ) ),
06166                             i18n("Save Picture") );
06167                 }
06168             }
06169             else
06170                 KMessageBox::sorry( this, i18n("URL %1 is invalid.").arg( url.prettyURL() ), i18n("Save Picture") );
06171         }
06172     }
06173 }
06174 
06175 void KWView::configureHeaderFooter()
06176 {
06177     KoPageLayout pgLayout;
06178     KoColumns cl;
06179     KoKWHeaderFooter kwhf;
06180     m_doc->getPageLayout( pgLayout, cl, kwhf );
06181 
06182     KWPageLayoutStruct oldLayout( pgLayout, cl, kwhf );
06183 
06184     KoHeadFoot hf;
06185     int flags = KW_HEADER_AND_FOOTER;
06186     KoUnit::Unit unit = m_doc->unit();
06187     KoUnit::Unit oldUnit = unit;
06188 
06189     if ( KoPageLayoutDia::pageLayout( pgLayout, hf, cl, kwhf, flags, unit ) ) {
06190         if( oldLayout._hf != kwhf )
06191         {
06192             KWPageLayoutStruct newLayout( pgLayout, cl, kwhf );
06193 
06194             KCommand *cmd = new KWPageLayoutCommand( i18n("Change Layout"), m_doc,
06195                                                      oldLayout, newLayout );
06196             m_doc->addCommand(cmd);
06197 
06198             m_doc->setPageLayout( pgLayout, cl, kwhf );
06199         }
06200         if ( unit != oldUnit )
06201             m_doc->setUnit( unit ); // needs undo/redo support
06202     }
06203 
06204 }
06205 
06206 void KWView::inlineFrame()
06207 {
06208     KWFrameView *view = frameViewManager()->selectedFrame();
06209     KWFrame *frame = view == 0 ? 0 : view->frame();
06210     if( !frame)
06211         return;
06212     KWFrameSet * fs = frame->frameSet();
06213     KWFrameSet * parentFs = fs->groupmanager() ? fs->groupmanager() : fs;
06214 
06215     if(m_actionInlineFrame->isChecked())
06216     {
06217 
06218         KMacroCommand* macroCmd = new KMacroCommand( i18n("Make Frameset Inline") );
06219         QValueList<FrameIndex> frameindexList;
06220         QValueList<FrameMoveStruct> frameindexMove;
06221 
06222         KoPoint initialPos = frame->topLeft();
06223         // turn non-floating frame into floating frame
06224         KWFrameSetInlineCommand *cmd = new KWFrameSetInlineCommand( i18n("Make Frameset Inline"), parentFs, true );
06225         cmd->execute();
06226 
06227         frameindexList.append( FrameIndex( frame ) );
06228         frameindexMove.append( FrameMoveStruct( initialPos, frame->topLeft() ) );
06229 
06230         KWFrameMoveCommand *cmdMoveFrame = new KWFrameMoveCommand( i18n("Move Frame"), frameindexList, frameindexMove );
06231 
06232         macroCmd->addCommand(cmdMoveFrame);
06233         macroCmd->addCommand(cmd);
06234         m_doc->addCommand(macroCmd);
06235     }
06236     else
06237     {
06238         KWFrameSetInlineCommand *cmd = new KWFrameSetInlineCommand( i18n("Make Frameset Non-Inline"), parentFs, false );
06239         m_doc->addCommand(cmd);
06240         cmd->execute();
06241     }
06242 }
06243 
06244 void KWView::openLink()
06245 {
06246     KWTextFrameSetEdit * edit = currentTextEdit();
06247     if ( edit )
06248         edit->openLink();
06249 }
06250 
06251 void KWView::changeLink()
06252 {
06253     KWTextFrameSetEdit * edit = currentTextEdit();
06254     if ( edit )
06255     {
06256         KoLinkVariable * var=edit->linkVariable();
06257         if(var)
06258         {
06259             QString oldhref= var->url();
06260             QString oldLinkName=var->value();
06261             QString link=oldLinkName;
06262             QString ref=oldhref;
06263             if(KoInsertLinkDia::createLinkDia(link, ref, m_doc->listOfBookmarkName(0), true, this))
06264             {
06265                 if(!link.isEmpty() && !ref.isEmpty())
06266                 {
06267                     if( ref != oldhref || link!=oldLinkName)
06268                     {
06269                         KWChangeLinkVariable*cmd=new KWChangeLinkVariable( i18n("Change Link"), m_doc,oldhref, ref, oldLinkName,link, var);
06270                         cmd->execute();
06271                         m_doc->addCommand(cmd);
06272                     }
06273                 }
06274             }
06275         }
06276     }
06277 }
06278 
06279 void KWView::copyLink()
06280 {
06281     KWTextFrameSetEdit * edit = currentTextEdit();
06282     if ( edit )
06283         edit->copyLink();
06284 }
06285 
06286 void KWView::removeLink()
06287 {
06288     KWTextFrameSetEdit * edit = currentTextEdit();
06289     if ( edit )
06290         edit->removeLink();
06291 }
06292 
06293 void KWView::addToBookmark()
06294 {
06295     KWTextFrameSetEdit * edit = currentTextEdit();
06296     if ( edit )
06297     {
06298         KoLinkVariable * var=edit->linkVariable();
06299         if(var)
06300         {
06301             edit->addBookmarks(var->url());
06302         }
06303     }
06304 }
06305 
06306 void KWView::showDocStructure()
06307 {
06308     m_doc->setShowDocStruct(m_actionShowDocStruct->isChecked());
06309     m_doc->reorganizeGUI();
06310     QTimer::singleShot( 0, this, SLOT( updateZoom() ) );
06311 }
06312 
06313 void KWView::showRuler()
06314 {
06315     m_doc->setShowRuler( m_actionShowRuler->isChecked());
06316     m_doc->reorganizeGUI();
06317     QTimer::singleShot( 0, this, SLOT( updateZoom() ) );
06318 }
06319 
06320 void KWView::viewGrid()
06321 {
06322     m_doc->setShowGrid( m_actionViewShowGrid->isChecked() );
06323     m_doc->setModified( true );
06324     m_doc->updateGridButton();
06325     m_doc->repaintAllViews(false);
06326 }
06327 
06328 void KWView::viewSnapToGrid()
06329 {
06330     m_doc->setSnapToGrid( m_actionViewSnapToGrid->isChecked() );
06331     m_doc->setModified( true );
06332     m_doc->updateGridButton();
06333 }
06334 
06335 void KWView::slotSoftHyphen()
06336 {
06337     KWTextFrameSetEdit * edit = currentTextEdit();
06338     if ( edit )
06339         edit->insertSoftHyphen();
06340 }
06341 
06342 void KWView::slotNonbreakingSpace()
06343 {
06344     KWTextFrameSetEdit * edit = currentTextEdit();
06345     if ( edit )
06346         edit->insertNonbreakingSpace();
06347 }
06348 
06349 void KWView::slotNonbreakingHyphen()
06350 {
06351     KWTextFrameSetEdit * edit = currentTextEdit();
06352     if ( edit )
06353         edit->insertNonbreakingHyphen();
06354 }
06355 
06356 void KWView::slotLineBreak()
06357 {
06358     KWTextFrameSetEdit * edit = currentTextEdit();
06359     if ( edit )
06360         edit->insertLineBreak();
06361 }
06362 
06363 void KWView::slotIncreaseNumberingLevel()
06364 {
06365     KWTextFrameSetEdit * edit = currentTextEdit();
06366     if ( edit )
06367         edit->increaseNumberingLevel( m_doc->styleCollection() );
06368 }
06369 
06370 void KWView::slotDecreaseNumberingLevel()
06371 {
06372     KWTextFrameSetEdit * edit = currentTextEdit();
06373     if ( edit )
06374         edit->decreaseNumberingLevel( m_doc->styleCollection() );
06375 }
06376 
06377 void KWView::refreshAllVariable()
06378 {
06379     m_doc->recalcVariables( VT_ALL );
06380 }
06381 
06382 void KWView::slotAllowAutoFormat()
06383 {
06384     bool state = m_actionAllowAutoFormat->isChecked();
06385     m_doc->setAllowAutoFormat( state );
06386 }
06387 
06388 void KWView::slotCompletion()
06389 {
06390     KWTextFrameSetEdit * edit = currentTextEdit();
06391     if ( edit )
06392         edit->completion();
06393 }
06394 
06395 void KWView::updateHeaderFooterButton()
06396 {
06397     m_actionViewHeader->setChecked(m_doc->isHeaderVisible());
06398     m_actionViewFooter->setChecked(m_doc->isFooterVisible());
06399 }
06400 
06401 void KWView::editComment()
06402 {
06403     KWTextFrameSetEdit * edit = currentTextEdit();
06404     if ( edit )
06405     {
06406         KoVariable * tmpVar=edit->variable();
06407         KoNoteVariable * var = dynamic_cast<KoNoteVariable *>(tmpVar);
06408         if(var)
06409         {
06410             QString authorName;
06411             KoDocumentInfo * info = m_doc->documentInfo();
06412             KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(info->page( "author" ));
06413             if ( !authorPage )
06414                 kdWarning() << "Author information not found in documentInfo !" << endl;
06415             else
06416                 authorName = authorPage->fullName();
06417             QString oldValue = var->note();
06418             QString createDate = var->createdNote();
06419             KoCommentDia *commentDia = new KoCommentDia( this, oldValue, authorName, createDate);
06420             if( commentDia->exec() )
06421             {
06422                 if ( oldValue != commentDia->commentText())
06423                 {
06424                     KWChangeVariableNoteText *cmd = new KWChangeVariableNoteText( i18n("Change Note Text"), m_doc, oldValue,commentDia->commentText(), var);
06425                     m_doc->addCommand( cmd );
06426                     cmd->execute();
06427                 }
06428             }
06429             delete commentDia;
06430         }
06431     }
06432 }
06433 
06434 void KWView::fileStatistics()
06435 {
06436     KWStatisticsDialog *statisticsDialog = new KWStatisticsDialog( this, m_doc );
06437     if ( !statisticsDialog->wasCanceled() )
06438         statisticsDialog->exec();
06439     delete statisticsDialog;
06440 }
06441 
06442 void KWView::removeComment()
06443 {
06444     KWTextFrameSetEdit * edit = currentTextEdit();
06445     if ( edit )
06446     {
06447         edit->removeComment();
06448     }
06449 }
06450 
06451 void KWView::copyTextOfComment()
06452 {
06453     KWTextFrameSetEdit * edit = currentTextEdit();
06454     if ( edit )
06455     {
06456         edit->copyTextOfComment();
06457     }
06458 }
06459 
06460 void KWView::configureCompletion()
06461 {
06462     m_doc->autoFormat()->readConfig();
06463     KoCompletionDia dia( this, 0, m_doc->autoFormat() );
06464     dia.exec();
06465 }
06466 
06467 void KWView::applyAutoFormat()
06468 {
06469     m_doc->autoFormat()->readConfig();
06470     KMacroCommand *macro = 0L;
06471     QValueList<KoTextObject *> list(m_doc->visibleTextObjects(viewMode()));
06472     QValueList<KoTextObject *>::Iterator fit = list.begin();
06473     for ( ; fit != list.end() ; ++fit )
06474     {
06475         KCommand *cmd = m_doc->autoFormat()->applyAutoFormat( *fit );
06476         if ( cmd )
06477         {
06478             if ( !macro )
06479                 macro = new KMacroCommand( i18n("Apply Autoformat"));
06480             macro->addCommand( cmd );
06481         }
06482     }
06483     if ( macro )
06484         m_doc->addCommand( macro );
06485 }
06486 
06487 void KWView::createStyleFromSelection()
06488 {
06489     KWTextFrameSetEdit * edit = currentTextEdit();
06490     if ( edit )
06491     {
06492         KoStyleCollection* coll = m_doc->styleCollection();
06493         KoCreateStyleDia *dia = new KoCreateStyleDia( QStringList(), this, 0 );
06494         if ( dia->exec() )
06495         {
06496             QString name = dia->nameOfNewStyle();
06497             KoParagStyle* style = coll->findStyleByDisplayName( name );
06498             if ( style ) // update existing style
06499             {
06500                 // TODO confirmation message box
06501                 edit->updateStyleFromSelection( style );
06502             }
06503             else // create new style
06504             {
06505                 style = edit->createStyleFromSelection( name );
06506                 m_doc->styleCollection()->addStyle( style );
06507                 m_doc->updateAllStyleLists();
06508             }
06509             showStyle( name );
06510         }
06511         delete dia;
06512     }
06513 }
06514 
06515 // Initially called by initGUIButton
06516 void KWView::switchModeView()
06517 {
06518     KWCanvas* canvas = m_gui->canvasWidget();
06519     slotUpdateRuler();
06520 
06521     // Now update the actions appropriately
06522     QString mode = canvas->viewMode()->type();
06523     bool isTextMode = mode == "ModeText";
06524     bool state = !isTextMode;
06525     m_actionToolsCreateText->setEnabled(state);
06526     m_actionToolsCreatePix->setEnabled(state);
06527     m_actionToolsCreatePart->setEnabled(state);
06528     m_actionInsertFormula->setEnabled(state);
06529     m_actionInsertTable->setEnabled(state);
06530     changeFootEndNoteState();
06531     m_actionViewFooter->setEnabled( state && m_doc->processingType() == KWDocument::WP );
06532     m_actionViewHeader->setEnabled( state && m_doc->processingType() == KWDocument::WP );
06533     //m_actionViewTextMode->setEnabled(m_doc->processingType()==KWDocument::WP);
06534     m_actionShowDocStruct->setEnabled(state);
06535     m_actionFormatPage->setEnabled(state);
06536     m_actionInsertContents->setEnabled( state );
06537     m_actionFrameStyle->setEnabled( state );
06538     m_actionTableStyle->setEnabled ( state );
06539     m_actionViewShowGrid->setEnabled( state );
06540     m_actionViewSnapToGrid->setEnabled( mode == "ModeNormal" || mode == "ModeEmbedded" ); // TODO fix snapping in preview mode
06541     if ( m_gui->getHorzRuler())
06542     {
06543         m_gui->getHorzRuler()->setPageLayoutMenuItemEnabled( state );
06544         if ( !koDocument()->isReadWrite())
06545             m_gui->getHorzRuler()->changeFlags( KoRuler::F_NORESIZE );
06546         else
06547         {
06548             if ( state )
06549                 m_gui->getHorzRuler()->changeFlags( m_gui->getHorzRuler()->flags() & ~(KoRuler::F_NORESIZE) );
06550             else
06551                 m_gui->getHorzRuler()->changeFlags( m_gui->getHorzRuler()->flags() | KoRuler::F_NORESIZE );
06552         }
06553     }
06554     if ( m_gui->getVertRuler() )
06555     {
06556         m_gui->getVertRuler()->setPageLayoutMenuItemEnabled( state );
06557         if ( !koDocument()->isReadWrite())
06558             m_gui->getVertRuler()->changeFlags( KoRuler::F_NORESIZE );
06559         else
06560         {
06561             if ( state )
06562                 m_gui->getVertRuler()->changeFlags( m_gui->getVertRuler()->flags() & ~(KoRuler::F_NORESIZE) );
06563             else
06564                 m_gui->getVertRuler()->changeFlags( m_gui->getVertRuler()->flags() | KoRuler::F_NORESIZE );
06565 
06566         }
06567     }
06568 
06569     if ( isTextMode )
06570     {
06571         if ( m_doc->showdocStruct() )
06572         {
06573             m_doc->setShowDocStruct(false);
06574             m_doc->reorganizeGUI();
06575         }
06576     }
06577     else
06578     {
06579         m_doc->setShowDocStruct(m_actionShowDocStruct->isChecked());
06580         m_doc->reorganizeGUI();
06581     }
06582     //recalc pgnum variable when we swith viewmode
06583     //because in text mode view we display field code and not value
06584     //normal because we don't have real page in this mode
06585     m_doc->recalcVariables( VT_PGNUM );
06586     if ( isTextMode )
06587     {
06588         // Make sure we edit the same frameset as the one shown in the textview ;-)
06589         canvas->editFrameSet( static_cast<KWViewModeText* >(canvas->viewMode())->textFrameSet() );
06590 
06591     }
06592     //remove/add "zoom to page". Not necessary in text mode view.
06593     updateZoomControls();
06594 
06595     updatePageInfo();
06596     // set page layout in rulers
06597     canvas->viewMode()->setPageLayout( m_gui->getHorzRuler(), m_gui->getVertRuler(), m_doc->pageLayout() );
06598 }
06599 
06600 void KWView::configureFootEndNote()
06601 {
06602     KWConfigFootNoteDia *dia = new KWConfigFootNoteDia( this, "configfootnote", m_doc );
06603     dia->exec();
06604     delete dia;
06605 }
06606 
06607 void KWView::editFootEndNote()
06608 {
06609     KWTextFrameSetEdit * edit = currentTextEdit();
06610     if ( edit )
06611     {
06612         KWFootNoteVariable * var = dynamic_cast<KWFootNoteVariable *>( edit->variable() );
06613         if ( var && var->frameSet() )
06614         {
06615             m_gui->canvasWidget()->editFrameSet( var->frameSet() );
06616             KWTextFrameSetEdit* textedit = currentTextEdit();
06617             if ( textedit )
06618                 textedit->ensureCursorVisible();
06619         }
06620     }
06621 }
06622 
06623 void KWView::changeFootNoteType()
06624 {
06625     KWTextFrameSetEdit * edit = currentTextEdit();
06626     if ( edit )
06627     {
06628         KoVariable * tmpVar=edit->variable();
06629         KWFootNoteVariable * var = dynamic_cast<KWFootNoteVariable *>(tmpVar);
06630         if(var && var->frameSet())
06631         {
06632             KWFootNoteDia dia( var->noteType(), var->numberingType(), (var->numberingType()==KWFootNoteVariable::Auto) ? QString::null : var->manualString(), this, m_doc, 0 );
06633             QPtrListIterator<KoTextCustomItem> it( edit->textDocument()->allCustomItems() );
06634             for ( ; it.current() ; ++it )
06635             {
06636                 KWFootNoteVariable *fnv = dynamic_cast<KWFootNoteVariable *>( it.current() );
06637                 if (fnv && !fnv->isDeleted() && fnv->frameSet() && !fnv->frameSet()->isDeleted() &&
06638                  fnv->numberingType()==KWFootNoteVariable::Manual && fnv != var)
06639                     dia.appendManualFootNote( fnv->text() );
06640             }
06641             if ( dia.exec() )
06642             {
06643                 FootNoteParameter oldParam( var );
06644                 FootNoteParameter newParam(dia.noteType(), dia.numberingType(), dia.manualString() );
06645                 KWChangeFootNoteParametersCommand * cmd = new KWChangeFootNoteParametersCommand( i18n("Change Footnote Parameters"), var , oldParam, newParam, m_doc);
06646                 cmd->execute();
06647                 m_doc->addCommand ( cmd );
06648             }
06649         }
06650     }
06651 }
06652 
06653 
06654 void KWView::autoSpellCheck()
06655 {
06656     autoSpellCheck( m_actionAllowBgSpellCheck->isChecked() );
06657 }
06658 
06659 void KWView::autoSpellCheck(bool b)
06660 {
06661     m_doc->changeBgSpellCheckingState( b );
06662 }
06663 
06664 void KWView::goToFootEndNote()
06665 {
06666     KWFrameView *view = frameViewManager()->selectedFrame();
06667     KWFrame *frame = view == 0 ? 0 : view->frame();
06668     if( !frame)
06669         return;
06670     KWFootNoteFrameSet *footNoteFrameSet = dynamic_cast<KWFootNoteFrameSet *>(frame->frameSet());
06671     if ( footNoteFrameSet )
06672     {
06673         KWFootNoteVariable* var=footNoteFrameSet->footNoteVariable();
06674         KoTextParag *parag = var->paragraph();
06675         int index = var->index();
06676         KWTextDocument *textDoc = static_cast<KWTextDocument *>(var->textDocument());
06677         KWTextFrameSet *frameSet =textDoc->textFrameSet();
06678         m_gui->canvasWidget()->editTextFrameSet( frameSet, parag, index );
06679     }
06680 }
06681 
06682 void KWView::openDocStructurePopupMenu( const QPoint &p, KWFrameSet *frameset, KWTextParag *parag)
06683 {
06684     bool rw = koDocument()->isReadWrite();
06685     bool kttsdInstalled = KoSpeaker::isKttsdInstalled();
06686     if (!rw && !kttsdInstalled)
06687         return;
06688     bool hasText = (frameset->type()==FT_TEXT || frameset->type()==FT_TABLE || frameset->type()==FT_FORMULA );
06689 
06690     m_actionDocStructEdit->setEnabled( rw && hasText );
06691     m_actionDocStructDelete->setEnabled( (rw && !parag && !frameset->isMainFrameset() &&
06692         !frameset->isFootEndNote() && !frameset->isHeaderOrFooter()) );
06693     m_actionDocStructSpeak->setEnabled( hasText && kttsdInstalled );
06694 
06695     QPopupMenu* popup = static_cast<QPopupMenu *>(factory()->container("docstruct_popup",this));
06696     if ( popup )
06697         popup->exec(p);
06698 }
06699 
06700 void KWView::docStructSelect()
06701 {
06702     if ( m_gui->getDocStruct() )
06703     {
06704         m_gui->getDocStruct()->selectItem();
06705     }
06706 }
06707 
06708 void KWView::docStructEdit()
06709 {
06710     if ( m_gui->getDocStruct() )
06711     {
06712         m_gui->getDocStruct()->editItem();
06713         //return focus to canvas.
06714         m_gui->canvasWidget()->setFocus();
06715     }
06716 }
06717 
06718 void KWView::docStructProperties()
06719 {
06720     if ( m_gui->getDocStruct() )
06721     {
06722         m_gui->getDocStruct()->editProperties();
06723     }
06724 }
06725 
06726 void KWView::docStructDelete()
06727 {
06728     if ( m_gui->getDocStruct() )
06729     {
06730         m_gui->getDocStruct()->deleteItem();
06731     }
06732 }
06733 
06734 void KWView::docStructSpeak()
06735 {
06736     if ( m_gui->getDocStruct() )
06737     {
06738         m_gui->getDocStruct()->speakItem();
06739     }
06740 }
06741 
06742 void KWView::insertFile()
06743 {
06744     KFileDialog fd( QString::null, QString::null, this, 0, TRUE );
06745     fd.setMimeFilter( "application/x-kword" );
06746     fd.setCaption(i18n("Insert File"));
06747     KURL url;
06748     if ( fd.exec() != QDialog::Accepted )
06749         return;
06750     url = fd.selectedURL();
06751     if( url.isEmpty() )
06752     {
06753         KMessageBox::sorry( this,
06754                             i18n("File name is empty."),
06755                             i18n("Insert File"));
06756         return;
06757     }
06758     insertFile( url );
06759 }
06760 
06761 void KWView::insertFile(const KURL& url)
06762 {
06763     KMacroCommand* macroCmd = 0L;
06764     bool hasFixedFramesets = false;
06765     KoStore* store=KoStore::createStore( this, url, KoStore::Read );
06766 
06767     // TODO: this code only supports KWord-1.3 stores, it needs to support OASIS too.
06768 
06769     // ###### All of this should be ported to use the pasting code instead.
06770 
06771     QString maindoc = "maindoc.xml";
06772     if ( store )
06773     {
06774         // We need to load the pictures before we treat framesets
06775         // because KWDocument::pasteFrames() calls processPictureRequests().
06776         bool b = store->open(maindoc);
06777         if ( !b )
06778         {
06779             KMessageBox::sorry( this,
06780                                 i18n("This file is not a KWord file!"),
06781                                 i18n("Insert File"));
06782             delete store;
06783             return;
06784         }
06785 
06786         QDomDocument doc;
06787         doc.setContent( store->device() );
06788         QDomElement word = doc.documentElement();
06789 
06790         m_doc->loadPictureMap( word );
06791         store->close();
06792         m_doc->loadImagesFromStore( store );
06793     }
06794     if ( store )
06795     {
06796         bool b = store->open(maindoc);
06797         if ( !b )
06798         {
06799             KMessageBox::sorry( this,
06800                                 i18n("File name is not a KWord file!"),
06801                                 i18n("Insert File"));
06802             delete store;
06803             return;
06804         }
06805         QDomDocument doc;
06806         doc.setContent( store->device() );
06807         QDomElement word = doc.documentElement();
06808 
06809         QDomElement framesets = word.namedItem( "FRAMESETS" ).toElement();
06810         if ( !framesets.isNull() )
06811         {
06812             QDomElement framesetElem = framesets.firstChild().toElement();
06813             // just in case
06814             while ( !framesetElem.isNull() && framesetElem.tagName() != "FRAMESET" )
06815                 framesetElem = framesetElem.nextSibling().toElement();
06816 
06817             if ( !framesetElem.isNull() )
06818             {
06819                 KWTextFrameSet *textFrameSet = dynamic_cast<KWTextFrameSet *>( m_doc->frameSet(0) );
06820                 KoTextCursor insertionCursor( textFrameSet->textDocument() );
06821                 KWTextFrameSetEdit* edit = currentTextEdit();
06822                 if ( edit && !edit->textFrameSet()->protectContent()) {
06823                     textFrameSet = edit->textFrameSet();
06824                     insertionCursor = *edit->cursor();
06825                 }
06826                 // Handle the main textframeset special - concatenate the text
06827                 QDomDocument domDoc( "PARAGRAPHS" );
06828                 QDomElement paragsElem = domDoc.createElement( "PARAGRAPHS" );
06829                 domDoc.appendChild( paragsElem );
06830 
06831                 // Need an intermediate list otherwise nextSibling doesn't work after moving the node
06832                 // to the other DOM tree ;)
06833                 QValueList<QDomElement> paragList;
06834                 QValueList<QString> inlineFsNames;
06835                 QDomElement fsElem;
06836 
06837                 QDomNode n = framesetElem.firstChild().toElement();
06838                 while( !n.isNull() )
06839                 {
06840                     QDomElement e = n.toElement(); // try to convert the node to an element.
06841                     if  ( !e.isNull() && e.tagName() == "PARAGRAPH" )
06842                     {
06843                         paragList.append( e );
06844                         // Handle inline framesets
06845                         QDomElement formatsElem = e.namedItem( "FORMATS" ).toElement();
06846                         if ( !formatsElem.isNull() )
06847                         {
06848                             // Get references to inline framesets
06849                             QDomElement formatElem = formatsElem.firstChild().toElement();
06850                             for ( ; !formatElem.isNull() ; formatElem = formatElem.nextSibling().toElement() )
06851                             {
06852                                 QDomElement anchorElem = formatElem.namedItem( "ANCHOR" ).toElement();
06853                                 if ( !anchorElem.isNull() )
06854                                 {
06855                                     QString type = anchorElem.attribute( "type" );
06856                                     if ( type == "grpMgr" /* old syntax */ || type == "frameset" )
06857                                     {
06858                                         QString iName = anchorElem.attribute( "instance" );
06859                                         inlineFsNames.append( iName );
06860                                         // inline framsets shall appear after the paragraph
06861                                         QString tableName;
06862                                         QDomElement table;
06863                                         fsElem = framesetElem.nextSibling().toElement();
06864                                         for ( ; !fsElem.isNull() ; fsElem = fsElem.nextSibling().toElement() )
06865                                         {
06866                                             if ( fsElem.tagName() == "FRAMESET" )
06867                                             {
06868                                                 QString name = fsElem.attribute( "name" );
06869                                                 QString grpMgr = fsElem.attribute( "grpMgr" );
06870                                                 if ( name == iName )
06871                                                 {
06872                                                     paragList.append( fsElem );
06873                                                     //kdDebug()<<k_funcinfo<<" Inline frameset: "<<name<<" added"<<endl;
06874                                                 }
06875                                                 else if ( grpMgr == iName )
06876                                                 {   // Table so we need to create table framset if it is new
06877                                                     if ( grpMgr != tableName )
06878                                                     {
06879                                                         tableName = grpMgr;
06880                                                         table = domDoc.createElement("FRAMESET");
06881                                                         table.setAttribute("frameType", FT_TABLE);
06882                                                         table.setAttribute("frameInfo", 0);
06883                                                         table.setAttribute("protectSize", fsElem.attribute("protectSize","0"));
06884                                                         table.setAttribute("name", tableName);
06885                                                         table.setAttribute("visible", fsElem.attribute("visible","1"));
06886                                                         paragList.append( table ); // same level as paragraphs, so it goes into the paragList
06887                                                         //kdDebug()<<k_funcinfo<<" paragList Added new table: "<<grpMgr<<endl;
06888                                                     }
06889 
06890                                                     table.appendChild( fsElem.cloneNode() ); // add the cell as child to the table frameset
06891                                                     //kdDebug()<<k_funcinfo<<" Inline table: "<<grpMgr<<" Added new cell: "<<name<<endl;
06892                                                 }
06893                                                 //else kdDebug()<<k_funcinfo<<" Fixed frameset: "<<name<<endl;
06894                                             }
06895                                             //else kdDebug()<<k_funcinfo<<" Not frameset: "<<fsElem.tagName()<<endl;
06896                                         }
06897                                         //kdDebug()<<k_funcinfo<<" Treated "<<i<<" frameset elements"<<endl;
06898                                     }
06899                                 }
06900                             }
06901                         }
06902                     }
06903                     n = n.nextSibling();
06904                 }
06905 
06906                 QValueList<QDomElement>::Iterator it = paragList.begin();
06907                 QValueList<QDomElement>::Iterator end = paragList.end();
06908                 for ( ; it!= end ; ++it )
06909                 {
06910                     //kdDebug()<<k_funcinfo<<" paragList tag: "<<(*it).tagName()<<" name: "<<(*it).attribute( "name" )<<" grpMgr: "<<(*it).attribute( "grpMgr" )<<endl;
06911                     paragsElem.appendChild( *it );
06912                 }
06913                 //kdDebug() << k_funcinfo << "Paragraphs:\n" << domDoc.toCString() << endl;
06914 
06915                 // The fixed framesets
06916                 // doctype SELECTION is used for fixed framesets
06917                 QDomDocument domDocFrames( "SELECTION" ); // see KWCanvas::copySelectedFrames
06918                 QDomElement topElem = domDocFrames.createElement( "SELECTION" );
06919                 domDocFrames.appendChild( topElem );
06920                 QString tableName;
06921                 QDomElement table;
06922                 QValueList<QString> fsInHeader;
06923                 QValueList<QDomElement> framesetsList;
06924 
06925                 framesetElem = framesetElem.nextSibling().toElement();
06926                 for ( ; !framesetElem.isNull() ; framesetElem = framesetElem.nextSibling().toElement() )
06927                 {
06928                     if ( framesetElem.tagName() == "FRAMESET" )
06929                     {
06930                         FrameSetType frameSetType = static_cast<FrameSetType>( KWDocument::getAttribute( framesetElem, "frameType", FT_BASE ) );
06931                         KWFrameSet::Info info = static_cast<KWFrameSet::Info>( framesetElem.attribute("frameInfo").toInt() );
06932                         if ( frameSetType == FT_TEXT &&
06933                              (info == KWFrameSet::FI_FIRST_HEADER ||
06934                               info == KWFrameSet::FI_EVEN_HEADER   ||
06935                               info == KWFrameSet::FI_ODD_HEADER  ||
06936                               info == KWFrameSet::FI_FIRST_FOOTER ||
06937                               info == KWFrameSet::FI_EVEN_FOOTER   ||
06938                               info == KWFrameSet::FI_ODD_FOOTER)
06939                             )
06940                             fsInHeader += getInlineFramesets( framesetElem );
06941 
06942                         QString name = framesetElem.attribute( "name" );
06943                         QString grpMgr = framesetElem.attribute( "grpMgr" );
06944                         if ( !inlineFsNames.contains(name) && !inlineFsNames.contains(grpMgr) )
06945                         {   // fixed frameset
06946                             if ( !grpMgr.isEmpty() )
06947                             {   // Table cell
06948                                 if ( grpMgr != tableName )
06949                                 {   // New table (first cell)
06950                                     tableName = grpMgr;
06951                                     table = domDocFrames.createElement("FRAMESET");
06952                                     table.setAttribute("frameType", FT_TABLE);
06953                                     table.setAttribute("frameInfo", 0);
06954                                     table.setAttribute("protectSize", framesetElem.attribute("protectSize","0"));
06955                                     table.setAttribute("name", tableName);
06956                                     table.setAttribute("visible", framesetElem.attribute("visible","1"));
06957                                     framesetsList.append( table );
06958                                     //kdDebug()<<k_funcinfo<<" framesetsList Added new table: "<<grpMgr<<endl;
06959                                 }
06960                                 table.appendChild( framesetElem.cloneNode() ); // add the cell as child to the table frameset
06961                                 //kdDebug()<<k_funcinfo<<" Fixed table '"<<grpMgr<<"': Added new cell: '"<<name<<"'"<<endl;
06962                             }
06963                             else // other frameset type
06964                             {
06965                                 framesetsList.append( framesetElem );
06966                                 //kdDebug()<<k_funcinfo<<" Fixed frameset: '"<<name<<"' added"<<endl;
06967                             }
06968                         }
06969                         //else kdDebug()<<k_funcinfo<<" Inline frameset, skipped: "<<name<<endl;
06970                     }
06971                     //else kdDebug()<<k_funcinfo<<" Not frameset element, skipped: "<<framesetElem.tagName()<<endl;
06972                 }
06973                 it = framesetsList.begin();
06974                 end = framesetsList.end();
06975                 for ( ; it != end ; ++it )
06976                 {
06977                     framesetElem = (*it);
06978                     FrameSetType frameSetType = static_cast<FrameSetType>( KWDocument::getAttribute( framesetElem, "frameType", FT_BASE ) );
06979                     KWFrameSet::Info info = static_cast<KWFrameSet::Info>( framesetElem.attribute("frameInfo").toInt() );
06980                     QString name = framesetElem.attribute("name");
06981                     QString grpMgr = framesetElem.attribute( "grpMgr" );
06982                     // We skip headers, footers and framsets/tables inside theese
06983                     if ( !fsInHeader.contains(name) && !fsInHeader.contains(grpMgr) &&
06984                          !( frameSetType == FT_TEXT &&
06985                             (info == KWFrameSet::FI_FIRST_HEADER ||
06986                              info == KWFrameSet::FI_EVEN_HEADER   ||
06987                              info == KWFrameSet::FI_ODD_HEADER  ||
06988                              info == KWFrameSet::FI_FIRST_FOOTER ||
06989                              info == KWFrameSet::FI_EVEN_FOOTER   ||
06990                              info == KWFrameSet::FI_ODD_FOOTER) )
06991                         )
06992                     {
06993                         hasFixedFramesets = true;
06994                         topElem.appendChild( framesetElem );
06995                     }
06996                 }
06997                 // Embedded documents
06998                 QDomDocument embeddedDoc( "SELECTION" );
06999                 QDomElement selElem = embeddedDoc.createElement( "SELECTION" );
07000                 embeddedDoc.appendChild( selElem );
07001 
07002                 QValueList<QDomElement> embeddedList;
07003                 QDomElement embeddedElem = word.namedItem( "EMBEDDED" ).toElement();
07004                 for ( ; !embeddedElem.isNull() ; embeddedElem = embeddedElem.nextSibling().toElement() )
07005                 {
07006                     if ( embeddedElem.tagName() == "EMBEDDED" )
07007                     {
07008                         embeddedList.append( embeddedElem );
07009                     }
07010                 }
07011                 it = embeddedList.begin();
07012                 end = embeddedList.end();
07013                 bool hasEmbedded = false;
07014                 for ( ; it!= end ; ++it )
07015                 {
07016                     selElem.appendChild( *it );
07017                     hasEmbedded = true;
07018                 }
07019                 store->close();
07020 
07021 
07022                 // Now we do the insertion
07023                 if ( !macroCmd )
07024                     macroCmd = new KMacroCommand( i18n("Insert File") );
07025 
07026                 if ( hasFixedFramesets )
07027                 {
07028                     // insert fixed framesets
07029                     //kdDebug() << k_funcinfo << domDocFrames.toCString() << endl;
07030                     m_doc->pasteFrames( topElem, macroCmd, false, false, false /* don't select frames */ );
07031                 }
07032                 if ( hasEmbedded )
07033                 {
07034                     //kdDebug()<<k_funcinfo<<" Embedded: \n"<<embeddedDoc.toCString()<<endl;
07035                     if ( !macroCmd )
07036                         macroCmd = new KMacroCommand( i18n("Insert File") );
07037                     m_doc->insertEmbedded( store, selElem, macroCmd, 0 );
07038                 }
07039 
07040                 // insert paragraphs and inline framesets (we always have at least one paragraph)
07041                 KCommand *cmd = textFrameSet->pasteOasis( &insertionCursor, domDoc.toCString(), true );
07042 
07043                 if ( cmd ) {
07044                     macroCmd->addCommand( cmd );
07045                 }
07046                 m_doc->addCommand( macroCmd );
07047 
07048             }
07049         }
07050 
07051         m_doc->loadImagesFromStore( store );
07052         m_doc->completePasting();
07053 
07054     }
07055     delete store;
07056 }
07057 
07058 QValueList<QString> KWView::getInlineFramesets( const QDomNode &framesetElem)
07059 {
07060     //kdDebug()<<k_funcinfo<<" Frameset: "<<framesetElem.toElement().attribute("name")<<endl;
07061     QValueList<QString> list;
07062     QDomNode n = framesetElem.firstChild().toElement();
07063     for( ; !n.isNull(); n = n.nextSibling() )
07064     {
07065         QDomElement e = n.toElement(); // try to convert the node to an element.
07066         if  ( !e.isNull() && e.tagName() == "PARAGRAPH" )
07067         {
07068             QDomElement formatsElem = e.namedItem( "FORMATS" ).toElement();
07069             if ( !formatsElem.isNull() )
07070             {
07071                 // Get references to inline framesets
07072                 QDomElement formatElem = formatsElem.firstChild().toElement();
07073                 for ( ; !formatElem.isNull() ; formatElem = formatElem.nextSibling().toElement() )
07074                 {
07075                     QDomElement anchorElem = formatElem.namedItem( "ANCHOR" ).toElement();
07076                     if ( !anchorElem.isNull() )
07077                     {
07078                         QString type = anchorElem.attribute( "type" );
07079                         if ( type == "grpMgr" /* old syntax */ || type == "frameset" )
07080                         {
07081                             QString iName = anchorElem.attribute( "instance" );
07082                             list.append( iName );
07083                             //kdDebug()<<k_funcinfo<<" added: "<<iName<<endl;
07084                         }
07085                     }
07086                 }
07087             }
07088         }
07089     }
07090     return list;
07091 }
07092 
07093 void KWView::addBookmark()
07094 {
07095     KWTextFrameSetEdit * edit = currentTextEdit();
07096     if ( edit )
07097     {
07098         //don't create list against viewmode. We must list all bookmarks.
07099         KWCreateBookmarkDia dia( m_doc->listOfBookmarkName(0L), this, 0 );
07100         if ( dia.exec() ) {
07101             QString bookName = dia.bookmarkName();
07102             KoTextCursor start, end;
07103             if ( edit->textDocument()->hasSelection( KoTextDocument::Standard ) ) {
07104                 start = edit->textDocument()->selectionStartCursor( KoTextDocument::Standard );
07105                 end = edit->textDocument()->selectionEndCursor( KoTextDocument::Standard );
07106             } else {
07107                 start = *edit->cursor();
07108                 end = start;
07109             }
07110             int startSel = start.index();
07111             int endSel = end.index();
07112             m_doc->insertBookmark(bookName, start.parag(),end.parag(), startSel, endSel);
07113         }
07114     }
07115 }
07116 
07117 void KWView::selectBookmark()
07118 {
07119     KWSelectBookmarkDia dia( m_doc->listOfBookmarkName(viewMode()), m_doc, this, 0 );
07120     if ( dia.exec() ) {
07121         QString bookName = dia.bookmarkSelected();
07122         const KoTextBookmark * book = m_doc->bookmarkByName( bookName );
07123         Q_ASSERT( book );
07124         if ( book )
07125         {
07126             Q_ASSERT( book->startParag() );
07127             Q_ASSERT( book->endParag() );
07128             if ( !book->startParag() || !book->endParag() )
07129                 return;
07130             KWTextFrameSet* textfs = static_cast<KWTextDocument *>( book->textDocument() )->textFrameSet();
07131             m_gui->canvasWidget()->editTextFrameSet( textfs, book->startParag(), book->bookmarkStartIndex() );
07132             KWTextFrameSetEdit * edit = currentTextEdit();
07133             Q_ASSERT( edit );
07134             if ( edit )
07135             {
07136                 edit->textDocument()->removeSelection( KoTextDocument::Standard );
07137                 edit->textDocument()->setSelectionStart( KoTextDocument::Standard, edit->cursor() );
07138                 edit->cursor()->setParag( book->endParag());
07139                 edit->cursor()->setIndex(book->bookmarkEndIndex() );
07140                 edit->textDocument()->setSelectionEnd( KoTextDocument::Standard, edit->cursor() );
07141                 book->startParag()->setChanged( true );
07142                 book->endParag()->setChanged( true );
07143                 m_doc->slotRepaintChanged( edit->frameSet() );
07144             }
07145         }
07146     }
07147 }
07148 
07149 void KWView::importStyle()
07150 {
07151     KWImportStyleDia dia( m_doc, m_doc->styleCollection(), this );
07152     if ( dia.exec() && !dia.importedStyles().isEmpty() ) {
07153         m_doc->styleCollection()->importStyles( dia.importedStyles() );
07154         m_doc->setModified( true );
07155         m_doc->updateAllStyleLists();
07156     }
07157 }
07158 
07159 void KWView::testAndCloseAllFrameSetProtectedContent()
07160 {
07161     KWTextFrameSetEdit* edit = currentTextEdit();
07162     if ( edit && edit->textFrameSet()->protectContent()) {
07163         m_doc->terminateEditing( edit->frameSet());
07164     }
07165 }
07166 
07167 void KWView::updateRulerInProtectContentMode()
07168 {
07169     KWTextFrameSetEdit* edit = currentTextEdit();
07170     KoRuler * hRuler = m_gui ? m_gui->getHorzRuler() : 0;
07171 
07172     if ( edit && hRuler) {
07173         if ( !edit->textFrameSet()->protectContent() )
07174             hRuler->changeFlags(KoRuler::F_INDENTS | KoRuler::F_TABS);
07175         else
07176             hRuler->changeFlags(0);
07177         hRuler->repaint();
07178     }
07179 }
07180 
07181 void KWView::deselectAllFrames()
07182 {
07183     m_gui->canvasWidget()->selectAllFrames( false );
07184 }
07185 
07186 void KWView::insertDirectCursor()
07187 {
07188 #if 0
07189     insertDirectCursor( m_actionInsertDirectCursor->isChecked());
07190 #endif
07191 }
07192 
07193 void KWView::insertDirectCursor(bool b)
07194 {
07195     m_doc->setInsertDirectCursor(b);
07196 }
07197 
07198 void KWView::updateDirectCursorButton()
07199 {
07200 #if 0
07201     m_actionInsertDirectCursor->setChecked(m_doc->insertDirectCursor());
07202 #endif
07203 }
07204 
07205 void KWView::convertTableToText()
07206 {
07207     KWCanvas * canvas = m_gui->canvasWidget();
07208     KWTableFrameSet *table = canvas->getCurrentTable();
07209     if ( table && table->isFloating() )
07210     {
07211         const QByteArray arr = table->convertTableToText();
07212         KWAnchor * anchor = table->findAnchor( 0 );
07213         if ( anchor && arr.size() )
07214         {
07215             KWTextFrameSet *frameset = table->anchorFrameset();
07216             KoTextParag *parag = anchor->paragraph();
07217             int pos = anchor->index();
07218             KMacroCommand *macro = new KMacroCommand(i18n("Convert Table to Text"));
07219             KCommand *cmd = table->anchorFrameset()->deleteAnchoredFrame( anchor );
07220             if ( cmd )
07221                 macro->addCommand( cmd);
07222 
07223             m_gui->canvasWidget()->editTextFrameSet( frameset, parag, pos );
07224 
07225             KWTextFrameSetEdit* edit = currentTextEdit();
07226             if ( edit && edit->textFrameSet())
07227             {
07228                 cmd = edit->textFrameSet()->pasteOasis( edit->cursor(), arr, true );
07229                 if ( cmd )
07230                     macro->addCommand( cmd );
07231             }
07232             m_doc->addCommand(macro);
07233         }
07234     }
07235 }
07236 
07237 void KWView::convertToTextBox()
07238 {
07239     KWTextFrameSetEdit* edit = currentTextEdit();
07240     if ( !edit )
07241         return;
07242 
07243     KWTextFrameSet* textfs = edit->textFrameSet();
07244     if( textfs->protectContent() || !textfs->textObject()->hasSelection() )
07245         return;
07246 
07247     KWOasisSaver oasisSaver( m_doc );
07248     textfs->textDocument()->copySelection( oasisSaver.bodyWriter(), oasisSaver.savingContext(), KoTextDocument::Standard );
07249     if ( !oasisSaver.finish() )
07250         return;
07251     const QByteArray arr = oasisSaver.data();
07252     if ( !arr.size() )
07253         return;
07254 
07255     KCommand *cmd = textfs->textObject()->removeSelectedTextCommand( edit->textView()->cursor(), KoTextDocument::Standard );
07256     Q_ASSERT( cmd );
07257     KMacroCommand* macro = new KMacroCommand( i18n("Convert to Text Box"));
07258     macro->addCommand( cmd );
07259     // Where to place the resulting text box? Maybe it should be made inline?
07260     cmd = m_gui->canvasWidget()->createTextBox( KoRect(30,30,300,300) );
07261     Q_ASSERT( cmd );
07262     if ( cmd )
07263         macro->addCommand( cmd );
07264 
07265     edit = currentTextEdit();
07266     Q_ASSERT( edit ); // if it can really be 0, we need to undo the above...
07267     if ( edit )
07268     {
07269         cmd = edit->textFrameSet()->pasteOasis( edit->textView()->cursor(), arr, true );
07270         if ( cmd )
07271             macro->addCommand( cmd );
07272         // Auto-resize the frame from its contents
07273         edit->textFrameSet()->layout();
07274     }
07275     m_doc->addCommand( macro );
07276 }
07277 
07278 void KWView::slotAddIgnoreAllWord()
07279 {
07280     KWTextFrameSetEdit* edit = currentTextEdit();
07281     if ( edit )
07282         m_doc->addSpellCheckIgnoreWord( edit->currentWordOrSelection() );
07283 }
07284 
07285 void KWView::sortText()
07286 {
07287     KWTextFrameSetEdit* edit = currentTextEdit();
07288     if ( edit && edit->textFrameSet()->hasSelection() )
07289     {
07290         KWSortDia dlg( this, "sort dia" );
07291         if ( dlg.exec() )
07292         {
07293             const QByteArray arr = edit->textFrameSet()->sortText(dlg.getSortType());
07294             if ( arr.size() )
07295             {
07296                 KCommand *cmd = edit->textFrameSet()->pasteOasis( edit->cursor(), arr, true );
07297                 if ( cmd )
07298                     m_doc->addCommand(cmd);
07299             }
07300         }
07301     }
07302 }
07303 
07304 void KWView::addPersonalExpression()
07305 {
07306     KWTextFrameSetEdit* edit = currentTextEdit();
07307     if ( !(edit && edit->textFrameSet()->hasSelection()))
07308         return;
07309 
07310     QString newExpression = edit->textFrameSet()->textObject()->selectedText();
07311     //load file !!!
07312     QString tmp=locateLocal("data","kword/expression/perso.xml");
07313     QFile file( tmp );
07314     if ( !file.open( IO_ReadOnly ) )
07315         return;
07316     QDomDocument doc;
07317     doc.setContent( &file );
07318     file.close();
07319 
07320     QString group;
07321     QMap<QString, QStringList>lstOfPersonalExp;
07322     QStringList list;
07323     QDomNode n = doc.documentElement().firstChild();
07324     for( ; !n.isNull(); n = n.nextSibling() )
07325     {
07326         if ( n.isElement() )
07327         {
07328             QDomElement e = n.toElement();
07329             if ( e.tagName() == "Type" )
07330             {
07331                 list.clear();
07332                 group = i18n( e.namedItem( "TypeName" ).toElement().text().utf8() );
07333 
07334                 QDomNode n2 = e.firstChild();
07335                 for( ; !n2.isNull(); n2 = n2.nextSibling() )
07336                 {
07337 
07338                     if ( n2.isElement() )
07339                     {
07340                         QDomElement e2 = n2.toElement();
07341                         if ( e2.tagName() == "Expression" )
07342                         {
07343                             QString text = i18n( e2.namedItem( "Text" ).toElement().text().utf8() );
07344                             list<<text;
07345                         }
07346                     }
07347                 }
07348                 lstOfPersonalExp.insert(group,list);
07349                 group = "";
07350             }
07351         }
07352     }
07353     //save
07354     doc = QDomDocument( "KWordExpression" );
07355     QDomElement begin = doc.createElement( "KWordExpression" );
07356     doc.appendChild( begin );
07357     QMapIterator<QString, QStringList> itPersonalExp = lstOfPersonalExp.find(i18n("Normal"));
07358     if ( itPersonalExp != lstOfPersonalExp.end())
07359     {
07360         list = itPersonalExp.data();
07361         list<<newExpression;
07362         lstOfPersonalExp.replace( i18n("Normal"), list);
07363     }
07364     else
07365     {
07366         list.clear();
07367         list<<newExpression;
07368         lstOfPersonalExp.insert( i18n("Normal"), list);
07369     }
07370 
07371 
07372     itPersonalExp = lstOfPersonalExp.begin();
07373     for ( ; itPersonalExp != lstOfPersonalExp.end(); ++itPersonalExp )
07374     {
07375         QDomElement type = doc.createElement( "Type" );
07376         begin.appendChild( type );
07377         QDomElement typeName = doc.createElement( "TypeName" );
07378         type.appendChild( typeName );
07379         typeName.appendChild( doc.createTextNode(itPersonalExp.key()  ) );
07380         list=itPersonalExp.data();
07381         for( uint i=0;i<list.count();i++ )
07382         {
07383             QDomElement expr = doc.createElement( "Expression" );
07384             type.appendChild( expr );
07385             QDomElement text = doc.createElement( "Text" );
07386             expr.appendChild( text );
07387             text.appendChild( doc.createTextNode(list[i] ) );
07388         }
07389     }
07390     QCString s = doc.toCString();
07391 
07392     if ( !file.open( IO_WriteOnly ) )
07393     {
07394         kdDebug()<<"Error in addPersonalExpression()\n";
07395         return;
07396     }
07397     file.writeBlock(s,s.length());
07398     file.close();
07399     m_doc->refreshMenuExpression();
07400 }
07401 
07402 void KWView::addWordToDictionary()
07403 {
07404     KWTextFrameSetEdit* edit = currentTextEdit();
07405     if ( edit )
07406     {
07407         QString word = edit->wordUnderCursor( *edit->cursor() );
07408         if ( !word.isEmpty() )
07409             m_doc->addWordToDictionary( word );
07410     }
07411 }
07412 
07413 void KWView::embeddedStoreInternal()
07414 {
07415     kdDebug(31001)<<k_funcinfo<<endl;
07416     KWFrameView *view = frameViewManager()->selectedFrame();
07417     KWFrame *frame = view == 0 ? 0 : view->frame();
07418     if( !frame)
07419         return;
07420     KWPartFrameSet *part = static_cast<KWPartFrameSet *>(frame->frameSet());
07421     part->storeInternal();
07422 }
07423 
07424 void KWView::goToDocumentStructure()
07425 {
07426     KWDocStruct* docStruct = getGUI()->getDocStruct();
07427     if (docStruct) docStruct->setFocusHere();
07428 }
07429 
07430 void KWView::goToDocument()
07431 {
07432     KWCanvas* canvas = getGUI()->canvasWidget();
07433     if (!canvas) return;
07434     canvas->setFocus();
07435 }
07436 
07437 void KWView::deleteFrameSet( KWFrameSet * frameset)
07438 {
07439     if ( frameset  && frameset->frame(0))
07440     {
07441         frameViewManager()->view(frameset->frame(0))->setSelected( true );
07442         deleteFrame();
07443     }
07444 }
07445 
07446 QPtrList<KAction> KWView::listOfResultOfCheckWord( const QString &word )
07447 {
07448     QPtrList<KAction> listAction;
07449     DefaultDictionary *dict = m_broker->defaultDictionary();
07450     const QStringList lst = dict->suggest( word );
07451     if ( !lst.contains( word ) )
07452     {
07453         QStringList::ConstIterator it = lst.begin();
07454         const QStringList::ConstIterator end = lst.end();
07455         for ( ; it != end ; ++it )
07456         {
07457             if ( !(*it).isEmpty() ) // in case of removed subtypes or placeholders
07458             {
07459                 KAction * act = new KAction( *it );
07460                 connect( act, SIGNAL(activated()), this, SLOT(slotCorrectWord()) );
07461                 listAction.append( act );
07462             }
07463         }
07464     }
07465     return listAction;
07466 }
07467 
07468 void KWView::slotCorrectWord()
07469 {
07470     KAction * act = (KAction *)(sender());
07471     KWTextFrameSetEdit* edit = currentTextEdit();
07472     if ( edit )
07473     {
07474         edit->selectWordUnderCursor( *(edit->cursor()) );
07475         m_doc->addCommand( edit->textObject()->replaceSelectionCommand( edit->cursor(), act->text(), i18n("Replace Word") ));
07476     }
07477 }
07478 
07479 void KWView::slotChildActivated( bool a )
07480 {
07481   // Same hack as in KoView
07482   KoViewChild* ch = child( (KoView*)sender() );
07483   if ( !ch )
07484     return;
07485   KWDocumentChild* kwchild = static_cast<KWDocumentChild *>( ch->documentChild() );
07486   KWPartFrameSet* fs = kwchild->partFrameSet();
07487   //kdDebug() << "KWView::slotChildActivated fs=" << fs << endl;
07488   Q_ASSERT( fs );
07489   if ( fs ) {
07490       if ( a )
07491           fs->startEditing();
07492       else
07493           fs->endEditing();
07494   }
07495   KoView::slotChildActivated( a );
07496 }
07497 
07498 Broker *KWView::broker() const
07499 {
07500     return m_broker;
07501 }
07502 
07503 void KWView::slotUnitChanged( KoUnit::Unit unit )
07504 {
07505     getGUI()->getHorzRuler()->setUnit( unit );
07506     getGUI()->getVertRuler()->setUnit( unit );
07507     if ( m_sbUnitLabel )
07508         m_sbUnitLabel->setText( ' ' + KoUnit::unitDescription( unit ) + ' ' );
07509 }
07510 
07511 KWFrameViewManager* KWView::frameViewManager() const {
07512     return getGUI()->canvasWidget()->frameViewManager();
07513 }
07514 
07515 void KWView::deleteSelectedFrames() {
07516     int nbCommand=0;
07517 
07518     int docItem=0; // bitmask for changed doc items.
07519 
07520     KMacroCommand * macroCmd = new KMacroCommand( i18n("Delete Frames") );
07521     KWFrameViewManager *fvMgr = frameViewManager();
07522     while (KWFrameView *frameView = fvMgr->selectedFrame()) {
07523         KWFrame *frame = frameView->frame();
07524         KWFrameSet *fs = frame->frameSet();
07525         if ( fs->isAFooter() || fs->isAHeader() )
07526             continue;
07527         KWTableFrameSet *table=fs->groupmanager();
07528         if ( table ) {
07529             docItem|=m_doc->typeItemDocStructure(table->type());
07530 
07531             if ( table->isFloating() ) {
07532                 docItem|=m_doc->typeItemDocStructure(fs->type());
07533 
07534                 KWAnchor * anchor = table->findAnchor( 0 );
07535                 KCommand * cmd=table->anchorFrameset()->deleteAnchoredFrame( anchor );
07536                 macroCmd->addCommand(cmd);
07537                 nbCommand++;
07538             }
07539             else {
07540                 KWDeleteTableCommand *cmd = new KWDeleteTableCommand( i18n("Delete Table"), table );
07541                 cmd->execute();
07542                 macroCmd->addCommand(cmd);
07543                 nbCommand++;
07544             }
07545         }
07546         else { // a simple frame
07547             if ( fs->isMainFrameset() )
07548                 continue;
07549 
07550             docItem|=m_doc->typeItemDocStructure(fs->type());
07551 
07552             if ( fs->isFloating() ) {
07553                 KWAnchor * anchor = fs->findAnchor( 0 );
07554                 KCommand *cmd=fs->anchorFrameset()->deleteAnchoredFrame( anchor );
07555                 macroCmd->addCommand(cmd);
07556                 nbCommand++;
07557             }
07558             else {
07559                 KWDeleteFrameCommand *cmd = new KWDeleteFrameCommand( i18n("Delete Frame"), frame );
07560                 cmd->execute();
07561                 macroCmd->addCommand(cmd);
07562                 nbCommand++;
07563             }
07564         }
07565     }
07566     if( nbCommand ) {
07567         m_doc->addCommand(macroCmd);
07568         m_doc->refreshDocStructure(docItem);
07569     }
07570     else
07571         delete macroCmd;
07572 }
07573 
07574 
07575 /******************************************************************/
07576 /* Class: KWGUI                                                */
07577 /******************************************************************/
07578 KWGUI::KWGUI( const QString& viewMode, QWidget *parent, KWView *daView )
07579   : QHBox( parent, "" ),
07580     m_view ( daView )
07581 {
07582 
07583     KWDocument * doc = m_view->kWordDocument();
07584 
07585     m_horRuler  = 0;
07586     m_vertRuler = 0;
07587 
07588     // The splitter
07589     m_panner = new QSplitter( Qt::Horizontal, this );
07590 
07591     // The left side
07592     m_docStruct = new KWDocStruct( m_panner, doc, this );
07593     m_docStruct->setMinimumWidth( 0 );
07594 
07595     // The right side
07596     m_right = new QWidget( m_panner );
07597     QGridLayout *gridLayout = new QGridLayout( m_right, 2, 2 );
07598     m_canvas = new KWCanvas( viewMode, m_right, doc, this );
07599     gridLayout->addWidget( m_canvas, 1, 1 );
07600 
07601     QValueList<int> l;
07602     l << 10;
07603     l << 90;
07604     m_panner->setSizes( l );
07605 
07606     KoPageLayout layout = doc->pageLayout();
07607 
07608     m_tabChooser = new KoTabChooser( m_right, KoTabChooser::TAB_ALL );
07609     m_tabChooser->setReadWrite(doc->isReadWrite());
07610     gridLayout->addWidget( m_tabChooser, 0, 0 );
07611 
07612     m_horRuler = new KoRuler( m_right, m_canvas->viewport(), Qt::Horizontal, layout,
07613                   KoRuler::F_INDENTS | KoRuler::F_TABS,
07614                   doc->unit(), m_tabChooser );
07615     m_horRuler->setReadWrite(doc->isReadWrite());
07616     gridLayout->addWidget( m_horRuler, 0, 1 );
07617 
07618     m_vertRuler = new KoRuler( m_right, m_canvas->viewport(), Qt::Vertical, layout,
07619                    0, doc->unit() );
07620     m_vertRuler->setReadWrite(doc->isReadWrite());
07621     gridLayout->addWidget( m_vertRuler, 1, 0 );
07622 
07623     m_horRuler->setZoom( doc->zoomedResolutionX() );
07624     m_vertRuler->setZoom( doc->zoomedResolutionY() );
07625 
07626     m_horRuler->setGridSize(doc->gridX());
07627 
07628     connect( m_horRuler, SIGNAL( newPageLayout( const KoPageLayout & ) ), m_view, SLOT( newPageLayout( const KoPageLayout & ) ) );
07629     connect( m_horRuler, SIGNAL( newLeftIndent( double ) ), m_view, SLOT( newLeftIndent( double ) ) );
07630     connect( m_horRuler, SIGNAL( newFirstIndent( double ) ), m_view, SLOT( newFirstIndent( double ) ) );
07631     connect( m_horRuler, SIGNAL( newRightIndent( double ) ), m_view, SLOT( newRightIndent( double ) ) );
07632 
07633     connect( m_horRuler, SIGNAL( doubleClicked() ), m_view, SLOT( slotHRulerDoubleClicked() ) );
07634     connect( m_horRuler, SIGNAL( doubleClicked(double) ), m_view, SLOT( slotHRulerDoubleClicked(double) ) );
07635     connect( m_horRuler, SIGNAL( unitChanged( KoUnit::Unit ) ), this, SLOT( unitChanged( KoUnit::Unit ) ) );
07636     connect( m_vertRuler, SIGNAL( newPageLayout( const KoPageLayout & ) ), m_view, SLOT( newPageLayout( const KoPageLayout & ) ) );
07637     connect( m_vertRuler, SIGNAL( doubleClicked() ), m_view, SLOT( formatPage() ) );
07638     connect( m_vertRuler, SIGNAL( unitChanged( KoUnit::Unit ) ), this, SLOT( unitChanged( KoUnit::Unit ) ) );
07639 
07640     m_horRuler->hide();
07641     m_vertRuler->hide();
07642 
07643     m_canvas->show();
07644 
07645     reorganize();
07646 
07647     connect( m_horRuler, SIGNAL( tabListChanged( const KoTabulatorList & ) ), m_view,
07648              SLOT( tabListChanged( const KoTabulatorList & ) ) );
07649 
07650     setKeyCompression( TRUE );
07651     setAcceptDrops( TRUE );
07652     setFocusPolicy( QWidget::NoFocus );
07653 }
07654 
07655 void KWGUI::showGUI()
07656 {
07657     reorganize();
07658 }
07659 
07660 void KWGUI::resizeEvent( QResizeEvent *e )
07661 {
07662     QWidget::resizeEvent( e );
07663     reorganize();
07664 }
07665 
07666 void KWGUI::reorganize()
07667 {
07668     int hSpace = m_vertRuler->minimumSizeHint().width();
07669     int vSpace = m_horRuler->minimumSizeHint().height();
07670     if(m_view->kWordDocument()->showRuler())
07671     {
07672         m_vertRuler->show();
07673         m_horRuler->show();
07674         m_tabChooser->show();
07675         m_tabChooser->setGeometry( 0, 0, hSpace, vSpace );
07676     }
07677     else
07678     {
07679         m_vertRuler->hide();
07680         m_horRuler->hide();
07681         m_tabChooser->hide();
07682         hSpace = 0;
07683         vSpace = 0;
07684     }
07685 
07686     if(m_view->kWordDocument()->showdocStruct()) {
07687         if(m_docStruct->isHidden()) {
07688             m_docStruct->show();
07689             if(m_panner->sizes()[0] < 50) {
07690                 QValueList<int> l;
07691                 l << 100;
07692                 l << width()-100;
07693                 m_panner->setSizes( l );
07694             }
07695         }
07696     } else
07697         m_docStruct->hide();
07698 
07699     if( m_view->statusBar())
07700     {
07701         if(m_view->kWordDocument()->showStatusBar())
07702             m_view->statusBar()->show();
07703         else
07704             m_view->statusBar()->hide();
07705     }
07706 
07707     if ( m_view->kWordDocument()->showScrollBar())
07708     {
07709         m_canvas->setVScrollBarMode(QScrollView::Auto);
07710         m_canvas->setHScrollBarMode(QScrollView::Auto);
07711     }
07712     else
07713     {
07714         m_canvas->setVScrollBarMode(QScrollView::AlwaysOff);
07715         m_canvas->setHScrollBarMode(QScrollView::AlwaysOff);
07716     }
07717 }
07718 
07719 void KWGUI::unitChanged( KoUnit::Unit u )
07720 {
07721     m_view->kWordDocument()->setUnit( u );
07722 }
07723 
07724 QPoint KWView::applyViewTransformations( const QPoint& p ) const
07725 {
07726     return viewMode()->normalToView( m_doc->zoomPoint( KoPoint( p ) ) );
07727 }
07728 
07729 QPoint KWView::reverseViewTransformations( const QPoint& p ) const
07730 {
07731     return m_doc->unzoomPoint( viewMode()->viewToNormal( p ) ).toQPoint();
07732 }
07733 
07734 int KWView::currentPage() const {
07735     return m_currentPage->pageNumber();
07736 }
07737 
07738 void KWView::slotDocumentLoadingCompleted()
07739 {
07740     updateStyleList();
07741 }
07742 
07743 #include "KWView.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys