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

« back to all changes in this revision

Viewing changes to kword/kwtextdocument.cc

  • 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:
17
17
   Boston, MA 02111-1307, USA.
18
18
*/
19
19
 
 
20
#include "kwtextdocument.h"
20
21
#include "kwtextparag.h"
21
 
#include "kwtextdocument.h"
22
22
#include "kwdoc.h"
23
23
#include "kwtextframeset.h"
24
 
#include "kwformat.h"
25
 
#include <kcommand.h>
26
24
#include <kdebug.h>
27
 
 
28
 
KoTextDocument::KoTextDocument( KoZoomHandler * zoomHandler, QTextDocument *p, KWTextFormatCollection *fc )
29
 
    : QTextDocument( p, fc ), m_zoomHandler( zoomHandler ), m_bDestroying( false )
30
 
{
31
 
    setAddMargins( true );                 // top margin and bottom are added, not max'ed
32
 
    QTextFormatter * formatter = new QTextFormatterBreakWords;
33
 
    formatter->setAllowBreakInWords( true ); // Necessary for lines without a single space
34
 
    setFormatter( formatter );
35
 
 
36
 
    setY( 0 );
37
 
    setLeftMargin( 0 );
38
 
    setRightMargin( 0 );
39
 
 
40
 
    // TODO clear(true) here if kpresenter uses kotextdocument directly,
41
 
    // otherwise in the derived constructor [virtual method call is the problem]
42
 
}
43
 
 
44
 
KoTextDocument::~KoTextDocument()
45
 
{
46
 
    m_bDestroying = true;
47
 
    clear( false );
48
 
}
49
 
 
50
 
QTextParag * KoTextDocument::createParag( QTextDocument *d, QTextParag *pr, QTextParag *nx, bool updateIds )
51
 
{
52
 
    return new KoTextParag( d, pr, nx, updateIds );
53
 
}
54
 
 
55
 
bool KoTextDocument::visitSelection( int selectionId, KWParagVisitor* visitor, bool forward )
56
 
{
57
 
    QTextCursor c1 = selectionStartCursor( selectionId );
58
 
    QTextCursor c2 = selectionEndCursor( selectionId );
59
 
    if ( c1 == c2 )
60
 
        return true;
61
 
    return visitFromTo( c1.parag(), c1.index(), c2.parag(), c2.index(), visitor, forward );
62
 
}
63
 
 
64
 
bool KoTextDocument::visitDocument( KWParagVisitor *visitor, bool forward )
65
 
{
66
 
    return visitFromTo( firstParag(), 0, lastParag(), lastParag()->length()-1, visitor, forward );
67
 
}
68
 
 
69
 
bool KoTextDocument::visitFromTo( QTextParag *firstParag, int firstIndex, QTextParag* lastParag, int lastIndex, KWParagVisitor* visitor, bool forw )
70
 
{
71
 
    if ( firstParag == lastParag )
72
 
    {
73
 
        return visitor->visit( firstParag, firstIndex, lastIndex );
74
 
    }
75
 
    else
76
 
    {
77
 
        bool ret = true;
78
 
        if ( forw )
79
 
        {
80
 
            // the -1 is for the trailing space
81
 
            ret = visitor->visit( firstParag, firstIndex, firstParag->length() - 1 );
82
 
            if (!ret) return false;
83
 
        }
84
 
        else
85
 
        {
86
 
            ret = visitor->visit( lastParag, 0, lastIndex );
87
 
            if (!ret) return false;
88
 
        }
89
 
 
90
 
        QTextParag* currentParag = forw ? firstParag->next() : lastParag->prev();
91
 
        QTextParag * endParag = forw ? lastParag : firstParag;
92
 
        while ( currentParag && currentParag != endParag )
93
 
        {
94
 
            ret = visitor->visit( currentParag, 0, currentParag->length() - 1 );
95
 
            if (!ret) return false;
96
 
            currentParag = forw ? currentParag->next() : currentParag->prev();
97
 
        }
98
 
        ASSERT( currentParag );
99
 
        ASSERT( endParag == currentParag );
100
 
        if ( forw )
101
 
            ret = visitor->visit( lastParag, 0, lastIndex );
102
 
        else
103
 
            ret = visitor->visit( currentParag, firstIndex, currentParag->length() - 1 );
104
 
        return ret;
105
 
    }
106
 
}
107
 
 
108
 
////
109
 
 
110
 
KWTextDocument::KWTextDocument( KWTextFrameSet * textfs, QTextDocument *p, KWTextFormatCollection *fc )
111
 
    : KoTextDocument( textfs->kWordDocument(), p, fc ), m_textfs( textfs )
 
25
#include <kglobalsettings.h>
 
26
#include "kwcommand.h"
 
27
#include <klocale.h>
 
