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

Private m_objBand As XtremeCommandBars.CommandBar

Private m_colTools As New SAToolbarTools

Private m_strCaption As String
Private m_strName As String
Private m_blnExtension As Boolean

Friend Property Get IsExtension() As Boolean
    IsExtension = m_blnExtension
End Property

Friend Property Let IsExtension(ByVal v_bln As Boolean)
    m_blnExtension = v_bln
End Property

Friend Property Get BarID() As Long
    If Not m_objBand Is Nothing Then
        BarID = m_objBand.BarID
    End If
End Property

Public Property Let IsCustomizable(ByVal v_blnValue As Boolean)
    If Not m_objBand Is Nothing Then
        m_objBand.Customizable = v_blnValue
    End If
End Property

Public Property Get IsCustomizable() As Boolean
    If Not m_objBand Is Nothing Then
        IsCustomizable = m_objBand.Customizable
    End If
End Property

Public Property Get Tools() As SAToolbarTools
    Set Tools = m_colTools
End Property

Public Property Get TypeX() As SATOOLBAR_BANDTYPE
    If m_objBand Is Nothing Then
        TypeX = SATB_BT_POPUP
    Else
        Select Case m_objBand.type
            Case xtpBarTypeMenuBar
                TypeX = SATB_BT_MENU
            Case xtpBarTypePopup:
                TypeX = SATB_BT_POPUP
            Case Else
                TypeX = SATB_BT_NORMAL
        End Select
    End If
End Property
Public Property Let TypeX(ByVal v_enuValue As SATOOLBAR_BANDTYPE)
'' This is READONLY
''    Select Case v_enuValue
''        Case SATB_BT_MENU
''            m_objBand.Type = xtpBarTypeMenuBar
''        Case SATB_BT_POPUP:
''            m_objBand.Type = xtpBarTypePopup
''        Case Else
''            m_objBand.Type = xtpBarTypeNormal
''    End Select
End Property

Public Property Get Visible() As Boolean
    If m_objBand Is Nothing Then
        Visible = True
    Else
        Visible = m_objBand.Visible
    End If
End Property
Public Property Let Visible(ByVal v_blnValue As Boolean)
    If Not m_objBand Is Nothing Then
        m_objBand.Visible = v_blnValue
    End If
End Property

Public Property Get Customizable() As Boolean
    Customizable = m_objBand.Customizable
End Property
Public Property Let Customizable(ByVal v_blnValue As Boolean)
    m_objBand.Customizable = v_blnValue
End Property

Public Property Get Closeable() As Boolean
    If Not m_objBand Is Nothing Then
        On Error Resume Next ' errors in eval
        Customizable = m_objBand.Closeable
    End If
End Property
Public Property Let Closeable(ByVal v_blnValue As Boolean)
    If Not m_objBand Is Nothing Then
        On Error Resume Next ' errors in eval
        m_objBand.Closeable = v_blnValue
    End If
End Property

Public Property Get Wrappable() As Boolean
'' Not supported
''''    If m_objBand Is Nothing Then
''''        Wrappable = False
''''    Else
''''        Wrappable = m_objBand.Wrappable
''''    End If
End Property
Public Property Let Wrappable(ByVal v_blnValue As Boolean)
'' Not supported
''''    If Not m_objBand Is Nothing Then
''''        m_objBand.Wrappable = v_blnValue
''''    End If
End Property

Public Property Get BandName() As String
    BandName = m_strName
End Property

Public Property Get Caption() As String
    If Not m_objBand Is Nothing Then
        Caption = m_objBand.Title
    Else
        Caption = m_strName
    End If
End Property
Public Property Let Caption(ByVal v_strValue As String)
    If Not m_objBand Is Nothing Then
        m_objBand.Title = v_strValue
    End If
End Property

Public Property Get DockingArea() As SATOOLBAR_DOCKINGAREA
    If m_objBand Is Nothing Then
        DockingArea = SATB_DA_Popup
    Else
        Select Case m_objBand.position
            Case xtpBarBottom:
                DockingArea = SATB_DA_Bottom
            Case xtpBarFloating:
                DockingArea = SATB_DA_Float
            Case xtpBarLeft:
                DockingArea = SATB_DA_Left
            Case xtpBarPopup:
                DockingArea = SATB_DA_Popup
            Case xtpBarRight:
                DockingArea = SATB_DA_Right
            Case Else ' xtpBarTop:
                DockingArea = SATB_DA_Top
        End Select
    End If
