TreeView - set_cursor



hello,

While developing an application I faced some difficulties which can be
demonstrated with the code at the end of the email.

The program is supposed to function as follows:
The tree has three columns. When the field in the second column is
filled with the word
"account", then the third column should be made visible and the cursor
is set to the
third row for editing.

Te Program behaves:
When the word "account" is entered in the second column in the first row,
the the third column is made visible and the focus is set on it, but
it doesn't start
editing. When the word "account" is enterd in the second row, the
result is as expect, because the third column is already visible.
Possible problem could be the setting of the visibility
property just
before the set_focus call in on_account_edited function.
my question is how can I ahieve the desired behaviour for the firs row?

When continue, another problem appears when on the first row, second
column is clicked so that
the text "account" is marked. then the second row second columns is clicked
without pressing any key. The result is the following message in the console:

(cursor:7860): Gtk-CRITICAL **: _gtk_tree_view_column_start_editing:
assertion `tree_column->editable_widget == NULL' failed

which I don't understand.

any help will be appreciated.



OS:    Debian
version: gtkmm-2.6.4
compiler:  g++-4.0

THE CODE

treeview.h :
#include    <gtkmm/window.h>
#include    <gtkmm/treeview.h>
#include    <gtkmm/liststore.h>

class Trv: public Gtk::Window   {
       private:
       class Example_Model: public Gtk::TreeModel::ColumnRecord  {
           public:
               Gtk::TreeModelColumn<unsigned int>              id;
               Gtk::TreeModelColumn<Glib::ustring>             account;
               Gtk::TreeModelColumn<double>                    sum;

                Example_Model()  {
                   add(id);
                   add(account);
                   add(sum);
               }
       };

       Example_Model                       store_columns;
       Glib::RefPtr<Gtk::ListStore>     ref_store;
       Gtk::TreeView                          treeview;

       void    on_account_edited(Glib::ustring, Glib::ustring);
       void    on_treeview_press_button(GdkEventButton*);
       public:

                       Trv();
               virtual ~Trv();
};

treeview.cc:
#include        "tree_view.h"


void Trv::on_account_edited(Glib::ustring path_str, Glib::ustring text) {
   Gtk::TreeIter   iter=ref_store->get_iter(path_str);

       if (iter)       {
               (*iter)[store_columns.account]=text;

               if (text=="account")    {
                       treeview.get_column(2)->set_visible(true);

                       // works only if the column was visible before
                       treeview.set_cursor(Gtk::TreePath(path_str),
*treeview.get_column(2), true);
               }
       }
}
void Trv::on_treeview_press_button(GdkEventButton* e)   {
       if(e->type==GDK_BUTTON_PRESS)   {
               Gtk::TreePath                   path;
               Gtk::TreeViewColumn*    p_column;
               int                                             x, y;

               if (treeview.get_path_at_pos(int(e->x), int(e->y),
path, p_column, x, y))       {
                       treeview.set_cursor(path, *p_column, true);
               }
       }
}

Trv::Trv():ref_store(Gtk::ListStore::create(store_columns))     {
   set_title("Account");
   set_size_request(600, 400);
   set_border_width(2);

       {
               Gtk::TreeRow    row=*(ref_store->append());

               row[store_columns.id]=ref_store->children().size();
               row[store_columns.account]="";
               row[store_columns.sum]=double(0);

               row=*(ref_store->append());
               row[store_columns.id]=ref_store->children().size();
               row[store_columns.account]="";
               row[store_columns.sum]=double(0);
       }

   treeview.set_model(ref_store);

   int         col=treeview.append_column("№", store_columns.id);

       col=treeview.append_column_editable("account", store_columns.account);
   (treeview.get_column(col-1))->set_expand(true);
       dynamic_cast<Gtk::CellRendererText*>(treeview.get_column_cell_renderer(col-1))->
               signal_edited().connect(sigc::mem_fun(*this,
&Trv::on_account_edited));

   col=treeview.append_column_numeric_editable("sum",
store_columns.sum, "%.2f");
       treeview.get_column(col-1)->set_visible(false);

       treeview.signal_button_press_event().connect_notify(
               sigc::mem_fun(*this, &Trv::on_treeview_press_button));

       add(treeview);

       show_all_children();
}
Trv::~Trv()     {}

main.cc:
#include    <gtkmm/main.h>      // Gtk::Main
#include    "tree_view.c++"

int main (int argc, char *argv[], char *env[])   {
   Gtk::Main   kit(argc, argv);
   Trv                 window;

   kit.run(window);

   return 0;
}

compile wit:
g++-4.0 main.cc -o cursor `pkg-config gtkmm-2.4 --cflags --libs`


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