kword

KWCanvas.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2002-2006 David Faure <faure@kde.org>
4 Copyright (C) 2005 Thomas Zander <zander@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef KWCANVAS_H
23#define KWCANVAS_H
24
25#include <kprinter.h>
26#include <KoRect.h>
27#include <tqscrollview.h>
28#include <tqstylesheet.h>
29#include <KoRichText.h>
30#include <KoQueryTrader.h>
31#include <KoPicture.h>
32
33#include "KWTextParag.h"
34#include "KWFrame.h"
35#include "KWVariable.h"
36#include "KWCommand.h"
37
39class KWDocument;
40class KWFrame;
41class KWFrameSet;
42class KWFrameSetEdit;
43class KWTableFrameSet;
45class KWViewMode;
47class KWGUI;
48class KWTableTemplate;
49class KoTextParag;
50class TQTimer;
52class KWFrameView;
53
60class KWCanvas : public TQScrollView
61{
62 TQ_OBJECT
63
64
65public:
66 KWCanvas(const TQString& viewMode, TQWidget *parent, KWDocument *d, KWGUI *lGui);
67 virtual ~KWCanvas();
68
69 KWDocument * kWordDocument() const { return m_doc; }
70 KWGUI * gui() const { return m_gui; }
71 KWFrameViewManager* frameViewManager() { return m_frameViewManager; }
72 KWFrameSetEdit *currentFrameSetEdit() const { return m_currentFrameSetEdit; }
73
74 void switchViewMode( const TQString& newViewMode );
75 KWViewMode *viewMode() const { return m_viewMode; }
76
77 void repaintAll( bool erase = false );
83 void repaintChanged( KWFrameSet * fs, bool resetChanged );
84
86 void viewportResizeEvent( TQResizeEvent * );
87
88 void print( TQPainter *painter, KPrinter *printer );
89 bool eventFilter( TQObject *o, TQEvent *e );
90 bool focusNextPrevChild( bool next);
91
92 void setFrameBackgroundColor( const TQBrush &backColor );
93
94 void editFrameProperties();
95 void editFrameProperties( KWFrameSet * frameset );
96
97 void pasteFrames();
98
99 // Mouse press
100 void mpCreate( const TQPoint& normalPoint, bool noGrid );
101 void mpCreatePixmap( const TQPoint& normalPoint, bool noGrid );
102 // Mouse move
103 void mmCreate( const TQPoint& normalPoint, bool noGrid );
104 // Mouse release
105 void mrEditFrame();
106 void mrCreateText();
107 void mrCreatePixmap();
108 void mrCreatePart();
109 void mrCreateFormula();
110 void mrCreateTable();
111
112 enum MouseMode {
113 MM_EDIT = 0,
114 MM_CREATE_TEXT = 2,
115 MM_CREATE_PIX = 3,
116 MM_CREATE_TABLE = 5,
117 MM_CREATE_FORMULA = 6,
118 MM_CREATE_PART = 7
119 };
120 void setMouseMode( MouseMode _mm );
121 MouseMode mouseMode()const { return m_mouseMode; }
122
123 // makes the user draw the rect for inserting the picture
124 void insertPicture( const KoPicture& newPicture, TQSize pixmapSize, bool _keepRatio );
125 void insertPart( const KoDocumentEntry &entry );
126 void pasteImage( TQMimeSource *e, const KoPoint &docPoint );
127 // insert a (non-inline) picture at the given position; used by dnd and dcop
128 void insertPictureDirect( const KoPicture& picture, const KoPoint& pos, const TQSize& sz = TQSize() );
129
130 void updateCurrentFormat();
131
132 void updateFrameFormat();
133
134 // Table creation support - methods used by KWView to reuse the last settings
135 unsigned int tableRows() const { return m_table.rows; }
136 void setTableRows( unsigned int rows ) { m_table.rows=rows; }
137 unsigned int tableCols() const { return m_table.cols; }
138 void setTableCols( unsigned int cols ) { m_table.cols=cols; }
139 int tableWidthMode()const { return m_table.width; }
140 int tableHeightMode()const { return m_table.height; }
141 bool tableIsFloating()const { return m_table.floating; }
142 int tableFormat()const { return m_table.format;}
143
144 void setTableFormat(int _nb){ m_table.format=_nb;}
145
146 TQString tableTemplateName()const { return m_table.tableTemplateName;}
147 void setTableTemplateName(const TQString &_name) { m_table.tableTemplateName=_name;}
148
149 void setPictureInline( bool _inline) { m_picture.pictureInline = _inline;}
150 bool pictureInline() const { return m_picture.pictureInline; }
151
152 void setPictureKeepRatio( bool _keep) { m_picture.keepRatio = _keep;}
153 bool pictureKeepRatio() const { return m_picture.keepRatio; }
154
155 void createTable( unsigned int rows, unsigned int cols,
156 int /*KWTableFrameSet::CellSize*/ wid, int /*KWTableFrameSet::CellSize*/ hei,
157 bool isFloating,
158 KWTableTemplate *tt=0L, int format=31 );
159
162 KWTableFrameSet *getCurrentTable()const { return m_currentTable; }
164 int currentTableRow() const;
166 int currentTableCol() const;
167
168 //move canvas to show point dPoint (in doc coordinates)
169 void scrollToOffset( const KoPoint & dPoint );
170
171 //for KWTextFrameSetEdit
172 void dragStarted() { m_mousePressed = false; }
173
174 void setXimPosition( int x, int y, int w, int h );
175
176 void updateRulerOffsets( int cx = -1, int cy = -1 );
177
178 void inlinePictureStarted();
179
180 void ensureCursorVisible();
181
182 void editFrameSet( KWFrameSet * frameSet, bool onlyText = false );
187 void editTextFrameSet( KWFrameSet * fs, KoTextParag* parag, int index );
188 bool checkCurrentEdit( KWFrameSet * fs, bool onlyText = false);
189
190
191 NoteType footNoteType()const{return m_footEndNote.noteType;}
192 KWFootNoteVariable::Numbering numberingFootNoteType() const { return m_footEndNote.numberingType;}
193
194 void setFootNoteType( NoteType _type ) { m_footEndNote.noteType = _type; }
195 void setNumberingFootNoteType(KWFootNoteVariable::Numbering _type) { m_footEndNote.numberingType = _type; }
196
197 void tableSelectCell(KWTableFrameSet *table, KWFrameSet *cell);
198 void selectAllFrames( bool select );
199
200 KCommand * createTextBox(const KoRect & rect );
201
202 // Called by KWTextFrameSetEdit when pgup/pgdown can't go further
203 // or directly called by pgup/pgdown if not using 'moves caret' feature.
204 void viewportScroll( bool up );
205
207 void resetStatusBarText();
208
211 KoPoint caretPos();
212 void applyGrid( KoPoint &p );
213
214 bool overwriteMode() const { return m_overwriteMode; }
215
216 // Returns the current text edit object, or 0 if
217 // - no frame is being edited
218 // - a non-text frame is being edited
219 KWTextFrameSetEdit* currentTextEdit() const;
220
221 bool insertInlinePicture();
222
223protected:
224 void drawGrid( TQPainter &p, const TQRect& rect );
225
229 virtual void drawContents( TQPainter *p, int cx, int cy, int cw, int ch );
236 void drawDocument( TQPainter *painter, const TQRect &crect, KWViewMode* viewMode );
241 void drawPageBorders( TQPainter * painter, const TQRect & crect, const TQRegion & emptySpaceRegion );
242
243 virtual void keyPressEvent( TQKeyEvent *e );
244 virtual void contentsMousePressEvent( TQMouseEvent *e );
245 virtual void contentsMouseMoveEvent( TQMouseEvent *e );
246 virtual void contentsMouseReleaseEvent( TQMouseEvent *e );
247 virtual void contentsMouseDoubleClickEvent( TQMouseEvent *e );
248 virtual void contentsDragEnterEvent( TQDragEnterEvent *e );
249 virtual void contentsDragMoveEvent( TQDragMoveEvent *e );
250 virtual void contentsDragLeaveEvent( TQDragLeaveEvent *e );
251 virtual void contentsDropEvent( TQDropEvent *e );
252 virtual void resizeEvent( TQResizeEvent *e );
253
254 KWTableFrameSet * createTable(); // uses m_insRect and m_table to create the table
255
256 void terminateCurrentEdit();
257 bool insertInlineTable();
258
259signals:
260 // Emitted when the current frameset edit changes
261 void currentFrameSetEditChanged();
262 // Emitted by the current frameset edit when its selection changes
263 void selectionChanged( bool hasSelection );
264 // Emitted when Mouse Mode changed
265 void currentMouseModeChanged(int newMouseMode);
266 // Emitted when frames have been selected or unselected (to disable/enable the UI in kwview)
267 void frameSelectedChanged();
268 // Emitted when the document structure has changed
269 // ### DF: IMHO this should be only emitted by KWDocument (e.g. addFrameSet)
270 void docStructChanged(int _type);
271 // Emitted when the insert key is pressed
272 void overwriteModeChanged( bool m_overwriteMode );
273
274 void viewTransformationsChanged();
275
276 void updateRuler();
277
278private slots:
279 void slotContentsMoving( int, int );
280 void slotNewContentsSize();
281 void slotMainTextHeightChanged();
282 void doAutoScroll();
283
284 //Terminate editing this frameset, if we were editing it.
285 void terminateEditing( KWFrameSet *fs );
286
287private:
292 void drawFrameSet( KWFrameSet * frameset, TQPainter * painter,
293 const TQRect & crect, bool onlyChanged, bool resetChanged, KWViewMode* viewMode );
294
295 void drawMovingRect( TQPainter & p );
296 void deleteMovingRect();
303 void applyAspectRatio( double ratio, KoRect& insRect );
304
305#ifndef NDEBUG
306 void printRTDebug( int );
307#endif
308
309 KWFrameViewManager *m_frameViewManager;
310 KWDocument *m_doc;
311 KWFrameSetEdit *m_currentFrameSetEdit;
312 KWGUI *m_gui;
313 TQTimer *m_scrollTimer;
314 bool m_mousePressed;
315 bool m_printing;
316 bool m_imageDrag;
317
318 //define type of frame (for set inline frame)
319 bool m_frameInline;
320 FrameSetType m_frameInlineType;
321
322 // Warning: the viewmode is stored here for good design ;)
323 // but it's owned by the document, since we currently have one viewmode for all views.
324 KWViewMode *m_viewMode;
325
326 // Frame stuff
327 MouseMode m_mouseMode;
328 MouseMeaning m_mouseMeaning; // set by mousePress, used by mouseMove
329 KoRect m_resizedFrameInitialSize; // when resizing a frame
330 double m_resizedFrameInitialMinHeight; // when resizing a frame
331 KoRect m_insRect;
332 bool m_deleteMovingRect;
333 KoPicture m_kopicture; // The picture
334 TQSize m_pixmapSize; // size when inserting a picture (not necessarily the size of the picture)
335 bool m_keepRatio;//when inserting a picture
336 KoDocumentEntry m_partEntry; // when inserting a part
337 int m_rowColResized; // when resizing a row or column
338 bool m_temporaryStatusBarTextShown; // Indicates if the temporary is shown
339 double m_previousTableSize; //previous column or row size before resizing it
340 KoPoint m_lastCaretPos; // position of caret when editing stopped in document coordinates
341 bool m_overwriteMode;
342
343 // Table creation support.
344 // Having this as a member variable allows to remember and reuse the last settings
345 struct
346 {
347 unsigned int cols;
348 unsigned int rows;
349 int format;
350 int /*KWTableFrameSet::CellSize*/ width;
351 int /*KWTableFrameSet::CellSize*/ height;
352 bool floating;
353 TQString tableTemplateName;
354 KWTableTemplate *tt;
355 } m_table;
356 KWTableFrameSet *m_currentTable;
357 InteractionPolicy *m_interactionPolicy;
358
359 struct
360 {
361 NoteType noteType;
362 KWFootNoteVariable::Numbering numberingType;
363 } m_footEndNote;
364
365 struct
366 {
367 bool pictureInline;
368 bool keepRatio;
369 }m_picture;
370};
371
380 public:
389 virtual void handleMouseMove(TQt::ButtonState keyState, const KoPoint &point) = 0;
395 virtual KCommand* createCommand() = 0;
400 void cancelInteraction();
404 virtual void finishInteraction() = 0;
405
414 static InteractionPolicy* createPolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point, TQt::ButtonState buttonState, TQt::ButtonState keyState);
415
416 void hadDragEvents() { m_gotDragEvents = true; }
417 bool gotDragEvents() { return m_gotDragEvents; }
418
419 protected:
426 InteractionPolicy(KWCanvas *parent, bool doInit = true, bool includeInlineFrames = false);
427
428 TQValueList<FrameIndex> m_indexFrame;
429 KWCanvas *m_parent;
430 TQValueList<KWFrame*> m_frames;
431
432 private:
433 void init();
434 bool m_gotDragEvents;
435};
436
443 public:
444 FrameResizePolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point);
445 void handleMouseMove(TQt::ButtonState keyState, const KoPoint &point);
446 KCommand *createCommand();
447 void finishInteraction();
448
449 private:
450 TQValueList<FrameResizeStruct> m_frameResize;
451 bool m_top, m_bottom, m_left, m_right;
452 KoRect m_boundingRect;
453 KoPoint m_hotSpot;
454};
455
462 public:
463 FrameMovePolicy(KWCanvas *parent, KoPoint &point);
464 void handleMouseMove(TQt::ButtonState keyState, const KoPoint &point);
465 KCommand *createCommand();
466 void finishInteraction();
467 private:
468 TQValueList<FrameMoveStruct> m_frameMove;
469 KoPoint m_hotSpot;
470 KoPoint m_startPoint;
471 KoRect m_boundingRect;
472};
473
478 public:
479 FrameSelectPolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point, TQt::ButtonState state, TQt::ButtonState keyState);
480 void handleMouseMove(TQt::ButtonState keyState, const KoPoint &point);
481 KCommand *createCommand();
482 void finishInteraction();
483 bool isValid() { return m_validSelection; }
484
485 private:
486 bool m_validSelection;
487};
488
489#endif
A policy that handles frame moves of any number of frames.
Definition KWCanvas.h:461
void handleMouseMove(TQt::ButtonState keyState, const KoPoint &point)
Extending classes should implement this method to alter the frames or other data based on the new mou...
void finishInteraction()
Override to make final changes to the data on the end of an interaction.
KCommand * createCommand()
For interactions that are undo-able this method should be implemented to return such a command.
A policy that handles resizes of any number of frames.
Definition KWCanvas.h:442
void finishInteraction()
Override to make final changes to the data on the end of an interaction.
KCommand * createCommand()
For interactions that are undo-able this method should be implemented to return such a command.
void handleMouseMove(TQt::ButtonState keyState, const KoPoint &point)
Extending classes should implement this method to alter the frames or other data based on the new mou...
A policy to select frames.
Definition KWCanvas.h:477
void finishInteraction()
Override to make final changes to the data on the end of an interaction.
void handleMouseMove(TQt::ButtonState keyState, const KoPoint &point)
Extending classes should implement this method to alter the frames or other data based on the new mou...
KCommand * createCommand()
For interactions that are undo-able this method should be implemented to return such a command.
Interaction policy defines the behavior in case the user clicks or drags the mouse.
Definition KWCanvas.h:379
virtual void handleMouseMove(TQt::ButtonState keyState, const KoPoint &point)=0
Extending classes should implement this method to alter the frames or other data based on the new mou...
static InteractionPolicy * createPolicy(KWCanvas *parent, MouseMeaning meaning, KoPoint &point, TQt::ButtonState buttonState, TQt::ButtonState keyState)
This instanciates a new policy object and decides which policy is created based on the params.
virtual void finishInteraction()=0
Override to make final changes to the data on the end of an interaction.
void cancelInteraction()
This method will undo frames based interactions by calling createCommand() and unexecuting that.
virtual KCommand * createCommand()=0
For interactions that are undo-able this method should be implemented to return such a command.
Class: KWCanvas This class is responsible for the rendering of the frames to the screen as well as th...
Definition KWCanvas.h:61
virtual void drawContents(TQPainter *p, int cx, int cy, int cw, int ch)
Reimplemented from TQScrollView, to draw the contents of the canvas.
Definition KWCanvas.cpp:256
void viewportResizeEvent(TQResizeEvent *)
We need to repaint if the window is resized.
Definition KWCanvas.cpp:207
int currentTableRow() const
When the cursor is in a table cell, this returns the row.
void drawDocument(TQPainter *painter, const TQRect &crect, KWViewMode *viewMode)
The main drawing method.
Definition KWCanvas.cpp:271
void editTextFrameSet(KWFrameSet *fs, KoTextParag *parag, int index)
Starting editing fs if we're not yet doing it.
void repaintChanged(KWFrameSet *fs, bool resetChanged)
Only repaint the frameset fs.
Definition KWCanvas.cpp:186
KoPoint caretPos()
Returns the caret position in document coordinates.
int currentTableCol() const
When the cursor is in a table cell, this returns the column.
void drawPageBorders(TQPainter *painter, const TQRect &crect, const TQRegion &emptySpaceRegion)
Draw page borders, but also clear up the space between the frames and the page borders,...
KWTableFrameSet * getCurrentTable() const
The current table (either because one or more cells are selected, or because the cursor is in a table...
Definition KWCanvas.h:162
void resetStatusBarText()
Resets the status bar text.
Command created when one or more frames are moved.
Definition KWCommand.h:273
This object is created to edit a particular frameset in a particular view The view's canvas creates i...
Class: KWFrameSet Base type, a frameset holds content as well as frames to show that content.
Definition KWFrameSet.h:62
Class that knows about all the (visible) frames in the document and will act as a manager between the...
an instance of a KWFrameView represents the view in the MVC model of a frame; there can be multiple K...
Definition KWFrameView.h:82
This class represents a single frame.
Definition KWFrame.h:68
This class implements tables by acting as the manager for the frame(set)s which make up the table cel...
Object that is created to edit a Text frame set (KWTextFrameSet).
Abstract base class for KWCanvas's view modes.
Definition KWViewMode.h:48