home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1999 April / CD_Shareware_Magazine_31.iso / Free / Prg / VertMenu.exe / VertMenu.ctl < prev    next >
Encoding:
Visual Basic user-defined control file  |  1997-03-11  |  27.8 KB  |  828 lines

  1. VERSION 5.00
  2. Begin VB.UserControl VerticalMenu 
  3.    BackColor       =   &H80000010&
  4.    BorderStyle     =   1  'Fixed Single
  5.    ClientHeight    =   1170
  6.    ClientLeft      =   0
  7.    ClientTop       =   0
  8.    ClientWidth     =   2640
  9.    Picture         =   "VertMenu.ctx":0000
  10.    PropertyPages   =   "VertMenu.ctx":0442
  11.    ScaleHeight     =   78
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   176
  14.    Begin VB.PictureBox picMenu 
  15.       Appearance      =   0  'Flat
  16.       BackColor       =   &H8000000C&
  17.       BorderStyle     =   0  'None
  18.       ClipControls    =   0   'False
  19.       ForeColor       =   &H80000008&
  20.       Height          =   780
  21.       Left            =   0
  22.       ScaleHeight     =   780
  23.       ScaleWidth      =   870
  24.       TabIndex        =   1
  25.       Top             =   0
  26.       Width           =   870
  27.    End
  28.    Begin VB.PictureBox picCache 
  29.       Appearance      =   0  'Flat
  30.       AutoRedraw      =   -1  'True
  31.       BackColor       =   &H80000005&
  32.       BorderStyle     =   0  'None
  33.       ClipControls    =   0   'False
  34.       ForeColor       =   &H80000008&
  35.       Height          =   540
  36.       Left            =   990
  37.       ScaleHeight     =   36
  38.       ScaleMode       =   3  'Pixel
  39.       ScaleWidth      =   51
  40.       TabIndex        =   0
  41.       Top             =   315
  42.       Visible         =   0   'False
  43.       Width           =   765
  44.    End
  45.    Begin VB.Image imgDown 
  46.       Height          =   240
  47.       Left            =   2160
  48.       Picture         =   "VertMenu.ctx":046F
  49.       Top             =   540
  50.       Visible         =   0   'False
  51.       Width           =   240
  52.    End
  53.    Begin VB.Image imgUp 
  54.       Height          =   240
  55.       Left            =   2160
  56.       Picture         =   "VertMenu.ctx":09B1
  57.       Top             =   120
  58.       Visible         =   0   'False
  59.       Width           =   240
  60.    End
  61. End
  62. Attribute VB_Name = "VerticalMenu"
  63. Attribute VB_GlobalNameSpace = False
  64. Attribute VB_Creatable = True
  65. Attribute VB_PredeclaredId = False
  66. Attribute VB_Exposed = True
  67. Attribute VB_Ext_KEY = "PropPageWizardRun" ,"Yes"
  68. Option Explicit
  69.  
  70. Dim mMenus As Menus
  71.  
  72. 'Default Property Values:
  73. Const m_def_WhatsThisHelpID = 0
  74. Const m_def_ToolTipText = ""
  75. Const m_def_MousePointer = 0
  76. Const m_def_Enabled = 0
  77. Const m_def_DrawWidth = 0
  78. Const m_def_DrawStyle = 0
  79. Const m_def_DrawMode = 0
  80. Const m_def_CurrentY = 0
  81. Const m_def_CurrentX = 0
  82. Const m_def_BorderStyle = 0
  83. Const m_def_BackStyle = 0
  84. Const m_def_Appearance = 0
  85. Const m_def_AutoRedraw = 0
  86. Const m_def_ClipControls = 0
  87. Const m_def_ScaleWidth = 0
  88. Const m_def_ScaleTop = 0
  89. Const m_def_ScaleMode = 3
  90. Const m_def_ScaleLeft = 0
  91. Const m_def_ScaleHeight = 0
  92. Const m_def_MenusMax = 1
  93. Const m_def_MenuCur = 1
  94. Const m_def_MenuStartup = 1
  95. Const m_def_MenuCaption = "Menu"
  96. Const m_def_MenuItemCaption = "Item"
  97. Const m_def_MenuItemsMax = 1
  98. Const m_def_MenuItemCur = 1
  99.  
  100. 'Property Variables:
  101. Private m_WhatsThisHelpID As Long
  102. Private m_ToolTipText As String
  103. Private m_MousePointer As Integer
  104. Private m_Enabled As Boolean
  105. Private m_DrawWidth As Integer
  106. Private m_DrawStyle As Integer
  107. Private m_DrawMode As Integer
  108. Private m_CurrentY As Single
  109. Private m_CurrentX As Single
  110. Private m_BorderStyle As Integer
  111. Private m_BackStyle As Integer
  112. Private m_ActiveControl As Control
  113. Private m_Appearance As Integer
  114. Private m_AutoRedraw As Boolean
  115. Private m_ClipControls As Boolean
  116. Private m_ScaleWidth As Single
  117. Private m_ScaleTop As Single
  118. Private m_ScaleMode As Integer
  119. Private m_ScaleLeft As Single
  120. Private m_ScaleHeight As Single
  121.  
  122. Private mlMenusMax As Long
  123. Private mlMenuCur As Long
  124. Private mlMenuStartup As Long
  125. Private msMenuCaption As String
  126. Private msMenuItemCaption As String
  127. Private mpicMenuItemIcon As Picture
  128. Private mlMenuItemsMax As Long
  129. Private mlMenuItemCur As Long
  130. Private mbInitializing As Boolean
  131. Private mbAsyncReadComplete As Boolean
  132. Private mbVBEnvironment As Boolean
  133.  
  134. ' Constants
  135. Const HIT_TYPE_MENU_BUTTON = 1
  136. Const HIT_TYPE_MENUITEM = 2
  137. Const HIT_TYPE_UP_ARROW = 3
  138. Const HIT_TYPE_DOWN_ARROW = 4
  139. Const BUTTON_HEIGHT = 18
  140. Const MOUSE_UP = 1
  141. Const MOUSE_DOWN = -1
  142. Const MOUSE_MOVE = 0
  143. Const MOUSE_IN_CAPTION = -2
  144. Const ICON_SIZE = 32
  145.  
  146. 'Event Declarations:
  147. Event Show()
  148. Event Resize()
  149. Event Hide()
  150. Event Click()
  151. Event DblClick()
  152. Event KeyDown(KeyCode As Integer, Shift As Integer)
  153. Event KeyPress(KeyAscii As Integer)
  154. Event KeyUp(KeyCode As Integer, Shift As Integer)
  155. Event MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  156. Event MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  157. Event MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  158. Event Paint()
  159. Event MenuItemClick(MenuNumber As Long, MenuItem As Long)
  160.  
  161. Private Sub picCache_Resize()
  162.     DrawCacheMenuButton
  163. End Sub
  164.  
  165. ' if picMenu considers a second mousedown event as a dblclick, the
  166. ' MouseDown event does not file so we need to do it instead
  167. Private Sub picMenu_DblClick()
  168.     Dim POINTAPI As POINTAPI
  169.     Dim lResCod As Long
  170.     
  171.     On Error Resume Next
  172.     lResCod = GetCursorPos(POINTAPI)
  173.     lResCod = ScreenToClient(picMenu.hWnd, POINTAPI)
  174.     picMenu_MouseDown vbLeftButton, 0, CSng(POINTAPI.x), CSng(POINTAPI.y)
  175. End Sub
  176.  
  177. Private Sub picMenu_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  178.     Dim lIndex As Long
  179.     Dim lHitType As Long    ' return variable
  180.     
  181.     On Error Resume Next
  182.  
  183.     If Button = vbLeftButton Then
  184.         With mMenus
  185.             ' currently we only care about MenuButton hits
  186.             ' all others are already processed
  187.             lIndex = .MouseProcess(MOUSE_DOWN, CLng(x), CLng(y), lHitType)
  188.             If lHitType = HIT_TYPE_MENU_BUTTON And lIndex > 0 Then
  189.                 MenuCur = lIndex
  190.             End If
  191.         End With
  192.     End If
  193. End Sub
  194.  
  195. Private Sub picMenu_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  196.     On Error Resume Next
  197.     ' we don't care about the HitType (an optional parameter)
  198.     mMenus.MouseProcess MOUSE_MOVE, CLng(x), CLng(y)
  199. End Sub
  200.  
  201. Private Sub picMenu_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  202.     Dim lMenuItem As Long
  203.     Dim lHitType As Long
  204.     
  205.     On Error Resume Next
  206.     If Button = vbLeftButton Then
  207.         lMenuItem = mMenus.MouseProcess(MOUSE_UP, CLng(x), CLng(y), lHitType)
  208.         If lHitType = HIT_TYPE_MENUITEM And lMenuItem > 0 Then
  209.             picMenu_MouseMove Button, Shift, x, y
  210.             RaiseEvent MenuItemClick(mlMenuCur, lMenuItem)
  211.             picMenu_MouseMove 0, 0, 0, 0
  212.         End If
  213.     End If
  214. End Sub
  215.  
  216. Private Sub picMenu_Paint()
  217.     On Error Resume Next
  218.     ' using the control with the internet explorer generates a paint
  219.     ' event each time an icon is loaded.  Therefore, don't do the paint
  220.     ' event unless picMenu is visible
  221.     If picMenu.Visible Then
  222.         mMenus.Paint
  223.     End If
  224. End Sub
  225.  
  226. Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
  227.     Dim lSavMenuCur As Long
  228.     Dim lSavMenuItemCur As Long
  229.     On Error Resume Next
  230.     mbAsyncReadComplete = True
  231.     With AsyncProp
  232.         lSavMenuCur = mlMenuCur
  233.         lSavMenuItemCur = mlMenuItemCur
  234.         mlMenuCur = Val(Left$(.PropertyName, 1))
  235.         mlMenuItemCur = Val(Mid$(.PropertyName, 2))
  236.         Set MenuItemIcon = AsyncProp.Value
  237.         mlMenuCur = lSavMenuCur
  238.         mlMenuItemCur = lSavMenuItemCur
  239.     End With
  240.     mbAsyncReadComplete = False
  241. End Sub
  242.  
  243. Private Sub UserControl_Paint()
  244.     On Error Resume Next
  245.     If Not mbInitializing Then
  246.         picMenu_Paint
  247.     End If
  248. End Sub
  249.  
  250. Private Sub UserControl_Initialize()
  251.     On Error Resume Next
  252.     Set mMenus = New Menus
  253.     Set mMenus.Menu = picMenu
  254.     Set mMenus.Cache = picCache
  255. End Sub
  256.  
  257. Private Sub UserControl_Resize()
  258.     On Error Resume Next
  259.     UserControl.ScaleMode = vbPixels
  260.     With picMenu
  261.         .ScaleMode = vbPixels
  262.         .Left = 0
  263.         .Top = 0
  264.         .Width = UserControl.ScaleWidth
  265.         .Height = UserControl.ScaleHeight
  266.     End With
  267.     
  268.     With picCache
  269.         .ScaleMode = vbPixels
  270.         .Width = picMenu.Width
  271.         .Height = (BUTTON_HEIGHT * 2) + 33
  272.     End With
  273. End Sub
  274.  
  275. Private Sub UserControl_Terminate()
  276.     On Error Resume Next
  277.     Set mMenus = Nothing
  278. End Sub
  279.  
  280. Public Property Get MenusMax() As Long
  281.     On Error Resume Next
  282.     MenusMax = mlMenusMax
  283. End Property
  284.  
  285. Public Property Let MenusMax(ByVal New_MenusMax As Long)
  286.     Dim l As Long
  287.     Dim lSavMenuCur As Long
  288.     Dim hWnd As Long
  289.     
  290.     On Error Resume Next
  291.     If New_MenusMax < 0 Or New_MenusMax > 6 Then
  292.         Beep
  293.         MsgBox "MenusMax must be between 0 and 6", vbOKOnly
  294.         Exit Property
  295.     End If
  296.     
  297.     UserControl.ScaleMode = vbPixels
  298.     
  299.     Select Case New_MenusMax
  300.         Case mlMenusMax             ' nothing to do
  301.         Case Is > mlMenusMax        ' add menus
  302.             lSavMenuCur = mlMenuCur
  303.             For mlMenuCur = mlMenusMax + 1 To New_MenusMax
  304.                 With mMenus
  305.                     .Add "", mlMenuCur, picMenu
  306.                     MenuCaption = m_def_MenuCaption & CStr(mlMenuCur)
  307.                 
  308.                     ' set the up/down bitmaps
  309.                     Set .Item(mlMenuCur).UpBitmap = imgUp.Picture
  310.                     Set .Item(mlMenuCur).DownBitmap = imgDown.Picture
  311.                     Set .Item(mlMenuCur).ImageCache = picCache
  312.                     
  313.                     ' add MenuItems to the menu
  314.                     .Item(mlMenuCur).AddMenuItem m_def_MenuItemCaption, 1, mpicMenuItemIcon
  315.                 End With
  316.             Next
  317.             mlMenuCur = lSavMenuCur
  318.         Case Is < mlMenusMax        ' delete menus
  319.             For l = mlMenusMax To New_MenusMax + 1 Step -1
  320.                 With mMenus
  321.                     .Delete l
  322.                     If New_MenusMax < mlMenuCur Then
  323.                         MenuCur = New_MenusMax
  324.                     End If
  325.                 End With
  326.             Next
  327.     End Select
  328.     
  329.     mlMenusMax = New_MenusMax
  330.     mMenus.NumberOfMenusChanged = True
  331.     SetupCache
  332.     UserControl_Paint
  333.     PropertyChanged "MenusMax"
  334. End Property
  335.  
  336. Public Property Get MenuCur() As Long
  337.     MenuCur = mlMenuCur
  338. End Property
  339.  
  340. Public Property Let MenuCur(ByVal New_MenuCur As Long)
  341.     On Error Resume Next
  342.     
  343.     ' if we are calling from AsyncReadComplete event, get out of here!
  344.     If mbAsyncReadComplete Then
  345.         Exit Property
  346.     End If
  347.     
  348.     mlMenuCur = New_MenuCur
  349.     mlMenuItemCur = 1           ' reset the menuitem
  350.     With mMenus
  351.         .MenuCur = mlMenuCur
  352.         mlMenuItemsMax = .Item(mlMenuCur).MenuItemCount
  353.         MenuCaption = .Item(mlMenuCur).Caption
  354.     End With
  355.     PropertyChanged "MenuCur"
  356. End Property
  357.  
  358. Public Property Get MenuStartup() As Long
  359.     On Error Resume Next
  360.     MenuStartup = mlMenuStartup
  361. End Property
  362.  
  363. Public Property Let MenuStartup(ByVal New_MenuStartup As Long)
  364.     On Error Resume Next
  365.     mlMenuStartup = New_MenuStartup
  366.     PropertyChanged "MenuStartup"
  367. End Property
  368.  
  369. Public Property Get MenuCaption() As String
  370.     On Error Resume Next
  371.     MenuCaption = msMenuCaption
  372. End Property
  373.  
  374. Public Property Let MenuCaption(ByVal New_MenuCaption As String)
  375.     On Error Resume Next
  376.     msMenuCaption = New_MenuCaption
  377.     mMenus.Item(mlMenuCur).Caption = New_MenuCaption
  378.     UserControl_Paint
  379.     PropertyChanged "MenuCaption"
  380. End Property
  381.  
  382. Public Property Get MenuItemCaption() As String
  383.     On Error Resume Next
  384.     msMenuItemCaption = mMenus.Item(mlMenuCur).MenuItemItem(mlMenuItemCur).Caption
  385.     MenuItemCaption = msMenuItemCaption
  386. End Property
  387.  
  388. Public Property Let MenuItemCaption(ByVal New_MenuItemCaption As String)
  389.     On Error Resume Next
  390.     With mMenus.Item(mlMenuCur)
  391.         .MenuItemItem(mlMenuItemCur).Caption = New_MenuItemCaption
  392.         msMenuItemCaption = New_MenuItemCaption
  393.     End With
  394.     If Not mbInitializing Then
  395.         picMenu.Cls
  396.         UserControl_Paint
  397.     End If
  398.     PropertyChanged "MenuItemCaption"
  399. End Property
  400.  
  401. Public Property Get MenuItemIcon() As Picture
  402.     On Error Resume Next
  403.     Set MenuItemIcon = mMenus.Item(mlMenuCur).MenuItemItem(mlMenuItemCur).Button
  404. End Property
  405.  
  406. Public Property Set MenuItemIcon(ByVal New_MenuItemIcon As Picture)
  407.     On Error Resume Next
  408.     Set mMenus.Item(mlMenuCur).MenuItemItem(mlMenuItemCur).Button = New_MenuItemIcon
  409.     If Not mbInitializing Then
  410.         SetupCache
  411.         UserControl_Paint
  412.     End If
  413.     PropertyChanged "MenuItemIcon"
  414. End Property
  415.  
  416. Public Property Get MenuItemPictureURL() As String
  417.     On Error Resume Next
  418.     MenuItemPictureURL = mMenus.Item(mlMenuCur).MenuItemItem(mlMenuItemCur).PictureURL
  419. End Property
  420.  
  421. Public Property Let MenuItemPictureURL(ByVal New_MenuItemPictureURL As String)
  422.     On Error Resume Next
  423.     mMenus.Item(mlMenuCur).MenuItemItem(mlMenuItemCur).PictureURL = New_MenuItemPictureURL
  424.     UserControl.AsyncRead New_MenuItemPictureURL, vbAsyncTypePicture, CStr(mlMenuCur) & CStr(mlMenuItemCur)
  425.     If Err.Number <> 0 Then
  426.     '    Set MenuItemIcon = mpicMenuItemIcon
  427.         Err.Clear
  428.     End If
  429.     PropertyChanged "MenuItemPictureURL"
  430. End Property
  431.  
  432. Public Property Get MenuItemKey() As String
  433.     On Error Resume Next
  434.     MenuItemKey = mMenus.Item(mlMenuCur).MenuItemItem(mlMenuItemCur).Key
  435. End Property
  436.  
  437. Public Property Let MenuItemKey(ByVal New_MenuItemKey As String)
  438.     On Error Resume Next
  439.     mMenus.Item(mlMenuCur).MenuItemItem(mlMenuItemCur).Key = New_MenuItemKey
  440.     PropertyChanged "MenuItemKey"
  441. End Property
  442.  
  443. Public Property Get MenuItemTag() As String
  444.     On Error Resume Next
  445.     MenuItemTag = mMenus.Item(mlMenuCur).MenuItemItem(mlMenuItemCur).Tag
  446. End Property
  447.  
  448. Public Property Let MenuItemTag(ByVal New_MenuItemTag As String)
  449.     On Error Resume Next
  450.     mMenus.Item(mlMenuCur).MenuItemItem(mlMenuItemCur).Tag = New_MenuItemTag
  451.     PropertyChanged "MenuItemTag"
  452. End Property
  453.  
  454. 'Initialize Properties for User Control
  455. Private Sub UserControl_InitProperties()
  456.     Dim l As Long
  457.     
  458.     On Error Resume Next
  459.     
  460.     mbInitializing = True
  461.     mbVBEnvironment = IsThisVB
  462.     
  463.     mMenus.ButtonHeight = BUTTON_HEIGHT             ' set button height for icons
  464.     
  465.     ' set property defaults
  466.     m_Enabled = m_def_Enabled
  467.     m_Appearance = m_def_Appearance
  468.     m_ScaleWidth = m_def_ScaleWidth
  469.     m_ScaleTop = m_def_ScaleTop
  470.     m_ScaleMode = m_def_ScaleMode
  471.     m_ScaleLeft = m_def_ScaleLeft
  472.     m_ScaleHeight = m_def_ScaleHeight
  473.     m_ToolTipText = m_def_ToolTipText
  474.     m_WhatsThisHelpID = m_def_WhatsThisHelpID
  475.     msMenuCaption = m_def_MenuCaption
  476.     msMenuItemCaption = m_def_MenuItemCaption
  477.     mlMenuItemCur = m_def_MenuItemCur
  478.     mlMenuItemsMax = m_def_MenuItemsMax
  479.     
  480.     ProcessDefaultIcon
  481.     
  482.     ' setup the image cache
  483.     With picCache
  484.         .Width = picMenu.Width
  485.         .Height = (BUTTON_HEIGHT * 2) + 33
  486.         .BackColor = BACKGROUND_COLOR
  487.     End With
  488.     picMenu.BackColor = BACKGROUND_COLOR
  489.     
  490.     ' setup the control
  491.     MenusMax = m_def_MenusMax
  492.     MenuCur = m_def_MenuStartup
  493.     MenuStartup = m_def_MenuStartup
  494.     m_WhatsThisHelpID = m_def_WhatsThisHelpID
  495.     m_ToolTipText = m_def_ToolTipText
  496.     m_MousePointer = m_def_MousePointer
  497.     m_Enabled = m_def_Enabled
  498.     m_AutoRedraw = m_def_AutoRedraw
  499.     m_ClipControls = m_def_ClipControls
  500.     
  501.     ' setup the menu caption button and menu item icon cache
  502.     SetupCache
  503.  
  504.     mbInitializing = False
  505. End Sub
  506.  
  507. 'Load property values from storage
  508. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  509.     Dim lSavMenuItemCur As Long
  510.     
  511.     On Error Resume Next
  512.     mbInitializing = True
  513.     mbVBEnvironment = IsThisVB
  514.     picMenu.BackColor = BACKGROUND_COLOR
  515.     
  516.     With PropBag
  517.         m_Enabled = .ReadProperty("Enabled", m_def_Enabled)
  518.         m_ToolTipText = .ReadProperty("ToolTipText", m_def_ToolTipText)
  519.         m_WhatsThisHelpID = .ReadProperty("WhatsThisHelpID", m_def_WhatsThisHelpID)
  520.         mlMenuItemCur = m_def_MenuItemCur
  521.         mlMenuItemsMax = m_def_MenuItemsMax
  522.     
  523.         Set mpicMenuItemIcon = .ReadProperty("MenuItemIcon0", Nothing)
  524.         ProcessDefaultIcon
  525.         
  526.         ' setup the image cache
  527.         With picCache
  528.             .Width = UserControl.Width
  529.             .Height = (BUTTON_HEIGHT * 2) + 33
  530.             .BackColor = BACKGROUND_COLOR
  531.         End With
  532.     
  533.         ' add the first menu (which already exists on the form) to the collection
  534.         ' note that calling MenusMax only add and deletes menus other that the 1 item
  535.         ' in the collection
  536.         mMenus.ButtonHeight = BUTTON_HEIGHT
  537.         MenusMax = .ReadProperty("MenusMax", m_def_MenusMax)
  538.         
  539.         ' setup the control arrays
  540.         For mlMenuCur = 1 To mlMenusMax
  541.             MenuCur = mlMenuCur
  542.             msMenuCaption = .ReadProperty("MenuCaption" & CStr(mlMenuCur), m_def_MenuCaption)
  543.             MenuCaption = msMenuCaption
  544.             
  545.             MenuItemsMax = .ReadProperty("MenuItemsMax" & CStr(mlMenuCur), m_def_MenuItemsMax)
  546.             
  547.             lSavMenuItemCur = mlMenuItemCur
  548.             For mlMenuItemCur = 1 To mMenus.Item(mlMenuCur).MenuItemCount
  549.                 If mbVBEnvironment Then
  550.                     Set MenuItemIcon = .ReadProperty("MenuItemIcon" & CStr(mlMenuCur) & CStr(mlMenuItemCur), mpicMenuItemIcon)
  551.                 Else
  552.                     MenuItemPictureURL = .ReadProperty("MenuItemPictureURL" & CStr(mlMenuCur) & CStr(mlMenuItemCur), "")
  553.                 End If
  554.                 MenuItemCaption = .ReadProperty("MenuItemCaption" & CStr(mlMenuCur) & CStr(mlMenuItemCur), m_def_MenuItemCaption)
  555.                 MenuItemKey = .ReadProperty("MenuItemKey" & CStr(mlMenuCur) & CStr(mlMenuItemCur), "")
  556.                 MenuItemTag = .ReadProperty("MenuItemTag" & CStr(mlMenuCur) & CStr(mlMenuItemCur), "")
  557.             Next
  558.             mlMenuItemCur = lSavMenuItemCur
  559.         Next
  560.         ' reset mlMenuCur right away so we don't have errors!
  561.         mlMenuCur = .ReadProperty("MenuCur", m_def_MenuCur)
  562.         
  563.         MenuItemCur = m_def_MenuItemCur
  564.         mlMenuStartup = .ReadProperty("MenuStartup", m_def_MenuStartup)
  565.         MenuStartup = mlMenuStartup
  566.         MenuCur = mlMenuStartup
  567.         m_WhatsThisHelpID = .ReadProperty("WhatsThisHelpID", m_def_WhatsThisHelpID)
  568.         m_ToolTipText = .ReadProperty("ToolTipText", m_def_ToolTipText)
  569.         m_MousePointer = .ReadProperty("MousePointer", m_def_MousePointer)
  570.         m_Enabled = .ReadProperty("Enabled", m_def_Enabled)
  571.         m_AutoRedraw = .ReadProperty("AutoRedraw", m_def_AutoRedraw)
  572.         m_ClipControls = .ReadProperty("ClipControls", m_def_ClipControls)
  573.     End With
  574.     
  575.     ' setup the menu caption button and menu item icon cache
  576.     SetupCache
  577.     
  578.     mbInitializing = False
  579. End Sub
  580.  
  581. 'Write property values to storage
  582. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  583.     Dim lSavMenuCur As Long
  584.     Dim lSavMenuItemCur As Long
  585.     
  586.     On Error Resume Next
  587.     
  588.     With PropBag
  589.         Call .WriteProperty("Enabled", m_Enabled, m_def_Enabled)
  590.         Call .WriteProperty("ToolTipText", m_ToolTipText, m_def_ToolTipText)
  591.         Call .WriteProperty("WhatsThisHelpID", m_WhatsThisHelpID, m_def_WhatsThisHelpID)
  592.         Call .WriteProperty("MenusMax", mlMenusMax, m_def_MenusMax)
  593.         Call .WriteProperty("MenuCur", mlMenuCur, m_def_MenuCur)
  594.         Call .WriteProperty("MenuStartup", mlMenuStartup, m_def_MenuStartup)
  595.         
  596.         lSavMenuCur = mlMenuCur
  597.         For mlMenuCur = 1 To mlMenusMax
  598.             Call .WriteProperty("MenuCaption" & CStr(mlMenuCur), mMenus.Item(mlMenuCur).Caption, m_def_MenuCaption)
  599.         
  600.             ' image stuff here
  601.             Call .WriteProperty("MenuItemsMax" & CStr(mlMenuCur), mMenus.Item(mlMenuCur).MenuItemCount, m_def_MenuItemsMax)
  602.             lSavMenuItemCur = mlMenuItemCur
  603.             For mlMenuItemCur = 1 To mMenus.Item(mlMenuCur).MenuItemCount
  604.                 If mbVBEnvironment Then
  605.                     Call .WriteProperty("MenuItemIcon" & CStr(mlMenuCur) & CStr(mlMenuItemCur), MenuItemIcon, Nothing)
  606.                 Else
  607.                     Call .WriteProperty("MenuItemPictureURL" & CStr(mlMenuCur) & CStr(mlMenuItemCur), MenuItemPictureURL, "")
  608.                 End If
  609.                 Call .WriteProperty("MenuItemCaption" & CStr(mlMenuCur) & CStr(mlMenuItemCur), MenuItemCaption, m_def_MenuItemCaption)
  610.                 Call .WriteProperty("MenuItemKey" & CStr(mlMenuCur) & CStr(mlMenuItemCur), MenuItemKey, "")
  611.                 Call .WriteProperty("MenuItemTag" & CStr(mlMenuCur) & CStr(mlMenuItemCur), MenuItemTag, "")
  612.             Next
  613.             mlMenuItemCur = lSavMenuItemCur
  614.         Next
  615.         mlMenuCur = lSavMenuCur
  616.         Call .WriteProperty("MenuItemIcon0", mpicMenuItemIcon, mpicMenuItemIcon)
  617.         Call .WriteProperty("WhatsThisHelpID", m_WhatsThisHelpID, m_def_WhatsThisHelpID)
  618.         Call .WriteProperty("ToolTipText", m_ToolTipText, m_def_ToolTipText)
  619.         Call .WriteProperty("MousePointer", m_MousePointer, m_def_MousePointer)
  620.         Call .WriteProperty("Enabled", m_Enabled, m_def_Enabled)
  621.         Call .WriteProperty("AutoRedraw", m_AutoRedraw, m_def_AutoRedraw)
  622.         Call .WriteProperty("ClipControls", m_ClipControls, m_def_ClipControls)
  623.     End With
  624. End Sub
  625.  
  626. Public Property Get MenuItemsMax() As Long
  627.     On Error Resume Next
  628.     MenuItemsMax = mlMenuItemsMax
  629. End Property
  630.  
  631. Public Property Let MenuItemsMax(ByVal New_MenuItemsMax As Long)
  632.     Dim l As Long
  633.     Dim lSavMenuItemCur As Long
  634.     
  635.     On Error Resume Next
  636.     If New_MenuItemsMax < 0 Or New_MenuItemsMax > 10 Then
  637.         Beep
  638.         MsgBox "MenuItemsMax must be between 0 and 10", vbOKOnly
  639.         Exit Property
  640.     End If
  641.     
  642.     lSavMenuItemCur = mlMenuItemCur
  643.     Select Case New_MenuItemsMax
  644.         Case mlMenuItemsMax             ' nothing to do
  645.         Case Is > mlMenuItemsMax        ' add menus
  646.             With mMenus.Item(mlMenuCur)
  647.                 For mlMenuItemCur = mlMenuItemsMax + 1 To New_MenuItemsMax
  648.                     .AddMenuItem m_def_MenuItemCaption, mlMenuItemCur, mpicMenuItemIcon
  649.                     MenuItemCaption = m_def_MenuItemCaption & CStr(mlMenuItemCur)
  650.                 Next
  651.                 mlMenuItemCur = lSavMenuItemCur
  652.             End With
  653.         Case Is < mlMenuItemsMax        ' delete menus
  654.             With mMenus.Item(mlMenuCur)
  655.                 For mlMenuItemCur = mlMenuItemsMax To New_MenuItemsMax + 1 Step -1
  656.                     .DeleteMenuItem mlMenuItemCur
  657.                 Next
  658.                 mlMenuItemCur = lSavMenuItemCur
  659.                 If New_MenuItemsMax < mlMenuItemCur Then
  660.                     mlMenuItemCur = New_MenuItemsMax
  661.                 End If
  662.             End With
  663.     End Select
  664.     ' reset the caption in the properties window
  665.     mlMenuItemsMax = New_MenuItemsMax
  666.     SetupCache
  667.     UserControl_Paint
  668.     PropertyChanged "MenuItemsMax"
  669. End Property
  670.  
  671. Public Property Get MenuItemCur() As Long
  672.     On Error Resume Next
  673.     MenuItemCur = mlMenuItemCur
  674. End Property
  675.  
  676. Public Property Let MenuItemCur(ByVal New_MenuItemCur As Long)
  677.     On Error Resume Next
  678.     
  679.     ' if we are calling from AsyncReadComplete event, get out of here!
  680.     If mbAsyncReadComplete Then
  681.         Exit Property
  682.     End If
  683.     
  684.     If New_MenuItemCur > mlMenuItemsMax Then
  685.         Beep
  686.         MsgBox "The current item must be between 0 and MenuItemsMax", vbOKOnly
  687.         Exit Property
  688.     End If
  689.     mlMenuItemCur = New_MenuItemCur
  690.     PropertyChanged "MenuItemCur"
  691. End Property
  692.  
  693. Public Sub SetupCache()
  694.     Dim lMenuItemCount As Long
  695.     Dim lMIndex As Long
  696.     Dim lMMax As Long
  697.     Dim lMIIndex As Long
  698.     Dim lMIMax As Long
  699.     Dim lIconIndex As Long
  700.     Const I_OFFSET = BUTTON_HEIGHT * 2 + ICON_SIZE
  701.  
  702.     On Error Resume Next
  703.     
  704.     picCache.Cls
  705.     DrawCacheMenuButton
  706.     
  707.     ' total MenuItems on the control
  708.     lMenuItemCount = mMenus.TotalMenuItems
  709.     
  710.     With picCache
  711.         .ScaleMode = vbPixels
  712.         
  713.         ' set the height for a menu button, space for an unpainted button
  714.         ' space for an unpainted icon and all the MenuItem icons
  715.         .Height = BUTTON_HEIGHT * 2 + (lMenuItemCount + 1) * ICON_SIZE
  716.  
  717.         ' loop thru the menus getting each icon for each MenuItem
  718.         lMMax = mMenus.Count
  719.         lIconIndex = 0
  720.         For lMIndex = 1 To lMMax
  721.             lMIMax = mMenus.Item(lMIndex).MenuItemCount
  722.             For lMIIndex = 1 To lMIMax
  723.                 lIconIndex = lIconIndex + 1
  724.                 picCache.PaintPicture mMenus.Item(lMIndex).MenuItemItem(lMIIndex).Button, _
  725.                     0, I_OFFSET + (lIconIndex - 1) * ICON_SIZE, ICON_SIZE, ICON_SIZE, 0, 0
  726.             Next
  727.         Next
  728.     End With
  729. End Sub
  730.  
  731. Private Sub ProcessDefaultIcon()
  732.     ' UserControl contains the default picture
  733.     ' set it into mpicMenuItemIcon to use as the default icon
  734.     ' (it will be written to the property bag later)
  735.     ' then delete UserControl.Picture
  736.     ' note that if mpicMenuItemIcon is nothing, then we are reading from
  737.     On Error Resume Next
  738.     If mpicMenuItemIcon Is Nothing Then
  739.         Set mpicMenuItemIcon = UserControl.Picture
  740.     End If
  741.     UserControl.Picture = LoadPicture()
  742. End Sub
  743.  
  744. Private Sub DrawCacheMenuButton()
  745.     Dim RECT As RECT
  746.     
  747.     RECT.Left = 0
  748.     RECT.Top = 0
  749.     RECT.Right = picCache.ScaleWidth
  750.     RECT.Bottom = BUTTON_HEIGHT
  751.     DrawEdge picCache.hdc, RECT, BDR_RAISED, BF_RECT Or BF_MIDDLE
  752. End Sub
  753.  
  754. Public Property Get WhatsThisHelpID() As Long
  755. Attribute WhatsThisHelpID.VB_Description = "Returns/sets an associated context number for an object."
  756.     WhatsThisHelpID = m_WhatsThisHelpID
  757. End Property
  758.  
  759. Public Property Let WhatsThisHelpID(ByVal New_WhatsThisHelpID As Long)
  760.     m_WhatsThisHelpID = New_WhatsThisHelpID
  761.     PropertyChanged "WhatsThisHelpID"
  762. End Property
  763.  
  764. Public Property Get ToolTipText() As String
  765. Attribute ToolTipText.VB_Description = "Returns/sets the text displayed when the mouse is paused over the control."
  766.     ToolTipText = m_ToolTipText
  767. End Property
  768.  
  769. Public Property Let ToolTipText(ByVal New_ToolTipText As String)
  770.     m_ToolTipText = New_ToolTipText
  771.     PropertyChanged "ToolTipText"
  772. End Property
  773.  
  774. Public Sub Refresh()
  775. Attribute Refresh.VB_Description = "Forces a complete repaint of a object."
  776.     UserControl_Paint
  777. End Sub
  778.  
  779. Public Property Get MousePointer() As Integer
  780. Attribute MousePointer.VB_Description = "Returns/sets the type of mouse pointer displayed when over part of an object."
  781.     MousePointer = m_MousePointer
  782. End Property
  783.  
  784. Public Property Let MousePointer(ByVal New_MousePointer As Integer)
  785.     m_MousePointer = New_MousePointer
  786.     PropertyChanged "MousePointer"
  787. End Property
  788.  
  789. Public Property Get Enabled() As Boolean
  790. Attribute Enabled.VB_Description = "Returns/sets a value that determines whether an object can respond to user-generated events."
  791.     Enabled = m_Enabled
  792. End Property
  793.  
  794. Public Property Let Enabled(ByVal New_Enabled As Boolean)
  795.     m_Enabled = New_Enabled
  796.     PropertyChanged "Enabled"
  797. End Property
  798.  
  799. Public Property Get ClipControls() As Boolean
  800. Attribute ClipControls.VB_Description = "Determines whether graphics methods in Paint events repaint an entire object or newly exposed areas."
  801.     ClipControls = m_ClipControls
  802. End Property
  803.  
  804. Public Property Let ClipControls(ByVal New_ClipControls As Boolean)
  805.     m_ClipControls = New_ClipControls
  806.     PropertyChanged "ClipControls"
  807. End Property
  808.  
  809. Public Sub ShowAboutBox()
  810. Attribute ShowAboutBox.VB_UserMemId = -552
  811.     dlgAbout.Show vbModal
  812.     Unload dlgAbout
  813.     Set dlgAbout = Nothing
  814. End Sub
  815.  
  816. ' we need to if we are running in VB or a browser
  817. ' VB supports this extender object while a browser doesn't
  818. ' note:  we can't read icons from the property bag using a browser - GPF's
  819. Private Function IsThisVB() As Boolean
  820.     Dim obj As Object
  821.  
  822.     On Error Resume Next
  823.     Set UserControl.Extender.Parent = obj
  824.     IsThisVB = (Err.Number = 0)
  825.     Set obj = Nothing
  826.     Err.Clear
  827. End Function
  828.