types.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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. {$ifndef Wince}
  119. // in Wince these are in unit windows. Under 32/64 in ActiveX.
  120. // for now duplicate them. Not that bad for untyped constants.
  121. STGTY_STORAGE = 1;
  122. STGTY_STREAM = 2;
  123. STGTY_LOCKBYTES = 3;
  124. STGTY_PROPERTY = 4;
  125. STREAM_SEEK_SET = 0;
  126. STREAM_SEEK_CUR = 1;
  127. STREAM_SEEK_END = 2;
  128. LOCK_WRITE = 1;
  129. LOCK_EXCLUSIVE = 2;
  130. LOCK_ONLYONCE = 4;
  131. E_FAIL = HRESULT($80004005);
  132. E_INVALIDARG = HRESULT($80070057);
  133. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  134. STG_E_FILENOTFOUND = HRESULT($80030002);
  135. STG_E_PATHNOTFOUND = HRESULT($80030003);
  136. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  137. STG_E_ACCESSDENIED = HRESULT($80030005);
  138. STG_E_INVALIDHANDLE = HRESULT($80030006);
  139. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  140. STG_E_INVALIDPOINTER = HRESULT($80030009);
  141. STG_E_NOMOREFILES = HRESULT($80030012);
  142. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  143. STG_E_SEEKERROR = HRESULT($80030019);
  144. STG_E_WRITEFAULT = HRESULT($8003001D);
  145. STG_E_READFAULT = HRESULT($8003001E);
  146. STG_E_SHAREVIOLATION = HRESULT($80030020);
  147. STG_E_LOCKVIOLATION = HRESULT($80030021);
  148. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  149. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  150. STG_E_MEDIUMFULL = HRESULT($80030070);
  151. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  152. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  153. STG_E_INVALIDHEADER = HRESULT($800300FB);
  154. STG_E_INVALIDNAME = HRESULT($800300FC);
  155. STG_E_UNKNOWN = HRESULT($800300FD);
  156. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  157. STG_E_INVALIDFLAG = HRESULT($800300FF);
  158. STG_E_INUSE = HRESULT($80030100);
  159. STG_E_NOTCURRENT = HRESULT($80030101);
  160. STG_E_REVERTED = HRESULT($80030102);
  161. STG_E_CANTSAVE = HRESULT($80030103);
  162. STG_E_OLDFORMAT = HRESULT($80030104);
  163. STG_E_OLDDLL = HRESULT($80030105);
  164. STG_E_SHAREREQUIRED = HRESULT($80030106);
  165. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  166. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  167. STG_E_BADBASEADDRESS = HRESULT($80030110);
  168. STG_E_INCOMPLETE = HRESULT($80030201);
  169. STG_E_TERMINATED = HRESULT($80030202);
  170. STG_S_CONVERTED = $00030200;
  171. STG_S_BLOCK = $00030201;
  172. STG_S_RETRYNOW = $00030202;
  173. STG_S_MONITORING = $00030203;
  174. STATFLAG_DEFAULT = 0;
  175. STATFLAG_NONAME = 1;
  176. STATFLAG_NOOPEN = 2;
  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. {$endif Windows}
  205. type
  206. tagSTATSTG =
  207. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  208. packed
  209. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  210. record
  211. pwcsName : POleStr;
  212. dwType : DWord;
  213. cbSize : Large_uint;
  214. mtime : TFileTime;
  215. ctime : TFileTime;
  216. atime : TFileTime;
  217. grfMode : DWord;
  218. grfLocksSupported : DWord;
  219. clsid : TCLSID;
  220. grfStateBits : DWord;
  221. reserved : DWord;
  222. end;
  223. TStatStg = tagSTATSTG;
  224. STATSTG = TStatStg;
  225. PStatStg = ^TStatStg;
  226. { classes depends on these interfaces, we can't use the activex unit in classes though }
  227. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  228. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  229. Function LockServer(fLock : LongBool) : HResult;StdCall;
  230. End;
  231. ISequentialStream = interface(IUnknown)
  232. ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  233. function Read(pv : Pointer;cb : DWORD;pcbRead : PDWORD) : HRESULT;stdcall;
  234. function Write(pv : Pointer;cb : DWORD;pcbWritten : PDWORD): HRESULT;stdcall;
  235. end;
  236. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  237. function Seek(dlibMove : LargeInt; dwOrigin : Longint;
  238. out libNewPosition : LargeInt) : HResult;stdcall;
  239. function SetSize(libNewSize : LargeInt) : HRESULT;stdcall;
  240. function CopyTo(stm: IStream;cb : LargeInt;out cbRead : LargeInt;
  241. out cbWritten : LargeInt) : HRESULT;stdcall;
  242. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  243. function Revert : HRESULT;stdcall;
  244. function LockRegion(libOffset : LargeInt;cb : LargeInt;
  245. dwLockType : Longint) : HRESULT;stdcall;
  246. function UnlockRegion(libOffset : LargeInt;cb : LargeInt;
  247. dwLockType : Longint) : HRESULT;stdcall;
  248. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  249. function Clone(out stm : IStream) : HRESULT;stdcall;
  250. end;
  251. function EqualRect(const r1,r2 : TRect) : Boolean;
  252. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  253. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  254. function Point(x,y : Integer) : TPoint;
  255. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  256. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  257. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  258. function IsRectEmpty(const Rect : TRect) : Boolean;
  259. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  260. function CenterPoint(const Rect: TRect): TPoint;
  261. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  262. function Size(AWidth, AHeight: Integer): TSize;
  263. function Size(ARect: TRect): TSize;
  264. implementation
  265. function EqualRect(const r1,r2 : TRect) : Boolean;
  266. begin
  267. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  268. end;
  269. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  270. begin
  271. Rect.Left:=Left;
  272. Rect.Top:=Top;
  273. Rect.Right:=Right;
  274. Rect.Bottom:=Bottom;
  275. end;
  276. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  277. begin
  278. Bounds.Left:=ALeft;
  279. Bounds.Top:=ATop;
  280. Bounds.Right:=ALeft+AWidth;
  281. Bounds.Bottom:=ATop+AHeight;
  282. end;
  283. function Point(x,y : Integer) : TPoint;
  284. begin
  285. Point.x:=x;
  286. Point.y:=y;
  287. end;
  288. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  289. begin
  290. PtInRect:=(p.y>=Rect.Top) and
  291. (p.y<Rect.Bottom) and
  292. (p.x>=Rect.Left) and
  293. (p.x<Rect.Right);
  294. end;
  295. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  296. begin
  297. Rect:=R1;
  298. with R2 do
  299. begin
  300. if Left>R1.Left then
  301. Rect.Left:=Left;
  302. if Top>R1.Top then
  303. Rect.Top:=Top;
  304. if Right<R1.Right then
  305. Rect.Right:=Right;
  306. if Bottom<R1.Bottom then
  307. Rect.Bottom:=Bottom;
  308. end;
  309. if IsRectEmpty(Rect) then
  310. begin
  311. FillChar(Rect,SizeOf(Rect),0);
  312. IntersectRect:=false;
  313. end
  314. else
  315. IntersectRect:=true;
  316. end;
  317. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  318. begin
  319. Rect:=R1;
  320. with R2 do
  321. begin
  322. if Left<R1.Left then
  323. Rect.Left:=Left;
  324. if Top<R1.Top then
  325. Rect.Top:=Top;
  326. if Right>R1.Right then
  327. Rect.Right:=Right;
  328. if Bottom>R1.Bottom then
  329. Rect.Bottom:=Bottom;
  330. end;
  331. if IsRectEmpty(Rect) then
  332. begin
  333. FillChar(Rect,SizeOf(Rect),0);
  334. UnionRect:=false;
  335. end
  336. else
  337. UnionRect:=true;
  338. end;
  339. function IsRectEmpty(const Rect : TRect) : Boolean;
  340. begin
  341. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  342. end;
  343. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  344. begin
  345. if assigned(@Rect) then
  346. begin
  347. with Rect do
  348. begin
  349. inc(Left,dx);
  350. inc(Top,dy);
  351. inc(Right,dx);
  352. inc(Bottom,dy);
  353. end;
  354. OffsetRect:=true;
  355. end
  356. else
  357. OffsetRect:=false;
  358. end;
  359. function Avg(a, b: Longint): Longint;
  360. begin
  361. if a < b then
  362. Result := a + ((b - a) shr 1)
  363. else
  364. Result := b + ((a - b) shr 1);
  365. end;
  366. function CenterPoint(const Rect: TRect): TPoint;
  367. begin
  368. with Rect do
  369. begin
  370. Result.X := Avg(Left, Right);
  371. Result.Y := Avg(Top, Bottom);
  372. end;
  373. end;
  374. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  375. begin
  376. if Assigned(@Rect) then
  377. begin
  378. with Rect do
  379. begin
  380. dec(Left, dx);
  381. dec(Top, dy);
  382. inc(Right, dx);
  383. inc(Bottom, dy);
  384. end;
  385. Result := True;
  386. end
  387. else
  388. Result := False;
  389. end;
  390. function Size(AWidth, AHeight: Integer): TSize;
  391. begin
  392. Result.cx := AWidth;
  393. Result.cy := AHeight;
  394. end;
  395. function Size(ARect: TRect): TSize;
  396. begin
  397. Result.cx := ARect.Right - ARect.Left;
  398. Result.cy := ARect.Bottom - ARect.Top;
  399. end;
  400. end.