GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 24, 2014 6:51 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: events with libglade
PostPosted: Thu Jun 12, 2008 11:03 am 
Offline
Familiar Face

Joined: Mon Feb 25, 2008 8:26 am
Posts: 16
Hello,

I created a program with Glade, produced a GtkEventBox and included it with glade_xml_new in the program.

I would now like the position of the mouse query when the button was pressed.
Is there somewhere an example?

I Use:
Glade 3

Greetings, Satyria


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 11:25 am 
Offline
Familiar Face

Joined: Mon Feb 25, 2008 8:26 am
Posts: 16
Here are the mini-source code

Code:
#include <glade/glade.h>
#include <gtk/gtk.h>

G_MODULE_EXPORT void on_event (GtkToolButton *item)
{
  g_print ("Ein Event wurde ausgeloest!\n");

/*How can I retrieve the events?*/
 
}

G_MODULE_EXPORT void on_event_key_press_event (GtkToolButton *item)
{
  g_print ("Taste wurde gedrueckt!\n");
  gtk_main_quit();
}


G_MODULE_EXPORT void on_window_delete_event (GtkToolButton *item)
{
  g_print ("Beenden wurde gedrueckt!\n");
  gtk_main_quit();
}



int main (int argc,
          char *argv[])
{
  GtkWidget *window;
  GladeXML *xml;

  gtk_init (&argc, &argv);

  xml = glade_xml_new ("zeichnen.glade", NULL, NULL);
  window = glade_xml_get_widget (xml, "window");
 
  glade_xml_signal_autoconnect (xml);

  gtk_widget_show_all (window);
  gtk_main ();
 
  return 0;
}

and the glade code:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.3 on Thu Jun 12 13:07:28 2008 -->
<glade-interface>
  <widget class="GtkWindow" id="window">
    <property name="title" translatable="yes">Zeichnen</property>
    <property name="default_width">300</property>
    <property name="default_height">300</property>
    <property name="icon">einhorn.jpg</property>
    <property name="icon_name">Zeichnen</property>
    <signal name="delete_event" handler="on_window_delete_event"/>
    <signal name="destroy_event" handler="on_window_delete_event"/>
    <child>
      <widget class="GtkEventBox" id="event">
        <property name="visible">True</property>
        <signal name="button_press_event" handler="on_event_button_press_event"/>
        <signal name="event" handler="on_event" object="user_event"/>
        <signal name="key_press_event" handler="on_event_key_press_event"/>
        <signal name="button_release_event" handler="on_event_button_release_event"/>
        <child>
          <widget class="GtkDrawingArea" id="drawingarea">
            <property name="visible">True</property>
            <property name="app_paintable">True</property>
          </widget>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>


Problem see line 8!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 12:33 pm 
Offline
Familiar Face

Joined: Mon Feb 25, 2008 8:26 am
Posts: 16
Hello, I've found a way and my problem is solved.

Also:

In the file galde were deleted the events (which makes sense for this?).
In the source code, I have added these lines:

Code:
   area =  glade_xml_get_widget (xml, "drawingarea");
   parray g_ptr_array_sized_new = (5000);

   gtk_widget_add_events (area, GDK_BUTTON_PRESS_MASK);
   
   g_signal_connect (G_OBJECT (area), "button_press_event"
                     G_CALLBACK (button_pressed), parray);

And this feature:

Code:
static gboolean button_pressed (GtkWidget * area,
                 GdkEventButton * event,
                 Parray GPtrArray *)
(
   int x, y;
   x = event-> x;
   y = event-> y;

   g_print ( "Der Button wurde bei %i %i ausgeloest\ n", x, y);
   return FALSE;
)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group