home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / TI_BC1.ZIP / TI1555.ZIP / TI1555.ASC
Text File  |  1993-08-31  |  11KB  |  529 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1555
  9.   VERSION  :  3.x
  10.        OS  :  DOS
  11.      DATE  :  August 31, 1993                          PAGE  :  1/8
  12.  
  13.     TITLE  :  Example of a restricted InputLine (Turbo Vision)
  14.  
  15.  
  16.  
  17.  
  18.   This document contains 3 files:
  19.  
  20.      RANGELIN.HPP
  21.      RANGELIN.CPP
  22.      INPUTEST.CPP
  23.  
  24.   **** BEGIN FILE: RANGELIN.HPP ****
  25.   /* -----------------------------------------------------------*/
  26.   /*                                                            */
  27.   /*   RANGELIN.HPP                                             */
  28.   /*                                                            */
  29.   /*   Copyright (c) Borland International 1991                 */
  30.   /*   All Rights Reserved.                                     */
  31.   /*                                                            */
  32.   /*   defines the class RangeLine                              */
  33.   /*                                                            */
  34.   /* -----------------------------------------------------------*/
  35.  
  36.   #ifndef __RANGELINE_
  37.   #define __RANGELINE_
  38.  
  39.   #define Uses_TInputLine
  40.   #define Uses_TEvent
  41.   #include <tv.h>
  42.  
  43.   //  Input Flags masks
  44.   const ushort
  45.       ifUpper         = 0x001,    //allow uppercase characters
  46.       ifLower         = 0x002,    //allow owercase characters
  47.       ifNum           = 0x004,    //allow digits
  48.       ifSpace         = 0x008,    //allow spaces
  49.       ifRange         = 0x010,    //a range of values will follow
  50.       ifDefault       = 0x020;    //allow all printable chars
  51.  
  52.  
  53.   class RangeLine : public TInputLine
  54.   {
  55.      short inputFlags;
  56.      short begin, end;
  57.  
  58.      public:
  59.       RangeLine(const TRect& bounds, int aMaxLen, ushort iMask,
  60.         short a = 0, short b=0):
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1555
  75.   VERSION  :  3.x
  76.        OS  :  DOS
  77.      DATE  :  August 31, 1993                          PAGE  :  2/8
  78.  
  79.     TITLE  :  Example of a restricted InputLine (Turbo Vision)
  80.  
  81.  
  82.  
  83.  
  84.       TInputLine( bounds, aMaxLen )
  85.       {
  86.          inputFlags = iMask;
  87.          begin = a;
  88.          end   = b;
  89.       }
  90.      protected:
  91.       virtual void handleEvent( TEvent& event );
  92.  
  93.   };
  94.  
  95.   #endif  //_RANGELINE_
  96.   **** END FILE: RANGELIN.HPP ****
  97.   **** BEGIN FILE: RANGELIN.CPP ****
  98.   /* -----------------------------------------------------------*/
  99.   /*                                                            */
  100.   /*   RANGELIN.CPP                                             */
  101.   /*                                                            */
  102.   /*   Copyright (c) Borland International 1991                 */
  103.   /*   All Rights Reserved.                                     */
  104.   /*                                                            */
  105.   /*   class RangeLine                                          */
  106.   /*                                                            */
  107.   /* -----------------------------------------------------------*/
  108.  
  109.   #include "rangelin.hpp"
  110.   #include <stdio.h>       //putchar
  111.   #include <ctype.h>       //isalpha, isdigit ...
  112.   #include <string.h>      //strncpy
  113.  
  114.  
  115.   void RangeLine::handleEvent(TEvent& event )
  116.   {
  117.       static char beep = '\a';
  118.       if( isprint(event.keyDown.charScan.charCode) )
  119.       {
  120.         if( ifDefault & inputFlags ||
  121.           (ifUpper & inputFlags &&
  122.             isupper(event.keyDown.charScan.charCode))||
  123.           (ifLower & inputFlags &&
  124.             islower(event.keyDown.charScan.charCode))||
  125.           (ifNum   & inputFlags &&
  126.             isdigit(event.keyDown.charScan.charCode))||
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1555
  141.   VERSION  :  3.x
  142.        OS  :  DOS
  143.      DATE  :  August 31, 1993                          PAGE  :  3/8
  144.  
  145.     TITLE  :  Example of a restricted InputLine (Turbo Vision)
  146.  
  147.  
  148.  
  149.  
  150.           (ifSpace & inputFlags &&
  151.             isspace(event.keyDown.charScan.charCode)) )
  152.           {
  153.             if( ifRange & inputFlags )
  154.               if( (event.keyDown.charScan.charCode < begin) ||
  155.                 (event.keyDown.charScan.charCode > end) )
  156.               {
  157.                  putchar(beep);
  158.                  clearEvent(event);
  159.                  return;
  160.               }
  161.  
  162.            }
  163.            else
  164.            {
  165.               putchar(beep);
  166.               clearEvent(event);
  167.               return;
  168.            }
  169.  
  170.       }
  171.  
  172.       TInputLine::handleEvent( event );
  173.  
  174.   }
  175.   **** END FILE: RANGELIN.CPP ****
  176.   **** BEGIN FILE: INPUTEST.CPP ****
  177.   /*************************************************************
  178.   **                           Inputest.cpp
  179.   **
  180.   **
  181.   **  Example of a TInputline implementation of a range inputLine.
  182.   **
  183.   **
  184.   **  Compile with: Bcc -ml inputest.cpp rangelin.cpp tv.lib
  185.   **
  186.   ***************************************************************/
  187.  
  188.   #define Uses_MsgBox
  189.   #define Uses_TApplication
  190.   #define Uses_TEventQueue
  191.   #define Uses_TEvent
  192.   #define Uses_TKeys
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1555
  207.   VERSION  :  3.x
  208.        OS  :  DOS
  209.      DATE  :  August 31, 1993                          PAGE  :  4/8
  210.  
  211.     TITLE  :  Example of a restricted InputLine (Turbo Vision)
  212.  
  213.  
  214.  
  215.  
  216.   #define Uses_TRect
  217.   #define Uses_TMenuBar
  218.   #define Uses_TSubMenu
  219.   #define Uses_TMenuItem
  220.   #define Uses_TStatusLine
  221.   #define Uses_TStatusItem
  222.   #define Uses_TStatusDef
  223.   #define Uses_TDeskTop
  224.   #define Uses_TView
  225.   #define Uses_TWindow
  226.   #define Uses_TMenu
  227.   #define Uses_TDialog
  228.   #define Uses_TStaticText
  229.   #define Uses_TInputLine
  230.   #define Uses_TButton
  231.   #define Uses_TRect
  232.   #define Uses_TLabel
  233.  
  234.  
  235.   #include <stdio.h>        //for puts
  236.   #include "rangelin.hpp"   //rangeline
  237.   #include <tv.h>
  238.  
  239.   const int cmTest = 100;
  240.  
  241.  
  242.   class TMyApp : public TApplication
  243.   {
  244.  
  245.   public:
  246.        TMyApp();
  247.        void handleEvent(TEvent& event);
  248.        void Test(void);
  249.  
  250.   protected:
  251.        static TMenuBar *initMenuBar( TRect );
  252.        static TStatusLine *initStatusLine( TRect );
  253.  
  254.   };
  255.  
  256.  
  257.   TMyApp::TMyApp() :
  258.        TProgInit( initStatusLine,
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                           NUMBER  :  1555
  273.   VERSION  :  3.x
  274.        OS  :  DOS
  275.      DATE  :  August 31, 1993                          PAGE  :  5/8
  276.  
  277.     TITLE  :  Example of a restricted InputLine (Turbo Vision)
  278.  
  279.  
  280.  
  281.  
  282.                initMenuBar,
  283.                initDeskTop
  284.              )
  285.   {
  286.      //
  287.      //put an event on the queue to bring up the dialog on
  288.      //start-up.
  289.      //
  290.      TEvent e;
  291.      e.what = evCommand;
  292.      e.message.command = cmTest;
  293.      putEvent( e );
  294.  
  295.   }
  296.  
  297.  
  298.   void TMyApp::Test(void)
  299.   {
  300.  
  301.       TDialog *pd =
  302.       new TDialog( TRect( 10,2,70,20), "Test Dialog");
  303.       if( validView( pd ) )
  304.       {
  305.          RangeLine *numLine =
  306.          new RangeLine( TRect(5,3,25,4), 50, ifNum );
  307.          pd->insert(numLine);
  308.          pd->insert( new TLabel(TRect(4,2,20,3),
  309.            "~N~umber Input", numLine));
  310.  
  311.          RangeLine *LowerLine =
  312.          new RangeLine( TRect(5,7,25,8), 50, ifLower);
  313.          pd->insert(LowerLine);
  314.          pd->insert( new TLabel(TRect(4,6,20,7),
  315.            "~L~ower Case", LowerLine));
  316.  
  317.          RangeLine *UpperLine =
  318.          new RangeLine( TRect(5,11,25,12), 50, ifUpper);
  319.          pd->insert(UpperLine);
  320.          pd->insert( new TLabel(TRect(4,10,20,11),
  321.            "~U~pper Case", UpperLine));
  322.  
  323.          RangeLine *DefaultLine =
  324.          new RangeLine( TRect(5,14,25,15), 50, ifDefault);
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Borland C++                           NUMBER  :  1555
  339.   VERSION  :  3.x
  340.        OS  :  DOS
  341.      DATE  :  August 31, 1993                          PAGE  :  6/8
  342.  
  343.     TITLE  :  Example of a restricted InputLine (Turbo Vision)
  344.  
  345.  
  346.  
  347.  
  348.          pd->insert(DefaultLine);
  349.          pd->insert( new TLabel(TRect(4,13,20,14),
  350.            "~D~efault", DefaultLine));
  351.  
  352.          RangeLine *UpperLower =
  353.          new RangeLine( TRect(35,3,55,4), 50, ifUpper|ifLower);
  354.          pd->insert(UpperLower);
  355.          pd->insert( new TLabel(TRect(34,2,55,3),
  356.            "~B~oth Upper and Lower", UpperLower));
  357.  
  358.          RangeLine *NumRange =
  359.          new RangeLine(TRect(35,7,55,8),50,ifNum|ifRange,'0','5');
  360.          pd->insert(NumRange);
  361.          pd->insert( new TLabel(TRect(34,6,55,7),
  362.            "~D~igits 0-5",NumRange));
  363.  
  364.          RangeLine *AlphaSpace =
  365.          new RangeLine( TRect(35,11,55,12), 50,
  366.            ifUpper|ifLower|ifSpace);
  367.          pd->insert(AlphaSpace);
  368.          pd->insert( new TLabel(TRect(34,10,55,11),
  369.            "~A~lpha w/Space", AlphaSpace));
  370.  
  371.          pd->selectNext(False);
  372.  
  373.          deskTop->execView(pd);
  374.       }
  375.       destroy(pd);
  376.  
  377.   }
  378.  
  379.  
  380.   void TMyApp::handleEvent(TEvent& event)
  381.   {
  382.  
  383.     TApplication::handleEvent( event );
  384.  
  385.      if( event.what == evCommand )
  386.      {
  387.         switch( event.message.command)
  388.         {
  389.        case cmTest:
  390.          Test();
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.   PRODUCT  :  Borland C++                           NUMBER  :  1555
  405.   VERSION  :  3.x
  406.        OS  :  DOS
  407.      DATE  :  August 31, 1993                          PAGE  :  7/8
  408.  
  409.     TITLE  :  Example of a restricted InputLine (Turbo Vision)
  410.  
  411.  
  412.  
  413.  
  414.          break;
  415.  
  416.        default:
  417.          break;
  418.         }
  419.         clearEvent( event );
  420.      }
  421.  
  422.  
  423.   }
  424.  
  425.  
  426.   TStatusLine *TMyApp::initStatusLine(TRect r)
  427.   {
  428.      r.a.y = r.b.y - 1;
  429.  
  430.      return new TStatusLine( r,
  431.          *new TStatusDef( 0, 0xFFFF) +
  432.          *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit) +
  433.          *new TStatusItem( "~Alt-T~ Test", kbAltT, cmTest)
  434.          );
  435.  
  436.   }
  437.  
  438.  
  439.   TMenuBar *TMyApp::initMenuBar( TRect r )
  440.   {
  441.       r.b.y = r.a.y + 1;
  442.  
  443.      TMenuItem *two =
  444.         new TMenuItem("~E~xit", cmQuit, kbAltX);
  445.  
  446.      TMenuItem *one =
  447.         new TMenuItem("~\xF0~", kbAltSpace,
  448.        new TMenu( *new TMenuItem("~T~est", cmTest, kbAltT)),
  449.             hcNoContext, two);
  450.  
  451.       return ( new TMenuBar( r, new TMenu( *one ) )  );
  452.  
  453.   }
  454.  
  455.  
  456.   int main()
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.   PRODUCT  :  Borland C++                           NUMBER  :  1555
  471.   VERSION  :  3.x
  472.        OS  :  DOS
  473.      DATE  :  August 31, 1993                          PAGE  :  8/8
  474.  
  475.     TITLE  :  Example of a restricted InputLine (Turbo Vision)
  476.  
  477.  
  478.  
  479.  
  480.   {
  481.  
  482.     TMyApp *myApp = new TMyApp();
  483.     myApp->run();
  484.     return 0;
  485.   }
  486.   **** END FILE: INPUTEST.CPP ****
  487.  
  488.  
  489.   DISCLAIMER: You have the right to use this technical information
  490.   subject to the terms of the No-Nonsense License Statement that
  491.   you received with the Borland product to which this information
  492.   pertains.
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.