sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "EditorPlainTextUndo.h"
|
sl@0
|
20 |
#include "EditorPlainTextCommands.h"
|
sl@0
|
21 |
#include "UndoSystemImpl.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
using namespace UndoSystem;
|
sl@0
|
24 |
|
sl@0
|
25 |
//////////////////////////////////////
|
sl@0
|
26 |
// //
|
sl@0
|
27 |
// CEditorPlainTextCommandFactory //
|
sl@0
|
28 |
// //
|
sl@0
|
29 |
//////////////////////////////////////
|
sl@0
|
30 |
|
sl@0
|
31 |
/**
|
sl@0
|
32 |
* Command factory. Used for obtaining 'command' versions of API calls to MUnifiedEditor
|
sl@0
|
33 |
* for the plain text functions.
|
sl@0
|
34 |
*
|
sl@0
|
35 |
* @internalComponent
|
sl@0
|
36 |
* @since App-frameworks6.1
|
sl@0
|
37 |
*/
|
sl@0
|
38 |
class CEditorPlainTextCommandFactory : public CBase
|
sl@0
|
39 |
{
|
sl@0
|
40 |
public:
|
sl@0
|
41 |
static CEditorPlainTextCommandFactory* NewL(MUnifiedEditor& aTarget)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
return new(ELeave) CEditorPlainTextCommandFactory(aTarget);
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
// these commands set up the prototypes and then pass them back
|
sl@0
|
47 |
const CEditorCommandInsertPlainTextProto*
|
sl@0
|
48 |
GetInsertProto(TInt aPos, const TDesC& aText)
|
sl@0
|
49 |
{
|
sl@0
|
50 |
iInsertProto.Set(aPos, aText);
|
sl@0
|
51 |
return &iInsertProto;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
const CEditorCommandDeletePlainTextProto*
|
sl@0
|
54 |
GetDeleteProto(TInt aPos, TInt aLength)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
iDeleteProto.Set(aPos, aLength);
|
sl@0
|
57 |
return &iDeleteProto;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
const CEditorCommandPastePlainTextProto*
|
sl@0
|
60 |
GetPasteProto(const CStreamStore& aStore,
|
sl@0
|
61 |
const CStreamDictionary& aDictionary, TInt aPos)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
iPasteProto.Set(aStore, aDictionary, aPos);
|
sl@0
|
64 |
return &iPasteProto;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
private:
|
sl@0
|
67 |
CEditorPlainTextCommandFactory(MUnifiedEditor& aTarget) :
|
sl@0
|
68 |
iTarget(aTarget),
|
sl@0
|
69 |
iInsertProto(aTarget),
|
sl@0
|
70 |
iDeleteProto(aTarget),
|
sl@0
|
71 |
iPasteProto(aTarget) {}
|
sl@0
|
72 |
|
sl@0
|
73 |
MUnifiedEditor& iTarget;
|
sl@0
|
74 |
// like Design Pattern prototypes, but not quite, because rather than
|
sl@0
|
75 |
// being clonable, they create inverses of themselves
|
sl@0
|
76 |
CEditorCommandInsertPlainTextProto iInsertProto;
|
sl@0
|
77 |
CEditorCommandDeletePlainTextProto iDeleteProto;
|
sl@0
|
78 |
CEditorCommandPastePlainTextProto iPasteProto;
|
sl@0
|
79 |
};
|
sl@0
|
80 |
|
sl@0
|
81 |
|
sl@0
|
82 |
////////////////////////////////
|
sl@0
|
83 |
// //
|
sl@0
|
84 |
// CEditorPlainTextWithUndo //
|
sl@0
|
85 |
// //
|
sl@0
|
86 |
////////////////////////////////
|
sl@0
|
87 |
|
sl@0
|
88 |
CEditorPlainTextWithUndo::CEditorPlainTextWithUndo()
|
sl@0
|
89 |
{
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
void CEditorPlainTextWithUndo::ConstructL(MUnifiedEditor& aEditorBasedOn,
|
sl@0
|
93 |
UndoSystem::CCommandManager& aSharedUndoSystem)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
iBaseEditor = &aEditorBasedOn;
|
sl@0
|
96 |
iFactory = CEditorPlainTextCommandFactory::NewL(aEditorBasedOn);
|
sl@0
|
97 |
iCommandManager = &aSharedUndoSystem;
|
sl@0
|
98 |
iCommandManager->NewReference();
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
CEditorPlainTextWithUndo::~CEditorPlainTextWithUndo()
|
sl@0
|
102 |
{
|
sl@0
|
103 |
if (iCommandManager)
|
sl@0
|
104 |
iCommandManager->Release();
|
sl@0
|
105 |
delete iFactory;
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
EXPORT_C CEditorPlainTextWithUndo* CEditorPlainTextWithUndo::NewL(MUnifiedEditor& aEditor,
|
sl@0
|
109 |
UndoSystem::CCommandManager* aSharedUndoSystem)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
__ASSERT_ALWAYS(aSharedUndoSystem,
|
sl@0
|
112 |
UndoSystem::Panic(UndoSystem::KEditorUndoNoCommandManager));
|
sl@0
|
113 |
CEditorPlainTextWithUndo* r = new(ELeave) CEditorPlainTextWithUndo;
|
sl@0
|
114 |
CleanupStack::PushL(r);
|
sl@0
|
115 |
r->ConstructL(aEditor, *aSharedUndoSystem);
|
sl@0
|
116 |
CleanupStack::Pop(r);
|
sl@0
|
117 |
return r;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
MTmOptionalInterface* CEditorPlainTextWithUndo::Interface(TUint aId)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
MTmOptionalInterface* baseInterface = iBaseEditor->Interface(aId);
|
sl@0
|
123 |
return aId == KUidMUnifiedEditorClipboardSupport?
|
sl@0
|
124 |
static_cast<MUnifiedEditor::MClipboardSupport*>(this)
|
sl@0
|
125 |
: baseInterface;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
void CEditorPlainTextWithUndo::InsertTextL(TInt aPos, const TDesC& aText,
|
sl@0
|
129 |
const TDesC*, const TTmCharFormatLayer*, const RTmParFormatLayer*)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
ASSERT(iFactory);
|
sl@0
|
132 |
const CSingleCommand* proto =
|
sl@0
|
133 |
iFactory->GetInsertProto(aPos, aText);
|
sl@0
|
134 |
ASSERT(proto);
|
sl@0
|
135 |
iCommandManager->ExecuteL(*proto);
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
void CEditorPlainTextWithUndo::DeleteTextL(TInt aPos, TInt aLength)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
ASSERT(iFactory);
|
sl@0
|
141 |
const CSingleCommand* proto =
|
sl@0
|
142 |
iFactory->GetDeleteProto(aPos, aLength);
|
sl@0
|
143 |
ASSERT(proto);
|
sl@0
|
144 |
iCommandManager->ExecuteL(*proto);
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
void CEditorPlainTextWithUndo::CopyToStoreL(CStreamStore& aStore,
|
sl@0
|
148 |
CStreamDictionary& aDictionary,
|
sl@0
|
149 |
TInt aPos,
|
sl@0
|
150 |
TInt aLength) const
|
sl@0
|
151 |
{
|
sl@0
|
152 |
ASSERT(iBaseEditor);
|
sl@0
|
153 |
MUnifiedEditor::MClipboardSupport* ci = iBaseEditor->ClipboardSupport();
|
sl@0
|
154 |
ASSERT(ci);
|
sl@0
|
155 |
ci->CopyToStoreL(aStore, aDictionary, aPos, aLength);
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
void CEditorPlainTextWithUndo::PasteFromStoreL(const CStreamStore& aStore,
|
sl@0
|
159 |
const CStreamDictionary& aDictionary,
|
sl@0
|
160 |
TInt aPos)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
ASSERT(iFactory);
|
sl@0
|
163 |
const CSingleCommand* proto =
|
sl@0
|
164 |
iFactory->GetPasteProto(aStore, aDictionary, aPos);
|
sl@0
|
165 |
ASSERT(proto);
|
sl@0
|
166 |
iCommandManager->ExecuteL(*proto);
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
void CEditorPlainTextWithUndo::SetBaseFormatL(const TTmCharFormat& aC,
|
sl@0
|
170 |
const RTmParFormat& aP)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
iBaseEditor->SetBaseFormatL(aC, aP);
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
void CEditorPlainTextWithUndo::SetCharFormatL(TInt aPos, TInt aLen, const TTmCharFormatLayer& aC)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
iBaseEditor->SetCharFormatL(aPos, aLen, aC);
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
void CEditorPlainTextWithUndo::SetParFormatL(TInt aPos, TInt aLen, const RTmParFormatLayer& aP)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
iBaseEditor->SetParFormatL(aPos, aLen, aP);
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
void CEditorPlainTextWithUndo::DeleteCharFormatL(TInt aPos, TInt aLen)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
iBaseEditor->DeleteCharFormatL(aPos, aLen);
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
void CEditorPlainTextWithUndo::DeleteParFormatL(TInt aPos, TInt aLen)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
iBaseEditor->DeleteParFormatL(aPos, aLen);
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
TInt CEditorPlainTextWithUndo::DocumentLength() const
|
sl@0
|
196 |
{
|
sl@0
|
197 |
return iBaseEditor->DocumentLength();
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
void CEditorPlainTextWithUndo::GetText(TInt aPos, TPtrC& aText) const
|
sl@0
|
201 |
{
|
sl@0
|
202 |
iBaseEditor->GetText(aPos, aText);
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
void CEditorPlainTextWithUndo::GetBaseFormatL(TTmCharFormat& aChar,
|
sl@0
|
206 |
RTmParFormat& aPar) const
|
sl@0
|
207 |
{
|
sl@0
|
208 |
iBaseEditor->GetBaseFormatL(aChar, aPar);
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
void CEditorPlainTextWithUndo::GetCharFormat(TInt aPos, TFormatLevel aLevel,
|
sl@0
|
212 |
TTmCharFormatLayer& aFormat,TInt& aRunLength) const
|
sl@0
|
213 |
{
|
sl@0
|
214 |
iBaseEditor->GetCharFormat(aPos, aLevel, aFormat, aRunLength);
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
void CEditorPlainTextWithUndo::GetParFormatL(TInt aPos, TFormatLevel aLevel,
|
sl@0
|
218 |
RTmParFormatLayer& aFormat, TInt& aRunLength) const
|
sl@0
|
219 |
{
|
sl@0
|
220 |
iBaseEditor->GetParFormatL(aPos, aLevel, aFormat, aRunLength);
|
sl@0
|
221 |
}
|
sl@0
|
222 |
|