types.pp 12 KB

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