kword

KWFrameSet.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999, 2000 Reginald Stadlbauer <reggie@kde.org>
00003    Copyright (C) 2005 Thomas Zander <zander@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef frame_set_h
00022 #define frame_set_h
00023 
00024 #include "KWFrame.h"
00025 #include <qptrvector.h>
00026 #include <qptrlist.h>
00027 #include "qdom.h"
00028 
00029 class KWAnchor;
00030 class KWFrame;
00031 class KWFrameSetEdit;
00032 class KWPageManager;
00033 class KWTableFrameSet;
00034 class KWTextFrameSet;
00035 class KWTextFrameSetEdit;
00036 class KWTextParag;
00037 class KWView;
00038 class KWordFrameSetIface;
00039 class KWFrameViewManager;
00040 
00041 class KoSavingContext;
00042 class KoTextDocument;
00043 class KoTextFormat;
00044 class KoTextParag;
00045 class KoXmlWriter;
00046 
00047 class KCommand;
00048 class QPoint;
00049 class QProgressDialog;
00050 
00051 
00061 class KWFrameSet : public QObject
00062 {
00063     Q_OBJECT
00064 public:
00066     KWFrameSet( KWDocument *doc );
00068     virtual ~KWFrameSet();
00069 
00070     virtual KWordFrameSetIface* dcopObject();
00071 
00075     virtual FrameSetType type() const { return FT_BASE; }
00076 
00077     virtual void addTextFrameSets( QPtrList<KWTextFrameSet> & /*lst*/, bool /*onlyReadWrite*/ = false ) {};
00078     virtual bool ownLine() const { return FALSE;}
00079 
00090     enum Info { FI_BODY = 0, FI_FIRST_HEADER = 1, FI_EVEN_HEADER = 2, FI_ODD_HEADER = 3,
00091                 FI_FIRST_FOOTER = 4, FI_EVEN_FOOTER = 5, FI_ODD_FOOTER = 6,
00092                 FI_FOOTNOTE = 7 };
00094     Info frameSetInfo()const { return m_info; }
00096     void setFrameSetInfo( Info fi ) { m_info = fi; }
00097 
00098     bool isAHeader() const;
00099     bool isAFooter() const;
00100     bool isHeaderOrFooter() const { return isAHeader() || isAFooter(); }
00101     bool isFootEndNote() const;
00102     const char* headerFooterTag() const; // for OASIS saving
00103 
00104     virtual bool isFootNote() const { return false; }
00105     virtual bool isEndNote() const { return false; }
00106 
00107     bool isMainFrameset() const;
00108     bool isMoveable() const;
00109 
00110     // frame management
00111     virtual void addFrame( KWFrame *_frame, bool recalc = true );
00112 
00118     virtual void deleteFrame( unsigned int num, bool remove = true, bool recalc = true );
00119 
00125     void deleteFrame( KWFrame *frm, bool remove = true, bool recalc = true ); // calls the virtual one
00126 
00128     virtual void frameDeleted( KWFrame* /*frm*/, bool /*recalc*/ ) {}
00129 
00130     void deleteAllFrames();
00131     void deleteAllCopies(); 
00132 
00134     KWFrame *frameAtPos( double _x, double _y ) const;
00135 
00142     bool isFrameAtPos( const KWFrame* frame, const QPoint& nPoint, bool borderOfFrameOnly=false ) const;
00143 
00145     KWFrame *frame( unsigned int _num ) const;
00146 
00155     static KWFrame * settingsFrame( const KWFrame* frame );
00156 
00158     const QPtrList<KWFrame> &frameIterator() const { return m_frames; }
00160     int frameFromPtr( KWFrame *frame );
00162     unsigned int frameCount() const { return m_frames.count(); }
00163 
00165     bool isDeleted() const { return m_frames.isEmpty(); }
00166 
00168     virtual KWFrameSetEdit * createFrameSetEdit( KWCanvas * ) { return 0; }
00169 
00184     virtual void createEmptyRegion( const QRect & crect, QRegion & emptyRegion, KWViewMode *viewMode );
00185 
00207     virtual void drawContents( QPainter *painter, const QRect &crect,
00208                                const QColorGroup &cg, bool onlyChanged, bool resetChanged,
00209                                KWFrameSetEdit *edit, KWViewMode *viewMode,
00210                                KWFrameViewManager *frameViewManager );
00211 
00228     void drawFrameAndBorders( KWFrame *frame,
00229                               QPainter *painter, const QRect &crect,
00230                               const QColorGroup &cg, bool, bool,
00231                               KWFrameSetEdit *edit, KWViewMode *viewMode,
00232                               KWFrame *settingsFrame, bool drawUnderlyingFrames );
00233 
00242     void drawFrameBorder( QPainter *painter, KWFrame *frame, KWFrame *settingsFrame,
00243                           const QRect &crect, KWViewMode *viewMode );
00244 
00264     virtual void drawFrame( KWFrame *frame, QPainter *painter, const QRect &fcrect, const QRect &crect,
00265                             const QPoint& translationOffset,
00266                             KWFrame *settingsFrame, const QColorGroup &cg, bool onlyChanged, bool resetChanged,
00267                             KWFrameSetEdit *edit, KWViewMode *viewMode, bool drawUnderlyingFrames );
00268 
00285     virtual void drawFrameContents( KWFrame * frame, QPainter *painter, const QRect& fcrect,
00286                                     const QColorGroup &cg, bool onlyChanged, bool resetChanged,
00287                                     KWFrameSetEdit * edit, KWViewMode *viewMode );
00288 
00292     virtual void drawPadding( KWFrame *frame, QPainter *p, const QRect &fcrect, const QColorGroup &cg, KWViewMode *viewMode);
00293 
00294     enum UpdateFramesFlags {
00295         UpdateFramesInPage = 1,
00296         SortFrames = 2 
00297         // next one is 4, not 3 ;)
00298     };
00303     virtual void updateFrames( int flags = 0xff );
00304 
00307     const QPtrList<KWFrame> & framesInPage( int pageNum ) const;
00308 
00310     bool hasFramesInPageArray() const { return !m_framesInPage.isEmpty(); }
00311 
00313     virtual void layout() {}
00314     virtual void invalidate() {}
00315 
00317     virtual QDomElement save( QDomElement &parentElem, bool saveFrames = true ) = 0;
00319     virtual QDomElement toXML( QDomElement &parentElem, bool saveFrames = true )
00320     { return save( parentElem, saveFrames ); }
00322     virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context, bool saveFrames ) const = 0;
00325     virtual bool canBeSavedAsInlineCharacter() const { return true; }
00326 
00328     virtual void load( QDomElement &framesetElem, bool loadFrames = true );
00329     KWFrame* loadOasisFrame( const QDomElement& tag, KoOasisContext& context );
00331     virtual void fromXML( QDomElement &framesetElem, bool loadFrames = true, bool /*useNames*/ = true )
00332     { load( framesetElem, loadFrames ); }
00333 
00334     virtual QString toPlainText() const { return QString::null; }
00335 
00336     //virtual void preparePrinting( QPainter *, QProgressDialog *, int & ) { }
00337 
00340     virtual void finalize();
00341 
00342     virtual int paragraphs() { return 0; }
00343     virtual int paragraphsSelected() { return 0; }
00344     virtual bool statistics( QProgressDialog * /*progress*/,  ulong & /*charsWithSpace*/, ulong & /*charsWithoutSpace*/, ulong & /*words*/,
00345                              ulong & /*sentences*/, ulong & /*syllables*/, ulong & /*lines*/,  bool /*process only selected */ ) { return true; }
00346 
00347     KWDocument* kWordDocument() const { return m_doc; }
00348 
00350     virtual bool canRemovePage( int num );
00351 
00352     //Note: none of those floating-frameset methods creates undo/redo
00353     //They are _called_ by the undo/redo commands.
00354 
00356     void setFloating();
00361     void setAnchored( KWTextFrameSet* textfs, KoTextParag* parag, int index, bool placeHolderExists = false, bool repaint = true );
00365     void setAnchored( KWTextFrameSet* textfs, int paragId, int index, bool placeHolderExists = false, bool repaint = true );
00367     void setAnchored( KWTextFrameSet* textfs );
00369     void setFixed();
00371     bool isFloating() const { return m_anchorTextFs; }
00373     KWTextFrameSet * anchorFrameset() const { return m_anchorTextFs; }
00375     void setAnchorFrameset(KWTextFrameSet * textfs) { m_anchorTextFs = textfs; }
00377     KWAnchor * findAnchor( int frameNum );
00379     virtual void setAnchorFormat( KoTextFormat* /*format*/, int /*frameNum*/ ) {}
00380 
00382     virtual KWAnchor * createAnchor( KoTextDocument *txt, int frameNum );
00383 
00386     virtual void moveFloatingFrame( int frameNum, const KoPoint &position );
00389     virtual KoSize floatingFrameSize( int frameNum = 0 );
00393     KoRect floatingFrameRect( int frameNum = 0 );
00396     virtual int floatingFrameBaseline( int /*frameNum*/ ) { return -1; }
00398     virtual KCommand * anchoredObjectCreateCommand( int frameNum );
00400     virtual KCommand * anchoredObjectDeleteCommand( int frameNum );
00401 
00405     void setGroupManager( KWTableFrameSet *gm ) { m_groupmanager = gm; }
00407     KWTableFrameSet *groupmanager()const { return m_groupmanager; }
00408 
00409     bool isProtectSize()const { return m_protectSize; }
00410     void setProtectSize( bool _b);
00411 
00421     bool isVisible( KWViewMode* viewMode = 0L ) const;
00422 
00424     virtual void setVisible( bool v );
00425 
00427     QString name() const { return m_name; }
00428     void setName( const QString &name );
00429 
00431     void setFrameBehavior( KWFrame::FrameBehavior fb );
00432 
00434     void setNewFrameBehavior( KWFrame::NewFrameBehavior nfb );
00435 
00436 #ifndef NDEBUG
00437     virtual void printDebug();
00438     virtual void printDebug( KWFrame * );
00439 #endif
00440 
00441     virtual KWTextFrameSet* nextTextObject( KWFrameSet * ) { return 0L;}
00442 
00443     bool isPaintedBy( KWFrameSet* fs ) const;
00444 
00446     virtual void setZOrder();
00447 
00448     virtual void setProtectContent ( bool protect ) = 0;
00449     virtual bool protectContent() const = 0;
00450 
00451     void setPageManager(KWPageManager *pm) { m_pageManager = pm; }
00452     KWPageManager* pageManager() const { return m_pageManager; }
00453 
00454 signals:
00455 
00459     void repaintChanged( KWFrameSet * frameset );
00460 
00461     void sigFrameAdded(KWFrame*);
00462     void sigFrameRemoved(KWFrame*);
00463 
00464     void sigNameChanged(KWFrameSet*);
00465 
00466 protected:
00467 
00469     void saveCommon( QDomElement &parentElem, bool saveFrames );
00470 
00475     QRegion frameClipRegion( QPainter * painter, KWFrame *frame, const QRect & crect,
00476                              KWViewMode * viewMode );
00477 
00478     void deleteAnchor( KWAnchor * anchor );
00479     virtual void deleteAnchors();
00480     virtual void createAnchors( KoTextParag * parag, int index, bool placeHolderExists = false, bool repaint = true );
00481 
00482 
00483     KWDocument *m_doc;            // Document
00484     QPtrList<KWFrame> m_frames;        // Our frames
00485 
00486     // Cached info for optimization
00488     QPtrVector< QPtrList<KWFrame> > m_framesInPage;
00490     int m_firstPage;
00492     QPtrList<KWFrame> m_emptyList; // ## make static pointer to save memory ?
00493 
00494     Info m_info;
00495     KWTableFrameSet *m_groupmanager;
00496     bool m_visible;
00497     bool m_protectSize;
00498     QString m_name;
00499     KWTextFrameSet * m_anchorTextFs;
00500     KWordFrameSetIface *m_dcop;
00501     KWPageManager *m_pageManager;
00502 };
00503 
00504 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys