VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "SAToolbarBands"
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" ,"SAToolbarBand"
Attribute VB_Ext_KEY = "Member0" ,"SAToolbarBand"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

Private m_objMenuBar As XtremeCommandBars.CommandBar   ' The main menu
Private m_objToolBars As XtremeCommandBars.CommandBars     ' The collection of actual toolbars
Private m_objPopupBands As XtremeCommandBars.CommandBarControls ' The designer controls - used for popups via a tool

'local variable to hold collection of PopupBands
Private mCol As Collection

Public Function Add(ByVal sName As String, ByVal v_enuType As SATOOLBAR_BANDTYPE, Optional v_lngToolID As Long, Optional ByVal v_enuToolType As SATOOLBAR_TOOLTYPE = SATOOLBAR_TOOLTYPE.SATB_TT_BUTTONPOPUP) As SAToolbarBand
    'create a new object
    Dim objNewMember As SAToolbarBand
    Dim objPopupTool As XtremeCommandBars.CommandBarPopup
    Dim enuType As XTPBarPosition
    Dim enuControlType As XTPControlType
    
    Select Case v_enuType
        Case SATB_BT_MENU
            enuType = xtpBarTop
        Case SATB_BT_POPUP:
            enuType = xtpBarPopup
            If v_lngToolID = 0 Then
                If CmdLineQAReporting Then
                    SAMessageBox "Toolbar error - MUST SPECIFY A TOOL ID FOR POPUPS" 'DEV_STRING
                End If
                Exit Function
            End If
        Case Else
            enuType = xtpBarTop
    End Select

    Set Add = Nothing
    
    On Error Resume Next
    Set objNewMember = mCol(sName)
    On Error GoTo 0
    If objNewMember Is Nothing Then
        Set objNewMember = New SAToolbarBand
        If v_enuType = SATB_BT_POPUP Then
            On Error Resume Next
            Set objPopupTool = GetPopupToolFromName(sName)
            If objPopupTool Is Nothing Then
                If v_enuType = SATB_BT_POPUP Then
                    Select Case v_enuToolType
                        Case SATB_TT_BUTTONDROPDOWN
                            enuControlType = xtpControlSplitButtonPopup
                        Case Else
                            enuControlType = xtpControlButtonPopup
                    End Select
                    Set objPopupTool = m_objPopupBands.Add(enuControlType, v_lngToolID, sName)
                End If
            End If
            objNewMember.Init sName, objPopupTool.CommandBar
            
            If CmdLineToolCheck Then
                If Not (IsDrawingTool(objPopupTool.Id) Or IsSpecialTool(objPopupTool.Id) Or IsColorToolName(sName)) Then
                    ' Add the tool to the master toolbar shadow file
                    TOOLCHECK_CreatePopup objNewMember
                End If
            End If
        ElseIf v_enuType = SATB_BT_MENU Then
            If sName = SAXRes.GetLocalString(IDS_uloc_____mainmenu) Then
                objNewMember.Init sName, m_objMenuBar
            Else
                objNewMember.Init sName, m_objToolBars.Add(sName, v_enuType)
            End If
        Else
            objNewMember.Init sName, m_objToolBars.Add(sName, v_enuType)
        End If
        mCol.Add objNewMember, sName
    End If
    
    'return the object created/retrieved
    Set Add = objNewMember
End Function

Friend Function AddMasterBandFromActualToolBar(ByVal v_strName As String, ByVal v_strTitle As String, ByVal blnIsPopup As Boolean) As SAToolbarBand
    'create a new object
    Dim objNewMember As SAToolbarBand
    Dim objPopupTool As XtremeCommandBars.CommandBarPopup
    Dim objCommandBar As XtremeCommandBars.CommandBar
    Dim strMainMenuBandName As String

    Set AddMasterBandFromActualToolBar = Nothing
    
    strMainMenuBandName = SAXRes.GetLocalString(IDS_uloc_____mainmenu)
    
    On Error Resume Next
    Set objNewMember = mCol(v_strName)
    On Error GoTo 0
    If objNewMember Is Nothing Then
        Set objNewMember = New SAToolbarBand
        If blnIsPopup Then
            Set objPopupTool = GetPopupToolFromName(v_strName)
            If Not objPopupTool Is Nothing Then
                objNewMember.Init v_strName, objPopupTool.CommandBar
            Else
                If CmdLineQAReporting Then
                        SAMessageBox "A popup band is being added which has no tool - it may be empty" & vbCrLf & v_strName 'DEV_STRING
                End If
                Set objNewMember = Nothing  ' Do not add it - CodeJock hasn't
            End If
        ElseIf v_strName = strMainMenuBandName Then
            objNewMember.Init v_strName, m_objMenuBar
        Else
            Set objCommandBar = GetCommandBarFromName(v_strTitle)
            objNewMember.Init v_strName, objCommandBar
        End If
        If Not objNewMember Is Nothing Then
            mCol.Add objNewMember, v_strName
            objNewMember.Caption = v_strTitle  ' Set the 'Caption' - this allows for localization
        End If
    End If
    
    'return the object created/retrieved
    Set AddMasterBandFromActualToolBar = objNewMember
End Function

