00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "vmsSkinMgr.h"
00009
00010 #ifdef _DEBUG
00011 #undef THIS_FILE
00012 static char THIS_FILE[]=__FILE__;
00013 #define new DEBUG_NEW
00014 #endif
00015
00016 vmsSkinMgr::vmsSkinMgr()
00017 {
00018 }
00019
00020 vmsSkinMgr::~vmsSkinMgr()
00021 {
00022
00023 }
00024
00025 void vmsSkinMgr::Scan()
00026 {
00027 m_vList.clear ();
00028
00029 CString strSkinDir = "Skins";
00030
00031 WIN32_FIND_DATA wfd;
00032 HANDLE hFind = FindFirstFile (strSkinDir + "\\*.*", &wfd);
00033 if (hFind == INVALID_HANDLE_VALUE)
00034 return;
00035
00036 do
00037 {
00038 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00039 {
00040 if (lstrcmp (wfd.cFileName, ".") && lstrcmp (wfd.cFileName, ".."))
00041 {
00042
00043 Scan_TryFolder (strSkinDir + "\\" + wfd.cFileName);
00044 }
00045 }
00046 }
00047 while (FindNextFile (hFind, &wfd));
00048
00049 FindClose (hFind);
00050 }
00051
00052 void vmsSkinMgr::Scan_TryFolder(LPCSTR pszFolder)
00053 {
00054 CFile file;
00055 CString strIni = pszFolder;
00056 strIni += "\\skin.ini";
00057
00058 if (GetFileAttributes (strIni) == DWORD (-1))
00059 return;
00060
00061 char szValues [30000] = "";
00062 GetPrivateProfileSection ("Skin", szValues, sizeof (szValues), strIni);
00063 if (*szValues == 0)
00064 return;
00065
00066 vmsSkinInfo skin;
00067 skin.strSkinFolder = pszFolder;
00068
00069 LPCSTR pszValue = szValues;
00070
00071 while (*pszValue)
00072 {
00073 LPSTR pszVVal = strchr (pszValue, '=');
00074 *pszVVal = 0;
00075 pszVVal++;
00076
00077 if (lstrcmpi (pszValue, "Name") == 0)
00078 skin.strName = pszVVal;
00079
00080 else if (lstrcmpi (pszValue, "tbSizeX") == 0)
00081 skin.tbSizeX = atoi (pszVVal);
00082
00083 else if (lstrcmpi (pszValue, "tbSizeY") == 0)
00084 skin.tbSizeY = atoi (pszVVal);
00085
00086 else if (lstrcmpi (pszValue, "tbUseAlpha") == 0)
00087 skin.tbUseAlpha = lstrcmpi (pszVVal, "yes") == 0;
00088
00089 else if (lstrcmpi (pszValue, "fdmBuild") == 0)
00090 skin.nFDMBuild = atoi (pszVVal);
00091
00092 pszValue = pszVVal;
00093 while (*pszValue++);
00094 }
00095
00096 if (skin.nFDMBuild < 425 || skin.nFDMBuild > PRG_BUILD_NUMBER)
00097 return;
00098
00099 m_vList.add (skin);
00100 }
00101
00102 void vmsSkinMgr::set_CurrentSkin(int iSkin)
00103 {
00104 m_nCurrSkin = iSkin;
00105 }
00106
00107 HBITMAP vmsSkinMgr::bmp_x(UINT nID, LPCSTR pszName)
00108 {
00109 if ((m_dwFlags & SM_ALLOWBITMAPS) == 0)
00110 pszName = NULL;
00111
00112 if (m_nCurrSkin == -1 || pszName == NULL)
00113 return (HBITMAP)
00114 LoadImage (m_hInst, MAKEINTRESOURCE (nID), IMAGE_BITMAP,
00115 0, 0, LR_CREATEDIBSECTION);
00116
00117 HBITMAP hbm = (HBITMAP)
00118 LoadImage (NULL, m_vList [m_nCurrSkin].strSkinFolder + "\\" + pszName + ".bmp",
00119 IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
00120
00121 return hbm ? hbm : bmp_x (nID, NULL);
00122 }
00123
00124 HBITMAP vmsSkinMgr::bmp(UINT nID)
00125 {
00126 static UINT aIDs [] = {
00127 IDB_BACK, IDB_BACK_D, IDB_CHECKS, IDB_DOWNLOADSTASKS_SEL,
00128 IDB_DOWNLOADSTASKS, IDB_DOWNLOADSINFO, IDB_FILELIST,
00129 IDB_FILELIST_SEL, IDB_GO, IDB_GROUPS, IDB_GROUPSMENU_D,
00130 IDB_GROUPSMENU, IDB_LOGSTATES, IDB_MUTE, IDB_SCHEDULER_SEL,
00131 IDB_SHEDULER, IDB_SITELIST, IDB_SITELIST_SEL,
00132 IDB_TOOL0, IDB_TOOL0_16, IDB_TOOL0_16_D, IDB_TOOL0_D,
00133 IDB_TOOL_DLDS, IDB_TOOL_DLDS_D, IDB_TOOL_DLD_16, IDB_TOOL_DLD_16_D,
00134 IDB_TOOL_HFE, IDB_TOOL_HFE_D, IDB_TOOL_HFE_16, IDB_TOOL_HFE_16_D,
00135 IDB_TOOL_SCHEDULE, IDB_TOOL_SCHEDULE_D, IDB_TOOL_SCH_16, IDB_TOOL_SCH_16_D,
00136 IDB_TOOL_SITES, IDB_TOOL_SITES_D, IDB_TOOL_SITES_16, IDB_TOOL_SITES_16_D,
00137 IDB_TOOL_SPIDER, IDB_TOOL_SPIDER_D, IDB_TOOL_SPIDER_16, IDB_TOOL_SPIDER_16_D,
00138 IDB_VIDMAN, IDB_VIDMAN_D
00139 };
00140
00141 static LPCSTR ppszNames [] = {
00142 "back", "back_d", "checks", "dldtasks_sel", "dldtasks",
00143 "dlinfo", "filelist", "filelist_sel", "go", "groups",
00144 "groupsmenu_d", "groupsmenu", "logstat", "mute",
00145 "scheduler_sel", "scheduler", "sitelist", "sitelist_sel",
00146 "tool0", "tool0_small", "tool0_small_d", "tool0_d",
00147 "tool_dld", "tool_dld_d", "tool_dld_small", "tool_dld_small_d",
00148 "tool_hfe", "tool_hfe_d", "tool_hfe_small", "tool_hfe_small_d",
00149 "tool_sch", "tool_sch_d", "tool_sch_small", "tool_sch_small_d",
00150 "tool_sites", "tool_sites_d", "tool_sites_small", "tool_sites_small_d",
00151 "tool_spider", "tool_spider_d", "tool_spider_small", "tool_spider_small_d",
00152 "vidman", "vidman_d"
00153 };
00154
00155 ASSERT (sizeof (aIDs)/sizeof (UINT) == sizeof (ppszNames)/sizeof (LPCSTR));
00156
00157 for (int i = 0; i < sizeof (aIDs) / sizeof (UINT); i++)
00158 {
00159 if (aIDs [i] == nID)
00160 return bmp_x (nID, ppszNames [i]);
00161 }
00162
00163 return bmp_x (nID, NULL);
00164 }
00165
00166 void vmsSkinMgr::Initialize()
00167 {
00168 m_nCurrSkin = -1;
00169 m_hInst = AfxGetInstanceHandle ();
00170 m_dwFlags = _App.Skin_Flags ();
00171 Scan ();
00172 CString strSkin = _App.Skin_Current ();
00173 if (strSkin != "")
00174 {
00175 for (int i = 0; i < m_vList.size (); i++)
00176 {
00177 if (m_vList [i].strName.CompareNoCase (strSkin) == 0)
00178 {
00179 m_nCurrSkin = i;
00180 break;
00181 }
00182 }
00183 }
00184 }
00185
00186 int vmsSkinMgr::tbSizeX()
00187 {
00188 return m_nCurrSkin == -1 || (m_dwFlags & SM_ALLOWBITMAPS) == 0 ? 32 : m_vList [m_nCurrSkin].tbSizeX;
00189 }
00190
00191 int vmsSkinMgr::tbSizeY()
00192 {
00193 return m_nCurrSkin == -1 || (m_dwFlags & SM_ALLOWBITMAPS) == 0 ? 32 : m_vList [m_nCurrSkin].tbSizeY;
00194 }
00195
00196 BOOL vmsSkinMgr::tbUseAlpha()
00197 {
00198 return m_nCurrSkin == -1 || (m_dwFlags & SM_ALLOWBITMAPS) == 0 ? TRUE : m_vList [m_nCurrSkin].tbUseAlpha;
00199 }
00200
00201 HICON vmsSkinMgr::icon(UINT nID, int cx, int cy)
00202 {
00203 static UINT aIDs [] = {
00204 IDI_CHOOSEFOLDER, IDI_CREATEGROUP, IDI_LOGO2, IDI_LOGIN,
00205 IDI_SETTIME, IDI_TOSEL, IDI_TOUNSEL,
00206 IDI_TRAY, IDI_TRAY_DOWNLOADING, IDI_TRAY_ERRORS,IDI_TRAY_UNKNOWN,
00207 IDI_TEST_OK,
00208 };
00209
00210 static LPCSTR ppszNames [] = {
00211 "choosefolder", "creategroup", "dropbox", "login", "settime",
00212 "tosel", "tounsel",
00213 "tray", "tray_down", "tray_err", "tray_starting",
00214 "check_ok",
00215 };
00216
00217 ASSERT (sizeof (aIDs)/sizeof (UINT) == sizeof (ppszNames)/sizeof (LPCSTR));
00218
00219 for (int i = 0; i < sizeof (aIDs) / sizeof (UINT); i++)
00220 {
00221 if (aIDs [i] == nID)
00222 return icon_x (nID, ppszNames [i], cx, cy);
00223 }
00224
00225 return icon_x (nID, NULL, cx, cy);
00226 }
00227
00228 HICON vmsSkinMgr::icon_x(UINT nID, LPCSTR pszName, int cx, int cy)
00229 {
00230 if ((m_dwFlags & SM_ALLOWICONS) == 0)
00231 pszName = NULL;
00232
00233 if (m_nCurrSkin == -1 || pszName == NULL)
00234 return (HICON)
00235 LoadIcon (m_hInst, MAKEINTRESOURCE (nID));
00236
00237 HICON hico = (HICON)
00238 LoadImage (NULL, m_vList [m_nCurrSkin].strSkinFolder + "\\" + pszName + ".ico",
00239 IMAGE_ICON, cx, cy, LR_LOADFROMFILE);
00240
00241 return hico ? hico : icon_x (nID, NULL, cx, cy);
00242 }
00243
00244 int vmsSkinMgr::get_Count()
00245 {
00246 return m_vList.size ();
00247 }
00248
00249 int vmsSkinMgr::get_Current()
00250 {
00251 return m_nCurrSkin;
00252 }
00253
00254 vmsSkinInfo* vmsSkinMgr::get_Skin(int iIndex)
00255 {
00256 return &m_vList [iIndex];
00257 }
00258
00259 BOOL vmsSkinMgr::tbUseAlpha_ForAllPluginMenuImages()
00260 {
00261 return m_nCurrSkin != -1 && tbUseAlpha ();
00262 }