VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Application"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Public Enum ActionFreezeCheckOut
    ACTION_CHECKOUT = 0
    ACTION_CHECKIN = 1
    ACTION_FREEZE = 2
    ACTION_UNFREEZE = 3
    ACTION_UNLOCK = 4
End Enum

' vbObjectError is &H80040000
Public Enum SA2001Errors
    SAERR_SA20001_ERROR_BASE = &H80040000
    SAERR_SANOTRUNNING = &H400
    SAERR_OBJECTNOTFOUND
    SAERR_SA20001_IMF_ERROR = &H1000
    SAERR_REQUIREDPROPERTYABSENT = &H2000
    SAERR_ENUMVARIANTERROR              ' error in the Hardcore classes
    SAERR_INVALIDOBJECT                 ' Encyc or handle no longer valid
    SAERR_BADDDID                       ' bad ddId
    SAERR_NOTIMPLEMENTED                ' Not implemented
    SAERR_OBJECTDOESNOTEXIST            ' Object does not exist
    SAERR_DIAGRAMNOTOPEN                ' Diagram must be opened before doing this
    SAERR_DIAGRAMOPEN                   ' Diagram already open
    SAERR_SYMBOLHASNODIAGRAM            ' Symbol's Diagram does not exist
    SAERR_DIAGRAMNOTSAME                ' Line diagram is different
    SAERR_INVALIDCLASS                  ' This is not valid for the SAClass
    SAERR_TOOMANYOBJECTS                ' Collection contains too many objects
    SAERR_INVALIDPROPERTY               ' the specified property is not valid
    SAERR_OBJECTISLOCKED                ' Failed to get object as it is locked
    SAERR_OPENEDASREADONLY              ' cannot save as object was opened read only
    SAERR_INVALIDTYPE                   ' Invalid type specified
    SAERR_INVALIDNAME                   ' Invalid name specified
    SAERR_TOOMANYARGUMENTS              ' More than 20 arguments passed to ExecuteMacroEx
    SAERR_MATRIXERROR                   ' A matrix error occured refer to the matrix error code
    SAERR_MENUTOOLNOTFOUND              ' The specified menu tool could not be found
    SAERR_UNABLETOLOCKALLITEMS          ' Not all items in the readall were locked as requested
    SAERR_OBJECTISBEINGEDITED           ' Failed to get object as it is being edited
    SAERR_TOOLNOTFOUND                  ' The specified tool was not found
    SAERR_INVALIDTOOLBAREXTENSION       ' An error was encountered parsing the extended toobar file
    SAERR_ITEMALREADYPRESENT            ' ListOf, HeteroListOf don't allow multiple references to the same item
    
    ' SAERR_UNKNOWNERROR - Must always be LAST
    SAERR_UNKNOWNERROR = &HFFFF         ' Max error number - if error is raised with a bad error number this is used
End Enum

Public Enum SYMEVENTS
    LINESYM_PREP = 5
    TEXTSYM_CREATED = 6
    NODESYM_ADDED_NAMED = 7
    LINESYM_ADDED_NAMED = 8
    LINESYM_CREATED = 9
    DELETED = 10
    DELETED_FINAL = 11
    NODESYM_CREATED = 12
    NODESYM_RESIZE_START = 13
    NODESYM_MOVE_START = 14
    LINESYM_ASSOCIATIVE_DONE = 20
    ADDCONN = 64
    BREAKCONN = 65
    TRANSFORMED = 66
    SYM_SELECTED = 256
    SYM_DESELECTED = 257
End Enum

'   The following Public Constants relate to returns from the callback lpfnCallBackShowNodeEvt
'   They must be kept in sync with those in XBrow and twllio.h
Public Enum NodeStatus
    statusDONTSHOW = 0
    statusSHOW = 1
    statusDONTCARE = 2
End Enum

