home *** CD-ROM | disk | FTP | other *** search
- /*
- #### # # # #
- # # # # # The FreeWare C library for
- # # ## ### # # # # ### RISC OS machines
- # # # # # # # # # # # ___________________________________
- # # #### ### ## # # # #
- # # # # # # # # # # Please refer to the accompanying
- #### ### #### # # ##### # ### documentation for conditions of use
- ________________________________________________________________________
-
- File: Icon.h
- Author: Copyright © 1992, 1993, 1994 Jason Williams
- Version: 1.10 (22 Mar 1994)
- Purpose: High-level icon handling routines
- */
-
-
- #ifndef __dl_icon_h
- #define __dl_icon_h
-
- #ifndef __dl_wimp_h
- #include "Wimp.h"
- #endif
-
- #ifndef __dl_dragaspr_h
- #include "DragASpr.h"
- #endif
-
-
- /* Icon_BarIcon ---------------------------------------------------------
- * This function places an icon on the iconbar. It makes a "normal"
- * sprite-only icon, with the "normal" default flags. If you want an
- * icon that is not this default, then create it yourself (it isn't hard!)
- *
- * If you wish to attach handlers/menus to the baricon, then remember
- * it's handle, and pass this to Event_Claim...
- * (Or wait for release 2 of DeskLib, which should have an Event_BarIcon)
- *
- * Pass in "spritename" - the name of a sprite in the Wimp Sprite pool
- * and "pos", which should be iconbar_LEFT or iconbar_RIGHT
- * The correct size of the icon will be determined and used
- * Returns: The icon handle of the created icon
- */
- extern icon_handle Icon_BarIcon(char *spritename, window_handle pos);
-
-
- /* Icon_BarIconUser -----------------------------------------------------
- * Plonk a sprite from a USER sprite area on the icon bar
- * Returns icon handle.
- */
- extern icon_handle Icon_BarIconUser(char *spritename, window_handle pos,
- unsigned int *area);
-
-
- /* Icon_GetSelect -------------------------------------------------------
- * Returns TRUE if the given icon is selected
- */
- extern BOOL Icon_GetSelect(window_handle window, icon_handle icon);
-
-
- /* Icon_GetShade --------------------------------------------------------
- * Returns TRUE if the given icon is shaded
- */
- extern BOOL Icon_GetShade(window_handle window, icon_handle icon);
-
-
- extern void Icon_SetSelect(window_handle window, icon_handle icon, int flag);
- /* Equivalent in action to Icon_Select + Icon_Deselect: Pass in a flag to
- * set the new selected status of the icon (0 = deselect, 1 = select)
- */
-
- extern void Icon_Select(window_handle window, icon_handle icon);
- /* If the given icon is currently deselected, it is selected */
-
- extern void Icon_Deselect(window_handle window, icon_handle icon);
- /* If the given icon is currently selected, it is deselected */
-
-
- extern void Icon_SetShade(window_handle window, icon_handle icon, int flag);
- /* Equivalent in action to Icon_Shade + Icon_Unshade: Pass in a flag to
- * set the new shaded status of the icon (0 = unshaded, 1 = shaded)
- */
-
- extern void Icon_Shade(window_handle window, icon_handle icon);
- /*
- * if the icon is currently unshaded (active) it is shaded (made inactive)
- * This includes removing the caret from the icon.
- */
-
- extern void Icon_Unshade(window_handle window, icon_handle icon);
- /* if the icon is currently shaded (inactive) it is unshaded (made active) */
-
-
- extern void Icon_SetForeColour(window_handle window, icon_handle icon,
- int wimpcolour);
- /* Sets an icon's foreground colour to the given WIMP colour (in range 0..15).
- * NOTE that this is a simple function which does not currently support
- * outline font icons (in fact, it'll corrupt their font handle and cause
- * untold grief)
- */
-
- extern void Icon_SetBackColour(window_handle window, icon_handle icon,
- int wimpcolour);
- /* Sets an icon's background colour to the given WIMP colour (in range 0..15).
- * NOTE that this is a simple function which does not currently support
- * outline font icons (in fact, it'll corrupt their font handle and cause
- * untold grief)
- */
-
-
- extern void Icon_ForceWindowRedraw(window_handle window, icon_handle icon);
- /* Force Redraws the area of WINDOW surrounding the icon, *including*
- * the 3-d border (validation string "b<bordertype>")
- */
-
- #define Icon_ForceRedraw(wind, icon) Wimp_SetIconState(wind, icon, 0, 0);
- /* Forces the WIMP to redraw (just) the icon */
-
-
-
- extern void Icon_SetCaret(window_handle window, icon_handle icon);
- /*
- * This routine sets the caret within the requested icon. It places the
- * caret at the (righthand) end of the text in the icon. If the icon is not
- * a text icon, then the function returns quietly
- */
-
- extern void Icon_LoseCaret(window_handle window, icon_handle icon);
- /* Icon_LoseCaret
- * This routine ensures that the caret is *not* contained within the
- * designated icon. Only sets a new position if the icon currently contains
- * the caret.
- */
-
-
-
- extern void Icon_SetInteger(window_handle w, icon_handle i, int value);
- /*
- * Sets the given icon's text to hold the number in "value". (and redraws icon)
- * If the number is too long (too many digits) it will be truncated to fit.
- * If unable to set the text (incorrect icon type), it returns quietly
- */
-
- extern void Icon_SetDouble(window_handle w, icon_handle i,
- double value, int decimalplaces);
- /*
- * Sets the given icon's text to hold the number in "value". (and redraws icon)
- * Only the first "decimalplaces" digits after the decimal point are
- * printed. If the number is too long (too many digits) it will be truncated
- * to fit. This may affect the accuracy or actual value of the number.
- * If unable to set the text (incorrect icon type), it returns quietly
- */
-
- extern void Icon_SetText(window_handle w, icon_handle i, char *text);
- /*
- * Copies the text string into the icon's indirected string buffer (and redraws)
- * If unable to set the text (incorrect icon type), it returns quietly
- * If text passed in is a NULL pointer, sets icon text to " "
- */
-
- extern void Icon_SetTextRJ(window_handle w, icon_handle i, char *text);
- /*
- * Copies the text string into the icon's indirected string buffer (and redraws)
- * This text is "right justified", meaning that if the text doesn't fit
- * into the available buffer space, it is truncated at the *LEFT*-hand side,
- * and preceded by a '...' (ellipsis) character.
- * If unable to set the text (incorrect icon type), it returns quietly
- * If text passed in is a NULL pointer, sets icon text to '\0'
- */
-
-
- extern void Icon_printf(window_handle window, icon_handle icon,
- char *format, ...);
- /*
- * Exactly the same as sprintf, but instead of passing in a string into which
- * the result is written, you pass in the window+icon identifier of an
- * indirected icon. (Anything other than an indirected icon will return
- * quietly with NO effect)
- * e.g Icon_printf(window, 5, "%d bytes copied", current);
- */
-
-
-
- extern double Icon_GetDouble(window_handle w, icon_handle i);
- /*
- * Gets the given icon's text and returns it in the form of a "double"
- * floating-point value. 0 will be returned from any error/invalid text
- */
-
- extern int Icon_GetInteger(window_handle w, icon_handle i);
- /*
- * Gets the given icon's text and returns it in the form of an integer
- * numeric value. 0 will be returned from any error/invalid text
- */
-
- extern void Icon_GetText(window_handle w, icon_handle i, char *text);
- /*
- * Copies the text string from the icon (sprite name, text, or indirected)
- * into the array pointed to by "text"
- * Note that the array pointed to by "text" must be big enough to hold the
- * resulting string, so the minimum sizes are:
- * If non-indirected (or a sprite), 12 characters
- * If indirected text, the indirected size of the icon.
- */
-
-
-
- /****************************************************************************
-
- char *Icon_GetTextPtr(window_handle window, icon_handle icon);
-
- Inputs: window, icon - handle pair of the icon to examine.
- Returns: Pointer to the *actual* indirected text buffer used for the
- given icon. If the icon is not indirected text, then you will
- get garbage back.
- Purpose: Get a pointer to the indirected text buffer for this icon, so
- you can read/change it.
-
- ****************************************************************************/
-
- extern char *Icon_GetTextPtr(window_handle, icon_handle);
-
-
- /****************************************************************************
-
- > os_error *Icon_SetFlags(window_handle window,
- icon_handle icon,
- int flags,
- BOOL set);
-
- Inputs: window, icon - window and icon handle pair of icon to change.
- flags - bitfield specifying the bits to change.
- set - if TRUE, all the flags defined by 'flags' will be set to
- 1, otherwise they will all be set to 0.
- Returns: Usual RISC OS error block.
- Purpose: Neat interface to the Wimp_SetIconState SWI.
- Errors: As for Wimp_SetIconState()
-
- ****************************************************************************/
-
- #define Icon_SetFlags(window, icon, flags, set) \
- Wimp_SetIconState((window), (icon), ((set) ? (flags) : 0), (flags))
-
-
- /****************************************************************************
-
- > os_error *Icon_SetFgCol(window, icon, col)
-
- Inputs: window, icon - handle pair to identify the icon to change.
- col - the new foreground colour to apply to the icon.
- Returns: Standard RISC OS error block.
- Purpose: Macro to allow simple call to change the foreground colour
- of an icon (via the Wimp_SetIconState SWI).
- SeeAlso: Icon_SetBgCol()
-
- ****************************************************************************/
-
- #define Icon_SetFgCol(w, i, col) \
- Wimp_SetIconState((w), (i), (col) * icon_FORECOLOUR, 0xF * icon_FORECOLOUR)
-
-
- /****************************************************************************
-
- > os_error *Icon_SetBgCol(window, icon, col)
-
- Inputs: window, icon - handle pair to identify the icon to change.
- col - the new background colour to apply to the icon.
- Returns: Standard RISC OS error block.
- Purpose: Macro to allow simple call to change the background colour
- of an icon (via the Wimp_SetIconState SWI).
- SeeAlso: Icon_SetFgCol()
-
- ****************************************************************************/
-
- #define Icon_SetBgCol(w, i, col) \
- Wimp_SetIconState((w), (i), \
- (unsigned) (col) * (unsigned) icon_BACKCOLOUR, \
- (unsigned) 0xF * (unsigned) icon_BACKCOLOUR)
-
-
- /****************************************************************************
-
- void Icon_ShadeGroup(window_handle window,
- icon_handle icons[],
- BOOL shade);
-
- Inputs: window - the window that contains the icons to be changed.
- icons - array of icon handles that specify the icons to change.
- The array should be terminated with -1.
- shade - TRUE to shade the icons, FALSE to unshade them.
- Purpose: Shade a group of icons as defined by an -1 terminated array of
- icon handles.
- SeeAlso: Icon_SelectGroup()
-
- ****************************************************************************/
-
- extern void Icon_ShadeGroup(window_handle window,
- icon_handle icons[],
- BOOL shade);
-
-
- /****************************************************************************
-
- void Icon_SelectGroup(window_handle window,
- icon_handle icons[],
- BOOL select);
-
- Inputs: window - the window that contains the icons to be changed.
- icons - array of icon handles that specify the icons to change.
- The array should be terminated with -1.
- select - TRUE to select the icons, FALSE to unselect them.
- Purpose: Select or unselect a group of icons, as defined by an -1
- terminated array of icon handles.
- SeeAlso: Icon_ShadeGroup()
-
- ****************************************************************************/
-
- extern void Icon_SelectGroup(window_handle window,
- icon_handle icons[],
- BOOL select);
-
-
-
-
- /****************************************************************************
-
- int Icon_GetFgCol(icon_block *icon);
-
- Inputs: icon - pointer to the icon info block that the colour should
- be extracted. This copes with anti-aliased icons.
- Returns: The foreground colour of the described icon.
- Purpose: Extract the foreground colour of an icon, coping with all the
- special cases.
-
- ****************************************************************************/
-
- extern int Icon_GetFgCol(icon_block *icon);
-
-
- /****************************************************************************
-
- int Icon_GetBgCol(icon_block *icon);
-
- Inputs: icon - pointer to the icon info block that the colour should
- be extracted. This copes with anti-aliased icons.
- Returns: The background colour of the described icon.
- Purpose: Extract the background colour of an icon, coping with all the
- special cases.
-
- ****************************************************************************/
-
- extern int Icon_GetBgCol(icon_block *icon);
-
-
-
-
- extern void Icon_SetRadios(window_handle window,
- icon_handle first, icon_handle last,
- icon_handle onradio);
- /*
- * Pass in a group of icons (specified by lowest-numbered icon and
- * highest-numbered icon), and the icon from this group that you want
- * selected. All icons except the one you want selected will be deselected.
- */
-
- extern int Icon_WhichRadio(window_handle window,
- icon_handle first, icon_handle last);
- /*
- * This function accepts parameters for the first (lowest numbered) and
- * last (highest numnbered) in a group of icons (generally a group of radio
- * buttons). It returns the icon number of the first icon it finds within
- * this range which is selected (or "last" if none are selected).
- * Use it to find which of a group of radios is selected.
- */
-
-
-
- /*
- * Waits for the given number of centiseconds.
- * This is a MULTITASKING wait - although your program will do nothing,
- * the rest of the desktop will continue to run.
- * The wait is aborted after the given time, or as soon as an event is
- * received. If an attempt is made to re-enter ClickWait(), it will return
- * immediately (i.e. if a click event causes ClickWait to ba called, then
- * a second click while "waiting" from the first click will have no effect.
- */
- extern void Icon_ClickWait(int waittime);
-
-
-
- /*
- * Starts a drag operation based on the given icon.
- * This is mainly used in "save as" windows to start drags of the file icon
- * when it is clicked on, but may be useful elsewhere.
- *
- * This call DOES NOT use DragASprite
- */
- extern void Icon_StartDrag(window_handle window, icon_handle icon);
-
- /*
- * Starts a drag operation based on the given icon, using DragASpr if available
- * extern void Icon_StartSolidDrag(window_handle window, icon_handle icon);
- */
- #define Icon_StartSolidDrag DragASprite_DragIcon
-
-
- /*
- * This will free any indirected data for this icon. It uses free(), so
- * obviously expects that malloc() was used to get the memory in the first
- * place, so make sure this is the case if you use this function.
- */
- extern void Icon_DisposeIndData(icon_data *data, icon_flags flags);
-
-
-
- /****************************************************************************
-
- void Icon_FileIcon(window_handle window, icon_handle icon, int filetype);
-
- Inputs: window - the window containing the icon to change.
- icon - handle of the icon to change.
- filetype - desired filetype sprite to display.
- Purpose: Changes an icon in a window to display the correct filetype
- sprite for the given filetype number.
- Requires that the specified icon is an indirected text-only
- icon with enough room in the text buffer to hold the sprite
- name.
- This function converts it to an indirected sprite-only icon,
- and fills in the sprite name and area.
-
- It does not check to make sure that the sprite corresponding
- to this filetype exists in the Wimp sprite pool - the caller
- should ensure that this is the case.
-
- ****************************************************************************/
-
- extern void Icon_FileIcon(window_handle window, icon_handle icon, int filetype);
-
-
- /****************************************************************************
-
- void Icon_ScreenPos(window_handle window, icon_handle icon,
- wimp_rect *rect)
-
- Inputs: window - the window containing the icon to examine.
- icon - handle of the icon to examine.
- Outputs: rect - the screen coordinates of the icon.
- Purpose: Gets the coordinate of an icon, and converts them into
- screen coordinates.
-
- ****************************************************************************/
-
- extern void Icon_ScreenPos(window_handle window,
- icon_handle icon,
- wimp_rect *rect);
-
-
-
- /* =========================================================================
- * Special high-level icon functions:
- * Slider icons: See "DeskLib.Libraries.Icon.c.Slider" for details
- */
-
- extern int Icon_SetSlider(window_handle window,
- icon_handle baseicon, icon_handle slidericon,
- int sliderpos);
- /* Sets a slider icon-pair to the specified position (specify as a
- * percentage). Values < 0 and > 1000 are clipped, and the value to which the
- * slider has been set is returned.
- */
-
- extern int Icon_UpdateSlider(window_handle window,
- icon_handle baseicon, icon_handle slidericon,
- int lastpos);
- /* (call on null events while slider being dragged)
- * Calculates a new slider percentage from the mouse pointer position.
- * If this differs from lastpos, the slider is updated (by recreating the
- * slidericon to the new length.
- * returns the new slider position percentage value.
- * NOTE: Slider update is achieved by DELETING and re-creating the slider
- * icon. This relies upon no icons of a lower icon handle having been deleted!
- */
-
-
- extern int Icon_DragSlider(window_handle window,
- icon_handle baseicon, icon_handle slidericon);
- /* Initiates the drag operation on a slider. Call this when you get a click
- * in either baseicon or slidericon.
- * Returns the new percentage represented by the slider (remember this so
- * you can pass it in to Icon_UpdateSlider to save unnecessary (flickery)
- * update.)
- * NOTE: It is up to you to turn on NULL events and remember that
- * Icon_UpdateSlider must be called on each poll...
- * An alternative is to make the 2 slider icons use button type ALWAYS, and
- * check the mouse button state yourself to see whether a drag needs to be
- * started/continued...
- */
-
- extern int Icon_ReadSlider(window_handle window,
- icon_handle baseicon, icon_handle slidericon);
- /* Given a slider icon-pair, returns a percentage representing the state */
-
-
-
- #endif
-