VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "SAToolBarExtensions"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Collection" ,"SAToolBarExtension"
Attribute VB_Ext_KEY = "Member0" ,"SAToolBarExtension"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

'local variable to hold collection
Private mCol As Collection
Private mColByExtID As Collection ' with extension guid and tool id as key for locating by external ID
Private m_lngNextSAToolbarID As Long

Private Const MinInternalExtensionID As Long = &H10000
Private Const MaxInternalExtensionID As Long = &H20000 ' unlikely as 65K id's

Public Function Add(ByRef r_objTools As SAToolbarTools, ByVal v_lngExtensionToolID As Long, ByVal v_strExtensionGUID As String) As SAToolBarExtension
    Dim objNew As SAToolBarExtension
    
    If v_lngExtensionToolID <= 0 Or 0 = Len(v_strExtensionGUID) Then
        Err.Raise SAERR_INVALIDTOOLBAREXTENSION, "SAToolBarExtensions.Add", SAXRes.FormatLocalString(SAXRes.GetLocalString(IDS_sa2001satoolbarextensionscls_____invalidtoobarextensionid0guid1idmustbegreaterthanzeroextensionmacrofileattributemustbespecifiedforsatoolsnode), v_lngExtensionToolID, v_strExtensionGUID) 'LEELOCAL
    End If
    
    While r_objTools.IndexOf(m_lngNextSAToolbarID) >= 0 And m_lngNextSAToolbarID < MaxInternalExtensionID ' unlikely absolute max
        m_lngNextSAToolbarID = m_lngNextSAToolbarID + 1
    Wend
    
    If m_lngNextSAToolbarID < MaxInternalExtensionID Then
#If TOOLDEBUGGING Then
    LogMessageTools "Ext.Add :" & mCol.Count() & ", " & v_lngExtensionToolID & ", " & v_strExtensionGUID  'DEV_STRING
#End If
        Set objNew = AddWithInternalToolID(m_lngNextSAToolbarID, v_lngExtensionToolID, v_strExtensionGUID)
        m_lngNextSAToolbarID = m_lngNextSAToolbarID + 1
    End If
    
    Set Add = objNew
End Function

Public Function AddWithInternalToolID(ByVal v_lngInternalToolID, ByVal v_lngExtensionToolID As Long, ByVal v_strExtensionGUID As String) As SAToolBarExtension
    Dim objNew As SAToolBarExtension
        
    On Error Resume Next
    Set objNew = mColByExtID.Item("$" & v_strExtensionGUID & "_" & v_lngExtensionToolID)
    On Error GoTo 0
    If objNew Is Nothing Then ' we need to add otherwise it's already been added
        Set objNew = New SAToolBarExtension
#If TOOLDEBUGGING Then
    LogMessageTools "Ext.AddWithInternalToolID :" & mCol.Count() & ", " & v_lngInternalToolID & ", " & v_lngExtensionToolID & ", " & v_strExtensionGUID 'DEV_STRING
#End If
        objNew.Init v_lngInternalToolID, v_lngExtensionToolID, v_strExtensionGUID
        mCol.Add objNew, "$" & v_lngInternalToolID 'DEV_STRING
        mColByExtID.Add objNew, "$" & v_strExtensionGUID & "_" & v_lngExtensionToolID
    End If
    Set AddWithInternalToolID = objNew
End Function

Public Property Get Count() As Long
    'used when retrieving the number of elements in the
    'collection. Syntax: Debug.Print x.Count
    Count = mCol.Count
End Property

Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
    'this property allows you to enumerate
    'this collection with the For...Each syntax
    Set NewEnum = mCol.[_NewEnum]
End Property

Private Sub Class_Initialize()
    'creates the collection when this class is created
    Set mCol = New Collection
    Set mColByExtID = New Collection
    m_lngNextSAToolbarID = MinInternalExtensionID
End Sub


Private Sub Class_Terminate()
    'destroys collection when this class is terminated
    Set mCol = Nothing
End Sub

Public Property Get ItemBySAToolbarID(ByVal v_lngSAToolbarID As Long) As SAToolBarExtension
    ' using SAToolbarTool.ID
    Dim tbXT As SAToolBarExtension
    
    On Error GoTo ErrExit
    Set ItemBySAToolbarID = mCol.Item("$" & v_lngSAToolbarID)
    
    Exit Property
ErrExit:
    Set ItemBySAToolbarID = Nothing
End Property

Public Property Get ItemByExtensionID(ByVal v_strExtensionGUID As String, ByVal v_lngExtensionToolID As Long) As SAToolBarExtension
    Dim tbXT As SAToolBarExtension
    
    On Error GoTo ErrExit
    Set ItemByExtensionID = mColByExtID.Item("$" & v_strExtensionGUID & "_" & v_lngExtensionToolID)

    Exit Property
ErrExit:
    Set ItemByExtensionID = Nothing
End Property

Public Sub RegisterExtensionMacroEventHandler(ByVal v_strExtensionGUID As String, ByVal v_strExtensionEventHandler As String)
    Dim tbXT As SAToolBarExtension
    
    For Each tbXT In mCol
        If 0 = StrComp(tbXT.ExtensionGuid, v_strExtensionGUID, vbTextCompare) Then
            tbXT.ExtensionEventMacro = v_strExtensionEventHandler
        End If
    Next
End Sub