Public Enum SHOWWINDOWCONSTANTS
    '/*
    ' * ShowWindow() Commands
    ' */
    SASW_HIDE = 0
    SASW_SHOWNORMAL = 1
    SASW_NORMAL = 1
    SASW_SHOWMINIMIZED = 2
    SASW_SHOWMAXIMIZED = 3
    SASW_MAXIMIZE = 3
    SASW_SHOWNOACTIVATE = 4
    SASW_SHOW = 5
    SASW_MINIMIZE = 6
    SASW_SHOWMINNOACTIVE = 7
    SASW_SHOWNA = 8
    SASW_RESTORE = 9
    SASW_SHOWDEFAULT = 10
    SASW_FORCEMINIMIZE = 11
    SASW_MAX = 11
End Enum

Private m_strExePath As String

' VBA Events
Public Event MainMenuUpdate()
Attribute MainMenuUpdate.VB_Description = "Menu handling event"
Public Event ToolsMenuUpdate()
Attribute ToolsMenuUpdate.VB_Description = "Menu handling event"
Public Event MethodMenuUpdate()
Attribute MethodMenuUpdate.VB_Description = "Menu handling event"
Public Event ReportsMenuUpdate()
Attribute ReportsMenuUpdate.VB_Description = "Menu handling event"
Public Event EncyOpen()
Attribute EncyOpen.VB_Description = "Event triggered when an ency is opened"
Public Event EncyAboutToChange(ByRef r_lngCancel As Long)
Public Event EncyClose()
Attribute EncyClose.VB_Description = "Event triggered when Encylopedia is closed."
Public Event DiagramSave()
Attribute DiagramSave.VB_Description = "SA2001 event"
Public Event SymbolEvent(ByVal hDgm As Long, ByVal hSym As Long, ByVal hSymOther As Long, ByVal SymEvent As SYMEVENTS, ByVal lData As Long)
Attribute SymbolEvent.VB_Description = "SA2001 symbol event"
Public Event DiagramOpen(ByVal hDgm As Long)
Attribute DiagramOpen.VB_Description = "SA2001 event"
Public Event DiagramClose(ByVal hDgm As Long)
Attribute DiagramClose.VB_Description = "SA2001 event"
Public Event Startup()
Attribute Startup.VB_Description = "SA2001 event, called during application startup."
Public Event ShutDown()
Attribute ShutDown.VB_Description = "SA2001 event called during application shutdown."
Public Event AuditIDChanged(NewAuditID As String)
Attribute AuditIDChanged.VB_Description = "Event triggered when AuditID is changed after SA2001 has started."
Public Event ShowNode(ByVal TabIndex As Integer, ByVal TabName As String, ByVal ddId As Long, ByVal Major As Long, ByVal Minor As Long, ByVal name As String, ByVal Memo As String, ByVal LockFlags As Long, RetCode As NodeStatus)
Attribute ShowNode.VB_Description = "Event triggered when browser VBA filter is active. Set the RetCode to show/hide this item."
Public Event EditDefinitionPostOK(ByVal v_lngClass As Long, ByVal v_lngType As Long, ByVal v_lngDDID As Long)
Attribute EditDefinitionPostOK.VB_Description = "SA2001 event triggered when the OK button of a definition edit session is clicked after the definition was saved"
Public Event EditDefinitionPostApply(ByVal v_lngClass As Long, ByVal v_lngType As Long, ByVal v_lngDDID As Long)
Public Event WorkspaceOpen()
Public Event WorkspaceBeforeOpen(ByRef r_lngCancel As Long)
' called to see if there are any user defined menu items to add to the view browser right click menu
' set lMenuID to 0 if none, 1-500 for a user menu insert 501-1000 reserved for system use
' bFlags bit 0 set indicates final call to clear down - reset for next time
' bFlags bit 1 can be set to indicate start of group
' the collection is a collection of selected ddIds
Public Event InsertBrowserMenuItem(ByRef collSelectedItems As Collection, ByRef lMenuID As Long, ByRef strMenuName As String, ByRef bFlags As Long)
' called when a user defined menu item is triggered
' the collection is a collection of selected ddIds
Public Event UserBrowserMenuItem(ByVal Items As Collection, ByVal lMenuID As Long)
Public Event Progress(ByVal lProgPerc As Long)
Public Event InitProgress(ByVal lMin As Long, ByVal lMax As Long)



