kword

KWTextFrameSet.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999, 2000 Reginald Stadlbauer <reggie@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef kwtextframeset_h
00021 #define kwtextframeset_h
00022 
00023 #include "KoRichText.h"
00024 #include "KWFrameSet.h"
00025 #include "KWFrameSetEdit.h"
00026 #include <KoTextView.h>
00027 #include <KoParagLayout.h>
00028 #include <KoChangeCaseDia.h>
00029 #include "KWVariable.h"
00030 
00031 class KoGenStyles;
00032 class KoParagStyle;
00033 class KWDocument;
00034 class DCOPObject;
00035 #ifndef KWTextFormat
00036 #define KWTextFormat KoTextFormat
00037 #endif
00038 class KWViewMode;
00039 class KWTextDocument;
00040 class KWordFrameSetIface;
00041 class KWFrame;
00042 class KWFrameViewManager;
00043 
00044 class KoTextObject;
00045 class KoDataToolInfo;
00046 class KoVariable;
00047 
00048 class KAction;
00049 class KNamedCommand;
00050 class KMacroCommand;
00051 
00052 class QDragObject;
00053 class QProgressDialog;
00054 
00063 class KWTextFrameSet : public KWFrameSet, public KoTextFlow, public KoTextFormatInterface
00064 {
00065     Q_OBJECT
00066 public:
00068     KWTextFrameSet( KWDocument *_doc, const QString & name );
00070     KWTextFrameSet( KWDocument* doc, const QDomElement& tag, KoOasisContext& context );
00072     ~KWTextFrameSet();
00073 
00074     virtual KWordFrameSetIface* dcopObject();
00075 
00079     virtual FrameSetType type() const { return FT_TEXT; }
00080 
00081     virtual KWFrameSetEdit * createFrameSetEdit( KWCanvas * canvas );
00082 
00084     KoTextObject * textObject() const { return m_textobj; }
00085 
00086     KoTextDocument *textDocument() const;
00087     KWTextDocument *kwTextDocument() const;
00088 
00089     void setProtectContent ( bool _protect ) { textObject()->setProtectContent(_protect);}
00090     bool protectContent() const { return textObject()->protectContent();}
00091 
00092     void clearUndoRedoInfo();
00093 
00096     KWFrame * documentToInternal( const KoPoint &dPoint, QPoint &iPoint ) const;
00097 
00099     enum RelativePosition { InsideFrame, LeftOfFrame, TopOfFrame, AtEnd };
00100     KWFrame * documentToInternalMouseSelection( const KoPoint &dPoint, QPoint &iPoint, RelativePosition& relPos, KWViewMode *viewMode ) const;
00101 
00105     KWFrame * internalToDocument( const KoPoint &relPoint, KoPoint &dPoint ) const;
00106     // version taking a LU point as input
00107     KWFrame * internalToDocument( const QPoint &iPoint, KoPoint &dPoint ) const;
00108 
00117     KWFrame * internalToDocumentWithHint( const QPoint &iPoint, KoPoint &dPoint, const KoPoint &hintDPoint ) const;
00118 
00122     KoPoint internalToDocumentKnowingFrame( const KoPoint &relPoint, KWFrame* theFrame ) const;
00123     // [deprecated?] version taking a LU point as input
00124     KoPoint internalToDocumentKnowingFrame( const QPoint &iPoint, KWFrame* theFrame ) const;
00125 
00128     QPoint moveToPage( int currentPgNum, short int direction ) const;
00129 
00132     virtual int availableHeight() const;
00133 
00135     bool isFrameEmpty( KWFrame * frame );
00136     virtual bool canRemovePage( int num );
00137     // reimp for internal reasons
00138     virtual void deleteFrame( unsigned int num, bool remove = true, bool recalc = true );
00139     void deleteFrame( KWFrame *frm, bool remove = true, bool recalc = true )
00140         { KWFrameSet::deleteFrame( frm, remove, recalc ); } // strange C++ feature ;)
00141 
00145     virtual void updateFrames( int flags = 0xff );
00146 
00155     void updateViewArea( QWidget * w, KWViewMode* viewMode, const QPoint & nPointBottom );
00156 
00157     virtual QDomElement save( QDomElement &parentElem, bool saveFrames = true )
00158     { return saveInternal( parentElem, saveFrames, false ); }
00160     virtual QDomElement toXML( QDomElement &parentElem, bool saveFrames = true )
00161     { return saveInternal( parentElem, saveFrames, true ); }
00162 
00163     virtual void load( QDomElement &attributes, bool loadFrames = true );
00165     void loadOasisContent( const QDomElement &bodyElem, KoOasisContext& context );
00167     KWFrame* loadOasis( const QDomElement& frame, const QDomElement &bodyElem, KoOasisContext& context );
00168 
00170     KWFrame* loadOasisTextFrame( const QDomElement& frameTag, const QDomElement &tag, KoOasisContext& context );
00171 
00173     void saveOasisContent( KoXmlWriter& writer, KoSavingContext& context ) const;
00175     virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context, bool saveFrames ) const;
00176 
00177     virtual QString toPlainText() const;
00178 
00179     virtual void finalize();
00180     //virtual void preparePrinting( QPainter *painter, QProgressDialog *progress, int &processedParags );
00181 
00183     bool hasSelection() const;
00185     QString selectedText() const;
00186 
00187     virtual void drawContents( QPainter *painter, const QRect &crect,
00188                                const QColorGroup &cg, bool onlyChanged, bool resetChanged,
00189                                KWFrameSetEdit* edit, KWViewMode *viewMode,
00190                                KWFrameViewManager *frameViewManager );
00191 
00192     virtual void drawFrame( KWFrame * frame, QPainter *painter, const QRect& fcrect, const QRect& crect,
00193                             const QPoint& translationOffset,
00194                             KWFrame *settingsFrame, const QColorGroup &cg, bool onlyChanged, bool resetChanged,
00195                             KWFrameSetEdit * edit, KWViewMode *viewMode, bool drawUnderlyingFrames );
00196 
00197     virtual void drawFrameContents( KWFrame * frame, QPainter *painter, const QRect & fcrect,
00198                                     const QColorGroup &cg, bool onlyChanged, bool resetChanged,
00199                                     KWFrameSetEdit * edit, KWViewMode *viewMode );
00200 
00201     void drawCursor( QPainter *p, KoTextCursor *cursor, bool cursorVisible, KWCanvas *canvas, KWFrame *currentFrame );
00202     QPoint cursorPos( KoTextCursor *cursor, KWCanvas* canvas, KWFrame* currentFrame );
00203 
00204 
00205     KCommand* pasteOasis( KoTextCursor * cursor, const QByteArray & data, bool removeSelected );
00206     void insertTOC( KoTextCursor * cursor );
00207     KNamedCommand* insertFrameBreakCommand( KoTextCursor *cursor );
00208     void insertFrameBreak( KoTextCursor * cursor );
00209     KCommand * setPageBreakingCommand( KoTextCursor * cursor, int pageBreaking );
00210 
00211     QRect paragRect( KoTextParag * parag ) const; // in normal coords
00212 
00213     KCommand *deleteAnchoredFrame( KWAnchor * anchor );
00214     void findPosition( const KoPoint &dPoint, KoTextParag * & parag, int & index );
00215 
00217     void highlightPortion( KoTextParag * parag, int index, int length, KWCanvas * canvas, bool repaint = true, KDialogBase* dialog = 0 );
00218     void removeHighlight( bool repaint = true );
00219 
00220     virtual void addTextFrameSets( QPtrList<KWTextFrameSet> &lst, bool onlyReadWrite=false );
00221 
00226     void applyStyleChange( KoStyleChangeDefMap changed );
00227 
00229     virtual void setVisible( bool v );
00230 
00232     void setInlineFramesVisible(bool);
00233 
00234 #ifndef NDEBUG
00235     virtual void printDebug();
00236 #endif
00237 
00239     virtual void layout();
00241     virtual void invalidate();
00242 
00243     virtual int paragraphs();
00244     virtual int paragraphsSelected();
00246     virtual bool statistics( QProgressDialog *progress, ulong & charsWithSpace, ulong & charsWithoutSpace,
00247         ulong & words, ulong& sentences, ulong & syllables, ulong & lines, bool selected );
00248 
00250     virtual void adjustMargins( int yp, int h, int reqMinWidth, int& leftMargin, int& rightMargin, int& pageWidth, KoTextParag* parag );
00252     virtual int adjustFlow( int y, int w, int h );
00253 
00255     int formatVertically( KoTextParag *parag, const QRect& rect );
00257     void fixParagWidth( KWTextParag* parag );
00258 
00263     void ensureFormatted( KoTextParag * parag, bool emitAfterFormatting = true );
00264 
00266     KWViewMode * currentViewMode() const { return m_currentViewMode; }
00269     KWFrame * currentDrawnFrame() const { return m_currentDrawnFrame; }
00270 
00272     virtual KoTextFormat * currentFormat() const;
00273 
00275     virtual KCommand *setFormatCommand( const KoTextFormat * newFormat, int flags, bool zoomFont = false );
00276 
00278     virtual const KoParagLayout * currentParagLayoutFormat() const;
00279 
00280     virtual bool rtl() const ;
00281 
00282 
00284     virtual KCommand *setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex=-1);
00285 
00286     virtual KCommand *setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type);
00287 
00289     void renumberFootNotes( bool repaint = true );
00290 
00294     virtual KWTextFrameSet* nextTextObject( KWFrameSet * ) { return this;}
00295 
00301     bool minMaxInternalOnPage( int pageNum, int& topLU, int& bottomLU ) const;
00302 
00306     KoTextParag* paragAtLUPos( int yLU ) const;
00307 
00311     KWFootNoteFrameSet * insertFootNote( NoteType noteType, KWFootNoteVariable::Numbering numType, const QString &manualString );
00312 
00313     KoTextDocCommand *deleteTextCommand( KoTextDocument *textdoc, int id, int index, const QMemArray<KoTextStringChar> & str, const CustomItemsMap & customItemsMap, const QValueList<KoParagLayout> & oldParagLayouts );
00314 
00315     QString copyTextParag( KoXmlWriter& writer, KoSavingContext& context, int selectionId );
00316 
00319     QByteArray sortText(SortType type) const;
00320 
00321     KoLinkVariable* linkVariableUnderMouse( const KoPoint& dPoint );
00322     KoVariable* variableUnderMouse( const KoPoint& dPoint );
00323 
00324 signals:
00326     void frameDeleted( KWFrame* frame );
00327 
00329     void mainTextHeightChanged();
00330 
00331 public slots:
00332     // Connected to KoTextObject
00333     void slotRepaintChanged();
00334 
00335 protected slots:
00336     // All those slots are connected to KoTextObject
00337     void slotAvailableHeightNeeded();
00338     void slotAfterFormatting( int bottom, KoTextParag *lastFormatted, bool* abort );
00339     void slotNewCommand( KCommand *cmd );
00340     void slotParagraphDeleted(KoTextParag*_parag);
00341     void slotParagraphCreated(KoTextParag*_parag);
00342     void slotParagraphModified(KoTextParag*_parag, int /*KoTextParag::ParagModifyType*/, int, int);
00343 
00344 
00345 protected: // for testing purposes
00346     KWTextFrameSet( const QString & name );
00347 
00348 private:
00349     void init();
00350     bool slotAfterFormattingNeedMoreSpace( int bottom, KoTextParag *lastFormatted );
00351     void slotAfterFormattingTooMuchSpace( int bottom );
00352     void getMargins( int yp, int h, int reqMinWidth, int* marginLeft, int* marginRight, int* pageWidth, int* validHeight,
00353                      int* breakBegin, int* breakEnd, KoTextParag* parag );
00354     bool checkVerticalBreak( int & yp, int & h, KoTextParag * parag, bool linesTogether, int breakBegin, int breakEnd );
00355     void frameResized( KWFrame *theFrame, bool invalidateLayout );
00360     QValueList<KWFrame*> framesFromTo( int y1, int y2 ) const;
00361     double footerHeaderSizeMax( KWFrame *theFrame );
00362     double footNoteSize( KWFrame *theFrame );
00363     QDomElement saveInternal( QDomElement &parentElem, bool saveFrames, bool saveAnchorsFramesets );
00364     bool createNewPageAndNewFrame( KoTextParag* lastFormatted, int difference );
00365 
00366 private:
00368     KoTextObject * m_textobj;
00370     KWViewMode * m_currentViewMode;
00372     KWFrame * m_currentDrawnFrame;
00374     int m_lastTextDocHeight;
00375 };
00376 
00384 class KWTextFrameSetEdit : public KoTextView, public KWFrameSetEdit
00385 {
00386     Q_OBJECT
00387 public:
00388     KWTextFrameSetEdit( KWTextFrameSet * fs, KWCanvas * canvas );
00389     virtual ~KWTextFrameSetEdit();
00390 
00391     virtual KoTextViewIface* dcopObject();
00392 
00393     virtual KWFrameSetEdit* currentTextEdit(){return this;}
00394 
00395     virtual void terminate(bool removeselection=true);
00396 
00397     KWTextFrameSet * textFrameSet() const
00398     {
00399         return static_cast<KWTextFrameSet*>(frameSet());
00400     }
00401     KoTextDocument * textDocument() const
00402     {
00403         return textFrameSet()->textDocument();
00404     }
00405 
00406     // Just in case we change to containing a textview instead
00407     KoTextView * textView() { return this; }
00408 
00409     // Events forwarded by the canvas (when being in "edit" mode)
00410     virtual void keyPressEvent( QKeyEvent * );
00411     virtual void keyReleaseEvent( QKeyEvent * );
00412     virtual void imStartEvent( QIMEvent * );
00413     virtual void imComposeEvent( QIMEvent * );
00414     virtual void imEndEvent( QIMEvent * );
00415     virtual void mousePressEvent( QMouseEvent *, const QPoint &, const KoPoint & );
00416     virtual void mouseMoveEvent( QMouseEvent *, const QPoint &, const KoPoint & ); // only called if button is pressed
00417     virtual void mouseReleaseEvent( QMouseEvent *, const QPoint &, const KoPoint & );
00418     virtual void mouseDoubleClickEvent( QMouseEvent *, const QPoint &, const KoPoint & );
00419     virtual void dragEnterEvent( QDragEnterEvent * );
00420     virtual void dragMoveEvent( QDragMoveEvent *, const QPoint &, const KoPoint & );
00421     virtual void dragLeaveEvent( QDragLeaveEvent * );
00422     virtual void dropEvent( QDropEvent *, const QPoint &, const KoPoint &, KWView* view );
00423     virtual void focusInEvent();
00424     virtual void focusOutEvent();
00425     virtual void selectAll();
00426 
00427     // Reimplemented from KoTextView
00428     virtual void drawCursor( bool b );
00429     virtual void showFormat( KoTextFormat *format );
00430     virtual bool pgUpKeyPressed();
00431     virtual bool pgDownKeyPressed();
00432     virtual void ctrlPgUpKeyPressed();
00433     virtual void ctrlPgDownKeyPressed();
00434 
00435     void setCursor( KoTextParag* parag, int index );
00436 
00437     void insertFrameBreak() { textFrameSet()->insertFrameBreak( cursor() ); }
00438     void insertWPPage();
00439     void insertVariable( int type, int subtype = 0 );
00440     void insertFootNote( NoteType noteType, KWFootNoteVariable::Numbering numType, const QString& manualString );
00441     void insertCustomVariable( const QString &name);
00442     void insertVariable( KoVariable *var,
00443                          KoTextFormat *format = 0 /*means currentFormat()*/,
00444                          bool refreshCustomMenu = false/*don't refresh all the time custom menu*/ );
00445 
00446     void insertLink(const QString &_linkName, const QString & hrefName);
00447     void insertComment(const QString &_comment);
00448 
00449     void insertExpression(const QString &_c);
00450     void insertFloatingFrameSet( KWFrameSet * fs, const QString & commandName );
00451     void insertTOC() { textFrameSet()->insertTOC( cursor() ); }
00452     KCommand * setPageBreakingCommand( int pageBreaking )
00453     { return textFrameSet()->setPageBreakingCommand( cursor(), pageBreaking ); }
00454 
00455 
00456     //const KoParagLayout & currentParagLayout() const { return m_paragLayout; }
00457     double currentLeftMargin() const { return m_paragLayout.margins[QStyleSheetItem::MarginLeft]; }
00458 
00459     virtual void removeToolTipCompletion();
00460 
00461     //bool isLinkVariable(const KoPoint &, bool setUrl=false);
00462 
00464     bool openLink( KoLinkVariable* variable );
00466     void openLink();
00467 
00468     void pasteData( QMimeSource* data, int provides, bool drop );
00469     KCommand* pasteOasisCommand( QMimeSource* data );
00470 
00476     KoBorder border(KoBorder::BorderType type);
00477 
00478 public slots:
00479     // Reimplemented from KWFrameSet and connected to KoTextView's signals
00480     virtual void cut();
00481     virtual void copy();
00482     virtual void paste();
00483 
00484     // Reimplemented from KoTextView
00485     virtual void updateUI( bool updateFormat, bool force = false );
00486     virtual void ensureCursorVisible();
00487 
00488 protected:
00489     // Reimplemented from KoTextView
00490     virtual void doAutoFormat( KoTextCursor* cursor, KoTextParag *parag, int index, QChar ch );
00491     virtual bool doIgnoreDoubleSpace(KoTextParag * parag, int index,QChar ch );
00492     virtual bool doCompletion( KoTextCursor* cursor, KoTextParag *parag, int index );
00493     virtual bool doToolTipCompletion( KoTextCursor* cursor, KoTextParag *parag, int index,int keyPress );
00494     virtual void showToolTipBox(KoTextParag *parag, int index, QWidget *widget, const QPoint &pos);
00495     virtual void textIncreaseIndent();
00496     virtual bool textDecreaseIndent();
00497 
00498     virtual void startDrag();
00499     QDragObject * newDrag( QWidget * parent );
00500 
00501 private slots:
00502     void slotFrameDeleted(KWFrame *);
00503 
00504 private:
00505     bool enterCustomItem( KoTextCustomItem* customItem, bool fromRight );
00506 
00507     KoParagLayout m_paragLayout;
00508     bool m_rtl; // maybe make part of KoParagLayout later
00509 };
00510 
00511 class KWFootNoteVariable;
00512 class KWFootNoteFrameSet : public KWTextFrameSet
00513 {
00514 public:
00516     KWFootNoteFrameSet( KWDocument *doc, const QString & name )
00517         : KWTextFrameSet( doc, name ), m_footNoteVar( 0L ) {}
00518 
00519     virtual KWordFrameSetIface* dcopObject();
00520 
00521     void setFootNoteVariable( KWFootNoteVariable* var );
00522     KWFootNoteVariable* footNoteVariable() const { return m_footNoteVar; }
00523 
00527     void createInitialFrame( int pageNum );
00528 
00534     void startEditing( KWCanvas* canvas );
00535 
00539     void setCounterText( const QString& text );
00540 
00541     virtual bool isFootNote() const;
00542     virtual bool isEndNote() const;
00543 
00544 private:
00545     KWFootNoteVariable* m_footNoteVar;
00546 };
00547 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys