Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

422 lines
13 KiB

  1. /*++ BUILD Version: 0001
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * GDI16.H
  8. *
  9. * History:
  10. * Created 01-Jul-1991 by John Colleran (johnc)
  11. *
  12. * Warning!!!
  13. * The same code is used to play 16 bit metafiles in WOW (16 bit code)
  14. * and GDI (32 bit code)
  15. *
  16. --*/
  17. #ifdef WOW
  18. #define WIN16
  19. #define UINT WORD
  20. #define HUGE_T huge
  21. #else
  22. #define WIN32
  23. #include "port1632.h"
  24. #include "firewall.h"
  25. #ifdef FIREWALLS
  26. #define DEBUG
  27. #endif
  28. #endif
  29. #define GDIENTRY FAR PASCAL
  30. #define INTERNAL NEAR PASCAL
  31. // If this is 32 bit code append a 16 to all the exported APIs
  32. #ifdef WIN32
  33. HANDLE FAR PASCAL GetMetaFile16(LPSTR);
  34. BOOL FAR PASCAL PlayMetaFile16(HDC, HANDLE);
  35. void FAR PASCAL PlayMetaFileRecord16(HDC, LPHANDLETABLE, LPMETARECORD, WORD);
  36. #define GetMetaFile GetMetaFile16
  37. #define DeleteMetaFile DeleteMetaFile16
  38. #define PlayMetaFile PlayMetaFile16
  39. #define PlayMetaFileRecord PlayMetaFileRecord16
  40. #define IsValidMetaFile IsValidMetaFile16
  41. #define AnimatePalettePriv AnimatePalette
  42. #define DeleteObjectPriv DeleteObject
  43. #define ResizePalettePriv ResizePalette
  44. #define SetPaletteEntriesPriv SetPaletteEntries
  45. #define GetViewportExt(hdc) GetViewportExt32(hdc)
  46. #define GetWindowExt(hdc) GetWindowExt32(hdc)
  47. #define SetViewportExt(h,x,y) SetViewportExt32(h,x,y)
  48. #define SetWindowExt(h,x,y) SetWindowExt32(h,x,y)
  49. LPINT ConvertInts( signed short * pWord, UINT cWords );
  50. DWORD GetViewportExt32(HDC hdc);
  51. DWORD GetWindowExt32(HDC hdc);
  52. DWORD SetViewportExt32(HDC hdc, UINT x, UINT y);
  53. DWORD SetWindowExt32(HDC hdc, UINT x, UINT y);
  54. #define CONVERTPTS(p,c) (LPPOINT)CONVERTINTS((signed short *)p,(c)*2)
  55. #define CONVERTINTS(p,c) ConvertInts((signed short *)p,c)
  56. #define FREECONVERT(p) LocalFree(p)
  57. #define PlayIntoAMetafile(a,b) 0
  58. #define DEFIFWIN16(a) 0
  59. #pragma pack(2)
  60. typedef struct
  61. {
  62. WORD mtType;
  63. WORD mtHeaderSize;
  64. WORD mtVersion;
  65. WORD mtSize;
  66. WORD mtSize2;
  67. WORD mtNoObjects;
  68. DWORD mtMaxRecord;
  69. WORD mtNoParameters;
  70. } METAHEADER16;
  71. #define METAHEADER METAHEADER16
  72. typedef struct tagLOGFONT16
  73. {
  74. int lfHeight;
  75. int lfWidth;
  76. int lfEscapement;
  77. int lfOrientation;
  78. int lfWeight;
  79. BYTE lfItalic;
  80. BYTE lfUnderline;
  81. BYTE lfStrikeOut;
  82. BYTE lfCharSet;
  83. BYTE lfOutPrecision;
  84. BYTE lfClipPrecision;
  85. BYTE lfQuality;
  86. BYTE lfPitchAndFamily;
  87. BYTE lfFaceName[LF_FACESIZE];
  88. } LOGFONT16;
  89. typedef LOGFONT16 FAR *LPLOGFONT16;
  90. #pragma pack()
  91. #define LOGFONT32FROM16( plf32, plf16 ) \
  92. { plf32->lfHeight = plf16->lfHeight; \
  93. plf32->lfWidth = plf16->lfWidth; \
  94. plf32->lfEscapement = plf16->lfEscapement; \
  95. plf32->lfOrientation = plf16->lfOrientation; \
  96. plf32->lfWeight = plf16->lfWeight; \
  97. plf32->lfItalic = plf16->lfItalic; \
  98. plf32->lfUnderline = plf16->lfUnderline; \
  99. plf32->lfStrikeOut = plf16->lfStrikeOut; \
  100. plf32->lfCharSet = plf16->lfCharSet; \
  101. plf32->lfOutPrecision = plf16->lfOutPrecision; \
  102. plf32->lfClipPrecision = plf16->lfClipPrecision; \
  103. plf32->lfQuality = plf16->lfQuality; \
  104. plf32->lfPitchAndFamily = plf16->lfPitchAndFamily; \
  105. memcpy( &plf32->lfItalic, &plf16->lfItalic, LF_FACESIZE); \
  106. }
  107. #define ISDCVALID(hdc) TRUE
  108. #define ISMETADC(hdc) FALSE
  109. #else
  110. #define CONVERTPTS(p,c) (LPPOINT)(p)
  111. #define CONVERTINTS(p,c) (p)
  112. #define FREECONVERT(p)
  113. #define DEFIFWIN16(a) a
  114. #define LOGFONT32FROM16( plf32, plf16 ) {plf32 = plf16;}
  115. #define ISDCVALID(hdc) IsDCValid(hdc)
  116. #define ISMETADC(hdc) IsMetaDC(hdc)
  117. typedef struct _RGNDATAHEADER {
  118. DWORD dwSize;
  119. DWORD iType;
  120. DWORD nCount;
  121. } RGNDATAHEADER, *PRGNDATAHEADER;
  122. typedef struct _RGNDATA {
  123. RGNDATAHEADER rdh;
  124. char Buffer[1];
  125. } RGNDATA,FAR *LPRGNDATA;
  126. typedef struct _RECTL {
  127. LONG xLeft;
  128. LONG yTop;
  129. LONG xRight;
  130. LONG yBottom;
  131. } RECTL,FAR *LPRECTL;
  132. #endif
  133. /*** MetaFile Internal Constants and Macros ***/
  134. #define METAVERSION 0x0300
  135. #define METAVERSION100 0x0100
  136. /* Metafile constants not in Windows.h */
  137. #define META_RESETDC 0x0149
  138. #define META_STARTDOC 0x0150
  139. #define META_STARTPAGE 0x0051
  140. #define META_ENDPAGE 0x0052
  141. #define META_ENDDOC 0x0053
  142. #define META_ABORTDOC 0x0054
  143. #define META_EXTFLOODFILL 0x0548
  144. #define MAXFILECHUNK ((unsigned)63*1024)
  145. #define METAFILEFAILURE 1
  146. #define METAEXITCODE 0 /* arbitrary value */
  147. #define MEMORYMETAFILE 1
  148. #define DISKMETAFILE 2
  149. #define DATASIZE 100
  150. #define HEADERSIZE (sizeof(METAHEADER)/sizeof(WORD))
  151. #define RECHDRSIZE (sizeof(WORD) + sizeof(DWORD))
  152. #define LMHtoP(handle) (*((char * *)(handle)))
  153. #define ID_METADC 0x444D // "MD"
  154. #define METADCBIT 0x1 // Set if DC is a MetaFile DC
  155. #define MAKEMETADC(h) (h|METADCBIT)
  156. #define HANDLEFROMMETADC(h) (((UINT)h) & (~METADCBIT))
  157. #define HMFFROMNPMF(h) (LocalHandle((WORD)h)|METADCBIT)
  158. #define NPFROMMETADC(h) (LMHtoP((h&(~METADCBIT))))
  159. //!!!!!! assert this
  160. #define MAXOBJECTSIZE sizeof(LOGFONT)
  161. /*** MetaFile Internal TypeDefs ***/
  162. typedef BYTE near *NPBYTE;
  163. typedef BYTE HUGE_T *HPBYTE;
  164. typedef WORD HUGE_T *HPWORD;
  165. typedef HANDLE HMETAFILE;
  166. typedef struct _METADATA { /* md */
  167. METAHEADER dataHeader;
  168. WORD metaDataStuff[DATASIZE];
  169. } METADATA;
  170. typedef METADATA *NPMETADATA;
  171. typedef METADATA FAR *LPMETADATA;
  172. typedef struct _METAFILE { /* mf */
  173. METAHEADER MetaFileHeader;
  174. UINT MetaFileNumber;
  175. DWORD MetaFilePosition;
  176. OFSTRUCT MetaFileBuffer;
  177. HANDLE MetaFileRecordHandle;
  178. } METAFILE;
  179. typedef METAFILE *NPMETAFILE;
  180. typedef METAFILE FAR *LPMETAFILE;
  181. typedef METAFILE HUGE_T *HPMETAFILE;
  182. typedef struct _METACACHE {
  183. HANDLE hCache;
  184. HANDLE hMF;
  185. WORD wCacheSize;
  186. WORD wCachePos;
  187. } METACACHE;
  188. typedef struct _ILOBJHEAD {
  189. WORD ident;
  190. WORD nextinchain;
  191. int ilObjType;
  192. long ilObjCount;
  193. HANDLE ilObjMetaList;
  194. } ILOBJHEAD;
  195. typedef struct _METARECORDER {
  196. ILOBJHEAD metaDCHeader;
  197. METAHEADER recordHeader;
  198. DWORD recFilePosition;
  199. OFSTRUCT recFileBuffer;
  200. DWORD sizeBuffer;
  201. WORD recFileNumber;
  202. WORD recFlags;
  203. HANDLE hMetaData;
  204. HANDLE hObjectTable;
  205. HANDLE recCurObjects[6]; // Current Selected Object
  206. } METARECORDER;
  207. typedef METARECORDER *NPMETARECORDER;
  208. typedef METARECORDER FAR *LPMETARECORDER;
  209. typedef METARECORD HUGE_T *HPMETARECORD;
  210. typedef struct _OBJECTTABLE {
  211. DWORD objectIndex;
  212. HANDLE objectCurHandle;
  213. } OBJECTTABLE;
  214. typedef OBJECTTABLE *NPOBJECTTABLE;
  215. typedef OBJECTTABLE FAR *LPOBJECTTABLE;
  216. typedef struct _OBJMETALIST {
  217. WORD omlCount;
  218. HANDLE omlMetaDC[1];
  219. } OBJMETALIST;
  220. typedef struct _WIN2OBJHEAD {
  221. WORD nextinchain;
  222. int w2ObjType;
  223. long w2ObjCount;
  224. } WIN2OBJHEAD;
  225. typedef WIN2OBJHEAD *NPWIN2OBJHEAD;
  226. typedef WIN2OBJHEAD FAR *LPWIN2OBJHEAD;
  227. typedef struct _SCAN {
  228. WORD scnPntCnt; // Scan point count
  229. WORD scnPntTop; // Top of scan
  230. WORD scnPntBottom; // Bottom of scan
  231. WORD scnPntsX[2]; // Start of points in scan
  232. WORD scnPtCntToo; // Point count-- to allow UP travel
  233. } SCAN;
  234. typedef SCAN *NPSCAN;
  235. typedef SCAN FAR *LPSCAN;
  236. typedef struct _WIN3REGION {
  237. WORD nextInChain; // Not used should be zero
  238. WORD ObjType; // Must always be 6 (Windows OBJ_RGN)
  239. DWORD ObjCount; // Not used
  240. WORD cbRegion; // size of following region struct
  241. WORD cScans;
  242. WORD maxScan;
  243. RECT rcBounding;
  244. SCAN aScans[1];
  245. } WIN3REGION;
  246. typedef WIN3REGION *NPWIN3REGION;
  247. typedef WIN3REGION FAR *LPWIN3REGION;
  248. typedef struct _EXTTEXTDATA {
  249. int xPos;
  250. int yPos;
  251. WORD cch;
  252. RECT rcClip;
  253. LPSTR lpString;
  254. LPWORD lpWidths;
  255. }EXTTEXTDATA;
  256. typedef EXTTEXTDATA *NPEXTTEXTDATA;
  257. typedef EXTTEXTDATA FAR *LPEXTTEXTDATA;
  258. // These are from wingdi.h
  259. #define OBJ_PEN 1
  260. #define OBJ_BRUSH 2
  261. #define OBJ_DC 3
  262. #define OBJ_METADC 4
  263. #define OBJ_PALETTE 5
  264. #define OBJ_FONT 6
  265. #define OBJ_BITMAP 7
  266. #define OBJ_RGN 8
  267. #define OBJ_METAFILE 9
  268. #define OBJ_MEMDC 10
  269. #define MIN_OBJ OBJ_PEN
  270. #define MAX_OBJ OBJ_MEMDC
  271. // These Function have no DC; so these function allow you to call them directly
  272. #ifdef WIN16
  273. HANDLE GDIENTRY GetCurrentObject(HDC hdc, WORD wObjType);
  274. DWORD GDIENTRY GetRegionData(HRGN, DWORD, LPRGNDATA);
  275. void GDIENTRY AnimatePalettePriv(HPALETTE, WORD, WORD, LPPALETTEENTRY);
  276. BOOL GDIENTRY DeleteObjectPriv(HANDLE);
  277. BOOL GDIENTRY ResizePalettePriv(HPALETTE, WORD);
  278. WORD GDIENTRY SetPaletteEntriesPriv(HPALETTE,WORD,WORD,LPPALETTEENTRY);
  279. #endif // WIN16
  280. BOOL GDIENTRY GdiFlush(VOID);
  281. DWORD GDIENTRY GetObjectType(HANDLE h);
  282. BOOL GDIENTRY IsValidMetaFile(HANDLE hMetaData);
  283. // Internal Function Declarations
  284. VOID INTERNAL AddToHandleTable(LPHANDLETABLE lpHandleTable, HANDLE hObject, WORD noObjs);
  285. HANDLE INTERNAL AllocBuffer(LPWORD iBufferSize);
  286. DWORD INTERNAL BigRead(UINT fileNumber, LPSTR lpRecord, DWORD dwSizeRec);
  287. VOID INTERNAL CallMetaFunction(HDC, FARPROC, WORD, LPWORD );
  288. BOOL INTERNAL GDIsSelectPalette(HDC hdc, HPALETTE pal, BOOL f);
  289. LPMETARECORD INTERNAL GetEvent(LPMETAFILE pmf,HPMETARECORD pmr,BOOL bFree);
  290. int INTERNAL GetObjectAndType(HANDLE hObj, LPSTR lpObjectBuf);
  291. HANDLE INTERNAL GetPMetaFile(HDC hdc);
  292. BOOL INTERNAL InitializeGdi(VOID);
  293. BOOL INTERNAL IsDIBBlackAndWhite(LPBITMAPINFOHEADER lpDIBInfo);
  294. BOOL INTERNAL IsDCValid(HDC hdc);
  295. BOOL INTERNAL IsMetaDC(HDC hdc);
  296. BOOL INTERNAL IsObjectStock(HANDLE hObj);
  297. BOOL INTERNAL LPtoSP(HDC,LPPOINT,int);
  298. BOOL INTERNAL PlayIntoAMetafile(LPMETARECORD lpMR, HDC hdcDest);
  299. int INTERNAL RecordObject(HANDLE hMF, WORD magic, WORD count, LPWORD lpParm);
  300. BOOL INTERNAL RecordParms(HANDLE hDC, WORD magic, DWORD count, LPWORD lpParm);
  301. BOOL INTERNAL RecordOther(HANDLE hMF, WORD magic, WORD count, LPWORD lpParm);
  302. BOOL INTERNAL Valid( HANDLE hnd, int l, int h);
  303. /****************************************************************************
  304. debugging support
  305. ****************************************************************************/
  306. // Put a wrapper around 16 bit memory Allocation to help track down bugs
  307. #ifdef DEBUG
  308. #ifndef WIN32
  309. PSTR INTERNAL _LocalLock(HANDLE h );
  310. BOOL INTERNAL _LocalUnlock(HANDLE h );
  311. HANDLE INTERNAL _LocalAlloc(WORD w, WORD w2);
  312. LPSTR INTERNAL _GlobalLock(HANDLE h );
  313. BOOL INTERNAL _GlobalUnlock(HANDLE h );
  314. HANDLE INTERNAL _GlobalAlloc(WORD w, DWORD dw );
  315. #define LocalLock(h) _LocalLock(h)
  316. #define GlobalLock(h) _GlobalLock(h)
  317. #define LocalUnlock(h) _LocalUnlock(h)
  318. #define GlobalUnlock(h) _GlobalUnlock(h)
  319. #define LocalAlloc(w, w2 ) _LocalAlloc(w, w2)
  320. #define GlobalAlloc(w, dw ) _GlobalAlloc(w, dw)
  321. #endif
  322. #endif
  323. #ifdef DEBUG
  324. extern void dDbgOut(int iLevel, LPSTR lpszFormat, ...);
  325. extern void dDbgAssert(LPSTR exp, LPSTR file, int line);
  326. #ifdef WIN32
  327. #define dprintf
  328. #define GdiLogFunc(str)
  329. #define GdiLogFunc2(str)
  330. #define GdiLogFunc3(str)
  331. #define ASSERTGDIW(exp,str,w) ASSERTGDI(exp,str)
  332. #else
  333. #define dprintf dDbgOut
  334. #define GdiLogFunc(str) {dDbgOut(3, str );}
  335. #define GdiLogFunc2(str) {dDbgOut(6, str );}
  336. #define GdiLogFunc3(str) {dDbgOut(7, str );}
  337. #define ASSERTGDI(exp,str) \
  338. {((exp) ? (void)0 : dDbgAssert(str, __FILE__, __LINE__));}
  339. #define ASSERTGDIW(exp,str,w) \
  340. { char buf[256]; \
  341. ((exp) ? 0 : \
  342. ( wsprintf(buf, (LPSTR)str, (WORD)w), \
  343. dDbgAssert(buf, __FILE__, __LINE__),0)); \
  344. } \
  345. #endif //WIN32
  346. #else // !DEBUG
  347. #ifdef i386
  348. #define dprintf /##/
  349. #else
  350. #define dprintf
  351. #endif
  352. #define GdiLogFunc(str)
  353. #define GdiLogFunc2(str)
  354. #define GdiLogFunc3(str)
  355. #define ASSERTGDI(exp,str)
  356. #define ASSERTGDIW(exp, str, w)
  357. #endif // else DEBUG