' Event IDs for use by RaiseExternalEvents
Private Enum AppEvents
    EVT_MAINMENUUPDATE = 1
    EVT_TOOLSMENUUPDATE
    EVT_METHODMENUUPDATE
    EVT_REPORTSMENUUPDATE
    EVT_ENCYOPEN
    EVT_ENCYABOUTTOCHANGE
    EVT_ENCYCLOSE
    EVT_DIAGRAMSAVE
    EVT_SYMBOLEVENT
    EVT_DIAGRAMOPEN
    EVT_DIAGRAMCLOSE
    EVT_STARTUP
    EVT_SHUTDOWN
    EVT_AUDITIDCHANGED
    EVT_SHOWNODE
    EVT_EDITDEFINITIONPOSTOK
    EVT_WORKSPACEOPEN
    EVT_WORKSPACEBEFOREOPEN
    EVT_INSERTBROWSERMENUITEM
    EVT_USERBROWSERMENUITEM
    EVT_EDITDEFINITIONPOSTAPPLY
    EVT_PROGRESS ' 22, used in SAUI
    EVT_INITPROGRESS
End Enum

Private Function GetEncyName() As String
    Dim l_s_Ency As String
    Dim lngResult As Long
    Const ABOUTITEM_ENCY As Long = 4
    
    On Error GoTo ErrOut
    
    GetEncyName = l_s_Ency
    
StdExit:
    On Error GoTo 0
    Exit Function
ErrOut:
    Err.Clear
    GetEncyName = SA_VB_EmptyString
    Resume StdExit
End Function

Public Function GetInternalData(ByVal DataItem As Long, ByRef retValue As Variant) As Long
Attribute GetInternalData.VB_Description = "Gets internal diagnostic information from the object model."
Attribute GetInternalData.VB_MemberFlags = "40"
    Dim l As Long
    
    GetInternalData = 0 ' Success
    Select Case DataItem
        Case GID_COMMANDLINE
            retValue = CommandLine
        Case GID_CMDQAREPORTING
            If CmdLineQAReporting Then
                retValue = 1
            Else
                retValue = 0
            End If
        Case GID_CMDWSENABLE
            retValue = CmdWSEnabled
        Case Else
            GetInternalData = -1   ' Error
    End Select
End Function

Public Function GetInternalDataInt(ByVal DataItem As Long, ByRef retValue As Integer) As Long
    Dim l As Long
    
    GetInternalDataInt = 0 ' Success
    Select Case DataItem
        Case GID_CMDQAREPORTING
            If CmdLineQAReporting Then
                retValue = 1
            Else
                retValue = 0
            End If
        Case GID_CMDWSENABLE
            If CmdWSEnabled Then
                retValue = 1
            Else
                retValue = 0
            End If
        Case Else
            GetInternalDataInt = -1   ' Error
    End Select
End Function

Public Function SetInternalData(ByVal DataItem As Long, ByRef value As Variant) As Long
Attribute SetInternalData.VB_Description = "Sets internal diagnostic and contol information into the object model."
Attribute SetInternalData.VB_MemberFlags = "40"
    SetInternalData = 0 ' Success
    Select Case DataItem
        Case Else
            SetInternalData = -1   ' Error
    End Select
End Function

Public Function GetExePath() As String
    Dim strSAFileName As String
    Dim lPos As Long
    
    If Len(m_strExePath) = 0 Then
        m_strExePath = MSAMain.GetExePath() & "\"
    
        If m_strExePath = "\" Then
            m_strExePath = App.Path & "\"
        End If
    End If
    GetExePath = m_strExePath
End Function

