home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase v5.5 / CUSTOM.PAK / VCR.CC < prev   
Encoding:
Text File  |  1995-07-18  |  16.1 KB  |  467 lines

  1. ********************************************************************************
  2. *  FILE:         Vcr.cc
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         3/95
  7. *
  8. *  UPDATED:      7/95
  9. *
  10. *  REVISION:     $Revision:   1.15  $
  11. *
  12. *  VERSION:      Visual dBASE
  13. *
  14. *  DESCRIPTION:  This files contains a VCR custom control that can be used
  15. *                for table navigation.  The control consists of 6 buttons
  16. *                with the following functions:
  17. *
  18. *                VCRFirstButton    -- Go to first record
  19. *                VCRPrevPageButton -- Move back a page of records
  20. *                VCRPrevButton     -- Move back one record
  21. *                VCRNextButton     -- Move forward one record
  22. *                VCRNextPageButton -- Move forward one page of records
  23. *                VCRLastButton     -- Go to last record
  24. *
  25. *                Custom Properties
  26. *                -----------------
  27. *                Speedbar (logical) -- if set to .T. will cause buttons to
  28. *                                      behave as if they were on the speedbar,
  29. *                                      i.e. they will not get focus, and you
  30. *                                      will not be able to TAB to them.
  31. *                                      Default -- .F.
  32. *
  33. *                Etched (logical)   -- if set to .T. will define a lowered
  34. *                                      rectangle underneath the buttons to
  35. *                                      give the whole control an "etched" look
  36. *                                      Default -- .F.
  37. *
  38. *                The above names are not the actual names of the buttons.
  39. *                The actual names will be VCRFirstButton1, ... etc.  With
  40. *                the last character being a digit incremented for each
  41. *                instance of the control on the current form.
  42. *                The first button, which is also the container control has
  43. *                have properties that reference each of the other controls.
  44. *                Those references are constant.  For example, the current
  45. *                nextButton control is referenced by this.VcrNextButton.
  46. *                Each of the sub controls, in turn, has a containerControl
  47. *                reference, which refers back to the first button.  These
  48. *                references are all generated in the DefineVCRButton procedure.
  49. *
  50. *
  51. *                Custom Methods
  52. *                --------------
  53. *                You can define routines to be executed before and after the
  54. *                OnClick routine for each of the VCR buttons.  To execute
  55. *                these routines, you would assign an appropriate function
  56. *                pointer to one of the following custom properties:
  57. *
  58. *                   BeforeFirstOnClick
  59. *                   AfterFirstOnClick
  60. *                   BeforePrevPageOnClick
  61. *                   AfterPrevPageOnClick
  62. *                   BeforePrevOnClick
  63. *                   AfterPrevOnClick
  64. *                   BeforeNextOnClick
  65. *                   AfterNextOnClick
  66. *                   BeforeNextPageOnClick
  67. *                   AfterNextPageOnClick
  68. *                   BeforeLastOnClick
  69. *                   AfterLastOnClick
  70. *
  71. *
  72. *  PARAMETERS:   None
  73. *
  74. *  CALLS:        None
  75. *
  76. *  USAGE:        When creating a form, select the "Set Up Custom Controls"
  77. *                menu from the "File" menu.  Select this file from the
  78. *                "dBASE Custom Controls" page of the "Set Up Custom
  79. *                Controls" dialog and then select "Add".  The custom
  80. *                control in this file will be available on the
  81. *                "Custom" page of the "Controls" window.
  82. *
  83. ********************************************************************************
  84.  
  85.  
  86. *******************************************************************************
  87. class VCRButtons(f,n) of Rectangle(f,n) custom
  88.  
  89. *  CONTROL:      VCR table traversing buttons
  90. *
  91. *  DESCRIPTION:  This control is a Rectangle, which defines 6 buttons for
  92. *                traversing a table in different directions.
  93. *                You can go to the beginning of a table, go back a
  94. *                page of records (whatever you define a page to be
  95. *                -- it is defined as 5 records by default), go back
  96. *                one record, go forward one record, forward a page, or
  97. *                go to the end of the table.
  98. *                All buttons are defined in the constructor for the first
  99. *                button.
  100. *
  101. *******************************************************************************
  102.    #include <Messdlg.h>
  103.  
  104.    #define PAGE_OF_RECORDS           5
  105.    #define VCR_BUTTON_HEIGHT         1.41
  106.    #define VCR_BUTTON_WIDTH          4
  107.    #define NUM_VCR_BUTTONS           6
  108.  
  109.    *** Constructor
  110.  
  111.    local curRec
  112.  
  113.    this.border = .F.
  114.    this.borderStyle = 2
  115.    this.left = 0
  116.    this.top = 0
  117.    this.height = VCR_BUTTON_HEIGHT + .15
  118.    this.width = VCR_BUTTON_WIDTH * 6 + .6
  119.  
  120.    *** Custom Properties for External use
  121.    this.etched = .F.    && Add etched look around buttons?
  122.    this.speedbar = .T.  && Treat buttons as if they are on speedbar?
  123.  
  124.    *** Routines to be executed along with button clicks
  125.    this.BeforeFirstOnClick = {;}
  126.    this.AfterFirstOnClick = {;}
  127.    this.BeforePrevPageOnClick = {;}
  128.    this.AfterPrevPageOnClick = {;}
  129.    this.BeforePrevOnClick = {;}
  130.    this.AfterPrevOnClick = {;}
  131.    this.BeforeNextOnClick = {;}
  132.    this.AfterNextOnClick = {;}
  133.    this.BeforeNextPageOnClick = {;}
  134.    this.AfterNextPageOnClick = {;}
  135.    this.BeforeLastOnClick = {;}
  136.    this.AfterLastOnClick = {;}
  137.  
  138.    *** Events
  139.    this.OnOpen = CLASS::VCRButtons_OnOpen
  140.    this.OnDesignOpen = CLASS::VCRButtons_OnDesignOpen
  141.    this.OnClose = {;close procedure program(1)}
  142.  
  143.    *** Internally Used Custom Properties (for bounds checks)
  144.    curRec = recno()
  145.    go top
  146.    this.firstRec = recno()   && Property for storing first record
  147.    go bottom
  148.    this.lastRec = recno()    && Property for storing last record
  149.    if .not. eof() .and. curRec > 0
  150.       go curRec
  151.    endif
  152.  
  153.  
  154.    ****************************************************************************
  155.    Procedure VCRButtons_OnOpen
  156.    ****************************************************************************
  157.  
  158.    * Define VCR Buttons, if they haven't been defined yet
  159.    if type("this.VCRFirstButton") = "U"
  160.       CLASS::SetUpControl()
  161.    endif
  162.  
  163.  
  164.  
  165.    ****************************************************************************
  166.    Procedure VCRButtons_OnDesignOpen(bFromPalette)
  167.  
  168.    * This procedure is called whenever the control is being designed in the
  169.    * Forms Designer.  It does the exact same thing as the OnOpen -- i.e.
  170.    * defines all the VCR Button controls.
  171.    ****************************************************************************
  172.  
  173.    CLASS::SetUpControl()
  174.  
  175.  
  176.    ****************************************************************************
  177.    procedure SetUpControl
  178.  
  179.    * Defines VCR Buttons, and sets custom properties based on
  180.    * control definition in the form.
  181.    ****************************************************************************
  182.  
  183.    * Temporary variable
  184.    private saveTalk
  185.  
  186.    * Don't want extraneous info on screen when creating control
  187.    if set("talk") = "ON"
  188.       set talk off
  189.       saveTalk = "ON"
  190.    else
  191.       saveTalk = "OFF"
  192.    endif
  193.  
  194.    *** Rest of buttons
  195.    CLASS::DefineVCRButton("VCRFirstButton",;
  196.                               CLASS::VCRFirstButton_OnClick, "851", 1,;
  197.                               "First Record", this.BeforeFirstOnClick,;
  198.                               this.AfterFirstOnClick)
  199.    CLASS::DefineVCRButton("VCRPrevPageButton",;
  200.                               CLASS::VCRPrevPageButton_OnClick, "852", 2,;
  201.                               "Previous Page", this.BeforePrevPageOnClick,;
  202.                               this.AfterPrevPageOnClick)
  203.    CLASS::DefineVCRButton("VCRPrevButton",;
  204.                               CLASS::VCRPrevButton_OnClick, "853", 3,;
  205.                               "Previous Record", this.BeforePrevOnClick,;
  206.                               this.AfterPrevOnClick)
  207.    CLASS::DefineVCRButton("VCRNextButton",;
  208.                               CLASS::VCRNextButton_OnClick, "854", 4,;
  209.                               "Next Record", this.BeforeNextOnClick,;
  210.                               this.AfterNextOnClick)
  211.    CLASS::DefineVCRButton("VCRNextPageButton",;
  212.                               CLASS::VCRNextPageButton_OnClick, "855", 5,;
  213.                               "Next Page", this.BeforeNextPageOnClick,;
  214.                               this.AfterNextPageOnClick)
  215.    CLASS::DefineVCRButton("VCRLastButton",;
  216.                               CLASS::VCRLastButton_OnClick, "856", 6,;
  217.                               "Bottom Record", this.BeforeLastOnClick,;
  218.                               this.AfterLastOnClick)
  219.  
  220.    * Create references to above buttons from this container control
  221.    CLASS::CreateButtonReferences()
  222.  
  223.    * Size and move this control to surround buttons
  224.    *this.top = this.VCRFirstButton.top - .1
  225.    *this.left = this.VCRFirstButton.left - .4
  226.    this.height = this.VCRFirstButton.height + .25
  227.    this.width = this.VCRFirstButton.width * 6 + .6
  228.  
  229.    *** Handle custom properties, if they are assigned
  230.    this.border = this.etched
  231.  
  232.    protect VCRFirstButton, VCRPrevPageButton, VCRPrevButton, VCRNextButton,;
  233.               VCRNextPageButton, VCRLastButton
  234.  
  235.    set talk &saveTalk
  236.  
  237.  
  238.    Function FindFirstVCRButton
  239.       local name
  240.       private control
  241.  
  242.       *control = form.first
  243.       control = this
  244.  
  245.       name = control.name
  246.       bFound = .F.
  247.       do
  248.          if (type("control.bIsVCRButton") <> 'U')
  249.             bFound = .T.
  250.          else
  251.             control = control.before
  252.          endif
  253.       until (control.name == name .or. bFound)
  254.  
  255.       return(control)
  256.  
  257.    ****************************************************************************
  258.    Procedure CreateButtonReferences
  259.  
  260.    * Creates references to all vcr buttons from this container control.
  261.    ****************************************************************************
  262.    private i, vcrButton
  263.  
  264.    vcrButton = this.FindFirstVCRButton()
  265.  
  266.  
  267.    for i = 1 to NUM_VCR_BUTTONS
  268.       do case
  269.          case i = 1
  270.             this.VCRFirstButton = vcrButton
  271.          case i = 2
  272.             this.VCRPrevPageButton = vcrButton
  273.          case i = 3
  274.             this.VCRPrevButton = vcrButton
  275.          case i = 4
  276.             this.VCRNextButton = vcrButton
  277.          case i = 5
  278.             this.VCRNextPageButton = vcrButton
  279.          case i = 6
  280.             this.VCRLastButton = vcrButton
  281.       endcase
  282.       vcrButton = vcrButton.before
  283.    next i
  284.  
  285.    ****************************************************************************
  286.    Procedure DefineVCRButton
  287.  
  288.    * Defines a single VCR Button.
  289.    ****************************************************************************
  290.    parameters buttonName, OnClickRoutine, resourceNum, buttonNum,;
  291.               speedTipText, BeforeOnClickRoutine, AfterOnClickRoutine
  292.  
  293.  
  294.    * Using the class name of the control as its name in control definition
  295.    * will create a unique name for that control
  296.    DEFINE PUSHBUTTON PUSHBUTTON OF FORM;
  297.       PROPERTY;
  298.          OnClick OnClickRoutine,;
  299.          Top this.top + .1,;
  300.          PageNo this.pageNo,;
  301.          UpBitmap "Resource #" + resourceNum,;
  302.          Width VCR_BUTTON_WIDTH,;
  303.          ColorNormal "BtnText/BtnFace",;
  304.          Text "",;
  305.          Group .T.,;
  306.          Height VCR_BUTTON_HEIGHT,;
  307.          Left this.left + VCR_BUTTON_WIDTH * (buttonNum - 1) + .4,;
  308.          SpeedBar this.speedBar,;
  309.          TabStop this.speedBar,;
  310.          SpeedTip speedTipText;
  311.       CUSTOM;
  312.          containerControl this,;
  313.          BeforeOnClick BeforeOnClickRoutine,;
  314.          AfterOnClick AfterOnClickRoutine,;
  315.          bIsVCRButton .T.
  316.  
  317.  
  318.    ****************************************************************************
  319.    Procedure VCRFirstButton_OnClick
  320.  
  321.    * OnClick routine for First button.
  322.    ****************************************************************************
  323.  
  324.    this.BeforeOnClick()
  325.    if CLASS::IsTableOpen()
  326.       if recno() = this.containerControl.firstRec
  327.          AlertMessage("At the first record","Alert")
  328.       else
  329.          go top
  330.       endif
  331.    endif
  332.    this.AfterOnClick()
  333.  
  334.  
  335.    ****************************************************************************
  336.    Procedure VCRPrevPageButton_OnClick
  337.  
  338.    * OnClick routine for PrevPage button.
  339.    ****************************************************************************
  340.  
  341.    this.BeforeOnClick()
  342.    if CLASS::IsTableOpen()
  343.       skip -PAGE_OF_RECORDS
  344.       CLASS::CheckBOF()
  345.    endif
  346.    this.AfterOnClick()
  347.  
  348.  
  349.    ****************************************************************************
  350.    Procedure VCRPrevButton_OnClick
  351.  
  352.    * OnClick routine for Prev button.
  353.    ****************************************************************************
  354.  
  355.    this.BeforeOnClick()
  356.    if CLASS::IsTableOpen()
  357.       skip - 1
  358.       CLASS::CheckBOF()
  359.    endif
  360.    this.AfterOnClick()
  361.  
  362.  
  363.    ****************************************************************************
  364.    Procedure VCRNextButton_OnClick
  365.  
  366.    * OnClick routine for Next button.
  367.    ****************************************************************************
  368.  
  369.    this.BeforeOnClick()
  370.    if CLASS::IsTableOpen()
  371.       skip
  372.       CLASS::CheckEOF()
  373.    endif
  374.    this.AfterOnClick()
  375.  
  376.  
  377.    ****************************************************************************
  378.    Procedure VCRNextPageButton_OnClick
  379.  
  380.    * OnClick routine for NextPage button.
  381.    ****************************************************************************
  382.  
  383.    this.BeforeOnClick()
  384.    if CLASS::IsTableOpen()
  385.       skip PAGE_OF_RECORDS
  386.       CLASS::CheckEOF()
  387.    endif
  388.    this.AfterOnClick()
  389.  
  390.  
  391.    ****************************************************************************
  392.    Procedure VCRLastButton_OnClick
  393.  
  394.    * OnClick routine for Last button.
  395.    ****************************************************************************
  396.  
  397.    this.BeforeOnClick()
  398.    if CLASS::IsTableOpen()
  399.       if recno() = this.containerControl.lastRec
  400.          AlertMessage("At the last record","Alert")
  401.       else
  402.          go bottom
  403.       endif
  404.    endif
  405.    this.AfterOnClick()
  406.  
  407.  
  408.    **************************** Support Functions *****************************
  409.  
  410.    ****************************************************************************
  411.    Function IsTableOpen
  412.    ****************************************************************************
  413.    private tableOpen
  414.  
  415.    if empty(dbf())      && if a table is not open in the current workarea
  416.       InformationMessage("There is no table open in the current workarea.",;
  417.          "Info")
  418.       tableOpen = .F.
  419.    else
  420.       tableOpen = .T.
  421.    endif
  422.  
  423.    return tableOpen
  424.  
  425.  
  426.    ****************************************************************************
  427.    Procedure CheckEOF
  428.    ****************************************************************************
  429.  
  430.    if eof()
  431.       go bottom
  432.       AlertMessage("At the last record","Alert")
  433.    endif
  434.  
  435.  
  436.    ****************************************************************************
  437.    Procedure CheckBOF
  438.    ****************************************************************************
  439.  
  440.    if bof()
  441.       go top
  442.       AlertMessage("At the first record","Alert")
  443.    endif
  444.  
  445.  
  446.    ****************************************************************************
  447.    Procedure Release
  448.  
  449.    * Redefinition of built in Release() method.
  450.    * Release all subcontrols, and then call the built in Release() method.
  451.    ****************************************************************************
  452.  
  453.    if type("this.VCRFirstButton") <> "U"        && Subcontrols defined in
  454.       this.VCRFirstButton.Release()             && OnOpen, so if control is
  455.       this.VCRPrevPageButton.Release()          && released before form is open
  456.       this.VCRPrevButton.Release()              && they will be undefined.
  457.       this.VCRNextButton.Release()
  458.       this.VCRNextPageButton.Release()
  459.       this.VCRLastButton.Release()
  460.    endif
  461.    SUPER::Release()
  462.  
  463.  
  464. endclass
  465.  
  466.  
  467.