Xfce Foundation Classes
Main Page  | IndexNamespace List  |  Alphabetical List  |  Class List  |  File List


Xfc::Gtk::Label Class Reference

A GtkLabel C++ wrapper class. More...

#include <xfc/gtk/label.hh>

Inheritance diagram for Xfc::Gtk::Label:

Xfc::Gtk::Misc Xfc::Gtk::Widget Xfc::Gtk::Object Xfc::Atk::Implementor Xfc::G::Object Xfc::G::TypeInterface Xfc::G::TypeInstance Xfc::G::TypeInstance Xfc::Trackable Xfc::Trackable Xfc::Gtk::AccelLabel List of all members.

Signal Prototypes

Public Member Functions

Accessors
Methods
Signal Proxies

Detailed Description

A GtkLabel C++ wrapper class.

The Label widget displays a small amount of text. As the name implies, most labels are used to label another widget such as a Button or a MenuItem.

Mnemonics

Labels may contain mnemonics. Mnemonics are underlined characters in the label, used for keyboard navigation. Mnemonics are created by providing a string with an underscore before the mnemonic character, such as "_File". Constructors and methods that can handle mnemonics have a bool argument use_underline to indicate whether or not the string has a mnemonic character.

Mnemonics automatically activate any activatable widget the label is inside, such as a Button; if the label is not inside the mnemonic's target widget, you have to tell the label about the target using Gtk::Label::set_mnemonic_widget(). Here's a simple example where the label is inside a button:

 // Pressing Alt+H will activate this button
 Gtk::Button *button = new Gtk::Button("_Hello", true);

To create a mnemonic for a widget alongside the label, such as an Entry, you have to point the label at the entry with Gtk::Label::set_mnemonic_widget():

 // Pressing Alt+H will activate this button
 Gtk::Entry *entry = new Gtk::Entry;
 Gtk::Label *label = new Gtk::Label("_Hello", true);
 label->set_mnemonic_widget(entry);

Markup (styled text)

To make it easy to format text in a label (changing colors, fonts, etc.), label text can be provided in a simple markup format. Here's how to create a label with a small font:

 Gtk::Label *label = new Gtk::Label;
 label->set_markup("<small>Small text</small>");

(See complete documentation of available tags in the Pango manual.) The markup passed to set_markup() must be valid; for example, literal </>/& characters must be escaped as <, >, and &. If you pass text obtained from the user, file, or a network to set_markup(), you'll want to escape it with g_markup_escape_text(). Markup strings are just a convenient way to set the Pango::AttrList on a label; set_attributes() may be a simpler way to set attributes in some cases. Be careful though; Pango::AttrList tends to cause internationalization problems, unless you're applying attributes to the entire string (i.e. unless you set the range of each attribute to [0, G_MAXINT)). The reason is that specifying the start_index and end_index for a Pango::Attribute requires knowledge of the exact string being displayed, so translations will cause problems.

Selectable labels

Labels can be made selectable with Gtk::Label::set_selectable(). Selectable labels allow the user to copy the label contents to the clipboard. Only labels that contain useful-to-copy information - such as error messages - should be made selectable.

Text layout

A label can contain any number of paragraphs, but will have performance problems if it contains more than a small number. Paragraphs are separated by newlines or other paragraph separators understood by Pango. Labels can automatically wrap text if you call set_line_wrap(). set_justify() sets how the lines in a label align with one another. If you want to set how the label as a whole aligns in its available space, see Gtk::Misc::set_alignment().

See also: the Label Widget HOWTO and example.


Constructor & Destructor Documentation

Xfc::Gtk::Label::Label ( GtkLabel *  label,
bool  owns_reference = false 
) [explicit, protected]

Construct a new Label from an existing GtkLabel.

Parameters:
label A pointer to a GtkLabel.
owns_reference Set false if the initial reference count is floating, set true if it's not.
The label can be a newly created GtkLabel or an existing GtkLabel (see G::Object::Object).

Xfc::Gtk::Label::Label ( const String str,
bool  use_underline = false 
) [explicit]

Construct a new Label with str as its text.

Parameters:
str The label text.
use_underline Set to true if str contains a mnemonic character.

Xfc::Gtk::Label::Label ( GtkLabel *  label,
bool  owns_reference = false 
) [explicit, protected]

Construct a new Label from an existing GtkLabel.

Parameters:
label A pointer to a GtkLabel.
owns_reference Set false if the initial reference count is floating, set true if it's not.
The label can be a newly created GtkLabel or an existing GtkLabel (see G::Object::Object).

Xfc::Gtk::Label::Label ( const String str,
bool  use_underline = false 
) [explicit]

Construct a new Label with str as its text.

Parameters:
str The label text.
use_underline Set to true if str contains a mnemonic character.


Member Function Documentation

String Xfc::Gtk::Label::get_text (  )  const

