Reference Manual

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:

List of all members.

## Public Member Functions

Constructors

- Label ()
    Construct an empty Label.
- Label (const String &str, bool use_underline=false)
    Construct a new Label with str as its text.
- virtual ~Label ()
    Destructor.

Accessors

- GtkLabel * gtk_label () const
    Get a pointer to the GtkLabel structure.
- GtkLabelClass * gtk_label_class () const
    Get a pointer to the GtkLabelClass structure.
- operator GtkLabel * () const
    Conversion operator; safely converts a Label to a GtkLabel pointer.
- String get_text () const
    Fetches the text from a label widget, as displayed on the screen.
- Pointer< Pango::AttrList > get_attributes () const
    Gets the attribute list that was set on the label using set_attributes(), if any.
- String get_label () const
    Fetches the text from a label widget including any embedded underlines indicating mnemonics and Pango markup (see get_text()).
- bool get_use_markup () const
    Returns whether the label's text is interpreted as marked up with the Pango text markup language (see set_use_markup()).
- bool get_use_underline () const
    Returns whether an embedded underline in the label indicates a mnemonic character key (see set_use_underline()).
- unsigned int 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.
- Widget * get_mnemonic_widget () const
    Retrieves the target of the mnemonic (keyboard shortcut) of this label (see set_mnemonic_widget()).
- Justification get_justify () const
    Returns the justification of the label (see set_justify()).
- bool get_line_wrap () const
    Returns whether lines in the label are automatically wrapped (see set_line_wrap()).
- bool get_selectable () const
    Gets the value set by set_selectable().
- void 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.
- bool get_selection_bounds (int *start, int *end) const
    Gets the selected range of characters in the label.
- Pango::Layout * get_layout () const
    Gets the Pango::Layout used to display the label.

Methods

- void set_text (const String &str)
    Sets the text within the Label widget, overwriting any text that was there before.
- void set_attributes (Pango::AttrList &attrs)
    Sets a Pango::AttrList; the attributes in the list are applied to the label text.
- void 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.
- void set_label (const String &str)
    Sets the text of the label.
- void 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.
- void 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.
- void set_text_with_mnemonic (const String &str)
    Sets the label's text from the string str.
- void set_justify (Justification jtype)
    Sets the alignment of the lines in the text of the label relative to each other.
- void set_pattern (const String &pattern)
    The pattern of underlines you want under the existing text within the Label widget.
- void set_line_wrap (bool wrap)
    Toggles line wrapping within the Label widget.
- void set_selectable (bool setting)
    Selectable labels allow the user to select text from the label, for copy-and-paste.
- void select_region (int start_offset, int end_offset)
    Selects a range of characters in the label, if the label is selectable (see set_selectable()).
- void set_use_markup (bool setting)
    Sets whether the text of the label contains markup in Pango's text markup language (see set_markup()).
- void 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.

Property Proxies

- const LabelPropertyProxy prop_label ()
    The text of the label (String : Read / Write).
- const AttributesPropertyProxy prop_attributes ()
    A list of style attributes to apply to the label text (Pointer<Pango::AttrList> : Read / Write).
- const UseMarkupPropertyProxy prop_use_markup ()
    The text of the label includes XML markup (bool : Read / Write). See pango_parse_markup().
- const UseUnderlinePropertyProxy prop_use_underline ()
    If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key (bool : Read / Write).
- const JustifyPropertyProxy prop_justify ()
    Alignment of the lines in the text of the label relative to each other (Justification : Read / Write).
- const PatternPropertyProxy prop_pattern ()
    A string with _ characters in positions corresponding to characters in the text to underline (String : Write).
- const WrapPropertyProxy prop_wrap ()
    If set, wrap lines if the text becomes too wide (bool : Read / Write).
- const SelectablePropertyProxy prop_selectable ()
    Whether the label text can be selected with the mouse (bool : Read / Write).
- const MnemonicKeyvalPropertyProxy prop_mnemonic_keyval ()
    The mnemonic accelerator key for this label (unsigned int : Read).
- const MnemonicWidgetPropertyProxy prop_mnemonic_widget ()
    The widget to be activated when the label's mnemonic key is pressed (Widget* : Read / Write).
- const CursorPositionPropertyProxy prop_cursor_position ()
    The current position of the insertion cursor in chars (int : Read).
- const SelectionBoundPropertyProxy prop_selection_bound ()
    The position of the opposite end of the selection from the cursor in chars (int : Read).

Signal Proxies

- const MoveCursorSignalProxy sig_move_cursor ()
    Connect to the move_cursor_signal; emitted when the cursor is moved using the arrow keys.
- const CopyClipboardSignalProxy sig_copy_clipboard ()
    Connect to the copy_clipboard_signal; emitted when the characters in the current selection are to be copied to the clipboard.
- const PopulatePopupSignalProxy sig_populate_popup ()
    Connect to the populate_popup_signal; emitted just before the popup menu is displayed in response the a right-click on a selectable label.

## Protected Member Functions

Constructors

- Label (GtkLabel *label, bool reference=false)
    Construct a new Label from an existing GtkLabel.

Signal Handlers

- virtual void on_move_cursor (MovementStep step, int count, bool extend_selection)
    Called when the cursor is moved using the arrow keys.
- virtual void on_copy_clipboard ()
    Called when the characters in the current selection are to be copied to the clipboard.
- virtual void on_populate_popup (Menu &menu)
    Called just before the popup menu is displayed in response the a right-click on a selectable label.

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

- label.h

Main Page - Footer