examples/Graphics/WS/Scroll/Base.cpp

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

Generated by  doxygen 1.6.2