Public Sub ResetPanelBackGround(Panel As Long)
Attribute ResetPanelBackGround.VB_Description = "Resets the background color of the status bar panel "
    Do_ResetPanelColor Panel
End Sub

Public Sub WriteStatusLineEx(ByVal Panel As Long, TextToShow As String, ByVal BackColor As Long, ByVal ForeColor As Long)
Attribute WriteStatusLineEx.VB_Description = "Writes text to the status bar and allows the background and text colors to be specified."
    Do_SetStatusStringEx Panel, TextToShow, BackColor, ForeColor
End Sub

Private Sub RaiseExternalEvents(TheEvent As AppEvents, Optional param1, Optional param2, Optional param3, Optional param4, Optional param5, Optional param6, Optional param7, Optional param8, Optional param9 As NodeStatus)
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' VBA Events
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Friend Sub AppEvent_MainMenuUpdate()
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    RaiseExternalEvents EVT_MAINMENUUPDATE
    RaiseEvent MainMenuUpdate
End Sub

Friend Sub AppEvent_ToolsMenuUpdate()
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    RaiseExternalEvents EVT_TOOLSMENUUPDATE
    RaiseEvent ToolsMenuUpdate
End Sub

Friend Sub AppEvent_MethodMenuUpdate()
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    RaiseExternalEvents EVT_METHODMENUUPDATE
    RaiseEvent MethodMenuUpdate
End Sub

Friend Sub AppEvent_ReportsMenuUpdate()
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    RaiseExternalEvents EVT_REPORTSMENUUPDATE
    RaiseEvent ReportsMenuUpdate
End Sub

Friend Sub AppEvent_Progress(ByVal lProgVal As Long)
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    RaiseExternalEvents EVT_PROGRESS, lProgVal
    RaiseEvent Progress(lProgVal)
End Sub

Friend Sub AppEvent_InitProgress(ByVal lMin As Long, ByVal lMax As Long)
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    RaiseExternalEvents EVT_INITPROGRESS, lMin, lMax
    RaiseEvent InitProgress(lMin, lMax)
End Sub

Friend Sub AppEvent_WorkspaceBeforeOpen(ByRef r_lngCancel As Long)
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Or g_blnSAIsBusy_ProcessingObjectHistory Then Exit Sub    ' Do NOT fire events during the critical period

    Call RaiseExternalEvents(EVT_WORKSPACEBEFOREOPEN, r_lngCancel)  ' test r_lngCancel

    If Not r_lngCancel Then
        RaiseEvent WorkspaceBeforeOpen(r_lngCancel)
    End If
End Sub

Friend Sub AppEvent_WorkspaceOpen()
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Or g_blnSAIsBusy_ProcessingObjectHistory Then Exit Sub   ' Do NOT fire events during the critical period
    
    UpdateCaption
    
    RaiseExternalEvents EVT_WORKSPACEOPEN
    RaiseEvent WorkspaceOpen
End Sub

Friend Sub AppEvent_EncyOpen()
    ' Object model stuff
    If ObjPtr(SAAppObj) = ObjPtr(Me) Then ' if we are the 'main' object
        ' we have a new encyclopedia
        ' and create a new one
        CheckEnableWorkspaceTools
    End If
    ' end of object model stuff
    
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    UpdateCaption
    
    RaiseExternalEvents EVT_ENCYOPEN
    RaiseEvent EncyOpen

End Sub

Friend Sub AppEvent_EncyAboutToChange(ByRef r_lngCancel As Long)
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Or g_blnSAIsBusy_ProcessingObjectHistory Then Exit Sub    ' Do NOT fire events during the critical period

    Call RaiseExternalEvents(EVT_ENCYABOUTTOCHANGE, r_lngCancel)  ' test r_lngCancel

    If Not r_lngCancel Then
        RaiseEvent EncyAboutToChange(r_lngCancel)
    End If
End Sub

