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.

508 lines
12 KiB

  1. // Copyright (c) 1997-2000 Microsoft Corporation
  2. // Select.cpp
  3. #include "pch.hxx" // PCH
  4. #pragma hdrstop
  5. #include "pgbase.h"
  6. #include "AccWiz.h"
  7. #include "resource.h"
  8. #include "Select.h"
  9. extern HPALETTE g_hpal3D;
  10. // Re-Write to use owner drawn controls....:a-anilk
  11. //////////////////////////////////////////////////////////////
  12. // CIconSizePg member functions
  13. //
  14. UINT IDMap[3][2] = { 0, IDC_ICON1,
  15. 1, IDC_ICON2,
  16. 2, IDC_ICON3
  17. };
  18. CIconSizePg::CIconSizePg(LPPROPSHEETPAGE ppsp)
  19. : WizardPage(ppsp, IDS_LKPREV_ICONTITLE, IDS_LKPREV_ICONSUBTITLE)
  20. {
  21. m_dwPageId = IDD_PREV_ICON2;
  22. ppsp->pszTemplate = MAKEINTRESOURCE(m_dwPageId);
  23. m_nCountValues = 3;
  24. m_rgnValues[0] = 32;
  25. m_rgnValues[1] = 48;
  26. m_rgnValues[2] = 64;
  27. }
  28. LRESULT CIconSizePg::OnInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
  29. {
  30. // Initialize the current selection..
  31. if(g_Options.m_schemePreview.m_nIconSize <= 32)
  32. m_nCurValueIndex = 0;
  33. else if(g_Options.m_schemePreview.m_nIconSize <= 48)
  34. m_nCurValueIndex = 1;
  35. else
  36. m_nCurValueIndex = 2;
  37. m_nCurrentHilight = m_nCurValueIndex;
  38. return 1;
  39. }
  40. // These is to set the Focus and sync the painting
  41. LRESULT CIconSizePg::OnPSN_SetActive(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  42. {
  43. syncInit = FALSE;
  44. uIDEvent = SetTimer(hwnd, NULL, 100, NULL);
  45. return 0;
  46. }
  47. LRESULT CIconSizePg::OnTimer( HWND hwnd, WPARAM wParam, LPARAM lParam )
  48. {
  49. KillTimer(hwnd, uIDEvent);
  50. syncInit = TRUE;
  51. return 1;
  52. }
  53. // Selection has chnaged, So Apply for preview.
  54. LRESULT CIconSizePg::SelectionChanged(int nNewSelection)
  55. {
  56. g_Options.m_schemePreview.m_nIconSize = m_rgnValues[nNewSelection];
  57. g_Options.ApplyPreview();
  58. return 0;
  59. }
  60. // Re-paints the previous radio control.
  61. void CIconSizePg::InvalidateRects(int PrevHilight)
  62. {
  63. InvalidateRect(GetDlgItem(m_hwnd, IDMap[PrevHilight][1]), NULL, TRUE);
  64. }
  65. // Sets the focus to the current item in OnInitDialog.
  66. void CIconSizePg::SetFocussedItem(int m_nCurrentHilight)
  67. {
  68. SetFocus(GetDlgItem(m_hwnd, IDMap[m_nCurrentHilight][1]));
  69. }
  70. // DrawItem. Handles painting checks the focussed item
  71. // to determine selection changes
  72. LRESULT CIconSizePg::OnDrawItem(HWND hwnd, WPARAM wParam, LPARAM lParam)
  73. {
  74. UINT idCtrl = (UINT) wParam;
  75. LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT) lParam;
  76. int index;
  77. BOOL hasChanged = FALSE;
  78. if ( !syncInit)
  79. SetFocussedItem(m_nCurrentHilight);
  80. switch(idCtrl)
  81. {
  82. case IDC_ICON1:
  83. index = 0;
  84. break;
  85. case IDC_ICON2:
  86. index = 1;
  87. break;
  88. case IDC_ICON3:
  89. index = 2;
  90. break;
  91. default:
  92. _ASSERTE(FALSE);
  93. return 1; // Prefix #113781 (this should never happen; only three controls on dialog)
  94. break;
  95. }
  96. // For each button, Check the state, And if the button is selected,
  97. // means that it has current focus, So Re-paint the previously hilighted and
  98. // the current selected buttons....
  99. // Make sure we ignore the initial events so that we minimize the flicker...
  100. if ( (lpDrawItemStruct->itemState & ODS_FOCUS) && (m_nCurrentHilight != index))
  101. {
  102. // If focussed item!
  103. if ( syncInit )
  104. {
  105. // Erase the previous one...
  106. InvalidateRects(m_nCurrentHilight);
  107. m_nCurrentHilight= m_nCurValueIndex = index;
  108. SelectionChanged(m_nCurValueIndex);
  109. }
  110. }
  111. Draw( lpDrawItemStruct, index );
  112. return 1;
  113. }
  114. void CIconSizePg::Draw(LPDRAWITEMSTRUCT ldi, int i)
  115. {
  116. HDC hdc = ldi->hDC;
  117. int nOldBkMode = SetBkMode(hdc, TRANSPARENT);
  118. int nOldAlign = SetTextAlign(hdc, TA_CENTER);
  119. RECT rcOriginal = ldi->rcItem ;
  120. TCHAR sz[100];
  121. LPCTSTR szBitmap = NULL;
  122. int nFontSize = 8;
  123. int nOffset = 0;
  124. HBITMAP hBitmap;
  125. switch(i)
  126. {
  127. case 0:
  128. szBitmap = __TEXT("IDB_ICON_SAMPLE_NORMAL2"); // NO NEED TO LOCALIZE
  129. LoadString(g_hInstDll, IDS_ICONSIZENAMENORMAL, sz, ARRAYSIZE(sz));
  130. nFontSize = 8;
  131. nOffset = 16 + 2;
  132. break;
  133. case 1:
  134. szBitmap = __TEXT("IDB_ICON_SAMPLE_LARGE2"); // NO NEED TO LOCALIZE
  135. LoadString(g_hInstDll, IDS_ICONSIZENAMELARGE, sz, ARRAYSIZE(sz));
  136. nFontSize = 12;
  137. nOffset = 24 + 2;
  138. break;
  139. case 2:
  140. szBitmap = __TEXT("IDB_ICON_SAMPLE_EXLARGE2"); // NO NEED TO LOCALIZE
  141. LoadString(g_hInstDll, IDS_ICONSIZENAMEEXTRALARGE, sz, ARRAYSIZE(sz));
  142. nFontSize = 18;
  143. nOffset = 32 + 2;
  144. break;
  145. default:
  146. _ASSERTE(FALSE);
  147. break;
  148. }
  149. HFONT hFontOld = (HFONT)SelectObject(hdc, g_Options.GetClosestMSSansSerif(nFontSize, (m_nCurrentHilight == i)));
  150. TextOut(hdc,
  151. (rcOriginal.left + rcOriginal.right)/2,
  152. (rcOriginal.top + rcOriginal.bottom)/2 + nOffset,
  153. sz, lstrlen(sz));
  154. SelectObject(hdc, hFontOld);
  155. HDC hDC = CreateCompatibleDC(hdc);
  156. if (!hDC)
  157. return; // Prefix #113779 (out of resources; give up)
  158. // Paint the selected Bitmap.
  159. hBitmap = (HBITMAP) LoadImage( g_hInstDll, szBitmap, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_SHARED | LR_LOADMAP3DCOLORS);
  160. SelectObject(hDC, hBitmap);
  161. BitBlt(hdc, (rcOriginal.left + rcOriginal.right)/2 - nOffset,
  162. (rcOriginal.top + rcOriginal.bottom)/2 - nOffset, 100, 100, hDC, 0, 0, SRCCOPY);
  163. DeleteDC(hDC);
  164. SetTextAlign(hdc, nOldAlign);
  165. SetBkMode(hdc, nOldBkMode);
  166. //If current hi-lighted item, Then draw the bounding rectangle.
  167. if ( m_nCurrentHilight == i)
  168. {
  169. DrawHilight(m_hwnd, ldi);
  170. }
  171. }
  172. /////////////////////////////////
  173. //CScrollBarPg members
  174. /////////////////////////////////
  175. //
  176. // Map the button-ID and the selection index
  177. //
  178. UINT IDMapS[4][2] = { 0, IDC_SCROLL1,
  179. 1, IDC_SCROLL2,
  180. 2, IDC_SCROLL3,
  181. 3, IDC_SCROLL4
  182. };
  183. CScrollBarPg::CScrollBarPg(LPPROPSHEETPAGE ppsp)
  184. : WizardPage(ppsp, IDS_LKPREV_SCROLLBARTITLE, IDS_LKPREV_SCROLLBARSUBTITLE)
  185. {
  186. m_dwPageId = IDD_FNTWIZSCROLLBAR;
  187. ppsp->pszTemplate = MAKEINTRESOURCE(m_dwPageId);
  188. // Initializes the scroll bar widths and number of elements from string table.
  189. LoadArrayFromStringTable(IDS_LKPREV_SCROLLSIZES, m_rgnValues, &m_nCountValues);
  190. }
  191. LRESULT CScrollBarPg::OnInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
  192. {
  193. m_nCurValueIndex = m_nCountValues - 1;
  194. // Compute the current scroll bar type...
  195. for(int i=0; i < m_nCountValues; i++)
  196. {
  197. if(g_Options.m_schemePreview.m_PortableNonClientMetrics.m_iScrollWidth <= m_rgnValues[i])
  198. {
  199. m_nCurValueIndex = i;
  200. break;
  201. }
  202. }
  203. m_nCurrentHilight = m_nCurValueIndex;
  204. return 1;
  205. }
  206. // When page set active, Start Timer to set the Focus and ignore the
  207. // Hilighted events....
  208. LRESULT CScrollBarPg::OnPSN_SetActive(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  209. {
  210. syncInit = FALSE;
  211. uIDEvent = SetTimer(hwnd, NULL, 100, NULL);
  212. return 0;
  213. }
  214. // Timer Handler
  215. LRESULT CScrollBarPg::OnTimer( HWND hwnd, WPARAM wParam, LPARAM lParam )
  216. {
  217. KillTimer(hwnd, uIDEvent);
  218. syncInit = TRUE;
  219. return 1;
  220. }
  221. // Apply new settings...
  222. LRESULT CScrollBarPg::SettingChanged(int nNewSelection)
  223. {
  224. int nNewValue = (int) m_rgnValues[nNewSelection];
  225. g_Options.m_schemePreview.m_PortableNonClientMetrics.m_iScrollWidth = nNewValue;
  226. g_Options.m_schemePreview.m_PortableNonClientMetrics.m_iScrollHeight = nNewValue;
  227. g_Options.m_schemePreview.m_PortableNonClientMetrics.m_iBorderWidth = nNewSelection;
  228. g_Options.ApplyPreview();
  229. return 0;
  230. }
  231. // Set the current focussed item....
  232. void CScrollBarPg::SetFocussedItem(int m_nCurrentHilight)
  233. {
  234. SetFocus(GetDlgItem(m_hwnd, IDMapS[m_nCurrentHilight][1]));
  235. }
  236. // Erase the previous one....
  237. void CScrollBarPg::InvalidateRects(int PrevHilight)
  238. {
  239. InvalidateRect(GetDlgItem(m_hwnd, IDMapS[PrevHilight][1]), NULL, TRUE);
  240. }
  241. // Owner Draw message
  242. LRESULT CScrollBarPg::OnDrawItem(HWND hwnd, WPARAM wParam, LPARAM lParam)
  243. {
  244. UINT idCtrl = (UINT) wParam;
  245. LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT) lParam;
  246. int index;
  247. if ( !syncInit)
  248. SetFocussedItem(m_nCurrentHilight);
  249. switch(idCtrl)
  250. {
  251. case IDC_SCROLL1:
  252. index = 0;
  253. break;
  254. case IDC_SCROLL2:
  255. index = 1;
  256. break;
  257. case IDC_SCROLL3:
  258. index = 2;
  259. break;
  260. case IDC_SCROLL4:
  261. index = 3;
  262. break;
  263. default:
  264. // Error
  265. _ASSERTE(FALSE);
  266. return 1; // Prefix #113782 (this should never happen; only four controls on dialog)
  267. break;
  268. }
  269. // For each button, Check the state, And if the button is selected,
  270. // means that it has current focus, So Re-paint the previously hilighted and
  271. // the current selected buttons....
  272. // Make sure we ignore the initial events so that we minimize the flicker...
  273. if ( (lpDrawItemStruct->itemState & ODS_FOCUS) && (m_nCurrentHilight != index))
  274. {
  275. if ( syncInit )
  276. {
  277. // Erase the previous one...
  278. InvalidateRects(m_nCurrentHilight);
  279. m_nCurrentHilight= m_nCurValueIndex = index;
  280. SettingChanged(m_nCurValueIndex);
  281. // dirty = TRUE;
  282. }
  283. }
  284. Draw( lpDrawItemStruct, index );
  285. return 1;
  286. }
  287. // Paints the scroll bars and the selected item
  288. void CScrollBarPg::Draw(LPDRAWITEMSTRUCT ldi, int i)
  289. {
  290. HDC hdc = ldi->hDC;
  291. RECT rcOriginal = ldi->rcItem ;
  292. RECT rci = rcOriginal;
  293. InflateRect(&rcOriginal, -10, -10);
  294. // Draw border
  295. DrawEdge(hdc, &rcOriginal, EDGE_RAISED, BF_BOTTOMRIGHT| BF_ADJUST);
  296. DrawEdge(hdc, &rcOriginal, BDR_RAISEDINNER, BF_FLAT | BF_BOTTOMRIGHT | BF_ADJUST);
  297. DrawEdge(hdc, &rcOriginal, BDR_RAISEDINNER, BF_FLAT | BF_BOTTOMRIGHT | BF_ADJUST);
  298. // Adjust for the border
  299. rcOriginal.right -= i;
  300. rcOriginal.bottom -= i;
  301. // Adjust to the width of the scroll bar
  302. rcOriginal.left = rcOriginal.right - m_rgnValues[i];
  303. RECT rc = rcOriginal;
  304. // Drop the top
  305. rc.bottom = rc.top + m_rgnValues[i];
  306. DrawFrameControl(hdc, &rc, DFC_SCROLL, DFCS_SCROLLUP);
  307. // Draw the middle
  308. rc.top = rc.bottom;
  309. rc.bottom = rcOriginal.bottom - 2 * m_rgnValues[i];
  310. HBRUSH hbr = (HBRUSH)DefWindowProc(m_hwnd, WM_CTLCOLORSCROLLBAR, (WPARAM)hdc, (LPARAM)m_hwnd);
  311. HBRUSH hbrOld = (HBRUSH)SelectObject(hdc, hbr);
  312. HPEN hpenOld = (HPEN)SelectObject(hdc, GetStockObject(NULL_PEN));
  313. // ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  314. Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
  315. SelectObject(hdc, hbrOld);
  316. SelectObject(hdc, hpenOld);
  317. // Draw the bottom
  318. rc.top = rc.bottom;
  319. rc.bottom = rc.top + m_rgnValues[i];
  320. DrawFrameControl(hdc, &rc, DFC_SCROLL, DFCS_SCROLLDOWN);
  321. // Draw the thumb
  322. rc.top = rc.bottom;
  323. rc.bottom = rc.top + m_rgnValues[i];
  324. DrawFrameControl(hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
  325. // Draw the right arrow
  326. rc.right = rc.left;
  327. rc.left = rc.right - m_rgnValues[i];
  328. DrawFrameControl(hdc, &rc, DFC_SCROLL, DFCS_SCROLLRIGHT);
  329. // Draw the middle of the bottom scroll bar
  330. rc.right = rc.left;
  331. rc.left = rci.left + 10;
  332. hbr = (HBRUSH)DefWindowProc(m_hwnd, WM_CTLCOLORSCROLLBAR, (WPARAM)hdc, (LPARAM)m_hwnd);
  333. hbrOld = (HBRUSH)SelectObject(hdc, hbr);
  334. hpenOld = (HPEN)SelectObject(hdc, GetStockObject(NULL_PEN));
  335. // ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  336. Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
  337. SelectObject(hdc, hbrOld);
  338. SelectObject(hdc, hpenOld);
  339. //If current hi-lighted item, Then draw the bounding rectangle.
  340. if ( m_nCurrentHilight == i)
  341. {
  342. DrawHilight(m_hwnd, ldi);
  343. }
  344. }
  345. // Global function to draw the hilighted rectangle....
  346. void DrawHilight(HWND hWnd, LPDRAWITEMSTRUCT ldi)
  347. {
  348. HDC hdc = ldi->hDC;
  349. UINT clrH = COLOR_HIGHLIGHT;
  350. HPALETTE hpalOld = NULL;
  351. SaveDC(hdc);
  352. if (g_hpal3D)
  353. {
  354. hpalOld = SelectPalette(hdc, g_hpal3D, TRUE);
  355. RealizePalette(hdc);
  356. }
  357. // Set the color for drawing the scroll bar
  358. COLORREF clrrefOld = SetBkColor(hdc, GetSysColor(COLOR_3DHILIGHT));
  359. COLORREF clrrefOldText = SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
  360. // OnDraw(hdc);
  361. // Draw the focus
  362. RECT rc = ldi->rcItem;
  363. InflateRect(&rc, -2, -2);
  364. RECT rcTemp;
  365. // If current window not in focus
  366. if ( GetForegroundWindow() != GetParent(hWnd) )
  367. clrH = COLOR_GRAYTEXT;
  368. HWND hwF = GetFocus();
  369. // Use 'selected' color for scroll bar selection
  370. COLORREF clrrefSelected = GetSysColor(COLOR_GRAYTEXT);
  371. if ( (hwF != NULL) && (GetParent(hwF) == hWnd))
  372. clrrefSelected = GetSysColor(COLOR_HIGHLIGHT); // Use 'Gray' or 'Selected'
  373. SetBkColor(hdc, clrrefSelected);
  374. // Draw left
  375. rcTemp = rc;
  376. rcTemp.right = rcTemp.left + 5;
  377. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcTemp, NULL, 0, NULL);
  378. // Draw top
  379. rcTemp = rc;
  380. rcTemp.bottom = rcTemp.top + 5;
  381. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcTemp, NULL, 0, NULL);
  382. // Draw right
  383. rcTemp = rc;
  384. rcTemp.left = rcTemp.right - 5;
  385. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcTemp, NULL, 0, NULL);
  386. // Draw bottom
  387. rcTemp = rc;
  388. rcTemp.top = rcTemp.bottom - 5;
  389. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcTemp, NULL, 0, NULL);
  390. // Reset the color from drawing the scroll bar
  391. SetBkColor(hdc, clrrefOld);
  392. SetTextColor(hdc, clrrefOldText);
  393. if (hpalOld)
  394. {
  395. hpalOld = SelectPalette(hdc, hpalOld, FALSE);
  396. RealizePalette(hdc);
  397. }
  398. RestoreDC(hdc, -1);
  399. }