Update contrib.
2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #ifndef EDITORPLAINTEXTCOMMANDS_H_
20 #define EDITORPLAINTEXTCOMMANDS_H_
22 #include "unified_editor.h"
23 #include "UniqueInstance.h"
24 #include "UndoSystem.h"
31 const TInt KMaxCharsInSingleCommand = 20;
32 const TInt KUndoDllUid = 0x1000902D;
35 using namespace LocalInFile;
40 * Takes two commands and returns one, which when executed will
41 * achieve the result of executing first aRight, then aLeft.
42 * Either argument may be null, indicating no effect of execution.
43 * In the event of a leave, aRight will be destroyed, however
44 * aLeft must be protected by the calling function.
45 * Ownership of aLeft is passed into the function if it exits
46 * cleanly, and ownership of the return value is passed back
47 * to the calling function.
49 CCommand* CoalesceL(CCommand* aLeft, CCommand* aRight);
52 // all the combinable commands:
53 class CEditorCommandInsertTextAndFormat;
54 class CEditorCommandDeleteText;
55 class CEditorCommandInsertPlainText;
56 class CEditorCommandDeletePlainText;
57 class CEditorCommandDeleteCharFormat;
58 class CEditorCommandDeleteParFormat;
61 * Editor command is the base class for all the MUnifiedEditor commands.
64 * @since App-frameworks6.1
66 NONSHARABLE_CLASS(CEditorCommand) : public UndoSystem::CSingleCommand
69 TUid FamilyUid() const;
71 // downcast to combinable internal commands
72 virtual CEditorCommandInsertTextAndFormat*
73 CastToCEditorCommandInsertTextAndFormat();
74 virtual CEditorCommandDeleteText*
75 CastToCEditorCommandDeleteText();
76 virtual CEditorCommandInsertPlainText*
77 CastToCEditorCommandInsertPlainText();
78 virtual CEditorCommandDeletePlainText*
79 CastToCEditorCommandDeletePlainText();
80 virtual CEditorCommandDeleteCharFormat*
81 CastToCEditorCommandDeleteCharFormat();
82 virtual CEditorCommandDeleteParFormat*
83 CastToCEditorCommandDeleteParFormat();
91 * Prototype command for inserting text with specified character and paragraph
95 * @since App-frameworks6.1
97 NONSHARABLE_CLASS(CEditorCommandInsertPlainTextProto) : public CEditorCommand
99 MUnifiedEditor& iTarget;
104 CEditorCommandInsertPlainTextProto(MUnifiedEditor& aTarget)
105 : iTarget(aTarget) {}
106 void Set(TInt aPos, const TDesC& aText);
108 UndoSystem::CCommand* CreateInverseL() const;
109 TInt ExecuteL() const;
111 TBool PrepareToAddInverseToLastL(UndoSystem::CSingleCommand& aLastCommand) const;
112 void AddInverseToLast(UndoSystem::CSingleCommand& aLastCommand) const;
116 * Prototype command for deleting text.
119 * @since App-frameworks6.1
121 NONSHARABLE_CLASS(CEditorCommandDeletePlainTextProto) : public CEditorCommand
123 enum { KMaxCombinableReinsertCharacters = 20 };
125 MUnifiedEditor& iTarget;
128 // For adding inverse to last command
129 mutable TBuf<KMaxCombinableReinsertCharacters> iDeletedText;
132 CEditorCommandDeletePlainTextProto(MUnifiedEditor& aTarget)
133 : iTarget(aTarget) {}
134 void Set(TInt aPos, TInt aLength);
136 UndoSystem::CCommand* CreateInverseL() const;
137 TInt ExecuteL() const;
139 TBool PrepareToAddInverseToLastL(UndoSystem::CSingleCommand& aLastCommand) const;
140 void AddInverseToLast(UndoSystem::CSingleCommand& aLastCommand) const;
144 * Implementation of plain text insertion for use by plain & rich text
145 * insertion commands.
148 * @since App-frameworks6.1
150 class TEditorInsertPlainTextImpl
152 MUnifiedEditor& iTarget;
154 TBuf<KMaxCharsInSingleCommand> iText;
156 TEditorInsertPlainTextImpl(MUnifiedEditor& aTarget, TInt aPos, const TDesC& aText)
157 : iTarget(aTarget), iPos(aPos), iText(aText) {}
158 MUnifiedEditor& Target() const { return iTarget; }
159 const TDesC& Text() const { return iText; }
160 TInt Pos() const { return iPos; }
161 TInt ExecuteL(const TDesC* aStyle, const TTmCharFormatLayer* aChar,
162 const RTmParFormatLayer* aPar) const;
163 TInt ExecuteL() const;
164 TInt CanAdd(TInt aPos, const TDesC& aText, MUnifiedEditor& aTarget) const;
165 void Add(TInt aPos, const TDesC& aText);
169 * Implementation of plain text deletion for use by plain & rich text
171 * Used only in the implementation of command objects.
174 * @since App-frameworks6.1
176 class TEditorDeletePlainTextImpl
178 MUnifiedEditor& iTarget;
183 TEditorDeletePlainTextImpl(MUnifiedEditor& aTarget, TInt aPos,
184 TInt aLength) : iTarget(aTarget), iPos(aPos), iLength(aLength) {}
185 MUnifiedEditor& Target() const { return iTarget; }
186 TInt Pos() const { return iPos; }
187 TInt Length() const { return iLength; }
188 TInt ExecuteL() const;
189 TBool CanAdd(TInt aPos, TInt aLength, MUnifiedEditor& aTarget) const;
190 void Add(TInt aLength);
194 * Implementation class for pasting text
197 * @since App-frameworks6.1
199 class TEditorPasteProtoImpl
201 MUnifiedEditor& iTarget;
202 const CStreamStore* iStore;
203 const CStreamDictionary* iStreamDictionary;
206 TEditorPasteProtoImpl(MUnifiedEditor& aTarget) : iTarget(aTarget) {}
207 void Set(const CStreamStore&, const CStreamDictionary&, TInt aPos);
208 TInt Pos() const { return iPos; }
209 const CStreamStore& Store() const { return *iStore; }
210 const CStreamDictionary& StreamDictionary() const { return *iStreamDictionary; }
211 MUnifiedEditor& Target() const { return iTarget; }
213 void OpenPlainTextStreamLC(RStoreReadStream& aStream) const;
214 // returns length of text in plain text stream. Leaves with KErrNotSupported
215 // if there is no such stream.
216 TInt LengthL() const;
217 TInt ExecuteL() const;
221 * Prototype command for pasting plain text.
224 * @since App-frameworks6.1
226 NONSHARABLE_CLASS(CEditorCommandPastePlainTextProto) : public CEditorCommand
228 TEditorPasteProtoImpl iImpl;
231 CEditorCommandPastePlainTextProto(MUnifiedEditor& aTarget)
233 void Set(const CStreamStore& aStore,
234 const CStreamDictionary& aStreamDictionary,
237 UndoSystem::CCommand* CreateInverseL() const;
238 TInt ExecuteL() const;
242 #endif // EDITORPLAINTEXTCOMMANDS_H_