| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# dom2_range.cpp

    00001
    00026 #include "dom/dom_exception.h"
    00027 #include "xml/dom_docimpl.h"
    00028 #include "xml/dom2_rangeimpl.h"
    00029
    00030 using namespace DOM;
    00031
    00032 Range::Range()
    00033 {
    00034     // a range can't exist by itself - it must be associated with a document
    00035     impl = 0;
    00036 }
    00037
    00038 Range::Range(const Document rootContainer)
    00039 {
    00040     if(rootContainer.handle())
    00041     {
    00042     impl = new RangeImpl(rootContainer.handle()->docPtr());
    00043     impl->ref();
    00044     }
    00045     else
    00046     impl = 0;
    00047 }
    00048
    00049 Range::Range(const Range &other)
    00050 {
    00051     impl = other.impl;
    00052     if (impl) impl->ref();
    00053 }
    00054
    00055 Range::Range(const Node startContainer, const long startOffset, const Node endContainer, const long endOffset)
    00056 {
    00057     if (startContainer.isNull() || endContainer.isNull()) {
    00058         throw DOMException(DOMException::NOT_FOUND_ERR);
    00059     }
    00060
    00061     if (!startContainer.handle()->getDocument() ||
    00062         startContainer.handle()->getDocument() != endContainer.handle()->getDocument()) {
    00063         throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
    00064     }
    00065
    00066     impl = new RangeImpl(startContainer.handle()->docPtr(),startContainer.handle(),startOffset,endContainer.handle(),endOffset);
    00067     impl->ref();
    00068 }
    00069
    00070 Range::Range(RangeImpl *i)
    00071 {
    00072     impl = i;
    00073     if (impl) impl->ref();
    00074 }
    00075
    00076 Range &Range::operator = (const Range &other)
    00077 {
    00078     if ( impl != other.impl ) {
    00079     if (impl) impl->deref();
    00080     impl = other.impl;
    00081     if (impl) impl->ref();
    00082     }
    00083     return *this;
    00084 }
    00085
    00086 Range::~Range()
    00087 {
    00088     if (impl) impl->deref();
    00089 }
    00090
    00091 Node Range::startContainer() const
    00092 {
    00093     if (!impl)
    00094         throw DOMException(DOMException::INVALID_STATE_ERR);
    00095
    00096     int exceptioncode = 0;
    00097     NodeImpl *r = impl->startContainer(exceptioncode);
    00098     throwException(exceptioncode);
    00099     return r;
    00100 }
    00101
    00102 long Range::startOffset() const
    00103 {
    00104     if (!impl)
    00105         throw DOMException(DOMException::INVALID_STATE_ERR);
    00106
    00107     int exceptioncode = 0;
    00108     long r = impl->startOffset(exceptioncode);
    00109     throwException(exceptioncode);
    00110     return r;
    00111
    00112 }
    00113
    00114 Node Range::endContainer() const
    00115 {
    00116     if (!impl)
    00117         throw DOMException(DOMException::INVALID_STATE_ERR);
    00118
    00119     int exceptioncode = 0;
    00120     NodeImpl *r = impl->endContainer(exceptioncode);
    00121     throwException(exceptioncode);
    00122     return r;
    00123 }
    00124
    00125 long Range::endOffset() const
    00126 {
    00127     if (!impl)
    00128         throw DOMException(DOMException::INVALID_STATE_ERR);
    00129
    00130     int exceptioncode = 0;
    00131     long r = impl->endOffset(exceptioncode);
    00132     throwException(exceptioncode);
    00133     return r;
    00134 }
    00135
    00136 bool Range::collapsed() const
    00137 {
    00138     if (!impl)
    00139         throw DOMException(DOMException::INVALID_STATE_ERR);
    00140
    00141     int exceptioncode = 0;
    00142     bool r = impl->collapsed(exceptioncode);
    00143     throwException(exceptioncode);
    00144     return r;
    00145 }
    00146
    00147 Node Range::commonAncestorContainer()
    00148 {
    00149     if (!impl)
    00150         throw DOMException(DOMException::INVALID_STATE_ERR);
    00151
    00152     int exceptioncode = 0;
    00153     NodeImpl *r = impl->commonAncestorContainer(exceptioncode);
    00154     throwException(exceptioncode);
    00155     return r;
    00156 }
    00157
    00158 void Range::setStart( const Node &refNode, long offset )
    00159 {
    00160     if (!impl)
    00161         throw DOMException(DOMException::INVALID_STATE_ERR);
    00162
    00163     int exceptioncode = 0;
    00164     impl->setStart(refNode.handle(),offset,exceptioncode);
    00165     throwException(exceptioncode);
    00166 }
    00167
    00168 void Range::setEnd( const Node &refNode, long offset )
    00169 {
    00170     if (!impl)
    00171         throw DOMException(DOMException::INVALID_STATE_ERR);
    00172
    00173     int exceptioncode = 0;
    00174     impl->setEnd(refNode.handle(),offset,exceptioncode);
    00175     throwException(exceptioncode);
    00176 }
    00177
    00178 void Range::setStartBefore( const Node &refNode )
    00179 {
    00180     if (!impl)
    00181         throw DOMException(DOMException::INVALID_STATE_ERR);
    00182
    00183
    00184     int exceptioncode = 0;
    00185     impl->setStartBefore(refNode.handle(),exceptioncode);
    00186     throwException(exceptioncode);
    00187 }
    00188
    00189 void Range::setStartAfter( const Node &refNode )
    00190 {
    00191     if (!impl)
    00192         throw DOMException(DOMException::INVALID_STATE_ERR);
    00193
    00194     int exceptioncode = 0;
    00195     impl->setStartAfter(refNode.handle(),exceptioncode);
    00196     throwException(exceptioncode);
    00197 }
    00198
    00199 void Range::setEndBefore( const Node &refNode )
    00200 {
    00201     if (!impl)
    00202         throw DOMException(DOMException::INVALID_STATE_ERR);
    00203
    00204     int exceptioncode = 0;
    00205     impl->setEndBefore(refNode.handle(),exceptioncode);
    00206     throwException(exceptioncode);
    00207 }
    00208
    00209 void Range::setEndAfter( const Node &refNode )
    00210 {
    00211     if (!impl)
    00212         throw DOMException(DOMException::INVALID_STATE_ERR);
    00213
    00214     int exceptioncode = 0;
    00215     impl->setEndAfter(refNode.handle(),exceptioncode);
    00216     throwException(exceptioncode);
    00217 }
    00218
    00219 void Range::collapse( bool toStart )
    00220 {
    00221     if (!impl)
    00222         throw DOMException(DOMException::INVALID_STATE_ERR);
    00223
    00224     int exceptioncode = 0;
    00225     impl->collapse(toStart,exceptioncode);
    00226     throwException(exceptioncode);
    00227 }
    00228
    00229 void Range::selectNode( const Node &refNode )
    00230 {
    00231     if (!impl)
    00232         throw DOMException(DOMException::INVALID_STATE_ERR);
    00233
    00234     int exceptioncode = 0;
    00235     impl->selectNode(refNode.handle(),exceptioncode);
    00236     throwException(exceptioncode);
    00237 }
    00238
    00239 void Range::selectNodeContents( const Node &refNode )
    00240 {
    00241     if (!impl)
    00242         throw DOMException(DOMException::INVALID_STATE_ERR);
    00243
    00244     int exceptioncode = 0;
    00245     impl->selectNodeContents(refNode.handle(),exceptioncode);
    00246     throwException(exceptioncode);
    00247 }
    00248
    00249 short Range::compareBoundaryPoints( CompareHow how, const Range &sourceRange )
    00250 {
    00251     if (!impl)
    00252         throw DOMException(DOMException::INVALID_STATE_ERR);
    00253
    00254     int exceptioncode = 0;
    00255     short r = impl->compareBoundaryPoints(how,sourceRange.handle(),exceptioncode);
    00256     throwException(exceptioncode);
    00257     return r;
    00258 }
    00259
    00260 bool Range::boundaryPointsValid(  )
    00261 {
    00262     if (!impl)
    00263         throw DOMException(DOMException::INVALID_STATE_ERR);
    00264
    00265     return impl->boundaryPointsValid();
    00266 }
    00267
    00268 void Range::deleteContents(  )
    00269 {
    00270     if (!impl)
    00271         throw DOMException(DOMException::INVALID_STATE_ERR);
    00272
    00273     int exceptioncode = 0;
    00274     impl->deleteContents(exceptioncode);
    00275     throwException(exceptioncode);
    00276 }
    00277
    00278 DocumentFragment Range::extractContents(  )
    00279 {
    00280     if (!impl)
    00281         throw DOMException(DOMException::INVALID_STATE_ERR);
    00282
    00283     int exceptioncode = 0;
    00284     DocumentFragmentImpl *r = impl->extractContents(exceptioncode);
    00285     throwException(exceptioncode);
    00286     return r;
    00287 }
    00288
    00289 DocumentFragment Range::cloneContents(  )
    00290 {
    00291     if (!impl)
    00292         throw DOMException(DOMException::INVALID_STATE_ERR);
    00293
    00294     int exceptioncode = 0;
    00295     DocumentFragmentImpl *r = impl->cloneContents(exceptioncode);
    00296     throwException(exceptioncode);
    00297     return r;
    00298 }
    00299
    00300 void Range::insertNode( const Node &newNode )
    00301 {
    00302     if (!impl)
    00303         throw DOMException(DOMException::INVALID_STATE_ERR);
    00304
    00305     int exceptioncode = 0;
    00306     impl->insertNode(newNode.handle(),exceptioncode);
    00307     throwException(exceptioncode);
    00308 }
    00309
    00310 void Range::surroundContents( const Node &newParent )
    00311 {
    00312     if (!impl)
    00313         throw DOMException(DOMException::INVALID_STATE_ERR);
    00314
    00315     int exceptioncode = 0;
    00316     impl->surroundContents(newParent.handle(),exceptioncode);
    00317     throwException(exceptioncode);
    00318 }
    00319
    00320 Range Range::cloneRange(  )
    00321 {
    00322     if (!impl)
    00323         throw DOMException(DOMException::INVALID_STATE_ERR);
    00324
    00325     int exceptioncode = 0;
    00326     RangeImpl *r = impl->cloneRange(exceptioncode);
    00327     throwException(exceptioncode);
    00328     return r;
    00329 }
    00330
    00331 DOMString Range::toString(  )
    00332 {
    00333     if (!impl)
    00334         throw DOMException(DOMException::INVALID_STATE_ERR);
    00335
    00336     int exceptioncode = 0;
    00337     DOMString r = impl->toString(exceptioncode);
    00338     throwException(exceptioncode);
    00339     return r;
    00340
    00341 }
    00342
    00343 DOMString Range::toHTML(  )
    00344 {
    00345     if (!impl)
    00346         throw DOMException(DOMException::INVALID_STATE_ERR);
    00347     int exceptioncode = 0;
    00348     DOMString r = impl->toHTML(exceptioncode);
    00349     throwException(exceptioncode);
    00350     return r;
    00351 }
    00352
    00353 DocumentFragment Range::createContextualFragment( const DOMString &html )
    00354 {
    00355     if (!impl)
    00356         throw DOMException(DOMException::INVALID_STATE_ERR);
    00357
    00358     int exceptioncode = 0;
    00359     DocumentFragment r = impl->createContextualFragment(html, exceptioncode);
    00360     throwException(exceptioncode);
    00361     return r;
    00362 }
    00363
    00364
    00365 void Range::detach(  )
    00366 {
    00367     if (!impl)
    00368         throw DOMException(DOMException::INVALID_STATE_ERR);
    00369
    00370     int exceptioncode = 0;
    00371     impl->detach(exceptioncode);
    00372     throwException(exceptioncode);
    00373 }
    00374
    00375 bool Range::isDetached() const
    00376 {
    00377     if (!impl)
    00378         throw DOMException(DOMException::INVALID_STATE_ERR);
    00379
    00380     return impl->isDetached();
    00381 }
    00382
    00383 RangeImpl *Range::handle() const
    00384 {
    00385     return impl;
    00386 }
    00387
    00388 bool Range::isNull() const
    00389 {
    00390     return (impl == 0);
    00391 }
    00392
    00393 void Range::throwException(int exceptioncode) const
    00394 {
    00395     if (!exceptioncode)
    00396         return;
    00397
    00398     // ### also check for CSS & other exceptions?
    00399     if (exceptioncode >= RangeException::_EXCEPTION_OFFSET && exceptioncode <= RangeException::_EXCEPTION_MAX)
    00400         throw RangeException(static_cast<RangeException::RangeExceptionCode>(exceptioncode-RangeException::_EXCEPTION_OFFSET));
    00401     else
    00402         throw DOMException(exceptioncode);
    00403 }
    00404
    00405
    00406

This file is part of the documentation for khtml Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:33:09 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003