Back to index

im-sdk  12.3.91
Classes | Defines | Typedefs | Functions
imlabel.h File Reference
#include <gdk/gdk.h>
#include <gtk/gtkmisc.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkmenu.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _ImLabel
struct  _ImLabelClass

Defines

#define IM_TYPE_LABEL   (im_label_get_type ())
#define IM_LABEL(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_LABEL, ImLabel))
#define IM_LABEL_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_LABEL, ImLabelClass))
#define IM_IS_LABEL(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_LABEL))
#define IM_IS_LABEL_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_LABEL))
#define IM_LABEL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_LABEL, ImLabelClass))

Typedefs

typedef struct _ImLabel
typedef struct _ImLabelClass
typedef struct _ImLabelSelectionInfo

Functions

GType im_label_get_type (void) G_GNUC_CONST
GtkWidget * im_label_new (const char *str)
void im_label_set_text (ImLabel *label, const char *str)
G_CONST_RETURN gchar * im_label_get_text (ImLabel *label)
 im_label_get_text: : a #ImLabel
void im_label_set_attributes (ImLabel *label, PangoAttrList *attrs)
 im_label_set_attributes: : a #ImLabel : a #PangoAttrList
PangoAttrList * im_label_get_attributes (ImLabel *label)
 im_label_get_attributes: : a #ImLabel
void im_label_set_label (ImLabel *label, const gchar *str)
 im_label_set_label: : a #ImLabel : the new text to set for the label
G_CONST_RETURN gchar * im_label_get_label (ImLabel *label)
 im_label_get_label: : a #ImLabel
void im_label_set_markup (ImLabel *label, const gchar *str)
 im_label_set_markup: : a #ImLabel : a markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)
void im_label_set_use_markup (ImLabel *label, gboolean setting)
gboolean im_label_get_use_markup (ImLabel *label)
void im_label_set_justify (ImLabel *label, GtkJustification jtype)
 im_label_set_justify: : a #ImLabel : a #GtkJustification
GtkJustification im_label_get_justify (ImLabel *label)
 im_label_get_justify: : a #ImLabel
void im_label_set_pattern (ImLabel *label, const gchar *pattern)
void im_label_set_selectable (ImLabel *label, gboolean setting)
 im_label_set_selectable: : a #ImLabel : TRUE to allow selecting text in the label
gboolean im_label_get_selectable (ImLabel *label)
 im_label_get_selectable: : a #ImLabel
void im_label_select_region (ImLabel *label, gint start_offset, gint end_offset)
 im_label_select_region: : a #ImLabel : start offset (in characters not bytes) : end offset (in characters not bytes)
gboolean im_label_get_selection_bounds (ImLabel *label, gint *start, gint *end)
 im_label_get_selection_bounds: : a #ImLabel : return location for start of selection, as a character offset : return location for end of selection, as a character offset
gint im_label_get_text_length (ImLabel *label)
void im_label_set_caret_index (ImLabel *label, gint caret)
PangoLayout * im_label_get_layout (ImLabel *label)
 im_label_get_layout: : a #ImLabel
void im_label_get_layout_offsets (ImLabel *label, gint *x, gint *y)
 im_label_get_layout_offsets: : a #ImLabel : location to store X offset of layout, or NULL : location to store Y offset of layout, or NULL
void im_label_get_caret_rect (ImLabel *label, int idx, int *px, int *py, int *pw, int *ph)

Class Documentation

struct _ImLabel

Definition at line 56 of file imlabel.h.

Class Members
PangoAttrList * attrs
gint caret_index
gint delay_hide_caret
PangoAttrList * effective_attrs
guint jtype: 2
gchar * label
PangoLayout * layout
GtkMisc misc
ImLabelSelectionInfo * select_info
gint showing_caret
gchar * text
gint timer_id
guint use_markup: 1

Define Documentation

#define IM_IS_LABEL (   obj)    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_LABEL))

Definition at line 46 of file imlabel.h.

#define IM_IS_LABEL_CLASS (   klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_LABEL))

Definition at line 47 of file imlabel.h.

#define IM_LABEL (   obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_LABEL, ImLabel))

Definition at line 44 of file imlabel.h.

#define IM_LABEL_CLASS (   klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_LABEL, ImLabelClass))

Definition at line 45 of file imlabel.h.

#define IM_LABEL_GET_CLASS (   obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_LABEL, ImLabelClass))

Definition at line 48 of file imlabel.h.

#define IM_TYPE_LABEL   (im_label_get_type ())

Definition at line 43 of file imlabel.h.


Typedef Documentation

typedef struct _ImLabel

Definition at line 51 of file imlabel.h.

typedef struct _ImLabelClass

Definition at line 52 of file imlabel.h.

typedef struct _ImLabelSelectionInfo

Definition at line 54 of file imlabel.h.


Function Documentation

PangoAttrList* im_label_get_attributes ( ImLabel *  label)

im_label_get_attributes: : a #ImLabel

Gets the attribute list that was set on the label using im_label_set_attributes(), if any. This function does not reflect attributes that come from the labels markup (see im_label_set_markup()). If you want to get the effective attributes for the label, use pango_layout_get_attribute (im_label_get_layout (label)).

Return value: the attribute list, or NULL if none was set.

Definition at line 618 of file imlabel.c.

{
  g_return_val_if_fail (IM_IS_LABEL (label), NULL);

  return label->attrs;
}
void im_label_get_caret_rect ( ImLabel *  label,
int  idx,
int *  px,
int *  py,
int *  pw,
int *  ph 
)

Definition at line 1151 of file imlabel.c.

{
    if (GTK_WIDGET_DRAWABLE (label)) {
        GtkWidget *widget = GTK_WIDGET (label);

        gint  len = im_label_get_text_length(label);
        if (idx < 0) idx = 0;
        if (idx > len) idx = len;

        if (idx >= 0)
            idx = g_utf8_offset_to_pointer (label->text, idx) - label->text;

        GtkTextDirection keymap_direction;
        GtkTextDirection widget_direction;
        PangoRectangle strong_pos, weak_pos;
        gboolean split_cursor;
        PangoRectangle *cursor1 = NULL;
        PangoRectangle *cursor2 = NULL;
        GdkRectangle cursor_location;
        GtkTextDirection dir1 = GTK_TEXT_DIR_NONE;
        GtkTextDirection dir2 = GTK_TEXT_DIR_NONE;
        GdkGC *gc;


        keymap_direction = GTK_TEXT_DIR_RTL;
        if (gdk_keymap_get_direction(gdk_keymap_get_for_display(gtk_widget_get_display (widget))) == PANGO_DIRECTION_LTR)
            keymap_direction = GTK_TEXT_DIR_LTR;

        widget_direction = gtk_widget_get_direction (widget);
        im_label_ensure_layout (label);

        //pango_layout_get_cursor_pos (label->layout, label->select_info->selection_end, &strong_pos, &weak_pos);
        pango_layout_get_cursor_pos (label->layout, idx, &strong_pos, &weak_pos);

        g_object_get (gtk_widget_get_settings (widget), "gtk-split-cursor", &split_cursor, NULL);

        dir1 = widget_direction;

        if (split_cursor) {
            cursor1 = &strong_pos;

            if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y) {
                dir2 = (widget_direction == GTK_TEXT_DIR_LTR) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR;
                cursor2 = &weak_pos;
            }

        } else {
            if (keymap_direction == widget_direction)
              cursor1 = &strong_pos;
            else
              cursor1 = &weak_pos;
        }

        *px = PANGO_PIXELS (cursor1->x);
        *py = PANGO_PIXELS (cursor1->y);
        *pw = 2;
        *ph = PANGO_PIXELS (cursor1->height);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

GtkJustification im_label_get_justify ( ImLabel *  label)

im_label_get_justify: : a #ImLabel

Returns the justification of the label. See im_label_set_justify ().

Return value: #GtkJustification

Definition at line 842 of file imlabel.c.

{
  g_return_val_if_fail (IM_IS_LABEL (label), 0);

  return label->jtype;
}
G_CONST_RETURN gchar* im_label_get_label ( ImLabel *  label)

im_label_get_label: : a #ImLabel

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

Return value: the text of the label widget. This string is owned by the widget and must not be modified or freed.

Definition at line 657 of file imlabel.c.

{
  g_return_val_if_fail (IM_IS_LABEL (label), NULL);

  return label->label;
}
PangoLayout* im_label_get_layout ( ImLabel *  label)

im_label_get_layout: : a #ImLabel

Gets the #PangoLayout used to display the label. The layout is useful to e.g. convert text positions to pixel positions, in combination with im_label_get_layout_offsets(). The returned layout is owned by the label so need not be freed by the caller.

Return value: the #PangoLayout for this label

Definition at line 1985 of file imlabel.c.

{
  g_return_val_if_fail (IM_IS_LABEL (label), NULL);

  im_label_ensure_layout (label);

  return label->layout;
}

Here is the call graph for this function:

void im_label_get_layout_offsets ( ImLabel *  label,
gint *  x,
gint *  y 
)

im_label_get_layout_offsets: : a #ImLabel : location to store X offset of layout, or NULL : location to store Y offset of layout, or NULL

Obtains the coordinates where the label will draw the #PangoLayout representing the text in the label; useful to convert mouse events into coordinates inside the #PangoLayout, e.g. to take some action if some part of the label is clicked. Of course you will need to create a #GtkEventBox to receive the events, and pack the label inside it, since labels are a #GTK_NO_WINDOW widget. Remember when using the #PangoLayout functions you need to convert to and from pixels using PANGO_PIXELS() or #PANGO_SCALE.

Definition at line 2011 of file imlabel.c.

{
  g_return_if_fail (IM_IS_LABEL (label));
  get_layout_location (label, x, y);
}

Here is the call graph for this function:

gboolean im_label_get_selectable ( ImLabel *  label)

im_label_get_selectable: : a #ImLabel

Gets the value set by im_label_set_selectable().

Return value: TRUE if the user can copy text from the label

Definition at line 1760 of file imlabel.c.

{
  g_return_val_if_fail (IM_IS_LABEL (label), FALSE);

  return label->select_info != NULL;
}

Here is the caller graph for this function:

gboolean im_label_get_selection_bounds ( ImLabel *  label,
gint *  start,
gint *  end 
)

im_label_get_selection_bounds: : a #ImLabel : return location for start of selection, as a character offset : return location for end of selection, as a character offset

Gets the selected range of characters in the label, returning TRUE if there's a selection.

Return value: TRUE if selection is non-empty

Definition at line 1916 of file imlabel.c.

{
  g_return_val_if_fail (IM_IS_LABEL (label), FALSE);

  if (label->select_info == NULL)
    {
      /* not a selectable label */
      if (start)
        *start = 0;
      if (end)
        *end = 0;

      return FALSE;
    }
  else
    {
      gint start_index, end_index;
      gint start_offset, end_offset;
      gint len;

      start_index = MIN (label->select_info->selection_anchor,
                   label->select_info->selection_end);
      end_index = MAX (label->select_info->selection_anchor,
                 label->select_info->selection_end);

      len = strlen (label->text);

      if (end_index > len)
        end_index = len;

      if (start_index > len)
        start_index = len;

      start_offset = g_utf8_strlen (label->text, start_index);
      end_offset = g_utf8_strlen (label->text, end_index);

      if (start_offset > end_offset)
        {
          gint tmp = start_offset;
          start_offset = end_offset;
          end_offset = tmp;
        }

      if (start)
        *start = start_offset;

      if (end)
        *end = end_offset;

      return start_offset != end_offset;
    }
}
G_CONST_RETURN gchar* im_label_get_text ( ImLabel *  label)

im_label_get_text: : a #ImLabel

Fetches the text from a label widget, as displayed on the screen. This does not include any embedded underlines indicating mnemonics or Pango markup. (See im_label_get_label())

Return value: the text in the label widget. This is the internal string used by the label, and must not be modified.

Definition at line 728 of file imlabel.c.

{
  g_return_val_if_fail (IM_IS_LABEL (label), NULL);

  return label->text;
}
gint im_label_get_text_length ( ImLabel *  label)

Definition at line 2199 of file imlabel.c.

{
    if (label->text) {
        return g_utf8_strlen (label->text, -1);
    }
    return 0;
}

Here is the caller graph for this function:

GType im_label_get_type ( void  )

Definition at line 138 of file imlabel.c.

{
  static GType label_type = 0;

  if (!label_type)
    {
      static const GTypeInfo label_info =
      {
        sizeof (ImLabelClass),
        NULL,           /* base_init */
        NULL,           /* base_finalize */
        (GClassInitFunc) im_label_class_init,
        NULL,           /* class_finalize */
        NULL,           /* class_data */
        sizeof (ImLabel),
        32,             /* n_preallocs */
        (GInstanceInitFunc) im_label_init,
      };

      label_type = g_type_register_static (GTK_TYPE_MISC, "ImLabel",
                                           &label_info, 0);
    }

  return label_type;
}

Here is the call graph for this function:

gboolean im_label_get_use_markup ( ImLabel *  label)
GtkWidget* im_label_new ( const char *  str)
void im_label_select_region ( ImLabel *  label,
gint  start_offset,
gint  end_offset 
)

im_label_select_region: : a #ImLabel : start offset (in characters not bytes) : end offset (in characters not bytes)

Selects a range of characters in the label, if the label is selectable. See im_label_set_selectable(). If the label is not selectable, this function has no effect. If or are -1, then the end of the label will be substituted.

Definition at line 1884 of file imlabel.c.

{
  g_return_if_fail (IM_IS_LABEL (label));

  if (label->text && label->select_info)
    {
      if (start_offset < 0)
        start_offset = g_utf8_strlen (label->text, -1);

      if (end_offset < 0)
        end_offset = g_utf8_strlen (label->text, -1);

      im_label_select_region_index (label,
                                     g_utf8_offset_to_pointer (label->text, start_offset) - label->text,
                                     g_utf8_offset_to_pointer (label->text, end_offset) - label->text);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void im_label_set_attributes ( ImLabel *  label,
PangoAttrList *  attrs 
)

im_label_set_attributes: : a #ImLabel : a #PangoAttrList

Sets a #PangoAttrList; the attributes in the list are applied to the label text. The attributes set with this function will be ignored if the "use_underline" property or the "use_markup" property is TRUE.

Definition at line 593 of file imlabel.c.

{
  g_return_if_fail (IM_IS_LABEL (label));

  im_label_set_attributes_internal (label, attrs);

  im_label_clear_layout (label);
  gtk_widget_queue_resize (GTK_WIDGET (label));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void im_label_set_caret_index ( ImLabel *  label,
gint  caret 
)

Definition at line 292 of file imlabel.c.

{
    g_return_if_fail (IM_IS_LABEL (label));
    
    gint  len = im_label_get_text_length(label);
    if (caret < 0) caret = 0;
    if (caret > len) caret = len;

    if (caret >= 0)
        caret = g_utf8_offset_to_pointer (label->text, caret) - label->text;

    if (label->caret_index == caret)
        return;

    label->caret_index = caret;
    label->showing_caret = label->delay_hide_caret = 1;
    gtk_widget_queue_draw(GTK_WIDGET (label));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void im_label_set_justify ( ImLabel *  label,
GtkJustification  jtype 
)

im_label_set_justify: : a #ImLabel : a #GtkJustification

Sets the alignment of the lines in the text of the label relative to each other. GTK_JUSTIFY_LEFT is the default value when the widget is first created with im_label_new(). If you instead want to set the alignment of the label as a whole, use gtk_misc_set_alignment() instead. im_label_set_justify() has no effect on labels containing only a single line.

Definition at line 815 of file imlabel.c.

{
  g_return_if_fail (IM_IS_LABEL (label));
  g_return_if_fail (jtype >= GTK_JUSTIFY_LEFT && jtype <= GTK_JUSTIFY_FILL);

  if ((GtkJustification) label->jtype != jtype)
    {
      label->jtype = jtype;

      /* No real need to be this drastic, but easier than duplicating the code */
      im_label_clear_layout (label);

      g_object_notify (G_OBJECT (label), "justify");
      gtk_widget_queue_resize (GTK_WIDGET (label));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void im_label_set_label ( ImLabel *  label,
const gchar *  str 
)

im_label_set_label: : a #ImLabel : the new text to set for the label

Sets the text of the label. The label is interpreted as including embedded underlines and/or Pango markup depending on the values of label->use_underline and label->use_markup.

Definition at line 635 of file imlabel.c.

{
  g_return_if_fail (IM_IS_LABEL (label));
  g_return_if_fail (str != NULL);

  im_label_set_label_internal (label, g_strdup (str));
  im_label_recalculate (label);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void im_label_set_markup ( ImLabel *  label,
const gchar *  str 
)

im_label_set_markup: : a #ImLabel : a markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)

Parses which is marked up with the <link linkend="PangoMarkupFormat">Pango text markup language</link>, setting the label's text and attribute list based on the parse results.

Definition at line 708 of file imlabel.c.

{
  g_return_if_fail (IM_IS_LABEL (label));

  im_label_set_label_internal (label, g_strdup (str ? str : ""));
  im_label_recalculate (label);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void im_label_set_pattern ( ImLabel *  label,
const gchar *  pattern 
)

Definition at line 790 of file imlabel.c.

{
  g_return_if_fail (IM_IS_LABEL (label));

  im_label_set_pattern_internal (label, pattern);

  im_label_clear_layout (label);
  gtk_widget_queue_resize (GTK_WIDGET (label));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void im_label_set_selectable ( ImLabel *  label,
gboolean  setting 
)

im_label_set_selectable: : a #ImLabel : TRUE to allow selecting text in the label

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

Definition at line 1696 of file imlabel.c.

{
  gboolean old_setting;

  g_return_if_fail (IM_IS_LABEL (label));

  setting = setting != FALSE;
  old_setting = label->select_info != NULL;

  if (setting)
    {
      if (label->select_info == NULL)
        {
          label->select_info = g_new0 (ImLabelSelectionInfo, 1);

          GTK_WIDGET_SET_FLAGS (label, GTK_CAN_FOCUS);

          if (GTK_WIDGET_REALIZED (label))
            im_label_create_window (label);

          if (GTK_WIDGET_MAPPED (label))
            gdk_window_show (label->select_info->window);
        }
    }
  else
    {
      if (label->select_info)
        {
          /* unselect, to give up the selection */
          im_label_select_region (label, 0, 0);

          if (label->select_info->window)
            {
              im_label_destroy_window (label);
            }

          g_free (label->select_info);

          label->select_info = NULL;

          GTK_WIDGET_UNSET_FLAGS (label, GTK_CAN_FOCUS);
        }
    }
  if (setting != old_setting)
    {
      g_object_freeze_notify (G_OBJECT (label));
      g_object_notify (G_OBJECT (label), "selectable");
      g_object_notify (G_OBJECT (label), "cursor_position");
      g_object_notify (G_OBJECT (label), "selection_bound");
      g_object_thaw_notify (G_OBJECT (label));
      gtk_widget_queue_draw (GTK_WIDGET (label));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void im_label_set_text ( ImLabel *  label,
const char *  str 
)
void im_label_set_use_markup ( ImLabel *  label,
gboolean  setting 
)