types.pp 12 KB

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