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.

906 lines
27 KiB

  1. //Copyright (c) 1997-2000 Microsoft Corporation
  2. /* LOOKPREV.C
  3. **
  4. **
  5. **
  6. ** History:
  7. **
  8. */
  9. #include "pch.hxx" // PCH
  10. #pragma hdrstop
  11. #include "AccWiz.h"
  12. #include "desk.h"
  13. //#include "deskid.h"
  14. #include "resource.h"
  15. #include "look.h"
  16. #include "LookPrev.h"
  17. #define RCZ(element) g_elements[element].rc
  18. //////////////////////////////////
  19. // Support function
  20. void MyDrawBorderBelow(HDC hdc, LPRECT prc);
  21. void MyDrawFrame(HDC hdc, LPRECT prc, HBRUSH hbrColor, int cl);
  22. HDC g_hdcMem;
  23. TCHAR g_szABC[] = TEXT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
  24. int cxSize;
  25. //////////////////////////////////////////////////////////////
  26. // Declarations of static variables declared in classes
  27. BOOL CLookPreviewGlobals::sm_bOneInstanceCreated = FALSE; // This variable insures that only one instance of CLookPreviewGlobals is created
  28. CLookPreviewGlobals CLookPrev::sm_Globals;
  29. //////////////////////////////////////////////////////////////
  30. // CLookPreviewGlobals member functions
  31. //
  32. BOOL CLookPreviewGlobals::Initialize()
  33. {
  34. if(m_bInitialized)
  35. return TRUE;
  36. m_bInitialized = TRUE;
  37. // Make sure there is only one instance of this class created
  38. _ASSERT(!sm_bOneInstanceCreated);
  39. sm_bOneInstanceCreated = TRUE;
  40. //
  41. // Load our display strings.
  42. //
  43. VERIFY(LoadString(g_hInstDll, IDS_ACTIVE, m_szActive, ARRAYSIZE(m_szActive)));
  44. VERIFY(LoadString(g_hInstDll, IDS_INACTIVE, m_szInactive, ARRAYSIZE(m_szInactive)));
  45. VERIFY(LoadString(g_hInstDll, IDS_MINIMIZED, m_szMinimized, ARRAYSIZE(m_szMinimized)));
  46. VERIFY(LoadString(g_hInstDll, IDS_ICONTITLE, m_szIconTitle, ARRAYSIZE(m_szIconTitle)));
  47. VERIFY(LoadString(g_hInstDll, IDS_NORMAL, m_szNormal, ARRAYSIZE(m_szNormal)));
  48. VERIFY(LoadString(g_hInstDll, IDS_DISABLED, m_szDisabled, ARRAYSIZE(m_szDisabled)));
  49. VERIFY(LoadString(g_hInstDll, IDS_SELECTED, m_szSelected, ARRAYSIZE(m_szSelected)));
  50. VERIFY(LoadString(g_hInstDll, IDS_MSGBOX, m_szMsgBox, ARRAYSIZE(m_szMsgBox)));
  51. VERIFY(LoadString(g_hInstDll, IDS_BUTTONTEXT, m_szButton, ARRAYSIZE(m_szButton)));
  52. // VERIFY(LoadString(g_hInstDll, IDS_SMCAPTION, m_szSmallCaption, ARRAYSIZE(m_szSmallCaption)));
  53. VERIFY(LoadString(g_hInstDll, IDS_WINDOWTEXT, m_szWindowText, ARRAYSIZE(m_szWindowText)));
  54. VERIFY(LoadString(g_hInstDll, IDS_MSGBOXTEXT, m_szMsgBoxText, ARRAYSIZE(m_szMsgBoxText)));
  55. /////////////////////////////////////////////
  56. // Register Look Preview window class
  57. WNDCLASS wc;
  58. memset(&wc, 0, sizeof(wc));
  59. wc.style = 0;
  60. wc.lpfnWndProc = CLookPrev::LookPreviewWndProc;
  61. wc.cbClsExtra = 0;
  62. wc.cbWndExtra = 0;
  63. wc.hInstance = g_hInstDll;
  64. wc.hIcon = NULL;
  65. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  66. wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
  67. wc.lpszMenuName = NULL;
  68. wc.lpszClassName = LOOKPREV_CLASS;
  69. VERIFY(RegisterClass(&wc));
  70. /////////////////////////////////////////////
  71. // Global initialization of g_hdcMem
  72. HBITMAP hbmDefault;
  73. HDC hdc = GetDC(NULL);
  74. VERIFY(g_hdcMem = CreateCompatibleDC(hdc));
  75. ReleaseDC(NULL, hdc);
  76. HBITMAP hbm = CreateBitmap(1, 1, 1, 1, NULL);
  77. if (!hbm)
  78. return FALSE; // Prefix #113777 (avoid null handle reference)
  79. hbmDefault = (HBITMAP)SelectObject(g_hdcMem, hbm);
  80. SelectObject(g_hdcMem, hbmDefault);
  81. DeleteObject(hbm);
  82. /////////////////////////////////////////////
  83. // Old initialization form Look_InitSysStuff()
  84. int i;
  85. NONCLIENTMETRICS ncm;
  86. HKEY hkey;
  87. hdc = GetDC(NULL);
  88. g_LogDPI = GetDeviceCaps(hdc, LOGPIXELSY);
  89. g_bPalette = GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE;
  90. ReleaseDC(NULL, hdc);
  91. // always make a palette even on non-pal device
  92. if (g_bPalette || TRUE)
  93. {
  94. DWORD pal[21];
  95. HPALETTE hpal = (HPALETTE)GetStockObject(DEFAULT_PALETTE);
  96. pal[1] = RGB(255, 255, 255);
  97. pal[2] = RGB(0, 0, 0 );
  98. pal[3] = RGB(192, 192, 192);
  99. pal[4] = RGB(128, 128, 128);
  100. pal[5] = RGB(255, 0, 0 );
  101. pal[6] = RGB(128, 0, 0 );
  102. pal[7] = RGB(255, 255, 0 );
  103. pal[8] = RGB(128, 128, 0 );
  104. pal[9] = RGB(0 , 255, 0 );
  105. pal[10] = RGB(0 , 128, 0 );
  106. pal[11] = RGB(0 , 255, 255);
  107. pal[12] = RGB(0 , 128, 128); // Needs to be changed to get Blue color
  108. pal[13] = RGB(0 , 0, 255);
  109. pal[14] = RGB(0 , 0, 128);
  110. pal[15] = RGB(255, 0, 255);
  111. pal[16] = RGB(128, 0, 128);
  112. GetPaletteEntries(hpal, 11, 1, (LPPALETTEENTRY)&pal[17]);
  113. pal[0] = MAKELONG(0x300, 17);
  114. g_hpalVGA = CreatePalette((LPLOGPALETTE)pal);
  115. // get magic colors
  116. GetPaletteEntries(hpal, 8, 4, (LPPALETTEENTRY)&pal[17]);
  117. pal[0] = MAKELONG(0x300, 20);
  118. g_hpal3D = CreatePalette((LPLOGPALETTE)pal);
  119. }
  120. // system colors
  121. for (i = 0; i < NT40_COLOR_MAX; i++)
  122. {
  123. g_Options.m_schemePreview.m_rgb[i] = GetSysColor(i);
  124. g_brushes[i] = NULL;
  125. }
  126. // sizes and fonts
  127. ncm.cbSize = sizeof(ncm);
  128. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm),
  129. (void far *)(LPNONCLIENTMETRICS)&ncm, FALSE);
  130. SetMyNonClientMetrics(&ncm);
  131. SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT),
  132. (void far *)(LPLOGFONT)&(g_fonts[FONT_ICONTITLE].lf), FALSE);
  133. SystemParametersInfo(SPI_SETGRADIENTCAPTIONS, 0, (PVOID)TRUE, 0);
  134. // default shell icon sizes
  135. g_sizes[ SIZE_ICON ].CurSize = GetSystemMetrics( SM_CXICON );
  136. g_sizes[ SIZE_SMICON ].CurSize = g_sizes[ SIZE_ICON ].CurSize / 2;
  137. if( RegOpenKey( HKEY_CURRENT_USER, c_szRegPathUserMetrics, &hkey )
  138. == ERROR_SUCCESS )
  139. {
  140. TCHAR val[ 8 ];
  141. LONG len = sizeof( val );
  142. if( RegQueryValueEx( hkey, c_szRegValIconSize, 0, NULL, (LPBYTE)&val,
  143. (LPDWORD)&len ) == ERROR_SUCCESS )
  144. {
  145. g_sizes[ SIZE_ICON ].CurSize = (int)MyStrToLong( val );
  146. }
  147. len = SIZEOF( val );
  148. if( RegQueryValueEx( hkey, c_szRegValSmallIconSize, 0, NULL, (LPBYTE)&val,
  149. (LPDWORD)&len ) == ERROR_SUCCESS )
  150. {
  151. g_sizes[ SIZE_SMICON ].CurSize = (int)MyStrToLong( val );
  152. }
  153. RegCloseKey( hkey );
  154. }
  155. g_sizes[ SIZE_DXICON ].CurSize =
  156. GetSystemMetrics( SM_CXICONSPACING ) - g_sizes[ SIZE_ICON ].CurSize;
  157. if( g_sizes[ SIZE_DXICON ].CurSize < 0 )
  158. g_sizes[ SIZE_DXICON ].CurSize = DEF_SPACING;
  159. g_sizes[ SIZE_DYICON ].CurSize =
  160. GetSystemMetrics( SM_CYICONSPACING ) - g_sizes[ SIZE_ICON ].CurSize;
  161. if( g_sizes[ SIZE_DYICON ].CurSize < 0 )
  162. g_sizes[ SIZE_DYICON ].CurSize = DEF_SPACING;
  163. // clean out the memory
  164. for (i = 0; i < NUM_FONTS; i++)
  165. {
  166. g_fonts[i].hfont = NULL;
  167. }
  168. // build all the brushes/fonts we need
  169. Look_RebuildSysStuff(TRUE);
  170. // From Look_InitDialog
  171. // initialize some globals
  172. cyBorder = GetSystemMetrics(SM_CYBORDER);
  173. cxBorder = GetSystemMetrics(SM_CXBORDER);
  174. cxEdge = GetSystemMetrics(SM_CXEDGE);
  175. cyEdge = GetSystemMetrics(SM_CYEDGE);
  176. return TRUE;
  177. }
  178. //////////////////////////////////////////////////////////////
  179. // CLookPreviewGlobals member functions
  180. //
  181. // This is the static window proc function of CLookPrev
  182. LRESULT CALLBACK CLookPrev::LookPreviewWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  183. {
  184. PAINTSTRUCT ps;
  185. CLookPrev *pThis = (CLookPrev *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
  186. if(!pThis)
  187. {
  188. // Create the class to handle this object
  189. // Store the 'this' pointer in
  190. pThis = new CLookPrev;
  191. if (!pThis)
  192. return ERROR_NOT_ENOUGH_MEMORY; // Prefix #113776 (catch null pointer)
  193. pThis->m_hwnd = hWnd;
  194. SetWindowLongPtr (hWnd, GWLP_USERDATA, (INT_PTR)pThis);
  195. }
  196. switch(message)
  197. {
  198. case WM_NCCREATE:
  199. {
  200. DWORD dw;
  201. dw = GetWindowLong (hWnd,GWL_STYLE);
  202. SetWindowLong (hWnd, GWL_STYLE, dw | WS_BORDER);
  203. dw = GetWindowLong (hWnd,GWL_EXSTYLE);
  204. SetWindowLong (hWnd, GWL_EXSTYLE, dw | WS_EX_CLIENTEDGE);
  205. }
  206. return TRUE;
  207. case WM_CREATE:
  208. pThis->OnCreate();
  209. break;
  210. case WM_PALETTECHANGED:
  211. if ((HWND)wParam == hWnd)
  212. break;
  213. //fallthru
  214. case WM_QUERYNEWPALETTE:
  215. if (g_hpal3D)
  216. InvalidateRect(hWnd, NULL, FALSE);
  217. break;
  218. case WM_PAINT:
  219. BeginPaint(hWnd, &ps);
  220. pThis->OnPaint(ps.hdc);
  221. EndPaint(hWnd, &ps);
  222. return 0;
  223. case LPM_REPAINT:
  224. pThis->OnRepaint();
  225. return 0;
  226. case LPM_RECALC:
  227. pThis->OnRecalc();
  228. return 0;
  229. }
  230. return DefWindowProc(hWnd,message,wParam,lParam);
  231. }
  232. void CLookPrev::OnCreate()
  233. {
  234. // Load menu for window
  235. m_hmenuSample = LoadMenu(g_hInstDll, MAKEINTRESOURCE(IDR_MENU));
  236. EnableMenuItem(m_hmenuSample, IDM_DISABLED, MF_GRAYED | MF_BYCOMMAND);
  237. HiliteMenuItem(m_hwnd, m_hmenuSample, IDM_SELECTED, MF_HILITE | MF_BYCOMMAND);
  238. // Create Bitmap for window
  239. RECT rc;
  240. HDC hdc;
  241. GetClientRect(m_hwnd, &rc);
  242. hdc = GetDC(NULL);
  243. m_hbmLook = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top);
  244. ReleaseDC(NULL, hdc);
  245. // Mirror the memory DC if the window is mirrored to keep the text readable.
  246. if (GetWindowLong(m_hwnd, GWL_EXSTYLE) & WS_EX_LAYOUTRTL) {
  247. SetLayout(g_hdcMem, LAYOUT_RTL);
  248. }
  249. }
  250. void CLookPrev::OnDestroy()
  251. {
  252. if (m_hbmLook)
  253. DeleteObject(m_hbmLook);
  254. if (m_hmenuSample)
  255. DestroyMenu(m_hmenuSample);
  256. // Un-allocate memory for this instance of the class
  257. delete this;
  258. }
  259. void CLookPrev::OnPaint(HDC hdc)
  260. {
  261. if (m_hbmLook)
  262. ShowBitmap(hdc);
  263. else
  264. Draw(hdc);
  265. }
  266. void CLookPrev::ShowBitmap(HDC hdc)
  267. {
  268. RECT rc;
  269. HBITMAP hbmOld;
  270. HPALETTE hpalOld = NULL;
  271. if (g_hpal3D)
  272. {
  273. hpalOld = SelectPalette(hdc, g_hpal3D, FALSE);
  274. RealizePalette(hdc);
  275. }
  276. GetClientRect(m_hwnd, &rc);
  277. hbmOld = (HBITMAP)SelectObject(g_hdcMem, m_hbmLook);
  278. BitBlt(hdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, g_hdcMem, 0, 0, SRCCOPY);
  279. SelectObject(g_hdcMem, hbmOld);
  280. if (hpalOld)
  281. {
  282. SelectPalette(hdc, hpalOld, FALSE);
  283. RealizePalette(hdc);
  284. }
  285. }
  286. void CLookPrev::Draw(HDC hdc)
  287. {
  288. RECT rcT;
  289. int nMode;
  290. DWORD rgbBk;
  291. int cxSize, cySize;
  292. HANDLE hOldColors;
  293. HPALETTE hpalOld = NULL;
  294. HICON hiconLogo;
  295. // HFONT hfontOld;
  296. SaveDC(hdc);
  297. if (g_hpal3D)
  298. {
  299. hpalOld = SelectPalette(hdc, g_hpal3D, TRUE);
  300. RealizePalette(hdc);
  301. }
  302. hOldColors = SetSysColorsTemp(g_Options.m_schemePreview.m_rgb, g_brushes, COLOR_MAX_97_NT5/*COLOR_MAX_95_NT4*/);
  303. hiconLogo = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON,
  304. g_sizes[SIZE_CAPTION].CurSize - 2*cxBorder,
  305. g_sizes[SIZE_CAPTION].CurSize - 2*cyBorder, 0);
  306. //
  307. // Setup drawing stuff
  308. //
  309. nMode = SetBkMode(hdc, TRANSPARENT);
  310. rgbBk = GetTextColor(hdc);
  311. cxSize = GetSystemMetrics(SM_CXSIZE);
  312. cySize = GetSystemMetrics(SM_CYSIZE);
  313. //
  314. // Desktop
  315. //
  316. FillRect(hdc, &RCZ(ELEMENT_DESKTOP), g_brushes[COLOR_BACKGROUND]);
  317. //
  318. // Inactive window
  319. //
  320. // Border
  321. rcT = RCZ(ELEMENT_INACTIVEBORDER);
  322. DrawEdge(hdc, &rcT, EDGE_RAISED, BF_RECT | BF_ADJUST);
  323. MyDrawFrame(hdc, &rcT, g_brushes[COLOR_INACTIVEBORDER], g_sizes[SIZE_FRAME].CurSize);
  324. MyDrawFrame(hdc, &rcT, g_brushes[COLOR_3DFACE], 1);
  325. // Caption
  326. rcT = RCZ(ELEMENT_INACTIVECAPTION);
  327. MyDrawBorderBelow(hdc, &rcT);
  328. // NOTE: because USER draws icon stuff using its own DC and subsequently
  329. // its own palette, we need to make sure to use the inactivecaption
  330. // brush before USER does so that it will be realized against our palette.
  331. // this might get fixed in USER by better be safe.
  332. // "clip" the caption title under the buttons
  333. rcT.left = RCZ(ELEMENT_INACTIVESYSBUT2).left - cyEdge;
  334. FillRect(hdc, &rcT, g_brushes[COLOR_GRADIENTINACTIVECAPTION]);
  335. rcT.right = rcT.left;
  336. rcT.left = RCZ(ELEMENT_INACTIVECAPTION).left;
  337. DrawCaptionTemp(NULL, hdc, &rcT, g_fonts[FONT_CAPTION].hfont, hiconLogo, sm_Globals.m_szInactive, DC_ICON | DC_TEXT | DC_GRADIENT);
  338. DrawFrameControl(hdc, &RCZ(ELEMENT_INACTIVESYSBUT1), DFC_CAPTION, DFCS_CAPTIONCLOSE);
  339. rcT = RCZ(ELEMENT_INACTIVESYSBUT2);
  340. rcT.right -= (rcT.right - rcT.left)/2;
  341. DrawFrameControl(hdc, &rcT, DFC_CAPTION, DFCS_CAPTIONMIN);
  342. rcT.left = rcT.right;
  343. rcT.right = RCZ(ELEMENT_INACTIVESYSBUT2).right;
  344. DrawFrameControl(hdc, &rcT, DFC_CAPTION, DFCS_CAPTIONMAX);
  345. #if 0
  346. //
  347. // small caption window
  348. //
  349. {
  350. HICON hicon;
  351. int temp;
  352. rcT = RCZ(ELEMENT_SMCAPTION);
  353. hicon = (HICON)LoadImage(NULL, IDI_APPLICATION,
  354. IMAGE_ICON,
  355. g_sizes[SIZE_SMCAPTION].CurSize - 2*cxBorder,
  356. g_sizes[SIZE_SMCAPTION].CurSize - 2*cyBorder,
  357. 0);
  358. DrawEdge(hdc, &rcT, EDGE_RAISED, BF_TOP | BF_LEFT | BF_RIGHT | BF_ADJUST);
  359. MyDrawFrame(hdc, &rcT, g_brushes[COLOR_3DFACE], 1);
  360. // "clip" the caption title under the buttons
  361. temp = rcT.left; // remember start of actual caption
  362. rcT.left = RCZ(ELEMENT_SMCAPSYSBUT).left - cxEdge;
  363. FillRect(hdc, &rcT, g_brushes[COLOR_ACTIVECAPTION]);
  364. rcT.right = rcT.left;
  365. rcT.left = temp; // start of actual caption
  366. DrawCaptionTemp(NULL, hdc, &rcT, g_fonts[FONT_SMCAPTION].hfont, hicon, sm_Globals.m_szSmallCaption, DC_SMALLCAP | DC_ICON | DC_TEXT);
  367. DestroyIcon(hicon);
  368. DrawFrameControl(hdc, &RCZ(ELEMENT_SMCAPSYSBUT), DFC_CAPTION, DFCS_CAPTIONCLOSE);
  369. }
  370. #endif
  371. //
  372. // Active window
  373. //
  374. // Border
  375. rcT = RCZ(ELEMENT_ACTIVEBORDER);
  376. DrawEdge(hdc, &rcT, EDGE_RAISED, BF_RECT | BF_ADJUST);
  377. MyDrawFrame(hdc, &rcT, g_brushes[COLOR_ACTIVEBORDER], g_sizes[SIZE_FRAME].CurSize);
  378. MyDrawFrame(hdc, &rcT, g_brushes[COLOR_3DFACE], 1);
  379. // Caption
  380. rcT = RCZ(ELEMENT_ACTIVECAPTION);
  381. MyDrawBorderBelow(hdc, &rcT);
  382. // "clip" the caption title under the buttons
  383. rcT.left = RCZ(ELEMENT_ACTIVESYSBUT2).left - cxEdge;
  384. FillRect(hdc, &rcT, g_brushes[COLOR_GRADIENTACTIVECAPTION]);
  385. rcT.right = rcT.left;
  386. rcT.left = RCZ(ELEMENT_ACTIVECAPTION).left;
  387. DrawCaptionTemp(NULL, hdc, &rcT, g_fonts[FONT_CAPTION].hfont, hiconLogo, sm_Globals.m_szActive, DC_ACTIVE | DC_ICON | DC_TEXT | DC_GRADIENT);
  388. DrawFrameControl(hdc, &RCZ(ELEMENT_ACTIVESYSBUT1), DFC_CAPTION, DFCS_CAPTIONCLOSE);
  389. rcT = RCZ(ELEMENT_ACTIVESYSBUT2);
  390. rcT.right -= (rcT.right - rcT.left)/2;
  391. DrawFrameControl(hdc, &rcT, DFC_CAPTION, DFCS_CAPTIONMIN);
  392. rcT.left = rcT.right;
  393. rcT.right = RCZ(ELEMENT_ACTIVESYSBUT2).right;
  394. DrawFrameControl(hdc, &rcT, DFC_CAPTION, DFCS_CAPTIONMAX);
  395. // Menu
  396. rcT = RCZ(ELEMENT_MENUNORMAL);
  397. #if 0 // HACK TO SLIP USING DrawMenuBarTemp() which is not available on Memphis
  398. DrawMenuBarTemp(m_hwnd, hdc, &rcT, g_Options.m_hmenuSample, g_fonts[FONT_MENU].hfont);
  399. #else
  400. {
  401. // JMC: HACK - HARD CODED TEXT
  402. HFONT hOldFont = (HFONT)SelectObject(hdc, g_fonts[FONT_MENU].hfont);
  403. COLORREF clrrefOldText = SetTextColor(hdc, g_Options.m_schemePreview.m_rgb[COLOR_MENUTEXT]);
  404. COLORREF clrrefOldBk = SetBkColor(hdc, g_Options.m_schemePreview.m_rgb[COLOR_MENU]);
  405. int nOldMode = SetBkMode(hdc, OPAQUE);
  406. // LPCTSTR lpszText = __TEXT(" File Edit Help");
  407. TCHAR szText[200];
  408. LoadString(g_hInstDll, IDS_PREVIEWMENUTEXT, szText, ARRAYSIZE(szText));
  409. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcT, NULL, 0, NULL);
  410. DrawText(hdc, szText, lstrlen(szText), &rcT, DT_VCENTER | DT_SINGLELINE | DT_EXPANDTABS);
  411. SetTextColor(hdc, clrrefOldText);
  412. SetBkColor(hdc, clrrefOldBk);
  413. SetBkMode(hdc, nOldMode);
  414. SelectObject(hdc, hOldFont);
  415. }
  416. #endif
  417. MyDrawBorderBelow(hdc, &rcT);
  418. //
  419. // Client area
  420. //
  421. rcT = RCZ(ELEMENT_WINDOW);
  422. DrawEdge(hdc, &rcT, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
  423. FillRect(hdc, &rcT, g_brushes[COLOR_WINDOW]);
  424. // window text
  425. SetBkMode(hdc, TRANSPARENT);
  426. SetTextColor(hdc, g_Options.m_schemePreview.m_rgb[COLOR_WINDOWTEXT]);
  427. TextOut(hdc, RCZ(ELEMENT_WINDOW).left + 2*cxEdge, RCZ(ELEMENT_WINDOW).top + 2*cyEdge, sm_Globals.m_szWindowText, lstrlen(sm_Globals.m_szWindowText));
  428. //
  429. // scroll bar
  430. //
  431. rcT = RCZ(ELEMENT_SCROLLBAR);
  432. //MyDrawFrame(hdc, &rcT, g_brushes[COLOR_3DSHADOW], 1);
  433. //g_brushes[COLOR_SCROLLBAR]);
  434. //FillRect(hdc, &rcT, (HBRUSH)DefWindowProc(m_hwnd, WM_CTLCOLORSCROLLBAR, (WPARAM)hdc, (LPARAM)m_hwnd));
  435. FillRect(hdc, &rcT, g_brushes[COLOR_SCROLLBAR]);
  436. DrawFrameControl(hdc, &RCZ(ELEMENT_SCROLLUP), DFC_SCROLL, DFCS_SCROLLUP);
  437. DrawFrameControl(hdc, &RCZ(ELEMENT_SCROLLDOWN), DFC_SCROLL, DFCS_SCROLLDOWN);
  438. #if 0 // Don't draw message box
  439. //
  440. // MessageBox
  441. //
  442. rcT = RCZ(ELEMENT_MSGBOX);
  443. DrawEdge(hdc, &rcT, EDGE_RAISED, BF_RECT | BF_ADJUST);
  444. FillRect(hdc, &rcT, g_brushes[COLOR_3DFACE]);
  445. rcT = RCZ(ELEMENT_MSGBOXCAPTION);
  446. MyDrawBorderBelow(hdc, &rcT);
  447. // "clip" the caption title under the buttons
  448. rcT.left = RCZ(ELEMENT_MSGBOXSYSBUT).left - cxEdge;
  449. FillRect(hdc, &rcT, g_brushes[COLOR_GRADIENTACTIVECAPTION]);
  450. rcT.right = rcT.left;
  451. rcT.left = RCZ(ELEMENT_MSGBOXCAPTION).left;
  452. DrawCaptionTemp(NULL, hdc, &rcT, g_fonts[FONT_CAPTION].hfont, hiconLogo, sm_Globals.m_szMsgBox, DC_ACTIVE | DC_ICON | DC_TEXT | DC_GRADIENT);
  453. DrawFrameControl(hdc, &RCZ(ELEMENT_MSGBOXSYSBUT), DFC_CAPTION, DFCS_CAPTIONCLOSE);
  454. // message box text
  455. SetBkMode(hdc, TRANSPARENT);
  456. SetTextColor(hdc, g_Options.m_schemePreview.m_rgb[COLOR_WINDOWTEXT]);
  457. hfontOld = (HFONT)SelectObject(hdc, g_fonts[FONT_MSGBOX].hfont);
  458. TextOut(hdc, RCZ(ELEMENT_MSGBOX).left + 3*cxEdge, RCZ(ELEMENT_MSGBOXCAPTION).bottom + cyEdge,
  459. sm_Globals.m_szMsgBoxText, lstrlen(sm_Globals.m_szMsgBoxText));
  460. if (hfontOld)
  461. SelectObject(hdc, hfontOld);
  462. //
  463. // Button
  464. //
  465. rcT = RCZ(ELEMENT_BUTTON);
  466. DrawFrameControl(hdc, &rcT, DFC_BUTTON, DFCS_BUTTONPUSH);
  467. // ?????? what font should this use ??????
  468. SetBkMode(hdc, TRANSPARENT);
  469. SetTextColor(hdc, g_Options.m_schemePreview.m_rgb[COLOR_BTNTEXT]);
  470. DrawText(hdc, sm_Globals.m_szButton, -1, &rcT, DT_CENTER | DT_NOPREFIX |
  471. DT_SINGLELINE | DT_VCENTER);
  472. #endif
  473. SetBkColor(hdc, rgbBk);
  474. SetBkMode(hdc, nMode);
  475. if (hiconLogo)
  476. DestroyIcon(hiconLogo);
  477. SetSysColorsTemp(NULL, NULL, (UINT_PTR)hOldColors);
  478. if (hpalOld)
  479. {
  480. hpalOld = SelectPalette(hdc, hpalOld, FALSE);
  481. RealizePalette(hdc);
  482. }
  483. RestoreDC(hdc, -1);
  484. }
  485. void CLookPrev::OnRepaint()
  486. {
  487. HBITMAP hbmOld;
  488. if (m_hbmLook)
  489. {
  490. hbmOld = (HBITMAP)SelectObject(g_hdcMem, m_hbmLook);
  491. Draw(g_hdcMem);
  492. SelectObject(g_hdcMem, hbmOld);
  493. }
  494. InvalidateRect(m_hwnd, NULL, FALSE);
  495. }
  496. void CLookPrev::OnRecalc()
  497. {
  498. DWORD cxNormal;
  499. int cxDisabled, cxSelected;
  500. int cxAvgCharx2;
  501. RECT rc;
  502. HFONT hfontT;
  503. int cxFrame, cyFrame;
  504. int cyCaption;
  505. int i;
  506. SIZE sizButton;
  507. GetClientRect(m_hwnd, &rc);
  508. //
  509. // Get our drawing data
  510. //
  511. cxSize = GetSystemMetrics(SM_CXSIZE);
  512. cxFrame = (g_sizes[SIZE_FRAME].CurSize + 1) * cxBorder + cxEdge;
  513. cyFrame = (g_sizes[SIZE_FRAME].CurSize + 1) * cyBorder + cyEdge;
  514. cyCaption = g_sizes[SIZE_CAPTION].CurSize;
  515. //
  516. // Get text dimensions, with proper font.
  517. //
  518. hfontT = (HFONT)SelectObject(g_hdcMem, g_fonts[FONT_MENU].hfont);
  519. GetTextExtentPoint32(g_hdcMem, sm_Globals.m_szNormal, lstrlen(sm_Globals.m_szNormal), &sizButton);
  520. cxNormal = sizButton.cx;
  521. GetTextExtentPoint32(g_hdcMem, sm_Globals.m_szDisabled, lstrlen(sm_Globals.m_szDisabled), &sizButton);
  522. cxDisabled = sizButton.cx;
  523. GetTextExtentPoint32(g_hdcMem, sm_Globals.m_szSelected, lstrlen(sm_Globals.m_szSelected), &sizButton);
  524. cxSelected = sizButton.cx;
  525. // get the average width (USER style) of menu font
  526. GetTextExtentPoint32(g_hdcMem, g_szABC, 52, &sizButton);
  527. cxAvgCharx2 = 2 * (sizButton.cx / 52);
  528. // actual menu-handling widths of strings is bigger
  529. cxDisabled += cxAvgCharx2;
  530. cxSelected += cxAvgCharx2;
  531. cxNormal += cxAvgCharx2;
  532. SelectObject(g_hdcMem, hfontT);
  533. GetTextExtentPoint32(g_hdcMem, sm_Globals.m_szButton, lstrlen(sm_Globals.m_szButton), &sizButton);
  534. //
  535. // Desktop
  536. //
  537. RCZ(ELEMENT_DESKTOP) = rc;
  538. InflateRect(&rc, -8*cxBorder, -8*cyBorder);
  539. //
  540. // Windows
  541. //
  542. rc.bottom -= cyFrame + cyCaption;
  543. RCZ(ELEMENT_ACTIVEBORDER) = rc;
  544. OffsetRect(&RCZ(ELEMENT_ACTIVEBORDER), cxFrame,
  545. cyFrame + cyCaption + cyBorder);
  546. RCZ(ELEMENT_ACTIVEBORDER).bottom -= cyCaption;
  547. //
  548. // Inactive window
  549. //
  550. rc.right -= cyCaption;
  551. RCZ(ELEMENT_INACTIVEBORDER) = rc;
  552. // Caption
  553. InflateRect(&rc, -cxFrame, -cyFrame);
  554. rc.bottom = rc.top + cyCaption + cyBorder;
  555. RCZ(ELEMENT_INACTIVECAPTION) = rc;
  556. // close button
  557. InflateRect(&rc, -cxEdge, -cyEdge);
  558. rc.bottom -= cyBorder; // compensate for magic line under caption
  559. RCZ(ELEMENT_INACTIVESYSBUT1) = rc;
  560. RCZ(ELEMENT_INACTIVESYSBUT1).left = rc.right - (cyCaption - cxEdge);
  561. // min/max buttons
  562. RCZ(ELEMENT_INACTIVESYSBUT2) = rc;
  563. RCZ(ELEMENT_INACTIVESYSBUT2).right = RCZ(ELEMENT_INACTIVESYSBUT1).left - cxEdge;
  564. RCZ(ELEMENT_INACTIVESYSBUT2).left = RCZ(ELEMENT_INACTIVESYSBUT2).right -
  565. 2 * (cyCaption - cxEdge);
  566. #if 0
  567. //
  568. // small caption window
  569. //
  570. RCZ(ELEMENT_SMCAPTION) = RCZ(ELEMENT_ACTIVEBORDER);
  571. RCZ(ELEMENT_SMCAPTION).bottom = RCZ(ELEMENT_SMCAPTION).top;
  572. RCZ(ELEMENT_SMCAPTION).top -= g_sizes[SIZE_SMCAPTION].CurSize + cyEdge + 2 * cyBorder;
  573. RCZ(ELEMENT_SMCAPTION).right -= cxFrame;
  574. RCZ(ELEMENT_SMCAPTION).left = RCZ(ELEMENT_INACTIVECAPTION).right + 2 * cxFrame;
  575. RCZ(ELEMENT_SMCAPSYSBUT) = RCZ(ELEMENT_SMCAPTION);
  576. // deflate inside frame/border to caption and then another edge's worth
  577. RCZ(ELEMENT_SMCAPSYSBUT).right -= 2 * cxEdge + cxBorder;
  578. RCZ(ELEMENT_SMCAPSYSBUT).top += 2 * cxEdge + cxBorder;
  579. RCZ(ELEMENT_SMCAPSYSBUT).bottom -= cxEdge + cxBorder;
  580. RCZ(ELEMENT_SMCAPSYSBUT).left = RCZ(ELEMENT_SMCAPSYSBUT).right -
  581. (g_sizes[SIZE_SMCAPTION].CurSize - cxEdge);
  582. #endif
  583. //
  584. // Active window
  585. //
  586. // Caption
  587. rc = RCZ(ELEMENT_ACTIVEBORDER);
  588. InflateRect(&rc, -cxFrame, -cyFrame);
  589. RCZ(ELEMENT_ACTIVECAPTION) = rc;
  590. RCZ(ELEMENT_ACTIVECAPTION).bottom =
  591. RCZ(ELEMENT_ACTIVECAPTION).top + cyCaption + cyBorder;
  592. // close button
  593. RCZ(ELEMENT_ACTIVESYSBUT1) = RCZ(ELEMENT_ACTIVECAPTION);
  594. InflateRect(&RCZ(ELEMENT_ACTIVESYSBUT1), -cxEdge, -cyEdge);
  595. RCZ(ELEMENT_ACTIVESYSBUT1).bottom -= cyBorder; // compensate for magic line under caption
  596. RCZ(ELEMENT_ACTIVESYSBUT1).left = RCZ(ELEMENT_ACTIVESYSBUT1).right -
  597. (cyCaption - cxEdge);
  598. // min/max buttons
  599. RCZ(ELEMENT_ACTIVESYSBUT2) = RCZ(ELEMENT_ACTIVESYSBUT1);
  600. RCZ(ELEMENT_ACTIVESYSBUT2).right = RCZ(ELEMENT_ACTIVESYSBUT1).left - cxEdge;
  601. RCZ(ELEMENT_ACTIVESYSBUT2).left = RCZ(ELEMENT_ACTIVESYSBUT2).right -
  602. 2 * (cyCaption - cxEdge);
  603. // Menu
  604. rc.top = RCZ(ELEMENT_ACTIVECAPTION).bottom;
  605. RCZ(ELEMENT_MENUNORMAL) = rc;
  606. rc.top = RCZ(ELEMENT_MENUNORMAL).bottom = RCZ(ELEMENT_MENUNORMAL).top + g_sizes[SIZE_MENU].CurSize;
  607. RCZ(ELEMENT_MENUDISABLED) = RCZ(ELEMENT_MENUSELECTED) = RCZ(ELEMENT_MENUNORMAL);
  608. RCZ(ELEMENT_MENUDISABLED).left = RCZ(ELEMENT_MENUNORMAL).left + cxNormal;
  609. RCZ(ELEMENT_MENUDISABLED).right = RCZ(ELEMENT_MENUSELECTED).left =
  610. RCZ(ELEMENT_MENUDISABLED).left + cxDisabled;
  611. RCZ(ELEMENT_MENUSELECTED).right = RCZ(ELEMENT_MENUSELECTED).left + cxSelected;
  612. //
  613. // Client
  614. //
  615. RCZ(ELEMENT_WINDOW) = rc;
  616. //
  617. // Scrollbar
  618. //
  619. InflateRect(&rc, -cxEdge, -cyEdge); // take off client edge
  620. RCZ(ELEMENT_SCROLLBAR) = rc;
  621. rc.right = RCZ(ELEMENT_SCROLLBAR).left = rc.right - g_sizes[SIZE_SCROLL].CurSize;
  622. RCZ(ELEMENT_SCROLLUP) = RCZ(ELEMENT_SCROLLBAR);
  623. RCZ(ELEMENT_SCROLLUP).bottom = RCZ(ELEMENT_SCROLLBAR).top + g_sizes[SIZE_SCROLL].CurSize;
  624. RCZ(ELEMENT_SCROLLDOWN) = RCZ(ELEMENT_SCROLLBAR);
  625. RCZ(ELEMENT_SCROLLDOWN).top = RCZ(ELEMENT_SCROLLBAR).bottom - g_sizes[SIZE_SCROLL].CurSize;
  626. //
  627. // Message Box
  628. //
  629. rc.top = RCZ(ELEMENT_WINDOW).top + (RCZ(ELEMENT_WINDOW).bottom - RCZ(ELEMENT_WINDOW).top) / 2;
  630. rc.bottom = RCZ(ELEMENT_DESKTOP).bottom - 2*cyEdge;
  631. rc.left = RCZ(ELEMENT_WINDOW).left + 2*cyEdge;
  632. rc.right = RCZ(ELEMENT_WINDOW).left + (RCZ(ELEMENT_WINDOW).right - RCZ(ELEMENT_WINDOW).left) / 2 + 3*cyCaption;
  633. RCZ(ELEMENT_MSGBOX) = rc;
  634. // Caption
  635. RCZ(ELEMENT_MSGBOXCAPTION) = rc;
  636. RCZ(ELEMENT_MSGBOXCAPTION).top += cyEdge + cyBorder;
  637. RCZ(ELEMENT_MSGBOXCAPTION).bottom = RCZ(ELEMENT_MSGBOXCAPTION).top + cyCaption + cyBorder;
  638. RCZ(ELEMENT_MSGBOXCAPTION).left += cxEdge + cxBorder;
  639. RCZ(ELEMENT_MSGBOXCAPTION).right -= cxEdge + cxBorder;
  640. RCZ(ELEMENT_MSGBOXSYSBUT) = RCZ(ELEMENT_MSGBOXCAPTION);
  641. InflateRect(&RCZ(ELEMENT_MSGBOXSYSBUT), -cxEdge, -cyEdge);
  642. RCZ(ELEMENT_MSGBOXSYSBUT).left = RCZ(ELEMENT_MSGBOXSYSBUT).right -
  643. (cyCaption - cxEdge);
  644. RCZ(ELEMENT_MSGBOXSYSBUT).bottom -= cyBorder; // line under caption
  645. // Button
  646. RCZ(ELEMENT_BUTTON).bottom = RCZ(ELEMENT_MSGBOX).bottom - (4*cyBorder + cyEdge);
  647. RCZ(ELEMENT_BUTTON).top = RCZ(ELEMENT_BUTTON).bottom - (sizButton.cy + 8 * cyBorder);
  648. i = (RCZ(ELEMENT_BUTTON).bottom - RCZ(ELEMENT_BUTTON).top) * 3;
  649. RCZ(ELEMENT_BUTTON).left = (rc.left + (rc.right - rc.left)/2) - i/2;
  650. RCZ(ELEMENT_BUTTON).right = RCZ(ELEMENT_BUTTON).left + i;
  651. }
  652. /////////////////////////////////////////////////////////
  653. // Support functions
  654. // ----------------------------------------------------------------------------
  655. //
  656. // MyDrawFrame() -
  657. //
  658. // Draws bordered frame, border size cl, and adjusts passed in rect.
  659. //
  660. // ----------------------------------------------------------------------------
  661. void MyDrawFrame(HDC hdc, LPRECT prc, HBRUSH hbrColor, int cl)
  662. {
  663. HBRUSH hbr;
  664. int cx, cy;
  665. RECT rcT;
  666. rcT = *prc;
  667. cx = cl * cxBorder;
  668. cy = cl * cyBorder;
  669. hbr = (HBRUSH)SelectObject(hdc, hbrColor);
  670. PatBlt(hdc, rcT.left, rcT.top, cx, rcT.bottom - rcT.top, PATCOPY);
  671. rcT.left += cx;
  672. PatBlt(hdc, rcT.left, rcT.top, rcT.right - rcT.left, cy, PATCOPY);
  673. rcT.top += cy;
  674. rcT.right -= cx;
  675. PatBlt(hdc, rcT.right, rcT.top, cx, rcT.bottom - rcT.top, PATCOPY);
  676. rcT.bottom -= cy;
  677. PatBlt(hdc, rcT.left, rcT.bottom, rcT.right - rcT.left, cy, PATCOPY);
  678. hbr = (HBRUSH)SelectObject(hdc, hbr);
  679. *prc = rcT;
  680. }
  681. /*
  682. ** draw a cyBorder band of 3DFACE at the bottom of the given rectangle.
  683. ** also, adjust the rectangle accordingly.
  684. */
  685. void MyDrawBorderBelow(HDC hdc, LPRECT prc)
  686. {
  687. int i;
  688. i = prc->top;
  689. prc->top = prc->bottom - cyBorder;
  690. FillRect(hdc, prc, g_brushes[COLOR_3DFACE]);
  691. prc->top = i;
  692. prc->bottom -= cyBorder;
  693. }
  694. /*-------------------------------------------------------------------
  695. ** draw a full window caption with system menu, minimize button,
  696. ** maximize button, and text.
  697. **-------------------------------------------------------------------*/
  698. void DrawFullCaption(HDC hdc, LPRECT prc, LPTSTR lpszTitle, UINT flags)
  699. {
  700. int iRight;
  701. int iFont;
  702. SaveDC(hdc);
  703. // special case gross for small caption that already drew on bottom
  704. if (!(flags & DC_SMALLCAP))
  705. MyDrawBorderBelow(hdc, prc);
  706. iRight = prc->right;
  707. prc->right = prc->left + cxSize;
  708. DrawFrameControl(hdc, prc, DFC_CAPTION, DFCS_CAPTIONCLOSE);
  709. prc->left = prc->right;
  710. prc->right = iRight - 2*cxSize;
  711. iFont = flags & DC_SMALLCAP ? FONT_SMCAPTION : FONT_CAPTION;
  712. DrawCaptionTemp(NULL, hdc, prc, g_fonts[iFont].hfont, NULL, lpszTitle, flags | DC_ICON | DC_TEXT);
  713. prc->left = prc->right;
  714. prc->right = prc->left + cxSize;
  715. DrawFrameControl(hdc, prc, DFC_CAPTION, DFCS_CAPTIONMIN);
  716. prc->left = prc->right;
  717. prc->right = prc->left + cxSize;
  718. DrawFrameControl(hdc, prc, DFC_CAPTION, DFCS_CAPTIONMAX);
  719. RestoreDC(hdc, -1);
  720. }