1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
#ifndef nsITextServicesDocument_h__
40
#define nsITextServicesDocument_h__
42
#include "nsISupports.h"
49
class nsITextServicesFilter;
52
TextServicesDocument interface to outside world
55
#define NS_ITEXTSERVICESDOCUMENT_IID \
56
{ /* 019718E1-CDB5-11d2-8D3C-000000000000 */ \
57
0x019718e1, 0xcdb5, 0x11d2, \
58
{ 0x8d, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
62
* The nsITextServicesDocument presents the document in as a
63
* bunch of flattened text blocks. Each text block can be retrieved
64
* as an nsString (array of characters).
66
class nsITextServicesDocument : public nsISupports{
69
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITEXTSERVICESDOCUMENT_IID)
71
typedef enum { eDSNormal=0, eDSUndlerline } TSDDisplayStyle;
73
typedef enum { eBlockNotFound=0, // There is no text block (TB) in or before the selection (S).
74
eBlockOutside, // No TB in S, but found one before/after S.
75
eBlockInside, // S extends beyond the start and end of TB.
76
eBlockContains, // TB contains entire S.
77
eBlockPartial // S begins or ends in TB but extends outside of TB.
78
} TSDBlockSelectionStatus;
81
* Initializes the text services document to use a particular
83
* @param aDOMDocument is the document to use. It is AddRef'd
85
* @param aPresShell is the presentation shell to use when
86
* setting the selection. It is AddRef'd by this method.
88
NS_IMETHOD InitWithDocument(nsIDOMDocument *aDOMDocument, nsIPresShell *aPresShell) = 0;
91
* Get the DOM document for the document in use.
92
* @return aDocument the dom document [OUT]
94
NS_IMETHOD GetDocument(nsIDOMDocument **aDocument) = 0;
97
* Initializes the text services document to use a particular
98
* editor. The text services document will use the DOM document
99
* and presentation shell used by the editor.
100
* @param aEditor is the editor to use. The editor is AddRef'd
103
NS_IMETHOD InitWithEditor(nsIEditor *aEditor) = 0;
106
* Sets the range/extent over which the text services document
107
* will iterate. Note that InitWithDocument() or InitWithEditor()
108
* should have been called prior to calling this method. If this
109
* method is never called, the text services defaults to iterating
110
* over the entire document.
112
* @param aDOMRange is the range to use. aDOMRange must point to a
113
* valid range object.
115
NS_IMETHOD SetExtent(nsIDOMRange* aDOMRange) = 0;
118
* Gets the range that the text services document
119
* is currently iterating over. If SetExtent() was never
120
* called, this method will return a range that spans the
121
* entire body of the document.
123
* @param aDOMRange will contain an AddRef'd pointer to the range.
125
NS_IMETHOD GetExtent(nsIDOMRange** aDOMRange) = 0;
128
* Expands the end points of the range so that it spans complete words.
129
* This call does not change any internal state of the text services document.
131
* @param aDOMRange the range to be expanded/adjusted.
133
NS_IMETHOD ExpandRangeToWordBoundaries(nsIDOMRange *aRange) = 0;
136
* Sets the filter to be used while iterating over content.
137
* @param aFilter filter to be used while iterating over content.
139
NS_IMETHOD SetFilter(nsITextServicesFilter *aFilter) = 0;
142
* Returns true if the document can be modified with calls
143
* to DeleteSelection() and InsertText().
144
* @param aCanEdit is true if the document can be modified,
147
NS_IMETHOD CanEdit(PRBool *aCanEdit) = 0;
150
* Returns the text in the current text block.
151
* @param aStr will contain the text.
154
NS_IMETHOD GetCurrentTextBlock(nsString *aStr) = 0;
157
* Tells the document to point to the first text block
158
* in the document. This method does not adjust the current
159
* cursor position or selection.
162
NS_IMETHOD FirstBlock() = 0;
165
* Tells the document to point to the last text block in the
166
* document. This method does not adjust the current cursor
167
* position or selection.
170
NS_IMETHOD LastBlock() = 0;
173
* Tells the document to point to the first text block that
174
* contains the current selection or caret.
175
* @param aSelectionStatus will contain the text block selection status
176
* @param aSelectionOffset will contain the offset into the
177
* string returned by GetCurrentTextBlock() where the selection
179
* @param aLength will contain the number of characters that are
180
* selected in the string.
183
NS_IMETHOD FirstSelectedBlock(TSDBlockSelectionStatus *aSelectionStatus, PRInt32 *aSelectionOffset, PRInt32 *aSelectionLength) = 0;
186
* Tells the document to point to the last text block that
187
* contains the current selection or caret.
188
* @param aSelectionStatus will contain the text block selection status
189
* @param aSelectionOffset will contain the offset into the
190
* string returned by GetCurrentTextBlock() where the selection
192
* @param aLength will contain the number of characters that are
193
* selected in the string.
196
NS_IMETHOD LastSelectedBlock(TSDBlockSelectionStatus *aSelectionStatus, PRInt32 *aSelectionOffset, PRInt32 *aSelectionLength) = 0;
199
* Tells the document to point to the text block before
200
* the current one. This method will return NS_OK, even
201
* if there is no previous block. Callers should call IsDone()
202
* to check if we have gone beyond the first text block in
206
NS_IMETHOD PrevBlock() = 0;
209
* Tells the document to point to the text block after
210
* the current one. This method will return NS_OK, even
211
* if there is no next block. Callers should call IsDone()
212
* to check if we have gone beyond the last text block
216
NS_IMETHOD NextBlock() = 0;
219
* IsDone() will always set aIsDone == PR_FALSE unless
220
* the document contains no text, PrevBlock() was called
221
* while the document was already pointing to the first
222
* text block in the document, or NextBlock() was called
223
* while the document was already pointing to the last
224
* text block in the document.
225
* @param aIsDone will contain the result.
228
NS_IMETHOD IsDone(PRBool *aIsDone) = 0;
231
* SetSelection() allows the caller to set the selection
232
* based on an offset into the string returned by
233
* GetCurrentTextBlock(). A length of zero places the cursor
234
* at that offset. A positive non-zero length "n" selects
235
* n characters in the string.
236
* @param aOffset offset into string returned by GetCurrentTextBlock().
237
* @param aLength number characters selected.
240
NS_IMETHOD SetSelection(PRInt32 aOffset, PRInt32 aLength) = 0;
243
* Scrolls the document so that the current selection is visible.
246
NS_IMETHOD ScrollSelectionIntoView() = 0;
249
* Deletes the text selected by SetSelection(). Calling
250
* DeleteSelection with nothing selected, or with a collapsed
251
* selection (cursor) does nothing and returns NS_OK.
254
NS_IMETHOD DeleteSelection() = 0;
257
* Inserts the given text at the current cursor position.
258
* If there is a selection, it will be deleted before the
262
NS_IMETHOD InsertText(const nsString *aText) = 0;
265
* Sets the display style for the text selected by SetSelection().
266
* @param aStyle is the style to apply to the selected text.
269
NS_IMETHOD SetDisplayStyle(TSDDisplayStyle aStyle) = 0;
272
* Returns the DOM range for a given offset and length
273
* @param aOffset offset into string returned by GetCurrentTextBlock().
274
* @param aLength number characters selected.
275
* @param aDOMRange the DOM range that represents the offset and length
277
NS_IMETHOD GetDOMRangeFor(PRInt32 aOffset, PRInt32 aLength, nsIDOMRange** aRange) = 0;
280
#endif // nsITextServicesDocument_h__