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

Generated by  doxygen 1.6.2