types.pp 11 KB

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