VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsFrameMgmt"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private FramePool() As objFrame
Public BotIndex As Integer

Public Function Init()
    ReDim FramePool(0)
    Set FramePool(0) = New objFrame
End Function

Public Function GetPool() As Object()
    Dim GP() As Object, i As Integer
    ReDim GP(UBound(FramePool))
    For i = 0 To UBound(FramePool)
        Set GP(i) = FramePool(i)
    Next i
    GetPool = GP
End Function

Public Function CreateFrame(Name As String, Owner As String, Title As String, Plugin As Boolean) As Object
On Error GoTo hErr:
    Dim i As Integer
    For i = 0 To UBound(FramePool)
        If Not FramePool(i) Is Nothing Then
            If LCase(FramePool(i).Name) = LCase(Name) Or LCase(FramePool(i).Title) = LCase(Title) Then
                Set CreateFrame = Nothing
                Exit Function
            End If
        End If
    Next
1   Dim FP As New objFrame
2   With frmBot
3       Load .lvFrame(.lvFrame.Count)
4       .lvFrame(.lvFrame.UBound).Tag = BotIndex & "%" & Title
5       .lvFrame(.lvFrame.UBound).ListItems.Clear
6       Load .rtbFrame(.rtbFrame.Count)
7       .rtbFrame(.rtbFrame.UBound).Tag = BotIndex & "%" & Title
8       .rtbFrame(.rtbFrame.UBound).Text = vbNS
9       Load .imlFrame(.imlFrame.Count)
10      .imlFrame(.imlFrame.UBound).Tag = BotIndex & "%" & Title
11      .imlFrame(.imlFrame.UBound).ListImages.Clear
    End With
12  With FP
13      Set .ImageList = frmBot.imlFrame(frmBot.imlFrame.UBound)
14      Set .List = frmBot.lvFrame(frmBot.lvFrame.UBound)
15      Set .ListTip = frmBot.TT
16      Set .RichText = frmBot.rtbFrame(frmBot.rtbFrame.UBound)
17      .List.FullRowSelect = True
18      .List.View = 3
19      .List.LabelEdit = 1
20      .List.HideColumnHeaders = True
21      .RichText.AutoVerbMenu = True
22      .Plugin = Plugin
23      .Name = Name
24      .Owner = Owner
25      .Title = Title
26  End With
27  If LenB(FramePool(0).Name) > 0 Then ReDim Preserve FramePool(UBound(FramePool) + 1)
28  Set FramePool(UBound(FramePool)) = FP
29  Set CreateFrame = FramePool(UBound(FramePool))
30  If SelBot = BotIndex Then ViewProfile SelTab
    Exit Function
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "FrameManagement", "CreateFrame"
End Function

Public Function DeleteFrame(Name As String, Optional Owner As String) As Boolean
On Error GoTo hErr
    Dim i As Integer
1   For i = UBound(FramePool) To 0 Step -1
2       Dim Owned As Boolean
3       Owned = True
4       If Len(Owner) > 0 Then Owned = ((LCase(FramePool(i).Owner) = LCase(Owner)))
5       If LCase(FramePool(i).Name) = LCase(Name) And Owned Then
6           Dim MyTitle As String
            MyTitle = FramePool(i).Title
8           Dim r As Integer
9           For r = i To UBound(FramePool) - 1
10              Set FramePool(r) = FramePool(r + 1)
11          Next
12          If UBound(FramePool) = 0 Then
13              ReDim FramePool(0)
14              Set FramePool(0) = New objFrame
            Else
15              ReDim Preserve FramePool(UBound(FramePool) - 1)
            End If
16          With frmBot
17              Dim L As ListView
18              For Each L In .lvFrame
19                  If LCase(L.Tag) = LCase(BotIndex & "%" & MyTitle) Then
20                      Unload L
                        Exit For
                    End If
                Next
21              Set L = Nothing
22              Dim t As RichTextBox
23              For Each t In .rtbFrame
24                  If LCase(t.Tag) = LCase(BotIndex & "%" & MyTitle) Then
25                      Unload t
                        Exit For
                    End If
                Next
26              Set t = Nothing
            End With
27          DeleteFrame = True
28          If SelBot = BotIndex Then ViewProfile SelTab
            Exit Function
        End If
    Next
    Exit Function
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "FrameManagement", "DeleteFrame"
End Function

Public Function OpenFrame(Name As String, Owner As String) As Object
On Error GoTo hErr:
1   Dim i As Integer
2   For i = 0 To UBound(FramePool)
3       If LCase$(FramePool(i).Name) = LCase$(Name) Or LCase(FramePool(i).Owner) = LCase$(Owner) Then
4           Set OpenFrame = FramePool(i): Exit Function
        End If
    Next
hErr:
5   Set OpenFrame = Nothing
End Function

Public Sub DeleteType(Owner As String, Script As Boolean)
    Dim i As Integer
    For i = UBound(FramePool) To 0 Step -1
        If FramePool(i).Plugin = Not Script Then
            Dim Name As String
            If Len(Owner) > 0 Then
                If LCase$(FramePool(i).Owner) = LCase$(Owner) Then
                    Name = FramePool(i).Name
                    DeleteFrame Name, Owner
                End If
            Else
                Name = FramePool(i).Name
                DeleteFrame Name
            End If
        End If
    Next i
End Sub


