VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsFrameWizard"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private mintFrame As Integer
Private mcmdPrevious As CommandButton
Private mcmdNext As CommandButton
Private mcmdFirst As CommandButton
Private mcmdLast As CommandButton
Private mcol As Collection
Private mstrWizardName As String
Private mblnDefaultDisable As Boolean

Public Event WizardComplete()
Public Event FrameChanged(NewPageNumber As Integer)
Public Event BeforeFrameChange(Cancel As Boolean)

Property Get PageNumber() As Integer
    PageNumber = mintFrame + 1
End Property

Property Get CurrentFrame() As Frame
    Set CurrentFrame = mcol(mintFrame)
End Property

Property Get FrameCount() As Integer
    FrameCount = mcol.Count
End Property

Sub AddFrame(FrameObject As Frame)
    Dim fra As Frame
    mcol.Add FrameObject ', FrameObject.Name & FrameObject.Index
    If FrameObject.Index = 0 Then
        FrameObject.ZOrder 0
    End If
    If LenB(mstrWizardName) Then
        For Each fra In mcol
            fra.Caption = mstrWizardName & ": Step " & fra.Index + 1 & " of " & mcol.Count
        Next
    End If
End Sub

Sub Initialize(WizardTitle As String, DefaultDisable As Boolean, ButtonFirst As CommandButton, ButtonPrevious As CommandButton, ButtonNext As CommandButton, ButtonLast As CommandButton)
    
    mstrWizardName = WizardTitle
    mblnDefaultDisable = DefaultDisable
    
    Set mcmdNext = ButtonNext
    mcmdNext.Caption = "Next ->"
    If mblnDefaultDisable Then mcmdNext.Enabled = False

    Set mcmdPrevious = ButtonPrevious
    mcmdPrevious.Caption = "<- Previous"

    Set mcmdLast = ButtonLast
    If Not (mcmdLast Is Nothing) Then mcmdLast.Caption = "Last >>"

    Set mcmdFirst = ButtonFirst
    If Not (mcmdFirst Is Nothing) Then mcmdFirst.Caption = " << First"

End Sub


Public Sub MoveNext()
    Dim blnCancel As Boolean
    If mintFrame < mcol.Count - 1 Then
        'This ensures the next button is disabled at each step so that
        'in the GUI, certain events have to be processed before the
        'next button enables
        If mblnDefaultDisable Then mcmdNext.Enabled = False
        RaiseEvent BeforeFrameChange(blnCancel)
        If blnCancel Then Exit Sub
        mintFrame = mintFrame + 1
        RaiseEvent FrameChanged(mintFrame + 1)
        mcol(mintFrame + 1).ZOrder 0
    Else
        RaiseEvent WizardComplete
    End If
    
    If mintFrame < mcol.Count - 1 Then
        mcmdNext.Caption = "Next ->"
    Else
        mcmdNext.Caption = "Finish"
    End If
    mcmdPrevious.Enabled = True
End Sub

Public Sub MovePrevious()
    Dim blnCancel As Boolean
    If mintFrame > 0 Then
        RaiseEvent BeforeFrameChange(blnCancel)
        If blnCancel Then Exit Sub
        mintFrame = mintFrame - 1
        RaiseEvent FrameChanged(mintFrame + 1)
        mcol(mintFrame + 1).ZOrder 0
    End If
    
    If mintFrame > 0 Then
        mcmdPrevious.Enabled = True
    Else
        mcmdPrevious.Enabled = False
    End If
    mcmdNext.Caption = "Next ->"
    mcmdNext.Enabled = True

End Sub

Public Function MoveFirst()
    Dim intFrame As Integer
    Dim blnCancel As Boolean
    intFrame = mintFrame
    mintFrame = 0
    If mintFrame <> intFrame Then
        RaiseEvent BeforeFrameChange(blnCancel)
        If blnCancel Then Exit Sub
        RaiseEvent FrameChanged(mintFrame + 1)
    End If
    mcol(mintFrame).ZOrder 0
    mcmdPrevious.Enabled = False
    mcmdNext.Enabled = "Next ->"
End Function

Public Function MoveLast()
    Dim intFrame As Integer
    Dim blnCancel As Boolean
    intFrame = mintFrame
    mintFrame = fraWizard.UBound
    If mintFrame <> intFrame Then
        RaiseEvent BeforeFrameChange(blnCancel)
        If blnCancel Then Exit Sub
        RaiseEvent FrameChanged(mintFrame + 1)
    End If
    mcol(mintFrame).ZOrder 0
    
    If mintFrame < fraWizard.UBound Then
        cmdNav(Index).Caption = "Next ->"
    Else
        cmdNav(Index).Caption = "Finish -|"
    End If
    mcmdPrevious.Enabled = True
End Function

Private Sub Class_Initialize()
    Set mcol = New Collection
End Sub

Private Sub Class_Terminate()
    Set mcol = Nothing
    Set mcmdPrevious = Nothing
    Set mcmdNext = Nothing
    Set mcmdFirst = Nothing
    Set mcmdLast = Nothing
End Sub
