Inside Microsoft® Visual Studio® .NET 2003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Inside Microsoft® Visual Studio® .NET 2003 [Electronic resources] - نسخه متنی

Brian Johnson

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










Point Objects


As you might guess, a point object represents a position in a text document. The automation object model gives you three point objects to choose from: TextPoint, VirtualPoint, and EditPoint.



TextPoint


The TextPoint object embodies the fundamental attributes of a text document location; VirtualPoint and EditPoint implement the TextPoint interface, so all point objects have these fundamental attributes in common. The following list gives you an idea of what these attributes might be:

Line information

The Line property returns which line of the document the point is in.

Offset information

The AbsoluteCharOffset and LineCharOffset properties return the number of characters between the point and the beginning of the document and the beginning of the current line, respectively.

Extreme information

The AtStartOfDocument, AtEndOfDocument, AtStartOfLine, and AtEndOfLine properties allow you to determine whether the point is at the beginning or end of a document or line.


The TextPoint LessThan, EqualTo, and GreaterThan methods also let you discover the relation of one point with respect to another.

The TextPoint object doesn't have methods that allow you to edit text directly. Instead, you either pass these point objects to editing methods or use them to create an EditPoint at a particular location, which you can then use to edit text. Table 11-3 shows you the different ways to find a TextPoint object.

Table 11-3. How to Retrieve a TextPoint Object

Returned By


Applies To


StartPoint property


TextDocument

TextPane

TextRange


EndPoint property


TextDocument

TextRange



VirtualPoint


A VirtualPoint object represents a point in virtual space, which, sorry to disappoint, has nothing to do with The Matrix. Virtual space is a text editor feature that allows the insertion point to move indefinitely past the end of a line; typing a character at a point in virtual space causes the editor to automatically fill in the space between the end of the line and the new character. You can enable virtual space for all languages by opening the Tools Options dialog box, selecting Text Editor | All Languages | General, and selecting the Enable Virtual Space check box in the Settings area. (See Figure 11-2.)


Figure 11-2. Enabling virtual space



Table 11-4 shows the different ways you can find a VirtualPoint object. As you can see from the table, VirtualPoint objects spring from TextSelection objects, which gives you a clue to their function; selections can extend into virtual space, so the TextSelection object needs VirtualPoint objects to keep track of endpoints that fall outside the text buffer.

Table 11-4. How to Retrieve a VirtualPoint Object

Returned By


Applies To


ActivePoint property

AnchorPoint property

BottomPoint property

TopPoint property


TextSelection

As with the TextPoint object, one of the VirtualPoint object's main uses involves the creation of EditPoint objects. Be aware, however, that a VirtualPoint object can't create an EditPoint object in virtual spaceif you try, the EditPoint gets created at the end of the current line instead. You can avoid those situations by using the following function, which tells you when a VirtualPoint has strayed into virtual space:


Function IsVirtualSpace(ByVal vrtPoint As VirtualPoint) As Boolean
' Description: Returns whether the VirtualPoint lies in virtual space
Return vrtPoint.LineCharOffset <> vrtPoint.VirtualCharOffset
End Function

The VirtualPoint object defines a property named VirtualCharOffset that returns how far the point is from the beginning of the line. The VirtualCharOffset property always has the same value as the LineCharOffset property except when the point is in virtual space.


Lab: Exploring Virtual Space


The best way to understand virtual space and its effects on point objects is to test it for yourself. Here's a quick experiment:

Turn off virtual space in the editor.

Open a new text file and type I am a fish. without hitting Enter.

Select the entire sentence by dragging the mouse from left to right. Notice that the editor won't extend the selection beyond the period.

Open the Output window and run the DisplayTextSelectionEditPoints macro. Observe that the DisplayColumn entries for TopPoint and BottomPoint are 1 and 13, respectively.

Run the DisplayTextSelectionVirtualPoints macro. Notice that the DisplayColumn entries for TopPoint and BottomPoint match those from the previous step.

Run the DisplayTextSelectionText macro and observe that the output is 'I am a fish.'


When you disable virtual space, you confine VirtualPoint objects to the limits of the text buffer. Enable virtual space, however, and those same VirtualPoint objects can wander off to parts unknown:

Enable virtual space in the text editor.

Reselect the entire sentence, but this time extend the selection beyond its end.

Rerun the DisplayTextSelectionEditPoints and DisplayTextSelectionVirtualPoints macros. Notice that the EditPoint values remain unchanged but the VirtualPoint's VirtualCharOffset and VirtualDisplayColumn values exceed those of the corresponding LineCharOffset and DisplayColumn values.

Run the DisplayTextSelectionText macro and observe that its output is the same as before.


That last step shows that virtual space exists outside the text buffer; it also shows that virtual space doesn't count as selected text. Instead, virtual space allows for what you might call WYSINWYG editingwhat you see isn't necessarily what you get.



EditPoint


The EditPoint is the workhorse of the point objects. In addition to the TextPoint methods and properties, EditPoint has methods that let you automate every possible modification of the text buffer. Table 11-5 shows the different ways you can get an EditPoint object.

Table 11-5. How to Retrieve an EditPoint Object

Returned By


Applies To


CreateEditPoint method


EditPoint

TextPoint

VirtualPoint

TextDocument

We'll examine EditPoint's methods shortly, in the section titled "A Comparison of TextSelection and EditPoint."


/ 118