home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / TVDEMOS.ZIP / TVDEMO2.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  9.4 KB  |  357 lines

  1. /*----------------------------------------------------------*/
  2. /*                                                          */
  3. /*   Turbo Vision 1.0                                       */
  4. /*   Copyright (c) 1991 by Borland International            */
  5. /*                                                          */
  6. /*   Turbo Vision TVDEMO source file                        */
  7. /*----------------------------------------------------------*/
  8.  
  9. #define Uses_TDialog
  10. #define Uses_TRect
  11. #define Uses_TStaticText
  12. #define Uses_TButton
  13. #define Uses_TEvent
  14. #define Uses_TWindow
  15. #define Uses_TColorGroup
  16. #define Uses_TColorItem
  17. #define Uses_TColorDialog
  18. #define Uses_TPalette
  19. #define Uses_TDeskTop
  20. #define Uses_TApplication
  21. #define Uses_TChDirDialog
  22.  
  23. #include <tv.h>
  24.  
  25. #include "tvdemo.h"
  26. #include "tvcmds.h"
  27. #include "demohelp.h"
  28. #include "ascii.h"
  29. #include "calendar.h"
  30. #include "calc.h"
  31.  
  32. #include <stdlib.h>
  33.  
  34. //
  35. //  DOS Shell Command.
  36. //
  37.  
  38. void TVDemo::shell()
  39. {
  40.     suspend();
  41.     system("cls");
  42.     cout << "Type EXIT to return...";
  43.     system( getenv( "COMSPEC"));
  44.     resume();
  45.     redraw();
  46. }
  47.  
  48.  
  49. //
  50. // DemoApp::handleEvent()
  51. //  Event loop to distribute the work.
  52. //
  53.  
  54. void TVDemo::handleEvent(TEvent &event)
  55. {
  56.     TApplication::handleEvent(event);
  57.  
  58.     if (event.what == evCommand)
  59.     {
  60.         switch (event.message.command)
  61.             {
  62.             case cmAboutCmd:            //  About Dialog Box
  63.                 aboutDlgBox();
  64.                 break;
  65.  
  66.             case cmCalendarCmd:         //  Calendar Window
  67.                 calendar();
  68.                 break;
  69.  
  70.             case cmAsciiCmd:            //  Ascii Table
  71.                 asciiTable();
  72.                 break;
  73.  
  74.             case cmCalcCmd:             //  Calculator
  75.                 calculator();
  76.                 break;
  77.  
  78.             case cmPuzzleCmd:           //  Puzzle
  79.                 puzzle();
  80.                 break;
  81.  
  82.             case cmOpenCmd:             //  View a file
  83.                 openFile("*.*");
  84.                 break;
  85.  
  86.             case cmChDirCmd:            //  Change directory
  87.                 changeDir();
  88.                 break;
  89.  
  90.             case cmDOS_Cmd:             //  DOS shell
  91.                 shell();
  92.                 break;
  93.  
  94.             case cmTile:             //  Tile current file windows
  95.                 tile();
  96.                 break;
  97.  
  98.             case cmCascade:          //  Cascade current file windows
  99.                 cascade();
  100.                 break;
  101.  
  102.             case cmMouseCmd:            //  Mouse control dialog box
  103.                 mouse();
  104.                 break;
  105.  
  106.             case cmColorCmd:            //  Color control dialog box
  107.                 colors();
  108.                 break;
  109.  
  110.         case cmSaveCmd:             //  Save current desktop
  111.                 saveDesktop();
  112.                 break;
  113.  
  114.         case cmRestoreCmd:          //  Restore saved desktop
  115.                 retrieveDesktop();
  116.                 break;
  117.  
  118.             default:                    //  Unknown command
  119.                 return;
  120.  
  121.             }
  122.         clearEvent (event);
  123.         }
  124. }
  125.  
  126.  
  127.  
  128. //
  129. // About Box function()
  130. //
  131.  
  132. void TVDemo::aboutDlgBox()
  133. {
  134.     TDialog *aboutBox = new TDialog(TRect(0, 0, 39, 13), "About");
  135.  
  136.     aboutBox->insert(
  137.       new TStaticText(TRect(9, 2, 30, 9),
  138.         "\003Turbo Vision Demo\n\003\n"     // These strings will be
  139.         "\003C++ Version\n\003\n"           // concatenated by the compiler.
  140.         "\003Copyright (c) 1991\n\003\n"    // The Ctrl-C centers the line.
  141.         "\003Borland International"
  142.         )
  143.       );
  144.  
  145.     aboutBox->insert(
  146.       new TButton(TRect(14, 10, 25, 12), " OK", cmOK, bfDefault)
  147.       );
  148.  
  149.     aboutBox->options |= ofCentered;
  150.  
  151.     deskTop->execView(aboutBox);
  152.  
  153.     destroy( aboutBox );
  154. }
  155.  
  156.  
  157. //
  158. // Ascii Chart function
  159. //
  160.  
  161. void TVDemo::asciiTable()
  162. {
  163.     TAsciiChart *chart = (TAsciiChart *) validView(new TAsciiChart);
  164.  
  165.     if(chart != 0)
  166.     {
  167.         chart->helpCtx = hcAsciiTable;
  168.         deskTop->insert(chart);
  169.     }
  170. }
  171.  
  172.  
  173. //
  174. // Calendar function()
  175. //
  176.  
  177. void TVDemo::calendar()
  178. {
  179.     TCalendarWindow *cal = (TCalendarWindow *) validView(new TCalendarWindow);
  180.  
  181.     if(cal != 0)
  182.     {
  183.         cal->helpCtx = hcCalendar;
  184.         deskTop->insert( cal );
  185.     }
  186. }
  187.  
  188.  
  189. //
  190. // Calculator function
  191. //
  192.  
  193. void TVDemo::calculator()
  194. {
  195.     TCalculator *calc = (TCalculator *) validView(new TCalculator);
  196.  
  197.     if(calc != 0)
  198.     {
  199.         calc->helpCtx = hcCalculator;
  200.         deskTop->insert(calc);
  201.     }
  202. }
  203.  
  204. //
  205. // Cascade function
  206. //
  207.  
  208. void TVDemo::cascade()
  209. {
  210.     deskTop->cascade( deskTop->getExtent() );
  211. }
  212.  
  213.  
  214. //
  215. // Change Directory function
  216. //
  217.  
  218. void TVDemo::changeDir()
  219. {
  220.     TView *d = validView( new TChDirDialog( 0, cmChangeDir ) );
  221.  
  222.     if( d != 0 )
  223.         {
  224.         d->helpCtx = hcFCChDirDBox;
  225.         deskTop->execView( d );
  226.         destroy( d );
  227.     }
  228. }
  229.  
  230.  
  231. //
  232. // Color Control Dialog Box function
  233. //
  234.  
  235. void TVDemo::colors()
  236. {
  237.  
  238.  
  239.     TColorGroup &group1 =
  240.         *new TColorGroup("Desktop") +
  241.             *new TColorItem("Color",             1)+
  242.  
  243.         *new TColorGroup("Menus") +
  244.             *new TColorItem("Normal",            2)+
  245.             *new TColorItem("Disabled",          3)+
  246.             *new TColorItem("Shortcut",          4)+
  247.             *new TColorItem("Selected",          5)+
  248.             *new TColorItem("Selected disabled", 6)+
  249.             *new TColorItem("Shortcut selected", 7
  250.         );
  251.  
  252.     TColorGroup &group2 =
  253.         *new TColorGroup("Dialogs/Calc") +
  254.             *new TColorItem("Frame/background",  33)+
  255.             *new TColorItem("Frame icons",       34)+
  256.             *new TColorItem("Scroll bar page",   35)+
  257.             *new TColorItem("Scroll bar icons",  36)+
  258.             *new TColorItem("Static text",       37)+
  259.  
  260.             *new TColorItem("Label normal",      38)+
  261.             *new TColorItem("Label selected",    39)+
  262.             *new TColorItem("Label shortcut",    40
  263.         );
  264.  
  265.     TColorItem &item_coll1 =
  266.         *new TColorItem("Button normal",     41)+
  267.         *new TColorItem("Button default",    42)+
  268.         *new TColorItem("Button selected",   43)+
  269.         *new TColorItem("Button disabled",   44)+
  270.         *new TColorItem("Button shortcut",   45)+
  271.         *new TColorItem("Button shadow",     46)+
  272.         *new TColorItem("Cluster normal",    47)+
  273.         *new TColorItem("Cluster selected",  48)+
  274.         *new TColorItem("Cluster shortcut",  49
  275.         );
  276.  
  277.     TColorItem &item_coll2 =
  278.         *new TColorItem("Input normal",      50)+
  279.         *new TColorItem("Input selected",    51)+
  280.         *new TColorItem("Input arrow",       52)+
  281.  
  282.         *new TColorItem("History button",    53)+
  283.         *new TColorItem("History sides",     54)+
  284.         *new TColorItem("History bar page",  55)+
  285.         *new TColorItem("History bar icons", 56)+
  286.  
  287.         *new TColorItem("List normal",       57)+
  288.         *new TColorItem("List focused",      58)+
  289.         *new TColorItem("List selected",     59)+
  290.         *new TColorItem("List divider",      60)+
  291.  
  292.         *new TColorItem("Information pane",  61
  293.         );
  294.  
  295.      group2 = group2 + item_coll1 + item_coll2;
  296.  
  297.      TColorGroup &group3 =
  298.          *new TColorGroup("Viewer") +
  299.              *new TColorItem("Frame passive",      8)+
  300.              *new TColorItem("Frame active",       9)+
  301.              *new TColorItem("Frame icons",       10)+
  302.              *new TColorItem("Scroll bar page",   11)+
  303.              *new TColorItem("Scroll bar icons",  12)+
  304.              *new TColorItem("Text",              13)+
  305.          *new TColorGroup("Puzzle")+
  306.              *new TColorItem("Frame passive",      8)+
  307.              *new TColorItem("Frame active",       9)+
  308.              *new TColorItem("Frame icons",       10)+
  309.              *new TColorItem("Scroll bar page",   11)+
  310.              *new TColorItem("Scroll bar icons",  12)+
  311.              *new TColorItem("Normal text",       13)+
  312.              *new TColorItem("Highlighted text",  14
  313.          );
  314.  
  315.  
  316.      TColorGroup &group4 =
  317.          *new TColorGroup("Calendar") +
  318.              *new TColorItem("Frame passive",     16)+
  319.              *new TColorItem("Frame active",      17)+
  320.              *new TColorItem("Frame icons",       18)+
  321.              *new TColorItem("Scroll bar page",   19)+
  322.              *new TColorItem("Scroll bar icons",  20)+
  323.              *new TColorItem("Normal text",       21)+
  324.              *new TColorItem("Current day",       22)+
  325.  
  326.          *new TColorGroup("Ascii table") +
  327.              *new TColorItem("Frame passive",     24)+
  328.              *new TColorItem("Frame active",      25)+
  329.              *new TColorItem("Frame icons",       26)+
  330.              *new TColorItem("Scroll bar page",   27)+
  331.              *new TColorItem("Scroll bar icons",  28)+
  332.              *new TColorItem("Text",              29
  333.          );
  334.  
  335.  
  336.     TColorGroup &group5 = group1 + group2 + group3 + group4;
  337.  
  338.     TColorDialog *c = new TColorDialog((TPalette*)0, &group5 );
  339.  
  340.     if( validView( c ) != 0 )
  341.         {
  342.         c->helpCtx = hcOCColorsDBox;  // set context help constant
  343.         c->setData(&getPalette());
  344.         if( deskTop->execView( c ) != cmCancel )
  345.             {
  346.             getPalette() = *(c->pal);
  347.             deskTop->setState( sfVisible, False );
  348.             deskTop->setState( sfVisible, True );
  349.             }
  350.         destroy( c );
  351.         }
  352.  
  353. }
  354.  
  355.  
  356.  
  357.