Пример #1
0
/**
 * clutter_text_buffer_set_max_length:
 * @buffer: a #ClutterTextBuffer
 * @max_length: the maximum length of the entry buffer, or 0 for no maximum.
 *   (other than the maximum length of entries.) The value passed in will
 *   be clamped to the range [ 0, %CLUTTER_TEXT_BUFFER_MAX_SIZE ].
 *
 * Sets the maximum allowed length of the contents of the buffer. If
 * the current contents are longer than the given length, then they
 * will be truncated to fit.
 *
 *
 **/
void
clutter_text_buffer_set_max_length (ClutterTextBuffer *buffer,
                                    gint               max_length)
{
  g_return_if_fail (CLUTTER_IS_TEXT_BUFFER (buffer));

  max_length = CLAMP (max_length, 0, CLUTTER_TEXT_BUFFER_MAX_SIZE);

  if (max_length > 0 && clutter_text_buffer_get_length (buffer) > max_length)
    clutter_text_buffer_delete_text (buffer, max_length, -1);

  buffer->priv->max_length = max_length;
  g_object_notify (G_OBJECT (buffer), "max-length");
}
Пример #2
0
static gboolean
st_im_text_retrieve_surrounding_cb (GtkIMContext *context,
                                    StIMText     *imtext)
{
  ClutterText *clutter_text = CLUTTER_TEXT (imtext);
  ClutterTextBuffer *buffer;
  const gchar *text;
  gint cursor_pos;

  buffer = clutter_text_get_buffer (clutter_text);
  text = clutter_text_buffer_get_text (buffer);

  cursor_pos = clutter_text_get_cursor_position (clutter_text);
  if (cursor_pos < 0)
    cursor_pos = clutter_text_buffer_get_length (buffer);

  gtk_im_context_set_surrounding (context, text,
                                  /* length and cursor_index are in bytes */
                                  clutter_text_buffer_get_bytes (buffer),
                                  g_utf8_offset_to_pointer (text, cursor_pos) - text);

  return TRUE;
}
Пример #3
0
/**
 * clutter_text_buffer_delete_text:
 * @buffer: a #ClutterTextBuffer
 * @position: position at which to delete text
 * @n_chars: number of characters to delete
 *
 * Deletes a sequence of characters from the buffer. @n_chars characters are
 * deleted starting at @position. If @n_chars is negative, then all characters
 * until the end of the text are deleted.
 *
 * If @position or @n_chars are out of bounds, then they are coerced to sane
 * values.
 *
 * Note that the positions are specified in characters, not bytes.
 *
 * Returns: The number of characters deleted.
 *
 *
 */
guint
clutter_text_buffer_delete_text (ClutterTextBuffer *buffer,
                                 guint              position,
                                 gint               n_chars)
{
  ClutterTextBufferClass *klass;
  guint length;

  g_return_val_if_fail (CLUTTER_IS_TEXT_BUFFER (buffer), 0);

  length = clutter_text_buffer_get_length (buffer);
  if (n_chars < 0)
    n_chars = length;
  if (position > length)
    position = length;
  if (position + n_chars > length)
    n_chars = length - position;

  klass = CLUTTER_TEXT_BUFFER_GET_CLASS (buffer);
  g_return_val_if_fail (klass->delete_text != NULL, 0);

  return (klass->delete_text) (buffer, position, n_chars);
}
Пример #4
0
/**
 * clutter_text_buffer_insert_text:
 * @buffer: a #ClutterTextBuffer
 * @position: the position at which to insert text.
 * @chars: the text to insert into the buffer.
 * @n_chars: the length of the text in characters, or -1
 *
 * Inserts @n_chars characters of @chars into the contents of the
 * buffer, at position @position.
 *
 * If @n_chars is negative, then characters from chars will be inserted
 * until a null-terminator is found. If @position or @n_chars are out of
 * bounds, or the maximum buffer text length is exceeded, then they are
 * coerced to sane values.
 *
 * Note that the position and length are in characters, not in bytes.
 *
 * Returns: The number of characters actually inserted.
 *
 *
 */
guint
clutter_text_buffer_insert_text (ClutterTextBuffer *buffer,
                                 guint              position,
                                 const gchar       *chars,
                                 gint               n_chars)
{
  ClutterTextBufferClass *klass;
  ClutterTextBufferPrivate *pv;
  guint length;

  g_return_val_if_fail (CLUTTER_IS_TEXT_BUFFER (buffer), 0);

  length = clutter_text_buffer_get_length (buffer);
  pv = buffer->priv;

  if (n_chars < 0)
    n_chars = g_utf8_strlen (chars, -1);

  /* Bring position into bounds */
  if (position > length)
    position = length;

  /* Make sure not entering too much data */
  if (pv->max_length > 0)
    {
      if (length >= pv->max_length)
        n_chars = 0;
      else if (length + n_chars > pv->max_length)
        n_chars -= (length + n_chars) - pv->max_length;
    }

  klass = CLUTTER_TEXT_BUFFER_GET_CLASS (buffer);
  g_return_val_if_fail (klass->insert_text != NULL, 0);

  return (klass->insert_text) (buffer, position, chars, n_chars);
}
Пример #5
0
static void
clutter_text_buffer_get_property (GObject    *obj,
                                  guint       prop_id,
                                  GValue     *value,
                                  GParamSpec *pspec)
{
  ClutterTextBuffer *buffer = CLUTTER_TEXT_BUFFER (obj);

  switch (prop_id)
    {
    case PROP_TEXT:
      g_value_set_string (value, clutter_text_buffer_get_text (buffer));
      break;
    case PROP_LENGTH:
      g_value_set_uint (value, clutter_text_buffer_get_length (buffer));
      break;
    case PROP_MAX_LENGTH:
      g_value_set_int (value, clutter_text_buffer_get_max_length (buffer));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
      break;
    }
}