examples/ForumNokia/BluetoothPMPExample/src/BluetoothPMPExampleRichTextEditorRTE.cpp

00001 /*
00002  * Copyright © 2009 Nokia Corporation.
00003  */
00004 
00005 // INCLUDES
00006 #include "BluetoothPMPExamplerichtexteditorrte.h"
00007 #include <barsread.h> // TResourceReader
00008 #include <BtPmpEx.rsg> // resources
00009 #include <eikrted.h> // CEikRichTextEditor
00010 #include <txtrich.h> // CRichText
00011 
00012 _LIT(KTextLines, "---------------------------");
00013 #define NEW_TEXT_TO_TOP //If defined the new text will be written to
00014                         //the top of the container
00015 // ----------------------------------------------------------------------------
00016 // CRichTextEditorRTE::CRichTextEditorRTE(void)
00017 //
00018 // Standard symbian OS 2nd phase constructor
00019 // ----------------------------------------------------------------------------
00020 void CRichTextEditorRTE::ConstructL()
00021     {
00022     TResourceReader reader;
00023 
00024     // Construct RichTextEditor from resource
00025     iCoeEnv->CreateResourceReaderLC(reader, R_RICHTEXTEDITOR_RICH_TEXT_EDITOR);
00026 
00027     ConstructFromResourceL(reader);
00028 
00029     CleanupStack::PopAndDestroy(); // reader
00030 
00031     // Sets that the control has keyboard focus
00032     SetFocus(ETrue);
00033     }
00034 
00035 
00036 // ----------------------------------------------------------------------------
00037 // CRichTextEditorRTE::CRichTextEditorRTE(void)
00038 //
00039 // Constructor
00040 // ----------------------------------------------------------------------------
00041 CRichTextEditorRTE::CRichTextEditorRTE(void)
00042     {
00043     }
00044 
00045 // ----------------------------------------------------------------------------
00046 // CRichTextEditorRTE::AddCarriageReturnL()
00047 //
00048 // Insert one line break at the end of the text.
00049 // ----------------------------------------------------------------------------
00050 void CRichTextEditorRTE::AddCarriageReturnL(TInt pos)
00051     {
00052     CRichText* richText = RichText();
00053     TInt carriagePosition = pos;
00054     if(pos == KCarriageReturnToEnd)
00055         {
00056         carriagePosition = richText->DocumentLength();
00057         }
00058 
00059     richText->InsertL(carriagePosition, CEditableText::ELineBreak);
00060     }
00061 
00062 
00063 // ----------------------------------------------------------------------------
00064 // CRichTextEditorRTE::AddTextL(const TDesC& aText)
00065 //
00066 // Draws text using black color.
00067 // ----------------------------------------------------------------------------
00068 void CRichTextEditorRTE::AddTextL(const TDesC& aText)
00069     {
00070     CRichText* text = RichText();
00071     TInt textSize = text->DocumentLength();
00072     TInt position = textSize;
00073     #ifdef NEW_TEXT_TO_TOP
00074         position = 0;
00075     #endif
00076 
00077     // Interested in color
00078     iCharacterFormatMask.SetAttrib(EAttColor);
00079     // Set it to Black
00080     iCharacterFormat.iFontPresentation.iTextColor = KRgbBlack;
00081     
00082     text->InsertL (position, aText);
00083 
00084     // Apply formatting
00085     text->ApplyCharFormatL(iCharacterFormat, iCharacterFormatMask,
00086                            position,aText.Length());
00087 
00088     AddCarriageReturnL(position);
00089 
00090     HandleTextChangedL();
00091 
00092 
00093     #ifdef NEW_TEXT_TO_TOP
00094         //Keep displaying the top of the screen
00095         MoveCursorL (TCursorPosition::EFPageUp, EFalse);
00096     #else
00097         //Keep displaying the bottom of the screen
00098         MoveCursorL (TCursorPosition::EFPageDown, EFalse);
00099     #endif    
00100     }
00101 
00102 // ----------------------------------------------------------------------------
00103 // CRichTextEditorRTE::DrawTextWithoutCarriageL( const TDesC& aText )
00104 //
00105 // Draw text without adding one line break at the end of the text.
00106 // ----------------------------------------------------------------------------
00107 void CRichTextEditorRTE::DrawTextWithoutCarriageL( const TDesC& aText )
00108     {
00109     CRichText* text = RichText();
00110     TInt textSize = text->DocumentLength();
00111 
00112     // Interested in color
00113     iCharacterFormatMask.SetAttrib(EAttColor);
00114     // Set it to Black
00115     iCharacterFormat.iFontPresentation.iTextColor = KRgbBlack;
00116     text->InsertL (textSize, aText);
00117     // Apply formatting
00118     text->ApplyCharFormatL(iCharacterFormat, iCharacterFormatMask,
00119                            textSize,aText.Length());
00120     HandleTextChangedL();
00121     }
00122 
00123 
00124 // ----------------------------------------------------------------------------
00125 // CRichTextEditorRTE::DrawTextWithoutCarriageL( const TDesC& aText )
00126 //
00127 //  Sets underline on or off.  This will be applied to text added in AddTextL()
00128 // ----------------------------------------------------------------------------
00129 void CRichTextEditorRTE::SetTextUnderlineOn(TBool aUnderlineOn)
00130     {
00131     iCharacterFormatMask.SetAttrib(EAttFontUnderline);
00132     if (aUnderlineOn)
00133         {
00134         iCharacterFormat.iFontPresentation.iUnderline = EUnderlineOn;
00135         }
00136     else
00137         {
00138         iCharacterFormat.iFontPresentation.iUnderline = EUnderlineOff;
00139         }
00140     }
00141 
00142 // ----------------------------------------------------------------------------
00143 // CRichTextEditorRTE::DrawLineL()
00144 //
00145 // Draw one line.
00146 // ----------------------------------------------------------------------------
00147 void CRichTextEditorRTE::DrawLineL()
00148     {
00149     AddTextL( KTextLines );
00150     HandleTextChangedL();
00151     }
00152 
00153 // ----------------------------------------------------------------------------
00154 // CRichTextEditorRTE::NewL()
00155 //
00156 // Symbian OS 2nd phase constructor.
00157 // ----------------------------------------------------------------------------
00158 CRichTextEditorRTE* CRichTextEditorRTE::NewL()
00159     {
00160     CRichTextEditorRTE* self = CRichTextEditorRTE::NewLC();
00161     CleanupStack::Pop(self);
00162     return self;
00163     }
00164 
00165 // ----------------------------------------------------------------------------
00166 // CRichTextEditorRTE::NewLC()
00167 //
00168 // Symbian OS 2nd phase constructor.
00169 // ----------------------------------------------------------------------------
00170 CRichTextEditorRTE* CRichTextEditorRTE::NewLC()
00171     {
00172     CRichTextEditorRTE* self = new (ELeave) CRichTextEditorRTE;
00173     CleanupStack::PushL(self);
00174     self->ConstructL();
00175     return self;
00176     }
00177 
00178 // ----------------------------------------------------------------------------
00179 // TKeyResponse CRichTextEditorRTE::OfferKeyEventL(const TKeyEvent& aKeyEvent,
00180 //      TEventCode aType)
00181 //
00182 // Called by the framework whenever a key event occurs. Handles scrolling
00183 // events.
00184 // ----------------------------------------------------------------------------
00185 TKeyResponse CRichTextEditorRTE::OfferKeyEventL(const TKeyEvent& aKeyEvent,
00186                                                 TEventCode aType)
00187     {
00188 
00189     if (aType == EEventKey)
00190         {
00191         if (aKeyEvent.iCode == EKeyDownArrow)
00192             {
00193             MoveCursorL (TCursorPosition::EFPageDown, EFalse);
00194 
00195             return EKeyWasConsumed;
00196             }
00197         else if (aKeyEvent.iCode == EKeyUpArrow)
00198             {
00199             MoveCursorL (TCursorPosition::EFPageUp, EFalse);
00200 
00201             return EKeyWasConsumed;
00202             }
00203         else
00204             {
00205             return CEikRichTextEditor::OfferKeyEventL(aKeyEvent, aType);
00206             }
00207         }
00208 
00209     return EKeyWasNotConsumed;
00210     }
00211 
00212 void CRichTextEditorRTE::ClearScreenL()
00213     {
00214     CRichText* text = RichText();
00215     text->DeleteL(0, text->DocumentLength() );
00216     HandleTextChangedL();
00217     }

Generated by  doxygen 1.6.2