1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
3 * |
|
4 * This library is free software; you can redistribute it and/or |
|
5 * modify it under the terms of the GNU Lesser General Public |
|
6 * License as published by the Free Software Foundation; either |
|
7 * version 2 of the License, or (at your option) any later version. |
|
8 * |
|
9 * This library is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 * Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public |
|
15 * License along with this library; if not, write to the |
|
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
17 * Boston, MA 02111-1307, USA. |
|
18 * |
|
19 * Description: |
|
20 * |
|
21 */ |
|
22 /* |
|
23 * ============================================================================ |
|
24 * Name : RichTextEditorRTE.cpp |
|
25 * Part of : VoIP test application. |
|
26 * Description : Utility for outputting formatted text to the display. |
|
27 * Version : %version: 2 % |
|
28 * ============================================================================ |
|
29 */ |
|
30 |
|
31 // INCLUDES |
|
32 #include <barsread.h> // TResourceReader |
|
33 #include <eikrted.h> // CEikRichTextEditor |
|
34 #include <txtrich.h> // CRichText |
|
35 #include <gstplayer.rsg> |
|
36 #include "RichTextEditor.h" |
|
37 |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // CRichTextEditorRTE::NewL |
|
41 // Symbian constructor. |
|
42 // ---------------------------------------------------------------------------- |
|
43 // |
|
44 CRichTextEditorRTE* CRichTextEditorRTE::NewL(const CCoeControl& aView) |
|
45 { |
|
46 CRichTextEditorRTE* self = CRichTextEditorRTE::NewLC(aView); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // CRichTextEditorRTE::NewLC |
|
53 // Symbian constructor with self pointer pushed into cleanup stack. |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 CRichTextEditorRTE* CRichTextEditorRTE::NewLC(const CCoeControl& aView) |
|
57 { |
|
58 CRichTextEditorRTE* self = new (ELeave) CRichTextEditorRTE; |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(aView); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CRichTextEditorRTE::ConstructL |
|
66 // Standard EPOC 2nd phase constructor |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CRichTextEditorRTE::ConstructL(const CCoeControl& aView) |
|
70 { |
|
71 TResourceReader reader; |
|
72 // Construct RichTextEditor from resource |
|
73 iCoeEnv->CreateResourceReaderLC(reader, R_RICHTEXTEDITOR_RICH_TEXT_EDITOR); |
|
74 SetContainerWindowL(aView); |
|
75 ConstructFromResourceL(reader); |
|
76 CleanupStack::PopAndDestroy(); //reader |
|
77 // Sets that the control has keyboard focus |
|
78 SetFocus(ETrue); |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // CRichTextEditorRTE::CRichTextEditorRTE |
|
83 // constructor |
|
84 // ---------------------------------------------------------------------------- |
|
85 // |
|
86 CRichTextEditorRTE::CRichTextEditorRTE(void) |
|
87 { |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // CRichTextEditorRTE::AddCarriageReturnL |
|
92 // Insert one line break at the end of the text. |
|
93 // ---------------------------------------------------------------------------- |
|
94 // |
|
95 void CRichTextEditorRTE::AddCarriageReturnL() |
|
96 { |
|
97 CRichText* text = RichText(); |
|
98 TInt len = text->DocumentLength(); |
|
99 text->InsertL(len, CEditableText::ELineBreak); |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // CRichTextEditorRTE::AddTextL |
|
104 // Draws text using selected color. |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 void CRichTextEditorRTE::AddTextL(const TDesC& aText, TRgb aRgb) |
|
108 { |
|
109 CRichText* text = RichText(); |
|
110 TInt len = text->DocumentLength(); |
|
111 |
|
112 // Interested in color |
|
113 iCharacterFormatMask.SetAttrib(EAttColor); |
|
114 // Set it to Black |
|
115 iCharacterFormat.iFontPresentation.iTextColor = aRgb; |
|
116 text->InsertL(len, aText); |
|
117 // Apply formatting |
|
118 text->ApplyCharFormatL(iCharacterFormat, |
|
119 iCharacterFormatMask, |
|
120 len, |
|
121 aText.Length()); |
|
122 AddCarriageReturnL(); |
|
123 HandleTextChangedL(); |
|
124 |
|
125 // Scroll pages to always display at the bottom of the screen |
|
126 for (TInt i = len + aText.Length(); (i / 50) > 1; i -= 50) |
|
127 { |
|
128 MoveCursorL(TCursorPosition::EFPageDown, EFalse); |
|
129 } |
|
130 } |
|
131 |
|
132 // ---------------------------------------------------------------------------- |
|
133 // TKeyResponse CRichTextEditorRTE::OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
134 // TEventCode aType) |
|
135 // |
|
136 // Called by the framework whenever a key event occurs. Handles scrolling |
|
137 // events. |
|
138 // ---------------------------------------------------------------------------- |
|
139 TKeyResponse CRichTextEditorRTE::OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
140 TEventCode aType) |
|
141 { |
|
142 if (aType == EEventKey) |
|
143 { |
|
144 if (aKeyEvent.iCode == EKeyDownArrow) |
|
145 { |
|
146 MoveCursorL (TCursorPosition::EFPageDown, EFalse); |
|
147 |
|
148 return EKeyWasConsumed; |
|
149 } |
|
150 else if (aKeyEvent.iCode == EKeyUpArrow) |
|
151 { |
|
152 MoveCursorL (TCursorPosition::EFPageUp, EFalse); |
|
153 |
|
154 return EKeyWasConsumed; |
|
155 } |
|
156 else |
|
157 { |
|
158 return CEikRichTextEditor::OfferKeyEventL(aKeyEvent, aType); |
|
159 } |
|
160 } |
|
161 |
|
162 return EKeyWasNotConsumed; |
|
163 } |
|
164 |
|
165 // End of file |
|