home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / fli106c / examples / generate.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-25  |  26.8 KB  |  896 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 "fliwin.h"
  11. #include "colors.h"
  12. #include "dds.h"
  13.  
  14. #include <stdio.h>
  15. #include <dos.h>
  16. #include <string.h>
  17.  
  18. // These are defined in DDS.CPP
  19.  
  20. extern int OverrideBlaze;
  21. extern int OmitComments;
  22.  
  23. //-------------------------------------------------------------------------
  24. //
  25. // Code Generator
  26. //
  27. //-------------------------------------------------------------------------
  28.  
  29. void DialogWindow::Generate(char *GenTo)
  30. {
  31.   //-------------------------------------------------------------------------
  32.   //
  33.   // Open the file for output
  34.   //
  35.   //-------------------------------------------------------------------------
  36.  
  37.   FILE *Output;
  38.  
  39.   Output=fopen(GenTo,"w+t");
  40.  
  41.   //-------------------------------------------------------------------------
  42.   //
  43.   // Pump out header lines
  44.   //
  45.   //-------------------------------------------------------------------------
  46.  
  47.   fputs(
  48.     "// Fusion Library Interface\n"
  49.     "// Dialog Development System Automated Code Generation\n"
  50.     "// Contents Copyright (C) 1991 by Software Dimensions\n"
  51.     "//\n",Output);
  52.  
  53.   if (!OmitComments)
  54.   {
  55.     fputs(
  56.     "// Usage instructions can be found at the bottom of this file\n",Output);
  57.   }
  58.  
  59.   fputs(
  60.     "// Includes (elements.h automatically includes fli.h/defines.h)\n\n"
  61.     "#include \"elements.h\"\n",Output);
  62.  
  63.   if (OverrideBlaze)
  64.     fputs("#include \"colors.h\"\n\n",Output);
  65.   else
  66.     fputs("\n",Output);
  67.  
  68.   //-------------------------------------------------------------------------
  69.   //
  70.   // Derive a class for our dialog and variables
  71.   //
  72.   //-------------------------------------------------------------------------
  73.  
  74.   fputs("// Class definition (you can copy this to a header file)\n\n",Output);
  75.  
  76.   if (DerivedClass[0] && DerivedClass)
  77.   {
  78.     fprintf(Output,"class %s : public DialogClass\n"
  79.       "{\n"
  80.       "  public:\n"
  81.       "    %s();\n"
  82.       "    int EventHandler(int);\n",DerivedClass,DerivedClass);
  83.   }
  84.   else
  85.   {
  86.     fputs("class Generate : public DialogClass\n"
  87.       "{\n"
  88.       "  public:\n"
  89.       "    Generate();\n"
  90.       "    int EventHandler(int);\n",Output);
  91.   }
  92.  
  93.   //-------------------------------------------------------------------------
  94.   //
  95.   // Stick any defined dialog variables into the class
  96.   //
  97.   //-------------------------------------------------------------------------
  98.  
  99.   if (NumberPieces)
  100.   {
  101.     for (int i=0,TrackIt=0;i<NumberPieces;i++)
  102.     {
  103.       PieceHandler &Piece=*Pieces[i];
  104.       if (Piece.LayOut>PieceHandler::__DUMMY__ && Piece.LayOut<PieceHandler::Push)
  105.       {
  106.         if (!TrackIt)
  107.         {
  108.           fputs("\n"
  109.             "    // Variable definitions\n"
  110.             "\n",Output);
  111.           TrackIt++;
  112.         }
  113.         switch(Piece.LayOut)
  114.         {
  115.           case PieceHandler::Character:
  116.             fprintf(Output,"    char %s[%d];\n",Piece.Variable,
  117.               strlen(Piece.Mask)+1);
  118.             break;
  119.           case PieceHandler::Integer:
  120.           case PieceHandler::VRadio:
  121.           case PieceHandler::HRadio:
  122.           case PieceHandler::Check:
  123.             fprintf(Output,"    int %s;\n",Piece.Variable);
  124.             break;
  125.           case PieceHandler::Long:
  126.             fprintf(Output,"    long %s;\n",Piece.Variable);
  127.             break;
  128.           case PieceHandler::Float:
  129.             fprintf(Output,"    float %s;\n",Piece.Variable);
  130.             break;
  131.           case PieceHandler::Double:
  132.             fprintf(Output,"    double %s;\n",Piece.Variable);
  133.             break;
  134.           case PieceHandler::Bcd:
  135.             fprintf(Output,"    bcd %s;\n",Piece.Variable);
  136.             break;
  137.         }
  138.       }
  139.     }
  140.   }
  141.  
  142.   fputs("};\n\n",Output);
  143.  
  144.   //-------------------------------------------------------------------------
  145.   //
  146.   // Generate the derived classes
  147.   //
  148.   //-------------------------------------------------------------------------
  149.  
  150.   if (NumberPieces)
  151.   {
  152.     for (int i=0,TrackIt=0;i<NumberPieces;i++)
  153.     {
  154.       PieceHandler &Piece=*Pieces[i];
  155.       if (Piece.LayOut>PieceHandler::__DUMMY__ &&
  156.         Piece.LayOut<PieceHandler::__DUMMY2__ &&
  157.         Piece.ToBeDerived)
  158.       {
  159.         if (!TrackIt)
  160.         {
  161.           fputs("// Declare derived classes (you can copy these into a header file)\n\n",Output);
  162.           TrackIt++;
  163.         }
  164.  
  165.         char ClassName[50];
  166.  
  167.         switch(Piece.LayOut)
  168.         {
  169.           case PieceHandler::Character:
  170.             strcpy(ClassName,"DiaChar");
  171.             break;
  172.  
  173.           case PieceHandler::Integer:
  174.             strcpy(ClassName,"DiaInt");
  175.             break;
  176.  
  177.           case PieceHandler::Long:
  178.             strcpy(ClassName,"DiaLong");
  179.             break;
  180.  
  181.           case PieceHandler::Float:
  182.             strcpy(ClassName,"DiaFloat");
  183.             break;
  184.  
  185.           case PieceHandler::Double:
  186.             strcpy(ClassName,"DiaDouble");
  187.             break;
  188.  
  189.           case PieceHandler::Bcd:
  190.             strcpy(ClassName,"DiaBcd");
  191.             break;
  192.  
  193.           case PieceHandler::Push:
  194.             strcpy(ClassName,"DiaPushButton");
  195.             break;
  196.  
  197.           case PieceHandler::Check:
  198.             strcpy(ClassName,"DiaCheckBox");
  199.             break;
  200.  
  201.           case PieceHandler::VRadio:
  202.             strcpy(ClassName,"DiaVertRadio");
  203.             break;
  204.  
  205.           case PieceHandler::HRadio:
  206.             strcpy(ClassName,"DiaHorizRadio");
  207.             break;
  208.  
  209.           case PieceHandler::PickGeneric:
  210.             strcpy(ClassName,"DiaPickGeneric");
  211.             break;
  212.         }
  213.  
  214.         fprintf(Output,"class %s : public %s\n"
  215.           "{\n"
  216.           "public:\n",Piece.DerivedClass,ClassName);
  217.  
  218.         switch(Piece.LayOut)
  219.         {
  220.           case PieceHandler::Character:
  221.             fprintf(Output,"  %s(int X,int Y,char *Mask,char *Value,int Visual=0,int MChar=0,\n"
  222.               "      int MWidth=0) :\n"
  223.               "    DiaChar(X,Y,Mask,Value,Visual,MChar,MWidth) { };\n",Piece.DerivedClass);
  224.             break;
  225.  
  226.           case PieceHandler::Integer:
  227.             fprintf(Output,"  %s(int X,int Y,char *Mask,int &Value) :\n"
  228.               "    DiaInt(X,Y,Mask,Value) { };\n",Piece.DerivedClass);
  229.             break;
  230.  
  231.           case PieceHandler::Long:
  232.             fprintf(Output,"  %s(int X,int Y,char *Mask,long &Value) :\n"
  233.               "    DiaLong(X,Y,Mask,Value) { };\n",Piece.DerivedClass);
  234.             break;
  235.  
  236.           case PieceHandler::Float:
  237.             fprintf(Output,"  %s(int X,int Y,char *Mask,float &Value) :\n"
  238.               "    DiaFloat(X,Y,Mask,Value) { };\n",Piece.DerivedClass);
  239.             break;
  240.  
  241.           case PieceHandler::Double:
  242.             fprintf(Output,"  %s(int X,int Y,char *Mask,double &Value) :\n"
  243.               "    DiaDouble(X,Y,Mask,Value) { };\n",Piece.DerivedClass);
  244.             break;
  245.  
  246.           case PieceHandler::Bcd:
  247.             fprintf(Output,"  %s(int X,int Y,char *Mask,bcd &Value) :\n"
  248.               "    DiaBcd(X,Y,Mask,Value) { };\n",Piece.DerivedClass);
  249.             break;
  250.  
  251.           case PieceHandler::Push:
  252.             fprintf(Output,"  %s(int X,int Y,char *Text,int Event,int Key=0) :\n"
  253.               "    DiaPushButton(X,Y,Text,Event,Key) { };\n",Piece.DerivedClass);
  254.             break;
  255.  
  256.           case PieceHandler::Check:
  257.             fprintf(Output,"  %s(int X,int Y,int &Checked,char *Text,int Key=0) :\n"
  258.               "    DiaCheckBox(X,Y,Checked,Text,Key) { };\n",Piece.DerivedClass);
  259.             break;
  260.  
  261.           case PieceHandler::HRadio:
  262.             fprintf(Output,"  %s(int X,int Y,int &Button,int Items,char **Choices) :\n"
  263.               "    DiaHorizRadio(X,Y,Button,Items,Choices) { };\n",Piece.DerivedClass);
  264.             break;
  265.  
  266.           case PieceHandler::VRadio:
  267.             fprintf(Output,"  %s(int X,int Y,int &Button,int Items,char **Choices) :\n"
  268.               "    DiaVertRadio(X,Y,Button,Items,Choices) { };\n",Piece.DerivedClass);
  269.             break;
  270.  
  271.           case PieceHandler::PickGeneric:
  272.             fprintf(Output,"  int Item;\n"
  273.               "  int ItemCount;\n\n"
  274.               "  %s() :\n"
  275.               "    DiaPickGeneric(%d,%d,%d,%d,Item,ItemCount)\n"
  276.               "  {\n"
  277.               "    // Define other items in this constructor *or*\n"
  278.               "    // set the ITEM or ITEMCOUNT to another location\n"
  279.               "    Item=0;\n"
  280.               "    ItemCount=0;\n"
  281.               "  };\n\n"
  282.               "  // Take the GetItem function and fill it with your own code.\n\n"
  283.               "  char *GetItem(int ItemNumber);\n\n",Piece.DerivedClass,
  284.                 Piece.X,Piece.Y,Piece.Width-3,Piece.Height);
  285.             break;
  286.         }
  287.         fputs("  // **Add living functions here\n};\n"
  288.           "\n",Output);
  289.       }
  290.     }
  291.   }
  292.  
  293.   //-------------------------------------------------------------------------
  294.   //
  295.   // Generate the constants for the push buttons
  296.   //
  297.   //-------------------------------------------------------------------------
  298.  
  299.   if (NumberPieces)
  300.   {
  301.     for (int i=0,TrackIt=0;i<NumberPieces;i++)
  302.     {
  303.       PieceHandler &Piece=*Pieces[i];
  304.       if (Piece.LayOut==PieceHandler::Push)
  305.       {
  306.         if (!TrackIt)
  307.         {
  308.           fputs("// Constants (for Push Buttons)\n"
  309.             "\n",Output);
  310.           TrackIt++;
  311.         }
  312.         fprintf(Output,"const %s=%d;\n",Piece.Constant,Piece.HelpId);
  313.       }
  314.     }
  315.     if (TrackIt)
  316.       fputs("\n",Output);
  317.   }
  318.  
  319.   //-------------------------------------------------------------------------
  320.   //
  321.   // Generate the event handler
  322.   //
  323.   //-------------------------------------------------------------------------
  324.  
  325.   fputs("// Event handler\n\n",Output);
  326.  
  327.   fprintf(Output,
  328.     "int %s::EventHandler(int Event)\n"
  329.     "{\n"
  330.     "  switch(Event)\n"
  331.     "  {\n"
  332.     "    case kbEsc:\n"
  333.     "    case kbCr:\n"
  334.     "    case CloseEvent:\n"
  335.     "    case OutsideEvent:\n"
  336.     "      return StopEvent;\n"
  337.     ,(DerivedClass[0])?DerivedClass:"Generate");
  338.  
  339.   //-------------------------------------------------------------------------
  340.   //
  341.   // If there are push buttons, place the case constants inside
  342.   // the event handler
  343.   //
  344.   //-------------------------------------------------------------------------
  345.  
  346.   if (NumberPieces)
  347.   {
  348.     for (int i=0,TrackIt=0;i<NumberPieces;i++)
  349.     {
  350.       PieceHandler &Piece=*Pieces[i];
  351.       if (Piece.LayOut==PieceHandler::Push)
  352.       {
  353.         if (!TrackIt)
  354.         {
  355.           fputs("\n    // Cases (for Push Buttons)\n"
  356.                 "    // **Change to suit your needs\n\n",Output);
  357.           TrackIt++;
  358.         }
  359.         fprintf(Output,"    case %s:\n"
  360.           "      return StopEvent;\n",Piece.Constant);
  361.       }
  362.     }
  363.   }
  364.  
  365.   fputs("  }\n"
  366.     "  return CompleteEvent;\n"
  367.     "}\n\n"
  368.     "// Constructor (defines your dialog)\n\n",Output);
  369.  
  370.   //-------------------------------------------------------------------------
  371.   //
  372.   // Generate the constructor
  373.   //
  374.   //-------------------------------------------------------------------------
  375.  
  376.   fprintf(Output,
  377.     "%s::%s() : DialogClass(%d,%d,\"%s\")\n"
  378.     "{\n\n",(DerivedClass[0])?DerivedClass:"Generate",
  379.     (DerivedClass[0])?DerivedClass:"Generate",
  380.     Width,Height,Title);
  381.  
  382.   //-------------------------------------------------------------------------
  383.   //
  384.   // initialize any defined dialog variables
  385.   //
  386.   //-------------------------------------------------------------------------
  387.  
  388.   if (NumberPieces)
  389.   {
  390.     for (int i=0,TrackIt=0;i<NumberPieces;i++)
  391.     {
  392.       PieceHandler &Piece=*Pieces[i];
  393.       if (Piece.LayOut>PieceHandler::__DUMMY__ && Piece.LayOut<PieceHandler::Push)
  394.       {
  395.         if (!TrackIt)
  396.         {
  397.           fputs("  // Initialize Variables\n"
  398.             "\n",Output);
  399.           TrackIt++;
  400.         }
  401.         switch(Piece.LayOut)
  402.         {
  403.           case PieceHandler::Character:
  404.             fprintf(Output,"  %s[0]=0;\n",Piece.Variable);
  405.             break;
  406.           case PieceHandler::Integer:
  407.           case PieceHandler::VRadio:
  408.           case PieceHandler::HRadio:
  409.           case PieceHandler::Check:
  410.           case PieceHandler::Long:
  411.           case PieceHandler::Float:
  412.           case PieceHandler::Double:
  413.           case PieceHandler::Bcd:
  414.             fprintf(Output,"  %s=0;\n",Piece.Variable);
  415.             break;
  416.         }
  417.       }
  418.     }
  419.     if (TrackIt)
  420.     {
  421.       fputs("\n",Output);
  422.     }
  423.   }
  424.  
  425.   //-------------------------------------------------------------------------
  426.   //
  427.   // Output Blaze Drawing Code (not Text)
  428.   //
  429.   //-------------------------------------------------------------------------
  430.  
  431.   int MouseHidden=0; // Was mouse hidden
  432.  
  433.   if (NumberPieces)
  434.   {
  435.     for (int i=0,TrackIt=0;i<NumberPieces;i++)
  436.     {
  437.       PieceHandler &Piece=*Pieces[i];
  438.       if (Piece.LayOut<PieceHandler::__DUMMY__)
  439.       {
  440.         if (!TrackIt)
  441.         {
  442.           fputs("  // Display blaze objects\n\n"
  443.             "  MouseHide(); // Hide the mouse\n\n",Output);
  444.           MouseHidden++;
  445.           TrackIt++;
  446.         }
  447.         switch(Piece.LayOut)
  448.         {
  449.           case PieceHandler::Box:
  450.             fprintf(Output,
  451.               (!OverrideBlaze)?
  452.               "  Blaze.Box(%d,%d,%d,%d,%d);\n":
  453.               "  Blaze.Box(%d,%d,%d,%d,Colors.DiaInterior);\n",
  454.               Piece.X,Piece.Y,Piece.Width,Piece.Height,Piece.Color);
  455.             break;
  456.  
  457.           case PieceHandler::FilledBox:
  458.             fprintf(Output,
  459.               (!OverrideBlaze)?
  460.               "  Blaze.BoxFilled(%d,%d,%d,%d,%d);\n":
  461.               "  Blaze.BoxFilled(%d,%d,%d,%d,Colors.DiaInterior);\n",
  462.               Piece.X,Piece.Y,Piece.Width,Piece.Height,Piece.Color);
  463.             break;
  464.  
  465.           case PieceHandler::HorizontalLine:
  466.             fprintf(Output,
  467.               (!OverrideBlaze)?
  468.               "  Blaze.CharacterRepeater(%d,%d,%d,%d,196);\n":
  469.               "  Blaze.CharacterRepeater(%d,%d,%d,Colors.DiaInterior,196);\n",
  470.               Piece.X,Piece.Y,Piece.Width,Piece.Color);
  471.             break;
  472.  
  473.           case PieceHandler::VerticalLine:
  474.             fprintf(Output,
  475.               (!OverrideBlaze)?
  476.               "  Blaze.CharacterRepeaterDown(%d,%d,%d,%d,179);\n":
  477.               "  Blaze.CharacterRepeaterDown(%d,%d,%d,Colors.DiaInterior,179);\n",
  478.               Piece.X,Piece.Y,Piece.Height,Piece.Color);
  479.             break;
  480.  
  481.           case PieceHandler::Shadow:
  482.             fprintf(Output,"  Blaze.Shadow(%d,%d,%d,%d);\n",
  483.               Piece.X,Piece.Y,Piece.Width,Piece.Height);
  484.             break;
  485.  
  486.           case PieceHandler::EraseArea:
  487.             fprintf(Output,
  488.               (!OverrideBlaze)?
  489.               "  Blaze.EraseArea(%d,%d,%d,%d,%d);\n":
  490.               "  Blaze.EraseArea(%d,%d,%d,%d,Colors.DiaInterior);\n",
  491.               Piece.X,Piece.Y,Piece.Width,Piece.Height,Piece.Color);
  492.             break;
  493.  
  494.           case PieceHandler::ColorizeArea:
  495.             fprintf(Output,
  496.               (!OverrideBlaze)?
  497.               "  Blaze.BoxAttribute(%d,%d,%d,%d,%d);\n":
  498.               "  Blaze.BoxAttribute(%d,%d,%d,%d,Colors.DiaInterior);\n",
  499.               Piece.X,Piece.Y,Piece.Width,Piece.Height,Piece.Color);
  500.             break;
  501.         }
  502.       }
  503.     }
  504.     if (TrackIt)
  505.     {
  506.       fputs("\n",Output);
  507.     }
  508.   }
  509.  
  510.   //-------------------------------------------------------------------------
  511.   //
  512.   // Output Optimized Blaze Text Code
  513.   //
  514.   // Although this segment of code is extremely short, it does a lot!
  515.   //
  516.   // The Blaze optimizer is designed to scan the screen and generate the
  517.   // cooresponding Blaze commands.  If two blocks are side by side and
  518.   // are the same color, the optimizer will not reposition the cursor.  If
  519.   // the color is the same for two consecutive blocks, the color will not
  520.   // be reloaded.  Both of these optimizations are designed to reduce the
  521.   // amount of code that is required and also to make the code easy to read.
  522.   //
  523.   //-------------------------------------------------------------------------
  524.  
  525.   int BlazeOverriden=0; // was blaze overriden?
  526.  
  527.   #define DumpString \
  528.     if (!TrackIt) \
  529.     { \
  530.       fputs("  // Display blaze text\n\n",Output); \
  531.       if (!MouseHidden) \
  532.       { \
  533.         MouseHidden++; \
  534.         fputs("  MouseHide(); // Hide the mouse\n\n",Output); \
  535.       } \
  536.       TrackIt++; \
  537.     } \
  538.     if (!OverrideBlaze) \
  539.     { \
  540.       if (SideBySide && PreviousColor!=ColorStore) \
  541.         fprintf(Output,"  Blaze << %d << \"%s\";\n",ColorStore,Storage); \
  542.       else if (SideBySide && PreviousColor==ColorStore) \
  543.         fprintf(Output,"  Blaze << \"%s\";\n",Storage); \
  544.       else if (CurrentLocation && PreviousColor!=ColorStore) \
  545.         fprintf(Output,"  Blaze (%d,%d) << %d << \"%s\";\n",XStart,y,ColorStore,Storage); \
  546.       else \
  547.         fprintf(Output,"  Blaze (%d,%d) << \"%s\";\n",XStart,y,Storage); \
  548.       Storage[0]=0; \
  549.     }  \
  550.     else \
  551.     { \
  552.       if (SideBySide && !BlazeOverriden) \
  553.         fprintf(Output,"  Blaze << Colors.DiaInterior << \"%s\";\n",Storage); \
  554.       else if (SideBySide && BlazeOverriden) \
  555.         fprintf(Output,"  Blaze << \"%s\";\n",Storage); \
  556.       else if (CurrentLocation && !BlazeOverriden) \
  557.         fprintf(Output,"  Blaze (%d,%d) << Colors.DiaInterior << \"%s\";\n",XStart,y,Storage); \
  558.       else \
  559.         fprintf(Output,"  Blaze (%d,%d) << \"%s\";\n",XStart,y,Storage); \
  560.       BlazeOverriden++; \
  561.       Storage[0]=0; \
  562.     }
  563.  
  564.   #define ControlIntercept \
  565.     if (*OutPut<32) \
  566.     { \
  567.       char Intercept[10]; \
  568.       sprintf(Intercept,"\\x%x",*OutPut); \
  569.       strcat(Storage,Intercept); \
  570.       CurrentLocation=strlen(Storage); \
  571.     } \
  572.     else \
  573.     { \
  574.       Storage[CurrentLocation++]=*OutPut; \
  575.       Storage[CurrentLocation]=0; \
  576.     }
  577.  
  578.   int PreviousColor=0; // previous color
  579.   int ColorStore=0; // current color
  580.  
  581.   int TrackIt=0;
  582.  
  583.   for (int y=0;y<Height-2;y++)
  584.   {
  585.     char *OutPut=Interior[y];
  586.  
  587.     char Storage[300] = "\0";
  588.  
  589.     int CurrentLocation=0;
  590.     int XStart=0;
  591.     int SideBySide=0;
  592.  
  593.     for (int x=0;x<Width-2;x++,OutPut+=2)
  594.     {
  595.       if (*OutPut)
  596.       {
  597.         if (CurrentLocation)
  598.         {
  599.           if (*(OutPut+1)!=ColorStore)
  600.           {
  601.             DumpString;
  602.             PreviousColor=ColorStore;
  603.             ColorStore=*(OutPut+1);
  604.             SideBySide=1;
  605.             CurrentLocation=0;
  606.             XStart=x;
  607.           }
  608.           ControlIntercept;
  609.         }
  610.         else
  611.         {
  612.           PreviousColor=ColorStore;
  613.           ColorStore=*(OutPut+1);
  614.           ControlIntercept;
  615.           SideBySide=0;
  616.           XStart=x;
  617.         }
  618.       }
  619.       else
  620.       {
  621.         if (CurrentLocation)
  622.         {
  623.           DumpString;
  624.           CurrentLocation=0;
  625.           SideBySide=0;
  626.         }
  627.       }
  628.     }
  629.     if (CurrentLocation)
  630.     {
  631.       DumpString;
  632.     }
  633.   }
  634.  
  635.   if (TrackIt)
  636.   {
  637.     fputs("\n",Output);
  638.   }
  639.  
  640.   if (MouseHidden)
  641.   {
  642.     fputs("  MouseShow(); // Restore the mouse\n\n",Output);
  643.   }
  644.  
  645.   //-------------------------------------------------------------------------
  646.   //
  647.   // Output Group Headings
  648.   //
  649.   //-------------------------------------------------------------------------
  650.  
  651.   if (NumberPieces)
  652.   {
  653.     for (int i=0,TrackIt=0;i<NumberPieces;i++)
  654.     {
  655.       PieceHandler &Piece=*Pieces[i];
  656.       if (Piece.LayOut>PieceHandler::__DUMMY2__)
  657.       {
  658.         if (!TrackIt)
  659.         {
  660.           fputs("  // Declare group headings\n\n",Output);
  661.           TrackIt++;
  662.         }
  663.         fprintf(Output,"  GroupHeading(%d,%d,%d,\"%s\",%s);\n",
  664.           Piece.X,Piece.Y,Piece.GroupCode,Piece.Text,Piece.HotKey);
  665.       }
  666.     }
  667.     if (TrackIt)
  668.     {
  669.       fputs("\n",Output);
  670.     }
  671.   }
  672.  
  673.   //-------------------------------------------------------------------------
  674.   //
  675.   // Output Dialog Class Code
  676.   //
  677.   //-------------------------------------------------------------------------
  678.  
  679.   if (NumberPieces)
  680.   {
  681.     for (int i=0,TrackIt=0;i<NumberPieces;i++)
  682.     {
  683.       PieceHandler &Piece=*Pieces[i];
  684.       if (Piece.LayOut>PieceHandler::__DUMMY__ &&
  685.         Piece.LayOut<PieceHandler::__DUMMY2__)
  686.       {
  687.         if (!TrackIt)
  688.         {
  689.           fputs("  // Declare elements, hot keys, help, and groups\n\n",Output);
  690.           TrackIt++;
  691.         }
  692.  
  693.         char Remember[50];
  694.  
  695.         if (Piece.GroupCode)
  696.           sprintf(Remember,"GroupElement(%d,",Piece.GroupCode);
  697.         else
  698.           strcpy(Remember,"Element(");
  699.  
  700.         char ClassName[50];
  701.  
  702.         if (Piece.ToBeDerived)
  703.           strcpy(ClassName,Piece.DerivedClass);
  704.         else
  705.         {
  706.           switch(Piece.LayOut)
  707.           {
  708.             case PieceHandler::Character:
  709.               strcpy(ClassName,"DiaChar");
  710.               break;
  711.  
  712.             case PieceHandler::Integer:
  713.               strcpy(ClassName,"DiaInt");
  714.               break;
  715.  
  716.             case PieceHandler::Long:
  717.               strcpy(ClassName,"DiaLong");
  718.               break;
  719.  
  720.             case PieceHandler::Float:
  721.               strcpy(ClassName,"DiaFloat");
  722.               break;
  723.  
  724.             case PieceHandler::Double:
  725.               strcpy(ClassName,"DiaDouble");
  726.               break;
  727.  
  728.             case PieceHandler::Bcd:
  729.               strcpy(ClassName,"DiaBcd");
  730.               break;
  731.  
  732.             case PieceHandler::Push:
  733.               strcpy(ClassName,"DiaPushButton");
  734.               break;
  735.  
  736.             case PieceHandler::Check:
  737.               strcpy(ClassName,"DiaCheckBox");
  738.               break;
  739.  
  740.             case PieceHandler::VRadio:
  741.               strcpy(ClassName,"DiaVertRadio");
  742.               break;
  743.  
  744.             case PieceHandler::HRadio:
  745.               strcpy(ClassName,"DiaHorizRadio");
  746.               break;
  747.           }
  748.         }
  749.  
  750.         switch(Piece.LayOut)
  751.         {
  752.           case PieceHandler::Character:
  753.             if (!Piece.ScrollWidth && !Piece.MaskWidth)
  754.               fprintf(Output,"  %snew %s(%d,%d,\"%s\",%s));\n",Remember,ClassName,
  755.                 Piece.X,Piece.Y,Piece.Mask,Piece.Variable);
  756.             else if (Piece.ScrollWidth && !Piece.MaskWidth)
  757.               fprintf(Output,"  %snew %s(%d,%d,\"%s\",%s,%d));\n",Remember,ClassName,
  758.                 Piece.X,Piece.Y,Piece.Mask,Piece.Variable,Piece.ScrollWidth);
  759.             else
  760.               fprintf(Output,"  %snew %s(%d,%d,0,%s,%d,'%c',%d));\n",Remember,ClassName,
  761.                 Piece.X,Piece.Y,Piece.Variable,Piece.ScrollWidth,
  762.                   (char)Piece.MaskCharacter,Piece.MaskWidth);
  763.             break;
  764.  
  765.           case PieceHandler::Integer:
  766.             fprintf(Output,"  %snew %s(%d,%d,\"%s\",%s));\n",Remember,ClassName,
  767.               Piece.X,Piece.Y,Piece.Mask,Piece.Variable);
  768.             break;
  769.  
  770.           case PieceHandler::Long:
  771.             fprintf(Output,"  %snew %s(%d,%d,\"%s\",%s));\n",Remember,ClassName,
  772.               Piece.X,Piece.Y,Piece.Mask,Piece.Variable);
  773.             break;
  774.  
  775.           case PieceHandler::Float:
  776.             fprintf(Output,"  %snew %s(%d,%d,\"%s\",%s));\n",Remember,ClassName,
  777.               Piece.X,Piece.Y,Piece.Mask,Piece.Variable);
  778.             break;
  779.  
  780.           case PieceHandler::Double:
  781.             fprintf(Output,"  %snew %s(%d,%d,\"%s\",%s));\n",Remember,ClassName,
  782.               Piece.X,Piece.Y,Piece.Mask,Piece.Variable);
  783.             break;
  784.  
  785.           case PieceHandler::Bcd:
  786.             fprintf(Output,"  %snew %s(%d,%d,\"%s\",%s));\n",Remember,ClassName,
  787.               Piece.X,Piece.Y,Piece.Mask,Piece.Variable);
  788.             break;
  789.  
  790.           case PieceHandler::Push:
  791.             fprintf(Output,
  792.               (*Piece.HotKey)?"  %snew %s(%d,%d,\"%s\",%s,%s));\n":
  793.               "  %snew %s(%d,%d,\"%s\",%s));\n"
  794.               ,Remember,ClassName,
  795.               Piece.X,Piece.Y,
  796.               Piece.Text,Piece.Constant,Piece.HotKey);
  797.             break;
  798.  
  799.           case PieceHandler::Check:
  800.             fprintf(Output,
  801.               (*Piece.HotKey)?"  %snew %s(%d,%d,%s,\"%s\",%s));\n":
  802.               "  %snew %s(%d,%d,%s,\"%s\"));\n",Remember,ClassName,
  803.               Piece.X,Piece.Y,Piece.Variable,Piece.Text,Piece.HotKey);
  804.             break;
  805.  
  806.           case PieceHandler::HRadio:
  807.           case PieceHandler::VRadio:
  808.             fprintf(Output,
  809.               "  %snew %s(%d,%d,%s,0,0));\n"
  810.               ,Remember,ClassName,Piece.X,Piece.Y,Piece.Variable);
  811.             fputs("  *this + ",Output);
  812.             for (int j=0,k=0;j<10;j++)
  813.             {
  814.               if (!*(Piece.Elements[j]+0))
  815.                 break;
  816.               if (k)
  817.                 fputs("\n        + ",Output);
  818.               k++;
  819.               fprintf(Output,"\"%s\"",Piece.Elements[j]);
  820.             }
  821.             fputs(";\n",Output);
  822.             break;
  823.  
  824.           case PieceHandler::PickGeneric:
  825.             fprintf(Output,"  %snew %s());\n",Remember,Piece.DerivedClass);
  826.             break;
  827.         }
  828.  
  829.         if (Piece.Prompter && *Piece.HotKey)
  830.         {
  831.           fprintf(Output,"  HotKey(%d,%d,\"%s\",%s);\n",Piece.PromptX,
  832.             Piece.PromptY,Piece.Prompter,Piece.HotKey);
  833.         }
  834.  
  835.         if (Piece.HelpId && !Piece.Constant)
  836.         {
  837.           fprintf(Output,"  FusionHelp(%d);\n",Piece.HelpId);
  838.         }
  839.  
  840.         if (Piece.Help && *Piece.Help)
  841.         {
  842.           fprintf(Output,"  Help(\"%s\");\n",Piece.Help);
  843.         }
  844.  
  845.         fputs("\n",Output);
  846.       }
  847.     }
  848.   }
  849.  
  850.   //-------------------------------------------------------------------------
  851.   //
  852.   // Close up the function we created
  853.   //
  854.   //-------------------------------------------------------------------------
  855.  
  856.   fputs("  // ... End of dialog definition\n"
  857.     "\n"
  858.     "}\n",Output);
  859.  
  860.   //-------------------------------------------------------------------------
  861.   //
  862.   // Provide instructions about class usage
  863.   //
  864.   //-------------------------------------------------------------------------
  865.  
  866.   if (!OmitComments)
  867.   {
  868.     fputs("\n/*\n"
  869.       "   DDS CODE USAGE INSTRUCTIONS\n\n"
  870.       "   Here is all you have to do to use this ready made dialog:\n\n"
  871.       "   1. Copy the \"Definition\" section into a header file.\n"
  872.       "      The declaration section is at the VERY TOP of this file.\n\n"
  873.       "   2. Define that header file in any file that will use this\n"
  874.       "      dialog.  Use code similar to this:\n\n"
  875.       "      #include \"mydialog.h\" // <- This header will declare the class\n\n"
  876.       "      void myFunc()\n"
  877.       "      {\n\n"
  878.       "        ...\n\n",Output);
  879.     fprintf(Output,
  880.       "        %s &PowerUp = *new %s();\n"
  881.       "        int ReturnedCode = PowerUp.UseDialog();\n\n"
  882.       "        // Evaluate ReturnedCode here ...\n"
  883.       "        // Mess with variables in the PowerUp class now ...\n\n"
  884.       "        delete &PowerUp;\n\n"
  885.       "        ...\n\n"
  886.       "      }\n"
  887.       "*/\n",DerivedClass,DerivedClass);
  888.   }
  889.  
  890.   fputs("\n// Thank you for using DDS!",Output);
  891.  
  892.   fclose(Output);
  893. }
  894.  
  895.  
  896.