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 "BackedUp.h"
00034
00035 _LIT(KString1,"1");
00036 _LIT(KString2,"2");
00037 _LIT(KString3,"3");
00038 _LIT(KString4,"4");
00039 _LIT(KString5,"5");
00040
00041 enum TBackedUpPanic
00042 {
00043 EConnectPanicRedrawToBackedUpWindow,
00044 };
00045
00046
00048
00050
00051
00052
00053
00054
00055 CNumberedWindow::CNumberedWindow (CWsClient* aClient)
00056 : CWindow (aClient), iOldPos(0,0)
00057 {
00058
00059 iNumber = iCount;
00060 iCount++;
00061 }
00062
00063
00064 CNumberedWindow::~CNumberedWindow ()
00065 {
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 void CNumberedWindow::Draw(const TRect& aRect)
00077 {
00078 const TBufC<1> strings[5] = { *&KString1,
00079 *&KString2,
00080 *&KString3,
00081 *&KString4,
00082 *&KString5
00083 };
00084
00085 CWindowGc* gc=SystemGc();
00086 gc->SetClippingRect(aRect);
00087 gc->Clear(aRect);
00088 TSize size=iWindow.Size();
00089 TInt height=size.iHeight;
00090 TInt ascent = Font()->AscentInPixels();
00091 TInt descent = Font()->DescentInPixels();
00092 TInt offset = (height + (ascent + descent)) / 2;
00093 gc->SetPenColor(TRgb(0,0,0));
00094 gc->UseFont(Font());
00095 gc->DrawText(strings[iNumber], TRect(TPoint(0,0), size), offset, CGraphicsContext::ECenter);
00096 gc->DiscardFont();
00097 }
00098
00099
00100
00101
00102
00103
00104
00105 void CNumberedWindow::HandlePointerEvent (TPointerEvent& aPointerEvent)
00106 {
00107 switch (aPointerEvent.iType)
00108 {
00109 case TPointerEvent::EDrag:
00110 {
00111 TPoint point = aPointerEvent.iParentPosition;
00112 TPoint distToMove = point - iOldPos;
00113 TPoint position = Window().Position();
00114 Window().SetPosition (position + distToMove);
00115 iOldPos = point;
00116 break;
00117 }
00118 case TPointerEvent::EButton1Down:
00119 {
00120
00121 Window().PointerFilter (EPointerFilterDrag, 0);
00122 Window().SetOrdinalPosition (0);
00123 iOldPos = aPointerEvent.iParentPosition;
00124 break;
00125 }
00126 case TPointerEvent::EButton1Up:
00127 {
00128
00129 Window().PointerFilter (EPointerFilterDrag, EPointerFilterDrag);
00130 break;
00131 }
00132 default:
00133 break;
00134 }
00135 }
00136
00137
00139
00141
00142
00143
00144
00145
00146
00147 CMainWindow::CMainWindow (CWsClient* aClient)
00148 : CBackedUpWindow (aClient)
00149 {
00150 }
00151
00152
00153 CMainWindow::~CMainWindow ()
00154 {
00155 iWindow.Close();
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 void CMainWindow::Draw(const TRect& )
00167 {
00168 _LIT(KPanicMsg,"BACKEDUP");
00169 User::Panic(KPanicMsg,EConnectPanicRedrawToBackedUpWindow);
00170 }
00171
00172 void CMainWindow::HandlePointerMoveBufferReady ()
00173 {
00174 TPoint pnts[KPointerMoveBufferSize];
00175 TPtr8 ptr((TUint8 *)&pnts,sizeof(pnts));
00176 TInt numPnts=Window().RetrievePointerMoveBuffer(ptr);
00177 CWindowGc* gc=SystemGc();
00178 gc->Activate(Window());
00179 for(TInt index=0;index<numPnts;index++) gc->DrawLineTo(pnts[index]);
00180 gc->Deactivate();
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190 void CMainWindow::HandlePointerEvent (TPointerEvent& aPointerEvent)
00191 {
00192 switch (aPointerEvent.iType)
00193 {
00194 case TPointerEvent::EButton1Down:
00195 {
00196 Window().SetShadowDisabled(EFalse);
00197 Window().EnablePointerMoveBuffer();
00198 CWindowGc* gc = SystemGc();
00199 gc->Activate(Window());
00200 gc->MoveTo(aPointerEvent.iPosition);
00201 gc->Deactivate();
00202 }
00203 default:
00204 break;
00205 }
00206 }
00207
00208
00210
00212
00213 CExampleWsClient* CExampleWsClient::NewL(const TRect& aRect)
00214 {
00215
00216 CExampleWsClient* client=new (ELeave) CExampleWsClient(aRect);
00217 CleanupStack::PushL(client);
00218 client->ConstructL();
00219 CleanupStack::Pop();
00220 return client;
00221 }
00222
00223
00224
00225
00226
00227
00228
00229 CExampleWsClient::CExampleWsClient(const TRect& aRect)
00230 :iRect(aRect)
00231 {
00232 }
00233
00234 CExampleWsClient::~CExampleWsClient ()
00235 {
00236 delete iMainWindow;
00237 delete iWindow1;
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 void CExampleWsClient::ConstructMainWindowL()
00249 {
00250
00251
00252 iMainWindow=new (ELeave) CMainWindow(this);
00253 iMainWindow->ConstructL(iRect);
00254 iWindow1 = new (ELeave) CNumberedWindow (this);
00255 iWindow1->ConstructL (TRect (TPoint (100, 100), TSize (100, 100)), TRgb (100, 100, 100),
00256 iMainWindow);
00257 }
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 void CExampleWsClient::RunL()
00269 {
00270
00271 iWs.GetEvent(iWsEvent);
00272 TInt eventType=iWsEvent.Type();
00273
00274 switch (eventType)
00275 {
00276
00277 case EEventNull:
00278 break;
00279 case EEventKey:
00280 {
00281 TKeyEvent& keyEvent=*iWsEvent.Key();
00282 HandleKeyEventL (keyEvent);
00283 break;
00284 }
00285 case EEventKeyUp:
00286 case EEventModifiersChanged:
00287 case EEventKeyDown:
00288 case EEventFocusLost:
00289 case EEventFocusGained:
00290 case EEventSwitchOn:
00291 case EEventPassword:
00292 case EEventWindowGroupsChanged:
00293 case EEventErrorMessage:
00294 break;
00295
00296 case EEventPointer:
00297 {
00298 CWindow* window=(CWindow*)(iWsEvent.Handle());
00299 TPointerEvent& pointerEvent=*iWsEvent.Pointer();
00300 window->HandlePointerEvent (pointerEvent);
00301 break;
00302 }
00303 case EEventPointerExit:
00304 case EEventPointerEnter:
00305 case EEventPointerBufferReady:
00306 {
00307 CWindow* window=(CWindow*)(iWsEvent.Handle());
00308 window->HandlePointerMoveBufferReady ();
00309 break;
00310 }
00311 case EEventDragDrop:
00312 break;
00313 default:
00314 break;
00315 }
00316 IssueRequest();
00317 }
00318
00319
00320
00321
00322
00323 void CExampleWsClient::HandleKeyEventL (TKeyEvent& )
00324 {
00325 }
00326
00327