Leaked source code of windows server 2003
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.

587 lines
15 KiB

  1. /*---------------------------------------------------------------------------
  2. **
  3. **-------------------------------------------------------------------------*/
  4. #include <pch.h>
  5. #include "dibutil.h"
  6. #include "billbrd.h"
  7. #include "animate.h"
  8. const UINT uiIDSteps[] = {
  9. IDS_STEP1,
  10. IDS_STEP2,
  11. IDS_STEP3,
  12. IDS_STEP4,
  13. IDS_STEP5 };
  14. int g_iCurrentStep = 1;
  15. HFONT g_hfont = NULL;
  16. HFONT g_hfontBold = NULL;
  17. TCHAR g_szBuffer[MAX_STRING];
  18. int GetStepText(int nStep, LPTSTR lpStr);
  19. int PaintStepsText(HDC hdc, RECT rc);
  20. BOOL GetStepsHeight(
  21. IN UINT cxScreen,
  22. IN UINT cyScreen,
  23. IN RECT rcSteps,
  24. OUT UINT* pcyBottom)
  25. {
  26. HDC hdcMem = NULL;
  27. HDC hdcScreen = NULL;
  28. HBITMAP hbmpMem = NULL;
  29. BOOL bRet = FALSE;
  30. hdcScreen = GetDC(NULL);
  31. if (hdcScreen)
  32. {
  33. hdcMem = CreateCompatibleDC(hdcScreen);
  34. hbmpMem = CreateCompatibleBitmap(hdcScreen,
  35. cxScreen,
  36. cyScreen);
  37. if (hdcMem && hbmpMem)
  38. {
  39. SelectObject(hdcMem, hbmpMem);
  40. *pcyBottom = (UINT) PaintStepsText(hdcMem, rcSteps);
  41. bRet = TRUE;
  42. }
  43. if (hbmpMem)
  44. {
  45. DeleteObject(hbmpMem);
  46. }
  47. if (hdcMem)
  48. {
  49. DeleteDC(hdcMem);
  50. }
  51. ReleaseDC(NULL, hdcScreen);
  52. }
  53. return bRet;
  54. }
  55. /*****************************************************************************
  56. * GetInfoBarFontHeight
  57. *
  58. * Export this function to facilities size estimation of g_hwndSteps.
  59. *
  60. ******************************************************************************/
  61. int GetInfoBarFontHeight()
  62. {
  63. int iInfobarRegularFontSize = 0;
  64. int idsInfobarFontSize;
  65. int iScreenSize;
  66. TCHAR szBuf[25];
  67. BB_ASSERT(g_hInstance != NULL);
  68. iScreenSize = GetSystemMetrics(SM_CXSCREEN);
  69. if(iScreenSize >= 1024)
  70. {
  71. idsInfobarFontSize = IDS_INFOFONTSIZE_1024;
  72. iInfobarRegularFontSize = UI_INFOBAR_FONT_SIZE_1024;
  73. }
  74. else if(iScreenSize == 800)
  75. {
  76. idsInfobarFontSize = IDS_INFOFONTSIZE_800;
  77. iInfobarRegularFontSize = UI_INFOBAR_FONT_SIZE_800;
  78. }
  79. else
  80. {
  81. idsInfobarFontSize = IDS_INFOFONTSIZE_640;
  82. iInfobarRegularFontSize = UI_INFOBAR_FONT_SIZE_640;
  83. }
  84. if (LoadString(g_hInstance,
  85. idsInfobarFontSize,
  86. szBuf,
  87. sizeof(szBuf)/sizeof(TCHAR)) != 0)
  88. {
  89. iInfobarRegularFontSize = MyAtoI((const TCHAR *)szBuf);
  90. }
  91. return -MulDiv(iInfobarRegularFontSize, 96, 72);
  92. }
  93. /******************************************************************
  94. *
  95. * CreateInfoBarFonts
  96. *
  97. * This function creates two fonts for the infobar based on the
  98. * screen resolution. The fonts are the same size, one is bold
  99. * and the other is normal. These fonts are used throughout infobar.
  100. *
  101. *******************************************************************/
  102. BOOL CreateInfoBarFonts()
  103. {
  104. LOGFONT lf = {0};
  105. TCHAR szSetupFontName[MAX_PATH];
  106. int ifHeight = 0;
  107. ifHeight = GetInfoBarFontHeight();
  108. if (!(LoadString(g_hInstance, IDS_INFOFONTNAME, (LPTSTR)szSetupFontName, MAX_PATH)))
  109. {
  110. lstrcpy(szSetupFontName, TEXT("system"));
  111. }
  112. //Create a font that will be used in the Infobar ui
  113. /*keep font size constant, even with large fonts*/
  114. lf.lfHeight = ifHeight;
  115. lstrcpy(lf.lfFaceName, (LPTSTR)szSetupFontName);
  116. lf.lfItalic = 0;
  117. lf.lfUnderline = 0;
  118. lf.lfStrikeOut = 0;
  119. lf.lfWeight = FW_NORMAL;
  120. lf.lfQuality = PROOF_QUALITY;
  121. #ifdef WINDOWS_THAI
  122. lf.lfCharSet = ANSI_CHARSET; //Thai Textout problem for Infobar font
  123. #else
  124. lf.lfCharSet = g_bCharSet;
  125. #endif
  126. g_hfont = CreateFontIndirect(&lf);
  127. //Create a Bold font
  128. /*keep font size constant, even with large fonts*/
  129. lf.lfHeight = ifHeight;
  130. lstrcpy(lf.lfFaceName, (LPTSTR)szSetupFontName);
  131. lf.lfItalic = 0;
  132. lf.lfUnderline = 0;
  133. lf.lfStrikeOut = 0;
  134. lf.lfWeight = FW_SEMIBOLD;
  135. lf.lfQuality = PROOF_QUALITY;
  136. #ifdef WINDOWS_THAI
  137. lf.lfCharSet = ANSI_CHARSET; //Thai Textout problem for Infobar font
  138. #else
  139. lf.lfCharSet = g_bCharSet;
  140. #endif
  141. g_hfontBold = CreateFontIndirect(&lf);
  142. if(g_hfont && g_hfontBold)
  143. return TRUE;
  144. else
  145. return FALSE;
  146. }
  147. /******************************************************************
  148. *
  149. * DeleteInfoBarFonts()
  150. *
  151. * This function deletes the two global fonts for the infobar.
  152. *
  153. *******************************************************************/
  154. void DeleteInfoBarFonts(void)
  155. {
  156. if(g_hfont)
  157. {
  158. DeleteObject(g_hfont);
  159. g_hfont = NULL;
  160. }
  161. if(g_hfontBold)
  162. {
  163. DeleteObject(g_hfontBold);
  164. g_hfontBold = NULL;
  165. }
  166. }
  167. /**********************************************************************
  168. * PaintStepsText()
  169. *
  170. * Paint the setup steps in the steps window. Highlites the current step.
  171. *
  172. **********************************************************************/
  173. int PaintStepsText(HDC hdc, RECT rc)
  174. {
  175. static TCHAR szSteps[UI_INFOBAR_NUM_STEPS][MAX_STRING];
  176. static int iNumLines[UI_INFOBAR_NUM_STEPS];
  177. static int iMaxNumLines = 1;
  178. static RECT rcSteps = {0, 0, 0, 0};
  179. COLORREF crOld = 0;
  180. int cxStepText;
  181. int cxStepBullet;
  182. int cyStep;
  183. RECT rcStepText;
  184. HFONT hfontOld = NULL;
  185. TEXTMETRIC tm;
  186. BITMAP bm;
  187. HBITMAP hbitmapOn = NULL;
  188. HBITMAP hbitmapOff = NULL;
  189. HBITMAP hbitmapHalf = NULL;
  190. HBITMAP hbitmap = NULL;
  191. int iCurrentStep = 0;
  192. //do gdi stuff
  193. SaveDC(hdc);
  194. SetMapMode(hdc, MM_TEXT);
  195. SetBkMode( hdc, TRANSPARENT );
  196. hbitmapOn = LoadImage(
  197. g_hInstance,
  198. MAKEINTRESOURCE(g_idbSelectedBullet),
  199. IMAGE_BITMAP,
  200. 0,
  201. 0,
  202. LR_DEFAULTCOLOR );
  203. hbitmapOff = LoadImage(
  204. g_hInstance,
  205. MAKEINTRESOURCE(g_idbReleasedBullet),
  206. IMAGE_BITMAP,
  207. 0,
  208. 0,
  209. LR_DEFAULTCOLOR );
  210. hbitmapHalf = LoadImage(
  211. g_hInstance,
  212. MAKEINTRESOURCE(g_idbCurrentBullet),
  213. IMAGE_BITMAP,
  214. 0,
  215. 0,
  216. LR_DEFAULTCOLOR );
  217. // select either one to get the width of the bullets
  218. // assume both type of bullet have same width
  219. hbitmap = (hbitmapOn) ? hbitmapOn : hbitmapOff;
  220. if (hbitmap)
  221. {
  222. GetObject( hbitmap, sizeof(BITMAP), &bm );
  223. }
  224. else
  225. {
  226. bm.bmWidth = 0;
  227. }
  228. crOld = SetTextColor(hdc, g_colStepsTxt);
  229. SelectObject(hdc, g_hfontBold);
  230. GetTextMetrics(hdc, &tm);
  231. if (g_bBiDi)
  232. {
  233. cxStepBullet = rc.right - bm.bmWidth;
  234. cxStepText = 0;
  235. rcStepText.left = rc.left;
  236. rcStepText.right = rc.right - 3 * bm.bmWidth / 2;
  237. rcStepText.top = rc.top;
  238. rcStepText.bottom = rc.bottom;
  239. }
  240. else
  241. {
  242. cxStepBullet = rc.left;
  243. cxStepText = 3 * bm.bmWidth / 2;
  244. rcStepText.left = rc.left;
  245. rcStepText.right = rc.right;
  246. rcStepText.top = rc.top;
  247. rcStepText.bottom = rc.bottom;
  248. }
  249. if (!EqualRect(&rcSteps, &rc))
  250. {
  251. iMaxNumLines = 1;
  252. for (iCurrentStep = 1; iCurrentStep <= UI_INFOBAR_NUM_STEPS; iCurrentStep++)
  253. {
  254. if (!LoadString(g_hInstance, uiIDSteps[iCurrentStep-1],
  255. (LPTSTR)szSteps[iCurrentStep-1], MAX_STRING))
  256. {
  257. szSteps[iCurrentStep-1][0] = TEXT('\0');
  258. }
  259. iNumLines[iCurrentStep-1] =
  260. WrapText(hdc, cxStepText, &rcStepText, szSteps[iCurrentStep-1]);
  261. if (iNumLines[iCurrentStep-1] > iMaxNumLines)
  262. {
  263. iMaxNumLines = iNumLines[iCurrentStep-1];
  264. }
  265. }
  266. for (iCurrentStep = 1; iCurrentStep <= UI_INFOBAR_NUM_STEPS; iCurrentStep++)
  267. {
  268. if (iNumLines[iCurrentStep-1] < iMaxNumLines)
  269. {
  270. TCHAR szStep[MAX_STRING];
  271. INT cchStep;
  272. // ImproveWrap may add a null character to the string.
  273. cchStep = LoadString(g_hInstance, uiIDSteps[iCurrentStep-1],
  274. (LPTSTR)szStep, MAX_STRING - 1);
  275. if (cchStep != 0)
  276. {
  277. ImproveWrap(szSteps[iCurrentStep-1],
  278. &iNumLines[iCurrentStep-1],
  279. szStep,
  280. cchStep);
  281. }
  282. }
  283. }
  284. CopyRect(&rcSteps, &rc);
  285. }
  286. cyStep = rc.top;
  287. for(iCurrentStep = 1; iCurrentStep <= UI_INFOBAR_NUM_STEPS; iCurrentStep++)
  288. {
  289. if(iCurrentStep < g_iCurrentStep)
  290. {
  291. SetTextColor(hdc, g_colStepsMarkTxt);
  292. SelectObject(hdc, g_hfontBold);
  293. hbitmap = hbitmapOn;
  294. }
  295. else if (iCurrentStep == g_iCurrentStep)
  296. {
  297. SetTextColor(hdc, g_colStepsCurrentTxt);
  298. SelectObject(hdc, g_hfontBold);
  299. hbitmap = hbitmapHalf;
  300. }
  301. else
  302. {
  303. SetTextColor(hdc, g_colStepsTxt);
  304. SelectObject(hdc, g_hfont);
  305. hbitmap = hbitmapOff;
  306. }
  307. if(!hbitmap)
  308. {
  309. OutputDebugString(TEXT("Billboard: PaintStepsText failed to load bitmap\r\n"));
  310. }
  311. else
  312. {
  313. DrawTransparentBitmap(
  314. hdc,
  315. hbitmap,
  316. cxStepBullet,
  317. cyStep,
  318. g_colBulletTrans);
  319. }
  320. DrawWrapText(
  321. hdc,
  322. &tm,
  323. 0,
  324. cxStepText,
  325. cyStep,
  326. &rcStepText,
  327. LEFT,
  328. iNumLines[iCurrentStep-1],
  329. szSteps[iCurrentStep-1]);
  330. if (iCurrentStep != UI_INFOBAR_NUM_STEPS)
  331. {
  332. cyStep += tm.tmHeight * (iMaxNumLines + 1);
  333. }
  334. else
  335. {
  336. int inc = tm.tmHeight * iMaxNumLines;
  337. if (inc < bm.bmHeight)
  338. {
  339. cyStep += bm.bmHeight;
  340. }
  341. else
  342. {
  343. cyStep += inc;
  344. }
  345. }
  346. }
  347. if (hbitmapOn)
  348. {
  349. DeleteObject(hbitmapOn);
  350. hbitmapOn = NULL;
  351. }
  352. if (hbitmapOff)
  353. {
  354. DeleteObject(hbitmapOff);
  355. hbitmapOff = NULL;
  356. }
  357. hbitmap = NULL;
  358. RestoreDC(hdc, -1);
  359. SelectObject(hdc, hfontOld); // select the original font back into the DC
  360. SetTextColor(hdc, crOld);
  361. return cyStep;
  362. }
  363. LRESULT CALLBACK InfoBarWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  364. {
  365. switch (msg)
  366. {
  367. case WM_PAINT:
  368. {
  369. PAINTSTRUCT ps;
  370. RECT rc;
  371. HDC hdc;
  372. RECT rcToParent;
  373. HWND hwndParent;
  374. HDC hdcBG;
  375. HDC hdcMem;
  376. HBITMAP hbmpMem;
  377. // try to draw steps without flickle
  378. hdc = BeginPaint(hwnd, &ps);
  379. GetClientRect(hwnd, &rc);
  380. GetRectInParent(hwnd, &rc, &rcToParent);
  381. hdcBG = GetBackgroundBuffer();
  382. hdcMem = CreateCompatibleDC(hdc);
  383. hbmpMem = CreateCompatibleBitmap(hdc, rc.right, rc.bottom);
  384. if (hdcMem && hbmpMem)
  385. {
  386. RECT rcLP;
  387. SelectObject(hdcMem, hbmpMem);
  388. BitBlt(hdcMem,
  389. rc.left,
  390. rc.top,
  391. rc.right - rc.left,
  392. rc.bottom - rc.top,
  393. hdcBG,
  394. rcToParent.left,
  395. rcToParent.top,
  396. SRCCOPY);
  397. CopyRect(&rcLP, &rc);
  398. DPtoLP(hdcMem, (LPPOINT) &rcLP, 2);
  399. PaintStepsText(hdcMem, rcLP);
  400. BitBlt(hdc,
  401. rc.left,
  402. rc.top,
  403. rc.right - rc.left,
  404. rc.bottom - rc.top,
  405. hdcMem,
  406. rc.left,
  407. rc.top,
  408. SRCCOPY);
  409. }
  410. if (hbmpMem != NULL)
  411. {
  412. DeleteObject(hbmpMem);
  413. hbmpMem = NULL;
  414. }
  415. if (hdcMem != NULL) {
  416. DeleteDC(hdcMem);
  417. hdcMem = NULL;
  418. }
  419. EndPaint(hwnd, &ps);
  420. return(0);
  421. }
  422. case WM_SETSTEP:
  423. {
  424. int iPanel;
  425. int ret;
  426. iPanel = (int) lParam;
  427. if (iPanel <= UI_INFOBAR_NUM_STEPS)
  428. {
  429. g_iCurrentStep = iPanel;
  430. ret = 1;
  431. InvalidateRect(hwnd, NULL, FALSE);
  432. UpdateWindow(hwnd);
  433. }
  434. else
  435. {
  436. ret = 0;
  437. }
  438. return ret;
  439. }
  440. case WM_DESTROY:
  441. {
  442. DeleteInfoBarFonts();
  443. return (DefWindowProc(hwnd, msg, wParam, lParam));
  444. }
  445. default:
  446. return DefWindowProc(hwnd, msg, wParam, lParam);
  447. }
  448. return 0;
  449. }
  450. BOOL WINAPI InitInfoBar(HWND hwndParent)
  451. {
  452. WNDCLASS wc;
  453. RECT rc1;
  454. wc.style = (UINT)CS_BYTEALIGNWINDOW;
  455. wc.lpfnWndProc = InfoBarWndProc;
  456. wc.cbClsExtra = 0;
  457. wc.cbWndExtra = 0;
  458. wc.hInstance = g_hInstance;
  459. wc.hIcon = NULL;
  460. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  461. wc.hbrBackground = NULL;
  462. wc.lpszMenuName = NULL;
  463. wc.lpszClassName = g_szStepsClassName;
  464. if (!RegisterClass (&wc))
  465. return FALSE;
  466. GetWindowRect(hwndParent, &rc1);
  467. g_hwndSteps = CreateWindow(
  468. g_szStepsClassName,
  469. TEXT(""),
  470. WS_CHILD,
  471. rc1.left + g_cxSteps,
  472. rc1.top + g_cySteps,
  473. g_cxStepsWidth,
  474. g_cyStepsHeight,
  475. hwndParent,
  476. NULL,
  477. g_hInstance,
  478. NULL );
  479. if (g_hwndSteps == NULL)
  480. {
  481. UnregisterClass(g_szStepsClassName, g_hInstance);
  482. return FALSE;
  483. }
  484. ShowWindow( g_hwndSteps, SW_SHOW );
  485. UpdateWindow( g_hwndSteps );
  486. return TRUE;
  487. }
  488. int GetStepText(int nStep, LPTSTR lpStr)
  489. {
  490. TCHAR szStep[16];
  491. wsprintf(szStep, TEXT("Step%d"), nStep);
  492. return GetPrivateProfileString(TEXT("Steps"), szStep, TEXT(""),
  493. lpStr, MAX_PATH, g_szFileName);
  494. }