Attribute VB_Name = "Menusubs"
Option Explicit

Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hDC As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As Size) As Long ' DEV_STRING
Public Const SYSMENU_SEPARATORID = 0
Public Const SYSMENU_SEPARATORNAME = "SYSMENU_SEPARATOR"        'DEV_STRING

Global Const IDMEXIT = 251
Global Const TOOL_SELECT = "SAIDM_299"        'DEV_STRING

Const TOOL_PEN_FIRST = 10022
Const TOOL_PEN_DEFAULT = "SAIDM_10023"        'DEV_STRING
Const TOOL_PEN_LAST = 10031
Const TOOL_PEN_10 = 10050

'+ BSS #18201
' JohnC 20-Oct-05
Global Const IDMEDITDLGSOFFSET = 600        'NO ids should be inserted between 600 and 699 because menu items are addded dynamically
Global Const IDMEDITDLGSLIMIT = 699
'- BSS #18201

Const MATRIX_MENU_FIRST = 364
Const IDMMATADDROW = 364
Const IDMMATADDCOL = 366
Const IDMMATVERTICAL = 367
Const IDMMATHORIZ = 368
Const IDMMATSLANTED = 369
Const IDMMATSORTROW = 370
Const IDMMATSORTCOL = 371
Const IDMMATAUTOFIT = 372
Const IDMMATRELOAD = 373
Const IDMMATREFRESH = 374
Const IDMMATXINCELL = 375
Const IDMMATMRU = 376
Const IDMMATPRINT = 377
Const IDMMATPRINTPREVIEW = 378
Const IDMMATSAVE = 379
Const IDMMATSAVEAS = 380
Const IDMMATEXPORT = 381
Const IDMMATINFER = 382
Const IDMMATCLOSE = 383
Const IDMMATROWLEFT = 384
Const IDMMATROWRIGHT = 385
Const IDMMATROWCENTRE = 386
Const IDMMATPRINTSETTINGS = 387
Const IDMMATSWITCHCOLSANDROWS = 388
Const IDMMATADDROWHEADER = 389
Const IDMMATADDCOLHEADER = 390
Const MATRIX_MENU_LAST = 393

Const PROP_OBJECT_IDENTIFIER As String = "Object Identifier"        ' DEV_STRING
Const MAX_MEMO_TEXT As Long = 32765

Public Const IDM_STATEFILTER = 800
Public Const IDM_ActiveCR = 801        ' Active CR has no icon, if it gets one this should probably be changed

Public Const SAIDM_TOOLBARCUSTOMIZE = 10008        ' Customize dialog for the toolbar
Public Const TOOL_TOOLBARCUSTOMIZE = "SAIDM_10008"        'DEV_STRING Customize dialog for the toolbar
Public Const SAIDM_TOOLBARRESET = 10009        ' Reset the toolbar to initial state
Public Const TOOL_TOOLBARRESET = "SAIDM_10009"        'DEV_STRING Reset the toolbar to initial state

Global Const BAND_DRAWTOOLBOX = "Draw"        'DEV_STRING
Global Const BAND_DRAWMENU = "id_Draw"        'DEV_STRING
Global Const TOOL_DRAWMENU = "id_Draw"        'DEV_STRING
Global Const BAND_DRAWLINEMENU = "id_DrawLine"        'DEV_STRING
Global Const BAND_DRAWNODEMENU = "id_DrawNode"        'DEV_STRING

Global Const BAND_DIAGRAM = "Diagram"        'DEV_STRING
Global Const TOOL_ZOOMPERCENT = "SAIDM_10033"        'DEV_STRING
Global Const TOOL_ZOOMER = "SAIDM_64"        'DEV_STRING

Global Const BAND_SEARCH = "Search"        'DEV_STRING
Global Const BAND_SEARCHCONTEXT = "id_SearchContext"        'DEV_STRING
Global Const TOOL_SEARCHCONTEXT = "id_SearchContext"        'DEV_STRING
Global Const BAND_OSLCCONTEXT = "id_OSLCCMMangament"        'DEV_STRING
Global Const TOOL_SEARCHTEXT = "SAIDM_10036"        'DEV_STRING
Global Const TOOL_SEARCHGO = "SAIDM_10037"        'DEV_STRING
Global Const TOOL_SEARCHALL = "SAIDM_10038"        'DEV_STRING
Global Const TOOL_SEARCHDGMSSYMS = "SAIDM_10039"        'DEV_STRING
Global Const TOOL_SEARCHDGMS = "SAIDM_10057"        'DEV_STRING
Global Const TOOL_SEARCHSYMS = "SAIDM_10058"        'DEV_STRING
Global Const TOOL_SEARCHSYMSONCURRDGM = "SAIDM_10059"        'DEV_STRING
Global Const TOOL_SEARCHDEFSONCURRDGM = "SAIDM_10064"        'DEV_STRING
Global Const TOOL_SEARCHDEFNS = "SAIDM_10040"        'DEV_STRING
Global Const TOOL_SEARCHADV = "SAIDM_10042"        'DEV_STRING
Global Const TOOL_OBJHIST = "SAIDM_10043"        ' DEV_STRING
Global Const TOOL_VIEWHMAPMGR = "SAIDM_10048"        ' DEV_STRING
Global Const BAND_SYMBOLSTYLE = "Symbol Style"        'DEV_STRING
Global Const BAND_PENS = "id_Pens"        'DEV_STRING
Global Const BAND_MATRIX = "Matrix"        'DEV_STRING
Global Const TOOL_FONTWHICH = "SAIDM_10049"        'DEV_STRING
Global Const TOOL_FONTNAMEDSTYLE = "SAIDM_10060"   'DEV_STRING
Global Const TOOL_FONTNAMEDSTYLE_MANAGE = "id_ManageNamedStyle"   'DEV_STRING
Global Const TOOL_FONTNAMEDSTYLE_RECORD = "SAIDM_10066" ' DEV_STRING
Global Const TOOL_FONTNAMEDSTYLE_COPYTO = "SAIDM_10068" ' DEV_STRING
Global Const TOOL_FONTNAMEDSTYLE_ADD = "SAIDM_10063" ' DEV_STRING
Global Const TOOL_FONTNAMEDSTYLE_DELETE = "SAIDM_10065" ' DEV_STRING
Global Const TOOL_FONTNAME = "SAIDM_10010"        'DEV_STRING
Global Const TOOL_FONTSIZE = "SAIDM_10011"        'DEV_STRING
Global Const TOOL_FONTBOLD = "SAIDM_10012"        'DEV_STRING
Global Const TOOL_FONTITALIC = "SAIDM_10013"        'DEV_STRING
Global Const TOOL_FONTUNDERLINE = "SAIDM_10014"        'DEV_STRING
Global Const TOOL_TEXTLEFT = "SAIDM_10015"        'DEV_STRING
Global Const TOOL_TEXTCENTER = "SAIDM_10016"        'DEV_STRING
Global Const TOOL_TEXTRIGHT = "SAIDM_10017"        'DEV_STRING
#If BIDI_DISABLED = False Then
Global Const TOOL_TEXT_DIRECTION_LTR = "SAIDM_10044"        'DEV_STRING
Global Const TOOL_TEXT_DIRECTION_CONTEXTUAL = "SAIDM_10045"        'DEV_STRING
Global Const TOOL_TEXT_DIRECTION_RTL = "SAIDM_10046"        'DEV_STRING
#End If
Global Const TOOL_PENSTYLE = "id_Pens"        'DEV_STRING
Global Const TOOL_SETSTYLE = "SAIDM_10032"        'DEV_STRING
Global Const TOOL_REPORTLISTCLEAR = "miWReportsClear"        'DEV_STRING
Global Const COLORPREFIX = "COLOR_"        'DEV_STRING
Global Const TOOLX_AUTOMATIC = "AUTOMATIC"        'DEV_STRING
Global Const TOOLX_MORECOLORS = "MORECOLOR"        'DEV_STRING
Global Const TOOL_PENCOLOR = "COLOR_PEN"        'DEV_STRING
Global Const TOOLX_PENCOLOR = "PEN"        'DEV_STRING
Global Const TOOL_FONTCOLOR = "COLOR_FONT"        'DEV_STRING
Global Const TOOLX_FONTCOLOR = "FONT"        'DEV_STRING
Global Const TOOL_FILLCOLOR = "COLOR_FILL"        'DEV_STRING
Global Const TOOLX_FILLCOLOR = "FILL"        'DEV_STRING

Global Const TOOL_SELECTWORKSPACE = "SAIDM_813"        ' DEV_STRING
Global Const TOOL_MANAGEWORKSPACES = "SAIDM_814"        ' DEV_STRING

Global Const TOOL_MODETEXT = "SAIDM_10051"        ' DEV_STRING
Global Const TOOL_APPLYMODE = "SAIDM_10052"        ' DEV_STRING

Global Const TOOL_LISTOSLCCR = "SAIDM_10053"
Global Const TOOL_LISTOSLCCR2 = "SAIDM_10055"
Global Const TOOL_LISTOSLCCR2WARN = "SAIDM_10056"
Global Const TOOL_CONFOSLCCR = "SAIDM_10054"


Global Const DEFAULT_MAX_SYMBOL_SELECTS_STYLE = 50        ' Default maximum number of selected symbols we process to determine the style

' These are hard coded into SA as defaults at the moment
Const AUTO_PENCOLOR = vbBlack
Const AUTO_FONTCOLOR = vbBlack
Const AUTO_FILLCOLOR = vbWhite

Private g_l_MAX_SYMBOL_SELECTS_STYLE As Long        ' Maximum number of selected symbols we process to determine the style
Private ColorPickerSelection As New Collection

Public aColors(14) As Long

Public Enum SA_Text_Flags
    ' text drawing flags in TextFlags - from fontflag.h
    TXLEFT = &H1               '  These four are mutually exclusive, but allocating separate bits simplifies coding
    TXCENTER = &H2
    TXRIGHT = &H4
    TXTABBED = &H100
    
    TXNAMELEFT = &H400            '  These three are mutually exclusive, but allocating separate bits simplifies coding
    TXNAMECENTER = &H800
    TXNAMERIGHT = &H1000
End Enum

Public Enum SA_TextDir_Flags
    ' from memorya.h
    TEXTDIR_LEAVE_UNCHANGED_TEXT_DIRECTION = 0
    TEXTDIR_LTR_TEXT_DIRECTION = 1
    TEXTDIR_RTL_TEXT_DIRECTION = 2
    TEXTDIR_CONTEXTUAL_TEXT_DIRECTION = 3
End Enum

Private PenPickerSelection As Long        ' Contains the current picked pen

' RE Advanced Search storage - arrays contain only as many entries as there are advanced reports
Private arr_lng_AdvancedSearches() As Long        ' Stores index numbers starting from 1 matching Itemn entries written to ini file,
' which identify which items in the Search combo are to be treated as advanced searches
' Value of 0 means the array position can be reused; it shouldn't be treated as a valid report
Private arr_str_AdvancedSearches() As String        ' Stores the actual advanced search reports
'(combo boxes only store 1024 characters, so an array is needed to store the report text)

Private Const MAX_ADVSEARCH_RPT As Long = 32768
Private Const STR_ADVSEARCH_CRTAG As String = "<<SA!CR>>"
Private Const MAX_SEARCH_SAVE As Long = 30        ' Maximum number of searches to save

Private fontarray() As String
Private fontarray_bReady As Boolean

Private Const STR_NAMEDFONTSTYLES As String = "NamedFontStyles"

Private ProcessFontStyle_bDontUpdateFontNameList As Boolean
Private ProcessFontStyle_bBIUfromTool As Boolean
'

Public Function GetPermissionState(ByVal v_lngPermType As Long, ByVal v_strPermID As String, ByRef r_lngFlags As Long, Optional ByRef r_objTool As SAToolbarTool) As Long
    GetPermissionState = 15
End Function

Private Sub RemoveItemIfOverLimit(ByRef r_objTool As SAToolbarTool)
'    Dim strMaxItems As String
'    Dim lngMaxItems As Long
'    Dim lngret As Long
'
'    strMaxItems = Space(4)
'    lngret = SADUtilsVB_ReadSettingNTS("Search", "MaxItems", "10", strMaxItems, Len(strMaxItems), SA_VB_EmptyString)        'DEV_STRING
'    If lngret > 0 Then
'        strMaxItems = szTruncate(strMaxItems)
'        lngMaxItems = CLng(strMaxItems)
'
'        ' Enforce upper limit
'        If (lngMaxItems > MAX_SEARCH_SAVE) Then
'            lngMaxItems = MAX_SEARCH_SAVE
'        End If
'
'        If r_objTool.CBListCount >= lngMaxItems Then
'            r_objTool.CBListRemoveLastItem
'        End If
'    End If
End Sub

Public Sub SetMenuToolStateAsStartup(Optional ByVal v_blnIgnoreMacros As Boolean = False)
    Dim BandItem As SAToolbarBand
    Dim ToolItem As SAToolbarTool
    Dim MainTool As SAToolbarTool
    Dim lngIndex As Long
    Dim strMainMenuBandName As String
    ' Make all tool items visible which are normally visible at startup - (they will be hidden by permissions later - if required)

    strMainMenuBandName = SAXRes.GetLocalString(IDS_uloc_____mainmenu)

    For Each BandItem In fMainForm.ATB.Bands
        If BandItem.BandName <> strMainMenuBandName Then        ' We don't do the top level menu (I.e. File, Edit, View should not have state affected by this code)
            For lngIndex = 0 To BandItem.Tools.Count - 1
                Set ToolItem = BandItem.Tools(lngIndex)
                On Error Resume Next
                Set MainTool = fMainForm.ATB.Tools(ToolItem.name)
                If Err.Number <> 0 Then
                    Set MainTool = Nothing
                End If
                On Error GoTo 0

                If MainTool Is Nothing Then
                    ' The tool is not in the main tool collection - so hide it
                    ToolItem.Visible = False
                Else
                    If 0 <> (MainTool.UpdateFlags And MENUTOOL_VISIBLEATSTARTUP) Then
                        MainTool.Visible = True
                        ToolItem.Visible = True
                    Else
                        If v_blnIgnoreMacros Then
                            ' Macro tools are only hidden at startup. Ency open, they are left as is.
                            If Not IsMacroTool(MainTool.toolID) Then
#If TOOLDEBUGGING Then
                                LogMessageTools "SetMenuToolStateAsStartup - hiding tool - " & MainTool.name        'DEV_STRING
#End If
                                MainTool.Visible = False
                                ToolItem.Visible = False
                            End If
                        Else
#If TOOLDEBUGGING Then
                            LogMessageTools "SetMenuToolStateAsStartup - hiding tool - " & MainTool.name        'DEV_STRING
#End If
                            If IsMacroTool(MainTool.toolID) Then
                                MainTool.Category = SA_VB_EmptyString        ' Ensure the macro item is not in the customize list - until it is loaded
                            End If

                            MainTool.Visible = False
                            ToolItem.Visible = False
                        End If
                    End If
                End If
            Next
        End If
    Next
End Sub

Public Sub SetToolSeparator(ByRef r_objTool As SAToolbarTool, ByVal v_blnHasSeparator As Boolean)
    If v_blnHasSeparator Then
        r_objTool.UpdateFlags = r_objTool.UpdateFlags Or MENUTOOL_SEPARATOR
    Else
        r_objTool.UpdateFlags = r_objTool.UpdateFlags And (Not MENUTOOL_SEPARATOR)
    End If
End Sub

'' TODO TOOLBAR Is this still needed?
Private Sub CustomizeSeparators()
    Dim objBand As SAToolbarBand
    Dim objTool As SAToolbarTool
    Dim lngIndex As Long
    Dim lngCount As Long
    Dim objSeparatorTool As SAToolbarTool

    On Error Resume Next
    Call fMainForm.ATB.Tools.Add(SYSMENU_SEPARATORID, SYSMENU_SEPARATORNAME)
    Set objSeparatorTool = fMainForm.ATB.Tools(SYSMENU_SEPARATORNAME)
    On Error GoTo 0

    If Not objSeparatorTool Is Nothing Then
        objSeparatorTool.Caption = SAXRes.GetLocalString(IDS_sa2001tbsubsbas_____separator)
        objSeparatorTool.Category = SAXRes.GetLocalString(IDS_sa2001tbsubsbas_____special)
        '' TODO TOOLBAR BMP        objSeparatorTool.SetPicture 0, SALoadResPicture(1000 + SYSMENU_SEPARATORID, 0), &HC0C0C0
        objSeparatorTool.Style = SATB_ST_Standard
        objSeparatorTool.Visible = True
        For Each objBand In fMainForm.ATB.Bands
            lngIndex = 0
            lngCount = objBand.Tools.Count
            While lngIndex < lngCount
                Set objTool = objBand.Tools(lngIndex)

                If objTool.Visible And objTool.BeginGroup Then
                    objTool.BeginGroup = False
                    objBand.Tools.Insert lngIndex, objSeparatorTool
                    lngIndex = lngIndex + 1
                    lngCount = lngCount + 1
                End If
                lngIndex = lngIndex + 1
            Wend
        Next
        fMainForm.ATB.RecalcLayout
    End If
End Sub

Private Sub UnCustomizeSeparators()
    Dim objBand As SAToolbarBand
    Dim objTool As SAToolbarTool
    Dim lngIndex As Long
    Dim varlngIndex As Variant
    Dim lngCount As Long
    Dim blnFound As Boolean
    Dim lngLeftIndex As Long
    Dim colBands As Collection
    Dim objColBand As SAToolbarBand
    Dim colDockLines As Collection

    On Error GoTo ErrExit

    For Each objBand In fMainForm.ATB.Bands
        lngIndex = 0
        lngCount = objBand.Tools.Count
        While lngIndex < lngCount
            Set objTool = objBand.Tools(lngIndex)

            If objTool.name = SYSMENU_SEPARATORNAME Then
                objBand.Tools.Remove lngIndex

                lngCount = lngCount - 1
                If lngIndex < lngCount Then
                    Set objTool = objBand.Tools(lngIndex)
                    blnFound = False
                    While Not blnFound And Not objTool Is Nothing
                        If (objTool.name = SYSMENU_SEPARATORNAME) Or (objTool.Visible = False) Then
                            If objTool.name = SYSMENU_SEPARATORNAME Then
                                objBand.Tools.Remove lngIndex
                                lngCount = lngCount - 1
                            Else
                                lngIndex = lngIndex + 1
                            End If
                            If lngIndex < lngCount Then
                                Set objTool = objBand.Tools(lngIndex)
                            Else
                                Set objTool = Nothing
                            End If
                        Else
                            blnFound = True
                        End If
                    Wend
                    If Not objTool Is Nothing Then
                        objTool.BeginGroup = True        ' Ensure actual toolbar bands are updated - they do not get the band_open event
                        Call SetToolSeparator(objTool, True)
                    End If
                End If
            Else
                If objTool.Visible Then
                    objTool.BeginGroup = False
                    Call SetToolSeparator(objTool, False)
                End If
            End If
            lngIndex = lngIndex + 1
        Wend
    Next

    On Error Resume Next
    Call fMainForm.ATB.Tools.Remove(SYSMENU_SEPARATORNAME)
    On Error GoTo 0

