textandlocutils/inlinetext/inc/InlineTextBase.h
changeset 37 6be019398652
equal deleted inserted replaced
32:8b9155204a54 37:6be019398652
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *     Base classes used for holding inline text for the Form MTmInlineTextSource interface.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef INLINETEXTBASE_H
       
    21 #define INLINETEXTBASE_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32std.h>
       
    25 #include <e32base.h>
       
    26 #include <medobsrv.h>
       
    27 #include <inlinetext.h>
       
    28 
       
    29 // CONSTANTS
       
    30 enum TInlineTextPanic
       
    31     {
       
    32     EInlineTextBadInlineTextFetch,
       
    33     EInlineTextStoreCorrupted
       
    34     };
       
    35 
       
    36 #define KInlineTextParagraphDelimiter 0x2029
       
    37 
       
    38 GLREF_C void Panic(TInlineTextPanic aPanic);
       
    39 
       
    40 // CLASS DECLARATION
       
    41 
       
    42 class TTmDocPos;
       
    43 
       
    44 /**
       
    45 * This class is used to hold text that is being formatted into text via the inline text 
       
    46 * interface.
       
    47 *
       
    48 *  @lib InlineText
       
    49 *  @since 3.2
       
    50 */
       
    51 NONSHARABLE_CLASS(CInlineTextPositionedText): public CBase
       
    52     {
       
    53     public: // 2stage constructor and descructor
       
    54     /**
       
    55     * Fully constructs the object given position and text. A copy of the passed-in text is made
       
    56     * on the heap, owned by the constructed object.
       
    57     *
       
    58     * @param    aPosition   TTmDocPos at which text is to be reported
       
    59     * @param    aInlineText Text to be returned at this position
       
    60     *
       
    61     * @return   pointer to fully constructed object
       
    62     */
       
    63     static CInlineTextPositionedText* NewL( const TTmDocPos& aPosition, const TDesC& aInlineText );
       
    64 
       
    65     /**
       
    66     * Destructor
       
    67     */
       
    68     ~CInlineTextPositionedText();
       
    69 
       
    70     public:
       
    71     
       
    72     /**
       
    73     * Access method to the position in the document of the inline text
       
    74     * @return   TTmDocPos of the inline text
       
    75     */
       
    76     const TTmDocPos& DocPos() const;
       
    77 
       
    78     /**
       
    79     * Access method to the text for the inline edit
       
    80     * @return   reference to an unmodifiable descriptor for the text held in this object
       
    81     */
       
    82     const TDesC& InlineText() const;
       
    83 
       
    84     private: 
       
    85     /**
       
    86     * C++ constructor
       
    87     */
       
    88     CInlineTextPositionedText( const TTmDocPos& aPosition );
       
    89     
       
    90     /**
       
    91     * This method completes the construction by allocating the text storage.. 
       
    92     */
       
    93     void ConstructL( const TDesC& aInlineText );
       
    94 
       
    95     private:
       
    96     TTmDocPos iDocPos;
       
    97     HBufC* iText; // owned
       
    98     };
       
    99 
       
   100 /**
       
   101 * Class to hold an array of inline texts for access
       
   102 *
       
   103 *  @lib InlineText
       
   104 *  @since 3.2
       
   105 */
       
   106 NONSHARABLE_CLASS(CInlineTextStore) : public CArrayPtrFlat<CInlineTextPositionedText>
       
   107     {
       
   108      public: // 2-stage constructor and destructor
       
   109         static CInlineTextStore* NewL();     
       
   110         ~CInlineTextStore();
       
   111 
       
   112     public:
       
   113         /**
       
   114         * Clears and destroys all inline texts
       
   115         */
       
   116         void Clear();
       
   117 
       
   118         /**
       
   119         * Clears and destroys inline texts in a range of document positions. Range is taken
       
   120         * to be inclusive.
       
   121         * @param    aStart  First position from which and including inline texts are removed
       
   122         * @param    aEnd    Final position up to which and including inline texts are removed
       
   123         */
       
   124         void ClearRange( const TTmDocPos& aStart, const TTmDocPos& aEnd );
       
   125 
       
   126         /**
       
   127         * Insert the inline text object into the store
       
   128         * @param    aInlineText     object to add
       
   129         */
       
   130         void InsertInlineTextL( CInlineTextPositionedText* aInlineText );
       
   131 
       
   132         /**
       
   133         * Returns the pointer to the document position closest after or including the passed-in
       
   134         * position.
       
   135         * @param    aDocPos     position from which to look for inline texts
       
   136         * @return               pointer to document position at or closest after input position 
       
   137         *                       NULL if none is found
       
   138         */
       
   139         const TTmDocPos* NextInlineTextDocPos( const TTmDocPos& aDocPos ) const;
       
   140 
       
   141         /**
       
   142         * Searches for the input document position and returns the index in the Store
       
   143         * @param    aDocPos     input document position
       
   144         * @return               index at which the input position is found
       
   145         *                       -1 if the document position is not in the store
       
   146         */
       
   147         TInt IndexFromDocPos( const TTmDocPos& aDocPos ) const;
       
   148 
       
   149     private: 
       
   150         /**
       
   151         * Private constructor; no derivation permitted
       
   152         */
       
   153         CInlineTextStore();
       
   154 
       
   155         /**
       
   156         * Internal method for determining index of the position later or including
       
   157         * the passed-in position
       
   158         */
       
   159         TInt NextIndexStartingAtDocPos( const TTmDocPos& aDocPos ) const;
       
   160 
       
   161     private: // data members
       
   162 
       
   163     };
       
   164 
       
   165 /**
       
   166 * Concrete implementation of MTmInlineTextSource, adding an edit observation interface
       
   167 * and common infrastructure for managing inline texts
       
   168 * 
       
   169 *  @lib InlineText
       
   170 *  @since 3.2
       
   171 */
       
   172 NONSHARABLE_CLASS(CInlineTextSource) : public CBase, public MTmInlineTextSource, public MEditObserver
       
   173     {
       
   174     public: // C++ constructor and destructor
       
   175         CInlineTextSource(); // Class is intended for derivation
       
   176         ~CInlineTextSource();
       
   177 
       
   178         /** 
       
   179         * 2nd state constructor
       
   180         */
       
   181         void ConstructL();
       
   182 
       
   183     public: // From MTmInlineTextSource
       
   184 
       
   185 	/**
       
   186     * Reports the next position into which inline text should be inserted
       
   187     *
       
   188     * See inlinetext.h
       
   189 	*/
       
   190 	virtual TInt GetNextInlineTextPosition(const TTmDocPos& aFrom, TInt aMaxLength, TTmDocPos& aNext);
       
   191 
       
   192 	/**
       
   193 	* Gets a view of the text to be inserted at aAt.
       
   194     * 
       
   195     * See inlinetext.h
       
   196 	*/
       
   197 	virtual TPtrC GetInlineText(const TTmDocPos& aAt);
       
   198 
       
   199     public: // From MEditObserver
       
   200 
       
   201     /**
       
   202     * See medobsrv.h
       
   203     * 
       
   204     * This class implements an empty implementation of this method. Implement in subclass only if 
       
   205     * action is to be taken upon edit - and if edit event is actually going to be supplied, which
       
   206     * is only available in the context of CEikRichTextEditor
       
   207     */
       
   208 	virtual void EditObserver(TInt aStart, TInt aExtent);
       
   209 
       
   210     public:
       
   211     // New methods
       
   212 
       
   213     /**
       
   214     * Framework method to inform subclasses what part of the document is currently being interrogated
       
   215     * for inline edits.
       
   216     * Currently this will be where formatting is performed and the store of inline texts updated.
       
   217     * (In future, an edit observer interface of some kind will be used to trigger that)
       
   218     *
       
   219     * @param aFrom  position from which to re-consider the formatting
       
   220     * @param aTo    position up to which to re-consider the formatting
       
   221     */
       
   222     virtual void CheckFormattingL(const TTmDocPos& aFrom, const TTmDocPos& aTo );
       
   223 
       
   224     /**
       
   225     * Non-virtual method for checking for inline text.  Similar behaviour to GetInlineText, except 
       
   226     * that is it const, and will not panic (but just return EFalse) if there is no inline text
       
   227     * at the input TTmDocPos.
       
   228     * 
       
   229     * @param aAt        Position at which to access inline text
       
   230     * @param aPtrFound  This contains the inline text if ETrue is returned
       
   231     * @return       EFalse if there is no inline text at the input position
       
   232     */
       
   233     TBool HasInlineTextAt( const TTmDocPos& aAt, TPtrC& aPtrFound ) const;
       
   234 
       
   235     protected:
       
   236 
       
   237     /**
       
   238     * Access to the inline text store for derived classes
       
   239     */
       
   240     CInlineTextStore* InlineTextStore() const;
       
   241     
       
   242     private:
       
   243     CInlineTextStore* iInlineTextStore; // owned
       
   244     };
       
   245 
       
   246 #endif
       
   247 
       
   248 // End of File