Friend Sub AppEvent_EncyClose()
    ' Object model stuff
    Set g_colstrxmlDgmSymConnTuples = Nothing
    ' end of object model stuff
    SetMenuToolStateAsStartup True
    EnableStartUpToolBars fMainForm.ATB

    If gEncyBrowserTabsTempFileName <> SA_VB_EmptyString Then
        Kill gEncyBrowserTabsTempFileName
        gEncyBrowserTabsTempFileName = SA_VB_EmptyString
    End If
    
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    UpdateCaption
    
    RaiseExternalEvents EVT_ENCYCLOSE
    RaiseEvent EncyClose
End Sub

Friend Sub AppEvent_Startup()
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    RaiseExternalEvents EVT_STARTUP
    RaiseEvent Startup
End Sub

Friend Sub AppEvent_ShutDown()
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    RaiseExternalEvents EVT_SHUTDOWN
    RaiseEvent ShutDown
End Sub

Friend Sub AppEvent_AuditIDChanged(ByVal NewAuditID As String)
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    RaiseExternalEvents EVT_AUDITIDCHANGED, NewAuditID
    RaiseEvent AuditIDChanged(NewAuditID)
End Sub

Friend Sub AppEvent_ShowNode(ByVal TabIndex As Integer, ByVal TabName As String, _
                            ByVal ddId As Long, _
                            ByVal Major As Long, ByVal Minor As Long, _
                            ByVal name As String, ByVal Memo As String, _
                            ByVal LockFlags As Long, RetCode As NodeStatus)
    If g_blnSAIsBusy_DoNOTProcessVBAEvents Then Exit Sub   ' Do NOT fire events during the critical period
    
    RaiseExternalEvents EVT_SHOWNODE, TabIndex, TabName, ddId, Major, Minor, name, Memo, LockFlags, RetCode
    RaiseEvent ShowNode(TabIndex, TabName, ddId, Major, Minor, name, Memo, LockFlags, RetCode)
End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' END OF VBA Events
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function AssignBMPtoMacroItem(MacroName As String, _
                                    BmpFileName As String) As Long
Attribute AssignBMPtoMacroItem.VB_Description = "Menu handling, assign a bitmap to a macro item."
    'AssignBMPtoMacroItem = MAC_AssignBMPtoMacroItem(MacroName, BmpFileName)
End Function

Public Function AssignHelpIDtoMacroItem(MacroName As String, _
                                    HelpId As Long) As Long
Attribute AssignHelpIDtoMacroItem.VB_Description = "Menu handling, assign a help ID to a macro item."
    'AssignHelpIDtoMacroItem = MAC_AssignHelpIDtoMacroItem(MacroName, HelpId)
End Function

Public Function AssignHelpIDtoMacroItemEx(ByVal MacroName As String, _
                                    ByVal HelpId As Long, _
                                    ByVal Caption As String) As Long
Attribute AssignHelpIDtoMacroItemEx.VB_Description = "Menu handling, assign a help ID to a macro item - include caption for multiple tagged macro menu items."
                                
    'AssignHelpIDtoMacroItemEx = MAC_AssignHelpIDtoMacroItem(MacroName, HelpId, Caption)
                                                                
End Function

