xforms-development
[Top][All Lists]
Advanced

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

[XForms] setting radio button invokes callback


From: Michal Szymanski
Subject: [XForms] setting radio button invokes callback
Date: Sat, 4 Dec 2010 05:24:00 +0100
User-agent: Mutt/1.4.2.2i

Hello,

While investigating strange duplication of some activities of my
application I found that, if one programatically (from within the
application) sets a radio button, its callback is invoked (unless it is
already set). This is contrary to the common sense and (more importantly :)
to the manual (here, see second paragraph, first is discussed below):

== Sect. 16.4: Other Button Routines: ==

  To this end use the routine
    void fl_set_button(FL_OBJECT *obj, int pushed);
  pushed indicates whether the button should be pushed (1) or
  released (0). When setting a [FL_RADIO_BUTTON], page 117 to be pushed
  this automatically releases the currently pushed radio button in the
  same form (or group).

  Also note that, while this routine only simulates the visual appearance
  and perhaps some internal states, it does not affect the program flow in
  any way, i.e. setting a button as being pushed does not invoke its
  callback or results in the button becoming returned to the program.

I was able to reproduce this behavior in a very simple program (attached
below). Both in 1.0.93sp1 and 1.0.94sp2. This looks like a real bug to
me.

Also, the manual is somewhat self-inconsistent on the matters regarding
setting the radio buttons from within the application:

== Sect. 3.4: Buttons ==
The application program can also set a button to be pushed or not itself
without a user action. (This is of course only useful for push buttons
and radio buttons. Setting a radio button does not mean that the
currently set radio button is reset. The application program has to do
this.)
== 

which seems to be contrary to what first paragraph of above cited sect.
16.4 says (and what seems to be true - other buttons do get "unset" when
one uses fl_set_button()

with best regards,
Michal.

-- 
  Michal Szymanski (msz at astrouw dot edu dot pl)
  Warsaw University Observatory, Warszawa, POLAND

-- cut, "radio.h" follows. "radio.c" is further below --

/* Header file generated by fdesign on Sat Dec  4 01:03:39 2010 */

#ifndef FD_radio_h_
#define FD_radio_h_

#include <forms.h>

/* Callbacks, globals and object handlers */

extern void cb_setrad1( FL_OBJECT *, long );
extern void cb_rad( FL_OBJECT *, long );


/* Forms and Objects */

typedef struct {
    FL_FORM   * radio;
    void      * vdata;
    char      * cdata;
    long        ldata;
    FL_OBJECT * setrad1;
    FL_OBJECT * radgrp;
    FL_OBJECT * rad[ 2 ];
} FD_radio;

extern FD_radio * create_form_radio( void );

#endif /* FD_radio_h_ */

--- cut, "radio.c" follows --

/* Form definition file generated by fdesign */

#include <stdlib.h>
#include "radio.h"

FD_radio *fd_radio;

/***************************************
 ***************************************/

FD_radio *
create_form_radio( void )
{
    FL_OBJECT *obj;
    FD_radio *fdui = fl_malloc( sizeof *fdui );

    fdui->vdata = fdui->cdata = NULL;
    fdui->ldata = 0;

    fdui->radio = fl_bgn_form( FL_NO_BOX, 320, 250 );

    obj = fl_add_box( FL_UP_BOX, 0, 0, 320, 250, "" );

    fdui->setrad1 = obj = fl_add_button( FL_NORMAL_BUTTON, 50, 140, 100, 50, 
"SET RADIO 1" );
    fl_set_object_lsize( obj, FL_NORMAL_SIZE );
    fl_set_object_lalign( obj, FL_ALIGN_CENTER );
    fl_set_object_callback( obj, cb_setrad1, 0 );

    fdui->radgrp = fl_bgn_group( );

    fdui->rad[0] = obj = fl_add_lightbutton( FL_RADIO_BUTTON, 40, 30, 60, 40, 
"0" );
    fl_set_object_lsize( obj, FL_MEDIUM_SIZE );
    fl_set_object_callback( obj, cb_rad, 0 );

    fdui->rad[1] = obj = fl_add_lightbutton( FL_RADIO_BUTTON, 120, 30, 60, 40, 
"1" );
    fl_set_object_lsize( obj, FL_MEDIUM_SIZE );
    fl_set_object_callback( obj, cb_rad, 1 );
    fl_end_group( );


    fl_end_form( );

    fdui->radio->fdui = fdui;

    return fdui;
}


/* Callbacks and freeobj handles for form radio */

/***************************************
 ***************************************/

void cb_rad( FL_OBJECT * ob,
         long        data )
{
  printf("setting RADIO %ld\n", data);
}


/***************************************
 ***************************************/

void cb_setrad1( FL_OBJECT * ob,
         long        data )
{
  fl_set_button(fd_radio->rad[1],1);
}


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

    fl_initialize( &argc, argv, 0, 0, 0 );
    fd_radio = create_form_radio( );

    /* Fill-in form initialization code */

    /* Show the first form */

    fl_show_form( fd_radio->radio, FL_PLACE_CENTERFREE, FL_FULLBORDER, "radio" 
);

    fl_do_forms( );

    if ( fl_form_is_visible( fd_radio->radio ) )
        fl_hide_form( fd_radio->radio );
    fl_free( fd_radio );
    fl_finish( );

    return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]