types.pp 11 KB

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