📄 mediaplayer.c
字号:
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);
// Initialize ProgCtl
pme->m_ProgCtl.m_pIShell = pme->m_pIShell;
pme->m_ProgCtl.m_pIDisplay = pme->m_pIDisplay;
if (!CProgCtl_Init(&pme->m_ProgCtl, &rectProg))
MP_WINERR_RETURN(pme);
MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_PLAY, IDM_PM_PLAY, 0);
MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_STOP, IDM_PM_STOP, 0);
MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_FULLSCRN, IDM_PM_FULLSCRN, 0);
MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_REWIND, IDM_PM_REWIND, 0);
MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_PAUSE, IDM_PM_PAUSE, 0);
MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_FF, IDM_PM_FF, 0);
if (pme->m_eWin == MPPW_RECORD)
MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_RECORD, IDM_PM_RECORD, 0);
MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_UP, IDM_PM_UP, 0);
MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_DOWN, IDM_PM_DOWN, 0);
}
return (IWindow *)pme;
}
/*===========================================================================
This function deletes the player window.
===========================================================================*/
static void CPlayerWin_Delete(IWindow * po)
{
CPlayerWin * pme = (CPlayerWin *)po;
MP_RELEASEIF(pme->m_pTitle);
MP_RELEASEIF(pme->m_pIdleImage);
MP_RELEASEIF(pme->m_pPlayerMenu);
// Release memory for file name allocated in CMediaPlayer
FREEIF(pme->m_pszFile);
if (CPlayerWin_IsMedia(pme))
{
MP_RELEASEIF(pme->m_pMedia);
CProgCtl_Release(&pme->m_ProgCtl);
if (pme->m_bProgTimer)
ISHELL_CancelTimer(pme->m_pIShell, (PFNNOTIFY)CPlayerWin_ProgTimerNotify, pme);
}
else if (CPlayerWin_IsImage(pme))
{
MP_RELEASEIF(pme->m_pImage);
MP_RELEASEIF(pme->m_pImageCtl);
}
FREE(pme);
}
/*===========================================================================
This function enables/disables the player window.
===========================================================================*/
static void CPlayerWin_Enable(IWindow * po, boolean bEnable)
{
CPlayerWin * pme = (CPlayerWin *)po;
boolean bActive;
if (!CWindow_ProcessEnable(po, bEnable))
return;
bActive = pme->m_bActive;
ISTATIC_SetActive(pme->m_pTitle, bActive);
IMENUCTL_SetActive(pme->m_pPlayerMenu, bActive);
if (CPlayerWin_IsImage(pme))
IIMAGECTL_SetActive(pme->m_pImageCtl, bActive);
if (!pme->m_bActive)
{
IIMAGE_Stop(pme->m_pIdleImage);
if (CPlayerWin_IsMedia(pme) && pme->m_pMedia)
IMEDIA_Stop(pme->m_pMedia);
}
else
{
IMENUCTL_SetSel(pme->m_pPlayerMenu, (uint16) (pme->m_eWin == MPPW_PLAY ? IDM_PM_PLAY : IDM_PM_RECORD));
}
}
/*===========================================================================
This function redraws player window.
If the full screen mode is on, then
(1) if playback is not ongoing, then it paints the screen with black.
(2) if image is being displayed, then redraws the image.
===========================================================================*/
static void CPlayerWin_Redraw(IWindow * po)
{
CPlayerWin * pme = (CPlayerWin *)po;
char * pszFile = pme->m_pszFile;
AEERect rect;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -