1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
// -*- C++ -*-
/*
* GChemPaint library
* operation.h
*
* Copyright (C) 2002-2008 Jean Bréfort <jean.brefort@normalesup.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*/
/*!\file*/
#ifndef GCHEMPAINT_OPERATION_H
#define GCHEMPAINT_OPERATION_H
#include <gcu/macros.h>
#include <gcu/object.h>
/*!\file*/
namespace gcp {
class Document;
/*!\enum OperationType gcp/operation.h
Enumeration of the different operation types See gcp::Document::GetNewOeration()
for its use.
*/
typedef enum
{
/*!
Object addition operation, see the AddOperation class.
*/
GCP_ADD_OPERATION,
/*!
Object deletion operation, see the DeleteOperation class.
*/
GCP_DELETE_OPERATION,
/*!
Object modification operation, see the ModifyOperation class.
*/
GCP_MODIFY_OPERATION,
} OperationType;
/*!\class Operation gcp/operation.h
Base operation class for the Undo/Redo framework.
This class is virtual since some methods are pure virtual.
*/
class Operation
{
public:
/*!
@param pDoc a document.
@param ID a unique operation ID for the document and the session.
Creates a new operation. Operations should always created by calls to
Document::GetNewOperation().
*/
Operation (Document *pDoc, unsigned long ID);
virtual ~Operation ();
/*!
Undo the changes represented by this operation.
*/
virtual void Undo () = 0;
/*!
Redo the changes represented by this operation.
*/
virtual void Redo () = 0;
/*!
@param pObject an Object affected by the changes.
@param type a number indicationg the role of the stored objects.
The \a type argument is only significant for the gcp::ModifyOperation class
where 0 represent the state of the objects before the operation, and 1 the
state of the objects after the operation.
Adds an object to the operation.
Typically, modifying an object whould need code like:
\code
Object *obj;
// Initialize the object pointer so that it points to a valid object
...
Document *doc = obj->GetDocument ();
Operation *op = doc->GetNewOperation (GCP_MODIFY_OPERATION);
op->AddObject (obj, 0);
// Modify the object
...
op->AddObject (obj, 1);
doc->FinishOperation ();
\endcode
*/
virtual void AddObject (gcu::Object* pObject, unsigned type = 0);
/*!
@param node an xml node related to the changes.
@param type a number indicationg the role of the stored objects.
The \a type argument is only significant for the gcp::ModifyOperation class
where 0 represent the state of the objects before the operation, and 1 the
state of the objects after the operation.
Adds the node to the document owning the operation. This might be used when
Objects are not available such as when editing text.
*/
virtual void AddNode (xmlNodePtr node, unsigned type = 0);
protected:
/*!
@param type a number indicationg the role of the stored objects.
The \a type argument is only significant for the gcp::ModifyOperation class
where 0 represent the state of the objects before the operation, and 1 the
state of the objects after the operation.
Adds the stored objects to the document owning the operation.
*/
void Add (unsigned type = 0);
/*!
@param type a number indicationg the role of the stored objects.
The \a type argument is only significant for the gcp::ModifyOperation class
where 0 represent the state of the objects before the operation, and 1 the
state of the objects after the operation.
Deletes the stored objects to the document owning the operation.
*/
void Delete (unsigned type = 0);
protected:
/*!
The xml nodes storing the changes.
*/
xmlNodePtr* m_Nodes;
private:
gcp::Document* m_pDoc;
GCU_RO_PROP (unsigned long, ID);
};
/*!\class AddOperation gcp/operation.h
Operation class representing objects additions.
*/
class AddOperation: public Operation
{
public:
/*!
@param pDoc a document.
@param ID a unique operation ID for the document and the session.
Creates a new AddOperation. Operations should always created by calls to
Document::GetNewOperation().
*/
AddOperation (gcp::Document *pDoc, unsigned long ID);
virtual ~AddOperation ();
/*!
Undo the additions represented by this operation.
*/
void Undo ();
/*!
Redo the additions represented by this operation.
*/
void Redo ();
};
/*!\class DeleteOperation gcp/operation.h
Operation class representing objects deletions.
*/
class DeleteOperation: public Operation
{
public:
/*!
@param pDoc a document.
@param ID a unique operation ID for the document and the session.
Creates a new DeleteOperation. Operations should always created by calls to
Document::GetNewOperation().
*/
DeleteOperation (gcp::Document *pDoc, unsigned long ID);
virtual ~DeleteOperation ();
/*!
Undo the deletions represented by this operation.
*/
void Undo ();
/*!
Redo the deletions represented by this operation.
*/
void Redo ();
};
/*!\class ModifyOperation gcp/operation.h
Operation class representing objects modifications.
*/
class ModifyOperation: public Operation
{
public:
/*!
@param pDoc a document.
@param ID a unique operation ID for the document and the session.
Creates a new ModifyOperation. Operations should always created by calls to
Document::GetNewOperation().
*/
ModifyOperation (gcp::Document *pDoc, unsigned long ID);
virtual ~ModifyOperation ();
/*!
Undo the modifications represented by this operation.
*/
void Undo ();
/*!
Redo the modifications represented by this operation.
*/
void Redo ();
};
} // namespace gcp
#endif //GCHEMPAINT_OPERATION_H
|