summaryrefslogtreecommitdiff
path: root/symbian/PerlUi.cpp
blob: 01be136d09f6fcdc897b315949433ef1641046eb (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
/* Copyright (c) 2005 Nokia. All rights reserved. */

/* The PerlUi class is licensed under the same terms as Perl itself. */

#include "PerlUi.h"

#ifdef __SERIES60__
# include <avkon.hrh>
# include <aknnotewrappers.h> 
# include <AknCommonDialogs.h>
# ifndef __SERIES60_1X__
#  include <CAknFileSelectionDialog.h>
# endif
#endif /* #ifdef __SERIES60__ */

#if defined(__SERIES80__) || defined(__SERIES90__)
# include <eikon.hrh>
# include <cknflash.h>
# include <ckndgopn.h>
# include <ckndgfob.h>
# include <eiklabel.h>
# include <cknconf.h>
#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */

#ifdef __UIQ__
# include <qikon.hrh>
# include <eikedwin.h>
# include <eiklabel.h>
#endif /* #ifdef __UIQ__ */

#include <apparc.h>
#include <e32base.h>
#include <e32cons.h>
#include <eikenv.h>
#include <bautils.h>
#include <eikappui.h>
#include <utf.h>
#include <f32file.h>

#include <coemain.h>

#include "PerlUi.hrh"
#include "PerlUi.rsg"

#if defined(__SERIES80__) || defined(__SERIES90__)
#include "Eikon.rsg"
#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "PerlBase.h"
#include "PerlUtil.h"

#define symbian_get_vars() Dll::Tls() // Not visible from perlXYZ.lib?

_LIT(KDefaultScript, "default.pl");

EXPORT_C void CPerlUiAppUi::ConstructL()
{
    BaseConstructL();
    iAppView = CPerlUiAppView::NewL(ClientRect());
    AddToStackL(iAppView);
    CEikonEnv::Static()->DisableExitChecks(ETrue); // Symbian FAQ-0577.
}

EXPORT_C TBool CPerlUi::OkCancelDialogL(TDesC& aMessage)
{
#ifdef __SERIES60__
    CAknNoteDialog* dlg =
        new (ELeave) CAknNoteDialog(CAknNoteDialog::EConfirmationTone);
    dlg->PrepareLC(R_PERLUI_OK_CANCEL_DIALOG);
    dlg->SetTextL(aMessage);
    return dlg->RunDlgLD() == EAknSoftkeyOk;
#endif /* #ifdef __SERIES60__ */
#if defined(__SERIES80__) || defined(__SERIES90__)
    return CCknConfirmationDialog::RunDlgWithDefaultIconLD(aMessage, R_EIK_BUTTONS_CANCEL_OK);
#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
#ifdef __UIQ__
    CEikDialog* dlg = new (ELeave) CEikDialog();
    return dlg->ExecuteLD(R_PERLUI_OK_CANCEL_DIALOG) == EEikBidOk;
#endif /* #ifdef __UIQ__ */
}

EXPORT_C TBool CPerlUi::YesNoDialogL(TDesC& aMessage)
{
#ifdef __SERIES60__
    CAknNoteDialog* dlg =
        new (ELeave) CAknNoteDialog(CAknNoteDialog::EConfirmationTone);
    dlg->PrepareLC(R_PERLUI_YES_NO_DIALOG);
    dlg->SetTextL(aMessage);
    return dlg->RunDlgLD() == EAknSoftkeyOk;
#endif /* #ifdef __SERIES60__ */
#if defined(__SERIES80__) || defined(__SERIES90__)
    return CCknConfirmationDialog::RunDlgWithDefaultIconLD(aMessage, R_EIK_BUTTONS_NO_YES);
#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
#ifdef __UIQ__
    CEikDialog* dlg = new (ELeave) CEikDialog();
    return dlg->ExecuteLD(R_PERLUI_YES_NO_DIALOG) == EEikBidOk;
#endif /* #ifdef __UIQ__ */
}

EXPORT_C void CPerlUi::InformationNoteL(TDesC& aMessage)
{
#ifdef __SERIES60__
    CAknInformationNote* note = new (ELeave) CAknInformationNote;
    note->ExecuteLD(aMessage);
#endif /* #ifdef __SERIES60__ */
#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
    CEikonEnv::Static()->InfoMsg(aMessage);
#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
}

EXPORT_C TInt CPerlUi::WarningNoteL(TDesC& aMessage)
{
#ifdef __SERIES60__
    CAknWarningNote* note = new (ELeave) CAknWarningNote;
    return note->ExecuteLD(aMessage);
#endif /* #ifdef __SERIES60__ */
#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
    CEikonEnv::Static()->AlertWin(aMessage);
    return ETrue;
#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
}

#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)

CPerlUiTextQueryDialog::CPerlUiTextQueryDialog(HBufC*& aBuffer) :
  iData(aBuffer)
{
}

TBool CPerlUiTextQueryDialog::OkToExitL(TInt /* aKeycode */)
{
  iData = static_cast<CEikEdwin*>(Control(EPerlUiTextQueryInputField))->GetTextInHBufL();
  return ETrue;
}

void CPerlUiTextQueryDialog::PreLayoutDynInitL()
{
  SetTitleL(iTitle);
  CEikLabel* promptLabel = ControlCaption(EPerlUiTextQueryInputField);
  promptLabel->SetTextL(iPrompt);
}

/* TODO: OfferKeyEventL() so that newline can be seen as 'OK'.
 * Or a hotkey for the button? */

#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */

EXPORT_C TBool CPerlUi::TextQueryDialogL(const TDesC& aTitle, const TDesC& aPrompt, TDes& aData, const TInt aMaxLength)
{
#ifdef __SERIES60__
    CAknTextQueryDialog* dlg =
        new (ELeave) CAknTextQueryDialog(aData);
    dlg->SetPromptL(aPrompt);
    dlg->SetMaxLength(aMaxLength);
    return dlg->ExecuteLD(R_PERLUI_TEXT_QUERY_DIALOG);
#endif /* #ifdef __SERIES60__ */
#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
    HBufC* data = NULL;
    CPerlUiTextQueryDialog* dlg =
      new (ELeave) CPerlUiTextQueryDialog(data);
    dlg->iTitle.Set(aTitle);
    dlg->iPrompt.Set(aPrompt);
    dlg->iMaxLength = aMaxLength;
    if (dlg->ExecuteLD(R_PERLUI_ONELINER_DIALOG)) {
        aData.Copy(*data);
        return ETrue;
    }
    return EFalse;
#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
}

EXPORT_C TBool CPerlUi::FileQueryDialogL(TDes& aFilename)
{
#ifdef __SERIES60__
  return AknCommonDialogs::RunSelectDlgLD(aFilename,
                                          R_PERLUI_FILE_SELECTION_DIALOG);
#endif /* #ifdef __SERIES60__ */
#if defined(__SERIES80__) || defined(__SERIES90__)
  if (CCknOpenFileDialog::RunDlgLD(aFilename,
                                    CCknFileListDialogBase::EShowAllDrives
                                   |CCknFileListDialogBase::EShowSystemFilesAndFolders
                                   |CCknFileListDialogBase::EShowBothFilesAndFolders
                                   )) {
    TEntry aEntry; // Be paranoid and check that the file is there.
    RFs aFs;
    aFs.Connect();
    if (aFs.Entry(aFilename, aEntry) == KErrNone)
      return ETrue;
    else
      CEikonEnv::Static()->InfoMsg(_L("File not found"));
  }
  return EFalse;
#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
#ifdef __UIQ__
  return EFalse; // No filesystem access in UIQ 2.x!
#endif /* #ifdef __UIQ__ */
}

#ifdef __SERIES60__

EXPORT_C void CPerlUiAppUi::HandleCommandL(TInt aCommand)
{
    switch(aCommand)
    {
    case EEikCmdExit:
    case EAknSoftkeyExit:
        Exit();
        break;
    default:
        DoHandleCommandL(aCommand);
        break;
    }
}

#endif /* #ifdef __SERIES60__ */

#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)

EXPORT_C void CPerlUiAppView::HandleCommandL(TInt aCommand, CPerlUiAppUi* aAppUi) {
    aAppUi->DoHandleCommandL(aCommand);
}

EXPORT_C void CPerlUiAppUi::HandleCommandL(TInt aCommand) {
    switch(aCommand)
    {
    case EEikCmdExit:
        Exit();
        break;
    default:
        iAppView->HandleCommandL(aCommand, this);
        break;
    }
}

#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */

CPerlUiAppView* CPerlUiAppView::NewL(const TRect& aRect)
{
    CPerlUiAppView* self = CPerlUiAppView::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
}

CPerlUiAppView* CPerlUiAppView::NewLC(const TRect& aRect)
{
    CPerlUiAppView* self = new (ELeave) CPerlUiAppView;
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
}

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

CPerlUiAppView::~CPerlUiAppView()
{
}

void CPerlUiAppView::Draw(const TRect& /*aRect*/) const
{
    CWindowGc& gc = SystemGc();
    TRect rect = Rect();
    gc.Clear(rect);
}