types.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2002 by Florian Klaempfl,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$MODE OBJFPC}
  13. unit types;
  14. interface
  15. {$ifdef Win32}
  16. uses
  17. Windows;
  18. {$endif Win32}
  19. {$ifndef ver1_0}
  20. const
  21. RT_RCDATA = PChar(10);
  22. type
  23. DWORD = LongWord;
  24. PLongint = System.PLongint;
  25. PInteger = System.PInteger;
  26. PSmallInt = System.PSmallInt;
  27. PDouble = System.PDouble;
  28. PByte = System.PByte;
  29. TIntegerDynArray = array of Integer;
  30. TCardinalDynArray = array of Cardinal;
  31. TWordDynArray = array of Word;
  32. TSmallIntDynArray = array of SmallInt;
  33. TByteDynArray = array of Byte;
  34. TShortIntDynArray = array of ShortInt;
  35. TInt64DynArray = array of Int64;
  36. TQWordDynArray = array of QWord;
  37. TLongWordDynArray = array of LongWord;
  38. TSingleDynArray = array of Single;
  39. TDoubleDynArray = array of Double;
  40. TBooleanDynArray = array of Boolean;
  41. TStringDynArray = array of AnsiString;
  42. TWideStringDynArray = array of WideString;
  43. {$ifdef Win32}
  44. TPoint = Windows.TPoint;
  45. {$else}
  46. TPoint =
  47. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  48. packed
  49. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  50. record
  51. X : Longint;
  52. Y : Longint;
  53. end;
  54. {$endif}
  55. PPoint = ^TPoint;
  56. tagPOINT = TPoint;
  57. {$ifdef Win32}
  58. TRect = Windows.TRect;
  59. {$else}
  60. TRect =
  61. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  62. packed
  63. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  64. record
  65. case Integer of
  66. 0: (Left,Top,Right,Bottom : Longint);
  67. 1: (TopLeft,BottomRight : TPoint);
  68. end;
  69. {$endif}
  70. PRect = ^TRect;
  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. PSize = ^TSize;
  80. tagSIZE = TSize;
  81. SIZE = TSize;
  82. TSmallPoint =
  83. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  84. packed
  85. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  86. record
  87. x : SmallInt;
  88. y : SmallInt;
  89. end;
  90. PSmallPoint = ^TSmallPoint;
  91. type
  92. TOleChar = WideChar;
  93. POleStr = PWideChar;
  94. PPOleStr = ^POleStr;
  95. {$ifndef win32}
  96. const
  97. STGTY_STORAGE = 1;
  98. STGTY_STREAM = 2;
  99. STGTY_LOCKBYTES = 3;
  100. STGTY_PROPERTY = 4;
  101. STREAM_SEEK_SET = 0;
  102. STREAM_SEEK_CUR = 1;
  103. STREAM_SEEK_END = 2;
  104. LOCK_WRITE = 1;
  105. LOCK_EXCLUSIVE = 2;
  106. LOCK_ONLYONCE = 4;
  107. E_FAIL = HRESULT($80004005);
  108. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  109. STG_E_FILENOTFOUND = HRESULT($80030002);
  110. STG_E_PATHNOTFOUND = HRESULT($80030003);
  111. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  112. STG_E_ACCESSDENIED = HRESULT($80030005);
  113. STG_E_INVALIDHANDLE = HRESULT($80030006);
  114. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  115. STG_E_INVALIDPOINTER = HRESULT($80030009);
  116. STG_E_NOMOREFILES = HRESULT($80030012);
  117. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  118. STG_E_SEEKERROR = HRESULT($80030019);
  119. STG_E_WRITEFAULT = HRESULT($8003001D);
  120. STG_E_READFAULT = HRESULT($8003001E);
  121. STG_E_SHAREVIOLATION = HRESULT($80030020);
  122. STG_E_LOCKVIOLATION = HRESULT($80030021);
  123. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  124. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  125. STG_E_MEDIUMFULL = HRESULT($80030070);
  126. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  127. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  128. STG_E_INVALIDHEADER = HRESULT($800300FB);
  129. STG_E_INVALIDNAME = HRESULT($800300FC);
  130. STG_E_UNKNOWN = HRESULT($800300FD);
  131. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  132. STG_E_INVALIDFLAG = HRESULT($800300FF);
  133. STG_E_INUSE = HRESULT($80030100);
  134. STG_E_NOTCURRENT = HRESULT($80030101);
  135. STG_E_REVERTED = HRESULT($80030102);
  136. STG_E_CANTSAVE = HRESULT($80030103);
  137. STG_E_OLDFORMAT = HRESULT($80030104);
  138. STG_E_OLDDLL = HRESULT($80030105);
  139. STG_E_SHAREREQUIRED = HRESULT($80030106);
  140. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  141. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  142. STG_E_BADBASEADDRESS = HRESULT($80030110);
  143. STG_E_INCOMPLETE = HRESULT($80030201);
  144. STG_E_TERMINATED = HRESULT($80030202);
  145. STG_S_CONVERTED = $00030200;
  146. STG_S_BLOCK = $00030201;
  147. STG_S_RETRYNOW = $00030202;
  148. STG_S_MONITORING = $00030203;
  149. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  150. type
  151. PCLSID = PGUID;
  152. TCLSID = TGUID;
  153. LARGE_INT = Int64;
  154. Largeint = LARGE_INT;
  155. PDWord = ^DWord;
  156. PDisplay = Pointer;
  157. PEvent = Pointer;
  158. TXrmOptionDescRec = record
  159. end;
  160. XrmOptionDescRec = TXrmOptionDescRec;
  161. PXrmOptionDescRec = ^TXrmOptionDescRec;
  162. Widget = Pointer;
  163. WidgetClass = Pointer;
  164. ArgList = Pointer;
  165. Region = Pointer;
  166. _FILETIME =
  167. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  168. packed
  169. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  170. record
  171. dwLowDateTime : DWORD;
  172. dwHighDateTime : DWORD;
  173. end;
  174. TFileTime = _FILETIME;
  175. FILETIME = _FILETIME;
  176. PFileTime = ^TFileTime;
  177. tagSTATSTG =
  178. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  179. packed
  180. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  181. record
  182. pwcsName : POleStr;
  183. dwType : Longint;
  184. cbSize : Largeint;
  185. mtime : TFileTime;
  186. ctime : TFileTime;
  187. atime : TFileTime;
  188. grfMode : Longint;
  189. grfLocksSupported : Longint;
  190. clsid : TCLSID;
  191. grfStateBits : Longint;
  192. reserved : Longint;
  193. end;
  194. TStatStg = tagSTATSTG;
  195. STATSTG = TStatStg;
  196. PStatStg = ^TStatStg;
  197. {$ifdef HASINTF}
  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 HASINTF}
  222. {$endif win32}
  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. {$endif ver1_0}
  234. implementation
  235. {$ifndef ver1_0}
  236. function EqualRect(const r1,r2 : TRect) : Boolean;
  237. begin
  238. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  239. end;
  240. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  241. begin
  242. Rect.Left:=Left;
  243. Rect.Top:=Top;
  244. Rect.Right:=Right;
  245. Rect.Bottom:=Bottom;
  246. end;
  247. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  248. begin
  249. Bounds.Left:=ALeft;
  250. Bounds.Top:=ATop;
  251. Bounds.Right:=ALeft+AWidth;
  252. Bounds.Bottom:=ATop+AHeight;
  253. end;
  254. function Point(x,y : Integer) : TPoint;
  255. begin
  256. Point.x:=x;
  257. Point.y:=y;
  258. end;
  259. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  260. begin
  261. PtInRect:=(p.y>=Rect.Top) and
  262. (p.y<Rect.Bottom) and
  263. (p.x>=Rect.Left) and
  264. (p.x<Rect.Right);
  265. end;
  266. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  267. begin
  268. Rect:=R1;
  269. with R2 do
  270. begin
  271. if Left>R1.Left then
  272. Rect.Left:=Left;
  273. if Top>R1.Top then
  274. Rect.Top:=Top;
  275. if Right<R1.Right then
  276. Rect.Right:=Right;
  277. if Bottom<R1.Bottom then
  278. Rect.Bottom:=Bottom;
  279. end;
  280. if IsRectEmpty(Rect) then
  281. begin
  282. FillChar(Rect,SizeOf(Rect),0);
  283. IntersectRect:=false;
  284. end
  285. else
  286. IntersectRect:=true;
  287. end;
  288. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  289. begin
  290. Rect:=R1;
  291. with R2 do
  292. begin
  293. if Left<R1.Left then
  294. Rect.Left:=Left;
  295. if Top<R1.Top then
  296. Rect.Top:=Top;
  297. if Right>R1.Right then
  298. Rect.Right:=Right;
  299. if Bottom>R1.Bottom then
  300. Rect.Bottom:=Bottom;
  301. end;
  302. if IsRectEmpty(Rect) then
  303. begin
  304. FillChar(Rect,SizeOf(Rect),0);
  305. UnionRect:=false;
  306. end
  307. else
  308. UnionRect:=true;
  309. end;
  310. function IsRectEmpty(const Rect : TRect) : Boolean;
  311. begin
  312. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  313. end;
  314. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  315. begin
  316. if assigned(@Rect) then
  317. begin
  318. with Rect do
  319. begin
  320. inc(Left,dx);
  321. inc(Top,dy);
  322. inc(Right,dx);
  323. inc(Bottom,dy);
  324. end;
  325. OffsetRect:=true;
  326. end
  327. else
  328. OffsetRect:=false;
  329. end;
  330. function CenterPoint(const Rect: TRect): TPoint;
  331. begin
  332. With Rect do
  333. begin
  334. Result.X:=(Left+Right) div 2;
  335. Result.Y:=(Top+Bottom) div 2;
  336. end;
  337. end;
  338. {$endif ver1_0}
  339. end.
  340. {
  341. $Log$
  342. Revision 1.8 2004-10-22 05:51:15 florian
  343. * corrected last commit
  344. Revision 1.6 2004/01/10 19:00:20 michael
  345. + Compatibility checks and code reformatting
  346. Revision 1.5 2003/10/05 19:10:03 florian
  347. * fixed some delphi compatibilty issues
  348. Revision 1.4 2003/04/24 11:09:36 florian
  349. * check included, if the compiler supports interfaces
  350. Revision 1.3 2003/01/02 22:22:12 peter
  351. * reuse Windows types to fix incompatible parameters
  352. Revision 1.2 2002/07/27 07:28:10 florian
  353. * fixed errror on non win32 targets with 1.0.x when doing a make cycle
  354. Revision 1.1 2002/07/23 20:39:54 florian
  355. + types unit added
  356. }