Reference Manual
Inti Logo
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Inti::Gtk::Label Class Reference

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

#include <inti/gtk/label.h>

Inheritance diagram for Inti::Gtk::Label:

Inti::Gtk::Misc Inti::Gtk::Widget Inti::Gtk::Object Inti::Atk::Implementor Inti::G::Object Inti::G::TypeInterface Inti::G::TypeInstance Inti::MemoryHandler Inti::G::TypeInstance Inti::ReferencedBase Inti::ReferencedBase Inti::Gtk::AccelLabel List of all members.

Public Member Functions

Constructors
Accessors
Methods
Property Proxies
Signal Proxies

Protected Member Functions

Constructors
Signal Handlers

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, a MenuItem, or an OptionMenu.

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().


Constructor & Destructor Documentation

Inti::Gtk::Label::Label GtkLabel *  label,
bool  reference = false
[explicit, protected]
 

Construct a new Label from an existing GtkLabel.

Parameters:
label A pointer to a GtkLabel.
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).

Inti::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

Pointer<Pango::AttrList> Inti::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 Inti::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.

Pango::Layout* Inti::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 Inti::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.

unsigned int Inti::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* Inti::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.

bool Inti::Gtk::Label::get_selectable  )  const
 

Gets the value set by set_selectable().

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

bool Inti::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.

String Inti::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()).

virtual void Inti::Gtk::Label::on_move_cursor MovementStep  step,
int  count,
bool  extend_selection
[protected, virtual]
 

Called when the cursor is moved using the arrow keys.

Parameters:
step The type of cursor movment.
count The number of characters the cursor moved.
extend_selection true if the current selection is being extended.

A count of -1 indicates that the cursor position is being set after the last character in the label.

virtual void Inti::Gtk::Label::on_populate_popup Menu menu  )  [protected, virtual]
 

Called just before the popup menu is displayed in response the a right-click on a selectable label.

Parameters:
menu The popup menu.

void Inti::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 Inti::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.

The attributes set with this method will be ignored if the "use_underline" property or the "use_markup" property is true.

void Inti::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 Inti::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 Inti::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 Inti::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 Inti::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 Inti::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 Inti::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 Inti::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 Inti::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 Inti::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 Inti::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 Inti::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.


The documentation for this class was generated from the following file: Main Page - Footer


Generated on Sun Sep 14 20:08:16 2003 for Inti by doxygen 1.3.2 written by Dimitri van Heesch, © 1997-2002