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 "Simple.h" 00019 00020 00022 // Implementation for derived window classes 00024 00026 // CMainWindow implementation // 00028 00029 /****************************************************************************\ 00030 | Function: Constructor/Destructor for CMainWindow 00031 | Doesn't do much, as most initialisation is done by the 00032 | CWindow base class. 00033 | Input: aClient Client application that owns the window 00034 \****************************************************************************/ 00035 CMainWindow::CMainWindow (CWsClient* aClient) 00036 : CWindow (aClient) 00037 { 00038 } 00039 00040 00041 CMainWindow::~CMainWindow () 00042 { 00043 } 00044 00045 00046 /****************************************************************************\ 00047 | Function: CMainWindow::Draw 00048 | Purpose: Redraws the contents of CMainWindow within a given 00049 | rectangle. As CMainWindow has no contents, it simply 00050 | clears the redraw area. A blank window could be used here 00051 | instead. The Clear() is needed because a redraw should 00052 | always draw to every pixel in the redraw rectangle. 00053 | Input: aRect Rectangle that needs redrawing 00054 | Output: None 00055 \****************************************************************************/ 00056 void CMainWindow::Draw(const TRect& aRect) 00057 { 00058 CWindowGc* gc=SystemGc(); // get a gc 00059 gc->SetClippingRect(aRect); // clip outside this rect 00060 gc->Clear(aRect); // clear 00061 } 00062 00063 /****************************************************************************\ 00064 | Function: CMainWindow::HandlePointerEvent 00065 | Purpose: Handles pointer events for CMainWindow. Doesn't do 00066 | anything here. 00067 | Input: aPointerEvent The pointer event 00068 | Output: None 00069 \****************************************************************************/ 00070 void CMainWindow::HandlePointerEvent (TPointerEvent& /*aPointerEvent*/) 00071 { 00072 } 00073 00074 00076 // CSmallWindow implementation 00078 00079 00080 /****************************************************************************\ 00081 | Function: Constructor/Destructor for CSmallWindow 00082 | Doesn't do much, as most initialisation is done by the 00083 | CWindow base class. 00084 | Input: aClient Client application that owns the window 00085 \****************************************************************************/ 00086 00087 CSmallWindow::CSmallWindow (CWsClient* aClient) 00088 : CWindow (aClient) 00089 { 00090 } 00091 00092 00093 CSmallWindow::~CSmallWindow () 00094 { 00095 iWindow.Close(); 00096 } 00097 00098 /****************************************************************************\ 00099 | Function: CSmallWindow::Draw 00100 | Purpose: Redraws the contents of CSmallWindow within a given 00101 | rectangle. CSmallWindow displays a square border around 00102 | the edges of the window, and two diagonal lines between the 00103 | corners. 00104 | Input: aRect Rectangle that needs redrawing 00105 | Output: None 00106 \****************************************************************************/ 00107 void CSmallWindow::Draw(const TRect& aRect) 00108 { 00109 // Drawing to a window is done using functions supplied by 00110 // the graphics context (CWindowGC), not the window. 00111 CWindowGc* gc=SystemGc(); // get a gc 00112 gc->SetClippingRect(aRect); // clip outside this rect 00113 gc->Clear(aRect); // clear 00114 TSize size=iWindow.Size(); 00115 TInt width=size.iWidth; 00116 TInt height=size.iHeight; 00117 // Draw a square border 00118 gc->DrawLine(TPoint(0,0),TPoint(0,height-1)); 00119 gc->DrawLine (TPoint (0, height-1), TPoint (width-1, height-1)); 00120 gc->DrawLine(TPoint(width-1,height-1),TPoint(width-1,0)); 00121 gc->DrawLine (TPoint (width-1, 0), TPoint (0, 0)); 00122 // Draw a line between the corners of the window 00123 gc->DrawLine(TPoint(0,0),TPoint(width, height)); 00124 gc->DrawLine (TPoint (0, height), TPoint (width, 0)); 00125 } 00126 00127 /****************************************************************************\ 00128 | Function: CSmallWindow::HandlePointerEvent 00129 | Purpose: Handles pointer events for CSmallWindow. Doesn't do 00130 | anything here. 00131 | Input: aPointerEvent The pointer event 00132 | Output: None 00133 \****************************************************************************/ 00134 00135 void CSmallWindow::HandlePointerEvent (TPointerEvent& /*aPointerEvent*/) 00136 { 00137 } 00138 00140 // CExampleWsClient implementation // 00142 00143 CExampleWsClient* CExampleWsClient::NewL(const TRect& aRect) 00144 { 00145 // make new client 00146 CExampleWsClient* client=new (ELeave) CExampleWsClient(aRect); 00147 CleanupStack::PushL(client); // push, just in case 00148 client->ConstructL(); // construct and run 00149 CleanupStack::Pop(); 00150 return client; 00151 } 00152 00153 /****************************************************************************\ 00154 | Function: Constructor/Destructor for CExampleWsClient 00155 | Destructor deletes everything that was allocated by 00156 | ConstructMainWindowL() 00157 \****************************************************************************/ 00158 00159 CExampleWsClient::CExampleWsClient(const TRect& aRect) 00160 :iRect(aRect) 00161 { 00162 } 00163 00164 CExampleWsClient::~CExampleWsClient () 00165 { 00166 delete iMainWindow; 00167 delete iSmallWindow; 00168 } 00169 00170 00171 /****************************************************************************\ 00172 | Function: CExampleWsClient::ConstructMainWindowL() 00173 | Called by base class's ConstructL 00174 | Purpose: Allocates and creates all the windows owned by this client 00175 | (See list of windows in CExampleWsCLient declaration). 00176 \****************************************************************************/ 00177 00178 void CExampleWsClient::ConstructMainWindowL() 00179 { 00180 iMainWindow=new (ELeave) CMainWindow(this); 00181 iMainWindow->ConstructL(iRect); 00182 iSmallWindow = new (ELeave) CSmallWindow (this); 00183 iSmallWindow->ConstructL (TRect (TPoint (100, 75), TSize (50, 50)), iMainWindow); 00184 } 00185 00186 00187 /****************************************************************************\ 00188 | Function: CExampleWsClient::RunL() 00189 | Called by active scheduler when an even occurs 00190 | Purpose: Processes events according to their type 00191 | For key events: calls HandleKeyEventL() (global to client) 00192 | For pointer event: calls HandlePointerEvent() for window 00193 | event occurred in. 00194 \****************************************************************************/ 00195 void CExampleWsClient::RunL() 00196 { 00197 // get the event 00198 iWs.GetEvent(iWsEvent); 00199 TInt eventType=iWsEvent.Type(); 00200 // take action on it 00201 switch (eventType) 00202 { 00203 // window-group related event types 00204 case EEventNull: 00205 break; 00206 case EEventKey: 00207 { 00208 TKeyEvent& keyEvent=*iWsEvent.Key(); // get key event 00209 HandleKeyEventL (keyEvent); 00210 break; 00211 } 00212 case EEventKeyUp: 00213 case EEventKeyDown: 00214 case EEventModifiersChanged: 00215 case EEventFocusLost: 00216 case EEventFocusGained: 00217 case EEventSwitchOn: 00218 case EEventPassword: 00219 case EEventWindowGroupsChanged: 00220 case EEventErrorMessage: 00221 break; 00222 // window related events 00223 case EEventPointer: 00224 { 00225 CWindow* window=(CWindow*)(iWsEvent.Handle()); // get window 00226 TPointerEvent& pointerEvent=*iWsEvent.Pointer(); 00227 window->HandlePointerEvent (pointerEvent); 00228 00229 break; 00230 } 00231 case EEventPointerEnter: 00232 case EEventPointerExit: 00233 case EEventPointerBufferReady: 00234 case EEventDragDrop: 00235 break; 00236 default: 00237 break; 00238 } 00239 IssueRequest(); // maintain outstanding request 00240 } 00241 00242 void CExampleWsClient::HandleKeyEventL(struct TKeyEvent& /*aKeyEvent*/) 00243 { 00244 }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.