|
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 |
|
20 |
|
21 #ifndef __UNIFIED_EDITOR_H__ |
|
22 #define __UNIFIED_EDITOR_H__ 1 |
|
23 |
|
24 #include <tagma.h> |
|
25 |
|
26 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
27 #include <tagma_internal.h> |
|
28 #endif |
|
29 |
|
30 /* |
|
31 The header file for MUnifiedEditor, an interface that unifies editing operations on backing text and layout, |
|
32 which are traditionally separated between ETEXT (backing text) and FORM (layout). It is not dependent |
|
33 on FORM or ETEXT, although there is an implementation (TFormAndTextEditor) using those components. |
|
34 */ |
|
35 |
|
36 /** |
|
37 Base class for optional interfaces |
|
38 @internalComponent |
|
39 */ |
|
40 class MTmOptionalInterface |
|
41 |
|
42 { |
|
43 }; |
|
44 |
|
45 /** |
|
46 UIDs for standard optional interfaces |
|
47 @internalComponent |
|
48 */ |
|
49 const TUint KUidMUnifiedEditorStyleSupport = 0x100092B6; |
|
50 const TUint KUidMUnifiedEditorPictureSupport = 0x100092B7; |
|
51 const TUint KUidMUnifiedEditorFieldSupport = 0x100092B8; |
|
52 const TUint KUidMUnifiedEditorClipboardSupport = 0x100095EF; |
|
53 |
|
54 /** |
|
55 An interface class for text editing. |
|
56 |
|
57 An object that supports text editing has some backing text - zero or more Unicode characters - and |
|
58 character and paragraph formats applicable to ranges of these characters. A paragraph is a sequence of characters |
|
59 terminating either at the end of the document or after the next paragraph separator, whichever comes first. |
|
60 |
|
61 The format for a given position is derived from up to three formatting layers. The base layer is the lowest and |
|
62 provides default attributes. These may be optionally overridden by attributes from a named style, and these in |
|
63 turn may be overridden by specific formatting. Text editing objects may support any or none of these layers; they |
|
64 may in fact ignore all attempts to set format attributes. |
|
65 @internalComponent |
|
66 */ |
|
67 class MUnifiedEditor |
|
68 |
|
69 { |
|
70 public: |
|
71 /** |
|
72 * constants used when getting formats |
|
73 */ |
|
74 enum TFormatLevel |
|
75 { |
|
76 ESpecific, // format applied by the user |
|
77 EEffective // the actual format: a combination of base and specific formats |
|
78 }; |
|
79 class MStyleSupport : public MTmOptionalInterface |
|
80 /** |
|
81 An optional interface to support styles |
|
82 @internalComponent |
|
83 */ |
|
84 { |
|
85 public: |
|
86 /** |
|
87 * Creates a style. |
|
88 */ |
|
89 virtual TInt CreateStyleL(const RTmStyle& /*aStyle*/) { return KErrNotSupported; } |
|
90 /** |
|
91 * Sets the attributes of a style. |
|
92 */ |
|
93 virtual TInt ChangeStyleL(const RTmStyle& /*aStyle*/) { return KErrNotSupported; } |
|
94 /** |
|
95 * Applies the named style to the specified run of text. |
|
96 */ |
|
97 virtual TInt SetStyleL(TInt aPos, TInt aLength, const TDesC& aName) = 0; |
|
98 /** |
|
99 * Renames a style. |
|
100 */ |
|
101 virtual TInt RenameStyleL(const TDesC& /*aOldName*/,const TDesC& /*aNewName*/) { return KErrNotSupported; } |
|
102 /** |
|
103 * Deletes the named style. |
|
104 */ |
|
105 virtual TInt DeleteStyleL(const TDesC& /*aName*/) { return KErrNotSupported; } |
|
106 /** |
|
107 * Get the number of named styles. |
|
108 */ |
|
109 virtual TInt StyleCount() const = 0; |
|
110 /** |
|
111 * Gets the style set at the document position aPos. If no style is set |
|
112 * there return an empty string and the run length over which no style |
|
113 * applies. |
|
114 */ |
|
115 virtual void GetStyle(TInt aPos, TPtrC& aName, TInt& aRunLength) const = 0; |
|
116 /** |
|
117 * Gets the attributes of a named style by completing aStyle from its |
|
118 * name. |
|
119 */ |
|
120 virtual TInt GetStyleByNameL(const TDesC& aName, RTmStyle& aStyle) const = 0; |
|
121 /** |
|
122 * Gets the name and attributes of a style by index; use this in |
|
123 * conjunction with StyleCount to enumerate existing styles. |
|
124 */ |
|
125 virtual TInt GetStyleByIndexL(TInt aIndex, RTmStyle& aStyle) const = 0; |
|
126 }; |
|
127 |
|
128 /** |
|
129 An optional interface to support embedded pictures |
|
130 @internalComponent |
|
131 */ |
|
132 class MPictureSupport : public MTmOptionalInterface |
|
133 |
|
134 { |
|
135 public: |
|
136 /** |
|
137 * Inserts a picture, passing ownership in. |
|
138 */ |
|
139 virtual void InsertPictureL(TInt aPos, const TPictureHeader& aPictureIn) = 0; |
|
140 /** |
|
141 * Deletes picture character in the text at aPos, if any. Ownership of |
|
142 * any picture is passed to the caller, therefore Picture(aPos, |
|
143 * aPictureOut) must have been called previously, and |
|
144 * aPictureOut.DeletePicture() must be called in the future to avoid a |
|
145 * memory leak. |
|
146 * If the character at aPos is a picture character, it will be deleted, |
|
147 * regardless of whether or not a picture was actually attatched. |
|
148 */ |
|
149 virtual void DropPictureL(TInt aPos) = 0; |
|
150 /** |
|
151 * Gets the picture if any at aPos. No picture is indicated by |
|
152 * aPictureOut.iPictureType containing KUidNull. |
|
153 * Ownership of the picture is retained. Note that aPictureOut is |
|
154 * merely overwritten by this function: aPictureOut.DeletePicture() is |
|
155 * NOT called! |
|
156 */ |
|
157 virtual void Picture(TInt aPos, TPictureHeader& aPictureOut) const = 0; |
|
158 }; |
|
159 |
|
160 /** |
|
161 An optional interface to support clipboard operations |
|
162 @internalComponent |
|
163 */ |
|
164 class MClipboardSupport : public MTmOptionalInterface |
|
165 |
|
166 { |
|
167 public: |
|
168 /** |
|
169 * Copy the text and formatting specified to the stream, updating |
|
170 * the dictionary as appropriate. |
|
171 */ |
|
172 virtual void CopyToStoreL(CStreamStore& aStore, CStreamDictionary& aDictionary, |
|
173 TInt aPos, TInt aLength) const = 0; |
|
174 /** |
|
175 * Insert text and formatting from the stream at aPos. |
|
176 */ |
|
177 virtual void PasteFromStoreL(const CStreamStore& aStore, |
|
178 const CStreamDictionary& aDictionary, TInt aPos) = 0; |
|
179 }; |
|
180 |
|
181 // VIRTUAL FUNCTIONS |
|
182 |
|
183 // getters |
|
184 |
|
185 /** |
|
186 * Returns the optional interface with the specified UID, or 0 if it is not |
|
187 * supported. |
|
188 */ |
|
189 virtual MTmOptionalInterface* Interface(TUint /*aId*/) { return NULL; } |
|
190 /** |
|
191 * Returns the length of the document in characters, not including any |
|
192 * notional final paragraph separator. |
|
193 */ |
|
194 virtual TInt DocumentLength() const = 0; |
|
195 /** |
|
196 * Gets some text starting at aPos. The amount of text returned may be as |
|
197 * much or as little as is convenient to the implementation, but must be |
|
198 * at least one character. The text is raw Unicode text including any |
|
199 * paragraph separators. |
|
200 */ |
|
201 virtual void GetText(TInt aPos,TPtrC& aText) const = 0; |
|
202 /** |
|
203 * Gets the base character and paragraph formats |
|
204 */ |
|
205 virtual void GetBaseFormatL(TTmCharFormat& aCharFormat,RTmParFormat& aParFormat) const = 0; |
|
206 /** |
|
207 * Gets the specific or effective character format and the run over which |
|
208 * that format applies. |
|
209 */ |
|
210 virtual void GetCharFormat(TInt aPos,TFormatLevel aLevel, |
|
211 TTmCharFormatLayer& aFormat,TInt& aRunLength) const = 0; |
|
212 /** |
|
213 * Gets the specific or effective paragraph format and the run over which |
|
214 * that format applies. |
|
215 */ |
|
216 virtual void GetParFormatL(TInt aPos,TFormatLevel aLevel, |
|
217 RTmParFormatLayer& aFormat,TInt& aRunLength) const = 0; |
|
218 |
|
219 // setters |
|
220 |
|
221 /** |
|
222 * Inserts text at aPos, optionally applying the specified character and |
|
223 * paragraph formats. Unspecified attributes take the format at the |
|
224 * insertion point; what this means in detail is implementation-dependent. |
|
225 */ |
|
226 virtual void InsertTextL(TInt aPos,const TDesC& aText, |
|
227 const TDesC* aStyle = NULL, |
|
228 const TTmCharFormatLayer* aCharFormat = NULL, |
|
229 const RTmParFormatLayer* aParFormat = NULL) = 0; |
|
230 /** |
|
231 * Deletes aLength characters starting at aPos. |
|
232 */ |
|
233 virtual void DeleteTextL(TInt aPos,TInt aLength) = 0; |
|
234 /** |
|
235 * Sets the base character and paragraph formats |
|
236 */ |
|
237 virtual void SetBaseFormatL(const TTmCharFormat& aCharFormat,const RTmParFormat& aParFormat) = 0; |
|
238 /** |
|
239 * Sets specific character attributes beginning at aPos for aLength characters. |
|
240 */ |
|
241 virtual void SetCharFormatL(TInt aPos,TInt aLength,const TTmCharFormatLayer& aFormat) = 0; |
|
242 /** |
|
243 * Sets specific paragraph attributes beginning at aPos for aLength characters. |
|
244 */ |
|
245 virtual void SetParFormatL(TInt aPos,TInt aLength,const RTmParFormatLayer& aFormat) = 0; |
|
246 /** |
|
247 * Deletes specific character attributes beginning at aPos for aLength characters. |
|
248 */ |
|
249 virtual void DeleteCharFormatL(TInt aPos,TInt aLength) = 0; |
|
250 /** |
|
251 * Deletes specific paragraph attributes beginning at aPos for aLength characters. |
|
252 */ |
|
253 virtual void DeleteParFormatL(TInt aPos,TInt aLength) = 0; |
|
254 |
|
255 // NON-VIRTUAL FUNCTIONS |
|
256 /** |
|
257 * Reads text into a writable descriptor. |
|
258 * |
|
259 * @see GetText(TInt, TPtrC) const |
|
260 */ |
|
261 IMPORT_C void GetText(TInt aPos, TDes& aText) const; |
|
262 /** |
|
263 * Returns the interface for manipulating styles, if applicable. |
|
264 */ |
|
265 inline MStyleSupport* StyleSupport(); |
|
266 inline const MStyleSupport* StyleSupport() const; |
|
267 /** |
|
268 * Returns the interface for manipulating pictures, if applicable. |
|
269 */ |
|
270 inline MPictureSupport* PictureSupport(); |
|
271 inline const MPictureSupport* PictureSupport() const; |
|
272 /** |
|
273 * Returns the interface for clipboard operations, if applicable. |
|
274 */ |
|
275 inline MClipboardSupport* ClipboardSupport(); |
|
276 inline const MClipboardSupport* ClipboardSupport() const; |
|
277 }; |
|
278 |
|
279 // inline functions |
|
280 |
|
281 MUnifiedEditor::MStyleSupport* MUnifiedEditor::StyleSupport() |
|
282 { |
|
283 return static_cast<MStyleSupport*>(Interface(KUidMUnifiedEditorStyleSupport)); |
|
284 } |
|
285 |
|
286 const MUnifiedEditor::MStyleSupport* MUnifiedEditor::StyleSupport() const |
|
287 { |
|
288 return static_cast<MStyleSupport*>( |
|
289 const_cast<MUnifiedEditor*>(this)->Interface(KUidMUnifiedEditorStyleSupport)); |
|
290 } |
|
291 |
|
292 MUnifiedEditor::MPictureSupport* MUnifiedEditor::PictureSupport() |
|
293 { |
|
294 return static_cast<MPictureSupport*>(Interface(KUidMUnifiedEditorPictureSupport)); |
|
295 } |
|
296 |
|
297 const MUnifiedEditor::MPictureSupport* MUnifiedEditor::PictureSupport() const |
|
298 { |
|
299 return static_cast<MPictureSupport*>( |
|
300 const_cast<MUnifiedEditor*>(this)->Interface(KUidMUnifiedEditorPictureSupport)); |
|
301 } |
|
302 |
|
303 MUnifiedEditor::MClipboardSupport* MUnifiedEditor::ClipboardSupport() |
|
304 { |
|
305 return static_cast<MClipboardSupport*>(Interface(KUidMUnifiedEditorClipboardSupport)); |
|
306 } |
|
307 |
|
308 const MUnifiedEditor::MClipboardSupport* MUnifiedEditor::ClipboardSupport() const |
|
309 { |
|
310 return static_cast<MClipboardSupport*>( |
|
311 const_cast<MUnifiedEditor*>(this)->Interface(KUidMUnifiedEditorClipboardSupport)); |
|
312 } |
|
313 |
|
314 #endif // __UNIFIED_EDITOR_H__ |