kword

KWPartFrameSet.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2000-2005 David Faure <faure@kde.org>
3 Copyright (C) 2005 Thomas Zander <zander@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KWPartFrameSet.h"
22#include "KWDocument.h"
23#include "KWCommand.h"
24#include "KWordPartFrameSetIface.h"
25#include "KWFrameViewManager.h"
26#include "KWFrameView.h"
27#include "KWViewMode.h"
28
29#include <KoOasisContext.h>
30#include <KoXmlWriter.h>
31#include <KoXmlNS.h>
32
33#include <tdelocale.h>
34#include <tdeapplication.h>
35
36#include <assert.h>
37
38KWPartFrameSet::KWPartFrameSet( KWDocument *_doc, KWDocumentChild *_child, const TQString & name )
39 : KWFrameSet( _doc ), m_child( 0 ), m_cmdMoveChild( 0 ), m_protectContent( false )
40{
41 if ( _child )
42 setChild( _child );
43
44 kdDebug(32001) << "KWPartFrameSet::KWPartFrameSet" << endl;
45 if ( name.isEmpty() )
46 m_name = _doc->generateFramesetName( i18n( "Object %1" ) );
47 else
48 m_name = name;
49}
50
51KWPartFrameSet::KWPartFrameSet( KWDocument* doc, const TQDomElement& frameTag,
52 const TQDomElement& objectTag, KoOasisContext& context )
53 : KWFrameSet( doc ), m_child( 0 ), m_cmdMoveChild( 0 ), m_protectContent( false )
54{
55 m_name = frameTag.attributeNS( KoXmlNS::draw, "name", TQString() );
56 if ( doc->frameSetByName( m_name ) ) // already exists!
57 m_name = doc->generateFramesetName( m_name + " %1" );
58
59 context.styleStack().save();
60 context.fillStyleStack( frameTag, KoXmlNS::draw, "style-name", "graphic" ); // get the style for the graphics element
61 KWFrame* frame = loadOasisFrame( frameTag, context );
62 context.styleStack().restore();
63
64 // Create a KWDocumentChild, without KoDocument inside
65 KWDocumentChild* child = doc->createChildDoc( frame->rect(), 0 );
66 setChild( child );
67 child->loadOasis( frameTag, objectTag );
69
70 // This is what loads the KoDocument
71 (void)child->loadOasisDocument( context.store(), context.manifestDocument() );
72}
73
74void KWPartFrameSet::setChild( KWDocumentChild* child )
75{
76 assert( !m_child );
77 m_child = child;
78 m_child->setPartFrameSet( this );
79 TQObject::connect( m_child, TQ_SIGNAL( changed( KoChild * ) ),
80 this, TQ_SLOT( slotChildChanged() ) );
81}
82
83KWPartFrameSet::~KWPartFrameSet()
84{
85}
86
87KWordFrameSetIface* KWPartFrameSet::dcopObject()
88{
89 if ( !m_dcop )
90 m_dcop = new KWordPartFrameSetIface( this );
91
92 return m_dcop;
93}
94
95
96void KWPartFrameSet::drawFrameContents( KWFrame* frame, TQPainter * painter, const TQRect & /*crect TODO*/,
97 const TQColorGroup &, bool onlyChanged, bool,
99{
100 if (!onlyChanged)
101 {
102 if ( !m_child || !m_child->document() )
103 {
104 kdDebug(32001) << "KWPartFrameSet::drawFrameContents " << this << " aborting. child=" << m_child
105 << " child->document()=" << (m_child?m_child->document():0) << endl;
106 return;
107 }
108
109 KoTextZoomHandler* zh = kWordDocument();
110
111 // We have to define better the merning of the rect that we pass. Does it include zooming ? (yes I think)
112 // Does it define the area to be repainted only? (no, that's the painter clip rect)
113 // So it defines the whole area covered by the embedded document, in pixels.
114 TQRect rframe( 0, 0,
115 zh->zoomItX( frame->innerWidth() ),
116 zh->zoomItY( frame->innerHeight() ) );
117 //kdDebug(32001) << "rframe=" << rframe << endl;
118
119 double zoomX = static_cast<double>( zh->zoom() ) / 100;
120 double zoomY = static_cast<double>( zh->zoom() ) / 100;
121 m_child->document()->paintEverything( *painter, rframe, true, 0L, zoomX, zoomY );
122
123 } //else kdDebug(32001) << "KWPartFrameSet::drawFrameContents " << this << " onlychanged=true!" << endl;
124}
125
127{
128 if( m_frames.isEmpty() ) // Deleted frameset
129 return;
130 m_child->setGeometry( m_frames.first()->toTQRect() );
131}
132
133void KWPartFrameSet::slotChildChanged()
134{
135 // This is called when the KoDocumentChild is resized (using the KoFrame)
136 TQPtrListIterator<KWFrame> listFrame = frameIterator();
137 KWFrame *frame = listFrame.current();
138 if ( frame )
139 {
140 frame->setRect( KoRect::fromTQRect( getChild()->geometry() ) );
141
142 //kdDebug(32001) << "KWPartFrameSet::slotChildChanged child's geometry " << getChild()->geometry()
143 // << " frame set to " << *frame << endl;
144 m_doc->frameChanged( frame );
145 //there is just a frame
146 if(m_cmdMoveChild)
147 m_cmdMoveChild->listFrameMoved().newRect = frame->normalize();
148 }
149 else
150 kdDebug(32001) << "Frame not found!" << endl;
151}
152
153TQDomElement KWPartFrameSet::save( TQDomElement &parentElem, bool saveFrames )
154{
155 if ( m_frames.isEmpty() ) // Deleted frameset -> don't save
156 return TQDomElement();
157 KWFrameSet::saveCommon( parentElem, saveFrames );
158 // Ok, this one is a bit hackish. KWDocument calls us for saving our stuff into
159 // the SETTINGS element, which it creates for us. So our save() doesn't really have
160 // the same behaviour as a normal KWFrameSet::save()....
161 return TQDomElement();
162}
163
164void KWPartFrameSet::saveOasis( KoXmlWriter& writer, KoSavingContext& context, bool ) const
165{
166 if ( m_frames.isEmpty() ) // Deleted frameset -> don't save
167 return;
168 // Save first frame with the whole contents
169 KWFrame* frame = m_frames.getFirst();
170 frame->startOasisFrame( writer, context.mainStyles(), name() );
171
172 writer.startElement( "draw:object" );
173 // #### let's hope name() is unique...
174 m_child->saveOasisAttributes( writer, name() );
175
176 writer.endElement(); // draw:object
177 writer.endElement(); // draw:frame
178}
179
180void KWPartFrameSet::load( TQDomElement &attributes, bool loadFrames )
181{
182 KWFrameSet::load( attributes, loadFrames );
183}
184
186{
187 // Content is protected -> can't edit. Maybe we should open part in readonly mode?
188 if ( m_protectContent )
189 return;
190 kdDebug() << k_funcinfo << endl;
191 //create undo/redo move command
192 KWFrame* frame = m_frames.first();
193 if (!frame)
194 return;
195 FrameIndex index( frame );
196 FrameResizeStruct tmpMove( frame->normalize(), 0, KoRect() );
197
198 if(!m_cmdMoveChild)
199 m_cmdMoveChild=new KWFramePartMoveCommand( i18n("Move/Resize Frame"), index, tmpMove );
200}
201
203{
204 kdDebug() << k_funcinfo << endl;
205 if( m_cmdMoveChild && m_cmdMoveChild->frameMoved() )
206 m_doc->addCommand(m_cmdMoveChild);
207 else
208 delete m_cmdMoveChild;
209 m_cmdMoveChild=0L;
210
211}
212
213void KWPartFrameSet::moveFloatingFrame( int frameNum, const KoPoint &position )
214{
215 //kdDebug()<<k_funcinfo<<" frame no="<<frameNum<<" to pos="<<position.x()<<","<<position.y()<<endl;
216 KWFrame * frame = m_frames.at( frameNum );
217 if ( frame )
218 {
219 KWFrameSet::moveFloatingFrame( frameNum, position );
220 m_child->setGeometry( frame->toTQRect(), true /* avoid circular events */ );
221 }
222}
223
225{
226 return 0L; // new KWPartFrameSetEdit( this, canvas );
227}
228
229#ifndef NDEBUG
230void KWPartFrameSet::printDebug()
231{
232 KWFrameSet::printDebug();
233 kdDebug() << " +-- Object Document: " << endl;
234 if ( getChild() )
235 {
236 if ( getChild()->document() )
237 kdDebug() << " Url : " << getChild()->document()->url().url()<<endl;
238 else
239 kdWarning() << "NO DOCUMENT" << endl;
240 kdDebug() << " Rectangle : " << getChild()->geometry().x() << "," << getChild()->geometry().y() << " " << getChild()->geometry().width() << "x" << getChild()->geometry().height() << endl;
241 } else
242 kdWarning() << "NO CHILD" << endl;
243}
244
245#endif
246
247void KWPartFrameSet::setDeleted( bool on)
248{
249 m_child->setDeleted( on );
250}
251
252void KWPartFrameSet::deleteFrame( unsigned int _num, bool remove, bool recalc )
253{
254 KWFrameSet::deleteFrame( _num, remove, recalc );
255 if ( m_frames.isEmpty() ) // then the whole frameset and thus the child is deleted
256 m_child->setDeleted();
257}
258
259void KWPartFrameSet::KWPartFrameSet::createEmptyRegion( const TQRect &crect, TQRegion &emptyRegion, KWViewMode *viewMode ) {
260 Q_UNUSED(crect);
261 Q_UNUSED(emptyRegion);
262 Q_UNUSED(viewMode);
263
264 // empty implementation since embedded parts can be transparant.
265}
266
267#if 0
268KWPartFrameSetEdit::KWPartFrameSetEdit( KWPartFrameSet * fs, KWCanvas * canvas )
269 : KWFrameSetEdit( fs, canvas )
270{
271 kdDebug(32001) << "KWPartFrameSetEdit::KWPartFrameSetEdit " << endl;
272 m_dcop=0L;
273 fs->startEditing();
274 TQObject::connect( m_canvas->gui()->getView(), TQ_SIGNAL( activated( bool ) ),
275 this, TQ_SLOT( slotChildActivated( bool ) ) );
276}
277
278KWPartFrameSetEdit::~KWPartFrameSetEdit()
279{
280 kdDebug(32001) << "KWPartFrameSetEdit::~KWPartFrameSetEdit" << endl;
281 delete m_dcop;
282}
283
284DCOPObject* KWPartFrameSetEdit::dcopObject()
285{
286 if ( !m_dcop )
287 m_dcop = new KWordPartFrameSetEditIface( this );
288 return m_dcop;
289}
290
291void KWPartFrameSetEdit::slotChildActivated(bool b)
292{
293 kdDebug() << "KWPartFrameSetEdit::slotChildActivated " << b << endl;
294 //we store command when we deactivate the child.
295 if( !b )
296 partFrameSet()->endEditing();
297
298}
299#endif
300
301void KWPartFrameSet::storeInternal()
302{
303 if ( getChild()->document()->storeInternal() )
304 {
305 KWFramePartExternalCommand* cmd =new KWFramePartExternalCommand( i18n("Make Document External"), this );
306 m_doc->addCommand(cmd);
307 getChild()->document()->setStoreInternal(false);
308 }
309 else
310 {
311 KWFramePartInternalCommand* cmd =new KWFramePartInternalCommand( i18n("Make Document Internal"), this );
312 m_doc->addCommand(cmd);
313 getChild()->document()->setStoreInternal(true);
314 }
315
316 kdDebug()<<k_funcinfo<<"url: "<<getChild()->url().url()<<" store internal="<<getChild()->document()->storeInternal()<<endl;
317}
318
319
320/******************************************************************/
321/* Class: KWDocumentChild */
322/******************************************************************/
323
324KWDocumentChild::KWDocumentChild( KWDocument *_wdoc, const TQRect& _rect, KoDocument *_doc )
325 : KoDocumentChild( _wdoc, _doc, _rect ), m_partFrameSet( 0 )
326{
327}
328
329KWDocumentChild::KWDocumentChild( KWDocument *_wdoc )
330 : KoDocumentChild( _wdoc ), m_partFrameSet( 0 )
331{
332}
333
334KWDocumentChild::~KWDocumentChild()
335{
336}
337
338void KWDocumentChild::setDocument( KoDocument *doc, const TQRect &geometry )
339{
340 // When hitTest returns true, we want to activate the part right away.
341 // PartManager supports selecting parts, but not in a doc/view separated way.
342 doc->setSelectable( false );
343 KoDocumentChild::setDocument( doc, geometry );
344}
345
346KoDocument* KWDocumentChild::hitTest( const TQPoint& p, const TQWMatrix& _matrix )
347{
348 Q_ASSERT( m_partFrameSet );
349 if ( isDeleted() || !document() ) {
350 return 0;
351 }
352
353#if KDE_IS_VERSION( 3, 4, 0 )
354 int keyState = kapp->keyboardMouseState();
355#else
356 int keyState = 0;
357 if ( kapp->keyboardModifiers() & TDEApplication::ControlModifier )
358 keyState = TQt::ControlButton;
359#endif
360
361 // Only activate when it's already selected, and when not clicking on the border.
362 // KWFrameView and the part frame policy have that logic already.
363 KWView* kwView = ::tqt_cast<KWView *>( parentDocument()->hitTestView() );
364 Q_ASSERT( kwView );
365 if ( kwView ) {
366 KWFrame* frame = m_partFrameSet->frame(0);
367 KWFrameView* frameView = kwView->frameViewManager()->view( frame );
368 Q_ASSERT( frameView );
369 MouseMeaning mouseMeaning = frameView->mouseMeaning( KoPoint( p ), keyState );
370 if ( mouseMeaning != MEANING_ACTIVATE_PART ) {
371 return 0;
372 }
373 }
374
375 return document()->hitTest( p, _matrix );
376}
377
378#include "KWPartFrameSet.moc"
Class: KWCanvas This class is responsible for the rendering of the frames to the screen as well as th...
Definition KWCanvas.h:61
Command created when a part with an external document is changed to be stored internal.
Definition KWCommand.h:351
Command created when a part with an external document is changed to be stored internal.
Definition KWCommand.h:335
Command created when one part is moved or resized.
Definition KWCommand.h:317
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
virtual void moveFloatingFrame(int frameNum, const KoPoint &position)
Move the frame frameNum to the given position - this is called when the frame is anchored and the anc...
virtual void deleteFrame(unsigned int num, bool remove=true, bool recalc=true)
Delete a frame from the set of frames this frameSet has.
const TQPtrList< KWFrame > & frameIterator() const
Iterator over the child frames.
Definition KWFrameSet.h:159
virtual void load(TQDomElement &framesetElem, bool loadFrames=true)
load from XML - when loading
void saveCommon(TQDomElement &parentElem, bool saveFrames)
save the common attributes for the frameset
KWFrame * frame(unsigned int _num) const
get a frame by number
TQString name() const
get/set frameset name. For tables in particular, this must be unique
Definition KWFrameSet.h:428
an instance of a KWFrameView represents the view in the MVC model of a frame; there can be multiple K...
Definition KWFrameView.h:82
MouseMeaning mouseMeaning(const KoPoint &point, int keyState)
Return the MouseMeaning enum value for the parent view.
This class represents a single frame.
Definition KWFrame.h:68
void startOasisFrame(KoXmlWriter &xmlWriter, KoGenStyles &mainStyles, const TQString &name, const TQString &lastFrameName=TQString()) const
Write out a draw:frame element and its style.
Definition KWFrame.cpp:544
const KoRect & rect() const
Return the rectangle for this frame.
Definition KWFrame.h:201
A frameset that contains an embedded object (a KWDocumentChild)
virtual void drawFrameContents(KWFrame *frame, TQPainter *painter, const TQRect &fcrect, const TQColorGroup &cg, bool onlyChanged, bool resetChanged, KWFrameSetEdit *edit, KWViewMode *viewMode)
Implement this one instead of drawFrame to benefit from double-buffering AND transparency handling (p...
virtual void load(TQDomElement &attributes, bool loadFrames=true)
load from XML - when loading
void updateChildGeometry()
Update the geometry of m_child based on the geometry of the frame.
virtual void moveFloatingFrame(int frameNum, const KoPoint &position)
Move the frame 'frameNum' to the given position and move the document child window with it This is ca...
void startEditing()
Called by KWView when the object is being edited (activated).
virtual TQDomElement save(TQDomElement &parentElem, bool saveFrames=true)
save to XML - when saving
void endEditing()
Called by KWView when the object is not being edited anymore (deactivated).
virtual void saveOasis(KoXmlWriter &writer, KoSavingContext &context, bool saveFrames) const
Save to OASIS format.
void deleteFrame(unsigned int num, bool remove=true, bool recalc=true)
Delete a frame from the set of frames this frameSet has.
virtual KWFrameSetEdit * createFrameSetEdit(KWCanvas *)
Create a framesetedit object to edit this frameset in canvas.
Abstract base class for KWCanvas's view modes.
Definition KWViewMode.h:48
Identifies a frame.
Definition KWCommand.h:98