Contents Up Previous Next

wxTextAttr

wxTextAttr represents the character and paragraph attributes, or style, for a range of text in a wxTextCtrl.

When setting up a wxTextAttr object, pass a bitlist mask to SetFlags to indicate which style elements should be changed. As a convenience, when you call a setter such as SetFont, the relevant bit will be set.

Derived from

No base class

Include files

<wx/textctrl.h>

Typedefs

wxTextPos is the type containing the index of a position in a text control. wxTextCoord contains the index of a column or a row in the control.

Note that although both of these types should probably have been unsigned, due to backwards compatibility reasons, are defined as long currently. Their use (instead of plain long) is still encouraged as it makes the code more readable.

Constants

The following values can be passed to SetAlignment to determine paragraph alignment.

enum wxTextAttrAlignment
{
    wxTEXT_ALIGNMENT_DEFAULT,
    wxTEXT_ALIGNMENT_LEFT,
    wxTEXT_ALIGNMENT_CENTRE,
    wxTEXT_ALIGNMENT_CENTER = wxTEXT_ALIGNMENT_CENTRE,
    wxTEXT_ALIGNMENT_RIGHT,
    wxTEXT_ALIGNMENT_JUSTIFIED
};

These values are passed in a bitlist to SetFlags to determine what attributes will be considered when setting the attributes for a text control.

#define wxTEXT_ATTR_TEXT_COLOUR             0x0001
#define wxTEXT_ATTR_BACKGROUND_COLOUR       0x0002
#define wxTEXT_ATTR_FONT_FACE               0x0004
#define wxTEXT_ATTR_FONT_SIZE               0x0008
#define wxTEXT_ATTR_FONT_WEIGHT             0x0010
#define wxTEXT_ATTR_FONT_ITALIC             0x0020
#define wxTEXT_ATTR_FONT_UNDERLINE          0x0040
#define wxTEXT_ATTR_FONT \
  wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT \
| wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE
#define wxTEXT_ATTR_ALIGNMENT               0x0080
#define wxTEXT_ATTR_LEFT_INDENT             0x0100
#define wxTEXT_ATTR_RIGHT_INDENT            0x0200
#define wxTEXT_ATTR_TABS                    0x0400

Members

wxTextAttr::wxTextAttr
wxTextAttr::GetAlignment
wxTextAttr::GetBackgroundColour
wxTextAttr::GetFont
wxTextAttr::GetLeftIndent
wxTextAttr::GetLeftSubIndent
wxTextAttr::GetRightIndent
wxTextAttr::GetTabs
wxTextAttr::GetTextColour
wxTextAttr::HasBackgroundColour
wxTextAttr::HasFont
wxTextAttr::HasTextColour
wxTextAttr::GetFlags
wxTextAttr::IsDefault
wxTextAttr::SetAlignment
wxTextAttr::SetBackgroundColour
wxTextAttr::SetFlags
wxTextAttr::SetFont
wxTextAttr::SetLeftIndent
wxTextAttr::SetRightIndent
wxTextAttr::SetTabs
wxTextAttr::SetTextColour


wxTextAttr::wxTextAttr

wxTextAttr()

wxTextAttr(const wxColour& colText, const wxColour& colBack = wxNullColour, const wxFont& font = wxNullFont, wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT)

The constructors initialize one or more of the text foreground colour, background colour, font, and alignment. The values not initialized in the constructor can be set later, otherwise wxTextCtrl::SetStyle will use the default values for them.


wxTextAttr::GetAlignment

wxTextAttrAlignment GetAlignment() const

Returns the paragraph alignment.


wxTextAttr::GetBackgroundColour

const wxColour& GetBackgroundColour() const

Return the background colour specified by this attribute.


wxTextAttr::GetFont

const wxFont& GetFont() const

Return the text font specified by this attribute.


wxTextAttr::GetLeftIndent

int GetLeftIndent() const

Returns the left indent in tenths of a millimetre.


wxTextAttr::GetLeftSubIndent

int GetLeftSubIndent() const

Returns the left sub indent for all lines but the first line in a paragraph in tenths of a millimetre.


wxTextAttr::GetRightIndent

int GetRightIndent() const

Returns the right indent in tenths of a millimetre.


wxTextAttr::GetTabs

const wxArrayInt& GetTabs() const

Returns the array of integers representing the tab stops. Each array element specifies the tab stop in tenths of a millimetre.


wxTextAttr::GetTextColour

const wxColour& GetTextColour() const

Return the text colour specified by this attribute.


wxTextAttr::HasBackgroundColour

bool HasBackgroundColour() const

Returns true if this style specifies the background colour to use.


wxTextAttr::HasFont

bool HasFont() const

Returns true if this style specifies the font to use.


wxTextAttr::HasTextColour

bool HasTextColour() const

Returns true if this style specifies the foreground colour to use.


wxTextAttr::GetFlags

long GetFlags()

Returns a bitlist indicating which attributes will be set.


wxTextAttr::IsDefault

bool IsDefault() const

Returns true if this style specifies any non-default attributes.


wxTextAttr::SetAlignment

void SetAlignment(wxTextAttrAlignment alignment)

Sets the paragraph alignment.


wxTextAttr::SetBackgroundColour

void SetBackgroundColour(const wxColour& colour)

Sets the background colour.


wxTextAttr::SetFlags

void SetFlags(long flags)

Pass a bitlist indicating which attributes will be set.


wxTextAttr::SetFont

void SetFont(const wxFont& font)

Sets the text font.


wxTextAttr::SetLeftIndent

void SetLeftIndent(int indent, int subIndent = 0)

Sets the left indent in tenths of a millimetre. subIndent sets the indent for all lines but the first line in a paragraph relative to the first line.


wxTextAttr::SetRightIndent

void SetRightIndent(int indent)

Sets the right indent in tenths of a millimetre.


wxTextAttr::SetTabs

void SetTabs(const wxArrayInt& tabs)

Sets the array of integers representing the tab stops. Each array element specifies the tab stop in tenths of a millimetre.


wxTextAttr::SetTextColour

void SetTextColour(const wxColour& colour)

Sets the text colour.