home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / School_Man20924211302007.psc / prischo / clsMyMenu.cls next >
Text File  |  2007-11-21  |  12KB  |  339 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsMyMenu"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16.  
  17. Private ImageLister As Control
  18. ' name of menus imagelist, can't use handle 'cause it can change per MSDN
  19. Public MainMenuID As Long  ' handle to form's main menu
  20. Public OldWinProc As Long  ' handle to form's window message processor
  21. Public ChildStatus As Byte ' 1 indicates a child
  22. Public ParentForm As Long  ' for MDI children, this is the MDI parent -- for others it is it's own handle
  23. Private MyMI() As MenuDataInformation       ' collection of menuitems
  24. Private menuIDs As Collection               ' index to myMI array
  25. Private mIDcurrent As Long                  ' current menu item
  26. Private MyPanels() As PanelDataInformation
  27. Private PanelData As Collection
  28. Private pIDcurrent As Long
  29. Private MDIchildren As Collection
  30.  
  31. Property Get TotalIcons() As Long
  32.     On Error Resume Next
  33.     TotalIcons = ImageLister.ListImages.Count
  34. End Property
  35.  
  36. Property Let Icon(lValue As Long)
  37.     MyMI(menuIDs(mIDcurrent)).Icon = lValue
  38. End Property
  39. Property Get Icon() As Long
  40.     Icon = MyMI(menuIDs(mIDcurrent)).Icon
  41. End Property
  42.  
  43. Property Let ItemHeight(lValue As Long)
  44.     MyMI(menuIDs(mIDcurrent)).ItemHeight = lValue
  45. End Property
  46. Property Get ItemHeight() As Long
  47.     ItemHeight = MyMI(menuIDs(mIDcurrent)).ItemHeight
  48. End Property
  49. Property Let ItemWidth(lValue As Long)
  50.     MyMI(menuIDs(mIDcurrent)).ItemWidth = lValue
  51. End Property
  52. Property Get ItemWidth() As Long
  53.     ItemWidth = MyMI(menuIDs(mIDcurrent)).ItemWidth
  54. End Property
  55. Property Let HotKeyPos(lValue As Long)
  56.     MyMI(menuIDs(mIDcurrent)).HotKeyPos = lValue
  57. End Property
  58. Property Get HotKeyPos() As Long
  59.     HotKeyPos = MyMI(menuIDs(mIDcurrent)).HotKeyPos
  60. End Property
  61.  
  62. Property Let Status(lValue As Long)
  63.     MyMI(menuIDs(mIDcurrent)).Status = lValue
  64. End Property
  65. Property Get Status() As Long
  66.     Status = MyMI(menuIDs(mIDcurrent)).Status
  67. End Property
  68.  
  69. Property Let Caption(sValue As String)
  70.     MyMI(menuIDs(mIDcurrent)).Caption = sValue
  71. End Property
  72. Property Get Caption() As String
  73.     Caption = MyMI(menuIDs(mIDcurrent)).Caption
  74. End Property
  75.  
  76. Property Get ImageViewerObj() As Control
  77.     On Error Resume Next
  78.     Set ImageViewerObj = ImageLister
  79. End Property
  80. Property Get ImageViewer() As Long
  81.    On Error Resume Next
  82.    ImageViewer = ImageLister.hImageList
  83. End Property
  84. Public Sub SetImageViewer(vObject As Control)
  85.     Set ImageLister = vObject
  86. End Sub
  87.  
  88. Property Get OriginalCaption() As String
  89.     OriginalCaption = MyMI(menuIDs(mIDcurrent)).OriginalCaption
  90. End Property
  91. Property Let OriginalCaption(sValue As String)
  92.     MyMI(menuIDs(mIDcurrent)).OriginalCaption = sValue
  93. End Property
  94.  
  95. Property Get SideBarIsText() As Boolean
  96.     On Error Resume Next
  97.     SideBarIsText = (MyPanels(CStr(pIDcurrent)).Status And 4) = 4
  98. End Property
  99. Property Get SideBarItem() As Long
  100.     SideBarItem = MyPanels(CStr(pIDcurrent)).SBarIcon
  101. End Property
  102. Property Get SideBarWidth() As Long
  103.     SideBarWidth = MyPanels(CStr(pIDcurrent)).SideBar
  104. End Property
  105. Property Get PanelWidth() As Long
  106.     PanelWidth = MyPanels(CStr(pIDcurrent)).Width
  107. End Property
  108. Property Get PanelIDcount() As Long
  109.     On Error Resume Next
  110.     PanelIDcount = PanelData.Count
  111. End Property
  112. Property Get PanelHeight() As Long
  113.     On Error Resume Next
  114.     PanelHeight = MyPanels(CStr(pIDcurrent)).Height
  115. End Property
  116. Property Get HotKeyEdge() As Integer
  117.     HotKeyEdge = CInt(MyPanels(CStr(pIDcurrent)).HKeyPos)
  118. End Property
  119.  
  120. Public Function GetSetMDIchildSysMenu(lValue As Long, bSet As Boolean) As Boolean
  121. On Error Resume Next
  122. Dim lHwnd As Long
  123. If bSet = True Then
  124.     If MDIchildren Is Nothing Then Set MDIchildren = New Collection
  125.     lHwnd = MDIchildren(CStr(lValue))
  126.     If lHwnd = 0 Then MDIchildren.add MDIchildren.Count + 1, CStr(lValue)
  127. Else
  128.     lHwnd = MDIchildren(CStr(lValue))
  129.     GetSetMDIchildSysMenu = (lHwnd <> 0)
  130. End If
  131. Err.Clear
  132. End Function
  133.  
  134. Property Get MenuIDcount() As Integer
  135. ' =====================================================================
  136. ' Simply returns the number of menu items processed
  137. ' =====================================================================
  138.     On Error Resume Next
  139.     MenuIDcount = menuIDs.Count
  140. End Property
  141.  
  142. Public Sub UpdatePanelID(vData() As Long, sText As String, bPartial As Boolean)
  143.     On Error Resume Next
  144.     With MyPanels(CStr(pIDcurrent))
  145.         .Width = vData(0)
  146.         .Height = vData(1)
  147.         .HKeyPos = vData(2)
  148.         .PanelIcon = vData(3)
  149.         If bPartial = False Then
  150.             'Debug.Print "full update on paneldata"
  151.             .SideBar = vData(4)
  152.             .SideBarXY = vData(5)
  153.             .BColor = vData(6)
  154.             .FColor = vData(7)
  155.             .Caption = sText
  156.             .Status = vData(9)
  157.             .SBarIcon = vData(10)
  158.         End If
  159.     End With
  160. End Sub
  161.  
  162. Public Sub GetPanelInformation(vData() As Long, sText As String)
  163. On Error Resume Next
  164. ReDim vData(0 To 10)
  165. With MyPanels(PanelData(CStr(MyMI(menuIDs(mIDcurrent)).Parent)))
  166.     vData(0) = .Width + 16
  167.     vData(1) = .Height
  168.     vData(2) = .HKeyPos
  169.     vData(3) = .PanelIcon
  170.     vData(4) = .SideBar
  171.     vData(5) = .SideBarXY
  172.     vData(6) = .BColor
  173.     vData(7) = .FColor
  174.     sText = .Caption
  175.     vData(9) = .Status
  176.     vData(10) = .SBarIcon
  177. End With
  178. End Sub
  179.  
  180. Public Function SetMenuID(iID As Long, hSubMenu As Long, byPosition As Boolean, Optional bAlwaysCreate As Boolean = True) As Boolean
  181. ' =====================================================================
  182. ' Used to create a new reference to a menu item or point to
  183. ' an existing reference
  184. ' =====================================================================
  185.  
  186.     On Error Resume Next
  187.     ' we reference passed menu item, if we don't have a reference
  188.     ' an error occurs which triggers a new reference if the
  189.     ' bAlwaysCreate boolean is set to true
  190.     If byPosition Then
  191.         ' menu item is positional (i.e., 1,2,3)
  192.         mIDcurrent = iID
  193.     Else
  194.         ' menu item is by ID vs position
  195.         mIDcurrent = menuIDs(CStr(iID) & "." & CStr(hSubMenu))
  196.     End If
  197.     If Err Then ' new reference
  198.         If bAlwaysCreate = True Then
  199.             ' let's add a new reference & use the menu ID as a key
  200.             menuIDs.add menuIDs.Count + 1, CStr(iID) & "." & CStr(hSubMenu)
  201.             mIDcurrent = menuIDs.Count
  202.             ' now we will add an MyMI array
  203.             ReDim Preserve MyMI(1 To menuIDs.Count)
  204.             MyMI(menuIDs(mIDcurrent)).ID = iID
  205.             MyMI(menuIDs(mIDcurrent)).Parent = hSubMenu
  206.             ' return a value indicating this is a new add
  207.             SetMenuID = True
  208.             Err.Clear
  209.             pIDcurrent = PanelData(CStr(hSubMenu))
  210.             If Err Then
  211.                 Err.Clear
  212.                 PanelData.add PanelData.Count + 1, CStr(hSubMenu)
  213.                 ReDim Preserve MyPanels(1 To PanelData.Count)
  214.                 MyPanels(PanelData.Count).ID = hSubMenu
  215.                 'Debug.Print "new panel created-count="; hSubMenu; PanelData.Count
  216.             End If
  217.         End If
  218.     Else    ' reference already exists
  219.         ' if the following flag wasn't set, then the drawing/measuring
  220.         ' routine wants to know if we have a reference
  221.         ' so we set return to true if so
  222.         ' otherwise, the menu metrics is calling this and we
  223.         ' need to return false indicating this is not a new add
  224.         If bAlwaysCreate = False Then SetMenuID = True
  225.     End If
  226.     pIDcurrent = PanelData(CStr(hSubMenu))
  227. End Function
  228.  
  229. Public Sub GetIconData(vData() As Long, IconIndex As Long)
  230. ' =====================================================================
  231. ' Returns image handle, type and icon index/transparency option
  232. ' when drawing routine requests it
  233. ' =====================================================================
  234.     On Error Resume Next
  235.     ReDim vData(0 To 2)
  236.     If Not ImageLister Is Nothing Then
  237.         vData(0) = ImageLister.ListImages(IconIndex).Picture.Handle
  238.         vData(1) = ImageLister.ListImages(IconIndex).Picture.Type
  239.         If (MyMI(menuIDs(mIDcurrent)).Status And 4) = 4 Then
  240.             vData(2) = 1
  241.         Else
  242.             If (MyMI(menuIDs(mIDcurrent)).Status And 8) = 8 Then vData(2) = 2
  243.         End If
  244.     End If
  245. End Sub
  246.  
  247. Public Function GetPanelID(iID As Long) As Long
  248. ' =====================================================================
  249. ' Returns then actual menuID and related submenu item for
  250. ' a stored menuitem -- used in preparation for the DeleteMenuItem sub
  251. ' =====================================================================
  252. On Error Resume Next
  253. GetPanelID = MyPanels(PanelData.Item(iID)).ID
  254. End Function
  255.  
  256. Public Sub PurgeObsoleteMenus(hSubMenu As Long)
  257. Dim newMyMI() As MenuDataInformation, newMyPanels() As PanelDataInformation
  258. Dim Looper As Long, lCounter As Long
  259. On Error GoTo ExitSub
  260. If menuIDs.Count Then
  261.     ReDim newMyMI(1 To menuIDs.Count)
  262.     lCounter = 1
  263.     For Looper = menuIDs.Count To 1 Step -1
  264.         If MyMI(menuIDs.Item(Looper)).Parent <> hSubMenu Then
  265.             newMyMI(lCounter) = MyMI(menuIDs.Item(Looper))
  266.             lCounter = lCounter + 1
  267.         End If
  268.     Next
  269.     If lCounter - 1 Then
  270.         Erase MyMI
  271.         ReDim MyMI(1 To lCounter - 1)
  272.         Set menuIDs = Nothing
  273.         Set menuIDs = New Collection
  274.         For Looper = 1 To lCounter - 1
  275.             MyMI(Looper) = newMyMI(Looper)
  276.             menuIDs.add Looper, CStr(newMyMI(Looper).ID) & "." & CStr(newMyMI(Looper).Parent)
  277.         Next
  278.         'Debug.Print "Finished indexing menuitems"
  279.     End If
  280.     Erase newMyMI
  281. End If
  282. If PanelData.Count Then
  283.     ReDim newMyPanels(1 To PanelData.Count)
  284.     lCounter = 1
  285.     For Looper = PanelData.Count To 1 Step -1
  286.         pIDcurrent = Looper
  287.         If MyPanels(PanelData.Item(Looper)).ID <> hSubMenu Then
  288.             newMyPanels(lCounter) = MyPanels(PanelData.Item(Looper))
  289.             If SideBarIsText = True Then DeleteObject MyPanels(PanelData.Item(Looper)).SBarIcon
  290.             lCounter = lCounter + 1
  291.         End If
  292.     Next
  293.     If lCounter - 1 Then
  294.         Erase MyPanels
  295.         ReDim MyPanels(1 To lCounter - 1)
  296.         Set PanelData = Nothing
  297.         Set PanelData = New Collection
  298.         For Looper = 1 To lCounter - 1
  299.             MyPanels(Looper) = newMyPanels(Looper)
  300.             PanelData.add Looper, CStr(newMyPanels(Looper).ID)
  301.         Next
  302.         'Debug.Print "Finished Indexing panels"
  303.     End If
  304.     Erase newMyPanels
  305. End If
  306. Looper = 0
  307. Looper = MDIchildren(CStr(hSubMenu))
  308. If Looper Then MDIchildren.Remove Looper
  309. ExitSub:
  310. End Sub
  311.  
  312. Private Sub Class_Terminate()
  313. ' =====================================================================
  314. ' Clean up variables, collections, etc for form closure
  315. ' =====================================================================
  316. On Error Resume Next
  317. Dim Looper As Long
  318. For Looper = 1 To PanelData.Count
  319.     pIDcurrent = Looper
  320.     If SideBarIsText = True Then DeleteObject MyPanels(PanelData.Item(Looper)).SBarIcon
  321. Next
  322. Set PanelData = Nothing
  323. Set MDIchildren = Nothing
  324. Set ImageLister = Nothing
  325. MainMenuID = 0
  326. OldWinProc = 0
  327. Set menuIDs = Nothing
  328. Erase MyMI
  329. End Sub
  330.  
  331. Private Sub Class_Initialize()
  332. Set menuIDs = New Collection
  333. Set PanelData = New Collection
  334. End Sub
  335.  
  336.  
  337.  
  338.  
  339.