GtkAdjustment Callback Parameters are Swapped



Hello,

I have found that the parameters that GTK passes to the callback for
adjustments are swapped (reversed from what the prototype indicates they
should be).  The documentation for the prototype for the callback
for the "value-changed" signal for the GtkAdjustment class follows:

"value-changed"
             void        user_function      (GtkAdjustment *adjustment,
                                             gpointer user_data);

Note that the GtkAdjustment associated with the signal is the first parameter
and the user_data is the second parameter, as is normally the case.

I created an adjustment, as shown below:

     /*  Create an adjustment.  */
     hadjustment = gtk_adjustment_new( 0.0,            /*  Initial value   */
                                       0.0,            /*  Lower value     */
                                       100.0,          /*  Upper value     */
                                       1.0,            /*  Step Increment  */
                                       20.0,           /*  Page Increment  */
                                       20.0            /*  Page Size       */
                                     );

I then registered my callback, as shown below:

        printf( "main:  hadjustment created.  Adjust = 0x%p.  Data = 0x%p.\n",
                hadjustment,
                (gpointer)0x1234
              );
        gtk_signal_connect_object(
                           GTK_OBJECT( hadjustment ),
                           "value-changed",
                           (GtkSignalFunc)value_changed_callback,
                           (gpointer)0x1234
                                 );

I then created a horizontal scrollbar based on this adjustment.
 
For testing purposes, my callback simply prints the values of the parameters,
as shown below:

/*  The callback for the horizontal adjustment.  */
static void value_changed_callback( GtkAdjustment  *adjust, gpointer  data )
{
   printf( "value_changed_callback:  adjust = 0x%p.  data = 0x%p.\n",
           adjust,
           data
         );
}


When I run this test and move the scrollbar associated with the horizontal
adjustment, the program outputs the following:

main:  hadjustment created.  Adjust = 0x3d548.  Data = 0x1234.
value_changed_callback:  adjust = 0x1234.  data = 0x3d548.

Note that the value of the adjustment in the callback is the value of the 
"user data" I passed to gtk_signal_connect_object() and vice versa.

Am I doing something wrong or is this a bug in GTK?

If you would like the test program I wrote (only 99 lines, including comments),
let me know.


Thanks,

Brad



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