ErrExit:
    fMainForm.ATB.RecalcLayout
End Sub

Private Sub CustomizeHiddenTools()
    Dim objBand As SAToolbarBand
    Dim objTool As SAToolbarTool
    Dim lngIndex As Long
    Dim lngCount As Long

    For Each objBand In fMainForm.ATB.Bands
        lngIndex = 0
        lngCount = objBand.Tools.Count
        While lngIndex < lngCount
            Set objTool = objBand.Tools(lngIndex)

            If objTool.Visible = False Then
                objTool.UpdateFlags = objTool.UpdateFlags Or MENUTOOL_HIDE
                objTool.Visible = True
            End If
            lngIndex = lngIndex + 1
        Wend
    Next
    fMainForm.ATB.RecalcLayout
End Sub

Private Sub UnCustomizeHiddenTools()
    Dim objBand As SAToolbarBand
    Dim objTool As SAToolbarTool
    Dim lngIndex As Long
    Dim lngCount As Long

    For Each objBand In fMainForm.ATB.Bands
        lngIndex = 0
        lngCount = objBand.Tools.Count
        While lngIndex < lngCount
            Set objTool = objBand.Tools(lngIndex)

            If 0 <> (objTool.UpdateFlags And MENUTOOL_HIDE) Then
                objTool.UpdateFlags = objTool.UpdateFlags And (Not MENUTOOL_HIDE)
                objTool.Visible = False
            End If
            lngIndex = lngIndex + 1
        Wend
    Next
    fMainForm.ATB.RecalcLayout
End Sub

Public Sub CalculateSeparators(ByRef r_objBand As SAToolbarBand)
    Dim objTool As SAToolbarTool
    Dim lngIndex As Long

    On Error GoTo ErrExit
    bInhibitMenuTimer = True
    For lngIndex = 0 To r_objBand.Tools.Count - 1
        Set objTool = r_objBand.Tools(lngIndex)
        If objTool.Visible = True Then
            If 0 <> (objTool.UpdateFlags And MENUTOOL_SEPARATOR) Then
                objTool.BeginGroup = True
            Else
                objTool.BeginGroup = False
            End If
        Else
            objTool.BeginGroup = False
        End If
    Next
ErrExit:
    bInhibitMenuTimer = False
End Sub

Public Function CalculateEnabledStatesForBandOpen(ByRef r_objBand As SAToolbarBand, Optional v_blnIsSubCall = False) As Boolean
    Dim objTool As SAToolbarTool
    Dim objSubBand As SAToolbarBand
    Dim objRootTool As SAToolbarTool
    Dim lngIndex As Long

    On Error GoTo ErrExit
    If Not v_blnIsSubCall Then
        bInhibitMenuTimer = True
    End If
    For lngIndex = 0 To r_objBand.Tools.Count - 1
        Set objTool = r_objBand.Tools(lngIndex)
        If Not objTool.SubBand Is Nothing Then
            On Error Resume Next
            Set objSubBand = Nothing
            Set objSubBand = objTool.SubBand
            On Error GoTo ErrExit

            If Not objSubBand Is Nothing Then
                ' This is a popup with a subband
                If CalculateEnabledStatesForBandOpen(objSubBand, True) Then
                    If Not v_blnIsSubCall Then
                        EnableMenuToolImmediate objTool, True
                    Else
                        CalculateEnabledStatesForBandOpen = True
                        Exit For
                    End If
                Else
                    If Not v_blnIsSubCall Then
                        EnableMenuToolImmediate objTool, False
                    End If
                End If
            Else
                If Not v_blnIsSubCall Then
                    EnableMenuToolImmediate objTool, False
                End If
            End If
        Else
            EnableBasedOnNewBrowser objTool
            If v_blnIsSubCall Then
                On Error Resume Next
                Set objRootTool = Nothing
                Set objRootTool = fMainForm.ATB.Tools(objTool.name)
                On Error GoTo 0
                If Not objRootTool Is Nothing Then
                    If objRootTool.Visible = True And objRootTool.Enabled = True Then
                        CalculateEnabledStatesForBandOpen = True
                        Exit For
                    End If
                End If
            End If
        End If
    Next
ErrExit:
    If Not v_blnIsSubCall Then
        bInhibitMenuTimer = False
    End If
End Function

Public Function CheckMenuTool(abTool As SAToolbarTool, bCheck As Boolean) As Boolean
    Dim lFlags As Long
    Dim strPermID As String

    If abTool Is Nothing Then Exit Function

    abTool.UpdateFlags = abTool.UpdateFlags And (Not MENUTOOL_CHECKMASK)

    If bCheck Then
        If IsMacroTool(abTool.toolID) Then
            If Left$(abTool.name, Len(MACROPOPUPPREFIX)) = MACROPOPUPPREFIX Then
                strPermID = Mid$(abTool.name, Len(MACROPOPUPPREFIX) + 1)
            Else
                strPermID = Mid$(abTool.name, Len(MACROPREFIX) + 1)
            End If
        Else
            strPermID = abTool.toolID
        End If
        ' 10000=Run Macro, 10001=Macro Projects,10002=Macro Security,10003=VBA Editor
        If (CmdLineNoVBA Or Not fMainForm.bVBAPresent) And (strPermID = "10000" Or strPermID = "10002" Or strPermID = "10003") Then
            lFlags = 0
        Else
            GetPermissionState PER_MENU, strPermID, lFlags, abTool
        End If
        'LogMessage "enable: perm state for " & abTool.name & " is " & Format(lFlags)
        If Not ((0 = (lFlags And PERFLAG_VISIBLE)) Or (0 = (lFlags And PERFLAG_ENABLED))) Then
            ' Not marked as hidden or disabled by permissions so allow enabling
            abTool.UpdateFlags = abTool.UpdateFlags Or MENUTOOL_CHECK
#If TOOLDEBUGGING Then
            LogMessageTools "CheckMenuTool - Checking menu item - " & abTool.name        'DEV_STRING
#End If
            CheckMenuTool = True
        Else
#If TOOLDEBUGGING Then
            LogMessageTools "CheckMenuTool - Couldn't menu item as it is not visible/enabled - " & abTool.name        'DEV_STRING
#End If
            CheckMenuTool = False
        End If
    Else
        abTool.UpdateFlags = abTool.UpdateFlags Or MENUTOOL_UNCHECK
#If TOOLDEBUGGING Then
        LogMessageTools "CheckMenuTool - Unchecking menu item - " & abTool.name        'DEV_STRING
#End If
        CheckMenuTool = True
    End If
    bMenusChanged = True        ' flag for timer to activate
End Function

' EnableMenuToolImmediate - SHOULD NOT BE USED unless it is necessary
' All normal menu processing is done in the menu timer, so use EnableMenuTool
' This is required by BandOpen at present
Public Function EnableMenuToolImmediate(abTool As SAToolbarTool, bEnable As Boolean) As Boolean
    Dim objRootTool As SAToolbarTool
    On Error Resume Next
    Set objRootTool = Nothing
    Set objRootTool = fMainForm.ATB.Tools(abTool.name)
    On Error GoTo 0
    If Not objRootTool Is Nothing Then
        objRootTool.Enabled = EnableMenuTool(abTool, bEnable)        ' Checks permission states
    End If
End Function

Public Function EnableMenuTool(abTool As SAToolbarTool, bEnable As Boolean) As Boolean
    Dim lFlags As Long
    Dim strPermID As String
    Dim lToolID As Long

    If abTool Is Nothing Then Exit Function
    
    lToolID = abTool.toolID

    abTool.UpdateFlags = abTool.UpdateFlags And (Not MENUTOOL_ENABLEMASK)

    EnableMenuTool = bEnable
    If bEnable Then
        If IsMacroTool(abTool.toolID) Then
            If Left$(abTool.name, Len(MACROPOPUPPREFIX)) = MACROPOPUPPREFIX Then
                strPermID = Mid$(abTool.name, Len(MACROPOPUPPREFIX) + 1)
            Else
                strPermID = Mid$(abTool.name, Len(MACROPREFIX) + 1)
            End If
        Else
            strPermID = abTool.toolID
        End If
        ' 10000=Run Macro, 10001=Macro Projects,10002=Macro Security,10003=VBA Editor
        If (CmdLineNoVBA Or Not fMainForm.bVBAPresent) And (strPermID = "10000" Or strPermID = "10002" Or strPermID = "10003") Then
            lFlags = 0
        Else
            GetPermissionState PER_MENU, strPermID, lFlags, abTool
        End If
        'LogMessage "enable: perm state for " & abTool.name & " is " & Format(lFlags)
        If Not ((0 = (lFlags And PERFLAG_VISIBLE)) Or (0 = (lFlags And PERFLAG_ENABLED))) Then
            ' Not marked as hidden or disabled by permissions so allow enabling
            abTool.UpdateFlags = abTool.UpdateFlags Or MENUTOOL_ENABLE
