Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

495 lines
14 KiB

  1. //////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. // rescache.cpp --- Implementation file for CResourceCache
  5. //
  6. //
  7. /*
  8. */
  9. //////////////////////////////////////////////////////////////////////////
  10. //
  11. // Includes
  12. //
  13. #include "header.h"
  14. // String Ids.
  15. #include "strtable.h"
  16. // Resource IDs
  17. #include "resource.h"
  18. //Our header
  19. //#include "rescache.h"
  20. //////////////////////////////////////////////////////////////////////////
  21. //
  22. // Globals
  23. //
  24. CResourceCache _Resource ;
  25. //////////////////////////////////////////////////////////////////////////
  26. //
  27. // CResourceCache
  28. //
  29. //////////////////////////////////////////////////////////////////////////
  30. //
  31. // Constuctor
  32. //
  33. CResourceCache::CResourceCache()
  34. : m_pszMsgBoxTitle(NULL),
  35. m_hUIFontDefault(NULL),
  36. m_hAccel(NULL),
  37. m_bInitTabCtrlKeys(false),
  38. m_hInstRichEdit(0),
  39. m_hUIAccessableFontDefault(NULL)
  40. {
  41. }
  42. //////////////////////////////////////////////////////////////////////////
  43. //
  44. // Destruct
  45. //
  46. CResourceCache::~CResourceCache()
  47. {
  48. CHECK_AND_FREE( m_pszMsgBoxTitle );
  49. if ( m_hUIAccessableFontDefault && (m_hUIAccessableFontDefault != m_hUIFontDefault) )
  50. {
  51. DeleteObject(m_hUIAccessableFontDefault);
  52. }
  53. if (m_hUIFontDefault)
  54. {
  55. DeleteObject(m_hUIFontDefault);
  56. }
  57. // Get rid of our accelerator table.
  58. if (m_hAccel)
  59. {
  60. DestroyAcceleratorTable(m_hAccel);
  61. }
  62. if (m_hInstRichEdit)
  63. {
  64. FreeLibrary(m_hInstRichEdit);
  65. }
  66. }
  67. //////////////////////////////////////////////////////////////////////////
  68. //
  69. // Initialization Functions
  70. //
  71. //////////////////////////////////////////////////////////////////////////
  72. //
  73. // InitMsgBoxTitle
  74. //
  75. void
  76. CResourceCache::InitMsgBoxTitle()
  77. {
  78. ASSERT(m_pszMsgBoxTitle == NULL) ;
  79. m_pszMsgBoxTitle = lcStrDup(GetStringResource(IDS_MSGBOX_TITLE));
  80. }
  81. /////////////////////////////////////////////////////////////////////////
  82. //
  83. // Init the RichEdit control if we need it.
  84. //
  85. void
  86. CResourceCache::InitRichEdit()
  87. {
  88. if ( (m_hInstRichEdit == 0) && (GetVersion() > 0x80000000) )
  89. m_hInstRichEdit = LoadLibrary("riched20.dll");
  90. }
  91. //////////////////////////////////////////////////////////////////////////
  92. //
  93. // InitAcceleratorTable
  94. //
  95. void
  96. CResourceCache::InitAcceleratorTable()
  97. {
  98. // Create the accelerator table.
  99. ASSERT(m_hAccel == NULL) ;
  100. m_hAccel = LoadAccelerators(_Module.GetResourceInstance(), MAKEINTRESOURCE(HH_ACCELERATORS));
  101. ASSERT(m_hAccel) ;
  102. }
  103. #if 0
  104. //////////////////////////////////////////////////////////////////////////
  105. //
  106. // InitDefaultFont
  107. //
  108. void
  109. CResourceCache::InitDefaultFont(HDC hDC, HFONT* phFont)
  110. {
  111. HFONT hFont;
  112. if (! phFont )
  113. {
  114. ASSERT(m_hfontDefault == NULL) ;
  115. if ( m_hfontDefault )
  116. return;
  117. }
  118. // Create a default font from our resource file
  119. int dyHeight = 0;
  120. PSTR pszFontName = (PSTR) GetStringResource(IDS_DEFAULT_RES_FONT);
  121. HWND hwndDesktop = GetDesktopWindow();
  122. HDC hdc = GetDC(hwndDesktop);
  123. int YAspectMul;
  124. if (!hdc)
  125. {
  126. ASSERT(0) ; //TODO: Fix
  127. return ;
  128. }
  129. // Get current text metrics
  130. TEXTMETRIC tm;
  131. GetTextMetrics(hdc, &tm);
  132. WORD defcharset = (WORD) tm.tmCharSet;
  133. YAspectMul = GetDeviceCaps(hDC?hDC:hdc, LOGPIXELSY);
  134. ReleaseDC(hwndDesktop, hdc);
  135. PSTR pszPoint = StrChr(pszFontName, ',');
  136. if (pszPoint)
  137. {
  138. *pszPoint = '\0';
  139. pszPoint = FirstNonSpace(pszPoint + 1);
  140. if (IsDigit((BYTE) *pszPoint))
  141. {
  142. dyHeight = MulDiv(YAspectMul, Atoi(pszPoint) * 2, 144);
  143. }
  144. }
  145. if (!dyHeight)
  146. dyHeight = YAspectMul / 6;
  147. if(g_langSystem == LANG_RUSSIAN)
  148. defcharset = RUSSIAN_CHARSET;
  149. // For non-localized OCX on DBCS platforms, we need to increase font size by one point
  150. //
  151. if (g_fDBCSSystem && CompareString(LOCALE_SYSTEM_DEFAULT,NORM_IGNORECASE, pszFontName,-1,"Arial",-1) == 2)
  152. dyHeight++; // increase size by one point
  153. if (g_langSystem == LANG_THAI &&
  154. CompareString(LOCALE_SYSTEM_DEFAULT,NORM_IGNORECASE, pszFontName,-1,"Arial",-1) == 2)
  155. {
  156. LONG dyHeightThai = MulDiv(YAspectMul, dyHeight * 2, 144);
  157. hFont = CreateFont(-(dyHeightThai+1), 0, 0, 0, 0, 0, 0, 0,
  158. THAI_CHARSET, OUT_DEFAULT_PRECIS,
  159. CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  160. DEFAULT_PITCH | FF_DONTCARE, "Angsana New"); //"AngsanaUPC");
  161. }
  162. else
  163. if (g_langSystem == LANG_JAPANESE &&
  164. CompareString(LOCALE_SYSTEM_DEFAULT,NORM_IGNORECASE, pszFontName,-1,"Arial",-1) == 2)
  165. {
  166. hFont = CreateFont(-dyHeight, 0, 0, 0, 0, 0, 0, 0,
  167. SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS,
  168. CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  169. VARIABLE_PITCH | FF_MODERN, "MS P-Gothic");
  170. }
  171. else
  172. if (g_langSystem == LANG_CHINESE &&
  173. CompareString(LOCALE_SYSTEM_DEFAULT,NORM_IGNORECASE, pszFontName,-1,"Arial",-1) == 2)
  174. {
  175. hFont = CreateFont(-dyHeight, 0, 0, 0, 0, 0, 0, 0,
  176. defcharset, OUT_DEFAULT_PRECIS,
  177. CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  178. VARIABLE_PITCH | FF_MODERN, "����");
  179. }
  180. else
  181. {
  182. hFont = CreateFont(-dyHeight, 0, 0, 0, 0, 0, 0, 0,
  183. defcharset, OUT_DEFAULT_PRECIS,
  184. CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  185. VARIABLE_PITCH | FF_MODERN, pszFontName);
  186. }
  187. ASSERT(hFont);
  188. if ( phFont )
  189. *phFont = hFont;
  190. else
  191. m_hfontDefault = hFont;
  192. #ifdef _DEBUG
  193. LOGFONT lf ;
  194. int r = GetObject(m_hfontDefault, sizeof(lf), &lf) ;
  195. #endif
  196. }
  197. #endif
  198. //////////////////////////////////////////////////////////////////////////
  199. //
  200. // InitDefaultUIFont
  201. //
  202. // Init the font that will be used to render all strings that come from hhctrl.ocx resources.
  203. //
  204. void
  205. CResourceCache::InitDefaultUIFont(HDC hDC, HFONT* phFont)
  206. {
  207. HFONT hFont;
  208. HDC hdc;
  209. int dyHeight = 0;
  210. int YAspectMul;
  211. WORD CharsetSpec = 0;
  212. WORD DefCharset;
  213. int iFontSpecResID = IDS_DEFAULT_RES_FONT;
  214. PSTR pszFontName;
  215. WCHAR *pwsFontName;
  216. if (! phFont )
  217. {
  218. ASSERT(m_hUIFontDefault == NULL) ;
  219. if ( m_hUIFontDefault )
  220. return;
  221. }
  222. // Create a default font from our resource file. We use a different resource font spec depending
  223. // on OS...
  224. //
  225. OSVERSIONINFO osvi;
  226. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  227. GetVersionEx(&osvi);
  228. #ifdef _DEBUG
  229. char* sz1, *sz2, *sz3;
  230. char szBuf[256];
  231. char szBuf2[256];
  232. if ( (GetKeyState(VK_SHIFT) < 0) )
  233. {
  234. sz1 = (PSTR)GetStringResource(IDS_DEFAULT_RES_FONT_NT5_WIN98);
  235. sz2 = (PSTR)GetStringResource(IDS_DEFAULT_RES_FONT);
  236. if ( _Module.m_Language.LoadSatellite() )
  237. {
  238. LANGID lid = _Module.m_Language.GetUiLanguage();
  239. wsprintf(szBuf2, "Operating from Satalite DLL resources: mui\\%04x", lid);
  240. sz3 = szBuf2;
  241. }
  242. else
  243. sz3 = "Operating from hhctrl.ocx reources";
  244. wsprintf(szBuf, "NT5/Win98 UIFont = %s\nNT4/Win95 UIFont = %s\n%s\n", sz1, sz2, sz3);
  245. MsgBox(szBuf, MB_OK);
  246. }
  247. #endif
  248. if ( (osvi.dwMajorVersion) == 5 || ((osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) && (osvi.dwMinorVersion == 10)) )
  249. iFontSpecResID = IDS_DEFAULT_RES_FONT_NT5_WIN98;
  250. if (g_bWinNT5)
  251. {
  252. if (! (pwsFontName = (WCHAR *) GetStringResourceW(iFontSpecResID)) || *pwsFontName == '\0' )
  253. {
  254. if (! (pwsFontName = (WCHAR *)GetStringResourceW(IDS_DEFAULT_RES_FONT)) || *pwsFontName == '\0' )
  255. pwsFontName = L"MS Shell Dlg,8,0";
  256. }
  257. if (! (hdc = GetDC(NULL)) )
  258. {
  259. ASSERT(0) ;
  260. return ;
  261. }
  262. // Get current text metrics
  263. //
  264. TEXTMETRIC tm;
  265. GetTextMetrics(hdc, &tm);
  266. DefCharset = (WORD) tm.tmCharSet;
  267. YAspectMul = GetDeviceCaps(hDC?hDC:hdc, LOGPIXELSY);
  268. ReleaseDC(NULL, hdc);
  269. WCHAR *pwsComma = StrChrW(pwsFontName, ','); // Get point size specification.
  270. if (pwsComma)
  271. {
  272. *pwsComma = '\0';
  273. pwsComma = FirstNonSpaceW(pwsComma + 1);
  274. if (IsDigit((BYTE) *pwsComma))
  275. {
  276. int hx = _wtoi(pwsComma);
  277. dyHeight = MulDiv(YAspectMul, hx * 2, 144);
  278. }
  279. }
  280. if ( (pwsComma = StrChrW(pwsComma, ',')) ) // Get charset specification.
  281. {
  282. pwsComma = FirstNonSpaceW(pwsComma + 1);
  283. if (iswdigit((BYTE) *pwsComma))
  284. {
  285. // This indicates we are using a satalite DLL which means we want to trust the charset spec.
  286. //
  287. if ( _Module.m_Language.LoadSatellite() )
  288. DefCharset = (CHAR)_wtoi(pwsComma);
  289. }
  290. }
  291. }
  292. else
  293. {
  294. if (! (pszFontName = (PSTR) GetStringResource(iFontSpecResID)) || *pszFontName == '\0' )
  295. {
  296. if (! (pszFontName = (PSTR)GetStringResource(IDS_DEFAULT_RES_FONT)) || *pszFontName == '\0' )
  297. pszFontName = "MS Shell Dlg,8,0";
  298. }
  299. if (! (hdc = GetDC(NULL)) )
  300. {
  301. ASSERT(0) ;
  302. return ;
  303. }
  304. // Get current text metrics
  305. //
  306. TEXTMETRIC tm;
  307. GetTextMetrics(hdc, &tm);
  308. DefCharset = (WORD) tm.tmCharSet;
  309. YAspectMul = GetDeviceCaps(hDC?hDC:hdc, LOGPIXELSY);
  310. ReleaseDC(NULL, hdc);
  311. PSTR pszComma = StrChr(pszFontName, ','); // Get point size specification.
  312. if (pszComma)
  313. {
  314. *pszComma = '\0';
  315. pszComma = FirstNonSpace(pszComma + 1);
  316. if (IsDigit((BYTE) *pszComma))
  317. {
  318. int hx = Atoi(pszComma);
  319. dyHeight = MulDiv(YAspectMul, hx * 2, 144);
  320. }
  321. }
  322. if ( (pszComma = StrChr(pszComma, ',')) ) // Get charset specification.
  323. {
  324. pszComma = FirstNonSpace(pszComma + 1);
  325. if (IsDigit((BYTE) *pszComma))
  326. {
  327. // This indicates we are using a satalite DLL which means we want to trust the charset spec.
  328. //
  329. if ( _Module.m_Language.LoadSatellite() )
  330. DefCharset = (CHAR)Atoi(pszComma);
  331. }
  332. }
  333. }
  334. if (!dyHeight)
  335. dyHeight = YAspectMul / 6;
  336. // Why is this here? We should have the correct defcharset from GetTextMetrics above correct?
  337. //
  338. if( g_langSystem == LANG_RUSSIAN )
  339. DefCharset = RUSSIAN_CHARSET;
  340. NONCLIENTMETRICS ncm;
  341. // If we need to detect non-localized OCX on DBCS platforms, we need can use DefCharset vs CharsetSpec
  342. // to see if they differ. <mikecole>
  343. //
  344. if (g_bWinNT5)
  345. {
  346. hFont = CreateFontW(-dyHeight, 0, 0, 0, 0, 0, 0, 0, DefCharset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  347. DEFAULT_QUALITY, VARIABLE_PITCH | FF_MODERN, pwsFontName);
  348. ncm.cbSize = sizeof(NONCLIENTMETRICS);
  349. BOOL bRet = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), (void*)&ncm, 0);
  350. if ( bRet && (ncm.lfMenuFont.lfHeight < (-dyHeight)) )
  351. {
  352. m_hUIAccessableFontDefault = CreateFontW(ncm.lfMenuFont.lfHeight, 0, 0, 0, 0, 0, 0, 0, DefCharset,
  353. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  354. VARIABLE_PITCH | FF_MODERN, pwsFontName);
  355. }
  356. else
  357. m_hUIAccessableFontDefault = hFont;
  358. }
  359. else
  360. {
  361. hFont = CreateFont(-dyHeight, 0, 0, 0, 0, 0, 0, 0, DefCharset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  362. DEFAULT_QUALITY, VARIABLE_PITCH | FF_MODERN, pszFontName);
  363. ncm.cbSize = sizeof(NONCLIENTMETRICS);
  364. BOOL bRet = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), (void*)&ncm, 0);
  365. if ( bRet && (ncm.lfMenuFont.lfHeight < (-dyHeight)) )
  366. {
  367. m_hUIAccessableFontDefault = CreateFont(ncm.lfMenuFont.lfHeight, 0, 0, 0, 0, 0, 0, 0, DefCharset,
  368. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  369. VARIABLE_PITCH | FF_MODERN, pszFontName);
  370. }
  371. else
  372. m_hUIAccessableFontDefault = hFont;
  373. }
  374. ASSERT(hFont);
  375. if ( phFont )
  376. *phFont = hFont;
  377. else
  378. m_hUIFontDefault = hFont;
  379. #ifdef _DEBUG
  380. LOGFONT lf ;
  381. int r = GetObject(m_hUIFontDefault, sizeof(lf), &lf) ;
  382. #endif
  383. }
  384. //////////////////////////////////////////////////////////////////////////
  385. //
  386. // InitTabCtrlKeys
  387. //
  388. void
  389. CResourceCache::InitTabCtrlKeys()
  390. {
  391. #ifndef CHIINDEX
  392. ASSERT(!m_bInitTabCtrlKeys) ;
  393. // Zero out array
  394. memset(m_TabCtrlKeys, NULL, c_NumTabCtrlKeys);
  395. // Get the accelerators for the standard tabs
  396. PCSTR psz = StrChr(GetStringResource(IDS_TAB_CONTENTS), '&');
  397. if (psz)
  398. m_TabCtrlKeys[HHWIN_NAVTYPE_TOC] = ToLower(psz[1]);
  399. psz = StrChr(GetStringResource(IDS_TAB_INDEX), '&');
  400. if (psz)
  401. m_TabCtrlKeys[HHWIN_NAVTYPE_INDEX] = ToLower(psz[1]);
  402. psz = StrChr(GetStringResource(IDS_TAB_SEARCH), '&');
  403. if (psz)
  404. m_TabCtrlKeys[HHWIN_NAVTYPE_SEARCH] = ToLower(psz[1]);
  405. psz = StrChr(GetStringResource(IDS_TAB_HISTORY), '&');
  406. if (psz)
  407. m_TabCtrlKeys[HHWIN_NAVTYPE_HISTORY] = ToLower(psz[1]);
  408. psz = StrChr(GetStringResource(IDS_TAB_FAVORITES), '&');
  409. if (psz)
  410. m_TabCtrlKeys[HHWIN_NAVTYPE_FAVORITES] = ToLower(psz[1]);
  411. // Get the accelerators for menus and other none tab things.
  412. psz = StrChr(GetStringResource(IDTB_OPTIONS), '&');
  413. if (psz)
  414. m_TabCtrlKeys[ACCEL_KEY_OPTIONS] = ToLower(psz[1]);
  415. // Custom tab keys are initialized when the tabs are loaded.
  416. // Finished initialization
  417. m_bInitTabCtrlKeys = true ;
  418. #endif
  419. }
  420. //////////////////////////////////////////////////////////////////////////
  421. //
  422. // Other Functions
  423. //
  424. //////////////////////////////////////////////////////////////////////////
  425. //
  426. // TabCtrlKeys -- Sets the tab accel keys for custom tabs
  427. //
  428. void
  429. CResourceCache::TabCtrlKeys(int TabIndex, char ch) //Sets an accelerator key. Only used for custom tabs.
  430. {
  431. // Initialize, if needed.
  432. if (!m_bInitTabCtrlKeys)
  433. {
  434. InitTabCtrlKeys() ;
  435. }
  436. if (TabIndex >= HH_TAB_CUSTOM_FIRST && TabIndex <= HH_TAB_CUSTOM_LAST)
  437. {
  438. m_TabCtrlKeys[TabIndex] = ch ;
  439. }
  440. }