home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a065 / 1.img / TBPRGS.EXE / TBINSP.PRG < prev    next >
Encoding:
Text File  |  1992-03-10  |  8.9 KB  |  232 lines

  1. // Tbinsp.prg
  2. //
  3. // Tbrowse inspector - display all instance vars in pop - up
  4. //                     window - Allows editing. Also displays
  5. //                     methods in another, allowing invocation
  6. //
  7. // Compile with /a /m /n /w
  8. //
  9. // Link with Tbindemo for test
  10.  
  11. #include "Inkey.ch"
  12. #include "Setcurs.ch"
  13.  
  14. MEMVAR getlist
  15.  
  16. FUNCTION TbDisp(oTbr)
  17.  
  18. #define GSBIVAR(i)  {|o, n| iif(n == NIL, o:i, o:i := n) }
  19.  
  20. // Array contains Ivar name, a get / set block for it, 
  21. // and whether is is assignable
  22. STATIC aTbIvars := { ;
  23.             { "colorSpec",   GSBIVAR(colorSpec),     .T. }, ;
  24.             { "autoLite",    GSBIVAR(autoLite),      .T. }, ;
  25.             { "colCount",    GSBIVAR(colCount) ,     .F. }, ;
  26.             { "colPos",      GSBIVAR(colPos),        .T. }, ;
  27.             { "colSep",      GSBIVAR(colSep),        .T. }, ;
  28.             { "freeze",      GSBIVAR(freeze),        .T. }, ;
  29.             { "headSep",     GSBIVAR(headSep),       .T. }, ;
  30.             { "hitBottom",   GSBIVAR(hitBottom),     .T. }, ;
  31.             { "hitTop",      GSBIVAR(hitTop),        .T. }, ;
  32.             { "leftVisible", GSBIVAR(leftVisible),   .F. }, ;
  33.             { "nTop",        GSBIVAR(nTop),          .T. }, ;
  34.             { "nLeft",       GSBIVAR(nLeft),         .T. }, ;
  35.             { "nBottom",     GSBIVAR(nBottom),       .T. }, ;
  36.             { "nRight",      GSBIVAR(nRight),        .T. }, ;
  37.             { "rightVisible",GSBIVAR(rightVisible),  .F. }, ;
  38.             { "rowCount",    GSBIVAR(rowCount),      .F. }, ;
  39.             { "rowPos",      GSBIVAR(rowPos),        .T. }, ;
  40.             { "stable",      GSBIVAR(stable),        .T. }  ;
  41.                    }
  42.  
  43. // Array contains method name, a block to evaluate it, and whether
  44. // we should save / restore the screen before / after evaluating it.
  45. #define INVMETH(m)  {|o|    o:m() }
  46. STATIC aTbMethods := { ;
  47.             {  "down",           INVMETH(down),           .F. }, ;
  48.             {  "end",            INVMETH(end),            .F. }, ;
  49.             {  "goBottom",       INVMETH(goBottom),       .F. }, ;
  50.             {  "goTop",          INVMETH(goTop),          .F. }, ;
  51.             {  "home",           INVMETH(home),           .F. }, ;
  52.             {  "left",           INVMETH(left),           .F. }, ;
  53.             {  "pageDown",       INVMETH(pageDown),       .F. }, ;
  54.             {  "pageUp",         INVMETH(pageUp),         .F. }, ;
  55.             {  "panEnd",         INVMETH(panEnd),         .F. }, ;
  56.             {  "panHome",        INVMETH(panHome),        .F. }, ;
  57.             {  "panLeft",        INVMETH(panLeft),        .F. }, ;
  58.             {  "panRight",       INVMETH(panRight),       .F. }, ;
  59.             {  "right",          INVMETH(right),          .F. }, ;
  60.             {  "up",             INVMETH(up),             .F. }, ;
  61.             {  "addColumn",      INVMETH(addColumn),      .F. }, ;
  62.             {  "colorRect",      INVMETH(colorRect),      .F. }, ;
  63.             {  "colWidth",       INVMETH(colWidth),       .F. }, ;
  64.             {  "configure",      INVMETH(configure),      .F. }, ;
  65.             {  "dehilite",       INVMETH(deHilite),       .F. }, ;
  66.             {  "delColumn",      INVMETH(delColumn),      .F. }, ;
  67.             {  "getColumn",      INVMETH(getColumn),      .F. }, ;
  68.             {  "hilite",         INVMETH(hilite),         .F. }, ;
  69.             {  "insColumn",      INVMETH(insColumn),      .F. }, ;
  70.             {  "invalidate",     INVMETH(invalidate),     .F. }, ;
  71.             {  "refreshCurrent", INVMETH(refreshCurrent), .F. }, ;
  72.             {  "refreshAll",     INVMETH(refreshAll),     .F. }, ;
  73.             {  "setColumn",      INVMETH(setColumn),      .F. }, ;
  74.             {  "stabilize",      INVMETH(stabilize),      .F. }, ;
  75.             {  "Full stabilize", {|o| fullStabilize(o) }, .T. }  ;
  76.                      }
  77.  
  78. LOCAL oTbrTemp1
  79. LOCAL oTbrTemp2
  80. LOCAL cSaveScr
  81. LOCAL i := 1
  82. LOCAL j := 1
  83. LOCAL oTbc
  84. LOCAL lExitRequested := .F.
  85. LOCAL nKey
  86. LOCAL nTop, nLeft, nBottom, nRight
  87. LOCAL nSaveRow := Row(), ;
  88.       nSaveCol := Col()
  89. LOCAL xTemp
  90. LOCAL nSaveCurs
  91. LOCAL oTbrCur
  92. LOCAL cCurScreen
  93.  
  94.   // Determine coordinates for TBrowse window - set coordinates
  95.   // to opposite quarter
  96.   IF nSaveRow > MaxRow() / 2
  97.     nTop := 0
  98.   ELSE
  99.     nTop := Int(MaxRow() / 2)
  100.   ENDIF
  101.   // Round up in case odd maxrow()
  102.   nBottom := nTop + Int((MaxRow() + 1) / 2)
  103.  
  104.   // Save area we will overwrite and frame it
  105.   cSaveScr := SaveScreen(nTop, 0, nBottom, MaxCol())
  106.   @ nTop, 0 TO nBottom, MaxCol()
  107.  
  108.   // Create TBrowse object to display instance variables
  109.   //   Browse array using "i" as the array index
  110.   oTbrTemp1 := TBrowseNew(nTop + 1, 1, ;
  111.                           nBottom - 1, Int(MaxCol() / 2))
  112.  
  113.   oTbrTemp1:goTopBlock    := {|| i := 1}
  114.   oTbrTemp1:goBottomBlock := {|| i := Len(aTbIvars) }
  115.   oTbrTemp1:skipBlock     := {|n, nSavei| ;
  116.                              nSavei := i, ;
  117.                              i := iif(n > 0, ;
  118.                                       Min(i + n, Len(aTbIvars)), ;
  119.                                       Max(1, i + n)), ;
  120.                              i - nSavei  ;
  121.                             }
  122.  
  123.   // TBcolumn for the instance variable
  124.   oTbc := TBColumnNew("Instance Var", {|| aTbIvars[i, 1] })
  125.   oTbc:width := 14
  126.   oTbrTemp1:addColumn(oTbc)
  127.  
  128.   // Column to display its value
  129.   oTbc := TBColumnNew("Current Value", {|| Eval(aTbIvars[i, 2], oTbr) })
  130.   oTbc:width := 14
  131.   oTbrTemp1:addColumn(oTbc)
  132.  
  133.   // Create second TBrowse object to display method names
  134.   //   Browse array using "j" as the array index
  135.   oTbrTemp2 := TBrowseNew(nTop + 1, int(MaxCol() / 2) + 1, ;
  136.                           nBottom - 1, MaxCol() - 1)
  137.  
  138.   oTbc := tbColumnNew("Methods", {|| aTbMethods[j, 1] })
  139.   oTbc:width := 14
  140.   oTbrTemp2:addColumn(oTbc)
  141. //  oTbrTemp2:colSep := chr(179)
  142.  
  143.   oTbrTemp2:goTopBlock    := {|| j := 1}
  144.   oTbrTemp2:goBottomBlock := {|| j := Len(aTbMethods) }
  145.   oTbrTemp2:skipBlock     := {|n, nSavej| ;
  146.                              nSavej := j, ;
  147.                              j := iif(n > 0, ;
  148.                                       min(j + n, len(aTbMethods)), ;
  149.                                       max(1, j + n)), ;
  150.                              j - nSavej  ;
  151.                             }
  152.  
  153.   // We now start our modal TBrowse.
  154.   //   First display method names
  155.  
  156.   DO WHILE !oTbrTemp2:stabilize()
  157.   ENDDO
  158.   oTbrTemp2:dehilite()
  159.  
  160.   // We allow users to move between the two tbrowse objects by using
  161.   // a third variable, oTbrCur, which refers to either oTbrTemp1 (the
  162.   // instance variables), or oTbrTemp2 (the method names).
  163.   // We start on oTbrTemp1
  164.   oTbrCur := oTbrTemp1
  165.   DO WHILE !lExitRequested
  166.     DO WHILE !oTbrCur:stabilize()
  167.     ENDDO
  168.     nKey := inkey(0)
  169.  
  170.     // First check whether user wants to move to the other TBrowse
  171.     // object
  172.     IF nKey == K_RIGHT .AND. oTbrCur == oTbrTemp1 .AND. ;
  173.               oTbrCur:colPos == oTbrCur:colCount
  174.       // Highlight bar was on ivars, now move it to methods
  175.       oTbrCur:deHilite()
  176.       oTbrCur := oTbrTemp2
  177.       IF i != j
  178.         oTbrTemp2:rowPos := oTbrTemp1:rowPos
  179.       ENDIF
  180.     ELSEIF nKey == K_LEFT .AND. oTbrCur == oTbrTemp2 .AND. ;
  181.            oTbrCur:colPos == 1
  182.       // Highlight bar was on methods, now move to ivars
  183.       oTbrCur:deHilite()
  184.       oTbrCur := oTbrTemp1
  185.       IF j != i
  186.         oTbrTemp1:rowPos := oTbrTemp2:rowPos
  187.       ENDIF
  188.     ELSEIF !StdMeth(nKey, oTbrCur)
  189.       DO CASE
  190.         CASE nKey == K_ESC
  191.           lExitRequested := .T.
  192.  
  193.         CASE nKey == K_ENTER
  194.           IF oTbrCur:colPos == 2 .AND. oTbrCur == oTbrTemp1 .AND. ;
  195.              aTbIvars[i, 3]
  196.             // We are on ivar contents column, and it is assignable
  197.             // Edit the ivar
  198.             nSaveCurs := Set(_SET_CURSOR, SC_NORMAL)
  199.  
  200.             // Evaluate its get/set block to get its value
  201.             xTemp := Eval(aTbIvars[i, 2], oTbr)
  202.             @ Row(), Col() GET xTemp
  203.             READ
  204.             IF updated()
  205.               // Now update the ivar by evaluating the get/set block and
  206.               // passing it a parameter
  207.               Eval(aTbIvars[i, 2], oTbr, xTemp)
  208.             ENDIF
  209.             Set(_SET_CURSOR, nSaveCurs)
  210.             oTbrCur:refreshCurrent()
  211.           ELSEIF oTbrCur == oTbrTemp2
  212.             // Highlight bar is on the method and the user just pressed
  213.             // the Enter key
  214.             IF aTbMethods[j, 3]
  215.               // This method will mess up screen - save / restore etc
  216.               cCurScreen := SaveScreen(nTop, 0, nBottom, MaxCol())
  217.               RestScreen(nTop, 0, nBottom, MaxCol(), cSaveScr)
  218.               Eval(aTbMethods[j, 2], oTbr)
  219.               cSaveScr := SaveScreen(nTop, 0, nBottom, MaxCol())
  220.               RestScreen(nTop, 0, nBottom, MaxCol(), cCurScreen)
  221.             ELSE
  222.               Eval(aTbMethods[j, 2], oTbr)
  223.             ENDIF
  224.           ENDIF
  225.       ENDCASE
  226.     ENDIF
  227.   ENDDO
  228.  
  229.   RestScreen(nTop, 0, nBottom, MaxCol(), cSaveScr)
  230.  
  231. RETURN NIL
  232.