''''''''''''''''''''''''''''''''''
' ShowMenu
'
' You can only Show or Hide any menu item using this method
' The enabled state is only changed to enabled if the menu item is a macro item
'
Public Function ShowMenu(ByVal v_strMenuID As String, ByVal v_blnVisible As Boolean) As Boolean
    Dim objTool As SAToolbarTool
    
    On Error Resume Next
    Set objTool = fMainForm.ATB.Tools(v_strMenuID)
    On Error GoTo 0
    If Not objTool Is Nothing Then
        ShowMenuTool fMainForm.ATB, objTool, v_blnVisible
        If Left(v_strMenuID, Len(MACROPREFIX)) = MACROPREFIX Or Left(v_strMenuID, Len(EXTPREFIX)) = EXTPREFIX _
        Or v_strMenuID = "id_ShowFramework" Then
            EnableMenuTool objTool, v_blnVisible
        End If

        ShowMenu = True
    End If
End Function

''''''''''''''''''''''''''''''''''
' EnableMenu
'
' You can only enable/disable macro menu items using this method - this is to prevent users from
' putting the application in to unsafe states
'
Public Function EnableMenu(ByVal v_strMenuID As String, ByVal v_blnEnabled As Boolean) As Boolean
    Dim objTool As SAToolbarTool
    
    If Left(v_strMenuID, Len(MACROPREFIX)) = MACROPREFIX Or Left(v_strMenuID, Len(EXTPREFIX)) = EXTPREFIX Then
        On Error Resume Next
        Set objTool = fMainForm.ATB.Tools(v_strMenuID)
        On Error GoTo 0
        If Not objTool Is Nothing Then
            EnableMenuTool objTool, v_blnEnabled
            EnableMenu = True
        End If
    End If
End Function

