00001 /* 00002 * Copyright © 2008 Nokia Corporation. 00003 */ 00004 00005 #include <eikrted.h> // CEikRichTextEditor 00006 #include <txtrich.h> // CRichText 00007 00008 #include "SMSExampleRTEContainer.h" 00009 00010 // Rich text editor starting position 00011 #define KEditorPosition TPoint(0,0) 00012 00013 // Number of controls inside this container 00014 const TInt KNumberOfControls = 1; 00015 00016 const TInt KNumberOfLines = 0; 00017 const TInt KTextLimit = 128; 00018 00019 _LIT(KEventLog, "Event log: \n" ); 00020 _LIT(KTextLine, "---------------------------"); 00021 00022 // ---------------------------------------------------------------------------- 00023 // Symbian OS 2 phase constructor. 00024 // ---------------------------------------------------------------------------- 00025 CSMSExampleRTEContainer* CSMSExampleRTEContainer::NewL(const TRect& aRect) 00026 { 00027 CSMSExampleRTEContainer* self = CSMSExampleRTEContainer::NewLC(aRect); 00028 CleanupStack::Pop(self); 00029 return self; 00030 } 00031 00032 // ---------------------------------------------------------------------------- 00033 // Symbian OS 2 phase constructor. 00034 // ---------------------------------------------------------------------------- 00035 CSMSExampleRTEContainer* CSMSExampleRTEContainer::NewLC(const TRect& aRect) 00036 { 00037 CSMSExampleRTEContainer* self = new (ELeave) CSMSExampleRTEContainer(); 00038 CleanupStack::PushL(self); 00039 self->ConstructL(aRect); 00040 return self; 00041 } 00042 00043 // --------------------------------------------------------- 00044 // Symbian OS two phased constructor. 00045 // --------------------------------------------------------- 00046 void CSMSExampleRTEContainer::ConstructL(const TRect& aRect) 00047 { 00048 CreateWindowL(); 00049 00050 iRTE = new (ELeave) CEikRichTextEditor(); 00051 iRTE->SetContainerWindowL(*this); 00052 iRTE->ConstructL(this, KNumberOfLines, KTextLimit, 00053 CEikEdwin::EReadOnly | CEikEdwin::EAvkonDisableCursor, 00054 EGulFontControlAll, EGulNoSymbolFonts); 00055 iRTE->CreateScrollBarFrameL()->SetScrollBarVisibilityL( 00056 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn); 00057 00058 SetRect(aRect); 00059 ActivateL(); 00060 00061 DrawTextL(KEventLog); 00062 } 00063 00064 // ---------------------------------------------------------------------------- 00065 // Destructor. 00066 // ---------------------------------------------------------------------------- 00067 CSMSExampleRTEContainer::~CSMSExampleRTEContainer() 00068 { 00069 delete iRTE; 00070 iRTE = 0; 00071 } 00072 00073 // ---------------------------------------------------------------------------- 00074 // Draw text without drawing a line break at the end. 00075 // ---------------------------------------------------------------------------- 00076 void CSMSExampleRTEContainer::DrawTextWithoutCarriageL(const TDesC& aText) 00077 { 00078 // Set color to black 00079 iCharacterFormatMask.SetAttrib(EAttColor); 00080 iCharacterFormat.iFontPresentation.iTextColor = KRgbBlack; 00081 00082 CRichText* text = iRTE->RichText(); 00083 TInt textSize = text->DocumentLength(); 00084 00085 text->InsertL(textSize, aText); 00086 // Apply formatting 00087 text->ApplyCharFormatL(iCharacterFormat, iCharacterFormatMask, 00088 textSize, aText.Length()); 00089 iRTE->HandleTextChangedL(); 00090 } 00091 00092 // ---------------------------------------------------------------------------- 00093 // Add text using a RichTextEditor 00094 // ---------------------------------------------------------------------------- 00095 void CSMSExampleRTEContainer::DrawTextL(const TDesC& aText) 00096 { 00097 DrawTextWithoutCarriageL(aText); 00098 AddCarriageReturnL(); 00099 iRTE->HandleTextChangedL(); 00100 00101 //Keep displaying the bottom of the screen 00102 iRTE->MoveCursorL(TCursorPosition::EFPageDown, EFalse); 00103 } 00104 00105 // ---------------------------------------------------------------------------- 00106 // Add one line break. 00107 // ---------------------------------------------------------------------------- 00108 void CSMSExampleRTEContainer::AddCarriageReturnL() 00109 { 00110 CRichText* text = iRTE->RichText(); 00111 text->InsertL(text->DocumentLength(), CEditableText::ELineBreak); 00112 } 00113 00114 // ---------------------------------------------------------------------------- 00115 // Draw using a RichtTextEditor. Set Underline off when finished drawing. 00116 // ---------------------------------------------------------------------------- 00117 void CSMSExampleRTEContainer::DrawUnderlinedTextL(const TDesC& aText) 00118 { 00119 iCharacterFormatMask.SetAttrib(EAttFontUnderline); 00120 00121 iCharacterFormat.iFontPresentation.iUnderline = EUnderlineOn; 00122 DrawTextWithoutCarriageL(aText); 00123 iCharacterFormat.iFontPresentation.iUnderline = EUnderlineOff; 00124 } 00125 00126 // ---------------------------------------------------------------------------- 00127 // Draw one line. 00128 // ---------------------------------------------------------------------------- 00129 void CSMSExampleRTEContainer::DrawLineL() 00130 { 00131 DrawTextL(KTextLine); 00132 } 00133 00134 // --------------------------------------------------------- 00135 // Called by framework when the view size is changed 00136 // --------------------------------------------------------- 00137 void CSMSExampleRTEContainer::SizeChanged() 00138 { 00139 TRect rect = Rect(); 00140 TInt scrollbarWidth = GetScrollbarWidth(); 00141 iRTE->SetExtent(KEditorPosition, TSize(rect.Width() - scrollbarWidth, 00142 rect.Height())); 00143 } 00144 00145 // ---------------------------------------------------------------------------- 00146 // Returns the width (breadth) of the scrollbar for the editor 00147 // ---------------------------------------------------------------------------- 00148 TInt CSMSExampleRTEContainer::GetScrollbarWidth() const 00149 { 00150 TInt scrollbarWidth = iRTE->ScrollBarFrame()-> 00151 ScrollBarBreadth(CEikScrollBar::EVertical); 00152 // If scrollbars are not drawn yet, the width remains zero. In this 00153 // case, an intentionally magical number is returned. 00154 if (scrollbarWidth == 0) 00155 { 00156 scrollbarWidth = 8; 00157 } 00158 return scrollbarWidth; 00159 } 00160 00161 TInt CSMSExampleRTEContainer::CountComponentControls() const 00162 { 00163 return KNumberOfControls; 00164 } 00165 00166 CCoeControl* CSMSExampleRTEContainer::ComponentControl(TInt aIndex) const 00167 { 00168 switch (aIndex) 00169 { 00170 case 0: 00171 return iRTE; 00172 default: 00173 return NULL; 00174 } 00175 } 00176 00177 void CSMSExampleRTEContainer::Draw(const TRect& aRect) const 00178 { 00179 CWindowGc& gc = SystemGc(); 00180 gc.SetPenStyle(CGraphicsContext::ENullPen); 00181 gc.SetBrushColor(KRgbWhite); 00182 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); 00183 gc.DrawRect(aRect); 00184 } 00185 00186 TKeyResponse CSMSExampleRTEContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, 00187 TEventCode aType) 00188 { 00189 if (iRTE) 00190 { 00191 return iRTE->OfferKeyEventL(aKeyEvent, aType); 00192 } 00193 else 00194 { 00195 return CCoeControl::OfferKeyEventL(aKeyEvent, aType); 00196 } 00197 } 00198 00199 // End of file
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.