Fetches the text from a label widget, as displayed on the screen.

Returns:
The text in the label widget.
This does not include any embedded underlines indicating mnemonics or Pango markup (see get_label()).

Pango::AttrList* Xfc::Gtk::Label::get_attributes (  )  const

Gets the attribute list that was set on the label using set_attributes(), if any.

Returns:
The attribute list, or null if none was set.
This method does not reflect attributes that come from the label's markup (see set_markup()). If you want to get the effective attributes for the label, use get_layout()->get_attributes().

String Xfc::Gtk::Label::get_label (  )  const

Fetches the text from a label widget including any embedded underlines indicating mnemonics and Pango markup (see get_text()).

Returns:
The text of the label widget.

unsigned int Xfc::Gtk::Label::get_mnemonic_keyval (  )  const

If the label has been set so that it has an mnemonic key this function returns the keyval used for the mnemonic accelerator.

Returns:
The mnemonic accelerator if set, otherwise GDK_VoidSymbol.

Widget* Xfc::Gtk::Label::get_mnemonic_widget (  )  const

Retrieves the target of the mnemonic (keyboard shortcut) of this label (see set_mnemonic_widget()).

Returns:
The target of the label's mnemonic, or null if none has been set.

Pango::EllipsizeMode Xfc::Gtk::Label::get_ellipsize (  )  const

Gets the ellipsizing position of the label (see set_ellipsize()).

Returns:
A Pango::EllipsizeMode.

int Xfc::Gtk::Label::get_width_chars (  )  const

Retrieves the desired width of label, in characters (see set_width_chars()).

Returns:
The width of the label in characters.

int Xfc::Gtk::Label::get_max_width_chars (  )  const

Retrieves the desired maximum width of label, in characters (see set_width_chars()).

Returns:
The maximum width of the label in characters.

bool Xfc::Gtk::Label::get_selectable (  )  const

Gets the value set by set_selectable().

Returns:
true if the user can copy text from the label.

void Xfc::Gtk::Label::set_angle ( double  angle  ) 

Sets the angle of rotation for the label.

Parameters:
angle The angle that the baseline of the label makes with the horizontal, in degrees, measured counterclockwise.
An angle of 90 reads from bottom to top, an angle of 270, from top to bottom. The angle setting for the label is ignored if the label is selectable, wrapped, or ellipsized.

double Xfc::Gtk::Label::get_angle (  )  const

Gets the angle of rotation for the label (see set_angle()).

Returns:
The angle of rotation for the label.

bool Xfc::Gtk::Label::get_selection_bounds ( int *  start,
int *  end 
) const

Gets the selected range of characters in the label.

Parameters:
start The location for start of selection, as a character offset.
end The location for end of selection, as a character offset.
Returns:
true if there's a selection.

Pango::Layout* Xfc::Gtk::Label::get_layout (  )  const

Gets the Pango::Layout used to display the label.

Returns:
The Pango::Layout for the Label.
The layout is useful to e.g. convert text positions to pixel positions, in combination with Gtk::Label::get_layout_offsets(). The returned layout is owned by the label.

void Xfc::Gtk::Label::get_layout_offsets ( int *  x,
int *  y 
) const

Obtains the coordinates where the label will draw the Pango::Layout representing the text in the label.

Parameters:
x The location to store X offset of layout, or null.
y The Location to store Y offset of layout, or null.
This method is useful to convert mouse events into coordinates inside the Pango::Layout, e.g. to take some action if some part of the label is clicked. Of course you will need to create an EventBox to receive the events, and pack the label inside it, since labels are a NO_WINDOW widget. Remember when using the Pango::Layout methods you need to convert to and from pixels using PANGO_PIXELS() or PANGO_SCALE.

bool Xfc::Gtk::Label::get_single_line_mode (  )  const

Determines whether the label is in single line mode.

Returns:
true when the label is in single line mode.

void Xfc::Gtk::Label::set_text ( const String str  ) 

Sets the text within the Label widget, overwriting any text that was there before.

Parameters:
str The text you want to set.
Note this will also clear any previously set mnemonic accelerators.

void Xfc::Gtk::Label::set_attributes ( Pango::AttrList attrs  ) 

Sets a Pango::AttrList; the attributes in the list are applied to the label text.

Parameters:
attrs A Pango::AttrList, or null to remove any previously set attributes.
The attributes set with this method will be ignored if the "use_underline" property or the "use_markup" property is true.

void Xfc::Gtk::Label::set_markup ( const String str  ) 

Parses str which is marked up with the Pango text markup language, setting the label's text and attribute list based on the parse results.

Parameters:
str A markup string (see Pango markup format).

void Xfc::Gtk::Label::set_label ( const String str  ) 

Sets the text of the label.

The label is interpreted as including embedded underlines and/or Pango markup depending on the values of use_underline() and use_markup().

Parameters:
str The new text to set for the label.

void Xfc::Gtk::Label::set_markup_with_mnemonic ( const String str  ) 

Parses str which is marked up with the Pango text markup language, setting the label's text and attribute list based on the parse results.

Parameters:
str A markup string (see Pango markup format).
If characters in str are preceded by an underscore, they are underlined indicating that they represent a keyboard accelerator called a mnemonic. The mnemonic key can be used to activate another widget, chosen automatically, or explicitly using Gtk::Label::set_mnemonic_widget().

void Xfc::Gtk::Label::set_mnemonic_widget ( Widget widget  ) 

If the label has been set so that it has an mnemonic key (using the constructor, set_markup_with_mnemonic(), set_text_with_mnemonic(), or the "use_underline" property) the label can be associated with a widget that is the target of the mnemonic.

Parameters:
widget The target Widget.
When the label is inside a widget (like a Button or a Notebook tab) it is automatically associated with the correct widget, but sometimes (i.e. when the target is a Entry next to the label) you need to set it explicitly using this method. The target widget will be accelerated by emitting "mnemonic_activate" on it. The default handler for this signal will activate the widget if there are no mnemonic collisions and toggle focus between the colliding widgets otherwise.

void Xfc::Gtk::Label::set_text_with_mnemonic ( const String str  ) 

Sets the label's text from the string str.

Parameters:
str A string.
If characters in str are preceded by an underscore, they are underlined indicatin that they represent a keyboard accelerator called a mnemonic. The mnemonic key can be used to activate another widget, chosen automatically, or explicitly using set_mnemonic_widget().

void Xfc::Gtk::Label::set_justify ( Justification  jtype  ) 

Sets the alignment of the lines in the text of the label relative to each other.

Parameters:
jtype A Justification. JUSTIFY_LEFT is the default value when the widget is first created. If you instead want to set the alignment of the label as a whole, use Gtk::Misc::set_alignment() instead. set_justify() has no effect on labels containing only a single line.

void Xfc::Gtk::Label::set_ellipsize ( Pango::EllipsizeMode  mode  ) 

Sets the mode used to ellipsize (add an ellipsis: "...") the text if there is not enough space to render the entire string.

Parameters:
mode A Pango::EllipsizeMode.

void Xfc::Gtk::Label::set_width_chars ( int  n_chars  ) 

Sets the desired width in characters of label to n_chars.

Parameters:
n_chars The new desired width, in characters.

void Xfc::Gtk::Label::set_max_width_chars ( int  n_chars  ) 

Sets the desired maximum width in characters of label to n_chars.

Parameters:
n_chars The new desired maximum width, in characters.

void Xfc::Gtk::Label::set_pattern ( const String pattern  ) 

The pattern of underlines you want under the existing text within the Label widget.

Parameters:
pattern The pattern string as described below.
For example, if the current text of the label says "FooBarBaz" passing a pattern of "___ ___" will underline "Foo" and "Baz" but not "Bar".

void Xfc::Gtk::Label::set_line_wrap ( bool  wrap  ) 

Toggles line wrapping within the Label widget.

Parameters:
wrap The setting.
If wrap is true lines are broken if text exceeds the widget's size. If wrap is false the text will get cut off by the edge of the widget if it exceeds the widget size.

void Xfc::Gtk::Label::set_selectable ( bool  setting  ) 

Selectable labels allow the user to select text from the label, for copy-and-paste.

Parameters:
setting true to allow selecting text in the label.

void Xfc::Gtk::Label::select_region ( int  start_offset,
int  end_offset 
)

Selects a range of characters in the label, if the label is selectable (see set_selectable()).

Parameters:
start_offset The start offset (in characters not bytes).
end_offset The end offset (in characters not bytes).
If the label is not selectable, this function has no effect. If start_offset or end_offset are -1, then the end of the label will be substituted.

void Xfc::Gtk::Label::set_use_markup ( bool  setting  ) 

Sets whether the text of the label contains markup in Pango's text markup language (see set_markup()).

Parameters:
setting true if the label's text should be parsed for markup.

void Xfc::Gtk::Label::set_use_underline ( bool  setting  ) 

If setting is true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.

Parameters:
setting true if underlines in the text indicate mnemonics.

void Xfc::Gtk::Label::set_single_line_mode ( bool  single_line_mode  ) 

Sets whether the label is in single line mode.

Parameters:
single_line_mode Set to true if the label should be in single line mode.


Member Data Documentation

const PopulatePopupSignalType Xfc::Gtk::Label::populate_popup_signal [static, protected]

Populate popup signal (see signal_populate_popup()).

Calls a slot with the signature:

< void function(Gtk::Menu& menu);
< // menu: The popup menu.
<


The documentation for this class was generated from the following file: Xfce Foundation Classes
Copyright © 2004-2005 The XFC Development Team XFC 4.3