types.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. tagSTATSTG =
  189. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  190. packed
  191. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  192. record
  193. pwcsName : POleStr;
  194. dwType : Longint;
  195. cbSize : Largeint;
  196. mtime : TFileTime;
  197. ctime : TFileTime;
  198. atime : TFileTime;
  199. grfMode : Longint;
  200. grfLocksSupported : Longint;
  201. clsid : TCLSID;
  202. grfStateBits : Longint;
  203. reserved : Longint;
  204. end;
  205. TStatStg = tagSTATSTG;
  206. STATSTG = TStatStg;
  207. PStatStg = ^TStatStg;
  208. IClassFactory = Interface(IUnknown) ['{00000001-0000-0000-C000-000000000046}']
  209. Function CreateInstance(Const unkOuter : IUnknown;Const riid : TGUID;Out vObject) : HResult;StdCall;
  210. Function LockServer(fLock : LongBool) : HResult;StdCall;
  211. End;
  212. ISequentialStream = interface(IUnknown)
  213. ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
  214. function Read(pv : Pointer;cb : DWORD;pcbRead : PDWORD) : HRESULT;stdcall;
  215. function Write(pv : Pointer;cb : DWORD;pcbWritten : PDWORD): HRESULT;stdcall;
  216. end;
  217. IStream = interface(ISequentialStream) ['{0000000C-0000-0000-C000-000000000046}']
  218. function Seek(dlibMove : LargeInt; dwOrigin : Longint;
  219. out libNewPosition : LargeInt) : HResult;stdcall;
  220. function SetSize(libNewSize : LargeInt) : HRESULT;stdcall;
  221. function CopyTo(stm: IStream;cb : LargeInt;out cbRead : LargeInt;
  222. out cbWritten : LargeInt) : HRESULT;stdcall;
  223. function Commit(grfCommitFlags : Longint) : HRESULT;stdcall;
  224. function Revert : HRESULT;stdcall;
  225. function LockRegion(libOffset : LargeInt;cb : LargeInt;
  226. dwLockType : Longint) : HRESULT;stdcall;
  227. function UnlockRegion(libOffset : LargeInt;cb : LargeInt;
  228. dwLockType : Longint) : HRESULT;stdcall;
  229. Function Stat(out statstg : TStatStg;grfStatFlag : Longint) : HRESULT;stdcall;
  230. function Clone(out stm : IStream) : HRESULT;stdcall;
  231. end;
  232. {$endif Windows}
  233. function EqualRect(const r1,r2 : TRect) : Boolean;
  234. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  235. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  236. function Point(x,y : Integer) : TPoint;
  237. function PtInRect(const Rect : TRect; const p : TPoint) : Boolean;
  238. function IntersectRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  239. function UnionRect(var Rect : TRect; const R1,R2 : TRect) : Boolean;
  240. function IsRectEmpty(const Rect : TRect) : Boolean;
  241. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  242. function CenterPoint(const Rect: TRect): TPoint;
  243. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  244. function Size(AWidth, AHeight: Integer): TSize;
  245. function Size(ARect: TRect): TSize;
  246. implementation
  247. function EqualRect(const r1,r2 : TRect) : Boolean;
  248. begin
  249. EqualRect:=(r1.left=r2.left) and (r1.right=r2.right) and (r1.top=r2.top) and (r1.bottom=r2.bottom);
  250. end;
  251. function Rect(Left,Top,Right,Bottom : Integer) : TRect;
  252. begin
  253. Rect.Left:=Left;
  254. Rect.Top:=Top;
  255. Rect.Right:=Right;
  256. Rect.Bottom:=Bottom;
  257. end;
  258. function Bounds(ALeft,ATop,AWidth,AHeight : Integer) : TRect;
  259. begin
  260. Bounds.Left:=ALeft;
  261. Bounds.Top:=ATop;
  262. Bounds.Right:=ALeft+AWidth;
  263. Bounds.Bottom:=ATop+AHeight;
  264. end;
  265. function Point(x,y : Integer) : TPoint;
  266. begin
  267. Point.x:=x;
  268. Point.y:=y;
  269. end;
  270. function PtInRect(const Rect : TRect;const p : TPoint) : Boolean;
  271. begin
  272. PtInRect:=(p.y>=Rect.Top) and
  273. (p.y<Rect.Bottom) and
  274. (p.x>=Rect.Left) and
  275. (p.x<Rect.Right);
  276. end;
  277. function IntersectRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  278. begin
  279. Rect:=R1;
  280. with R2 do
  281. begin
  282. if Left>R1.Left then
  283. Rect.Left:=Left;
  284. if Top>R1.Top then
  285. Rect.Top:=Top;
  286. if Right<R1.Right then
  287. Rect.Right:=Right;
  288. if Bottom<R1.Bottom then
  289. Rect.Bottom:=Bottom;
  290. end;
  291. if IsRectEmpty(Rect) then
  292. begin
  293. FillChar(Rect,SizeOf(Rect),0);
  294. IntersectRect:=false;
  295. end
  296. else
  297. IntersectRect:=true;
  298. end;
  299. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  300. begin
  301. Rect:=R1;
  302. with R2 do
  303. begin
  304. if Left<R1.Left then
  305. Rect.Left:=Left;
  306. if Top<R1.Top then
  307. Rect.Top:=Top;
  308. if Right>R1.Right then
  309. Rect.Right:=Right;
  310. if Bottom>R1.Bottom then
  311. Rect.Bottom:=Bottom;
  312. end;
  313. if IsRectEmpty(Rect) then
  314. begin
  315. FillChar(Rect,SizeOf(Rect),0);
  316. UnionRect:=false;
  317. end
  318. else
  319. UnionRect:=true;
  320. end;
  321. function IsRectEmpty(const Rect : TRect) : Boolean;
  322. begin
  323. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  324. end;
  325. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  326. begin
  327. if assigned(@Rect) then
  328. begin
  329. with Rect do
  330. begin
  331. inc(Left,dx);
  332. inc(Top,dy);
  333. inc(Right,dx);
  334. inc(Bottom,dy);
  335. end;
  336. OffsetRect:=true;
  337. end
  338. else
  339. OffsetRect:=false;
  340. end;
  341. function CenterPoint(const Rect: TRect): TPoint;
  342. begin
  343. With Rect do
  344. begin
  345. Result.X:=(Left+Right) div 2;
  346. Result.Y:=(Top+Bottom) div 2;
  347. end;
  348. end;
  349. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  350. begin
  351. if Assigned(@Rect) then
  352. begin
  353. with Rect do
  354. begin
  355. dec(Left, dx);
  356. dec(Top, dy);
  357. inc(Right, dx);
  358. inc(Bottom, dy);
  359. end;
  360. Result := True;
  361. end
  362. else
  363. Result := False;
  364. end;
  365. function Size(AWidth, AHeight: Integer): TSize;
  366. begin
  367. Result.cx := AWidth;
  368. Result.cy := AHeight;
  369. end;
  370. function Size(ARect: TRect): TSize;
  371. begin
  372. Result.cx := ARect.Right - ARect.Left;
  373. Result.cy := ARect.Bottom - ARect.Top;
  374. end;
  375. end.