00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <w32std.h>
00018 #include "Base.h"
00019 #include "Scroll.h"
00020
00021 _LIT(KString1,"1");
00022 _LIT(KString2,"2");
00023 _LIT(KString3,"3");
00024 _LIT(KString4,"4");
00025 _LIT(KString5,"5");
00026
00028
00030
00031
00032
00033
00034
00035 CNumberedWindow::CNumberedWindow (CWsClient* aClient, TInt aNum)
00036 : CWindow (aClient), iNumber(aNum), iOldPos(0,0), iOffset(0,0), iRepeatRect(0,0,0,0)
00037 {
00038 }
00039
00040
00041 CNumberedWindow::~CNumberedWindow ()
00042 {
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 void CNumberedWindow::Draw(const TRect& aRect)
00054 {
00055 const TBufC<1> strings[5] = { *&KString1,
00056 *&KString2,
00057 *&KString3,
00058 *&KString4,
00059 *&KString5
00060 };
00061
00062 CWindowGc* gc=SystemGc();
00063 gc->SetClippingRect(aRect);
00064 gc->Clear(aRect);
00065 TSize size=iWindow.Size();
00066 TInt height=size.iHeight;
00067 TInt ascent = Font()->AscentInPixels();
00068 TInt descent = Font()->DescentInPixels();
00069 TInt offset = (height + (ascent + descent)) / 2;
00070 gc->SetPenColor(TRgb(0,0,0));
00071 gc->UseFont(Font());
00072 gc->DrawText(strings[iNumber], TRect(TPoint(0,0) + iOffset, size), offset,
00073 CGraphicsContext::ECenter);
00074 gc->DrawLine(TPoint(0,0) + iOffset, TPoint(size.iWidth, height) + iOffset);
00075 gc->DiscardFont();
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 void CNumberedWindow::HandlePointerEvent (TPointerEvent& aPointerEvent)
00085 {
00086 switch (aPointerEvent.iType)
00087 {
00088 case TPointerEvent::EButton1Down:
00089 {
00090 Window().Scroll(TPoint(0,-2));
00091 iOffset += TPoint(0,-2);
00092 iRepeatRect.iTl = aPointerEvent.iPosition - TPoint(10,10);
00093 iRepeatRect.iBr = aPointerEvent.iPosition + TPoint(10,10);
00094 iScrollDir = Up;
00095 Window().RequestPointerRepeatEvent(TTimeIntervalMicroSeconds32 (20000), iRepeatRect);
00096 break;
00097 }
00098 case TPointerEvent::EButtonRepeat:
00099 {
00100 if (iScrollDir == Up)
00101 {
00102 Window().Scroll(TPoint(0,-2));
00103 iOffset += TPoint(0,-2);
00104 }
00105 else
00106 {
00107 Window().Scroll(TPoint(0,2));
00108 iOffset += TPoint(0,2);
00109 }
00110 Window().RequestPointerRepeatEvent(TTimeIntervalMicroSeconds32 (20000), iRepeatRect);
00111 break;
00112 }
00113 case TPointerEvent::EButton3Down:
00114 {
00115 Window().Scroll(TPoint(0,2));
00116 iOffset += TPoint(0,2);
00117 iRepeatRect.iTl = aPointerEvent.iPosition - TPoint(10,10);
00118 iRepeatRect.iBr = aPointerEvent.iPosition + TPoint(10,10);
00119 iScrollDir = Down;
00120 Window().RequestPointerRepeatEvent(TTimeIntervalMicroSeconds32 (100000), iRepeatRect);
00121 break;
00122 }
00123 default:
00124 break;
00125 }
00126 }
00127
00128
00130
00132
00133
00134
00135
00136
00137
00138 CMainWindow::CMainWindow (CWsClient* aClient)
00139 : CWindow (aClient)
00140 {
00141 }
00142
00143 CMainWindow::~CMainWindow ()
00144 {
00145 iWindow.Close();
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 void CMainWindow::Draw(const TRect& aRect)
00157 {
00158 CWindowGc* gc=SystemGc();
00159 gc->SetClippingRect(aRect);
00160 gc->Clear(aRect);
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170 void CMainWindow::HandlePointerEvent (TPointerEvent& aPointerEvent)
00171 {
00172 switch (aPointerEvent.iType)
00173 {
00174 case TPointerEvent::EButton1Down:
00175 case TPointerEvent::EButton1Up:
00176 break;
00177 default:
00178 break;
00179 }
00180 }
00181
00182
00184
00186
00187 CExampleWsClient* CExampleWsClient::NewL(const TRect& aRect)
00188 {
00189
00190 CExampleWsClient* client=new (ELeave) CExampleWsClient(aRect);
00191 CleanupStack::PushL(client);
00192 client->ConstructL();
00193 CleanupStack::Pop();
00194 return client;
00195 }
00196
00197
00198
00199
00200
00201
00202
00203 CExampleWsClient::CExampleWsClient(const TRect& aRect)
00204 :iRect(aRect)
00205 {
00206 }
00207
00208 CExampleWsClient::~CExampleWsClient ()
00209 {
00210 delete iMainWindow;
00211 delete iWindow1;
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 void CExampleWsClient::ConstructMainWindowL()
00223 {
00224 iMainWindow=new (ELeave) CMainWindow(this);
00225 iMainWindow->ConstructL(iRect, TRgb (255,255,255));
00226 iWindow1 = new (ELeave) CNumberedWindow (this,1);
00227 TRect rec(iRect);
00228 rec.Resize(-50,-50);
00229 iWindow1->ConstructL (rec, TRgb (200, 200, 200),iMainWindow);
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 void CExampleWsClient::RunL()
00242 {
00243
00244 iWs.GetEvent(iWsEvent);
00245 TInt eventType=iWsEvent.Type();
00246
00247 switch (eventType)
00248 {
00249
00250 case EEventNull:
00251 break;
00252 case EEventKey:
00253 {
00254 TKeyEvent& keyEvent=*iWsEvent.Key();
00255 HandleKeyEventL (keyEvent);
00256 break;
00257 }
00258 case EEventModifiersChanged:
00259 break;
00260 case EEventKeyUp:
00261 case EEventKeyDown:
00262 case EEventFocusLost:
00263 case EEventFocusGained:
00264 case EEventSwitchOn:
00265 case EEventPassword:
00266 case EEventWindowGroupsChanged:
00267 case EEventErrorMessage:
00268 break;
00269
00270 case EEventPointer:
00271 {
00272 CWindow* window=(CWindow*)(iWsEvent.Handle());
00273 TPointerEvent& pointerEvent=*iWsEvent.Pointer();
00274 window->HandlePointerEvent (pointerEvent);
00275 break;
00276 }
00277 case EEventPointerExit:
00278 case EEventPointerEnter:
00279 case EEventPointerBufferReady:
00280 case EEventDragDrop:
00281 break;
00282 default:
00283 break;
00284 }
00285 IssueRequest();
00286 }
00287
00288
00289
00290
00291
00292 void CExampleWsClient::HandleKeyEventL (TKeyEvent& )
00293 {
00294 }
00295