ListBox with radio Button Problem



Hi all,

I have created a treeview in which I have radion buttons in first column
& some text in 2nd column. When I click on any radio button of other row
I could see both the rows having radio buttons .

How can I make them mutually exclusive? If 3rd is clicked 1st shud not
show radio on it.

Please help me soon its urgent.

Below is the code for reference.......


\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\


#include <gtk/gtk.h>

static GtkWidget *window = NULL;

typedef struct
{
    gboolean  fixed;
    gchar    *languages;
}
array_data;

array_data arr[8];

static GtkTreeModel *
        create_model (void)
{
    gint i = 0, j = 0;
    GtkListStore *store;
    GtkTreeIter iter;
    
    gint k;

    arr[0].fixed = 1;
    arr[0].languages = "abc";
    for(k = 1 ; k < 8 ; k++)
    {
        arr[k].fixed = 0;
        arr[k].languages = "xyz";
    }

    /* create list store */
    store = gtk_list_store_new (2,
                                G_TYPE_BOOLEAN,
                                G_TYPE_STRING);

    /* add data to the list store */
    for (i = 0; i < 8; i++)
    {

        gtk_list_store_append (store, &iter);
        gtk_list_store_set (store, &iter,
                            0, arr[i].fixed,
                            1, arr[i].languages, -1);
    }

     
        
    return GTK_TREE_MODEL (store);
}

static void
        fixed_toggled (GtkCellRendererToggle *cell,
                       gchar                 *path_str,
                       gpointer               data)
{
    GtkTreeModel *model = (GtkTreeModel *)data;
    GtkTreeIter  iter;
    GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
    gboolean fixed;
 int i;

    /* get toggled iter */
    gtk_tree_model_get_iter (model, &iter, path);
    gtk_tree_model_get (model, &iter, 0, &fixed, -1);

    /* do something with the value */

     printf(" The path is ....%s\n", path_str);

    if(fixed == TRUE)
    {
        printf(" IT is TRUE\n");
        
    }
    else
    {

        for(i = 0 ; i < 8 ; i++)
        {
            if(arr[i].fixed  ==  1)
                printf(" IT is the set TRUE value\n");
            arr[i].fixed  = 0;
            //gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0,
arr[i].fixed, -1);

        }
        printf(" IT is FALSE\n");
        fixed ^= 1;
        /* set new value */
        gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, fixed,
-1);
    }     
   
 
     /* clean up */
    gtk_tree_path_free (path);
    
}

static void
        add_columns (GtkTreeView *treeview)
{
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;
    GtkTreeModel *model = gtk_tree_view_get_model (treeview);
    GtkCellRendererToggle *toggle;
    gboolean radio;
    /* column for fixed toggles */
    renderer = gtk_cell_renderer_toggle_new ();
    
    g_signal_connect (renderer, "toggled",
                      G_CALLBACK (fixed_toggled), model);

    column = gtk_tree_view_column_new_with_attributes ("Fixed?",
            renderer,
            "active", 0,
            NULL);

    /* set this column to a fixed sizing (of 50 pixels) */
    gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
                                     GTK_TREE_VIEW_COLUMN_FIXED);
    gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column),
50);
    gtk_tree_view_append_column (treeview, column);
    
 
gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(renderer),TR
UE);

    /* column for severities */
    renderer = gtk_cell_renderer_text_new ();
    column = gtk_tree_view_column_new_with_attributes ("Languages",
            renderer,
            "text",
            1,
            NULL);
    gtk_tree_view_append_column (treeview, column);
}

GtkWidget*
        create_window (void)
{
  
        GtkWidget *vbox;
        GtkWidget *label;
        GtkWidget *sw;
        GtkTreeModel *model;
        GtkWidget *treeview;

        /* create window, etc */
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_widget_set_size_request (window, 720, 480);
        gtk_window_set_title (GTK_WINDOW
(window),"subtitle_menu_window");

        
        g_signal_connect (window, "destroy",
                          G_CALLBACK (gtk_widget_destroyed), &window);
        gtk_container_set_border_width (GTK_CONTAINER (window), 8);

        vbox = gtk_vbox_new (FALSE, 8);
        gtk_widget_show(vbox);
        gtk_container_add (GTK_CONTAINER (window), vbox);

        sw = gtk_scrolled_window_new (NULL, NULL);
        gtk_widget_show(sw);
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
                                             GTK_SHADOW_ETCHED_IN);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                        GTK_POLICY_NEVER,
                                        GTK_POLICY_AUTOMATIC);
        gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);


        /* create tree model */
        //if (toggle_flag = 1)
        model = create_model ();

        /* create tree view */
        treeview = gtk_tree_view_new_with_model (model);
       
        g_object_unref (model);
        gtk_widget_show(treeview);

        
        gtk_container_add (GTK_CONTAINER (sw), treeview);

        /* add columns to the tree view */
        add_columns (GTK_TREE_VIEW (treeview));
        
        /* finish & show */
        gtk_window_set_default_size (GTK_WINDOW (window), 217, 103);
        gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview),
FALSE);
   
    return window;
}


int main(int argc, char *argv[])
{
    GtkWidget* do_widget;
    gtk_set_locale ();
    gtk_init (&argc, &argv);
    do_widget = create_window ();
    
    g_signal_connect(G_OBJECT(do_widget), "delete-event",
                     gtk_main_quit, NULL);

    gtk_widget_show (window);
    gtk_main ();
    return 0;
    
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\\\\

Thanks
richa
****** Message from InterScan VirusWall 6 ******

** No virus found in attached file noname.htm

The information contained in this e-mail message and in any annexure is confidential to the  recipient and may contain privileged information. If you are not the intended recipient, please notify the sender and delete the message along with any annexure. You should not disclose, copy or otherwise use the information contained in the message or any annexure. Any views expressed in this e-mail are those of the individual sender except where the sender specifically states them to be the views of SoCrates Software India Pvt Ltd., Bangalore.
*****************     End of message     ***************



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