End Property
Public Property Let DockingArea(ByVal v_enuValue As SATOOLBAR_DOCKINGAREA)
    If Not m_objBand Is Nothing Then
        Select Case m_objBand.DockingArea
            Case SATB_DA_Bottom:
                m_objBand.DockingArea = xtpBarBottom
            Case SATB_DA_Float:
                m_objBand.DockingArea = xtpBarFloating
            Case SATB_DA_Left:
                m_objBand.DockingArea = xtpBarLeft
            Case SATB_DA_Popup:
                m_objBand.DockingArea = xtpBarPopup
            Case SATB_DA_Right:
                m_objBand.DockingArea = xtpBarRight
            Case Else ' xtpBarTop:
                m_objBand.DockingArea = xtpBarTop
        End Select
    End If
End Property

Public Sub Refresh()
    If Not m_objBand Is Nothing Then
        m_objBand.Refresh
    End If
End Sub

Public Sub Init(ByVal v_strBandName As String, ByRef r_objCommandBar As XtremeCommandBars.CommandBar)
    ' Init the tools collection
    m_colTools.Init v_strBandName, r_objCommandBar
    Set m_objBand = r_objCommandBar
    Title = v_strBandName
    m_strName = v_strBandName   ' Ensure the ORIGINAL US English band name is remembered
End Sub

' if tool of name strKey is present in band then that is returned
' r_tTopTool is set to the tool in the root band that contains the located tool in a subband
Public Function FindToolInSubBands(ByVal strKey As String, ByRef r_tTopTool As SAToolbarTool, Optional ByVal v_bRecursiveCall As Boolean = False) As SAToolbarTool
    Dim objTool As SAToolbarTool
    Dim objRet As SAToolbarTool
    Dim lngIndex As Long
    
    If Not v_bRecursiveCall Then
        Set r_tTopTool = Nothing
    End If
    
    Set objTool = Me.Tools(strKey)
    If Not objTool Is Nothing Then
        Set objRet = objTool
    Else
        For lngIndex = 0 To Me.Tools.Count - 1
            Set objTool = Me.Tools(lngIndex)
        
            If Not objTool.SubBand Is Nothing Then
                Set objRet = objTool.SubBand.FindToolInSubBands(strKey, r_tTopTool, True)
                If Not objRet Is Nothing Then
                    If Not v_bRecursiveCall And r_tTopTool Is Nothing Then
                        Set r_tTopTool = objTool
                    End If
                    Exit For
                End If
            End If
        Next
    End If
    
    Set FindToolInSubBands = objRet
End Function

Public Sub ReplaceTools(ByRef bandFrom As SAToolbarBand)
    Dim t As SAToolbarTool
    Dim t2 As SAToolbarTool
    Dim l As Long
    Dim l2 As Long
    Dim s As String
    
    If Not bandFrom Is Nothing Then
        Tools.RemoveAll
        For l = 0 To bandFrom.Tools.Count - 1
            Set t = bandFrom.Tools.Item(l)
            Set t2 = Tools.Add(t.toolID, t.name, Len(t.SubBandName) > 0)
            If Not t2 Is Nothing Then
                t2.Tool.iconID = t.Tool.iconID
                t2.Style = t.Style
            End If
        Next
    End If
End Sub

Public Property Get Band() As XtremeCommandBars.CommandBar
    Set Band = m_objBand
End Property

' Note this uses the Checked state of SAToolbarTool which may be inconsistent with the current real tool
' The invoked function updates the SAToolbarTools and actual tools
Public Sub UncheckAll(ByVal v_blnRec As Boolean, ByVal v_blnStopAtFirst As Boolean, Optional ByVal v_iFlags As Integer = 1, Optional ByRef r_col As Collection)
    Dim t As SAToolbarTool
    Dim l As Long
    Dim s As String
    Dim bRecCall As Boolean
    
    On Error GoTo eh
    If Not r_col Is Nothing Then
        bRecCall = True
    Else
        Set r_col = New Collection
    End If
    
    If Not m_colTools Is Nothing Then
        For l = 0 To m_colTools.Count - 1
            If (v_iFlags And 1) <> 0 Then
                Set t = fMainForm.ATB.Tools(m_colTools(l).name)
            Else
                Set t = m_colTools(l)
            End If
            If Not t Is Nothing Then
                'If t.Checked Then
                    s = t.name
                    If (v_iFlags And 1) <> 0 Then
                        CheckMenuTool t, False
                    Else
                        't.Checked2 False, True
                        r_col.Add t
                    End If
                    If Not t.SubBand Is Nothing Then
                        t.SubBand.UncheckAll v_blnRec, v_blnStopAtFirst, , r_col
                    End If
                    If v_blnStopAtFirst Then
                        Exit For
                    End If
                'End If
            End If
        Next
    End If
    
    If Not bRecCall Then
        For Each t In r_col
            t.Checked = False
            t.Checked2 False, True
        Next
    End If
    Exit Sub
eh:
End Sub
