home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / fli106c / examples / panel.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-25  |  15.4 KB  |  559 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 "colors.h"
  12. #include "fliwin.h"
  13. #include "dds.h"
  14.  
  15. #include <io.h>
  16. #include <sys\stat.h>
  17. #include <fcntl.h>
  18.  
  19. #pragma warn -inl
  20. #pragma warn -lvc
  21.  
  22. //-------------------------------------------------------------------------
  23. //
  24. // Control panel event handler
  25. //
  26. //-------------------------------------------------------------------------
  27.  
  28. class ControlPanelDialog : public DialogClass
  29. {
  30. public:
  31.  
  32.   int VideoModeChanged;
  33.   int ColorsChanged;
  34.   __FusionColors ColorSet;
  35.  
  36.   ControlPanelDialog() : DialogClass(37,18,"Control Panel")
  37.     { VideoModeChanged=0;
  38.       ColorsChanged=0;
  39.       ColorSet=Colors; }
  40.  
  41.   int ChangeColors(__FusionColors &Colorize);
  42.   int ChangeVideoMode();
  43.  
  44.   int EventHandler(int Event)
  45.   {
  46.     if (Event==kbEsc ||
  47.         Event==kbCr ||
  48.         Event==CloseEvent ||
  49.         Event==OutsideEvent ||
  50.         Event==panelAcceptButton)
  51.       return StopEvent;
  52.     if (Event==panelColorButton)
  53.       ColorsChanged=ChangeColors(ColorSet);
  54.     if (Event==panelVideoButton)
  55.       VideoModeChanged=ChangeVideoMode();
  56.     return CompleteEvent;
  57.   }
  58. };
  59.  
  60. //-------------------------------------------------------------------------
  61. //
  62. // Storage for the available panel video modes
  63. //
  64. //-------------------------------------------------------------------------
  65.  
  66. static int VideoModes[] =
  67.   { Normal_80x25,
  68.     EGA_VGA_43or50,
  69.     ATI_Wonder_132x25,
  70.     ATI_Wonder_132x44,
  71.     Compaq_VGS_132x25,
  72.     Compaq_VGS_132x28,
  73.     Compaq_VGS_132x43,
  74.     Compaq_VGS_132x50,
  75.     Compaq_VGS_132x60,
  76.     Genoa_VGA_132x25,
  77.     Genoa_VGA_132x28,
  78.     Genoa_VGA_132x43,
  79.     Orchid_VGA_80x60,
  80.     Orchid_VGA_132x25,
  81.     Orchid_VGA_132x28,
  82.     Orchid_VGA_132x44,
  83.     Paradise_132x25,
  84.     Paradise_132x43,
  85.     Sigma_VGA_132x25,
  86.     Sigma_VGA_132x44,
  87.     STB_VGA_132x25,
  88.     STB_VGA_132x44,
  89.     Tecmar_132x25,
  90.     Tseng_132x25,
  91.     Tseng_132x28,
  92.     Tseng_132x44,
  93.     VEGA_80x43,
  94.     VEGA_80x60,
  95.     VEGA_100x60,
  96.     VEGA_120x25,
  97.     VEGA_120x43,
  98.     VEGA_132x25,
  99.     VEGA_132x43 };
  100.  
  101. //-------------------------------------------------------------------------
  102. //
  103. // Window system interface behavior control dialog
  104. //
  105. // RememberLastVideo is used to save the last video mode change.  It is
  106. // necessary in case the video mode isn't changed at a dialog and helps
  107. // guarantee that the user won't lose the video mode setting when using
  108. // DDS at another time.
  109. //
  110. //-------------------------------------------------------------------------
  111.  
  112. static int RememberLastVideo=0;
  113.  
  114. int DesignerWindow::ControlPanel()
  115. {
  116.   ControlPanelDialog &Behave = *new ControlPanelDialog();
  117.  
  118.   Behave.Element(new DiaVertRadio(1,2,MenuManager::IsPullDown,0,0));
  119.   Behave + "Pop Down" + "Pull Down";
  120.   Behave.Help("Select the type of menu control that you desire");
  121.   Behave.HotKey(1,1,"~Menu Style",kbAltM);
  122.   Behave.FusionHelp(10010);
  123.  
  124.   int Repeat;
  125.  
  126.   if (MouseRepeatSpeed)
  127.     Repeat=0;
  128.   else
  129.     Repeat=1;
  130.  
  131.   Behave.Element(new DiaVertRadio(19,2,Repeat,0,0));
  132.   Behave + "Slow     " + "Fast     ";
  133.   Behave.Help("Select the speed of the automatic mouse repeat");
  134.   Behave.HotKey(19,1,"Mouse ~Repeat",kbAltR);
  135.   Behave.FusionHelp(10011);
  136.  
  137.   int Click;
  138.  
  139.   if (MouseDoubleClickFactor<=7)
  140.     Click=0;
  141.   else if (MouseDoubleClickFactor>7 && MouseDoubleClickFactor<=11)
  142.     Click=1;
  143.   else
  144.     Click=2;
  145.  
  146.   Behave.Element(new DiaVertRadio(1,6,Click,0,0));
  147.   Behave + "Short    " + "Normal   " + "Long    ";
  148.   Behave.Help("Select the speed of the double click");
  149.   Behave.HotKey(1,5,"~Double Click",kbAltD);
  150.   Behave.FusionHelp(10012);
  151.  
  152.   int Delay;
  153.  
  154.   if (MouseRepeatDelay<3)
  155.     Delay=0;
  156.   else if (MouseRepeatDelay>=3 && MouseRepeatDelay<5)
  157.     Delay=1;
  158.   else
  159.     Delay=2;
  160.  
  161.   Behave.Element(new DiaVertRadio(19,6,Delay,0,0));
  162.   Behave + "Short    " + "Normal   " + "Long     ";
  163.   Behave.Help("Select the delay before the automatic mouse repeat");
  164.   Behave.HotKey(19,5,"Repeat ~Lag",kbAltL);
  165.   Behave.FusionHelp(10013);
  166.  
  167.   Behave.Element(new DiaVertRadio(1,11,MenuManager::Beneath,0,0));
  168.   Behave + "Right\x1a   " + "Below\x19   ";
  169.   Behave.Help("Select the location of the sub menus");
  170.   Behave.HotKey(1,10,"Sub Me~nus",kbAltN);
  171.   Behave.FusionHelp(10020);
  172.  
  173.   Behave.Element(new DiaVertRadio(19,11,FusionShadowing,0,0));
  174.   Behave + "Disabled " + "Enabled  ";
  175.   Behave.Help("Turn the shadowing capability on or off");
  176.   Behave.HotKey(19,10,"S~hadows",kbAltH);
  177.   Behave.FusionHelp(10020);
  178.  
  179.   Behave.Element(new DiaPushButton(1,14,"Color~s",panelColorButton,kbAltS));
  180.   Behave.Help("Change the window, menu, or miscellaneous colors");
  181.  
  182.   Behave.Element(new DiaPushButton(12,14,"~Videos",panelVideoButton,kbAltV));
  183.   Behave.Help("Change the video mode");
  184.  
  185.   Behave.Element(new DiaPushButton(23,14,"Continue",panelAcceptButton,0,1));
  186.   Behave.Help("Press to change the settings and save them to your disk");
  187.  
  188.   int BehaveCheck=Behave.UseDialog();
  189.  
  190.   if (BehaveCheck==kbCr || BehaveCheck==panelAcceptButton)
  191.   {
  192.     if (!Click)
  193.       MouseDoubleClickFactor=7;
  194.     else if (Click==1)
  195.       MouseDoubleClickFactor=10;
  196.     else
  197.       MouseDoubleClickFactor=13;
  198.  
  199.     if (!Repeat)
  200.       MouseRepeatSpeed=2;
  201.     else
  202.       MouseRepeatSpeed=0;
  203.  
  204.     if (!Delay)
  205.       MouseRepeatDelay=1;
  206.     else if (Delay==1)
  207.       MouseRepeatDelay=3;
  208.     else
  209.       MouseRepeatDelay=5;
  210.  
  211.     int VideoModeChanged=Behave.VideoModeChanged;
  212.     int ColorsChanged=Behave.ColorsChanged;
  213.  
  214.     // Save the settings into a defaults file
  215.  
  216.     int Handle=open("PANEL.FLI",O_CREAT|O_TRUNC|O_RDWR|O_BINARY,S_IREAD|S_IWRITE);
  217.  
  218.     write(Handle,&MouseDoubleClickFactor,sizeof(int));
  219.     write(Handle,&MouseRepeatSpeed,sizeof(int));
  220.     write(Handle,&MouseRepeatDelay,sizeof(int));
  221.     write(Handle,&MenuManager::Beneath,sizeof(int));
  222.     write(Handle,&MenuManager::IsPullDown,sizeof(int));
  223.     write(Handle,&FusionShadowing,sizeof(int));
  224.  
  225.     if (RememberLastVideo && !VideoModeChanged)
  226.       write(Handle,&RememberLastVideo,sizeof(int));
  227.     else
  228.     {
  229.       RememberLastVideo=VideoModeChanged;
  230.       write(Handle,&VideoModeChanged,sizeof(int));
  231.     }
  232.  
  233.     write(Handle,&Behave.ColorSet,sizeof(__FusionColors));
  234.  
  235.     close(Handle);
  236.  
  237.     if (ColorsChanged)
  238.       Colors=Behave.ColorSet;
  239.  
  240.     delete &Behave;
  241.  
  242.     if (VideoModeChanged)
  243.     {
  244.       RemoveAllMenus();
  245.  
  246.       BlazeClass Blaze;
  247.       Blaze[VideoModes[VideoModeChanged-1]];
  248.       -Blaze;
  249.     }
  250.     return (VideoModeChanged)?1:ColorsChanged;
  251.   }
  252.  
  253.   delete &Behave;
  254.  
  255.   return 0;
  256. }
  257.  
  258. //-------------------------------------------------------------------------
  259. //
  260. // AutoPowerupSequencer -- This loads saved control panel settings at
  261. // program startup.  It is presented with the lowest priority number so
  262. // it is loaded LAST at program startup to ensure that the colors class
  263. // is correctly loaded and is not overriden.  In addition, this must
  264. // activate *AFTER* the FLI video protection feature.
  265. //
  266. // The PanelAutoEngaged variable is set to a non-zero value if the
  267. // panel settings file exists.  This variable can be accessed anywhere
  268. // in your program to see if settings were loaded.  This can be used
  269. // if you override certain items at startup if the panel file doesn't
  270. // exist.  See the DDS.CPP file for an example of this.
  271. //
  272. //-------------------------------------------------------------------------
  273.  
  274. int PanelAutoEngaged=0;
  275.  
  276. void AutoPowerupSequencer()
  277. {
  278.   if (access("PANEL.FLI",0))
  279.     return;
  280.  
  281.   PanelAutoEngaged=1;
  282.  
  283.   int Handle=open("PANEL.FLI",O_RDWR|O_BINARY,S_IREAD|S_IWRITE);
  284.  
  285.   lseek(Handle,0,SEEK_SET);
  286.  
  287.   int VideoModeChanged, ColorsChanged;
  288.  
  289.   read(Handle,&MouseDoubleClickFactor,sizeof(int));
  290.   read(Handle,&MouseRepeatSpeed,sizeof(int));
  291.   read(Handle,&MouseRepeatDelay,sizeof(int));
  292.   read(Handle,&MenuManager::Beneath,sizeof(int));
  293.   read(Handle,&MenuManager::IsPullDown,sizeof(int));
  294.   read(Handle,&FusionShadowing,sizeof(int));
  295.   read(Handle,&VideoModeChanged,sizeof(int));
  296.  
  297.   if (VideoModeChanged)
  298.   {
  299.     BlazeClass Blaze;
  300.     Blaze[VideoModes[VideoModeChanged-1]];
  301.     RememberLastVideo=VideoModeChanged;
  302.     -Blaze;
  303.   }
  304.  
  305.   read(Handle,&Colors,sizeof(__FusionColors));
  306.  
  307.   close(Handle);
  308. }
  309.  
  310. #pragma startup AutoPowerupSequencer 255
  311.  
  312. //-------------------------------------------------------------------------
  313. //
  314. // Event handler for color changing dialog
  315. //
  316. //-------------------------------------------------------------------------
  317.  
  318. class ColorDialog : public DialogClass
  319. {
  320. public:
  321.  
  322.   ColorDialog() : DialogClass(64,18,"Object Colors")
  323.     {  }
  324.  
  325.   int EventHandler(int Event)
  326.   {
  327.     if (Event==kbEsc ||
  328.         Event==kbCr ||
  329.         Event==CloseEvent ||
  330.         Event==OutsideEvent ||
  331.         Event==colorChange ||
  332.         Event==colorCancel)
  333.       return StopEvent;
  334.     return CompleteEvent;
  335.   }
  336. };
  337.  
  338. //-------------------------------------------------------------------------
  339. //
  340. // Color list and changing dialog
  341. //
  342. //-------------------------------------------------------------------------
  343.  
  344. class ColorList : public DiaPickList, public CurrentColor
  345. {
  346. public:
  347.  
  348.   __FusionColors &ColorSet;
  349.  
  350.   ColorList(int X,int Y,int Width,int Height,int &ItemNumber,int &NumberOfItems,
  351.     char **ListOfItems,__FusionColors &Colorize) :
  352.   DiaPickList(X,Y,Width,Height,ItemNumber,NumberOfItems,ListOfItems) ,
  353.   ColorSet(Colorize)
  354.   {
  355.     int *Panel=&ColorSet.MenuBorder;
  356.     TheColor=(Panel+DiaPickList::Item);
  357.   }
  358.  
  359.   int EventHandler(int Event)
  360.   {
  361.     int Item=DiaPickList::Item;
  362.  
  363.     int Returned=DiaPickList::EventHandler(Event);
  364.  
  365.     if (Item!=DiaPickList::Item)
  366.     {
  367.       int *Panel=&ColorSet.MenuBorder;
  368.       TheColor=(Panel+DiaPickList::Item);
  369.       return OtherRefreshEvent;
  370.     }
  371.     else
  372.       return Returned;
  373.   }
  374. };
  375.  
  376. int ControlPanelDialog::ChangeColors(__FusionColors &Colorize)
  377. {
  378.   static char *Coloring[] =
  379.     {
  380.       "Menus        Border",
  381.       "Menus        Close Icon",
  382.       "Menus        Disabled Option",
  383.       "Menus        HiLighted Option",
  384.       "Menus        Interior",
  385.       "Menus        Quick Key",
  386.       "Menus        Title",
  387.       "Menus        Hot Key",
  388.       "Menus        Pointer to Sub Menu",
  389.       "Menus        Check Mark",
  390.       "Menus        Selectables",
  391.       "Menu Bar     Quick Key",
  392.       "Menu Bar     Normal Text",
  393.       "Dialog       Numerical Element",
  394.       "Dialog       HiLighted Numerical Element",
  395.       "Dialog       Character Element",
  396.       "Dialog       HiLighted Character Element",
  397.       "Dialog       Push Button",
  398.       "Dialog       Quick Key for Push Button",
  399.       "Dialog       HiLighted Push Button",
  400.       "Dialog       Active Push Button",
  401.       "Dialog       Check Box",
  402.       "Dialog       Check Mark",
  403.       "Dialog       HiLighted Check Box",
  404.       "Dialog       Check Mark Quick Key",
  405.       "Dialog       Radio Buttons",
  406.       "Dialog       Radio Button Check Mark",
  407.       "Dialog       HiLighted Radio Button",
  408.       "Dialog       Pick List",
  409.       "Dialog       Marked Pick List Item",
  410.       "Dialog       HiLighted Pick List Item",
  411.       "Dialog       Pick List Scroll Bar",
  412.       "Dialog       Border",
  413.       "Dialog       Close Icon",
  414.       "Dialog       Interior",
  415.       "Dialog       Title",
  416.       "Dialog       Locator",
  417.       "Dialog       Bold Locator",
  418.       "Dialog       Locator Quick Key",
  419.       "Dialog       Disabled Locator",
  420.       "Dialog       Group Heading",
  421.       "Dialog       Bold Group Heading",
  422.       "Dialog       Group Quick Key",
  423.       "Prompt Line  Hot Key",
  424.       "Prompt Line  Description",
  425.       "Work Space   Background Color",
  426.       "Window       Border",
  427.       "Window       Icons",
  428.       "Window       Title",
  429.       "Window       Scroll Bars",
  430.       "Window       Size Corner",
  431.       "Window       Interior",
  432.       "Window       Bold Interior",
  433.       "Window       Alternate Interior",
  434.       "Window       Window in Background"
  435.       };
  436.  
  437.   ColorDialog &Dialog=*new ColorDialog();
  438.  
  439.   int Current=0;
  440.  
  441.   Dialog.Element(new ColorList(1,2,40,11,Current,55,Coloring,Colorize));
  442.   Dialog.HotKey(1,1,"~Objects",kbAltO);
  443.   Dialog.Help("Select the item of whose colors you wish to change");
  444.  
  445.   Dialog.Element(new ForeGround(47,3,47,14));
  446.   Dialog.HotKey(48,1,"~Foreground",kbAltF);
  447.   Dialog.Help("Select the foreground color for this object");
  448.  
  449.   Dialog.Element(new BackGround(47,10,47,14));
  450.   Dialog.HotKey(48,8,"~Background",kbAltB);
  451.   Dialog.Help("Select the background color for this object");
  452.  
  453.   Dialog.Element(new DiaPushButton(7,14,"Change Colors",colorChange,0,1));
  454.   Dialog.Help("Change the colors to the newly selected colors");
  455.  
  456.   Dialog.Element(new DiaPushButton(29,14,"Cancel",colorCancel));
  457.   Dialog.Help("Do not change the colors");
  458.  
  459.   Dialog.Blaze.Box(45,1,16,7,Colors.DiaInterior);
  460.   Dialog.Blaze.Box(45,8,16,5,Colors.DiaInterior);
  461.   Dialog.Blaze.UserBoxDefineQuick(2);
  462.   Dialog.Blaze.Box(45,13,16,3,Colors.DiaInterior);
  463.   Dialog.Blaze.UserBoxDefineQuick(1);
  464.   Dialog.Blaze (50,13) << Colors.DiaInterior << "Sample";
  465.  
  466.   int Remember=Dialog.UseDialog();
  467.  
  468.   delete &Dialog;
  469.  
  470.   return (Remember==kbCr || Remember==colorChange || Remember==MousedEvent)?1:0;
  471. }
  472.  
  473. //-------------------------------------------------------------------------
  474. //
  475. // Video mode changing dialog
  476. //
  477. //-------------------------------------------------------------------------
  478.  
  479. class VideoModeDialog : public DialogClass
  480. {
  481. public:
  482.  
  483.   VideoModeDialog() : DialogClass(37,14,"Video Mode")
  484.     {  }
  485.  
  486.   int EventHandler(int Event)
  487.   {
  488.     if (Event==kbEsc ||
  489.         Event==kbCr ||
  490.         Event==CloseEvent ||
  491.         Event==OutsideEvent ||
  492.         Event==videoChange ||
  493.         Event==videoCancel)
  494.       return StopEvent;
  495.     return CompleteEvent;
  496.   }
  497. };
  498.  
  499. int ControlPanelDialog::ChangeVideoMode()
  500. {
  501.   static char *Videos[] =
  502.     { "Standard 80x25",
  503.       "EGA/VGA 43x25 or 50x25",
  504.       "ATI Wonder 132x25",
  505.       "ATI Wonder 132x43",
  506.       "Compaq Integrated VGS 132x25",
  507.       "Compaq Integrated VGS 132x28",
  508.       "Compaq Integrated VGS 132x43",
  509.       "Compaq Integrated VGS 132x50",
  510.       "Compaq Integrated VGS 132x60",
  511.       "Genoa VGA 132x25",
  512.       "Genoa VGA 132x28",
  513.       "Genoa VGA 132x43",
  514.       "Orchid VGA 80x60",
  515.       "Orchid VGA 132x25",
  516.       "Orchid VGA 132x28",
  517.       "Orchid VGA 132x44",
  518.       "Paradise VGA 132x25",
  519.       "Paradise VGA 132x43",
  520.       "Sigma VGA 132x25",
  521.       "Sigma VGA 132x43",
  522.       "STB VGA 132x25",
  523.       "STB VGA 132x43",
  524.       "Tecmar VGA 132x25",
  525.       "Tseng VGA 132x25",
  526.       "Tseng VGA 132x28",
  527.       "Tseng VGA 132x44",
  528.       "VEGA VGA 80x43",
  529.       "VEGA VGA 80x60",
  530.       "VEGA VGA 100x60",
  531.       "VEGA VGA 120x25",
  532.       "VEGA VGA 120x43",
  533.       "VEGA VGA 132x25",
  534.       "VEGA VGA 132x43" };
  535.  
  536.   VideoModeDialog &Dialog=*new VideoModeDialog();
  537.  
  538.   int Current=0;
  539.  
  540.   Dialog.Element(new DiaPickList(1,1,30,8,Current,33,Videos));
  541.   Dialog.Help("Select the video mode that you would like to switch to");
  542.  
  543.   Dialog.Element(new DiaPushButton(7,10,"Change",videoChange,0,1));
  544.   Dialog.Help("Change to the selected video mode");
  545.  
  546.   Dialog.Element(new DiaPushButton(19,10,"Cancel",videoCancel));
  547.   Dialog.Help("Do not change to the selected video mode");
  548.  
  549.   int Remember=Dialog.UseDialog();
  550.  
  551.   delete &Dialog;
  552.  
  553.   if (Remember==videoChange || Remember==kbCr || Remember==MousedEvent)
  554.     return Current+1;
  555.  
  556.   return 0;
  557. }
  558.  
  559.