home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1999 April / CD_Shareware_Magazine_31.iso / Free / Prg / VertMenu.exe / Menu.cls < prev    next >
Encoding:
Visual Basic class definition  |  1997-01-25  |  7.5 KB  |  272 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "VMenu"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = False
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. Private msCaption As String      ' caption of the Menu
  13. Private mlIndex As Long          ' location of the Menu
  14. Private picMenu As PictureBox
  15. Private picCache As PictureBox
  16. Private mlButtonHeight As Long
  17. Private mMenuItems As MenuItems
  18. Private mpicUp As Arrow
  19. Private mpicDown As Arrow
  20. Private mHotSpot As Rect
  21. Private mlTopMenuItemDisplayed As Long
  22.  
  23. Const TYPE_UP = 1
  24. Const TYPE_DOWN = -1
  25. Const BTN_UP = 1
  26. Const BTN_DOWN = -1
  27. Const MOUSE_UP = 1
  28. Const MOUSE_DOWN = -1
  29. Const MOUSE_MOVE = 0
  30. Const SCROLL_DOWN = -100
  31. Const SCROLL_UP = 100
  32.  
  33. Public Property Get Caption() As String
  34.     On Error Resume Next
  35.     Caption = msCaption
  36. End Property
  37.  
  38. Public Property Let Caption(ByVal sNewValue As String)
  39.     On Error Resume Next
  40.     msCaption = sNewValue
  41.     ' only print the caption if the index has been set
  42.     If mlIndex > 0 Then
  43. '        PaintCaption
  44.     End If
  45. End Property
  46.  
  47. Public Property Get Index() As Long
  48.     On Error Resume Next
  49.     Index = mlIndex
  50. End Property
  51.  
  52. Public Property Let Index(ByVal lNewValue As Long)
  53.     On Error Resume Next
  54.     mlIndex = lNewValue
  55. End Property
  56.  
  57. Public Property Get Control() As Object
  58.     On Error Resume Next
  59.     Set Control = picMenu
  60. End Property
  61.  
  62. Public Property Set Control(pic As Object)
  63.     On Error Resume Next
  64.     Set picMenu = pic
  65.     
  66.     ' also tell the arrows who the parent is
  67.     Set mpicUp.Parent = pic
  68.     Set mpicDown.Parent = pic
  69. End Property
  70.  
  71. Public Function AddMenuItem(sCaption As String, lMenuItemlIndex As Long, picIcon As Object) As MenuItems
  72.     On Error Resume Next
  73.     With mMenuItems
  74.         .Add sCaption, lMenuItemlIndex, mlButtonHeight, picIcon
  75.         Set .Item(lMenuItemlIndex).Parent = picMenu
  76.         Set .Item(lMenuItemlIndex).Cache = picCache
  77.     End With
  78. End Function
  79.  
  80. Public Sub DeleteMenuItem(lMenuItemlIndex As Long)
  81.     On Error Resume Next
  82.     mMenuItems.Delete lMenuItemlIndex
  83. End Sub
  84.  
  85. Public Function MenuItemCount() As Long
  86.     On Error Resume Next
  87.     MenuItemCount = mMenuItems.Count
  88. End Function
  89.  
  90. Public Function MenuItemItem(lMenuItemlIndex As Long) As MenuItem
  91.     On Error Resume Next
  92.     Set MenuItemItem = mMenuItems.Item(lMenuItemlIndex)
  93. End Function
  94.  
  95. ' process mouse events for arrow buttons
  96. Public Function MouseProcessForArrows(ByVal iMousePosition, ByVal X As Long, ByVal Y As Long) As Long
  97.     Dim bResult As Boolean
  98.     Dim pic As Arrow
  99.     Dim i As Integer
  100.     Static lLastPosition(1) As Long
  101.         
  102.     On Error Resume Next
  103.     For i = 0 To 1
  104.         If i = 0 Then
  105.             Set pic = mpicDown
  106.         Else
  107.             Set pic = mpicUp
  108.         End If
  109.  
  110.         bResult = pic.HitTest(iMousePosition, X, Y)
  111.         If bResult Then
  112.             Select Case iMousePosition
  113.                 Case MOUSE_UP
  114.                     If lLastPosition(i) = BTN_DOWN Then
  115.                         If i = 0 Then
  116.                             MouseProcessForArrows = SCROLL_DOWN
  117.                         Else
  118.                             MouseProcessForArrows = SCROLL_UP
  119.                         End If
  120.                     End If
  121.                     lLastPosition(i) = iMousePosition
  122.                 Case MOUSE_DOWN
  123.                     lLastPosition(i) = iMousePosition
  124.                 Case MOUSE_MOVE
  125.                     If lLastPosition(i) <> BTN_DOWN Then
  126.                         lLastPosition(i) = iMousePosition
  127.                     End If
  128.             End Select
  129.         Else
  130.             If iMousePosition = MOUSE_UP Then
  131.                 lLastPosition(i) = BTN_UP
  132.             End If
  133.         End If
  134.     Next
  135.     Set pic = Nothing
  136. End Function
  137.  
  138. Public Property Get ButtonHeight() As Long
  139.     On Error Resume Next
  140.     ButtonHeight = mlButtonHeight
  141. End Property
  142.  
  143. Public Property Let ButtonHeight(ByVal lNewValue As Long)
  144.     On Error Resume Next
  145.     mlButtonHeight = lNewValue
  146.     mpicUp.ButtonHeight = lNewValue
  147.     mpicDown.ButtonHeight = lNewValue
  148. End Property
  149.  
  150. Private Sub Class_Initialize()
  151.     On Error Resume Next
  152.     Set mMenuItems = New MenuItems
  153.     
  154.     ' create our up arrow
  155.     Set mpicUp = New Arrow
  156.     mpicUp.ArrowType = TYPE_UP
  157.     
  158.     ' create our down arrow
  159.     Set mpicDown = New Arrow
  160.     mpicDown.ArrowType = TYPE_DOWN
  161.     
  162.     mlTopMenuItemDisplayed = 1
  163. End Sub
  164.  
  165. Private Sub Class_Terminate()
  166.     On Error Resume Next
  167.     Set mpicDown = Nothing
  168.     Set mpicUp = Nothing
  169.     Set picMenu = Nothing
  170. End Sub
  171.  
  172. Public Property Get UpBitmap() As Object
  173.     On Error Resume Next
  174.     Set UpBitmap = mpicUp.Bitmap
  175. End Property
  176.  
  177. Public Property Set UpBitmap(ByVal oNewValue As Object)
  178.     On Error Resume Next
  179.     Set mpicUp.Bitmap = oNewValue
  180. End Property
  181.  
  182. Public Property Get DownBitmap() As Object
  183.     On Error Resume Next
  184.     Set DownBitmap = mpicDown.Bitmap
  185. End Property
  186.  
  187. Public Property Set DownBitmap(ByVal oNewValue As Object)
  188.     On Error Resume Next
  189.     Set mpicDown.Bitmap = oNewValue
  190. End Property
  191.  
  192. Public Property Set ImageCache(ByVal ctlNewValue As Object)
  193.     On Error Resume Next
  194.     Set picCache = ctlNewValue
  195. End Property
  196.  
  197. ' hittest to see if the points are in the menu button
  198. Public Function IsMenuSelected(ByVal ptX As Long, ByVal ptY As Long) As Boolean
  199.     On Error Resume Next
  200.     IsMenuSelected = Not (PtInRect(mHotSpot, ptX, ptY) = 0)
  201.     If Err.Number <> 0 Then
  202.         IsMenuSelected = False
  203.         Err.Clear
  204.     End If
  205. End Function
  206.  
  207. ' menu button location
  208. ' all we need to do to set the structure is pass the top
  209. ' because we can compute the other locations
  210. ' same reason all we need to do is return the top location
  211. Public Property Get ButtonTop() As Long
  212.     ButtonTop = mHotSpot.Top
  213. End Property
  214.  
  215. Public Property Let ButtonTop(ByVal lNewValue As Long)
  216.     With picMenu
  217.         .ScaleMode = vbPixels
  218.         mHotSpot.Left = 0
  219.         mHotSpot.Top = lNewValue
  220.         mHotSpot.Right = .ScaleWidth
  221.         mHotSpot.Bottom = lNewValue + mlButtonHeight
  222.     End With
  223. End Property
  224.  
  225. Public Function PaintItems(lIconStart As Long, lMenuCur As Long, lClipY As Long, lMax As Long) As Boolean
  226.     Dim i As Integer
  227.     
  228.     On Error Resume Next
  229.     If Not mMenuItems.Paint(mlTopMenuItemDisplayed, lIconStart, lMenuCur, lClipY) Then
  230.         ' the second parameter for the down button is the
  231.         ' number of buttons at the bottom of the menu
  232.         mpicDown.Show BTN_UP, MenusAtBottom:=lMax - lMenuCur + 1, TotalMenus:=lMax
  233.     Else
  234.         mpicDown.Hide
  235.     End If
  236.     If mlTopMenuItemDisplayed > 1 Then
  237.         ' the second parameter for the down button is the
  238.         ' number of buttons at the to of the menu
  239.         mpicUp.Show BTN_UP, MenusAtTop:=lMenuCur, TotalMenus:=lMax
  240.     Else
  241.         mpicUp.Hide
  242.     End If
  243. End Function
  244.  
  245. Public Property Get MenuItems() As MenuItems
  246.     On Error Resume Next
  247.     Set MenuItems = mMenuItems
  248. End Property
  249.  
  250. Public Sub HideButton(iThisButton As Integer, lOffset As Long)
  251.     On Error Resume Next
  252.     If iThisButton = TYPE_UP Then
  253.         mpicUp.Hide
  254.     Else
  255.         mpicDown.Hide
  256.     End If
  257. End Sub
  258.  
  259. Public Property Get TopMenuItem() As Long
  260.     If mlTopMenuItemDisplayed = 0 Then
  261.         mlTopMenuItemDisplayed = 1
  262.     End If
  263.     TopMenuItem = mlTopMenuItemDisplayed
  264. End Property
  265.  
  266. Public Property Let TopMenuItem(ByVal lNewValue As Long)
  267.     If lNewValue <> 0 Then
  268.         mlTopMenuItemDisplayed = lNewValue
  269.     End If
  270. End Property
  271.  
  272.