javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/inc/swtconstrainedtext.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 SWTCONSTRAINEDTEXT_H
       
    14 #define SWTCONSTRAINEDTEXT_H
       
    15 
       
    16 
       
    17 #include <coecntrl.h>
       
    18 #include <eikedwob.h>
       
    19 #include "eswtmobileextensions.h"
       
    20 #include "swttextbase.h"
       
    21 
       
    22 
       
    23 /**
       
    24  * CSwtConstrainedText
       
    25  * @lib eswt
       
    26  */
       
    27 NONSHARABLE_CLASS(CSwtConstrainedText)
       
    28         : public CSwtTextBase
       
    29         , public MSwtConstrainedText
       
    30         , public MEikEdwinObserver
       
    31 {
       
    32 public:
       
    33     /**
       
    34       * 1st phase constructor.
       
    35       * @param aDisplay parent display
       
    36       * @param aPeer java peer
       
    37       * @param aParen composite parent
       
    38       * @param aStyle supported styles
       
    39       */
       
    40     static CSwtConstrainedText* NewL(MSwtDisplay& aDisplay, TSwtPeer aPeer,
       
    41     MSwtComposite& aParent, TInt aStyle);
       
    42 
       
    43 private:
       
    44     /**
       
    45      * Default C++ constructor.
       
    46      * @param aDisplay parent display
       
    47      * @param aPeer java peer
       
    48      * @param aParen composite parent
       
    49      * @param aStyle supported styles
       
    50      */
       
    51     inline CSwtConstrainedText(MSwtDisplay& aDisplay, TSwtPeer aPeer,
       
    52                                MSwtComposite& aParent, TInt aStyle);
       
    53 
       
    54     /**
       
    55      * Destructor.
       
    56      */
       
    57     ~CSwtConstrainedText();
       
    58 
       
    59     /**
       
    60      * Checks Navigation key.
       
    61      * @param aKeyEvent type of key event
       
    62      * @return navigation key
       
    63      */
       
    64     TBool IsNavigationKey(const TKeyEvent& aKeyEvent) const;
       
    65 
       
    66     /**
       
    67      * Checks Hot key.
       
    68      * @param aKeyEvent type of key event
       
    69      * @return one of CEikEdwin::TEdwinHotKeys or -1 if cannot translate.
       
    70      */
       
    71     TBool IsHotKeyL(const TKeyEvent& aKeyEvent) const;
       
    72 
       
    73     /**
       
    74     * Checks the content will remain valid if the specified text replaces
       
    75     * the given range
       
    76     * @param aStart starting point of the text
       
    77     * @param aEnd ending point of the text
       
    78     * @param aText Text to replace
       
    79     * @return KErrNone for valid text else KErrArgument
       
    80     */
       
    81     TInt LooseCheckReplacementL(TInt aStart, TInt aEnd, const TDesC& aText) const;
       
    82 
       
    83     /**
       
    84      * Checks the content will remain valid if the specified character replaces
       
    85      * the given range.
       
    86      * @param aStart starting point of the character
       
    87      * @param aEnd ending point of the character
       
    88      * @param aChar character to replace
       
    89      * @return KErrNone for valid character else KErrArgument
       
    90      */
       
    91     TInt LooseCheckReplacementL(TInt aStart, TInt aEnd, TInt aChar) const;
       
    92 
       
    93     /**
       
    94      * Checks the content will remain valid if the specified text replaces
       
    95      * the current selection.
       
    96      * @param text to be replaced
       
    97      * @return KErrNone for valid character else KErrArgument
       
    98      */
       
    99     TInt StrictCheckReplacementL(const TDesC& aText) const;
       
   100 
       
   101     /**
       
   102      * Checks the content will remain valid if the specified text replaces
       
   103      * the given range.
       
   104      * @param aStart starting point of the text
       
   105      * @param aEnd ending point of the text
       
   106      * @param aText Text to replace
       
   107      * @return KErrNone for valid text else KErrArgument
       
   108      */
       
   109     TInt CheckReplacementL(TInt aStart, TInt aEnd, const TDesC& aText,
       
   110                            TBool aStrict) const;
       
   111 
       
   112     /**
       
   113      * Checks whether a given text is an acceptable for all styles
       
   114      * @param text to be validate
       
   115      * @return KErrNone for valid text else KErrArgument
       
   116      */
       
   117     TInt LooseValidateText(const TDesC& aText) const;
       
   118 
       
   119     /**
       
   120      * Strick Checks whether a given text is an acceptable for all styles
       
   121      * @param text to be validate
       
   122      * @return KErrNone for valid text else KErrArgument
       
   123      */
       
   124     TInt StrictValidateText(const TDesC& aText) const;
       
   125 
       
   126     /**
       
   127      * Checks whether a given text is an acceptable Numeric.
       
   128      * It must be made of digits only and an optional leading minus sign.
       
   129      * If the maximum text size is 1, then no minus sign is allowed.
       
   130      * @param text to be validate
       
   131      * @return KErrNone for valid text else KErrArgument
       
   132      */
       
   133     TInt LooseValidateNumeric(const TDesC& aText) const;
       
   134 
       
   135     /**
       
   136      *  Strict version of the NUMERIC check. Same as the loose one except a "-" is
       
   137      *  no longer accepted.
       
   138      *  @param aText text to be validate
       
   139      *  @return KErrNone for valid text else KErrArgument
       
   140      */
       
   141     TInt StrictValidateNumeric(const TDesC& aText) const;
       
   142 
       
   143     /**
       
   144      * Checks whether a text is an acceptable DECIMAL. It consists of an
       
   145      * optional minus sign '-', followed by one or more whole-number
       
   146      * decimal digits, followed by an optional fraction separator,
       
   147      * followed by zero or more decimal fraction digits. The whole-number
       
   148      * decimal digits may be omitted if the fraction separator and one or
       
   149      * more decimal fraction digits are present.
       
   150      * @param text to be validate
       
   151      * @return KErrNone for valid text else KErrArgument
       
   152      */
       
   153     TInt LooseValidateDecimal(const TDesC& aText) const;
       
   154 
       
   155     /**
       
   156      * Strict version of the DECIMAL check. Same as the loose one except "-", "."
       
   157      * and "-." are no longer accepted.
       
   158      * @param text to be validate
       
   159      * @return KErrNone for valid text else KErrArgument
       
   160      */
       
   161     TInt StrictValidateDecimal(const TDesC& aText) const;
       
   162 
       
   163     /**
       
   164      * Checks if a character is acceptable in a phone number
       
   165      * @param aAllowedChars one of the other allowed chars
       
   166      * @param aChar character to be validate@return returns valid phone Number
       
   167      * @return returns valid phone Number
       
   168      */
       
   169     static TBool IsPhoneNumberChar(const TChar &aChar, const TDesC& aAllowedChars);
       
   170 
       
   171     /**
       
   172      * Checks if a text is a correct PHONENUMBER. it contains only
       
   173      * allowed characters, no syntax checking.
       
   174      * @param aText text to be validate
       
   175      * @return KErrNone for valid text else KErrArgument
       
   176      */
       
   177     static TInt  ValidatePhoneNumber(const TDesC& aText);
       
   178 
       
   179     /**
       
   180      * Convertes '.' or any decimal seperator to localised decimal seperator
       
   181      * @param aText text or text which containes decimal seperator to convert localised
       
   182      * @return HBufC* converted text for localised decimal seperator
       
   183      */
       
   184     HBufC* ConvertToLocalizedDecimalLC(const TDesC& aText);
       
   185 
       
   186     /**
       
   187      * Convertes local decimal seperator to '.'
       
   188      * @param aText text or text which containes local decimal seperator to convert '.'
       
   189      * @return void nothing to return.
       
   190      */
       
   191     void ConvertFromLocalizedDecimal(HBufC* buf) const;
       
   192 
       
   193 // From CCoeControl
       
   194 public:
       
   195     TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
       
   196 
       
   197 // From CCoeControl
       
   198 protected:
       
   199     void Draw(const TRect& aRect) const;
       
   200 
       
   201 // From MSwtControl
       
   202 public:
       
   203     void ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
       
   204 
       
   205 // From MSwtConstrainedText
       
   206 public:
       
   207     MSwtControl* Control();
       
   208     void  SetConstraintL(TConstraint aConstraint);
       
   209     HBufC* GetTextL() const;
       
   210     TBool SetTextL(const TDesC& aText);
       
   211     TBool AppendL(const TDesC& aText);
       
   212     TBool InsertL(const TDesC& aText);
       
   213     TInt  GetCharCount() const;
       
   214     TBool SetTextLimitL(TInt aLimit);
       
   215     TInt  GetCaretPosition() const;
       
   216     void  SetSelectionL(TInt aStart, TInt aEnd);
       
   217     void  ClearSelectionL();
       
   218     void  SelectAllL();
       
   219     void  ShowSelectionL();
       
   220     TBool CutL();
       
   221     void  CopyL();
       
   222     TBool PasteL();
       
   223     TBool GetEditable() const;
       
   224     void  SetEditable(TBool aEditable);
       
   225 
       
   226 // From MEikEdwinObserver
       
   227 public:
       
   228     void HandleEdwinEventL(
       
   229         CEikEdwin *aEdwin,
       
   230         TEdwinEvent aEventType);
       
   231 // Data
       
   232 private:
       
   233     /**
       
   234      * The styles of the ConstrainedText
       
   235      */
       
   236     TConstraint iConstraint;
       
   237 
       
   238     /**
       
   239      * Text Limit of the Editor
       
   240      */
       
   241     TInt iTextLimit;
       
   242 
       
   243     /**
       
   244      * Rectangle of the Editor
       
   245      */
       
   246     TRect iRect;
       
   247     /**
       
   248      * For Localised decimal seperator
       
   249      */
       
   250     TChar iDecimalSeparator;
       
   251 
       
   252     /**
       
   253      * Last view visible rectangle.
       
   254      */
       
   255     mutable TRect iLastViewVisibleRect;
       
   256 };
       
   257 
       
   258 
       
   259 #endif // SWTCONSTRAINEDTEXT_H