home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / desklib / examples / DeskLib / Examples / Widget5 / !Widget5 / c / Configure < prev    next >
Encoding:
Text File  |  1995-05-10  |  9.4 KB  |  344 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *        File: Configure.c                                             *
  4.  *                                                                      *
  5.  *     Purpose: Configuration options for program.                      *
  6.  *              Routines to load and save options and display window to *
  7.  *              change options.                                         *
  8.  *                                                                      *
  9.  ************************************************************************/
  10.  
  11. #include "DeskLib:WimpSWIs.h"          /* Low-level WIMP commands         */
  12. #include "DeskLib:Window.h"            /* Window handling automation      */
  13. #include "DeskLib:Core.h"              /* usefull core functions          */
  14. #include "DeskLib:Error.h"             /* Error despatcher                */
  15. #include "DeskLib:Event.h"             /* Event despatcher                */
  16. #include "DeskLib:EventMsg.h"          /* Wimp Message event dispatcher   */
  17. #include "DeskLib:File.h"              /* Low level file handling         */
  18. #include "DeskLib:Msgs.h"              /* Message translation code        */
  19. #include "DeskLib:Resource.h"          /* Handles finding resource files  */
  20. #include "DeskLib:Sound.h"             /* Beep!                           */
  21. #include "DeskLib:Template.h"          /* Template loading and caching    */
  22. #include "DeskLib:Icon.h"              /* Icon handling automation        */
  23. #include "DeskLib:Screen.h"            /* Caching screen info             */
  24. #include "DeskLib:Sprite.h"            /* Sprite handling routines        */
  25. #include "DeskLib:File.h"              /* OS file IO                      */
  26. #include "DeskLib:KeyCodes.h"          /* Codes for wimp returned keys    */
  27. #include "DeskLib:KernelSWIs.h"        /* OS_Byte                         */
  28.  
  29. #include "HackLib:flex.h"              /* Flexable malloc                 */
  30.  
  31. #include "kernel.h"                    /* clib kernel functions           */
  32. #include "MySWIs.h"                    /* SWI no defs                     */
  33. #include "Configure.h"
  34. #include "Misc.h"
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39.  
  40. extern window_handle db;
  41.  
  42. static window_handle configure = NULL;
  43.  
  44. #define size_256x256 0
  45. #define size_512x512 1
  46. extern wimp_point widget4size = 0;
  47.  
  48. extern int destinationbanktype = 0;
  49. extern int graphtype = 0;
  50. extern BOOL fullversion = FALSE;
  51. extern int drawtype = 0;
  52. extern BOOL realtime = FALSE;
  53.  
  54. /* icon numbers for radios */
  55. #define process_MIN 2
  56. #define process_MAX 3
  57.  
  58. #define format_MIN 6
  59. #define format_MAX 7
  60.  
  61. #define graph_MIN 13 /* large graph */
  62. #define graph_MAX 14 /* small graph */
  63.  
  64. #define drawtype_MIN 17
  65. #define drawtype_MID 18
  66. #define drawtype_MAX 19
  67.  
  68. #define icon_REALTIME 22
  69.  
  70. static BOOL Click_configure(event_pollblock *event, void *reference);
  71. static BOOL Close_configure(event_pollblock *event, void *reference);
  72. void close_configure(BOOL ok, BOOL keepopen);
  73. void load_options(void);
  74. void save_options(void);
  75.  
  76. /******************************************************************************
  77.  *                              Click handlers                                *
  78.  ******************************************************************************/
  79.  
  80. static BOOL Click_configure(event_pollblock *event, void *reference)
  81. {
  82.  
  83.   switch(event->data.mouse.icon)
  84.   {
  85.  
  86.     case process_MIN: case process_MAX:
  87.       Icon_Select(configure, event->data.mouse.icon);
  88.       break;
  89.  
  90.     case format_MIN: case format_MAX:
  91.       Icon_Select(configure, event->data.mouse.icon);
  92.       break;
  93.  
  94.     case graph_MIN: case graph_MAX:
  95.       Icon_Select(configure, event->data.mouse.icon);
  96.       break;
  97.  
  98.     case drawtype_MIN: case drawtype_MID: case drawtype_MAX:
  99.       Icon_Select(configure, event->data.mouse.icon);
  100.       break;
  101.  
  102.     case 8: /* Save */
  103.       close_configure(TRUE, event->data.mouse.button.data.adjust);
  104.       save_options();
  105.       break;
  106.  
  107.     case 9: /* Cancel */
  108.       close_configure(FALSE, FALSE);
  109.       break;
  110.  
  111.     case 10: /* Change */
  112.       close_configure(TRUE, event->data.mouse.button.data.adjust);
  113.       break;
  114.       
  115.   }
  116.   return(TRUE);
  117. }
  118.  
  119. /******************************************************************************
  120.  *                                open handlers                               *
  121.  ******************************************************************************/
  122.  
  123. extern void Configure_Open(void)
  124. {
  125.  /*
  126.   * open configure window on screen
  127.   */
  128.  
  129.   if(configure == NULL){
  130.  
  131.     /*
  132.      * create the window
  133.      */
  134.      configure = Window_Create("Configure", template_TITLEMIN);
  135.  
  136.     /*
  137.      * process destination
  138.      */
  139.      Icon_SetRadios(configure, process_MIN, process_MAX, process_MIN+destinationbanktype);
  140.  
  141.  
  142.     /*
  143.      * widget 4 load format
  144.      */
  145.      if( (widget4size.x == 256) && (widget4size.y == 256) )
  146.         Icon_SetRadios(configure, format_MIN, format_MAX, format_MIN);
  147.      else
  148.         Icon_SetRadios(configure, format_MIN, format_MAX, format_MAX);
  149.  
  150.     /*
  151.      * graph size
  152.      */
  153.      Icon_SetRadios(configure, graph_MIN, graph_MAX, graph_MIN + graphtype);
  154.  
  155.     /*
  156.      * drawing greymap type
  157.      */
  158.      Icon_SetRadios(configure, drawtype_MIN, drawtype_MAX, drawtype_MIN + drawtype);
  159.  
  160.     /*
  161.      * real-time updates
  162.      */
  163.      Icon_SetSelect(configure, icon_REALTIME, realtime);
  164.  
  165.     /*
  166.      * install event handlers
  167.      */
  168.      Event_Claim(event_CLICK, configure, event_ANY, Click_configure, NULL);
  169.  
  170.      Event_Claim(event_CLOSE, configure, event_ANY, Close_configure, NULL);
  171.   }
  172.  
  173.   Window_Show(configure, open_WHEREVER);
  174.  
  175. }
  176.  
  177.  
  178. /******************************************************************************
  179.  *                               close handlers                               *
  180.  ******************************************************************************/
  181.  
  182. void close_configure(BOOL ok, BOOL keepopen)
  183. {
  184.  
  185.   if(ok == TRUE){
  186.  
  187.     /*
  188.      * process destination
  189.      */
  190.      destinationbanktype = Icon_WhichRadio(configure,process_MIN,process_MAX)-process_MIN;
  191.  
  192.     /*
  193.      * graph size
  194.      */
  195.      graphtype = Icon_WhichRadio(configure, graph_MIN, graph_MAX) - graph_MIN;
  196.  
  197.     /*
  198.      * draw greymap type
  199.      */
  200.      drawtype = Icon_WhichRadio(configure, drawtype_MIN, drawtype_MAX) - drawtype_MIN;
  201.  
  202.     /*
  203.      * real-time updates
  204.      */
  205.      realtime = Icon_GetSelect(configure, icon_REALTIME);
  206.  
  207.     /*
  208.      * widget 4 load format
  209.      */
  210.      if((Icon_WhichRadio(configure, format_MIN, format_MAX)-format_MIN) == size_256x256){
  211.         widget4size.x = 256;
  212.         widget4size.y = 256;
  213.      }
  214.      else{
  215.         widget4size.x = 512;
  216.         widget4size.y = 512;
  217.      }
  218.  
  219.   }
  220.  
  221.   if(keepopen == FALSE){
  222.  
  223.      Window_Delete(configure);
  224.      configure = NULL;
  225.   }
  226.  
  227. }
  228.  
  229. /******************************************************************************/
  230.  
  231. static BOOL Close_configure(event_pollblock *event, void *reference)
  232. {
  233.   close_configure(FALSE, FALSE);
  234.  
  235.   return(FALSE);
  236. }
  237.  
  238. /******************************************************************************
  239.  *                           menu choice handlers                             *
  240.  ******************************************************************************/
  241.  
  242. /******************************************************************************
  243.  *                            extern routines                                 *
  244.  ******************************************************************************/
  245.  
  246. extern void Configure_Init(void)
  247. {
  248.  /*
  249.   * initialisation to be done on startup
  250.   */
  251.   char buffer[20];
  252.   window_block *block;
  253.  
  254.   load_options();
  255.  
  256.   fullversion = FALSE;
  257.  
  258.   if(OS_ReadVarVal("Widget5$Options", buffer, 20)){
  259.      if(strcmp(buffer, "X") == 0)
  260.         fullversion = TRUE;
  261.   }
  262.  
  263.   /* mod the configure window template to hide the Widget4 file size
  264.    * options if not on full version mode
  265.    */
  266.   if(!fullversion){
  267.  
  268.      block = Template_Find("Configure");
  269.  
  270.      block->screenrect.max.y = block->screenrect.max.y - 188;
  271.      block->scroll.y =  block->scroll.x - 188;
  272.      block->minsize.y = block->minsize.y - 188;
  273.   }
  274. }
  275.  
  276. /******************************************************************************
  277.  *                             misc routines                                  *
  278.  ******************************************************************************/
  279.  
  280. void load_options(void)
  281. {
  282.   char filename[60];
  283.   file_handle channel;
  284.   int temp;
  285.  
  286.   strcpy(filename, resource_pathname);
  287.   strcat(filename, "Choices");
  288.  
  289.   if(File_Exists(filename) == FALSE)
  290.      save_options();
  291.  
  292.   channel = File_Open(filename, file_READ);
  293.  
  294.   destinationbanktype = File_ReadInt(channel);
  295.  
  296.   temp = File_ReadInt(channel);
  297.   if(temp == size_256x256){
  298.      widget4size.x = 256;
  299.      widget4size.y = 256;
  300.   }
  301.   else{
  302.      widget4size.x = 512;
  303.      widget4size.y = 512;
  304.   }
  305.  
  306.   graphtype = File_ReadInt(channel);
  307.  
  308.   drawtype = File_ReadInt(channel);
  309.  
  310.   realtime = File_ReadInt(channel);
  311.  
  312.   File_Close(channel);
  313.  
  314. }
  315.  
  316. void save_options(void)
  317. {
  318.   char filename[60];
  319.   file_handle channel;
  320.  
  321.   strcpy(filename, resource_pathname);
  322.   strcat(filename, "Choices");
  323.  
  324.   channel = File_Open(filename, file_WRITE);
  325.  
  326.   File_WriteInt(channel, destinationbanktype);
  327.  
  328.   if( (widget4size.x == 256) && (widget4size.y == 256) )
  329.      File_WriteInt(channel, size_256x256);
  330.   else
  331.      File_WriteInt(channel, size_512x512);
  332.  
  333.   File_WriteInt(channel, graphtype);
  334.  
  335.   File_WriteInt(channel, drawtype);
  336.  
  337.   File_WriteInt(channel, realtime);
  338.  
  339.   File_Close(channel);
  340.  
  341.   File_SetType(filename, filetype_TEXT);
  342.  
  343. }
  344.