lib

kformulacontainer.h
1/* This file is part of the KDE project
2 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
3 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
4
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.
9
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.
14
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., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef KFORMULACONTAINER_H
22#define KFORMULACONTAINER_H
23
24#include <tqclipboard.h>
25#include <tqdom.h>
26#include <tqimage.h>
27#include <tqptrlist.h>
28#include <tqobject.h>
29#include <tqptrstack.h>
30#include <tqstring.h>
31
32#include <kcommand.h>
33//#include <KoCommandHistory.h>
34#include "KoCommandHistory.h"
35#include "kformuladefs.h"
36
37class TQColorGroup;
38class TQKeyEvent;
39class TQPainter;
40
41class KCommand;
42class KPrinter;
43
44KFORMULA_NAMESPACE_BEGIN
45
46class BasicElement;
47class Document;
48class FormulaCursor;
49class FormulaElement;
50class IndexElement;
51class PlainCommand;
52class SymbolTable;
53
54
62class FormulaDocument {
63 // not allowed
64 FormulaDocument( const FormulaDocument& ) {}
65 FormulaDocument& operator=( const FormulaDocument& ) { return *this; }
66public:
67
68 FormulaDocument() {}
69 virtual ~FormulaDocument() {}
70
71 virtual void elementRemoval(BasicElement* /*child*/) {}
72 virtual void changed() {}
73 virtual void cursorHasMoved( FormulaCursor* ) {}
74 virtual void moveOutLeft( FormulaCursor* ) {}
75 virtual void moveOutRight( FormulaCursor* ) {}
76 virtual void moveOutAbove( FormulaCursor* ) {}
77 virtual void moveOutBelow( FormulaCursor* ) {}
78 virtual void tell( const TQString& /*msg*/ ) {}
79 virtual void insertFormula( FormulaCursor* ) {}
80 virtual void removeFormula( FormulaCursor* ) {}
81 virtual void baseSizeChanged( int, bool ) {}
82 virtual const SymbolTable& getSymbolTable() const = 0;
83};
84
85
90class KOFORMULA_EXPORT Container : public TQObject, public FormulaDocument {
91 friend class MimeSource;
92 TQ_OBJECT
93
94
95 // no copying
96 Container( const Container& );
97 Container& operator= ( const Container& );
98
99public:
100
101 enum ViewActions { EXIT_LEFT, EXIT_RIGHT,
102 EXIT_ABOVE, EXIT_BELOW,
103 INSERT_FORMULA, REMOVE_FORMULA };
104
113 Container( Document* doc, int pos, bool registerMe=true );
114 ~Container();
115
121 void initialize();
122
129
134 void elementRemoval(BasicElement* child);
135
140 void changed();
141
148
153 void moveOutLeft( FormulaCursor* );
154 void moveOutRight( FormulaCursor* );
155 void moveOutAbove( FormulaCursor* );
156 void moveOutBelow( FormulaCursor* );
157 void tell( const TQString& msg );
158 void removeFormula( FormulaCursor* );
159
163 void registerFormula( int pos=-1 );
164 void unregisterFormula();
165
169 void baseSizeChanged( int size, bool owned );
170
174 void draw( TQPainter& painter, const TQRect& r,
175 const TQColorGroup& cg, bool edit=false );
176
180 void draw( TQPainter& painter, const TQRect& r, bool edit=false );
181
185 void save( TQDomElement &root );
186
190 void saveMathML( TQTextStream& stream, bool oasisFormat = false );
191
196 bool loadMathML( const TQDomDocument &doc, bool oasisFormat = false );
197
202 bool loadMathML( const TQDomElement &doc, bool oasisFormat = false );
203
207 bool load( const TQDomElement &fe );
208
212 TQString texString();
213
214 TQString formulaString();
215
219 void print(KPrinter& printer);
220
224 TQImage drawImage( int width, int height );
225
230 const FormulaCursor* activeCursor() const;
231
238 void setActiveCursor(FormulaCursor* cursor);
239
243 TQRect boundingRect() const;
244
248 TQRect coveredRect();
249
250 double width() const;
251 double height() const;
252
257 double baseline() const;
258
263 void moveTo( int x, int y );
264
271 virtual double getDocumentX() const { return -1; }
272 virtual double getDocumentY() const { return -1; }
273 virtual void setDocumentPosition( double /*x*/, double /*y*/ ) {}
274
282 virtual void startEvaluation() {}
283
287 void testDirty();
288
292 virtual void recalc();
293
297 bool isEmpty();
298
302 virtual Document* document() const;
303
304 virtual const SymbolTable& getSymbolTable() const;
305
306 int fontSize() const;
307
311 void setFontSize( int pointSize, bool forPrint = false );
312
313 void setFontSizeDirect( int pointSize );
314
318 void updateMatrixActions();
319
320signals:
321
327
331 void leaveFormula( Container* formula, FormulaCursor* cursor, int cmd );
332
336 void formulaChanged( int width, int height );
337 void formulaChanged( double width, double height );
338
342 void statusMsg( const TQString& msg );
343
347 void errorMsg( const TQString& );
348
353
358
362 void baseSizeChanged( int );
363
364public:
365
369 void input( TQKeyEvent* event );
370
371 void performRequest( Request* request );
372
373 // There are a lot of thing we can do with the formula.
374
378 void paste();
379
383 void paste( const TQDomDocument& document, TQString desc );
384
388 void copy();
389
393 void cut();
394
395protected:
396
397 KoCommandHistory* getHistory() const;
398
403
408
409 void emitErrorMsg( const TQString& );
410
411private:
412
416 void execute(KCommand *command);
417
421 void checkCursor();
422
426 bool hasValidCursor() const;
427
428 struct Container_Impl;
429 Container_Impl* impl;
430
431 // debug
432 friend class TestFormulaCursor;
433 friend class TestFormulaElement;
434 friend class TestIndexElement;
435 friend class TestCommands;
436};
437
438KFORMULA_NAMESPACE_END
439
440#endif // KFORMULACONTAINER_H
Basis of every formula element.
bool loadMathML(const TQDomDocument &doc, bool oasisFormat=false)
Load function.
FormulaElement * rootElement() const
void registerFormula(int pos=-1)
Register and unregister this formula with its document.
void leaveFormula(Container *formula, FormulaCursor *cursor, int cmd)
The cursor wants to leave this formula.
void copy()
Copy the current selection to the clipboard.
FormulaCursor * createCursor()
Returns a new cursor.
void paste()
Insert data from the clipboard.
void initialize()
Needs to be called before anything else can be done with a newly created formula!
void cursorMoved(FormulaCursor *cursor)
The cursor has been moved but the formula hasn't been changed.
void errorMsg(const TQString &)
A message that describes an error.
void baseSizeChanged(int size, bool owned)
The base size changed.
void cursorHasMoved(FormulaCursor *)
Gets called when a request has the side effect of moving the cursor.
virtual double getDocumentX() const
KWord uses a transformed painter to draw formulas, so every formula has the internal position (0,...
double baseline() const
void formulaChanged(int width, int height)
The formula has changed and needs to be redrawn.
void baseSizeChanged(int)
We've got a new base size.
virtual Document * document() const
TQImage drawImage(int width, int height)
virtual void startEvaluation()
Start the documents evaluation at this formula.
bool load(const TQDomElement &fe)
Loads a formula from the document.
virtual FormulaElement * createMainSequence()
Factory method.
TQString texString()
void setActiveCursor(FormulaCursor *cursor)
Sets the cursor that is to be used for any editing.
void save(TQDomElement &root)
Saves the data into the document.
void moveOutLeft(FormulaCursor *)
Inside the formula occurred an event that must be handled outside.
void cut()
Copy and remove.
void print(KPrinter &printer)
Prints the formula.
void statusMsg(const TQString &msg)
A message that might be a useful hint.
void changed()
Gets called when ever something changes and we need to recalc.
void input(TQKeyEvent *event)
General input.
void formulaLoaded(FormulaElement *)
Tells the cursors that we have just loaded a new formula.
void elementWillVanish(BasicElement *element)
The element is going to leave the formula with and all its children.
FormulaCursor * activeCursor()
void draw(TQPainter &painter, const TQRect &r, const TQColorGroup &cg, bool edit=false)
Draws the whole thing.
void moveTo(int x, int y)
Moves the formula to a new location.
void elementRemoval(BasicElement *child)
Gets called just before the child is removed from the element tree.
TQRect boundingRect() const
void saveMathML(TQTextStream &stream, bool oasisFormat=false)
Save formula as MathML.
A document that can contain a lot of formulas (container).
The selection.
The main element.
The element with up to four indexes in the four corners.
The command history stores a (user) configurable amount of Commands.
Base for all kformula commands.
The symbol table.
Definition symboltable.h:77