types.pp 12 KB

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