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