Re: Ad-on hook idea (fwd)



On Tue, 16 Nov 1999 redhog@mini.dhs.org wrote:

> When it comes to the wheel-scrolling thing, I have a little problem - I
> want _every_ button press/move/release that vis not used for something
> else for a the widget inside the scrolledwindow widget, to scroll the
> scrolledwindow widget. But I don't know how to get the knowledge of if
> some event has been used allready. If someone could help me with this, I
> would be ready with such a module in a few days!

event handlers return a boolean value indicating whether an event has
been processed or not (and should be propagated uop the widget heirarchy).
though this is pretty unelegant and may not be supported in future versions,
you could cod eup a gtk module that patches GtkScrolledWindow's button_press
handler. this would look something like this (upon module initialization):

static gboolean (*orig_button_press_event) (GtkWidget *widget, GdkEvent *event) = NULL;
static GtkWidgetClass *scrolled_window_class = NULL;


  class = gtk_type_class (GTK_TYPE_SCROLLED_WINDOW);
  orig_button_press_event = class->button_press_event;
  class->button_press_event = my_scrolled_window_button_press_event;


static gboolean
my_scrolled_window_button_press_event (GtkWidget *widget,
                                       GdkEvent  *event)
{
  /* chain original class handler first */
  if (orig_button_press_event && orig_button_press_event (widget, event))
    return TRUE;
  
  /* button press unhandled */
 
  if (event->button.button == 4)
    {
      do_stuff_here ();
    
      return TRUE; /* we handled the event now */
    }
  else
    return FALSE; /* event unhandled */
}

> Last, a question about the module system: Is it possible to create a
> library call that Gtk programs could do to the module, that just returns
> an error message if that module isn't loaded, and that calls some function
> inside the module if it is loaded? Is there such a call allready?

there are actually two fucntions featured and you need to define both,
the first is called by the GModule code to check for versioning and
similar stuff, you can cut and paste this code:

G_MODULE_EXPORT const gchar* g_module_check_init (GModule *module);
const gchar*
g_module_check_init (GModule *module)
{
  GModule *main_module;
  gchar *version_check = NULL;

  main_module = g_module_open (NULL, 0);
  if (!main_module)
    return "no main handle";
  if (!g_module_symbol (main_module, "gtk_major_version", (gpointer*) &version_check) && version_check)
    return "no gtk library?";

  version_check = gtk_check_version (GTK_MAJOR_VERSION,
                                     GTK_MINOR_VERSION,
                                     GTK_MICRO_VERSION - GTK_INTERFACE_AGE);
  if (version_check)
    return version_check;

  return NULL;
}

the second is called by gtk for actuall module initialization, this is where
you should put the above code:

G_MODULE_EXPORT void gtk_module_init (gint *argc, gchar ***argv);
void
gtk_module_init (int            *argc,
                 char           ***argv)
{
  /* freak out on the scrolled window class */
}

gtk modules are always resident, so you don't need to worry about destruction/
unloading.


> With best regards,
> Egil Möller
> 

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]