types.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. const
  19. RT_RCDATA = PChar(10);
  20. type
  21. DWORD = LongWord;
  22. PLongint = System.PLongint;
  23. PSmallInt = System.PSmallInt;
  24. PDouble = System.PDouble;
  25. PByte = System.PByte;
  26. TIntegerDynArray = array of Integer;
  27. TCardinalDynArray = array of Cardinal;
  28. TWordDynArray = array of Word;
  29. TSmallIntDynArray = array of SmallInt;
  30. TByteDynArray = array of Byte;
  31. TShortIntDynArray = array of ShortInt;
  32. TInt64DynArray = array of Int64;
  33. TQWordDynArray = array of QWord;
  34. TLongWordDynArray = array of LongWord;
  35. TSingleDynArray = array of Single;
  36. TDoubleDynArray = array of Double;
  37. TBooleanDynArray = array of Boolean;
  38. TStringDynArray = array of AnsiString;
  39. TWideStringDynArray = array of WideString;
  40. TPointerDynArray = array of Pointer;
  41. {$ifdef Windows}
  42. TPoint = Windows.TPoint;
  43. {$else}
  44. TPoint =
  45. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  46. packed
  47. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  48. record
  49. X : Longint;
  50. Y : Longint;
  51. end;
  52. {$endif}
  53. PPoint = ^TPoint;
  54. tagPOINT = TPoint;
  55. {$ifdef Windows}
  56. TRect = Windows.TRect;
  57. {$else}
  58. TRect =
  59. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  60. packed
  61. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  62. record
  63. case Integer of
  64. 0: (Left,Top,Right,Bottom : Longint);
  65. 1: (TopLeft,BottomRight : TPoint);
  66. end;
  67. {$endif Windows}
  68. PRect = ^TRect;
  69. {$ifdef Windows}
  70. TSize = Windows.TSize;
  71. {$else}
  72. TSize =
  73. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  74. packed
  75. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  76. record
  77. cx : Longint;
  78. cy : Longint;
  79. end;
  80. {$endif Windows}
  81. PSize = ^TSize;
  82. tagSIZE = TSize;
  83. SIZE = TSize;
  84. TSmallPoint =
  85. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  86. packed
  87. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  88. record
  89. x : SmallInt;
  90. y : SmallInt;
  91. end;
  92. PSmallPoint = ^TSmallPoint;
  93. type
  94. TOleChar = WideChar;
  95. POleStr = PWideChar;
  96. PPOleStr = ^POleStr;
  97. {$ifndef Windows}
  98. const
  99. STGTY_STORAGE = 1;
  100. STGTY_STREAM = 2;
  101. STGTY_LOCKBYTES = 3;
  102. STGTY_PROPERTY = 4;
  103. STREAM_SEEK_SET = 0;
  104. STREAM_SEEK_CUR = 1;
  105. STREAM_SEEK_END = 2;
  106. LOCK_WRITE = 1;
  107. LOCK_EXCLUSIVE = 2;
  108. LOCK_ONLYONCE = 4;
  109. E_FAIL = HRESULT($80004005);
  110. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  111. STG_E_FILENOTFOUND = HRESULT($80030002);
  112. STG_E_PATHNOTFOUND = HRESULT($80030003);
  113. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  114. STG_E_ACCESSDENIED = HRESULT($80030005);
  115. STG_E_INVALIDHANDLE = HRESULT($80030006);
  116. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  117. STG_E_INVALIDPOINTER = HRESULT($80030009);
  118. STG_E_NOMOREFILES = HRESULT($80030012);
  119. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  120. STG_E_SEEKERROR = HRESULT($80030019);
  121. STG_E_WRITEFAULT = HRESULT($8003001D);
  122. STG_E_READFAULT = HRESULT($8003001E);
  123. STG_E_SHAREVIOLATION = HRESULT($80030020);
  124. STG_E_LOCKVIOLATION = HRESULT($80030021);
  125. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  126. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  127. STG_E_MEDIUMFULL = HRESULT($80030070);
  128. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  129. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  130. STG_E_INVALIDHEADER = HRESULT($800300FB);
  131. STG_E_INVALIDNAME = HRESULT($800300FC);
  132. STG_E_UNKNOWN = HRESULT($800300FD);
  133. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  134. STG_E_INVALIDFLAG = HRESULT($800300FF);
  135. STG_E_INUSE = HRESULT($80030100);
  136. STG_E_NOTCURRENT = HRESULT($80030101);
  137. STG_E_REVERTED = HRESULT($80030102);
  138. STG_E_CANTSAVE = HRESULT($80030103);
  139. STG_E_OLDFORMAT = HRESULT($80030104);
  140. STG_E_OLDDLL = HRESULT($80030105);
  141. STG_E_SHAREREQUIRED = HRESULT($80030106);
  142. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  143. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  144. STG_E_BADBASEADDRESS = HRESULT($80030110);
  145. STG_E_INCOMPLETE = HRESULT($80030201);
  146. STG_E_TERMINATED = HRESULT($80030202);
  147. STG_S_CONVERTED = $00030200;
  148. STG_S_BLOCK = $00030201;
  149. STG_S_RETRYNOW = $00030202;
  150. STG_S_MONITORING = $00030203;
  151. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  152. type
  153. PCLSID = PGUID;
  154. TCLSID = TGUID;
  155. LARGE_INT = Int64;
  156. Largeint = LARGE_INT;
  157. PDWord = ^DWord;
  158. PDisplay = Pointer;
  159. PEvent = Pointer;
  160. TXrmOptionDescRec = record
  161. end;
  162. XrmOptionDescRec = TXrmOptionDescRec;
  163. PXrmOptionDescRec = ^TXrmOptionDescRec;
  164. Widget = Pointer;
  165. WidgetClass = Pointer;
  166. ArgList = Pointer;
  167. Region = Pointer;
  168. _FILETIME =
  169. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  170. packed
  171. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  172. record
  173. dwLowDateTime : DWORD;
  174. dwHighDateTime : DWORD;
  175. end;
  176. TFileTime = _FILETIME;
  177. FILETIME = _FILETIME;
  178. PFileTime = ^TFileTime;
  179. tagSTATSTG =
  180. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  181. packed
  182. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  183. record
  184. pwcsName : POleStr;
  185. dwType : Longint;
  186. cbSize : Largeint;
  187. mtime : TFileTime;
  188. ctime : TFileTime;
  189. atime : TFileTime;
  190. grfMode : Longint;
  191. grfLocksSupported : Longint;
  192. clsid : TCLSID;
  193. grfStateBits : Longint;
  194. reserved : Longint;
  195. end;
  196. TStatStg = tagSTATSTG;
  197. STATSTG = TStatStg;
  198. PStatStg = ^TStatStg;
  199. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  200. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  201. Function LockServer(fLock : LongBool) : HResult;StdCall;
  202. End;
  203. ISequentialStream = interface(IUnknown) ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  204. function Read(pv : Pointer;cb : DWord;pcbRead : PDWord) : HRESULT;stdcall;
  205. function Write(pv : Pointer;cb : DWord;pcbWritten : PDWord) : HRESULT;stdcall;
  206. end;
  207. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  208. function Seek(dlibMove : LargeInt; dwOrigin : Longint;
  209. out libNewPosition : LargeInt) : HResult;stdcall;
  210. function SetSize(libNewSize : LargeInt) : HRESULT;stdcall;
  211. function CopyTo(stm: IStream;cb : LargeInt;out cbRead : LargeInt;
  212. out cbWritten : LargeInt) : HRESULT;stdcall;
  213. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  214. function Revert : HRESULT;stdcall;
  215. function LockRegion(libOffset : LargeInt;cb : LargeInt;
  216. dwLockType : Longint) : HRESULT;stdcall;
  217. function UnlockRegion(libOffset : LargeInt;cb : LargeInt;
  218. dwLockType : Longint) : HRESULT;stdcall;
  219. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  220. function Clone(out stm : IStream) : HRESULT;stdcall;
  221. end;
  222. {$endif Windows}
  223. function EqualRect(const r1,r2 : TRect) : Boolean;
  224. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  225. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  226. function Point(x,y : Integer) : TPoint;
  227. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  228. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  229. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  230. function IsRectEmpty(const Rect : TRect) : Boolean;
  231. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  232. function CenterPoint(const Rect: TRect): TPoint;
  233. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  234. implementation
  235. function EqualRect(const r1,r2 : TRect) : Boolean;
  236. begin
  237. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  238. end;
  239. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  240. begin
  241. Rect.Left:=Left;
  242. Rect.Top:=Top;
  243. Rect.Right:=Right;
  244. Rect.Bottom:=Bottom;
  245. end;
  246. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  247. begin
  248. Bounds.Left:=ALeft;
  249. Bounds.Top:=ATop;
  250. Bounds.Right:=ALeft+AWidth;
  251. Bounds.Bottom:=ATop+AHeight;
  252. end;
  253. function Point(x,y : Integer) : TPoint;
  254. begin
  255. Point.x:=x;
  256. Point.y:=y;
  257. end;
  258. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  259. begin
  260. PtInRect:=(p.y>=Rect.Top) and
  261. (p.y<Rect.Bottom) and
  262. (p.x>=Rect.Left) and
  263. (p.x<Rect.Right);
  264. end;
  265. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  266. begin
  267. Rect:=R1;
  268. with R2 do
  269. begin
  270. if Left>R1.Left then
  271. Rect.Left:=Left;
  272. if Top>R1.Top then
  273. Rect.Top:=Top;
  274. if Right<R1.Right then
  275. Rect.Right:=Right;
  276. if Bottom<R1.Bottom then
  277. Rect.Bottom:=Bottom;
  278. end;
  279. if IsRectEmpty(Rect) then
  280. begin
  281. FillChar(Rect,SizeOf(Rect),0);
  282. IntersectRect:=false;
  283. end
  284. else
  285. IntersectRect:=true;
  286. end;
  287. function UnionRect(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. UnionRect:=false;
  305. end
  306. else
  307. UnionRect:=true;
  308. end;
  309. function IsRectEmpty(const Rect : TRect) : Boolean;
  310. begin
  311. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  312. end;
  313. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  314. begin
  315. if assigned(@Rect) then
  316. begin
  317. with Rect do
  318. begin
  319. inc(Left,dx);
  320. inc(Top,dy);
  321. inc(Right,dx);
  322. inc(Bottom,dy);
  323. end;
  324. OffsetRect:=true;
  325. end
  326. else
  327. OffsetRect:=false;
  328. end;
  329. function CenterPoint(const Rect: TRect): TPoint;
  330. begin
  331. With Rect do
  332. begin
  333. Result.X:=(Left+Right) div 2;
  334. Result.Y:=(Top+Bottom) div 2;
  335. end;
  336. end;
  337. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  338. begin
  339. if Assigned(@Rect) then
  340. begin
  341. with Rect do
  342. begin
  343. dec(Left, dx);
  344. dec(Top, dy);
  345. inc(Right, dx);
  346. inc(Bottom, dy);
  347. end;
  348. Result := True;
  349. end
  350. else
  351. Result := False;
  352. end;
  353. end.