This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
update t/porting/filenames.t to check for path components contaning two
[perl5.git] / symbian / PerlUi.cpp
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
16 #if defined(__SERIES80__) || defined(__SERIES90__)
17 # include <eikon.hrh>
18 # include <cknflash.h>
19 # include <ckndgopn.h>
20 # include <ckndgfob.h>
21 # include <eiklabel.h>
22 # include <cknconf.h>
23 #endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
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
45 #if defined(__SERIES80__) || defined(__SERIES90__)
46 #include "Eikon.rsg"
47 #endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
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
60 EXPORT_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
68 EXPORT_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__ */
77 #if defined(__SERIES80__) || defined(__SERIES90__)
78     return CCknConfirmationDialog::RunDlgWithDefaultIconLD(aMessage, R_EIK_BUTTONS_CANCEL_OK);
79 #endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
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
86 EXPORT_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__ */
95 #if defined(__SERIES80__) || defined(__SERIES90__)
96     return CCknConfirmationDialog::RunDlgWithDefaultIconLD(aMessage, R_EIK_BUTTONS_NO_YES);
97 #endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
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
104 EXPORT_C void CPerlUi::InformationNoteL(TDesC& aMessage)
105 {
106 #ifdef __SERIES60__
107     CAknInformationNote* note = new (ELeave) CAknInformationNote;
108     note->ExecuteLD(aMessage);
109 #endif /* #ifdef __SERIES60__ */
110 #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
111     CEikonEnv::Static()->InfoMsg(aMessage);
112 #endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
113 }
114
115 EXPORT_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__ */
121 #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
122     CEikonEnv::Static()->AlertWin(aMessage);
123     return ETrue;
124 #endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
125 }
126
127 #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
128
129 CPerlUiTextQueryDialog::CPerlUiTextQueryDialog(HBufC*& aBuffer) :
130   iData(aBuffer)
131 {
132 }
133
134 TBool CPerlUiTextQueryDialog::OkToExitL(TInt /* aKeycode */)
135 {
136   iData = static_cast<CEikEdwin*>(Control(EPerlUiTextQueryInputField))->GetTextInHBufL();
137   return ETrue;
138 }
139
140 void 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
150 #endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
151
152 EXPORT_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__ */
161 #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
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;
173 #endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
174 }
175
176 EXPORT_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__ */
182 #if defined(__SERIES80__) || defined(__SERIES90__)
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;
197 #endif /* #if defined(__SERIES80__) || defined(__SERIES90__) */
198 #ifdef __UIQ__
199   return EFalse; // No filesystem access in UIQ 2.x!
200 #endif /* #ifdef __UIQ__ */
201 }
202
203 #ifdef __SERIES60__
204
205 EXPORT_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
221 #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__)
222
223 EXPORT_C void CPerlUiAppView::HandleCommandL(TInt aCommand, CPerlUiAppUi* aAppUi) {
224     aAppUi->DoHandleCommandL(aCommand);
225 }
226
227 EXPORT_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
239 #endif /* #if defined(__SERIES80__) || defined(__SERIES90__) || defined(__UIQ__) */
240
241 CPerlUiAppView* CPerlUiAppView::NewL(const TRect& aRect)
242 {
243     CPerlUiAppView* self = CPerlUiAppView::NewLC(aRect);
244     CleanupStack::Pop(self);
245     return self;
246 }
247
248 CPerlUiAppView* 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
256 void CPerlUiAppView::ConstructL(const TRect& aRect)
257 {
258     CreateWindowL();
259     SetRect(aRect);
260     ActivateL();
261 }
262
263 CPerlUiAppView::~CPerlUiAppView()
264 {
265 }
266
267 void CPerlUiAppView::Draw(const TRect& /*aRect*/) const
268 {
269     CWindowGc& gc = SystemGc();
270     TRect rect = Rect();
271     gc.Clear(rect);
272 }
273