diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_ordinal_8cpp-source.html --- a/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_ordinal_8cpp-source.html Tue Mar 30 11:56:28 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,380 +0,0 @@ - -
-00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). -00002 // All rights reserved. -00003 // This component and the accompanying materials are made available -00004 // under the terms of "Eclipse Public License v1.0" -00005 // which accompanies this distribution, and is available -00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". -00007 // -00008 // Initial Contributors: -00009 // Nokia Corporation - initial contribution. -00010 // -00011 // Contributors: -00012 // -00013 // Description: -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 // CNumberedWindow implementation -00029 -00030 /****************************************************************************\ -00031 | Function: Constructor/Destructor for CNumberedWindow -00032 | Input: aClient Client application that owns the window -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 | Function: CNumberedWindow::Draw -00047 | Purpose: Redraws the contents of CNumberedWindow within a given -00048 | rectangle. CNumberedWindow displays a number in the window. -00049 | Input: aRect Rectangle that needs redrawing -00050 | Output: None -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(); // get a graphics context -00062 gc->SetClippingRect(aRect); // clip outside the redraw area -00063 gc->Clear(aRect); // clear the redraw area -00064 TSize size=iWindow.Size(); -00065 TInt height=size.iHeight; // Need window height to calculate vertical text offset -00066 TInt ascent = Font()->AscentInPixels(); -00067 TInt descent = Font()->DescentInPixels(); -00068 TInt offset = (height + (ascent + descent)) / 2; // Calculate vertical text offset -00069 gc->SetPenColor(TRgb(0,0,0)); // Set pen to black -00070 gc->UseFont(Font()); -00071 gc->DrawText(strings[iNumber], TRect(TPoint(0,0), size), offset, CGraphicsContext::ECenter); -00072 gc->DiscardFont(); -00073 } -00074 -00075 /****************************************************************************\ -00076 | Function: CNumberedWindow::HandlePointerEvent -00077 | Purpose: Handles pointer events for CNumberedWindow. -00078 | Input: aPointerEvent The pointer event -00079 | Output: None -00080 \****************************************************************************/ -00081 void CNumberedWindow::HandlePointerEvent (TPointerEvent& aPointerEvent) -00082 { -00083 switch (aPointerEvent.iType) -00084 { -00085 case TPointerEvent::EDrag: -00086 { -00087 // Move the window position as the pointer is dragged. -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 // Move window to front -00098 Window().SetOrdinalPosition (0); -00099 // Request drag events -00100 Window().PointerFilter (EPointerFilterDrag, 0); -00101 // Initialize starting point for dragging -00102 iOldPos = aPointerEvent.iParentPosition; -00103 break; -00104 } -00105 case TPointerEvent::EButton1Up: -00106 { -00107 // Cancel the request for drag events. -00108 Window().PointerFilter (EPointerFilterDrag, EPointerFilterDrag); -00109 break; -00110 } -00111 case TPointerEvent::EButton3Down: -00112 { -00113 // Cascade windows in top left corner. -00114 // Window at the front should be cascaded last. -00115 // The window at the front (ordinal position 0) is given by Child(), and -00116 // each window behind it is given by NextSibling(). We need to go down -00117 // the sibling list till we get to the last sibling, and move this to -00118 // the top left corner. Then go back up the list and move each previous -00119 // sibling on top of the last, displaced by an offset (of TPoint(10,10)). -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 // CMainWindow implementation -00158 -00159 -00160 /****************************************************************************\ -00161 | Function: Constructor/Destructor for CMainWindow -00162 | Input: aClient Client application that owns the window -00163 \****************************************************************************/ -00164 CMainWindow::CMainWindow (CWsClient* aClient) -00165 : CWindow (aClient) -00166 { -00167 } -00168 -00169 -00170 CMainWindow::~CMainWindow () -00171 { -00172 iWindow.Close(); -00173 } -00174 -00175 /****************************************************************************\ -00176 | Function: CMainWindow::Draw -00177 | Purpose: Redraws the contents of CMainWindow within a given -00178 | rectangle. -00179 | Input: aRect Rectangle that needs redrawing -00180 | Output: None -00181 \****************************************************************************/ -00182 -00183 void CMainWindow::Draw(const TRect& aRect) -00184 { -00185 CWindowGc* gc=SystemGc(); // get a gc -00186 gc->SetClippingRect(aRect); // clip outside this rect -00187 gc->Clear(aRect); // clear -00188 } -00189 -00190 -00191 /****************************************************************************\ -00192 | Function: CMainWindow::HandlePointerEvent -00193 | Purpose: Handles pointer events for CMainWindow. -00194 | Input: aPointerEvent The pointer event! -00195 | Output: None -00196 \****************************************************************************/ -00197 -00198 void CMainWindow::HandlePointerEvent (TPointerEvent& aPointerEvent) -00199 { -00200 switch (aPointerEvent.iType) -00201 { -00202 case TPointerEvent::EButton3Down: -00203 { -00204 // Cascade windows in top left corner -00205 // Window at the front should be cascaded last. -00206 // The window at the front (ordinal position 0) is given by Child(), and -00207 // each window behind it is given by NextSibling(). We need to go down -00208 // the sibling list till we get to the last sibling, and move this to -00209 // the top left corner. Then go back up the list and move each previous -00210 // sibling on top of the last, displaced by an offset (of TPoint(10,10)). -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 // CExampleWsClient implementation -00249 -00250 CExampleWsClient* CExampleWsClient::NewL(const TRect& aRect) -00251 { -00252 // make new client -00253 CExampleWsClient* client=new (ELeave) CExampleWsClient(aRect); -00254 CleanupStack::PushL(client); // push, just in case -00255 client->ConstructL(); // construct and run -00256 CleanupStack::Pop(); -00257 return client; -00258 } -00259 -00260 /****************************************************************************\ -00261 | Function: Constructor/Destructor for CExampleWsClient -00262 | Destructor deletes everything that was allocated by -00263 | ConstructMainWindowL() -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 | Function: CExampleWsClient::ConstructMainWindowL() -00284 | Called by base class's ConstructL -00285 | Purpose: Allocates and creates all the windows owned by this client -00286 | (See list of windows in CExampleWsCLient declaration). -00287 \****************************************************************************/ -00288 -00289 void CExampleWsClient::ConstructMainWindowL() -00290 { -00291 // Resources allocated in this function are freed in the CExampleWsClient destructor -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 | Function: CExampleWsClient::RunL() -00313 | Called by active scheduler when an even occurs -00314 | Purpose: Processes events according to their type -00315 | For key events: calls HandleKeyEventL() (global to client) -00316 | For pointer event: calls HandlePointerEvent() for window -00317 | event occurred in. -00318 \****************************************************************************/ -00319 void CExampleWsClient::RunL() -00320 { -00321 // get the event -00322 iWs.GetEvent(iWsEvent); -00323 TInt eventType=iWsEvent.Type(); -00324 // take action on it -00325 switch (eventType) -00326 { -00327 // events global within window group -00328 case EEventNull: -00329 break; -00330 case EEventKey: -00331 { -00332 TKeyEvent& keyEvent=*iWsEvent.Key(); // get key event -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 // events local to specific windows -00347 case EEventPointer: -00348 { -00349 CWindow* window=(CWindow*)(iWsEvent.Handle()); // get window -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(); // maintain outstanding request -00364 } -00365 -00366 /****************************************************************************\ -00367 | Function: CExampleWsClient::HandleKeyEventL() -00368 | Purpose: Processes key events for CExampleWsClient -00369 | Gets the key code from the key event. Exits on 'Escape' -00370 \****************************************************************************/ -00371 void CExampleWsClient::HandleKeyEventL (TKeyEvent& /*aKeyEvent*/) -00372 { -00373 } -00374 -