VERSION 5.00
Begin {AFA72951-79E9-4BF8-A8D2-7AEC6F38B0E0} FSGate 
   ClientHeight    =   11085
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   11025
   Pages           =   ""
End
Attribute VB_Name = "FSGate"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'******************************************************************************
'* Class: Gate
'*   Пользовательский интерфейс для шлюза к файловой системе
'******************************************************************************
Option Explicit

Implements WorkflowObjectsUI.IDVObjectUI
Implements WorkflowObjectsUI.IObjectUI
Implements WorkflowObjectsUI.IGateUI
Implements WorkflowObjectsUI.IGateInit
Implements WorkflowObjectsUI.IObjectLocalize

Private m_Settings As cSettings     'настройки шлюза
Private m_hWnd As Long
Private m_ObjectTypes As WorkflowObjectsUI.IObjectTypeCollection
Private m_Methods As WorkflowObjectsUI.IMethodCollection
Private Const m_cFSGateXMLOffset As Integer = 2200
Private m_sDefinition As String
Private m_xmlGateDef As MSXML2.DOMDocument

Public Enum FSVarTypeEnum
    FileFolder = 0
    File = 1
End Enum

Private Property Get GateDefinition() As MSXML2.DOMDocument
   If m_xmlGateDef Is Nothing Then
      Set m_xmlGateDef = New MSXML2.DOMDocument40
      If Not m_xmlGateDef.loadXML(m_sDefinition) Then Err.Raise m_xmlGateDef.parseError.errorCode, , m_xmlGateDef.parseError.reason
   End If
   Set GateDefinition = m_xmlGateDef
End Property

'******************************************************************************
' Implementation of IObjectLocalize interface
'******************************************************************************
Private Function IObjectLocalize_GetLocaleID() As Long
   IObjectLocalize_GetLocaleID = GetLocaleID
End Function

Private Sub IObjectLocalize_SetLocaleID(ByVal LocaleID As Long)
   SetLocaleID g_LocaleID
End Sub

Private Property Set IDVObjectUI_Host(ByVal RHS As Object)
'
End Property

Private Property Get IDVObjectUI_Host() As Object
'
End Property

Private Property Set IDVObjectUI_UserSession(ByVal RHS As Object)
   SetLocaleID Val(RHS.Properties("LocaleID").Value)
End Property

Private Property Get IDVObjectUI_UserSession() As Object
'
End Property


'******************************************************************************
' Implementation of IObjectUI interface
'******************************************************************************
' Картинка для отображения пользователю
Private Property Get IObjectUI_Icon() As stdole.Picture
    Set IObjectUI_Icon = LoadResPicture(RES_FS_GATE_ICON, vbResIcon)
End Property

' Название шлюза для отображения пользователю
Private Property Get IObjectUI_TypeName() As String
    IObjectUI_TypeName = RES_FILE_CAPTION
End Property

' Идентификатор
Private Property Get IObjectUI_ID() As String
    IObjectUI_ID = ID_FS_GATE
End Property

' Настройки шлюза
Private Property Let IObjectUI_Data(ByVal Data As String)
    m_Settings.xml = Data
End Property
Private Property Get IObjectUI_Data() As String
    IObjectUI_Data = m_Settings.xml
End Property

'******************************************************************************
' Implementation of IGateInit interface
'******************************************************************************
Private Sub IGateInit_Initialize(ByVal Data As String)
   m_sDefinition = Data
End Sub

'******************************************************************************
' Implementation of IGateUI interface
'******************************************************************************
Private Property Get IGateUI_hWnd() As Long
    IGateUI_hWnd = m_hWnd
End Property

Private Property Let IGateUI_hWnd(ByVal hWnd As Long)
    m_hWnd = hWnd
End Property

