• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdehtml
 

tdehtml

  • tdehtml
  • dom
dom2_range.cpp
1 
26 #include "dom/dom_exception.h"
27 #include "xml/dom_docimpl.h"
28 #include "xml/dom2_rangeimpl.h"
29 
30 using namespace DOM;
31 
32 Range::Range()
33 {
34  // a range can't exist by itself - it must be associated with a document
35  impl = 0;
36 }
37 
38 Range::Range(const Document rootContainer)
39 {
40  if(rootContainer.handle())
41  {
42  impl = new RangeImpl(rootContainer.handle()->docPtr());
43  impl->ref();
44  }
45  else
46  impl = 0;
47 }
48 
49 Range::Range(const Range &other)
50 {
51  impl = other.impl;
52  if (impl) impl->ref();
53 }
54 
55 Range::Range(const Node startContainer, const long startOffset, const Node endContainer, const long endOffset)
56 {
57  if (startContainer.isNull() || endContainer.isNull()) {
58  throw DOMException(DOMException::NOT_FOUND_ERR);
59  }
60 
61  if (!startContainer.handle()->getDocument() ||
62  startContainer.handle()->getDocument() != endContainer.handle()->getDocument()) {
63  throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
64  }
65 
66  impl = new RangeImpl(startContainer.handle()->docPtr(),startContainer.handle(),startOffset,endContainer.handle(),endOffset);
67  impl->ref();
68 }
69 
70 Range::Range(RangeImpl *i)
71 {
72  impl = i;
73  if (impl) impl->ref();
74 }
75 
76 Range &Range::operator = (const Range &other)
77 {
78  if ( impl != other.impl ) {
79  if (impl) impl->deref();
80  impl = other.impl;
81  if (impl) impl->ref();
82  }
83  return *this;
84 }
85 
86 Range::~Range()
87 {
88  if (impl) impl->deref();
89 }
90 
91 Node Range::startContainer() const
92 {
93  if (!impl)
94  throw DOMException(DOMException::INVALID_STATE_ERR);
95 
96  int exceptioncode = 0;
97  NodeImpl *r = impl->startContainer(exceptioncode);
98  throwException(exceptioncode);
99  return r;
100 }
101 
102 long Range::startOffset() const
103 {
104  if (!impl)
105  throw DOMException(DOMException::INVALID_STATE_ERR);
106 
107  int exceptioncode = 0;
108  long r = impl->startOffset(exceptioncode);
109  throwException(exceptioncode);
110  return r;
111 
112 }
113 
114 Node Range::endContainer() const
115 {
116  if (!impl)
117  throw DOMException(DOMException::INVALID_STATE_ERR);
118 
119  int exceptioncode = 0;
120  NodeImpl *r = impl->endContainer(exceptioncode);
121  throwException(exceptioncode);
122  return r;
123 }
124 
125 long Range::endOffset() const
126 {
127  if (!impl)
128  throw DOMException(DOMException::INVALID_STATE_ERR);
129 
130  int exceptioncode = 0;
131  long r = impl->endOffset(exceptioncode);
132  throwException(exceptioncode);
133  return r;
134 }
135 
136 bool Range::collapsed() const
137 {
138  if (!impl)
139  throw DOMException(DOMException::INVALID_STATE_ERR);
140 
141  int exceptioncode = 0;
142  bool r = impl->collapsed(exceptioncode);
143  throwException(exceptioncode);
144  return r;
145 }
146 
147 Node Range::commonAncestorContainer()
148 {
149  if (!impl)
150  throw DOMException(DOMException::INVALID_STATE_ERR);
151 
152  int exceptioncode = 0;
153  NodeImpl *r = impl->commonAncestorContainer(exceptioncode);
154  throwException(exceptioncode);
155  return r;
156 }
157 
158 void Range::setStart( const Node &refNode, long offset )
159 {
160  if (!impl)
161  throw DOMException(DOMException::INVALID_STATE_ERR);
162 
163  int exceptioncode = 0;
164  impl->setStart(refNode.handle(),offset,exceptioncode);
165  throwException(exceptioncode);
166 }
167 
168 void Range::setEnd( const Node &refNode, long offset )
169 {
170  if (!impl)
171  throw DOMException(DOMException::INVALID_STATE_ERR);
172 
173  int exceptioncode = 0;
174  impl->setEnd(refNode.handle(),offset,exceptioncode);
175  throwException(exceptioncode);
176 }
177 
178 void Range::setStartBefore( const Node &refNode )
179 {
180  if (!impl)
181  throw DOMException(DOMException::INVALID_STATE_ERR);
182 
183 
184  int exceptioncode = 0;
185  impl->setStartBefore(refNode.handle(),exceptioncode);
186  throwException(exceptioncode);
187 }
188 
189 void Range::setStartAfter( const Node &refNode )
190 {
191  if (!impl)
192  throw DOMException(DOMException::INVALID_STATE_ERR);
193 
194  int exceptioncode = 0;
195  impl->setStartAfter(refNode.handle(),exceptioncode);
196  throwException(exceptioncode);
197 }
198 
199 void Range::setEndBefore( const Node &refNode )
200 {
201  if (!impl)
202  throw DOMException(DOMException::INVALID_STATE_ERR);
203 
204  int exceptioncode = 0;
205  impl->setEndBefore(refNode.handle(),exceptioncode);
206  throwException(exceptioncode);
207 }
208 
209 void Range::setEndAfter( const Node &refNode )
210 {
211  if (!impl)
212  throw DOMException(DOMException::INVALID_STATE_ERR);
213 
214  int exceptioncode = 0;
215  impl->setEndAfter(refNode.handle(),exceptioncode);
216  throwException(exceptioncode);
217 }
218 
219 void Range::collapse( bool toStart )
220 {
221  if (!impl)
222  throw DOMException(DOMException::INVALID_STATE_ERR);
223 
224  int exceptioncode = 0;
225  impl->collapse(toStart,exceptioncode);
226  throwException(exceptioncode);
227 }
228 
229 void Range::selectNode( const Node &refNode )
230 {
231  if (!impl)
232  throw DOMException(DOMException::INVALID_STATE_ERR);
233 
234  int exceptioncode = 0;
235  impl->selectNode(refNode.handle(),exceptioncode);
236  throwException(exceptioncode);
237 }
238 
239 void Range::selectNodeContents( const Node &refNode )
240 {
241  if (!impl)
242  throw DOMException(DOMException::INVALID_STATE_ERR);
243 
244  int exceptioncode = 0;
245  impl->selectNodeContents(refNode.handle(),exceptioncode);
246  throwException(exceptioncode);
247 }
248 
249 short Range::compareBoundaryPoints( CompareHow how, const Range &sourceRange )
250 {
251  if (!impl)
252  throw DOMException(DOMException::INVALID_STATE_ERR);
253 
254  int exceptioncode = 0;
255  short r = impl->compareBoundaryPoints(how,sourceRange.handle(),exceptioncode);
256  throwException(exceptioncode);
257  return r;
258 }
259 
260 bool Range::boundaryPointsValid( )
261 {
262  if (!impl)
263  throw DOMException(DOMException::INVALID_STATE_ERR);
264 
265  return impl->boundaryPointsValid();
266 }
267 
268 void Range::deleteContents( )
269 {
270  if (!impl)
271  throw DOMException(DOMException::INVALID_STATE_ERR);
272 
273  int exceptioncode = 0;
274  impl->deleteContents(exceptioncode);
275  throwException(exceptioncode);
276 }
277 
278 DocumentFragment Range::extractContents( )
279 {
280  if (!impl)
281  throw DOMException(DOMException::INVALID_STATE_ERR);
282 
283  int exceptioncode = 0;
284  DocumentFragmentImpl *r = impl->extractContents(exceptioncode);
285  throwException(exceptioncode);
286  return r;
287 }
288 
289 DocumentFragment Range::cloneContents( )
290 {
291  if (!impl)
292  throw DOMException(DOMException::INVALID_STATE_ERR);
293 
294  int exceptioncode = 0;
295  DocumentFragmentImpl *r = impl->cloneContents(exceptioncode);
296  throwException(exceptioncode);
297  return r;
298 }
299 
300 void Range::insertNode( const Node &newNode )
301 {
302  if (!impl)
303  throw DOMException(DOMException::INVALID_STATE_ERR);
304 
305  int exceptioncode = 0;
306  impl->insertNode(newNode.handle(),exceptioncode);
307  throwException(exceptioncode);
308 }
309 
310 void Range::surroundContents( const Node &newParent )
311 {
312  if (!impl)
313  throw DOMException(DOMException::INVALID_STATE_ERR);
314 
315  int exceptioncode = 0;
316  impl->surroundContents(newParent.handle(),exceptioncode);
317  throwException(exceptioncode);
318 }
319 
320 Range Range::cloneRange( )
321 {
322  if (!impl)
323  throw DOMException(DOMException::INVALID_STATE_ERR);
324 
325  int exceptioncode = 0;
326  RangeImpl *r = impl->cloneRange(exceptioncode);
327  throwException(exceptioncode);
328  return r;
329 }
330 
331 DOMString Range::toString( )
332 {
333  if (!impl)
334  throw DOMException(DOMException::INVALID_STATE_ERR);
335 
336  int exceptioncode = 0;
337  DOMString r = impl->toString(exceptioncode);
338  throwException(exceptioncode);
339  return r;
340 
341 }
342 
343 DOMString Range::toHTML( )
344 {
345  if (!impl)
346  throw DOMException(DOMException::INVALID_STATE_ERR);
347  int exceptioncode = 0;
348  DOMString r = impl->toHTML(exceptioncode);
349  throwException(exceptioncode);
350  return r;
351 }
352 
353 DocumentFragment Range::createContextualFragment( const DOMString &html )
354 {
355  if (!impl)
356  throw DOMException(DOMException::INVALID_STATE_ERR);
357 
358  int exceptioncode = 0;
359  DocumentFragment r = impl->createContextualFragment(html, exceptioncode);
360  throwException(exceptioncode);
361  return r;
362 }
363 
364 
365 void Range::detach( )
366 {
367  if (!impl)
368  throw DOMException(DOMException::INVALID_STATE_ERR);
369 
370  int exceptioncode = 0;
371  impl->detach(exceptioncode);
372  throwException(exceptioncode);
373 }
374 
375 bool Range::isDetached() const
376 {
377  if (!impl)
378  throw DOMException(DOMException::INVALID_STATE_ERR);
379 
380  return impl->isDetached();
381 }
382 
383 RangeImpl *Range::handle() const
384 {
385  return impl;
386 }
387 
388 bool Range::isNull() const
389 {
390  return (impl == 0);
391 }
392 
393 void Range::throwException(int exceptioncode) const
394 {
395  if (!exceptioncode)
396  return;
397 
398  // ### also check for CSS & other exceptions?
399  if (exceptioncode >= RangeException::_EXCEPTION_OFFSET && exceptioncode <= RangeException::_EXCEPTION_MAX)
400  throw RangeException(static_cast<RangeException::RangeExceptionCode>(exceptioncode-RangeException::_EXCEPTION_OFFSET));
401  else
402  throw DOMException(exceptioncode);
403 }
404 
405 
406 
DOM::DOMException
DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impos...
Definition: dom_exception.h:58
DOM::DOMString
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
DOM::DocumentFragment
DocumentFragment is a "lightweight" or "minimal" Document object.
Definition: dom_doc.h:992
DOM::Document
The Document interface represents the entire HTML or XML document.
Definition: dom_doc.h:246
DOM::Node
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:275
DOM::Node::isNull
bool isNull() const
tests if this Node is 0.
Definition: dom_node.h:892
DOM
The Document Object Model (DOM) is divided into two parts, the COREDOM core DOM, specifying some core...
Definition: design.h:57

tdehtml

Skip menu "tdehtml"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdehtml

Skip menu "tdehtml"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdehtml by doxygen 1.9.1
This website is maintained by Timothy Pearson.