21#include <KoDocument.h>
22#include <KoMainWindow.h>
24#include <KoViewIface.h>
25#include <KoDocumentChild.h>
30#include <tdeparts/partmanager.h>
31#include <tdeparts/event.h>
34#include <kstatusbar.h>
35#include <tdeapplication.h>
43 m_inOperation =
false;
45 m_children.setAutoDelete(
true );
47 m_tempActiveWidget = 0L;
50 m_documentDeleted=
false;
56 TQGuardedPtr<KoDocument> m_doc;
57 TQGuardedPtr<KParts::PartManager> m_manager;
59 TQPtrList<KoViewChild> m_children;
60 TQWidget *m_tempActiveWidget;
61 KoViewIface *m_dcopObject;
63 bool m_documentDeleted;
66 TQTimer *m_scrollTimer;
73 : m_widget(0), m_visible(false)
75 StatusBarItem( TQWidget * widget,
int stretch,
bool permanent )
76 : m_widget(widget), m_stretch(stretch), m_permanent(permanent), m_visible(false)
79 TQWidget * widget()
const {
return m_widget; }
81 void ensureItemShown( KStatusBar * sb )
85 sb->addWidget( m_widget, m_stretch, m_permanent );
90 void ensureItemHidden( KStatusBar * sb )
94 sb->removeWidget( m_widget );
105 TQValueList<StatusBarItem> m_statusBarItems;
110 : TQWidget( parent, name )
112 Q_ASSERT( document );
115 d =
new KoViewPrivate;
119 setFocusPolicy( TQWidget::StrongFocus );
121 setMouseTracking(
true );
126 connect( d->m_doc, TQ_SIGNAL( sigBeginOperation() ),
129 connect( d->m_doc, TQ_SIGNAL( sigEndOperation() ),
134 setupGlobalActions();
148 connect( coll, TQ_SIGNAL( actionStatusText(
const TQString & ) ),
150 connect( coll, TQ_SIGNAL( clearStatusText() ),
153 connect( d->m_doc, TQ_SIGNAL( sigStatusBarMessage(
const TQString& ) ),
155 connect( d->m_doc, TQ_SIGNAL( sigClearStatusBarMessage() ),
158 d->m_doc->setCurrent();
160 d->m_scrollTimer =
new TQTimer(
this );
161 connect (d->m_scrollTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( slotAutoScroll() ) );
166 kdDebug(30003) <<
"KoView::~KoView " <<
this << endl;
167 delete d->m_scrollTimer;
168 delete d->m_dcopObject;
169 if (!d->m_documentDeleted)
173 if ( d->m_manager && d->m_registered )
175 d->m_doc->removeView(
this);
176 d->m_doc->setCurrent(
false );
189 d->m_documentDeleted =
true;
194 return d->m_documentDeleted;
199 return child( doc ) != 0L;
204 d->m_manager = manager;
208 d->m_registered =
true;
212 d->m_registered =
false;
222 static const TQString &attrName = TDEGlobal::staticQString(
"name" );
223 TQString name = element.attribute( attrName );
228 act = d->m_doc->KXMLGUIClient::action( name.utf8() );
303 return const_cast<KoView *
>(
this);
322 if ( KParts::PartActivateEvent::test( ev ) )
324 else if ( KParts::PartSelectEvent::test( ev ) )
326 else if( KParts::GUIActivateEvent::test( ev ) )
334 assert( event->part()->inherits(
"KoDocument" ) );
337 if (
child && event->activated() )
339 if (
child->isRectangle() && !
child->isTransparent() )
342 d->m_children.append( viewChild );
344 TQApplication::setOverrideCursor(waitCursor);
346 d->m_manager->setActivePart(
child->document(), viewChild->frame()->view() );
347 TQApplication::restoreOverrideCursor();
350 viewChild->setInitialFrameGeometry();
354 emit regionInvalidated(
child->frameRegion(
matrix() ),
true );
356 emit childActivated(
child );
360 emit regionInvalidated(
child->frameRegion(
matrix() ),
true );
361 emit childDeactivated(
child );
367 emit activated( event->activated() );
374 assert( event->part()->inherits(
"KoDocument" ) );
378 if (
child && event->selected() )
382 emit regionInvalidated( r,
true );
383 emit childSelected(
child );
389 emit regionInvalidated( r,
true );
390 emit childUnselected(
child );
396 emit selected( event->selected() );
409 TQValueListIterator<KoViewPrivate::StatusBarItem> it = d->m_statusBarItems.begin();
410 for ( ; it != d->m_statusBarItems.end() ; ++it )
412 (*it).ensureItemShown( sb );
414 (*it).ensureItemHidden( sb );
419 KoViewPrivate::StatusBarItem item( widget, stretch, permanent );
420 d->m_statusBarItems.append(item);
421 TQValueListIterator<KoViewPrivate::StatusBarItem> it = d->m_statusBarItems.fromLast();
425 (*it).ensureItemShown( sb );
431 TQValueListIterator<KoViewPrivate::StatusBarItem> it = d->m_statusBarItems.begin();
432 for ( ; it != d->m_statusBarItems.end() ; ++it )
433 if ( (*it).widget() == widget )
436 (*it).ensureItemHidden( sb );
437 d->m_statusBarItems.remove( it );
440 if ( it == d->m_statusBarItems.end() )
441 kdWarning() <<
"KoView::removeStatusBarItem. Widget not found : " << widget << endl;
449 KParts::Part *selectedPart = d->m_manager->selectedPart();
451 if ( !selectedPart || !selectedPart->inherits(
"KoDocument" ) )
464 if ( !activePart || !activePart->inherits(
"KoDocument" ) )
472 d->m_scrollTimer->start( 50 );
477 d->m_scrollTimer->stop();
487 TQPtrListIterator<KoViewChild> it( d->m_children );
488 for (; it.current(); ++it )
489 if ( it.current()->frame()->view() == view )
497 TQPtrListIterator<KoViewChild> it( d->m_children );
498 for (; it.current(); ++it )
499 if ( it.current()->documentChild()->document() == doc )
513void KoView::slotChildActivated(
bool a )
523 KoView* view = ch->frame()->view();
525 TQWidget *activeWidget = view->d->m_tempActiveWidget;
527 if ( d->m_manager->activeWidget() )
528 activeWidget = d->m_manager->activeWidget();
530 if ( !activeWidget || !activeWidget->inherits(
"KoView" ) )
536 TQObject *n = activeWidget;
538 if ( n == (TQObject *)view )
544 d->m_tempActiveWidget = activeWidget;
545 TQApplication::setOverrideCursor(waitCursor);
546 d->m_manager->setActivePart( 0L );
548 TQGuardedPtr<KoDocumentChild> docChild = ch->documentChild();
549 TQGuardedPtr<KoFrame> chFrame = ch->frame();
550 if ( docChild && chFrame && chFrame->view() )
552 docChild->setContentsPos( chFrame->view()->canvasXOffset(),
553 chFrame->view()->canvasYOffset() );
554 docChild->document()->setViewBuildDocument( chFrame->view(), chFrame->view()->xmlguiBuildDocument() );
557 d->m_children.remove( ch );
559 d->m_manager->addPart( docChild->document(),
false );
561 TQApplication::restoreOverrideCursor();
566 emit activated(
false );
571 TQRegion region(
child->oldPointArray(
matrix() ) );
572 emit regionInvalidated(
child->frameRegion(
matrix(),
true ).unite( region ),
true );
575int KoView::autoScrollAcceleration(
int offset )
const
580 return offset*offset/40;
583void KoView::slotAutoScroll( )
585 TQPoint scrollDistance;
586 bool actuallyDoScroll =
false;
587 TQPoint pos( mapFromGlobal( TQCursor::pos() ) );
592 scrollDistance.setY ((
int) - autoScrollAcceleration( - pos.y() +
topBorder() ));
593 actuallyDoScroll =
true;
597 scrollDistance.setY ((
int) autoScrollAcceleration(pos.y() - height() +
bottomBorder() ));
598 actuallyDoScroll =
true;
603 scrollDistance.setX ((
int) - autoScrollAcceleration( - pos.x() +
leftBorder() ));
604 actuallyDoScroll =
true;
608 scrollDistance.setX ((
int) autoScrollAcceleration( pos.x() - width() +
rightBorder() ));
609 actuallyDoScroll =
true;
612 if ( actuallyDoScroll )
614 int state = kapp->keyboardMouseState();
616 pos =
canvas()->mapFrom(
this, pos);
617 TQMouseEvent *
event =
new TQMouseEvent(TQEvent::MouseMove, pos, 0, state);
619 TQApplication::postEvent(
canvas(), event );
620 emit autoScroll( scrollDistance );
625void KoView::setupGlobalActions() {
626 actionNewView =
new TDEAction( i18n(
"&New View" ),
"window-new", 0,
633 kdDebug() <<
"KoView::setupPrinter not implemented by the application!" << endl;
638 kdDebug() <<
"KoView::print not implemented by the application!" << endl;
642 assert( ( d!=0L && d->m_doc ) );
646 shell->setRootDocument(thisDocument);
652 return d->m_inOperation;
657 d->m_inOperation =
true;
658 canvas()->setUpdatesEnabled(
false);
663 canvas()->setUpdatesEnabled(
true);
664 d->m_inOperation =
false;
671 return dynamic_cast<KoMainWindow *
>( topLevelWidget() );
701 if ( !d->m_dcopObject )
702 d->m_dcopObject =
new KoViewIface(
this );
703 return d->m_dcopObject;
706class KoViewChild::KoViewChildPrivate
712 ~KoViewChildPrivate()
719 d =
new KoViewChildPrivate;
720 m_parentView = _parentView;
723 m_frame =
new KoFrame( parentView()->canvas() );
727 view->setPartManager( parentView()->partManager() );
732 m_frame->setView( view );
736 parentView()->canvasAddChild(
this );
763 connect( view, TQ_SIGNAL( activated(
bool ) ),
764 parentView(), TQ_SLOT( slotChildActivated(
bool ) ) );
767KoViewChild::~KoViewChild()
771 slotFrameGeometryChanged();
772 delete static_cast<KoFrame *
>( m_frame );
777void KoViewChild::slotFrameGeometryChanged()
780 TQRect geom = m_frame->geometry();
781 int b = m_frame->border();
782 TQRect borderRect( geom.x() + b + parentView()->canvasXOffset(),
783 geom.y() + b + parentView()->canvasYOffset(),
784 geom.width() - b * 2,
785 geom.height() - b * 2 );
791 TQRect borderLessRect( geom.x() + m_frame->leftBorder() + parentView()->canvasXOffset(),
792 geom.y() + m_frame->topBorder() + parentView()->canvasYOffset(),
793 geom.width() - m_frame->leftBorder() - m_frame->rightBorder(),
794 geom.height() - m_frame->topBorder() - m_frame->bottomBorder() );
798 TQRect childGeom = parentView()->reverseViewTransformations( borderLessRect );
799 kdDebug() <<
"KoChild::slotFrameGeometryChanged child geometry "
800 << (
geometry() == childGeom ?
"already " :
"set to " )
801 << childGeom << endl;
802 m_child->setGeometry( childGeom );
807void KoViewChild::slotDocGeometryChanged()
813 TQRect geom = parentView()->applyViewTransformations( m_child->geometry() );
814 TQRect borderRect( geom.x() - m_frame->leftBorder() - parentView()->canvasXOffset(),
815 geom.y() - m_frame->topBorder() - parentView()->canvasYOffset(),
816 geom.width() + m_frame->leftBorder() + m_frame->rightBorder(),
817 geom.height() + m_frame->topBorder() + m_frame->bottomBorder() );
818 kdDebug() <<
"KoViewChild::slotDocGeometryChanged frame geometry "
819 << ( m_frame->geometry() == borderRect ?
"already " :
"set to " )
820 << borderRect << endl;
822 m_frame->setGeometry( borderRect );
827 return TQPoint( tqRound( p.x() *
zoom() ), tqRound( p.y() *
zoom() ) );
832 return TQPoint( tqRound( v.x() /
zoom() ), tqRound( v.y() /
zoom() ) );
847void KoViewChild::setInitialFrameGeometry()
849 kdDebug() << k_funcinfo << endl;
852 connect( m_frame, TQ_SIGNAL( geometryChanged() ),
853 this, TQ_SLOT( slotFrameGeometryChanged() ) );
855 this, TQ_SLOT( slotDocGeometryChanged() ) );
858 slotDocGeometryChanged();
860 slotFrameGeometryChanged();
void setPartObject(TQObject *object)
const TQPtrList< Part > * parts() const
virtual void addPart(Part *part, bool setActive=true)
virtual TDEInstance * instance() const
void setXMLGUIBuildDocument(const TQDomDocument &doc)
TDEAction * action(const char *name) const
virtual TDEActionCollection * actionCollection() const
KoChild is an abstract base class that represents the geometry associated with an embedded document.
void setGeometry(const TQRect &rect, bool noEmit=false)
Sets a new geometry for this child document.
void changed(KoChild *thisChild)
Emitted every time this child changes, but only if this child is not locked.
void lock()
Locks this child and stores the current transformation.
void unlock()
Unlocks this child and emits a changed signal.
virtual double xScaling() const
virtual double yScaling() const
virtual TQRegion frameRegion(const TQWMatrix &matrix=TQWMatrix(), bool solid=false) const
bool locked() const
If the child is locked, geometry changes (including scaling, rotation, ...) are not backed up.
Holds an embedded object.
KoDocument * document() const
The KOffice document class.
virtual KParts::Part * hitTest(TQWidget *widget, const TQPoint &globalPos)
Reimplemented from KParts::Part.
KoDocumentChild * child(KoDocument *doc)
KoView * createView(TQWidget *parent=0, const char *name=0)
Create a new view for the document.
virtual void paintEverything(TQPainter &painter, const TQRect &rect, bool transparent=false, KoView *view=0L, double zoomX=1.0, double zoomY=1.0)
Paints the whole document into the given painter object.
Main window for a KOffice application.
This class represents an active embedded document.
This class is used to display a KoDocument.
virtual void guiActivateEvent(KParts::GUIActivateEvent *)
Handles the event KParts::GUIActivateEvent.
void removeStatusBarItem(TQWidget *widget)
Remove a widget from the statusbar for this view.
TDEMainWindow * mainWindow() const
virtual int leftBorder() const
Retrieves the left border width that is displayed around the content if the view is active.
virtual TDEAction * action(const TQDomElement &element) const
Returns the action described action object.
virtual double zoom() const
virtual DCOPObject * dcopObject()
Return a DCOP interface for this view KOffice Applications are strongly recommended to reimplement th...
KoDocument * koDocument() const
Retrieves the document object of this view.
virtual void endOperation()
Slot to allow code to signal the end of an operation where the screen should not have been updating.
bool hasDocumentInWindow(KoDocument *doc)
virtual int bottomBorder() const
virtual TQWidget * canvas() const
Overload this function if the content will be displayed on some child widget instead of the view dire...
virtual int topBorder() const
virtual void partActivateEvent(KParts::PartActivateEvent *event)
Handles the event KParts::PartActivateEvent.
virtual TQPoint reverseViewTransformations(const TQPoint &) const
Reverse the transformations that the view makes to its contents, i.e.
virtual int canvasYOffset() const
Overload this function if the content will be displayed with an offset relative to the upper left cor...
KoViewChild * child(KoView *view)
void setDocumentDeleted()
Tells this view that its document has got deleted (called internally).
virtual int canvasXOffset() const
Overload this function if the content will be displayed with an offset relative to the upper left cor...
virtual void setZoom(double zoom)
Scales the view on the content.
virtual void customEvent(TQCustomEvent *ev)
This method handles three events: KParts::PartActivateEvent, KParts::PartSelectEvent and KParts::GUIA...
void addStatusBarItem(TQWidget *widget, int stretch=0, bool permanent=false)
This adds a widget to the statusbar for this view.
virtual KoDocumentChild * activeChild()
virtual void partSelectEvent(KParts::PartSelectEvent *event)
Handles the event KParts::PartSelectEvent.
void enableAutoScroll()
Sets up so that autoScroll signals are emitted when the mouse pointer is outside the view.
void slotActionStatusText(const TQString &text)
Display a message in the status bar (calls TQStatusBar::message()).
virtual KoDocumentChild * selectedChild()
virtual void canvasAddChild(KoViewChild *child)
Overload this function if you need to perform some actions after KoView (the part widget) is inserted...
virtual TQWMatrix matrix() const TDE_DEPRECATED
Returns the matrix which is used by the view to transform the content.
virtual void print(KPrinter &printer)
Overload this method with your own printing code.
virtual int rightBorder() const
virtual ~KoView()
Destroys the view and unregisters at the document.
virtual TQPoint applyViewTransformations(const TQPoint &) const
Apply the transformations that the view makes to its contents.
virtual void newView()
Slot to create a new view around the contained koDocument.
bool isInOperation() const
Check to see if the view is currently in the middle of an operation which means that there will be no...
KStatusBar * statusBar() const
void disableAutoScroll()
Stops the emitting of autoScroll signals.
virtual void beginOperation()
Slot to allow code to signal the beginning of an operation where the screen should not update until i...
KoMainWindow * shell() const
virtual void paintEverything(TQPainter &painter, const TQRect &rect, bool transparent=false)
calls KoDocument::paintEverything()
void showAllStatusBarItems(bool show)
Show or hide all statusbar items.
virtual KoDocument * hitTest(const TQPoint &pos)
Retrieves the document that is hit.
virtual void setupPrinter(KPrinter &printer)
Overload this method to setup KPrinter before the actual printing.
KoView(KoDocument *document, TQWidget *parent=0, const char *name=0)
Creates a new view for the document.
void slotClearStatusText()
End of the message in the status bar (calls TQStatusBar::clear()).
bool documentDeleted() const
void setHighlightingEnabled(bool enable)
virtual void setWidget(TQWidget *widget)
TDEAction * zoom(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)