home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / TI_BC1.ZIP / TI1554.ZIP / TI1554.ASC
Text File  |  1993-08-30  |  15KB  |  727 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  9.   VERSION  :  3.1
  10.        OS  :  DOS
  11.      DATE  :  August 30, 1993                         PAGE  :  1/11
  12.  
  13.     TITLE  :  Context sensitive help example (Turbo Vision)
  14.  
  15.  
  16.  
  17.  
  18.   Two files are enclosed in this document:
  19.  
  20.      TESTHELP.CPP
  21.      TEXTHELP.TXT
  22.  
  23.   Run TVHC (Turbo Vision Help Compiler) on the TESTHELP.TXT file.
  24.   This will create two files:  TESTHELP.HLP and TESTHELP.H.  Then
  25.   compile the TESTHELP.CPP file as you would any other Turbo Vision
  26.   application.
  27.  
  28.   **** BEGIN FILE: TESTHELP.CPP ****
  29.   //=============================================================
  30.   //  The following routines have been uploaded to the Borland
  31.   //  Forum BPROGB on CompuServe by the Technical Support staff.
  32.   //  They are provided as a courtesy and not as part of a Borland
  33.   //  product; and, as such, are provided without the assurance of
  34.   //  technical support or any specific guarantees.
  35.   //==============================================================
  36.   //  Turbo Vision - Context Sensitive Help
  37.   //
  38.   //  - This sample code demonstrates creating context sensitive
  39.   //    help.
  40.   //
  41.   //  - The Step to follow are:
  42.   //
  43.   //     1) Overload TApplication::getPalette to return a new
  44.   //        palette which contains palette entries for the help
  45.   //        system.
  46.   //
  47.   //     2) Overload TApplication::getEvent to handle the cmMyHelp
  48.   //        command.  Overloading getEvent allows the application
  49.   //        to help requests comming from any view.
  50.   //
  51.   //     3) Inherit from TStatusLine to create THintStatusline.
  52.   //
  53.   //     4) Create a  XXXX.txt file (see testhelp.txt).
  54.   //          a) compile XXXX.txt with tvhc.exe in the
  55.   //             borlandc\tvision\help subdirectory.  The
  56.   //             resulting file XXXX.hlp is the binary
  57.   //             file which Turbo Vision uses to access help
  58.   //             at runtime.
  59.   //
  60.   //==============================================================
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  75.   VERSION  :  3.1
  76.        OS  :  DOS
  77.      DATE  :  August 30, 1993                         PAGE  :  2/11
  78.  
  79.     TITLE  :  Context sensitive help example (Turbo Vision)
  80.  
  81.  
  82.  
  83.  
  84.   #define Uses_TWindow
  85.   #define Uses_TMenuBox
  86.   #define Uses_TMenu
  87.   #define Uses_TKeys
  88.   #define Uses_TApplication
  89.   #define Uses_TEvent
  90.   #define Uses_TRect
  91.   #define Uses_TDeskTop
  92.   #define Uses_TMenuBar
  93.   #define Uses_TMenuItem
  94.   #define Uses_TSubMenu
  95.   #define Uses_TStatusLine
  96.   #define Uses_TStatusDef
  97.   #define Uses_TStatusItem
  98.   #define Uses_MsgBox
  99.   #define Uses_fpstream
  100.   #define Uses_TDialog
  101.   #define Uses_TButton
  102.   #define Uses_TStaticText
  103.   #define Uses_TRadioButtons
  104.   #define Uses_TSItem
  105.  
  106.  
  107.   #include <tv.h>
  108.   #include <help.h>
  109.  
  110.   //
  111.   //these are the constants created by TVHC
  112.   //
  113.  
  114.   #include "testhelp.h"
  115.  
  116.   const int cmAbout     = 100;
  117.   const int cmMyHelp    = 101;
  118.   const int cmMySave    = 102;
  119.   const int cmMyOpen    = 103;
  120.  
  121.   //
  122.   //This is the help file generated from testhelp.txt by TVHC
  123.   //
  124.   const char * HELPFILE = "testhelp.hlp";
  125.  
  126.   //
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  141.   VERSION  :  3.1
  142.        OS  :  DOS
  143.      DATE  :  August 30, 1993                         PAGE  :  3/11
  144.  
  145.     TITLE  :  Context sensitive help example (Turbo Vision)
  146.  
  147.  
  148.  
  149.  
  150.   //Statusline hints help give the user information
  151.   //
  152.   class THintStatusLine: public TStatusLine
  153.   {
  154.  
  155.   public:
  156.  
  157.        THintStatusLine(TRect& r, TStatusDef& d)
  158.             : TStatusLine(r, d) {}
  159.        const char* hint(ushort);
  160.   };
  161.  
  162.  
  163.   //
  164.   //Here we return a hint depending on the current help context
  165.   //
  166.   const char* THintStatusLine::hint(ushort context)
  167.   {
  168.        switch (context)
  169.        {
  170.          case hcNoContext:
  171.            return "";
  172.  
  173.          case hcExit:
  174.            return "Alt-X to Exit";
  175.  
  176.          case hcSave:
  177.            return "Save a file";
  178.  
  179.          case hcEdit:
  180.            return "Edit file";
  181.  
  182.          case hcClose:
  183.            return "Close the current file";
  184.  
  185.          case hcOpen:
  186.            return "Open a file";
  187.  
  188.          case hcAbout:
  189.         return "View the About Box";
  190.  
  191.          case hcHello:
  192.            return "Hello World";
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  207.   VERSION  :  3.1
  208.        OS  :  DOS
  209.      DATE  :  August 30, 1993                         PAGE  :  4/11
  210.  
  211.     TITLE  :  Context sensitive help example (Turbo Vision)
  212.  
  213.  
  214.  
  215.  
  216.          default:
  217.            return "";
  218.        }
  219.   }
  220.  
  221.  
  222.   class TMyApplication : public TApplication
  223.   {
  224.    public:
  225.        TMyApplication();
  226.        TPalette& getPalette() const;
  227.        void getEvent(TEvent&);
  228.        virtual void handleEvent(TEvent&);
  229.        static TMenuBar* initMenuBar(TRect);
  230.        static TStatusLine* initStatusLine(TRect);
  231.   };
  232.  
  233.  
  234.   TMyApplication::TMyApplication()
  235.        : TProgInit(initStatusLine,initMenuBar,initDeskTop)
  236.   {
  237.   }
  238.  
  239.  
  240.   TPalette& TMyApplication::getPalette() const
  241.   {
  242.        //
  243.        //We need to add palette entries for the help screen
  244.        //
  245.        static TPalette
  246.          color(cpColor cHelpColor,
  247.             sizeof(cpColor cHelpColor) - 1);
  248.  
  249.        static TPalette
  250.          blackwhite(cpBlackWhite cHelpBlackWhite,
  251.               sizeof(cHelpBlackWhite) - 1);
  252.        static TPalette
  253.  
  254.          monochrome(cpMonochrome cHelpMonochrome,
  255.                  sizeof(cHelpMonochrome) - 1);
  256.  
  257.        static TPalette *palettes[] =
  258.        {
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  273.   VERSION  :  3.1
  274.        OS  :  DOS
  275.      DATE  :  August 30, 1993                         PAGE  :  5/11
  276.  
  277.     TITLE  :  Context sensitive help example (Turbo Vision)
  278.  
  279.  
  280.  
  281.  
  282.          &color,
  283.          &blackwhite,
  284.          &monochrome
  285.        };
  286.  
  287.        return *(palettes [appPalette] );
  288.   }
  289.  
  290.  
  291.   //
  292.   //We use the Application getEvent to access help requests
  293.   //from any view.
  294.   //
  295.   void TMyApplication::getEvent(TEvent& event)
  296.   {
  297.        static Boolean helpInUse = False;
  298.  
  299.        TProgram::getEvent(event);
  300.        if (event.what == evCommand)
  301.        {
  302.  
  303.          switch (event.message.command)
  304.          {
  305.  
  306.            case cmMyHelp:
  307.               if (helpInUse == True)
  308.                  return;
  309.  
  310.               fpstream& helpStream = *new fpstream(HELPFILE,
  311.                      ios::in | ios::binary);
  312.               THelpFile* helpFile = new THelpFile(helpStream);
  313.  
  314.               if (!helpStream)
  315.               {
  316.            messageBox("Could not open help file NEWHELP.HLP",
  317.                       mfError | mfOKButton);
  318.                     delete helpFile;
  319.               }
  320.               else
  321.               {
  322.                  helpInUse = True;
  323.                  TWindow* window =
  324.                  (TWindow*)validView(new THelpWindow(helpFile,
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  339.   VERSION  :  3.1
  340.        OS  :  DOS
  341.      DATE  :  August 30, 1993                         PAGE  :  6/11
  342.  
  343.     TITLE  :  Context sensitive help example (Turbo Vision)
  344.  
  345.  
  346.  
  347.  
  348.                               getHelpCtx() ) );
  349.                  if (window)
  350.                  {
  351.                     execView(window);
  352.                     destroy(window);
  353.                     helpInUse = False;
  354.                  }
  355.                  clearEvent(event);
  356.               }
  357.  
  358.              break;
  359.          }
  360.        }
  361.  
  362.   }
  363.  
  364.  
  365.   //
  366.   //Application handleEvent
  367.   //
  368.   void TMyApplication::handleEvent(TEvent &event)
  369.   {
  370.        TApplication::handleEvent(event);
  371.  
  372.        if (event.what == evCommand)
  373.        {
  374.          switch (event.message.command)
  375.          {
  376.            case cmAbout:
  377.             TDialog *pd =
  378.                new TDialog(TRect(20,4,60,20), "About");
  379.             if( validView(pd) )
  380.             {
  381.                //
  382.                //assign help context to this view
  383.                //
  384.                pd->helpCtx = hcAboutBox;
  385.                //
  386.                //insert Statictext
  387.                //
  388.                pd->insert( new TStaticText(TRect(5,3,35,6),
  389.                    "\003TestHelp About Box\n\n\003Provided by"
  390.                    "\n\n\003Borland Technical Support"));
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  405.   VERSION  :  3.1
  406.        OS  :  DOS
  407.      DATE  :  August 30, 1993                         PAGE  :  7/11
  408.  
  409.     TITLE  :  Context sensitive help example (Turbo Vision)
  410.  
  411.  
  412.  
  413.  
  414.                TRadioButtons *rb =
  415.                       new TRadioButtons(TRect(7,7,32,9),
  416.                            new TSItem("One",
  417.                            new TSItem("Two",
  418.                            new TSItem("Three",
  419.                            new TSItem("Four", 0) ))));
  420.                //
  421.                //assign help context to the RadioButtons
  422.                //
  423.                rb->helpCtx = hcAboutRadio;
  424.                pd->insert(rb);
  425.  
  426.                pd->insert(new TButton(TRect(15,10,25,12),
  427.                        "~O~k", cmOK, bfDefault) );
  428.                execView(pd);
  429.                destroy(pd);
  430.             }
  431.          }
  432.          clearEvent (event);
  433.        }
  434.   }
  435.  
  436.  
  437.   //
  438.   //Application MenuBar - this method of building a menu will
  439.   //      never produce the 'out of memory' problem generated
  440.   //      by nested menus.
  441.   //
  442.   TMenuBar* TMyApplication::initMenuBar(TRect r)
  443.   {
  444.        r.b.y = r.a.y + 1;
  445.  
  446.       TSubMenu& sub1 =
  447.           *new TSubMenu("~≡~", kbAltSpace, hcNoContext ) +
  448.           *new TMenuItem("~A~bout...", cmAbout, 0, hcAbout, 0, 0)+
  449.           *new TMenuItem("E~x~it", cmQuit, kbAltX, hcExit, 0, 0);
  450.  
  451.       TSubMenu& sub2 = *new TSubMenu( "~T~est", kbAltT, hcTest) +
  452.           *new TMenuItem( "~H~ello", cmOK, kbAltH, hcHello, 0, 0);
  453.  
  454.       TSubMenu& sub3 = *new TSubMenu( "~F~ile", kbNoKey, hcFile)+
  455.           *new TMenuItem( "~S~ave", cmOK, kbAltS, hcSave, 0, 0) +
  456.           *new TMenuItem( "~E~dit", cmOK, kbAltE, hcEdit, 0, 0) +
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  471.   VERSION  :  3.1
  472.        OS  :  DOS
  473.      DATE  :  August 30, 1993                         PAGE  :  8/11
  474.  
  475.     TITLE  :  Context sensitive help example (Turbo Vision)
  476.  
  477.  
  478.  
  479.  
  480.           *new TMenuItem( "~O~pen", cmOK, kbAltO, hcOpen, 0, 0);
  481.  
  482.       TMenuBar * menuBar =
  483.           new TMenuBar( r, new TMenu((TMenuItem &)
  484.             (sub1 + sub2 + sub3)));
  485.  
  486.       return menuBar;
  487.   }
  488.  
  489.  
  490.   //
  491.   //Application statusline
  492.   //
  493.   TStatusLine* TMyApplication::initStatusLine(TRect r)
  494.   {
  495.        r.a.y = r.b.y - 1;
  496.  
  497.        //standard statusline help
  498.        return new THintStatusLine( r,
  499.          *new TStatusDef(hcNoContext, hcEndStandard ) +
  500.            *new TStatusItem("~F1~ Help", kbF1, cmMyHelp) +
  501.            *new TStatusItem("~Alt+X~ Exit", kbAltX, cmQuit ) +
  502.  
  503.        //statusline help for your about box
  504.          *new TStatusDef(hcAboutBox, hcAboutBox) +
  505.            *new TStatusItem("~F1~ Help", kbF1, cmMyHelp) +
  506.            *new TStatusItem("~Esc~ to Close Dialog", kbEsc,
  507.                 cmClose));
  508.  
  509.   }
  510.  
  511.   int main()
  512.   {
  513.        TMyApplication *Myapp = new TMyApplication();
  514.        Myapp->deskTop->helpCtx = hcNoContext;
  515.        Myapp->run();
  516.        TProgram::destroy(Myapp);
  517.        return 0;
  518.   }
  519.   **** END FILE: TESTHELP.CPP ****
  520.   **** BEGIN FILE: TESTHELP.TXT ****
  521.   .topic Nocontext=0
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  537.   VERSION  :  3.1
  538.        OS  :  DOS
  539.      DATE  :  August 30, 1993                         PAGE  :  9/11
  540.  
  541.     TITLE  :  Context sensitive help example (Turbo Vision)
  542.  
  543.  
  544.  
  545.  
  546.    ╔══════════════════╗
  547.    ║ Test Help System ║
  548.    ╚══════════════════╝
  549.   To create the boxes, use the IBM extended characters.  Generate
  550.   these characters by pressing 'Alt keycode,' for instance: to
  551.   generate ╗ hold down the Alt key and press (on the numeric key
  552.   pad) 187, then release the Alt key.
  553.  
  554.   Short cut:
  555.    Notice .topic NoContext=0 and .topic Edit=1100 are the only
  556.    explicit assignments in this help file.  TVHC (Turbo Vision
  557.    Help Compiler) will automatically assign values to all other
  558.    topic contexts.  These values are placed into a XXXX.h file
  559.    which should be placed into your source file.  Thus, future
  560.    changes to the help file will only require recompiling the
  561.    help file and application, and no explicit changes to the
  562.    source code will be necessary.
  563.  
  564.     Operations
  565.     ▀▀▀▀▀▀▀▀▀▀
  566.  
  567.         {Edit}
  568.         {File Stuff:File}
  569.         {Exit}
  570.  
  571.  
  572.   .topic Edit=1000
  573.  
  574.    ╔══════════════╗
  575.    ║ Edit Control ║
  576.    ╚══════════════╝
  577.  
  578.   This is where you tell your users how to edit a file.
  579.  
  580.  
  581.  
  582.  
  583.   .topic File
  584.  
  585.    ╔══════════════╗
  586.    ║ File Control ║
  587.    ╚══════════════╝
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  603.   VERSION  :  3.1
  604.        OS  :  DOS
  605.      DATE  :  August 30, 1993                        PAGE  :  10/11
  606.  
  607.     TITLE  :  Context sensitive help example (Turbo Vision)
  608.  
  609.  
  610.  
  611.  
  612.    File Operations:
  613.  
  614.          {Open}
  615.          {Close}
  616.          {Save}
  617.          {What ever:What}
  618.  
  619.  
  620.   .topic Exit
  621.  
  622.    ╔══════╗
  623.    ║ Exit ║
  624.    ╚══════╝
  625.  
  626.   Use Alt-X to exit the testhelp.
  627.  
  628.  
  629.  
  630.   .topic Open
  631.  
  632.   Open a file with the open command.
  633.  
  634.  
  635.   .topic Close
  636.  
  637.   Close a file to close it.
  638.  
  639.  
  640.   .topic Save
  641.  
  642.   Save a file to save it.
  643.  
  644.  
  645.   .topic What
  646.  
  647.   To do whatever to a file, talk about it here.
  648.  
  649.  
  650.   .topic About
  651.  
  652.   TestHelp About
  653.  
  654.   .topic Test
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.   PRODUCT  :  Borland C++                           NUMBER  :  1554
  669.   VERSION  :  3.1
  670.        OS  :  DOS
  671.      DATE  :  August 30, 1993                        PAGE  :  11/11
  672.  
  673.     TITLE  :  Context sensitive help example (Turbo Vision)
  674.  
  675.  
  676.  
  677.  
  678.   This is a Test
  679.  
  680.   .topic Hello
  681.  
  682.   Hello World, Help!
  683.  
  684.  
  685.   .topic AboutRadio
  686.  
  687.   Help for RadioButton ONE.
  688.  
  689.   .topic radio2
  690.  
  691.   Help for RadioButton TWO.
  692.  
  693.   .topic radio3
  694.  
  695.   Help for RadioButton THREE.
  696.  
  697.   .topic radio4
  698.  
  699.   Help for RadioButton FOUR.
  700.  
  701.   .topic AboutBox
  702.  
  703.   You are now in the TestHelp about box.  Turbo Vision knows this
  704.   because the TApplication::getEvent is overloaded and events can
  705.   be captured from any view... including this dialog box.
  706.  
  707.  
  708.   .topic EndStandard
  709.  
  710.   ****************************************************************
  711.   this is the dummy help context which is the end of standard help
  712.   ****************************************************************
  713.  
  714.   **** END FILE: TESTHELP.TXT ****
  715.  
  716.  
  717.   DISCLAIMER: You have the right to use this technical information
  718.   subject to the terms of the No-Nonsense License Statement that
  719.   you received with the Borland product to which this information
  720.   pertains.
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.