fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / khtml / editing / editor.h
blob324ffda92211b69457c08cbfb411eb88f743a269
1 /* This file is part of the KDE project
3 * Copyright (C) 2004 Leo Savernik <l.savernik@aon.at>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #ifndef __EDITOR_H
22 #define __EDITOR_H
24 #include "editor_command.h"
26 #include <khtml_export.h>
28 #include <QObject>
30 class QKeyEvent;
32 class KHTMLPart;
33 class KHTMLView;
34 class KHTMLEditorPart;
36 namespace khtml {
37 class EditCommand;
38 struct EditorContext;
41 namespace DOM {
43 class Range;
44 class NodeImpl;
45 class ElementImpl;
46 class DOMString;
47 class CSSStyleDeclarationImpl;
48 class EditorPrivate;
50 /**
51 * This class resembles the editing API when the associated khtml document
52 * is editable (in design mode), or contains editable elements.
54 * FIXME: document this thoroughly
56 * @short API to Wysiwyg Markup-Editor.
57 * @author Leo Savernik
59 class KHTML_EXPORT Editor : public QObject {
60 Q_OBJECT
62 Editor(KHTMLPart *);
63 virtual ~Editor();
64 public:
66 /**
67 * Tri-state boolean.
69 enum TriState { FalseTriState, TrueTriState, MixedTriState };
71 // == interface to editor commands
73 /**
74 * Executes the given editor command.
75 * @param command name of command
76 * @param userInterface whether an user interface should be used to input data. This is command dependant.
77 * @param value value for command. Its semantic depends on the command.
79 bool execCommand(const DOMString &command, bool userInterface, const DOMString &value);
80 /** Checks whether the given command is enabled. */
81 bool queryCommandEnabled(const DOMString &command);
82 /** Checks whether the given command's style is indeterminate */
83 bool queryCommandIndeterm(const DOMString &command);
84 /** Checks whether the given command's style is state */
85 bool queryCommandState(const DOMString &command);
86 /** Checks whether the given command is supported in the current context */
87 bool queryCommandSupported(const DOMString &command);
88 /** Returns the given command's value */
89 DOMString queryCommandValue(const DOMString &command);
91 /**
92 * Executes the given built-in editor command.
93 * @param EditorCommand index of command
94 * @param userInterface whether an user interface should be used to input data. This is command dependant.
95 * @param value value for command. Its semantic depends on the command.
97 bool execCommand(EditorCommand, bool userInterface, const DOMString &value);
98 /** Checks whether the given command is enabled. */
99 bool queryCommandEnabled(EditorCommand);
100 /** Checks whether the given command's style is indeterminate */
101 bool queryCommandIndeterm(EditorCommand);
102 /** Checks whether the given command's style is state */
103 bool queryCommandState(EditorCommand);
104 /** Checks whether the given command is supported in the current context */
105 bool queryCommandSupported(EditorCommand);
106 /** Returns the given command's value */
107 DOMString queryCommandValue(EditorCommand);
109 // == direct interface to some built-in commands
111 /** copy selection to clipboard */
112 void copy();
113 /** cut selection and insert into clipboard */
114 void cut();
115 /** paste into current selection from clipboard */
116 void paste();
117 /** returns whether clipboard contains data to be pasted */
118 bool canPaste() const;
119 /** redo last undone action */
120 void redo();
121 /** undo last action */
122 void undo();
123 /** returns whether any actions can be redone */
124 bool canRedo() const;
125 /** returns whether any actions can be undone */
126 bool canUndo() const;
127 /** applies the given style to the current selection */
128 void applyStyle(DOM::CSSStyleDeclarationImpl *);
129 /** returns whether the selection has got applied the given style */
130 TriState selectionHasStyle(DOM::CSSStyleDeclarationImpl *) const;
131 /** returns whether the selection has got applied the given style */
132 bool selectionStartHasStyle(DOM::CSSStyleDeclarationImpl *) const;
133 /** ? */
134 DOM::DOMString selectionStartStylePropertyValue(int stylePropertyID) const;
135 /** prints the current document */
136 void print();
137 /** computed style of current selection */
138 DOM::CSSStyleDeclarationImpl *selectionComputedStyle(DOM::NodeImpl *&nodeToRemove) const;
141 // == ### more stuff I'm not sure about whether it should be public
144 * Returns the most recent edit command applied.
146 khtml::EditCommand lastEditCommand() const;
149 * Called when editing has been applied.
151 void appliedEditing(khtml::EditCommand &);
154 * Called when editing has been unapplied.
156 void unappliedEditing(khtml::EditCommand &);
159 * Called when editing has been reapplied.
161 void reappliedEditing(khtml::EditCommand &);
164 * Returns the typing style for the document.
166 DOM::CSSStyleDeclarationImpl *typingStyle() const;
169 * Sets the typing style for the document.
171 void setTypingStyle(DOM::CSSStyleDeclarationImpl *);
174 * Clears the typing style for the document.
176 void clearTypingStyle();
178 private:
179 /** Handles key events. Returns true if event has been handled. */
180 bool handleKeyEvent(QKeyEvent *);
182 private:
183 EditorPrivate *const d;
185 DOM::CSSStyleDeclarationImpl *m_typingStyle;
187 KHTMLPart *m_part;
189 friend class ::KHTMLPart;
190 friend class ::KHTMLView;
191 friend class ::KHTMLEditorPart;
192 friend struct khtml::EditorContext;
193 friend class DOM::ElementImpl;
196 }/*namespace DOM*/
198 #endif // __EDITOR_H