#If TOOLDEBUGGING Then
            LogMessageTools "EnableMenuTool - Enabling menu item - " & abTool.name        'DEV_STRING
#End If
        Else
            abTool.UpdateFlags = abTool.UpdateFlags Or MENUTOOL_DISABLE        ' Ensure it is disabled
#If TOOLDEBUGGING Then
            LogMessageTools "EnableMenuTool - Disabling menu item - " & abTool.name        'DEV_STRING
#End If
            If 0 = (lFlags And PERFLAG_VISIBLE) Then
                abTool.UpdateFlags = abTool.UpdateFlags Or MENUTOOL_HIDE        ' Ensure it is hidden
#If TOOLDEBUGGING Then
                LogMessageTools "EnableMenuTool - Hiding menu item - " & abTool.name        'DEV_STRING
#End If
            End If
            EnableMenuTool = False
        End If
    Else
        abTool.UpdateFlags = abTool.UpdateFlags Or MENUTOOL_DISABLE
#If TOOLDEBUGGING Then
        LogMessageTools "EnableMenuTool - Disabling menu item - " & abTool.name        'DEV_STRING
#End If
    End If
    bMenusChanged = True        ' flag for timer to activate
End Function

Public Sub ShowMenuTool(ByRef ATB As SAToolbar, ToolOrName As Variant, bShow As Boolean)
    Dim lFlags As Long
    Dim strPermID As String
    Dim abTool As SAToolbarTool
    Dim lToolID As Long

    If TypeOf ToolOrName Is SAToolbarTool Then
        Set abTool = ToolOrName
    Else
        On Error Resume Next
        Set abTool = ATB.Tools(ToolOrName)
        On Error GoTo 0
        If abTool Is Nothing Then Exit Sub
    End If

    lToolID = abTool.toolID

    abTool.UpdateFlags = abTool.UpdateFlags And (Not MENUTOOL_VISIBLEMASK)


    '' Must always enforce the update, since other items in the menu may not have
    '' taken the effect.
    ''     If abTool.Visible <> bShow Then
    If bShow Then
        If IsMacroTool(abTool.toolID) Then
            If Left$(abTool.name, Len(MACROPOPUPPREFIX)) = MACROPOPUPPREFIX Then
                strPermID = Mid$(abTool.name, Len(MACROPOPUPPREFIX) + 1)
            Else
                strPermID = Mid$(abTool.name, Len(MACROPREFIX) + 1)
            End If
        Else
            strPermID = abTool.toolID
        End If
        GetPermissionState PER_MENU, strPermID, lFlags, abTool
        'LogMessage "perm state for " & abTool.name & " is " & Format(lFlags)
        If Not (0 = (lFlags And PERFLAG_VISIBLE)) Then
            ' Not marked as hidden by permissions so allow showing
            abTool.UpdateFlags = abTool.UpdateFlags Or MENUTOOL_SHOW
#If TOOLDEBUGGING Then
            LogMessageTools "ShowMenuTool - asked to show tool - " & abTool.name        'DEV_STRING
#End If
        End If
    Else
        abTool.UpdateFlags = abTool.UpdateFlags Or MENUTOOL_HIDE
#If TOOLDEBUGGING Then
        LogMessageTools "ShowMenuTool - asked to hide tool - " & abTool.name        'DEV_STRING
#End If
    End If
    bMenusChanged = True        ' flag for timer to activate
    ''    End If
End Sub

Public Function FindMenuBand(theATB As SAToolbar, BandName As String) As Long
' Given an toolbar, this searches through all of the menu/popup bands, for a band with the given caption.
' If a match is found the index is returned, otherwise -1 is returned
    Dim bandPos As Long
    Dim bFound As Boolean

    bandPos = 0
    bFound = False

    With theATB
        ' With the toolbars

        ' Find the menu, the item is in
        While Not bFound And bandPos < .Bands.Count        ' while not found and still bands to search
            If .Bands.Item(bandPos).BandName = BandName And _
               ((.Bands.Item(bandPos).TypeX = SATB_BT_MENU) Or _
                (.Bands.Item(bandPos).TypeX = SATB_BT_POPUP)) Then        ' If found matching caption in menu
                bFound = True
            Else        ' Otherwise continue search
                bandPos = bandPos + 1
            End If
        Wend
    End With

    If Not bFound Then bandPos = -1        ' Not found

    FindMenuBand = bandPos
End Function

Public Function FindToolInBand(theATB As SAToolbar, bandIndex As Long, toolCaption As String) As String
' Given an toolbar, this searches through the band of 'bandindex' (not recursively) for the tool caption.
' If a match is found, then the tool.name is returned, otherwise "" is returned.
    Dim toolPos As Long
    Dim bFound As Boolean

    On Error GoTo 0

    FindToolInBand = SA_VB_EmptyString        ' Assume not found

    With theATB
        ' With the toolbars

        ' Find the item in the menus
        If toolCaption <> SA_VB_EmptyString Then        ' If we are looking for a menu item
            bFound = False
            toolPos = 0

            While Not bFound And toolPos < .Bands.Item(bandIndex).Tools.Count        ' while not found and still tools to search
                If .Bands.Item(bandIndex).Tools.Item(toolPos).Caption = toolCaption Then        ' if found matching tool
                    bFound = True
                Else
                    toolPos = toolPos + 1        ' Otherwise continue search
                End If
            Wend

            If bFound Then        ' Store the item ID
                FindToolInBand = .Bands.Item(bandIndex).Tools.Item(toolPos).name
            End If
        End If
    End With
End Function

Public Function FindToolInTools(theATB As SAToolbar, toolCaption As String) As String
' Given a toolbar, this searches through the tools collection for the tool caption.
' If a match is found, then the tool.name is returned, otherwise "" is returned.
    Dim toolPos As Long
    Dim bFound As Boolean

    On Error GoTo 0

    FindToolInTools = SA_VB_EmptyString        ' Assume not found

    With theATB
        ' With the toolbars

        ' Find the item in the menus
        If toolCaption <> SA_VB_EmptyString Then        ' If we are looking for a menu item
            bFound = False
            toolPos = 0

            While Not bFound And toolPos < .Tools.Count        ' while not found and still tools to search
                If .Tools.Item(toolPos).Caption = toolCaption Then        ' if found matching tool
                    bFound = True
                Else
                    toolPos = toolPos + 1        ' Otherwise continue search
                End If
            Wend

            If bFound Then        ' Store the item ID
                FindToolInTools = .Tools.Item(toolPos).name
            End If
        End If
    End With
End Function

Public Function GetMenuName(ByVal hWnd As Long, ByVal lPos As Long) As String

' This function accepts a menu's handle and a menu item's position, and returns its text string

    Dim sMenuName As String
    Dim lLength As Long

    ' Prepare the string for use with API
    sMenuName = String(255, vbNullChar)

    ' This API returns the text displayed by a menu (which includes the item's shortcut key)
    lLength = GetMenuString(hWnd, lPos, sMenuName, 254, MF_BYPOSITION)
    GetMenuName = Left$(sMenuName, lLength)

End Function

Public Function CleanMenuID(ByVal sDirty As String) As String

' This function accepts a string containing a Tool's ID, removes any of the characters below,
' and returns the new string

    Dim sChr As String
    Dim i As Long

    For i = 0 To 8

        Select Case i
            Case 0
                sChr = Space(1)
            Case 1
                sChr = "&"        'DEV_STRING
            Case 2
                sChr = "..."        'DEV_STRING
            Case 3
                sChr = "("        'DEV_STRING
            Case 4
                sChr = ")"        'DEV_STRING
            Case 5
                sChr = "[G'"        'DEV_STRING - Special case for 000 locale strings
            Case 6
                sChr = "Ii|]"        'DEV_STRING - Special case for 000 locale strings
            Case 7
                sChr = "["        'DEV_STRING
            Case 8
                sChr = "]"        'DEV_STRING
        End Select

        sDirty = Filter(sDirty, sChr)

    Next i

    CleanMenuID = sDirty

End Function

Public Function CleanMenuPopup(ByVal sDirty As String) As String

' This function accepts a string containing a Tool's ID, removes any of the characters below,
' and returns the new string

    Dim sChr As String
    Dim i As Long

    For i = 0 To 2

        Select Case i
            Case 0
                sChr = "&"        'DEV_STRING
            Case 1
                sChr = "[G'"        'DEV_STRING - Special case for 000 locale strings
            Case 2
                sChr = "Ii|]"        'DEV_STRING - Special case for 000 locale strings
        End Select

        sDirty = Filter(sDirty, sChr)

    Next i

    CleanMenuPopup = sDirty

End Function

Private Function Filter(ByVal sParse As String, ByVal sDirtyChr As String) As String

' This function accepts a string and a character to remove from that string,
' and returns the new string, which will not contain the character

    Dim lDirty As Long
    Dim sLeft As String
    Dim sRight As String

    lDirty = InStr(sParse, sDirtyChr)

    Do While lDirty

        sParse = Left$(sParse, lDirty - 1) & Right$(sParse, Len(sParse) - lDirty - Len(sDirtyChr) + 1)
        lDirty = InStr(sParse, sDirtyChr)

    Loop

    Filter = sParse

End Function

