icon.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. {
  2. This file is part of the Free Pascal run time library.
  3. A file in Amiga system run time library.
  4. Copyright (c) 1998-2003 by Nils Sjoholm
  5. member of the Amiga RTL development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. History:
  14. Added overlay functions for Pchar->Strings, functions
  15. and procedures.
  16. 14 Jul 2000.
  17. Removed amigaoverlays, use smartlink instead.
  18. 05 Nov 2002.
  19. Added the defines use_amiga_smartlink and
  20. use_auto_openlib. Implemented autoopening of
  21. the library.
  22. 14 Jan 2003.
  23. Update for AmigaOS 3.9.
  24. A lof of new const and a record.
  25. Functions added.
  26. FUNCTION DupDiskObjectA
  27. FUNCTION IconControlA
  28. PROCEDURE DrawIconStateA
  29. FUNCTION GetIconRectangleA
  30. FUNCTION NewDiskObject
  31. FUNCTION GetIconTagList
  32. FUNCTION PutIconTagList
  33. FUNCTION LayoutIconA
  34. PROCEDURE ChangeToSelectedIconColor
  35. plus overlay for
  36. FUNCTION GetIconTagList;
  37. FUNCTION PutIconTagList
  38. Changed start code for unit.
  39. 02 Feb 2003.
  40. Changed cardinal > longword.
  41. 09 Feb 2003.
  42. [email protected]
  43. }
  44. unit icon;
  45. INTERFACE
  46. uses exec, workbench,utility,amigados,agraphics,intuition,datatypes;
  47. const
  48. ICONA_Dummy = TAG_USER + $9000;
  49. { }
  50. { Error reporting (LONG ) }
  51. ICONA_ErrorCode = ICONA_Dummy + 1;
  52. { Points to the tag item that caused the error (struct TagItem ). }
  53. ICONA_ErrorTagItem = ICONA_Dummy + 75;
  54. { }
  55. { Global options for IconControlA() }
  56. { Screen to use for remapping Workbench icons to (struct Screen ) }
  57. ICONCTRLA_SetGlobalScreen = ICONA_Dummy + 2;
  58. ICONCTRLA_GetGlobalScreen = ICONA_Dummy + 3;
  59. { Icon color remapping precision; defaults to PRECISION_ICON (LONG) }
  60. ICONCTRLA_SetGlobalPrecision = ICONA_Dummy + 4;
  61. ICONCTRLA_GetGlobalPrecision = ICONA_Dummy + 5;
  62. { Icon frame size dimensions (struct Rectangle ) }
  63. ICONCTRLA_SetGlobalEmbossRect = ICONA_Dummy + 6;
  64. ICONCTRLA_GetGlobalEmbossRect = ICONA_Dummy + 7;
  65. { Render image without frame (BOOL) }
  66. ICONCTRLA_SetGlobalFrameless = ICONA_Dummy + 8;
  67. ICONCTRLA_GetGlobalFrameless = ICONA_Dummy + 9;
  68. { Enable NewIcons support (BOOL) }
  69. ICONCTRLA_SetGlobalNewIconsSupport = ICONA_Dummy + 10;
  70. ICONCTRLA_GetGlobalNewIconsSupport = ICONA_Dummy + 11;
  71. { Enable color icon support (BOOL) }
  72. ICONCTRLA_SetGlobalColorIconSupport = ICONA_Dummy + 77;
  73. ICONCTRLA_GetGlobalColorIconSupport = ICONA_Dummy + 78;
  74. { Set/Get the hook to be called when identifying a file (struct Hook ) }
  75. ICONCTRLA_SetGlobalIdentifyHook = ICONA_Dummy + 12;
  76. ICONCTRLA_GetGlobalIdentifyHook = ICONA_Dummy + 13;
  77. { Set/get the maximum length of a file/drawer name supported
  78. by icon.library (LONG).
  79. }
  80. ICONCTRLA_SetGlobalMaxNameLength = ICONA_Dummy + 67;
  81. ICONCTRLA_GetGlobalMaxNameLength = ICONA_Dummy + 68;
  82. {**************************************************************************}
  83. { Per icon local options for IconControlA() }
  84. { Get the icon rendering masks (PLANEPTR) }
  85. ICONCTRLA_GetImageMask1 = ICONA_Dummy + 14;
  86. ICONCTRLA_GetImageMask2 = ICONA_Dummy + 15;
  87. { Transparent image color; set to -1 if opaque }
  88. ICONCTRLA_SetTransparentColor1 = ICONA_Dummy + 16;
  89. ICONCTRLA_GetTransparentColor1 = ICONA_Dummy + 17;
  90. ICONCTRLA_SetTransparentColor2 = ICONA_Dummy + 18;
  91. ICONCTRLA_GetTransparentColor2 = ICONA_Dummy + 19;
  92. { Image color palette (struct ColorRegister ) }
  93. ICONCTRLA_SetPalette1 = ICONA_Dummy + 20;
  94. ICONCTRLA_GetPalette1 = ICONA_Dummy + 21;
  95. ICONCTRLA_SetPalette2 = ICONA_Dummy + 22;
  96. ICONCTRLA_GetPalette2 = ICONA_Dummy + 23;
  97. { Size of image color palette (LONG) }
  98. ICONCTRLA_SetPaletteSize1 = ICONA_Dummy + 24;
  99. ICONCTRLA_GetPaletteSize1 = ICONA_Dummy + 25;
  100. ICONCTRLA_SetPaletteSize2 = ICONA_Dummy + 26;
  101. ICONCTRLA_GetPaletteSize2 = ICONA_Dummy + 27;
  102. { Image data; one by per pixel (UBYTE ) }
  103. ICONCTRLA_SetImageData1 = ICONA_Dummy + 28;
  104. ICONCTRLA_GetImageData1 = ICONA_Dummy + 29;
  105. ICONCTRLA_SetImageData2 = ICONA_Dummy + 30;
  106. ICONCTRLA_GetImageData2 = ICONA_Dummy + 31;
  107. { Render image without frame (BOOL) }
  108. ICONCTRLA_SetFrameless = ICONA_Dummy + 32;
  109. ICONCTRLA_GetFrameless = ICONA_Dummy + 33;
  110. { Enable NewIcons support (BOOL) }
  111. ICONCTRLA_SetNewIconsSupport = ICONA_Dummy + 34;
  112. ICONCTRLA_GetNewIconsSupport = ICONA_Dummy + 35;
  113. { Icon aspect ratio (UBYTE ) }
  114. ICONCTRLA_SetAspectRatio = ICONA_Dummy + 36;
  115. ICONCTRLA_GetAspectRatio = ICONA_Dummy + 37;
  116. { Icon dimensions; valid only for palette mapped icon images (LONG) }
  117. ICONCTRLA_SetWidth = ICONA_Dummy + 38;
  118. ICONCTRLA_GetWidth = ICONA_Dummy + 39;
  119. ICONCTRLA_SetHeight = ICONA_Dummy + 40;
  120. ICONCTRLA_GetHeight = ICONA_Dummy + 41;
  121. { Check whether the icon is palette mapped (LONG ). }
  122. ICONCTRLA_IsPaletteMapped = ICONA_Dummy + 42;
  123. { Get the screen the icon is attached to (struct Screen ). }
  124. ICONCTRLA_GetScreen = ICONA_Dummy + 43;
  125. { Check whether the icon has a real select image (LONG ). }
  126. ICONCTRLA_HasRealImage2 = ICONA_Dummy + 44;
  127. { Check whether the icon is of the NewIcon type (LONG ). }
  128. ICONCTRLA_IsNewIcon = ICONA_Dummy + 79;
  129. { Check whether this icon was allocated by icon.library
  130. or if consists solely of a statically allocated
  131. struct DiskObject. (LONG ).
  132. }
  133. ICONCTRLA_IsNativeIcon = ICONA_Dummy + 80;
  134. {**************************************************************************}
  135. { Icon aspect ratio is not known. }
  136. ICON_ASPECT_RATIO_UNKNOWN = 0;
  137. { Tags for use with GetIconTagList() }
  138. { Default icon type to retrieve (LONG) }
  139. ICONGETA_GetDefaultType = ICONA_Dummy+45;
  140. { Retrieve default icon for the given name (STRPTR) }
  141. ICONGETA_GetDefaultName = ICONA_Dummy + 46;
  142. { Return a default icon if the requested icon
  143. file cannot be found (BOOL).
  144. }
  145. ICONGETA_FailIfUnavailable = ICONA_Dummy + 47;
  146. { If possible, retrieve a palette mapped icon (BOOL). }
  147. ICONGETA_GetPaletteMappedIcon = ICONA_Dummy + 48;
  148. { Set if the icon returned is a default icon (BOOL ). }
  149. ICONGETA_IsDefaultIcon = ICONA_Dummy + 49;
  150. { Remap the icon to the default screen, if possible (BOOL). }
  151. ICONGETA_RemapIcon = ICONA_Dummy + 50;
  152. { Generate icon image masks (BOOL). }
  153. ICONGETA_GenerateImageMasks = ICONA_Dummy + 51;
  154. { Label text to be assigned to the icon (STRPTR). }
  155. ICONGETA_Label = ICONA_Dummy + 52;
  156. { Screen to remap the icon to (struct Screen ). }
  157. ICONGETA_Screen = ICONA_Dummy + 69;
  158. {**************************************************************************}
  159. { Tags for use with PutIconTagList() }
  160. { Notify Workbench of the icon being written (BOOL) }
  161. ICONPUTA_NotifyWorkbench = ICONA_Dummy + 53;
  162. { Store icon as the default for this type (LONG) }
  163. ICONPUTA_PutDefaultType = ICONA_Dummy + 54;
  164. { Store icon as a default for the given name (STRPTR) }
  165. ICONPUTA_PutDefaultName = ICONA_Dummy + 55;
  166. { When storing a palette mapped icon, don't save the
  167. the original planar icon image with the file. Replace
  168. it with a tiny replacement image.
  169. }
  170. ICONPUTA_DropPlanarIconImage = ICONA_Dummy + 56;
  171. { Don't write the chunky icon image data to disk. }
  172. ICONPUTA_DropChunkyIconImage = ICONA_Dummy + 57;
  173. { Don't write the NewIcons tool types to disk. }
  174. ICONPUTA_DropNewIconToolTypes = ICONA_Dummy + 58;
  175. { If this tag is enabled, the writer will examine the
  176. icon image data to find out whether it can compress
  177. it more efficiently. This may take extra time and
  178. is not generally recommended.
  179. }
  180. ICONPUTA_OptimizeImageSpace = ICONA_Dummy + 59;
  181. { Don't write the entire icon file back to disk,
  182. only change the do->do_CurrentX/do->do_CurrentY
  183. members.
  184. }
  185. ICONPUTA_OnlyUpdatePosition = ICONA_Dummy + 72;
  186. { Before writing a palette mapped icon back to disk,
  187. icon.library will make sure that the original
  188. planar image data is stored in the file. If you
  189. don't want that to happen, set this option to
  190. FALSE. This will allow you to change the planar icon
  191. image data written back to disk.
  192. }
  193. ICONPUTA_PreserveOldIconImages = ICONA_Dummy + 84;
  194. {**************************************************************************}
  195. { For use with the file identification hook. }
  196. type
  197. PIconIdentifyMsg = ^tIconIdentifyMsg;
  198. tIconIdentifyMsg = record
  199. { Libraries that are already opened for your use. }
  200. iim_SysBase : PLibrary;
  201. iim_DOSBase : PLibrary;
  202. iim_UtilityBase : PLibrary;
  203. iim_IconBase : PLibrary;
  204. { File context information. }
  205. iim_FileLock : BPTR; { Lock on the object to return an icon for. }
  206. iim_ParentLock : BPTR; { Lock on the object's parent directory, if available. }
  207. iim_FIB : PFileInfoBlock; { Already initialized for you. }
  208. iim_FileHandle : BPTR; { If non-NULL, pointer to the file to examine,
  209. * positioned right at the first byte, ready
  210. * for you to use.
  211. }
  212. iim_Tags : PTagItem; { Tags passed to GetIconTagList(). }
  213. end;
  214. {**************************************************************************}
  215. { Tags for use with DupDiskObjectA() }
  216. const
  217. { Duplicate do_DrawerData }
  218. ICONDUPA_DuplicateDrawerData = ICONA_Dummy + 60;
  219. { Duplicate the Image structures. }
  220. ICONDUPA_DuplicateImages = ICONA_Dummy + 61;
  221. { Duplicate the image data (Image->ImageData) itself. }
  222. ICONDUPA_DuplicateImageData = ICONA_Dummy + 62;
  223. { Duplicate the default tool. }
  224. ICONDUPA_DuplicateDefaultTool = ICONA_Dummy + 63;
  225. { Duplicate the tool types list. }
  226. ICONDUPA_DuplicateToolTypes = ICONA_Dummy + 64;
  227. { Duplicate the tool window. }
  228. ICONDUPA_DuplicateToolWindow = ICONA_Dummy + 65;
  229. { If the icon to be duplicated is in fact a palette mapped
  230. icon which has never been set up to be displayed on the
  231. screen, turn the duplicate into that palette mapped icon.
  232. }
  233. ICONDUPA_ActivateImageData = ICONA_Dummy + 82;
  234. {**************************************************************************}
  235. { Tags for use with DrawIconStateA() and GetIconRectangleA(). }
  236. { Drawing information to use (struct DrawInfo ). }
  237. ICONDRAWA_DrawInfo = ICONA_Dummy + 66;
  238. { Draw the icon without the surrounding frame (BOOL). }
  239. ICONDRAWA_Frameless = ICONA_Dummy + 70;
  240. { Erase the background before drawing a frameless icon (BOOL). }
  241. ICONDRAWA_EraseBackground = ICONA_Dummy + 71;
  242. { Draw the icon without the surrounding border and frame (BOOL). }
  243. ICONDRAWA_Borderless = ICONA_Dummy + 83;
  244. { The icon to be drawn refers to a linked object (BOOL). }
  245. ICONDRAWA_IsLink = ICONA_Dummy + 89;
  246. {**************************************************************************}
  247. { Reserved tags; don't use! }
  248. ICONA_Reserved1 = ICONA_Dummy + 73;
  249. ICONA_Reserved2 = ICONA_Dummy + 74;
  250. ICONA_Reserved3 = ICONA_Dummy + 76;
  251. ICONA_Reserved4 = ICONA_Dummy + 81;
  252. ICONA_Reserved5 = ICONA_Dummy + 85;
  253. ICONA_Reserved6 = ICONA_Dummy + 86;
  254. ICONA_Reserved7 = ICONA_Dummy + 87;
  255. ICONA_Reserved8 = ICONA_Dummy + 88;
  256. { }
  257. ICONA_LAST_TAG = ICONA_Dummy + 89;
  258. {**************************************************************************}
  259. Const
  260. ICONNAME : PChar = 'icon.library';
  261. VAR IconBase : pLibrary = nil;
  262. FUNCTION AddFreeList(freelist : pFreeList location 'a0'; const mem : POINTER location 'a1'; size : ULONG location 'a2') : LongBool; syscall IconBase 072;
  263. FUNCTION BumpRevision(newname : pCHAR location 'a0'; const oldname : pCHAR location 'a1') : pCHAR; syscall IconBase 108;
  264. FUNCTION DeleteDiskObject(const name : pCHAR location 'a0') : LongBool; syscall IconBase 138;
  265. FUNCTION FindToolType(const toolTypeArray : POINTER location 'a0'; const typeName : pCHAR location 'a1') : pCHAR; syscall IconBase 096;
  266. PROCEDURE FreeDiskObject(diskobj : pDiskObject location 'a0'); syscall IconBase 090;
  267. PROCEDURE FreeFreeList(freelist : pFreeList location 'a0'); syscall IconBase 054;
  268. FUNCTION GetDefDiskObject(typ : LONGINT location 'd0') : pDiskObject; syscall IconBase 120;
  269. FUNCTION GetDiskObject(const name : pCHAR location 'a0') : pDiskObject; syscall IconBase 078;
  270. FUNCTION GetDiskObjectNew(const name : pCHAR location 'a0') : pDiskObject; syscall IconBase 132;
  271. FUNCTION MatchToolValue(const typeString : pCHAR location 'a0'; const value : pCHAR location 'a1') : LongBool; syscall IconBase 102;
  272. FUNCTION PutDefDiskObject(const diskObject : pDiskObject location 'a0') : LongBool; syscall IconBase 126;
  273. FUNCTION PutDiskObject(const name : pCHAR location 'a0'; const diskobj : pDiskObject location 'a1') : LongBool; syscall IconBase 084;
  274. { version 44 }
  275. FUNCTION DupDiskObjectA(CONST diskObject : pDiskObject location 'a0'; CONST tags : pTagItem location 'a1') : pDiskObject; syscall IconBase 150;
  276. FUNCTION IconControlA(icon : pDiskObject location 'a0'; CONST tags : pTagItem location 'a1') : longword; syscall IconBase 156;
  277. PROCEDURE DrawIconStateA(rp : pRastPort location 'a0'; CONST icon : pDiskObject location 'a1'; CONST label_ : pCHAR location 'a2'; leftOffset : LONGINT location 'd0'; topOffset : LONGINT location 'd1'; state : longword location 'd2'; CONST tags : pTagItem location 'a3'); syscall IconBase 162;
  278. FUNCTION GetIconRectangleA(rp : pRastPort location 'a0'; CONST icon : pDiskObject location 'a1'; CONST label_ : pCHAR location 'a2'; rect : pRectangle location 'a3'; CONST tags : pTagItem location 'a4') : LongBool; syscall IconBase 168;
  279. FUNCTION NewDiskObject(type_ : LONGINT location 'd0') : pDiskObject; syscall IconBase 174;
  280. FUNCTION GetIconTagList(CONST name : pCHAR location 'a0'; CONST tags : pTagItem location 'a1') : pDiskObject; syscall IconBase 180;
  281. FUNCTION PutIconTagList(CONST name : pCHAR location 'a0'; CONST icon : pDiskObject location 'a1'; CONST tags : pTagItem location 'a2') : LongBool; syscall IconBase 186;
  282. FUNCTION LayoutIconA(icon : pDiskObject location 'a0'; screen : pScreen location 'a1'; tags : pTagItem location 'a2') : LongBool; syscall IconBase 192;
  283. PROCEDURE ChangeToSelectedIconColor(cr : pColorRegister location 'a0'); syscall IconBase 198;
  284. { overlay }
  285. FUNCTION BumpRevision(newname : pCHar; const oldname : RawByteString) : pCHAR;
  286. FUNCTION DeleteDiskObject(const name : RawByteString) : BOOLEAN;
  287. FUNCTION FindToolType(const toolTypeArray : POINTER;const typeName : RawByteString) : pCHAR;
  288. FUNCTION GetDiskObject(const name : RawByteString) : pDiskObject;
  289. FUNCTION GetDiskObjectNew(const name : RawByteString) : pDiskObject;
  290. FUNCTION MatchToolValue(const typeString : RawByteString;const value : pCHAR) : BOOLEAN;
  291. FUNCTION MatchToolValue(const typeString : pCHAR;const value : RawByteString) : BOOLEAN;
  292. FUNCTION MatchToolValue(const typeString : RawByteString;const value : RawByteString) : BOOLEAN;
  293. FUNCTION PutDiskObject(const name : RawByteString;const diskobj : pDiskObject) : BOOLEAN;
  294. { version 44 overlay}
  295. FUNCTION GetIconTagList(CONST name : RawByteString; CONST tags : pTagItem) : pDiskObject;
  296. FUNCTION PutIconTagList(CONST name : RawByteString; CONST icon : pDiskObject; CONST tags : pTagItem) : BOOLEAN;
  297. {macros}
  298. function PACK_ICON_ASPECT_RATIO(num,den : longint) : longint;
  299. IMPLEMENTATION
  300. function PACK_ICON_ASPECT_RATIO(num,den : longint) : longint;
  301. begin
  302. PACK_ICON_ASPECT_RATIO:=(num shl 4) or den;
  303. end;
  304. FUNCTION BumpRevision(newname : pCHar;const oldname : RawByteString) : pCHAR;
  305. begin
  306. BumpRevision := BumpRevision(newname,PChar(oldname));
  307. end;
  308. FUNCTION DeleteDiskObject(const name : RawByteString) : BOOLEAN;
  309. begin
  310. DeleteDiskObject := DeleteDiskObject(PChar(name));
  311. end;
  312. FUNCTION FindToolType(const toolTypeArray : POINTER;const typeName : RawByteString) : pCHAR;
  313. begin
  314. FindToolType := FindToolType(toolTypeArray,PChar(typeName));
  315. end;
  316. FUNCTION GetDiskObject(const name : RawByteString) : pDiskObject;
  317. begin
  318. GetDiskObject := GetDiskObject(PChar(name));
  319. end;
  320. FUNCTION GetDiskObjectNew(const name : RawByteString) : pDiskObject;
  321. begin
  322. GetDiskObjectNew := GetDiskObjectNew(PChar(name));
  323. end;
  324. FUNCTION MatchToolValue(const typeString : RawByteString;const value : pCHAR) : BOOLEAN;
  325. begin
  326. MatchToolValue := MatchToolValue(PChar(typeString),value);
  327. end;
  328. FUNCTION MatchToolValue(const typeString : pCHAR;const value : RawByteString) : BOOLEAN;
  329. begin
  330. MatchToolValue := MatchToolValue(typeString,PChar(value));
  331. end;
  332. FUNCTION MatchToolValue(const typeString : RawByteString;const value : RawByteString) : BOOLEAN;
  333. begin
  334. MatchToolValue := MatchToolValue(PChar(typeString),PChar(value));
  335. end;
  336. FUNCTION PutDiskObject(const name : RawByteString;const diskobj : pDiskObject) : BOOLEAN;
  337. begin
  338. PutDiskObject := PutDiskObject(PChar(name),diskobj);
  339. end;
  340. FUNCTION GetIconTagList(CONST name : RawByteString; CONST tags : pTagItem) : pDiskObject;
  341. begin
  342. GetIconTagList := GetIconTagList(PChar(name),tags);
  343. end;
  344. FUNCTION PutIconTagList(CONST name : RawByteString; CONST icon : pDiskObject; CONST tags : pTagItem) : BOOLEAN;
  345. begin
  346. PutIconTagList := PutIconTagList(PChar(name),icon,tags);
  347. end;
  348. const
  349. { Change VERSION and LIBVERSION to proper values }
  350. VERSION : string[2] = '0';
  351. LIBVERSION : longword = 0;
  352. initialization
  353. IconBase := OpenLibrary(ICONNAME,LIBVERSION);
  354. finalization
  355. if Assigned(IconBase) then
  356. CloseLibrary(IconBase);
  357. END. (* UNIT ICON *)