types.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2002 by Florian Klaempfl,
  4. member of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$MODE OBJFPC}
  12. unit types;
  13. interface
  14. {$ifdef Windows}
  15. uses
  16. Windows;
  17. {$endif Windows}
  18. type
  19. DWORD = LongWord;
  20. PLongint = System.PLongint;
  21. PSmallInt = System.PSmallInt;
  22. {$ifndef FPUNONE}
  23. PDouble = System.PDouble;
  24. {$endif}
  25. PByte = System.PByte;
  26. Largeint = int64;
  27. LARGE_INT = LargeInt;
  28. PLargeInt = ^LargeInt;
  29. LargeUint = qword;
  30. LARGE_UINT= LargeUInt;
  31. PLargeuInt = ^LargeuInt;
  32. TIntegerDynArray = array of Integer;
  33. TCardinalDynArray = array of Cardinal;
  34. TWordDynArray = array of Word;
  35. TSmallIntDynArray = array of SmallInt;
  36. TByteDynArray = array of Byte;
  37. TShortIntDynArray = array of ShortInt;
  38. TInt64DynArray = array of Int64;
  39. TQWordDynArray = array of QWord;
  40. TLongWordDynArray = array of LongWord;
  41. {$ifndef FPUNONE}
  42. TSingleDynArray = array of Single;
  43. TDoubleDynArray = array of Double;
  44. {$endif}
  45. TBooleanDynArray = array of Boolean;
  46. TStringDynArray = array of AnsiString;
  47. TWideStringDynArray = array of WideString;
  48. TPointerDynArray = array of Pointer;
  49. {$ifdef Windows}
  50. TPoint = Windows.TPoint;
  51. {$else}
  52. TPoint =
  53. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  54. packed
  55. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  56. record
  57. X : Longint;
  58. Y : Longint;
  59. end;
  60. {$endif}
  61. PPoint = ^TPoint;
  62. tagPOINT = TPoint;
  63. {$ifdef Windows}
  64. TRect = Windows.TRect;
  65. {$else}
  66. TRect =
  67. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  68. packed
  69. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  70. record
  71. case Integer of
  72. 0: (Left,Top,Right,Bottom : Longint);
  73. 1: (TopLeft,BottomRight : TPoint);
  74. end;
  75. {$endif Windows}
  76. PRect = ^TRect;
  77. {$ifdef Windows}
  78. TSize = Windows.TSize;
  79. {$else}
  80. TSize =
  81. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  82. packed
  83. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  84. record
  85. cx : Longint;
  86. cy : Longint;
  87. end;
  88. {$endif Windows}
  89. PSize = ^TSize;
  90. tagSIZE = TSize;
  91. // SIZE = TSize;
  92. TSmallPoint =
  93. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  94. packed
  95. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  96. record
  97. x : SmallInt;
  98. y : SmallInt;
  99. end;
  100. PSmallPoint = ^TSmallPoint;
  101. TDuplicates = (dupIgnore, dupAccept, dupError);
  102. type
  103. TOleChar = WideChar;
  104. POleStr = PWideChar;
  105. PPOleStr = ^POleStr;
  106. TListCallback = procedure(data,arg:pointer) of object;
  107. TListStaticCallback = procedure(data,arg:pointer);
  108. const
  109. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  110. STGTY_STORAGE = 1;
  111. STGTY_STREAM = 2;
  112. STGTY_LOCKBYTES = 3;
  113. STGTY_PROPERTY = 4;
  114. STREAM_SEEK_SET = 0;
  115. STREAM_SEEK_CUR = 1;
  116. STREAM_SEEK_END = 2;
  117. LOCK_WRITE = 1;
  118. LOCK_EXCLUSIVE = 2;
  119. LOCK_ONLYONCE = 4;
  120. STATFLAG_DEFAULT = 0;
  121. STATFLAG_NONAME = 1;
  122. STATFLAG_NOOPEN = 2;
  123. {$ifndef Wince}
  124. // in Wince these are in unit windows. Under 32/64 in ActiveX.
  125. // for now duplicate them. Not that bad for untyped constants.
  126. E_FAIL = HRESULT($80004005);
  127. E_INVALIDARG = HRESULT($80070057);
  128. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  129. STG_E_FILENOTFOUND = HRESULT($80030002);
  130. STG_E_PATHNOTFOUND = HRESULT($80030003);
  131. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  132. STG_E_ACCESSDENIED = HRESULT($80030005);
  133. STG_E_INVALIDHANDLE = HRESULT($80030006);
  134. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  135. STG_E_INVALIDPOINTER = HRESULT($80030009);
  136. STG_E_NOMOREFILES = HRESULT($80030012);
  137. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  138. STG_E_SEEKERROR = HRESULT($80030019);
  139. STG_E_WRITEFAULT = HRESULT($8003001D);
  140. STG_E_READFAULT = HRESULT($8003001E);
  141. STG_E_SHAREVIOLATION = HRESULT($80030020);
  142. STG_E_LOCKVIOLATION = HRESULT($80030021);
  143. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  144. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  145. STG_E_MEDIUMFULL = HRESULT($80030070);
  146. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  147. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  148. STG_E_INVALIDHEADER = HRESULT($800300FB);
  149. STG_E_INVALIDNAME = HRESULT($800300FC);
  150. STG_E_UNKNOWN = HRESULT($800300FD);
  151. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  152. STG_E_INVALIDFLAG = HRESULT($800300FF);
  153. STG_E_INUSE = HRESULT($80030100);
  154. STG_E_NOTCURRENT = HRESULT($80030101);
  155. STG_E_REVERTED = HRESULT($80030102);
  156. STG_E_CANTSAVE = HRESULT($80030103);
  157. STG_E_OLDFORMAT = HRESULT($80030104);
  158. STG_E_OLDDLL = HRESULT($80030105);
  159. STG_E_SHAREREQUIRED = HRESULT($80030106);
  160. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  161. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  162. STG_E_BADBASEADDRESS = HRESULT($80030110);
  163. STG_E_INCOMPLETE = HRESULT($80030201);
  164. STG_E_TERMINATED = HRESULT($80030202);
  165. STG_S_CONVERTED = $00030200;
  166. STG_S_BLOCK = $00030201;
  167. STG_S_RETRYNOW = $00030202;
  168. STG_S_MONITORING = $00030203;
  169. {$endif}
  170. {$ifndef Windows}
  171. type
  172. PCLSID = PGUID;
  173. TCLSID = TGUID;
  174. PDWord = ^DWord;
  175. PDisplay = Pointer;
  176. PEvent = Pointer;
  177. TXrmOptionDescRec = record
  178. end;
  179. XrmOptionDescRec = TXrmOptionDescRec;
  180. PXrmOptionDescRec = ^TXrmOptionDescRec;
  181. Widget = Pointer;
  182. WidgetClass = Pointer;
  183. ArgList = Pointer;
  184. Region = Pointer;
  185. _FILETIME =
  186. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  187. packed
  188. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  189. record
  190. dwLowDateTime : DWORD;
  191. dwHighDateTime : DWORD;
  192. end;
  193. TFileTime = _FILETIME;
  194. FILETIME = _FILETIME;
  195. PFileTime = ^TFileTime;
  196. {$else}
  197. type
  198. PCLSID = Windows.PCLSID;
  199. TCLSID = Windows.CLSID;
  200. TFiletime = Windows.TFileTime;
  201. Filetime = Windows.FileTime;
  202. PFiletime = Windows.PFileTime;
  203. {$endif Windows}
  204. type
  205. tagSTATSTG = record
  206. pwcsName : POleStr;
  207. dwType : DWord;
  208. cbSize : Large_uint;
  209. mtime : TFileTime;
  210. ctime : TFileTime;
  211. atime : TFileTime;
  212. grfMode : DWord;
  213. grfLocksSupported : DWord;
  214. clsid : TCLSID;
  215. grfStateBits : DWord;
  216. reserved : DWord;
  217. end;
  218. TStatStg = tagSTATSTG;
  219. STATSTG = TStatStg;
  220. PStatStg = ^TStatStg;
  221. { classes depends on these interfaces, we can't use the activex unit in classes though }
  222. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  223. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  224. Function LockServer(fLock : LongBool) : HResult;StdCall;
  225. End;
  226. ISequentialStream = interface(IUnknown)
  227. ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  228. function Read(pv : Pointer;cb : DWORD;pcbRead : PDWORD) : HRESULT;stdcall;
  229. function Write(pv : Pointer;cb : DWORD;pcbWritten : PDWORD): HRESULT;stdcall;
  230. end;
  231. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  232. function Seek(dlibMove : LargeInt; dwOrigin : Longint;
  233. out libNewPosition : LargeInt) : HResult;stdcall;
  234. function SetSize(libNewSize : LargeInt) : HRESULT;stdcall;
  235. function CopyTo(stm: IStream;cb : LargeInt;out cbRead : LargeInt;
  236. out cbWritten : LargeInt) : HRESULT;stdcall;
  237. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  238. function Revert : HRESULT;stdcall;
  239. function LockRegion(libOffset : LargeInt;cb : LargeInt;
  240. dwLockType : Longint) : HRESULT;stdcall;
  241. function UnlockRegion(libOffset : LargeInt;cb : LargeInt;
  242. dwLockType : Longint) : HRESULT;stdcall;
  243. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  244. function Clone(out stm : IStream) : HRESULT;stdcall;
  245. end;
  246. function EqualRect(const r1,r2 : TRect) : Boolean;
  247. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  248. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  249. function Point(x,y : Integer) : TPoint; inline;
  250. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  251. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  252. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  253. function IsRectEmpty(const Rect : TRect) : Boolean;
  254. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  255. function CenterPoint(const Rect: TRect): TPoint;
  256. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  257. function Size(AWidth, AHeight: Integer): TSize;
  258. function Size(const ARect: TRect): TSize;
  259. implementation
  260. function EqualRect(const r1,r2 : TRect) : Boolean;
  261. begin
  262. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  263. end;
  264. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  265. begin
  266. Rect.Left:=Left;
  267. Rect.Top:=Top;
  268. Rect.Right:=Right;
  269. Rect.Bottom:=Bottom;
  270. end;
  271. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  272. begin
  273. Bounds.Left:=ALeft;
  274. Bounds.Top:=ATop;
  275. Bounds.Right:=ALeft+AWidth;
  276. Bounds.Bottom:=ATop+AHeight;
  277. end;
  278. function Point(x,y : Integer) : TPoint; inline;
  279. begin
  280. Point.x:=x;
  281. Point.y:=y;
  282. end;
  283. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  284. begin
  285. PtInRect:=(p.y>=Rect.Top) and
  286. (p.y<Rect.Bottom) and
  287. (p.x>=Rect.Left) and
  288. (p.x<Rect.Right);
  289. end;
  290. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  291. var
  292. lRect: TRect;
  293. begin
  294. lRect := R1;
  295. if R2.Left > R1.Left then
  296. lRect.Left := R2.Left;
  297. if R2.Top > R1.Top then
  298. lRect.Top := R2.Top;
  299. if R2.Right < R1.Right then
  300. lRect.Right := R2.Right;
  301. if R2.Bottom < R1.Bottom then
  302. lRect.Bottom := R2.Bottom;
  303. // The var parameter is only assigned in the end to avoid problems
  304. // when passing the same rectangle in the var and const parameters.
  305. // See http://bugs.freepascal.org/view.php?id=17722
  306. if IsRectEmpty(lRect) then
  307. begin
  308. FillChar(Rect,SizeOf(Rect),0);
  309. IntersectRect:=false;
  310. end
  311. else
  312. begin
  313. IntersectRect:=true;
  314. Rect := lRect;
  315. end;
  316. end;
  317. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  318. var
  319. lRect: TRect;
  320. begin
  321. lRect:=R1;
  322. if R2.Left<R1.Left then
  323. lRect.Left:=R2.Left;
  324. if R2.Top<R1.Top then
  325. lRect.Top:=R2.Top;
  326. if R2.Right>R1.Right then
  327. lRect.Right:=R2.Right;
  328. if R2.Bottom>R1.Bottom then
  329. lRect.Bottom:=R2.Bottom;
  330. if IsRectEmpty(lRect) then
  331. begin
  332. FillChar(Rect,SizeOf(Rect),0);
  333. UnionRect:=false;
  334. end
  335. else
  336. begin
  337. Rect:=lRect;
  338. UnionRect:=true;
  339. end;
  340. end;
  341. function IsRectEmpty(const Rect : TRect) : Boolean;
  342. begin
  343. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  344. end;
  345. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  346. begin
  347. if assigned(@Rect) then
  348. begin
  349. with Rect do
  350. begin
  351. inc(Left,dx);
  352. inc(Top,dy);
  353. inc(Right,dx);
  354. inc(Bottom,dy);
  355. end;
  356. OffsetRect:=true;
  357. end
  358. else
  359. OffsetRect:=false;
  360. end;
  361. function Avg(a, b: Longint): Longint;
  362. begin
  363. if a < b then
  364. Result := a + ((b - a) shr 1)
  365. else
  366. Result := b + ((a - b) shr 1);
  367. end;
  368. function CenterPoint(const Rect: TRect): TPoint;
  369. begin
  370. with Rect do
  371. begin
  372. Result.X := Avg(Left, Right);
  373. Result.Y := Avg(Top, Bottom);
  374. end;
  375. end;
  376. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  377. begin
  378. if Assigned(@Rect) then
  379. begin
  380. with Rect do
  381. begin
  382. dec(Left, dx);
  383. dec(Top, dy);
  384. inc(Right, dx);
  385. inc(Bottom, dy);
  386. end;
  387. Result := True;
  388. end
  389. else
  390. Result := False;
  391. end;
  392. function Size(AWidth, AHeight: Integer): TSize;
  393. begin
  394. Result.cx := AWidth;
  395. Result.cy := AHeight;
  396. end;
  397. function Size(const ARect: TRect): TSize;
  398. begin
  399. Result.cx := ARect.Right - ARect.Left;
  400. Result.cy := ARect.Bottom - ARect.Top;
  401. end;
  402. end.