Package com.ms.fx Previous
Previous
Contents
Contents
Index
Index
Next
Next

Class FxFormattedText

Constructors , Methods , Fields

public class FxFormattedText extends FxText implements IFxTextConstants, IFxGraphicsConstants 
{
  // Fields
  protected int flags;
  protected Font font;
  protected FontMetrics fm;
  protected IFxTextCallback callMe;
  protected IFxShape outline;
  
  // Constructors
  public FxFormattedText();
  public FxFormattedText(String newBuff);
  public FxFormattedText(char newBuff[]);
  public FxFormattedText(char newBuff[], int offset, int length);
  
  // Methods
  public FxFormattedText dropTail(int iStart);
  public void setCallback(IFxTextCallback c);
  public Font getFont();
  protected void updateFontInfo(Graphics g);
  public void ensureNotDirty( Graphics g );
  public void setFont(Font f);
  public int getWordWrap();
  public void setWordWrap(int ww);
  public int getWidth();
  public int getHeight();
  public String getText();
  public void setText(char newBuff[], int offset, int len);
  public void setText(char newBuff[]);
  public void setText(String s);
  public void setStartPoint(int x, int y);
  public void setStartPoint(Point p);
  public Point getStartPoint();
  public void setStartPointAtOrigin();
  public Rectangle getBounding();
  public Rectangle shrinkBound(boolean reset);
  public void setBounding(Rectangle r, boolean bRetainCurrPoint);
  public void setTextDirection(int dir);
  public int getTextDirection();
  public void setHorizAlign(int h);
  public void setVertAlign(int v);
  public int getHorizAlign();
  public int getVertAlign();
  public void setOutline(IFxShape outline);
  public IFxShape getOutline();
  public void paint(FxGraphics g, int startPos, int length, int opaquing);
  public void paint(Graphics g);
  public Point getNextStartPoint();
  public void setKerning(boolean useKerning);
  public boolean getKerning();
  public boolean isDirty();
  public void insert(char key, int iPos);
  public void insert(char key[], int iPos);
  public void insert(char key[], int offs, int len, int iPos);
  public void remove(int iPos, int numberToRemove);
  public int getOffsetFromPos(int scrnX, int scrnY, int flags);
  public boolean isBodyLocationDetermined();
  public Point getScrnLocation(int index);
  public Point getClosestOffset(int scrnX, int scrnY);
  public int getLocale();
  public void setPasswordChar(char c);
  public boolean getMnemonicDrawing();
  public void setMnemonicDrawing(boolean mnem);
  public void setLocale(int locale);
}

This class is an improved version of DrawText(). It is designed for use with any language and will be superclassed for the basis of an edit class. Alignment, text direction, and others are completely specifiable.


Constructors


FxFormattedText

public FxFormattedText();

Creates an empty sentence.


FxFormattedText

public FxFormattedText(String newBuff);

Creates a new sentence based on a string.

ParameterDescription
newBuff The string that the new sentence will be based on.


FxFormattedText

public FxFormattedText(char newBuff[]);

Creates a new sentence based on an array of characters.

ParameterDescription
newBuff The array of characters that the new sentence will be based on.


FxFormattedText

public FxFormattedText(char newBuff[], int offset, int length);

Creates a new sentence based on an array of characters.

ParameterDescription
newBuff The array of characters to base the new sentence will be based on.
offset The offset to use.
length The length of the array used.


Methods


dropTail

public FxFormattedText dropTail(int iStart);

Forms a clone of this class that contains all the text that is in this class, from iStart onward. The new block will have all the same attribs as this one. Then, remove the text from iStart onward from this block and return the new one.

ParameterDescription
iStart The starting point of the text that should be removed.


setCallback

public void setCallback(IFxTextCallback c);

Sets the callback.

Return Value:

No return value.

ParameterDescription
c The callback to set.

Remarks:

This method is used to allow applications to make final modifications to the layout after all script processing has been done.


getFont

public Font getFont();

Retrieves the font being used.

Return Value:

Returns the font being used.


updateFontInfo

protected void updateFontInfo(Graphics g);

Updates the font being used.

Return Value:

No return value.

ParameterDescription
g The graphics object to update the font.


ensureNotDirty

public void ensureNotDirty(Graphics g);

Updates the text block formatting for the specified graphics context.

Return Value:

No return value.

ParameterDescription
g The graphics object.

Remarks:

This method must be called before widths, heights, and other parameters can be retrieved.


setFont

public void setFont(Font f);

Sets the font of the sentence.

Return Value:

No return value.

ParameterDescription
f The font to set the sentence to.


getWordWrap

public int getWordWrap();

Retrieves the word-wrapping functionality.

Return Value:

Returns the word-wrapping functionality.


setWordWrap

public void setWordWrap(int ww);

