home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / truegrid / disk1 / graphic / graphic.$ / TGUTILS.BAS < prev    next >
Encoding:
BASIC Source File  |  1995-02-17  |  9.5 KB  |  326 lines

  1. Option Explicit
  2.  
  3. Function TgFindColumn (ctl As TrueGrid, ByVal txt As String) As Integer
  4.     
  5.     ' ==========================================================
  6.     ' Sub: TgFindColumn
  7.     '
  8.     ' Given a string which represents a field name (or a heading)
  9.     ' this routine returns the column index of the column, or
  10.     ' zero.
  11.     ' ==========================================================
  12.  
  13.     Dim i As Integer
  14.  
  15.     TgFindColumn = 0
  16.     txt = UCase$(txt)
  17.  
  18.     ' Search fields first
  19.  
  20.     For i = 1 To ctl.Columns
  21.     If txt = UCase$(ctl.ColumnField(i)) Then
  22.         TgFindColumn = i
  23.         Exit Function
  24.     End If
  25.     Next
  26.  
  27.     ' Now search for headings
  28.  
  29.     For i = 1 To ctl.Columns
  30.     If txt = UCase$(ctl.ColumnName(i)) Then
  31.         TgFindColumn = i
  32.         Exit Function
  33.     End If
  34.     Next
  35.  
  36. End Function
  37.  
  38. Function TgGetVisibleCols (ctl As TrueGrid) As Integer
  39.     ' ==========================================================
  40.     ' Sub: TgGetVisibleCols
  41.     '
  42.     ' Returns the number of columns which are visible in the
  43.     ' current split.  The setting of SplitPropsGlobal is
  44.     ' irrelevant since ColumnVisible always RETURNS the
  45.     ' value for the current split.
  46.     ' ==========================================================
  47.  
  48.     Dim ret As Integer
  49.     Dim i As Integer
  50.  
  51.     ret = 0
  52.  
  53.     For i = 1 To ctl.Columns
  54.     If ctl.ColumnVisible(i) Then ret = ret + 1
  55.     Next i
  56.  
  57.     TgGetVisibleCols = ret
  58.  
  59. End Function
  60.  
  61. Sub TgLockColumn (ctl As TrueGrid, ByVal col As Integer, atleft As Integer)
  62.     
  63.     ' ==========================================================
  64.     ' Sub: TGLockColumn
  65.     '
  66.     ' Locks a column in the leftmost or rightmost split,
  67.     ' depending upon the value of atleft.  The column will
  68.     ' be hidden in any other split it is present in.  If there
  69.     ' is no split, then one will be created.
  70.     ' ==========================================================
  71.  
  72.     Dim oldSplitIndex As Integer
  73.     Dim oldPropsGlobal As Integer
  74.     Dim newSplit As Integer
  75.     Dim i As Integer
  76.  
  77.     ' Save the existing split index and global setting
  78.  
  79.     oldSplitIndex = ctl.SplitIndex
  80.     oldPropsGlobal = ctl.SplitPropsGlobal
  81.  
  82.     ctl.SplitPropsGlobal = False
  83.  
  84.     ' First, determine whether or not we need to create a new
  85.     ' split for locked columns.
  86.  
  87.     If atleft Then
  88.     newSplit = 1
  89.     Else
  90.     newSplit = ctl.Splits
  91.     End If
  92.  
  93.     ctl.SplitIndex = newSplit
  94.  
  95.     If ctl.SplitSizeMode <> GSPT_COLUMNS Then
  96.     ' Insert a split at the left and modify the caller's original
  97.     ' split index.
  98.     
  99.     If atleft Then
  100.         ctl.InsertSplit = 1
  101.         oldSplitIndex = oldSplitIndex + 1
  102.     Else
  103.         ctl.InsertSplit = ctl.Splits + 1
  104.         newSplit = newSplit + 1
  105.     End If
  106.  
  107.     ' Hide all columns in the newly created split
  108.  
  109.     For i = 1 To ctl.Columns
  110.         ctl.ColumnVisible(i) = False
  111.     Next i
  112.     End If
  113.  
  114.     ' Make the column visible in the new split, make sure it's
  115.     ' invisible elsewhere, but don't touch splits which are
  116.     ' set to a fixed number of columns.
  117.  
  118.     ctl.ColumnVisible(col) = True
  119.  
  120.     For i = 1 To ctl.Splits
  121.     ctl.SplitIndex = i
  122.     If i <> newSplit And ctl.SplitSizeMode <> GSPT_COLUMNS Then
  123.         ctl.ColumnVisible(col) = False
  124.     End If
  125.     Next i
  126.  
  127.     ' Now, set the sizemode and size for the split.  Lock the split
  128.     ' so that it has no split bar
  129.  
  130.     ctl.SplitIndex = newSplit
  131.     ctl.SplitSizeMode = GSPT_COLUMNS
  132.     ctl.SplitSize = TgGetVisibleCols(ctl)
  133.     ctl.SplitLocked = True
  134.  
  135.     ' Reset the old split number and the global properties flag
  136.  
  137.     ctl.SplitIndex = oldSplitIndex
  138.     ctl.SplitPropsGlobal = oldPropsGlobal
  139.  
  140. End Sub
  141.  
  142. Sub TgLockColumnLeft (ctl As TrueGrid, ByVal col As Integer)
  143.  
  144.     ' ==========================================================
  145.     ' Sub: TgLockColumnLeft
  146.     '
  147.     ' Locks a column in the leftmost split of the grid,
  148.     ' and creates a new split there for locked columns if
  149.     ' one doesn't exist.
  150.     ' ==========================================================
  151.  
  152.     TgLockColumn ctl, col, True
  153.  
  154. End Sub
  155.  
  156. Sub TgLockColumnRight (ctl As TrueGrid, ByVal col As Integer)
  157.  
  158.     ' ==========================================================
  159.     ' Sub: TgLockColumnRight
  160.     '
  161.     ' Locks a column in the rightmost split of the grid,
  162.     ' and creates a new split there for locked columns if
  163.     ' one doesn't exist.
  164.     ' ==========================================================
  165.  
  166.     TgLockColumn ctl, col, False
  167.  
  168. End Sub
  169.  
  170. Sub TgSetCurCellColor (ctl As TrueGrid, fg As Long, bg As Long)
  171.  
  172.     ' ==========================================================
  173.     ' Sub: TgSetCurCellColor
  174.     '
  175.     ' This routine sets the color of the current cell.  If you
  176.     ' want the entire highlighted row marquee to be a different
  177.     ' color, then execute TgSetMarqueeColor FIRST.
  178.     ' ==========================================================
  179.  
  180.     ' Set parameters
  181.  
  182.     ctl.ParamForeColor = fg
  183.     ctl.ParamBackColor = bg
  184.  
  185.     ' Set the color for all possible current cell combinations,
  186.     ' but not for other cells in the highlighted row
  187.  
  188.     ctl.SetStatusAttr = GFS_CURCELL
  189.     ctl.SetStatusAttr = GFS_CURCELL + GFS_SELECTED
  190.     ctl.SetStatusAttr = GFS_CURCELL + GFS_CHANGED
  191.     ctl.SetStatusAttr = GFS_CURCELL + GFS_CHANGED + GFS_SELECTED
  192.     ctl.SetStatusAttr = GFS_HIGHROW + GFS_CURCELL
  193.     ctl.SetStatusAttr = GFS_HIGHROW + GFS_CURCELL + GFS_SELECTED
  194.     ctl.SetStatusAttr = GFS_HIGHROW + GFS_CURCELL + GFS_CHANGED
  195.     ctl.SetStatusAttr = GFS_HIGHROW + GFS_CURCELL + GFS_CHANGED + GFS_SELECTED
  196.     
  197. End Sub
  198.  
  199. Sub TgSetMarqueeColor (ctl As TrueGrid, fg As Long, bg As Long)
  200.  
  201.     ' ==========================================================
  202.     ' Sub: TgSetMarqueeColor
  203.     '
  204.     ' This routine sets the color of the marquee, including
  205.     ' the current cell within the marquee.  If you want to
  206.     ' make the current cell a different color, then execute
  207.     ' TgSetCurCellColor AFTER executing this subroutine.
  208.     ' ==========================================================
  209.  
  210.     ' Set parameters first
  211.  
  212.     ctl.ParamForeColor = fg
  213.     ctl.ParamBackColor = bg
  214.     ctl.ParamFontStyle = -1
  215.  
  216.     ' Set the color for all possible marquee status combinations
  217.  
  218.     ctl.SetStatusAttr = GFS_CURCELL
  219.     ctl.SetStatusAttr = GFS_CURCELL + GFS_HIGHROW
  220.     ctl.SetStatusAttr = GFS_CURCELL + GFS_HIGHROW + GFS_SELECTED
  221.     ctl.SetStatusAttr = GFS_HIGHROW
  222.     ctl.SetStatusAttr = GFS_HIGHROW + GFS_SELECTED
  223.  
  224.     ' For changed data, then maintain the foreground color
  225.  
  226.     ctl.ParamForeColor = -1
  227.  
  228.     ctl.SetStatusAttr = GFS_CHANGED + GFS_CURCELL
  229.     ctl.SetStatusAttr = GFS_CHANGED + GFS_CURCELL + GFS_HIGHROW
  230.     ctl.SetStatusAttr = GFS_CHANGED + GFS_CURCELL + GFS_HIGHROW + GFS_SELECTED
  231.     ctl.SetStatusAttr = GFS_CHANGED + GFS_HIGHROW
  232.     ctl.SetStatusAttr = GFS_CHANGED + GFS_HIGHROW + GFS_SELECTED
  233.  
  234. End Sub
  235.  
  236. Sub TgUnlockColumn (ctl As TrueGrid, ByVal col As Integer)
  237.     
  238.     ' ==========================================================
  239.     ' Sub: TgUnlockColumn
  240.     '
  241.     ' Unlocks a column which was locked with TgLockColumnLeft
  242.     ' or TgLockColumnRight.  A column is considered locked if
  243.     ' it is part of a locked split which has SplitSizeMode
  244.     ' set to GSPT_COLUMNS.
  245.     ' ==========================================================
  246.  
  247.     Dim oldSplitIndex As Integer
  248.     Dim oldPropsGlobal As Integer
  249.     Dim lockSplit As Integer
  250.     Dim visible As Integer
  251.     Dim i As Integer
  252.  
  253.     ' Save the existing split index and global settings
  254.  
  255.     oldSplitIndex = ctl.SplitIndex
  256.     oldPropsGlobal = ctl.SplitPropsGlobal
  257.  
  258.     ctl.SplitPropsGlobal = False
  259.  
  260.     ' Find the split which contains the locked column
  261.  
  262.     ctl.SplitIndex = 1
  263.     Do While ctl.SplitIndex <= ctl.Splits
  264.     If ctl.SplitSizeMode = GSPT_COLUMNS And ctl.SplitLocked Then
  265.         If ctl.ColumnVisible(col) Then Exit Do
  266.     End If
  267.  
  268.     ' Exit the sub if we didn't find the column
  269.  
  270.     If ctl.SplitIndex = ctl.Splits Then
  271.         ctl.SplitIndex = oldSplitIndex
  272.         ctl.SplitPropsGlobal = oldPropsGlobal
  273.         Exit Sub
  274.     End If
  275.     ctl.SplitIndex = ctl.SplitIndex + 1
  276.     Loop
  277.  
  278.     lockSplit = ctl.SplitIndex
  279.  
  280.     ' The locked column is in the current split.  Hide it in the
  281.     ' current split, and unhide it in all other splits which aren't
  282.     ' set to a fixed number of columns.
  283.  
  284.     ctl.ColumnVisible(col) = False
  285.     For i = 1 To ctl.Splits
  286.     ctl.SplitIndex = i
  287.     If i <> lockSplit And ctl.SplitSizeMode <> GSPT_COLUMNS Then
  288.         ctl.ColumnVisible(col) = True
  289.     End If
  290.     Next i
  291.  
  292.     ' If there are no columns visible in the current split, then remove
  293.     ' the split
  294.  
  295.     ctl.SplitIndex = lockSplit
  296.     If TgGetVisibleCols(ctl) = 0 Then
  297.     ctl.RemoveSplit = lockSplit
  298.     If oldSplitIndex > lockSplit Or oldSplitIndex > ctl.Splits Then oldSplitIndex = oldSplitIndex - 1
  299.     End If
  300.  
  301.     ctl.SplitIndex = oldSplitIndex
  302.     ctl.SplitPropsGlobal = oldPropsGlobal
  303.  
  304. End Sub
  305.  
  306. Sub TgSetNegativeColColor (ctl As TrueGrid, col As Integer, fg As Long, bg As Long)
  307.     
  308.     ' ==========================================================
  309.     ' Sub: SetNegativeColColor
  310.     '
  311.     ' For a given column, sets the colors to be used for cells
  312.     ' which appear to have negative numbers (start with a leading
  313.     ' minus sign, or are enclosed in parenthesis)
  314.     ' ==========================================================
  315.  
  316.     ctl.ParamForeColor = fg
  317.     ctl.ParamBackColor = bg
  318.     ctl.ParamFontStyle = -1
  319.     ctl.ParamStatus = -1
  320.  
  321.     ctl.ColumnAddRegexAttr(col) = "^ *-"
  322.     ctl.ColumnAddRegexAttr(col) = "^(.+)$"
  323.  
  324. End Sub
  325.  
  326.