1 /********************************************************************************
2 *                                                                               *
3 *                     U n d o a b l e   C o m m a n d s                         *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1998,2021 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This program is free software: you can redistribute it and/or modify          *
9 * it under the terms of the GNU General Public License as published by          *
10 * the Free Software Foundation, either version 3 of the License, or             *
11 * (at your option) any later version.                                           *
12 *                                                                               *
13 * This program is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
16 * GNU General Public License for more details.                                  *
17 *                                                                               *
18 * You should have received a copy of the GNU General Public License             *
19 * along with this program.  If not, see <http://www.gnu.org/licenses/>.         *
20 ********************************************************************************/
21 #ifndef COMMANDS_H
22 #define COMMANDS_H
23 
24 
25 
26 // Undo record for text fragment
27 class FXTextCommand : public FXCommand {
28   FXDECLARE_ABSTRACT(FXTextCommand)
29 protected:
30   FXText *text;     // Text widget
31   FXchar *buffer;   // Character buffer
32   FXint   pos;      // Character position
33   FXint   ndel;     // Deleted characters
34   FXint   nins;     // Inserted characters
35 public:
FXTextCommand(FXText * txt,FXint p,FXint nd,FXint ni)36   FXTextCommand(FXText* txt,FXint p,FXint nd,FXint ni):text(txt),buffer(NULL),pos(p),ndel(nd),nins(ni){}
37   virtual FXuint size() const;
38   virtual ~FXTextCommand();
39   };
40 
41 
42 // Insert command
43 class FXTextInsert : public FXTextCommand {
44   FXDECLARE_ABSTRACT(FXTextInsert)
45 public:
46   FXTextInsert(FXText* txt,FXint p,FXint ni,const FXchar* ins);
undoName()47   virtual FXString undoName() const { return "Undo insert"; }
redoName()48   virtual FXString redoName() const { return "Redo insert"; }
49   virtual void undo();
50   virtual void redo();
51   };
52 
53 
54 // Delete command
55 class FXTextDelete : public FXTextCommand {
56   FXDECLARE_ABSTRACT(FXTextDelete)
57 public:
58   FXTextDelete(FXText* txt,FXint p,FXint nd,const FXchar* del);
undoName()59   virtual FXString undoName() const { return "Undo delete"; }
redoName()60   virtual FXString redoName() const { return "Redo delete"; }
61   virtual void undo();
62   virtual void redo();
63   };
64 
65 
66 // Replace command
67 class FXTextReplace : public FXTextCommand {
68   FXDECLARE_ABSTRACT(FXTextReplace)
69 public:
70   FXTextReplace(FXText* txt,FXint p,FXint nd,FXint ni,const FXchar* del,const FXchar* ins);
undoName()71   virtual FXString undoName() const { return "Undo replace"; }
redoName()72   virtual FXString redoName() const { return "Redo replace"; }
73   virtual void undo();
74   virtual void redo();
75   };
76 
77 #endif
78 
79