|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // dnd.cpp - name resolver daemon main module |
|
15 // |
|
16 |
|
17 #include <eikfnlab.h> |
|
18 #include <eikfontd.h> |
|
19 |
|
20 #include <eikenv.h> |
|
21 |
|
22 |
|
23 #include <coeccntx.h> |
|
24 |
|
25 #include <eikappui.h> |
|
26 #include <eikapp.h> |
|
27 #include <eikdoc.h> |
|
28 #include <eikconso.h> |
|
29 |
|
30 #include "dnd.hrh" |
|
31 #include "demon.h" |
|
32 #include <dndapp.rsg> |
|
33 |
|
34 const TUid KUidDndApp = {0x10000882}; |
|
35 // |
|
36 // CSimpleConsole |
|
37 // |
|
38 enum TMessageControlFontStyle |
|
39 { |
|
40 EStyleElementBold=EMenuCommandBold, |
|
41 EStyleElementItalic=EMenuCommandItalic, |
|
42 EStyleElementInverse=EMenuCommandInverse, |
|
43 EStyleElementUnderline=EMenuCommandUnderline, |
|
44 EStyleElementColor=EMenuCommandColor |
|
45 }; |
|
46 |
|
47 class CConsoleControl : public CCoeControl |
|
48 { |
|
49 public: |
|
50 CConsoleControl() {} |
|
51 ~CConsoleControl(); |
|
52 void ConstructL(const TPoint& aLeftTop, const TSize& aSize, TInt aFlags); |
|
53 void HandleCommandL(TInt aCommand); |
|
54 void ActivateL(); |
|
55 void SetScrollBarVisibilityL(CEikScrollBarFrame::TScrollBarVisibility aHBarVisibility, CEikScrollBarFrame::TScrollBarVisibility aVBarVisibility); |
|
56 void DrawCursor(); |
|
57 void Write(const TDesC &aDes); |
|
58 CEikConsoleControl *ConsoleControl(); |
|
59 TBool UpdateScrollBars(); |
|
60 void ClearScreen(); |
|
61 void Redraw(const TRect &aRect); |
|
62 void Lf(); |
|
63 protected: |
|
64 void FocusChanged(TDrawNow aDrawNow); |
|
65 private: |
|
66 void ToggleFontStyleAndRedrawL(TMessageControlFontStyle aStyleElement); |
|
67 |
|
68 private: |
|
69 CEikConsoleScreen* iConsole; |
|
70 TInt iHistory; |
|
71 }; |
|
72 |
|
73 |
|
74 // |
|
75 // class CDndView |
|
76 // |
|
77 class CDndEngine; |
|
78 class CDndView : public CCoeControl, public MCoeControlBrushContext, public MDemonMain |
|
79 { |
|
80 public: |
|
81 ~CDndView(); |
|
82 void ConstructL(const TRect& aRect); |
|
83 |
|
84 void Start(); |
|
85 void Stop(); |
|
86 void Dump(); |
|
87 TInt CountComponentControls() const; |
|
88 CCoeControl* ComponentControl(TInt aIndex) const; |
|
89 void Write(const TDesC &aDes); |
|
90 void WriteList(const TDesC &aFmt, VA_LIST aList); |
|
91 void ClearScreen(); |
|
92 void ShowError(TInt aId); |
|
93 TInt CheckResult(const TDesC &aText, TInt aResult); |
|
94 |
|
95 void HandleCommandL(TInt aCommand); |
|
96 private: |
|
97 void Draw(const TRect& /*aRect*/) const; |
|
98 |
|
99 //Component Controls |
|
100 void CreateBigConsoleL(TInt aFlags); |
|
101 |
|
102 void ShowError(TDes &msg); |
|
103 void ShowError(TDes &msg, TInt aErr); |
|
104 |
|
105 private: |
|
106 CConsoleControl* iConsole; |
|
107 |
|
108 MDemonEngine *iModel; |
|
109 TBool iRunning; |
|
110 TBuf<1024> iBuf; //< A work buffer for formatting messsages (Writef) |
|
111 }; |
|
112 |
|
113 |
|
114 // |
|
115 // CDndAppUi |
|
116 // |
|
117 class CDndAppUi : public CEikAppUi |
|
118 { |
|
119 public: |
|
120 void ConstructL(); |
|
121 ~CDndAppUi(); |
|
122 |
|
123 private: |
|
124 void HandleCommandL(TInt aCommand); |
|
125 // TBool LaunchOptionsDialog(CUDPSendEngine* aModel); |
|
126 // void LaunchAboutDialog(); |
|
127 private: |
|
128 CDndView* iAppView; |
|
129 // CHelpTask *iHelp; |
|
130 }; |
|
131 |
|
132 // |
|
133 // CDndDocument |
|
134 // |
|
135 class CDndDocument : public CEikDocument |
|
136 { |
|
137 public: |
|
138 CDndDocument(CEikApplication& aApp); |
|
139 private: |
|
140 CEikAppUi* CreateAppUiL(); |
|
141 }; |
|
142 |
|
143 // |
|
144 // CDndAppUi |
|
145 // |
|
146 class CDndApplication : public CEikApplication |
|
147 { |
|
148 private: // from CApaApplication |
|
149 CApaDocument* CreateDocumentL(); |
|
150 TUid AppDllUid() const; |
|
151 }; |
|
152 |
|
153 // |
|
154 // CConsoleControl |
|
155 // |
|
156 CConsoleControl::~CConsoleControl() |
|
157 { |
|
158 delete iConsole; |
|
159 } |
|
160 |
|
161 void CConsoleControl::ConstructL(const TPoint& aTopLeft,const TSize& aSize,TInt aFlags) |
|
162 { |
|
163 TRect rect(aTopLeft,aTopLeft + aSize.AsPoint()); |
|
164 SetRect(rect); |
|
165 iConsole= new (ELeave) CEikConsoleScreen; |
|
166 iConsole->ConstructL(_L("TEST"),aTopLeft,aSize,aFlags,EEikConsWinInPixels); |
|
167 iConsole->SetHistorySizeL(200,0); |
|
168 //iConsole->SetAllPrintable(ETrue); |
|
169 iHistory=200; |
|
170 } |
|
171 |
|
172 void CConsoleControl::ActivateL() |
|
173 { |
|
174 CCoeControl::ActivateL(); |
|
175 iConsole->SetKeepCursorInSight(TRUE); |
|
176 iConsole->DrawCursor(); |
|
177 iConsole->SetAtt(ATT_NORMAL); |
|
178 } |
|
179 |
|
180 void CConsoleControl::HandleCommandL(TInt aCommand) |
|
181 { |
|
182 switch (aCommand) |
|
183 { |
|
184 case EConsolFontDialog: |
|
185 { |
|
186 TCharFormat charFormat; |
|
187 charFormat.iFontSpec = iConsole->Font(); |
|
188 TCharFormatMask dummy; |
|
189 if (CEikFontDialog::RunDlgLD(charFormat, dummy)) |
|
190 { |
|
191 //charFormat.iFontSpec.iTypeface.SetIsProportional(EFalse); |
|
192 iConsole->SetFontL(charFormat.iFontSpec); |
|
193 } |
|
194 } |
|
195 break; |
|
196 #if 0 |
|
197 case EConsolHistory: |
|
198 { |
|
199 CHistoryDialog* dialog2 = new(ELeave) CHistoryDialog(&iHistory); |
|
200 if (dialog2->ExecuteLD(R_KMD_HISTORY_DIALOG)) |
|
201 iConsole->SetHistorySizeL(iHistory,0); |
|
202 } |
|
203 break; |
|
204 #endif |
|
205 case EConsolScrollNone: |
|
206 iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOff); |
|
207 break; |
|
208 case EConsolScrollHor: |
|
209 iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto,CEikScrollBarFrame::EOff); |
|
210 break; |
|
211 case EConsolScrollVert: |
|
212 iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto); |
|
213 break; |
|
214 case EConsolScrollBoth: |
|
215 iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto,CEikScrollBarFrame::EAuto); |
|
216 break; |
|
217 |
|
218 default: |
|
219 break; |
|
220 } |
|
221 } |
|
222 |
|
223 void CConsoleControl::FocusChanged(TDrawNow aDrawNow) |
|
224 { |
|
225 iConsole->ConsoleControl()->SetFocus(IsFocused(), aDrawNow); |
|
226 } |
|
227 |
|
228 void CConsoleControl::ToggleFontStyleAndRedrawL(TMessageControlFontStyle aStyleElement) |
|
229 { |
|
230 switch (aStyleElement) |
|
231 { |
|
232 case EStyleElementColor: |
|
233 if ( iConsole->Att() & ATT_COLORMASK ) // color? |
|
234 iConsole->SetAtt(ATT_NORMAL); // then set normal |
|
235 else // else |
|
236 iConsole->SetAtt(4,11); // set 4 (darkgray) on 11 (lightgray) |
|
237 break; |
|
238 case EStyleElementBold: |
|
239 // clear color flag (just to be sure) and switch bold flag |
|
240 iConsole->SetAtt( (iConsole->Att()&(~ATT_COLORMASK)) ^ ATT_BOLD ); |
|
241 break; |
|
242 case EStyleElementItalic: |
|
243 // clear color flag (just to be sure) and switch italic flag |
|
244 iConsole->SetAtt( (iConsole->Att()&(~ATT_COLORMASK)) ^ ATT_ITALIC ); |
|
245 break; |
|
246 case EStyleElementInverse: |
|
247 // clear color flag (just to be sure) and switch inverse flag |
|
248 iConsole->SetAtt( (iConsole->Att()&(~ATT_COLORMASK)) ^ ATT_INVERSE ); |
|
249 break; |
|
250 case EStyleElementUnderline: |
|
251 // clear color flag (just to be sure) and switch underline flag |
|
252 iConsole->SetAtt( (iConsole->Att()&(~ATT_COLORMASK)) ^ ATT_UNDERLINE ); |
|
253 break; |
|
254 } |
|
255 } |
|
256 |
|
257 void CConsoleControl::SetScrollBarVisibilityL(CEikScrollBarFrame::TScrollBarVisibility aHBarVisibility, CEikScrollBarFrame::TScrollBarVisibility aVBarVisibility) |
|
258 { |
|
259 iConsole->SetScrollBarVisibilityL(aHBarVisibility,aVBarVisibility); |
|
260 iConsole->ConsoleControl()->UpdateArea(); |
|
261 iConsole->UpdateScrollBars(); |
|
262 iConsole->ConsoleControl()->UpdateArea(); |
|
263 //TBool b=iConsole->RecalculateSize(); |
|
264 } |
|
265 |
|
266 |
|
267 void CConsoleControl::DrawCursor() |
|
268 { |
|
269 iConsole->DrawCursor(); |
|
270 } |
|
271 |
|
272 |
|
273 void CConsoleControl::Write(const TDesC &aMsg) |
|
274 { |
|
275 iConsole->Write(aMsg); |
|
276 iConsole->FlushChars(); |
|
277 } |
|
278 |
|
279 |
|
280 CEikConsoleControl *CConsoleControl::ConsoleControl() |
|
281 { |
|
282 return iConsole->ConsoleControl(); |
|
283 } |
|
284 |
|
285 TBool CConsoleControl::UpdateScrollBars() |
|
286 { |
|
287 return iConsole->UpdateScrollBars(); |
|
288 } |
|
289 |
|
290 void CConsoleControl::ClearScreen() |
|
291 { |
|
292 iConsole->ClearScreen(); |
|
293 } |
|
294 |
|
295 |
|
296 void CConsoleControl::Redraw(const TRect &aRect) |
|
297 { |
|
298 iConsole->Redraw(aRect); |
|
299 } |
|
300 |
|
301 void CConsoleControl::Lf() |
|
302 { |
|
303 iConsole->Lf(); |
|
304 } |
|
305 |
|
306 |
|
307 // **************** |
|
308 // APPLICATION VIEW |
|
309 // **************** |
|
310 // |
|
311 void CDndView::ConstructL(const TRect& aRect) |
|
312 { |
|
313 CreateWindowL(); |
|
314 SetRect(aRect); |
|
315 |
|
316 iContext = this; |
|
317 iBrushStyle = CGraphicsContext::ESolidBrush; |
|
318 iBrushColor = KRgbWhite; |
|
319 CreateBigConsoleL(CEikConsoleScreen::ENoInitialCursor); |
|
320 |
|
321 ActivateL(); |
|
322 } |
|
323 |
|
324 void CDndView::CreateBigConsoleL(TInt aFlags) |
|
325 { |
|
326 iConsole =new(ELeave) CConsoleControl; |
|
327 // TRect rect=Rect(); |
|
328 // rect.Shrink(3,3); |
|
329 iConsole->ConstructL(Position(), Rect().Size(),aFlags); |
|
330 iConsole->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto); |
|
331 } |
|
332 |
|
333 CDndView::~CDndView() |
|
334 { |
|
335 delete iConsole; |
|
336 delete iModel; |
|
337 } |
|
338 |
|
339 TInt CDndView::CountComponentControls() const |
|
340 { |
|
341 return 1; |
|
342 } |
|
343 |
|
344 CCoeControl* CDndView::ComponentControl(TInt aIndex) const |
|
345 { |
|
346 switch (aIndex) |
|
347 { |
|
348 case 0: |
|
349 return iConsole; |
|
350 default: |
|
351 return 0; |
|
352 } |
|
353 } |
|
354 |
|
355 void CDndView::Draw(const TRect& /*aRect*/) const |
|
356 { |
|
357 } |
|
358 |
|
359 void CDndView::Start() |
|
360 { |
|
361 TInt err; |
|
362 |
|
363 if (!iModel) |
|
364 { |
|
365 |
|
366 TRAP(err, iModel = MDemonEngine::NewL(*this)); |
|
367 if (err == KErrNone && iModel) |
|
368 { |
|
369 CEikonEnv::Static()->BusyMsgL(R_BUSY); |
|
370 TRAP(err, iModel->ConstructL()); |
|
371 CEikonEnv::Static()->BusyMsgCancel(); |
|
372 if (err!=KErrNone) |
|
373 { |
|
374 TBuf<50> msg; |
|
375 msg.Format(_L("Error initializing: %d"), err); |
|
376 ShowError(msg); |
|
377 Stop(); |
|
378 } |
|
379 } |
|
380 } |
|
381 else |
|
382 CEikonEnv::Static()->InfoMsg(_L("Already started!")); |
|
383 } |
|
384 |
|
385 void CDndView::Write(const TDesC &aMsg) |
|
386 { |
|
387 iConsole->Write(aMsg); |
|
388 iConsole->Write(_L("\n")); |
|
389 } |
|
390 |
|
391 void CDndView::WriteList(const TDesC &aFmt, VA_LIST aList) |
|
392 { |
|
393 iBuf.FormatList(aFmt, aList); |
|
394 iConsole->Write(iBuf); |
|
395 iConsole->Write(_L("\n")); |
|
396 } |
|
397 |
|
398 |
|
399 void CDndView::ShowError(TInt aId) |
|
400 { |
|
401 iEikonEnv->InfoMsg(aId); |
|
402 } |
|
403 |
|
404 void CDndView::ShowError(TDes &msg) |
|
405 { |
|
406 iEikonEnv->InfoMsg(msg); |
|
407 } |
|
408 |
|
409 void CDndView::ShowError(TDes &msg, TInt aErr) |
|
410 { |
|
411 TBuf<100> txt; |
|
412 TBuf<100> txt2; |
|
413 |
|
414 txt.Format(msg); |
|
415 iEikonEnv->GetErrorText(txt2,aErr); |
|
416 txt.AppendFormat(txt2); |
|
417 iEikonEnv->InfoMsg(txt); |
|
418 } |
|
419 |
|
420 TInt CDndView::CheckResult(const TDesC &aText, TInt aResult) |
|
421 { |
|
422 if (aResult == KErrNone) |
|
423 return KErrNone; |
|
424 |
|
425 TBuf<100> err; |
|
426 iEikonEnv->GetErrorText(err, aResult); |
|
427 |
|
428 TBuf<200> str(aText); |
|
429 str.AppendFormat(_L(" returned with [%d: %s] "), aResult,err.PtrZ()); |
|
430 Write(str); |
|
431 return aResult; |
|
432 } |
|
433 |
|
434 |
|
435 void CDndView::Stop() |
|
436 { |
|
437 TInt err; |
|
438 if (iModel) |
|
439 { |
|
440 TRAP(err, CEikonEnv::Static()->BusyMsgL(R_BUSY)); |
|
441 delete iModel; |
|
442 iModel = NULL; |
|
443 CEikonEnv::Static()->BusyMsgCancel(); |
|
444 Write(_L("*Stopped*")); |
|
445 } |
|
446 else |
|
447 { |
|
448 CEikonEnv::Static()->InfoMsg(_L("Not started!")); |
|
449 } |
|
450 } |
|
451 |
|
452 void CDndView::ClearScreen() |
|
453 { |
|
454 TInt err; |
|
455 delete iConsole; |
|
456 iConsole = NULL; |
|
457 TRAP(err, CreateBigConsoleL(CEikConsoleScreen::ENoInitialCursor)); |
|
458 } |
|
459 |
|
460 void CDndView::HandleCommandL(TInt aCommand) |
|
461 { |
|
462 switch (aCommand) |
|
463 { |
|
464 case EDndStart: |
|
465 Start(); |
|
466 break; |
|
467 case EDndStop: |
|
468 Stop(); |
|
469 break; |
|
470 case EDndClearScreen: |
|
471 ClearScreen(); |
|
472 break; |
|
473 case EDndDump: |
|
474 if (iModel) |
|
475 { |
|
476 CEikonEnv::Static()->BusyMsgL(R_BUSY); |
|
477 iModel->HandleCommandL(aCommand); |
|
478 CEikonEnv::Static()->BusyMsgCancel(); |
|
479 } |
|
480 else |
|
481 CEikonEnv::Static()->InfoMsg(_L("Not started!")); |
|
482 break; |
|
483 |
|
484 default: |
|
485 ASSERT(iConsole != NULL); |
|
486 iConsole->HandleCommandL(aCommand); |
|
487 if (iModel) |
|
488 iModel->HandleCommandL(aCommand); |
|
489 } |
|
490 } |
|
491 |
|
492 // ************** |
|
493 // APPLICATION UI |
|
494 // ************** |
|
495 // |
|
496 void CDndAppUi::ConstructL() |
|
497 { |
|
498 BaseConstructL(); |
|
499 |
|
500 iAppView= new (ELeave) CDndView; |
|
501 iAppView->ConstructL(ClientRect()); |
|
502 } |
|
503 |
|
504 void CDndAppUi::HandleCommandL(TInt aCommand) |
|
505 { |
|
506 switch (aCommand) |
|
507 { |
|
508 case EEikCmdExit: |
|
509 Exit(); |
|
510 return; |
|
511 default: |
|
512 iAppView->HandleCommandL(aCommand); |
|
513 } |
|
514 } |
|
515 |
|
516 CDndAppUi::~CDndAppUi() |
|
517 { |
|
518 delete iAppView; |
|
519 } |
|
520 |
|
521 // ******** |
|
522 // DOCUMENT |
|
523 // ******** |
|
524 CDndDocument::CDndDocument(CEikApplication& aApp) |
|
525 : CEikDocument(aApp) |
|
526 { |
|
527 } |
|
528 |
|
529 CEikAppUi* CDndDocument::CreateAppUiL() |
|
530 { |
|
531 return new (ELeave) CDndAppUi; |
|
532 } |
|
533 |
|
534 // *********** |
|
535 // APPLICATION |
|
536 // *********** |
|
537 // |
|
538 |
|
539 TUid CDndApplication::AppDllUid() const |
|
540 { |
|
541 return KUidDndApp; |
|
542 } |
|
543 |
|
544 CApaDocument* CDndApplication::CreateDocumentL() |
|
545 { |
|
546 return new(ELeave) CDndDocument(*this); |
|
547 } |
|
548 |
|
549 // **** |
|
550 // MAIN |
|
551 // **** |
|
552 // |
|
553 EXPORT_C CApaApplication* NewApplication() |
|
554 { |
|
555 return new CDndApplication; |
|
556 } |
|
557 |
|
558 |
|
559 GLDEF_C TInt E32Dll() |
|
560 { |
|
561 return KErrNone; |
|
562 } |