00001
00002
00003
00004
00005
00006 #include "BluetoothPMPExamplerichtexteditorrte.h"
00007 #include <barsread.h>
00008 #include <BtPmpEx.rsg>
00009 #include <eikrted.h>
00010 #include <txtrich.h>
00011
00012 _LIT(KTextLines, "---------------------------");
00013 #define NEW_TEXT_TO_TOP //If defined the new text will be written to
00014
00015
00016
00017
00018
00019
00020 void CRichTextEditorRTE::ConstructL()
00021 {
00022 TResourceReader reader;
00023
00024
00025 iCoeEnv->CreateResourceReaderLC(reader, R_RICHTEXTEDITOR_RICH_TEXT_EDITOR);
00026
00027 ConstructFromResourceL(reader);
00028
00029 CleanupStack::PopAndDestroy();
00030
00031
00032 SetFocus(ETrue);
00033 }
00034
00035
00036
00037
00038
00039
00040
00041 CRichTextEditorRTE::CRichTextEditorRTE(void)
00042 {
00043 }
00044
00045
00046
00047
00048
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
00065
00066
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
00078 iCharacterFormatMask.SetAttrib(EAttColor);
00079
00080 iCharacterFormat.iFontPresentation.iTextColor = KRgbBlack;
00081
00082 text->InsertL (position, aText);
00083
00084
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
00095 MoveCursorL (TCursorPosition::EFPageUp, EFalse);
00096 #else
00097
00098 MoveCursorL (TCursorPosition::EFPageDown, EFalse);
00099 #endif
00100 }
00101
00102
00103
00104
00105
00106
00107 void CRichTextEditorRTE::DrawTextWithoutCarriageL( const TDesC& aText )
00108 {
00109 CRichText* text = RichText();
00110 TInt textSize = text->DocumentLength();
00111
00112
00113 iCharacterFormatMask.SetAttrib(EAttColor);
00114
00115 iCharacterFormat.iFontPresentation.iTextColor = KRgbBlack;
00116 text->InsertL (textSize, aText);
00117
00118 text->ApplyCharFormatL(iCharacterFormat, iCharacterFormatMask,
00119 textSize,aText.Length());
00120 HandleTextChangedL();
00121 }
00122
00123
00124
00125
00126
00127
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
00144
00145
00146
00147 void CRichTextEditorRTE::DrawLineL()
00148 {
00149 AddTextL( KTextLines );
00150 HandleTextChangedL();
00151 }
00152
00153
00154
00155
00156
00157
00158 CRichTextEditorRTE* CRichTextEditorRTE::NewL()
00159 {
00160 CRichTextEditorRTE* self = CRichTextEditorRTE::NewLC();
00161 CleanupStack::Pop(self);
00162 return self;
00163 }
00164
00165
00166
00167
00168
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
00180
00181
00182
00183
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 }