Public Function GetIndex(bTools As SAToolbarTools, Id As String) As Long
' given an ID find out the index.
    Dim myTool As SAToolbarTool
    Dim i As Long
    For i = 0 To bTools.Count - 1
        Set myTool = bTools.Item(i)
        If myTool.name = Id Then
            GetIndex = i
            Exit Function
        End If
    Next i
    GetIndex = -1        ' not found so use -1
End Function

Public Function GetIndexFromToolID(bTools As SAToolbarTools, Id As Long) As Long
' given a tool ID find out the index.
    Dim myTool As SAToolbarTool
    Dim i As Long
    For i = 0 To bTools.Count - 1
        Set myTool = bTools.Item(i)
        If myTool.toolID = Id Then
            GetIndexFromToolID = i
            Exit Function
        End If
    Next i
    GetIndexFromToolID = -1        ' not found so use -1
End Function

Public Function ToolInATBCollection(abTools As SAToolbarTools, ToolName As String) As Boolean
    Dim i As Long
    Dim abTool As SAToolbarTool
    Set abTool = abTools.Item(ToolName)
    If Not abTool Is Nothing Then
        ToolInATBCollection = True
        Exit Function
    End If
End Function

Public Function ToolInMasterCollection(ToolName As String, Optional ByRef r_objToolRet As SAToolbarTool) As Boolean
    Dim i As Long
    Dim abTool As SAToolbarTool
    Set abTool = fMainForm.ATB.Tools(ToolName)
    If Not abTool Is Nothing Then
        ToolInMasterCollection = True
        If Not IsMissing(r_objToolRet) Then
            Set r_objToolRet = abTool
            Exit Function
        End If
    End If
End Function

Public Function BandInATBCollection(abBands As SAToolbarBands, BandName As String) As Boolean
    Dim i As Long
    Dim abBand As SAToolbarBand
    For i = 0 To abBands.Count - 1
        Set abBand = abBands(i)
        If abBand.BandName = BandName Then
            BandInATBCollection = True
            Exit Function
        End If
    Next i
    BandInATBCollection = False
End Function


Public Function DestroyToolItemByToolID(ToolsCol As SAToolbarTools, theID As Long) As Long
    On Error GoTo ErrExit

    DestroyToolItemByToolID = 0        ' Assume success
    fMainForm.SSAtbUpdating = True
    ToolsCol.Remove GetIndexFromToolID(ToolsCol, theID)
    fMainForm.SSAtbUpdating = False
    Exit Function
ErrExit:
    DestroyToolItemByToolID = -1        ' Failure
    LogMessage "Error removing menu ID by Tool ID - " + Format(theID)        'DEV_STRING
End Function

Public Function IsSpecialTool(ByVal v_lngToolID As Long) As Boolean
    IsSpecialTool = True
    Select Case v_lngToolID
        Case -1        ' Version main version number
        Case 0        ' Separator
        Case 60001        ' ??? Toolbar intermediate version
        Case 35000 To 35002        ' Codejock specific ids
        Case Else
            IsSpecialTool = False
    End Select
End Function

Public Function IsColorTool(ByRef r_objTool As SAToolbarTool) As Boolean
    IsColorTool = IsColorToolName(r_objTool.name)
End Function

Public Function IsColorToolName(ByVal v_strToolName As String) As Boolean
    If Left(v_strToolName, Len(COLORPREFIX)) = COLORPREFIX Then
        IsColorToolName = True
    End If
End Function

Public Function IsDrawingTool(idNum As Long) As Boolean
    IsDrawingTool = False        ' assume false
    If idNum = 299 Then
        IsDrawingTool = True
    ElseIf idNum >= DRAWSYMLOW And idNum < DRAWSYMHIGH Then
        IsDrawingTool = True
    ElseIf idNum >= STEREODRAWSYMLOW And idNum < STEREODRAWSYMHIGH Then
        IsDrawingTool = True
    ElseIf idNum >= DRAWTOOLBARSUBIDSTART And idNum < DRAWTOOLBARSUBIDEND Then
        IsDrawingTool = True
    End If
End Function

Public Function GetDrawingStereoTypeBand(ByVal v_strID As String) As SAToolbarBand
    Dim lngID As Long
    Dim strId As String

    On Error Resume Next
    lngID = dicStereoDrawTools(v_strID)        ' If this is a stereotype we will get a parent band id
    On Error GoTo 0

    If lngID <> 0 Then
        strId = "TB_" & GetActiveDiagramType() & GetUserMode() & "TB_" & CStr(lngID)
        On Error Resume Next
        Set GetDrawingStereoTypeBand = fMainForm.ATB.Bands(strId)
        On Error GoTo 0
    End If
End Function

Public Function IsMacroTool(idNum As Long) As Boolean
    IsMacroTool = False        ' assume false
    If idNum >= NEXTINTERNALMACROIDSTART And idNum <= NEXTINTERNALMACROIDEND Then
        IsMacroTool = True
    End If
End Function

Public Function IsExtensionTool(idNum As Long) As Boolean
    IsExtensionTool = False
    On Error Resume Next
    IsExtensionTool = fMainForm.ATB.Tools(idNum).IsExtension
End Function
''''''
''''''Public Function IsStereoDrawingTool(idNum As Long) As Boolean
''''''    IsStereoDrawingTool = False ' assume false
''''''    If idNum >= STEREODRAWSYMLOW And idNum < STEREODRAWSYMHIGH Then
''''''        IsStereoDrawingTool = True
''''''    End If
''''''    If CmdLineTestMode Then
''''''        If idNum = 61 + DRAWSYMLOW Or idNum = 60 + DRAWSYMLOW _
 ''''''        Or idNum = 70 + DRAWSYMLOW Or idNum = 66 + DRAWSYMLOW _
 ''''''        Or idNum = 112 + DRAWSYMLOW Or idNum = 113 + DRAWSYMLOW _
 ''''''        Or idNum = 114 + DRAWSYMLOW _
 ''''''        Then
''''''            IsStereoDrawingTool = True
''''''        End If
''''''    End If
''''''End Function

Public Function IsGeneratedToolID(ByVal idNum As Long) As Boolean
    IsGeneratedToolID = False        ' assume false
    If idNum > MAXNONINTERNALTOOLID Then
        IsGeneratedToolID = True
    End If
End Function

Public Function IsContextMenu(ByVal v_strBandName As String) As Boolean
    If v_strBandName = "id_SYMCONTEXT" Or v_strBandName = "id_DGMCONTEXT" Then
        IsContextMenu = True
    End If
End Function

Sub ClearSymbolStyleBar(barMain As SAToolbar)
    On Error Resume Next

    barMain.Tools(TOOL_FONTNAME).Text = SA_VB_EmptyString
    barMain.Tools(TOOL_FONTSIZE).Text = SA_VB_EmptyString
    barMain.Tools(TOOL_FONTBOLD).Checked = False
    barMain.Tools(TOOL_FONTITALIC).Checked = False
    barMain.Tools(TOOL_FONTUNDERLINE).Checked = False
    barMain.Tools(TOOL_TEXTCENTER).Checked = False
    barMain.Tools(TOOL_TEXTLEFT).Checked = False
    barMain.Tools(TOOL_TEXTRIGHT).Checked = False

    On Error GoTo 0
End Sub

' Rewrites ini settings using SA as the sole source of the information
Private Sub WriteSearchIniSettings(ByRef r_objTool As SAToolbarTool)
End Sub

Sub UpdateSymbolStyleBarFonts(barMain As SAToolbar)
End Sub

Sub UpdateSymbolStyleBar(barMain As SAToolbar)
End Sub

Public Function IsMatrixMenu(barMain As SAToolbar, CurTool As SAToolbarTool) As Boolean
    If val(Mid(CurTool.name, 7)) >= MATRIX_MENU_FIRST And val(Mid(CurTool.name, 7)) <= MATRIX_MENU_LAST Then
        IsMatrixMenu = True
    Else
        IsMatrixMenu = False
    End If
End Function

Public Sub EnableOtherTools(ByRef r_objBarMain As SAToolbar)
    EnableMenuTool r_objBarMain.Tools(TOOL_TOOLBARRESET), True
    EnableMenuTool r_objBarMain.Tools(TOOL_TOOLBARCUSTOMIZE), True
End Sub

Public Sub ShowBidiTools(ByRef r_objBarMain As SAToolbar)
    ShowMenuTool fMainForm.ATB, r_objBarMain.Tools(TOOL_TEXT_DIRECTION_LTR), True
    ShowMenuTool fMainForm.ATB, r_objBarMain.Tools(TOOL_TEXT_DIRECTION_CONTEXTUAL), True
    ShowMenuTool fMainForm.ATB, r_objBarMain.Tools(TOOL_TEXT_DIRECTION_RTL), True
End Sub

Public Sub EnableMatrixTools(ByRef r_objBarMain As SAToolbar, ByVal v_blnMatrixVisible As Boolean)
    Dim lngID As Long
    Dim objTool As SAToolbarTool

#If TOOLDEBUGGING Then
    LogMessageTools "EnableMatrixTools - " & v_blnMatrixVisible        'DEV_STRING
#End If
    If r_objBarMain.Tools("id_Matrix").Visible <> v_blnMatrixVisible Then        'DEV_STRING
        ' Tested Matrix menu tool. If this is not the same as the request
        ' do the enable/disable - otherwise assume it has been done
        ' This ensure options which have been disabled separately are not
        ' affected e.g. Infer (which is disabled for non MDM matrices)
        ' Disable/Enable the matrix bar and tools
        For lngID = MATRIX_MENU_FIRST To MATRIX_MENU_LAST
            On Error Resume Next
            Set objTool = r_objBarMain.Tools("SAIDM_" & CStr(lngID))        'DEV_STRING
            On Error GoTo 0
            If Not objTool Is Nothing Then
