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 #include <w32std.h>
00032 #include "Base.h"
00033 #include "Ordinal.h"
00034
00035 _LIT(KString1,"1");
00036 _LIT(KString2,"2");
00037 _LIT(KString3,"3");
00038 _LIT(KString4,"4");
00039 _LIT(KString5,"5");
00040
00042
00044
00045
00046
00047
00048
00049 CNumberedWindow::CNumberedWindow (CWsClient* aClient, TInt aNum)
00050 : CWindow (aClient), iNumber(aNum), iOldPos(0,0)
00051 {
00052 }
00053
00054
00055 CNumberedWindow::~CNumberedWindow ()
00056 {
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 void CNumberedWindow::Draw(const TRect& aRect)
00068 {
00069 const TBufC<1> strings[5] = { *&KString1,
00070 *&KString2,
00071 *&KString3,
00072 *&KString4,
00073 *&KString5
00074 };
00075
00076 CWindowGc* gc=SystemGc();
00077 gc->SetClippingRect(aRect);
00078 gc->Clear(aRect);
00079 TSize size=iWindow.Size();
00080 TInt height=size.iHeight;
00081 TInt ascent = Font()->AscentInPixels();
00082 TInt descent = Font()->DescentInPixels();
00083 TInt offset = (height + (ascent + descent)) / 2;
00084 gc->SetPenColor(TRgb(0,0,0));
00085 gc->UseFont(Font());
00086 gc->DrawText(strings[iNumber], TRect(TPoint(0,0), size), offset, CGraphicsContext::ECenter);
00087 gc->DiscardFont();
00088 }
00089
00090
00091
00092
00093
00094
00095
00096 void CNumberedWindow::HandlePointerEvent (TPointerEvent& aPointerEvent)
00097 {
00098 switch (aPointerEvent.iType)
00099 {
00100 case TPointerEvent::EDrag:
00101 {
00102
00103 TPoint point = aPointerEvent.iParentPosition;
00104 TPoint distToMove = point - iOldPos;
00105 TPoint position = Window().Position();
00106 Window().SetPosition (position + distToMove);
00107 iOldPos = point;
00108 break;
00109 }
00110 case TPointerEvent::EButton1Down:
00111 {
00112
00113 Window().SetOrdinalPosition (0);
00114
00115 Window().PointerFilter (EPointerFilterDrag, 0);
00116
00117 iOldPos = aPointerEvent.iParentPosition;
00118 break;
00119 }
00120 case TPointerEvent::EButton1Up:
00121 {
00122
00123 Window().PointerFilter (EPointerFilterDrag, EPointerFilterDrag);
00124 break;
00125 }
00126 case TPointerEvent::EButton3Down:
00127 {
00128
00129
00130
00131
00132
00133
00134
00135 TPoint point (0,0);
00136 TUint32 nextSib, prevSib;
00137 CWindow* childWindow;
00138 TInt numChildren = 0;
00139 TUint32 child = Window().Child();
00140 if (child)
00141 {
00142 childWindow = (CWindow*)child;
00143 numChildren++;
00144 nextSib = childWindow->Window().NextSibling();
00145 while (nextSib)
00146 {
00147 numChildren++;
00148 childWindow = (CWindow*)nextSib;
00149 nextSib = childWindow->Window().NextSibling();
00150 }
00151 for (TInt i=numChildren; i>0; i--)
00152 {
00153 childWindow->Window().SetPosition (point);
00154 prevSib = childWindow->Window().PrevSibling();
00155 if (prevSib)
00156 {
00157 childWindow = (CWindow*)prevSib;
00158 point += TPoint(10,10);
00159 }
00160 }
00161 }
00162 break;
00163 }
00164 default:
00165 break;
00166 }
00167 }
00168
00169
00171
00173
00174
00175
00176
00177
00178
00179 CMainWindow::CMainWindow (CWsClient* aClient)
00180 : CWindow (aClient)
00181 {
00182 }
00183
00184
00185 CMainWindow::~CMainWindow ()
00186 {
00187 iWindow.Close();
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 void CMainWindow::Draw(const TRect& aRect)
00199 {
00200 CWindowGc* gc=SystemGc();
00201 gc->SetClippingRect(aRect);
00202 gc->Clear(aRect);
00203 }
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 void CMainWindow::HandlePointerEvent (TPointerEvent& aPointerEvent)
00214 {
00215 switch (aPointerEvent.iType)
00216 {
00217 case TPointerEvent::EButton3Down:
00218 {
00219
00220
00221
00222
00223
00224
00225
00226 TPoint point (0,0);
00227 TUint32 nextSib, prevSib;
00228 CWindow* childWindow;
00229 TInt numChildren = 0;
00230 TUint32 child = Window().Child();
00231 if (child)
00232 {
00233 childWindow = (CWindow*)child;
00234 numChildren++;
00235 nextSib = childWindow->Window().NextSibling();
00236 while (nextSib)
00237 {
00238 numChildren++;
00239 childWindow = (CWindow*)nextSib;
00240 nextSib = childWindow->Window().NextSibling();
00241 }
00242 for (TInt i=numChildren; i>0; i--)
00243 {
00244 childWindow->Window().SetPosition (point);
00245 prevSib = childWindow->Window().PrevSibling();
00246 if (prevSib)
00247 {
00248 childWindow = (CWindow*)prevSib;
00249 point += TPoint(10,10);
00250 }
00251 }
00252 }
00253 break;
00254 }
00255 default:
00256 break;
00257 }
00258 }
00259
00260
00262
00264
00265 CExampleWsClient* CExampleWsClient::NewL(const TRect& aRect)
00266 {
00267
00268 CExampleWsClient* client=new (ELeave) CExampleWsClient(aRect);
00269 CleanupStack::PushL(client);
00270 client->ConstructL();
00271 CleanupStack::Pop();
00272 return client;
00273 }
00274
00275
00276
00277
00278
00279
00280
00281 CExampleWsClient::CExampleWsClient(const TRect& aRect)
00282 :iRect(aRect)
00283 {
00284 }
00285
00286 CExampleWsClient::~CExampleWsClient ()
00287 {
00288 delete iWindow1;
00289 delete iWindow2;
00290 delete iWindow3;
00291 delete iWindow4;
00292 delete iWindow5;
00293 delete iMainWindow;
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 void CExampleWsClient::ConstructMainWindowL()
00305 {
00306
00307
00308 iMainWindow=new (ELeave) CMainWindow(this);
00309 iMainWindow->ConstructL(iRect, TRgb (255,255,255));
00310 TInt count=0;
00311 TRect rect(0,0,40,40);
00312 iWindow1 = new (ELeave) CNumberedWindow (this, count++);
00313 iWindow1->ConstructL (rect, TRgb (50, 50, 50),iMainWindow);
00314 iWindow2 = new (ELeave) CNumberedWindow (this, count++);
00315 iWindow2->ConstructL (rect, TRgb (100, 100, 100),iMainWindow);
00316 iWindow3 = new (ELeave) CNumberedWindow (this, count++);
00317 iWindow3->ConstructL (rect, TRgb (150, 150, 150),iMainWindow);
00318 iWindow4 = new (ELeave) CNumberedWindow (this, count++);
00319 rect.Shrink(10,10);
00320 iWindow4->ConstructL (rect, TRgb (200, 200, 200),iWindow1);
00321 iWindow5 = new (ELeave) CNumberedWindow (this, count++);
00322 iWindow5->ConstructL (rect, TRgb (150, 150, 150),iWindow1);
00323 }
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 void CExampleWsClient::RunL()
00335 {
00336
00337 iWs.GetEvent(iWsEvent);
00338 TInt eventType=iWsEvent.Type();
00339
00340 switch (eventType)
00341 {
00342
00343 case EEventNull:
00344 break;
00345 case EEventKey:
00346 {
00347 TKeyEvent& keyEvent=*iWsEvent.Key();
00348 HandleKeyEventL (keyEvent);
00349 break;
00350 }
00351 case EEventKeyUp:
00352 case EEventModifiersChanged:
00353 case EEventKeyDown:
00354 case EEventFocusLost:
00355 case EEventFocusGained:
00356 case EEventSwitchOn:
00357 case EEventPassword:
00358 case EEventWindowGroupsChanged:
00359 case EEventErrorMessage:
00360 break;
00361
00362 case EEventPointer:
00363 {
00364 CWindow* window=(CWindow*)(iWsEvent.Handle());
00365 TPointerEvent& pointerEvent=*iWsEvent.Pointer();
00366 window->HandlePointerEvent (pointerEvent);
00367 break;
00368 }
00369 case EEventPointerExit:
00370 case EEventPointerEnter:
00371 case EEventPointerBufferReady:
00372 break;
00373 case EEventDragDrop:
00374 break;
00375 default:
00376 break;
00377 }
00378 IssueRequest();
00379 }
00380
00381
00382
00383
00384
00385
00386 void CExampleWsClient::HandleKeyEventL (TKeyEvent& )
00387 {
00388 }
00389