This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add &CORE::glob
[perl5.git] / symbian / PerlUi.cpp
CommitLineData
d0d72822
JH
1/* Copyright (c) 2005 Nokia. All rights reserved. */
2
3/* The PerlUi class is licensed under the same terms as Perl itself. */
4
5#include "PerlUi.h"
6
7#ifdef __SERIES60__
8# include <avkon.hrh>
9# include <aknnotewrappers.h>
10# include <AknCommonDialogs.h>
11# ifndef __SERIES60_1X__
12# include <CAknFileSelectionDialog.h>
13# endif
14#endif /* #ifdef __SERIES60__ */
15
53d44271 16#if defined(__SERIES80__) || defined(__SERIES90__)
d0d72822
JH
17# include <eikon.hrh>
18# include <cknflash.h>
19# include <ckndgopn.h>
20# include <ckndgfob.h>
21# include <eiklabel.h>
22# include <cknconf.h>
53d44271 23#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
d0d72822
JH
24
25#ifdef __UIQ__
26# include <qikon.hrh>
27# include <eikedwin.h>
28# include <eiklabel.h>
29#endif /* #ifdef __UIQ__ */
30
31#include <apparc.h>
32#include <e32base.h>
33#include <e32cons.h>
34#include <eikenv.h>
35#include <bautils.h>
36#include <eikappui.h>
37#include <utf.h>
38#include <f32file.h>
39
40#include <coemain.h>
41
42#include "PerlUi.hrh"
43#include "PerlUi.rsg"
44
53d44271 45#if defined(__SERIES80__) || defined(__SERIES90__)
d0d72822 46#include "Eikon.rsg"
53d44271 47#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
d0d72822
JH
48
49#include "EXTERN.h"
50#include "perl.h"
51#include "XSUB.h"
52
53#include "PerlBase.h"
54#include "PerlUtil.h"
55
56#define symbian_get_vars() Dll::Tls() // Not visible from perlXYZ.lib?
57
58_LIT(KDefaultScript, "default.pl");
59
60EXPORT_C void CPerlUiAppUi::ConstructL()
61{
62 BaseConstructL();
63 iAppView = CPerlUiAppView::NewL(ClientRect());
64 AddToStackL(iAppView);
65 CEikonEnv::Static()->DisableExitChecks(ETrue); // Symbian FAQ-0577.
66}
67
68EXPORT_C TBool CPerlUi::OkCancelDialogL(TDesC& aMessage)
69{
70#ifdef __SERIES60__
71 CAknNoteDialog* dlg =
72 new (ELeave) CAknNoteDialog(CAknNoteDialog::EConfirmationTone);
73 dlg->PrepareLC(R_PERLUI_OK_CANCEL_DIALOG);
74 dlg->SetTextL(aMessage);
75 return dlg->RunDlgLD() == EAknSoftkeyOk;
76#endif /* #ifdef __SERIES60__ */
53d44271 77#if defined(__SERIES80__) || defined(__SERIES90__)
d0d72822 78 return CCknConfirmationDialog::RunDlgWithDefaultIconLD(aMessage, R_EIK_BUTTONS_CANCEL_OK);
53d44271 79#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
d0d72822
JH
80#ifdef __UIQ__
81 CEikDialog* dlg = new (ELeave) CEikDialog();
82 return dlg->ExecuteLD(R_PERLUI_OK_CANCEL_DIALOG) == EEikBidOk;
83#endif /* #ifdef __UIQ__ */
84}
85
86EXPORT_C TBool CPerlUi::YesNoDialogL(TDesC& aMessage)
87{
88#ifdef __SERIES60__
89 CAknNoteDialog* dlg =
90 new (ELeave) CAknNoteDialog(CAknNoteDialog::EConfirmationTone);
91 dlg->PrepareLC(R_PERLUI_YES_NO_DIALOG);
92 dlg->SetTextL(aMessage);
93 return dlg->RunDlgLD() == EAknSoftkeyOk;
94#endif /* #ifdef __SERIES60__ */
53d44271 95#if defined(__SERIES80__) || defined(__SERIES90__)
d0d72822 96 return CCknConfirmationDialog::RunDlgWithDefaultIconLD(aMessage, R_EIK_BUTTONS_NO_YES);
53d44271 97#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
d0d72822
JH
98#ifdef __UIQ__
99 CEikDialog* dlg = new (ELeave) CEikDialog();
100 return dlg->ExecuteLD(R_PERLUI_YES_NO_DIALOG) == EEikBidOk;
101#endif /* #ifdef __UIQ__ */
102}
103
104EXPORT_C void CPerlUi::InformationNoteL(TDesC& aMessage)
105{
106#ifdef __SERIES60__
107 CAknInformationNote* note = new (ELeave) CAknInformationNote;
108 note->ExecuteLD(aMessage);
109#endif /* #ifdef __SERIES60__ */
53d44271 110#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
d0d72822 111 CEikonEnv::Static()->InfoMsg(aMessage);
53d44271 112#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
d0d72822
JH
113}
114
115EXPORT_C TInt CPerlUi::WarningNoteL(TDesC& aMessage)
116{
117#ifdef __SERIES60__
118 CAknWarningNote* note = new (ELeave) CAknWarningNote;
119 return note->ExecuteLD(aMessage);
120#endif /* #ifdef __SERIES60__ */
53d44271 121#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
d0d72822
JH
122 CEikonEnv::Static()->AlertWin(aMessage);
123 return ETrue;
53d44271 124#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
d0d72822
JH
125}
126
53d44271 127#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
d0d72822
JH
128
129CPerlUiTextQueryDialog::CPerlUiTextQueryDialog(HBufC*& aBuffer) :
130 iData(aBuffer)
131{
132}
133
134TBool CPerlUiTextQueryDialog::OkToExitL(TInt /* aKeycode */)
135{
136 iData = static_cast<CEikEdwin*>(Control(EPerlUiTextQueryInputField))->GetTextInHBufL();
137 return ETrue;
138}
139
140void CPerlUiTextQueryDialog::PreLayoutDynInitL()
141{
142 SetTitleL(iTitle);
143 CEikLabel* promptLabel = ControlCaption(EPerlUiTextQueryInputField);
144 promptLabel->SetTextL(iPrompt);
145}
146
147/* TODO: OfferKeyEventL() so that newline can be seen as 'OK'.
148 * Or a hotkey for the button? */
149
53d44271 150#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
d0d72822
JH
151
152EXPORT_C TBool CPerlUi::TextQueryDialogL(const TDesC& aTitle, const TDesC& aPrompt, TDes& aData, const TInt aMaxLength)
153{
154#ifdef __SERIES60__
155 CAknTextQueryDialog* dlg =
156 new (ELeave) CAknTextQueryDialog(aData);
157 dlg->SetPromptL(aPrompt);
158 dlg->SetMaxLength(aMaxLength);
159 return dlg->ExecuteLD(R_PERLUI_TEXT_QUERY_DIALOG);
160#endif /* #ifdef __SERIES60__ */
53d44271 161#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
d0d72822
JH
162 HBufC* data = NULL;
163 CPerlUiTextQueryDialog* dlg =
164 new (ELeave) CPerlUiTextQueryDialog(data);
165 dlg->iTitle.Set(aTitle);
166 dlg->iPrompt.Set(aPrompt);
167 dlg->iMaxLength = aMaxLength;
168 if (dlg->ExecuteLD(R_PERLUI_ONELINER_DIALOG)) {
169 aData.Copy(*data);
170 return ETrue;
171 }
172 return EFalse;
53d44271 173#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
d0d72822
JH
174}
175
176EXPORT_C TBool CPerlUi::FileQueryDialogL(TDes& aFilename)
177{
178#ifdef __SERIES60__
179 return AknCommonDialogs::RunSelectDlgLD(aFilename,
180 R_PERLUI_FILE_SELECTION_DIALOG);
181#endif /* #ifdef __SERIES60__ */
53d44271 182#if defined(__SERIES80__) || defined(__SERIES90__)
d0d72822
JH
183 if (CCknOpenFileDialog::RunDlgLD(aFilename,
184 CCknFileListDialogBase::EShowAllDrives
185 |CCknFileListDialogBase::EShowSystemFilesAndFolders
186 |CCknFileListDialogBase::EShowBothFilesAndFolders
187 )) {
188 TEntry aEntry; // Be paranoid and check that the file is there.
189 RFs aFs;
190 aFs.Connect();
191 if (aFs.Entry(aFilename, aEntry) == KErrNone)
192 return ETrue;
193 else
194 CEikonEnv::Static()->InfoMsg(_L("File not found"));
195 }
196 return EFalse;
53d44271 197#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
d0d72822
JH
198#ifdef __UIQ__
199 return EFalse; // No filesystem access in UIQ 2.x!
200#endif /* #ifdef __UIQ__ */
201}
202
203#ifdef __SERIES60__
204
205EXPORT_C void CPerlUiAppUi::HandleCommandL(TInt aCommand)
206{
207 switch(aCommand)
208 {
209 case EEikCmdExit:
210 case EAknSoftkeyExit:
211 Exit();
212 break;
213 default:
214 DoHandleCommandL(aCommand);
215 break;
216 }
217}
218
219#endif /* #ifdef __SERIES60__ */
220
53d44271 221#if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
d0d72822
JH
222
223EXPORT_C void CPerlUiAppView::HandleCommandL(TInt aCommand, CPerlUiAppUi* aAppUi) {
224 aAppUi->DoHandleCommandL(aCommand);
225}
226
227EXPORT_C void CPerlUiAppUi::HandleCommandL(TInt aCommand) {
228 switch(aCommand)
229 {
230 case EEikCmdExit:
231 Exit();
232 break;
233 default:
234 iAppView->HandleCommandL(aCommand, this);
235 break;
236 }
237}
238
53d44271 239#endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
d0d72822
JH
240
241CPerlUiAppView* CPerlUiAppView::NewL(const TRect& aRect)
242{
243 CPerlUiAppView* self = CPerlUiAppView::NewLC(aRect);
244 CleanupStack::Pop(self);
245 return self;
246}
247
248CPerlUiAppView* CPerlUiAppView::NewLC(const TRect& aRect)
249{
250 CPerlUiAppView* self = new (ELeave) CPerlUiAppView;
251 CleanupStack::PushL(self);
252 self->ConstructL(aRect);
253 return self;
254}
255
256void CPerlUiAppView::ConstructL(const TRect& aRect)
257{
258 CreateWindowL();
259 SetRect(aRect);
260 ActivateL();
261}
262
263CPerlUiAppView::~CPerlUiAppView()
264{
265}
266
267void CPerlUiAppView::Draw(const TRect& /*aRect*/) const
268{
269 CWindowGc& gc = SystemGc();
270 TRect rect = Rect();
271 gc.Clear(rect);
272}
273