Sets the word-wrapping functionality.

Return Value:

No return value.

ParameterDescription
ww The value to set.


getWidth

public int getWidth();

Retrieves the width of the entire buffer if it was one long string.

Return Value:

Returns the buffer width.


getHeight

public int getHeight();

Retrieves the height of the current font.

Return Value:

Returns the height of the current font.


getText

public String getText();

Retrieves the current text in the sentence.

Return Value:

Returns a string that contains the current text in the sentence.


setText

public void setText(String s);

Replaces the text in the sentence.

Return Value:

No return value.

ParameterDescription
s The string to replace the sentence with.


setText

public void setText(char newBuff[], int offset, int len);

Replaces the text in the sentence with that of a character array, starting at a specified offset.

Return Value:

No return value.

ParameterDescription
newBuff[] A character array.
offset The specified offset.
len The length of the character array.


setText

public void setText(char newBuff[]);

Replaces the text in the sentence with that of a character array.

Return Value:

No return value.

ParameterDescription
newBuff[] A character array.


setStartPoint

public void setStartPoint(int x, int y);

Sets the start point of the text.

Return Value:

No return value.

ParameterDescription
x The x coordinate of the start point.
y The y coordinate of the start point.

Remarks:

If there is no bounding box, this is the (x,y) position, and the text will be drawn relative to it via the alignment flags. If there is a bounding box, then the xy position is used to set the start point within the bounding box and the box is used for limiting the text. It is legal to set the xy point outside the bounding box, this means that the start of the text will be missing (not drawn).


setStartPoint

public void setStartPoint(Point p);

Sets the start point for the text.

Return Value:

No return value.

ParameterDescription
p The starting point for the text.


getStartPoint

public Point getStartPoint();

Retrieves the start point for drawing the text.

Return Value:

Returns the point where the text starts.


setStartPointAtOrigin

public void setStartPointAtOrigin();

Resets the text start position to be the origin based on what the script requires.

Return Value:

No return value.


getBounding

public Rectangle getBounding();

Retrieves the current bounding box.

Return Value:

Returns the rectangle that is being used as the bounding box.


shrinkBound

public Rectangle shrinkBound(boolean reset);

Shrinks the bounding rectangle to be as small as possible and still contain all the text. This method is the same as DrawRect(DT_CALCRECT).

Return Value:

Returns the new bounding rectangle if reset is true.

ParameterDescription
reset If true, the bounding rectangle of the object will reflect the change; otherwise, the result will be returned but the bounding rectangle will not be updated.

Remarks:

The direction of shrinkage will depend on the text direction (for example, the upper left corner is not guaranteed to remain at (0,0)).


setBounding

public void setBounding(Rectangle r, boolean bRetainCurrPoint);

Sets the bounding box. If there isn't a bounding box, the text is drawn in the same way as DrawText(DT_SINGLELINE).

Return Value:

No return value.

ParameterDescription
r The rectangle to set as the bounding box.
bRetainCurrPoint If bRetainCurrPoint is false, the alignment is processed as in DrawText() and the currPoint is lost. If the alignments are set to scriptDefault, RTOL/TOB/, and so on, will be picked up.

Remarks:

See the rules for setCurrPoint.


setTextDirection

public void setTextDirection(int dir);

Sets the text flow direction. The direction can either be one of the tdXXX values specified in textConstants or a value of 0.360 is an angle where 0 is "east."

Return Value:

No return value.

ParameterDescription
dir The direction that the text should flow.


getTextDirection

public int getTextDirection();

Retrieves the current text direction.

Return Value:

Returns the current text direction.


setHorizAlign

public void setHorizAlign(int h);

Sets the horizontal alignment for the text.

Return Value:

No return value.

ParameterDescription
h The horizontal alignment.


setVertAlign

public void setVertAlign(int v);

Sets the vertical alignment for the text.

Return Value:

No return value.

ParameterDescription
v The vertical alignment.


getHorizAlign

public int getHorizAlign();

Retrieves the horizontal alignment for the text.

Return Value:

Returns the horizontal alignment.


getVertAlign

public int getVertAlign();

Retrieves the vertical alignment for the text.

Return Value:

Returns the vertical alignment.


setOutline

public void setOutline(IFxShape outline);

Sets the outline for which the text will wrap around.

Return Value:

No return value.

ParameterDescription
outline The shape to use as the outline.

Remarks:

When a shape is used, the parameters of the block change their meanings. The horizontal alignment is used as the reference of how to sit on the shape (left, center, and so on). The vertical alignment is whether the text sits above, on, or below the shape. Opaquing has no effect when a shape is in use. As a result, as it cannot be determined.


getOutline

public IFxShape getOutline();

Retrieves the outline.

Return Value:

Returns the shape that is used as the outline.


paint

