types.pp 10 KB

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