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

📄 win32preferencewindow.cpp

📁 FreeAMP(MP3播放)程序源代码-用来研究MP3解码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*____________________________________________________________________________
	
	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: Win32PreferenceWindow.cpp,v 1.69 2001/03/06 04:29:21 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

/* system headers */
#include <windows.h>
#include <windowsx.h>
#include <shlwapi.h>
#include <shlobj.h>
#include <commctrl.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>

#include <sstream>
#include <set>

using namespace std;

#include "eventdata.h"
#include "thread.h"
#include "win32updatemanager.h"
#include "Win32PreferenceWindow.h"
#include "Win32Window.h"
#include "help.h"
#include "Debug.h"
#include "player.h"
#include "aps.h"

#define DB Debug_v("%s:%d\n", __FILE__, __LINE__);

static Win32PreferenceWindow *g_pCurrentPrefWindow = NULL;
const char* kThemeFileFilter =
            BRANDING" Themes (.fat)\0"
            "*.fat\0"
            "All Files (*.*)\0"
            "*.*\0";

uint32 CalcStringEllipsis(HDC hdc, string& displayString, int32 columnWidth);

#define UWM_HELP WM_USER + 1

static BOOL CALLBACK 
MainCallback(HWND hwnd, 
             UINT msg, 
             WPARAM wParam, 
             LPARAM lParam)
{
	return g_pCurrentPrefWindow->MainProc(hwnd, msg, wParam, lParam);
}

static BOOL CALLBACK 
PrefGeneralCallback(HWND hwnd, 
                    UINT msg, 
                    WPARAM wParam, 
                    LPARAM lParam)
{
	return g_pCurrentPrefWindow->PrefGeneralProc(hwnd, msg, wParam, lParam);
}

static BOOL CALLBACK 
PrefThemeCallback(HWND hwnd, 
                  UINT msg, 
                  WPARAM wParam, 
                  LPARAM lParam)
{
	return g_pCurrentPrefWindow->PrefThemeProc(hwnd, msg, wParam, lParam);
}

static BOOL CALLBACK 
PrefStreamingCallback(HWND hwnd, 
                      UINT msg, 
                      WPARAM wParam, 
                      LPARAM lParam)
{
	return g_pCurrentPrefWindow->PrefStreamingProc(hwnd, msg, wParam, lParam);
}

static BOOL CALLBACK 
PrefPluginsCallback(HWND hwnd, 
                    UINT msg, 
                    WPARAM wParam, 
                    LPARAM lParam)
{
	return g_pCurrentPrefWindow->PrefPluginsProc(hwnd, msg, wParam, lParam);
}

static BOOL CALLBACK 
PrefUpdateCallback(HWND hwnd, 
                   UINT msg, 
                   WPARAM wParam, 
                   LPARAM lParam)
{
	return g_pCurrentPrefWindow->PrefUpdateProc(hwnd, msg, wParam, lParam);
}

static BOOL CALLBACK 
PrefCDAudioCallback(HWND hwnd, 
                    UINT msg, 
                    WPARAM wParam, 
                    LPARAM lParam)
{
	return g_pCurrentPrefWindow->PrefCDAudioProc(hwnd, msg, wParam, lParam);
}

static BOOL CALLBACK 
PrefAdvancedCallback(HWND hwnd, 
                     UINT msg, 
                     WPARAM wParam, 
                     LPARAM lParam)
{
	return g_pCurrentPrefWindow->PrefAdvancedProc(hwnd, msg, wParam, lParam);
}

static BOOL CALLBACK 
PrefAboutCallback(HWND hwnd, 
                  UINT msg, 
                  WPARAM wParam, 
                  LPARAM lParam)
{
	return g_pCurrentPrefWindow->PrefAboutProc(hwnd, msg, wParam, lParam);
}

static BOOL CALLBACK 
PrefDirectoryCallback(HWND hwnd, 
                  UINT msg, 
                  WPARAM wParam, 
                  LPARAM lParam)
{
	return g_pCurrentPrefWindow->PrefDirectoryProc(hwnd, msg, wParam, lParam);
}   

static BOOL CALLBACK 
PrefDebugCallback(HWND hwnd, 
                  UINT msg, 
                  WPARAM wParam, 
                  LPARAM lParam)
{
	return g_pCurrentPrefWindow->PrefDebugProc(hwnd, msg, wParam, lParam);
}            

static BOOL CALLBACK
PrefProfileCallback(HWND hwnd,
                    UINT msg,
                    WPARAM wParam,
                    LPARAM lParam)
{
       return g_pCurrentPrefWindow->PrefProfileProc(hwnd, msg, wParam, lParam);
}

static BOOL CALLBACK 
PrefBrowserCallback(HWND hwnd, 
                    UINT msg, 
                    WPARAM wParam, 
                    LPARAM lParam)
{
      return g_pCurrentPrefWindow->PrefBrowserProc(hwnd, msg, wParam, lParam);
}

Win32PreferenceWindow::Win32PreferenceWindow(FAContext *context,
                                             ThemeManager *pThemeMan,
                                             UpdateManager *pUpdateMan,
                                             uint32 defaultPage) :
     PreferenceWindow(context, pThemeMan)
{     
	g_pCurrentPrefWindow = this;
    m_defaultPage = defaultPage;
    m_updateManager = (Win32UpdateManager*)pUpdateMan;
    m_prefs = context->prefs;
    deleteUpdateManager = false;
    m_hwndPref = NULL;
    m_startPage = defaultPage;
    m_currentPage = NULL;

    if(!m_updateManager)
    {
        deleteUpdateManager = true;
        m_updateManager = new Win32UpdateManager(m_pContext);
        m_updateManager->DetermineLocalVersions();
        m_updateManager->SetPlatform(string("WIN32"));
#if defined( _M_ALPHA )
        m_updateManager->SetArchitecture(string("ALPHA"));
#else
        m_updateManager->SetArchitecture(string("X86"));
#endif
    }
}

Win32PreferenceWindow::~Win32PreferenceWindow(void)
{
	g_pCurrentPrefWindow = NULL;
} 

bool Win32PreferenceWindow::Show(Window *pWindow)
{
	HWND hWnd;
    
    hWnd = ((Win32Window *)pWindow)->GetWindowHandle(); 
    return DisplayPreferences(hWnd);
}

bool Win32PreferenceWindow::DisplayPreferences(HWND hwndParent)
{
    bool result = false;
    HINSTANCE hinst = (HINSTANCE)GetWindowLong(hwndParent, GWL_HINSTANCE);

    PrefPage page;

    page.hInstance = hinst;
    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_GENERAL);
    page.pfnDlgProc = PrefGeneralCallback;
    page.bChild = false;
    page.lParam = 0;
    page.hwnd = NULL;
    
    m_pages.push_back(page);

    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_THEME);
    page.pfnDlgProc = PrefThemeCallback;
    m_pages.push_back(page);

    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_DIRECTORY);
    page.pfnDlgProc = PrefDirectoryCallback;
    m_pages.push_back(page);

    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_STREAMING);
    page.pfnDlgProc = PrefStreamingCallback;
    m_pages.push_back(page);

    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_PLUGINS);
    page.pfnDlgProc = PrefPluginsCallback;
    m_pages.push_back(page);

    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_CDAUDIO);
    page.pfnDlgProc = PrefCDAudioCallback;
    m_pages.push_back(page);

    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_UPDATE);
    page.pfnDlgProc = PrefUpdateCallback;
    m_pages.push_back(page);

    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_ADVANCED);
    page.pfnDlgProc = PrefAdvancedCallback;
    m_pages.push_back(page);

    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_PROFILE);
    page.pfnDlgProc = PrefProfileCallback;
    m_pages.push_back(page);

    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_BROWSER);
    page.pfnDlgProc = PrefBrowserCallback;
    m_pages.push_back(page);

    page.pszTemplate = MAKEINTRESOURCE(IDD_PREF_ABOUT);
    page.pfnDlgProc = PrefAboutCallback;
    m_pages.push_back(page);
        
    GetPrefsValues(&m_originalValues);
    GetPrefsValues(&m_currentValues);
    GetPrefsValues(&m_proposedValues);

    result = (DialogBox(hinst, 
                        MAKEINTRESOURCE(IDD_MAIN_PREF_DIALOG),
                        hwndParent,
                        MainCallback) > 0);

    if(deleteUpdateManager)
        delete m_updateManager;

    return result;
}

void Win32PreferenceWindow::GetPrefsValues(PrefsStruct* values)
{
    uint32 bufferSize = 1;
    uint32 size;

    // get the string prefs
    char* buffer = (char*)malloc(bufferSize);

    size = bufferSize;

    if(kError_BufferTooSmall == m_prefs->GetPrefString(kPMOPref, buffer, &size))
    {
        bufferSize = size;
        buffer = (char*)realloc(buffer, bufferSize);
        m_prefs->GetPrefString(kPMOPref, buffer, &size);
    }

    values->defaultPMO = buffer;
    size = bufferSize;

    if(kError_BufferTooSmall == m_prefs->GetPrefString(kUIPref, buffer, &size))
    {
        bufferSize = size;
        buffer = (char*)realloc(buffer, bufferSize);
        m_prefs->GetPrefString(kUIPref, buffer, &size);
    }
    
    values->defaultUI = buffer;
    size = bufferSize;

    if(kError_BufferTooSmall == m_prefs->GetPrefString(kProxyHostPref, buffer, &size))
    {
        bufferSize = size;
        buffer = (char*)realloc(buffer, bufferSize);
        m_prefs->GetPrefString(kProxyHostPref, buffer, &size);
    }

    values->proxyServer = buffer;
    size = bufferSize;

    if(kError_BufferTooSmall == m_prefs->GetPrefString(kSaveStreamsDirPref, buffer, &size))
    {
        bufferSize = size;
        buffer = (char*)realloc(buffer, bufferSize);
        m_prefs->GetPrefString(kSaveStreamsDirPref, buffer, &size);
    }

    values->saveStreamsDirectory = buffer;
    size = bufferSize;

    if(kError_BufferTooSmall == m_prefs->GetPrefString(kAlternateNICAddressPref, buffer, &size))
    {
        bufferSize = size;
        buffer = (char*)realloc(buffer, bufferSize);
        m_prefs->GetPrefString(kAlternateNICAddressPref, buffer, &size);
    }

    values->alternateIP = buffer;
    size = bufferSize;

    if(kError_BufferTooSmall == m_prefs->GetPrefString(kThemeDefaultFontPref, buffer, &size))
    {
        bufferSize = size;
        buffer = (char*)realloc(buffer, bufferSize);
        m_prefs->GetPrefString(kThemeDefaultFontPref, buffer, &size);
    }

    values->defaultFont = buffer;
    size = bufferSize;

    if(kError_BufferTooSmall == m_prefs->GetPrefString(kPlaylistHeaderColumnsPref, buffer, &size))
    {
        bufferSize = size;
        buffer = (char*)realloc(buffer, bufferSize);
        m_prefs->GetPrefString(kPlaylistHeaderColumnsPref, buffer, &size);
    }

    values->playlistHeaderColumns = buffer;
    size = bufferSize;

    if(kError_BufferTooSmall == m_prefs->GetPrefString(kSaveMusicDirPref, buffer, &size))
    {
        bufferSize = size;
        buffer = (char*)realloc(buffer, bufferSize);
        m_prefs->GetPrefString(kSaveMusicDirPref, buffer, &size);
    }

    values->saveMusicDirectory = buffer;
    size = bufferSize;

    if(kError_BufferTooSmall == m_prefs->GetPrefString(kMBServerPref, buffer, &size))
    {
        bufferSize = size;
        buffer = (char*)realloc(buffer, bufferSize);
        m_prefs->GetPrefString(kMBServerPref, buffer, &size);
    }

    values->MBServerURL = buffer;
    size = bufferSize;

    if(kError_BufferTooSmall == m_prefs->GetPrefString(kUsersPortablePlayersPref, buffer, &size))

⌨️ 快捷键说明

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