khtml Library API Documentation

dom2_range.cpp

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