home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / fli106c / examples / radio.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-25  |  7.9 KB  |  320 lines

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.02
  4. // Copyright (C) 1990, 1991
  5. // Software Dimensions
  6. //
  7. // Dialog Development System
  8. //
  9.  
  10. #include "elements.h"
  11. #include "mask.h"
  12. #include "colors.h"
  13.  
  14. #include <string.h>
  15.  
  16. const layoutContinue=30000;
  17. const layoutCancel=30001;
  18. const layoutButtons=30002;
  19.  
  20. //-------------------------------------------------------------------------
  21. //
  22. // Event handler for the radio button definition dialog
  23. // This dialog defines each button
  24. //
  25. //-------------------------------------------------------------------------
  26.  
  27. int ButtonDialog::EventHandler(int Event)
  28. {
  29.     if (Event==kbEsc ||
  30.             Event==kbCr ||
  31.             Event==CloseEvent ||
  32.             Event==OutsideEvent ||
  33.             Event==layoutContinue ||
  34.             Event==layoutCancel)
  35.         return StopEvent;
  36.     return CompleteEvent;
  37. }
  38.  
  39. //-------------------------------------------------------------------------
  40. //
  41. // Event handler for the *main* radio button definition dialog
  42. // This dialog defines the global characteristics
  43. //
  44. //-------------------------------------------------------------------------
  45.  
  46. int RadioDialog::EventHandler(int Event)
  47. {
  48.     if (Event==kbEsc ||
  49.             Event==kbCr ||
  50.             Event==CloseEvent ||
  51.             Event==OutsideEvent ||
  52.             Event==layoutContinue ||
  53.             Event==layoutCancel)
  54.         return StopEvent;
  55.  
  56.   if (Event==layoutButtons)
  57.   {
  58.     ButtonDialog &Buttons=*new ButtonDialog();
  59.  
  60.     for (int i=0;i<10;i++)
  61.       strcpy(Buttons.RadioButtons[i],RadioButtons[i]);
  62.  
  63.     if (Buttons.GetButtons())
  64.     {
  65.       for (int q=0;q<10;q++)
  66.         RadioButtons[q][0]=0;
  67.  
  68.       for (int i=0,j=0;i<10;i++)
  69.       {
  70.         if (Buttons.RadioButtons[i][0])
  71.           strcpy(RadioButtons[j++],Buttons.RadioButtons[i]);
  72.       }
  73.     }
  74.  
  75.     delete &Buttons;
  76.  
  77.     return CompleteEvent;
  78.   }
  79.  
  80.     return CompleteEvent;
  81. }
  82.  
  83. //-------------------------------------------------------------------------
  84. //
  85. // Show and feed in currently defined buttons
  86. //
  87. //-------------------------------------------------------------------------
  88.  
  89. ButtonDialog::ButtonDialog() :
  90.   DialogClass(48,17,"Button Definitions")
  91. {
  92.   Blaze.Box(1,1,44,12,Colors.DiaInterior);
  93.  
  94.   GroupHeading(16,1,1,"~Radio Buttons",kbAltR);
  95.  
  96.   for (int i=0;i<10;i++)
  97.   {
  98.     RadioButtons[i][0]=0;
  99.     GroupElement(1,new DiaChar(3,2+i,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",RadioButtons[i]));
  100.     Help("Define this radio button");
  101.   }
  102.  
  103.   Element(new DiaPushButton(11,13,"Continue",layoutContinue,0,1));
  104.     Help("Accept these radio buttons");
  105.  
  106.   Element(new DiaPushButton(25,13,"Cancel",layoutCancel));
  107.     Help("Do not accept these radio buttons");
  108. }
  109.  
  110. //-------------------------------------------------------------------------
  111. //
  112. // Get the radio buttons
  113. //
  114. //-------------------------------------------------------------------------
  115.  
  116. int ButtonDialog::GetButtons()
  117. {
  118. DoAgain:
  119.  
  120.     int Save=UseDialog();
  121.  
  122.     if (Save==kbCr || Save==layoutContinue)
  123.   {
  124.     for (int i=0,j=0;i<10;i++)
  125.     {
  126.       if (RadioButtons[i][0])
  127.         j++;
  128.     }
  129.  
  130.     if (!j)
  131.     {
  132.       InfoBox NotValid;
  133.  
  134.       NotValid
  135.         + "You have not defined any radio"
  136.         + "buttons for this element.";
  137.  
  138.       NotValid.Title("Warning");
  139.       NotValid.UseInfoBox();
  140.     }
  141.  
  142.     return 1;
  143.   }
  144.  
  145.   return 0;
  146. }
  147.  
  148. //-------------------------------------------------------------------------
  149. //
  150. // Define the global radio button dialog
  151. //
  152. //-------------------------------------------------------------------------
  153.  
  154. RadioDialog::RadioDialog(int Gp,int Hp,int Sl) :
  155.   DialogClass(78,19,"Radio Specifications")
  156. {
  157.   VariableName[0]=0;
  158.   Prompter[0]=0;
  159.   HotKeyDefine[0]=0;
  160.   DerivedClass[0]=0;
  161.   HelpLine[0]=0;
  162.  
  163.   for (int i=0;i<10;i++)
  164.     RadioButtons[i][0]=0;
  165.  
  166.   Enabled=0;
  167.  
  168.   GroupingCode=Gp;
  169.   HelpScreen=Hp;
  170.   SetForLiving=Sl;
  171.  
  172.   Blaze.Box(1,1,57,7,Colors.DiaInterior);
  173.   Blaze.Box(1,8,57,5,Colors.DiaInterior);
  174.   Blaze.Box(1,13,74,3,Colors.DiaInterior);
  175.  
  176.   GroupHeading(18,1,1,"Element ~Characteristics",kbAltC);
  177.   GroupHeading(17,8,2,"~Derivision Characteristics",kbAltD);
  178.   GroupHeading(30,13,3,"Help/Prompt ~Line",kbAltL);
  179.  
  180.     GroupElement(1,new DiaChar(12,2,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",VariableName));
  181.     Help("Enter the variable name that this element will be placed into");
  182.     HotKey(3,2,"~Variable",kbAltV);
  183.  
  184.     GroupElement(1,new DiaChar(12,4,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",Prompter));
  185.     Help("Enter the prompter to use for this element (~ for hot key)");
  186.     HotKey(3,4,"~Prompter",kbAltP);
  187.  
  188.     GroupElement(1,new DiaChar(11,6,"xxxxxxxxxxxxx",HotKeyDefine));
  189.   Help("Enter the hot key #define to assign to this element (0 for none)");
  190.     HotKey(3,6,"~Hot Key",kbAltH);
  191.  
  192.     GroupElement(1,new DiaInt(39,6,"###",GroupingCode));
  193.   Available(Enabled);
  194.     Help("Enter the group to assign this element to (0 for none)");
  195.     HotKey(25,6,"~Grouping Code",kbAltG);
  196.  
  197.     GroupElement(1,new DiaInt(51,6,"#####",HelpScreen));
  198.     Help("Enter the help screen for this element (0 for none)");
  199.     HotKey(43,6,"~Help Id",kbAltG);
  200.  
  201.   GroupElement(2,new DiaHorizRadio(17,9,SetForLiving,0,0));
  202.   (*this) + "Do Not Derive!" + "Derive a Class";
  203.   Help("Should a derived class be created for this element?");
  204.   HotKey(3,9,"~Derived Class",kbAltD);
  205.  
  206.     GroupElement(2,new DiaChar(19,11,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",DerivedClass));
  207.     Help("Enter the name of the derived class");
  208.     HotKey(3,11,"~Name of Derived",kbAltN);
  209.  
  210.     GroupElement(3,new DiaChar(13,14,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",HelpLine));
  211.     Help("Help that you would like to appear at the bottom of the screen");
  212.     HotKey(3,14,"Help ~Line",kbAltL);
  213.  
  214.     Element(new DiaPushButton(62,4,"~Buttons!",layoutButtons,kbAltB));
  215.     Help("Define the radio buttons");
  216.  
  217.   Element(new DiaPushButton(62,7,"Continue",layoutContinue,0,1));
  218.     Help("Accept this title and continue");
  219.  
  220.   Element(new DiaPushButton(63,10,"Cancel",layoutCancel));
  221.     Help("Do not accept this title");
  222. }
  223.  
  224. //-------------------------------------------------------------------------
  225. //
  226. // Get the global radio button information
  227. //
  228. //-------------------------------------------------------------------------
  229.  
  230. int RadioDialog::GetRadio()
  231. {
  232. DoAgain:
  233.  
  234.     int Save=UseDialog();
  235.  
  236.     if (Save==kbCr || Save==layoutContinue)
  237.   {
  238.     if (!VariableName[0])
  239.     {
  240.       InfoBox NotValid;
  241.  
  242.       NotValid
  243.         + "Sorry, you must define a variable"
  244.         + "name.  This variable name signifies"
  245.         + "where you would like the input"
  246.         + "from this element to go.";
  247.  
  248.       NotValid.Title("Need a Variable");
  249.       NotValid.UseInfoBox();
  250.  
  251.       goto DoAgain;
  252.     }
  253.     if (Prompter[0] && !HotKeyDefine[0])
  254.     {
  255.       InfoBox NotValid;
  256.  
  257.       NotValid
  258.         + "Sorry, if you define a prompter"
  259.         + "you MUST define a hot key to"
  260.         + "accompany it.  Enter a \"0\" in the"
  261.         + "input spot if there isn't one.";
  262.  
  263.       NotValid.Title("Need a Hot Key");
  264.       NotValid.UseInfoBox();
  265.  
  266.       goto DoAgain;
  267.     }
  268.     if (HelpScreen && (HelpScreen<1000 || HelpScreen>32000))
  269.     {
  270.       InfoBox NotValid;
  271.  
  272.       NotValid
  273.         + "Sorry, the help screen that you"
  274.         + "specified is invalid.  It must"
  275.         + "be between 1000 and 32000.";
  276.  
  277.       NotValid.Title("Incorrect Help");
  278.       NotValid.UseInfoBox();
  279.  
  280.       goto DoAgain;
  281.     }
  282.     if (SetForLiving && !DerivedClass[0])
  283.     {
  284.       InfoBox NotValid;
  285.  
  286.       NotValid
  287.         + "Sorry, a name for the derived"
  288.         + "class must be specified.";
  289.  
  290.       NotValid.Title("Missing Derived");
  291.       NotValid.UseInfoBox();
  292.  
  293.       goto DoAgain;
  294.     }
  295.  
  296.     for (int i=0,j=0;i<10;i++)
  297.     {
  298.       if (RadioButtons[i][0])
  299.         j++;
  300.     }
  301.  
  302.     if (!j)
  303.     {
  304.       InfoBox NotValid;
  305.  
  306.       NotValid
  307.         + "You have not defined any radio"
  308.         + "buttons for this element.";
  309.  
  310.       NotValid.Title("No Buttons");
  311.       NotValid.UseInfoBox();
  312.  
  313.       goto DoAgain;
  314.     }
  315.     return 1;
  316.   }
  317.  
  318.   return 0;
  319. }
  320.