types.pp 12 KB

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