types.pp 11 KB

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