|
1 /* |
|
2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "TCustomWrap.h" |
|
20 #include <basched.h> |
|
21 #include <coecntrl.h> |
|
22 #include <coeccntx.h> |
|
23 #include <coemain.h> |
|
24 #include <e32keys.h> |
|
25 #include <techview/eikon.hrh> |
|
26 #include <eikappui.h> |
|
27 #include <eikapp.h> |
|
28 #include <eikdoc.h> |
|
29 #include <eikenv.h> |
|
30 #include <techview/eikrted.h> |
|
31 #include <techview/eikedwin.h> |
|
32 #include <eikdef.h> |
|
33 #include <eikstart.h> |
|
34 #include <txtrich.h> |
|
35 #include "TCustomWrap.hrh" |
|
36 #include <tcustomwrap.rsg> |
|
37 |
|
38 // |
|
39 // ---------------- CCustomWrapAppControl (a simple Edwin control) ----------- |
|
40 |
|
41 class CCustomWrapAppControl : public CCoeControl, public MCoeControlObserver |
|
42 { |
|
43 public: |
|
44 ~CCustomWrapAppControl(); |
|
45 void ConstructL(); |
|
46 void SetCustomWrapOnL(); |
|
47 void SetCustomWrapCustomL(); |
|
48 void SetCustomWrapOffL(); |
|
49 void ReformatL(); |
|
50 |
|
51 private: // framework |
|
52 void Draw(const TRect& aRect) const; |
|
53 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType); |
|
54 void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType); // from the MCoeControlObserverInterface |
|
55 // void ActivateL(); |
|
56 virtual TInt CountComponentControls() const; |
|
57 virtual CCoeControl* ComponentControl(TInt aIndex) const; |
|
58 // the two functions above are needed in order for the control to work correctly. |
|
59 |
|
60 |
|
61 private: |
|
62 void CreateEdwinL(); |
|
63 |
|
64 |
|
65 private: |
|
66 CCoeControl* iFocusControl; // The control that is currently in focus. |
|
67 CEikEdwin* iEdwin; // I still need a focus control, even if just one EikEdwin... |
|
68 const MFormCustomWrap* iStandardCustomWrap; |
|
69 TTestCustomWrap iCustomCustomWrap; |
|
70 }; |
|
71 |
|
72 CCustomWrapAppControl::~CCustomWrapAppControl() |
|
73 { |
|
74 delete iEdwin; |
|
75 } |
|
76 |
|
77 void CCustomWrapAppControl::ConstructL() |
|
78 { |
|
79 CreateWindowL(); |
|
80 Window().SetShadowDisabled(ETrue); |
|
81 CreateEdwinL(); |
|
82 iStandardCustomWrap = iEdwin->TextLayout()->CustomWrap(); |
|
83 iFocusControl=iEdwin; |
|
84 SetExtentToWholeScreen(); |
|
85 ActivateL(); |
|
86 iFocusControl->SetFocus(ETrue); |
|
87 } |
|
88 |
|
89 //void CCustomWrapAppControl::ActivateL() |
|
90 // { |
|
91 // CCoeControl::ActivateL(); |
|
92 // iEdwin->ActivateL(); |
|
93 // } |
|
94 |
|
95 void CCustomWrapAppControl::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType) |
|
96 { |
|
97 if (aEventType==EEventRequestFocus) |
|
98 { |
|
99 iFocusControl=aControl; |
|
100 iFocusControl->SetFocus(ETrue,EDrawNow); |
|
101 } |
|
102 } |
|
103 |
|
104 TInt CCustomWrapAppControl::CountComponentControls() const |
|
105 { |
|
106 return 1; |
|
107 } |
|
108 |
|
109 CCoeControl* CCustomWrapAppControl::ComponentControl(TInt /*aIndex*/) const |
|
110 { |
|
111 return iEdwin; |
|
112 } |
|
113 |
|
114 void CCustomWrapAppControl::CreateEdwinL() |
|
115 { |
|
116 const TSize screenSize(iCoeEnv->ScreenDevice()->SizeInPixels()); |
|
117 // Rich text editor. |
|
118 iEdwin=new(ELeave) CEikRichTextEditor; |
|
119 STATIC_CAST(CEikRichTextEditor*,iEdwin)->ConstructL(this,0,0,EEikEdwinCustomWrap); |
|
120 //STATIC_CAST(CEikRichTextEditor*,iEdwin)->ConstructL(this,0,0,EEikEdwinInclusiveSizeFixed); |
|
121 iEdwin->SetObserver(this); |
|
122 iEdwin->CreateScrollBarFrameL(); |
|
123 iEdwin->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn); |
|
124 iEdwin->SetExtent(TPoint(screenSize.iWidth/5,screenSize.iHeight/8),TSize(screenSize.iWidth/3,screenSize.iHeight*3/5)); |
|
125 } |
|
126 |
|
127 TKeyResponse CCustomWrapAppControl::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
128 { |
|
129 if (aType==EEventKey) |
|
130 { |
|
131 iEdwin->OfferKeyEventL(aKeyEvent, aType); |
|
132 } |
|
133 return(EKeyWasConsumed); |
|
134 } |
|
135 |
|
136 void CCustomWrapAppControl::Draw(const TRect& aRect) const |
|
137 { |
|
138 CWindowGc& gc=SystemGc(); |
|
139 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
140 gc.SetBrushColor(KRgbWhite); |
|
141 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
142 gc.DrawRect(aRect); |
|
143 } |
|
144 |
|
145 |
|
146 void CCustomWrapAppControl::SetCustomWrapOnL() |
|
147 { |
|
148 iEdwin->TextLayout()->SetCustomWrap(iStandardCustomWrap); |
|
149 ReformatL(); |
|
150 } |
|
151 |
|
152 void CCustomWrapAppControl::SetCustomWrapCustomL() |
|
153 { |
|
154 iEdwin->TextLayout()->SetCustomWrap(&iCustomCustomWrap); |
|
155 ReformatL(); |
|
156 } |
|
157 |
|
158 void CCustomWrapAppControl::SetCustomWrapOffL() |
|
159 { |
|
160 iEdwin->TextLayout()->SetCustomWrap(0); |
|
161 ReformatL(); |
|
162 } |
|
163 |
|
164 void CCustomWrapAppControl::ReformatL() |
|
165 { |
|
166 iEdwin->NotifyNewFormatL(); |
|
167 } |
|
168 |
|
169 // |
|
170 // ---------------------- CCustomWrapAppView definition ---------------- |
|
171 // |
|
172 |
|
173 class CCustomWrapAppUi : public CEikAppUi |
|
174 { |
|
175 public: |
|
176 void ConstructL(); |
|
177 ~CCustomWrapAppUi(); |
|
178 private: // from CEikAppUi -- framework |
|
179 void HandleCommandL(TInt aCommand); |
|
180 private: |
|
181 CCustomWrapAppControl* iCustomWrapAppControl; |
|
182 |
|
183 }; |
|
184 |
|
185 void CCustomWrapAppUi::ConstructL() |
|
186 { |
|
187 BaseConstructL(); |
|
188 iCustomWrapAppControl=new(ELeave) CCustomWrapAppControl; |
|
189 iCustomWrapAppControl->ConstructL(); |
|
190 AddToStackL(iCustomWrapAppControl); |
|
191 } |
|
192 |
|
193 CCustomWrapAppUi::~CCustomWrapAppUi() |
|
194 { |
|
195 RemoveFromStack(iCustomWrapAppControl); |
|
196 delete iCustomWrapAppControl; |
|
197 } |
|
198 |
|
199 void CCustomWrapAppUi::HandleCommandL(TInt aCommand) |
|
200 { |
|
201 switch(aCommand) |
|
202 { |
|
203 case EAppCmdExit: |
|
204 CBaActiveScheduler::Exit(); |
|
205 break; |
|
206 case EAppCmdWrap0: |
|
207 iCustomWrapAppControl->SetCustomWrapOffL(); |
|
208 break; |
|
209 case EAppCmdWrap1: |
|
210 iCustomWrapAppControl->SetCustomWrapOnL(); |
|
211 break; |
|
212 case EAppCmdWrap2: |
|
213 iCustomWrapAppControl->SetCustomWrapCustomL(); |
|
214 break; |
|
215 default: |
|
216 break; |
|
217 } |
|
218 } |
|
219 |
|
220 // |
|
221 // --------------------- CCustomWrapAppDoc class Definition ------------ |
|
222 // |
|
223 |
|
224 class CCustomWrapAppDoc : public CEikDocument |
|
225 { |
|
226 public: |
|
227 CCustomWrapAppDoc(CEikApplication& aApp); |
|
228 private: |
|
229 CEikAppUi* CreateAppUiL(); |
|
230 }; |
|
231 |
|
232 |
|
233 CCustomWrapAppDoc::CCustomWrapAppDoc(CEikApplication& aApp):CEikDocument(aApp) |
|
234 { |
|
235 // Nothing else to do, just call the base class constructor |
|
236 // |
|
237 } |
|
238 |
|
239 CEikAppUi* CCustomWrapAppDoc::CreateAppUiL() |
|
240 { |
|
241 return new (ELeave) CCustomWrapAppUi; |
|
242 } |
|
243 // |
|
244 // ------------------------------ CCustomWrapApp ----------------------- |
|
245 // |
|
246 |
|
247 |
|
248 const TUid KCustomWrapUid = {0x10005d2f}; |
|
249 |
|
250 class CCustomWrapApp : public CEikApplication |
|
251 { |
|
252 private: |
|
253 CApaDocument* CreateDocumentL(); |
|
254 TUid AppDllUid() const; |
|
255 |
|
256 }; |
|
257 |
|
258 TUid CCustomWrapApp::AppDllUid() const |
|
259 { |
|
260 return KCustomWrapUid; |
|
261 } |
|
262 |
|
263 CApaDocument* CCustomWrapApp::CreateDocumentL() |
|
264 { |
|
265 return new (ELeave) CCustomWrapAppDoc(*this); |
|
266 } |
|
267 |
|
268 |
|
269 //////////////////////////////////////////////////////////////////////////////////////////// |
|
270 // |
|
271 |
|
272 static CApaApplication* NewApplication() |
|
273 { |
|
274 return new CCustomWrapApp; |
|
275 } |
|
276 |
|
277 TInt E32Main() |
|
278 { |
|
279 return EikStart::RunApplication(&NewApplication); |
|
280 } |
|
281 |
|
282 |