rm unused file
[picodrive.git] / platform / uiq3 / Dialogs.cpp
... / ...
CommitLineData
1/*******************************************************************\r
2 *\r
3 * File: Dialogs.cpp\r
4 *\r
5 * Author: Peter van Sebille (peter@yipton.net)\r
6 *\r
7 * Modified/adapted for picodriveN by notaz, 2006\r
8 *\r
9 * (c) Copyright 2006, notaz\r
10 * (c) Copyright 2002, Peter van Sebille\r
11 * All Rights Reserved\r
12 *\r
13 *******************************************************************/\r
14\r
15#include "Dialogs.h"\r
16#include "Engine.h"\r
17#include "picodrive.hrh"\r
18#include "rsc/picodrive.rsg"\r
19\r
20#include "version.h"\r
21#include "CSimpleTextParser.h"\r
22#include <txtrich.h> // CRichText\r
23#include <eikrted.h> // CEikRichTextEditor\r
24#include <qikvertoptionbuttonlist.h> // CEikHorOptionButtonList\r
25#include <eikopbut.h> // CEikOptionButton\r
26#include <eikedwin.h> // CEikEdwin\r
27#include <quartzkeys.h> // EQuartzKeyTwoWayDown\r
28\r
29#include <qikcommand.h>\r
30#include "../common/emu.h"\r
31\r
32\r
33/************************************************\r
34 *\r
35 * config Dialog\r
36 *\r
37 ************************************************/\r
38\r
39CPicoConfigDialog::CPicoConfigDialog(_currentConfig_t &cfg) : config(cfg)\r
40{\r
41}\r
42\r
43void CPicoConfigDialog::PostLayoutDynInitL()\r
44{\r
45 CEikHorOptionButtonList *buttons_rot = (CEikHorOptionButtonList*) Control( ECtlOptRotation );\r
46 CEikHorOptionButtonList *buttons_disp = (CEikHorOptionButtonList*) Control( ECtlOptScreenMode );\r
47 CEikCheckBox *chkbox_altrend= (CEikCheckBox*) Control( ECtlOptUseAltRend );\r
48// CEikCheckBox *chkbox_acctmng= (CEikCheckBox*) Control( ECtlOptUseAccTiming );\r
49 CEikCheckBox *chkbox_sram = (CEikCheckBox*) Control( ECtlOptUseSRAM );\r
50 CEikCheckBox *chkbox_fps = (CEikCheckBox*) Control( ECtlOptShowFPS );\r
51 CEikCheckBox *chkbox_sound = (CEikCheckBox*) Control( ECtlOptEnableSound );\r
52 CEikCheckBox *chkbox_z80 = (CEikCheckBox*) Control( ECtlOptEmulateZ80 );\r
53 CEikCheckBox *chkbox_ym2612 = (CEikCheckBox*) Control( ECtlOptEmulateYM2612 );\r
54 CEikCheckBox *chkbox_sn76496= (CEikCheckBox*) Control( ECtlOptEmulateSN76496 );\r
55 CEikChoiceListBase *combo_sndq = (CEikChoiceListBase*) Control( ECtlOptSndQuality );\r
56 CEikCheckBox *chkbox_6bpad = (CEikCheckBox*) Control( ECtlOpt6ButtonPad );\r
57 CEikCheckBox *chkbox_gzipst = (CEikCheckBox*) Control( ECtlOptGzipStates );\r
58// CEikCheckBox *chkbox_accsprt= (CEikCheckBox*) Control( ECtlOptUseAccSprites );\r
59 CEikChoiceListBase *combo_region = (CEikChoiceListBase*) Control( ECtlOptRegion );\r
60 CEikOptionButton *opt_fit2 = (CEikOptionButton*) buttons_disp->ComponentControl( TPicoConfig::PMFit2 );\r
61 CEikCheckBox *chkbox_cdda = (CEikCheckBox*) Control( ECtlOptCDcdda );\r
62 CEikCheckBox *chkbox_pcm = (CEikCheckBox*) Control( ECtlOptCDpcm );\r
63 CEikCheckBox *chkbox_ramcart= (CEikCheckBox*) Control( ECtlOptCDramcart );\r
64 CEikCheckBox *chkbox_sclrot = (CEikCheckBox*) Control( ECtlOptCDscalerot );\r
65 CEikCheckBox *chkbox_bsync = (CEikCheckBox*) Control( ECtlOptCDbettersync );\r
66\r
67 buttons_rot ->SetButtonById(ECtlOptRotation0 + config.rotation);\r
68 buttons_disp->SetButtonById(ECtlOptScreenModeCenter + config.scaling);\r
69 chkbox_sram ->SetState(config.EmuOpt & 1 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
70 chkbox_fps ->SetState(config.EmuOpt & 2 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
71 chkbox_sound ->SetState(config.EmuOpt & 4 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
72 chkbox_gzipst ->SetState(config.EmuOpt & 8 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
73 chkbox_z80 ->SetState(config.s_PicoOpt& 4 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
74 chkbox_ym2612 ->SetState(config.s_PicoOpt& 1 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
75 chkbox_sn76496->SetState(config.s_PicoOpt& 2 ? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
76 chkbox_altrend->SetState(config.s_PicoOpt& 0x10? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
77 chkbox_6bpad ->SetState(config.s_PicoOpt& 0x20? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
78// chkbox_acctmng->SetState(config.s_PicoOpt& 0x40? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
79// chkbox_accsprt->SetState(config.s_PicoOpt& 0x80? CEikButtonBase::ESet : CEikButtonBase::EClear);\r
80 chkbox_cdda ->SetState(config.s_PicoOpt&0x0800?CEikButtonBase::ESet : CEikButtonBase::EClear);\r
81 chkbox_pcm ->SetState(config.s_PicoOpt&0x0400?CEikButtonBase::ESet : CEikButtonBase::EClear);\r
82 chkbox_ramcart->SetState(config.s_PicoOpt&0x8000?CEikButtonBase::ESet : CEikButtonBase::EClear);\r
83 chkbox_sclrot ->SetState(config.s_PicoOpt&0x1000?CEikButtonBase::ESet : CEikButtonBase::EClear);\r
84 chkbox_bsync ->SetState(config.s_PicoOpt&0x2000?CEikButtonBase::ESet : CEikButtonBase::EClear);\r
85\r
86 // dim "fit2" if we are not in 0 or 180 mode\r
87 if (config.rotation != TPicoConfig::PRot0 && config.rotation != TPicoConfig::PRot180)\r
88 opt_fit2->SetDimmed(ETrue);\r
89 // dim some stuff for alternative renderer\r
90 if (config.s_PicoOpt & 0x10) {\r
91 // dim accurate sprites\r
92 //chkbox_accsprt->SetState(CEikButtonBase::EClear);\r
93 //chkbox_accsprt->SetDimmed(ETrue);\r
94 // dim fit\r
95 if(buttons_rot->LabeledButtonId() == ECtlOptRotation0 || buttons_rot->LabeledButtonId() == ECtlOptRotation180)\r
96 ((CEikOptionButton*)(buttons_disp->ComponentControl(TPicoConfig::PMFit)))->SetDimmed(ETrue);\r
97 }\r
98\r
99 TInt sel = 0;\r
100 switch (config.s_PsndRate) {\r
101 case 11025: sel = 1; break;\r
102 case 16000: sel = 2; break;\r
103 case 22050: sel = 3; break;\r
104 case 44100: sel = 4; break;\r
105 }\r
106 sel += (config.s_PicoOpt&8) ? 5 : 0;\r
107 if (sel >= 10) sel = 0;\r
108 combo_sndq->SetCurrentItem(sel);\r
109\r
110 switch(config.s_PicoRegion) {\r
111 case 1: sel = 4; break;\r
112 case 2: sel = 3; break;\r
113 case 4: sel = 2; break;\r
114 case 8: sel = 1; break;\r
115 default:sel = 0; // auto\r
116 }\r
117 combo_region->SetCurrentItem(sel);\r
118}\r
119\r
120TBool CPicoConfigDialog::OkToExitL(TInt aButtonId)\r
121{\r
122 if(aButtonId != EEikBidOk) return ETrue;\r
123\r
124 CEikHorOptionButtonList *buttons_rot = (CEikHorOptionButtonList*) Control( ECtlOptRotation );\r
125 CEikHorOptionButtonList *buttons_disp = (CEikHorOptionButtonList*) Control( ECtlOptScreenMode );\r
126 CEikCheckBox *chkbox_altrend= (CEikCheckBox*) Control( ECtlOptUseAltRend );\r
127// CEikCheckBox *chkbox_acctmng= (CEikCheckBox*) Control( ECtlOptUseAccTiming );\r
128 CEikCheckBox *chkbox_sram = (CEikCheckBox*) Control( ECtlOptUseSRAM );\r
129 CEikCheckBox *chkbox_fps = (CEikCheckBox*) Control( ECtlOptShowFPS );\r
130 CEikCheckBox *chkbox_sound = (CEikCheckBox*) Control( ECtlOptEnableSound );\r
131 CEikCheckBox *chkbox_z80 = (CEikCheckBox*) Control( ECtlOptEmulateZ80 );\r
132 CEikCheckBox *chkbox_ym2612 = (CEikCheckBox*) Control( ECtlOptEmulateYM2612 );\r
133 CEikCheckBox *chkbox_sn76496= (CEikCheckBox*) Control( ECtlOptEmulateSN76496 );\r
134 CEikChoiceListBase *combo_sndq = (CEikChoiceListBase*) Control( ECtlOptSndQuality );\r
135 CEikCheckBox *chkbox_6bpad = (CEikCheckBox*) Control( ECtlOpt6ButtonPad );\r
136 CEikCheckBox *chkbox_gzipst = (CEikCheckBox*) Control( ECtlOptGzipStates );\r
137// CEikCheckBox *chkbox_accsprt= (CEikCheckBox*) Control( ECtlOptUseAccSprites );\r
138 CEikChoiceListBase *combo_region = (CEikChoiceListBase*) Control( ECtlOptRegion );\r
139 CEikCheckBox *chkbox_cdda = (CEikCheckBox*) Control( ECtlOptCDcdda );\r
140 CEikCheckBox *chkbox_pcm = (CEikCheckBox*) Control( ECtlOptCDpcm );\r
141 CEikCheckBox *chkbox_ramcart= (CEikCheckBox*) Control( ECtlOptCDramcart );\r
142 CEikCheckBox *chkbox_sclrot = (CEikCheckBox*) Control( ECtlOptCDscalerot );\r
143 CEikCheckBox *chkbox_bsync = (CEikCheckBox*) Control( ECtlOptCDbettersync );\r
144\r
145 config.rotation = (TPicoConfig::TPicoScreenRotation) (buttons_rot->LabeledButtonId() - ECtlOptRotation0);\r
146 config.scaling = (TPicoConfig::TPicoScreenMode) (buttons_disp->LabeledButtonId() - ECtlOptScreenModeCenter);\r
147\r
148 if(chkbox_sram ->State() == CEikButtonBase::ESet) config.EmuOpt |= 1; else config.EmuOpt &= ~1;\r
149 if(chkbox_fps ->State() == CEikButtonBase::ESet) config.EmuOpt |= 2; else config.EmuOpt &= ~2;\r
150 if(chkbox_sound ->State() == CEikButtonBase::ESet) config.EmuOpt |= 4; else config.EmuOpt &= ~4;\r
151 if(chkbox_gzipst ->State() == CEikButtonBase::ESet) config.EmuOpt |= 8; else config.EmuOpt &= ~8;\r
152 if(chkbox_z80 ->State() == CEikButtonBase::ESet) config.s_PicoOpt|= 4; else config.s_PicoOpt&= ~4;\r
153 if(chkbox_ym2612 ->State() == CEikButtonBase::ESet) config.s_PicoOpt|= 1; else config.s_PicoOpt&= ~1;\r
154 if(chkbox_sn76496->State() == CEikButtonBase::ESet) config.s_PicoOpt|= 2; else config.s_PicoOpt&= ~2;\r
155 if(chkbox_altrend->State() == CEikButtonBase::ESet) config.s_PicoOpt|= 0x10;else config.s_PicoOpt&= ~0x10;\r
156 if(chkbox_6bpad ->State() == CEikButtonBase::ESet) config.s_PicoOpt|= 0x20;else config.s_PicoOpt&= ~0x20;\r
157// if(chkbox_acctmng->State() == CEikButtonBase::ESet) config.s_PicoOpt|= 0x40;else config.s_PicoOpt&= ~0x40;\r
158// if(chkbox_accsprt->State() == CEikButtonBase::ESet) config.s_PicoOpt|= 0x80;else config.s_PicoOpt&= ~0x80;\r
159 if(chkbox_cdda ->State() == CEikButtonBase::ESet) config.s_PicoOpt |= 0x0800; else config.s_PicoOpt&= ~0x0800;\r
160 if(chkbox_pcm ->State() == CEikButtonBase::ESet) config.s_PicoOpt |= 0x0400; else config.s_PicoOpt&= ~0x0400;\r
161 if(chkbox_ramcart->State() == CEikButtonBase::ESet) config.s_PicoOpt |= 0x8000; else config.s_PicoOpt&= ~0x8000;\r
162 if(chkbox_sclrot ->State() == CEikButtonBase::ESet) config.s_PicoOpt |= 0x1000; else config.s_PicoOpt&= ~0x1000;\r
163 if(chkbox_bsync ->State() == CEikButtonBase::ESet) config.s_PicoOpt |= 0x2000; else config.s_PicoOpt&= ~0x2000;\r
164\r
165 TInt sel = combo_sndq->CurrentItem();\r
166 if(sel >= 5) { config.s_PicoOpt |= 8; sel-=5; } else config.s_PicoOpt &= ~8;\r
167 switch (sel) {\r
168 default:config.s_PsndRate = 8000; break;\r
169 case 1: config.s_PsndRate = 11025; break;\r
170 case 2: config.s_PsndRate = 16000; break;\r
171 case 3: config.s_PsndRate = 22050; break;\r
172 case 4: config.s_PsndRate = 44100; break;\r
173 }\r
174\r
175 switch (combo_region->CurrentItem()) {\r
176 case 4: config.s_PicoRegion = 1; break;\r
177 case 3: config.s_PicoRegion = 2; break;\r
178 case 2: config.s_PicoRegion = 4; break;\r
179 case 1: config.s_PicoRegion = 8; break;\r
180 default:config.s_PicoRegion = 0; // auto\r
181 }\r
182\r
183 return ETrue;\r
184}\r
185\r
186// simple GUI stuff needs lots of code\r
187void CPicoConfigDialog::HandleControlStateChangeL(TInt aControlId)\r
188{\r
189 if (aControlId == ECtlOptEnableSound)\r
190 {\r
191 CEikCheckBox *chkbox_sound = (CEikCheckBox*) Control( ECtlOptEnableSound );\r
192 CEikCheckBox *chkbox_z80 = (CEikCheckBox*) Control( ECtlOptEmulateZ80 );\r
193 CEikCheckBox *chkbox_ym2612 = (CEikCheckBox*) Control( ECtlOptEmulateYM2612 );\r
194 CEikCheckBox *chkbox_sn76496= (CEikCheckBox*) Control( ECtlOptEmulateSN76496 );\r
195\r
196 if(chkbox_sound->State() == CEikButtonBase::ESet) {\r
197 // check all sound chips too, but only if they all are not set\r
198 if((chkbox_z80->State() | chkbox_ym2612->State() | chkbox_sn76496->State()) == CEikButtonBase::EClear) { // (==0)\r
199 chkbox_z80 ->SetState(CEikButtonBase::ESet);\r
200 chkbox_ym2612 ->SetState(CEikButtonBase::ESet);\r
201 chkbox_sn76496->SetState(CEikButtonBase::ESet);\r
202 chkbox_z80 ->DrawDeferred();\r
203 chkbox_ym2612 ->DrawDeferred();\r
204 chkbox_sn76496->DrawDeferred();\r
205 }\r
206 } else {\r
207 // clear everything, but only if everything is set\r
208 if((chkbox_z80->State() & chkbox_ym2612->State() & chkbox_sn76496->State()) == CEikButtonBase::ESet) { // (==1)\r
209 chkbox_z80 ->SetState(CEikButtonBase::EClear);\r
210 chkbox_ym2612 ->SetState(CEikButtonBase::EClear);\r
211 chkbox_sn76496->SetState(CEikButtonBase::EClear);\r
212 chkbox_z80 ->DrawDeferred();\r
213 chkbox_ym2612 ->DrawDeferred();\r
214 chkbox_sn76496->DrawDeferred();\r
215 }\r
216 }\r
217 }\r
218 else if(aControlId == ECtlOptUseAltRend || aControlId == ECtlOptRotation)\r
219 {\r
220 CEikCheckBox *chkbox_altrend= (CEikCheckBox*) Control( ECtlOptUseAltRend );\r
221// CEikCheckBox *chkbox_accsprt= (CEikCheckBox*) Control( ECtlOptUseAccSprites );\r
222 CEikHorOptionButtonList *buttons_rot = (CEikHorOptionButtonList*) Control( ECtlOptRotation );\r
223 CEikHorOptionButtonList *buttons_disp = (CEikHorOptionButtonList*) Control( ECtlOptScreenMode );\r
224 CEikOptionButton *opt_fit = (CEikOptionButton*) buttons_disp->ComponentControl( TPicoConfig::PMFit );\r
225 CEikOptionButton *opt_fit2 = (CEikOptionButton*) buttons_disp->ComponentControl( TPicoConfig::PMFit2 );\r
226\r
227 TBool dimmed = chkbox_altrend->State() == CEikButtonBase::ESet;\r
228 // show/hide more stuff for alternative renderer\r
229// chkbox_accsprt->SetDimmed(dimmed);\r
230 if(buttons_rot->LabeledButtonId() == ECtlOptRotation0 || buttons_rot->LabeledButtonId() == ECtlOptRotation180) {\r
231 opt_fit->SetDimmed(dimmed);\r
232 if(dimmed && buttons_disp->LabeledButtonId() == ECtlOptScreenModeFit)\r
233 buttons_disp->SetButtonById(ECtlOptScreenModeFit2);\r
234 }\r
235 else opt_fit->SetDimmed(EFalse);\r
236// chkbox_accsprt->DrawDeferred();\r
237 buttons_disp->DrawDeferred();\r
238\r
239 if(buttons_rot->LabeledButtonId() == ECtlOptRotation0 || buttons_rot->LabeledButtonId() == ECtlOptRotation180) {\r
240 opt_fit2->SetDimmed(EFalse);\r
241 } else {\r
242 if(opt_fit2->State() == CEikButtonBase::ESet) {\r
243 buttons_disp->SetButtonById(ECtlOptScreenModeFit);\r
244 buttons_disp->DrawDeferred();\r
245 }\r
246 opt_fit2->SetDimmed(ETrue);\r
247 }\r
248 opt_fit2->DrawDeferred();\r
249 }\r
250}\r
251\r
252\r
253/************************************************\r
254 *\r
255 * About Dialog\r
256 *\r
257 ************************************************/\r
258\r
259void CAboutDialog::PostLayoutDynInitL()\r
260{\r
261 TBuf<16> versionText;\r
262 TBuf<512> text;\r
263\r
264 #if (KPicoBuildNumber != 0)\r
265 versionText.Format(_L("%d.%d%d"), KPicoMajorVersionNumber, KPicoMinorVersionNumber, KPicoBuildNumber);\r
266 #else\r
267 versionText.Format(_L("%d.%d"), KPicoMajorVersionNumber, KPicoMinorVersionNumber);\r
268 #endif\r
269\r
270 CEikRichTextEditor* richTextEd = LocateControlByUniqueHandle<CEikRichTextEditor>(ECtlPicoAboutText);\r
271 User::LeaveIfNull(richTextEd);\r
272\r
273 HBufC *aboutFormat = CEikonEnv::Static()->AllocReadResourceLC(R_PICO_TEXT_ABOUT);\r
274 CSimpleTextFormatParser *parser = CSimpleTextFormatParser::NewLC();\r
275\r
276 text.Format(*aboutFormat, &versionText);\r
277 parser->ParseL(text, *richTextEd->RichText());\r
278\r
279 richTextEd->UpdateAllFieldsL(); // Updates all the fields in the document\r
280\r
281 CleanupStack::PopAndDestroy(parser);\r
282 CleanupStack::PopAndDestroy(aboutFormat);\r
283}\r
284\r
285/*************************************************************\r
286*\r
287* Credits dialog\r
288*\r
289**************************************************************/\r
290\r
291void CCreditsDialog::PreLayoutDynInitL()\r
292{\r
293 CEikEdwin *edwin = LocateControlByUniqueHandle<CEikEdwin>(ECtlPicoCreditsText);\r
294 User::LeaveIfNull(edwin);\r
295\r
296 CDesCArrayFlat* desArray = CEikonEnv::Static()->ReadDesCArrayResourceL(R_PICO_TBUF_CREDITS);\r
297 CleanupStack::PushL(desArray);\r
298\r
299 edwin->SetTextLimit(2048); // to prevent stupid "too big" warning\r
300 TInt count = desArray->Count();\r
301 for (TInt i = 0; i < count; i++)\r
302 {\r
303 edwin->Text()->InsertL(edwin->TextLength(), desArray->operator[](i));\r
304 edwin->Text()->InsertL(edwin->TextLength(), CEditableText::ELineBreak);\r
305 }\r
306 CleanupStack::PopAndDestroy(desArray);\r
307}\r
308\r
309TKeyResponse CCreditsDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)\r
310{\r
311 if (aType == EEventKey)\r
312 {\r
313 CEikEdwin *edwin = LocateControlByUniqueHandle<CEikEdwin>(ECtlPicoCreditsText);\r
314 User::LeaveIfNull(edwin);\r
315\r
316 if (aKeyEvent.iCode == EQuartzKeyTwoWayDown)\r
317 {\r
318 edwin->MoveDisplayL(TCursorPosition::EFLineDown);\r
319 edwin->UpdateScrollBarsL();\r
320 return EKeyWasConsumed;\r
321 }\r
322 else if (aKeyEvent.iCode == EQuartzKeyTwoWayUp)\r
323 {\r
324 edwin->MoveDisplayL(TCursorPosition::EFLineUp);\r
325 edwin->UpdateScrollBarsL();\r
326 return EKeyWasConsumed;\r
327 }\r
328 }\r
329 return CQikSimpleDialog::OfferKeyEventL(aKeyEvent, aType);\r
330}\r
331\r
332/*************************************************************\r
333*\r
334* Debug dialog\r
335*\r
336**************************************************************/\r
337\r
338CDebugDialog::CDebugDialog(char *t)\r
339{\r
340 Mem::Copy(iText, t, 1024);\r
341 iText[1023] = 0;\r
342}\r
343\r
344void CDebugDialog::PreLayoutDynInitL()\r
345{\r
346 char *p = iText, *line = iText;\r
347 TBool end=0;\r
348 TBuf<128> tbuf;\r
349 CEikEdwin *editor = LocateControlByUniqueHandle<CEikEdwin>(ECtlPicoCreditsText);\r
350\r
351 while(!end) {\r
352 while(*p && *p != '\r' && *p != '\n') p++;\r
353 if(!*p) end=1;\r
354 *p = 0;\r
355 TPtrC8 ptr((TUint8*) line);\r
356 tbuf.Copy(ptr);\r
357 editor->Text()->InsertL(editor->TextLength(), tbuf);\r
358 editor->Text()->InsertL(editor->TextLength(), CEditableText::ELineBreak);\r
359 line = ++p;\r
360 }\r
361}\r