2
0

types.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. const
  98. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  99. {$ifndef Windows}
  100. STGTY_STORAGE = 1;
  101. STGTY_STREAM = 2;
  102. STGTY_LOCKBYTES = 3;
  103. STGTY_PROPERTY = 4;
  104. STREAM_SEEK_SET = 0;
  105. STREAM_SEEK_CUR = 1;
  106. STREAM_SEEK_END = 2;
  107. LOCK_WRITE = 1;
  108. LOCK_EXCLUSIVE = 2;
  109. LOCK_ONLYONCE = 4;
  110. E_FAIL = HRESULT($80004005);
  111. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  112. STG_E_FILENOTFOUND = HRESULT($80030002);
  113. STG_E_PATHNOTFOUND = HRESULT($80030003);
  114. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  115. STG_E_ACCESSDENIED = HRESULT($80030005);
  116. STG_E_INVALIDHANDLE = HRESULT($80030006);
  117. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  118. STG_E_INVALIDPOINTER = HRESULT($80030009);
  119. STG_E_NOMOREFILES = HRESULT($80030012);
  120. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  121. STG_E_SEEKERROR = HRESULT($80030019);
  122. STG_E_WRITEFAULT = HRESULT($8003001D);
  123. STG_E_READFAULT = HRESULT($8003001E);
  124. STG_E_SHAREVIOLATION = HRESULT($80030020);
  125. STG_E_LOCKVIOLATION = HRESULT($80030021);
  126. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  127. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  128. STG_E_MEDIUMFULL = HRESULT($80030070);
  129. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  130. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  131. STG_E_INVALIDHEADER = HRESULT($800300FB);
  132. STG_E_INVALIDNAME = HRESULT($800300FC);
  133. STG_E_UNKNOWN = HRESULT($800300FD);
  134. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  135. STG_E_INVALIDFLAG = HRESULT($800300FF);
  136. STG_E_INUSE = HRESULT($80030100);
  137. STG_E_NOTCURRENT = HRESULT($80030101);
  138. STG_E_REVERTED = HRESULT($80030102);
  139. STG_E_CANTSAVE = HRESULT($80030103);
  140. STG_E_OLDFORMAT = HRESULT($80030104);
  141. STG_E_OLDDLL = HRESULT($80030105);
  142. STG_E_SHAREREQUIRED = HRESULT($80030106);
  143. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  144. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  145. STG_E_BADBASEADDRESS = HRESULT($80030110);
  146. STG_E_INCOMPLETE = HRESULT($80030201);
  147. STG_E_TERMINATED = HRESULT($80030202);
  148. STG_S_CONVERTED = $00030200;
  149. STG_S_BLOCK = $00030201;
  150. STG_S_RETRYNOW = $00030202;
  151. STG_S_MONITORING = $00030203;
  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. function Size(AWidth, AHeight: Integer): TSize;
  235. function Size(ARect: TRect): TSize;
  236. implementation
  237. function EqualRect(const r1,r2 : TRect) : Boolean;
  238. begin
  239. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  240. end;
  241. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  242. begin
  243. Rect.Left:=Left;
  244. Rect.Top:=Top;
  245. Rect.Right:=Right;
  246. Rect.Bottom:=Bottom;
  247. end;
  248. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  249. begin
  250. Bounds.Left:=ALeft;
  251. Bounds.Top:=ATop;
  252. Bounds.Right:=ALeft+AWidth;
  253. Bounds.Bottom:=ATop+AHeight;
  254. end;
  255. function Point(x,y : Integer) : TPoint;
  256. begin
  257. Point.x:=x;
  258. Point.y:=y;
  259. end;
  260. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  261. begin
  262. PtInRect:=(p.y>=Rect.Top) and
  263. (p.y<Rect.Bottom) and
  264. (p.x>=Rect.Left) and
  265. (p.x<Rect.Right);
  266. end;
  267. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  268. begin
  269. Rect:=R1;
  270. with R2 do
  271. begin
  272. if Left>R1.Left then
  273. Rect.Left:=Left;
  274. if Top>R1.Top then
  275. Rect.Top:=Top;
  276. if Right<R1.Right then
  277. Rect.Right:=Right;
  278. if Bottom<R1.Bottom then
  279. Rect.Bottom:=Bottom;
  280. end;
  281. if IsRectEmpty(Rect) then
  282. begin
  283. FillChar(Rect,SizeOf(Rect),0);
  284. IntersectRect:=false;
  285. end
  286. else
  287. IntersectRect:=true;
  288. end;
  289. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  290. begin
  291. Rect:=R1;
  292. with R2 do
  293. begin
  294. if Left<R1.Left then
  295. Rect.Left:=Left;
  296. if Top<R1.Top then
  297. Rect.Top:=Top;
  298. if Right>R1.Right then
  299. Rect.Right:=Right;
  300. if Bottom>R1.Bottom then
  301. Rect.Bottom:=Bottom;
  302. end;
  303. if IsRectEmpty(Rect) then
  304. begin
  305. FillChar(Rect,SizeOf(Rect),0);
  306. UnionRect:=false;
  307. end
  308. else
  309. UnionRect:=true;
  310. end;
  311. function IsRectEmpty(const Rect : TRect) : Boolean;
  312. begin
  313. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  314. end;
  315. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  316. begin
  317. if assigned(@Rect) then
  318. begin
  319. with Rect do
  320. begin
  321. inc(Left,dx);
  322. inc(Top,dy);
  323. inc(Right,dx);
  324. inc(Bottom,dy);
  325. end;
  326. OffsetRect:=true;
  327. end
  328. else
  329. OffsetRect:=false;
  330. end;
  331. function CenterPoint(const Rect: TRect): TPoint;
  332. begin
  333. With Rect do
  334. begin
  335. Result.X:=(Left+Right) div 2;
  336. Result.Y:=(Top+Bottom) div 2;
  337. end;
  338. end;
  339. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  340. begin
  341. if Assigned(@Rect) then
  342. begin
  343. with Rect do
  344. begin
  345. dec(Left, dx);
  346. dec(Top, dy);
  347. inc(Right, dx);
  348. inc(Bottom, dy);
  349. end;
  350. Result := True;
  351. end
  352. else
  353. Result := False;
  354. end;
  355. function Size(AWidth, AHeight: Integer): TSize;
  356. begin
  357. Result.cx := AWidth;
  358. Result.cy := AHeight;
  359. end;
  360. function Size(ARect: TRect): TSize;
  361. begin
  362. Result.cx := ARect.Right - ARect.Left;
  363. Result.cy := ARect.Bottom - ARect.Top;
  364. end;
  365. end.