2
0

types.pp 12 KB

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