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.

542 lines
13 KiB

  1. #include "sol.h"
  2. VSZASSERT
  3. /* flags for _lseek */
  4. #define SEEK_CUR 1
  5. #define SEEK_END 2
  6. #define SEEK_SET 0
  7. #define cbBand 8192
  8. BGND bgnd;
  9. BOOL _FValidBm(BMP *pbm)
  10. {
  11. return((pbm->biBitCount == 1 || pbm->biBitCount == 4)
  12. && pbm->biPlanes == 1 && pbm->biSize == sizeof(BMP));
  13. }
  14. BOOL FInitBgnd(TCHAR *szFile)
  15. {
  16. INT fh;
  17. BOOL fResult;
  18. LONG lcbBm;
  19. LONG dwBmSize;
  20. fResult = fFalse;
  21. bgnd.fUseBitmap = fFalse;
  22. if((fh = OpenFile(szFile, &bgnd.of, OF_CANCEL|OF_READ)) == -1)
  23. return fFalse;
  24. if(!FReadDibBitmapInfo(fh, &bgnd.bm))
  25. goto ReturnClose;
  26. bgnd.dwOfsBits = M_llseek( fh, 0L, SEEK_CUR);
  27. if(!_FValidBm(&bgnd.bm))
  28. goto ReturnClose;
  29. /* BUG: check if bitmap is ok */
  30. bgnd.cbLine = (((INT) bgnd.bm.biWidth * bgnd.bm.biBitCount+31)/32)*4;
  31. lcbBm = (LONG) bgnd.cbLine * DyBmp(bgnd.bm);
  32. bgnd.ibndMac = (INT) ((lcbBm+cbBand-1) / cbBand);
  33. if((bgnd.rghbnd = PAlloc(bgnd.ibndMac*sizeof(HANDLE))) == NULL)
  34. goto ReturnClose;
  35. bgnd.dyBand = (INT) ((LONG) DyBmp(bgnd.bm) * cbBand / lcbBm);
  36. bgnd.fUseBitmap = fTrue;
  37. SetBgndOrg();
  38. fResult = fTrue;
  39. ReturnClose:
  40. M_lclose(fh);
  41. return fResult;
  42. }
  43. BOOL FDestroyBgnd()
  44. {
  45. INT ibnd;
  46. HANDLE *phbnd;
  47. if(bgnd.fUseBitmap)
  48. {
  49. for(ibnd = 0; ibnd < bgnd.ibndMac; ibnd++)
  50. {
  51. if(*(phbnd = &bgnd.rghbnd[ibnd]) != NULL)
  52. {
  53. GlobalFree(*phbnd);
  54. *phbnd = NULL;
  55. }
  56. }
  57. FreeP(bgnd.rghbnd);
  58. }
  59. return fTrue;
  60. }
  61. BOOL FGetBgndFile(TCHAR *sz)
  62. {
  63. if(bgnd.fUseBitmap)
  64. PszCopy(bgnd.of.szPathName, sz);
  65. else
  66. sz[0] = TEXT('\000');
  67. return fTrue;
  68. }
  69. BOOL _FLoadBand(INT ibnd, Y y)
  70. {
  71. HANDLE hbnd;
  72. BYTE[ ]*FAR[ ]**lpb;
  73. INT ipln;
  74. INT fh;
  75. LONG lcbpln;
  76. HANDLE *phbnd;
  77. DY dy;
  78. phbnd = &bgnd.rghbnd[ibnd];
  79. if(*phbnd != NULL)
  80. GlobalFree(*phbnd);
  81. hbnd = GlobalAlloc(GMEM_MOVEABLE|GMEM_DISCARDABLE, (LONG) cbBand);
  82. lpb = GlobalLock(hbnd);
  83. if(lpb == NULL)
  84. return fFalse;
  85. fh = OpenFile("", &bgnd.of, OF_REOPEN|OF_READ );
  86. lcbpln = 0L;
  87. dy = WMin(bgnd.dyBand, DyBmp(bgnd.bm)-y);
  88. for(ipln = 0; ipln < CplnBmp(bgnd.bm); ipln++)
  89. {
  90. M_llseek( fh, (LONG)OfsBits(bgnd)+ipln*lcbpln+(y)*CbLine(bgnd), 0);
  91. M_lread( fh, (LPSTR) lpb+ipln*CbLine(bgnd)*bgnd.dyBand, dy * CbLine(bgnd));
  92. }
  93. GlobalUnlock(hbnd);
  94. *phbnd = hbnd;
  95. M_lclose(fh);
  96. return fTrue;
  97. }
  98. Y _YDrawBand(HDC hdcMem, HBITMAP hbm, X xLeft, Y yTop, X xRight, Y yBot)
  99. {
  100. HBITMAP hbmSav;
  101. HANDLE hbnd;
  102. BYTE[ ]*FAR[ ]**lpb;
  103. Y y;
  104. INT ibnd;
  105. /* round yTop to nearest band */
  106. y = ((yTop-bgnd.ptOrg.y)/bgnd.dyBand)*bgnd.dyBand;
  107. ibnd = y/bgnd.dyBand;
  108. if(ibnd < 0)
  109. return bgnd.ptOrg.y;
  110. if(ibnd >= bgnd.ibndMac)
  111. return yBot+1;
  112. ibnd = bgnd.ibndMac-ibnd-1;
  113. Assert(ibnd >= 0);
  114. Assert(ibnd < bgnd.ibndMac);
  115. while((hbnd = bgnd.rghbnd[ibnd]) == NULL ||
  116. (lpb = (BYTE[ ]*FAR[ ]**) GlobalLock(hbnd)) == NULL)
  117. {
  118. if(!_FLoadBand(ibnd, y))
  119. /* KLUDGE:, should back out gracefully */
  120. return yBot;
  121. }
  122. Assert(lpb != NULL);
  123. SetDIBitsToDevice(hdcCur, xLeft-xOrgCur, yTop-yOrgCur,
  124. WMin(xRight-xLeft, DyBmp(bgnd.bm)-xLeft+bgnd.ptOrg.x),
  125. WMin(WMin(bgnd.dyBand, yBot-yTop), DyBmp(bgnd.bm)-yTop+bgnd.ptOrg.y),
  126. 0, 0,
  127. y-bgnd.ptOrg.y,
  128. bgnd.dyBand,
  129. // xLeft-bgnd.ptOrg.x, yTop-y-bgnd.ptOrg.y,
  130. // 0,
  131. // WMin(WMin(bgnd.dyBand, yBot-yTop), DyBmp(bgnd.bm)-yTop+bgnd.ptOrg.y),
  132. lpb,
  133. (BITMAPINFO FAR *)&bgnd.bm,
  134. DIB_RGB_COLORS);
  135. GlobalUnlock(hbnd);
  136. return y+bgnd.dyBand+bgnd.ptOrg.y;
  137. }
  138. VOID DrawBgnd(X xLeft, Y yTop, X xRight, Y yBot)
  139. {
  140. INT dy;
  141. Y y;
  142. HDC hdcMem;
  143. HBITMAP hbm;
  144. HBRUSH hbr;
  145. if(bgnd.fUseBitmap)
  146. {
  147. for(y = yTop; y <= yBot; )
  148. {
  149. y = _YDrawBand(hdcMem, hbm, xLeft, y, xRight, yBot);
  150. }
  151. ExcludeClipRect(hdcCur, bgnd.ptOrg.x-xOrgCur, bgnd.ptOrg.y-yOrgCur, bgnd.ptOrg.x+DxBmp(bgnd.bm)-xOrgCur, bgnd.ptOrg.y+DyBmp(bgnd.bm)-yOrgCur);
  152. }
  153. MSetBrushOrg(hdcCur, xOrgCur, yOrgCur);
  154. MUnrealizeObject( hbrTable );
  155. hbr = SelectObject(hdcCur, hbrTable);
  156. Assert(xRight >= xLeft);
  157. Assert(yBot >= yTop);
  158. PatBlt(hdcCur, xLeft-xOrgCur, yTop-yOrgCur, xRight-xLeft, yBot-yTop, PATCOPY);
  159. SelectObject(hdcCur, hbr);
  160. if(bgnd.fUseBitmap)
  161. SelectClipRgn(hdcCur, NULL);
  162. }
  163. VOID SetBgndOrg()
  164. {
  165. bgnd.ptOrg.x = (rcClient.xRight - DxBmp(bgnd.bm))/2;
  166. bgnd.ptOrg.y = (rcClient.yBot - DyBmp(bgnd.bm))/2;
  167. }
  168. /*
  169. * ReadDibBitmapInfo()
  170. *
  171. * Will read a file in DIB format and return a global HANDLE to it's
  172. * BITMAPINFO. This function will work with both "old" and "new"
  173. * bitmap formats, but will allways return a "new" BITMAPINFO
  174. *
  175. */
  176. BOOL FReadDibBitmapInfo(INT fh, BITMAPINFO *pbi)
  177. {
  178. DWORD off;
  179. HANDLE hbi = NULL;
  180. INT size;
  181. INT i;
  182. WORD nNumColors;
  183. RGBQUAD FAR *pRgb;
  184. BITMAPINFOHEADER bi;
  185. BITMAPCOREHEADER bc;
  186. LPBITMAPINFOHEADER lpbi;
  187. BITMAPFILEHEADER bf;
  188. if (fh == -1)
  189. return NULL;
  190. off = M_llseek( fh, 0L, SEEK_CUR);
  191. if (sizeof(bf) != M_lread( fh, (LPSTR)&bf, sizeof(bf)) )
  192. return fFalse;
  193. /*
  194. * do we have a RC HEADER?
  195. */
  196. if (!ISDIB(bf.bfType))
  197. {
  198. bf.bfOffBits = 0L;
  199. M_llseek( fh, off, SEEK_SET );
  200. }
  201. if (sizeof(bi) != M_lread( fh, (LPSTR)&bi, sizeof(bi)) )
  202. return fFalse;
  203. nNumColors = DibNumColors(&bi);
  204. /*
  205. * what type of bitmap info is this?
  206. */
  207. switch (size = (INT)bi.biSize)
  208. {
  209. case sizeof(BITMAPINFOHEADER):
  210. break;
  211. case sizeof(BITMAPCOREHEADER):
  212. bc = *(BITMAPCOREHEADER*)&bi;
  213. bi.biSize = sizeof(BITMAPINFOHEADER);
  214. bi.biWidth = (DWORD)bc.bcWidth;
  215. bi.biHeight = (DWORD)bc.bcHeight;
  216. bi.biPlanes = (WORD)bc.bcPlanes;
  217. bi.biBitCount = (WORD)bc.bcBitCount;
  218. bi.biStyle = 0;
  219. bi.biSizeImage = 0;
  220. bi.biXPelsPerMeter = 0;
  221. bi.biYPelsPerMeter = 0;
  222. bi.biClrUsed = nNumColors;
  223. bi.biClrImportant = nNumColors;
  224. M_llseek(fh, (LONG)sizeof(BITMAPCOREHEADER)-sizeof(BITMAPINFOHEADER), SEEK_CUR);
  225. break;
  226. default:
  227. return fFalse; /* not a DIB */
  228. }
  229. /*
  230. * fill in some default values!
  231. */
  232. if (bi.biSizeImage == 0)
  233. {
  234. bi.biSizeImage = WIDTHBYTES((DWORD)bi.biWidth * bi.biBitCount)
  235. * bi.biHeight;
  236. }
  237. if (bi.biXPelsPerMeter == 0)
  238. {
  239. bi.biXPelsPerMeter = 0; // ??????????????
  240. }
  241. if (bi.biYPelsPerMeter == 0)
  242. {
  243. bi.biYPelsPerMeter = 0; // ??????????????
  244. }
  245. if (bi.biClrUsed == 0)
  246. {
  247. bi.biClrUsed = DibNumColors(&bi);
  248. }
  249. lpbi = (VOID FAR *)pbi;
  250. *lpbi = bi;
  251. pRgb = (RGBQUAD FAR *)((LPSTR)lpbi + bi.biSize);
  252. if (nNumColors)
  253. {
  254. if (size == sizeof(BITMAPCOREHEADER))
  255. {
  256. /*
  257. * convert a old color table (3 byte entries) to a new
  258. * color table (4 byte entries)
  259. */
  260. M_lread( fh, (LPSTR)pRgb, nNumColors * sizeof(RGBTRIPLE) );
  261. for (i=nNumColors-1; i>=0; i--)
  262. {
  263. RGBQUAD rgb;
  264. rgb.rgbRed = ((RGBTRIPLE FAR *)pRgb)[i].rgbtRed;
  265. rgb.rgbBlue = ((RGBTRIPLE FAR *)pRgb)[i].rgbtBlue;
  266. rgb.rgbGreen = ((RGBTRIPLE FAR *)pRgb)[i].rgbtGreen;
  267. rgb.rgbReserved = (BYTE)0;
  268. pRgb[i] = rgb; // BUG, this is wrong!!!!
  269. }
  270. }
  271. else
  272. {
  273. M_lread(fh, (LPSTR)pRgb, nNumColors * sizeof(RGBQUAD));
  274. }
  275. }
  276. if (bf.bfOffBits != 0L)
  277. M_llseek( fh, off + bf.bfOffBits, SEEK_SET );
  278. return fTrue;
  279. }
  280. /* How Many colors does this DIB have?
  281. * this will work on both PM and Windows bitmap info structures.
  282. */
  283. WORD DibNumColors(VOID FAR * pv)
  284. {
  285. INT bits;
  286. /*
  287. * with the new format headers, the size of the palette is in biClrUsed
  288. * else is dependent on bits per pixel
  289. */
  290. if (((LPBITMAPINFOHEADER)pv)->biSize != sizeof(BITMAPCOREHEADER))
  291. {
  292. if (((LPBITMAPINFOHEADER)pv)->biClrUsed != 0)
  293. return (WORD)((LPBITMAPINFOHEADER)pv)->biClrUsed;
  294. bits = ((LPBITMAPINFOHEADER)pv)->biBitCount;
  295. }
  296. else
  297. {
  298. bits = ((LPBITMAPCOREHEADER)pv)->bcBitCount;
  299. }
  300. switch (bits)
  301. {
  302. case 1:
  303. return 2;
  304. case 4:
  305. return 16;
  306. case 8:
  307. Assert(fFalse); // NYI
  308. return 256;
  309. default:
  310. return 0;
  311. }
  312. }
  313. #ifdef LATER
  314. HDC HdcCreateImage(HDC hdcApp, INT idbMask, INT idbImage, LONG rgb, DX *pdx, DY *pdy)
  315. {
  316. HDC hdcMem, hdcMem1;
  317. HBITMAP hbmT, hbmTT, hbmMask;
  318. HBRUSH hbr;
  319. BITMAP bm;
  320. hdcMem = CreateCompatibleDC(hdcApp);
  321. hbmMask = LoadBitmap(hinstApp, MAKEINTRESOURCE(idbMask));
  322. GetObject(hbmMask, sizeof(BITMAP), (LPSTR) &bm);
  323. /* enlarge the size of hdc */
  324. hbmT = SelectObject(hdcMem, CreateCompatibleBitmap(hdcApp, bm.bmWidth, bm.bmHeight));
  325. hbr = SelectObject(hdcMem, hbrTable);
  326. PatBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, PATCOPY);
  327. SelectObject(hdcMem, hbr);
  328. hdcMem1 = CreateCompatibleDC(hdcApp);
  329. hbmTT = SelectObject(hdcMem1, hbmMask);
  330. BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem1, 0, 0, SRCAND);
  331. /* load image and delete hbmMask */
  332. DeleteObject(SelectObject(hdcMem1, LoadBitmap(hinstApp, MAKEINTRESOURCE(idbImage))));
  333. /* load brush to color image */
  334. hbr = SelectObject(hdcMem, CreateSolidBrush(rgb));
  335. #define ropDPSao 0x00EA02E9 /* (Source & Pattern) | Dest */
  336. BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem1, 0, 0, ropDPSao);
  337. DeleteObject(SelectObject(hdcMem, hbr));
  338. DeleteObject(SelectObject(hdcMem1, hbmTT));
  339. DeleteDC(hdcMem1);
  340. *pdx = bm.bmWidth;
  341. *pdy = bm.bmHeight;
  342. return hdcMem;
  343. }
  344. Marquee(RC *prc)
  345. {
  346. HDC hdc;
  347. HDC hdcObj;
  348. X x;
  349. Y y;
  350. DX dxObj;
  351. DY dyObj;
  352. DX dx;
  353. DY dy;
  354. INT dobjX, dobjY; /* # of objects per dir */
  355. INT iobj;
  356. INT iSlice, iSlice1;
  357. hdc = GetDC(hwndApp);
  358. hdcObj = HdcCreateImage(hdc, idbBlackBear, idbWhiteBear, RGB(255, 0, 0), &dxObj, &dyObj);
  359. dobjX = (prc->xRight-prc->xLeft)/dxObj;
  360. dobjY = (prc->yBot-prc->yTop)/dyObj;
  361. dx = dxObj*2;
  362. dy = 0;
  363. y = prc->yTop-dyObj;
  364. x = prc->xLeft-dxObj+iSlice%dxObj;
  365. for(iobj = 0; iobj < 2*dobjX+2*dobjY; iobj++)
  366. {
  367. BitBlt(hdc, x, y, dxObj, dyObj, hdcObj, 0, 0, SRCCOPY);
  368. if(dy == 0)
  369. {
  370. if(x > prc->xRight+dxObj)
  371. {
  372. dy = dyObj*2;
  373. dx = 0;
  374. }
  375. else if(x < prc->xLeft-dxObj)
  376. {
  377. dy = -dyObj*2;
  378. dx = 0;
  379. }
  380. }
  381. else if(dx == 0)
  382. {
  383. if(y > prc->yBot+dyObj)
  384. {
  385. dx = -dxObj*2;
  386. dy = 0;
  387. }
  388. }
  389. x+=dx;
  390. y+=dy;
  391. }
  392. for(iSlice = 0; iSlice < 5; iSlice++)
  393. {
  394. for(iSlice1 = 0; iSlice1 < dxObj; iSlice1++)
  395. {
  396. BitBlt(hdc, prc->xLeft-dxObj+iSlice1+1, prc->yTop-dyObj, prc->xRight-prc->xLeft+dxObj, dyObj,
  397. hdc, prc->xLeft-dxObj+iSlice1, prc->yTop-dyObj, SRCCOPY);
  398. BitBlt(hdc, prc->xRight+dxObj, prc->yTop-dyObj+iSlice1+1, dxObj, prc->yBot-prc->yTop+dyObj,
  399. hdc, prc->xRight+dxObj, prc->yTop-dyObj+iSlice1, SRCCOPY);
  400. }
  401. }
  402. DeleteDC(hdcObj);
  403. ReleaseDC(hwndApp, hdc);
  404. return fTrue;
  405. }
  406. Animation()
  407. {
  408. INT iX, iY, ihdc;
  409. DX dx;
  410. DY dy;
  411. HDC hdc;
  412. HDC rghdc[3];
  413. RC rc;
  414. rc.xLeft = 100; rc.xRight = 300;
  415. rc.yTop = 100; rc.yBot = 200;
  416. Marquee(&rc);
  417. return fTrue;
  418. }
  419. #endif /* LATER */