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.

516 lines
13 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 changed, 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. HGDIOBJ hObject = SelectObject(hdc, hFontOld);
  155. DeleteObject(hObject);
  156. HDC hDC = CreateCompatibleDC(hdc);
  157. if (!hDC)
  158. return; // Prefix #113779 (out of resources; give up)
  159. // Paint the selected Bitmap.
  160. hBitmap = (HBITMAP) LoadImage( g_hInstDll, szBitmap, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_SHARED | LR_LOADMAP3DCOLORS);
  161. HGDIOBJ hBitmapOld = SelectObject(hDC, hBitmap);
  162. BitBlt(hdc, (rcOriginal.left + rcOriginal.right)/2 - nOffset,
  163. (rcOriginal.top + rcOriginal.bottom)/2 - nOffset, 100, 100, hDC, 0, 0, SRCCOPY);
  164. SelectObject(hdc, hBitmapOld);
  165. DeleteObject(hBitmap);
  166. DeleteDC(hDC);
  167. SetTextAlign(hdc, nOldAlign);
  168. SetBkMode(hdc, nOldBkMode);
  169. //If current hi-lighted item, Then draw the bounding rectangle.
  170. if ( m_nCurrentHilight == i)
  171. {
  172. DrawHilight(m_hwnd, ldi);
  173. }
  174. }
  175. /////////////////////////////////
  176. //CScrollBarPg members
  177. /////////////////////////////////
  178. //
  179. // Map the button-ID and the selection index
  180. //
  181. UINT IDMapS[4][2] = { 0, IDC_SCROLL1,
  182. 1, IDC_SCROLL2,
  183. 2, IDC_SCROLL3,
  184. 3, IDC_SCROLL4
  185. };
  186. CScrollBarPg::CScrollBarPg(LPPROPSHEETPAGE ppsp)
  187. : WizardPage(ppsp, IDS_LKPREV_SCROLLBARTITLE, IDS_LKPREV_SCROLLBARSUBTITLE)
  188. {
  189. m_dwPageId = IDD_FNTWIZSCROLLBAR;
  190. ppsp->pszTemplate = MAKEINTRESOURCE(m_dwPageId);
  191. // Initializes the scroll bar widths and number of elements from string table.
  192. LoadArrayFromStringTable(IDS_LKPREV_SCROLLSIZES, m_rgnValues, &m_nCountValues);
  193. }
  194. LRESULT CScrollBarPg::OnInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
  195. {
  196. m_nCurValueIndex = m_nCountValues - 1;
  197. // Compute the current scroll bar type...
  198. for(int i=0; i < m_nCountValues; i++)
  199. {
  200. if(g_Options.m_schemePreview.m_PortableNonClientMetrics.m_iScrollWidth <= m_rgnValues[i])
  201. {
  202. m_nCurValueIndex = i;
  203. break;
  204. }
  205. }
  206. m_nCurrentHilight = m_nCurValueIndex;
  207. return 1;
  208. }
  209. // When page set active, Start Timer to set the Focus and ignore the
  210. // Hilighted events....
  211. LRESULT CScrollBarPg::OnPSN_SetActive(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  212. {
  213. syncInit = FALSE;
  214. uIDEvent = SetTimer(hwnd, NULL, 100, NULL);
  215. return 0;
  216. }
  217. // Timer Handler
  218. LRESULT CScrollBarPg::OnTimer( HWND hwnd, WPARAM wParam, LPARAM lParam )
  219. {
  220. KillTimer(hwnd, uIDEvent);
  221. syncInit = TRUE;
  222. return 1;
  223. }
  224. // Apply new settings...
  225. LRESULT CScrollBarPg::SettingChanged(int nNewSelection)
  226. {
  227. int nNewValue = (int) m_rgnValues[nNewSelection];
  228. g_Options.m_schemePreview.m_PortableNonClientMetrics.m_iScrollWidth = nNewValue;
  229. g_Options.m_schemePreview.m_PortableNonClientMetrics.m_iScrollHeight = nNewValue;
  230. g_Options.m_schemePreview.m_PortableNonClientMetrics.m_iBorderWidth = nNewSelection;
  231. g_Options.ApplyPreview();
  232. return 0;
  233. }
  234. // Set the current focussed item....
  235. void CScrollBarPg::SetFocussedItem(int m_nCurrentHilight)
  236. {
  237. SetFocus(GetDlgItem(m_hwnd, IDMapS[m_nCurrentHilight][1]));
  238. }
  239. // Erase the previous one....
  240. void CScrollBarPg::InvalidateRects(int PrevHilight)
  241. {
  242. InvalidateRect(GetDlgItem(m_hwnd, IDMapS[PrevHilight][1]), NULL, TRUE);
  243. }
  244. // Owner Draw message
  245. LRESULT CScrollBarPg::OnDrawItem(HWND hwnd, WPARAM wParam, LPARAM lParam)
  246. {
  247. UINT idCtrl = (UINT) wParam;
  248. LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT) lParam;
  249. int index;
  250. if ( !syncInit)
  251. SetFocussedItem(m_nCurrentHilight);
  252. switch(idCtrl)
  253. {
  254. case IDC_SCROLL1:
  255. index = 0;
  256. break;
  257. case IDC_SCROLL2:
  258. index = 1;
  259. break;
  260. case IDC_SCROLL3:
  261. index = 2;
  262. break;
  263. case IDC_SCROLL4:
  264. index = 3;
  265. break;
  266. default:
  267. // Error
  268. _ASSERTE(FALSE);
  269. return 1; // Prefix #113782 (this should never happen; only four controls on dialog)
  270. break;
  271. }
  272. // For each button, Check the state, And if the button is selected,
  273. // means that it has current focus, So Re-paint the previously hilighted and
  274. // the current selected buttons....
  275. // Make sure we ignore the initial events so that we minimize the flicker...
  276. if ( (lpDrawItemStruct->itemState & ODS_FOCUS) && (m_nCurrentHilight != index))
  277. {
  278. if ( syncInit )
  279. {
  280. // Erase the previous one...
  281. InvalidateRects(m_nCurrentHilight);
  282. m_nCurrentHilight= m_nCurValueIndex = index;
  283. SettingChanged(m_nCurValueIndex);
  284. // dirty = TRUE;
  285. }
  286. }
  287. Draw( lpDrawItemStruct, index );
  288. return 1;
  289. }
  290. // Paints the scroll bars and the selected item
  291. void CScrollBarPg::Draw(LPDRAWITEMSTRUCT ldi, int i)
  292. {
  293. HDC hdc = ldi->hDC;
  294. RECT rcOriginal = ldi->rcItem ;
  295. RECT rci = rcOriginal;
  296. InflateRect(&rcOriginal, -10, -10);
  297. // Draw border
  298. DrawEdge(hdc, &rcOriginal, EDGE_RAISED, BF_BOTTOMRIGHT| BF_ADJUST);
  299. DrawEdge(hdc, &rcOriginal, BDR_RAISEDINNER, BF_FLAT | BF_BOTTOMRIGHT | BF_ADJUST);
  300. DrawEdge(hdc, &rcOriginal, BDR_RAISEDINNER, BF_FLAT | BF_BOTTOMRIGHT | BF_ADJUST);
  301. // Adjust for the border
  302. rcOriginal.right -= i;
  303. rcOriginal.bottom -= i;
  304. // Adjust to the width of the scroll bar
  305. rcOriginal.left = rcOriginal.right - m_rgnValues[i];
  306. RECT rc = rcOriginal;
  307. // Drop the top
  308. rc.bottom = rc.top + m_rgnValues[i];
  309. DrawFrameControl(hdc, &rc, DFC_SCROLL, DFCS_SCROLLUP);
  310. // Draw the middle
  311. rc.top = rc.bottom;
  312. rc.bottom = rcOriginal.bottom - 2 * m_rgnValues[i];
  313. HBRUSH hbr = (HBRUSH)DefWindowProc(m_hwnd, WM_CTLCOLORSCROLLBAR, (WPARAM)hdc, (LPARAM)m_hwnd);
  314. HBRUSH hbrOld = (HBRUSH)SelectObject(hdc, hbr);
  315. HPEN hpenOld = (HPEN)SelectObject(hdc, GetStockObject(NULL_PEN));
  316. // ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  317. Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
  318. HGDIOBJ hObject = SelectObject(hdc, hbrOld);
  319. DeleteObject(hObject);
  320. SelectObject(hdc, hpenOld);
  321. // Draw the bottom
  322. rc.top = rc.bottom;
  323. rc.bottom = rc.top + m_rgnValues[i];
  324. DrawFrameControl(hdc, &rc, DFC_SCROLL, DFCS_SCROLLDOWN);
  325. // Draw the thumb
  326. rc.top = rc.bottom;
  327. rc.bottom = rc.top + m_rgnValues[i];
  328. DrawFrameControl(hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
  329. // Draw the right arrow
  330. rc.right = rc.left;
  331. rc.left = rc.right - m_rgnValues[i];
  332. DrawFrameControl(hdc, &rc, DFC_SCROLL, DFCS_SCROLLRIGHT);
  333. // Draw the middle of the bottom scroll bar
  334. rc.right = rc.left;
  335. rc.left = rci.left + 10;
  336. hbr = (HBRUSH)DefWindowProc(m_hwnd, WM_CTLCOLORSCROLLBAR, (WPARAM)hdc, (LPARAM)m_hwnd);
  337. hbrOld = (HBRUSH)SelectObject(hdc, hbr);
  338. hpenOld = (HPEN)SelectObject(hdc, GetStockObject(NULL_PEN));
  339. // ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  340. Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
  341. hObject = SelectObject(hdc, hbrOld);
  342. DeleteObject(hObject);
  343. hObject = SelectObject(hdc, hpenOld);
  344. DeleteObject(hObject);
  345. //If current hi-lighted item, Then draw the bounding rectangle.
  346. if ( m_nCurrentHilight == i)
  347. {
  348. DrawHilight(m_hwnd, ldi);
  349. }
  350. }
  351. // Global function to draw the hilighted rectangle....
  352. void DrawHilight(HWND hWnd, LPDRAWITEMSTRUCT ldi)
  353. {
  354. HDC hdc = ldi->hDC;
  355. UINT clrH = COLOR_HIGHLIGHT;
  356. HPALETTE hpalOld = NULL;
  357. SaveDC(hdc);
  358. if (g_hpal3D)
  359. {
  360. hpalOld = SelectPalette(hdc, g_hpal3D, TRUE);
  361. RealizePalette(hdc);
  362. }
  363. // Set the color for drawing the scroll bar
  364. COLORREF clrrefOld = SetBkColor(hdc, GetSysColor(COLOR_3DHILIGHT));
  365. COLORREF clrrefOldText = SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
  366. // OnDraw(hdc);
  367. // Draw the focus
  368. RECT rc = ldi->rcItem;
  369. InflateRect(&rc, -2, -2);
  370. RECT rcTemp;
  371. // If current window not in focus
  372. if ( GetForegroundWindow() != GetParent(hWnd) )
  373. clrH = COLOR_GRAYTEXT;
  374. HWND hwF = GetFocus();
  375. // Use 'selected' color for scroll bar selection
  376. COLORREF clrrefSelected = GetSysColor(COLOR_GRAYTEXT);
  377. if ( (hwF != NULL) && (GetParent(hwF) == hWnd))
  378. clrrefSelected = GetSysColor(COLOR_HIGHLIGHT); // Use 'Gray' or 'Selected'
  379. SetBkColor(hdc, clrrefSelected);
  380. // Draw left
  381. rcTemp = rc;
  382. rcTemp.right = rcTemp.left + 5;
  383. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcTemp, NULL, 0, NULL);
  384. // Draw top
  385. rcTemp = rc;
  386. rcTemp.bottom = rcTemp.top + 5;
  387. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcTemp, NULL, 0, NULL);
  388. // Draw right
  389. rcTemp = rc;
  390. rcTemp.left = rcTemp.right - 5;
  391. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcTemp, NULL, 0, NULL);
  392. // Draw bottom
  393. rcTemp = rc;
  394. rcTemp.top = rcTemp.bottom - 5;
  395. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcTemp, NULL, 0, NULL);
  396. // Reset the color from drawing the scroll bar
  397. SetBkColor(hdc, clrrefOld);
  398. SetTextColor(hdc, clrrefOldText);
  399. if (hpalOld)
  400. {
  401. hpalOld = SelectPalette(hdc, hpalOld, FALSE);
  402. DeleteObject(hpalOld);
  403. RealizePalette(hdc);
  404. }
  405. RestoreDC(hdc, -1);
  406. }