#If TOOLDEBUGGING Then
                LogMessageTools "EnableMatrixTools - Enabling item - " & objTool.Caption        'DEV_STRING
#End If
                EnableMenuTool objTool, v_blnMatrixVisible
            End If
        Next

        ' Update the matrix menu state (ensure hidden if no matrix active)
        EnableMenuTool r_objBarMain.Tools("id_Matrix"), v_blnMatrixVisible        'DEV_STRING
        r_objBarMain.Tools("id_Matrix").Visible = v_blnMatrixVisible        'DEV_STRING
        r_objBarMain.RecalcLayout
    End If
End Sub

Public Sub SetupMatrixMenu(barMain As SAToolbar)
End Sub

Public Sub ProcessMatrixMenu(barMain As SAToolbar, CurTool As SAToolbarTool)
End Sub

Public Sub EnableTAUTools(ByRef r_objBarMain As SAToolbar, ByVal v_blnTAUVisible As Boolean)
End Sub

Public Function IsTAUMenu(barMain As SAToolbar, CurTool As SAToolbarTool) As Boolean
End Function

Public Sub ProcessTAUMenu(barMain As SAToolbar, CurTool As SAToolbarTool)
End Sub

'' We don't show the properties of the symbol we are about to draw on this bar
''
''Sub ProcessDrawToolSelectionChange(barMain As SAToolBar, CurTool As SAToolBarTool)
''    Dim sXMLStyle As String
''    Dim lType As Long
''
''    MsgBox CurTool.Name
''    If Left(CurTool.Name, 6) = "SAIDM_" Then 'DEV_STRING
''        ' A drawing tool has been selected
''        On Error Resume Next
''        lType = CLng(Mid$(CurTool.Name, Len("SAIDM_") + 1)) 'DEV_STRING
''        On Error GoTo 0
''    ElseIf Left(CurTool.Name, 3) = "TB_" Then 'DEV_STRING
''        ' A drawing tool with stereotypes has been selected
''        On Error Resume Next
''        lType = CLng(Mid$(CurTool.Name, Len("TB_") + 1)) 'DEV_STRING
''        On Error GoTo 0
''    End If
''
''    If lType > DRAWSYMLOW And lType < STEREODRAWSYMLOW Then
''        lType = lType - DRAWSYMLOW
''    ElseIf lType = 299 Then
''        ' NOTE: We don't do stereotypes or the select tool
''        Exit Sub
''    End If
''
''    If 0 = SADesign.SAObjGetSymbolTypeStyle(lType, sXMLStyle) Then
''        ' Got the current symbol tool's style
''        Call UpdateSymbolStyleBar(barMain, sXMLStyle)
''    End If
''End Sub

Function IsDrawingPen(barMain As SAToolbar, CurTool As SAToolbarTool) As Boolean
    If val(Mid(CurTool.name, 7)) >= TOOL_PEN_FIRST And val(Mid(CurTool.name, 7)) <= TOOL_PEN_LAST _
    Or val(Mid(CurTool.name, 7)) = TOOL_PEN_10 Then
        IsDrawingPen = True
    Else
        IsDrawingPen = False
    End If
End Function

Sub SetPenStyle()
End Sub

Sub ProcessPenStyle(barMain As SAToolbar, CurTool As SAToolbarTool)
End Sub

Private Function ProcessNamedFontStyle_GetStorageValue(barMain As SAToolbar) As String
End Function

Private Sub ProcessNamedFontStyle_UpdateBarFromStorageValue(barMain As SAToolbar, ByVal sVal As String)
End Sub

Public Function ProcessNamedFontStyle_GetStorageValue2(ByVal v_sStyle As String) As String
End Function

' Flag integer enums map to Long type
Private Function ProcessNamedFontStyle_GetStorageValue3(ByVal v_strFName As String, ByVal v_iFHeight As Integer, ByVal v_lFlags As Long, ByVal v_lTextDrawFlags As SA_Text_Flags, ByVal v_bAuto As Boolean, ByVal v_lColor As Long, lTextDirFlags As SA_TextDir_Flags) As String
End Function

Public Sub ProcessNamedFontStyle_UpdateSymFromStorageValue(ByRef r_Sym As Object, ByVal sVal As String, ByVal v_lFor As Long)
End Sub

Private Function ProcessNamedFontStyle_GetStyleFromStorageValue(barMain As SAToolbar, ByVal v_sVal As String) As String
End Function

Private Sub ProcessNamedFontStyle_Record(barMain As SAToolbar, CurTool As SAToolbarTool, ByVal sStyle As String)
End Sub

Private Sub ProcessNamedFontStyle_Record2(barMain As SAToolbar, CurTool As SAToolbarTool, ByVal sStyle As String, ByVal sVal As String)
End Sub

' CurTool is initially the selected command, it is then replaced with the named style dropllist tool
Public Sub ProcessNamedFontStyle(barMain As SAToolbar, CurTool As SAToolbarTool)
End Sub

Public Sub ProcessFontStyle(barMain As SAToolbar, CurTool As SAToolbarTool)
End Sub

Public Function ProcessTextStyle(barMain As SAToolbar, CurTool As SAToolbarTool)
End Function

Private Sub PaintColorStripe(pic As PictureBox, icon As IPictureDisp, iColor As Long)
    Dim X As Long, y As Long
    Dim hBrush As Long
    Dim aRect As RECT
    Dim lngBrush As Long
    Dim lngOldBrush As Long
    Dim lngPen As Long
    Dim lngOldPen As Long

    On Error Resume Next

    pic.Height = 16
    pic.Width = 16

    pic.ScaleMode = vbPixels
    pic.AutoRedraw = True
    Set pic.Picture = icon

    Call SetBkColor(pic.hDC, iColor)
    Call SetBkMode(pic.hDC, OPAQUE)

    lngPen = CreatePen(0, 1, iColor)
    lngBrush = CreateSolidBrush(iColor)
    lngOldPen = SelectObject(pic.hDC, lngPen)
    lngOldBrush = SelectObject(pic.hDC, lngBrush)

    Call Rectangle(pic.hDC, 0, 12, 16, 16)

    Call SelectObject(pic.hDC, lngOldPen)
    Call SelectObject(pic.hDC, lngOldBrush)
    DeleteObject lngPen
    DeleteObject lngBrush

    pic.Refresh
    pic.Picture = pic.Image
    pic.Refresh
End Sub

Private Sub GetColorDetails(ByVal ColorToolFullName As String, CurrentColor As Long, bCurrentAuto As Boolean, AutoColor As Long, ColorToolNameX As String, ColorToolItem As String)
    Dim Color
    Dim strColorPickerNameX As String
    Dim strPrefix As String
    Dim strColorPickerSubTool As String
    Dim arrParts As Variant
    Dim i As Integer
    On Error Resume Next

    arrParts = Split(ColorToolFullName, "_")        'DEV_STRING

    For i = 0 To UBound(arrParts)
        Select Case i
            Case 0
                strPrefix = arrParts(i) & "_"        'DEV_STRING
            Case 1
                strColorPickerNameX = arrParts(i)
            Case 2
                strColorPickerSubTool = arrParts(i)
        End Select
    Next

    ColorToolNameX = strColorPickerNameX
    ColorToolItem = strColorPickerSubTool

    If strPrefix = COLORPREFIX Then
        Select Case strColorPickerNameX
            Case TOOLX_FONTCOLOR
                AutoColor = AUTO_FONTCOLOR
            Case TOOLX_FILLCOLOR
                AutoColor = AUTO_FILLCOLOR
            Case Else        ' Pen Color
                AutoColor = AUTO_PENCOLOR
        End Select

        On Error Resume Next
        Color = ColorPickerSelection(strColorPickerNameX)
        On Error GoTo 0

        If IsEmpty(Color) Then
            Color = SAXRes.GetLocalString(IDS_sa2001tbsubsbas_____auto)
        End If

        If CStr(Color) = SAXRes.GetLocalString(IDS_sa2001tbsubsbas_____auto) Then
            bCurrentAuto = True
            CurrentColor = AutoColor
        Else
            bCurrentAuto = False
            CurrentColor = CLng(Color)
        End If
    End If
End Sub

Sub SetColorFromPicker(barMain As SAToolbar, ByVal ColorToolFullName As String)
End Sub

Function ProcessColorPicker(barMain As SAToolbar, CurTool As SAToolbarTool, Optional CommonDialog1 As CommonDialog) As Boolean
End Function

Sub UpdateColorPicker(barMain As SAToolbar, ByVal ColorToolFullName As String, ByVal bUpdate As Boolean, Optional ByVal Color As Long, Optional ByVal bAuto As Boolean)
End Sub