''''''''''''''''''''''''''''''''''
' CheckMenu
'
' You can only check/uncheck macro menu items using this method - this is to prevent users from
' putting the application in to unsafe states
'
Public Function CheckMenu(ByVal v_strMenuID As String, ByVal v_blnChecked As Boolean) As Boolean
    Dim objTool As SAToolbarTool
    
    If Left(v_strMenuID, Len(MACROPREFIX)) = MACROPREFIX Or Left(v_strMenuID, Len(EXTPREFIX)) = EXTPREFIX Then
        On Error Resume Next
        Set objTool = fMainForm.ATB.Tools(v_strMenuID)
        On Error GoTo 0
        If Not objTool Is Nothing Then
            CheckMenuTool objTool, v_blnChecked
            CheckMenu = True
        End If
    End If
End Function

Public Function CheckMenuIsChecked(ByVal v_strMenuID As String) As Boolean
    Dim objTool As SAToolbarTool
    
    If Left(v_strMenuID, Len(MACROPREFIX)) = MACROPREFIX Or Left(v_strMenuID, Len(EXTPREFIX)) = EXTPREFIX Then
        On Error Resume Next
        Set objTool = fMainForm.ATB.Tools(v_strMenuID)
        On Error GoTo 0
        If Not objTool Is Nothing Then
            CheckMenuIsChecked = objTool.Checked
        End If
    End If
End Function

Public Function InsertMacroItemInMenuEx(MacroName As String, _
                                MacroItemCaption As String, _
                                InMenuTitleCaption As String, _
                                Optional BeforeMenuItemCaption As String = "", _
                                Optional Tag As String = "", _
                                Optional bAfterSeparator As Boolean = False) As Long 'DEV_STRING
                                
    'InsertMacroItemInMenuEx = MAC_InsertMacroItemInMenu(MacroName, MacroItemCaption, InMenuTitleCaption, BeforeMenuItemCaption, Tag, bAfterSeparator)
                                                                
End Function

Public Function GetToolBarExtensionTool(ByVal v_strExtensionGUID As String, ByVal v_lngExtensionToolID) As SAToolBarExtension
    Set GetToolBarExtensionTool = fMainForm.ATB.ExtensionTools.ItemByExtensionID(v_strExtensionGUID, v_lngExtensionToolID)
End Function

Public Function GetToolBarExtensionToolName(ByVal v_strExtensionGUID As String, ByVal v_lngExtensionToolID) As String
    GetToolBarExtensionToolName = GetToolBarExtensionToolNameInternal(v_strExtensionGUID, v_lngExtensionToolID)
End Function

Public Function InsertMacroItemInMenu(MacroName As String, _
                                MacroItemCaption As String, _
                                InMenuTitleCaption As String, _
                                Optional BeforeMenuItemCaption As String = "") As Long 'DEV_STRING
                                
    'InsertMacroItemInMenu = MAC_InsertMacroItemInMenu(MacroName, MacroItemCaption, InMenuTitleCaption, BeforeMenuItemCaption)
                                                                
End Function

Public Function RemoveItemFromMenu(ItemCaption As String, _
                                FromMenuTitleCaption As String) As Long
Attribute RemoveItemFromMenu.VB_Description = "Menu handling"
    'RemoveItemFromMenu = MAC_RemoveItemFromMenu(ItemCaption, FromMenuTitleCaption)
End Function

Public Function CreatePopUpMenu(PopUpName As String, Optional BmpFileName As String = "") As Long 'DEV_STRING
Attribute CreatePopUpMenu.VB_Description = "Menu handling"
    'CreatePopUpMenu = MAC_CreatePopUpMenu(PopUpName, BmpFileName)
End Function

Public Function RemovePopUpMenu(PopUpName As String) As Long
Attribute RemovePopUpMenu.VB_Description = "Menu handling"
        ' This was changed to Destroy instead of Remove, to allow users to REALLY
        ' get rid of a popup. This will not hide the item it WILL remove
        ' all trace of it from the toolbar
        ' To hide a popup (everywhere) use RemoveItemFromMenu "Popup Caption", ""
    'RemovePopUpMenu = MAC_DestroyPopUpMenu(PopUpName)
End Function

Public Function InsertPopupMenuItemInMenu(PopUpName As String, _
                                InMenuTitleCaption As String, _
                                Optional BeforeMenuItemCaption As String = "") As Long 'DEV_STRING
Attribute InsertPopupMenuItemInMenu.VB_Description = "Menu handling"
    'InsertPopupMenuItemInMenu = MAC_InsertPopupMenuItemInMenu(PopUpName, InMenuTitleCaption, BeforeMenuItemCaption)
End Function

Public Function InsertPopupMenuItemInMenuEx(PopUpName As String, _
                                InMenuTitleCaption As String, _
                                Optional BeforeMenuItemCaption As String = "", _
                                Optional bAfterSeparator As Boolean = False) As Long 'DEV_STRING
    'InsertPopupMenuItemInMenuEx = MAC_InsertPopupMenuItemInMenu(PopUpName, InMenuTitleCaption, BeforeMenuItemCaption, bAfterSeparator)
End Function

Public Function SetSeparatorBefore(ItemCaption As String, _
                                  FromMenuTitleCaption As String, _
                                  bHasSeparator) As Long
Attribute SetSeparatorBefore.VB_Description = "Menu handling"
    'SetSeparatorBefore = MAC_SetSeparatorBefore(ItemCaption, FromMenuTitleCaption, bHasSeparator)
End Function

Public Function Interface(ByVal InterfaceName As String) As Object
Attribute Interface.VB_Description = "Returns the requested interface as an object. Currently only accepts ""ISAImf"""
    If Not CheckRunning Then Exit Function
    Select Case LCase(InterfaceName)
        
        Case Else
            Set Interface = Nothing
            
            Err.Raise SAERR_OBJECTNOTFOUND, "Application.Interface", _
                "invalid interface" 'DEV_STRING
            
    End Select
End Function

''Public Sub Show(ByVal TheForm As Object)
'' NOW SUPPORTED IN VBA6  HostContainer.HostShowModeless TheForm
''End Sub

Public Sub ShowWindowFrame(lShow As SHOWWINDOWCONSTANTS)
End Sub

Public Sub WriteStatusLine(TextToShow As String)
Attribute WriteStatusLine.VB_Description = "Show text in the status bar"
    Do_ResetPanelColor 1
    Do_SetStatusString 1, TextToShow
End Sub

Public Property Get MousePointer() As Integer
Attribute MousePointer.VB_Description = "Get/Set the aopplication mousepointer."
    MousePointer = Screen.MousePointer
End Property

Public Property Let MousePointer(ByVal mpointer As Integer)
    Screen.MousePointer = mpointer
End Property

Public Property Get Visible() As Boolean
Attribute Visible.VB_Description = "Property is true when the application is running and initialised. Setting True does nothing. Setting False causes SA2001 to exit. Can be used to wait for SA2001 startup:\r\nDo While Not SA2001.Visible\r\n  DoEvents\r\nLoop\r\n"
    Visible = SAInitialized
End Property

Public Property Let Visible(bValue As Boolean)
    If bValue Then
        ' we just ignore this
'        Do While Not SAInitialized
'            'DoEvents
'        Loop
    Else
'        If Not SAInitialized Then
            bRequestShutDown = True ' request shutdown here
'        Else
'            CloseDownApp
'        End If
    End If
End Property

Public Property Get IsStudentVersion() As Boolean
    IsStudentVersion = False
End Property

Private Sub Class_Initialize()
    'If Not CheckRunning Then Exit Function
    
    If SAAppObj Is Nothing Then
        'Initialise exception handler
        
        If g_blnInitMainAppThisTime Then
        Else
            ' COM started the app - Ensure we note their object reference
            SAAppObjColl.Add ObjPtr(Me), Format(ObjPtr(Me))
            g_lngRefUsedToStartSA = ObjPtr(Me)  ' Note the reference
            LogMessage "Extern reference to SA initializing - This ref started our application - " & CStr(ObjPtr(Me)) 'DEV_STRING
        End If
    Else
        ' Another instance of this class is being made - ensure we keep an _
        uncounted reference to allow them to receive events
        SAAppObjColl.Add ObjPtr(Me), Format(ObjPtr(Me))
        LogMessage "Extern reference to SA initializing - another external reference - " & CStr(ObjPtr(Me)) 'DEV_STRING
    
'        LogMessage "Waiting for startup complete" 'DEV_STRING
'        Do While Not SAIMFAvailable  ' wait for SA to startup.
'            DoEvents
'        Loop
    End If
End Sub

Private Function CheckRunning() As Boolean
    If SAIMFAvailable Then
'    If SAInitialized Then
        CheckRunning = True
    Else
        CheckRunning = False
        
        Err.Raise SAERR_SANOTRUNNING, "Application.CheckRunning", _
                "sa not initialized" 'DEV_STRING
        
    End If
End Function

Private Sub Class_Terminate()
    On Error Resume Next
    
    If Not SAAppObj Is Nothing Then
        'terminate exception handling
        If ObjPtr(SAAppObj) <> ObjPtr(Me) Then
            ' We are not the main Application object created by SA - so we must remove _
            the uncounted reference to ourselves prior to termination
            SAAppObjColl.Remove Format(ObjPtr(Me))
            If g_lngRefUsedToStartSA = CLng(ObjPtr(Me)) Then
                LogMessage "Extern reference to SA terminating - This ref started our application - " & CStr(ObjPtr(Me)) 'DEV_STRING
            Else
                LogMessage "Extern reference to SA terminating - " & CStr(ObjPtr(Me)) 'DEV_STRING
            End If
        End If
    End If
End Sub


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' SA2001 stuff
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Sub ExecuteMenubyName(strName As String)
Attribute ExecuteMenubyName.VB_Description = "Actions a menu item by menu tool name. Must not be called from within a routine activated by a menu item. Menu tool names can be determined by hitting Ctrl-Shift-F1 when mouse in hovering over the menu item."
    Dim objTool As SAToolbarTool


    On Error Resume Next
    Set objTool = fMainForm.ATB.Tools(strName)
    On Error GoTo 0
    
    If objTool Is Nothing Then
        RaiseError SAERR_MENUTOOLNOTFOUND, "Application.ExecuteMenubyName", _
            SAXRes.GetLocalString(IDS_sa2001sadcomcls_____themenutoolcouldnotbefoundn) & strName 'DEV_STRING
    End If
End Sub

Public Sub InvokeSAHelp(lngHelpID As Long)
    ActiveHelpID = lngHelpID
    MyExecuteMenuCommand 173
End Sub

