home *** CD-ROM | disk | FTP | other *** search
- <html>
- <title>Icon</title>
- <h1>Icon</h1>
-
- An Icon is an object which represents a WIMP icon. The reason for having a
- separate C++ object is to allow manipulation of the icon by use of C++
- member function calls. It also allows the definition of composite icons
- which appear like a single Icon.
- <p>
- It is <em>not</em> necessary to create an Icon object for every icon in a window. When
- an icon is clicked, the task will invoke a member function for an Icon object
- if the object exists, otherwise the window will be informed of the click.
- <p>
- Two classes are defined here. The Icon itself represents a single icon. The
- IconSet class is used when multiple icons are present and need to be manipulated
- as a single icon.
-
- <h2>Synopsis</h2>
-
- <pre>
-
- class Icon
- {
- friend class Window ;
-
- public:
- enum <a href="file:icon#iconflags">iconflags</a> ;
- enum <a href="file:icon#buttontype">buttontype</a> ;
- enum <a href="file:icon#direction">Direction</a> ;
- enum <a href="file:icon#colourmask">ColourMask</a> ;
- public:
- <a href="file:icon#ct1">Icon</a>(int priority, int window, int x0, int y0, int x1, int y1, iconflags flags, IconData *data,
- void *ref = 0) ;
- <a href="file:icon#ct2">Icon</a>(Window *w, int iconnum = -1, void *ref = 0, char *menu = 0) ;
- <a href="file:icon#ct3">Icon</a>() ;
- <a href="file:icon#ct4">Icon</a>(Window *w,Icon *temp, Direction direction = DOWN, int gap = 0, void *ref = 0, char *menu = 0) ;
- <a href="file:icon#ct5">Icon</a>(Window *w,Icon *temp, int x, int y, void *ref = 0, char *menu = 0) ;
- virtual <a href="file:icon#dt">~Icon</a>() ;
-
- void <a href="file:icon#attach">attach</a> (Window *w, int iconnum) ;
- void <a href="file:icon#move1">move</a> (int dx, int dy) ;
- void <a href="file:icon#move2">move</a> (Direction direction, int dist) ;
- void <a href="file:icon#move_to">move_to</a> (int x, int y) ;
- void <a href="file:icon#resize">resize</a> (int width, int height) ;
- void <a href="file:icon#read_position">read_position</a> (Box &pos) ;
- void <a href="file:icon#plot">plot</a>() ;
- virtual void <a href="file:icon#set_caret">set_caret</a>() ;
- virtual void <a href="file:icon#drag">drag</a> (int mx, int my, int buttons) ;
- virtual void <a href="file:icon#redraw">redraw</a> (int x0, int y0, int x1, int y1) ;
- virtual void <a href="file:icon#click">click</a>(int mx, int my, int button, int icon) ;
- virtual void <a href="file:icon#key">key</a> (int icon, int x, int y, int height, int index, int code) ;
- virtual void <a href="file:icon#select">select</a>() ;
- virtual void <a href="file:icon#unselect">unselect</a>() ;
- virtual void <a href="file:icon#fade">fade</a>() ;
- virtual void <a href="file:icon#unfade">unfade</a>() ;
- virtual void <a href="file:icon#set_fore_colour">set_fore_colour</a> (int colour) ;
- virtual void <a href="file:icon#set_fore_colour">set_back_colour</a> (int colour) ;
- virtual int <a href="file:icon#is_writeable">is_writeable</a>() ;
- virtual int <a href="file:icon#is_selected">is_selected</a>() ;
- virtual void <a href="file:icon#print">print</a> (char *format,...) ;
- virtual void <a href="file:icon#change_sprite">change_sprite</a> (char *sprite_name, int area = 1) ;
- virtual void <a href="file:icon#read_sprite">read_sprite</a> (char *sprite_name) ;
- virtual void <a href="file:icon#reads">read</a> (char *s) ;
- virtual void <a href="file:icon#readi">read</a> (int &n) ;
- virtual void <a href="file:icon#readf">read</a> (float &n) ;
- virtual void <a href="file:icon#readd">read</a> (double &n) ;
- virtual void <a href="file:icon#writes">write</a> (char *s) ;
- virtual void <a href="file:icon#writei">write</a> (int &n) ;
- virtual void <a href="file:icon#writef">write</a> (float &n) ;
- virtual void <a href="file:icon#writed">write</a> (double &n) ;
-
- virtual int <a href="file:icon#compare1">compare</a>(int icon) ;
- virtual int <a href="file:icon#compare2">compare</a> (Icon *icon) ;
-
- Menu *<a href="file:icondisplay_menu">#display_menu</a> (int x, int y, int button, int icon) ;
- virtual void <a href="file:icon#pre_menu">pre_menu</a>(Menu *m, int x, int y, int button, int icon) ;
- virtual char *<a href="file:icon#get_menu">get_menu</a> (int x, int y, int button, int icon) ;
- virtual void <a href="file:icon#menu">menu</a>(MenuItem items[]) ;
- virtual char *<a href="file:icon#help">help</a> (int mx, int my, int buttons) ;
- public:
- int <a href="file:icon#handle">handle</a> ;
- Window *<a href="file:icon#window">window</a> ;
- void *<a href="file:icon#user_ref">user_ref</a> ;
- } ;
-
-
-
- class IconSet
- {
- public:
- IconSet (int num_icons) ;
- ~IconSet() ;
- int compare(int icon) ;
- void add_icon(int icon) ;
- virtual void select (int icon) ;
- virtual void select();
- virtual void fade(int icon) ;
- virtual void fade() ;
- virtual void unselect (int icon) ;
- virtual void unselect();
- virtual void unfade(int icon) ;
- virtual void unfade() ;
- protected:
- int max_icons ;
- int num_icons ;
- int *icons ; // dynamic array
- } ;
-
- </pre>
-
- <h2>Description</h2>
-
- Icons are things in windows which can be clicked and dragged by the user. They consist
- of the above class which is mapped to one or more WIMP icons (referred to by a number).
- You should derive new classes from the base class Icon (or IconSet) when you want an
- icon to do something (like react to a click for example). The function 'click'
- is called when the user clicks on (one of) the WIMP icon(s) in the window. by default,
- the Icon class ignored clicks.
- <p>
- For example, the following Icon is a button which calls the function 'do_compile'
- when the icon is clicked. It is created within a window (called w) and is mapped
- onto an icon number within that window (set up by a template editor).
- <pre>
-
- class Compile : public Icon
- {
- public:
- Compile(Window *w, int icon) ;
- void click(int mx, int my, int button, int icon) ;
- } ;
-
- Compile::Compile(Window *w, int icon) : Icon (w,icon)
- {
- }
-
- void Compile::click(int mx, int my, int button, int icon)
- {
- do_compile() ;
- }
-
- </pre>
-
- <h2>Members</h2>
-
- <p>
- <a name="iconflags"></a>
- <h3>Icon::iconflags</h3>
-
- This enumeration contains the defined flags for an icon.
-
-
- <p>
- <a name="buttontype"></a>
- <h3>Icon::buttontype</h3>
-
- This enumeration contains defintions for the icon button types.
-
-
- <p>
- <a name="direction"></a>
- <h3>Icon::Direction</h3>
-
- This enumeration defines values for the 'direction' parameter for one of
- the constructors.
-
-
- <p>
- <a name="colourmask"></a>
- <h3>Icon::ColourMask</h3>
-
- This enumeration defines values for masking with the icon flags in order
- to set or read the icon colour.
-
-
- <p>
- <a name="ct1"></a>
- <h3>Icon::Icon (int priority, int window, int x0, int y0, int x1, int y1,
- iconflags flags, IconData *data,
- void *ref = 0)</h3>
-
- This constructor create an icon given the raw data as required by Wimp_CreateIcon.
-
-
- <p>
- <a name="ct2"></a>
- <h3>Icon::Icon (Window *w, int iconnum = -1, void *ref = 0)</h3>
-
- This constructor creates an icon in a window. The 'iconnum' parameter is the
- icon number within the window definition.
-
-
- <p>
- <a name="ct3"></a>
- <h3>Icon::Icon()</h3>
-
- This is the default constructor and does nothing.
-
-
- <p>
- <a name="ct4"></a>
- <h3>Icon::Icon (Window *w,Icon *temp, Direction direction = DOWN, int gap = 0, void *ref = 0)</h3>
-
- This constructor creates an icon which is based on an existing icon. It will
- copy the icon passed in 'temp' (for template) and move it either up, down,
- left or right depending on the value of 'direction'. The amount to
- move is given in 'gap' and is on OS units.
-
-
- <p>
- <a name="ct5"></a>
- <h3>Icon::Icon (Window *w,Icon *temp, int x, int y, void *ref = 0)</h3>
-
- This constructor will create a new icon by copying that passed in 'temp' (for
- template) and olace it at the coordinates passed in 'x' and 'y' (both in
- window coordinates).
-
-
- <p>
- <a name="dt"></a>
- <h3>Icon::~Icon()</h3>
-
- The iconic destructor (sounds sinister).
-
-
- <p>
- <a name="attach"></a>
- <h3>Icon::attach (Window *w, int iconnum)</h3>
-
- This is used to attach a new icon to a window.
-
-
- <p>
- <a name="move1"></a>
- <h3>Icon::move (int dx, int dy)</h3>
-
- Move the icon given the deltas 'dx' and 'dy'. The icon is moved the
- appropriate distance and redrawn.
-
-
- <p>
- <a name="move2"></a>
- <h3>Icon::move (Direction direction, int dist)</h3>
-
- Move the icon in a certain direction for a certain distance.
-
-
- <p>
- <a name="move_to"></a>
- <h3>Icon::move_to (int x, int y)</h3>
-
- Move the icon to a certain position in the window. I would have liked to
- call this function 'move' but C++ won't let me.
-
-
- <p>
- <a name="resize"></a>
- <h3>Icon:resize (int width, int height)</h3>
-
- Change the size of the icon. At present this uses the RISC OS 3.1 method
- or resizing by deleting and recreating the icon.
-
-
- <p>
- <a name="read_position"></a>
- <h3>Icon::read_position (Box &pos)</h3>
-
- Read the position of the icon into the 4 word structure passed.
-
-
- <p>
- <a name="plot"></a>
- <h3>Icon::plot()</h3>
-
- Plot the icon using Wimp_PlotIcon.
-
-
- <p>
- <a name="set_caret"></a>
- <h3>Icon::set_caret()</h3>
-
- Set the caret inside the icon. The icon should be writeable.
-
-
- <p>
- <a name="drag"></a>
- <h3>Icon::drag (int mx, int my, int buttons)</h3>
-
- Begin a drag of the icon. The parameters are in OS units.
-
-
- <p>
- <a name="redraw"></a>
- <h3>Icon::redraw (int x0, int y0, int x1, int y1)</h3>
-
- Redraw the icon. The parameters are in window coordinates.
-
-
- <p>
- <a name="click"></a>
- <h3>Icon::click (int mx, int my, int button, int icon)</h3>
-
- The user has clicked on the icon. The coordinates are in window
- coordinates.
-
-
- <p>
- <a name="key"></a>
- <h3>Icon::key (int icon, int x, int y, int height, int index, int code)</h3>
-
- A key has been pressed on the icon.
-
-
- <p>
- <a name="select"></a>
- <h3>Icon::select()</h3>
-
- Select the icon.
-
-
- <p>
- <a name="unselect"></a>
- <h3>Icon::unselect()</h3>
-
- Unselect the icon.
-
-
- <p>
- <a name="fade"></a>
- <h3>Icon::fade()</h3>
-
- Fade the icon.
-
-
- <p>
- <a name="unfade"></a>
- <h3>Icon::unfade()</h3>
-
- Unfade the icon.
-
-
- <p>
- <a name="set_fore_colour"></a>
- <h3>Icon::set_fore_colour(int colour), Icon::set_back_colour(int colour)</h3>
-
- Set the foreground and background colour for the icon.
-
-
- <p>
- <a name="is_writeable"></a>
- <h3>Icon::is_writeable()</h3>
-
- Returns whether the icon is writeable or not. Non-zero means yes.
-
-
- <p>
- <a name="is_selected"></a>
- <h3>Icon::is_selected()</h3>
-
- Returns whether the icon is selected or not. Non-zero means yes.
-
-
- <p>
- <a name="print"></a>
- <h3>Icon::print (char *format...)</h3>
-
- Write a string into the icon. The parameter 'format' is a printf style format
- string and additional parameters contain the values to print. The icon
- must be indirected.
-
-
- <p>
- <a name="change_sprite"></a>
- <h3>Icon::change_sprite (char *sprite_name, int area = 1)</h3>
-
- Change the sprite of an icon to that named. 'area' is the
- sprite area in which the sprite resides, or the WIMP pool
- if it is 1.
-
-
- <p>
- <a name="read_sprite"></a>
- <h3>Icon::read_sprite (char *sprite_name)</h3>
-
- Read the name of the sprite into the buffer passed. The buffer must be
- long enough.
-
-
- <p>
- <a name="reads"></a>
- <h3>Icon::read (char *s)</h3>
-
- Read the contents of the icon into the buffer passed. The buffer must be
- long enough.
-
-
- <p>
- <a name="readi"></a>
- <h3>Icon::read (int &n)</h3>
-
- Read the contents of an icon containing an integer into the variable
- passed.
-
-
- <p>
- <a name="readf"></a>
- <h3>Icon::read (float &n)</h3>
-
- Read the contents of an icon containing a single precision floating
- point number into the variable passed.
-
-
- <p>
- <a name="readd"></a>
- <h3>Icon::read (double &n)</h3>
-
- Read the contents of an icon containing a double precision floating point
- number into the variable passed.
-
-
- <p>
- <a name="writes"></a>
- <h3>Icon::write (char *s)</h3>
-
- Write the string passed into the icon's value. The icon must
- be indirect and the value must be long enough to hold the string.
- long enough.
-
-
- <p>
- <a name="writei"></a>
- <h3>Icon::write (int &n)</h3>
-
- Write an integer into the icon value.
-
-
- <p>
- <a name="writef"></a>
- <h3>Icon::write (float &n)</h3>
-
- Write a single precision floating point number into the icon value.
-
-
- <p>
- <a name="writed"></a>
- <h3>Icon::write (double &n)</h3>
-
- Write a double precision floating point number into the icon value.
-
-
-
- <p>
- <a name="compare1"></a>
- <h3>Icon::compare (int icon)</h3>
-
- Compare the icon number passed with my icon number. Return non-zero if
- a match is found.
-
-
- <p>
- <a name="compare2"></a>
- <h3>Icon::compare (Icon *icon)</h3>
-
- Compare the contents of the icon passed with my contents. Both icons
- must be indirected. The comparison is done by case insensitive
- string comparison. The value returned is the difference between the
- first non matching characters. This allows for sorting icons. The
- value returned is similar to the C library strcmp function except case
- is not taken into account.
-
- <p>
- <a name="display_menu"></a>
- <h3>Icon::display_menu (int x, int y, int button, int icon)</h3>
-
- This function is the same as <a href="file:window#display_menu">Window::display_menu.</a>
- It is called when a menu is to be displayed for an Icon.
-
- <p>
- <a name="pre_menu"></a>
- <h3> Window::pre_menu (Menu *m, int x, int y, int button, int icon)</h3>
-
- This virtual function is called just before a menu is displayed on the
- screen. The purpose is to allow the user to change the contents of the
- menu.
-
-
- <p>
- <a name="get_menu"></a>
- <h3> Window::get_menu (int x, int y, int button, int icon)</h3>
-
- This is called when there was no default menu provided to the constructor.
- It is a virtual function which should be supplied by a derived class
- if it needs to decide on a number of menus. It returns the name
- of the menu to display.
-
- <p>
- <a name="help"></a>
- <h3> Icon::help (int mx, int my, int buttons)</h3>
-
- This function is called when help is being requested. The default
- action is to return NULL, meaning that the icon is not prepared
- to give anything away. Derived classes may provide their own
- help function. The function return a string (char *) which
- is a pointer to the help text.
- <p>
- The function will be called when the mouse is over the Icon.
-
-
- <p>
- <a name="handle"></a>
- <h3>Icon::handle</h3>
-
- This is the WIMP handle for the icon.
-
-
- <p>
- <a name="window"></a>
- <h3>Icon::window</h3>
-
- This is the window to which the icon belongs. NULL means that it is a
- free standing icon.
-
-
- <p>
- <a name="user_ref"></a>
- <h3>Icon::user_ref</h3>
-
- This is a void * pointer holding a user supplied reference for the icon.
-
-