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

' WARNING remember that tool objects within bands are not the same objects as in the root tools collection of the
'control. Therfore you must be consistent with regards to which collection you access the tool from.

Private m_objTool As XtremeCommandBars.CommandBarControl

Private m_objSubBand As SAToolbarBand
Private m_strExecToolID As String
Private m_lngUpdateFlags As Long
Private m_lngHelpID As Long
Private m_strMacroArg As String
Private m_blnIsMaster As Boolean
Private m_blnExtension As Boolean
Private m_blnCancelIfFocusLost As Boolean
Private m_blnIsDrawMenuPopup As Boolean
Private m_lngIconID As Long ' override
Private m_lngListIndex As Long
Private m_strText As String

Private m_enuROState As SATOOLBAR_ROSTATE

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 CancelIfFocusLost() As Boolean
    CancelIfFocusLost = m_blnCancelIfFocusLost
End Property

Friend Property Let CancelIfFocusLost(ByVal v_bln As Boolean)
    m_blnCancelIfFocusLost = v_bln
End Property

Public Function CanItemBeAdded(ByVal v_strText As String) As Boolean
Dim objTool As XtremeCommandBars.CommandBarComboBox
Dim lngRes As Long

    On Error GoTo ErrOut
    
    CanItemBeAdded = False
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            lngRes = objTool.FindItem(v_strText)
            If lngRes = 0 Then
                CanItemBeAdded = True
            End If
        End If
    End If
    
StdExit:
    On Error GoTo 0
    Exit Function
ErrOut:
    Err.Clear
    Resume StdExit
End Function

Public Sub MoveItemToTop(ByVal v_strText As String)
Dim objTool As XtremeCommandBars.CommandBarComboBox
Dim lngRes As Long

    On Error GoTo ErrOut
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            lngRes = objTool.FindItem(v_strText)
            If lngRes <> 0 Then
                objTool.RemoveItem lngRes
                objTool.AddItem v_strText, 1
                ' At this pointm_lngListIndex still points to the old index
                If m_lngListIndex = lngRes Then
                    m_lngListIndex = 1
                ElseIf m_lngListIndex < lngRes Then
                    m_lngListIndex = m_lngListIndex + 1
                End If
            End If
        End If
    End If
    
StdExit:
    On Error GoTo 0
    Exit Sub
ErrOut:
    Err.Clear
    Resume StdExit
End Sub
Friend Property Get Tool() As XtremeCommandBars.CommandBarControl
    Set Tool = m_objTool
End Property

Public Property Get MacroArgument() As String
    MacroArgument = m_strMacroArg
End Property

Public Property Let MacroArgument(ByVal v_strValue As String)
    If m_strMacroArg <> v_strValue Then
        m_strMacroArg = v_strValue
        If CmdLineToolCheck Then
            TOOLCHECK_ToolChanged Me
        End If
    End If
End Property

Public Property Get Alignment() As SATOOLBAR_ALIGNMENT
'' Text alignment - Not supported by XtremeCunsignedLongommandBars
    Alignment = SATB_AL_CenterCenter    ' Return default
    
''    Select Case m_objTool.Alignment
''        Case DDALeftTop:
''            Alignment = SATB_AL_LeftTop
''        Case DDACenterTop:
''            Alignment = SATB_AL_CenterTop
''        Case DDARightTop:
''            Alignment = SATB_AL_RightTop
''        Case DDALeftCenter:
''            Alignment = SATB_AL_LeftCenter
''        Case DDARightCenter:
''            Alignment = SATB_AL_RightCenter
''        Case DDALeftBottom:
''            Alignment = SATB_AL_LeftBottom
''        Case DDACenterBottom:
''            Alignment = SATB_AL_CenterBottom
''        Case DDARightBottom:
''            Alignment = SATB_AL_RightBottom
''        Case Else 'DDACenterCenter:
''            Alignment = SATB_AL_CenterCenter
''    End Select
End Property
Public Property Let Alignment(ByVal v_enuValue As SATOOLBAR_ALIGNMENT)
'' Text alignment - Not supported by XtremeCommandBars
'' Do nothing

''    Select Case v_enuValue
''        Case SATB_AL_LeftTop:
''            m_objTool.Alignment = DDALeftTop
''        Case SATB_AL_CenterTop:
''            m_objTool.Alignment = DDACenterTop
''        Case SATB_AL_RightTop:
''            m_objTool.Alignment = DDARightTop
''        Case SATB_AL_LeftCenter:
''            m_objTool.Alignment = DDALeftCenter
''        Case SATB_AL_RightCenter:
''            m_objTool.Alignment = DDARightCenter
''        Case SATB_AL_LeftBottom:
''            m_objTool.Alignment = DDALeftBottom
''        Case SATB_AL_CenterBottom:
''            m_objTool.Alignment = DDACenterBottom
''        Case SATB_AL_RightBottom:
''            m_objTool.Alignment = DDARightBottom
''        Case Else 'DDACenterCenter:
''            m_objTool.Alignment = DDACenterCenter
''    End Select
End Property

Public Property Get BeginGroup() As Boolean
    BeginGroup = m_objTool.BeginGroup
End Property
Public Property Let BeginGroup(ByVal v_blnValue As Boolean)
    m_objTool.BeginGroup = v_blnValue
End Property
                      
Public Property Get Caption() As String
    Caption = m_objTool.Caption
End Property
Public Property Let Caption(ByVal v_strValue As String)
    If m_objTool.Caption <> v_strValue Then
        m_objTool.Caption = v_strValue
        If CmdLineToolCheck Then
            TOOLCHECK_ToolChanged Me
        End If
    End If
End Property

Public Property Get name() As String
    name = m_objTool.Parameter
End Property
Public Property Let name(ByVal v_strValue As String)
    m_objTool.Parameter = v_strValue
End Property

Public Property Get SubBandName() As String
    If m_blnIsMaster Then
        If Not m_objSubBand Is Nothing Then
            SubBandName = m_objSubBand.BandName
        Else
    ''        SubBandName = m_strSubBandName
            SubBandName = SA_VB_EmptyString
        End If
    Else
        On Error Resume Next
        SubBandName = fMainForm.ATB.Tools(Me.name).SubBandName
    End If
End Property

Public Property Get SubBand() As SAToolbarBand
    If m_blnIsMaster Then
        Set SubBand = m_objSubBand
    Else
        On Error Resume Next
        Set SubBand = fMainForm.ATB.Tools(Me.name).SubBand
        On Error GoTo 0
    End If
End Property
Public Property Set SubBand(ByRef r_objValue As SAToolbarBand)
    If m_blnIsMaster Then
        Set m_objSubBand = r_objValue
        If Not TypeOf m_objTool Is XtremeCommandBars.CommandBarPopup Then
            If CmdLineQAReporting Then
                SAMessageBox "Error in toolbar file - Unable to convert tool to Popup - " & Me.Caption & " - " & Me.name & " OBJ = " & CStr(m_objTool.type) 'DEV_STRING
            End If
            Exit Property
        End If
    Else
        Set fMainForm.ATB.Tools(Me.name).SubBand = r_objValue
    End If
End Property

Public Property Get Category() As String
    Category = m_objTool.Category
End Property
Public Property Let Category(ByVal v_strValue As String)
    m_objTool.Category = v_strValue
End Property
        
Public Property Get Description() As String
    Description = m_objTool.DescriptionText
End Property
Public Property Let Description(ByVal v_strValue As String)
    m_objTool.DescriptionText = v_strValue
End Property
        
Public Property Get HelpContextID() As Long
    HelpContextID = m_lngHelpID
End Property
Public Property Let HelpContextID(ByVal v_lngValue As Long)
    m_lngHelpID = v_lngValue
End Property
        
Public Property Get Style() As SATOOLBAR_STYLES
    If m_objTool.type = xtpControlButton Or m_objTool.type = xtpControlButtonPopup Then
        Select Case m_objTool.Style
            Case xtpButtonCaption:
                Style = SATB_ST_Text
            Case xtpButtonIcon:
                Style = SATB_ST_Icon
            Case xtpButtonIconAndCaption
                Style = SATB_ST_IconText
            Case Else ' xtpButtonAutomatic
                Style = SATB_ST_Standard
        End Select
    Else
        Style = SATB_ST_Standard
    End If
End Property
Public Property Let Style(ByVal v_enuValue As SATOOLBAR_STYLES)
    If m_objTool.type = xtpControlButton Or m_objTool.type = xtpControlButtonPopup Then
        Select Case v_enuValue
            Case SATB_ST_Text:
                m_objTool.Style = xtpButtonCaption
            Case SATB_ST_Icon:
                m_objTool.Style = xtpButtonIcon
            Case SATB_ST_IconText
                m_objTool.Style = xtpButtonIconAndCaption
            Case Else ' xtpButtonAutomatic
                m_objTool.Style = xtpButtonAutomatic
        End Select
    End If
End Property
       
Public Property Get Enabled() As Boolean
    Enabled = m_objTool.Enabled
End Property

Public Property Let Enabled(ByVal v_blnValue As Boolean)
    m_objTool.Enabled = v_blnValue
End Property

Public Property Get Visible() As Boolean
    Visible = m_objTool.Visible
End Property
Public Property Let Visible(ByVal v_blnValue As Boolean)
    m_objTool.Visible = v_blnValue
End Property

Public Property Get Checked() As Boolean
    Checked = m_objTool.Checked
End Property
Public Property Let Checked(ByVal v_blnValue As Boolean)
    m_objTool.Checked = v_blnValue
End Property
Public Sub Checked2(ByVal v_blnValue, Optional v_bSetMain As Boolean = False)
    If m_blnIsMaster Or Not v_bSetMain Then
        m_objTool.Checked = v_blnValue
    ElseIf v_bSetMain Then
        On Error Resume Next ' the item may not be found:
        fMainForm.ATB.Tools(Me.name).Checked2 v_blnValue
    End If
End Sub

Public Property Get Text() As String
    Text = m_strText
End Property
Public Property Let Text(ByVal v_strValue As String)
    m_strText = v_strValue
    If ControlType = SATB_TT_COMBOBOX Then
        m_lngListIndex = CBListFindItem(v_strValue)
    End If
End Property

Public Property Get ToolTipText() As String
    ToolTipText = m_objTool.ToolTipText
End Property
Public Property Let ToolTipText(ByVal v_strValue As String)
    m_objTool.ToolTipText = v_strValue
    If CmdLineToolCheck Then
        If m_objTool.ToolTipText <> v_strValue Then
            TOOLCHECK_ToolChanged Me
        End If
    End If
End Property

Public Property Get ExecCommandID() As String
    If m_blnIsMaster Then
        ExecCommandID = m_strExecToolID
    Else
        ExecCommandID = fMainForm.ATB.Tools(Me.name).ExecCommandID
    End If
End Property
Public Property Let ExecCommandID(ByVal v_strValue As String)
    If m_blnIsMaster Then
        m_strExecToolID = v_strValue
    Else
        fMainForm.ATB.Tools(Me.name).ExecCommandID = v_strValue
    End If
End Property

Public Property Get UpdateFlags() As Long
    If m_blnIsMaster Then
        UpdateFlags = m_lngUpdateFlags
    Else
        On Error Resume Next
        UpdateFlags = fMainForm.ATB.Tools(Me.name).UpdateFlags
    End If
End Property
Public Property Let UpdateFlags(ByVal v_lngValue As Long)
    If m_blnIsMaster Then
        m_lngUpdateFlags = v_lngValue
    Else
        On Error Resume Next
        fMainForm.ATB.Tools(Me.name).UpdateFlags = v_lngValue
    End If
End Property

Public Property Get iconID() As Long
    iconID = m_lngIconID
End Property

Public Property Let iconID(ByVal v_lngValue As Long)
    m_lngIconID = v_lngValue
End Property

Public Property Get toolID() As Long
    toolID = m_objTool.Id
End Property

Public Property Let toolID(ByVal v_lngValue As Long)
    If m_objTool.Id <> 0 Then
        ' Previously had a number
    Else
        m_objTool.Id = v_lngValue
    End If
End Property

Public Property Get ControlType() As SATOOLBAR_TOOLTYPE
    Select Case m_objTool.type
        Case xtpControlSplitButtonPopup:
            ControlType = SATB_TT_BUTTONDROPDOWN
        Case xtpControlComboBox:
            ControlType = SATB_TT_COMBOBOX
        Case xtpControlEdit:
            ControlType = SATB_TT_EDIT
        Case xtpControlLabel:
            ControlType = SATB_TT_STATIC
        Case xtpControlButtonPopup:
            ControlType = SATB_TT_BUTTONPOPUP
        Case Else
            ControlType = SATB_TT_BUTTON
    End Select
End Property
Public Property Let ControlType(ByVal v_enuValue As SATOOLBAR_TOOLTYPE)
' This property is READONLY for real tool items - because it is read only in the control we use
End Property

' Create is called when we wish to setup AND REALLY CREATE a tool and SAToolBarTool for use by the client
Public Sub Create(ByRef r_objTool As XtremeCommandBars.CommandBarControl)
    Dim objPicture As IPictureDisp
    
    Set m_objTool = r_objTool
    
    ' override style, based on whether the tool has a bitmap...
    On Error Resume Next
    Set objPicture = SALoadResPicture(1000 + m_objTool.Id, vbResBitmap)
    
    On Error GoTo 0
    If Not objPicture Is Nothing Then
        fMainForm.ctlImageMan.Icons.AddBitmap objPicture.Handle, m_objTool.Id, xtpImageNormal, False
        Style = SATB_ST_Icon
    Else
        Style = SATB_ST_Text
    End If
