types.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. {$ifdef wince}
  19. //roozbeh:the reason is currently RT_RCDATA is defines in windows for wince as constant,
  20. // but in win32 it is function so here is required to redeclared.
  21. //RT_RCDATA = PWideChar(10);
  22. {$else}
  23. const
  24. RT_RCDATA = PChar(10);
  25. {$endif}
  26. type
  27. DWORD = LongWord;
  28. PLongint = System.PLongint;
  29. PSmallInt = System.PSmallInt;
  30. PDouble = System.PDouble;
  31. PByte = System.PByte;
  32. Largeint = int64;
  33. LARGE_INT = LargeInt;
  34. PLargeInt = ^LargeInt;
  35. LargeUint = qword;
  36. LARGE_UINT= LargeUInt;
  37. PLargeuInt = ^LargeuInt;
  38. TIntegerDynArray = array of Integer;
  39. TCardinalDynArray = array of Cardinal;
  40. TWordDynArray = array of Word;
  41. TSmallIntDynArray = array of SmallInt;
  42. TByteDynArray = array of Byte;
  43. TShortIntDynArray = array of ShortInt;
  44. TInt64DynArray = array of Int64;
  45. TQWordDynArray = array of QWord;
  46. TLongWordDynArray = array of LongWord;
  47. TSingleDynArray = array of Single;
  48. TDoubleDynArray = array of Double;
  49. TBooleanDynArray = array of Boolean;
  50. TStringDynArray = array of AnsiString;
  51. TWideStringDynArray = array of WideString;
  52. TPointerDynArray = array of Pointer;
  53. {$ifdef Windows}
  54. TPoint = Windows.TPoint;
  55. {$else}
  56. TPoint =
  57. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  58. packed
  59. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  60. record
  61. X : Longint;
  62. Y : Longint;
  63. end;
  64. {$endif}
  65. PPoint = ^TPoint;
  66. tagPOINT = TPoint;
  67. {$ifdef Windows}
  68. TRect = Windows.TRect;
  69. {$else}
  70. TRect =
  71. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  72. packed
  73. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  74. record
  75. case Integer of
  76. 0: (Left,Top,Right,Bottom : Longint);
  77. 1: (TopLeft,BottomRight : TPoint);
  78. end;
  79. {$endif Windows}
  80. PRect = ^TRect;
  81. {$ifdef Windows}
  82. TSize = Windows.TSize;
  83. {$else}
  84. TSize =
  85. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  86. packed
  87. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  88. record
  89. cx : Longint;
  90. cy : Longint;
  91. end;
  92. {$endif Windows}
  93. PSize = ^TSize;
  94. tagSIZE = TSize;
  95. // SIZE = TSize;
  96. TSmallPoint =
  97. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  98. packed
  99. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  100. record
  101. x : SmallInt;
  102. y : SmallInt;
  103. end;
  104. PSmallPoint = ^TSmallPoint;
  105. TDuplicates = (dupIgnore, dupAccept, dupError);
  106. type
  107. TOleChar = WideChar;
  108. POleStr = PWideChar;
  109. PPOleStr = ^POleStr;
  110. TListCallback = procedure(data,arg:pointer) of object;
  111. TListStaticCallback = procedure(data,arg:pointer);
  112. const
  113. GUID_NULL: TGUID = '{00000000-0000-0000-0000-000000000000}';
  114. {$ifndef Windows}
  115. STGTY_STORAGE = 1;
  116. STGTY_STREAM = 2;
  117. STGTY_LOCKBYTES = 3;
  118. STGTY_PROPERTY = 4;
  119. STREAM_SEEK_SET = 0;
  120. STREAM_SEEK_CUR = 1;
  121. STREAM_SEEK_END = 2;
  122. LOCK_WRITE = 1;
  123. LOCK_EXCLUSIVE = 2;
  124. LOCK_ONLYONCE = 4;
  125. E_FAIL = HRESULT($80004005);
  126. STG_E_INVALIDFUNCTION = HRESULT($80030001);
  127. STG_E_FILENOTFOUND = HRESULT($80030002);
  128. STG_E_PATHNOTFOUND = HRESULT($80030003);
  129. STG_E_TOOMANYOPENFILES = HRESULT($80030004);
  130. STG_E_ACCESSDENIED = HRESULT($80030005);
  131. STG_E_INVALIDHANDLE = HRESULT($80030006);
  132. STG_E_INSUFFICIENTMEMORY = HRESULT($80030008);
  133. STG_E_INVALIDPOINTER = HRESULT($80030009);
  134. STG_E_NOMOREFILES = HRESULT($80030012);
  135. STG_E_DISKISWRITEPROTECTED = HRESULT($80030013);
  136. STG_E_SEEKERROR = HRESULT($80030019);
  137. STG_E_WRITEFAULT = HRESULT($8003001D);
  138. STG_E_READFAULT = HRESULT($8003001E);
  139. STG_E_SHAREVIOLATION = HRESULT($80030020);
  140. STG_E_LOCKVIOLATION = HRESULT($80030021);
  141. STG_E_FILEALREADYEXISTS = HRESULT($80030050);
  142. STG_E_INVALIDPARAMETER = HRESULT($80030057);
  143. STG_E_MEDIUMFULL = HRESULT($80030070);
  144. STG_E_PROPSETMISMATCHED = HRESULT($800300F0);
  145. STG_E_ABNORMALAPIEXIT = HRESULT($800300FA);
  146. STG_E_INVALIDHEADER = HRESULT($800300FB);
  147. STG_E_INVALIDNAME = HRESULT($800300FC);
  148. STG_E_UNKNOWN = HRESULT($800300FD);
  149. STG_E_UNIMPLEMENTEDFUNCTION = HRESULT($800300FE);
  150. STG_E_INVALIDFLAG = HRESULT($800300FF);
  151. STG_E_INUSE = HRESULT($80030100);
  152. STG_E_NOTCURRENT = HRESULT($80030101);
  153. STG_E_REVERTED = HRESULT($80030102);
  154. STG_E_CANTSAVE = HRESULT($80030103);
  155. STG_E_OLDFORMAT = HRESULT($80030104);
  156. STG_E_OLDDLL = HRESULT($80030105);
  157. STG_E_SHAREREQUIRED = HRESULT($80030106);
  158. STG_E_EXTANTMARSHALLINGS = HRESULT($80030108);
  159. STG_E_DOCFILECORRUPT = HRESULT($80030109);
  160. STG_E_BADBASEADDRESS = HRESULT($80030110);
  161. STG_E_INCOMPLETE = HRESULT($80030201);
  162. STG_E_TERMINATED = HRESULT($80030202);
  163. STG_S_CONVERTED = $00030200;
  164. STG_S_BLOCK = $00030201;
  165. STG_S_RETRYNOW = $00030202;
  166. STG_S_MONITORING = $00030203;
  167. type
  168. PCLSID = PGUID;
  169. TCLSID = TGUID;
  170. PDWord = ^DWord;
  171. PDisplay = Pointer;
  172. PEvent = Pointer;
  173. TXrmOptionDescRec = record
  174. end;
  175. XrmOptionDescRec = TXrmOptionDescRec;
  176. PXrmOptionDescRec = ^TXrmOptionDescRec;
  177. Widget = Pointer;
  178. WidgetClass = Pointer;
  179. ArgList = Pointer;
  180. Region = Pointer;
  181. _FILETIME =
  182. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  183. packed
  184. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  185. record
  186. dwLowDateTime : DWORD;
  187. dwHighDateTime : DWORD;
  188. end;
  189. TFileTime = _FILETIME;
  190. FILETIME = _FILETIME;
  191. PFileTime = ^TFileTime;
  192. {$endif Windows}
  193. type
  194. tagSTATSTG =
  195. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  196. packed
  197. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  198. record
  199. pwcsName : POleStr;
  200. dwType : Longint;
  201. cbSize : Largeint;
  202. mtime : TFileTime;
  203. ctime : TFileTime;
  204. atime : TFileTime;
  205. grfMode : Longint;
  206. grfLocksSupported : Longint;
  207. clsid : TCLSID;
  208. grfStateBits : Longint;
  209. reserved : Longint;
  210. end;
  211. TStatStg = tagSTATSTG;
  212. STATSTG = TStatStg;
  213. PStatStg = ^TStatStg;
  214. { classes depends on these interfaces, we can't use the activex unit in classes though }
  215. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  216. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  217. Function LockServer(fLock : LongBool) : HResult;StdCall;
  218. End;
  219. ISequentialStream = interface(IUnknown)
  220. ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  221. function Read(pv : Pointer;cb : DWORD;pcbRead : PDWORD) : HRESULT;stdcall;
  222. function Write(pv : Pointer;cb : DWORD;pcbWritten : PDWORD): HRESULT;stdcall;
  223. end;
  224. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  225. function Seek(dlibMove : LargeInt; dwOrigin : Longint;
  226. out libNewPosition : LargeInt) : HResult;stdcall;
  227. function SetSize(libNewSize : LargeInt) : HRESULT;stdcall;
  228. function CopyTo(stm: IStream;cb : LargeInt;out cbRead : LargeInt;
  229. out cbWritten : LargeInt) : HRESULT;stdcall;
  230. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  231. function Revert : HRESULT;stdcall;
  232. function LockRegion(libOffset : LargeInt;cb : LargeInt;
  233. dwLockType : Longint) : HRESULT;stdcall;
  234. function UnlockRegion(libOffset : LargeInt;cb : LargeInt;
  235. dwLockType : Longint) : HRESULT;stdcall;
  236. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  237. function Clone(out stm : IStream) : HRESULT;stdcall;
  238. end;
  239. function EqualRect(const r1,r2 : TRect) : Boolean;
  240. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  241. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  242. function Point(x,y : Integer) : TPoint;
  243. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  244. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  245. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  246. function IsRectEmpty(const Rect : TRect) : Boolean;
  247. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  248. function CenterPoint(const Rect: TRect): TPoint;
  249. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  250. function Size(AWidth, AHeight: Integer): TSize;
  251. function Size(ARect: TRect): TSize;
  252. implementation
  253. function EqualRect(const r1,r2 : TRect) : Boolean;
  254. begin
  255. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  256. end;
  257. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  258. begin
  259. Rect.Left:=Left;
  260. Rect.Top:=Top;
  261. Rect.Right:=Right;
  262. Rect.Bottom:=Bottom;
  263. end;
  264. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  265. begin
  266. Bounds.Left:=ALeft;
  267. Bounds.Top:=ATop;
  268. Bounds.Right:=ALeft+AWidth;
  269. Bounds.Bottom:=ATop+AHeight;
  270. end;
  271. function Point(x,y : Integer) : TPoint;
  272. begin
  273. Point.x:=x;
  274. Point.y:=y;
  275. end;
  276. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  277. begin
  278. PtInRect:=(p.y>=Rect.Top) and
  279. (p.y<Rect.Bottom) and
  280. (p.x>=Rect.Left) and
  281. (p.x<Rect.Right);
  282. end;
  283. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  284. begin
  285. Rect:=R1;
  286. with R2 do
  287. begin
  288. if Left>R1.Left then
  289. Rect.Left:=Left;
  290. if Top>R1.Top then
  291. Rect.Top:=Top;
  292. if Right<R1.Right then
  293. Rect.Right:=Right;
  294. if Bottom<R1.Bottom then
  295. Rect.Bottom:=Bottom;
  296. end;
  297. if IsRectEmpty(Rect) then
  298. begin
  299. FillChar(Rect,SizeOf(Rect),0);
  300. IntersectRect:=false;
  301. end
  302. else
  303. IntersectRect:=true;
  304. end;
  305. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  306. begin
  307. Rect:=R1;
  308. with R2 do
  309. begin
  310. if Left<R1.Left then
  311. Rect.Left:=Left;
  312. if Top<R1.Top then
  313. Rect.Top:=Top;
  314. if Right>R1.Right then
  315. Rect.Right:=Right;
  316. if Bottom>R1.Bottom then
  317. Rect.Bottom:=Bottom;
  318. end;
  319. if IsRectEmpty(Rect) then
  320. begin
  321. FillChar(Rect,SizeOf(Rect),0);
  322. UnionRect:=false;
  323. end
  324. else
  325. UnionRect:=true;
  326. end;
  327. function IsRectEmpty(const Rect : TRect) : Boolean;
  328. begin
  329. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  330. end;
  331. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  332. begin
  333. if assigned(@Rect) then
  334. begin
  335. with Rect do
  336. begin
  337. inc(Left,dx);
  338. inc(Top,dy);
  339. inc(Right,dx);
  340. inc(Bottom,dy);
  341. end;
  342. OffsetRect:=true;
  343. end
  344. else
  345. OffsetRect:=false;
  346. end;
  347. function CenterPoint(const Rect: TRect): TPoint;
  348. begin
  349. With Rect do
  350. begin
  351. Result.X:=(Left+Right) div 2;
  352. Result.Y:=(Top+Bottom) div 2;
  353. end;
  354. end;
  355. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  356. begin
  357. if Assigned(@Rect) then
  358. begin
  359. with Rect do
  360. begin
  361. dec(Left, dx);
  362. dec(Top, dy);
  363. inc(Right, dx);
  364. inc(Bottom, dy);
  365. end;
  366. Result := True;
  367. end
  368. else
  369. Result := False;
  370. end;
  371. function Size(AWidth, AHeight: Integer): TSize;
  372. begin
  373. Result.cx := AWidth;
  374. Result.cy := AHeight;
  375. end;
  376. function Size(ARect: TRect): TSize;
  377. begin
  378. Result.cx := ARect.Right - ARect.Left;
  379. Result.cy := ARect.Bottom - ARect.Top;
  380. end;
  381. end.