summaryrefslogtreecommitdiff
path: root/src/symbian/uqmapp.cpp
blob: 86ac5dd792ca122ed9af9e2ca178e4c4176e5d3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#include <coecntrl.h>
#include <aknappui.h>
#include <aknapp.h>
#include <akndoc.h>
#include <sdlepocapi.h>
#include <aknnotewrappers.h>
#include <eikstart.h>
#include <badesca.h>
#include <bautils.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL_keysym.h>

const TUid KUidSdlApp={ 0xA000A0C3 };

class CSDL;

class CSDLObserver : public CBase, public MSDLObserver
{
public:
    CSDLObserver(CSDL* aSdl);

    TInt SdlEvent(TInt aEvent, TInt aParam);
    TInt SdlThreadEvent(TInt aEvent, TInt aParam);

private:
    CSDL* iSdl;    
};

class MExitWait
    {
    public:
        virtual void DoExit(TInt aErr) = 0;
    };   

class CExitWait : public CActive
    {
    public:
        CExitWait(MExitWait& aWait);
        void Start();
        ~CExitWait();
    private:
        void RunL();
        void DoCancel();
    private:
        MExitWait& iWait;
        TRequestStatus* iStatusPtr;
    };

class CSDLWin : public CCoeControl
    {
    public:
        void ConstructL(const TRect& aRect);
        RWindow& GetWindow() const;
        void SetNoDraw();
    private:
        void Draw(const TRect& aRect) const;
    };  
    
class CSdlApplication : public CAknApplication
    {
private:
    // from CApaApplication
    CApaDocument* CreateDocumentL();
    TUid AppDllUid() const;
    };
    
    
class CSdlAppDocument : public CAknDocument
    {
public:
    CSdlAppDocument(CEikApplication& aApp): CAknDocument(aApp) { }
private:
    CEikAppUi* CreateAppUiL();
    };
    
            
class CSdlAppUi : public CAknAppUi, public MExitWait
    {
public:
    void ConstructL();
    ~CSdlAppUi();
private:
    void HandleCommandL(TInt aCommand);
    void DoExit(TInt aErr);
    void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination);
    void HandleResourceChangeL(TInt aType);
    void AddCmdLineParamsL(CDesC8Array& aArgs);
private:
    CExitWait* iWait;
    CSDLWin* iSDLWin;
    CSDL* iSdl;
    CSDLObserver* iSdlObserver;
    TBool iExit;
    };  


CExitWait::CExitWait(MExitWait& aWait) : CActive(CActive::EPriorityStandard), iWait(aWait)
    {
    CActiveScheduler::Add(this);
    }
    
CExitWait::~CExitWait()
    {
    Cancel();
    }
 
void CExitWait::RunL()
    {
    if(iStatusPtr != NULL )
        iWait.DoExit(iStatus.Int());
    }
    
void CExitWait::DoCancel()
    {
    if(iStatusPtr != NULL )
        User::RequestComplete(iStatusPtr , KErrCancel);
    }
    
void CExitWait::Start()
    {
    SetActive();
    iStatusPtr = &iStatus;
    }

void CSDLWin:: ConstructL(const TRect& aRect)   
    {
    CreateWindowL();
    SetRect(aRect);
    ActivateL();
    }

    
RWindow& CSDLWin::GetWindow() const
    {
    return Window();
    }
    

void CSDLWin::Draw(const TRect& /*aRect*/) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ESolidPen);
    gc.SetPenColor(KRgbBlack);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.SetBrushColor(0x000000);
    gc.DrawRect(Rect());
    }   
    
void CSdlAppUi::ConstructL()    
    {
    BaseConstructL(ENoScreenFurniture | EAppOrientationLandscape);
        
    iSDLWin = new (ELeave) CSDLWin;
    iSDLWin->ConstructL(ApplicationRect());
                
    iSdl = CSDL::NewL(CSDL::EEnableFocusStop);
    iSdlObserver = new (ELeave) CSDLObserver(iSdl);
    
    iSdl->SetContainerWindowL(
                    iSDLWin->GetWindow(), 
                    iEikonEnv->WsSession(),
                    *iEikonEnv->ScreenDevice());    
    iSdl->SetObserver(iSdlObserver);
    iSdl->DisableKeyBlocking(*this);    
    
    iWait = new (ELeave) CExitWait(*this);    
    CDesC8ArrayFlat* args = new (ELeave)CDesC8ArrayFlat(10);
    AddCmdLineParamsL(*args);
    
    iSdl->CallMainL(iWait->iStatus, *args, CSDL::ENoFlags, 81920);
    delete args;
    
    iWait->Start();     
    }

void CSdlAppUi::HandleCommandL(TInt aCommand)
    {
    switch(aCommand)
        {
        case EAknCmdExit:
        case EAknSoftkeyExit:
        case EEikCmdExit:
            exit(0);
            break;
            
        default:
            break;
        }
    }
    
void CSdlAppUi::DoExit(TInt aErr)
    {       
    delete iSdl;
    iSdl = NULL;
    
    if(iExit)
        Exit();
    }
    
void CSdlAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
    {
    if(iSdl != NULL)
        iSdl->AppendWsEvent(aEvent);
    CAknAppUi::HandleWsEventL(aEvent, aDestination);
    }
    
void CSdlAppUi::HandleResourceChangeL(TInt aType)
    {
    CAknAppUi::HandleResourceChangeL(aType);
    
    if(aType == KEikDynamicLayoutVariantSwitch)
        {
        iSDLWin->SetRect(ApplicationRect());
        if (iSdl)
            {
            iSdl->SetContainerWindowL(
                        iSDLWin->GetWindow(),
                        iEikonEnv->WsSession(),
                        *iEikonEnv->ScreenDevice());
            }                       
        }
    }

void CSdlAppUi::AddCmdLineParamsL(CDesC8Array& aArgs)
    {       
    _LIT8(KAddonParam, "--addondir=?:\\uqm-addons");
    _LIT16(KTestFolder, "?:\\uqm-addons");
    RFs fs;
    
    fs.Connect();   
    for (TInt8 c = 'e'; c < 'z'; ++c)
        {
        TBuf16<32> buf(KTestFolder);
        buf[0] = c;
        if (BaflUtils::FolderExists(fs, buf))
            {
            TBuf8<32> arg(KAddonParam);
            arg[11] = c;
            aArgs.AppendL(arg);
            break;
            }
        }
    fs.Close();
    }

CSdlAppUi::~CSdlAppUi()
    {
    if(iWait != NULL)
        iWait->Cancel();
    delete iSdl;
    delete iWait;
    delete iSDLWin;
    delete iSdlObserver;
    }

CEikAppUi* CSdlAppDocument::CreateAppUiL()
    {
    return new(ELeave) CSdlAppUi();
    }   
    
TUid CSdlApplication::AppDllUid() const
    {
    return KUidSdlApp;
    }   
    

CApaDocument* CSdlApplication::CreateDocumentL()
    {
    CSdlAppDocument* document = new (ELeave) CSdlAppDocument(*this);
    return document;
    }
  
LOCAL_C CApaApplication* NewApplication()
    {
    return new CSdlApplication;
    }

GLDEF_C TInt E32Main()
    {
    return EikStart::RunApplication(NewApplication);
    }

CSDLObserver::CSDLObserver(CSDL* aSdl) : iSdl(aSdl)
{
}

TInt CSDLObserver::SdlEvent(TInt aEvent, TInt aParam)
{
    if (aEvent == EEventKeyMapInit)
    {
        // starmap zoom
        iSdl->SetSDLCode('3', SDLK_KP_PLUS);
        iSdl->SetSDLCode('2', SDLK_KP_MINUS);
        
        iSdl->SetSDLCode('A', SDLK_KP_PLUS);
        iSdl->SetSDLCode('Z', SDLK_KP_MINUS);
        
        iSdl->SetSDLCode('a', SDLK_KP_PLUS);
        iSdl->SetSDLCode('z', SDLK_KP_MINUS);        
    }
    return 0;
}

TInt CSDLObserver::SdlThreadEvent(TInt aEvent, TInt aParam)
{
    return 0;
}