End Sub

' Init is called when we wish to setup a SAToolBarTool for use by the client
' This is NOT the same as creating one in the toolbar for real - we only provide this as an interface
Public Sub Init(ByRef r_objTool As XtremeCommandBars.CommandBarControl, Optional ByVal v_blnIsMasterTool As Boolean = False)
    Set m_objTool = r_objTool
    m_blnIsMaster = v_blnIsMasterTool
End Sub

Public Sub ClearPicture()
    fMainForm.ctlImageMan.Icons.RemoveIcon Me.toolID
    m_objTool.iconID = Me.toolID
End Sub

Public Sub CopyPicture(ByRef objFromTool As SAToolbarTool)
    Dim objTool As SAToolbarTool
    Dim l As Long
    
    Set objTool = objFromTool

    If Not objTool Is Nothing Then
        If SATB_ST_Icon = objTool.Style _
        Or SATB_ST_IconText = objTool.Style Then
            ' Copy image from that tool
            ' Get internal tool
            Dim objIntTool As XtremeCommandBars.CommandBarControl
            Set objIntTool = objTool.Tool
            If Not objIntTool Is Nothing Then
                l = objIntTool.iconID
                m_objTool.iconID = objIntTool.iconID
                l = m_objTool.iconID
            End If
            m_objTool.Style = objTool.Style
        End If
        Exit Sub
    End If
End Sub

Public Sub SetPicture(Optional ByVal v_varImageFileOrIndex As Variant)
    Dim objPicture As IPictureDisp
    Dim strBMPFile As String
    Dim lngIconID As Long
    
    Style = SATB_ST_Text
    
    If IsMissing(v_varImageFileOrIndex) Then
        v_varImageFileOrIndex = toolID
        If iconID <> 0 Then
            v_varImageFileOrIndex = iconID
        End If
    End If
    
    If TypeOf v_varImageFileOrIndex Is StdPicture Then
        On Error Resume Next
        fMainForm.ctlImageMan.Icons.AddBitmap v_varImageFileOrIndex.Handle, m_objTool.iconID, xtpImageNormal, False
        If Err.Number = 0 Then
            Style = SATB_ST_Icon
        End If
    ElseIf IsNumeric(v_varImageFileOrIndex) Then
        On Error Resume Next
        lngIconID = CLng(v_varImageFileOrIndex)
        On Error GoTo 0
        If lngIconID > 0 Then
            If m_objTool.Id <> lngIconID Then
                m_objTool.iconID = lngIconID    ' Some tools have a different icon to their id (popup stereotype symbol icons)
                Style = SATB_ST_Icon
            Else
                On Error Resume Next
                'First check for an icon resource
                Set objPicture = SALoadResPicture(1000 + lngIconID, vbResIcon)
                
                'If we didn't find an icon check for a bitmap resource
                If objPicture Is Nothing Then
                    Set objPicture = SALoadResPicture(1000 + lngIconID, vbResBitmap)
                End If
                
                On Error GoTo 0
                If Not objPicture Is Nothing Then
                    On Error Resume Next
                    If objPicture.type = vbPicTypeIcon Then
                        fMainForm.ctlImageMan.Icons.AddIcon objPicture.Handle, m_objTool.iconID, xtpImageNormal
                    Else
                        fMainForm.ctlImageMan.Icons.AddBitmap objPicture.Handle, m_objTool.iconID, xtpImageNormal, False
                    End If
                    If Err.Number = 0 Then
                        Style = SATB_ST_Icon
                    End If
                End If
            End If
        End If
    Else
        ' Could be a filename
        On Error Resume Next
        strBMPFile = v_varImageFileOrIndex
        On Error GoTo 0
        If strBMPFile <> SA_VB_EmptyString Then
            On Error Resume Next
            fMainForm.ctlImageMan.Icons.LoadBitmap strBMPFile, m_objTool.iconID, xtpImageNormal
            If Err.Number = 0 Then
                Style = SATB_ST_Icon
            End If
            On Error GoTo 0
        End If
    End If
End Sub

Public Sub CBListAddItem(ByVal v_strText As String)
    Dim objTool As XtremeCommandBars.CommandBarComboBox
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            objTool.AddItem v_strText
        End If
    End If
End Sub

