home *** CD-ROM | disk | FTP | other *** search
- // **************************************************************************
- // Copyright 1996 David Allison
- //
- // VV VV IIIIII SSSSS TTTTTT AA
- // VV VV II SS TT AA AA
- // VV VV II SSSS TT AA AA
- // VV VV II SS TT AAAAAAAA
- // VV IIIIII SSSS TT AA AA
- //
- // MULTI-THREADED C++ WIMP CLASS LIBRARY
- // for RISC OS
- // **************************************************************************
- //
- // P U B L I C D O M A I N L I C E N C E
- // -------------------------------------------
- //
- // This library is copyright. You may not sell the library for
- // profit, but you may sell products which use it providing
- // those products are presented as executable code and are not
- // libraries themselves. The library is supplied without any
- // warranty and the copyright owner cannot be held responsible for
- // damage resulting from failure of any part of this library.
- //
- // See the User Manual for details of the licence.
- //
- // *************************************************************************
-
- //
- // c.tools
- //
-
-
- #include "Vista:tools.h"
- #include "Vista:window.h"
- #include <kernel.h>
- #include <stdlib.h>
- #include <swis.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdarg.h>
- #include "Vista:task.h"
-
-
- //
- // adjuster arrow tool
- //
-
-
- Adjuster::Adjuster (Window *w, int upicon, int downicon, int valueicon, int write_init, int defvalue)
- :IconSet (4), Icon (w, valueicon)
- {
- add_icon (upicon) ;
- add_icon (downicon) ;
- add_icon (valueicon) ;
- value = defvalue ;
- if (write_init)
- write (defvalue) ;
- }
-
- Adjuster::~Adjuster()
- {
- }
-
- void Adjuster::write (int v)
- {
- value = v ;
- print ("%d",v) ;
- }
-
- int Adjuster::compare (int icon)
- {
- return IconSet::compare(icon) ;
- }
-
-
- void Adjuster::click (int mx, int mt, int button, int icon)
- {
- int up = 0, down = 0 ;
- if (button & 4) // select?
- {
- up = 1 ;
- down = -1 ;
- }
- else if (button & 1) // adjust?
- {
- up = -1 ;
- down = 1 ;
- }
- if (icon == icons[UP])
- write (value+up) ;
- else if (icon == icons[DOWN])
- write (value+down) ;
- }
-
-
- Meter::Meter (Window *w, int backgroundicon, int valueicon, int maxvalue)
- : Icon (w,valueicon)
- {
- _kernel_swi_regs r ;
- _kernel_oserror *e ;
- int block[10] ;
- block[0] = w->handle ;
- block[1] = backgroundicon ;
- r.r[1] = (int)block ;
- if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
- throw (e) ;
- range = block[4] - block[2] ; // x1 - x0
- background_icon = backgroundicon ;
- max_value = maxvalue ;
- reset() ;
- }
-
- //
- // set the meter according to a value
- //
-
- void Meter::write (int v)
- {
- int minx, maxx ; // min and max x coords for redraw
- if (v > max_value)
- v = max_value ;
- if (v <= 0)
- percent = 0 ;
- else
- percent = (v * 100) / max_value ;
- int val = (range * percent) / 100 ;
- // dprintf ("max = %d, v = %d, percent = %d%%, range = %d, val = %d",max_value,v,percent,range,val) ;
- _kernel_swi_regs r ;
- _kernel_oserror *e ;
- int block[10] ;
- block[0] = window->handle ;
- block[1] = handle ; // value icon
- r.r[1] = (int)block ;
- if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
- throw (e) ;
- // calculate the change in coords
- if ((block[2] + val) > xsize) // increasing in size?
- {
- minx = xsize ;
- maxx = block[2] + val ;
- }
- else
- {
- minx = block[2] + val ;
- maxx = xsize ;
- }
- block[4] = block[2] + val ;
- xsize = block[4] ;
- int delblock[2] ;
- delblock[0] = window->handle ;
- delblock[1] = handle ;
- r.r[1] = (int)delblock ;
- if ((e = _kernel_swi (Wimp_DeleteIcon, &r, &r)) != NULL)
- throw (e) ;
- r.r[1] = (int)&block[1] ;
- r.r[0] = handle ;
- block[1] = window->handle ; // set window handle
- if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
- throw (e) ;
-
- //
- // now redraw just the bit that's changed
- //
-
- r.r[0] = window->handle ;
- r.r[1] = minx ;
- r.r[2] = block[3] ;
- r.r[3] = maxx ;
- r.r[4] = block[5] ;
- if ((e = _kernel_swi (Wimp_ForceRedraw, &r, &r)) != NULL)
- throw (e) ;
- }
-
- void Meter::reset()
- {
- write(0) ;
- }
-
- Meter::~Meter()
- {
- }
-
- Slider::Slider (Window *w, int upicon, int downicon, int valueicon,
- int backgroundicon, int maxvalue, int defvalue)
- : Icon (w, valueicon),
- Adjuster (w, upicon, downicon, valueicon, 0, defvalue),
- Meter (w, backgroundicon, valueicon, maxvalue)
- {
- add_icon (backgroundicon) ;
- }
-
-
- void Slider::write (int v)
- {
- if (v < 0)
- v = 0 ;
- if (v > max_value)
- v = max_value ;
- value = v ;
- Meter::write (v) ;
- }
-
- void Slider::click (int mx, int my, int button, int icon)
- {
- if (icon != background_icon && icon != handle)
- Adjuster::click (mx, my, button, icon) ;
- else
- {
- _kernel_swi_regs r ;
- _kernel_oserror *e ;
- int block[10] ;
- int x, p, v ;
- for (;;)
- {
- block[0] = window->handle ;
- block[1] = handle ; // value icon
- r.r[1] = (int)block ;
- if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
- throw (e) ;
- x = mx + (window->scx - window->x0) ;
- p = ((x - block[2]) * 100) / range ; // calc percentage
- v = (p * 100) / max_value ;
- write (v) ;
- r.r[1] = (int)block ;
- if ((e = _kernel_swi (Wimp_GetPointerInfo, &r, &r)) != NULL)
- throw (e) ;
- if (block[2] == 0)
- break ;
- mx = block[0] ;
- }
- }
- }
-
-
- Slider::~Slider()
- {
- }
-
- void Slider::read (int &v)
- {
- v = percent ;
- }
-
-
- Popup::Popup (Window *w, int displayicon, int menuicon, char *menu)
- :IconSet (2), Icon (w, displayicon,0,menu)
- {
- add_icon (displayicon) ;
- add_icon (menuicon) ;
- }
-
- Popup::~Popup()
- {
- }
-
- int Popup::compare (int icon)
- {
- return IconSet::compare(icon) ;
- }
-
- void Popup::menu (MenuItem items[])
- {
- char buf[256] ;
- items[0].read (buf) ;
- print (buf) ;
- }
-
- void Popup::click (int mx, int my, int button, int icon)
- {
- Menu *m = display_menu (mx, my, button, icon) ;
- if (m != NULL)
- window->task->set_menu (m, this) ;
- }
-
-