types.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. begin
  293. Rect:=R1;
  294. with R2 do
  295. begin
  296. if Left>R1.Left then
  297. Rect.Left:=Left;
  298. if Top>R1.Top then
  299. Rect.Top:=Top;
  300. if Right<R1.Right then
  301. Rect.Right:=Right;
  302. if Bottom<R1.Bottom then
  303. Rect.Bottom:=Bottom;
  304. end;
  305. if IsRectEmpty(Rect) then
  306. begin
  307. FillChar(Rect,SizeOf(Rect),0);
  308. IntersectRect:=false;
  309. end
  310. else
  311. IntersectRect:=true;
  312. end;
  313. function UnionRect(var Rect : TRect;const R1,R2 : TRect) : Boolean;
  314. begin
  315. Rect:=R1;
  316. with R2 do
  317. begin
  318. if Left<R1.Left then
  319. Rect.Left:=Left;
  320. if Top<R1.Top then
  321. Rect.Top:=Top;
  322. if Right>R1.Right then
  323. Rect.Right:=Right;
  324. if Bottom>R1.Bottom then
  325. Rect.Bottom:=Bottom;
  326. end;
  327. if IsRectEmpty(Rect) then
  328. begin
  329. FillChar(Rect,SizeOf(Rect),0);
  330. UnionRect:=false;
  331. end
  332. else
  333. UnionRect:=true;
  334. end;
  335. function IsRectEmpty(const Rect : TRect) : Boolean;
  336. begin
  337. IsRectEmpty:=(Rect.Right<=Rect.Left) or (Rect.Bottom<=Rect.Top);
  338. end;
  339. function OffsetRect(var Rect : TRect;DX : Integer;DY : Integer) : Boolean;
  340. begin
  341. if assigned(@Rect) then
  342. begin
  343. with Rect do
  344. begin
  345. inc(Left,dx);
  346. inc(Top,dy);
  347. inc(Right,dx);
  348. inc(Bottom,dy);
  349. end;
  350. OffsetRect:=true;
  351. end
  352. else
  353. OffsetRect:=false;
  354. end;
  355. function Avg(a, b: Longint): Longint;
  356. begin
  357. if a < b then
  358. Result := a + ((b - a) shr 1)
  359. else
  360. Result := b + ((a - b) shr 1);
  361. end;
  362. function CenterPoint(const Rect: TRect): TPoint;
  363. begin
  364. with Rect do
  365. begin
  366. Result.X := Avg(Left, Right);
  367. Result.Y := Avg(Top, Bottom);
  368. end;
  369. end;
  370. function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean;
  371. begin
  372. if Assigned(@Rect) then
  373. begin
  374. with Rect do
  375. begin
  376. dec(Left, dx);
  377. dec(Top, dy);
  378. inc(Right, dx);
  379. inc(Bottom, dy);
  380. end;
  381. Result := True;
  382. end
  383. else
  384. Result := False;
  385. end;
  386. function Size(AWidth, AHeight: Integer): TSize;
  387. begin
  388. Result.cx := AWidth;
  389. Result.cy := AHeight;
  390. end;
  391. function Size(ARect: TRect): TSize;
  392. begin
  393. Result.cx := ARect.Right - ARect.Left;
  394. Result.cy := ARect.Bottom - ARect.Top;
  395. end;
  396. end.