Commit Graph

92 Commits

Author SHA1 Message Date
Neil Roberts
9fdc9ca583 [ClutterText] Fix actors with a width but no wrapping and the wrap modes
Setting the wrap mode on the PangoLayout seems to have disappeared
during the text-actor-layout-height branch merge so this brings it
back. The test for this in test-text-cache no longer needs to be
disabled.

We also shouldn't set the width on the layout if there is no wrapping
or ellipsizing because otherwise it implicitly enables wrapping. This
only matters if the actor gets allocated smaller than its natural
size.
2009-04-27 17:43:48 +01:00
Emmanuele Bassi
ffefbe4661 [text] Avoid a Pango warning with empty markup
When the markup string is empty Pango complains about invalid
characters.
2009-04-21 14:08:55 +01:00
Emmanuele Bassi
1c42e6334e [text] Emit ::cursor-event only on changes
The documentation for the ::cursor-event says that the signal
is emitted only when the cursor position changes. Right now it
is being emitted every time we ensure the cursor position during
the Text paint sequence.

The clutter_text_ensure_cursor_position() function should check
whether the stored cursor position has changed since the last
paint, and emit the ::cursor-event signal only when there has
been a change.
2009-04-21 12:11:42 +01:00
Emmanuele Bassi
368f61fa65 [text] Return the correct minimum height
The correct minimum height in case of ellipsis is still 1px.
2009-04-21 12:11:41 +01:00
Emmanuele Bassi
5c8263ecb7 [text] Limit the Layout width
We only want to eschew the pango_layout_set_width() on editable,
single-line Text actors because they can "scroll" the PangoLayout.

This fixes the ellipsization on entries.
2009-04-21 12:11:41 +01:00
Chris Lord
56ac4baf17 [ClutterText] Return 1 for min width when editable
Editable ClutterText will scroll when allocated less width than is
necessary to lay out the entire layout on a single line, so return 1 for
the minimum width in this case.

Approved by Emmanuele Bassi, fixes bug #1555.
2009-04-16 16:34:15 +01:00
Emmanuele Bassi
425fa78a27 Merge branch 'text-actor-layout-height'
* text-actor-layout-height:
  [clutter-text] Fix ellipsizing
  Support pango_layout_set_height() in ClutterText

Conflicts:
	clutter/clutter-text.c
2009-04-15 18:08:14 +01:00
Emmanuele Bassi
f8256e4b23 [text] Do not ellipsize non-editable layouts
If a ClutterText is set as non-editable then its PangoLayout
will occupy as much width as its contents and ignore the
ellipsization setting.
2009-04-15 17:23:45 +01:00
Neil Roberts
fbd9c59c7c [clutter-text] Fix ellipsizing
Ellipsizing was effectively broken for two reasons. There was a typo
in the code to set the width so it always ended up being some massive
value. If no height should be set on the layout it was being set to
G_MAXINT. Setting a height greater than 0 enables wrapping which so
ellipsizing is not performed. It should be left at the default of -1
instead.
2009-04-15 14:46:45 +01:00
Neil Roberts
1edc19d1d3 [clutter-text] Add a separate property for the selection color
Adds a new property so that the selection color can be different from
the cursor color. If no selection color is specified it will use the
cursor color as before. If no cursor color is specified either it will
use the text color.
2009-04-06 15:22:31 +01:00
Raymond Liu
a362a4a889 [text] Use the base class binding pool
Bug 1518 - [Patch] Widget derivied from ClutterText will crash on
           key_press_event

In clutter_text_key_press() we are using G_OBJECT_TYPE_NAME to find
out the actor's type name. However, if some widget is derived from
ClutterText, when the key press handler is called, G_OBJECT_TYPE_NAME
will return the name of the derived widget.

The default implementation should get the binding pool for the base
class.

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2009-03-30 16:57:11 +01:00
Emmanuele Bassi
02ea81ce02 [text] Different selection modes with multiple clicks
ClutterText should offer multiple selection modes depending on the
number of pointer clicks.

Following the GTK+ conventions:

  - double click selects the current word
  - triple click selects the current line
2009-03-30 16:50:26 +01:00
Emmanuele Bassi
a1a8193179 [text] Check text length in ::button-press-event
Bug 1529 - Selection bound out of sync with an empty Text actor

When the user clicks on a Text actor the cursor position and the
selection bound are set using bytes_to_offset(); if the Text is
empty, this means placing them both to 0. Setting the selection
bound to 0 means that when the user inserts a character by typing
it into the Text, the selection will be [0,1]; this will select
the first character, which will then be overwritten when typing
a new character.

The Text actor should, instead, check if there are no contents
and set the cursor position and the selection bound to -1.

The clutter_text_set_selection_bound() method should also validate
the value passed, in case it's bigger than the text lenght, or
smaller than -1.
2009-03-30 07:54:42 +01:00
Emmanuele Bassi
ccca24ab76 Remove usage of the grave accent as quotation mark
See:

  http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html

This should make Thomas happy.
2009-03-17 14:13:31 +00:00
Owen W. Taylor
d88bc30b87 Allow NULL for clutter_text_set_text()
As a convenience, if NULL is passed for the text argument of
clutter_text_set_text() (and for consistency,
clutter_text_set_markup()), treat that the same as "".
2009-03-11 18:20:42 +00:00
Raymond Liu
75e5b805ab [text] Insertion of multi-byte characters broken
Bug 1501 - clutter_text_insert_text not working right with non-onebyte
           character

In clutter_text_insert_text(), the position is expressed in characters, not
in bytes.

Actually, it turns out to be working on bytes, so when there are already
multi-byte character in the text buffer, insert text at the position after
the multi-byte character will not work right.

Also, the position is not updated after the insert work is done.

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2009-03-11 18:00:21 +00:00
Raymond Liu
039e282a40 [text] Crash when multi-byte utf8 text exceeds max_length
Bug 1500 - [Patch] clutter_text crash with non one-byte utf8 text exceed
           max_length

In clutter_text_set_text_internal(), when text length in character is greater
than max_length, and there are multi-byte character in it, then the new text
string buffer is not malloc()'ed with right length. This will cause the app to
crash with segmention fault.

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2009-03-11 17:50:51 +00:00
Emmanuele Bassi
f82c9e7dba [text] Convert units to the right type
The COGL API expects a floating point value, so Units should be
converted to floats, not to ClutterFixed.
2009-03-10 12:38:04 +00:00
Owen W. Taylor
c5afd98416 Add gobject-introspection annotations
Add annotations such as (transfer-none) (out) (element-type ClutterActor),
and so forth to the doc comments as appropriate.

The annotations added here are a combination of the annotations previously
in gir-repository for Clutter and annotations found in a review of all
return values with that were being parsed with a transfer of "full".

http://bugzilla.openedhand.com/show_bug.cgi?id=1452

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2009-02-20 12:09:07 +00:00
Robert Bragg
2b5a72dde5 [Cogl] cogl_clip_{set*,unset} renamed to cogl_clip_{push*,pop}
This is so they self document the stacking semantics of the cogl clip API
2009-02-18 16:00:51 +00:00
Emmanuele Bassi
9cf02bfdb9 [text] Rename :alignment to :line-alignment
The :alignment property is prone to generate confusion: developers
will set it thinking that the contents of a ClutterText will
automagically align themselves.

Instead of using the generic term :alignment, and following the
GTK+ convention, we should use a more specific term, conveying the
actual effect of the property: alignment of the lines with respect
to each other, and not to the overall allocated area.

See bug 1428:

  http://bugzilla.openedhand.com/show_bug.cgi?id=1428
2009-02-05 19:54:48 +00:00
Emmanuele Bassi
2747aa7be2 [text] Use create_pango_layout()
Since we added clutter_actor_get_pango_layout() it would be a
good idea to use it in the ClutterText actor to cut down the
PangoContext-related calls.
2009-02-02 12:07:29 +00:00
Emmanuele Bassi
488de99fc6 [text] Merge the attributes with markup enabled
ClutterText should merge the PangoAttributes set by using
clutter_text_set_attributes() with the attributes generated by
parsing Pango markup.

For this to work we must parse the markup and merge the attributes
we get out of pango_parse_markup() with the attributes set by
the user.

Setting the markup or the attributes on an editable text should
not work for the time being.
2009-02-02 12:07:28 +00:00
Robert Bragg
ef4052c18d Changes cogl_rectangle to take x1, y1, x2, y2 args not x1, y1, width, height
This makes it consistent with cogl_rectangle_with_{multi,}texture_coords.
Notably the reason cogl_rectangle_with_{multi,}texture_coords wasn't changed
instead is that the former approach lets you describe back facing rectangles.
(though technically you could pass negative width/height values to achieve
 this; it doesn't seem as neat.)
2009-01-28 17:20:15 +00:00
Neil Roberts
89b0b00dd1 Listen for the font-changed signal on the backend in ClutterText
Whenever a ClutterText is created it now connects to the font-changed
signal. When it is emitted the layout cache is dirtied and a relayout
is queued. That way changes to the font options or resolution will
cause an immediate update to the labels in the scene.
2009-01-27 17:07:02 +00:00
Neil Roberts
ffc15e0962 [clutter-text] Fix x-position of cursor when moving up or down
ClutterText already has code to try to preserve the x position when
moving up or down. A target x-position is stored and the cursor is
positioned at the nearest point to that in the appropriate line when
up or down is pressed. However the target position was never cleared
so it would always target the x-position of the cursor from the first
time you pressed up or down.

To fix this the patch clears the target position in set_position and
then sets it after the call in real_move_up/down. That way pressing
up or down sets the target position and any other movement will clear
it.

To get an index for the pixel position in the line
pango_layout_line_x_to_index is used. However when x is greater than
the length of the line then the index before the last grapheme is
returned which was causing it to jump to the penultimate
character. The patch makes it add on the trailing value so that it
will jump to the last character.
2009-01-14 11:12:02 +00:00
Neil Roberts
b57c7e12d4 [clutter-text] Fix offset_to_bytes to work when pos == 0
The old function ended up returning the length of the string when pos
was zero. This caused it to insert characters at the end when the
cursor was at the beginning of the string.
2009-01-13 18:42:50 +00:00
Neil Roberts
e93c266647 [clutter-text] Don't allow control characters to be inserted
If an unbound control key is pressed (such as Ctrl+R) it would insert
a rectangle into the text.

Also zero is considered a valid unicode character by
g_unichar_validate so pressing a key such as shift would cause the
current selection to be deleted. The character isn't actually inserted
because insert_unichar disallows zeroes.
2009-01-13 18:17:17 +00:00
Emmanuele Bassi
efd7ad7e55 [text] Fix GObject properties in ClutterText
Some of the read-write properties of ClutterText were missing
an implementation in clutter_text_get_property(), as well as
the :position and :selection-bound properties being wrongly
converted from fixed point to integer, passing through floating
point values.
2009-01-08 17:06:04 +00:00
Emmanuele Bassi
5d5b93bd2a Rename a variable masking index()
The maintainer CFLAGS found another masking of the index() function
by an helpless variable.
2009-01-07 16:41:17 +00:00
Emmanuele Bassi
c1c7131199 [text] Do not use markup on an editable Text
An editable ClutterText should not use pango_layout_set_markup(),
as the contents of the text actor will not match the text.

Only read-only text actors should parse the contents for Pango
markup.
2009-01-07 13:48:45 +00:00
Emmanuele Bassi
368df450b2 [text] Do not ensure the cursor if not needed
If the Text actor is neither editable nor has its cursor set
to visible, then we should not be ensuring the cursor position.

This fixes a failure in the conformance test unit for the
layout cache.
2009-01-07 13:16:11 +00:00
Emmanuele Bassi
c54bd99097 Merge the ClutterText actor
Merge branch 'text-actor'

* text-actor: (108 commits)
  Re-align ClutterText header file
  [text] Fix cursor sizing
  Comments and whitespace fixes to ClutterText
  [docs] Add newly added :single-line-mode accessors
  Update the ignore file
  [tests] Add text field interactive test
  [text] Add single-line-mode to ClutterText
  [text] Fix the deletion actions
  [text] Use cached length when possible
  [tests] Add unit for the ClutterText:password-char property
  [docs] Update the Text section
  [text] Coalesce text visibility and password character
  Allow localizations to change the text direction
  Clean up the update_pango_context() function
  Pass the PangoContext, not the MainContext
  Revert the logic of the PangoContext check
  Remove the binding pool entry from the list
  Remove BindingPool::list_actions()
  Add ClutterActor::create_pango_context()
  Rename the PangoContext creation functions
  ...
2009-01-07 12:06:33 +00:00
Emmanuele Bassi
328534fc95 [text] Fix cursor sizing
The cursor should be slightly smaller than the height of the actor, to
allow for painting a border. Let's pad it by 1 pixel on the top and 1
on the bottom.

Also, we should use the cursor size everywhere and not use hardcoded
magic numbers.
2009-01-07 11:44:54 +00:00
Emmanuele Bassi
f3142a70dc Comments and whitespace fixes to ClutterText 2009-01-07 00:43:24 +00:00
Emmanuele Bassi
43f82332dd [text] Add single-line-mode to ClutterText
Allow using ClutterText as a single line text field. This is useful for
text fields that accept just a single line of contents by default, and
respond to the Enter key press to execute some action.

The :single-line-mode property enables this behaviour inside ClutterText
by clipping and scrolling the contents of the PangoLayout if they do
not fit the allocated width of the Text actor.
2009-01-07 00:25:24 +00:00
Emmanuele Bassi
8182b354b1 [text] Fix the deletion actions
When using the delete-prev action from the end of the text we end
up either missing the first glyph we have to delete or falling
through the last one in the text.

This commit fixes both issues.
2009-01-06 20:54:20 +00:00
Emmanuele Bassi
3d32d464e9 [text] Use cached length when possible
Since clutter_text_set_text() measures the length of the text
each time, we should use the cached length instead of recomputing
the text length each time. This should save us some time when
dealing with long, multi-byte texts.
2009-01-06 20:52:03 +00:00
Emmanuele Bassi
979b6794bb [text] Coalesce text visibility and password character
Using two properties to set a password entry can be construed as
both cumbersome and a gtk-ism. And rightly so on both counts.

The :text-visible property has also conflicting semantics with the
:cursor-visible one: while the latter hides the cursor, the former
changes the display of the contents of the Text actor. It is, thus,
not a matter of "visibility" but of "rendering".

Instead of setting the :text-visible and :invisible-char properties
to have a password text field, the Text actor should just have a
single :password-char property holding a Unicode character. If the
value of the :password-char is non-zero, the Text actor will use the
Unicode character to render the contents of the text entry.

This commit removes the following methods:

  clutter_text_set_text_visible()
  clutter_text_get_text_visible()
  clutter_text_set_invisible_char()
  clutter_text_get_invisible_char()

And the following properties:

  ClutterText:text-visible
  ClutterText:invisible-char

In favour of:

  clutter_text_set_password_char()
  clutter_text_get_password_char()

And:

  ClutterText:password-char

Thus making obvious what use the property and accessor methods are
for and simplifying the process of creating a simple password text
field to:

  text = clutter_text_new ();
  clutter_text_set_password_char (CLUTTER_TEXT (text), '*');
2009-01-06 15:22:31 +00:00
Emmanuele Bassi
33459f63d6 Whitespace fixes 2009-01-05 15:26:57 +00:00
Emmanuele Bassi
55a22d5750 [text] Add select-all binding
Bind Ctrl+A to the "select all" action.
2009-01-05 12:27:45 +00:00
Emmanuele Bassi
e3785f4f45 Use the default font from the Backend
Instead of storing the default font name and size as a pre-processor
macro, use the newly added ClutterBackend API to retrieve the current
default font from the backend.
2008-12-23 15:05:16 +00:00
Emmanuele Bassi
a865a5d4ea Create the PangoContext of the Text actor
Instead of creating a single, private PangoContext for every
Text actor, use the newly added clutter_actor_get_pango_context()
function.
2008-12-23 14:11:27 +00:00
Emmanuele Bassi
b021f518c1 Use "" as the default value for the :text property
This follows the convention of GtkLabel/GtkEntry in GTK+ and the old
ClutterEntry.

It makes it easier to use strlen/strcmp etc on the output, since we can
assume that it is always a string.

This commit also updates the test unit for ClutterText to verify that
the clutter_text_get_text() function also returns an empty string when
a ClutterText actor has been created.
2008-12-22 13:43:41 +00:00
Emmanuele Bassi
4a934c363c Do not include cogl-pango.h multiple times
The clutter-private.h header already includes cogl-pango.h with
the correct inclusion path, because the main context stores a
pointer to the font map.

There is no need for clutter-text.c to include cogl-pango.h
again since it already includes clutter-private.h.
2008-12-22 13:24:52 +00:00
Emmanuele Bassi
6b782ce4e7 Fix the selection behaviour around the 0th glyph
After fixing the cursor position issues around the initial
glyph of the layout, the selection position needs fixing as
well.

The fix is similar: check if the position of the selection
is 0 and provide a fast path by setting the offset to 0.
2008-12-16 15:53:57 +00:00
Emmanuele Bassi
d7ce56bb46 Support pango_layout_set_height() in ClutterText
This is the port of the patch attached to bug 1266:

  ClutterLabel support for pango_layout_set_height()

to the ClutterText actor. This patch adds support for the
pango_layout_set_height() function inside the layout creation
and caching, so that setting the height of a ClutterText will
make PangoLayout try to fill out the given height before
ellipsizing the contents of the ClutterText actor.

The original patch is from Havoc Pennington.

This commit ports the patch to ClutterText and applies a small
change to the height computation pointed out by Behdad Esfahbod
on GNOME's Bugzilla:

  http://bugzilla.gnome.org/show_bug.cgi?id=560931

That the layout heights when doing a size request should be
set to be G_MAXINT instead of -1.

Unfortunately, the patch seems to break the conformance suite
when setting the ellipsization on the layout.
2008-12-16 14:10:41 +00:00
Emmanuele Bassi
a3fbdb5949 Add ClutterText::set_selection()
The clutter_text_set_selection() function is a convenience
method for setting the cursor position and the selection
boundary to a given position in a single call, with sanity
checks for the positions.
2008-12-16 12:41:20 +00:00
Emmanuele Bassi
2209e17432 Fix ClutterText::get_selection()
The clutter_text_get_selection() function was not checking the
passed argument, and was still accessing the contents of the
Text actor using clutter_text_get_text().

This commit also adds the last few gtk-doc annotations missing
from ClutterText.
2008-12-16 12:25:45 +00:00
Emmanuele Bassi
e28fb9ae10 [docs] Add more gtk-doc annotations
Almost reaching full documentation.
2008-12-16 12:25:15 +00:00