~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to kword/kwframelayout.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef KWFRAMELAYOUT_H
 
2
#define KWFRAMELAYOUT_H
 
3
 
 
4
#include <qptrlist.h>
 
5
#include <kdebug.h>
 
6
#include <koRect.h>
 
7
#include <qmap.h>
 
8
 
 
9
class KWDocument;
 
10
class KWFrameSet;
 
11
class KWTextFrameSet;
 
12
class KoRect;
 
13
 
 
14
class KWFrameLayout
 
15
{
 
16
public:
 
17
    // Maybe all that data should go into a KWHeaderFooterFrameSet
 
18
    // (or rather a base class shared by KWFootNoteFrameSet....)
 
19
    struct HeaderFooterFrameset {
 
20
        enum OddEvenAll { Even, Odd, All };
 
21
 
 
22
        HeaderFooterFrameset( KWTextFrameSet* fs, int start, int end,
 
23
                              double spacing, OddEvenAll oea = All );
 
24
 
 
25
        // Frameset. Also gives the type (header, footer, footnote).
 
26
        KWTextFrameSet* m_frameset;
 
27
 
 
28
        // Future features - but already used for "first page" stuff
 
29
        int m_startAtPage;
 
30
        int m_endAtPage; // (-1 for no end)
 
31
 
 
32
        // Odd/even/all
 
33
        OddEvenAll m_oddEvenAll;
 
34
 
 
35
        // Height in pt
 
36
        double m_height;
 
37
 
 
38
        // Space between this frame and the next one
 
39
        // (the one at bottom for headers, the one on top for footers/footnotes).
 
40
        // e.g. ptHeaderBodySpacing for headers/footers
 
41
        double m_spacing;
 
42
 
 
43
        // Minimum Y value - for footnotes
 
44
        double m_minY;
 
45
 
 
46
        // True once the footnote has been correctly positionned and
 
47
        // shouldn't be moved by checkFootNotes anymore.
 
48
        bool m_positioned;
 
49
 
 
50
        // frame number for the given page.... -1 if no frame on that page
 
51
        int frameNumberForPage( int page /* 0-based! */ ) const
 
52
            {
 
53
                if ( page < m_startAtPage || ( m_endAtPage != -1 && page > m_endAtPage ) )
 
54
                    return -1;
 
55
                int pg = page - m_startAtPage; // always >=0
 
56
                // Note that 'page' is 0-based. This is why "Odd" looks for even numbers, and "Even" looks for odd numbers :}
 
57
                switch (m_oddEvenAll) {
 
58
                case Odd:
 
59
                    // we test page, not bg: even/odd is for the absolute page number, too confusing otherwise
 
60
                    if ( page % 2 == 0 )
 
61
                        return pg / 2; // page 0[+start] -> frame 0, page 2[+start] -> frame 1
 
62
                    else
 
63
                        return -1;
 
64
                case Even:
 
65
                    if ( page % 2 )
 
66
                        return pg / 2; // page 1 -> 0, page 3 -> 1
 
67
                    else
 
68
                        return -1;
 
69
                case All:
 
70
                    return pg; // page 0[+start] -> frame 0, etc.
 
71
                default:
 
72
                    return -1;
 
73
                }
 
74
            }
 
75
 
 
76
        // the last frame we need, layout() will delete any frame after that
 
77
        int lastFrameNumber( int lastPage ) const
 
78
            {
 
79
                if ( lastPage < m_startAtPage )
 
80
                    return -1; // we need none
 
81
                int pg = lastPage;
 
82
                if ( m_endAtPage > -1 )
 
83
                    pg = QMIN( m_endAtPage, pg );
 
84
                pg -= m_startAtPage; // always >=0
 
85
                Q_ASSERT( pg >= 0 );
 
86
                switch (m_oddEvenAll) {
 
87
                case Odd:
 
88
                case Even:
 
89
                    return pg / 2; // page 0 and 1 -> 0. page 2 and 3 -> 1.
 
90
                case All:
 
91
                    return pg; // page 0 -> 0 etc. ;)
 
92
                default:
 
93
                    return -1;
 
94
                }
 
95
            }
 
96
 
 
97
        void debug();
 
98
        bool deleteFramesAfterLast( int lastPage );
 
99
    };
 
100
 
 
101
    /**
 
102
     * Constructor
 
103
     * @param doc the KWDocument we're layouting
 
104
     * @param headersFooters list of header and footer HFFs (see definition of HeaderFooterFrameset)
 
105
     * @param footnotes list of footnotes framesets HFFs
 
106
     * @param endnotes list of endnotes framesets HFFs
 
107
     */
 
108
    KWFrameLayout( KWDocument* doc, QPtrList<HeaderFooterFrameset>& headersFooters,
 
109
                   QPtrList<HeaderFooterFrameset>& footnotes, QPtrList<HeaderFooterFrameset>& endnotes )
 
110
        : m_headersFooters( headersFooters ), m_footnotes( footnotes ), m_endnotes( endnotes ), m_doc( doc )
 
111
        {}
 
112
 
 
113
    enum { DontRemovePages = 1 };
 
114
    /**
 
115
     * The main method of this file. Do the frame layout.
 
116
     * @param mainTextFrameSet if set, its frames will be resized. Usually: set in WP mode, not set in DTP mode.
 
117
     * @param numColumns number of columns to create for the main textframeset. Only relevant if mainTextFrameSet!=0.
 
118
     * @param fromPage first page to layout ( 0-based )
 
119
     * @param toPage last page to layout ( 0-based )
 
120
     * @param flags see enum above
 
121
     */
 
122
    void layout( KWFrameSet* mainTextFrameSet, int numColumns,
 
123
                 int fromPage, int toPage, uint flags );
 
124
 
 
125
protected:
 
126
    void resizeOrCreateHeaderFooter( KWTextFrameSet* headerFooter, uint frameNumber, const KoRect& rect );
 
127
    KoRect firstColumnRect( KWFrameSet* mainTextFrameSet, int pageNum, int numColumns ) const;
 
128
    enum HasFootNotes { NoFootNote, WithFootNotes, NoChange };
 
129
    bool resizeMainTextFrame( KWFrameSet* mainTextFrameSet, int pageNum, int numColumns, double ptColumnWidth, double ptColumnSpacing, double left, double top, double bottom, HasFootNotes hasFootNotes );
 
130
    void checkFootNotes();
 
131
 
 
132
private:
 
133
    // A _ref_ to a list. Must remain alive as long as this object.
 
134
    QPtrList<HeaderFooterFrameset>& m_headersFooters;
 
135
    QPtrList<HeaderFooterFrameset>& m_footnotes;
 
136
    QPtrList<HeaderFooterFrameset>& m_endnotes;
 
137
    QMap<KWFrameSet *, bool> m_framesetsToUpdate;
 
138
    KWDocument* m_doc;
 
139
    int m_lastMainFramePage;
 
140
};
 
141
 
 
142
#endif