Re: gtk_text_view_im_context_filter_keypress - howto replace Tab with 4-spaces?

2015-12-21 Thread Liam R. E. Quin
On Mon, 2015-12-21 at 02:22 -0600, David C. Rankin wrote:
> 
[...]
> 
>  if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW 
> (app->view),
>    event)) {
>  printf ("  Tab key handled by im_context\n");

This is the wrong way round. I think that
if gtk_text_view_im_context_filter_keypress returns true you're
supposed to return TRUE without doing anything.

> You may find the devhelp program useful - search for this function in
> the index and you'll see an example.

Liam

-- 
Liam R. E. Quin 

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: gtk_text_view_im_context_filter_keypress - howto replace Tab with 4-spaces?

2015-12-21 Thread David C. Rankin

On 12/21/2015 02:57 AM, Liam R. E. Quin wrote:

On Mon, 2015-12-21 at 02:22 -0600, David C. Rankin wrote:



[...]


  if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW
(app->view),
event)) {
  printf ("  Tab key handled by im_context\n");


This is the wrong way round. I think that
if gtk_text_view_im_context_filter_keypress returns true you're
supposed to return TRUE without doing anything.


You may find the devhelp program useful - search for this function in
the index and you'll see an example.


Liam



Thank you Liam,

  I went back and re-read the documentation again, and then it made sense. If 
gtk_text_view_im_context_filter_keypress returns true, as you say, it is telling 
you there is nothing more you can do to handle the keypress. It is only when it 
returns false that you can further handle the keypress before returning true 
telling the default handler that you handled the keypress.


  I guess the way it works was just counterintuitive to what I expected and the 
2 sentences worth of documentation weren't quite enough to cure the confusion.


  Thanks again. I ended up doing the following:

gboolean on_keypress (GtkWidget *widget, GdkEventKey *event, context *app)
{
switch (event->keyval)
{
case GDK_KEY_Tab:   /* catch tab, replace with spaces */
if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW 
(app->view),

  event)) {
return TRUE;
}
else {
GtkTextBuffer *buffer;
gchar *tab_string;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (app->view));
tab_string = g_strdup_printf ("%*s", app->tabspaces, " ");
gtk_text_buffer_insert_at_cursor (buffer, tab_string, -1);
g_free (tab_string);
return TRUE;/* return TRUE - no further processing */
}
default:  /* indicate default handling should take place */
return FALSE;
}
}


--
David C. Rankin, J.D.,P.E.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list