sample_palmos.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:80k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*****************************************************************************  *  * This program is free software ; you can redistribute it and/or modify  * it under the terms of the GNU General Public License as published by  * the Free Software Foundation; either version 2 of the License, or  * (at your option) any later version.  *  * This program is distributed in the hope that it will be useful,  * but WITHOUT ANY WARRANTY; without even the implied warranty of  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  * GNU General Public License for more details.  *  * You should have received a copy of the GNU General Public License  * along with this program; if not, write to the Free Software  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *  * $Id: sample_palmos.c 623 2006-02-01 13:19:15Z picard $  *  * The Core Pocket Media Player  * Copyright (c) 2004-2005 Gabor Kovacs  *  ****************************************************************************/ #include "../common/common.h" #include "../common/palmos/pace.h" #include "../common/palmos/dia.h"
  2. #include "../interface/win.h"
  3. #include "../interface/settings.h"
  4. #include "../interface/benchresult.h"
  5. #include "../interface/palmos/keys.h"
  6. #include "../interface/skin.h"
  7. #include "resources.h"
  8. #include "events.h"
  9. static int ProgramId = 'TPLY'; static const tchar_t ProgramName[] = T("TCPMP"); static const tchar_t ProgramVersion[] =  #include "../version" ;
  10. #ifdef HAVE_PALMONE_SDK
  11. #include <Common/System/palmOneChars.h>
  12. #include <68K/System/PmPalmOSNVFS.h>
  13. #endif
  14. static diastate MainState; static int SIPState = 0;
  15. static player* Player = NULL; static bool_t HighDens = 0;
  16. static bool_t RefreshResize = 0;
  17. static int NoPaintResize = 0;
  18. static bool_t AttnEvent = 0;
  19. static bool_t FullScreen = 0;
  20. static int InFullScreen = -1; static bool_t MainDrawn = 0;
  21. static FormEventHandlerType* MouseDown = NULL; static UInt16 PrefCurrPage = PrefAudio;
  22. static bool_t KeyTrackNext = 0;
  23. static bool_t KeyTrackPrev = 0;
  24. static bool_t KeySelectHold = 0;
  25. static UInt16 LaunchCode = 0;
  26. static MemPtr LaunchParameters = NULL; static array VideoDriver;
  27. static array VideoDriverNames;
  28. static bool_t NoEventChecking = 0;
  29. static void* SkinDb = NULL;
  30. //static int InSkin = 0;
  31. static UInt32 SkinNo = 0;
  32. static skin Skin[MAX_SKIN];
  33. static NOINLINE void GetObjectBounds(FormType* Form, int Index, RectangleType* Rect) {     WinHandle Old = WinSetDrawWindow(FrmGetWindowHandle(Form));     FrmGetObjectBounds(Form,(UInt16)Index,Rect);     if (Old)         WinSetDrawWindow(Old); } static NOINLINE void SetObjectBounds(FormType* Form, int Index, const RectangleType* Rect) {     WinHandle Old = WinSetDrawWindow(FrmGetWindowHandle(Form));     FrmSetObjectBounds(Form,(UInt16)Index,Rect);     if (Old)         WinSetDrawWindow(Old); } static NOINLINE void ObjectPosition(FormType* Form,UInt16 Id,int x1,int x2,int y1,int y2,int w,int h) { RectangleType Rect; int Index = FrmGetObjectIndex(Form,Id); GetObjectBounds(Form,Index,&Rect); if (x1>=0 || x2>=0) { if (x1<0) Rect.topLeft.x = (Coord)(w - (160-x2) - Rect.extent.x); else { Rect.topLeft.x = (Coord)x1; if (x2>=0) Rect.extent.x = (Coord)(w - (160-x2) - x1); } } if (y1>=0 || y2>=0) { if (y1<0) Rect.topLeft.y = (Coord)(h - (160-y2) - Rect.extent.y); else { Rect.topLeft.y = (Coord)y1; if (y2>=0) Rect.extent.y = (Coord)(h - (160-y2) - y1); } } SetObjectBounds(Form,Index,&Rect); }
  34. static void HandleEvents();
  35. static void Refresh(FormType* Form,bool_t Draw);
  36. static bool_t Toggle(int Param,int Force);
  37. static void SetFullScreen(bool_t State);
  38. static NOINLINE bool_t IsVideoPrimary()
  39. {
  40. node* VOutput;
  41. bool_t Primary;
  42. int CoverArt = -2;
  43. node* Format = NULL;
  44. int VStream;
  45. if (Player->Get(Player,PLAYER_VOUTPUT,&VOutput,sizeof(VOutput))!=ERR_NONE || !VOutput)
  46. return 0;
  47. if (VOutput->Get(VOutput,VOUT_PRIMARY,&Primary,sizeof(Primary))!=ERR_NONE || !Primary)
  48. return 0;
  49. if (Player->Get(Player,PLAYER_FORMAT,&Format,sizeof(Format))==ERR_NONE && Format &&
  50. Format->Get(Format,FORMAT_COVERART,&CoverArt,sizeof(CoverArt))==ERR_NONE &&
  51. Player->Get(Player,PLAYER_VSTREAM,&VStream,sizeof(VStream))==ERR_NONE && VStream==CoverArt)
  52. return 0;
  53. return 1;
  54. }
  55. static NOINLINE void ShowObject(FormType* Form,UInt16 Id,bool_t State)
  56. {
  57. UInt16 Index = FrmGetObjectIndex(Form,Id);
  58. if (Index != frmInvalidObjectId)
  59. {
  60. if (State)
  61. FrmShowObject(Form,Index);
  62. else
  63. FrmHideObject(Form,Index);
  64. }
  65. }
  66. static NOINLINE void SetClipping(bool_t b)
  67. {
  68. if (b && IsVideoPrimary())
  69. Toggle(PLAYER_PLAY,0);
  70. Player->Set(Player,PLAYER_CLIPPING,&b,sizeof(b));
  71. if (b)
  72. SetDisplayPower(1,0);
  73. }
  74. static void MainFormResize(FormType* Form) {     Coord Width;     Coord Height; RectangleType Bounds; rect Viewport; diastate State;
  75. if (!FullScreen)
  76. SIPState = DIAGet(DIA_ALL);
  77. DIAGetState(&State);
  78. if (MainState.Width != State.Width ||
  79. MainState.Height != State.Height ||
  80. MainState.Direction != State.Direction)
  81. {
  82. memcpy(&MainState,&State,sizeof(State)); WinGetDisplayExtent(&Width, &Height); Bounds.topLeft.x = 0; Bounds.topLeft.y = 0; Bounds.extent.x = Width; Bounds.extent.y = Height; WinSetBounds(FrmGetWindowHandle(Form), &Bounds);
  83. if (FullScreen)
  84. { ObjectPosition(Form,MainViewport,0,160,0,160,Width,Height);
  85. Viewport.x = 0;
  86. Viewport.y = 0;
  87. Viewport.Width = (Coord)Width;
  88. Viewport.Height = (Coord)Height;
  89. }
  90. else
  91. {
  92. if (Skin[SkinNo].Valid)
  93. {
  94. Viewport = Skin[SkinNo].Item[SKIN_VIEWPORT].Rect;
  95. ObjectPosition(Form,MainViewport,Viewport.x,Viewport.y,Viewport.x+Viewport.Width,Viewport.y+Viewport.Height,Width,Height);
  96. }
  97. else
  98. { ObjectPosition(Form,MainViewport,0,160,15,130,Width,Height);
  99. ObjectPosition(Form,MainWinTitle,0,-1,0,-1,Width,Height);
  100. ObjectPosition(Form,MainTitle,45,159,2,-1,Width,Height); ObjectPosition(Form,MainPosition,1,129,-1,143,Width,Height);
  101. ObjectPosition(Form,MainTimer,-1,159,-1,143,Width,Height);
  102. ObjectPosition(Form,MainPrev,1,-1,-1,159,Width,Height); ObjectPosition(Form,MainPlay,31,-1,-1,159,Width,Height); ObjectPosition(Form,MainNext,71,-1,-1,159,Width,Height); ObjectPosition(Form,MainFullScreen,101,-1,-1,159,Width,Height); ObjectPosition(Form,MainPref,131,-1,-1,159,Width,Height);
  103. Viewport.x = 0; Viewport.y = 15; Viewport.Width = (Coord)(160+Width-160-Viewport.x); Viewport.Height = (Coord)(130+Height-160-Viewport.y);
  104. }
  105. }
  106. if (HighDens) { UInt16 OldCoord = WinSetCoordinateSystem(kCoordinatesNative); Viewport.Width = WinScaleCoord((Coord)(Viewport.x+Viewport.Width),1); Viewport.Height = WinScaleCoord((Coord)(Viewport.y+Viewport.Height),1); Viewport.x = WinScaleCoord((Coord)Viewport.x,0); Viewport.y = WinScaleCoord((Coord)Viewport.y,0); Viewport.Width -= Viewport.x; Viewport.Height -= Viewport.y; WinSetCoordinateSystem(OldCoord); }
  107. Player->Set(Player,PLAYER_ROTATEBEGIN,NULL,0); Player->Set(Player,PLAYER_RESETVIDEO,NULL,0); Player->Set(Player,PLAYER_SKIN_VIEWPORT,&Viewport,sizeof(rect)); Player->Set(Player,PLAYER_FULLSCREEN,&FullScreen,sizeof(FullScreen));
  108. Player->Set(Player,PLAYER_UPDATEVIDEO,NULL,0);
  109. NoPaintResize = -1; // force redraw }
  110. if (NoPaintResize<=0)
  111. {
  112. if (FullScreen)
  113. {
  114. Player->Set(Player,PLAYER_ROTATEEND,NULL,0);
  115. }
  116. else
  117. {
  118. if (MainDrawn)
  119. {
  120. IndexedColorType BackColor;
  121. RectangleType Rect;
  122. UInt16 i,n = FrmGetNumberOfObjects(Form);
  123. WinHandle Old = WinSetDrawWindow(FrmGetWindowHandle(Form));
  124. if (!Skin[SkinNo].Valid)
  125. {
  126. WinGetBounds(FrmGetWindowHandle(Form), &Rect );
  127. BackColor = WinSetBackColor(UIColorGetTableEntryIndex(UIFormFill));
  128. Rect.topLeft.x = 0;
  129. Rect.topLeft.y = (Coord)(Rect.extent.y-160+130);
  130. Rect.extent.y = 160-130;
  131. WinEraseRectangle(&Rect,0);
  132. Rect.topLeft.y = 0;
  133. Rect.extent.y = 15;
  134. WinEraseRectangle(&Rect,0);
  135. WinSetBackColor(BackColor);
  136. for (i=0;i<n;++i)
  137. FrmShowObject(Form,i);
  138. }
  139. else
  140. {
  141. SkinDraw(&Skin[SkinNo],FrmGetWindowHandle(Form),NULL);
  142. ShowObject(Form,MainViewport,1);
  143. }
  144. if (Old)
  145. WinSetDrawWindow(Old);
  146. }
  147. else
  148. {
  149. if (Skin[SkinNo].Valid)
  150. {
  151. ShowObject(Form,MainTitle,0);
  152. ShowObject(Form,MainPosition,0);
  153. ShowObject(Form,MainTimer,0);
  154. ShowObject(Form,MainPrev,0);
  155. ShowObject(Form,MainNext,0);
  156. ShowObject(Form,MainPlay,0);
  157. ShowObject(Form,MainFullScreen,0);
  158. ShowObject(Form,MainPref,0);
  159. }
  160. FrmDrawForm(Form);
  161. if (Skin[SkinNo].Valid)
  162. SkinDraw(&Skin[SkinNo],FrmGetWindowHandle(Form),NULL);
  163. MainDrawn = 1;
  164. }
  165. if (Skin[SkinNo].Valid)
  166. {
  167. RectangleType Rect;
  168. WinGetBounds(FrmGetWindowHandle(Form), &Rect );
  169. if (Rect.extent.y > Skin[SkinNo].Bitmap[0].Height)
  170. {
  171. RGBColorType c,c0;
  172. c.index = 0;
  173. c.r = 0;
  174. c.g = 0;
  175. c.b = 0;
  176. WinSetBackColorRGB(&c,&c0);
  177. Rect.topLeft.x = 0;
  178. Rect.topLeft.y = (UInt16)Skin[SkinNo].Bitmap[0].Height;
  179. Rect.extent.y = (Int16)(Rect.extent.y - Skin[SkinNo].Bitmap[0].Height);
  180. WinEraseRectangle(&Rect,0);
  181. WinSetBackColorRGB(&c0,&c);
  182. }
  183. }
  184. }
  185. }
  186. NoPaintResize = 0;
  187. if (RefreshResize)
  188. {
  189. RefreshResize = 0;
  190. Refresh(Form,1);
  191. SetClipping(0);
  192. }
  193. }
  194. static void EnumDir(const tchar_t* Path,const tchar_t* Exts,int Deep) { if (Deep>=0) { streamdir DirItem; stream* Stream = GetStream(Path,1); if (Stream) { int Result = Stream->EnumDir(Stream,Path,Exts,1,&DirItem); while (Result == ERR_NONE) { tchar_t FullPath[MAXPATH]; AbsPath(FullPath,TSIZEOF(FullPath),DirItem.FileName,Path); if (DirItem.Size < 0) EnumDir(FullPath,Exts,Deep-1); else if (DirItem.Type == FTYPE_AUDIO || DirItem.Type == FTYPE_VIDEO) { int n; Player->Get(Player,PLAYER_LIST_COUNT,&n,sizeof(n)); Player->Set(Player,PLAYER_LIST_URL+n,FullPath,sizeof(FullPath)); } Result = Stream->EnumDir(Stream,NULL,NULL,0,&DirItem); } NodeDelete((node*)Stream); } } } static void GenExts(tchar_t* Exts,int ExtsLen) { int* i; array List; Exts[0]=0; NodeEnumClass(&List,MEDIA_CLASS); for (i=ARRAYBEGIN(List,int);i!=ARRAYEND(List,int);++i) { const tchar_t* s = LangStr(*i,NODE_EXTS); if (s[0]) { if (Exts[0]) tcscat_s(Exts,ExtsLen,T(";")); tcscat_s(Exts,ExtsLen,s); } } ArrayClear(&List); } static void SearchFiles() { tchar_t* Exts = malloc(1024*sizeof(tchar_t)); if (Exts) { int n; GenExts(Exts,1024); n=0; Player->Set(Player,PLAYER_LIST_COUNT,&n,sizeof(n)); EnumDir("",Exts,2); free(Exts); n=0; Player->Set(Player,PLAYER_LIST_CURRIDX,&n,sizeof(n)); } } static NOINLINE bool_t Visible(FormType* Form) {
  195. return !FullScreen && FrmGetActiveForm()==Form; } static void UpdatePosition(FormType* Form,bool_t Draw) {
  196. static tchar_t Timer[40] = {0};
  197. tchar_t s[40];
  198. fraction Percent; UInt16 Pos;
  199. if (Player->Get(Player,PLAYER_PERCENT,&Percent,sizeof(Percent)) != ERR_NONE)
  200. {
  201. Percent.Num = 0;
  202. Percent.Den = 1;
  203. } if (Percent.Num>Percent.Den) Percent.Num=Percent.Den; if (Percent.Num<0) Percent.Num=0; Pos = (UInt16)Scale(16384,Percent.Num,Percent.Den); CtlSetSliderValues(FrmGetObjectPtr(Form,FrmGetObjectIndex(Form,MainPosition)),NULL,NULL,NULL,&Pos);
  204. Player->Get(Player,PLAYER_TIMER,s,sizeof(s));
  205. if (tcscmp(s,Timer)!=0)
  206. {
  207. FieldType* Field = (FieldType*)FrmGetObjectPtr(Form,FrmGetObjectIndex(Form,MainTimer));
  208. tcscpy_s(Timer,TSIZEOF(Timer),s);
  209. FldSetTextPtr(Field,Timer);
  210. if (Draw)
  211. FldDrawField(Field);
  212. }
  213. } static void UpdateTitle(FormType* Form,bool_t Draw) { static tchar_t Title[40] = {0}; tchar_t s[40];
  214. Player->Get(Player,PLAYER_TITLE,s,sizeof(s)); if (tcscmp(s,Title)!=0) { FormType* Form = FrmGetFormPtr(MainForm); FieldType* Field = (FieldType*)FrmGetObjectPtr(Form,FrmGetObjectIndex(Form,MainTitle)); tcscpy_s(Title,TSIZEOF(Title),s); FldSetTextPtr(Field,Title);
  215. if (Draw) FldDrawField(Field); } } static void UpdatePlayButton(FormType* Form) { bool_t Play; Player->Get(Player,PLAYER_PLAY,&Play,sizeof(Play)); CtlSetValue(FrmGetObjectPtr(Form,FrmGetObjectIndex(Form,MainPlay)),(Int16)Play); }
  216. static void Refresh(FormType* Form,bool_t Draw) { if (Visible(Form)) { UpdatePosition(Form,Draw); UpdatePlayButton(Form); UpdateTitle(Form,Draw);
  217. }
  218. }
  219. static void BenchmarkVerify()
  220. {
  221. node* Node;
  222. Player->Get(Player,PLAYER_VOUTPUT,&Node,sizeof(Node));
  223. if (Node)
  224. {
  225. int Dropped = 0;
  226. Node->Get(Node,OUT_DROPPED,&Dropped,sizeof(int));
  227. if (Dropped > 2)
  228. ShowError(0,BENCHRESULT_ID,BENCHRESULT_INVALID);
  229. }
  230. }
  231. static NOINLINE bool_t IsAudioPlayed()
  232. {
  233. bool_t Play,FFwd;
  234. node* AOutput;
  235. Player->Get(Player,PLAYER_PLAY,&Play,sizeof(Play));
  236. Player->Get(Player,PLAYER_FFWD,&FFwd,sizeof(FFwd));
  237. return Player->Get(Player,PLAYER_AOUTPUT,&AOutput,sizeof(AOutput))==ERR_NONE && AOutput && (Play || FFwd);
  238. }
  239. static NOINLINE bool_t IsPlayList()
  240. {
  241. int Count;
  242. return Player->Get(Player,PLAYER_LIST_COUNT,&Count,sizeof(Count))==ERR_NONE && Count>1;
  243. }
  244. static int PlayerNotify(FormType* Form,int Id,int Value) {
  245. if (Id == PLAYER_PERCENT && Value==1)
  246. {
  247. GetDisplayPower(); // udpate if display has turned on somehow
  248. if (!NoEventChecking)
  249. HandleEvents(); //EvtGetEvent() has to be called (alarm) even if the main loop is busy with decoding
  250. }
  251. if (Id == PLAYER_FULLSCREEN)  
  252. SetFullScreen(Value); 
  253. if (Visible(Form)) { if (Id == PLAYER_PERCENT)
  254. UpdatePosition(Form,1);
  255. if (Id == PLAYER_PLAY) UpdatePlayButton(Form); if (Id == PLAYER_TITLE) UpdateTitle(Form,1); } if (Id == PLAYER_BENCHMARK) { EventType Event; Toggle(PLAYER_PLAY,0); SetFullScreen(0);
  256. BenchmarkVerify();
  257. memset(&Event,0,sizeof(Event)); Event.eType = menuEvent; Event.data.menu.itemID = MainBenchmarkForm; _EvtAddUniqueEventToQueue(&Event, 0, 1); }
  258. if (Id == PLAYER_POWEROFF && !Value)
  259. {
  260. if (Form != FrmGetActiveForm()) 
  261. SetClipping(1); // probably keylock window
  262. if ((FullScreen?0:SIPState)!=DIAGet(DIA_ALL))
  263. {
  264. // overlay will be reinited in a different mode
  265. // we need to clear MainState so next resize will 
  266. // reinit overlay when dia is restored
  267. memset(&MainState,0,sizeof(MainState));
  268. }
  269. } return ERR_NONE; }
  270. static void UpdateSkin(bool_t Init);
  271. static void MainFormInit(FormType* Form) { notify Notify; UInt32 Version; Notify.This = Form; Notify.Func = (notifyfunc)PlayerNotify; Player->Set(Player,PLAYER_NOTIFY,&Notify,sizeof(Notify)); HighDens = FtrGet(sysFtrCreator, sysFtrNumWinVersion, &Version)==errNone && Version>=4;
  272. SkinDb = SkinLoad(Skin,Form,NULL);
  273. UpdateSkin(1);
  274. FtrGet(Context()->ProgramId,20000,&SkinNo);
  275. } static void UpdateControls(bool_t State) {
  276. static const UInt16 Controls[] = { 
  277. MainTitle, MainPosition, MainTimer, MainPrev,
  278. MainPlay, MainNext, MainFullScreen, MainPref, 0 };
  279. FormType* Form = FrmGetFormPtr(MainForm);
  280. const UInt16* i;
  281. if (Skin[SkinNo].Valid)
  282. State = 0;
  283. for (i=Controls;*i;++i)
  284. {
  285. UInt16 Index = FrmGetObjectIndex(Form,*i);
  286. if (Index != frmInvalidObjectId)
  287. CtlSetUsable(FrmGetObjectPtr(Form,Index),(Boolean)State);
  288. }
  289. } static void ApplicationPostEvent();
  290. static Boolean ApplicationHandleEvent(EventPtr Event);
  291. static Boolean PlatformHandleEvent(EventPtr Event)
  292. {
  293. if (Event->eType == keyDownEvent && Event->data.keyDown.chr == vchrPowerOff && !GetDisplayPower())
  294. {
  295. SetDisplayPower(1,0);
  296. SetKeyboardBacklight(1);
  297. return 1;
  298. }
  299. else
  300. if ((Event->eType == penDownEvent || Event->eType == penUpEvent) && 
  301. FrmGetActiveForm() == FrmGetFormPtr(MainForm) && !GetDisplayPower())
  302. return 1;
  303. if (Event->eType == keyUpEvent)
  304. GetDisplayPower(); // refresh, if neccessary disable led blinking
  305. return 0;
  306. }
  307. static NOINLINE void PushReDraw()
  308. {
  309. EventType e;
  310. memset(&e,0,sizeof(e));
  311. e.eType = winDisplayChangedEvent;
  312. _EvtAddUniqueEventToQueue(&e, 0, 1);
  313. }
  314. static void HandleEvents() { EventType event; for (;;) { _EvtGetEvent(&event,0); if (event.eType == nilEvent)
  315. break;
  316. if (!PlatformHandleEvent(&event))
  317. if (!ApplicationHandleEvent(&event)) // important: before SysHandleEvent
  318. OSHandleEvent(&event);
  319. ApplicationPostEvent(); } }
  320. static void UpdateSkin(bool_t Init)
  321. {
  322. if (SkinNo>0 && !Skin[SkinNo].Valid)
  323. SkinNo=0;
  324. if (!Init || Skin[SkinNo].Valid)
  325. UpdateControls(!FullScreen);
  326. }
  327. static void SetFullScreen(bool_t State)
  328. {
  329. if (InFullScreen>=0)
  330. {
  331. InFullScreen=State;
  332. return;
  333. }
  334. InFullScreen = State;
  335. while (FullScreen != InFullScreen)
  336. {
  337. Player->Set(Player,PLAYER_ROTATEBEGIN,NULL,0);
  338. FullScreen = (bool_t)InFullScreen;
  339. memset(&MainState,0,sizeof(MainState));
  340. if (FullScreen)
  341. {
  342. UpdateControls(0);
  343. DIASet(0,DIA_ALL);
  344. SetKeyboardBacklight(0);
  345. }
  346. else
  347. {
  348. Refresh(FrmGetFormPtr(MainForm),0);
  349. DIASet(SIPState,DIA_ALL);
  350. SetKeyboardBacklight(1);
  351. UpdateControls(1);
  352. }
  353. PushReDraw();
  354. HandleEvents();
  355. }
  356. InFullScreen = -1;
  357. }
  358. static NOINLINE bool_t Toggle(int Param,int Force) { bool_t State = 0; if (Player->Get(Player,Param,&State,sizeof(State))==ERR_NONE && State!=Force) { State = !State; Player->Set(Player,Param,&State,sizeof(State)); Player->Get(Player,Param,&State,sizeof(State)); } return State; } static NOINLINE int Delta(int Param,int d,int Min,int Max) { int State; if (Player && Player->Get(Player,Param,&State,sizeof(State))==ERR_NONE) { State += d; if (State < Min) State = Min; if (State > Max) State = Max; Player->Set(Player,Param,&State,sizeof(State)); if (Param == PLAYER_VOLUME && State > Min)  Toggle(PLAYER_MUTE,0); } return State; } static Boolean ViewportEventHandler(struct FormGadgetTypeInCallback *gadgetP, UInt16 cmd, void *paramP) { if (cmd == formGadgetDrawCmd) {
  359. diastate State;
  360. DIAGetState(&State);
  361. if (MainState.Width == State.Width &&
  362. MainState.Height == State.Height &&
  363. MainState.Direction == State.Direction)
  364. {
  365. gadgetP->attr.visible = true;
  366. Player->Set(Player,PLAYER_ROTATEEND,NULL,0);
  367. } return 1; } return 0; } static Boolean WinTitleEventHandler(struct FormGadgetTypeInCallback *gadgetP, UInt16 cmd, void *paramP)
  368. {
  369. if (cmd == formGadgetDrawCmd)
  370. {
  371. IndexedColorType BackColor,TextColor;
  372. FontID Font;
  373. BackColor = WinSetBackColor(UIColorGetTableEntryIndex(UIFormFrame));
  374. TextColor = WinSetTextColor(UIColorGetTableEntryIndex(UIFormFill));
  375. Font = FntSetFont(boldFont);
  376. WinEraseRectangle(&gadgetP->rect,0);
  377. WinDrawChars(Context()->ProgramName,(Int16)tcslen(Context()->ProgramName),
  378. (Coord)(gadgetP->rect.topLeft.x+2),(Coord)(gadgetP->rect.topLeft.y+2));
  379. WinSetBackColor(BackColor);
  380. WinSetTextColor(TextColor);
  381. FntSetFont(Font);
  382. gadgetP->attr.visible = true;
  383. return 1;
  384. }
  385. return 0;
  386. }
  387. static void OpenResize(Coord Width,Coord Height); static void ResizeForm(FormType* Form) {     Coord Width;     Coord Height; RectangleType Bounds; WinHandle Win = FrmGetWindowHandle(Form); WinGetDisplayExtent(&Width, &Height); WinGetBounds(Win, &Bounds ); if (Bounds.topLeft.x!=0 || Bounds.topLeft.y!=0 || Bounds.extent.x!=Width || Bounds.extent.y!=Height) { Bounds.topLeft.x = 0; Bounds.topLeft.y = 0; Bounds.extent.x = Width; Bounds.extent.y = Height; WinSetBounds(Win, &Bounds); switch (FrmGetFormId(Form)) {
  388. case PrefForm: ObjectPosition(Form,PrefGeneral,-1,-1,-1,143+15,Width,Height);
  389. ObjectPosition(Form,PrefVideo,-1,-1,-1,143+15,Width,Height);
  390. ObjectPosition(Form,PrefAudio,-1,-1,-1,143+15,Width,Height);
  391. ObjectPosition(Form,PrefClose,-1,-1,-1,143+15,Width,Height);
  392. break; case OpenForm: OpenResize(Width,Height); break;
  393. case EqForm:
  394. ObjectPosition(Form,EqReset,-1,-1,-1,146+12,Width,Height);
  395. //no break
  396. default:
  397. ObjectPosition(Form,DummyOk,-1,-1,-1,146+12,Width,Height);
  398. break;
  399. } }
  400. FrmDrawForm(Form); }
  401. static Boolean DummyHandler( FormType* Form, EventPtr Event ) { if (DIAHandleEvent(Form,Event)) return 1; switch (Event->eType) { case frmOpenEvent: SetClipping(1);
  402. PushReDraw(); break;
  403. case frmUpdateEvent:
  404. PushReDraw();
  405. return 1;
  406.   case winDisplayChangedEvent: ResizeForm(Form); return 1;
  407. case winEnterEvent: if (Event->data.winEnter.enterWindow == (WinHandle)Form && Form == FrmGetActiveForm()) PushReDraw(); return 1; case winExitEvent: return 1; case ctlSelectEvent: if (Event->data.ctlSelect.controlID == DummyOk ||  Event->data.ctlSelect.controlID == DummyCancel) {
  408. FrmReturnToForm(MainForm); return 1; } break; default: break; } return 0; }
  409. static NOINLINE void UpdateVideoCaps(FormType* Form)
  410. {
  411. int i;
  412. bool_t b;
  413. node* Color = NodeEnumObject(NULL,COLOR_ID);
  414. b = Color->Get(Color,COLOR_BRIGHTNESS,&i,sizeof(i))==ERR_NONE;
  415. ShowObject(Form,PrefVideoBrightness,b);
  416. ShowObject(Form,PrefVideoBrightnessLabel,b);
  417. ShowObject(Form,PrefVideoBrightnessValue,b);
  418. b = Color->Get(Color,COLOR_CONTRAST,&i,sizeof(i))==ERR_NONE;
  419. ShowObject(Form,PrefVideoContrast,b);
  420. ShowObject(Form,PrefVideoContrastLabel,b);
  421. ShowObject(Form,PrefVideoContrastValue,b);
  422. b = Color->Get(Color,COLOR_SATURATION,&i,sizeof(i))==ERR_NONE;
  423. ShowObject(Form,PrefVideoSaturation,b);
  424. ShowObject(Form,PrefVideoSaturationLabel,b);
  425. ShowObject(Form,PrefVideoSaturationValue,b);
  426. b = Color->Get(Color,COLOR_R_ADJUST,&i,sizeof(i))==ERR_NONE;
  427. ShowObject(Form,PrefVideoRed,b);
  428. ShowObject(Form,PrefVideoRedLabel,b);
  429. ShowObject(Form,PrefVideoRedValue,b);
  430. b = Color->Get(Color,COLOR_G_ADJUST,&i,sizeof(i))==ERR_NONE;
  431. ShowObject(Form,PrefVideoGreen,b);
  432. ShowObject(Form,PrefVideoGreenLabel,b);
  433. ShowObject(Form,PrefVideoGreenValue,b);
  434. b = Color->Get(Color,COLOR_B_ADJUST,&i,sizeof(i))==ERR_NONE;
  435. ShowObject(Form,PrefVideoBlue,b);
  436. ShowObject(Form,PrefVideoBlueLabel,b);
  437. ShowObject(Form,PrefVideoBlueValue,b);
  438. b = Color->Get(Color,COLOR_DITHER,&i,sizeof(i))==ERR_NONE;
  439. ShowObject(Form,PrefVideoDither,b);
  440. b = Player->Get(Player,PLAYER_VIDEO_QUALITY,&i,sizeof(i))==ERR_NONE;
  441. ShowObject(Form,PrefVideoQuality,b);
  442. }
  443. static void PrefPage(FormType* Form,UInt16 Id) { static const UInt16 Group[] =  { PrefGeneralRepeat,PrefGeneral, PrefGeneralShuffle,PrefGeneral, PrefGeneralSpeedLabel,PrefGeneral, PrefGeneralSpeedValue,PrefGeneral,
  444. PrefGeneralSpeed,PrefGeneral, PrefGeneralSpeedOrig,PrefGeneral, PrefGeneralSpeedCustom,PrefGeneral,
  445. PrefGeneralMoveFFwdLabel,PrefGeneral, PrefGeneralMoveFFwd,PrefGeneral,
  446. PrefGeneralMoveFFwdLabel2,PrefGeneral,
  447. PrefGeneralMoveBackLabel,PrefGeneral,
  448. PrefGeneralMoveBack,PrefGeneral,
  449. PrefGeneralMoveBackLabel2,PrefGeneral,
  450. PrefGeneralAVOffsetLabel,PrefGeneral,
  451. PrefGeneralAVOffset,PrefGeneral,
  452. PrefGeneralAVOffsetLabel2,PrefGeneral,
  453. PrefAudioDisable,PrefAudio, PrefAudioVolumeLabel,PrefAudio, PrefAudioVolumeValue,PrefAudio,
  454. PrefAudioVolume,PrefAudio, PrefAudioPreampLabel,PrefAudio, PrefAudioPreampValue,PrefAudio,
  455. PrefAudioPreamp,PrefAudio, PrefAudioPreampReset,PrefAudio,
  456. PrefAudioPanLabel,PrefAudio, PrefAudioPanLabel2,PrefAudio,
  457. PrefAudioPanValue,PrefAudio,
  458. PrefAudioPan,PrefAudio,
  459. PrefAudioPanReset,PrefAudio,
  460. PrefAudioStereo,PrefAudio, PrefVideoDriver,PrefVideo, PrefVideoAspect,PrefVideo,
  461. PrefVideoFullLabel,PrefVideo, PrefVideoSkinLabel,PrefVideo, PrefVideoZoomLabel,PrefVideo, PrefVideoRotateLabel,PrefVideo, PrefVideoFullZoom,PrefVideo, PrefVideoSkinZoom,PrefVideo, PrefVideoFullRotate,PrefVideo, PrefVideoSkinRotate,PrefVideo, PrefVideoDither,PrefVideo, PrefVideoQuality,PrefVideo,
  462. PrefVideoBrightness,PrefVideo, PrefVideoContrast,PrefVideo, PrefVideoSaturation,PrefVideo, PrefVideoRed,PrefVideo, PrefVideoGreen,PrefVideo, PrefVideoBlue,PrefVideo, PrefVideoBrightnessLabel,PrefVideo, PrefVideoContrastLabel,PrefVideo, PrefVideoSaturationLabel,PrefVideo, PrefVideoRedLabel,PrefVideo, PrefVideoGreenLabel,PrefVideo, PrefVideoBlueLabel,PrefVideo, PrefVideoBrightnessValue,PrefVideo,
  463. PrefVideoContrastValue,PrefVideo,
  464. PrefVideoSaturationValue,PrefVideo,
  465. PrefVideoRedValue,PrefVideo,
  466. PrefVideoGreenValue,PrefVideo,
  467. PrefVideoBlueValue,PrefVideo,
  468. 0,0 }; const UInt16* i; RectangleType r;
  469. //FrmGlueNavRemoveFocusRing(Form); //crashes in longterm at program exit!
  470. if (WinGetDrawWindow() == FrmGetWindowHandle(Form)) { r.topLeft.x = 0; r.topLeft.y = 16; r.extent.x = 160; r.extent.y = 126; WinEraseRectangle(&r,0); } for (i=Group;i[0];i+=2) if (Id != i[1]) ShowObject(Form,i[0],0); for (i=Group;i[0];i+=2) if (Id == i[1])
  471. ShowObject(Form,i[0],1);
  472. if (Id == PrefVideo)
  473. UpdateVideoCaps(Form);
  474. PrefCurrPage = Id;
  475. /* //crashes in longterm at program exit!
  476. switch (PrefCurrPage)
  477. {
  478. case PrefGeneral: FrmGlueNavObjectTakeFocus(Form, PrefGeneralSpeedOrig); break;
  479. case PrefVideo: FrmGlueNavObjectTakeFocus(Form, PrefVideoSkinZoom); break;
  480. case PrefAudio: FrmGlueNavObjectTakeFocus(Form, PrefAudioVolume); break;
  481. }
  482. */
  483. } static NOINLINE void SetList(FormType* Form,int Id,int IdList,int Value,bool_t OnlyLabel) { void* List = FrmGetObjectPtr(Form,FrmGetObjectIndex(Form,(UInt16)IdList)); if (!OnlyLabel) 
  484. LstSetSelection(List,(Int16)Value);
  485. CtlSetLabel(FrmGetObjectPtr(Form,FrmGetObjectIndex(Form,(UInt16)Id)),LstGetSelectionText(List,(Int16)Value)); }
  486. static NOINLINE bool_t GetFieldInt(FormType* Form,UInt16 Id,int* Value)
  487. {
  488. FieldType* Field = (FieldType*)FrmGetObjectPtr(Form,FrmGetObjectIndex(Form,Id));
  489. const tchar_t* s = FldGetTextPtr(Field);
  490. return s && stscanf(s,T("%d"),Value)==1;
  491. }
  492. static NOINLINE void SetFieldInt(FormType* Form,UInt16 Id,int Value,bool_t Draw)
  493. {
  494. FieldType* Field = (FieldType*)FrmGetObjectPtr(Form,FrmGetObjectIndex(Form,Id));
  495.     MemHandle h0,h = MemHandleNew(12*sizeof(tchar_t));
  496. tchar_t *s;
  497. if (h)
  498. {
  499. s=MemHandleLock(h);
  500. IntToString(s,12,Value,0);
  501. MemHandleUnlock(h);
  502. h0 = FldGetTextHandle(Field);
  503. FldSetTextHandle(Field,h);
  504. if (h0)
  505. MemHandleFree(h0);
  506. if (Draw)
  507. FldDrawField(Field);
  508. }
  509. }
  510. static NOINLINE int FromDir(int i) { switch (i) { case 0: return 1; case DIR_SWAPXY | DIR_MIRRORLEFTRIGHT: return 2; case DIR_MIRRORUPDOWN | DIR_MIRRORLEFTRIGHT: return 3; case DIR_SWAPXY | DIR_MIRRORUPDOWN: return 4; } return 0; } static NOINLINE int ToDir(int i) { switch (i) { case 1: return 0; case 2: return DIR_SWAPXY | DIR_MIRRORLEFTRIGHT; case 3: return DIR_MIRRORUPDOWN | DIR_MIRRORLEFTRIGHT; case 4: return DIR_SWAPXY | DIR_MIRRORUPDOWN; } return -1; }
  511. static const fraction ZoomTab[10] =
  512. {
  513. {0,0},
  514. {-4,SCALE_ONE},
  515. {-3,SCALE_ONE},
  516. {-11,10},
  517. {-12,10},
  518. {-13,10},
  519. {1,2},
  520. {1,1},
  521. {3,2},
  522. {2,1},
  523. };
  524. static NOINLINE void ToZoom(int i,fraction* f) {
  525. *f = ZoomTab[i];
  526. } static NOINLINE int FromZoom(const fraction* f) {
  527. int i;
  528. if (f->Num) for (i=1;i<10;++i)
  529. if (EqFrac(f,ZoomTab+i)) 
  530. return i;
  531. return 0; }
  532. static const fraction AspectTab[8] =
  533. {
  534. {0,1},
  535. {1,1},
  536. {-4,3},
  537. {10,11},
  538. {12,11},
  539. {-16,9},
  540. {40,33},
  541. {16,11},
  542. };
  543. static NOINLINE void ToAspect(int i,fraction* f)
  544. {
  545. *f = AspectTab[i];
  546. }
  547. static NOINLINE int FromAspect(const fraction* f)
  548. {
  549. int i;
  550. if (f->Num)
  551. for (i=1;i<8;++i)
  552. if (EqFrac(f,AspectTab+i))
  553. return i;
  554. return 0;
  555. }
  556. static NOINLINE int TickConvert(tick_t t,int n)
  557. {
  558. int Adjust = TICKSPERSEC/(n*2);
  559. if (t<0)
  560. t -= Adjust;
  561. else
  562. t += Adjust;
  563. return Scale(t,n,TICKSPERSEC);
  564. }
  565. static NOINLINE void SetValue(FormType* Form,int Id,int Value)
  566. {
  567. CtlSetValue(FrmGetObjectPtr(Form,FrmGetObjectIndex(Form,(UInt16)Id)),(Int16)Value);
  568. }
  569. static NOINLINE int GetValue(FormType* Form,int Id)
  570. {
  571. return CtlGetValue(FrmGetObjectPtr(Form,FrmGetObjectIndex(Form,(UInt16)Id)));
  572. }
  573. static void PrefInit(FormType* Form) {
  574. UInt16 Idx;
  575. ListType* ListControl;
  576. array List; bool_t b;
  577. RectangleType ListRect,ItemRect; fraction f;
  578. const tchar_t *s;
  579. int *q; int i,j;
  580. tick_t t;
  581. node* Color = NodeEnumObject(NULL,COLOR_ID); SetValue(Form,PrefCurrPage,1); PrefPage(Form,PrefCurrPage);
  582. Player->Get(Player,PLAYER_PLAY_SPEED,&f,sizeof(f)); SetFieldInt(Form,PrefGeneralSpeedValue,Scale(f.Num,100,f.Den),0);
  583. SetValue(Form,PrefGeneralSpeedOrig,f.Den == f.Num); SetValue(Form,PrefGeneralSpeedCustom,f.Den != f.Num); SetValue(Form,PrefGeneralSpeed,(f.Num>f.Den?Scale(512,f.Num,f.Den)-512:Scale(600,f.Num,f.Den)-600)+512); Player->Get(Player,PLAYER_REPEAT,&b,sizeof(b)); SetValue(Form,PrefGeneralRepeat,b); Player->Get(Player,PLAYER_SHUFFLE,&b,sizeof(b)); SetValue(Form,PrefGeneralShuffle,b);
  584. Context()->Advanced->Get(Context()->Advanced,ADVANCED_AVOFFSET,&t,sizeof(t));
  585. SetFieldInt(Form,PrefGeneralAVOffset,TickConvert(t,1000),0);
  586. Player->Get(Player,PLAYER_MOVEBACK_STEP,&t,sizeof(t));
  587. SetFieldInt(Form,PrefGeneralMoveBack,TickConvert(t,1),0);
  588. Player->Get(Player,PLAYER_MOVEFFWD_STEP,&t,sizeof(t));
  589. SetFieldInt(Form,PrefGeneralMoveFFwd,TickConvert(t,1),0);
  590. Player->Get(Player,PLAYER_VOLUME,&i,sizeof(i)); SetValue(Form,PrefAudioVolume,i);
  591. SetFieldInt(Form,PrefAudioVolumeValue,i,0);
  592. Player->Get(Player,PLAYER_PAN,&i,sizeof(i));   SetFieldInt(Form,PrefAudioPanValue,i,0); i>>=1;
  593. SetValue(Form,PrefAudioPan,i+50);  Player->Get(Player,PLAYER_PREAMP,&i,sizeof(i));  SetFieldInt(Form,PrefAudioPreampValue,i,0); i>>=1;
  594. SetValue(Form,PrefAudioPreamp,i+50);  Player->Get(Player,PLAYER_AOUTPUTID,&i,sizeof(i)); SetValue(Form,PrefAudioDisable,i==0);
  595. Player->Get(Player,PLAYER_STEREO,&i,sizeof(i));
  596. SetList(Form,PrefAudioStereo,PrefAudioStereoList,i,0);
  597. Color->Get(Color,COLOR_BRIGHTNESS,&i,sizeof(i)); i>>=1; SetValue(Form,PrefVideoBrightness,i+64); SetFieldInt(Form,PrefVideoBrightnessValue,i,0);
  598. Color->Get(Color,COLOR_CONTRAST,&i,sizeof(i)); i>>=1; SetValue(Form,PrefVideoContrast,i+64); SetFieldInt(Form,PrefVideoContrastValue,i,0);
  599. Color->Get(Color,COLOR_SATURATION,&i,sizeof(i)); i>>=1; SetValue(Form,PrefVideoSaturation,i+64); SetFieldInt(Form,PrefVideoSaturationValue,i,0);
  600. Color->Get(Color,COLOR_R_ADJUST,&i,sizeof(i)); i>>=1; SetValue(Form,PrefVideoRed,i+32); SetFieldInt(Form,PrefVideoRedValue,i,0);
  601. Color->Get(Color,COLOR_G_ADJUST,&i,sizeof(i)); i>>=1; SetValue(Form,PrefVideoGreen,i+32); SetFieldInt(Form,PrefVideoGreenValue,i,0);
  602. Color->Get(Color,COLOR_B_ADJUST,&i,sizeof(i)); i>>=1; SetValue(Form,PrefVideoBlue,i+32); SetFieldInt(Form,PrefVideoBlueValue,i,0);
  603. Color->Get(Color,COLOR_DITHER,&b,sizeof(b)); SetValue(Form,PrefVideoDither,b);
  604. Player->Get(Player,PLAYER_VIDEO_QUALITY,&i,sizeof(i));
  605. SetList(Form,PrefVideoQuality,PrefVideoQualityList,i,0);
  606. ArrayClear(&VideoDriver);
  607. ArrayClear(&VideoDriverNames);
  608. NodeEnumClass(&List,VOUT_CLASS);
  609. j = 0;
  610. Player->Get(Player,PLAYER_VOUTPUTID,&i,sizeof(i));
  611. Player->Get(Player,PLAYER_VIDEO_ACCEL,&b,sizeof(b));
  612. for (q=ARRAYBEGIN(List,int);q!=ARRAYEND(List,int);++q)
  613. {
  614. if (VOutIDCT(*q))
  615. {
  616. if (i==*q && b)
  617. j = ARRAYCOUNT(VideoDriverNames,tchar_t*);
  618. s = LangStr(VOUT_IDCT_CLASS(*q),NODE_NAME);
  619. ArrayAppend(&VideoDriver,q,sizeof(int),32);
  620. ArrayAppend(&VideoDriverNames,&s,sizeof(tchar_t*),32);
  621. }
  622. if (i==*q && !b)
  623. j = ARRAYCOUNT(VideoDriverNames,tchar_t*);
  624. s = LangStr(*q,NODE_NAME);
  625. ArrayAppend(&VideoDriver,q,sizeof(int),32);
  626. ArrayAppend(&VideoDriverNames,&s,sizeof(tchar_t*),32);
  627. }
  628. ArrayClear(&List);
  629. if (i==0)
  630. j = ARRAYCOUNT(VideoDriverNames,tchar_t*);
  631. s = T("Disabled video");
  632. ArrayAppend(&VideoDriver,q,sizeof(int),32);
  633. ArrayAppend(&VideoDriverNames,&s,sizeof(tchar_t*),32);
  634. Idx = FrmGetObjectIndex(Form,PrefVideoDriverList);
  635. ListControl = (ListType*)FrmGetObjectPtr(Form,Idx);
  636. LstSetListChoices(ListControl,
  637. ARRAYBEGIN(VideoDriverNames,tchar_t*),(UInt16)ARRAYCOUNT(VideoDriverNames,tchar_t*));
  638. LstSetHeight(ListControl,(UInt16)(min(6,ARRAYCOUNT(VideoDriverNames,tchar_t*))));
  639. GetObjectBounds(Form,Idx,&ListRect);
  640. GetObjectBounds(Form,FrmGetObjectIndex(Form,PrefVideoDriver),&ItemRect);
  641. ListRect.topLeft.y = (Coord)(ItemRect.topLeft.y + ItemRect.extent.y - ListRect.extent.y);
  642. SetObjectBounds(Form,Idx,&ListRect);
  643. SetList(Form,PrefVideoDriver,PrefVideoDriverList,j,0);
  644. Player->Get(Player,PLAYER_ASPECT,&f,sizeof(f));
  645. SetList(Form,PrefVideoAspect,PrefVideoAspectList,FromAspect(&f),0);
  646. Player->Get(Player,PLAYER_SKIN_ZOOM,&f,sizeof(f)); SetList(Form,PrefVideoSkinZoom,PrefVideoSkinZoomList,FromZoom(&f),0); Player->Get(Player,PLAYER_FULL_ZOOM,&f,sizeof(f)); SetList(Form,PrefVideoFullZoom,PrefVideoFullZoomList,FromZoom(&f),0); Player->Get(Player,PLAYER_SKIN_DIR,&i,sizeof(i)); SetList(Form,PrefVideoSkinRotate,PrefVideoSkinRotateList,FromDir(i),0); Player->Get(Player,PLAYER_FULL_DIR,&i,sizeof(i)); SetList(Form,PrefVideoFullRotate,PrefVideoFullRotateList,FromDir(i),0); }
  647. static Boolean MediaInfoHandler( EventPtr Event )
  648. {
  649. return DummyHandler(FrmGetFormPtr(MediaInfoForm),Event);
  650. }
  651. static Boolean BenchmarkHandler( EventPtr Event )
  652. {
  653. return DummyHandler(FrmGetFormPtr(BenchmarkForm),Event);
  654. }
  655. static Boolean AboutHandler( EventPtr Event )
  656. {
  657. return DummyHandler(FrmGetFormPtr(AboutForm),Event);
  658. }
  659. static bool_t Tweak(int Class,int No,bool_t* State,bool_t Set)
  660. {
  661. node* p = NodeEnumObject(NULL,Class);
  662. if (p)
  663. {
  664. bool_t v;
  665. datadef Def;
  666. if (!NodeDataDef(p,No,&Def) || (Def.Flags & DF_HIDDEN))
  667. return 0;
  668. if (p->Get(p,No,&v,sizeof(bool_t))==ERR_NONE)
  669. {
  670. if (!Set)
  671. *State = v;
  672. else
  673. p->Set(p,No,State,sizeof(bool_t));
  674. return 1;
  675. }
  676. }
  677. return 0;
  678. }
  679. static Boolean TweakHandler( EventPtr Event )
  680. {
  681. FormType* Form = FrmGetFormPtr(TweakForm);
  682. if (Event->eType == ctlSelectEvent && Event->data.ctlSelect.controlID == DummyOk)
  683. {
  684. bool_t Memory = GetValue(Form,TweakMemory);
  685. bool_t Borderless = GetValue(Form,TweakBorderless);
  686. bool_t TrippleBuffer = GetValue(Form,TweakTrippleBuffer);
  687. bool_t Battery = GetValue(Form,TweakBattery);
  688. FrmReturnToForm(MainForm);
  689. Tweak(ADVANCED_ID,ADVANCED_MEMORYOVERRIDE,&Memory,1);
  690. Tweak(HIRES_ID,HIRES_USEBORDER,&Borderless,1);
  691. Tweak(HIRES_ID,HIRES_TRIPLEBUFFER,&TrippleBuffer,1);
  692. EvtOverride((Boolean)Battery);
  693. return 1;
  694. }
  695. return DummyHandler(Form,Event);
  696. }
  697. static void EqInit(FormType* Form,bool_t Draw);
  698. static Boolean EqHandler( EventPtr Event )
  699. {
  700. bool_t b;
  701. int n,i;
  702. node* Eq = NodeEnumObject(NULL,EQUALIZER_ID);
  703. FormType* Form = FrmGetFormPtr(EqForm);
  704. if (Event->eType == ctlSelectEvent && Event->data.ctlSelect.controlID == EqReset)
  705. {
  706. i=0;
  707. for (n=0;n<10;++n)
  708. Eq->Set(Eq,EQUALIZER_1+n,&i,sizeof(i));
  709. Eq->Set(Eq,EQUALIZER_PREAMP,&i,sizeof(i));
  710. EqInit(Form,1);
  711. }
  712. if (Event->eType == ctlSelectEvent)
  713. {
  714. switch (Event->data.ctlSelect.controlID)
  715. {
  716. case EqEnable:
  717. b = GetValue(Form,EqEnable);
  718. Eq->Set(Eq,EQUALIZER_ENABLED,&b,sizeof(b));
  719. break;
  720. case EqAttenuate:
  721. b = GetValue(Form,EqAttenuate);
  722. Eq->Set(Eq,EQUALIZER_ATTENUATE,&b,sizeof(b));
  723. break;
  724. }
  725. }
  726. if (Event->eType == ctlRepeatEvent)
  727. {
  728. int n = Event->data.ctlRepeat.controlID;
  729. switch (n)
  730. {
  731. case EqPreamp:
  732. i = (Int16)Event->data.ctlRepeat.value-20;
  733. SetFieldInt(Form,EqPreampValue,i,1);
  734. Eq->Set(Eq,EQUALIZER_PREAMP,&i,sizeof(i));
  735. break;
  736. case Eq1:
  737. case Eq2:
  738. case Eq3:
  739. case Eq4:
  740. case Eq5:
  741. case Eq6:
  742. case Eq7:
  743. case Eq8:
  744. case Eq9:
  745. case Eq10:
  746. i = (Int16)Event->data.ctlRepeat.value-20;
  747. SetFieldInt(Form,(UInt16)(Eq1Value+(n-Eq1)),i,1);
  748. Eq->Set(Eq,EQUALIZER_1+(n-Eq1),&i,sizeof(i));
  749. break;
  750. }
  751. }
  752. return DummyHandler(Form,Event);
  753. }
  754. static Boolean AdvHandler( EventPtr Event )
  755. {
  756. FormType* Form = FrmGetFormPtr(AdvForm);
  757. if (Event->eType == ctlSelectEvent && Event->data.ctlSelect.controlID == DummyOk)
  758. {
  759. bool_t b,b2;
  760. node* Advanced = Context()->Advanced;
  761. b = GetValue(Form,AdvNoBatteryWarning);
  762. Advanced->Set(Advanced,ADVANCED_NOBATTERYWARNING,&b,sizeof(b));
  763. b = GetValue(Form,AdvNoEventChecking);
  764. Advanced->Set(Advanced,ADVANCED_NOEVENTCHECKING,&b,sizeof(b));
  765. NoEventChecking = b;
  766. b = GetValue(Form,AdvCardPlugins);
  767. Advanced->Get(Advanced,ADVANCED_CARDPLUGINS,&b2,sizeof(b2));
  768. if (b != b2)
  769. {
  770. Advanced->Set(Advanced,ADVANCED_CARDPLUGINS,&b,sizeof(b));
  771. ShowMessage(NULL,LangStr(SETTINGS_ID,SETTINGS_RESTART));
  772. }
  773. b = GetValue(Form,AdvKeyFollowDir);
  774. Advanced->Set(Advanced,ADVANCED_KEYFOLLOWDIR,&b,sizeof(b));
  775. b = GetValue(Form,AdvAVIFrameRate);
  776. Advanced->Set(Advanced,ADVANCED_AVIFRAMERATE,&b,sizeof(b));
  777. b = GetValue(Form,AdvBenchFromPos);
  778. Advanced->Set(Advanced,ADVANCED_BENCHFROMPOS,&b,sizeof(b));
  779. b = GetValue(Form,AdvNoDeblocking);
  780. Advanced->Set(Advanced,ADVANCED_NODEBLOCKING,&b,sizeof(b));
  781. b = GetValue(Form,AdvBlinkLED);
  782. Advanced->Set(Advanced,ADVANCED_BLINKLED,&b,sizeof(b));
  783. b = GetValue(Form,AdvSmoothZoom);
  784. Player->Set(Player,PLAYER_SMOOTHALWAYS,&b,sizeof(b));
  785. b = GetValue(Form,AdvPreRotate);
  786. Player->Set(Player,PLAYER_AUTOPREROTATE,&b,sizeof(b));
  787. FrmReturnToForm(MainForm);
  788. return 1;
  789. }
  790. return DummyHandler(Form,Event);
  791. }
  792. static Boolean PrefHandler( EventPtr Event ) { FormType* Form = FrmGetFormPtr(PrefForm);
  793. node* Color;
  794. fraction f; bool_t b;
  795. tick_t t; int i;
  796. if (DummyHandler(Form,Event)) return 1; if (Event->eType == ctlRepeatEvent) {
  797. Color = NodeEnumObject(NULL,COLOR_ID);
  798. switch (Event->data.ctlRepeat.controlID) { case PrefVideoBrightness: i = (Int16)Event->data.ctlRepeat.value-64; SetFieldInt(Form,PrefVideoBrightnessValue,i,1); i*=2;
  799. Color->Set(Color,COLOR_BRIGHTNESS,&i,sizeof(i));
  800. break; case PrefVideoContrast: i = (Int16)Event->data.ctlRepeat.value-64; SetFieldInt(Form,PrefVideoContrastValue,i,1); i*=2;
  801. Color->Set(Color,COLOR_CONTRAST,&i,sizeof(i)); break; case PrefVideoSaturation: i = (Int16)Event->data.ctlRepeat.value-64; SetFieldInt(Form,PrefVideoSaturationValue,i,1); i*=2;
  802. Color->Set(Color,COLOR_SATURATION,&i,sizeof(i)); break; case PrefVideoRed: i = (Int16)Event->data.ctlRepeat.value-32; SetFieldInt(Form,PrefVideoRedValue,i,1); i*=2;
  803. Color->Set(Color,COLOR_R_ADJUST,&i,sizeof(i)); break; case PrefVideoGreen: i = (Int16)Event->data.ctlRepeat.value-32; SetFieldInt(Form,PrefVideoGreenValue,i,1); i*=2;
  804. Color->Set(Color,COLOR_G_ADJUST,&i,sizeof(i)); break; case PrefVideoBlue: i = (Int16)Event->data.ctlRepeat.value-32; SetFieldInt(Form,PrefVideoBlueValue,i,1); i*=2;
  805. Color->Set(Color,COLOR_B_ADJUST,&i,sizeof(i)); break; case PrefAudioVolume: i = (Int16)Event->data.ctlRepeat.value; Player->Set(Player,PLAYER_VOLUME,&i,sizeof(i)); SetFieldInt(Form,PrefAudioVolumeValue,i,1);
  806. break; case PrefAudioPan: i = (Int16)Event->data.ctlRepeat.value; i-=50; i*=2; Player->Set(Player,PLAYER_PAN,&i,sizeof(i)); SetFieldInt(Form,PrefAudioPanValue,i,1);
  807. break; case PrefAudioPreamp: i = (Int16)Event->data.ctlRepeat.value; i-=50; i*=2; Player->Set(Player,PLAYER_PREAMP,&i,sizeof(i)); SetFieldInt(Form,PrefAudioPreampValue,i,1);
  808. break; case PrefGeneralSpeed:
  809. f.Num = (Int16)Event->data.ctlRepeat.value - 512;
  810. if (f.Num<0)
  811. {
  812. f.Num += 600; f.Den = 600;
  813. }
  814. else
  815. {
  816. f.Num += 512;
  817. f.Den = 512;
  818. } Player->Set(Player,PLAYER_PLAY_SPEED,&f,sizeof(f)); SetValue(Form,PrefGeneralSpeedCustom,1); SetValue(Form,PrefGeneralSpeedOrig,0); SetFieldInt(Form,PrefGeneralSpeedValue,Scale(f.Num,100,f.Den),1);
  819. break; } }
  820. if (Event->eType == popSelectEvent) { switch (Event->data.popSelect.listID) { case PrefAudioStereoList:
  821. i = Event->data.popSelect.selection;
  822. Player->Set(Player,PLAYER_STEREO,&i,sizeof(i));
  823. SetList(Form,PrefAudioStereo,PrefAudioStereoList,Event->data.popSelect.selection,1);
  824. break;
  825. case PrefVideoQualityList:
  826. i = Event->data.popSelect.selection;
  827. Player->Set(Player,PLAYER_VIDEO_QUALITY,&i,sizeof(i));
  828. SetList(Form,PrefVideoQuality,PrefVideoQualityList,Event->data.popSelect.selection,1);
  829. break;
  830. case PrefVideoFullRotateList: i = ToDir(Event->data.popSelect.selection); Player->Set(Player,PLAYER_FULL_DIR,&i,sizeof(i)); SetList(Form,PrefVideoFullRotate,PrefVideoFullRotateList,Event->data.popSelect.selection,1);
  831. break; case PrefVideoSkinRotateList: i = ToDir(Event->data.popSelect.selection); Player->Set(Player,PLAYER_SKIN_DIR,&i,sizeof(i)); SetList(Form,PrefVideoSkinRotate,PrefVideoSkinRotateList,Event->data.popSelect.selection,1);
  832. break; case PrefVideoSkinZoomList: ToZoom(Event->data.popSelect.selection,&f); Player->Set(Player,PLAYER_SKIN_ZOOM,&f,sizeof(f)); SetList(Form,PrefVideoSkinZoom,PrefVideoSkinZoomList,Event->data.popSelect.selection,1);
  833. break; case PrefVideoFullZoomList: ToZoom(Event->data.popSelect.selection,&f); Player->Set(Player,PLAYER_FULL_ZOOM,&f,sizeof(f)); SetList(Form,PrefVideoFullZoom,PrefVideoFullZoomList,Event->data.popSelect.selection,1);
  834. break;
  835. case PrefVideoAspectList:
  836. ToAspect(Event->data.popSelect.selection,&f);
  837. Player->Set(Player,PLAYER_ASPECT,&f,sizeof(f));
  838. SetList(Form,PrefVideoAspect,PrefVideoAspectList,Event->data.popSelect.selection,1);
  839. break;
  840. case PrefVideoDriverList:
  841. i = Event->data.popSelect.selection;
  842. b = 0;
  843. if (i<0 || i>=ARRAYCOUNT(VideoDriver,int)-1)
  844. i = 0;
  845. else
  846. {
  847. b = ARRAYBEGIN(VideoDriver,int)[i+1] == ARRAYBEGIN(VideoDriver,int)[i];
  848. i = ARRAYBEGIN(VideoDriver,int)[i];
  849. }
  850. Player->Set(Player,PLAYER_VIDEO_ACCEL,&b,sizeof(b));
  851. Player->Set(Player,PLAYER_VOUTPUTID,&i,sizeof(i));
  852. UpdateVideoCaps(Form);
  853. SetList(Form,PrefVideoDriver,PrefVideoDriverList,Event->data.popSelect.selection,1);
  854. break;
  855. } }
  856. if (Event->eType == frmCloseEvent)
  857. {
  858. ArrayClear(&VideoDriver);
  859. ArrayClear(&VideoDriverNames);
  860. }
  861. if (Event->eType == ctlSelectEvent) { switch (Event->data.ctlSelect.controlID) { case PrefGeneral: case PrefAudio: case PrefVideo:
  862. if (PrefCurrPage != Event->data.ctlSelect.controlID) PrefPage(Form,Event->data.ctlSelect.controlID); return 1; case PrefClose:
  863. if (GetFieldInt(Form,PrefGeneralMoveBack,&i))
  864. {
  865. t = i*TICKSPERSEC;
  866. Player->Set(Player,PLAYER_MOVEBACK_STEP,&t,sizeof(t));
  867. }
  868. if (GetFieldInt(Form,PrefGeneralMoveFFwd,&i))
  869. {
  870. t = i*TICKSPERSEC;
  871. Player->Set(Player,PLAYER_MOVEFFWD_STEP,&t,sizeof(t));
  872. }
  873. if (GetFieldInt(Form,PrefGeneralAVOffset,&i))
  874. {
  875. t = Scale(i,TICKSPERSEC,1000);
  876. Context()->Advanced->Set(Context()->Advanced,ADVANCED_AVOFFSET,&t,sizeof(t));
  877. }
  878. ArrayClear(&VideoDriver);
  879. ArrayClear(&VideoDriverNames);
  880. FrmReturnToForm(MainForm);
  881. return 1;
  882. case PrefVideoDither:
  883. Color = NodeEnumObject(NULL,COLOR_ID);
  884. b = CtlGetValue(Event->data.ctlSelect.pControl) != 0; Color->Set(Color,COLOR_DITHER,&b,sizeof(b)); return 1; case PrefAudioDisable:
  885. b = CtlGetValue(Event->data.ctlSelect.pControl) != 0; if (b) i=0; else i=NodeEnumClass(NULL,AOUT_CLASS); Player->Set(Player,PLAYER_AOUTPUTID,&i,sizeof(i)); return 1; case PrefGeneralSpeedOrig: f.Num = 1; f.Den = 1; Player->Set(Player,PLAYER_PLAY_SPEED,&f,sizeof(f)); SetValue(Form,PrefGeneralSpeed,512); SetFieldInt(Form,PrefGeneralSpeedValue,Scale(f.Num,100,f.Den),1);
  886. return 1;
  887. case PrefGeneralRepeat: b = CtlGetValue(Event->data.ctlSelect.pControl) != 0; Player->Set(Player,PLAYER_REPEAT,&b,sizeof(b)); return 1; case PrefGeneralShuffle: b = CtlGetValue(Event->data.ctlSelect.pControl) != 0; Player->Set(Player,PLAYER_SHUFFLE,&b,sizeof(b)); return 1;
  888. case PrefAudioPreampReset:
  889. i = 0;
  890. Player->Set(Player,PLAYER_PREAMP,&i,sizeof(i));
  891. SetFieldInt(Form,PrefAudioPreampValue,i,1); i>>=1;
  892. SetValue(Form,PrefAudioPreamp,i+50); 
  893. return 1;
  894. case PrefAudioPanReset:
  895. i = 0;
  896. Player->Set(Player,PLAYER_PAN,&i,sizeof(i));
  897. SetFieldInt(Form,PrefAudioPanValue,i,1); i>>=1;
  898. SetValue(Form,PrefAudioPan,i+50); 
  899. return 1; } } return 0; } typedef struct openitem { bool_t Checked; bool_t Selected; int Image; tchar_t FileName[MAXPATH]; tchar_t Name[64]; } openitem; typedef struct openfile { array List; int Count; int First;
  900. int FirstMax; int PageSize; int ItemHeight; int Mouse; bool_t MouseDir; FormType* Form; tchar_t Path[MAXPATH]; tchar_t Last[MAXPATH]; tchar_t Exts[1024]; MemPtr Checked[2]; MemPtr Image[2]; } openfile; static openfile* OpenFile = NULL; static void OpenClear(openfile* p) { ArrayDrop(&p->List); p->Count = 0; p->First = 0; } static void OpenDraw(openfile* p,int Pos) { int n; RectangleType Rect; RectangleType OldClip; WinGetClip( &OldClip ); WinPushDrawState(); GetObjectBounds(p->Form,FrmGetObjectIndex(p->Form,OpenList),&Rect); Rect.extent.y = (Coord)p->ItemHeight; for (n=0;n<p->PageSize;++n) { if (Pos<0 || n+p->First==Pos) { UIColorTableEntries c; openitem* i = NULL; if (n+p->First < p->Count) i = ARRAYBEGIN(p->List,openitem)+n+p->First; WinSetClip(&Rect); if (i && i->Selected) c = UIMenuSelectedFill; else if (i && i->Checked) c = UIFieldTextHighlightBackground; else c = UIFormFill; WinSetBackColor(UIColorGetTableEntryIndex(c)); WinEraseRectangle(&Rect,0); if (i) { if (i->Selected) c = UIMenuSelectedForeground; else if (i->Checked) c = UIFieldTextHighlightForeground; else c = UIFieldText; WinSetTextColor(UIColorGetTableEntryIndex(c)); WinSetForeColor(UIColorGetTableEntryIndex(c)); WinDrawChars(i->Name,(Int16)tcslen(i->Name),(Coord)(Rect.topLeft.x+24),Rect.topLeft.y); if (i->Image != OpenImageUp) { BitmapType* Bitmap = p->Checked[i->Checked]; if (Bitmap)      WinDrawBitmap(Bitmap, Rect.topLeft.x, Rect.topLeft.y); } if (i->Image == OpenImageDir || i->Image == OpenImageUp) { BitmapType* Bitmap = NULL; switch (i->Image) { case OpenImageDir: Bitmap = p->Image[0]; break; case OpenImageUp: Bitmap = p->Image[1]; break; }      if (Bitmap) WinDrawBitmap(Bitmap, (Coord)(Rect.topLeft.x+12), (Coord)(Rect.topLeft.y)); } } } Rect.topLeft.y = (Coord)(Rect.topLeft.y+p->ItemHeight); } WinPopDrawState(); WinSetClip( &OldClip ); } static Boolean OpenListHandler(struct FormGadgetTypeInCallback *gadgetP, UInt16 cmd, void *paramP) { if (cmd == formGadgetDrawCmd && OpenFile) { OpenDraw(OpenFile,-1); return 1; } return 0; } static Boolean OpenLineHandler(struct FormGadgetTypeInCallback *gadgetP, UInt16 cmd, void *paramP) { if (cmd == formGadgetDrawCmd && OpenFile) { RectangleType Rect; GetObjectBounds(OpenFile->Form,FrmGetObjectIndex(OpenFile->Form,OpenLine),&Rect); WinDrawRectangle(&Rect,0); return 1; } return 0; } static void OpenPost(int Cmd) { EventType e; memset(&e,0,sizeof(e)); e.eType = ctlSelectEvent; e.data.ctlSelect.controlID = (UInt16)Cmd; _EvtAddUniqueEventToQueue(&e, 0, 1); } static bool_t OpenIsSelected(openfile* p) { openitem* i; for (i=ARRAYBEGIN(p->List,openitem);i!=ARRAYEND(p->List,openitem);++i) if (i->Checked) return 1; return 0; } static void OpenPageSize(openfile* p) { RectangleType Bounds; GetObjectBounds(p->Form,FrmGetObjectIndex(p->Form,OpenList),&Bounds); p->PageSize = Bounds.extent.y / p->ItemHeight; } static void OpenAdd(openfile* p) { if (Player && OpenIsSelected(p)) { bool_t b; int n; openitem* i; b = 0; Player->Set(Player,PLAYER_PLAY,&b,sizeof(b)); n = 0; Player->Set(Player,PLAYER_LIST_COUNT,&n,sizeof(n)); for (i=ARRAYBEGIN(p->List,openitem);i!=ARRAYEND(p->List,openitem);++i) if (i->Checked) { tchar_t URL[MAXPATH]; if (i->FileName[0]) AbsPath(URL,TSIZEOF(URL),i->FileName,p->Path); else tcscpy_s(URL,TSIZEOF(URL),p->Path); if (i->Image == OpenImageDir) n = PlayerAddDir(Player,n,URL,p->Exts,1,0); else n = PlayerAdd(Player,n,URL,NULL); } n=0; Player->Set(Player,PLAYER_LIST_CURRIDX,&n,sizeof(n)); } } static void OpenUpdate(openfile* p,bool_t Silent,int ListMode); static void OpenSetScroll(openfile* p);
  901. static void OpenInit(FormType* Form) { openfile* p = OpenFile = malloc(sizeof(openfile)); if (p) { bool_t HasHost; memset(p,0,sizeof(openfile)); p->Form = Form; p->ItemHeight = 11; p->Mouse = -1; p->Checked[0] = MemHandleLock(DmGetResource(bitmapRsc,OpenImageUnchecked)); p->Checked[1] = MemHandleLock(DmGetResource(bitmapRsc,OpenImageChecked)); p->Image[0] = MemHandleLock(DmGetResource(bitmapRsc,OpenImageDir)); p->Image[1] = MemHandleLock(DmGetResource(bitmapRsc,OpenImageUp)); Player->Get(Player,PLAYER_CURRENTDIR,p->Path,sizeof(p->Path)); GenExts(p->Exts,TSIZEOF(p->Exts)); GetMime(p->Path,NULL,0,&HasHost); OpenPageSize(p); OpenUpdate(p,1,HasHost?0:2);
  902. FrmSetGadgetHandler(Form, FrmGetObjectIndex(Form, OpenList),OpenListHandler); FrmSetGadgetHandler(Form, FrmGetObjectIndex(Form, OpenLine),OpenLineHandler);
  903. //FrmGlueNavObjectTakeFocus(Form, OpenOk); //crashes in longterm at program exit! } } static void OpenDone(openfile* p) { int i; for (i=0;i<2;++i) if (p->Checked[i])  MemPtrUnlock(p->Checked[i]); for (i=0;i<2;++i) if (p->Image[i])  MemPtrUnlock(p->Image[i]); Player->Set(Player,PLAYER_CURRENTDIR,p->Path,sizeof(p->Path)); ArrayClear(&p->List); } static void OpenResize(Coord Width,Coord Height) { openfile* p = OpenFile; if (p) { ObjectPosition(p->Form,OpenURL,2,158,16,-1,Width,Height); ObjectPosition(p->Form,OpenLine,0,152,28,-1,Width,Height); ObjectPosition(p->Form,OpenList,0,152,30,140,Width,Height); ObjectPosition(p->Form,OpenScroll,-1,159,30,140,Width,Height); ObjectPosition(p->Form,OpenOk,2,-1,-1,143+15,Width,Height); ObjectPosition(p->Form,OpenAll,42,-1,-1,143+15,Width,Height); ObjectPosition(p->Form,OpenNone,82,-1,-1,143+15,Width,Height); ObjectPosition(p->Form,OpenCancel,122,-1,-1,143+15,Width,Height);
  904. OpenPageSize(p); OpenSetScroll(p);
  905. } } static int OpenFindPos(openfile* p,int x,int y,bool_t* Dir) { openitem* Item; int n; RectangleType Rect; GetObjectBounds(p->Form,FrmGetObjectIndex(p->Form,OpenList),&Rect); x -= Rect.topLeft.x; y -= Rect.topLeft.y; if (x<0 || x>=Rect.extent.x || y<0 || y>=p->PageSize*p->ItemHeight) return -1; n = y/p->ItemHeight; n += p->First; if (n>=p->Count) return -1; Item = ARRAYBEGIN(p->List,openitem)+n; if (Dir) { if (Item->Image == OpenImageUp) *Dir = 1; else *Dir = Item->Image == OpenImageDir && (Rect.topLeft.x + 14 < x); } return n; } static Boolean OpenHandler( EventPtr Event ) { FormType* Form = FrmGetFormPtr(OpenForm);
  906. openfile* p = OpenFile; openitem* i; openitem* Item; bool_t Selected;
  907. if (DummyHandler(Form,Event)) return 1; if (!p && Event->eType == ctlSelectEvent) { FrmReturnToForm(MainForm); } if (p) switch (Event->eType) {
  908. case keyUpEvent:
  909. case keyDownEvent:
  910. if (KeyUp(Event)>0)
  911. {
  912. p->First -= p->PageSize-1;
  913. OpenSetScroll(p);
  914. OpenDraw(p,-1);
  915. return 1;
  916. }
  917. if (KeyDown(Event)>0)
  918. {
  919. p->First += p->PageSize-1;
  920. OpenSetScroll(p);
  921. OpenDraw(p,-1);
  922. return 1;
  923. }
  924. break;
  925. case penUpEvent: if (p->Mouse>=0) { Item = ARRAYBEGIN(p->List,openitem)+p->Mouse; Selected = OpenFindPos(p,Event->screenX,Event->screenY,NULL) == p->Mouse; if (Selected != Item->Selected && !p->MouseDir) Item->Checked = !Item->Checked; Item->Selected = 0; OpenDraw(p,p->Mouse); p->Mouse = -1; if (Selected) SndPlaySystemSound(sndClick); if (Selected && p->MouseDir) { if (Item->Image == OpenImageUp) { if (UpperPath(p->Path,p->Last,TSIZEOF(p->Last)))  OpenUpdate(p,1,1); } else { tchar_t Path[MAXPATH]; AbsPath(Path,TSIZEOF(Path),Item->FileName,p->Path); tcscpy_s(p->Path,TSIZEOF(p->Path),Path); p->Last[0] = 0; OpenUpdate(p,1,1); } } return 1; } break; case penMoveEvent: if (p->Mouse>=0) { Item = ARRAYBEGIN(p->List,openitem)+p->Mouse; Selected = OpenFindPos(p,Event->screenX,Event->screenY,NULL) == p->Mouse; if (Selected != Item->Selected) { if (!p->MouseDir) Item->Checked = !Item->Checked; Item->Selected = Selected; OpenDraw(p,p->Mouse); } } break; case penDownEvent: p->Mouse = OpenFindPos(p,Event->screenX,Event->screenY,&p->MouseDir); if (p->Mouse>=0) { Item = ARRAYBEGIN(p->List,openitem)+p->Mouse; Item->Selected = 1; if (!p->MouseDir) Item->Checked = !Item->Checked; OpenDraw(p,p->Mouse); return 1; } break; case sclRepeatEvent: p->First = Event->data.sclRepeat.newValue; OpenDraw(p,-1); break; case ctlSelectEvent: if (Event->data.ctlSelect.controlID == OpenAll) { bool_t All = 1; for (i=ARRAYBEGIN(p->List,openitem);i!=ARRAYEND(p->List,openitem);++i) if (!i->Checked && i->Image != OpenImageUp && i->Image != OpenImageDir) { All = 0; break; } for (i=ARRAYBEGIN(p->List,openitem);i!=ARRAYEND(p->List,openitem);++i) if (i->Image != OpenImageUp && (i->Image != OpenImageDir || All)) i->Checked = 1; OpenDraw(p,-1); } if (Event->data.ctlSelect.controlID == OpenNone) { for (i=ARRAYBEGIN(p->List,openitem);i!=ARRAYEND(p->List,openitem);++i) i->Checked = 0; OpenDraw(p,-1); } if (Event->data.ctlSelect.controlID == OpenOk ||  Event->data.ctlSelect.controlID == OpenCancel) { if (Event->data.ctlSelect.controlID == OpenOk) OpenAdd(p); OpenDone(p); free(p); OpenFile = NULL; FrmReturnToForm(MainForm); return 1; } break; default: break; } return 0; } static int OpenCmp(const void* pa,const void* pb) { const openitem* a = (const openitem*)pa; const openitem* b = (const openitem*)pb; int Result; if (a->Image==OpenImageUp) return -1; if (b->Image==OpenImageUp) return 1; if (a->Image==OpenImageDir) if (b->Image==OpenImageDir) Result = tcsicmp(a->Name,b->Name); else Result = -1; else if (b->Image==OpenImageDir) Result = 1; else Result = tcsicmp(a->Name,b->Name);  return Result; } static void OpenSetScroll(openfile* p) { if (p->Count > p->PageSize) p->FirstMax = p->Count - p->PageSize; else p->FirstMax = 0;
  926. if (p->First < 0)
  927. p->First = 0;
  928. if (p->First > p->FirstMax)
  929. p->First = p->FirstMax; SclSetScrollBar(FrmGetObjectPtr(p->Form,FrmGetObjectIndex(p->Form,OpenScroll)), (Int16)p->First,0,(Int16)p->FirstMax,(Int16)(p->PageSize-1)); } static void OpenUpdate(openfile* p,bool_t Silent,int ListMode) { streamdir DirItem; stream* Stream; openitem New; int Result;
  930. bool_t Draw = FrmVisible(p->Form); FieldType* Field = (FieldType*)FrmGetObjectPtr(p->Form,FrmGetObjectIndex(p->Form,OpenURL)); FldSetTextPtr(Field,p->Path[0] ? p->Path : T("/"));
  931. OpenClear(p); if (!ListMode)
  932. { if (Draw)
  933. FldDrawField(Field);
  934. return;
  935. } memset(&New,0,sizeof(New)); Stream = GetStream(p->Path,Silent); if (Stream) { bool_t HasHost; if (*GetMime(p->Path,NULL,0,&HasHost) || (!HasHost && p->Path[0])) { New.Image = OpenImageUp; New.Checked = 0; tcscpy_s(New.FileName,TSIZEOF(New.FileName),T("..")); tcscpy_s(New.Name,TSIZEOF(New.Name),New.FileName); if (ArrayAppend(&p->List,&New,sizeof(New),4096)) ++p->Count; } Result = Stream->EnumDir(Stream,p->Path,p->Exts,1,&DirItem); if (ListMode==2 && Result == ERR_FILE_NOT_FOUND && UpperPath(p->Path,p->Last,TSIZEOF(p->Last))) { OpenUpdate(p,Silent,ListMode); return; } if (Result == ERR_NOT_DIRECTORY && !Silent) { tcscpy_s(New.FileName,TSIZEOF(New.FileName),DirItem.FileName); New.Image = OpenImageFile; New.Checked = 1; if (ArrayAppend(&p->List,&New,sizeof(New),4096)) ++p->Count; OpenPost(OpenOk); } while (Result == ERR_NONE) { tchar_t Name[MAXPATH];
  936. openitem* i;
  937. for (i=ARRAYBEGIN(p->List,openitem);i!=ARRAYEND(p->List,openitem);++i)
  938. if (tcscmp(i->FileName,DirItem.FileName)==0)
  939. break;
  940. if (i==ARRAYEND(p->List,openitem))
  941. {
  942. New.Checked = 0; tcscpy_s(New.FileName,TSIZEOF(New.FileName),DirItem.FileName); if (DirItem.Size < 0) { int Len; New.Image = OpenImageDir; tcscpy_s(Name,TSIZEOF(Name),New.FileName); Len = tcslen(Name); if (Len>=3 && tcscmp(Name+Len-3,T("://"))==0) Name[Len-3] = 0; } else { switch (DirItem.Type) { case FTYPE_AUDIO: New.Image = OpenImageAudio; break; case FTYPE_PLAYLIST: New.Image = OpenImagePlayList; break; case FTYPE_VIDEO: New.Image = OpenImageVideo; break; default: New.Image = OpenImageFile; break; } SplitURL(New.FileName,NULL,0,NULL,0,Name,TSIZEOF(Name),Name,TSIZEOF(Name)); } tcscpy_s(New.Name,TSIZEOF(New.Name),Name); if (ArrayAppend(&p->List,&New,sizeof(New),4096)) ++p->Count;
  943. } Result = Stream->EnumDir(Stream,NULL,NULL,0,&DirItem); } NodeDelete((node*)Stream); } qsort(ARRAYBEGIN(p->List,openitem),p->Count,sizeof(openitem),OpenCmp); p->First = 0; OpenSetScroll(p);
  944. if (Draw)
  945. {
  946. FldDrawField(Field);
  947. OpenDraw(p,-1);
  948. } }
  949. static void EqInit(FormType* Form,bool_t Draw)
  950. {
  951. node* Eq = NodeEnumObject(NULL,EQUALIZER_ID);
  952. bool_t b;
  953. int n,i;
  954. for (n=0;n<10;++n)
  955. {
  956. Eq->Get(Eq,EQUALIZER_1+n,&i,sizeof(i));
  957. SetValue(Form,Eq1+n,i+20);
  958. SetFieldInt(Form,(UInt16)(Eq1Value+n),i,Draw);
  959. }
  960. Eq->Get(Eq,EQUALIZER_PREAMP,&i,sizeof(i));
  961. SetValue(Form,EqPreamp,i+20);
  962. SetFieldInt(Form,EqPreampValue,i,Draw);
  963. Eq->Get(Eq,EQUALIZER_ENABLED,&b,sizeof(b));
  964. SetValue(Form,EqEnable,b);
  965. Eq->Get(Eq,EQUALIZER_ATTENUATE,&b,sizeof(b));
  966. SetValue(Form,EqAttenuate,b);
  967. }
  968. static void AdvInit(FormType* Form)
  969. {
  970. bool_t b;
  971. node* Advanced = Context()->Advanced;
  972. Advanced->Get(Advanced,ADVANCED_NOBATTERYWARNING,&b,sizeof(b));
  973. SetValue(Form,AdvNoBatteryWarning,b);
  974. Advanced->Get(Advanced,ADVANCED_KEYFOLLOWDIR,&b,sizeof(b));
  975. SetValue(Form,AdvKeyFollowDir,b);
  976. Advanced->Get(Advanced,ADVANCED_AVIFRAMERATE,&b,sizeof(b));
  977. SetValue(Form,AdvAVIFrameRate,b);
  978. Advanced->Get(Advanced,ADVANCED_BENCHFROMPOS,&b,sizeof(b));
  979. SetValue(Form,AdvBenchFromPos,b);
  980. Advanced->Get(Advanced,ADVANCED_NODEBLOCKING,&b,sizeof(b));
  981. SetValue(Form,AdvNoDeblocking,b);
  982. Advanced->Get(Advanced,ADVANCED_BLINKLED,&b,sizeof(b));
  983. SetValue(Form,AdvBlinkLED,b);
  984. Advanced->Get(Advanced,ADVANCED_CARDPLUGINS,&b,sizeof(b));
  985. SetValue(Form,AdvCardPlugins,b);
  986. SetValue(Form,AdvNoEventChecking,NoEventChecking);
  987. Player->Get(Player,PLAYER_SMOOTHALWAYS,&b,sizeof(b));
  988. SetValue(Form,AdvSmoothZoom,b);
  989. Player->Get(Player,PLAYER_AUTOPREROTATE,&b,sizeof(b));
  990. SetValue(Form,AdvPreRotate,b);
  991. //FrmGlueNavObjectTakeFocus(Form, DummyOk); //crashes in longterm at program exit!
  992. }
  993. static void TweakInit(FormType* Form)
  994. {
  995. bool_t v;
  996. if (!Tweak(ADVANCED_ID,ADVANCED_MEMORYOVERRIDE,&v,0))
  997. ShowObject(Form,TweakMemory,0);
  998. else
  999. SetValue(Form,TweakMemory,v);
  1000. if (!Tweak(HIRES_ID,HIRES_USEBORDER,&v,0))
  1001. {
  1002. ShowObject(Form,TweakBorderless,0);
  1003. ShowObject(Form,TweakBorderlessLabel1,0);
  1004. ShowObject(Form,TweakBorderlessLabel2,0);
  1005. }
  1006. else
  1007. SetValue(Form,TweakBorderless,v);
  1008. if (!Tweak(HIRES_ID,HIRES_TRIPLEBUFFER,&v,0))
  1009. {
  1010. ShowObject(Form,TweakTrippleBuffer,0);
  1011. ShowObject(Form,TweakTrippleBufferLabel1,0);
  1012. }
  1013. else
  1014. SetValue(Form,TweakTrippleBuffer,v);
  1015. SetValue(Form,TweakBattery,EvtGetOverride());
  1016. //FrmGlueNavObjectTakeFocus(Form, DummyOk); //crashes in longterm at program exit!
  1017. }
  1018. static void AboutInit(FormType* Form) { int Mhz=0; tchar_t s[40]; uint32_t Max = 0; uint32_t Free = 0; node* Platform = Context()->Platform; stprintf_s(s,TSIZEOF(s),T("%s Version %s"),Context()->ProgramName,Context()->ProgramVersion); FrmCopyLabel(Form,AboutVersion,s); tcscpy_s(s,TSIZEOF(s),T("PalmOS ")); Platform->Get(Platform,PLATFORM_VERSION,s+tcslen(s),sizeof(s)-tcslen(s)*sizeof(tchar_t)); FrmCopyLabel(Form,AboutOSVersion,s); Platform->Get(Platform,PLATFORM_OEMINFO,s,sizeof(s)); FrmCopyLabel(Form,AboutOEMInfo,s); Platform->Get(Platform,PLATFORM_CPU,s,sizeof(s)); Platform->Get(Platform,PLATFORM_CPUMHZ,&Mhz,sizeof(Mhz)); if (Mhz) stcatprintf_s(s,TSIZEOF(s),T(" ~%d Mhz"),Mhz); FrmCopyLabel(Form,AboutCPU,s); if (MemHeapFreeBytes(MemHeapID(0,1),&Free,&Max)==errNone) {
  1019. stprintf_s(s,TSIZEOF(s),T("Storage heap: %dKB"),(int)Free/1024);
  1020. #ifdef HAVE_PALMONE_SDK
  1021. {
  1022. UInt32 Version;
  1023. if (FtrGet(sysFtrCreator,sysFtrNumDmAutoBackup,&Version)==errNone && Version==1 &&
  1024. MemHeapFreeBytes(1|dbCacheFlag,&Free,&Max)==errNone)
  1025. stcatprintf_s(s,TSIZEOF(s),T(" (%dKB)"),(int)Free/1024);
  1026. }
  1027. #endif
  1028. FrmCopyLabel(Form,AboutMem1,s); } if (MemHeapFreeBytes(MemHeapID(0,0),&Free,&Max)==errNone) { stprintf_s(s,TSIZEOF(s),T("Dynamic heap: %dKB"),(int)Free/1024); FrmCopyLabel(Form,AboutMem2,s); }
  1029. //FrmGlueNavObjectTakeFocus(Form, DummyOk); //crashes in longterm at program exit!
  1030. } static void MediaInfoInit(FormType* Form) { tchar_t Rate[16]; tchar_t s[40]; node* Format = NULL; node* VOutput = NULL; packetformat Packet; pin Pin; int i,j; s[0] = 0; Player->Get(Player,PLAYER_LIST_CURRENT,&i,sizeof(i)); Player->Get(Player,PLAYER_LIST_URL+i,s,sizeof(s)); FrmCopyLabel(Form,MediaInfoURL,s); Player->Get(Player,PLAYER_FORMAT,&Format,sizeof(Format)); if (Format) { tcscpy_s(s,sizeof(s),LangStr(Format->Class,NODE_NAME)); FrmCopyLabel(Form,MediaInfoFormat,s); Player->Get(Player,PLAYER_VSTREAM,&i,sizeof(i)); if (i>=0 && Format->Get(Format,(FORMAT_STREAM+i)|PIN_FORMAT,&Packet,sizeof(Packet))==ERR_NONE && Packet.Type == PACKET_VIDEO) { stprintf_s(s,TSIZEOF(s),"%dx%d ",Packet.Format.Video.Width,Packet.Format.Video.Height); if (Packet.PacketRate.Num) { FractionToString(Rate,TSIZEOF(Rate),&Packet.PacketRate,0,2); stcatprintf_s(s,TSIZEOF(s),"%s fps",Rate); } FrmCopyLabel(Form,MediaVideoFormat,s); } if (i>=0 && Format->Get(Format,(FORMAT_STREAM+i),&Pin,sizeof(Pin))==ERR_NONE && Pin.Node) FrmCopyLabel(Form,MediaVideoCodec,LangStr(Pin.Node->Class,NODE_NAME)); Player->Get(Player,PLAYER_ASTREAM,&i,sizeof(i)); if (i>=0 && Format->Get(Format,(FORMAT_STREAM+i)|PIN_FORMAT,&Packet,sizeof(Packet))==ERR_NONE && Packet.Type == PACKET_AUDIO) { s[0]=0; if (Packet.Format.Audio.SampleRate) stcatprintf_s(s,TSIZEOF(s),"%dHz ",Packet.Format.Audio.SampleRate); if (Packet.Format.Audio.Bits) stcatprintf_s(s,TSIZEOF(s),"%dBits ",Packet.Format.Audio.Bits); if (Packet.Format.Audio.Channels==1) tcscat_s(s,TSIZEOF(s),T("Mono")); if (Packet.Format.Audio.Channels==2) tcscat_s(s,TSIZEOF(s),T("Stereo")); FrmCopyLabel(Form,MediaAudioFormat,s); } if (i>=0 && Format->Get(Format,(FORMAT_STREAM+i),&Pin,sizeof(Pin))==ERR_NONE && Pin.Node) { tcscpy_s(s,sizeof(s),LangStr(Pin.Node->Class,NODE_NAME)); FrmCopyLabel(Form,MediaAudioCodec,s); } Player->Get(Player,PLAYER_VOUTPUT,&VOutput,sizeof(VOutput)); if (VOutput) { VOutput->Get(VOutput,OUT_TOTAL,&i,sizeof(int)); VOutput->Get(VOutput,OUT_DROPPED,&j,sizeof(int)); stprintf_s(s,TSIZEOF(s),T("Played frames: %d"),i+j); FrmCopyLabel(Form,MediaVideoTotal,s); stprintf_s(s,TSIZEOF(s),T("Dropped frames: %d"),j); FrmCopyLabel(Form,MediaVideoDropped,s); } }
  1031. //FrmGlueNavObjectTakeFocus(Form, DummyOk); //crashes in longterm at program exit!
  1032. }
  1033. static void BenchmarkInit(FormType* Form) { tchar_t v[16]; tchar_t s[40]; tick_t OrigTick = -1; tick_t Tick = -1; fraction f; int Frames = 0;
  1034. node* Node; int i; Player->Get(Player,PLAYER_BENCHMARK,&Tick,sizeof(Tick)); TickToString(v,TSIZEOF(v),Tick,0,1,0); stprintf_s(s,TSIZEOF(s),T("Benchmark time: %s"),v); FrmCopyLabel(Form,BenchmarkTime,s);
  1035. Player->Get(Player,PLAYER_AOUTPUT,&Node,sizeof(Node)); if (Node) { packetformat Audio; Audio.Type = PACKET_NONE; Node->Get(Node,OUT_INPUT|PIN_FORMAT,&Audio,sizeof(Audio)); if (Audio.Type == PACKET_AUDIO && Audio.Format.Audio.Bits && Audio.Format.Audio.Channels && Audio.Format.Audio.SampleRate) { int Samples = 0; Node->Get(Node,OUT_TOTAL,&Samples,sizeof(int)); Samples /= Audio.Format.Audio.Bits/8; if (!(Audio.Format.Audio.Flags & PCM_PLANES)) Samples /= Audio.Format.Audio.Channels; OrigTick = Scale(Samples,TICKSPERSEC,Audio.Format.Audio.SampleRate); } } Player->Get(Player,PLAYER_VOUTPUT,&Node,sizeof(Node)); if (Node) { Node->Get(Node,OUT_TOTAL,&Frames,sizeof(int));
  1036. if (Frames) { f.Num = Frames; f.Den = Tick; Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT); f.Num *= TICKSPERSEC; FractionToString(v,TSIZEOF(v),&f,0,2); stprintf_s(s,TSIZEOF(s),T("Benchmark FPS: %s"),v); FrmCopyLabel(Form,BenchmarkFPS,s); Player->Get(Player,PLAYER_VSTREAM,&i,sizeof(i)); if (i>=0)  { node* Format; packetformat Video; Video.Type = PACKET_NONE; Player->Get(Player,PLAYER_FORMAT,&Format,sizeof(Format)); if (Format) Format->Get(Format,(FORMAT_STREAM+i)|PIN_FORMAT,&Video,sizeof(Video)); if (Video.Type == PACKET_VIDEO && Video.PacketRate.Num) { OrigTick = Scale64(Frames,(int64_t)Video.PacketRate.Den*TICKSPERSEC,Video.PacketRate.Num); FractionToString(v,TSIZEOF(v),&Video.PacketRate,0,2); stprintf_s(s,TSIZEOF(s),T("Original FPS: %s"),v); FrmCopyLabel(Form,BenchmarkOrigFPS,s); } } } } if (OrigTick >= 0) { TickToString(v,TSIZEOF(v),OrigTick,0,1,0); stprintf_s(s,TSIZEOF(s),T("Original time: %s"),v); FrmCopyLabel(Form,BenchmarkOrigTime,s); f.Num = OrigTick; f.Den = Tick; FractionToString(v,TSIZEOF(v),&f,1,2); stprintf_s(s,TSIZEOF(s),T("Average speed: %s"),v); FrmCopyLabel(Form,BenchmarkSpeed,s); }
  1037. //FrmGlueNavObjectTakeFocus(Form, DummyOk); //crashes in longterm at program exit!
  1038. } static bool_t HitObject(EventType* Event,FormType* Form,UInt16 Id,int dx0,int dx1,int dy0,int dy1) { RectangleType Rect; GetObjectBounds(Form,FrmGetObjectIndex(Form,Id),&Rect); return Event->screenX >= Rect.topLeft.x + dx0 &&        Event->screenX < Rect.topLeft.x + Rect.extent.x + dx1 &&        Event->screenY >= Rect.topLeft.y + dy0 &&        Event->screenY < Rect.topLeft.y + Rect.extent.y + dy1; }
  1039. static Boolean PenMainDummy(EventPtr Event)
  1040. {
  1041. return 1;
  1042. }
  1043. static bool_t ExitFullScreen()
  1044. {
  1045. if (FullScreen)
  1046. {
  1047. Toggle(PLAYER_PLAY,0);
  1048. SetFullScreen(0);
  1049. return 1;
  1050. }
  1051. return 0;
  1052. }
  1053. static void PlayAndFullScreen(bool_t ExitFullScreen)
  1054. {
  1055. bool_t b;
  1056. Player->Get(Player,PLAYER_PLAY,&b,sizeof(b));
  1057. if (b)
  1058. {
  1059. Toggle(PLAYER_PLAY,0);
  1060. if (FullScreen && ExitFullScreen)
  1061. SetFullScreen(0);
  1062. }
  1063. else
  1064. {
  1065. if (IsVideoPrimary())
  1066. SetFullScreen(1);
  1067. Toggle(PLAYER_PLAY,1);
  1068. }
  1069. }
  1070. static Boolean PenMainViewport(EventPtr Event) { if (Event && Event->eType == penUpEvent)
  1071. { if (FullScreen)
  1072. {
  1073. Toggle(PLAYER_PLAY,0);
  1074. SetFullScreen(0);
  1075. }
  1076. else
  1077. if (HitObject(Event,FrmGetFormPtr(MainForm),MainViewport,0,0,0,0))
  1078. PlayAndFullScreen(1);
  1079. }
  1080. return 1; } static Boolean PenMainWinTitle(EventPtr Event)
  1081. {
  1082. if (Event && Event->eType == penUpEvent &&
  1083. HitObject(Event,FrmGetFormPtr(MainForm),MainWinTitle,0,0,0,0))
  1084. _EvtEnqueueKey( menuChr, 0, commandKeyMask );
  1085. return 1;
  1086. }
  1087. static NOINLINE void InSeek(bool_t b)
  1088. {
  1089. Player->Set(Player,PLAYER_INSEEK,&b,sizeof(b));
  1090. }
  1091. static Boolean PenMainPosition(EventPtr Event) { bool_t b;
  1092. if (Event && Event->eType == penDownEvent)
  1093. InSeek(1);
  1094. if (Event && Player->Get(Player,PLAYER_INSEEK,&b,sizeof(b))==ERR_NONE && b)
  1095. {
  1096. fraction Percent;
  1097. RectangleType Rect;
  1098. FormType* Form = FrmGetFormPtr(MainForm);
  1099. GetObjectBounds(Form,FrmGetObjectIndex(Form,MainPosition),&Rect);
  1100. Percent.Num = Event->screenX - Rect.topLeft.x-4;
  1101. Percent.Den = Rect.extent.x-8;
  1102. Player->Set(Player,PLAYER_PERCENT,&Percent,sizeof(Percent));
  1103. }
  1104. if (Event==NULL || Event->eType == penUpEvent)
  1105. InSeek(0); return 1; } static void CancelMouseDown() { if (MouseDown) { MouseDown(NULL); MouseDown = NULL; } }
  1106. static NOINLINE int KeyDir(EventType* Event,bool_t* NoUp)
  1107. {
  1108. int i,d;
  1109. if ((d = KeyUp(Event))!=0)
  1110. i = 1;
  1111. else
  1112. if ((d = KeyRight(Event))!=0)
  1113. i = 2;
  1114. else
  1115. if ((d = KeyDown(Event))!=0)
  1116. i = 3;
  1117. else
  1118. if ((d = KeyLeft(Event))!=0)
  1119. i = 4;
  1120. else
  1121. return 0;
  1122. if (QueryAdvanced(ADVANCED_KEYFOLLOWDIR))
  1123. {
  1124. int Dir;
  1125. int Offset;
  1126. Player->Get(Player,PLAYER_REL_DIR,&Dir,sizeof(Dir));
  1127. if (Dir & DIR_SWAPXY)
  1128. Offset = (Dir & DIR_MIRRORUPDOWN) ? 1:3;
  1129. else
  1130. Offset = (Dir & DIR_MIRRORUPDOWN) ? 2:0;
  1131. i += Offset;
  1132. if (i>4) i-=4;
  1133. }
  1134. if (NoUp)
  1135. *NoUp = d>1;
  1136. if (d<0)
  1137. i = -i;
  1138. return i;
  1139. }
  1140. static void PopupForm(UInt16 Id)
  1141. {
  1142. int i;
  1143. for (i=0;i<1000;++i)
  1144. {
  1145. if (AvailMemory()<40000)
  1146. {
  1147. if (!NodeHibernate())
  1148. break;
  1149. }
  1150. else
  1151. {
  1152. _FrmPopupForm(Id);
  1153. return;
  1154. }
  1155. }
  1156. ShowOutOfMemory();
  1157. }
  1158. static void CheckClipping(FormType* Form)
  1159. {
  1160. if (WinGetActiveWindow() == FrmGetWindowHandle(Form))
  1161. SetClipping(0);
  1162. }
  1163. static NOINLINE void Launch(const tchar_t* URL)
  1164. {
  1165. bool_t b,b0;
  1166. int n;
  1167. n = 1;
  1168. Player->Set(Player,PLAYER_LIST_COUNT,&n,sizeof(n));
  1169. PlayerAdd(Player,0,URL,NULL);
  1170. b = 1;
  1171. Player->Get(Player,PLAYER_PLAYATOPEN_FULL,&b0,sizeof(b0));
  1172. Player->Set(Player,PLAYER_PLAYATOPEN_FULL,&b,sizeof(b));
  1173. n = 0;
  1174. Player->Set(Player,PLAYER_LIST_CURRIDX,&n,sizeof(n));
  1175. Player->Set(Player,PLAYER_PLAYATOPEN_FULL,&b0,sizeof(b0));
  1176. }
  1177. static bool_t IsParams()
  1178. {
  1179. return LaunchParameters && (LaunchCode == sysAppLaunchCmdOpenDB || LaunchCode == sysAppLaunchCmdCustomBase);
  1180. }
  1181. static void ProcessParams()
  1182. {
  1183. if (LaunchParameters)
  1184. {
  1185. tchar_t URL[MAXPATH];
  1186. if (LaunchCode == sysAppLaunchCmdOpenDB)
  1187. {
  1188. SysAppLaunchCmdOpenDBType2* Param = (SysAppLaunchCmdOpenDBType2*)LaunchParameters;
  1189. if (DBFrom(Param->cardNo,Param->dbID[0]+((UInt32)Param->dbID[1]<<16),URL,TSIZEOF(URL)))
  1190. Launch(URL);
  1191. }
  1192. else
  1193. if (LaunchCode == sysAppLaunchCmdCustomBase)
  1194. {
  1195. vfspath* Param = (vfspath*)LaunchParameters;
  1196. if (VFSFromVol(Param->volRefNum,Param->path,URL,TSIZEOF(URL)))
  1197. Launch(URL);
  1198. }
  1199. }
  1200. }
  1201. static Boolean MainFormEventHandler(EventPtr Event) {
  1202. FormType* Form = FrmGetFormPtr(MainForm);
  1203. tick_t t;
  1204. int i; fraction f; UInt16 Id; EventType e;
  1205. if (DIAHandleEvent(Form,Event)) return 1; switch (Event->eType) { case frmOpenEvent: DIASet(0,DIA_SIP); SIPState = DIAGet(DIA_ALL);
  1206. NoPaintResize = -1;
  1207. PushReDraw(); return 1;
  1208. case frmUpdateEvent:
  1209. NoPaintResize = -1;
  1210. PushReDraw();
  1211. return 1;
  1212. case winDisplayChangedEvent:
  1213. MainFormResize(Form); return 1; case winEnterEvent:
  1214. if (Event->data.winEnter.enterWindow == (WinHandle)Form && Form == FrmGetActiveForm()) {
  1215. if (FullScreen)
  1216. DIASet(0,DIA_ALL);
  1217. else
  1218. if (MainDrawn && DIAGet(DIA_ALL) != SIPState)
  1219. DIASet(SIPState,DIA_ALL);
  1220. if (Context()->Wnd == NULL)
  1221. {
  1222. HandleEvents(); // make sure form is drawn
  1223. if (IsParams())
  1224. {
  1225. bool_t b = 1;
  1226. Player->Set(Player,PLAYER_DISCARDLIST,&b,sizeof(b));
  1227. }
  1228. Context_Wnd(Form);
  1229. NoEventChecking = QueryAdvanced(ADVANCED_NOEVENTCHECKING);
  1230. ProcessParams();
  1231. Refresh(Form,1);
  1232. SetClipping(0);
  1233. }
  1234. else
  1235. {
  1236. if (NoPaintResize==0)
  1237. NoPaintResize = 1;
  1238. RefreshResize = 1;
  1239. PushReDraw();
  1240. }
  1241. CancelMouseDown();
  1242. } return 1; case winExitEvent:
  1243. if (Event->data.winExit.exitWindow == (WinHandle)Form) { CancelMouseDown();
  1244. SetClipping(1);
  1245. RefreshResize = 0;
  1246. } return 1;     case frmCloseEvent:
  1247. Player->Set(Player,PLAYER_NOTIFY,NULL,0);
  1248. FtrSet(Context()->ProgramId,20000,SkinNo);
  1249. SkinFree(Skin,SkinDb);
  1250. SetFullScreen(0); Context_Wnd(NULL); break;
  1251. case menuEvent: switch (Event->data.menu.itemID) {
  1252. case MainClear:
  1253. i = 0;
  1254. Player->Set(Player,PLAYER_LIST_COUNT,&i,sizeof(i));
  1255. Player->Set(Player,PLAYER_STOP,NULL,0);
  1256. for (i=0;i<1000;++i)
  1257. if (!NodeHibernate()) // free everything
  1258. break;
  1259. PushReDraw();
  1260. return 1; case MainOpenFiles:
  1261. PopupForm(OpenForm); return 1; case MainSearchFiles: SearchFiles(); return 1; case MainQuit: memset(&e,0,sizeof(e)); e.eType = appStopEvent; _EvtAddUniqueEventToQueue(&e,0,1); return 1;
  1262. case MainMenuPref:
  1263. PopupForm(PrefForm);
  1264. break; case MainAbout: PopupForm(AboutForm); return 1; case MainMenuTweaks:
  1265. PopupForm(TweakForm);
  1266. return 1;
  1267. case MainMenuAdv:
  1268. PopupForm(AdvForm);
  1269. return 1;
  1270. case MainMenuEq:
  1271. PopupForm(EqForm);
  1272. return 1;
  1273. case MainBenchmark:
  1274. if (IsVideoPrimary())
  1275. SetFullScreen(1); t = 0; Player->Set(Player,PLAYER_BENCHMARK,&t,sizeof(t)); return 1; case MainBenchmarkForm: PopupForm(BenchmarkForm); return 1; case MainMediaInfo: PopupForm(MediaInfoForm); return 1; } break; case penUpEvent: if (MouseDown) { MouseDown(Event); MouseDown = NULL; return 1; } break; case penMoveEvent: if (MouseDown) { MouseDown(Event); return 1; } break; case penDownEvent:
  1276. CheckClipping(Form);
  1277. if (FullScreen || HitObject(Event,Form,MainViewport,0,0,0,-5))  { MouseDown = PenMainViewport; return 1; }
  1278. if (HitObject(Event,Form,MainWinTitle,0,0,0,0))
  1279. {
  1280. MouseDown = PenMainWinTitle;
  1281. return 1;
  1282. } if (HitObject(Event,Form,MainPosition,-2,2,-5,0)) { MouseDown = PenMainPosition; PenMainPosition(Event); return 1; } if (HitObject(Event,Form,MainTimer,0,0,0,0))
  1283. {
  1284. Toggle(PLAYER_TIMER_LEFT,-1);
  1285. UpdatePosition(Form,1);
  1286. MouseDown = PenMainDummy;
  1287. return 1;
  1288. }
  1289. break; case ctlSelectEvent:  Id = Event->data.ctlSelect.controlID; switch (Id) { case MainPref: PopupForm(PrefForm); break; case MainFullScreen:
  1290. if (IsVideoPrimary())
  1291. SetFullScreen(1);
  1292. else
  1293. if (IsAudioPlayed())
  1294. {
  1295. SetDisplayPower(0,0);
  1296. SetKeyboardBacklight(0);
  1297. }
  1298. break; case MainPlay: PlayerNotify(Form,PLAYER_PLAY,Toggle(PLAYER_PLAY,-1)); break; case MainNext:  Player->Set(Player,PLAYER_NEXT,NULL,0); break; case MainOpen:
  1299. PopupForm(OpenForm);
  1300. break;
  1301. case MainPrev: Player->Set(Player,PLAYER_PREV,NULL,1);
  1302. break; case MainStop: Player->Set(Player,PLAYER_STOP,NULL,0);
  1303. f.Num = 0; f.Den = 1; Player->Set(Player,PLAYER_PERCENT,&f,sizeof(f)); break; } break; default: break; } return 0; }
  1304. static void ApplicationPostEvent()
  1305. {
  1306. if (AttnEvent)
  1307. {
  1308. AttnEvent = 0;
  1309. if (FrmGetActiveForm() == FrmGetFormPtr(MainForm))
  1310. {
  1311. SetClipping(0);
  1312. }
  1313. }
  1314. }
  1315. static Boolean ApplicationHandleEvent(EventPtr Event) {
  1316. bool_t NoUp;
  1317. if (Event->eType == keyDownEvent || Event->eType == keyUpEvent || Event->eType == keyHoldEvent)
  1318. {
  1319. FormType* Form = FrmGetFormPtr(MainForm);
  1320. if (WinGetActiveWindow() == FrmGetWindowHandle(Form))
  1321. {
  1322. int i;
  1323. if (Event->eType == keyDownEvent)
  1324. {
  1325. if (Event->data.keyDown.chr == vchrCalc && QueryPlatform(PLATFORM_MODEL)==MODEL_ZODIAC)
  1326. Event->data.keyDown.chr = vchrMenu;
  1327. if (Event->data.keyDown.chr == vchrLowBattery && QueryAdvanced(ADVANCED_NOBATTERYWARNING))
  1328. {
  1329. UInt16 Level,Critical;
  1330. Level = SysBatteryInfo(0,NULL,&Critical,NULL,NULL,NULL,NULL);
  1331. if (Level > Critical)
  1332. return 1;
  1333. }
  1334. if (Event->data.keyDown.chr == vchrMenu || //menu will be opened
  1335. Event->data.keyDown.chr == vchrLowBattery ||
  1336. #ifdef HAVE_PALMONE_SDK
  1337. Event->data.keyDown.chr == vchrSilkClock ||
  1338. Event->data.keyDown.chr == vchrClock ||
  1339. Event->data.keyDown.chr == vchrPopupBrightness ||
  1340. #endif
  1341. Event->data.keyDown.chr == vchrLaunch) //PSHack will open a password window
  1342. SetClipping(1);
  1343. else
  1344. if (Event->data.keyDown.chr == vchrAttnStateChanged ||
  1345. Event->data.keyDown.chr == vchrAttnIndicatorTapped ||
  1346. Event->data.keyDown.chr == vchrAttnUnsnooze)
  1347. {
  1348. AttnEvent = 1;
  1349. SetClipping(1);
  1350. }
  1351. else
  1352. SetClipping(0);
  1353. }
  1354. switch (KeyDir(Event,&NoUp))
  1355. {
  1356. case 1:
  1357. Delta(PLAYER_VOLUME,5,0,100);
  1358. return 1;
  1359. case 3:
  1360. Delta(PLAYER_VOLUME,-5,0,100);
  1361. return 1;
  1362. case 2:
  1363. KeyTrackNext = IsPlayList() && !KeyHold(Event);
  1364. if (!KeyTrackNext)
  1365. {
  1366. if (!NoUp) InSeek(1);
  1367. Player->Set(Player,PLAYER_MOVEFFWD,NULL,0);
  1368. }
  1369. return 1;
  1370. case 4:
  1371. KeyTrackPrev = IsPlayList() && !KeyHold(Event);
  1372. if (!KeyTrackPrev)
  1373. {
  1374. if (!NoUp) InSeek(1);
  1375. Player->Set(Player,PLAYER_MOVEBACK,NULL,0);
  1376. }
  1377. return 1;
  1378. case -2:
  1379. if (KeyTrackNext)
  1380. Player->Set(Player,PLAYER_NEXT,NULL,0);
  1381. InSeek(0);
  1382. return 1;
  1383. case -4:
  1384. if (KeyTrackPrev)
  1385. Player->Set(Player,PLAYER_PREV,NULL,1);
  1386. InSeek(0);
  1387. return 1;
  1388. }
  1389. if (KeyMediaStop(Event)>0)
  1390. {
  1391. if (IsVideoPrimary())
  1392. SetFullScreen(!FullScreen);
  1393. return 1;
  1394. }
  1395. if (KeyMediaVolumeUp(Event)>0)
  1396. {
  1397. Delta(PLAYER_VOLUME,2,0,100);
  1398. return 1;
  1399. }
  1400. if (KeyMediaVolumeDown(Event)>0)
  1401. {
  1402. Delta(PLAYER_VOLUME,-2,0,100);
  1403. return 1;
  1404. }
  1405. if (KeyMediaNext(Event)>0)
  1406. {
  1407. Player->Set(Player,PLAYER_NEXT,NULL,0);
  1408. return 1;
  1409. }
  1410. if (KeyMediaPrev(Event)>0)
  1411. {
  1412. Player->Set(Player,PLAYER_PREV,NULL,1);
  1413. return 1;
  1414. }
  1415. i = KeySelect(Event);
  1416. if (i==1)
  1417. {
  1418. KeySelectHold = KeyHold(Event);
  1419. if (FullScreen && KeySelectHold)
  1420. {
  1421. ExitFullScreen();
  1422. return 1;
  1423. }
  1424. }
  1425. if (((i&2) && !KeySelectHold) || KeyMediaPlay(Event)>0)
  1426. {
  1427. PlayAndFullScreen(0);
  1428. return 1;
  1429. }
  1430. }
  1431. }
  1432. if (Event->eType == frmLoadEvent) { UInt16 Id = Event->data.frmLoad.formID; FormPtr Form = FrmInitForm(Id);
  1433. DIALoad(Form); switch (Id) { case OpenForm: OpenInit(Form); FrmSetEventHandler(Form, OpenHandler); break; case AboutForm: AboutInit(Form); FrmSetEventHandler(Form, AboutHandler); break;
  1434. case TweakForm:
  1435. TweakInit(Form);
  1436. FrmSetEventHandler(Form, TweakHandler);
  1437. break;
  1438. case AdvForm:
  1439. AdvInit(Form);
  1440. FrmSetEventHandler(Form, AdvHandler);
  1441. break;
  1442. case EqForm:
  1443. EqInit(Form,0);
  1444. FrmSetEventHandler(Form, EqHandler);
  1445. break;
  1446. case PrefForm: PrefInit(Form); FrmSetEventHandler(Form, PrefHandler); break; case MediaInfoForm: MediaInfoInit(Form); FrmSetEventHandler(Form, MediaInfoHandler); break; case BenchmarkForm: BenchmarkInit(Form); FrmSetEventHandler(Form, BenchmarkHandler); break; case MainForm: memset(&MainState,0,sizeof(MainState));
  1447. MainDrawn = 0; MainFormInit(Form); FrmSetEventHandler(Form, MainFormEventHandler); FrmSetGadgetHandler(Form, FrmGetObjectIndex(Form, MainViewport),ViewportEventHandler); FrmSetGadgetHandler(Form, FrmGetObjectIndex(Form, MainWinTitle),WinTitleEventHandler);
  1448. break; } FrmSetActiveForm(Form);
  1449. return 1; } return 0; } void Main() { int Sleep = max(GetTimeFreq()/250,1); EventType event; FrmGotoForm(MainForm);
  1450. Player = (player*)Context()->Player; if (Player) {
  1451. event.eType = nilEvent;
  1452. do { int Timeout; switch (Player->Process(Player)) { case ERR_BUFFER_FULL: Timeout = NoEventChecking?evtNoWait:Sleep; break; case ERR_STOPPED: Timeout = evtWaitForever; break; default: Timeout = evtNoWait; break; } while (Timeout || _EvtEventAvail()) {  _EvtGetEvent(&event,Timeout);
  1453. if (event.eType == nilEvent) break;
  1454. if (!PlatformHandleEvent(&event))
  1455. if (!ApplicationHandleEvent(&event)) // important: before SysHandleEvent
  1456. OSHandleEvent(&event);
  1457. ApplicationPostEvent();
  1458. if (event.eType == appStopEvent) break;
  1459. Timeout = 0;
  1460. } }  while (event.eType != appStopEvent); } FrmCloseAllForms(); }
  1461. UInt32 PilotMain(UInt16 launchCode, MemPtr launchParameters, UInt16 launchFlags) {
  1462. if ((launchCode == sysAppLaunchCmdNormalLaunch ||
  1463.  launchCode == sysAppLaunchCmdOpenDB ||
  1464.  launchCode == sysAppLaunchCmdCustomBase) &&  Context_Init(ProgramName,ProgramVersion,ProgramId,NULL,NULL)) {
  1465. LaunchCode = launchCode;
  1466. LaunchParameters = launchParameters;
  1467. Main(); Context_Done(); } else if (launchCode == sysAppLaunchCmdNotify)
  1468. LaunchNotify((SysNotifyParamType*)launchParameters,FrmGetActiveForm() == FrmGetFormPtr(MainForm));
  1469. return errNone; }