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.

3066 lines
86 KiB

  1. /*
  2. ** CUTILS.C
  3. **
  4. ** Common utilities for common controls
  5. **
  6. */
  7. #include "ctlspriv.h"
  8. #include "advpub.h" // For REGINSTALL
  9. #include <ntverp.h>
  10. #include "ccver.h" // App compat version hacks
  11. #include <shfusion.h>
  12. #ifndef SSW_EX_IGNORESETTINGS
  13. #define SSW_EX_IGNORESETTINGS 0x00040000 // ignore system settings to turn on/off smooth scroll
  14. #endif
  15. // the insert mark is 6 pixels wide
  16. #define INSERTMARKSIZE 6
  17. //
  18. // Globals - REVIEW_32
  19. //
  20. BOOL g_fAnimate;
  21. BOOL g_fSmoothScroll;
  22. BOOL g_fEnableBalloonTips = TRUE;
  23. int g_cxEdge;
  24. int g_cyEdge;
  25. int g_cxEdgeScaled;
  26. int g_cyEdgeScaled;
  27. int g_cxBorder;
  28. int g_cyBorder;
  29. int g_cxScreen;
  30. int g_cyScreen;
  31. int g_cxFrame;
  32. int g_cyFrame;
  33. int g_cxVScroll;
  34. int g_cyHScroll;
  35. int g_cxIcon, g_cyIcon;
  36. int g_cxSmIcon, g_cySmIcon;
  37. int g_cxIconSpacing, g_cyIconSpacing;
  38. int g_cxIconMargin, g_cyIconMargin;
  39. int g_cyLabelSpace;
  40. int g_cxLabelMargin;
  41. int g_cxDoubleClk;
  42. int g_cyDoubleClk;
  43. int g_cxScrollbar;
  44. int g_cyScrollbar;
  45. int g_fDragFullWindows;
  46. double g_dScaleX = 1.0;
  47. double g_dScaleY = 1.0;
  48. BOOL g_fScale = FALSE;
  49. int g_iDPI = 96.0;
  50. BOOL g_fHighContrast = FALSE;
  51. int g_cyCompensateInternalLeading;
  52. int g_fLeftAligned = FALSE;
  53. COLORREF g_clrWindow;
  54. COLORREF g_clrWindowText;
  55. COLORREF g_clrWindowFrame;
  56. COLORREF g_clrGrayText;
  57. COLORREF g_clrBtnText;
  58. COLORREF g_clrBtnFace;
  59. COLORREF g_clrBtnShadow;
  60. COLORREF g_clrBtnHighlight;
  61. COLORREF g_clrHighlight;
  62. COLORREF g_clrHighlightText;
  63. COLORREF g_clrInfoText;
  64. COLORREF g_clrInfoBk;
  65. COLORREF g_clr3DDkShadow;
  66. COLORREF g_clr3DLight;
  67. COLORREF g_clrMenuHilight;
  68. COLORREF g_clrMenuText;
  69. HBRUSH g_hbrGrayText;
  70. HBRUSH g_hbrWindow;
  71. HBRUSH g_hbrWindowText;
  72. HBRUSH g_hbrWindowFrame;
  73. HBRUSH g_hbrBtnFace;
  74. HBRUSH g_hbrBtnHighlight;
  75. HBRUSH g_hbrBtnShadow;
  76. HBRUSH g_hbrHighlight;
  77. HBRUSH g_hbrMenuHilight;
  78. HBRUSH g_hbrMenuText;
  79. DWORD g_dwHoverSelectTimeout;
  80. HFONT g_hfontSystem;
  81. void InitGlobalColors()
  82. {
  83. BOOL fFlatMenuMode = FALSE;
  84. static fMenuColorAlloc = FALSE;
  85. g_clrWindow = GetSysColor(COLOR_WINDOW);
  86. g_clrWindowText = GetSysColor(COLOR_WINDOWTEXT);
  87. g_clrWindowFrame = GetSysColor(COLOR_WINDOWFRAME);
  88. g_clrGrayText = GetSysColor(COLOR_GRAYTEXT);
  89. g_clrBtnText = GetSysColor(COLOR_BTNTEXT);
  90. g_clrBtnFace = GetSysColor(COLOR_BTNFACE);
  91. g_clrBtnShadow = GetSysColor(COLOR_BTNSHADOW);
  92. g_clrBtnHighlight = GetSysColor(COLOR_BTNHIGHLIGHT);
  93. g_clrHighlight = GetSysColor(COLOR_HIGHLIGHT);
  94. g_clrHighlightText = GetSysColor(COLOR_HIGHLIGHTTEXT);
  95. g_clrInfoText = GetSysColor(COLOR_INFOTEXT);
  96. g_clrInfoBk = GetSysColor(COLOR_INFOBK);
  97. g_clr3DDkShadow = GetSysColor(COLOR_3DDKSHADOW);
  98. g_clr3DLight = GetSysColor(COLOR_3DLIGHT);
  99. SystemParametersInfo(SPI_GETFLATMENU, 0, (PVOID)&fFlatMenuMode, 0);
  100. if (fFlatMenuMode)
  101. {
  102. g_clrMenuHilight = GetSysColor(COLOR_MENUHILIGHT);
  103. g_clrMenuText = GetSysColor(COLOR_MENUTEXT);
  104. }
  105. else
  106. {
  107. g_clrMenuHilight = GetBorderSelectColor(60, GetSysColor(COLOR_HIGHLIGHT));
  108. g_clrMenuText = GetSysColor(COLOR_HIGHLIGHTTEXT);
  109. }
  110. g_hbrGrayText = GetSysColorBrush(COLOR_GRAYTEXT);
  111. g_hbrWindow = GetSysColorBrush(COLOR_WINDOW);
  112. g_hbrWindowText = GetSysColorBrush(COLOR_WINDOWTEXT);
  113. g_hbrWindowFrame = GetSysColorBrush(COLOR_WINDOWFRAME);
  114. g_hbrBtnFace = GetSysColorBrush(COLOR_BTNFACE);
  115. g_hbrBtnHighlight = GetSysColorBrush(COLOR_BTNHIGHLIGHT);
  116. g_hbrBtnShadow = GetSysColorBrush(COLOR_BTNSHADOW);
  117. g_hbrHighlight = GetSysColorBrush(COLOR_HIGHLIGHT);
  118. g_hfontSystem = GetStockObject(SYSTEM_FONT);
  119. if (fMenuColorAlloc)
  120. {
  121. DeleteObject(g_hbrMenuHilight);
  122. }
  123. if (fFlatMenuMode)
  124. {
  125. fMenuColorAlloc = FALSE;
  126. g_hbrMenuHilight = GetSysColorBrush(COLOR_MENUHILIGHT);
  127. g_hbrMenuText = GetSysColorBrush(COLOR_MENUTEXT);
  128. }
  129. else
  130. {
  131. fMenuColorAlloc = TRUE;
  132. g_hbrMenuHilight = CreateSolidBrush(g_clrMenuHilight);
  133. g_hbrMenuText = GetSysColorBrush(COLOR_HIGHLIGHTTEXT);
  134. }
  135. }
  136. #define CCS_ALIGN (CCS_TOP | CCS_NOMOVEY | CCS_BOTTOM)
  137. ///
  138. //
  139. // Implement MapWindowPoints as if the hwndFrom and hwndTo aren't
  140. // mirrored. This is used when any of the windows (hwndFrom or hwndTo)
  141. // are mirrored. See below. [samera]
  142. //
  143. int TrueMapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT cPoints)
  144. {
  145. int dx, dy;
  146. RECT rcFrom={0,0,0,0}, rcTo={0,0,0,0};
  147. if (hwndFrom) {
  148. GetClientRect(hwndFrom, &rcFrom);
  149. MapWindowPoints(hwndFrom, NULL, (LPPOINT)&rcFrom.left, 2);
  150. }
  151. if (hwndTo) {
  152. GetClientRect(hwndTo, &rcTo);
  153. MapWindowPoints(hwndTo, NULL, (LPPOINT)&rcTo.left, 2);
  154. }
  155. dx = rcFrom.left - rcTo.left;
  156. dy = rcFrom.top - rcTo.top;
  157. /*
  158. * Map the points
  159. */
  160. while (cPoints--) {
  161. lppt->x += dx;
  162. lppt->y += dy;
  163. ++lppt;
  164. }
  165. return MAKELONG(dx, dy);
  166. }
  167. // Note that the default alignment is CCS_BOTTOM
  168. //
  169. void NewSize(HWND hWnd, int nThickness, LONG style, int left, int top, int width, int height)
  170. {
  171. // Resize the window unless the user said not to
  172. //
  173. if (!(style & CCS_NORESIZE))
  174. {
  175. RECT rc, rcWindow, rcBorder;
  176. // Remember size that was passed in and don't bother calling SetWindowPos if we're not
  177. // actually going to change the window size
  178. int leftSave = left;
  179. int topSave = top;
  180. int widthSave = width;
  181. int heightSave = height;
  182. // Calculate the borders around the client area of the status bar
  183. GetWindowRect(hWnd, &rcWindow);
  184. rcWindow.right -= rcWindow.left; // -> dx
  185. rcWindow.bottom -= rcWindow.top; // -> dy
  186. GetClientRect(hWnd, &rc);
  187. //
  188. // If the window is mirrored, mirror the anchor point
  189. // since it will be passed to SWP which accepts screen
  190. // ccordinates. This mainly fixes the display of status bar
  191. // and others. [samera]
  192. //
  193. if (IS_WINDOW_RTL_MIRRORED(hWnd))
  194. {
  195. TrueMapWindowPoints(hWnd, NULL, (LPPOINT)&rc.left, 1);
  196. }
  197. else
  198. {
  199. ClientToScreen(hWnd, (LPPOINT)&rc);
  200. }
  201. rcBorder.left = rc.left - rcWindow.left;
  202. rcBorder.top = rc.top - rcWindow.top ;
  203. rcBorder.right = rcWindow.right - rc.right - rcBorder.left;
  204. rcBorder.bottom = rcWindow.bottom - rc.bottom - rcBorder.top ;
  205. if (style & CCS_VERT)
  206. nThickness += rcBorder.left + rcBorder.right;
  207. else
  208. nThickness += rcBorder.top + rcBorder.bottom;
  209. // Check whether to align to the parent window
  210. //
  211. if (style & CCS_NOPARENTALIGN)
  212. {
  213. // Check out whether this bar is top aligned or bottom aligned
  214. //
  215. switch (style & CCS_ALIGN)
  216. {
  217. case CCS_TOP:
  218. case CCS_NOMOVEY:
  219. break;
  220. default: // CCS_BOTTOM
  221. if(style & CCS_VERT)
  222. left = left + width - nThickness;
  223. else
  224. top = top + height - nThickness;
  225. }
  226. }
  227. else
  228. {
  229. // It is assumed there is a parent by default
  230. //
  231. GetClientRect(GetParent(hWnd), &rc);
  232. // Don't forget to account for the borders
  233. //
  234. if(style & CCS_VERT)
  235. {
  236. top = -rcBorder.right;
  237. height = rc.bottom + rcBorder.top + rcBorder.bottom;
  238. }
  239. else
  240. {
  241. left = -rcBorder.left;
  242. width = rc.right + rcBorder.left + rcBorder.right;
  243. }
  244. if ((style & CCS_ALIGN) == CCS_TOP)
  245. {
  246. if(style & CCS_VERT)
  247. left = -rcBorder.left;
  248. else
  249. top = -rcBorder.top;
  250. }
  251. else if ((style & CCS_ALIGN) != CCS_NOMOVEY)
  252. {
  253. if (style & CCS_VERT)
  254. left = rc.right - nThickness + rcBorder.right;
  255. else
  256. top = rc.bottom - nThickness + rcBorder.bottom;
  257. }
  258. }
  259. if (!(style & CCS_NOMOVEY) && !(style & CCS_NODIVIDER))
  260. {
  261. if (style & CCS_VERT)
  262. left += g_cxEdge;
  263. else
  264. top += g_cyEdge; // double pixel edge thing
  265. }
  266. if(style & CCS_VERT)
  267. width = nThickness;
  268. else
  269. height = nThickness;
  270. SetWindowPos(hWnd, NULL, left, top, width, height, SWP_NOZORDER);
  271. }
  272. }
  273. BOOL MGetTextExtent(HDC hdc, LPCTSTR lpstr, int cnt, int * pcx, int * pcy)
  274. {
  275. BOOL fSuccess;
  276. SIZE size = {0,0};
  277. if (cnt == -1)
  278. cnt = lstrlen(lpstr);
  279. fSuccess=GetTextExtentPoint(hdc, lpstr, cnt, &size);
  280. if (pcx)
  281. *pcx=size.cx;
  282. if (pcy)
  283. *pcy=size.cy;
  284. return fSuccess;
  285. }
  286. // these are the default colors used to map the dib colors
  287. // to the current system colors
  288. #define RGB_BUTTONTEXT (RGB(000,000,000)) // black
  289. #define RGB_BUTTONSHADOW (RGB(128,128,128)) // dark grey
  290. #define RGB_BUTTONFACE (RGB(192,192,192)) // bright grey
  291. #define RGB_BUTTONHILIGHT (RGB(255,255,255)) // white
  292. #define RGB_BACKGROUNDSEL (RGB(000,000,255)) // blue
  293. #define RGB_BACKGROUND (RGB(255,000,255)) // magenta
  294. #define FlipColor(rgb) (RGB(GetBValue(rgb), GetGValue(rgb), GetRValue(rgb)))
  295. #define MAX_COLOR_MAPS 16
  296. void _MapBitmapColors(LPBITMAPINFOHEADER pbih, LPCOLORMAP pcmp, int iCmps, COLOR_STRUCT* pcsMask, UINT cMask, DWORD wFlags)
  297. {
  298. static const COLORMAP c_acmpSys[] =
  299. {
  300. { RGB_BUTTONTEXT, COLOR_BTNTEXT }, // black
  301. { RGB_BUTTONSHADOW, COLOR_BTNSHADOW }, // dark grey
  302. { RGB_BUTTONFACE, COLOR_BTNFACE }, // bright grey
  303. { RGB_BUTTONHILIGHT, COLOR_BTNHIGHLIGHT }, // white
  304. { RGB_BACKGROUNDSEL, COLOR_HIGHLIGHT }, // blue
  305. { RGB_BACKGROUND, COLOR_WINDOW }, // magenta
  306. };
  307. COLORMAP acmpDef[ARRAYSIZE(c_acmpSys)];
  308. COLORMAP acmpDIB[MAX_COLOR_MAPS];
  309. COLOR_STRUCT* pcs = (COLOR_STRUCT*)(((LPBYTE)pbih) + pbih->biSize);
  310. int i;
  311. if (!pcmp)
  312. {
  313. // Get system colors for the default color map
  314. for (i = 0; i < ARRAYSIZE(acmpDef); i++)
  315. {
  316. acmpDef[i].from = c_acmpSys[i].from;
  317. acmpDef[i].to = GetSysColor((int)c_acmpSys[i].to);
  318. }
  319. pcmp = acmpDef;
  320. iCmps = ARRAYSIZE(acmpDef);
  321. }
  322. else
  323. {
  324. // Sanity check color map count
  325. if (iCmps > MAX_COLOR_MAPS)
  326. iCmps = MAX_COLOR_MAPS;
  327. }
  328. for (i = 0; i < iCmps; i++)
  329. {
  330. acmpDIB[i].to = FlipColor(pcmp[i].to);
  331. acmpDIB[i].from = FlipColor(pcmp[i].from);
  332. }
  333. // if we are creating a mask, build a color table with white
  334. // marking the transparent section (where it used to be background)
  335. // and black marking the opaque section (everything else). this
  336. // table is used below to build the mask using the original DIB bits.
  337. if (wFlags & CMB_MASKED)
  338. {
  339. COLOR_STRUCT csBkgnd = FlipColor(RGB_BACKGROUND);
  340. ASSERT(cMask == MAX_COLOR_MAPS);
  341. for (i = 0; i < MAX_COLOR_MAPS; i++)
  342. {
  343. if (pcs[i] == csBkgnd)
  344. pcsMask[i] = 0xFFFFFF; // transparent section
  345. else
  346. pcsMask[i] = 0x000000; // opaque section
  347. }
  348. }
  349. for (i = 0; i < MAX_COLOR_MAPS; i++)
  350. {
  351. int j;
  352. for (j = 0; j < iCmps; j++)
  353. {
  354. if ((pcs[i] & 0x00FFFFFF) == acmpDIB[j].from)
  355. {
  356. pcs[i] = acmpDIB[j].to;
  357. break;
  358. }
  359. }
  360. }
  361. }
  362. HBITMAP _CreateMappedBitmap(LPBITMAPINFOHEADER pbih, LPBYTE lpBits, COLOR_STRUCT* pcsMask, UINT cMask, UINT wFlags)
  363. {
  364. HBITMAP hbm = NULL;
  365. HDC hdc = GetDC(NULL);
  366. if (hdc)
  367. {
  368. HDC hdcMem = CreateCompatibleDC(hdc);
  369. if (hdcMem)
  370. {
  371. int nWidth = (int)pbih->biWidth;
  372. int nHeight = (int)pbih->biHeight;
  373. if (wFlags & CMB_DIBSECTION)
  374. {
  375. // Have to edit the header slightly, since CreateDIBSection supports
  376. // only BI_RGB and BI_BITFIELDS. This is the same whackery that USER
  377. // does in LoadImage.
  378. LPVOID pvDummy;
  379. DWORD dwCompression = pbih->biCompression;
  380. if (dwCompression != BI_BITFIELDS)
  381. pbih->biCompression = BI_RGB;
  382. hbm = CreateDIBSection(hdc, (LPBITMAPINFO)pbih, DIB_RGB_COLORS,
  383. &pvDummy, NULL, 0);
  384. pbih->biCompression = dwCompression;
  385. }
  386. if (hbm == NULL)
  387. {
  388. // If CMB_DIBSECTION failed, then create a DDB instead. Not perfect,
  389. // but better than creating nothing. We also get here if the caller
  390. // didn't ask for a DIB section.
  391. // if creating a mask, the bitmap needs to be twice as wide.
  392. int nWidthBmp;
  393. if (wFlags & CMB_MASKED)
  394. nWidthBmp = nWidth * 2;
  395. else
  396. nWidthBmp = nWidth;
  397. hbm = CreateCompatibleBitmap(hdc, nWidthBmp, nHeight);
  398. }
  399. if (hbm)
  400. {
  401. HBITMAP hbmOld = SelectObject(hdcMem, hbm);
  402. // set the main image
  403. StretchDIBits(hdcMem, 0, 0, nWidth, nHeight, 0, 0, nWidth, nHeight, lpBits,
  404. (LPBITMAPINFO)pbih, DIB_RGB_COLORS, SRCCOPY);
  405. // if building a mask, replace the DIB's color table with the
  406. // mask's black/white table and set the bits. in order to
  407. // complete the masked effect, the actual image needs to be
  408. // modified so that it has the color black in all sections
  409. // that are to be transparent.
  410. if (wFlags & CMB_MASKED)
  411. {
  412. if (cMask > 0)
  413. {
  414. COLOR_STRUCT* pcs = (COLOR_STRUCT*)(((LPBYTE)pbih) + pbih->biSize);
  415. hmemcpy(pcs, pcsMask, cMask * sizeof(RGBQUAD));
  416. }
  417. StretchDIBits(hdcMem, nWidth, 0, nWidth, nHeight, 0, 0, nWidth, nHeight, lpBits,
  418. (LPBITMAPINFO)pbih, DIB_RGB_COLORS, SRCCOPY);
  419. BitBlt(hdcMem, 0, 0, nWidth, nHeight, hdcMem, nWidth, 0, 0x00220326); // DSna
  420. }
  421. SelectObject(hdcMem, hbmOld);
  422. }
  423. DeleteObject(hdcMem);
  424. }
  425. ReleaseDC(NULL, hdc);
  426. }
  427. return hbm;
  428. }
  429. // This is almost the same as LoadImage(..., LR_MAP3DCOLORS) except that
  430. //
  431. // - The app can specify a custom color map,
  432. // - The default color map maps colors beyond the 3D colors,
  433. //
  434. HBITMAP CreateMappedBitmap(HINSTANCE hInstance, INT_PTR idBitmap,
  435. UINT wFlags, LPCOLORMAP lpColorMap, int iNumMaps)
  436. {
  437. HBITMAP hbm = NULL;
  438. BOOL bColorTable;
  439. HRSRC hrsrc = FindResource(hInstance, MAKEINTRESOURCE(idBitmap), RT_BITMAP);
  440. if (hrsrc)
  441. {
  442. HGLOBAL hglob = LoadResource(hInstance, hrsrc);
  443. LPBITMAPINFOHEADER pbihRes = (LPBITMAPINFOHEADER)LockResource(hglob);
  444. if (pbihRes)
  445. {
  446. // munge on a copy of the color table instead of the original
  447. // (prevent possibility of "reload" with messed table
  448. UINT cbOffset;
  449. LPBITMAPINFOHEADER pbih;
  450. WORD biBitCount = pbihRes->biBitCount;
  451. if ((biBitCount > 8) && (pbihRes->biCompression == BI_RGB))
  452. {
  453. // No bmiColors table, image bits start right after header
  454. cbOffset = pbihRes->biSize;
  455. bColorTable = FALSE;
  456. }
  457. else
  458. {
  459. // Bits start after bmiColors table
  460. cbOffset = pbihRes->biSize + ((1 << (pbihRes->biBitCount)) * sizeof(RGBQUAD));
  461. bColorTable = TRUE;
  462. }
  463. pbih = (LPBITMAPINFOHEADER)LocalAlloc(LPTR, cbOffset);
  464. if (pbih)
  465. {
  466. COLOR_STRUCT acsMask[MAX_COLOR_MAPS];
  467. LPBYTE lpBits = (LPBYTE)(pbihRes) + cbOffset;
  468. UINT uColorTableLength = (bColorTable ? ARRAYSIZE(acsMask) : 0);
  469. memcpy(pbih, pbihRes, cbOffset);
  470. if (bColorTable)
  471. _MapBitmapColors(pbih, lpColorMap, iNumMaps, acsMask, uColorTableLength, wFlags);
  472. hbm = _CreateMappedBitmap(pbih, lpBits, acsMask, uColorTableLength, wFlags);
  473. LocalFree(pbih);
  474. }
  475. UnlockResource(hglob);
  476. }
  477. FreeResource(hrsrc);
  478. }
  479. return hbm;
  480. }
  481. // moved from shelldll\dragdrop.c
  482. // should caller pass in message that indicates termination
  483. // (WM_LBUTTONUP, WM_RBUTTONUP)?
  484. //
  485. // in:
  486. // hwnd to do check on
  487. // x, y in client coordinates
  488. //
  489. // returns:
  490. // TRUE the user began to drag (moved mouse outside double click rect)
  491. // FALSE mouse came up inside click rect
  492. //
  493. // FEATURE, should support VK_ESCAPE to cancel
  494. BOOL CheckForDragBegin(HWND hwnd, int x, int y)
  495. {
  496. RECT rc;
  497. int dxClickRect = GetSystemMetrics(SM_CXDRAG);
  498. int dyClickRect = GetSystemMetrics(SM_CYDRAG);
  499. if (dxClickRect < 4)
  500. {
  501. dxClickRect = dyClickRect = 4;
  502. }
  503. // See if the user moves a certain number of pixels in any direction
  504. SetRect(&rc, x - dxClickRect, y - dyClickRect, x + dxClickRect, y + dyClickRect);
  505. MapWindowRect(hwnd, HWND_DESKTOP, &rc); // client -> screen
  506. //
  507. // SUBTLE! We use PeekMessage+WaitMessage instead of GetMessage,
  508. // because WaitMessage will return when there is an incoming
  509. // SendMessage, whereas GetMessage does not. This is important,
  510. // because the incoming message might've been WM_CAPTURECHANGED.
  511. //
  512. SetCapture(hwnd);
  513. do {
  514. MSG32 msg32;
  515. if (PeekMessage32(&msg32, NULL, 0, 0, PM_REMOVE, TRUE))
  516. {
  517. // See if the application wants to process the message...
  518. if (CallMsgFilter32(&msg32, MSGF_COMMCTRL_BEGINDRAG, TRUE) != 0)
  519. continue;
  520. switch (msg32.message) {
  521. case WM_LBUTTONUP:
  522. case WM_RBUTTONUP:
  523. case WM_LBUTTONDOWN:
  524. case WM_RBUTTONDOWN:
  525. ReleaseCapture();
  526. return FALSE;
  527. case WM_MOUSEMOVE:
  528. if (IsWindow(hwnd) && !PtInRect(&rc, msg32.pt)) {
  529. ReleaseCapture();
  530. return TRUE;
  531. }
  532. break;
  533. default:
  534. TranslateMessage32(&msg32, TRUE);
  535. DispatchMessage32(&msg32, TRUE);
  536. break;
  537. }
  538. }
  539. else WaitMessage();
  540. // WM_CANCELMODE messages will unset the capture, in that
  541. // case I want to exit this loop
  542. } while (IsWindow(hwnd) && GetCapture() == hwnd);
  543. return FALSE;
  544. }
  545. /* Regular StrToInt; stops at first non-digit. */
  546. int WINAPI StrToInt(LPCTSTR lpSrc) // atoi()
  547. {
  548. #define ISDIGIT(c) ((c) >= TEXT('0') && (c) <= TEXT('9'))
  549. int n = 0;
  550. BOOL bNeg = FALSE;
  551. if (*lpSrc == TEXT('-')) {
  552. bNeg = TRUE;
  553. lpSrc++;
  554. }
  555. while (ISDIGIT(*lpSrc)) {
  556. n *= 10;
  557. n += *lpSrc - TEXT('0');
  558. lpSrc++;
  559. }
  560. return bNeg ? -n : n;
  561. }
  562. //
  563. // Wrappers for StrToInt
  564. //
  565. int WINAPI StrToIntA(LPCSTR lpSrc) // atoi()
  566. {
  567. LPWSTR lpString;
  568. INT iResult;
  569. lpString = ProduceWFromA (CP_ACP, lpSrc);
  570. if (!lpString) {
  571. return 0;
  572. }
  573. iResult = StrToIntW(lpString);
  574. FreeProducedString (lpString);
  575. return iResult;
  576. }
  577. //
  578. // From zmouse.h in the Magellan SDK
  579. //
  580. #define MSH_MOUSEWHEEL TEXT("MSWHEEL_ROLLMSG")
  581. // Class name for Magellan/Z MSWHEEL window
  582. // use FindWindow to get hwnd to MSWHEEL
  583. #define MOUSEZ_CLASSNAME TEXT("MouseZ") // wheel window class
  584. #define MOUSEZ_TITLE TEXT("Magellan MSWHEEL") // wheel window title
  585. #define MSH_WHEELMODULE_CLASS (MOUSEZ_CLASSNAME)
  586. #define MSH_WHEELMODULE_TITLE (MOUSEZ_TITLE)
  587. #define MSH_SCROLL_LINES TEXT("MSH_SCROLL_LINES_MSG")
  588. #define DI_GETDRAGIMAGE TEXT("ShellGetDragImage") // Copied from Shlobj.w
  589. UINT g_msgMSWheel;
  590. UINT g_ucScrollLines = 3; /* default */
  591. int gcWheelDelta;
  592. UINT g_uDragImages;
  593. // --------------------------------------------------------------------------
  594. // _TrackMouseEvent() entrypoint
  595. //
  596. // calls TrackMouseEvent because we run on an OS where this exists
  597. //
  598. // --------------------------------------------------------------------------
  599. BOOL WINAPI _TrackMouseEvent(LPTRACKMOUSEEVENT lpTME)
  600. {
  601. return TrackMouseEvent(lpTME);
  602. }
  603. //
  604. // Checks the process to see if it is running under the system SID
  605. //
  606. BOOL IsSystemProcess()
  607. {
  608. BOOL bRet = FALSE; // assume we are not a system process
  609. HANDLE hProcessToken;
  610. if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hProcessToken))
  611. {
  612. PSID pSIDSystem;
  613. static SID_IDENTIFIER_AUTHORITY sSystemSidAuthority = SECURITY_NT_AUTHORITY;
  614. if (AllocateAndInitializeSid(&sSystemSidAuthority,
  615. 1,
  616. SECURITY_LOCAL_SYSTEM_RID,
  617. 0, 0, 0, 0, 0, 0, 0,
  618. &pSIDSystem))
  619. {
  620. CheckTokenMembership(hProcessToken, pSIDSystem, &bRet);
  621. FreeSid(pSIDSystem);
  622. }
  623. CloseHandle(hProcessToken);
  624. }
  625. return bRet;
  626. }
  627. //
  628. // !! WARNING !! - Be very careful about opening HKCU in InitGlobalMetrics(). Basically this gets
  629. // called during processattach and system process will end up loading the user hive
  630. // and because advapi32 is lame we end up pinning the hive for the life of this process.
  631. //
  632. void InitGlobalMetrics(WPARAM wParam)
  633. {
  634. static BOOL fInitMouseWheel;
  635. static HWND hwndMSWheel;
  636. static UINT msgMSWheelGetScrollLines;
  637. HDC hdcScreen;
  638. BOOL fRemoteSession = (BOOL)GetSystemMetrics( SM_REMOTESESSION );
  639. HKEY hkcu = NULL;
  640. if (!fInitMouseWheel)
  641. {
  642. fInitMouseWheel = TRUE;
  643. g_msgMSWheel = WM_MOUSEWHEEL;
  644. }
  645. g_uDragImages = RegisterWindowMessage(DI_GETDRAGIMAGE);
  646. SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &g_ucScrollLines, 0);
  647. g_cxIcon = GetSystemMetrics(SM_CXICON);
  648. g_cyIcon = GetSystemMetrics(SM_CYICON);
  649. g_cxSmIcon = GetSystemMetrics(SM_CXSMICON);
  650. g_cySmIcon = GetSystemMetrics(SM_CYSMICON);
  651. g_cxIconSpacing = GetSystemMetrics( SM_CXICONSPACING );
  652. g_cyIconSpacing = GetSystemMetrics( SM_CYICONSPACING );
  653. hdcScreen = GetDC(NULL);
  654. if (hdcScreen)
  655. {
  656. g_iDPI = GetDeviceCaps(hdcScreen, LOGPIXELSX);
  657. g_dScaleX = GetDeviceCaps(hdcScreen, LOGPIXELSX) / 96.0;
  658. g_dScaleY = GetDeviceCaps(hdcScreen, LOGPIXELSY) / 96.0;
  659. if (g_dScaleX > 1.0 ||
  660. g_dScaleY > 1.0)
  661. {
  662. g_fScale = TRUE;
  663. }
  664. ReleaseDC(NULL, hdcScreen);
  665. }
  666. // Full window drag stays off if running remotely. Sessions could become remote after
  667. // being started.
  668. if (!fRemoteSession &&
  669. (wParam == 0 || wParam == SPI_SETDRAGFULLWINDOWS))
  670. {
  671. SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, sizeof(g_fDragFullWindows), &g_fDragFullWindows, 0);
  672. }
  673. if (wParam == 0 || wParam == SPI_SETHIGHCONTRAST)
  674. {
  675. HIGHCONTRAST hc = { sizeof(hc) };
  676. if (SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(hc), &hc, 0))
  677. {
  678. g_fHighContrast = (hc.dwFlags & HCF_HIGHCONTRASTON);
  679. }
  680. }
  681. // (see warning at the top of this fn.)
  682. //
  683. // As this function may be called within a DllMain, open HKCU via RegOpenCurrentUser,
  684. // instead of RegOpenKeyEx (which locks the hive in memory) - see the comment at the
  685. // top of this function.
  686. RegOpenCurrentUser(KEY_READ, &hkcu);
  687. // Smooth scrolling stays off if running remotely
  688. if (!fRemoteSession)
  689. {
  690. g_fSmoothScroll = TRUE;
  691. //
  692. // (see warning at the top of this fn.)
  693. //
  694. // we want to avoid loading the users hive if we are running as a system process since advapi32
  695. // will hold the hive for as long as this process exists
  696. if (!IsSystemProcess() && hkcu)
  697. {
  698. HKEY hkey;
  699. if (RegOpenKeyEx(hkcu, TEXT("Control Panel\\Desktop"), 0, KEY_READ, &hkey) == ERROR_SUCCESS)
  700. {
  701. DWORD dwSize = sizeof(g_fSmoothScroll);
  702. RegQueryValueEx(hkey, TEXT("SmoothScroll"), 0, NULL, (LPBYTE)&g_fSmoothScroll, &dwSize);
  703. RegCloseKey(hkey);
  704. }
  705. }
  706. }
  707. if (fRemoteSession)
  708. {
  709. // Nobody should've turned these on
  710. g_fDragFullWindows = FALSE;
  711. g_fSmoothScroll = FALSE;
  712. }
  713. // some of these are also not members of NONCLIENTMETRICS
  714. if ((wParam == 0) || (wParam == SPI_SETNONCLIENTMETRICS))
  715. {
  716. NONCLIENTMETRICS ncm;
  717. // REVIEW, make sure all these vars are used somewhere.
  718. g_cxEdgeScaled = g_cxEdge = GetSystemMetrics(SM_CXEDGE);
  719. g_cyEdgeScaled = g_cyEdge = GetSystemMetrics(SM_CYEDGE);
  720. CCDPIScaleX(&g_cxEdgeScaled);
  721. CCDPIScaleY(&g_cyEdgeScaled);
  722. g_cxBorder = GetSystemMetrics(SM_CXBORDER);
  723. g_cyBorder = GetSystemMetrics(SM_CYBORDER);
  724. g_cxScreen = GetSystemMetrics(SM_CXSCREEN);
  725. g_cyScreen = GetSystemMetrics(SM_CYSCREEN);
  726. g_cxFrame = GetSystemMetrics(SM_CXFRAME);
  727. g_cyFrame = GetSystemMetrics(SM_CYFRAME);
  728. ncm.cbSize = sizeof(ncm);
  729. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
  730. g_cxVScroll = g_cxScrollbar = (int)ncm.iScrollWidth;
  731. g_cyHScroll = g_cyScrollbar = (int)ncm.iScrollHeight;
  732. // this is true for 4.0 modules only
  733. // for 3.x modules user lies and adds one to these values
  734. // ASSERT(g_cxVScroll == GetSystemMetrics(SM_CXVSCROLL));
  735. // ASSERT(g_cyHScroll == GetSystemMetrics(SM_CYHSCROLL));
  736. g_cxIconMargin = g_cxBorder * 8;
  737. g_cyIconMargin = g_cyEdge;
  738. g_cyLabelSpace = g_cyIconMargin + (g_cyEdge);
  739. g_cxLabelMargin = g_cxEdge;
  740. g_cxDoubleClk = GetSystemMetrics(SM_CXDOUBLECLK);
  741. g_cyDoubleClk = GetSystemMetrics(SM_CYDOUBLECLK);
  742. g_fEnableBalloonTips = TRUE;
  743. //
  744. // (see warning at the top of this fn.)
  745. //
  746. // we want to avoid loading the users hive if we are running as a system process since advapi32
  747. // will hold the hive for as long as this process exists
  748. if (!IsSystemProcess() && hkcu)
  749. {
  750. HKEY hkey;
  751. if (RegOpenKeyEx(hkcu, REGSTR_EXPLORER_ADVANCED, 0, KEY_READ, &hkey) == ERROR_SUCCESS)
  752. {
  753. DWORD dwSize = sizeof(g_fEnableBalloonTips);
  754. RegQueryValueEx(hkey, TEXT("EnableBalloonTips"), 0, NULL, (LPBYTE)&g_fEnableBalloonTips, &dwSize);
  755. RegCloseKey(hkey);
  756. }
  757. }
  758. }
  759. SystemParametersInfo(SPI_GETMENUDROPALIGNMENT, 0, &g_fLeftAligned, 0);
  760. //NT 4.0 has this SPI_GETMOUSEHOVERTIME
  761. SystemParametersInfo(SPI_GETMOUSEHOVERTIME, 0, &g_dwHoverSelectTimeout, 0);
  762. if (hkcu != NULL)
  763. {
  764. RegCloseKey(hkcu);
  765. }
  766. }
  767. void RelayToToolTips(HWND hwndToolTips, HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  768. {
  769. if(hwndToolTips)
  770. {
  771. MSG msg;
  772. msg.lParam = lParam;
  773. msg.wParam = wParam;
  774. msg.message = wMsg;
  775. msg.hwnd = hWnd;
  776. SendMessage(hwndToolTips, TTM_RELAYEVENT, 0, (LPARAM)(LPMSG)&msg);
  777. }
  778. }
  779. #define DT_SEARCHTIMEOUT 1000L // 1 seconds
  780. __inline BOOL IsISearchTimedOut(PISEARCHINFO pis)
  781. {
  782. return GetMessageTime() - pis->timeLast > DT_SEARCHTIMEOUT &&
  783. !IsFlagSet(g_dwPrototype, PTF_NOISEARCHTO);
  784. }
  785. int GetIncrementSearchString(PISEARCHINFO pis, LPTSTR lpsz)
  786. {
  787. if (IsISearchTimedOut(pis))
  788. {
  789. pis->iIncrSearchFailed = 0;
  790. pis->ichCharBuf = 0;
  791. }
  792. if (pis->ichCharBuf && lpsz)
  793. {
  794. StringCchCopy(lpsz, pis->ichCharBuf+1, pis->pszCharBuf);
  795. }
  796. return pis->ichCharBuf;
  797. }
  798. // Now only Korean version is interested in incremental search with composition string.
  799. BOOL IncrementSearchImeCompStr(PISEARCHINFO pis, BOOL fCompStr, LPTSTR lpszCompStr, LPTSTR *lplpstr)
  800. {
  801. BOOL fRestart = FALSE;
  802. if (!pis->fReplaceCompChar && IsISearchTimedOut(pis))
  803. {
  804. pis->iIncrSearchFailed = 0;
  805. pis->ichCharBuf = 0;
  806. }
  807. if (pis->ichCharBuf == 0)
  808. {
  809. fRestart = TRUE;
  810. pis->fReplaceCompChar = FALSE;
  811. }
  812. pis->timeLast = GetMessageTime();
  813. // Is there room for new character plus zero terminator?
  814. //
  815. if (!pis->fReplaceCompChar && pis->ichCharBuf + 1 + 1 > pis->cbCharBuf)
  816. {
  817. LPTSTR psz = ReAlloc(pis->pszCharBuf, sizeof(TCHAR)*(pis->cbCharBuf + 16));
  818. if (!psz)
  819. return fRestart;
  820. pis->cbCharBuf += 16;
  821. pis->pszCharBuf = psz;
  822. }
  823. if (pis->fReplaceCompChar)
  824. {
  825. if (lpszCompStr[0])
  826. {
  827. pis->pszCharBuf[pis->ichCharBuf-1] = lpszCompStr[0];
  828. pis->pszCharBuf[pis->ichCharBuf] = 0;
  829. }
  830. else
  831. {
  832. pis->ichCharBuf--;
  833. pis->pszCharBuf[pis->ichCharBuf] = 0;
  834. }
  835. }
  836. else
  837. {
  838. pis->pszCharBuf[pis->ichCharBuf++] = lpszCompStr[0];
  839. pis->pszCharBuf[pis->ichCharBuf] = 0;
  840. }
  841. pis->fReplaceCompChar = (fCompStr && lpszCompStr[0]);
  842. if (pis->ichCharBuf == 1 && pis->fReplaceCompChar)
  843. fRestart = TRUE;
  844. *lplpstr = pis->pszCharBuf;
  845. return fRestart;
  846. }
  847. /*
  848. * Thunk for LVM_GETISEARCHSTRINGA
  849. */
  850. int GetIncrementSearchStringA(PISEARCHINFO pis, UINT uiCodePage, LPSTR lpsz)
  851. {
  852. if (IsISearchTimedOut(pis))
  853. {
  854. pis->iIncrSearchFailed = 0;
  855. pis->ichCharBuf = 0;
  856. }
  857. if (pis->ichCharBuf && lpsz) {
  858. ConvertWToAN( uiCodePage, lpsz, pis->ichCharBuf, pis->pszCharBuf, pis->ichCharBuf );
  859. lpsz[pis->ichCharBuf] = '\0';
  860. }
  861. return pis->ichCharBuf;
  862. }
  863. // Beep only on the first failure.
  864. void IncrementSearchBeep(PISEARCHINFO pis)
  865. {
  866. if (!pis->iIncrSearchFailed)
  867. {
  868. pis->iIncrSearchFailed = TRUE;
  869. MessageBeep(0);
  870. }
  871. }
  872. //
  873. // IncrementSearchString - Add or clear the search string
  874. //
  875. // ch == 0: Reset the search string. Return value meaningless.
  876. //
  877. // ch != 0: Append the character to the search string, starting
  878. // a new search string if we timed out the last one.
  879. // lplpstr receives the string so far.
  880. // Return value is TRUE if a new search string was
  881. // created, or FALSE if we appended to an existing one.
  882. //
  883. BOOL IncrementSearchString(PISEARCHINFO pis, UINT ch, LPTSTR *lplpstr)
  884. {
  885. BOOL fRestart = FALSE;
  886. if (!ch) {
  887. pis->ichCharBuf =0;
  888. pis->iIncrSearchFailed = 0;
  889. return FALSE;
  890. }
  891. if (IsISearchTimedOut(pis))
  892. {
  893. pis->iIncrSearchFailed = 0;
  894. pis->ichCharBuf = 0;
  895. }
  896. if (pis->ichCharBuf == 0)
  897. fRestart = TRUE;
  898. pis->timeLast = GetMessageTime();
  899. // Is there room for new character plus zero terminator?
  900. //
  901. if (pis->ichCharBuf + 1 + 1 > pis->cbCharBuf)
  902. {
  903. LPTSTR psz = ReAlloc(pis->pszCharBuf, ((pis->cbCharBuf + 16) * sizeof(TCHAR)));
  904. if (!psz)
  905. return fRestart;
  906. pis->cbCharBuf += 16;
  907. pis->pszCharBuf = psz;
  908. }
  909. pis->pszCharBuf[pis->ichCharBuf++] = (TCHAR)ch;
  910. pis->pszCharBuf[pis->ichCharBuf] = 0;
  911. *lplpstr = pis->pszCharBuf;
  912. return fRestart;
  913. }
  914. // strips out the accelerators. they CAN be the same buffers.
  915. int StripAccelerators(LPTSTR lpszFrom, LPTSTR lpszTo, BOOL fAmpOnly)
  916. {
  917. LPTSTR lpszStart = lpszTo;
  918. while (*lpszTo = *lpszFrom)
  919. {
  920. if (!fAmpOnly && (g_fDBCSInputEnabled))
  921. {
  922. if (*lpszFrom == TEXT('(') && *(lpszFrom + 1) == CH_PREFIX)
  923. {
  924. int i;
  925. LPTSTR psz = lpszFrom + 2;
  926. for(i = 0; i < 2 && *psz; i++, psz = FastCharNext(psz))
  927. {
  928. ;
  929. }
  930. if (*psz == '\0')
  931. {
  932. *lpszTo = 0;
  933. break;
  934. }
  935. else if (i == 2 && *psz == TEXT(')'))
  936. {
  937. lpszTo--;
  938. lpszFrom = psz+1;
  939. continue;
  940. }
  941. }
  942. }
  943. if (*lpszFrom == TEXT('\t'))
  944. {
  945. *lpszTo = TEXT('\0');
  946. break;
  947. }
  948. if ((*lpszFrom++ != CH_PREFIX) || (*lpszFrom == CH_PREFIX))
  949. {
  950. lpszTo++;
  951. }
  952. }
  953. return (int)(lpszTo - lpszStart);
  954. }
  955. void ScrollShrinkRect(int x, int y, LPRECT lprc)
  956. {
  957. if (lprc) {
  958. if (x > 0) {
  959. lprc->left += x;
  960. } else {
  961. lprc->right += x;
  962. }
  963. if (y > 0) {
  964. lprc->top += y;
  965. } else {
  966. lprc->bottom += y;
  967. }
  968. }
  969. }
  970. // common control info helpers
  971. void CIInitialize(LPCCONTROLINFO lpci, HWND hwnd, LPCREATESTRUCT lpcs)
  972. {
  973. TEXTMETRIC tm;
  974. HFONT hfStatus;
  975. lpci->hwnd = hwnd;
  976. lpci->hwndParent = lpcs->hwndParent;
  977. lpci->style = lpcs->style;
  978. lpci->uiCodePage = CP_ACP;
  979. lpci->dwExStyle = lpcs->dwExStyle;
  980. lpci->iVersion = 6;
  981. #ifdef DPITEST
  982. lpci->fDPIAware = TRUE;
  983. #endif
  984. // See if the default listview font has no internal leading.
  985. // If not, then we have to inflate the focus rectangle so we
  986. // don't overlap the first pixel.
  987. //
  988. // Note that this is a global and not per-TextOut.
  989. // Otherwise controls with a mix of fonts will get
  990. // inconsistently-placed focus rectangles.
  991. //
  992. hfStatus = CCCreateStatusFont();
  993. if (hfStatus)
  994. {
  995. HDC hdc = GetDC(hwnd);
  996. if (hdc)
  997. {
  998. HFONT hfPrev = SelectFont(hdc, hfStatus);
  999. if (GetTextMetrics(hdc, &tm) &&
  1000. tm.tmInternalLeading == 0)
  1001. {
  1002. g_cyCompensateInternalLeading = 1;
  1003. }
  1004. SelectFont(hdc, hfPrev);
  1005. ReleaseDC(hwnd, hdc);
  1006. }
  1007. DeleteObject(hfStatus);
  1008. }
  1009. lpci->bUnicode = lpci->hwndParent &&
  1010. SendMessage (lpci->hwndParent, WM_NOTIFYFORMAT,
  1011. (WPARAM)lpci->hwnd, NF_QUERY) == NFR_UNICODE;
  1012. if (lpci->hwndParent)
  1013. {
  1014. LRESULT lRes = SendMessage(lpci->hwndParent, WM_QUERYUISTATE, 0, 0);
  1015. lpci->wUIState = LOWORD(lRes);
  1016. }
  1017. }
  1018. LRESULT CIHandleNotifyFormat(LPCCONTROLINFO lpci, LPARAM lParam)
  1019. {
  1020. if (lParam == NF_QUERY)
  1021. {
  1022. return NFR_UNICODE;
  1023. }
  1024. else if (lParam == NF_REQUERY)
  1025. {
  1026. LRESULT uiResult;
  1027. uiResult = SendMessage (lpci->hwndParent, WM_NOTIFYFORMAT,
  1028. (WPARAM)lpci->hwnd, NF_QUERY);
  1029. lpci->bUnicode = BOOLIFY(uiResult == NFR_UNICODE);
  1030. return uiResult;
  1031. }
  1032. return 0;
  1033. }
  1034. UINT CCSwapKeys(WPARAM wParam, UINT vk1, UINT vk2)
  1035. {
  1036. if (wParam == vk1)
  1037. return vk2;
  1038. if (wParam == vk2)
  1039. return vk1;
  1040. return (UINT)wParam;
  1041. }
  1042. UINT RTLSwapLeftRightArrows(CCONTROLINFO *pci, WPARAM wParam)
  1043. {
  1044. if (pci->dwExStyle & RTL_MIRRORED_WINDOW)
  1045. {
  1046. return CCSwapKeys(wParam, VK_LEFT, VK_RIGHT);
  1047. }
  1048. return (UINT)wParam;
  1049. }
  1050. //
  1051. // New for v5.01:
  1052. //
  1053. // Accessibility (and some other callers, sometimes even us) relies on
  1054. // a XXM_GETITEM call filling the buffer and not just redirecting the
  1055. // pointer. Accessibility is particularly impacted by this because they
  1056. // live outside the process, so the redirected pointer means nothing
  1057. // to them. Here, we copy the result back into the app buffer and return
  1058. // the raw pointer. The caller will return the raw pointer back to the
  1059. // app, so the answer is in two places, either the app buffer, or in
  1060. // the raw pointer.
  1061. //
  1062. // Usage:
  1063. //
  1064. // if (nm.item.mask & LVIF_TEXT)
  1065. // pitem->pszText = CCReturnDispInfoText(nm.item.pszText,
  1066. // pitem->pszText, pitem->cchTextMax);
  1067. //
  1068. LPTSTR CCReturnDispInfoText(LPTSTR pszSrc, LPTSTR pszDest, UINT cchDest)
  1069. {
  1070. // Test pszSrc != pszDest first since the common case is that they
  1071. // are equal.
  1072. if (pszSrc != pszDest && !IsFlagPtr(pszSrc) && !IsFlagPtr(pszDest))
  1073. {
  1074. StringCchCopy(pszDest, cchDest, pszSrc);
  1075. }
  1076. return pszSrc;
  1077. }
  1078. #define SUBSCROLLS 100
  1079. #define abs(x) ( ( x > 0 ) ? x : -x)
  1080. #define DEFAULT_MAXSCROLLTIME ((GetDoubleClickTime() / 2) + 1) // Ensure >= 1
  1081. #define DEFAULT_MINSCROLL 8
  1082. int SmoothScrollWindow(PSMOOTHSCROLLINFO psi)
  1083. {
  1084. int dx = psi->dx;
  1085. int dy = psi->dy;
  1086. LPCRECT lprcSrc = psi->lprcSrc;
  1087. LPCRECT lprcClip = psi->lprcClip;
  1088. HRGN hrgnUpdate = psi->hrgnUpdate;
  1089. LPRECT lprcUpdate = psi->lprcUpdate;
  1090. UINT fuScroll = psi->fuScroll;
  1091. int iRet = SIMPLEREGION;
  1092. RECT rcUpdate;
  1093. RECT rcSrc;
  1094. RECT rcClip;
  1095. int xStep;
  1096. int yStep;
  1097. int iSlicesDone = 0;
  1098. int iSlices;
  1099. DWORD dwTimeStart, dwTimeNow;
  1100. HRGN hrgnLocalUpdate;
  1101. UINT cxMinScroll = psi->cxMinScroll;
  1102. UINT cyMinScroll = psi->cyMinScroll;
  1103. UINT uMaxScrollTime = psi->uMaxScrollTime;
  1104. int iSubScrolls;
  1105. PFNSMOOTHSCROLLPROC pfnScrollProc;
  1106. DWORD dwRedrawFlags = RDW_ERASE | RDW_ERASENOW | RDW_INVALIDATE;
  1107. if (!lprcUpdate)
  1108. lprcUpdate = &rcUpdate;
  1109. SetRectEmpty(lprcUpdate);
  1110. if (psi->cbSize != sizeof(SMOOTHSCROLLINFO))
  1111. {
  1112. return 0;
  1113. }
  1114. // check the defaults
  1115. if (!(psi->fMask & SSIF_MINSCROLL )
  1116. || cxMinScroll == SSI_DEFAULT)
  1117. {
  1118. cxMinScroll = DEFAULT_MINSCROLL;
  1119. }
  1120. if (!(psi->fMask & SSIF_MINSCROLL)
  1121. || cyMinScroll == SSI_DEFAULT)
  1122. {
  1123. cyMinScroll = DEFAULT_MINSCROLL;
  1124. }
  1125. if (!(psi->fMask & SSIF_MAXSCROLLTIME)
  1126. || uMaxScrollTime == SSI_DEFAULT)
  1127. {
  1128. uMaxScrollTime = DEFAULT_MAXSCROLLTIME;
  1129. }
  1130. if (uMaxScrollTime < SUBSCROLLS)
  1131. {
  1132. uMaxScrollTime = SUBSCROLLS;
  1133. }
  1134. if ((!(fuScroll & SSW_EX_IGNORESETTINGS)) &&
  1135. (!g_fSmoothScroll))
  1136. {
  1137. fuScroll |= SSW_EX_IMMEDIATE;
  1138. }
  1139. if ((psi->fMask & SSIF_SCROLLPROC) && psi->pfnScrollProc)
  1140. {
  1141. pfnScrollProc = psi->pfnScrollProc;
  1142. }
  1143. else
  1144. {
  1145. pfnScrollProc = ScrollWindowEx;
  1146. }
  1147. #ifdef ScrollWindowEx
  1148. #undef ScrollWindowEx
  1149. #endif
  1150. if (fuScroll & SSW_EX_IMMEDIATE)
  1151. {
  1152. return pfnScrollProc(psi->hwnd, dx, dy, lprcSrc, lprcClip, hrgnUpdate,
  1153. lprcUpdate, LOWORD(fuScroll));
  1154. }
  1155. if (fuScroll & SSW_EX_UPDATEATEACHSTEP)
  1156. {
  1157. dwRedrawFlags |= RDW_UPDATENOW;
  1158. }
  1159. // copy input rects locally
  1160. if (lprcSrc)
  1161. {
  1162. rcSrc = *lprcSrc;
  1163. lprcSrc = &rcSrc;
  1164. }
  1165. if (lprcClip)
  1166. {
  1167. rcClip = *lprcClip;
  1168. lprcClip = &rcClip;
  1169. }
  1170. if (!hrgnUpdate)
  1171. hrgnLocalUpdate = CreateRectRgn(0,0,0,0);
  1172. else
  1173. hrgnLocalUpdate = hrgnUpdate;
  1174. //set up initial vars
  1175. dwTimeStart = GetTickCount();
  1176. if (fuScroll & SSW_EX_NOTIMELIMIT)
  1177. {
  1178. xStep = cxMinScroll * (dx < 0 ? -1 : 1);
  1179. yStep = cyMinScroll * (dy < 0 ? -1 : 1);
  1180. }
  1181. else
  1182. {
  1183. iSubScrolls = (uMaxScrollTime / DEFAULT_MAXSCROLLTIME) * SUBSCROLLS;
  1184. if (!iSubScrolls)
  1185. iSubScrolls = SUBSCROLLS;
  1186. xStep = dx / iSubScrolls;
  1187. yStep = dy / iSubScrolls;
  1188. }
  1189. if (xStep == 0 && dx)
  1190. xStep = dx < 0 ? -1 : 1;
  1191. if (yStep == 0 && dy)
  1192. yStep = dy < 0 ? -1 : 1;
  1193. while (dx || dy)
  1194. {
  1195. int x,y;
  1196. RECT rcTempUpdate;
  1197. if (fuScroll & SSW_EX_NOTIMELIMIT)
  1198. {
  1199. x = xStep;
  1200. y = yStep;
  1201. if (abs(x) > abs(dx))
  1202. x = dx;
  1203. if (abs(y) > abs(dy))
  1204. y = dy;
  1205. }
  1206. else
  1207. {
  1208. int iTimePerScroll = uMaxScrollTime / iSubScrolls;
  1209. if (!iTimePerScroll)
  1210. iTimePerScroll = 1;
  1211. dwTimeNow = GetTickCount();
  1212. iSlices = ((dwTimeNow - dwTimeStart) / iTimePerScroll) - iSlicesDone;
  1213. if (iSlices < 0)
  1214. iSlices = 0;
  1215. do
  1216. {
  1217. int iRet = 0;
  1218. iSlices++;
  1219. if ((iSlicesDone + iSlices) <= iSubScrolls)
  1220. {
  1221. x = xStep * iSlices;
  1222. y = yStep * iSlices;
  1223. // this could go over if we rounded ?Step up to 1(-1) above
  1224. if (abs(x) > abs(dx))
  1225. x = dx;
  1226. if (abs(y) > abs(dy))
  1227. y = dy;
  1228. }
  1229. else
  1230. {
  1231. x = dx;
  1232. y = dy;
  1233. }
  1234. //DebugMsg(DM_TRACE, "SmoothScrollWindowCallback %d", iRet);
  1235. if (x == dx && y == dy)
  1236. break;
  1237. if ((((UINT)(abs(x)) >= cxMinScroll) || !x) &&
  1238. (((UINT)(abs(y)) >= cyMinScroll) || !y))
  1239. break;
  1240. }
  1241. while (1);
  1242. }
  1243. if (pfnScrollProc(psi->hwnd, x, y, lprcSrc, lprcClip, hrgnLocalUpdate, &rcTempUpdate, LOWORD(fuScroll)) == ERROR)
  1244. {
  1245. iRet = ERROR;
  1246. goto Bail;
  1247. }
  1248. UnionRect(lprcUpdate, &rcTempUpdate, lprcUpdate);
  1249. RedrawWindow(psi->hwnd, NULL, hrgnLocalUpdate, dwRedrawFlags);
  1250. ScrollShrinkRect(x,y, (LPRECT)lprcSrc);
  1251. dx -= x;
  1252. dy -= y;
  1253. iSlicesDone += iSlices;
  1254. }
  1255. Bail:
  1256. if (fuScroll & SW_SCROLLCHILDREN)
  1257. {
  1258. RedrawWindow(psi->hwnd, lprcUpdate, NULL, RDW_ERASE | RDW_UPDATENOW | RDW_INVALIDATE);
  1259. }
  1260. if (hrgnLocalUpdate != hrgnUpdate)
  1261. DeleteObject(hrgnLocalUpdate);
  1262. return iRet;
  1263. }
  1264. #define CCH_KEYMAX 256
  1265. void CCPlaySound(LPCTSTR lpszName)
  1266. {
  1267. TCHAR szFileName[MAX_PATH];
  1268. LONG cbSize = SIZEOF(szFileName);
  1269. TCHAR szKey[CCH_KEYMAX];
  1270. // check the registry first
  1271. // if there's nothing registered, we blow off the play,
  1272. // but we don't set the MM_DONTLOAD flag so taht if they register
  1273. // something we will play it
  1274. StringCchPrintf(szKey, ARRAYSIZE(szKey), TEXT("AppEvents\\Schemes\\Apps\\.Default\\%s\\.current"), lpszName);
  1275. if ((RegQueryValue(HKEY_CURRENT_USER, szKey, szFileName, &cbSize) == ERROR_SUCCESS) &&
  1276. (cbSize > SIZEOF(szFileName[0])))
  1277. {
  1278. PlaySound(szFileName, NULL, SND_FILENAME | SND_ASYNC);
  1279. }
  1280. }
  1281. BOOL CCForwardEraseBackground(HWND hwnd, HDC hdc)
  1282. {
  1283. HWND hwndParent = GetParent(hwnd);
  1284. LRESULT lres = 0;
  1285. if (hwndParent)
  1286. {
  1287. // Adjust the origin so the parent paints in the right place
  1288. POINT pt = {0,0};
  1289. MapWindowPoints(hwnd, hwndParent, &pt, 1);
  1290. OffsetWindowOrgEx(hdc,
  1291. pt.x,
  1292. pt.y,
  1293. &pt);
  1294. lres = SendMessage(hwndParent, WM_ERASEBKGND, (WPARAM) hdc, 0L);
  1295. SetWindowOrgEx(hdc, pt.x, pt.y, NULL);
  1296. }
  1297. return(lres != 0);
  1298. }
  1299. HFONT CCGetHotFont(HFONT hFont, HFONT *phFontHot)
  1300. {
  1301. if (!*phFontHot) {
  1302. LOGFONT lf;
  1303. // create the underline font
  1304. GetObject(hFont, sizeof(lf), &lf);
  1305. #ifndef DONT_UNDERLINE
  1306. lf.lfUnderline = TRUE;
  1307. #endif
  1308. *phFontHot = CreateFontIndirect(&lf);
  1309. }
  1310. return *phFontHot;
  1311. }
  1312. HFONT CCCreateStatusFont(void)
  1313. {
  1314. NONCLIENTMETRICS ncm;
  1315. ncm.cbSize = sizeof(NONCLIENTMETRICS);
  1316. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
  1317. return CreateFontIndirect(&ncm.lfStatusFont);
  1318. }
  1319. HFONT CCCreateUnderlineFont(HFONT hf)
  1320. {
  1321. HFONT hUnderline = NULL;
  1322. LOGFONT lf;
  1323. if (hf && GetObject(hf, sizeof(lf), &lf))
  1324. {
  1325. lf.lfUnderline = TRUE;
  1326. hUnderline = CreateFontIndirect(&lf);
  1327. }
  1328. return hUnderline;
  1329. }
  1330. void* CCLocalReAlloc(void* p, UINT uBytes)
  1331. {
  1332. if (uBytes) {
  1333. if (p) {
  1334. return LocalReAlloc(p, uBytes, LMEM_MOVEABLE | LMEM_ZEROINIT);
  1335. } else {
  1336. return LocalAlloc(LPTR, uBytes);
  1337. }
  1338. } else {
  1339. if (p)
  1340. LocalFree(p);
  1341. return NULL;
  1342. }
  1343. }
  1344. /*----------------------------------------------------------
  1345. Purpose: This function provides the commctrl version info. This
  1346. allows the caller to distinguish running NT SUR vs.
  1347. Win95 shell vs. Nashville, etc.
  1348. This API was not supplied in Win95 or NT SUR, so
  1349. the caller must GetProcAddress it. If this fails,
  1350. the caller is running on Win95 or NT SUR.
  1351. Returns: NO_ERROR
  1352. ERROR_INVALID_PARAMETER if pinfo is invalid
  1353. Cond: --
  1354. */
  1355. // All we have to do is declare this puppy and CCDllGetVersion does the rest
  1356. // Note that we use VER_FILEVERSION_DW because comctl32 uses a funky
  1357. // version scheme
  1358. DLLVER_DUALBINARY(VER_FILEVERSION_DW, VER_PRODUCTBUILD_QFE);
  1359. //
  1360. // Translate the given font to a code page used for thunking text
  1361. //
  1362. UINT GetCodePageForFont(HFONT hFont)
  1363. {
  1364. LOGFONT lf;
  1365. TCHAR szFontName[LF_FACESIZE];
  1366. CHARSETINFO csi;
  1367. DWORD dwSize, dwType;
  1368. HKEY hKey;
  1369. if (!GetObject (hFont, sizeof(lf), &lf))
  1370. {
  1371. return CP_ACP;
  1372. }
  1373. //
  1374. // Check for font substitutes
  1375. //
  1376. StringCchCopy(szFontName, ARRAYSIZE(szFontName), lf.lfFaceName);
  1377. if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  1378. TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes"),
  1379. 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  1380. {
  1381. dwSize = SIZEOF(szFontName);
  1382. RegQueryValueEx(hKey, lf.lfFaceName, NULL, &dwType, (LPBYTE)szFontName, &dwSize);
  1383. RegCloseKey (hKey);
  1384. }
  1385. //
  1386. // This is to fix office for locales that use non 1252 versions
  1387. // of Ms Sans Serif and Ms Serif. These fonts incorrectly identify
  1388. // themselves as having an Ansi charset, so TranslateCharsetInfo will
  1389. // return the wrong value.
  1390. //
  1391. // NT bug 260697: Office 2000 uses Tahoma.
  1392. //
  1393. if ((lf.lfCharSet == ANSI_CHARSET) &&
  1394. (!lstrcmpi(L"Helv", szFontName) ||
  1395. !lstrcmpi(L"Ms Sans Serif", szFontName) ||
  1396. !lstrcmpi(L"Ms Serif", szFontName) ||
  1397. !lstrcmpi(L"Tahoma", szFontName)))
  1398. {
  1399. return CP_ACP;
  1400. }
  1401. //
  1402. // This is to fix FE office95a and Pro. msofe95.dll sets wrong charset when create
  1403. // listview control. so TranslateCharsetInfo will return the wrong value.
  1404. // Korea : DotumChe.
  1405. // Taiwan : New MingLight
  1406. // China : SongTi
  1407. if ((lf.lfCharSet == SHIFTJIS_CHARSET) &&
  1408. (!lstrcmpi(L"\xb3cb\xc6c0\xccb4", lf.lfFaceName)) || // Korea
  1409. (!lstrcmpi(L"\x65b0\x7d30\x660e\x9ad4", lf.lfFaceName)) || // Taiwan
  1410. (!lstrcmpi(L"\x5b8b\x4f53", lf.lfFaceName))) // PRC
  1411. {
  1412. return CP_ACP;
  1413. }
  1414. if (!TranslateCharsetInfo((DWORD *) lf.lfCharSet, &csi, TCI_SRCCHARSET)) {
  1415. return CP_ACP;
  1416. }
  1417. return csi.ciACP;
  1418. }
  1419. LONG GetMessagePosClient(HWND hwnd, LPPOINT ppt)
  1420. {
  1421. LPARAM lParam;
  1422. POINT pt;
  1423. if (!ppt)
  1424. ppt = &pt;
  1425. lParam = GetMessagePos();
  1426. ppt->x = GET_X_LPARAM(lParam);
  1427. ppt->y = GET_Y_LPARAM(lParam);
  1428. ScreenToClient(hwnd, ppt);
  1429. return MAKELONG(ppt->x, ppt->y);
  1430. }
  1431. LPTSTR StrDup(LPCTSTR lpsz)
  1432. {
  1433. DWORD cchRet = (lstrlen(lpsz) + 1);
  1434. LPTSTR lpszRet = (LPTSTR)LocalAlloc(LPTR, cchRet * sizeof(TCHAR));
  1435. if (lpszRet)
  1436. {
  1437. StringCchCopy(lpszRet, cchRet, lpsz);
  1438. }
  1439. return lpszRet;
  1440. }
  1441. LPSTR StrDupA(LPCSTR lpsz)
  1442. {
  1443. DWORD cchRet = (lstrlenA(lpsz) + 1);
  1444. LPSTR lpszRet = (LPSTR)LocalAlloc(LPTR, cchRet * sizeof(CHAR));
  1445. if (lpszRet)
  1446. {
  1447. StringCchCopyA(lpszRet, cchRet, lpsz);
  1448. }
  1449. return lpszRet;
  1450. }
  1451. HWND GetDlgItemRect(HWND hDlg, int nIDItem, LPRECT prc) //relative to hDlg
  1452. {
  1453. HWND hCtrl = NULL;
  1454. if (prc)
  1455. {
  1456. hCtrl = GetDlgItem(hDlg, nIDItem);
  1457. if (hCtrl)
  1458. {
  1459. GetWindowRect(hCtrl, prc);
  1460. MapWindowRect(NULL, hDlg, prc);
  1461. }
  1462. else
  1463. SetRectEmpty(prc);
  1464. }
  1465. return hCtrl;
  1466. }
  1467. /*----------------------------------------------------------
  1468. Purpose: Calls the ADVPACK entry-point which executes an inf
  1469. file section.
  1470. */
  1471. HRESULT CallRegInstall(LPSTR szSection)
  1472. {
  1473. HRESULT hr = E_FAIL;
  1474. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  1475. if (hinstAdvPack)
  1476. {
  1477. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  1478. if (pfnri)
  1479. {
  1480. hr = pfnri(g_hinst, szSection, NULL);
  1481. }
  1482. FreeLibrary(hinstAdvPack);
  1483. }
  1484. return hr;
  1485. }
  1486. /*----------------------------------------------------------
  1487. Purpose: Install/uninstall user settings
  1488. */
  1489. STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
  1490. {
  1491. HRESULT hres = S_OK;
  1492. #ifdef DEBUG
  1493. if (IsFlagSet(g_dwBreakFlags, BF_ONAPIENTER))
  1494. {
  1495. TraceMsg(TF_ALWAYS, "Stopping in DllInstall");
  1496. DEBUG_BREAK;
  1497. }
  1498. #endif
  1499. if (bInstall)
  1500. {
  1501. // Delete any old registration entries, then add the new ones.
  1502. // Keep ADVPACK.DLL loaded across multiple calls to RegInstall.
  1503. // (The inf engine doesn't guarantee DelReg/AddReg order, that's
  1504. // why we explicitly unreg and reg here.)
  1505. //
  1506. CallRegInstall("RegDll");
  1507. }
  1508. else
  1509. {
  1510. CallRegInstall("UnregDll");
  1511. }
  1512. return hres;
  1513. }
  1514. //---------------------------------------------------------------------------------------
  1515. void FlipRect(LPRECT prc)
  1516. {
  1517. SWAP(prc->left, prc->top, int);
  1518. SWAP(prc->right, prc->bottom, int);
  1519. }
  1520. //---------------------------------------------------------------------------------------
  1521. //
  1522. // Returns previous window bits.
  1523. DWORD SetWindowBits(HWND hWnd, int iWhich, DWORD dwBits, DWORD dwValue)
  1524. {
  1525. DWORD dwStyle;
  1526. DWORD dwNewStyle;
  1527. dwStyle = GetWindowLong(hWnd, iWhich);
  1528. dwNewStyle = ( dwStyle & ~dwBits ) | (dwValue & dwBits);
  1529. if (dwStyle != dwNewStyle) {
  1530. dwStyle = SetWindowLong(hWnd, iWhich, dwNewStyle);
  1531. }
  1532. return dwStyle;
  1533. }
  1534. //---------------------------------------------------------------------------------------
  1535. BOOL CCDrawEdge(HDC hdc, LPRECT lprc, UINT edge, UINT flags, LPCOLORSCHEME lpclrsc)
  1536. {
  1537. RECT rc, rcD;
  1538. UINT bdrType;
  1539. COLORREF clrTL, clrBR;
  1540. //
  1541. // Enforce monochromicity and flatness
  1542. //
  1543. // if (oemInfo.BitCount == 1)
  1544. // flags |= BF_MONO;
  1545. if (flags & BF_MONO)
  1546. flags |= BF_FLAT;
  1547. CopyRect(&rc, lprc);
  1548. //
  1549. // Draw the border segment(s), and calculate the remaining space as we
  1550. // go.
  1551. //
  1552. if (bdrType = (edge & BDR_OUTER))
  1553. {
  1554. DrawBorder:
  1555. //
  1556. // Get colors. Note the symmetry between raised outer, sunken inner and
  1557. // sunken outer, raised inner.
  1558. //
  1559. if (flags & BF_FLAT)
  1560. {
  1561. if (flags & BF_MONO)
  1562. clrBR = (bdrType & BDR_OUTER) ? g_clrWindowFrame : g_clrWindow;
  1563. else
  1564. clrBR = (bdrType & BDR_OUTER) ? g_clrBtnShadow: g_clrBtnFace;
  1565. clrTL = clrBR;
  1566. }
  1567. else
  1568. {
  1569. // 5 == HILIGHT
  1570. // 4 == LIGHT
  1571. // 3 == FACE
  1572. // 2 == SHADOW
  1573. // 1 == DKSHADOW
  1574. switch (bdrType)
  1575. {
  1576. // +2 above surface
  1577. case BDR_RAISEDOUTER: // 5 : 4
  1578. clrTL = ((flags & BF_SOFT) ? g_clrBtnHighlight : g_clr3DLight);
  1579. clrBR = g_clr3DDkShadow; // 1
  1580. if (lpclrsc) {
  1581. if (lpclrsc->clrBtnHighlight != CLR_DEFAULT)
  1582. clrTL = lpclrsc->clrBtnHighlight;
  1583. if (lpclrsc->clrBtnShadow != CLR_DEFAULT)
  1584. clrBR = lpclrsc->clrBtnShadow;
  1585. }
  1586. break;
  1587. // +1 above surface
  1588. case BDR_RAISEDINNER: // 4 : 5
  1589. clrTL = ((flags & BF_SOFT) ? g_clr3DLight : g_clrBtnHighlight);
  1590. clrBR = g_clrBtnShadow; // 2
  1591. if (lpclrsc) {
  1592. if (lpclrsc->clrBtnHighlight != CLR_DEFAULT)
  1593. clrTL = lpclrsc->clrBtnHighlight;
  1594. if (lpclrsc->clrBtnShadow != CLR_DEFAULT)
  1595. clrBR = lpclrsc->clrBtnShadow;
  1596. }
  1597. break;
  1598. // -1 below surface
  1599. case BDR_SUNKENOUTER: // 1 : 2
  1600. clrTL = ((flags & BF_SOFT) ? g_clr3DDkShadow : g_clrBtnShadow);
  1601. clrBR = g_clrBtnHighlight; // 5
  1602. if (lpclrsc) {
  1603. if (lpclrsc->clrBtnShadow != CLR_DEFAULT)
  1604. clrTL = lpclrsc->clrBtnShadow;
  1605. if (lpclrsc->clrBtnHighlight != CLR_DEFAULT)
  1606. clrBR = lpclrsc->clrBtnHighlight;
  1607. }
  1608. break;
  1609. // -2 below surface
  1610. case BDR_SUNKENINNER: // 2 : 1
  1611. clrTL = ((flags & BF_SOFT) ? g_clrBtnShadow : g_clr3DDkShadow);
  1612. clrBR = g_clr3DLight; // 4
  1613. if (lpclrsc) {
  1614. if (lpclrsc->clrBtnShadow != CLR_DEFAULT)
  1615. clrTL = lpclrsc->clrBtnShadow;
  1616. if (lpclrsc->clrBtnHighlight != CLR_DEFAULT)
  1617. clrBR = lpclrsc->clrBtnHighlight;
  1618. }
  1619. break;
  1620. default:
  1621. return(FALSE);
  1622. }
  1623. }
  1624. //
  1625. // Draw the sides of the border. NOTE THAT THE ALGORITHM FAVORS THE
  1626. // BOTTOM AND RIGHT SIDES, since the light source is assumed to be top
  1627. // left. If we ever decide to let the user set the light source to a
  1628. // particular corner, then change this algorithm.
  1629. //
  1630. // Bottom Right edges
  1631. if (flags & (BF_RIGHT | BF_BOTTOM))
  1632. {
  1633. // Right
  1634. if (flags & BF_RIGHT)
  1635. {
  1636. rc.right -= g_cxBorder;
  1637. // PatBlt(hdc, rc.right, rc.top, g_cxBorder, rc.bottom - rc.top, PATCOPY);
  1638. rcD.left = rc.right;
  1639. rcD.right = rc.right + g_cxBorder;
  1640. rcD.top = rc.top;
  1641. rcD.bottom = rc.bottom;
  1642. FillRectClr(hdc, &rcD, clrBR);
  1643. }
  1644. // Bottom
  1645. if (flags & BF_BOTTOM)
  1646. {
  1647. rc.bottom -= g_cyBorder;
  1648. // PatBlt(hdc, rc.left, rc.bottom, rc.right - rc.left, g_cyBorder, PATCOPY);
  1649. rcD.left = rc.left;
  1650. rcD.right = rc.right;
  1651. rcD.top = rc.bottom;
  1652. rcD.bottom = rc.bottom + g_cyBorder;
  1653. FillRectClr(hdc, &rcD, clrBR);
  1654. }
  1655. }
  1656. // Top Left edges
  1657. if (flags & (BF_TOP | BF_LEFT))
  1658. {
  1659. // Left
  1660. if (flags & BF_LEFT)
  1661. {
  1662. // PatBlt(hdc, rc.left, rc.top, g_cxBorder, rc.bottom - rc.top, PATCOPY);
  1663. rc.left += g_cxBorder;
  1664. rcD.left = rc.left - g_cxBorder;
  1665. rcD.right = rc.left;
  1666. rcD.top = rc.top;
  1667. rcD.bottom = rc.bottom;
  1668. FillRectClr(hdc, &rcD, clrTL);
  1669. }
  1670. // Top
  1671. if (flags & BF_TOP)
  1672. {
  1673. // PatBlt(hdc, rc.left, rc.top, rc.right - rc.left, g_cyBorder, PATCOPY);
  1674. rc.top += g_cyBorder;
  1675. rcD.left = rc.left;
  1676. rcD.right = rc.right;
  1677. rcD.top = rc.top - g_cyBorder;
  1678. rcD.bottom = rc.top;
  1679. FillRectClr(hdc, &rcD, clrTL);
  1680. }
  1681. }
  1682. }
  1683. if (bdrType = (edge & BDR_INNER))
  1684. {
  1685. //
  1686. // Strip this so the next time through, bdrType will be 0.
  1687. // Otherwise, we'll loop forever.
  1688. //
  1689. edge &= ~BDR_INNER;
  1690. goto DrawBorder;
  1691. }
  1692. //
  1693. // Fill the middle & clean up if asked
  1694. //
  1695. if (flags & BF_MIDDLE)
  1696. FillRectClr(hdc, &rc, (flags & BF_MONO) ? g_clrWindow : g_clrBtnFace);
  1697. if (flags & BF_ADJUST)
  1698. CopyRect(lprc, &rc);
  1699. return(TRUE);
  1700. }
  1701. BOOL CCThemeDrawEdge(HTHEME hTheme, HDC hdc, PRECT prc, int iPart, int iState, UINT edge, UINT flags, LPCOLORSCHEME pclrsc)
  1702. {
  1703. RECT rc;
  1704. if (!hTheme)
  1705. return CCDrawEdge(hdc, prc, edge, flags, pclrsc);
  1706. return S_OK == DrawThemeEdge(hTheme, hdc, iPart, iState, prc, edge, flags, &rc);
  1707. }
  1708. //---------------------------------------------------------------------------------------
  1709. //CCInvalidateFrame -- SWP_FRAMECHANGED, w/o all the extra params
  1710. //
  1711. void CCInvalidateFrame(HWND hwnd)
  1712. {
  1713. SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
  1714. return;
  1715. }
  1716. //---------------------------------------------------------------------------------------
  1717. // FlipPoint - flip the x and y coordinates of a point
  1718. //
  1719. void FlipPoint(LPPOINT lppt)
  1720. {
  1721. SWAP(lppt->x, lppt->y, int);
  1722. }
  1723. //
  1724. // When we want to turn a tooltip into an infotip, we set its
  1725. // width to 300 "small pixels", where there are 72 small pixels
  1726. // per inch when you are in small fonts mode.
  1727. //
  1728. // Scale this value based on the magnification in effect
  1729. // on the owner's monitor. But never let the tooltip get
  1730. // bigger than 3/4 of the screen.
  1731. //
  1732. void CCSetInfoTipWidth(HWND hwndOwner, HWND hwndToolTips)
  1733. {
  1734. HDC hdc = GetDC(hwndOwner);
  1735. int iWidth = MulDiv(GetDeviceCaps(hdc, LOGPIXELSX), 300, 72);
  1736. int iMaxWidth = GetDeviceCaps(hdc, HORZRES) * 3 / 4;
  1737. SendMessage(hwndToolTips, TTM_SETMAXTIPWIDTH, 0, min(iWidth, iMaxWidth));
  1738. ReleaseDC(hwndOwner, hdc);
  1739. }
  1740. // Mirror a bitmap in a DC (mainly a text object in a DC)
  1741. //
  1742. // [samera]
  1743. //
  1744. void MirrorBitmapInDC( HDC hdc , HBITMAP hbmOrig )
  1745. {
  1746. HDC hdcMem;
  1747. HBITMAP hbm;
  1748. BITMAP bm;
  1749. if( !GetObject( hbmOrig , sizeof(BITMAP) , &bm ))
  1750. return;
  1751. hdcMem = CreateCompatibleDC( hdc );
  1752. if( !hdcMem )
  1753. return;
  1754. hbm = CreateCompatibleBitmap( hdc , bm.bmWidth , bm.bmHeight );
  1755. if( !hbm )
  1756. {
  1757. DeleteDC( hdcMem );
  1758. return;
  1759. }
  1760. //
  1761. // Flip the bitmap
  1762. //
  1763. SelectObject( hdcMem , hbm );
  1764. SET_DC_RTL_MIRRORED(hdcMem);
  1765. BitBlt( hdcMem , 0 , 0 , bm.bmWidth , bm.bmHeight ,
  1766. hdc , 0 , 0 , SRCCOPY );
  1767. SET_DC_LAYOUT(hdcMem,0);
  1768. //
  1769. // The offset by 1 is to solve the off-by-one (in hdcMem) problem. Solved.
  1770. // [samera]
  1771. //
  1772. BitBlt( hdc , 0 , 0 , bm.bmWidth , bm.bmHeight ,
  1773. hdcMem , 0 , 0 , SRCCOPY );
  1774. DeleteDC( hdcMem );
  1775. DeleteObject( hbm );
  1776. return;
  1777. }
  1778. // returns TRUE if handled
  1779. BOOL CCWndProc(CCONTROLINFO* pci, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plres)
  1780. {
  1781. if (uMsg >= CCM_FIRST && uMsg < CCM_LAST)
  1782. {
  1783. LRESULT lres = 0;
  1784. switch (uMsg)
  1785. {
  1786. case CCM_SETUNICODEFORMAT:
  1787. lres = pci->bUnicode;
  1788. pci->bUnicode = BOOLFROMPTR(wParam);
  1789. break;
  1790. case CCM_GETUNICODEFORMAT:
  1791. lres = pci->bUnicode;
  1792. break;
  1793. case CCM_SETVERSION:
  1794. lres = 6;
  1795. break;
  1796. case CCM_GETVERSION:
  1797. lres = 6;
  1798. break;
  1799. case CCM_DPISCALE:
  1800. pci->fDPIAware = (BOOL)wParam;
  1801. lres = 1;
  1802. break;
  1803. }
  1804. ASSERT(plres);
  1805. *plres = lres;
  1806. return TRUE;
  1807. }
  1808. return FALSE;
  1809. }
  1810. // Draws an insertmark.
  1811. void CCDrawInsertMark(HDC hdc, LPRECT prc, BOOL fHorizMode, COLORREF clr)
  1812. {
  1813. HPEN hPnMark = CreatePen(PS_SOLID, 1, clr);
  1814. HPEN hOldPn;
  1815. POINT rgPoint[4];
  1816. if (!hPnMark)
  1817. hPnMark = (HPEN)GetStockObject(BLACK_PEN); // fallback to draw with black pen
  1818. hOldPn = (HPEN)SelectObject(hdc, (HGDIOBJ)hPnMark);
  1819. if ( fHorizMode )
  1820. {
  1821. if (RECTWIDTH(*prc)>INSERTMARKSIZE && RECTHEIGHT(*prc)>3)
  1822. {
  1823. int iXCentre = prc->left + RECTWIDTH(*prc)/2; // make sure we truncate towards prc->left (not towards 0!)
  1824. rgPoint[0].x = iXCentre + 1;
  1825. rgPoint[0].y = prc->top + 2;
  1826. rgPoint[1].x = iXCentre + 3;
  1827. rgPoint[1].y = prc->top;
  1828. rgPoint[2].x = iXCentre - 2;
  1829. rgPoint[2].y = prc->top;
  1830. rgPoint[3].x = iXCentre;
  1831. rgPoint[3].y = prc->top + 2;
  1832. ASSERT(rgPoint[0].x >= prc->left && rgPoint[0].x < prc->right && rgPoint[0].y >= prc->top && rgPoint[0].y < prc->bottom);
  1833. ASSERT(rgPoint[1].x >= prc->left && rgPoint[1].x < prc->right && rgPoint[1].y >= prc->top && rgPoint[1].y < prc->bottom);
  1834. ASSERT(rgPoint[2].x >= prc->left && rgPoint[2].x < prc->right && rgPoint[2].y >= prc->top && rgPoint[2].y < prc->bottom);
  1835. ASSERT(rgPoint[3].x >= prc->left && rgPoint[3].x < prc->right && rgPoint[3].y >= prc->top && rgPoint[3].y < prc->bottom);
  1836. // draw the top bit...
  1837. Polyline( hdc, rgPoint, 4 );
  1838. rgPoint[0].x = iXCentre;
  1839. rgPoint[0].y = prc->top;
  1840. rgPoint[1].x = iXCentre;
  1841. rgPoint[1].y = prc->bottom - 1;
  1842. rgPoint[2].x = iXCentre + 1;
  1843. rgPoint[2].y = prc->bottom - 1;
  1844. rgPoint[3].x = iXCentre + 1;
  1845. rgPoint[3].y = prc->top;
  1846. ASSERT(rgPoint[0].x >= prc->left && rgPoint[0].x < prc->right && rgPoint[0].y >= prc->top && rgPoint[0].y < prc->bottom);
  1847. ASSERT(rgPoint[1].x >= prc->left && rgPoint[1].x < prc->right && rgPoint[1].y >= prc->top && rgPoint[1].y < prc->bottom);
  1848. ASSERT(rgPoint[2].x >= prc->left && rgPoint[2].x < prc->right && rgPoint[2].y >= prc->top && rgPoint[2].y < prc->bottom);
  1849. ASSERT(rgPoint[3].x >= prc->left && rgPoint[3].x < prc->right && rgPoint[3].y >= prc->top && rgPoint[3].y < prc->bottom);
  1850. // draw the middle...
  1851. Polyline( hdc, rgPoint, 4 );
  1852. rgPoint[0].x = iXCentre + 1;
  1853. rgPoint[0].y = prc->bottom - 3;
  1854. rgPoint[1].x = iXCentre + 3;
  1855. rgPoint[1].y = prc->bottom - 1;
  1856. rgPoint[2].x = iXCentre - 2;
  1857. rgPoint[2].y = prc->bottom - 1;
  1858. rgPoint[3].x = iXCentre;
  1859. rgPoint[3].y = prc->bottom - 3;
  1860. ASSERT(rgPoint[0].x >= prc->left && rgPoint[0].x < prc->right && rgPoint[0].y >= prc->top && rgPoint[0].y < prc->bottom);
  1861. ASSERT(rgPoint[1].x >= prc->left && rgPoint[1].x < prc->right && rgPoint[1].y >= prc->top && rgPoint[1].y < prc->bottom);
  1862. ASSERT(rgPoint[2].x >= prc->left && rgPoint[2].x < prc->right && rgPoint[2].y >= prc->top && rgPoint[2].y < prc->bottom);
  1863. ASSERT(rgPoint[3].x >= prc->left && rgPoint[3].x < prc->right && rgPoint[3].y >= prc->top && rgPoint[3].y < prc->bottom);
  1864. // draw the bottom bit...
  1865. Polyline( hdc, rgPoint, 4 );
  1866. }
  1867. }
  1868. else
  1869. {
  1870. if (RECTHEIGHT(*prc)>INSERTMARKSIZE && RECTWIDTH(*prc)>3)
  1871. {
  1872. int iYCentre = prc->top + RECTHEIGHT(*prc)/2; // make sure we truncate towards prc->top (not towards 0!)
  1873. rgPoint[0].x = prc->left + 2;
  1874. rgPoint[0].y = iYCentre;
  1875. rgPoint[1].x = prc->left;
  1876. rgPoint[1].y = iYCentre - 2;
  1877. rgPoint[2].x = prc->left;
  1878. rgPoint[2].y = iYCentre + 3;
  1879. rgPoint[3].x = prc->left + 2;
  1880. rgPoint[3].y = iYCentre + 1;
  1881. ASSERT(rgPoint[0].x >= prc->left && rgPoint[0].x < prc->right && rgPoint[0].y >= prc->top && rgPoint[0].y < prc->bottom);
  1882. ASSERT(rgPoint[1].x >= prc->left && rgPoint[1].x < prc->right && rgPoint[1].y >= prc->top && rgPoint[1].y < prc->bottom);
  1883. ASSERT(rgPoint[2].x >= prc->left && rgPoint[2].x < prc->right && rgPoint[2].y >= prc->top && rgPoint[2].y < prc->bottom);
  1884. ASSERT(rgPoint[3].x >= prc->left && rgPoint[3].x < prc->right && rgPoint[3].y >= prc->top && rgPoint[3].y < prc->bottom);
  1885. // draw the top bit...
  1886. Polyline( hdc, rgPoint, 4 );
  1887. rgPoint[0].x = prc->left;
  1888. rgPoint[0].y = iYCentre;
  1889. rgPoint[1].x = prc->right - 1;
  1890. rgPoint[1].y = iYCentre;
  1891. rgPoint[2].x = prc->right - 1;
  1892. rgPoint[2].y = iYCentre + 1;
  1893. rgPoint[3].x = prc->left;
  1894. rgPoint[3].y = iYCentre + 1;
  1895. ASSERT(rgPoint[0].x >= prc->left && rgPoint[0].x < prc->right && rgPoint[0].y >= prc->top && rgPoint[0].y < prc->bottom);
  1896. ASSERT(rgPoint[1].x >= prc->left && rgPoint[1].x < prc->right && rgPoint[1].y >= prc->top && rgPoint[1].y < prc->bottom);
  1897. ASSERT(rgPoint[2].x >= prc->left && rgPoint[2].x < prc->right && rgPoint[2].y >= prc->top && rgPoint[2].y < prc->bottom);
  1898. ASSERT(rgPoint[3].x >= prc->left && rgPoint[3].x < prc->right && rgPoint[3].y >= prc->top && rgPoint[3].y < prc->bottom);
  1899. // draw the middle...
  1900. Polyline( hdc, rgPoint, 4 );
  1901. rgPoint[0].x = prc->right - 3;
  1902. rgPoint[0].y = iYCentre;
  1903. rgPoint[1].x = prc->right - 1;
  1904. rgPoint[1].y = iYCentre - 2;
  1905. rgPoint[2].x = prc->right - 1;
  1906. rgPoint[2].y = iYCentre + 3;
  1907. rgPoint[3].x = prc->right - 3;
  1908. rgPoint[3].y = iYCentre + 1;
  1909. ASSERT(rgPoint[0].x >= prc->left && rgPoint[0].x < prc->right && rgPoint[0].y >= prc->top && rgPoint[0].y < prc->bottom);
  1910. ASSERT(rgPoint[1].x >= prc->left && rgPoint[1].x < prc->right && rgPoint[1].y >= prc->top && rgPoint[1].y < prc->bottom);
  1911. ASSERT(rgPoint[2].x >= prc->left && rgPoint[2].x < prc->right && rgPoint[2].y >= prc->top && rgPoint[2].y < prc->bottom);
  1912. ASSERT(rgPoint[3].x >= prc->left && rgPoint[3].x < prc->right && rgPoint[3].y >= prc->top && rgPoint[3].y < prc->bottom);
  1913. // draw the bottom bit...
  1914. Polyline( hdc, rgPoint, 4 );
  1915. }
  1916. }
  1917. SelectObject( hdc, hOldPn );
  1918. DeleteObject((HGDIOBJ)hPnMark);
  1919. }
  1920. BOOL CCGetIconSize(LPCCONTROLINFO pCI, HIMAGELIST himl, int* pcx, int* pcy)
  1921. {
  1922. BOOL f = ImageList_GetIconSize(himl, pcx, pcy);
  1923. if (f && pCI->fDPIAware)
  1924. {
  1925. CCDPIScaleX(pcx);
  1926. CCDPIScaleY(pcy);
  1927. }
  1928. return f;
  1929. }
  1930. // The return value tells if the state changed or not (TRUE == change)
  1931. BOOL CCOnUIState(LPCCONTROLINFO pControlInfo,
  1932. UINT uMessage, WPARAM wParam, LPARAM lParam)
  1933. {
  1934. WORD wOldUIState = pControlInfo->wUIState;
  1935. // That's the only message we handle
  1936. if (WM_UPDATEUISTATE == uMessage)
  1937. {
  1938. switch (LOWORD(wParam))
  1939. {
  1940. case UIS_SET:
  1941. pControlInfo->wUIState |= HIWORD(wParam);
  1942. break;
  1943. case UIS_CLEAR:
  1944. pControlInfo->wUIState &= ~(HIWORD(wParam));
  1945. break;
  1946. }
  1947. }
  1948. // These message always need to be passed to DefWindowProc
  1949. return (wOldUIState != pControlInfo->wUIState);
  1950. }
  1951. BOOL CCNotifyNavigationKeyUsage(LPCCONTROLINFO pControlInfo, WORD wFlag)
  1952. {
  1953. BOOL fRet = FALSE;
  1954. // do something only if not already in keyboard mode
  1955. if ((CCGetUIState(pControlInfo) & (UISF_HIDEFOCUS | UISF_HIDEACCEL)) != wFlag)
  1956. {
  1957. SendMessage(pControlInfo->hwndParent, WM_CHANGEUISTATE,
  1958. MAKELONG(UIS_CLEAR, wFlag), 0);
  1959. pControlInfo->wUIState &= ~(wFlag);
  1960. // we did the notify
  1961. fRet = TRUE;
  1962. }
  1963. return fRet;
  1964. }
  1965. BOOL CCGetUIState(LPCCONTROLINFO pControlInfo)
  1966. {
  1967. return pControlInfo->wUIState;
  1968. }
  1969. #ifdef FULL_DEBUG
  1970. void DebugPaintInvalid(HWND hwnd, RECT* prc, HRGN rgn)
  1971. {
  1972. if (GetKeyState(VK_SCROLL) < 0)
  1973. {
  1974. HDC hdc;
  1975. HBRUSH hbrush;
  1976. int bkMode;
  1977. static int s_iclr;
  1978. static COLORREF s_aclr[] =
  1979. {
  1980. RGB(0, 0, 0),
  1981. RGB(255, 0, 0),
  1982. RGB(0, 255, 0),
  1983. RGB(0, 0, 255),
  1984. RGB(255, 255, 0),
  1985. RGB(0, 255, 255),
  1986. RGB(255, 255, 255),
  1987. RGB(255, 0, 255),
  1988. };
  1989. s_iclr = (s_iclr + 1) % ARRAYSIZE(s_aclr);
  1990. hdc = GetDC(hwnd);
  1991. hbrush = CreateHatchBrush(HS_DIAGCROSS, s_aclr[s_iclr]);
  1992. bkMode = SetBkMode(hdc, TRANSPARENT);
  1993. if (rgn)
  1994. {
  1995. FillRgn(hdc, rgn, hbrush);
  1996. }
  1997. else
  1998. {
  1999. RECT rc;
  2000. if (prc == NULL)
  2001. {
  2002. prc = &rc;
  2003. GetClientRect(hwnd, &rc);
  2004. OffsetRect(&rc, -rc.left, -rc.top);
  2005. }
  2006. FillRect(hdc, prc, hbrush);
  2007. }
  2008. DeleteObject((HGDIOBJ)hbrush);
  2009. SetBkMode(hdc, bkMode);
  2010. ReleaseDC(hwnd, hdc);
  2011. if (GetKeyState(VK_SHIFT) < 0)
  2012. Sleep(500);
  2013. else
  2014. Sleep(120);
  2015. }
  2016. }
  2017. void DebugPaintClip(HWND hwnd, HDC hdc)
  2018. {
  2019. if (GetKeyState(VK_SCROLL) < 0)
  2020. {
  2021. HDC hdcH = GetDC(hwnd);
  2022. HRGN hrgn = CreateRectRgn(0, 0, 0, 0);
  2023. GetClipRgn(hdc, hrgn);
  2024. InvertRgn(hdcH, hrgn);
  2025. if (GetKeyState(VK_SHIFT) < 0)
  2026. Sleep(500);
  2027. else
  2028. Sleep(120);
  2029. InvertRgn(hdcH, hrgn);
  2030. DeleteObject(hrgn);
  2031. ReleaseDC(hwnd, hdcH);
  2032. }
  2033. }
  2034. void DebugPaintRect(HDC hdc, PRECT prc)
  2035. {
  2036. if (GetKeyState(VK_SCROLL) < 0)
  2037. {
  2038. HRGN hrgn = CreateRectRgnIndirect(prc);
  2039. InvertRgn(hdc, hrgn);
  2040. if (GetKeyState(VK_SHIFT) < 0)
  2041. Sleep(500);
  2042. else
  2043. Sleep(120);
  2044. InvertRgn(hdc, hrgn);
  2045. DeleteObject(hrgn);
  2046. }
  2047. }
  2048. #endif
  2049. void SHOutlineRectThickness(HDC hdc, const RECT* prc, COLORREF cr, COLORREF crDefault, int cp)
  2050. {
  2051. RECT rc;
  2052. COLORREF clrSave = SetBkColor(hdc, cr == CLR_DEFAULT ? crDefault : cr);
  2053. // See if we overflow the bounding rect
  2054. if (IsRectEmpty(prc))
  2055. {
  2056. return;
  2057. }
  2058. //top
  2059. rc.left = prc->left;
  2060. rc.top = prc->top;
  2061. rc.right = prc->right;
  2062. rc.bottom = prc->top + cp;
  2063. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  2064. //left
  2065. rc.left = prc->left;
  2066. rc.top = prc->top;
  2067. rc.right = prc->left + cp;
  2068. rc.bottom = prc->bottom;
  2069. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  2070. //right
  2071. rc.left = prc->right - cp;
  2072. rc.top = prc->top;
  2073. rc.right = prc->right;
  2074. rc.bottom = prc->bottom;
  2075. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  2076. // bottom
  2077. rc.left = prc->left;
  2078. rc.top = prc->bottom - cp;
  2079. rc.right = prc->right;
  2080. rc.bottom = prc->bottom;
  2081. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  2082. SetBkColor(hdc, clrSave);
  2083. }
  2084. BOOL IsUsingCleartype()
  2085. {
  2086. int iSmoothingType = FE_FONTSMOOTHINGSTANDARD;
  2087. SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &iSmoothingType, 0);
  2088. return FE_FONTSMOOTHINGCLEARTYPE == iSmoothingType;
  2089. }
  2090. //#define NO_UXTHEME_PRINTING
  2091. // Gets the bits from the parent for a rect relative to the client
  2092. BOOL CCSendPrintRect(CCONTROLINFO* pci, HDC hdc, RECT* prc)
  2093. {
  2094. #ifndef NO_UXTHEME_PRINTING
  2095. // Call into UxTheme to get the background image. They have hooks to
  2096. // tell us if an app processed this message.
  2097. return (S_OK == DrawThemeParentBackground(pci->hwnd, hdc, prc));
  2098. #else
  2099. HRGN hrgnOld = NULL;
  2100. POINT pt;
  2101. RECT rc;
  2102. if (prc)
  2103. {
  2104. hrgnOld = CreateRectRgn(0,0,0,0);
  2105. // Is there a clipping rgn set on the context already?
  2106. if (GetClipRgn(hdc, hrgnOld) == 0)
  2107. {
  2108. // No, then get rid of the one I just created. NOTE: hrgnOld is NULL meaning we will
  2109. // remove the region later that we set in this next call to SelectClipRgn
  2110. DeleteObject(hrgnOld);
  2111. hrgnOld = NULL;
  2112. }
  2113. IntersectClipRect(hdc, prc->left, prc->top, prc->right, prc->bottom);
  2114. }
  2115. GetWindowRect(pci->hwnd, &rc);
  2116. MapWindowPoints(NULL, pci->hwndParent, (POINT*)&rc, 2);
  2117. GetViewportOrgEx(hdc, &pt);
  2118. SetViewportOrgEx(hdc, pt.x - rc.left, pt.y - rc.top, NULL);
  2119. SendMessage(pci->hwndParent, WM_PRINTCLIENT, (WPARAM)hdc, (LPARAM)PRF_CLIENT);
  2120. SetViewportOrgEx(hdc, pt.x, pt.y, NULL);
  2121. if (hrgnOld)
  2122. {
  2123. SelectClipRgn(hdc, hrgnOld);
  2124. DeleteObject(hrgnOld);
  2125. }
  2126. return TRUE;
  2127. #endif
  2128. }
  2129. // Gets the bits from the parent for the whole control
  2130. BOOL CCSendPrint(CCONTROLINFO* pci, HDC hdc)
  2131. {
  2132. #ifndef NO_UXTHEME_PRINTING
  2133. // Call into UxTheme to get the background image. They have hooks to
  2134. // tell us if an app processed this message.
  2135. return (S_OK == DrawThemeParentBackground(pci->hwnd, hdc, NULL));
  2136. #else
  2137. return CCSendPrintRect(pci, hdc, NULL);
  2138. #endif
  2139. }
  2140. BOOL CCForwardPrint(CCONTROLINFO* pci, HDC hdc)
  2141. {
  2142. #ifndef NO_UXTHEME_PRINTING
  2143. // Call into UxTheme to get the background image. They have hooks to
  2144. // tell us if an app processed this message.
  2145. return (S_OK == DrawThemeParentBackground(pci->hwnd, hdc, NULL));
  2146. #else
  2147. return CCSendPrintRect(pci, hdc, NULL);
  2148. #endif
  2149. }
  2150. BOOL CCShouldAskForBits(CCONTROLINFO* pci, HTHEME hTheme, int iPart, int iState)
  2151. {
  2152. // If the control is transparent, we assume composited.
  2153. return !(pci->dwExStyle & WS_EX_TRANSPARENT) &&
  2154. IsThemeBackgroundPartiallyTransparent(hTheme, iPart, iState);
  2155. }
  2156. BOOL AreAllMonitorsAtLeast(int iBpp)
  2157. {
  2158. DISPLAY_DEVICE DisplayDevice = { SIZEOF(DISPLAY_DEVICE) };
  2159. BOOL fAreAllMonitorsAtLeast = TRUE;
  2160. int iEnum = 0;
  2161. while (EnumDisplayDevices(NULL, iEnum, &DisplayDevice, 0))
  2162. {
  2163. if (DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
  2164. {
  2165. HDC hdc = CreateDC(NULL, (LPTSTR)DisplayDevice.DeviceName, NULL, NULL);
  2166. if (hdc)
  2167. {
  2168. int iBits = GetDeviceCaps(hdc, BITSPIXEL);
  2169. if (iBits < iBpp)
  2170. fAreAllMonitorsAtLeast = FALSE;
  2171. DeleteDC(hdc);
  2172. }
  2173. }
  2174. ZeroMemory(&DisplayDevice, SIZEOF(DisplayDevice));
  2175. DisplayDevice.cb = SIZEOF(DisplayDevice);
  2176. iEnum++;
  2177. }
  2178. return fAreAllMonitorsAtLeast;
  2179. }
  2180. int CCGetScreenDPI()
  2181. {
  2182. return g_iDPI;
  2183. }
  2184. BOOL CCIsHighDPI()
  2185. {
  2186. return g_fScale;
  2187. }
  2188. void CCDPIScaleX(int* x)
  2189. {
  2190. if (g_fScale)
  2191. *x = (int)( *x * g_dScaleX);
  2192. }
  2193. void CCDPIScaleY(int* y)
  2194. {
  2195. if (g_fScale)
  2196. *y = (int)( *y * g_dScaleY);
  2197. }
  2198. void CCAdjustForBold(LOGFONT* plf)
  2199. {
  2200. ASSERT(plf);
  2201. plf->lfWeight = FW_BOLD;
  2202. }
  2203. #ifdef DEBUG
  2204. void DumpRgn(ULONGLONG qwFlags, char* trace, HRGN hrgn)
  2205. {
  2206. int iSize = GetRegionData(hrgn, 0, NULL);
  2207. if (iSize > 0)
  2208. {
  2209. RGNDATA* rd = (RGNDATA*)LocalAlloc(LPTR, iSize + sizeof(RGNDATA));
  2210. if (rd)
  2211. {
  2212. DWORD i;
  2213. RECT* prc;
  2214. rd->rdh.dwSize = sizeof(rd->rdh);
  2215. rd->rdh.iType = RDH_RECTANGLES;
  2216. GetRegionData(hrgn, iSize, rd);
  2217. prc = (RECT*)&rd->Buffer;
  2218. for (i = 0; i < rd->rdh.nCount; i++)
  2219. {
  2220. TraceMsg(qwFlags, "%s: %d, %d, %d, %d", trace, prc[i].left, prc[i].top, prc[i].right, prc[i].bottom);
  2221. }
  2222. LocalFree(rd);
  2223. }
  2224. }
  2225. }
  2226. #endif
  2227. HDC CCBeginDoubleBuffer(HDC hdcIn, RECT* prc, CCDBUFFER* pdb)
  2228. {
  2229. HDC hdc = hdcIn;
  2230. ZeroMemory(pdb, sizeof(CCDBUFFER));
  2231. pdb->hPaintDC = hdcIn;
  2232. pdb->rc = *prc;
  2233. pdb->hMemDC = CreateCompatibleDC(hdcIn);
  2234. if (pdb->hMemDC)
  2235. {
  2236. pdb->hMemBm = CreateCompatibleBitmap(hdc, RECTWIDTH(pdb->rc), RECTHEIGHT(pdb->rc));
  2237. if (pdb->hMemBm)
  2238. {
  2239. pdb->hOldBm = (HBITMAP) SelectObject(pdb->hMemDC, pdb->hMemBm);
  2240. // Offset painting to paint in region
  2241. OffsetWindowOrgEx(pdb->hMemDC, pdb->rc.left, pdb->rc.top, NULL);
  2242. pdb->fInitialized = TRUE;
  2243. hdc = pdb->hMemDC;
  2244. }
  2245. else
  2246. {
  2247. DeleteDC(pdb->hMemDC);
  2248. }
  2249. }
  2250. return hdc;
  2251. }
  2252. void CCEndDoubleBuffer(CCDBUFFER* pdb)
  2253. {
  2254. if (pdb->fInitialized)
  2255. {
  2256. BitBlt(pdb->hPaintDC, pdb->rc.left, pdb->rc.top, RECTWIDTH(pdb->rc), RECTHEIGHT(pdb->rc), pdb->hMemDC, pdb->rc.left, pdb->rc.top, SRCCOPY);
  2257. SelectObject(pdb->hMemDC, pdb->hOldBm);
  2258. DeleteObject(pdb->hMemBm);
  2259. DeleteDC(pdb->hMemDC);
  2260. }
  2261. }
  2262. #ifdef FEATURE_FOLLOW_FOCUS_RECT
  2263. HWND g_hwndFocus = NULL;
  2264. void CCLostFocus(HWND hwnd)
  2265. {
  2266. // if (g_hwndFocus)
  2267. // DestroyWindow(g_hwndFocus);
  2268. // g_hwndFocus = NULL;
  2269. }
  2270. HDC CreateLayer(RECT* prc)
  2271. {
  2272. HDC hdc;
  2273. BITMAPINFO bi = {0};
  2274. bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
  2275. bi.bmiHeader.biWidth = RECTWIDTH(*prc);
  2276. bi.bmiHeader.biHeight = RECTHEIGHT(*prc);
  2277. bi.bmiHeader.biPlanes = 1;
  2278. bi.bmiHeader.biBitCount = 32;
  2279. bi.bmiHeader.biCompression = BI_RGB;
  2280. hdc = CreateCompatibleDC(NULL);
  2281. if (hdc)
  2282. {
  2283. ULONG* prgb;
  2284. HBITMAP hbmp = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, (void**)&prgb, NULL, 0);
  2285. if (hbmp)
  2286. {
  2287. int z;
  2288. SIZE sz = {RECTWIDTH(*prc), RECTHEIGHT(*prc)};
  2289. RECT rc = {0, 0, sz.cx, sz.cy};
  2290. int iTotalSize = sz.cx * sz.cy;
  2291. DeleteObject(SelectObject(hdc, hbmp));
  2292. InflateRect(&rc, -2, -2);
  2293. SHOutlineRectThickness(hdc, &rc, RGB(0,0,255), RGB(0,0,255), 1);
  2294. for (z = 0; z < iTotalSize; z++)
  2295. {
  2296. if (((PULONG)prgb)[z] != 0)
  2297. ((PULONG)prgb)[z] = 0xa0000000;
  2298. }
  2299. BlurBitmap(prgb, sz, RGB(0,0,255));
  2300. InflateRect(&rc, -2, -2);
  2301. FillRectClr(hdc, &rc, RGB(0,0,0));
  2302. }
  2303. }
  2304. return hdc;
  2305. }
  2306. typedef struct tagEffect
  2307. {
  2308. HDC hdcImage;
  2309. RECT rcCurrent;
  2310. RECT rcSrc;
  2311. RECT rcDest;
  2312. int iStep;
  2313. } Effect;
  2314. #define EW_SETFOCUS WM_USER+1
  2315. #define EW_LOSTFOCUS WM_USER+2
  2316. void Effect_GenerateRect(Effect* pe, RECT* prc)
  2317. {
  2318. HDC hdcWin = GetDC(g_hwndFocus);
  2319. if (hdcWin)
  2320. {
  2321. BLENDFUNCTION bf = {0};
  2322. POINT pt = {0};
  2323. POINT ptDest = {pe->rcCurrent.left, pe->rcCurrent.top};
  2324. SIZE sz = {RECTWIDTH(*prc), RECTHEIGHT(*prc)};
  2325. if (pe->hdcImage)
  2326. DeleteDC(pe->hdcImage);
  2327. pe->hdcImage = CreateLayer(prc);
  2328. bf.BlendOp = AC_SRC_OVER;
  2329. bf.AlphaFormat = AC_SRC_ALPHA;
  2330. bf.SourceConstantAlpha = 255;
  2331. UpdateLayeredWindow(g_hwndFocus, hdcWin, &ptDest, &sz, pe->hdcImage, &pt, 0, &bf, ULW_ALPHA);
  2332. SetWindowPos(g_hwndFocus, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
  2333. ReleaseDC(g_hwndFocus, hdcWin);
  2334. }
  2335. }
  2336. LRESULT EffectWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2337. {
  2338. Effect* pe = (Effect*)GetWindowLongPtr(hwnd, GWL_USERDATA);
  2339. if ( pe == NULL)
  2340. {
  2341. if (uMsg == WM_NCCREATE)
  2342. {
  2343. pe = LocalAlloc(LPTR, sizeof(Effect));
  2344. SetWindowLong(hwnd, GWL_USERDATA, (LONG)pe);
  2345. }
  2346. if (pe == NULL)
  2347. return 0;
  2348. }
  2349. else switch (uMsg)
  2350. {
  2351. case EW_SETFOCUS:
  2352. {
  2353. RECT* prc = (RECT*)lParam;
  2354. if (IsRectEmpty(&pe->rcCurrent))
  2355. pe->rcSrc = pe->rcCurrent = *prc;
  2356. pe->rcDest = *prc;
  2357. Effect_GenerateRect(pe, prc);
  2358. KillTimer(hwnd, 1);
  2359. pe->rcSrc = pe->rcCurrent;
  2360. pe->iStep = 1;
  2361. SetTimer(hwnd, 2, 5, NULL);
  2362. }
  2363. break;
  2364. case EW_LOSTFOCUS:
  2365. //SetTimer(hwnd, 1, 100, NULL);
  2366. break;
  2367. case WM_TIMER:
  2368. if (wParam == 1)
  2369. {
  2370. DestroyWindow(hwnd);
  2371. g_hwndFocus = NULL;
  2372. }
  2373. else if (wParam == 2)
  2374. {
  2375. BLENDFUNCTION bf = {0};
  2376. POINT pt = {0};
  2377. POINT ptDest;
  2378. SIZE sz;
  2379. if (pe->iStep >= 20 || IsRectEmpty(&pe->rcCurrent) || EqualRect(&pe->rcCurrent, &pe->rcDest))
  2380. {
  2381. pe->rcCurrent = pe->rcDest;
  2382. pe->iStep = 0;
  2383. KillTimer(hwnd, 2);
  2384. }
  2385. else
  2386. {
  2387. pe->rcCurrent.top += (pe->rcDest.top - pe->rcSrc.top) / 20;
  2388. pe->rcCurrent.left += (pe->rcDest.left - pe->rcSrc.left) / 20;
  2389. pe->rcCurrent.right += (pe->rcDest.right - pe->rcSrc.right) / 20;
  2390. pe->rcCurrent.bottom += (pe->rcDest.bottom - pe->rcSrc.bottom) / 20;
  2391. pe->iStep++;
  2392. }
  2393. sz.cx = RECTWIDTH(pe->rcCurrent);
  2394. sz.cy = RECTHEIGHT(pe->rcCurrent);
  2395. ptDest.x = pe->rcCurrent.left;
  2396. ptDest.y = pe->rcCurrent.top;
  2397. Effect_GenerateRect(pe, &pe->rcCurrent);
  2398. }
  2399. break;
  2400. case WM_DESTROY:
  2401. if (pe->hdcImage)
  2402. DeleteDC(pe->hdcImage);
  2403. LocalFree(pe);
  2404. break;
  2405. default:
  2406. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  2407. }
  2408. return 1;
  2409. }
  2410. void CCSetFocus(HWND hwnd, RECT* prc)
  2411. {
  2412. RECT rc;
  2413. if (prc == NULL)
  2414. {
  2415. prc = &rc;
  2416. GetWindowRect(hwnd, &rc);
  2417. }
  2418. InflateRect(prc, 4, 4);
  2419. if (!g_hwndFocus)
  2420. {
  2421. WNDCLASS wc ={0};
  2422. wc.hbrBackground = GetStockObject(BLACK_BRUSH);
  2423. wc.hInstance = HINST_THISDLL;
  2424. wc.lpfnWndProc = EffectWndProc;
  2425. wc.lpszClassName = TEXT("Effect");
  2426. RegisterClass(&wc);
  2427. g_hwndFocus = CreateWindowEx(WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOOLWINDOW, TEXT("Effect"),
  2428. NULL, WS_POPUP, prc->left, prc->top, RECTWIDTH(*prc), RECTHEIGHT(*prc),
  2429. NULL, NULL, HINST_THISDLL, NULL);
  2430. }
  2431. if (g_hwndFocus)
  2432. {
  2433. SendMessage(g_hwndFocus, EW_SETFOCUS, (WPARAM)hwnd, (LPARAM)prc);
  2434. }
  2435. }
  2436. #endif
  2437. BOOL CCDrawNonClientTheme(HTHEME hTheme, HWND hwnd, HRGN hRgnUpdate, HBRUSH hbr, int iPartId, int iStateId)
  2438. {
  2439. BOOL fRet = FALSE;
  2440. HDC hdc;
  2441. DWORD dwFlags = DCX_USESTYLE | DCX_WINDOW | DCX_LOCKWINDOWUPDATE;
  2442. if (hRgnUpdate)
  2443. dwFlags |= DCX_INTERSECTRGN | DCX_NODELETERGN;
  2444. hdc = GetDCEx(hwnd, hRgnUpdate, dwFlags);
  2445. if (hdc)
  2446. {
  2447. RECT rc;
  2448. HRGN hrgn;
  2449. int cxBorder = g_cxBorder, cyBorder = g_cyBorder;
  2450. if (SUCCEEDED(GetThemeInt(hTheme, iPartId, iStateId, TMT_SIZINGBORDERWIDTH, &cxBorder)))
  2451. {
  2452. cyBorder = cxBorder;
  2453. }
  2454. GetWindowRect(hwnd, &rc);
  2455. //
  2456. // Create an update region without the client edge
  2457. // to pass to DefWindowProc
  2458. //
  2459. InflateRect(&rc, -g_cxEdge, -g_cyEdge);
  2460. hrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
  2461. if (hrgn)
  2462. {
  2463. if (hRgnUpdate)
  2464. {
  2465. CombineRgn(hrgn, hRgnUpdate, hrgn, RGN_AND);
  2466. }
  2467. //
  2468. // Zero-origin the rect
  2469. //
  2470. OffsetRect(&rc, -rc.left, -rc.top);
  2471. //
  2472. // clip our drawing to the non-client edge
  2473. //
  2474. OffsetRect(&rc, g_cxEdge, g_cyEdge);
  2475. ExcludeClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
  2476. InflateRect(&rc, g_cxEdge, g_cyEdge);
  2477. DrawThemeBackground(hTheme, hdc, iPartId, iStateId, &rc, 0);
  2478. //
  2479. // Fill with the control's brush first since the ThemeBackground
  2480. // border may not be as thick as the client edge
  2481. //
  2482. if ((cxBorder < g_cxEdge) && (cyBorder < g_cyEdge))
  2483. {
  2484. InflateRect(&rc, cxBorder-g_cxEdge, cyBorder-g_cyEdge);
  2485. FillRect(hdc, &rc, hbr);
  2486. }
  2487. DefWindowProc(hwnd, WM_NCPAINT, (WPARAM)hrgn, 0);
  2488. DeleteObject(hrgn);
  2489. }
  2490. ReleaseDC(hwnd, hdc);
  2491. fRet = TRUE;
  2492. }
  2493. return fRet;
  2494. }
  2495. void FillRectClr(HDC hdc, PRECT prc, COLORREF clr)
  2496. {
  2497. COLORREF clrSave = SetBkColor(hdc, clr);
  2498. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, prc, NULL, 0, NULL);
  2499. SetBkColor(hdc, clrSave);
  2500. }