[gtkmm] PopUp Context Menu Gtk::TreeView problem



Hi,

I am having problem here. First I need to make Gtk::TreeStore that have
right-click enable ( popup menu ) via libglademm library.
Without right-click enabled, I don't have problem because I just use
Gtk::TreeStore directly. So here is my code:

//treeview.h
<snip>
class Treeview : public Gtk::Window
{
     ....
  class ModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:

    ModelColumns()
    { add(m_col_id); add(m_col_name); }

    Gtk::TreeModelColumn<int> m_col_id;
    Gtk::TreeModelColumn<Glib::ustring> m_col_name;
  };

  ModelColumns m_Columns;

  Gtk::ScrolledWindow* m_ScrolledWindow;
  Gtk::TreeView* m_TreeView;
  //No problem here because I use it directly
  Glib::RefPtr<Gtk::TreeStore> m_refTreeModel;
  ...
}

//treeview.cpp
   m_refGlade->get_widget( "treeview1", m_tree );
   if( m_tree )
   {
      m_refTreeModel = Gtk::TreeStore::create( m_Columns );
      this->set_model( m_refTreeModel );

      Gtk::TreeModel::Row row = *( m_refTreeModel->append() );
      row[ m_Columns.m_col_id ] = 1;
      row[ m_Columns.m_col_name ] = "Billy Bob";

      Gtk::TreeModel::Row childrow = *( m_refTreeModel->append(
row.children() ) );
      childrow[ m_Columns.m_col_name ] = "Son of Rohan";
      childrow[ m_Columns.m_col_id ] = 11;

      row = *( m_refTreeModel->append() );

      row[ m_Columns.m_col_name ] = "Sally Belephit";

      this->append_column( "ID", m_Columns.m_col_id );
      this->append_column( "Name", m_Columns.m_col_name );
   }

No problem, happily ever after. But I try to put right click feature. The
example in gtkmm documentation suggest using derived class from
Gtk::TreeView.
So I make a derived class from Gtk::TreeView. But how do I access from
glade pointer? Where do I have to put the implementation for TreeStore?
Should it in Derived class constructor just like in example? Or in if
block of glade pointer? And you know, m_tree ( the pointer for
Gtk::TreeView widget in glade file ) point to GtkTreeView class and I
cannot change it to the derived class from Glade program? Confuse here.

Here is my workaround ( but failed to show TreeStore )
//treeview.h
I change   Gtk::TreeView* m_TreeView; to TreeView_WithPopup* m_TreeView;

//treeview.cpp
   m_refGlade->get_widget( "treeview1", m_tree );
   if( m_tree )
   {
      m_refTreeModel = Gtk::TreeStore::create( m_Columns );
      m_tree->set_model( m_refTreeModel );
      //Here is I cannot use this->set_model because the
      //implementation goes to derived class from TreeView
      //not in derived class from Window again

      Gtk::TreeModel::Row row = *( m_refTreeModel->append() );
      row[ m_Columns.m_col_id ] = 1;
      row[ m_Columns.m_col_name ] = "Billy Bob";

      Gtk::TreeModel::Row childrow = *( m_refTreeModel->append(
row.children() ) );
      childrow[ m_Columns.m_col_name ] = "Son of Rohan";
      childrow[ m_Columns.m_col_id ] = 11;

      row = *( m_refTreeModel->append() );

      row[ m_Columns.m_col_name ] = "Lydia Bradphot";

      childrow = *( m_refTreeModel->append( row.children() ) );

      childrow[ m_Columns.m_col_name ] = "Bustard of Lydia";

      m_tree->append_column( "ID", m_Columns.m_col_id );
      m_tree->append_column( "Name", m_Columns.m_col_name );
   }

This is my derived class from GtkTreeStore:
class TreeView_WithPopup : public Gtk::TreeView
{
   public:
      TreeView_WithPopup();
      virtual ~TreeView_WithPopup();

   protected:
      virtual bool on_button_press_event( GdkEventButton *ev );
      virtual void on_menu_file_popup_generic();


      Gtk::Menu m_Menu_Popup;
};

The implementation does nothing to make this problem simpler. The result
is nothing appear in my program. And I got this message.
** (treeview:1677): CRITICAL **: Gnome::Glade::Xml::get_widget():
dynamic_cast<> failed.

Help me, please.
Thank you.




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