' Диалог выбора пользователя
Private Function IGateUI_SelectObject(ByVal hWnd As Long, ByVal TypeID As Long, ObjectID As String) As Boolean
    Dim objUI As Object
    Select Case TypeID
       Case FSVarTypeEnum.FileFolder: Set objUI = New cFSFolderDlg: objUI.hWnd = hWnd
       Case FSVarTypeEnum.File: Set objUI = New cFSFileDialog
       Case Else
         Dim sErrMessage As String: sErrMessage = RES_ERRSELECTVARIABLEVALUE
         Err.Raise vbObjectError + 100, , sErrMessage
    End Select
    ' показываем диалог
    IGateUI_SelectObject = objUI.Show(ObjectID)
End Function

' Читаемое имя документа
Private Function IGateUI_GetObjectDisplayValue(ByVal TypeID As Long, ByVal ObjectID As String) As String
    Dim objUI As Object
    Select Case TypeID
       Case FSVarTypeEnum.FileFolder: Set objUI = New cFSFolderDlg
       Case FSVarTypeEnum.File: Set objUI = New cFSFileDialog
    End Select
    IGateUI_GetObjectDisplayValue = objUI.GetDisplayName(ObjectID)
End Function

Private Function IGateUI_GetObjectReference(ByVal TypeID As Long, ByVal ObjectID As String, ByVal ReferenceType As WorkflowObjectsUI.ObjectReferenceTypeEnum) As String
   Select Case TypeID
      Case FSVarTypeEnum.File, FSVarTypeEnum.FileFolder
         IGateUI_GetObjectReference = ObjectID
      Case Else
         IGateUI_GetObjectReference = vbNullString
   End Select
End Function

Private Function IGateUI_GetObjectTypes() As WorkflowObjectsUI.IObjectTypeCollection
   If m_ObjectTypes Is Nothing Then
      Dim oObjectTypes As WorkflowTypeManager.ObjectTypeCollection
      Set oObjectTypes = New WorkflowTypeManager.ObjectTypeCollection
      
      Dim oTypesNode As MSXML2.IXMLDOMNode
      Set oTypesNode = GateDefinition.documentElement.selectSingleNode("ObjectTypes")
      
      If Not oTypesNode Is Nothing Then
         Dim oTypeNode As MSXML2.IXMLDOMNode
         For Each oTypeNode In oTypesNode.selectNodes("ObjectType")
            oObjectTypes.LoadFromXmlNode oTypeNode, True
         Next
      End If
      
      Set m_ObjectTypes = oObjectTypes
   End If
   Set IGateUI_GetObjectTypes = m_ObjectTypes
End Function

Private Function IGateUI_GetMethods() As WorkflowObjectsUI.IMethodCollection
   If m_Methods Is Nothing Then
      Dim oMethodsInit As WorkflowTypeManager.MethodCollection
      Set oMethodsInit = New WorkflowTypeManager.MethodCollection
      
      Dim oMethodsNode As MSXML2.IXMLDOMNode
      Set oMethodsNode = GateDefinition.documentElement.selectSingleNode("Methods")
      
      If Not oMethodsNode Is Nothing Then
         Dim oMethodNode As MSXML2.IXMLDOMNode
         For Each oMethodNode In oMethodsNode.selectNodes("Method")
            oMethodsInit.LoadFromXmlNode oMethodNode, True
         Next
      End If
      
      Set m_Methods = oMethodsInit
   End If
   
   Set IGateUI_GetMethods = m_Methods
End Function

Private Function IGateUI_GetQuickSearchValues(ByVal TypeID As Long, ByVal SearchFor As String) As Object
'
End Function

Private Sub IGateUI_ShowObject(ByVal hWnd As Long, ByVal TypeID As Long, ByVal ObjectID As String)
   Select Case TypeID
      Case FSVarTypeEnum.File, FSVarTypeEnum.FileFolder
         OpenDocument ObjectID, , , hWnd
      Case Else
         Dim sErrMessage As String: sErrMessage = RES_ERRSELECTVARIABLEVALUE
         Err.Raise vbObjectError + 100, , sErrMessage
   End Select
End Sub

Private Sub PropsObject_Initialize()
    Set m_Settings = New cSettings
End Sub

Private Sub PropsObject_Terminate()
    Set m_Settings = Nothing
End Sub
