types.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. TDuplicates = (dupIgnore, dupAccept, dupError);
  94. type
  95. TOleChar = WideChar;
  96. POleStr = PWideChar;
  97. PPOleStr = ^POleStr;
  98. const
  99. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  100. {$ifndef Windows}
  101. STGTY_STORAGE = 1;
  102. STGTY_STREAM = 2;
  103. STGTY_LOCKBYTES = 3;
  104. STGTY_PROPERTY = 4;
  105. STREAM_SEEK_SET = 0;
  106. STREAM_SEEK_CUR = 1;
  107. STREAM_SEEK_END = 2;
  108. LOCK_WRITE = 1;
  109. LOCK_EXCLUSIVE = 2;
  110. LOCK_ONLYONCE = 4;
  111. E_FAIL = HRESULT($80004005);
  112. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  113. STG_E_FILENOTFOUND = HRESULT($80030002);
  114. STG_E_PATHNOTFOUND = HRESULT($80030003);
  115. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  116. STG_E_ACCESSDENIED = HRESULT($80030005);
  117. STG_E_INVALIDHANDLE = HRESULT($80030006);
  118. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  119. STG_E_INVALIDPOINTER = HRESULT($80030009);
  120. STG_E_NOMOREFILES = HRESULT($80030012);
  121. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  122. STG_E_SEEKERROR = HRESULT($80030019);
  123. STG_E_WRITEFAULT = HRESULT($8003001D);
  124. STG_E_READFAULT = HRESULT($8003001E);
  125. STG_E_SHAREVIOLATION = HRESULT($80030020);
  126. STG_E_LOCKVIOLATION = HRESULT($80030021);
  127. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  128. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  129. STG_E_MEDIUMFULL = HRESULT($80030070);
  130. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  131. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  132. STG_E_INVALIDHEADER = HRESULT($800300FB);
  133. STG_E_INVALIDNAME = HRESULT($800300FC);
  134. STG_E_UNKNOWN = HRESULT($800300FD);
  135. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  136. STG_E_INVALIDFLAG = HRESULT($800300FF);
  137. STG_E_INUSE = HRESULT($80030100);
  138. STG_E_NOTCURRENT = HRESULT($80030101);
  139. STG_E_REVERTED = HRESULT($80030102);
  140. STG_E_CANTSAVE = HRESULT($80030103);
  141. STG_E_OLDFORMAT = HRESULT($80030104);
  142. STG_E_OLDDLL = HRESULT($80030105);
  143. STG_E_SHAREREQUIRED = HRESULT($80030106);
  144. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  145. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  146. STG_E_BADBASEADDRESS = HRESULT($80030110);
  147. STG_E_INCOMPLETE = HRESULT($80030201);
  148. STG_E_TERMINATED = HRESULT($80030202);
  149. STG_S_CONVERTED = $00030200;
  150. STG_S_BLOCK = $00030201;
  151. STG_S_RETRYNOW = $00030202;
  152. STG_S_MONITORING = $00030203;
  153. type
  154. PCLSID = PGUID;
  155. TCLSID = TGUID;
  156. LARGE_INT = Int64;
  157. Largeint = LARGE_INT;
  158. PDWord = ^DWord;
  159. PDisplay = Pointer;
  160. PEvent = Pointer;
  161. TXrmOptionDescRec = record
  162. end;
  163. XrmOptionDescRec = TXrmOptionDescRec;
  164. PXrmOptionDescRec = ^TXrmOptionDescRec;
  165. Widget = Pointer;
  166. WidgetClass = Pointer;
  167. ArgList = Pointer;
  168. Region = Pointer;
  169. _FILETIME =
  170. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  171. packed
  172. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  173. record
  174. dwLowDateTime : DWORD;
  175. dwHighDateTime : DWORD;
  176. end;
  177. TFileTime = _FILETIME;
  178. FILETIME = _FILETIME;
  179. PFileTime = ^TFileTime;
  180. tagSTATSTG =
  181. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  182. packed
  183. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  184. record
  185. pwcsName : POleStr;
  186. dwType : Longint;
  187. cbSize : Largeint;
  188. mtime : TFileTime;
  189. ctime : TFileTime;
  190. atime : TFileTime;
  191. grfMode : Longint;
  192. grfLocksSupported : Longint;
  193. clsid : TCLSID;
  194. grfStateBits : Longint;
  195. reserved : Longint;
  196. end;
  197. TStatStg = tagSTATSTG;
  198. STATSTG = TStatStg;
  199. PStatStg = ^TStatStg;
  200. TListCallback = procedure(data,arg:pointer) of object;
  201. TListStaticCallback = procedure(data,arg:pointer);
  202. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  203. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  204. Function LockServer(fLock : LongBool) : HResult;StdCall;
  205. End;
  206. ISequentialStream = interface(IUnknown) ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  207. function Read(pv : Pointer;cb : DWord;pcbRead : PDWord) : HRESULT;stdcall;
  208. function Write(pv : Pointer;cb : DWord;pcbWritten : PDWord) : HRESULT;stdcall;
  209. end;
  210. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  211. function Seek(dlibMove : LargeInt; dwOrigin : Longint;
  212. out libNewPosition : LargeInt) : HResult;stdcall;
  213. function SetSize(libNewSize : LargeInt) : HRESULT;stdcall;
  214. function CopyTo(stm: IStream;cb : LargeInt;out cbRead : LargeInt;
  215. out cbWritten : LargeInt) : HRESULT;stdcall;
  216. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  217. function Revert : HRESULT;stdcall;
  218. function LockRegion(libOffset : LargeInt;cb : LargeInt;
  219. dwLockType : Longint) : HRESULT;stdcall;
  220. function UnlockRegion(libOffset : LargeInt;cb : LargeInt;
  221. dwLockType : Longint) : HRESULT;stdcall;
  222. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  223. function Clone(out stm : IStream) : HRESULT;stdcall;
  224. end;
  225. {$endif Windows}
  226. function EqualRect(const r1,r2 : TRect) : Boolean;
  227. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  228. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  229. function Point(x,y : Integer) : TPoint;
  230. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  231. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  232. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  233. function IsRectEmpty(const Rect : TRect) : Boolean;
  234. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  235. function CenterPoint(const Rect: TRect): TPoint;
  236. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  237. function Size(AWidth, AHeight: Integer): TSize;
  238. function Size(ARect: TRect): TSize;
  239. implementation
  240. function EqualRect(const r1,r2 : TRect) : Boolean;
  241. begin
  242. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  243. end;
  244. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  245. begin
  246. Rect.Left:=Left;
  247. Rect.Top:=Top;
  248. Rect.Right:=Right;
  249. Rect.Bottom:=Bottom;
  250. end;
  251. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  252. begin
  253. Bounds.Left:=ALeft;
  254. Bounds.Top:=ATop;
  255. Bounds.Right:=ALeft+AWidth;
  256. Bounds.Bottom:=ATop+AHeight;
  257. end;
  258. function Point(x,y : Integer) : TPoint;
  259. begin
  260. Point.x:=x;
  261. Point.y:=y;
  262. end;
  263. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  264. begin
  265. PtInRect:=(p.y>=Rect.Top) and
  266. (p.y<Rect.Bottom) and
  267. (p.x>=Rect.Left) and
  268. (p.x<Rect.Right);
  269. end;
  270. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  271. begin
  272. Rect:=R1;
  273. with R2 do
  274. begin
  275. if Left>R1.Left then
  276. Rect.Left:=Left;
  277. if Top>R1.Top then
  278. Rect.Top:=Top;
  279. if Right<R1.Right then
  280. Rect.Right:=Right;
  281. if Bottom<R1.Bottom then
  282. Rect.Bottom:=Bottom;
  283. end;
  284. if IsRectEmpty(Rect) then
  285. begin
  286. FillChar(Rect,SizeOf(Rect),0);
  287. IntersectRect:=false;
  288. end
  289. else
  290. IntersectRect:=true;
  291. end;
  292. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  293. begin
  294. Rect:=R1;
  295. with R2 do
  296. begin
  297. if Left<R1.Left then
  298. Rect.Left:=Left;
  299. if Top<R1.Top then
  300. Rect.Top:=Top;
  301. if Right>R1.Right then
  302. Rect.Right:=Right;
  303. if Bottom>R1.Bottom then
  304. Rect.Bottom:=Bottom;
  305. end;
  306. if IsRectEmpty(Rect) then
  307. begin
  308. FillChar(Rect,SizeOf(Rect),0);
  309. UnionRect:=false;
  310. end
  311. else
  312. UnionRect:=true;
  313. end;
  314. function IsRectEmpty(const Rect : TRect) : Boolean;
  315. begin
  316. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  317. end;
  318. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  319. begin
  320. if assigned(@Rect) then
  321. begin
  322. with Rect do
  323. begin
  324. inc(Left,dx);
  325. inc(Top,dy);
  326. inc(Right,dx);
  327. inc(Bottom,dy);
  328. end;
  329. OffsetRect:=true;
  330. end
  331. else
  332. OffsetRect:=false;
  333. end;
  334. function CenterPoint(const Rect: TRect): TPoint;
  335. begin
  336. With Rect do
  337. begin
  338. Result.X:=(Left+Right) div 2;
  339. Result.Y:=(Top+Bottom) div 2;
  340. end;
  341. end;
  342. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  343. begin
  344. if Assigned(@Rect) then
  345. begin
  346. with Rect do
  347. begin
  348. dec(Left, dx);
  349. dec(Top, dy);
  350. inc(Right, dx);
  351. inc(Bottom, dy);
  352. end;
  353. Result := True;
  354. end
  355. else
  356. Result := False;
  357. end;
  358. function Size(AWidth, AHeight: Integer): TSize;
  359. begin
  360. Result.cx := AWidth;
  361. Result.cy := AHeight;
  362. end;
  363. function Size(ARect: TRect): TSize;
  364. begin
  365. Result.cx := ARect.Right - ARect.Left;
  366. Result.cy := ARect.Bottom - ARect.Top;
  367. end;
  368. end.