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

'Klasa Caretaker
Private drawings As Collection
Private undoList As Collection

Public Sub init(dcol As Collection)
  Set drawings = dcol
  Set undoList = New Collection
End Sub
'------------------------------------
Public Sub rememberPosition(vrect As VisRectangle)
  Dim m As Memento
  Set m = New Memento
  m.init vrect
  undoList.add m
End Sub
'------------------------------------
Public Sub clear(drw As Collection)
  Set undoList = New Collection
  Set drawings = drw
End Sub

Public Sub add(intObj As Integer)
  Dim integ As intClass
  Set integ = New intClass
  integ.init intObj
  undoList.add integ
End Sub
'------------------------------------
Private Sub removeLast()
  drawings.remove drawings.count
End Sub
'------------------------------------
Private Sub remove(obj As Memento)
  obj.restore
End Sub
'-----------------------------------
Public Sub undo()
  Dim obj As Object
  If undoList.count > 0 Then
    'Pobierz ostatni element z listy wycofań
    Set obj = undoList(undoList.count)
    undoList.remove undoList.count   'I usuń go
    If Not (TypeOf obj Is Memento) Then
      removeLast                  'Usuń instancję klasy Integer
    Else
      remove obj                  'Usuń instancję klasy Memento
    End If
  End If
End Sub
