javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/inc/swttext.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - S60 implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 
       
    13 #ifndef SWTTEXT_H
       
    14 #define SWTTEXT_H
       
    15 
       
    16 
       
    17 #include <txtglobl.h>
       
    18 #include <eikedwob.h>
       
    19 #include "swttextbase.h"
       
    20 
       
    21 
       
    22 /**
       
    23  * CSwtText
       
    24  * @lib eswt
       
    25  */
       
    26 NONSHARABLE_CLASS(CSwtText)
       
    27         : public CSwtTextBase
       
    28         , public MSwtText
       
    29         , public MSwtVerifyEventObserver
       
    30         , public MEikEdwinObserver
       
    31 {
       
    32 private:
       
    33     class CPasswordText;
       
    34 
       
    35 public:
       
    36     /**
       
    37      * Two phase constructor.
       
    38      * @param aDisplay parent display
       
    39      * @param aPeer java peer
       
    40      * @param aParen composite parent
       
    41      * @param aStyle supported styles
       
    42      */
       
    43     static CSwtText* NewL(
       
    44         MSwtDisplay& aDisplay,
       
    45         TSwtPeer aPeer,
       
    46         MSwtComposite& aParent,
       
    47         TInt aStyle);
       
    48 
       
    49 protected:
       
    50     /**
       
    51      * First phase constructor.
       
    52      * @param aDisplay parent display
       
    53      * @param aPeer java peer
       
    54      * @param aParen composite parent
       
    55      * @param aStyle supported styles
       
    56      */
       
    57     inline CSwtText(
       
    58         MSwtDisplay& aDisplay,
       
    59         TSwtPeer aPeer,
       
    60         MSwtComposite& aParent,
       
    61         TInt aStyle);
       
    62 
       
    63     /**
       
    64      * Destructor.
       
    65      */
       
    66     ~CSwtText();
       
    67 
       
    68     /**
       
    69      * Second phase constructor.
       
    70      */
       
    71     void ConstructL();
       
    72 
       
    73     /**
       
    74      * Compute alignment based on the control's style.
       
    75      * @return computed alignment.
       
    76      */
       
    77     CParaFormat::TAlignment ComputeAlignment() const;
       
    78 
       
    79     /**
       
    80      * Set alignment base on the control's style.
       
    81      */
       
    82     void SetAlignmentL();
       
    83 
       
    84     /**
       
    85      * Process line brakes based on style.
       
    86      * Length of the processed string might change.
       
    87      * @param aText string to be processed.
       
    88      */
       
    89     void ProcessLineBrakes(TDes& aText) const;
       
    90 
       
    91     /**
       
    92      * Remove anything beyound the first line brake.
       
    93      * Length of the processed string might change.
       
    94      * @param aText string to be processed.
       
    95      */
       
    96     static void CropToFirstLine(TDes& aText);
       
    97 
       
    98     /**
       
    99      * Replace legacy ASCII line brakes with Unicode ones.
       
   100      * Length of the processed string might change.
       
   101      * @param aText string to be processed.
       
   102      */
       
   103     static void ConvertToUnicodeBreaks(TDes& aText);
       
   104 
       
   105     /**
       
   106      * Post a Verify event with string.
       
   107      * @param aStart start of selection.
       
   108      * @param aEnd end of selection.
       
   109      * @param aText string to be inserted.
       
   110      */
       
   111     virtual void PostVerifyEventL(
       
   112         TInt aStart,
       
   113         TInt aEnd,
       
   114         TDes& aText);
       
   115 
       
   116     /**
       
   117      * Post Verify event with char.
       
   118      * @param aStart start of selection.
       
   119      * @param aEnd end of selection.
       
   120      * @param aChar char to be inserted.
       
   121      */
       
   122     void PostVerifyEventL(
       
   123         TInt aStart,
       
   124         TInt aEnd,
       
   125         TInt aChar);
       
   126 
       
   127     /**
       
   128      * Send char to the editor in the form of a key event.
       
   129      * param aChar char to be sent.
       
   130      */
       
   131     void SendCharacterL(TText aChar);
       
   132 
       
   133 // From CSwtTextBase
       
   134 public:
       
   135     void HandleResourceChange(TInt aType);
       
   136 
       
   137 // From CCoeControl
       
   138 public:
       
   139     void SizeChanged();
       
   140     TKeyResponse OfferKeyEventL(
       
   141         const TKeyEvent& aKeyEvent,
       
   142         TEventCode aType);
       
   143 
       
   144 // From CCoeControl
       
   145 protected:
       
   146     void Draw(const TRect& aRect) const;
       
   147 
       
   148 // From MSwtControl
       
   149 public:
       
   150     void ProcessKeyEventL(
       
   151         const TKeyEvent& aKeyEvent,
       
   152         TEventCode aType);
       
   153 
       
   154 // From MSwtText
       
   155 public:
       
   156     MSwtScrollable* Scrollable();
       
   157     HBufC* GetTextL() const;
       
   158     HBufC* GetTextRangeL(TInt aStart, TInt aEnd) const;
       
   159     TBool SetTextL(TDes& aText);
       
   160     TBool AppendL(TDes& aText);
       
   161     TBool InsertL(TDes& aText);
       
   162     TInt GetCharCount() const;
       
   163     TBool SetTextLimitL(TInt aLimit);
       
   164     TInt GetCaretLineNumber() const;
       
   165     TPoint GetCaretLocationL() const;
       
   166     TInt GetCaretPosition() const;
       
   167     TPoint GetSelection() const;
       
   168     HBufC* GetSelectionTextL() const;
       
   169     void SetSelectionL(TInt aStart, TInt aEnd);
       
   170     void ClearSelectionL();
       
   171     void SelectAllL();
       
   172     void ShowSelectionL();
       
   173     //TBool CutL();
       
   174     void CopyL();
       
   175     TBool PasteL();
       
   176     TBool GetEditable() const;
       
   177     void SetEditable(TBool aEditable);
       
   178     TInt GetLineCount() const;
       
   179     TInt GetLineHeightL() const;
       
   180     TInt GetTopIndexL() const;
       
   181     void SetTopIndexL(TInt aIndex);
       
   182     TInt GetTopPixelL() const;
       
   183     TText GetEchoChar() const;
       
   184     void SetEchoCharL(TText aEcho);
       
   185     void SetDoubleClickEnabled(TBool aEnabled);
       
   186     TInt GetOrientation() const;
       
   187     void SetOrientationL(TInt aOrientation);
       
   188 
       
   189 // From MSwtVerifyEventObserver
       
   190 public:
       
   191     void ProcessVerifiedTextL(
       
   192         TInt aStart,
       
   193         TInt aEnd,
       
   194         TDes& aText);
       
   195 
       
   196 // From MEikEdwinObserver
       
   197 public:
       
   198     void HandleEdwinEventL(
       
   199         CEikEdwin *aEdwin,
       
   200         TEdwinEvent aEventType);
       
   201 
       
   202     void SetVisibleScrollBar(TInt aStyle, TBool aVisible);
       
   203 // Data
       
   204 private:
       
   205     /**
       
   206      * Maximum length of the text.
       
   207      */
       
   208     TInt iTextLimit;
       
   209 
       
   210     /**
       
   211      * The word to post to a Java Verify event
       
   212      */
       
   213     //RBuf iBufferToVerify;
       
   214 
       
   215     /**
       
   216      * Last view visible rectangle.
       
   217      */
       
   218     mutable TRect iLastViewVisibleRect;
       
   219 };
       
   220 
       
   221 
       
   222 inline CSwtText::CSwtText(
       
   223     MSwtDisplay& aDisplay,
       
   224     TSwtPeer aPeer,
       
   225     MSwtComposite& aParent,
       
   226     TInt aStyle)
       
   227         : CSwtTextBase(aDisplay, aPeer, aParent, aStyle)
       
   228 {
       
   229 }
       
   230 
       
   231 NONSHARABLE_CLASS(CSwtText::CPasswordText)
       
   232         : public CGlobalText
       
   233 {
       
   234 public:
       
   235     static CPasswordText* NewL(
       
   236         const CParaFormatLayer* aParaLayer,
       
   237         const CCharFormatLayer* aCharLayer,
       
   238         CEikEdwin* aEditor,
       
   239         TBool aPaswdEnable);
       
   240 
       
   241     ~CPasswordText();
       
   242 private:
       
   243     inline CPasswordText(
       
   244         const CParaFormatLayer* aParaLayer,
       
   245         const CCharFormatLayer* aCharLayer,
       
   246         CEikEdwin* aEdwin,
       
   247         TBool aPaswdEnable);
       
   248     void ConstructL();
       
   249     static TInt TimerCallback(TAny* aThis);
       
   250     void DoTimerCallbackL(TBool aNotifyFormat);
       
   251     void SaveClearTextL(TInt aPos, const TDesC& aBuf);
       
   252 
       
   253 // From CGlobalText
       
   254 public:
       
   255     void Reset();
       
   256     void InsertL(TInt aPos, const TChar& aChar);
       
   257     void InsertL(TInt aPos, const TDesC& aBuf) ;
       
   258     TBool DeleteL(TInt aPos, TInt aLength);
       
   259     TInt PasteFromStoreL(const CStreamStore& aStore,
       
   260                          const CStreamDictionary& aDictionary,
       
   261                          TInt aPos);
       
   262     void CopyToStoreL(CStreamStore& aStore,
       
   263                       CStreamDictionary& aDictionary,
       
   264                       TInt aPos,
       
   265                       TInt aLength) const;
       
   266     void Extract(TDes& aBuf, TInt aPos = 0) const;
       
   267     void Extract(TDes& aBuf, TInt aPos, TInt aLength) const;
       
   268     void SetEchoCharL();
       
   269 
       
   270 // Data
       
   271 public:
       
   272     TText iEchoChar;
       
   273 private:
       
   274 
       
   275     // The timer used to show the temporary clear character
       
   276     CPeriodic* iTimer;
       
   277 
       
   278     // A reference to the text editor that owns us
       
   279     CEikEdwin* iEditor;
       
   280 
       
   281     // The position of the temporary clear character
       
   282     TInt iClearCharPos;
       
   283 
       
   284     // The clear text
       
   285     HBufC* iClearText;
       
   286 
       
   287     // checking for password text or not
       
   288     TBool iPswdEnable;
       
   289 };
       
   290 
       
   291 #endif // SWTTEXT_H