28
 
 
29
KWTextDocument::KWTextDocument( KWTextFrameSet * textfs, KoTextFormatCollection *fc, KoTextFormatter *formatter )
 
30
    : KoTextDocument( textfs->kWordDocument(), fc, formatter, false ), m_textfs( textfs )
112
31
{
113
32
    init();
114
33
}
115
34
 
116
35
KWTextDocument::KWTextDocument( KoZoomHandler * zoomHandler )
117
 
    : KoTextDocument( zoomHandler, 0, new KWTextFormatCollection( QFont("helvetica") /*unused*/ ) ),
 
36
    : KoTextDocument( zoomHandler, new KoTextFormatCollection( KGlobalSettings::generalFont() /*unused*/, QColor(), KGlobal::locale()->language() , false, 1.0), 0L, false ),
118
37
      m_textfs( 0 )
119
38
{
120
39
    init();
121
 
    setWidth( 1000 );
122
40
}
123
41
 
124
42
void KWTextDocument::init()
125
43
{
126
 
    // QTextDocument::QTextDocument creates a parag, but too early for our createParag to get called !
127
 
    // So we have to get rid of it.
 
44
    // Create initial paragraph as a KWTextParag
128
45
    clear( true );
129
 
    // Using clear( false ) is a bit dangerous, since we don't always check cursor->parag() for != 0
130
 
}
131
 
 
132
 
QTextParag * KWTextDocument::createParag( QTextDocument *d, QTextParag *pr, QTextParag *nx, bool updateIds )
133
 
{
134
 
    return new KWTextParag( d, pr, nx, updateIds );
135
 
}
136
 
 
137
 
int KWTextCustomItem::index() const
138
 
{
139
 
    ASSERT( paragraph() );
140
 
    KWTextParag * parag = static_cast<KWTextParag *>( paragraph() );
141
 
    return parag->findCustomItem( this );
142
 
}
143
 
 
144
 
QTextFormat * KWTextCustomItem::format() const
145
 
{
146
 
    QTextParag * parag = paragraph();
147
 
    //kdDebug() << "KWTextCustomItem::format index=" << index() << " format=" << parag->at( index() )->format() << endl;
148
 
    return parag->at( index() )->format();
149
 
}
150
 
 
151
 
void CustomItemsMap::insertItems( const QTextCursor & startCursor, int size )
152
 
{
153
 
    if ( isEmpty() )
154
 
        return;
155
 
 
156
 
    QTextCursor cursor( startCursor );
157
 
    for ( int i = 0; i < size; ++i )
158
 
    {
159
 
        CustomItemsMap::Iterator it = find( i );
160
 
        if ( it != end() )
161
 
        {
162
 
            kdDebug() << "CustomItemsMap::insertItems setting custom item " << it.data() << endl;
163
 
            static_cast<KWTextParag *>(cursor.parag())->setCustomItem( cursor.index(), it.data(), 0 );
164
 
            it.data()->setDeleted( false );
165
 
        }
166
 
        cursor.gotoRight();
167
 
    }
168
 
}
169
 
 
170
 
void CustomItemsMap::deleteAll( KMacroCommand *macroCmd )
171
 
{
172
 
    Iterator it = begin();
173
 
    for ( ; it != end(); ++it )
174
 
    {
175
 
        KWTextCustomItem * item = it.data();
176
 
        KCommand * itemCmd = item->deleteCommand();
177
 
        if ( itemCmd && macroCmd )
178
 
        {
179
 
            macroCmd->addCommand( itemCmd );
180
 
            itemCmd->execute(); // the item-specific delete stuff hasn't been done
181
 
        }
182
 
        item->setDeleted( true );
183
 
    }
184
 
}
 
46
}
 
47
 
 
48
KWTextDocument::~KWTextDocument()
 
49
{
 
50
}
 
51
 
 
52
KoTextParag * KWTextDocument::createParag( KoTextDocument *d, KoTextParag *pr, KoTextParag *nx, bool updateIds )
 
53
{
 
54
    return new KWTextParag( static_cast<KoTextDocument *>(d), static_cast<KoTextParag *>(pr), static_cast<KoTextParag *>(nx), updateIds );
 
55
}
 
56
 
 
57
KoTextDocCommand *KWTextDocument::deleteTextCommand( KoTextDocument *textdoc, int id, int index, const QMemArray<KoTextStringChar> & str, const CustomItemsMap & customItemsMap, const QValueList<KoParagLayout> & oldParagLayouts )
 
58
{
 
59
    //kdDebug()<<" KoTextDocument::deleteTextCommand************\n";
 
60
    return new KWTextDeleteCommand( textdoc, id, index, str, customItemsMap, oldParagLayouts );
 
61
}
 
62
 
185
63
 
186
64
#include "kwtextdocument.moc"