types.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. function CenterPoint(const Rect: TRect): TPoint;
  209. {$endif ver1_0}
  210. implementation
  211. {$ifndef ver1_0}
  212. function EqualRect(const r1,r2 : TRect) : Boolean;
  213. begin
  214. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  215. end;
  216. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  217. begin
  218. Rect.Left:=Left;
  219. Rect.Top:=Top;
  220. Rect.Right:=Right;
  221. Rect.Bottom:=Bottom;
  222. end;
  223. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  224. begin
  225. Bounds.Left:=ALeft;
  226. Bounds.Top:=ATop;
  227. Bounds.Right:=ALeft+AWidth;
  228. Bounds.Bottom:=ATop+AHeight;
  229. end;
  230. function Point(x,y : Integer) : TPoint;
  231. begin
  232. Point.x:=x;
  233. Point.y:=y;
  234. end;
  235. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  236. begin
  237. PtInRect:=(p.y>=Rect.Top) and
  238. (p.y<Rect.Bottom) and
  239. (p.x>=Rect.Left) and
  240. (p.x<Rect.Right);
  241. end;
  242. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  243. begin
  244. Rect:=R1;
  245. with R2 do
  246. begin
  247. if Left>R1.Left then
  248. Rect.Left:=Left;
  249. if Top>R1.Top then
  250. Rect.Top:=Top;
  251. if Right<R1.Right then
  252. Rect.Right:=Right;
  253. if Bottom<R1.Bottom then
  254. Rect.Bottom:=Bottom;
  255. end;
  256. if IsRectEmpty(Rect) then
  257. begin
  258. FillChar(Rect,SizeOf(Rect),0);
  259. IntersectRect:=false;
  260. end
  261. else
  262. IntersectRect:=true;
  263. end;
  264. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  265. begin
  266. Rect:=R1;
  267. with R2 do
  268. begin
  269. if Left<R1.Left then
  270. Rect.Left:=Left;
  271. if Top<R1.Top then
  272. Rect.Top:=Top;
  273. if Right>R1.Right then
  274. Rect.Right:=Right;
  275. if Bottom>R1.Bottom then
  276. Rect.Bottom:=Bottom;
  277. end;
  278. if IsRectEmpty(Rect) then
  279. begin
  280. FillChar(Rect,SizeOf(Rect),0);
  281. UnionRect:=false;
  282. end
  283. else
  284. UnionRect:=true;
  285. end;
  286. function IsRectEmpty(const Rect : TRect) : Boolean;
  287. begin
  288. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  289. end;
  290. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  291. begin
  292. if assigned(@Rect) then
  293. begin
  294. with Rect do
  295. begin
  296. inc(Left,dx);
  297. inc(Top,dy);
  298. inc(Right,dx);
  299. inc(Bottom,dy);
  300. end;
  301. OffsetRect:=true;
  302. end
  303. else
  304. OffsetRect:=false;
  305. end;
  306. function CenterPoint(const Rect: TRect): TPoint;
  307. begin
  308. With Rect do
  309. begin
  310. Result.X:=(Left+Right) div 2;
  311. Result.Y:=(Top+Bottom) div 2;
  312. end;
  313. end;
  314. {$endif ver1_0}
  315. end.
  316. {
  317. $Log$
  318. Revision 1.6 2004-01-10 19:00:20 michael
  319. + Compatibility checks and code reformatting
  320. Revision 1.5 2003/10/05 19:10:03 florian
  321. * fixed some delphi compatibilty issues
  322. Revision 1.4 2003/04/24 11:09:36 florian
  323. * check included, if the compiler supports interfaces
  324. Revision 1.3 2003/01/02 22:22:12 peter
  325. * reuse Windows types to fix incompatible parameters
  326. Revision 1.2 2002/07/27 07:28:10 florian
  327. * fixed errror on non win32 targets with 1.0.x when doing a make cycle
  328. Revision 1.1 2002/07/23 20:39:54 florian
  329. + types unit added
  330. }