types.pp 10 KB

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