'''''''''''''''''''''
' EnableBand
' This does NOT disable and enable bands completely anymore.
' Instead it disables or enables the tools which are normally (default) on this band
' This allows user customisation on the band
Public Sub EnableBand(ByVal v_blnEnable As Boolean, ByVal v_strBandName As String)
    Dim tTool As SAToolbarTool
    Dim objBand As SAToolbarBand
    Dim lngIndex As Long

    On Error Resume Next

    Set objBand = fMainForm.ATB.Bands(v_strBandName)

    If Not objBand Is Nothing Then
        Select Case v_strBandName
            Case TOOL_FILLCOLOR, TOOL_FONTCOLOR, TOOL_PENCOLOR, BAND_PENS, TOOL_FONTNAMEDSTYLE_MANAGE
                ' These bands are NOT customizable
                For lngIndex = 0 To objBand.Tools.Count - 1
                    Set tTool = objBand.Tools(lngIndex)
#If TOOLDEBUGGING Then
                    LogMessageTools "EnableBand - bEnable=" & v_blnEnable & " - " & tTool.name        'DEV_STRING
#End If
                    EnableMenuTool fMainForm.ATB.Tools(tTool.name), v_blnEnable
                Next
            Case BAND_OSLCCONTEXT
                EnableOSLCToolbar True, True

            Case BAND_SEARCHCONTEXT
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHCONTEXT), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHALL), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHDGMSSYMS), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHDGMS), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHSYMS), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHSYMSONCURRDGM), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHDEFSONCURRDGM), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHDEFNS), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHTEXT), v_blnEnable

                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHGO), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHADV), v_blnEnable
            Case BAND_SYMBOLSTYLE
                ' This band is customizable and these are the default tools on it
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10049"), v_blnEnable        'DEV_STRING
                
                ' This didn't work in ConfigureSymbolStyleBar
                If fMainForm.ATB.Tools("SAIDM_10049").Text = "" Then
                    fMainForm.ATB.Tools("SAIDM_10049").Text = SAXRes.GetLocalString(IDS_sa2001____fontstyleforall)
                End If
                
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10010"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10011"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10012"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10013"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10014"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10015"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10016"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10017"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10018"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10019"), v_blnEnable        'DEV_STRING
#If BIDI_DISABLED = False Then
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10044"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10045"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10046"), v_blnEnable        'DEV_STRING
#End If
                EnableMenuTool fMainForm.ATB.Tools(TOOL_PENSTYLE), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10021"), v_blnEnable        'DEV_STRING

                If Not v_blnEnable Then
                    ' Only disable this - it is enabled by select.c SelectOne or SelectMany
                    EnableMenuTool fMainForm.ATB.Tools("SAIDM_35"), v_blnEnable        'DEV_STRING
                End If
                EnableMenuTool fMainForm.ATB.Tools("SAIDM_10032"), v_blnEnable        'DEV_STRING
                EnableMenuTool fMainForm.ATB.Tools(TOOL_SETSTYLE), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_FONTNAMEDSTYLE), v_blnEnable
                EnableMenuTool fMainForm.ATB.Tools(TOOL_FONTNAMEDSTYLE_MANAGE), v_blnEnable

                EnableBand v_blnEnable, TOOL_FILLCOLOR
                EnableBand v_blnEnable, TOOL_FONTCOLOR
                EnableBand v_blnEnable, TOOL_PENCOLOR
                EnableBand v_blnEnable, BAND_PENS
                EnableBand v_blnEnable, TOOL_FONTNAMEDSTYLE_MANAGE
        End Select

        EnableMenuTool fMainForm.ATB.Tools(v_strBandName), v_blnEnable        ' Ensure the band tool is enabled - so the user can access the band
        bMenusChanged = True        ' flag for timer to activate
    End If

    On Error GoTo 0
End Sub

''''''''''''''''''''''''''''''''
' DisableAllToolBars
' DO NOT CALL THIS FUNCTION - except at startup, before the menus have been setup
' Otherwise you will not know which tools to re-enable afterwards (remember users customise toolbars)
Public Sub DisableAllToolBars(barMain As SAToolbar)
    Dim ABand As SAToolbarBand
    Dim tTool As SAToolbarTool
    Dim lngIndex As Long

    On Error Resume Next

    UpdateColorPicker barMain, TOOL_FILLCOLOR, True, vbWhite        ' Restore the default fill color at the startup.
    UpdateColorPicker barMain, TOOL_PENCOLOR, True, vbBlack        ' Restore the default pen color at the startup.
    UpdateColorPicker barMain, TOOL_FONTCOLOR, True, vbBlack        ' Restore the default pen color at the startup.
    ProcessPenStyle barMain, barMain.Tools(TOOL_PEN_DEFAULT)

    For Each ABand In barMain.Bands
        For lngIndex = 0 To ABand.Tools.Count - 1
            Set tTool = ABand.Tools(lngIndex)
#If TOOLDEBUGGING Then
            LogMessageTools "DisableAllToolBars - bEnable=" & False & " Band= " & ABand.BandName & " Name= " & tTool.name & " ID= " & tTool.toolID        'DEV_STRING
#End If
            EnableMenuTool barMain.Tools(tTool.name), False
        Next
    Next
    On Error GoTo 0
    bMenusChanged = True        ' flag for timer to activate
End Sub

Public Sub EnableStartUpToolBars(barMain As SAToolbar)
    EnableBand False, BAND_SYMBOLSTYLE
    EnableMatrixTools barMain, False
    EnableOtherTools barMain
End Sub

Public Sub UpdateZoomPercentage(hWnd As Long)
End Sub

Public Sub ProcessZoomPercent()
End Sub

Public Sub ConfigureDiagramBar(barMain As SAToolbar)
End Sub

Private Function IsThisSearchItemAdvanced(ByVal v_lngCBIndex As Long, ByRef r_lngIndex As Long) As Boolean
    Dim lngCount As Long

    ' CBIndex values run from 1 upwards; 0 is reserved for empty string
    For lngCount = LBound(arr_lng_AdvancedSearches) To UBound(arr_lng_AdvancedSearches)
        If arr_lng_AdvancedSearches(lngCount) = v_lngCBIndex And v_lngCBIndex > 0 Then
            IsThisSearchItemAdvanced = True
            r_lngIndex = lngCount
            Exit Function
        End If
    Next
    IsThisSearchItemAdvanced = False
End Function

Public Sub ConfigureSearchBar(barMain As SAToolbar)
    Dim objTool As SAToolbarTool
    Dim strItems() As String
    Dim lngLower As Long
    Dim lngUpper As Long
    Dim lngCount As Long
    Dim lngAdvNdx As Long


    On Error GoTo ErrOut

    Set objTool = barMain.Tools(TOOL_SEARCHTEXT)
    If Not objTool Is Nothing Then
        objTool.CancelIfFocusLost = False
        objTool.CBListClear
        'GetSearchINISettings strItems(), arr_lng_AdvancedSearches, arr_str_AdvancedSearches
        On Error Resume Next
        lngLower = LBound(strItems())
        If Err = 0 Then
            lngUpper = UBound(strItems())
            For lngCount = lngUpper To lngLower Step -1
                If Len(strItems(lngCount)) > 0 Then
                    objTool.CBListAddItemAtTop strItems(lngCount)
                End If
            Next
        Else
            Err.Clear
            On Error GoTo ErrOut
        End If
        objTool.Text = SAXRes.GetLocalString(IDS_sa2001tbsubsbas_____searchtext)
        objTool.ToolTipText = objTool.Text
    End If
    Set objTool = barMain.Tools(TOOL_SEARCHALL)
    ExecuteSearchMenuItem barMain, objTool        'This to set the initial state

StdExit:
    On Error GoTo 0
    Exit Sub
ErrOut:
    Err.Clear
    Resume StdExit
End Sub

Sub SymbolStyleBar_InitNamedStyles(barMain As SAToolbar)
End Sub

Sub SymbolStyleBar_InitFonts(barMain As SAToolbar)
End Sub

Public Sub ConfigureSymbolStyleBar(barMain As SAToolbar)
End Sub

Public Sub SetMaxSymbolSelectStyle(MaxSymbolSelects As Long)
    g_l_MAX_SYMBOL_SELECTS_STYLE = MaxSymbolSelects
End Sub

Public Sub ToolbarLanguageSetUp(barMain As SAToolbar)
'''' TODO TOOLBAR
''''    Dim RetCode As Long
''''    Dim DialogFontName As String
''''    Dim DialogFontSize As String
''''    Dim CommaPtr As Integer
''''
''''    DialogFontName = String(255, Space(1))
''''    RetCode = SADUtilsVB_ReadSettingNTS(SAXRes.GetLocalString(IDS_uloc_____systemarchitect__), "SADialogFont", "", DialogFontName, 255, "") 'DEV_STRING
''''    If RetCode = 0 Then
''''        Exit Sub
''''    End If
''''    DialogFontName = ConvertCStringToBasic(DialogFontName)
''''    CommaPtr = InStr(DialogFontName, SA_VB_Comma)
''''    If CommaPtr <> 0 Then
''''        DialogFontSize = Right(DialogFontName, Len(DialogFontName) - CommaPtr)
''''        barMain.ControlFont.Size = val(DialogFontSize)
''''        DialogFontName = Left(DialogFontName, CommaPtr - 1)
''''    End If
''''    barMain.ControlFont.Name = DialogFontName
''''    barMain.ControlFont.Charset = DEFAULT_CHARSET
End Sub

Private Function ConvertCStringToBasic(CString As String) As String
    Dim ZeroPtr As Integer

    ZeroPtr = InStr(CString, Chr(0))
    If ZeroPtr > 0 Then
        ConvertCStringToBasic = Left$(CString, ZeroPtr - 1)
    Else
        ConvertCStringToBasic = CString
    End If
End Function

Public Function SetupBrowserPopup(ByRef r_objBrowser As Object, ByRef r_blnInhibitBrowserPopup As Boolean, ByRef r_mnuMenu As Variant, ByRef r_mnuDOORS As Variant, ByRef r_mnuDOORSMenu As Variant) As Boolean
End Function

Public Function IsBrowserMenu(ByVal v_lngSAIDMToolID As Long) As Boolean
End Function

Public Sub ExecuteBrowserMenuItem(ByVal v_lngSAIDMToolID As Long)
End Sub

Public Sub ClearToolBarFlag(ByRef r_objTool As SAToolbarTool, ByVal v_enuMenuToolTag As MENUTOOLTAG)
    r_objTool.UpdateFlags = CLng(r_objTool.UpdateFlags) And (Not CLng(v_enuMenuToolTag))
End Sub

Public Sub QSStrings(sArray() As String, l As Integer, r As Integer)

    Dim i As Integer
    Dim j As Integer
    Dim X As String
    Dim y As String

    i = l
    j = r
    X = sArray((l + r) / 2)

    While (i <= j)
        While (sArray(i) < X And i < r)
            i = i + 1
        Wend

        While (X < sArray(j) And j > l)
            j = j - 1
        Wend

        If (i <= j) Then
            y = sArray(i)
            sArray(i) = sArray(j)
            sArray(j) = y
            i = i + 1
            j = j - 1
        End If
    Wend

    If (l < j) Then QSStrings sArray(), l, j
    If (i < r) Then QSStrings sArray(), i, r

End Sub

Public Function GetUserTBFPath() As String
    Dim strPath As String
    'strPath = SA_File_GetFolderLocation(0, SASF_SALocalAppData)
    'GetUserTBFPath = strPath & SAXRes.GetLocalString(IDS_uloc_____sausrtbf) & SAXRes.GetLocalString(IDS_uloc_____tbf)
    GetUserTBFPath = App.Path & "\" & SAXRes.GetLocalString(IDS_uloc_____sausrtbf) & SAXRes.GetLocalString(IDS_uloc_____tbf)
End Function

Public Function IsNewerVersion(ByVal v_strTBVersion As String, ByVal v_strMasterVersion As String) As Boolean
    Dim arrTLBVer As Variant
    Dim arrMastVer As Variant

    arrMastVer = Split(Mid(v_strMasterVersion, 2), "_")        'DEV_STRING
    arrTLBVer = Split(Mid(v_strTBVersion, 2), "_")        'DEV_STRING

    If CLng(arrMastVer(0)) > CLng(arrTLBVer(0)) Then
        IsNewerVersion = True
    ElseIf CLng(arrMastVer(0)) = CLng(arrTLBVer(0)) Then
        If CLng(arrMastVer(1)) > CLng(arrTLBVer(1)) Then
            IsNewerVersion = True
        ElseIf CLng(arrMastVer(1)) = CLng(arrTLBVer(1)) Then
            If CLng(arrMastVer(2)) > CLng(arrTLBVer(2)) Then
                IsNewerVersion = True
            End If
        End If
    End If
End Function

Public Sub ExecuteSAToolbarExtensionMenuItem(ByVal v_atb As SAToolbar, ByVal v_objSATBTool As SAToolbarTool)
End Sub

Public Function IsSearchMenu(ByVal v_strSAIDMToolID As String) As Boolean
    Select Case v_strSAIDMToolID
        Case TOOL_SEARCHCONTEXT, TOOL_SEARCHTEXT, TOOL_SEARCHGO, TOOL_SEARCHALL, _
             TOOL_SEARCHDGMSSYMS, TOOL_SEARCHDGMS, TOOL_SEARCHSYMS, TOOL_SEARCHSYMSONCURRDGM, TOOL_SEARCHDEFSONCURRDGM, TOOL_SEARCHDEFNS, TOOL_SEARCHADV
            IsSearchMenu = True
    End Select
End Function

Function strGetReportTitleFromWhereClause(ByVal v_strReport As String) As String
    Const STR_WHERETAG As String = "WHERE"        ' DEV_STRING
    Dim lngPos As Long
    Dim lngPos2 As Long
    Dim strTest As String
    Dim strTest2 As String
    Dim blnFound As Boolean
    Dim str As String
    Dim lngLastFound As Long

    lngLastFound = 1
    Do
        blnFound = False
        lngPos = InStr(lngLastFound, v_strReport, STR_WHERETAG)
        If lngPos > 0 Then
            strTest = Mid$(v_strReport, lngPos - 1, 1)
            strTest2 = Mid$(v_strReport, lngPos + Len(STR_WHERETAG), 1)
            If (strTest = vbCr Or strTest = vbLf Or strTest = vbTab Or strTest = Chr(32)) And _
               (strTest2 = vbTab Or strTest2 = Chr(32)) Then
                blnFound = True
                lngLastFound = lngPos + Len(STR_WHERETAG)
                If Len(str) > 0 Then
                    str = str & ", "        ' DEV_STRING
                End If
                lngPos = lngPos + Len(STR_WHERETAG)
                lngPos2 = InStr(lngPos, v_strReport, vbNewLine)
                If lngPos2 > 0 Then
                    str = str & Trim$(Mid$(v_strReport, lngPos, lngPos2 - lngPos))
                End If
            End If
        End If
    Loop Until Not blnFound

    strGetReportTitleFromWhereClause = str
End Function

Public Sub ExecuteSearchMenuItem(ByRef r_atb As SAToolbar, ByRef r_objSATBTool As SAToolbarTool)
End Sub

Public Sub ProcessSearchText(ByRef r_atb As SAToolbar, ByRef r_objSATool As SAToolbarTool)
    On Error Resume Next
    r_atb.Tools(TOOL_SEARCHTEXT).Text = r_objSATool.Text
    bMenusChanged = True
End Sub

Private Sub EnableBasedOnNewBrowser(abTool As SAToolbarTool)
End Sub

' Invoked from KeyboardMessageHook.. can use GetKeyState to check state of shift keys and such - examples in aforementioned
' Return True to cause keypress to be swallowed; not passed on to other handlers
Public Function SearchComboKeydownHandler(ByVal v_lngKey As Long, ByRef r_objSATool As SAToolbarTool) As Boolean
    Dim blnShift As Boolean
    Dim blnCtrl As Boolean
    Dim blnAlt As Boolean
    Dim lngIndex As Long
    Const VK_ALT As Long = 18
    Const VK_CAPSLOCK As Long = 20
    Const VK_STARTL As Long = 91
    Const VK_STARTR As Long = 92
    Const VK_CONTEXT As Long = 93

    blnShift = (&H8000 And GetKeyState(VK_SHIFT)) <> 0
    blnAlt = (&H8000 And GetKeyState(VK_ALT)) <> 0
    blnCtrl = (&H8000 And GetKeyState(VK_CONTROL)) <> 0

    ' Objective is to filter out all those keypresses which mean that the user isn't modifying the text data
    If blnShift And Not blnAlt And Not blnCtrl And v_lngKey = VK_TAB Then        ' Tabbing between controls
    ElseIf Not blnShift And Not blnAlt And Not blnCtrl And v_lngKey = VK_TAB Then        ' Tabbing between controls
    ElseIf v_lngKey = VK_DOWN Or v_lngKey = VK_UP Or v_lngKey = vbKeyPageUp Or v_lngKey = vbKeyPageDown Then        ' up/down
    ElseIf v_lngKey = VK_SHIFT Or v_lngKey = VK_CONTROL Or v_lngKey = VK_ALT Then
    ElseIf blnAlt Or (blnCtrl And Not (v_lngKey = VK_V Or v_lngKey = VK_X Or v_lngKey = VK_TAB Or v_lngKey = VK_SPACE)) Then
    ElseIf v_lngKey = VK_LEFT Or v_lngKey = VK_RIGHT Or v_lngKey = VK_HOME Or v_lngKey = VK_END Or v_lngKey = VK_INSERT Then
    ElseIf v_lngKey = VK_NUMLOCK Or v_lngKey = VK_ESCAPE Or v_lngKey = VK_CAPSLOCK Then
    ElseIf v_lngKey = VK_STARTL Or v_lngKey = VK_STARTR Or v_lngKey = VK_CONTEXT Or v_lngKey = VK_PAUSE Or v_lngKey = VK_RETURN Then
    ElseIf v_lngKey = VK_F1 Or v_lngKey = VK_F2 Or v_lngKey = VK_F3 Or v_lngKey = VK_F4 Or v_lngKey = VK_F5 Or v_lngKey = VK_F6 Then
    ElseIf v_lngKey = VK_F7 Or v_lngKey = VK_F8 Or v_lngKey = VK_F9 Or v_lngKey = VK_F10 Or v_lngKey = VK_F11 Or v_lngKey = VK_F12 Then
    Else
        If IsThisSearchItemAdvanced(r_objSATool.CBListIndex, lngIndex) Then
            Debug.Print v_lngKey & " ignored"
            ' Clear the text - doesn't work
            'r_objSATool.Text = ""
            'SearchComboKeydownHandler = True
            ' The control still manages to handle delete and backspace keypresses even though we do this.

            ' Can re-enable the Scope button though...
            EnableMenuTool fMainForm.ATB.Tools(TOOL_SEARCHCONTEXT), True
        Else
            Debug.Print v_lngKey
        End If
    End If
End Function

Private Function IsSAReadOnly() As Boolean

    On Error GoTo ErrorHandler
    
    IsSAReadOnly = True
    
    Exit Function
    
ErrorHandler:
    IsSAReadOnly = False
    
End Function
