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 // @file 00015 // 00016 00017 #include <w32std.h> 00018 #include "Base.h" 00019 00021 // CWindow implementation 00023 00024 CWindow::CWindow(CWsClient* aClient) 00025 : iClient(aClient) 00026 { 00027 } 00028 00029 void CWindow::ConstructL (const TRect& aRect, const TRgb& aColor, CWindow* aParent) 00030 { 00031 _LIT(KFontName,"Swiss"); 00032 // If a parent window was specified, use it; if not, use the window group 00033 // (aParent defaults to 0). 00034 RWindowTreeNode* parent= aParent ? (RWindowTreeNode*) &(aParent->Window()) : &(iClient->iGroup); 00035 // Allocate and construct the window 00036 iWindow=RWindow(iClient->iWs); 00037 User::LeaveIfError(iWindow.Construct(*parent,(TUint32)this)); 00038 // Store the window's extent 00039 iRect = aRect; 00040 // Set up the new window's extent 00041 iWindow.SetExtent(iRect.iTl, iRect.Size()); 00042 // Set its background color 00043 iWindow.SetBackgroundColor (aColor); 00044 // Set up font for displaying text 00045 TFontSpec fontSpec(KFontName,200); 00046 User::LeaveIfError(iClient->iScreen->GetNearestFontInTwips(iFont,fontSpec)); 00047 // Activate the window 00048 iWindow.Activate(); 00049 } 00050 00051 CWindow::~CWindow() 00052 { 00053 iWindow.Close(); 00054 iClient->iScreen->ReleaseFont(iFont); 00055 } 00056 00057 RWindow& CWindow::Window() 00058 { 00059 return iWindow; 00060 } 00061 00062 CWindowGc* CWindow::SystemGc() 00063 { 00064 return iClient->iGc; 00065 } 00066 00067 CWsScreenDevice* CWindow::Screen() 00068 { 00069 return iClient->iScreen; 00070 } 00071 00072 CFont* CWindow::Font() 00073 { 00074 return iFont; 00075 } 00076 00077 00079 // CWsRedrawer implementation 00081 00082 CWsRedrawer::CWsRedrawer() 00083 : CActive(CActive::EPriorityLow) 00084 { 00085 } 00086 00087 void CWsRedrawer::ConstructL(CWsClient* aClient) 00088 { 00089 iClient=aClient; // remember WsClient that owns us 00090 CActiveScheduler::Add(this); // add ourselves to the scheduler 00091 IssueRequest(); // issue request to draw 00092 } 00093 00094 CWsRedrawer::~CWsRedrawer() 00095 { 00096 Cancel(); 00097 } 00098 00099 void CWsRedrawer::IssueRequest() 00100 { 00101 iClient->iWs.RedrawReady(&iStatus); 00102 SetActive(); 00103 } 00104 00105 void CWsRedrawer::DoCancel() 00106 { 00107 iClient->iWs.RedrawReadyCancel(); 00108 } 00109 00110 void CWsRedrawer::RunL() 00111 { 00112 // find out what needs to be done in response to the event 00113 TWsRedrawEvent redrawEvent; 00114 iClient->iWs.GetRedraw(redrawEvent); // get event 00115 CWindow* window=(CWindow*)(redrawEvent.Handle()); // get window 00116 if (window) 00117 { 00118 TRect rect=redrawEvent.Rect(); // and rectangle that needs redrawing 00119 // now do drawing 00120 iClient->iGc->Activate(window->Window()); 00121 window->Window().BeginRedraw(); 00122 window->Draw(rect); 00123 window->Window().EndRedraw(); 00124 iClient->iGc->Deactivate(); 00125 } 00126 // maintain outstanding request 00127 IssueRequest(); 00128 } 00129 00130 00132 // CWsClient implementation 00134 CWsClient::CWsClient() 00135 : CActive(CActive::EPriorityStandard) 00136 { 00137 } 00138 00139 void CWsClient::ConstructL() 00140 { 00141 // add ourselves to active scheduler 00142 CActiveScheduler::Add(this); 00143 // get a session going 00144 User::LeaveIfError(iWs.Connect()); 00145 // construct our one and only window group 00146 iGroup=RWindowGroup(iWs); 00147 User::LeaveIfError(iGroup.Construct(2,ETrue)); // '2' is a meaningless handle 00148 // construct screen device and graphics context 00149 iScreen=new (ELeave) CWsScreenDevice(iWs); // make device for this session 00150 User::LeaveIfError(iScreen->Construct()); // and complete its construction 00151 User::LeaveIfError(iScreen->CreateContext(iGc)); // create graphics context 00152 // construct redrawer 00153 iRedrawer=new (ELeave) CWsRedrawer; 00154 iRedrawer->ConstructL(this); 00155 // construct main window 00156 ConstructMainWindowL(); 00157 // request first event and start scheduler 00158 IssueRequest(); 00159 } 00160 00161 CWsClient::~CWsClient() 00162 { 00163 // neutralize us as an active object 00164 Deque(); // cancels and removes from scheduler 00165 // get rid of everything we allocated 00166 delete iGc; 00167 delete iScreen; 00168 delete iRedrawer; 00169 // destroy window group 00170 iGroup.Close(); // what's the difference between this and destroy? 00171 // finish with window server 00172 iWs.Close(); 00173 } 00174 00175 void CWsClient::IssueRequest() 00176 { 00177 iWs.EventReady(&iStatus); // request an event 00178 SetActive(); // so we're now active 00179 } 00180 00181 void CWsClient::DoCancel() 00182 { 00183 iWs.EventReadyCancel(); // cancel event request 00184 } 00185 00186 void CWsClient::ConstructMainWindowL() 00187 { 00188 } 00189
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.