Main Page   Class Hierarchy   Compound List   File List   Compound Members  

RangeImpl.hpp

00001 #ifndef RangeImpl_HEADER_GUARD_
00002 #define RangeImpl_HEADER_GUARD_
00003 /*
00004  * The Apache Software License, Version 1.1
00005  *
00006  * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
00007  * reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  *
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in
00018  *    the documentation and/or other materials provided with the
00019  *    distribution.
00020  *
00021  * 3. The end-user documentation included with the redistribution,
00022  *    if any, must include the following acknowledgment:
00023  *       "This product includes software developed by the
00024  *        Apache Software Foundation (http://www.apache.org/)."
00025  *    Alternately, this acknowledgment may appear in the software itself,
00026  *    if and wherever such third-party acknowledgments normally appear.
00027  *
00028  * 4. The names "Xerces" and "Apache Software Foundation" must
00029  *    not be used to endorse or promote products derived from this
00030  *    software without prior written permission. For written
00031  *    permission, please contact apache\@apache.org.
00032  *
00033  * 5. Products derived from this software may not be called "Apache",
00034  *    nor may "Apache" appear in their name, without prior written
00035  *    permission of the Apache Software Foundation.
00036  *
00037  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00038  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00039  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00040  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00041  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00042  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00043  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00044  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00045  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00046  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00047  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00048  * SUCH DAMAGE.
00049  * ====================================================================
00050  *
00051  * This software consists of voluntary contributions made by many
00052  * individuals on behalf of the Apache Software Foundation, and was
00053  * originally based on software copyright (c) 1999, International
00054  * Business Machines, Inc., http://www.ibm.com .  For more information
00055  * on the Apache Software Foundation, please see
00056  * <http://www.apache.org/>.
00057  */
00058 
00059  /*
00060  * $Id: RangeImpl.hpp,v 1.1 2002/05/11 19:57:48 bhavani Exp $
00061  */
00062 
00063 
00064 
00065 #include "DOM_Node.hpp"
00066 #include "RefCountedImpl.hpp"
00067 #include "DOM_Range.hpp"
00068 #include "DOM_Text.hpp"
00069 #include "DOM_Document.hpp"
00070 #include <xercesc/util/RefVectorOf.hpp>
00071 
00072 
00073 typedef RefVectorOf<RangeImpl> Ranges;
00074  
00075 class CDOM_EXPORT RangeImpl : public RefCountedImpl {
00076 public:    
00077     //c'tor
00078     RangeImpl(DOM_Document doc);
00079     RangeImpl(const RangeImpl& other);
00080 
00081     //d'tor
00082     ~RangeImpl();
00083 
00084     //referencing related functions
00085     virtual void                unreferenced();
00086     
00087 
00088     //getter functions
00089     DOM_Node    getStartContainer() const;
00090     unsigned    int getStartOffset() const;
00091     DOM_Node    getEndContainer() const;
00092     unsigned int getEndOffset() const;
00093     
00094     
00095     
00096     void        collapse(bool toStart);
00097     bool        getCollapsed() const;
00098 
00099     void        setStartBefore(const DOM_Node& node);
00100     void        setStartAfter(const DOM_Node& node);
00101     void        setEndBefore(const DOM_Node& node);
00102     void        setEndAfter(const DOM_Node& node);
00103 
00104     void        setStart(const DOM_Node& node, unsigned int offset);
00105     void        setEnd(const DOM_Node& node, unsigned int offset);
00106 
00107     void        selectNode(const DOM_Node& node);
00108     void        selectNodeContents(const DOM_Node& node);
00109    
00110     short       compareBoundaryPoints(DOM_Range::CompareHow how, RangeImpl* range) const;
00111    
00112     void        detach();
00113    
00114     void        deleteContents();
00115     
00116     RangeImpl*  cloneRange() const;
00117     DOMString   toString() const;    
00118 
00119     DOM_Document getDocument();
00120     void        surroundContents(DOM_Node& node);
00121     DOM_DocumentFragment extractContents();
00122     DOM_DocumentFragment cloneContents() const;
00123     void        insertNode(DOM_Node& newNode);
00124     const DOM_Node    getCommonAncestorContainer() const;
00125 
00126     // functions to inform all existing valid ranges about a change
00127     void updateSplitInfo(TextImpl* oldNode, TextImpl* startNode, unsigned int offset);
00128     void updateRangeForInsertedNode(NodeImpl* node);
00129     void receiveReplacedText(NodeImpl* node);
00130     void updateRangeForDeletedText(DOM_Node& node, unsigned int offset, int count);
00131     void updateRangeForDeletedNode(NodeImpl* node);
00132 
00133 private:
00134     enum TraversalType {
00135         EXTRACT_CONTENTS = 1,
00136         CLONE_CONTENTS   = 2,
00137         DELETE_CONTENTS  = 3
00138     };
00139 
00140     enum TraversePoint {
00141         BEFORE  = -1,    
00142         START   = 0,
00143         AFTER   = 1
00144     };
00145 
00146     //setter functions
00147     void        setStartContainer(const DOM_Node& node); 
00148     void        setStartOffset(unsigned int offset) ;
00149     void        setEndContainer(const DOM_Node& node);
00150     void        setEndOffset(unsigned int offset) ;
00151 
00152     //misc functions
00153     void        validateNode(const DOM_Node& node) const;
00154     bool        isValidAncestorType(const DOM_Node& node) const; 
00155     bool        hasLegalRootContainer(const DOM_Node& node) const;
00156     bool        isLegalContainedNode(const DOM_Node& node ) const;
00157     void        checkIndex(const DOM_Node& node, unsigned int offset) const;
00158     static bool isAncestorOf(const DOM_Node& a, const DOM_Node& b);
00159     
00160     unsigned short indexOf(const DOM_Node& child, const DOM_Node& parent) const;
00161 
00162     const DOM_Node    commonAncestorOf(const DOM_Node& pointA, const DOM_Node& pointB) const;
00163     DOM_Node    nextNode(const DOM_Node& node, bool visitChildren) const;
00164     DOM_DocumentFragment traverseContents(TraversalType type);
00165     void        checkReadOnly(DOM_Node& start, DOM_Node& end, 
00166                     unsigned int starOffset, unsigned int endOffset);
00167     void        recurseTreeAndCheck(DOM_Node& start, DOM_Node& end);
00168     DOM_Node    removeChild(DOM_Node& parent, DOM_Node& child);
00169 
00170     DOM_DocumentFragment traverseSameContainer( int how );
00171     DOM_DocumentFragment traverseCommonStartContainer( DOM_Node endAncestor, int how );
00172     DOM_DocumentFragment traverseCommonEndContainer( DOM_Node startAncestor, int how );
00173     DOM_DocumentFragment traverseCommonAncestors( DOM_Node startAncestor, DOM_Node endAncestor, int how );
00174     DOM_Node    traverseRightBoundary( DOM_Node root, int how );
00175     DOM_Node    traverseLeftBoundary( DOM_Node root, int how );
00176     DOM_Node    traverseNode( DOM_Node n, bool isFullySelected, bool isLeft, int how );
00177     DOM_Node    traverseFullySelected( DOM_Node n, int how );
00178     DOM_Node    traversePartiallySelected( DOM_Node n, int how );
00179     DOM_Node    traverseTextNode( DOM_Node n, bool isLeft, int how );
00180     DOM_Node    getSelectedNode( DOM_Node container, int offset );
00181 
00182    
00183     //private data 
00184     DOM_Node        fStartContainer;
00185     unsigned int    fStartOffset;
00186     DOM_Node        fEndContainer;
00187     unsigned int    fEndOffset;
00188     bool            fCollapsed;
00189     DOM_Document    fDocument;
00190     bool            fDetached;
00191     
00192     DOM_Node        fRemoveChild;
00193     
00194 };
00195 
00196 #endif

Generated on Tue Nov 19 09:36:32 2002 by doxygen1.3-rc1