icon.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2014 by Free Pascal development team
  4. icon.library functions
  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. unit icon;
  12. interface
  13. uses
  14. exec, workbench, utility, amigados, agraphics, intuition;
  15. //,datatypes;
  16. const
  17. ICONNAME : PChar = 'icon.library';
  18. ICONA_Dummy = TAG_USER + $9000; // Start of icon.library tags
  19. ICONA_ErrorCode = ICONA_Dummy + 1; // Errorcode (PLongInt)
  20. ICONA_ErrorTagItem = ICONA_Dummy + 75; //Points to the tag item that caused the error (^PTagItem).
  21. {Global options for IconControlA()}
  22. { Screen to use for remapping Workbench icons to (PScreen) }
  23. ICONCTRLA_SetGlobalScreen = ICONA_Dummy + 2;
  24. ICONCTRLA_GetGlobalScreen = ICONA_Dummy + 3;
  25. { Icon color remapping precision; defaults to PRECISION_ICON (LongInt) }
  26. ICONCTRLA_SetGlobalPrecision = ICONA_Dummy + 4;
  27. ICONCTRLA_GetGlobalPrecision = ICONA_Dummy + 5;
  28. { Icon frame size dimensions (PRectange) }
  29. ICONCTRLA_SetGlobalEmbossRect = ICONA_Dummy + 6;
  30. ICONCTRLA_GetGlobalEmbossRect = ICONA_Dummy + 7;
  31. { Render image without frame (BOOL) }
  32. ICONCTRLA_SetGlobalFrameless = ICONA_Dummy + 8;
  33. ICONCTRLA_GetGlobalFrameless = ICONA_Dummy + 9;
  34. { Enable NewIcons support (BOOL) }
  35. ICONCTRLA_SetGlobalNewIconsSupport = ICONA_Dummy + 10;
  36. ICONCTRLA_GetGlobalNewIconsSupport = ICONA_Dummy + 11;
  37. { Enable color icon support (BOOL) }
  38. ICONCTRLA_SetGlobalColorIconSupport = ICONA_Dummy + 77;
  39. ICONCTRLA_GetGlobalColorIconSupport = ICONA_Dummy + 78;
  40. { Set/Get the hook to be called when identifying a file (PHook) }
  41. ICONCTRLA_SetGlobalIdentifyHook = ICONA_Dummy + 12;
  42. ICONCTRLA_GetGlobalIdentifyHook = ICONA_Dummy + 13;
  43. { Set/get the maximum length of a file/drawer name supported
  44. by icon.library (LONG). }
  45. ICONCTRLA_SetGlobalMaxNameLength = ICONA_Dummy + 67;
  46. ICONCTRLA_GetGlobalMaxNameLength = ICONA_Dummy + 68;
  47. { Per icon local options for IconControlA() }
  48. { Get the icon rendering masks (PLANEPTR) }
  49. ICONCTRLA_GetImageMask1 = ICONA_Dummy + 14;
  50. ICONCTRLA_GetImageMask2 = ICONA_Dummy + 15;
  51. { Transparent image color; set to -1 if opaque }
  52. ICONCTRLA_SetTransparentColor1 = ICONA_Dummy + 16;
  53. ICONCTRLA_GetTransparentColor1 = ICONA_Dummy + 17;
  54. ICONCTRLA_SetTransparentColor2 = ICONA_Dummy + 18;
  55. ICONCTRLA_GetTransparentColor2 = ICONA_Dummy + 19;
  56. { Image color palette (PColorRegister) }
  57. ICONCTRLA_SetPalette1 = ICONA_Dummy + 20;
  58. ICONCTRLA_GetPalette1 = ICONA_Dummy + 21;
  59. ICONCTRLA_SetPalette2 = ICONA_Dummy + 22;
  60. ICONCTRLA_GetPalette2 = ICONA_Dummy + 23;
  61. { Size of image color palette (LongInt) }
  62. ICONCTRLA_SetPaletteSize1 = ICONA_Dummy + 24;
  63. ICONCTRLA_GetPaletteSize1 = ICONA_Dummy + 25;
  64. ICONCTRLA_SetPaletteSize2 = ICONA_Dummy + 26;
  65. ICONCTRLA_GetPaletteSize2 = ICONA_Dummy + 27;
  66. { Image data; one by per pixel (PBYTE) }
  67. ICONCTRLA_SetImageData1 = ICONA_Dummy + 28;
  68. ICONCTRLA_GetImageData1 = ICONA_Dummy + 29;
  69. ICONCTRLA_SetImageData2 = ICONA_Dummy + 30;
  70. ICONCTRLA_GetImageData2 = ICONA_Dummy + 31;
  71. { Render image without frame (BOOL) }
  72. ICONCTRLA_SetFrameless = ICONA_Dummy + 32;
  73. ICONCTRLA_GetFrameless = ICONA_Dummy + 33;
  74. { Enable NewIcons support (BOOL) }
  75. ICONCTRLA_SetNewIconsSupport = ICONA_Dummy + 34;
  76. ICONCTRLA_GetNewIconsSupport = ICONA_Dummy + 35;
  77. { Icon aspect ratio (PBYTE) }
  78. ICONCTRLA_SetAspectRatio = ICONA_Dummy + 36;
  79. ICONCTRLA_GetAspectRatio = ICONA_Dummy + 37;
  80. { Icon dimensions; valid only for palette mapped icon images (LongInt) }
  81. ICONCTRLA_SetWidth = ICONA_Dummy + 38;
  82. ICONCTRLA_GetWidth = ICONA_Dummy + 39;
  83. ICONCTRLA_SetHeight = ICONA_Dummy + 40;
  84. ICONCTRLA_GetHeight = ICONA_Dummy + 41;
  85. { Check whether the icon is palette mapped (PLongInt). }
  86. ICONCTRLA_IsPaletteMapped = ICONA_Dummy + 42;
  87. { Get the screen the icon is attached to (^PScreen). }
  88. ICONCTRLA_GetScreen = ICONA_Dummy + 43;
  89. { Check whether the icon has a real select image (PLongInt). }
  90. ICONCTRLA_HasRealImage2 = ICONA_Dummy + 44;
  91. { Check whether the icon is of the NewIcon type (PLongInt). }
  92. ICONCTRLA_IsNewIcon = ICONA_Dummy + 79;
  93. { Check whether this icon was allocated by icon.library
  94. or if consists solely of a statically allocated
  95. struct DiskObject. (PLongInt).}
  96. ICONCTRLA_IsNativeIcon = ICONA_Dummy + 80;
  97. { Icon Aspect Handling}
  98. { Icon aspect ratio is not known. }
  99. ICON_ASPECT_RATIO_UNKNOWN = 0;
  100. { Tags for use with GetIconTagList() }
  101. { Default icon type to retrieve (LongInt) }
  102. ICONGETA_GetDefaultType = ICONA_Dummy+45;
  103. { Retrieve default icon for the given name (PChar) }
  104. ICONGETA_GetDefaultName = ICONA_Dummy + 46;
  105. { Return a default icon if the requested icon
  106. file cannot be found (BOOL).}
  107. ICONGETA_FailIfUnavailable = ICONA_Dummy + 47;
  108. { If possible, retrieve a palette mapped icon (BOOL). }
  109. ICONGETA_GetPaletteMappedIcon = ICONA_Dummy + 48;
  110. { Set if the icon returned is a default icon (PLongBool). }
  111. ICONGETA_IsDefaultIcon = ICONA_Dummy + 49;
  112. { Remap the icon to the default screen, if possible (BOOL). }
  113. ICONGETA_RemapIcon = ICONA_Dummy + 50;
  114. { Generate icon image masks (BOOL). }
  115. ICONGETA_GenerateImageMasks = ICONA_Dummy + 51;
  116. { Label text to be assigned to the icon (PChar). }
  117. ICONGETA_Label = ICONA_Dummy + 52;
  118. { Screen to remap the icon to (PScreen). }
  119. ICONGETA_Screen = ICONA_Dummy + 69;
  120. { Tags for use with PutIconTagList() }
  121. { Notify Workbench of the icon being written (BOOL) }
  122. ICONPUTA_NotifyWorkbench = ICONA_Dummy + 53;
  123. { Store icon as the default for this type (LongInt) }
  124. ICONPUTA_PutDefaultType = ICONA_Dummy + 54;
  125. { Store icon as a default for the given name (PChar) }
  126. ICONPUTA_PutDefaultName = ICONA_Dummy + 55;
  127. { When storing a palette mapped icon, don't save the
  128. the original planar icon image with the file. Replace
  129. it with a tiny replacement image.}
  130. ICONPUTA_DropPlanarIconImage = ICONA_Dummy + 56;
  131. { Don't write the chunky icon image data to disk. }
  132. ICONPUTA_DropChunkyIconImage = ICONA_Dummy + 57;
  133. { Don't write the NewIcons tool types to disk. }
  134. ICONPUTA_DropNewIconToolTypes = ICONA_Dummy + 58;
  135. { If this tag is enabled, the writer will examine the
  136. icon image data to find out whether it can compress
  137. it more efficiently. This may take extra time and
  138. is not generally recommended.}
  139. ICONPUTA_OptimizeImageSpace = ICONA_Dummy + 59;
  140. { Don't write the entire icon file back to disk,
  141. only change the do^.do_CurrentX/do^.do_CurrentY
  142. members.}
  143. ICONPUTA_OnlyUpdatePosition = ICONA_Dummy + 72;
  144. { Before writing a palette mapped icon back to disk,
  145. icon.library will make sure that the original
  146. planar image data is stored in the file. If you
  147. don't want that to happen, set this option to
  148. FALSE. This will allow you to change the planar icon
  149. image data written back to disk.}
  150. ICONPUTA_PreserveOldIconImages = ICONA_Dummy + 84;
  151. { For use with the file identification hook. }
  152. type
  153. PIconIdentifyMsg = ^TIconIdentifyMsg;
  154. TIconIdentifyMsg = record
  155. { Libraries that are already opened for your use. }
  156. iim_SysBase : PLibrary;
  157. iim_DOSBase : PLibrary;
  158. iim_UtilityBase : PLibrary;
  159. iim_IconBase : PLibrary;
  160. { File context information. }
  161. iim_FileLock : BPTR; // Lock on the object to return an icon for.
  162. iim_ParentLock : BPTR; // Lock on the object's parent directory, if available.
  163. iim_FIB : PFileInfoBlock;// Already initialized for you.
  164. iim_FileHandle : BPTR; // If non-NULL, pointer to the file to examine,
  165. // positioned right at the first byte, ready
  166. // for you to use.
  167. iim_Tags : PTagItem; // Tags passed to GetIconTagList().
  168. end;
  169. { Tags for use with DupDiskObjectA() }
  170. const
  171. ICONDUPA_DuplicateDrawerData = ICONA_Dummy + 60; // Duplicate do_DrawerData
  172. ICONDUPA_DuplicateImages = ICONA_Dummy + 61; // Duplicate the Image structures.
  173. ICONDUPA_DuplicateImageData = ICONA_Dummy + 62; // Duplicate the image data (Image->ImageData) itself.
  174. ICONDUPA_DuplicateDefaultTool = ICONA_Dummy + 63; // Duplicate the default tool.
  175. ICONDUPA_DuplicateToolTypes = ICONA_Dummy + 64; // Duplicate the tool types list.
  176. ICONDUPA_DuplicateToolWindow = ICONA_Dummy + 65; // Duplicate the tool window.
  177. ICONDUPA_ActivateImageData = ICONA_Dummy + 82;{ If the icon to be duplicated is in fact a palette mapped
  178. icon which has never been set up to be displayed on the
  179. screen, turn the duplicate into that palette mapped icon.}
  180. { Tags for use with DrawIconStateA() and GetIconRectangleA(). }
  181. ICONDRAWA_DrawInfo = ICONA_Dummy + 66; // Drawing information to use (PDrawInfo).
  182. ICONDRAWA_Frameless = ICONA_Dummy + 70; // Draw the icon without the surrounding frame (BOOL).
  183. ICONDRAWA_EraseBackground = ICONA_Dummy + 71; // Erase the background before drawing a frameless icon (BOOL).
  184. ICONDRAWA_Borderless = ICONA_Dummy + 83; // Draw the icon without the surrounding border and frame (BOOL).
  185. { Reserved tags; don't use! }
  186. ICONA_Reserved1 = ICONA_Dummy + 73;
  187. ICONA_Reserved2 = ICONA_Dummy + 74;
  188. ICONA_Reserved3 = ICONA_Dummy + 76;
  189. ICONA_Reserved4 = ICONA_Dummy + 81;
  190. ICONA_Reserved5 = ICONA_Dummy + 85;
  191. ICONA_Reserved6 = ICONA_Dummy + 86;
  192. ICONA_Reserved7 = ICONA_Dummy + 87;
  193. ICONA_Reserved8 = ICONA_Dummy + 88;
  194. { The last Tag}
  195. ICONA_LAST_TAG = ICONA_Dummy + 88;
  196. var
  197. IconBase: PLibrary;
  198. function AddFreeList(FreeList: PFreeList; const Mem: APTR; Size: ULONG): BOOL; syscall IconBase 12;
  199. function BumpRevision(NewName: PChar; const OldName: PChar): PChar; syscall IconBase 18;
  200. function DeleteDiskObject(const Name: PChar): BOOL; syscall IconBase 23;
  201. function FindToolType(const ToolTypeArray: PPChar; const TypeName: STRPTR): STRPTR; syscall IconBase 16;
  202. procedure FreeDiskObject(DiskObj: PDiskObject); syscall IconBase 15;
  203. procedure FreeFreeList(FreeList: PFreeList); syscall IconBase 9;
  204. function GetDefDiskObject(Typ: LongInt): PDiskObject; syscall IconBase 20;
  205. function GetDiskObject(const Name: STRPTR): PDiskObject; syscall IconBase 13;
  206. function GetDiskObjectNew(const Name : PChar): PDiskObject; syscall IconBase 22;
  207. function MatchToolValue(const TypeString: PChar; const Value: PChar): BOOL; syscall IconBase 17;
  208. function PutDefDiskObject(const Icon: PDiskObject): BOOL; syscall IconBase 21;
  209. function PutDiskObject(const Name: STRPTR; const Icon: PDiskObject): BOOL; syscall IconBase 14;
  210. { version 44 }
  211. function DupDiskObjectA(const Icon: PDiskObject; const Tags: PTagItem): PDiskObject; syscall IconBase 25;
  212. function IconControlA(Icon: PDiskObject; const Tags: PTagItem): ULONG; syscall IconBase 26;
  213. procedure DrawIconStateA(Rp: PRastPort; const Icon: PDiskObject; const Label_: STRPTR;
  214. LeftEdge: LongInt; TopEdge: LongInt; State: ULONG; const Tags: PTagItem); syscall IconBase 27;
  215. function GetIconRectangleA(Rp: PRastPort; const Icon: PDiskObject; const Label_: PChar;
  216. Rect: PRectangle; const Tags: PTagItem): BOOL; syscall IconBase 28;
  217. function NewDiskObject(Type_: ULONG): PDiskObject; syscall IconBase 29;
  218. function GetIconTagList(const Name: STRPTR; const Tags: PTagItem): PDiskObject; syscall IconBase 30;
  219. function PutIconTagList(const Name: STRPTR; const Icon: PDiskObject; const Tags: PTagItem): BOOL; syscall IconBase 31;
  220. function LayoutIconA(Icon: PDiskObject; Screen: PScreen; Tags: PTagItem): BOOL; syscall IconBase 32;
  221. procedure ChangeToSelectedIconColor(Cr: Pointer); syscall IconBase 33; //TODO: pColorRegister // 33
  222. {macros}
  223. function PACK_ICON_ASPECT_RATIO(Num, Den: LongInt): LongInt;
  224. procedure UNPACK_ICON_ASPECT_RATIO(Aspect: LongInt; var Num, Den: LongInt);
  225. type
  226. TToolTypeArray= array of AnsiString;
  227. function GetToolTypes(Filename: AnsiString): TToolTypeArray;
  228. implementation
  229. function GetToolTypes(Filename: AnsiString): TToolTypeArray;
  230. var
  231. DObj: PDiskObject;
  232. Tooltype: PPChar;
  233. Idx: Integer;
  234. begin
  235. SetLength(GetToolTypes, 0);
  236. DObj := GetDiskObject(PChar(FileName));
  237. if not Assigned(Dobj) then
  238. Exit;
  239. Tooltype := DObj^.do_Tooltypes;
  240. while Assigned(ToolType^) do
  241. begin
  242. Idx := Length(GetToolTypes);
  243. SetLength(GetToolTypes, Idx + 1);
  244. GetToolTypes[Idx] := ToolType^;
  245. Inc(ToolType);
  246. end;
  247. FreeDiskObject(DObj);
  248. end;
  249. function PACK_ICON_ASPECT_RATIO(Num, Den: LongInt): LongInt; inline;
  250. begin
  251. PACK_ICON_ASPECT_RATIO := (Num shl 4) or Den;
  252. end;
  253. procedure UNPACK_ICON_ASPECT_RATIO(Aspect: LongInt; var Num, Den: LongInt); inline;
  254. begin
  255. Num := (Aspect shr 4) and $F;
  256. Den := Aspect and $15;
  257. end;
  258. initialization
  259. IconBase := OpenLibrary(ICONNAME, 40);
  260. finalization
  261. CloseLibrary(IconBase);
  262. end.