examples/Graphics/WS/Simple/Base.cpp

00001 /*
00002 Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 #include <w32std.h>
00032 #include "Base.h"
00033 
00037 
00038 CWindow::CWindow(CWsClient* aClient)
00039         : iClient(aClient)
00040         {
00041         }
00042 
00043 void CWindow::ConstructL (const TRect& aRect, CWindow* aParent)
00044         {
00045         // If a parent window was specified, use it; if not, use the window group
00046         // (aParent defaults to 0).
00047         RWindowTreeNode* parent= aParent ? (RWindowTreeNode*) &(aParent->Window()) : &(iClient->iGroup);
00048         iWindow=RWindow(iClient->iWs); // use app's session to window server
00049         User::LeaveIfError(iWindow.Construct(*parent,(TUint32)this));
00050         iRect = aRect;
00051         iWindow.SetExtent(iRect.iTl, iRect.Size()); // set extent relative to group coords
00052         iWindow.Activate(); // window is now active
00053         }
00054 
00055 
00056 CWindow::~CWindow()
00057         {
00058         iWindow.Close(); // close our window
00059         }
00060 
00061 RWindow& CWindow::Window()
00062         {
00063         return iWindow;
00064         }
00065 
00066 CWindowGc* CWindow::SystemGc()
00067         {
00068         return iClient->iGc;
00069         }
00070 
00071 
00075 
00076 CWsRedrawer::CWsRedrawer()
00077         : CActive(CActive::EPriorityLow)
00078         {
00079         }
00080 
00081 void CWsRedrawer::ConstructL(CWsClient* aClient)
00082         {
00083         iClient=aClient; // remember WsClient that owns us
00084         CActiveScheduler::Add(this); // add ourselves to the scheduler
00085         IssueRequest(); // issue request to draw
00086         }
00087 
00088 CWsRedrawer::~CWsRedrawer()
00089         {
00090         Cancel();
00091         }
00092 
00093 void CWsRedrawer::IssueRequest()
00094         {
00095         iClient->iWs.RedrawReady(&iStatus);
00096         SetActive();
00097         }
00098 
00099 void CWsRedrawer::DoCancel()
00100         {
00101         iClient->iWs.RedrawReadyCancel();
00102         }
00103 
00104 void CWsRedrawer::RunL()
00105         {       
00106         // find out what needs to be done
00107         TWsRedrawEvent redrawEvent;
00108     iClient->iWs.GetRedraw(redrawEvent); // get event
00109         CWindow* window=(CWindow*)(redrawEvent.Handle()); // get window
00110         if (window)
00111                 {
00112                 TRect rect=redrawEvent.Rect(); // and rectangle that needs redrawing
00113                 // now do drawing
00114                 iClient->iGc->Activate(window->Window());
00115                 window->Window().BeginRedraw(rect);
00116                 window->Draw(rect);
00117                 window->Window().EndRedraw();
00118                 iClient->iGc->Deactivate();
00119                 }
00120         // maintain outstanding request
00121         IssueRequest();
00122         }
00123 
00124 
00128 CWsClient::CWsClient()
00129         : CActive(CActive::EPriorityHigh)
00130         {
00131         }
00132 
00133 void CWsClient::ConstructL()
00134         {
00135         // add ourselves to active scheduler
00136         CActiveScheduler::Add(this);
00137         // get a session going
00138         User::LeaveIfError(iWs.Connect());
00139         // construct our one and only window group
00140         iGroup=RWindowGroup(iWs);
00141         User::LeaveIfError(iGroup.Construct(2,ETrue)); // meaningless handle; enable focus
00142         // construct screen device and graphics context
00143         iScreen=new (ELeave) CWsScreenDevice(iWs); // make device for this session
00144         User::LeaveIfError(iScreen->Construct()); // and complete its construction
00145         User::LeaveIfError(iScreen->CreateContext(iGc)); // create graphics context
00146         // construct redrawer
00147         iRedrawer=new (ELeave) CWsRedrawer;
00148         iRedrawer->ConstructL(this);
00149         // construct main window
00150         ConstructMainWindowL();
00151         // request first event and start scheduler
00152         IssueRequest();
00153         }
00154 
00155 CWsClient::~CWsClient()
00156         {
00157         // neutralize us as an active object
00158         Deque(); // cancels and removes from scheduler
00159         // get rid of everything we allocated
00160         delete iGc;
00161         delete iScreen;
00162         delete iRedrawer;
00163         // destroy window group
00164         iGroup.Close();
00165         // finish with window server
00166         iWs.Close();
00167         }
00168 
00169 void CWsClient::IssueRequest()
00170         {
00171         iWs.EventReady(&iStatus); // request an event
00172         SetActive(); // so we're now active
00173         }
00174 
00175 void CWsClient::DoCancel()
00176         {
00177         iWs.EventReadyCancel(); // cancel event request
00178         }
00179 
00180 void CWsClient::ConstructMainWindowL()
00181         {
00182         }
00183 

Generated by  doxygen 1.6.2