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::HasAlignment
wxTextAttr::HasBackgroundColour
wxTextAttr::HasFont
wxTextAttr::HasLeftIndent
wxTextAttr::HasRightIndent
wxTextAttr::HasTabs
wxTextAttr::HasTextColour
wxTextAttr::GetFlags
wxTextAttr::IsDefault
wxTextAttr::Merge
wxTextAttr::SetAlignment
wxTextAttr::SetBackgroundColour
wxTextAttr::SetFlags
wxTextAttr::SetFont
wxTextAttr::SetLeftIndent
wxTextAttr::SetRightIndent
wxTextAttr::SetTabs
wxTextAttr::SetTextColour
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.
wxTextAttrAlignment GetAlignment() const
Returns the paragraph alignment.
const wxColour& GetBackgroundColour() const
Return the background colour specified by this attribute.
const wxFont& GetFont() const
Return the text font specified by this attribute.
int GetLeftIndent() const
Returns the left indent in tenths of a millimetre.
int GetLeftSubIndent() const
Returns the left sub indent for all lines but the first line in a paragraph in tenths of a millimetre.
int GetRightIndent() const
Returns the right indent in tenths of a millimetre.
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.
const wxColour& GetTextColour() const
Return the text colour specified by this attribute.
bool HasAlignment() const
Returns true if this style specifies the text alignment.
bool HasBackgroundColour() const
Returns true if this style specifies the background colour to use.
bool HasFont() const
Returns true if this style specifies the font to use.
bool HasLeftIndent() const
Returns true if this style specifies the left indent.
bool HasRightIndent() const
Returns true if this style specifies the right indent.
bool HasTabs() const
Returns true if this style specifies any tabstobs.
bool HasTextColour() const
Returns true if this style specifies the foreground colour to use.
long GetFlags()
Returns a bitlist indicating which attributes will be set.
bool IsDefault() const
Returns true if this style specifies any non-default attributes.
void Merge(const wxTextAttr& overlay)
Copies all defined/valid properties from overlay to current object.
static wxTextAttr Merge(const wxTextAttr& base, const wxTextAttr& overlay)
Creates a new wxTextAttr which is a merge of base and overlay. Properties defined in overlay take precedence over those in base. Properties undefined/invalid in both are undefined in the result.
void SetAlignment(wxTextAttrAlignment alignment)
Sets the paragraph alignment.
void SetBackgroundColour(const wxColour& colour)
Sets the background colour.
void SetFlags(long flags)
Pass a bitlist indicating which attributes will be set.
void SetFont(const wxFont& font)
Sets the text font.
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.
void SetRightIndent(int indent)
Sets the right indent in tenths of a millimetre.
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.
void SetTextColour(const wxColour& colour)
Sets the text colour.