24#include "KWTableFrameSet.h"
25#include "KWPartFrameSet.h"
26#include "KWFormulaFrameSet.h"
27#include "KWDocument.h"
29#include "KWViewMode.h"
30#include "KWFrameDia.h"
32#include "KWTableTemplate.h"
33#include "KWTextDocument.h"
34#include "KWFrameList.h"
35#include "KWPageManager.h"
37#include "KWPictureFrameSet.h"
38#include "KWFrameView.h"
39#include "KWFrameViewManager.h"
43#include <tqclipboard.h>
44#include <tqprogressdialog.h>
45#include <tqobjectlist.h>
46#include <tqapplication.h>
47#include <tqwhatsthis.h>
50#include <KoStoreDrag.h>
51#include <KoPictureCollection.h>
53#include <tdetempfile.h>
57#include <tdemessagebox.h>
58#include <tdemultipledrag.h>
61#include <tdeio/netaccess.h>
66KWCanvas::KWCanvas(
const TQString& viewMode, TQWidget *parent, KWDocument *d, KWGUI *lGui)
67 : TQScrollView( parent,
"canvas", WStaticContents| WResizeNoErase | WRepaintNoErase ), m_doc( d )
71 m_currentFrameSetEdit = 0L;
72 m_mouseMeaning = MEANING_NONE;
73 m_mousePressed =
false;
75 m_frameInline =
false;
76 m_overwriteMode =
false;
79 m_picture.pictureInline =
false;
80 m_picture.keepRatio =
true;
84 m_frameInlineType = FT_TABLE;
85 m_viewMode = KWViewMode::create( viewMode, m_doc,
this );
86 m_interactionPolicy = 0;
91 m_table.width = KWTableFrameSet::TblAuto;
92 m_table.height = KWTableFrameSet::TblAuto;
93 m_table.floating =
true;
94 m_table.tableTemplateName=TQString();
97 m_footEndNote.noteType = FootNote;
98 m_footEndNote.numberingType = KWFootNoteVariable::Auto;
103 m_deleteMovingRect =
false;
104 m_resizedFrameInitialMinHeight = 0;
105 m_temporaryStatusBarTextShown =
false;
107 viewport()->setBackgroundMode( PaletteBase );
108 viewport()->setAcceptDrops(
true );
110 setKeyCompression(
true );
111 viewport()->setMouseTracking(
true );
113 m_scrollTimer =
new TQTimer(
this );
114 connect( m_scrollTimer, TQ_SIGNAL( timeout() ),
115 this, TQ_SLOT( doAutoScroll() ) );
117 viewport()->setFocusProxy(
this );
118 viewport()->setFocusPolicy( TQWidget::WheelFocus );
119 setInputMethodEnabled(
true );
121 viewport()->installEventFilter(
this );
122 installEventFilter(
this );
123 KCursor::setAutoHideCursor(
this,
true,
true );
125 connect(
this, TQ_SIGNAL(contentsMoving(
int,
int )),
126 this, TQ_SLOT(slotContentsMoving(
int,
int )) );
128 connect( m_doc, TQ_SIGNAL( newContentsSize() ),
129 this, TQ_SLOT( slotNewContentsSize() ) );
131 connect( m_doc, TQ_SIGNAL( mainTextHeightChanged() ),
132 this, TQ_SLOT( slotMainTextHeightChanged() ) );
134 connect( m_doc, TQ_SIGNAL( sig_terminateEditing(
KWFrameSet * ) ),
135 this, TQ_SLOT( terminateEditing(
KWFrameSet * ) ) );
137 slotNewContentsSize();
139 m_mouseMode = MM_EDIT;
140 setMouseMode( MM_EDIT );
144 TQString fsName = m_doc->initialFrameSet();
145 if ( !fsName.isEmpty() )
146 fs = m_doc->frameSetByName( fsName );
148 fs = m_doc->frameSet( 0 );
150 if ( fs && fs->
isVisible( m_viewMode ) ) {
151 checkCurrentEdit( fs );
154 int paragId = m_doc->initialCursorParag();
155 int index = m_doc->initialCursorIndex();
156 if ( paragId != 0 || index != 0 ) {
157 KoTextParag* parag = textedit->textDocument()->paragAt( paragId );
159 textedit->setCursor( parag, index );
163 m_doc->deleteInitialEditingInfo();
165 connect(frameViewManager(), TQ_SIGNAL(sigFrameResized(
const TQValueList<KWFrame*>&)),
166 m_doc, TQ_SLOT(framesChanged(
const TQValueList<KWFrame*>&)));
167 connect(frameViewManager(), TQ_SIGNAL(sigFrameMoved(
const TQValueList<KWFrame*>&)),
168 m_doc, TQ_SLOT(framesChanged(
const TQValueList<KWFrame*>&)));
173 delete m_interactionPolicy;
174 delete m_currentFrameSetEdit;
175 m_currentFrameSetEdit = 0;
178 disconnect(frameViewManager(), TQ_SIGNAL(sigFrameResized(
const TQValueList<KWFrame*>&)),
179 m_doc, TQ_SLOT(framesChanged(
const TQValueList<KWFrame*>&)));
180 disconnect(frameViewManager(), TQ_SIGNAL(sigFrameMoved(
const TQValueList<KWFrame*>&)),
181 m_doc, TQ_SLOT(framesChanged(
const TQValueList<KWFrame*>&)));
182 delete m_frameViewManager;
183 m_frameViewManager = 0;
190 TQPainter p( viewport() );
191 p.translate( -contentsX(), -contentsY() );
192 p.setBrushOrigin( -contentsX(), -contentsY() );
193 TQRect crect( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
194 drawFrameSet( fs, &p, crect,
true, resetChanged, m_viewMode );
197 if ( m_doc->showGrid() )
198 drawGrid( p, crect );
201void KWCanvas::repaintAll(
bool erase )
204 viewport()->repaint( erase );
209 viewport()->update();
212void KWCanvas::print( TQPainter *painter, KPrinter *printer )
215 if ( m_currentFrameSetEdit )
216 m_currentFrameSetEdit->focusOutEvent();
220 TQValueList<int> pageList = printer->pageList();
221 TQProgressDialog progress( i18n(
"Printing..." ), i18n(
"Cancel" ),
222 pageList.count() + 1,
this );
224 progress.setProgress( 0 );
225 TQValueList<int>::Iterator it = pageList.begin();
226 for ( ; it != pageList.end(); ++it )
228 progress.setProgress( ++j );
229 tqApp->processEvents();
231 if ( progress.wasCancelled() )
234 if ( it != pageList.begin() )
239 int yOffset = m_doc->zoomItY( m_doc->pageManager()->
topOfPage( pgNum ) );
240 kdDebug(32001) <<
"printing page " << pgNum <<
" yOffset=" << yOffset << endl;
241 TQRect pageRect = m_doc->pageManager()->
page(pgNum)->
zoomedRect(m_doc);
242 painter->fillRect( pageRect, white );
244 painter->translate( 0, -yOffset );
245 painter->setBrushOrigin( 0, -yOffset );
247 tqApp->processEvents();
250 if ( m_currentFrameSetEdit )
251 m_currentFrameSetEdit->focusInEvent();
258 if ( isUpdatesEnabled() )
261 painter->setBrushOrigin( -contentsX(), -contentsY() );
262 drawDocument( painter, TQRect( cx, cy, cw, ch ), m_viewMode );
263 if ( m_doc->showGrid() )
264 drawGrid( *painter, TQRect( cx, cy, cw, ch ) );
265 else if ( m_doc->snapToGrid() && ( m_interactionPolicy && m_interactionPolicy->gotDragEvents()
266 || m_mouseMode != MM_EDIT ) )
267 drawGrid( *painter, TQRect(contentsX(), contentsY(), visibleWidth(), visibleHeight()) );
277 if ( painter->device()->devType() != TQInternal::Printer )
279 TQRegion emptySpaceRegion( crect );
280 m_doc->createEmptyRegion( crect, emptySpaceRegion, viewMode );
281 viewMode->drawPageBorders( painter, crect, emptySpaceRegion );
285 TQPtrListIterator<KWFrameSet> fit = m_doc->framesetsIterator();
286 for ( ; fit.current() ; ++fit )
290 drawFrameSet( frameset, painter, crect,
false,
true, viewMode );
293 m_doc->maybeDeleteDoubleBufferPixmap();
296void KWCanvas::drawFrameSet(
KWFrameSet * frameset, TQPainter * painter,
297 const TQRect & crect,
bool onlyChanged,
bool resetChanged,
KWViewMode* viewMode )
304 bool focus = hasFocus() || viewport()->hasFocus();
305 if ( painter->device()->devType() == TQInternal::Printer )
308 TQColorGroup gb = TQApplication::palette().active();
309 if ( focus && m_currentFrameSetEdit && frameset == m_currentFrameSetEdit->frameSet() )
311 m_currentFrameSetEdit->
drawContents( painter, crect, gb, onlyChanged, resetChanged, viewMode, m_frameViewManager );
313 frameset->
drawContents( painter, crect, gb, onlyChanged, resetChanged, 0L, viewMode, m_frameViewManager );
316void KWCanvas::keyPressEvent( TQKeyEvent *e )
318 if( !m_doc->isReadWrite()) {
321 setContentsPos( contentsX(), contentsY() + 10 );
324 setContentsPos( contentsX(), contentsY() - 10 );
327 setContentsPos( contentsX() - 10, contentsY() );
330 setContentsPos( contentsX() + 10, contentsY() );
332 case TQt::Key_PageUp:
333 setContentsPos( contentsX(), contentsY() - visibleHeight() );
335 case TQt::Key_PageDown:
336 setContentsPos( contentsX(), contentsY() + visibleHeight() );
339 setContentsPos( contentsX(), 0 );
342 setContentsPos( contentsX(), contentsHeight() - visibleHeight() );
352void KWCanvas::switchViewMode(
const TQString& newViewMode )
355 m_viewMode = KWViewMode::create( newViewMode, m_doc,
this );
358void KWCanvas::mpCreate(
const TQPoint& normalPoint,
bool noGrid )
360 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
361 if ( m_doc->snapToGrid() && !noGrid )
362 applyGrid( docPoint );
363 m_insRect.setCoords( docPoint.x(), docPoint.y(), 0, 0 );
364 m_deleteMovingRect =
false;
367void KWCanvas::mpCreatePixmap(
const TQPoint& normalPoint,
bool noGrid )
369 if ( !m_kopicture.isNull() )
372 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
373 if ( m_doc->snapToGrid() && ! noGrid )
374 applyGrid( docPoint );
375 int pageNum = m_doc->pageManager()->pageNumber( docPoint );
376 m_insRect.setRect( docPoint.x(), docPoint.y(), 0, 0 );
377 m_deleteMovingRect =
false;
379 if ( !m_pixmapSize.isEmpty() )
382 uint width = tqRound( (
double)m_pixmapSize.width() * m_doc->zoomedResolutionX() / POINT_TO_INCH( KoGlobal::dpiX() ) );
383 uint height = tqRound( (
double)m_pixmapSize.height() * m_doc->zoomedResolutionY() / POINT_TO_INCH( KoGlobal::dpiY() ) );
384 m_insRect.setWidth( m_doc->unzoomItX( width ) );
385 m_insRect.setHeight( m_doc->unzoomItY( height ) );
387 width = kMin( width, m_doc->paperWidth(pageNum) - normalPoint.x() - 5 );
388 height = kMin( height, m_doc->paperHeight(pageNum) - normalPoint.y() - 5 );
392 double ratio = ((double) m_pixmapSize.width()) / ((double) m_pixmapSize.height());
393 applyAspectRatio( ratio, m_insRect );
396 TQPoint nPoint( normalPoint.x() + m_doc->zoomItX( m_insRect.width() ),
397 normalPoint.y() + m_doc->zoomItY( m_insRect.height() ) );
398 TQPoint vPoint = m_viewMode->normalToView( nPoint );
399 vPoint = contentsToViewport( vPoint );
400 TQRect viewportRect( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
401 if ( viewportRect.contains( vPoint ) )
402 TQCursor::setPos( viewport()->mapToGlobal( vPoint ) );
404 emit docStructChanged(Pictures);
405 if ( !m_doc->showGrid() && m_doc->snapToGrid() )
406 repaintContents(
false );
410void KWCanvas::contentsMousePressEvent( TQMouseEvent *e )
412 TQPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
413 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
416 if ( e->button() == TQt::LeftButton )
418 m_mousePressed =
true;
422 if ( !m_doc->isReadWrite() && ( m_mouseMode != MM_EDIT || e->button() != TQt::LeftButton ) )
428 switch ( m_mouseMode ) {
431 if(! viewMode()->hasFrames() ) {
433 docPoint = KoPoint(TQMAX(0, docPoint.x()), TQMAX(0, docPoint.y()));
434 if ( m_currentFrameSetEdit )
435 m_currentFrameSetEdit->mousePressEvent( e, normalPoint, docPoint );
439 m_mouseMeaning = m_frameViewManager->mouseMeaning( docPoint, e->state());
442 switch ( m_mouseMeaning ) {
443 case MEANING_MOUSE_INSIDE:
444 case MEANING_MOUSE_OVER_LINK:
445 case MEANING_MOUSE_OVER_FOOTNOTE:
446 case MEANING_MOUSE_INSIDE_TEXT:
447 case MEANING_ACTIVATE_PART:
452 KWFrameView *view = m_frameViewManager->view( docPoint, KWFrameViewManager::frameOnTop );
453 if ( ! ( e->button() == TQt::RightButton && view && view->
selected() ) )
454 selectAllFrames(
false );
456 KWFrame * frame = view ? view->
frame() : 0L;
457 KWFrameSet * fs = frame ? frame->
frameSet() : 0L;
460 bool emitChanged =
false;
464 emitChanged = checkCurrentEdit( fs );
467 if ( m_currentFrameSetEdit )
468 m_currentFrameSetEdit->mousePressEvent( e, normalPoint, docPoint );
471 emit currentFrameSetEditChanged();
477 bool inlineCreated =
true;
478 if(m_frameInlineType == FT_TABLE)
479 inlineCreated = insertInlineTable();
480 else if(m_frameInlineType == FT_PICTURE)
481 inlineCreated = insertInlinePicture();
483 KMessageBox::information(0L, i18n(
"Read-only content cannot be changed. No modifications will be accepted."));
487 case MEANING_RESIZE_COLUMN:
488 case MEANING_RESIZE_ROW:
490 terminateCurrentEdit();
495 KWFrameView *view = m_frameViewManager->view(docPoint, KWFrameViewManager::frameOnTop);
498 KWTableFrameSet::Cell* cell =
dynamic_cast<KWTableFrameSet::Cell *
>(view->
frame()->frameSet());
502 if ( m_mouseMeaning == MEANING_RESIZE_COLUMN )
505 m_previousTableSize = table->columnSize( m_rowColResized );
509 m_rowColResized = table->
rowEdgeAt( docPoint.y() );
510 m_previousTableSize = table->rowSize( m_rowColResized );
512 m_currentTable = table;
513 kdDebug(32002) <<
"resizing row/col edge. m_rowColResized=" << m_rowColResized << endl;
519 m_mousePressed =
true;
520 m_deleteMovingRect =
false;
522 delete m_interactionPolicy;
524 if(m_interactionPolicy)
525 terminateCurrentEdit();
526 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, e->state() ) );
530 case MM_CREATE_TEXT:
case MM_CREATE_PART:
case MM_CREATE_TABLE:
531 case MM_CREATE_FORMULA:
532 if ( e->button() == TQt::LeftButton )
533 mpCreate( normalPoint, e->state() & TQt::ShiftButton);
536 if ( e->button() == TQt::LeftButton )
537 mpCreatePixmap( normalPoint, e->state() & TQt::ShiftButton );
541 m_scrollTimer->start( 50 );
543 if ( e->button() == TQt::MidButton ) {
544 if ( m_doc->isReadWrite() && m_currentFrameSetEdit && m_mouseMode == MM_EDIT )
546 TQApplication::clipboard()->setSelectionMode(
true );
547 m_currentFrameSetEdit->paste();
548 TQApplication::clipboard()->setSelectionMode(
false );
551 else if ( e->button() == TQt::RightButton ) {
552 if(!m_doc->isReadWrite())
554 if ( m_deleteMovingRect )
557 switch ( m_mouseMode )
560 if ( !viewMode()->hasFrames() ) {
561 KWFrameView *view = m_frameViewManager->view(m_doc->frameSet( 0 )->frame(0));
562 view->
showPopup(docPoint, m_gui->getView(), TQCursor::pos());
565 m_frameViewManager->showPopup(docPoint, m_gui->getView(), e->state(), TQCursor::pos());
569 case MM_CREATE_TABLE:
570 case MM_CREATE_FORMULA:
572 setMouseMode( MM_EDIT );
575 m_mousePressed =
false;
580void KWCanvas::createTable(
unsigned int rows,
unsigned int cols,
583 KWTableTemplate *tt,
int format )
589 m_table.height = hei;
590 m_table.floating = isFloating;
591 m_table.format = format;
593 m_table.tableTemplateName = tt ? tt->displayName():TQString();
599 m_frameInlineType=FT_TABLE;
600 m_gui->getView()->displayFrameInlineInfo();
605 setMouseMode( MM_CREATE_TABLE );
609bool KWCanvas::insertInlinePicture()
611 bool inserted = m_gui->getView()->insertInlinePicture();
613 m_frameInline =
false;
617bool KWCanvas::insertInlineTable()
619 KWTextFrameSetEdit * edit =
dynamic_cast<KWTextFrameSetEdit *
>(m_currentFrameSetEdit);
622 if ( edit->textFrameSet()->
textObject()->protectContent() )
624 m_insRect = KoRect( 0, 0, edit->frameSet()->
frame(0)->width(), 10 );
626 KWTableFrameSet * table = createTable();
627 m_doc->addFrameSet( table,
false );
628 edit->insertFloatingFrameSet( table, i18n(
"Insert Inline Table") );
632 KWTableTemplateCommand *ttCmd=
new KWTableTemplateCommand(
"Apply template to inline table", table, m_table.tt );
633 m_doc->addCommand(ttCmd);
637 m_doc->updateAllFrames();
638 m_doc->refreshDocStructure(Tables);
640 m_gui->getView()->updateFrameStatusBarItem();
641 m_frameInline =
false;
645void KWCanvas::applyGrid( KoPoint &p )
647 if ( m_viewMode->type() !=
"ModeNormal" )
654 p.setX(
static_cast<int>( p.x() / m_doc->gridX() + 1e-10 ) * m_doc->gridX() );
655 p.setY(
static_cast<int>( p.y() / m_doc->gridY() + 1e-10 ) * m_doc->gridY() );
660void KWCanvas::drawGrid( TQPainter &p,
const TQRect& rect )
663 if ( !m_viewMode->hasFrames() )
665 TQPen pen = TQPen( TQt::black, 6, TQt::DotLine );
666 TQPen oldPen = p.pen();
669 const double offsetX = m_doc->gridX();
670 const double offsetY = m_doc->gridY();
674 for (
int pgNum = m_doc->startPage() ; pgNum <= m_doc->lastPage() ; ++pgNum) {
675 const TQRect pageRect = m_viewMode->viewPageRect( pgNum );
676 const TQRect crect = pageRect & rect;
677 if ( crect.isEmpty() )
682 KoPoint pageTopLeft (0, m_doc->pageManager()->topOfPage(pgNum) + 2);
683 TQPoint pageTopLeftView = m_viewMode->normalToView( m_doc->zoomPoint(pageTopLeft) );
686 const KoRect docRect = m_doc->unzoomRect( m_viewMode->viewToNormal( crect ) );
690 const double firstOffsetY = pageTopLeft.y() - offsetY *
static_cast<int>( docRect.y() / offsetY );
691 const double bottom = docRect.bottom() - pageTopLeft.y();
693 for (
double x = 0; x <= docRect.right(); x += offsetX ) {
694 const int zoomedX = m_doc->zoomItX( x ) + pageTopLeftView.x();
695 for (
double y = firstOffsetY; y <= bottom; y += offsetY ) {
696 const int zoomedY = m_doc->zoomItY( y ) + pageTopLeftView.y();
697 p.drawPoint( zoomedX, zoomedY );
705void KWCanvas::applyAspectRatio(
double ratio, KoRect& insRect )
707 double width = insRect.width();
708 double height = insRect.height();
709 if ( width < height )
710 width = height * ratio;
712 height = width / ratio;
713 insRect.setRight( insRect.left() + width );
714 insRect.setBottom( insRect.top() + height );
718void KWCanvas::mmCreate(
const TQPoint& normalPoint,
bool noGrid )
721 p.begin( viewport() );
722 p.translate( -contentsX(), -contentsY() );
723 p.setRasterOp( NotROP );
725 p.setBrush( NoBrush );
727 if ( m_deleteMovingRect )
730 int page = m_doc->pageManager()->pageNumber( m_insRect );
734 KoRect oldRect = m_insRect;
737 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
738 if ( m_doc->snapToGrid() && m_mouseMode != MM_CREATE_PIX && !noGrid )
739 applyGrid( docPoint );
741 m_insRect.setRight( docPoint.x() );
742 m_insRect.setBottom( docPoint.y() );
745 KoRect r = m_insRect.normalize();
746 if ( !m_doc->pageManager()->page(page)->rect().contains(r) )
755 if ( m_mouseMode == MM_CREATE_PIX && m_keepRatio )
757 double ratio = (double)m_pixmapSize.width() / (double)m_pixmapSize.height();
758 applyAspectRatio( ratio, m_insRect );
763 m_deleteMovingRect =
true;
766void KWCanvas::drawMovingRect( TQPainter & p )
769 p.drawRect( m_viewMode->normalToView( m_doc->zoomRect( m_insRect ) ) );
772void KWCanvas::deleteMovingRect()
774 Q_ASSERT( m_deleteMovingRect );
776 p.begin( viewport() );
777 p.translate( -contentsX(), -contentsY() );
778 p.setRasterOp( NotROP );
780 p.setBrush( NoBrush );
782 m_deleteMovingRect =
false;
786void KWCanvas::contentsMouseMoveEvent( TQMouseEvent *e )
790 TQPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
791 if(normalPoint.x() == -1)
793 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
795 if ( m_mousePressed ) {
798 switch ( m_mouseMode ) {
801 if ( m_currentFrameSetEdit )
802 m_currentFrameSetEdit->mouseMoveEvent( e, normalPoint, docPoint );
803 if( ! m_doc->isReadWrite() )
805 if ( m_mouseMeaning == MEANING_RESIZE_COLUMN || m_mouseMeaning == MEANING_RESIZE_ROW )
808 TQRect oldRect( m_viewMode->normalToView( m_doc->zoomRect( m_currentTable->boundingRect() ) ) );
809 if ( m_mouseMeaning == MEANING_RESIZE_ROW )
810 m_currentTable->resizeRow( m_rowColResized, docPoint.y() );
812 m_currentTable->resizeColumn( m_rowColResized, docPoint.x() );
814 TQRect newRect( m_viewMode->normalToView( m_doc->zoomRect( m_currentTable->boundingRect() ) ) );
815 repaintContents( TQRegion(oldRect).unite(newRect).boundingRect(),
false );
817 else if (m_interactionPolicy) {
818 m_interactionPolicy->handleMouseMove(e->state(),
819 m_doc->unzoomPoint( normalPoint ));
820 m_interactionPolicy->hadDragEvents();
823 case MM_CREATE_TEXT:
case MM_CREATE_PIX:
case MM_CREATE_PART:
824 case MM_CREATE_TABLE:
case MM_CREATE_FORMULA:
825 mmCreate( normalPoint, e->state() & ShiftButton );
831 if ( m_mouseMode == MM_EDIT )
833 MouseMeaning meaning = m_frameViewManager->mouseMeaning( docPoint, e->state() );
835 case MEANING_MOUSE_OVER_FOOTNOTE:
837 KWFrameView *view = m_frameViewManager->view(docPoint, KWFrameViewManager::frameOnTop);
838 KWFrame* frame = view ? view->
frame() : 0;
839 KWFrameSet * fs = frame ? frame->
frameSet() : 0;
840 if (fs && fs->
type() == FT_TEXT)
842 KoVariable* var =
static_cast<KWTextFrameSet *
>(fs)->variableUnderMouse(docPoint);
845 KWFootNoteVariable * footNoteVar =
dynamic_cast<KWFootNoteVariable *
>( var );
849 gui()->getView()->setTemporaryStatusBarText( footNoteVar->
frameSet()->textDocument()->firstParag()->string()->toString() );
850 m_temporaryStatusBarTextShown =
true;
857 case MEANING_MOUSE_OVER_LINK:
859 KWFrameView *view = m_frameViewManager->view(docPoint, KWFrameViewManager::frameOnTop);
860 KWFrame* frame = view ? view->
frame() : 0;
861 KWFrameSet * fs = frame ? frame->
frameSet() : 0L;
862 if (fs && fs->
type() == FT_TEXT)
864 KWTextFrameSet *frameset =
static_cast<KWTextFrameSet *
>(fs);
866 TQString link = frameset->linkVariableUnderMouse(docPoint)->url();
867 if ( link.startsWith(
"bkm://") )
868 link.replace( 0, 6, i18n(
"Bookmark target: ") );
869 gui()->getView()->setTemporaryStatusBarText( link );
870 m_temporaryStatusBarTextShown =
true;
878 if(viewMode()->hasFrames())
879 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, e->state() ) );
881 viewport()->setCursor( TQt::ibeamCursor );
886void KWCanvas::mrEditFrame() {
888 if(m_interactionPolicy) {
889 m_interactionPolicy->finishInteraction();
890 KCommand *cmd = m_interactionPolicy->createCommand();
892 m_doc->addCommand(cmd);
893 delete(m_interactionPolicy);
894 m_interactionPolicy = 0;
895 if ( !m_doc->showGrid() && m_doc->snapToGrid() )
898 m_mousePressed =
false;
901KCommand *KWCanvas::createTextBox(
const KoRect & rect )
903 if ( !m_doc->snapToGrid() || ( rect.width() > m_doc->gridX() && rect.height() > m_doc->gridY() ) ) {
904 KWFrame *frame =
new KWFrame(0L, rect.x(), rect.y(), rect.width(), rect.height() );
905 frame->setNewFrameBehavior(KWFrame::Reconnect);
908 TQString name = m_doc->generateFramesetName( i18n(
"Text Frameset %1" ) );
909 KWTextFrameSet *_frameSet =
new KWTextFrameSet(m_doc, name );
910 _frameSet->addFrame( frame );
911 m_doc->addFrameSet( _frameSet );
912 KWCreateFrameCommand *cmd=
new KWCreateFrameCommand( i18n(
"Create Text Frame"), frame );
913 if ( checkCurrentEdit(frame->
frameSet(),
true) )
914 emit currentFrameSetEditChanged();
920void KWCanvas::mrCreateText()
922 m_insRect = m_insRect.normalize();
923 if ( !m_doc->snapToGrid() || ( m_insRect.width() > m_doc->gridX() && m_insRect.height() > m_doc->gridY() ) ) {
924 KWFrame *frame =
new KWFrame(0L, m_insRect.x(), m_insRect.y(), m_insRect.width(), m_insRect.height() );
926 frame->setNewFrameBehavior(KWFrame::Reconnect);
928 KWFrameDia frameDia(
this, frame, m_doc, FT_TEXT );
929 frameDia.setCaption(i18n(
"Connect Frame"));
931 if ( checkCurrentEdit(frame->
frameSet(),
true) )
932 emit currentFrameSetEditChanged();
934 setMouseMode( MM_EDIT );
935 m_doc->repaintAllViews();
936 emit docStructChanged(TextFrames);
937 emit currentFrameSetEditChanged();
940void KWCanvas::mrCreatePixmap()
943 Q_ASSERT(m_insRect.width() > 0 && m_insRect.height() > 0);
945 double ratio = m_insRect.width() / m_insRect.height();
946 KoRect picRect(m_doc->pageManager()->clipToDocument(m_insRect.topLeft()),
947 m_doc->pageManager()->clipToDocument(m_insRect.bottomRight()) );
948 picRect = picRect.normalize();
951 KWPage *page = m_doc->pageManager()->page( picRect.bottom() );
952 KoRect pageRect = page->
rect();
953 picRect = pageRect.intersect(picRect);
956 double height = picRect.width() / ratio ;
957 if(picRect.height() > height)
958 picRect.setBottom(picRect.top() + height);
960 picRect.setRight(picRect.left() + ratio * picRect.height());
962 setMouseMode( MM_EDIT );
963 if ( !m_kopicture.isNull() ) {
964 KWPictureFrameSet *fs =
new KWPictureFrameSet( m_doc, TQString() );
965 fs->insertPicture( m_kopicture );
966 fs->setKeepAspectRatio( m_keepRatio );
967 KWFrame *frame =
new KWFrame(fs, picRect.x(), picRect.y(), picRect.width(),
970 fs->addFrame( frame,
false );
971 m_doc->addFrameSet( fs );
972 KWCreateFrameCommand *cmd=
new KWCreateFrameCommand( i18n(
"Insert Picture"), frame );
973 m_doc->addCommand(cmd);
974 m_doc->frameChanged( frame );
975 frameViewManager()->view(frame)->setSelected(
true);
977 emit docStructChanged(Pictures);
980void KWCanvas::mrCreatePart()
982 m_insRect = m_insRect.normalize();
983 if ( !m_doc->snapToGrid() || ( m_insRect.width() > m_doc->gridX() && m_insRect.height() > m_doc->gridY() ) ) {
984 KWPartFrameSet *fs = m_doc->insertObject( m_insRect, m_partEntry,
this );
985Q_ASSERT(viewMode()->canvas());
989 setMouseMode( MM_EDIT );
990 emit docStructChanged(Embedded);
993void KWCanvas::mrCreateFormula()
995 m_insRect = m_insRect.normalize();
996 if ( !m_doc->snapToGrid() || ( m_insRect.width() > m_doc->gridX() && m_insRect.height() > m_doc->gridY() ) ) {
997 KWFormulaFrameSet *frameset =
new KWFormulaFrameSet( m_doc, TQString() );
998 KWFrame *frame =
new KWFrame(frameset, m_insRect.x(), m_insRect.y(), m_insRect.width(), m_insRect.height() );
1000 frameset->addFrame( frame,
false );
1001 m_doc->addFrameSet( frameset );
1002 KWCreateFrameCommand *cmd=
new KWCreateFrameCommand( i18n(
"Create Formula Frame"), frame );
1003 m_doc->addCommand(cmd);
1004 m_doc->frameChanged( frame );
1006 setMouseMode( MM_EDIT );
1007 emit docStructChanged(FormulaFrames);
1010void KWCanvas::mrCreateTable()
1012 m_insRect = m_insRect.normalize();
1013 if ( !m_doc->snapToGrid() || ( m_insRect.width() > m_doc->gridX() && m_insRect.height() > m_doc->gridY() ) ) {
1014 if ( m_table.cols * s_minFrameWidth + m_insRect.x() > m_doc->pageManager()->pageLayout(0).ptWidth )
1016 KMessageBox::sorry(0, i18n(
"KWord is unable to insert the table because there "
1017 "is not enough space available."));
1020 KWTableFrameSet * table = createTable();
1021 KMacroCommand *macroCmd =
new KMacroCommand( i18n(
"Create Table") );
1023 KWCreateTableCommand *cmd=
new KWCreateTableCommand(
"Create table", table );
1024 macroCmd->addCommand(cmd);
1026 KWTableTemplateCommand *ttCmd=
new KWTableTemplateCommand(
"Apply template to table", table, m_table.tt );
1027 macroCmd->addCommand(ttCmd);
1029 m_doc->addCommand(macroCmd);
1030 macroCmd->execute();
1032 emit docStructChanged(Tables);
1034 m_doc->updateAllFrames();
1039 setMouseMode( MM_EDIT );
1044 KWTableFrameSet *table =
new KWTableFrameSet( m_doc, TQString() );
1045 int pageNum = m_doc->pageManager()->pageNumber(m_insRect.topLeft());
1048 for (
unsigned int i = 0; i < m_table.rows; i++ ) {
1049 for (
unsigned int j = 0; j < m_table.cols; j++ ) {
1050 KWTableFrameSet::Cell *cell =
new KWTableFrameSet::Cell( table, i, j, TQString() );
1051 KWFrame *frame =
new KWFrame(cell, 0, 0, 0, 0, KWFrame::RA_BOUNDINGRECT );
1052 frame->
setZOrder( m_doc->maxZOrder( pageNum ) + 1 );
1053 cell->addFrame( frame,
false );
1054 frame->setFrameBehavior(KWFrame::AutoExtendFrame);
1055 frame->setNewFrameBehavior(KWFrame::NoFollowup);
1058 KWTableFrameSet::CellSize w;
1059 w=
static_cast<KWTableFrameSet::CellSize
>( m_table.width );
1060 if(m_frameInline) w=KWTableFrameSet::TblManual;
1061 table->
setBoundingRect( m_insRect , w,
static_cast<KWTableFrameSet::CellSize
>( m_table.height ));
1065void KWCanvas::contentsMouseReleaseEvent( TQMouseEvent * e )
1069 if ( m_scrollTimer->isActive() )
1070 m_scrollTimer->stop();
1071 if ( m_mousePressed ) {
1072 if ( m_deleteMovingRect )
1075 TQPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
1076 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
1078 if(m_insRect.bottom()==0 && m_insRect.right()==0) {
1080 int page = m_doc->pageManager()->
pageNumber(docPoint);
1083 KoPageLayout pageLayout = m_doc->pageManager()->pageLayout(page);
1084 m_insRect.setLeft(TQMIN(m_insRect.left(), pageLayout.ptWidth - 200));
1085 m_insRect.setTop(TQMIN(m_insRect.top(), pageLayout.ptHeight - 150));
1086 m_insRect.setBottom(m_insRect.top()+150);
1087 m_insRect.setRight(m_insRect.left()+200);
1089 MouseMode old_mouseMove = m_mouseMode;
1090 switch ( m_mouseMode ) {
1092 if ( m_currentFrameSetEdit )
1093 m_currentFrameSetEdit->mouseReleaseEvent( e, normalPoint, docPoint );
1095 if ( m_mouseMeaning == MEANING_RESIZE_COLUMN )
1097 KWResizeColumnCommand *cmd =
new KWResizeColumnCommand( m_currentTable, m_rowColResized, m_previousTableSize, docPoint.x() );
1098 m_doc->addCommand(cmd);
1101 else if ( m_mouseMeaning == MEANING_RESIZE_ROW )
1103 KWResizeRowCommand *cmd =
new KWResizeRowCommand( m_currentTable, m_rowColResized, m_previousTableSize, docPoint.y() );
1104 m_doc->addCommand(cmd);
1109 m_mouseMeaning = MEANING_NONE;
1112 case MM_CREATE_TEXT:
1118 case MM_CREATE_PART:
1121 case MM_CREATE_TABLE:
1124 case MM_CREATE_FORMULA:
1129 if ( old_mouseMove != MM_EDIT && !m_doc->showGrid() && m_doc->snapToGrid() )
1130 repaintContents(
false );
1131 m_mousePressed =
false;
1135void KWCanvas::contentsMouseDoubleClickEvent( TQMouseEvent * e )
1139 TQPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
1140 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
1141 switch ( m_mouseMode ) {
1143 if ( m_currentFrameSetEdit )
1145 m_mousePressed =
true;
1146 m_scrollTimer->start( 50 );
1147 m_currentFrameSetEdit->mouseDoubleClickEvent( e, normalPoint, docPoint );
1153 KWFrameView *view = m_frameViewManager->selectedFrame();
1154 bool isPartFrameSet = view &&
dynamic_cast<KWPartFrameSet*
>(view->
frame()->frameSet());
1155 if ( !isPartFrameSet )
1156 editFrameProperties();
1158 m_mousePressed =
false;
1166void KWCanvas::setFrameBackgroundColor(
const TQBrush &_backColor )
1168 TQValueList<KWFrameView*> selectedFrames = m_frameViewManager->selectedFrames();
1169 if (selectedFrames.isEmpty())
1171 bool colorChanged=
false;
1172 TQPtrList<FrameIndex> frameindexList;
1173 TQPtrList<TQBrush> oldColor;
1175 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
1176 while(framesIterator != selectedFrames.end()) {
1178 FrameIndex *index=
new FrameIndex( frame );
1179 frameindexList.append(index);
1181 TQBrush *_color=
new TQBrush(frame->backgroundColor());
1182 oldColor.append(_color);
1187 frame->setBackgroundColor(_backColor);
1193 KWFrameBackGroundColorCommand *cmd=
new KWFrameBackGroundColorCommand(i18n(
"Change Frame Background Color"),frameindexList,oldColor,_backColor);
1194 m_doc->addCommand(cmd);
1195 m_doc->repaintAllViews();
1199 frameindexList.setAutoDelete(
true);
1200 oldColor.setAutoDelete(
true);
1204void KWCanvas::editFrameProperties(
KWFrameSet * frameset )
1206 KWFrameDia *frameDia;
1207 KWFrame *frame = frameset->
frame(0);
1208 frameDia =
new KWFrameDia(
this, frame );
1213void KWCanvas::editFrameProperties()
1215 TQValueList<KWFrameView*> selectedFrames = m_frameViewManager->selectedFrames();
1216 if(selectedFrames.count()==0)
return;
1218 KWFrameDia *frameDia;
1219 if(selectedFrames.count()==1)
1220 frameDia =
new KWFrameDia(
this, selectedFrames[0]->frame());
1222 TQPtrList<KWFrame> frames;
1223 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
1224 for(;framesIterator != selectedFrames.end(); ++framesIterator)
1225 frames.append( (*framesIterator)->frame() );
1226 frameDia =
new KWFrameDia(
this, frames );
1232void KWCanvas::selectAllFrames(
bool select ) {
1233 TQValueList<KWFrameView*> frameViews = m_frameViewManager->frameViewsIterator();
1234 TQValueList<KWFrameView*>::iterator frames = frameViews.begin();
1235 for(; frames != frameViews.end(); ++frames ) {
1238 if ( select && fs->isMainFrameset() )
1240 (*frames)->setSelected(select);
1246 terminateCurrentEdit();
1247 m_frameViewManager->view(cell->
frame(0))->setSelected(
true);
1248 m_currentTable = table;
1251void KWCanvas::editFrameSet(
KWFrameSet * frameSet,
bool onlyText )
1253 selectAllFrames(
false );
1254 bool emitChanged = checkCurrentEdit( frameSet, onlyText );
1257 emit currentFrameSetEditChanged();
1263 selectAllFrames(
false );
1268 if ( fs->isAHeader() && !m_doc->isHeaderVisible() && !(viewMode()->type()==
"ModeText"))
1269 m_doc->setHeaderVisible(
true );
1270 if ( fs->isAFooter() && !m_doc->isFooterVisible() && !(viewMode()->type()==
"ModeText"))
1271 m_doc->setFooterVisible(
true );
1276 setMouseMode( MM_EDIT );
1277 bool emitChanged = checkCurrentEdit( fs );
1279 if ( m_currentFrameSetEdit && m_currentFrameSetEdit->frameSet()->type()==FT_TEXT ) {
1283 parag = tmp->firstParag();
1288 textedit->hideCursor();
1289 textedit->setCursor( parag, index );
1290 textedit->showCursor();
1291 textedit->ensureCursorVisible();
1295 emit currentFrameSetEditChanged();
1299void KWCanvas::ensureCursorVisible()
1301 Q_ASSERT( m_currentFrameSetEdit );
1304 textedit->ensureCursorVisible();
1307bool KWCanvas::checkCurrentEdit(
KWFrameSet * fs ,
bool onlyText )
1309 bool emitChanged =
false;
1310 if ( fs && m_currentFrameSetEdit && m_currentFrameSetEdit->frameSet() != fs )
1312 KWTextFrameSet * tmp =
dynamic_cast<KWTextFrameSet *
>(fs );
1313 if ( tmp && tmp->protectContent() && !m_doc->cursorInProtectedArea() )
1316 KWTextFrameSetEdit *edit = currentTextEdit();
1317 if(edit && onlyText)
1321 m_currentFrameSetEdit->terminate(
false);
1324 m_currentFrameSetEdit->terminate();
1325 delete m_currentFrameSetEdit;
1326 m_currentFrameSetEdit = 0L;
1332 if ( fs && !m_currentFrameSetEdit )
1334 KWTextFrameSet * tmp =
dynamic_cast<KWTextFrameSet *
>(fs );
1335 if ( tmp && tmp->protectContent() && !m_doc->cursorInProtectedArea() )
1338 if(fs->
type()==FT_TABLE || fs->
type()==FT_TEXT || !onlyText)
1340 if ( fs->
type() == FT_TABLE )
1341 m_currentTable =
static_cast<KWTableFrameSet *
>(fs);
1342 else if ( fs->
type() == FT_TEXT )
1343 m_currentTable =
static_cast<KWTextFrameSet *
>(fs)->groupmanager();
1345 m_currentTable = 0L;
1346 if ( m_currentTable ) {
1347 m_currentFrameSetEdit = m_currentTable->createFrameSetEdit(
this );
1348 static_cast<KWTableFrameSetEdit *
>( m_currentFrameSetEdit )->setCurrentCell( fs );
1353 if ( m_currentFrameSetEdit ) {
1354 KWTextFrameSetEdit *edit = currentTextEdit();
1356 edit->setOverwriteMode( m_overwriteMode );
1364void KWCanvas::terminateCurrentEdit()
1366 if(m_currentFrameSetEdit == 0)
1369 m_currentFrameSetEdit->terminate();
1370 delete m_currentFrameSetEdit;
1371 m_currentFrameSetEdit = 0L;
1372 emit currentFrameSetEditChanged();
1376void KWCanvas::terminateEditing(
KWFrameSet *fs )
1378 if ( m_currentFrameSetEdit && m_currentFrameSetEdit->frameSet() == fs )
1379 terminateCurrentEdit();
1382 for ( ; frameIt.current(); ++frameIt ) {
1383 KWFrameView* view = m_frameViewManager->view(frameIt.current());
1391 if ( m_currentFrameSetEdit )
1392 return dynamic_cast<KWTextFrameSetEdit *
>(m_currentFrameSetEdit->currentTextEdit());
1396void KWCanvas::setMouseMode( MouseMode newMouseMode )
1398 if ( m_mouseMode != newMouseMode )
1400 selectAllFrames(
false );
1402 if ( newMouseMode != MM_EDIT )
1403 terminateCurrentEdit();
1405 m_mouseMode = newMouseMode;
1406 if ( !m_doc->showGrid() && m_doc->snapToGrid() )
1407 repaintContents(
false );
1410 m_mouseMode = newMouseMode;
1411 emit currentMouseModeChanged(m_mouseMode);
1413 switch ( m_mouseMode ) {
1415 TQPoint mousep = mapFromGlobal(TQCursor::pos()) + TQPoint( contentsX(), contentsY() );
1416 TQPoint normalPoint = m_viewMode->viewToNormal( mousep );
1417 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
1418 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, 0 ) );
1419 m_frameInline =
false;
1421 case MM_CREATE_TEXT:
1423 case MM_CREATE_TABLE:
1424 case MM_CREATE_FORMULA:
1425 case MM_CREATE_PART:
1426 viewport()->setCursor( crossCursor );
1431void KWCanvas::insertPicture(
const KoPicture& newPicture, TQSize pixmapSize,
bool _keepRatio )
1433 setMouseMode( MM_CREATE_PIX );
1434 m_kopicture = newPicture;
1435 m_pixmapSize = pixmapSize;
1436 if ( pixmapSize.isEmpty() )
1437 m_pixmapSize = newPicture.getOriginalSize();
1438 m_keepRatio = _keepRatio;
1441void KWCanvas::insertPictureDirect(
const KoPicture& picture,
const KoPoint& pos,
const TQSize& sz )
1444 m_pixmapSize = sz.isEmpty() ? picture.getOriginalSize() : sz;
1445 m_kopicture = picture;
1446 m_insRect = KoRect( pos.x(), pos.y(), m_doc->unzoomItX( m_pixmapSize.width() ), m_doc->unzoomItY( m_pixmapSize.height() ) );
1451void KWCanvas::insertPart(
const KoDocumentEntry &entry )
1453 m_partEntry = entry;
1454 if ( m_partEntry.isEmpty() )
1456 setMouseMode( MM_EDIT );
1459 setMouseMode( MM_CREATE_PART );
1462void KWCanvas::contentsDragEnterEvent( TQDragEnterEvent *e )
1464 int provides = KWView::checkClipboard( e );
1465 if ( ( provides & KWView::ProvidesImage ) || KURLDrag::canDecode( e ) )
1472 m_imageDrag =
false;
1473 if ( m_currentFrameSetEdit )
1474 m_currentFrameSetEdit->dragEnterEvent( e );
1478void KWCanvas::contentsDragMoveEvent( TQDragMoveEvent *e )
1482 TQPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
1483 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
1484 KWFrameView *view = m_frameViewManager->view(docPoint, KWFrameViewManager::frameOnTop);
1485 KWFrame *frame = view ? view->
frame() : 0;
1486 KWFrameSet * fs = frame ? frame->
frameSet() : 0L;
1487 bool emitChanged =
false;
1491 emitChanged = checkCurrentEdit( fs,
true );
1493 if ( m_currentFrameSetEdit )
1495 m_currentFrameSetEdit->dragMoveEvent( e, normalPoint, docPoint );
1498 emit currentFrameSetEditChanged();
1503void KWCanvas::contentsDragLeaveEvent( TQDragLeaveEvent *e )
1505 if ( !m_imageDrag && m_currentFrameSetEdit )
1506 m_currentFrameSetEdit->dragLeaveEvent( e );
1509void KWCanvas::contentsDropEvent( TQDropEvent *e )
1511 TQPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
1512 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
1514 if ( TQImageDrag::canDecode( e ) ) {
1515 pasteImage( e, docPoint );
1516 }
else if ( KURLDrag::canDecode( e ) ) {
1522 KURLDrag::decode( e, lst );
1524 KURL::List::ConstIterator it = lst.begin();
1525 for ( ; it != lst.end(); ++it ) {
1526 const KURL &url( *it );
1529 if ( !TDEIO::NetAccess::download( url, filename,
this ) )
1532 KMimeType::Ptr res = KMimeType::findByFileContent( filename );
1534 if ( res && res->isValid() ) {
1535 TQString mimetype = res->name();
1536 if ( mimetype.contains(
"image" ) ) {
1538 key.setKeyFromFile( filename );
1539 KoPicture newKoPicture;
1540 newKoPicture.setKey( key );
1541 newKoPicture.loadFromFile( filename );
1542 insertPictureDirect( newKoPicture, docPoint );
1545 TDEIO::NetAccess::removeTempFile( filename );
1550 if ( m_currentFrameSetEdit )
1551 m_currentFrameSetEdit->dropEvent( e, normalPoint, docPoint, m_gui->getView() );
1553 m_gui->getView()->pasteData( e,
true );
1555 m_mousePressed =
false;
1556 m_imageDrag =
false;
1559void KWCanvas::pasteImage( TQMimeSource *e,
const KoPoint &docPoint )
1562 if ( !TQImageDrag::decode(e, i) ) {
1563 kdWarning() <<
"Couldn't decode image" << endl;
1566 KTempFile tmpFile( TQString(),
".png");
1567 tmpFile.setAutoDelete(
true );
1568 if ( !i.save(tmpFile.name(),
"PNG") ) {
1569 kdWarning() <<
"Couldn't save image to " << tmpFile.name() << endl;
1572 m_pixmapSize = i.size();
1575 key.setKeyFromFile( tmpFile.name() );
1576 KoPicture newKoPicture;
1577 newKoPicture.setKey( key );
1578 newKoPicture.loadFromFile( tmpFile.name() );
1579 m_kopicture = newKoPicture;
1580 m_insRect = KoRect( docPoint.x(), docPoint.y(), m_doc->unzoomItX( i.width() ), m_doc->unzoomItY( i.height() ) );
1585void KWCanvas::doAutoScroll()
1587 if ( !m_mousePressed )
1589 m_scrollTimer->stop();
1594 TQPoint pos( mapFromGlobal( TQCursor::pos() ) );
1596 pos = TQPoint(pos.x() - viewport()->x(), pos.y() - viewport()->y());
1597 if ( (pos.y() < 0) || (pos.y() > visibleHeight()) ||
1598 (pos.x() < 0) || (pos.x() > visibleWidth()) )
1601 viewportToContents(pos.x(), pos.y(), xm, ym);
1602 if ( m_currentFrameSetEdit )
1603 m_currentFrameSetEdit->focusOutEvent();
1604 if ( m_deleteMovingRect )
1606 ensureVisible( xm, ym, 0, 5 );
1607 if ( m_currentFrameSetEdit )
1608 m_currentFrameSetEdit->focusInEvent();
1612void KWCanvas::slotContentsMoving(
int cx,
int cy )
1615 TQPoint nPointBottom = m_viewMode->viewToNormal( TQPoint( cx + visibleWidth(), cy + visibleHeight() ) );
1619 TQPtrList<KWTextFrameSet> textFrameSets = m_doc->allTextFramesets(
false );
1620 TQPtrListIterator<KWTextFrameSet> fit( textFrameSets );
1621 for ( ; fit.current() ; ++fit )
1623 if(! fit.current()->isVisible())
continue;
1624 fit.current()->updateViewArea(
this, m_viewMode, nPointBottom );
1628 updateRulerOffsets( cx, cy );
1634 TQTimer::singleShot( 0,
this, TQ_SIGNAL( viewTransformationsChanged() ) );
1637void KWCanvas::slotMainTextHeightChanged()
1640 if (
dynamic_cast<KWViewModeText *
>(m_viewMode) && m_gui->getHorzRuler() )
1642 slotNewContentsSize();
1643 m_viewMode->setPageLayout( m_gui->getHorzRuler(), m_gui->getVertRuler(), KoPageLayout() );
1648void KWCanvas::slotNewContentsSize()
1650 TQSize size = m_viewMode->contentsSize();
1651 if ( size != TQSize( contentsWidth(), contentsHeight() ) )
1654 resizeContents( size.width(), size.height() );
1658void KWCanvas::resizeEvent( TQResizeEvent *e )
1660 slotContentsMoving( contentsX(), contentsY() );
1661 TQScrollView::resizeEvent( e );
1664void KWCanvas::scrollToOffset(
const KoPoint & d )
1666 kdDebug() <<
"KWCanvas::scrollToOffset " << d.x() <<
"," << d.y() << endl;
1668 bool blinking = blinkTimer.isActive();
1672 TQPoint nPoint = m_doc->zoomPoint( d );
1673 TQPoint cPoint = m_viewMode->normalToView( nPoint );
1674 setContentsPos( cPoint.x(), cPoint.y() );
1682void KWCanvas::updateRulerOffsets(
int cx,
int cy )
1684 if ( cx == -1 && cy == -1 )
1691 TQPoint pc = m_viewMode->pageCorner();
1693 if (m_gui->getHorzRuler())
1694 m_gui->getHorzRuler()->setOffset( cx - pc.x(), 0 );
1695 if (m_gui->getVertRuler())
1696 m_gui->getVertRuler()->setOffset( 0, cy - pc.y() );
1700bool KWCanvas::eventFilter( TQObject *o, TQEvent *e )
1702 if ( o ==
this || o == viewport() ) {
1704 if(m_currentFrameSetEdit && o ==
this )
1707 KCursor::autoHideEventFilter( o, e );
1710 switch ( e->type() ) {
1711 case TQEvent::FocusIn:
1713 if ( m_currentFrameSetEdit && !m_printing )
1714 m_currentFrameSetEdit->focusInEvent();
1716 case TQEvent::FocusOut:
1718 if ( m_currentFrameSetEdit && !m_printing )
1719 m_currentFrameSetEdit->focusOutEvent();
1720 if ( m_scrollTimer->isActive() )
1721 m_scrollTimer->stop();
1722 m_mousePressed =
false;
1724 case TQEvent::AccelOverride:
1728 TQKeyEvent * keyev =
static_cast<TQKeyEvent*
>(e);
1731 if ( ( keyev->state() & ControlButton ) && ( keyev->state() & ShiftButton ) )
1733 switch ( keyev->key() ) {
1743 m_doc->printDebug();
1744 kdDebug(32002) <<
"Current framesetedit: " << m_currentFrameSetEdit <<
" " <<
1745 ( m_currentFrameSetEdit ? m_currentFrameSetEdit->frameSet()->className() :
"" ) << endl;
1749 m_doc->printStyleDebug();
1754 const TQDateTime dtMark ( TQDateTime::currentDateTime() );
1755 kdDebug(32002) <<
"Developer mark: " << dtMark.toString(
"yyyy-MM-dd hh:mm:ss,zzz") << endl;
1767 case TQEvent::KeyPress:
1771 TQKeyEvent * keyev =
static_cast<TQKeyEvent*
>(e);
1773 if ( !m_doc->pgUpDownMovesCaret() && ( (keyev->state() & ShiftButton) == 0 )
1774 && ( keyev->key() == TQt::Key_PageUp || keyev->key() == Key_PageDown ) )
1776 viewportScroll( keyev->key() == TQt::Key_PageUp );
1782 else if ( keyev->key() == TDEGlobalSettings::contextMenuKey() ) {
1784 if(!m_doc->isReadWrite())
return true;
1785 if (m_mouseMode != MM_EDIT)
return true;
1786 KoPoint docPoint = m_doc->unzoomPoint( TQCursor::pos() );
1788 if ( viewMode()->type()==
"ModeText") {
1789 KWFrameView *view = m_frameViewManager->view(m_doc->frameSet( 0 )->frame(0));
1790 view->
showPopup(docPoint, m_gui->getView(), TQCursor::pos());
1793 m_frameViewManager->showPopup( docPoint, m_gui->getView(), keyev->state(), pos());
1797 else if ( keyev->key() == TQt::Key_Return && keyev->state() == 0
1798 && (m_mouseMode != MM_EDIT || m_frameInline )) {
1807 if (m_lastCaretPos.isNull())
return true;
1808 int page = m_doc->pageManager()->pageNumber(m_lastCaretPos);
1809 if(page == -1)
return true;
1810 TQPoint normalPoint = m_doc->zoomPoint(m_lastCaretPos);
1815 normalPoint += TQPoint(2,2);
1816 TQPoint vP = m_viewMode->normalToView(normalPoint);
1817 TQPoint gP = mapToGlobal(vP);
1818 TQMouseEvent mevPress(TQEvent::MouseButtonPress, vP,
1819 gP, TQt::LeftButton, 0);
1820 contentsMousePressEvent(&mevPress);
1821 TQMouseEvent mevRelease(TQEvent::MouseButtonRelease, vP,
1822 gP, TQt::LeftButton, 0);
1823 contentsMouseReleaseEvent(&mevRelease);
1825 else if ( keyev->key() == TQt::Key_Escape ) {
1826 if ( m_mouseMode != MM_EDIT )
1827 setMouseMode( MM_EDIT );
1828 else if(m_interactionPolicy) {
1829 m_interactionPolicy->cancelInteraction();
1830 delete(m_interactionPolicy);
1831 m_interactionPolicy = 0;
1832 m_mousePressed =
false;
1835 TQPoint mousep = mapFromGlobal(TQCursor::pos()) + TQPoint( contentsX(), contentsY() );
1836 TQPoint normalPoint = m_viewMode->viewToNormal( mousep );
1837 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
1838 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, keyev->stateAfter() ) );
1839 if ( !m_doc->showGrid() && m_doc->snapToGrid() )
1843 else if ( keyev->key() == Key_Insert && keyev->state() == 0 ) {
1844 m_overwriteMode = !m_overwriteMode;
1845 KWTextFrameSetEdit *edit = currentTextEdit();
1847 edit->setOverwriteMode( m_overwriteMode );
1848 emit overwriteModeChanged( m_overwriteMode );
1850 kdDebug()<<
"Insert is pressed, overwrite mode: "<< m_overwriteMode << endl;
1853 if ( m_currentFrameSetEdit && m_mouseMode == MM_EDIT && m_doc->isReadWrite() && !m_printing )
1855 KWTextFrameSetEdit *edit =
dynamic_cast<KWTextFrameSetEdit *
>(m_currentFrameSetEdit );
1858 if ( !edit->textFrameSet()->
textObject()->protectContent() || (keyev->text().length() == 0))
1859 m_currentFrameSetEdit->keyPressEvent( keyev );
1860 else if(keyev->text().length() > 0)
1861 KMessageBox::information(
this, i18n(
"Read-only content cannot be changed. No modifications will be accepted."));
1864 m_currentFrameSetEdit->keyPressEvent( keyev );
1869 if ( keyev->key() == TQt::Key_Control )
1871 TQPoint mousep = mapFromGlobal(TQCursor::pos()) + TQPoint( contentsX(), contentsY() );
1872 TQPoint normalPoint = m_viewMode->viewToNormal( mousep );
1873 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
1874 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, keyev->stateAfter() ) );
1876 else if ( (keyev->key() == TQt::Key_Delete || keyev->key() ==Key_Backspace )
1877 && m_frameViewManager->selectedFrame() && !m_printing )
1878 m_gui->getView()->editDeleteFrame();
1880 case TQEvent::KeyRelease:
1882 TQKeyEvent * keyev =
static_cast<TQKeyEvent*
>(e);
1883 if ( keyev->key() == TQt::Key_Control )
1885 TQPoint mousep = mapFromGlobal(TQCursor::pos()) + TQPoint( contentsX(), contentsY() );
1886 TQPoint normalPoint = m_viewMode->viewToNormal( mousep );
1887 KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
1888 viewport()->setCursor( m_frameViewManager->mouseCursor( docPoint, keyev->stateAfter() ) );
1891 if ( m_currentFrameSetEdit && m_mouseMode == MM_EDIT && m_doc->isReadWrite() && !m_printing )
1893 m_currentFrameSetEdit->keyReleaseEvent( keyev );
1898 case TQEvent::IMStart:
1900 TQIMEvent * imev =
static_cast<TQIMEvent *
>(e);
1901 m_currentFrameSetEdit->imStartEvent( imev );
1904 case TQEvent::IMCompose:
1906 TQIMEvent * imev =
static_cast<TQIMEvent *
>(e);
1907 m_currentFrameSetEdit->imComposeEvent( imev );
1910 case TQEvent::IMEnd:
1912 TQIMEvent * imev =
static_cast<TQIMEvent *
>(e);
1913 m_currentFrameSetEdit->imEndEvent( imev );
1920 return TQScrollView::eventFilter( o, e );
1923bool KWCanvas::focusNextPrevChild(
bool next)
1932void KWCanvas::updateCurrentFormat()
1934 KWTextFrameSetEdit * edit =
dynamic_cast<KWTextFrameSetEdit *
>(m_currentFrameSetEdit);
1936 edit->updateUI(
true,
true );
1940void KWCanvas::printRTDebug(
int info )
1942 KWTextFrameSet * textfs = 0L;
1943 if ( m_currentFrameSetEdit ) {
1944 KWTextFrameSetEdit* edit = currentTextEdit();
1946 textfs =
dynamic_cast<KWTextFrameSet *
>( edit->frameSet() );
1951 textfs =
dynamic_cast<KWTextFrameSet *
>(m_doc->frameSet( 0 ));
1957void KWCanvas::setXimPosition(
int x,
int y,
int w,
int h )
1964 TQWidget::setMicroFocusHint( x - contentsX(), y - contentsY(), w, h );
1967void KWCanvas::inlinePictureStarted()
1970 m_frameInlineType=FT_PICTURE;
1975 if ( !m_currentFrameSetEdit )
1988 if ( !m_currentFrameSetEdit )
1999void KWCanvas::viewportScroll(
bool up )
2002 setContentsPos( contentsX(), contentsY() - visibleHeight() );
2004 setContentsPos( contentsX(), contentsY() + visibleHeight() );
2009 if ( m_temporaryStatusBarTextShown )
2011 gui()->getView()->updateFrameStatusBarItem();
2012 m_temporaryStatusBarTextShown =
false;
2021 if (!m_currentFrameSetEdit)
return KoPoint();
2023 if (!textEdit)
return KoPoint();
2024 KoTextCursor* cursor = textEdit->cursor();
2025 if (!cursor)
return KoPoint();
2027 dynamic_cast<KWTextFrameSet *
>(m_currentFrameSetEdit->frameSet());
2028 if (!textFrameset)
return KoPoint();
2029 KWFrame* currentFrame = m_currentFrameSetEdit->currentFrame();
2030 if (!currentFrame)
return KoPoint();
2032 TQPoint viewP = textFrameset->cursorPos(cursor,
this, currentFrame);
2033 viewP.rx() += contentsX();
2034 viewP.ry() += contentsY();
2035 TQPoint normalP = m_viewMode->viewToNormal(viewP);
2036 KoPoint docP = m_doc->unzoomPoint(normalP);
2043 m_gotDragEvents =
false;
2046 TQValueList<KWFrameView*> selectedFrames = m_parent->frameViewManager()->selectedFrames();
2047 TQValueListIterator<KWFrameView*> framesIterator = selectedFrames.begin();
2048 for(;framesIterator != selectedFrames.end(); ++framesIterator) {
2049 KWFrame *frame = (*framesIterator)->frame();
2053 if(fs->isMainFrameset() )
continue;
2054 if(fs->
isFloating() && !includeInlineFrames)
continue;
2055 if(fs->isProtectSize() )
continue;
2056 if(fs->
type() == FT_TABLE )
continue;
2057 if(fs->
type() == FT_TEXT && fs->
frameSetInfo() != KWFrameSet::FI_BODY )
continue;
2058 m_frames.append( frame );
2065 if(buttonState & TQt::LeftButton || buttonState & TQt::RightButton) {
2069 Selector(
KWCanvas *canvas, KoPoint &point, TQt::ButtonState buttonState, TQt::ButtonState keyState) :
2070 m_canvas(canvas), m_point(point), m_state(keyState) {
2071 m_leftClick = buttonState & TQt::LeftButton;
2073 KWFrameViewManager::frameOnTop);
2074 m_doSomething = (view && !view->
selected());
2078 if(! m_doSomething)
return;
2079 m_canvas->frameViewManager()->selectFrames(m_point, m_state, m_leftClick);
2084 TQt::ButtonState m_state;
2085 bool m_leftClick, m_doSomething;
2088 Selector selector(parent, point, buttonState, keyState);
2090 case MEANING_MOUSE_MOVE:
2091 selector.doSelect();
2093 case MEANING_TOPLEFT:
2095 case MEANING_TOPRIGHT:
2097 case MEANING_BOTTOMRIGHT:
2098 case MEANING_BOTTOM:
2099 case MEANING_BOTTOMLEFT:
2101 selector.doSelect();
2123FrameResizePolicy::FrameResizePolicy(
KWCanvas *parent, MouseMeaning meaning, KoPoint &point) :
2126 if( meaning == MEANING_TOPLEFT) {
2127 m_top =
true; m_bottom =
false; m_left =
true; m_right =
false;
2129 else if( meaning == MEANING_TOP) {
2130 m_top =
true; m_bottom =
false; m_left =
false; m_right =
false;
2132 else if( meaning == MEANING_TOPRIGHT) {
2133 m_top =
true; m_bottom =
false; m_left =
false; m_right =
true;
2135 else if( meaning == MEANING_RIGHT) {
2136 m_top =
false; m_bottom =
false; m_left =
false; m_right =
true;
2138 else if( meaning == MEANING_BOTTOMRIGHT) {
2139 m_top =
false; m_bottom =
true; m_left =
false; m_right =
true;
2141 else if( meaning == MEANING_BOTTOM) {
2142 m_top =
false; m_bottom =
true; m_left =
false; m_right =
false;
2144 else if( meaning == MEANING_BOTTOMLEFT) {
2145 m_top =
false; m_bottom =
true; m_left =
true; m_right =
false;
2147 else if( meaning == MEANING_LEFT) {
2148 m_top =
false; m_bottom =
false; m_left =
true; m_right =
false;
2151 TQValueListConstIterator<KWFrame*> framesIterator = m_frames.begin();
2152 for(;framesIterator != m_frames.end(); ++framesIterator) {
2153 KWFrame *frame = *framesIterator;
2155 m_frameResize.append(frs);
2158 m_hotSpot = point - m_boundingRect.topLeft();
2166 bool keepAspect = keyState & TQt::AltButton;
2167 for(
unsigned int i=0; !keepAspect && i < m_frames.count(); i++) {
2168 KWPictureFrameSet *picFs =
dynamic_cast<KWPictureFrameSet*
>(m_frames[i]->frameSet());
2170 keepAspect = picFs->keepAspectRatio();
2173 bool noGrid = keyState & TQt::ShiftButton;
2174 bool scaleFromCenter = keyState & TQt::ControlButton;
2176 KoPoint p( point.x() - (m_hotSpot.x() + m_boundingRect.x()),
2177 point.y() - (m_hotSpot.y() + m_boundingRect.y()) );
2179 if ( m_parent->kWordDocument()->snapToGrid() && !noGrid )
2180 m_parent->applyGrid( p );
2182 KoRect sizeRect = m_boundingRect;
2184 sizeRect.setY(sizeRect.y() + p.y());
2186 sizeRect.setBottom(sizeRect.bottom() + p.y());
2188 sizeRect.setX(sizeRect.left() + p.x());
2190 sizeRect.setRight(sizeRect.right() + p.x());
2192 double ratio = m_boundingRect.width() / m_boundingRect.height();
2193 double width = sizeRect.width();
2194 double height = sizeRect.height();
2195 int toLargestEdge = (m_bottom?1:0) + (m_top?1:0) +
2196 (m_left?1:0) + (m_right?1:0);
2197 bool horizontal = m_left || m_right;
2199 if(toLargestEdge != 1) {
2201 width = height * ratio;
2203 height = width / ratio;
2206 height = width / ratio;
2208 width = height * ratio;
2211 sizeRect.setBottom(sizeRect.top() + height);
2213 sizeRect.setTop(sizeRect.bottom() - height);
2216 sizeRect.setLeft(sizeRect.right() - width);
2218 sizeRect.setRight(sizeRect.left() + width);
2220 if(scaleFromCenter) {
2221 KoPoint origCenter(m_boundingRect.x() + m_boundingRect.width() / 2,
2222 m_boundingRect.y() + m_boundingRect.height() / 2);
2223 KoPoint newCenter(sizeRect.x() + sizeRect.width() / 2,
2224 sizeRect.y() + sizeRect.height() / 2);
2225 sizeRect.moveTopLeft(sizeRect.topLeft() + (origCenter - newCenter));
2228 KWPageManager *pageManager = m_parent->kWordDocument()->pageManager();
2229 sizeRect.moveTopLeft(pageManager->
clipToDocument(sizeRect.topLeft()));
2230 sizeRect.moveBottomRight(pageManager->
clipToDocument(sizeRect.bottomRight()));
2231 sizeRect.setX( TQMAX(0, sizeRect.x()) );
2238 Converter(KoRect &from, KoRect &to,
KWViewMode *viewMode) {
2239 m_from = from.topLeft();
2240 m_to = to.topLeft();
2241 m_viewMode = viewMode;
2242 m_diffX = to.width() / from.width();
2243 m_diffY = to.height() / from.height();
2246 void update(
KWFrame *frame, KoRect &orig) {
2247 TQRect oldRect( m_viewMode->normalToView( frame->
outerRect(m_viewMode) ) );
2249 frame->moveTopLeft( convert( orig.topLeft() ) );
2250 KoPoint bottomRight( convert( orig.bottomRight() ) );
2251 frame->setBottom( bottomRight.y() );
2252 frame->setRight( bottomRight.x() );
2254 TQRect newRect( frame->
outerRect(m_viewMode) );
2255 TQRect frameRect( m_viewMode->normalToView( newRect ) );
2257 m_repaintRegion += TQRegion(oldRect).unite(frameRect).boundingRect();
2260 TQRegion repaintRegion() {
2261 return m_repaintRegion;
2265 KoPoint convert(KoPoint point) {
2266 double offsetX = point.x() - m_from.x();
2267 double offsetY = point.y() - m_from.y();
2268 KoPoint answer(m_to.x() + offsetX * m_diffX, m_to.y() + offsetY * m_diffY);
2272 KoPoint m_from, m_to;
2274 TQRegion m_repaintRegion;
2275 double m_diffX, m_diffY;
2278 Converter converter(m_boundingRect, sizeRect, m_parent->viewMode());
2279 for(
unsigned int i=0; i < m_frames.count(); i++)
2280 converter.update(m_frames[i], m_frameResize[i].oldRect);
2282 if ( !m_parent->kWordDocument()->showGrid() && m_parent->kWordDocument()->snapToGrid() )
2283 m_parent->repaintContents(
false );
2285 m_parent->repaintContents( converter.repaintRegion().boundingRect(),
false );
2286 m_parent->gui()->getView()->updateFrameStatusBarItem();
2290 for(
unsigned int i=0; i < m_frames.count(); i++) {
2292 FrameResizeStruct frs = m_frameResize[i];
2293 frs.newRect = frame->
rect();
2294 frs.newMinHeight = frame->height();
2295 m_frameResize[i] = frs;
2302 for(
unsigned int i=0; i < m_frames.count(); i++) {
2311FrameMovePolicy::FrameMovePolicy(
KWCanvas *parent, KoPoint &point) :
2314 TQValueListConstIterator<KWFrame*> framesIterator = m_frames.begin();
2315 for(;framesIterator != m_frames.end(); ++framesIterator) {
2316 KWFrame *frame = *framesIterator;
2318 FrameMoveStruct fms(frame->topLeft(), KoPoint(0,0));
2319 m_frameMove.append(fms);
2322 m_hotSpot = point - m_boundingRect.topLeft();
2323 m_startPoint = m_boundingRect.topLeft();
2327 bool noGrid = keyState & TQt::ShiftButton;
2328 bool linearMove = (keyState & TQt::AltButton) || (keyState & TQt::ControlButton);
2330 KWPageManager *pageManager = m_parent->kWordDocument()->pageManager();
2332 KoRect oldBoundingRect = m_boundingRect;
2336 KoPoint p( point.x() - m_hotSpot.x(), point.y() - m_hotSpot.y() );
2338 if(TQABS(p.x() - m_startPoint.x()) < TQABS(p.y() - m_startPoint.y()))
2339 p.setX(m_startPoint.x());
2341 p.setY(m_startPoint.y());
2343 if ( m_parent->kWordDocument()->snapToGrid() && !noGrid )
2344 m_parent->applyGrid( p );
2347 m_boundingRect.moveTopLeft( p );
2348 m_boundingRect.moveBottomRight( pageManager->
clipToDocument(m_boundingRect.bottomRight()) );
2351 int topPage = pageManager->
pageNumber( m_boundingRect.topLeft() );
2352 int bottomPage = pageManager->
pageNumber( m_boundingRect.bottomRight() );
2354 if ( topPage != bottomPage ) {
2356 Q_ASSERT( bottomPage == -1 || topPage + 1 == bottomPage );
2357 double topPart = m_boundingRect.bottom() - pageManager->
bottomOfPage(topPage);
2358 if ( topPart < m_boundingRect.height() / 2 )
2359 p.setY( pageManager->
bottomOfPage(topPage) - m_boundingRect.height() - 1 );
2361 p.setY( pageManager->
topOfPage(bottomPage) );
2362 m_boundingRect.moveTopLeft( p );
2363 m_boundingRect.moveBottomRight( pageManager->
clipToDocument(m_boundingRect.bottomRight()) );
2366 if( m_boundingRect.topLeft() == oldBoundingRect.topLeft() )
2374 TQPtrList<KWTableFrameSet> tablesMoved;
2375 tablesMoved.setAutoDelete(
false );
2376 TQRegion repaintRegion;
2377 KoPoint _move=m_boundingRect.topLeft() - oldBoundingRect.topLeft();
2379 TQValueListIterator<KWFrame*> framesIterator = m_frames.begin();
2380 for(; framesIterator != m_frames.end(); ++framesIterator) {
2381 KWFrame *frame = *framesIterator;
2384 if ( fs->
type() == FT_TABLE ) {
2385 if ( tablesMoved.findRef(
static_cast<KWTableFrameSet *
> (fs) ) == -1 )
2389 TQRect oldRect( m_parent->viewMode()->normalToView( frame->
outerRect(m_parent->viewMode()) ) );
2391 frame->moveTopLeft( frame->topLeft() + _move );
2393 TQRect newRect( frame->
outerRect(m_parent->viewMode()) );
2395 TQRect frameRect( m_parent->viewMode()->normalToView( newRect ) );
2397 repaintRegion += TQRegion(oldRect).unite(frameRect).boundingRect();
2401 if ( !tablesMoved.isEmpty() ) {
2403 for (
unsigned int i = 0; i < tablesMoved.count(); i++ ) {
2405 for ( KWTableFrameSet::TableIter k(table) ; k ; ++k ) {
2406 KWFrame * frame = k->frame( 0 );
2407 TQRect oldRect( m_parent->viewMode()->normalToView( frame->
outerRect(m_parent->viewMode()) ) );
2408 frame->moveTopLeft( frame->topLeft() + _move );
2410 TQRect newRect( frame->
outerRect(m_parent->viewMode()) );
2411 TQRect frameRect( m_parent->viewMode()->normalToView( newRect ) );
2413 repaintRegion += TQRegion(oldRect).unite(frameRect).boundingRect();
2418 if ( !m_parent->kWordDocument()->showGrid() && m_parent->kWordDocument()->snapToGrid() )
2419 m_parent->repaintContents(
false );
2421 m_parent->repaintContents( repaintRegion.boundingRect(),
false );
2422 m_parent->gui()->getView()->updateFrameStatusBarItem();
2426 for(
unsigned int i=0; i < m_frames.count(); i++) {
2428 FrameMoveStruct fms = m_frameMove[i];
2429 fms.newPos = frame->topLeft();
2430 m_frameMove[i] = fms;
2437 for(
unsigned int i=0; i < m_frames.count(); i++) {
2439 frameViewManager->
slotFrameMoved(frame, m_frameMove[i].oldPos.y());
2445FrameSelectPolicy::FrameSelectPolicy(
KWCanvas *parent, MouseMeaning meaning, KoPoint &point, TQt::ButtonState buttonState, TQt::ButtonState keyState)
2448 bool leftButton = buttonState & TQt::LeftButton;
2454 if(leftButton && fse) {
2456 KWFrameViewManager::unselected,
true);
2459 point.setX(TQMAX(point.x(), view->
frame()->left()));
2460 point.setY(TQMAX(point.y(), view->
frame()->top()));
2461 point.setX(TQMIN(point.x(), view->
frame()->right()));
2462 point.setY(TQMIN(point.y(), view->
frame()->bottom()));
2465 TQPoint normalPoint = parent->kWordDocument()->zoomPoint(point);
2466 TQPoint mousePos = parent->viewMode()->
normalToView(normalPoint);
2467 TQMouseEvent *me =
new TQMouseEvent(TQEvent::MouseButtonPress, mousePos,
2468 buttonState, keyState);
2469 fse->mousePressEvent(me, normalPoint, point );
2472 m_validSelection =
false;
2477 m_validSelection = meaning != MEANING_NONE;
2478 m_parent->frameViewManager()->selectFrames(point, keyState, leftButton );
2493#include "KWCanvas.moc"
A policy that handles frame moves of any number of frames.
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.
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.
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.
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.
InteractionPolicy(KWCanvas *parent, bool doInit=true, bool includeInlineFrames=false)
Constructor.
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...
virtual void drawContents(TQPainter *p, int cx, int cy, int cw, int ch)
Reimplemented from TQScrollView, to draw the contents of the canvas.
void viewportResizeEvent(TQResizeEvent *)
We need to repaint if the window is resized.
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.
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.
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 resetStatusBarText()
Resets the status bar text.
Command created when one or more frames are moved.
Command created when a frame is resized (or "moved and resized" as for KWPartFrameSet).
This object is created to edit a particular frameset in a particular view The view's canvas creates i...
virtual void drawContents(TQPainter *, const TQRect &, const TQColorGroup &, bool onlyChanged, bool resetChanged, KWViewMode *viewMode, KWFrameViewManager *frameViewManager)
Paint this frameset in "has focus" mode (e.g.
Class: KWFrameSet Base type, a frameset holds content as well as frames to show that content.
static KWFrame * settingsFrame(const KWFrame *frame)
Returns the original frame that the param frame is a copy off, or the frame itself.
virtual FrameSetType type() const
The type of frameset.
const TQPtrList< KWFrame > & frameIterator() const
Iterator over the child frames.
virtual KWFrameSetEdit * createFrameSetEdit(KWCanvas *)
Create a framesetedit object to edit this frameset in canvas.
virtual void drawContents(TQPainter *painter, const TQRect &crect, const TQColorGroup &cg, bool onlyChanged, bool resetChanged, KWFrameSetEdit *edit, KWViewMode *viewMode, KWFrameViewManager *frameViewManager)
Paint this frameset.
bool isFloating() const
Return true if this frameset is floating (inline), false if it's fixed.
KWTableFrameSet * groupmanager() const
returns the groupManager this frameset belongs to.
KWFrame * frame(unsigned int _num) const
get a frame by number
Info frameSetInfo() const
Returns the type of TextFrameSet this is.
bool isVisible(KWViewMode *viewMode=0L) const
Returns true if the frameset is visible.
Class that knows about all the (visible) frames in the document and will act as a manager between the...
void slotFrameResized(KWFrame *f)
notify this slot if a Frame has been resized
KWFrameView * view(const KoPoint &point, SelectionType select, bool borderOnly=false) const
Returns a frameView representing a frame positioned at point, or 0 when no match found.
void slotFrameMoved(KWFrame *f, double previousYPosition)
notify this slot if a Frame has been moved
an instance of a KWFrameView represents the view in the MVC model of a frame; there can be multiple K...
void setSelected(bool selected, MouseMeaning selectPolicy=MEANING_MOUSE_SELECT)
Set the selected state of this frameView.
KWFrame * frame() const
returns the frame this frameView represents
bool selected() const
returns if this frameView is selected. A selected frame is shown differently on screen.
void showPopup(const KoPoint &point, KWView *view, const TQPoint &popupPoint) const
Show a context-sensitive popup menu based on the location of 'point'.
This class represents a single frame.
TQRect outerRect(KWViewMode *viewMode) const
Return the zoomed rectangle for this frame, including the border - for drawing.
double minimumFrameHeight(void) const
KWFrameSet * frameSet() const
Data stucture methods.
void setMinimumFrameHeight(double h)
The property minimum frame height is used to make the automatic frame shrinking code stop.
void setZOrder(int z)
The z-order of the frame, relative to the other frames on the same page.
int pageNumber() const
The page on which this frame is.
KoRect outerKoRect() const
Return the unzoomed rectangle, including the border, for the frames-on-top list.
const KoRect & rect() const
Return the rectangle for this frame.
The Page Manager manages all the pages a document contains and separates all the frames the document ...
double topOfPage(int pageNumber) const
Return the y-offset in this document of the top of page with pageNumber Note that pageNumber is NOT a...
KoPoint clipToDocument(const KoPoint &point)
Returns the argument point, with altered coordinats if the point happens to be outside all pages.
int pageNumber(const KoRect *rect) const
return pageNumber of frame, pagenumbers for a normal document start at 1.
KWPage * page(int pageNumber) const
return the KWPage of a specific page number. Returns 0 if page does not exist.
double bottomOfPage(int pageNumber) const
Return the y-offset in this document of the bottom of page with pageNumber Note that pageNumber is NO...
int pageNumber() const
returns the number of this page as it will be shown to the user.
TQRect zoomedRect(KoZoomHandler *zoomHandler)
return a TQRect with the size of this page in pixels.
const KoRect rect() const
return a KoRect with the (pt) sizes of this page. Margins are ignored for this function.
void updateChildGeometry()
Update the geometry of m_child based on the geometry of the frame.
This class implements tables by acting as the manager for the frame(set)s which make up the table cel...
virtual void finalize()
Called once the frameset has been completely loaded or constructed.
void setBoundingRect(KoRect rect, CellSize widthMode, CellSize heightMode)
Layout all cells to fit inside the rect, cells will however use a minimum size, so the table might en...
int columnEdgeAt(double x) const
return the number of the column edge closest to x (between 0 and getCols()+1)
int rowEdgeAt(double y) const
return the number of the row edge closest to x (between 0 and getRows()+1)
This is our KoTextDocument reimplementation, to create KWTextParag instead of KoTextParags,...
Object that is created to edit a Text frame set (KWTextFrameSet).
Class: KWTextFrameSet Contains text (KoTextObject) and frames to display that text.
KoTextObject * textObject() const
Return the contained text object.
The view mode used when printing (pages under one another, no selections).
Abstract base class for KWCanvas's view modes.
virtual TQPoint normalToView(const TQPoint &nPoint)=0
Normal coord -> view coord.