types.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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 Win32}
  15. {$define Win32orCE}
  16. {$endif Win32}
  17. {$ifdef Wince}
  18. {$define Win32orCE}
  19. {$endif Wince}
  20. {$ifdef Win32orCE}
  21. uses
  22. Windows;
  23. {$endif Win32orCE}
  24. const
  25. RT_RCDATA = PChar(10);
  26. type
  27. DWORD = LongWord;
  28. PLongint = System.PLongint;
  29. PInteger = System.PInteger;
  30. PSmallInt = System.PSmallInt;
  31. PDouble = System.PDouble;
  32. PByte = System.PByte;
  33. TIntegerDynArray = array of Integer;
  34. TCardinalDynArray = array of Cardinal;
  35. TWordDynArray = array of Word;
  36. TSmallIntDynArray = array of SmallInt;
  37. TByteDynArray = array of Byte;
  38. TShortIntDynArray = array of ShortInt;
  39. TInt64DynArray = array of Int64;
  40. TQWordDynArray = array of QWord;
  41. TLongWordDynArray = array of LongWord;
  42. TSingleDynArray = array of Single;
  43. TDoubleDynArray = array of Double;
  44. TBooleanDynArray = array of Boolean;
  45. TStringDynArray = array of AnsiString;
  46. TWideStringDynArray = array of WideString;
  47. {$ifdef Win32orCE}
  48. TPoint = Windows.TPoint;
  49. {$else}
  50. TPoint =
  51. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  52. packed
  53. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  54. record
  55. X : Longint;
  56. Y : Longint;
  57. end;
  58. {$endif}
  59. PPoint = ^TPoint;
  60. tagPOINT = TPoint;
  61. {$ifdef Win32orCE}
  62. TRect = Windows.TRect;
  63. {$else}
  64. TRect =
  65. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  66. packed
  67. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  68. record
  69. case Integer of
  70. 0: (Left,Top,Right,Bottom : Longint);
  71. 1: (TopLeft,BottomRight : TPoint);
  72. end;
  73. {$endif Win32orCE}
  74. PRect = ^TRect;
  75. {$ifdef Win32orCE}
  76. TSize = Windows.TSize;
  77. {$else}
  78. TSize =
  79. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  80. packed
  81. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  82. record
  83. cx : Longint;
  84. cy : Longint;
  85. end;
  86. {$endif Win32orCE}
  87. PSize = ^TSize;
  88. tagSIZE = TSize;
  89. SIZE = TSize;
  90. TSmallPoint =
  91. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  92. packed
  93. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  94. record
  95. x : SmallInt;
  96. y : SmallInt;
  97. end;
  98. PSmallPoint = ^TSmallPoint;
  99. type
  100. TOleChar = WideChar;
  101. POleStr = PWideChar;
  102. PPOleStr = ^POleStr;
  103. {$ifndef win32orCE}
  104. const
  105. STGTY_STORAGE = 1;
  106. STGTY_STREAM = 2;
  107. STGTY_LOCKBYTES = 3;
  108. STGTY_PROPERTY = 4;
  109. STREAM_SEEK_SET = 0;
  110. STREAM_SEEK_CUR = 1;
  111. STREAM_SEEK_END = 2;
  112. LOCK_WRITE = 1;
  113. LOCK_EXCLUSIVE = 2;
  114. LOCK_ONLYONCE = 4;
  115. E_FAIL = HRESULT($80004005);
  116. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  117. STG_E_FILENOTFOUND = HRESULT($80030002);
  118. STG_E_PATHNOTFOUND = HRESULT($80030003);
  119. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  120. STG_E_ACCESSDENIED = HRESULT($80030005);
  121. STG_E_INVALIDHANDLE = HRESULT($80030006);
  122. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  123. STG_E_INVALIDPOINTER = HRESULT($80030009);
  124. STG_E_NOMOREFILES = HRESULT($80030012);
  125. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  126. STG_E_SEEKERROR = HRESULT($80030019);
  127. STG_E_WRITEFAULT = HRESULT($8003001D);
  128. STG_E_READFAULT = HRESULT($8003001E);
  129. STG_E_SHAREVIOLATION = HRESULT($80030020);
  130. STG_E_LOCKVIOLATION = HRESULT($80030021);
  131. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  132. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  133. STG_E_MEDIUMFULL = HRESULT($80030070);
  134. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  135. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  136. STG_E_INVALIDHEADER = HRESULT($800300FB);
  137. STG_E_INVALIDNAME = HRESULT($800300FC);
  138. STG_E_UNKNOWN = HRESULT($800300FD);
  139. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  140. STG_E_INVALIDFLAG = HRESULT($800300FF);
  141. STG_E_INUSE = HRESULT($80030100);
  142. STG_E_NOTCURRENT = HRESULT($80030101);
  143. STG_E_REVERTED = HRESULT($80030102);
  144. STG_E_CANTSAVE = HRESULT($80030103);
  145. STG_E_OLDFORMAT = HRESULT($80030104);
  146. STG_E_OLDDLL = HRESULT($80030105);
  147. STG_E_SHAREREQUIRED = HRESULT($80030106);
  148. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  149. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  150. STG_E_BADBASEADDRESS = HRESULT($80030110);
  151. STG_E_INCOMPLETE = HRESULT($80030201);
  152. STG_E_TERMINATED = HRESULT($80030202);
  153. STG_S_CONVERTED = $00030200;
  154. STG_S_BLOCK = $00030201;
  155. STG_S_RETRYNOW = $00030202;
  156. STG_S_MONITORING = $00030203;
  157. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  158. type
  159. PCLSID = PGUID;
  160. TCLSID = TGUID;
  161. LARGE_INT = Int64;
  162. Largeint = LARGE_INT;
  163. PDWord = ^DWord;
  164. PDisplay = Pointer;
  165. PEvent = Pointer;
  166. TXrmOptionDescRec = record
  167. end;
  168. XrmOptionDescRec = TXrmOptionDescRec;
  169. PXrmOptionDescRec = ^TXrmOptionDescRec;
  170. Widget = Pointer;
  171. WidgetClass = Pointer;
  172. ArgList = Pointer;
  173. Region = Pointer;
  174. _FILETIME =
  175. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  176. packed
  177. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  178. record
  179. dwLowDateTime : DWORD;
  180. dwHighDateTime : DWORD;
  181. end;
  182. TFileTime = _FILETIME;
  183. FILETIME = _FILETIME;
  184. PFileTime = ^TFileTime;
  185. tagSTATSTG =
  186. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  187. packed
  188. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  189. record
  190. pwcsName : POleStr;
  191. dwType : Longint;
  192. cbSize : Largeint;
  193. mtime : TFileTime;
  194. ctime : TFileTime;
  195. atime : TFileTime;
  196. grfMode : Longint;
  197. grfLocksSupported : Longint;
  198. clsid : TCLSID;
  199. grfStateBits : Longint;
  200. reserved : Longint;
  201. end;
  202. TStatStg = tagSTATSTG;
  203. STATSTG = TStatStg;
  204. PStatStg = ^TStatStg;
  205. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  206. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  207. Function LockServer(fLock : LongBool) : HResult;StdCall;
  208. End;
  209. ISequentialStream = interface(IUnknown) ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  210. function Read(pv : Pointer;cb : DWord;pcbRead : PDWord) : HRESULT;stdcall;
  211. function Write(pv : Pointer;cb : DWord;pcbWritten : PDWord) : HRESULT;stdcall;
  212. end;
  213. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  214. function Seek(dlibMove : LargeInt; dwOrigin : Longint;
  215. out libNewPosition : LargeInt) : HResult;stdcall;
  216. function SetSize(libNewSize : LargeInt) : HRESULT;stdcall;
  217. function CopyTo(stm: IStream;cb : LargeInt;out cbRead : LargeInt;
  218. out cbWritten : LargeInt) : HRESULT;stdcall;
  219. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  220. function Revert : HRESULT;stdcall;
  221. function LockRegion(libOffset : LargeInt;cb : LargeInt;
  222. dwLockType : Longint) : HRESULT;stdcall;
  223. function UnlockRegion(libOffset : LargeInt;cb : LargeInt;
  224. dwLockType : Longint) : HRESULT;stdcall;
  225. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  226. function Clone(out stm : IStream) : HRESULT;stdcall;
  227. end;
  228. {$endif win32orCE}
  229. function EqualRect(const r1,r2 : TRect) : Boolean;
  230. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  231. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  232. function Point(x,y : Integer) : TPoint;
  233. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  234. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  235. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  236. function IsRectEmpty(const Rect : TRect) : Boolean;
  237. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  238. function CenterPoint(const Rect: TRect): TPoint;
  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. end.