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