types.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. {$ifndef ver1_0}
  19. const
  20. RT_RCDATA = PChar(10);
  21. type
  22. DWORD = LongWord;
  23. PLongint = System.PLongint;
  24. PInteger = System.PInteger;
  25. PSmallInt = System.PSmallInt;
  26. PDouble = System.PDouble;
  27. PByte = System.PByte;
  28. TIntegerDynArray = array of Integer;
  29. TCardinalDynArray = array of Cardinal;
  30. TWordDynArray = array of Word;
  31. TSmallIntDynArray = array of SmallInt;
  32. TByteDynArray = array of Byte;
  33. TShortIntDynArray = array of ShortInt;
  34. TInt64DynArray = array of Int64;
  35. TQWordDynArray = array of QWord;
  36. TLongWordDynArray = array of LongWord;
  37. TSingleDynArray = array of Single;
  38. TDoubleDynArray = array of Double;
  39. TBooleanDynArray = array of Boolean;
  40. TStringDynArray = array of AnsiString;
  41. TWideStringDynArray = array of WideString;
  42. {$ifdef Win32}
  43. TPoint = Windows.TPoint;
  44. {$else}
  45. TPoint =
  46. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  47. packed
  48. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  49. record
  50. X : Longint;
  51. Y : Longint;
  52. end;
  53. {$endif}
  54. PPoint = ^TPoint;
  55. tagPOINT = TPoint;
  56. {$ifdef Win32}
  57. TRect = Windows.TRect;
  58. {$else}
  59. TRect =
  60. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  61. packed
  62. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  63. record
  64. case Integer of
  65. 0: (Left,Top,Right,Bottom : Longint);
  66. 1: (TopLeft,BottomRight : TPoint);
  67. end;
  68. {$endif Win32}
  69. PRect = ^TRect;
  70. {$ifdef Win32}
  71. TSize = Windows.TSize;
  72. {$else}
  73. TSize =
  74. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  75. packed
  76. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  77. record
  78. cx : Longint;
  79. cy : Longint;
  80. end;
  81. {$endif Win32}
  82. PSize = ^TSize;
  83. tagSIZE = TSize;
  84. SIZE = TSize;
  85. TSmallPoint =
  86. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  87. packed
  88. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  89. record
  90. x : SmallInt;
  91. y : SmallInt;
  92. end;
  93. PSmallPoint = ^TSmallPoint;
  94. type
  95. TOleChar = WideChar;
  96. POleStr = PWideChar;
  97. PPOleStr = ^POleStr;
  98. {$ifndef win32}
  99. const
  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. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  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. {$ifdef HASINTF}
  201. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  202. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  203. Function LockServer(fLock : LongBool) : HResult;StdCall;
  204. End;
  205. ISequentialStream = interface(IUnknown) ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  206. function Read(pv : Pointer;cb : DWord;pcbRead : PDWord) : HRESULT;stdcall;
  207. function Write(pv : Pointer;cb : DWord;pcbWritten : PDWord) : HRESULT;stdcall;
  208. end;
  209. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  210. function Seek(dlibMove : LargeInt; dwOrigin : Longint;
  211. out libNewPosition : LargeInt) : HResult;stdcall;
  212. function SetSize(libNewSize : LargeInt) : HRESULT;stdcall;
  213. function CopyTo(stm: IStream;cb : LargeInt;out cbRead : LargeInt;
  214. out cbWritten : LargeInt) : HRESULT;stdcall;
  215. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  216. function Revert : HRESULT;stdcall;
  217. function LockRegion(libOffset : LargeInt;cb : LargeInt;
  218. dwLockType : Longint) : HRESULT;stdcall;
  219. function UnlockRegion(libOffset : LargeInt;cb : LargeInt;
  220. dwLockType : Longint) : HRESULT;stdcall;
  221. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  222. function Clone(out stm : IStream) : HRESULT;stdcall;
  223. end;
  224. {$endif HASINTF}
  225. {$endif win32}
  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. {$endif ver1_0}
  237. implementation
  238. {$ifndef ver1_0}
  239. function EqualRect(const r1,r2 : TRect) : Boolean;
  240. begin
  241. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  242. end;
  243. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  244. begin
  245. Rect.Left:=Left;
  246. Rect.Top:=Top;
  247. Rect.Right:=Right;
  248. Rect.Bottom:=Bottom;
  249. end;
  250. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  251. begin
  252. Bounds.Left:=ALeft;
  253. Bounds.Top:=ATop;
  254. Bounds.Right:=ALeft+AWidth;
  255. Bounds.Bottom:=ATop+AHeight;
  256. end;
  257. function Point(x,y : Integer) : TPoint;
  258. begin
  259. Point.x:=x;
  260. Point.y:=y;
  261. end;
  262. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  263. begin
  264. PtInRect:=(p.y>=Rect.Top) and
  265. (p.y<Rect.Bottom) and
  266. (p.x>=Rect.Left) and
  267. (p.x<Rect.Right);
  268. end;
  269. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  270. begin
  271. Rect:=R1;
  272. with R2 do
  273. begin
  274. if Left>R1.Left then
  275. Rect.Left:=Left;
  276. if Top>R1.Top then
  277. Rect.Top:=Top;
  278. if Right<R1.Right then
  279. Rect.Right:=Right;
  280. if Bottom<R1.Bottom then
  281. Rect.Bottom:=Bottom;
  282. end;
  283. if IsRectEmpty(Rect) then
  284. begin
  285. FillChar(Rect,SizeOf(Rect),0);
  286. IntersectRect:=false;
  287. end
  288. else
  289. IntersectRect:=true;
  290. end;
  291. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  292. begin
  293. Rect:=R1;
  294. with R2 do
  295. begin
  296. if Left<R1.Left then
  297. Rect.Left:=Left;
  298. if Top<R1.Top then
  299. Rect.Top:=Top;
  300. if Right>R1.Right then
  301. Rect.Right:=Right;
  302. if Bottom>R1.Bottom then
  303. Rect.Bottom:=Bottom;
  304. end;
  305. if IsRectEmpty(Rect) then
  306. begin
  307. FillChar(Rect,SizeOf(Rect),0);
  308. UnionRect:=false;
  309. end
  310. else
  311. UnionRect:=true;
  312. end;
  313. function IsRectEmpty(const Rect : TRect) : Boolean;
  314. begin
  315. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  316. end;
  317. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  318. begin
  319. if assigned(@Rect) then
  320. begin
  321. with Rect do
  322. begin
  323. inc(Left,dx);
  324. inc(Top,dy);
  325. inc(Right,dx);
  326. inc(Bottom,dy);
  327. end;
  328. OffsetRect:=true;
  329. end
  330. else
  331. OffsetRect:=false;
  332. end;
  333. function CenterPoint(const Rect: TRect): TPoint;
  334. begin
  335. With Rect do
  336. begin
  337. Result.X:=(Left+Right) div 2;
  338. Result.Y:=(Top+Bottom) div 2;
  339. end;
  340. end;
  341. {$endif ver1_0}
  342. end.