[gtkada] Problem with gtkada-canvas.adb

Clark, G L g.l.clark at lmco.com
Fri Mar 22 00:00:46 CET 2002


Emmanuel, et al.

  With GtkAda 1.2.12 Gtkada.Canvas (gtkada-canvas.adb). There are multiple
events inadvertently forwarded to On_Button_Click when the right mouse
button is used to click.  A Button_Press event from function Button_Press()
followed by a NULL event and a Button_Release from function
Button_Release(). There is also an attempt to free the NULL event which only
exists when a left click is released on a canvas_item.  This causes a !=
NULL assertion to fail in gdkevents.c.

  Below is an explanation and a quick fix.

  George Clark
  Lockheed Martin Aeronautics Company
  Legacy F-16 System / Software Engineering Environment



In: function Button_Pressed
  Starting on line 1696.  If the item is double clicked, or clicked on with
any button except for Button 1 the button_press is forwarded to
On_Button_Click. Otherwise the event is stored in Canvas.Event_Press to send
later after the user drags the item on the canvas.

--- original code 1700 - 1706   ---- --- --- -- -- -  -   -
      --  Double-click events are transmitted directly to the item, and are
      --  not used to move an item.
      --  Clicks other than left mouse button are also transmitted directly

      if Get_Event_Type (Event) = Gdk_2button_Press
        or else Get_Button (Event) /= 1
      then
         --  ??? Should do so for each item in the selection
         On_Button_Click (Canvas.Selection.Item, Event);
         return False;
      end if;
--- end original code ---- ---- ---- --- --- -- -- -  -   -

In: function Button_Released
  Starting on line 1789 the code assumes the button press was not forwarded
to On_Button_Click. However, it was only not forwarded if the item was
clicked on using Mouse Button 1.  When a canvas_item is clicked on with the
right mouse button the event is forwarded to On_Button_Click. When the user
releases the right mouse button two more events are forwarded to
On_Button_Click. There is also an attempt to free Canvas.Event_Press but it
only exists when the item was clicked with Mouse Button 1. This results in a
violated assertion in the c code:

Gdk-CRITICAL **: file gdkevents.c: line 724 (gdk_event_free): assertion
`event != NULL' failed.

                                               
--- original code 1789 - 1802   ---- --- --- -- -- -  -   -
         --  The button-press event wasn't forwarded, since we were
expecting
         --  that the item would move. We thus forward it now
         On_Button_Click (Canvas.Selection.Item, Canvas.Event_Press);

         Set_X (Event, Gdouble (Get_Value (Canvas.Hadj)) +  Get_X (Event)
                - Gdouble (To_Canvas_Coordinates
                           (Canvas, Canvas.Selection.Item.Coord.X)));
         Set_Y (Event, Gdouble (Get_Value (Canvas.Vadj)) + Get_Y (Event)
                - Gdouble (To_Canvas_Coordinates
                           (Canvas, Canvas.Selection.Item.Coord.Y)));
         On_Button_Click (Canvas.Selection.Item, Event);
      end if;

      Free (Canvas.Event_Press);
--- end original code ---- ---- ---- --- --- -- -- -  -   -

  The solution is to wrap the lines 1791 and 1802 in if statements.

         --  The button-press event wasn't forwarded, since we were
expecting
         --  that the item would move. We thus forward it now

         --  This WAS forwarded if the item was double clicked or clicked
         --  with anything other than Mouse Button 1.  So we only want to
send
         --  it now if it was previously clicked on with Mouse Button 1.
         if Get_Button(Event) = 1 then
            -- line 1791
            On_Button_Click(Canvas.Selection.Item, Canvas.Event_Press);
         end if;

         -- Also we only want to free the event it was Mouse Button 1.
         if Get_Button(Event) = 1 then
            -- line 1802
            Free (Canvas.Event_Press);
         end if;



-----Original Message-----
From: Clark, G L [mailto:g.l.clark at lmco.com]
Sent: Tuesday, March 19, 2002 4:46 PM
To: 'gtkada at lists.act-europe.fr'
Subject: RE: [gtkada] Canvas : Selected_Item Callback.


 I wrote a simple test application with a Gtkada.Canvas widget.  I basically
create a few canvas_items and put them on the canvas.  I've implemented no
handlers and only overloaded the Draw function to create the pixmaps.

 As expected when I left-click on an item nothing happens because no
handlers were implemented.  However, when I right-click on an item I still
get the error below printed to the console.  The program continues
execution.  So, if the problem is "somewhere in my code" then it would be
due to something that was not implemented rather than something implemented
incorrectly.
 
Gdk-CRITICAL **: file gdkevents.c: line 724 (gdk_event_free): assertion
`event != NULL' failed.

  According to the docs it seems there are two ways to go about implementing
a handler for selecting and manipulating items.
1.  Use the signal:
    "item_selected" 
	procedure Handler (Canvas : access Interactive_Canvas_Record'Class; 
				 Item : Canvas_Item);
    
2.  Overload On_Button_Click:
procedure On_Button_Click      
  (Item               : access Canvas_Item_Record;
   Event              :        Gdk.Event.Gdk_Event_Button);
-- Function called whenever the item was clicked on.

  In the program which cause me to write the original email I've not been
using On_Button_Click, I'm only catching the item_selected signal and
manipulating the Item from there.  Could this be the source of my problem?
If so, are there any examples of overloading On_Button_Click? Also are there
any examples of right clicking on a Canvas_Item?

  Thanks,
    George
 
-----Original Message-----
From: Emmanuel Briot [mailto:briot at ACT-Europe.FR]
Sent: Friday, March 15, 2002 3:16 AM
To: gtkada at lists.act-europe.fr
Subject: Re: [gtkada] Canvas : Selected_Item Callback.


"Clark, G L" <g.l.clark at lmco.com> writes:

>   I'm writing an application which uses a Gtkada.Canvas widget.  I have
> successfully implemented a handler for the Item_Selected signal.  When I
> click on an item with the left mouse button the event is handled
correctly.
> When I click on an item with the right mouse button I get:
[...]
>   Is this something which is not implemented in Gtkada.Canvas or am I
going
> about this the wrong way?


This works fine in GtkAda, the problem is somewhere in your code (or in the
interaction of your code with GtkAda).

Emmanuel

_______________________________________________
gtkada mailing list
gtkada at lists.act-europe.fr
http://lists.act-europe.fr/mailman/listinfo/gtkada

_______________________________________________
gtkada mailing list
gtkada at lists.act-europe.fr
http://lists.act-europe.fr/mailman/listinfo/gtkada




More information about the gtkada mailing list