public void paint(FxGraphics g, int startPos, int length, int opaquing);

Paints the selected characters in the text block.

Return Value:

No return value.

ParameterDescription
g The graphics object to use.
startPos The starting position.
length The length.
opaquing Used only if the graphics object has a text background color set and the text has a bounding box. Can be a combination of the following values:
0 Don't opaque.
1 Opaque everything prior to the starting position.
2 Clean everything between StartPos and NextPos (that is, fill out the lines painted).
3 Opaque everything after NextPos.


paint

public void paint(Graphics g);

Paints the sentence.

Return Value:

No return value.

ParameterDescription
g The graphics object to use.


getNextStartPoint

public Point getNextStartPoint();

Retrieves the next position to draw after the text.

Return Value:

Returns the point that is the next position to draw after the text.

Remarks:

This method is useful for tying multiple sentences together and is used by the textParagraph class. Be aware that if the text ends on a CR, xyNext must point to the next line.


getKerning

public boolean getKerning();

Determines whether kerning is in use.

Return Value:

Returns true if kerning is used.


setKerning

public void setKerning(boolean useKerning);

Sets whether the text should use kerning when formatting.

Return Value:

No return value.


isDirty

public boolean isDirty();

Determines whether the text needs reformatting before anything can be done with it.

Return Value:

Returns true if there is a pending update for the text.


insert

public void insert(char key, int iPos);

Inserts a character into the buffer.

Return Value:

No return value.

ParameterDescription
key The character to insert.
iPos The position in the buffer where the character is to be inserted.


insert

public void insert(char key[], int iPos);

Inserts a character into the buffer.

Return Value:

No return value.

ParameterDescription
key The array of characters to insert.
iPos The position where the characters are to be inserted.


insert

public void insert(char key[], int offs, int len, int iPos);

Inserts an array of characters into the buffer.

Return Value:

No return value.

ParameterDescription
key The array of characters to insert.
offs The specified offset.
len The length of the character array.
iPos The position in the buffer where the characters are to be inserted.


remove

public void remove(int iPos, int numberToRemove);

Deletes a character.

Return Value:

No return value.

ParameterDescription
iPos The starting position of the characters to remove.
numberToRemove The number of characters to remove.


getOffsetFromPos

public int getOffsetFromPos(int scrnX, int scrnY, int flags);

Retrieves the offset of the character nearest to the point requested.

Return Value:

Returns offset if successful; otherwise, returns -1.

ParameterDescription
scrnX The x coordinate of the location to check.
scrnY The y coordinate of the location to check.
flags The flags controlling the method.

Remarks:

Used by the Edit class to find what character is nearest the caret. The flags are the same as those for opaquing drawing. If there are dy arrays, this will fail. A failure is signified by returning -1. If a failure occurs, use getClosesetOffset.


isBodyLocationDetermined

public boolean isBodyLocationDetermined();

Checks if there definable start, body, and end screen positions.

Return Value:

Returns true if there is a definable start, body, and end screen positions.

Remarks:

This method will be false of dy is defined anywhere, and so can we find exactly which character is nearest the caret.


getScrnLocation

public Point getScrnLocation(int index);

Finds the location of a particular character.

Return Value:

Returns the point where the character is located.

ParameterDescription
index The character to look for.


getClosestOffset

public Point getClosestOffset(int scrnX, int scrnY);

Finds the closest character to the screen location.

Return Value:

Returns the point where the closest character was found.

ParameterDescription
scrnX The x coordinate of the screen location.
scrnY The y coordinate of the screen location.

Remarks:

The point returned contains x = offset idx into the buffer. y = match param (x-x1)2 + (y-y1)2 (this is returned so all formats in a UIEDIT get the chance to pick the character position).


getLocale

public int getLocale();

Retrieves the locale that the text is based on.

Return Value:

Returns the locale.


setPasswordChar

public void setPasswordChar(char c);

Sets the character echoed when password text is entered.

Return Value:

No return value.

ParameterDescription
c The character to use.


getMnemonicDrawing

public boolean getMnemonicDrawing();

Determine whether text is using underlines for hot key tracking.

Return Value:

Returns true if underlines are being set.


setMnemonicDrawing

public void setMnemonicDrawing(boolean mnem);

Sets whether the text displays underlines for hot key tracking.

Return Value:

No return value.

ParameterDescription
mnem Set to true to enable mnemonic drawing.


setLocale

public void setLocale(int locale);

Sets the locale for the text.

Return Value:

No return value.

ParameterDescription
locale The locale.

Remarks:

This method determines which locale handler is used for formatting, word-breaking, and other operations.


Fields

flags
The internal flags.
font
The default font.
fm
The font metrics.
callMe
The IFxTextCallback.
outline
The IFxShape.


Top© 1997 Microsoft Corporation. All rights reserved. Legal Notices.