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