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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
/***************************************************************************
kafkahtmlpart.h
-------------------
copyright : (C) 2001 - The Kafka Team
(C) 2003, 2004 - Nicolas Deschildre
email : kde-kafka@master.kde.org && ndeschildre@kdewebdev.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef KAFKAHTMLPART_H
#define KAFKAHTMLPART_H
#include <kurl.h>
#include <tdehtml_part.h>
#include <tdehtml_events.h>
#include <tdeparts/event.h>
#include <tqstringlist.h>
#include <tqptrlist.h>
#include <tqdockwindow.h>
#include <tqevent.h>
#include <dom/dom_node.h>
#include <dom/dom_element.h>
class DOMString;
class KafkaWidgetPrivate;
class KafkaDocument;
class NodeModifsSet;
class TQPopupMenu;
/*
* It is the main central widget which get the cursor focus and takes care of "simple" edition
* such as typing text.
*/
class KafkaWidget : public TDEHTMLPart
{
Q_OBJECT
public:
KafkaWidget(TQWidget *parent, TQWidget *widgetParent, KafkaDocument *part,
const char *name = 0);
~KafkaWidget();
/**
* Category: Standard Functions
* Called by KafkaPart to create a new document
*/
void newDocument();
/**
* Returns the current Node (which has the focus) and its offset.
* @param currentNode The Node which has the cursor focus.
* @param offset The offset of the cursor in _currentNode.
*/
void getCurrentNode(DOM::Node ¤tNode, long &offset);
/**
* Set the focus.
* @param node The DOM::Node which will get the focus.
* @param offset The offset of the cursor if node is a DOM::Node::TEXT_NODE
*/
void setCurrentNode(DOM::Node node, int offset);
/**
* Convenience function to set the current node.
* @param node The Quanta node which will get the focus.
* @param offset The offset of the cursor if node tag is of type Tag::Text.
*/
void setCurrentNode(Node* cursorNode, int cursorOffset);
/**
* Get the next DOM::Node after _node.
* @param _node The DOM::Node the search starts from.
* @param goUp A needed boolean for several consecutive call to
* this function. Setting it to false by default, or to true if we don't want to go through
* the childs of _node.
* @param skipParentNodes Specifies if we should skip the parent Node when going up :
* this implies that Nodes will not be returned two times.
* @param dontBlock Specifies if the search should or not be blocked by BlockingTags.
* @param _endNode Specifies at which DOM::Node the search should end. It is useful
* when setting skipParentNodes to true.
* @return Returns the next Node :)
*/
DOM::Node getNextNode(DOM::Node _node, bool &goUp, bool skipParentNodes = false,
bool dontBlock = false, DOM::Node _endNode = DOM::Node());
/**
* The same that above, but this function search the previous DOM::Node.
*/
DOM::Node getPrevNode(DOM::Node _node, bool &goUp, bool skipParentNodes = false,
bool dontBlock = false, DOM::Node _endNode = DOM::Node());
/**
* Set the TagActions checked/unchecked in context.
* This is called when the cursor position changes.
* @param domNode
* @param offset
*/
void updateToggableTagActions(/*const DOM::Node &domNode, long offset*/) const;
/** --------------- DOM::Node modifications -------------------------- */
/**
* It will move DOM::Nodes from startNode to endNode as children of newParent. It does NOT check
* if the move is valid, so it may crash. Please check before with kafkaCommon::parentSupports().
* @param newParent The new parent of the DOM::Nodes.
* @param startNode The first node to move.
* @param endNode Starting from endNode, the last sibling to move.
* @param refNode The reference DOM::Node.
* @bool before If set to true, the DOM::nodes will be moved at the left of refNode,
* otherwise they will be happenend at the right of refNode.
*/
void moveDomNodes(DOM::Node newParent, DOM::Node startNode, DOM::Node endNode,
DOM::Node refNode, bool before);
public slots:
/**
* Category: HTML Editing Functions
* Adds text into a DOM::Node of type DOM::Node::TEXT_NODE
* @param node The node where text should be added
* @param text The text to be added
* @param position Specifies the position where to add text
*/
void insertText(DOM::Node node, const TQString &text, int position);
/**
* Category: HTML Editing Functions
* Adds text into the current DOM::Node
* @param text The text to add
* @param position Specifies the position where to add text, if it's -1
* the text will be appended after the last position
*/
void insertText(const TQString &text, int position);
/**
* Puts all the child Text DOM::Node into a "normal" form where only
* structure (e.g., elements, comments, processing instructions, CDATA
* sections, and entity references) separates Text nodes, i.e., there are
* neither adjacent Text nodes nor empty Text nodes.
* Should be used instead of DOM::Node::normalize().
* @param _node This node is the parent node of the childs normalized
*/
void normalize(DOM::Node _node);
/**
* Set the cursor after having loaded the DOM tree from scratch.
* Look for the first available location for the cursor.
*/
void putCursorAtFirstAvailableLocation();
/**
* Reload the TagAttributesTree if necessary;
* @param domNode The current DOM::Node.
* @param offset The current cursor offset.
*/
void slotNewCursorPos(const DOM::Node &domNode, long offset);
/**
* Called to set the cursor Position with a TQTimer::singleShot() after calling
* document->updateRendering()
*/
void slotDelayedSetCaretPosition();
signals:
/**
* Category: HTML Editing Signal
* Is emitted whenever the DOM tree has changed
* Not yet implemented
*/
void domChanged();
/**
* Category: HTML Editing Signal
* Is emitted whenever a dom Node is inserted to the tree.
* @param node is the node created.
* @param insertChilds Specifies if we should insert the _node's childs
* @param modifs The changes made are logged into modifs.
*/
void domNodeInserted(DOM::Node node, bool insertChilds, NodeModifsSet *modifs);
/**
* Category: HTML Editing Signal
* Is emitted whenever a DOM node has its properties modified.
* @param node is the node modified.
* @param modifs The changes made are logged into modifs.
*/
void domNodeModified(DOM::Node node, NodeModifsSet *modifs);
/**
* Category: HTML Editing Signal
* Is emitted whenever a DOM node is about to be removed from the tree.
* @param node is the node to be deleted.
* @param deleteChilds Specifies if we should delete the child nodes of _node.
* @param modifs The changes made are logged into modifs.
*/
void domNodeIsAboutToBeRemoved(DOM::Node node, bool deleteChilds, NodeModifsSet *modifs);
/**
* Is emitted whenever a DOM::Node is about to be moved in the tree.
* @param node The DOM::Node which will be moved.
* @param newParent The new parent of domNode.
* @param before domNode will be placed before before.
* @param modifs The changes made are logged into modifs.
*/
void domNodeIsAboutToBeMoved(DOM::Node node, DOM::Node newParent, DOM::Node before, NodeModifsSet *modifs);
/**
* Category: HTML Editing Signal
* Is emitted whenever the cursor position change in one DOM::Node.
* @param node The DOM::Node which contains the cursor.
* @param _offset The new cursorOffset.
*/
void domNodeNewCursorPos(DOM::Node node, int offset);
/**
* Category: Widget Signal
* Is emitted whenever the KafkaWidget widget get or lost the focus
* @param focus True if it has got the focus, false otherwise.
*/
void hasFocus(bool focus);
protected:
bool eventFilter(TQObject *object, TQEvent *event);
virtual void tdehtmlMouseMoveEvent(tdehtml::MouseMoveEvent *event);
virtual void tdehtmlMousePressEvent(tdehtml::MousePressEvent *event);
virtual void tdehtmlMouseReleaseEvent(tdehtml::MouseReleaseEvent *event);
virtual void tdehtmlDrawContentsEvent(tdehtml::DrawContentsEvent *event);
private slots:
void slotContextMenuRequested(const TQString& url, const TQPoint& point);
private:
#if 0
/**
* NOT IMPLEMENTED.
* Internal function used by keyBackspace(), keyDelete() to delete Nodes.
* @param startNode The DOM::Node location of the point where we start deleting Nodes.
* @param offset The offset location of the point where we start deleting Nodes. They can be
* updated.
* @param backspace Specifies if it should delete Nodes backward (backspace keystroke)
* or torwards (delete backspace).
*/
void keyDeleteNodes(DOM::Node &startNode, long &offset, bool backspace);
#endif
/**
* Delete one character/DOM::Node left to the cursor.
*/
void keyBackspace();
/**
* Delete one character/DOM::Node right to the cursor.
*/
void keyDelete();
/**
* Break the current line.
* @param specialPressed If a special touch is pressed e.g. ctrl, we try to insert a BR,
* otherwise we try to insert a P.
*/
void keyReturn(bool specialPressed);
/**
* Postprocess the cursor position, i.e. when the cursor is between two
* DOM::Nodes, it set the cursor in the right node to make edition as
* in a word processor.
*/
void postprocessCursorPosition();
/**
* Make the cursor visible whenever it is going :-)
* @param xMargin The minimum margin in the X axis between the cursor
* and the edge of the widget.
* @param yMargin The minimim margin in the Y axis between the cursor
* and the edge of the widget.
*/
void makeCursorVisible(int xMargin = 50, int yMargin = 50);
/**
* Removes the selection and places the cursor in the right place.
*/
void removeSelection();
void applyQueuedToggableTagActions();
private:
/**
* When some changes are made, store the changes made in m_modifs.
* It will be created when a key is pressed, and will be submitted to
* the undoRedo system after the changes have been made.
*/
NodeModifsSet *m_modifs;
DOM::Node m_currentNode;
KafkaWidgetPrivate *d;
KafkaDocument *w;
friend class KafkaWidgetPrivate;
TQPopupMenu* m_contextPopupMenu;
};
#endif
|