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 00022 00023 CWindow::CWindow(CWsClient* aClient) 00024 : iClient(aClient) 00025 { 00026 } 00027 00028 void CWindow::ConstructL (const TRect& aRect, CWindow* aParent) 00029 { 00030 // If a parent window was specified, use it; if not, use the window group 00031 // (aParent defaults to 0). 00032 RWindowTreeNode* parent= aParent ? (RWindowTreeNode*) &(aParent->Window()) : &(iClient->iGroup); 00033 iWindow=RWindow(iClient->iWs); // use app's session to window server 00034 User::LeaveIfError(iWindow.Construct(*parent,(TUint32)this)); 00035 iRect = aRect; 00036 iWindow.SetExtent(iRect.iTl, iRect.Size()); // set extent relative to group coords 00037 iWindow.Activate(); // window is now active 00038 } 00039 00040 00041 CWindow::~CWindow() 00042 { 00043 iWindow.Close(); // close our window 00044 } 00045 00046 RWindow& CWindow::Window() 00047 { 00048 return iWindow; 00049 } 00050 00051 CWindowGc* CWindow::SystemGc() 00052 { 00053 return iClient->iGc; 00054 } 00055 00056 00060 00061 CWsRedrawer::CWsRedrawer() 00062 : CActive(CActive::EPriorityLow) 00063 { 00064 } 00065 00066 void CWsRedrawer::ConstructL(CWsClient* aClient) 00067 { 00068 iClient=aClient; // remember WsClient that owns us 00069 CActiveScheduler::Add(this); // add ourselves to the scheduler 00070 IssueRequest(); // issue request to draw 00071 } 00072 00073 CWsRedrawer::~CWsRedrawer() 00074 { 00075 Cancel(); 00076 } 00077 00078 void CWsRedrawer::IssueRequest() 00079 { 00080 iClient->iWs.RedrawReady(&iStatus); 00081 SetActive(); 00082 } 00083 00084 void CWsRedrawer::DoCancel() 00085 { 00086 iClient->iWs.RedrawReadyCancel(); 00087 } 00088 00089 void CWsRedrawer::RunL() 00090 { 00091 // find out what needs to be done 00092 TWsRedrawEvent redrawEvent; 00093 iClient->iWs.GetRedraw(redrawEvent); // get event 00094 CWindow* window=(CWindow*)(redrawEvent.Handle()); // get window 00095 if (window) 00096 { 00097 TRect rect=redrawEvent.Rect(); // and rectangle that needs redrawing 00098 // now do drawing 00099 iClient->iGc->Activate(window->Window()); 00100 window->Window().BeginRedraw(rect); 00101 window->Draw(rect); 00102 window->Window().EndRedraw(); 00103 iClient->iGc->Deactivate(); 00104 } 00105 // maintain outstanding request 00106 IssueRequest(); 00107 } 00108 00109 00113 CWsClient::CWsClient() 00114 : CActive(CActive::EPriorityHigh) 00115 { 00116 } 00117 00118 void CWsClient::ConstructL() 00119 { 00120 // add ourselves to active scheduler 00121 CActiveScheduler::Add(this); 00122 // get a session going 00123 User::LeaveIfError(iWs.Connect()); 00124 // construct our one and only window group 00125 iGroup=RWindowGroup(iWs); 00126 User::LeaveIfError(iGroup.Construct(2,ETrue)); // meaningless handle; enable focus 00127 // construct screen device and graphics context 00128 iScreen=new (ELeave) CWsScreenDevice(iWs); // make device for this session 00129 User::LeaveIfError(iScreen->Construct()); // and complete its construction 00130 User::LeaveIfError(iScreen->CreateContext(iGc)); // create graphics context 00131 // construct redrawer 00132 iRedrawer=new (ELeave) CWsRedrawer; 00133 iRedrawer->ConstructL(this); 00134 // construct main window 00135 ConstructMainWindowL(); 00136 // request first event and start scheduler 00137 IssueRequest(); 00138 } 00139 00140 CWsClient::~CWsClient() 00141 { 00142 // neutralize us as an active object 00143 Deque(); // cancels and removes from scheduler 00144 // get rid of everything we allocated 00145 delete iGc; 00146 delete iScreen; 00147 delete iRedrawer; 00148 // destroy window group 00149 iGroup.Close(); 00150 // finish with window server 00151 iWs.Close(); 00152 } 00153 00154 void CWsClient::IssueRequest() 00155 { 00156 iWs.EventReady(&iStatus); // request an event 00157 SetActive(); // so we're now active 00158 } 00159 00160 void CWsClient::DoCancel() 00161 { 00162 iWs.EventReadyCancel(); // cancel event request 00163 } 00164 00165 void CWsClient::ConstructMainWindowL() 00166 { 00167 } 00168
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.