types.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  159. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  160. Function LockServer(fLock : LongBool) : HResult;StdCall;
  161. End;
  162. ISequentialStream = interface(IUnknown) ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  163. function Read(pv : Pointer;cb : DWord;pcbRead : PDWord) : HRESULT;stdcall;
  164. function Write(pv : Pointer;cb : DWord;pcbWritten : PDWord) : HRESULT;stdcall;
  165. end;
  166. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  167. function Seek(dlibMove : LargeInt; dwOrigin : Longint;
  168. out libNewPosition : LargeInt) : HResult;stdcall;
  169. function SetSize(libNewSize : LargeInt) : HRESULT;stdcall;
  170. function CopyTo(stm: IStream;cb : LargeInt;out cbRead : LargeInt;
  171. out cbWritten : LargeInt) : HRESULT;stdcall;
  172. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  173. function Revert : HRESULT;stdcall;
  174. function LockRegion(libOffset : LargeInt;cb : LargeInt;
  175. dwLockType : Longint) : HRESULT;stdcall;
  176. function UnlockRegion(libOffset : LargeInt;cb : LargeInt;
  177. dwLockType : Longint) : HRESULT;stdcall;
  178. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  179. function Clone(out stm : IStream) : HRESULT;stdcall;
  180. end;
  181. {$endif win32}
  182. function EqualRect(const r1,r2 : TRect) : Boolean;
  183. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  184. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  185. function Point(x,y : Integer) : TPoint;
  186. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  187. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  188. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  189. function IsRectEmpty(const Rect : TRect) : Boolean;
  190. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  191. {$endif ver1_0}
  192. implementation
  193. {$ifndef ver1_0}
  194. function EqualRect(const r1,r2 : TRect) : Boolean;
  195. begin
  196. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  197. end;
  198. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  199. begin
  200. Rect.Left:=Left;
  201. Rect.Top:=Top;
  202. Rect.Right:=Right;
  203. Rect.Bottom:=Bottom;
  204. end;
  205. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  206. begin
  207. Bounds.Left:=ALeft;
  208. Bounds.Top:=ATop;
  209. Bounds.Right:=ALeft+AWidth;
  210. Bounds.Bottom:=ATop+AHeight;
  211. end;
  212. function Point(x,y : Integer) : TPoint;
  213. begin
  214. Point.x:=x;
  215. Point.y:=y;
  216. end;
  217. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  218. begin
  219. PtInRect:=(p.y>=Rect.Top) and (p.y<Rect.Bottom) and (p.x>=Rect.Left) and (p.x<Rect.Right);
  220. end;
  221. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  222. begin
  223. Rect:=R1;
  224. with R2 do
  225. begin
  226. if Left>R1.Left then
  227. Rect.Left:=Left;
  228. if Top>R1.Top then
  229. Rect.Top:=Top;
  230. if Right<R1.Right then
  231. Rect.Right:=Right;
  232. if Bottom<R1.Bottom then
  233. Rect.Bottom:=Bottom;
  234. end;
  235. if IsRectEmpty(Rect) then
  236. begin
  237. FillChar(Rect,SizeOf(Rect),0);
  238. IntersectRect:=false;
  239. end
  240. else
  241. IntersectRect:=true;
  242. end;
  243. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  244. begin
  245. Rect:=R1;
  246. with R2 do
  247. begin
  248. if Left<R1.Left then
  249. Rect.Left:=Left;
  250. if Top<R1.Top then
  251. Rect.Top:=Top;
  252. if Right>R1.Right then
  253. Rect.Right:=Right;
  254. if Bottom>R1.Bottom then
  255. Rect.Bottom:=Bottom;
  256. end;
  257. if IsRectEmpty(Rect) then
  258. begin
  259. FillChar(Rect,SizeOf(Rect),0);
  260. UnionRect:=false;
  261. end
  262. else
  263. UnionRect:=true;
  264. end;
  265. function IsRectEmpty(const Rect : TRect) : Boolean;
  266. begin
  267. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  268. end;
  269. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  270. begin
  271. if assigned(@Rect) then
  272. begin
  273. with Rect do
  274. begin
  275. inc(Left,dx);
  276. inc(Top,dy);
  277. inc(Right,dx);
  278. inc(Bottom,dy);
  279. end;
  280. OffsetRect:=true;
  281. end
  282. else
  283. OffsetRect:=false;
  284. end;
  285. {$endif ver1_0}
  286. end.
  287. {
  288. $Log$
  289. Revision 1.3 2003-01-02 22:22:12 peter
  290. * reuse Windows types to fix incompatible parameters
  291. Revision 1.2 2002/07/27 07:28:10 florian
  292. * fixed errror on non win32 targets with 1.0.x when doing a make cycle
  293. Revision 1.1 2002/07/23 20:39:54 florian
  294. + types unit added
  295. }