kpresenter

KPrTextDocument.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001 Laurent Montel <lmontel@mandrakesoft.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KPrTextDocument.h"
21
22#include "KPrDocument.h"
23#include "KPrTextObject.h"
24#include <KoTextParag.h>
25#include <kdebug.h>
26
27#include "KPrVariableCollection.h"
28
29#include <KoOasisContext.h>
30#include <KoDom.h>
31#include <KoXmlNS.h>
32
33KPrTextDocument::KPrTextDocument( KPrTextObject * textobj, KoTextFormatCollection *fc, KoTextFormatter *formatter )
34 : KoTextDocument( textobj->kPresenterDocument()->zoomHandler(), fc, formatter, true ), m_textobj( textobj )
35{
36 //kdDebug(33001) << "KPrTextDocument constructed " << this << " KPrTextObject:" << textobj << endl;
37}
38
39KPrTextDocument::~KPrTextDocument()
40{
41}
42
43
44bool KPrTextDocument::loadSpanTag( const TQDomElement& tag, KoOasisContext& context,
45 KoTextParag* parag, uint pos,
46 TQString& textData, KoTextCustomItem* & customItem )
47{
48 const TQString localName( tag.localName() );
49 const bool isTextNS = tag.namespaceURI() == KoXmlNS::text;
50 kdDebug( 32500 ) << "KPrTextDocument::loadSpanTag: " << localName << endl;
51
52 if ( isTextNS )
53 {
54 if ( localName == "a" )
55 {
56 TQString href( tag.attributeNS( KoXmlNS::xlink, "href", TQString() ) );
57 if ( href.startsWith( "#" ) )
58 {
59 context.styleStack().save();
60 // We have a reference to a bookmark (### TODO)
61 // As we do not support it now, treat it as a <span> without formatting
62 parag->loadOasisSpan( tag, context, pos ); // recurse
63 context.styleStack().restore();
64 }
65 else
66 {
67 // The text is contained in a <span> inside the <a> element. In theory
68 // we could have multiple spans there, but OO ensures that there is always only one,
69 // splitting the hyperlink if necessary (at format changes).
70 // Note that we ignore the formatting of the span.
71 TQDomElement spanElem = KoDom::namedItemNS( tag, KoXmlNS::text, "span" );
72 TQString text;
73 if ( spanElem.isNull() )
74 text = tag.text();
75 if ( spanElem.isNull() )
76 text = tag.text();
77 else {
78 // The save/restore of the stack is done by the caller (KoTextParag::loadOasisSpan)
79 // This allows to use the span's format for the variable.
80 //kdDebug(32500) << "filling stack with " << spanElem.attributeNS( KoXmlNS::text, "style-name", TQString() ) << endl;
81 context.fillStyleStack( spanElem, KoXmlNS::text, "style-name", "text" );
82 text = spanElem.text();
83 }
84 textData = KoTextObject::customItemChar(); // hyperlink placeholder
85 // unused tag.attributeNS( KoXmlNS::office, "name", TQString() )
86 KoVariableCollection& coll = context.variableCollection();
87 customItem = new KoLinkVariable( this, text, href,
88 coll.formatCollection()->format( "STRING" ),
89 &coll );
90 }
91 return true;
92 }
93 }
94 else // non "text:" tags
95 {
96 kdDebug()<<"Extension found tagName : "<< localName <<endl;
97 }
98 return false;
99}
100
101
102#include "KPrTextDocument.moc"
KPrTextDocument(KPrTextObject *textobj, KoTextFormatCollection *fc, KoTextFormatter *formatter=0L)
A text document inside a kptextobject.
bool loadSpanTag(const TQDomElement &tag, KoOasisContext &context, KoTextParag *parag, uint pos, TQString &textData, KoTextCustomItem *&customItem)
Extensions to KoTextParag::loadOasisSpan.