summaryrefslogtreecommitdiffstats
path: root/part/kxe_treeview.h
blob: f307ca2edaa9ad8b44ce4dbe184b2795b2fe4598 (plain)
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
/***************************************************************************
                          kxe_treeview.h  -  description
                             -------------------
    begin                : Thu Sep 20 2001
    copyright            : (C) 2001, 2002, 2003 by The KXMLEditor Team
    email                : OleBowle@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 KXE_TREEVIEW_H
#define KXE_TREEVIEW_H

#include <tdelistview.h>
#include <tqstrlist.h>

class KXESearchDialog;

class TQDomDocument;
class TQDomNode;
class TQDomElement;
class TQDomCharacterData;
class TQDomProcessingInstruction;

class TQMouseEvent;
class TQTimer;
class TQKeyEvent;
class KXMLGUIClient;
class KXE_TreeViewItem;

/**
 * This is a listview, which displays the XML tree structure.
 * @short shows XML tree
 */
class KXE_TreeView : public TDEListView
{
		TQ_OBJECT

public:
	KXE_TreeView( KXMLGUIClient * pGUIClient, TQWidget * pParent = 0, const char * pszName = 0 );

	/** Changes the behaviour of this view to readonly or readwrite. */
	void setReadWrite( bool fReadWrite );

	/** Selects the given item. */
	void selectItem( KXE_TreeViewItem * const pItem );

	/** Selects the item corresponding to the given node.
		 *  Returns true on success, false otherwise. */
	bool selectNode( const TQDomNode & node );
	
	/** Returns the a pointer to the selected items node or a null pointer (if no item is selected). */
	TQDomNode * getSelectedNode() const;

	/** Returns the a pointer to the special processing instruction or a null pointer for (if no item is exists). */
	TQDomNode * getSpecProcInstrNode(const TQString& target) const;

	/** Returns the selected items path or an empty string, if no item is selected. */
	TQString getSelectedPath() const;
	
	/** Returns true, if this tree view contains bookmarked tree items and false otherwise. */
	bool containsBookmarkedItems() const { return (m_nBookmarkedItems>0); }

	/** Drop or paste text into item */
	bool drop(TQListViewItem *, TQDropEvent *);

	/** toggles bookmark on the selected item */
	void bookmarksToggle();

	/** searches for the next bookmarked item */
	void bookmarksPrev();

	/** searches for the previous bookmarked item */
	void bookmarksNext();

	/** deselects currently selected item */
	void editDeselect();

	/** Selects the selected item's parent item. */
	void viewNodeUp();

	/** Expands the selected tree item's subtree to the given level (see @ref KXE_TreeViewItem::expandSubTree). */
	void viewExpNode( int nLevel );

	/** Collapses the selected tree item's subtree to the given level (see @ref KXE_TreeViewItem::collapseSubTree). */
	void viewColNode( int nLevel );

 /**
	 * Creates new item(s) to the given node (and its child nodes)
	 * and inserts it (or them) in the tree.
	 */
	void updateNodeCreated( const TQDomNode & node );

  /** Changes the item corresponding to the given node. */
	void updateNodeChanged( const TQDomNode & node );

  /** Removes the item corresponding to the given node. */
	void updateNodeDeleted( const TQDomNode & node );

	/** Moves the item corresponding to the given node. */
	void updateNodeMoved( const TQDomNode & node );

	/** Clears the whole tree. */
	void updateClear();

 /**
	* Handles inplace-renaming of items, because in our case
	* only items representing XML elements are to be renameable.
	* For the actual renaming of the items text, the base
	* class functionality is used and the signal
	* @ref sigItemRenamedInplace emitted.
	*/
	virtual void rename( TQListViewItem * pItem, int nColumn );

	/** Returns info, is root element is already created */
	bool hasRootNode();
	/** Returns last top-level child on the tree. If there are no chold in the tree, null is returned. */
	KXE_TreeViewItem* lastChild();

public slots:

	// configuration slots
	//////////////////////////////////////////////////////////////

	/**
	 * Changes this tree view's settings according to the current
	 * configuration.
	 */
	void slotTreeViewSettingsChanged();

signals:
	/** emitted, when no item is selected */
	void sigSelectionCleared(bool);

	/** emitted, when an XML element item is selected */
	void sigSelectionChanged( const TQDomElement & );

	/** emitted, when an XML Content item is selected */
	void sigSelectionChanged( const TQDomCharacterData & );

	/** emitted, when an XML proc.instr. item is selected */
	void sigSelectionChanged( const TQDomProcessingInstruction & );

	/**
	 * Signals the change of bookmark status.
	 * true -  item(s) bookmarked
	 * false - no item bookmarked
	 */
	void sigNewBookmarkStatus( bool fStatus );

	/** Emitted, when a context menu is requested */
	void sigContextMenuRequested( const TQString & szMenuName, const TQPoint & pos );
	/** Emitted when user presses a key. */
	void sigKeyPressed(TQKeyEvent* e);

protected:
	/** if RMB shows the popupmenu corresponding to the selected item */
	void contentsMousePressEvent( TQMouseEvent * );

	/** Finds the corresponding treeview item to the given node. */
	KXE_TreeViewItem * findCorrespondingItem( const TQDomNode & node );

	/** Overrides TDEListView::contentsMouseReleaseEvent */
	void contentsMouseReleaseEvent(TQMouseEvent *);

	/** Overrides TDEListView::contentsMouseMoveEvent */
	void contentsMouseMoveEvent(TQMouseEvent *);

	/** Overrides TQScrollView::contentsDragEnterEvent */
	void contentsDragEnterEvent(TQDragEnterEvent *);

	/** Overrides TQScrollView::contentsDragMoveEvent */
	void contentsDragMoveEvent(TQDragMoveEvent *);

	/** Overrides TQScrollView::contentsDragLeaveEvent */
	void contentsDragLeaveEvent(TQDragLeaveEvent *);

	/** Overrides TQScrollView::contentsDropEvent */
	void contentsDropEvent(TQDropEvent *);
    virtual void keyPressEvent(TQKeyEvent *e);

protected slots:
	/** Checks, which type of item was selected an emits the corresponding signal. */
	void slotSelectionChanged();
	/**
	 * Ensures that the expanded item's grandchild items are created.
	 * This is very important for the "create items on demand" mode. But even in
	 * "create all items while loading" mode, this function has to be executed,
	 * because KXMLEditor could have been in "create items on demand" mode during
	 * the opening of the document.
	 *
	 * To be connected to the signal TQListView::expanded(TQListViewItem*).
	 */
	void slotItemExpanded( TQListViewItem * );

private slots:

	/** Called, when m_autoOpenTimer timeout occured */
	void slotAutoOpenFolder();

protected:

	/** the GUI client, needed for the popupmenus */
	KXMLGUIClient * m_pGUIClient;

	/** number of bookmarked items */
	unsigned int m_nBookmarkedItems;	

	/** True if drag&drop operation started, otherwise is false */
	bool m_bDrag;

	/** Contain mouse position of drag operation */
	TQPoint m_dragPos;

	/** The item that was current before the drag-enter event happened */
	TQListViewItem *m_pCurrentBeforeDropItem;

	/** The item we are moving the mouse over (during a drag) */
	TQListViewItem *m_pDropItem;

	/** List of avalilable drop formats */
	TQStrList m_lstDropFormats;

	/** Timer for counting time to auto open fselected folder while drag */
	TQTimer *m_autoOpenTimer;
};

#endif