' 1-based
Public Sub CBListRemoveItem(ByVal ndx As Long)
    Dim objTool As XtremeCommandBars.CommandBarComboBox
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            objTool.RemoveItem ndx
        End If
    End If
End Sub

Public Sub CBListRemoveLastItem()
    Dim objTool As XtremeCommandBars.CommandBarComboBox
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            objTool.RemoveItem objTool.ListCount
        End If
    End If
End Sub
Public Sub CBListAddItemAtTop(ByVal v_strText As String)
    Dim objTool As XtremeCommandBars.CommandBarComboBox
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            objTool.AddItem v_strText, 1
        End If
    End If
End Sub
Public Sub CBListClear()
    Dim objTool As XtremeCommandBars.CommandBarComboBox
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            objTool.Clear
        End If
    End If
End Sub

Public Property Get CBListCount() As Long
    Dim objTool As XtremeCommandBars.CommandBarComboBox
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            CBListCount = objTool.ListCount
        End If
    End If
End Property

' 0-based!!!!
Public Property Get CBListItem(ByVal v_lngIndex As Long) As String
    Dim objTool As XtremeCommandBars.CommandBarComboBox
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            CBListItem = objTool.List(v_lngIndex + 1)
        End If
    End If
End Property

' 1-based; can be left at 0 by setting text value that isn't in the list
Public Property Get CBListIndex() As Long
    CBListIndex = m_lngListIndex
End Property

Public Property Let CBListIndex(ByVal v_lngValue As Long)
    m_lngListIndex = v_lngValue
    If ControlType = SATB_TT_COMBOBOX Then
        If v_lngValue > 0 Then
            m_strText = CBListItem(v_lngValue - 1)
        Else
            m_strText = ""
        End If
    End If
End Property

' Returns 0 if not found
' 1-based if found
Public Function CBListFindItem(ByVal v_strValue As String) As Long
    Dim objTool As XtremeCommandBars.CommandBarComboBox
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            CBListFindItem = objTool.FindItem(v_strValue)
        End If
    End If
End Function

Public Property Get CBWidth() As Long
    Dim objTool As XtremeCommandBars.CommandBarComboBox
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            CBWidth = objTool.Width
        End If
    End If
End Property

Public Property Let CBWidth(ByVal v_lngValue As Long)
    Dim objTool As XtremeCommandBars.CommandBarComboBox
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_COMBOBOX Then
            Set objTool = m_objTool
            objTool.Width = v_lngValue
        End If
    End If
End Property

Public Property Get EditWidth() As Long
    Dim objTool As XtremeCommandBars.CommandBarEdit
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_EDIT Then
            Set objTool = m_objTool
            EditWidth = objTool.Width
        End If
    End If
End Property

Public Property Let EditWidth(ByVal v_lngValue As Long)
    Dim objTool As XtremeCommandBars.CommandBarEdit
    
    If Not m_objTool Is Nothing Then
        If Me.ControlType = SATB_TT_EDIT Then
            Set objTool = m_objTool
            objTool.Width = v_lngValue
        End If
    End If
End Property

Public Property Get ROState() As SATOOLBAR_ROSTATE
    ROState = m_enuROState
End Property

Public Property Let ROState(ByVal v_enuState As SATOOLBAR_ROSTATE)
    m_enuROState = v_enuState
End Property

Private Sub Class_Initialize()
    m_blnCancelIfFocusLost = True   ' Default behaviour
End Sub

' RE combo controls: false means listonly, true means editable combo
Public Property Let DropDownListStyle(b As Boolean) ' for combo controls
    Tool.DropDownListStyle = b
End Property
Public Property Get DropDownListStyle() As Boolean ' for combo controls
    DropDownListStyle = Tool.DropDownListStyle
End Property

Public Property Let IsDrawMenuPopup(ByVal b As Boolean)
    If m_blnIsMaster Then
        m_blnIsDrawMenuPopup = b
    Else
        On Error Resume Next
        fMainForm.ATB.Tools(Me.name).IsDrawMenuPopup = b
    End If
End Property
Public Property Get IsDrawMenuPopup() As Boolean
    If m_blnIsMaster Then
        IsDrawMenuPopup = m_blnIsDrawMenuPopup
    Else
        On Error Resume Next
        IsDrawMenuPopup = fMainForm.ATB.Tools(Me.name).IsDrawMenuPopup
    End If
End Property

Public Property Get CBHwnd() As Long
    Dim objTool As XtremeCommandBars.CommandBarComboBox

    Set objTool = m_objTool
    CBHwnd = objTool.EditHandle
End Property
