Commit Graph

138 Commits

Author SHA1 Message Date
Emmanuele Bassi
7ebb9ff6b7 Allow selecting with line-start and line-end bindings
Instead of installing the line-start and line-end key bindings
using the bare ClutterBindingPool API, we can use the internal
clutter_text_add_move_binding(), which automatically installs
the same key binding with the Shift modifier mask.

This allows selecting when pressing Shift+Home or Shift+End.

The selection behaviour is still incorrect around the zeroeth
position, with all the text after the first line being selected.
2008-12-16 10:39:52 +00:00
Emmanuele Bassi
ea5a6abd9d Add :cursor-size property to ClutterText
We can control the width of the cursor when painting by using
a simple property.

The magic -1 number passed to the setter method will reset the
cursor size to the default one of 2px.

The getter method will return an unsigned integer with the
current size.
2008-12-16 10:37:45 +00:00
Emmanuele Bassi
ffb500d3a6 Remove unused page up/down key bindings
Moving the text by a "page" depends on being able to define a
"page size" in terms of lines of text. Since we don't define
something similar to an Adjustment that allows us to handle this
behaviour, we should defer the paging implementation to a higher
level class based on ClutterText.
2008-12-16 10:19:56 +00:00
Emmanuele Bassi
dc49dab350 Fix line start and line end key binding behaviour
Another fix for the key navigation behaviour around the zeroeth
glyph in the layout.

This commit adds a fast path for for the zero index when the
cursor position is set as zero, in case we are using the line-start
or line-end key bindings, similarly to what we did in commit
be64cbcdc2 for the move-up and
move-down bindings.
2008-12-16 10:15:57 +00:00
Emmanuele Bassi
be64cbcdc2 Fix up/down key navigation
The behaviour of ClutterText around the initial position is still
a little bit erratic.

This commit fixes the key navigation with Up and Down arrows around
the first line of text.
2008-12-15 18:46:08 +00:00
Emmanuele Bassi
e615b8cc6b Use units in position_to_coords()
We loose precision with a direct conversion for PangoUnits to
pixels, so we should do the conversion as needed, inside the
callers of clutter_text_position_to_coords().
2008-12-15 18:24:42 +00:00
Emmanuele Bassi
a50dfefbc3 Fix documentation issues
Provide a description for the ClutterText section, and fix some
misnamed arguments inside the header file.
2008-12-11 15:00:22 +00:00
Emmanuele Bassi
0ac1590378 Lazily create the PangoContext on Text::init
If we create the PangoContext for ClutterText inside the class
initialization we might not have a Clutter main context yet.

Ideally, we should store the Pango context inside the main context
and create it on clutter_init(), but for now we can lazily create
the PangoContext when we initialize a ClutterText instance for the
first time.
2008-12-11 14:57:46 +00:00
Emmanuele Bassi
786bc4d4d5 Allow only synthetic events with keyval 0
We allow KeyEvents with a key symbol of '0' to fall through only
if they are marked as synthetic. Otherwise we discard them without
mercy.

Synthetic events are useful to test ClutterText behaviour; in fact,
we do use them inside the test suite exactly for that reason.
2008-12-11 12:24:45 +00:00
Emmanuele Bassi
77b3b9d5f4 Do not use contractions when not needed
I understand we are not Pascal developers, and we don't have to
use cute and cuddly names like "i_am_an_integer_counter", but
a ClutterButtonEvent should be stored inside an "event" variable.
Using "bev" instead? Mmmh, not so much.
2008-12-11 12:21:57 +00:00
Emmanuele Bassi
2ca7cb46f9 Use the paint opacity when painting a ClutterText
ClutterText should use the paint opacity for both text and
cursor.

ClutterLabel had the wrong behaviour, as it set the actor's
opacity using the text color's alpha channel, and ClutterEntry
completely disregarded the actor's opacity when painting the
cursor.

This commit harmonizes the ClutterText behaviour to always
use a composition of the actor's paint opacity and the text
and cursor alpha channel values, thus behaving more
consistently with the rest of Clutter.
2008-12-11 12:18:26 +00:00
Emmanuele Bassi
e9c369f86d Add documentation annotations
ClutterText is heavily under-documented. This commit ports most of
the API documentation from ClutterLabel and ClutterEntry to
ClutterText.
2008-12-11 12:17:11 +00:00
Emmanuele Bassi
cfb6022831 Code style fixes
Fix the arguments alignment whenever not consistent with the
coding style rules.
2008-12-11 12:15:49 +00:00
Emmanuele Bassi
7a93bcb64e Remove unused types
Since ClutterText now uses ClutterBindingPool there is no more
need for the internal key mapping types.
2008-12-11 12:14:53 +00:00
Emmanuele Bassi
f13e00b411 Truncate selections on text insertion
When inserting text on a key press event we should also truncate
the selection.

We should not truncate the selection when inserting any Unicode
character, since changing the selection also changes the cursor
position - and one of the invariants we inherited from ClutterEntry
is that inserting characters programmatically does not change the
cursor position.
2008-12-11 12:10:46 +00:00
Emmanuele Bassi
35172a7615 Change the binding propagation when truncating a selection
If a selection has been truncated inside a key binding handler,
we should just return and let the usual key event handler continue.

This fixes the case where we deleted a selection using the Delete
or the Backspace keys.
2008-12-11 12:08:20 +00:00
Emmanuele Bassi
eae98800d2 Use ClutterBindPool inside ClutterText
ClutterText should use the newly added ClutterBindingPool API to
handle key events, instead of its homegrown code.

This commit removes the action/mapping code and defers the entire
key binding matching to a ClutterBindingPool created inside the
Text class initialization function.
2008-12-11 12:03:17 +00:00
Emmanuele Bassi
b1c366a143 Add Text::get_chars() implementation and tests
The clutter_text_get_chars() function returns a section of the
contents of the Text actor, delimited by a start and an end position.

This commit adds the implementation for that function and a test
unit that guarantees the offset-to-bytes computations are correct.
2008-12-11 11:59:50 +00:00
Emmanuele Bassi
2fedd3263c Do not namespace internal data structures
Since the internal data structures are not exported (duh!), we
can eschew the namespacing and save us some characters.
2008-12-11 11:57:46 +00:00
Emmanuele Bassi
4a1f4d6f9a Move internal data structures on top
Try to keep the declarations section of the source files clean and
possibly consistent.
2008-12-11 11:55:39 +00:00
Emmanuele Bassi
d84a88ac3b Coding style consistency
Channel mitch's spirit.

This is also how I get to have the highest commit count on Clutter's
repository.
2008-12-11 11:54:32 +00:00
Emmanuele Bassi
d10f7127a2 Implement Text:max-length
The :max-length property establishes the maximum available
length for the Text actor's contents, in characters.
2008-12-11 11:54:07 +00:00
Emmanuele Bassi
1ff02f570e Use the stored contents length in ::delete_chars()
Instead of recomputing it, we can reuse the contents length we
compute and store inside clutter_text_set_text().
2008-12-11 11:50:02 +00:00
Emmanuele Bassi
4cc57bdc41 Improve the safety checks inside the text setters
We should check that the contents of the Text actor are
not NULL when computing the offsets in bytes.
2008-12-11 11:49:45 +00:00
Emmanuele Bassi
c72722df8c Add :cursor-color-set property declaration
The :cursor-color-set property is a read-only property that
reflects whether the ClutterText actor is going to use the
color set inside the :cursor-color property when painting
the cursor.
2008-12-11 11:49:14 +00:00
Emmanuele Bassi
bdb0cc462d General whitespace fixes in ClutterText
Let's keep whitespace fixes to their own commit to avoid
polluting git-blame.
2008-12-11 11:48:17 +00:00
Emmanuele Bassi
7fa93ebe9e Replace offset_to_bytes() implementation
We should re-use the offset_to_bytes() implementation from ClutterEntry
as it guaranteed some behaviour and sanity checks that we want to keep
inside ClutterText.
2008-12-11 11:47:06 +00:00
Emmanuele Bassi
9169dff794 Add text editing methods
Port the text editing methods from ClutterEntry, so that
ClutterText exposes the same API.
2008-12-11 11:43:56 +00:00
Emmanuele Bassi
74257dfa27 Add missing basic constructor
ClutterText should have an empty constructor, mostly for
bindings to use, that just proxies call to g_object_new()
without setting any property.
2008-12-11 11:43:37 +00:00
Emmanuele Bassi
7af992974e Initialize the cursor position
By default, the cursor position is initialized to -1, meaning
"place the cursor always at the end of the text".
2008-12-11 11:42:33 +00:00
Emmanuele Bassi
d5df1bebcf Add text-visibility accessors for ClutterText
A ClutterText can be put in "password mode" by setting the
text as "invisible": every character inside the Text actor's
contents will be replaced when building the Pango layout with
a specific Unicode character.

The Unicode character is set to '*' by default, but the user
can be changed using the provided API.
2008-12-11 11:40:55 +00:00
Emmanuele Bassi
97cf7e6819 Correctly initialize the initial state of ClutterText
Some of the values in ClutterText have an initial state that
does not match a zero-ed out ClutterTextPrivate structure.
2008-12-11 11:35:52 +00:00
Emmanuele Bassi
fc168a3482 Merge the ClutterLabel properties into ClutterText
ClutterText should have the same properties as ClutterLabel.

While at it, we can finally fix the disconnect between the wrap
and wrap-mode properties and its accessors, that we perpetuated
from GtkLabel.

The ClutterText:line-wrap property and ClutterText:line-wrap-mode
are mapped to the set_line_wrap(), get_line_wrap() and
set_line_wrap_mode(), get_line_wrap_mode() accessor functions
respectively. This should simplify bindings the Vala ones that
map a property into a method.
2008-12-11 11:33:10 +00:00
Emmanuele Bassi
437f96982e Expose the Text accessors as public API
Fix up the header to expose ClutterText accessors for the main
properties, matching ClutterLabel.
2008-12-11 11:20:14 +00:00
Emmanuele Bassi
4d62da80ad Coalesce ClutterLabel API usage
ClutterText replaces ClutterLabel, so it should expose the same
kind of API - ideally with the minimal amount of changes, so that
the porting is trivial.
2008-12-11 11:17:26 +00:00
Emmanuele Bassi
a91bb5450f Group all the integer private fields
Integer fields using the ": <bits>" notation should be packed
together so that the compiler can optimize the structure size
correctly.
2008-12-11 11:15:56 +00:00
Emmanuele Bassi
f9bf187e5d Use internal headers
Since ClutterText is part of Clutter, it can use the internal
and private headers instead of the catch-all clutter.h.
2008-12-11 11:15:11 +00:00
Emmanuele Bassi
a98720ae19 Initial import of the Text actor from Tidy
The TidyText actor is meant as a replacement for both ClutterLabel
and ClutterText.

Any text-displaying and editing actor should derive from ClutterText
and implement the various visual cues to differentiate the editable
from the non-editable state. Those visual cues usually belong to
a high-level toolkit, especially if themeing is involved.
2008-12-11 11:12:48 +00:00