types.pp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2002 by Florian Klaempfl,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$MODE OBJFPC}
  13. unit types;
  14. interface
  15. const
  16. RT_RCDATA = PChar(10);
  17. type
  18. DWORD = LongWord;
  19. PLongint = System.PLongint;
  20. PInteger = System.PInteger;
  21. PSmallInt = System.PSmallInt;
  22. PDouble = System.PDouble;
  23. PByte = System.PByte;
  24. TPoint = packed record
  25. X : Longint;
  26. Y : Longint;
  27. end;
  28. PPoint = ^TPoint;
  29. tagPOINT = TPoint;
  30. TRect = packed record
  31. case Integer of
  32. 0: (Left,Top,Right,Bottom : Longint);
  33. 1: (TopLeft,BottomRight : TPoint);
  34. end;
  35. PRect = ^TRect;
  36. TSize = packed record
  37. cx : Longint;
  38. cy : Longint;
  39. end;
  40. PSize = ^TSize;
  41. tagSIZE = TSize;
  42. SIZE = TSize;
  43. TSmallPoint = packed record
  44. x : SmallInt;
  45. y : SmallInt;
  46. end;
  47. PSmallPoint = ^TSmallPoint;
  48. {$ifndef win32}
  49. const
  50. STGTY_STORAGE = 1;
  51. STGTY_STREAM = 2;
  52. STGTY_LOCKBYTES = 3;
  53. STGTY_PROPERTY = 4;
  54. STREAM_SEEK_SET = 0;
  55. STREAM_SEEK_CUR = 1;
  56. STREAM_SEEK_END = 2;
  57. LOCK_WRITE = 1;
  58. LOCK_EXCLUSIVE = 2;
  59. LOCK_ONLYONCE = 4;
  60. E_FAIL = HRESULT($80004005);
  61. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  62. STG_E_FILENOTFOUND = HRESULT($80030002);
  63. STG_E_PATHNOTFOUND = HRESULT($80030003);
  64. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  65. STG_E_ACCESSDENIED = HRESULT($80030005);
  66. STG_E_INVALIDHANDLE = HRESULT($80030006);
  67. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  68. STG_E_INVALIDPOINTER = HRESULT($80030009);
  69. STG_E_NOMOREFILES = HRESULT($80030012);
  70. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  71. STG_E_SEEKERROR = HRESULT($80030019);
  72. STG_E_WRITEFAULT = HRESULT($8003001D);
  73. STG_E_READFAULT = HRESULT($8003001E);
  74. STG_E_SHAREVIOLATION = HRESULT($80030020);
  75. STG_E_LOCKVIOLATION = HRESULT($80030021);
  76. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  77. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  78. STG_E_MEDIUMFULL = HRESULT($80030070);
  79. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  80. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  81. STG_E_INVALIDHEADER = HRESULT($800300FB);
  82. STG_E_INVALIDNAME = HRESULT($800300FC);
  83. STG_E_UNKNOWN = HRESULT($800300FD);
  84. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  85. STG_E_INVALIDFLAG = HRESULT($800300FF);
  86. STG_E_INUSE = HRESULT($80030100);
  87. STG_E_NOTCURRENT = HRESULT($80030101);
  88. STG_E_REVERTED = HRESULT($80030102);
  89. STG_E_CANTSAVE = HRESULT($80030103);
  90. STG_E_OLDFORMAT = HRESULT($80030104);
  91. STG_E_OLDDLL = HRESULT($80030105);
  92. STG_E_SHAREREQUIRED = HRESULT($80030106);
  93. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  94. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  95. STG_E_BADBASEADDRESS = HRESULT($80030110);
  96. STG_E_INCOMPLETE = HRESULT($80030201);
  97. STG_E_TERMINATED = HRESULT($80030202);
  98. STG_S_CONVERTED = $00030200;
  99. STG_S_BLOCK = $00030201;
  100. STG_S_RETRYNOW = $00030202;
  101. STG_S_MONITORING = $00030203;
  102. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  103. type
  104. TOleChar = WideChar;
  105. POleStr = PWideChar;
  106. PPOleStr = ^POleStr;
  107. PCLSID = PGUID;
  108. TCLSID = TGUID;
  109. LARGE_INT = Int64;
  110. Largeint = LARGE_INT;
  111. PDWord = ^DWord;
  112. PDisplay = Pointer;
  113. PEvent = Pointer;
  114. TXrmOptionDescRec = record
  115. end;
  116. XrmOptionDescRec = TXrmOptionDescRec;
  117. PXrmOptionDescRec = ^TXrmOptionDescRec;
  118. Widget = Pointer;
  119. WidgetClass = Pointer;
  120. ArgList = Pointer;
  121. Region = Pointer;
  122. _FILETIME = packed record
  123. dwLowDateTime : DWORD;
  124. dwHighDateTime : DWORD;
  125. end;
  126. TFileTime = _FILETIME;
  127. FILETIME = _FILETIME;
  128. PFileTime = ^TFileTime;
  129. tagSTATSTG = packed record
  130. pwcsName : POleStr;
  131. dwType : Longint;
  132. cbSize : Largeint;
  133. mtime : TFileTime;
  134. ctime : TFileTime;
  135. atime : TFileTime;
  136. grfMode : Longint;
  137. grfLocksSupported : Longint;
  138. clsid : TCLSID;
  139. grfStateBits : Longint;
  140. reserved : Longint;
  141. end;
  142. TStatStg = tagSTATSTG;
  143. STATSTG = TStatStg;
  144. PStatStg = ^TStatStg;
  145. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  146. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  147. Function LockServer(fLock : LongBool) : HResult;StdCall;
  148. End;
  149. ISequentialStream = interface(IUnknown) ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  150. function Read(pv : Pointer;cb : DWord;pcbRead : PDWord) : HRESULT;stdcall;
  151. function Write(pv : Pointer;cb : DWord;pcbWritten : PDWord) : HRESULT;stdcall;
  152. end;
  153. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  154. function Seek(dlibMove : LargeInt; dwOrigin : Longint;
  155. out libNewPosition : LargeInt) : HResult;stdcall;
  156. function SetSize(libNewSize : LargeInt) : HRESULT;stdcall;
  157. function CopyTo(stm: IStream;cb : LargeInt;out cbRead : LargeInt;
  158. out cbWritten : LargeInt) : HRESULT;stdcall;
  159. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  160. function Revert : HRESULT;stdcall;
  161. function LockRegion(libOffset : LargeInt;cb : LargeInt;
  162. dwLockType : Longint) : HRESULT;stdcall;
  163. function UnlockRegion(libOffset : LargeInt;cb : LargeInt;
  164. dwLockType : Longint) : HRESULT;stdcall;
  165. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  166. function Clone(out stm : IStream) : HRESULT;stdcall;
  167. end;
  168. {$endif win32}
  169. function EqualRect(const r1,r2 : TRect) : Boolean;
  170. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  171. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  172. function Point(x,y : Integer) : TPoint;
  173. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  174. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  175. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  176. function IsRectEmpty(const Rect : TRect) : Boolean;
  177. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  178. implementation
  179. function EqualRect(const r1,r2 : TRect) : Boolean;
  180. begin
  181. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  182. end;
  183. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  184. begin
  185. Rect.Left:=Left;
  186. Rect.Top:=Top;
  187. Rect.Right:=Right;
  188. Rect.Bottom:=Bottom;
  189. end;
  190. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  191. begin
  192. Bounds.Left:=ALeft;
  193. Bounds.Top:=ATop;
  194. Bounds.Right:=ALeft+AWidth;
  195. Bounds.Bottom:=ATop+AHeight;
  196. end;
  197. function Point(x,y : Integer) : TPoint;
  198. begin
  199. Point.x:=x;
  200. Point.y:=y;
  201. end;
  202. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  203. begin
  204. PtInRect:=(p.y>=Rect.Top) and (p.y<Rect.Bottom) and (p.x>=Rect.Left) and (p.x<Rect.Right);
  205. end;
  206. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  207. begin
  208. Rect:=R1;
  209. with R2 do
  210. begin
  211. if Left>R1.Left then
  212. Rect.Left:=Left;
  213. if Top>R1.Top then
  214. Rect.Top:=Top;
  215. if Right<R1.Right then
  216. Rect.Right:=Right;
  217. if Bottom<R1.Bottom then
  218. Rect.Bottom:=Bottom;
  219. end;
  220. if IsRectEmpty(Rect) then
  221. begin
  222. FillChar(Rect,SizeOf(Rect),0);
  223. IntersectRect:=false;
  224. end
  225. else
  226. IntersectRect:=true;
  227. end;
  228. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  229. begin
  230. Rect:=R1;
  231. with R2 do
  232. begin
  233. if Left<R1.Left then
  234. Rect.Left:=Left;
  235. if Top<R1.Top then
  236. Rect.Top:=Top;
  237. if Right>R1.Right then
  238. Rect.Right:=Right;
  239. if Bottom>R1.Bottom then
  240. Rect.Bottom:=Bottom;
  241. end;
  242. if IsRectEmpty(Rect) then
  243. begin
  244. FillChar(Rect,SizeOf(Rect),0);
  245. UnionRect:=false;
  246. end
  247. else
  248. UnionRect:=true;
  249. end;
  250. function IsRectEmpty(const Rect : TRect) : Boolean;
  251. begin
  252. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  253. end;
  254. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  255. begin
  256. if assigned(@Rect) then
  257. begin
  258. with Rect do
  259. begin
  260. inc(Left,dx);
  261. inc(Top,dy);
  262. inc(Right,dx);
  263. inc(Bottom,dy);
  264. end;
  265. OffsetRect:=true;
  266. end
  267. else
  268. OffsetRect:=false;
  269. end;
  270. end.
  271. {
  272. $Log$
  273. Revision 1.1 2002-07-23 20:39:54 florian
  274. + types unit added
  275. }