1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
// -*- c++ -*-
/* This file is part of the KDE project
Original TQTextCustomItem is
Copyright (C) 1999-2000 Trolltech AS. All rights reserved.
KoText modifications
Copyright (C) 2001-2005 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
// This file isn't standalone at this point; it's included by KoRichText.h
/**
* KoTextCustomItem is the base class for custom items (i.e. special chars)
* Custom items include:
* - variables ( KoVariable, kovariable.h )
* - in kword: inline images ( KWTextImage, kwtextimage.h ) (to be removed)
* - in kword: anchors, i.e. floating frames ( KWAnchor, kwanchor.h )
*/
class KOTEXT_EXPORT KoTextCustomItem
{
public:
KoTextCustomItem( KoTextDocument *p );
virtual ~KoTextCustomItem();
virtual void draw(TQPainter* p, int x, int y, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected ) /* = 0*/;
// Called after the item's paragraph has been formatted
virtual void finalize() {}
void move( int x, int y ) { xpos = x; ypos = y; }
int x() const { return xpos; }
int y() const { return ypos; }
// Called when the format of the character is being changed, see KoTextStringChar::setFormat
virtual void setFormat( KoTextFormat * ) { }
//virtual void setPainter( TQPainter*, bool adjust );
enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
virtual Placement placement() const { return PlaceInline; }
bool placeInline() { return placement() == PlaceInline; }
virtual bool ownLine() const { return FALSE; }
// Called for "ownline" items
virtual void resize( int nwidth ) { width = nwidth; }
virtual void invalidate() {};
virtual bool isNested() const { return FALSE; }
virtual int minimumWidth() const { return 0; }
virtual int widthHint() const { return 0; }
virtual int ascent() const { return height; }
virtual TQString richText() const { return TQString(); }
int width;
int height;
TQRect geometry() const { return TQRect( xpos, ypos, width, height ); }
virtual bool enter( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy, bool atEnd = FALSE );
virtual bool enterAt( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy, const TQPoint & );
virtual bool next( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy );
virtual bool prev( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy );
virtual bool down( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy );
virtual bool up( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g, int &idx, int &ox, int &oy );
void setParagraph( KoTextParag * p ) { parag = p; }
KoTextParag *paragraph() const { return parag; }
virtual void pageBreak( int /*y*/, KoTextFlow* /*flow*/ ) {}
KoTextDocument *parent;
/** The text document in which this customitem is */
KoTextDocument * textDocument() const { return parent; }
/** When the user deletes a custom item, it isn't destroyed but
* moved into the undo/redo history - setDeleted( true )
* and it can be then copied back from there into the real world - setDeleted( false ). */
virtual void setDeleted( bool b ) { m_deleted = b; }
bool isDeleted() const { return m_deleted; }
/** Called when the item is created or 'deleted' by the user
* Most custom items don't need to reimplement those, since
* the custom item is simply moved into the undo/redo history
* when deleting (or undoing a creation).
* It is not deleted and re-created later. */
virtual KCommand * createCommand() { return 0L; }
virtual KCommand * deleteCommand() { return 0L; }
/** Save to XML */
virtual void save( TQDomElement& formatElem ) = 0;
/** Save to Oasis XML */
virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const = 0;
/** Return type of custom item. See DTD for VARIABLE.id docu. */
virtual int typeId() const = 0;
/** Reimplement this to calculate the item width
* It is important to start with "if ( m_deleted ) return;" */
virtual void resize() {}
/** Reimplemented by KoVariable to recalculate the value.
* It exists at the KoTextCustomItem level so that KoTextParag::setCustomItem
* can call it to set the initial value.
* This should call always resize(). */
virtual void recalc() { resize(); }
/** The index in paragraph(), where this anchor is
* Slightly slow (does a linear search in the paragraph) */
int index() const;
/** The formatting given to this 'special' character
* Slightly slow (does a linear search in the paragraph) */
KoTextFormat * format() const;
/**
* All coordinates are in pixels.
*/
virtual void drawCustomItem(TQPainter* p, int x, int y, int wpix, int hpix, int ascentpix, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected, int offset, bool drawingShadow) = 0;
protected:
bool m_deleted;
protected:
int xpos;
int ypos;
private:
KoTextParag *parag;
};
|