Private Function GetPopupToolFromName(ByVal name As String) As CommandBarControl
    Dim cbc As CommandBarControl
    
    For Each cbc In m_objPopupBands
        If cbc.Type = xtpControlButtonPopup Or cbc.Type = xtpControlSplitButtonPopup Then
            If cbc.Parameter = name Then
                Set GetPopupToolFromName = cbc
                Exit Function
            End If
        End If
    Next
End Function

Private Function GetCommandBarFromName(ByVal name As String) As CommandBar
    Dim cb As CommandBar
    
    For Each cb In m_objToolBars
        If cb.Title = name Then
            Set GetCommandBarFromName = cb
            Exit Function
        End If
    Next
End Function

Public Function GetBandFromCommandBarTitle(ByVal v_strName As String) As SAToolbarBand
    Dim objBand As SAToolbarBand
    Dim lngIndex As Long
    Dim blnFound As Boolean
    
    For lngIndex = 1 To mCol.Count
        Set objBand = mCol(lngIndex)
        If objBand.Caption = v_strName Then
            blnFound = True
            Exit For
        End If
    Next
    
    If blnFound Then
        Set GetBandFromCommandBarTitle = objBand
    End If
End Function

Public Property Get Item(ByVal vntIndexKey As Variant) As SAToolbarBand
Attribute Item.VB_UserMemId = 0
    'used when referencing an element in the collection
    'vntIndexKey contains either the Index or Key to the collection,
    'this is why it is declared as a Variant
    'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
    If IsNumeric(vntIndexKey) Then
        vntIndexKey = vntIndexKey + 1
    End If
  
    Set Item = mCol(vntIndexKey)
End Property

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

' bForce is for removal of saved Draw toolbars
Public Sub Remove(ByVal vntIndexKey As Variant, Optional bForce As Boolean)
    'used when removing an element from the collection
    'vntIndexKey contains either the Index or Key, which is why
    'it is declared as a Variant
    'Syntax: x.Remove(xyz)
    If IsNumeric(vntIndexKey) Then
        vntIndexKey = vntIndexKey + 1
    End If
' Remove the toolbar band

    Dim objNewMember As SAToolbarBand
    Dim objPopupTool As XtremeCommandBars.CommandBarPopup
    Dim bRemove As Boolean

    On Error Resume Next
    Set objNewMember = mCol(vntIndexKey)
    On Error GoTo 0
    
    On Error GoTo ErrHdlr
    If Not objNewMember Is Nothing Then
        bRemove = bForce
        If objNewMember.TypeX = SATB_BT_POPUP Then
            Set objPopupTool = GetPopupToolFromName(vntIndexKey)
            If Not objPopupTool Is Nothing Then
                objPopupTool.Delete
            End If
            bRemove = True
        ElseIf objNewMember.TypeX = SATB_BT_MENU Then
            If vntIndexKey = SAXRes.GetLocalString(IDS_uloc_____mainmenu) Then
                ' We don't remove the main menu
            Else
                ' We don't remove any actual toolbars
            End If
        Else
            ' We don't remove any actual toolbars
        End If

        If bRemove Then
            mCol.Remove vntIndexKey
            If bForce Then
                On Error Resume Next ' caused error in eval from KillDrawMenus for id_drawnnn
                objNewMember.Band.Delete
            End If
        End If
    End If
    Exit Sub
ErrHdlr:
End Sub

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
End Sub

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

Friend Sub Init(ByRef ctlMenuBar As XtremeCommandBars.CommandBar, ByRef r_objToolBars As XtremeCommandBars.CommandBars, ByRef r_objPopupBands As XtremeCommandBars.CommandBarControls)
    Set m_objMenuBar = ctlMenuBar
    Set m_objToolBars = r_objToolBars
    Set m_objPopupBands = r_objPopupBands
End Sub

Public Sub ConfigureDefaultBandLayout()
    On Error GoTo ErrorHandler

    ' NOTE: This is NEVER called when the toolbar has been localized - so ALWAYS use the English names!
    DockBarRightOf GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarDiagramCaption____diagram)), GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarStandardCaption____standard))
    DockBarRightOf GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarEditCaption____edit)), GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarDiagramCaption____diagram))
    DockBarRightOf GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarZoomCaption____zoom)), GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarEditCaption____edit))
    DockBarRightOf GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarSearchCaption____search)), GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarZoomCaption____zoom))
    DockBarRightOf GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarSymbolAlignCaption____symbolalign)), GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarSymbolStyleCaption____symbolstyle))
    DockBarRightOf GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarSymbolSelectCaption____symbolselect)), GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarSymbolAlignCaption____symbolalign))
    DockBarRightOf GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarVisualBasicCaption____visualbasic)), GetCommandBarFromName(SAXRes.GetUSEnglishString(IDS_DsgnT_ToolbarEditCaption____edit))
    Exit Sub

ErrorHandler:

End Sub

Private Sub DockBarRightOf(BarToDock As CommandBar, BarOnLeft As CommandBar)
    
    Dim Left As Long
    Dim Top As Long
    Dim Right As Long
    Dim Bottom As Long
    
    On Error GoTo ErrorHandler
    
    m_objToolBars.RecalcLayout
    BarOnLeft.GetWindowRect Left, Top, Right, Bottom
    m_objToolBars.DockToolBar BarToDock, Right, (Bottom + Top) / 2, BarOnLeft.Position

    Exit Sub
    
ErrorHandler:

End Sub
