⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playlistview.cpp

📁 FreeAMP(MP3播放)程序源代码-用来研究MP3解码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*____________________________________________________________________________

        FreeAmp - The Free MP3 Player

        Portions Copyright (C) 1999 EMusic.com

        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., 675 Mass Ave, Cambridge, MA 02139, USA.

        $Id: PlaylistView.cpp,v 1.69 2001/01/18 17:30:55 ijr Exp $
____________________________________________________________________________*/

// The debugger can't handle symbols more than 255 characters long.
// STL often creates symbols longer than that.
// When symbols are longer than 255 characters, the warning is disabled.
#ifdef WIN32
#pragma warning(disable:4786) 
#endif

#include <windows.h>
#include <windowsx.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <direct.h>

#include <algorithm>

using namespace std;

#include "config.h"
#include "utility.h"
#include "resource.h"
#include "Win32MusicBrowser.h"
#include "DropSource.h"
#include "DropObject.h"

#define kPrePadding 5

BOOL MusicBrowserUI::DrawItem(int32 controlId, DRAWITEMSTRUCT* dis)
{
    BOOL result = TRUE;

    switch(controlId)
    {
        case IDC_PLAYLISTBOX:
        {
            uint32 uiFlags = ILD_TRANSPARENT;
            RECT rcClip;
            HIMAGELIST himl;
            HFONT boldFont = NULL, oldFont = NULL;
            int32 cxImage = 0, cyImage = 0;

            // Get Image List
            himl = ListView_GetImageList(dis->hwndItem, LVSIL_SMALL);
            ImageList_GetIconSize(himl, &cxImage, &cyImage);

            rcClip = dis->rcItem;
        
            HWND hwndList = GetDlgItem(m_hWnd, IDC_PLAYLISTBOX);
            PlaylistItem* item;
            LV_ITEM lv_item;
            string displayString;

            lv_item.mask = LVIF_PARAM;
            lv_item.iItem = dis->itemID;
            lv_item.iSubItem = 0;
            lv_item.lParam = NULL;

            ListView_GetItem(hwndList, &lv_item);

            //item = (PlaylistItem*) lv_item.lParam;
            item = m_plm->ItemAt(dis->itemID);

            if(item == NULL)
                return FALSE;

            // is this the current index? if so make it bold ...
            // btw, we only do this if it is the primary browser
            if(dis->itemID == m_plm->GetCurrentIndex() && !m_pParent)
            {
                LOGFONT lf;

                GetObject(GetWindowFont(hwndList), sizeof(LOGFONT), &lf);

                lf.lfWeight = FW_BOLD;

                boldFont = CreateFontIndirect(&lf);

                oldFont = (HFONT)SelectObject(dis->hDC, boldFont);
            }

            // Item index
            char buf[64];
            sprintf(buf, "%d", dis->itemID + 1);
            displayString = buf;
            
            CalcStringEllipsis(dis->hDC, 
                               displayString, 
                               ListView_GetColumnWidth(hwndList, 0) /*- (cxImage + 1)*/);

			UINT oldAlign;

            oldAlign = SetTextAlign(dis->hDC, TA_CENTER | TA_TOP );

            RECT indexRect = rcClip;

            indexRect.right = indexRect.left + ListView_GetColumnWidth(hwndList, 0) - 1;

            UINT left = indexRect.left + (ListView_GetColumnWidth(hwndList, 0)/2);

            COLORREF scrollColor = GetSysColor(COLOR_SCROLLBAR);
            COLORREF winColor = GetSysColor(COLOR_WINDOW);

            if(scrollColor == winColor)
            {
                int r = GetRValue(scrollColor);
                int g = GetGValue(scrollColor);
                int b = GetBValue(scrollColor);

                if(( r + g + b)/3 < 128)
                {
                    r -= 25;
                    g -= 25;
                    b -= 25;

                    if(r < 0)
                        r = 0;
                    if(g < 0)
                        g = 0;
                    if(b < 0)
                        b = 0;
                }
                else
                {
                    r += 25;
                    g += 25;
                    b += 25;

                    if(r > 255)
                        r = 255;
                    if(g > 255)
                        g = 255;
                    if(b > 255)
                        b = 255;
                }

                SetBkColor(dis->hDC, RGB(r, g, b));
            }
            else
            {
                SetBkColor(dis->hDC, GetSysColor(COLOR_SCROLLBAR)); //COLOR_INFOBK ));
            }
            
            SetTextColor(dis->hDC, GetSysColor(COLOR_WINDOWTEXT)); //COLOR_INFOTEXT));
            

            ExtTextOut( dis->hDC, 
                        left, indexRect.top + 1,
                        ETO_CLIPPED | ETO_OPAQUE,
                        &indexRect, 
                        displayString.c_str(),
                        displayString.size(),
                        NULL);

            SetTextAlign(dis->hDC, oldAlign);

            
            // Move over to the next column
            rcClip.left = indexRect.right; //ListView_GetColumnWidth(hwndList, 0);

            // Check to see if this item is selected
            if(dis->itemState & ODS_SELECTED && GetFocus() == hwndList)
            {
                // Set the text background and foreground colors
                SetTextColor(dis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
                SetBkColor(dis->hDC, GetSysColor(COLOR_HIGHLIGHT));

		        // Also add the ILD_BLEND50 so the images come out selected
		        //uiFlags |= ILD_BLEND50;
            }
            else
            {
                // Set the text background and foreground colors to the
                // standard window colors
                SetTextColor(dis->hDC, GetSysColor(COLOR_WINDOWTEXT));
                SetBkColor(dis->hDC, GetSysColor(COLOR_WINDOW));
            }


            // 
            // Iterate over all the columns that are currently visible,
            // finding the text that should be displayed in that particular
            // slot.
            // Paint the text, and update the paint rect.
            //

            HWND header = ListView_GetHeader(hwndList);
            int nCols   = Header_GetItemCount(header);

            for (int i = 1; i < nCols; i++)
            {
                const char *columnText = GetColumnText(i);
                if (!columnText)
                    break;
 
                if (stricmp(columnText, ARTIST_COLUMN) == 0)
                {
                    displayString = item->GetMetaData().Artist();
                }
                else if ( stricmp( columnText, TITLE_COLUMN ) == 0 )
                {
                    displayString = item->GetMetaData().Title();
                }
                else if ( stricmp( columnText, ALBUM_COLUMN ) == 0 )
                {
                    displayString = item->GetMetaData().Album();
                }
                else if ( stricmp( columnText, LOCATION_COLUMN ) == 0 )
                {

                    char path[_MAX_PATH];
                    uint32 length = sizeof(path);
                    URLToFilePath(item->URL().c_str(), path, &length);
                    displayString = path;
                }
                else if ( stricmp( columnText, TIME_COLUMN ) == 0 )
                {
                    char buf[16];
                    if (item->GetMetaData().Time() != 0)
                    {
                        int32 seconds = item->GetMetaData().Time();
                        int32 hours = seconds / 3600;
                        int32 minutes = seconds / 60 - hours * 60;
                        seconds = seconds - minutes * 60 - hours * 3600;
                           
                        if (hours)
                            sprintf(buf, "%d:%02d:%02d", hours, minutes, seconds);
                        else
                            sprintf(buf, "%d:%02d", minutes, seconds);

                        displayString = buf;
                    }
                }
                else if ( stricmp( columnText, GENRE_COLUMN ) == 0 )
                {
                    displayString = item->GetMetaData().Genre();
                }
                else if ( stricmp( columnText, COMMENT_COLUMN ) == 0 )
                {
                    displayString = item->GetMetaData().Comment();
                }
                else if ( stricmp( columnText, YEAR_COLUMN ) == 0 )
                {
                    char buf[16];
                    int32 year = item->GetMetaData().Year();
                    if (year)
                        sprintf(buf, "%d", year );
                    else
                        sprintf(buf, "Unknown");
                    displayString = buf;
                }
                else if ( stricmp( columnText, TRACK_COLUMN ) == 0 )
                {
                    char buf[16];
                    int32 track = item->GetMetaData().Track();
                    if(track)
                        sprintf(buf, "%d", track );
                    else
                        sprintf(buf, "Unknown");
                    displayString = buf;
                }
                else
                {
                    displayString = "Unknown";
                }
 
                CalcStringEllipsis(dis->hDC,               
                                   displayString, 
                                   ListView_GetColumnWidth(hwndList, i) - kPrePadding);

                ExtTextOut( dis->hDC, 
                            rcClip.left + kPrePadding, rcClip.top + 1, 
                            ETO_CLIPPED | ETO_OPAQUE,
                            &rcClip, 
                            displayString.c_str(),
                            displayString.size(),
                            NULL);            

                // Move over to the next column
                rcClip.left += ListView_GetColumnWidth(hwndList, i);
            }

            break;
        }


    }

    return result;
}

#define LENGTH_COLUMN_WIDTH 60
#define INDEX_COLUMN_WIDTH 25
#define FIXED_COLUMN_WIDTH (LENGTH_COLUMN_WIDTH + INDEX_COLUMN_WIDTH)

void MusicBrowserUI::InitList(void)
{
    m_hPlaylistHeader = FindWindowEx(m_hPlaylistView, NULL, WC_HEADER, NULL);

    if(m_hPlaylistHeader)
    {
        HD_ITEM hd_item;
    
        hd_item.mask = HDI_FORMAT;
        hd_item.fmt = HDF_OWNERDRAW;

        Header_SetItem(m_hPlaylistHeader, 0, &hd_item);
    }

    // First column is always inserted
    InsertColumn("#", 0);

    //
    // Insert the columns that are specified by the user.
    // 

    uint32 size = 100;
    char *buffer = new char[size];
    if (kError_BufferTooSmall == m_context->prefs->GetPrefString(
                                                     kPlaylistHeaderColumnsPref,
                                                     buffer, &size))
    {
        int bufferSize = size;
        delete [] buffer;
        buffer = new char[bufferSize];
        m_context->prefs->GetPrefString(kPlaylistHeaderColumnsPref, buffer, &size);
    }

    int columnN = 1;
    char *token = strtok(buffer, "|");
    while (token != NULL)
    {
        InsertColumn(token, columnN);
        token = strtok(NULL, "|");
        columnN++;
    }

    delete [] buffer;

    if(m_itemsAddedBeforeWeWereCreated)
    {
        for(uint32 i = 0; i < m_itemsAddedBeforeWeWereCreated; i++)
        {
            LV_ITEM lv_item;

            lv_item.mask = 0;
            lv_item.iSubItem = 0;
            lv_item.iItem = 0;

            ListView_InsertItem(m_hPlaylistView, &lv_item);
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -