📄 win32preferencewindow.cpp
字号:
/*____________________________________________________________________________
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.29 2000/01/14 05:26:15 elrod Exp $
____________________________________________________________________________*/
/* system headers */
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <shlobj.h>
#include <commctrl.h>
#include <stdlib.h>
#include <assert.h>
// 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 <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"
#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);
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
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
PrefDebugCallback(HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
return g_pCurrentPrefWindow->PrefDebugProc(hwnd, msg, wParam, lParam);
}
static int CALLBACK PropSheetProc( HWND hwnd, UINT msg, LPARAM lParam)
{
if(msg == PSCB_INITIALIZED)
{
//DLGTEMPLATE* dlg = (DLGTEMPLATE*)lParam;
//dlg->dwExtendedStyle ^= WS_EX_CONTEXTHELP;
LONG style = GetWindowLong(GetParent(hwnd), GWL_EXSTYLE);
style ^= WS_EX_CONTEXTHELP;
SetWindowLong(GetParent(hwnd), GWL_EXSTYLE, style);
}
return 0;
}
Win32PreferenceWindow::Win32PreferenceWindow(FAContext *context,
ThemeManager *pThemeMan,
UpdateManager *pUpdateMan,
uint32 defaultPage) :
PreferenceWindow(context, pThemeMan)
{
g_pCurrentPrefWindow = this;
m_defaultPage = defaultPage;
m_pUpdateManager = pUpdateMan;
}
Win32PreferenceWindow::~Win32PreferenceWindow(void)
{
g_pCurrentPrefWindow = NULL;
}
bool Win32PreferenceWindow::Show(Window *pWindow)
{
HWND hWnd;
hWnd = ((Win32Window *)pWindow)->GetWindowHandle();
return DisplayPreferences(hWnd, m_pContext->prefs);
}
bool Win32PreferenceWindow::DisplayPreferences(HWND hwndParent, Preferences* prefs)
{
bool result = false;
PROPSHEETPAGE psp[7];
PROPSHEETHEADER psh;
HINSTANCE hinst = (HINSTANCE)GetWindowLong(hwndParent, GWL_HINSTANCE);
psp[0].dwSize = sizeof(PROPSHEETPAGE);
psp[0].dwFlags = PSP_HASHELP;
psp[0].hInstance = hinst;
psp[0].pszTemplate = MAKEINTRESOURCE(IDD_PREF_GENERAL);
psp[0].pszIcon = NULL;
psp[0].pfnDlgProc = PrefGeneralCallback;
psp[0].pszTitle = NULL;
psp[0].lParam = (LPARAM)prefs;
psp[1].dwSize = sizeof(PROPSHEETPAGE);
psp[1].dwFlags = PSP_HASHELP;
psp[1].hInstance = hinst;
psp[1].pszTemplate = MAKEINTRESOURCE(IDD_PREF_THEME);
psp[1].pszIcon = NULL;
psp[1].pfnDlgProc = PrefThemeCallback;
psp[1].pszTitle = NULL;
psp[1].lParam = (LPARAM)prefs;
psp[2].dwSize = sizeof(PROPSHEETPAGE);
psp[2].dwFlags = PSP_HASHELP;
psp[2].hInstance = hinst;
psp[2].pszTemplate = MAKEINTRESOURCE(IDD_PREF_STREAMING);
psp[2].pszIcon = NULL;
psp[2].pfnDlgProc = PrefStreamingCallback;
psp[2].pszTitle = NULL;
psp[2].lParam = (LPARAM)prefs;
psp[3].dwSize = sizeof(PROPSHEETPAGE);
psp[3].dwFlags = PSP_HASHELP;
psp[3].hInstance = hinst;
psp[3].pszTemplate = MAKEINTRESOURCE(IDD_PREF_PLUGINS);
psp[3].pszIcon = NULL;
psp[3].pfnDlgProc = PrefPluginsCallback;
psp[3].pszTitle = NULL;
psp[3].lParam = (LPARAM)prefs;
UpdateManager* updateManager = NULL;
if(!m_pUpdateManager)
{
updateManager = new Win32UpdateManager(m_pContext);
updateManager->DetermineLocalVersions();
updateManager->SetPlatform(string("WIN32"));
#if defined( _M_ALPHA )
updateManager->SetArchitecture(string("ALPHA"));
#else
updateManager->SetArchitecture(string("X86"));
#endif
}
else
{
updateManager = m_pUpdateManager;
}
psp[4].dwSize = sizeof(PROPSHEETPAGE);
psp[4].dwFlags = PSP_HASHELP;
psp[4].hInstance = hinst;
psp[4].pszTemplate = MAKEINTRESOURCE(IDD_PREF_UPDATE);
psp[4].pszIcon = NULL;
psp[4].pfnDlgProc = PrefUpdateCallback;
psp[4].pszTitle = NULL;
psp[4].lParam = (LPARAM)updateManager;
psp[5].dwSize = sizeof(PROPSHEETPAGE);
psp[5].dwFlags = PSP_HASHELP;
psp[5].hInstance = hinst;
psp[5].pszTemplate = MAKEINTRESOURCE(IDD_PREF_ADVANCED);
psp[5].pszIcon = NULL;
psp[5].pfnDlgProc = PrefAdvancedCallback;
psp[5].pszTitle = NULL;
psp[5].lParam = (LPARAM)prefs;
psp[6].dwSize = sizeof(PROPSHEETPAGE);
psp[6].dwFlags = PSP_HASHELP;
psp[6].hInstance = hinst;
psp[6].pszTemplate = MAKEINTRESOURCE(IDD_PREF_ABOUT);
psp[6].pszIcon = NULL;
psp[6].pfnDlgProc = PrefAboutCallback;
psp[6].pszTitle = NULL;
psp[6].lParam = (LPARAM)prefs;
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_HASHELP;
psh.hwndParent = hwndParent;
psh.hInstance = hinst;
psh.pszIcon = NULL;
psh.pszCaption = BRANDING" Preferences";
psh.nPages = sizeof(psp)/sizeof(PROPSHEETPAGE);
psh.nStartPage = m_defaultPage;
psh.ppsp = psp;
psh.pfnCallback = NULL;
GetPrefsValues(prefs, &m_originalValues);
m_proposedValues = m_currentValues = m_originalValues;
result = (PropertySheet(&psh) > 0);
if(!m_pUpdateManager)
delete updateManager;
return result;
}
void Win32PreferenceWindow::GetPrefsValues(Preferences* prefs,
PrefsStruct* values)
{
uint32 bufferSize = 1;
uint32 size;
// get the string prefs
char* buffer = (char*)malloc(bufferSize);
size = bufferSize;
if(kError_BufferTooSmall == prefs->GetDefaultPMO(buffer, &size))
{
bufferSize = size;
buffer = (char*)realloc(buffer, bufferSize);
prefs->GetDefaultPMO(buffer, &size);
}
values->defaultPMO = buffer;
size = bufferSize;
if(kError_BufferTooSmall == prefs->GetDefaultUI(buffer, &size))
{
bufferSize = size;
buffer = (char*)realloc(buffer, bufferSize);
prefs->GetDefaultUI(buffer, &size);
}
values->defaultUI = buffer;
size = bufferSize;
if(kError_BufferTooSmall == prefs->GetProxyServerAddress(buffer, &size))
{
bufferSize = size;
buffer = (char*)realloc(buffer, bufferSize);
prefs->GetProxyServerAddress(buffer, &size);
}
values->proxyServer = buffer;
size = bufferSize;
if(kError_BufferTooSmall == prefs->GetSaveStreamsDirectory(buffer, &size))
{
bufferSize = size;
buffer = (char*)realloc(buffer, bufferSize);
prefs->GetSaveStreamsDirectory(buffer, &size);
}
values->saveStreamsDirectory = buffer;
size = bufferSize;
if(kError_BufferTooSmall == prefs->GetAlternateNICAddress(buffer, &size))
{
bufferSize = size;
buffer = (char*)realloc(buffer, bufferSize);
prefs->GetAlternateNICAddress(buffer, &size);
}
values->alternateIP = buffer;
size = bufferSize;
if(kError_BufferTooSmall == prefs->GetThemeDefaultFont(buffer, &size))
{
bufferSize = size;
buffer = (char*)realloc(buffer, bufferSize);
prefs->GetThemeDefaultFont(buffer, &size);
}
values->defaultFont = buffer;
size = bufferSize;
if(kError_BufferTooSmall == prefs->GetSaveMusicDirectory(buffer, &size))
{
bufferSize = size;
buffer = (char*)realloc(buffer, bufferSize);
prefs->GetSaveMusicDirectory(buffer, &size);
}
values->saveMusicDirectory = buffer;
size = bufferSize;
if(kError_BufferTooSmall == prefs->GetUsersPortablePlayers(buffer, &size))
{
bufferSize = size;
buffer = (char*)realloc(buffer, bufferSize);
prefs->GetUsersPortablePlayers(buffer, &size);
}
char* cp = buffer;
char* name = cp;
while(cp = strchr(cp, ';'))
{
*cp = 0x00;
values->portablePlayers.insert(string(name));
//MessageBox(NULL, name, "name", MB_OK);
cp++;
name = cp;
}
if(*name)
{
values->portablePlayers.insert(string(name));
//MessageBox(NULL, name, "name", MB_OK);
}
//values->portablePlayers = buffer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -