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