📄 playlistdlg.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
///////////////////////////////////////////////////////////////////////////////
// File: PlaylistDlg.cpp
//
// Desc: This file implements the CPlaylistDialog object, which contains the
// playlist view dialog.
//
///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#include "PlaylistDlg.h"
#include "CEPlayerUtil.h"
#include "PlaylistMgr.h"
#include "AddTracksDlg.h"
#include "AddDeleteDlg.h"
#include "PlayerWindow.h"
#include "SelectPlaylistDlg.h"
#include "aygshell_helper.h"
#define MENU_ICON_WIDTH 16
#define NUM_TRACKS_MENU_ICONS 7
#define I_IMAGENONE (-2)
#define APPBAR_HEIGHT 22
#define MENU_ITEM_HEIGHT 20
#define MENU_ITEM_HORZ_MARGIN 2
#define MAX_MENU_ITEM_WIDTH 200
extern bool g_bSmallScreen;
CPlaylistDialog::CPlaylistDialog(HWND hwndParent, bool bOrganizeFavorites) :
CBaseDialog(hwndParent, IDD_PLAYLIST_TRACKS),
m_hwndDropdown(NULL),
m_hwndMB(NULL),
m_hwndTrackList(NULL),
m_hFont(NULL),
m_pPlaylist(NULL),
m_bOrganizeFavorites(bOrganizeFavorites)
{
CPlaylistMgr * pManager = CPlaylistMgr::GetInstance();
m_hFont = GetBoldFont();
m_himgPlaylist = ImageList_LoadBitmap(g_hInst,
MAKEINTRESOURCE(IDB_PLAYLIST),
MENU_ICON_WIDTH,
1,
CLR_DEFAULT);
m_himgLocationList = ImageList_LoadBitmap(g_hInst,
MAKEINTRESOURCE(IDB_LOCATIONLIST),
MENU_ICON_WIDTH,
1,
CLR_DEFAULT);
if (!m_bOrganizeFavorites && pManager)
{
m_pPlaylist = pManager->CurrentPlaylist();
}
if (NULL != m_pPlaylist)
{
m_pPlaylist->Load();
//
// Check to see if this playlist is empty
//
CMediaClip * pClip;
int iAvailCount = 0;
int iCount;
iCount = (int)m_pPlaylist->GetCount();
for (int i = 0; i < iCount; i++)
{
pClip = m_pPlaylist->GetTrack(i);
if (pClip && pClip->IsAvailable())
{
iAvailCount++;
}
}
if (0 == iAvailCount && iCount > 0)
{
CSelectPlaylistDialog selPlaylist(hwndParent);
if (ID_ALL_MUSIC != selPlaylist.DoModal())
{
CAddDeleteDialog addDelete(hwndParent, hwndParent);
addDelete.DoModal();
m_pPlaylist = pManager->CurrentPlaylist();
if (m_pPlaylist) m_pPlaylist->Load();
}
else
{
m_pPlaylist = NULL;
}
}
}
}
CPlaylistDialog::~CPlaylistDialog()
{
if (NULL != m_hFont)
{
DeleteObject(m_hFont);
}
if (NULL != m_himgPlaylist)
{
ImageList_Destroy(m_himgPlaylist);
}
if (NULL != m_himgLocationList)
{
ImageList_Destroy(m_himgLocationList);
}
#ifdef UNDER_CE
if (NULL != m_hwndDropdown)
{
CommandBar_Destroy(m_hwndDropdown);
}
if (NULL != m_hwndMB)
{
CommandBar_Destroy(m_hwndMB);
}
#endif /* UNDER_CE */
}
HRESULT CPlaylistDialog::CreateBars()
{
HRESULT hr = S_OK;
DWORD dwStyle;
int iImg = 0;
do
{
//
// Setup the "Menu Bar" (this appears at the bottom of the window)
//
#ifdef UNDER_CE
m_hwndMB = CommandBar_Create(g_hInst, m_hwndDlg, 1234);
#endif /* UNDER_CE */
dwStyle = SendMessage(m_hwndMB, TB_GETSTYLE, 0, 0);
dwStyle &= ~CCS_TOP;
dwStyle |= CCS_BOTTOM | TBSTYLE_FLAT;
SendMessage(m_hwndMB, TB_SETSTYLE, 0, dwStyle);
#ifdef UNDER_CE
iImg = CommandBar_AddBitmap(m_hwndMB,
g_hInst,
IDB_PLAYLIST,
2,
16,
16);
#endif /* UNDER_CE */
if (-1 == iImg)
{
hr = E_FAIL;
break;
}
#ifdef UNDER_CE
iImg = CommandBar_AddBitmap(m_hwndMB,
g_hInst,
IDB_PLAYLISTMB,
6,
16,
16);
#endif /* UNDER_CE */
if (-1 == iImg)
{
hr = E_FAIL;
break;
}
TBBUTTON buttons[NUM_TRACKS_MENU_ICONS];
int iButton;
static int commands[NUM_TRACKS_MENU_ICONS-1] =
{
ID_ADD_TRACKS,
ID_DELETE_TRACKS,
ID_REORDER_UP,
ID_REORDER_DOWN,
ID_PLAY_SONG,
ID_TRACK_INFO
};
for (iButton = 0; iButton < NUM_TRACKS_MENU_ICONS-3; iButton++)
{
buttons[iButton].iBitmap = iButton + 2;
buttons[iButton].idCommand = commands[iButton];
buttons[iButton].fsState = TBSTATE_ENABLED;
buttons[iButton].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
buttons[iButton].dwData = 0;
buttons[iButton].iString = 0;
}
buttons[iButton].iBitmap = I_IMAGENONE;
buttons[iButton].idCommand = ID_DEAD_SPACE;
buttons[iButton].fsState = 0;
buttons[iButton].fsStyle = TBSTYLE_BUTTON;
buttons[iButton].dwData = 0;
buttons[iButton].iString = 0;
iButton++;
for (; iButton < NUM_TRACKS_MENU_ICONS; iButton++)
{
buttons[iButton].iBitmap = iButton + 1;
buttons[iButton].idCommand = commands[iButton-1];
buttons[iButton].fsState = TBSTATE_ENABLED;
buttons[iButton].fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
buttons[iButton].dwData = 0;
buttons[iButton].iString = 0;
}
#ifdef UNDER_CE
if (!CommandBar_AddButtons(m_hwndMB, NUM_TRACKS_MENU_ICONS, buttons))
{
hr = E_FAIL;
break;
}
#endif /* UNDER_CE */
//
// This sets up the "Drop Down" command bar...
//
#ifdef UNDER_CE
m_hwndDropdown = CommandBar_Create(g_hInst, m_hwndDlg, 2134);
#endif /* UNDER_CE */
dwStyle = SendMessage(m_hwndDropdown, TB_GETSTYLE, 0, 0);
dwStyle &= ~CCS_BOTTOM;
dwStyle |= CCS_TOP | TBSTYLE_FLAT;
SendMessage(m_hwndDropdown, TB_SETSTYLE, 0, dwStyle);
#ifdef UNDER_CE
iImg = CommandBar_AddBitmap(m_hwndDropdown,
g_hInst,
IDB_PLAYLIST,
2,
16,
16);
#endif /* UNDER_CE */
if (-1 == iImg)
{
hr = E_FAIL;
break;
}
// Add our dropdown button to the command bar
TBBUTTON button;
button.idCommand = IDC_PLAYLIST_DROPDOWN;
button.fsState = TBSTATE_ENABLED;
button.fsStyle = TBSTYLE_BUTTON | TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE;
button.dwData = 0;
if (m_pPlaylist)
{
button.iBitmap = I_PLAYLIST;
button.iString = (int)m_pPlaylist->GetName();
}
else if (m_bOrganizeFavorites)
{
button.iBitmap = -1;
button.iString = (int)TEXT("Organize Playlists");
}
else
{
button.iBitmap = -1;
button.iString = (int)TEXT("Local Content");
}
#ifdef UNDER_CE
if (!CommandBar_AddButtons(m_hwndDropdown, 1, &button))
{
hr = E_FAIL;
break;
}
#endif /* UNDER_CE */
} while (0);
return hr;
}
void CPlaylistDialog::EnableMenubarIcons()
{
int iCount = (int)ListView_GetSelectedCount(m_hwndTrackList);
int iIndex = (int)ListView_GetNextItem(m_hwndTrackList, -1, LVNI_SELECTED);
CPlaylistMgr * pManager = CPlaylistMgr::GetInstance();
// always enable the "All My Music" and "All Playlists" buttons
TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof (tbbi);
tbbi.dwMask = TBIF_STATE;
if (NULL != m_pPlaylist || m_bOrganizeFavorites)
{
tbbi.fsState = TBSTATE_ENABLED;
}
else
{
tbbi.fsState = 0;
}
SendMessage(m_hwndMB, TB_SETBUTTONINFO, ID_ADD_TRACKS, (LPARAM)&tbbi);
if (iCount == 1)
{
tbbi.fsState = TBSTATE_ENABLED;
}
else
{
tbbi.fsState = 0;
}
SendMessage(m_hwndMB, TB_SETBUTTONINFO, ID_DELETE_TRACKS, (LPARAM)&tbbi);
if ((NULL != m_pPlaylist || m_bOrganizeFavorites)
&& iIndex > 0 && 1 == iCount)
{
tbbi.fsState = TBSTATE_ENABLED;
}
else
{
tbbi.fsState = 0;
}
SendMessage(m_hwndMB, TB_SETBUTTONINFO, ID_REORDER_UP, (LPARAM)&tbbi);
if (NULL != m_pPlaylist
&& -1 != iIndex && 1 == iCount
&& m_pPlaylist->GetCount() > (UINT)(iIndex + 1))
{
tbbi.fsState = TBSTATE_ENABLED;
}
else if (m_bOrganizeFavorites
&& -1 != iIndex
&& pManager
&& pManager->GetFavorites()
&& pManager->GetFavorites()->GetCount() > (UINT)(iIndex + 1))
{
tbbi.fsState = TBSTATE_ENABLED;
}
else
{
tbbi.fsState = 0;
}
SendMessage(m_hwndMB, TB_SETBUTTONINFO, ID_REORDER_DOWN, (LPARAM)&tbbi);
CPlaylist * pPlaylist = NULL;
if (NULL != m_pPlaylist)
{
pPlaylist = m_pPlaylist;
}
else if (m_bOrganizeFavorites && pManager)
{
pPlaylist = pManager->GetFavorites();
}
else if (pManager)
{
pPlaylist = pManager->LocalContent();
}
CMediaClip * pClip = NULL;
if (pPlaylist) pClip = pPlaylist->GetTrack(iIndex);
if ((1 == iCount
&& NULL != pClip
&& pClip->IsAvailable())
|| 0 == iCount)
{
tbbi.fsState = TBSTATE_ENABLED;
}
else
{
tbbi.fsState = 0;
}
SendMessage(m_hwndMB, TB_SETBUTTONINFO, ID_PLAY_SONG, (LPARAM)&tbbi);
if (1 == iCount
&& NULL != pClip
&& pClip->IsLocal())
{
tbbi.fsState = TBSTATE_ENABLED;
}
else
{
tbbi.fsState = 0;
}
SendMessage(m_hwndMB, TB_SETBUTTONINFO, ID_TRACK_INFO, (LPARAM)&tbbi);
}
BOOL CPlaylistDialog::DialogProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
BOOL fHandled = FALSE;
CPlaylistMgr * pManager = CPlaylistMgr::GetInstance();
switch (msg)
{
case WM_INITDIALOG:
OnInitDialog();
g_pPlayerWindow->m_hWndPlay = m_hwndDlg;
fHandled = FALSE; // we set focus, so don't change it
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -