Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Maemo: Developers

Word completion in Fremantle

 

 

Maemo developers RSS feed   Index | Next | Previous | View Threaded


hald at icandy

Nov 6, 2009, 11:11 AM

Post #1 of 6 (599 views)
Permalink
Word completion in Fremantle

Hi,

I need to know whether or not a word suggestion[1] is currently
displayed inside a HildonTextView. Even better it would be if I could
access the content of this suggestion. Is that somehow possible?

Could someone explain how the suggestion is added to the text view? I
can't find any signals that get fired, but somehow the text is part of
the text view, I mean, for example, text on the right side of the
suggestion is correctly moved to the right, text wrapping is working
etc...

It would be great if someone could explain this black magic to me. What
I'm trying to do is to apply a certain text style/formatting onto the
suggestion to make it look consistent with the rest of the text.

Thanks!
Conny


[1] the selected text on the right side of the cursor, that can be
accepted by pressing the right cursor key.


_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers


femorandeira at igalia

Nov 6, 2009, 11:43 AM

Post #2 of 6 (565 views)
Permalink
Re: Word completion in Fremantle [In reply to]

Hi,

take a look at set_preedit_buffer() in HildonIMContext:

https://stage.maemo.org/svn/maemo/projects/haf/trunk/hildon-input-method-framework/src/hildon-im-context.c

In a nutshell, the preedit text is set by emitting the "preedit-changed"
signal in the HildonIMContext (which extends GtkIMContext). You could
probably try to get a reference to the context and then either listen to
this signal or use gtk_im_context_get_preedit_string().

static void
set_preedit_buffer (HildonIMContext *self, const gchar* s)
{
[...]

if (s != NULL)
{
[...]

self->show_preedit = TRUE;
g_signal_emit_by_name(self,
"preedit-changed",
self->preedit_buffer->str);

[...]
}
else
{
self->show_preedit = FALSE;

if (self->preedit_buffer != NULL && self->preedit_buffer->len != 0)
{
g_string_truncate(self->preedit_buffer, 0);
g_signal_emit_by_name(self,
"preedit-changed",
self->preedit_buffer->str);
}
}
}



Cornelius Hald wrote:
> Hi,
>
> I need to know whether or not a word suggestion[1] is currently
> displayed inside a HildonTextView. Even better it would be if I could
> access the content of this suggestion. Is that somehow possible?
>
> Could someone explain how the suggestion is added to the text view? I
> can't find any signals that get fired, but somehow the text is part of
> the text view, I mean, for example, text on the right side of the
> suggestion is correctly moved to the right, text wrapping is working
> etc...
>
> It would be great if someone could explain this black magic to me. What
> I'm trying to do is to apply a certain text style/formatting onto the
> suggestion to make it look consistent with the rest of the text.
>
> Thanks!
> Conny
>
>
> [1] the selected text on the right side of the cursor, that can be
> accepted by pressing the right cursor key.
>
>
> _______________________________________________
> maemo-developers mailing list
> maemo-developers [at] maemo
> https://lists.maemo.org/mailman/listinfo/maemo-developers
>
Attachments: signature.asc (0.19 KB)


hald at icandy

Nov 7, 2009, 8:11 AM

Post #3 of 6 (535 views)
Permalink
Re: Word completion in Fremantle [In reply to]

Hi Felipe,

your information helped me a lot to understand what's going on behind
the scene, so it's not black magic anymore ;)

Unfortunately I see no way of getting an instance of HildonIMContext or
GtkIMContext. I checked GdkWindow, GtkWidget, GtkTextBuffer and
GtkTextView, but non of them let me retrieve the IMContext.
To me it looks like the IMContext knows the text widget, but not the
other way around. Do you know a way to get the IMContext?

I also checked where the "preedit-changed" signal is handled and
followed this back to GtkTextView and GtkLayout but found no way of
intercepting it.

Also there is a GtkTextMark called "preedit" used and I can listen to
changes of this mark, but unfortunately this does not give me enough
information.

I think I really need that HildonIMContext instance. It would be great
if you have an idea how to get it.

Thanks a lot!
Conny

P.S. Maybe I could use a signal emission hook to intercept the
"preedit-changed" signal. Not sure, but it could work. I'll give it a
try...


On Fri, 2009-11-06 at 19:43 +0000, Felipe Erias Morandeira wrote:
> Hi,
>
> take a look at set_preedit_buffer() in HildonIMContext:
>
> https://stage.maemo.org/svn/maemo/projects/haf/trunk/hildon-input-method-framework/src/hildon-im-context.c
>
> In a nutshell, the preedit text is set by emitting the "preedit-changed"
> signal in the HildonIMContext (which extends GtkIMContext). You could
> probably try to get a reference to the context and then either listen to
> this signal or use gtk_im_context_get_preedit_string().
>
> static void
> set_preedit_buffer (HildonIMContext *self, const gchar* s)
> {
> [...]
>
> if (s != NULL)
> {
> [...]
>
> self->show_preedit = TRUE;
> g_signal_emit_by_name(self,
> "preedit-changed",
> self->preedit_buffer->str);
>
> [...]
> }
> else
> {
> self->show_preedit = FALSE;
>
> if (self->preedit_buffer != NULL && self->preedit_buffer->len != 0)
> {
> g_string_truncate(self->preedit_buffer, 0);
> g_signal_emit_by_name(self,
> "preedit-changed",
> self->preedit_buffer->str);
> }
> }
> }
>
>
>
> Cornelius Hald wrote:
> > Hi,
> >
> > I need to know whether or not a word suggestion[1] is currently
> > displayed inside a HildonTextView. Even better it would be if I could
> > access the content of this suggestion. Is that somehow possible?
> >
> > Could someone explain how the suggestion is added to the text view? I
> > can't find any signals that get fired, but somehow the text is part of
> > the text view, I mean, for example, text on the right side of the
> > suggestion is correctly moved to the right, text wrapping is working
> > etc...
> >
> > It would be great if someone could explain this black magic to me. What
> > I'm trying to do is to apply a certain text style/formatting onto the
> > suggestion to make it look consistent with the rest of the text.
> >
> > Thanks!
> > Conny
> >
> >
> > [1] the selected text on the right side of the cursor, that can be
> > accepted by pressing the right cursor key.
> >
> >
> > _______________________________________________
> > maemo-developers mailing list
> > maemo-developers [at] maemo
> > https://lists.maemo.org/mailman/listinfo/maemo-developers
> >
>
> _______________________________________________
> maemo-developers mailing list
> maemo-developers [at] maemo
> https://lists.maemo.org/mailman/listinfo/maemo-developers

_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers


hald at icandy

Nov 7, 2009, 11:12 AM

Post #4 of 6 (547 views)
Permalink
Re: Word completion in Fremantle [In reply to]

> P.S. Maybe I could use a signal emission hook to intercept the
> "preedit-changed" signal. Not sure, but it could work. I'll give it a
> try...

I've tried that now, but still no luck. My code looks like this:

static gboolean
on_preedit_changed (GSignalInvocationHint *ihint,
guint n_param_values,
const GValue *param_values,
gpointer data)
{
g_printerr("### Preedit parameter count: %i\n", n_param_values);
}

guint sid = g_signal_lookup("preedit-changed", GTK_TYPE_IM_CONTEXT);
g_signal_add_emission_hook(sid, 0, on_preedit_changed, textview, NULL);


on_preedit_changed() is called only one time during startup and with a
bogus parameter. It might be that I should use HILDON_TYPE_IM_CONTEXT as
type, but that's not possible, because the header file
hildon-im-context.h is missing from the SDK. I don't know why and I
don't know whether or not that's the problem. Maybe I'm doing something
else wrong?!

Anyways, more help would really be appreciated!

Thanks!
Conny


_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers


hald at icandy

Nov 7, 2009, 12:38 PM

Post #5 of 6 (537 views)
Permalink
Re: Word completion in Fremantle [In reply to]

On Sat, 2009-11-07 at 19:12 +0000, Cornelius Hald wrote:
> on_preedit_changed() is called only one time during startup and with a
> bogus parameter. It might be that I should use HILDON_TYPE_IM_CONTEXT as
> type, but that's not possible, because the header file
> hildon-im-context.h is missing from the SDK.

Ok, it was my fault that on_preedit_changed() was only called once. I
forgot to return TRUE at the end of the function. Now it's called every
time the preedit is changed and the parameter is a correct GtkIMContext.

So far so good, now I have the correct IMContext. The problem is, that I
cannot change the preedit text nor the preedit formatting. I can get
both, but those are copies so changing them has no effect.

I guess the only chance to dynamically change the formatting of the
preedit text is to create a subclass of GtkIMContext which would
basically be HildonIMContext but with a different implementation of
get_preedit_string().

Well, that's a bit overkill, so I'll have a look if I can change the
font handling in Conboy in a way to make it work with the default
HildonIMContext.

Cheers!
Conny


_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers


hald at icandy

Nov 13, 2009, 2:21 AM

Post #6 of 6 (473 views)
Permalink
Re: Word completion in Fremantle [In reply to]

Hi!

> sorry for the delay in answering.

Donīt worry :)

> I understand that what you really want is that the suggested text has
> the same attributes (size, font) as the text around it. It seems a
> pretty obvious thing, taking into account that different editors (i.e.
> Notes) allow for different sizes and fonts.

For most applications (including Notes) itīs working out of the box. The
problem is, that I use the text view in a (maybe) non-standard way. Iīll
try to explain:

Letīs assume we want to write the word "Halloween" in bold and once we
have written "Hallo" the auto completion kicks in and sets the preedit
text "ween". The "ween" part should also be bold.

In Notes the cursor is always between the starting and ending
GtkTextTag. So everything you type will automatically be bold. Gtk takes
care of that and will push the end tag further to the right with every
entered character. So in the case of "Halloween" it looks like that:

H a l l o
^ ^
<b> </b> <- GtkTextTags

Now the preedit text is inserted at the cursor position:

H a l l o w e e n
^ ^
<b> </b> <- GtkTextTags

Because the preedit text is inserted between the GtkTextTags the preedit
text is automatically formatted in the same manner as the first part of
the text. This is the reason why it works for most editors out of the box.

Now in Conboy I had to do the handling of formatting differently. It
works like that:
There is a set of "active formatting tags" and with each keypress those
tags are applied to the just inserted character. Basically like this:

H a l ...
^ ^ ^
<b> <b> <b>
</b> </b> </b>

GtkTextBuffer now automatically merges those tags together to one. The
result looks like this:

H a l l o
^ ^
<b> </b> <- GtkTextTags

Now the cursor is on the right side of the character 'o' and the word
completion inserts the preedit text at the cursor position. This time
however the cursor is outside the GtkTextTags and therefore the preedit
text does not get the specified formatting. The result would be:

H a l l o w e e n
^ ^
<b> </b> <- GtkTextTags

"Hallo" is bold "ween" not.

Please note this problem only exists for the preedit text. Once the user
presses the right-cursor button the preedit text is normally inserted
into the GtkTextBuffer and I can apply tags as I do it with every key
press. With bold is not that bad, but with different font sizes it looks
really ugly.

This is the reason why I was looking for a way to apply tags to the
preedit text. I know I could (theoretically) change my code to make sure
that the cursor is always inside the tags and not outside. But this
would be a very intrusive change to the code with many side effects. So
I would like to avoid that.

> If that is the case, yes, extending the class would be overkill. From
> the IM context it is possible to get a list of Pango attributes for the
> insert position and return them together with the preedit text. This
> would solve the problem.

Iīve seen that. But it would only solve the problem if Iīm able to
change those Pango attribtues. Because the Pango attributes are
generated by looking at the GtkTextTags. Unfortunately I couldnīt find a
way to change the Pango attributes from outside the context.

> I am aware that the IM code at stage.maemo.org hasn't been updated in a
> while, so maybe what I just said will be in the final version :-)

Ok, so if there have been changes to that code it might still be
possible. OTOH it looks like HildonIMContext does not introduce own API
at all, but just overwrites some methods of GtkIMContext, therefore the
API of GtkIMContext should apply and with this API I see now way of
altering those Pango attributes.

Thanks a lot for your reply and if you have other suggestions or
corrections I would be very happy to hear them. At the moment I think I
have to live with it or change my code. If changing my own code would be
easy I would have done that already of course...

Thanks!
Conny
_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers

Maemo developers RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.