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.
- //
- // *************************************************************************
-
- //
- // Example of a DialogueBox
- //
-
- #include "DBox.h"
- #include <kernel.h>
- #include <swis.h>
- #include <string.h>
-
- //
- // define the main program variable
- //
-
- DBox *dbox ;
-
- // ---------------------------------------------------------------------
- // MainWindow class constructor - called when the main window is created
- // ---------------------------------------------------------------------
-
-
- MainWindow::MainWindow (Task *task)
- : Window (task, "main") // template = "main"
- {
- display = new Icon (this, DISPLAY) ; // create the display icon
- }
-
- //
- // MainWindow destructor
- //
-
- MainWindow::~MainWindow()
- {
- delete display ;
- }
-
-
- //
- // This is called when the user clicks in the window outside all Icons.
- //
- // Note that we have not created an Icon object for the ShowBox button
- // but just deal with the click on it here. We could have created
- // an Icon object for it, but it makes the thing more complicated.
- //
-
- void MainWindow::click(int x, int y, int button, int icon)
- {
- if (button & 4 && icon == SHOWBOX) // select on Show Box icon
- {
- ExampleBox box (task) ; // create the dialogue box
- box.show() ; // show it on the screen
- display->print ("Box displayed, sleeping...") ; // print a message
- task->sleep (&box) ; // sleep until box is closed
- if (box.cancelled) // was cancel pressed?
- display->print ("Box cancelled") ; // yes, tell user
- else
- {
- display->print ("Box values are:") ; // begin to print the values at intervals
- task->sleep (100) ; // of 1 second (100 centiseconds)
- display->print ("Port: %s",box.ports[0]?"None":
- box.ports[1]?"Serial":
- box.ports[2]?"Parallel":
- box.ports[3]?"Net":"Unknown") ;
- task->sleep (100) ;
- display->print ("Voice: %s",box.voice) ;
- task->sleep (100) ;
- display->print ("Volume: %d",box.volume) ;
- task->sleep (100) ;
- display->print ("Font Cache: %d",box.font_cache) ;
- task->sleep (100) ;
- display->print ("H Scroll: %d",box.hscroll) ;
- task->sleep (100) ;
- display->print ("V scroll: %d",box.vscroll) ;
- task->sleep (100) ;
- display->print ("Mode: %d",box.screen_mode) ;
- task->sleep (100) ;
- display->print ("") ;
- }
- }
-
- }
-
-
- //
- // The constructor for the example dialogue box
- //
-
- ExampleBox::ExampleBox (Task *task)
- : DialogueBox (task, "dbox", CANCEL, OK)
- {
- //
- // initialise the attribute values
- //
-
- for (int i = 0 ; i < 4 ; i++)
- ports[i] = false ;
- ports[0] = true ; // start at None
- strcpy (voice,"") ;
- volume = 0 ;
- font_cache = 1024 ;
- hscroll = true ;
- vscroll = false ;
- screen_mode = 12 ;
-
- //
- // create the tools
- //
-
- volume_control = new Slider (this, VOLUME_UP, VOLUME_DOWN,VOLUME_VALUE,VOLUME_BACKGROUND,100) ;
- voice_control = new Popup (this, VOICE_DISPLAY,VOICE_MENU, "voice") ;
- font_cache_control = new Adjuster (this, FONTCACHE_UP, FONTCACHE_DOWN, FONTCACHE_VALUE) ;
-
- //
- // tell the dialogue box about the attributes
- //
-
- create_attribute (volume_control, volume) ;
- create_attribute (voice_control, voice) ;
- create_attribute (font_cache_control, font_cache) ;
- create_attribute (4, ports, PORT_NONE, PORT_SERIAL, PORT_PARALLEL, PORT_NET) ;
- create_attribute (HSCROLL, hscroll) ;
- create_attribute (VSCROLL, vscroll) ;
- create_attribute (SCREENMODE, screen_mode) ;
- }
-
-
- //
- // the destructor - just delete any objects we have created
- //
-
-
- ExampleBox::~ExampleBox()
- {
- delete volume_control ;
- delete voice_control ;
- delete font_cache_control ;
- }
-
-
- // ************************************************************************
- // The main task class itself
- // ************************************************************************
-
-
- DBox::DBox()
- : Task ("Dialogue Box Example", "DBox", "!DBox", "iconbar")
- {
- mainwin = new MainWindow (this) ; // create the main window
- }
-
- //
- // icon bar click on our icon
- //
-
- void DBox::click (int x, int y, int button, int icon)
- {
- mainwin->do_open() ; // just open the main window
- }
-
- //
- // menu hit on the iconbar menu
- //
-
-
- void DBox::menu(MenuItem items[])
- {
- switch (items[0])
- {
- case INFO:
- { // need these braces
- ProgramInfo proginfo (this, 4, "1.0 (9 Jan 1996)") ;
- proginfo.show() ;
- sleep (&proginfo) ;
- break ;
- }
- case QUIT:
- exit() ; // exit task (Task::exit())
- break ;
- }
- }
-
-
- main()
- {
- #ifdef __EASY_C
- try
- #endif
- {
- dbox = new DBox() ; // create the task
- dbox->run() ; // run it
- }
- #ifdef __EASY_C
- catch (_kernel_oserror *e)
- {
- _kernel_swi_regs r ;
- r.r[0] = (int)e ;
- r.r[1] = 0 ;
- r.r[2] = (int)"DBox" ;
- _kernel_swi (Wimp_ReportError, &r, &r) ;
- }
-
- catch (char *s)
- {
- _kernel_oserror err ;
- _kernel_swi_regs r ;
- err.errnum = 0 ;
- strcpy (err.errmess, s) ;
- r.r[0] = (int)&err ;
- r.r[1] = 0 ;
- r.r[2] = (int)"DBox" ;
- _kernel_swi (Wimp_ReportError, &r, &r) ;
- }
- #endif
- }
-