21#include "KWTextFrameSet.h"
22#include "KWDocument.h"
23#include "KWViewMode.h"
25#include <KoXmlWriter.h>
31 : KoTextCustomItem( textDocument),
32 m_frameset( frameset ),
39 kdDebug(32001) <<
"KWAnchor::~KWAnchor" << endl;
42void KWAnchor::setFormat( KoTextFormat* format )
44 m_frameset->setAnchorFormat( format, m_frameNum );
47void KWAnchor::finalize()
52 int paragx = paragraph()->rect().x();
53 int paragy = paragraph()->rect().y();
54 kdDebug(32001) <<
this <<
" KWAnchor::finalize " << x() <<
"," << y() <<
" paragx=" << paragx <<
" paragy=" << paragy << endl;
56 KWTextFrameSet * fs =
static_cast<KWTextDocument *
>(textDocument())->textFrameSet();
62 m_frameset->moveFloatingFrame( m_frameNum, dPoint );
66 kdDebug(32001) <<
"KWAnchor::move internalToDocument returned 0L for " << x()+paragx <<
", " << y()+paragy << endl;
70void KWAnchor::draw( TQPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch,
const TQColorGroup& cg,
bool selected )
78 Q_ASSERT( x == xpos );
79 Q_ASSERT( y == ypos );
80 if ( x != xpos || y != ypos )
81 kdDebug() <<
"Warning: x=" << x <<
" y=" << y <<
" xpos=" << xpos <<
" ypos=" << ypos << endl;
84 KWTextFrameSet * fs =
static_cast<KWTextDocument *
>(textDocument())->textFrameSet();
85 KoTextZoomHandler* zh = fs->textDocument()->paintingZoomHandler();
87 int paragx = paragraph()->rect().x();
88 int paragy = paragraph()->rect().y();
89 TQRect inlineFrameLU( paragx+xpos, paragy+ypos, width, height );
91 kdDebug(32001) <<
"KWAnchor::draw x:" << x <<
", y:" << y <<
" paragx=" << paragx <<
" paragy=" << paragy << endl;
92 kdDebug(32001) <<
" inline frame in LU coordinates: " << inlineFrameLU << endl;
95 TQRect crectLU = TQRect( (cx > 0 ? cx : 0)+paragx, cy+paragy, cw, ch );
97 kdDebug(32001) <<
" crect in LU coordinates: " << DEBUGRECT( crectLU ) << endl;
100 crectLU = crectLU.intersect ( inlineFrameLU );
104 kdDebug(32001) <<
" crect&frame in LU coordinates: " << DEBUGRECT( crectLU ) << endl;
108 TQPoint topLeftLU = crectLU.topLeft();
109 TQPoint bottomRightLU = crectLU.bottomRight();
114 TQPoint paragPos = inlineFrameLU.topLeft();
122 KoRect crectPt( topLeftPt, bottomRightPt );
127 crect.rBottom() += 2;
130 kdDebug() <<
" crect in view coordinates (pixel) : " << DEBUGRECT( crect ) << endl;
137 if ( containingFrame && containingFrame->
isCopy() )
142 while ( !frameIt.atFirst() && frameIt.current() != containingFrame )
144 if ( frameIt.atFirst() && frameIt.current() != containingFrame )
145 kdWarning() <<
"KWAnchor::draw: containingFrame not found " << containingFrame << endl;
146 while ( !frameIt.atFirst() && frameIt.current()->isCopy() )
148 containingFrame = frameIt.current();
153 KoPoint topLeftParagPt( 0, 0 );
154 if ( containingFrame )
155 topLeftParagPt = containingFrame->innerRect().topLeft();
157 topLeftParagPt.rx() += zh->layoutUnitPtToPt( zh->pixelYToPt( paragx ) );
158 topLeftParagPt.ry() += zh->layoutUnitPtToPt( zh->pixelYToPt( paragy ) );
159 if ( containingFrame )
160 topLeftParagPt.ry() -= containingFrame->internalY();
168 p->translate( -topLeftParag.x(), -topLeftParag.y() );
170 kdDebug() <<
" translating by " << -topLeftParag.x() <<
"," << -topLeftParag.y() << endl;
173 TQColorGroup cg2( cg );
175 KWFrameViewManager *fvm = 0;
176 if(m_frameset->kWordDocument()) {
177 TQValueList<KWView *> views = m_frameset->kWordDocument()->getAllViews();
179 if ( !views.isEmpty() )
180 fvm = views.first()->frameViewManager();
182 m_frameset->drawContents( p, crect, cg2,
false,
true, 0L, fs->
currentViewMode(), fvm);
184 if( selected && placement() == PlaceInline && p->device()->devType() != TQInternal::Printer )
188 TQRect frameRect = crect;
190 kdDebug() <<
"KWAnchor::draw selected frame. frameRect=" << frameRect << endl;
192 p->fillRect( frameRect, TQBrush( cg.highlight(), TQBrush::Dense4Pattern) );
197 kdDebug() <<
"KWAnchor::draw done" << endl;
203 KoSize kosz = m_frameset->floatingFrameSize( m_frameNum );
205 KoTextZoomHandler * zh = textDocument()->formattingZoomHandler();
206 TQSize sz( zh->ptToLayoutUnitPixX( kosz.width() ), zh->ptToLayoutUnitPixY( kosz.height() ) );
211 sz = TQSize( width, height );
215int KWAnchor::ascent()
const
218 int ret = ( baseline == -1 ) ? height : baseline;
223void KWAnchor::resize()
228 if ( width != s.width() || height != s.height() )
232 kdDebug(32001) <<
"KWAnchor::resize " << width <<
"x" << height << endl;
233 KoTextParag * parag = paragraph();
236 kdDebug(32001) <<
"KWAnchor::resize invalidating parag " << parag->paragId() << endl;
237 parag->invalidate( 0 );
242KCommand * KWAnchor::createCommand()
244 kdDebug(32001) <<
"KWAnchor::addCreateCommand" << endl;
245 return m_frameset->anchoredObjectCreateCommand( m_frameNum );
248KCommand * KWAnchor::deleteCommand()
250 kdDebug(32001) <<
"KWAnchor::addDeleteCommand" << endl;
251 return m_frameset->anchoredObjectDeleteCommand( m_frameNum );
254void KWAnchor::setDeleted(
bool b )
257 KoTextCustomItem::setDeleted( b );
259 kdDebug() <<
"KWAnchor::setDeleted " << b << endl;
261 m_frameset->setAnchored( 0L );
263 m_frameset->setAnchored(
static_cast<KWTextDocument *
>(textDocument())->textFrameSet() );
266void KWAnchor::save( TQDomElement &parentElem )
268 TQDomElement anchorElem = parentElem.ownerDocument().createElement(
"ANCHOR" );
269 parentElem.appendChild( anchorElem );
270 anchorElem.setAttribute(
"type",
"frameset" );
274 anchorElem.setAttribute(
"instance", m_frameset->name() );
277void KWAnchor::saveOasis( KoXmlWriter& writer, KoSavingContext& context )
const
279 if ( m_frameset->canBeSavedAsInlineCharacter() )
280 m_frameset->saveOasis( writer, context,
true );
283 writer.startElement(
"draw:frame" );
284 writer.addAttribute(
"draw:name", m_frameset->name() +
"-Wrapper" );
286 writer.addAttribute(
"koffice:is-wrapper-frame",
"true" );
288 KoSize kosz = m_frameset->floatingFrameSize( m_frameNum );
289 writer.addAttributePt(
"svg:width", kosz.width() );
290 writer.addAttributePt(
"svg:height", kosz.height() );
291 writer.startElement(
"draw:text-box" );
292 m_frameset->saveOasis( writer, context,
true );
298bool KWAnchor::ownLine()
const
304 return m_frameset->ownLine();
KWAnchor(KoTextDocument *textdoc, KWFrameSet *frameset, int frameNum)
Constructor.
int frameNum() const
The index the frameset needs to access which content is displayed in the anchor object.
TQSize size() const
Return the size of the item, i.e.
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.
const TQPtrList< KWFrame > & frameIterator() const
Iterator over the child frames.
virtual int floatingFrameBaseline(int)
Get the 'baseline' to use for the "floating frame" identified by frameNum.
bool isCopy() const
Drawing property: if isCopy, this frame is a copy of the previous frame in the frameset.
KoPoint internalToDocumentKnowingFrame(const KoPoint &relPoint, KWFrame *theFrame) const
A variant of internalToDocument, when the frame is already known.
KWFrame * internalToDocument(const KoPoint &relPoint, KoPoint &dPoint) const
Convert the in the internal qtextdoc coordinates (in layout units) into a point in the document coord...
KWViewMode * currentViewMode() const
The viewmode that was passed to drawContents.
KWFrame * currentDrawnFrame() const
The frame that we are currently drawing in drawFrame.
virtual TQPoint normalToView(const TQPoint &nPoint)=0
Normal coord -> view coord.