00001
00002
00003
00004
00005 #include <aknnotewrappers.h>
00006 #include <coemain.h>
00007 #include <eikedwin.h>
00008 #include <gdi.h>
00009 #include <txtrich.h>
00010 #include "Client.pan"
00011 #include "ClientAppView.h"
00012 #include "ClientApplication.h"
00013 #include "ClientEngine.h"
00014 #include "HTTPClientExample_sc.hlp.hrh"
00015
00016
00017 const TInt KNumberOfControls = 2;
00018 const TInt KNumberOfLines = 0;
00019 const TInt KTextLimit = 128;
00020
00021 const TInt KBorderThickness = 4;
00022 const TInt KSizeOffset = KBorderThickness * 2;
00023
00024
00025 #define KBackgroundColor TRgb(128, 128, 128)
00026 #define KBorderColor TRgb(180, 0, 0)
00027
00028
00029
00030
00031
00032
00033 CClientAppView* CClientAppView::NewL(const TRect& aRect)
00034 {
00035 CClientAppView* self = CClientAppView::NewLC(aRect);
00036 CleanupStack::Pop(self);
00037 return self;
00038 }
00039
00040
00041
00042
00043
00044
00045 CClientAppView* CClientAppView::NewLC(const TRect& aRect)
00046 {
00047 CClientAppView* self = new (ELeave) CClientAppView;
00048 CleanupStack::PushL(self);
00049 self->ConstructL(aRect);
00050 return self;
00051 }
00052
00053
00054
00055
00056
00057
00058 CClientAppView::CClientAppView()
00059 {
00060 }
00061
00062
00063
00064
00065
00066
00067 CClientAppView::~CClientAppView()
00068 {
00069 delete iOutputWindow;
00070 delete iStatusWindow;
00071 }
00072
00073
00074
00075
00076
00077
00078 void CClientAppView::ConstructL(const TRect& aRect)
00079 {
00080
00081 CreateWindowL();
00082
00083
00084 iOutputWindow = new (ELeave) CEikRichTextEditor();
00085 iOutputWindow->SetContainerWindowL(*this);
00086 iOutputWindow->ConstructL(this, KNumberOfLines, KTextLimit,
00087 CEikEdwin::EReadOnly | CEikEdwin::EAvkonDisableCursor,
00088 EGulFontControlAll, EGulNoSymbolFonts);
00089 iOutputWindow->CreateScrollBarFrameL()->SetScrollBarVisibilityL(
00090 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn);
00091
00092
00093 iStatusWindow = new (ELeave) CEikRichTextEditor();
00094 iStatusWindow->SetContainerWindowL(*this);
00095 iStatusWindow->ConstructL(this, KNumberOfLines, KTextLimit,
00096 CEikEdwin::EReadOnly | CEikEdwin::EAvkonDisableCursor,
00097 EGulFontControlAll, EGulNoSymbolFonts);
00098 iStatusWindow->CreateScrollBarFrameL()->SetScrollBarVisibilityL(
00099 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn);
00100
00101 iStatusWindow->SetFocus(ETrue);
00102
00103
00104 ActivateL();
00105
00106
00107 SetRect(aRect);
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 void CClientAppView::SizeChanged()
00119 {
00120 TRect r = Rect();
00121 TInt scrollbarWidth = GetScrollbarWidth(iOutputWindow);
00122 TInt editorWidth = r.Width() - KSizeOffset - scrollbarWidth;
00123
00124 TPoint upperEditPosition = TPoint(KBorderThickness, KBorderThickness);
00125 TInt upperEditHeight = r.Height()*3/4 - KSizeOffset;
00126 iOutputWindow->SetExtent(upperEditPosition, TSize(editorWidth,
00127 upperEditHeight));
00128
00129 upperEditPosition.iY += upperEditHeight + KBorderThickness;
00130 upperEditHeight = r.Height()/4 - KBorderThickness;
00131 iStatusWindow->SetExtent(upperEditPosition, TSize(editorWidth,
00132 upperEditHeight));
00133 }
00134
00135
00136
00137
00138
00139
00140 void CClientAppView::GetHelpContext(TCoeHelpContext& aContext) const
00141 {
00142
00143 aContext.iMajor = KUidHelpFile;
00144
00145 aContext.iContext = KContextApplication;
00146 }
00147
00148
00149
00150
00151
00152
00153 void CClientAppView::HandleResourceChange(TInt aType)
00154 {
00155 CCoeControl::HandleResourceChange(aType);
00156
00157
00158
00159 if ( aType==KEikDynamicLayoutVariantSwitch )
00160 {
00161 TRect rect;
00162 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00163 SetRect(rect);
00164 }
00165 }
00166
00167
00168
00169
00170
00171
00172 void CClientAppView::Draw(const TRect& aRect) const
00173 {
00174 CWindowGc& gc = SystemGc();
00175
00176 gc.SetPenStyle( CGraphicsContext::ENullPen );
00177 gc.SetBrushColor( KBackgroundColor );
00178 gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
00179 gc.DrawRect( aRect );
00180
00181
00182 gc.SetBrushColor(KBorderColor);
00183 if (iOutputWindow->IsFocused())
00184 {
00185 TInt scrollbarWidth = GetScrollbarWidth(iOutputWindow);
00186 TRect editorRect = iOutputWindow->Rect();
00187 editorRect.Grow(KBorderThickness + scrollbarWidth, KBorderThickness);
00188 editorRect.Move(scrollbarWidth, 0);
00189 gc.DrawRect(editorRect);
00190 }
00191
00192 if (iStatusWindow->IsFocused())
00193 {
00194 TInt scrollbarWidth = GetScrollbarWidth(iStatusWindow);
00195 TRect editorRect = iStatusWindow->Rect();
00196 editorRect.Grow(KBorderThickness + scrollbarWidth, KBorderThickness);
00197 editorRect.Move(scrollbarWidth, 0);
00198 gc.DrawRect(editorRect);
00199 }
00200 }
00201
00202
00203
00204
00205 TInt CClientAppView::GetScrollbarWidth(CEikRichTextEditor* anEditor) const
00206 {
00207 TInt scrollbarWidth = anEditor->ScrollBarFrame()->
00208 ScrollBarBreadth(CEikScrollBar::EVertical);
00209
00210
00211 if (scrollbarWidth == 0)
00212 {
00213 scrollbarWidth = 8;
00214 }
00215 return scrollbarWidth;
00216 }
00217
00218
00219
00220
00221
00222
00223 TInt CClientAppView::CountComponentControls() const
00224 {
00225 return KNumberOfControls;
00226 }
00227
00228
00229
00230
00231
00232
00233 CCoeControl* CClientAppView::ComponentControl(TInt aIndex) const
00234 {
00235 switch(aIndex)
00236 {
00237 case 0:
00238 return iOutputWindow;
00239 case 1:
00240 return iStatusWindow;
00241 default:
00242 Panic(EClientView);
00243 return 0;
00244 }
00245 }
00246
00247
00248
00249
00250
00251
00252 void CClientAppView::HandleControlEventL(CCoeControl* ,
00253 TCoeEvent )
00254 {
00255 }
00256
00257
00258
00259
00260
00261
00262 void CClientAppView::ResetL()
00263 {
00264 iOutputWindow->Text()->Reset();
00265 iOutputWindow->HandleTextChangedL();
00266 iOutputWindow->SetCursorPosL(0, EFalse);
00267
00268 iStatusWindow->Text()->Reset();
00269 iStatusWindow->HandleTextChangedL();
00270 iStatusWindow->SetCursorPosL(0, EFalse);
00271 }
00272
00273
00274
00275
00276
00277
00278 TKeyResponse CClientAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,
00279 TEventCode aType)
00280 {
00281
00282
00283 if(aType == EEventKey)
00284 {
00285 switch(aKeyEvent.iScanCode)
00286 {
00287 case EStdKeyNkp5:
00288 case EStdKeyDevice3:
00289 SwitchFocus();
00290 return EKeyWasConsumed;
00291 }
00292 }
00293
00294
00295 if (iOutputWindow)
00296 {
00297 if (iOutputWindow->IsFocused())
00298 return iOutputWindow->OfferKeyEventL(aKeyEvent, aType);
00299 }
00300
00301 if (iStatusWindow)
00302 {
00303 if (iStatusWindow->IsFocused())
00304 return iStatusWindow->OfferKeyEventL(aKeyEvent, aType);
00305 }
00306
00307 return EKeyWasNotConsumed;
00308 }
00309
00310
00311
00312
00313
00314
00315 void CClientAppView::SwitchFocus()
00316 {
00317 if (iOutputWindow->IsFocused())
00318 {
00319 iOutputWindow->SetFocus(EFalse);
00320 iStatusWindow->SetFocus(ETrue);
00321 }
00322 else
00323 {
00324 iStatusWindow->SetFocus(EFalse);
00325 iOutputWindow->SetFocus(ETrue);
00326 }
00327
00328 DrawNow();
00329 }
00330
00331
00332
00333
00334
00335
00336 void CClientAppView::AddToStatusWindowL(const TDesC& aText)
00337 {
00338
00339 CRichText* text = iStatusWindow->RichText();
00340 text->InsertL(text->DocumentLength(), aText);
00341 text->InsertL(text->DocumentLength(), CEditableText::ELineBreak);
00342 iStatusWindow->HandleTextChangedL();
00343 iStatusWindow->MoveCursorL(TCursorPosition::EFLineDown, EFalse);
00344 }
00345
00346
00347
00348
00349
00350
00351 void CClientAppView::AddToOutputWindowL(const TDesC8& aText)
00352 {
00353
00354 HBufC* tempBuf = HBufC::NewL(aText.Length());
00355 CleanupStack::PushL(tempBuf);
00356 tempBuf->Des().Copy(aText);
00357 CRichText* text = iOutputWindow->RichText();
00358 text->InsertL(text->DocumentLength(), *tempBuf);
00359 iOutputWindow->HandleTextChangedL();
00360
00361 CleanupStack::PopAndDestroy(tempBuf);
00362 }
00363
00364
00365
00366
00367
00368
00369 void CClientAppView::ClientEvent(const TDesC& aEventDescription)
00370 {
00371 TRAPD(err, AddToStatusWindowL(aEventDescription));
00372 if(err)
00373 Panic(EClientView);
00374 }
00375
00376
00377
00378
00379
00380
00381 void CClientAppView::ClientBodyReceived(const TDesC8& aBodyData)
00382 {
00383 TRAPD(err, AddToOutputWindowL(aBodyData));
00384 if(err)
00385 Panic(EClientView);
00386 }
00387
00388