|
1 // guicons.h |
|
2 // |
|
3 // Copyright (c) 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #ifndef __GUICONS_H__ |
|
14 #define __GUICONS_H__ |
|
15 |
|
16 #include <coecntrl.h> |
|
17 #include <e32cons.h> |
|
18 #include <fshell/consoleproxy.h> |
|
19 #include <fshell/consoleextensions.h> |
|
20 |
|
21 static const TInt KFontBitmapWidthChars = 8; |
|
22 static const TInt KFontBitmapHeightChars = 12; |
|
23 static const TInt KFontBitmapFirstCharCode = ' '; |
|
24 static const TInt KNumGlyphs = KFontBitmapWidthChars * KFontBitmapHeightChars; |
|
25 static const TInt KFontBitmapLastCharCode = KFontBitmapFirstCharCode + KNumGlyphs - 1; |
|
26 static const TInt KDefaultCursorHeightPercentage = 20; |
|
27 static const TInt KTabSize = 4; |
|
28 static const TInt KNumColors = 16; |
|
29 |
|
30 class CConsoleControl; |
|
31 class CConsoleLine; |
|
32 class CConsoleFont; |
|
33 class MGuiConsoleReader; |
|
34 class MConsoleUi; |
|
35 class TBufferPosition; |
|
36 class TConsCursorPosition; |
|
37 class TViewPosition; |
|
38 class CImageDecoder; |
|
39 class RImageDecodeThreadParams; |
|
40 |
|
41 IMPORT_C CServer2* StartGuiConsServerL(const TDesC& aServerName, MConsoleUi& aConsoleUi); |
|
42 |
|
43 class MConsoleUi |
|
44 { |
|
45 public: |
|
46 virtual void HandleNewConsoleL(CConsoleControl* aConsole) = 0; |
|
47 virtual void HandleConsoleClosed(CConsoleControl* aConsole) = 0; |
|
48 virtual void ConsoleTitleChangedL(const CConsoleControl*, const TDesC&){}; |
|
49 virtual TInt GetConsoleBufferSize() = 0; |
|
50 virtual const TDesC& GetConsoleFont() = 0; |
|
51 }; |
|
52 |
|
53 /** |
|
54 Position relative to the text buffer. The cursor window and view window will be somewhere within this. |
|
55 */ |
|
56 class TBufferPosition |
|
57 { |
|
58 public: |
|
59 TBufferPosition(const CConsoleControl& aConsole, TPoint aPosition); |
|
60 TBufferPosition(const CConsoleControl& aConsole, TInt aX, TInt aY); |
|
61 TBufferPosition(const TConsCursorPosition& aCursorPosition); |
|
62 TBufferPosition(const TViewPosition& aViewPosition); |
|
63 public: |
|
64 const CConsoleControl& iConsole; |
|
65 TPoint iPoint; |
|
66 }; |
|
67 |
|
68 /** |
|
69 Position relative to the cursor window - i.e. the area that the cursor can move around in |
|
70 */ |
|
71 class TConsCursorPosition |
|
72 { |
|
73 public: |
|
74 TConsCursorPosition(const CConsoleControl& aConsole, TPoint aPosition); |
|
75 TConsCursorPosition(const CConsoleControl& aConsole, TInt aX, TInt aY); |
|
76 TConsCursorPosition(const TBufferPosition& aBufferPosition); |
|
77 TConsCursorPosition(const TViewPosition& aViewPosition); |
|
78 public: |
|
79 const CConsoleControl& iConsole; |
|
80 TPoint iPoint; |
|
81 }; |
|
82 |
|
83 /** |
|
84 Position relative to the view window - i.e. the area of the console seen on the screen |
|
85 */ |
|
86 class TViewPosition |
|
87 { |
|
88 public: |
|
89 TViewPosition(const CConsoleControl& aConsole, TPoint aPosition); |
|
90 TViewPosition(const CConsoleControl& aConsole, TInt aX, TInt aY); |
|
91 TViewPosition(const TConsCursorPosition& aCursorPosition); |
|
92 TViewPosition(const TBufferPosition& aBufferPosition); |
|
93 public: |
|
94 const CConsoleControl& iConsole; |
|
95 TPoint iPoint; |
|
96 }; |
|
97 |
|
98 /** |
|
99 Position in pixels relative to CConsoleControl's rectangle. |
|
100 */ |
|
101 class TScreenPosition |
|
102 { |
|
103 public: |
|
104 TScreenPosition(const CConsoleControl& aConsole, TPoint aPosition); |
|
105 TScreenPosition(const CConsoleControl& aConsole, TInt aX, TInt aY); |
|
106 TScreenPosition(const TViewPosition& aViewPosition); |
|
107 public: |
|
108 const CConsoleControl& iConsole; |
|
109 TPoint iPoint; |
|
110 }; |
|
111 |
|
112 class TConsoleCursor |
|
113 { |
|
114 public: |
|
115 TConsoleCursor(CConsoleControl& aOwner); |
|
116 void SetFont(const CConsoleFont& aFont); |
|
117 TConsCursorPosition Position() const; |
|
118 void SetPosAbs(TConsCursorPosition aPos); |
|
119 void SetPosRel(TConsCursorPosition aPos); |
|
120 void SetHeight(TInt aPercentage); |
|
121 |
|
122 void Hide(); |
|
123 |
|
124 void operator++(int); |
|
125 void operator--(int); |
|
126 void operator+=(TUint aHowMuch); |
|
127 void operator-=(TUint aHowMuch); |
|
128 void Down(); |
|
129 void Up(); |
|
130 |
|
131 void Update(); |
|
132 private: |
|
133 void BoundsCheck(); |
|
134 private: |
|
135 CConsoleControl& iOwner; |
|
136 TSize iGlyphSize; |
|
137 TPoint iPosition; |
|
138 TTextCursor iTextCursor; |
|
139 TInt iTextCursorOffset; |
|
140 }; |
|
141 |
|
142 class MGuiConsoleReader |
|
143 { |
|
144 public: |
|
145 virtual void ReadComplete(TInt aStatus) = 0; |
|
146 }; |
|
147 |
|
148 class CGuiConsole : public CConsoleBase |
|
149 , public MGuiConsoleReader |
|
150 , public MProxiedConsole |
|
151 { |
|
152 public: |
|
153 IMPORT_C CGuiConsole(CConsoleControl& aControl); |
|
154 |
|
155 IMPORT_C CConsoleControl& Control(); |
|
156 |
|
157 // from CConsoleBase |
|
158 IMPORT_C virtual TInt Create(const TDesC &aTitle,TSize aSize); |
|
159 IMPORT_C virtual void Read(TRequestStatus& aStatus); |
|
160 IMPORT_C virtual void ReadCancel(); |
|
161 IMPORT_C virtual void Write(const TDesC &aDes); |
|
162 IMPORT_C virtual TPoint CursorPos() const; |
|
163 IMPORT_C virtual void SetCursorPosAbs(const TPoint &aPoint); |
|
164 IMPORT_C virtual void SetCursorPosRel(const TPoint &aPoint); |
|
165 IMPORT_C virtual void SetCursorHeight(TInt aPercentage); |
|
166 IMPORT_C virtual void SetTitle(const TDesC &aTitle); |
|
167 IMPORT_C virtual void ClearScreen(); |
|
168 IMPORT_C virtual void ClearToEndOfLine(); |
|
169 IMPORT_C virtual TSize ScreenSize() const; |
|
170 IMPORT_C virtual TKeyCode KeyCode() const; |
|
171 IMPORT_C virtual TUint KeyModifiers() const; |
|
172 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); |
|
173 |
|
174 // from MGuiConsoleReader |
|
175 virtual void ReadComplete(TInt aStatus); |
|
176 // from MProxiedConsole: |
|
177 virtual void Open(); |
|
178 virtual void Close(); |
|
179 virtual CConsoleBase* Console(); |
|
180 virtual void Read(CConsoleProxySession& aSession); |
|
181 private: |
|
182 ~CGuiConsole(); |
|
183 private: |
|
184 CConsoleControl& iControl; |
|
185 TInt iRefCount; |
|
186 TRequestStatus* iReadStatus; |
|
187 CConsoleProxySession* iReader; |
|
188 }; |
|
189 |
|
190 class CConsoleControl : public CCoeControl |
|
191 { |
|
192 public: |
|
193 IMPORT_C static CConsoleControl* NewL(TInt aBufferSize, MConsoleUi* aUi = NULL); |
|
194 IMPORT_C static CConsoleControl* NewL(TInt aBufferSize, const TDesC& aFontFile, MConsoleUi* aUi = NULL); |
|
195 IMPORT_C virtual ~CConsoleControl(); |
|
196 IMPORT_C void Closed(); |
|
197 |
|
198 IMPORT_C void InjectKeysL(const TDesC& aKeys); |
|
199 IMPORT_C TBool FivewayNavIsDisplaying() const; |
|
200 IMPORT_C void SetDisplayFivewayNav(TBool aShow); |
|
201 |
|
202 // from CCoeControl: |
|
203 IMPORT_C virtual void Draw(const TRect& aRect) const; |
|
204 IMPORT_C virtual void SizeChanged(); |
|
205 IMPORT_C virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType); |
|
206 IMPORT_C virtual TCoeInputCapabilities InputCapabilities() const; |
|
207 IMPORT_C virtual void FocusChanged(TDrawNow aDrawNow); |
|
208 IMPORT_C virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent); |
|
209 |
|
210 // CConsoleBase API |
|
211 IMPORT_C void Read(MGuiConsoleReader &aStatus); |
|
212 IMPORT_C void ReadCancel(); |
|
213 IMPORT_C void Write(const TDesC &aDes); |
|
214 IMPORT_C TPoint CursorPos() const; |
|
215 IMPORT_C void SetCursorPosAbs(const TPoint &aPoint); |
|
216 IMPORT_C void SetCursorPosRel(const TPoint &aPoint); |
|
217 IMPORT_C void SetCursorHeight(TInt aPercentage); |
|
218 IMPORT_C void SetTitle(const TDesC &aTitle); |
|
219 IMPORT_C void ClearScreen(); |
|
220 IMPORT_C void ClearToEndOfLine(); |
|
221 IMPORT_C TSize ScreenSize() const; |
|
222 IMPORT_C TKeyCode KeyCode() const; |
|
223 IMPORT_C TUint KeyModifiers() const; |
|
224 |
|
225 IMPORT_C void ViewScrollUp(); |
|
226 IMPORT_C void ViewScrollDown(); |
|
227 IMPORT_C void ViewPageUp(); |
|
228 IMPORT_C void ViewPageDown(); |
|
229 IMPORT_C void ViewHome(); |
|
230 IMPORT_C void ViewEnd(); |
|
231 IMPORT_C TInt SetAttributes(TUint aAttributes, ConsoleAttributes::TColor aForegroundColor, ConsoleAttributes::TColor aBackgroundColor); |
|
232 |
|
233 // calls from CConsoleCursor: |
|
234 void CursorWindowScrollDown(); |
|
235 |
|
236 TPoint ViewPosition() const; |
|
237 TPoint CursorWindowPosition() const; |
|
238 TSize GlyphSize() const; |
|
239 void ActivateL(); |
|
240 void StartBlinking(); |
|
241 |
|
242 private: |
|
243 CConsoleControl(MConsoleUi* aUi, TInt aBufferSize); |
|
244 void ConstructL(CConsoleFont* aFont); |
|
245 void SizeChangedL(); |
|
246 |
|
247 void DrawLine(TViewPosition aLine, CBitmapContext& aDrawTo) const; |
|
248 TRect LineRect(TViewPosition aLine) const; |
|
249 |
|
250 TBool IsSpecialChar(TChar aChar) const; |
|
251 void HandleSpecialChar(TChar aChar); |
|
252 |
|
253 void SendKey(); |
|
254 |
|
255 CConsoleLine* GetLine(TBufferPosition aLine) const; |
|
256 void ViewMoved(); |
|
257 void Invalidate5Way(); |
|
258 enum TButton { EUp, EDown, ELeft, ERight, ECenter, ENumButtons }; |
|
259 void SimulateKeyL(TButton aButton); |
|
260 void WriteL(const TDesC &aDes); |
|
261 |
|
262 static TInt BlinkCallback(TAny* aPtr); |
|
263 |
|
264 private: |
|
265 MConsoleUi* iUi; |
|
266 CConsoleFont* iFont; |
|
267 RPointerArray<CConsoleLine> iBuffer; |
|
268 CPeriodic* iBlinkTimer; |
|
269 TSize iSizeChars; |
|
270 TConsoleCursor iCursor; |
|
271 TPoint iCursorWindow; |
|
272 TPoint iViewWindow; |
|
273 |
|
274 MGuiConsoleReader* iReader; |
|
275 RArray<TKeyEvent> iKeyQueue; |
|
276 TKeyEvent iCurrentKey; |
|
277 |
|
278 TPoint iDragStart; |
|
279 TBool iIgnoringDrags; |
|
280 |
|
281 TRect iButtonRects[ENumButtons]; |
|
282 TBool iDrawNavigator; |
|
283 ConsoleAttributes::TAttributes iCurrentAttributes; |
|
284 |
|
285 TInt iBufferSize; |
|
286 TBool iBlinkOn; |
|
287 }; |
|
288 |
|
289 class CConsoleFont : public CBase |
|
290 { |
|
291 public: |
|
292 IMPORT_C static CConsoleFont* NewL(const TDesC& aFontFile); |
|
293 IMPORT_C static CConsoleFont* NewL(const TDesC8& aEncodedFontImage); |
|
294 IMPORT_C ~CConsoleFont(); |
|
295 IMPORT_C TSize GlyphSize() const; |
|
296 IMPORT_C void DrawChar(TChar aChar, CBitmapContext& aDrawTo, TPoint aPosPixels, TRgb aColor); |
|
297 void PrepareForegroundColorL(TRgb aColor); |
|
298 private: |
|
299 CConsoleFont(); |
|
300 void ConstructL(const TDesC& aFontFile); |
|
301 void ConstructL(const TDesC8& aEncodedFontImage); |
|
302 void ConstructL(RImageDecodeThreadParams& aThreadParams); |
|
303 CFbsBitmap* ForegroundBitmap(TRgb aColor); |
|
304 private: |
|
305 TFixedArray<CFbsBitmap*, KNumGlyphs> iChars; |
|
306 TFixedArray<CFbsBitmap*, KNumColors> iColors; |
|
307 TRect iGlyphRect; |
|
308 }; |
|
309 |
|
310 class RAttributeMap |
|
311 { |
|
312 public: |
|
313 RAttributeMap(); |
|
314 void Close(); |
|
315 void Reset(); |
|
316 void AddL(TInt aPosition, TInt aLineWidth, const ConsoleAttributes::TAttributes& aAttributes); |
|
317 void RemoveFrom(TInt aPosition); |
|
318 TInt NumberOfBlocks() const; |
|
319 void GetBlock(TInt aIndex, TInt aLineWidth, TInt& aStartPosition, TInt& aEndPosition, ConsoleAttributes::TAttributes& aAttributes) const; |
|
320 private: |
|
321 class TAttributes |
|
322 { |
|
323 public: |
|
324 TAttributes(TInt aPosition, const ConsoleAttributes::TAttributes& aAttributes); |
|
325 TBool operator==(const TAttributes& aAttributes) const; |
|
326 public: |
|
327 TInt iPosition; |
|
328 ConsoleAttributes::TAttributes iAttributes; |
|
329 }; |
|
330 private: |
|
331 RArray<TAttributes> iAttributes; |
|
332 }; |
|
333 |
|
334 NONSHARABLE_CLASS(CConsoleLine) : public CBase |
|
335 { |
|
336 public: |
|
337 static CConsoleLine* NewL(CConsoleControl& aControl, const CConsoleFont& aFont, TInt aWidth); |
|
338 ~CConsoleLine(); |
|
339 |
|
340 void SetWidthL(TInt aNewWidth); |
|
341 |
|
342 void SetL(TInt aIndex, TUint8 aChar, const ConsoleAttributes::TAttributes& aAttributes); |
|
343 void Clear(); |
|
344 void ClearFrom(TBufferPosition aPosition); |
|
345 |
|
346 void Draw(CBitmapContext& aDrawTo, TViewPosition aViewPosition) const; |
|
347 TBool NeedToBlink(TBool aBlinkOn); |
|
348 private: |
|
349 CConsoleLine(CConsoleControl& aControl, const CConsoleFont& aFont); |
|
350 void ConstructL(TInt aWidth); |
|
351 TUint16 At(TInt aPos) const; |
|
352 private: |
|
353 CConsoleControl& iControl; |
|
354 const CConsoleFont& iFont; |
|
355 RBuf8 iText; |
|
356 RAttributeMap iAttributeMap; |
|
357 TInt iWidth; |
|
358 TBool iBlinkOn; |
|
359 }; |
|
360 |
|
361 |
|
362 #endif //__GUICONS_H__ |