Re: Using AbiWidget

From: Teus Benschop <teus_at_teusbenschop.nl>
Date: Sat Mar 10 2007 - 10:25:01 CET

There is some code in the example program below that disables the Ctrl-O
key in the abiwidget.

Regards,

Teus.

#include <stdio.h>
#include <stdlib.h>
#include <libabiword.h>
#include <abiwidget.h>
#include <gdk/gdkkeysyms.h>

  GtkWidget *window;
  GtkWidget *vbox1;
  GtkWidget *abi;

static gboolean on_key_press_event (GtkWidget * widget, GdkEventKey *
event, gpointer user_data)
{
  // Handle control pressed.
  guint modifiers = gtk_accelerator_get_default_mod_mask ();
  if ((event->state & modifiers) == GDK_CONTROL_MASK) {
    switch (event->keyval) {
      case GDK_O:
      case GDK_o:
        return TRUE;
        break;
      default:
        break;
    }
  }
  return FALSE;
}

int main(int argc, char ** argv)
{

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_usize(GTK_WIDGET(window), 640, 640);

  vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vbox1);
  gtk_container_add (GTK_CONTAINER (window), vbox1);

  /* Initialize libabiword */

  libabiword_init(argc, (const char **)argv);
  abi = abi_widget_new ();
  /* The key press event must be connected at this stage, else the
widget absorbs every event */
  g_signal_connect (G_OBJECT (abi), "key_press_event", G_CALLBACK
(on_key_press_event), NULL);
  gtk_box_pack_start (GTK_BOX (vbox1), abi, TRUE, TRUE, 0);
  gtk_widget_show_all (window);

  g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK
(gtk_main_quit), NULL);
  g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK
(gtk_main_quit), NULL);

  if(argv[1]) {
    abi_widget_load_file (ABI_WIDGET (abi), argv[1]);
  } else {
    abi_widget_load_file (ABI_WIDGET (abi), "");
  }
 
  gtk_widget_grab_focus (abi);

  gtk_main ();

  /* Close libabiword */

  libabiword_shutdown ();
  return 0;
}

J.M. Maurer wrote:
> On Fri, 2007-03-09 at 13:36 +0200, Teus Benschop wrote:
>
>> Hi Martin,
>>
>> Thanks for your kind words to a newcomer.
>>
>> The problem was that the Ctrl-O shortcuts actually allows the user to
>> open a file in the widget and once this new file was loaded, the
>> abiwidget stopped emitting any signals. Hence I was looking for a method
>> to override this shortcut.
>>
>> The hack found later was an unusual one, yet it worked: connect to the
>> signal before the widget is shown:
>>
>> libabiword_init(argc, (const char **)argv);
>> abi = abi_widget_new ();
>> g_signal_connect (G_OBJECT (abi), "key_press_event", G_CALLBACK
>> (on_key_press_event), NULL);
>> gtk_container_add (GTK_CONTAINER (window), abi);
>> gtk_widget_show_all (window);
>>
>> I hope that this is a permanent hack and not something that might
>> disappear in later versions of Gtk.
>>
>> Does the abiwidget have its own way to disable keybindings, or are we
>> stuck with this hack?
>>
>
> You can't do it at the moment, but I need that too for OLPC, so it will
> come soonish I hope.
>
> Marc
>
>
>> Regards,
>>
>> Teus.
>>
>>
>>
>> msevior@physics.unimelb.edu.au wrote:
>>
>>> Hi Tues,
>>> Thanks for your interest in AbiWord and particularly libabiword. I
>>> suggest you direct these sort of technical questions to the
>>> development mailing list here:
>>>
>>> abiword-dev@abisource.com
>>>
>>> Cheers!
>>>
>>> Martin
>>>
>>>
>>>
>>>> Hello,
>>>>
>>>> I've been looking around the internet for any examples of programs that
>>>> use the abiwidget. There is one example on
>>>> http://www.abiword.org/twiki/bin/view/Abiword/AbiWordSDK, and that was
>>>> very helpful.
>>>>
>>>> But there is something I do not yet know how to solve. The AbiWidget has
>>>> its own keybindings. I'd like to override these. For example, Ctrl-B now
>>>> switches bold on. How to override this so that Ctrl-B no longer does that?
>>>>
>>>> I connected to the GtkWkidget's "key_press_event", like so:
>>>>
>>>> static gboolean on_key_press_event (GtkWidget * widget, GdkEventKey *
>>>> event, gpointer user_data)
>>>> {
>>>> g_print ("Key pressed");
>>>> return FALSE;
>>>> }
>>>>
>>>> g_signal_connect (G_OBJECT (abi), "key_press_event", G_CALLBACK
>>>> (on_key_press_event), NULL);
>>>>
>>>>
>>>> But to no avail. The keybinding was still there. Setting the return
>>>> value to TRUE makes no difference.
>>>>
>>>> Any help on overriding the keybindings is greatly appreciated.
>>>>
>>>> Teus.
>>>> -----------------------------------------------
>>>> To unsubscribe from this list, send a message to
>>>> abiword-user-request@abisource.com with the word
>>>> unsubscribe in the message body.
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>
>
>
>
>
>
Received on Sat Mar 10 10:27:48 2007

This archive was generated by hypermail 2.1.8 : Sat Mar 10 2007 - 10:27:48 CET