home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / v / vista / c / icon < prev    next >
Text File  |  1996-02-01  |  23KB  |  962 lines

  1. // **************************************************************************
  2. //                     Copyright 1996 David Allison
  3. //
  4. //             VV    VV    IIIIII     SSSSS     TTTTTT       AA
  5. //             VV    VV      II      SS           TT       AA  AA
  6. //             VV    VV      II        SSSS       TT      AA    AA
  7. //              VV  VV       II           SS      TT      AAAAAAAA
  8. //                VV       IIIIII     SSSS        TT      AA    AA
  9. //
  10. //                    MULTI-THREADED C++ WIMP CLASS LIBRARY
  11. //                                for RISC OS
  12. // **************************************************************************
  13. //
  14. //             P U B L I C    D O M A I N    L I C E N C E
  15. //             -------------------------------------------
  16. //
  17. //     This library is copyright. You may not sell the library for
  18. //     profit, but you may sell products which use it providing
  19. //     those products are presented as executable code and are not
  20. //     libraries themselves.  The library is supplied without any
  21. //     warranty and the copyright owner cannot be held responsible for
  22. //     damage resulting from failure of any part of this library.
  23. //
  24. //          See the User Manual for details of the licence.
  25. //
  26. // *************************************************************************
  27.  
  28. //
  29. // c.icon
  30. //
  31.  
  32.  
  33. #include "Vista:icon.h"
  34. #include "Vista:window.h"
  35. #include <kernel.h>
  36. #include <stdlib.h>
  37. #include <swis.h>
  38. #include <string.h>
  39. #include <stdio.h>
  40. #include <stdarg.h>
  41. #include "Vista:task.h"
  42. #include <ctype.h>
  43.  
  44.  
  45. Icon::Icon()       // default constructor
  46.    {
  47.    }
  48.  
  49. Icon::Icon (int priority, int window, int x0, int y0, int x1, int y1, iconflags flags, IconData *data, void *ref)
  50.    {
  51.    _kernel_swi_regs r ;
  52.    _kernel_oserror *e ;
  53.    int icon[9] ;
  54.    r.r[0] = priority ;
  55.    r.r[1] = (int)icon ;
  56.    icon[0] = window ;
  57.    icon[1] = x0 ;
  58.    icon[2] = y0 ;
  59.    icon[3] = x1 ;
  60.    icon[4] = y1 ;
  61.    icon[5] = (int)flags ;
  62.    memcpy (&icon[6], data, sizeof (IconData)) ;
  63.    if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
  64.       throw (e) ;
  65.    delete_wimp_icon = true ;
  66.    window = NULL ;
  67.    handle = r.r[0] ;
  68.    prev = NULL ;
  69.    next = NULL ;
  70.    user_ref = ref ;
  71.    default_menu = NULL ;
  72.    }
  73.  
  74.  
  75. Icon::Icon (Window *w, int iconnum, void *ref, char *menu)
  76.    {
  77.    prev = NULL ;
  78.    next = NULL ;
  79.    user_ref = ref ;
  80.    if (menu == NULL)
  81.       default_menu = NULL ;
  82.    else
  83.       {
  84.       default_menu = w->task->find_menu (menu) ;
  85.       if (default_menu == NULL)
  86.          throw ("Unknown menu") ;
  87.       }
  88.    delete_wimp_icon = false ;
  89.    attach (w,iconnum) ;
  90.    }
  91.  
  92. Icon::~Icon()
  93.    {
  94.    if (window != NULL)
  95.      {
  96.       if (delete_wimp_icon)
  97.          {
  98.          _kernel_swi_regs r ;
  99.          _kernel_oserror *e ;
  100.          int block[2] ;
  101.          r.r[1] = (int)block ;
  102.          block[0] = window->handle ;
  103.          block[1] = handle ;
  104.          if ((e = _kernel_swi (Wimp_DeleteIcon, &r, &r)) != NULL)
  105.             throw (e) ;
  106.          }
  107.       window->remove_icon (this) ;
  108.      }
  109.    }
  110.  
  111. Icon::Icon (Window *w, Icon *temp, Direction direction, int gap, void *ref, char *menu)
  112.    {
  113.    _kernel_swi_regs r ;
  114.    _kernel_oserror *e ;
  115.    int block[40] ;
  116.  
  117.    if (menu == NULL)
  118.       default_menu = NULL ;
  119.    else
  120.       {
  121.       default_menu = w->task->find_menu (menu) ;
  122.       if (default_menu == NULL)
  123.          throw ("Unknown menu") ;
  124.       }
  125.    block[0] = w->handle ;
  126.    block[1] = temp->handle ;
  127.    r.r[1] = (int)block ;
  128.    if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
  129.       throw (e) ;
  130.    int size ;
  131.    Box *box = (Box*)&block[2] ;
  132.    IconData *data = (IconData*)&block[7] ;
  133.    switch (direction)
  134.       {
  135.       case UP:
  136.          size = box->y1 - box->y0 + gap ;
  137.          box->y0 += size ;
  138.          box->y1 += size ;
  139.          break ;
  140.       case DOWN:
  141.          size = box->y1 - box->y0 + gap ;
  142.          box->y0 -= size ;
  143.          box->y1 -= size ;
  144.          break ;
  145.       case LEFT:
  146.          size = box->x1 - box->x0 + gap ;
  147.          box->x0 -= size ;
  148.          box->x1 -= size ;
  149.          break ;
  150.       case RIGHT:
  151.          size = box->x1 - box->x0 + gap ;
  152.          box->x0 += size ;
  153.          box->x1 += size ;
  154.          break ;
  155.       }
  156.    if (block[6] & INDIRECT && block[6] & ITEXT)
  157.       {
  158.       char *p = (char*)malloc (data->indirecttext.bufflen) ;
  159.       if (p == NULL)
  160.          throw ("Out of Memory") ;
  161.       data->indirecttext.buffer = p ;
  162.       p[0] = 0 ;
  163.       }
  164.    block[1] = w->handle ;       // copy window handle to right place
  165.    r.r[1] = (int)&block[1] ;
  166.    if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
  167.       throw (e) ;
  168.    prev = NULL ;
  169.    next = NULL ;
  170.    user_ref = ref ;
  171.    delete_wimp_icon = true ;
  172.    attach (w,r.r[0]) ;
  173.    }
  174.  
  175. Icon::Icon (Window *w, Icon *temp, int x, int y, void *ref, char *menu)
  176.    {
  177.    _kernel_swi_regs r ;
  178.    _kernel_oserror *e ;
  179.    int block[40] ;
  180.  
  181.    if (menu == NULL)
  182.       default_menu = NULL ;
  183.    else
  184.       {
  185.       default_menu = w->task->find_menu (menu) ;
  186.       if (default_menu == NULL)
  187.          throw ("Unknown menu") ;
  188.       }
  189.    block[0] = w->handle ;
  190.    block[1] = temp->handle ;
  191.    r.r[1] = (int)block ;
  192.    if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
  193.       throw (e) ;
  194.    int xsize, ysize ;
  195.    Box *box = (Box*)&block[2] ;
  196.    IconData *data = (IconData*)&block[7] ;
  197.    xsize = box->x1 - box->x0 ;
  198.    ysize = box->y1 - box->y0 ;
  199.    box->x0 = x ;
  200.    box->x1 = box->x0 + xsize ;
  201.    box->y0 = y ;
  202.    box->y1 = box->y0 + ysize ;
  203.    if (block[6] & INDIRECT && block[6] & ITEXT)
  204.       {
  205.       char *p = (char*)malloc (data->indirecttext.bufflen) ;
  206.       if (p == NULL)
  207.          throw ("Out of Memory") ;
  208.       data->indirecttext.buffer = p ;
  209.       p[0] = 0 ;
  210.       }
  211.    block[1] = w->handle ;       // copy window handle to right place
  212.    r.r[1] = (int)&block[1] ;
  213.    if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
  214.       throw (e) ;
  215.    prev = NULL ;
  216.    next = NULL ;
  217.    user_ref = ref ;
  218.    delete_wimp_icon = true ;
  219.    attach (w,r.r[0]) ;
  220.    }
  221.  
  222.  
  223. void Icon::attach (Window *w, int iconnum)
  224.    {
  225.    window = w ;
  226.    handle = iconnum ;
  227.    w->add_icon (this) ;
  228.    }
  229.  
  230. void Icon::move (int dx, int dy)
  231.    {
  232.    _kernel_swi_regs r ;
  233.    _kernel_oserror *e ;
  234.    int block[40] ;
  235.    int delblock[2] ;
  236.  
  237.    block[0] = window->handle ;
  238.    block[1] = handle ;
  239.    r.r[1] = (int)block ;
  240.    if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
  241.       throw (e) ;
  242.    Box *box = (Box*)&block[2] ;
  243.    box->x0 += dx ;
  244.    box->x1 += dx ;
  245.    box->y0 += dy ;
  246.    box->y1 += dy ;
  247.    delblock[0] = window->handle ;
  248.    delblock[1] = handle ;
  249.    r.r[1] = (int)delblock ;
  250.    if ((e = _kernel_swi (Wimp_DeleteIcon, &r, &r)) != NULL)
  251.       throw (e) ;
  252.    r.r[1] = (int)&block[1] ;
  253.    r.r[0] = handle ;
  254.    block[1] = window->handle ;   // set window handle
  255.    if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
  256.       throw (e) ;
  257.    r.r[0] = window->handle ;
  258.    r.r[1] = block[2] ;
  259.    r.r[2] = block[3] ;
  260.    r.r[3] = block[4] ;
  261.    r.r[4] = block[5] ;
  262.    if ((e = _kernel_swi (Wimp_ForceRedraw, &r, &r)) != NULL)
  263.       throw (e) ;
  264.    }
  265.  
  266. void Icon::move (Direction direction, int dist)
  267.    {
  268.    _kernel_swi_regs r ;
  269.    _kernel_oserror *e ;
  270.    int block[40] ;
  271.    int delblock[2] ;
  272.  
  273.    block[0] = window->handle ;
  274.    block[1] = handle ;
  275.    r.r[1] = (int)block ;
  276.    if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
  277.       throw (e) ;
  278.    Box *box = (Box*)&block[2] ;
  279.    switch (direction)
  280.       {
  281.       case UP:
  282.          box->y0 += dist ;
  283.          box->y1 += dist ;
  284.          break ;
  285.       case DOWN:
  286.          box->y0 -= dist ;
  287.          box->y1 -= dist ;
  288.          break ;
  289.       case LEFT:
  290.          box->x0 += dist ;
  291.          box->x1 += dist ;
  292.          break ;
  293.       case RIGHT:
  294.          box->x0 -= dist ;
  295.          box->x1 -= dist ;
  296.          break ;
  297.       }
  298.    delblock[0] = window->handle ;
  299.    delblock[1] = handle ;
  300.    r.r[1] = (int)delblock ;
  301.    if ((e = _kernel_swi (Wimp_DeleteIcon, &r, &r)) != NULL)
  302.       throw (e) ;
  303.    r.r[1] = (int)&block[1] ;
  304.    r.r[0] = handle ;
  305.    block[1] = window->handle ;   // set window handle
  306.    if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
  307.       throw (e) ;
  308.    r.r[0] = window->handle ;
  309.    r.r[1] = block[2] ;
  310.    r.r[2] = block[3] ;
  311.    r.r[3] =