📄 mediaplayer.c
字号:
CMainWin * pme = (CMainWin *)po;
MP_RELEASEIF(pme->m_pLogo);
if (pme->m_pMainMenu)
pme->m_pOwner->m_wMainWin = IMENUCTL_GetSel(pme->m_pMainMenu);
MP_RELEASEIF(pme->m_pMainMenu);
FREE(pme);
}
/*===========================================================================
This function enables/disables the main window.
===========================================================================*/
static void CMainWin_Enable(IWindow * po, boolean bEnable)
{
CMainWin * pme = (CMainWin *)po;
if (!CWindow_ProcessEnable(po, bEnable))
return;
if (!pme->m_bActive)
{
IMENUCTL_SetActive(pme->m_pMainMenu, FALSE);
IIMAGE_Stop(pme->m_pLogo);
return;
}
IMENUCTL_SetActive(pme->m_pMainMenu, TRUE);
IMENUCTL_SetSel(pme->m_pMainMenu, pme->m_pOwner->m_wMainWin);
MP_DrawImage(pme->m_pLogo, &pme->m_rectLogo, TRUE);
}
/*===========================================================================
This function redraws the main window.
===========================================================================*/
static void CMainWin_Redraw(IWindow * po)
{
CMainWin * pme = (CMainWin *)po;
if (!pme->m_bActive)
return;
IDISPLAY_ClearScreen(pme->m_pIDisplay);
MP_DRAWHEADER(pme);
MP_DrawImage(pme->m_pLogo, &pme->m_rectLogo, TRUE);
IMENUCTL_Redraw(pme->m_pMainMenu);
IDISPLAY_Update(pme->m_pIDisplay);
}
/*===========================================================================
This function processes events routed to main window.
===========================================================================*/
static boolean CMainWin_HandleEvent(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
CMainWin * pme = (CMainWin *)po;
boolean bRet = TRUE;
if (eCode == EVT_COPYRIGHT_END && pme->m_bAbout)
{
pme->m_bAbout = FALSE;
CMediaPlayer_Redraw(pme->m_pOwner, TRUE);
return TRUE;
}
if (MP_ISEVTKEY(eCode))
return IMENUCTL_HandleEvent(pme->m_pMainMenu, eCode, wParam, dwParam);
if (!MP_ISEVTCMD(eCode))
return FALSE;
switch (wParam)
{
case IDM_MAIN_PLAYFILE:
CMediaPlayer_SetWindow(pme->m_pOwner, MPW_FILELIST, 0);
break;
case IDM_MAIN_RECORD:
CMediaPlayer_RecordQCPFile(pme->m_pOwner, MP_QCP_REC_FILE);
break;
#if defined(MEDIAPLAYER_SETTINGS)
case IDM_MAIN_SETTINGS:
break;
#endif // defined(MEDIAPLAYER_SETTINGS)
case IDM_MAIN_ABOUT:
CMainWin_About(pme);
break;
default:
bRet = FALSE;
break;
}
return bRet;
}
/*===========================================================================
This function displays the About dialog of the app.
===========================================================================*/
static void CMainWin_About(CMainWin * pme)
{
CMediaPlayer_DisableWin(pme->m_pOwner);
pme->m_bAbout = TRUE;
IDISPLAY_ClearScreen(pme->m_pIDisplay);
MP_DRAWHEADER(pme);
ISHELL_ShowCopyright(pme->m_pIShell);
}
/*===============================================================================
CFileListWin Functions
=============================================================================== */
/*===========================================================================
This function constucts the file list window.
===========================================================================*/
static IWindow * CFileListWin_New(CMediaPlayer * pOwner)
{
CFileListWin * pme;
VTBL(IWindow) vtbl;
MP_IWINDOW_SETVTBL(&vtbl, CFileListWin_Enable, CFileListWin_Redraw, CFileListWin_HandleEvent, CFileListWin_Delete);
pme = (CFileListWin *)CWindow_New(sizeof(CFileListWin), pOwner, &vtbl);
if (!pme)
return NULL;
{
int cx = pme->m_pOwner->m_cxWidth;
int cy = pme->m_pOwner->m_cyHeight;
AEERect rect;
FileInfo fi;
uint16 wItemID = 0;
AECHAR *szBuf;
int y;
IFileMgr * pIFileMgr;
if (ISHELL_CreateInstance(pme->m_pIShell, AEECLSID_MENUCTL, (void **)&pme->m_pFileMenu))
MP_WINERR_RETURN(pme);
y = pme->m_pOwner->m_rectHdr.dy + 1;
SETAEERECT(&rect, 0, y, cx, cy - y);
MP_SetMenuAttr(pme->m_pFileMenu, AEECLSID_MENUCTL, pme->m_pOwner->m_nColorDepth, &rect, 0);
IMENUCTL_SetTitle(pme->m_pFileMenu, MEDIAPLAYER_RES_FILE, IDS_FILELISTMENU_TITLE, NULL);
// Enumerate all music files and add them to menu
szBuf = MALLOC(MAX_FILE_NAME * sizeof(AECHAR));
if(!szBuf)
MP_WINERR_RETURN(pme);
if (ISHELL_CreateInstance(pme->m_pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr))
{
FREE(szBuf);
MP_WINERR_RETURN(pme);
}
IFILEMGR_EnumInit(pIFileMgr, MP_MEDIA_DIR, FALSE);
while (wItemID < MP_MAX_FILES && IFILEMGR_EnumNext(pIFileMgr, &fi))
{
char * szName;
pme->m_szFileArray[wItemID] = STRDUP(fi.szName);
if (!pme->m_szFileArray[wItemID])
{
pme->m_NumFiles = wItemID;
FREE(szBuf);
MP_RELEASEIF(pIFileMgr);
MP_WINERR_RETURN(pme);
}
// Add only the file name
szName = MP_GetFileName(fi.szName);
if (szName)
{
uint16 wIconID = CMediaPlayer_FindHandlerType(pme->m_pOwner, szName);
if (wIconID)
{
STRTOWSTR(szName, szBuf, MAX_FILE_NAME);
MP_AddMenuItem(pme->m_pFileMenu, 0, szBuf, wIconID, (uint16)(IDM_FILELIST_BASE + wItemID), 0);
}
}
wItemID++;
}
pme->m_NumFiles = wItemID;
MP_RELEASEIF(pIFileMgr);
FREE(szBuf);
}
return (IWindow *)pme;
}
/*===========================================================================
This function deletes the file list window.
===========================================================================*/
static void CFileListWin_Delete(IWindow * po)
{
CFileListWin * pme = (CFileListWin *)po;
int i;
for ( i = 0; i < pme->m_NumFiles; i++ )
{
if (pme->m_szFileArray[i])
FREE((void *)pme->m_szFileArray[i]);
}
if (pme->m_pFileMenu)
pme->m_pOwner->m_wFileListWin = IMENUCTL_GetSel(pme->m_pFileMenu);
MP_RELEASEIF(pme->m_pFileMenu);
FREE(pme);
}
/*===========================================================================
This function enables/disables the file list window.
===========================================================================*/
static void CFileListWin_Enable(IWindow * po, boolean bEnable)
{
CFileListWin * pme = (CFileListWin *)po;
if (!CWindow_ProcessEnable(po, bEnable))
return;
if (!pme->m_bActive)
{
IMENUCTL_SetActive(pme->m_pFileMenu, FALSE);
return;
}
if (pme->m_NumFiles)
{
IMENUCTL_SetActive(pme->m_pFileMenu, TRUE);
IMENUCTL_SetSel(pme->m_pFileMenu, pme->m_pOwner->m_wFileListWin);
}
else
{
MP_ErrorDlg(pme->m_pOwner, IDS_ERR_NOFILES);
}
}
/*===========================================================================
This function redraws the file list window.
===========================================================================*/
static void CFileListWin_Redraw(IWindow * po)
{
CFileListWin * pme = (CFileListWin *)po;
if (!pme->m_bActive)
return;
IDISPLAY_ClearScreen(pme->m_pIDisplay);
MP_DRAWHEADER(pme);
IMENUCTL_Redraw(pme->m_pFileMenu);
IDISPLAY_Update(pme->m_pIDisplay);
}
/*===========================================================================
This function processes events routed to the file list window.
===========================================================================*/
static boolean CFileListWin_HandleEvent(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
CFileListWin * pme = (CFileListWin *)po;
if (MP_ISCLR(eCode) || MP_ISCMD(eCode, IDS_OK))
{
CMediaPlayer_SetWindow(pme->m_pOwner, MPW_MAIN, 0);
return TRUE;
}
if (MP_ISEVTKEY(eCode))
{
return IMENUCTL_HandleEvent(pme->m_pFileMenu, eCode, wParam, dwParam);
}
// Check if it is EVT_COMMAND and corresponds to files
if (!MP_ISEVTCMD(eCode))
return FALSE;
if (wParam < IDM_FILELIST_BASE)
return FALSE;
// Play the file...
CMediaPlayer_PlayFile(pme->m_pOwner, pme->m_szFileArray[(int)wParam - IDM_FILELIST_BASE]);
return TRUE;
}
/*===============================================================================
CPlayerWin Functions
=============================================================================== */
/*===========================================================================
This function constructs player window.
Player window type can be
(1) MPPW_PLAY: Plays media files
(2) MPPW_RECORD: Records QCP file
(3) MPPW_IMAGE: Displays image (of IImage type)
===========================================================================*/
static IWindow * CPlayerWin_New(CMediaPlayer * pOwner, MPPlayerWin eWin)
{
CPlayerWin * pme;
VTBL(IWindow) vtbl;
int y;
int dy;
MP_IWINDOW_SETVTBL(&vtbl, CPlayerWin_Enable, CPlayerWin_Redraw, CPlayerWin_HandleEvent, CPlayerWin_Delete);
pme = (CPlayerWin *)CWindow_New(sizeof(CPlayerWin), pOwner, &vtbl);
if (!pme)
return NULL;
pme->m_eWin = eWin;
// Set title and image rects. Create the static control.
{
int cx = pme->m_pOwner->m_cxWidth;
int cy = pme->m_pOwner->m_cyHeight;
int nLChSize = pme->m_pOwner->m_nLChSize;
int cyProgMain = pme->m_pOwner->m_nNChSize + 2;
AEERect rectTitle;
AEERect rectMenu;
// File name text rect
y = pme->m_pOwner->m_rectHdr.dy + 1;
dy = nLChSize;
SETAEERECT(&rectTitle, 0, y, cx, dy);
// Create IStatic for file name
if (ISHELL_CreateInstance(pme->m_pIShell, AEECLSID_STATIC, (void **)&pme->m_pTitle))
MP_WINERR_RETURN(pme);
ISTATIC_SetRect(pme->m_pTitle, &rectTitle);
ISTATIC_SetProperties(pme->m_pTitle, ST_CENTERTEXT | ST_NOSCROLL);
// Image rect
y += rectTitle.dy;
dy = cy - y - cyProgMain - MP_ICONVIEWCTL_CY - 2;
SETAEERECT(&pme->m_rectImage, 0, y, cx, dy);
MEMCPY(&pme->m_rectImageCopy, &pme->m_rectImage, sizeof(AEERect));
// IconViewCtl rect
y = cy - MP_ICONVIEWCTL_CY;
dy = MP_ICONVIEWCTL_CY;
SETAEERECT(&rectMenu, 0, y, cx, dy);
if (ISHELL_CreateInstance(pme->m_pIShell, AEECLSID_SOFTKEYCTL, (void **)&pme->m_pPlayerMenu))
MP_WINERR_RETURN(pme);
MP_SetMenuAttr(pme->m_pPlayerMenu, AEECLSID_ICONVIEWCTL, pme->m_pOwner->m_nColorDepth, &rectMenu, MP_MAXSOFTKEYITEMS);
}
if (CPlayerWin_IsImage(pme))
{
MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_FULLSCRN, IDM_PM_FULLSCRN, 0);
}
else if (CPlayerWin_IsMedia(pme))
{
int cx = pme->m_pOwner->m_cxWidth;
int cy = pme->m_pOwner->m_cyHeight;
int cyProgMain = pme->m_pOwner->m_nNChSize + 2;
AEERect rectProg;
// ProgMain rect
y = cy - cyProgMain - MP_ICONVIEWCTL_CY - 2;
dy = cyProgMain;
SETAEERECT(&rectProg, 0, y, cx, dy);
// Initialize logo below the header
pme->m_pIdleImage = ISHELL_LoadResImage(pme->m_pIShell, MEDIAPLAYER_RES_FILE, IDB_LOGO);
if (!pme->m_pIdleImage)
MP_WINERR_RETURN(pme);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -