home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_BAS / DGDEMO.ZIP / TGUTILS.BAS < prev    next >
BASIC Source File  |  1994-01-22  |  10KB  |  335 lines

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