home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / v / vista / Examples / !Dbox / c / dbox
Encoding:
Text File  |  1996-02-01  |  6.7 KB  |  241 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. // Example of a DialogueBox
  30. //
  31.  
  32. #include "DBox.h"
  33. #include <kernel.h>
  34. #include <swis.h>
  35. #include <string.h>
  36.  
  37. //
  38. // define the main program variable
  39. //
  40.  
  41. DBox *dbox ;
  42.  
  43. // ---------------------------------------------------------------------
  44. // MainWindow class constructor - called when the main window is created
  45. // ---------------------------------------------------------------------
  46.  
  47.  
  48. MainWindow::MainWindow (Task *task)
  49.    : Window (task, "main")          // template = "main"
  50.    {
  51.    display = new Icon (this, DISPLAY) ;  // create the display icon
  52.    }
  53.  
  54. //
  55. // MainWindow destructor
  56. //
  57.  
  58. MainWindow::~MainWindow()
  59.    {
  60.    delete display ;
  61.    }
  62.  
  63.  
  64. //
  65. // This is called when the user clicks in the window outside all Icons.
  66. //
  67. // Note that we have not created an Icon object for the ShowBox button
  68. // but just deal with the click on it here.  We could have created
  69. // an Icon object for it, but it makes the thing more complicated.
  70. //
  71.  
  72. void MainWindow::click(int x, int y, int button, int icon)
  73.    {
  74.    if (button & 4 && icon == SHOWBOX)           // select on Show Box icon
  75.       {
  76.       ExampleBox box (task) ;                          // create the dialogue box
  77.       box.show() ;                                     // show it on the screen
  78.       display->print ("Box displayed, sleeping...") ;  // print a message
  79.       task->sleep (&box) ;                             // sleep until box is closed
  80.       if (box.cancelled)                               // was cancel pressed?
  81.          display->print ("Box cancelled") ;            // yes, tell user
  82.       else
  83.          {
  84.          display->print ("Box values are:") ;          // begin to print the values at intervals
  85.          task->sleep (100) ;                           // of 1 second (100 centiseconds)
  86.          display->print ("Port: %s",box.ports[0]?"None":
  87.                                     box.ports[1]?"Serial":
  88.                                     box.ports[2]?"Parallel":
  89.                                     box.ports[3]?"Net":"Unknown") ;
  90.          task->sleep (100) ;
  91.          display->print ("Voice: %s",box.voice) ;
  92.          task->sleep (100) ;
  93.          display->print ("Volume: %d",box.volume) ;
  94.          task->sleep (100) ;
  95.          display->print ("Font Cache: %d",box.font_cache) ;
  96.          task->sleep (100) ;
  97.          display->print ("H Scroll: %d",box.hscroll) ;
  98.          task->sleep (100) ;
  99.          display->print ("V scroll: %d",box.vscroll) ;
  100.          task->sleep (100) ;
  101.          display->print ("Mode: %d",box.screen_mode) ;
  102.          task->sleep (100) ;
  103.          display->print ("") ;
  104.          }
  105.       }
  106.  
  107.    }
  108.  
  109.  
  110. //
  111. // The constructor for the example dialogue box
  112. //
  113.  
  114. ExampleBox::ExampleBox (Task *task)
  115.    : DialogueBox (task, "dbox", CANCEL, OK)
  116.    {
  117. //
  118. // initialise the attribute values
  119. //
  120.  
  121.    for (int i = 0 ; i < 4 ; i++)
  122.       ports[i] = false ;
  123.    ports[0] = true ;              // start at None
  124.    strcpy (voice,"") ;
  125.    volume = 0 ;
  126.    font_cache = 1024 ;
  127.    hscroll = true ;
  128.    vscroll = false ;
  129.    screen_mode = 12 ;
  130.  
  131. //
  132. // create the tools
  133. //
  134.  
  135.    volume_control = new Slider (this, VOLUME_UP, VOLUME_DOWN,VOLUME_VALUE,VOLUME_BACKGROUND,100) ;
  136.    voice_control = new Popup (this, VOICE_DISPLAY,VOICE_MENU, "voice") ;
  137.    font_cache_control = new Adjuster (this, FONTCACHE_UP, FONTCACHE_DOWN, FONTCACHE_VALUE) ;
  138.  
  139. //
  140. // tell the dialogue box about the attributes
  141. //
  142.  
  143.    create_attribute (volume_control, volume) ;
  144.    create_attribute (voice_control, voice) ;
  145.    create_attribute (font_cache_control, font_cache) ;
  146.    create_attribute (4, ports, PORT_NONE, PORT_SERIAL, PORT_PARALLEL, PORT_NET) ;
  147.    create_attribute (HSCROLL, hscroll) ;
  148.    create_attribute (VSCROLL, vscroll) ;
  149.    create_attribute (SCREENMODE, screen_mode) ;
  150.    }
  151.  
  152.  
  153. //
  154. // the destructor - just delete any objects we have created
  155. //
  156.  
  157.  
  158. ExampleBox::~ExampleBox()
  159.    {
  160.    delete volume_control ;
  161.    delete voice_control ;
  162.    delete font_cache_control ;
  163.    }
  164.  
  165.  
  166. // ************************************************************************
  167. // The main task class itself
  168. // ************************************************************************
  169.  
  170.  
  171. DBox::DBox()
  172.    : Task ("Dialogue Box Example", "DBox", "!DBox", "iconbar")
  173.    {
  174.    mainwin = new MainWindow (this) ;            // create the main window
  175.    }
  176.  
  177. //
  178. // icon bar click on our icon
  179. //
  180.  
  181. void DBox::click (int x, int y, int button, int icon)
  182.     {
  183.     mainwin->do_open() ;           // just open the main window
  184.     }
  185.  
  186. //
  187. // menu hit on the iconbar menu
  188. //
  189.  
  190.  
  191. void DBox::menu(MenuItem items[])
  192.    {
  193.    switch (items[0])
  194.       {
  195.       case INFO:
  196.          {                          // need these braces
  197.          ProgramInfo proginfo (this, 4, "1.0 (9 Jan 1996)") ;
  198.          proginfo.show() ;
  199.          sleep (&proginfo) ;
  200.          break ;
  201.          }
  202.       case QUIT:
  203.          exit() ;             // exit task (Task::exit())
  204.          break ;
  205.       }
  206.    }
  207.  
  208.  
  209. main()
  210.    {
  211. #ifdef __EASY_C
  212.    try
  213. #endif
  214.       {
  215.       dbox = new DBox() ;           // create the task
  216.       dbox->run() ;                   // run it
  217.       }
  218. #ifdef __EASY_C
  219.    catch (_kernel_oserror *e)
  220.       {
  221.       _kernel_swi_regs r ;
  222.       r.r[0] = (int)e ;
  223.       r.r[1] = 0 ;
  224.       r.r[2] = (int)"DBox" ;
  225.       _kernel_swi (Wimp_ReportError, &r, &r) ;
  226.       }
  227.  
  228.    catch (char *s)
  229.       {
  230.       _kernel_oserror err ;
  231.       _kernel_swi_regs r ;
  232.       err.errnum = 0 ;
  233.       strcpy (err.errmess, s) ;
  234.       r.r[0] = (int)&err ;
  235.       r.r[1] = 0 ;
  236.       r.r[2] = (int)"DBox" ;
  237.       _kernel_swi (Wimp_ReportError, &r, &r) ;
  238.       }
  239. #endif
  240.    }
  241.