home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20os2.zip / demos / tvdemo2.cpp < prev    next >
C/C++ Source or Header  |  1999-05-31  |  9KB  |  360 lines

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